/**
 *  @fileoverview   Functions for Flash.ExternalInterface.
 *//*
 *  Functions
 *    js2asActivatePlan(flashId, userPlanId)
 *    js2asGetPlans(flashId)
 *    js2asMarkPlan(flashId)
 *    js2asPlayVideo(flashId, userPlanId)
 *    as2jsCancelPlan(userPlanId)
 *    as2jsCompletePlan(userPlanID)
 */
 
/**
 *  On-click of link in sidebar plan list, call this EternalInterface function (activatePlan) in the
 *  swf to notify if that a plan has been activated.
 *
 *  @param  {String} flashId    id of the swf object in the page
 *  @param  {int} userPlanId    database user_plan_join table id
 *  @type   void
 */
function js2asActivatePlan(flashId, userPlanId)
{
  try {
    document.getElementById(flashId).js2asActivatePlan(userPlanId);
  }
  catch (e) {
    alert(flashErrMsg + "\n\n" + arguments.callee + "\n\n" + e);
  }
}

/**
 *  On-login from My Easy Actions, call this swf.ExternalInterface function to tell the Flash to
 *  fetch the user's plans.
 *
 *  @param  {String} flashId    id of the swf object in the page
 *  @type   void
 */
function js2asGetPlans(flashId)
{
  try {
    document.getElementById(flashId).js2asGetPlans();
  }
  catch (e) {
    alert(flashErrMsg + "\n\n" + arguments.callee + "\n\n" + e);
  }

}

/**
 *  On-click 'Try plan again', call this swf.ExternalInterface function to tell the Flash request
 *  get_plans.php.
 *
 *  @param  {String} flashId    id of the swf object in the page
 *  @type   void
 */
function js2asMarkPlan(flashId)
{
  switch (page) {
    case "mea":
      try {
        document.getElementById(flashId).js2asMarkPlan();
      }
      catch (e) {
        alert(flashErrMsg + "\n\n" + arguments.callee + "\n\n" + e);
      }
      break;

    case "act":
      try {
        document.getElementById(flashId).markPlan();
      }
      catch (e) {
        alert(flashErrMsg + "\n\n" + arguments.callee + "\n\n" + e);
      }
      break;
  }
}

/**
 *  On-user-click 'Watch video', call this swf.ExternalInterface function to have Flash play video.
 *
 *  @param  {String} flashId      id of the swf object in the page
 *  @param  {String} userPlanId   id of the user-plan
 *  @type   void
 */
function js2asPlayVideo(flashId, userPlanId)
{
  try {
    document.getElementById(flashId).js2asPlayVideo(userPlanId);
  }
  catch (e) {
    alert(flashErrMsg + "\n\n" + arguments.callee + "\n\n" + e);
  }
}

/**
 *  ExternalInterface callback function called when the user clicks the cancel button in the swf.
 *
 *  @param  {int} userPlanId    database user_plan_join table id
 *  @type   void
 */
function as2jsCancelPlan(userPlanId)
{
  cancelActivePlan();
}

/**
 *  ExternalInterface callback function called when the user completes a plan (submits the last
 *  score).
 *
 *  @param  {int} userPlanId    database user_plan_join table id
 *  @param  {int} score         possible values 0 to 4
 */
function as2jsCompletePlan(userPlanID)
{
  completePlan();
}
