var xmlHttpReq = false;

function GetXmlHttpObject() {
  var xmlHttpReq = false;
  var xmlHttpReq = null;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttpReq = new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttpReq;
}

function admin(){
  window.open("admin.php", "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=800, height=600 , top=0 , left=0");
}

function fechar(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'sair.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
     setTimeout("location.href='admin.php'",500);
     }
  }
  xmlHttpReq.send();
}

function post_inscricao(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }

   id_curso   = document.cad.id.value;
   nome       = document.cad.nome.value;
   funcao     = document.cad.funcao.value;
   conselho   = document.cad.conselho.value;
   inscricao  = document.cad.inscricao.value;
   nasc       = document.cad.nasc.value;
   sexo       = document.cad.sexo.value;
   ecivil     = document.cad.ecivil.value;
   rg         = document.cad.rg.value;
   data_exp   = document.cad.data_exp.value;
   cpf        = document.cad.cpf.value;
   pis        = document.cad.pis.value;
   titulo     = document.cad.titulo.value;
   zona       = document.cad.zona.value;
   secao      = document.cad.secao.value;
   cnh        = document.cad.cnh.value;
   categ      = document.cad.categ.value;
   validade   = document.cad.validade.value;
   endereco   = document.cad.endereco.value;
   complemento= document.cad.complemento.value;
   bairro     = document.cad.bairro.value;
   cidade     = document.cad.cidade.value;
   cep        = document.cad.cep.value;
   UF         = document.cad.UF.value;
   celular    = document.cad.celular.value;
   residencial= document.cad.residencial.value;
   comercial  = document.cad.comercial.value;
   email      = document.cad.email.value;

   if (nome==""){
      alert("FAVOR INFORMAR O NOME COMPLETO");
      document.cad.nome.focus();
      return;
   }
   if (cpf==""){
      alert("FAVOR INFORMAR O NÚMERO DO CPF");
      document.cad.cpf.focus();
      return;
   }
   if (rg==""){
      alert("FAVOR INFORMAR O NÚMERO DO RG");
      document.cad.rg.focus();
      return;
   }
   if (funcao==""){
      alert("FAVOR INFORMAR O CAMPO PROFISSÃO");
      document.cad.funcao.focus();
      return;
   }
   if (nasc==""){
      alert("FAVOR INFORMAR O DATA DE NASCIMENTO");
      document.cad.nasc.focus();
      return;
   }
   if (sexo==""){
      alert("SELECIONE CAMPO SEXO");
      document.cad.sexo.focus();
      return;
   }
   if (ecivil==""){
      alert("SELECIONE CAMPO ESTADO CÍVIL");
      document.cad.ecivil.focus();
      return;
   }

   param = "&id="+id_curso+"&nome="+nome+"&funcao="+funcao+"&conselho="+conselho+
   "&inscricao="+inscricao+"&nasc="+nasc+"&sexo="+sexo+"&ecivil="+ecivil+
   "&rg="+rg+"&data_exp="+data_exp+"&cpf="+cpf+"&pis="+pis+"&titulo="+titulo+
   "&zona="+zona+"&secao="+secao+"&cnh="+cnh+"&categ="+categ+
   "&validade="+validade+"&endereco="+endereco+"&comp="+complemento+
   "&bairro="+bairro+"&cidade="+cidade+"&cep="+cep+"&UF="+UF+
   "&celular="+celular+"&resid="+residencial+"&comercial="+comercial+
   "&email="+email;
   
   xmlHttpReq.open('POST', 'post_inscricao.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {

   if (xmlHttpReq.readyState == 4) {
      document.getElementById("main").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send(param);
}

function inscricao(id,tema){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'ficha_inscricao.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("main").innerHTML = xmlHttpReq.responseText;
      setTimeout("document.cad.nome.focus();",500);
   }
  }
  xmlHttpReq.send("i=23&id="+id+"&tema="+tema);
}

function enviar_contato(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }

      if (document.cad.nome.value==""){
         alert('Favor informar campo nome');
         document.cad.nome.focus();
         return false;
      }
      if (document.cad.assunto.value==""){
         alert('Favor informar o campo assunto');
         document.cad.assunto.focus();
         return false;
      }
      if (document.cad.comentario.value==""){
         alert('Favor descrever texto de comentário');
         document.cad.comentario.focus();
         return false;
      }

   document.getElementById("msg").innerHTML = "<font face='arial' size=8>Enviando contato...</font>";

   param = "nome="+document.cad.nome.value+"&email="+document.cad.email.value+
           "&telefone="+document.cad.telefone.value+"&assunto="+document.cad.assunto.value+
           "&comentario="+document.cad.comentario.value;

   xmlHttpReq.open('POST', 'email.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("msg").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send(param);
}

