function MM_openBrWindow(theURL,winName,features)
{
  window.open(theURL,winName,features);
}

function SelectedCombo(Objeto)
{
  return Objeto[Objeto.selectedIndex].value;
}

function isFieldBlank(theField)
{
  inStr = theField.value;
  inLen = inStr.length;
      
  for(var i = 0; i < inLen; i++)
  {
    var ch = inStr.substring(i, i+1)

    if (ch != " ")
      return (false);   
  }

  theField.Value = "";
  return (true);
}
function isFieldBlankText(theField)
{
  inStr = theField.value;
  inLen = inStr.length;
      
  for(var i = 0; i < inLen; i++)
  {
    var ch = inStr.substring(i, i+1)
    var chcode = inStr.charCodeAt(i);
    if ((chcode == 13) || (chcode==10))
      ch = " ";
    
    if (ch != " ")
      return (false);   
  }

  theField.Value = "";
  return (true);
}

function isNumberME(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 isFloat(theFloat)
{
  inStr = theFloat.value;
  inAux = "";
  inLen = inStr.length;
  var cont = 0;

  if (inStr == ".")
    return (false);
    
  if (inStr == ",")
    return (false);
    
  for(var i = 0; i < inLen; i++)
  {
    var ch = inStr.substring(i, i+1)

    if ((ch < "0") || (ch > "9"))
      if ((ch != ".") && (ch != ","))
        return (false);

    if ((ch == ".") || (ch == ","))
      cont++;

    if (cont >= 2)
      return (false);

    if (ch == ",")
      inAux = inAux + "."
    else 
      inAux = inAux + ch;
  }
  
  theFloat.value = inAux;
  return (true);
}

function isFloatNeg(theFloat)
{
  inStr = theFloat.value;
  inAux = "";
  inLen = inStr.length;
  var cont = 0;

  if (inStr == "-")
    return (false);
    
  if (inStr == ".")
    return (false);
    
  if (inStr == ",")
    return (false);
    
  for(var i = 0; i < inLen; i++)
  {
    var ch = inStr.substring(i, i+1)

    if ((ch < "0") || (ch > "9"))
      if ((ch != ".") && (ch != ","))
        if (ch != "-")
          return (false);
    
    if (ch == "-")
      if (i != 0)
        return (false);

    if ((ch == ".") || (ch == ","))
      cont++;

    if (cont >= 2)
      return (false);

    if (ch == ",")
      inAux = inAux + "."
    else 
      inAux = inAux + ch;
  }

  theFloat.value = inAux;
  return (true);
}
function isTime(theTime)
{
  var i = 0;
  var qcaracter = 2;
  inStr = theTime.value;
  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);
}

/* Criada por David 
   Exclui espacos em branco do fim e do inicio de uma string */
function spaceTrim(theString)
{
  var strAux = theString;
  var strLen = strAux.length;
  var saida  = false;
  var chAux  = ""; 
  
  while (! saida)  
  {
    chAux = strAux.substring(strLen-1,strLen);
    if (chAux != " ") 
      saida = true
    else
    {
      strAux = strAux.substring(0,strLen-1);
      strLen = strAux.length;
    }
  }
  
  saida = false;  
  
  while (! saida)  
  {
    chAux = strAux.substring(0,1);
    if (chAux != " ") 
      saida = true
    else
    {
      strAux = strAux.substring(1,strLen);
      strLen = strAux.length;
    }
  }
  
  return(strAux);
}

