function hasSupport()
{
    if(typeof hasSupport.support!="undefined")
    {
        return(hasSupport.support);
    }
    var ie55=/msie 5\.[56789]/i.test(navigator.userAgent);

    hasSupport.support= (typeof document.implementation != "undefined" && document.implementation.hasFeature("html", "1.0") || ie55 )

    // Patch the IE55 DOM1 bug
    if(ie55)
    {
        document._getElementsByTagName = document.getElementsByTagName;
        document.getElementsByTagName  = function(sTagName)
        {
            if(sTagName=="*")
            {
                return document.all;
            }
            else
            {
                return document._getElementsByTagName(sTagName);
            }
        };
    }
    return(hasSupport.support);
}

////////////////////////////////////////////////////////////////////////////////
// Tab pane constructor
//
// el : HTMLElement
// bUseCookie : Boolean, Optional, Default is true for Persistence
////////////////////////////////////////////////////////////////////////////////

function LBCTabPane(el, bUseCookie)
{
    if(!hasSupport()||el==null) return;

    this.element=el;
    this.element.tabPane=this;
    this.pages=[];
    this.selectedIndex = null;
    this.useCookie=bUseCookie!=null?bUseCookie:false;
    this.useCookie = false;

    // add class name tag to class name

    this.element.className=this.classNameTag + " " + this.element.className;

    // add tab row

    this.tabRow=document.createElement("div");
    this.tabRow.className="tab-row";
    el.insertBefore(this.tabRow, el.firstChild);

    var tabIndex=0;

    if (this.useCookie)
    {
        tabIndex = Number(LBCTabPane.getCookie("LBCtab_" + this.element.id));
        if (isNaN(tabIndex)) tabIndex = 0;
    }
    else
    {
        LBCTabPane.removeCookie("LBCtab_" + this.element.id)
    }

    // loop through child nodes and add them

    var cs=el.childNodes;
    this.selectedIndex = tabIndex < cs.length ? tabIndex : 0;

    for(var i=0; i<cs.length; i++)
    {
        if(cs[i].nodeType==1&&cs[i].className=="tab-page")
        {
            this.addTabPage(cs[i]);
        }
    }
}

LBCTabPane.prototype.classNameTag="LBC-tab-pane-control";

LBCTabPane.prototype.setSelectedIndex=function(n)
{
    if(this.selectedIndex!=n)
    {
        if(this.selectedIndex!=null&&this.pages[this.selectedIndex]!=null)
            this.pages[this.selectedIndex].hide();

        this.selectedIndex=n;
        this.pages[this.selectedIndex].show();
        if(this.useCookie)
            LBCTabPane.setCookie("LBCtab_" + this.element.id, n);
    }
};

LBCTabPane.prototype.getSelectedIndex=function()
{
    return(this.selectedIndex);
};

LBCTabPane.prototype.getCurrentTab=function()
{
    return this.pages[this.selectedIndex];
};

LBCTabPane.prototype.addTabPage=function(oElement)
{
    if(!hasSupport()) return;
    if(oElement.tabPage==this) return oElement.tabPage; // already added

    var n=this.pages.length;
    var tp=this.pages[n]=new LBCTabPage(oElement, this, n);

    tp.tabPane=this;

// move the tab out of the box

    this.tabRow.appendChild(tp.tab);
    if(n==this.selectedIndex)
    {
        tp.show();
    }
    else
    {
        tp.hide();
    }
    return(tp);

};

LBCTabPane.prototype.dispose=function()
{
    this.element.tabPane=null;
    this.element=null;		
    this.tabRow=null;

    for(var i=0; i<this.pages.length; i++)
    {
        this.pages[i].dispose();
        this.pages[i]=null;
    }
    this.pages=null;
};

// Persistence cookie handler

LBCTabPane.setCookie=function(sName, sValue, nDays)
{
    var expires="";

    if(nDays)
    {
        var d=new Date();

        d.setTime(d.getTime() + nDays * 24 * 60 * 60 * 1000 );
        expires="; expires=" + d.toGMTString();
    }
    document.cookie=sName + "=" + sValue + expires + "; path=/";
};

LBCTabPane.getCookie=function(sName)
{
    var re=new RegExp("(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)" );
    var res=re.exec(document.cookie);

    return(res!=null?res[3]:null);
};

LBCTabPane.removeCookie=function(name)
{
    LBCTabPane.setCookie(name, "", -1);
};

////////////////////////////////////////////////////////////////////////////////
// Tab page constructor
// Do NOT call directly Use LBCTabPage.addTabPage instead
//
// el      : HTMLElement
// tabPane : LBCTabPane   - The parent tab pane
// nindex  : Number      - The index of the page in the parent pane page array
////////////////////////////////////////////////////////////////////////////////

