var txtItemQty;


function AddPlanItemToCart(txtQty, itemType, itemId, ProductId, PlanId) {
    $.ajaxSetup({
        // Disable caching of AJAX responses */
        cache: false
    });

    var qty ;
    txtItemQty = txtQty;
    if (txtQty != "") 
    {        
        qty = $("#" + txtQty).val();
    }
    else
        qty = "0";

    
    if (qty != "") 
    {
        $("#ajaxStatus").center();
        $("#ajaxStatus").show();
        $("#ajaxStatus").empty().html('<img style="vertical-align: bottom" src="../images/ajax-loader-pink.gif" />&nbsp;Please wait...');
        $.ajax({
        url: base_url + "_private/webservice/add-plan-item-to-cart.aspx?qty=" + qty + "&itemType=" + itemType + "&itemId=" + itemId + "&ProductId=" + ProductId + "&PlanId=" + PlanId,
            success: function(msg) {
                if (msg == "OK") {
                    $("#ajaxStatus").empty().html('<span style="color: green; font-weight: bold">Item added successfully to shopping bag!</span>');
                }
                else {
                    $("#ajaxStatus").empty().html('<span style="color: red; font-weight: bold">' + msg + '</span>');
                }
                window.setTimeout(HideAjaxStatus, 2000);
            }
        });
    }
    return false;
}





function AddItemToCart(txtQty, ProductId) {
    $.ajaxSetup({
        // Disable caching of AJAX responses */
        cache: false
    });

    var qty;
    txtItemQty = txtQty;
    if (txtQty != "") {
        qty = $("#" + txtQty).val();
    }
    else
        qty = "0";


    if (qty != "") {
        $("#ajaxStatus").center();
        $("#ajaxStatus").show();
        $("#ajaxStatus").empty().html('<img style="vertical-align: bottom" src="../images/ajax-loader-pink.gif" />&nbsp;Please wait...');
        $.ajax({
        url: base_url + "_private/webservice/add-to-cart.aspx?qty=" + qty + "&ProductId=" + ProductId,
            success: function(msg) {
                if (msg == "OK") {
                    $("#ajaxStatus").empty().html('<span style="color: green; font-weight: bold">Item added successfully to shopping bag!</span>');
                }
                else {
                    $("#ajaxStatus").empty().html('<span style="color: red; font-weight: bold">' + msg + '</span>');
                }
                window.setTimeout(HideAjaxStatus, 2000);
            }
        });
    }
    return false;
}


function AddItemToCartWithPrice(txtQty, ProductId, price) {
    $.ajaxSetup({
        // Disable caching of AJAX responses */
        cache: false
    });

    var qty;
    txtItemQty = txtQty;
    if (txtQty != "") {
        qty = $("#" + txtQty).val();
    }
    else
        qty = "0";


    if (qty != "") {
        $("#ajaxStatus").center();
        $("#ajaxStatus").show();
        $("#ajaxStatus").empty().html('<img style="vertical-align: bottom" src="../images/ajax-loader-pink.gif" />&nbsp;Please wait...');
        $.ajax({
        url: base_url + "_private/webservice/add-to-cart.aspx?qty=" + qty + "&ProductId=" + ProductId + "&ProductPrice=" + price,
            success: function(msg) {
                if (msg == "OK") {
                    $("#ajaxStatus").empty().html('<span style="color: green; font-weight: bold">Item added successfully to shopping bag!</span>');
                }
                else {
                    $("#ajaxStatus").empty().html('<span style="color: red; font-weight: bold">' + msg + '</span>');
                }
                window.setTimeout(HideAjaxStatus, 2000);
            }
        });
    }
    return false;
}

function HideAjaxStatus() {
    $("#ajaxStatus").hide();
    //if (txtItemQty != "") {
        //$("#" + txtItemQty).val("");
    //}
}
jQuery.fn.center = function() {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    return this;
}
