function validatemail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.regform.email.value;
   if(reg.test(address)) return true;
   else return false;
}


function delspaces(cadena)
{
	// Funcion equivalente a trim en PHP
	var x=0, y=cadena.length-1;
	while(cadena.charAt(x)==" ") x++;	
	while(cadena.charAt(y)==" ") y--;	
	return cadena.substr(x, y-x+1);
}


function passw(pwd,rpwd){
if(pwd == rpwd){
return true;
}else return false;
	
}


function validatepassword(valor)
{
	/* Funcion encargada de validar lo ingresado por el usuario. Se devuelve TRUE en caso de ser 
	valido, FALSE en caso contrario */
	var reg=/(^[a-zA-Z0-9ñÑ]{6,15}$)/;
	if(reg.test(valor)) return true;
	else return false;
}



function validate(valor)
{
	/* Funcion encargada de validar lo ingresado por el usuario. Se devuelve TRUE en caso de ser 
	valido, FALSE en caso contrario */
	var reg=/(^[a-zA-Z0-9]{6,15}$)/;
	if(reg.test(valor)) return true;
	else return false;
}

function validatecity(valor)
{
	/* Funcion encargada de validar lo ingresado por el usuario. Se devuelve TRUE en caso de ser 
	valido, FALSE en caso contrario */
	var reg=/(^[a-zA-Z0-9.'-ñÑ´áéíóúÁÉÍÓÚÜü ]{2,255}$)/;
	if(reg.test(valor)) return true;
	else return false;
}

function validatename(valor)
{
	/* Funcion encargada de validar lo ingresado por el usuario. Se devuelve TRUE en caso de ser 
	valido, FALSE en caso contrario */
	var reg=/(^[a-zA-Z0-9.'-ñÑ´áéíóúÁÉÍÓÚÜü ]{2,255}$)/;
	if(reg.test(valor)) return true;
	else return false;
}

function dovalidation()
{
var login = document.regform.login.value;
var pwd = document.regform.pwd.value;
var rpwd = document.regform.rpwd.value;
var email = document.regform.email.value;
var birthcountry = document.regform.birthcountry.value;
var birthstate = document.regform.birthstate.value;
var birthcity = document.regform.birthcity.value;
var fname = document.regform.fname.value;
var mname = document.regform.mname.value;
var lname = document.regform.lname.value;
var addname = document.regform.addname.value;
var birthdate = document.regform.birthdate.value;
var gender = document.regform.gender.value;
var familynick = document.regform.familynick.value;
var iobirth = document.regform.iobirth.value;
var codeuserr = document.regform.codeuserr.value;

// ------------------- REQUIRED FIELDS -------------------------------------------------

document.getElementById("error").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
document.getElementById("error3").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
document.getElementById("error4").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
document.getElementById("error6").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
document.getElementById("error7").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
document.getElementById("error8").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
document.getElementById("error9").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
document.getElementById("error11").innerHTML = "<div style='background-color: #EEEEEE;'></div>";

//login
login = delspaces(login);
if( login == "" ){
document.getElementById("error").innerHTML = "El Usuario es obligatorio";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise su USUARIO";
return false;
}else{
document.getElementById("error").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

if(!validate(login)) 
{
document.getElementById("error").innerHTML = "Caracteres invalidos o tamaño del USUARIO incorrecto";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise su USUARIO";
return false;
}else{
document.getElementById("error").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}





//password
login = delspaces(login);
if( pwd == "" || rpwd == ""){
document.getElementById("error11").innerHTML = "Contraseña y Repetir contraseña son obligatorios";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise sus CONTRASEÑAS";
return false;
}else{
document.getElementById("error11").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

if(!validatepassword(pwd) || !validatepassword(rpwd)) 
{
document.getElementById("error11").innerHTML = "Caracteres invalidos o tamaño de sus CONTRASEÑAS incorrecto";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise sus CONTRASEÑAS";
return false;
}else{
document.getElementById("error11").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

if(!passw(pwd,rpwd)){
document.getElementById("error11").innerHTML = "Ambas contraseñas deben ser iguales";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise sus CONTRASEÑAS";
return false;
}else{
document.getElementById("error11").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}


//email
email = delspaces(email);
if( email == "" ){
document.getElementById("error3").innerHTML = "Correo electronico es obligatorio";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise su CORREO ELECTRONICO";
return false;
}else{
document.getElementById("error3").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

if(!validatemail(email)) 
{
document.getElementById("error3").innerHTML = "Correo electronico invalido";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise su CORREO ELECTRONICO";
return false;
}else{
document.getElementById("error3").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

//fname
fname = delspaces(fname);
if( fname == "" ){
document.getElementById("error7").innerHTML = "Primer nombre es obligatorio";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise su PRIMER NOMBRE";
return false;
}else{
document.getElementById("error7").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

//lname
lname = delspaces(lname);
if( lname == "" ){
document.getElementById("error8").innerHTML = "Apellido paterno es obligatorio";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise su APELLIDO PATERNO";
return false;
}else{
document.getElementById("error8").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}
	
//birthcountry
birthcountry = delspaces(birthcountry);
if( birthcountry == "" ){
document.getElementById("error4").innerHTML = "País de nacimiento es obligatorio";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise su PAIS DE NACIMIENTO";
return false;
}else{
document.getElementById("error4").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

//birthcity
birthcity = delspaces(birthcity);
if( birthcity == "" ){
document.getElementById("error6").innerHTML = "Ciudad de nacimiento es obligatoria";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise su CIUDAD DE NACIMIENTO";
return false;
}else{
document.getElementById("error6").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}


//birthdate
birthdate = delspaces(birthdate);
if( birthdate == "" ){
document.getElementById("error9").innerHTML = "Fecha de nacimiento es obligatoria";
document.getElementById("generalerrors").innerHTML = "Vaya al PASO 1 y revise su FECHA DE NACIMIENTO";
return false;
}else{
document.getElementById("error9").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}


//codeuserr
codeuserr = delspaces(codeuserr);
if( codeuserr == "" ){
document.getElementById("generalerrors").innerHTML = "Escriba el codigo de validacion de arriba";
return false;
}


// -----------------------------------------------------------------------------------

} // del dovalidation