function isEmail2(email)
{
	if (email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
	{
		return false;
	}
	else
	{
		return true;
	}
}
function IntThis(theNumber)
{
  inStr = theNumber.value;
  inAux = "";
  inLen = inStr.length;
  
  if (inStr == ".")
  {
    return ('');
  }

  if (inStr == ",")
  {
    return ('');
  }
  
  if (inStr == "")
  {
    return ('');
  }
  
  for(var i = 0; i < inLen; i++)
  {
    var ch = inStr.substring(i, i+1);
    
    if ((ch < "0") || (ch > "9"))
      {
        alert("Formato para o número inválido.\nUtilize apenas números.\nNão utilize separador de milhar.");
        theNumber.focus();
        return ('');
      }
    else
      {
      inAux = inAux + ch
      }
  }

  return (inAux);
}
function CheckedValue(Objeto)
{
  var LenAux = Objeto.length;

  if (LenAux == undefined)
  {
	return Objeto.value;
  }
  else{
	  for ( i = 0; i < LenAux; i ++)
	  {
		if (Objeto[i].checked)
		  return Objeto[i].value;
	  }
	  return "";
  }
}

function CheckedValuei(Objeto)
{
  var LenAux = Objeto.length;
  
  for ( i = 0; i < LenAux; i ++)
  {
    if (Objeto[i].checked)
      return i;
  }
  return "";
}

// 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 AnoBissexto(Ano)
{
  var DifAno = (Ano/4) - Math.ceil(Ano/4)
  if (DifAno != 0)
    return (false);

  return (true);
}

function ValidaData(CampoData)
{
  inStr = CampoData.value;

  var ok = true;
  var ch =  inStr.substring(0,2)
  var i = 0;
  AnoBiss = (AnoBissexto(inStr.substring(6,10)))
  
  while ( i < 6)
  {
    i++;

    if (i == 1)
    {
      Dia = ch;

      if (isNaN(Dia) || ((Dia < 1) || (Dia > 31)))
        ok = false
      else
        ch = inStr.substring(2,3);
    }

    if (i == 2)
      if (ch != "/")
        ok = false
      else
        ch = inStr.substring(3,5);

    if (i == 3)
    {
      Mes = ch;

      if (isNaN(Mes) || ((Mes < 1) || (Mes > 12)))
        ok = false
      else

        if (((! AnoBiss) && Mes == 2 && Dia > 28) || ((AnoBiss) && Mes == 2 && Dia > 29) || (Dia > 30 && (Mes == 4 || Mes == 6 || Mes == 9 || Mes == 11))) 
          ok = false
        else
          ch = inStr.substring(5,6);
    }

    if (i == 4)
      if (ch != "/")
        ok = false
      else
        ch = inStr.substring(6,10);

    if (i == 5)
    {
      Ano = ch;

      if (isNaN(Ano) || Ano < 1990)
        ok = false;
    }
  }
  return (ok);
}

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 Mascara(formato, keypress, objeto)
{
	campo = eval (objeto);
// mascara de login
	if (formato == 'Acesso')
	{
		if(39==window.event.keyCode)
		{
			event.returnValue = false;
		}
		if(34==window.event.keyCode)
		{
			event.returnValue = false;
		}
		if(13==window.event.keyCode)
		{
			event.returnValue = false;
		}
	}
	
// mascara de data
	if (formato == 'Data')
	{
		caracteres = '01234567890';
		conjuntos = 3;
		conjunto1 = 2;
		conjunto2 = 3;
		conjunto3 = 5;
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		(conjunto1 + conjunto2 + conjunto3))
		{
			if (campo.value.length == conjunto1)
			{
				campo.value = campo.value + "/";
			}
			if (campo.value.length == conjunto1 + conjunto2)
			{
				campo.value = campo.value + "/";
			}
		}
		else 
			event.returnValue = false;
	}
	
// mascara de caracter numerico
	if (formato == 'Numero')
		//alert(campo.value.length)
	{
		caracteres = '01234567890';
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < caracteres)
		{}
		else
			event.returnValue = false;
	}
	
}
// validando campo e-mail
function ValidateMail(sValue)
{
	var sPat = /^(([a-z]|[A-Z])([a-z]|[A-Z]|[0-9]|.|_)+)@(([a-z]|[A-Z])([a-z]|[A-Z]|[0-9]|_)+)\.(([a-z]|[A-Z]){1,3})(\.([a-z]|[A-Z]){1,3})?$/;
	return sPat.test(sValue);
}
function BlocCaracteres(Param, Objeto)
{
	//alert(window.event.keyCode);
	if(document.getElementById(Objeto).value.length >= Param)
	{
		if (window.event.keyCode == 8)
		{
			event.returnValue = true;	
		}
		else if (window.event.keyCode == 16)
		{
			event.returnValue = true;	
		}
		else if (window.event.keyCode == 17)
		{
			event.returnValue = true;	
		}
		else if (window.event.keyCode == 35)
		{
			event.returnValue = true;	
		}
		else if (window.event.keyCode == 36)
		{
			event.returnValue = true;	
		}
		else if (window.event.keyCode == 37)
		{
			event.returnValue = true;	
		}
		else if (window.event.keyCode == 38)
		{
			event.returnValue = true;	
		}
		else if (window.event.keyCode == 39)
		{
			event.returnValue = true;	
		}
		else if (window.event.keyCode == 40)
		{
			event.returnValue = true;	
		}
		else if (window.event.keyCode == 46)
		{
			event.returnValue = true;	
		}
		else
		{
			event.returnValue = false;	
		}
	}
}
function MascaraData(Campo)
{
	if(Campo.value.length==2)
	{
		Campo.value= Campo.value + "/";
	}
	if(Campo.value.length==5)
	{
		Campo.value= Campo.value + "/";
	}
}

