function soNum(evt) {
  //  evt = (evt) ? evt : window.event
  //  var charCode = (evt.which) ? evt.which : evt.keyCode
  //  if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57 )) { 
   //     return false
   // }
    return true
}
function checkMail(mail){
        var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
        if(typeof(mail) == "string"){
                if(er.test(mail)){ return true; }
        }else if(typeof(mail) == "object"){
                if(er.test(mail.value)){ 
                                        return true; 
                                }
        }else{
                return false;
                }
}

function selClasse(classe){
	window.open('loja.php?cls='+classe,'_self')
}
function selSubClasse(classe,subclasse){
	window.open('loja.php?cls='+classe+'&subcls='+subclasse,'_self')
}
function ordenaBusca(opcao){
	window.open('loja.php?ord='+opcao,'_self')
}
function filtraFabricante(fabr){
	window.open('loja.php?fabr='+fabr,'_self')
}
function mudaPg(pagina){
	window.open('loja.php?pg='+pagina,'_self')
}
function produto(codigo){
	window.open('loja.php?produto='+codigo,'_self')
}


function apagaBanner(codigo){
	if (confirm('Deseja excluir TODOS os produtos da Banner?')) {
		var handleSubmit = {
			success:function( args){},
			failure:function( args){
				alert(args.responseText)
			}
		};
		YAHOO.util.Connect.asyncRequest('GET', 'ajax/delBanner.php?codigo='+codigo, handleSubmit);
	}
}
function selecionaBanner(qual,codigo){
	var handleSubmit = {
		success:function( args){
			alert("Produto incluido como Banner!")
		},
		failure:function( args){
			alert(args.responseText)
		}
	};
	YAHOO.util.Connect.asyncRequest('GET', 'ajax/selBanner.php?codigo='+codigo+'&qual='+qual, handleSubmit);
}

function apagaPromocao(codigo){
	if (confirm('Deseja excluir TODOS os produtos da Promocao?')) {
		var handleSubmit = {
			success:function( args){},
			failure:function( args){
				alert(args.responseText)
			}
		};
		YAHOO.util.Connect.asyncRequest('GET', 'ajax/delPromocao.php?codigo='+codigo, handleSubmit);
	}
}
function selecionaPromocao(qual,codigo){
	var handleSubmit = {
		success:function( args){
			alert("Produto incluido como Promocao!")
		},
		failure:function( args){
			alert(args.responseText)
		}
	};
	YAHOO.util.Connect.asyncRequest('GET', 'ajax/selPromocao.php?codigo='+codigo+'&qual='+qual, handleSubmit);
}
function apagaDestaque(codigo){
	if (confirm('Deseja excluir TODOS os produtos dos Destaques?')) {
		var handleSubmit = {
			success:function( args){},
			failure:function( args){
				alert(args.responseText)
			}
		};
		YAHOO.util.Connect.asyncRequest('GET', 'ajax/delDestaque.php?codigo='+codigo, handleSubmit);
	}
}
function selecionaDestaque(qual,codigo){
	var handleSubmit = {
		success:function( args){
			alert("Produto incluido como destaque!")
		},
		failure:function( args){
			alert(args.responseText)
		}
	};
	YAHOO.util.Connect.asyncRequest('GET', 'ajax/selDestaque.php?codigo='+codigo+'&qual='+qual, handleSubmit);
}
function continuarComprando() {
	document.getElementById("carrinhoDIV").style.display ='none';
	document.getElementById("produtoDIV").style.display ='none';
	document.getElementById("conteudoDIV").style.display ='block';
	document.getElementById("menuvertDIV").style.display ='block';
}

