
//
// Responses
//

function returnNewSub() {

  var request = returnNewSub.reqObj;

  if (request.readyState == 4) {
    if (request.status == 200) {

		var mytext = request.responseText;

        if (mytext == '0') {
          alert("ERROR! There was a problem attempting to save new subcategory:\nYou have been logged out or there was a problem with the category listing.  Please try again.");
        } else if (mytext == '1') {
          alert("The subcategory you are trying to add already exists!  Please select the existing subcategory from the pulldown.");
        } else {

  		  var jsonObject = eval('(' + mytext + ')');

	      // variables from json
	      var uniqueId       = jsonObject.uniqueId;
	      var category_name  = jsonObject.category_name;
	      var category_id    = jsonObject.category_id;
	      var parent_id      = jsonObject.parent_id;

		  // variables built here
		  var formObj = $('formAddNew_'+uniqueId);
		  var parentSelectObj = formObj.previousSibling.previousSibling;

		   // remove form
		   formObj.parentNode.removeChild(formObj);

	       // add option to existing pulldown
	       var numOptions = parentSelectObj.options.length;
	       var theOption = new Option(category_name,category_id);
	       parentSelectObj.options[numOptions] = theOption;
	       parentSelectObj.selectedIndex = numOptions;
	       parentSelectObj.onchange();  // TODO: is this valid in all browsers?

		    // update recursive array
		    // TODO: this is hard-coded
		    if (!categoryChildren[parent_id]) categoryChildren[parent_id] = new Array;
		    categoryChildren[parent_id][category_id] = category_name;
		    categoryParents[category_id] = parent_id;

        }

    } else {
      alert("ERROR! There was a problem attempting to save new subcategory:\nCould not find the required AJAX file.  Please try again.");
    }

  }
  return true;

}

function returnMetaAll() {

  var request = returnMetaAll.reqObj;

  if (request.readyState == 4) {
    if (request.status == 200) {

		var mytext = request.responseText;

        if (mytext == '1') {
          // worked!!
        } else {

		  // error
		  alert("ERROR! There was a problem attempting to save to value of the 'seperate info' | 'same info' pulldown.  Please try again.");

  		  //var jsonObject = eval('(' + mytext + ')');

        }

    } else {
      alert("ERROR! There was a problem attempting to save to value of the 'seperate info' | 'same info' pulldown: could not find the required AJAX file.  Please try again.");
    }

  }
  return true;

}

function returnAdminAnonUpload() {

  var request = returnAdminAnonUpload.reqObj;

  if (request.readyState == 4) {
    if (request.status == 200) {

		var mytext = request.responseText;

        if (mytext == '1') {
          // worked!!
        } else {

		  // error
		  alert("ERROR! There was a problem attempting to save to value of admin anonymous upload pulldown.  Please try again.");

  		  //var jsonObject = eval('(' + mytext + ')');

        }

    } else {
      alert("ERROR! There was a problem attempting to save to value of admin anonymous upload pulldown: could not find the required AJAX file.  Please try again.");
    }

  }
  return true;

}

