Get Chat Status in JSON format |  |

# (1) Obtain operator status

Call the 'get_chat_status.php' script, asking it to return data in JSON format.

`<script language="javascript" type="text/javascript" src="/dmx/core/webchat/php/get_chat_status.php?res_type=json"></script>`

This creates a javascript object named dmx_webchat [ show details ]

[ hide details ]

### dmx_webchat object: properties

dmx_webchat is a javascript object containing lots of data (or more formally, having lots of properties) describing which chat operators are online, and the departments they belong to. It has the following structure...

dmx_webchat.chatserver contains the domain name or IP address of the chat server
dmx_webchat.all contains data about all departments:
dmx_webchat.all.num = The total number of chat operators available, eg 2
dmx_webchat.all.depts = A list of departments online (each preceded and followed by '#')
eg '#Technical Support#Sales#'
dmx_webchat.all.names = A list of operators online (each preceded and followed by '#')
eg '#Rich#Sascha#'
dmx_webchat.depts contains similar information of a department by department basis, eg:
dmx_webchat.depts.technical_support.num = 1
dmx_webchat.depts.technical_support.names = '#Rich#'
dmx_webchat.depts.sales.num = 1
dmx_webchat.depts.sales.names = '#Sascha#'
dmx_webchat.operators contains the status of each operator (if present)
Note that when used in the dmx_webchat.depts sub-object, department names are lowercase,
with spaces replaced by underscores, eg: 'Technical Support' => 'technical_support'

## (2) Example code: display a chat link if any operators are available

Test dmx_webchat.all.num to get the total number of operators available.
Insert either the 'Chat with us now' graphic or a 'Chat unavailable' graphic.

    <script language="javascript">
    <!--
    if (dmx_webchat.all.num > 0) {
    	document.write('<a href="#" onclick="window.open(\'http://' + dmx_webchat.chatserver + '/chat/chatstart.htm');
    	document.write('?domain=' + window.location.host);
    	document.write('&bg=http://' + window.location.host + '/dmx/core/webchat/images/chat_bg.jpg\', ');
    	document.write('\'new_win\', \'\width=484,height=361\'); return false;">');
    	document.write('<img src="/dmx/core/webchat/images/icon_chat_on_black.gif" border="0" /><\/a>');
    } else {
    	document.writeln('<img src="/dmx/core/webchat/images/icon_chat_off_black.gif" />');
    }
    //-->
    </script>

RESULT:

## (3) Example code: display a chat link if anyone form 'Technical Support' is available

Test dmx_webchat.depts.technical_support.num to get the number of online operators from 'Technical Support'.
Insert either the 'Chat with us now' graphic or a 'Chat unavailable' graphic.

    <script language="javascript">
    <!--
    var department = 'Technical Support'; // Set department to test here
    // -------------------------------------------------------------------------------------------------
    var d = department.replace(' ', '_').toLowerCase();
    if (dmx_webchat.all.depts.indexOf('#' + department + '#') != -1 && dmx_webchat.depts[d].num > 0) {
    	document.write('<a href="#" onclick="window.open(\'http://' + dmx_webchat.chatserver + '/chat/chatstart.htm');
    	document.write('?domain=' + window.location.host);
    	document.write('&bg=http://' + window.location.host + '/dmx/core/webchat/images/chat_bg.jpg');
    	document.write('&department=' + encodeURI(department) + '\', ');
    	document.write('\'new_win\', \'\width=484,height=361\'); return false;">');
    	document.write('<img src="/dmx/core/webchat/images/icon_chat_on_black.gif" border="0" /><\/a>');
    } else {
    	document.writeln('<img src="/dmx/core/webchat/images/icon_chat_off_black.gif" />');
    }
    //-->
    </script>

RESULT: