	function formataNum(){
		// retorna o valor das caixas
		var valor1 = $("#min").val();
		var valor2 = $("#max").val();
		// atribui os pontos e virgulas aos valores
		document.getElementById('min').value = FormatNumber(valor1,1,3);
		document.getElementById('max').value = FormatNumber(valor2,1,3);
		// passa os valores correctos
		document.getElementById('min2').value = valor1;
		document.getElementById('max2').value = valor2;
	}

function mudaFundo(id){
	document.getElementById(id).style.backgroundColor = "#666";
}

$(document).ready(function(){				   
	
	countFavourites();			   
	   
	$("#twn_id").change(function(){
		$('#ngh_id').empty();
		$('#ngh_id').html('<option value="">loading...</option>');
		$.get('includes/twnBox.htm?twn='+$(this).val(), function(dados){
			$('#ngh_id').html('<option value="">('+tradQualq+')</option>').append((dados));
			return true;
		});
	});
	$("#ngh_id").change(function(){
		$('#zon_id').empty();
		$('#zon_id').html('<option value="">loading...</option>');
		$.get('includes/nghBox.htm?ngh='+$(this).val(), function(dados){
			$('#zon_id').html('<option value="">('+tradQualq+')</option>').append((dados));
			return true;
		});
	});
	
	
	$("#twnHp_id").change(function(){
		$('#zonHp_id').empty();
		$('#zonHp_id').html('<option value="">loading...</option>');
		$.get('includes/nghBox.htm?twn='+$(this).val(), function(dados){
			$('#zonHp_id').html('<option value="">('+tradQualq+')</option>').append((dados));
			return true;
		});
	});
	$("#twn2_id").change(function(){
		$('#zon2_id').empty();
		$('#zon2_id').html('<option value="">loading...</option>');
		$.get('../includes/nghBox.htm?twn='+$(this).val(), function(dados){
			$('#zon2_id').html('<option value="">('+tradQualq+')</option>').append((dados));
			return true;
		});
	});
	
	
});



/* slideshow */
function slideSwitch() {
    var $active = $('#slideshow img.active');

	$active.addClass('last-active');

	// verifica se existe um próximo objeto na div #slideshow, caso ele nao exista, retorna para o primeiro
    var $next =  $active.next().length ? $active.next() : $('#slideshow img:first');

	// Codigo que define as transicoes entre as imagens
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
	//Executa a função a cada 5 segundos
	setInterval( "slideSwitch()", 10000 );
});

// JavaScript Document
Cufon.replace('h5, h6', { fontFamily: 'ArialT' });
Cufon.replace('.tit', { hover: 'true' });
Cufon.replace('span.tit', {
fontFamily: 'ArialT',
textShadow: '#535353 1px 1px'
});
/*Cufon.replace('#pesqAvz a, #pesqAvz a:hover', {
fontFamily: 'Francois',
textShadow: '#FFF 1px 1px'
});*/
Cufon.replace('.nat-typ, span.elemento div, .desde, .bc_1, .bc_3', {
fontFamily: 'Francois',
textShadow: '#535353 1px 1px'
});
Cufon.replace('.nr, h3, .zona, span.elemento div span ', { fontFamily: 'Francois' });



/* preloader fotos 
		$(function () {
			$('#foto_1').hide();//hide all the images on the page
		});
		
		var i = 0;//initialize
		var int=0;//Internet Explorer Fix
		$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
			var int = setInterval("doThis(i)",500);//500 is the fade in speed in milliseconds
		});
 
		function doThis() {
			var imgs = $('#foto_1').length;//count the number of images on the page
			if (i >= imgs) {// Loop the images
				clearInterval(int);//When it reaches the last image the loop ends
			}
			$('#foto_1:hidden').eq(0).fadeIn(500);//fades in the hidden images one by one
			i++;//add 1 to the count
		}

*/

/* fazer scroll na pagina */
function goToByScroll(id){
		$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}


