//*********************************************************CLIENT***********************************************************//
var field_main;
function do_blink(field)
{
	var errorcolor="#ff0000";
	field.focus();
	field.select();
	field.style.background=errorcolor;
    field_main=field;
	setInterval("temp()",500);    
}

function temp(field)
{
	var okcolor="#484848";
	field_main.style.background=okcolor;
}
function Paymentdelivery(form)
{
	index_sep=21;
	if(form.copydelivery.checked)
	{
		
		for(counter=2;counter<12;counter++)
		{
			
			//alert(form[counter].value);
			index_sep++;
			form[index_sep].value=form[counter].value;
			
		}
		
	}
	else
	{
		index_sep=21;
		for(counter=2;counter<12;counter++)
		{
			index_sep++;
			form[index_sep].value="";
		}	
	}
}
function CheckMenuOrder(f)
{
	if(f.company.value == '')
	{
		alert("Company name is Mandatory.");
		do_blink(f.company);
		return false;
	}name
	if(f.name.value == '')
	{
		alert("Contact person name is Mandatory.");
		do_blink(f.name);
		return false;
	}
	if(f.email.value == "")
	{
		alert("Email is Mandatory.");
		do_blink(f.email);
		return false;
	}
	else
	{
		var f1=f.email.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(f1))) 
		{ 
		  	alert("Email address is incorrect.");
			do_blink(f.email);
			return false;
		}
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
		 if (f1.match(illegalChars)) 
		 {
			 	alert("Email address contains illegal characters.");
				do_blink(f.email);
				return false;
		 }
	}
	if(f.address.value == '')
	{
		alert("Address is Mandatory.");
		do_blink(f.address);
		return false;
	}
	if(f.phone.value == '')
	{
		alert("Telephone number is Mandatory.");
		do_blink(f.phone);
		return false;
	}
	if(f.fax.value == '')
	{
		alert("Fax is Mandatory.");
		do_blink(f.fax);
		return false;
	}
	f.submit();
}
function CheckShipBill(f)
{
	if(f.sfname.value == '')
	{
		alert("First name is Mandatory.");
		do_blink(f.sfname);
		return false;
	}
	
	if(f.semail.value == "")
	{
		alert("Email is Mandatory.");
		do_blink(f.semail);
		return false;
	}
	else
	{
		var f1=f.semail.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(f1))) 
		{ 
		  	alert("Email address is incorrect.");
			do_blink(f.semail);
			return false;
		}
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
		 if (f1.match(illegalChars)) 
		 {
			 	alert("Email address contains illegal characters.");
				do_blink(f.semail);
				return false;
		 }
	}
	if(f.saddress.value == '')
	{
		alert("Address is Mandatory.");
		do_blink(f.saddress);
		return false;
	}
	if(f.sstate.value == '')
	{
		alert("State is Mandatory.");
		do_blink(f.sstate);
		return false;
	}
	else
	{
		var strRegExp = "[^A-Za-z0-9\\s]";
		var check = f.sstate.value.search(strRegExp);
		 if(check >= 0) 
    	{
			alert("Only alpha-numeric characters and space allowed.");
			do_blink(f.sstate);
			return(false);
		}
	}
	if(f.scity.value == '')
	{
		alert("City is Mandatory.");
		do_blink(f.scity);
		return false;
	}
	else
	{
		var strRegExp = "[^A-Za-z0-9\\s]";
		var check = f.scity.value.search(strRegExp);
		 if(check >= 0) 
    	{
			alert("Only alpha-numeric characters and space allowed.");
			do_blink(f.scity);
			return(false);
		}
	}
	
	if(f.spostalcode.value == ""){
		alert("Postal Code is Mandatory.");
		do_blink(f.spostalcode);
		return(false);
	}
	else
	{
		if(!checkPostCode (f.spostalcode.value)) 
		{
			alert ("Postcode has invalid format")
			do_blink(f.spostalcode);
			return(false);
		}	
	}
	if(f.bfname.value == '')
	{
		alert("First name is Mandatory.");
		do_blink(f.bfname);
		return false;
	}
	if(f.bemail.value == "")
	{
		alert("Email is Mandatory.");
		do_blink(f.bemail);
		return false;
	}
	else
	{
		var f1=f.bemail.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(f1))) 
		{ 
		  	alert("Email address is incorrect.");
			do_blink(f.bemail);
			return false;
		}
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
		 if (f1.match(illegalChars)) 
		 {
			 	alert("Email address contains illegal characters.");
				do_blink(f.bemail);
				return false;
		 }
	}
	if(f.baddress.value == '')
	{
		alert("Address is Mandatory.");
		do_blink(f.baddress);
		return false;
	}
	if(f.bstate.value == '')
	{
		alert("State is Mandatory.");
		do_blink(f.bstate);
		return false;
	}
	else
	{
		var strRegExp = "[^A-Za-z0-9\\s]";
		var check = f.bstate.value.search(strRegExp);
		 if(check >= 0) 
    	{
			alert("Only alpha-numeric characters and space allowed.");
			do_blink(f.bstate);
			return(false);
		}
	}
	if(f.bcity.value == '')
	{
		alert("City is Mandatory.");
		do_blink(f.bcity);
		return false;
	}
	else
	{
		var strRegExp = "[^A-Za-z0-9\\s]";
		var check = f.bcity.value.search(strRegExp);
		 if(check >= 0) 
    	{
			alert("Only alpha-numeric characters and space allowed.");
			do_blink(f.bcity);
			return(false);
		}
	}
	
	if(f.bpostalcode.value == ""){
		alert("Postal Code is Mandatory.");
		do_blink(f.bpostalcode);
		return(false);
	}
	else
	{
		if(!checkPostCode (f.bpostalcode.value)) 
		{
			alert ("Postcode has invalid format")
			do_blink(f.bpostalcode);
			return(false);
		}	
	}
	if(f.sphone.value != "")
	{
		if (!checkUKTelephone (f.sphone.value)) 
		{
     		alert (telNumberErrors[telNumberErrorNo]);
			do_blink(f.sphone);
			return(false);
  		}
	}
	f.submit();
}
function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}
// UK telephone number validation
function checkUKTelephone (telephoneNumber) {

  // Convert into a string and check that we were provided with something
  var telnum = telephoneNumber + " ";
  if (telnum.length == 1)  {
     telNumberErrorNo = 1;
     return false
  }
  telnum.length = telnum.length - 1;
  
  // Don't allow country codes to be included (assumes a leading "+")
  var exp = /^(\+)[\s]*(.*)$/;
  if (exp.test(telnum) == true) {
     telNumberErrorNo = 2;
     return false;
  }
  
  // Remove spaces from the telephone number to help validation
  while (telnum.indexOf(" ")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
  }
  
  // Remove hyphens from the telephone number to help validation
  while (telnum.indexOf("-")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
  }  
  
  // Now check that all the characters are digits
  exp = /^[0-9]{10,11}$/;
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 3;
     return false;
  }
  
  // Now check that the first digit is 0
  exp = /^0[0-9]{9,10}$/;
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 4;
     return false;
  }
	
	// Disallow numbers allocated for dramas.
	 
  // Array holds the regular expressions for the drama telephone numbers
  var tnexp = new Array ();
	tnexp.push (/^(0113|0114|0115|0116|0117|0118|0121|0131|0141|0151|0161)(4960)[0-9]{3}$/);
	tnexp.push (/^02079460[0-9]{3}$/);
	tnexp.push (/^01914980[0-9]{3}$/);
	tnexp.push (/^02890180[0-9]{3}$/);
	tnexp.push (/^02920180[0-9]{3}$/);
	tnexp.push (/^01632960[0-9]{3}$/);
	tnexp.push (/^07700900[0-9]{3}$/);
	tnexp.push (/^08081570[0-9]{3}$/);
	tnexp.push (/^09098790[0-9]{3}$/);
	tnexp.push (/^03069990[0-9]{3}$/);
	
	for (var i=0; i<tnexp.length; i++) {
    if ( tnexp[i].test(telnum) ) {
      telNumberErrorNo = 5;
      return false;
    }
	}
  
  // Finally check that the telephone number is appropriate.
  exp = (/^(01|02|03|05|070|071|072|073|074|075|07624|077|078|079)[0-9]+$/);
	if (exp.test(telnum) != true) {
     telNumberErrorNo = 5;
     return false;
  }
  
  // Telephone number seems to be valid - return the stripped telehone number  
  return telnum;
}
var telNumberErrorNo = 0;
var telNumberErrors = new Array ();
telNumberErrors[0] = "Valid UK telephone number";
telNumberErrors[1] = "Telephone number not provided";
telNumberErrors[2] = "UK telephone number without the country code, please";
telNumberErrors[3] = "UK telephone numbers should contain 10 or 11 digits";
telNumberErrors[4] = "The telephone number should start with a 0";
telNumberErrors[5] = "The telephone number is either invalid or inappropriate";
function copyshtobilling(form)
{
	index_sep=11;
	if(form.shsamebilling.checked)
	{
		
		for(counter=0;counter<11;counter++)
		{
			
			//alert(form[counter].value);
			index_sep++;
			form[index_sep].value=form[counter].value;
			
		}
		
	}
	else
	{
		index_sep=11;
		for(counter=0;counter<11;counter++)
		{
			index_sep++;
			form[index_sep].value="";
		}	
	}
}
// client signup
function regcheck(f)
{
		var alertMsg = "";
		if(f.email.value == ""){
		alertMsg += "Email is Mandatory.\n";
	}
		
	if(f.password.value == ""){
		alertMsg += "Password is Mandatory.\n";
	}
	if(f.cpassword.value == ""){
		alertMsg += "Confirm Password is Mandatory.\n";
	}
	if(f.password.value != f.cpassword.value){
		alertMsg += "Password and Confirm Password did not matched.\n";
	}
	if(f.f_sh_name.value == ""){
		alertMsg += "Full Forename is Mandatory.\n";
	}
	if(f.sh_address.value == ""){
		alertMsg += "Address is Mandatory.\n";
	}

	
	if(f.sh_city.value == ""){
		alertMsg += "City is Mandatory.\n";
	}
	else
	{
		var strRegExp = "[^A-Za-z0-9\\s]";
		var check = f.sh_city.value.search(strRegExp);
		 if(check >= 0) 
    	{
			alertMsg += "Only alpha-numeric characters and space allowed.\n";
		}
	}
	if(f.sh_state.value == "")
	{
	alertMsg += "County is Mandatory.\n";
	}
	else
	{
		var strRegExp = "[^A-Za-z0-9\\s]";
		var check = f.sh_state.value.search(strRegExp);
		 if(check >= 0) 
    	{
			alertMsg += "Only alpha-numeric characters and space allowed.\n";
		}
	}
	if(f.sh_postalcode.value == ""){
		alertMsg += "Postal Code is Mandatory.\n";
	}
	
	
	if(f.sh_country.value == ""){
		alertMsg += "Country is Mandatory.\n";
	}

	if(alertMsg!=""){
		alert(alertMsg);
		return(false);
	}else{
		f.submit();
		return true;
	}

}

