Get Chat Status in JSON format better business through  innovative telecoms dmClub logo

(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 ]

(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: