//Validar formulario
function msgError(mensaje){
	document.getElementById("error").style.visibility = "visible";
	document.getElementById("msgError").innerHTML=(mensaje);
}
//exclusivo para el paso 3 reserva
function msgError2(mensaje){
	document.getElementById("error2").style.visibility = "visible";
	document.getElementById("msgError2").innerHTML=(mensaje);
}
function ocultarError(){
	document.getElementById("error").style.visibility = "hidden";
	document.getElementById("msgError").innerHTML="";
}
function ocultarError2(){
	document.getElementById("error2").style.visibility = "hidden";
	document.getElementById("msgError2").innerHTML="";
}

function checkContact(){
	var politica = document.getElementById("politica").checked;
	var nombre=document.getElementById("nombre").value;
	var apellidos=document.getElementById("apellidos").value;
	var email=document.getElementById("email").value;
	var telefono=document.getElementById("telefono").value;
	var comentarios=document.getElementById("comentarios").value;
	
	//comprueba que los campos estan rellenados
	if(politica==false){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" height=\"16px\" width=\"16px\" /> You must read and accept the privacy policy.");
	}else if(nombre==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" height=\"16px\" width=\"16px\" /> Put your name in");
	}else if(email==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" height=\"16px\" width=\"16px\" /> Put your e-mail address in");
	}else if(comentarios==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" height=\"16px\" width=\"16px\" /> Put the reason in why you are contact us");
	}else{
		document.getElementById("formContacto").submit();
	}
}

function checkCliente(){
	//datos cuenta
	var politica = document.getElementById("politica").checked;
	var nombre=document.getElementById("nombreCliente").value;
	var apellidos=document.getElementById("apellidosCliente").value;
	var telefono=document.getElementById("telefonoCliente").value;
	var email=document.getElementById("emailCliente").value;
	var clave1=document.getElementById("clave1Cliente").value;
	var clave2=document.getElementById("clave2Cliente").value;
	//datos direccion
	var direccion=document.getElementById("direccionCliente").value;
	var ciudad=document.getElementById("ciudadCliente").value;
	var provincia = document.getElementById("provinciaCliente").value;
	var pais=document.getElementById("paisCliente").value;
	//datos dni
	var numeroDNI = document.getElementById("dniCliente").value;
	var diaDNI=document.getElementById("diadniCliente").value;
	var mesDNI=document.getElementById("mesdniCliente").value;
	var anoDNI=document.getElementById("anodniCliente").value;
	var lugarDNI=document.getElementById("lugardniCliente").value;
	//datos permiso
	var numeroPermiso = document.getElementById("nconducirCliente").value;
	var diaPermiso=document.getElementById("diapermisoCliente").value;
	var mesPermiso=document.getElementById("mespermisoCliente").value;
	var anoPermiso=document.getElementById("anopermisoCliente").value;
	var lugarPermiso=document.getElementById("lugarconducirCliente").value;
	//datos medio conocimiento
	var conocimiento=document.getElementById("conocimientoCliente").value;

	if(politica==false){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" height=\"16px\" width=\"16px\" /> You must read and accept the privacy policy.");
	}else if(nombre==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your name in");
	}else if(apellidos==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your last name in");
	}else if(telefono==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your phone number in");
	}else if(email==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your e-mail in");
	}else if(clave1==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your password in");
	}else if(clave1.length<6){
		document.getElementById("clave1Cliente").value = "";
		document.getElementById("clave2Cliente").value = "";
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Your password needs to have more than 6 caracters");
	}else if(clave1!=clave2){
		document.getElementById("clave1Cliente").value = "";
		document.getElementById("clave2Cliente").value = "";
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> You didn´t confirm your new password correct");
	}else if(direccion=="" || ciudad=="" || provincia=="" || pais=="Por favor, selecciona"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your home address in");
	}else if(numeroDNI==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your passport number in");
	}else if(diaDNI=="Día" || mesDNI=="Mes" || anoDNI=="Año"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put the expiry date of your passport in");
	}else if(lugarDNI==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your license number in");
	}else if(numeroPermiso==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put the expiry date of your license in");
	}else if(diaPermiso=="Día" || mesPermiso=="Mes" || anoPermiso=="Año"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Issued in");
	}else if(lugarPermiso==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Issued in");
	}else if(conocimiento=="Por favor, selecciona"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> How do you know us?");
	}else{
		document.getElementById("formNuevoCliente").submit();
	}
}

function validarPresupuesto(){
	var fRecogida=document.getElementById("fechaRecogida").value;
	var fDevolucion=document.getElementById("fechaDevolucion").value;
	document.getElementById("fechaRecogidaR").value=fRecogida;
	document.getElementById("fechaDevolucionR").value=fDevolucion;
	document.getElementById("formPresupuesto").submit();
}

