// ------------ VALIDATE OPEN AN ACCOUNT FORM ---------//

function validateBooking(){

	var name		=	document.bookingform.name.value;
	var strPhone	=	document.bookingform.tel.value;
	var strEmail	=	document.bookingform.email.value;
	var car			=	document.bookingform.car.value;
	var pass		=	document.bookingform.passengers.value;
	var lugg		=	document.bookingform.luggage.value;
	var date		=	document.bookingform.pickupdate.value;
	var hours		=	document.bookingform.hours.value;
	var mins		=	document.bookingform.mins.value;
	var pickup		=	document.bookingform.pickup.value;
	var dest 		=	document.bookingform.destination.value;

  	var valid = true;


	if(name==''){
		alert('Please enter your name');
		document.bookingform.name.focus();
		valid = false;
		return false;
	}

	if(strPhone==''){
		alert('Please enter your contact telephone number');
		document.bookingform.tel.focus();
		valid = false;
		return false;
	}

	if(!strPhone==''){
		var validChars = "1234567890() "
		for(var Idx=0; Idx<strPhone.length; Idx++) 
		{ 
			var Char = strPhone.charAt(Idx); 
			var Match = false; 
	
			for(var Idx1=0; Idx1<validChars.length; Idx1++) 
			{ 
				if(Char == validChars.charAt (Idx1)) 
					Match = true; 
			} 
			if (!Match) {
				alert("Please enter a valid phone number (only digits, brackets and spaces are allowed)");
				document.bookingform.tel.focus(); 
				valid = false;
				return false; 
				}
		} 
	}
	

  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.bookingform.email.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address"); document.bookingform.email.focus(); 
		valid = false;
		return false;
	}


	 if(!(document.bookingform.car[0].checked || document.bookingform.car[1].checked || document.bookingform.car[2].checked )){
		alert("Please select which type of car you require");
		valid = false;
		return false;
	}
	
	if(pass==''){
		alert('Please select the number of passengers');
		document.bookingform.passengers.focus();
		valid = false;
		return false;
	}
	if(lugg==''){
		alert('Please select the number of large pieces of luggage');
		document.bookingform.luggage.focus();
		valid = false;
		return false;
	}		
	
	if(date==''){
		alert('Please select a pick up date');
		document.bookingform.pickupdate.focus();
		valid = false;
		return false;
	}
	if(!date==''){	
		var cbdateArray 	=	new Array();	
		cbdateArray			=	document.bookingform.pickupdate.value.split("/");
		var now = new Date();
		var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());
		var date = new Date(cbdateArray[2],cbdateArray[1]-1,cbdateArray[0]);
		if(date < today){
			alert('Please select a date in the future');
			valid = false;
			return false;		
		}
	}
	if(hours==''){
		alert('Please select the time in hours to pick you up');
		document.bookingform.hours.focus();
		valid = false;
		return false;
	}
	if(mins==''){
		alert('Please select the time in minutes to pick you up');
		document.bookingform.mins.focus();
		valid = false;
		return false;
	}	
	
	if(pickup==''){
		alert('Please enter the pick up address');
		document.bookingform.pickup.focus();
		valid = false;
		return false;
	}	
	
	if(dest==''){
		alert('Please enter your destination');
		document.bookingform.destination.focus();
		valid = false;
		return false;
	}

	if(document.bookingform.accept.checked) 
		{
		valid = true
		}
	else {
	        alert('Please tick the box to confirm you have read and accept the A&H Terms of service.');
                valid = false ;
		return false;
	}

  	if (valid) return true;
	else return false;
}


