    
function Main(
         lblCompanyNameID,
         lblUserNameID,
         tbSearchID,
         cbExtendSessionID,
         splitterBodyID,
         paneContentID,
         paneMenuID,
         cbGetGMTOffsetID,
         winChatPopupID
         )
{
    this.LoadCompany = LoadCompany;
    this.LoadContentFrame = LoadContentFrame;
    this.DoSearch = DoSearch;
    this.ExtendSession = ExtendSession
    this.HideMenuPane = HideMenuPane;
    this.GetGMTOffset = GetGMTOffset;
    this.StartChat = StartChat;
    this.HandleChatWindowClosed = HandleChatWindowClosed;
    this.CloseChatWindow = CloseChatWindow;
    this.ClearChatWindowContents = ClearChatWindowContents;
    this.HandleNewMessages = HandleNewMessages;
    this.HandleChatWindowCommand = HandleChatWindowCommand;
    this.HandleWindowOnBlur = HandleWindowOnBlur;
    this.HandleWindowOnFocus = HandleWindowOnFocus;
     
    // Code to handle window blur and focus
    var fWindowHasFocus = true;
    function HandleWindowOnBlur() 
    {
        fWindowHasFocus = false;
    }
    function HandleWindowOnFocus() 
    {
        fWindowHasFocus = true;
    }
    if (/*@cc_on!@*/false) {    // check for Internet Explorer
        document.onfocusin = this.HandleWindowOnFocus;
        document.onfocusout = this.HandleWindowOnBlur;
    } else {
        window.onfocus = this.HandleWindowOnFocus;
        window.onblur = this.HandleWindowOnBlur;
    }  
    
    function HideMenuPane()
    {
        var splitter = $find(splitterBodyID);
        var pane = splitter.getPaneById(paneMenuID);
        if (!pane) return;
        pane.collapse();
    }
    
    
    function ExtendSession()
    {
        ASPxClientControl.GetControlCollection().Get(cbExtendSessionID).SendCallback("extendsession");
    }
    
    function GetGMTOffset()
    {
        var d = new Date();
        var offset = d.getTimezoneOffset();
        ASPxClientControl.GetControlCollection().Get(cbGetGMTOffsetID).SendCallback(offset);
    }
    
    function DoSearch()
    {
      var tbSearch = document.getElementById(tbSearchID);
      
      if (tbSearch.value == null || tbSearch.value == "" || tbSearch.value == "Knowledge Base Search")
      {
        alert("Please enter some search keywords.");
        return;
      }
      var url = "KBSearch.aspx?searchtext=" + tbSearch.value;
      this.LoadContentFrame(url);
    }
  
    
    function LoadContentFrame(url) 
    {
        var splitter = $find(splitterBodyID);
        var pane = splitter.getPaneById(paneContentID);
        if (!pane) return;
        pane.set_contentUrl(url);
    }


    function LoadCompany(id, name)
    {
        // Update the company name label
        document.getElementById(lblCompanyNameID).innerHTML = name;
        
        
        // Reload the IncidentList page into the content pane
        LoadContentFrame("IncidentList.aspx");
       
    }

    //var fChatWindowTitle;
    function StartChat(title, channelid) 
    {
        // When starting a new chat session pass in the real channelid and 0 for the chatid
        // When restoring an existing chat session pass in 0 for the channelid and the real chatid
        var win = $find(winChatPopupID);

        if (win.isVisible()) 
        {
            alert("You can only have one chat window open at a time.  To start a new chat please close the existing chat window.");
        }
        else 
        {
            win.set_title(title);
            win.setUrl("ChatStart.aspx?channelid=" + channelid + "&title=" + title);
            win.show();
            //PositionChatWindow(win);
        }

        fKBArticleSolvedChatIssue = false;
    }

    function HandleChatWindowClosed() 
    {
        // Call EndChat() in the actual chat page that appears in the popup in order to end the chat session
        var win = $find(winChatPopupID);
        if (win != null)
        {
            var _chat = win.get_contentFrame().contentWindow._chat;
            if (_chat != null)
                _chat.EndChat(fKBArticleSolvedChatIssue);
         }   
        // Note: win.setUrl cannot be called at this point to clear the contents of the chat popup because
        // if it's called then the logig withing _chat.EndChat() will not complete correctly
        //win.setUrl('');

        // reset fKBArticleSolvedChatIssue to a default of false in case this function get's called by closing the chat window
        // using the X button because in that case fKBArticleSolvedChatIssue will not 
        fKBArticleSolvedChatIssue = false;
    }

    var fKBArticleSolvedChatIssue = false;
    function CloseChatWindow(kbArticleSolvedIssue) 
    {
        // store the value of kbArticleSolvedIssue in a class level var so it can be referenced in HandleChatWindowClosed
        fKBArticleSolvedChatIssue = kbArticleSolvedIssue;
        
        // close the chat window which will trigger the HandleChatWindowClosed event handler
        var win = $find(winChatPopupID);
        win.close();
    }

    function ClearChatWindowContents() 
    {
        // Clear the contents of the chat window by resetting the url to blank
        var win = $find(winChatPopupID);
        win.setUrl('');
    }

    function HandleNewMessages() 
    {
        // If the chat window is minimized and there are new messages 
        // then restore the chat window and play a sound to notify the user
        var win = $find(winChatPopupID);
        var playsound = false;
        if (win != null && win.isMinimized()) 
        {
            // restore the window
            win.restore();
            playsound = true;
        }

        // Set the window focus in case a different window has the focus
        //window.focus();
        
        if (!fWindowHasFocus) {
            window.focus();
            playsound = true;
        }

        if (playsound) {
            var _chat = win.get_contentFrame().contentWindow._chat;
            if (_chat != null)
                _chat.PlayNewMessageSound();
        }
     
    }

    function HandleChatWindowCommand(sender, eventArgs) {

    }

//    function PositionChatWindow() {

//        var win = $find(winChatPopupID);
//        if (win != null) {
//            var Y = document.body.clientHeight +
//                        document.body.scrollTop -
//                        win.get_height();

//            var X = document.body.clientWidth +
//                        document.body.scrollLeft -
//                        win.get_width();

//            X = X - 25;
//            Y = Y - 3;
//            
//            Y = (Y > 0) ? Y : 0;
//            X = (X > 0) ? X : 0;
//            win.moveTo(X, Y);
//        }
//    }

    
  
}

