//escreve o flash na div desejada para que nao precise clicar nele antes de usa-lo
var pathSite = "/";
function montaFlash(destino, flavez, width, height, trans, scale){

    var myFlash =
    '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+flavez+'" align="middle">'+
    '<param name="allowScriptAccess" value="sameDomain" />'+
    '<param name="movie" value="'+pathSite+'swf/'+flavez+'" />'
    ;
    if (trans == "yes"){
        myFlash += '<param name="wmode" value="transparent" />';
    }
    if (scale == "yes"){
        myFlash += '<param name="scale" value="noscale" />';
    }
    myFlash +=
    '<param name="quality" value="high" />'+
    '<param name="bgcolor" value="#ffffff" />'+
    '<embed src="'+pathSite+'swf/'+flavez+'" wmode="transparent" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="empresas" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
    '</object>'
    ;

    document.getElementById(destino).innerHTML = myFlash;
}


// SOLU��O PARA O SCRIPT DO JQUERY QUE ENTRA EM CONFLITO COM O SCRIPT DO PROTOTYPE.
// FOI SUBSTTITUIDO O $ PARA $foo PARA SOLUCIONAR O PROBLEMA DO CONFLITO ENTRE OS SCRIPTS.
var $foo = jQuery.noConflict();

var inHome = true;


// 1 VARI�VEL (VETOR) E 2 METODOS PARA CONTROLAR AS LISTAS DE CATEGORIAS NA GALERIA DE FOTOS DO SITE
var categorias = new Array();


function verificaHome(){
    var urlAtual = window.location.href;
    var array = urlAtual.split("#");
    var tamanho = array.length;
	
    if(tamanho > 1)
    {
        var param = array[tamanho-1];
    }
    else
    {
        var param = "";
    }
	
    if((param == "") && (tamanho <= 2))
    {
        carregapagina("principal");
    }
}


//valida data
function ValidaData(data){
    exp = /\d{2}\/\d{2}\/\d{4}/
    if(!exp.test(data.value)){
        return false;
    }
		
    return true;
}

function validaCEP(cep){
    if(!(/^[0-9]{2}\.[0-9]{3}\-[0-9]{3}$/.test(cep))){
        return false;
    } else {
        return true;
    }
}

function validaCPF(Objcpf){
    var cpf = Objcpf;
    exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" );
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;

    for(i=0;i<9;i++){
        soma1+=eval(cpf.charAt(i)*(vlr-1));
        soma2+=eval(cpf.charAt(i)*vlr);
        vlr--;
    }
    soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
    soma2=(((soma2+(2*soma1))*10)%11);

    var digitoGerado=(soma1*10)+soma2;
    if(digitoGerado!=digitoDigitado){
        return false;
    }else {
        return true;
    }
}


				
function carregapagina(params){
    show_loading();
	
    setTimeout("pausa('"+params+"')",100);
}

function pausa (params) {
		   
    $foo("#internas").load(pathSite+"ctrl.php?acao="+params, hide_loading);
}


//mostra a mensagem de carregando
show_loading = function() {
    //document.getElementById("fundoInternas").style.backgroundColor = "#FFFFFF";
    // $foo("#ajax_loader").show();
    $foo("#internas").slideUp("normal");
//$foo("#internas").slideUp(300);
	
}

//oculta a mensagem de carregando
hide_loading = function() {
    //$foo("#ajax_loader").hide();
    $foo("#internas").slideDown("normal");
	
    //$foo("#internas").slideDown("normal");
    
    //inicializa novamente o lightbox para paginas carregadas internamente via ajax
    setTimeout("Lightbox.prototype.updateImageList()", 100);
}

//verifica se o email informada eh valido
function validaEmail(email){
    ER = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]{2,64}(\.[a-z0-9-]{2,64})*\.[a-z]{2,4}$");
    if (ER.test(email)){
        return true;
    }
    else{
        return false;
    }
}
/***** CONTATO *****/

/**
 * @form formulário a ser validado
 */

/***** INDEX *****/

function getBairrosByCidade(acao, div, id)
{
    document.getElementById(div+id).style.visibility = "hidden";
    jQuery("#"+div+id).load(pathSite+"ctrl.php?acao=listarBairros&cidade="+acao,showBairrosByCidades(div,id));
}

showBairrosByCidades = function(div,id)
{
    document.getElementById(div+id).style.visibility = "visible";
    document.getElementById(div+id).disabled = false;
}


function htmlExpandMapa(src,width,height,id){
    setTimeout(function(){
        $foo('.highslide-body').GoogleMaps({
            width : (width || 530) - 30,
            height : (height || 400) - 45,
            zoom : 17,
            showInfoImovel : true,
            lightbox : false
        });
        $foo.GoogleMaps.buscarImoveis(null,id);
    },1000);
    return hs.htmlExpand(src, {
        width:width || 530,
        height:height || 400,
        dimmingOpacity:0.1,
        wrapperClassName: 'draggable-header no-footer'
    });
    
}

function tiraOverflow(id,idMais,idMenos){
    document.getElementById(id).className = "divContOverflowFiltroAuto";
    document.getElementById(idMais).style.display = "none";
    document.getElementById(idMenos).style.display = "";
}

function overflowOk(id,idMais,idMenos){
    document.getElementById(id).className = "divContOverflowFiltro";
    document.getElementById(idMais).style.display = "";
    document.getElementById(idMenos).style.display = "none";

}

