//===============================================================================
//= FUNÇÕES DE FORMULÁRIO =======================================================
//===============================================================================
var tipo = 0;

function FaleConosco() {
	tipo = 1;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}

function Newsletter() {
	tipo = 2;
	document.form1.action = "newsletter-act.asp";
	document.form1.method = "post";
}

function BuscaPP() {
	tipo = 3;
	document.form1.action = "imoveis/busca.asp";
	document.form1.method = "post";
}

function Busca() {
	tipo = 4;
	document.form1.action = "../imoveis/busca.asp";
	document.form1.method = "post";
}

function LocarComprar() {
	tipo = 5;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}

function AnunciarCadastrar() {
	tipo = 6;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}

function BuscaAvancada() {
	tipo = 7;
	document.form1.action = "resultados.asp";
	document.form1.method = "post";
}

function EnviarImovel() {
	tipo = 8;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}




function EnviaFormulario() {
	switch(tipo) {
		case 1: return VFaleConosco(); break;
		case 2: return VNewsletter(); break;
		case 3: return VBusca(); break;
		case 4: return VBusca(); break;
		case 5: return VLocarComprar(); break;
		case 6: return VAnunciarCadastrar(); break;
		case 7: return VBusca(); break;
		case 8: return VEnviarImovel(); break;
	}
	return false;
}


//===============================================================================
//= BUSCA =======================================================================
//===============================================================================
function VBusca() {
	return true;
}

//===============================================================================
//= FUNÇÃO DE EXIBIÇÃO DOS MENUS ================================================
//===============================================================================
function SHMenu(menu, linkMenu) {
	element = document.getElementById("menu" + menu);
	element.style.display = element.style.display != 'none' ? 'none' : '';
}


//===============================================================================
//= FUNÇÃO DE EXIBIÇÃO DOS MENUS DE CATEGORIA ===================================
//===============================================================================
function EscondeCat(id) {
	document.getElementById(id).style.display = (document.getElementById(id).style.display == 'none') ? '' : 'none';
}


//===============================================================================
//= JUMP MENU ===================================================================
//===============================================================================
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


//===============================================================================
//= ABRE POP-UP CENTRALIZADO ====================================================
//===============================================================================
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = parseInt((screen.width) ? (screen.width-w)/2 : 0);
	TopPosition = parseInt((screen.height) ? (screen.height-h)/2 : 0);
	settings = 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',noresizable,status=yes'
	win = window.open(mypage,myname,settings)
}


//===============================================================================
//= REDIMENSIONA POP-UP =========================================================
//===============================================================================
function Redimensiona(w, h) {
	//Corrige o tamanho da janela
	if (navigator.appName == "Microsoft Internet Explorer") {
		w = parseInt(w) + 10;
		h = parseInt(h) + 48;
	} else {
		w = parseInt(w) + 6;
		h = parseInt(h) + 49;
	};
	// IE 7
	var nversao = navigator.appVersion;
	var nresult = nversao.search(/\bMSIE 7.0\b/g);
	if (nresult > 0) {
		h = parseInt(h) + 28;
	};
	//
	window.resizeTo(w, h);
	LeftPosition =  parseInt((screen.width) ? (screen.width-w)/2 : 0);
	TopPosition =  parseInt((screen.height) ? (screen.height-h)/2 : 0);
	window.moveTo(LeftPosition,TopPosition);
	window.focus();
}


//===============================================================================
//= EXIBE FLASHS ================================================================
//===============================================================================
function ExibeFlash(movie,w,h,wmode,bg) {
	if(wmode == "transparent") { ftransp = true; wmode = "wmode='transparent'"; } else { ftransp = false; wmode = ""; };

	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">');
	if(ftransp) { document.write('<param name="wmode" value="transparent"/>'); };
	document.write('<param name="quality" value="high"/>');
	document.write('<param name="movie" value="'+movie+'"/>');
	document.write('<embed src="'+movie+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" '+wmode+' width="'+w+'" height="'+h+'"></embed>');
	document.write('</object>');
}

//===============================================================================
//= AJAX ========================================================================
//===============================================================================
function ajaxInit() {
	var req;
	
	try {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(ex) {
			try {
				req = new XMLHttpRequest();
			} catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				req = null;
			}
		}
	}
	return req;
};

function LoadAjax(metodo, url, send, destino, loadshow, loadcontent, loaddestino, janela) {
	var ajax = ajaxInit();	
	if(ajax) {  
		if(metodo == "post") {  
				ajax.open("POST", url, true);  
				ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
		} else {
				ajax.open("GET", url + "?rnd="+ Math.random() +"&"+ send, true);  
		}
		ajax.onreadystatechange = function() { 
																if (ajax.readyState == 1) {
																	if (loadshow == 2) {
																		document.getElementById(loaddestino).innerHTML = loadcontent;
																	};
																}
																if (ajax.readyState == 4) {
																	if (ajax.status == 200) {
																		var resultado = ajax.responseText; // Coloca o retornado pelo Ajax nessa variável 
																		resultado = resultado.replace(/\+/g," "); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4) 
																		resultado = unescape(resultado); // Resolve o problema dos acentos 
																		if (loadshow == 2) {
																			document.getElementById(loaddestino).innerHTML = '';
																		};
																		if (janela != 2) {
																			document.getElementById(destino).innerHTML = resultado;
																		} else {
																			opener.document.getElementById(destino).innerHTML = resultado;
																			setTimeout("window.close()", 1000);
																		};
																	};
																}
															}  
			
		if(metodo == "post") {  
			ajax.send(send);  
		} else {  
			ajax.send(null);  
		}  
	}  
}