﻿
/************************************************************************************************************************************************************************
** 
** Filename: scormHelper.js
** File Description: This file contains the core functions require for communication between the LMS and SCO via the SCORM API.
** Author: Technical Team (James Jackson)
** Company Name: Saffron Interactive
** References: Saffron JavaScript Container v2.0
**
/************************************************************************************************************************************************************************




			/***************************************************************************************************************************************
			**
			** SCORMHELPER CONSTRUCTOR 
			**
			****************************************************************************************************************************************/

                        var isInternal = false;
                        // var courseId = opener.courseId;
						// var userId = opener.userId;
						var showConfiguration = false;
						
						var sdsHolder = "empty"
						function scormHelper(){
				
								/*************************************************************************************************************
								/** scorm methods 
								*************************************************************************************************************/
									try {
										
										
										this.start = scormHelper_start;
										this.finish = scormHelper_finish;
										this.setLocation = scormHelper_setLocation;
										this.getLocation = scormHelper_getLocation;
										this.setStatus = scormHelper_setStatus;
										this.getStatus = scormHelper_getStatus;
										this.getCredit = scormHelper_getCredit;
										this.getEntry = scormHelper_getEntry;
										this.getMode = scormHelper_getMode;
										this.setExit = scormHelper_setExit;
										this.setSessionTime = scormHelper_setSessionTime;
										this.saveSessionTime = scormHelper_saveSessionTime;
										this.getTotalTime = scormHelper_getTotalTime;
										this.getStudentID = scormHelper_getStudentID;
										this.getStudentName = scormHelper_getStudentName;
										this.setRawScore = scormHelper_setRawScore;
										this.getRawScore = scormHelper_getRawScore;
										this.setMaxScore = scormHelper_setMaxScore;
										this.getMaxScore = scormHelper_getMaxScore;
										this.setMinScore = scormHelper_setMinScore;
										this.getMinScore = scormHelper_getMinScore;
										this.commitSuspendData = scormHelper_commitSuspendData;
										this.retrieveSuspendData = scormHelper_retrieveSuspendData;
										this.setSuspendData = scormHelper_setSuspendData;
										this.getSuspendData = scormHelper_getSuspendData;
										this.setSuspendDataElement = scormHelper_setSuspendDataElement;
										this.getSuspendDataElement = scormHelper_getSuspendDataElement;
										this.addSuspendDataElement = scormHelper_addSuspendDataElement;
										this.removeSuspendDataElement = scormHelper_removeSuspendDataElement;
										this.setupSuspendData = scormHelper_setupSuspendData;
										this.getLaunchData = scormHelper_getLaunchData;
										this.getIsShowConfigOptions = scormHelper_getIsShowConfigOptions;

										
									}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> methods]");}
								
								
								/*************************************************************************************************************
								/** scorm properties 
								*************************************************************************************************************/
									
									try {	
										this.groupDivider = "#";
										this.elementDivider = "|";
										this.suspendDataHolder = "undefined";
										this.coursePassed = "false";
										this.firstRun = "false";
										this.onChangePage = false;
										this.isConnectionClosed = false;
									}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> properties]");}
									
									
								
						}

	
		

			/***************************************************************************************************************************************
			**
			** CORE LESSON FUNCTIONALITY
			**
			****************************************************************************************************************************************/
	
	


					/*************************************************************************************************************
					**
					** Function start()
					** Description: This function handles the communication with the LMS when the SCO is started.
					**
					*************************************************************************************************************/

		
		
							function scormHelper_start(){
							  
								try {
									
									// // // alert("Scorm_helper_start()")
									
									if(isInternal)
									{
										var request = new ActiveXObject("Msxml2.XMLHTTP");
										if (request == null)
										{
											request = new ActiveXObject("Microsoft.XMLHTTP");
										}
										
										if(request != null)
										{
											request.onreadystatechange = processReqChange;
											request.Open("GET", "http://saffroninter.com/TrackingService2/TrackingService.asmx/start?CourseId=" + courseId + "&UserId=" + userId, false);
											request.Send();
											
											function processReqChange() 
											{
												// only if req shows "complete"
												if (request.readyState == 4) 
												{
													// only if "OK"
													if (request.status == 200) 
													{
														
													} else 
													{
														// // // alert("There was a problem retrieving  the XML data:\n" + request.statusText);
													}
												}
											}
											
                                            this.retrieveSuspendData();
											
										    // if(this.suspendDataHolder.length < 50)
											// {
												this.setupSuspendData();
												this.setStatus("incomplete");
												this.setLocation("undefined");
												this.firstRun = "true";
											// }
											
											var startTime = _timer.getCurrentTime();
											this.setSuspendDataElement("session_time", startTime);
											this.commitSuspendData();
											
										} else
                                        {
											// // // alert("Request obj in setStatus is null");
                                        }
										
									} else
									{
										var result = _scorm.doLMSInitialize();
										this.retrieveSuspendData();
                                       
										// // // alert("dl : " + this.suspendDataHolder.length)
										
										//When the default suspend data changes, the length test (200) will need to be changed	
											if(this.suspendDataHolder.length < 50)
											{
												this.setupSuspendData();
												// this.setStatus("incomplete");
												this.setLocation("undefined");
												this.setSuspendDataElement("session_time", startTime);
												
												// showConfiguration = true;
												
												_scorm.doLMSSetValue("cmi.suspend_data", this.suspendDataHolder);
												
												this.commitSuspendData();
										
												this.firstRun = "true";
											}
										
										//// // alert if the data is less than the defined limit	
										//if(this.suspendDataHolder.length < 200){// // alert("LMS Error: Incorrect cmi.suspend_data");}
										
										// // // alert("start : " + setupSuspendData)
										
										var startTime = _timer.getCurrentTime();
										
										this.setSuspendDataElement("session_time", startTime);
										
										this.commitSuspendData();
										
										var isSuccess = _scorm.doLMSCommit();
										
										//commented by madhan if(isSuccess != "true") alert("Error: Unable open connection with LMS")
										
									}	
										
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> start()");}
							}	
					
					
					
		
					/*************************************************************************************************************
					**
					** Function finish()
					** Description: This function handles the communication with the LMS the SCO is exited by the user.
					**
					*************************************************************************************************************/
		
		
		
							function scormHelper_finish(){
								try {	
								if(isInternal)
								{
                                    var finish_request = new ActiveXObject("Msxml2.XMLHTTP");
                                    if (finish_request == null)
                                    {
                                        finish_request = new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                    finish_request.onreadystatechange = processFinishChange;
                                    finish_request.Open("GET", "http://saffroninter.com/TrackingService2/TrackingService.asmx/finish?CourseId=" + courseId + "&UserId=" + userId, true);
                                    finish_request.Send();
                                               function processFinishChange() 
                                                {
                                                    // only if req shows "complete"
                                                    if (finish_request.readyState == 4) {
                                                        if (finish_request.status == 200) {
                                                        // all OK
                                                        } else {
                                                            // // // alert("There was a problem retrieving  the XML data:\n" + finish_request.statusText);
                                                        }
                                                    }
                                                }     
								}
								else
								{
								     //// // alert("in finish EXTERNAL")
									this.saveSessionTime();
								}
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> finish()");}
							}		
					
					
			
			
			
			/***************************************************************************************************************************************
			**
			** LESSON LOCATION
			**
			****************************************************************************************************************************************/
					
				
				
				
					/***********************************************************************************************************************
					**
					** Function: setLocation(location)
					** Description: This function handles the bookmarking of the students position within the Lesson to the LMS.
					**
					************************************************************************************************************************/


	function scormHelper_setLocation(location){
					try {	
							if(isInternal)
							{
        					var setLocation_request = new ActiveXObject("Msxml2.XMLHTTP");;
                                     if (setLocation_request == null)
                                     {
                                       setLocation_request = new ActiveXObject("Microsoft.XMLHTTP");
                                     }
             if(setLocation_request != null)
               {
                                setLocation_request.onreadystatechange = processSetLocationChange;
                                setLocation_request.Open("GET", "http://saffroninter.com/TrackingService2/TrackingService.asmx/setLocation?CourseId=" + courseId + "&UserId=" + userId + "&value=" + location , false);
                                setLocation_request.Send();
                                                function processSetLocationChange() 
                                                {
                                                    // only if req shows "complete"
                                                    if (setLocation_request.readyState == 4)
                                                     {
                                                        if (setLocation_request.status == 200) {
                                                          //// // alert("All OK");  // ...processing statements go here...
                                                        } else {
                                                            // // // alert("There was a problem retrieving  the XML data:\n" + setLocation_request.statusText);
                                                        }
                                                    }
                                                }
            }
        else
        {
        // // // alert("Request obj is null");
        }
								        }
								        else
								        {
										_scorm.doLMSSetValue( "cmi.core.lesson_location", location);
										}
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setLocation()");}
							}	
					
					
					
					/***********************************************************************************************************************
					**
					** Function: setLocation()
					** Return: bookmarked position
					** Description: This function handles the retrivieal of the students bookmarked position within the Lesson from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getLocation(){
								try {	
											return _scorm.doLMSGetValue( "cmi.core.lesson_location");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getLocation()");}
							}
					
				
				
			/***************************************************************************************************************************************
			**
			** LESSON STATUS
			**
			****************************************************************************************************************************************/
					
				
				
					/***********************************************************************************************************************
					**
					** Function setStatus(status)
					** Description: This function handles the bookmarking of  the students position within the Lesson to the LMS.
					**
					************************************************************************************************************************/

							function scormHelper_setStatus(status){
							//// // alert("scormHelper_setStatus: status  = " + status);
								try {	
								    if(isInternal)
								   {
                                    var setStatus_request = new ActiveXObject("Msxml2.XMLHTTP");
                                    if (setStatus_request == null)
                                    {
                                       setStatus_request = new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                               if(setStatus_request != null)
                               {
                                    setStatus_request.onreadystatechange = processSetStatusChange;
                                    setStatus_request.Open("GET", "http://saffroninter.com/TrackingService2/TrackingService.asmx/setStatus?CourseId=" + courseId + "&UserId=" + userId + "&value=" + status, false);
                                    setStatus_request.Send();
                                                function processSetStatusChange() 
                                                {
                                                    if (setStatus_request.readyState == 4) {
                                                        // only if "OK"
                                                        if (setStatus_request.status == 200) {
                                                        } else {
                                                            // // // alert("There was a problem retrieving  the XML data in scormHelper_setStatus(status) :\n" + setStatus_request.statusText);
                                                        }
                                                    }
                                                }
                                }
                                else
                                {
                                // // // alert("Request obj in setStatus is null");
                                }
        
                                
        
        return false;
							        }	
							        else
							        {
										   //// // alert("set Status EXTERNAL");
										    if (useCookieTracking) 
										    {
											    // if the course has been completed, send an email to BT
											    if (status == "completed") 
											    {
												    writeEmail();
											    }
    											
										    }
										    else 
										    {
											    _scorm.doLMSSetValue( "cmi.core.lesson_status", status);
										    }
    										
								    }			
										
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setStatus()");}
							}
					
					
					
					/***********************************************************************************************************************
					**
					** Function: getStatus()
					** Return: Returns the status of the course
					** Description: This function handles the retrivieal of the students bookmarked position within the Lesson from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getStatus(){
								try {
								    if(isInternal)
								    {
								       // // // alert("get Status INTERNAL");
								        request.Open("POST", "http://saffroninter.com/salesacademystation/TrackingService.asmx/getStatus?CourseId=" + courseId + "&UserId=" + userId, true);
                                        request.Send();
                                       // // // alert(request.responseText);
                                        return request.responseText;
							        }	
							        else
							        {
										return _scorm.doLMSGetValue("cmi.core.lesson_status");
									}
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getStatus()");}
							}		
					
					
			/***************************************************************************************************************************************
			**
			** LESSON CREDIT
			**
			****************************************************************************************************************************************/
					
					
					
					
					/***********************************************************************************************************************
					**
					** Function: getCredit()
					** Return: Returns an indication of credition for the lesson
					** Description: This function handles the retrivieal an indication if the student is being credited on there proformance
					** for this lesson.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getCredit(){
								try {
										return _scorm.doLMSGetValue( "cmi.core.credit");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getCredit()");}
							}
							
							
									
					
			/***************************************************************************************************************************************
			**
			** LESSON ENTRY
			**
			****************************************************************************************************************************************/
					
				
				
					
					/***********************************************************************************************************************
					**
					** Function: getEntry()
					** Return: Returns the status of the course
					** Description: This function handles the retrivieal of the student's bookmarked position within the Lesson from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getEntry(){
								try {
										return _scorm.doLMSGetValue( "cmi.core.entry");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getEntry()");}
							}
							
							
			/***************************************************************************************************************************************
			*
			** LESSON MODE
			**
			****************************************************************************************************************************************/
					
				
				
					
					/***********************************************************************************************************************
					**
					** Function: getMode()
					** Return: Returns the mode which the lesson needs to be viewed in.
					** Description: This function handles the retrivieal of the Lesson mode from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getMode(){
								try {
										return _scorm.doLMSGetValue( "cmi.core.lesson_mode");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getMode()");}
							}							



			/***************************************************************************************************************************************
			*
			** LESSON EXIT
			**
			****************************************************************************************************************************************/
					
				
				
					
					/***********************************************************************************************************************
					**
					** Function: setExit(status)
					** Description: This function handles the setting the status of the exit from the lesson
					**
					************************************************************************************************************************/
					
					
							function scormHelper_setExit(status){
								// // // alert("setExit called");
								try {
										_scorm.doLMSSetValue( "cmi.core.exit", status);
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setExit()");}
							}



			/***************************************************************************************************************************************
			**
			** LESSON SESSION TIME
			**
			****************************************************************************************************************************************/
					
				
				
					/***********************************************************************************************************************
					**
					** Function setSessionTime(time)
					** Description: This function handles the saving of the student's session time for the lesson to the LMS.
					**
					************************************************************************************************************************/

							function scormHelper_setSessionTime(time){
							//// // alert("scormHelper_setSessionTime");
								try {
									if(isInternal)
									{
									        var request = new ActiveXObject("Microsoft.XMLHTTP");
									        if (request == null)
                                            {
                                               request = new ActiveXObject("Microsoft.XMLHTTP");
                                            }
									        request.Open("get", "http://saffroninter.com/salesacademystation/TrackingService.asmx/setSessionTime?CourseId=" + courseId + "&UserId=" + userId, true);
                                            request.Send();
                                            //request.setRequestHeader("Content-Type", "text/xml");
                                            //// // alert("scormHelper_setSessionTime : request.statusText = " + request.statusText);
										  // this.setSuspendDataElement("session_time", _timer.getCurrentTime());
									}
									else
									{
									
										_scorm.doLMSSetValue( "cmi.core.session_time", time);
									}
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setSessionTime()");}
							}
					
					
					/***********************************************************************************************************************
					**
					** Function setSessionTime(time)
					** Description: This function handles the saving of the student's session time for the lesson to the LMS.
					**
					************************************************************************************************************************/

							function scormHelper_saveSessionTime(){
							//// // alert("scormHelper_saveSessionTime");
								try {	
										if(this.isConnectionClosed == false)
										{
											// alert("scormHelper_saveSessionTime")
											
											//Gets the Suspend Data from LMS
												_scormHelper.retrieveSuspendData();
											
											//Save the time to the LMS
												var startTime = this.getSuspendDataElement("session_time");
												var sessionTime = _timer.computeTime(startTime);
												this.setSessionTime(sessionTime);
											
											//If no Change Page event has been set then update the current Session Item
												if(!this.onChangePage){
													var currentSession = parseInt(this.getSuspendDataElement("currentSession"));
													if((currentSession+1) < 5){currentSession++;}
													else{currentSession=0;}
													
													this.setSuspendDataElement("currentSession",currentSession);												
												}
												
											//Commit the Data Back to the LMS
												_scormHelper.commitSuspendData();
												
												var isSuccess = _scorm.doLMSCommit();
												
												//commented by madhan if(isSuccess != "true") alert("Error: Unable close connection with LMS:" + isSuccess )
												
											//If no Change Page event has been set then do a LMSFinish	
												if(!this.onChangePage){_scorm.doLMSFinish();}
												
												this.isConnectionClosed = true;
										}
										
										
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setSessionTime()");}
							}
					
					
					/***********************************************************************************************************************
					**
					** Function: getTotalTime()
					** Return: Returns the total time the student has been viewing content in the lesson
					** Description: This function handles the retrivieal of the total time the students been in the Lesson from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getTotalTime(){
							//// // alert("scormHelper_getTotalTime()");
								try {
										return _scorm.doLMSGetValue( "cmi.core.total_time");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getTotalTime()");}
							}				
							
							
							
									
			/***************************************************************************************************************************************
			**
			** STUDENT INFORMATION
			**
			****************************************************************************************************************************************/
					
				
				
					
					/***********************************************************************************************************************
					**
					** Function: getStudentID()
					** Return: Returns the id of the student taking the course
					** Description: This function handles the retrivieal of the student's ID from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getStudentID(){
							//// // alert("scormHelper_getStudentID");
								try {
										return _scorm.doLMSGetValue( "cmi.core.student_id");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getStudentID()");}
							}
							
							
					
					
					/***********************************************************************************************************************
					**
					** Function: getStudentName()
					** Return: Returns the status of the course
					** Description: This function handles the retrivieal of the student's Name from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getStudentName(){
								try {
										return _scorm.doLMSGetValue( "cmi.core.student_name");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getStudentName()");}
							}					
			
			
			
			
			/***************************************************************************************************************************************
			**
			** STUDENT'S RAW SCORE
			**
			****************************************************************************************************************************************/
					
				
				
					
					/***********************************************************************************************************************
					**
					** Function setRawScore(score)
					** Description: This function handles the saving of the student's raw score for the lesson to the LMS.
					**
					************************************************************************************************************************/

							function scormHelper_setRawScore(score){
								try {
									if (! isNaN(score)) {	
										
										if (useCookieTracking) {
											
											createCookie("rawScore",score,100);
										
										} else {
											_scorm.doLMSSetValue( "cmi.core.score.raw", score);
										}
										
										
										}
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setRawScore()");}
							}
					
					
					
					
					/***********************************************************************************************************************
					**
					** Function: getRawScore()
					** Return: Returns the raw score for the Lesson
					** Description: This function handles the retrivieal of the students bookmarked position within the Lesson from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getRawScore(){
								try {
										return _scorm.doLMSGetValue( "cmi.core.score.raw");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getRawScore()");}
							}			
			


			/***************************************************************************************************************************************
			**
			** STUDENT'S MAXIMUM SCORE
			**
			****************************************************************************************************************************************/
					
				


					/***********************************************************************************************************************
					**
					** Function setMaxScore(score)
					** Description: This function handles the saving of the student's maximum score for the lesson to the LMS.
					**
					************************************************************************************************************************/

							function scormHelper_setMaxScore(score){
								try {	
										_scorm.doLMSSetValue( "cmi.core.score.max", score);
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setMaxScore()");}
							}
					
					
					
					
					/***********************************************************************************************************************
					**
					** Function: getMaxScore()
					** Return: Returns the raw score for the Lesson
					** Description: This function handles the retrivieal of the students bookmarked position within the Lesson from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getMaxScore(){
								try {
										return _scorm.doLMSGetValue( "cmi.core.score.max");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getMaxScore()");}
							}
				
				
							
			/***************************************************************************************************************************************
			**
			** STUDENT'S MINIMUM SCORE
			**
			****************************************************************************************************************************************/
					
				
				
					/***********************************************************************************************************************
					**
					** Function setMinScore(score)
					** Description: This function handles the saving of the student's maximum score for the lesson to the LMS.
					**
					************************************************************************************************************************/

							function scormHelper_setMinScore(score){
								try {	
										_scorm.doLMSSetValue( "cmi.core.score.min", score);
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setMinScore()");}
							}
					
					
					
					
					/***********************************************************************************************************************
					**
					** Function: getMinScore()
					** Return: Returns the raw score for the Lesson
					** Description: This function handles the retrivieal of the students bookmarked position within the Lesson from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getMinScore(){
								try {
										return _scorm.doLMSGetValue("cmi.core.score.min");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getMinScore()");}
							}
			
			
			
			
					
			/***************************************************************************************************************************************
			**
			** SUSPEND DATA
			**
			****************************************************************************************************************************************/
					
					
					
					/***********************************************************************************************************************
					**
					** Function setSuspendData(data)
					** Description: This function handles the suspended data for the students session to the LMS.
					**
					************************************************************************************************************************/

							function scormHelper_commitSuspendData(){
								try {
								    
									// _scorm.doLMSSetValue("cmi.suspend_data", this.suspendDataHolder);
									
									if(isInternal)
									{
								    var commit_request = new ActiveXObject("Msxml2.XMLHTTP");
								    if (commit_request == null)
                                    {
                                       commit_request = new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                    try
                                    {
                                        commit_request.Open("GET", "http://saffroninter.com/salesacademystation/TrackingService.asmx/setSuspendData?CourseId=" + courseId + "&UserId=" + userId + "&value=" + this.suspendDataHolder, true);
                                        commit_request.onreadystatechange = processCommitSDSReqChange;
                                        commit_request.Send();
                                    }
                                    catch(err)
                                    {
                                        // // alert(err);
                                    } 

                                         function processCommitSDSReqChange() 
                                        {
                                            if (commit_request.readyState == 4) {
                                                // only if "OK"
                                                if (commit_request.status == 200) {
                                                //All OK
                                                } else {
                                                    // // alert("There was a problem retrieving  the XML data in commitSuspendData:\n" + commit_request.statusText);
                                                }
                                            }
                                        }
										
									}
									
									else
									{	
									if (useCookieTracking) {
											
											// set suspend data in cookie
											//// // alert(" ^ Setting suspend data: "+this.suspendDataHolder);
											createCookie("suspendData",this.suspendDataHolder,100);
											
										} else {
											_scorm.doLMSSetValue("cmi.suspend_data", this.suspendDataHolder);
										}
								    }
									
									
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setSuspendData()");}
							}
					
					
					
					/***********************************************************************************************************************
					**
					** Function: getSuspendData()
					** Return: Returns the status of the course
					** Description: This function handles the retrivieal of the student's suspended data from the LMS.
					**
					************************************************************************************************************************/
					
 
					
							function scormHelper_retrieveSuspendData(){
							//// // alert('in retrieveSuspendData()');
							
								try {
									
								   // var localsds = "";
								    if(isInternal)
									{
									
									 var retrieve_request = new ActiveXObject("Msxml2.XMLHTTP");
                                    try
                                    {
                                            retrieve_request.Open("GET", "http://saffroninter.com/TrackingService2/TrackingService.asmx/getSuspendData?CourseId=" + courseId + "&UserId=" + userId, false);
                                            retrieve_request.onreadystatechange = processRetrieveSDSReqChange;
                                            retrieve_request.Send();
                                    }
                                    catch(err)
                                    {
                                    // // // alert(err);
                                    } 

                                         function processRetrieveSDSReqChange() 
                                        {
                                            // only if req shows "complete"
                                            if (retrieve_request.readyState == 4) {
                                                // only if "OK"
                                                if (retrieve_request.status == 200) {
                                                     var xmlDoc=retrieve_request.responseXML; 
                                                    var responseElement=xmlDoc.getElementsByTagName("string")[0]; 
                                                    var respText=responseElement.firstChild.nodeValue;
                                                        _scormHelper.suspendDataHolder = respText;
                                                } else {
                                                    // // // alert("There was a problem retrieving  the XML data:\n" + retrieve_request.statusText);
                                                }
                                            }
                                        }

									}
									else
									{
										        if (useCookieTracking) 
										        {
        											
											        // get suspend data from cookie
											        //// // alert(" v Getting suspend data: " + readCookie("suspendData"));
											        this.suspendDataHolder = readCookie("suspendData");
										        } else 
										        {
											        this.suspendDataHolder = _scorm.doLMSGetValue("cmi.suspend_data");
													
													// // // alert("retrieveSuspendData() : " + this.suspendDataHolder)
										        }
								    }
								}
								
								
								
								catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getSuspendData()");}
							
							}
							

					
					/***********************************************************************************************************************
					**
					** Function setSuspendData(data)
					** Description: This function handles the suspended data for the students session to the LMS.
					**
					************************************************************************************************************************/

							function scormHelper_setSuspendData(data){
								try {
								 if(isInternal)
									{
									    this.suspendDataHolder = data;
									}
									else
									{	
										this.suspendDataHolder = data;
									}
									
									// // // alert("scormHelper_setSuspendData : " + this.suspendDataHolder)
									
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setSuspendData()");}
							}
					
					
					
					
					/***********************************************************************************************************************
					**
					** Function: getSuspendData()
					** Return: Returns the status of the course
					** Description: This function handles the retrivieal of the student's suspended data from the LMS.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getSuspendData(){
							
								try {
								 if(isInternal)
									{
									    return this.suspendDataHolder;
									}
									else
									{
										// // // alert('getSuspendData(): suspendDataHolder = ' + this.suspendDataHolder);
										return this.suspendDataHolder;
									}
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getSuspendData()");}
							}							
			
					
					
					/***********************************************************************************************************************
					**
					** Function: getSuspendDataElement(name, value)
					** Description: This function handles the saving of a name value pair to the suspend data field
					**
					************************************************************************************************************************/
					
							function scormHelper_setSuspendDataElement(name, value){
								try {
									
									var elementvalue = [];
									var elementName = [];
									var data = [];
										
									var suspend_data = this.getSuspendData();
									var elementsGroups = suspend_data.split(this.groupDivider);
									
									for(var group in elementsGroups){
										
										elementvalue = [];
										elementName = [];
										data = [];
										
										var elements = elementsGroups[group].split(this.elementDivider);
									
										for(var count in elements){
											elementName[count] =  elements[count].split("=")[0];
											elementvalue[count] =  elements[count].split("=")[1];
											if(elementName[count] == name){data[count] = elementName[count] + "=" + value;
											}else{data[count] = elementName[count] + "=" + elementvalue[count];}
										}
										elementsGroups[group] = data.join(this.elementDivider);
									}
									
									suspend_data =elementsGroups.join(this.groupDivider);
									this.setSuspendData(suspend_data);		
										
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setSuspendDataElement()");}
							}
					
					
					
							
					/***********************************************************************************************************************
					**
					** Function: getSuspendDataElement(name)
					** Return: the value of the name pair requested
					** Description: This function handles the retrivieal of a name value pair from the suspend_data field
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getSuspendDataElement(name){

								try {
									var elements = []; 
									var suspend_data = this.getSuspendData();
									var elementsGroups = suspend_data.split(this.groupDivider);
									
									for(var group in elementsGroups){
										elements = elementsGroups[group].split(this.elementDivider);
										for(var count in elements){
											if (elements[count].split("=")[0].toLowerCase() == name.toLowerCase()){
												
												// alert("getSuspendDataElement : " + elements[count].split("=")[1])
												
												return elements[count].split("=")[1];}
											}
									}	
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getSuspendDataElement()");}
							}
			
		
		
		
					/***********************************************************************************************************************
					**
					** Function: addSuspendDataElement(name, value)
					** Description: This function handles the adding of the new name value pair to the suspend data field
					**
					************************************************************************************************************************/
					
					
							function scormHelper_addSuspendDataElement(group, name, value){
							//// // alert('scormHelper_addSuspendDataElement(group = '+ group + ', name=' + name + ', value=' + value + ')');
								try {
								
									this.removeSuspendDataElement(name);
									
									var elementsGroups=[]; 
									var suspend_data = this.getSuspendData();
									var elementsGroups = suspend_data.split(this.groupDivider);
									var elements = elementsGroups[group].split(this.elementDivider);
									
									if(elementsGroups[group] == ""){elements[0] = name + "=" + value;
									}else{elements.push(name + "=" + value);}
									
									elementsGroups[group] = elements.join(this.elementDivider);
									suspend_data = elementsGroups.join(this.groupDivider);
									this.setSuspendData(suspend_data);			
								
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> addSuspendDataElement()");}
							}
							
							
							
					/***********************************************************************************************************************
					**
					** Function: removeSuspendDataElement(name)
					** Description: This function handles the removing of a exsiting name value pair to the suspend data field
					**
					************************************************************************************************************************/
					
					
							function scormHelper_removeSuspendDataElement(name){
								//// // alert('scormHelper_removeSuspendDataElement(name=' + name + ')');
								try {
									
									var data = [];
									var elements = [];
									
									var suspend_data = this.getSuspendData();
									var elementsGroups = suspend_data.split(this.groupDivider);
									
									for(var group in elementsGroups){
										data = [];
										elements = elementsGroups[group].split(this.elementDivider);
									
										for(var count in elements){
											if(elements[count].split("=")[0].toLowerCase() != name.toLowerCase() && elementsGroups[group] !=""){
												data[count] = elements[count].split("=")[0] + "=" + elements[count].split("=")[1];
											}
										}
										elementsGroups[group] = data.join(this.elementDivider);
									}
									
									suspend_data = elementsGroups.join(this.groupDivider);
									this.setSuspendData(suspend_data);
										
										
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> removeSuspendDataElement()");}
							}			
					
		
		
					/***********************************************************************************************************************
					**
					** Function: setupSuspendData()
					** Description: Setups the values in the suspend data
					**
					************************************************************************************************************************/
					
					
							function scormHelper_setupSuspendData()
							{	
								try {
										var launchData = this.getLaunchData();
										
										// // // alert("in scormHelper_setupSuspendData() : " + launchData)
										
										launchData = xreplace(launchData , "|" , "#");
										launchData = xreplace(launchData , "," , "|");
										this.setSuspendData(launchData);
										
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> setupSuspendData()");}
							}	
							
							
			/***************************************************************************************************************************************
			**
			** LAUNCH DATA
			**
			****************************************************************************************************************************************/
					
				
					/***********************************************************************************************************************
					**
					** Function: getLaunchData()
					** Return: Returns the status of the course
					** Description: This function handles the retrivieal of the launch data for the SCO.
					**
					************************************************************************************************************************/
					
					
							function scormHelper_getLaunchData(){
								try {
										return launch_data;
										//return _scorm.doLMSGetValue("cmi.launch_data");
								}catch(e){errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getLaunchData()");}
							}							
				
			/***************************************************************************************************************************************
			**
			** BNP Paribas hook to check whether the learner has already chosen a cofiguration for the course
			**
			****************************************************************************************************************************************/
			
					/***********************************************************************************************************************
					**
					** Function: getLaunchData()
					** Return: Returns the status of the course
					** Description: This function handles the retrivieal of the launch data for the SCO.
					**
					************************************************************************************************************************/
					
					
						function scormHelper_getIsShowConfigOptions() 
						{
							try 
							{
								// alert("showConfiguration : " + showConfiguration)
								
								var tmpLessonStatus = scormHelper_getStatus();
								
								// alert("scormHelper_getIsShowConfigOptions : " + tmpLessonStatus)
								
								// return false;
								
								// if(showConfiguration && tmpLessonStatus.toLowerCase() != "completed")
								
								if(tmpLessonStatus.toLowerCase() == "not attempted" || tmpLessonStatus.toLowerCase() == "completed" || tmpLessonStatus.toLowerCase() == "passed")
								{
									return true;
									
								} else 
								{
									return false;
								}
								
								
							} catch(e)
							{
								errorReporter(e, errorLocation, "<b>file:</b> scormHelper.js - <b>function:</b> getLaunchData()");
							}
							
						}
						
			
