<!--
function validaCPF(formulario)
{
//	alert("txtCPF="+formulario.txtCPF.value);
  if (formulario.txtCPF.value == ""){
      alert(" Você deve informar o CPF !");
      formulario.txtCPF.focus();
      return (false);
  }

	resultado = js_validateCPF(formulario.txtCPF.value);

//	alert("resultado="+resultado);
	
  if ( resultado == false){
      alert("CPF = "+formulario.txtCPF.value+" INVALIDO!");
      formulario.txtCPF.focus();
      return (false);
  }
}

function validaUsuario(formUsuario)
{
  if (formUsuario.txtNome.value == ""){
      alert("Informar o NOME!");
      formUsuario.txtNome.focus();
      return (false);
  }

 // if (formUsuario.txtCPF.value == ""){
 //     alert("Informar o CPF!");
 //     formUsuario.txtCPF.focus();
 //     return (false);
 // }
  if (formUsuario.dataNascimento.value == ""){
      alert("Informar Data de Nascimento!");
      formUsuario.dataNascimento.focus();
      return (false);
  }

  if (formUsuario.txtEndereco.value == ""){
      alert("Informar o ENDEREÇO!");
      formUsuario.txtEndereco.focus();
      return (false);
  }
  if (formUsuario.txtCidade.value == ""){
      alert("Informar NOME DA CIDADE!");
      formUsuario.txtCidade.focus();
      return (false);
  }

  if ( (formUsuario.txtFoneRes.value == "")  && 
	     (formUsuario.txtFoneCel.value == "") &&
	     (formUsuario.txtFoneCom.value == "") ) {	
        alert("Informar pelo menos um número TELEFONICO!");
        formUsuario.txtFoneRes.focus();
        return (false);
  } 

}

function validaCadastro(formUsuario)
{
  if (formUsuario.txtNome.value == ""){
      alert("Você deve informar o nome do USUÁRIO!");
      formUsuario.txtNome.focus();
      return (false);
  }

  if (formUsuario.dataNascimento.value == ""){
      alert("Informar Data de Nascimento!");
      formUsuario.dataNascimento.focus();
      return (false);
  }

  if (formUsuario.txtEndereco.value == ""){
      alert("Informar ENDEREÇO!");
      formUsuario.txtEndereco.focus();
      return (false);
  }
  if (formUsuario.txtCidade.value == ""){
      alert("Informar NOME DA CIDADE!");
      formUsuario.txtCidade.focus();
      return (false);
  }

  if ( (formUsuario.txtFoneRes.value == "")  && 
	     (formUsuario.txtFoneCel.value == "") &&
	     (formUsuario.txtFoneCom.value == "") ) {	
        alert("Informar pelo menos um número TELEFONICO!");
        formUsuario.txtFoneRes.focus();
        return (false);
  } 
}