function validateOpenAccount(){

	var accounttype		=	document.openaccount.accounttype.value;
	var address			=	document.openaccount.address.value;
	var orgname			=	document.openaccount.orgname.value;
	var strPhone		=	document.openaccount.tel.value;
	var strEmail		=	document.openaccount.email.value;
	var name			=	document.openaccount.name.value;
	var expenditure		=	document.openaccount.expenditure.value;
	var bankname		=	document.openaccount.bankname.value;
	var bankaddress		=	document.openaccount.bankaddress.value;
	var branchtel		=	document.openaccount.branchtel.value;
	var bankaccountname	=	document.openaccount.bankaccountname.value;
	var bankaccountno	=	document.openaccount.bankaccountno.value;
	var sortcode		=	document.openaccount.sortcode.value;
	var ref1 			=	document.openaccount.ref1.value;
	var ref2			=	document.openaccount.ref2.value;

  	var valid = true;

	if(accounttype==''){
		alert('Please select the account type you require');
		document.openaccount.accounttype.focus();
		valid = false;
		return false;
	}

	if(address==''){
		alert('Please enter the trading address');
		document.openaccount.address.focus();
		valid = false;
		return false;
	}
	
	if(orgname==''){
		alert('Please enter the name of your organisation');
		document.openaccount.orgname.focus();
		valid = false;
		return false;
	}

	if(strPhone==''){
		alert('Please enter a contact telephone number');
		document.openaccount.tel.focus();
		valid = false;
		return false;
	}

	if(!strPhone==''){
		var validChars = "1234567890() "
		for(var Idx=0; Idx<strPhone.length; Idx++) 
		{ 
			var Char = strPhone.charAt(Idx); 
			var Match = false; 
	
			for(var Idx1=0; Idx1<validChars.length; Idx1++) 
			{ 
				if(Char == validChars.charAt (Idx1)) 
					Match = true; 
			} 
			if (!Match) {
				alert("Please enter a valid phone number (only digits, brackets and spaces are allowed)");
				document.openaccount.tel.focus(); 
				valid = false;
				return false; 
				}
		} 
	}
	

  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.openaccount.email.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address"); document.openaccount.email.focus(); 
		valid = false;
		return false;
	}


	if(expenditure==''){
		alert('Please select your expected monthly expenditure');
		document.openaccount.expenditure.focus();
		valid = false;
		return false;
	}
	if(name==''){
		alert('Please enter a contact name');
		document.openaccount.name.focus();
		valid = false;
		return false;
	}		
	
	if(bankname==''){
		alert('Please enter the name of your bank');
		document.openaccount.bankname.focus();
		valid = false;
		return false;
	}
	if(bankaddress==''){
		alert('Please enter the address of your bank');
		document.openaccount.bankaddress.focus();
		valid = false;
		return false;
	}
	if(branchtel==''){
		alert('Please enter the telephone number of the branch of your bank');
		document.openaccount.branchtel.focus();
		valid = false;
		return false;
	}
	if(!branchtel==''){
		var validChars = "1234567890() "
		for(var Idx=0; Idx<branchtel.length; Idx++) 
		{ 
			var Char = branchtel.charAt(Idx); 
			var Match = false; 
	
			for(var Idx1=0; Idx1<validChars.length; Idx1++) 
			{ 
				if(Char == validChars.charAt (Idx1)) 
					Match = true; 
			} 
			if (!Match) {
				alert("Please enter a valid branch phone number (only digits, brackets and spaces are allowed)");
				document.openaccount.branchtel.focus(); 
				valid = false;
				return false; 
				}
		} 
	}	
	if(bankaccountname==''){
		alert('Please enter the bank account name');
		document.openaccount.bankaccountname.focus();
		valid = false;
		return false;
	}
	if(bankaccountno==''){
		alert('Please enter the bank account number');
		document.openaccount.bankaccountno.focus();
		valid = false;
		return false;
	}
	if(sortcode==''){
		alert('Please enter the sort code of your bank');
		document.openaccount.sortcode.focus();
		valid = false;
		return false;
	}	
	
	if(ref1==''){
		alert('Please enter the first trade reference');
		document.openaccount.ref1.focus();
		valid = false;
		return false;
	}	
	if(ref2==''){
		alert('Please enter the second trade reference');
		document.openaccount.ref2.focus();
		valid = false;
		return false;
	}	
	
	if(document.openaccount.accept.checked) 
		{
		valid = true
		}
	else {
	        alert('Please tick the box to confirm you have read and accept the A&H Terms of service.');
                valid = false ;
		return false;
	}

  	if (valid) return true;
	else return false;
}





// ------------ VALIDATE CONTACT FORM ---------//

function validateContact(){

	var strFirstName	=	document.contact.firstname.value;
	var strLastName		=	document.contact.lastname.value;
	var strEmail		=	document.contact.email.value;
	var strCountryCode	=	document.contact.countrycode.value;
	var strPhone		=	document.contact.phone.value;

  	var valid = true;

	if(strFirstName==''){
		alert('Please enter your first name');
		document.contact.firstname.focus();
		valid = false;
		return false;
	}
	if(strLastName==''){
		alert('Please enter your last name');
		document.contact.lastname.focus();
		valid = false;
		return false;
	}

	if(strCountryCode==''){
		alert('Please select the country code for your phone number');
		document.contact.countrycode.focus();
		valid = false;
		return false;
	}
	if(strPhone==''){
		alert('Please enter your phone number');
		document.contact.phone.focus();
		valid = false;
		return false;
	}

	if(!strPhone==''){
		var validChars = "1234567890() "
		for(var Idx=0; Idx<strPhone.length; Idx++) 
		{ 
			var Char = strPhone.charAt(Idx); 
			var Match = false; 
	
			for(var Idx1=0; Idx1<validChars.length; Idx1++) 
			{ 
				if(Char == validChars.charAt (Idx1)) 
					Match = true; 
			} 
			if (!Match) {
				alert("Please enter a valid phone number (only digits, brackets and spaces are allowed)");
				document.contact.phone.focus(); 
				valid = false;
				return false; 
				}
		} 
	}

 	var strEmail = document.contact.email.value;
  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.contact.email.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address"); document.contact.email.focus(); 
		valid = false;
		return false;
	}

  	if (valid) return true;
	else return false;
}



