function isNUMB(c)
{
	if((cx=c.indexOf(","))!=-1)
	{
  		c = c.substring(0,cx)+"."+c.substring(cx+1);
  	}

	if((parseFloat(c) / c != 1))
  	{
  		if(parseFloat(c) * c == 0)
   		{
   			return(1);
   		}
  		else
   		{
   			return(0);
		}
	}
	else
	{
	 return(1);
	}
}

function LIMP(c)
{
 while((cx=c.indexOf("-"))!=-1)
  {
  c = c.substring(0,cx)+c.substring(cx+1);
  }
 while((cx=c.indexOf("/"))!=-1)
  {
  c = c.substring(0,cx)+c.substring(cx+1);
  }
 while((cx=c.indexOf(","))!=-1)
  {
  c = c.substring(0,cx)+c.substring(cx+1);
  }
 while((cx=c.indexOf("."))!=-1)
  {
  c = c.substring(0,cx)+c.substring(cx+1);
  }
 while((cx=c.indexOf("("))!=-1)
  {
  c = c.substring(0,cx)+c.substring(cx+1);
  }
 while((cx=c.indexOf(")"))!=-1)
  {
  c = c.substring(0,cx)+c.substring(cx+1);
  }
 while((cx=c.indexOf(" "))!=-1)
  {
  c = c.substring(0,cx)+c.substring(cx+1);
  }
 return(c);
 }

function VerifyCNPJ(CNPJ)
 {
 CNPJ = LIMP(CNPJ);
 if(isNUMB(CNPJ) != 1)
  {
  return(0);
  }
 else
  {
  if(CNPJ == 0)
   {
   return(0);
   }
  else
   {
   g=CNPJ.length-2;
   if(RealTestaCNPJ(CNPJ,g) == 1)
    {
    g=CNPJ.length-1;
    if(RealTestaCNPJ(CNPJ,g) == 1)
     {
     return(1);
     }
    else
     {
     return(0);
     }
    }
   else
    {
    return(0);
    }
   }
  }
 }

function RealTestaCNPJ(CNPJ,g)
{
 var VerCNPJ=0;
 var ind=2;
 var tam;
 for(f=g;f>0;f--)
  {
  VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind;
  if(ind>8)
   {
   ind=2;
   }
  else
   {
   ind++;
   }
  }
  VerCNPJ%=11;
  if(VerCNPJ==0 || VerCNPJ==1)
   {
   VerCNPJ=0;
   }
  else
   {
   VerCNPJ=11-VerCNPJ;
   }
 if(VerCNPJ!=parseInt(CNPJ.charAt(g)))
  {
  return(0);
  }
 else
  {
  return(1);
  }
 }
//---------------------------------------------------------------------------------------------------------

function FormataCGC(Formulario, Campo, TeclaPres)
{
    var tecla = TeclaPres.keyCode;
     
    var strCampo;
    var vr;
    var tam;
    var TamanhoMaximo = 14;

    eval("strCampo = document." + Formulario + "." + Campo);

    vr = strCampo.value;
    vr = vr.replace("/", "");
    vr = vr.replace("/", "");
    vr = vr.replace("/", "");
    vr = vr.replace(",", "");
    vr = vr.replace(".", "");
    vr = vr.replace(".", "");
    vr = vr.replace(".", "");
    vr = vr.replace(".", "");
    vr = vr.replace(".", "");
    vr = vr.replace(".", "");
    vr = vr.replace(".", "");
    vr = vr.replace("-", "");
    vr = vr.replace("-", "");
    vr = vr.replace("-", "");
    vr = vr.replace("-", "");
    vr = vr.replace("-", "");
    tam = vr.length;

    if (tam < TamanhoMaximo && tecla != 8)
    {
      tam = vr.length + 1;
    }

    if (tecla == 8)
    {
      tam = tam - 1;
    }

    if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)
    {
      if (tam <= 2)
      {
        strCampo.value = vr;
      }
       if ((tam > 2) && (tam <= 6))
       {
         strCampo.value = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam);
       }
       if ((tam >= 7) && (tam <= 9))
       {
         strCampo.value = vr.substr(0, tam - 6) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam);
      }
       if ((tam >= 10) && (tam <= 12))
       {
         strCampo.value = vr.substr(0, tam - 9) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam);
      }
       if ((tam >= 13) && (tam <= 14))
       {
         strCampo.value = vr.substr(0, tam - 12) + '.' + vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam);
      }
       if ((tam >= 15) && (tam <= 17))
       {
         strCampo.value = vr.substr(0, tam - 14) + '.' + vr.substr(tam - 14, 3) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam);
      }
    }
}
//---------------------------------------------------------------------------------------------------------

