/*-----------------------------------------------------------------------------------------------------*/
function maisDominio()
{
	var Pais = document.getElementById("pais");
	var Falso = document.getElementById("login_falso");
	var Login = document.getElementById("user_camp");
	var dominio;
	
		if(Pais.value)
	{
		
		for(x = 0; x < PAISES.length; x++)
		{
			if(PAISES[x][0] == Pais.value) 
			{
				dominio=PAISES[x][1];
			}		
		}
	
	aux=Falso.value;
	if(aux.indexOf(dominio) == -1){
		Login.value = aux+=dominio;
	}else{
		Login.value = aux;
	}
	} 
}
/*-----------------------------------------------------------------------------------------------------*/
function tira_aroba()
{
var Texto = document.getElementById("user_camp");
var chr;
var str1;

str1 = Texto.value;
for(x = 0; x < Texto.value.length; x++)
	{
	chr = Texto.value.charAt(x);
	if (chr == "@")
		{			
		str1=Texto.value.substring(0,x); 
		}	
	
	}
Texto.value = str1;
}
/*-----------------------------------------------------------------------------------------------------*/

/*posiciona elemento relativo a otro*/
function getElementPosition(el){
	var x=0; var y=0;
	while(el.offsetParent){
		x+=el.offsetLeft; y+=el.offsetTop;
		el=el.offsetParent;
	}
	x+=el.offsetLeft; y+=el.offsetTop;
	return { x:x, y:y };
}

function posiciona(boton,caixa,pixX,pixY) {
	fBoton=document.getElementById(boton);
	fLayer=document.getElementById(caixa);
	posicBoton=getElementPosition(fBoton);
	yPos=posicBoton.y+pixY;
	xPos=posicBoton.x+pixX;
	fLayer.style.top=yPos+"px";
	fLayer.style.left=xPos+"px";
}

/*abre o cerra layer login onclick*/
conta = 0;
function menuLogin() {
	if (conta ==0) {
		document.getElementById('layer_login').style.display = 'block';
		document.forms.fLogin.login_falso.focus();
		conta = 1;
	}else{
		document.getElementById('layer_login').style.display = 'none';
		conta = 0;
	}
}
function change_selectbox(nro) {
var selbox = document.getElementById("pais");
for (var i = 0; i < selbox.options.length; i++) {
	if (selbox.options[i].value == nro)
		selbox.options[i].selected = true;
}
maisDominio();
}
/*validación de login con email terra*/
function validate() {
var Texto = document.getElementById("login_falso");
var chr;
var str1;
var str2 = "";
var nro_item = 0;
var re = /terra.com/ig;
str1 = Texto.value;
for(x = 0; x < Texto.value.length; x++)	{
	chr = Texto.value.charAt(x);
	if (chr == "@") {			
		str1=Texto.value.substring(0,x);
		str2=Texto.value.substring(x+1); 
	}	
}
if ((str2.match(re) != null)||(str2.match(/.cl/ig) != null)) {
	Texto.value = str1;
	var pos=str2.lastIndexOf('.');
	if (pos > 0)
		str2 = str2.substr(pos);
	switch(str2.replace('.', '')) {
		case "ar": nro_item=10; break;
		case "br": nro_item=1; break;
		case "cl": nro_item=41; break;
		case "co": nro_item=45; break;
		case "ec": nro_item=58;	break;
		case "mx": nro_item=138; break;
		case "pe": nro_item=153; break;
		case "ve": nro_item=204; break;
		default: nro_item=63; break;
	}
	if (nro_item > 0)
		change_selectbox(nro_item);
}
return true;
}