

/*******************************************************/
/** ARQUIVO QUE CONTEM TODAS AS FUNCOES DE JAVASCRIPT **/
/*******************************************************/

 function verificaCEP(pCep) {
 
	var cep = document.frmCadastra.cep.value
	if (cep==""){
		alert("Preencha o campo cep!");
		document.frmCadastra.cep.focus()
		return false
		}
 }

 function buscaCEP(pCep) {
 
	//var cep = document.frmCadastra.cep.value
	//if (cep==""){
	//	alert("Preencha o campo cep!");
	//	document.frm1.frmCadastra.focus()
	//	return false
	//	}

//  location.href = "chamaCEP.asp?cepConsultado=" + pCep;
 }


/*****************************************************/
/*   FUNCAO QUE EXIBE UMA TABELA                     */
/*****************************************************/

function trocoExibe(numero) {
	if (numero == "1") {
		document.getElementById("ExibeFl").style.display="";
		document.getElementById("ExibeTroco").style.display="";
		document.getElementById("ExibeTicket").style.display="none";
	}
	else if (numero == "3") {
		document.getElementById("ExibeFl").style.display="";
		document.getElementById("ExibeTroco").style.display="none";
		document.getElementById("ExibeTicket").style.display="";	
	}
	else{
		document.getElementById("ExibeFl").style.display="none";
		document.getElementById("ExibeTroco").style.display="none";
		document.getElementById("ExibeTicket").style.display="none";
	}

}



/*****************************************************/
/* FUNCAO QUE MUTIPLICA O VALOR DA COMPRA
/*****************************************************/

function calcQtd(total,cd,qtd)
{	
	var soma;
	soma = cd*qtd;
	document.getElementById(total).value=soma;	
	
}
/*****************************************************/
/*   FUNCAO QUE EXIBE UMA TABELA                     */
/*****************************************************/

function MaisInfo(str,aux) {
	if (str == "E") 
		document.getElementById(aux).style.display="";	
	else
		document.getElementById(aux).style.display="none";
}




function MsgLista(varAux){
	if(varAux == '200'){
		alert("Itens adicionados a Lista de Compras!");
	}
	else if(varAux == '201'){
		alert("Itens adicionados e exluidos a Lista de Compras!");
	}
	else if(varAux == '202'){
		alert("Itens excluidos a Lista de Compras!");
	}
	else if (varAux == '300'){
		alert("Erro ao tentar cadastrar!\n\nE-mail já cadatrado.\n");
	}
	else if(varAux == '501'){
		alert("Erro ao tentar de Login!\n\nE-mail ou senha não conferem.\n");
	}
	else if(varAux == '500'){
		alert("Por Favor Faça o Login no site!\n");	
	}
}
//*****************************************************************************
//	TEXTO NA BARRA DE STATUS
//**************************************************************************
window.status = 'Padaria Laville';

//*****************************************************************************
//	FUNÇÃO PARA VALIDAR SE VARIAVEL ESTA EM BRANCO
//*****************************************************************************
function isEmpty(varData){
	for ( var i = 0 ; i < varData.length ; i++ ){
		if ( varData.substring( i, i+1 ) != " " )
			return false;
	}
	return true;
}


//*****************************************************************************
//	FUNÇÃO PARA VALIDAR CAMPO E-MAIL SE TEM @ . ETC...
//*****************************************************************************
function chkMail(varMail){
	
	if (varMail == "") return false;	
	var t = varMail;
	
	var Alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var Digit = '1234567890';
	var Symbol='_-';
	var check = '@.' + Alpha + Digit + Symbol;

	for (i=0; i < t.length; i++)
	   if(check.indexOf(t.substring(i,i+1)) < 0) 	{
		return false;
		}

	var check = '@';
	var a = 0;
	for (i=0; i < t.length; i++)
	  if(check.indexOf(t.substring(i,i+1)) >= 0) 	a = i;
	
	var check = '.';
	var b = 0;	
	for (i=a+1; i < t.length; i++)
		if(check.indexOf(t.substring(i,i+1)) >= 0) 	b = i;

	if (a != 0 && b != 0 && b != t.length-1 ) {
		return true;
	} else {
		return false;
	}

}