/* mostrar e esconder caixas */
function mostraCaixa(caixa){	
		if(caixa == "conocernos"){
			document.getElementById(caixa).style.display = "block";
			document.getElementById('inmuebles').style.display = "none";
			document.getElementById('servicios').style.display = "none";
			$(".submenu").fadeTo("fast", 1);
			$(".submenu2").fadeTo("fast", 0.1);
			$(".submenu3").fadeTo("fast", 0.1);
		} 
		else if(caixa == "inmuebles"){
			$(".submenu2").fadeTo("fast", 1);
			$(".submenu").fadeTo("fast", 0.1);
			$(".submenu3").fadeTo("fast", 0.1);
			document.getElementById(caixa).style.display = "block";
			document.getElementById('conocernos').style.display = "none";
			document.getElementById('servicios').style.display = "none";
			
		} else if(caixa == "servicios"){
			$(".submenu2").fadeTo("fast", 0.1);
			$(".submenu").fadeTo("fast", 0.1);
			$(".submenu3").fadeTo("fast", 1);
			document.getElementById(caixa).style.display = "block";
			document.getElementById('conocernos').style.display = "none";
			document.getElementById('inmuebles').style.display = "none";
		} else if(caixa == "esconder"){
			$(".submenu2").fadeTo("fast", 0.1);
			$(".submenu").fadeTo("fast", 0.1);
			$(".submenu3").fadeTo("fast", 0.1);
			document.getElementById('servicios').style.display = "none";
			document.getElementById('conocernos').style.display = "none";
			document.getElementById('inmuebles').style.display = "none";
		}
}
/* FAVORITOS detalhes */
function adFavorito(divID,estado){
	if(estado == "over"){
		alert("está over");
		document.getElementById(divID).style.backgroundImage = "../images/fundobotoesON.gif";
		//estado = "out";
	} else if(estado == "out"){
		alert("está out");
		document.getElementById(divID).style.backgroundImage = "../images/fundobotoes.gif";
		//estado = "over";
	}
}


/* menu COMERCIALIZAR (escolher por label) */
function selectrd(id)
{
	var opt=(id==1)?"yes":"no";
	var tg=document.getElementById("rd" + opt);
	tg.checked=true;
}


/* mapa CONTACTOS */
function mostraMapa(estado,loja){
	if(estado == "abrir"){
		document.getElementById('fundocor').style.display = "block";
		document.getElementById('fecharCaixa').style.display = "block";
		document.getElementById('localCaixa').style.display = "block";
		/*document.getElementById('centro2').style.zIndex = -1;
		document.getElementById('ref').style.zIndex = -1;
		document.getElementById('inipesq').style.zIndex = -1;*/
		$('#centro2').css({"z-index":-1});
		$('#ref').css({"visibility":"hidden"});
		$('.enviarPesqR').css({"z-index":-1});
		if(loja == 1){
			agencia = 1;
		} else if(loja == 2){
			agencia = 2;
		}
		
	} else if(estado == "fechar"){
		document.getElementById('fundocor').style.display = "none";
		document.getElementById('fecharCaixa').style.display = "none";
		document.getElementById('localCaixa').style.display = "none";
		$('#centro2').css({"z-index":0});
		$('#ref').css({"visibility":"visible"});
		$('.enviarPesqR').css({"z-index":0});
	}	
}

function analisaCx(accao, id, valor){
	//alert('teste');
	if(accao == "esvazia" && document.getElementById(id).value == valor){
		document.getElementById(id).value = "";
	} else if(accao == "preenche" && document.getElementById(id).value == ""){
		document.getElementById(id).value = valor;
	}
}
function repoeCx(id, valor){
	//return false;
	 if(document.getElementById(id).value == valor){
		//alert("passa por aqui");
		document.getElementById(id).value = "";
	}
	return true;
}

function abrirCaixas(caixa,estado){
	
		if(estado == "on"){
			document.getElementById(caixa).style.display = "block";
		} 
		else if(estado == "off"){
			document.getElementById(caixa).style.display = "none";
		}
}
/* referencia pesquisa rapida */

function caract(estado){
	
		if(estado == "on"){
			document.getElementById('caracteristicas').style.display = "block";
		} 
		else if(estado == "off"){
			document.getElementById('caracteristicas').style.display = "none";
		}
}

function showFeat(divId,btID){
	if(
			document.getElementById(divId).style.display == "none")
		{
			document.getElementById(divId).style.display = "block";
			document.getElementById(btID).src="../images/det_menos.gif";
		} else{
			document.getElementById(divId).style.display = "none";
			document.getElementById(btID).src="../images/det_mais.gif";
		}
}


