// JavaScript Document

//////////////////////////////////////////Notícias///////////////////////////////////////////////////
function ChamaNoticia(param, id, vai) {
 if (vai == 1){
	 location.href = param+"/noticias/noticias.jsp?id="+id;
 }	
 if (vai == 2){
	 location.href = param+"/noticias/noticias_fontes.jsp?id="+id;
 } 
 //alert(param);
}

function ChamaNoticiaInterna(param, id, vai) {
 if (vai == 1){
	 parent.top.location.href = param+"/noticias/noticias.jsp?id="+id;
 }	
 if (vai == 2){
	 location.href = param+"/noticias/noticias_fontes.jsp?id="+id;
 } 
 //alert(param);
}
////////////////////////////////////////////////////////////////////////////
// Verifica o tipo de navegador para ajustar os layers
agent = navigator.userAgent;
browserVer = 2;
var winX = 0;
var winY = 0;

if (agent.substring(0,7) == "Mozilla")
{
    if (parseInt(agent.substring(8,9)) >= 3)
	{
		browserVer = 1;
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Valida o formulário de pesquisa
function Pesquisa() {
  if ((document.form.inicio.value == "") || (document.form.final.value == "")) {
     alert ("Digite um período");
	 if (document.form.inicio.value == "") 
 	    document.form.inicio.focus()
	 else
	    document.form.final.focus();	
	 return false;
  }
 document.form.submit();
  
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Realiza o login para realizar a manutenção das notícias
function Login(param) {
 if (param == null) {
    location.href = "noticias.jsp?L=1";
 }else {
    location.href = "noticias.jsp?L=1&id="+param;
 }	
 // window.open("login.jsp","Login","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=285,height=140,left=250,top=250");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Valida o formulário de login
function validaLogin() {
  if ((document.forms[0].login.value == "") || (document.forms[0].senha.value == "")) {
     alert ("Digite um login e uma senha válida");
	 return false;
  }
  return true;
}  
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Chama a tela de inclusão
function Inclusao(){
 location.href = "manutencao.jsp?acao=I";
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Chama a tela de inclusão
function Manutencao(){
 if (document.forms[0].p_tit.value == ""){
   alert("Digite o título da notícia");
   document.forms[0].p_tit.focus();
   return false;
 }
 if (document.forms[0].p_data.value == ""){
   alert("Digite a data da notícia");
   document.forms[0].p_data.focus();
   return false;
 }
 if (document.forms[0].p_manchete.value == ""){
   alert("Selecione se a notícia é manchete");
   document.forms[0].p_manchete.focus();
   return false;
 }
 if (document.forms[0].p_materia.value == ""){
   alert("Digite a matéria da notícia");
   document.forms[0].p_materia.focus();
   return false;
 }
 
 if (document.forms[0].p_tipo.value == ""){
   alert("Selecione o tipo da notícia");
   document.forms[0].p_tipo.focus();
   return false;
 }
 
  return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Anexar
// Chama a tela Anexo
function AbreFoto(id, param){
   //cookie('cra',document.forms[0].p_materia.value, 1); 
  page = param+"/noticias/anexar.jsp?id="+id;
    window.open(page,"anexo","width=510,height=400,top=1,left=1,status=yes,scrollbars=yes");
}
////////////////////////////////////////////////////////////////////////////
function IncFoto(id, caminho){
   var page = caminho+"/noticias/anexarfoto.jsp?id="+id+"&a=A";
   //window.open(page,"anexo","width=300,height=60,top=250,left=250,status=yes");
   location.href = page;
}
//Excluir uma foto
function ExFoto(id, sequencial, caminho, nome){
  if(confirm("Confirma a exclusão da Foto?")){
  	var page = caminho+"/excluirfoto?id="+id+"&seq="+sequencial+"&nome="+nome;
  	document.forms[0].action = page;
	document.forms[0].submit();		
 }	
}
//Altera a legenda da foto
function AltFoto(id, sequencial, legenda, caminho){
    var valor = eval("document.forms[0]."+legenda+".value");
  	var page = caminho+"/editarfoto?id="+id+"&seq="+sequencial+"&leg="+valor;
  	document.forms[0].action = page;
	document.forms[0].submit();	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
function cookie(nome_do_cookie, value, expiredays){
 var ExpireDate = new Date ();
 ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
 document.cookie = nome_do_cookie + "=" + escape(value) + 
 ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function lerCookie(name){
 var cookieValue = "";
 var search = name + "=";
 if(document.cookie.length > 0){
  offset = document.cookie.indexOf(search);
  if (offset != -1){
   offset += search.length;
   end = document.cookie.indexOf(";", offset);
   if (end == -1) end = document.cookie.length;
   cookieValue = unescape(document.cookie.substring(offset, end))
  }
 }
 return cookieValue;
}

//Excluir
function Apagar(param, caminho) {
 if (confirm("Deseja excluir a notícia?")){
   location.href = caminho+"/editarexcluir?id_noticia="+param+"&acao=EX";
 }  
 //alert(param);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function colocadata(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 retiradata(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;
  }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////