// JavaScript Document
function PosicaoFundo(){
	altura = document.getElementById("principal").scrollHeight;
	if (altura<=500){ altura=500;}
	document.getElementById("menu").style.height = altura;
}

function LibCreateRequestObject()
{
	var request_o;
	if(navigator.appName == "Microsoft Internet Explorer")
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	else
		request_o = new XMLHttpRequest();
	return request_o;
}

function CarrPagina(Div,Pagina)
{

	var httpPesquisar = LibCreateRequestObject();
	var strEnvio = Pagina;
	httpPesquisar.open('get', strEnvio);
	httpPesquisar.onreadystatechange = function HandlePesquisa()
	{
		if(httpPesquisar.readyState == 4)
		{
			document.getElementById(Div).innerHTML = httpPesquisar.responseText;
		}
	}
	httpPesquisar.send(null);	
}


function CheckConsistencia()
{
	var Nome = document.getElementById("Nome").value;
	var Empresa = document.getElementById("Empresa").value;
	var Email = document.getElementById("Email").value;
	var Senha = document.getElementById("Senha").value;
	
	if (Nome == "")
	{
		alert("Preencha o campo Nome / Cargo!");
		return false;
	}
	
	if (Empresa == "")
	{
		alert("Preencha o campo Zona Alfandegária / Porto!");
		return false;
	}
	
	if (Email == "")
	{
		alert("Preencha o campo Email!");
		return false;
	} else {
		if (!CheckEmailValido(Email))
			{
				alert("O campo E-mail está incorreto!");
				return false;
			}
	}
	
	if (Senha == "")
	{
		alert("Preencha o campo Senha!");
		return false;
	}
	return true;
}

function CheckEmailValido(varEmail)
{
	//se o email for fazio
	if (varEmail == "")
	{
		return false;
	}
	
	//se o primeiro caractere for diferente de caractere especial
	var primChar = varEmail.charAt(0);
	var listaIncorretaChar = "'!@#$%¨&*()-_=+]}{´`^~?/<>,.;:|\ ";
	if (listaIncorretaChar.indexOf(primChar) > 0)
	{
		return false;
	}
	
	//se o email não tiver arroba
	if (varEmail.indexOf("@") < 0)
	{
		return false;
	}

	//se o email tiver mais que um arroba
	var arrobas = varEmail.split("@");
	if (arrobas.length > 2)
	{
		return false;
	}
	
	//se o email possui caracteres após o arroba
	var posArroba = varEmail.indexOf("@");
	if (posArroba == varEmail.length-1)
	{
		return false;
	}
	if (listaIncorretaChar.indexOf(varEmail.charAt(posArroba + 1)) > 0)
	{
		return false;
	}
	
	//se o email não possui pontos após o arroba
	if (arrobas[1].indexOf(".") < 0)
	{
		return false;
	}

	//se o email não possui caracteres após o último ponto
	var posUltimoPonto = arrobas[1].indexOf(".");
	if (posUltimoPonto == arrobas[1].length-1)
	{
		return false;
	}
	if (listaIncorretaChar.indexOf(arrobas[1].charAt(posUltimoPonto + 1)) > 0)
	{
		return false;
	}
	
	return true;
}
