function qtde_check_marcados(){
 var cont = 0;
 for (var i=0;i<document.form.elements.length;i++)
    if (document.form.elements[i].type=="checkbox")
	   if (document.form.elements[i].checked) 
	      cont++;
 return (cont);
}

function existe(nome){
 for (var i=0;(i<document.form.elements.length)&&(document.form.elements[i].name != nome);i++);
 return (i<document.form.elements.length) ;
}

function mudar(destino){
var f = document.form;
 f.action = destino;
 f.submit();	
}

function mudar_menu(destino){
var f = document.form;
 f.action = destino;
 f.categoria.value = ''; 
 f.submit();	
}

function mudar_file(destino){
var f = document.form;
 f.action = './';
 f.categoria.value = '';
 f.mfile.value = destino; 
 f.submit();	
}

function mudar_redirec(destino){
var f = document.formRedirec;
 f.action = './';
 f.mfile.value = destino; 
 f.submit();	
}

function adicionar_item(id){
var f = document.form;
 f.id_item.value = id;
 f.submit();	
}

function mudar_href(destino){
 location.href = destino;
}

function enviar(destino){
 var f = document.form;
 if (!verifica_se_vazio(f.filtro.value)) {
   f.action = destino;
   f.submit();	
   } else {           
           f.filtro.focus();
		   alert('Por favor, preencha o campo pesquisar!');		   
		  }
}

function verifica_se_vazio(str){
 var i=0;
 while(str.charAt(i)==' ')
     i++; 	  
	 	 
 if (str.length == i)
    return true;
 else return false;	
}

function pesq_menu(categoria,descricao){
 var f = document.form;
 f.menu.value = '1';
 f.descricao.value = descricao;
 f.categoria.value = categoria;
 f.action = './';
 f.submit();	
}

function pesquisar(){
 var f = document.form;
 if (!verifica_se_vazio(f.filtro.value)) {
  f.pagina_atual.value = '0';
  f.action = '';
  f.submit();	
 } else {
         f.filtro.focus();
		 alert('Por favor, preencha o campo pesquisar!');
		 }
}

function abrir(nome_imagem,id_produto){
 window.open('adm/include/popup_imagem.php?id_imagem='+nome_imagem+'&id_produto='+id_produto,'imagem'+nome_imagem,'resizable=no,scrollbars=no,width=270,height=325');
}

function foto_evento(nome_imagem){
 window.open('adm/include/imagens_eventos.php?id_imagem='+nome_imagem,'fotos_encontro'+nome_imagem,'resizable=no,scrollbars=no,width=630,height=520');
}

function limpar_cesta(){
 if (confirm ("Tem certeza que deseja limpar a cesta de pedidos?")) {
  document.form.deletar_itens.value = 'todos';
  mudar_file('5');
  }
}

function deletar_cesta(){
 var qtde = qtde_check_marcados(); 
 if (qtde) {
   var msg = (qtde==1) ? "Tem certeza que deseja deleta o item selecionado?" : "Tem certeza que deseja deletar os itens selecionados?";  
   if (confirm (msg)) {
     document.form.deletar_itens.value = 'selecao';
     mudar_file('5');
   }
 }  
 else alert("Não existe nenhum item selecionado!");  
}

function login_cliente(tipo){ 
 document.form.login_usuario.value = tipo;
 if (tipo=='1') {
      if (document.form.login_email.value == '') {
	    alert('Por favor, preecha o campo email!');
		document.form.login_email.focus();
	  } else
	  if (document.form.login_senha.value == '') {
	    alert('Por favor, preecha o campo senha!');
		document.form.login_senha.focus();
	  } else {
         document.form.email.value = document.form.login_email.value;
	     mudar_file('6');
		 }	 
	}
 else if (tipo=='0'){
       if (document.form.cadastro_email.value == ''){	      
	      alert('Por favor, preecha o campo email!');
		  document.form.cadastro_email.focus();
		  }
	   else {
	         document.form.email.value = document.form.cadastro_email.value;
			 mudar_file('7'); 	
			} 
	    } 
 else {
         if (document.form.login_email.value == '') {
	        alert('Por favor, preecha o campo email acima para solicitar sua senha!');
		    document.form.login_email.focus();
	       }
		 else  {
		        document.form.email.value = document.form.login_email.value;
			    mudar_file('12'); 	
		       }       
      }	  
	  
}

function cliente_sair(){
 if (confirm('Deseja realmente efetuar Logout?')) {
   document.form.sair_cliente.value = '1';
   mudar_file('8'); 
 }
}

function enviar_conta(acao,destino){
 document.form.acao_conta.value = acao;
 mudar_file(destino);
}
