function $(e){
 return document.getElementById(e);
}

function $N(e){
 return document.getElementsByName(e);
}

function $T(e){
 return document.getElementsByTagName(e);
}

function AbreJanela(destino,x,y,prt1) {
 var prt = prt1.split(",");
 var prt2 = 'width='+x+', height='+y+', toolbar='+prt[0]+',directories='+prt[1]+',status='+prt[2]+',location='+prt[3]+', menubar='+prt[4]+', resizable='+prt[5]+', scrollbars='+prt[6];
 var janela = window.open(destino,'',prt2);
 if (janela === false) { window.alert("Este site utiliza popups!\nPor favor desabilite seu bloqueador de popups e tente novamente!"); }
}

function JanelaUnica(destino,x,y,prt1) {
 var prt = prt1.split(",");
 var prt2 = 'width='+x+', height='+y+', toolbar='+prt[0]+',directories='+prt[1]+',status='+prt[2]+',location='+prt[3]+', menubar='+prt[4]+', resizable='+prt[5]+', scrollbars='+prt[6];
 var janela = window.open(destino,'Popup',prt2);
 if (janela === false) { window.alert("Este site utiliza popups!\nPor favor desabilite seu bloqueador de popups e tente novamente!"); }
}


function CarregaPagina(url) { $('conteudo').src = url; }

function AbreMenu(id) { $(id).style.display = $(id).style.display == 'none' ? 'block' : 'none';  }

function Foco(id) { $(id).focus(); }

function LimpaForm(id) { 
 for (i=0; i<$(id).length; i++) { 
  if ($(id).elements[i].type == "text" || $(id).elements[i].type == "hidden" || $(id).elements[i].type == "textarea") $(id).elements[i].value = "";  
  if ($(id).elements[i].type == "select-one") $(id).elements[i].item(0).selected = true;  
 }  
} 

function Sel(id) { $(id).style.background = "#0063C6"; $(id).style.color = "#FFFFFF"; }

function Normal(id) { $(id).style.background = "#FFFFFF";  $(id).style.color = "#000000"; }

function ExcluiData(id) { window.opener.$(id).style.display = "none"; }

function Clock() {
 var now = new Date();

 var ampm = (now.getHours() >= 12) ? " P.M." : " A.M."
 var hora = ((now.getHours() > 12) ? now.getHours() - 12 : now.getHours());
 var minuto = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
 var segundo = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
 var NomeDia = ["Domingo","Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado"]; 
 var NomeMes = ["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"];

 window.status = "Jaboticabal, "+NomeDia[now.getDay()]+", "+now.getDate()+" de "+NomeMes[now.getMonth()]+" de "+ now.getYear()+ " - "+hora+minuto+segundo+ampm;
 //window.status = now.toLocaleString();
 setTimeout("Clock();",1000) 
}

function dominio(campo) {
 var valor = $(campo).value;
 var reTipo = /^\d+$/;
 if (valor.length > 0) {
  if (reTipo.test(valor) == false) {
   window.alert("Por favor utilize apenas números!");  
   $(campo).value = "";
  }
 }
}

function CheckCPF(campo) {
 var v = $(campo).value;
 var s1 = 0;
 var s2 = v.charAt(9)*2;
 for (i = 0; i < 9;i++) { 
  s1 = s1 + (v.charAt(i)*(10-i)); 
  s2 = s2 + (v.charAt(i)*(11-i)); 
 }
 var d1 =  (11-(s1%11) > 10 ? 0 : (11-(s1%11)) );
 var d2 =  (11-(s2%11) > 10 ? 0 : (11-(s2%11)) );
 if ( (d1!=v.charAt(9)) || (d2!=v.charAt(10)) || v.length <= 0) { 
  window.alert("O CPF digitado não é válido!\nPor favor digite um CPF válido!"); 
  $(campo).focus();
  return false
 } else { return true }
}

function WNav(vals){
 var a = vals.split(","); 
 for (i=0; i < a.length; i++) { 
  var b = a[i].split("="); 
  window.opener.$(b[0]).value=b[1];
 }
 window.close();
}

function Retornar(url,rotulo) {
 parent.window.$("link_local").href = url;
 parent.window.$("link_local").innerText = rotulo;
}

/*
function WNavF(vals,frm){
 var a = vals.split(","); 
 for (i=0; i < a.length; i++) { 
  var b = a[i].split("="); 
  window.opener.$(b[0]).value=b[1];
  window.opener.$(frm).submit();
 }
 window.close();
}
*/

/**
 * @return {void}
 * @param {String} url Url que deve ser aberta
 * @param {String} titulo Titulo da janela (opcional)
 * @param {Integer} width Largura da janela
 * @param {Integer} height Altura da janela
 * @param {yes|no} tootlbar [Padrao no] Barra de ferramentas
 * @param {yes|no} directories [Padrao no] Pasta Links dos Favoritos
 * @param {yes|no} status [Padrao no] Barra de status
 * @param {yes|no} location [Padrao no] Barra de enderecos
 * @param {yes|no} menubar [Padrao no] Menu padrao
 * @param {yes|no} resizable [Padrao no] Redimensionamento 
 * @param {yes|no} scrollbars [Padrao no] Barra de rolagem
 */
function PopupWindow() {
 this.url = "";
 this.titulo = "";
 this.width = "";
 this.height = "";
 this.toolbar = "no";
 this.directories = "no";
 this.status = "no";
 this.location = "no";
 this.menubar = "no";
 this.resizable = "no";
 this.scrollbars = "no";
 this.move = "";
 this.openWindow = function() {
  var popup = window.open(this.url, this.titulo, "width=" + this.width +
                                                 ",height=" + this.height +
                                                 ",innerWidth=" + this.width +
                                                 ",innerHeight=" + this.height +
                                                 ",toolbar=" + this.toolbar + 
                                                 ",directories=" + this.directories + 
                                                 ",status=" + this.status + 
                                                 ",location=" + this.location + 
                                                 ",menubar=" + this.menubar + 
                                                 ",resizable=" + this.resizable + 
                                                 ",scrollbars=" + this.scrollbars);
 
  if (popup == false) {
   window.alert("Este site utiliza popups!\nPor favor desabilite seu bloqueador de popups e tente novamente!");
  }

  if (this.move != "") {
   var p = explode(",", this.move);
   popup.moveTo(p[0], p[1]);
  }
 
 };
}


/**
 * Emula a função ereg do PHP
 * @param {String} patern
 * @param {String} value
 * @return {Boolean}
 */
function ereg(pattern, value) {
 var patt1 = new RegExp(pattern);
 return patt1.test(value);
}

/**
 * Recebe como parametro um formulário e gera cookies de todos dos campos
 * @param {Formulário} e
 */
function GeraCookies(form) {
 if (navigator.cookieEnabled == 1) {
  for (i = 0; i < $(form).length; i++) {
   document.cookie = $(form).elements[i].name + "=" + $(form).elements[i].value + ";";
  }
  return true;
 } else {
  window.alert("Esse script usa cookies!\nPor favor habilite os cookies no seu navegador e tente novamente!");
  return false;
 }
}