<!--
// -----------------------------
// Id declarations
// -----------------------------

var _lbl_ShoppingCartCount          = "lblShoppingCartCount";
var _lbl_ShoppingCartPrice          = "lblShoppingCartPrice";
var _img_Cart                       = "imgCart";
var _lnk_PriorOrders                = "lnkPriorOrders";

// -----------------------------
// Source types(for calls
// -----------------------------

var _shopping_source                = 1; 
var _cart_source                    = 2;
var _detail_source                  = 3;
var _detail_self_source             = 4;
var _login_source                   = 5;
var _login_admin_source             = 6;
var _register_source                = 7;
var _detail_admin_source            = 8;


// -----------------------------
// Image urls
// -----------------------------

//var _src_cart                       = "Images/cart.gif";
var _src_cart                       = "Images/cart_rounded.gif";
var _src_cart_full                  = "Images/cart_full.gif";
var _src_lock_open                  = "Images/lock_open.gif";
var _src_lock_closed                = "Images/lock_closed.gif";

var timerPD;

var promotionTimer;
var promotionOpacity = 100;
var promotionCount = 0; //this is not a count of promotions, but used to decide how long to stay at 100% opacity.
var promotionIndex = 0;
var promotionDirection = false; //if false, go down, if true, go up.

var _error_Messages                 = new Array();

var _customerKey                    = 0;



/* I THINK THIS IS OLD CODE
var _count = 0;
var _int;
var _mwg_int;

var cat_ids = new Array();
cat_ids[0] = 'divCat1';
cat_ids[1] = 'divCat2';
cat_ids[2] = 'divCat3';
cat_ids[3] = 'divCat4';
cat_ids[4] = 'divCat5';

cat_ids[5] = 'divCat6';
cat_ids[6] = 'divCat7';
cat_ids[7] = 'divCat8';
cat_ids[8] = 'divCat9';
cat_ids[9] = 'divCat10';

cat_ids[10] = 'divCat11';
cat_ids[11] = 'divCat12';
cat_ids[12] = 'divCat13';
cat_ids[13] = 'divCat14';
cat_ids[14] = 'divCat15';

var _widget_width = 125;

var _mwg_cnt = 0;

function test()
{
    var x = document.body.offsetHeight;
}

function Slide(dir)
{ 
    if(_count<=0)
    {
        var fn = '';
        var txtFirstCurrentIndex = $('txtFirstCurrentIndex');
        var index = SafeInt(txtFirstCurrentIndex.value);

        if(dir=='prev')
        {   
            fn = 'MoveWidgets('+index+',1,0)';
        }
        else
        {   
            fn = 'MoveWidgets('+index+',-1,4)';
        }
        
        
        _mwg_int = setInterval("MoveWidgetGroup(5,'"+fn+"')",10);
       
    }
    
    PreventPostBack();

}

function MoveWidgetGroup(num,fn)
{
    if(_mwg_cnt<num)
    {
        if(_count<=0)
        {
            _int = setInterval(fn,1);
            _mwg_cnt++;
        }
    }
    else
    {
        _mwg_cnt = 0;
        clearInterval(_mwg_int); 
    }
}

function MoveWidgets(index,mplr,ofst)
{
    var pli = 6*mplr;
    var i = 0;
    
    var txtFirstCurrentIndex = document.getElementById('txtFirstCurrentIndex');
    var divCategories = document.getElementById('divCategories');
    
    //** move all the categories by the offset
    for(i=0;i<6;i++)
    {   
        id = (index+ofst) + (i*mplr);
        
        cat = document.getElementById(cat_ids[id]);
    
        cat.style.left = (SafeInt(cat.style.left) - pli)+'px';
        
    }
    
    if(_count < 24)
        _count++;
    else
    {
        _count = 0;
        clearInterval(_int); 
    }   
}

function CreateCategory(id,left,content)
{
    var div = document.createElement('DIV');
    
    div.id = id;
    div.className = 'widget_category';
    div.style.left = parseInt(left) + 'px';
    div.style.backgroundImage = "url('Images/category_bg.JPG')";
    div.innerText = content;
    Hide(div.id);
    
    var divCategories = document.getElementById('divCategories');
    divCategories.appendChild(div);
    
    return div;
}
*/
function txtSearchFor_onkeypress(event)
{
    if(event.keyCode == 13)    //** Check if ENTER was pressed in the text box
        $('btnSearch').click();
}