//----------------------------------------------------------------------------
function FormataCpf(campo,tammax,teclapres) {
//----------------------------------------------------------------------------
 var tecla = teclapres.keyCode;
 // vr = document.form[campo].value;
 vr = event.srcElement.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( "-", "" );
 tam = vr.length;

 if (tam < tammax && 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 ){ 
    event.srcElement.value = vr ; }
   if ( (tam > 2) && (tam <= 5) ){
    event.srcElement.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 6) && (tam <= 8) ){
    event.srcElement.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 9) && (tam <= 11) ){
    event.srcElement.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 12) && (tam <= 14) ){
    event.srcElement.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 15) && (tam <= 17) ){
    event.srcElement.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 ) ;}
 }  
}
//----------------------------------------------------------------------------
function js_validateCPF(textVal)
//----------------------------------------------------------------------------
{
 var pattern1,pattern2,pattern3,result2,result3;

 pattern2 = /^0{9}|1{9}|2{9}|3{9}|4{9}|5{9}|6{9}|7{9}|8{9}|9{9}/;
 pattern3 = /^(\d|[\.\/\-\s]){11,14}$/; 

 result2 = textVal.match(pattern2);
 result3 = textVal.match(pattern3);

 switch (textVal) {
    case '000.000.000-00':
    case '111.111.111-11':
    case '123.456.789-09': 
    case '222.222.222-22': 
    case '333.333.333-33': 
    case '444.444.444-44': 
    case '555.555.555-55': 
		case '666.666.666-66':
    case '777.777.777-77': 
    case '888.888.888-88': 
    case '999.999.999-99':
		     return false;
 }

 if (result2 )  // se for null 
 {
    return false;             
 }
 else if( result3 ){      
      textVal = js_trimPreCPF(textVal);   
      var len = textVal.length;

      if (textVal.length == 11) {
          var last2digits = textVal.substring(textVal.length-2,textVal.length);
          var baseCPF = textVal.substring(0,9);
          var blnCheckSum = js_checkSum(baseCPF,last2digits);
          if (blnCheckSum){
              return true;
          } else {
//            open_window('erro.php?Msg=100');
//              alert("ERRO100 - CPF invalido!"); 
              return false;
          }
 } else {
//           open_window('erro.php?Msg=200'); 
//	         alert("ERRO200 - CPF invalido!");
    return false;
  }
 }
 else {
//           open_window('erro.php?Msg=999');
// 	         alert("ERRO999 - CPF invalido!"); 
    return false; 
 }
}
// -----------------------------------
// js_checkSum(baseCPF,checkSumDigits)
// -----------------------------------
function js_checkSum(baseCPF,checkSumDigits){
 var checkSumDigit1 = checkSumDigits.charAt(0);
 var checkSumDigit2 = checkSumDigits.charAt(1); 
 var checkSumDigit1_shouldBe = 0;
 var checkSumDigit2_shouldBe = 0;
 
 for (i=0,j=10; i<9; i++,j--) {
   checkSumDigit1_shouldBe += baseCPF.charAt(i) * j;
 }
 checkSumDigit1_shouldBe = ((checkSumDigit1_shouldBe * 10) % 11) % 10;
 
 for (i=0,j=11; i<9; i++,j--) {
   checkSumDigit2_shouldBe += baseCPF.charAt(i) * j;
 }
 checkSumDigit2_shouldBe += checkSumDigit1*2;
 checkSumDigit2_shouldBe = ((checkSumDigit2_shouldBe * 10) % 11) % 10;
 
 if(checkSumDigit1_shouldBe != checkSumDigit1 || checkSumDigit2_shouldBe != checkSumDigit2){
  return false;
 }
 else{
  return true;
 }
}

function js_trimPreCPF(preCPF)
{
 var tempTextVal = js_trimStr(preCPF);
 var len = tempTextVal.length;
 if (null==len || len<1)
  return "";
 
 var tempCPF = "";
 var charPosition = new Array();
 var count = 0;
 var pattern = /^\s|\/|\-|\.$/;
 
 for (var i=0; i<len; i++)//(tempTextVal.charAt(i)==".")
 {
  //nonspstr.test(textVal.charAt(i))
  if (pattern.test(tempTextVal.charAt(i))) 
  {
   charPosition[count]=i;
   count++;  
  }
    
 }
 
 if (charPosition.length > 0){
  for(i=0; i<charPosition.length; i++){
   if (i==0){
    if ( i==charPosition.length-1){
     tempCPF = tempCPF + tempTextVal.slice(0,charPosition[i]) + tempTextVal.slice(charPosition[i]+1);
    }else{
     tempCPF = tempCPF + tempTextVal.slice(0,charPosition[i]);
    }
   }else {
    if (i==charPosition.length-1) {
    tempCPF = tempCPF + tempTextVal.slice(charPosition[i-1]+1,charPosition[i]) + tempTextVal.slice(charPosition[i]+1);
   
    }else { 
    tempCPF = tempCPF + tempTextVal.slice(charPosition[i-1]+1,charPosition[i]);
    }
   }
  
  }
 return tempCPF ; 
 }
 else 
  return tempTextVal;
}

function js_trimStr(textVal)
{
 var len=textVal.length;
 if (null==len || len<1)
  return "";
 var trimleft = "";
 var nonspstr = /^\S$/;
 var spaceCount = 0;
 for (i=0; i<len; i++)
 {
  if ( nonspstr.test(textVal.charAt(i)) )
   break;
  else
   spaceCount++;
 }
 if (spaceCount==len)
  return "";
 else
  trimleft = textVal.slice(spaceCount);
 len = trimleft.length;
 spaceCount = 0;
 for (i=len-1; i > 0; i--)
 {
  if ( nonspstr.test(trimleft.charAt(i)) )
   break;
  else
   spaceCount++;
 }
 if (spaceCount==0)
  return trimleft;
 else
  return trimleft.slice(0, len-spaceCount);
}
//-->