function TabClick(e, DblClick) {
    if (e.ctrlKey || e.shiftKey || e.altKey)
        return;
    if (DblClick==1 && e.button!=0) return;
    if (DblClick==0 && e.button!=1) return;

    var aTab = e.originalTarget;
    if (aTab.localName=="toolbarbutton")
        return;
    while(aTab.localName != "tabs") {
        if (aTab.localName == "tab")
            break;
        else
            aTab = aTab.parentNode;
    }
    if (aTab.localName != "tab") {
        if (DblClick == 1)
            BrowserOpenTab();
        else
            undoCloseTab();
    }
    else if(gBrowser.mTabContainer.childNodes.
        length == 1)
        openUILinkIn("about:blank", "current");
    else
        gBrowser.removeTab(aTab);
}
function TabBarClick(e) {
    if (e) TabClick(e, 0);
}
function TabBarDblClick(e) {
    if (e) TabClick(e, 1);
}
getBrowser().onTabClick = TabBarClick;
getBrowser().onTabBarDblClick = TabBarDblClick;