//método que muda o contaúdo de um determinado "objeto"
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)
				}
			}
		}
		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)
					}
				}
			}
			xmlhttp.open(tRequest,url,true)
			if(tRequest=="POST")
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlhttp.send()
		}
	}
}


//página atual da navegação
var pagAtual =  "";
//página anterior da navegação
var pagAnt =  "";

//Método que decide qual conteúdo será inserido
function mudaConteudo(endpagina) {
	if (!endpagina || endpagina==""){
		myCoo = getCookie('pagina');
		myPrimVez = getCookie('primVez');
		if (myPrimVez == 'true'){
			mypagina = "home";
			setCookie('pagina', mypagina);
			setCookie('primVez', 'false');
		}
		else{
			mypagina = myCoo;
			setCookie('pagina', mypagina);
		}
	}
	else{
		mypagina = endpagina
	}
	if (mypagina != pagAtual){
		pagAnt = pagAtual;
		pagAtual = mypagina;
		loadXMLDoc('inc/'+mypagina+'.php', 'topo', 'GET');
		setCookie('pagina', mypagina);
		if (pagAnt != "home" && pagAnt != ""){
			mudaImg('bot'+pagAnt, 'off', '');
		}
		if (mypagina != "home"){
			mudaImg('bot'+mypagina, 'on', '');
		}
	}
}


//método que altera as imagens do menu.
//As imagens deverão seguir o seguinte padrão de nome: // botNomedapagina_estado.gif
function mudaImg(imagem, estado, narq){

	if (narq != pagAtual){
		myImg = document.getElementById(imagem)
		if (myImg != undefined){
			myImg.src = "img/"+imagem+"_"+estado+".gif";
		}
	}
	alert(myImg.src);
}


function volta(){
	loadXMLDoc('inc/'+pagAnt+'.php', 'contGeral', 'GET');
	holdPagAnt = pagAnt;
	pagAnt = pagAtual;
	pagAtual = holdPagAnt;
	holdPagAnt = "";
}

function simplePreload() {
	var args = simplePreload.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i<args.length; i++){
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}

function Abre(url, width, height, rola)	{
	if (rola==""){rola="yes"}
	window.open(url,"_blank","resizable=no,toolbar=no,status=no,top=" + (window.screen.height - height)/2 + ",left=" + (window.screen.width - width)/2 + ",menubar=no,scrollbars=" + rola + ",width=" + width + ",height=" + height);
}


function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0){
		offset = document.cookie.indexOf(search)
		if (offset != -1){
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if (end == -1)
			end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

function expira(){
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000*60*60*24*365);
	return expires;
}

function checaCookie(name,nomim) {
	if (getCookie(name)=='on'){
		Elemento = document.getElementById(nomim);
		Elemento.style.display="block";
	}
}

function submeteNews(dados) {
	box = document.news.remetente;
	if (box.value.length==0){
		alert('Digite seu E-mail');
	}
	else {
		Abre('./popupCadNews.php?module=news&add_mail='+box.value, 420, 270, "no");
	}
}

/*function onlyNumbers(){
if (event.keyCode < 48 || event.keyCode > 57)
event.returnValue = false;
else if (event.which < 48 || event.which > 57){
event.returnValue = false;
}
}*/

function mascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
	if (strCheck.indexOf(key) == -1) return false; // Chave inválida
	len = objTextBox.value.length;
	for(i = 0; i < len; i++)
	if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) objTextBox.value = '';
	if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
	if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
	if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += SeparadorMilesimo;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		objTextBox.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		objTextBox.value += aux2.charAt(i);
		objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
	}
	return false;
}

function maskTel(objTel) {
	if(objTel.value.length==2) {
		tel = "("+objTel.value+")";
		objTel.value = tel;
	}
	if(objTel.value.length==8) {
		tel = objTel.value+"-";
		objTel.value = tel;
	}
}

function onlyNumbers(e){
	if (document.all)
	var tecla = event.keyCode;
	else{
		var tecla = e.which;
	}
	if ((tecla > 47 && tecla < 58) || tecla == 8 || tecla == 0) // numeros de 0 a 9
	return true;
	else{
		return false;
	}
}

/*function validaTelefone(elemId) {
if (event.keyCode < 48 || event.keyCode > 57) {
event.returnValue = false;
}
var nkey = event.keyCode;
d = document.getElementById(elemId);
if (nkey != 8) {
if (d.value.length == 4) {
d.value += "-";
}
else if (d.value.length == 9){
return false;
}
}

}*/

function mudaCor(myTr,myCor){
	myTr.className=myCor;
}

function abreDet(url2){
	if (window.screen.height > "600"){
		rola2="no";
		width2="773";
		height2="587";
		posTop2=(window.screen.height - height2)/2;
		posLeft2=(window.screen.width - width2)/2;
	}
	else{
		rola2="yes";
		width2="792";
		height2="510";
		posTop2="0";
		posLeft2="0";
	}
	window.open(url2,"_blank","resizable=no,toolbar=no,status=yes,top=" + posTop2 + ",left=" + posLeft2 + ",menubar=no,scrollbars=" + rola2 + ",width=" + width2 + ",height=" + height2);
}

