// JavaScript Document
function doFormQS()
{
	if(document.getElementById('car').style.display == "block")
	{
		if(checkForm() && checkDate())
		{
			return true;
		} else {
			return false;
		}
	}
	SearchWithShowHide()
	return true;
}

function checkForm()
{
	

	if(document.ProductForm.CmbCountry.value == "" )
	{
		alert("Please select a specific destination from the country dropdown list.");
		document.ProductForm.CmbCountry.focus();
		return false;

	// check a pick up location has been selected
	} else if(document.ProductForm.CmbLocationPick.value == "") {
		alert("Please select a pick-up location.");
		document.ProductForm.CmbLocationPick.focus();
		return false;

	// check a drop off location has been selected
	} else if(document.ProductForm.CmbLocationDrop.value == "") {
		alert("Please select a drop-off location.");
		document.ProductForm.CmbLocationDrop.focus();
		return false;
	}
	else if(document.ProductForm.slFromDay.value == "" || document.ProductForm.slFromDay.value == "" || document.ProductForm.slFromDay.value == "") {
		alert("Please select pick-up date.");
		document.ProductForm.slFromDay.focus();
		return false;
	}
	else if(document.ProductForm.slToDay.value == "" || document.ProductForm.slToDay.value == "" || document.ProductForm.slToDay.value == "") {
		alert("Please select drop-off date.");
		document.ProductForm.slToDay.focus();
		return false;
	}
	return true;
}

function checkDate()
{
	/* get selected values */	
	var pDate = document.ProductForm.slFromDay.value;
	var pMonth = document.ProductForm.slFromMonth.value;
	var pYear = document.ProductForm.slFromYear.value;
	
	var dDate = document.ProductForm.slToDay.value;
	var dMonth = document.ProductForm.slToMonth.value;
	var dYear = document.ProductForm.slToYear.value;
	
	/* check pick up date exists */
	if(((pMonth == "4" || pMonth == "6" || pMonth == "9" || pMonth == "11") && pDate == "31") || ((pMonth == "2") && (pDate == "29" || pDate == "30" || pDate == "31")))
	{
		alert("You have selected an invalid pick-up date. Please reselect.");
		document.ProductForm.slToMonth.focus();
		return false;
	}

	/* check drop off date exists */
	if(((dMonth == "4" || dMonth == "6" || dMonth == "9" || dMonth == "11") && dDate == "31") || ((dMonth == "2") && (dDate == "29" || dDate == "30" || dDate == "31")))
	{
		alert("You have selected an invalid drop-off date. Please reselect.");
		document.ProductForm.slToMonth.focus();
		return false;
	}
	
	/* build date objects */
	var pDateValid = new Date(pYear,pMonth - 1,pDate);
	var dDateValid = new Date(dYear,dMonth - 1,dDate);

	/* get today's date */
	var tDate = new Date();
	
	/* is pick up today? */
	if((pDateValid.getDate() == tDate.getDate()) && (pDateValid.getMonth() == tDate.getMonth()))
	{
		alert("We are unable to make online bookings for same day pick-up, but we may be able to help you.\nPlease call our call centre on 1300 554 432 or 02 9939 4433");
		document.ProductForm.slFromMonth.focus();
		return false;

	} else if(pDateValid < tDate) {
		alert("The pick-up date you have selected has already passed. Please reselect");
		document.ProductForm.slFromMonth.focus();
		return false;

	} else if(dDateValid < pDateValid) {
		alert("The drop-off date you have selected is before your pick-up date. Please reselect");
		document.ProductForm.slFromMonth.focus();
		return false;
	}
	return true;
}


function change_option(type)
	{
		if (type == 'e')
		{
			document.getElementById("e_tr").style.display = "block";
			document.getElementById("f_tr").style.display = "none";		
		}
		else if (type == 'f')
		{
			document.getElementById("e_tr").style.display = "none";		
			document.getElementById("f_tr").style.display = "block";
		}
	}
	function changecombo(d_type)
	{
		if (d_type == "depart")
		{
			if (document.frm.TxtDepartDate.value != "")
			{
				var a=document.frm.TxtDepartDate.value.split("/");
				document.frm.CmbDepartMonth.value = parseFloat(a[0]);
				document.frm.CmbDepartDay.value =parseFloat(a[1]);
				document.frm.TxtDepartYear.value =parseFloat(a[2]);
			}
		}
		else if (d_type == "return")
		{
			if (document.frm.TxtReturnDate.value != "")
			{
				var a=document.frm.TxtReturnDate.value.split("/");
				document.frm.CmbReturnMonth.value = parseFloat(a[0]);
				document.frm.CmbReturnDay.value =parseFloat(a[1]);
				document.frm.TxtReturnYear.value =parseFloat(a[2]);
			}
		}
	}
	
	function changecombo_car(d_type)
	{
		if (d_type == "pickup")
		{
			if (document.ProductForm.TxtPickupDate.value != "")
			{
				var a=document.ProductForm.TxtPickupDate.value.split("/");
				document.ProductForm.CmbPickupMonth.value = parseFloat(a[0]);
				document.ProductForm.CmbPickupDay.value =parseFloat(a[1]);
				document.ProductForm.TxtPickupYear.value =parseFloat(a[2]);
			}
		}
		else if (d_type == "dropoff")
		{
			if (document.ProductForm.TxtDropoffDate.value != "")
			{
				var a=document.ProductForm.TxtDropoffDate.value.split("/");
				document.ProductForm.CmbDropoffMonth.value = parseFloat(a[0]);
				document.ProductForm.CmbDropoffDay.value =parseFloat(a[1]);
				document.ProductForm.TxtDropoffYear.value =parseFloat(a[2]);
			}
		}
	}


	function changecombo_hotel(d_type)
	{
		if (d_type == "in")
		{
			if (document.ProductForm.TxtInDate.value != "")
			{
				var a=document.ProductForm.TxtInDate.value.split("/");
				document.ProductForm.CmbInMonth.value = parseFloat(a[0]);
				document.ProductForm.CmbInDay.value =parseFloat(a[1]);
				document.ProductForm.TxtInYear.value =parseFloat(a[2]);
			}
		}
		else if (d_type == "out")
		{
			if (document.ProductForm.TxtOutDate.value != "")
			{
				var a=document.ProductForm.TxtOutDate.value.split("/");
				document.ProductForm.CmbOutMonth.value = parseFloat(a[0]);
				document.ProductForm.CmbOutDay.value =parseFloat(a[1]);
				document.ProductForm.TxtOutYear.value =parseFloat(a[2]);
			}
		}
	}
