// JavaScript Document

var escreveu = 0;

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function abre_foto(cd_foto,id,im){
   if (cd_foto){
      window.open('mostra_foto.php?cd_foto='+cd_foto+'&id='+id+'&im='+im,'jfotoSite'+cd_foto,'width=420,height=360');
   }   
}
function abre_popup(cd_popup,w,h){
   if (cd_popup){
      window.open('popup.php?cd_popup='+cd_popup,'pop','width='+w+',height='+h);
   }   
}
function abre_foto_lancamento(cd_foto,id,lan,tipo,arq){
      window.open('mostra_foto_lancamento.php?cd_foto='+cd_foto+'&id='+id+'&lan='+lan+'&tipo='+tipo+'&arquivo='+arq,'jfotoSite'+cd_foto,'width=420,height=360');
}
function ficha_impressao(cd_imovel) {
	window.open('./ficha_impressao.php?id='+cd_imovel,'ficha','width=750,height=550');
}
function abre_mapa(end,foto,lat,lng) {
	window.open('./mapa.php?end='+end+'&foto='+foto+'&lat='+lat+'&lng='+lng,'mapa','width=520,height=390');
}

function reloadCidade(where){
   document.fpesc.page.value=where;
   document.fpesc.submit();
}/*
function abre_corretor(id,cd_negocio,cd_tipo,cd_imovel,referencia){
      window.open('/manager/chat/index.php?id='+id+'&cd_negocio='+cd_negocio+'&cd_tipo='+cd_tipo+'&cd_imovel='+cd_imovel+'&referencia='+referencia,'jfotoSite','width=480,height=460');
}*/

function abre_corretor(id,sessao,resposta,retorno){
//	if (IsPopupBlocker()) {
//		alert('O seu navegador está com o bloqueador de popups ativo!\nPara abrir o chat com o corretor online será necessário desabilitá-lo');
//	}else{
		window.open('http://imochat.com.br/chamado.php?id='+id+'&se='+sessao+'&resp='+resposta+'&ret='+retorno,'chamado','width=400,height=500');
//	}
}

