
/***************** FECHA **************/
var pong;

function makeArray(n){
	this.length = n;
	for (i=1;i<=n;i++)
		this[i]=0;
	
	return this;
}



function displayDate() {
  var this_month = new makeArray(12);
  this_month[0]  = "Enero";
  this_month[1]  = "Febrero";
  this_month[2]  = "Marzo";
  this_month[3]  = "Abril";
  this_month[4]  = "Mayo";
  this_month[5]  = "Junio";
  this_month[6]  = "Julio";
  this_month[7]  = "Agosto";
  this_month[8]  = "Septiembre";
  this_month[9]  = "Octubre";
  this_month[10] = "Noviembre";
  this_month[11] = "Diciembre";

  var this_day_e = new makeArray(7);
  this_day_e[0]  = "Domingo";
  this_day_e[1]  = "Lunes";
  this_day_e[2]  = "Martes";
  this_day_e[3]  = "Miércoles";
  this_day_e[4]  = "Jueves";
  this_day_e[5]  = "Viernes";
  this_day_e[6]  = "Sábado";

  var today = new Date();
  var day   = today.getDate();
  var month = today.getMonth();
  var year  = today.getYear();
  var dia = today.getDay();
    if (year < 1000) {
       year += 1900; }
  return( "<span class='fecha-cab'> " + this_day_e[dia] + ", " + day + " de " + this_month[month] + " " + year + "</span>");
}

/************************************************************************************************************/

/************************************************ añadir a favoritos ****************************************/

function favoritos()
{
	var direccion="http://www.solmar.es"; 
	var titulo="Sol-Mar, Alquiler de vehículos"; 
	var ns = "Para añadir esta página a tu libreta de Bookmarks, <br> pulsa: <b>[Ctrl] + [ D ]</b> "; 
	var op = "Para añadir esta página a tus Preferidos de Opera, pulsa: <br><b>[Ctrl] + [Mays] + [T]</b>"; 
	
	if (navigator.userAgent.indexOf("Opera")!=-1) document.write(op) 
	else { if (navigator.appName == "Netscape") document.write(ns) 
	else { 
		document.write(' <a href="javascript:window.external.AddFavorite(direccion, titulo);" ') 
		document.write(' onMouseOver="window.status= ') 
		document.write(" 'Añadir Sol-Mar, alquiler de vehículos a sus Favoritos.'; return true ") 
		document.write(' " onMouseOut="window.status= ') 
		document.write(" ' '; return true ") 
		document.write(' ">Añadir Sol-Mar, alquiler de vehículos a sus Favoritos</a>') } } 
}

/*************************************************************************************************************/


/******************************************* abre un pop up para oficinas ************************************/

function AbrirVentana(pagina,nombreventana) 
{
	myWin=window.open(pagina,nombreventana,'width=540,height=480,toolbar=si,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=no');
}

/*************************************************************************************************************/

/******************************************* abre un pop up para flota  **********************************/

function AbrirVentanaF(pagina,nombreventana) 
{
	myWin=window.open(pagina,nombreventana,'width=450,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,titlebar=no');
}

/*************************************************************************************************************/

/******************************************* abre un pop up para flota  **********************************/

function AbrirVentanaC(pagina,nombreventana) 
{
	myWin=window.open(pagina,nombreventana,'width=250,height=150,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,titlebar=no');
}
/*************************************************************************************************************/
 
 /******************************************* centra la ventana  **********************************/
 
function centrar() { 
    iz=(screen.width-document.body.clientWidth) / 2; 
    de=(screen.height-document.body.clientHeight) / 2; 
    moveTo(iz,de); 
}     
/*************************************************************************************************************/

/******************************************* calendario *****************************************************/
var ventanaCalendario=false 

function muestraCalendario(formulario_destino,campo_destino,boton, idioma, sender, mes, anyo, sucur){ 
	//funcion para abrir una ventana con un calendario. 
	if (typeof ventanaCalendario.document == "object") { 
	   ventanaCalendario.close();
	}
	ventanaCalendario = window.open("http://www.solmar.es/calendario/calendario/p_calendario.php?boton=" + boton + "&formulario=" + formulario_destino + "&nomcampo=" + campo_destino + "&idioma=" + idioma + "&sender=" + sender + "&nuevo_mes=" + mes + "&nuevo_ano=" + anyo + "&sucursal=" + sucur,"calendario", "width=250,height=250, left=100,top=100, scrollbars=no,menubars=no,statusbar=NO, status=NO, resizable=YES,location=NO") 
} 

function muestraCalendarioAgencia(formulario_destino,campo_destino,boton, idioma, sender){ 
	//funcion para abrir una ventana con un calendario. 
	if (typeof ventanaCalendario.document == "object") { 
	   ventanaCalendario.close();
	}
	ventanaCalendario = window.open("http://www.solmar.es/calendario/calendario/p_calendario.php?boton=" + boton + "&formulario=" + formulario_destino + "&nomcampo=" + campo_destino + "&idioma=" + idioma + "&sender=" + sender + "&sucursal=" + sucur,"calendario", "width=250,height=300, left=100,top=100, scrollbars=no,menubars=no,statusbar=NO, status=NO, resizable=YES,location=NO") 
} 

