function resposta(msg) {

     $(document).ready(function(){

     $('.lock').show(); 
     $('#resposta').fadeIn().html(msg);

     setTimeout("$('.lock').hide(); $('#resposta').hide();",2000);

     });

}



/* BUSCA POR CEP */




function fecharCompra(){

          var cepi = document.basket.cep;
          var ruai = document.basket.rua;
          var numeroi = document.basket.numero;
          var complementoi = document.basket.complemento;
          var bairroi = document.basket.bairro;
          var cidadei = document.basket.cidade;
          var estadoi = document.basket.estado;

          var erro = 0;

          if(cepi.value.length < 8){
               resposta('Insira um CEP valido!');
               $("#cep").css({'border':'2px solid red','background':'#ffeeee'});
               erro++;
          }else{
               $("#cep").css({'border':'1px solid green','background':'#eeffee'});
          }


          if(ruai.value ==""){
               $("#rua").css({'border':'2px solid red','background':'#ffeeee'});
               erro++;
          }else{
               $("#rua").css({'border':'1px solid green','background':'#eeffee'});
          }



          if(numeroi.value < 1){
               $("#numero").css({'border':'2px solid red','background':'#ffeeee'});
               erro++;
          }else{
               $("#numero").css({'border':'1px solid green','background':'#eeffee'});
          }


          if(bairroi.value ==""){
               $("#bairro").css({'border':'2px solid red','background':'#ffeeee'});
               erro++;
          }else{
               $("#bairro").css({'border':'1px solid green','background':'#eeffee'});
          }


          if(cidadei.value ==""){
               $("#cidade select").css({'border':'2px solid red','background':'#ffeeee'});
               erro++;
          }else{
               $("#cidade select").css({'border':'1px solid green','background':'#eeffee'});
          }


          if(estadoi.value ==""){
               $("#estado").css({'border':'2px solid red','background':'#ffeeee'});
               erro++;
          }else{
               $("#estado").css({'border':'1px solid green','background':'#eeffee'});
          }


          if(erro<1){

               document.basket.submit();

          }

}


function buscaCep(){

          $("#calcing").fadeIn("fast");


          var cepi = document.confirma.cep;
          var ruai = document.confirma.rua;
          var numeroi = document.confirma.numero;
          var complementoi = document.confirma.complemento;
          var bairroi = document.confirma.bairro;
          var cidadei = document.confirma.cidade;
          var estadoi = document.confirma.estado;

          $.ajax({
               type: "POST",
               url: "libs/php/ajax.php?cmd=busca-cep&cep="+cepi.value,
               dataType:"text",
               success: function(msg){

                    $("#calcing").fadeOut("fast");

                    var cjson = eval("("+msg+")");

                         $("#rua").attr("value",cjson["rua"]);
                         $("#numero").attr("value","");
                         $("#complemento").attr("value","");
                         $("#bairro").attr("value",cjson["bairro"]);
                         $("#cidade").attr("value",cjson["cidade"]);
                         $("#estado").attr("value",cjson["estado"]);

               }
          });

}




/* BUSCA CIDADES */



function busca_cidade(valor){

          $("#estado").effect("transfer",{to: "#cidade", className: "transfer"},500,"");


          $.ajax({
               type: "POST",
               url: "libs/php/ajax.php?cmd=busca-cidade&estado="+valor,
               dataType:"text",
               success: function(msg){

                                   $("#cidade").html(msg);

                            }
          });

}



/* 

function remove_item(indice){

          $.ajax({
               type: "POST",
               url: "libs/php/ajax.php?cmd=remove-item&i="+indice,
               dataType:"text",
               success: function(msg){

                                   $("#tr"+indice).fadeOut().remove();
                                   var json = eval("("+msg+")"); 
                                   $("#total"+indice).html("R$ "+json["totalitem"]);
                                   $("#resultado").html(json["valortotal"]);
                                   $("#q-itens").html(json["qtdadeitens"]);
                                   $("#itenst").html(json["qtdadeitens"]);
                                   $("#v-itens").html(json["valortotal"]);
                                   $("#pesot").html(json["totalpeso"]);
                                   $("#vfinal").html("R$ "+json["vfinal"]);
                                   $("#vfrete").html("R$ "+json["jfrete"]); 
                                   $("#vfinal").html("R$ "+json["jfinal"]); 

                            }
          });

}

*/


