// JavaScript Document

//	Changes the Price to include upgrades and extras
function changePricing(PickRegionID) {
	var carprice	= $('carprice').value;
	var cpi_req		= $('cpi_req').value;
	var cpi_gbp		= $('cpi_gbp').value;
	var sat_req		= $('sat_req').value;
	var sat_gbp		= $('sat_gbp').value;
	var ydp_req		= $('ydp_req').value;
	var ydp_gbp		= $('ydp_gbp').value;

	var url = '/_inc/pageElement_BookingStep3Pricing.php?carprice=' + carprice + '&cpi_req=' + cpi_req + '&cpi_gbp=' + cpi_gbp + '&sat_req=' + sat_req + '&sat_gbp=' + sat_gbp + '&ydp_req=' + ydp_req + '&ydp_gbp=' + ydp_gbp;

	new Ajax(url, {
		method: 'get',
		update: $('area_ShowPricing')
	}).request();
}

function checkBookingStep1() {
	if ($('regionID').value == 'none') {
		alert('Please select a Destination');
		return false;
	} else if ($('pickDate').value == '') {
		alert('Please enter the Date of Collection');
		return false;
	} else if ($('dropDate').value == '') {
		alert('Please enter the Date of Return');
		return false;
	} else {
		document.forms['BookingStep1'].submit();
	}
}

function checkBookingStep3() {
	if ($('drivers_initial').value == '') {
		alert('Please enter the Driver\'s Initial');
		return false;
	} else if ($('drivers_surname').value == '') {
		alert('Please enter the Driver\'s Surname');
		return false;
	} else if ($('telephone').value == '') {
		alert('Please enter your Telephone Number');
		return false;
	} else if ($('email_address').value == '') {
		alert('Please enter your Email Address');
		return false;
	} else {
		document.forms['BookingStep3'].submit();
	}
}

//	Converts a TR to a link using the href in 1 of the TDs
function ConvertRowsToLinks(xTableId){
	var rows = document.getElementById(xTableId).getElementsByTagName("tr");

	for(i=0;i<rows.length;i++){
		var link = rows[i].getElementsByTagName("a")
		if(link.length == 1){
			rows[i].onclick = new Function("document.location.href='" + link[0].href + "'");
			rows[i].onmouseover = new Function("this.className='highlight'");
			rows[i].onmouseout = new Function("this.className=''");
		}
	}
}

//	Gets the drop off offices for the selected region
function getDropOfficesFF(regionID,officeID) {
	var url = '/_inc/pageElement_BookingStep1OfficeFF.php?regionID=' + regionID + '&officeID=' + officeID;

	new Ajax(url, {
		method: 'get',
		update: $('dropOfficeID')
	}).request();
}

//	Gets the pick up offices for the selected region
function getPickOfficesFF(regionID,officeID) {
	var url = '/_inc/pageElement_BookingStep1OfficeFF.php?regionID=' + regionID + '&officeID=' + officeID;

	new Ajax(url, {
		method: 'get',
		update: $('pickOfficeID')
	}).request();
}

//	Gets the drop off offices for the selected region
function getDropOfficesIE(regionID,officeID) {
	var url = '/_inc/pageElement_BookingStep1OfficeIE.php?section=drop&regionID=' + regionID + '&officeID=' + officeID;

	new Ajax(url, {
		method: 'get',
		update: $('area_PickOffice')
	}).request();
}

//	Gets the pick up offices for the selected region
function getPickOfficesIE(regionID,officeID) {
	var url = '/_inc/pageElement_BookingStep1OfficeIE.php?section=pick&regionID=' + regionID + '&officeID=' + officeID;

	new Ajax(url, {
		method: 'get',
		update: $('area_DropOffice')
	}).request();
}