var urlCountriesList = "http://microsite.europcar.com/locations/getcountries.js";
var vcntryLoaded = "";
var loadingCountriesList = "";
var valuesLoadedFor = "";
var value = "";
function getStations(){	
	loadCountriesList();
}
function ClearOptions(id){
	var selectObj = document.getElementById(id);
	var selectParentNode = selectObj.parentNode;
	var newSelectObj = selectObj.cloneNode(false); 
	selectParentNode.replaceChild(newSelectObj, selectObj);
	AddDest("Escoja un destino","none");
	return newSelectObj;
}
function loadCountriesList(){
	var scriptDestinations = document.createElement('script'); 
	scriptDestinations.type = 'text/javascript'; 
	scriptDestinations.src = urlCountriesList; 
	document.getElementsByTagName('head')[0].appendChild(scriptDestinations);
	loadingCountriesList = setInterval("isLoaded()",10)
	
}
function isLoaded(){
	
	if (vcntryLoaded == 'loaded'){
		clearInterval(loadingCountriesList);
		writeSelect();
		document.getElementById('cont').disabled=false;  
		document.getElementById('Waitcountry').style.display = "none";
		setParamsfromURL();
	}	
}
//When user select a dest
function loadDestinationsList(){
	document.getElementById('dest').disabled=true;
	document.getElementById('Waitdest').style.display = "block";
	valuesLoadedFor = "";
	var idioma = document.destform.idioma.value;
	var country = document.getElementById('cont').options[document.getElementById('cont').selectedIndex].value;
	var newCodeForDestinationsList = 'getstations_' + country.toUpperCase() + '_' + idioma.toLowerCase() ;
	var scriptLoadDestinations = document.createElement('script'); 
	scriptLoadDestinations.type = 'text/javascript'; 
	scriptLoadDestinations.src = 'http://microsite.europcar.com/locations/' + newCodeForDestinationsList + '.js' ;
	scriptLoadDestinations.id = newCodeForDestinationsList;
	document.getElementsByTagName('head')[0].appendChild(scriptLoadDestinations);
	return newCodeForDestinationsList;
}
function isDestinationsListLoaded(){
ClearOptions('dest');
	value = loadDestinationsList();
	loadingDestinationList =setInterval("isDLLoaded()",100);	
}
function isDLLoaded(){	
	if (valuesLoadedFor == value){
		clearInterval(loadingDestinationList);
		document.getElementById('dest').disabled=false;
		document.getElementById('Waitdest').style.display = "none";
		loadValues();
		setSTATIONCO();
		}
}
function AddCntry(CntryName,CntryCode){
	var s = document.getElementById('cont');
	s.options[s.options.length] = new Option(CntryName,CntryCode);
}
function AddDest(DestName,DestCode){
	var s = document.getElementById('dest');
	s.options[s.options.length] = new Option(DestName,DestCode)
}
function getRentalLocations(){
	if (document.forms["destform"].elements["cont"].value=='none')
	document.getElementById('dest').disabled=true;  
	else
	isDestinationsListLoaded();
}