
function abre(obj){
  document.getElementById(obj).style.display = 'block';
  document.getElementById('pf').style.display = 'none';
  location.href="#fadsl";
}

function habilitaPrSearch(){
	var ad = document.getElementById('formsearch2');
	
	if ( ad.cidade_s.value != "" || ad.bairro_s.value != ""  || ad.categoria_s.value != "" ){
        document.getElementById('box-pr-search').style.display = 'block';
	}else{
		document.getElementById('box-pr-search').style.display = 'none';
	}
	
}

function formSearch(){
	
	var ad = document.formsearch;

	if ( ad.cidade_s.value == "" && ad.bairro_s.value== ""  && ad.categoria_s.value == "" ){
		alert('Você não selecionou nehum tipo de busca.');
		return false;
	}
	
}


function sizeVideo(tipo){
var IE = document.all?true:false;
var elemento=document.getElementById('swfvideoslide2');
sizeLope(elemento, tipo);
if(!IE){
var elemento=document.getElementById('swfvideoslide');
sizeLope(elemento, tipo);
}
}

function sizeLope(obj, tipo){
  
  var box_swf = document.getElementById('box-video-slide-position');

  if(tipo == 1)
  {
     obj.width= '196'; 
	 obj.height= '140';
	 box_swf.className = 'box-video-p';
  }
  else
  {
     obj.width = '446'; 
	 obj.height = '325';
	 box_swf.className = 'box-video-b';
  }


}


function swfObject(cod_video, width, height){
   
       document.write('<object id="swfvideoslide" width="'+width+'" height="'+height+'"><param name="movie" value="http://www.youtube.com/v/'+cod_video+'&color1=0x669999&amp;color2=0x669999&hl=pt-br&fs=1"></param><param name="allowscriptaccess" value="always"></param><param name="allowscriptaccess" value="always"></param><embed id="swfvideoslide2" src="http://www.youtube.com/v/'+cod_video+'&color1=0x669999&amp;color2=0x669999&hl=pt-br&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed></object>');
	
}


function contato(){
	var mensarem_erro="", cont_erro=0;
	var ad = document.getElementById('form_contato');
	var d = document.getElementById('erro').style;
	
			
	if (ad.nome_cont.value == "") {
        mensarem_erro += "<b>Nome:</b> é de preenchimento obrigatório<br />";
		d.display = 'block';
		cont_erro++;
		
	}
			
			
	if (ad.email_cont.value == "") {
        mensarem_erro += "<b>Email:</b> é de preenchimento obrigatório<br />";	
		d.display = 'block';
		
		cont_erro++;				
	}
			
   if (ad.email_cont.value != "") {			
   		if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(ad.email_cont.value))) { 
			mensarem_erro += "<b>Email:</b> Inválido<br />";
			d.display = 'block';
			cont_erro++;			
	   }		
   }

	if (ad.cidade_cont.value == "") {
         mensarem_erro += "<b>Cidade:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}
	
	if (ad.estado_cont.value == "") {
         mensarem_erro += "<b>Estado:</b> é de preenchimento obrigatório<br />";	
		 d.display = 'block';
	     cont_erro++;				
	}
	
	if (ad.assunto_cont.value == "") {
         mensarem_erro += "<b>Assunto:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}	
	
	if (ad.texto_cont.value == "") {
         mensarem_erro += "<b>Comentário:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}
			
	if (cont_erro > 0) {
		document.getElementById("erro").style.display="block";
		var mensagem_final = "<h4>Foram encontrados "+ cont_erro +" erros no formulário.</h4><p class=\"er\">"+ mensarem_erro +"</p>";
		document.getElementById("erro").innerHTML = mensagem_final;			
		///location.href="#erro";	
		return false;
	}
	
	return true;
			
}

/********telefone***********/
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function telefone(v){
    v=v.replace(/\D/g,"")                
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2")
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    
    return v
}


function aboft(){
        var xmlhttp=false;
        try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
                try{
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(E){
                        xmlhttp = false;
                }
        }

        if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
                xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
}


function limp(obj){
 document.getElementById(obj).style.display="none";
}

function informacoes(field){
        var conteudo;
        c = document.getElementById('loading_info');
		var ad = document.getElementById('formInfo');
		
		c.style.display = "block";
			
	if (ad.nomeInfo.value == "") {
        c.innerHTML = "Campo <b>Seu nome</b> é obrigatório";
		ad.nomeInfo.focus();
		return false;
	}
	
	if (ad.emailInfo.value == "") {
        c.innerHTML = "Campo <b>Seu e-mail</b> é obrigatório";
		ad.emailInfo.focus();
		return false;
	}
	if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(ad.emailInfo.value))) { 
		c.innerHTML = "<b>Seu email</b> inválido";
		ad.emailInfo.focus();
		return false;		
	}
	if (ad.telefoneInfo.value == "") {
        c.innerHTML = "Campo <b>Telefone:</b> é obrigatório";
		ad.telefoneInfo.focus();
		return false;
	}
	
 
        ajax=aboft(); 
		
var IE = document.all?true:false;
if(!IE){
  metho = 'GET';
}else{
  metho = 'POST';
}

        ajax.open(metho, 'ajax/informacao-imovel.php?'+field, true);
		ajax.setRequestHeader("Cache-Control", "no-cache");
        ajax.setRequestHeader("Pragma", "no-cache");
        ajax.setRequestHeader("Charset", "ISO-8859-1");
		
		c.innerHTML= '<img src="images/loading.gif" align="absmiddle" style="margin-right:3px;" />Enviando...';
		
        ajax.onreadystatechange=function(){
                if(ajax.readyState==1){	
                      
                }else if(ajax.readyState==4){
	                        if(ajax.status==200){
							
							  c.innerHTML = ajax.responseText;
							  
							  if(c.innerHTML == 1)
							  {
								 c.innerHTML = '<p class="sucessoInfo">Em breve estaremos retornando o contato !</p>';  
								 setInterval("c.style.display='none'", 5000);
							  }
		
                        }else if(ajax.status==404){
                                conteudo.innerHTML = "Página não encontrada";
                        }else{

                                conteudo.innerHTML = "Error:".ajax.status; 
                        }
                }
        }
        ajax.send(field);

}