// client edit account
function CheckEditAccount(f)
{
		var alertMsg = "";
	if(f.f_sh_name.value == ""){
		alertMsg += "First Name is Mandatory.\n";
	}
	if(f.sh_address.value == ""){
		alertMsg += "Address is Mandatory.\n";
	}
	if(f.sh_country.value == ""){
		alertMsg += "Country is Mandatory.\n";
	}
	
	if(f.sh_state.value == "")
	{
		alertMsg += "State is Mandatory.\n";
	}
	
	if(f.sh_city.value == ""){
		alertMsg += "City is Mandatory.\n";
	}
	if(f.sh_postalcode.value == ""){
		alertMsg += "Postal Code is Mandatory.\n";
	}
	
	
	
	if(alertMsg!=""){
		alert(alertMsg);
		return(false);
	}else{
		f.submit();
		return true;
	}

}
//  client login
function loginclientcheck(f)
{
		var alertMsg = "";
	if(f.email.value == ""){
		alertMsg += "Login Name is Mandatory.\n";
	}
	if(f.pass.value == ""){
		alertMsg += "Password is Mandatory.\n";
	}
	if(alertMsg!=""){
		alert(alertMsg);
		return(false);
	}else{
		f.submit();
		return true;
	}

}
// client forget pass

function checkforgetpass(f)
{
		
		var alertMsg = "";
	
	if(f.emailadd.value == ""){
		alertMsg += "Email is Mandatory.\n";
	}
	else
	{
		var f1=f.emailadd.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(f1))) 
		{ 
		  alertMsg += "Email address is incorrect.\n";
		}
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
		 if (f1.match(illegalChars)) 
		 {
			 alertMsg += "Email address contains illegal characters.\n";
		 }
		
		
	}
	
		
	if(alertMsg!=""){
		alert(alertMsg);
		return(false);
	}else{
		//f.submit();
		return true;
	}

}
// client change pass
function CheckChangePass(f)
{
		var alertMsg = "";
	if(f.old_pass.value == ""){
		alertMsg += "Old Password is Mandatory.\n";
	}
	if(f.new_pass.value == ""){
		alertMsg += "New Password is Mandatory.\n";
	}
	if(f.conf_pass.value == ""){
		alertMsg += "Confirm Password is Mandatory.\n";
	}
	else
	{
		if(f.conf_pass.value != f.new_pass.value){
		alertMsg += "Password & Confirm Password didnot matched.\n";
		}	
	}
	
		
	if(alertMsg!=""){
		alert(alertMsg);
		return(false);
	}else{
		f.submit();
		return true;
	}

}
// update qty
function CheckQty(f)
{
	var qty = document.getElementsByName('qty[]');

	var alertMsg = "";
	for(i=0;i<qty.length;i++)
	{
		if(qty[i].value == 0)
		{
			alertMsg = "Quantity Should not be Zero or Null.\n";
		}
		bool=qty[i].value.match("^[0-9]{1,2}$");
		if(isNaN(qty[i].value)||(qty[i].value.indexOf(".")!=-1))
		{
			alertMsg = "Quantity must be number.\n";
		}
		else if((!bool))
		{
			alertMsg += "Quantity must be 0-99.\n";	
		}
	}
		
	if(alertMsg!=""){
		alert(alertMsg);
		return(false);
	}else{
		f.submit();
		return true;
	}

}
// check final order 
function checkfinalorder(f)
{
	var alertMsg = "";
	
	if(f.ddate.value == ""){
		alertMsg += "Please give the delivery date.\n";
	}
	else
	{
		
		if(!isDate(f.ddate.value,'MM-dd-yyyy'))	
			alertMsg += "Incorrect date formate.\n";
	}
	if(f.email.value == ""){
		alertMsg += "Email is Mandatory.\n";
	}
	else
	{
		var f1=f.email.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(f1))) 
		{ 
		  alertMsg += "Email address is incorrect.\n";
		}
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
		 if (f1.match(illegalChars)) 
		 {
			 alertMsg += "Email address contains illegal characters.\n";
		 }
		
		
	}
	if(f.f_sh_name.value == ""){
		alertMsg += "First Name is Mandatory.\n";
	}
	if(f.sh_address.value == ""){
		alertMsg += "Address is Mandatory.\n";
	}
	if(f.sh_country.value == ""){
		alertMsg += "Country is Mandatory.\n";
	}
	
	if( (f.sh_state.value == "") && (f.otherstate.value == "") )
	{
		alertMsg += "State is Mandatory.\n";
	}
			
	
	if(f.sh_city.value == ""){
		alertMsg += "City is Mandatory.\n";
	}
	if(f.sh_postalcode.value == ""){
		alertMsg += "Postal Code is Mandatory.\n";
	}
	
	
	
	if(f.card.checked==true)
	{
		if(f.fname.value=="")
		{
			alertMsg += "First name is Mandatory.\n";
		}
		
		if(f.lname.value=="")
		{
			alertMsg += "Last name is Mandatory.\n";
		}
		
		if(f.cardno.value.length != "16")
		{
			alertMsg += "Invalid Card number.\n";
		}
		
		if(f.pin.value.length!="3")
		{
			alertMsg += "Invalid Pin number.\n";
		}
		
	}
		
	if(alertMsg!=""){
		alert(alertMsg);
		return(false);
	}else{
		f.submit();
		return true;
	}

}

