/* Início do script exibição de fotos */
 function exibir_foto(imagem)
   {
    foto = new Image();
	foto.src = imagem;
   }
/* Fim do Início do script formatação de texto */

/* Início do script formatação de texto */
 function selecao(posicaoCursor) 
   { if (posicaoCursor.createTextRange) posicaoCursor.caretPos = document.selection.createRange().duplicate(); }
 function inserirCodigo(startcode,endcode)
   {
    var elem = document.form_cad_noticia.txt_noticia;
    var selecao = document.selection.createRange();
    var texto = selecao.text;
    var caretPos = elem.caretPos;	
  
    caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? startcode + texto + endcode : startcode + texto + endcode;
   }
/* Fim do script formatação de texto */

/* Início do script data */ 
 function data()
   {
    hoje = new Date();
    dia  = hoje.getDate();
    diaS = hoje.getDay();
    mes  = hoje.getMonth();
    ano  = hoje.getFullYear();
    hora = hoje.getHours();
    minu = hoje.getMinutes();
    if ((hora >= 0) && (minu >= 0) && (hora < 12) && (minu <= 59))  { saudacao = "Bom Dia! ";   }
	if ((hora >= 12) && (minu >= 0) && (hora < 18) && (minu <= 59)) { saudacao = "Boa Tarde! "; }
	if ((hora >= 18) && (minu >= 0)) { saudacao = "Boa Noite! "; }
	diaSemana = ["Domingo","Segunda-Feira","Terça-Feira","Quarta-Feira","Quinta-Feira","Sexta-Feira","Sábado"];
	nomeMes   = ["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"];
    document.write(saudacao+"Hoje é: "+diaSemana[diaS]+" / "+dia+" de "+nomeMes[mes]+" de "+ano+" <br>");
   }
/* Fim do script data */

/* Início do script de efeito rollover */
 ponto_out      = new Image();
 ponto_out.src  = "imagens/ponto_out.jpg";
 ponto_over     = new Image();
 ponto_over.src = "imagens/ponto_over.jpg";
/* Fim do script de efeito rollover */ 

/* Início do script de sub_menu */
 ativo = null;
 tempo = null;
 document.onclick = new Function("exibir();");
 function exibir(obj)
   {
    menu = document.getElementById(obj);
    if (ativo != null) { ativo.style.visibility = "hidden"; ativo = null; }
	if (tempo != null) { clearTimeout(tempo); }
	if (menu)          { menu.style.visibility = "visible"; ativo = menu; }
   }
 function ocultar()
   {
    if (ativo)
	  { tempo = setTimeout("ativo.style.visibility = 'hidden'; ativo = null; tempo = null;",3000); }
   }
/* Fim do script de sub_menu */

/* Tratamento de data */
 function barra(obj,evento)
   {
    if (obj == "txt_data")
	  { d = document.frm_eventos.txt_data; }
	evento = (evento) ? evento : window.event
	var charCode = (evento.which) ? evento.which : evento.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) 
	  {
	   window.status = "Este campo aceita apenas números!";
	   return false;
	  }
	if (d.value.length == 2)
	  {
	   var dia = d.value.substring(0,2);
       if ((dia > 0) && (dia <= 31))
	     { 
          d.value += "/";
		  return true;
		 }
	   else
	     {
		  alert("Valor inválido para o dia!");
		  return false;
		 }
	  }
	if (d.value.length == 5)
      {
	   var mes = d.value.substring(5,3);
	   if ((mes > 0) && (mes <= 12))
	     {
		  d.value += "/";
		  return true;
		 }
	   else
	     {
		  alert("Valor inválido para o mês!");
		  return false;
		 }
	  }
	if (d.value.length == 9)
	  {
	   var ano = d.value.substring(6,10);
	   if ((ano < 190) || (ano > 200))
	     {
		  alert("Valor inválido para o ano!");
		  return false;
		 }
	  }
   }
/* Fim do script de tratamento */

/* Tratamento de fone */
 function divisao(campo,evento)
   {
    if (campo == "txt_fone")
	  { d = document.form_mat_reg.txt_fone; }
	if (campo == "txt_celular")
	  { d = document.form_mat_reg.txt_celular; }
	if (campo == "txt_fone_frm2")
	  { d = document.form_mat_prof_mod.txt_fone_frm2; }
	if (campo == "txt_fone02_frm2")
	  { d = document.form_mat_prof_mod.txt_fone02_frm2; }
	evento = (evento) ? evento : window.event
	var charCode = (evento.which) ? evento.which : evento.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) 
	  {
	   window.status = "Este campo aceita apenas números!";
	   return false;
	  }
    else if (d.value.length == 2)
	    { d.value = "(" + d.value + ")"; return true; }
	else if (d.value.length == 8)
	    { d.value += "-"; return true; }
   }
	 
/* Fim do tratamento de fone */