////////////////////////////////////////////////////// PEOPLE ACESS
function logar(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   if (document.log.login.value=="" || document.log.pws.value==""){
      return;
   }
   xmlHttpReq.open('POST', 'acesso.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      ret = xmlHttpReq.responseText;
  	  if (ret.indexOf("naocon")>0){
         document.getElementById("msg").innerHTML = xmlHttpReq.responseText;
      }else{
         document.getElementById("main").innerHTML = xmlHttpReq.responseText;
      }
     }
   }
   xmlHttpReq.send("&login="+document.log.login.value+"&pws="+document.log.pws.value);
}

function new_people(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_people.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      document.getElementById("peop").style.visibility = "visible";
     }
   }
   xmlHttpReq.send();
}

function list_people(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_people.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function edit_people(u1){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_people.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      document.getElementById("peop").style.visibility = "visible";
     }
   }
   xmlHttpReq.send("u1="+u1);
}

function post_people(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   u1 = document.usu.id.value;
   u2 = document.usu.login.value;
   u3 = document.usu.pws.value;
   u4 = document.usu.nivel.value;

   if (u1>0){
      for (i=0;i<document.usu.acao.length;i++){
         if (document.usu.acao[i].checked)
            break;
      }
      u5 = document.usu.acao[i].value;
   }else{
      u5=0;
   }

   if (u2==""){
      alert("Favor informar nome de login");
      document.usu.login.value;
      return
   }
   if (u3==""){
      alert("Favor informar a senha");
      document.usu.pws.value;
      return
   }
   if (u4=="0"){
      alert("Favor selecionar o nível de permissão");
      document.usu.nivel.value;
      return
   }

   xmlHttpReq.open('POST', 'list_people.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send("u1="+u1+"&u2="+u2+"&u3="+u3+"&u4="+u4+"&u5="+u5);
}

////////////////////////////////////////////// NOTICIAS
function show_screen_noticia(){
  document.getElementById("noticia").style.visibility = "visible";
}

function new_noticia(){
  window.open("FCKeditor265/editor.php", "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=800, height=500 , top=100 , left=100");
}

function edit_noticia(n1){
  window.open("FCKeditor265/editor.php?id="+n1, "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=800, height=500 , top=100 , left=100");
}

function close_screen_noticia(){
  document.getElementById("noticia").style.visibility = "hidden";
}

function list_noticia(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_noticia.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function post_noticia(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   n1 = document.cad.id.value;
   n2 = document.cad.data.value;
   n3 = document.cad.titulo.value;
   n4 = document.cad.texto.value;
   n5 = 0;

   if (document.cad.publica.checked==true){
      n5 = 1;
   }

   if (n1>0){
      for (i=0;i<document.cad.acao.length;i++){
         if (document.cad.acao[i].checked)
            break;
      }
      n6 = document.cad.acao[i].value;
   }else{
      n6=0;
   }

   if (n2==""){
      alert("Favor informar a data de públicação");
      document.cad.data.value;
      return
   }
   if (n3==""){
      alert("Favor informar o título da notícia");
      document.cad.titulo.value;
      return
   }
   if (n4=="0"){
      alert("Favor escrever a nóticia");
      document.cad.texto.value;
      return
   }

   xmlHttpReq.open('POST', 'list_noticia.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send("n1="+n1+"&n2="+n2+"&n3="+n3+"&n4="+n4+"&n5="+n5+"&n6="+n6);
}

////////////////////////////////////////////// AULAS
function show_screen_aula(){
  document.getElementById("aula").style.visibility = "visible";
}

function new_aula(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_aula.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      document.getElementById("aula").style.visibility = "visible";
     }
   }
   xmlHttpReq.send();
}

function close_screen_aula(){
  document.getElementById("aula").style.visibility = "hidden";
}

function list_aula(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_aula.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function post_aula(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   a1 = document.cad.id.value;
   a2 = document.cad.data.value;
   a3 = document.cad.titulo.value;
   a4 = document.cad.tipo.value;
   a5 = document.cad.url.value;
   a7 = document.cad.arq.value;

   if (a1>0){
      for (i=0;i<document.cad.acao.length;i++){
         if (document.cad.acao[i].checked)
            break;
      }
      a6 = document.cad.acao[i].value;
   }else{
      a6=0;
   }

   if (a2==""){
      alert("Favor informar a data de públicação");
      document.cad.data.value;
      return
   }
   if (a3==""){
      alert("Favor informar o título da aula");
      document.cad.titulo.value;
      return
   }

   xmlHttpReq.open('POST', 'list_aula.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send("a1="+a1+"&a2="+a2+"&a3="+a3+"&a4="+a4+"&a5="+a5+"&a6="+a6+"&a7="+a7);
}

function edit_aula(a1){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_aula.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_aula();
     }
   }
   xmlHttpReq.send("a1="+a1);
}

function capa_aula(id){
  window.open("aulas/upload_capa.php?id="+id, "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=600, height=400 , top=200 , left=200");
}

function arq_aula(id){
  window.open("aulas/upload_arq.php?id="+id, "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=600, height=200 , top=200 , left=200");
}

function mostra_arquivo(fto){
  document.getElementById("img_arq").background=fto;
}

function download(arq){
  window.open("aulas/download.php?arq="+arq, "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=10, height=10 , top=200 , left=200");
}

function curso_url(){
   document.location.href="http://localhost:8080/site/index.php?i=4&p=0";  
}

function escolha_tipo(tp){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'select_aulas.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_aula();
     }
   }
   xmlHttpReq.send("tipo="+tp);
}

