
function handleBranch(lEvent, lFrameSet) {

	if (lFrameSet) {
		this.location = lEvent + ".html";	
	} else {
		parent.location = lEvent + ".html";
	}
	
} // end handleBranch


function pageRedirect() {
	// ** redirect ** //
	gBitrate = MultiCookieGet("Module","bitrate");
	lEventSuffix = (gBitrate == "_tg") ? gBitrate : "_av";
	if(!gBitrate) { 
		alert("Bitrate is not set.  Called from " + gThisScript ); 
	} else {
		setTimeout("this.location = gThisScript + lEventSuffix + '.html';","50");	
	}
}

function IsArray(obj) {
  return ((typeof obj == "object") && (obj.constructor == Array));
}

// Returns the DOM reference used by IE and NAV 4.  Support for GetElementByID should be added in the future
function buildObjRef(lObject, lStyle) {
// [layer, image], false
// ["BodyText", "tester"], "form"

	lIsArray = IsArray(lObject) // is object param an array?
	if (lStyle==true || typeof(lStyle)=="undefined") { // set style tag?
		lStyleTag = ".style";
	} else {
		lStyleTag = ""; // no style
	}

	// W3C Browsers (6.x browsers)
	if (dom=="w3c"){		
		if (lIsArray) {
			if(lStyleTag==""){
				return eval("document." + lObject[lObject.length-1])
			} else {
				return eval("document.getElementById('" + lObject[lObject.length-1] + "')" + lStyleTag);
			}
		} else {
			if(lStyleTag==""){
				return eval("document." + lObject)
			} else {
			    return eval("document.getElementById('" + lObject + "')" + lStyleTag);	
			}

		}
	} else if(dom=="NS4") {
		if (lIsArray) {
			lEvalString = ""
			for(var i=0; i<=lObject.length-1; i++) {
				lEvalString += "document." + lObject[i]
					if (i < lObject.length-1) {
						lEvalString += "."
					}
		 	}
		} else {
			if(typeof(document[lObject])=="undefined") { alert ("The object (" + lObject + ") is undefined.  Called from buildObjRef()")}
			lEvalString = "document." + lObject }
			return eval(lEvalString)
		}	
	else if(dom=="IE") {
		if (lIsArray) {
			return eval("document.all." + lObject[lObject.length-1] + lStyleTag)
		} else {				
		    return eval("document.all." + lObject + lStyleTag)		
		}
	}
}

function writeLnToDoc(lLayer, lString){

	if (lLayer=="null") {
		var lLayerMode = false	
	} else {
		var lLayerMode = true
	}

	// do the actual document.writing
	lEvalString = 'document.write(lString)';
    if(dom=="NS4") {
		if (lLayerMode) {
			if (IsArray(lLayer)) {
				lEvalString = ""
				for(var i=0; i<=lLayer.length-1; i++) {
					lEvalString += "document." + lLayer[i]
						if (i < lLayer.length-1) {
							lEvalString += "."
						}
			 	}		
				lEvalString += ".document.write(lString)"
			} else {			
				if(typeof(document[lLayer])=="undefined") { alert ("The layer (" + lLayer + ") is undefined.  Called from writeLnToDoc()")}
				lEvalString = 'document[lLayer].document.write(lString)';
			}				
		}
	}

	eval(lEvalString)
	
} // end writeToDoc


function btnRoll(){
	if (!this.keephl && this.enabled) {
		this.toggle = !(this.toggle);	
		this.image.src = (this.toggle) ? this.hilite : this.lolite;
	}
}

function buttonObj(name, layername, source, btnfiletype) {
	// properties
	this.enabled = true;
	this.name = name || "";
	this.btnfiletype = btnfiletype || "gif";	
	this.path = (source=="common") ? gComGraphPath : gModGraphPath;
	this.lolite = this.path + this.name + "_lo." + this.btnfiletype;
	this.hilite = this.path + this.name + "_hi." + this.btnfiletype;
	this.toggle = 0;
	
	// methods
	this.btnRoll = btnRoll;
	this.disableMe = function() {this.graylyr.visibility = "visible"; this.enabled = false; this.image.src=this.lolite; this.toggle = 0} 
	this.enableMe = function() {this.graylyr.visibility = "hidden"; this.enabled = true;}
	
	// object references
	if (layername) {
		this.layer = buildObjRef(layername);
		this.image = buildObjRef([layername,name],false);
	}
}

// Opens a new window and centers it on the screen
// Default appearance is no chrome except status. Scroll bars auto.
//
// Mandatory Arguments: windowname, htmlfilename, width, height
// Optional Arguments: toolbar, directories, loc bar, statusbars, menubar, scrollable and resizable
//
// Returns: window reference

function openNewWin(file, winname, w, h, options) {
 
	 // options: array of window options to be set to "yes" (fullscreen, tool, loc, dir, status, menu, scroll, resize)
	 var fullscreen = "no";
	 var tool = "no";
	 var loc = "no";
	 var dir = "no";
	 var status = "no";
	 var menu = "no";
	 var scroll = "no";
	 var resize = "no";
	 
	 for(i=0; i<options.length; i++) {
	  eval(options[i] +' = "yes";');
	 }
	 
	 // init arguments
	 var x = (screen.width/2)-(w/2); 
	 var y = (screen.height/2)-(h/2);
	 
	 // init chrome
	 lChrome = "toolbar="+tool+",location="+loc+",fullscreen="+fullscreen+",directories="+dir+",status="+status+",menubar="+menu+",scrollbars="+scroll+",resizable="+resize+",width="+w+",height="+h+",left="+x+",top="+y;
	 
	 // open window and return reference
	 return window.open(file, winname, lChrome);
}


