
function nuevoAjax() {
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
var xmlhttp=nuevoAjax();


// --------------------------------------------------------------------------------------------------- SELECT LUGAR DE RECOGIDA
function obtener_lugar_recogida(){			
			
	pais = document.getElementById("select_paises").value;
	if (pais==0){
		document.getElementById('div_select_recogida').innerHTML = '<select id="select_recogida" name="select_recogida" onChange="obtener_lugar_entrega();" style="width:275px;"><option value="0">Select the country first</option></select>';
		document.getElementById('div_select_entrega').innerHTML = '<select id="select_entrega" name="select_entrega" onChange="cambiar_lugar_entrega_texto();" style="width:275px;"><option value="0">Select the pick up location first</option></select>';
		document.getElementById("select_recogida").disabled = true;
		document.getElementById("select_entrega").disabled = true;
	}
	else{
	parametros = "tipo=recogida&idioma=EN&pais="+pais;
	
	document.getElementById("select_recogida").options[0].text = "Loading...";
	document.getElementById("select_recogida").selectedIndex = 0;
	document.getElementById("select_recogida").disabled = true;	
	document.getElementById("select_entrega").options[0].text = "Select the pick up location first";
	document.getElementById("select_entrega").selectedIndex = 0;
	document.getElementById("select_entrega").disabled = true;
	cadena = "/xmlhttp_lib.php";
	xmlhttp.open("POST",cadena,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", parametros.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=obtener_lugar_recogida_llego;
	xmlhttp.send(parametros);
	}
}

function obtener_lugar_recogida_llego(){
	if (xmlhttp.readyState==4) { // Transacción finalizada
		if (xmlhttp.status == 200) { // Estado correcto	
			var xmlDoc=xmlhttp.responseText;
			document.getElementById('div_select_recogida').innerHTML = xmlDoc;
		}
	}	
}

// --------------------------------------------------------------------------------------------------- SELECT LUGAR DE ENTREGA
function obtener_lugar_entrega(){
	document.getElementById("lugar_recogida_texto").value=document.getElementById("select_recogida").options[document.getElementById("select_recogida").selectedIndex].text;
	recogida = document.getElementById("select_recogida").value;
	if (recogida==0){
		document.getElementById('div_select_entrega').innerHTML = '<select id="select_entrega" name="select_entrega" onChange="cambiar_lugar_entrega_texto();" style="width:275px;"><option value="0">Select the pick up location first</option></select>';
		document.getElementById("select_entrega").disabled = true;
	}
	else{
	parametros = "tipo=entrega&idioma=EN&recogida="+recogida;
	
	document.getElementById("select_entrega").options[0].text = "Loading...";
	document.getElementById("select_entrega").selectedIndex = 0;
	document.getElementById("select_entrega").disabled = true;
	
	cadena = "/xmlhttp_lib.php";
	xmlhttp.open("POST",cadena,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", parametros.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=obtener_lugar_entrega_llego;
	xmlhttp.send(parametros);
	}
}

function obtener_lugar_entrega_llego(){
	if (xmlhttp.readyState==4) { // Transacción finalizada
		if (xmlhttp.status == 200) { // Estado correcto	
			var xmlDoc=xmlhttp.responseText;
			document.getElementById('div_select_entrega').innerHTML = xmlDoc;
		}
	}	
}

function saltar_a_fecha(){
	//document.getElementById("saltar_a_fechas").submit();	
	//GUARDAR LA CATEGORIA ELEGIDA
	parametros = "tipo=volver";
	cadena = "/xmlhttp_lib.php";
	xmlhttp.open("POST",cadena,false);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", parametros.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(parametros);
	//FIN GUARDAR LA CATEGORIA ELEGIDA
	location.href="http://www.elitecarhire.com/booking_location_date.php";
}

function saltar_a_coche(){
	//document.getElementById("saltar_a_coches").submit();	
	//GUARDAR LA CATEGORIA ELEGIDA
	parametros = "tipo=volver";
	cadena = "/xmlhttp_lib.php";
	xmlhttp.open("POST",cadena,false);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", parametros.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(parametros);
	//FIN GUARDAR LA CATEGORIA ELEGIDA
	location.href="http://www.elitecarhire.com/booking_car.php";
}

function cambiar_lugar_entrega_texto(){
	document.getElementById("lugar_entrega_texto").value=document.getElementById("select_entrega").options[document.getElementById("select_entrega").selectedIndex].text;	
}


