﻿function v(qid, m, v)	//the function that loads pages via AJAX
{
    var oldVal = $('#v' + qid)[0].innerHTML;
      $.ajax({	//create an ajax request to load_page.php
          type: "POST",
          url: "/vote.aspx",
          data: 'id=' + qid + '&a=' + m + '&v=' + v, //with the page number as a parameter
          dataType: "html", //expect html to be returned
          success: function(msg) {

          $('#v' + qid).html(msg);
          if ($('#v' + qid)[0].innerHTML != oldVal) {
                    showCursorMessage('<div style="padding: 20px;"><nobr>Ваш голос засчитан</nobr></div>');
              }
              else {
                  showCursorMessage('<div style="padding: 20px;background-color:red;"><nobr>Вы уже голосовали за эту футболку</nobr></div>');
              }



          }
      })
  }

  function b(id) {
      $.ajax({
          type: "POST",
          url: "/basket.aspx",
          data: 'item=' + id,
          dataType: "html",
          success: function(msg) {

              $('#basket').html(msg);
              window.location = "/basket";
              //showCursorMessage('<div style="padding: 20px;"><nobr>Товар добавлен в корзину</nobr></div>');

          }
      })
  }

  function b2(id, size) {
      $.ajax({
          type: "POST",
          url: "/basket.aspx",
          data: 'item=' + id + "&size=" + size,
          dataType: "html",
          success: function (msg) {

              $('#basket').html(msg);
              window.location = "/basket";

              //showCursorMessage('<div style="padding: 20px;"><nobr>Товар добавлен в корзину</nobr></div>');

          }
      })
  }

  function b3(id, size,color) {
      $.ajax({
          type: "POST",
          url: "/basket.aspx",
          data: 'item=' + id + "&size=" + size + "&color=" + color,
          dataType: "html",
          success: function (msg) {

              $('#basket').html(msg);
              window.location = "/basket";

              //showCursorMessage('<div style="padding: 20px;"><nobr>Товар добавлен в корзину</nobr></div>');

          }
      })
  }

  function showCursorMessage(msg) {
      $.cursorMessage(msg);
  }


  $(document).ready(function() {
      $(".showImg").colorbox({ maxHeight: "100%", close: 'закрыть' });
      $(".inputHint").ztInputHint({ hintClass: 'hintStyle' });

      $("input").keypress(function (e) { //change submit for input boxes. for input box create 'submit' atribute with value=class name of submit button
          if (($(this).attr('submit') != null) && ($(this).attr('submit').length > 0) && ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))) {

              
              $("." + $(this).attr('submit')).click();
              return true;
          }
      });


      $("#searchFor").keypress(function (e) { //change submit for input boxes. for input box create 'submit' atribute with value=class name of submit button
          if (($(this).attr('submit').length > 0)&& ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))) {

		window.location.replace('/find/'+($('#searchFor').val().length>0?$('#searchFor').val().replace(' ','%20'):'%20'));return false;              
          }
      });


        



  });




