function checkPostcode(postcode, type){
		
		if(type == 1){
			//Inbound Postcode
			//alert("inward");
			inputIDText = "validInPostcode";
			imageVerdictText = "#verdict2";
			postcodeInputIDText = "inwardfrom";
		}
		else{
			//Outbound Postcode
			//alert("outward");
			inputIDText = "validOutPostcode";
			imageVerdictText = "#verdict1";
			postcodeInputIDText = "outwardfrom";
		}
		
		//postcode = postcode.replace(/\s/g,'-').replace(/[\W\-]/g,'').toLowerCase();
		//postcode = postcode.replace(/\s/g,'-').replace(/[^\w\-]/g,'').toLowerCase();
		//postcode = postcode.replace(/^\s+|\s+$/g,"-").toLowerCase();
		//postcode = postcode.replace(/\s+/g,'').toLowerCase();
		postcode = postcode.toUpperCase();
		//alert(postcode);
		var postcodelength = postcode.length;
		
		
		if(postcodelength < 6){
			if (postcode === ''){
				//alert('here');
				document.getElementById(inputIDText).value = 0;
			    $(imageVerdictText).attr('src','/images/red-cross-icon.png');
			    alert ('You must enter a postcode.');    
			}
			else{
				document.getElementById(inputIDText).value = 0;
			    $(imageVerdictText).attr('src','/images/red-cross-icon.png');
			    alert ('Invalid postcode. Please try again.'); 			
			}
		}
		else{
			var where_is_space_character = postcode.indexOf(' ');
			//alert('The a is at position '+where_is_space_character+'.');
			var checklength;
			
			if(where_is_space_character == -1){
				checklength = -1;
			}
			else if (where_is_space_character == 3){
				checklength = 7;
			}
			else{
				checklength = 8;
			}
			
			
			//alert(postcode);
			/*if (postcode === '' && postcodelength != 0){
				//alert('here');
				document.getElementById(inputIDText).value = 0;
			    $(imageVerdictText).attr('src','/images/red-cross-icon.png');
			    alert ('You must enter a postcode.');    
			}*/
			/*if(postcodelength < 8){
				document.getElementById(inputIDText).value = 0;
				$(imageVerdictText).attr('src','/images/red-cross-icon.png');
			}
			else {*/
				
				// bit of jQuery to get the data.
				
				$.get("/check-postcode.php?postcodestring="+postcode+"&type="+type, function(data) {					    
				    if(data == 'valid'){
					    $(imageVerdictText).attr('src','/images/green-tick-icon.png');
					    document.getElementById(inputIDText).value = 1;
					    document.getElementById(postcodeInputIDText).value = postcode;
					    
				    }else {
					    document.getElementById(inputIDText).value = 0;
					    $(imageVerdictText).attr('src','/images/red-cross-icon.png');
					    if(data == 'no_string'){
					    	errormsg = "No postcode string has been given";			    
					    }
					    else if(data == 'sql_error'){
					    	errormsg = "An error occurred checking the postcode. Contact us directly for a quote.";	
					    }
					    else if(data == 'exceeds'){
					    	errormsg = "The length of the given postcode exceeds the maximum of 8 characters. Please enter a valid postcode";	
					    }
					    else{ //inuse
					    	errormsg = "Sorry postcode was not found.\n\nPlease check that the postcode is valid and correctly entered (including a space character).\n\nIf you have entered a valid postcode then you need to call us as we may not operate in this area.";		
					    }
					    if(checklength == -1){
					    	alert("Please check that the postcode includes a space character");
					    }
					    else{
					    	if(postcodelength >= checklength){
					    		alert(errormsg);
					    	}
					   	}
				    }
				});
			//}
		
		}
}


function checkSlugSubmission(FormName){

	//var doc = document.forms[FormName];
	//alert(FormName);
	var value = document.getElementById("valslug").value;
	
	if(value == 1){
		document.forms[FormName].submit();
	}
	else{
		alert('Cannot submit the form as you have an invalid slug.\nPlease edit the slug field and create a valid slug.');
		return false;
	}


}


function changeJourneyType(FormName, listID){
	
	/*
	journeyType == 1 --> Return TO the airport
	journeyType == 2 --> Retrun FROM the airport
	journeyType == 3 --> Single TO the airport
	journeyType == 4 --> Single FROM the airport
	*/
	
	/* Outbound INPUTS */
	
	/*
	var valid_out_postcode = document.forms[FormName].valid_out_postcode.value;
	var outward_postcode = document.forms[FormName].outward_postcode.value;
	alert(valid_out_postcode);
	*/
	
	/*var selObj = document.getElementById(listID);
	
	var selIndex = selObj.selectedIndex;
	var txtIndexObj = selIndex;
	var txtValueObj = selObj.options[selIndex].value;
	var txtTextObj = selObj.options[selIndex].text;

	alert(txtValueObj);
	*/

}

function validate1(FormName, noticeInMilliseconds){
	
	/*
	journeyType == 1 --> Return TO the airport
	journeyType == 2 --> Retrun FROM the airport
	journeyType == 3 --> Single TO the airport
	journeyType == 4 --> Single FROM the airport
	*/
	//alert(noticeInMilliseconds);
	
	/*
	turned off time validation 22.07.10
	var notice_in_hours = noticeInMilliseconds / 1000 / 60 / 60;
	
	var adjustedDate = currentdate + noticeInMilliseconds;
	*/
	var currentdate = new Date().getTime();
	
	if(journeyType != 4){
		var outjourneydayselect = document.getElementById('journeyday');
		var selectedIndex = outjourneydayselect.selectedIndex;
		var outday = outjourneydayselect.options[selectedIndex].value;
		var outjourneymthselect = document.getElementById('journeymonth');
		var selectedIndex = outjourneymthselect.selectedIndex;
		var outmth = outjourneymthselect.options[selectedIndex].value;
		var outmth = outmth -1;
		var outjourneyyearselect = document.getElementById('journeyyear');
		var selectedIndex = outjourneyyearselect.selectedIndex;
		var outyr = outjourneyyearselect.options[selectedIndex].value;
		var outjourneyhourselect = document.getElementById('pickuphour');
		var selectedIndex = outjourneyhourselect.selectedIndex;
		var outhour = outjourneyhourselect.options[selectedIndex].value;
		var outjourneyminselect = document.getElementById('pickupminute');
		var selectedIndex = outjourneyminselect.selectedIndex;
		var outmin = outjourneyminselect.options[selectedIndex].value;
		
		var outdate = new Date(outyr, outmth, outday, outhour, outmin, 0, 0).getTime();
	}
	if(journeyType != 3){
		var injourneydayselect = document.getElementById('returnjourneyday');
		var selectedIndex = injourneydayselect.selectedIndex;
		var inday = injourneydayselect.options[selectedIndex].value;
		var injourneymthselect = document.getElementById('returnjourneymonth');
		var selectedIndex = injourneymthselect.selectedIndex;
		var inmth = injourneymthselect.options[selectedIndex].value;
		var inmth = inmth -1;
		var injourneyyearselect = document.getElementById('returnjourneyyear');
		var selectedIndex = injourneyyearselect.selectedIndex;
		var inyr = injourneyyearselect.options[selectedIndex].value;
		var injourneyhourselect = document.getElementById('returnpickuphour');
		var selectedIndex = injourneyhourselect.selectedIndex;
		var inhour = injourneyhourselect.options[selectedIndex].value;
		var injourneyminselect = document.getElementById('returnpickupminute');
		var selectedIndex = injourneyminselect.selectedIndex;
		var inmin = injourneyminselect.options[selectedIndex].value;
		
		var indate = new Date(inyr, inmth, inday, inhour, inmin, 0, 0).getTime();
	}
	//alert(outday+" "+outmth +" "+outyr+" "+outhour+" "+outmin);
	//alert("CUR DATE: "+currentdate+"\nADJ DATE: "+adjustedDate+"\nOUT DATE: "+outdate+"\nINN DATE: "+indate);
	/*var myDate=new Date();
	myDate.setFullYear(outyr,outmth,outday, outhour, outmin);
	var today = new Date();
	if (outdate < adjustedDate){
		alert("Outbound date is before our minimum notice period ");
	}
	else if (indate <= outdate){
		alert("Inbound date is the same as or before the Outbound date");
	}
	else {
		alert("Both dates are valid ");
	}*/
		
	var processform = true;
	var doc = document.forms[FormName];
	var valid_out_postcode = document.forms[FormName].valid_out_postcode.value;
	var valid_in_postcode = document.forms[FormName].valid_in_postcode.value;
	
	
	var selObj = document.getElementById('journeytype');
	var selIndex = selObj.selectedIndex;
	
	var journeyType = selObj.options[selIndex].value;

	
	//var txtTextObj = selObj.options[selIndex].text;
	//var txtIndexObj = selIndex;
	
	if(journeyType == 1){
		/*if (outdate < adjustedDate){
			alert("Outbound date is before our minimum notice period. Minimum notice period is "+notice_in_hours+" hours ");
			return false;
		}*/
		if (indate <= outdate){
			alert("Inbound date is the same as or before the Outbound date. Please check and amend your dates.");
			return false;
		}
		if(!validpostcodeValue("outward", valid_out_postcode)){
			//processform = false;
			return false;
		}
		
		if(!validpostcodeValue("inward", valid_in_postcode)){
			//processform = false;
			return false;
		}
				
	}
	else if(journeyType == 2){
		/*if (indate < adjustedDate){
			alert("Inbound date is before our minimum notice period. Minimum notice period is "+notice_in_hours+" hours");
			return false;
		}*/
		if (outdate <= indate){
			alert("Outbound date is the same as or before the Inbound date");
			return false;
		}
		if(!validpostcodeValue("inward", valid_in_postcode)){
			//processform = false;
			return false;
		}
		if(!validpostcodeValue("outward", valid_out_postcode)){
			//processform = false;
			return false;
		}
	}
	else if(journeyType == 3){
		if (outdate < currentdate){
			alert("Outbound date is in the past. Please select a date in the future. ");
			return false;
		}
		if(!validpostcodeValue("outward", valid_out_postcode)){
			//processform = false;
			return false;
		}
	}
	else{
		if (indate < currentdate){
			alert("Inbound date is in the past. Please select a date in the future. ");
			return false;
		}
		if(!validpostcodeValue("inward", valid_in_postcode)){
			//processform = false;
			return false;
		}
	}
	
	if(processform){
		doc.submit();
		//alert('processform');
	}
	
}

