function saca(n,m){
	n.className=n.className.replace('Off', 'On');
	n.style.cursor='hand'
		//if(m==1||m==4){
		cual="subMen"+m
		subMenu=document.getElementById(cual)
		if (subMenu!=null)
		{
			subMenu.style.display='block'
		}
		//}
	}
	
	
function mete(n,m,activo){
	if(m!=activo){
	n.className=n.className.replace('On', 'Off');
	}
		//if(m==1||m==4){
		cual="subMen"+m
		subMenu=document.getElementById(cual)
		if (subMenu!=null)
		{
			subMenu.style.display='none'
		}
		//}
}

function over(n){
n.className=n.className.replace('Off', 'On');
n.style.cursor='hand'
}

function out(n){
n.className=n.className.replace('On', 'Off');
n.style.cursor='hand'
}

function abreDetalle(n){
window.open('detallePais.aspx?id='+n,'pais','height=500,width=570,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=10,top=10')
}

function abreServicio(n){
window.open('detalleServicio.aspx?id='+n,'servicio','height=530,width=955,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=10,top=10')
}

function abreAeropuerto(n){
	if(n!=''){
	window.open('detalleAeropuerto.aspx?id='+n,'aeropuerto','height=455,width=865,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=10,top=10');
	}
}
function abreNoticia(n, m){
window.open('detalleNoticia.aspx?id='+n+'&ch='+m,'noticia','height=460,width=570,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=10,top=10')
}

function abreFormu(n){
window.open(n,'formulario','height=472,width=570,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=10,top=10')
}

function abrePie(n){
window.open(n,'pie','height=472,width=630,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=10,top=10')
}

function abreOferta(n, m){
window.open('detalleOferta.aspx?id='+n+'&ch='+m,'oferta','height=460,width=570,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=10,top=10')
}

function IsMailAddress (sMail)
{
	var Pos    = sMail.indexOf('@')
	var Period   = sMail.lastIndexOf('.')
	var Space    = sMail.indexOf(' ')
	var Length   = sMail.length - 1   // Array is from 0 to length-1
	var invalid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // invalid characters
	var valid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid characters
	var end = /\.[a-zA-Z]{2,3}$/; // end of email

	if ((Pos < 3) ||				// Must be atleast 3 characters before @ sign
		(Period <= Pos+1) ||        // Must be atleast one valid char btwn '@' and '.'
		(Period == Length ) ||      // Must be atleast one valid char after '.'
		(Space  != -1) ||           // No empty spaces permitted
		(invalid.test(sMail)) ||	// Mustn't contain invalid characters
		(!valid.test(sMail)) ||		// Must contain valid characters
		(sMail.search(end) == -1))  // Check email's end
	{  
      //alert("Sorry, this email address seems wrong. Please check it.")
      return false;
	}
	return true;
}



/***************************************************************************
* La función validar_formato_fecha, es una función genérica para validar la
* fecha. Los parámetros que necesita
* son el día, mes y año.
****************************************************************************/


