// From an idea courtesy of those lovely folks at SitePoint - thanks Kev and Cam

		var Core = {};

		// W3C DOM 2 Events model
		if (document.addEventListener)
		{
			Core.addEventListener = function(target, type, listener)
			{
				target.addEventListener(type, listener, false);
			};

			Core.removeEventListener = function(target, type, listener)
			{
				target.removeEventListener(type, listener, false);
			};

			Core.preventDefault = function(event)
			{
				event.preventDefault();
			};

			Core.stopPropagation = function(event)
			{
				event.stopPropagation();
			};
		}
		// Internet Explorer Events model
		else if (document.attachEvent)
		{
			Core.addEventListener = function(target, type, listener)
			{
				// prevent adding the same listener twice, since DOM 2 Events ignores
				// duplicates like this
				if (Core._findListener(target, type, listener) != -1) return;

				// listener2 calls listener as a method of target in one of two ways,
				// depending on what this version of IE supports, and passes it the global
				// event object as an argument
				var listener2 = function()
				{
					var event = window.event;

					if (Function.prototype.call)
					{
						listener.call(target, event);
					}
					else
					{
						target._currentListener = listener;
						target._currentListener(event)
						target._currentListener = null;
					}
				};

				// add listener2 using IE's attachEvent method
				target.attachEvent("on" + type, listener2);

				// create an object describing this listener so we can clean it up later
				var listenerRecord =
				{
					target: target,
					type: type,
					listener: listener,
					listener2: listener2
				};

				// get a reference to the window object containing target
				var targetDocument = target.document || target;
				var targetWindow = targetDocument.parentWindow;

				// create a unique ID for this listener
				var listenerId = "l" + Core._listenerCounter++;

				// store a record of this listener in the window object
				if (!targetWindow._allListeners) targetWindow._allListeners = {};
				targetWindow._allListeners[listenerId] = listenerRecord;

				// store this listener's ID in target
				if (!target._listeners) target._listeners = [];
				target._listeners[target._listeners.length] = listenerId;

				// set up Core._removeAllListeners to clean up all listeners on unload
				if (!targetWindow._unloadListenerAdded)
				{
					targetWindow._unloadListenerAdded = true;
					targetWindow.attachEvent("onunload", Core._removeAllListeners);
				}
			};

			Core.removeEventListener = function(target, type, listener)
			{
				// find out if the listener was actually added to target
				var listenerIndex = Core._findListener(target, type, listener);
				if (listenerIndex == -1) return;

				// get a reference to the window object containing target
				var targetDocument = target.document || target;
				var targetWindow = targetDocument.parentWindow;

				// obtain the record of the listener from the window object
				var listenerId = target._listeners[listenerIndex];
				var listenerRecord = targetWindow._allListeners[listenerId];

				// remove the listener, and remove its ID from target
				target.detachEvent("on" + type, listenerRecord.listener2);
				target._listeners.splice(listenerIndex, 1);

				// remove the record of the listener from the window object
				delete targetWindow._allListeners[listenerId];
			};

			Core.preventDefault = function(event)
			{
				event.returnValue = false;
			};

			Core.stopPropagation = function(event)
			{
				event.cancelBubble = true;
			};

			Core._findListener = function(target, type, listener)
			{
				// get the array of listener IDs added to target
				var listeners = target._listeners;
				if (!listeners) return -1;

				// get a reference to the window object containing target
				var targetDocument = target.document || target;
				var targetWindow = targetDocument.parentWindow;

				// searching backward (to speed up onunload processing), find the listener
				for (var i = listeners.length - 1; i >= 0; i--)
				{
					// get the listener's ID from target
					var listenerId = listeners[i];

					// get the record of the listener from the window object
					var listenerRecord = targetWindow._allListeners[listenerId];

					// compare type and listener with the retrieved record
					if (listenerRecord.type == type && listenerRecord.listener == listener)
					{
						return i;
					}
				}
				return -1;
			};

			Core._removeAllListeners = function()
			{
				var targetWindow = this;

				for (id in targetWindow._allListeners)
				{
					var listenerRecord = targetWindow._allListeners[id];
					listenerRecord.target.detachEvent(
					"on" + listenerRecord.type, listenerRecord.listener2);
					delete targetWindow._allListeners[id];
				}
			};

			Core._listenerCounter = 0;
		}

		Core.addClass = function(target, theClass)
		{
			if (!Core.hasClass(target, theClass))
			{
				if (target.className == "")
				{
					target.className = theClass;
				}
				else
				{
					target.className += " " + theClass;
				}
			}
		};

		Core.addClassGlobal = function(target, theClass)
		{
			for(var i=0; i<target.length; i++) 
			{
				Core.addClass(target[i], theClass);
			}
		}


		Core.getElementsByClassName = function(theClass)
		{
/*
			if(
				(document.getElementsByClassName)
			)
			{
				return document.getElementsByClassName(theClass);
			}
*/

			if(arguments[1]) 
			{
				// a second argument restricts the tags searched
				// this makes IE (particularly) much faster by limiting the document.all to searching for a class within a specified tag only
				var tagName = arguments[1]; 
			}
			else 
			{
				// otherwise we search 'em all
				var tagName = "*";
			}
			var elementArray = document.getElementsByTagName(tagName);
			var matchedArray = [];
			var pattern = new RegExp("(^| )" + theClass + "( |$)");

			for (var i = 0; i < elementArray.length; i++)
			{
				if (pattern.test(elementArray[i].className))
				{
					matchedArray[matchedArray.length] = elementArray[i];
				}
			}

			return matchedArray;
		};

		Core.hasClass = function(target, theClass)
		{
			var pattern = new RegExp("(^| )" + theClass + "( |$)");

			if (pattern.test(target.className))
			{
				return true;
			}

			return false;
		};

		Core.removeClass = function(target, theClass)
		{
			var pattern = new RegExp("(^| )" + theClass + "( |$)");

			target.className = target.className.replace(pattern, "$1");
			target.className = target.className.replace(/ $/, "");
		};

		Core.removeClassGlobal = function(target, theClass)
		{
			var pattern = new RegExp("(^| )" + theClass + "( |$)");
			for(var i=0; i<target.length; i++) {
				target[i].className = target[i].className.replace(pattern, "$1");
				target[i].className = target[i].className.replace(/ $/, "");					
			}

		};
		
		Core.toggleClass = function(target, theClass)
		{
			if(Core.hasClass(target, theClass)) Core.removeClass(target, theClass);
			else Core.addClass(target, theClass);
		};	
		
		Core.getStyleRuleId = function(selector)
		{
			// returns an the id of the rule matching the 'selector'
			// the optional second argument selects the styleSheet by id
			// assumes only one matching rule
			if(arguments[1])
			{
				var ss = arguments[1]
			}
			else
			{
				var ss = 0;
			}
			
			if(document.styleSheets[ss].cssRules)
			{
				// w3c model
				for(var i=document.styleSheets[ss].cssRules.length-1; i>=0; i--)
				{
					// search backwards for speed
					if(document.styleSheets[ss].cssRules[i].selectorText.indexOf(selector) != -1)
					{
						return i;// return the id 
					}
				}
				return false;
			}
			
			else if(document.styleSheets[ss].rules)
			{
				// microsoft model
				for(var i=document.styleSheets[ss].rules.length-1; i>=0; i--)
				{
					// search backwards for speed
					if(document.styleSheets[ss].rules[i].selectorText.indexOf(selector) != -1)
					{
						return i;// return the id 
					}
				}
				return false;
			}			
		};
		
		Core.switchStyleRules = function(selector1, selector2, theRule)
		{
			// switches the style rule (theRule) from css selector1 to selector2
			// body[0]._switch records the state as selector_n where n =  the index of the rule in styleSheets[0]
			// first call initialises body[0]._switch 
			// we use this method because we don't trust browsers to reliably identify the rule by our searching for it
			
			if(!document.styleSheets[0]) return false;
			
			if(document.styleSheets[0].cssRules)
			{
				// w3c model
				// we assume thatere is a maximum of only one rule matching each selector
				var id1 = Core.getStyleRuleId(selector1)
				var id2 = Core.getStyleRuleId(selector2)
				if(id1)
				{
					document.styleSheets[0].deleteRule(id1);
					document.styleSheets[0].insertRule(selector2 + '{' + theRule + '}', document.styleSheets[0].cssRules.length);
				}
				else if(id2)
				{
					document.styleSheets[0].deleteRule(id2);
					document.styleSheets[0].insertRule(selector1 + '{' + theRule + '}', document.styleSheets[0].cssRules.length);	
				}
				else
				{
					// first call - initialise
					document.styleSheets[0].insertRule(selector2 + '{' + theRule + '}', document.styleSheets[0].cssRules.length);	
				}	
			}
			else if(document.styleSheets[0].rules)
			{
				// microsoft model
				// we assume thatere is a maximum of only one rule matching each selector
				var id1 = Core.getStyleRuleId(selector1)
				var id2 = Core.getStyleRuleId(selector2)
				if(id1)
				{
					document.styleSheets[0].removeRule(id1);
					document.styleSheets[0].addRule(selector2, theRule, document.styleSheets[0].rules.length);
				}
				else if(id2)
				{
					document.styleSheets[0].removeRule(id2);
					document.styleSheets[0].addRule(selector1, theRule, document.styleSheets[0].rules.length);	
				}
				else
				{
					// first call - initialise
					document.styleSheets[0].addRule(selector2, theRule, document.styleSheets[0].rules.length);	
				}
			}
		};

		
		Core.getComputedStyle = function(element, styleProperty)
		{
			var computedStyle = null;

			if (typeof element.currentStyle != "undefined")
			{
				computedStyle = element.currentStyle;
			}
			else
			{
				computedStyle = document.defaultView.getComputedStyle(element, null);
			}

			return computedStyle[styleProperty];
		};
		
     Core.ascendDOM = function (e, tag, s) 
     {
			if(arguments[1]) {
				var stopTag = s
			}
			else {
				var stopTag = "html";
			}
          while ((e.nodeName.toLowerCase() != tag) && (e.nodeName.toLowerCase() != stopTag)) {
          	e = e.parentNode;
          }
          return (e.nodeName.toLowerCase() == stopTag) ? null : e;
     };
		
		Core.firstChildTag = function (e)
		{
			// return the first child node having nodeType = 1;
			var c = e.childNodes;
			for(var i = 0; i < c.length; i++)
			{
				if(c[i].nodeType==1) return c[i];
			}			
			return false;
		};	
		Core.discardElement = function(e)
		{
			// discard the element e
			x.parentNode.removeChild(e);
			e = null;
		};
		Core.discardNode = function(n)
		{
			// discard the node whose id is 'n'
			var x = document.getElementById(n);
			x.parentNode.removeChild(x);
			x = null;
		};

		Core.start = function(runnable)
		{
			Core.addEventListener(window, "load", runnable.init);
		};	

		Core.getHTTPObject = function()
		{		
			var xhr = false;
			if (window.ActiveXObject) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} else if (window.XMLHttpRequest) {
				xhr = new XMLHttpRequest();
			}
			return xhr;
		};
		
		var Help =
		{
			init: function() 
			// adds listeners to all <span> tags with class 'helpLink' 
			{
				var links =  Core.getElementsByClassName("helpLink", "span");
				for(var j=0; j < links.length; j++) {
                   Core.addEventListener(links[j], "mouseover", Help.showHelpListener);
                   Core.addEventListener(links[j], "mouseout", Help.hideHelpListener);
				}				
			},
			showHelpListener: function(event)
			{
				Help.showHelp(this, event);
				Core.preventDefault(event);
			},

			hideHelpListener: function(event)
			{
				clearTimeout(this._timer);
				Help.hideHelp(this);
			},	
			
			showHelp: function(link, event)
			{
				//Core.removeEventListener(link, "mouseover", Help.showHelpListener); // prevent multiple triggering
				//Help.hideHelpListener(event);
				
				if(document.getElementById('help')) return;  // only one at a time!
				var body = document.getElementsByTagName('body');
				var help = document.createElement("span");
				var content = link.id;
				help.id='help';
				help.className += " help invisible";
				body[0].appendChild(help);
				body[0]._help = help;
				body[0]._cursorX = Viewport.getCursorPosition(event).x;
				body[0]._cursorY = Viewport.getCursorPosition(event).y;
				body[0]._availableY = Viewport.viewport(event)[1] - Viewport.whereOnViewport(event)[1];
				body[0]._availableX = Viewport.whereOnViewport(event)[0];
				
				if((body[0]._content == content) && (body[0]._helpText)){
					// we've loaded this content already -> show it now
					help.innerHTML = body[0]._helpText;
                    if(document.getElementById('helpText')) document.getElementById('helpText').style.opacity = 0;														
                    Help.positionHelp(link, help, body[0]._cursorX, body[0]._cursorY, body[0]._availableX, body[0]._availableY);
                    Help.revealHelp(help);	
					Core.addEventListener(link, 'click', Help.openHelpWindow);		
					return;				
				}
				
               help.innerHTML = "<p class='bold'><img id='helpIcon' src='images/waitingAnimSmall.gif'>&nbsp;Loading Help & Information</p>";						
               Help.positionHelp(link, help, body[0]._cursorX, body[0]._cursorY, body[0]._availableX, body[0]._availableY);
               Core.removeClass(help, "invisible");				
               var ajaxRequest = Core.getHTTPObject();
			
				if(ajaxRequest) {
					ajaxRequest.onreadystatechange = function()
					{
						if(ajaxRequest.readyState == 4) {
							if(ajaxRequest.status == 200) {
								// response body contains formatted help text
								var responseText = ajaxRequest.responseText
								if(responseText !="") {
									// retrieve help for the category stored in the id - assumes only one identical helplink per page!!
									responseText = responseText.replace(/^\s+/, ' '); // remove any leading whitespace	
									var helpText = responseText.replace(/\<table(.|\n)*/gi, ''); // truncate from <table 
									Core.addClass(help, 'invisible'); // hide until positioned
									if(helpText.replace(/(\<(\w+|\/\w+).*?\>)|(\s{2,})/g,'').length > 700) // length without tags ) 
									{
										helpText = helpText.match(/.{0,700}\b/) 
										helpText += "&hellip;</div><div class='small bold center' id='moremsg'><p class='center'>~&nbsp; Click Icon for More ~</p><p class='small ghost center'>[Opens in a new window]</p></div>";
									}
									else
									{
										helpText = helpText + "<div class='small bold center' id='moremsg'><p class='center ghost'>~&nbsp; Click Icon to open in a new window</p></div>";
									}
									help.innerHTML = helpText;
									body[0]._content = content; // save which help content we've just loaded	
									body[0]._responseText = responseText; // save the text for openHelpWindow function
									body[0]._helpText = helpText; 								
									if(document.getElementById('helpText')) document.getElementById('helpText').style.opacity = 0;														
									Help.positionHelp(link, help, body[0]._cursorX, body[0]._cursorY, body[0]._availableX, body[0]._availableY);
									Help.revealHelp(help);
									Core.addEventListener(link, 'click', Help.openHelpWindow);					
								}
							}
							
						}
					}
					// build search string for POST

					var searchString = "c=" + content;

					ajaxRequest.open("POST", "genericHelpLoad.php", true);
					ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					ajaxRequest.send(searchString);
				}
			},		
			
			openHelpWindow: function() {
				var body = document.getElementsByTagName('body');
				if(document.getElementById('helpText')) 
				{
					var m = document.getElementById('moremsg');
					m.innerHTML = "<div class='small bold center red'><img src= 'images/waitingAnimSmall.gif'> Opening Help Window</div>";
				}
				if(body[0]._content) {
					helpWindow = window.open('', '', 'height=600, width=600,scrollbars=yes,resizable=yes');
					helpWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">'
						+ '<html>'
     				+ '<head>'
          			+ '<link href="microsite.css" rel="stylesheet" type="text/css">'		
          			+ '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'
						+ '</head>'
						+ '<body>'
						+ '<div class="frame">'
						+ '<div class="medium right"><a class="link" onclick="window.close()">Close X&nbsp;&nbsp;&nbsp;</a></div>'
					     + '<div class = "help">'
						+ body[0]._responseText
						+ '</div>'
						+ "<script type='text/javaScript'>if(opener.document.getElementById('moremsg')) opener.document.getElementById('moremsg').innerHTML = ''; this.focus();  </script>"
						+ '</div>'
						+ '</body>'
						+ '</html>');
				} 
			},
			
			positionHelp: function(link, help, cursorX, cursorY, availableX, availableY) 
			{
				// position help 
				var helpHeight = help.offsetHeight;
				var helpWidth = help.offsetWidth;
				
				if(availableY > helpHeight + 25) var offsetTop = cursorY ;
				else var offsetTop = cursorY - help.offsetHeight + availableY - 25; // don't go off the bottom

				if((availableX + helpWidth + 10) > Viewport.viewport()[0]) var offsetLeft = cursorX - helpWidth -10 ;
				else	var offsetLeft = cursorX + 10; // don't go off the RHS

				help.style.top = offsetTop + 'px';
				help.style.left = offsetLeft + 'px';

			},
			
			revealHelp: function(help) {
				Core.removeClass(help, 'invisible');	
				this._timer = setTimeout(function()
				{
					if(document.getElementById('helpText')) {
						var t = document.getElementById('helpText');
						if(t.style.opacity) {
                              t.style.opacity = String(parseFloat(t.style.opacity) + 0.075);
                              if(parseFloat(t.style.opacity) < 0.99) Help.revealHelp(help); 
						}
					}
				}, 40);


			},			
			
			hideHelp: function(link)
			{
				Core.removeEventListener(link, 'click', Help.openHelpWindow);
				var body = document.getElementsByTagName('body');
				if (body[0]._help)
				{
					//if(document.getElementById('helpText')) {
						body[0].removeChild(body[0]._help);
						body[0]._help = null;		
					//}
				}
				//setTimeout(function() {Core.addEventListener(link, "mouseover", Help.showHelpListener); }, 500);// delay/resume mouseover listening on this link						
			}			
		};
		
		Core.start(Help);			

		
		
		var Screenscore =
		{
			init: function() 
			// adds listeners to all <sic> tags with class 'screenscore' 
			{
				var links =  Core.getElementsByClassName("screenscore", "td");
				for(var j=0; j < links.length; j++) {
                   Core.addEventListener(links[j], "mouseover", Screenscore.showScreenscoreListener);
                   Core.addEventListener(links[j], "mouseout", Screenscore.hideScreenscoreListener);
				}				
			},
			showScreenscoreListener: function(event)
			{
				Screenscore.showScreenscore(this, event);
				Core.preventDefault(event);
			},

			hideScreenscoreListener: function(event)
			{
				var body = document.getElementsByTagName('body');
				clearTimeout(body[0]._timer);
				Screenscore.hideScreenscore(this);
			},	
			
			showScreenscore: function(link, event)
			{
				
				if(document.getElementById('screenscore')) return;  // only one at a time!
				var body = document.getElementsByTagName('body');
				var screenscore = document.createElement("span");
				var applicantid = link.id.replace("screen", "");
				screenscore.id='screenscore';
				screenscore.className += " screenscore invisible";
				body[0].appendChild(screenscore);
				body[0]._screenscore = screenscore;
				body[0]._cursorX = Viewport.getCursorPosition(event).x;
				body[0]._cursorY = Viewport.getCursorPosition(event).y;
				body[0]._availableY = Viewport.viewport(event)[1] - Viewport.whereOnViewport(event)[1] - 30;
				body[0]._availableX = Viewport.whereOnViewport(event)[0];
				
				if((body[0]._applicantid == applicantid) && (body[0]._screenscoreText))
				{
					// we've loaded this applicantid already -> show it now
					screenscore.innerHTML = body[0]._screenscoreText;
                    if(document.getElementById('screenscore')) document.getElementById('screenscore').style.opacity = 0;														
                    Screenscore.positionScreenscore(link, screenscore, body[0]._cursorX, body[0]._cursorY, body[0]._availableX, body[0]._availableY);
                    Screenscore.revealScreenscore(screenscore);		
					return;				
				}

				body[0]._timer = setTimeout(function() {				
                    
                    screenscore.innerHTML = "<p class='bold'><img id='screenscoreIcon' src='images/waitingAnimSmall.gif'>&nbsp;Loading Key Negative Responses to Screening Questions</p>";						
                    Screenscore.positionScreenscore(link, screenscore, body[0]._cursorX, body[0]._cursorY, body[0]._availableX, body[0]._availableY);
					Core.removeClass(screenscore, "invisible");
                    var ajaxRequest = Core.getHTTPObject();
     			
     				if(ajaxRequest) {
     					ajaxRequest.onreadystatechange = function()
     					{
     						if(ajaxRequest.readyState == 4) {
     							if(ajaxRequest.status == 200) {
     								// response body contains formatted screenscore text
     								var responseText = ajaxRequest.responseText;
     								if(responseText !="") {
     									// retrieve screenscore for the category stored in the id - assumes only one identical screenscorelink per page!!
     									Core.addClass(screenscore, 'invisible'); // hide until positioned
     									var scoreText = "<div class='big bold red'>Screening Questions Score:&nbsp; " + document.getElementById('screenscoreText' + applicantid).innerHTML + '</div>';
     									if(responseText.length > 1500) 
     									{
     										var screenscoreText = scoreText + responseText.substr(0, 1300) + "&hellip; <b>more</b></div>";
     									}
     									else 
     									{
     										var screenscoreText = scoreText + responseText; 
     									}
										screenscoreText += "<div class='small bold center' id='moremsg'><p>~&nbsp; Click Score to Review All Responses ~</p><p class='small ghost center'>[Opens in a new window]</p></div>";
     									screenscore.innerHTML = screenscoreText;
     									body[0]._applicantid = applicantid; // save which screenscore applicantid we've just loaded
											body[0]._screenscoreText = screenscoreText; // save the screenscore text we've just loaded										
     									if(document.getElementById('screenscore')) document.getElementById('screenscore').style.opacity = 0;														
     									Screenscore.positionScreenscore(link, screenscore, body[0]._cursorX, body[0]._cursorY, body[0]._availableX, body[0]._availableY);
     									Screenscore.revealScreenscore(screenscore);				
     								}
     							}
     							
     						}
     					}
     
     					// build search string for POST
     
     					var searchString = "a=" + applicantid + "&ppt=4rt5q";     
     					ajaxRequest.open("POST", "screenscoreLoad.php", true);
     					ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     					ajaxRequest.send(searchString);
     				}
				}, 800);			
			},		
			
			positionScreenscore: function(link, screenscore, cursorX, cursorY, availableX, availableY) {
				// position screenscore 
				var screenscoreHeight = screenscore.offsetHeight;
				var screenscoreWidth = screenscore.offsetWidth;
				
				if(availableY > screenscoreHeight) var offsetTop = cursorY ;
				else var offsetTop = cursorY - screenscore.offsetHeight + availableY - 5; // don't go off the bottom

				if((availableX + screenscoreWidth + 10) > Viewport.viewport()[0]) var offsetLeft = cursorX - screenscoreWidth -5 ;
				else	var offsetLeft = cursorX + 5; // don't go off the RHS

				screenscore.style.top = offsetTop + 'px';
				screenscore.style.left = offsetLeft + 'px';

			},

			revealScreenscore: function(screenscore) {
				Core.removeClass(screenscore, 'invisible');	
				var doItAgain = false;
				this._timer = setTimeout(function()
				{
					if(document.getElementById('screenscore')) {
						var t = document.getElementById('screenscore');
						if(t.style.opacity) {
                              t.style.opacity = String(parseFloat(t.style.opacity) + 0.075);
                              if(parseFloat(t.style.opacity) < 0.99) doItAgain = true;
						}
/*
						else {
							// alpha for that SOB IE -> ignored because it spoils appearance (? no cool-type)
							alpha = parseInt(t.style.filter.slice(t.style.filter.search(/\d+/), t.style.filter.search(/\)/)));
							alpha +=5;
							t.style.filter = 'alpha(opacity=' + alpha + ')';
							if(alpha < 99) doItAgain = true;
						}
*/
						if(doItAgain) Screenscore.revealScreenscore(screenscore);
					}
				}, 40);


			},			
			
			hideScreenscore: function(link)
			{
				Core.removeEventListener(link, 'click', Screenscore.openScreenscoreWindow);
				var body = document.getElementsByTagName('body');
				if (body[0]._screenscore)
				{
                    body[0].removeChild(body[0]._screenscore);
                    body[0]._screenscore = null;		
				}
				
			},
			toggleScreenscores: function() 
			{
				var si = Core.getElementsByClassName('screenscoreIcon', 'img');
				var st = Core.getElementsByClassName('screenscoreText', 'div');		
				for(var i=0;i<si.length; i++)
				{
					Core.toggleClass(si[i], 'noShow');
					Core.toggleClass(st[i], 'noShow');
				}
				Ajax.post('screenscoreDisplayStatus.php');
			}			
		};
					
		
		
		var Flyopen =
		{
			init: function(theClass, theOnEvent, theOffEvent) 
			// adds listeners to all elements with class = theClass 
			// url = the relative url of the backend php service page
			{
				if(arguments[3])
				{
					// optional tagName to restrict
					var theTag = arguments[3];
					var links =  Core.getElementsByClassName(theClass, theTag);
				}
				else
				{
					var links =  Core.getElementsByClassName(theClass);
				}
				
				for(var j=0; j < links.length; j++) {
                   Core.addEventListener(links[j], theOnEvent, Flyopen.showFlyopenListener);
                   Core.addEventListener(links[j], theOffEvent, Flyopen.hideFlyopenListener);
				}				
			},
			showFlyopenListener: function(event)
			{
				Flyopen.showFlyopen(this, event);
				Core.preventDefault(event);
			},

			hideFlyopenListener: function(event)
			{
				var body = document.getElementsByTagName('body');
				clearTimeout(body[0]._timer);
				Flyopen.hideFlyopen(this);
			},	
			
			showFlyopen: function(link, event)
			{
				
				if(document.getElementById('flyopen')) return;  // only one at a time!
				var body = document.getElementsByTagName('body');
				var flyopen = document.createElement("span");
				var temp = link.id.split(/_/g);
				var flyname = temp[0]; // the name of this flyopen series must precede the underscore
				var elementid = temp[1]; // the id of the trigger element must follow the underscore
				
				flyopen.id='flyopen';
				flyopen.className += " flyopen invisible";
				body[0].appendChild(flyopen);
				body[0]._flyopen = flyopen;
				body[0]._cursorX = Viewport.getCursorPosition(event).x;
				body[0]._cursorY = Viewport.getCursorPosition(event).y;
				body[0]._availableY = Viewport.viewport(event)[1] - Viewport.whereOnViewport(event)[1] - 30;
				body[0]._availableX = Viewport.whereOnViewport(event)[0];
				

				body[0]._timer = setTimeout(function() 
				{				
                    
                    flyopen.innerHTML = "<p class='bold'><img id='flyopenIcon' src='images/waitingAnimSmall.gif'>&nbsp;Loading&hellip;</p>";						
                    Flyopen.positionFlyopen(link, flyopen, body[0]._cursorX, body[0]._cursorY, body[0]._availableX, body[0]._availableY);
					Core.removeClass(flyopen, "invisible");
                    var ajaxRequest = Core.getHTTPObject();
     			
     				if(ajaxRequest) 
     				{
     					ajaxRequest.onreadystatechange = function()
     					{
     						if(ajaxRequest.readyState == 4) {
     							if(ajaxRequest.status == 200) {
     								// response body contains formatted flyopen text
     								var responseText = ajaxRequest.responseText;
     								if(responseText !="") {
     									// retrieve flyopen for the category stored in the id - assumes only one identical flyopenlink per page!!
     									Core.addClass(flyopen, 'invisible'); // hide until positioned
     									if(responseText.replace(/(\<(\w+|\/\w+).*?\>)|(\s{2,})/g,'').length > 5000) // length without tags 
     									{
     										var flyopenText = responseText.match(/.{0,5000}\b/) + "&hellip; <b>more</b></div>";
     									}
     									else 
     									{
     										var flyopenText = responseText; 
     									}
     									flyopen.innerHTML = flyopenText;									
     									if(document.getElementById('flyopen')) document.getElementById('flyopen').style.opacity = 0;														
     									Flyopen.positionFlyopen(link, flyopen, body[0]._cursorX, body[0]._cursorY, body[0]._availableX, body[0]._availableY);
     									Flyopen.revealFlyopen(flyopen);				
     								}
     							}
     							
     						}
     					}
     
     					// build search string for POST
     
     					var searchString = "name=" + flyname + "&id=" + elementid + "&ppt=4rt5q";     
     					ajaxRequest.open("POST", 'flyopenLoad.ajax.php', true);
     					ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     					ajaxRequest.send(searchString);
     				}
				}, 800);			
			},		
			
			positionFlyopen: function(link, flyopen, cursorX, cursorY, availableX, availableY) {
				// position flyopen 
				var flyopenHeight = flyopen.offsetHeight;
				var flyopenWidth = flyopen.offsetWidth;
				
				if(availableY > flyopenHeight) var offsetTop = cursorY ;
				else var offsetTop = cursorY - flyopen.offsetHeight + availableY - 5; // don't go off the bottom

				if((availableX + flyopenWidth + 10) > Viewport.viewport()[0]) var offsetLeft = cursorX - flyopenWidth - 10 ;
				else	var offsetLeft = cursorX + 10; // don't go off the RHS

				flyopen.style.top = offsetTop + 'px';
				flyopen.style.left = offsetLeft + 'px';

			},

			revealFlyopen: function(flyopen) {
				Core.removeClass(flyopen, 'invisible');	
				var doItAgain = false;
				this._timer = setTimeout(function()
				{
					if(document.getElementById('flyopen')) {
						var t = document.getElementById('flyopen');
						if(t.style.opacity) {
                              t.style.opacity = String(parseFloat(t.style.opacity) + 0.075);
                              if(parseFloat(t.style.opacity) < 0.99) doItAgain = true;
						}
/*
						else {
							// alpha for that SOB IE -> ignored because it spoils appearance (? no cool-type)
							alpha = parseInt(t.style.filter.slice(t.style.filter.search(/\d+/), t.style.filter.search(/\)/)));
							alpha +=5;
							t.style.filter = 'alpha(opacity=' + alpha + ')';
							if(alpha < 99) doItAgain = true;
						}
*/
						if(doItAgain) Flyopen.revealFlyopen(flyopen);
					}
				}, 40);


			},			
			
			hideFlyopen: function(link)
			{
				var body = document.getElementsByTagName('body');
				if (body[0]._flyopen)
				{
                    body[0].removeChild(body[0]._flyopen);
                    body[0]._flyopen = null;		
				}
				
			}

		};
					



					
		// Again courtesy of those lovely dudes at SitePoint - thanks Kev & Cam - d'ya like the changes?
		var Tooltips =
		{
			init: function() 
			// if no arguments, adds listeners to all <a> tags 
			// otherwise also add listeners to elements with tagnames in argument list that have class ='link'
			{
				var links = new Array;
				if(arguments.length == 0)  links[0] = document.getElementsByTagName("a");
				else {
					links[0] = document.getElementsByTagName("a");
					for(i=0; i<arguments.length; i++) {
						links[i +1] = Core.getElementsByClassName("link", arguments[i]);
					}						
				} 
				for(var j=0; j < links.length; j++) {
					// iterate the links for each tag in the argument list 
                    for (var i = 0; i < links[j].length; i++){
                    	var title = links[j][i].getAttribute("title");
                    	if (title && title.length > 0) { 
                              Core.addEventListener(links[j][i], "mouseover", Tooltips.showTipListener);
							Core.addEventListener(links[j][i], "mouseout", Tooltips.hideTipListener);
                    	}
					}
				}				
			},

			positionTip: function(link, tip, event) {
				// position the tooltip
				var tipHeight = tip.offsetHeight;
				var tipWidth = tip.offsetWidth;
				var availableBelowCursor = Viewport.viewport(event)[1] - Viewport.whereOnViewport(event)[1];
				if(availableBelowCursor > tipHeight) var offsetTop = Viewport.getCursorPosition(event).y - 40 ;
				else var offsetTop = Viewport.getCursorPosition(event).y - tip.offsetHeight + availableBelowCursor - 40; // don't go off the bottom
				var glurk = Viewport.viewport()[0];
				if((Viewport.whereOnViewport(event)[0] + tipWidth + 10) > Viewport.viewport()[0]) var offsetLeft = Viewport.getCursorPosition(event).x - tipWidth -5 ;
				else	var offsetLeft = Viewport.getCursorPosition(event).x + 10; // don't go off the RHS

				tip.style.top = offsetTop + 'px';
				tip.style.left = offsetLeft + 'px';
				tip.style.height = '1px';

			},

			revealTip: function(tip) {
				Core.removeClass(tip, 'invisible');
				var doItAgain = false;


				this._timer = setTimeout(function()
				{
					if(document.getElementById('tip')) {
						var body = document.getElementsByTagName('body');
											
                              tip.style.opacity = String(parseFloat(tip.style.opacity) + 0.055);
							tip.style.height = Math.min(body[0]._tooltipScrollheight, (tip.offsetHeight + 1)) + 'px';

                              if(
								(parseFloat(tip.style.opacity) < 0.99)
								||
								(tip.offsetHeight < body[0]._tooltipScrollheight)
							) 
							{
								doItAgain = true;
							}
						if(doItAgain) Tooltips.revealTip(tip);
						else {
							// tweak it to make FF display rounded corners correctly
							tip.style.left = (tip.offsetLeft +1) + 'px';
							tip.style.left = (tip.offsetLeft -1) + 'px';
						}
					}
				}, 40);
			},


			showTip: function(link, event)
			{

				Tooltips.hideTip(link);
				if(link.getAttribute("title").length <=0) return ; // don't show emptied tips
				var body = document.getElementsByTagName('body');
				
				var tip = document.createElement("span");
				tip.id='tip';
				tip.className += " tooltip noPrint ";

				var tipText = document.createTextNode(link.getAttribute("title"));

				tip.appendChild(tipText);
				if(tip.innerHTML) {
					tip.innerHTML = tip.innerHTML.replace(/\&lt\;/gi, "<").replace(/\&gt\;/gi, ">");
				}
				Core.addClass(tip, 'invisible'); // hide until positioned
				body[0].appendChild(tip)
				body[0]._tooltip = tip;
				body[0]._tooltipText = link.title;
				body[0]._tooltipScrollheight = tip.scrollHeight;
				link.title = "";
				tip.style.opacity = .1;
				Tooltips.positionTip(link, tip, event);
				setTimeout(function(){Tooltips.revealTip(tip)}, 400);

			},

			hideTip: function(link)
			{
				var body = document.getElementsByTagName('body');
				if (body[0]._tooltip)
				{
					// restore the title attribute
					body[0].removeChild(body[0]._tooltip);
					link.title = body[0]._tooltipText
					// clean up
					body[0]._tooltip = null;
					body[0]._tooltipText = null;
					body[0]._tooltipScrollheight = null;					

				}
			},

			showTipListener: function(event)
			{
				Tooltips.showTip(this, event);
				Core.preventDefault(event);
			},

			hideTipListener: function(event)
			{
				//clearTimeout(this._timer);
				Tooltips.hideTip(this);
			}
		};

		// Core.start(Tooltips); - start this explicitly for each required page

		