function validate2(FormName, journeytypeID, isOutAirport, isInAirport){
	
	var doc = document.forms[FormName];
	var bookingName = document.getElementById('bookingName').value;
	var contactTel = document.getElementById('contactTel').value;
	var bookedBy = document.getElementById('bookedBy').value;
	var contactEmail = document.getElementById('contactEmail').value;
	var confirmEmail = document.getElementById('confirmEmail').value;
	var numericExpression = /^[0-9]+$/;
	
			
	if(bookingName === ''){
		alert("Booking Name: Empty\n\nPlease enter the full name of the person the booking is for.");
		return false;
	}
	if(bookedBy === ''){
		alert("Booked By: Empty\n\nPlease enter the full name of the person who is making the booking.");
		return false;
	}
	if(contactTel === ''){
		alert("Contact Number: Empty\n\nPlease enter a contact telephone. We may need to contact you regarding your booking.");
		return false;
	}
	if(!contactTel.match(numericExpression)){
		alert("Contact Number: Only Numbers Allowed\n\nPlease only enter numbers for the contact telephone. Remove any space characters.");
		return false;
	}
	if(journeytypeID == 1){
		var contactTel2 = document.getElementById('contactTel2').value;
		if(contactTel2 === ''){
			alert("Mobile Contact Number: Empty\n\nPlease enter a mobile telephone you will be taking with you. We may need to contact you regarding your pick up.");
			return false;
		}
		if(!contactTel2.match(numericExpression)){
			alert("Mobile Contact Number: Only Numbers Allowed\n\nPlease only enter numbers for the mobile contact telephone. Remove any space characters.");
			return false;
		}
	}
	
	if(contactEmail == ""){
		alert("Email: Empty\n\nPlease enter an email address. We will need to email your booking confirmation.");
		return false;
	}
	if(contactEmail != ""){
		var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(!contactEmail.match(emailExp)){
			alert('Email: Invalid\n\nPlease check the email address supplied and check that it is a valid email address.');
			return false;
		}
	}
	if(contactEmail != confirmEmail){
		alert("Confirm Email: Not Matching\n\nThe supplied email addresses do not match. Please check both addresses and try again.");
		return false;
	}
	
	if(journeytypeID == 1 || journeytypeID == 2 || journeytypeID == 3 ){
		var pickUpAddress1 = document.getElementById('pickUpAddress1').value;
		var pickUpCity = document.getElementById('pickUpCity').value;
		
		var outward_house_no = document.getElementById('pickUpHouseNo').value;
		
		if(outward_house_no === ''){
			alert("Outbound Journey\n\nPick Up House No/Name: Empty\n\nPlease enter the house number or name of the address for the Outbound journey.");
			return false;
		}
		if(pickUpAddress1 === ''){
			alert("Outbound Journey\n\nPick Up Address line 1: Empty\n\nPlease enter the first line of the address for the Outbound journey.");
			return false;
		}
		if(pickUpCity === ''){
			alert("Outbound Journey\n\nPick Up City/Town: Empty\n\nPlease enter the town/city of the address for the Outbound journey.");
			return false;
		}
		/*if(isOutAirport == 1){
			var outwardFlightNo = document.getElementById('outwardFlightNo').value;
			if(outwardFlightNo === ''){
				alert("Departing Flight No.: Empty\n\nPlease enter the flight number for the Outbound journey.");
				return false;
			}
		}*/
		
	}
	if(journeytypeID == 1 || journeytypeID == 2 || journeytypeID == 4 ){
		var DropOffAddress1 = document.getElementById('DropOffAddress1').value;
		var DropOffCity = document.getElementById('DropOffCity').value;
		
		var inward_house_no = document.getElementById('DropOffHouseNo').value;
		
		if(inward_house_no === ''){
			alert("Inbound Journey\n\nDrop Off House No/Name: Empty\n\nPlease enter the house number or name of the address for the Inbound Journey.");
			return false;
		}
		if(DropOffAddress1 === ''){
			alert("Inbound Journey\n\nDrop Off Address line 1: Empty\n\nPlease enter the first line of the address for the Inbound Journey.");
			return false;
		}
		if(DropOffCity === ''){
			alert("Inbound Journey\n\nDrop Off City/Town: Empty\n\nPlease enter the town/city of the address for the Inbound Journey.");
			return false;
		}
		if(isInAirport == 1){
			var inwardFlightNo = document.getElementById('inwardFlightNo').value;
			if(inwardFlightNo === ''){
				alert("Arriving Flight No.: Empty\n\nPlease enter the flight number for the Inbound Journey.");
				return false;
			}
		}
	}
	
	myOption = -1;
	for (i = doc.paymentvalue.length-1; i > -1; i--) {
		if (doc.paymentvalue[i].checked) {
			myOption = i; i = -1;
		}
	}
	if (myOption == -1) {
		alert("You must select a a payment method");
		return false;
	}
	else{
		var payment_type = doc.paymentvalue[myOption].value;
		
		//PAY BY CARD - CHECK BILLING INFO 
		//if(payment_type == 1){ - add if statment back in if are hiding billing info for pay on day!
			var BillFirstName = document.getElementById('BillFirstName').value;
			var BillLastName = document.getElementById('BillLastName').value;
			var BillAddress1 = document.getElementById('BillAddress1').value;
			var BillCity = document.getElementById('BillCity').value;
			var BillPostal = document.getElementById('BillPostal').value;
			
			if(BillFirstName === ''){
				alert("Billing First Name: Empty\n\nPlease enter the First Name of the card holder who is making the payment.");
				return false;
			}
			if(BillLastName === ''){
				alert("Billing Surname Name: Empty\n\nPlease enter the Surname Name of the card holder who is making the payment.");
				return false;
			}
			if(BillAddress1 === ''){
				alert("Billing Address Line1: Empty\n\nPlease enter the First Line of the billing address to which the card is registered to. Please include the house number or name.");
				return false;
			}
			if(BillCity === ''){
				alert("Billing City/Town: Empty\n\nPlease enter the City/Town of the billing address to which the card is registered to. Please include the house number or name.");
				return false;
			}
			if(BillPostal === ''){
				alert("Billing Postcode: Empty\n\nPlease enter the Postcode of the billing address to which the card is registered to. Please include the house number or name.");
				return false;
			}		
		//}
	}
	
	if(document.getElementById('acceptTerms').checked != true){
		alert("Terms and Conditions: Not accepted.\n\nPlease read the terms and conditions and check the box to accept them.");
		return false;
	}
	else{
		doc.submit();
	}
	
	

}