function checkmsg(msg){
	if (msg==1){
	  alert("Sua solicitação foi enviada com sucesso!");
	}else{
		if (msg=="ok"){
		  alert("Sua mensagem foi enviada com sucesso!");
		}
		if (msg=="nok"){
		  alert("Mensagem não enviada por suspeita de SPAM!!!\n\nVerifique se você digitou corretamente as consoantes indicadas na imagem!");
		}
		if (msg=="cnok"){
		  alert("Imóvel não cadastrado por suspeita de SPAM!!!\n\nVerifique se você digitou corretamente as consoantes indicadas na imagem!");
		}
	}
}
function validate_cadastra(){

	 tipo_imovel = document.fcadastro.cd_tipo_padrao.value;
	 nome = document.fcadastro.nome.value;
	 telefone = document.fcadastro.telefone.value;
	 email = document.fcadastro.real_email.value;
	 captcha = document.fcadastro.captcha.value;
	 var ls_email=document.fcadastro.real_email.value;
     if (!tipo_imovel){
        alert("Informe o tipo de imóvel!");
        document.fcadastro.cd_tipo_padrao.focus();
     }else
	 if (!nome){
        alert("Informe o nome do proprietário!");
        document.fcadastro.nome.focus();
     }else
	 if (!telefone){
        alert("Informe o telefone do proprietário!");
        document.fcadastro.telefone.focus();
     }else
	 if (!email){
        alert("Informe o e-mail do proprietário!");
        document.fcadastro.real_email.focus();
     }else
	 if(ls_email.search("@")<0){
		alert("E-mail Inválido!");
		document.fcadastro.real_email.focus();
     }else
	 if (captcha.length == 0) {
		 alert("Digite no campo indicado as 4 consoantes que aparecem na imagem!");
		 document.fcadastro.captcha.focus();
	 }else{
		 if (captcha.length != 4){
			 if (captcha.length < 4) {
				alert("Digite TODAS as 4 consoantes que aparecem na imagem!");
				document.fcadastro.captcha.focus();
			 }else{
				alert("Digite apenas as 4 consoantes que aparecem na imagem!");
				document.fcadastro.captcha.focus();
			 }
		 }else{
			 var valoresPossiveis = "bcdfghjklmnpqrstvwxyz";
			 if ((valoresPossiveis.indexOf(captcha.charAt(0))==-1)||(valoresPossiveis.indexOf(captcha.charAt(1))==-1)||(valoresPossiveis.indexOf(captcha.charAt(2))==-1)||(valoresPossiveis.indexOf(captcha.charAt(3))==-1)) {
				 alert("Na imagem só existem consoantes minúsculas!\nUtilize apenas esse tipo de caracter e verifique se o 'CapsLock' do seu teclado está desligado!");
				 document.fcadastro.captcha.select();
				document.fcadastro.captcha.focus();
			 }else{
				 document.fcadastro.submit();
			 }
		 }
	 }
}
function validate_contato(){

	telefone = document.fcontato.telefone.value;
	mensagem = document.fcontato.mensagem.value;
	nome = document.fcontato.nome.value;
	captcha = document.fcontato.captcha.value;
	if (document.fcontato.real_email) {
		email = document.fcontato.real_email.value;
	}else{
		email = document.fcontato.email.value;
	}
	if (!telefone){
		alert("Informe seu telefone!");
		document.fcontato.telefone.focus();
	}else{
		if (!mensagem){
			alert("Escreva sua mensagem!");
			document.fcontato.mensagem.focus();
		}else{
			if (!nome){
				alert("Informe seu nome!");
				document.fcontato.nome.focus();
			}else{
				if (!email){
					alert("Informe seu e-mail!");
					document.fcontato.real_email.focus();
				}else{
					if (captcha.length == 0) {
						 alert("Digite no campo indicado as 4 consoantes que aparecem na imagem!");
						 document.fcontato.captcha.focus();
					 }else{
						 if (captcha.length != 4){
							 if (captcha.length < 4) {
								alert("Digite TODAS as 4 consoantes que aparecem na imagem!");
								document.fcontato.captcha.focus();
							 }else{
								alert("Digite apenas as 4 consoantes que aparecem na imagem!");
								document.fcontato.captcha.focus();
							 }
						 }else{
							 var valoresPossiveis = "bcdfghjklmnpqrstvwxyz";
							 if ((valoresPossiveis.indexOf(captcha.charAt(0))==-1)||(valoresPossiveis.indexOf(captcha.charAt(1))==-1)||(valoresPossiveis.indexOf(captcha.charAt(2))==-1)||(valoresPossiveis.indexOf(captcha.charAt(3))==-1)) {
								 alert("Na imagem só existem consoantes minúsculas!\nUtilize apenas esse tipo de caracter e verifique se o 'CapsLock' do seu teclado está desligado!");
								 document.fcontato.captcha.select();
								document.fcontato.captcha.focus();
							 }else{
								 document.fcontato.submit();
							 }
						 }
					 }
				}
			}
		}
	}
}
function abre_indicador(indicador, ano) {
	window.open("mostra_indicador.php?indicador=" + indicador + "&ano=" + ano,null,"directories=no, height=300, left=300, scrollbars=no, titlebar=no, top=100, width=200");
}
function setar_offline(id_sessao) {
	window.open('status_update.php','goodbye','width=20,height=20');	
}
function andamento_lanc(lanc,id) {
	window.open('popup_obras.php?cd_lancamento='+lanc+'&id='+id,'lanc_obras','width=800,height=600');
}

function mostrar_detalhes(id,caminho) {
	if (id == "ex") {
		alert("Este imovel é apenas um exemplo pois ainda não há nenhum imóvel cadastrado no site!");
	}else{
		window.location = caminho;
	}
}