//*****************************************************************************
//	FUNÇÃO DE MASCARA
//*****************************************************************************
function FormataCampo(Campo,teclapres,mascara){
//pegando o tamanho do texto da caixa de texto com delay de -1 no event
//ou seja o caractere que foi digitado não ser encontado.
strtext = Campo.value
tamtext = strtext.length
//pegando o tamanho da máscara
tammask = mascara.length
//criando um array para guardar cada caractere da máscara
arrmask = new Array(tammask)
//jogando os caracteres para o vetor
for (var i = 0 ; i < tammask; i++){
arrmask[i] = mascara.slice(i,i+1)
}
//alert (teclapres.keyCode)
//começando o trabalho sujo
if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){
if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){
Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)
}
else{
Detona_Event(Campo,strtext)
}
} else {
if ((arrmask[tamtext] == "A")) {
charupper = event.valueOf()
//charupper = charupper.toUpperCase()
Detona_Event(Campo,strtext)
masktext = strtext + charupper
Campo.value = masktext
}
}
}
//Adiciona todos os caracteres que podem ser usados como máscara
function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){
if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){
separador = arrpos
masktext = strtext + separador
Campo.value = masktext
}
}
function Detona_Event(Campo,strtext){
event.returnValue = false
if (strtext != "") {
Campo.value = strtext
}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////
// VALIDAÇÕES DO PAINEL DE CONTROLE
///////////////////////////////////////////////////////////////////////////////////////////////////////

//*****************************************************************************
//	FUNCTION QUE COLOCA USUÁRIO NO RODAPÉ DO NAVEGADOR
//*****************************************************************************

function rodape(usuario,data)
{
window.status = 'Usuário: ' + usuario + '  /// Data: ' + data;
}


//*****************************************************************************
//	VALIDACAO PARA ESCLUSAO 
//*****************************************************************************
function Excluir(strURL){
	if(confirm('Você tem mais do que certeza que deseja excluir???'))
		{
			location.href='' + strURL + ''
		}
}


//*****************************************************************************
//	POPUP PARA CADASTRO
//*****************************************************************************

function PopSenha(cd){
	window.open('pop_senha.asp','url','width=300, height=310, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no')
}





//*****************************************************************************
//	POPUP AJUSTAVEL
//*****************************************************************************
function popup(str,wi,he,tool,loca,direc,stat,menu,scro,rezi){
	var conf = 'width=' + wi + ',height=' + he + ',toolbar=' + tool + ',location=' + loca + ',directories=' + direc + ',status=' + stat + ',menubar=' + menu + ',scrollbars=' + scro + ',resizable=' + rezi;
	window.open(str,'url',conf)
}

//**************************************************************************************
//PARA MOSTRAS AS IMAGENS
//**************************************************************************************
function ExibeImg(str) {
	if (str == "Exibe") {
	document.getElementById("viewFoto").style.display="";
	codigoIMG = document.frm.foto.value
	document.getElementById("foto").src="../img_thumbs/" + codigoIMG + ".jpg";
	}else {
	document.getElementById("viewFoto").style.display="none";
	}
}

//-----------------------------------------------------
/*FUNCAO QUE ABRE E FECHA O MENU*/
function ValidaInfo(str){
	frm.action='<%=Request.ServerVariables("SCRIPT_NAME")%>?valor=' + str;
	frm.submit();
}


//*****************************************************************************
//	VALIDACAO LOGIN
//*****************************************************************************
function chkFormLogin(form){
	
		if(!chkMail(form.email.value)){
			alert("E-mail incorreto!");
			form.email.focus();
			return false; 
		}
		
		if(isEmpty(form.senha.value)){
			alert("Digite sua Senha!");
			form.senha.focus();
			return false;
		}		
        return true;	
}
//*****************************************************************************
//	VALIDACAO CADASTRO
//*****************************************************************************
function chkFormCadastra(form){
		
		
		if(isEmpty(form.nome.value)){
			alert("Digite seu Nome!");
			form.nome.focus();
			return false;
		}
		
		if(!chkMail(form.email.value)){
			alert("E-mail incorreto!");
			form.email.focus();
			return false; 
		}
		if(isEmpty(form.senha.value)){
			alert("Digite a Senha!");
			form.senha.focus();
			return false;
		}
		if(isEmpty(form.csenha.value)){
			alert("Confime Sua Senha!");
			form.csenha.focus();
			return false;
		}
		
		if((form.senha.value) !== (form.csenha.value)){
			alert("Senhas Não Conferem!");
			form.senha.focus();
			return false;
		}
		
		if(isEmpty(form.ddd.value)){
			alert("Digite o DDD!");
			form.csenha.focus();
			return false;
		}
		if(isEmpty(form.telefone.value)){
			alert("Digite o Telefone!");
			form.telefone.focus();
			return false;
		}	
		if(isEmpty(form.cep.value)){
			alert("Digite o CEP!");
			form.cep.focus();
			return false;
		}	
        return true;		
}



//*****************************************************************************
//	VALIDACAO DO CARRINHO VAZIO
//*****************************************************************************
function chkProduto(form,num){
  	for (i=0; i<num; i++){
		var strAux = "produto"+i;
		var varAux = 0;
		
/*		if((form.document.getElementById(strAux).checked) ==! '' ){	
			varAux = 1;
		}
		if ( varAux == 1 ){
			return true;
		}*/
	}
//	form.document.getElementById(strAux).focus();
	//alert("Você não selecionou nenhum item do cardápio. \nClick na caixa de seleção próximo ao item desejado");
    //return false;
	return true;
}

/************************************************************************************************************************************************************************************************************/
/* F U N C 0A O   D O   P A I N E L
/************************************************************************************************************************************************************************************************************/

function chkFrmPainelUsuario(form){
		if(isEmpty(form.nome.value)){
			alert("Digite sua Nome!");
			form.nome.focus();
			return false;
		}
		if(isEmpty(form.login.value)){
			alert("Digite o login!");
			form.login.focus();
			return false;
		}		
		if(isEmpty(form.senha.value)){
			alert("Digite a Senha!");
			form.senha.focus();
			return false;
		}
		if(isEmpty(form.csenha.value)){
			alert("Confime Sua Senha!");
			form.csenha.focus();
			return false;
		}
		
		if((form.senha.value) !== (form.csenha.value)){
			alert("Senhas Não Conferem!");
			form.senha.focus();
			return false;
		}
		if(!chkMail(form.email.value)){
			alert("E-mail incorreto!");
			form.email.focus();
			return false; 
		}
        return true;	
}

function chkFrmPainelMenu(form){
		if(isEmpty(form.categoria.value)){
			alert("Selecione a categoria!");
			form.categoria.focus();
			return false;
		}
		if(isEmpty(form.descricao.value)){
			alert("Digite a Descrição!");
			form.descricao.focus();
			return false;
		}		
		if(isEmpty(form.cor.value)){
			alert("Selecione a Cor!");
			form.cor.focus();
			return false;
		}
		if(isEmpty(form.sequencia.value)){
			alert("Selecione a Sequencia!");
			form.sequencia.focus();
			return false;
		}   
		return true;	
}

function chkFrmPainelSubMenu(form){
		if(isEmpty(form.menu.value)){
			alert("Selecione o Menu!");
			form.menu.focus();
			return false;
		}
		if(isEmpty(form.categoria.value)){
			alert("Selecione a Categoria!");
			form.categoria.focus();
			return false;
		}		
		if(isEmpty(form.descricao.value)){
			alert("Digite a descrição");
			form.descricao.focus();
			return false;
		}
		if(isEmpty(form.imagem.value)){
			alert("Selecione a Categoria!");
			form.imagem.focus();
			return false;
		}   
		if(isEmpty(form.sequencia.value)){
			alert("Selecione a sequencia!");
			form.sequencia.focus();
			return false;
		}   
		return true;	
}

function chkFrmPainelProduto(form){
		if(isEmpty(form.categoria.value)){
			alert("Selecione o Menu!");
			form.categoria.focus();
			return false;
		}
		if(isEmpty(form.subcategoria.value)){
			alert("Selecione o Sub Menu!");
			form.subcategoria.focus();
			return false;
		}
		if(isEmpty(form.codigo.value)){
			alert("Digite o Codigo do Produto");
			form.codigo.focus();
			return false;
		}		

		if(isEmpty(form.preco.value)){
			alert("Digite o Preco!");
			form.preco.focus();
			return false;
		}
		return true;	
}


function chkFrmPainelPromocao(form){
		if(isEmpty(form.produto.value)){
			alert("Selecione o Produto!");
			form.produto.focus();
			return false;
		}
		if(isEmpty(form.imagem.value)){
			alert("Selecione a imagem!");
			form.imagem.focus();
			return false;
		}
		if(isEmpty(form.descricao.value)){
			alert("Digite a Descrição");
			form.descricao.focus();
			return false;
		}
		if(isEmpty(form.texto.value)){
			alert("Digite o Texto");
			form.texto.focus();
			return false;
		}	
		if(isEmpty(form.dataInicio.value)){
			alert("Selecione o Dia de Inicio!");
			form.dataInicio.focus();
			return false;
		}		
		if(isEmpty(form.dataFinal.value)){
			alert("Selecione o Dia de Termino!");
			form.dataFinal.focus();
			return false;
		}
		return true;	
}

function chkFrmPainelImagem(form){
		if(isEmpty(form.tipo.value)){
			alert("Selecione o Tipo!");
			form.tipo.focus();
			return false;
		}
		if(isEmpty(form.descricao.value)){
			alert("Digite a descricao!");
			form.descricao.focus();
			return false;
		}
		return true;	
}
/******************************************************/
/*CALEDARIO*/
/******************************************************/
function funToolCalendary(obj){
	if(ToolCalendary.style.left == 0) 
	{
	ToolCalendary.style.left=event.clientX+'px';
	ToolCalendary.style.top=event.clientY+'px';
	}
	frameToolCalendary.navigate('toolcalendary.asp?Instruction='+obj);
}
function MM_findObj(n,d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

/************************************************************************************/
/*funcoao que esconde os campos */
/************************************************************************************/
function saborQtd(strQtd)
{
	if(strQtd == '2'){
		document.getElementById("pizza1").style.display="";
		document.getElementById("pizza2").style.display="";
		document.getElementById("pizza3").style.display="none";
		document.getElementById("pizza4").style.display="none";
	}
	else if(strQtd == '3'){
		document.getElementById("pizza1").style.display="";
		document.getElementById("pizza2").style.display="";
		document.getElementById("pizza3").style.display="";
		document.getElementById("pizza4").style.display="none";
	}
	else if(strQtd == '4'){
		document.getElementById("pizza1").style.display="";
		document.getElementById("pizza2").style.display="";
		document.getElementById("pizza3").style.display="";
		document.getElementById("pizza4").style.display="";
	}
	else{
		document.getElementById("pizza1").style.display="none";
		document.getElementById("pizza2").style.display="none";
		document.getElementById("pizza3").style.display="none";
		document.getElementById("pizza4").style.display="none";
	}
}