function mostraInfo(qual){
	window.open('info.php?qual='+qual,'_self')
	
}
function info(results){
	document.getElementById("infoDIV").innerHTML = results
}
function excluiFoto(qual){
	if (confirm('Confirma a exclus&atilde;o da foto do produto?')) {
		var handleSubmitOrd = {
			success:function( args){
				window.open('loja.php?produto='+args.responseText,'_self')
			},
			failure:function( args){
				alert(args.responseText)
			} 
		}
		try{
			YAHOO.util.Connect.asyncRequest('GET', 'produtos/excluirFoto.php?qual='+qual, handleSubmitOrd);
		}catch(e){}	
	}
}
function excluiManual(qual){
	if (confirm('Confirma a exclus&atilde;o deste documento do produto?')) {
		var handleSubmitOrd = {
			success:function( args){
				window.open('loja.php?produto='+args.responseText,'_self')
			},
			failure:function( args){
				alert(args.responseText)
			} 
		}
		try{
			YAHOO.util.Connect.asyncRequest('GET', 'produtos/excluirManual.php?qual='+qual, handleSubmitOrd);
		}catch(e){}	
	}
}
function verNum(campo) {
	ret='';
	for (a=0;a<campo.value.length;a++)
	if ('0123456789'.indexOf(campo.value.charAt(a))>=0) ret+=campo.value.charAt(a)
	if (ret!=campo.value) campo.value=ret
}

function soNumeros(event)
{
  validos = "1234567890";
  if(navigator.appName.indexOf("Microsoft") != -1)
    caracter = String.fromCharCode(event.keyCode);
  else {
    caracter = String.fromCharCode(event.which);
    if((event.which == 8)||(event.which == 0)) return true;
  }
  if(validos.indexOf(caracter) != -1)
    return true;
  else
    return false;
}





function mudaQuantidade(codigo,quant) {
	var r=document.getElementById("estoque").value;
	var est=parseInt(r);
	erroLocal=0;
	if (quant>est) {		
		document.getElementById("quantidade").value=est;
		quant=est;
		erroLocal=1;
	}
	
	var handleSubmitOrd = {
		success:function( args){
			if (erroLocal==1) document.getElementById("pedidoDIVok").innerHTML ='&raquo; Quantidade alterada para a disponibilidade de estoque.<br><br><a href="javascript:continuarComprando()"><img src="imagens/continuarComprando.gif" width="144" height="16" alt=""></a><br><br><a href="carrinho.php"><img src="imagens/finalizarCompra.gif" width="144" height="16" alt=""></a>';
			else document.getElementById("pedidoDIVok").innerHTML ='&raquo; Quantidade alterada com sucesso!<br><br><a href="javascript:continuarComprando()"><img src="imagens/continuarComprando.gif" width="144" height="16" alt=""></a><br><br><a href="carrinho.php"><img src="imagens/finalizarCompra.gif" width="144" height="16" alt=""></a>';
		},
		failure:function( args){
			alert(args.responseText)
		} 
	}
	try{
		YAHOO.util.Connect.asyncRequest('GET', 'produtos/altQuantCarrinho.php?valor='+codigo+'&quant='+quant, handleSubmitOrd);
	}catch(e){}	
}
function colocarItemCarrinho(codigo) {
	var handleSubmitOrd = {
		success:function( args){
			document.getElementById("colocarCarrinhoDIV").style.display ='none';
			document.getElementById("pedidoDIV").style.display ='block';
			document.getElementById("pedidoDIVok").innerHTML ='&raquo; Produto colocado em seu carrinho com sucesso!<br><br><a href="javascript:continuarComprando()"><img src="imagens/continuarComprando.gif" width="144" height="16" alt=""></a><br><br><a href="carrinho.php"><img src="imagens/finalizarCompra.gif" width="144" height="16" alt=""></a>';
			document.getElementById("quantCarrinho").innerHTML =args.responseText;
		},
		failure:function( args){
			alert(args.responseText)
		} 
	}
	try{
		YAHOO.util.Connect.asyncRequest('GET', 'produtos/colocarCarrinho.php?valor='+codigo, handleSubmitOrd);
	}catch(e){}	
}
function removerItemCarrinho(codigo,lista) {
	var handleSubmitOrd = {
		success:function( args){
			if (lista!=1) {
				document.getElementById("colocarCarrinhoDIV").style.display ='block';
				document.getElementById("pedidoDIV").style.display ='none';
				document.getElementById("pedidoDIVok").innerHTML ='&raquo; Produto retirado do carrinho.<br><br><a href="javascript:continuarComprando()"><img src="imagens/continuarComprando.gif" width="144" height="16" alt=""></a><br><br><a href="carrinho.php"><img src="imagens/finalizarCompra.gif" width="144" height="16" alt=""></a>';
				
				document.getElementById("quantCarrinho").innerHTML =args.responseText;
				
			}
			else {
				document.getElementById("lista"+codigo).style.display ='none';
				document.getElementById('somaTotal').innerHTML=args.responseText;
			}
		},
		failure:function( args){
			alert(args.responseText)
		} 
	}
	try{
		YAHOO.util.Connect.asyncRequest('GET', 'produtos/excCarrinho.php?valor='+codigo+'&lista='+lista, handleSubmitOrd);
	}catch(e){}	
}