//sistema de buscar da pagina principal

function buscarScript(){
    if (document.getElementById('bNumQuartos').value != "null"){
        var idQuarto = "&idQuarto="+document.getElementById('bNumQuartos').value;
    }else{
        var idQuarto = "";
    }

    if (document.getElementById('bTipo').value != "null"){
        var idTipo = "&idCategoria="+document.getElementById('bTipo').value;
    }else{
        var idTipo = "";
    }

    if (document.getElementById('bCidade').value != "null"){
        var idCidade = "&idCidade="+document.getElementById('bCidade').value;
    }else{
        var idCidade = "";
    }

    if (document.getElementById('bBairro').value != "null"){
        var idBairro = "&idBairro="+document.getElementById('bBairro').value;
    }else{
        var idBairro = "";
    }
    
    var idCompra = document.getElementById('compra').value;
    var idAluguel = document.getElementById('aluguel').value;



    document.location = pathSite+"buscar/"+idQuarto+idTipo+idCidade+idBairro;
    

}

function openCloseDetailsImovel(id){
    if($foo("#"+id).css('display')=='none'){
        $foo("#"+id).slideDown(1000, function(){
            return;
        });
    } else {
        $foo("#"+id).slideUp(1000, function(){
            return;
        });
    }
}

function getCidadesTrabalhe(uf,id){
      document.getElementById("cidades"+id).style.visibility = "hidden";
        jQuery("#cidades").load(pathSite+"ctrl.php?acao=listarCidades&uf="+uf,showCidadesTrabalhe(id));

    }

showCidadesTrabalhe = function(id){
        document.getElementById("cidades").style.visibility = "visible";
        document.getElementById("cidades").disabled = false;
    }

function getBairroTrabalhe(uf,id){
      document.getElementById("bairros"+id).style.visibility = "hidden";
        jQuery("#bairros").load(pathSite+"ctrl.php?acao=listarBairrosTrabalhe&cidade="+uf,showBairrosTrabalhe(id));

    }

showBairrosTrabalhe = function(id){
        document.getElementById("bairros").style.visibility = "visible";
        document.getElementById("bairros").disabled = false;
    }
	
	
	
	
	function atendimento(path)
	{
		window.open(path+'atendimento/livehelp.php?department=2', null, 'height=400, width=600, status=no, toolbar=no, menubar=no, location=no')	
	}
	
function ligacao()
{
	window.open(pathSite+'internas/ligacao.php','Ligar_de_Graca','width=430,height=370');
}

function favoritos(urlMostra,titleMostra){
    var url      = urlMostra;
    var title    = titleMostra;
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}

function validaFrmIndique(form){
	$foo("#resposta").show();
	if(form.txtSeuNome.value==""){
		$foo("#resposta").html("Por favor, preencha o campo NOME!");
		form.txtSeuNome.focus();
		return false;
	}
	if(form.txtSeuEmail.value==""){
		$foo("#resposta").html("Por favor, preencha o campo EMAIL!");
		form.txtSeuEmail.focus();
		return false;
	}else{
		if(!validaEmail(form.txtSeuEmail.value)){
			$foo("#resposta").html("Por favor, informe um EMAIL V&Aacute;LIDO!");
			form.txtSeuEmail.focus();
			return false;
		}
	}

	if(form.txtNomeAmigo.value==""){
		$foo("#resposta").html("Por favor, preencha o campo NOME DO AMIGO!");
		form.txtNomeAmigo.focus();
		return false;
	}
	if(form.txtEmailAmigo.value==""){
		$foo("#resposta").html("Por favor, preencha o campo EMAIL DO AMIGO!");
		form.txtEmailAmigo.focus();
		return false;
	}else{
		if(!validaEmail(form.txtEmailAmigo.value)){
			$foo("#resposta").html("Por favor, informe um EMAIL DE AMIGO V&Aacute;LIDO!");
			form.txtEmailAmigo.focus();
			return false;
		}
	}

	$foo("#resposta").load('/ctrl.php?'+$foo("#frmIndicaAmigo").formSerialize());
}


function validaFrmContato(form)
{
    if(form.nome.value == "")
    {
        document.getElementById('respostaContato').innerHTML = "<span style='color:red;'>&there4; Preencha o campo NOME! &there4;</span>";
        form.nome.focus();
        return false;
    }

    if(form.email.value == "")
    {
        document.getElementById('respostaContato').innerHTML = "<span style='color:red;'>&there4; Preencha o campo E-MAIL! &there4;</span>";
        form.email.focus();
        return false;
    }
    else
    {
        if(!validaEmail(form.email.value))
        {
            document.getElementById('respostaContato').innerHTML = "<span style='color:red;'>&there4; E-MAIL INVÁLIDO! &there4;</span>";
            form.email.focus();
            return false;
        }
    }
    if(form.telefone.value == "")
    {
        document.getElementById('respostaContato').innerHTML = "<span style='color:red;'>&there4; Preencha o campo TELEFONE! &there4;</span>";
        form.telefone.focus();
        return false;
    }

    if(form.mensagem.value == "")
    {
        document.getElementById('respostaContato').innerHTML = "<span style='color:red;'>&there4; Preencha o campo MENSAGEM! &there4;</span>";
        form.mensagem.focus();
        return false;
    }

    document.getElementById('respostaContato').innerHTML = "";

}

/********************/
/*					*/
/***** CADASTRO *****/
/*					*/
/********************/


