/*  
ABRIR NOVA JANELA (POP UP)
*/
function novajanela(endereco,w,h) {
	if(screen.width){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}else{winl = 0;wint =0;}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += 'toolbar=no,location=no,status=no,scrollbars=no,resizable=no';
	win = window.open(endereco,'sub100windows',settings);
}

/*  
ABRIR NOVA JANELA (POP UP) COM BARRA DE ROLAGEM
*/
function novajanelarolagem(endereco,w,h) {
	if(screen.width){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}else{winl = 0;wint =0;}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += 'toolbar=no,location=no,status=no,scrollbars=yes,resizable=no';
	win = window.open(endereco,'sub100windowsroll',settings);
}

/*  
ABRIR NOVA JANELA EM TELA CHEIA
*/
function telacheia(endereco){
	var w = screen.width;
	var h = screen.height;  
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=0,';
	settings += 'left=0,';
	settings += 'toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes';
	win = window.open(endereco, 'sub100windowsfull', settings);
}

/*
FUNÇAO QUE VALIDA ACEITA APENAS NUMEROS NOS FORMULÁRIOS
Como usar: onKeyPress="return soNumero(this, event)"
*/
function isNum( caractere ){
	var strValidos = "0123456789"
	
	if ( strValidos.indexOf( caractere ) == -1 ){
		return false;
	}	
	return true;
}

function soNumero(campo, event){
	var key;
	var tecla;
	
	var teclasPermitidas = new Array(8,9,0);
	
	CheckTAB=true;
	
	if(navigator.appName.indexOf("Netscape")!= -1)
	tecla= event.which;
	else
	tecla= event.keyCode;
	
	key = String.fromCharCode( tecla);
	
	if ( tecla == 13 )
	return false;
	
	var i;
	
	for(i=0;i<teclasPermitidas.length;i++)
	if (tecla == teclasPermitidas[i])
	return true;
	
	return (isNum(key));
}


/*
FUNÇAO QUE HABILITA A NAVEGACAO DE LIGHTBOX QUANDO CARREGADA POR XAJAX
*/
function GroupDelegate(id) {
	var objLink = document.getElementById(id);
	Lightbox.prototype.start(objLink);
}


/*
FUNÇÃO PARA REDIRECIONAR LINKS DE ANÚNCIOS
*/
function PublicidadeClique(url,anuncio, canal, origem){
	window.open(url+'publicidade.php?id='+anuncio+'&idcanal='+canal+'&origem='+origem, "_blank");
}


/* 
FUNÇÃO QUE FORMATA VALOR EM REAIS 
*/
function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	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 retiraAcento(palavra) {
	
	palavra = palavra.replace(" ", "-");
	palavra = palavra.replace("&", "e");
	
	com_acento = 'ãááàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇàèìòùâêîôûäëïöüáéíóúãõÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÁÉÍÓÚÃÕãã ';
	sem_acento = 'aaaaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUCaeiouaeiouaeiouaeiouaoAEIOUAEIOUAEIOUAEIOUAOaa-';
	nova = '';
	
	for(i=0; i < palavra.length; i++) {
		if (com_acento.search(palavra.substr(i,1))>=0) {
			nova += sem_acento.substr(com_acento.search(palavra.substr(i,1)),1);
		} else {
			nova += palavra.substr(i,1);
		}
	}
	
	return nova;
	
}


function Formata(campo,tammax,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal
	
	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 <= dec )
		{ campo.value = vr ; }
		
		if ( (tam > dec) && (tam <= 5) ){
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, 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 - dec, 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 - dec, 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 ) ;}
	} 

}
/*  
TROCA PALAVRA QUANDO O TIPO É RURAL
*/
function tipoRural(tipo){
	if(tipo == 'RURAIS' || tipo == 'CHÁCARAS' || tipo == 'FAZENDAS' || tipo == 'CHÁCARAS EM ÁREA LAZER' || tipo == 'CHÁCARAS EM CONDOMÍNIO' || tipo == 'SÍTIOS' || tipo == 'FAZENDAS' || tipo == 'HARAS'){
		$('#b_cidade option:eq(0)').text('TODAS');
		$('#b_cidade option:eq(0)').val('0');
	}else{
		$('#b_cidade option:eq(0)').text('SELECIONE');
		$('#b_cidade option:eq(0)').val('');
	}
}

//http://www.featureblend.com/license.txt
var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};}
return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i<len;i++){if(properties[i]>=arguments[i]){if(i+1<len&&properties[i]==arguments[i]){continue;}else{return true;}}else{return false;}}};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(!obj.activeXError){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.JS_RELEASE="1.0.4";

function PublicidadeSWFIMG(url, largura, altura, arquivo, id, getcanal, origem, extensao) { if(FlashDetect.installed && extensao == 'swf'){ document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+largura+'" height="'+altura+'"><param name="movie" value="'+url+"publicidade/"+arquivo+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /><param name="FlashVars" value="urlsite='+url+'&anuncio='+id+'&canal='+getcanal+'&origem='+origem+'" /><embed src="'+url+'publicidade/'+arquivo+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'" FlashVars="urlsite='+url+'&anuncio='+id+'&canal='+getcanal+'&origem='+origem+'" wmode="transparent"></embed></object>'); }else{ var novoarquivo = arquivo.replace(".swf", ".jpg"); document.write('<a onClick=\'PublicidadeClique("'+url+'","'+id+'","'+getcanal+'","'+origem+'")\' href="javascript:;"><img src="'+url+'publicidade/'+novoarquivo+'" width="'+largura+'" height="'+altura+'" border="0" /></a>'); }}