////////////////////////////////////////////// CADASTRO
function list_cadastro(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_cadastro.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function show_screen_cadf(){
  document.getElementById("cadf").style.visibility = "visible";
}

function close_screen_cadf(){
  document.getElementById("cadf").style.visibility = "hidden";
}

function edit_cadastro(c1){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_cadastro.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_cadf();
     }
   }
   xmlHttpReq.send("c1="+c1);
}

function post_cadastro(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   c1 = document.cad.id.value;
   c2 = document.cad.data.value;
   c3 = document.cad.solicitante.value;
   c4 = document.cad.email.value;
   c5 = document.cad.telefone.value;
   c6 = document.cad.base.value;
   c7 = document.cad.login.value;
   c8 = document.cad.senha.value;
   c9 = document.cad.autoriza.value;
   if (document.cad.autoriza.checked==false){
      c9=0;
   }

   if (c1>0){
      for (i=0;i<document.cad.acao.length;i++){
         if (document.cad.acao[i].checked)
            break;
      }
      c10 = document.cad.acao[i].value;
   }else{
      c10 = 0;
   }
   c11 = 0;

   if (c3==""){
      alert("Favor informar o nome do solicitante");
      document.cad.solicitante.value;
      return
   }
   if (c4==""){
      alert("Favor informar email");
      document.cad.email.value;
      return
   }
   if (c8==""){
      alert("Favor informar senha de autorização");
      return
   }

   if (c10==0){ c11=1; }

   param = "c1="+c1+"&c2="+c2+"&c3="+c3+"&c4="+c4+"&c5="+c5+
           "&c6="+c6+"&c7="+c7+"&c8="+c8+"&c9="+c9+"&c10="+c10+"&c11="+c11;

   if (c10==1){
      document.getElementById("msg").style.visibility = "visible";
   }

   xmlHttpReq.open('POST', 'list_cadastro.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send(param);
}

function new_cadastro(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_cadastro.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_cadf();
     }
   }
   xmlHttpReq.send();
}

function cadastro(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'cadastro.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("doc").innerHTML = xmlHttpReq.responseText;
      setTimeout("document.cad.nome.focus()",500);
     }
   }
   xmlHttpReq.send();
}

function enviar_cad(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return
   }

   if (document.cad.nome.value==""){
      alert('Favor informar campo nome');
      document.cad.nome.focus();
      return
   }
   if (document.cad.email.value==""){
      alert('Favor informar campo email');
      document.cad.email.focus();
      return
   }
   if (document.cad.base.value=="0"){
      alert('Favor selecionar a Base de trabalho');
      document.cad.base.focus();
      return
   }

   document.getElementById("msg").style.visibility = "visible";
   document.getElementById("btn").disabled=true;

   param = "nome="+document.cad.nome.value+"&email="+document.cad.email.value+
           "&telefone="+document.cad.telefone.value+"&base="+document.cad.base.value;

   xmlHttpReq.open('POST', 'cadastro.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("doc").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send(param);
}


