//funcion encargada de crear el objeto
function objetus() {
        try {
                objetus_ = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                        objetus_= new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                        objetus_= false;
                }
        }
        if (!objetus_ && typeof XMLHttpRequest!='undefined') {
                objetus_ = new XMLHttpRequest();
        }
        return objetus_
}

function calcprecio() {
	var error =0;
	var fecha=document.getElementById("fecha").value;
	var fechaf=document.getElementById("fechaf").value;
	var nombre=document.getElementById("nombre").value;
	var mail=document.getElementById("mail").value;
	var tel=document.getElementById("tel").value;
	var maskm=document.getElementById("maskm").value;
	//var entregadom=document.getElementById("entregadom").checked;
	
	if ((fecha == "") && (error == 0)){
		alert("Por favor indique la fecha de inicio del alquiler");
		error=1;
	}
	if ((fechaf == "") && (error == 0)) {
		alert("Por favor indique la fecha de fin del alquiler");
		error=1;
	}
	if ((nombre == "")  && (error == 0)){
		alert("Por favor indique su nombre");
		error=1;
	}
	if ((mail == "")  && (error == 0)){
		alert("Por favor indique un e-mail válido");
		error=1;
	}
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if ( (!filter.test(mail))  && (error == 0)) {
		alert("Por favor indique un e-mail válido");
		error=1;
	}
	if ((tel.length != 9)  && (error == 0)) {
		alert("Por favor indique un número de teléfono válido");
		error =1;
	}
	if ( (isNaN(parseInt(tel)))  && (error == 0)) {
		alert("Por favor indique un número de teléfono válido");
		error =1;
	}
	if (error == 0) {
		var capa = document.getElementById("cajaflota");
		document.getElementById("t").innerHTML="Calculando precio <img src='/img/ajax-loader.gif' style='vertical-align: top;'/>";
		var vehi=document.getElementById("idvehi").value;
		var apellidos=document.getElementById("apellidos").value;
		var ofi = document.getElementById("ofi").options[document.getElementById("ofi").selectedIndex].text;
		//var lugar = document.getElementById("lugar").options[document.getElementById("lugar").selectedIndex].text;
		var precio = new objetus();
		url="/inc/precio.php?vehi="+vehi+"&fecha="+fecha+"&fechaf="+fechaf+"&ofi="+ofi+"&nombre="+nombre+"&apellidos="+apellidos+"&mail="+mail+"&tel="+tel+"&maskm="+maskm+"";
		precio.open("GET",url,true);
		precio.onreadystatechange = function() {
			if (precio.readyState==4) {
				capa.innerHTML=precio.responseText;
			}
		}
		precio.send(null);
	}
}