/* CARRINHO DE COMPRAS */

function remove_item(indice){

          $.ajax({
               type: "POST",
               url: "libs/php/ajax.php?cmd=remove-item&i="+indice,
               dataType:"text",
               success: function(msg){

                                   $("#tr"+indice).fadeOut().remove();
                                   var ijson = eval("("+msg+")");

                                   $("#total"+indice).html("R$ "+ijson["totalitem"]);
                                   $("#resultado").html("R$ "+ijson["valortotal"]);
                                   $("#q-itens").html(ijson["qtdadeitens"]);
                                   $("#itenst").html(ijson["qtdadeitens"]);
                                   $("#v-itens").html("R$ "+ijson["valortotal"]);
                                   $("#pesot").html(ijson["totalpeso"]);
                                   $("#vfinal").html("R$ "+ijson["vfinal"]);
                                   $("#vfrete").html("R$ "+ijson["vfrete"]);

                                   
                                   $("#concluir").fadeOut(100);
                                  
                                   if(ijson["qtdadeitens"] < 1){ $("<div class='aviso'>Seu carrinho de compras est&aacute; vazio!!</div>").insertAfter('#carrinho');}else{ $("#c-frete").fadeIn(100); $("#c-frete").html("A quantidade de produtos  foi alterada, <br/> calcule o Frete Novamente para poder Finalizar a Compra");}
                            }
          });

}

function refresh_qtdade(valor,indice,preco,peso){


          $.ajax({
               type: "POST",
               url: "libs/php/ajax.php?cmd=altera-qtdade&qtdade="+valor+"&i="+indice+"&preco="+parseFloat(preco)+"&peso="+parseFloat(peso),
               dataType:"text",
               success: function(msg){

                                   var json = eval("("+msg+")");
                                   $("#total"+indice).html("R$ "+json["totalitem"]);
                                   $("#resultado").html("R$ "+json["valortotal"]);
                                   $("#q-itens").html(json["qtdadeitens"]);
                                   $("#itenst").html(json["qtdadeitens"]);
                                   $("#v-itens").html("R$ "+json["vfinal"]);
                                   $("#pesot").html(json["totalpeso"]);
                                   $("#vfinal").html("R$ "+json["vfinal"]);
                                    $("#c-frete").html("A quantidade de produtos  foi alterada, <br/> calcule o Frete Novamente para poder Finalizar a Compra");
                                   $("#c-frete").fadeIn(100);
                                    $("#concluir").fadeOut(100);
/*
                                   if(json["tipofrete"]== "gratis"){ $("#fretegratis").html("<div class='calculo-frete'>Frete Gr&aacute;tis para esta quantidade!</div>");  $("#concluir").show(0);   $("#calc-frete").hide(0); }else{  $("#fretegratis").html("");  $("#concluir").hide(0);  $("#calc-frete").show(0);    }
                                   if(json["tipofrete"]== "transportadora"){ $("#fretegratis").html("<div class='calculo-frete'>Valor do Frete pela Transportadora: R$ "+json["valorfrete"]+"</div>");  $("#concluir").show(0); $("#calc-frete").hide(0);   }
                                   if(json["tipofrete"]== "correios"){ $("#fretegratis").html("<div class='calculo-frete'>Calcule o Frete, clique no bot&atilde;o abaixo para prosseguir.</div>"); $("#concluir").hide(0);   $("#calc-frete").show(0); }
*/

                            }

          });



}