// Test the viewport ... with thanks to www.quirksmode.org
var Viewport =
		{
		viewport: function() {
			if (self.innerHeight) // all except Explorer
			{
				x = self.innerWidth;
				y = self.innerHeight;
			}
			else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
			{
				x = document.documentElement.clientWidth;
				y = document.documentElement.clientHeight;
			}
			else if (document.body) // other Explorers
			{
				x = document.body.clientWidth;
				y = document.body.clientHeight;
			}
			return new Array(x,y);
		},

		getPos: function(obj)
		{
			var curleft = curtop = 0;

			if (obj.offsetParent) {
				do {
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;	
				} while (obj = obj.offsetParent);
			}
			return new Array(curleft,curtop);
		},

		// Scrolling offset -> How much the page has scrolled.
		scroll: function() {
			if (self.pageYOffset) // all except Explorer
			{
				x = self.pageXOffset;
				y = self.pageYOffset;
			}
			else if (document.documentElement && document.documentElement.scrollTop)
			// Explorer 6 Strict
			{
				x = document.documentElement.scrollLeft;
				y = document.documentElement.scrollTop;
			}
			else if (document.body) // all other Explorers
			{
				x = document.body.scrollLeft;
				y = document.body.scrollTop;
			}
			return new Array(x,y);
		},
		

	whereOnViewport: function(e) 
	{
		// where (wrt the visible viewport) did this event occur
		eventOffsetX = Viewport.getCursorPosition(e).x;
		eventOffsetY = Viewport.getCursorPosition(e).y;		
		//alert(p + " / " + s);
		
		return new Array(eventOffsetX-Viewport.scroll()[0], eventOffsetY-Viewport.scroll()[1]);
	},


     getCursorPosition: function (e) {
          e = e || window.event;
          var cursor = {x:0, y:0};
          if (e.pageX || e.pageY) {
               cursor.x = e.pageX;
               cursor.y = e.pageY;
          }
          else {
          var de = document.documentElement;
          var b = document.body;
          	cursor.x = e.clientX +
          	(de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
          	cursor.y = e.clientY +
          	(de.scrollTop || b.scrollTop) - (de.clientTop || 0);
          }
          return cursor;
     },
		
		slideWindow: function(yPos, yStop, yDirection, delay, init) {
				// slide the viewport quickly at first -> slowly
			
				var yStep, pos;
				if(typeof(delay) === 'undefined') delay = 10;
				if(typeof(init) === 'undefined') init = 5;
				function slide()
				{
					yStep = Math.max(Math.abs(yPos - yStop)/init, 1);
                    setTimeout(function () 
					{
						yPos = yPos + (yDirection * yStep);
                         window.scrollTo(0, yPos);
                         pos = Math.abs(yPos - yStop);
                         if(
                         	
                         	(pos> init)
                         	&&
                         	(yPos > 0)
                         )
                         {
                         	slide();
                         }
                    
					}, delay);
				}
				slide();			
		},
			
		innerWindow: function() {
               var xy = new Array();
               if (self.innerHeight) // all except Explorer
               {
               	xy[0] = self.innerWidth;
               	xy[1] = self.innerHeight;
               }
               else if (document.documentElement && document.documentElement.clientHeight)
               	// Explorer 6 Strict Mode
               {
               	xy[0] = document.documentElement.clientWidth;
               	xy[1] = document.documentElement.clientHeight;
               }
               else if (document.body) // other Explorers
               {
               	xy[0] = document.body.clientWidth;
               	xy[1] = document.body.clientHeight;
               }
				return xy;		
		}, 
			
		pageOffset: function () {
               var xy = new Array();
               if (self.pageYOffset) // all except Explorer
               {
               	xy[0] = self.pageXOffset;
               	xy[1] = self.pageYOffset;
               }
               else if (document.documentElement && document.documentElement.scrollTop)
               	// Explorer 6 Strict
               {
               	xy[0] = document.documentElement.scrollLeft;
               	xy[1] = document.documentElement.scrollTop;
               }
               else if (document.body) // all other Explorers
               {
               	xy[0] = document.body.scrollLeft;
               	xy[1] = document.body.scrollTop;
               }		
				return xy;	
		},
		
		
		insertAtCursor: function (myField, myValue) {
			if(
				(myField)
				&&
				(
					(myField.type == 'text')
					||
					(myField.type == 'textarea')
				)
			)
			{
				//ie support
				if (document.selection) 
				{
					myField.focus();
					sel = document.selection.createRange();
					sel.text = myValue;
				}
				//mozilla/netscape support
				else if (myField.selectionStart !== false) 
				{
					var startPos = myField.selectionStart;
					var endPos = myField.selectionEnd;
					myField.value = myField.value.substring(0, startPos)
						+ myValue
						+ myField.value.substring(endPos, myField.value.length);
				} 
				else 
				{
					myField.value += myValue;
				}
			}
		}
};

var Table =
{
		highlight: function() 
		{
			if(arguments[0])
			{
				var theClass = arguments[0]; 
			}
			else
			{
				var theClass = 'highlight';
			}
			if(arguments[1])
			{
				var theTag = arguments[1]; 
			}
			else
			{
				var theTag = 'tr';  
			}
			var tr = document.getElementsByTagName(theTag);
			for(var i=0; i< tr.length; i++) 
			{
				if(!Core.hasClass(tr[i], 'noHighlight')) 
				{
					Core.addEventListener(tr[i], 'mouseover', function() {Core.addClass(this, theClass)})
					Core.addEventListener(tr[i], 'mouseout', function() {Core.removeClass(this, theClass)})
				}
			}
		}
};		
		


var LiveHelp = { 
		
		init: function () {
			if(document.getElementById('liveHelp')) {
               var liveImage = document.getElementById('liveImg');	
				if(liveImage.width > 171) return; // we sense online/offline by making the custom offline image a few pixels wider
               window._imageWidth = liveImage.width; // a global			   
               Core.addEventListener(document.getElementById('offlineHelp'), 'mouseover', LiveHelp.show);
               Core.addEventListener(document.getElementById('offlineHelp'), 'mouseout', LiveHelp.hide);
               document.getElementById('liveHelp').style.filter = 'alpha(opacity = 85)';

				var page = location.href.replace(/(^.*\/)|(\..*?$)/gi, ""); // parse -> the page name (without extension)
				var c = Cookies.get('polite');
				if(!c) c = "";
				if(c.indexOf(page) == -1) {
					// if this page is not listed in cookie as having been visited before -> auto-display live help
					window._timeout = setTimeout("LiveHelp.reveal('liveImg', 0.1, 30)", 3000);
					Cookies.put('polite', c + page + "|");					
				}
			}		
	},
		     	
     reveal: function (imageId, step, delay, shrink) {
			     
     	if(window._timeout && typeof(window._timeout !== 'undefined')) clearTimeout(window._timeout);
			
          // position the image before growing it
          var oH = document.getElementById('offlineHelp');
          var lH = document.getElementById('liveHelp');

			lH.style.right =  document.getElementsByTagName('html')[0].clientWidth - oH.offsetLeft - Math.ceil(oH.clientWidth/2) + 'px';
          lH.style.top = oH.offsetTop + Math.ceil(oH.clientHeight/2)  + 'px';
			lH.className = '';
						
     	// grow/shrink help image
     	var liveImage = document.getElementById(imageId);
     	var minImageWidth = Math.round(window._imageWidth  * step)+1;
			var maxImageWidth = Math.round(window._imageWidth  * 1.05);

     	if(typeof(shrink) == 'undefined' ) {
     			var initialWidth = Math.ceil(step * window._imageWidth );
     			var i = 1 + step;
					var finalState = '';
					liveImage.className =  '';
     	}
     	else {
     			var initialWidth = window._imageWidth ;	
     			i = 1 - step;
					var finalState = ' noShow ';
     	}
     	liveImage.width = initialWidth;
     	function growIt() {
     			window._timeout = setTimeout(function () {
     				liveImage.width = Math.round(liveImage.width*i);
     				if((liveImage.width > minImageWidth) && (liveImage.width < window._imageWidth )) growIt();
						else {
							liveImage.className =  finalState;
							if(finalState == '') window._timeout = setTimeout('LiveHelp.reveal("liveImg", 0.1, 30, 1)', 3000);
							liveImage.width = window._imageWidth ;							
						}
     			},
     			delay); 
     	}
     	growIt();
     },
		
		show: function() {
			LiveHelp.reveal('liveImg', 0.2, 30);
		},
		
		hide: function() {
			LiveHelp.reveal('liveImg', 0.15, 30, 1);
		}


};		
Core.start(LiveHelp);

var Cookies = {
	
	get: function(name) {
			var s = name + "="
   			if (document.cookie.length > 0) { // if there are any cookies
      		var offset = document.cookie.indexOf(s) 
      		if (offset != -1) { // if cookie exists 
         			offset += s.length 
         			// set index of beginning of value
         			end = document.cookie.indexOf(";", offset) 
         			// set index of end of cookie value
         			if (end == -1) end = document.cookie.length;
         			return unescape(document.cookie.substring(offset, end))
      		}
				else return false; 
   			}
			else return false;
	},
	
		put: function (name, value, expire) {
			document.cookie = name + "=" + value + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
		}


};

var Server = {
	init: function() {
			Server.keepAlive();
	},
	
	keepAlive: function() {
     		setTimeout(function() {
     			var ajaxRequest = Core.getHTTPObject();
     			if (ajaxRequest) {
     				ajaxRequest.onreadystatechange = function()
     				{
     					if(ajaxRequest.readyState == 4) {
     						if(ajaxRequest.status == 200) {
     							responseText = ajaxRequest.responseText;
     							if(responseText != '') {
     								Server.keepAlive()
     							}
     						}
     					}
     				}
     			}
     			//ajaxRequest.open("GET", "keepAlive.php", true);
					var searchString = "ppt=1";     
					ajaxRequest.open("POST", "keepAlive.php", true);
					ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					ajaxRequest.send(searchString);
     		}, 600000);
	}
};
Core.start(Server);

var Ajax = {
	
	 // a general Ajax (post) call where url is the url of the called page 
	 // and subsequent arguments (of the form arg=value) are assembled into the search string
	 // the [optional] response can be loaded into a DOM element or saved in a body._ variable on the calling page
	 // a flag is set in body._ajaxDone when the call is complete
	post: function(url) 
	{
		var searchString = "ppt=5gDq1";
		for(var i=1; i < arguments.length; i++)
		{
			// construct a search string
			searchString += "&" + arguments[i];
		}
		
		var ajaxRequest = Core.getHTTPObject();
		if (ajaxRequest) {
			ajaxRequest.onreadystatechange = function()
			{
				if(ajaxRequest.readyState == 4) {
					if(ajaxRequest.status == 200) {
						responseText = ajaxRequest.responseText;
						if(responseText != '') 
						{
							//some response text has been returned 	
							if(responseText.substr(0,7) == 'target=')
							{	// the response text begins with 'target=' -> there is a target id -> extract it
								// parse the responseText for a target element id to insert the remainder of the response into
								// string must be 'target=xxx;' where xxx is the id of the target element and is terminated with a ';'
								targetElementId = responseText.substr(7, (responseText.indexOf(';')) - 7);
								insertText = responseText.substr(responseText.indexOf(';') +1);
								if(document.getElementById(targetElementId))
								{
									// the target exists
									document.getElementById(targetElementId).innerHTML = insertText;
									document.getElementsByTagName('body')[0]._ajaxDone = true; // flag it's done
								}								
							}
							else if(responseText.substr(0,5) == 'save=')
							{
								// the responsetext begins with 'save='
								// save it into a variable in the page body
								document.getElementsByTagName('body')[0]._ajaxDone = true; // flag it's done
								document.getElementsByTagName('body')[0]._ajaxResponseBody = responseText.substr(responseText.indexOf('=') + 1); // save the response
							}
							else if(responseText != 1)
							{
								// else if other than true or '1'
								// the responseText is to be treated as a function name to execute
								responseText;
							}
						}					
					}
					else
					{
						// no response -> fail
						 alert('We are sorry.\n\nYour Internet connection was interrupted.\n\nPlease try again.\n\n');
					}						
				}
			}
		}
    
		ajaxRequest.open("POST", url, true);
		ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajaxRequest.send(searchString);

	},
	
	wait: function(theFunction)
	{
		// waits for Ajax.post to flag it's done
		this._timer = setTimeout
		(
			function()
			{	
				if(document.getElementsByTagName('body')[0]._ajaxDone)
				{
					document.getElementsByTagName('body')[0]._ajaxDone = false;
					theFunction();
				}
				else
				{
					Ajax.wait(theFunction);
				}
			}
			
			, 300
		);
	},
	
	waitFor: function(theId, theFunction)
	{
		// waits for DOM element theId -> the executes theFunction
		this._timer = setTimeout
		(
			function()
			{	
				if(document.getElementById(theId))
				{
					theFunction(theId, theFunction);
				}
				else
				{
					Ajax.waitFor(theId, theFunction);
				}
			}
			
			, 300
		);
	},
	
	waitUntil: function(theId, theFunction)
	{
		// waits for DOM element theId to disappear -> then executes theFunction
		this._timer = setTimeout
		(
			function()
			{	
				if(!document.getElementById(theId))
				{
					theFunction(theId, theFunction);
				}
				else
				{
					Ajax.waitFor(theId, theFunction);
				}
			}
			, 300
		);
	}
};


var Popup = {
	open: function(url) {
			var chrome = '';
			if(arguments[1]) var name = arguments[1]; else var name = 'popup';
			if(arguments[2]) chrome += 'width=' + arguments[2];
			if((arguments[2]) && (arguments[3])) chrome += ",";
			if(arguments[3]) chrome += 'height=' + arguments[3];
			if(arguments[4]) {
				if(arguments[4] === true) chrome += ',scrollbars=yes,resizable=yes'; 
				else chrome += ',' + arguments[4]; 
			}
     	window.open(url, name, chrome);
	},
	exportData: function(dataId)
	{
		// dataId is the id of the DOM element containing the data
		
		var data = document.getElementById(dataId).innerHTML;	
		
		//data = data.replace(/\&\w+\;/gi, ''); // remove other html entities
		data = data.replace(/\t/gi, ''); // remove tabs
		data = data.replace(/\<img\s.*?alt\s*\=\W*?([\w\-]+)(\W*?).*?\>/gi, '$1'); // remove img tag except the content of the alt attribute
		data = data.replace(/\,/gi, "",""); // surround commas with "" 
		data = data.replace(/\s*?\<\/td.*?\>/gi, ','); // replace </td> with comma
		data = data.replace(/<\/th.*?\>/gi, ','); // replace </th> with comma
		data = data.replace(/\r|\n/gi, ''); // remove newlines
		data = data.replace(/<\/tr.*?\>/gi, '~~~'); // placeholder for a line break
		data = data.replace(/\&amp\;/gi, '&'); // preserve/translate &amp;
		data = data.replace(/\&\w*?;/gi, ''); // remove html entities
		data = data.replace(/(^\s*?,|\s*?,$)/gi, ''); // trim leading comma+space or trailing comma
		

		data = escape(data);
		var body = document.getElementsByTagName('body');
		var d = document.createElement('div');
		d.innerHTML = "<form name='exportData' action = 'exportData.php' method='POST'>"
			+ "<input name='data' value ='" + data + "'>"
			+ "<input name='id' value = '" + dataId + "'>"
			+'</form>'			
		body[0].appendChild(d);

		document.exportData.data.value = data;
		document.exportData.id.value = dataId;			
		document.exportData.submit();

		d.parentNode.removeChild(d);
		d=null;
	},
	
	alertOpen: function(text)
	{
		// opens an alert overlay panel as child of element body
		if(document.getElementById('popupAlertOverlay'))
		{
			Core.discardNode("popupAlertOverlay");
		}
		var target = document.createElement('div');
		target.id = 'popupAlertOverlay';
		target.className = 'noShow';
		Core.addEventListener(target, 'click', Popup.alertClose);
		var r = Math.round(Math.random());
		if(r)
		{
			var iSrc = 'images/gotchaTalkingHeadFemale.gif';
			
		}
		else
		{
			var iSrc = 'images/gotchaTalkingHeadMale.gif';
		}
		target.innerHTML = "<p class='floatRight clearRight'>"
			+ '<img src="'
			+ iSrc
			+ '">'
			+ "</p>"
			+ text
			+ "<p class='small footer'>Please click anywhere within to close this message panel</p>"
		;
		var s = Viewport.scroll();
		var h = Viewport.viewport()
		target.style.top = Math.round(s[1]) + Math.round(h[1]/2) + 'px';
		document.body.appendChild(target);
		Slide.open(target);
	},
	alertClose: function(e)
	{
		if(document.getElementById('popupAlertOverlay'))
		{
			Slide.closed(document.getElementById('popupAlertOverlay'))
			Slide.wait(function()
				{
					Core.discardNode('popupAlertOverlay');
				}
			)
		}
	},
	panelOpen: function(text)
	{
		// opens an overlay panel as child of element body
		// second [optional] argument specifies an alternative element 
		if(document.getElementById('popupPanelOverlay'))
		{
			Core.discardNode("popupPanelOverlay");
		}
		var target = document.createElement('div');
		target.id = 'popupPanelOverlay';
		target.className = 'noShow';
		Core.addEventListener(target, 'click', Popup.alertClose);
		var r = Math.round(Math.random());
		if(r)
		{
			var iSrc = 'images/gotchaTalkingHeadFemale.gif';
			
		}
		else
		{
			var iSrc = 'images/gotchaTalkingHeadMale.gif';
		}
		target.innerHTML = "<p class='floatRight clearRight'>"
			+ '<img src="'
			+ iSrc
			+ '">'
			+ "</p>"
			+ text
		;
		var s = Viewport.scroll();
		var h = Viewport.viewport()
		target.style.top = Math.round(s[1]) + Math.round(h[1]/3.3) + 'px';
		if(
			(arguments[1])
		)
		{
			arguments[1].appendChild(target);
		}
		else
		{
			document.body.appendChild(target);
		}
		Slide.open(target);
	},
	panelClose: function(e)
	{
		if(document.getElementById('popupPanelOverlay'))
		{
			Slide.closed(document.getElementById('popupPanelOverlay'))
			Slide.wait(function()
				{
					Core.discardNode('popupPanelOverlay');
				}
			)
		}
	},
	panelOpenAjax: function(selector, id)
	{
		// opens an overlay panel as child of element body whose contents are supplied from backend
		// third [optional] argument specifies an alternative element 
		if(document.getElementById('popupAjaxOverlay'))
		{
			Core.discardNode("popupAjaxOverlay");
		}
		var target = document.createElement('div');
		target.id = 'popupAjaxOverlay';
		target.className = '$noShow';
		target.innerHTML='<img src="images/waitingIcon.gif">';
		Core.addEventListener(target, 'click', Popup.alertClose);
		Ajax.post('panelLoad.ajax.php', 'id=' + id, 'selector=' + selector);
		var s = Viewport.scroll();
		var h = Viewport.viewport()
		target.style.top = Math.round(s[1]) + Math.round(h[1]/3.3) + 'px';
		if(
			(arguments[2])
		)
		{
			arguments[2].appendChild(target);
		}
		else
		{
			document.body.appendChild(target);
		}		
		Ajax.wait(function()
			{

				Slide.open(target);
			}
		)


	},
	panelCloseAjax: function(e)
	{
		if(document.getElementById('popupAjaxOverlay'))
		{
			Slide.closed(document.getElementById('popupAjaxOverlay'))
			Slide.wait(function()
				{
					Core.discardNode('popupAjaxOverlay');
				}
			)
		}
	}	
};
	
var Form = {
	limitLength: function(i, len)
	{
		// limit input element length
		if(i.value.length>len) this.value = this.value.substr(0,len)
	},
	testRadioButtonValue: function(target, value) 
	{
			// returns true if the element in a radio button array whose name=target is checked 
          var r = document.getElementsByTagName('input');
          for(var i = 0; i < r.length; i++)
          {
               if(r[i].name == target) 
               {
               	if(
               		(r[i].value == value)
               		&&
               		(r[i].checked)
               	)
               	{
               		 return true;
               	}
               }
          }
          return false;   
	},
	
	radioButtonValue: function(target) {
			// returns the value of element in a radio button array that  is checked 
          var r = document.getElementsByTagName('input');
          for(var i = 0; i < r.length; i++)
          {
               if(r[i].name == target) 
               {
               	if(r[i].checked)
               	{
               		 return r[i].value;
               	}
               }
          }
          return false;   
	},
	
	setRadioButtonValue: function(target, value)
	{
		// sets the value of radioButton array 'target' whose value is 'value'
          var r = document.getElementsByTagName('input');
          for(var i = 0; i < r.length; i++)
          {
               if(r[i].name == target) 
               {
               	if(r[i].value == value)
               	{
               		 r[i].checked = true;
               	}
               }
          }
          return false;   
	},	
	
	checkboxesEmpty: function(c) {
	// scans an array of checkboxes and returns true if all are unchecked 
	  for(var i = 0; i < c.length; i++)
	  {
		   if(c[i].checked) 
		   {
		   		return false;
		   }
	  }
	  return true;   
	},
	
	clearElements: function(el)
	{
		// clears all elements (el)
		for(var i=0; i<el.length; i++)
		{
			if(el[i].checked)
			{
				el[i].checked = false;
			}
			if(el[i].value)
			{
				el[i].value = '';
			}
		}
	},
	
	clearElementsByClassName: function(theClass)
	{
		// clears all input elements having className = 'theClass'
		var el = Core.getElementsByClassName(theClass, 'input');
		Form.clearElements(el);
	},
	
	adjustTextareaHeightById: function(textareaId)
	{
		// adjust height of a textarea element whose id = textareaId to suit original contents -> no scroll bar
		if(!document.getElementById(textareaId)) return false; // no such textarea
		var t = document.getElementById(textareaId);
		var actualHeight = t.offsetHeight;
		var scrollHeight = t.scrollHeight;
		if(scrollHeight > actualHeight) 
		{
			t.style.height =  scrollHeight + Math.round(scrollHeight/10) + 'px'; 
			return true; // an adjustment was made
		}
		else return false; // no adjustment was made
	},	
	
	adjustTextareaHeight: function(t)
	{
		// adjust height of a textarea element to suit contents -> no scroll bar
		var actualHeight = t.offsetHeight;
		var scrollHeight = t.scrollHeight;
		if(scrollHeight > actualHeight) 
		{
			t.style.height =  scrollHeight + Math.round(scrollHeight/7) + 'px'; 
			return true; // an adjustment was made
		}
		else return false; // no adjustment was made
	},		
	
	growTextarea: function(e)
	{
		// listener -> calls adjustTextAreaHeight
		// where e is the event
		if(e.target)
		{
			var eT = e.target;
		}
		else if(e.srcElement)
		{
			var eT = e.srcElement;
		}
		Form.adjustTextareaHeight(eT)
	},
	
	setTextareaHeights: function()
	{
		// sets heights of text areas to suit initial contents
		var t = document.getElementsByTagName('textarea');
		for(var i=0; i<t.length; i++)
		{
			if(arguments[0]) // optional argument = className to be required
			{
				if(Core.hasClass(t[i], arguments[0]))
				{
					Form.adjustTextareaHeight(t[i]);
				}
			}
			else
			{
				Form.adjustTextareaHeight(t[i]);
			}
		}
	},
	
	dynamicTextareaHeights: function()
	{
		// set text areas to automtically expand as filled
		var t = document.getElementsByTagName('textarea');
		for(var i=0; i<t.length; i++)
		{
			if(arguments[0]) // optional argument = className to be required
			{
				if(Core.hasClass(t[i], arguments[0]))
				{
					Core.addEventListener(t[i], 'keyup', Form.growTextarea);
				}
			}
			else
			{
				Core.addEventListener(t[i], 'keyup', Form.growTextarea);
			}
		}		
	},
	
	toggleTextarea: function(e)
	{
		// alternates a textarea and formatted text in place
		
	},
	
	limitLength: function(el, limit)
	{
		// limit length of form element el to limit

		if(el.value.length > limit)
		{
			el.value = el.value.substr(0,limit)
		}
	},
	
	validateField: function (theField, theRegExp, theClass) 
	{
		// validates input (field) against regExp (r) and adds class (c) to parent if no match
		if(
			(typeof(theField) == 'undefined')
			||
			(!theField.parentNode)
		)
		{
			return true;
		}
		if(typeof(theClass) == 'undefined') theClass = 'error'; 
		if(typeof(theField.value) == 'undefined') 
		{
			theField.value = ''
		}
		else
		{
			theField.value = theField.value.replace(/^\s+|\s+$/g, ''); // trim leading and trailing spaces
		}
		this.value = theField.value;
		var r = theRegExp.test(theField.value)
		if(r) 
		{
			Core.removeClass(theField.parentNode, theClass);
			Core.removeClass(theField.parentNode, 'alert'); // this is the class inserted when the user tries to submt a dud form
		}
		else 
		{
			Core.addClass(theField.parentNode, theClass);
		}
		return r
	},
	
	cleanUpPhone: function(p) 
	{
		p.value = p.value.replace(/^ *| *$/g, ""); // trim
		p.value = p.value.replace(/(\-|\(|\))/g, " "); // replace any - ( ) with space
		p.value = p.value.replace(/(  )+?/g, " "); // remove any resulting double spaces
		
	},
	
	cleanUpEmail: function(e)
	{
		e.value = e.value.replace(/ /g, "").replace(/,/g,".");
	},
	
	trim: function(f)
	{
		f.value = f.value.replace(/^\s|\s$/g, '');
	}
	
};
	
var Slide = {
	
	init: function(e) 
	{
		document.body._slide = 0;
		var c = Core.firstChildTag(e); 
		if(!Core.hasClass(c, 'slideWrapper'))  
		{
			e.innerHTML = "<div class='slideWrapper'>" + e.innerHTML + "</div>"; // add a wrapper if it's not already there - nicer with DOM but how??
		}
	},

	open: function(e) {	
		// slide open DOM element 'e',
		if(!Core.hasClass(e, 'noShow'))
		{
			return; // already open!
		}
		Slide.init(e); 
		var body = document.body;			
		var c = e.childNodes;
		for(var i = 0; i < c.length; i++)
		{
			if(c[i].nodeType==1)
			{
				if(Core.hasClass(c[i], 'slideWrapper')) 
				{
					var w = c[i];
				}
				else var w = false;
			}
		}
		Core.addClass(w, 'invisible');
		w.style.overflow = 'hidden';
		Core.removeClass(e, 'noShow');	
		Core.removeClass(w, 'noShow');
		body._slideHeight = w.scrollHeight;												    
		w.style.height = '1px';
		e.style.opacity = 0;	
		Core.removeClass(w, 'invisible');				
		Slide.show(e);
	},
	
	show: function(e) {
          this._timer = setTimeout(function()
               {
                    var body = document.body;
					var w = Core.firstChildTag(e); 
                    e.style.opacity = Math.min(1, String(parseFloat(e.style.opacity) + 0.04));
                    w.style.height = Math.min(body._slideHeight, (w.offsetHeight + Math.ceil(body._slideHeight/15))) + 'px';								
                    if(
                         (parseFloat(e.style.opacity) < 0.99)
                         ||
                         (w.offsetHeight < document.body._slideHeight)
                    ) 
                    {
                    	Slide.show(e);
					}
                    else {
						w.style.height = 'auto'; //body._slideHeight + 'px';	
						setTimeout(function()
							{
							Core.toggleClass(w, 'shrink'); // force re-draw for IE6 display bug 
							Core.toggleClass(w, 'shrink');
						}, 200);
						document.body._slide = 1;
					}						
          	}, 20);					
	},
	
	closed: function(e) 
	{
		// slide closed DOM element 'e', 
		if(Core.hasClass(e, 'noShow')) return; // only if it's not already closed 		
		Slide.init(e); 	
		var w = Core.firstChildTag(e);
		document.body._slideHeight = w.scrollHeight;
		w.style.height = w.scrollHeight + 'px';			
		w.style.overflow = 'hidden';	
		Slide.hide(e);
	},
				
	hide: function(e) {						
	  this._timer = setTimeout(function()
		   {
				var w = e.firstChild;				
				var h = w.style.height.replace('px', "");
				
				h = Math.max(5, h -= Math.round(h/4));
				w.style.height = h + 'px';	
				if(h > 5){
					Slide.hide(e);
				}
				else 
				{
					Core.addClass(e, 'noShow');
					w.style.height = document.body._slideHeight + 'px';
					e.style.opacity = 0;
					document.body._slide = 2;					
				}									
		}, 30);					
	},
	
	toggle: function(e) {	
			if(Core.hasClass(e, 'noShow')) Slide.open(e);
			else if(!Core.hasClass(e, 'noShow')) Slide.closed(e);
	},
	
	wait: function(theFunction)
	{
		// waits for Slide to flag it's done
		this._wait = setTimeout
		(
			function()
			{	
				if(document.body._slide)
				{
					// open or close complete
					theFunction();
					this._wait = null;
				}
				else
				{
					Slide.wait(theFunction);
				}
			}
			
			, 300
		);
	}
	
};	