function verificaPopup() {
	var cort = document.getElementById('cortinaPopup');
	var popup = document.getElementById('popup');
	var estrutura = document.getElementById('estrutura');
	
	if (cort.style.display != "none" && popup.style.display != "none") {
	//	var alturaTela = document.getElementById('tamanhoTela').offsetHeight;
	//	var tamanhoTela = document.body.offsetWidth;
		var alturaTela = $(window).height();
		var tamanhoTela = $('body').width();
		var alturaPopup = popup.offsetHeight;
		var tamanhoPopup = popup.offsetWidth;
		var scrollTopo = document.body.scrollTop;
		var popupLeft = tamanhoTela/2; 
		popupLeft = popupLeft - tamanhoPopup/2;
		var popupTop = alturaTela/2; 
		popupTop = popupTop - alturaPopup/2;
		
		popup.style.left = popupLeft+"px";
		popup.style.top = (popupTop+scrollTopo)+"px";
		
		if (tamanhoTela > estrutura.offsetWidth) { tamanhoCort = tamanhoTela; }else{ tamanhoCort = estrutura.offsetWidth; }
		alturaCort = $('html').height();
		
		cort.style.width = tamanhoCort+"px";
		cort.style.height = alturaCort+"px";
		
		setTimeout("verificaPopup();",500);
	}
}

function fechaPopup() {
	var cort = document.getElementById('cortinaPopup');
	var popup = document.getElementById('popup');
	
	cort.style.display = "none";
	popup.style.display = "none";
	popup.innerHTML = "";
	
	$('body').attr('scroll','auto').css('overflow','auto');
}

function escreveFlash(w,h,f,fv,id) {
	if (id && id != "") { id = "id='"+id+"'"; }
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' "+id+" codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' align='middle'>");
	document.write("<param name='allowScriptAccess' value='sameDomain' />");
	document.write("<param name='movie' value='"+f+"' />");
	document.write("<param name='FlashVars' value='"+fv+"' />");
	document.write("<param name='quality' value='high' />");
	document.write("<param name='bgcolor' value='#000000' />");
	document.write("<param name='wmode' value='transparent' />");
	document.write("<embed src='"+f+"' FlashVars='"+fv+"' wmode='transparent' quality='high' bgcolor='#000000' width='"+w+"' height='"+h+"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
}

function returnFlash(w,h,f,fv,id) {
	var obj = "";
	if (id && id != "") { id = "id='"+id+"'"; }
	obj += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' "+id+" codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' align='middle'>";
	obj += "<param name='allowScriptAccess' value='sameDomain' />";
	obj += "<param name='movie' value='"+f+"' />";
	obj += "<param name='FlashVars' value='"+fv+"' />";
	obj += "<param name='quality' value='high' />";
	obj += "<param name='bgcolor' value='#000000' />";
	obj += "<param name='wmode' value='transparent' />";
	obj += "<embed src='"+f+"' FlashVars='"+fv+"' wmode='transparent' quality='high' bgcolor='#000000' width='"+w+"' height='"+h+"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
	obj += "</object>";
	
	return obj;
}

if (window.Event) 
document.captureEvents(Event.MOUSEUP); 

function nocontextmenu(e) { 
	if (!e) {
		e = window.event;
	}
	e.cancelBubble = true; 
	e.returnValue = false; 
	
	return false; 
} 

function norightclick(e) {
	if (window.event) { 
		if (event.button == 2 || event.button == 3) { 
			event.cancelBubble = true;
			event.returnValue = false; 
			return false; 
		}
	}else{
		if (e.which == 2 || e.which == 3) {
			return false;
		}
	}
} 

if (document.layers) { 
document.captureEvents(Event.MOUSEDOWN); 
} 
document.oncontextmenu = nocontextmenu; 
document.onmousedown = norightclick; 
document.onmouseup = norightclick;