
function validarPais(){
        if (document.alta.pais.options[document.alta.pais.selectedIndex].value != 56 && document.alta.pais.options[document.alta.pais.selectedIndex].value != 68){
		top.location="http://www.terra.com/nonus.html";
	        //document.alta.method="get";
       		//document.alta.action="http://www.terra.com/nonus.html";
        	//document.alta.submit();
        }
}

function validarNulo(campo,dato,text,tipo) {
	if (tipo=="T") {
    		if (campo.value.length==0) {
       		 	alert("You have forgotten to fill out the "+text+" field, you cannot leave this area blank on the page.");
            		campo.focus();
            		return false;
        	}
	}
    	if (tipo=="S") {
    		if (campo.selectedIndex==0) {
        		alert("You have forgotten to fill out the "+text+" field, you cannot leave this area blank on this form.");
            		campo.focus();
            		return false;
        	}
    	}
        if (tipo=="R") {
                var chequeado=0;
		if (campo.length == undefined) {
			if (campo.checked)
				chequeado=1;
		} else {
                	for (var i=0;i<campo.length;i++) {
	                        if (campo[i].checked)
       		                         chequeado=1;
	                }
		}
                if (chequeado==0) {
                        alert("You have forgotten to fill out the "+text+" field, you cannot leave this area blank on this form.");
                        return false;
                }
        }
        if (tipo=="C") {
                var chequeado=0;
                for (var i=0;i<campo.checked;i++) {
                        if (campo[i].checked)
                                chequeado=1;
                }
                if (chequeado==0) {
                        alert("You have forgotten to fill out the "+text+" field, you cannot leave this area blank on this form.");
                        return false;
                }
        }
	return true;
}

function validarNumero(campo,text) {
	for (var i=0;i<campo.value.length;i++) {
    	chr=campo.value.substring(i,i+1);
        if ( (chr!="0") && (chr!="1") && (chr!="2") && (chr!="3") && (chr!="4") && (chr!="5") && (chr!="6") && (chr!="7") && (chr!="8") && (chr!="9") ) {
			alert("The "+text+" is not correct");
			campo.focus();
			return false;
		}
	}
	return true;
}

function validarDia(campo) {
	if (parseInt(campo.dia_nac.value)<=0 || parseInt(campo.dia_nac.value)>31 ) {
        	alert("The birthdate is not correct");
        	campo.focus();
    		return false;
    	}
	for (var i=0;i<campo.value.length;i++) {
		chr=campo.value.substring(i,i+1);
        	if ( (chr!="0") && (chr!="1") && (chr!="2") && (chr!="3") && (chr!="4") && (chr!="5") && (chr!="6") && (chr!="7") && (chr!="8") && (chr!="9") ) {
    	   		alert("The birthdate is not correct");
           		campo.focus();
			return false;
		}
	}
	return true;
}

function validarAnyo(campo) {
	if (campo.value.length!=4) {
    		alert("The birth year is not correct");
        	campo.focus();
        	return false;
    	}
    	for (var i=0;i<campo.value.length;i++) {
    		chr=campo.value.substring(i,i+1);
        	if ( (chr!="0") && (chr!="1") && (chr!="2") && (chr!="3") && (chr!="4") && (chr!="5") && (chr!="6") && (chr!="7") && (chr!="8") && (chr!="9") ) {
        		alert("The birth year is not correct");
            		campo.focus();
			return false;
		}
	}
	return true;
}

function validarMail(campo) {
	var goodEmail = campo.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	if (goodEmail) {
   		good = true;
   		return true;
	} else {
   		alert('The email address that you have chosen is not correct. Please remember that spaces are not permitted and that the email address should contain the @ character and the "dot" (.)');
   		campo.focus();
   		campo.select();
   		good = false;
   		return false;
 	}
}

function esVacio(campo) {
	if (campo.value.length == 0)
		return true;
	else
		return false;
}


function validarClavesIguales(clave1,clave2)
{
        if ( clave1.value!=clave2.value )
        {
                 alert("You have entered different values in the password fields. You should enter the same password in the Choose Your Password field and the Enter Your Password Again fields.");
                clave2.focus();
                return false;
        }
return true;
}

function validarLoginClaveIguales(login,clave)
{
        if ( login.value.toUpperCase()==clave.value.toUpperCase() )
        {
                 alert("The password that you have chosen is the same as your ID. You should choose a password that is different from your ID.");
                clave.focus();
                return false;
        }
return true;	
}

function validarClave(campo)
{
var chr;
        if (campo.value.length<6 || campo.value.length>32)
        {
                 alert("The password that you have chosen is not valid. It should have between 6 and 32 characters.");
                campo.focus();
                return false;
        }
return true;
}


function validarLogin(campo)
{
var chr;
        if (campo.value.length<3 || campo.value.length>32)
        {
                 alert("The ID (identifier) that you have chosen is not correct. It should be between 3 and 32 characters.");
                campo.focus();
                return false;
        }
        for (var i=0;i<campo.value.length;i++)
        {
                chr=campo.value.substring(i,i+1);
                if ( (chr<"0") || (chr.toUpperCase()>"Z") || (chr==" ") || (chr=="?") || (chr=="@") || (chr=="=") || (chr==":") || (chr==";") || (chr=="<") || ( chr==">") )
                {
                        if ( (chr!="-") && (chr!="_") && (chr!=".") )
                        {
                        alert("The ID (identifier) that you have chosen is not correct. Please remember that only letters, numbers, dashes (-), underscores (_) and periods (.) are permitted (no foreign characters are allowed).");
                               campo.focus();
                                return false;
                        }
                }
        }
return true;
}

function rellenarStringCheck()
{
var stringUsos="";      
var stringContenidos="";        
var stringServicios=""; 

var primerUso="S";
var primerContenido="S";
var primerServicio="S";

for (var i=0;i<document.alta.elements.length;i++)
{
        if (document.alta.elements[i].name=="uso_internet")
        {
                if ( (document.alta.elements[i].checked==true) && (primerUso=="S") )
                {
                        stringUsos=stringUsos+document.alta.elements[i].value;
                        primerUso="N";
                }
                else
                if (document.alta.elements[i].checked==true)
                        stringUsos=stringUsos+","+document.alta.elements[i].value;
        }
        if (document.alta.elements[i].name=="contenidos_interes")
        {
                if ( (document.alta.elements[i].checked==true) && (primerContenido=="S") )
                {
                        stringContenidos=stringContenidos+document.alta.elements[i].value;
                        primerContenido="N";
                }
                else
                if (document.alta.elements[i].checked==true)
                        stringContenidos=stringContenidos+","+document.alta.elements[i].value;
        }
        if (document.alta.elements[i].name=="servicios_interes")
        {
                if ( (document.alta.elements[i].checked==true) && (primerServicio=="S") )
                {
                        stringServicios=stringServicios+document.alta.elements[i].value;
                        primerServicio="N";
                }
                else
                if (document.alta.elements[i].checked==true)
                        stringServicios=stringServicios+","+document.alta.elements[i].value;
        }
}
document.alta.h_uso_internet.value=stringUsos;
document.alta.h_contenidos_interes.value=stringContenidos;
document.alta.h_servicios_interes.value=stringServicios;


}

