/**************************************************
 ** Global Variables                             **
 **************************************************/

/**************************************************
 ** Inbox Functions                              **
 **************************************************/

/**     
 * doViewInbox
 *
 * Load's the users current inbox.
 *
 */
function doViewInbox() {
  var request = createXMLHttpRequest();

  changeById('helpContainer', '<div id="APRSMail:Inbox:Data"></div>'
                              + '<div id="APRSMail:Inbox:Error" style="color: red; font-size: 8px; font-weight: bold; text-transform: uppercase"></div>'
            );

  if (!loggedIn) {
    changeById('APRSMail:Inbox:Error', 'You must be logged in to use this feature.');
    return;
  } // if

  changeById('APRSMail:Inbox:Error', "Loading inbox...");

  var queryString = "/ajax/aprsmail/inbox/view.php?h="
                    + seed;

  request.open("GET", queryString, true);
  request.onreadystatechange = function() {

    if (request.readyState == 4) {
      var xmlDoc = request.responseXML;

      var retData = new Array();
      xmlArray("/openaprs/reply", xmlDoc, retData);
      for (i=0; i < retData.length; i++) {
        if (retData[i]["done"] == "yes") {
          changeById('APRSMail:Inbox:Data', retData[i]["response"]);
          changeById('APRSMail:Inbox:Error', '');
        } // if
        else {
          //changeById('helpContainer', "There was an error loading your inbox.");
          changeById(retData[i]["field"], retData[i]["response"]);
        } // else
      } // for

    } // if

  } // function()

  request.send(null);
} // doViewInbox

/**     
 * doDeleteMessages
 *
 * Load's a help article into the help window.
 *
 */
function doDeleteMessages(isPass) {
  var request = createXMLHttpRequest();

  if (!loggedIn) { 
    changeById('Signup:Error', 'You must be logged in to use this feature.');
    return;
  } // if

  if (isPass)
    var queryString = "/ajax/signup/passview.php?h="
                      + seed;
  else
    var queryString = "/ajax/signup/view.php?h="
                      + seed;

  request.open("GET", queryString, true);
  request.onreadystatechange = function() {

    if (request.readyState == 4) {
      var xmlDoc = request.responseXML;

      var retData = new Array();
      xmlArray("/openaprs/signup", xmlDoc, retData);
      for (i=0; i < retData.length; i++) {
        if (retData[i]["done"] == "yes")
          changeById('helpContainer', retData[i]["response"]);
        else {
          changeById('wasHelpful', "There was an error processing your signup, see the fields with red error messages next to them to correct the problem.");
          changeById(retData[i]["field"], retData[i]["response"]);
        } // else
      } // for

    } // if

  } // function()

  request.send(null);
} // doDeleteMessages