function validpostcodeValue(type, value){

	if(value == 0){
		if(type == 'outward'){
			alert("Sorry, Outbound postcode is invalid please try again");
		}
		else{
			alert("Sorry, Inbound postcode is invalid please try again");	
		}
		//processform = false;
		return false;
	}
	else{
		return true;
	}

}


function updateQuote(payment_type){
			
	var base_quote = document.getElementById("baseQuote").value;
	
	var percentage_fee = document.getElementById("percentageFee").value;
	var adjust_percentage = percentage_fee / 100 + 1;
	
	var new_quote = base_quote * adjust_percentage;
	
	if(payment_type == 1){ // pay by card
		
		new_quote = new_quote.toFixed(2);
	}
	else{
		new_quote = base_quote;	
	}
	
	$('#mainquote').replaceWith('<div id=\"mainquote\"><h1>'+new_quote+'</h1></div>');
	
	if(payment_type == 1){
		$('#cardquote').replaceWith('<div id=\"cardquote\"><h2>&#163;'+new_quote+'</h2></div>');
		$('#nocardquote').replaceWith('<div id=\"nocardquote\"></div>');
		$('#confirm_button_text').replaceWith('<span id=\"confirm_button_text\">Make Payment</span>');
	}
	else{
		$('#cardquote').replaceWith('<div id=\"cardquote\"></div>');
		$('#nocardquote').replaceWith('<div id=\"nocardquote\"><h2>&#163;'+new_quote+'</h2></div>');
		$('#confirm_button_text').replaceWith('<span id=\"confirm_button_text\">Confirm Booking</span>');
	}
		
	//alert('fee = '+percentage_fee+' q = '+base_quote +' adj = '+adjust_percentage+' new q = '+new_quote.toFixed(2));
	
	//$('.second').replaceWith('<h2>New heading</h2>');


}

function changeFormElements(FormName, listID){
	
	var doc = document.forms[FormName];
	var selObj = document.getElementById('journeytype');
	var selIndex = selObj.selectedIndex;
	
	var journeyType = selObj.options[selIndex].value;
	//alert(journeyType);
	
	if(journeyType == 1){
		
	}
	else if(journeyType == 2){
	
	}
	else if(journeyType == 3){
	
	}
	else{
	
	}
	
}
