function checkEmail()
	{
	var strEmail, strError, countAtRate, countDot, i;
	var checkAtRate, checkDot;
	var ValidChars,CountValidChars;
	ValidChars="abcdefghijklmnopqrstuvwxyz0123456789_.@ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
	strEmail = checkEmail.arguments[0];
	countAtRate=0;
	countDot=0;
	CountValidChars=0;
	if (strEmail.length > 7)
		{
		for(i=0;i<strEmail.length;i++)
			{
			if(strEmail.charAt(i)=="@")
				countAtRate++;
			if(strEmail.charAt(i)==".")
				countDot++;
			CountValidChars=0;
			for(j=0;j<ValidChars.length;j++)
				{
				if(strEmail.charAt(i)==ValidChars.charAt(j))
					{
					CountValidChars++;
					}
				}
			if(CountValidChars==0)
				{
				strError=0;
				break;
				}
			}
		}
	checkAtRate=strEmail.indexOf("@",1);
	checkDot=strEmail.indexOf(".",1);
	for(i=1;i<countDot;i++)
		checkDot=strEmail.indexOf(".",checkDot+1);
	if(countAtRate==1 && countDot > 0 && strEmail.length >=7 && strError != 0)
		strError=1;
	else
		strError=0;
	if(checkDot>=strEmail.length-2)
		strError=0;
	if(strEmail.charAt(0)=="@" || strEmail.charAt(strEmail.length-1)=="@")
		strError=0;
	if(strEmail.charAt(0)=="." || strEmail.charAt(strEmail.length-1)==".")
		strError=0;
	if(checkDot < checkAtRate)
		strError=0;

	return strError;
}

function frmSearch(){
	var strError="";
	//if(document.frmsearch.txtsearch.value=="")
	//  strError=strError+"\nPlease enter text for search";
	strError=strError+"\nUnder Construction";
	if(strError!=""){
	  alert("Check the missing fields:\n=========================="+strError);
	  return false;
	}
	else {
	  return true;
	}  
}

 
 function chkSpace(txtfield){
 	var i,j,txtval;
 	j=0;
 		txtfield=eval(txtfield)
 		txtval=txtfield.value;
 		for(i=0;i<txtval.length;i++){
 			j++
 		    if(txtval.substr(i,1)!=" ")
 	    	break;
 	    }
 
 		txtval=txtval.substr(j-1,txtval.length);
 		if(txtval==" ")
 			txtval="";
 			txtfield.value=txtval;
 			return(txtval);
}

 function checkEnter(funName)
 {
  if(event.keyCode==13)
  eval(funName);
}
 function postSearch(frmVal,args1)
  {
  	
  	var g=eval(frmVal);
  	if (chkSpace(g.srh).length>2)
  	{
  		g.method="get";
 		g.action="search.php";
 		g.submit();
 		if(postSearch.arguments[1]=="")	return true;
  	}
  	else
  	{
 
  	 alert("Enter text of at least three characters");
 	 if(postSearch.arguments[1]=="") return false;
 	 
 	}
 	
 }
 
 function validatesendmail(){
   var strError="";
   if(document.frm.txtname.value=="")
     strError=strError+"\nName";
   if(document.frm.txtphone.value=="")
     strError=strError+"\nPhone";    
   if(document.frm.txtemail.value=="")
     strError=strError+"\nEmail";
   if(document.frm.txtemail.value!=""){  
     if(checkEmail(document.frm.txtemail.value)==0)
       strError=strError+"\nInvalid Email";		
     }
   if(document.frm.txtsubject.value=="")
     strError=strError+"\nSubject";    
   if(document.frm.txtenquiry.value=="")
     strError=strError+"\nEnquiry";    
   if(strError!=""){
     alert("Check the missing fields:\n=========================="+strError);
     return false;
   }
   else {
     return true;
   }
}

