function validarCIF(cif){
					
{
par = 0
non = 0
letras="ABCDEFGHKLMNPQS"
let=cif.charAt(0)

if (!isNaN(let))
  {
  nif=cif
  validar(nif)
  return false
  }

if (cif.length!=9)
  {
  alert('El Cif debe tener 9 dígitos.')
  document.formulario.nif.focus()
  return false
  }

if (letras.indexOf(let.toUpperCase())==-1)
  {
  alert("El comienzo del Cif no es válido.")
  document.formulario.nif.focus()
  return false
  }

for (zz=2;zz<8;zz+=2)
  {
  par = par+parseInt(cif.charAt(zz))
  }

for (zz=1;zz<9;zz+=2)
  {
  nn = 2*parseInt(cif.charAt(zz))
  if (nn > 9) nn = 1+(nn-10)
  non = non+nn
}

parcial = par + non

control = (10 - ( parcial % 10))

if (control==10) control=0

if (control!=cif.charAt(8))
  {
  alert("Por favor, inserte un CIF valido.")
  document.formulario.nif.focus()
  return false
  }
return true;
}

function validar(abc)
{
dni=abc.substring(0,abc.length-1)
let=abc.charAt(abc.length-1)
if (!isNaN(let))
 {
  alert('Por favor, inserte la letra del campo CIF.')
  document.formulario.nif.focus()
  return false
 }
else
 {
  cadena="TRWAGMYFPDXBNJZSQVHLCKET"
  posicion = dni % 23
  letra = cadena.substring(posicion,posicion+1)
  if (letra!=let.toUpperCase())
   {
    alert("Por favor, inserte un NIF valido.")
    document.formulario.nif.focus()
    return false
   }
 }

return true;
}
			
				}





function validarEmail(valor,formulario) {

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
	} else {
		alert("Por favor, indique una dirección de email correcta.");
       document.formulario.valor.focus();
       return 0;
		}
}


function validarEntero(valor){ 
      //intento convertir a entero. 
     //si era un entero no le afecta, si no lo era lo intenta convertir 
     valor = parseInt(valor) 

      //Compruebo si es un valor numérico 
      if (isNaN(valor)) { 
            //entonces (no es número) devuelvo el valor cadena vacia 
            return "" 
      }else{ 
            //En caso contrario (Si era un número) devuelvo el valor 
            return valor 
      } 
} 


function Fecha(Cadena){  
    var Fecha= new String(Cadena)   // Crea un string  
    var RealFecha= new Date()   // Para sacar la fecha de hoy  
    //Cadena Año  
    var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))  
    // Cadena Mes  
    var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))  
    // Cadena Día  
    var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))  
  
    // Valido el año  
    if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){  
       //alert('Año inválido')  
        return false  
    }  
    //Valido el Mes  
    if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){  
       // alert('Mes inválido')  
        return false  
    }  
    //Valido el Dia  
    if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){  
      //  alert('Día inválido')  
        return false  
    }  
    if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {  
        if (Mes==2 && Dia > 28 || Dia>30) {  
          //  alert('Día inválido')  
            return false  
        }  
    }  
      
  //para que envie los datos, quitar las  2 lineas siguientes  
}  
function valida(){

	// COMIDA SIN SELECCIONAR
    if (document.formulario.comida.selectedIndex==0){
       alert("Por favor, indique un tipo de servicio.")
       document.formulario.comida.focus()
       return 0;
    }
	
	// POBLACION VACIO
    if (document.formulario.poblacion.value.length==0){
       alert("Por favor, inserte una población.");
       document.formulario.poblacion.focus()
       return 0;
    }
	
	// VALIDA FECHA
	if (Fecha(document.formulario.date.value)==false) { alert('Por favor, inserte una fecha correcta.'); return 0; }  

	// PERSONAS VACIO
	if (document.formulario.personas.value.length==0){
       alert("Por favor, inserte un número de personas.");
       document.formulario.personas.focus()
       return 0;
	}
	
	// NUMERO PERSONAS
	var personas = document.formulario.personas.value;
    personas = validarEntero(personas);
    document.formulario.personas.value=personas;
    if (personas==""){
       alert("Por favor, inserte un número de personas válido.")
       document.formulario.personas.focus()
       return 0;
    }
	
	//PPP NO ES FLOAT
	var ppp = document.formulario.ppp.value;

	var pppFloat = parseFloat(ppp);
	
	var pppOk = isNaN(parseFloat(ppp));
	
	if(pppOk == true){
		alert('Precio por personas no es un importe válido.');
		return 0;
	}

document.getElementById("accion").value = "Añadir";
document.formulario.submit();


} 	



