function popup(nome,vlx,vly,scrol) {
  var attrib='toolbar=no,scrollbars=' + scrol + ',no,resizable=no,width=' + vlx + ',height=' + vly;
  window.open (nome,'_blank',attrib);
}

function confirmacao(objeto, mensagem) {
    if (confirm(mensagem)) {return true} else {return false}
}

function abrepg(nome) {
  window.open (nome,'_self');
}

function formatdate(dia,evento) {
  var permitidos = '0123456789';
  var tecla = (window.Event) ? evento.which : evento.keyCode;
  var keyChar = String.fromCharCode(tecla); 
  
  if (evento.keyCode ==  8) return true;
  if (evento.keyCode ==  9) return true;
  if (evento.keyCode == 13) return true;
  if (evento.keyCode == 35) return true;
  if (evento.keyCode == 36) return true;
  if (evento.keyCode == 37) return true;
  if (evento.keyCode == 39) return true;
  if (evento.keyCode == 46) return true;

  if (permitidos.indexOf(keyChar) == -1) {
     return false;
  }   
  
  
  if (dia.value.length == 2) {dia.value = dia.value + '/'}
  if (dia.value.length == 5) {dia.value = dia.value + '/'}
  return true;
}

function formathour(hora,evento) {
  var permitidos = '0123456789';
  var tecla = (window.Event) ? evento.which : evento.keyCode;
  var keyChar = String.fromCharCode(tecla); 
  
  if (evento.keyCode ==  8) return true;
  if (evento.keyCode ==  9) return true;
  if (evento.keyCode == 13) return true;
  if (evento.keyCode == 35) return true;
  if (evento.keyCode == 36) return true;
  if (evento.keyCode == 37) return true;
  if (evento.keyCode == 39) return true;
  if (evento.keyCode == 46) return true;

  if (permitidos.indexOf(keyChar) == -1) {
     return false;
  }   
  
  if (hora.value.length == 2) {hora.value = hora.value + ':'}
  return true;
}

function formatnum(num,evento) {
  var permitidos = '0123456789';
  var tecla = (window.Event) ? evento.which : evento.keyCode;
  var keyChar = String.fromCharCode(tecla); 
  
  if (evento.keyCode ==  8) return true;
  if (evento.keyCode ==  9) return true;
  if (evento.keyCode == 13) return true;
  if (evento.keyCode == 35) return true;
  if (evento.keyCode == 36) return true;
  if (evento.keyCode == 37) return true;
  if (evento.keyCode == 39) return true;
  if (evento.keyCode == 46) return true;

  if (permitidos.indexOf(keyChar) == -1) {
     return false;
  }   
  
  if (num.value.length == 1) {num.value = num.value + '.'}
  return true;
}

function formatrotulo(num,evento) {
  var permitidos = '0123456789';
  var tecla = (window.Event) ? evento.which : evento.keyCode;
  var keyChar = String.fromCharCode(tecla); 
  
  if (evento.keyCode ==  8) return true;
  if (evento.keyCode ==  9) return true;
  if (evento.keyCode == 13) return true;
  if (evento.keyCode == 35) return true;
  if (evento.keyCode == 36) return true;
  if (evento.keyCode == 37) return true;
  if (evento.keyCode == 39) return true;
  if (evento.keyCode == 46) return true;

  if ((tecla == 69) || (tecla == 101)) {
     if (num.value.length == 0) {num.value = num.value + 'E';}
  } 

  if ((tecla == 72) || (tecla == 104)) {
     if (num.value.length == 0) {num.value = num.value + 'H';}
  } 

  if (permitidos.indexOf(keyChar) == -1) {
     return false;
  }   
  
}

function formatsonum(num,evento) {
  var permitidos = '0123456789';
  var tecla = (window.Event) ? evento.which : evento.keyCode;
  var keyChar = String.fromCharCode(tecla); 
  
  if (evento.keyCode ==  8) return true;
  if (evento.keyCode ==  9) return true;
  if (evento.keyCode == 13) return true;
  if (evento.keyCode == 35) return true;
  if (evento.keyCode == 36) return true;
  if (evento.keyCode == 37) return true;
  if (evento.keyCode == 39) return true;
  if (evento.keyCode == 46) return true;

  if (permitidos.indexOf(keyChar) == -1) {
     return false;
  }   
  return true;
}

