function NavRollOver(oTd) {
	//if (!oTd.contains(event.fromElement)) {
	if (!oTd.fromElement) {
		oTd.bgColor="#FFFF00";
		event.srcElement.parentElement.style.cursor="hand";
	}
}

function NavRollOut(oTd) {
	//if (!oTd.contains(event.toElement)) {
	if (!oTd.toElement) {
		if (oTd.id == "odd") {
			oTd.bgColor="#FFFFFF";
		} else {
			oTd.bgColor="#CFD9E5";
		}
	}
}

/****
 * This is mouseOver specific functions
 * Used for the topNav links
 */

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_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_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/*****
 * Used for opening the site credit pop up
 */
function openSiteCredit() {
	var attributes, creditWindow;
	attributes = "height=200, width=200, scrollbars=0, status=0, toolbar=0, resizeable=0, directories=0, menubar=0";
	
	creditWindow = window.open("sitecredit.html", "SiteCredit", attributes);
	creditWindow.moveTo(screen.width/2-100, screen.height/2-100);
}

function openProductReferral(productID) {
	var attributes, productReferralWindow;
	attributes = "height=338, width=318, scrollbars=0, status=0, toolbar=0, resizeable=0, directories=0, menubar=0";
	
	productReferralWindow = window.open("productReferral.asp?productID=" + productID, "ProductReferral", attributes);
	productReferralWindow.moveTo(screen.width/2-159, screen.height/2-169);
}


/*****
 * Validation functions
 */
function IsEmail(str) {
	var nLen;
	var nCnt1, nCnt2;

  nCnt1=0;
  nCnt2=0;
  nLen = str.length;
  for(var i=0; i<nLen; i++){     
		if(str.charAt(i)=='\'' || str.charAt(i)=='\"'){
		        return false;
		}
		if(str.charAt(i)=='<' || str.charAt(i)=='>' ){
		        return false;
		}
		if(str.charAt(i)=='@'){
		        nCnt1++;
		}
		if(str.charAt(i)=='.'){
		        nCnt2++;
		}
  }
  if( nCnt1!=1 || nCnt2<1){
    return false;
  }
  else
  	return true;
}

function isValidPasscode(sText) {
	if (sText.length > 0) {
		return true;
	} else {
		return false;
	}
}

function validateEmail(aForm) {	
	if (IsEmail(aForm.email.value)==false){
		alert("Please confirm your email");
	  aForm.email.focus();
	  return (false);
	}
	
	return(true);
}

function validateSubscribeEmail(aForm) {
	if (IsEmail(aForm.subscribe_email.value)==false){
		alert("Please confirm your email");
	  aForm.subscribe_email.focus();
	  return (false);
	}
	
	return(true);
}

function validateLogin(aForm) {
	if (IsEmail(aForm.account_email.value)==false){
		alert("Please enter a valid email");
	  aForm.account_email.focus();
	  return (false);
	} else if (isValidPasscode(aForm.account_password.value) == false) {
		alert("Please enter a valid password");
		aForm.account_password.focus();
	  return (false);
	}
	
	return(true);
}

function validateNewAccountForm(aForm) {
	if (IsEmail(aForm.email.value)==false){
	  alert("Please confirm your email");
	  aForm.email.focus();
	  return (false);
	}
	
	if ((isValidPasscode(aForm.passcode.value) == true) && (isValidPasscode(aForm.confirm_passcode.value) == true)) {
		if (aForm.passcode.value == aForm.confirm_passcode.value) {
			var conf = confirm("Is " + aForm.email.value + " the correct email?");
			
			if (conf) {
				return(true);
			} else {
				return(false);
			}
		} else {
			alert("Your passcode do not match");
	  	aForm.confirm_passcode.focus();
			return(false);
		}
	} else {
		alert("Please do not enter an empty passcode");
		aForm.passcode.focus();
		return (false);
	}
	
	return (true);
}

function check(what) {
	if (what.from.value == "") {
		alert ("Name field cannot be empty");
		return false;
	}
	else if (what.frommail.value == "") {
		alert ("Email field cannot be empty");
		return false;
	}
	else if (!IsEmail(what.frommail.value)) {
		alert ("Email is invalid");
		return false;
	}
	return true;
}

function validateChangePassword(aForm) {
	if (aForm.newpwd1.value != "" && aForm.newpwd2.value != "") {
		if (aForm.newpwd1.value == aForm.newpwd2.value) {
			return true;
		} else {
			alert ("The new password you provided do not match");
			return false;
		}
	} else {
		alert ("New password can not be empty");
		return false;
	}
	
	return true;
}

function isAgreementRead(aForm) {
	var isChecked = aForm.readAgreement.checked;
	//if (aForm.newpwd1.value != "" && aForm.newpwd2.value != "") {
	if (isChecked) {
		return true;
	} else {
		alert("Please read the Purchase Agreement");
		return false;
	}
}

function refreshMe() {
	var currentURL = location.href;
	location.href = currentURL;
}