// Setting up the opening variables
defaultOverTableColor = "#E7EFF7"
defaultOutTableColor = "#F6FBFF"
var whatYresouution =  screen.availHeight;

function dev(){
	alert("Under development");
}

function doPageNumbers(whatPage, whatDirection) {
	if (whatPage) {
		parent.content.location = whatPage
	} else {
		if (whatDirection == "prev") {
			alert("This is the first page. ");
		} else if (whatDirection == "next") {
			alert("There are no further pages.");
		}
	}
}
//------ DISPLAY PAGE TITLE IN STATUS BAR --------//

function doStatus(messageForStatus){
//alert(parent.content.nextLink);
//if (parent.content.nextLink == false) {
//	parent.bottomNav.prev.visible = false
//	alert("here");
//}
	if (!messageForStatus) {
		window.status = document.title;
		return true;
	} else {
		window.status = messageForStatus;
		return true;
	}
	
}

//---------------- IMAGE PRELOAD ----------------//

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

//---------------- PRINT FUNCTION ----------------//

function printPage(frameName) {
	if ((navigator.userAgent.indexOf("Mac") != -1) && (navigator.appName.indexOf("Microsoft") != -1)) {
		//This is the Mac IE window
		alert("Sorry, your browser doesn't support this feature. Please use the Print option from the browser's File menu");
	} else {
		if(!frameName){
			//These are the other windows (pc ie and ns, mac ns)
			self.print();
		} else {
			var frameToPrint = eval("parent." + frameName);
			frameToPrint.focus();
			frameToPrint.print();		
		}
	}
}

//---------------- GLOSSARY FUNCTIONS ----------------//

var glossary = new Array();
var g = "";
var path = "";

function GlossaryItem(key,d) {
	this.key = key
	this.definition = d
}

function addGlossaryItem(k,d) {	
	glossary[glossary.length] = new GlossaryItem(k,d)
}

function doGlossary(k, levels) {
	
	var path = "";
	for(i=0; i < levels; i++){
		path += "../"
	}

//	glossLocation = path + "glossary/gloss.htm?" + k;
	glossLocation = "../../../shared/html/glossary/glossary.htm#" + k;
//	openCenteredWin(glossLocation, "glossary", 400, 220); // popup the window
	openCenteredWin(glossLocation, "glossary", 600, 220); // popup the window

}

// this function is called by the glossary frameset when pops up (toolbox/resources/glossary/definefs.htm)
function showDefinition(){

var urlString = document.location.toString();
var term = urlString.split("?")[1];
var k = unescape(term);

var found = false;

	for(var i = 0 ; i < glossary.length ; i++) {
		if(glossary[i].key == k){
			found = true
			g += '<h2>' + glossary[i].key + '</h2>\n' 
			+ glossary[i].definition + '\n'
			break
		}
	}
	
	if(!found){
		g += '<p>Sorry, couldn\'t locate a definition for <b>' + k + '</b>.</p>'
	}
	
	document.write(g);
	document.close();
}

// Displays all definitions for specified letters
// Eg. showAllDefinitions("A,B,C,D"); will display all definitions for these letters only
function showAllDefinitions(letters){

	var displayLetters = new Array();
	displayLetters = letters.split(",");
	numLetters = displayLetters.length;
	
	var headLinks = "<div class='center'>|"
	for(var i = 0 ; i < numLetters; i++) {
		headLinks += '&nbsp;&nbsp;&nbsp;<a href="#' + displayLetters[i] + '" title="Go to items beginning with ' + displayLetters[i] + '">' + displayLetters[i] + '</a>';
	}
	headLinks += '&nbsp;&nbsp;&nbsp;|</div>'
	document.write(headLinks);
	
	x = 0;
	while(x < numLetters){
		var found = false;
		
		for(var i = 0 ; i < glossary.length ; i++) {
			if(glossary[i].key == "$section$" && glossary[i].definition == displayLetters[x]){
				found = true
				g += '<a name="' + glossary[i].definition + '" id="' + glossary[i].definition + '"></a>\n'
				g += '<h1 class="glosshead">' + glossary[i].definition + '</h1>\n'
				g += '<div class="defs">\n'
				pos = i+1;
				while(glossary[pos].key != "$section$"){
					if(glossary[pos].key != ""){
						g += '<h3 class="glossWord">' + glossary[pos].key + '</h3>' + glossary[pos].definition + '\n\n'
					} else {
						g += '<p>There are no definitions for the letter '  + glossary[i].definition +  '</p>\n'
					}
					pos++;
				}
				//g += '<p class="top"><a href="javascript:scroll(0,0)" title="Go to top">top</a></p>\n';
				g += '</div>';
				g += '<p align="right">\n'
				g += '<a href="javascript:void(0);" onclick="javascript:scroll(0,0);" onmouseout="changeImages(\'sm_top' + i + '\', \'../images/sm_top.gif\'); return true;" onmouseover="changeImages(\'sm_top' + i + '\', \'../images/sm_top_on.gif\'); return true;"><img src="../images/sm_top.gif" border="0" width="41" height="13" alt="Go to top" name="sm_top' + i + '" id="sm_top' + i + '" /></a>\n'
				g += '</p>\n'
			}
		}
		x++;
	}

	//if(!found){
	//	g += '<p>Sorry, couldn\'t locate a definition for <b>' + k + '</b>.</p>'
	//}

	return g;
}

// functions to change the bgColor of a table cell

function doColorChangeOver(whatTableCell) {
	whatTableCell.bgColor = defaultOverTableColor;
}
function doColorChangeOut(whatTableCell) {
	whatTableCell.bgColor = defaultOutTableColor;
}
function doPageLink(whatPageToLinkTo) {
	document.location.href = whatPageToLinkTo;
}

function doBRLines(howManyLoopsToDo) {
//alert(whatYresouution);
//alert(document.floatingNav.topMargin);
//document.floatingNav.top = whatYresouution
	if (whatXresouution == "800") {
		howManyLoopsToDo = 4
	}
	if (whatXresouution == "1024") {
		howManyLoopsToDo = 14
	}
	if (whatXresouution == "1280") {
		howManyLoopsToDo = 21
	}
	for (var i = 0; i < howManyLoopsToDo; i++) {
//		document.writeln("<br clear='all' />");
	}
}	

function doHashDown(whereToGo) {
	document.location.hash = whereToGo
}