function isblank(s)

{

	for(var i = 0; i < s.length; i++) {

		var c = s.charAt(i);

		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;

	}

	return true;

}



function CheckEmail(strEmail) {

	var i;

	var getChar;





	if ((Left(strEmail, 1) == "@") || (Right(strEmail, 1) == "@") )

		return false;

	



		getChar = 0;

	for (i = 0 ; i < strEmail.length ; i++ ) {

		if (strEmail.charAt(i)=='@'){

			getChar++;

		}

	}	    



	if ( getChar != 1 )

		return false;



	var email1;

	var email2;

	var temail;

	

	temail = strEmail.split('@')

	email1 = temail[0].replace(/\s/g, "");

	email2 = temail[1].replace(/\s/g, "");	

	

	var cemail;

	cemail = strEmail;

	cemail = cemail.replace(/\@/g, "");	

	cemail = cemail.replace(/\./g, "");	

	

	if (cemail.length == 0)

		return false;

	

	var allow;

	allow = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";

	for(i = 0 ; i < cemail.length; i++ )

		if (allow.indexOf(cemail.charAt(i)) < 0 )

			return false;



	if (Left(email1, 1) == '.')

		return false;



	

	if (Left(email2, 1) == '.' || Right(email2, 1) == '.' || email2.replace(/\./g, "").length == email2.length)

		return false;



	if (email2.indexOf("..") >= 0 )

		return false;



	if (Left(email2, 1) == '-' || Right(email2, 1) == '-')

		return false;



	if (Left(email2, 1) == '_' || Right(email2, 1) == '_')

		return false;

	

	return true;

}	



function Left( sourceStr, charIdx ) {

	if((sourceStr==null) || (sourceStr=="")) return "";

	return sourceStr.substring(0, charIdx);

}



function Right( sourceStr, charIdx ) {	

	if((sourceStr==null) || (sourceStr=="")) return "";

	return sourceStr.substring(sourceStr.length-charIdx, sourceStr.length);

}





// Check Login

function check_login(e)

{

	var msg;

	var textun="";

	var textpw="";

	var fg=1;



	if ((e.username.value == null) || (e.username.value == "") || isblank(e.username.value)) { textun = "E-mail Address is Required.\n"; fg=0;}

	

	if (fg) { 

	  if (!CheckEmail(e.username.value)) { textun = "An Error occurred. Please enter a correct email address. \n";} 	

	}

	

	

	if ((e.password.value == null) || (e.password.value == "") || isblank(e.password.value)) { textpw = "Password is Required.\n"; }

		

	if (e.username.style) e.username.style.backgroundColor = textun != "" ? '#FFCC66':'#FFFFFF';

	if (e.password.style) e.password.style.backgroundColor = textpw != "" ? '#FFCC66':'#FFFFFF';

	

	if (textun == "" && textpw == "") { e.submit(); return true; }

	else { msg = textun+textpw;	} 

	

	alert(msg);

	return false;

}



// Check Lost Password

function check_lost(e)

{

	var msg;

	var textun="";

	var textfn="";

	var textln="";

	var fg=1;



	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textun = "E-mail Address is Required.\n"; fg=0;}

	

	if (fg) { 

	  if (!CheckEmail(e.email.value)) { textun = "An Error occurred. Please enter a correct email address. \n";} 	

	}

	

	

	if ((e.firstname.value == null) || (e.firstname.value == "") || isblank(e.firstname.value)) { textfn = "First Name is Required.\n"; }

	if ((e.lastname.value == null) || (e.lastname.value == "") || isblank(e.lastname.value)) { textln = "Last Name is Required.\n"; }

		

	if (e.email.style) e.email.style.backgroundColor = textun != "" ? '#FFCC66':'#FFFFFF';

	if (e.firstname.style) e.firstname.style.backgroundColor = textfn != "" ? '#FFCC66':'#FFFFFF';

	if (e.lastname.style) e.lastname.style.backgroundColor = textln != "" ? '#FFCC66':'#FFFFFF';

	

	if (textun == "" && textfn == "" && textln == "") { e.submit(); return true; }

	else { msg = textun+textfn+textln;	} 

	

	alert(msg);

	return false;

}



//Contact Submit

function checkForm(e)

