  
function MM_openBrWindow(theURL,winName,features) {
  winName = window.open(theURL, winName, features);
  winName.focus();
}

function MM_openCons(parms) {
  MM_openBrWindow('ExportUsuarios.asp' + parms,'Docs','menubar=yes,status=no,resizable=yes,scrollbars=yes,width=780,height=540,screenX=0,screenY=0,left=0,top=0');
}

function isFieldBlank(theField)
{
  var inStr = theField.value;
  var inLen = inStr.length;
      
  for(var i = 0; i < inLen; i++)
  {
    var ch = inStr.substring(i, i+1)

    if (ch != " ")
      return (false);   
  }

  //Permissoes de seguranca nao deixavam a atribuicao funcionar 
  inStr = "";
  return (true);
}

function isNumber(theNumber)
{
  inStr = theNumber.value;
  inLen = inStr.length;

  for(var i = 0; i < inLen; i++)
  {
    var ch = inStr.substring(i, i+1)
  
    if ((ch < "0") || (ch > "9"))
      return (false);
  }
  
  return (true);
}

function isColor(theColor)
{
  inStr = theColor.value;
  inLen = inStr.length;
  
  if (inLen != 7)
    return(false);

  var hexa = '0123456789ABCDEFabcdef';
  
  var ch = inStr.substring(0,1);
  
  if (ch != '#')
    return(false)
    
  for(var i = 1; i < inLen; i++)
  {
    var ch = inStr.substring(i, i+1)
  
    if (hexa.indexOf(ch,0) == -1)
      return (false);
  }
  
  return (true);
}

function isTime(theTime)
{
  var i = 0;
  var qcaracter = 2;
  inStr = theTime.value;
  if (inStr.length > 5){
   return false;
  }
  var ch =  inStr.substring(0,2)
  while ( i < 4)
  {
    i++;
    if (i == 1)  
      if ((ch < "00")  || (ch > "23"))
        return (false)
      else
        ch = inStr.substring(2,3);

    if (i == 2)
      if (ch != ":")
        return (false)
      else
        ch = inStr.substring(3,5);

    if (i == 3) 
      if ((ch < "00")  || (ch > "59"))
        return (false);
  }

  return (true);
}

function dataValida(data,formato)
{
  if (data.length < 10) 
  {   
    return (false);
  }
  myRe = new RegExp;

  if (formato == 1)
    myRe=/([0-2][0-9]|3[01])\/(0[1-9]|1[0-2])\/([12][0-9]{3,3})/ig;
  else if (formato == 2)
    myRe=/(0[1-9]|1[0-2])\/([0-2][0-9]|3[01])\/([12][0-9]{3,3})/ig;
  else if (formato == 3)
    myRe=/([12][0-9]{3,3})\/(0[1-9]|1[0-2])\/([0-2][0-9]|3[01])/ig;
  else
    return(false);
    
  if (! eval("myRe.exec(data)"))
  {
    return false;
  }
  myRe.exec(data)
  
  if (formato == 1)
  {
    var dia = RegExp.$1;
    var mes = RegExp.$2;
    var ano = RegExp.$3;
  }
  else if (formato == 2)
  {
    var mes = RegExp.$1;
    var dia = RegExp.$2;
    var ano = RegExp.$3;
  }
  else if (formato == 3)
  {
    var ano = RegExp.$1;
    var mes = RegExp.$2;
    var dia = RegExp.$3;
  }
  
  if (dia.charAt(0) == "0")
  {
    dia = dia.charAt(1);
  }  
  
  if (mes.charAt(0) == "0")
  {
    mes = mes.charAt(1);
  }  
  
  dia = parseInt(dia);  
  mes = parseInt(mes);    
  ano = parseInt(ano);     

  if ((ano%400==0) || ((ano%4==0) && (ano%100!=0))) 
  {
    var DiasMes=new Array(31,29,31,30,31,30,31,31,30,31,30,31);
  }
  else
  {
    var DiasMes=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  }

  if (dia > DiasMes[mes-1])
  {
    return (false);
  }
  return (true);
}  

function horaValida(hora)
{
  if (hora.length < 5)
  {
    return (false);
  }
  myRe = new RegExp;

  myRe = /^([0-1][0-9]|2[0-4]):([0-5][0-9])$/ig;

  if (! eval("myRe.exec(hora)"))
  {
    return false;
  }
  myRe.exec(hora);
  myRe = null;
  return (true);
}

