// JavaScript Document
//PRECISA DA FUNÇÃO trim QUE ESTÁ NO ARQUIVO stringUtils.js

function isValidEmail(email){
	
	var aEmail = String(trim(email));
	var exp_reg_email=/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/;

	if (aEmail.search(exp_reg_email)==-1)
		return false
	else
		return true;
}


function validaCPF(cpf) 
 {
   erro = new String;
	 
 	if (cpf.length == 11)
 	{	
 			cpf = cpf.replace('.', '');
 			cpf = cpf.replace('.', '');
 			cpf = cpf.replace('-', '');
 
 			var nonNumbers = /\D/;
 	
 			if (nonNumbers.test(cpf)) 
 			{
 					erro = "A verificacao de CPF suporta apenas números!"; 
 			}
 			else
 			{
 					if (cpf == "00000000000" || 
 							cpf == "11111111111" || 
 							cpf == "22222222222" || 
 							cpf == "33333333333" || 
 							cpf == "44444444444" || 
 							cpf == "55555555555" || 
 							cpf == "66666666666" || 
 							cpf == "77777777777" || 
 							cpf == "88888888888" || 
 							cpf == "99999999999") {
 							
 							erro = "Número de CPF inválido!"
 					}
 	
 					var a = [];
 					var b = new Number;
 					var c = 11;
 
 					for (i=0; i<11; i++){
 							a[i] = cpf.charAt(i);
 							if (i < 9) b += (a[i] * --c);
 					}
 	
 					if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
 					b = 0;
 					c = 11;
 	
 					for (y=0; y<10; y++) b += (a[y] * c--); 
 	
 					if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
 	
 					if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])) {
 						erro = "Número de CPF inválido.";
 					}
 			}
 	}
 	else
 	{
 		if(cpf.length == 0)
 			return false
 		else
 			erro = "Número de CPF inválido.";
 	}
 	if (erro.length > 0) {
// 			alert(erro);
// 			cpf.focus();
 			return false;
 	} 	
 	return true;	
 }

function onKeyupLimitedField(field, maxSize, spanCounter){
	caracteresDisponiveis = maxSize - field.value.length;
	if (caracteresDisponiveis <= 0){
		field.value = field.value.substring(0, maxSize-1);
		caracteresDisponiveis = 0;
	}
	if (spanCounter != null)
		spanCounter.innerHTML = caracteresDisponiveis;
		
}