function frete(){
	  var cep_input = document.basket.cep.value;
	  var tipo_input = document.basket.tfrete.value;

	  $("#c-frete").fadeOut(100);
	  $("#calcing").fadeIn(100);
	  
//	  38440-000 a 38449-999
//	  38400-000 a 38415-999
//	  if(((cep_input>=38400000) && (cep_input<=38415999)) || ((cep_input>=38440000 ) && (cep_input<=38449999))) {
//		  resposta("Não entregamos para essa região!");
//	      $(".concluir-compra").fadeOut("fast");
//	      $("#calcing").fadeOut(100);
//	  } else {
	      $.ajax({
	           type: "POST",
	           url: "libs/php/ajax.php?cmd=calc-frete&cep="+cep_input+"&tipo="+tipo_input,
	           dataType:"text",
	           success: function(msg){
	                var ijson = eval("("+msg+")");
	                if(ijson["jfrete"]=="gratis"){ 
	                	 $("#vfrete").html("<span style='color:green;'>Frete Gr&aacute;tis </span>"); 
	                } else { 
	                	$("#vfrete").html("R$ "+ijson["jfrete"]);
	                }
	
	                $("#vfinal").html("R$ "+ijson["jfinal"]);
	                $("#v-itens").html("R$ "+ijson["jfinal"]);
	                
	                 if((parseFloat(ijson["jfrete"])> 0.1)||(ijson["jfrete"]=="gratis")){
	                          $(".concluir-compra").fadeIn("fast");
	                     }else{
	                    	 if((ijson["cep"]!=null) && (ijson["cep"])) {
	                    		 resposta("Não entregamos para essa região!");
	                    		 $(".concluir-compra").fadeOut("fast");
	                    	 } else {
	                    		 resposta("O CEP informado &eacute; invalido!");
	                    		 $(".concluir-compra").fadeOut("fast");
	                    	 }
	                     }
	                          $("#calcing").fadeOut(100);
	           }
	
	      });
//	  }
}






function cupomCheck(){

          var cupom_input = document.basket.cupom.value;



            $("#ticketing").fadeIn(100);

               $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=valida-ticket&cupom="+cupom_input,
                    dataType:"text",
                    success: function(msg){

                    var json = eval("("+msg+")");

                             $("#ticket-info").html(json["mensagem"]);
                             frete();



                    }

          });

                             $("#ticketing").fadeOut(100);



}



function anulaTicket(){

          var cupom_input = document.basket.cupom;



            $("#ticketing").fadeIn(100);

               $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=anula-ticket",
                    dataType:"text",
                    success: function(msg){

                    var json = eval("("+msg+")");

                             $("#ticket-info").html(json["mensagem"]);
                              cupom_input.value='';
                             frete();



                    }

          });

                             $("#ticketing").fadeOut(100);

}





function enviaTicket(cliente,chave,email){

               $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=envia-ticket&cliente="+cliente+"&chave="+chave+"&email="+email,
                    dataType:"text",
                    success: function(msg){


                         if(msg=="sucess"){

                                   resposta("O ticket foi enviado!");

                         }else{

                                   resposta("Falha ao enviar Ticket!");

                         }

                    }

          });

}




function freteOwner(){

          var cep_input = document.basket.cep.value;
          var tipo_input = document.basket.tfrete.value;
            
            $("#calcing").fadeIn(100);



          $.ajax({
               type: "POST",
               url: "libs/php/ajax.php?cmd=calc-frete&cep="+cep_input+"&tipo="+tipo_input+"&owner=yes",
               dataType:"text",
               success: function(msg){ 
                    var ijson = eval("("+msg+")");
                     if(ijson["jfrete"]=="gratis"){ $("#vfrete").html("<span style='color:green;'>Gr&aacute;tis para esta Quantidade</span>"); }else{ $("#vfrete").html("R$ "+ijson["jfrete"]);  }

                    $("#vfinal").html("R$ "+ijson["jfinal"]);
                    $("#v-itens").html("R$ "+ijson["jfinal"]);

                         if((parseFloat(ijson["jfrete"])> 0.1)||(ijson["jfrete"]=="gratis")){

                              $(".concluir-compra").fadeIn("fast");

                         }else{

                              $(".concluir-compra").fadeOut("fast");

                         }

                              $("#calcing").fadeOut(100);

               }


          });



}


/* PERFIL */