function CheckOut()
{
    window.location = "Checkout.aspx";
}

function ShowCart()
{
    //document.getElementById('light').style.display='block';
    //document.getElementById('fade').style.display='block';
    //document.getElementById('selSearchBy').disabled=true;
    
    SetCartProperties();
    
    var fade = $('fade');
    fade.style.opacity = 0;	
    fade.style.filter  = 'Alpha(opacity = 0)';
    
    fade.style.display='block';
    new Effect.Opacity(fade, {duration:0.5, from:0.0, to:0.8});
    
    //fade.style.opacity = .8;	
    //fade.style.filter  = 'Alpha(opacity = 80)';
    
    //if ($('iframe_shoppingCart'))
        //$('iframe_shoppingCart').src = "ShoppingCart.aspx";
    
    $('light').style.display='block'
    
    if(Client.Engine.name=='ie'&&Client.Engine.version<7)
    {
        if($('selSearchBy'))
            $('selSearchBy').hide();
            
        var idx = 0;
        var ctl = $('pfsel_' + idx)
        while(ctl)
        {
            ctl.hide();
            idx++;
            ctl = $('pfsel_' + idx);
        }
    }
    
    //new Effect.Opacity(newWidget, {duration:0.5, from:1.0, to:0.3});
    //this.style.opacity = .5;	
    //this.style.filter  = 'Alpha(opacity = 50)';
    
    __refreshCart();
}

function ShowPriorOrders()
{
    //document.getElementById('light_priororders').style.display='block';
    //document.getElementById('fade').style.display='block';
    //document.getElementById('selSearchBy').disabled=true;
    
    SetPriorOrdersProperties();
    
    if(Client.Engine.name=='ie'&&Client.Engine.version<7)
    {
        if($('selSearchBy'))
            $('selSearchBy').hide();
            
        var idx = 0;
        var ctl = $('pfsel_' + idx)
        while(ctl)
        {
            ctl.hide();
            idx++;
            ctl = $('pfsel_' + idx);
        }
    }
    
    var fade = $('fade');
    fade.style.opacity = 0;	
    fade.style.filter  = 'Alpha(opacity = 0)';
    
    fade.style.display='block';
    new Effect.Opacity(fade, {duration:0.5, from:0.0, to:0.8});
    
    //fade.style.opacity = .8;	
    //fade.style.filter  = 'Alpha(opacity = 80)';
    
    if ($('iframe1'))
        $('iframe1').src = "PriorOrders.aspx?Source=1";
    $('light_priororders').style.display='block'
    
    //new Effect.Opacity(newWidget, {duration:0.5, from:1.0, to:0.3});
    //this.style.opacity = .5;	
    //this.style.filter  = 'Alpha(opacity = 50)';
    
    __refreshCart();
}
function ShowLogin(source)
{
    //document.getElementById('light_priororders').style.display='block';
    //document.getElementById('fade').style.display='block';
    //document.getElementById('selSearchBy').disabled=true;
    
    SetLoginProperties();
    
    if(Client.Engine.name=='ie'&&Client.Engine.version<7)
    {
        $('selSearchBy').hide();
        var idx = 0;
        var ctl = $('pfsel_' + idx)
        while(ctl)
        {
            ctl.hide();
            idx++;
            ctl = $('pfsel_' + idx);
        }
    }
    
    var fade = $('fade');
    fade.style.opacity = 0;	
    fade.style.filter  = 'Alpha(opacity = 0)';
    
    fade.style.display='block';
    new Effect.Opacity(fade, {duration:0.5, from:0.0, to:0.8});
    
    //fade.style.opacity = .8;	
    //fade.style.filter  = 'Alpha(opacity = 80)';
    
    if ($('iframe1'))
        $('iframe1').src = "PriorOrders.aspx?Source=1";    
    
    $('light_login').style.display='block';
    $('iframe_login').src = "Login.aspx?Source=" + source;
    var sel = Get('selSearchBy');
    
    if (sel)
        $('selSearchBy').disabled=true;  //** this is used for a bug in ie6
    
    //new Effect.Opacity(newWidget, {duration:0.5, from:1.0, to:0.3});
    //this.style.opacity = .5;	
    //this.style.filter  = 'Alpha(opacity = 50)';
    
    //__refreshCart();
}

