// Product : sofTV - Presenter  Version : 5:0:0:5006  Date : 26 August 2009
// Build No: 5.0.0.5006
var DEBUG = 0; 

var g_Navigator;
var g_bInitialised = false;
var g_bTimeOut = false;


function getAPIAdapter( win ) 
{
	while(win != null)
	{
		var api = findAPI( win );

		if(api != null)
			return api;
		
		if( "IE" == g_Navigator )
			win = win.opener; 
		else
			return null;
	}

	return null;
}

function findAPI(win) 
{
	if (win.document.API != null)
		return win.document.API;
	
	if (win.API != null)
		return win.API;
	
	if( win.parent != null && win.parent != win ) //start search from inner window modification.
		return findAPI( win.parent );
	else if( win.parent == win ) //Modified here for RM30LMS on [ 6/18/2004 3:26:52 PM ] //Purpose: SCORM XML EXAM in Pathlore LMS issue.
	{
		return null;
	}
	else if( win.length > 0 ) // does the window have frames?
	{
		for( var i=0; i< win.length; i++ )
		{
			var objAPI = findAPI(win.frames[i]);
			if (objAPI != null)
				return objAPI;
		}
	}
	
	return null;
}

function OnLoadSCO( )
{
	g_bInitialised = true;

	
	if( navigator.appName == "Microsoft Internet Explorer" )
		g_Navigator = "IE";
	else if( navigator.appName == "Netscape" )
		g_Navigator = "NN";

	var api = getAPIAdapter(this);

	if( api != null )
	{
		if( api.LMSInitialize("") != "true" )
		{
			var errCode = api.LMSGetLastError();
			alert( "Error : " + api.LMSGetErrorString(errCode) );
			return false;
		}
	}
	else
	{
		//alert("Unable to locate the LMS's API Implementation.\nLMSInitialize was not successful.");
		return false;
	}

	return true; //initializeData( api);
}

function OnUnloadSCO()
{
	if(g_bInitialised == false)
		return false;

	var api = getAPIAdapter(this);

	if(api != null)
	{
		//updateData( api );
		api.LMSSetValue( "cmi.core.score.raw", "100");
		api.LMSSetValue( "cmi.core.lesson_status", "completed");
		api.LMSCommit("");
		api.LMSFinish("");
	}
	
	g_bInitialised = false;

	return true;
}


function CheckChildren(strchildren,strdatModel)
{
	if (strchildren != null)
	{
		if (strchildren.indexOf(strdatModel) != -1)
		   return true;
	}
	return false;
}