function editProfile(obj,linha,valor,id){

          $.ajax({

               type: "POST",
               url: "libs/php/ajax.php?cmd=edit-profile&line="+linha+"&valor="+valor+"&id="+id,
               dataType:"text",
               success: function(msg){
                         if(msg=="err"){ $('<span style="color:red;" id="remove-me"> Erro ao Salvar </span>').insertAfter(obj);  }else{  $('<span style="color:green;"> Salvo! </span>').insertAfter(obj); }

               }

          });

}


/* PAINEL */


function loadCategorias(valor){

          $("#categ").html("<img src='libs/img/ajax-loader.gif' alt=''/>");
          $.ajax({
               type: "POST",
               url: "libs/php/ajax.php?cmd=load-categorias&grupo="+valor,
               dataType:"text",
               success: function(msg){ $("#categ").html(msg); }
          });

}


function findCategorias(elemento,valor,id){

     if(elemento.checked==true){

               $("#categ-loader").fadeIn("fast");
               $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=find-categorias&grupo="+valor+"&id="+id,
                    dataType:"text",
                    success: function(msg){ $(msg).prependTo("#categ"); $("#categ-loader").fadeOut(); }
               });

   }else{

               $("#categ p:has(#c"+id+")").remove();
               $("#subcateg p:has(#c"+id+")").remove();

     }

}


function findSubcategorias(elemento,valor,id,ids){

     if(elemento.checked==true){

               $("#subcateg-loader").fadeIn("fast");
               $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=find-subcategorias&categoria="+valor+"&id="+id+"&ids="+ids,
                    dataType:"text",
                    success: function(msg){ $(msg).prependTo("#subcateg"); $("#subcateg-loader").fadeOut(); }
               });

   }else{

               $("#subcateg #s"+ids).remove();

     }

}



function alterInfo(valor,id){

               $("#subcateg-loader").fadeIn("fast");
               $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=add-info&observacao="+valor+"&id="+id,
                    dataType:"text"

               });

}




function checkUser(obj, login){

if(login!=""){
               $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=check-user&login="+login,
                    dataType:"text",
                    success: function(msg){

                          if(msg=="err"){


                                        $('#res').html('<strong>'+login+'</strong>: Este nome de usuario ja existe! Escolha outro...');
                                        obj.value = "";

                                   }else{


                                        $('#res').html('ok!');

                                   }

                    }
               });
}
}


function checkCpf(obj, valor){

if(valor!=""){
               $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=check-cpf&cpf="+valor,
                    dataType:"text",
                    success: function(msg){

                          if(msg=="err"){


                                        $('#rescpf').html('<strong>'+valor+'</strong>: ja &eacute; cadastrado.. enviamos um email para voc&ecirc; com seus dados para login');
                                        obj.value = "";

                                   }else{


                                        $('#rescpf').html("");

                                   }

                    }
               });
}
}



function resetarBusca(){

               $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=reset-busca",
                    dataType:"text",
                    success: function(msg){
                         $("#busca-counter .tdregistros td").html("");
                         $("#resetar").fadeOut();
                   }
     });
}






/* NEWSLETER */


function subscribe(){

          var valor = document.newsletter.email;
          
          if(valor.value!=""){
          $.ajax({
               type: "POST",
               url: "libs/php/ajax.php?cmd=newsletter-subscribe&email="+valor.value,
               dataType:"text",
               success: function(msg){ resposta(msg);  valor.value='';}
          });
               valor.style.borderColor = "#cccccc";
          
          }else{
               
               valor.style.borderColor = "#cc0000";
               valor.value = "Digite seu email";
          }
}




/* DETALHES */

function recomendarProduto(endereco,titulo){

          var erro = 0;

          var inp_nome = document.recomend.nome;
          var inp_dest = document.recomend.destinatario;
          var inp_mail = document.recomend.email;


          if(inp_nome.value==""){ erro++;  inp_nome.style.borderColor = "#cc0000"; }else{ inp_nome.style.borderColor = "#cccccc"; }
          if(inp_dest.value==""){ erro++; inp_dest.style.borderColor = "#cc0000"; }else{  inp_dest.style.borderColor = "#cccccc"; }
          if(inp_mail.value==""){ erro++; inp_mail.style.borderColor = "#cc0000";  }else{ inp_mail.style.borderColor = "#cccccc"; }

          if(erro < 1){

              $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=recomendar-produto&nome="+inp_nome.value+"&destinatario="+inp_dest.value+"&email="+inp_mail.value+"&url="+endereco+"&titulo="+titulo,
                    dataType:"text",
                    success: function(msg){ 

                          inp_dest.value = "";
                         inp_mail.value = "";

                         $(".recomendar").slideUp();
                         $(".lock").hide();
                         resposta("O email foi enviado!");

                         }
               });

          }
}

