function SetToFirstControl()
{
  var bFound = false; 

  for (f=0; f < document.forms.length; f++) 
  {
    for(i=0; i < document.forms[f].length; i++)
    {
      if (document.forms[f][i].type != "hidden") 
      { 
        if (document.forms[f][i].disabled != true) 
        {
          try {
             document.forms[f][i].focus();
             var bFound = true;
          }
          catch(er) {
          }
        }
      }
      if (bFound == true)
        break;
    }
    if (bFound == true)
      break;
  }
}


// VALIDACION DATOS

var pulsado=false;
function validarDatos()
{
pulsado=false;

if (!validarNulo(document.agreeform.ID,"ID","ELIGE UN IDENTIFICADOR (ID)","T"))
        return false;

if (!validarLogin(document.agreeform.ID))
        return false;

if (!validarNulo(document.agreeform.pw,"pw","ELIGE UNA CONTRASEÑA","T"))
        return false;

if (!validarClave(document.agreeform.pw))
        return false;

if (!validarLoginClaveIguales(document.agreeform.ID,document.agreeform.pw))
        return false;

if (!validarNulo(document.agreeform.pw1,"pw1","ESCRÍBELA DE NUEVO","T"))
        return false;

if (!validarClavesIguales(document.agreeform.pw,document.agreeform.pw1))
        return false;

if (!validarpregunta())
	return false;

if (!validarNulo(document.agreeform.resp,"resp","RESPUESTA A LA PREGUNTA","T"))
        return false;

if (!validarNulo(document.agreeform.nomb,"nomb","NOMBRE","T"))
        return false;

if (!validarNulo(document.agreeform.apell,"apell","APELLIDO","T"))
        return false;

if (! validarMail(document.agreeform.mail))
	return false;

if (!validarNulo(document.agreeform.nac_dia,"nac_dia","DÍA DE NACIMIENTO","S"))
        return false;

if (!validarNulo(document.agreeform.nac_mes,"nac_mes","MES DE NACIMIENTO","S"))
        return false;

if (!validarNulo(document.agreeform.nac_ano,"nac_ano","A\361O DE NACIMIENTO","T"))
        return false;
		
if (!validarAnyo())
        return false;		
 
if (!validarNulo(document.agreeform.ciudad,"ciudad","CIUDAD","T"))
	return false;

if (!validarNulo(document.agreeform.pais_res,"pais_res","PAÍS DE RESIDENCIA","S"))
        return false;

if (!validarNulo(document.agreeform.estado,"estado","ESTADO Ó REGIÓN","T"))
	return false;

if (!validarNulo(document.agreeform.cpostal,"cpostal","CÓDIGO POSTAL","T"))
        return false;

if (!validarNulo(document.agreeform.pais_orig,"pais_orig","PAÍS DE ORIGEN","S"))
        return false;

if (!validarNulo(document.agreeform.profesion,"profesion","OCUPACIÓN","S"))
        return false;

if (! validarMail(document.agreeform.mail1))
	return false;
	
if (! validarMail(document.agreeform.mail2))
	return false;
	
if (! validarMail(document.agreeform.mail3))
	return false;

if (!validarNulo(document.agreeform.agreecheck,"agreecheck","ACEPTO LOS TÉRMINOS DE CUBANISIMO","C"))
    return false;
		
pulsado=true
return true;
}



function validarNulo(campo,dato,texto,tipo)
{

        if (tipo=="T")
        {
                if (campo.value.length==0)
                {
                        alert("ERROR: Has olvidado rellenar el campo "+texto+", que no puede dejarse en blanco en este formulario");
                        campo.focus();
                        return false;
                }
}
        if (tipo=="S")
        {
                if (campo.selectedIndex==0)
                {
                        alert("ERROR: Has olvidado rellenar el campo "+texto+", que no puede dejarse en blanco en este formulario");
                        campo.focus();
                        return false;
                }
        }
        if (tipo=="C")
        {
                var chequeado=0;
                for (var i=0;i<document.agreeform.elements.length;i++)
                {
                        if (document.agreeform.elements[i].name==dato)
                        {
                                if (document.agreeform.elements[i].checked==true)
                                        chequeado=1;
                        }
                }
 if (chequeado==0)
                {
                        alert("ERROR: Has olvidado marcar el campo "+texto+". Debes estar de acuerdo con nuestros términos legales");
						return false;
                }
        }
return true;
}



function validarClave(campo)
{
var chr;
        if (campo.value.length<6 || campo.value.length>32)
        {
                 alert("ERROR: La contrase\361a que has elegido no es correcta. Debe tener entre 6 y 32 caracteres");
                campo.focus();
                return false;
        }
return true;
}



