/**
 *  @fileoverview   Functions for easy-actions page.
 *//*
 *  Functions
 *    markPlan(planId)
 *    procMarkPlanRsp()
 */

/**
 *  Adds an action plan to a user's account.
 *
 *  @global {XMLHttpRequest} xhRequest
 *  @global {String} page
 *  @param {int} userPlanId
 *  @param {int} planId
 *  @type   void
 */
function markPlan(userPlanId, planId)
{
  if (makeXMLHttpRequest()) {
    xhRequest.procFunc = procMarkPlanRsp;
    xhRequest.post(updir + "rsp_mark_plan.php", "page=" + page +
      "&plan_id=" + planId + "&user_plan_id=" + userPlanId);
  }
}

/**
 *  Process the response from rsp_mark_plan.
 *
 *  @global {String} flashId
 *  @type   void
 */
function procMarkPlanRsp()
{
  var status;

  try {
    status = xhRequest.responseXML.getElementsByTagName("status")[0].firstChild.nodeValue;
  }
  catch (e) {
    status = -1;
  }

  switch (status) {
    case -1:
      alert("ERROR: no xml-http-request response");
      break;

    case DB_ERR:
      alert("ERROR: database error");
      break;

    case NO_LOGIN:
      toggleOverlay("overlay_signup");
      break;

    case INVALID_USER:
      alert("ERROR: invalid user id");
      break;

    case PLAN_ALREADY_MARKED:
      alert("ERROR: plan already marked");
      break;

    case PLAN_INVALID_PLAN:
      alert("ERROR: invalid plan id");
      break;

    case PLAN_MARK_SUCCESS:
      switch (page) {
        case "mea":
        case "act":
          js2asMarkPlan(flashId);
          procSidebar();
          break;
      }

      break;

    case PLAN_ACTIVATE_SUCCESS:
      switch (page) {
        case "mea":
          js2asMarkPlan(flashId);
          procSidebar();
          break;
      }

	  break;

    default:
      alert("ERROR: " + status);
  }
}