// check add to cart in client
function CheckAddToCart(f)
{
	
	var alertMsg = "";
	
	
	if(f.qty.value == ""){
		alertMsg += "Quantity is Mandatory.\n";
	}
	else
	{
		if(f.qty.value == 0){
			alertMsg += "Quantity is not zero.\n";
		}
		else
		{
			bool=f.qty.value.match("^[0-9]{1,2}$");
			if(isNaN(f.qty.value)|| (f.qty.value.indexOf(".")!=-1))
			{
				alertMsg += "Quantity must be number.\n";
			}
			else if((!bool))
			{
				alertMsg += "Quantity must be 0-99.\n";	
			}
		}
	}
		
	if(alertMsg!=""){
		alert(alertMsg);
		return(false);
	}else{
		f.submit();
		return true;
	}

}
function validateCard(f)
{
	var alertMsg = "";
	
	if(f.ccfname.value == "")
	{
		alertMsg += "First name is Mandatory.\n";
	}
		if(f.ACCT.value == "") 
	{						
		alertMsg += "Please enter card number.\n";
					
	}
	else
	{
		if(!checkCreditCard (f.ACCT.value, f.debittype.value))
		{
			alertMsg += "Invalid card number\n";
		}	
	}
	if(f.ccv.value.length == 0) 
	{						
		alertMsg += "Please enter security number.\n";
					
	}
	/*if(expired(f.month.value, f.year.value)) 
	{							
		alertMsg += "Sorry! The expiration date you have entered would make this card invalid.\n";
		
	}*/
	if(f.debittype.value == "Maestro" || f.debittype.value == "Solo") 
	{						
		if(f.startdate.value == "" && f.issuenumber.value == "") 
		{						
			alertMsg += "Please enter start date or issue number.\n";
		}
	}
		
	if(alertMsg!="")
	{
		alert(alertMsg);
		return(false);
	}
	else
	{
		f.submit();
		return true;
	}
}

