function GetMainFormName(){
	var i;
	for (i=0;i<document.forms.length;i++){
		if (document.forms[i].name.indexOf("aspnetForm") != -1)
		return document.forms[i].name;
	}
	return null;
}

function GetElement(ElementName, formName)
{
	return document.forms[formName].elements[GetElementName(ElementName,formName)];
}

function GetElementName(name,mf){
	var n = name.toLowerCase()
	if (n==null || n=="") return null;
	var i, s, j;
	for (i=0;i<document.forms[mf].elements.length;i++){
		if (document.forms[mf].elements[i].name.toLowerCase().indexOf(n) != -1){
			var strform = document.forms[mf].elements[i].name.toLowerCase();
			var strformname = strform.substr(strform.indexOf(n),n.length);
			if (strformname == n)
				return document.forms[mf].elements[i].name;
		}	
	}
	return null;
}

function SetSuccessurl(url)
{
	url = url + '?RetourUrl=' + document.location;
	window.open(url, '_self');
}

function facebook(subject) {
	u=location.href;
	if ( typeof(subject) != 'undefined' ){
	    u=location.href + "#videotab";
	    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(subject),'sharer','toolbar=0,status=0,width=626,height=436');
	}    
    else
        window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

// FLASH ACTIVATION
function CreateControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL, FLASHVARS, AUTOSTART,BGCOLOR)
{
  var d = document.getElementById(DivID);
  var objectTag = '<object classid=' + CLSID + ' id=' + ObjectID + ' width=' + WIDTH + ' height=' + HEIGHT +' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
  objectTag = objectTag + '<param name="allowScriptAccess" value="sameDomain">';
  objectTag = objectTag + '<param name="movie" value=' + URL + '>'
  objectTag = objectTag + '<param name="FlashVars" value=' + FLASHVARS + '>';
  objectTag = objectTag + '<param name="quality" value="high">'  
  //objectTag = objectTag + '<param name="bgcolor" value="#000000">'  
  objectTag = objectTag + '<param name="bgcolor" value=' + BGCOLOR +'>'  
  objectTag = objectTag + '<param name="autoStart" value=' + AUTOSTART + '/>';
  objectTag = objectTag + '<embed src="' + URL + '" flashVars="' + FLASHVARS + '" quality="high" bgcolor="' + BGCOLOR + '"  width="' + WIDTH + '" height="' + HEIGHT +'" name="main" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
  objectTag = objectTag + "</object>";
  d.innerHTML = objectTag;
}
				
function CreateTransparentControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL, FLASHVARS, AUTOSTART)
{
  var d = document.getElementById(DivID);
  var objectTag = '<object classid=' + CLSID + ' id=' + ObjectID + ' width=' + WIDTH + ' height=' + HEIGHT +' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
  objectTag = objectTag + '<param name="allowScriptAccess" value="sameDomain">';
  objectTag = objectTag + '<param name="movie" value=' + URL + '>'
  objectTag = objectTag + '<param name="FlashVars" value=' + FLASHVARS + '>';
  objectTag = objectTag + '<param name="quality" value="high">'  
  objectTag = objectTag + '<param name="autoStart" value=' + AUTOSTART + '/>';
  
  objectTag = objectTag + '<param name="wmode" value="transparent" />'
				
  objectTag = objectTag + '<embed wmode="transparent" src="' + URL + '" flashVars="' + FLASHVARS + '" quality="high" bgcolor="#000000" width="' + WIDTH + '" height="' + HEIGHT +'" name="main" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
  objectTag = objectTag + "</object>";
  d.innerHTML = objectTag;
}


var newWindow

function openPopup(url, popupWidth, popupHeight) {
	if (newWindow && !newWindow.closed)	{
		newWindow.close()
	}	
		
	var winl = (screen.width - popupWidth) / 2;
	var wint = (screen.height - popupHeight) / 2;
		//alert(popupWidth + " " + popupHeight);
	newWindow = open(url, 'SaveOurSkin', ("toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,top=" + wint + ",left=" + winl + ",width=" + popupWidth + ",height=" + popupHeight + "\""));
	newWindow.focus();
}


function openPopupReview(url, popupWidth, popupHeight) {
	if (newWindow && !newWindow.closed)	{
		newWindow.close()
	}	
		
	var winl = (screen.width - popupWidth) / 2;
	var wint = (screen.height - popupHeight) / 2;
		//alert(popupWidth + " " + popupHeight);
	newWindow = open(url, 'SaveOurSkin', ("toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,top=" + wint + ",left=" + winl + ",width=" + popupWidth + ",height=" + popupHeight + "\""));
	newWindow.focus();
}

/*Large popups with scrollbars */

function openLargePopup(url, popupWidth, popupHeight) {
	if (newWindow && !newWindow.closed)	{
		newWindow.close()
	}	
		
	var winl = (screen.width - popupWidth) / 2;
	var wint = (screen.height - popupHeight) / 2;
		
	newWindow = open(url, 'SaveOurSkin', ("toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,top=" + wint + ",left=" + winl + ",width=" + popupWidth + ",height=" + popupHeight + "\""));
	newWindow.focus();
}