function valida02(){

	// NOMBRE
    if (document.newuser.nombre.value.length==0){
       alert("Por favor, indique el nombre de la agencia u organizador de grupo.");
       document.newuser.nombre.focus();
       return 0;
    }

	// RAZON SOCIAL
    if (document.newuser.razonsocial.value.length==0){
       alert("Por favor, indique la razón social de la empresa.");
       document.newuser.razonsocial.focus();
       return 0;
    }

	// CONTACTO
    if (document.newuser.contacto.value.length==0){
       alert("Por favor, indique la persona de contacto.");
       document.newuser.contacto.focus();
       return 0;
    }
	
	// DIRECCION
    if (document.newuser.direccion.value.length==0){
       alert("Por favor, indique la dirección.");
       document.newuser.direccion.focus();
       return 0;
    }

    if (document.newuser.cif.value.length!=0){
		if( (validarCIF(document.getElementById('cif').value)) == false ) { 
		     document.newuser.cif.focus();
			 return 0; 
		}
	}
	// LOCALIDAD
    if (document.newuser.localidad.value.length==0){
       alert("Por favor, indique la localidad.");
       document.newuser.localidad.focus();
       return 0;
    }
	
	// PROVINCIA
    if (document.newuser.provincia.value.length==0){
       alert("Por favor, indique la provincia.");
       document.newuser.provincia.focus();
       return 0;
    }
	
	// CODIGO POSTAL
    if (document.newuser.codigopostal.value.length==0){
       alert("Por favor, indique el codigo postal.");
       document.newuser.codigopostal.focus();
       return 0;
    }
	
	if((/^[0-9]{1,}$/).exec(document.newuser.codigopostal.value)==null){ 
        alert("Por favor inserte un código postal válido."); 
        document.newuser.codigopostal.focus(); 
        return false; 
    }


//CIF






	// PAIS
    if (document.newuser.pais.value.length==0){
       alert("Por favor, indique su país.");
       document.newuser.pais.focus();
       return 0;
    }
	
	// TELEFONO 1
    if (document.newuser.telefono1.value.length==0){
       alert("Por favor indique su teléfono principal.");
       document.newuser.telefono1.focus();
       return 0;
    }

	if((/^[0-9]{1,}$/).exec(document.newuser.telefono1.value)==null){ 
        alert("Por favor inserte un teléfono válido."); 
        document.newuser.telefono1.focus(); 
        return false; 
    }
	
    if (document.newuser.telefono2.value.length>0){
		if((/^[0-9]{1,}$/).exec(document.newuser.telefono2.value)==null){ 
			alert("Por favor inserte un teléfono 2 válido."); 
			document.newuser.telefono2.focus(); 
			return false; 
		}
    }

	// FAX 1
    if (document.newuser.fax1.value.length==0){
       alert("Por favor, indique su fax principal.");
       document.newuser.fax1.focus();
       return 0;
    }

	if((/^[0-9]{1,}$/).exec(document.newuser.fax1.value)==null){ 
        alert("Por favor inserte un fax válido."); 
        document.newuser.fax1.focus(); 
        return false; 
    }

    if (document.newuser.fax2.value.length>0){
		if((/^[0-9]{1,}$/).exec(document.newuser.fax2.value)==null){ 
			alert("Por favor inserte un fax 2 válido."); 
			document.newuser.fax2.focus(); 
			return false; 
		}
    }

	
	// MAIL
    if (document.newuser.mail.value.length==0){
       alert("Por favor, indique su e-mail de contacto.");
       document.newuser.mail.focus();
       return 0;
    }else{validarEmail(document.newuser.mail.value,'newuser');}
	

	// USUARIO
    if (document.newuser.usuario.value.length<4){
       alert("Por favor, indique un nombre de usuario válido.");
       document.newuser.usuario.focus();
       return 0;
    }

	// CLAVE
    if (document.newuser.contrasena2.value.length<4){
       alert("Por favor, inserte una contraseña válida.");
       document.newuser.contrasena2.focus();
       return 0;
    }
	
	// REPITA CLAVE
    if (document.newuser.contrasena.value.length<4){
       alert("Por favor, inserte una contraseña válida.");
       document.newuser.contrasena.focus();
       return 0;
    }
	
	if(document.newuser.contrasena.value != document.newuser.contrasena2.value){
		alert("Por favor, revise su contraseña, no coinciden los dos campos.");
		document.newuser.contrasena.focus();
		document.newuser.contrasena.value ="";
		document.newuser.contrasena2.value ="";
		return 0;
	}
	
	// COMIDA SIN SELECCIONAR
    if (document.newuser.donde.selectedIndex==0){
       alert("Por favor, indique dónde nos encontró.");
       document.newuser.donde.focus();
       return 0;
    }
	
	
	// ACEPTO LAS CONDICIONES
	if(document.newuser.acepto.checked!=true){ 
		alert('Por favor, acepte las condiciones generales.'); 
		return 0;
	
	}
	
	// CAPTCHA
	if(document.newuser.code.value.length==0){
		alert('Por favor rellene el validador.');
		return 0;
	
	}
	
	document.newuser.submit();


} 	