function abreDentro(url){
	if (window.screen.height > 600){
		rola="no";
		width="660";
		height="356";
		posTop=(window.screen.height - height)/2;
		posLeft=(window.screen.width - width)/2;
	}
	else{
		rola="yes";
		width="792";
		height="510";
		posTop="0";
		posLeft="0";
	}
	window.open(url,"_blank","resizable=no,toolbar=NO,status=yes,top=" + posTop + ",left=" + posLeft + ",menubar=no,scrollbars=" + rola + ",width=" + width + ",height=" + height);
}

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 abreUrlHidden(url, width, height,scrools){
	win=window.open(url,"","width="+width+",height="+height+",top=200, left=200, scrollbars="+scrools+", resizable=NO");
	return win;
}


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>'
	;
	if(document.getElementById(destino)){
		document.getElementById(destino).innerHTML = myFlash;
	}else{
		alert('não achou a div');
	}
}


function abreImo(url){
	if (window.screen.height > 600){
		rola="no";
		width="773";
		height="587";
		posTop=(window.screen.height - height)/2;
		posLeft=(window.screen.width - width)/2;
	}
	else{
		rola="yes";
		width="792";
		height="510";
		posTop="0";
		posLeft="0";
	}
	window.open(url,"_blank","resizable=no,toolbar=no,status=yes,top=" + posTop + ",left=" + posLeft + ",menubar=no,scrollbars=" + rola + ",width=" + width + ",height=" + height);
}

function validaMail(objMail){
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(objMail)))
	{
		email = false;
	}
	else{
		email = true;
	}
	return email;
}

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

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

	if (submit==false){
		return false;
	}
	else{
		return true;
	}
}

function validaForm(obj) {
	objAux = obj.elements;
	parametros = "";
	erro = 0;
	msgErro = "Campo Obrigatórios\n\n";
	if(obj.txtnome.value=="") {
		erro = 1;
		msgErro += "- Razão Social/Nome\n";
	}
	if(obj.txtddd.value=="" || obj.txttelefone.value=="") {
		erro = 1;
		msgErro += "- Telefone\n";
	}
	if(obj.txtemail.value=="") {
		erro = 1;
		msgErro += "- E-Mail";
	}else{
		if(!validaMail(obj.txtemail.value)) {
			alert("E-Mail Inválido.");
		}
	}
	if(erro) {
		alert(msgErro);
	}else{
		for(var i=0; i < objAux.length; i++) {
			if(obj[i].type=="select-one" || obj[i].type=="text" || obj[i].type=="hidden" || obj[i].type=="textarea") {
				parametros += obj[i].name+"="+obj[i].value+"&";
			}
		}
		consultaAjaxText("submeteForms.php", parametros, "post", "contGeral", "Enviando Aguarde...");
	}
}

function listImCompleta(){
	parametros = "uf=1&codcidade=3&codsetor=0&quartos=0&busca=1&visual=1&tipo=0&categ=0&pais=0";
	consultaAjaxText("inc/gedoor_list.php", parametros, "get", "contGeral", "Carregando Aguarde...");
	//consultaAjaxText("inc/"+url+".php", parametros, "get", "contGeral", "Carregando Aguarde...");
}
function mudaImagem(i){
	var obj = document.getElementById('foto');
	if(obj.src==window.location.href){
		obj.src=arrayFotos[0];
	}
	else{
		obj.style.visible=false;
	}
	obj.src=arrayFotos[i];
}

var i = 0;
function percorre(){
	mudaImagem(i);
	if(arrayFotos.length-2==i){
		i=0;
	}else{
		++i;
	}
	setTimeout("percorre()",15000);
}
function overMouse(myBot,myClass){
	if(myBot=="[object]"){myObj = myBot}
	else{myObj = document.getElementById(myBot)}
	myObj.className=myClass;
}
function goURL(url) {
	document.location.href=url;
}


function submitBusca(obj,destino){
	objAux = obj.elements;
	parametros = "";
	//alert(obj);
	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+"&";
		}
	}
	consultaAjaxText("inc/gedoor_list.php", parametros, "get", ""+destino+"", "Carregando Aguarde...");
}
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 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 Limpa_Campo(obj){
	obj.value='';
}
function cadNews(Form){
	emailNews = Form.email;

	if(emailNews.value==""){
		alert("Informe o e-mail que deseja cadastrar!");
		return false;
	}else{
		if(!validaMail(emailNews.value)){
			alert("Informe um e-mail válido!");
			return false;
		}

		parametros = "emailNews="+emailNews.value+"&nomeNews="+Form.nome.value+"&action=5";
		Form.reset();
		consultaAjaxText("ctrlImplementa.php", parametros, "post","resposta_news", "");
		return false;
	}
}


function loadSubCate(idCateMae,dirSis){
	var divCarrega   = document.getElementById("loadSubCate"+idCateMae);
	var imgMaisMenos = document.getElementById("img"+idCateMae);

	if(divCarrega.style.display=="none"){
		divCarrega.style.display = "";
		imgMaisMenos.src = dirSis+"/imgs/menos.gif";
		consultaAjaxText(dirSis+"/../index.php?acao=listaSubCate&id_cateMae="+idCateMae, "", "post", "loadSubCate"+idCateMae, "");
	}else{
		divCarrega.style.display = "none";
		imgMaisMenos.src = dirSis+"/imgs/mais.gif";
	}
}
