<!--

//////////////////////////////////////////////////////////////
function modulocgc(str) {
 soma=0;
 ind=2;
 for(pos=str.length-1;pos>-1;pos=pos-1) {
  soma = soma + (parseInt(str.charAt(pos)) * ind);
  ind++;
  if(str.length>11) {
	if(ind>9) ind=2;
	}
  }
 resto = soma - (Math.floor(soma / 11) * 11);
 if(resto < 2) {
  return 0;
  }
 else {
  return (11 - resto);
  }
}
function checa1cgc(str) {
 while (str.indexOf(".") > 0) {
	str = str.replace(".","")
 }
 while (str.indexOf("/") > 0) {
	str = str.replace("/","")
 }
 while (str.indexOf("-") > 0) {
	str = str.replace("-","")
 }
 while (str.indexOf(",") > 0) {
	str = str.replace(",","")
 }
 if (str.length >= 15) {
	 str =  str.substring(str.length - 15,str.length)
 }
else {
 while (str.length < 15) {
   str = '0' + str
  }
}
 //FormJuridica.Cgc.value = str
 if(!(modulocgc(str.substring(0,str.length - 2)).toString()+modulo(str.substring(0,str.length - 1)).toString() == str.substring(str.length - 2,str.length))) {
	  alert("Digite um CNPJ Valido");
	  return false;
 }
return true;
}
/////////////////////////////////////////////////////////////
function formatear_cpf(sCGC)
{
    var POS;
    if (sCGC == "") return;
    do {POS = sCGC.indexOf(".",0);
        if (POS == -1)break;
        sCGC = sCGC.substr(0, POS) + sCGC.substr(POS + 1);}
    while (POS !== -1);
    do {POS = sCGC.indexOf("/",0);
        if (POS == -1)break;
        sCGC = sCGC.substr(0, POS) + sCGC.substr(POS + 1);}
    while (POS !== -1);
    do {POS = sCGC.indexOf("-",0);
        if (POS == -1)break;
        sCGC = sCGC.substr(0, POS) + sCGC.substr(POS + 1);}
    while (POS !== -1);
    return sCGC;
}
function verificar_cpf(sCPF)
{
    if (sCPF == "") return 3;
    var i;
    var intDigito;
    var varQuociente;
    var iCPF = new Array();
    var iDig = new Array();
    sCPF=formatear_cpf(sCPF);
    if (sCPF == "") return 4;
    for (i = 1;i<10;i++) {
        iCPF[i] = sCPF.substr(i-1, 1);
        iCPF[i] = parseInt(iCPF[i]);}
    iDig[1] = sCPF.substr(9, 1);
    iDig[1] = parseInt(iDig[1]);
    iDig[2] = sCPF.substr(10, 1);
    iDig[2] = parseInt(iDig[2]);
    intDigito = (iCPF[9] * 2) + (iCPF[8] * 3) + (iCPF[7] * 4);
    intDigito = intDigito + (iCPF[6] * 5) + (iCPF[5] * 6) + (iCPF[4] * 7);
    intDigito = intDigito + (iCPF[3] * 8) + (iCPF[2] * 9) + (iCPF[1] * 10);
    intDigito = (intDigito * 10) % 11;
    if (intDigito == 10) intDigito = 0;
    if (intDigito !== iDig[1])return 1;
    intDigito = (iDig[1] * 2) + (iCPF[9] * 3) + (iCPF[8] * 4) + (iCPF[7] * 5);
    intDigito = intDigito + (iCPF[6] * 6) + (iCPF[5] * 7) + (iCPF[4] * 8);
    intDigito = intDigito + (iCPF[3] * 9) + (iCPF[2] * 10) + (iCPF[1] * 11);
    intDigito = (intDigito * 10) % 11;
    if (intDigito == 10) intDigito = 0;
    if (intDigito !== iDig[2]) return 2;
	return 0;
}

//////////////
function modulo(str) {
    	soma=0;
    	ind=2;
    	for(pos=str.length-1;pos>-1;pos=pos-1) {
    		soma = soma + (parseInt(str.charAt(pos)) * ind);
    		ind++;
    		if(str.length>11) {
    			if(ind>9) ind=2;
    		}
		}
    	resto = soma - (Math.floor(soma / 11) * 11);
    	if(resto < 2) {
	    	return 0
    	}
    	else {
    		return 11 - resto
    	}
	}

function checa1(valor) {
		cpfcompleto = valor
		valorfinal = cpfcompleto.replace(".","");
		valorfinalb = valorfinal.replace(".","");
		valor = valorfinalb.replace("-","")
		//alert(valor)
		if (valor.length != 11) {
    		alert("O CPF digitado não é válido.\nFavor Tente novamente!")
    		return false;
		}
    	if(modulo(valor.substring(0,valor.length - 2)) + "" +

modulo(valor.substring(0,valor.length - 1)) != valor.substring(valor.length - 2,valor.length)) {
    		alert("Os dados do seu CPF aparentam não ser válidos.\nRedigite-os sem pontos (.) traços (-) ou vírgulas (,).");
    		return false;
    	}
		return true;
	}
