﻿// © Copyright Strategy Builders Inc. 2000-2009. All rights reserved.
//   
// The entire contents of this file is protected by International and
// U.S.Copyright Laws. Unauthorized reproduction, distribution, 
// redistribution and reverse engineering of any or all portion of the code 
// contained in this file is strictly prohibited and may
// result in severe civil and criminal penalties and will be
// prosecuted to the maximum extent possible under the law.
//  
// RESTRICTIONS 
//  
// THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES  
// ARE CONFIDENTIAL AND PROPRIETARY TRADE  
// SECRETS OF Strategy Builders Inc. 
//  
// THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED
// FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE  
// COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE 
// AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  
// AND PERMISSION FROM Strategy Builders Inc. 
//  
// CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON 
// ADDITIONAL RESTRICTIONS.
//  

function CreateShoppingCartControl(id, ShoppingCartItems) {
    
    var cartControl = new ShoppingCartControl(id, ShoppingCartItems);
    cartControl.setTemplate('productListcartTemplate');
    // \
//<table border="1" cellspacing="0" cellpadding="0">\
//<tr>\
//[%CartTotalRow%]\
//[%ShoppingRowItems%] \
//</tr>\
//</table>\
//<table border="1" cellspacing="0" cellpadding="0">\
//<tr>\
//<td>\
//<input id="btnProceedToCheckout" type="button" style="font-size: x-small; height: auto; width: auto;" value="Proceed To Checkout" onclick="javvascript:jsProceedToCheckout();" />\
//</td>\
//</tr>\
//</table>\
//        ');

    cartControl.setCartItemsTemplate('productListCartItemsTemplate');
    // \
//        <td valign="bottom"> \
//        <div id="imgDiv%%shoppingCartItem.CatalogGoods.ProductId%%" > <img src="http://%%shoppingCartItem.CatalogGoods.SmallImageUrl%%" /> \
//        <br/> \
//        <span style="font-size:X-Small;">\
//        %%shoppingCartItem.Quantity%%  x %%formatCurrency(shoppingCartItem.CatalogGoods.Price)%% = %%formatCurrency(shoppingCartItem.Quantity * shoppingCartItem.CatalogGoods.Price)%%\
//        </span> \
//        <br/> \
//        <input type="button" value="Remove" style="font-size: x-small; height: auto; width: auto;"  onclick="javascript:jsRemoveFromCart(%%shoppingCartItem.CatalogGoods.CatalogBusinessId%%, %%shoppingCartItem.CatalogGoods.BusinessId%%, %%shoppingCartItem.CatalogGoods.ProductId%%, %%shoppingCartItem.Quantity%%); return false;" />\
//        </div>\
//        </td>\
//        ');

    cartControl.setCartTotalTemplate('productListCartTotalTemplate');
    // \
//        <td>\
//        <img src="images/red_cart.jpg" id="imgCart" height="60" width="70"/>\
//        <br/>\
//        <font face="Verdana" size="0.5">\
//        %%totalQuantity%% \
//        Items | \
//        %%formatCurrency(totalPrice)%% \
//        </font> \
//        </td> \
//        <input type="hidden" id="hdnProductTotal" value="%%convertToCurrency(totalPrice)%%" > </input> \
//        ');

    return cartControl;

}



/////////////////////////////// Shopping cart ................................

function OnRefreshCart(shoppingCartItems) {
    CartControl.setCartItems(shoppingCartItems);
    document.getElementById("dvCart").innerHTML = CartControl.getHTML();  //getCartHTML(shoppingCartItems);
    if (CartWasOpen) {
        OpenCart();
    } else {
        CloseCart();
    }
    //positionCartOnScreen();
    //jsProceedToCheckout();
}

function jsAddToCartMultiple(businessid, productid, quantity) {
    //relocate($get('dvProductImage'), $get('imgProductMedium'));
    //InitialLoad();
    //fly($get('dvProductImage'), $get('imgCart'));
    var imageToFly = $get('imgProductMedium');
    if (imageToFly == null) imageToFly = $get('img_' + productid);
    relocate(imageToFly, imageToFly);
    // make the size smaller
    var imageWidth = '100%';
    var imageHeight = '100%';
    if (imageToFly && imageToFly.style) {
        imageWidth = imageToFly.style.width;
        imageHeight = imageToFly.style.height;
        imageToFly.style.width = '10%';
        imageToFly.style.height = '10%';
    }
    fly(imageToFly, $get('imgCartToggle'), function () { var ShoppingCart = new StoreFrontService.ShoppingCart(); ret = ShoppingCart.AddToCart(businessid, productid, quantity, OnRefreshCart, OnWSError, OnWSTimeout); });
    imageToFly.style.width = imageWidth;
    imageToFly.style.height = imageHeight;

    CartWasOpen = true;
    OpenCart();
    return (true);
}

function jsAddToCart(businessid, productid) {


    //alert('before flying');
    if ($get('img_' + productid) != null) {
        relocate($get('img_' + productid), $get('img_' + productid));
    }
        fly($get('img_' + productid), $get('imgCartToggle'), function () { var ShoppingCart = new StoreFrontService.ShoppingCart(); ret = ShoppingCart.AddToCart(businessid, productid, 1, OnRefreshCart, OnWSError, OnWSTimeout); });
        //alert('after flying');
    CartWasOpen = true;
    OpenCart();
    return (true);
}

function jsRemoveFromCart(businessid, productid, quantity) {

    var imageCtrl = $get('imgDiv' + productid);

    fade(imageCtrl);

    //alert(quantity);

    var ShoppingCart = new StoreFrontService.ShoppingCart();
    ret = ShoppingCart.RemoveFromCart(businessid, productid, quantity, OnRefreshCart, OnWSError, OnWSTimeout);

    return (true);
}

function jsRemoveFromCart(businessid, productid) {

    var imageCtrl = $get('imgDiv' + productid);

    fade(imageCtrl);

    var ShoppingCart = new StoreFrontService.ShoppingCart();
    ret = ShoppingCart.RemoveFromCart(businessid, productid, 1, OnRefreshCart, OnWSError, OnWSTimeout);

    return (true);
}

function jsGetCartItems() {

    var ShoppingCart = new StoreFrontService.ShoppingCart();
    ret = ShoppingCart.GetCartItems(OnRefreshCart, OnWSError, OnWSTimeout);

    return (true);
}

function jsProceedToCheckout() {
    //location.href = "Checkout.aspx?StoreBusinessId=" + $get('hdnStoreBusinessId').value + "&LanguageId=" + $get('hdnLanguageId').value;
    if (CartControl != null) {
        window.location.href = 'https://' + CartControl.getAttribute('DomainName') + '/Checkout.aspx';
    }
}


function OnCartStatusChanged(o) {
    //alert(o);
    CartWasOpen = o;
}

function SetCartStatusToOpen() {
    if (CartControl != null) {
        var ShoppingCart = new StoreFrontService.ShoppingCart();
        var ret = ShoppingCart.SetCartStatusToOpen(OnCartStatusChanged, OnWSError, OnWSTimeout);
    }
}

function SetCartStatusToClose() {
    if (CartControl != null) {
        var ShoppingCart = new StoreFrontService.ShoppingCart();
        var ret = ShoppingCart.SetCartStatusToClose(OnCartStatusChanged, OnWSError, OnWSTimeout);
    }
}
        


/////////////////////////////// End of Shopping cart ...........................

