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,texto,tipo) {
	if (tipo=="T") {
    		if (campo.value.length==0) {
       		 	alert("Haz olvidado llenar el espacio "+texto+".");
            		campo.focus();
            		return false;
        	}
	}
    	if (tipo=="S") {
    		if (campo.selectedIndex==0) {
        		alert("Haz olvidado escoger el "+texto+".");
            		campo.focus();
            		return false;
        	}
    	}
        if (tipo=="R") {
                var chequeado=0;
                for (var i=0;i<campo.length;i++) {
                        if (campo[i].checked)
                                chequeado=1;
                }
                if (chequeado==0) {
                        alert("Haz olvidado llenar el espacio "+texto+".");
                        return false;
                }
        }
        if (tipo=="C") {
                var chequeado=0;
                for (var i=0;i<campo.length;i++) {
                        if (campo[i].checked)
                                chequeado=1;
                }
                if (chequeado==0) {
                        alert("Haz olvidado llenar el espacio "+texto+".");
                        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: EL espacio para el "+texto+" está incorrecto.");
			campo.focus();
			return false;
		}
	}
	return true;
}

function validarDia(campo) {
	if (parseInt(campo.dia_nac.value)<=0 || parseInt(campo.dia_nac.value)>31 ) {
        	alert("ERROR: El d&iacute;a de nacimiento no es correcto");
        	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: El d&iacute;a de nacimiento no es correcto");
           		campo.focus();
			return false;
		}
	}
	return true;
}

function validarLetras(campo){ 
  var charpos = campo.value.search("[^A-Za-z]"); 
  if(campo.value.length > 0 &&  charpos >= 0) 
  { 
	strError = campo.name+": Only alphabetic characters allowed ";                         
	alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
	return false; 
  }//if 
  return true;
}//alpha 

function validarAnyo(campo) {
	if (campo.value.length!=4) {
    		alert("ERROR: El a&ntilde;o de nacimiento no es correcto");
        	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: El a&ntilde;o de nacimiento no es correcto");
            		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: El correo electrónico está incorrecto. Acuérdese de usar el signo @ y de poner el punto. Por exemplo: fulanito@telemundo.com');
   		campo.focus();
   		campo.select();
   		good = false;
   		return false;
 	}
}

function esVacio(campo) {
	if (campo.value.length == 0)
		return true;
	else
		return false;
}


function validarClavesIguales(pwd1,pwd2)
{
        if ( pwd1.value!=pwd2.value )
        {
                 alert("ERROR: The values of the password are different. Make sure that the password are correct in both fields the Password and Confirm Password fields.");
                pwd2.focus();
                return false;
        }
return true;
}

function validarLoginClaveIguales(login,clave)
{
        if ( login.value.toUpperCase()==clave.value.toUpperCase() )
        {
                 alert("ERROR: La contrase\361a que Haz elegido es igual que tu ID. Debes elegir como contrase\361a un valor diferente a tu ID");
                clave.focus();
                return false;
        }
return true;	
}

function validarClave(campo)
{
var chr;
        if (campo.value.length<6 || campo.value.length>32)
        {
                 alert("ERROR: La contrase\361a que Haz 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 Haz 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 Haz 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 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;


}


var currentMenu = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;

    //if (window.opera) return; // I'm too tired

    actuator.onmouseover = function() {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden";
            this.showMenu();
        }
    }
  
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        return false;
    }

    actuator.showMenu = function() {
        menu.style.left = this.offsetLeft + "px";
        menu.style.top = this.offsetTop + this.offsetHeight + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}

var ns=false;
var ie=false;
var ns6=false;
ie = navigator.appName.indexOf('Microsoft Internet Explorer');
ns6 = navigator.appName.indexOf('Netscape');

function getPositionX(img) {

	if((ie) || (ns6)) {
		
		
		if (ie) {obj = eval('document.' + img)}
		if (ns6) { obj = eval('document.getElementById("' + img + '")' )}
		//if (ns6) {alert("entro en ns6"); obj = eval('document.images["' + img + '"]')}
		
		xPos = 0;
		xPos++;yPos--;
		xPos = obj.offsetLeft;
		
		
		while (obj.offsetParent)
		{
			obj = obj.offsetParent;
			xPos += obj.offsetLeft;

		}
		
		if (ie) {xPos +=1;}
		return xPos;
		
	}

	if(ns) {
		obj = eval('document.' + obj);
		return obj.x;
	}
	
}

function getPositionY(obj) {

	if((ie) || (ns6)) {

		if (ie) {obj = eval('document.' + obj)}
		if (ns6) {obj = eval('document.getElementById("' + obj + '")')}

	yPos = 0
	yPos++;yPos--;
	yPos = obj.offsetTop;

	while (obj.offsetParent)
	{
		obj = obj.offsetParent
		yPos += obj.offsetTop

	}
	//alert(yPos);
	if (ie) {yPos -=8;}
	return yPos;

	} 
	if(ns) {
		obj = eval('document.' + obj);
		return obj.y;
	}

}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function objPosition(campo,img) {
	//alert(obj);
	//menu = obj;
	nextTo =img;
	//obj = getObj(campo);
	//alert("OBJ2=" + obj.offsetTop);
	if (document.getElementById) {
		obj = eval('document.getElementById("' + campo + '")' )
		obj.style.top = parseInt(getPositionY(nextTo))+ "px" ;
		obj.style.left = parseInt(getPositionX(nextTo)) + "px" ;
	} else {
		theObj = eval("document." + objPart1 + campo + objPart2);
		theObj.top = parseInt(getPositionY(nextTo));
		theObj.left = parseInt(getPositionX(nextTo));
	}
	
	//obj.top=parseInt(getPositionY(nextTo));
	//obj.left = parseInt(getPositionX(nextTo));
	//alert("top=" + obj.visibility);
	return nextTo;
}

//POPUP WINDOWS
function popupWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);

}