function redrawLyr() { // Force reload if IE, so re-center can occur
	if(document.all) location.reload();
}

function getCursorPos(evt) {
   var mouseLocs = new Array();
   mouseLocs[0] = (dom=="IE4") ? parseInt(evt.clientX) : parseInt(evt.pageX);
   mouseLocs[1] = (dom=="IE4") ? parseInt(evt.clientY) : parseInt(evt.pageY);

   return mouseLocs;
}

function resetIEScroll(){
// Resets the scroll bars to 0,0 for IE5 because
// using the spacebar in a "focused" frame without
// a scrollbar will cause the frame to scroll
//
// Arguments: none
//
// Returns: none
 
 if(dom=="IE4") { scrollTo(0,0); }
}

function readStatus(event, num) {
	var lStatus = MultiCookieGet("Module", "Status" + event);
	var lStatusArray = lStatus.split("");
	
	if (num) {
		return lStatusArray[num-1];			
	} else {
		return lStatusArray;
	}
}


function statusAdd(event, num, val) {

	// init vars
	var lStatusArray = readStatus(event, 0);
	
	var len = lStatusArray.length
	var lString = "";
	
	// set the value
	lStatus = lStatusArray[num-1]
	if (lStatus!="C") {
		lStatusArray[num-1] = val;
	}
	// build string for cookie
	for(var i=0; i<len; i++) {
		lString += lStatusArray[i];
	}
	
	// write cookie	
	MultiCookieSet("Module", "Status" + event, lString)
}


function statusComplete(event) {
	var lStatus = MultiCookieGet("Module", "Status" + event);
	var lStatusArray = lStatus.split("");
	var len = lStatusArray.length;
	var lComplete = true;
	
	// build string for cookie
	for(var i=0; i<len; i++) {
		if (lStatusArray[i]!="C") {
			lComplete = false;
			break;
		}
	}
	
	return lComplete;
}

function cookieToList(cookie, mcookie) {

	lString = MultiCookieGet(cookie, mcookie)
	return lString.split("|");	
}

function listToCookie(cookie, mcookie, array) {

	lString = ""
	for (var i=0; i<array.length; i++){
		lString+=array[i] + "|";
	}
	MultiCookieSet(cookie, mcookie, lString)
}


// Due to browser limitations that don't allow the "zoom box" to be disabled in IE, 
// this script will snap the size back to the original window size upon clicking
// the zoom box.

function handleIEResize() {
	if(BR.brand=="IE")
		resizeTo (766, 525);
}

// DISABLECLICK.JS
//
// Written by C. Benoit for Midi, Inc.
// 6/29/00
//
// Disables the right click menu in Netscape and IE
// There is separate code for Netscape and IE4.  The code
// for IE4 requires an alert box.  

function disableContextMenu(){
	
	if (BR.brand=="IE" && BR.name!="IE4") {
		document.oncontextmenu = function(){return false}
	}
	if (BR.name=="NS6") {
		document.onclick = function(e) {if (e.which == 3) return false}
//		document.ondblclick = function(e) {alert(e.which);if (e.which == 3) return false}
		document.onmouseup = function(e) {if (e.which == 3) return false}	
		document.onmousedown = function(e) {if (e.which == 3) return false}	
	}
	if (BR.name=="NS4") {
		window.captureEvents(Event.MOUSEDOWN);
		window.onmousedown = function(e){if(e.target==document)return false;}
	}
	if (BR.name=="IE4") { 
		window.onmousedown = function() {alert('Right-clicking to display the browser\'s context menu is not available during the quiz.');}
	}
}

function getBasePath(fullpath, pos) {
	var lArray = unescape(fullpath).split("/")
	var lNewString = ""
	for(var i=0; i<lArray.length-pos; i++) {
		lNewString += lArray[i] + "/"
	}
	
	return lNewString;
}

// 3.1 -- new function that conditionally writes out content for onFocus event in image maps.  Function this.blur crashes IE4 with a click & drag.

function mapBlur () {
		switch (BR.name) {
			case "IE4":
				lBlurText = "" // no this.blur for IE4.
				break
			case "IE5":						
				lBlurText = "this.blur()"
				break
			case "IE5.5":
				lBlurText = "this.blur()"
				break
			case "IE6":
				lBlurText = "this.blur()"
				break
			case "IE6":
				lBlurText = "this.blur()"
				break
			case "NS4":	
				lBlurText = "this.blur()"
				break				
			case "NS6":	
				lBlurText = "" // no this.blur for NS6.
				break					
		}
		
	return lBlurText
}

// 3.2 method that will detect whether a layer exists.  Only use with 3.2+
function layerExists(lLayer){

	if (dom=="w3c"){
		lObj = eval("document.getElementById('" + lLayer + "')");	
	} else if(dom=="NS4") {
		lObj = document[lLayer];
	} else if(dom=="IE") {
		lObj = eval("document.all." + lLayer);
	}
	
	if (typeof(lObj)=="undefined") {
		return false
	}
	return true	
}