var _Debug=false;var _NoError=0;var _GeneralException=101;var _InvalidArgumentError=201;var _NotInitialized=301;var _NotImplementedError=401;var apiHandle=null;function LMSInitialize()
{var api=getAPIHandle();if(api==null)
{alert("Unable to locate the LMS's API Implementation.\nLMSInitialize was not successful.");return false;}
var emptyString=new String("");var initResult=api.LMSInitialize("");if(initResult.toString()!="1")
{var err=ErrorHandler();}
return initResult;}
function LMSFinish()
{var api=getAPIHandle();if(api==null)
{}
else
{var emptyString=new String("");api.LMSFinish(emptyString);var err=ErrorHandler();}
return;}
function LMSGetValue(name)
{var api=getAPIHandle();if(api==null)
{alert("Unable to locate the LMS's API Implementation.\nLMSGetValue was not successful.");return null;}
else
{var value=api.LMSGetValue(name);var err=ErrorHandler();if(err!=_NoError)
{return null;}
else
{if(typeof value=='undefined'){return '';}else{return value.toString();}}}}
function LMSSetValue(name,value)
{var api=getAPIHandle();if(api==null)
{alert("Unable to locate the LMS's API Implementation.\nLMSSetValue was not successful.");}
else
{api.LMSSetValue(name,value);var err=ErrorHandler();}
return;}
function LMSCommit()
{var api=getAPIHandle();if(api==null)
{alert("Unable to locate the LMS's API Implementation.\nLMSCommit was not successful.");}
else
{api.LMSCommit("");var err=ErrorHandler();}
return;}
function LMSGetLastError()
{var api=getAPIHandle();if(api==null)
{alert("Unable to locate the LMS's API Implementation.\nLMSGetLastError was not successful.");return _GeneralError;}
return api.LMSGetLastError().toString();}
function LMSGetErrorString(errorCode)
{var api=getAPIHandle();if(api==null)
{alert("Unable to locate the LMS's API Implementation.\nLMSGetErrorString was not successful.");}
return api.LMSGetErrorString(errorCode).toString();}
function LMSGetDiagnostic(errorCode)
{var api=getAPIHandle();if(api==null)
{alert("Unable to locate the LMS's API Implementation.\nLMSGetDiagnostic was not successful.");}
return api.LMSGetDiagnostic(errorCode).toString();}
function LMSIsInitialized()
{var api=getAPIHandle();if(api==null)
{alert("Unable to locate the LMS's API Implementation.\nLMSIsInitialized() failed.");return false;}
else
{var value=api.LMSGetValue("cmi.core.student_name");var errCode=api.LMSGetLastError().toString();if(errCode==_NotInitialized)
{return false;}
else
{return true;}}}
function ErrorHandler()
{var api=getAPIHandle();if(api==null)
{alert("Unable to locate the LMS's API Implementation.\nCannot determine LMS error code.");return;}
var errCode=api.LMSGetLastError().toString();if(errCode!=_NoError)
{var errDescription=api.LMSGetErrorString(errCode);if(_Debug==true)
{errDescription+="\n";errDescription+=api.LMSGetDiagnostic(null);}}
return errCode;}
function getAPIHandle()
{if(apiHandle==null)
{apiHandle=getAPI();}
return apiHandle;}
function findAPI(win)
{if(_Debug)
{alert("win is: "+win.location.href);}
if(win.API!=null)
{if(_Debug)
{alert("found api in this window");}
return win.API;}
if(win.length>0)
{if(_Debug)
{alert("looking for api in windows frames");}
for(var i=0;i<win.length;i++)
{if(_Debug)
{alert("looking for api in frames["+i+"]");}
var theAPI=findAPI(win.frames[i]);if(theAPI!=null)
{return theAPI;}}}
if(_Debug)
{alert("didn't find api in this window (or its children)");}
return null;}
function getAPI()
{var theAPI=findAPI(this.top);if(theAPI==null)
{if(_Debug)
{alert("checking to see if this window has an opener");alert("window.opener typeof is> "+typeof(window.opener));}
if(typeof(this.opener)!="undefined")
{if(_Debug)
{alert("checking this windows opener");}
if(this.opener!=null)
{if(_Debug)
{alert("this windows opener is NOT null - looking there");}
theAPI=findAPI(this.opener.top);}
else
{if(_Debug)
{alert("this windows opener is null");}}}}
return theAPI;}
