﻿function _getManager()
{
    var oManager = null;
    oManager = getChatWin().GetRadWindowManager();
    if (!oManager)        
        oManager = getChatWin().GetRadWindowManager();
    if (!oManager)        
        oManager = getChatWin().oWindowManager;
    return oManager;        
}

function ShowStatusWindow(name, content)
{
    var oWnd = getWindow(name);
    if (oWnd == null)
    {
        oWnd = openWindow(name, '', 300, 300);        
        if (content)
        {
            //oWnd.SetContent(content); não funcionou no prometheus
            var frame = oWnd.get_ContentFrame();
            if (frame)
            {
                var _document = null;
                if (frame.contentDocument)
                    _document = frame.contentDocument;
                else _document = frame.contentWindow.document;
                if (_document)
                {
                    _document.open();
                    _document.write(content);
                }
            }
        }                
    }
    oWnd.show();
    oWnd.center();
}

function UpdateStatusWindow(name, content)
{
    var oWnd = getWindow(name);
    if (oWnd != null)
    {
        if (content == null)
          content = '';
        //oWnd.SetContent(content); não funcionou no prometheus
        var frame = oWnd.get_ContentFrame();
        if (frame)
        {
            var _document = null;
            if (frame.contentDocument)
                _document = frame.contentDocument;
            else _document = frame.contentWindow.document;
            if (_document)
            {
                _document.open();
                _document.write(content);
            }
        }        
        oWnd.center();
    }    
}

function CloseStatusWindow(name)
{
    var oWnd = getWindow(name);
    if (oWnd != null)
    {   
        oWnd.Hide();     
        oWnd.Close();
    }
}

function openWindow(name, src, width, height)
{
    var oManager = _getManager();
    var oWnd = oManager.Open(src, name);
    oWnd.setSize(width, height);
    oWnd.center();
    return oWnd;
}

function getWindow(name)
{
    var oManager = _getManager();
    var oWnd = null;
    if (oManager)
        oWnd = oManager.getWindowByName(name);
    return oWnd;
}

function GetSelectedWindow()
{
    var oManager = _getManager();
    var oWnd = oManager.GetActiveWindow();
    oWnd.center();
    return oWnd;
}

function chatAlert(msg, forcerad)
{
    try
    { 
        if (forcerad) 
          chatRadAlert(msg);
        else
        {          
            if (Html_IsWinIE)
              alert(msg);
            else chatRadAlert(msg); 
        }
    }
    catch (e)
    { getChatWin().alert(msg); }
}

function chatRadAlert(msg)
{
    try
    { 
        getChatWin().radalert(msg, 320, 200, "Alerta do LiveCHAT");        
    }
    catch (e)
    { getChatWin().alert(msg); }
}

function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    return oWindow;
} 