function muestraCalendarioprueba(formulario_destino,campo_destino,boton, idioma, sender, mes, anyo){ 
	//funcion para abrir una ventana con un calendario. 
	if (typeof ventanaCalendario.document == "object") { 
	   ventanaCalendario.close();
	}
	ventanaCalendario = window.open("http://www.solmar.es/calendario2/calendario/p_calendario.php?boton=" + boton + "&formulario=" + formulario_destino + "&nomcampo=" + campo_destino + "&idioma=" + idioma + "&sender=" + sender + "&nuevo_mes=" + mes + "&nuevo_ano=" + anyo,"calendario", "width=300,height=350, left=100,top=100, scrollbars=no,menubars=no,statusbar=NO, status=NO, resizable=YES,location=NO") 
} 
/*************************************************************************************************************/

/***************************** MUESTRA TABLA DE VEHÍCULOS ****************************************************/
function viewHide(id, origen) 
{
			var targetId, srcElement, targetElement;
			var targetElement;
			
			
				targetElement = document.getElementById('v7');
				targetElement.style.display = "none";
				targetElement = document.getElementById('v1');
				targetElement.style.display = "none";
				targetElement = document.getElementById('v2');
				targetElement.style.display = "none";
				targetElement = document.getElementById('v3');
				targetElement.style.display = "none";
				targetElement = document.getElementById('v4');
				targetElement.style.display = "none";
				targetElement = document.getElementById('v6');
				targetElement.style.display = "none";
				targetElement = document.getElementById('v8');
				targetElement.style.display = "none";
				targetElement = document.getElementById('v9');
				targetElement.style.display = "none";
				targetElement = document.getElementById('v10');
				targetElement.style.display = "none";
				if(origen=='web')
				{
					targetElement = document.getElementById('v99');
					targetElement.style.display = "none";
				}
				
				targetElement = document.getElementById(id);
				if (targetElement.style.display == "none") 
				{
					targetElement.style.display = "";
				} 
				else 
				{	
					targetElement.style.display = "none";
				} 
}
		
/*************************************************************************************************************/
/*************************************************************************************************************/
/************************************ VALIDACIÓN DE DATOS ****************************************************/
/*************************************************************************************************************/
/*************************************************************************************************************/

//ANYOS BISIESTOS
function anyoBisiesto(anyo)
{
        if (anyo < 100)
            var fin = anyo + 1900;
        else
            var fin = anyo ;

        if (fin % 4 != 0)
            return false;
        else
        {
            if (fin % 100 == 0)
            {
                if (fin % 400 == 0)
                {
                    return true;
                }
               	else
                {
                    return false;
                }
            }
            else
            {
                return true;
            }
        }
}
function reg_nuevoc() {
//registronuevocliente.php validacion de campos
nombre = document.getElementById("NOMCLI").value;
if( nombre == null || nombre.length == 0 || /^\s+$/.test(nombre) ) {
alert ("El campo nombre es obligatorio, por favor rellenelo.");
return false;
}
	
apellidos = document.getElementById("APECLI").value;
if( apellidos == null || apellidos.length == 0 || /^\s+$/.test(apellidos) ) {
alert ("El campo apellidos es obligatorio, por favor rellenelo.");
return false;
}
fn = document.getElementById("FENCLI").value;
if( fn == null || fn.length != 10 || /^\s+$/.test(fn) ) {
alert ("La fecha de nacimiento no es correcta o está vacia, por favor corrijalo.");
return false;
}
numper = document.getElementById("PERCLI").value;
if( numper == null || numper.length == 0 || /^\s+$/.test(numper) ) {
alert ("El número de permiso es obligatorio, por favor rellenelo.");
return false;
}
fe = document.getElementById("FEPCLI").value;
if( fe == null || fe.length != 10 || /^\s+$/.test(fe) ) {
alert ("La fecha de expedición no es correcta o está vacia, por favor corrijalo.");
return false;
}

direc = document.getElementById("DIRCLI").value;
if( direc == null || direc.length == 0 || /^\s+$/.test(direc) ) {
alert ("El campo de direción está vacio, por favor rellenelo.");
return false;
}

pob = document.getElementById("POBCLI").value;
if( pob == null || pob.length == 0 || /^\s+$/.test(pob) ) {
alert ("El campo de población está vacio, por favor rellenelo.");
return false;
}

pob = document.getElementById("COPCLI").value;
if( pob == null || pob.length == 0 || /^\s+$/.test(pob) ) {
alert ("Por favor rellene el código postal.");
return false;
}

prob = document.getElementById("PROCLI").value;
if( prob == null || prob.length == 0 || /^\s+$/.test(prob) ) {
alert ("Por favor rellene la provincia.");
return false;
}
mail = document.getElementById("EMLCLI").value;
if( !(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(mail)) ) {
alert("El e-mail está vacío o no es correcto, por favor corrijalo.");
return false;
}

tlf = document.getElementById("TELCLI").value;
if( !(/^\d{9}$/.test(tlf)) ) {
alert("El numero de teléfono está vacío o no es correcto, por favor compruebelo.");
return false;
//fin de registrociente.php
}

}
function valregdom(){
// registrodomicilios.php validacion de campos
var errordom = false;

direcion = document.getElementById("direccion").value;
if( direcion == null || direcion.length == 0 || /^\s+$/.test(direcion) ) {
errordom = true;}

pobla = document.getElementById("poblacion").value;
if( pobla == null || pobla.length == 0 || /^\s+$/.test(pobla) ) {
errordom = true;}

postcod = document.getElementById("cp").value;
if( postcod == null || postcod.length == 0 || /^\s+$/.test(postcod) ) {
errordom = true;}

if(errordom == true){
alert ("Por favor, para guardar los cambios rellene todos los campos. Si quiere continuar sin guardar haga click en Siguiente.");
return false;
	}
else {
	return true;
	}
}
function valregconduc(){
	// registroconductores.php validacion de campos
var errordom = false;

permis = document.getElementById("permi").value;
if( permis == null || permis.length == 0 || /^\s+$/.test(permis) ) {
errordom = true;}

nom = document.getElementById("nombre").value;
if( nom == null || nom.length == 0 || /^\s+$/.test(nom) ) {
errordom = true;}

if(errordom == true){
	alert ("Por favor, para guardar los cambios rellene todos los campos. Si quiere continuar sin guardar haga click en Siguiente.");
	return false;
	}
else {
	return true;
	}

	}

