//*********************************************************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="#ffffff";
	field_main.style.background=okcolor;
}
var i = 0;
var delecounter=5; 
			

function delete_rows(tablename)
{
	var tbl = document.getElementById(tablename);
	if(tbl.rows.length>3)
		tbl.deleteRow(tbl.rows.length-1);
	else
		alert('No More Rows to Delete');
}
function CheckCompanyAccount(f)
{
	if (f.name.value == '') 
	{
		alert("Name is Mandatory");
		do_blink(f.name);
		return false;
	}
	if (f.address.value == '') 
	{
		alert("Address is Mandatory");
		do_blink(f.address);
		return false;
	}
	if (f.postcode.value == '') 
	{
		alert("Postcode is Mandatory");
		do_blink(f.postcode);
		return false;
	}
	else
	{
		if(!checkPostCode (f.postcode.value)) 
		{
			alert ("Postcode has invalid format")
			do_blink(f.postcode);
			return(false);
		}	
	}
	var comptype = document.getElementsByName('comptype[]');
	
	myOption = -1;
	for (i=comptype.length-1; i > -1; i--)
	{
		if (comptype[i].checked) 
		{
			myOption = i; 
			i = -1;
			
		}
	}
	if (myOption == -1) 
	{
		alert("Please select company type.");
		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;
		 }
	}
	
	f.submit();	
}
function CheckPrivateAccount(f)
{
	if (f.name.value == '') 
	{
		alert("Name is Mandatory");
		do_blink(f.name);
		return false;
	}
	if (f.address.value == '') 
	{
		alert("Address is Mandatory");
		do_blink(f.address);
		return false;
	}
	if (f.postcode.value == '') 
	{
		alert("Postcode is Mandatory");
		do_blink(f.postcode);
		return false;
	}
	else
	{
		if(!checkPostCode (f.postcode.value)) 
		{
			alert ("Postcode has invalid format")
			do_blink(f.postcode);
			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;
		 }
	}
	
	f.submit();
	
}
function ShowQuote(f)
{
	
	var from = document.getElementsByName('from[]');
	
	myOption = -1;
	for (i=from.length-1; i > -1; i--)
	{
		if (from[i].checked) 
		{
			var pickupf = from[i].value;
			myOption = i; 
			i = -1;
			
		}
	}
	if (myOption == -1) 
	{
		alert("PickUp is Mandatory");
		return false;
	}
	else
	{
		if(pickupf != 0)
		{
			var pickup = document.getElementById('pickup').value;
			var flag1 = 1;
			if(pickup == '')
			{
				alert("PickUp is Mandatory");
				return false;
			}
		}
		else
		{
			var pickup = document.getElementById('pickup').value;
			var flag1 = 0;
			var addf = document.getElementById('addf').value;
			if(addf == '')
			{
				alert("Pickup Address is Mandatory");
				return false;	
			}
			var cityf = document.getElementById('cityf').value;
			if(cityf == '')
			{
				alert("Pickup City is Mandatory");
				return false;	
			}
			
		}
		
	}
	
	var to = document.getElementsByName('to[]');
	myOptionto = -1;
	for (i=to.length-1; i > -1; i--)
	{
		if (to[i].checked) 
		{
			var dropofff = to[i].value;
			myOptionto = i; 
			i = -1;
			
		}
	}
	if (myOptionto == -1) 
	{
		alert("Destination is Mandatory");
		return false;
	}
	else
	{
		if(dropofff != 0)
		{
			var dropoff = document.getElementById('dropoff').value;
			var flag2 = 1;
			if(dropoff == '')
			{
				alert("Destination is Mandatory");
				return false;
			}
		}
		else
		{
			var dropoff = document.getElementById('dropoff').value;
			var flag2 = 0;
			var addt = document.getElementById('addt').value;
			if(addt == '')
			{
				alert("Destination Address is Mandatory");
				return false;	
			}
			var cityt = document.getElementById('cityt').value;
			if(cityt == '')
			{
				alert("Destination City is Mandatory");
				return false;	
			}
		}
	}

	if(flag2 == 0)
	{
		var otheraddp = addf;
		var othercityp = cityf;
		
		var otheraddd = addt;
		var othercityd = cityt;
	}
	else
	{
		var otheraddp = '';
		var othercityp = '';
		
		var otheraddd = '';
		var othercityd = '';
	}
	
	
	
	var vehicletype = document.getElementsByName('vehicletype[]');
	var traveltype = document.getElementsByName('traveltype[]');

	
	for(i=0;i<traveltype.length;i++)
	{
		
		if(traveltype[i].checked)
		{
			//alert(traveltype[i].value);
			var tt = traveltype[i].value;
		}
		
	}
	
	var vehicletype = document.getElementsByName('vehicletype[]');
	myOptionvt = -1;
	for (i=vehicletype.length-1; i > -1; i--)
	{
		if (vehicletype[i].checked) 
		{
			var vt = vehicletype[i].value;
			myOptionvt = i; 
			i = -1;
			
		}
	}
	if (myOptionvt == -1) 
	{
		alert("Please select Vehicle");
		return false;
	}
	// additinal drop off
	var pc = '';
	var postcode = document.getElementsByName('postcode[]');
	
	for (i=0; i < postcode.length; i++)
	{
		pc += postcode[i].value+'_';
		
	}
	
	var ct = '';
	var city = document.getElementsByName('city[]');
	
	for (i=city.length-1; i > -1; i--)
	{
		ct += city[i].value+'_';
		
	}
	
	var add = '';
	var address = document.getElementsByName('address[]');
	
	for (i=address.length-1; i > -1; i--)
	{
		add += address[i].value+'_';
		
	}
	var returndate = document.getElementsByName('returndate');
	var returntime = document.getElementsByName('returntime');
	var returnplace = document.getElementsByName('returnplace');
	//alert(dropoff);
	JourneyPrice('includes/clientajax.php?for=journeyprice','DivJourneyPrice',pickup,dropoff,tt,vt,add,ct,pc,flag1,flag2,otheraddp,othercityp,otheraddd,othercityd,returndate,returntime,returnplace);
}

