//************  FUNCION MensajeLogin **************

function MensajeLogin(){
	alert("To access this sector you have to be registered");
}

function MensajeClubs(){
	alert("Complete contract number of a club.");
}

/******************************************************************************
*****************   FUNCIONES DE Search  ************************
******************************************************************************/

function submitSearch(){

	if(!validaCampoRelleno(document.formSearch.strSearch)){
		return false;
	}
	if(document.formSearch.strSearch.value.indexOf("'")!=-1){
       alert('Do not use simple comma in this field' + document.formSearch.strSearch.title); 
       document.formSearch.strSearch.focus(); // Selección del campo  
       return false;
	}
	document.formSearch.submit();
//	return true;
}

/******************************************************************************
*****************   FUNCIONES DEL MENU  ************************
******************************************************************************/
	function sobre(n,m){
		cual='../../imagenes/'+m+'1.gif'
		n.src=cual
	}
	
	function fuera(n,m){
		cual='../../imagenes/'+m+'0.gif'
		n.src=cual
	}
	
	function activa(n){
		n.style.background='#A38C48'
		n.style.cursor='hand'
	}
	
	function activa2(n,m){
		if(m=="True"){
			n.className='submenOn'
			
		}
		else{
			n.className='subitOn'		
			
		}
		n.style.cursor='hand'
	}

	function desactiva(n){
		n.style.background='#ffffff'
	}

	function desactiva2(n,m){
		if(m=="True"){
			n.className='submenOff1'
		}
		else{
			n.className='submenOff' 			
		}
	}
	
    function sacaSub(n,m){
	if(m!=activo){
		if(activo!=0){
		apagon()
		}
	n.parentNode.className='itemOn'
	subopciones1[m].style.display='block'
	activo=m
	}
	else{
	apagon()
	activo=0
	if(subactivo!=0) subactivo=0
	}
	}
	
	function sacaSub2(n,m){
		if(m!=subactivo){
			if(subactivo!=0){
				subopciones2[subactivo].style.display='none'
				subopciones2[subactivo].parentNode.className='submenOff'
			}
			n.parentNode.className='submen1On'
			subopciones2[m].style.display='block'
			subactivo=m
		}
		else{
			subopciones2[m].style.display='none'
			subopciones2[m].parentNode.className='submenOn'
			subactivo=0
		}
	}
	
	function apagon(){
		subopciones1[activo].style.display='none'
		subopciones1[activo].parentNode.className='itemOff'
		if(subactivo!=0) subopciones2[subactivo].style.display='none'
	}
	
/******************************************************************************
*****************   OTRAS FUNCIONES  DE  VALIDACION GENERAL  ************************
******************************************************************************/

/******************************************************************************
* La función validaPassword, nos valida que el campo login y password estén rellenos
* y tenga un formato correcto. Esta fucnión es la que valida el include memberLogin.inc
* que es el recuadro amarillo de login que aparece en todas las páginas
*******************************************************************************/
function validaPassword(frmLogin){
	if (frmLogin == 'undefined') {
		return false;
	}
	
	if(!validaCampoRelleno(frmLogin.login)){
		return false;
	}
	if(!validaCampoRelleno(frmLogin.pass)){
		return false;
	}
	if(!login_contrasena(frmLogin.pass)){
		return false;
	}		
	return true;
}


/******************************************************************************
* La función IsNumeric, nos valida que el campo sea un número
*******************************************************************************/
function IsNumeric(sNumber)
{
	for ( lPos = 0; lPos < sNumber.length; lPos++ ) {
		var sChar = sNumber.charAt( lPos );
		if ( isNaN( parseInt( sChar ) ) 
   			&& sChar != "-"
     		&& sChar != "+"
     		&& sChar != "."
	   		&& sChar != "," ) {
			return false;
		}
	}
	return true;
}

/******************************************************************************
* La función IsMailAddress, nos valida que el campo email tenga un formato de
* correo correcto
*******************************************************************************/
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,4}|[0-9]{1,3})(\]?)$/; // valid characters
	var end = /\.[a-zA-Z]{2,4}$/; // end of email
	

	if ((Pos < 2) ||				// 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
	{       		
		return false;
	}
  return true;
}

/******************************************************************************
* La función MensajeEmail, contiene el mensaje que se muestra cuando  el email no es
correcto
*******************************************************************************/

function MensajeEmail(campo){
	alert("Field incorrect " + campo.title );
	campo.focus();
}

/******************************************************************************
* La función MensajeError, contiene el mensaje que se muestra cuando un campo no es
correcto
*******************************************************************************/

function MensajeError(campo){
	alert("Field incorrect " + campo.title );
	campo.focus();
}

/******************************************************************************
* La función click, Desactiva el botón derecho del ratón
*******************************************************************************/

function click() {
	if (event.button==2) alert ('This button is out of use.')
}


/******************************************************************************
* La función contador, fuerza a un límite de caracteres los campos
*******************************************************************************/
function contador (campo,cuentacampo,limite)
{
	if (campo.value.length > limite){
		campo.value = campo.value.substring (0, limite);
	}else{
		cuentacampo.value = limite - campo.value.length;
	}	
}

/******************************************************************************
* La función tamanoCampo, también fuerza a un límite de caracteres los campos
* sin utilizar cuentacampo
*******************************************************************************/
function tamanoCampo(nombre,tamano){
	var escritas=nombre.value.length;
	if(escritas>=tamano){
		return false;
	}else{
		return true;
	}
}



