function SoNumeros(campo,e,max) //no campo do form usar "onKeyUp=SoNumeros(this,event,xxx);"
//substituir "xxx" pelo número máximo de caracteres que o campo aceita.
{
    myval = campo.value;
    if(window.event)//IE
        keycode = window.event.keyCode;
    else if (e) //FIREFOX e outros. É ' else if ' mesmo, senão não dá pra botar argumentos...
        keycode = e.which;
    if(!(keycode==8 || keycode==9 || (keycode > 47 && keycode < 58) || (keycode > 95 && keycode < 106)))
        myval = myval.substr(0,(myval.length-1));
    campo.value = myval;
    campo.focus();
} 


//Verifica se CPF é válido
//Se for válido, retorna TRUE, caso contrário retorna FALSE
function isCpf (numcpf)
{
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	numcpf1="";
	len = numcpf.length; x = len -1;
	// var numcpf = "12345678909";
	for (var i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x);
		x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	//alert ("Digito Verificador : " + dig1 + "" + dig2);
	if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return true;
	}
	return false;
}

function isDdd( value )
{
	if (value.length < 2)
		return false;
	
	return true;
}


function isTelefone( value )
{
	if (value.length < 8)
		return false;
	
	return true;
}

function isEmail( value )
{

    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(value) == "string"){
        if(er.test(value)){ return true; }
    }else if(typeof(value) == "object"){
        if(er.test(value.value)){
                    return true;
                }
    }else{
        return false;
	}
}


