// JavaScript Document - form validation
//************************************//
function check_accounting(accounting){// form validation accounting services
	if(accounting.name.value == ""){alert("please enter your name");accounting.name.focus();return(false);}//end if
	if(accounting.businessname.value == ""){alert("please enter your business name");accounting.businessname.focus();return(false);}//end if
	if(accounting.industry.value == ""){alert("please enter your business industry");accounting.industry.focus();return(false);}//end if
	if(accounting.email.value.indexOf("@",0) == -1){alert("please enter a valid email address");accounting.email.focus();return(false);}//end if
	if(accounting.contact.value == ""){alert("please enter your contact number");accounting.contact.focus();return(false);}//end if
	if(!accounting.bookkeeping.checked && !accounting.annualreturn.checked && !accounting.taxreturn.checked && !accounting.vatreporting.checked && !accounting.annualaccounts.checked){alert("please select at least one service you require");return(false);}//end if
	return(true);
}//end function
//************************************//
function check_marketing(marketing){// form validation marketing & advertising
	if(marketing.name.value == ""){alert("please enter your name");marketing.name.focus();return(false);}//end if
	if(marketing.businessname.value == ""){alert("please enter your business name");marketing.businessname.focus();return(false);}//end if
	if(marketing.industry.value == ""){alert("please enter your business industry");marketing.industry.focus();return(false);}//end if
	if(marketing.email.value.indexOf("@",0) == -1){alert("please enter a valid email address");marketing.email.focus();return(false);}//end if
	if(marketing.contact.value == ""){alert("please enter your contact number");marketing.contact.focus();return(false);}//end if
	if(!marketing.marketingstrategy.checked && !marketing.marketingcampaign.checked && !marketing.advertising.checked && !marketing.onlinemarketing.checked && !marketing.emailmarketing.checked && !marketing.design.checked){alert("please select at least one service you require");return(false);}//end if
	return(true);
}//end function
//************************************//
function check_software(software){// form validation software & design
	if(software.name.value == ""){alert("please enter your name");software.name.focus();return(false);}//end if
	if(software.businessname.value == ""){alert("please enter your business name");software.businessname.focus();return(false);}//end if
	if(software.industry.value == ""){alert("please enter your business industry");software.industry.focus();return(false);}//end if
	if(software.email.value.indexOf("@",0) == -1){alert("please enter a valid email address");software.email.focus();return(false);}//end if
	if(software.contact.value == ""){alert("please enter your contact number");software.contact.focus();return(false);}//end if
	if(!software.websitedesign.checked && !software.onlinepayment.checked){alert("please select at least one service you require");return(false);}//end if
	return(true);
}//end function
//************************************//
function check_services(services){// form validation services for new in the uk
	if(services.name.value == ""){alert("please enter your name");services.name.focus();return(false);}//end if
	if(services.email.value.indexOf("@",0) == -1){alert("please enter a valid email address");services.email.focus();return(false);}//end if
	if(services.contact.value == ""){alert("please enter your contact number");services.contact.focus();return(false);}//end if
	if(!services.ukbankaccount.checked && !services.ciscard.checked && !services.soletrader.checked && !services.cscscard.checked && !services.ninumber.checked && !services.driving.checked && !services.residential.checked && !services.benefits.checked){alert("please select at least one service you require");return(false);}//end if
	return(true);
}//end function
//************************************//
function check_login(login){// form validation login
	if(login.username.value == "" || login.username.value == "email address"){alert("please enter your username");login.username.focus();return(false);}//end if
	if(login.passwd.value == "" || login.passwd.value == "password"){alert("please enter your password");login.passwd.focus();return(false);}//end if
	return(true);
}//end function
//************************************//
function check_forgot(forgot){// form validation forgot login
	if(forgot.username.value == "" || forgot.username.value == "email address"){alert("please enter your email address");forgot.username.focus();return(false);}//end if
	return(true);
}//end function
//************************************//
function check_registration(reg){//form validation new user registration
	if(reg.name.value == ""){alert("please enter your first name");reg.name.focus();return(false);}//end if
	if(reg.surname.value == ""){alert("please enter your surname");reg.surname.focus();return(false);}//end if
	if(reg.address1.value == ""){alert("please enter your address");reg.address1.focus();return(false);}//end if
	if(reg.county.value == ""){alert("please enter your county");reg.county.focus();return(false);}//end if
	if(reg.country.value == ""){alert("please enter your country");reg.country.focus();return(false);}//end if
	if(reg.postcode.value == ""){alert("please enter your postcode");reg.postcode.focus();return(false);}//end if
	if(reg.email.value.indexOf("@",0) == -1){alert("please enter a valid email address");reg.email.focus();return(false);}//end if
	if(reg.contact.value == ""){alert("please enter your contact number");reg.contact.focus();return(false);}//end if
	if(reg.passwd.value == ""){alert("please enter your password");reg.passwd.focus();return(false);}//end if
	if(reg.passwd_confirm.value == ""){alert("please confirm your password");reg.passwd_confirm.focus();return(false);}//end if
	if(reg.passwd.value != reg.passwd_confirm.value){alert("your passwords do not match");reg.passwd.focus();return(false);}//end if
	var passwd_str = reg.passwd.value;
	if(passwd_str.length < 8){alert("your password needs to be at least 8 characters in length");reg.passwd.focus();return(false);}//end if
	var SHOW_ALERT = true; // make be false to supress the alerts.
	var _alpha = reg.passwd.value.search(/[a-z]|[A-Z]/);
	var _numer = reg.passwd.value.search(/\d/);
	if(_alpha==-1){if(SHOW_ALERT)alert("your password doesn't have any characters!");return false;}//end if
	if(_numer==-1){if(SHOW_ALERT)alert("your password doesn't have any numbers!");return false;}//end if
	return(true);
}//end function
//************************************//
function check_companyformation(companyformation){//form validation company formation
	if(companyformation.company_company.value == ""){alert("please enter your company name");companyformation.company_company.focus();return(false);}//end if
	if(companyformation.company_fullname.value == ""){alert("please enter your name");companyformation.company_fullname.focus();return(false);}//end if
	if(companyformation.company_addressstreet.value == ""){alert("please enter the company street address");companyformation.company_addressstreet.focus();return(false);}//end if
	if(companyformation.company_addresscity.value == ""){alert("please enter the company city");companyformation.company_addresscity.focus();return(false);}//end if
	if(companyformation.company_addresscountry.value == ""){alert("please enter the companys country");companyformation.company_addresscountry.focus();return(false);}//end if
	if(companyformation.company_addresscode.value == ""){alert("please enter the company postal code");companyformation.company_addresscode.focus();return(false);}//end if
	if(companyformation.director1_fullname.value == ""){alert("please enter the directors full name");companyformation.director1_fullname.focus();return(false);}//end if
	if(companyformation.director1_addressstreet.value == ""){alert("please enter the directors street address");companyformation.director1_addressstreet.focus();return(false);}//end if
	if(companyformation.director1_addresscity.value == ""){alert("please enter the directors city");companyformation.director1_addresscity.focus();return(false);}//end if
	if(companyformation.director1_addresscountry.value == ""){alert("please enter the directors country");companyformation.director1_addresscountry.focus();return(false);}//end if
	if(companyformation.director1_addresscode.value == ""){alert("please enter the directors postal code");companyformation.director1_addresscode.focus();return(false);}//end if
	if(companyformation.director1_dob.value == ""){alert("please enter the directors date of birth");companyformation.director1_dob.focus();return(false);}//end if
	if(companyformation.director1_nationality.value == ""){alert("please enter the directors nationality");companyformation.director1_nationality.focus();return(false);}//end if
	if(companyformation.director1_occupation.value == ""){alert("please enter the directors occupation");companyformation.director1_occupation.focus();return(false);}//end if
	if(companyformation.director1_pob.value == ""){alert("please enter the directors place of birth");companyformation.director1_pob.focus();return(false);}//end if
	if(companyformation.director1_mother.value == ""){alert("please enter the directors mothers name");companyformation.director1_mother.focus();return(false);}//end if
	if(companyformation.director1_father.value == ""){alert("please enter the directors fathers name");companyformation.director1_father.focus();return(false);}//end if
	if(companyformation.shares_num.value == ""){alert("please enter the number of shares");companyformation.shares_num.focus();return(false);}//end if
	if(companyformation.shares_value.value == ""){alert("please enter the shares value");companyformation.shares_value.focus();return(false);}//end if
	if(companyformation.shareholder0_fullname.value == ""){alert("please enter the shareholders full name");companyformation.shareholder0_fullname.focus();return(false);}//end if
	if(companyformation.shareholder0_dob.value == ""){alert("please enter the shareholders date of birth");companyformation.shareholder0_dob.focus();return(false);}//end if
	if(companyformation.shareholder0_nationality.value == ""){alert("please enter the shareholders nationality");companyformation.shareholder0_nationality.focus();return(false);}//end if
	if(companyformation.shareholder0_tel.value == ""){alert("please enter the shareholders telephone number");companyformation.shareholder0_tel.focus();return(false);}//end if
	if(companyformation.shareholder0_addressstreet.value == ""){alert("please enter the shareholders street address");companyformation.shareholder0_addressstreet.focus();return(false);}//end if
	if(companyformation.shareholder0_addresscity.value == ""){alert("please enter the shareholders city");companyformation.shareholder0_addresscity.focus();return(false);}//end if
	if(companyformation.shareholder0_addresscountry.value == ""){alert("please enter the shareholders country");companyformation.shareholder0_addresscountry.focus();return(false);}//end if
	if(companyformation.shareholder0_addresscode.value == ""){alert("please enter the shareholders postal code");companyformation.shareholder0_addresscode.focus();return(false);}//end if
	if(companyformation.shareholder0_percentage.value == ""){alert("please enter the shareholders percentage");companyformation.shareholder0_percentage.focus();return(false);}//end if
	return(true);
}//end function
//************************************//
function check_carinsurance(car){//form validation car insurance
	if(car.name.value == ""){alert("please enter your name");car.name.focus();return(false);}//end if
	if(car.surname.value == ""){alert("please enter your surname");car.surname.focus();return(false);}//end if
	if(car.email.value.indexOf("@",0) == -1){alert("please enter a valid email address");car.email.focus();return(false);}//end if
	if(car.dob.value == ""){alert("please enter your date of birth");car.dob.focus();return(false);}//end if
	if(car.title.value == ""){alert("please enter your title");car.title.focus();return(false);}//end if
	if(!car.resident_birth.checked && (car.resident_mm.value=="" || car.resident_mm.value=="mm" || car.resident_yyyy.value=="" || car.resident_yyyy.value=="yyyy")){
		alert("please enter since when you where a resident in the UK");
		car.resident_mm.focus();
		return(false);
	}//end if
	if(car.maritalstatus.value == ""){alert("please select your marital status");car.maritalstatus.focus();return(false);}//end if
	if(car.employment.value == ""){alert("please select your employment status");car.employment.focus();return(false);}//end if
	if(car.licencetype.value == ""){alert("please select your licence type");car.licencetype.focus();return(false);}//end if
	if(car.heldfor.value == ""){alert("how long have you had your licence for?");car.heldfor.focus();return(false);}//end if
	if(car.postcode.value == ""){alert("please enter your postcode");car.postcode.focus();return(false);}//end if
	if(car.housenum.value == ""){alert("please enter your house number");car.housenum.focus();return(false);}//end if
	if(car.streetaddress.value == ""){alert("please enter your street address");car.streetaddress.focus();return(false);}//end if
	if(car.tel.value == ""){alert("please enter your telephone number");car.tel.focus();return(false);}//end if
	if(car.regnum.value == ""){alert("please enter your registration number");car.regnum.focus();return(false);}//end if
	if(car.cover.value == ""){alert("please select your type of cover");car.cover.focus();return(false);}//end if
	if(car.claims.value == ""){alert("please select your claims bonus");car.claims.focus();return(false);}//end if
	if(car.numdrivers.value == ""){alert("please enter the amount of drivers");car.numdrivers.focus();return(false);}//end if
	if(car.vehicleuse.value == ""){alert("what do you use your vehicle for?");car.vehicleuse.focus();return(false);}//end if
	if(car.annualmileage.value == ""){alert("please select your annual mileage");car.annualmileage.focus();return(false);}//end if
	if(car.numvehiclehousehold.value == ""){alert("please enter the number of vehicles in your house hold");car.numvehiclehousehold.focus();return(false);}//end if
	if(car.vehicleovernight.value == ""){alert("where is the vehicle parked overnight?");car.vehicleovernight.focus();return(false);}//end if
	if(car.vehiclevalue.value == ""){alert("please enter the value of your vechile");car.vehiclevalue.focus();return(false);}//end if
	if(car.numseats.value == ""){alert("please enter the amount of seats");car.numseats.focus();return(false);}//end if
	if(car.registeredkeeper.value == ""){alert("who is the registered keeper?");car.registeredkeeper.focus();return(false);}//end if
	return(true);
}//end function
//************************************//
function check_search(frm_search){//form validation company formation search
	if(frm_search.companyname.value == ""){alert("please enter your company name");frm_search.companyname.focus();return(false);}//end if
	return(true);
}//end function
//************************************//
function Mod10(ccNumb){//v2.0
	var valid = "0123456789";//Valid digits in a credit card number
	var len = ccNumb.length;//The length of the submitted cc number
	var iCCN = parseInt(ccNumb);//integer of ccNumb
	var sCCN = ccNumb.toString();//string of ccNumb
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');//strip spaces
	var iTotal = 0;//integer total set at zero
	var bNum = true;//by default assume it is a number
	var bResult = false;//by default assume it is NOT a valid cc
	var temp;//temp variable for parsing string
	var calc;//used for calculation of each digit
	
	//Determine if the ccNumb is in fact all numbers
	for(var j=0; j<len; j++){
		temp = "" + sCCN.substring(j, j+1);
		if(valid.indexOf(temp) == "-1"){
			bNum = false;
		}//end if
	}//end for
	
	//if it is NOT a number, you can either alert to the fact, or just pass a failure
	if(!bNum){
		/*alert("Not a Number");*/
		bResult = false;
	}//end if
	
	//Determine if it is the proper length 
	if((len == 0)&&(bResult)){//nothing, field is blank AND passed above # check
		bResult = false;
	}else{//ccNumb is a number and the proper length - let's see if it is a valid card number
		if(len >= 15){//15 or 16 for Amex or V/MC
			for(var i=len;i>0;i--){//LOOP throught the digits of the card
				calc = parseInt(iCCN) % 10;//right most digit
				calc = parseInt(calc);//assure it is an integer
				iTotal += calc;//running total of the card number as we loop - Do Nothing to first digit
				i--;//decrement the count - move to the next digit in the card
				iCCN = iCCN / 10;//subtracts right most digit from ccNumb
				calc = parseInt(iCCN) % 10 ;//NEXT right most digit
				calc = calc *2;//multiply the digit by two
				
				//Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
				//I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
				switch(calc){
					case 10: calc = 1; break;//5*2=10 & 1+0 = 1
					case 12: calc = 3; break;//6*2=12 & 1+2 = 3
					case 14: calc = 5; break;//7*2=14 & 1+4 = 5
					case 16: calc = 7; break;//8*2=16 & 1+6 = 7
					case 18: calc = 9; break;//9*2=18 & 1+8 = 9
					default: calc = calc;//4*2= 8 & 8 = 8 -same for all lower numbers
				}//end switch
				iCCN = iCCN / 10;//subtracts right most digit from ccNum
				iTotal += calc;//running total of the card number as we loop
			}//end for
			if((iTotal%10)==0){//check to see if the sum Mod 10 is zero
				bResult = true;//This IS (or could be) a valid credit card number.
			}else{
				bResult = false;//This could NOT be a valid credit card number
			}//end if
		}//end if
	}//end if
	
	//change alert to on-page display or other indication as needed.
	if(bResult){
		//alert("This IS a valid Credit Card Number!");
	}//end if
	if(!bResult){
		alert("This is NOT a valid Card Number!");
		document.frm_hsbc.card_num2.focus();
	}//end if
	return bResult;//Return the results
}//end function
//------------------------------------//
function check_hsbc(frm_hsbc){//form validation hsbc direct payment details
	if(frm_hsbc.cname.value == ""){alert("please enter the name on your card");frm_hsbc.cname.focus();return(false);}//end if
	if(frm_hsbc.card_num2.value == ""){alert("please enter your card number");frm_hsbc.card_num2.focus();return(false);}//end if
	if(frm_hsbc.title.value == ""){alert("please select your title");frm_hsbc.title.focus();return(false);}//end if
	if(frm_hsbc.fname.value == ""){alert("please enter your first name");frm_hsbc.fname.focus();return(false);}//end if
	if(frm_hsbc.lname.value == ""){alert("please enter your last name");frm_hsbc.lname.focus();return(false);}//end if
	if(frm_hsbc.street1.value == ""){alert("please enter your street address");frm_hsbc.street1.focus();return(false);}//end if
	if(frm_hsbc.city.value == ""){alert("please enter your city/town");frm_hsbc.city.focus();return(false);}//end if
	if(frm_hsbc.state.value == ""){alert("please enter your state/county");frm_hsbc.state.focus();return(false);}//end if
	if(frm_hsbc.zip.value == ""){alert("please enter your postal code");frm_hsbc.zip.focus();return(false);}//end if
	if(frm_hsbc.country.value == ""){alert("please enter your country");frm_hsbc.country.focus();return(false);}//end if
	if(frm_hsbc.email.value.indexOf("@",0) == -1){alert("please enter a valid email address");frm_hsbc.email.focus();return(false);}//end if
	if(!frm_hsbc.terms.checked){alert("you need to accept the terms and conditions before you can continue");frm_hsbc.terms.focus();return(false);}//end if
	if(frm_hsbc.card_num2.value.indexOf("*",0) == 0){
	}else{
		if(frm_hsbc.card_num2.value == ""){alert("please enter your card number");frm_hsbc.card_num2.focus();return(false);}//end if
	}//end if
	return(true);
}//end function
//************************************//
function payment_select(that){//PAYMENT TYPE SELECT
	if(that.value=="Switch/Maestro" || that.value=="Solo"){
		document.getElementById('extra').style.display='block';
	}else{
		document.getElementById('extra').style.display='none';
	}//end if
}//end function
