/***************
 ** Variables **
 ***************/

var wHelp = new webHELP();

function webHELP() {
  this.on = false;
} // aprsTACTICAL::Constructor

webHELP.prototype.ON = function() {
  if (this.on)
    return;

  this.on = true;
} // webHELP::ON

webHELP.prototype.isON = function() {
  return this.on;
} // aprsTACTICAL::isON

webHELP.prototype.OFF = function() {
  if (!this.on)
    return false;

  this.on = false;
} // webHELP::OFF

/** 
 * webHELP::doSurvey
 *
 * Load's a help article into the help window.
 *
 */
webHELP.prototype.doSurvey = function(helpId, surveyId) {
  var request = createXMLHttpRequest();
  var me = this;

  if (helpId.length != 32) {
    changeById('webHELP:Survey:Error', 'Invalid article id.');
    return;
  } // if

  if (surveyId.length != 32) {
    changeById('webHELP:Survey:Error', 'OK!');
    surveyId = '';
  } // if

  // reset error fields
  changeById('webHELP:Error', '');

  var queryString = "/ajax/help/survey.php?"
                    + "&hl="
                    + helpId
                    + "&s="
                    + surveyId;

  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('webHELP:Survey', retData[i]["response"]);
        } // if
        else {
          if (retData[i]["field"] != 'webHELP:Survey:Error')
            changeById('webHELP:Survey:Error', 'There was an error processing your request.');

          changeById(retData[i]["field"], retData[i]["response"]);
        } // else
      } // for
    } // if
  
  } // function()
    
  request.send(null);
} // webHELP:doSurvey

