﻿// QSearch form validation
function doFormQS()
{
	// get today's date
	var todayDate = 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 tDate = new Date(todayDate.getFullYear(),todayDate.getMonth(),todayDate.getDate());
		
	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("please choose a country in the destination list");
		document.details.area.focus();
		return false;

	// check for a pick up location
	} else if(document.details.tlocation.value == "") {
		alert("please choose a pick up location");
		document.details.tlocation.focus();
		return false;

	// check for a drop off location
	} else if(document.details.tdropoff.value == "") {
		alert("please choose a drop off location");
		document.details.tdropoff.focus();
		return false;

	// check if pickup is today
	} else if (pMonth == tMonth && pDay == tDay) {
		alert("please contact us at 078/15 25 35 in case of a rental starting today");
		return false;

	// check pickup date hasn't already passed
	} else if (pDate < tDate){
		alert("the pick up date has already passed, please re-enter");
		document.details.slFromMonth.focus();
		return false;

	// compare the 2 dates
	} else if(dDate < pDate) {
		alert("the drop off date you choosed is before pick up date, please re-enter");
		document.details.slFromMonth.focus();
		return false;		
		
	// check there is a driver age
	} else if(document.details.fiDriverAge.value == "") {
		alert("please enter a valid driver age. Driver between 21 and 65 can book online. \n For further information, please call 078/15 25 35");
		document.details.fiDriverAge.focus();
		return false;

	// check driver age is valid
	} else if(document.details.fiDriverAge.value < 21 || document.details.fiDriverAge.value > 65) {
		alert("please enter a valid driver age. Driver between 21 and 65 can book online. \n For further information, please call 078/15 25 35");
		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=BEL&lang=BEE";
	
	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 setDefYear (frm) {

    if (frm.defyearFrom.value) {

        frm.slFromYear[frm.defyearFrom.value].selected = true;

    }

    if (frm.defyearTo.value) {

        frm.slToYear[frm.defyearTo.value].selected = true;

    }

}

function setYear (ipt) {

     ipt.length = 0;

     var year = new Date ().getFullYear ();

     ipt[ipt.length] = new Option (year, year);

     ipt[ipt.length] = new Option (year+1, year+1);

     ipt[ipt.length] = new Option (year+2, year+2);

}

var months = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function doLeapYear (inY) {

    if ((inY % 400 == 0) || (inY % 4 == 0) && (!(inY % 100 == 0))) {

        months[1] = 29;

    } else {

        months[1] = 28;

    }

}

function setDays (ipt, mn, inY, slo) {

    var sl = 0;

    if (ipt.selectedIndex) {

        sl = ipt.selectedIndex;

    }

    doLeapYear (inY);

    ipt.length = 0;

    for (var i = 0; i < months[mn-1]; i++) {

        ipt[ipt.length] = new Option (i+1, i+1);

    }

    if (sl > (ipt.length-1)) {

        sl = (ipt.length-1);

    }

    if (slo) {

        ipt.options[0].selected = true;

    } else {

        ipt.options[sl].selected = true;

    }

}

function modDays () {

    with (document.details) {

        setDays (slFromDay, slFromMonth[slFromMonth.selectedIndex].value, slFromYear[slFromYear.selectedIndex].value);

        setDays (slToDay, slToMonth[slToMonth.selectedIndex].value, slToYear[slToYear.selectedIndex].value);

    }

}

function addDur () {

    modDays ();

    return;

}

function chnDur () {

    modDays ();

    return;

}




// menu javascript


isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("navig");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {this.className+=" over";}
node.onmouseout=function() {this.className=this.className.replace(" over", "");}
}}}}
SafeAddOnload(startList);

var gSafeOnload = new Array();
function SafeAddOnload(f){
  if (IEmac && IE4)	{window.onload = SafeOnload;gSafeOnload[gSafeOnload.length] = f;}
	else if (window.onload){
		if (window.onload != SafeOnload){gSafeOnload[0] = window.onload;window.onload = SafeOnload;}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else window.onload = f;
}





