function montaFlash(destino, flavez, width, height, trans, scale){
	var myFlash =
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+flavez+'" align="middle">'+
	'<param name="allowScriptAccess" value="sameDomain" />'+
	'<param name="movie" value="'+flavez+'.swf" />'
	;
	if (trans == "yes"){
		myFlash += '<param name="wmode" value="transparent" />';
	}
	if (scale == "yes"){
		myFlash += '<param name="scale" value="noscale" />';
	}
	myFlash +=
	'<param name="quality" value="high" />'+
	'<param name="bgcolor" value="#ffffff" />'+
	'<embed src="'+flavez+'.swf" wmode="transparent" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="empresas" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
	'</object>'
	;
	document.getElementById(destino).innerHTML = myFlash;
}

function pageload(hash) {

	// hash doesn't contain the first # character.
	//alert(hash);
	$("#internas").hide("slow");
	setTimeout("show_loading()",5);

	if(hash) {

		//$("#internas").load(hash.replace("pg=","")+".html");
		$.ajax({
			type: "POST",
			url:"ctrlImplementa.php",
			data:hash,
			success: function(msg){
				$("#internas").html(msg);
				$("#internas").show("slow");
				hide_loading();

			}});

	} else {
		$.ajax({
			type: "POST",
			url:"ctrlImplementa.php",
			data:"pg=home",
			success: function(msg){
				$("#internas").html(msg);
				$("#internas").show("slow");
				hide_loading();

			}});
	}
}

$(document).ready(function(){

	$.historyInit(pageload);


	$("a[@rel='history']").click(function(){
		var hash = this.href;
		//	alert(hash);
		var mapa = document.getElementById('mapas');
		if(mapa){	
			mapa.style.display='none';
		} 
		var hash2 = hash.split("?");
		//alert(hash2[1])

		// moves to a new page.
		// pageload is called at once.

		$.historyLoad(hash2[1]);
		return false;
	});
});


function Limpa_Campo(objeto){
	if(objeto.value==""){
		objeto.value="Pesquisa Rápida";
	}else if(objeto.value=="Pesquisa Rápida"){
		objeto.value="";

	}

}
function submitBusca(obj,destino){
	objAux = obj.elements;
	parametros = "";
	for(var i=0; i < objAux.length; i++) {
		if(obj[i].type=="select-one" || obj[i].type=="text" || obj[i].type=="hidden") {
			parametros += obj[i].name+"="+obj[i].value+"&";
		}
	}
	CarregarPagina('internas/gedoor_list.php',parametros);
}
function CarregarPagina(pagina,parametros){
	show_loading();
	$.ajax({
		type: "POST",
		url:pagina,
		data:parametros,
		success: function(msg){
			$("#internas").html(msg);
			hide_loading();

		}});
}

show_loading = function() {
	$("#internas").hide("slow");
	$("#carregando").fadeIn();
}

//oculta a mensagem de carregando
hide_loading = function() {
	$("#carregando").fadeOut();
	$("#internas").show("slow");
}

var Mapinhas;

function mapinha(){

	Mapinhas.setImovel(imoveis);

	Mapinhas.setImobiliaria(clientes);

	Mapinhas.setImoveis(codimovel);

	Mapinhas.setCidade(cidades);

	Mapinhas.setUf(uf);

	Mapinhas.setQuartos(quarto);

	Mapinhas.setSuites(suite);

	Mapinhas.setGaragem(garagem);

	Mapinhas.setBairros(setor);

	Mapinhas.setComercializacao(comercializacao);



	Mapinhas.setValor(valores);

	Mapinhas.setSite(urls);

	setTimeout("Mapinhas.CriarMapa('')",0);

}



function mostraEsconde(div){

	var status = document.getElementById(div).style.display;

	if(status=="none"){

		document.getElementById(div).style.display = "block";

	}else if((status=="block") || (status=="")){

		document.getElementById(div).style.display = "none";

	}

}


/***************************************************************
Formulário de contato
***************************************************************/

