﻿function bloquearTeclas(e) {
   var key;
   var keychar;
   var reg;
   if (window.event) {
      key = e.keyCode;
   } else if(e.which) {
      key = e.which;
   } else {
      return true;
   }

   keychar = String.fromCharCode(key);
   reg = /\d/;
   return reg.test(keychar);
}

function FormataTelefone() {
   if (document.frmInterna.Telefone.value.length > 0) {
      Telefone = document.frmInterna.Telefone.value + "00000000";
      Telefone = Telefone.replace("-","");
      Telefone = Telefone.substring(0,4) + "-" + Telefone.substring(4,8);
      document.frmInterna.Telefone.value = Telefone;
   }
}

function LimparCampos() {
   document.frmLogin.Login.value="";
   document.frmLogin.Senha.value="";
   document.getElementById("Status").innerHTML = "<font style='color: #555555; font-size: 12px;'>informe o seu login e a sua senha!</font>";
   document.getElementById("StatusLogin").innerHTML = "";
   document.getElementById("StatusSenha").innerHTML = "";
   document.frmLogin.Login.focus();
}

function EfetuarLogin() {
   document.getElementById("StatusLogin").innerHTML = "";
   document.getElementById("StatusSenha").innerHTML = "";
   document.getElementById("Status").innerHTML = "";
   if (document.frmLogin.Login.value.length == 0) {
      document.getElementById("StatusLogin").innerHTML = "<font style='color: #FF0000; font-size: 12px;'>informe o seu login!</font>";
      document.frmLogin.Login.focus();
      return;
   }
   if (document.frmLogin.Senha.value.length == 0) {
      document.getElementById("StatusSenha").innerHTML = "<font style='color: #FF0000; font-size: 12px;'>informe a sua senha!</font>";
      document.frmLogin.Senha.focus();
      return;
   }
   document.frmLogin.submit();
}

function EfetuarLogout() {
   location.href="logout.asp";
}

function ExibeMsg(Opcao,Acao) {
   Cor = "#555555";
   Cor2 = "#FCFCFC";
   Cor3 = "#DEDEDE";
   Opcao2 = "";
   if ((Opcao == "Clientes") && (Acao == "in")) {
      Opcao2 = "Cadastre, Altere e Exclua os Clientes que terão acesso a Área Restrita!";
      Cor = "#c6d83d";
      Cor2 = "#fcffe4";
      Cor3 = "#c6d83d";
      Imagem = "images/clientes2.png";
   } 
   if ((Opcao == "Clientes") && (Acao == "out")) {
      Imagem = "images/clientes.png";
   } 
   if ((Opcao == "Paginas") && (Acao == "in")) {
      Opcao2 = "Controle as Páginas, enviando arquivos PDF, Fotos e Plantas, além de textos informativos!";
      Cor = "#c6d83d";
      Cor2 = "#fcffe4";
      Cor3 = "#c6d83d";
      Imagem = "images/paginas2.png";
   } 
   if ((Opcao == "Paginas") && (Acao == "out")) {
      Imagem = "images/paginas.png";
   } 
   document.getElementById("mensagem").innerHTML = Opcao2;
   document.getElementById("fonte" + Opcao).style.color = Cor;
   document.getElementById("box" + Opcao).style.backgroundColor = Cor2;
   document.getElementById("box" + Opcao).style.borderColor = Cor3;
   document.getElementById("imagem" + Opcao).src = Imagem;
}

function CarregaOpcao(Opcao) {
   location.href = Opcao.toLowerCase() + ".asp";
}