// ------------ VALIDATE HOMEPAGE Quick Quote Calculator Form - POINT 2 POINT ---------//

function validateQQCP2P(){

	var strpickup		=	document.calcform.pickup.value;
	var strdest		=	document.calcform.dest.value;

  	var valid = true;

	if(strpickup==''){
		alert('Please select a pickup point');
		document.calcform.pickup.focus();
		valid = false;
		return false;
	}
	if(strdest==''){
		alert('Please select a destination');
		document.calcform.dest.focus();
		valid = false;
		return false;
	}
	
	 if(!(document.calcform.car[0].checked || document.calcform.car[1].checked || document.calcform.car[2].checked )){
		alert("Please select which type of car you require");
		valid = false;
		return false;
	}
	
  	if (valid) return true;
	else return false;
}

// ------------ VALIDATE HOMEPAGE Quick Quote Calculator Form - HOURLY ---------//

function validateQQCH(){

	var strhours	=	document.calcform.hourly_option.value;

  	var valid = true;

	if(strhours==''){
		alert('Please select the number of hours, days or weeks required.');
		document.calcform.hourly_option.focus();
		valid = false;
		return false;
	}
	
	 if(!(document.calcform.car[0].checked || document.calcform.car[1].checked || document.calcform.car[2].checked )){
		alert("Please select which type of car you require");
		valid = false;
		return false;
	}
	
  	if (valid) return true;
	else return false;
}



function validateOnlineBooking(){

	var name		=	document.bookingform.name.value;
	var strPhone	=	document.bookingform.tel.value;
	var strEmail	=	document.bookingform.email.value;
	var car			=	document.bookingform.car.value;
	var pass		=	document.bookingform.passengers.value;
	var lugg		=	document.bookingform.luggage.value;
	var date		=	document.bookingform.pickupdate.value;
	var hours		=	document.bookingform.hours.value;
	var mins		=	document.bookingform.mins.value;
	var pickup		=	document.bookingform.pickup.value;
	var dest 		=	document.bookingform.destination.value;

  	var valid = true;

	if(pass==''){
		alert('Please select the number of passengers');
		document.bookingform.passengers.focus();
		valid = false;
		return false;
	}
	if(lugg==''){
		alert('Please select the number of large pieces of luggage');
		document.bookingform.luggage.focus();
		valid = false;
		return false;
	}		
	
	if(date==''){
		alert('Please select a pick up date');
		document.bookingform.pickupdate.focus();
		valid = false;
		return false;
	}
	if(!date==''){	
		var cbdateArray 	=	new Array();	
		cbdateArray			=	document.bookingform.pickupdate.value.split("/");
		var now = new Date();
		var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());
		var date = new Date(cbdateArray[2],cbdateArray[1]-1,cbdateArray[0]);
		if(date < today){
			alert('Please select a date in the future');
			valid = false;
			return false;		
		}
	}
	if(hours==''){
		alert('Please select the time in hours to pick you up');
		document.bookingform.hours.focus();
		valid = false;
		return false;
	}
	if(mins==''){
		alert('Please select the time in minutes to pick you up');
		document.bookingform.mins.focus();
		valid = false;
		return false;
	}	
	
	if(pickup==''){
		alert('Please enter the pick up address');
		document.bookingform.pickup.focus();
		valid = false;
		return false;
	}	
	
	if(dest==''){
		alert('Please enter your destination');
		document.bookingform.destination.focus();
		valid = false;
		return false;
	}



	if(name==''){
		alert('Please enter your name');
		document.bookingform.name.focus();
		valid = false;
		return false;
	}

	if(strPhone==''){
		alert('Please enter your contact telephone number');
		document.bookingform.tel.focus();
		valid = false;
		return false;
	}

	if(!strPhone==''){
		var validChars = "1234567890() "
		for(var Idx=0; Idx<strPhone.length; Idx++) 
		{ 
			var Char = strPhone.charAt(Idx); 
			var Match = false; 
	
			for(var Idx1=0; Idx1<validChars.length; Idx1++) 
			{ 
				if(Char == validChars.charAt (Idx1)) 
					Match = true; 
			} 
			if (!Match) {
				alert("Please enter a valid phone number (only digits, brackets and spaces are allowed)");
				document.bookingform.tel.focus(); 
				valid = false;
				return false; 
				}
		} 
	}
	

  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.bookingform.email.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address"); document.bookingform.email.focus(); 
		valid = false;
		return false;
	}



	if(document.bookingform.accept.checked) 
		{
		valid = true
		}
	else {
	        alert('Please tick the box to confirm you have read and accept the A&H Terms of service.');
                valid = false ;
		return false;
	}

  	if (valid) return true;
	else return false;
}