// client CheckFinalEnquiry
function CheckFinalEnquiry(f)
{
		var alertMsg = "";
	if(f.f_sh_name.value == ""){
		alertMsg += "First Name is Mandatory.\n";
	}
	if(f.sh_address.value == ""){
		alertMsg += "Address is Mandatory.\n";
	}
	if(f.sh_country.value == ""){
		alertMsg += "Country is Mandatory.\n";
	}
	if(f.sh_state.value == "")
	{
	alertMsg += "State is Mandatory.\n";
	}
	else
	{
		var strRegExp = "[^A-Za-z0-9\\s]";
		var check = f.sh_state.value.search(strRegExp);
		 if(check >= 0) 
    	{
			alertMsg += "Only alpha-numeric characters and space allowed.\n";
		}
	}
	if(f.sh_city.value == ""){
		alertMsg += "City is Mandatory.\n";
	}
	else
	{
		var strRegExp = "[^A-Za-z0-9\\s]";
		var check = f.sh_city.value.search(strRegExp);
		 if(check >= 0) 
    	{
			alertMsg += "Only alpha-numeric characters and space allowed.\n";
		}
	}
	if(f.sh_postalcode.value == ""){
		alertMsg += "Postal Code is Mandatory.\n";
	}
	if(f.sh_postalcode.value == ""){
		alertMsg += "Postal Code is Mandatory.\n";
	}
	else
	{
		if(!checkPostCode (f.sh_postalcode.value)) 
		{
			alertMsg += "Postcode has invalid format.\n";
		}	
	}
	if(f.sh_phone.value != "")
	{
		if (!checkUKTelephone (f.sh_phone.value)) 
		{
			alertMsg += telNumberErrors[telNumberErrorNo];
		}
	}
	if(f.email.value == ""){
		alertMsg += "Email is Mandatory.\n";
	}
	else
	{
		var f1=f.email.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(f1))) 
		{ 
		  alertMsg += "Email address is incorrect.\n";
		}
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
		 if (f1.match(illegalChars)) 
		 {
			 alertMsg += "Email address contains illegal characters.\n";
		 }
	}
	
	
	if(alertMsg!=""){
		alert(alertMsg);
		return(false);
	}else{
		f.submit();
		return true;
	}

}


