/*
**********************************************************************
*        Sistema: PXU                                                *
*       Programa: PXUSCFHM.JS                                        *
*      Descricao: Calculo de digito de controle, modulo 11           *
*       Analista: Ronaldo Rapacki                                    *
*    Programador: Alexandre Collatto                                 *
*           Data: Dezembro/94                                        *
*      Alteracao: Marco/99 - Diego Nobre                             *
*                 Conversao para 32 bits                             *
*  Ult.alteracao: Julho/2003 - Charles Diego da Silveira             *
*                 Conversão p/ JavaScript                            *
**********************************************************************
*/
var _pxuscfhm = true;

function pxuscfhm(numcpfc11)
{
	//*** DECLARAÇÃO DA ESTRUTURA DE PARAMETROS ***
	var xucfcodretornoc02='';
	var xucfnumcpfc11='';
	var xucfdigcpfc02='';
    
	function pxuscfhm()
	{
		var rcode_i,soma_i,resto_i,ind_i,indj_i,indk_i;
		var aux_nc;
		var numcpf_pi,digcpf_pc;
		
		//*** VALIDA O CPF INFORMADO ***
		if (this.xucfnumcpfc11.length > 11) {
			this.xucfcodretornoc02='01';
			return; }
		if (this.xucfnumcpfc11.substring(0,9) == '999999999' ||  
			this.xucfnumcpfc11.substring(0,9) == '000000000') {
			this.xucfcodretornoc02='01';
			return; }
		//*** VERIFICA SE NRO DE CPF SEM NC É VÁLIDO ***
		numcpf_pi='';
		for (ind_i=0;ind_i < 9;ind_i++)
		{
			if ((this.xucfnumcpfc11.substring(ind_i,ind_i+1) < '0') || 
				(this.xucfnumcpfc11.substring(ind_i,ind_i+1) > '9')) {
   				this.xucfcodretornoc02='01';
				return; }
			else {
				numcpf_pi += this.xucfnumcpfc11.substring(ind_i,ind_i+1);
			}
			
		}
		//*** VERIFICA SE NRO NC DO CPF É VÁLIDO ***
		if (((this.xucfnumcpfc11.substring(9,10) >= '0') && (this.xucfnumcpfc11.substring(9,10) <= '9') ||
			 (this.xucfnumcpfc11.substring(9,10) == ' ')) &&
			((this.xucfnumcpfc11.substring(9,10) >= '0') && (this.xucfnumcpfc11.substring(9,10) <= '9') ||
			 (this.xucfnumcpfc11.substring(9,10) == ' '))) {
			digcpf_pc=this.xucfnumcpfc11.substring(9,11);}
		else {
			this.xucfcodretornoc02='01';
			return; }
		
		//*** CALCULA NUMERO DE CONTROLE DO CPF ***
		for (indk_i = 8; indk_i < 10; indk_i++)
		{
			for (soma_i = 0, indj_i = 2, ind_i = indk_i; ind_i >= 0;ind_i--, indj_i++)
			{
				soma_i += numcpf_pi.substring(ind_i,ind_i+1) * indj_i;
			} 
			resto_i = soma_i % 11;
			if ((resto_i == 1) || (resto_i == 0)) {
				resto_i = 0; }
			else {
				resto_i = 11 - resto_i; }

			numcpf_pi += resto_i;
		}
		
		this.xucfdigcpfc02 = numcpf_pi.substring(9,11);
		
		if (((this.xucfdigcpfc02.substring(0,1) == digcpf_pc.substring(0,1)) &&
			 (this.xucfdigcpfc02.substring(1,2) == digcpf_pc.substring(1,2))) ||
			 (digcpf_pc.substring(0,1) == ' ') && 
			 (digcpf_pc.substring(1,2) == ' ')) {
			this.xucfcodretornoc02='00'; }
		else {
			this.xucfcodretornoc02='01'; }
	}
	
	//*** DECLARAÇÃO DO EVENTO DA PXU ***
    this.xucfnumcpfc11=numcpfc11;
    
    this.pxuscfhm=pxuscfhm;
}