// SCRIPTS GERAIS

//======================================================================================================================================//
//AJAX

// Retorna o HttpRequest que deve ser acionado

function GetXmlHttpObject() {
	
	var objXMLHttp = null;
	
	if (window.XMLHttpRequest) { objXMLHttp = new XMLHttpRequest() }
	else if (window.ActiveXObject) { objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP") }
	
	return objXMLHttp;

}

// Busca informações no servidor

function findInfo(engine, parametros) {
	
	//objeto xmlHttp
	xmlHttp = GetXmlHttpObject();
	
	//url no servidor
	var url = "ajax" + engine + ".php"
	if(typeof parametros != "undefined") { url += "?" + parametros; }

	//acionar ajax
	xmlHttp.onreadystatechange = eval("show" + engine)
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)

}

//======================================================================================================================================//
// RETORNAR QUERYSTRING

function getQuery() {
	
	//valores querystring
	this.queryText = window.location.search.replace("?","");
	var queryArray = this.queryText.split("&");
	
	//para cada valor
	for (var i = 0; i < queryArray.length; i++) {
		if(queryArray[i]) {
			var inQuery = queryArray[i].split("=");
			eval("this." + inQuery[0] + " = '" + inQuery[1] + "'");
		}
	}
		
}

// Retorno Faixas de imovel
function showGetFaixas() {
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
      var alvo = document.getElementById('faixa_valor_id');
		if(xmlHttp.responseText != 0) {
			var dupla = xmlHttp.responseText.split('!!!');
			var id = dupla[0].split('||');
			var label = dupla[1].split('||');
			
			// Limpa o alvo
			alvo.innerHTML = '';
			for(var i=0; i<id.length; i++) {
				var opt = document.createElement('option');
				var txt = document.createTextNode(label[i]);
				opt.setAttribute('value', id[i]);
				opt.appendChild(txt);
				alvo.appendChild(opt);
			}
		}
   }
}
