  //////////////////////////
  // AJAX Callback Routine
  //////////////////////////
  function chatPopup_callback(ajax) {

    // alert(ajax.responseText);

    var xml = ajax.responseXML;

    ///////////////////////////////////////////////////////
    // Open a DENIED window if a chat request was denied
    ///////////////////////////////////////////////////////
    if (xml.getElementsByTagName("denied").length) {
      var firstname = getNodeText(xml.getElementsByTagName("firstname")[0]);
      var lastname = getNodeText(xml.getElementsByTagName("lastname")[0]);
      open_denied_chat_window (firstname, lastname);
    }

    //////////////////////////////////////////////////////////
    // Open an ACCEPTED window if a chat request was accepted
    //////////////////////////////////////////////////////////
    else if (xml.getElementsByTagName("accepted").length) {
      var firstname = getNodeText(xml.getElementsByTagName("firstname")[0]);
      var lastname = getNodeText(xml.getElementsByTagName("lastname")[0]);
      var chatroom = getNodeText(xml.getElementsByTagName("chatroom")[0]);
      open_accepted_chat_window (firstname, lastname, chatroom);
    }

    //////////////////////////////////////////////////////////
    // Open a REQUEST window if a chat session was requested
    //////////////////////////////////////////////////////////
    else if (! xml.getElementsByTagName("no_chat").length) {
      var firstname = getNodeText(xml.getElementsByTagName("firstname")[0]);
      var lastname = getNodeText(xml.getElementsByTagName("lastname")[0]);
      var chatroom = getNodeText(xml.getElementsByTagName("chatroom")[0]);
      open_chat_window (firstname, lastname, chatroom);
    }

    // alert(firstname + lastname + chatroom);

    setTimeout("chatPopup()", 15000);
  }


  ////////////////////////////////////////////////////////
  // Open a chat window when a chat session is denied
  ////////////////////////////////////////////////////////
  function open_accepted_chat_window (fname, lname, chatroom) {
    var inlinewin=dhtmlwindow.open("broadcastbox", "inline", "<div id=\"content_left\"><h2>" + fname + " " + lname + " has<br />accepted your chat request.</h2><a href='/dashboard/chat/chat_now.php?room=" + chatroom + "&status=A'><img src='images/icon_chatnow.gif' border='0'></a></div>", "Accepted Chat Request", "width=300px,height=115px,left=30px,top=30px,resize=0,scrolling=0", "recal") 
  }

  ////////////////////////////////////////////////////////
  // Open a chat window when a chat session is denied
  ////////////////////////////////////////////////////////
  function open_denied_chat_window (fname, lname) {
    var inlinewin=dhtmlwindow.open("broadcastbox", "inline", "<div id=\"content_left_dash\"><h2>" + fname + " " + lname + " has<br />denied your chat request.</h2><a href='/dashboard/'><img src='images/icon_closewin.gif' border='0'></a></div>", "Denied Chat Request", "width=300px,height=115px,left=30px,top=30px,resize=0,scrolling=0", "recal") 
  }

  ////////////////////////////////////////////////////////
  // Open a chat window when a chat session is requested
  ////////////////////////////////////////////////////////
  function open_chat_window (fname, lname, chatroom) {
    var inlinewin=dhtmlwindow.open("broadcastbox", "inline", "<div id=\"content_left_dash\"><h2>" + fname + " " + lname + " has requested<br /> a chat session with you.</h2><a href='/chat?room=" + chatroom + "&status=A'><img src='/dashboard/images/icon_accept.gif' border='0'></a>&nbsp;<a href='./?decline=true&room=" + chatroom + "'><img src='/dashboard/images/icon_decline.gif' border='0'></a></center></div>", "Incoming Chat Request", "width=300px,height=115px,left=30px,top=30px,resize=0,scrolling=0", "recal") 
  }

  ///////////////////////////
  // Main AJAX Chat Handler
  ///////////////////////////
  function chatPopup() {
    var ajax = new thajax();
    ajax.request("/dashboard/chat/chat_check_xml.php",chatPopup_callback);
  }