/* CHEQUE CARTAO - FINANCIAMENTO */

function chequeCartao(endereco,titulo){

	var erro = 0;

	var dataArray = $("#chequecartao").serializeArray();
	var dataErro = new Array();
	
	var queryString = "";
	for(var i = 0; i < dataArray.length; i++) {
    	queryString += "&" + dataArray[i]["name"] + "+" + encodeURIComponent(dataArray[i]["value"]);
    	
	    if((dataArray[i]["value"] == null) || (dataArray[i]["value"] == '')) {
	    	erro = 1;
	    	dataErro.push(dataArray[i]["name"]);
	    	$('form#chequecartao input[name="'+ dataArray[i]["name"] +'"]').css('border-color','#cc0000');
	    } else { 
	    	$('form#chequecartao input[name="'+ dataArray[i]["name"] +'"]').css('border-color','#cccccc');
	    }	    

	}
	
	if(erro == 0) {
		$.ajax({
			type: "POST",
		    url: "libs/php/ajax.php?cmd=cheque-cartao&url="+endereco+"&titulo="+titulo,
		    // data: queryString,
		    data: dataArray,
		    dataType: 'json',
		    contentType:"application/x-www-form-urlencoded; charset=UTF-8",
		    beforeSend: function() {
		    	
		    },
		    success: function(msg) {
		        	// alert('oK');
		        	// alert(msg);
					// inp_nome.value = "";
		          	// inp_email.value = "";
		          	// inp_telefone.value = "";
		          	// inp_cpf.value = "";
		          	// inp_dtnasc.value = "";
	
				if(msg == "ok") {
					$(dataArray).each(function(i) {
						if((dataArray[i]['name'] == "produto") || (dataArray[i]['name'] == "valor")) {
						} else {
							$('form#chequecartao input[name="'+ dataArray[i]['name'] +'"]').val("");
						}
					});
		
             		$(".chequecartao").slideUp();
             		$(".lock").hide();
             		resposta("O email foi enviado!*");
	            } else {
	            	$(".chequecartao").slideUp();
             		$(".lock").hide();
             		resposta("Ocorreu um erro. Tente novamente mais tarde.");
	            }
		    }
		});
	} else {
		// if(dataErro != null) {
			// $(dataErro).each(function(i) {
				// $('input[name="'+i+'"]').css('background','#cc0000'));
			// });
		// }
		resposta("Alguns campos obrigatórios não foram preenchidos! Valide por favor.");
	}

/*
          var inp_nome = document.chequess.nome;
          var inp_email = document.chequess.email;
          var inp_telefone = document.chequess.telefone;
          var inp_cpf = document.chequess.cpf;
          var inp_dtnasc = document.chequess.dtnasc;
          var inp_valor = document.chequess.valor;
          
          var inp_renda = document.chequess.renda;
          var inp_obs = document.chequess.obs;
          var inp_produto = document.chequess.produto;

          if(inp_nome.value==""){ erro++;  inp_nome.style.borderColor = "#cc0000"; }else{ inp_nome.style.borderColor = "#cccccc"; }
          if(inp_telefone.value==""){ erro++; inp_telefone.style.borderColor = "#cc0000"; }else{  inp_telefone.style.borderColor = "#cccccc"; }
          if(inp_email.value==""){ erro++; inp_email.style.borderColor = "#cc0000";  }else{ inp_email.style.borderColor = "#cccccc"; }
          if(inp_cpf.value==""){ erro++; inp_cpf.style.borderColor = "#cc0000";  }else{ inp_cpf.style.borderColor = "#cccccc"; }
          if(inp_dtnasc.value==""){ erro++; inp_dtnasc.style.borderColor = "#cc0000";  }else{ inp_dtnasc.style.borderColor = "#cccccc"; }
          
          if(inp_renda.value==""){ erro++; inp_renda.style.borderColor = "#cc0000";  }else{ inp_renda.style.borderColor = "#cccccc"; }

          if(erro < 1){

              $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=cheque-cartao" + 
                    	"&nome="+inp_nome.value+
                    	"&email="+inp_email.value+
                    	"&telefone="+inp_telefone.value+
                    	"&cpf="+inp_cpf.value+
                    	"&dtnasc="+inp_dtnasc.value+
                    	"&valor="+inp_valor.value+
                    	"&obs="+inp_obs.value+
                    	"&renda="+inp_renda.value+
                    	"&produto="+inp_produto.value+
                    	"&url="+endereco+
                    	"&titulo="+titulo,
                    dataType:"text",
                    success: function(msg){ 

				          inp_nome.value = "";
				          inp_email.value = "";
				          inp_telefone.value = "";
				          inp_cpf.value = "";
				          inp_dtnasc.value = "";

                         $(".chequecartao").slideUp();
                         $(".lock").hide();
                         resposta("O email foi enviado!*");

                         }
               });

          }
          */
}





