// JavaScript Document

/* FUNCOES */
function redirect(pag){ location.href=pag; }
function mostraMsg(msg){ window.attachEvent("onload", alert(msg) ); }
function maximaExtensao (campo, maximo){ if( campo.value.length>maximo ){ campo.value=campo.value.substring(0, maximo-1);} }
function mudaImg(campo,valor){ id = (campo.id) ? campo.id : campo; document.getElementById(id).src = "thumb.php?end=css/img/"+valor+"&largura=100&altura=80"; }
function showHide(id,mostra){
	i=0;
	while ( document.getElementById(id+i) ){ document.getElementById(id+i).style.display = "none"; i++; }
	document.getElementById(id+mostra).style.display = (document.getElementById(id+mostra).style.display=="block") ? "none" : "block";
}
function abreAmbiente(){
	Shadowbox.open({
		player: 'iframe',
		content: 'ambienteDetalhes.php',
		height: 550,
		width: 840,
		title: 'Processos de Plantio'
	});
};


function openWin(url,valor){ 
	janela = window.open(url,'_blank','location=no,directories=no,status=no,menubar=no,'+valor);
	janela.focus();
}
function imprimir(url,valor){ 
	janela = window.open(url,'_blank','location=no,directories=no,status=no,menubar=no,'+valor);
	janela.focus();
	janela.print();
	janela.stop();
}
function sigla(uf){ sendRequest('consultoresDetalhes.php?est='+uf,'divCon'); }

function abrirSB(id){
	 Shadowbox.open({
		  player:     'iframe',
		  title:      'Lan&ccedil;amentos',
		  content:    'lancamentosDetalhe.php?id='+id,
		  width:      990,
		  height:     540
	 });
}

/* AJAX */
function sendRequest(url,id,postData){
	document.getElementById(id).innerHTML = "<div style='text-align:center;width:auto;'><img src='./css/img/loading.gif' alt='carregando...' /></div>";
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (req.overrideMimeType) req.overrideMimeType('text/html');
	if (postData) req.setRequestHeader('Content-type','application/x-www-form-urlencoded');

	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
			alert('HTTP error ' + req.status);
			return;
		}
		document.getElementById(id).innerHTML = req.responseText; 
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try { xmlhttp = XMLHttpFactories[i](); } catch (e) { continue; }
		break;
	}
	return xmlhttp;
}
/**/

/* ACESSO RESTRITO */
function getAcesso(){
	if (document.getElementById("login").value=="" || document.getElementById("login").value=="login"){
		alert("Informe o login!");
		document.getElementById("login").focus();
		return false;
	}
	if (document.getElementById("senha").value=="" || document.getElementById("senha").value=="senha"){
		alert("Informe a senha!");
		document.getElementById("senha").focus();
		return false;
	}
}
/**/

/*NEWSLETTER*/