function validaEmail(email){
	ER = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]{2,64}(\.[a-z0-9-]{2,64})*\.[a-z]{2,4}$");
	if (ER.test(email)){
		return true;
	}
	else{
		return false;
	}
}

function ValidarFormulario(Formulario){
	if(validarFormularios(Formulario)){
		show_loading();
		$.ajax({

			type: "POST",
			url: "ctrlImplementa.php?pg=envia_email",
			data: parametros,
			success: function(msg){
				//alert('enviado com sucesso');
				$("#internas").html(msg);
				hide_loading();

			}

		});
		return false;
	}else{
		Formulario[posicao].focus();
		document.getElementById("resposta_erro").innerHTML=texto;
		return false;
	}
	return false;

}
var posicao=null;
var texto ="";
var parametros="";
function validarFormularios(Formulario){

	var Quantidade = Formulario.elements.length;
	posicao=null;
	texto="";
	var erros="";
	var i=0;
	parametros="";
	for(i;i< Quantidade;i++){
		parametros+=Formulario[i].name+"="+Formulario[i].value+"&";
		if(Formulario[i].title=="obr"){
			//alert(Formulario[i].name);
			if(Formulario[i].value==""){
				document.getElementById("label_"+Formulario[i].name).style.color="#f00";
				if(posicao==null){
					posicao= i;
					var nome = Formulario[i].name;
					nome = nome.replace("txt","");
					texto=" Preencha o Campo "+nome+" \r\n";
				}
			}else{
				if(Formulario[i].name=="email"){
					if(!validaEmail(Formulario[i].value)){
						document.getElementById("label_"+Formulario[i].name).style.color="#f00";
						if(posicao==null){
							posicao= i;
							texto=" E-mail Informado Incorretamente";
						}
					}else{
						document.getElementById("label_"+Formulario[i].name).style.color="#000";
					}

				}else{
					document.getElementById("label_"+Formulario[i].name).style.color="#000";
				}


			}

		}
	}
	if(posicao!=null){

		return false;
	}else{
		return true;
	}
}
/**********************************************************************
Formulário de contato
***********************************************************************/


function abreUrlNew(url, width, height, scrools){
	win=window.open(url,"","width="+width+",height="+height+",top=100, left=200, scrollbars="+scrools+", resizable=YES, status=no");
	return win;
}
function mudaCor(myTr,myCor){
	myTr.className=myCor;
}

function mudaImagem(imagem, div){
	immggg = document.getElementById(div);
	immggg.style.display = 'block'
	immggg.src = imagem;
}


var xmlhttp
function loadXMLDoc(url, idWrite, tRequest)
{
	if(tRequest!="GET" || tRequest!="POST")
	tRequest = "GET";
	element	=  document.getElementById(idWrite);
	element.innerHTML  = "<div style=\"width:100%; padding-top:70px; text-align:center;\"><div style=\"width:150px;\"><div style=\"float:left; padding-top:5px;\">Carregando Aguarde...</div><div style=\"float:left;\"><img src=\"img/clocks.gif\" style=\"margin-left:10px;\" align=\"center\"></div></div</div>";
	// código para Firefox, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4)
			{
				// if OK
				if (xmlhttp.status==200)
				{
					element.innerHTML=xmlhttp.responseText
				}
				else
				{
					alert("Problem Ao Tentar Abrir Arquivo:" + xmlhttp.statusText+" "+url )
				}
			}
		}
		xmlhttp.open(tRequest,url,true)
		xmlhttp.send(null)
	}
	// código para IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
		{
			xmlhttp.onreadystatechange=function(){
				if (xmlhttp.readyState==4)
				{
					// if OK
					if (xmlhttp.status==200)
					{
						element.innerHTML=xmlhttp.responseText
					}
					else
					{
						alert("Problem Ao Tentar Abrir Arquivo:" + xmlhttp.statusText+" "+url)
					}
				}
			}
			xmlhttp.open(tRequest,url,true)
			if(tRequest=="POST")
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlhttp.send()
		}
	}
}

function confirmar(){

	var submit

	submit=confirm("Você Confirma a Ação Selecionada?");



	if (submit==false){

		return false;

	}

	else{

		return true;

	}

}
