/***************** 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]  = "January";
  this_month[1]  = "February";
  this_month[2]  = "March";
  this_month[3]  = "April";
  this_month[4]  = "May";
  this_month[5]  = "June";
  this_month[6]  = "July";
  this_month[7]  = "August";
  this_month[8]  = "September";
  this_month[9]  = "October";
  this_month[10] = "November";
  this_month[11] = "December";

  var this_day_e = new makeArray(7);
  this_day_e[0]  = "Sunday";
  this_day_e[1]  = "Monday";
  this_day_e[2]  = "Tuesday";
  this_day_e[3]  = "Wednesday";
  this_day_e[4]  = "Thursday";
  this_day_e[5]  = "Friday";
  this_day_e[6]  = "Saturday";

  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( " " + this_day_e[dia] + ", " + day + " de " + this_month[month] + " " + year);
  month=month+1;
	return( day + "/" + month + "/" + year);
}

/************************************************************************************************************/

/************************************************ añadir a favoritos ****************************************/

function favoritos()
{
	var direccion="http://www.solmar.es"; 
	var titulo="Sol-Mar, Car hire"; 
	var ns = "To Add this page on your Bookmarks, <br> please click : <b>[Ctrl] + [ D ]</b> "; 
		
	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(" 'Add Sol-Mar rent a car on your Bookmarks.'; return true ") 
		document.write(' " onMouseOut="window.status= ') 
		document.write(" ' '; return true ") 
		document.write(' ">Add Sol-Mar rent a car on your Bookmarks</a>') }  
}

/*************************************************************************************************************/

/******************************************* abre un pop up para oficinas ************************************/

function AbrirVentana(pagina,nombreventana) 
{
	myWin=window.open(pagina,nombreventana,'width=530,height=520,top=150,left=300,toolbar=no,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,top=150,left=300,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") 
}  
/*************************************************************************************************************/

/***************************** MUESTRA TABLA DE VEHÍCULOS ****************************************************/
function viewHide(id, origen) 
{
			var targetId, srcElement, targetElement;
			var targetElement;
			
			targetElement = document.getElementById('7');
			targetElement.style.display = "none";
			targetElement = document.getElementById('1');
			targetElement.style.display = "none";
			targetElement = document.getElementById('2');
			targetElement.style.display = "none";
			targetElement = document.getElementById('3');
			targetElement.style.display = "none";
			targetElement = document.getElementById('4');
			targetElement.style.display = "none";
			targetElement = document.getElementById('6');
			targetElement.style.display = "none";
			targetElement = document.getElementById('8');
			targetElement.style.display = "none";
			targetElement = document.getElementById('9');
			targetElement.style.display = "none";
			targetElement = document.getElementById('10');
			targetElement.style.display = "none";
			if(origen=='web')
			{
				targetElement = document.getElementById('99');
				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;
            }
        }
}

//COMPARAR FECHAS
function Comparar_Fecha(String1,String2, anyohoy) 
{
//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("The introduced date should be in numbers");
     	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("The introduced month is not valid, Please put the correct month in");
           return false;
    }
       
    if ((mes1==2) && ((dia1<1) || (dia1>febrero)))
    {
           alert("The introduced day is not valid, Please put the correct day in");
           return;
    }
	if ((mes2==2) && ((dia2<1) || (dia2>febrero)))
    {
           alert("The introduced day is not valid, Please put the correct day in");
           return;
    }
	
	if (((mes1==1) || (mes1==3) || (mes1==5) || (mes1==7) || (mes1==8) || (mes1==10) || (mes1==12)) && ((dia1<1) || (dia1>31)))
    {
           alert("The introduced day is not valid, Please put the correct day in");
           return false;
    }
       
   if (((mes1==4) || (mes1==6) || (mes1==9) || (mes1==11)) && ((dia1<1) || (dia1>30)))
   {
	   alert("The introduced day is not valid, Please put the correct day in");
	   return false;
   }
   if (((mes2==1) || (mes2==3) || (mes2==5) || (mes2==7) || (mes2==8) || (mes2==10) || (mes2==12)) && ((dia2<1) || (dia2>31)))
    {
           alert("The introduced day is not valid, Please put the correct day in");
           return false;
    }
       
   if (((mes2==4) || (mes2==6) || (mes2==9) || (mes2==11)) && ((dia2<1) || (dia2>30)))
   {
	   alert("The introduced day is not valid, Please put the correct day in");
	   return false;
   }
   
   if ((anyo1<anyohoy) || (anyo1>anyohoy+2))
   {
           alert("The introduced year is not valid.");
		   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)
	{
		return false;	//fecha1>fecha2
	}
	
	if ((anyo1==anyo2) && (mes1>mes2))
	{
		return false;
	}
	if ((anyo1==anyo2) && (mes1==mes2) && (dia1>dia2))
	{
		return false;
	} 
	
	return true;
}
/********************************************************/


