// JavaScript Document
//Valida o formulário de Boletim
function ValidaBoletim() {
 if (document.formboletim.nomeboletim.value == "")  {
     alert ("Entre com nome");
	 document.formboletim.nomeboletim.focus();
	 return false;
 }
 if (document.formboletim.emailboletim.value == "")  {
     alert ("Entre com e-mail");
	 document.formboletim.emailboletim.focus();
	 return false;
 }
  if (document.formboletim.emailboletim.value != "")  {
     if (document.formboletim.emailboletim.value.indexOf('@',0)==-1)	{
		alert ("Entre com um e-mail válido !!!");
	    document.formboletim.emailboletim.focus();
	    return false;
     }
  }
  //document.form.submit();
  return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Excluir
function ApagaBoletim() {
 if (confirm("Deseja excluir?")){
   document.formboletim.opcboletim.value = "E";
   document.formboletim.submit();
 }  
 //alert(param);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Abre o Boletim
function Boletim(){
  location.href = "noticias.jsp?B=1";
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function MostraBoletim(){
 if (document.formEnviaBoletim.dtini.value == "")  {
     alert ("Entre com a data inicial");
	 document.formEnviaBoletim.dtini.focus();
	 return false;
 }
 if (document.formEnviaBoletim.dtfin.value == "")  {
     alert ("Entre com a data final");
	 document.formEnviaBoletim.dtfin.focus();
	 return false;
 }
 return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
//Envia o Boletim
function EnviaBoletim(caminho){
    marcado = -1;
	for (i=0; i<document.formEnviaBoletim.elements.length; i++) {
	     if( document.formEnviaBoletim.elements[i].type == "text" ) {
		    if (document.formEnviaBoletim.elements[i].name.substring(0,4) == "NTS_"){
		       if ( document.formEnviaBoletim.elements[i].value != ""){
		  	      marcado =1;
			   }	  
			}	  
		 } 
	}
	//alert(marcado);
	if (marcado == -1){
	   alert("Selecine a(s) mensagem(ns) para o boletim !!!");
    } else{
	   if (document.formEnviaBoletim.p_edicao.value == ""){
	      alert("Digite a seleção do boletim");
	   }else{	 
	      document.formEnviaBoletim.mesg.value = "[ Aguarde enviando... ]"; 
	      document.formEnviaBoletim.action = caminho+"/enviaboletim";
	      document.formEnviaBoletim.submit();
	   }	  
	}	   
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function colocadataBoletim(campo,e) {
  var vr = campo.value;
  var hoje = new Date();
  var ok = false;
  if (vr == "") {
   ok = true;
  } else {
	  if (vr.length == 8){
		 dia = vr.substring(0,2);
		 mes = vr.substring(2,4);
		 ano = vr.substring(4,8);
		 diaatual = hoje.getDate();
		 mesatual = hoje.getMonth()+1;
		 anoatual = hoje.getFullYear();
		  if (mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12) var dmax = 31;
		  else if(mes==4 || mes==6 || mes==9 || mes==11) dmax = 30;
		  else if((ano%400==0) || (ano%4==0 && ano%100!=0)) dmax = 29;
		  else dmax = 28;			  			   
		  if ( (dia > dmax) || (mes > 12)){
		     alert( "[ Data inválida ]");
			 campo.focus();
		     ok = false;
		  } else{
			 vr = vr.substring(0,2)+"/"+vr.substring(2,4)+"/"+vr.substring(4,8); 
		     ok = true;
		  }
	  }	else {
		 alert("[ Data inválida ]");
		 campo.focus();
		 ok = false;
	  } 
  }
  campo.value = vr;
  return ok;
}


//Retira a formatação da data
function retiradataBoletim(campo,e) {
  var vr = campo.value;
  if (vr != ""){
    vr = vr.replace("/","");
	vr = vr.replace("/","");	
  }	 
  campo.value = vr;
}

//Aceita apenas números
function Aceita_Numero(e){
  if(document.all) // Internet Explorer
    var tecla = event.keyCode;
  else if(document.layers) // Nestcape
    var tecla = e.which;
	
  if((tecla > 47 && tecla < 58) || (tecla > 95 && tecla < 106) || 
     (tecla == 13) || (tecla == 8)  || (tecla == 37) || (tecla == 39) ||
	 (tecla == 9) || (tecla == 36) || (tecla == 35) || (tecla == 46) ) {
	 // numeros de 0 a 9, enter, backspace, setas
    return true;
  } else {
      if (tecla != 8) // backspace
        return false;
      else
        return true;
  }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////