﻿

   jQuery(document).ready(function($) {
    /***Select personalizado**********/
    //    $('.selectArea > p').live('click', function() {
    //        var ul = '#selectAreaUl' + $(this).attr('id');
    //        $(ul).slideToggle('fast');
    //        $(this).css('background-color', '#FEFDC0');
    //    });

    //    $('.selectArea').live('mouseleave', function() {
    //        var ul = '#selectAreaUl' + $(this).attr('id').replace("selectArea", "");
    //        $(ul).slideUp('fast');
    //        $('#' + $(this).attr('id') + " > p").css('background-color', '#FFF');
    //    });

    //    $('.selectArea > ul > li').live('click', function() {
    //        $("#" + $(this).attr('class')).val($(this).attr('id').replace('seleAreaLi', ''));

    //        var filtro = '#selectArea' + $(this).attr('class') + " > p";

    //        $(filtro).html($(this).html());
    //    });

    /***Select com checkbox***********/

$('.divSelectCheck').each(function() {

        $(this).mouseleave(function() {
            //$(this).firstchild().next().next().next().hide('slow');
            $('.ulSelectCheck li').hide('fast');
            selCheck = "#" + $(this).attr('id') + " input:checked";

            //            if ($(selCheck).length == 1)
            //                $("#" + $(this).attr('id') + " > p").html($("#li" + $(selCheck).attr('value') + $(this).attr('id').replace('divSelectCheck', '') + " > span").html());
            //            else
            if ($(selCheck).length > 0)
                $("#" + $(this).attr('id') + " > p").html($(selCheck).length.toString() + " Selecionados")
            //            else
            //                $("#" + $(this).attr('id') + " > p").html($("#" + $(this).attr('id') + " > b").html());
        });
        $(this).click(function() {
            // $('.ulSelectCheck').show('fast');
            $(this).find('ul').show('fast');
            $(this).find('ul').find('li').show('fast');
            //$('.ulSelectCheck li').show('fast');
        });
    });
    //    $('.divSelectCheck > p').live('click', function() {
    //        var ul = '#ulSelectCheck' + $(this).attr('id');
    //        $(ul).slideToggle('fast');
    //        $(this).css('background-color', '#FEFDC0');
    //    });
    //	
    //	$('.divSelectCheck > ul > li').live('click',function(){
    //		var check = "#" + $(this).attr('id') + " > input";
    //		var icCheck = $(check).attr('checked');
    //		if((icCheck == "false")||(icCheck==""))
    //			$(check).attr('checked','true');
    //		else
    //			$(check).attr('checked','');

    //	});

    //	$('.divSelectCheck input').live('click',function(){
    //		var icCheck = $(this).attr('checked');
    //		if((icCheck == "false")||(icCheck==""))
    //			$(this).attr('checked','true');
    //		else
    //			$(this).attr('checked','');
    //	});

    //    $('.divSelectCheck').live('mouseleave', function() {
    //        var ul = '#ulSelectCheck' + $(this).attr('id').replace("divSelectCheck", "");
    //        $(ul).slideUp('fast');
    //        $('#' + $(this).attr('id') + " > p").css('background-color', '#FFF');

    //        selCheck = "#" + $(this).attr('id') + " input:checked";

    //        if ($(selCheck).length == 1)
    //            $("#" + $(this).attr('id') + " > p").html($("#li" + $(selCheck).attr('value') + $(this).attr('id').replace('divSelectCheck', '') + " > span").html());
    //        else
    //            if ($(selCheck).length > 1)
    //            $("#" + $(this).attr('id') + " > p").html($(selCheck).length.toString() + " Selecionados")
    //        else
    //            $("#" + $(this).attr('id') + " > p").html($("#" + $(this).attr('id') + " > b").html());
    //    });

    $('#titleImvVisu').click(function() {
        $('#centroImvVisu').slideToggle('slow');
        if ($('#imgSetaImvVisu').attr('title') == 'minimizar') {
            $('#imgSetaImvVisu').attr('title', 'maximizar');
            $('#imgSetaImvVisu').attr('alt', 'maximizar');
            $('#imgSetaImvVisu').attr('src', 'IMAGENS/setaAbaixo.png');
        }
        else {
            $('#imgSetaImvVisu').attr('title', 'minimizar');
            $('#imgSetaImvVisu').attr('alt', 'minimizar');
            $('#imgSetaImvVisu').attr('src', 'IMAGENS/setaAcima.png');
        }
    });

    $('#esqImvVisu').click(function() {
        if (pgAtual > 1) {
            $("#fotoImvVisu").animate({ "left": "+=846px" }, "normal");
            pgAtual--;
        }
    });

    $('#dirImvVisu').click(function() {
        if (pgAtual < qtdPaginas) {
            $("#fotoImvVisu").animate({ "left": "-=846px" }, "normal")
            pgAtual++;
        }
    });

    $('#compareImoveis').click(function() {
        var resu = "";
        var qtd = 0;

        $('div[title="selecionar item"]').each(function(index) {
            if (($(this).css("background-color") == "rgb(255,179,179)") || ($(this).css("background-color") == "rgb(255, 179, 179)")) {
                resu += $(this).attr('id').replace("div", "") + "-"
                qtd++;
            }
        });

        if (qtd > 1)
            document.location = "index.asp?pagina=compImoveis&imvs=" + resu;
        else
            alert('Para realizar o comparação de imóveis, selecione no mínimo 2 imóveis!')

    });

    /*********************************/

});

