/******************************************************************

Copyright © Global Knowledge Software LLC 2006.  All Rights Reserved.

This program is protected by U.S. and International Copyright and
Patent Laws.  Unauthorized duplication and/or distribution of this
program is strictly prohibited. Distribution and duplication of this
program are limited by license. If you do not currently have a valid
license from Global Knowledge for this program, any copying or
distribution of the program is unauthorized.  If you do have a current
license from Global Knowledge to utilize this program, your use is
strictly limited by the terms of that license.

Patent Pending.

******************************************************************/

var main=parent;
var new_fullscreen_mode = false;
var doitref = null;
var helpmenu = null;

//defines
var SM_CYCAPTION=19;
var	SM_CXFRAME=4;
var SM_CYFRAME=4;
var SM_CYHSCROLL=16;
var SM_CXVSCROLL=16;

function _detect_fullscreen_mode()
{
	var s = oClientCaps.getComponentVersion("{89820200-ECBD-11CF-8B85-00AA005B4383}","ComponentID");
	var v = s.split(",");
	if (Number(v[0])>6 || (Number(v[0])==6 && Number(v[2])>=3790))
		new_fullscreen_mode = true;
}

_detect_fullscreen_mode();

function EventCancel(event)
{
 	return false 
}

//This will determine when to remove the 
//text in the action buttons.
var ScreenWidthTolerance = 0;

var oJumpInPopup=createPopup();
oJumpInPopup.document.body.style.borderStyle="solid";
oJumpInPopup.document.body.style.borderWidth="2px";
oJumpInPopup.document.body.style.marginLeft="11px";
oJumpInPopup.document.body.style.marginTop="11px";
oJumpInPopup.document.body.style.marginRight="11px";
oJumpInPopup.document.body.style.marginBottom="11px";

var jumpinMode;

function JumpInEntry(text,frame_id)
{
	this.jieText=text;
	this.jieFrame=frame_id;
}

function JumpInMgr()
{
	this.jipEntries=new Array;
}

JumpInMgr.prototype.Reset = function()
{
	this.jipEntries=new Array;
}

JumpInMgr.prototype.AddEntry = function(text,frame_id)
{
	this.jipEntries[this.jipEntries.length]=new JumpInEntry(text,frame_id);
}

JumpInMgr.prototype.ShowPopup = function()
{
	var nEntries=this.jipEntries.length+2;
	if (nEntries>15)
		nEntries=15;
	var nHeight=nEntries*19;
		
	var str='<A href=""></A><P style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt">'+R_jumpin_header+'</P>';
	str+='<DIV style="overflow: auto; position: relative; height='+nHeight+'">'; 
	str+='<UL type="disc">';
	str+='<LI style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt"><A href="" onclick="parent.JumpIn('+"'Start'"+')">'+R_jumpin_beginning+'</A></LI>';

	for (var i=0; i<this.jipEntries.length; i++)
	{
		str+='<LI style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt"><A href="" onclick="parent.JumpIn('+"'"+this.jipEntries[i].jieFrame+"'"+')">'+this.jipEntries[i].jieText+'</A></LI>';
	}	
	
	str+='</UL>';
	str+='</DIV>';
	str+='<A style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt">'+R_menu_press_esc+'</A><A style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt" href="" onclick="parent.oJumpInPopup.hide()">'+R_menu_close+'</A><A style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt">'+R_menu_this+'</A>';

	oJumpInPopup.document.body.innerHTML=str;
	oJumpInPopup.show(0,Get_Element_Height('linkbJ'+jumpinMode),400,83+nHeight,Get_Element('linkbJ'+jumpinMode));
}

var jiMgr=new JumpInMgr;

function ModeButton()
{
	this.enabled=false;
}

var ModeButtons=new Array;
ModeButtons["S"]=new ModeButton();
ModeButtons["T"]=new ModeButton();
ModeButtons["K"]=new ModeButton();
ModeButtons["D"]=new ModeButton();
ModeButtons["JS"]=new ModeButton();
ModeButtons["JT"]=new ModeButton();
ModeButtons["JD"]=new ModeButton();

function imgOn(mode)
{
	if (ModeButtons[mode] && ModeButtons[mode].enabled) {
        document['img'+mode+"1"].style.display = "inline";        
        document['img'+mode+"0"].style.display = "none";        
        document['img'+mode+"x"].style.display = "none";        
    }
}

function imgOff(mode)
{
	if (ModeButtons[mode] && ModeButtons[mode].enabled) {
        document['img'+mode+"0"].style.display = "inline";        
        document['img'+mode+"1"].style.display = "none";        
        document['img'+mode+"x"].style.display = "none";        
    }
}