//uso : <input type='text' name='hora' OnKeyUp="FormataCampo(this,'##/##/#### ##:##',event);">
function FormataCampo(obj,mascara,evento)
{
var tecla = evento.keyCode;//Event.keyCode;
var campo = obj.value;
var tam_mascara = mascara.length;

	obj.maxlength = tam_mascara;
	
	//limpa o campo dos caracteres de formatação
    tam   = campo.length;
	//limpa o texto
	for (i=0; i<tam; i++)
	{
		for (j=0; j<tam_mascara; j++)
		{
			car_mask = mascara.charAt(j);				
			if ( car_mask != "#" )
			{				
				campo = campo.replace(car_mask, "");
			}
		}
	}

	tam   = campo.length;

	if ( tam > tam_mascara )
	{
		obj.value = obj.value.substring(0,mascara.length);	  
	  	return;
	}

	novo_valor = ""; 
    if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)
    {
 		idx_car = 0;
		for (i=0; i<tam_mascara; i++)
		{
			car 	 = campo.charAt(idx_car);
			car_mask = mascara.charAt(i);				

			if ( idx_car < tam )
			{
				if ( car_mask=="#" )
				{
					novo_valor += car;
					idx_car++;
					window.status = novo_valor;
				}
				else
				{
					novo_valor += car_mask;
				}
			}			
		}			

		obj.value = novo_valor;
	}
	
	
}
//---------------------------------------------------------------------------------------------------------

function VerificaBranco(campo,nomecampo)
{
	if ( campo.value == "" )
	{
		alert( nomecampo + " não pode estar em branco!");
        campo.focus();
		return false;
	}
	
return true;
}
//---------------------------------------------------------------------------------------------------------


//function TESTA()
// {
// if(VerifyCNPJ(document.forms[0].CNPJ.value) == 1)
//  {
//  alert("CNPJ válido!");
//  }
// else
//  {
//  alert("CNPJ não é válido!");
//  }
// document.forms[0].CNPJ.focus();
// return;
// }

//<body><p align=justify>Este é um modelo de código JavaScript que faz a validação de um número de CNPJ (o antigo CGC) brasileiro.</p>
//<form name=Form action='javascript: TESTA()'>Digite aqui o CNPJ: <input type='text' maxlength=18 name='CNPJ' onFocus='this.select();' OnKeyUp="FormataCGC('Form', 'CNPJ', event);"> <input type='button' value='VALIDA' onClick='TESTA();'></form><br><br>
//</body></html>

function NovaJanela(url,nome,cx,cy)
{
//resizable=1 
//scrollbars=1,
//fullscreen=1,
	return window.open(url,nome, "resizable=1,scrollbars=1,toolbar=1,menubar=1,left=0,top=0,,width="+ cx + ",height=" + cy);
}

function AbreDialogo(url,nome,cx,cy)
{
	return window.open(url,nome, "resizable=1,scrollbars=1,toolbar=0,menubar=0,width="+ cx + ",height=" + cy);
}

function ExecutaSubmit(newName,newValue)
{
	document.FORMCCK.OPERACAO.value = newValue;
	document.FORMCCK.OPERACAO.name = newName;
	document.FORMCCK.submit();
}

