function setParameters() {
	setFormDate();
	// preselect CNTRY (country of residence) with 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;
		    }
		 }
 if (country == "GB") {document.destform.CNTRY.options[226].selected = true}
		 
}

function is_ISO(paramValue){
	if(parseInt(paramValue.substring(5,7))==0) return true;
	else return false;
}

var ISODateValue=true;

function Valid(){
	departureString = $('.date-pick').dpGetSelectedString();
	
	if (departureString==undefined){
		alert('please choose a pick-up date')
		return false
		//return false
	}
	if (departureString!=undefined){
			checkOutDay = departureString.substring(0,2);
			checkOutMonth = departureString.substring(3,5);
			checkOutYear = departureString.substring(6,10);
			checkOutYYYYMMDD = checkOutYear+checkOutMonth+checkOutDay;
	}
		
		
	arrivalString = $('.date-picker').dpGetSelectedString();
	if (arrivalString==undefined){
		alert('please choose a return date')
		return false
	}
		//return false
	if (arrivalString!=undefined){
		checkInDay = arrivalString.substring(0,2);
		checkInMonth = arrivalString.substring(3,5);
		checkInYear = arrivalString.substring(6,10);
		checkInYYYYMMDD = checkInYear+checkInMonth+checkInDay;
	}		
		


	
	
	heuredepart  = document.destform.DATECOhour.options[document.destform.DATECOhour.selectedIndex].value;
	minutedepart  = document.destform.DATECOminute.options[document.destform.DATECOminute.selectedIndex].value;
	heurearrive  = document.destform.DATECIhour.options[document.destform.DATECIhour.selectedIndex].value;
	minutearrive  = document.destform.DATECIminute.options[document.destform.DATECIminute.selectedIndex].value;
	depart=Date.UTC(checkOutYear,checkOutMonth-1,checkOutDay,heuredepart,minutedepart,0)
				
	//condition. depart>=today
	auxToday=new Date()
	theToday=Date.UTC(auxToday.getFullYear(),auxToday.getMonth(),auxToday.getDate(),auxToday.getHours(),auxToday.getMinutes(),0)
	diff = depart - theToday 
		
	if (depart< theToday || diff<7200000){
			alert("Please, select a valid pick-up date")
			return false
	}

	depart=Date.UTC(checkOutYear,checkOutMonth-1,checkOutDay,heuredepart,minutedepart,0)
	retour=Date.UTC(checkInYear,checkInMonth-1,checkInDay,heurearrive,minutearrive,0)
	nowaday=new Date();
	intwoweeks=new Date( Date.UTC((nowaday.getFullYear()),nowaday.getMonth(),nowaday.getDate() + 14));
	nowadayinsec=Date.UTC(nowaday.getFullYear(),nowaday.getMonth(),nowaday.getDate());
	intwoweeksinsec=nowadayinsec+(86400000*17);
	diff=depart-intwoweeksinsec;
	
	if (depart >= retour){
			alert("Please ensure the pick-up date is before the return date.")
			return false
	}

	iSTATIONCO=document.destform.dest.selectedIndex
	STATIONCO=document.destform.dest.options[document.destform.dest.selectedIndex].value
	STATIONLONG=STATIONCO.length;
	//CTRCT=document.destform.ctrct.options[document.destform.ctrct.selectedIndex].value
	//CTRCT='';
	
	

/*	if (CTRCT=="0") {
			window.alert("Please select your membership level");
			return false;
	}*/
	
	

	if (iSTATIONCO==0 || STATIONCO=="0" || STATIONCO=="traitdebut" || STATIONCO=="traitfin" || STATIONCO=="null" ) {
			alert("Please select a destination");
			return false;
	}
	iCNTRY=document.destform.CNTRY.selectedIndex

	if (iCNTRY==0) {
			alert("Please select a country of residence");
			return false;
	}
							
	
	
	CNTRY=document.destform.CNTRY.options[iCNTRY].value
	iRENTALCNTRY=document.destform.cont.selectedIndex
	RENTALCNTRY=document.destform.cont.options[document.destform.cont.selectedIndex].value
	

	//Put values in form
	document.sendForm.stationCodeCheckout.value=STATIONCO
	document.sendForm.stationCodeCheckin.value=STATIONCO
	document.sendForm.countryCodeCheckout.value=RENTALCNTRY
	document.sendForm.countryCodeCheckin.value=RENTALCNTRY
	document.sendForm.checkoutCountry.value=RENTALCNTRY
	document.sendForm.checkinCountry.value=RENTALCNTRY
	document.sendForm.checkoutLocation.value=STATIONCO
	document.sendForm.checkinLocation.value=STATIONCO
	document.sendForm.checkoutYear.value=checkOutYear
	document.sendForm.checkoutMonth.value=checkOutMonth
	document.sendForm.checkoutDay.value=checkOutDay
	document.sendForm.checkoutHour.value=heuredepart
	document.sendForm.checkoutMin.value=minutedepart
	document.sendForm.checkinDay.value=checkInDay
	document.sendForm.checkinMonth.value=checkInMonth
	document.sendForm.checkinYear.value=checkInYear
	document.sendForm.checkinHour.value=heurearrive
	document.sendForm.checkinMin.value=minutearrive	
	document.sendForm.CTRCT.value=document.forms.sendForm.CTRCT.value;
	

	document.sendForm.submit()
}

var returnDateChoose = false;

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((today.getFullYear()),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.getFullYear();
		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+"/"+(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((today_aux.getFullYear()),today_aux.getMonth(),today_aux.getDate() + 1));

	tomorrow=new Date( Date.UTC((today.getFullYear()),today.getMonth(),today.getDate() + 1));
	
	vyear=new String(today.getFullYear())
	tyear=new String(tomorrow.getFullYear())
	
	vday=today.getDate()
	vmonth=new String(today.getMonth()+1)
	if (vmonth.length==1) vmonth="0" + vmonth
	
	todayString=vday+'/'+vmonth+'/'+vyear;
	$('.date-pick').dpSetSelected(todayString);	
	
	tday=tomorrow.getDate()
	tmonth=new String(tomorrow.getMonth()+1)
	if (tmonth.length==1) tmonth="0" + tmonth
	
	tomorrowString=tday+'/'+tmonth+'/'+tyear;
	$('.date-picker').dpSetSelected(tomorrowString);	
	
}





function init(){
	setParameters();
}