function valida03(){
	

// Referencia
    if (document.formulario.referencia.value.length==0){
       alert("Por favor, indique una referencia de grupo.");
       document.formulario.referencia.focus();
       return 0;
    }

// Persona de contacto
    if (document.formulario.contacto.value.length==0){
       alert("Por favor, indique una persona de contacto.");
       document.formulario.contacto.focus();
       return 0;
    }

// Condiones
	if(document.formulario.acepto.checked!=true){ 
		alert('Por favor, acepte las condiciones generales.'); 
		return 0;
	}


	document.getElementById("accion").value = "Envio";
	document.formulario.submit();
} 	


function validaContacto(){

    if (document.contacto.nombre.value.length==0){
       alert("Por favor, indique el nombre del establecimiento.");
       document.contacto.nombre.focus();
       return 0;
    }

    if (document.contacto.personacontacto.value.length==0){
       alert("Por favor, indique el nombre de la persona de contacto.");
       document.contacto.personacontacto.focus();
       return 0;
    }

    if (document.contacto.mail.value.length==0){
       alert("Por favor, indique su e-mail de contacto.");
       document.contacto.mail.focus();
       return 0;
    }else{validarEmail(document.contacto.mail.value,'contacto');}

    if (document.contacto.telefono.value.length==0){
       alert("Por favor, indique un número de teléfono.");
       document.contacto.telefono.focus();
       return 0;
    }

    if (document.contacto.telefono.value.length>0){
		if((/^[0-9]{1,}$/).exec(document.contacto.telefono.value)==null){ 
			alert("Por favor, indique un número de teléfono válido."); 
			document.contacto.telefono.focus(); 
			return false; 
		}
    }


    if (document.contacto.comentario.value.length==0){
       alert("Por favor, rellene el campo comentario.");
       document.contacto.comentario.focus();
       return 0;
    }

	if(document.contacto.acepto.checked!=true){ 
		alert('Por favor, acepte las condiciones generales.'); 
		return 0;
	}

	document.contacto.submit();

}

function validaSugerencias(){

    if (document.contacto.nombre.value.length==0){
       alert("Por favor, indique el nombre del establecimiento.");
       document.contacto.nombre.focus();
       return 0;
    }

    if (document.contacto.mail.value.length==0){
       alert("Por favor, indique su e-mail de contacto.");
       document.contacto.mail.focus();
       return 0;
    }else{validarEmail(document.contacto.mail.value,'contacto');}

    if (document.contacto.telefono.value.length==0){
       alert("Por favor, indique un número de teléfono.");
       document.contacto.telefono.focus();
       return 0;
    }

    if (document.contacto.telefono.value.length>0){
		if((/^[0-9]{1,}$/).exec(document.contacto.telefono.value)==null){ 
			alert("Por favor, indique un número de teléfono válido."); 
			document.contacto.telefono.focus(); 
			return false; 
		}
    }


    if (document.contacto.comentario.value.length==0){
       alert("Por favor, rellene el campo comentario.");
       document.contacto.comentario.focus();
       return 0;
    }

	if(document.contacto.acepto.checked!=true){ 
		alert('Por favor, acepte las condiciones generales.'); 
		return 0;
	}

	document.contacto.submit();

}

function validaBoletin(){

    if (document.boletin.email.value.length==0){
       alert("Por favor, indique su e-mail de contacto.");
       document.boletin.email.focus();
       return 0;
    }

    if (document.boletin.email.value.length>0){
		validarEmail(document.boletin.email.value,'boletin.');
	}


	if(document.boletin.acepto.checked!=true){ 
		alert('Por favor, acepte las condiciones generales.'); 
		return 0;
	}

	document.boletin.submit();

}


function validaBuscador(){

	// LOCALIDAD
    if (document.busqueda.localidad.value.length==0){
       alert("Por favor, indique la localidad.");
       document.busqueda.localidad.focus();
       return false;
    }
	
	return true;

}