function CloseLogin()
{
    //alert('CloseLogin');
    if(Client.Engine.name=='ie'&&Client.Engine.version<7)
    {
        $('selSearchBy').show();
        var idx = 0;
        var ctl = $('pfsel_' + idx)
        while(ctl)
        {
            ctl.show();
            idx++;
            ctl = $('pfsel_' + idx);
        }
    }
        
    new Effect.Opacity($('fade'), {duration:0.5, from:0.8, to:0.0});
        
    $('light_login').hide();
    $('fade').hide();
    if ($('selSearchBy'))
        $('selSearchBy').disabled=false;
        
    __refreshCart();
    
    //** reload the prior orders screen for the new user
    if(window.frames["iframe1"])
        window.frames["iframe1"].ClickBtnLoadOrders();
}

function ShowProductDetail(productId,subCategoryId,categoryId)
{
    if (categoryId == null)
        categoryId = 0;
        
    //Cancel the message box from image hovering that will be pending
    CancelMessageBox();
    
    //** display loading message in shopping area
    $('divShoppingArea').innerHTML = GetLoadingProductsHTML();   

    //call load store event 
    __loadStore(subCategoryId, null, null, categoryId, 0, productId);
}

function ShowProductDetailXXX(productId,subCategoryId,categoryId)
{
    if (categoryId == null)
        categoryId = 0;
        
    //alert('ShowProductDetail');
    //document.getElementById('light_priororders').style.display='block';
    //document.getElementById('fade').style.display='block';
    //document.getElementById('selSearchBy').disabled=true;
 
    //Cancel the message box from image hovering that will be pending
    CancelMessageBox();
    
    //Go ahead and set the product id of the detail page and click the button to select it
//    window.frames['iframe_itemDetail'].document.getElementById('hdnProductId').value = productId;
//    window.frames['iframe_itemDetail'].document.getElementById('btnSelectProduct').click();

    var oIframe = document.getElementById('iframe_itemDetail');
    var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
    if (oDoc.document)
        oDoc = oDoc.document;
        
    if(oDoc.document = true)
        if (!(oDoc.getElementById && oDoc.getElementById('hdnProductId')))
            return;
            
        oDoc.getElementById('hdnProductId').value = productId;
        oDoc.getElementById('hdnSubCategoryId').value = subCategoryId;
        oDoc.getElementById('hdnCategoryId').value = categoryId;
        //oDoc.getElementById('btnSelectProduct').click();
        //window.frames('iframe_id').contentWindow.document.getElementById('elId');

        //$('iframe_itemDetail').contentDocument.getElementById('hdnProductId').value = productId;
        //$('iframe_itemDetail').contentDocument.getElementById('btnSelectProduct').click();
        window.frames["iframe_itemDetail"].Click_Show_Product_Detail();
    
    if(Client.Engine.name=='ie'&&Client.Engine.version<7)
    {
        $('selSearchBy').hide();
        var idx = 0;
        var ctl = $('pfsel_' + idx)
        while(ctl)
        {
            ctl.hide();
            idx++;
            ctl = $('pfsel_' + idx);
        }
    }
   
    //window.frames["iframe_itemDetail"].Test();


    //$('iframe_itemDetail').contentWindow.document.src = 'ProductDetail.aspx?ProductId=' + productId;
    //FinishShowingProductDetail(productId);
    
//    var fade = $('fade');
//    fade.style.opacity = 0;	
//    fade.style.filter  = 'Alpha(opacity = 0)';
//    
//    fade.style.display='block';
//    new Effect.Opacity(fade, {duration:0.5, from:0.0, to:0.8});
//    
//    //fade.style.opacity = .8;	
//    //fade.style.filter  = 'Alpha(opacity = 80)';
//    
//    $('light_productdetail').style.display='block'
//    var sel = Get('selSearchBy');
//    if (sel)
//        $('selSearchBy').disabled=true  //** this is used for a bug in ie6
//    
//    //new Effect.Opacity(newWidget, {duration:0.5, from:1.0, to:0.3});
//    //this.style.opacity = .5;	
//    //this.style.filter  = 'Alpha(opacity = 50)';
//    
//    //** refresh the Related Products cross sell area
//    __loadRelatedProducts(productId);
}