//fin registroconductores.php

function valregpass(){
	// registroacceso.php validacion de campos
var errordom = false;

cont1 = document.getElementById("contrasena1").value;
if( cont1 == null || cont1.length == 0 || /^\s+$/.test(cont1) ) {
errordom = true;}

cont2 = document.getElementById("contrasena2").value;
if( cont2 == null || cont2.length == 0 || /^\s+$/.test(cont2) ) {
errordom = true;}

if(cont1 == cont2){

if(errordom == true){
	alert ("Los campos de contraseña son obligatorios, rellenelos y vuelva a intentarlo.");
	return false;
	}
	
else {
	return true;
	}

	}
	
	else{
		 alert("La contraseña no coincide con la contraseña de confirmacion, por favor vuelva a introducirlas e intentelo de nuevo.");
		 	return false;

	}
}

//fin registroaceso.php


//COMPARAR FECHAS
function Comparar_Fecha(String1,String2, anyohoy, sender) //devuelve true cuando
{
//alert("en comparar fecha:")
//alert(String1.value)
	if (String1.substring(1,2)=="/") {
		String1="0"+String1
	}
	
	if (String1.substring(4,5)=="/"){
		String1=String1.substring(0,3)+"0"+String1.substring(3,9)
	}
	
	if (String2.substring(1,2)=="/") {
		String2="0"+String2
	}
	if (String2.substring(4,5)=="/"){
		String2=String2.substring(0,3)+"0"+String2.substring(3,9)
	}
	
	dia1=String1.substring(0,2);
	mes1=String1.substring(3,5);
	anyo1=String1.substring(6,10);
	dia2=String2.substring(0,2);
	mes2=String2.substring(3,5);
	anyo2=String2.substring(6,10);
	anyo1=parseInt(anyo1, 10);
	if(anyo1<1900) anyo1=anyo1+1900;
	//VALIDAMOS FORMATO
	
	if( (isNaN(dia1)==true) || (isNaN(mes1)==true) || (isNaN(anyo1)==true) || (isNaN(dia2)==true) || (isNaN(mes2)==true) || (isNaN(anyo2)==true) )
    {
        	alert("La fecha introducida debe estar formada sólo por números");
     	return false;
    }
	//COMPROBAMOS SI ES AÑO BISIESTO
	if(anyoBisiesto(anyo1))
           febrero=29;
    else
           febrero=28;
	
	//COMPROBAMOS LOS DIAS DEL MES
	if ((mes1<1) || (mes1>12) || (mes2<1) || (mes2>12))
    {
           alert("El mes introducido no es valido. Por favor, introduzca un mes correcto");
        return false;
    }
       
    if ((mes1==2) && ((dia1<1) || (dia1>febrero)))
    {
           alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
        return;
    }
	if ((mes2==2) && ((dia2<1) || (dia2>febrero)))
    {
           alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
        return;
    }
	
	if (((mes1==1) || (mes1==3) || (mes1==5) || (mes1==7) || (mes1==8) || (mes1==10) || (mes1==12)) && ((dia1<1) || (dia1>31)))
    {
           alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
        return false;
    }
       
   if (((mes1==4) || (mes1==6) || (mes1==9) || (mes1==11)) && ((dia1<1) || (dia1>30)))
   {
	   	  alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
	   return false;
   }
   if (((mes2==1) || (mes2==3) || (mes2==5) || (mes2==7) || (mes2==8) || (mes2==10) || (mes2==12)) && ((dia2<1) || (dia2>31)))
    {
           alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
        return false;
    }
       
   if (((mes2==4) || (mes2==6) || (mes2==9) || (mes2==11)) && ((dia2<1) || (dia2>30)))
   {
   
	   	alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
	    return false;
   }
   
   if (sender=='reserva' && ((anyo1<anyohoy) || (anyo1>anyohoy+2)))
   {		   
	    alert("El año introducido no es valido.");
		return false;
   } 
	
	if (dia1 == "08") 
		dia1 = "8";
	if (dia1 == '09') 
		dia1 = "9";
	if (mes1 == "08") 
		mes1 = "8";
	if (mes1 == "09") 
		mes1 = "9";
	if (dia2 == "08") 
		dia2 = "8";
	if (dia2 == '09') 
		dia2 = "9";
	if (mes2 == "08") 
		mes2 = "8";
	if (mes2 == "09") 
		mes2 = "9";
	
	dia1=parseInt(dia1,10);
	dia2=parseInt(dia2,10);
	mes1=parseInt(mes1,10);
	mes2=parseInt(mes2,10);
	anyo1=parseInt(anyo1,10);
	anyo2=parseInt(anyo2,10);
	
	if ((anyo1>anyo2) || ((anyo1==anyo2) && (mes1>mes2)) || ((anyo1==anyo2) && (mes1==mes2) && (dia1>dia2)))
	{
		if (sender=="reserva")
			alert("Fecha de devolución anterior a la fecha de recogida del vehículo.");
		if(sender=="agencia")
			alert("La fecha inicial debe ser anterior a la fecha final");
		return false;	//fecha1>fecha2
	}
	
	return true;
}
/********************************************************/


