function envia_busca(){
	f = document.buscar;
	f.submit();
}
//--------------------------------------------------------------------------------------------//
function carrega_cep() {
	
	f = document.form_novo;
	if(f.cep.value == ''){
		alert("Preencha o CEP antes de pesquisar.");
		f.cep.focus();
	}else{
		ajax = inicia();
		if(ajax) {
			ajax.open('post','paginas/cep.php?',true);
			ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			var parametros = 'cep='+f.cep.value;
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					if(ajax.status == 200) {
						//alert(ajax.responseText);
						var valores = ajax.responseText.split("+");
											
						f.cep.value  		= valores[0];
						f.cidade.value  	= valores[1];
						f.estado.value  	= valores[2];
						f.endereco.value  	= valores[3];
						f.bairro.value  	= valores[4];
						f.numero.focus();
					}
				}
			}
		}
		ajax.send(parametros);
	}
}
//--------------------------------------------------------------------------------------------//
function CrossEvent(evt) {
	evt = evt?evt:(window.event?window.event:null);
	if(evt) {
		this.originalEvent = evt;
		this.type = evt.type;
		//--posição do mouse
		//this.screenX = evt.screenX;
		//this.screenY = evt.screenY;
		// IE: srcElement
		this.target = evt.target?evt.target:evt.srcElement;
		// N4: modifiers
		if (evt.modifiers) {
			this.altKey   = evt.modifiers & Event.ALT_MASK;
			this.ctrlKey  = evt.modifiers & Event.CONTROL_MASK;
			this.shiftKey = evt.modifiers & Event.SHIFT_MASK;
			this.metaKey  = evt.modifiers & Event.META_MASK;
		}
		else {
			this.altKey   = evt.altKey;
			this.ctrlKey  = evt.ctrlKey;
			this.shiftKey = evt.shiftKey;
			this.metaKey  = evt.metaKey;
		}
		// N4: which // N6+: charCode
		this.charCode = !isNaN(evt.charCode)?evt.charCode:!isNaN(evt.keyCode)?evt.keyCode:evt.which;
		this.keyCode = !isNaN(evt.keyCode)?evt.keyCode: evt.which;
		this.button = !isNaN(evt.button)?evt.button:!isNaN(evt.which)?evt.which-1:null;
		this.debug = "c:" + evt.charCode + " k:" + evt.keyCode + " b:" + evt.button + " w:" + evt.which;
	}
}
//--funções de validação
function validacao_numeros(objEvent,tipo) {
	var evt = new CrossEvent(objEvent);
	var teclaKey = evt.keyCode;
	var teclaChar = evt.charCode;
	//--CHAR CODE
	//--47 à 58 - números de 0 à 9
	//--44 - vírgula
	//--46 - ponto
	//--KEY CODE
	//--8 - backspace
	//--9 - tab
	//--37 - setinha: esquerda
	//--39 - setinha: direita
	//--46 - delete
	//alert(evt.debug)
	//--------------------------------------
	if(tipo=='inteiro'&&((teclaChar>47&&teclaChar<58)||teclaKey==8||teclaKey==9||teclaKey==37||teclaKey==39||teclaKey==46))
		return true;
	else if(tipo=='decimal'&&((teclaChar>47&&teclaChar<58)||teclaKey==8||teclaKey==9||teclaKey==37||teclaKey==39||teclaKey==46||teclaChar==44))
		return true;
	else if(tipo=='ponto'&&((teclaChar>47&&teclaChar<58)||teclaKey==8||teclaKey==9||teclaKey==37||teclaKey==39||teclaKey==46||teclaChar==46))
		return true;
	else
		return false;
}
//--------------------------------------------------------------------------------------------//
/*pula campo*/
var nextFocus = true;
var frm = null;
var compIndex = -1;
//--------------------------
function getForm( comp ){
	for ( i = 0; i < document.forms.length; i++ ){
		for ( i2 = 0; i2 < document.forms[i].elements.length; i2++ ){
			if ( comp.name == document.forms[i].elements[i2].name ){
				frm = document.forms[i];
				compIndex = i2;
				return;
			}
		}
	}
}
//--------------------------
function gotoNextFocus( source, maxLength ){
	getForm( source );
	if (( !nextFocus ) || ( frm == null ) || ( compIndex == -1 ) ){
		return;
	}
	var ix = compIndex + 1;
	var size = source.value.length;
	var canFocus = false;
	while ( !canFocus ) {
		if ( ( frm.elements[ix].type == "hidden" ) && ( ix < frm.elements.length )){
			ix++;
		}
		else {
			canFocus = true;
		}
	}
	if ( (canFocus) && ( size == maxLength ) ){
	frm.elements[ix].focus();
	}
}
//--------------------------
function offNextFocus(){
	nextFocus = false;
}
//--------------------------
function onNextFocus(){
	nextFocus = true;
}
//----------------------------
function menu() {
	/*--elementos do site--*/
	var topo = document.getElementById('topo').offsetHeight;
	var conteudo = document.getElementById('conteudo').offsetHeight;
	var menu = document.getElementById('menu_lateral').offsetHeight;
	var elem = document.getElementById('menu_lateral');
	/*--faz cálculos--*/
	var a = conteudo;
	var conteudo_topo = topo + conteudo;
	
	//-----------------
	if(conteudo_topo>menu) {
		var d = conteudo_topo-menu;
		var x = d + menu;
		elem.style.height = x + 15 +'px';
		'<img src="imagens/borda_inferior.jpg" title="" alt="" border="0" class="left" />'
	}else{
		'<img src="imagens/borda_inferior.jpg" title="" alt="" border="0" class="left" />'
		//elem.style.height = 550+'px';
	}
}
//--------------------------------------------------------------------------------------------//
function detalhe_imob(URL) {
	window.open('modulos/associadas/detalhes.php?id='+URL,'teste1', 'width=530, height=500, scrollbars=yes');
}
//--------------------------------------------------------------------------------------------//
function mostra_servico(codigo) {
	ajax = inicia();
	if(ajax) {
		var obj = document.getElementById('servicos');
		ajax.onreadystatechange = function(){
			if(ajax.readyState==1)
				obj.innerHTML = 'Carregando...';
			if(ajax.readyState==4) {
				if(ajax.status==200) {
					obj.innerHTML = '';
					obj.innerHTML = ajax.responseText;
				}
			}
		}
		ajax.open('get','modulos/servicosonline/index.php?codigo='+codigo,true);
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.send(null);
	}
}
function validar_busca_pat() {
	if(document.form.tipo.value != ''
	   || document.form.cidade.value != ''
	   || document.form.valor_minimo.value != ''
	   || document.form.valor_maximo.value != ''
	   || document.form.n_quartos.value != ''
	   || document.form.codigo.value != ''
	   || document.form.cidade.value != ''
	   || (document.form.finalidade[0].checked || document.form.finalidade[1].checked)
	   ) 
	{
		var query = '=';
		if(document.form.tipo.value != '')
			query += '&tipo='+document.form.tipo.value;
		if(document.form.cidade.value != '')
			query += '&cidade='+document.form.cidade.value;
		if(document.form.valor_minimo.value != '')
			query += '&valor_minimo='+document.form.valor_minimo.value;
		if(document.form.valor_maximo.value != '')
			query += '&valor_maximo='+document.form.valor_maximo.value;
		if(document.form.n_quartos.value != '')
			query += '&n_quartos='+document.form.n_quartos.value;
		if(document.form.codigo.value != '')
			query += '&codigo='+document.form.codigo.value;
		if(document.form.finalidade[0].checked)
			query += '&finalidade='+document.form.finalidade[0].value;
		if(document.form.finalidade[1].checked)
			query += '&finalidade='+document.form.finalidade[1].value;
		window.location = '?pesquisa/index2,'+query;
	}
	else 
	{
		alert('Por favor preencha pelo menos um campo');
		return false;
	}
}

//----------------------------------------------------------------------------------------//
function url_encode(str) {
	var hex_chars = '0123456789ABCDEF';
	var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
	var n, strCode, hex1, hex2, strEncode = '';  
	for(n = 0; n < str.length; n++) {
		if(noEncode.test(str.charAt(n))) {
			strEncode += str.charAt(n);
		}
		else {
			strCode = str.charCodeAt(n);
			hex1 = hex_chars.charAt(Math.floor(strCode / 16));
			hex2 = hex_chars.charAt(strCode % 16);
			strEncode += '%' + (hex1 + hex2);
		}
	}
	return strEncode;
}
//----------------------------------------------------------------------------------------//
// correção no uso de vírgulas
function trata_dados(campo) {
	var c = 0;
	var temp = campo;
	var t = campo.length;
	for(x=0;x<t;x++) if(campo.substring(x,(x+1))==',') c++;
	for(x=1;x<=c;x++) temp = temp.replace(',','^^');
	temp = url_encode(temp);
	return temp;
}
//----------------------------------------------------------------------------------------//