/*var vcntryLoaded = "" ;
var vcntry=[];
function ChangeCountries(){
	theSelectCont=eval("document.getElementById('cont')")
	theSelectDest=eval("document.getElementById('dest')")
	//del old options
	for (m=theSelectDest.options.length-1;m>0;m--) {
		theSelectDest.options[m]=null;
	}
	vContinent=theSelectCont.options[theSelectCont.selectedIndex].value;
	x=(theSelectCont.options.selectedIndex-1);

	if (vContinent.value != "none"){
		for (i=0;i<vcntry[x].length;i++){
			theSelectDest.options[i+1]=new Option(vcntry[x][i].text,vcntry[x][i].value);
		}
		if (x == document.getElementById('cont').length){
			theSelectDest.selectedIndex = 1;
			theSelectDest.style.visibility = 'hidden';
		}
		if (x != document.getElementById('cont').length){
			theSelectDest.style.visibility = 'visible';
		}
	}	
}
function isVcntryLoaded(){
	var loc = document.forms.sendForm.locale.value;
	if(vcntryLoaded == "loaded"){ 
		clearInterval(LoadingVCntry); 
		var idioma = window.document.forms.sendForm.locale.value;
		writeSelect();
		loadValues();
		time(); month('DATECOmonth',loc); month('DATECImonth',loc);	
		residencia(loc);
		setParameters();
		/*setTimeout("initTurbo2()",500);*/
