function testAjax()
{
	try {
	 return new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				return new XMLHttpRequest();
			}
			catch(exc) {
			   alert("Esse browser não tem recursos para uso do Ajax");
			   return null;
			}
		}
	}
}

function imovelAjax(codigo,opcao,combo,resultado,form) {
	   
	if(ajax = testAjax()) {
	 
		ajax.open("POST", "../../modulos/imoveis/portifolio.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		ajax.onreadystatechange = function() {
		
			if(ajax.readyState == 1){
				switch(opcao){
					//case '0':document.getElementById(combo).innerHTML		= "Carregando..."; break;
					case '1':document.getElementById(resultado).innerHTML	= "Carregando..."; break;
				}
			}
			
			if(ajax.readyState == 4 ){
				switch(opcao){
					
					case '0':preenchCombo(form,combo,ajax.responseText,resultado);	break;
					case '1':document.getElementById(resultado).innerHTML	= unescape(ajax.responseText.replace(/\+/g," "));break;
						
				}
			}
			
		}
		
		var params = "codigo="+codigo+"&modo=1&opcao="+opcao; 
		ajax.send(params);
		
	}
		
	 
}

function preenchCombo(nomeForm,nomeCombo,texto,resultado){
						
	var componente = document.forms[nomeForm].elements[nomeCombo];
	
	componente.options.length = 0; 

	if(texto != "erro"){
		var results = texto.split(";"); 
		for(i=0; i<(results.length-1); i++){ 
			var string = results[i].split("|"); 
			componente.options[i] = new Option( unescape(string[1].replace(/\+/g," ")),string[0]); 
		}
	}else{
			componente.options[0] = new Option("Escolha um tipo","0"); 
			document.getElementById(resultado).innerHTML = "";
	}
			
}


