/* Inicio Script da Tela administrativa */
function TrocaTexto (texto,elemento) {
	document.getElementById(elemento).innerHTML = texto;
}

function esqueceu()
{
	with(document.esquecer)
	{
		if (email.value=="")
		{
			alert ("O campo E-MAIL deve ser preenchido!");
			email.focus();
		 	return false;
		}
		if (email.value.indexOf ("@",0) == -1 || email.value.indexOf (".",0) == -1)
		{
		    alert("Por favor, preencha o campo E-MAIL corretamente!")
		    email.focus();
		    return false;
		 }
	}

}
/* Fim Script da Tela administrativa */

function Visualizar(url,page,w,h,sc) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
if(sc=="")
sc = "Yes";
win = window.open(url,page, 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+sc+',resizable=no')
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function validarNews()
{
	with(document.formNews)
	{
		if(nome.value=="")
		{
			alert("O campo NOME deve ser preenchido!");
			nome.focus();
			return false;
		}
		if (email.value=="")
		{
			alert ("O campo E-MAIL deve ser preenchido!");
		  	email.focus();
		   	return false;
		}
		if (email.value.indexOf ("@",0) == -1 || email.value.indexOf (".",0) == -1)
	    {
	    	alert("Por favor, preencha o campo E-MAIL corretamente!")
	        email.focus();
	        return false;
	    }
		return true;
	}
}

function validarNewsRemover()
{
	with(document.formNewsRemover)
	{
		if (email.value=="")
		{
			alert ("O campo E-MAIL deve ser preenchido!");
		  	email.focus();
		   	return false;
		}
		if (email.value.indexOf ("@",0) == -1 || email.value.indexOf (".",0) == -1)
	    {
	    	alert("Por favor, preencha o campo E-MAIL corretamente!")
	        email.focus();
	        return false;
	    }
		return true;
	}
}

function validarPainel()
{
	with(document.formPainel)
	{
		if(login.value=="" || login.value=="Login:")
		{
			alert("O campo LOGIN deve ser preenchido!");
			login.focus();
			return false;
		}
		if (senha.value=="" || senha.value=="Senha:")
	    {
	    	alert("O campo SENHA deve ser preenchido!");
	        senha.focus();
	        return false;
	    }
		return true;
	}
}

function validaForm2( NomeForm )
{
	if (NomeForm == 'frmBusca')
	{
		if (document.forms[NomeForm].elements['busca'].value == "")
		{
			alert("O campo BUSCA deve ser preenchido!");
			document.forms[NomeForm].elements['busca'].focus();
			return false;
		}
		else
			if (document.forms[NomeForm].elements['busca'].value.length < 3)
			{
				alert("O campo BUSCA deve ser preenchido com no mínimo 3 letras!");
				document.forms[NomeForm].elements['busca'].focus();
				return false;
			}
	location = "?busca="+document.forms[NomeForm].elements['busca'].value;
	} //Fim FrmBusca
}

function validaForm( NomeForm )
{
	if (NomeForm == 'frmContato')
	{
		if (document.forms[NomeForm].elements['nome'].value == "")
		{
			alert("O campo NOME deve ser preenchido!");
			document.forms[NomeForm].elements['nome'].focus();
			return false;
		}
		
		if(document.forms[NomeForm].elements['email'].value == ""){
			alert("O campo E-MAIL deve ser preenchido!");
			document.forms[NomeForm].elements['email'].focus();
			return false;
		}else{
				if(!(validaEmail(document.forms[NomeForm].elements['email'].value))){
					alert("O campo E-MAIL não está com um e-mail válido!");
					document.forms[NomeForm].elements['email'].focus();
					return false;
				}
		}
		if (document.forms[NomeForm].elements['telefone'].value == "")
		{
			alert("O campo TELEFONE deve ser preenchido!");
			document.forms[NomeForm].elements['telefone'].focus();
			return false;
		}
		if (document.forms[NomeForm].elements['endereco'].value == "")
		{
			alert("O campo ENDERECO deve ser preenchido!");
			document.forms[NomeForm].elements['endereco'].focus();
			return false;
		}
		
		if (document.forms[NomeForm].elements['mensagem'].value == "")
		{
			alert("O campo MENSAGEM deve ser preenchido!");
			document.forms[NomeForm].elements['mensagem'].focus();
			return false;
		}
		return true;
	} //Fim frmContato
	
}

function validaEmail(email)
{
	if(email.length < 6)
	{
		return false;
	}
	var x=0;
	for(var c=0;c<email.length;c++)
	{
		if(email.substring(c,c+1)=='@')
		{
			x=c;
		}
	}
	var y=0;
	if(x > 0)
	{
		for(c=x;c<email.length;c++)
		{
			if(email.substring(c,c+1)=='.')
			{
				y=c;
				var valida=1;
			}
		}					
	}
	else
		{
			return false;
		}

	if(y<=x+2)
	{
		return false;
	}

	if(valida==1)
	{
		return true;
	}
	return true;
}
