/*
 * Набор скриптов для проекта Imperiashop
 * Авторы http://devcult.ru/
 */

function addCart(paramstr){
    $.ajax({
        url: '/order/add?' + paramstr,
        type: 'GET',
        datatype: 'html',
        success: function(html){
            $("#ordercart").fadeOut(100, function() {
                //alert("2");
                $(this).html(html);
                $(this).fadeIn(100)
            } ) ;

        }
    });
}
var opened = 0;

function popupitem (p){
  if (opened==0){
      $("#popup").html("<div class='popup-frame'><div class='popup-content'></div><div class='popup-shadow'></div></div>");
      opened = 1;
  }
  $.ajax({
      url: '/catalog/popup_ajax/?product_id='+p,
      type: 'GET',
      datatype: 'html',
      cache: true,
      success: function(html){
          $("#popup .popup-content").fadeOut(100, function(){
              $('#popup').html(html);
              $(this).fadeIn(100)
          })
      }
  })
}
function closepopup(){$("#popup").html(""); opened = 0}

function incamount(product_id){
    var price = parseInt($("#"+product_id).attr("price"));
    var amount =  parseInt($("#"+product_id+" input").attr("value"))+1;
    $("#"+product_id+" input").attr("value", amount);
    $("#"+product_id+" .total-price").html(price*amount+" грн");
    $("#"+product_id+" .amount").html(amount);
    //alert($("#cartprice").text());
    $("#cartprice").text(parseInt($("#cartprice").text())+price );

}
function decamount(product_id){
    var price = parseInt($("#"+product_id).attr("price"));
    var amount =  parseInt($("#"+product_id+" input").attr("value"));
    if (amount>0){
        amount--;
        $("#"+product_id+" input").attr("value", amount);
        $("#"+product_id+" .total-price").html(price*amount+" грн");
        $("#"+product_id+" .amount").html(amount);
        $("#cartprice").text(parseInt($("#cartprice").text())-price );
    } else {
        // пусто
    }
}


fform = ['fname','fphone', 'fstreet','fhouse','fblock','fcode','fflat','fcomments'];

function savecontacts(){
    for (i in fform) {
        $.cookie(fform[i], $("#"+fform[i]).val(), { expires: 360, path: '/' });

    }
}
function restorecontacts(){
    for (i in fform){
        $("#"+fform[i]).val($.cookie(fform[i]));
    }
}


// Вызов после окончания загрузки страницы
$(document).ready(function(){
   $.ajax({
       url: "/order/order_ajax/",
       cache: false,
       success: function(html){
           $("#ordercart").html(html)
       }
   });
   // place for new calls
});