window.onload = function(){ 
	document.getElementById('nome').onfocus = limpa
    document.getElementById('telefone').onfocus = limpa
    document.getElementById('email').onfocus = limpa
	
	document.getElementById('nomer').onfocus = limpa
    document.getElementById('telefoner').onfocus = limpa
	document.getElementById('celularr').onfocus = limpa
    document.getElementById('emailr').onfocus = limpa
	document.getElementById('enderecor').onfocus = limpa
    document.getElementById('cidader').onfocus = limpa
	document.getElementById('representar').onfocus = limpa
	document.getElementById('atender').onfocus = limpa
		
	document.getElementById('aba').style.backgroundPosition = "bottom"
	document.getElementById('aba').style.color = "#000"	
	document.getElementById('aba').onmouseover = abaOver
	document.getElementById('aba2').onmouseover = abaOver
	document.getElementById('aba3').onmouseover = abaOver
	
	document.getElementById('aba').onmouseout = abaOut
	document.getElementById('aba2').onmouseout = abaOut
	document.getElementById('aba3').onmouseout = abaOut
	
	document.getElementById('aba').onclick = function(){troca(1);}
	document.getElementById('aba2').onclick = function(){troca(2);}
	document.getElementById('aba3').onclick = function(){troca(3);}
	
	if(getQuery("area") == "representante"){
		troca(2);	
	}
	else if(getQuery("area") == "trabalheconosco"){
		troca(3);	
	}
	
}

var opacidade = 100, tempo = 100, velocidade = 45, t;
var opacidade2 = 100, tempo2 = 100, velocidade2 = 45, t2;
var aba_atual = "aba", form_atual = "form01";
var cor = "#efeeee", corErro = "#e6e298";

function validar(){
	var fml=document.contatoForm
	var status=true;
	var arroba = fml.email.value.indexOf("@");
	var ponto = fml.email.value.indexOf(".");
	
	//Valida o campo NOME.
	if(fml.nome.value.length < 3){
	 	document.getElementById("caixa_nome").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_nome").style.background = cor;
	}

	//Valida o campo E-MAIL.
	if(fml.email.value.length < 5 || arroba == -1 || ponto == -1){
		document.getElementById("caixa_email").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_email").style.background = cor;
	}
	
	//Valida o campo TELEFONE
	if(fml.telefone.value.length < 7){
		document.getElementById("caixa_telefone").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_telefone").style.background = cor;
	}
	
	if(status){
//		 fml.action = "../scripts/redirect.asp";
 		 fml.submit();	
	}
	else{
		avisar(true);	
	}
}

function enviar2(){
	var fml=document.repreForm
	var status=true;
	var arroba = fml.email.value.indexOf("@");
	var ponto = fml.email.value.indexOf(".");
	
	//Valida o campo NOME.
	if(fml.nome.value.length < 3){
	 	document.getElementById("caixa_nomer").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_nomer").style.background = cor;
	}

	//Valida o campo E-MAIL.
	if(fml.email.value.length < 5 || arroba == -1 || ponto == -1){
		document.getElementById("caixa_emailr").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_emailr").style.background = cor;
	}
	
	//Valida o campo TELEFONE
	if(fml.telefone.value.length < 7){
		document.getElementById("caixa_telefoner").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_telefoner").style.background = cor;
	}
	
	//Valida o campo CELULAR
	if(fml.celular.value.length < 7){
		document.getElementById("caixa_celularr").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_celularr").style.background = cor;
	}
	
	//Valida o campo ENDEREÇO
	if(fml.endereco.value.length < 3){
		document.getElementById("caixa_enderecor").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_enderecor").style.background = cor;
	}
	
	//Valida o campo CIDADE
	if(fml.cidade.value.length < 3){
		document.getElementById("caixa_cidader").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_cidader").style.background = cor;
	}
	
	//Valida o campo EMPRESAS REPRESENTADAS
	if(fml.representa.value.length < 3){
		document.getElementById("caixa_representar").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_representar").style.background = cor;
	}
	
	//Valida o campo CIDADES ATENDIDAS
	if(fml.atende.value.length < 3){
		document.getElementById("caixa_atender").style.background = corErro;
		status=false;
	}
	else{
		document.getElementById("caixa_atender").style.background = cor;
	}
	
	if(status){
		 fml.action = "Scripts/redirect2.asp";
 		 fml.submit();	
	}
	else{
		avisar2(true);	
	}
}