function validacion_index(fecha1, fecha2, h1, h2, sus, sue)
{		
			
	/**************************** VALIDACIÓN FECHAS *********************************/

			if (fecha1.length != 10) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("The pick up Date format is not correct");	//MENSAJE POR PANTALLA
				return false;
			}

			if (fecha2.length != 10) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("The drop off Date format is not correct");
				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("Date format is not correct");	//MENSAJE POR PANTALLA
				return false;
			}


			if (fecha1.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Please, introduce pick up date");	//MENSAJE POR PANTALLA
				return false;
			}

			if (fecha2.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Please, introduce drop off date");
				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);
			if (retorno1==false)
			{
				alert("The drop off date cannot be earlier than pick up date");
				return false;
			}
			else if(retorno1!=true)
			{
				return false;
			}
			
			h1i=parseInt(h1,10)
			h2i=parseInt(h2,10)
						
			if((fecha1==fecha2)&&(h1i>=h2i))
			{
				alert("date and time drop off should be after the picking up date and time.");
				return false;
			}
										
			var retorno2;
			retorno2 = Comparar_Fecha(hoy, fecha1, year);
			
			if (retorno2==false)
			{
				alert("The pick up date cannot be prior/ before to today");
				return false;
			}
			else if(retorno2!=true)
				return false;
			
			if(minutos==0)
				hora=hora+1
			
			h=parseInt(hora,10)
		
			if ((fecha1==hoy) && (h>=h1i))
			{
				alert("Pick up time cannot be prior to the actual time");
				return false;
			}
			retorno2=Comparar_Fecha('10/01/2007',fecha1, year);
			if(((sus=='BC') || (sue=='BC') ) && (retorno2==false))
			{
				alert("Lo sentimos. Nuestras oficinas en Barcelona no estarán operativas hasta el 10 de enero. 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("Please introduce your name");	//MENSAJE POR PANTALLA
				return false;
			}

			if (poblacion.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Please, introduce your City");
				return false;
			}

			if (provincia.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Please, introduce your Country");	//MENSAJE POR PANTALLA
				return false;
			}

			if (edad.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Please, introduce your age");
				return false;
			}
			if (nacionalidad.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Please, introduce your Nationality");	//MENSAJE POR PANTALLA
				return false;
			}

			if (telf.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Please, introduce your telephone number");
				return false;
			}
			
			if (email.length == 0) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Please, introduce your e-mail address");	//MENSAJE POR PANTALLA
				return false;
			}
			
			if (idiomas.length == 8) //SI ESTÁ VACIO MOSTRAMOS MENSAJE Y SALIMOS DE LA FUNCION
			{
				alert("Please, how many languages do you speak?");
				return false;
			}
			
			var er_email = /^(.+\@.+\..+)$/
			
			if(!er_email.test(email)) 
			{ 
				//       		alert('Invalid e-mail address.')
			alert(email)
				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("Fields marked with an asterisk are required")
		return false
	}
	
	if(!er_email.test(email)) 
	{ 
       		       		alert('Invalid e-mail address.')
			
       		return false
    }
	
	if(validarfecha(f_nac)==false)
	{
		alert("D.O.B. format is not correcto");	//MENSAJE POR PANTALLA
		return false
	}
	
	if(f_nac.length!=0)
	{
		anyos = calcular_edad(f_nac);
		if(anyos < 23)
		{
			alert ('The minimum age required to rent a car is 23 years old');
			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((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("Fields marked with an asterisk are required");
		return false;
	}

	if(!er_email.test(email)) 
	{ 
       		      		alert('Invalid e-mail address.')
			
       		return false;
    	}
		
	if(validarfecha(f_nac)==false)
	{
		alert("D.O.B. format is not correcto");	//MENSAJE POR PANTALLA
		return false
	}
	
	if(f_nac.length!=0)
	{	
		anyos = calcular_edad(f_nac);
		if(anyos < 23)
		{
			alert ('The minimum age required to rent a car is 23 years old');
			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((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("	Fields marked with an asterisk are required");
		return false;
	}

	if(!er_email.test(email)) 
	{ 
alert('Invalid e-mail address.')

       		return false;
    	}
		
	if(validarfecha(f_nac)==false)
	{
		alert("D.O.B. format is not correcto");	//MENSAJE POR PANTALLA
		return false
	}
	
		
	anyos = calcular_edad(f_nac);
	if(anyos < 23)
	{
		alert ('The minimum age required to rent a car is 23 years old');
		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((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("	Fields marked with an asterisk are required");
		return false;
	}

	if(!er_email.test(email)) 
	{ 
       		       		alert('Invalid e-mail address.')

       		return false;
    	}
	
	if(validarfecha(f_nac)==false)
	{
		alert("D.O.B. format is not correcto");	//MENSAJE POR PANTALLA
		return false
	}
	anyos = calcular_edad(f_nac);
	if(anyos < 23)
	{
		alert ('The minimum age required to rent a car is 23 years old');
		return false
	}
}

//validamos el registro de las agencias
function validacion_registroa(nom, tel, ema, dir, pob, cp, cif, nac, fax)
{
	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))
	{
		alert("	Fields marked with an asterisk are required");
		return false;
	}
	
	if(!er_email.test(email)) 
	{ 
       		alert('Invalid e-mail address.')

       	return false;
   	}
}

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;
}