function GetLink(link_id)
{
	for (var i=0; i<document.anchors.length; i++)
	{
		var lnk=document.anchors[i];
		if (lnk.id==link_id)
			return lnk;
	}
	
	return null;
}

function EnableMode(mode,enable)
{
	if (ModeButtons[mode] && ModeButtons[mode].enabled!=enable)
	{
		ModeButtons[mode].enabled=enable;
		if (enable) {
			document['img'+mode+"0"].style.display = "inline";
			document['img'+mode+"1"].style.display = "none";
			document['img'+mode+"x"].style.display = "none";
		}
		else {
			document['img'+mode+"x"].style.display = "inline";
			document['img'+mode+"0"].style.display = "none";
			document['img'+mode+"1"].style.display = "none";
		}
		if (!document.layers)
		{
			var lnkb=GetLink("linkb"+mode);
			if (lnkb)
				lnkb.style.cursor=enable?"hand":"default";

			var lnkt=GetLink("linkt"+mode);
			if (lnkt)
			{
				lnkt.style.cursor=enable?"hand":"default";
				lnkt.style.color=enable?"#003399":"#999999";
			}
		}
    }
}

function Update()
{
	if (main.stateSelection.type!="T")
	{
		EnableMode("S",false);
		EnableMode("T",false);
		EnableMode("K",false);
		EnableMode("D",false);
		EnableMode("JS",false);
		EnableMode("JT",false);
		EnableMode("JD",false);
	}
	else
	{
		var s=(main.stateSelection.modes.indexOf("S")!=-1);
		EnableMode("S",s);
		EnableMode("JS",s);
		var t=(main.stateSelection.modes.indexOf("T")!=-1);
		EnableMode("T",t);
		EnableMode("JT",t);
		EnableMode("K",(main.stateSelection.modes.indexOf("K")!=-1));
		var d=(main.stateSelection.modes.indexOf("D")!=-1 || main.stateSelection.modes.indexOf("G")!=-1);
		EnableMode("D",d);
		EnableMode("JD",d);
	}
}