function limpa(e){
    try{var x = e.target          }catch(er){};
    try{var x = event.srcElement  }catch(er){};
	if(x.id == "nome"){ document.getElementById("caixa_nome").style.background = cor;}
	if(x.id == "telefone"){ document.getElementById("caixa_telefone").style.background = cor;}
	if(x.id == "email") {document.getElementById("caixa_email").style.background = cor;}
	
	if(x.id == "nomer"){ document.getElementById("caixa_nomer").style.background = cor;}
	if(x.id == "telefoner"){ document.getElementById("caixa_telefoner").style.background = cor;}
	if(x.id == "celularr"){ document.getElementById("caixa_celularr").style.background = cor;}
	if(x.id == "emailr") {document.getElementById("caixa_emailr").style.background = cor;}
	if(x.id == "enderecor") {document.getElementById("caixa_enderecor").style.background = cor;}
	if(x.id == "cidader") {document.getElementById("caixa_cidader").style.background = cor;}
	if(x.id == "representar") {document.getElementById("caixa_representar").style.background = cor;}
	if(x.id == "atender") {document.getElementById("caixa_atender").style.background = cor;}
	
}

function limpar2(){
	var fml=document.repreForm
	fml.reset();
	avisar2(false);
	document.getElementById("caixa_nomer").style.background = cor;
    document.getElementById("caixa_emailr").style.background = cor;
	document.getElementById("caixa_telefoner").style.background = cor;
	document.getElementById("caixa_celularr").style.background = cor;
	document.getElementById("caixa_enderecor").style.background = cor;
	document.getElementById("caixa_cidader").style.background = cor;
	document.getElementById("caixa_representar").style.background = cor;
	document.getElementById("caixa_atender").style.background = cor;
}

function limpar(){
	var fml=document.contatoForm
	fml.reset();
	avisar(false);
	document.getElementById("caixa_nome").style.background = cor;
    document.getElementById("caixa_email").style.background = cor;
	document.getElementById("caixa_telefone").style.background = cor;
	
}

function avisar(mostrar){
	if(mostrar){
		clearTimeout(t)
		setarVar();
		document.getElementById("aviso").style.visibility = 'visible';
		show();			
	}
	else{
		clearTimeout(t)
		document.getElementById("aviso").style.visibility = 'hidden';
		setarVar();
	}
}

function avisar2(mostrar){
	if(mostrar){
		clearTimeout(t2)
		setarVar2();
		document.getElementById("aviso2").style.visibility = 'visible';
		show2();			
	}
	else{
		clearTimeout(t2)
		document.getElementById("aviso2").style.visibility = 'hidden';
		setarVar2();
	}
}


function setarVar(){
	opacidade = 100;
	tempo = 100;
	var objeto = document.getElementById("aviso").style;
	objeto.opacity = 1; //FIREFOX
	objeto.MozOpacity = 1; // BROWSER NÃO IDENTIFICADO
	objeto.KhtmlOpacity = 1; // BROWSER NÃO IDENTIFICADO
	objeto.filter = "alpha(opacity=100)";//I.E.
}

function setarVar2(){
	opacidade2 = 100;
	tempo2 = 100;
	var objeto = document.getElementById("aviso2").style;
	objeto.opacity = 1; //FIREFOX
	objeto.MozOpacity = 1; // BROWSER NÃO IDENTIFICADO
	objeto.KhtmlOpacity = 1; // BROWSER NÃO IDENTIFICADO
	objeto.filter = "alpha(opacity=100)";//I.E.
}


function show(){
	if(tempo > 0){
		tempo --;
		t = setTimeout("show()", velocidade); 
	}
	else if(opacidade > 0 ){
		opacidade -=5;
		var objeto = document.getElementById("aviso").style;
		objeto.opacity = (opacidade / 100); //FIREFOX
		objeto.MozOpacity = (opacidade / 100); // BROWSER NÃO IDENTIFICADO
		objeto.KhtmlOpacity = (opacidade / 100); // BROWSER NÃO IDENTIFICADO
		objeto.filter = "alpha(opacity=" + opacidade + ")";//I.E.
		t = setTimeout("show()", velocidade); 
	}
	else{
		clearTimeout(t)
		document.getElementById("aviso").style.visibility = 'hidden';
		setarVar();
	}
}

