// ===========================================
//						MASCARAS 
// ===========================================
// onkeypress="Formata(this, '§§/§§/§§§§', event)"
function Formata(campo, mask, evt) { 
	if(document.all) { // Internet Explorer 
		key = evt.keyCode; 
	} else{ // Nestcape 
		key = evt.which; 
	} 
	teclasPermitidas = Array(0, 8, 13);
	for (i=0; i < teclasPermitidas.length; i++) {
		if (key == teclasPermitidas[i]) return true;
	}

	string = campo.value;  
	i = string.length;
	if (i < mask.length) {
		if (mask.charAt(i) == '§') {
			return (key > 47 && key < 58);
		} else {
			if (mask.charAt(i) == '!') {
				return true;
			}
			for (c = i; c < mask.length; c++) {
				if (mask.charAt(c) != '§' && mask.charAt(c) != '!')
					campo.value = campo.value + mask.charAt(c);
				else if (mask.charAt(c) == '!'){
					return true;
				} else {
					return (key > 47 && key < 58);
				}
			}
		}
	} else return false;
}
// ===========================================
//								VALIDAÇÕES 
// ===========================================

function validaVazio(obj, msgErro) {
    if (obj.value == "") {
	   alert(msgErro);
	   obj.focus();
	   return true;
    }
    return false;
}


function valida_mail(valor) {
	   prim = valor.indexOf("@")
	   if(prim < 1) return false;
	   if(valor.indexOf("@",prim + 1) != -1) return false;
	   if(valor.indexOf(".") < 1) return false;
	   if(valor.indexOf("zipmeil.com") > 0) return false;
	   if(valor.indexOf("hotmeil.com") > 0) return false;
	   if(valor.indexOf(".@") > 0) return false;
	   if(valor.indexOf("@.") > 0) return false;
	   if(valor.indexOf(".com.br.") > 0) return false;
	   if(valor.indexOf("/") > 0) return false;
	   if(valor.indexOf("[") > 0) return false;
	   if(valor.indexOf("]") > 0) return false;
	   if(valor.indexOf("(") > 0) return false;
	   if(valor.indexOf(")") > 0) return false;
	   if(valor.indexOf("..") > 0) return false;
	   if(valor.indexOf(",") > 0) return false;
	   return true;

}

function ValidaData(valor) {
	if (valor.length == 0)
		return true;
	else if (valor.length != 10)
		return false;

	var dia = valor.substr(0, 2);
	var mes = valor.substr(3, 2);
	var ano = valor.substr(6, 4);

	if (!ValidaNum(dia)) return false;
	if (!ValidaNum(mes)) return false;
	if (!ValidaNum(ano)) return false;

	if (mes > 12 || mes < 1) return false;
	if (dia < 1) return false;
	if (ano < 1) return false;
	if ((mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12) && dia > 31) return false;
	if ((mes == 4 || mes == 6 || mes == 9 || mes == 11) && dia > 30) return false;
	if (mes == 2 && (((ano % 4) == 0 && (ano % 100) != 0) || (ano % 400) == 0) && dia > 29) return false;
	if (mes == 2 && !(((ano % 4) == 0 && (ano % 100) != 0) || (ano % 400) == 0)  && dia > 28) return false;
	return true;
}

function ValidaNum(NUM) {
	for (var i = 0; i < NUM.length ; i++) {
		if (NUM.substring(i, i + 1) < '0' || NUM.substring(i, i + 1) > '9') {
			return false;
		}
	}
	return true;
}

function FormataInteiro(campo, event) {
	var strNumeros = '0123456789';

	for (i = 0; i < campo.value.length; i++)
		if ((strNumeros.indexOf(campo.value.substr(i, 1)) == -1) && !((i == 0) && (campo.value.substr(i, 1) == '-'))) {
			campo.value = campo.value.substr(0, i);
			return false;
		}
}

function trim(valor)
{
	return valor.replace(/^\s*/, "").replace(/\s*$/, "");
} //String.trim