function voltar_form(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'formularios.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("doc").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function cod_base(){
  document.cad.senha.value=Math.round(Math.random() * 1000000);
}

function acessar_form(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }

   if (document.cad.nome.value==''){
      return
   }
   if (document.cad.senha.value==''){
      return
   }

   param = "nome="+document.cad.nome.value+"&senha="+document.cad.senha.value
           "&btn="+document.cad.btn.value ;

   xmlHttpReq.open('POST', 'formularios.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("doc").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send(param);
}


////////////////////////////////////////////// CURSO
function list_curso(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_cursos.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}


function show_screen_curso(){
  document.getElementById("cadc").style.visibility = "visible";
}

function close_screen_curso(){
  document.getElementById("cadc").style.visibility = "hidden";
}

function new_curso(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_cursos.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_curso();
     }
   }
   xmlHttpReq.send();
}

function edit_curso(c1){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_cursos.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_curso();
     }
   }
   xmlHttpReq.send("c1="+c1);
}


function post_curso(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   c1 = document.cad.id.value;
   c2 = document.cad.tema.value;
   c3 = document.cad.inicio.value;
   c4 = document.cad.terminio.value;
   c5 = document.cad.vagas.value;
   c6 = document.cad.carga_hora.value;
   c7 = document.cad.objetivo.value;

   if (c1>0){
      for (i=0;i<document.cad.acao.length;i++){
         if (document.cad.acao[i].checked)
            break;
      }
      c8 = document.cad.acao[i].value;
   }else{
      c8 = 0;
   }

   if (c2==""){
      alert("Favor informar o nome do tema do curso");
      document.cad.tema.focus();
      return
   }
   if (c3==""){
      alert("Favor informar a data de início do curso");
      document.cad.inicio.focus();
      return
   }
   if (c4==""){
      alert("Favor informar a data de termínio do curso");
      document.cad.terminio.focus();
      return
   }
   if (c5==""){
      alert("Favor informar o número de vagas");
      document.cad.vagas.focus();
      return
   }
   if (c6==""){
      alert("Favor informar o número de Carga Horária");
      document.cad.carga_hora.focus();
      return
   }

   param = "c1="+c1+"&c2="+c2+"&c3="+c3+"&c4="+c4+"&c5="+c5+
           "&c6="+c6+"&c7="+c7+"&c8="+c8;

   xmlHttpReq.open('POST', 'list_cursos.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send(param);
}

////////////////////////////////////////////// FORMULARIO
function show_screen_form(){
  document.getElementById("frm").style.visibility = "visible";
}

function new_form(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_formulario.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      document.getElementById("frm").style.visibility = "visible";
     }
   }
   xmlHttpReq.send();
}

function close_screen_form(){
  document.getElementById("frm").style.visibility = "hidden";
}

function list_formulario(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_formulario.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function post_form(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   f1 = document.cad.id.value;
   f2 = document.cad.data.value;
   f3 = document.cad.titulo.value;
   f4 = document.cad.tipo.value;

   if (f1>0){
      for (i=0;i<document.cad.acao.length;i++){
         if (document.cad.acao[i].checked)
            break;
      }
      f5 = document.cad.acao[i].value;
   }else{
      f5=0;
   }

   if (f3==""){
      alert("Favor informar o título do formulário");
      document.cad.titulo.value;
      return
   }

   xmlHttpReq.open('POST', 'list_formulario.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send("f1="+f1+"&f2="+f2+"&f3="+f3+"&f4="+f4+"&f5="+f5);
}

function edit_form(f1){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_formulario.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_form();
     }
   }
   xmlHttpReq.send("f1="+f1);
}

function arq_form(id){
  window.open("formularios/upload_arq.php?id="+id, "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=600, height=200 , top=200 , left=200");
}

function down_form(arq){
  window.open("formularios/download.php?arq="+arq, "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=10, height=10 , top=200 , left=200");
}

////////////////////////////////////////////// LEGISLAÇÃO
function show_screen_legis(){
  document.getElementById("legis").style.visibility = "visible";
}

function new_legis(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_legislacao.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      document.getElementById("legis").style.visibility = "visible";
     }
   }
   xmlHttpReq.send();
}

