// JavaScript Document

	menuOpen=Array();
	function changeMenu(id, name)
	{
		if(menuOpen[id]==0 || menuOpen[id]==undefined)
		{
			document.getElementById('menu_img_'+id).src=name+'';
			document.getElementById('menuSource_'+id).style.display="block";
			menuOpen[id]=1;
		}
		else
		{
			document.getElementById('menu_img_'+id).src=name+'';
			document.getElementById('menuSource_'+id).style.display="none";
			menuOpen[id]=0;
		}
	}
	
	function postado()
 {
	  var aviso="";
	  var erro=0;
	  var matricula=document.getElementById("codigo").value;
	  var cpf=document.getElementById("cpf").value;
	 if(matricula==""||cpf==""){
	   erro++;
	   }
	   var dia=document.getElementById("dia").value;
	   var mes=document.getElementById("mes").value;
	   var ano=document.getElementById("ano").value;
	   if ((ano % 4 == 0 && ano % 100 != 0) || (ano % 400 == 0))
       	var bissexto=1;
	   if ((dia == 31) && (mes == 4 || mes == 6 || mes == 9 || mes == 11))
	     {
		   erro++;
		  }
	   if ((dia==29 && mes==2 && bissexto!=1)||(dia>29 && mes==2))
	      {
		    erro++;
		  }
	   
	   if(erro!=0)
		  {
		   //document.getElementById("mensagens").style.display="block";
			document.getElementById("mensagens").innerHTML="<p><div style=' margin-left: 7px; margin-top: -7px; font-size: 9px;' align='justify'><font color='#ca2332'>Os Dados não Conferem!</font><br><br></div></p><p><div style=' margin-left: 7px; margin-top: -7px; font-size: 9px;' align='justify'>Preencha corretamente o formulário, só usando números.<br><br></div></p><p><div style=' margin-left: 7px; margin-top: -7px; font-size: 9px;' align='justify'>Para se cadastrar você deve ser aluno da instituição, e ter em mãos o seu número de matrícula.<br><br></div></p><p><div style=' margin-left: 7px; margin-top: -7px; font-size: 9px;' align='justify'>Caso não consiga a verificação de seus dados entre em contato com a recepção.<br></div></p>";
		  }
		  else
		  {
		    document.formulario.action="restrito.php?inserir=verifica&postagem=sim";
			document.formulario.submit();
		  }
 }

function numeros(e){
    var whichCode = (window.Event)? e.which : e.keyCode;
    if(whichCode>=48 && whichCode<=57 || whichCode==8 || whichCode==0 || whichCode==32) return true;
    return false;
  }
function Verifica_campo_cpf(campo)
  {
	var cpf = campo.value; // Recebe o valor digitado no campo
	// Aqui começa a checagem do cpf
	var POSICAO, I, SOMA, DV, DV_INFORMADO;
	var DIGITO = new Array(10);
	DV_INFORMADO = cpf.substr(9, 2); // Retira os dois últimos dígitos do número informado
	// Desemembra o número do cpf na array DIGITO
	for (I=0; I<=8; I++) {
	  DIGITO[I] = cpf.substr( I, 1);
	}
	// Calcula o valor do 10º dígito da verificação
	POSICAO = 10;
	SOMA = 0;
	   for (I=0; I<=8; I++) {
		  SOMA = SOMA + DIGITO[I] * POSICAO;
		  POSICAO = POSICAO - 1;
	   }
	DIGITO[9] = SOMA % 11;
	   if (DIGITO[9] < 2) {
			DIGITO[9] = 0;
	}
	   else{
		   DIGITO[9] = 11 - DIGITO[9];
	}
	// Calcula o valor do 11º dígito da verificação
	POSICAO = 11;
	SOMA = 0;
	   for (I=0; I<=9; I++) {
		  SOMA = SOMA + DIGITO[I] * POSICAO;
		  POSICAO = POSICAO - 1;
	   }
	DIGITO[10] = SOMA % 11;
	   if (DIGITO[10] < 2) {
			DIGITO[10] = 0;
	   }
	   else {
			DIGITO[10] = 11 - DIGITO[10];
	   }
	// Verifica se os valores dos dígitos verificadores conferem
	DV = DIGITO[9] * 10 + DIGITO[10];
	   if (DV != DV_INFORMADO) {
		  alert('cpf inválido');
		  campo.value = '';
		  campo.focus();
		  return false;
	   }
  }
  
function Comparasenha() {
	var d=document.getElementById("senha").value;
	var d1=document.getElementById("senha1").value;
	var erro=0;
	//validar senha
	if ((d == "") || (d.length < 4)){
		erro++;
	         alert("A Senha não pode ser vazia e deve conter mais de 3 caracteres!");
		}
	if(d != d1){
		erro++;
			alert("Os campos devem ser iguais!");
		}
		
	    //return false;
	if (erro==0){
			document.cadastro.action="restrito.php?inserir=cadastro&confirmado=ok";
			document.cadastro.submit();
		}
		d.focus();
}

function ErroSQL(){
	document.getElementById("mensagens").innerHTML="<p><div style=' margin-left: 7px; margin-top: -7px; font-size: 9px;' align='justify'><font color='#ca2332'>Os Dados não Conferem!</font><br><br></div></p><p><div style=' margin-left: 7px; margin-top: -7px; font-size: 9px;' align='justify'>Preencha corretamente o formulário, só usando números.<br><br></div></p><p><div style=' margin-left: 7px; margin-top: -7px; font-size: 9px;' align='justify'>Para se cadastrar você deve ser aluno da instituição, e ter em mãos o seu número de matrícula.<br><br></div></p><p><div style=' margin-left: 7px; margin-top: -7px; font-size: 9px;' align='justify'>Caso não consiga a verificação de seus dados entre em contato com a recepção.<br></div></p>";
}

//Crie IDs nos botões e troque os ids das chamadas nas funções
//No html os botões têm que ter no onClick=função('url','nomeDaDiv','id')
//Funções para formulários em uma DIV

function chamaajax(url,local){
    var secao = local;
    var tipoform = document.getElementById('chama_ajax').value;
    url = url + '?abrir=' + tipoform;
    if (document.getElementById) { //Verifica se o Browser suporta DHTML.
        if (window.XMLHttpRequest) {
            HttpReq = new XMLHttpRequest();
            HttpReq.onreadystatechange = XMLHttpRequestChange;
            HttpReq.open("GET", url, true);
            HttpReq.send(null);
        } else if (window.ActiveXObject) {
            HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            if (HttpReq) {
                HttpReq.onreadystatechange = XMLHttpRequestChange;
                HttpReq.open("GET", url, true);
                HttpReq.send();
            }
        }
    }
}

function GetXMLHttp(){
    if(navigator.appName == "Microsoft Internet Explorer"){
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}
var xmlRequest = GetXMLHttp();

function chamaajax(url,local,id){
    var secao = local;
    //var tipoform = document.getElementById('chama_ajax').value;
    url = url + '?abrir=' + id;
	xmlRequest.onreadystatechange = mudancaEstado;
	xmlRequest.open("GET",url,true);
	xmlRequest.send(null);

if (xmlRequest.readyState == 1){
	document.getElementById("divBoletimIndividual").innerHTML = "Carregando ";
	}
	return url;
}

function mudancaEstado(){
	if (xmlRequest.readyState == 4){
		document.getElementById("divBoletimIndividual").innerHTML = xmlRequest.responseText;
	 }
}
