﻿// base URL for the Ajax call to service
var baseUrl = "http://indexic.net/Services/ShoppingCart.svc/";

function CheckForjQuery() {
    if (typeof jQuery != 'undefined') {
        return 1;
    }
    else {
        // VS 11 parser has problems with the script tags in the string litteral, so assign string using &lt; for < then replace before displaying
        var msg = 'You must include jQuery (see jQuery.com) to use this function. Add &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">&lt;/script> between the &lt;head>&lt;/head> tags of your page.'
        alert(msg.replace(/&lt;/g, '<'));
        return 0;
    }
}

function GetShoppingCartStatus(UrlFriendlyCompanyName) {
    if (CheckForjQuery()) {
        var cartDiv = $(".cartDiv");
        if (cartDiv.length != 0) {
            var x = $.ajax(baseUrl + "GetCartLink"
                , {
                data: ({ "UrlFriendlyCompanyName": UrlFriendlyCompanyName })
                , dataType: "jsonp"
                , success: function (data) { cartDiv.html(data); }
                , error: function (a, b, c) { alert(b); }
            });
        }
        else {
            alert('No cartDiv defined in your document, place <div class="cartDiv"></div> in your html page where you want the cart icon to appear.');
        }
    }
}

function GetShoppingCartAmount( callBack ) {
    if (CheckForjQuery()) {
            var x = $.ajax(baseUrl + "GetCartTotal"
                , { dataType: "jsonp"
                , success: callBack
                , error: function (a, b, c) { alert(b); }
            });
    }
}