function validacion_index(fecha1, fecha2, h1, h2, sender, sus, sue)
{		
			
	/**************************** VALIDACIÓN FECHAS *********************************/

			if (fecha1.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca la fecha de recogida del vehículo");	//MENSAJE POR PANTALLA
				return false;
			}

			if (fecha2.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca la fecha de devolución del vehículo");
				return false;
			}
			
			if (fecha1.length != 10) 
			{
				alert("Formato de fecha de recogida incorrecto");	//MENSAJE POR PANTALLA
				return false;
			}
						
			var separador1f1= fecha1.charAt(2)
			var separador2f1= fecha1.charAt(5)
			var separador1f2= fecha2.charAt(2)
			var separador2f2= fecha2.charAt(5)
			
			if (separador1f1!= '/' || separador2f1!= '/' || separador1f2!= '/' || separador2f2!= '/') 
			{
				//alert ("sep1f1" + separador1f1)
				alert("Formato de fecha incorrecto");	//MENSAJE POR PANTALLA
				return false;
			}

			if (fecha2.length != 10) 
			{
				alert("Formato de fecha de devolución incorrecto");
				return false;
			}

			var today = new Date();
  			var day   = today.getDate();
  			var month = today.getMonth();
  			var year  = today.getYear();
  			var dia = today.getDay();
			var hora = today.getHours();
			var minutos = today.getMinutes();
			
			month=month+1;
			
			if (day == "1") 
				day = "01";
			if (day == "2") 
				day = "02";
			if (day == "3") 
				day = "03";
			if (day == "4") 
				day = "04";
			if (day == "5") 
				day = "05";
			if (day == "6") 
				day = "06";
			if (day == "7") 
				day = "07";
			if (day == "8") 
				day = "08";
			if (day == "9") 
				day = "09";
			if (month == "1") 
				month = "01";
			if (month == "2") 
				month = "02";
			if (month == "3") 
				month = "03";
			if (month == "4") 
				month = "04";
			if (month == "5") 
				month = "05";
			if (month == "6") 
				month = "06";
			if (month == "7") 
				month = "07";
			if (month == "8") 
				month = "08";
			if (month == "9") 
				month = "09";
			
			if(year<1900) year=year+1900;
			var hoy=day + "/" + month + "/" + year;
   			
			if (year < 1000) 
			{
     				year += 1900; 
			}
			
			var retorno1;
			retorno1 = Comparar_Fecha(fecha1, fecha2, year, sender);
			if (retorno1==false)
			{
				return false;
			}
			else if(retorno1!=true)
			{
				return false;
			}
			
			h1i=parseInt(h1,10)
			h2i=parseInt(h2,10)
						
			if((fecha1==fecha2)&&(h1i>=h2i))
			{
				alert("La fecha y hora de devolución del vehículo debe ser posterior a la fecha y hora de recogida");
				return false;
			}
										
			var retorno2;
			retorno2 = Comparar_Fecha(hoy, fecha1, year, sender);
			
			if (retorno2==false)
			{
				alert("La fecha de recogida no puede ser anterior a la fecha actual");
				return false;
			}
			else if(retorno2!=true)
				return false;
			
			if(minutos==0)
				hora=hora+1
			
			h=parseInt(hora,10)
		
			if ((fecha1==hoy) && (h>=h1i))
			{
				
				alert("La hora de recogida no puede ser anterior a la hora actual");
				return false;
			}
			
			retorno2=Comparar_Fecha('23/10/2008',fecha1, year, 'nuevaapertura');

			if(((sus=='SG') || (sue=='SG') ) && (retorno2==false))
			{
				alert("Lo sentimos. Nuestras oficinas en Santiago de Compostela no estarán operativas hasta el 23 de Octubre. Actualmente aceptamos reservas a partir de esta fecha.");
				return false;
			}
			
			
			retorno2=Comparar_Fecha('21/08/2008',fecha1, year, 'nuevaapertura');
			var patron=/^ME/;
			if((patron.test(sus) || patron.test(sue)) && (retorno2==false))
			{
				alert("Lo sentimos. Hasta el 21 de Agosto no se podrán realizar reservas via web en Menorca. Actualmente aceptamos reservas a partir de esta fecha.");
				return false;
			}

}
function validacion_fechas(fecha1, fecha2)
{		
			
	/**************************** VALIDACIÓN FECHAS *********************************/

			if (fecha1.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca la fecha de recogida del vehículo");	//MENSAJE POR PANTALLA
				return false;
			}

			if (fecha2.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca la fecha de devolución del vehículo");
				return false;
			}
			
			if (fecha1.length != 10) 
			{
				alert("Formato de fecha de recogida incorrecto");	//MENSAJE POR PANTALLA
				return false;
			}
						
			var separador1f1= fecha1.charAt(2)
			var separador2f1= fecha1.charAt(5)
			var separador1f2= fecha2.charAt(2)
			var separador2f2= fecha2.charAt(5)
			
			if (separador1f1!= '/' || separador2f1!= '/' || separador1f2!= '/' || separador2f2!= '/') 
			{
				//alert ("sep1f1" + separador1f1)
				alert("Formato de fecha incorrecto");	//MENSAJE POR PANTALLA
				return false;
			}

			if (fecha2.length != 10) 
			{
				alert("Formato de fecha de devolución incorrecto");
				return false;
			}

			var today = new Date();
  			var day   = today.getDate();
  			var month = today.getMonth();
  			var year  = today.getYear();
  			var dia = today.getDay();
			var hora = today.getHours();
			var minutos = today.getMinutes();
			
			month=month+1;
			
			if (day == "1") 
				day = "01";
			if (day == "2") 
				day = "02";
			if (day == "3") 
				day = "03";
			if (day == "4") 
				day = "04";
			if (day == "5") 
				day = "05";
			if (day == "6") 
				day = "06";
			if (day == "7") 
				day = "07";
			if (day == "8") 
				day = "08";
			if (day == "9") 
				day = "09";
			if (month == "1") 
				month = "01";
			if (month == "2") 
				month = "02";
			if (month == "3") 
				month = "03";
			if (month == "4") 
				month = "04";
			if (month == "5") 
				month = "05";
			if (month == "6") 
				month = "06";
			if (month == "7") 
				month = "07";
			if (month == "8") 
				month = "08";
			if (month == "9") 
				month = "09";
			
			if(year<1900) year=year+1900;
			var hoy=day + "/" + month + "/" + year;
   			
			if (year < 1000) 
			{
     				year += 1900; 
			}
			
			var retorno1;
			retorno1 = Comparar_Fecha(fecha1, fecha2, year, sender);
			if (retorno1==false)
			{
				return false;
			}
			else if(retorno1!=true)
			{
				return false;
			}
			
			h1i=parseInt(h1,10)
			h2i=parseInt(h2,10)
						
			if((fecha1==fecha2)&&(h1i>=h2i))
			{
				alert("La fecha y hora de devolución del vehículo debe ser posterior a la fecha y hora de recogida");
				return false;
			}
										
			var retorno2;
			retorno2 = Comparar_Fecha(hoy, fecha1, year, sender);
			
			if (retorno2==false)
			{
				alert("La fecha de recogida no puede ser anterior a la fecha actual");
				return false;
			}
			else if(retorno2!=true)
				return false;
			
			if(minutos==0)
				hora=hora+1
			
			h=parseInt(hora,10)
		
			if ((fecha1==hoy) && (h>=h1i))
			{
				
				alert("La hora de recogida no puede ser anterior a la hora actual");
				return false;
			}
			
			retorno2=Comparar_Fecha('05/05/2008',fecha1, year, 'nuevaapertura');
			if(((sus=='VI') || (sue=='VI') ) && (retorno2==false))
			{
				alert("Lo sentimos. Nuestras oficinas en Vigo no estarán operativas hasta el 5 de Mayo. Actualmente aceptamos reservas a partir de esta fecha.");
				return false;
			}
			if(((sus=='SE') || (sue=='SE') ) && (retorno2==false))
			{
				alert("Lo sentimos. Nuestras oficinas en Sevilla no estarán operativas hasta el 5 de Mayo. Actualmente aceptamos reservas a partir de esta fecha.");
				return false;
			}
			if(((sus=='SA') || (sue=='SA') ) && (retorno2==false))
			{
				alert("Lo sentimos. Nuestras oficinas en Santander no estarán operativas hasta el 5 de Mayo. Actualmente aceptamos reservas a partir de esta fecha.");
				return false;
			}
			if(((sus=='AS') || (sue=='AS') ) && (retorno2==false))
			{
				alert("Lo sentimos. Nuestras oficinas en Asturias no estarán operativas hasta el 5 de Mayo. Actualmente aceptamos reservas a partir de esta fecha.");
				return false;
			}
			if(((sus=='BI') || (sue=='BI') ) && (retorno2==false))
			{
				alert("Lo sentimos. Nuestras oficinas en Bilbao no estarán operativas hasta el 5 de Mayo. Actualmente aceptamos reservas a partir de esta fecha.");
				return false;
			}
			
			retorno2=Comparar_Fecha('28/07/2008',fecha1, year, 'nuevaapertura');
			if(((sus=='MA') || (sue=='MA') ) && (retorno2==false))
			{
				alert("Lo sentimos. Nuestras oficinas en Malaga no estarán operativas hasta el 28 de Julio. Actualmente aceptamos reservas a partir de esta fecha.");
				return false;
			}

} 


