//abre o menu flutuante
function menu_flutuante(id,estado)
{
	var id_menu="menu_"+id;
	var id_menu_principal="flutuante_"+id;
	if(estado==1)
	{
		document.getElementById(id_menu).style.display="block";
		document.getElementById(id_menu_principal).className="item_menu_principal_ativo";
	}else
		{
			document.getElementById(id_menu).style.display="none";
			document.getElementById(id_menu_principal).className="item_menu_principal";
		}
}

//abrir layer do simulador do financiamento
function abre_financiamento(estado)
{
	if(estado==1)
		document.getElementById("financiamento").style.display="block";
	else
		document.getElementById("financiamento").style.display="none";
}

//limpa campo
function limpa_campo(id)
{
	var valor_default=document.getElementById(id).title;
	var valor_atual=document.getElementById(id).value;
	if(valor_atual == valor_default)
		document.getElementById(id).value="";
	else
		{
			if(valor_atual =="")
				document.getElementById(id).value=valor_default;
		}
}

//adiciona aos favoritos
function addFav(){
    var url      = "http://192.168.24.112/phator";
    var title    = "Phator Imoveis";
    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 pesquisa_avancada(estado)
{
	if(estado==1)
	{
		document.getElementById("pesquisa_avancada").style.display="block";
		document.getElementById("botao_pesquisar").style.display="none";
		document.getElementById("link_pesquisa_avancada").style.display="none";
	}else
		{
			document.getElementById("pesquisa_avancada").style.display="none";
			document.getElementById("botao_pesquisar").style.display="block";
			document.getElementById("link_pesquisa_avancada").style.display="block";
		}
}

function numero_real(num)
{	
   x = 0;

   if(num<0){
	  num = Math.abs(num);
	  x = 1;
   }

   if(isNaN(num)) num = "0";
	  cents = Math.floor((num*100+0.5)%100);

   num = Math.floor((num*100+0.5)/100).toString();

   if(cents < 10) cents = "0" + cents;
	  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		 num = num.substring(0,num.length-(4*i+3))+'.'
			   +num.substring(num.length-(4*i+3));

   ret = num + ',' + cents;

   if (x == 1) ret = ' - ' + ret;
   
   /*arredondar = Math.round(ret*Math.pow(10,2))/Math.pow(10,2);	  
   alert(arredondar);   
   return arredondar;*/
   
   return ret;
}

/*######################### FADE IN & FADE OUT*/
function fadeOut(id, time) {
	target = document.getElementById(id);
	alpha = 100;
	timer = (time*1000)/50;
	var i = setInterval(
			function() {
				if (alpha <= 0)
					clearInterval(i);
				setAlpha(target, alpha);
				alpha -= 2;
			}, timer);
}

function fadeIn(id, time) {
	target = document.getElementById(id);
	alpha = 0;
	timer = (time*1000)/50;
	var i = setInterval(
			function() {
				if (alpha >= 100)
					clearInterval(i);
				setAlpha(target, alpha);
				alpha += 2;
			}, timer);
}

function setAlpha(target, alpha) {
	target.style.filter = "alpha(opacity="+ alpha +")";
	target.style.opacity = alpha/100;
}
/*##########################*/

function altera_imagem(img,titulo){
	fadeOut('portfolio_imagem', 0.1);
	document.getElementById('portfolio_imagem').style.backgroundImage="url("+img+")";
	document.getElementById('portfolio_imagem').alt=titulo;
	fadeIn('portfolio_imagem', 0.1);
}