function FinishShowingProductDetail(productId)
{
    var fade = $('fade');
    fade.style.opacity = 0;
    fade.style.filter  = 'Alpha(opacity = 0)';
    
    fade.style.display='block';
    new Effect.Opacity(fade, {duration:0.5, from:0.0, to:0.8});
    
    //fade.style.opacity = .8;	
    //fade.style.filter  = 'Alpha(opacity = 80)';
    
    $('light_productdetail').style.display='block';
    var sel = Get('selSearchBy');
    if (sel)
        $('selSearchBy').disabled=false;  //** this is used for a bug in ie6
    
    //new Effect.Opacity(newWidget, {duration:0.5, from:1.0, to:0.3});
    //this.style.opacity = .5;	
    //this.style.filter  = 'Alpha(opacity = 50)';
    
    //** refresh the Related Products cross sell area
    __loadRelatedProducts(productId);
}

function ShowCategoryDetail(categoryId,subCategoryId)
{
    //Cancel the message box from image hovering that may be pending
    CancelMessageBox();
    
    //** display loading message in shopping area
    $('divShoppingArea').innerHTML = GetLoadingProductsHTML();     

    //call load store event 
    __loadStore(subCategoryId, null, null, categoryId,0, 0, 1);
}

function ShowProductGroupDetail(productGroupId,categoryId,subCategoryId)
{
    if (categoryId == null)
        categoryId = 0;
        
    //Cancel the message box from image hovering that will be pending
    CancelMessageBox();
    
    //** display loading message in shopping area
    $('divShoppingArea').innerHTML = GetLoadingProductsHTML();     

    //call load store event 
    __loadStore(subCategoryId, null, null, categoryId,productGroupId, 0);
    
    //refresh the Shopping Area with the Product Group Detail UI
    //update the title tags, meta content and meta description appropriately.
//    var params = 'categoryId='+categoryId+'&subCategoryId='+subCategoryId+'&productGroupId='+productGroupId;
//    new Ajax.Request('Shopping.asmx/CreateProductGroupDetailHTML',
//        {
//            method:'post',
//            parameters: params,
//            onComplete: function(transport)
//            {
//                if(transport.status == 200)
//                {
//                    var returnObj = new Object();
//                    var returnObj = ((transport.responseXML.text) ? transport.responseXML.text.evalJSON() : transport.responseXML.lastChild.textContent.evalJSON());
//                    FinishShowProductGroupDetail(returnObj);                 
//                }
//                else
//                {
//                     __logError('ShowProductGroupDetail Transport Failed:'+ transport.status, '', '', _customerKey, 0, false);
//                }
//            },
//            onFailure: function(transport) { __logError('ShowProductGroupDetail Ajax Failed:'+ transport.status, '', '', _customerKey, 0, false); }
//         });
}

function FinishShowProductGroupDetail(obj)
{
    var screen = obj.DynamicScreen;
    
    document.title = screen.Title;
    $("divShoppingArea").innerHTML = screen.Body;
}

function InitalizeScreen()
{
    if ($('divShoppingArea'))
        $('divShoppingArea').style.visibility = 'visible';

    window.onscroll = SetFadePosition;
    //window.onResize = SetFadePosition;
    
    //** set the images that need to be preloaded on the screen
    PreLoadImages('images/ajax-loader.gif, images/message_box_green_bottom.gif, images/message_box_green_middle.gif, images/message_box_green_top.gif, images/message_box_yellow_bottom.gif, images/message_box_yellow_middle.gif, images/message_box_yellow_top.gif');
    
    ResizeProducts();
    SetFadePosition();
    
    _customerKey = SafeInt($('hdnCustomerKey').value);
    
    //check if the cart should be displayed
    //if(SafeBool($('hdnViewCart').value))
    //    ShowCart();
        
    switch(SafeTrim($('hdnState').value))
    {
        case 'cart':
            ShowCart();
            break;
            
        case 'login':
            ShowLogin(1);
            break;
        
        case 'priororders':
            ShowPriorOrders();
            break;
    }
    
    //Show promotions
    DisplayPromotions();
}

function ResizeShopping()
{
    //wrapper function to eliminate safari bug
    ResizeProducts();
    SetFadePosition();
}