function validaData(diain) {
  var ok=true;
  var dia=diain.value.substr(0,2);     
  var mes=diain.value.substr(3,2);     
  var ano=diain.value.substr(6,4);     

  if (diain != "") {
     if (dia == "00") {
        alert("Dia Inválido!");
        ok=false;
     }
     if (dia > "31") {
        alert("Dia Inválido!");
        ok=false;
     }
  
     if (dia == "31") {
        if ((mes == "02") | (mes == "04") | (mes == "06") | (mes == "09") | (mes == "11")) {  
            alert("Dia Inválido!");
           ok=false;
        }
     }
  
     if ((dia > "29") & (mes == "02")) {
        alert("Dia Inválido!");
        ok=false;
     }
  
     if ((dia == "29") & (mes == "02")) {
        if ((ano % 4) != 0) {   
            alert("Dia Inválido!");
           ok=false;
        }
     }
  
     if (mes == "00") {
        alert("Mês Inválido!");
        ok=false;
     }
     if (mes > "12") {
        alert("Mês Inválido!");
        ok=false;
     }
     if (ano < "1970") {
        alert("Ano Inválido!");
        ok=false;
     }
  } 

  if (!ok) { 
     return false; 
  } 
}

function validaHora(horain) {
  var ok=true;
  var hh=horain.value.substr(0,2);     
  var mm=horain.value.substr(3,2);     

  if (horain != "") {
     if (hh > "24") {
        alert("Hora Inválida!");
        ok=false;
     }
  
     if (mm > "59") {
        alert("Minuto Inválido!");
        ok=false;
     }
  } 

  if (!ok) { 
     return false; 
  } 
}

function popupsearch(nome,formulario,campo1,campo2,campo3,campo4,campo5,campo6,vlx,vly,scrol) {
  var attrib="toolbar=no,scrollbars="+scrol+",no,resizable=no,width="+vlx+",height="+vly;
  window.open (nome,'_blank',attrib);
  campoCp1 = eval("document." + formulario + "." + campo1);
  campoCp2 = eval("document." + formulario + "." + campo2);
  campoCp3 = eval("document." + formulario + "." + campo3);
  campoCp4 = eval("document." + formulario + "." + campo4);
  campoCp5 = eval("document." + formulario + "." + campo5);
  campoCp6 = eval("document." + formulario + "." + campo6);
}
function returnValue(cp1,cp2,cp3,cp4,cp5,cp6) {
    window.opener.campoCp1.value = cp1;
    window.opener.campoCp2.value = cp2;
    window.opener.campoCp3.value = cp3;
    window.opener.campoCp4.value = cp4;
    window.opener.campoCp5.value = cp5;
    window.opener.campoCp6.value = cp6;
    window.close();
}

function ctk_popupsearch(nome,formulario,campo1,campo2,vlx,vly,scrol) {
  var attrib="toolbar=no,scrollbars="+scrol+",no,resizable=no,width="+vlx+",height="+vly;
  window.open (nome,'_blank',attrib);
  campoCp1 = eval("document." + formulario + "." + campo1);
  campoCp2 = eval("document." + formulario + "." + campo2);
}

function ctk_returnValue(cp1,cp2) {
    window.opener.campoCp1.value = cp1;
    window.opener.campoCp2.value = cp2;
    window.close();
}

function cepsearch(cep,formulario,campo1,campo2,campo3,campo4) {
  var attrib="toolbar=no,scrollbars=no,no,resizable=no,width=100,height=100";
  window.open ('cepsearch.php?cep='+cep.value,'popupcep',attrib);
  campoCp1 = eval("document." + formulario + "." + campo1);
  campoCp2 = eval("document." + formulario + "." + campo2);
  campoCp3 = eval("document." + formulario + "." + campo3);
  campoCp4 = eval("document." + formulario + "." + campo4);
}

function returnValue(cp1,cp2,cp3,cp4) {
    window.opener.campoCp1.value = cp1;
    window.opener.campoCp2.value = cp2;
    window.opener.campoCp3.value = cp3;
    window.opener.campoCp4.value = cp4;
    window.close();
}

