/*
 * Copyright (c) 2005 Absolutely Training Limited
 *  
 * Contains code and functions that initialize sco api. Also contains miscellaneous functions make 
 * the root frameset accessable and control the api instance.
 *
 * @author fritzd
 */

/**
 * Flag that indicates whether user users one-page-per-topic mode
 */
var ONE_PAGE_PER_TOPIC = false;

var HIDDE_CONTINUE = "hideContinue";
var HIDDE_PREVIOUS = "hidePrevious";
var SHOW_ALL = "showAll";
var host;

var scoPresentation;
/**
 * Initialize api instance
 */
var API_1484_11 = new api_imp(this, "content", misc_findHost());
var API = API_1484_11;

var contentHtml;
/**
 * Frame accessors
 */
function control_getContentFrame() {	
	return parent.frames['content'];
}

function control_launchSco(navigationRequest, courseId, bookingId) {
	API_1484_11.launchSco(navigationRequest, courseId, bookingId);
}
/**
 * To launch sco from menu
 */
function control_launchScoFromMenu(navigationRequest, courseId, presentationMode) {
	scoPresentation = presentationMode;
	
	if (API_1484_11.state == "Running") {
		API_1484_11.SetValueDirect("adl.nav.request", navigationRequest);
		API_1484_11.courseId = courseId;
//		API_1484_11.Terminate("");
		control_getContentFrame().location.href = misc_findHost() + "loadNewPage.html";
	}
	else {
		API_1484_11.launchSco(navigationRequest, courseId);
	}
}

/**
 * To launch sco from menu
 */
function control_launchScoFromMenuForCOIds(navigationRequest, contentObjectCourseId) {
		API_1484_11.Terminate("");
		API_1484_11.SetValueDirect("adl.nav.request", navigationRequest);
		API_1484_11.launchScoForCOCourseId(navigationRequest, contentObjectCourseId);
	
	
}

/**
 * To launch sco from menu
 */
function control_launchScoFromMenuForContentObjectLink(navigationRequest, contentObjectCourseId) {

		API_1484_11.launchScoForContentObjectLink(navigationRequest, contentObjectCourseId);
	
	
}


/**
 * To launch sco from footer navigation
 */
function control_launchScoFromNavigation(navigationRequest) {
	if (API_1484_11.state == "Running") {
		API_1484_11.SetValueDirect("adl.nav.request", navigationRequest);
//		API_1484_11.Terminate("");
		control_getContentFrame().location.href = misc_findHost() + "loadNewPage.html";
	}
	else {
		API_1484_11.launchSco(navigationRequest);
	}
}
/**
 * Launches test sco for course. Used by training plan.
 * Notifies api_instance about which sco was launched.
 */
function control_launchCourseTestSco(testableId, courseId, bookingId) {
	control_launchSco("{target=Sco" + testableId + "CourseTest}choice", courseId, bookingId);
}

/**
 * Gets api instance to launch new sco in new window
 */
function control_launchScoInNewWindow(scoIdentifier, href, courseId) {
	API_1484_11.launchScoInNewWindow(scoIdentifier, href, courseId);
}


/**
 * Call content frame and passes the pages that need to get loaded. Used to generate the frameset using document.write. This lead
 * to problems in internet explorer.
 */
function control_generateFrame(targetFrame, contentUrl, navUrl, presentationMode) {
	scoPresentation = presentationMode;
	targetFrame.location.href =misc_findHost()+ "html/"+control_getContentPage()+"?contentUrl=" + contentUrl + "&navUrl=" + navUrl;
}

/**
 * Call content frame and passes the pages that need to get loaded. Used to generate the frameset using document.write. This lead
 * to problems in internet explorer.
 */
function control_generateFrameWithHost(targetFrame, contentUrl, navUrl, presentationMode) {	
	scoPresentation = presentationMode;
	targetFrame.location.href = "loadNewPage.html";
}

/**
 * Return either a page that has displays buttons or one that does not. 
 *
 */
function control_getContentPage(){
	
	if (scoPresentation==SHOW_ALL || scoPresentation==HIDDE_CONTINUE||scoPresentation==HIDDE_PREVIOUS){
		contentHtml ="content.html";
	} else {
		contentHtml ="content_no_navigation.html";
	}
	return contentHtml;
}

/**
 *	Select the view to be use for de buttons. If only one button is to be selected, it selects the appropriate view.  
 */
function control_getViewPage(presentationMode){

	var viewName;

	if (presentationMode==HIDDE_CONTINUE){
		viewName = "menuFooterContinue";
	} else 	if (presentationMode==HIDDE_PREVIOUS){
		viewName = "menuFooterPrevious";
	} else {
		viewName = "menuFooter";
	}
	return viewName;
}


