﻿    var apiPointer12;
	var apiPointer13;

	// SCORM 1.2 functions
	function FindApi12() {
		apiPointer12 = RetrieveSCORMAPI_12();

		return (apiPointer12 != null);
	}

	function InitSCORM12() {
		if (apiPointer12 != null) {
			return apiPointer12.LMSInitialize("");
		}
		else {
		    alert("apiPointer has not been initialized.");
		    return false;
		}
	}

	function Close12() {
			if (apiPointer12 != null) {
				return apiPointer12.LMSFinish("");
			}
			else {
				alert("apiPointer has not been initialized.");
			}
	}

	function GetValue12(paramId) {
		if (apiPointer12 != null) {
			return apiPointer12.LMSGetValue(paramId);
		}
		else {
			alert("apiPointer has not been initialized.");
		}
	}

	function SetValue12(paramId, paramValue) {
		if (apiPointer12 != null) {
			return apiPointer12.LMSSetValue(paramId, paramValue);
		}
		else {
			alert("apiPointer has not been initialized.");
		}
	}

	function GetLastError12() {
			if (apiPointer12 != null) {
				return apiPointer12.LMSGetLastError("");
			}
			else {
				alert("apiPointer has not been initialized.");
			}
	}

	function GetLastErrorString12(paramId) {
			if (apiPointer12 != null) {
				return apiPointer12.LMSGetErrorString(paramId);
			}
			else {
				alert("apiPointer has not been initialized.");
			}
	}

	// 1.2 helper function
	function LocateSCORMAPI_12(windowID) {
		if (windowID.API != null) {
			return windowID.API;
		}
		else if (windowID.parent == null || windowID.parent == windowID) {
			return null;
		}
		else {
			return LocateSCORMAPI_12(windowID.parent);
		}
	}

	function RetrieveSCORMAPI_12() {
		var pointerId = null;

		//debugger;
		pointerId = LocateSCORMAPI_12(window);
		if (pointerId == null && window.opener != null) {
			pointerId = LocateSCORMAPI_12(window.opener);
		}
		else if (pointerId == null && window.parent.opener != null) {
			pointerId = LocateSCORMAPI_12(window.parent.opener);
		}
		if (pointerId == null) {
		    alert("Could not find SCORM 1.2 API Object.");
		}

		return (pointerId);
	}

	// SCORM 1.3 functions
		function FindApi13() {
			apiPointer13 = RetrieveSCORMAPI_13();

			return (apiPointer13 != null);
		}

		function InitSCORM13() {
			if (apiPointer13 != null) {
				return apiPointer13.Initialize("");
			}
			else {
			    alert("apiPointer has not been initialized.");
			    return false;
			}
		}

		function Close13() {
				if (apiPointer13 != null) {
					return apiPointer13.Terminate("");
				}
				else {
					alert("apiPointer has not been initialized.");
				}
		}

		function GetValue13(paramId) {
			if (apiPointer13 != null) {
				return apiPointer13.GetValue(paramId);
			}
			else {
				alert("apiPointer has not been initialized.");
			}
		}

		function SetValue13(paramId, paramValue) {
			if (apiPointer13 != null) {
				return apiPointer13.SetValue(paramId, paramValue);
			}
			else {
				alert("apiPointer has not been initialized.");
			}
		}

		function GetLastError13() {
				if (apiPointer13 != null) {
					return apiPointer13.GetLastError("");
				}
				else {
					alert("apiPointer has not been initialized.");
				}
		}

		function GetLastErrorString13(paramId) {
				if (apiPointer13 != null) {
					return apiPointer13.GetErrorString(paramId);
				}
				else {
					alert("apiPointer has not been initialized.");
				}
		}

		// 1.3 helper function
		function LocateSCORMAPI_13(windowID) {
			if (windowID.API_1484_11 != null) {
				return windowID.API_1484_11;
			}
			else if (windowID.parent == null || windowID.parent == windowID) {
				return null;
			}
			else {
				return LocateSCORMAPI_13(windowID.parent);
			}
		}

		function RetrieveSCORMAPI_13() {
			var pointerId = null;

			pointerId = LocateSCORMAPI_13(window);
			if (pointerId == null && window.opener != null) {
				pointerId = LocateSCORMAPI_13(window.opener);
			}
			else if (pointerId == null && window.parent.opener != null) {
				pointerId = LocateSCORMAPI_13(window.parent.opener);
			}
			if (pointerId == null) {
				alert("Could not find SCORM 1.3/2004 API Object.");
			}

			return( pointerId );
		}
