function VerifyEMail(emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
//		alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
//	    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
//		        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
//		alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
//	   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
//	   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

function check_mail(mail){
	if(mail.length > 0){
	   if (!VerifyEMail(mail)){
			alert('Incorrect Email');
			return (false);

	   }
	   else return true;
	}
	alert('Incorrect Email');
	return false;

}

function ShowTrusted() {
	open('trusted.php','','height=500,width=600,left=200,top=140,statusbar=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no');
}

//for login.php
function check_login(){
	ok=1;
	err="<font size=2 face=Arial><b>";//init the err display
	
	if(document.log.user1.value==''){
		ok=0;
		 err+="Please provide a Username<br>";
	}
	if(document.log.pass1.value==''){
		ok=0;
		 err+="Please provide a Password<br>";
	}
	
	err+="</b></font><br>";
	
	if(ok==1) return true;
	else{
		tbl_err.style.display="inline";
		tbl_err.innerHTML=err;
		return false;
	}	
	return false;
}

function check_login2(){
	ok=1;
	err="<font size=2 face=Arial><b>";//init the err display
	
	if(document.log.useremail.value==''){
		ok=0;
		 err+="Please fill in your E-mail address<br>";
	} else if (document.log.username.value==''){
		ok=0;
		 err+="Please fill in your Username<br>";
	}
	err+="</b></font><br>";
	
	if(ok==1) return true;
	else{
		tbl_err.style.display="inline";
		tbl_err.innerHTML=err;
		return false;
	}	
	return false;
}

//for cart.php




function CheckoutClick(sURL) {
	if (document.getElementsByName("Product250").length) {
		for (var iProduct = 0; iProduct < document.getElementsByName("Product250").length; iProduct++) {
			if (document.getElementsByName("Product250")[iProduct].checked) {
				break;
			}
		}
		if (iProduct < document.getElementsByName("Product250").length) {
			//document.location.href = (sURL + "free_id=" + document.getElementsByName("Product250")[iProduct].value);
			window.location.assign(sURL + "free_id=" + document.getElementsByName("Product250")[iProduct].value);
		} else {
			alert("Please choose your free gift");
		}
	} else {
		//document.location.href = (sURL);
		window.location.assign(sURL);
	}
}

function ClickFree250(nOption) {
	document.getElementsByName("Product250")[nOption-1].click();
}

//for the check out


function filltheshipping() {
	document.forma.f_ship_to_phone.value=document.forma.f_phone.value;
	document.forma.f_ship_to_first_name.value=document.forma.f_first_name.value;
	document.forma.f_ship_to_last_name.value=document.forma.f_last_name.value;
	document.forma.f_ship_to_address.value=document.forma.f_address.value;
	document.forma.f_ship_to_city.value=document.forma.f_city.value;
	document.forma.f_ship_to_zip.value=document.forma.f_zip.value;
	document.forma.f_ship_to_country.value=document.forma.f_country.value;
	document.forma.f_ship_to_state.value=document.forma.f_state.value;
	document.forma.f_ship_to_country.onchange();
}



function check_mail2(mail){
	if(mail.length > 0){
		var i   = mail.indexOf("@")
		var j   = mail.indexOf(".",i)
		var k   = mail.indexOf(",")
		var kk  = mail.indexOf(" ")
	   if ((i < 0) || (j < 0) || (k != -1) || (kk != -1)){
	alert('Incorrect Email');
			return (false);

	   }
	   else return true;
	}
	alert('Incorrect Email');
	return false;

}
//register
function f_check(){
	ok=1;
	//err="<font color=#A1CAF3 face=Arial><b>";//init the err display
	err='';
	
	//user info form
	if(document.sub.web.value==''){
		 err+="please provide your Website Name<br>";
		 ok=0;
	}	
	if(document.sub.site.value==''){
		 err+="please provide your Website Address<br>";
		 ok=0;
	}	
	if(document.sub.aff_bonus_title.value==''){
		 err+="please provide your Bonus Title<br>";
		 ok=0;
	}	
	if(document.sub.billing.value==''){
		 err+="please provide your Billing Name<br>";
		 ok=0;
	}	
	
	if(document.sub.email.value==''){
		 err+="please provide email address<br>";
		 ok=0;
	}
	test=document.sub.email.value;
	if(test!='' && !check_mail(test)){
		err+="your Email address seems to be incorrect<br>";
		ok=0;
	}
	if(document.sub.email.value!=document.sub.cemail.value){
		 err+="Email addresses do not match<br>";
		 ok=0;
	}
	
	if(document.sub.uname.value==''){
		 err+="please provide a UserName<br>";
		 ok=0;
	}	
	test=document.sub.uname.value;
	if(test.length<6){
		  err+="Username should be at least 6 chars<br>";
		 ok=0;
	}
	if(document.sub.fname.value==''){
		 err+="please provide your First Name<br>";
		 ok=0;
	}	
	if(document.sub.lname.value==''){
		 err+="please provide your Last Name<br>";
		 ok=0;
	}	
	if(document.sub.phone.value==''){
		 err+="please provide your Phone<br>";
		 ok=0;
	}	
	if(document.sub.pass1.value==''){
		 err+="please provide a Password<br>";
		 ok=0;
	}
	if(document.sub.pass1.value!=document.sub.cpass1.value){
		 err+="Passwords do not match<br>";
		 ok=0;
	}
	test=document.sub.pass1.value;
	if(test.length<6){
		 err+="Password should be at least 6 chars<br>";
		 ok=0;
	}
	//*
	test=document.sub.phone.value;
	if(isNaN(test) && test!=''){
		 err+="Phone number must be numeric<br>";
		 ok=0;
	}
	//*/
	if(document.sub.street.value==''){
		 err+="please provide your street<br>";
		 ok=0;
	}
	if(document.sub.city.value==''){
		 err+="please provide your City<br>";
		 ok=0;
	}	
	if(document.sub.zip.value==''){
		 err+="please provide your Zip<br>";
		 ok=0;
	}//	
	//test=document.sub.zip.value;
	//if(isNaN(test) && test!=''){
	//	 err+="Zip number must be numeric<br>";
	//	 ok=0;
	//}
	if(document.sub.country.value==''){
		 err+="please provide your Country<br>";
		 ok=0;
	}			 
	if(document.sub.country.value=='United States' && document.sub.state.value==''){
		 err+="please provide your State<br>";
		 ok=0;
	}
	
	if(!document.sub.declare.checked){
		 err+="Please approve that you have read the declaration and understand it<br>";
		 ok=0;
	}
	
	//err+="</b></font><br>";
	err+="<br>";
	
	if(ok==1) return true;
	else{
		tbl_err.style.display="inline";
		tbl_err.innerHTML=err;
		tbl_err.focus();
		return false;
	}	
	return false;
}

function checkSTS(c){
	if(c=="United States"){
		sts.style.display="inline";		
	}
	else{
		sts.style.display="none";
	}
}