/* Testar campos formulário matrícula regular */
 function testar(formulario)
   {
    if (formulario == "form_mat_reg")
	  {
       d = document.form_mat_reg;
       campos = ["Ensino","Nome do Aluno","Data de Nascimento","Naturalidade","Sexo","Nome do Pai","Nome da Mãe","Reg. de Nascismento","N° da Folha","N° do Livro","Cartório","Comarca","Emissão de Registro","Endereço","Bairro","Fone","Celular","E-Mail","Ano","Série","Curso","Responsável","Senha"];
       tipo_v = ["n","n","n","n","n","n","n","s","s","s","s","s","s","n","n","s","s","n","n","n","n","n","n"];
       tipo_t = ["s","s","s","s","s","s","s","n","n","n","s","s","s","s","s","s","s","s","n","s","s","s","n"];
	  }
	if (formulario == "form_mat_prof_mod")
	  {
	   d = document.form_mat_prof_mod;
	   campos = ["Curso","Nome","RG. N°","Org. Emissor","Data de Emissão","CPF","Data de Emissão","Endereço","Bairro","Telefone","Data de Nasc.","Naturalidade","Estado Civil","Nome do Pai","Nome da Mãe","Local de Trabalho","Telefone","Profissão","Cargo","Conhecimento através:","Quem indicou:","login","Senha"];
	   tipo_v = ["n","n","n","n","n","n","n","n","n","s","n","n","n","n","n","s","s","s","s","n","s","n","n","s"];
	   tipo_t = ["s","s","n","s","s","n","s","s","s","s","s","s","s","s","s","s","s","s","s","s","s","s","s","s"];
	  }
	for (var i = 0; i < d.elements.length; i++)
	   {
        if (d.elements[i].value == "")
		  {
		   if (tipo_v[i] == "n")
		     {
			  alert("O campo "+campos[i]+" não pode ficar vazio!");
			  d.elements[i].focus();
			  return true;
			 }
		  }
		if (d.elements[i].value != "")
		  {
		   if (tipo_t[i] == "s")
		     {
		      if (!isNaN(d.elements[i].value))
		        {
			     alert("O campo "+campos[i]+" não pode conter números!");
			     d.elements[i].select();
			     return true;
			    }
		     }
		   if (tipo_t[i] == "n")
		     {
		      if (isNaN(d.elements[i].value))
		        {
			     alert("O campo "+campos[i]+" não pode conter letras!");
			     d.elements[i].select();
			     return true;
			    }
		     }
		  }
	   }
	 if (d.pas_senha.value != d.pas_conf.value)
	   {
	    alert("A confirmação de senha está incorreta!");
		d.pas_conf.value.select();
		return true;
	   }
	 d.submit();
   }

/* Fim de teste campos formulário matrícula regular */

/* Testar validade de cpf */

  function cpf()
    {
	 d = document.form_mat_prof_mod;
	 cpfInv = ["00000000000","11111111111","22222222222","33333333333","44444444444","55555555555","66666666666","77777777777","88888888888","99999999999"];
	 if (d.txt_cpf.value != "")
	   {
	    if (isNaN(d.txt_cpf.value))
	      {
	       alert("O campo CPF não pode conter letras!");
		   d.txt_cpf.select();
		   return true;
	      }
	    if (d.txt_cpf.value.length < 11)
	      {
	       alert("O campo CPF deve conter 11 dígitos!\n\nVocê digitou apenas "+d.txt_cpf.value.length+" dígitos!");
		   d.txt_cpf.select();
		   return true;
	      }
	   }
	 for (var i = 0; i < cpfInv.length; i++)
	    {
		 if (d.txt_cpf.value == cpfInv[i])
		   {
		    alert("CPF inválido!");
			d.txt_cpf.select();
			return true;
			break;
		   }
		}
	 var a = [];
	 var b = new Number;
	 var c = 11;
	 for (var y = 0; y < 11; y++)
	    {
		 a[y] = d.txt_cpf.value.charAt(y);
		 if (y < 9)
		   {
		    b += (a[y] * --c);
		   }
		}
	 if ((x10 = (b % 11)) < 2)
	   { x10 = 0; }
	 else
	   { x10 = 11 - x10; }
	 b = 0;
	 c = 11;
	 for (var q = 0; q < 11; q++)
	    {
		 a[q] = d.txt_cpf.value.charAt(q);
		 if (q < 10)
		   {
		    b += (a[q] * c--);
		   }
		}
	 if ((x11 = (b % 11)) < 2)
	   {
	    x11 = 0;
	   }
	 else
	   {
	    x11 = 11 - x11;
	   }
	 if ((x10 != a[9]) || (x11 != a[10]))
	   {
	    alert("CPF inválido!");
		d.txt_cpf.select();
		return true;
	   }
	}

/* Fim do teste de validade do cpf */