function SetFadePosition()
{
    //alert('SetFadePosition');
    //** this function positions the fade div to the user's screen
    //** this is used for the cart and prior orders popup
    
    /*var fade = $('fade');
    if(fade)
    {
        var coor = getScrollXY();
        var style = 
        {
            top: coor[1],
            left: coor[0]
        }
        setElementStyle(fade, style);   
    }*/
    
    var fade = document.getElementById('fade');
    var frm = document.getElementById('frmShopping');
    var sz = document.body.parentNode;
    
    if(fade && frm && sz)
    {
        fade.style.left = "-" + frm.offsetLeft + "px";
        fade.style.top = "-" + frm.offsetTop + "px";
    
        fade.style.width = sz.scrollWidth + "px";
        fade.style.height = sz.scrollHeight + "px";
    }
}

function ResizeProducts()
{ 
    var divPrd = $('divProducts');
    var divDet = $('divDetail');
    var divShp = $('divShoppingArea');
    var divFiltTop = $('divProductFilterTop');
    var divFilt = $('divProductFilter');
    var divFiltBottom = $('divProductFilterBottom');
    var divFiltArea = $('divProductFilterArea');
    
    if(divPrd && divDet && divShp)
    {
        var minPrd = 435;
        var minDet = 535;
        var minShp = 405;
        var minFilt = 75;
        
        //var h = window.screen.height - 330;
        //var h = pageHeight() - 200;
        var h = pageHeight() - divShp.cumulativeOffset().top;
        var hDet = h + (minDet - minPrd);
        var hShp = h - (15*2);
        
        if(GlobalVars)
        {
            if(GlobalVars.GlobalScreen.ShowProductFilter == "true")
            {
                //Need to adjust shopping area's height for filter regardless of minimum
                divShp.style.height = "325px";
                //hShp = hShp - 80;
                divFiltTop.className = "divProductFilterTop";
                divFiltBottom.className = "divProductFilterBottom";
                divFilt.className = "divProductFilterDetail";
                divFiltArea.className = "divProductFilterArea";
                
                //Set detail section height regardless of minimum
                divDet.style.height = '535px';
                hDet = hDet + 80;
            }
        }
     
        if(h>minPrd)
        {
            //alert(h);
            //divPrd.style.height = h;
            //divDet.style.height = h + (minDet - minPrd);    //** The conatining DIV divDetail does not resize based on containing elements, this is work around til I can figure out the problem with the style
            
            var stylePrd = 
            {
                height: h
            }
            setElementStyle(divPrd, stylePrd);
            
            var styleDet = 
            {
                height: hDet
            }
            setElementStyle(divDet, styleDet);
            
            var styleShp = 
            {
                height: hShp
            }
            setElementStyle(divShp, styleShp);
        }
    }
}

function SelectFilter(catid, type, crit)
{
    var criteria = "";
    var i = 0;
    var id = $("pftxt_" + i);
    var ctl = $("pfsel_" + i);
    var opt;
    
    //Loop through selection controls to create the filter list
    while(ctl)
    {
        if(ctl.selectedIndex != 0)
        {
            opt = ctl.options[ctl.selectedIndex];
            if(criteria == "")
                criteria = id.value + ":" + ctl.value;
            else
                criteria = criteria + "," + id.value + ":" + ctl.value;
        }
            
        i++;
        id = $("pftxt_" + i);
        ctl = $("pfsel_" + i);
    }
    
    //Pass the main product retrieval method
    if(catid == 0)
    {        
        criteria = criteria + "_" + type + ":" + crit;    
    }
    else
    {
        criteria = criteria + "_0:" + catid; 
    }
    
    //Load up the store
    __loadStore(WidgetBars[WidgetBarTemplate.vertical].selectedCategoryID, "4", criteria, WidgetBars[WidgetBarTemplate.horizontal].selectedCategoryID);
}