function getNews(){
	if (document.getElementById('emailNews').value==""){
		alert("Informe seu e-mail!");
		document.getElementById('emailNews').focus();
		return false;
	} else {
		mail = document.getElementById('emailNews');
		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
		if(typeof(mail) == "string"){
			if(!er.test(mail)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else if(typeof(mail) == "object"){
			if(!er.test(mail.value)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else{
			alert('E-mail inválido!'); 
			mail.focus();
			return false;
		}
	}
}
/**/


/*ENVIE*/

function getEnvie(){
	if (document.getElementById("nomeAmigo").value==""){
		alert("Informe o nome de seu amigo!");
		document.getElementById("nomeAmigo").focus();
		return false;
	}
	if (document.getElementById('emailAmigo').value==""){
		alert("Informe o e-mail de seu amigo!");
		document.getElementById('emailAmigo').focus();
		return false;
	} else {
		mail = document.getElementById('emailAmigo');
		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
		if(typeof(mail) == "string"){
			if(!er.test(mail)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else if(typeof(mail) == "object"){
			if(!er.test(mail.value)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else{
			alert('E-mail inválido!'); 
			mail.focus();
			return false;
		}
	}
	if (document.getElementById("nome").value==""){
		alert("Informe o seu nome!");
		document.getElementById("nome").focus();
		return false;
	}
	if (document.getElementById('email').value==""){
		alert("Informe o seu e-mail!");
		document.getElementById('email').focus();
		return false;
	} else {
		mail = document.getElementById('email');
		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
		if(typeof(mail) == "string"){
			if(!er.test(mail)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else if(typeof(mail) == "object"){
			if(!er.test(mail.value)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else{
			alert('E-mail inválido!'); 
			mail.focus();
			return false;
		}
	}
}
/**/

/* CONTATO */

function getContato(){
	if (document.getElementById("nomee").value==""){
		alert("Informe seu nome!");
		document.getElementById("nomee").focus();
		return false;
	}
	if (document.getElementById("endereco").value==""){
		alert("Informe seu endereço!");
		document.getElementById("endereco").focus();
		return false;
	}
	if (document.getElementById("cidade").value==""){
		alert("Informe sua cidade!");
		document.getElementById("cidade").focus();
		return false;
	}
	if (document.getElementById("uf").value==""){
		alert("Informe seu Estado!");
		document.getElementById("uf").focus();
		return false;
	}
	if (document.getElementById("bairro").value==""){
		alert("Informe seu bairro!");
		document.getElementById("bairro").focus();
		return false;
	}
	if (document.getElementById("cep").value==""){
		alert("Informe seu CEP!");
		document.getElementById("cep").focus();
		return false;
	}
	if (document.getElementById("telefone").value==""){
		alert("Informe seu telefone!");
		document.getElementById("telefone").focus();
		return false;
	}
	if (document.getElementById('email').value==""){
		alert("Informe seu e-mail!");
		document.getElementById('email').focus();
		return false;
	} else {
		mail = document.getElementById('email');
		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
		if(typeof(mail) == "string"){
			if(!er.test(mail)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else if(typeof(mail) == "object"){
			if(!er.test(mail.value)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else{
			alert('E-mail inválido!'); 
			mail.focus();
			return false;
		}
	}
	if (document.getElementById("assunto").value==""){
		alert("Informe seu assunto!");
		document.getElementById("assunto").focus();
		return false;
	}
	if (document.getElementById("mensagem").value==""){
		alert("Informe sua mensagem!");
		document.getElementById("mensagem").focus();
		return false;
	}
}

/* TRABALHE CONOSCO */

function getTrabalhe(){
	if (document.getElementById("nomee").value==""){
		alert("Informe seu nome!");
		document.getElementById("nomee").focus();
		return false;
	} else {
		var txt = strlen(document.getElementById("nomee").value);
		if ( txt <= 5 ){
			alert("Preencha o nome completo!");
			document.getElementById("nomee").focus();
			return false;
		}
	}
	if (document.getElementById("nascimento").value==""){
		alert("Informe sua data de nascimento!");
		document.getElementById("nascimento").focus();
		return false;
	}
	if (document.getElementById("estadoCivil").value==""){
		alert("Informe seu estado civil!");
		document.getElementById("estadoCivil").focus();
		return false;
	}
	if (document.getElementById("cpf").value==""){
		alert("Informe seu CPF!");
		document.getElementById("cpf").focus();
		return false;
	}
	if (document.getElementById("rg").value==""){
		alert("Informe seu RG!");
		document.getElementById("rg").focus();
		return false;
	}
	if (document.getElementById('email').value==""){
		alert("Informe seu e-mail!");
		document.getElementById('email').focus();
		return false;
	} else {
		mail = document.getElementById('email');
		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
		if(typeof(mail) == "string"){
			if(!er.test(mail)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else if(typeof(mail) == "object"){
			if(!er.test(mail.value)){ 
				alert('E-mail inválido!'); 
				mail.focus();
				return false; 
			}
		}else{
			alert('E-mail inválido!'); 
			mail.focus();
			return false;
		}
	}
	if (document.getElementById("endereco").value==""){
		alert("Preencha o Endereço!");
		document.getElementById("endereco").focus();
		return false;
	}
	if (document.getElementById("bairro").value==""){
		alert("Preencha o Bairro!");
		document.getElementById("bairro").focus();
		return false;
	}
	if (document.getElementById("cidade").value==""){
		alert("Preencha a Cidade!");
		document.getElementById("cidade").focus();
		return false;
	}
	if (document.getElementById("uf").value==""){
		alert("Preencha o Estado!");
		document.getElementById("uf").focus();
		return false;
	}
	if (document.getElementById("cep").value==""){
		alert("Preencha o CEP!");
		document.getElementById("cep").focus();
		return false;
	}
	if (document.getElementById("preferencial").value==""){
		alert("Informe seu contato preferencial!");
		document.getElementById("preferencial").focus();
		return false;
	}
	if (document.getElementById("residencial").value==""){
		alert("Informe seu telefone residencial!");
		document.getElementById("residencial").focus();
		return false;
	}
	if (document.getElementById("celular").value==""){
		alert("Informe seu celular!");
		document.getElementById("celular").focus();
		return false;
	}
	if (document.getElementById("qualificacao").value==""){
		alert("Informe sua qualificação!");
		document.getElementById("qualificacao").focus();
		return false;
	}
	return true;
}

/**/


/***  onblur="tiramascara(this,'_999.999.999-99');" onkeyup="mascara(this,event,'_999.999.999-99');"   ***/
function mascara(campo,e,mask){  //*
	if (e.keyCode>30 || e.keyCode==8){
		dado1=campo.value;
		completar=' ';
		dado2='';
		if (mask.charAt(0)=='_') { completar='_'; mask=mask.substr(1); }
		while (dado1.search(/[^0-9]/)>=0) {dado1=dado1.replace(/[^0-9]/,'');}
		while (completar==' ' && dado1.charAt(0)=='0') {dado1=dado1.substr(1);}

		for (i1=0,i2=0;i1<mask.length;i1++) {
			maskch=mask.charAt(mask.length-i1-1);
			if (maskch=='9' || maskch=='0') {
				if (i2<dado1.length) { 
					dado2=dado1.charAt(dado1.length-(i2++)-1)+dado2;
				}	else {
					if (maskch=='9') { dado2=completar+dado2; } else { dado2='0'+dado2; }
				}
			} else {
				if (i2<dado1.length || mask.substr(0,mask.length-i1).search(/[0]/)>=0 || completar!=' ') {
					dado2=maskch+dado2;
				} else {
					dado2=completar+dado2;
				}
			}
		}
    campo.value=dado2;
  }

}

function tiramascara(campo,mask){  //*

	dado1=campo.value; completar=' '; dado2='';
	if (mask.charAt(0)=='_') {completar='_';mask=mask.substr(1);}
	while (dado1.search(/[^0-9]/)>=0) {dado1=dado1.replace(/[^0-9]/,'');}
	while (completar==' ' && dado1.charAt(0)=='0') {dado1=dado1.substr(1);}

	for (i1=0,i2=0;i1<mask.length;i1++) {
		maskch=mask.charAt(mask.length-i1-1);
		if (maskch=='9' || maskch=='0') {
			if (i2<dado1.length) {
				dado2=dado1.charAt(dado1.length-(i2++)-1)+dado2;
			} else {
				if (maskch=='9') {dado2=dado2;} else {dado2='0'+dado2;}
			}
		} else {
			if ( i2<dado1.length || mask.substr(0,mask.length-i1).search(/[0]/)>=0 ){
				dado2=maskch+dado2;
			} else {
				dado2=dado2;
			}
		}
	}
	campo.value="";
	campo.value=dado2;
}
/**/
