﻿// Add item to shoppingcart
function AddItem(nodeID, camID, senderID) {

    $.get(location.href, { AddItem: "1", ItemNodeID: nodeID, ItemCamID: camID },
       function (msg) {
           UpdateShoppingCart(msg);
       });

       $("#book" + senderID).hide();
       $("#booked" + senderID).show();
}


// Remove item from shoppingcart
function RemoveItem(nodeID, camID) {

    $.get(location.href, { RemoveItem: "1", ItemNodeID: nodeID, ItemCamID: camID },
       function (msg) {
           UpdateShoppingCart(msg);
           document.location = document.location;
       });
}

// Update shopping cart. Show / hide cart / qutote and display correct message
function UpdateShoppingCart(msg) {
    var count = msg.d[0];
    var courseName = msg.d[1];

    if (count < 1) {
        $("#top-shopping-cart").hide();
        $("#top-quote").show();
    }
    else {
        $("#top-shopping-cart").show();
        $("#top-quote").hide();

        $('body,html').animate({
            scrollTop: $("body,html").offset().top
        }, 200, 'linear', function () {
             $("#top-shopping-cart").delay(300).effect("highlight", {color:"#FFCF00"}, 800);
        });

        if (count == 1)
            $("#selected-content").html(courseName);
        else
            $("#selected-content").html("Du har valt " + count + " kurser / kurstillfällen");
    }
}

// Set rounded corners
$('.corp-rounded').corner("5px");

$(document).ready(function () {
    $.ajaxSetup({
        // Disable caching of AJAX responses to prevent 304 for shopping cart add/remove items
        cache: false
    });
});
