﻿/// <reference path="Sinch.js" />
function loadBasket() {
    var basketID = $('#ddlBaskets').val();
    $('#currentBasket').load(
        '/Controls/SearchResults/Basket.uc',
        { command: 1, basketID: basketID },
        function () {
            getAllCustomerPrices();
            $("#hlViewBasket").attr("href", "/MySinch/Baskets/Details/" + basketID);

            if ($("#hfBasketCustomerUserID").val() == "0") {
                $("#hlAddCustomer").show();
            }
            else {
                $("#hlAddCustomer").hide();
            }
        });
}

function deleteBasketProduct(productID) {
    $('#currentBasket').load('/Controls/SearchResults/Basket.uc', { command: 2, productID: productID });
}

function deleteBasketCustomer() {
    $('#currentBasket').load('/Controls/SearchResults/Basket.uc', { command: 3 }, function () { getAllCustomerPrices(); $("#hlAddCustomer").show(); });
}

function addBasketProduct(productID, quantityID) {
    var quantity = $('#' + quantityID).val();

    if (!new RegExp('^\\d{1,7}$').test(quantity)) {
        alert('Please enter a valid quantity');
    }
    else {
        $('#currentBasket').load('/Controls/SearchResults/Basket.uc', { command: 4, productID: productID, quantity: quantity }, function () { $('#currentBasket').effect('highlight', {}, 500); });
    }
}

function addNewBasket(basketName) {
    $.post(
        '/Controls/SearchResults/Basket.uc',
        { command: 5, basketName: basketName },
        function (b) {
            getAllCustomerPrices();
            $("#hlNewBasket").show("fast");
            $("#pnlNewBasket").hide("fast");
            $("#ddlBaskets").append(
                $("<option></option>").val(b.ID).html(b.Name)
            );
            $("#ddlBaskets").val(b.ID);
            $("#ddlBaskets").trigger("change");
        },
        'json');
}

function clearBasket() {
    $('#currentBasket').load('/Controls/SearchResults/Basket.uc', { command: 6 });
}

$(document).ready(function () {
    $("#hlNewBasket").click(function () {
        $(this).hide("fast");
        $("#pnlNewBasket").show("fast");
    });

    $("#hlCancelBasket").click(function () {
        $("#hlNewBasket").show("fast");
        $("#pnlNewBasket").hide("fast");
    });
});