/* End */

function openPopupPrint(url, popupWidth, popupHeight) {
	if(diagCode != '')
	{
		openPopup(url + '?catcode=' + diagCode, popupWidth, popupHeight);
	}
	else
	{
		openPopup(url, popupWidth, popupHeight);
	}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null)
{
document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
	if ((obj=MM_findObj(args[i]))!=null) 
	{ 
		v=args[i+2];
		if (obj.style) 
		{ 
			obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; 
		}
		obj.visibility=v; 		
	}
	//If there's a popup...
	if(args[3] != null)
	{
		var layer = MM_findObj(args[0]);	
		var popuptxt = MM_findObj(args[3]);	
		var oBo = cBB (popuptxt);
		var oBp = cBB (layer);			
		layer.style.left = oBo.l + popuptxt.offsetWidth - 40;
		//Layer1.style.top = oBo.t - 200;
		layer.style.top = oBo.t - layer.offsetHeight + 5;		
	}
}

function ValidateZip()
{		
	document.all.divZipError.style.display = "none";
		
	var mf = GetMainFormName();				
	var zipTextboxRef =  GetElementName("address_zip", mf);
	var zipTextbox = document.forms[mf].elements[zipTextboxRef];
	
	//Check if zip code length is 5
	if(zipTextbox.value.length != 5)
	{
		document.all.tblcellZip.style.color = "#ED950A";
		document.all.divZipError.style.display = "block";
		return false;
	}				
	else			
	{
		//If zipcode length is 5, only allow 0-9 to be entered as the characters
		var checkOK = "0123456789";
		var allValid = true;
		for (var i=0; i < zipTextbox.value.length; i++) 
		{ 
			ch = zipTextbox.value.charAt(i);
			
			for (var j = 0;  j < checkOK.length;  j++)
			{							
				if (ch == checkOK.charAt(j))
					break;							
			}
			
			if (j == checkOK.length)
			{							
				allValid = false;
				break;
			}
		}
		if (!allValid) 
		{
			document.all.tblcellZip.style.color = "#ED950A";
			document.all.divZipError.style.display = "block";
			return false;
		}	
		else
		{
			//Fix for Birthdate textboxes getting validated by core even though Birthdate
			//is not mandatory: Clear Birthdate textboxes before submitting form
			ClearDate(); 
			return true;
		}						
	}
}

/* Vadlidate Zip and State */
function ValidateZipState()
{		
	document.all.divZipError.style.display = "none";
	document.all.divStateError.style.display = "none";
	document.all.tblcellState.style.color = "#333";
	document.all.tblcellZip.style.color = "#333";
		
	var mf = GetMainFormName();				
	var zipTextboxRef =  GetElementName("address_zip", mf);
	var zipTextbox = document.forms[mf].elements[zipTextboxRef];	
	
	var StateboxRef =  GetElement("address_state_choice", mf);
	var Statebox = document.forms[mf].elements[StateboxRef];
	
	// check state is not '' empty selected
	if (StateboxRef.options[StateboxRef.selectedIndex].value == "")
	{
		//alert("blank selected");
		document.all.divStateError.style.display = "block";
		document.all.tblcellState.style.color = "#ED950A";
		return false;
	}
	
	//Check if zip code length is 5
	if(zipTextbox.value.length != 5)
	{
		document.all.tblcellZip.style.color = "#ED950A";
		document.all.divZipError.style.display = "block";
		return false;
	}				
	else			
	{
		//If zipcode length is 5, only allow 0-9 to be entered as the characters
		var checkOK = "0123456789";
		var allValid = true;
		for (var i=0; i < zipTextbox.value.length; i++) 
		{ 
			ch = zipTextbox.value.charAt(i);
			
			for (var j = 0;  j < checkOK.length;  j++)
			{							
				if (ch == checkOK.charAt(j))
					break;							
			}
			
			if (j == checkOK.length)
			{							
				allValid = false;
				break;
			}
		}
		if (!allValid) 
		{
			document.all.tblcellZip.style.color = "#ED950A";
			document.all.divZipError.style.display = "block";
			return false;
		}			
		else
		{
			//Fix for Birthdate textboxes getting validated by core even though Birthdate
			//is not mandatory: Clear Birthdate textboxes before submitting form
			ClearDate(); 
			return true;
		}						
	}
}

function ClearDate()
{
var mf = GetMainFormName();
var monthTextboxName = GetElementName("birthmonth", mf);
var dayTextboxName = GetElementName("birthday", mf);
var yearTextboxName = GetElementName("birthyear", mf);

var monthTextbox =  document.forms[mf].elements[monthTextboxName];
var dayTextbox =  document.forms[mf].elements[dayTextboxName];
var yearTextbox =  document.forms[mf].elements[yearTextboxName];
										
if (monthTextbox.value =='MM' && dayTextbox.value =='DD' && yearTextbox.value=='YYYY')
	{
		monthTextbox.value ='';
		dayTextbox.value ='';
		yearTextbox.value ='';
	}
}

/*
** This function is used to extend the string object to implement the trim function
*/
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}

