// JavaScript Document
//VALIDA FORM

function ValidaSemPreenchimento(form){
	for (i=0;i<form.length;i++){
		if (form[i].getAttribute("obrigatorio") == 1){
			if (form[i].value == ""){
				var nome = form[i].name;
				alert("Campo de preenchimento obrigatório");
				form[i].focus();
				return false;
			}
		}
		if (form[i].getAttribute("ehemail") == 1){
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form[i].value))){
				alert("Por favor preencha o campo \"E-mail\" corretamente.\nO seu endereço não é um endereço válido.");
				form[i].focus();
				return false;
		 	}
		}
	}
	return true;
}

//tab entre campos
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % 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;
}

//mascara para campos
function formatar(src, mask){
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
	src.value += texto.substring(0,1);
  }
}

//produtos
function mostraItem(produto,itemmenu){
	document.getElementById('msginicial').className='invisivel';
	itemmenu.className = 'selecionado';
	document.getElementById(produto).className='visivel';
	//document.getElementById('itens_produtos').length;
}

function escondeItem(produto,itemmenu){
	document.getElementById('msginicial').className='visivel';
	itemmenu.className = 'nselecionado';
	document.getElementById(produto).className='invisivel';
	//document.getElementById('itens_produtos').length;
}