function AbreJanela(url, width, height, nome, scrollbars) {
	var top; var left;
	top = ( (screen.height/2) - (height/1.55) )
	left = ( (screen.width/2) - (width/2) )
	window.open(url, nome,'width='+width+',height='+height+',scrollbars='+scrollbars+',toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}

function navegacao(pag){
	var ind = location.href.indexOf("&pag=");
	var ind2 = location.href.indexOf("#corpo");
	var url;
	
	if(ind2 > -1)
		url = location.href.substring(0,ind2);
	else
		url = location.href;
	
	if(ind > -1)	
		url = url.substring(0,ind);
	else
		url = url;
		
	location.href = url + "&pag=" + pag	+"#corpo"
}

function maiorMenor(ordem){
	var ind = location.href.indexOf("&ordem=");
	var ind2 = location.href.indexOf("#corpo");
	var url;
	
	if(ind2 > -1)	
		url = location.href.substring(0,ind2);
	else
		url = location.href;
	
	if(ind > -1)	
		url = location.href.substring(0,ind);
	else
		url = location.href;
		
	location.href = url + "&ordem=" + ordem	+"#corpo"	
}

function checkMail(mail){
    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)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){ 
                    return true; 
                }
    }else{
        return false;
        }
}

function vEmail(campo){
	if(checkMail(campo.value))
		return true;
	else{
		alert('Email inválido');
		campo.focus();
		return false;	
	}	
}


function vField(campo,msgErro){
	if(campo.value != "")
		return true;
	else{
		alert(msgErro);
		campo.focus();
		return false;	
	}	
}

function PesquisarRef(form, icForm){
	with(form){
		if(vField(txtRef,"Informe o referência"))
			location.href = "index.asp?pagina=busca&ref=" + txtRef.value;			
	}	
	if(icForm)
		return false;
}

function ImovelInserir(idImovel){
	var imovel = new DetalhesImovel();
  	imovel.Inserir('conteudoDetalhes',idImovel);
	imovel.Chat('bancodedados.imb.br/casalitoral/livezilla.php');
}

/*---OBJETOS DE MANIPULACAO VIA AJAX--*/
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function getNewsletter(email_obj, nome_obj)
{
	var email = document.getElementById(email_obj);
	var nome = document.getElementById(nome_obj);
	if ((email.value != "")&&(nome.value != ""))
	{
		if(vEmail(email)){
			xmlHttp=GetXmlHttpObject();
			xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
						{
							alert(xmlHttp.responseText);
							email.value = "Email";
							nome.value = "Nome";
						}
				}
			url = "insere_exclui_newsletter.asp?email="+email.value+"&acao=inclui&nome="+nome.value;
		
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}
	else
	{
		alert('Informe o seu nome e seu email!');
		nome.focus();
	}
}

function solicitarLigacao(){
	var flag=true;
	if(($('#v_nome_tel').val() == "")||($('#v_nome_tel').val() == "Insira seu nome")){
		alert('Informe seu nome');
		$('#v_nome_tel').focus();
		flag = false;	
	}
	
	if(flag)
		if(($('#v_tel_ligamos').val() == "")||($('#v_tel_ligamos').val() == "Insira seu telefone")){
			alert('Informe seu telefone');
			$('#v_tel_ligamos').focus();
			flag = false;	
		}
	
	if(flag){
		var dados = "v_nome_tel=" + $('#v_nome_tel').val()+"&" + "v_tel=" + $('#v_tel_ligamos').val();

		$.ajax({
			   type: "POST",
			   url: "ligamos_enviar.asp",
			   data: dados,
			   success: function(msg){
					if(msg==""){
						alert('Solicitação de ligação realizada com sucesso');
						$('#v_nome_tel').val('Insira seu nome');	
						$('#v_tel_ligamos').val('Insira seu telefone');
					}
					else
						alert('Erro indefinido ao solicitar telefonema, favor entrar em contato através de nossa página de contato');   
			   }
		});	
	}		
}

var menuSelected, conteudoMenu; 

function createSubMenu(menu, cM){
	cMenu = document.getElementById(cM);
	
	if (menuSelected != undefined){
		menuSelected.style.height = "18px";
		conteudoMenu.style.visibility = "hidden";
	}
	
	cMenu.style.visibility = "visible";
	menu.style.height = "85px";
	menuSelected = menu;
	conteudoMenu = cMenu;
}

function tiraMenu(){
	if (menuSelected != undefined){
		menuSelected.style.height = "18px";
		conteudoMenu.style.visibility = "hidden";
	}		
}

function clicaLimpa(obj){
	document.getElementById(obj).value = "";
}

function restauraTexto(obj,texto){
	if(document.getElementById(obj).value == ""){
		document.getElementById(obj).value = texto;
	}
}

/*---COMPARACAO DE IMOVEIS----------------------*/
function overComp(obj){
	var cor = obj.style.backgroundColor;

	if((cor == "")||(cor=="rgb(240, 240, 240)")||(cor=="rgb(240,240,240)"))
		obj.style.backgroundColor = "rgb(228, 228, 249)";
	else
		if((cor == "rgb(228, 228, 249)")||(cor == "rgb(228,228,249)"))
			obj.style.backgroundColor = "rgb(240, 240, 240)";
}

function clickComp(obj){
	var cor = obj.style.backgroundColor;
	if((cor == "rgb(228, 228, 249)")||(cor == "rgb(228,228,249)"))		
		obj.style.backgroundColor = "rgb(255,179,179)";
	else
		obj.style.backgroundColor = "rgb(228, 228, 249)";	
}