function validar_formato_fecha(dia,mes,ano,showAlert){
	if(!validaCampoRelleno(dia,showAlert)){
			return false;
	}
	if(!validaCampoRelleno(mes,showAlert)){
			return false;
	}
	if(!validaCampoRelleno(ano,showAlert)){
			return false;
	}
	 
	 if (!(validar_formato_numero(dia,showAlert)&&validar_formato_numero(mes,showAlert)&&validar_formato_numero(ano,showAlert)))
	{
		return false;
	}
	 
	 for (i=dia.value.length;dia.value.length<2;i++)
	 {
		dia.value='0'+dia.value;
	 }
	 for (i=mes.value.length;mes.value.length<2;i++)
	 {
		mes.value='0'+mes.value;
	 }
	 if(ano.value.length==1){
		ano.value='200'+ano.value
	 }else if (ano.value.length==2){
		if (ano.value>=50) ano.value='19'+ano.value
		else ano.value='20'+ano.value
	}else if(ano.value.length!=4){
		if (showAlert) alert('Introduce four digits in the year of ' + ano.title );
		ano.focus();
		return false;
    } 
	/*if(dia.value.length!=2){
       if (showAlert) alert('Introduce two digits in this field ' + dia.title + ', e.g. if “3” write “03”');
	     dia.focus();
	    return false;
   	}
	if(mes.value.length!=2){
       if (showAlert) alert('Introduce two digits in this field ' + mes.title + ', e.g. if “3” write “03”');
	    mes.focus();
	    return false;
   	}
	if(ano.value.length!=4){
		if (showAlert) alert('Introduce four digits in the year of ' + ano.title );
		ano.focus();
		return false;
    }*/

    var bisiesto;  // Variable para almacenar el resto de la división 
      //del año introducido por el usuario entre el número 4 para 
      //para comprobar si el año introducido es bisiesto
    bisiesto=ano.value%4;//Asignación a la variable bisiesto del resto del
      //cociente entre el año introducido por usuario y el número 4 (cada 4 años
      // es año bisiesto)
    if (ano.value%4==0&&(ano.value%100!=0 || ano.value%400==0))
    {
		bisiesto=0;
    }else{
		bisiesto=-1;
	}
	

	if((dia.value >31)||(dia.value <1)){
		// el día introducido tiene que estar comprendido entre los dígitos 1 y 31
		if (showAlert) alert('Introduce a day between 1 and 31'); 
		dia.focus();
		return false;
	}else if((mes.value >12)||(mes.value <1)){
		// el mes introducido tiene que estar comprendido entre los dígitos 1 y 12
	   if (showAlert) alert('Introduce a month between 1 and 12'); 
	   mes.focus();
	   return false;
	}else if((dia.value>=29)&&(mes.value==2)&&(bisiesto!=0)){
		// comprobación si el año introducido es bisiesto o no lo es
		if (showAlert) alert('February has 28 days');
		dia.focus();
	  return false;
	}else if((dia.value>29)&&(mes.value==2)){
		if (showAlert) alert('February has 29 days');
		// febrero no puede tener más de 29 días
		dia.focus();
        return false;
    }else if (dia.value==31 && (mes.value==4 || mes.value==6 || mes.value==9 || mes.value==11)){
		if (showAlert) alert('The month has 30 days');
		// marzo, junio, septiembre y noviembre no pueden tener más de 30 días
		dia.focus();
        return false;
    }
	// fin del último else
    return true;
 } // Fin de la función validar_formato_fecha

/***************************************************************************
* La función validar_formato_fecha, es una función genérica para validar la
* fecha. Los parámetros que necesita
* son el día, mes y año.
****************************************************************************/


function validar_formato_fecha_entera(fecha,showAlert){

	Datos=fecha.value.split('/');

	if (Datos.length<3)
	{
		if (showAlert) alert('Introduce correct date in ' + fecha.title + '. (dd/mm/yyyy)');
		fecha.focus();
        return false;
	}	
	 
	if(Datos[0].length!=2){
       if (showAlert) alert('Introduce two digits in this field ' + fecha.title + ', e.g. if “3” write “03”');
		fecha.focus();
	    return false;
   	}
	if(Datos[1].length!=2){
       if (showAlert) alert('Introduce two digits in the month of ' + fecha.title + ', e.g. if “3” write “03”');
	    fecha.focus();
	    return false;
   	}
	if(Datos[2].length!=4){
		if (showAlert) alert('Introduce four digits in the year of ' + fecha.title );
		fecha.focus();
		return false;
    }

	dia=Datos[0]
	mes=Datos[1]
	ano=Datos[2]

    var bisiesto;  // Variable para almacenar el resto de la división 
      //del año introducido por el usuario entre el número 4 para 
      //para comprobar si el año introducido es bisiesto
    bisiesto=ano%4;//Asignación a la variable bisiesto del resto del
      //cociente entre el año introducido por usuario y el número 4 (cada 4 años
      // es año bisiesto)
    if (ano%4==0&&(ano%100!=0 || ano%400==0))
    {
		bisiesto=0;
    }else{
		bisiesto=-1;
	}
	

	
	if(isNaN(dia)){
       if (showAlert) alert('Introduce two digits in the day of '+ fecha.title); 
       fecha.focus(); // Selección del campo  
       return false;
	}
	if(isNaN(mes)){
       if (showAlert) alert('Introduce two digits in the month of '+ fecha.title); 
       fecha.focus(); // Selección del campo  
       return false;
	}
	if(isNaN(ano)){
       if (showAlert) alert('Introduce four digits in the year of '+ fecha.title); 
       fecha.focus(); // Selección del campo  
       return false;
	}

	if((dia >31)||(dia <1)){
		// el día introducido tiene que estar comprendido entre los dígitos 1 y 31
		if (showAlert) alert('Introduce a day between 1 and 31'); 
		fecha.focus();
		return false;
	}else if((mes >12)||(mes <1)){
		// el mes introducido tiene que estar comprendido entre los dígitos 1 y 12
	   if (showAlert) alert('Introduce a month between 1 and 12'); 
	   fecha.focus();
	   return false;
	}else if((dia>=29)&&(mes==2)&&(bisiesto!=0)){
		// comprobación si el año introducido es bisiesto o no lo es
		if (showAlert) alert('February has 28 days');
		fecha.focus();
	  return false;
	}else if((dia>29)&&(mes==2)){
		if (showAlert) alert('February has 29 days');
		// febrero no puede tener más de 29 días
		fecha.focus();
        return false;
    }else if (dia.value==31 && (mes.value==4 || mes.value==6 || mes.value==9 || mes.value==11)){
		if (showAlert) alert('The month has 30 days');
		// marzo, junio, septiembre y noviembre no pueden tener más de 30 días
		dia.focus();
        return false;
    }
	// fin del último else

    return true;
 } // Fin de la función validar_formato_fecha_entera