/* TRACKING CORREIOS */

function enviarTracking(email,idcompra,idobj){

          var erro = 0;

          var obj = document.getElementById(idobj);

          if(obj.value.length > 12){


              obj.style.background = "#eeffee";

              $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=tracking-correios&tracking="+obj.value+"&idcompra="+idcompra+"&email="+email,
                    dataType:"text",
                    success: function(msg){ 

                         resposta("O email foi enviado!");

                         }
               });

          }else{

               obj.style.background = "#ffeeee";

          }
}




function enviarMotivo(email,idcompra,idobj){

          var erro = 0;

          var obj = document.getElementById(idobj);

          if(obj.value.length > 12){


              obj.style.background = "#eeffee";

              $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=enviar-motivo&detalhe="+obj.value+"&idcompra="+idcompra+"&email="+email,
                    dataType:"text",
                    success: function(msg){

                         resposta("O email foi enviado!");

                         }
               });

          }else{

               obj.style.background = "#ffeeee";

          }
}



function avisar(produto){

          var erro = 0;

         var tamanho_inp = document.buy.estoque_tamanho.value;
         var cor_inp = document.buy.estoque_cor.value;
         var inp_mail = document.avise.email;


          if(inp_mail.value==""){ erro++; inp_mail.style.borderColor = "#cc0000";  }else{ inp_mail.style.borderColor = "#cccccc"; }

          if(erro < 1){

              $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=avisar&email="+inp_mail.value+"&produto="+produto+"&tamanho="+tamanho_inp+"&cor="+cor_inp,
                    dataType:"text",
                    success: function(msg){ 

                         inp_mail.value = "";

                         $(".avisar").slideUp();
						 $(".lock").hide();
                         resposta("Voc&ecirc; ser&aacute; avisado quando este produto estiver disponivel!");

                         }
               });

          }
}






function submitFrete(a) {
     var Key = a.keyCode || a.which;
     if(Key == "13"){

           frete();
          return (false);

     }

}








function postarMensagem(){

         var assuntoi = document.message.assunto;
         var mensagemi = document.message.mensagem;

          if((mensagemi.value!="") && (assuntoi.value!="")){

              $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=postar-mensagem&assunto="+assuntoi.value+"&mensagem="+mensagemi.value,
                    dataType:"text",
                    success: function(msg){ 

                         if(msg=="sucess"){

                                   assuntoi.value="";
                                   mensagemi.value="";
                                   resposta("Sua mensagem foi enviada!");

                                        }else{

                                   resposta("Falha! Tente Novamente!");

                            }

                      }

               });

          }else{

                   resposta("Preencha todos os campos!");

          }
}