/* carregar flashes */
	function carregaFlash(destino,url,largura,altura){
    $(destino).flash(
        { src: url,
          width: largura,
          height: altura },
        { version: 8 }
    );
	}

 function GetDecimalDelimiter(countryCode)
{
 
  switch (countryCode)
  {
    case 3:   
           return '#';
    case 2:   
           return '.';
    default:
           return '.';
  }
}

function GetCommaDelimiter(countryCode)
{
 
  switch (countryCode)
  { 
    case 3:          
           return '*';
    case 2:   
           return '.';
    default:
           return '.';
  }
 
}

function FormatClean(num)
{
     var sVal='';
     var nVal = num.length;
     var sChar='';
     
   try
   {
      for(c=0;c<nVal;c++)
      {
         sChar = num.charAt(c);
         nChar = sChar.charCodeAt(0);
         if ((nChar >=48) && (nChar <=57))  { sVal += num.charAt(c);   }
      }
   }
    catch (exception) { AlertError("Format Clean",exception); }
    return sVal;
}
  

function FormatNumber(num,countryCode,decimalPlaces)
{       

  var minus='';
  var comma='';
  var dec='';
  var preDecimal='';
  var postDecimal='';
  
  try 
  {
   
    decimalPlaces = parseInt(decimalPlaces);
    comma = GetCommaDelimiter(countryCode);
    dec = GetDecimalDelimiter(countryCode);
    
    if (decimalPlaces < 1) { dec = ''; }
    if (num.lastIndexOf("-") == 0) { minus='-'; }
   
    preDecimal = FormatClean(num);
    
    // preDecimal doesn't contain a number at all.
    // Return formatted zero representation.
    
    if (preDecimal.length < 1)
    {
       return minus + FormatEmptyNumber(dec,decimalPlaces);
    }
    
    // preDecimal is 0 or a series of 0's.
    // Return formatted zero representation.
    
    if (parseInt(preDecimal) < 1)
    {
       return minus + FormatEmptyNumber(dec,decimalPlaces);
    }
    
    // predecimal has no numbers to the left.
    // Return formatted zero representation.
    
    if (preDecimal.length == decimalPlaces)
    {
      return minus + '0' + dec + preDecimal;
    }
    
    // predecimal has fewer characters than the
    // specified number of decimal places.
    // Return formatted leading zero representation.
    
    if (preDecimal.length < decimalPlaces)
    {
       if (decimalPlaces == 2)
       {
        return minus + FormatEmptyNumber(dec,decimalPlaces - 1) + preDecimal;
       }
       return minus + FormatEmptyNumber(dec,decimalPlaces - 2) + preDecimal;
    }
    
    // predecimal contains enough characters to
    // qualify to need decimal points rendered.
    // Parse out the pre and post decimal values
    // for future formatting.
    
    if (preDecimal.length > decimalPlaces)
    {
      postDecimal = dec + preDecimal.substring(preDecimal.length - decimalPlaces,
                                               preDecimal.length);
      preDecimal = preDecimal.substring(0,preDecimal.length - decimalPlaces);
    }

    // Place comma oriented delimiter every 3 characters
    // against the numeric represenation of the "left" side
    // of the decimal representation.  When finished, return
    // both the left side comma formatted value together with
    // the right side decimal formatted value.
    
    var regex  = new RegExp('(-?[0-9]+)([0-9]{3})');
 
    while(regex.test(preDecimal))
    {
       preDecimal = preDecimal.replace(regex, '$1' + comma + '$2');
    }
       
  }
  catch (exception) { AlertError("Format Number",exception); }
  return minus + preDecimal + postDecimal;
}

function FormatEmptyNumber(decimalDelimiter,decimalPlaces)
{
    var preDecimal = '0';
    var postDecimal = '';
 
    for(i=0;i<decimalPlaces;i++)
    {
      if (i==0) { postDecimal += decimalDelimiter; }
      postDecimal += '0';
    }
   return preDecimal + postDecimal;
}
  

 function AlertError(methodName,e)
 {
            if (e.description == null) { alert(methodName + " Exception: " + e.message); }
            else {  alert(methodName + " Exception: " + e.description); }
 }
