Advertisement
luque

Untitled

Nov 15th, 2014
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.  
  3.    $("#newsticker").jCarouselLite({
  4.         vertical: true,
  5.         hoverPause:true,
  6.         btnPrev: "#news-prev",
  7.         btnNext: "#news-next",
  8.         visible: 3,
  9.         auto:3000,
  10.         speed:500
  11.     });
  12.  
  13. loadcart();
  14.  
  15. $("#style-grid").click(function(){
  16.    
  17. $("#block-tovar-grid").show();
  18. $("#block-tovar-list").hide();
  19.  
  20. $("#style-grid").attr("src","/images/00grid2.png");
  21. $("#style-list").attr("src","/images/list.png");
  22.  
  23. $.cookie('select_style','grid');    
  24. });
  25.  
  26. $("#style-list").click(function(){
  27.    
  28. $("#block-tovar-grid").hide();
  29. $("#block-tovar-list").show();
  30.  
  31. $("#style-list").attr("src","/images/0list.png");
  32. $("#style-grid").attr("src","/images/0grid2.png");
  33.  
  34.  
  35. $.cookie('select_style','list');    
  36. });
  37.  
  38.  
  39. if ($.cookie('select_style') == 'grid' )
  40. {
  41. $("#block-tovar-grid").show();
  42. $("#block-tovar-list").hide();
  43.  
  44. $("#style-grid").attr("src","/images/00grid2.png");
  45. $("#style-list").attr("src","/images/list.png");    
  46. }
  47. else
  48. {
  49. $("#block-tovar-grid").hide();
  50. $("#block-tovar-list").show();
  51.  
  52. $("#style-list").attr("src","/images/0list.png");
  53. $("#style-grid").attr("src","/images/0grid2.png");    
  54. }
  55.  
  56.  
  57. $("#select-sort").click(function(){  
  58.    $("#sorting-list").slideToggle(200);    
  59. });
  60.  
  61.  $('#block-category > ul > li > a').click(function(){
  62.                        
  63.             if ($(this).attr('class') != 'active'){
  64.                
  65.             $('#block-category > ul > li > ul').slideUp(400);
  66.             $(this).next().slideToggle(400);
  67.            
  68.                     $('#block-category > ul > li > a').removeClass('active');
  69.                     $(this).addClass('active');
  70.                     $.cookie('select_cat', $(this).attr('id'));
  71.                    
  72.                 }else
  73.                 {
  74.                                    
  75.                     $('#block-category > ul > li > a').removeClass('active');
  76.                     $('#block-category > ul > li > ul').slideUp(400);
  77.                     $.cookie('select_cat', '');  
  78.                 }                                  
  79. });
  80.  
  81. if ($.cookie('select_cat') != '')
  82. {
  83. $('#block-category > ul > li > #'+$.cookie('select_cat')).addClass('active').next().show();
  84. }
  85.  
  86.  $('#genpass').click(function(){
  87.  $.ajax({
  88.   type: "POST",
  89.   url: "/functions/genpass.php",
  90.   dataType: "html",
  91.   cache: false,
  92.   success: function(data) {
  93.   $('#reg_pass').val(data);
  94.   }
  95. });
  96.  
  97. });
  98.  
  99.  
  100. $('#reloadcaptcha').click(function(){
  101. $('#block-captcha > img').attr("src","/reg/reg_captcha.php?r="+ Math.random());
  102. });
  103.  
  104.  
  105.   $('.top-auth').toggle(
  106.        function() {
  107.            $(".top-auth").attr("id","active-button");
  108.            $("#block-top-auth").fadeIn(200);
  109.        },
  110.        function() {
  111.            $(".top-auth").attr("id","");
  112.            $("#block-top-auth").fadeOut(200);  
  113.        }
  114.     );
  115.  
  116.  
  117.  
  118. $("#button-auth").click(function() {
  119.        
  120.  var auth_login = $("#auth_login").val();
  121.  var auth_pass = $("#auth_pass").val();
  122.  
  123.  
  124.  if (auth_login == "" || auth_login.length > 30 )
  125.  {
  126.     $("#auth_login").css("borderColor","#FDB6B6");
  127.     send_login = 'no';
  128.  }else {
  129.    
  130.    $("#auth_login").css("borderColor","#DBDBDB");
  131.    send_login = 'yes';
  132.       }
  133.  
  134.  
  135. if (auth_pass == "" || auth_pass.length > 15 )
  136.  {
  137.     $("#auth_pass").css("borderColor","#FDB6B6");
  138.     send_pass = 'no';
  139.  }else { $("#auth_pass").css("borderColor","#DBDBDB");  send_pass = 'yes'; }
  140.  
  141.  
  142.  
  143.  if ($("#rememberme").prop('checked'))
  144.  {
  145.     auth_rememberme = 'yes';
  146.  
  147.  }else { auth_rememberme = 'no'; }
  148.  
  149.  
  150.  if ( send_login == 'yes' && send_pass == 'yes' )
  151.  {
  152.   $("#button-auth").hide();
  153.   $(".auth-loading").show();
  154.    
  155.     $.ajax({
  156.   type: "POST",
  157.   url: "/include/auth.php",
  158.   data: "login="+auth_login+"&pass="+auth_pass+"&rememberme="+auth_rememberme,
  159.   dataType: "html",
  160.   cache: false,
  161.   success: function(data) {
  162.  
  163.   if (data == 'yes_auth')
  164.   {
  165.       location.reload();
  166.   }else
  167.   {
  168.       $("#message-auth").slideDown(400);
  169.       $(".auth-loading").hide();
  170.       $("#button-auth").show();
  171.      
  172.   }
  173.  
  174. }
  175. });  
  176. }
  177. });
  178.  
  179.  //Шаблон проверки email на правильность
  180.     function isValidEmailAddress(emailAddress) {
  181.     var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
  182.     return pattern.test(emailAddress);
  183.     }
  184.  // Контактные данные
  185.   $('#confirm-button-next').click(function(e){  
  186.  
  187.    var order_fio = $("#order_fio").val();
  188.    var order_email = $("#order_email").val();
  189.    var order_phone = $("#order_phone").val();
  190.    var order_address = $("#order_address").val();
  191.    
  192.  if (!$(".order_delivery").is(":checked"))
  193.  {
  194.     $(".label_delivery").css("color","#E07B7B");
  195.     send_order_delivery = '0';
  196.  
  197.  }else { $(".label_delivery").css("color","black"); send_order_delivery = '1';
  198.  
  199.  
  200.   // Проверка ФИО
  201.  if (order_fio == "" || order_fio.length > 50 )
  202.  {
  203.     $("#order_fio").css("borderColor","#FDB6B6");
  204.    send_order_fio = '0';
  205.    
  206.  }else { $("#order_fio").css("borderColor","#DBDBDB");  send_order_fio = '1';}
  207.  
  208.  
  209.  //проверка email
  210.  if (isValidEmailAddress(order_email) == false)
  211.  {
  212.     $("#order_email").css("borderColor","#FDB6B6");
  213.   send_order_email = '0';  
  214.  }else { $("#order_email").css("borderColor","#DBDBDB"); send_order_email = '1';}
  215.  
  216.  // Проверка телефона
  217.  
  218.   if (order_phone == "" || order_phone.length > 50)
  219.  {
  220.     $("#order_phone").css("borderColor","#FDB6B6");
  221.     send_order_phone = '0';  
  222.  }else { $("#order_phone").css("borderColor","#DBDBDB"); send_order_phone = '1';}
  223.  
  224.  // Проверка Адресса
  225.  
  226.   if (order_address == "" || order_address.length > 150)
  227.  {
  228.     $("#order_address").css("borderColor","#FDB6B6");
  229.     send_order_address = '0';  
  230.  }else { $("#order_address").css("borderColor","#DBDBDB"); send_order_address = '1';}
  231.  
  232. }
  233.  // Глобальная проверка
  234.  if (send_order_delivery == "1" && send_order_fio == "1" && send_order_email == "1" && send_order_phone == "1" && send_order_address == "1")
  235.  {
  236.     // Отправляем форму
  237.    return true;
  238.  }
  239.  
  240. e.preventDefault();
  241.  
  242. });
  243.  
  244.  
  245.  
  246.  
  247. $('.add-cart-style-list,.add-cart-style-grid,.add-cart,.random-add-cart').click(function(){
  248.              
  249.  var  tid = $(this).attr("tid");
  250.  
  251.  $.ajax({
  252.   type: "POST",
  253.   url: "/include/addtocart.php",
  254.   data: "id="+tid,
  255.   dataType: "html",
  256.   cache: false,
  257.   success: function(data) {
  258.   loadcart();
  259.       }
  260. });
  261.  
  262. });
  263.  
  264. function loadcart(){
  265.      $.ajax({
  266.   type: "POST",
  267.   url: "/include/loadcart.php",
  268.   dataType: "html",
  269.   cache: false,
  270.   success: function(data) {
  271.    
  272.   if (data == "0")
  273.   {
  274.  
  275.     $("#block-basket > a").html("Корзина пуста");
  276.    
  277.   }else
  278.   {
  279.     $("#block-basket > a").html(data);
  280.  
  281.   }  
  282.    
  283.       }
  284. });    
  285.        
  286. }
  287.  
  288.  
  289.  function fun_group_price(intprice) {  
  290.     // Группировка цифр по разрядам
  291.   var result_total = String(intprice);
  292.   var lenstr = result_total.length;
  293.  
  294.     switch(lenstr) {
  295.   case 4: {
  296.   groupprice = result_total.substring(0,1)+" "+result_total.substring(1,4);
  297.     break;
  298.   }
  299.   case 5: {
  300.   groupprice = result_total.substring(0,2)+" "+result_total.substring(2,5);
  301.     break;
  302.   }
  303.   case 6: {
  304.   groupprice = result_total.substring(0,3)+" "+result_total.substring(3,6);
  305.     break;
  306.   }
  307.   case 7: {
  308.   groupprice = result_total.substring(0,1)+" "+result_total.substring(1,4)+" "+result_total.substring(4,7);
  309.     break;
  310.   }
  311.   default: {
  312.   groupprice = result_total;  
  313.   }
  314. }  
  315.     return groupprice;
  316.     }
  317.  
  318. $('.count-minus').click(function(){
  319.  
  320.   var iid = $(this).attr("iid");      
  321.  
  322.  $.ajax({
  323.   type: "POST",
  324.   url: "/include/count-minus.php",
  325.   data: "id="+iid,
  326.   dataType: "html",
  327.   cache: false,
  328.   success: function(data) {  
  329.   $("#input-id"+iid).val(data);  
  330.   loadcart();
  331.  
  332.   // переменная с ценной продукта
  333.   var priceproduct = $("#tovar"+iid+" > p").attr("price");
  334.   // Цену умножаем на колличество
  335.   result_total = Number(priceproduct) * Number(data);
  336.  
  337.   $("#tovar"+iid+" > p").html(fun_group_price(result_total)+" грн");
  338.   $("#tovar"+iid+" > h5 > .span-count").html(data);
  339.  
  340.   itog_price();
  341.       }
  342. });
  343.  
  344. });
  345.  
  346. $('.count-plus').click(function(){
  347.  
  348.   var iid = $(this).attr("iid");      
  349.  
  350.  $.ajax({
  351.   type: "POST",
  352.   url: "/include/count-plus.php",
  353.   data: "id="+iid,
  354.   dataType: "html",
  355.   cache: false,
  356.   success: function(data) {  
  357.   $("#input-id"+iid).val(data);  
  358.   loadcart();
  359.  
  360.   // переменная с ценной продукта
  361.   var priceproduct = $("#tovar"+iid+" > p").attr("price");
  362.   // Цену умножаем на колличество
  363.   result_total = Number(priceproduct) * Number(data);
  364.  
  365.   $("#tovar"+iid+" > p").html(fun_group_price(result_total)+" грн");
  366.   $("#tovar"+iid+" > h5 > .span-count").html(data);
  367.  
  368.   itog_price();
  369.       }
  370. });
  371.  
  372. });
  373.  
  374.  $('.count-input').keypress(function(e){
  375.    
  376.  if(e.keyCode==13){
  377.        
  378.  var iid = $(this).attr("iid");
  379.  var incount = $("#input-id"+iid).val();        
  380.  
  381.  $.ajax({
  382.   type: "POST",
  383.   url: "/include/count-input.php",
  384.   data: "id="+iid+"&count="+incount,
  385.   dataType: "html",
  386.   cache: false,
  387.   success: function(data) {
  388.   $("#input-id"+iid).val(data);  
  389.   loadcart();
  390.    
  391.   // переменная с ценной продукта
  392.   var priceproduct = $("#tovar"+iid+" > p").attr("price");
  393.   // Цену умножаем на количество
  394.   result_total = Number(priceproduct) * Number(data);
  395.  
  396.  
  397.   $("#tovar"+iid+" > p").html(fun_group_price(result_total)+" грн");
  398.   $("#tovar"+iid+" > h5 > .span-count").html(data);
  399.   itog_price();
  400.  
  401.       }
  402. });
  403.   }
  404. });
  405.  
  406. function  itog_price(){
  407.  
  408.  $.ajax({
  409.   type: "POST",
  410.   url: "/include/itog_price.php",
  411.   dataType: "html",
  412.   cache: false,
  413.   success: function(data) {
  414.  
  415.   $(".itog-price > strong").html(data);
  416.  
  417. }
  418. });
  419.        
  420. }
  421.  
  422. $('#button-send-review').click(function(){
  423.                
  424.    var name = $("#name_review").val();
  425.    var good = $("#good_review").val();
  426.    var bad = $("#bad_review").val();
  427.    var comment = $("#comment_review").val();
  428.    var iid = $("#button-send-review").attr("iid");
  429.  
  430.     if (name != "")
  431.      {
  432.           name_review = '1';
  433.           $("#name_review").css("borderColor","#DBDBDB");
  434.       }else {
  435.            name_review = '0';
  436.            $("#name_review").css("borderColor","#FDB6B6");
  437.       }
  438.                  
  439.     if (good != "")
  440.        {
  441.           good_review = '1';
  442.           $("#good_review").css("borderColor","#DBDBDB");
  443.       }else {
  444.           good_review = '0';
  445.           $("#good_review").css("borderColor","#FDB6B6");
  446.       }
  447.            
  448.     if (bad != "")
  449.      {
  450.           bad_review = '1';
  451.           $("#bad_review").css("borderColor","#DBDBDB");
  452.      }else {
  453.           bad_review = '0';
  454.           $("#bad_review").css("borderColor","#FDB6B6");
  455.      }
  456.                                          
  457.            
  458.             // Глобальная проверка и отправка отзыва
  459.            
  460.     if ( name_review == '1' && good_review == '1' && bad_review == '1')
  461.       {
  462.          $("#button-send-review").hide();
  463.          $("#reload-img").show();
  464.                  
  465.       $.ajax({
  466.          type: "POST",
  467.          url: "/include/add_review.php",
  468.          data: "id="+iid+"&name="+name+"&good="+good+"&bad="+bad+"&comment="+comment,
  469.          dataType: "html",
  470.          cache: false,
  471.          success: function() {
  472.          setTimeout("$.fancybox.close()", 1000);
  473.          }
  474.          });  
  475.          }        
  476. });
  477.  
  478.      
  479.  
  480. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement