
function setParameters() {
	setFormDate();
	//i see in url for params
	/*
	locale=EN  (it always be this language)
	IATA
	RENTALCNTRY=BE     /   DE     /    ES   /    FR   /   GB   /   IT   / PT
	STATIONCO=XXXXX (cf. from the list) optional
	*/
	params=top.location.search.substring(1).split("&")
	//array with params
	theValors=new Array()
	for (j=0; j < params.length;j++){
		theValors[params[j].split("=")[0]]=params[j].split("=")[1]
	}
	//set or preselect values
	document.sendForm.locale.value="en"			//theValors["locale"]
	if (theValors["IATA"]) document.sendForm.IATA.value=theValors["IATA"]
	document.sendForm.RENTALCNTRY.value=theValors["RENTALCNTRY"]
	if (theValors["STATIONCO"])   {
		document.sendForm.STATIONCO.value=document.sendForm.STATIONCI.value=theValors["STATIONCO"]
		//select in list dest
		var selectItem = document.destform.dest;

		for(i=0;i<selectItem.length;i++) {
			opt = selectItem.options[i];
			if(opt.value==theValors["STATIONCO"]) {
		         opt.selected = true;
		         break;
		    }
		 }
	}
	//Preselect destination with the navigator language
	if (navigator.appName == 'Netscape') language = navigator.language.toUpperCase();
		else language = navigator.browserLanguage.toUpperCase();
		 if(language!=null) {
	         if(language.indexOf("-")!=-1) country = language.substr(3,2);
	         else country = language.substr(0,2);
		 }
	if(country=="US") country = "GB";
	if(country=="EN") country = "GB";
	var selectItem = document.destform.CNTRY;

		for(i=0;i<selectItem.length;i++) {
			opt = selectItem.options[i];
			if(opt.value==country) {
		         opt.selected = true;
		         break;
		    }
		 }
}

var largeurEcran = (screen.availWidth-700)/2
var hauteurEcran = screen.availHeight/10
var nempop=0;
var LocalCountry=false;

function sesame(page,larg,haut,scraul)
{

	var posXpop = (screen.availWidth-larg)/2
	var posYpop = (screen.availHeight-haut)/2
	param = "width="+larg+",height="+haut+",left="+posXpop+",top="+posYpop+",status=1,scrollbars="+scraul
	popup = window.open(page,"pop",param)
}
var theRental=new Array()



theRental["US"]="US"
theRental["BE"]="BE"
theRental["JP"]="JP"
theRental["CA"]="CA"
theRental["DA"]="DA"
theRental["DK"]="DK"
theRental["FR"]="FR"
theRental["DE"]="DE"
theRental["GB"]="GB"
theRental["IT"]="IT"
theRental["IE"]="IE"
theRental["NL"]="NL"
theRental["PT"]="PT"
theRental["ES"]="ES"
theRental["SE"]="SE"
theRental["CH"]="CH"