function SelEquip(idEquip,idCli,idUni,szEquip,szCli,szUni)
{
	document.FORMCCK.IDEQUIP.value = idEquip;
	document.FORMCCK.IDCLI.value = idCli;
	document.FORMCCK.IDUNI.value = idUni;

	document.FORMCCK.SZEQUIP.value = szEquip;
	document.FORMCCK.SZCLI.value = szCli;
	document.FORMCCK.SZUNI.value = szUni;
	document.FORMCCK.submit();
}

function CarregaMenu()
{
 	if( parent.frames[0] && parent.frames['cckweb_menu'].Go )
	{
		parent.frames['cckweb_menu'].Go()
	}
}

function ValidaData(pCtrDia,pCtrMes,pCtrAno)
{
ctrDia=null;
ctrMes=null;
ctrAno=null;

	if ( pCtrDia )
	{
		ctrDia = document.getElementById(pCtrDia);
		if ( ( ctrDia.value>31 ) || (ctrDia.value==0) )
		{
			alert("Dia inválido!\nFavor digitar novamente.");
			ctrDia.focus();			
			return false;		
		}
	}

	if ( pCtrMes )
	{
		ctrMes = document.getElementById(pCtrMes);
		if ( ( ctrMes.value>12 ) || (ctrMes.value==0) )
		{
			alert("Mês inválido!\nFavor digitar novamente.");
			ctrMes.focus();			
			return false;		
		}
	}
	
	if ( pCtrAno )
	{
		ctrAno = document.getElementById(pCtrAno);
		if ( ( ctrAno.value>3000 ) || (ctrAno.value<1990) )
		{
			alert("Ano inválido!\nFavor digitar novamente.");
			ctrAno.focus();			
			return false;		
		}
	}
	
	return true;
}

function ExibirOcultar(obj)
{
var el = document.getElementById(obj);
	if ( el )
	{
		if ( el.style.display == "none" )
		{
			el.style.display = "";
		}
		else
		{
			el.style.display = "none";
		}
	}
}
//----------------------------------------------------------------------------------------------------------

function ExibirOcultarEstado(obj,estado)
{
var el = document.getElementById(obj);
	if ( el )
	{
		el.style.display = (estado?"":"none");
	}
}
//----------------------------------------------------------------------------------------------------------

function ExibirOcultarPorControle(obj,controle_estado)
{
var el 			= document.getElementById(obj);
var el_estado  	= document.getElementById(controle_estado);
var estado 		= false;
	
	if ( el_estado )
	{
		estado = el_estado.checked;
	}
	
	if ( el )
	{
		el.style.display = (estado?"":"none");
	}
}
//----------------------------------------------------------------------------------------------------------

function encpu()
{
var txt_usuario= document.LOGIN.txtUsuario;
var txt_senha  = document.LOGIN.txtSenha;
var chave      = document.LOGIN.chave_enc.value;
	
	if ( !txt_usuario.value.length )
	{
		return false;	  
	}
		
	if ( !txt_senha.value.length )
	{
		return false;	  
	}
	
var enc_senha   = new String("");
var enc_usuario = new String("");
var sep = "";		
	
	for(i = 0; i < txt_usuario.value.length; i++)
	{
		if (i)
		{
			sep = ",";		  
		}
				
		enc_usuario = enc_usuario  + sep + (chave*txt_usuario.value.charCodeAt(i));
	}

	sep = "";		
	for(i = 0; i < txt_senha.value.length; i++)
	{
		if (i)
		{
			sep = ",";		  
		}
				
		enc_senha   = enc_senha+ sep + (chave*txt_senha.value.charCodeAt(i));
	}

	document.LOGIN.enc_txtUsuario.value = enc_usuario;
	document.LOGIN.enc_txtSenha.value = enc_senha;

	document.LOGIN.txtUsuario = "";
	document.LOGIN.txtSenha = "";
	document.LOGIN.txtSenha.value = "";
	document.LOGIN.txtUsuario.value = "";
	//document.LOGIN.chave_enc.value = "";

	return true;
}








