$(document).ready(function() {
	$('#emailNews').focusin(function(){
		if($(this).attr('value')=='Email'){
			$(this).attr('value','');	
		}	
	});	
	
	$('#emailNews').focusout(function(){
		if($(this).attr('value')==''){
			$(this).attr('value','Email');	
		}		
	});
	
	$('#nomeNews').focusin(function(){
		if($(this).attr('value')=='Nome'){
			$(this).attr('value','');	
		}	
	});	
	
	$('#nomeNews').focusout(function(){
		if($(this).attr('value')==''){
			$(this).attr('value','Nome');	
		}		
	});
	
	$('#v_nome_tel').focusin(function(){
		if($(this).attr('value')=='Insira seu nome'){
			$(this).attr('value','');	
		}	
	});	
	
	$('#v_nome_tel').focusout(function(){
		if($(this).attr('value')==''){
			$(this).attr('value','Insira seu nome');	
		}		
	});
	
	$('#v_tel_ligamos').focusin(function(){
		if($(this).attr('value')=='Insira seu telefone'){
			$(this).attr('value','');	
		}	
	});	
	
	$('#v_tel_ligamos').focusout(function(){
		if($(this).attr('value')==''){
			$(this).attr('value','Insira seu telefone');	
		}		
	});
	
	$('#txtRef').focusin(function(){
		if($(this).attr('value')=='Busca por referência'){
			$(this).attr('value','');	
		}	
	});	
	
	$('#txtRef').focusout(function(){
		if($(this).attr('value')==''){
			$(this).attr('value','Busca por referência');	
		}		
	});
	
	/***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 > 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==""))
			$(check).attr('checked','true');
		else
			$(check).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());		
	});
	
	/*********************************/
	
	/*---PAGINA DE LOCALIZACAO--*/
	$('.lstLocalizacoes span').click(function(){
		var loja = $(this).attr('id');
		var src = "";
		
		switch(loja){
			case "loja2":
				src='http://maps.google.com.br/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=Av.+Pres.+Kennedy,+14070&amp;sll=-24.028735,-46.487273&amp;sspn=0.009486,0.021007&amp;ie=UTF8&amp;hq=&amp;hnear=Av.+Pres.+Kennedy,+14070+-+Cai%C3%A7ara,+Praia+Grande+-+S%C3%A3o+Paulo,+11707-000&amp;ll=-24.051245,-46.539373&amp;spn=0.047027,0.051413&amp;z=14&amp;output=embed';
				break;
			case "loja3":
				src='http://maps.google.com.br/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=Av.+Presidente+Kennedy,+12550&amp;sll=-24.051696,-46.53785&amp;sspn=0.009484,0.021007&amp;ie=UTF8&amp;hq=&amp;hnear=Av.+Pres.+Kennedy,+12550+-+Cai%C3%A7ara,+Praia+Grande+-+S%C3%A3o+Paulo,+11706-000&amp;ll=-24.044936,-46.525083&amp;spn=0.011757,0.012853&amp;z=16&amp;output=embed';
				break;
			case "loja4":
				src='http://maps.google.com.br/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=Av.+Presidente+Kennedy,+7607&amp;sll=-24.045386,-46.52386&amp;sspn=0.009484,0.021007&amp;ie=UTF8&amp;hq=&amp;hnear=Av.+Pres.+Kennedy,+7607+-+Cidade+Ocian,+Praia+Grande+-+S%C3%A3o+Paulo,+11704-100&amp;ll=-24.026632,-46.480408&amp;spn=0.011759,0.012853&amp;z=16&amp;output=embed';
				break;
			case "loja5":
				src='http://maps.google.com.br/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=Av.+Presidente+Kennedy,+14078&amp;sll=-24.026472,-46.481176&amp;sspn=0.009486,0.021007&amp;ie=UTF8&amp;hq=&amp;hnear=Av.+Pres.+Kennedy,+14078+-+Cai%C3%A7ara,+Praia+Grande+-+S%C3%A3o+Paulo,+11707-000&amp;ll=-24.051598,-46.538944&amp;spn=0.011757,0.012853&amp;z=16&amp;output=embed';
				break;
			case "loja6":
				src='http://maps.google.com.br/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=Av.+Presidente+Castelo+Branco,+7242+-+Cidade+Ocian+-+Praia+Grande&amp;aq=&amp;sll=-24.027597,-46.46912&amp;sspn=0.00633,0.008272&amp;ie=UTF8&amp;hq=&amp;hnear=Av.+Pres.+Castelo+Branco,+7242+-+Cidade+Ocian,+Praia+Grande+-+S%C3%A3o+Paulo,+11704-600&amp;ll=-24.027073,-46.468949&amp;spn=0.00588,0.006427&amp;z=17&amp;iwloc=A&amp;output=embed';
				break;
			default:
				src='http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=Rua+Dr.+Jo%C3%A3o+Sampaio,+119+Jd.+Guilhermina&amp;sll=37.0625,-95.677068&amp;sspn=33.710275,86.044922&amp;ie=UTF8&amp;hq=Rua+Dr.+Jo%C3%A3o+Sampaio,+119+Jd.+Guilhermina&amp;hnear=&amp;radius=15000&amp;ll=-24.012912,-46.424596&amp;spn=0.01176,0.012853&amp;z=16&amp;output=embed';	
				break;
		}
		
		$('.lojaAtual').html(loja.replace('loja','Loja 0'));
		$('#containerLocalizacao').html('<iframe width="755" height="558" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+src+'"></iframe>');
			
	});	
	
});

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 url;
	
	if(ind > -1)	
		url = location.href.substring(0,ind);
	else
		url = location.href;
		
	location.href = url + "&pag=" + pag		
}

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('videostreaming.com.br/vidanovaimoveis/livezilla.php');
	imovel.DominioArquivos('imobiliariapraiagrande.com.br');
}

/*---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');   
			   }
		});	
	}		
}
