// JavaScript Document
function emailCheck (emailStr) {
	//remove espaços antes da verificação
	var emailStr = trim(emailStr)
	/* Critica de e-mail */
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
			alert("O endereço de e-mail parece incorreto (verifique @ e .'s)")
			return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
		alert("O nome de usuário do e-mail não parece ser válido.")
		return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
			  for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					alert("O endereço IP de destino do e-mail é inválido!")
					return false
				}
		}
		return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
			alert("O nome do domínio do e-mail não parece ser válido.")
		return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>3) {
	   alert("O endereço de e-mail deve terminar com um domínio de 3 letras ou um país com 2 letras.")
	   return false
	}

	if (len<2) {
	   var errStr="Este endereço de e-mail não possui um nome de Host!"
	   alert(errStr)
	   return false
	}

	return true;
}
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}
//Login Lateral
function f_validaCadastroRestrito(){
retorno = campoVazio(document.restrito.lemail,"E-mail");
if (retorno == false)
{
  return false;
}else{
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Trim(document.restrito.lemail.value)))) 
	{ 
		alert("Favor informar um e-mail válido.") 
		document.restrito.lemail.focus() 
		return false
	}
}

retorno = campoVazio(document.restrito.senha,"Senha");
if (retorno == false)
{
  return false;
}
}

function mostraMsg(erro)
{
if ( erro == '1' )
{
	document.getElementById('trErroLogin').style.display = 'inline';
	document.getElementById('trFormLogin').style.display = 'inline';
	document.getElementById('trLogado').style.display = 'none';
	document.restrito.lemail.value = '';
	document.restrito.senha.value = '';
	document.restrito.lemail.focus()
}else if ( erro == '0' )
{
/*	document.getElementById('trErroLogin').style.display = 'none';
	document.getElementById('trFormLogin').style.display = 'none';
	document.getElementById('trLogado').style.display = 'inline';
*/
	window.location='../areacliente/home/';
}
}

// Login do Webmail
function mostraWebmail(vis)
{
	if ( vis == '1' )
	{
		document.getElementById('mailform').style.display = 'inline';	
		document.getElementById('ttopo').style.display = 'none';
		document.mailform.email.focus();
	}else if ( vis == '0')
	{
		document.getElementById('mailform').style.display = 'none';	
		document.getElementById('ttopo').style.display = 'inline';
	}
}

function loginWebmail()
{
  if (document.mailform.email.value.length != 0)
  {
	var retorno = emailCheck(document.mailform.email.value);
	if (retorno == false)
	{
	 mailform.email.focus();
	 return false;
	}
  }
 if(mailform.email.value == '') 
 {
  alert("O campo 'E-mail' não pode ser deixado em branco.");
  mailform.email.focus();
  return false;
 }
 if(mailform.password.value == '') 
 {
  alert("O campo 'Senha' não pode ser deixado em branco.");
  mailform.password.focus();
  return false;
 }
var strMail;
strMail = document.mailform.email.value;
vetMail = strMail.split('@');
strMail = vetMail[1];

document.mailform.action = 'http://webmail.'+strMail+'/Login.aspx';
}						