function AdicionarCliente() {
   location.href="clientes.asp?Opcao=Adicionar";
}
function EditarCliente() {
   idCliente = "";
   if (document.frmAdmin.idCliente == undefined) {
      alert("Nenhum cliente disponível!");
   } else {         
      if (document.frmAdmin.idCliente.length != undefined) {
         for (x = 0; x < document.frmAdmin.idCliente.length; x++) {
            if (document.frmAdmin.idCliente[x].checked) {
               idCliente = document.frmAdmin.idCliente[x].value;
               break;
            }
         }
         if (idCliente.length > 0) {
            location.href="clientes.asp?Opcao=Alterar&idCliente="+idCliente;
         } else {
            alert("Selecione um cliente para fazer a alteração dos dados!");
         }
      } else {
         if (document.frmAdmin.idCliente.checked) {
            location.href="clientes.asp?Opcao=Alterar&idCliente="+document.frmAdmin.idCliente.value;
         } else {
            alert("Selecione um cliente para fazer a alteração dos dados!");
         }
      }   
   }      
}

function ExcluirCliente() {
   idCliente = "";
   if (document.frmAdmin.idCliente == undefined) {
      alert("Nenhum cliente disponível!");
   } else {         
      if (document.frmAdmin.idCliente.length != undefined) {
         for (x = 0; x < document.frmAdmin.idCliente.length; x++) {
            if (document.frmAdmin.idCliente[x].checked) {
               idCliente = document.frmAdmin.idCliente[x].value;
               break;
            }
         }
         if (idCliente.length > 0) {
	        if (confirm("Deseja realmente excluir este cliente?")) {
               location.href="clientes.asp?Opcao=Excluir&idCliente="+idCliente;
            }
         } else {
            alert("Selecione uma cliente para fazer a exclusão dele!");
         }
      } else {
         if (document.frmAdmin.idCliente.checked) {
            if (confirm("Deseja realmente excluir este cliente?")) {
               location.href="clientes.asp?Opcao=Excluir&idCliente="+document.frmAdmin.idCliente.value;
            }
         } else {
            alert("Selecione um cliente para fazer a exclusão dele!");
         }
      }  
   }       
}      

function Filtrar() {
   if (document.getElementById("filtro").style.display == "block") {
      document.getElementById("filtro").style.display = "none";
      document.frmAdmin.cmdFiltrar.value = "ABRIR FILTRO";
   } else {
      document.getElementById("filtro").style.display = "block";
      document.frmAdmin.cmdFiltrar.value = "FECHAR FILTRO";      
   }
}

function SelecionaFiltro(Filtro) {
   if (Filtro == "Nome") {
      document.frmAdmin.FiltroeMail.value = "";
      document.frmAdmin.FiltroUnidade.value = "";
      document.frmAdmin.FiltroTipo.selectedIndex = 0;
      document.frmAdmin.FiltroLogin.value = "";
   }
   if (Filtro == "eMail") {
      document.frmAdmin.FiltroNome.value = "";
      document.frmAdmin.FiltroUnidade.value = "";
      document.frmAdmin.FiltroTipo.selectedIndex = 0;
      document.frmAdmin.FiltroLogin.value = "";
   }
   if (Filtro == "Unidade") {
      document.frmAdmin.FiltroNome.value = "";
      document.frmAdmin.FiltroeMail.value = "";
      document.frmAdmin.FiltroTipo.selectedIndex = 0;
      document.frmAdmin.FiltroLogin.value = "";
   }
   if (Filtro == "Tipo") {
      document.frmAdmin.FiltroNome.value = "";
      document.frmAdmin.FiltroeMail.value = "";
      document.frmAdmin.FiltroUnidade.value = "";
      document.frmAdmin.FiltroLogin.value = "";
   }
   if (Filtro == "Login") {
      document.frmAdmin.FiltroNome.value = "";
      document.frmAdmin.FiltroTipo.selectedIndex = 0;
      document.frmAdmin.FiltroeMail.value = "";
      document.frmAdmin.FiltroUnidade.value = "";
   }
   document.getElementById("filtroNome").style.display = "none";
   document.getElementById("filtroeMail").style.display = "none";
   document.getElementById("filtroUnidade").style.display = "none";
   document.getElementById("filtroTipo").style.display = "none";
   document.getElementById("filtroLogin").style.display = "none";
   document.getElementById("filtro" + Filtro).style.display = "block";
}

function Cancelar() {
   location.href="clientes.asp";
}

