// Copyright SmartForce Ltd 2000

function findAppletFrame(win)
{
	if (win.frames['sfAppletFrame'])
		return win.frames['sfAppletFrame'];
	else if (win.parent == null || win.parent == win)
		return null;
	else
		return findAppletFrame(win.parent);
}

var app = findAppletFrame(window);
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var nBrowserVersion = parseFloat(navigator.appVersion);
var MAX_LP = 20;

function startLOSession()
{
	if(app)
		app.sfUI.sfStartSession();
}

function getLOProgress()
{
	if(app)
		app.sfUI.sfGetProgress();
}

function stopLOSession()
{
	if(app)
		app.sfUI.sfStopSession();
}

function getNumLearningPoints()
{
	var nNoLP;
	if(app){
		nNoLP = app.sfUI.sfGetNumberOfTopics();	 
		if ((nNoLP -1) > MAX_LP)
			return MAX_LP;
		else
			return nNoLP;	
	}else{
		return -9;	// Just made this number up
	}	
}

function getNumLearningPoints()
{
	var nNoLP;
	if(app){
		nNoLP = app.sfUI.sfGetNumberOfTopics();	// Includes maps 
		if ((nNoLP -1) > MAX_LP)
			return MAX_LP;
		else
			return nNoLP;	
	}else{
		return -9;	// Just made this number up
	}	
}

function getLearningPointName(nLPNo)
{	
	if ((nLPNo < 0) || (nLPNo > MAX_LP))
		return "Learning Point out of range";
		
	if(app){
		return app.sfUI.sfgetTopicsName(nLPNo);
		//return "Learning Point "+ nLPNo;
	}else
		return "Unknown Learning Point";
}

function getLearningObjectName()
{
	if(app)
		return app.sfUI.sfGetLOName();  
	else
		return "Unknown Learning Object Name";	
}

function getLearningObjectObjective()
{
	if(app){		
		sHTML =  "After completing this learning objective,\
			you should be able to understand ";
				
		var nNoOfLPs = getNumLearningPoints();	
	
		for (var i=1; i<nNoOfLPs+1; i++){		  					
			if (i != nNoOfLPs)
				sHTML += getLearningPointName(i) + ", ";
			else	
				sHTML += " and " +getLearningPointName(i);
		}
		return sHTML;
	}else
		return "Unknown Learning Object Objective";		
}

function getRHSCustLogo()
{
	if (app){	
		return app.sfUI.sfGetLR("rhscustlogo")
	}	
	return null;
}	

function getLearningObjectObjectiveSrc()
{	
	if (app){	
		return app.sfUI.sfGetLR("objective")
	}	
	return null;
}

function getLHSCustLogo()
{
	if (app){	
		return app.sfUI.sfGetLR("lhscustlogo")
	}	
	return null;
}

function getMentoringSrc()
{
	if (app){	
		return app.sfUI.sfGetLR("mentoring")
	}	
	return null;
}

function getResourcesSrc()
{
	if (app){	
		return app.sfUI.sfGetLR("resources")
	}	
	return null;
}

function onLine()
{
	return top.connectedToWWW;
}


function displayEButtonBut()
{
	sResourcesSrc = getResourcesSrc();
	if (!onLine())
		return false;
	else if ((sResourcesSrc == null) ||(sResourcesSrc =="")){
		return false;
	}	
	return true;
}

function displayMentoringBut()
{
	sMentoringSrc = getMentoringSrc();
	if (!onLine())
		return false;
	else if (( sMentoringSrc == null) || (sMentoringSrc == "")){
		return false;
	}			
	return true;
}

function sendProgress()
{
	if (app)
	{	
		app.sfUI.sfSendProgress();
	}	
}

function exitcourse()
{
	if (app)
	{
		app.sfUI.sfStopCaching();
		app.sfUI.sfStopSession();
	}	
}


function DoNothing()
{	
}

	
function nextLOAvailable()
{
	if (app)
	{
		return app.sfUI.sfIsNextLearningObjectAvailable();
	}
	return false;
}

function prevLOAvailable()
{
	if (app)
	{
		return app.sfUI.sfIsPrevLearningObjectAvailable();
	}
	return false;
}

function moveToNextLO()
{
	if (app)
	{
		app.sfUI.sfMoveToNextLearningObject();
	}	
}


function moveToPrevLO()
{
	if (app)
	{
		app.sfUI.sfMoveToPrevLearningObject();
	}	
}


// BrowserInfo added by DH 31/8/00
// Allows detection of browser version and OS
function BrowserInfo()
{
	this.SetBrowserInfo=BrowserInfo_SetBrowserClientInformation;
	this.GetBrowserInfo=BrowserInfo_GetBrowserClientInformation;
	this.GetOSInfo=BrowserInfo_GetBrowserOperatingSystemInformation;

	this.SetBrowserInfo();
}

// Called when BrowserInfo object is created
// Do not call this yourself.
function BrowserInfo_SetBrowserClientInformation()
{
	this.oBrowser = new Object();
	this.oBrowser.appVersion = navigator.appVersion;

	<!--Use "[" for NS and "(" for IE to extract full version number -->
	var aVersionArray = this.oBrowser.appVersion.split(" ");

	this.oBrowser.Version = aVersionArray[0];
	this.oBrowser.Version-=0;
	this.oBrowser.tigVersion = aVersionArray[3];

	if(navigator.appName.indexOf("Netscape") != -1){
		this.oBrowser.Platform = "ns";
		if(aVersionArray[1].slice(1,aVersionArray[1].length-1)=='Macintosh')
			this.oBrowser.OS = aVersionArray[1].slice(1,aVersionArray[1].length-1);
		else
			this.oBrowser.OS = aVersionArray[2].slice(1,aVersionArray[2].length-1);
	}else if(navigator.appName.indexOf("Microsoft") != -1){
		this.oBrowser.Platform = "ie";
		this.oBrowser.OS = aVersionArray[4];
		if(this.oBrowser.OS=='SunOS')
			this.oBrowser.OS = aVersionArray[7];
	}else{
		this.oBrowser.Platform = "unknown";
		this.oBrowser.OS='X11';
	}
}

// Returns one of the following
// "ie" = Internet Explorer
// "ns" = Netscape
// "unknown" = Doh!
function BrowserInfo_GetBrowserClientInformation()
{
	return this.oBrowser.Platform;
}

// Returns one of the following
// "Windows" = guess what
// "Macintosh" = Apple Mac
// "SunOS" = Solaris
// "X11" = a non Sun Unix system such as Linux
function BrowserInfo_GetBrowserOperatingSystemInformation()
{
	return this.oBrowser.OS;
}