function CheckFinalBooking(f)
{
	if (f.pass_name.value == '') 
	{
		alert("Passenger name is Mandatory");
		do_blink(f.pass_name);
		return false;
	}
	if (f.contact_no.value == '') 
	{
		alert("Conatact number is Mandatory");
		do_blink(f.contact_no);
		return false;
	}
	else
	{
		if(isNaN(f.contact_no.value))
		{
			alert("Incorrect Conatact number");
			do_blink(f.contact_no);
			return false;	
		}
		
		if(f.contact_no.length < 10)
		{
			alert("Incorrect length of conatact number");
			do_blink(f.contact_no);
			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.bookingdate.value == ""){
		alert("Booking date is Mandatory");
		do_blink(f.bookingdate);
		return false;
	}
	else
	{
		
		if(!isDate(f.bookingdate.value,'dd-MM-yyyy'))
		{
			alert("Incorrect date formate");
			do_blink(f.bookingdate);
			return false;
		}
	}
	
	if(f.showstat1.value == '1')
	{
		if(f.flightnumber.value == "")
		{
			alert("Flight number is Mandatory");
			do_blink(f.flightnumber);
			return false;
		}
	}
	
	
	var paymethod = document.getElementsByName('paymethod[]');
	
	myOption = -1;
	for (i=paymethod.length-1; i > -1; i--)
	{
		if (paymethod[i].checked) 
		{
			var paym = paymethod[i].value;
			myOption = i; 
			i = -1;
			
		}
	}
	if (myOption == -1) 
	{
		alert("Please choose payment method.");
		return false;
	}
	else
	{
		
		if(paym == 'card')
		{
			if(f.ccfname.value == "")
			{
				alert("First name is Mandatory");
				do_blink(f.ccfname);
				return false;
			}
			if(f.cclname.value == "")
			{
				alert("Last name is Mandatory");
				do_blink(f.cclname);
				return false;
			}
			if(f.ACCT.value == "")
			{
				alert("Card number is Mandatory");
				do_blink(f.ACCT);
				return false;
			}
			
			if(f.ccv.value == "")
			{
				alert("Security Code is Mandatory");
				do_blink(f.ccv);
				return false;
			}
		}
		else if(paym == 'cash')
		{
			if(f.payaddress.value == "")
			{
				alert("Address is Mandatory");
				do_blink(f.payaddress);
				return false;
			}
			if(f.paycity.value == "")
			{
				alert("City is Mandatory");
				do_blink(f.paycity);
				return false;
			}
			if(f.paycountry.value == "")
			{
				alert("Country is Mandatory");
				do_blink(f.paycountry);
				return false;
			}
			if(f.paypostcode.value == "")
			{
				alert("Post code is Mandatory");
				do_blink(f.paypostcode);
				return false;
			}
		}
		else if(paym == 'account')
		{
			if(f.accountnumber.value == "")
			{
				alert("Account number is Mandatory");
				do_blink(f.accountnumber);
				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;
	}
	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=10;
	if(form.shsamebilling.checked)
	{
		
		for(counter=0;counter<10;counter++)
		{
			
			//alert(form[counter].value);
			index_sep++;
			form[index_sep].value=form[counter].value;
			
		}
		
	}
	else
	{
		index_sep=10;
		for(counter=0;counter<10;counter++)
		{
			index_sep++;
			form[index_sep].value="";
		}	
	}
}
// client signup
function regcheck(f)
{
		var alertMsg = "";
	if(f.f_sh_name.value == ""){
		alertMsg += "Shipping Address First Name is Mandatory.\n";
	}
	if(f.sh_address.value == ""){
		alertMsg += "Shipping Address is Mandatory.\n";
	}
	if(f.sh_country.value == ""){
		alertMsg += "Shipping Address Country is Mandatory.\n";
	}
	if(f.sh_state.value == "")
	{
	alertMsg += "Shipping Address 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 += "Shipping Address 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 += "Shipping Address 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";
	}
	if(f.cemail.value == ""){
		alertMsg += "Confirm Email is Mandatory.\n";
	}
	if(f.cemail.value != f.email.value){
		alertMsg += "Email and Confirm Email did not matched.\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(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";
	}
	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(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.lastname.value == "")
	{
		alertMsg += "Last name is Mandatory.\n";
	}*/
	/*if(!checkCreditCard (f.ACCT.value, f.debittype.value))
	{
		alertMsg += ccErrors[ccErrorNo]+"\n";
	}*/
	if(f.ACCT.value == "") 
	{						
		alertMsg += "Please enter card number.\n";
					
	}
	if(f.ccv.value.length == 0) 
	{						
		alertMsg += "Please enter security number.\n";
					
	}
	
	/*if(expired(f.expmon.value, f.expyr.value)) 
	{							
		alertMsg += "Sorry! The expiration date you have entered would make this card invalid.\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;
	}

}
// checks date formate
// validate date
function validDate(month, day, year){
	if(month =='0' || day =='0' || year=='0'){
		return false;
	}
	switch(month)
	{
		case '1': //** jan
		case '3': //** March
		case '5': //** May
		case '7': //** July
		case '8': //** Aug
		case '10': //** Nov
		case '12': //** Dec
			if(day>=1 && day<=31){
				return true;
			} else {
				return false;
			}
		case '4': //** APRIL
		case '6' : //** JUNE
		case '9' : //** SEPTEMBER
		case '11' : //** NOVEMBER
			if(day>=1 && day<=30){
				return true;
			} else {
				return false;
			}
		case '2' :
			if(isLeapYear(year)){
				if(day>=1 && day<=29){
					return true;
				}
			} else if(day>=1 && day <= 28){
				return true;
			} else {
				return false;
			}
		default:
			return false;
	}
}



function isLeapYear(year){  // Checking wdr a year is leap year or not
	if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)){
		return true;
	} else {
		return false;
	}
}

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);

			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
function expired( month, year ) 
{
	var now = new Date();							
	var expiresIn = new Date(year,month,0,0,0);		
	expiresIn.setMonth(expiresIn.getMonth()+1);		
	if( now.getTime() < expiresIn.getTime() ) return false;
	return true;									
}
	

	
var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {
     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "MasterCard", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,16", 
               prefixes: "300,301,302,303,304,305,36,38,55",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "AmEx", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011,650",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "15,16", 
               prefixes: "3,1800,2131",
               checkdigit: true};
  cards [7] = {name: "enRoute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
  cards [8] = {name: "Solo", 
               length: "16,18,19", 
               prefixes: "6334, 6767",
               checkdigit: true};
  cards [9] = {name: "Switch", 
               length: "16,18,19", 
               prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
               checkdigit: true};
  cards [10] = {name: "Maestro", 
               length: "16,18", 
               prefixes: "5020,6",
               checkdigit: true};
  cards [11] = {name: "VisaElectron", 
               length: "16", 
               prefixes: "417500,4917,4913",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardnumber = cardnumber.replace (/\s/g, "");
  
  // Check that the number is numeric
  var cardNo = cardnumber
  var cardexp = /^[0-9]{13,19}$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}

