//**********************************************************************
// VERIFICA SE O NUMERO INDICA UM CGC
// PARAMETROS:
// Source -> TEXTO ORIGINAL
// RETORNO:
// TRUE SE E' UM CGC
// DEPENDENCIAS:
// IsInteger
//**********************************************************************
function IsCGC(Source)
{
	var Total=0;			//SOMA DOS DIGITOS
	var Digito1=0;			//DIGITO SUPERIOR
	var Digito2=0;			//DIGITO INFERIOR
	var Texto=""			//STRING DE TRABALHO
	
	Texto=Source;
	if (Texto!="")
	{//EXISTE VALOR
		if (Texto.length!=14)
		{// TAMANHO IMPROPRIO
			return(false);
		}//if
		if (!IsInteger(Texto))
		{// EXISTEM CARACTERES NAO NUMERICOS
			return(false);
		}//if
		Total=Texto.charAt(0)*6+Texto.charAt(1)*7+Texto.charAt(2)*8+Texto.charAt(3)*9+Texto.charAt(4)*2+Texto.charAt(5)*3+Texto.charAt(6)*4+Texto.charAt(7)*5+Texto.charAt(8)*6+Texto.charAt(9)*7+Texto.charAt(10)*8+Texto.charAt(11)*9;
		Digito1=Total%11;
		Digito1=Digito1%10;
		Total=Texto.charAt(0)*5+Texto.charAt(1)*6+Texto.charAt(2)*7+Texto.charAt(3)*8+Texto.charAt(4)*9+Texto.charAt(5)*2+Texto.charAt(6)*3+Texto.charAt(7)*4+Texto.charAt(8)*5+Texto.charAt(9)*6+Texto.charAt(10)*7+Texto.charAt(11)*8+Digito1*9;
		Digito2=Total%11;
		Digito2=Digito2%10;
		if ((Digito1!=Texto.charAt(12)) || (Digito2!=Texto.charAt(13)))
		{//DIGITO NAO CONFERE
			return(false);
		}//if
	}//if
	return(true);
}

