// use this script to include all courseware specific javascript functions

var courseID = "a";

var courseWidth = 1014;
var courseHeight = 675;

var openX = screen.width/2 - courseWidth/2;
var openY = screen.height/2 - courseHeight/2;

function testJS( msg )
{
	alert(msg);	
}

function getFlashVariable( vName )
{
	var x = document.flashMovie.GetVariable( vName );
	alert(x);
}

// ***************************************************
// ************ window functions *********************
// ***************************************************

/**
   function to calculate the x position of a new window so that it appears centered on screen
   @param nWidth integer specifying the width of the new window being opened
   @return integer specifying the x position for the ne window
*/
function getNewWinX( nWidth )
{
	var iLeft = screen.width/2 - nWidth/2
	return iLeft;	
}

/**
   function to calculate the y position of a new window so that it appears centered on screen
   @param nHeight integer specifying the height of the new window being opened
   @return integer specifying the y position for the ne window
*/
function getNewWinY( nHeight )
{
	var iTop = screen.height/2 - nHeight/2;
	return iTop;	
}

// ***************************************************
// ************ cookie functions *********************
// ***************************************************

/**
   function to create a cookie
   @param name the name of the cookie to be created
   @param value the value of the cookie
   @param days (optional) the number of days for which the cookie should exist
   @return nothing
*/
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	document.cookie = name+"="+ escape(value)+expires+"; path=/";
}

/**
   function to read the value of a given cookie
   @param name the name of the cookie to be read
   @return the value of the given cookie or empty string "" if the cookie can't be found
*/
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
	
}

/**
   function to erase a given cookie
   @param name the name of the cookie to be read
   @return nothing
*/
function eraseCookie(name)
{
	createCookie(name,"",-1);
}


// ***************************************************

/**
   function to open a captivate file
   @param name the name of the captivate file
   @return nothing
*/
function openWindow(file_path,width,height)
{
	
	var theURL = file_path;
	
	var winParams = "toolbars=no,location=no,status=yes,resizeable=yes";
	winParams += ",width=" + width + ",height=" + height;
	winParams += ",left=" + openX + ",top=" + openY;
	
	islWin = window.open( theURL , "extra" , winParams);
}


// ***************************************************

function checkScreenSize()
{
	if (screen.width < 1024 || screen.height < 768) {
		alert("This course runs in a 1024x768 frame.\r\nYou need to change your screen resolution to a minimum of 1024x768 to view it fully.\r\nPlease change your settings before continuing with the course");
	}	
}

function triggerTimeoutMessage() { 
	parent.content.location.replace("timeout.htm");
}

/*
	Write out the HTML for a flash movie, can use this we don't want to do any flash detection via swfobject
	parameters = filename, width, height and id of the swf
*/
function createFlashObject(fileref, thewidth, theheight, swfid)
{
	document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ");
	document.write("codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0'");
	document.write(" WIDTH='" + thewidth + "' HEIGHT='" + theheight + "' id='" + swfid + "' ALIGN=''>");
	document.write("<PARAM NAME=movie VALUE='" + fileref + "'>"); 
	document.write("<PARAM NAME=quality VALUE=high> <PARAM NAME=loop VALUE=false>");
	document.write("<PARAM NAME=menu VALUE=false> <PARAM NAME=bgcolor VALUE=#FFFFFF>");
	document.write("");
	document.write("<EMBED src='" + fileref + "'");
	document.write("quality=high bgcolor=#FFFFFF  WIDTH='" + thewidth + "' HEIGHT='" + theheight + "' NAME='" + swfid + "' ");
	document.write("loop=false menu=false ALIGN='' ");
	document.write("TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'")
	document.write(" swLiveConnect=true></EMBED>");
	document.write("</OBJECT>");
}
