function validarNulo(campo,dato,texto,tipo) {
        if (tipo=="T") {
                if (campo.value.length==0) {
                        alert("ERROR: You have forgotten to fill in the field "+texto+". This field can not be left blank in the form.");						
                        campo.focus();
                        return false;
                }
        }
        if (tipo=="S") {
                //if (campo.selectedIndex<0) {
				if (campo.selectedIndex==0) {
                        alert("ERROR: You have forgotten to fill in the field "+texto+". This field can not be left blank in the 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("ERROR: You have forgotten to fill in the field "+texto+". This field can not be left blank in the form.");
                        return false;
                }
        }

        if (tipo=="C") {
                var chequeado=0;
                for (var i=0;i<campo.elements.length;i++) {
                        if (campo.elements[i].name==dato) {
                                if (campo.elements[i].checked)
                                        chequeado=1;
                        }
                }
                if (chequeado==0) {
                        alert("ERROR: You have forgotten to fill in the field "+texto+". This field can not be left blank in the form.");
                        return false;
                }
        }
        return true;
}

function validarNumero(campo,texto) {
        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("ERROR: The "+texto+" 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("ERROR: The birth date 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("ERROR: The birth month is not correct.");
                        campo.focus();
                        return false;
                }
        }
        return true;
}

function validarAnyo(campo) {
        if (campo.value.length!=4) {
                alert("ERROR: 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("ERROR:  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('ERROR: The email addres you have selected is not correct. Please note that blank spaces are not permitted and that it should include the @ character and the period (.).  ');
                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("ERROR: Your passwords do not match. Please confirm that you have written the password correctly in both the Pick Your Password field and the Enter Your Password Again field.	");
                clave2.focus();
                return false;
        }
return true;
}

function validarLoginClaveIguales(login,clave)
{
        if ( login.value.toUpperCase()==clave.value.toUpperCase() )
        {
                 alert("ERROR: The password you have chosen is the same as your ID.  You should choose different values for your password and ID. ");				 
                clave.focus();
                return false;
        }
return true;    
}

function validarClave(campo)
{
var chr;
        if (campo.value.length<6 || campo.value.length>32)
        {
                 alert("ERROR: The password you have chosen is incorrect it should be 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("ERROR: The ID 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("ERROR: The Id you have chosen is not correct. Please note you can only use letters (except the letter ñ or vowels with accents), numbers, and the following characters: dash (-), underline (_) and period (.).");
                               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;
        
}

