//Valida e-mail
function evaluateEmail(obj) {     
    if (obj.search(/^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{ 1,3}){3}\])$/)==-1)
    {
		return false;
    }
    else
    {
		return true;           
	}
} 

//Valida um CPF (apenas números)
function evaluateCPF(cpf) {
	valor = true;
	erro = new String;
	if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";	
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
			erro += "Numero de CPF invalido!"
	}
	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 +="Digito verificador com problema!";
	}
	if (erro.length > 0){
		//alert(erro);
		return false;
	}
	return true;
}

//Limpa Todos os campos de um formulário
function clearForm(objForm) {
	for(i=0;i<=(objForm.length - 1);i++){
		vType = (objForm.item(i).name).substring(0,3)
		switch(vType){
			case "txt":
				(objForm.item(i)).value = ""
			case "chk":
				(objForm.item(i)).checked = false
			case "lst":
				(objForm.item(i)).selectedIndex = 0
		}
	}
}

//Aplica a mascara desejada a um campo texto
function maskFormat(mask,obj){
	if(obj.value != ""){
		sObj = obj.value.toString()
		nString = ""
		for(i=0;i<(sObj.length);i++){
			if(!isNaN(sObj.charAt(i)) && (sObj.charAt(i) != " ")) {
				nString = nString + sObj.charAt(i)
			}
		}
		j = 0
		k = 0
		mString = ""
		while(j < nString.length && k < mask.length){
			if(mask.charAt(k).toUpperCase() == "N"){
				mString = mString + nString.charAt(j)
				j = j+1
			} else {
				mString = mString + mask.charAt(k)
			}
			k = k+1
		}
		obj.value = mString
	}
}
function maskFormatPlate(obj){
	if(obj){
		if(obj.value != ""){
			sObj = obj.value.toString()
			nString = ""
			mask = "LLL-NNNN"
			for(i=0;i<(sObj.length);i++){
				if(i < 3){
					letter = sObj.charAt(i).toUpperCase();
					if((letter >= "A") && (letter <= "Z") && (sObj.charAt(i) != " ")) {
						nString = nString + letter
					}
				}else{
					if(!isNaN(sObj.charAt(i)) && (sObj.charAt(i) != " ")) {
						nString = nString + sObj.charAt(i)
					}
				}
			}
			j = 0
			k = 0
			mString = ""
			while(j < nString.length && k < mask.length){
				if(mask.charAt(k).toUpperCase() == "N" || mask.charAt(k).toUpperCase() == "L"){
					mString = mString + nString.charAt(j)
					j = j+1
				} else {
					mString = mString + mask.charAt(k)
				}
				k = k+1
			}
			obj.value = mString
		}
	}
}
//Mostra a dica do campo em um objeto SPAN de nome info
function msg_onfocus(msg) {
	info.innerHTML = msg
}

//Mostra o tamanho da caixa e texto ou textarea em um objeto SPAN passado em objCounter
function counter(obj, objCounter,maxLength){
	if(obj.value.length > maxLength){
		obj.value = (obj.value).substring(0,maxLength)
	}
	objCounter.innerHTML = "(" + (obj.value).length + "/" + maxLength + ")"
}

function validateFloat(Obj) {
	if (isNaN(Obj.value)) {
		val = Obj.value.toString()
		newval = ''
		for (i=0;i<=val.length;i++) {
			if (!isNaN(val.substring(i,i+1)) || val.substring(i,i+1) == '.' || val.substring(i,i+1) == ',') {
				if (val.substring(i,i+1) == ',') {
					newval = newval + '.'
				} else {
					newval = newval + val.substring(i,i+1)
				}
			}
		}
		Obj.value = newval
		Obj.focus()
	}
}

