//*** INICIO FUNCAO PARA MOSTRAR E OCULTAR CAMPOS ***//
	// Mostra a camada
	function mostrar_camada(camadas) {
		var camada = camadas.split(",");

		for(i=0;i<camada.length;i++) {
			document.getElementById(camada[i]).style.display="block";
		}
	}

	// Oculta a camada
	function ocultar_camada(camadas) {
		var camada = camadas.split(",");

		for(i=0;i<camada.length;i++) {
			document.getElementById(camada[i]).style.display="none";
		}
	}
//*** FIM FUNCAO PARA MOSTRAR E OCULTAR CAMPOS ***//

//*** INICIO VARIAS FUNCOES ***//
	// Confirma exclusao
	function confirma_acao(msg,url){
		if(confirm(msg)) {
			open(url,"_self");
		}
	}

	// Abrir janela pop-up
	function nova_janela(url,nome_janela,largura_janela,altura_janela) {
		posicao_x = ((window.screen.width-50)-largura_janela)/2;
		posicao_y = ((window.screen.height)-altura_janela)/2;

		window.open(url, nome_janela, 'top='+ posicao_y +',left='+ posicao_x +',width='+ largura_janela +',height='+ altura_janela +'');
	}
	
	// Abre nova URL
	function jump_url(targ,selObj){ //v3.0
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	}	
	
	// Abrir foto ampliada
	function ampliar_foto_detalhesimovel(imagem) {
		var subImages = document.getElementById('foto_ampliada_di');
		subImages.src = imagem;
	}
	
	// Maxima a tela e centraliza
	function maximiza_tela() {
		window.moveTo(0,0);
		window.resizeTo(screen.width,screen.height);
	}

//CNPJ//
function mascaraCnpj(campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1;
		if (tecla != 14){
		if (tam == 3)
			campo.value = vr.substr(0, 2) + '.';
		if (tam == 6)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
		if (tam == 10)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
		if (tam == 15)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
	}
}

//INSCRIÇÃO ESTADUAL//
function mascaraInscEstadual(campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1;
		if (tecla != 9){
		if (tam == 3)
			campo.value = vr.substr(0, 2) + '.';
		if (tam == 6)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
		if (tam == 10)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '-' + vr.substr(9, 4);
	}
}

//CEP//
function mascaraCEP(campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(campo.value);
	vr = vr.replace("-", "");
	tam = vr.length + 1;
		if (tecla != 9){
		if (tam == 6)
			campo.value = vr.substr(0, 5) + '-';
	}
}

	// Valida o e-mail
function Cond_email(Email)	{
	// O campo e-mail precisa conter mais do que 5 caracteres.	
	if(Email.length < 5) return false;
	// O campo e-mail precisa conter um '@'.
	for (sinal=0; sinal < Email.length; sinal++)
		if (Email.charAt(sinal) == '@')
			break;
		if (sinal == Email.length) return false;
	// O campo e-mail precisa conter um '.' após o '@'.
	for (sinal_=sinal+1; sinal_ < Email.length; sinal_++)
		if (Email.charAt(sinal_) == '.')
			break;
		if (sinal_ == Email.length) return false;
return true;
}

// Valida formulario do faleconosco
function valida_contato() {
	// Pega o form
	formulario = document.contato;
	
	// Validar nome
	if(formulario.nome.value == "") {
		alert("O campo nome deve ser preenchido!");
		formulario.nome.focus();
		return false;
	}
	
	// Validar e-mail
	if (Cond_email(formulario.email.value) == ""){
		alert("O campo e-mail deve ser preenchido!");
		formulario.email.focus();
		return false;
	}
	
		// Validar cidade
	if (formulario.cidade.value == ""){
		alert("O campo cidade deve ser preenchido!");
		formulario.cidade.focus();
		return false;
	}
	
		// Validar estado
	if (formulario.estado.value == ""){
		alert("O campo estado deve ser preenchido!");
		formulario.estado.focus();
		return false;
	}
	
	// Validar telefone
	if (formulario.telefone.value == ""){
		alert("O campo telefone deve ser preenchido!");
		formulario.telefone.focus();
		return false;
	}
	
	// Validar assunto
	if (formulario.assunto.value == ""){
		alert("O campo assunto deve ser preenchido!");
		formulario.assunto.focus();
		return false;			
	}
	
	// Validar messagem
	if (formulario.mensagem.value == ""){
		alert("O campo mensagem deve ser preenchido!");
		formulario.mensagem.focus();
		return false;			
	}	
}
	
	// Controla os checkbox do guia de profissionais
	function guiaprofissionais_checkbox(op) {
		// Formulario
		formulario = document.form_guiaprofissionais;
	
		// Seleciona todos os checkbox do formulário
		for(i=0;i<formulario.elements.length;i++) {
			if(formulario.elements[i].type == "checkbox") {
				formulario.elements[i].checked = op;
			}
		}
	
		// Modifica o label, o href do link e a imagem
		if(op == 0) {
			document.getElementById('bt_checkbox').innerHTML = "Marca todas as empresas";
			document.getElementById('link_checkbox').href = "javascript: guiaprofissionais_checkbox(1);";
			document.getElementById('img_checkbox').src = "/imagens/icone/icone_ok.png";
		} else {
			document.getElementById('bt_checkbox').innerHTML = "Desmarca todas as empresas";


			document.getElementById('link_checkbox').href = "javascript: guiaprofissionais_checkbox(0);";
			document.getElementById('img_checkbox').src = "/imagens/icone/icone_erro.png";
		}
	}
	
