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

var cCallsign = new aprsCALLSIGN();

function aprsCALLSIGN() {
} // aprsCALLSIGN::Constructor

/** 
 * aprsCALLSIGN::Add
 *
 * Load's a help article into the help window.
 *
 */
aprsCALLSIGN.prototype.Add = function() {
  var request = createXMLHttpRequest();
  var callsign = document.getElementById('aprsCALLSIGN:Form:Callsign');
  var me = this;

  if (callsign == null)
    return;

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

  /**
   * Default Variables
   *
   * Span through the possible field values
   * and set our variable list accordingly.
   *
   */
  var ids = {
    "c": "aprsCALLSIGN:Form:Callsign"
  }

  var dfts = {
    "c": ""
  }

  var var_list = createURI(document, false, ids, dfts);

  var queryString = "/ajax/callsign/add.php?&h="
                    + seed
                    + var_list;

  disableField('aprsTACTICAL:Form:Add');
  
  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('aprsCALLSIGN:Error', retData[i]["response"]);
          changeFieldById('openaprs_form_chat_callsign', callsign.value);
          createCookie('myCallsign', callsign.value, 365);
          ClearField('aprsCALLSIGN:Form:Callsign');
          hideWindow('callsignOverlay');
        } // if
        else {
          if (retData[i]["field"] != 'aprsCALLSIGN:Error')
            changeById('aprsCALLSIGN:Error', 'There was an error processing your request.');

          changeById(retData[i]["field"], retData[i]["response"]);
        } // else
      } // for

      enableField('aprsCALLSIGN:Form:Add');
    } // if
  
  } // function()
    
  request.send(null);
} // aprsCALLSIGN::Add