function validarLogin(campo)
{
var chr;
        if (campo.value.length<3 || campo.value.length>32)
        {
                 alert("ERROR: El ID (identificador) que has elegido no es correcto. Debe tener entre 3 y  32 caracteres");
                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: El ID (identificador) que has elegido no es correcto. Recuerda que sólo se admiten las letras (excepto de la 'ñ' y vocales acentuadas), los números y los caracteres guión (-), subrayado (_) y punto (.)");
                               campo.focus();
                                return false;
                        }
                }
        }
return true;
}



function validarClavesIguales(clave1,clave2)
{
        if ( clave1.value!=clave2.value )
        {
                 alert("ERROR: Has escrito valores diferentes en los campos de la contraseña. Comprueba que escribes el mismo valor tanto en el campo ELIGE UNA CONTRASEÑA como en el campo ESCRÍBELA DE NUEVO.");
                clave2.focus();
                return false;
        }
return true;
}



function validarLoginClaveIguales(login,clave)
{
        if ( login.value.toUpperCase()==clave.value.toUpperCase() )
        {
                 alert("ERROR: La contrase\361a que has elegido es igual que tu ID. Debes elegir como contrase\361a un valor diferente a tu ID");
                clave.focus();
                return false;
        }
return true;
}



function validarpregunta() {

var valor;
var obj;
var obj2;
var text;

obj = document.agreeform.preg;
obj2 = document.agreeform.resp2;
valor=document.agreeform.preg.value;
text = obj.options[obj.selectedIndex].text;
valor2=obj2.value

if (valor == "0") {
	alert("ERROR: El campo PREGUNTA PARA RECORDAR CONTTRASEÑA, no puede dejarse en blanco en este formulario");
	obj.focus()
	return false;
}

if (valor == "99") {
		if (valor2 == "Pregunta personal aqui") {
			alert("ERROR: El campo PREGUNTA PARA RECORDAR CONTRASEÑA, no puede dejarse en blanco en este formulario");
			obj2.focus();
			return false;
		} else {
			document.agreeform.resp2.value = valor2;
		}
		return true;
	} else {
		
		document.agreeform.resp2.value = text;
	}
return true;
}


function validarMail(campo)
{
var chr;
var arrobas=0;
var puntos=0;
var blancos=0;
if (campo.value.length!=0)
{
        for (var i=0;i<campo.value.length;i++)
        {
                chr=campo.value.substring(i,i+1);
                if ( (chr=="@") )
                        arrobas=arrobas+1;
                if ( (chr==".") )
                        puntos=puntos+1;
                if ( (chr==" ") )
                        blancos=blancos+1;
        }

        if ( (blancos!=0) || (arrobas!=1) || (puntos<1) )
        {
                alert("ERROR: Dirección de correo incorrecta. Recuerda: NO se admiten espacios en blanco y debe contener los caracteres arroba (@) y punto (.)");
                campo.focus();
                return false;
        }
}

return true;
}



function validarAnyo()
{
        if (document.agreeform.nac_ano.value.length!=4)
        {
                alert("ERROR: El año de nacimiento no es correcto");
                document.agreeform.nac_ano.focus();
                return false;
        }
        for (var i=0;i<document.agreeform.nac_ano.value.length;i++)
        {
                chr=document.agreeform.nac_ano.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: El año de nacimiento no es correcto");
                	document.agreeform.nac_ano.focus();
			return false;
		}
	}

return true;
}



function checkotros() {
var listValue;
	listValue=document.agreeform.estado_c.value
	if (listValue == "2" ) {
		document.agreeform.nov[0].disabled=true;
		document.agreeform.nov[1].disabled=true;
		document.agreeform.rom[0].disabled=true;
		document.agreeform.rom[1].disabled=true;
		document.agreeform.rom[2].disabled=true;
		document.agreeform.rom[3].disabled=true;

	} 
	if (listValue != "2" ) {
		document.agreeform.nov[0].disabled=false;
		document.agreeform.nov[1].disabled=false;
		document.agreeform.rom[0].disabled=false;
		document.agreeform.rom[1].disabled=false;
		document.agreeform.rom[2].disabled=false;
		document.agreeform.rom[3].disabled=false;
	} 
return;
}



function otraopc() {
var listValue1;	
    listValue1=document.agreeform.preg.value
	if (listValue1 == "99" ) {
	    document.agreeform.resp2.disabled=false;
	}
	if (listValue1 != "99" ) {
	    document.agreeform.resp2.disabled=true;
	}
}



function otraopc1() {
var listValue1;	
    listValue1=document.agreeform.pais_res.value
	if (listValue1 == "us" ) {
	    document.agreeform.us_stat.disabled=false;
	}
	if (listValue1 != "us" ) {
	    document.agreeform.us_stat.disabled=true;
	}
}
//-->
