/* Constantes */
var BACKSPACE = 8, DEL = 46, DIREITA = 39, ESQUERDA = 37, TAB = 9, ENTER = 13;
var HOME = 36, END = 35, CIMA = 38, BAIXO = 40, VIRGULA = 44;
var NMIN = 48, NMAX = 57;
/* Definicoes ajax */
$.ajaxSetup({
  type: 'POST',
  contentType: 'application/x-www-form-urlencoded; charset=utf-8',
  cache: false,
  dataType: 'html',
  timeout: 30 * (1000),
  error: function(data) {
    alert('Erro identificado: ' + data);
  }
});
/* Retorna ascii tecla pressionada */
function getKey(evt) {
  return evt ? (evt.keyCode ? evt.keyCode : (evt.which ? evt.which : evt.charCode)) : null;
}
/* funcao trim */
String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g, '');
}
/* Retorna se valor = vazio / nulo */
function IsEmpty(s) {
  return ((s == null) || (s.length == 0) || (s == '') || typeof(s) == 'undefined' || (s == '&nbsp;'))
}
/* Requer confirmacao para operacoes */
function OpConfirme(msg) {
  if (confirm(msg)) {
    return true;
  } else {
    return false;
  }
}
/* Bloqueia edicao de texto em input file */
function BlockEdit(msg) {
  alert(msg);
  return false;
}
/* Obtem objetos pelo ID */
function gE(tI) {
  if (document.getElementById) {
    return document.getElementById(tI);
  }
  else if (document.all) {
    return document.all[tI];
  }
  else {
    return false;
  }
}
/* verificar navegador */
function checkBrowser(str) {
  var detect = navigator.userAgent.toLowerCase();
  if (detect.indexOf(str) + 1) {
    return true;
  } else {
    return false;
  }
}
/* Formata / Codifica dados de formularios em UTF-8 para Ajax */
function gForm(obj) {
  return encodeURI(gE(obj).value);
}
/* Retorna somente numeros */
function isDigit(c) {
  return ((c >= '0') && (c <= '9'));
}
/* Retira espacos em brancos no inicio e no fim de uma string */
function Trim(Str) {
  var l, j;
  for (l = 0; l < Str.length; l++) {
    if (Str.charAt(l) != ' ') {
      break;
    }
  }
  if (l == Str.length) {
    return '';
  }
  fim = Str.length - 1;
  for (i = 0; i < Str.length; i++) {
    if (Str.charAt(i) != ' ') {
      break;
    }
  }
  for (j = fim; j > 0; j--) {
    if (Str.charAt(j) != ' ') {
      break;
    }
  }
  return Str.substring(i, j + 1);
}
/* Funcao para teclas de controle */
function ControlKey(key) {
  if (key == HOME || key == END) {
    return true;
  }
  else if (key == BACKSPACE || key == DEL || key == TAB || key == ENTER || key == ESQUERDA || key == DIREITA) {
    return true;
  }
  else {
    return false;
  }
}
/* Retorna somente numeros */
function SoNum(evtKeyPress) {
  var key = getKey(evtKeyPress);
  if (ControlKey(key)) {
    return true;
  }
  if (key >= NMIN && key <= NMAX) {
    return true;
  }
  return false;
}
/* Tira caracteres especiais */
function LimparFormatacao(Str) {
  var s = '', espaco = 'X X';
  Str = Trim(Str);
  for (var i = 0; i < Str.length ; i++) {
    if (Str.charAt(i) != '/' && Str.charAt(i) != '-' && Str.charAt(i) != '.' && Str.charAt(i) != ',' &&
      Str.charAt(i) != ';' && Str.charAt(i) != '|' && Str.charAt(i) != espaco.charAt(1) && Str.charAt(i) != '\\' &&
      Str.charAt(i) != ':' && Str.charAt(i) != '(' && Str.charAt(i) != ')') {
      s = s + Str.charAt(i);
    }
  }
  return s;
}
/* Abre janela popup personalizada */
function AbrirPop(pagina, nome, coord_x, coord_y, barras, fixo, full) {
  var esq = (screen.width - coord_x) / 2;
  var top = ((screen.height - coord_y) / 2) - 40;
  var win_props = 'resizable=' + fixo + ', status=0, scrollbars=' + barras + ', directories=0, toolbar=0, width=' + coord_x + ', height=' + coord_y + ', top=' + top + ', left=' + esq + ', fullscreen=' + full
  var janela = window.open(pagina, nome, win_props);
  janela.focus();
}
/* Pre-seleciona item em drop-down */
function Selecione(obj_select, valor) {
  if (valor != '') {
    for (var i = 0; i < obj_select.options.length; i++) {
      if (obj_select.options[i].value == valor) {
        obj_select.selectedIndex = i;
        break;
      }
    }
  }
}
/* Pre-seleciona item em drop-down */
function SelecioneMulti(obj_select, valor) {
  if (valor != '') {
    var vetor = valor.split(',');
    for (var i = 0; i < vetor.length; i++) {
      for (var j = 0; j < obj_select.options.length; j++) {
        if (obj_select.options[j].value == vetor[i]) {
          obj_select.options[j].selected = true;
        }
      }
    }
  }
}
/* Funcaoo que formata data ##/##/#### (digitacao) */
function ajustaData(input, evento) {
  var key = getKey(evento);
  if (ControlKey(key)) return true;
  if (key == ENTER) return false;
  if (key < NMIN || key > NMAX) {
    evento.returnValue = false;
    return false;
  } else {
    if (input.value.length == 2 || input.value.length == 5) {
      input.value += '/' ;
    }
  }
  return true;
}
/* funcao que formata cpf ###.###.###-## (digitacao) */
function ajustaCPF(input, evento) {
  var key = getKey(evento);
  if (ControlKey(key)) return true;
  if (key == ENTER) return false;
  if (key < NMIN || key > NMAX) {
    evento.returnValue = false;
    return false;
  } else {
    if (input.value.length == 3 || input.value.length == 7) {
      input.value += '.';
    }
    else if (input.value.length == 11) {
      input.value += '-';
    }
  }
  return true;
}
/* funcao que formata cnpj ##.###.###/####-## (digitacao) */
function ajustaCNPJ(input, evento) {
  var key = getKey(evento);
  if (ControlKey(key)) return true;
  if (key == ENTER) return false;
  if (key < NMIN || key > NMAX) {
    evento.returnValue = false;
    return false;
  } else {
    if (input.value.length == 2 || input.value.length == 6) {
      input.value += '.';
    }
    else if (input.value.length == 10) {
      input.value += '/';
    }
    else if (input.value.length == 15) {
      input.value += '-';
    }
  }
  return true;
}
/* funcao que formata cep ##.###-#### (digitacao) */
function ajustaCEP(input, evento) {
  var key = getKey(evento);
  if (ControlKey(key)) return true;
  if (key == ENTER) return false;
  if (key < NMIN || key > NMAX) {
    evento.returnValue = false;
    return false;
  } else {
    if (input.value.length == 2) {
      input.value += '.' ;
    }
    else if (input.value.length == 6) {
      input.value += '-' ;
    }
  }
  return true;
}
/* funcao que formata telefone (##) ####-#### (digitacao) */
function ajustaFone(input, evento) {
  var key = getKey(evento);
  if (ControlKey(key)) return true;
  if (key == ENTER) return false;
  if (key < NMIN || key > NMAX) {
    evento.returnValue = false;
    return false;
  } else {
    if (input.value.length == 0 || input.value.length == 1) {
      input.value = '(' + input.value;
    }
    else if (input.value.length == 3) {
      input.value += ') ';
    }
    else if (input.value.length == 4) {
      input.value += ' ';
    }
    else if (input.value.length == 9) {
      input.value += '-';
    }
  }
  return true;
}
/* funcao que formata pis (999.99999.99-9) */
function ajustaPIS(input, evento) {
  var key = getKey(evento);
  if (ControlKey(key)) return true;
  if (key == ENTER) return false;
  if (key < NMIN || key > NMAX) {
    evento.returnValue = false;
    return false;
  } else {
    if (input.value.length == 3 || input.value.length == 9) {
      input.value += '.';
    }
    else if (input.value.length == 12) {
      input.value += '-';
    }
  }
  return true;
}
/* Verifica formato de hora */
function ajustaHora(input, evento) {
  var key = getKey(evento);
  if (ControlKey(key)) return true;
  if (key == ENTER) return false;
  if (key < NMIN || key > NMAX) {
    evento.returnValue = false;
    return false;
  } else {
    if (input.value.length == 2) {
      input.value += ':';
    }
  }
  return true;
}
/* funcao para formatar valores decimais (digitacao : numericos e com somente uma virgula) */
function ajustaDecimal(input, evento) {
  var key = getKey(evento);
  if (ControlKey(key)) return true;
  if (key == ENTER) return false;
  if (key == VIRGULA) if (input.value.indexOf(',') == -1) return true;
  return (key >= NMIN && key <= NMAX);
}
/* funcao para formatar valores monetarios (digitacao : pontos para milhares e virgula para centavos) */
function ajustaMoeda(input) {
  var n = '__0123456789', len = 15;
  var valor = input.value, l = valor.length, r = '';
  if (l > 0) {
    z = valor.substr(0, l - 1);
    s = '';
    a = 2;
    for (i = 0; i < l; i++) {
      c = valor.charAt(i);
      if (n.indexOf(c) > a) {
        a = 1;
        s += c;
      }
    }
    l = s.length;
    t = len - 1;
    if (l > t) {
      l = t;
      s = s.substr(0, t);
    }
    if (l > 2) {
      r = s.substr(0,l-2) + ',' + s.substr(l - 2, 2);
    }
    else {
      if (l == 2) {
        r = '0,' + s;
      }
      else {
        if (l == 1) r = '0,0' + s;
      }
    }
    if (r == '') {
      r = '0,00';
    }
    else {
      l = r.length;
      if (l > 6) {
        j = l % 3;
        w = r.substr(0, j);
        wa = r.substr(j, l - j - 6);
        wb = r.substr(l - 6, 6);
        if (j > 0) {
          w += '.';
        }
        k = (l - j) / 3 - 2;
        for (i = 0; i < k; i++) w += wa.substr(i * 3, 3) + '.';
        r = w + wb;
      }
    }
  }
  if (r.length <= len) {
    input.value = r;
  }
  else {
    input.value = z;
  }
}
/* funcao que formata periodo ##/#### (digitacao) */
function ajustaReferencia(input, evento) {
  var key = getKey(evento);
  if (ControlKey(key)) return true;
  if (key == ENTER) return false;
  if (key < NMIN || key > NMAX) {
    evento.returnValue = false;
    return false;
  } else {
    if (input.value.length == 2) {
      input.value += '/';
    }
  }
  return true;
}
/* Formata valor monetario para exibicao */
function MoedaMascara(num) {
  if (isNaN(num)) num = '0';
  var sign = (num == (num = Math.abs(num)));
  num = Math.floor(num * 100 + 0.50000000001);
  var cents = (num % 100);
  num = Math.floor(num / 100).toString();
  if (cents < 10) cents = '0' + cents;
  for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
    num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));
  return (((sign) ? '' : '-') + num + ',' + cents);
}
/* formata valor para ponto decimal */
function CMoeda(valor) {
  return (valor.length > 0) ? valor.replace('.', '').replace(',', '.') : 0;
}
/* formata valor monetario digitado convertido para inteiro */
function CMoedaInteiro(valor) {
  return (!isNaN(valor)) ? retorno = Math.round(valor * 100) : 0;
}
/* Validacao de Inputs */
/* Verifica formato de E-mail */
function vEmail(email) {
  var BadChars = 'áàâãäêéèëíìïîóòôõöúùûüçÿý*´`$#!\'"¨&(){}?/\^~:;,= ';
  var GoodChars = '@.';
  var posarroba = email.indexOf ('@', 0);
  if (email.length < 6) {
    return true;
  }
  for (var j = 0; j < email.length; j++) {
    if (BadChars.indexOf(email.charAt(j)) != -1) {
      return true;
    }
  }
  for (var i = 0; i < GoodChars.length; i++) {
    if (email.indexOf(GoodChars.charAt(i)) == -1) return true;
    if (email.indexOf(GoodChars.charAt(i), 0) == 0) return true;
    if (email.lastIndexOf(GoodChars.charAt(i)) > email.length - 3) return true;
  }
  if (email.lastIndexOf('@') > email.lastIndexOf('.')) return true;
  if (email.indexOf ('@.', 0) != -1 || email.indexOf ('.@', 0) != -1) return true;
  if (email.indexOf ('@', posarroba + 1) != -1) return true;
  return false;
}
/* Valida validade de Data */
function vData(data) {
  if (data == '') {
    alert('Data n\u00e3o digitada!');
    return true;
  }
  else if (data.length < 8) {
    alert('Formato de campo "Data" inv\u00e1lido!');
    return true;
  }
  var v_data = data.split('/');
  var tmpDia = Math.abs(v_data[0]), tmpMes = Math.abs(v_data[1]), tmpAno = Math.abs(v_data[2]);
  var bissexto;
  if (isNaN(tmpDia) || isNaN(tmpMes) || isNaN(tmpAno)) {
    alert('Valores n\u00e3o permitidos para campo "Data".');
    return true;
  }
  if ((tmpDia <= 0) || (tmpDia > 31) || (tmpMes <= 0) || (tmpMes > 12)) {
    alert('Valores para "Data" inv\u00e1lidos!');
    return true;
  }
  else {
    /* Verificando se o ano e bissexto */
    if ((tmpAno % 4 == 0) || (tmpAno % 100 == 0) || (tmpAno % 400 == 0)) {
      bissexto = 1;
    }
    /* Valindando o m\u00eas de fevereiro */
    if ((tmpMes == 2) && (bissexto == 1) && (tmpDia > 29)) {
      alert('Dia inv\u00e1lido para M\u00eas selecionado!\n(O ano selecionado n\u00e3o corresponde a ano Bissexto)');
      return true;
    }
    if ((tmpMes == 2) && (bissexto != 1) && (tmpDia > 28)) {
      alert('Dia inv\u00e1lido para M\u00eas selecionado!');
      return true;
    }
    /* Validando o mes */
    if ((tmpDia == 31) && ((tmpMes == 4) || (tmpMes == 6) || (tmpMes == 9) || (tmpMes == 11))) {
      alert('Rela\u00e7\u00e3o Dia/M\u00eas inv\u00e1lida!\n(O M\u00eas selecionado n\u00e3o possui 31 dias)');
      return true;
    }
    return false;
  }
}
/* Valida formato de Referencia */
function vReferencia(ref) {
  var d = new Date();
  var mes = Math.abs(ref.substring(0, 2)), ano = Math.abs(ref.substring(3, 7));
  var nAno = d.getFullYear();
  if (isNaN(mes) || isNaN(ano)) {
    alert('Valores n\u00e3o permitidos para campo "MM/AAAA".');
    return true;
  }
  if ((mes < 1) || (mes > 12) || (ano > (nAno + 1))) {
    alert('Valores n\u00e3o permitidos para campo "MM/AAAA".');
    return true;
  }
  return false;
}
/* Verifica periodo de data (data final menor que data inicio) */
function vDataPeriodo(di, df, msg) {
  var dia_i = Math.abs(di.substring(0,2)), mes_i = Math.abs(di.substring(3,5)), ano_i = Math.abs(di.substring(6,10));
  var dia_f = Math.abs(df.substring(0,2)), mes_f = Math.abs(df.substring(3,5)), ano_f = Math.abs(df.substring(6,10));
  if ((ano_f < ano_i) || ((dia_f < dia_i) && (mes_f == mes_i) && (ano_f == ano_i)) || ((mes_f < mes_i) && (ano_f == ano_i))) {
    if (IsEmpty(s)) {
      msg = 'Data final menor que a data inicial!';
    }
    alert(msg);
    return true;
  } else return false;
}
/* valida e compara duas datas */
function vDataNow(data) {
  var d = new Date();
  var agora = d.getDate() + '/' + (d.getMonth() + 1) + '/' + d.getFullYear();
  if (vData(data.value)) {
    data.focus();
    return true;
  }
  else if (vDataPeriodo(agora, data.value, 'Data digita menor que a data atual!')) {
    data.focus();
    return true;
  }
  else return false;
}
/* valida periodo (data inicial / data final) */
function vPeriodo(d_ini, d_fim) {
  if (vData(d_ini.value)) {
    d_ini.focus();
    return true;
  }
  else if (vData(d_fim.value)) {
    d_fim.focus();
    return true;
  }
  else if (vDataPeriodo(d_ini.value, d_fim.value)) {
    d_fim.focus();
    return true;
  }
  else return false;
}
/* Verifica formato de HH:MM */
function vHora(horario) {
  var tmpHora = Math.abs(horario.substring(0,2)), tmpMinuto = Math.abs(horario.substring(3,5));
  if ((tmpHora < 0) || (tmpHora > 23) || (tmpMinuto < 0) || (tmpMinuto > 59)) return false;
  return true;
}
/* funcao que testa farmato de n. de telefone */
function vFone(str) {
  if ((str.length == 0) || (str.length != 10)) return false;
  if (isNaN(str)) return false;
  return true;
}
/* funcao que testa farmato de CEP */
function vCEP(str) {
  if ((str.length == 0) || (str.length != 8)) return false;
  if (isNaN(str)) return false;
  return true;
}
/* funcao que testa validade de CPF */
function vCPF(str) {
  var NR_CPF = str.substr(0, 9), NR_DV = str.substr(9, 2), d1 = 0, d2 = 0;
  if ((str.length > 11) || IsEmpty(NR_CPF)) return false;
  for (var i = 0; i < 9; i++) d1 += NR_CPF.charAt(i) * (10 - i);
  d1 = 11 - (d1 % 11);
  if (d1 > 9) d1 = 0;
  if (NR_DV.charAt(0) != d1) return false;
  d1 *= 2;
  for (var j = 0; j < 9; j++) d1 += NR_CPF.charAt(j) * (11 - j);
  d1 = 11 - (d1 % 11);
  if (d1 > 9) d1 = 0;
  if (NR_DV.charAt(1) != d1) return false;
  return true;
}
/* funcao que testa validade de CNPJ */
function vCNPJ(str) {
  var vale, int_z, int_i, int_j, soma, fim;
  vale = (str.length == 14);
  if (vale) {
    for (int_z = 0; int_z < 2; int_z++) {
      soma = 0;
      for (int_i = (5 + int_z), int_j = 0; int_j < (12 + int_z); int_i--, int_j++) {
        soma += (str.substr(int_j, 1) * int_i);
        if (int_i == 2) int_i = 10;
      }
      fim = (((soma % 11) < 2) ? 0 : (((soma % 11) == 10) ? 1 : 11 - (soma % 11)));
      if (!(vale = (str.substr((12 + int_z), 1) == fim))) break;
    }
  }
  return vale;
}
/* Formata, valida e exibe informacoes relativas se necessario (usa evento onblur : numerico) */
/* obj = campo; tam = tamanho max do campo; tipo = cpf | cnpj | data | cep | moeda */
function vEditaNum(obj, tam, tipo) {
  var i, strCampo = obj.value, j = 0, nTamanho = obj.value.length, szCampo = '';
  for (i = nTamanho - 1; i >= 0; i--) {
    if (isDigit(strCampo.charAt(i)))	{
      szCampo = strCampo.charAt(i) + szCampo;
      j++;
      if (j > tam) break;
    }
  }
  if (j == 0) {
    obj.value = '';
    return true;
  }
  switch (tipo) {
    case 'data':
      if (vData(strCampo)) {
        obj.focus();
        return false;
      }
      else {
        obj.value = szCampo.substr(0, 2) + '/' + szCampo.substr(2, 2) + '/' + szCampo.substr(4, 4);
        return true;
      }
      break;
    case 'periodo':
      if (!vPeriodo(strCampo)) {
        alert('Formato de per\u00edodo inv\u00e1lido [MM/AAAA]!');
        obj.focus();
        return false;
      }
      else {
        obj.value = szCampo.substr(0, 2) + '/' + szCampo.substr(2, 4);
        return true;
      }
      break;
    case 'cpf':
      if (!vCPF(szCampo)) {
        alert('N\u00famero de CPF inv\u00e1lido!');
        obj.focus();
        return false;
      }
      else {
        obj.value = szCampo.substr(0, 3) + '.' + szCampo.substr(3, 3) + '.' + szCampo.substr(6, 3) + '-' + szCampo.substr(9, 2);
        return true;
      }
      break;
    case 'cnpj':
      if (!vCNPJ(szCampo)) {
        alert('N\u00famero de CNPJ / CGC inv\u00e1lido!');
        obj.focus();
        return false;
      }
      else {
        obj.value = szCampo.substr(0, 2) + '.' + szCampo.substr(2, 3) + '.' + szCampo.substr(5, 3) + '/' + szCampo.substr(8, 4) + '-' + szCampo.substr(12, 2);
        return true;
      }
      break;
    case 'cep':
      if (!vCEP(szCampo)) {
        alert('O CEP digitado possui formato inv\u00e1lido!');
        obj.focus();
        return false;
      }
      else {
        obj.value = szCampo.substr(0, 2) + '.' + szCampo.substr(2, 3) + '-' + szCampo.substr(5, 3);
        return true;
      }
      break;
    case 'fone':
      if (!vFone(szCampo)) {
        alert('N\u00famero de telefone digitado possui formato inv\u00e1lido!');
        obj.focus();
        return false;
      }
      else {
        obj.value = '(' + szCampo.substr(0, 2) + ') ' + szCampo.substr(2, 4) + '-' + szCampo.substr(6, 4);
        return true;
      }
      break;
    case 'hora':
      if (!vHora(szCampo)) {
        alert('Hora digitada possui formato inv\u00e1lido!');
        obj.focus();
        return false;
      }
      else {
        obj.value = szCampo.substr(0, 2) + ':' + szCampo.substr(2, 4);
        return true;
      }
      break;
    case 'moeda':
      if (szCampo.length > 0) {
        obj.value = MoedaMascara(szCampo);
      }
      return true;
      break;
  }
}
/* Verifica preenchimento de dados de login */
function ValLogin(d) {
  if (d.log_name.value.length < 3) {
    alert('Por favor, digite seu nome de usu\u00e1rio\ne senha antes de continuar!');
    d.log_name.focus();
    return false;
  }
  else if (d.log_pass.value.length < 3) {
    alert('Por favor, digite sua senha para efetuar o login!');
    d.log_pass.focus();
    return false;
  }
  else {
    return true;
  }
}
/* Verifica preenchimento de dados de login */
function ValLoginMedico() {
  if ($('#medico_crm').val().length < 3) {
    alert('Por favor, entre com o CRM para continuar!');
    $('#medico_crm').focus();
    return false;
  }
  else if ($('#medico_pass').val().length < 3) {
    alert('Por favor, digite sua senha para efetuar o login!');
    $('#medico_pass').focus();
    return false;
  }
  else {
    return true;
  }
}
/* Valida formulario de criacao de novo usuario */
function ValUsuario() {
  var ret = false;
  if (IsEmpty($('#Nome').val())) {
    alert('Por favor, entre com o Nome do Usu\u00e1rio.');
    $('#Nome').focus();
  }
  else if (IsEmpty($('#Usuario').val())) {
    alert('Por favor, entre com o Login do Usu\u00e1rio.');
    $('#Usuario').focus();
  }
  else if ($('#Act').val() == 'cadastrar' && $('#Senha').val().length < 3) {
    alert('Por favor, entre com a Senha de acesso (m\u00ednimo de 3 caracters).');
    $('#Senha').focus();
  }
  else if ($('#Act').val() == 'cadastrar' && $('#ReSenha').val().length < 3) {
    alert('Por favor, Redigite a Senha de acesso.');
    $('#ReSenha').focus();
  }
  else if ($('#Act').val() == 'cadastrar' && $('#Senha').val() != $('#ReSenha').val()) {
    alert('Senhas n\u00e3o coincidem!\nRedigite as senhas.');
    $('#Senha').val('');
    $('#ReSenha').val('');
    $('#Senha').focus();
  }
  else if ($('#Act').val() == 'atualizar' && !IsEmpty($('#Senha').val())) {
    if ($('#Senha').val().length < 3) {
      alert('Por favor, entre com a Senha de acesso (m\u00ednimo de 3 caracters).');
      $('#Senha').focus();
    }
    else if ($('#ReSenha').val().length < 3) {
      alert('Por favor, Redigite a Senha de acesso.');
      $('#ReSenha').focus();
    }
    else if ($('#Senha').val() != $('#ReSenha').val()) {
      alert('Senhas n\u00e3o coincidem!\nRedigite as senhas.' + $('Senha').val() + ':' + $('#ReSenha').val());
      $('#Senha').val('');
      $('#ReSenha').val('');
      $('#Senha').focus();
    }
    else {
      ret = true;
    }
  } else {
    ret = true;
  }
  if (ret) {
    $('#sub_usuario').disabled = true;
    $('#form_usuarios').submit();
  }
}
/* valida formulario de contato */
function ValContato() {
  if (IsEmpty($('#CNome').val())) {
    alert('Por favor, entre com o seu nome');
    $('#CNome').focus();
    return false;
  }
  else if (vEmail($('#CEmail').val())) {
    alert('Endere\u00e7o de e-mail n\u00e3o preenchido ou inv\u00e1lido.');
    $('#CEmail').focus();
    return false;
  }
  else if (IsEmpty($('#CAssunto').val())) {
    alert('Por favor, entre com o assunto da mensagem');
    $('#CAssunto').focus();
    return false;
  }
  else if (IsEmpty($('#CMensagem').val())) {
    alert('Por favor, entre com a Mensagem');
    $('#CMensagem').focus();
    return false;
  }
  else {
    return true;
  }
}
/* valida formulario de trabalhe conosco */
function ValTrabalhe() {
  alert($('#TArea').val());
  if (IsEmpty($('#TNome').val())) {
    alert('Por favor, entre com o seu nome');
    $('#TNome').focus();
    return false;
  }
  else if (vEmail($('#TEmail').val())) {
    alert('Endere\u00e7o de e-mail n\u00e3o preenchido ou inv\u00e1lido.');
    $('#TEmail').focus();
    return false;
  }
  else if (IsEmpty($('#TArea').val())) {
    alert('Por favor, selecione a \u00C1rea Pretendida');
    $('#TArea').focus();
    return false;
  }
  else if (IsEmpty($('#TCV').val())) {
    alert('Por favor, selecione o Curr\u00edculo a enviar');
    $('#TCV').focus();
    return false;
  }
  else {
    return true;
  }
}
/* valida formulario de contato para convenio */
function ValSendConvenio() {
  if (IsEmpty($('#Empresa').val())) {
    alert('Por favor, entre com o da Empresa');
    $('#Empresa').focus();
    return false;
  }
  else if (IsEmpty($('#Segmento').val())) {
    alert('Por favor, entre com o Segmento da Empresa');
    $('#Segmento').focus();
    return false;
  }
  else if (IsEmpty($('#Nome').val())) {
    alert('Por favor, entre com o seu Nome');
    $('#Nome').focus();
    return false;
  }
  else if (vEmail($('#Email').val())) {
    alert('Endere\u00e7o de e-mail n\u00e3o preenchido ou inv\u00e1lido.');
    $('#Email').focus();
    return false;
  }
  else if (IsEmpty($('#Telefone').val())) {
    alert('Por favor, entre com o Telefone de Contato');
    $('#Telefone').focus();
    return false;
  }
  else if (IsEmpty($('#Mensagem').val())) {
    alert('Por favor, entre com a Mensagem');
    $('#Mensagem').focus();
    return false;
  }
  else {
    return true;
  }
}
/* valida formulario de receita online */
function ValReceita() {
  if (IsEmpty($('#Nome').val())) {
    alert('Por favor, entre com o seu nome');
    $('#Nome').focus();
    return false;
  }
  else if (IsEmpty($('#RG').val())) {
    alert('Por favor, entre com seu RG.');
    $('#RG').focus();
    return false;
  }
  else if (IsEmpty($('#Telefone').val())) {
    alert('Por favor, entre com um telefone de contato.');
    $('#Telefone').focus();
    return false;
  }
  else if (vEmail($('#Email').val())) {
    alert('Endere\u00e7o de e-mail n\u00e3o preenchido ou inv\u00e1lido.');
    $('#Email').focus();
    return false;
  }
  else if (IsEmpty($('#Arquivo').val())) {
    alert('Por favor, selecione o Arquivo contendo a Receita.');
    $('#Arquivo').focus();
    return false;
  }
  else if (IsEmpty($('#Endereco').val())) {
    alert('Por favor, entre com o seu Endere\u00e7o');
    $('#Endereco').focus();
    return false;
  }
  else if (IsEmpty($('#Unidade').val())) {
    alert('Por favor, selecione a Unidade para qual Receita ser\u00e1 enviada');
    $('#Endereco').focus();
    return false;
  }
  else if (IsEmpty($('#Medico').val())) {
    alert('Por favor, entre com o nome do M\u00e9dico');
    $('#Medico').focus();
    return false;
  }
  else if (IsEmpty($('#MedicoEndereco').val())) {
    alert('Por favor, entre com o Endere\u00e7o do M\u00e9dico');
    $('#MedicoEndereco').focus();
    return false;
  }
  else if (IsEmpty($('#Observacao').val())) {
    alert('Por favor, entre com demais orienta\u00e7\u00F5es');
    $('#Observacao').focus();
    return false;
  }
  else {
    return true;
  }
}
/* valida formulario de agendamento de visita a laboratorio */
function ValVisita() {
  if (IsEmpty($('#Nome').val())) {
    alert('Por favor, entre com o seu nome');
    $('#Nome').focus();
    return false;
  }
  else if (vEmail($('#Email').val())) {
    alert('Endere\u00e7o de e-mail n\u00e3o preenchido ou inv\u00e1lido.');
    $('#Email').focus();
    return false;
  }
  else if (IsEmpty($('#Telefone').val())) {
    alert('Por favor, entre com um telefone de contato.');
    $('#Telefone').focus();
    return false;
  }
  else if (IsEmpty($('#Mensagem').val())) {
    alert('Por favor, entre com a Mensagem');
    $('#Mensagem').focus();
    return false;
  }
  else {
    return true;
  }
}
/* valida formulário ao adicionar notícia ao sistema */
function ValNoticia() {
  if (IsEmpty($('#Titulo').val())) {
    alert('Por favor, entre com o T\u00edtulo da Not\u00edcia.');
    $('#Titulo').focus();
  }
  else if (IsEmpty($('#Conteudo').val())) {
    alert('Por favor, entre com o Texto da Not\u00edcia!');
    $('#Conteudo').focus();
  }
  else {
    $('#sub_noticia').disabled = true;
    $('#form_noticias').submit();
  }
}
/* valida formulário ao adicionar notícia ao sistema */
function ValVideo() {
  if (IsEmpty($('#Titulo').val())) {
    alert('Por favor, entre com o T\u00edtulo da V\u00eddeo.');
    $('#Titulo').focus();
  }
  else if (IsEmpty($('#Descricao').val())) {
    alert('Por favor, entre com a Descri\u00e7\u00e3o do V\u00eddeo!');
    $('#Descricao').focus();
  }
  else if (IsEmpty($('#Mini').val())) {
    alert('Por favor, entre com a Miniatura do V\u00eddeo!');
    $('#Mini').focus();
  }
  else if (IsEmpty($('#Link').val())) {
    alert('Por favor, entre com o Link do V\u00eddeo!');
    $('#Link').focus();
  }
  else {
    $('#sub_tv').disabled = true;
    $('#form_tv').submit();
  }
}
/* valida formulário ao adicionar notícia ao sistema */
function ValTudobem() {
  if (IsEmpty($('#Numero').val())) {
    alert('Por favor, entre com o N\u00famero da Revista.');
    $('#Numero').focus();
  }
  else if (IsEmpty($('#Link').val())) {
    alert('Por favor, entre com o Link para Issuu!');
    $('#Link').focus();
  }
  else {
    $('#sub_tudobem').disabled = true;
    $('#form_tudobem').submit();
  }
}
/* valida formulário ao adicionar notícia ao sistema */
function ValLink() {
  if (IsEmpty($('#Titulo').val())) {
    alert('Por favor, entre com o T\u00edtulo do Link.');
    $('#Titulo').focus();
  }
  else if (IsEmpty($('#Href').val())) {
    alert('Por favor, entre com o Endere\u00e7o!');
    $('#Href').focus();
  }
  else {
    $('#sub_link').disabled = true;
    $('#form_links').submit();
  }
}
/* valida formulário ao adicionar informe ao sistema */
function ValInforme() {
  if (IsEmpty($('#Titulo').val())) {
    alert('Por favor, entre com o T\u00edtulo do Informe.');
    $('#Titulo').focus();
  }
  else if (IsEmpty($('#Conteudo').val())) {
    alert('Por favor, entre com o Texto do Informe!');
    $('#Conteudo').focus();
  }
  else {
    $('#sub_informe').disabled = true;
    $('#form_informe').submit();
  }
}
/* valida formulário ao adicionar informe ao sistema */
function ValProduto() {
  if (IsEmpty($('#idMarca').val())) {
    alert('Por favor, selecione a marca do Produto.');
    $('#idMarca').focus();
  }
  else if (IsEmpty($('#Produto').val())) {
    alert('Por favor, entre com o Nome do produto.');
    $('#Produto').focus();
  }
  else if (IsEmpty($('#Descricao').val())) {
    alert('Por favor, entre com a Descri\u00e7\u00e3o do produto!');
    $('#Descricao').focus();
  }
  else {
    $('#sub_produto').disabled = true;
    $('#form_produto').submit();
  }
}
/* valida formulário ao adicionar informe ao sistema */
function ValMarca() {
  if (IsEmpty($('#Marca').val())) {
    alert('Por favor, entre com o Nome da Marca.');
    $('#Marca').focus();
  }
  else {
    $('#sub_marca').disabled = true;
    $('#form_marcas').submit();
  }
}
/* valida formulário ao adicionar informe ao sistema */
function ValProfissional() {
  if (IsEmpty($('#CRF').val())) {
    alert('Por favor, entre com o CRF do profissional.');
    $('#CRF').focus();
  }
  else if (IsEmpty($('#Nome').val())) {
    alert('Por favor, entre com o Nome do profissional!');
    $('#Nome').focus();
  }
  else {
    $('#sub_profissional').disabled = true;
    $('#form_profissional').submit();
  }
}
/* valida formulário ao adicionar informe ao sistema */
function ValSecao() {
  if (IsEmpty($('#Texto').val())) {
    alert('Por favor, entre com o Texto da Se\u00e7\u00e3o.');
    $('#Texto').focus();
  }
  else {
    $('#sub_secao').disabled = true;
    $('#form_secoes').submit();
  }
}
/* valida formulário ao adicionar informe ao sistema */
function ValConvenio() {
  if (IsEmpty($('#Nome').val())) {
    alert('Por favor, entre com o Nome da Empresa Conveniada!');
    $('#Nome').focus();
  }
  else if (IsEmpty($('#Endereco').val())) {
    alert('Por favor, entre com o Endere\u00e7o da Empresa Conveniada!');
    $('#Endereco').focus();
  }
  else {
    $('#sub_convenio').disabled = true;
    $('#form_convenios').submit();
  }
}
/* valida formulário ao adicionar informe ao sistema */
function ValLoja() {
  if (IsEmpty($('#Cidade').val())) {
    alert('Por favor, entre com o Nome da Cidade');
    $('#Cidade').focus();
  }
  else if (IsEmpty($('#Endereco').val())) {
    alert('Por favor, entre com o Endere\u00e7o da Loja');
    $('#Endereco').focus();
  }
  else if (IsEmpty($('#Telefax').val())) {
    alert('Por favor, entre com o Telefax da Loja!');
    $('#Telefax').focus();
  }
  else {
    $('#sub_loja').disabled = true;
    $('#form_lojas').submit();
  }
}
/* Valida formulario de cadastro medico */
function ValMedico() {
  var ret = false;
  if (IsEmpty($('#Nome').val())) {
    alert('Por favor, entre com o Nome do m\u00e9dico.');
    $('#Nome').focus();
  }
  else if (vEmail($('#Email').val())) {
    alert('Endere\u00e7o de e-mail n\u00e3o preenchido ou inv\u00e1lido.');
    $('#Email').focus();
  }
  else if (IsEmpty($('#CRM').val())) {
    alert('Por favor, entre com o CRM do m\u00e9dico.');
    $('#CRM').focus();
  }
  else if ($('#Act').val() == 'cadastrar' && $('#Senha').val().length < 3) {
    alert('Por favor, entre com a Senha de acesso (m\u00ednimo de 3 caracters).');
    $('#Senha').focus();
  }
  else if ($('#Act').val() == 'cadastrar' && $('#ReSenha').val().length < 3) {
    alert('Por favor, Redigite a Senha de acesso.');
    $('#ReSenha').focus();
  }
  else if ($('#Act').val() == 'cadastrar' && $('#Senha').val() != $('#ReSenha').val()) {
    alert('Senhas n\u00e3o coincidem!\nRedigite as senhas.');
    $('#Senha').val('');
    $('#ReSenha').val('');
    $('#Senha').focus();
  }
  else if ($('#Act').val() == 'atualizar' && !IsEmpty($('#Senha').val())) {
    if ($('#Senha').val().length < 3) {
      alert('Por favor, entre com a Senha de acesso (m\u00ednimo de 3 caracters).');
      $('#Senha').focus();
    }
    else if ($('#ReSenha').val().length < 3) {
      alert('Por favor, Redigite a Senha de acesso.');
      $('#ReSenha').focus();
    }
    else if ($('#Senha').val() != $('#ReSenha').val()) {
      alert('Senhas n\u00e3o coincidem!\nRedigite as senhas.' + $('Senha').val() + ':' + $('#ReSenha').val());
      $('#Senha').val('');
      $('#ReSenha').val('');
      $('#Senha').focus();
    }
    else {
      ret = true;
    }
  } else {
    ret = true;
  }
  if (ret) {
    $('#sub_medico').disabled = true;
    $('#form_medicos').submit();
  }
}
/* Valida formulario de cadastro medico */
function ValMedicoEdt() {
  var ret = false;
  if (IsEmpty($('#Nome').val())) {
    alert('Por favor, entre com o Nome do m\u00e9dico.');
    $('#Nome').focus();
  }
  else if (vEmail($('#Email').val())) {
    alert('Endere\u00e7o de e-mail n\u00e3o preenchido ou inv\u00e1lido.');
    $('#Email').focus();
  }
  else if ($('#Act').val() == 'cadastrar' && $('#Senha').val().length < 3) {
    alert('Por favor, entre com a Senha de acesso (m\u00ednimo de 3 caracters).');
    $('#Senha').focus();
  }
  else if ($('#Act').val() == 'cadastrar' && $('#ReSenha').val().length < 3) {
    alert('Por favor, Redigite a Senha de acesso.');
    $('#ReSenha').focus();
  }
  else if ($('#Act').val() == 'cadastrar' && $('#Senha').val() != $('#ReSenha').val()) {
    alert('Senhas n\u00e3o coincidem!\nRedigite as senhas.');
    $('#Senha').val('');
    $('#ReSenha').val('');
    $('#Senha').focus();
  }
  else if ($('#Act').val() == 'atualizar' && !IsEmpty($('#Senha').val())) {
    if ($('#Senha').val().length < 3) {
      alert('Por favor, entre com a Senha de acesso (m\u00ednimo de 3 caracters).');
      $('#Senha').focus();
    }
    else if ($('#ReSenha').val().length < 3) {
      alert('Por favor, Redigite a Senha de acesso.');
      $('#ReSenha').focus();
    }
    else if ($('#Senha').val() != $('#ReSenha').val()) {
      alert('Senhas n\u00e3o coincidem!\nRedigite as senhas.' + $('#Senha').val() + ':' + $('#ReSenha').val());
      $('#Senha').val('');
      $('#ReSenha').val('');
      $('#Senha').focus();
    }
    else {
      ret = true;
    }
  } else {
    ret = true;
  }
  if (ret) {
    $('#sub_medico').disabled = true;
    $('#form_medico').submit();
  }
}
/* funcao para exibir mapa da loja */
function ViewMapa(loja) {
  $.ajax({
    url: 'funcoes/view_mapa.php',
    data: {
      idLoja: loja
    },
    success: function(data) {
      $('#google_mapa').html(data);
      $('#google_mapa').dialog({
        modal: true,
        height: 440,
        width: 470,
        closeText: 'Fechar',
        resizable: true,
        title: 'Unidades Terap\u00eautica',
        buttons: {
          Ok: function() {
            $(this).dialog('close');
          }
        }
      });
    }
  });
}
/* funcoes dreamweaver para pre-carregar imagens */
function MM_swapImgRestore() { //v3.0
  var i, x, a = document.MM_sr;
  for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d = document;
  if (d.images) {
    if (!d.MM_p) d.MM_p = new Array();
    var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
    for (i = 0; i < a.length; i++)
      if (a[i].indexOf("#") != 0) {
        d.MM_p[j] = new Image;
        d.MM_p[j++].src = a[i];
      }
  }
}
function MM_findObj(n, d) { //v4.01
  var p, i, x;
  if (!d) d = document;
  if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
    d = parent.frames[n.substring(p + 1)].document;
    n = n.substring(0, p);
  }
  if (!(x = d[n]) && d.all) x = d.all[n];
  for (i = 0; !x && i < d.forms.length; i++) x=d.forms[i][n];
  for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
  if (!x && d.getElementById) x = d.getElementById(n);
  return x;
}
function MM_swapImage() { //v3.0
  var i, j = 0, x, a = MM_swapImage.arguments;
  document.MM_sr = new Array;
  for (i = 0;i < (a.length - 2); i += 3)
    if ((x = MM_findObj(a[i])) != null) {
      document.MM_sr[j++] = x;
      if (!x.oSrc) x.oSrc = x.src;
      x.src = a[i + 2];
    }
}
if ($('.fadein')) {
  $('.fadein img:gt(0)').hide();
  setInterval(function() {
    $('.fadein :first-child').fadeOut('fast').next('img').fadeIn().end().appendTo('.fadein');
  }, 8000);
}