function validacion_empleo(nombre, poblacion, provincia, edad, nacionalidad, telf, email, idiomas)
{		
			
	/**************************** VALIDACIÓN FECHAS *********************************/

			if (nombre.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca su nombre");	//MENSAJE POR PANTALLA
				return false;
			}

			if (poblacion.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca su población");
				return false;
			}

			if (provincia.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca su provincia");	//MENSAJE POR PANTALLA
				return false;
			}

			if (edad.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca su edad");
				return false;
			}
			if (nacionalidad.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca su nacionalidad");	//MENSAJE POR PANTALLA
				return false;
			}

			if (telf.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca su teléfono");
				return false;
			}
			
			if (email.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca su e-mail");	//MENSAJE POR PANTALLA
				return false;
			}
			
			if (idiomas.length == 8) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Introduzca los idiomas que habla");
				return false;
			}
			
			var er_email = /^(.+\@.+\..+)$/
			
			if(!er_email.test(email)) 
			{ 
				alert('Campo e-mail no válido.')
				return false
    		}
} 
/****************************************  CALCULA LA EDAD **************************************************/
function calcular_edad(fecha){ 

    //calculo la fecha de hoy 
    hoy=new Date() 
    //alert(hoy) 

    //calculo la fecha que recibo 
    //La descompongo en un array 
    var array_fecha = fecha.split("/") 
    //si el array no tiene tres partes, la fecha es incorrecta 
    if (array_fecha.length!=3) 
       return false 

    //compruebo que los ano, mes, dia son correctos 
    var ano 
    ano = parseInt(array_fecha[2],10); 
    if (isNaN(ano)) 
       return false 

    var mes 
    mes = parseInt(array_fecha[1],10); 
    if (isNaN(mes)) 
       return false 

    var dia 
    dia = parseInt(array_fecha[0],10); 
    if (isNaN(dia)) 
       return false 


    //si el año de la fecha que recibo solo tiene 2 cifras hay que cambiarlo a 4 
    
	 if(ano<1900) ano=ano+1900;

    //resto los años de las dos fechas 
	aaaa=hoy.getYear();
	if(aaaa<1900) aaaa=aaaa+1900;
    edad=aaaa - ano - 1; //-1 porque no se si ha cumplido años ya este año 

    //si resto los meses y me da menor que 0 entonces no ha cumplido años. Si da mayor si ha cumplido 
    if (hoy.getMonth() + 1 - mes < 0) //+ 1 porque los meses empiezan en 0 
       return edad 
    if (hoy.getMonth() + 1 - mes > 0) 
       return edad+1 

    //entonces es que eran iguales. miro los dias 
    //si resto los dias y me da menor que 0 entonces no ha cumplido años. Si da mayor o igual si ha cumplido 
    if (hoy.getUTCDate() - dia >= 0) 
       return edad + 1 

    return edad 
} 