function getRental(d){
	return theRental[d]
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function setda(){

	var now = new Date();
	var laps = Date.UTC(y2k(now.getYear()),(now.getMonth()),(now.getDate() + 2),0,0,0);
 	var now = new Date(Date.UTC(y2k(now.getYear()),(now.getMonth()),(now.getDate() + 1),0,0,0));
	var retour = new Date(laps);
	var param = "";
	var tmp;

	if(now.getDate() > 9 ) tmp = now.getDate();
	else tmp = "0" + (now.getDate());
    param += '&DATECO.day=' + tmp;

    if(retour.getDate() > 9 ) tmp = retour.getDate();
	else tmp = "0" + (retour.getDate());
	param += '&DATECI.day=' + tmp;

    if(now.getMonth() > 8 ) tmp = now.getMonth() + 1;
	else tmp = "0" + (now.getMonth() + 1);
	param += '&DATECO.month=' + tmp;

    if(retour.getMonth() > 8 ) tmp = retour.getMonth() + 1;
	else tmp = "0" + (retour.getMonth() + 1);
	param += '&DATECI.month=' + tmp;
	param += '&DATECO.year=' + y2k(now.getYear());
	param += '&DATECI.year=' + y2k(retour.getYear());
	param += '&DATECO.hour=10&DATECO.minute=00';
	param += '&DATECI.hour=17&DATECI.minute=00';

	return param;
}

function is_ISO(paramValue){
	if(parseInt(paramValue.substring(5,7))==0) return true;
	else return false;
}

/* test de la version ISO */
ISODateValue=true;


function Valid(){
//DATES
	datedepart  = document.destform.DATECOday.options[document.destform.DATECOday.selectedIndex].value;
	dateretour  = document.destform.DATECIday.options[document.destform.DATECIday.selectedIndex].value;
	moisdepart  = document.destform.DATECOmonth.options[document.destform.DATECOmonth.selectedIndex].value.substring(0,2);
	moisretour  = document.destform.DATECImonth.options[document.destform.DATECImonth.selectedIndex].value.substring(0,2);
	anneedepart = document.destform.DATECOmonth.options[document.destform.DATECOmonth.selectedIndex].value.substring(2,6);
	anneeretour = document.destform.DATECImonth.options[document.destform.DATECImonth.selectedIndex].value.substring(2,6);
	heuredepart  = document.destform.DATECOhour.options[document.destform.DATECOhour.selectedIndex].value;
	minutedepart = '00';
	//minutedepart  = document.destform.DATECOminute.options[document.destform.DATECOminute.selectedIndex].value;
	heurearrive  = document.destform.DATECIhour.options[document.destform.DATECIhour.selectedIndex].value;
	minutearrive = '00';
	//minutearrive  = document.destform.DATECIminute.options[document.destform.DATECIminute.selectedIndex].value;

	depart=Date.UTC(anneedepart,moisdepart-1,datedepart,0,0,0)
	retour=Date.UTC(anneeretour,moisretour-1,dateretour,0,0,0)
	if (depart > retour){
		alert("Please ensure the pick-up date is before the return date.")
		return false
	}
	// ************** PARAMS ****************************
	//function init put the values in form sendForm
	//locale,CNTRY,IATA,
	//
	//Get values for STATIONCO and RENTALCNTRY

	iSTATIONCO=document.destform.dest.selectedIndex
	STATIONCO=document.destform.dest.options[document.destform.dest.selectedIndex].value

	if (iSTATIONCO==0 || STATIONCO=="0") {
			window.alert("Please, select a destination");
			return false;
	}
	iCNTRY=document.destform.CNTRY.selectedIndex

	if (iCNTRY==0) {
			window.alert("Please, select a Country of residence");
			return false;
	}
	CNTRY=document.destform.CNTRY.options[iCNTRY].value
	//RENTALCNTRY=getRental(STATIONCO)
	RENTALCNTRY=STATIONCO;


	//Put values in form
	document.sendForm.STATIONCO.value=STATIONCO
	document.sendForm.STATIONCI.value=STATIONCO
	document.sendForm.RENTALCNTRY.value=RENTALCNTRY
	document.sendForm.CNTRY.value=CNTRY
	document.sendForm.DATECO.value= anneedepart+moisdepart+datedepart+heuredepart+minutedepart
	document.sendForm.DATECI.value= anneeretour+moisretour+dateretour+heurearrive+minutearrive



	document.sendForm.submit()
}

/** keep if return date was already choosen*/
var returnDateChoose = false;

/**
* add to change return date when picup date was choosen
* after return date was sets change on pickup date do nothing
*/
function setCIDate(){
	if (returnDateChoose)
		return;
	newday  = parseInt(document.destform.DATECOday.options[document.destform.DATECOday.selectedIndex].value,10);
	newmois  = document.destform.DATECOmonth.options[document.destform.DATECOmonth.selectedIndex].value.substring(0,2);
	newannee = document.destform.DATECOmonth.options[document.destform.DATECOmonth.selectedIndex].value.substring(2,6);
	today=new Date(newannee,newmois-1,newday)

	tomorrow=new Date( Date.UTC(y2k(today.getYear()),today.getMonth(),today.getDate() + 1));

	vmonth=new String(tomorrow.getMonth()+1)

	if (vmonth.length==1) vmonth="0" + vmonth
	vyear=new String(tomorrow.getFullYear())

	tmp_value=(ISODateValue)? vmonth+vyear:vyear+vmonth;

	for (i=0; i<document.forms[0]["DATECImonth"].length; i++){
		if(document.forms[0]["DATECImonth"][i].value==tmp_value){
			document.forms[0]["DATECImonth"].selectedIndex=i;
		}
	}


	document.forms[0]["DATECIday"].selectedIndex=tomorrow.getDate()-1

	theSelect=document.destform["DATECImonth"]
	getOptionsDayList(theSelect, 'DATECIday')

}



/* */
function getOptionsDayList(SelectObject, DaySelectName){
	strObjectValue=SelectObject[SelectObject.selectedIndex].value;
	intMonth=strObjectValue.substring(0,2);
	intYear=strObjectValue.substring(2);
	getDayList(intMonth,intYear,DaySelectName);
}


function getDayList(intMonth,intYear,SelectName){
	is_validMonth=true;
	currentDaySelected=document.forms[0][SelectName].selectedIndex;
	document.forms[0][SelectName].options.length=0;
	currentDate=new Date(intMonth+"/01/"+intYear);

	while(is_validMonth){
		currentMonth=currentDate.getMonth();
		currentyear=currentDate.getYear();
		currentDayNumber=currentDate.getDate();

		strCurrentDayNumber=(currentDayNumber<10)? "0"+currentDayNumber:currentDayNumber;

		document.forms[0][SelectName].options[document.forms[0][SelectName].options.length]=new Option(strCurrentDayNumber,strCurrentDayNumber);
		NextDay=parseInt(currentDayNumber)+1;

		currentDate=new Date((currentMonth+1)+"/"+NextDay+"/"+y2k(currentyear));
		if(parseInt(currentDate.getMonth())!=parseInt(currentMonth)) is_validMonth=false;
	}

	if(currentDaySelected>document.forms[0][SelectName].options.length-1) currentDaySelected=document.forms[0][SelectName].options.length-1;

	document.forms[0][SelectName].selectedIndex=currentDaySelected;


}

/* */



function setFormDate(){

	today_aux=new Date(); //today is = today + 1 for select day and month
	today=new Date( Date.UTC(y2k(today_aux.getYear()),today_aux.getMonth(),today_aux.getDate() + 1));

	tomorrow=new Date( Date.UTC(y2k(today.getYear()),today.getMonth(),today.getDate() + 1));

	//1: Select month in DATECOmonth
	//2: select today in DATECOday
	//3. Charge days in DATECOday
	//1.
	vmonth=new String(today.getMonth()+1)
	if (vmonth.length==1) vmonth="0" + vmonth
	vyear=new String(today.getYear())
	tmp_value=(ISODateValue)? vmonth+vyear:vyear+vmonth;
	for (i=0; i<document.forms[0]["DATECOmonth"].length; i++){
		if(document.forms[0]["DATECOmonth"][i].value==tmp_value){
			document.forms[0]["DATECOmonth"].selectedIndex=i;
		}
	}
	//2.
	document.forms[0]["DATECOday"].selectedIndex=today.getDate()-1
	//3.
	theSelect=document.destform["DATECOmonth"]
	getOptionsDayList(theSelect, 'DATECOday')

	//
	//the same for CI
	vmonth=new String(tomorrow.getMonth()+1)
	if (vmonth.length==1) vmonth="0" + vmonth
	vyear=new String(tomorrow.getYear())
	tmp_value=(ISODateValue)? vmonth+vyear:vyear+vmonth;
	for (i=0; i<document.forms[0]["DATECImonth"].length; i++){
		if(document.forms[0]["DATECImonth"][i].value==tmp_value){
			document.forms[0]["DATECImonth"].selectedIndex=i;
		}
	}


	//2.
	document.forms[0]["DATECIday"].selectedIndex=tomorrow.getDate()-1
	//3.
	theSelect=document.destform["DATECImonth"]
	getOptionsDayList(theSelect, 'DATECIday')
}

	/** generate modify URL whith language and site */
	function generateModifyURL(){
		/*var loc='https://microsite.europcar.com/bienvenue'.split("/");
		var rep=loc[loc.length -1];
		var url = "https://microsite.europcar.com/" + rep;*/
		var url = 'https://microsite.europcar.com/australia';
		//alert("rep: " + rep);
		//return "https://res.europcar.com/?locale=en&MCS=" + url + "&PAGE=search_res";
		return "resaweb.html?locale=en&MCS=" + url + "&PAGE=search_res";
	}

function popUp(theURL,winName,features) {
  window.open(theURL,winName,features);
}


function init(){
	setParameters();
}
