function VerificaDados(form)
{
	for (i = 0; i < requiredfields.length; i++) {
		obj = form[requiredfields[i]];
		if (obj.value == "") return mensagemErro(requireddescs[i],requiredfields[i],obj);
	}
	return true;
}

function VerificaValores(form)
{
	for (i = 0; i < valFieldsNames.length; i++) {
		obj   = form[valFieldsNames[i]];
		valor = ucNumero(obj.value)/1;
		if (valor == 0) return mensagemErro(valFieldsDescs[i],valFieldsNames[i],obj);
	}
	return true;
}

function verificaEmail(obj)
{
	if (obj.value == "") return true;
	var filtro = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filtro.test(obj.value) == false) return erroForm(obj, 'E-mail');
	return true;
}

function verificaCPFCNPJ(obj)
{
	form = obj.form;
	if (form.tipoPessoa.value == "2") return verificaCPF(obj);
	else if (form.tipoPessoa.value == "1") return verificaCNPJ(obj);
}

function verificaCPF (obj)
{
	if (obj.value == "") return true;

	var soma1, soma2, s1, s2;

	var form = obj.form;
	var cpf  = obj.value;

	var str_cpf = "";
	var verifzero = 0;

	for (i = 0; i <= cpf.length - 1; i++)
	if ((cpf.charAt(i)).match(/\d/)) {
		str_cpf += cpf.charAt(i);
		verifzero+=cpf.charAt(i);
	}
	else if (!(cpf.charAt(i)).match(/[\.\-]/)) return erroForm(obj, 'CPF');

	if (str_cpf.length != 11) return erroForm(obj, 'CPF');

	if (verifzero==0) return erroForm(obj, 'CPF');

	if (str_cpf==11111111111 || str_cpf==22222222222 || str_cpf==33333333333 || str_cpf==44444444444 || str_cpf==55555555555 || str_cpf==66666666666 || str_cpf==77777777777 || str_cpf==88888888888 || str_cpf==99999999999) return erroForm(obj, 'CPF');

	soma1 = soma2 = 0;
	for (i = 0; i <= 8; i++) {
		soma1 += str_cpf.charAt(i) * (10-i);
		soma2 += str_cpf.charAt(i) * (11-i);
	}
	s1 = ((soma1 * 10) % 11) % 10;
	s2 = (((soma2 + (s1 * 2)) * 10) % 11) % 10;

	if ((s1 != str_cpf.charAt(9)) || (s2 != str_cpf.charAt(10))) return erroForm(obj, 'CPF');

	return true;
}

function verificaCNPJ(obj)
{
	if (obj.value == "") return true;

	CNPJ = obj.value;
	erro = new String;
	if (CNPJ.length < 18) return erroForm(obj, 'CNPJ');
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")) {
		if (erro.length == 0) return erroForm(obj, 'CNPJ');
	}
	//substituir os caracteres que não são números
	if(document.layers && parseInt(navigator.appVersion) == 4){
		x = CNPJ.substring(0,2);
		x += CNPJ. substring (3,6);
		x += CNPJ. substring (7,10);
		x += CNPJ. substring (11,15);
		x += CNPJ. substring (16,18);
		CNPJ = x;
	} else {
		re1  = /\./gi;
		re2  = /\-/gi;
		re3  = /\//gi;
		CNPJ = CNPJ. replace (re1,"");
		CNPJ = CNPJ. replace (re2,"");
		CNPJ = CNPJ. replace (re3,"");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) return erroForm(obj, 'CNPJ');
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++){
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	b = 0;
	for (y=0; y<13; y++) {
		b += (a[y] * c[y]);
	}
	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])) return erroForm(obj, 'CNPJ');
	if (erro.length > 0) return erroForm(obj, 'CNPJ');
	else return true;
	return true;
}

function verificaCEP(obj)
{
	cep = obj.value;
	cepDesformatado = cep.substr(0,2)+cep.substr(3,3)+cep.substr(7,3);

	if (cep != "")
	{
		if (cep.length < 10) return erroForm(obj, 'CEP');
		else if (cepDesformatado.length != 8) return erroForm(obj, 'CEP');
		else if ((cepDesformatado / 1) == 0) return erroForm(obj, 'CEP');
		else if ((cepDesformatado.substr(2,6)/1) == 0) return erroForm(obj, 'CEP');
		else if ((cepDesformatado == "11111111") || (cepDesformatado == "22222222") || (cepDesformatado == "33333333") || (cepDesformatado == "44444444") || (cepDesformatado == "55555555") || (cepDesformatado == "66666666") || (cepDesformatado == "77777777") || (cepDesformatado == "88888888") || (cepDesformatado == "99999999")) return erroForm(obj, 'CEP');
	}
	return true;
}

function VerificaData(obj, permiteMaior, permiteMenor)
{
	if (obj.value == "") return true;
	else if (permiteMenor == undefined) permiteMenor = 0;

	data = obj.value;
	if (data.length == 6)
	{
		data = data.substr(0,2) + '/' + data.substr(2,2) + '/' + '20'  + data.substr(4,2);
		obj.value = data;
	}

	barras = data.split("/");
	if (barras.length == 3)
	{
		dia = barras[0];
		mes = barras[1] - 1;
		ano = barras[2];
		if (ano < 2000) ano = ano.substr(2, 2);
		else anoAux = ano - 1900;

		newData = new Date(ano, mes, dia);
		today   = new Date();

		if (newData.getMonth() != Number(mes) || newData.getDate() != Number(dia) || (newData.getYear() != Number(ano) && newData.getYear() != Number(anoAux))) return erroForm(obj, 'Data');
		else if (permiteMaior == 0 && newData > today) return erroForm(obj, 'Data', 'Erro! Você entrou com uma data futura.');
		else if (permiteMenor == 0 && newData < today) return erroForm(obj, 'Data', 'Erro! Você entrou com uma data passada.');
	} else return erroForm(obj, 'Data');
}

function VerificaMoeda(obj, event)
{
	tecla = event.keyCode;
	if (teclasIgnore.in_array(tecla)) { return; }

	if (obj.value.indexOf(',') > -1)
	{
		arrAux = obj.value.split(',');
		if (arrAux[1].length == 2) autoTab(obj, -1, event);
	} else {
		if (obj.value.length >= 7) obj.value = obj.value.substr(0,7);
	}
}