/******************* VALIDAMOS DATOS DEL CLIENTE ***********************************/
function validarfecha(fecha)
{
	var separador1f1= fecha.charAt(2)
	var separador2f1= fecha.charAt(5)
	
	if (separador1f1!= '/' || separador2f1!= '/') 
		return false;

	else
	{
		//La descompongo en un array 
		var array_fecha = fecha.split("/")
		anyo = parseInt(array_fecha[2])
		 
		//si el array no tiene tres partes, la fecha es incorrecta 
		if (array_fecha.length!=3 || anyo<=99) 
		   return false 
		else
			return true;
	}
 }
// SIN SEGUNDO CONDUCTOR
function validacion_cliente(pais, nom, ape, numper, tel, f_nac, email, dir, pob, cp, domp, pobp)
{
	var er_email = /^(.+\@.+\..+)$/
	
	
	if((nom.length == 0)||(ape.length == 0)||(numper.length == 0)||(tel.length == 0)||(email.length == 0)||(dir.length == 0)||(pob.length == 0)||(cp.length == 0)||(domp.length == 0)||(pobp.length == 0))
	{
		alert("Debe completar todos los campos obligatorios")
		
		return false
	}
	
	if(!er_email.test(email)) 
	{ 
       		alert('Campo e-mail no válido.')
       		return false
    }
	
	if(validarfecha(f_nac)==false)
	{
		alert("Formato de fecha de nacimiento incorrecto");	//MENSAJE POR PANTALLA
		return false
	}
	
	if(f_nac.length!=0)
	{
		anyos = calcular_edad(f_nac);
		if(anyos < 23)
		{
			alert ('La edad mínima para alquilar un vehículo son 23 años');
			return false
		}
	}
	

}

// CON SEGUNDO CONDUCTOR
function validacion_cliente21(pais, nom, ape, numper, tel, f_nac, email, dir, pob, cp, domp, pobp, nom_seg, numper2)
{
	var er_email = /^(.+\@.+\..+)$/

	if((pais=="Seleccione pais") || (nom.length == 0)||(ape.length == 0)||(numper.length == 0)||(tel.length == 0)||(email.length == 0)||(dir.length == 0)||(pob.length == 0)||(cp.length == 0)||(domp.length == 0)||(pobp.length == 0)|| (nom_seg.length ==0) || (numper2.length== 0))
	{
		alert("Debe completar todos los campos obligatorios");
		return false;
	}

	if(!er_email.test(email)) 
	{ 
       		alert('Campo e-mail no válido.')
       		return false;
    	}
	
	if(validarfecha(f_nac)==false)
	{
		alert("Formato de fecha de nacimiento incorrecto");	//MENSAJE POR PANTALLA
		return false
	}
	
	if(f_nac.length!=0)
	{	
		anyos = calcular_edad(f_nac);
		if(anyos < 23)
		{
			alert ('La edad mínima para alquilar un vehículo son 23 años');
			return false
		}
	}
	
}