function show2(){
	if(tempo2 > 0){
		tempo2 --;
		t2 = setTimeout("show2()", velocidade2); 
	}
	else if(opacidade2 > 0 ){
		opacidade2 -=5;
		var objeto = document.getElementById("aviso2").style;
		objeto.opacity = (opacidade2 / 100); //FIREFOX
		objeto.MozOpacity = (opacidade2 / 100); // BROWSER NÃO IDENTIFICADO
		objeto.KhtmlOpacity = (opacidade2 / 100); // BROWSER NÃO IDENTIFICADO
		objeto.filter = "alpha(opacity=" + opacidade2 + ")";//I.E.
		t2 = setTimeout("show2()", velocidade2); 
	}
	else{
		clearTimeout(t2)
		document.getElementById("aviso2").style.visibility = 'hidden';
		setarVar2();
	}
}

function mapa(){
var pgWidth = 700;
var pgHeight= 465;
var pLeft = (screen.width/2) - (pgWidth/2);
var pTop =  (screen.height/2)-(pgHeight/2)-50;
window.open("mapa.html","mapa","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=700, height=465, top="+pTop+",left="+pLeft+"")
}

function abaOver(e){
    try{var x = e.target          }catch(er){};
    try{var x = event.srcElement  }catch(er){};
	if(x.id == "aba3" && aba_atual != "aba3"){ document.getElementById("aba3").style.color = "#000"; document.getElementById("aba3").style.backgroundPosition = "0px 54px";}
	if(x.id == "aba2" && aba_atual != "aba2"){ document.getElementById("aba2").style.color = "#000"; document.getElementById("aba2").style.backgroundPosition = "0px 54px";}
	if(x.id == "aba" && aba_atual != "aba") {document.getElementById("aba").style.color = "#000"; document.getElementById("aba").style.backgroundPosition = "0px 54px"; }
}
function abaOut(e){
    try{var x = e.target          }catch(er){};
    try{var x = event.srcElement  }catch(er){};
	if(x.id == "aba3" && aba_atual != "aba3"){ document.getElementById("aba3").style.color = "#666"; document.getElementById("aba3").style.backgroundPosition = "0px 0px";}
	if(x.id == "aba2" && aba_atual != "aba2"){ document.getElementById("aba2").style.color = "#666"; document.getElementById("aba2").style.backgroundPosition = "0px 0px";}
	if(x.id == "aba" && aba_atual != "aba") {document.getElementById("aba").style.color = "#666"; document.getElementById("aba").style.backgroundPosition = "0px 0px";}
}

function troca(area){
	if(area==1 && aba_atual != "aba"){
		document.getElementById(aba_atual).style.color = "#666";
		document.getElementById(aba_atual).style.backgroundPosition = "top";
		document.getElementById(form_atual).style.display = "none";
		aba_atual = "aba";
		form_atual = "form01";
		document.getElementById("aba").style.color = "#000";
		document.getElementById("aba").style.backgroundPosition = "bottom";
		document.getElementById("form01").style.display = "block";
	}
	else if(area==2 && aba_atual != "aba2"){
		document.getElementById(aba_atual).style.color = "#666";
		document.getElementById(aba_atual).style.backgroundPosition = "top";
		document.getElementById(form_atual).style.display = "none";
		aba_atual = "aba2";
		form_atual = "form02";
		document.getElementById("aba2").style.color = "#000";
		document.getElementById("aba2").style.backgroundPosition = "bottom";
		document.getElementById("form02").style.display = "block";
	}
	else if(area==3 && aba_atual != "aba3"){
		document.getElementById(aba_atual).style.color = "#666";
		document.getElementById(aba_atual).style.backgroundPosition = "top";
		document.getElementById(form_atual).style.display = "none";
		aba_atual = "aba3";
		form_atual = "form03";
		document.getElementById("aba3").style.color = "#000";
		document.getElementById("aba3").style.backgroundPosition = "bottom";
		document.getElementById("form03").style.display = "block";
	}
}

//getQuerry
function getQuery(variavel){
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) { 
		var parte = vars[i].split("=");
		if (parte[0] == variavel) {
			return parte[1];
		}
	}
}
		