function Gravar() {
   NomeCompleto = document.frmAdmin.NomeCompleto.value;
   eMail = document.frmAdmin.eMail.value;
   Unidade = document.frmAdmin.Unidade.value;
   Tipo = document.frmAdmin.Tipo.selectedIndex;
   Login = document.frmAdmin.Login.value;
   Senha = document.frmAdmin.Senha.value;
   document.getElementById("erroNOME").innerHTML = "&nbsp;";
   document.getElementById("erroEMAIL").innerHTML = "&nbsp;";
   document.getElementById("erroUNIDADE").innerHTML = "&nbsp;";
   document.getElementById("erroLOGIN").innerHTML = "&nbsp;";
   document.getElementById("erroSENHA").innerHTML = "&nbsp;";
   document.getElementById("erroTIPO").innerHTML = "&nbsp;";
   
   if (NomeCompleto.length == 0) {
      document.getElementById("erroNOME").innerHTML = "Informe o Nome Completo!";
      document.frmAdmin.NomeCompleto.focus();
      return;
   }
   if (eMail.length == 0) {
      document.getElementById("erroEMAIL").innerHTML = "Informe o e-Mail!";
      document.frmAdmin.eMail.focus();
      return;
   }
   AchouArroba = document.frmAdmin.eMail.value.indexOf("@");
   AchouPonto = document.frmAdmin.eMail.value.indexOf(".");
   if (AchouArroba <= 0 || AchouPonto <= 0) {
      document.getElementById("erroEMAIL").innerHTML = "Formato do e-Mail inválido!";
      document.frmAdmin.eMail.focus();
      return;
   }      
   if (Unidade.length == 0) {
      document.getElementById("erroUNIDADE").innerHTML = "Informe a Unidade!";
      document.frmAdmin.Unidade.focus();
      return;
   }
   if (Tipo == "0") {
      document.getElementById("erroTIPO").innerHTML = "Informe o Tipo de Apartamento!";
      document.frmAdmin.Tipo.focus();
      return;
   }
   if (Login.length == 0) {
      document.getElementById("erroLOGIN").innerHTML = "Informe o Login!";
      document.frmAdmin.Login.focus();
      return;
   }
   if (Senha.length == 0) {
      document.getElementById("erroSENHA").innerHTML = "Informe a Senha!";
      document.frmAdmin.Senha.focus();
      return;
   }         
   document.frmAdmin.submit();
}

function GerarSenha() {
   StringRandom = "";
   String = "0123456789abcdefghiklmnopqrstuvwxyz";
   Tamanho = 10;
   for (x = 0; x < Tamanho; x++) {
      rnum = Math.floor(Math.random() * String.length);
	  StringRandom = StringRandom + String.substring(rnum,rnum+1);
   }
   document.frmAdmin.Senha.value = StringRandom;
}

function EnviarArquivo(Tipo) {
   JanelaUploadArquivo = window.open("uploadarquivo.asp?Tipo=" + Tipo,"JanelaUploadArquivo","width=500,height=285,status=yes");
   JanelaUploadArquivo.focus();
}

function ExcluirArquivo(TipoArquivo) {
   idArquivo = "";
   if (document.frmAdmin.idArquivo == undefined) {
      alert("Nenhum arquivo disponível!");
   } else {         
      if (document.frmAdmin.idArquivo.length != undefined) {
         for (x = 0; x < document.frmAdmin.idArquivo.length; x++) {
            if (document.frmAdmin.idArquivo[x].checked) {
               idArquivo = document.frmAdmin.idArquivo[x].value;
               break;
            }
         }
         if (idArquivo.length > 0) {
	        if (confirm("Deseja realmente excluir este arquivo?")) {
               location.href="paginas.asp?Opcao=Excluir&idArquivo="+idArquivo+"&TipoArquivo="+TipoArquivo;
            }
         } else {
            alert("Selecione uma arquivo para fazer a exclusão dele!");
         }
      } else {
         if (document.frmAdmin.idArquivo.checked) {
            if (confirm("Deseja realmente excluir este arquivo?")) {
               location.href="paginas.asp?Opcao=Excluir&idArquivo="+document.frmAdmin.idArquivo.value+"&TipoArquivo="+TipoArquivo;
            }
         } else {
            alert("Selecione um arquivo para fazer a exclusão dele!");
         }
      }  
   }       
}