function enviarPedido(){
	var handleSubmitOrd = {
		success:function( args){
			//document.getElementById("carrinhoDIV").innerHTML =args.responseText
			document.getElementById("carrinhoDIV").innerHTML ='<div align="center"><br><br><br><br><br><br><b>Pedido processando com sucesso!</b><br>Você pode verificar seus pedidos clicando no link <b>Portal de Relacionamento.</b><br>A CWA Security agradece sua prefer&ecirc;ncia.<br><br><br><br><br><br></div>';
		},
		failure:function( args){
			alert(args.responseText)
		} 
	}
	try{
		YAHOO.util.Connect.setForm('finalzarForm', false);
		YAHOO.util.Connect.asyncRequest('POST', 'produtos/enviarPedido.php', handleSubmitOrd);
		document.getElementById("carrinhoDIV").innerHTML ='<div align="center"><br><br><br><br><br><br><img src="imagens/loading.gif" width="220" height="19" alt=""><br>Aguarde, estamos processando seu pedido.<br><br><br><br><br><br></div>';
	}catch(e){}	
}

function mudarEnderecoEntrega() {
	document.getElementById("divAtualEnderecoEntrega").style.display='none';
	document.getElementById("divNovoEnderecoEntrega").style.display='block';
}
function cancelaEnderecoEntrega() {
	document.getElementById("divAtualEnderecoEntrega").style.display='block';
	document.getElementById("divNovoEnderecoEntrega").style.display='none';
}


function pagamentoPedido(){
	if (document.getElementById("divAtualEnderecoEntrega").style.display=='none') {
		alert('Você precisa finalizar a atualização do endereço de entrega antes de prosseguir.')
		return;
	}
	
	var handleSubmitOrd = {
		success:function( args){
			window.open('carrinho','_self')
		},
		failure:function( args){
			alert(args.responseText)
		} 
	}
	try{
		YAHOO.util.Connect.setForm('formEnderecoObservacoes', false);
		YAHOO.util.Connect.asyncRequest('POST', 'produtos/identificacaoPedidoAtualizaObs.php', handleSubmitOrd);
	}catch(e){}	
}
function atualizaEnderecoEntrega(){
	var handleSubmitOrd = {
		success:function( args){
			document.getElementById("divAtualEnderecoEntrega").innerHTML =args.responseText;
		},
		failure:function( args){
			alert(args.responseText)
		} 
	}
	try{
		YAHOO.util.Connect.setForm('formEnderecoEntregaNovo', false);
		YAHOO.util.Connect.asyncRequest('POST', 'produtos/identificacaoPedidoAtualizaEnd.php', handleSubmitOrd);
		document.getElementById("divAtualEnderecoEntrega").innerHTML ='<div align="center"><br><br><img src="imagens/loading.gif" width="220" height="19" alt=""><br>Aguarde...<br><br></div>';
		document.getElementById("divAtualEnderecoEntrega").style.display='block';
		document.getElementById("divNovoEnderecoEntrega").style.display='none';
	}catch(e){}	
}