//*** INICIO MASCARAS DO FORMULARIO ***//
jQuery(function($) {
	$.mask.definitions['~']='[+-]';
	$('#ano_construcao').mask('9999'); // ano de construção do PAINEL
	$('#data_inicio').mask('99/99/9999'); // data inicial do PAINEL
	$('#data_fim').mask('99/99/9999'); // data final do PAINEL
	$("#cnpj").mask('99.999.999/9999-99'); // CNPJ
	$("#area_util").maskMoney(); // area util do PAINEL
	$("#area_aberta").maskMoney(); // area aberta do PAINEL
	$("#area_total").maskMoney(); // area total do PAINEL
	$("#valor_agio").maskMoney(); // valor do agio do PAINEL
	$("#valor_prestacao").maskMoney(); // valor da prestacao do PAINEL
	$("#valor_condominio").maskMoney(); // valor do condominio do PAINEL
	$("#valor_imovel").maskMoney(); // valor do imovel do PAINEL
	//$("#valor").maskMoney();  valor do PRODUTO
	
	$("#valor_imovel_min").maskMoney(); // valor minimo do imovel no INDEX BUSCA RAPIDA
	$("#valor_imovel_max").maskMoney(); // valor maximo do imovel no INDEX BUSCA RAPIDA
	
	$('#telefone').mask('(99) 9999-9999'); // telefone na sessão FALE CONOSCO
	$('#celular').mask('(99) 9999-9999'); // celular na sessão FALE CONOSCO
	$('#cep').mask('99999-999'); // cep na sessão FALE CONOSCO
	
	$('#seu_telefone').mask('(99) 9999-9999'); // telefone na sessão CONTATO COM A IMOBILIARIA
	
	$('#telefone_amigo').mask('(99) 9999-9999'); // telefone na sessão INDICAR IMOVEL

	$("#area_util_de").maskMoney(); // area util do BUSCA AVANÇADA
	$("#area_util_ate").maskMoney(); // area aberta do BUSCA AVANÇADA
	$("#area_total_de").maskMoney(); // area total do BUSCA AVANÇADA
	$("#area_total_ate").maskMoney(); // valor do agio do BUSCA AVANÇADA
	$("#valor_condominio_de").maskMoney(); // valor do condominio do BUSCA AVANÇADA
	$("#valor_condominio_ate").maskMoney(); // valor do condominio do BUSCA AVANÇADA
	$("#valor_imovel_de").maskMoney(); // valor do imovel do BUSCA AVANÇADA
	$("#valor_imovel_ate").maskMoney(); // valor minimo do imovel no BUSCA AVANÇADA
	
	$('#fax').mask('(99) 9999-9999'); // fax na sessão ADMTOP
});
//*** FIM MASCARAS DO FORMULARIO ***//

//*** INICIO - HINT ***/
var horizontal_offset = "5px"; //horizontal offset of hint box from anchor link

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.style.cursor="default"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox
//*** FIM - HINT ***/

//DATAS//
function mascaraData_inicio(campoData_inicio){              
		var data_inicio = campoData_inicio.value;              
			if (data_inicio.length == 2){                  
		data_inicio = data_inicio + '/';                  
		document.forms[0].data_inicio.value = data_inicio;
		    return true;
				}
			if (data_inicio.length == 5){                  
		data_inicio = data_inicio + '/';                  
		document.forms[0].data_inicio.value = data_inicio;                  
			return true;              
			}
		} 

function mascaraData_fim(campoData_fim){              
		var data_fim = campoData_fim.value;              
			if (data_fim.length == 2){                  
		data_fim = data_fim + '/';                  
		document.forms[0].data_fim.value = data_fim;
		    return true;
				}
			if (data_fim.length == 5){                  
		data_fim = data_fim + '/';                  
		document.forms[0].data_fim.value = data_fim;                  
			return true;              
			}
		}
		
function mascaraData(campoData){              
		var data = campoData.value;              
			if (data.length == 2){                  
		data = data + '/';                  
		document.forms[0].data.value = data;
		    return true;
				}
			if (data.length == 5){                  
		data = data + '/';                  
		document.forms[0].data.value = data;                  
			return true;              
			}
		} 
	
//SELECIONA TUDO //
function marcar_tudo(){ 
   for (i=0;i<document.form1.elements.length;i++) 
      if(document.form1.elements[i].type == "checkbox")	
         document.form1.elements[i].checked=1 
}

function desmarcar_tudo(){ 
   for (i=0;i<document.form1.elements.length;i++) 
      if(document.form1.elements[i].type == "checkbox")	
         document.form1.elements[i].checked=0 
}

//OCULTAR CAMPO//
function valor(destaque) {
if(destaque=="sim") {
document.form1.posicao.style.display="block";
}
if(destaque=="nao") {
document.form1.posicao.style.display="none";
}
} 