function validacion_cliente22(pais, nom, ape, numper, tel, f_nac, email, dir, pob, cp, domp, pobp, nom_seg, numper2, nom_seg2, numper22)
{
	var er_email = /^(.+\@.+\..+)$/

	if((pais=="Seleccione pais") || (nom.length == 0)||(ape.length == 0)||(numper.length == 0)||(tel.length == 0)||(email.length == 0)||(dir.length == 0)||(pob.length == 0)||(cp.length == 0)||(domp.length == 0)||(pobp.length == 0)|| (nom_seg.length ==0) || (numper2.length== 0) || (nom_seg2.length ==0) || (numper22.length== 0))
	{
		alert("Debe completar todos los campos obligatorios");
		return false;
	}

	if(!er_email.test(email)) 
	{ 
       		alert('Campo e-mail no válido.')
       		return false;
    	}
		
	if(validarfecha(f_nac)==false)
	{
		alert("Formato de fecha de nacimiento incorrecto");	//MENSAJE POR PANTALLA
		return false
	}
	if(f_nac.length!=0)
	{	
		anyos = calcular_edad(f_nac);
		if(anyos < 23)
		{
			alert ('La edad mínima para alquilar un vehículo son 23 años');
			return false
		}
	}
}

function validacion_cliente23(pais, nom, ape, numper, tel, f_nac, email, dir, pob, cp, domp, pobp, nom_seg, numper2, nom_seg2, numper22, nom_seg3, numper23)
{
	var er_email = /^(.+\@.+\..+)$/

	if((pais=="Seleccione pais") || (nom.length == 0)||(ape.length == 0)||(numper.length == 0)||(tel.length == 0)||(email.length == 0)||(dir.length == 0)||(pob.length == 0)||(cp.length == 0)||(domp.length == 0)||(pobp.length == 0)|| (nom_seg.length ==0) || (numper2.length== 0) || (nom_seg2.length ==0) || (numper22.length== 0) || (nom_seg3.length ==0) || (numper23.length== 0))
	{
		alert("Debe completar todos los campos obligatorios");
		return false;
	}

	if(!er_email.test(email)) 
	{ 
       		alert('Campo e-mail no válido.')
       		return false;
    	}
	
	if(validarfecha(f_nac)==false)
	{
		alert("Formato de fecha de nacimiento incorrecto");	//MENSAJE POR PANTALLA
		return false
	}
	
	if(f_nac.length!=0)
	{
		anyos = calcular_edad(f_nac);
		if(anyos < 23)
		{
			alert ('La edad mínima para alquilar un vehículo son 23 años');
			return false
		}
	}
}

/*****************************************************************************************************************/
/*****************************************************************************************************************/
/*****************************************************************************************************************/
/*****************************************************************************************************************/
/************************************************ AGENCIAS *******************************************************/
/*****************************************************************************************************************/
/*****************************************************************************************************************/
/*****************************************************************************************************************/
/*****************************************************************************************************************/

//validamos el registro de las agencias
function validacion_registroa(nom, tel, ema, dir, pob, cp, cif, nac, fax, con)
{
	var er_email = /^(.+\@.+\..+)$/
	
	if((nom.length == 0)||(tel.length == 0)||(ema.length == 0)||(dir.length == 0)||(pob.length == 0)||(cp.length == 0)||(cif.length == 0)||(fax.length == 0)|| (nac.length ==0)|| (con.length ==0))
	{
		alert("Debe completar todos los campos obligatorios");
		return false;
	}
	
	if(!er_email.test(ema)) 
	{ 
       	alert('Campo e-mail no válido.')
       	return false;
   	}
}

function validacion_agencia(codigo, clave)
{
/*	var er_agn = /^[0-9]{1,8}$/
	
	if(!er_agn.test(codigo)) 
	{ 
       		alert("Código de agencia no válido.")
       		return false;
    }
*/
	if(clave.length < 0 || clave.length > 8)
	{
		alert("Contraseña no válida.")
		
		return false
	}
}	


// CALCULAR LA FECHA ACTUAL EN FORMATO: DD/MM/AAAA

function devuelve_hoy()
{
	var today = new Date();
	var today = new Date();
  	var day   = today.getDate();
  	var month = today.getMonth();
  	var year  = today.getYear();
  	var dia = today.getDay();
	var hora = today.getHours();
	var minutos = today.getMinutes();
		
	month=month+1;
			
	if (day == "1") 
		day = "01";
	if (day == "2") 
		day = "02";
	if (day == "3") 
		day = "03";
	if (day == "4") 
		day = "04";
	if (day == "5") 
		day = "05";
	if (day == "6") 
		day = "06";
	if (day == "7") 
		day = "07";
	if (day == "8") 
		day = "08";
	if (day == "9") 
		day = "09";
	if (month == "1") 
		month = "01";
	if (month == "2") 
		month = "02";
	if (month == "3") 
		month = "03";
	if (month == "4") 
		month = "04";
	if (month == "5") 
		month = "05";
	if (month == "6") 
		month = "06";
	if (month == "7") 
		month = "07";
	if (month == "8") 
		month = "08";
	if (month == "9") 
		month = "09";
			
	if(year<1900) year=year+1900;
	var hoy=day + "/" + month + "/" + year;
			
	return hoy;
}