function close_screen_legis(){
  document.getElementById("legis").style.visibility = "hidden";
}

function list_legislacao(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_legislacao.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function post_legis(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   l1 = document.cad.id.value;
   l2 = document.cad.titulo.value;
   l3 = document.cad.classe.value;

   if (l1>0){
      for (i=0;i<document.cad.acao.length;i++){
         if (document.cad.acao[i].checked)
            break;
      }
      l4 = document.cad.acao[i].value;
   }else{
      l4=0;
   }

   if (l2==""){
      alert("Favor informar o título do formulário");
      document.cad.titulo.value;
      return
   }

   xmlHttpReq.open('POST', 'list_legislacao.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send("l1="+l1+"&l2="+l2+"&l3="+l3+"&l4="+l4);
}

function edit_legis(l1){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_legislacao.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_legis();
     }
   }
   xmlHttpReq.send("l1="+l1);
}

function arq_legis(id){
  window.open("legislacao/upload_arq.php?id="+id, "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=600, height=200 , top=200 , left=200");
}

function down_legis(arq){
  window.open("legislacao/download.php?arq="+arq, "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=10, height=10 , top=200 , left=200");
}

////////////////////////////////////////////// LICITAÇÕES
function show_screen_licita(){
  document.getElementById("licita").style.visibility = "visible";
}

function new_licita(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_licitacoes.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      document.getElementById("licita").style.visibility = "visible";
     }
   }
   xmlHttpReq.send();
}

function close_screen_licita(){
  document.getElementById("licita").style.visibility = "hidden";
}

function list_licitacoes(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_licitacoes.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function post_licita(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }

   id         = document.cad.id.value;
   licitacao  = document.cad.licitacao.value;
   resumo     = document.cad.resumo.value;
   cliente    = document.cad.cliente.value;
   pregoeiro  = document.cad.pregoeiro.value;
   edital     = document.cad.edital.value;
   processo   = document.cad.processo.value;
   modalidade = document.cad.modalidade.value;
   tipo       = document.cad.tipo.value;
   fornecedor = document.cad.fornecedor.value;
   impugna    = document.cad.impugna.value;
   situacao   = document.cad.situacao.value;
   inicio     = document.cad.inicio.value;
   limite     = document.cad.limite.value;
   abertura   = document.cad.abertura.value;
   publicacao = document.cad.publicacao.value;
   data_hora  = document.cad.data_hora.value;

   url        = document.cad.url.value;
   url        = url.replace("&","#");
   acao       = document.cad.acao.value;

   if (document.cad.acao.length>0){
     acao = 0;
     for(var i = 0; i < 2; i++) {
		if(document.cad.acao[i].checked) {
			acao = document.cad.acao[i].value;
		}
     }
  }else{
     acao = document.cad.acao.value;
  }

   if (licitacao==""){
      alert("INFORME O NÚMERO DA LICITAÇÃO");
      document.cad.licitacao.value;
      return
   }

   if (resumo==""){
      alert("DESCREVA UM BREVE RESUMO DA LICITAÇÃO");
      document.cad.titulo.value;
      return
   }

   if (edital==""){
      alert("INFORME O NÚMERO DO EDITAL");
      document.cad.edital.value;
      return
   }

   param = "id="+id+"&licitacao="+licitacao+"&resumo="+resumo+
           "&cliente="+cliente+"&pregoeiro="+pregoeiro+
           "&edital="+edital+"&processo="+processo+
           "&modalidade="+modalidade+"&tipo="+tipo+
           "&fornecedor="+fornecedor+"&impugna="+impugna+
           "&situacao="+situacao+"&inicio="+inicio+
           "&limite="+limite+"&abertura="+abertura+
           "&data_hora="+data_hora+"&acao="+acao+
           "&publicacao="+publicacao+"&url="+url;

   xmlHttpReq.open('POST', 'list_licitacoes.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send(param);
}

function edit_licita(id){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_licitacoes.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_licita();
     }
   }
   xmlHttpReq.send("id="+id);
}

////////////////////////////////////////////// BANNER
function show_screen_banner(){
  document.getElementById("bann").style.visibility = "visible";
}

function new_banner(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_banner.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      document.getElementById("bann").style.visibility = "visible";
     }
   }
   xmlHttpReq.send();
}

