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 = "Login is required";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your LOGIN";
return false;
}else{
document.getElementById("error").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

if(!validate(login)) 
{
document.getElementById("error").innerHTML = "Invalid characters or login length";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your LOGIN";
return false;
}else{
document.getElementById("error").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}



//password
login = delspaces(login);
if( pwd == "" || rpwd == ""){
document.getElementById("error11").innerHTML = "Password and Repeat Password are required";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your PASSWORDS";
return false;
}else{
document.getElementById("error11").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

if(!validatepassword(pwd) || !validatepassword(rpwd)) 
{
document.getElementById("error11").innerHTML = "Invalid characters or length for passwords";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your PASSWORDS";
return false;
}else{
document.getElementById("error11").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

if(!passw(pwd,rpwd)){
document.getElementById("error11").innerHTML = "Both passwords must be the same";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your PASSWORDS";
return false;
}else{
document.getElementById("error11").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}


//email
email = delspaces(email);
if( email == "" ){
document.getElementById("error3").innerHTML = "Email is required";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your EMAIL";
return false;
}else{
document.getElementById("error3").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

if(!validatemail(email)) 
{
document.getElementById("error3").innerHTML = "Invalid Email address";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your EMAIL";
return false;
}else{
document.getElementById("error3").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

//fname
fname = delspaces(fname);
if( fname == "" ){
document.getElementById("error7").innerHTML = "First Name is required";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your FIRST NAME";
return false;
}else{
document.getElementById("error7").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

//lname
lname = delspaces(lname);
if( lname == "" ){
document.getElementById("error8").innerHTML = "Last Name is required";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your LAST NAME";
return false;
}else{
document.getElementById("error8").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}	

//birthcountry
birthcountry = delspaces(birthcountry);
if( birthcountry == "" ){
document.getElementById("error4").innerHTML = "Birth Country is required";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your BIRTH COUNTRY";
return false;
}else{
document.getElementById("error4").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

//birthcity
birthcity = delspaces(birthcity);
if( birthcity == "" ){
document.getElementById("error6").innerHTML = "Birth City is required";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your BIRTH CITY";
return false;
}else{
document.getElementById("error6").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}

//birthdate
birthdate = delspaces(birthdate);
if( birthdate == "" ){
document.getElementById("error9").innerHTML = "Birth Date is required";
document.getElementById("generalerrors").innerHTML = "Go to STEP 1 and check out your BIRTH DATE";
return false;
}else{
document.getElementById("error9").innerHTML = "<div style='background-color: #EEEEEE;'></div>";
}


//codeuserr
codeuserr = delspaces(codeuserr);
if( codeuserr == "" ){
document.getElementById("generalerrors").innerHTML = "Please enter the validation code above";
return false;
}


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

} // del dovalidation