function miniflota(lang) {
	var capa = document.getElementById("cajaflota");
	document.getElementById("t").innerHTML="Cargando Datos <img src='/img/ajax-loader.gif' style='vertical-align: top;'/>";
	var miniflota = new objetus();
	var url = "/inc/miniflota.php"+"?lang="+lang;
	miniflota.open("GET",url,true);
	miniflota.onreadystatechange = function() {
		if (miniflota.readyState==4) {
			capa.innerHTML=miniflota.responseText;
		}
	}
	miniflota.send(null);
}
function chargefoto() {
	var capa = document.getElementById("idvehi");
	var valor=capa.value;
	var imagen = document.getElementById("fotoform");
	var t=valor.split("_");
	valor=t[0];
	var kminctext=t[1];
	imagen.src="/img/cargaimg.gif";	
	imagen.src="/img/flota/res_"+valor+"";
	document.getElementById("kminctext").innerHTML=kminctext;
}
function formatras(vehi,f,ff,l,o,n,a,t,m) {
	var capa = document.getElementById("cajaflota");
	document.getElementById("t").innerHTML="Cargando Datos <img src='/img/ajax-loader.gif' style='vertical-align: top;'/>";
	var formulario = new objetus();
	url="/inc/formreser.php?id="+vehi+"";
	formulario.open("GET",url,true);
	formulario.onreadystatechange = function() {
		if (formulario.readyState==4) {
			capa.innerHTML=formulario.responseText;
			Calendar.setup({
        			inputField:     "fecha",     // id del campo de texto
        			ifFormat:       "%d/%m/%Y", // formato de la fecha que se escriba en el campo de texto
        			button:         "botcal"    // el id del botï¿½ que lanzarï¿½el calendario
			});
			Calendar.setup({
			        inputField:     "fechaf",     // id del campo de texto
			        ifFormat:       "%d/%m/%Y", // formato de la fecha que se escriba en el campo de texto
			        button:         "botcald"    // el id del botï¿½ que lanzarï¿½el calendario
			});
			/*
			if (vehi == "") {
				chargefoto();
			}
			*/
			document.getElementById("fecha").value=f;
			document.getElementById("fechaf").value=ff;
			for (i=0;i<document.getElementById("ofi").options.length;i++) {
				if (document.getElementById("ofi").options[i].text == o) {
					document.getElementById("ofi").options[i].selected=true;
				}
			}
			for (i=0;i<document.getElementById("lugar").options.length;i++) {
				if (document.getElementById("lugar").options[i].text == l) {
					document.getElementById("lugar").options[i].selected=true;
				}
			}
			document.getElementById("nombre").value=n;
			document.getElementById("apellidos").value=a;
			document.getElementById("mail").value=m;
			document.getElementById("tel").value=t;
		}
	}
	formulario.send(null);
}
function form(id,lang) {
	var capa = document.getElementById("cajaflota");
	document.getElementById("t").innerHTML="Cargando Datos <img src='/img/ajax-loader.gif' style='vertical-align: top;'/>";
	var formulario = new objetus();
	url="/inc/formreser.php?id="+id+"&lang="+lang+"";
	formulario.open("GET",url,true);
	formulario.onreadystatechange = function() {
		if (formulario.readyState==4) {
			capa.innerHTML=formulario.responseText;
			Calendar.setup({
        			inputField:     "fecha",     // id del campo de texto
        			ifFormat:       "%d/%m/%Y", // formato de la fecha que se escriba en el campo de texto
        			button:         "botcal"    // el id del botï¿½ que lanzarï¿½el calendario
			});
			Calendar.setup({
			        inputField:     "fechaf",     // id del campo de texto
			        ifFormat:       "%d/%m/%Y", // formato de la fecha que se escriba en el campo de texto
			        button:         "botcald"    // el id del botï¿½ que lanzarï¿½el calendario
			});
			if (id == "") {
				chargefoto();
			}
		}
	}
	formulario.send(null);
}
function sendreserva(v,f,ff,l,o,n,a,t,m,p,k,e) {
	var capa = document.getElementById("cajaflota");
	document.getElementById("t").innerHTML="Cargando Datos <img src='/img/ajax-loader.gif' style='vertical-align: top;'/>";
	var formulario = new objetus();
	url="/inc/finreser.php?v="+v+"&f="+f+"&ff="+ff+"&l="+l+"&o="+o+"&n="+n+"&a="+a+"&t="+t+"&m="+m+"&p="+p+"&k="+k+"&e="+e+"";
	formulario.open("GET",url,true);
	formulario.onreadystatechange = function() {
		if (formulario.readyState==4) {
			capa.innerHTML=formulario.responseText;
		}
	}
	formulario.send(null);
}

function mandacontact() {
	this.scroll(1,0);
	capa="formulario";
	nombre=document.getElementById("nombre").value;
	apellidos=document.getElementById("apellidos").value;
	telefono=document.getElementById("tel").value;
	mail=document.getElementById("mail").value;
	texto=document.getElementById("observaciones").value;
	
	document.getElementById(capa).innerHTML="<div class='centrado'><p>Enviando solicitud ...</p><p><img src='/img/loading.gif' width='43' height='11'/></p>";
	
	_section=objetus();
	_datos="nombre="+nombre+"&apellidos="+apellidos+"&telefono="+telefono+"&mail="+mail+"&texto="+texto+"";
	_url="/inc/mandacontact.php?"+_datos+"";
	_section.open("GET",_url,true);
	_section.onreadystatechange=function() {
		 if (_section.readyState==4)
		 	{
			document.getElementById(capa).innerHTML=_section.responseText;
			}
		}
	_section.send(null);
}



