// QSearch form validation
function doFormQS()
{
	// get today's date
	var tDate = new Date();
	
	// build 2 dates from dropdowns
	var pDate = new Date(document.details.slFromYear.value,document.details.slFromMonth.value - 1,document.details.slFromDay.value);
	var dDate = new Date(document.details.slToYear.value,document.details.slToMonth.value - 1,document.details.slToDay.value);
		
	var tMonth = tDate.getMonth();
	var tDay = tDate.getDate();

	var pMonth = pDate.getMonth();
	var pDay = pDate.getDate();
	
	// check for a country
	if(document.details.area.value == "sel" || document.details.area.value == "none")
	{
		alert("merci de selectionnez un pays.");
		document.details.area.focus();
		return false;

	// check for a pick up location
	} else if(document.details.tlocation.value == "") {
		alert("merci de selectionner un lieu de prise.");
		document.details.tlocation.focus();
		return false;

	// check for a drop off location
	} else if(document.details.tdropoff.value == "") {
		alert("merci de selectionner un lieu de restitution.");
		document.details.tdropoff.focus();
		return false;

	// check if pickup is today
	// } else if (pMonth == tMonth && pDay == tDay) {
	// alert("la durée de location est de 1 jour minimum. Merci de modifier vos dates");
	// return false;

	// check pickup date hasn't already passed
	} else if (pDate < tDate){
		alert("la date de prise du vehicule est déja passée. Merci de modifier vos dates.");
		document.details.slFromMonth.focus();
		return false;

	// compare the 2 dates
	} else if(dDate < pDate) {
		alert("la date de retour est antérieure à la date de prise du véhicule. Merci de modifier vos dates");
		document.details.slFromMonth.focus();
		return false;		
		
	// check there is a driver age
	} else if(document.details.fiDriverAge.value == "") {
		alert("merci de saisir l'âge du conducteur");
		document.details.fiDriverAge.focus();
		return false;

	// check driver age is valid
	//} else if(document.details.fiDriverAge.value < 21 || document.details.fiDriverAge.value > 70) {
	//	alert("merci de saisir l'âge du conducteur. si vous avez moins de 21 ans ou plus de 70 ans, merci de nous contacter.");
	//	document.details.fiDriverAge.focus();
	//	return false;

	}
}

// get a variable from the querystring
function getQueryVariable(variable)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i < vars.length; i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{
			return pair[1];
		}
	} 
}

// deeplink into carlist.w
function carlistLink(area,loc) {
	// get area & location
	var area = area;
	var location = loc;

	if(getQueryVariable("aff"))
	{
		var affcode = getQueryVariable("aff");
	} else {
		var affcode = "";
	}
	
	// get pick up dates
	var fDate = document.details.slFromDay.value;
	var fMonth = document.details.slFromMonth.value;
	if(fMonth < 10)
	{
		fMonth = "0" + fMonth;
	}
	var fYear = document.details.slFromYear.value;
	var fTime = document.details.slFromTime.value;
	fTimeNew = new String(fTime);
	fTimeNew.replace(":","%3A");
	
	// get drop off dates
	var tDate = document.details.slToDay.value;
	var tMonth = document.details.slToMonth.value;
	if(tMonth < 10)
	{
		tMonth = "0" + tMonth;
	}
	var tYear = document.details.slToYear.value;
	var tTime = document.details.slToTime.value;
	tTimeNew = new String(tTime);
	tTimeNew.replace(":","%3A");

	var baseURL = "/cgi-bin/liveweb.sh/carlist.w?UckUcZllaaIpkkac=&POlfigXkjkjkWbdq=&SblzdbFStskKccak=&ctryref=FRA&lang=FR";
	
	var action = baseURL + "&aff=" + affcode + 
						"&selFromTime=" + fTimeNew + 
						"&slFromDay=" + fDate + 
						"&slFromMonth=" + fMonth + 
						"&slFromYear=" + fYear + 
						"&selToTime=" + tTimeNew + 
						"&slToDay=" + tDate +
						"&slToMonth=" + tMonth + 
						"&slToYear=" + tYear + 
						"&area=" + area + 
						"&tlocation=" + location + 
						"&tdropoff=" + location + 
						"&fidriverage=26";

	window.location = action;
}

// chnDur and addDur to get rid of js errors
function chnDur() { }
function addDur() { }

//....................... script divers pour le site .......................
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// supprimer les erreurs
//function errorsuppressor(){
//return true
//}
//window.onerror=errorsuppressor
