/**
 * Validaciond e distintos campos de formulario
 * Mediante expresiones regulares
 * Tambien pueden usarse las mismas expresiones en php
 * @author Javier Lopez
 */


//Expresiones regulares

var nomreg = /^[abcdefghijklmnopqrstuvwxyz]+\s?[abcdefghijklmnopqrstuvwxyz]*$/i;

var wordreg = /^[abcdefghijklmnopqrstuvwxyz1234567890. ,!:-@]*$/i;

var telefonoregC = new RegExp("^2[0-9]{7}$");

var telefonoregM = new RegExp("^7[0-9]{7}$");

var correoreg = /^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;

var anoreg = new RegExp("^19|20[0-9]{2}$");

//Se comprueba el correo electronico
function validarCorreo(id){

if  ( !( correo = document.getElementById(id) ))
	return true;

if(correo.value.length === 0){

	correo.focus();

	alert("Tiene que escribir una direccion de correo");

	return false;

}else{

	if(!correo.value.match(wordreg)){

		correo.focus();

		alert("Por favor escriba una direccion de correo electronico valida");

		return false;

	}

}
return true;

}

function validarTexto(id){

if ( !( campo = document.getElementById(id)  ))
	return true;

if (campo.value.length === 0){

   	campo.focus();

	alert("Este campo no puede ser vac\u00edo");

	return false;

}else{

	if(!(campo.value.match(wordreg))){

		campo.focus();

		alert("Ha escrito un caracter no valido");

		return false;

	}

}

return true;
}


function validarTelefono(id){

if ( !(telefono = document.getElementById(id) ))
	return true;

if(telefono.value.length === 0){
	telefono.focus();
        alert("Por favor escriba un numero telefonico");
	return false;
}else{
        if(!telefono.value.match(wordreg) && !telefono.value.match(telefonoregM)){
                telefono.focus();
                alert("Por favor escriba un numero telefonico v\u00e1lido");
                return false;
        }
}
return true;
}


