//function soNumero(intMax)
function soNumero()
{
	var keyCode = event.keyCode;
	if (!(keyCode > 47 && keyCode < 58))
		event.keyCode = 0;
}
	
function autoTab(input,len, e)
{
	if (e == null && !isNN) e = event;
	if (len == null && !isNN) len = input.maxLength;	
	var isNN    = (navigator.appName.indexOf("Netscape") != -1);
	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 x;

	if((input.value.length >= len) && (!containsElement(filter,keyCode)))
	{
		input.value = input.value.slice(0, len);
		if((input.form[(getIndex(input)+1) % input.form.length].disabled)== false)
			input.form[(getIndex(input)+1) % input.form.length].focus();
		else
		{
			if((input.form[(getIndex(input)+2) % input.form.length].disabled)== false)
				input.form[(getIndex(input)+2) % input.form.length].focus();
			else
				input.form[(getIndex(input)+4) % input.form.length].focus();
		}
	}
	
	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(input)
	{
		var index = -1, i = 0, found = false;
		while ((i < input.form.length) && (index == -1))
		if (input.form[i] == input)
			index = i;
		else
			i++;
	
		return index;
	}
	return true;
}
	
function soNumeroFloat(fltMax)
{

}

function validarCpf(control){
	cpf = new String(control.value);
	cpf = clearCpfCnpj(cpf);	//limpa a formatação
	cpf = completeCpf(cpf);		//completa zeros à esquerda, caso necessário
	
	if(!validateCpf(cpf)){
		alert("CPF Inválido!\n");
		control.value="";
		control.focus();
		return false;
	}
}
function clearCpfCnpj(par){
    var cpfcnpj = new String(par);
    var tmp = "";
    for(var i=0;i<cpfcnpj.length;i++ ){
        if(cpfcnpj.charAt(i)!="." && cpfcnpj.charAt(i)!="/" && cpfcnpj.charAt(i)!="-")
            tmp = tmp + cpfcnpj.charAt(i);
    }
    return tmp;   
}
function completeCpf(cpf){
	/*********************************************************************
	O Função não aceita pontos ou traço	
	**********************************************************************/
	var s = new String(cpf);
	
	while(s.length < 11)
		s = "0" + s;
		
	return s;
}
function completeCnpj(cnpj){
	/*********************************************************************
	O Função não aceita pontos ou traço	
	**********************************************************************/
	var s = new String(cpf);
	
	while(s.length < 14)
		s = "0" + s;
		
	return s;
}
function validateCpf(cpf){
	/*********************************************************************
	Função aceita cpf sem pontos ou traço, ex: 71826547681
	Para limpar a formatação de um cpf no formato 718.265.476-81, utilize a função clearCpfCnpj().
	Para acrescentar zeros à esquerda do cpf, utilize a função completeCpf()
	**********************************************************************/
    var numeros, digitos, soma, i, resultado, digitos_iguais;
    digitos_iguais = 1;
    if (cpf.length < 11)
        return false;
    for (i = 0; i < cpf.length - 1; i++)
        if (cpf.charAt(i) != cpf.charAt(i + 1))
                {
                digitos_iguais = 0;
                break;
                }
    if (!digitos_iguais)
        {
        numeros = cpf.substring(0,9);
        digitos = cpf.substring(9);
        soma = 0;
        for (i = 10; i > 1; i--)
                soma += numeros.charAt(10 - i) * i;
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0))
                return false;
        numeros = cpf.substring(0,10);
        soma = 0;
        for (i = 11; i > 1; i--)
                soma += numeros.charAt(11 - i) * i;
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1))
                return false;
        return true;
        }
    else
        return false;
    }
function validateCnpj(cnpj){
	/*********************************************************************
	Função aceita cpf sem pontos ou traço.
	Para limpar a formatação de um cpf no formato 718.265.476-81, utilize a função clearCpfCnpj().
	Para acrescentar zeros à esquerda do cpf, utilize a função completeCpf()
	**********************************************************************/	  
  var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
  digitos_iguais = 1;
  if (cnpj.length < 14 && cnpj.length < 15)
		return false;
  for (i = 0; i < cnpj.length - 1; i++)
		if (cnpj.charAt(i) != cnpj.charAt(i + 1))
			  {
			  digitos_iguais = 0;
			  break;
			  }
  if (!digitos_iguais)
		{
		tamanho = cnpj.length - 2
		numeros = cnpj.substring(0,tamanho);
		digitos = cnpj.substring(tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i >= 1; i--)
			  {
			  soma += numeros.charAt(tamanho - i) * pos--;
			  if (pos < 2)
					pos = 9;
			  }
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0))
			  return false;
		tamanho = tamanho + 1;
		numeros = cnpj.substring(0,tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i >= 1; i--)
			  {
			  soma += numeros.charAt(tamanho - i) * pos--;
			  if (pos < 2)
					pos = 9;
			  }
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1))
			  return false;
		return true;
		}
  else
		return false;
} 	
function formatarData(objeto){
	
	if (((objeto.value.length == 2 || objeto.value.length == 5) && ((event.keyCode != 8) && event.keyCode != 46))){
		objeto.value = objeto.value+"/";
	}
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strDay=dtStr.substring(0,pos1);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy");
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month");
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day");
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date");
		return false
	}
return true
}
function validarData(control){
	if (isDate(control.value)==false){
		alert("Data inválida!");
		control.focus();
		return false
	}
    return true
 }


