function ScormOnload() {
	if (API != null) {
   	  API.LMSInitialize("");
   	  lmsStudentName = API.LMSGetValue("cmi.core.student_name");
   	  first_name = lmsStudentName.substring((lmsStudentName.lastIndexOf(',')+1),
   	    lmsStudentName.length);
   	  my_status = API.LMSGetValue("cmi.core.lesson_status");
   	  my_LMS_score = API.LMSGetValue("cmi.core.score.raw");
   	  my_last_loc =API.LMSGetValue("cmi.core.lesson_location");
   	  my_time =API.LMSGetValue("cmi.core.total_time");
   	  if (my_status != "not attempted") {
   	    if (my_status == "completed") {
   	      alert("You have already completed this lesson.")
   	    } else {
   	      alert("Your previous score: " + my_LMS_score+".\nLast page viewed: "+
   	        my_last_loc+".\nTotal time spent on lesson: "+my_time+".")
        }
   	  }
   	  if (my_last_loc) {
   	    if (window.location!=my_last_loc) {window.location=my_last_loc}
   	    alert("You were last on the following page: "+my_last_loc)
   	   }  
   	   API.LMSSetValue("cmi.core.lesson_location", file_name);
   	   API.LMSSetValue("cmi.core.lesson_status", my_status);
   	   startTimer();
}}
function ScormOnunload() {
	if (API != null) {
	  computeTime();
      API.LMSSetValue("cmi.core.lesson_location", file_name);
      API.LMSSetValue("cmi.core.lesson_status", my_status);
	  API.LMSCommit("");
      API.LMSFinish("");
}}
function sendScorm(my_status,total_points,my_score,no,q_type,student_answer,correct) {
    if (API != null) {
      my_id = "cmi.interactions."+(no-1)+".id";
      q_id = "Q"+no;
      my_type = "cmi.interactions."+(no-1)+".type";
      my_answer = eval("right_answers"+no);
      my_response = "cmi.interactions."+(no-1)+".student_response";
      my_result = "cmi.interactions."+(no-1)+".result";
	  API.LMSSetValue("cmi.core.score.min", "0");
	  API.LMSSetValue("cmi.core.score.max", total_points);
	  API.LMSSetValue("cmi.core.score.raw", my_score);
	  API.LMSSetValue("cmi.core.lesson_status", my_status);
      API.LMSSetValue(my_id,q_id);
      API.LMSSetValue(my_type,q_type_names[q_type]);
      API.LMSSetValue(my_response,student_answer);
      if (correct == "yes") {
        API.LMSSetValue(my_result,"correct");
      } else {
        API.LMSSetValue(my_result,"wrong");
      }
      if (my_answer.length > 1) {
         for (var i = 0; i <= (my_answer.length-1); i++) {
          my_pattern = "cmi.interactions."+(no-1)+".correct_responses."+i+".pattern";
          API.LMSSetValue(my_pattern,my_answer[i]);
        }
       } else {
         my_pattern ="cmi.interactions."+(no-1)+".correct_responses.0.pattern";
      }
      API.LMSCommit("");  //make sure that LMS is storing data sent - not sure whether to leave in??
     } 
     else {
       alert(my_status+'Your score could not be submitted through SCORM.  Check to see that your LMS is SCORM-compliant.');
	 }
}
function startTimer() {
   startDate = new Date().getTime();
   SetCookie ("my_date"+rand_no,startDate);
}

function computeTime() {
   startDate =parseInt(GetCookie('my_date'+rand_no));
   if ( startDate != 0 )
   {
      var currentDate = new Date().getTime();
      var elapsedSeconds = ( (currentDate - startDate) / 1000 );
      var formattedTime = convertTotalSeconds( elapsedSeconds );
   }
   else
   {
      formattedTime = "00:00:00.0";
   }
   API.LMSSetValue("cmi.core.session_time",formattedTime);
}