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 VerificaCPF(valor) {
	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=11){
		return false;
	}
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) {
			falso=false
		}
	}
	if (falso){
		return false;
	}
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) != valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}


// MUDA DE CAMPO (TEXT) AUTOMATICAMENTE (EX.: CEP)
function AutoNext(who, maxLength) 
{
	if (who.value.length == maxLength) 
	{
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) 
		{
			for (j=0; j<document.forms[i].elements.length; j++) 
			{
				if (document.forms[i].elements[j].name == who.name) 
				{
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == who.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				break;
			}
		}
	}
}
//

// SOMENTE NÚMEROS
function NumbersOnly()
{
    var tecla = window.event.keyCode;
    tecla     = String.fromCharCode(tecla);
    if(!((tecla >= "0") && (tecla <= "9")))
    {
        window.event.keyCode = 0;
    }
}

//

