function login(lang)
{
	
	var user=document.getElementById('usuario').value;
	var pass=document.getElementById('password').value;
	var myConn = new XHConn();
	myConn.connect('php/login.php','POST','usuario='+user+'&clave='+pass+'&lang='+lang,leerDatoslogin);
}

function logout(lang)
{
	var myConn = new XHConn();
	myConn.connect('php/logout.php','POST','lang='+lang,nada);
	if (document.getElementById('cliente'))	
		document.getElementById('cliente').value='';
}

function leerDatoslogin(oXML)
{

	var codigo  = oXML.responseText.split('|');
	if (codigo[0]=='ok')
	{
		if (document.getElementById('listado'))
		{
			var formulario=document.getElementById('listado')
			var myConn2 = new XHConn();
			horar=formulario.hora_recogida.value.split(':');
			horae=formulario.hora_entrega.value.split(':');
			myConn2.connect('php/vehiculos.php','POST','fecha_recogida='+formulario.fecha_recogida.value
			+'&fecha_entrega='+formulario.fecha_entrega.value+'&hora_recogida='+horar[0]+
			'hora_entrega='+horae[0]+'&minutos_recogida='+horar[1]+'&minutos_entrega='+horae[1]+
			'&recogida='+formulario.punto_recogida.value+'&entrega='+formulario.punto_entrega.value+
			'&lang='+formulario.lang.value,leer_vehiculos);
		}

		
		if (document.getElementById('formulario'))
		{
			var extras=total-alquiler_ini;
			var numero = new oNumero(alquiler_des);
			document.getElementById('alquiler').innerHTML=numero.formato(2, false)+' &euro;';
			total=alquiler_des+extras;
			var numero = new oNumero(total);
			document.getElementById('total').innerHTML=numero.formato(2, false)+' &euro;';
		}
		if(document.getElementById('nombre'))
		{
		document.getElementById('nombre').value=codigo[1];
		document.getElementById('email').value=codigo[2];
		document.getElementById('telefono').value=codigo[3];
		//document.getElementById('comentarios').value=codigo[4];
		document.getElementById('cliente').value='registro';
		}
		document.getElementById('tabla_login').style.display='none';
		document.getElementById('tabla_logout').style.display='';
		document.getElementById('tdnombre').innerHTML=codigo[1];
		//sIFR.replaceElement("menu", "arialnarrow.swf", "#35aad2", "#72151c", null, null, 0, 0, 0, 0, null, null, "transparent");
		if (document.getElementById('td_recordar'))
			document.getElementById('td_recordar').style.display='none';
		if (document.getElementById('td_recordar2'))	
			document.getElementById('td_recordar2').style.display='none';
	if (document.getElementById('tr_clave'))	
		document.getElementById('tr_clave').style.display='none';
	}
	else
	{
		document.getElementById('usuario').value='';
		document.getElementById('password').value='';
		alert(codigo[1]);
	}
}

function nada(oXML)
{
	var codigo  = oXML.responseText;
		document.getElementById('tabla_login').style.display='';
		document.getElementById('tabla_logout').style.display='none';
		document.getElementById('usuario').value="";
		document.getElementById('password').value="";

	if (document.getElementById('formulario'))
	{
		var extras=total-alquiler_des;
		var numero = new oNumero(alquiler_ini);
		document.getElementById('alquiler').innerHTML=numero.formato(2, false)+' &euro;';
		total=alquiler_ini+extras;
		var numero = new oNumero(total);
		document.getElementById('total').innerHTML=numero.formato(2, false)+' &euro;';

		document.forms['formulario'].recordar.checked=false;
			document.getElementById('tr_clave').style.display='';
			document.forms['formulario'].clave.value='';
			document.forms['formulario'].reclave.value='';
			document.getElementById('tr_clave').style.display='none';
	}
				
	if(document.getElementById('nombre'))
	{
		document.getElementById('nombre').value='';
		document.getElementById('email').value='';
		document.getElementById('telefono').value='';
		//document.getElementById('comentarios').value=codigo[4];
		document.getElementById('cliente').value='';
	}	
	//sIFR.replaceElement("menu", "arialnarrow.swf", "#35aad2", "#72151c", null, null, 0, 0, 0, 0, null, null, "transparent");	
	if (document.getElementById('td_recordar'))
		document.getElementById('td_recordar').style.display='';
	if (document.getElementById('td_recordar2'))	
		document.getElementById('td_recordar2').style.display='';
	//if (document.getElementById('tr_clave'))	
	//	document.getElementById('tr_clave').style.display='';
	
	if (document.getElementById('listado'))
	{
		formulario=document.getElementById('listado');
		var myConn2 = new XHConn();
		horar=formulario.hora_recogida.value.split(':');
		horae=formulario.hora_entrega.value.split(':');
			myConn2.connect('php/vehiculos.php','POST','fecha_recogida='+formulario.fecha_recogida.value
			+'&fecha_entrega='+formulario.fecha_entrega.value+'&hora_recogida='+horar[0]+
			'hora_entrega='+horae[0]+'&minutos_recogida='+horar[1]+'&minutos_entrega='+horae[1]+
			'&recogida='+formulario.punto_recogida.value+'&entrega='+formulario.punto_entrega.value+
			'&lang='+formulario.lang.value,leer_vehiculos);
	}
}

function recordar(txt,lan)
{
	var usuario = document.getElementById('usuario').value;
	if(usuario=='')
	{
		alert(txt);
		return false;
	}
	var myConn = new XHConn();
	myConn.connect('php/recordar.php','POST','usuario='+usuario+'&lang='+lan,nada2);
}

function nada2(oXML)
{
	alert(oXML.responseText)
}

function leer_vehiculos(oXML)
{
	document.getElementById('listado_vehiculos').innerHTML=oXML.responseText;
}
