// pop depomibilidade
function popjanelas(url,destino,w,h){
 	window.open(url,destino,'width='+w+' height='+h)
}

function popdisponibilidade(url,destino,w,h){
 	window.open(url,destino,'width='+w+' height='+h)
}


// Mascara de campos campos
function formatar(src, mask) { 
	var tipoCampo = ''; 
	if (mask == 'cpf') { 
		mask = '###.###.###-##'; 
		tipoCampo = 'cpf'; 
	} else if ( mask == 'cnpj') { 
		mask = '##.###.###/####-##'; 
		tipoCampo = 'cnpj'; 
	} else if ( mask == 'cep') { 
		mask = '#####-###'; 
		tipoCampo = 'cep'; 
	} else if (mask == 'data') { 
		mask = '##/##/####'; 
		tipoCampo = 'data'; 
	} else if (mask == 'tel'){
		mask = '##.####-####'; 
	}
	var i = src.value.length; 
	var saida = mask.substring(0,1); 
	var texto = mask.substring(i) 
	if (texto.substring(0,1) != saida) { 
		src.value += texto.substring(0,1); 
	} 
} 
		
// formata cpf
function FormataCPF( el )  
{  
    vr = el.value;  
    tam = vr.length;  

    if ( vr.indexOf(".") == -1 )  
    {  
        if ( tam <= 3 )  
            el.value = vr;  

        if ( (tam > 3) && (tam <= 7) )  
            el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 4, tam );  

        if ( (tam >= 8) && (tam <= 11) )  
            el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 5, 3 ) + '-';  

        if ( (tam >= 11) && (tam <= 18) )  
            el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 2 );  
    } 

    return true;  

} 

		
// Formata Campos Númericos
function Limpar(valor, validos) {
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}
	
function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	if (tecla == 8 ){ tam = tam - 1 ; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
			campo.value = vr ;
		}
		if ( (tam > 2) && (tam <= 5) ){
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - 2, tam ) ; 
		}
		if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ; 
		}
		if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;
		}
		if ( (tam >= 12) && (tam <= 14) ){
			campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ; 
		}
		if ( (tam >= 15) && (tam <= 17) ){
			campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;
		}
	} 
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,"");
	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));
	return (num + "," + cents);
}



// troca cor do frames

	var highlightcolor="#ffffcc"
	var ns6=document.getElementById&&!document.all
	var previous=''
	var eventobj

	var intended=/INPUT|TEXTAREA|SELECT|OPTION/

	function checkel(which){
		if (which.style&&intended.test(which.tagName)){
			if (ns6&&eventobj.nodeType==3)
				eventobj=eventobj.parentNode.parentNode
				return true
			}
		else
		return false
	}

	function highlight(e){
		eventobj=ns6? e.target : event.srcElement
		if (previous!=''){
			if (checkel(previous))
				previous.style.backgroundColor=''
				previous=eventobj
				if (checkel(eventobj))
					eventobj.style.backgroundColor=highlightcolor
				} else {
					if (checkel(eventobj))
						eventobj.style.backgroundColor=highlightcolor
						previous=eventobj
			}
	}  

	//  msg de help
	function msghelp(msg){
		document.getElementById('help').innerHTML  = msg;
	}	

	
	function trocaCor(idAlvo,idCor){
		document.getElementById(idAlvo).style.background = idCor;
		document.getElementById(idAlvo).style.cursor = 'hand';
	
	}
	
	function getPosicaoElemento(elemID){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}

	
	function ShowHideImo(Cod_a, Aca_a, Cod_b, Aca_b, Cod_c, Aca_c){
	
		document.getElementById(Cod_a).style.visibility=Aca_a;
		document.getElementById(Cod_b).style.visibility=Aca_b;
		document.getElementById(Cod_c).style.visibility=Aca_c;
		
		
		document.getElementById(Cod_b).style.left = getPosicaoElemento(Cod_a).left
		document.getElementById(Cod_c).style.left = getPosicaoElemento(Cod_a).left
	
	
	}
	
	function dispesquisa(varTipoPes, varAlvo, varCampo, varTipoImo){
	
		if(varAlvo == 'nd'){
			alert('Selecione uma Opção!');
		} else {
			location.href = '../imo_pesquisa.php?idPesquisa='+varTipoPes+'&idCmp='+varCampo+'&idAvl='+varAlvo+'&idTipo='+varTipoImo
		}
	}

function agregar(){
   if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
      var url="http://www.imobiliariaabs.com.br/";
      var titulo="Imobiliária ABS - São Pedro - SP";
      window.external.AddFavorite(url,titulo);
   }
   else {
      if(navigator.appName == "Netscape")
         alert ("Pressione Crtl+D para agregar o site da Imobiliária ABS em seus Bookmarks");
   }
}
/* Alimentar select da pesquisa */

function carregaCidade(varTipoImovel){
	$('CidaImovel').innerHTML = ""
	$('CidaImovel').innerHTML =  "Localizando..."
	var urlCidade = 'pg_pesquisa_imoveis.php';
	var dadCidade = 'rand='+Math.ceil( Math.random() * 100000 );
	dadCidade += '&idAcao=lstCidade';
	dadCidade += '&idTipo='+varTipoImovel;
	var tarCidade = 'CidaImovel';
	var disCidade = new Ajax.Updater(tarCidade,urlCidade,{method:'post',evalScript:true,parameters:dadCidade,onComplete:function(){
		contarImoveis();
	}})
}

function carregaValor(){

	$('ValoImovel').innerHTML = ""
	$('ValoImovel').innerHTML =  "Localizando..."
	var urlValor= 'pg_pesquisa_imoveis.php';
	var dadValor = 'rand='+Math.ceil( Math.random() * 100000 );
	dadValor += '&idAcao=valor';
	dadValor += '&idTipo='+$F('lstTipo');
	dadValor += '&idCida='+$F('lstCidade');
	var tarValor = 'ValoImovel';
	var disValor = new Ajax.Updater(tarValor,urlValor,{method:'post',evalScript:true,parameters:dadValor,onComplete:function(){
		contarImoveis();
	}})

}

function contarImoveis(){
	$('total').innerHTML = ""
	$('total').innerHTML =  "Calculando..."
	var urlCidade = 'pg_pesquisa_imoveis.php';
	var dadCidade = 'rand='+Math.ceil( Math.random() * 100000 );
	dadCidade += '&idAcao=Calcula';
	dadCidade += '&idTipo='+$F('lstTipo');
	dadCidade += '&idCida='+$F('lstCidade');
	dadCidade += '&idvalor='+$F('lstValor');
	var tarCidade = 'total';
	var disCidade = new Ajax.Updater(tarCidade,urlCidade,{method:'post',evalScript:true,parameters:dadCidade,onComplete:function(){
		
	}})
}