function LBCTabPage(el, tabPane, nIndex)
{
    if(!hasSupport()||el==null) return;
    this.element=el;
    this.element.tabPage=this;
    this.index=nIndex;

    var cs=el.childNodes;

    for(var i=0; i<cs.length; i++)
    {
        if(cs[i].nodeType==1&&cs[i].className=="tab")
        {
            this.tab=cs[i];
            break;
        }
    }

    this.url     = null;
    this.params  = null;
    this.display = null;

    for(var i=0; i<cs.length; i++)
    {
        if(cs[i].className == "tab-frame-asp")
        {
            this.url = cs[i].firstChild.nodeValue;
            break;
        }
    }

    for(var i=0; i<cs.length; i++)
    {
        if(cs[i].className == "tab-frame-params")
        {
            this.params = cs[i].firstChild.nodeValue;
            break;
        }
    }

    for(var i=0; i<cs.length; i++)
    {
        if(cs[i].className == "tab-data-display")
        {
            this.display = cs[i];
            break;
        }
    }

    // envelop a tag around content to support keyboard navigation

    var a=document.createElement("A");
    this.aElement=a;
    a.href="#";
    a.onclick=function()
    {
        return false;
    };

    while(this.tab.hasChildNodes())
    {
        a.appendChild(this.tab.firstChild);
    }
    this.tab.appendChild(a);

    // hook up events, using DOM0

    var oThis=this;
    this.tab.onclick=function()
    {
        oThis.select();
    };

    this.tab.onmouseover=function()
    {
        LBCTabPage.tabOver(oThis);
    };

    this.tab.onmouseout=function()
    {
        LBCTabPage.tabOut(oThis);
    };
}

LBCTabPage.prototype.show=function()
{
    var el=this.tab;
    var s=el.className + " selected";

    s=s.replace(/ +/g, " ");
    el.className=s;
    this.element.style.display="block";
    this.refresh()
};

LBCTabPage.prototype.hide=function()
{
    var el=this.tab;
    var s=el.className;

    s=s.replace(/ selected/g, "");
    el.className=s;
    this.display.src = ''
    this.element.style.display="none";
};

LBCTabPage.prototype.refresh=function()
{
    if (this.url != null && this.params != null) this.display.src = this.url + '?' + this.params + '&dummy=' + (new Date()).getTime();
};

LBCTabPage.prototype.select=function()
{
    this.tabPane.setSelectedIndex(this.index);
};

LBCTabPage.prototype.dispose=function()
{
    this.aElement.onclick=null;
    this.aElement=null;
    this.element.tabPage=null;
    this.tab.onclick=null;
    this.tab.onmouseover=null;
    this.tab.onmouseout=null;
    this.tab=null;
    this.tabPane=null;
    this.element=null;
};

LBCTabPage.tabOver=function(tabpage)
{
    var el=tabpage.tab;
    var s=el.className + " hover";

    s=s.replace(/ +/g, " ");
    el.className=s;
};

LBCTabPage.tabOut=function(tabpage)
{
    var el=tabpage.tab;
    var s=el.className;

    s=s.replace(/ hover/g, "");
    el.className=s;
};

/*******************************************************************************
 The following methods load and unload the tabs
 ********************************************************************************/

// Initialise all uninitialised tab panes and tab pages

function setupAllTabs(pPersistence)
{
    if(!hasSupport()) return;

    var all = document.getElementsByTagName("*");
    var l = all.length;
    var tabPaneRe = /tab\-pane/;
    var tabPageRe = /tab\-page/;
    var cn;
    var el;
    var parentTabPane;
    var Persistence = pPersistence != null ? pPersistence : false;

    for(var i=0; i<l; i++)
    {
        el=all[i]
        cn=el.className;

        // no className
        if(cn=="") continue;

        // uninitiated tab pane
        if(tabPaneRe.test(cn)&&!el.tabPane) new LBCTabPane(el,Persistence);

        // uninitiated tab page with a valid tab pane parent
        else if(tabPageRe.test(cn)&&!el.tabPage&&tabPaneRe.test(el.parentNode.className))
        {
            el.parentNode.tabPane.addTabPage(el, Persistence);
        }
    }
}

function disposeAllTabs()
{
    if(!hasSupport()) return;

    var all=document.getElementsByTagName("*");
    var l=all.length;
    var tabPaneRe=/tab\-pane/;
    var cn;
    var el;
    var tabPanes=[];

    for(var i=0; i<l; i++)
    {
        el = all[i]
        cn = el.className;

        // no className
        if(cn == "") continue;

        // tab pane
        if(tabPaneRe.test(cn)&&el.tabPane) tabPanes[tabPanes.length]=el.tabPane;
    }

    for(var i=tabPanes.length-1; i>=0; i--)
    {
        tabPanes[i].dispose();
        tabPanes[i]=null;
    }
}

/*****************************************************************************
 The following code sets the window events to load/unload the tabs
 ******************************************************************************/

if(typeof window.addEventListener != "undefined") // DOM2
{
    window.addEventListener("load", setupAllTabs, false);
}
else if(typeof window.attachEvent != "undefined" ) // IE
{
    window.attachEvent("onload", setupAllTabs);
    window.attachEvent("onunload", disposeAllTabs);
}
else
{
    if(window.onload != null)
    {
        var oldOnload = window.onload;
        window.onload = function(e)
        {
            oldOnload(e);
            setupAllTabs();
        };
    }
    else 
    {
        window.onload = setupAllTabs;
    }
}
