function ajax() {
    try {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch(ex) {
            try {
                return new XMLHttpRequest();
            } catch(exc) {
                alert("Esse browser não tem recursos para uso do AJAX");
                return false;
            }
        }
    }
}
ajax1 = new ajax;




function somente_numero(campo){   
	var digits="0123456789"   
	var campo_temp   
	for (var i=0;i<campo.value.length;i++){   
		campo_temp=campo.value.substring(i,i+1)   
		if (digits.indexOf(campo_temp)==-1){   
			campo.value = campo.value.substring(0,i);   
		}   
	}   
}

function Validar(theCPF) {
  
  if (theCPF.value == "")
  {
    alert("Campo inválido. É necessário informar o CPF ou CNPJ");
    
	
	document.getElementById("bole_cpf").value = "";
	
    return (false);
  }
  if (((theCPF.value.length == 11) && (theCPF.value == 11111111111) || (theCPF.value == 22222222222) || (theCPF.value == 33333333333) || (theCPF.value == 44444444444) || (theCPF.value == 55555555555) || (theCPF.value == 66666666666) || (theCPF.value == 77777777777) || (theCPF.value == 88888888888) || (theCPF.value == 99999999999) || (theCPF.value == 00000000000)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }


  if (!((theCPF.value.length == 11) || (theCPF.value.length == 14)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = theCPF.value;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Favor preencher somente com dígitos o campo CPF/CNPJ.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }

  var chkVal = allNum;
  var prsVal = parseFloat(allNum);
  if (chkVal != "" && !(prsVal > "0"))
  {
    alert("CPF zerado !");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }

if (theCPF.value.length == 11)
{
  var tot = 0;

  for (i = 2;  i <= 10;  i++)
    tot += i * parseInt(checkStr.charAt(10 - i));

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(9)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }
  
  tot = 0;
  
  for (i = 2;  i <= 11;  i++)
    tot += i * parseInt(checkStr.charAt(11 - i));

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(10)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }
}
else
{
  var tot  = 0;
  var peso = 2;
  
  for (i = 0;  i <= 11;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(11 - i));
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(12)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }
  
  tot  = 0;
  peso = 2;
  
  for (i = 0;  i <= 12;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(12 - i));
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(13)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }
}

  return(true);
}

function Validar2(theCPF)
{
  
  if (theCPF.value == "")
  {
    alert("Campo inv&aacute;lido. É necess&aacute;rio informar o CPF ou CNPJ");
    
	
	document.getElementById("cartao_cpf").value = "";
	
    return (false);
  }
  if (((theCPF.value.length == 11) && (theCPF.value == 11111111111) || (theCPF.value == 22222222222) || (theCPF.value == 33333333333) || (theCPF.value == 44444444444) || (theCPF.value == 55555555555) || (theCPF.value == 66666666666) || (theCPF.value == 77777777777) || (theCPF.value == 88888888888) || (theCPF.value == 99999999999) || (theCPF.value == 00000000000)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("cartao_cpf").value = "";
    return (false);
  }


  if (!((theCPF.value.length == 11) || (theCPF.value.length == 14)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("cartao_cpf").value = "";
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = theCPF.value;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Favor preencher somente com dígitos o campo CPF/CNPJ.");
    document.getElementById("cartao_cpf").value = "";
    return (false);
  }

  var chkVal = allNum;
  var prsVal = parseFloat(allNum);
  if (chkVal != "" && !(prsVal > "0"))
  {
    alert("CPF zerado !");
    document.getElementById("cartao_cpf").value = "";
    return (false);
  }

if (theCPF.value.length == 11)
{
  var tot = 0;

  for (i = 2;  i <= 10;  i++)
    tot += i * parseInt(checkStr.charAt(10 - i));

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(9)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("cartao_cpf").value = "";
    return (false);
  }
  
  tot = 0;
  
  for (i = 2;  i <= 11;  i++)
    tot += i * parseInt(checkStr.charAt(11 - i));

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(10)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("cartao_cpf").value = "";
    return (false);
  }
}
else
{
  var tot  = 0;
  var peso = 2;
  
  for (i = 0;  i <= 11;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(11 - i));
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(12)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("cartao_cpf").value = "";
    return (false);
  }
  
  tot  = 0;
  peso = 2;
  
  for (i = 0;  i <= 12;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(12 - i));
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(13)))
  {
    alert("CPF/CNPJ inválido.");
    document.getElementById("cartao_cpf").value = "";
    return (false);
  }
}
  return(true);
}



<!--
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

	function autoTab(form_input,len, e)
	{
		var keyCode = (isNN) ? e.which : e.keyCode;
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		var Carac_digitados = 0;
		//alert("Form:" + form_input.value.length + "len" + len);
		if(form_input.value.length >= len && !containsElement(filter,keyCode))
		{
	    	form_input.value = form_input.value.slice(0, len);
			//alert("Form:" + form_input.value.length + "len" + len);  // form_input.value.length + ", " + form_input.value.length + ";"
			form_input.form[(getIndex(form_input)+1) % form_input.form.length].focus();
			//alert(form_input.value.length);
		}

		function containsElement(arr, ele)
		{
			var found = false, index = 0;
			while(!found && index < arr.length)
			if(arr[index] == ele)
			found = true;
			else
			index++;
			return found;
		}

		function getIndex(form_input)
		{
			var index = -1, i = 0, found = false;
			while (i < form_input.form.length && index == -1)
			if (form_input.form[i] == form_input)index = i;
			else i++;
			return index;
		}
		return true;
	}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function show1() {
	document.getElementById("d1").style.display = "block";
	document.getElementById("d2").style.display  = "none";
}

function hide1() {
	document.getElementById("d1").style.display  = "none";
	document.getElementById("d2").style.display  = "block";
}













function Validar3(theCPF) {
  
  if (theCPF.value == "")
  {
    alert("Campo inválido. É necessário informar o CNPJ");
    
	
	document.getElementById("bole_cpf").value = "";
	
    return (false);
  }


  if (theCPF.value.length != 14)
  {
    alert("CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = theCPF.value;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Favor preencher somente com dígitos o campo CNPJ.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }

  var chkVal = allNum;
  var prsVal = parseFloat(allNum);
  if (chkVal != "" && !(prsVal > "0"))
  {
    alert("CPF zerado !");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }

if (theCPF.value.length == 11)
{
  var tot = 0;

  for (i = 2;  i <= 10;  i++)
    tot += i * parseInt(checkStr.charAt(10 - i));

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(9)))
  {
    alert("CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }
  
  tot = 0;
  
  for (i = 2;  i <= 11;  i++)
    tot += i * parseInt(checkStr.charAt(11 - i));

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(10)))
  {
    alert("CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }
}
else
{
  var tot  = 0;
  var peso = 2;
  
  for (i = 0;  i <= 11;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(11 - i));
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(12)))
  {
    alert("CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }
  
  tot  = 0;
  peso = 2;
  
  for (i = 0;  i <= 12;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(12 - i));
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(13)))
  {
    alert("CNPJ inválido.");
    document.getElementById("bole_cpf").value = "";
    return (false);
  }
}
  return(true);
}