function setField() {

field = "&nomeInfo="+encodeURI(document.getElementById('nomeInfo').value)+"&emailInfo="+encodeURI(document.getElementById('emailInfo').value)+"&telefoneInfo="+encodeURI(document.getElementById('telefoneInfo').value)+"&mensagemInfo="+encodeURI(document.getElementById('mensagemInfo').value)+"&cod_imovelInfo="+encodeURI(document.getElementById('cod_imovelInfo').value)+"&titulo_imovelInfo="+encodeURI(document.getElementById('titulo_imovelInfo').value);

}






function indica_imovel(field){
        var conteudo;
        c = document.getElementById('loading_indique');
		var ad = document.getElementById('form_indica_imovel');
		
		c.style.display = "block";
			
	if (ad.ip_seu_nome.value == "") {
        c.innerHTML = "Campo <b>Seu nome</b> é obrigatório";
		ad.ip_seu_nome.focus();
		return false;
	}
	
	if (ad.ip_seu_email.value == "") {
        c.innerHTML = "Campo <b>Seu e-mail</b> é obrigatório";
		ad.ip_seu_email.focus();
		return false;
	}
	if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(ad.ip_seu_email.value))) { 
		c.innerHTML = "'Seu <b>e-mail</b> inválido";
		ad.ip_seu_email.focus();
		return false;		
	}
	if (ad.ip_nome_amigo.value == "") {
        c.innerHTML = "Campo <b>Nome amigo</b> é obrigatório";
		ad.nome_a.focus();
		return false;
	}
	if (ad.ip_email_amigo.value == "") {
        c.innerHTML = "Campo <b>E-mail amigo</b> é obrigatório";
		ad.ip_email_amigo.focus();
		return false;
	}
	if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(ad.ip_email_amigo.value))) { 
		c.innerHTML = "'<b>E-mail amigo</b> inválido";
		ad.ip_email_amigo.focus();
		return false;		
	}
	if (ad.ip_comentario.value == "") {
        c.innerHTML = "Campo <b>Comentário</b> é obrigatório";
		ad.ip_comentario.focus();
		return false;
	}
	
 
        ajax=aboft(); 
		
		
var IE = document.all?true:false;
if(!IE){
  metho = 'GET';
}else{
  metho = 'POST';
}

        ajax.open(metho, 'ajax/indica_imovel.php?'+field, true);
		ajax.setRequestHeader("Cache-Control", "no-cache");
        ajax.setRequestHeader("Pragma", "no-cache");
        ajax.setRequestHeader("Charset", "ISO-8859-1");
		
		c.innerHTML= '<img src="images/loading.gif" align="absmiddle" style="margin-right:3px;" />Enviando...';
		
        ajax.onreadystatechange=function(){
                if(ajax.readyState==1){	
                      
                }else if(ajax.readyState==4){
	                        if(ajax.status==200){
							
							  c.innerHTML = ajax.responseText;
                              
							  if(c.innerHTML == 1)
							  {
								 c.innerHTML = '<p class="sucessoInfo">Imóvel indicado com sucesso !</p>';  
								 setInterval("c.style.display='none'", 5000);
							  }
							  
                            }else if(ajax.status==404){
                                conteudo.innerHTML = "Página não encontrada";
                        }else{

                                conteudo.innerHTML = "Error:".ajax.status; 
                        }
                }
        }
        ajax.send(field);

}


function setField_imovel() {

field = "&cod_imovel="+encodeURI(document.getElementById('cod_imovel').value)+"&ip_seu_nome="+encodeURI(document.getElementById('ip_seu_nome').value)+"&ip_seu_email="+encodeURI(document.getElementById('ip_seu_email').value)+"&ip_nome_amigo="+encodeURI(document.getElementById('ip_nome_amigo').value)+"&ip_email_amigo="+encodeURI(document.getElementById('ip_email_amigo').value)+"&ip_comentario="+encodeURI(document.getElementById('ip_comentario').value);

}