function validateRegistration(){	
   var strError="";
   if(document.registration_form.name_first.value=="" || document.registration_form.name_family.		 		value=="" )
     strError=strError+"\nName";
 	if(document.registration_form.address1.value=="")
     strError=strError+"\nAddress 1";    	
	if(document.registration_form.city.value=="")
     strError=strError+"\nCity";  
	if(document.registration_form.zipPostal.value=="")
     strError=strError+"\nZip Code/Postal Code"; 
	if(document.registration_form.country.value==0)
     strError=strError+"\nCountry";
	 //email checking begins
	if(document.registration_form.email.value=="" || document.registration_form.confirm_email.value==  		"")
	strError=strError+"\nOne Email Field";
	else{
    	if(checkEmail(document.registration_form.email.value)==0)
			strError=strError+"\nInvalid Email";
		else{
			if(checkEmail(document.registration_form.confirm_email.value)==0)
				strError=strError+"\nInvalid Email Confirmation";
			else{
				if(document.registration_form.email.value!=document.registration_form.confirm_email.value)
       strError=strError+"\nEmail Missmatch";	
			}//end of else-3
		}//end of else-2
     }//end of else-1
	//end of email checking	  
//checking password begins
if((document.registration_form.psw.value)=='' || (document.registration_form.confirm_psw.value)=='')
	strError=strError+"\nOne Password Field";
else if((document.registration_form.psw.value).length<=5)
	strError=strError+"\nPassword Length"; 
else{
	if((document.registration_form.psw.value==document.registration_form.name_first.value)|| (document.registration_form.psw.value==document.registration_form.name_family.value))
	strError=strError+"\nPassword similar to Name";	
	if((document.registration_form.psw.value==document.registration_form.citizen_number.value)|| (document.registration_form.psw.value==document.registration_form.contact.value))
	strError=strError+"\nPassword similar to contact or citizen";									 
	if(document.registration_form.psw.value!=document.registration_form.confirm_psw.value)
		strError=strError+"\nPassword Mismatch";		
}
if(document.registration_form.psw_hint.value=='')
		strError=strError+"\nPassword Hint"; 
//end of password
	if(document.registration_form.date.value==0 ||document.registration_form.month.value==0 ||document.registration_form.year.value==0)
		strError=strError+"\nBirthday";
    if(strError!=""){
     alert("Check the missing fields:\n=========================="+strError);
     return false;
   }
   else {
     return true;
   }
}//end of registration check

function checkContactNumber(number){
	var strNumber=number;
	if((isNaN(strNumber) )&& ((strNumber.length)!=9 || (strNumber.length)!=10))
		return false;
	else
		return true;	
}
function checkPassword(psw){
	if(psw==''){		
		return false;
	}	
	if(psw.length<=5){		
		return false;
	}
	else
		return true;	
}

function loginVerification(){
   var strError="";
   if(document.login_form.user_name_field.value=="")
     strError=strError+"\nUser Name";
	else{
		if(checkEmail(document.login_form.user_name_field.value)==0)
	 strError=strError+"\nUser Name must be email";
		}
	if(document.login_form.psw_field.value=="")
		strError=strError+"\nPassword";
	
	if(strError!=""){
	  alert("Check the missing fields:\n=========================="+strError);
	  return false;
	}
	
	else {
	  return true;
	}  
}

function f_psw(){
   var strError="";
   if(checkEmail(document.r_psw_form.email_field.value)==0)
	 strError=strError+"\nUser Name must be email address";
	if(strError!=""){
	  alert("Check the missing fields:\n=========================="+strError);
	  return false;
	}	
	else {
	  return true;
	}  
}

function goToCartPage(pid,qty){
var p_id=pid;	
window.open("cart_process.php?pid="+p_id+"&&qty="+qty+"&&action=add","_self","width=100%,height=100% scrollbars=1 resizable=1");
}
function product_detail(pid){
	window.open("product.php?pid="+pid+"&&clicked_value=1","_self","width=100%,height=100% scrollbars=1 resizable=1");
}

function updateCart(addSubtract,pid,i,itemNumber){	
var qty=0;
	if(itemNumber==1)
		qty=document.cartForm.quantity.value;		
	else
		qty=document.cartForm.quantity[i].value;
	
	if((addSubtract=='s') && (qty<2))
			alert("Quantity should be greater than 0");		
	else
	window.open("cart_process.php?action=update&&addSub="+addSubtract+"&&pid="+pid+"","_self",  					"width=100%,height=100% scrollbars=1 resizable=1");
		
}//end of function updateCart

function continueShoping(){
	window.open("index.php","_self","width=100%,height=100% scrollbars=1 resizable=1");
}

function validateShipping(){
var strError=""; 
if(checkEmail(document.shipping_form.email.value)==0)
	strError=strError+"\nInvalid Email";	
if(document.shipping_form.s_txtfname.value=='')
	strError=strError+"\nFirst Name for Shipping";	
if(document.shipping_form.s_txtlname.value=='')
	strError=strError+"\nLast Name for shipping";
if(document.shipping_form.s_txtaddress1.value=='')
	strError=strError+"\nAddress";
if(document.shipping_form.s_txtcity.value=='')
	strError=strError+"\nCity";	
if(document.shipping_form.s_txtzip.value=='')
	strError=strError+"\nZip Postal";
if(checkEmail(document.shipping_form.s_txtemail.value)==0)
	strError=strError+"\nInvalid Email";
if(strError!=""){
     alert("Check the missing fields:\n=========================="+strError);
     return false;
   }
else {
     return true;
   }
}

function validateCreditCard(){
	var strError=""; 
if(document.creditCardForm.card_name.value=='')
	strError=strError+"\nCredit Card Holder";	
if(document.creditCardForm.card_number.value=='' || isNaN(document.creditCardForm.card_number.value))
	strError=strError+"\nCard Number must be Number";	
if(document.creditCardForm.month.value==0 || document.creditCardForm.year.value==0)
	strError=strError+"\nExpiring Date";
if(strError!=""){
     alert("Check the missing fields:\n=========================="+strError);
     return false;
   }
else {
     return true;
   }
}