function Verifica_numeros(campo){
	var campo = campo;
	var valor = campo.value;
	if ((isNaN(valor))){
		alert('Campo deve ser preenchido somente com números!');
		campo.focus();
		return(false);
	}
}

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 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 < 1900)
        ok = false;
    }
  }
  return (ok);
}


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;
	}
	
}


function MascaraData(Campo)
{
	if(Campo.value.length==2)
	{
		Campo.value= Campo.value + "/";
	}
	if(Campo.value.length==5)
	{
		Campo.value= Campo.value + "/";
	}
}


function VerificaData(Param)
{
	oForm = document.formulario;
	str = eval('oForm.' + Param);
	if (!isFieldBlank(str))
	{
		if (!ValidaData(str))
		{
			alert("Preencha o campo data corretamente no formato dd/mm/aaaa!");
			str.value = "";
			str.focus();
			return(false);
		}
	}
	return(true);
}


function criaMascara(_RefObjeto, _Modelo){
	var tipo = _Modelo;
	if ( (tipo == undefined)  )
	{
		_Modelo = '###.###.###-##';
	}
	
    var valorAtual = _RefObjeto.value;
    var valorNumerico = '';
    var nIndexModelo = 0;
    var nIndexString = 0;
    var valorFinal = '';
    var adicionarValor = true;


      // limpa a string valor atual para verificar
      // se todos os caracteres são números
      for (i=0;i<_Modelo.length;i++){
        if (_Modelo.substr(i,1) != '#'){
          valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
      }}

      // verifica se todos os caracteres são números
      for (i=0;i<valorAtual.length;i++){
        if (!isNaN(parseFloat(valorAtual.substr(i,1)))){
          valorNumerico = valorNumerico + valorAtual.substr(i,1);
      }}

      // aplica a máscara ao campo informado usando
      // o modelo de máscara informado no script
      for (i=0;i<_Modelo.length;i++){

        if (_Modelo.substr(i,1) == '#'){
          if (valorNumerico.substr(nIndexModelo,1) != ''){
            valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
            nIndexModelo++;nIndexString++;
          }
            else {
              adicionarValor = false;
        }}

          else {
            if (adicionarValor && valorNumerico.substr(nIndexModelo,1) !=
''){
            valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
            nIndexString++;
          }}
      }

      //alert(valorFinal)
      _RefObjeto.value = valorFinal

  }

//hide selects on page - copy code below


function hideSelects(action) {
//documentation for this script at http://www.shawnolson.net/a/1198/
//possible values for action are 'hidden' and 'visible'
if (top.document.frames.length > 0)
{
	if (action!='visible'){action='hidden';}
	if (navigator.appName.indexOf("MSIE")) {
	for (var S = 0; S < frameEditorF.document.forms.length; S++){
	for (var R = 0; R < frameEditorF.document.forms[S].length; R++) {
	if (frameEditorF.document.forms[S].elements[R].options) {
	frameEditorF.document.forms[S].elements[R].style.visibility = action;
	window.focus()
	}
	}
	}

	for (var S = 0; S < frameEditorJ.document.forms.length; S++){
	for (var R = 0; R < frameEditorJ.document.forms[S].length; R++) {
	if (frameEditorJ.document.forms[S].elements[R].options) {
	frameEditorJ.document.forms[S].elements[R].style.visibility = action;
	window.focus()
	}
	}
	}
	
	
	
	}
	}
}

//end code


//hide selects on page - copy code below


function hideSelects2(action) {
//documentation for this script at http://www.shawnolson.net/a/1198/
//possible values for action are 'hidden' and 'visible'
if (top.document.frames.length > 0)
{
	if (action!='visible'){action='hidden';}
	if (navigator.appName.indexOf("MSIE")) {
	for (var S = 0; S < document.forms.length; S++){
	for (var R = 0; R < document.forms[S].length; R++) {
	if (document.forms[S].elements[R].options) {
	document.forms[S].elements[R].style.visibility = action;
	window.focus()
	}
	}
	}
	}
	}
}

//end code