function StartPlay(mode,frame_id,from_topic)
{
	function OpenPlayer(link,from_topic)
	{
		var size = "";

		link = "noscroll.html#"+escape(link);
		if (from_topic)
			link="../../../toc/"+link;

		primarydisplay=true;

	
		if (dual_monitor_supported)
		{
			var testwindow=window.open("","","width=10,height=10");
			if (testwindow.screenLeft<0 || testwindow.screenLeft>this.screen.width)
				primarydisplay=false;
			if (testwindow.screenTop<0 || testwindow.screenTop>this.screen.height)
				primarydisplay=false;
			testwindow.close();
		}
	
		var params="toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,";
		if (primarydisplay)
		{
			params+="fullscreen=1";
		}
		else
		{
			sw=window.screen.availWidth-2*SM_CYFRAME;				// screen width
			sh=window.screen.availHeight-2*SM_CYFRAME-SM_CYCAPTION;	// screen height
			params+="top=0,left=0,width="+sw+",height="+sh;
		}
		
		if (new_fullscreen_mode)
			params+=",channelmode=1";
		window.open(link, "player", params);
	}
	
	if (main.stateSelection.type!="T")
		return;
		
	if (mode=="D")
	{
		if (main.stateSelection.modes.indexOf("D")!=-1)
			mode="D";
		else if (main.stateSelection.modes.indexOf("G")!=-1)
			mode="G";
		else
			return;
	}
	else
	{
		if (main.stateSelection.modes.indexOf(mode)==-1)
			return;
	}
	
	var frame="";
	if (frame_id)
		frame=frame_id;

	if (main.systemFatPlayer!="")
	{
		var n=main.stateSelection.path.indexOf("/");
		var cmd="App="+main.stateCurrentApp+"&Module="+encodeURIComponent(main.stateSelection.path.substr(0,n))+"&Topic="+encodeURIComponent(main.stateSelection.path.substr(n+1))+"&Mode="+mode;
		if (frame!="")
		{
			if (frame!="Start")
				cmd+="&Frame="+frame.substr(1);
		}
		else if (main.stateCurrentCtxOd!="")
			cmd+="&Ctx="+main.stateCurrentCtxOd;
		FatPlayerCommand("Play",cmd);
	}
	else
	{
		if (mode=="S" || mode=="T" || mode=="K")
		{
			var topic="../"+main.stateCurrentApp+"/"+main.stateSelection.path+"/TOPIC.HTML?Mode="+mode;
			if (frame!="")
				topic+="&Frame="+frame;
			else if (main.stateCurrentCtxEx!="")
			   topic+="&CTXEX="+main.stateCurrentCtxEx;

			OpenPlayer(topic,from_topic);
		}
		else
		{
			if(doitref)
			{
				if(!doitref.closed)
				{
					alert(R_toc_doit_err);
					return;
				}
			}
			var topic="TOPICG.HTML";
			if (!from_topic)
				topic="../"+main.stateCurrentApp+"/"+main.stateSelection.path+"/"+topic;
			if (frame!="")
				topic+="?Frame="+frame;
			else if (main.stateCurrentCtxEx!="")
			   topic+= "?CTXEX=" + main.stateCurrentCtxEx;
				
			doitref = window.open(topic, "guideitplayer", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,left=1500");
		}
	}
	
	return;
}

function JumpInPoints(mode)
{
	if (!ModeButtons["J"+mode].enabled)
		return;

	jiMgr.Reset();
	jumpinMode=mode;
	var path="../"+main.stateCurrentApp+"/"+main.stateSelection.path+"/JUMPIN.JS";

	setTimeout("data.src='" + path + "'", 10);
}

function JumpIn(frame_id)
{
	oJumpInPopup.hide();
	StartPlay(jumpinMode,frame_id);
}

function Preferences()
{
	main.Preferences();
}

function CloseToc()
{
	if (main.systemFatPlayer!="")
		FatPlayerCommand("Close");
	else
		main.close();
}
//Will open a secondary window
function OpenDialog(DestUrl,resizable,toolbar,menubar,location,scrollbars)
{
	var day = new Date();
	var id = day.getTime();
	var strFeatures = "width=506,height=338,left=147,top=131,screenX=250," + 
			"screenY=250,resizable=" + resizable + ",toolbar=" + toolbar + 
			",scrollbars=" + scrollbars + ",location=" + location + ",menubar=" + menubar;
	window.open(DestUrl, id, strFeatures)
}

//This function will remove the text of the inner window width
//is less then the size of the ScreenWidthTolerance var
function RemoveText(){
	//For support of Navigator we will need to change
	//document.body.clientWidth to window.innerWidth
	if(document.body.clientWidth <= ScreenWidthTolerance){
		Get_Element("SeeIt").innerText="   "
		Get_Element("KnowIt").innerText=""
		Get_Element("TryIt").innerText="   "
		Get_Element("DoIt").innerText="   "
	}else{
		Get_Element("SeeIt").innerText=" "+R_mode_seeit+" "
		Get_Element("KnowIt").innerText=" "+R_mode_knowit+" "
		Get_Element("TryIt").innerText=" "+R_mode_tryit+" "
		Get_Element("DoIt").innerText=" "+R_mode_doit+" "
		
	}
}

function tocban_onload()
{
	ScreenWidthTolerance = 454 + Get_Element("ODLogo").width;

	if (!main.UserPrefs.EnablePreferences || (main.systemFatPlayer=="" && !main.systemEnableCookies))
	{
		var preflink=Get_Element_Style("PrefLink");
		if (preflink)
			preflink.visibility="hidden";
		var preflinksep=Get_Element_Style("PrefLinkSep");
		if (preflinksep)
			preflinksep.visibility="hidden";
	}
	RemoveText();
	main.BannerLoaded();
}
	
function tocban_onunload()
{
}

function tocban_onabout()
{
	if (main.systemFatPlayer!="")
		FatPlayerCommand("About");
	else
		OpenAbout('../preferences/about.html');
}

function tocban_onhelp()
{
	if(Disable_Tutorial) tocban_help_help();
	else
	{
		helpmenu = new HelpMenu();
//		helpmenu.Open(-70,Get_Element_Height('PrefLinkSep'),120,160,Get_Element("PrefLinkSep"));
		helpmenu.Open(-70,Get_Element_Height('PrefLinkSep'));
		helpmenu.Refresh();
	}
}

function tocban_help_help()
{
	OpenHelp('../help/help.html',(main.systemFatPlayer!=""));
}

function tocban_help_tutorial(mode)
{
	main.RunTutorialDialog(mode,1,"",true);
}

function tocban_help_close()
{
	helpmenu.Close();
}

function EventKeyDown()
{
	return main.SearchKeyEvent(window.event.keyCode);
}

//preloading right nav cell bgs			
leftCurve = new Image(12,22);
leftCurve.src = "images/curvlt003366.gif";

rightCurve = new Image(12,22);
rightCurve.src = "images/curvrt003366.gif";

spacer = new Image;
spacer.src = "../images/giftrk1.gif";
		
document.ondragstart = EventCancel;
document.onkeydown = EventKeyDown;
		  
