﻿function cartAddToCart(txtQtyId, productId)
{
    if (document.getElementById(txtQtyId))
    {
        var qty = document.getElementById(txtQtyId).value;
        if (!IsIntegerValue(qty))
        {
            qty = 1;
        }
        
        location.href = timhortons_host + "Cart/Default.aspx?formAction=add&productId=" + productId + "&qty=" + qty;
    }
    else
    {
    }
}//end of addToCart

function cartAddBundleToCart(txtQtyId, bundleId)
{
    if (document.getElementById(txtQtyId))
    {
        var qty = document.getElementById(txtQtyId).value;
        if (!IsIntegerValue(qty))
        {
            qty = 1;
        }
        
        location.href = timhortons_host + "Cart/Default.aspx?formAction=add&bundleId=" + bundleId + "&qty=" + qty;
    }    
}//end of addToCart

function cartRemoveItem(id)
{
    if (IsIntegerValue(id))
    {
        location.href = timhortons_host + "Cart/Default.aspx?formAction=remove&productId=" + id;
    }
}//end of cartRemoveItem

function cartRemoveBundleItem(id)
{
    if (IsIntegerValue(id))
    {
        location.href = timhortons_host + "Cart/Default.aspx?formAction=remove&bundleId=" + id;
    }
}//end of cartRemoveItem

/**
* shows, hides & position the cart popup element
*/
function toggleCartPopup(callerId)
{
    var caller = document.getElementById("cartButton");
    //var cartPopup = document.getElementById("shoppingCartPopup");
    var cartPopup = document.getElementById("cartItemsPopup");
    if (cartPopup && caller)
    {
        if (cartPopup.style.display == "block")
        {
            cartPopup.style.display = "none";
        }
        else
        {
            //caller position
            var callerPositon = findElementPosition(caller);
            var callerPositionLeft = callerPositon[0];
            var callerPositionTop = callerPositon[1];
            //cart position
            var cartLeft = parseInt(callerPositionLeft);
            var cartTop = parseInt(callerPositionTop) + 40;
            

            if (Brand2MediaBrowser.IE && !Brand2MediaBrowser.IE6)
            {
                cartLeft -= 2; 
                cartTop -= 2; 
            }
            else if(Brand2MediaBrowser.IE6)
            {
                cartLeft -= 2;
                cartTop -= 2; 
            }
            
//            alert("callerPositionLeft: " + callerPositionLeft 
//                + "\ncallerPositionTop: " + callerPositionTop);
            
            cartPopup.style.left = cartLeft + "px";
            cartPopup.style.top = cartTop + "px";
            cartPopup.style.display = "block"
        }        
    }

}//end of toggleCartPopup

