
var toolButtonsInitialized=false;
ToolButtons = function() 
{
    var _status;
    var _alertTimer;
    var _timer;
    var _alertInterval;
    
    this.initialize = function(alertInterval)
    {
        _alertInterval=alertInterval;
        if(toolButtonsInitialized)return;
        toolButtonsInitialized=true;
        var obxalert=document.createElement("span");
        obxalert.setAttribute("id","obx_Alert");
        obxalert.className="obx_Alert";
        obxalert.innerHTML="<a href=\"javascript:;\"></a>";
        var obxquerier=document.createElement("span");
        obxquerier.setAttribute("id","obx_Querier");
        obxquerier.className="obx_Querier";
        obxquerier.innerHTML="<a href=\"javascript:;\"></a>";
        
        
        $("toolbuttons").appendChild(obxalert);
        $("toolbuttons").appendChild(obxquerier);
        
        _alertsHandler=Function.createDelegate(this,this._clickAlerts);
        $("obx_Alert").onclick=_alertsHandler;
        
        _queryHandler=Function.createDelegate(this,this._clickQuery);
        $("obx_Querier").onclick=_queryHandler;
        
        this._edit(false);
        this._startAlert();
    }
    
    //-----------------------------------menu buttons---------------------------------
    this._clickAlerts=function()
    {
        if(_status!="edit"&&uimanager.CurrentDesktop.Attribute.ID>0)
        {
            _ShowWindow("ObxAlertWindow");
            this.endFlicker();
        }
    }
    this._clickQuery=function()
    {
        if(_status!="edit"&&uimanager.CurrentDesktop.Attribute.ID>0)
        {
            //_ShowPopupWin("ObxQueryWindow");   
            _ShowWindow("ObxQuickSearchWindow");
        }
    }
    this._clickSetup=function(){}
    this._clickLogout=function(){}
    
    //-------------------------------menu buttons ----------------------------------------
    this.logout=function()
    {
        if(window.confirm('Are you sure you want to logout?'))
        {
        var dt=new Date(); 
	    document.cookie="OBX_AUTH=;expires=" + dt.toGMTString();
        context.request(LoginHandler_URL,"action=logout");
        }
    }
    this.admintool=function()
    {
        context.request(DesktopHandler_URL,"action=active&objectid=-1");

    }
    this.editDesktop=function()
    {
        //this.closeWindows();
        context.request(DesktopHandler_URL,"action=edit&objectid="+uimanager.CurrentDesktop.Attribute.ID);
        //uimanager.CurrentDesktop.edit();
    }
    this.restoreDesktop=function()
    {
        uimanager.CurrentDesktop.restore();
    }
    this.saveDesktop=function()
    {
        uimanager.CurrentDesktop.save();
    }
    this.saveDesktopShow=function(boname)
    {
        uimanager.CurrentDesktop.saveDesktopShow(boname);
    }
    
    this.cancelEditDesktop=function()
    {
        uimanager.CurrentDesktop.destoryGadgets();
        uimanager.CurrentDesktop.cancelEdit();
        uimanager.CurrentDesktop.restore();
        
    }
    //----------------------------------------------------------------------------------------------
    this.refreshWindows=function()
    {
        uimanager.CurrentDesktop.refresh();
    }
    this.showWindows=function()
    {
        uimanager.CurrentDesktop.showWindows();
    }
    this.closeWindows=function()
    {
        uimanager.CurrentDesktop.closeWindows();
    }
    this.minWindows=function()
    {
        uimanager.CurrentDesktop.minWindows();
    }
    this.tileWindows=function()
    {
        uimanager.CurrentDesktop.tile();
    }
    this.cascadeWindows=function()
    {
        uimanager.CurrentDesktop.cascade();
    }
    //--------------------------------------------timer method------------------------------------------
    this._startAlert=function()
    {
        if(!_alertTimer)
        {
            //this._requestAlert();
            _alertTimer=window.setInterval("toolbtn._requestAlert()",_alertInterval);
        }
    }
    this._requestAlert=function()
    {
        context.request(AlertHandler_URL+"?action=alert&objectid="+uimanager.CurrentDesktop.Attribute.ID);
    }
    //-------------------------------------------------------
    this.startFlicker=function()
    {
        if(!_timer)
        {
            _timer=window.setInterval("toolbtn._flicker()",500);
        }
    }
    this._flicker=function()
    {
        if($("obx_Alert").className=="obx_Alert")
        {
            $("obx_Alert").className="obx_hasAlert";
        }
        else
        {
            $("obx_Alert").className="obx_Alert";
        }
    }
    this.endFlicker=function()
    {
        if(_timer)window.clearInterval(_timer);
        _timer=null;
    }
    //--------------------------------------------status method-------------------------------------------
    this._edit=function(value)
    {
        if(value==true)
        {
            $("menu").style.display="none";
            $("menuedit").style.display="block";
        }
        else
        {
            $("menuedit").style.display="none";
            $("menu").style.display="block";
        }
    }
    this.lock=function()
    {
        this._edit(true);
        _status="edit";
    }
    this.unlock=function()
    {
        this._edit(false);
        _status="";
    }
    //this.initialize();
}
