﻿// 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("Merci de choisir un pays");
		document.details.area.focus();
		return false;

	// check for a pick up location
	} else if(document.details.tlocation.value == "") {
		alert("Merci de choisir une ville de d\351part");
		document.details.tlocation.focus();
		return false;

	// check for a drop off location
	} else if(document.details.tdropoff.value == "") {
		alert("Merci de choisir une ville d arriv\351e");
		document.details.tdropoff.focus();
		return false;

	// check if pickup is today
	} else if (pMonth == tMonth && pDay == tDay) {
		alert("Si vous voulez louer une voiture aujourd hui, veuillez nous appeller au ? ");
		return false;

	// check pickup date hasn't already passed
	} else if (pDate < tDate){
		alert("La date que vous avez spécifié est déjà passée merci de saisir une date valide.");
		document.details.slFromMonth.focus();
		return false;

	// compare the 2 dates
	} else if(dDate < pDate) {
		alert("La date de retour de votre véhicule est antérieure à la date de prise de votre véhicule, merci de saisir une date valide");
		document.details.slFromMonth.focus();
		return false;		
		
	// check there is a driver age
	} else if(document.details.fiDriverAge.value == "") {
		alert("Si vous avez 21 ans ou plus de 65 ans, merci de contacter nos agents de voyages au ?");
		document.details.fiDriverAge.focus();
		return false;

	// check driver age is valid
	} else if(document.details.fiDriverAge.value < 21 || document.details.fiDriverAge.value > 70) {
		alert("Si vous avez 21 ans ou plus de 65 ans, merci de contacter nos agents de voyages au ?");
		document.details.fiDriverAge.focus();
		return false;

	} else if(document.details.fldDropoffYear.value==document.details.fldPickupYear.value && document.details.fldDropoffMonth.value==document.details.fldPickupMonth.value&& document.details.fldDropoffDay.value==document.details.fldPickupDay.value && document.details.fldDropoffTime.value==document.details.fldPickupTime.value) {
		alert("Vos dates de depart et darrivee sont au meme moment, merci de les modifier.");
		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];
		}
	} 
}



// 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 addDur () {
    modDays ();
   
var mydate1=new Date(document.details.fldPickupYear.value, (document.details.fldPickupMonth.value-1), document.details.fldPickupDay.value);
var unix_mydate1=mydate1.getTime();
var unix_mydate2=unix_mydate1+3600*1000*24*7;
var mydate2=new Date(unix_mydate2);


var day=(mydate2.getDate());
var month=(mydate2.getMonth());
var year=(mydate2.getFullYear());

document.details.fldDropoffYear.value=year;
document.details.fldDropoffMonth.value=(month+1);
document.details.fldDropoffDay.value=day; 
    modDays ();

return;
}



function chnDur () {

    modDays ();

    return;

}


// MOUSE OVER javascript

var offsetfrommouse=[-75,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 20;	// maximum image size.
if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}
function gettrailobj(){
if (document.getElementById)
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}
function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimagid
}
function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function showtrail(text){
	height=20;
	if (height > 0){
		currentimageheight = height;
	}
	document.onmousemove=followmouse;
	cameraHTML = '';
	
	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #6db337; width:150px;">';
	newHTML = newHTML + '<span class="largetitle">' + text + '</span>';
	
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible";
}
function hidetrail(){
	gettrailobj().visibility="hidden"
	document.onmousemove=""
	gettrailobj().left="-500px"
}
function followmouse(e){
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
	//if (document.all){
	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 300){
			xcoord = e.pageX - xcoord - 56; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		//if (docheight - e.pageY < (currentimageheight + 110)){
			//ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		//} else {
			ycoord += e.pageY;
		//}
	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 300){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

