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='http://174.123.210.242/~samu192/admin.php'",500);
     }
  }
  xmlHttpReq.send();
}

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;

   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);
}

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 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);
}


////////////////////////////////////////////// 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;
   }

   l1 = document.cad.id.value;
   l2 = document.cad.data.value;
   l3 = document.cad.titulo.value;
   l4 = document.cad.resumo.value;
   l5 = document.cad.url.value;
   l5 = l5.replace("&","#");

   l6 = 0;

   if (document.cad.publica.checked==true){
      l6 = 1;
   }

   if (l1>0){
      for (i=0;i<document.cad.acao.length;i++){
         if (document.cad.acao[i].checked)
            break;
      }
      l7 = document.cad.acao[i].value;
   }else{
      l7=0;
   }

   if (l2==""){
      alert("Informe a Data da licitação");
      document.cad.data.value;
      return
   }

   if (l3==""){
      alert("Informe o título da licitação");
      document.cad.titulo.value;
      return
   }

   if (l4==""){
      alert("Descreva um breve resumo da licitação");
      document.cad.resumo.value;
      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("l1="+l1+"&l2="+l2+"&l3="+l3+"&l4="+l4+"&l5="+l5+"&l6="+l6+"&l7="+l7);
}

function edit_licita(l1){
   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("l1="+l1);
}

////////////////////////////////////////////// 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 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");
}

// 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;
}