// CALCULAR LA FECHA ACTUAL EN FORMATO: DD/MM/AAAA + 7dias

/*function masSiete()
{
	var today = new Date();
	var today = new Date();
  	var day   = today.getDate();
  	var month = today.getMonth();
  	var year  = today.getYear();
  	var dia = today.getDay();
	var hora = today.getHours();
	var minutos = today.getMinutes();
	
	var day   = day+7;
	
	/*if(var day2>=31)
	{
		var day= var day2 - var day;
		
	}
		
	month=month+1;
			
	if (day == "1") 
		day = "01";
	if (day == "2") 
		day = "02";
	if (day == "3") 
		day = "03";
	if (day == "4") 
		day = "04";
	if (day == "5") 
		day = "05";
	if (day == "6") 
		day = "06";
	if (day == "7") 
		day = "07";
	if (day == "8") 
		day = "08";
	if (day == "9") 
		day = "09";
	if (month == "1") 
		month = "01";
	if (month == "2") 
		month = "02";
	if (month == "3") 
		month = "03";
	if (month == "4") 
		month = "04";
	if (month == "5") 
		month = "05";
	if (month == "6") 
		month = "06";
	if (month == "7") 
		month = "07";
	if (month == "8") 
		month = "08";
	if (month == "9") 
		month = "09";
			
	if(year<1900) year=year+1900;
	var hoy=day + "/" + month + "/" + year;
			
	return hoy;
}

*/
//carga las fechas de mañana y 7 dias despues en el formulario
function fechas() 
{ 
	window.document.reserva.f_recogida.value=manyana();
	window.document.reserva.f_devolucion.value=manyanamassiete();
} 

//NOS DEVUELVE LA FECHA DEL DIA SIGUIENTE + 7
function manyanamassiete()
{
	var today = new Date();
	var dev = new Date();
		
	var segundos=today.getTime()+(8*24*60*60*1000);
	dev.setTime(segundos);
	
	var day   = dev.getDate();
  	var month = dev.getMonth();
  	var year  = dev.getYear();
		
	month=month+1;
				
	if (day == "1") 
		day = "01";
	if (day == "2") 
		day = "02";
	if (day == "3") 
		day = "03";
	if (day == "4") 
		day = "04";
	if (day == "5") 
		day = "05";
	if (day == "6") 
		day = "06";
	if (day == "7") 
		day = "07";
	if (day == "8") 
		day = "08";
	if (day == "9") 
		day = "09";
	if (month == "1") 
		month = "01";
	if (month == "2") 
		month = "02";
	if (month == "3") 
		month = "03";
	if (month == "4") 
		month = "04";
	if (month == "5") 
		month = "05";
	if (month == "6") 
		month = "06";
	if (month == "7") 
		month = "07";
	if (month == "8") 
		month = "08";
	if (month == "9") 
		month = "09";
			
	if(year<1900) year=year+1900;
	var hoy=day + "/" + month + "/" + year;
			
	return hoy;
}

//funcion para obtener mañana

function manyana()
{
	var today = new Date();
	var dev = new Date();
		
	var segundos=today.getTime()+(24*60*60*1000);
	dev.setTime(segundos);
	
	var day   = dev.getDate();
  	var month = dev.getMonth();
  	var year  = dev.getYear();
		
	month=month+1;
				
	if (day == "1") 
		day = "01";
	if (day == "2") 
		day = "02";
	if (day == "3") 
		day = "03";
	if (day == "4") 
		day = "04";
	if (day == "5") 
		day = "05";
	if (day == "6") 
		day = "06";
	if (day == "7") 
		day = "07";
	if (day == "8") 
		day = "08";
	if (day == "9") 
		day = "09";
	if (month == "1") 
		month = "01";
	if (month == "2") 
		month = "02";
	if (month == "3") 
		month = "03";
	if (month == "4") 
		month = "04";
	if (month == "5") 
		month = "05";
	if (month == "6") 
		month = "06";
	if (month == "7") 
		month = "07";
	if (month == "8") 
		month = "08";
	if (month == "9") 
		month = "09";
			
	if(year<1900) year=year+1900;
	var hoy=day + "/" + month + "/" + year;
			
	return hoy;
}

//funcion validacion area agencia X****************************************************************************************
function validacion_panelagenciax(noms, apes, fess, fees, hoss, hoes, accion, suss, sues, nub)
{
	if(validacion_index(fess, fees, hoss, hoes, accion, suss, sues)==false)
		return false;
	if ((noms.length==0)||(apes.length==0)||(nub.length==0)) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
	{
		alert("* Los campos marcados con asterisco son obligatorios");
		return false;
	}	
}

function validacion_panelagenciax2(noms, apes, fess, fees, hoss, hoes, accion, suss, sues)
{
	if(validacion_index(fess, fees, hoss, hoes, accion, suss, sues)==false)
		return false;
	if ((noms.length==0)||(apes.length==0)) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
	{
		alert("* Los campos marcados con asterisco son obligatorios");
		return false;
	}	
}