function presupuestar(){
	var diaRecogida=new Date(document.getElementById("fechaRecogida_Year_ID").value,document.getElementById("fechaRecogida_Month").value,document.getElementById("fechaRecogida_Day_ID").value);	
	var diaDevolucion=new Date(document.getElementById("fechaDevolucion_Year_ID").value,document.getElementById("fechaDevolucion_Month").value,document.getElementById("fechaDevolucion_Day_ID").value);
	/* calculo fechas */
	var diferencia = diaDevolucion.getTime() - diaRecogida.getTime();
	var dias = Math.round(diferencia / (1000 * 60 * 60 * 24))
	
	if(dias<=0){
		alert("The dates you put in are not correct");
	}else{
		document.getElementById("presupuestoOnline").submit();
	}
}

function checkPaso1(){
	/* calculo fechas */
	var diaRecogida=new Date(document.getElementById("fechaRecogidaReserva_Year_ID").value,document.getElementById("fechaRecogidaReserva_Month").value,document.getElementById("fechaRecogidaReserva_Day_ID").value);	
	var diaDevolucion=new Date(document.getElementById("fechaDevolucionReserva_Year_ID").value,document.getElementById("fechaDevolucionReserva_Month").value,document.getElementById("fechaDevolucionReserva_Day_ID").value);
	var diferencia = diaDevolucion.getTime() - diaRecogida.getTime();
	var dias = Math.round(diferencia / (1000 * 60 * 60 * 24));
	
	var lRecogida=document.getElementById("lugarRecogidaR").value;
	var fRecogida=document.getElementById("fechaRecogidaReserva").value;
	var hRecogida=document.getElementById("horaRecogidaR").value;
	var mRecogida=document.getElementById("minutoRecogidaR").value;
	var lDevolucion=document.getElementById("lugarDevolucionR").value;
	var fDevolucion=document.getElementById("fechaDevolucionReserva").value;
	var hDevolucion=document.getElementById("horaDevolucionR").value;
	var mDevolucion=document.getElementById("minutoDevolucionR").value;
	
	if(lRecogida=="Seleccione un lugar"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Where you want to pick up the car?");
	}else if(lDevolucion=="Seleccione un lugar"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Where you want to drop the car off?");
	}else if(dias<=0){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> The dates you put in are not correct");
	}else if(hRecogida=="--" || mRecogida=="--"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Pick up time");
	}else if(hDevolucion=="--" || mDevolucion=="--"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> drop off time");
	}else{
		document.getElementById("error").style.visibility = "hidden";
		/* relleno hidden con datos*/
		document.getElementById("step").value="1";
		document.getElementById("formReservaOnline").submit();
	}
}

function checkPaso2(grupo,tarifa,modelo){
	document.getElementById("grupoR").value=grupo;
	document.getElementById("tarifaR").value=tarifa;
	document.getElementById("modeloR").value=modelo;
	document.getElementById("step").value="2";
	document.getElementById("formReservaOnline").submit();
}

function checkPaso3(){
	var politica = document.getElementById("politica").checked;
	var nombre=document.getElementById("nombreR").value;
	var apellidos=document.getElementById("apellidosR").value;
	var email=document.getElementById("emailR").value;
	var telefono=document.getElementById("telefonoR").value;
	var direccion=document.getElementById("direccionR").value;
	var municipio=document.getElementById("municipioR").value;
	var provincia=document.getElementById("provinciaR").value;
	var pais=document.getElementById("paisR").value;
	var direccionLocal=document.getElementById("direccionLocalR").value;
	var municipioLocal=document.getElementById("municipioLocalR").value;
	var provinciaLocal=document.getElementById("provinciaLocalR").value;
	var dni=document.getElementById("dniR").value;
	var diaDni=document.getElementById("diadniR").value;
	var mesDni=document.getElementById("mesdniR").value;
	var anoDni=document.getElementById("anodniR").value;
	var lugarDni=document.getElementById("lugarDniR").value;
	var permiso=document.getElementById("permisoR").value;
	var diaPermiso=document.getElementById("diapermisoR").value;
	var mesPermiso=document.getElementById("mespermisoR").value;
	var anoPermiso=document.getElementById("anopermisoR").value;
	var lugarPermiso=document.getElementById("lugarPermisoR").value;
	var comentarios=document.getElementById("comentariosR").value;
	
	if(politica==false){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" height=\"16px\" width=\"16px\" /> You must read and accept the privacy policy.");
	}else if(nombre==""){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your name in");
	}else if(apellidos==""){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your surname in");
	}else if(email==""){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your e-mail in");
	}else if(telefono==""){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your phone number in");
	}else if(direccion=="" || municipio=="" || provincia=="" || pais=="Por favor, selecciona"){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your home adress in");
	}else if(direccionLocal=="" || municipioLocal=="" || provinciaLocal==""){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your local adress in");
	}else if(dni==""){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your passport number in");
	}else if(diaDni=="Día" || mesDni=="Mes" || anoDni=="Año"){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put expiry date of your passport in");
	}else if(lugarDni==""){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Issued in");
	}else if(permiso==""){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your license number in");
	}else if(diaPermiso=="Día" || mesPermiso=="Mes" || anoPermiso=="Año"){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put the expiry date of your license in");
	}else if(lugarPermiso==""){
		msgError2("<img src=\"_img/advertencia.gif\" align=\"top\" /> Issued in");
	}else{
		document.getElementById("step").value="4";
		document.getElementById("formReservaOnline").submit();
	}
}
function checkUsuario(){
	document.getElementById("formReservaOnline").submit();
}