////////////////
var radiotipo
radiotipo = ""

function ValidacaoAssinatura(theForm)
{

  if (theForm.nome.value.length < 1)
  {
    alert("É necessário que você informe seu NOME ou RAZÃO SOCIAL.");
    theForm.nome.focus();
    return (false);
  }
  
  if(theForm.tipocadastro[0].checked == true)
  {
  	    if(!(checa1(theForm.documento.value)))
		{
			theForm.documento.focus()
			return false;
		}
  }
  if(theForm.tipocadastro[1].checked == true)
  {
  			with(theForm) {
				if(!(checa1cgc(documento.value))) {
					return false
					}
				return true;
				}
  }

  if (theForm.documento.value.length < 1)
  {
    alert("Você precisa digitar um CPF ou CNPJ válido.");
    theForm.documento.focus();
    return (false);
  }

  
  if (theForm.email.value.length < 6)
  {
    alert("É necessário que você informe seu E-MAIL.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.logradouro.value.length < 1)
  {
    alert("É necessário que você informe seu ENDEREÇO.");
    theForm.logradouro.focus();
    return (false);
  }
  

  if (theForm.numero_casa.value.length < 1)
  {
    alert("É necessário que você informe o NÚMERO de seu ENDEREÇO.");
    theForm.numero_casa.focus();
    return (false);
  }
  
  if (theForm.bairro.value.length < 1)
  {
    alert("É necessário que você informe o BAIRRO de seu ENDEREÇO.");
    theForm.bairro.focus();
    return (false);
  }

  if (theForm.cidade.value.length < 1)
  {
    alert("É necessário que você informe o CIDADE de seu ENDEREÇO.");
    theForm.cidade.focus();
    return (false);
  }
  
  if (theForm.estado.value.length < 1)
  {
    alert("É necessário que você informe o ESTADO de seu ENDEREÇO.");
    theForm.estado.focus();
    return (false);
  }

  if (theForm.cep.value.length < 8)
  {
    alert("É necessário que você informe o CEP de seu ENDEREÇO.");
    theForm.cep.focus();
    return (false);
  }

  if (theForm.ddd.value.length < 2)
  {
    alert("É necessário que você informe o DDD de seu TELEFONE.");
    theForm.cep.focus();
    return (false);
  }
  
  if (theForm.numero.value.length < 7)
  {
    alert("É necessário que você informe o NÚMERO de seu TELEFONE.");
    theForm.numero.focus();
    return (false);
  }
  
  return (true);
}

function FormataCPF(pForm,pCampo){
if(document.cadastro.tipocadastro[0].checked == true)
{
 var wTecla, wVr, wTam, pTamMax, pPos1, pPos2, pPosTraco, pTeclaPres;
 pTamMax = 11
 pPos1 = 8
 pPos2 = 5
 pPosTraco = 2
 pTeclaPres = event

       // alert(document.cadastro[pCampo].value);

 wTecla = pTeclaPres.keyCode;
 wVr = document.cadastro[pCampo].value;
 wVr = wVr.toString().replace( "-", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( "/", "" );
 wTam = wVr.length ;

 if (wTam < pTamMax && wTecla != 8) {
    wTam = wVr.length + 1 ;
 }

 if (wTecla == 8 ) {
    wTam = wTam - 1 ;
 }

 if ( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105 ){
  if ( wTam <= 2 ){
    document.cadastro[pCampo].value = wVr ;
  }
  if (wTam > pPosTraco && wTam <= pTamMax) {
        wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
  }
  if ( wTam == pTamMax){
        wVr = wVr.substr( 0, wTam - pPos1 ) + '.' + wVr.substr(wTam - pPos1, 3) + '.' + wVr.substr(wTam - pPos2, wTam);
  }
  document.cadastro[pCampo].value = wVr;

 }
}
}

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
     var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

     if(document.all) { // Internet Explorer
       nTecla = evtKeyPress.keyCode; }
     else if(document.layers) { // Nestcape
       nTecla = evtKeyPress.which;
     }

     sValue = objForm[strField].value;

     // Limpa todos os caracteres de formatação que
     // já estiverem no campo.
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( " ", "" );
     sValue = sValue.toString().replace( " ", "" );
     fldLen = sValue.length;
     mskLen = sMask.length;

     i = 0;
     nCount = 0;
     sCod = "";
     mskLen = fldLen;

     while (i <= mskLen) {
       bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
       bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

       if (bolMask) {
         sCod += sMask.charAt(i);
         mskLen++; }
       else {
         sCod += sValue.charAt(nCount);
         nCount++;
       }

       i++;
     }

     objForm[strField].value = sCod;

     if (nTecla != 8) { // backspace
       if (sMask.charAt(i-1) == "9") { // apenas números...
         return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
       else { // qualquer caracter...
         return true;
       } }
     else {
       return true;
     }
   }
//-->