function isEmail(mail)
{
  if (mail.value.length < 6)
  {
    return (false);
  }
  myRe = new RegExp;
  
  RegExp.lastIndex = 0;

  myRe = /([_a-zA-Z\d\-\.][_a-zA-Z\d\-\.]+)@([_a-zA-Z\d\-][_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-][_a-zA-Z\d\-]+))/;

  if (! myRe.test(mail.value))
  {
    return false;
  }
  
  myRe.exec(mail);

  myRe = null;

  return (true);
}

function ComparaData(CampoDataInicio, CampoDataFim)
{
  Dia = CampoDataInicio.value.substring(0,2);
  Mes = CampoDataInicio.value.substring(3,5);
  Ano = CampoDataInicio.value.substring(6,10);
  var DataInicioConvert = Ano + Mes + Dia;

  Dia = CampoDataFim.value.substring(0,2);
  Mes = CampoDataFim.value.substring(3,5);
  Ano = CampoDataFim.value.substring(6,10);
  var DataFimConvert = Ano + Mes + Dia;

  if (DataFimConvert < DataInicioConvert){
    return (false);
  }
  return (true);
}  


function contar(campo,rest,limite, mens)
{
  if (campo.value.length > limite)
  {
    campo.value = campo.value.substring(0, limite);
    alert(mens.replace(/%char%/g, limite));
  }
  else
  {
    rest.value = limite - campo.value.length;
  }
}

function TamanhoCampo(theField, Tamanho, mens)
{
  if (theField.value.length > Tamanho)
  {
    theField.value = theField.value.substring(0, Tamanho-1);
    alert(mens.replace(/%char%/g, Tamanho));
  }
}

// Procura o Ch1 e troca por Ch2 na string de entrada
function Replace(theString, Ch1, Ch2)
{
  var strAux = theString;
  var strLen = strAux.length;
  var saida  = "";
  var chAux  = ""; 
  var P = 0;

  while (P < strLen)
  {
    chAux = strAux.substring(P, P + 1);

    if (chAux == Ch1) 
      saida = saida + Ch2
    else
      saida = saida + chAux;
 
    P++;
  }

  return(saida);
}

function DeleteAspas(theString)
{
  theString.value = theString.value.replace(/\"|\'/g, "");
}

// ZL - Para pegar o value de um combo
function SelectedCombo(Objeto)
{
  return Objeto[Objeto.selectedIndex].value
}

function GetColorBar(value)
{
  if (parseFloat(value) < 30)
  {
    return('PixAzul1.gif')
  }
  else if (parseFloat(value) < 60)
  {
    return('PixAzul2.gif')
  }
  else if (parseFloat(value) < 100)
  {
    return('PixAzul3.gif')
  }
  else 
  {
    return('PixVerde.gif')
  }
}

function GetDatePart(inStr,Part,Formato) {
  // Part = 1 - dd
  // Part = 2 - mm
  // Part = 3 - yyyy
  if (Formato == 1)
  {
    if (Part == 1)
     return(eval(inStr.substring(0,2)));
    else if (Part == 2)
     return(eval(inStr.substring(3,5)));
    else if (Part == 3)
     return(eval(inStr.substring(6,10)));
  }
  else if (Formato == 2)
  {
    if (Part == 1)
     return(eval(inStr.substring(3,5)));
    else if (Part == 2)
     return(eval(inStr.substring(0,2)));
    else if (Part == 3)
     return(eval(inStr.substring(6,10)));
  }
  else if (Formato == 3)
  {
    if (Part == 1)
     return(eval(inStr.substring(8,10)));
    else if (Part == 2)
     return(eval(inStr.substring(5,7)));
    else if (Part == 3)
     return(eval(inStr.substring(0,4)));
  }
}

// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
// USO <INPUT NAME="dollar" SIZE=5 MAXLENGTH=5 onKeyPress="return numbersonly(this, event)">

function numbersonly(myfield, e, dec)
{

  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key);

  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
    return true;

  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
    return true;

  // decimal point jump
  else if (dec && (keychar == "."))
  {
    myfield.form.elements[dec].focus();
    return false;
  }
  else
    return false;
}