function openWindow(pagina,largura,altura) {

w = screen.width;
h = screen.height;

meio_w = w/2;
meio_h = h/2;

altura2 = altura/2;
largura2 = largura/2;
meio1 = meio_h-altura2;
meio2 = meio_w-largura2;

window.open(pagina,'','height=' + altura + ', width=' + largura + ', top=0, left=0'); 
}


function post_rec(){
var mensarem_erro="", cont_erro=0;
var ad = document.form_post_recado;

if (ad.nome.value == "") {
			mensarem_erro += "<b>Nome:</b> é de preenchimento obrigatório<br />";
		    cont_erro++;	}

if (ad.email.value == "") {
        mensarem_erro += "<b>E-mail:</b> é de preenchimento obrigatório<br />";				
		cont_erro++;				
	}
if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(ad.email.value))) {
			mensarem_erro += "<b>E-mail:</b> inválido<br />";
		    cont_erro++;}
			
if (ad.cidade.value == "") {
			mensarem_erro += "<b>Cidade:</b> é de preenchimento obrigatório<br />";
		    cont_erro++;}

if (ad.estado.value == "") {
        mensarem_erro += "<b>Estado:</b> é de preenchimento obrigatório<br />";				
		cont_erro++;				
	}
			
if (ad.recado.value == "") {
			mensarem_erro += "<b>Recado:</b> é de preenchimento obrigatório<br />";
		    cont_erro++;}
			
if (ad.img_seguranca.value == "") {
			mensarem_erro += "<b>Código de segurança:</b> é de preenchimento obrigatório<br />";
		    cont_erro++;}
			
if (cont_erro > 0) {
		document.getElementById("erro").style.display="block";
		var mensagem_final = "<h4>Foram encontrados "+ cont_erro +" erros no formulário.</h4><p class=\"er\">"+ mensarem_erro +"</p>";
		document.getElementById("erro").innerHTML = mensagem_final;			
		location.href="#erro";	
		return false;
	}
}





function anuncie(){
	var mensarem_erro="", cont_erro=0;
	var ad = document.getElementById('form_anunciar_imovel');
	var d = document.getElementById('erro').style;
	
			
	if (ad.nome_anu.value == "") {
        mensarem_erro += "<b>Nome:</b> é de preenchimento obrigatório<br />";
		d.display = 'block';
		cont_erro++;
		
	}
			
    if (ad.tel_anu.value == "") {
         mensarem_erro += "<b>Telefone:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}			
			
	if (ad.email_anu.value == "") {
        mensarem_erro += "<b>E-mail:</b> é de preenchimento obrigatório<br />";	
		d.display = 'block';
		
		cont_erro++;				
	}
			
    if (ad.email_anu.value != "") {			
   		if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(ad.email_anu.value))) { 
			mensarem_erro += "<b>E-mail:</b> Inválido<br />";
			d.display = 'block';
			cont_erro++;			
	   }		
    }

	
	
	if (ad.nomeimovel_cont.value == "") {
         mensarem_erro += "<b>Nome do imóvel:</b> é de preenchimento obrigatório<br />";	
		 d.display = 'block';
	     cont_erro++;				
	}
	
	if (ad.categoria_anu.value == "") {
         mensarem_erro += "<b>Categoria:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}	
	
	if (ad.endereco_anu.value == "") {
         mensarem_erro += "<b>Endereço:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}	
	
	if (ad.bairro_anu.value == "") {
         mensarem_erro += "<b>Bairrp:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}	
	
	if (ad.cidade_anu.value == "") {
         mensarem_erro += "<b>Cidade:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}
	
	if (ad.suites_anu.value == "") {
         mensarem_erro += "<b>Suítes:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}
	
	if (ad.dormitorios_anu.value == "") {
         mensarem_erro += "<b>Dormitórios:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}
	
	if (ad.banheiros_anu.value == "") {
         mensarem_erro += "<b>Banheiros:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}
	
	if (ad.garagem_anu.value == "") {
         mensarem_erro += "<b>Garagem:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}
	
	if (ad.valor_anu.value == "") {
         mensarem_erro += "<b>Valor:</b> é de preenchimento obrigatório<br />";
		 d.display = 'block';
	     cont_erro++;				
	}
	
			
	if (cont_erro > 0) {
		document.getElementById("erro").style.display="block";
		var mensagem_final = "<h4>Foram encontrados "+ cont_erro +" erros no formulário.</h4><p class=\"er\">"+ mensarem_erro +"</p>";
		document.getElementById("erro").innerHTML = mensagem_final;			
		///location.href="#erro";	
		return false;
	}
	
	return true;
			
}




function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else 
document.getElementById("cont_recado").innerHTML = maxlimit - field.value.length;
}




var Convert = {
initialize: function() {
var spans = document.getElementsByTagName("span");
for (var i = 0; i < spans.length; i++) {
if(spans[i].getAttribute("class") == "maskemail") {
string = spans[i].childNodes[0].nodeValue;
email = string.split("_")[0] + "@" + string.split("_")[2];
spans[i].innerHTML = '<a class="email" href="mailto:' + email + '">' + email + '<\/a>';
}
}
}
}
window.onload = Convert.initialize;