function SearchButtonClick(event)
{
    var btn = document.getElementById("btnSearch");
    var txt = document.getElementById("txtSearchFor");
    var sel = document.getElementById("selSearchBy");
    
    //PreventPostBack(event);
    
    if(!(btn) && (txt))
    {
        alert("One of the elements required for validation does not exist.");
        return false;
    }
    else
    {
        if(txt.value == null || txt.value == "" || txt.value.length < 3)
        {
            _error_Messages.push("Please enter at least three characters to search.");
            txt.focus();
        }
        else if (txt.value.length > 50)
        {
            _error_Messages.push("The search string has exceeded the maximum length of 50 characters.  Please redefine your search.");
            txt.focus();
        }
        else
        {
            //** display loading message in shopping area
            $('divShoppingArea').innerHTML = GetLoadingProductsHTML();
    
            __loadStore(0, sel.value, txt.value, 0,null,null,1);
        
            //call load product filter if product filtering is turned on
            if(GlobalVars)
            {
                if(GlobalVars.GlobalScreen.ShowProductFilter == "true")
                {
                    __loadProductFilter(0, sel.value, txt.value);
                }
            }
            
            var hBar = WidgetBars[WidgetBarTemplate.horizontal];
            var vBar = WidgetBars[WidgetBarTemplate.vertical];
            
            if(hBar.widgets[hBar.selectedIndex]) 
            {
                if (!(hBar.widgets[hBar.selectedIndex].SetBackgroundImage))
                {
                    AppendSetBackgroundImage(hBar.widgets[hBar.selectedIndex]);
                }
                hBar.widgets[hBar.selectedIndex].SetBackgroundImage(hBar.widgets[hBar.selectedIndex].backgroundImage);
            }
            
            if(vBar.widgets[vBar.selectedIndex]) 
            {
                if (!(vBar.widgets[vBar.selectedIndex].SetBackgroundImage))
                {
                    AppendSetBackgroundImage(vBar.widgets[vBar.selectedIndex]);
                }            
                vBar.widgets[vBar.selectedIndex].SetBackgroundImage(vBar.widgets[vBar.selectedIndex].backgroundImage);
            }
            
            hBar.selectedIndex = 0;
            hBar.selectedCategoryID = 0;
            vBar.selectedIndex = 0;
            vBar.selectedCategoryID = 0;            
        }
    }
    
    if (_error_Messages.length > 0)
    {
        alert(_error_Messages.join("\n"));  //display all errors, each on their own line
        _error_Messages = new Array();      //clear the array so we don't get duplicate error messages
        return false;
    }
}

function ShowRegister()
{
        window.open("Register.aspx", "_parent");
}

function RefreshLogin()
{
    //this will set the "login" label to "Logout" or "Login" depending upon the cookie value
    var label = $('lblLogin');
    if(label)
    {
        var text = null;
        
        (GetCookie("IsAuthenticated") == "True") ? text = document.createTextNode("Logout") : text = document.createTextNode("Login");
        
        label.removeChild(label.childNodes[0]);          
        label.appendChild(text);
    }
}

function showDropDowns()
{
    if(Client.Engine.name=='ie'&&Client.Engine.version<7)
    {
        if($('selSearchBy'))
            $('selSearchBy').show();
            
        var idx = 0;
        var ctl = $('pfsel_' + idx)
        while(ctl)
        {
            ctl.show();
            idx++;
            ctl = $('pfsel_' + idx);
        }
    }
}
//Object: SelectType value key: 
//  1 : Category/SubCategory
//  2 : ProductGroup
//  3 : Product
//  4 : Search

function SelectPage(selectType, pageNumber, categoryId, parentCategoryId, searchType, name,  productGroupId, productId)
{
    //Check Parameter
    if (selectType == null || parseInt(selectType,10) == 0 || pageNumber == null || parseInt(pageNumber,10) == 0)
        return;
    
    //Cancel the message box from image hovering that may be pending
    CancelMessageBox();
    
    //Display loading message in shopping area
    $('divShoppingArea').innerHTML = GetLoadingProductsHTML();
    
    //Load Store
    switch(selectType)
    {
        // Category/SubCategory 
        case 1:
            __loadStore(categoryId,0,"",parentCategoryId,0,0,pageNumber);
            break;
        case 4:
            __loadStore(0,searchType,name,0,0,0,pageNumber);
            break;
        default:
            break;
    }
}
/**************************************
POC STUFF
**************************************/

