// JavaScript Document
function openAjax() {
	var ajax;
	try{
		ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers decentes, como: Firefox, Safari, dentre outros.
	}catch(ee){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
		}catch(e){
			try{
				ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
			}catch(E){
				ajax = false;
			}
		}
	}
	return ajax;
}


function buscaEmpreendimento(cod,tipo){
	var resposta2;
	var ajax = openAjax(); 
	
	ajax.open("GET", "busca_empreendimento.php?Cod_Empreendimento="+cod+"&tipo="+tipo, true); 
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 4) { 
			if(ajax.status == 200) {
				resposta = ajax.responseText;
				resposta = resposta.replace(/\+/g," "); 
				resposta = unescape(resposta);
				//alert(resposta);
				alteraDiv(resposta,tipo,cod);
			}
		}
	}
	ajax.send(null);
	return false;
}

function alteraDiv(resp,tipo,cod){
	var arr;
	arr = resp.split(";");
	//alert(resp);
	
	
	
	var divt = document.getElementById("span_titulo_"+tipo);
	divt.innerHTML = arr[0];
	
	var divb = document.getElementById("span_bairro_"+tipo);
	divb.innerHTML = arr[1];
	
	var divq = document.getElementById("span_quarto_"+tipo);
	divq.innerHTML = arr[2];
	
	var divs = document.getElementById("span_suite_"+tipo);
	divs.innerHTML = arr[3];
	
	if(tipo == 1){
		i = "formata_imagem_x.php?imagem=img/img_i/img_n/";	
	} else if(tipo == 2){
		i= "formata_imagem_x.php?imagem=img/img_i/img_p/";	
	} else if(tipo == 3){
		i= "formata_imagem_x.php?imagem=img/img_i/img_f/";	
	} else if(tipo == 4){
		i= "formata_imagem_x.php?imagem=img/img_i/img_s/";	
	}
	
	if(arr[4] != ""){
		var divi = document.getElementById("img_"+tipo);
		divi.src = i+arr[4]+"&xmax=129";
	} else {
		var divi = document.getElementById("img_"+tipo);
		divi.src = "formata_imagem_x.php?imagem=img/foto-default.jpg&xmax=130";
	}
	
	if(tipo == 1){
		l = "empreendimento_emconstrucao_interno.php?Cod_Empreendimento=";	
	} else if(tipo == 2){
		l = "empreendimento_prontos_interno.php?Cod_Empreendimento=";	
	} else if(tipo == 3){
		l = "empreendimento_futuros_interno.php?Cod_Empreendimento=";	
	} else if(tipo == 4){
		l = "empreendimento_seminovos_interno.php?Cod_Empreendimento=";	
	}
		
	
	var linkl = document.getElementById("link_"+tipo);
	linkl.href = l+cod;
	
	Effect.Appear("div_"+tipo);
	
	var d = document.getElementById("carregando"+tipo);
	d.style.display = "none";
}