{

	var msg;

	var textAll = "Please check your Personal Information.";

	var textfn="";

	var textln="";

	var textem="";

	var fg=1;

	

	if ((e.fristname.value == null) || (e.fristname.value == "") || isblank(e.fristname.value)) { textfn = "First Name is Required.\n";}	

	if ((e.lastname.value == null) || (e.lastname.value == "") || isblank(e.lastname.value)) { textln = "Last Name is Required.\n";}

	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}

	if (fg) {

		 if (!CheckEmail(e.email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 

		}

	

	if (e.fristname.style) e.fristname.style.backgroundColor = textfn != "" ? '#FFCC66':'#FFFFFF';

	if (e.lastname.style) e.lastname.style.backgroundColor = textln != "" ? '#FFCC66':'#FFFFFF';

	if (e.email.style) e.email.style.backgroundColor = textem != "" ? '#FFCC66':'#FFFFFF';

	

	if ((textfn == "") && (textln == "") && (textem == "")) { e.submit(); return true;}

	

	if (textfn && textln && textem) {

		msg = textAll;

	} else {

		msg = textfn + textln + textem;

	}		

	alert(msg);

	return false;

}





// Review Submit

function check_review(e)

{

	var msg;

	var textcm="";



	if ((e.comment.value == null) || (e.comment.value == "") || isblank(e.comment.value)) { textcm = "Comment is Required.\n"; }	

		

	if (e.comment.style) e.comment.style.backgroundColor = textcm != "" ? '#FFCC66':'#FFFFFF';

	

	if (textcm == "") { e.submit(); return true; }

	else { msg = textcm;	} 

	

	alert(msg);

	return false;

}





// Check Register

function check_info(e)

{

	var msg;

	var textAll = "Please check your Personal Information.";

	var textfn="";

	var textln="";

	var textem="";

	var textct="";

	var textsp="";

	var textcy="";

	var textpw="";

	var fg=1;

	var vg=1;



	if ((e.customers_firstname.value == null) || (e.customers_firstname.value == "") || isblank(e.customers_firstname.value)) { textfn = "First Name is Required.\n";}	

	if ((e.customers_lastname.value == null) || (e.customers_lastname.value == "") || isblank(e.customers_lastname.value)) { textln = "Last Name is Required.\n";}

	if ((e.customers_email.value == null) || (e.customers_email.value == "") || isblank(e.customers_email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}

	if (fg) {

		 if (!CheckEmail(e.customers_email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 

		}

	if ((e.entry_city.value == null) || (e.entry_city.value == "") || isblank(e.entry_city.value)) { textct = "City is Required.\n";}

	if(e.entry_country.value != 209){

		if ((e.entry_state.value == null) || (e.entry_state.value == "") || isblank(e.entry_state.value)) { textsp = "State or Province is Required.\n";}

	}

	if (e.entry_country.value == 0) { textcy = "Country is Required.\n";}

	if ((e.password.value == null) || (e.password.value == "") || isblank(e.password.value)) { textpw = "Password is Required.\n"; vg=0;}

	if (vg) {

	 if (e.password.value != e.confirmation.value) { textpw = "Password does not match.\n"; }

	}

	if (e.customers_firstname.style) e.customers_firstname.style.backgroundColor = textfn != "" ? '#FFCC66':'#FFFFFF';

	if (e.customers_lastname.style) e.customers_lastname.style.backgroundColor = textln != "" ? '#FFCC66':'#FFFFFF';

	if (e.customers_email.style) e.customers_email.style.backgroundColor = textem != "" ? '#FFCC66':'#FFFFFF';

	if (e.entry_city.style) e.entry_city.style.backgroundColor = textct != "" ? '#FFCC66':'#FFFFFF';

	if(e.entry_country.value != 209){

		if (e.entry_state.style) e.entry_state.style.backgroundColor = textsp != "" ? '#FFCC66':'#FFFFFF';

	}

	if (e.entry_country.style) e.entry_country.style.backgroundColor = textcy != "" ? '#FFCC66':'#FFFFFF';

	if (e.password.style) e.password.style.backgroundColor = textpw != "" ? '#FFCC66':'#FFFFFF';

	if (e.confirmation.style) e.confirmation.style.backgroundColor = textpw != "" ? '#FFCC66':'#FFFFFF';

	

	if ((textfn == "") && (textln == "") && (textem == "") && (textct == "") && (textsp == "")  && (textcy == "")  && (textpw == "")) { e.submit(); return true;}

	

	if (textfn && textln && textem && textct && textsp && textcy && textpw) {

		msg = textAll;

	} else {

		msg = textfn + textln + textem + textct  + textsp + textcy + textpw;

	}		

	alert(msg);

	return false;

}



// Check Update

function check_update(e)

{

	var msg;

	var textAll = "Please check your Personal Information.";

	var textfn="";

	var textln="";

	var textct="";

	var textsp="";

	var textcy="";



	if ((e.customers_firstname.value == null) || (e.customers_firstname.value == "") || isblank(e.customers_firstname.value)) { textfn = "First Name is Required.\n";}	

	if ((e.customers_lastname.value == null) || (e.customers_lastname.value == "") || isblank(e.customers_lastname.value)) { textln = "Last Name is Required.\n";}

	if ((e.entry_city.value == null) || (e.entry_city.value == "") || isblank(e.entry_city.value)) { textct = "City is Required.\n";}

	if(e.entry_country.value != 209){

		if ((e.entry_state.value == null) || (e.entry_state.value == "") || isblank(e.entry_state.value)) { textsp = "State or Province is Required.\n";}

	}

	if (e.entry_country.value == 0) { textcy = "Country is Required.\n";}



	if (e.customers_firstname.style) e.customers_firstname.style.backgroundColor = textfn != "" ? '#FFCC66':'#FFFFFF';

	if (e.customers_lastname.style) e.customers_lastname.style.backgroundColor = textln != "" ? '#FFCC66':'#FFFFFF';

	if (e.entry_city.style) e.entry_city.style.backgroundColor = textct != "" ? '#FFCC66':'#FFFFFF';

	if(e.entry_country.value != 209){

		if (e.entry_state.style) e.entry_state.style.backgroundColor = textsp != "" ? '#FFCC66':'#FFFFFF';

	}

	if (e.entry_country.style) e.entry_country.style.backgroundColor = textcy != "" ? '#FFCC66':'#FFFFFF';

	

	if ((textfn == "") && (textln == "") && (textct == "") && (textsp == "")  && (textcy == "")) { e.submit(); return true;}

	

	if (textfn && textln && textct && textsp && textcy) {

		msg = textAll;

	} else {

		msg = textfn + textln + textct  + textsp + textcy;

	}		

	alert(msg);

	return false;

}



// Check Raffle Form

function check_raffle(e)

{

	var msg;

	var textAll = "Please check your Personal Information.";

	var textun="";

	var textag="";

	var textem="";

	var textad="";

// referral check
//	var textre="";

	var fg=1;



	if ((e.username.value == null) || (e.username.value == "") || isblank(e.username.value)) { textun = "Name is Required.\n";}	

	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}

	if (fg) {

		 if (!CheckEmail(e.email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 

		}

	if ((e.address.value == null) || (e.address.value == "") || isblank(e.address.value)) {textad = "Address is Required.\n";}

// referral check
//    if ((e.referred.value == null) || (e.referred.value == "") || isblank(e.referred.value)) { textre = "Referred By is Required.\n"; }

	if ((e.age.value == null) || (e.age.value == "") || isblank(e.age.value)) { textag = "Age is Required.\n";}



	if (e.username.style) e.username.style.backgroundColor = textun != "" ? '#FFCC66':'#FFFFFF';

	if (e.email.style) e.email.style.backgroundColor = textem != "" ? '#FFCC66':'#FFFFFF';

	if (e.address.style) e.address.style.backgroundColor = textad != "" ? '#FFCC66':'#FFFFFF';

// referral check
//	if (e.referred.style) e.referred.style.backgroundColor = textre != "" ? '#FFCC66':'#FFFFFF';

	if (e.age.style) e.age.style.backgroundColor = textag != "" ? '#FFCC66':'#FFFFFF';

	

	if ((textun == "") && (textem == "") && (textad == "") && (textag == "") && (textre == "")) { return true;}

	

	if (textun && textem && textad && textag && textre) {

		msg = textAll;

	} else {

		msg = textun + textag + textem + textad + textre;

	}		

	alert(msg);

	return false;

}



//check type of the file

    function CheckExt(ext)

    {

    	//set type of the file

    	var AllowExt="avi|mpeg";

    	var ExtOK=false;

			var ArrayExt;

			if(AllowExt.indexOf('|')!=-1)

			{

				ArrayExt=AllowExt.split('|');

				for(i=0;i<ArrayExt.length;i++)

				{

					if(ext.toLowerCase()==ArrayExt[i])

					{

						ExtOK=true;

						break;

					}

				}

			}

			else

			{

				ArrayExt=AllowExt;

				if(ext.toLowerCase()==ArrayExt)

				{

					ExtOK=true;

				}

			}

			return ExtOK;

    }







function check_pwd(e)

{

	var msg;

	var textAll = "Please check your submit form.";

	var textop="";

	var textnp="";

	var fg=1;

	

	

   if ((e.o_pass.value == null) || (e.o_pass.value == "") || isblank(e.o_pass.value)) { textop = "Current Password is Required.\n"; fg=0;}

   if (fg) { if (calcMD5(e.o_pass.value) != e.mdpass.value) { textop = "Current Password is Wrong.\n";} }

   if ((e.n_pass.value == null) || (e.n_pass.value == "") || isblank(e.n_pass.value)) { textnp = "New Password is Required.\n"; }

   

   if (e.n_pass.value != e.c_pass.value) { textnp = "New Passowrd does not match.\n"; }

  

	if (e.o_pass.style) e.o_pass.style.backgroundColor = textop != "" ? '#FFCC66':'#FFFFFF';

	if (e.n_pass.style) e.n_pass.style.backgroundColor = textnp != "" ? '#FFCC66':'#FFFFFF';

	if (e.c_pass.style) e.c_pass.style.backgroundColor = textnp != "" ? '#FFCC66':'#FFFFFF';

		

	if ((textop == "") && (textnp == "")) {

		e.submit(); 

	return false;

	}

	

	if (textop && textnp) {

		msg = textAll;

	} else {

		msg = textop + textnp;

	}		

	

	alert(msg);

	return false;

}


function check_user(e)
{
error=0;
if((e.n_user.value == "")||(e.n_user.value.charAt(0) == " ")) { e.n_user.value = ""; error=1; }
if(error==1) { 
  alert('Invalid: Username Required'); 
  return false; 
  }
else { 
  e.submit(); 
  return false;
  }
}

function check_email(e)

{

	var msg;

	var textem="";

	var fg=1;



	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}

	

	if (fg) { 

	  if (!CheckEmail(e.email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 	

	}

		

	if (e.email.style) e.email.style.backgroundColor = textem != "" ? '#FFCC66':'#FFFFFF';

	

	if (textem == "") { e.submit(); return true; }

	else { msg = textem;	} 

	

	alert(msg);

	return false;

}





function check_type(e){

var txt="Date of Birth";

  if (!checkStr(e.value)) {

    e.style.backgroundColor = '#FFCC66';

	e.focus(); 

	e.select(); 

    txt = txt+" that you input is error!";

	alert(txt);

	return false;

  }

  e.style.backgroundColor = '#FFFFFF';

  return true;

}



function checkStr(str)

{

    for( var i=0; i < str.length; i++) {

        var ch = str.substring( i, i+1 );

        if( (ch < "0" || ch > "9") && ch != "-") 

            return false;              

    }    

    return true;

}



function check_num(e){

var txt="Quantity ";

  if (!checkData(e.value)) {

    e.style.backgroundColor = '#FFCC66';

	e.focus(); 

	e.select(); 

	e.value = "";

    txt = txt+" should be number!";

	alert(txt);

	return false;

  }

  e.style.backgroundColor = '#FFFFFF';

  return true;

}



function checkData(str)

{

    for( var i=0; i < str.length; i++) {

        var ch = str.substring( i, i+1 );

        if(ch < "0" || ch > "9") 

            return false;              

    }    

    return true;

}



function check_card(e){

var txt="Card Number";

  if (!checkCard(e.value)) {

    e.style.backgroundColor = '#FFCC66';

	e.focus(); 

    txt = txt+" has illegal character!";

	alert(txt);

	return false;

  }

  e.style.backgroundColor = '#FFFFFF';

  return true;

}



function checkCard(str)

{

    for( var i=0; i < str.length; i++) {

        var ch = str.substring( i, i+1 );

        if( (ch < "0" || ch > "9") && ch != " ") 

            return false;              

    }    

    return true;

}

