function myOffersResetUI(stateValue)
{
    if(!stateValue)
        return;
        
    var stateVals = stateValue.split(';');
        
    if (stateVals)
    {
        var previewCtrl = document.getElementById(stateVals[0]);
        var detailCtrl = document.getElementById(stateVals[1]);
        
        myOfferShowHideCtrl(previewCtrl, false);
        myOfferShowHideCtrl(detailCtrl, true);    
    }
}

function myOfferShow(previewId, detailsId, stateId)
{
    var previewCtrl = document.getElementById(previewId);
    var detailCtrl = document.getElementById(detailsId);
    var stateCtrl = document.getElementById(stateId);


    var stateVals = null;
    
    if(stateCtrl.value)
        stateVals = stateCtrl.value.split(';');
        
    if (stateVals)
    {
        var currPreviewCtrl = document.getElementById(stateVals[0]);
        var currDetailCtrl = document.getElementById(stateVals[1]);
        
        myOfferShowHideCtrl(currPreviewCtrl, true);
        myOfferShowHideCtrl(currDetailCtrl, false);    
    }
    
    stateCtrl.value = previewId + ';' + detailsId;
    myOfferShowHideCtrl(previewCtrl, false);
    myOfferShowHideCtrl(detailCtrl, true);
}

function myOfferHide(previewId, detailsId, stateId)
{
    var previewCtrl = document.getElementById(previewId);
    var detailCtrl = document.getElementById(detailsId);
    var stateCtrl = document.getElementById(stateId);    
    
    stateCtrl.value = '';
    
    myOfferShowHideCtrl(previewCtrl, true);
    myOfferShowHideCtrl(detailCtrl, false);
}

function myOfferShowHideCtrl(ctrl, show)
{
    var _style = ctrl.style;
    
    if(!show || show != true)
    {
        _style.visibility = 'hidden';
        _style.display = 'none';
    }
    else
    {
        _style.visibility = 'visible';
        _style.display = 'block';
    }    
}




/*---------------------------------------
layer expansion on My Offers page
---------------------------------------*/

var openItem = null;

/* Firefox does not ignore whitespace/linebreaks between divs properly. 
To get around it, we sort out the DOM tree nodes first depending on the browser */
function ShowHideOfferItem(clickedObj)
{
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        ShowHideOfferItemBrowser(clickedObj, 0, 2, 0, 1, 2, 3, 3);
    }
    else
        ShowHideOfferItemBrowser(clickedObj, 1, 5, 1, 3, 5, 7, 7);    
}


function ShowHideOfferItemBrowser(clickedObj, show, textarea, shorttext, readmore, longtext, button, hide)
{
    if (clickedObj.className == "branditem_show" || clickedObj.className == "branditem_image")
    {                            
        var brandItemDiv = clickedObj.parentNode;
        
        var showSibling = brandItemDiv.childNodes[show];
        showSibling.className = "branditem_invisible";
        
        var textAreaSibling = brandItemDiv.childNodes[textarea];           
        var shortTextChild = textAreaSibling.childNodes[shorttext];
        shortTextChild.className = "branditem_invisible";
        var readmoreChild = textAreaSibling.childNodes[readmore];
        readmoreChild.className = "branditem_invisible";
        var longTextChild = textAreaSibling.childNodes[longtext];
        longTextChild.className = "branditem_longtext";
        var buttonChild = textAreaSibling.childNodes[button];
        buttonChild.className = "branditem_button";
        
        var hideSibling = brandItemDiv.childNodes[hide];
        hideSibling.className = "branditem_hide";
        
        if (openItem != null && openItem != brandItemDiv) { closeItem(openItem, show, textarea, shorttext, readmore, longtext, button, hide); }
        brandItemDiv.className = "branditem_open";
        openItem = brandItemDiv;           
    }
    
    if (clickedObj.className == "branditem_readmore")
    {
        var brandItemDiv = clickedObj.parentNode.parentNode;
                      
        var showSibling = brandItemDiv.childNodes[show];
        showSibling.className = "branditem_invisible";
        var textAreaSibling = brandItemDiv.childNodes[textarea];
        
        var shortTextChild = textAreaSibling.childNodes[shorttext];
        shortTextChild.className = "branditem_invisible";
        var readmoreChild = textAreaSibling.childNodes[readmore];
        readmoreChild.className = "branditem_invisible";
        var longTextChild = textAreaSibling.childNodes[longtext];
        longTextChild.className = "branditem_longtext";
        var buttonChild = textAreaSibling.childNodes[button];
        buttonChild.className = "branditem_button";
        
        var hideSibling = brandItemDiv.childNodes[hide];
        hideSibling.className = "branditem_hide";
        
        if (openItem != null) { closeItem(openItem, show, textarea, shorttext, readmore, longtext, button, hide); }
        brandItemDiv.className = "branditem_open";
        openItem = brandItemDiv;                       
    }
    
    if (clickedObj.className == "branditem_hide")
    {        
        var brandItemDiv = clickedObj.parentNode;

        var showSibling = brandItemDiv.childNodes[show];
        showSibling.className = "branditem_show";
        var textAreaSibling = brandItemDiv.childNodes[textarea];
        
        var shortTextChild = textAreaSibling.childNodes[shorttext];
        shortTextChild.className = "branditem_shorttext";
        var readmoreChild = textAreaSibling.childNodes[readmore];
        readmoreChild.className = "branditem_readmore";
        var longTextChild = textAreaSibling.childNodes[longtext];
        longTextChild.className = "branditem_invisible";
        var buttonChild = textAreaSibling.childNodes[button];
        buttonChild.className = "branditem_invisible";
        
        var hideSibling = brandItemDiv.childNodes[hide];
        hideSibling.className = "branditem_invisible";
        
        openItem.className = "branditem";
        openItem = null;            
    }
}

function closeItem(item, show, textarea, shorttext, readmore, longtext, button, hide)
{
    var showSibling = item.childNodes[show];
    showSibling.className = "branditem_show";
    var textAreaSibling = item.childNodes[textarea];
    
    var shortTextChild = textAreaSibling.childNodes[shorttext];
    shortTextChild.className = "branditem_shorttext";
    var readmoreChild = textAreaSibling.childNodes[readmore];
    readmoreChild.className = "branditem_readmore";
    var longTextChild = textAreaSibling.childNodes[longtext];
    longTextChild.className = "branditem_invisible";
    var buttonChild = textAreaSibling.childNodes[button];
    buttonChild.className = "branditem_invisible";
    
    var hideSibling = item.childNodes[hide];
    hideSibling.className = "branditem_invisible"; 
    
    item.className = "branditem";       
}