function gerarCupom(i){


               var cupons = $("#cupom"+i).attr("value");
               var valores = $("#valores"+i).attr("value");
               var dias = $("#dias"+i).attr("value");

              $.ajax({
                    type: "POST",
                    url: "libs/php/ajax.php?cmd=ticket&i="+i+"&tipo="+cupons+"&valor="+valores+"&dias="+dias,
                    dataType:"text",
                    success: function(msg){ 

                         if(msg=="sucess"){  resposta("O Ticket foi gerado!");  }else{    resposta("Falha ao gerar Ticket!"); }

                   }
               });

}








function surfRight(largura){

     var leftm = parseInt($("#img-tire").css("margin-left"));

     if(leftm >= largura){

          $("#img-tire").animate({marginLeft:"-=112px"},50);
          $(".roll-left").animate({opacity:1},100);

     }

     if(leftm < largura+102){  $(".roll-right").animate({opacity:0.25},100);  }

}


function surfLeft(){
 
     var leftm = parseInt($("#img-tire").css("margin-left")) + 102;
     if(leftm <= 0){
          $("#img-tire").animate({marginLeft:"+=112px"},50);
          $(".roll-right").animate({opacity:1},100);
     }

     if(leftm >= -102){  $(".roll-left").animate({opacity:0.25},100);  }

}



function showconfirm(){

     $(".confirm-status").slideDown(100);
     $(".lock").fadeIn(50);

}
function showconfirmajax(){

     $(".confirm-status-ajax").slideDown(100);
     $(".lock").fadeIn(50);

}




// Generate Captcha colors buttons
function generateButtons(formulario) {    
	$.ajax({
		type: "POST",
	    url: "libs/php/ajax.php?cmd=captcha-buttons",
	    // data: queryString,
	    // data: dataArray,
	    dataType: 'json',
	    contentType:"application/x-www-form-urlencoded; charset=UTF-8",
	    beforeSend: function() {
	    	
	    },
	    success: function(buttons) {
	    	$('.' + formulario + ' #validator').remove();
	    	$('.' + formulario + ' input[type=submit]#post').remove();
	    	$('.' + formulario + ' #chequecartao').append(buttons)
	    }
	});     	
}


/* JQuery Ready */
$(document).ready(function(){

     $('input[name=TRANSACAO]').change(function() {
          if($(this).val() == "08") {
               $('#TOTAL').val($('#TOTAL_REAL').val());
               //$('.mostravalor').html('R$' + $('#TOTAL').val());
               // $('.bandeiras').fadeIn();
               $('.parcelas').fadeIn();
               // $('.parcelas select option:eq(01)').prop('selected', true)
               $('.parcelas select').val('01');
          } else {
               $('#TOTAL').val($('#TOTAL_DESCONTO').val());
               //$('.mostravalor').html('R$' + $('#TOTAL').val());
               // $('.bandeiras').fadeOut();
               $('.parcelas').fadeOut();
               $('.parcelas select').val('00');
          }
     });

    $(".amplia_foto img").click(function(){
        $(this).css({"position":"relative","z-index":"100"});
        $(this).animate({width:"+=117%",height:"+=117%"},50);
        $(".lockscreen").css({"display":"block"});
    });

    $(".lockscreen").click(function(){
        $(".amplia_foto img").css({"position":"relative","z-index":"100"});
        $(".amplia_foto img").animate({width:"100%",height:"100%"},50);
        $(this).css({"display":"none"});
        $("#medidas").slideUp(100);
    });

    $('.lock').click(function() {
	   $(".chequecartao").slideUp();
	   $(".recomendar").slideUp();
	   $(".avisar").slideUp();
        $(".lock").hide();
    });

	$("#tabs").tabs();
	$("#accordion").accordion({autoHeight:false});
	$("#gallery a").lightBox();


     $('#change-estatus').bind('click', function(event) {
          event.preventDefault();
          
          // $('#updatevendas').submit();
          var updatevendas = $('#updatevendas').attr('action');
          // alert(updatevendas);
          $.post(updatevendas, $('#updatevendas').serialize());
          $('#' + $(this).attr('href') + '').fadeOut();
          
          $('.lock').fadeOut(50);
          $('.confirm-status-ajax').slideUp(100);

     });
});