function close_screen_banner(){
  document.getElementById("bann").style.visibility = "hidden";
}

function list_banner(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_banner.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function post_banner(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   b1 = document.cad.id.value;
   b2 = document.cad.comenta.value;
   b3 = document.cad.url.value;

   if (b1>0){
      for (i=0;i<document.cad.acao.length;i++){
         if (document.cad.acao[i].checked)
            break;
      }
      b4 = document.cad.acao[i].value;
   }else{
      b4=0;
   }

   if (b2==""){
      alert("Descreva um breve comentário sobre o banner");
      document.cad.comenta.value;
      return
   }
   if (b3==""){
      alert("Favor informar a URL do banner");
      document.cad.url.value;
      return
   }

   xmlHttpReq.open('POST', 'list_banner.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send("b1="+b1+"&b2="+b2+"&b3="+b3+"&b4="+b4);
}

function edit_banner(b1){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_banner.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      show_screen_banner();
     }
   }
   xmlHttpReq.send("b1="+b1);
}

function arq_banner(id){
  window.open("banner/upload_arq.php?id="+id, "SAMU192" , "statusbar=no , scrollbars=no, Toolbar=no ,width=600, height=200 , top=200 , left=200");
}

////////////////////////////////////////////////////// DIRIGENTES
function list_dirigente(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_dirigentes.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send();
}

function edit_dirigente(d1){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   xmlHttpReq.open('POST', 'list_dirigentes.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
      document.getElementById("dir").style.visibility = "visible";
     }
   }
   xmlHttpReq.send("d1="+d1);
}

function post_dirigente(){
   xmlHttpReq = GetXmlHttpObject();
   if (xmlHttpReq == null) {
      alert ("Seu Browser não suporta AJAX!");
      return;
   }
   d1 = document.usu.id.value;
   d2 = document.usu.nome.value;

   if (d2==""){
      alert("Favor informar nome do dirigente");
      document.usu.nome.value;
      return
   }

   xmlHttpReq.open('POST', 'list_dirigentes.php', true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      document.getElementById("area").innerHTML = xmlHttpReq.responseText;
     }
   }
   xmlHttpReq.send("d1="+d1+"&d2="+d2+"&d3=1");
}

function veja_cpf(id,cfc){
  xmlHttpReq = GetXmlHttpObject();
  if (xmlHttpReq == null) {
     alert ("Seu Browser não suporta AJAX!");
     return;
  }

  if (valida_cpf(cfc)==false || cfc==""){
     return
  }

  xmlHttpReq.open('POST', 'veja_CPF.php', true);
  xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttpReq.onreadystatechange = function() {
  if (xmlHttpReq.readyState == 4) {
     ret = xmlHttpReq.responseText;
  	 if (ret.indexOf("!!!")>0){
        alert(xmlHttpReq.responseText);
        layer.cad.cpf.focus();
        document.cad.getElementById("cpf").focus();
        return false;
     }
   }
 }
 xmlHttpReq.send("cpf="+cfc+"&id="+id);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
function mOverNav(navTD, caption){if (!navTD.contains(event.fromElement)){navTD.style.backgroundColor='#FFE2C6';navTD.style.cursor='hand';window.status=caption;}}
function mOutNav(navTD, caption){if (!navTD.contains(event.toElement)) {navTD.style.backgroundColor='#FFFFFF';window.status=caption;}}

function abre(link){
  var w = 950; /*largura*/
  var h = 600; /*altura*/
  var x = (screen.width-w)/2;
  var y = (screen.height-h)/2;
  tit = link.replace("=","");
  tit = tit.replace("/","");
  tit = tit.replace("&","");
  tit = tit.replace("_","");
  tit = tit.replace("=","");
  tit = tit.replace(".","");
  window.open(link,tit, "height="+h+", width="+w+", top="+y+", left="+x+", scrollbars=yes");
}

function valida_cpf(cfc){
  var i;
  s = cfc;
  if (cfc==""){
     return
  }
  var c = s.substr(0,9);
  var dv = s.substr(9,2);
  var d1 = 0;
  for (i = 0; i < 9; i++){
     d1 += c.charAt(i)*(10-i);
  }
  if (d1 == 0){
     alert("CPF Invalido")
     document.getElementById('cpf').focus();
     return false;
  }
  d1 = 11 - (d1 % 11);
  if (d1 > 9) d1 = 0;
  if (dv.charAt(0) != d1){
     alert("CPF Invalido")
     document.getElementById('cpf').focus();
     return false;
  }

  d1 *= 2;
  for (i = 0; i < 9; i++){
      d1 += c.charAt(i)*(11-i);
  }
  d1 = 11 - (d1 % 11);
  if (d1 > 9) d1 = 0;
  if (dv.charAt(1) != d1){
     alert("CPF Invalido")
     document.getElementById('cpf').focus();
     return false;
  }
  return true;
}


// Exemplo: onKeyPress="Mascara('CEP',this,event);"
function Mascara(tipo, campo, teclaPress) {
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}

	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');

	tam = s.length + 1;

	if ( tecla != 9 && tecla != 8 ) {
		switch (tipo)
		{
		case 'CPF' :
			if (tam > 3 && tam < 7)
				campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
			if (tam >= 7 && tam < 10)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
		break;

		case 'CNPJ' :

			if (tam > 2 && tam < 6)
				campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
			if (tam >= 6 && tam < 9)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
			if (tam >= 9 && tam < 13)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
			if (tam >= 13 && tam < 15)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
		break;

		case 'TEL' :
			if (tam > 2 && tam < 4)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
			if (tam >= 7 && tam < 11)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
		break;

		case 'DATA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
			if (tam > 4 && tam < 11)
				campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
		break;

		case 'HORA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + ':' + s.substr(2, tam);
			if (tam > 3 && tam < 5)
				campo.value = s.substr(0,2) + ':' + s.substr(2,2);
		break;

		case 'CEP' :
			if (tam > 5 && tam < 7)
				campo.value = s.substr(0,5) + '-' + s.substr(6, tam);
			if (tam > 7 && tam < 9)
				campo.value = s.substr(0,5) + '-' + s.substr(5,tam-3);
		break;
		}
	}
}