/******************************************************************************
* La función validaCampoRelleno, nos valida que el campo indicado esté relleno
*******************************************************************************/
function validaCampoRelleno(campo)
{
	if (campo.value=="")
	{			
		alert("Complete the field " + campo.title);
		campo.focus();
		return false;
	}
	return true;
}
/***************************************************************************************
* La función validaSelectRelleno, nos valida que en el select exista una opción elegida
****************************************************************************************/
function validaSelectRelleno(campoSelect)
{
	var indice=campoSelect.selectedIndex
	if(campoSelect.options[indice].value==-1 || campoSelect.options[indice].value==""){
		alert("Select an option of drop down menu " + campoSelect.title);
		campoSelect.focus();
		return false;
	}	
	return true;
}

/*************************************************************************************************
* La función validaRadioRelleno, nos valida que exista una opción elegida entre los radioButtons
**************************************************************************************************/

function validaRadioRelleno(varRadio,nombreCampo){

	var select=false;
	var i 
	for (i=0;i<varRadio.length;i++){ 
	   if (varRadio[i].checked) 
		 select=true;
	} 
	if (select==false){
		alert("Select option for " + nombreCampo);
		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){
  
    if(numero.value.length==0){
		return true;
    }
	if(isNaN(numero.value)){
       alert('Introduce digits only in this field '+ numero.title); 
       numero.focus(); // Selección del campo  
       return false;
	}
    if(numero.value.indexOf('.')!=-1){
       alert('Do not use decimal points in this field ' + numero.title); 
       numero.focus(); // Selección del campo  
       return false;
	}
	if(numero.value.indexOf(',')!=-1){
       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


/***************************************************************************
* 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){
	if(!validaCampoRelleno(dia)){
			return false;
	}
	if(!validaCampoRelleno(mes)){
			return false;
	}
	if(!validaCampoRelleno(ano)){
			return false;
	}
	 
	if(dia.value.length!=2){
       alert('Introduce two digits in this field ' + dia.title + ', e.g. if “3” write “03”');
	     dia.focus();
	    return false;
   	}
	if(mes.value.length!=2){
       alert('Introduce two digits in this field ' + mes.title + ', e.g. if “3” write “03”');
	    mes.focus();
	    return false;
   	}
	if(ano.value.length!=4){
		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 (!(validar_formato_numero(dia,'dia')&&validar_formato_numero(mes,'mes')&&validar_formato_numero(ano,'año')))
	{
		return false;
	}else if((dia.value >31)||(dia.value <1)){
		// el día introducido tiene que estar comprendido entre los dígitos 1 y 31
		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
	   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
		alert('February has 28 days');
		dia.focus();
	  return false;
	}else if((dia.value>29)&&(mes.value==2)){
		alert('February has 28 days');
		// febrero no puede tener más de 29 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){

	Datos=fecha.value.split('/');

	if (Datos.length<3)
	{
		alert('Introduce correct date in ' + fecha.title + '. (dd/mm/yyyy)');
		fecha.focus();
        return false;
	}	
	 
	if(Datos[0].length!=2){
       alert('Introduce two digits in this field ' + fecha.title + ', e.g. if “3” write “03”');
		fecha.focus();
	    return false;
   	}
	if(Datos[1].length!=2){
       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){
		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)){
       alert('Introduce two digits in the day of '+ fecha.title); 
       fecha.focus(); // Selección del campo  
       return false;
	}
	if(isNaN(mes)){
       alert('Introduce two digits in the month of '+ fecha.title); 
       fecha.focus(); // Selección del campo  
       return false;
	}
	if(isNaN(ano)){
       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
		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
	   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
		alert('February has 28 days');
		fecha.focus();
	  return false;
	}else if((dia>29)&&(mes==2)){
		alert('February has 28 days');
		// febrero no puede tener más de 29 días
		fecha.focus();
        return false;
    }
	// fin del último else

    return true;
 } // Fin de la función validar_formato_fecha_entera

/*********************************************************************************
* La función login_contrasena, nos validará que estos campos tengan una longitud
* mínima de 4 caracteres y que esos caracteres sean letras (may´úsculas, minúsculas)
* , números y los caracteres -, _. 
*********************************************************************************/

function login_contrasena(campo){
	if(campo.value.length==0){
	   return true;
	}
	var caracteres=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0","-","_","@", ".");
	var guardar_caracter=new Array();
	var cierto=0;
	if(campo.value.length < 8){
		alert('The field ' + campo.title +' should be of at least eight characters');
		campo.focus();
		return false;
	} // fin del if
	for(i=0;i<campo.value.length;i++){
		guardar_caracter[i]=campo.value.charAt(i);
		for(j=0;j<caracteres.length;j++){   
			if (guardar_caracter[i]==caracteres[j]){
			   cierto=cierto+1;
			}// cierre del if
	    }// cierre del for j
	}// cierre del for i

    if(cierto!=campo.value.length){
      alert('Introduce only letters, numbers, upper and lower hyphens, points and @ ' + campo.title);
	  campo.focus();
	  return false;
	}// cierre del if
	return true;
}// Fin de la función


/*********************************************************************************
* La función compara_contrasena, nos validará que estos campos sean iguales
*********************************************************************************/

function compara_contrasena( password, passwordConfirmg)
{
	if (password.value!=passwordConfirmg.value)
	{			
		alert("The fields " + password.title + " y " + passwordConfirmg.title + " do not coincide.");
		password.value=""
		passwordConfirmg.value=""
		password.focus();
		return false;
	}
	return true;
}


  /***************************/
 /*abrir popup special offer*/
/***************************/

function ventanaSecundaria (URL){ 
window.open(URL,"ventana1","width=460, height=690, scrollbars=no, menubar=no, location=no, resizable=no") 

} 