function checkVolver(step){
	document.getElementById("step").value=step;
	document.getElementById("formReservaOnline").submit();
}
function activarModificacion(){
	var campos=new Array("nombreCliente","apellidosCliente","telefonoCliente","emailCliente","direccionCliente","ciudadCliente","provinciaCliente","paisCliente","dniCliente","diadniCliente","mesdniCliente","anodniCliente","lugardniCliente","nconducirCliente","diapermisoCliente","mespermisoCliente","anopermisoCliente","lugarconducirCliente");
	for(i=0;i<campos.length;i++){
		document.getElementById(campos[i]).disabled=false;
	}
	document.getElementById("update").style.display="";
	document.getElementById("edit").style.display="none";
}
function updateCliente(){
	//datos cuenta
	var nombre=document.getElementById("nombreCliente").value;
	var apellidos=document.getElementById("apellidosCliente").value;
	var telefono=document.getElementById("telefonoCliente").value;
	var email=document.getElementById("emailCliente").value;
	//datos direccion
	var direccion=document.getElementById("direccionCliente").value;
	var ciudad=document.getElementById("ciudadCliente").value;
	var provincia = document.getElementById("provinciaCliente").value;
	var pais=document.getElementById("paisCliente").value;
	//datos dni
	var numeroDNI = document.getElementById("dniCliente").value;
	var diaDNI=document.getElementById("diadniCliente").value;
	var mesDNI=document.getElementById("mesdniCliente").value;
	var anoDNI=document.getElementById("anodniCliente").value;
	var lugarDNI=document.getElementById("lugardniCliente").value;
	//datos permiso
	var numeroPermiso = document.getElementById("nconducirCliente").value;
	var diaPermiso=document.getElementById("diapermisoCliente").value;
	var mesPermiso=document.getElementById("mespermisoCliente").value;
	var anoPermiso=document.getElementById("anopermisoCliente").value;
	var lugarPermiso=document.getElementById("lugarconducirCliente").value;
	//datos medio conocimiento

	if(nombre==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your name in");
	}else if(apellidos==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your surname in");
	}else if(telefono==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your phone number in");
	}else if(email==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your e-mail adress");
	}else if(direccion=="" || ciudad=="" || provincia=="" || pais=="Por favor, selecciona"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your home address in");
	}else if(numeroDNI==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" />Put your passport number in");
	}else if(diaDNI=="Día" || mesDNI=="Mes" || anoDNI=="Año"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put the expiry date of your passport in");
	}else if(lugarDNI==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Issued in");
	}else if(numeroPermiso==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your license number in");
	}else if(diaPermiso=="Día" || mesPermiso=="Mes" || anoPermiso=="Año"){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put the expiry date of your license in");
	}else if(lugarPermiso==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Issued in");
	}else{
		document.getElementById("updateCliente").submit();
	}
}

function cambiarClaveCliente(){
	var claveAntigua=document.getElementById("claveClienteAntigua").value;
	var claveNueva=document.getElementById("claveClienteNueva").value;
	var claveConfirmada=document.getElementById("claveClienteConfirmada").value;
	
	if(claveAntigua==""){
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Put your old password in");
	}else if(claveNueva.length<6){
		document.getElementById("claveClienteNueva").value = "";
		document.getElementById("claveClienteConfirmada").value = "";
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> Your password needs to have more than 6 caracteres");
	}else if(claveNueva!=claveConfirmada){
		document.getElementById("claveClienteNueva").value = "";
		document.getElementById("claveClienteConfirmada").value = "";
		msgError("<img src=\"_img/advertencia.gif\" align=\"top\" /> You didn´t confirm your new password correct");
	}else{
		document.getElementById("changePass").submit();
	}
}