function AmpliarImagem(ID,Tipo) {
   if (ID.length > 0) {
      JanelaImagem = window.open("ampliar.asp?idImagem=" + ID + "&TipoArquivo=" + Tipo,"JanelaImagem","width=680,height=500,scrollbars=yes,left=10,top=10");
      JanelaImagem.focus();
   } else {
      alert("Selecione uma Foto para ampliar!");
   }
}

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 EnviarMSGFaleConosco(idUsuario) {
   document.getElementById("erroASSUNTO").innerHTML = "";
   document.getElementById("erroFALE").innerHTML = "";
   document.getElementById("erroEMAIL").innerHTML = "";
   document.getElementById("erroTELEFONE").innerHTML = "";
   Assunto = document.frmInterna.Assunto.value;
   Mensagem = document.frmInterna.Mensagem.value;
   DDD = document.frmInterna.DDD.value;
   Telefone = document.frmInterna.Telefone.value;
   eMail = document.frmInterna.eMail.value;
   if (Assunto.length == 0) {
      document.getElementById("erroASSUNTO").innerHTML = "Informe o assunto!";
      document.frmInterna.Assunto.focus();
      return;
   }
   if (eMail.length == 0) {
      document.getElementById("erroEMAIL").innerHTML = "Informe o seu e-Mail!";
      document.frmInterna.eMail.focus();
      return;
   }
   AchouArroba = eMail.indexOf("@");
   AchouPonto = eMail.indexOf(".");
   if (AchouArroba <= 0 || AchouPonto <= 0) {
      document.getElementById("erroEMAIL").innerHTML = "Formato do e-Mail inválido!";
      document.frmInterna.eMail.focus();
      return;
   }         
   if (DDD.length == 0) {
      document.getElementById("erroTELEFONE").innerHTML = "Informe o seu DDD!";
      document.frmInterna.DDD.focus();
      return;
   }
   if (Telefone.length == 0) {
      document.getElementById("erroTELEFONE").innerHTML = "Informe o seu Telefone!";
      document.frmInterna.Telefone.focus();
      return;
   }
   if (Mensagem.length == 0) {
      document.getElementById("erroFALE").innerHTML = "Digite a mensagem!";
      document.frmInterna.Mensagem.focus();
      return;
   } else {
      Status = false;
      for (x = 0; x < Mensagem.length; x++) {
         if ((Mensagem.charCodeAt(x,1) != "32") && (Mensagem.charCodeAt(x,1) != "13") && (Mensagem.charCodeAt(x,1) != "10")) {
            Status = true;
         }
      }
      if (Status == false) {
         document.getElementById("erroFALE").innerHTML = "Digite a mensagem!";
         document.frmInterna.Mensagem.focus();
         return;      
      }
   }
   ajax2 = ajaxInit();
   resultado = "";
   document.getElementById("erroFALE").innerHTML = "<img src='images/loading3.gif' alt='' align='absmiddle' /> enviando mensagem!";
   if (ajax2) {
      ajax2.open("GET", "faleconosco.asp?idUsuario=" + idUsuario + "&Assunto=" + Assunto + "&eMail=" + eMail + "&DDD=" + DDD+ "&Telefone=" + Telefone + "&Mensagem=" + Mensagem, true);
      //ajax2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      ajax2.onreadystatechange = function() {
         if(ajax2.readyState == 4) {
            if(ajax2.status == 200) {
               resultado = ajax2.responseText;
               if (resultado == "1") {
 			      document.getElementById("erroFALE").innerHTML = "<font color='green'>Mensagem Enviada com sucesso!</font>";
 			      document.frmInterna.reset();
 			      document.frmInterna.Assunto.focus();
			   } else {
			      document.getElementById("erroFALE").innerHTML = "Erro ao enviar a Mensagem. Tente novamente!";
			   }			   
            }
         }      
      }
      ajax2.send(null);
   }  
}