/******************************************************************************
* La función validaCampoRelleno, nos valida que el campo indicado esté relleno
*******************************************************************************/
function validaCampoRelleno(campo,showAlert)
{
	if (campo.value=="")
	{			
		if (showAlert) alert("Complete the field " + campo.title);
		campo.focus();
		return false;
	}
	return true;
}
/******************************************************************************
* La función validar_formato_numero, nos valida la existencia de números enteros!!!
* en un campo que debe de ser numérico.Recibe un parámetro, el valor del campo
* del formulario a evaluar. No permite ni puntos ni comas.
*******************************************************************************/

function validar_formato_numero(numero,showAlert){
  
    if(numero.value.length==0){
		return true;
    }
	if(isNaN(numero.value)){
       if (showAlert) alert('Introduce digits only in this field '+ numero.title); 
       numero.focus(); // Selección del campo  
       return false;
	}
    if(numero.value.indexOf('.')!=-1){
       if (showAlert) alert('Do not use decimal points in this field ' + numero.title); 
       numero.focus(); // Selección del campo  
       return false;
	}
	if(numero.value.indexOf(',')!=-1){
       if (showAlert) alert('Do not use decimal comma in this field ' + numero.title); 
       numero.focus(); // Selección del campo  
       return false;
	}
  
	return true;
} // Fin de la función validar_formato_numero

function marcaChecks(chk)
{
	f = document.forms[0];
	if (f!=null && chk!=null)
	{
		n=f.length; //nº de elementos
		bTable = false; //Elemento todos
		for ( i=0; i<n ; i++) //recorremos elementos del formulario
		{
			element = f.elements[i];
			
			if (element == chk)
			{
				//Se trata del check "Todos"
				bTable = true;
			}
			else if (element.id.indexOf("Aeropuerto_") != 0)
			{
				//Se trata de un check que no representa a un aeropuerto
				bTable = false;
			}
			else if (bTable==true)
			{
				//Se trata de un check que representa a un aeropuerto del grupo "Todos" correspondiente
				f.elements[i].checked = chk.checked;
			}
		}
	}
}

function desmarcaCheck(chk)
{
	f = document.forms[0];
	
	if (f!=null && chk!=null && chk.checked==false)
	{
		last = null;
		n=f.length; //nº de elementos
		for ( i=0; i<n ; i++) //recorremos elementos del formulario
		{
			element = f.elements[i];
			if (element.id.indexOf("Aeropuerto_") != 0)
			{
				//Se trata de un elemento que no es de un aeropuerto
				last = element;
			}
			else if (last!=null && chk==element)
			{
				//Se trata del check pinchado, desmarcar el ultimo check que no representaba a un aeropuerto
				last.checked = false;
				return;
			}
		}
	}
}