//===== so mascaras =========
// Exemplo: OnKeyUp="Mascara_Hora(this.value, this)"
 function Mascara_Hora(Hora, campo){
    var hora01 = '';
    hora01 = hora01 + Hora;
    if (hora01.length == 2){
       hora01 = hora01 + ':';
       campo.value = hora01;
    }
    if (hora01.length == 5){
       Verifica_Hora(campo);
    }
 }

 function Verifica_Hora(campo){
    hrs = (campo.value.substring(0,2));
    min = (campo.value.substring(3,5));
    estado = "";
    if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59)){
       estado = "errada";
    }

    if (campo.value == "") {
       estado = "errada";
    }
    if (estado == "errada") {
       alert("Hora invalida!");
       campo.value="";
       campo.focus();
    }
 }

//   onblur="return validaDat(this,this.value)"
function validaData(campo,valor) {
	var date=valor;
	var ardt=new Array;
	var ExpReg=new RegExp("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}");
	if (campo.value==""){
       return true;
    }
	ardt=date.split("/");
	erro=false;
	if ( date.search(ExpReg)==-1){
		erro = true;
		}
	else if (((ardt[1]==4)||(ardt[1]==6)||(ardt[1]==9)||(ardt[1]==11))&&(ardt[0]>30))
		erro = true;
	else if ( ardt[1]==2) {
		if ((ardt[0]>28)&&((ardt[2]%4)!=0))
			erro = true;
		if ((ardt[0]>29)&&((ardt[2]%4)==0))
			erro = true;
	}
	if (erro) {
		alert("\"" + valor + "\" não é uma data válida!!!");
		campo.focus();
		campo.value = "";
		return false;
	}
	return true;
}

function SomenteNumero(e){
  var tecla=(window.event)?event.keyCode:e.which;
  if((tecla > 47 && tecla < 58)) return true;
  else{
    if (tecla != 8) return false;
    else return true;
   }
}

function seta_focus_login(){
  if (document.acess.login.value!=""){
     document.acess.senha.focus();
  }else{
     document.acess.login.focus();
  }
}

//
// CONVERTE ENTER PARA TAB
// exemplo: onkeypress="return handleEnter(this, event)" ;
function handleEnter (field, event) {
   var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if (keyCode == 13) {
    var i;
  for (i = 0; i < field.form.elements.length; i++)
     if (field == field.form.elements[i])
       break;
       i = (i + 1) % field.form.elements.length;
       field.form.elements[i].focus();
       return false;
    }
   else
     return true;
}