function DisplayPromotions()
{
    if (GlobalVars.GlobalScreen.StoreWidePromotions && GlobalVars.GlobalScreen.StoreWidePromotions.string && (!(GlobalVars.GlobalScreen.StoreWidePromotions.string[0] && GlobalVars.GlobalScreen.StoreWidePromotions.string[0].length && (GlobalVars.GlobalScreen.StoreWidePromotions.string[0].length > 1))))
    {
        var divPromotions = document.getElementById("promotions");
        
        divPromotions.innerHTML = GlobalVars.GlobalScreen.StoreWidePromotions.string;
    }
    else if (GlobalVars.GlobalScreen.StoreWidePromotions && GlobalVars.GlobalScreen.StoreWidePromotions.string && GlobalVars.GlobalScreen.StoreWidePromotions.string[0])
    {
        var divPromotions = document.getElementById("promotions");
        
        divPromotions.innerHTML = GlobalVars.GlobalScreen.StoreWidePromotions.string[0];    
    }
    
    //if there is more than one promotion, start ticking.
    if (GlobalVars.GlobalScreen.StoreWidePromotions && GlobalVars.GlobalScreen.StoreWidePromotions.string && GlobalVars.GlobalScreen.StoreWidePromotions.string[0] && GlobalVars.GlobalScreen.StoreWidePromotions.string.length && (GlobalVars.GlobalScreen.StoreWidePromotions.string.length > 1) && GlobalVars.GlobalScreen.StoreWidePromotions.string[0].length && (GlobalVars.GlobalScreen.StoreWidePromotions.string[0].length > 1))
    {
        promotionTimer = setTimeout("TickPromotions()",10);
    }
}

function TickPromotions()
{
    //handle the case of already at 100% opacity.
    if (promotionOpacity == 100)
    {
        //if we've been here for 10 seconds, start fading.
        if (promotionCount == 500)
        {
            promotionDirection = false;
            promotionOpacity = 99;
            promotionCount = 0;
        }
        //if we've not been here for 10 seconds, add to count and return.
        else
        {
            promotionCount = promotionCount + 1;
            promotionTimer = setTimeout("TickPromotions()",10);
            return;
        }
    }
    //handle the case of being at 0%.
    else if (promotionOpacity == 0)
    {
        //if we've reached the top, set index to 0.
        if (promotionIndex == (GlobalVars.GlobalScreen.StoreWidePromotions.string.length - 1))
            promotionIndex = 0;
        //otherwise, increment.
        else
            promotionIndex = promotionIndex + 1;
            
        //set the opacity and the text of the promotions div.
        var divPromotions = document.getElementById("promotions");
        
        divPromotions.innerHTML = GlobalVars.GlobalScreen.StoreWidePromotions.string[promotionIndex];
        
        promotionOpacity = 1; 
        
        promotionDirection = true;
    }
    //handle the case of being anywhere between.
    else
    {
        if (promotionDirection == true)
            promotionOpacity = promotionOpacity + 1
        else
            promotionOpacity = promotionOpacity - 1;
    }
    
    //Change Opacity of div
    changeOpac(promotionOpacity, "promotions");
    
    //set timeout
    promotionTimer = setTimeout("TickPromotions()",10);
}

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

//set the properties for the login lightbox based on customerkey
function SetLoginProperties()
{
    var ck = GlobalVars.GlobalScreen.CustomerKey;
    var repository = GlobalVars.GlobalScreen.Repository;
    var login = $("light_login");
    var frame = $("iframe_login");
    var image = "/Images/loginlightboxbackground.jpg";
    var browser = navigator.appName;
    
    //this fixes a bug in firefox
    if (browser == "Netscape")
        frame.height = "329px";
    
    if ((ck == 3) && (login))
        login.style.backgroundImage = "url(" + repository + "CK" + ck + image + ")";
}

//set the properties for the shopping cart lightbox based on customerkey
function SetCartProperties()
{
    var ck = GlobalVars.GlobalScreen.CustomerKey;
    var repository = GlobalVars.GlobalScreen.Repository;
    var cart = $("light");
    var image = "/Images/loginlightboxbackground.jpg";
    
    if ((ck == 3) && (cart))
        cart.style.backgroundImage = "url(" + repository + "CK" + ck + image + ")";
}

//set the properties for the prior orders lightbox based on customerkey
function SetPriorOrdersProperties()
{
    var ck = GlobalVars.GlobalScreen.CustomerKey;
    var repository = GlobalVars.GlobalScreen.Repository;
    var priororders = $("light_priororders");
    var image = "/Images/loginlightboxbackground.jpg";
    
    if ((ck == 3) && (priororders))
        priororders.style.backgroundImage = "url(" + repository + "CK" + ck + image + ")";
}