/*	}
}*/
function agregar(){
	if ((navigator.appName=="Microsoft Internet Explorer") && 
			(parseInt(navigator.appVersion)>=4)) {
		var url="http://www.europcar.com"; 
		var titulo="Europcar";
		window.external.AddFavorite(url,titulo);
	} else { 
		if(navigator.appName == "Netscape") 
		alert("Press Crtl+D to add this site in your bookmarks"); 
	}
} 

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=window.top.location;
	//alert(params)
	params=params.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.getElementById('sendForm').locale.value="en"			//theValors["locale"]
	if (theValors["IATA"]) document.getElementById('sendForm').IATA.value=theValors["IATA"]
	if (theValors["promobox"]){ loadPromoInBox(theValors["promobox"]); }
	document.getElementById('sendForm').RENTALCNTRY.value=theValors["RENTALCNTRY"]
	if (theValors["PICKUP"])   {
		document.getElementById('sendForm').STATIONCO.value=document.getElementById('sendForm').STATIONCI.value=theValors["STATIONCO"]     
		//select in list dest
		var selectItem = document.getElementById('destform').dest;
		
		for(i=0;i<selectItem.length;i++) {
			opt = selectItem.options[i];
			if(opt.value==theValors["PICKUP"]) {
				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.getElementById('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["AT"]="AT";theRental["BE"]="BE";theRental["BG"]="BG";theRental["CY"]="CY";theRental["CZ"]="CZ";theRental["FR"]="FR";theRental["DE"]="DE";theRental["GB"]="GB";theRental["GR"]="GR";theRental["HU"]="HU";theRental["IE"]="IE";theRental["IT"]="IT";theRental["LY"]="LY";theRental["MT"]="MT";theRental["MA"]="MA";theRental["NL"]="NL";theRental["NO"]="NO";theRental["PT"]="PT";theRental["RO"]="RO";theRental["RU"]="RU";theRental["ES"]="ES";theRental["SE"]="SE";theRental["CH"]="CH";theRental["TN"]="TN";theRental["TR"]="TR";theRental["XX"]="XX";



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 */
var ISODateValue=true;


function Valid(){
	//DATES
	var fDestForm = document.getElementById('destform'); var fSendForm = document.getElementById('sendForm'); 
	datedepart  = fDestForm.DATECOday.options[fDestForm.DATECOday.selectedIndex].value;
	dateretour  = fDestForm.DATECIday.options[fDestForm.DATECIday.selectedIndex].value;
	moisdepart  = fDestForm.DATECOmonth.options[fDestForm.DATECOmonth.selectedIndex].value.substring(0,2);
	moisretour  = fDestForm.DATECImonth.options[fDestForm.DATECImonth.selectedIndex].value.substring(0,2);
	anneedepart = fDestForm.DATECOmonth.options[fDestForm.DATECOmonth.selectedIndex].value.substring(2,6);
	anneeretour = fDestForm.DATECImonth.options[fDestForm.DATECImonth.selectedIndex].value.substring(2,6);
	heuredepart  = fDestForm.DATECOhour.options[fDestForm.DATECOhour.selectedIndex].value;
	minutedepart  = fDestForm.DATECOminute.options[fDestForm.DATECOminute.selectedIndex].value;	
	heurearrive  = fDestForm.DATECIhour.options[fDestForm.DATECIhour.selectedIndex].value;
	minutearrive  = fDestForm.DATECIminute.options[fDestForm.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("The pick-up date should always be lower than the return date.")
		return false
	}
	// ************** PARAMS ****************************
	//function init put the values in form sendForm
	//locale,CNTRY,IATA,
	//
	//Get values for STATIONCO and RENTALCNTRY
	
	iSTATIONCO=fDestForm.dest.selectedIndex
	STATIONCO=fDestForm.dest.options[fDestForm.dest.selectedIndex].value
	
	iCNTRY=fDestForm.CNTRY.selectedIndex
	

	CNTRY=fDestForm.CNTRY.options[iCNTRY].value
	RENTALCNTRY=STATIONCO
	//Put values in form
	createFormElementWithValue('IATA','input',document.forms.sendForm,'01308772','hidden');
	fSendForm.STATIONCO.value=STATIONCO; fSendForm.STATIONCI.value=STATIONCO; fSendForm.RENTALCNTRY.value=RENTALCNTRY; fSendForm.CNTRY.value=CNTRY; 
	fSendForm.DATECO.value= anneedepart+moisdepart+datedepart+heuredepart+minutedepart;	fSendForm.DATECI.value= anneeretour+moisretour+dateretour+heurearrive+minutearrive;
	if(STATIONCO=="YVRT01"){fSendForm.CARLIST.value = "E***,C***,IC**,IF**,F***,M***,S***,L***"}
	if(STATIONCO == "CPTT02" || STATIONCO == "JNBT01"){fSendForm.CARLIST.value = "ED*R,CD**,I***,CC**,EC**,S***,F***,P***"}
	//alert(document.getElementById('sendForm').IATA.value)
	//testtonationalize(CNTRY,anneedepart,moisdepart,datedepart,heuredepart,minutedepart,anneeretour,moisretour,dateretour,heurearrive,minutearrive,STATIONCO,STATIONCO)
	fSendForm.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(){
	var fDestForm = document.getElementById('destform');
	if (returnDateChoose)
	return;
	newday  = parseInt(fDestForm.DATECOday.options[fDestForm.DATECOday.selectedIndex].value,10);
	newmois  = fDestForm.DATECOmonth.options[fDestForm.DATECOmonth.selectedIndex].value.substring(0,2);
	newannee = fDestForm.DATECOmonth.options[fDestForm.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<fDestForm["DATECImonth"].length; i++){
		if(fDestForm["DATECImonth"][i].value==tmp_value){
			fDestForm["DATECImonth"].selectedIndex=i;
		}
	}
	

	fDestForm["DATECIday"].selectedIndex=tomorrow.getDate()-1

	theSelect=fDestForm["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){
	var fDestForm = document.getElementById('destform');
	is_validMonth=true;
	currentDaySelected=fDestForm[SelectName].selectedIndex;
	fDestForm[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;
		
		fDestForm[SelectName].options[fDestForm[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>fDestForm[SelectName].options.length-1) currentDaySelected=fDestForm[SelectName].options.length-1;
	
	fDestForm[SelectName].selectedIndex=currentDaySelected;
	
	
}

/* */



function setFormDate(){
	var fDestForm = document.getElementById('destform');
	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<fDestForm["DATECOmonth"].length; i++){
		if(fDestForm["DATECOmonth"][i].value==tmp_value){
			fDestForm["DATECOmonth"].selectedIndex=i;
		}
	}
	//2.
	fDestForm["DATECOday"].selectedIndex=today.getDate()-1
	//3.
	theSelect=fDestForm["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<fDestForm["DATECImonth"].length; i++){
		if(fDestForm["DATECImonth"][i].value==tmp_value){
			fDestForm["DATECImonth"].selectedIndex=i;
		}
	}
	
	
	//2.
	fDestForm["DATECIday"].selectedIndex=tomorrow.getDate()-1
	//3.
	theSelect=fDestForm["DATECImonth"]
	getOptionsDayList(theSelect, 'DATECIday')
}

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

function popUp(theURL,winName,features) { 
	window.open(theURL,winName,features);
}
function testtonationalize(Ecountres,anneedepart,moisdepart,datedepart,heuredepart,minutedepart,anneeretour,moisretour,dateretour,heurearrive,minutearrive,EstationCO,EstationCI){
	if(EstationCO != "CPTT02" && EstationCO != "JNBT01"){
		nationalize(Ecountres,anneedepart,moisdepart,datedepart,heuredepart,minutedepart,anneeretour,moisretour,dateretour,heurearrive,minutearrive,EstationCO,EstationCI);
	}
}
function nationalize(Ecountres,anneedepart,moisdepart,datedepart,heuredepart,minutedepart,anneeretour,moisretour,dateretour,heurearrive,minutearrive,EstationCO,EstationCI){ //GO TO NATIONAL by PAUL.M on Feb 09
	//https://www.nationalcar.com/index.do?action=/validateRental.do&contractId=VRGINBLU&countryOfResidenceCode=AU&pickUpDropOffDetailForm.pickupTime=8:00%20AM&pickUpDropOffDetailForm.dropoffTime=8:00%20PM&pickUpDropOffDetailForm.pickupStationName=SFOT01&pickUpDropOffDetailForm.dropoffStationName=SFOT01&pickUpDropOffDetailForm.pickupMonthYear=APR-2009&pickUpDropOffDetailForm.pickupDay=10&pickUpDropOffDetailForm.dropoffMonthYear=APR-2009&pickUpDropOffDetailForm.dropoffDay=17&footer=1&header=1&source=vaustralia_logo.jpg 
	var Nfooter = '&footer=' + '1'; 	var Nheader = '&header='+'1';	var Nsource = '&source=' + 'vaustralia_logo.jpg'; 	var Ncontractid = "&contractId=" + "VRGINBLU";	
	var pickupStationName = "&pickUpDropOffDetailForm.pickupStationName=" + EstationCO;	var dropoffStationName = "&pickUpDropOffDetailForm.dropoffStationName=" + EstationCI;	
	var pickupDay = "&pickUpDropOffDetailForm.pickupDay=" + datedepart;	var dropoffDay = "&pickUpDropOffDetailForm.dropoffDay=" + dateretour;	
	var AMPMCO = "AM";	var AMPMCI = "AM";
	if (heuredepart > 11) {AMPMCO = "PM"; heuredepart = heuredepart - 12}; if (heurearrive > 11) {AMPMCI = "PM"; heurearrive = heurearrive - 12}
	var pickupTime = heuredepart + ":" + minutedepart  + " " + AMPMCO; 	var dropoffTime = heurearrive + ":" + minutearrive + " " + AMPMCI;
	pickupTime = "&pickUpDropOffDetailForm.pickupTime=" + pickupTime; dropoffTime = "&pickUpDropOffDetailForm.dropoffTime=" + dropoffTime;
	var countryOfResidenceCode = "&countryOfResidenceCode=" + Ecountres; 	
	var pickupMonthYear = "";	var dropoffMonthYear = "";
	switch (moisdepart){
	case "01": 			pickupMonthYear = 'JAN-' ;			break;
	case "02":			pickupMonthYear = 'FEB-';			break;
	case "03":			pickupMonthYear = 'MAR-';			break;
	case "04":			pickupMonthYear = 'APR-';			break;
	case "05":			pickupMonthYear = 'MAY-';			break;
	case "06":			pickupMonthYear = 'JUN-';			break;
	case "07":			pickupMonthYear = 'JUL-';			break;
	case "08":			pickupMonthYear = 'AUG-';			break;
	case "09":			pickupMonthYear = 'SEP-';			break;
	case "10":			pickupMonthYear = 'OCT-';			break;
	case "11":			pickupMonthYear = 'NOV-';			break;
	case "12":			pickupMonthYear = 'DEC-';			break;
		
	} pickupMonthYear = "&pickUpDropOffDetailForm.pickupMonthYear=" + pickupMonthYear + anneedepart ;
	switch (moisdepart,moisretour){
	case "01":			dropoffMonthYear = 'JAN-';			break;
	case "02":			dropoffMonthYear = 'FEB-';			break;
	case "03":			dropoffMonthYear = 'MAR-';			break;
	case "04":			dropoffMonthYear = 'APR-';			break;
	case "05":			dropoffMonthYear = 'MAY-';			break;
	case "06":			dropoffMonthYear = 'JUN-';			break;
	case "07":			dropoffMonthYear = 'JUL-';			break;
	case "08":			dropoffMonthYear = 'AUG-';			break;
	case "09":			dropoffMonthYear = 'SEP-';			break;
	case "10":			dropoffMonthYear = 'OCT-';			break;
	case "11":			dropoffMonthYear = 'NOV-';			break;
	case "12":			dropoffMonthYear = 'DEC-';			break;
		
	} dropoffMonthYear = "&pickUpDropOffDetailForm.dropoffMonthYear=" + dropoffMonthYear + anneedepart ;
	var SF = document.getElementById('sendForm');
	SF.action = 'https://www.nationalcar.com/index.do?action=/validateRental.do';
	SF.target = "_top";
	SF.method = 'POST';
	SF.action = SF.action + Ncontractid + pickupStationName + dropoffStationName + pickupDay + dropoffDay + pickupTime + dropoffTime + countryOfResidenceCode + pickupMonthYear + dropoffMonthYear  + Nfooter + Nheader + Nsource;
	//alert(SF.action);
}

function init(){
	time(); 
	month('DATECOmonth','en'); 
	month('DATECImonth','en'); 
	loadPromoInBox('middle');
	setParameters();
}

/*function init(){
	var loc = document.forms.sendForm.locale.value;
	countriesListUrl = '../../stations/' + loc + '.js' ;
	var scriptDestinations = document.createElement('script');
	scriptDestinations.type = 'text/javascript';
	scriptDestinations.src = countriesListUrl;
	document.getElementsByTagName('head')[0].appendChild(scriptDestinations);
	LoadingVCntry = setInterval("isVcntryLoaded()",10)
}*/
function createFormElementWithValue(objectName,objectTagName,objectParent,objectValue,objectType){
	var newFormElement = document.createElement(objectTagName);
	newFormElement.id = objectName;
	newFormElement.name = objectName;
	newFormElement.value = objectValue;
	newFormElement.type = objectType;
	objectParent.appendChild(newFormElement);
}
