$(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());		
	});
	
	/*********************************/
	
});

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/pordosol/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;
	}
}
