var g_jsFile_events_js_firstLoad = (typeof(g_jsFile_events_js_firstLoad) == "undefined");
var g_jsFile_events_js = true;
var ___i = 0;

function setupDWR()
{
if (typeof(DWREngine) != "undefined")
{

DWREngine.setWarningHandler( function (warning)
{
dm("<span style='color: orange'>DWR Warning: " + warning + "</span>");
});

DWREngine.setErrorHandler(function (error)
{
if (error.name && error.message)
dm("<span style='color: red'>DWR Error ("+error.name+") " + 
error.sourceURL + ":" + error.line + " : " + error.message + "</span>");
else
dm("<span style='color: red'>DWR Error: " + error + "</span>");
});

DWREngine.setVerb("POST");
}
}

if (typeof(allowExit) == "undefined")
{
allowExit = true;
}

if (typeof(exitOK) == "undefined")
{
function exitOK()
{
return true;
}
}

if (typeof(g_objectRegistery) == "undefined")
{
g_objectRegistery = new Array;
g_onunloadQueue = new Array;

window.onunload = function(ev)
{
for (var i in g_onunloadQueue)
{
if (g_onunloadQueue[i])
{
g_onunloadQueue[i](getEvent(ev));
g_onunloadQueue[i] = null;
}
}

__runGC();
}
}

function gc()
{
if (typeof(document.all) == "undefined" || !document.all)
return;

for (var i=0; i<arguments.length; i++)
g_objectRegistery[g_objectRegistery.length] = arguments[i];
}

function __gcDumpString(obj)
{
if (typeof(obj) == "object")
return "Object(" + typeof(obj) + ")";
else if (typeof(obj) == "function")
{
var str = obj.toString();
str = escapeHTML(str.split("\n").join(" "));
str = escapeHTML(str.split("\r").join(""));
while (str.substring(0, 1) == " ")
str = str.substring(1, str.length);

if (str.substring(0, 8) == "function")
str = str.substring(8, str.length);

if (str.length > 50)
str = "<i>"+str.substring(0, 50)+"</i>...";
else
str = "<i>"+str+"</i>";



return "<span style='color: blue;'>function</span>"+str+"";
}
else if (typeof(obj) == "undefined")
return "[undefined]";

return "" + obj;
}

function dumpGC()
{
var str = "Garbage collection registry dump ("+g_objectRegistery.length+" objects): <br><ul>";

str += "<li><b>"+g_objectRegistery.length+" Object(s) registered with gc():</b><ul>";

for (var i=0; i<g_objectRegistery.length; i++)
str += "<li>" + __gcDumpString(g_objectRegistery[i]) + "</li>";

str += "</ul></li>";

str += "<li><b>"+g_globalObjects.length+" Object(s) registered with storeObject():</b><ul>";

for (var i=0; i<g_globalObjects.length; i++)
str += "<li>" + __gcDumpString(g_globalObjects[i]) + "</li>";

str += "</ul></li>";

str += "</ul>";

debugMessage(str);
}

function __gcObject(obj)
{
g_objectRegistery[i] = null;

if (typeof(obj) != "undefined" && obj != null)
delete obj;
else
return false;

obj = null;

return true;
}

function __runGC()
{
var count = 0;

if (typeof(document.all) == "undefined")
{
dm("Manual GC not needed");
return;
}

for (var i in g_objectRegistery)
count += __gcObject(g_objectRegistery[i]) ? 1 : 0;

for (var i in g_globalObjects)
count += __gcObject(g_globalObjects[i]) ? 1 : 0;

g_objectRegistery = new Array;
g_globalObjects = new Array;

dm("<b>Garbage Collector executed: " + count + " objects have been deleted</b>");
}


function runOnce(code)
{
if (g_jsFile_events_js_firstLoad)
{
code();
}
}



function init()
{
g_objData = new Array;
g_objsToStore = new Array;
g_pageName = "__unkownpage";


g_pageLoaded = false;


g_safariBrowser = navigator.userAgent.match(/Safari/i);


g_globalObjects = [];


g_requestHandlers = new Array();


g_mousePosition = null;
}


runOnce(init);



function isSafari()
{
return g_safariBrowser;
}


function isIE()
{
return (navigator.userAgent.indexOf('MSIE')!=-1);
}


function isPageLoaded()
{
return g_pageLoaded;
}


function isDebugMode()
{
return typeof(DEBUG) != "undefined" && DEBUG;
}


function getTime()
{
return (new Date).getTime();
}


function trim(str, chars)
{
if (typeof(chars) != "string")
chars = " \t\r\n";

return str.substr(0, str.length - str.match("(["+chars+"]*)$")[1].length).match("^["+chars+"]*(.*)")[1];
}


function translateDateYear(year)
{
if (translateDateYear.dateYearIsNotModdedAfter2000)
{
if (year < 100)
return 1900 + year;
return year;
}
else
return 1900 + year;
}
translateDateYear.dateYearIsNotModdedAfter2000 = new Date("1/1/3000").getYear() == 3000;



function trimLeft(str, chars)
{
if (typeof(chars) != "string")
chars = " \t\r\n";

return str.match("^["+chars+"]*(.*)")[1];
}


function trimRight(str, chars)
{
if (typeof(chars) != "string")
chars = " \t\r\n";

return str.substr(0, str.length - str.match("(["+chars+"]*)$")[1].length);
}

function defineClass()
{
for (var i=0; i<arguments.length; i++)
{
var classObject = arguments[i];
if (typeof(classObject) == "function")
classObject.prototype.className = classObject.TYPE = classObject.toString().match(/function ([a-zA-z_0-9]+)/)[1];
}
}


function extendClass(newClass, oldClass)
{
if (newClass.prototype && oldClass.prototype)
{
defineClass(oldClass, newClass);

for (var i in oldClass.prototype)
newClass.prototype[i] = oldClass.prototype[i];

newClass.prototype.getSuper = _getSuperClass;
newClass.prototype.callSuper = _callSuperMethod;

newClass.prototype.superClass = newClass.prototype._super = oldClass;
var superClasses = newClass.prototype.superClasses = new Object;

var curClass = oldClass;
while (curClass)
{
superClasses[curClass.className] = curClass;
curClass = curClass.prototype.superClass;
}
}
}


function userType(object)
{
if (typeof(object) != "undefined" && typeof(object["className"]) == "string")
return object["className"];

return typeof(object);
}


function _getSuperClass(name)
{
if (typeof(name) == "undefined" || !name)
return this.superClass;

return this.superClasses[name];
}

function _callSuperMethod(methodName)
{
this._tmpSuperMethod = this.superClass.prototype[methodName];
var result = null;

if (arguments.length == 1)
result = _doCallback(this, "_tmpSuperMethod", []);
else
{
var args = [];
for (var i=1; i<arguments.length; i++)
args[i-i] = arguments[i];

result = _doCallback(this, "_tmpSuperMethod", args);
}

return result;
}


function getElementsByTagNames(names)
{
var elems = [];
for (var i in names)
{
var es = document.getElementsByTagName(names[i]);
for (var j=0; j<es.length; j++)
elems[elems.length] = es[j];
}

return elems;
}


function setInputPeerValue(input, peerName, value)
{
var peer = input.form.elements[peerName];
if (peer)
{
peer.value = value;
return true;
}

return false;
}


function setElemOpacity(elem, opacity)
{
elem.style.opacity = opacity / 100;

elem.style.filter = "alpha(opacity="+opacity+")";
}


function getElemOpacity(elem)
{
return elem.style.opacity;
}

function Effects()
{

}

Effects.fadeIn = function (elem)
{
startFade(elem, 0, 100, 15, 30);
}

Effects.fadeOut = function (elem, noHideAtEnd)
{
startFade(elem, 100, 0, 15, 30, noHideAtEnd ? null : function (e) { e.style.display = "none"; });
}

function startFade(elem, start, end, inc, time, endCallback)
{
var data = new Object;
data.elem = elem;
data.cur = start;
data.end = end;
data.inc = inc;
data.time = time;
data.onEnd = endCallback;
data.doFade = doFade;
data.doAgain = function() { data.doFade(); };

setElemOpacity(elem, start);

data.doFade();
}

function doFade()
{
if (this.cur > this.end)
this.cur -= Math.min(this.cur - this.end, this.inc);

if (this.cur < this.end)
this.cur += Math.min(this.end - this.cur, this.inc);

setElemOpacity(this.elem, this.cur);

if (this.cur != this.end)
setTimeout(this.doAgain, this.time);

else if (this.onEnd)
this.onEnd(this.elem);
}


function stripHTML(html, includeGoodTags, includeBadTags)
{
var text = "";
var tagText = "";

var inTag = false;
var quoteChar = null;

if (typeof(includeGoodTags) == "undefined")
includeGoodTags = false;

if (typeof(includeBadTags) == "undefined")
includeBadTags = true;

for (var i=0; i<html.length; i++)
{
var c = html.charAt(i);

if (inTag)
{
if (quoteChar != null)
{
if (c == quoteChar)
{
quoteChar = null;
}
}
else
{
if (c == "'" || c == '"')
{
quoteChar = c;
tagText += c;
continue;
}

if (c == ">")
{
inTag = false;
tagText += c;

if (includeGoodTags)
text += tagText;

tagText = "";
continue;
}

if (!c.match(/[A-Za-z0-9_\r\n\t\- \=\/\:]/) || i == html.length - 1)
{
if (c != "<")
tagText += c;

if (includeBadTags)
text += tagText;

tagText = "";

inTag = false;
if (c == "<") i--;
continue;
}
}

tagText += c;
}
else
{
if (c == "<")
{
tagText = "" + c;
inTag = true;
continue;
}

text += c;
}
}

return text;
}

function testStripHTML()
{
if (stripHTML("<i>italic</i>") != "italic" ||
stripHTML("<i>italic</i", false, false) != "italic" ||
stripHTML("<i>italic</i", true, false) != "<i>italic" ||
stripHTML("<i>italic</i", true, true) != "<i>italic</i" ||
stripHTML("<i>italic</i", false, true) != "italic</i"
)
{
alert("Warning, stripHTML does not function correctly.\nTests:\n" + 

'stripHTML("<i>italic</i>") != "italic"\t|\t' +                  stripHTML("<i>italic</i>") +" != "+ "italic"                  + "\n" + 
'stripHTML("<i>italic</i", false, false) != "italic"\t|\t' +     stripHTML("<i>italic</i", false, false) +" != "+ "italic"     + "\n" + 
'stripHTML("<i>italic</i", true, false) != "<i>italic"\t|\t' +   stripHTML("<i>italic</i", true, false) +" != "+ "<i>italic"   + "\n" + 
'stripHTML("<i>italic</i", true, true) != "<i>italic</i"\t|\t' + stripHTML("<i>italic</i", true, true) +" != "+ "<i>italic</i" + "\n" + 
'stripHTML("<i>italic</i", false, true) != "italic</i"\t|\t' +   stripHTML("<i>italic</i", false, true) +" != "+ "italic</i"   + "\n"

);
}
}
if (isDebugMode())
{
runOnce(testStripHTML);
}


function setSelectionRange(input, selectionStart, selectionEnd)
{
if (input.setSelectionRange) 
{
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange)
{
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}


var g_debugMessages = "";

function clearDebugMessages()
{
g_debugMessages = "";
var box = elem("__debugText");
if (box)
box.innerHTML = "";

debugMessage("<b>Debuging messages have been cleared.</b>");
}

function hideDebugMessages()
{
var box = elem("__debugBox");
if (box)
removeElem(box);
}

function moveDebugMessageBox()
{
var e = elem("__debugBox");
if (e)
{
var vpSize = getViewportSize();
e.style.left = vpSize.x - 620 + "px";
}
}

function gnew(obj, args)
{
if (typeof(obj) != "undefined" && obj)
{

}
}

function debugMessage(message)
{
var now = new Date();
var time = padNumber(now.getHours(), 2) + ":" + padNumber(now.getMinutes(), 2) + ":" + padNumber(now.getSeconds(), 2);

hookEvent(window, "onresize", moveDebugMessageBox);

message = "\n[<strong>" + time + "</strong>] " + message + "<hr>";

var box = elem("__debugText");

if (box || !isDebugMode())
g_debugMessages += message;

if (!isDebugMode())
return;

if (!box)
{
var vpSize = getViewportSize();

with (new ElemBuilder())
{
table();
attr("id", "__debugBox");
position("fixed");
style("top", "5px");
style("left", vpSize.x - 620 + "px");

border("1px solid #000080");
style("background-color", "#FFFAFA");
tbody();
tr();
td();

style("background-color", "#F8F8FF");
button();
text("Clear Console");
onclick(debugMessage.onClearConsole);
end();
button();
text("Hide Console");
onclick(debugMessage.onHideConsole);
end();
button();
text("Dump GC");
onclick(debugMessage.onDumpGC);
end();
button();
text("Run JS");
onclick(debugMessage.onRunJS);
end();
button();
text("Disable Console");
onclick(debugMessage.onDisableConsole);
end();
button();
style("background-color", "#FF0000");
style("color", "#FFFFFF");
onclick(debugMessage.onRunGC);
text("Run GC");
end();
end();
end();
tr();
td();
div();
size("600px", "300px");
background("#EFEFEF");
border("1px solid black");
style("z-order", 5000);
attr("id", "__debugText");
box = curElem;

style("font-family", "monospace");
style("white-space", "pre");
style("overflow", "scroll");
end();
end();
end();
end()
table();
}

box.innerHTML += g_debugMessages;
g_debugMessages = "";
}

box.innerHTML += message;
box.scrollTop = box.scrollHeight;
}
dm = debugMessage;

debugMessage.lastRunJS = "// JS to run\n\n";

debugMessage.onHideConsole = function()
{
hideDebugMessages();
}

debugMessage.onClearConsole = function()
{
clearDebugMessages();
}

debugMessage.onRunJS = function()
{
var js = inputDialog("Enter the JS to run", "Please enter javascript below to be run at the window level.", debugMessage.lastRunJS, debugMessage.onRunJSCallback);
}


debugMessage.onRunJSCallback = function(js)
{
if (!js)
return;

debugMessage.lastRunJS = js;

try
{
var res = eval(js);
if (res != window.undefined)
{
dm("Custom JS Result: " + res);
}
}
catch (x)
{
dm("<b>Custom JS Error:</b><br/><span style='color: red'>"+x+"</span>");
}
}

debugMessage.onRunGC = function()
{
if (confirm("Are you sure you want to run the ilrn-javascript-garbage-collector?\nDoing so will likely cause many parts of this page to stop functioning correctly until it is reloaded."))
__runGC();
}

debugMessage.onDumpGC = function()
{
dumpGC();
}

debugMessage.onDisableConsole = function()
{
DEBUG = false;
hideDebugMessages();

if (g_debugCookie)
g_debugCookie.set("on", false);
}


function getEvent(ev)
{
var e = ev;
try
{
if (event && typeof(ev) == "undefined")
{
e = event;
e.target = e.srcElement;
}
}
catch (x)
{
}

return e;
}


function isChildElem(parentItem, elem)
{
while (elem && elem != document.body)
{
if (elem == parentItem)
return true;
else
elem = elem.parentNode;
}
return false;
}


function getTBody(oTableElem)
{
if (oTableElem.tagName == "TBODY")
return oTableElem;

var elems = oTableElem.getElementsByTagName("TBODY");
for (var i=0; i<elems.length; i++)
{
if (elems[i].parentNode == oTableElem)
{
return elems[i];
}
}

return createTBody(oTableElem);
}


function createElem(name, attributes, parent)
{
var doc = document;
if (parent)
{
if (parent.ownerDocument)
doc = parent.ownerDocument;
else if (parent.document)
doc = parent.document;
}

var oElem = doc.createElement(name);
if (attributes)
for (var i in attributes)
oElem.setAttribute(attributes[i][0], attributes[i][1]);

if (parent)
parent.appendChild(oElem);

return oElem;
}


function createInput(type, name, parent)
{
return createElem("input", [["type", type], ["name", name]], parent);
}


function createTd(parent)
{
return createElem("td", null, parent);
}


function insertAfter(nodeToInsert, afterNode)
{
var parent = afterNode.parentNode;
if (afterNode.nextSibling == null)
parent.appendChild(nodeToInsert);
else
parent.insertBefore(nodeToInsert, afterNode.nextSibling)
}


function getInputTextBeforeSelection(inputBox)
{
var curVal = inputBox.value;

if (document.selection)
{
var range = document.selection.createRange();
var text = range.text + "";

var curSelPart = curVal.substring(curVal.length - text.length, curVal.length);
var beforeSelPart = curVal.substring(0, curVal.length - text.length);


if (text == curSelPart && beforeSelPart + curSelPart == curVal)
curVal = beforeSelPart;


return curVal;
}

if (inputBox.selectionStart != inputBox.selectionEnd && inputBox.selectionEnd == curVal.length)
curVal = curVal.substring(0, inputBox.selectionStart);
return curVal;
}


function getInputSelectionInfo(box)
{
if (document.selection)
{
try
{
var selRange = document.selection.createRange();
var tmpRange = box.createTextRange();

tmpRange.setEndPoint( 'EndToEnd', selRange);

box.selectionStart = tmpRange.text.length - selRange.text.length;
box.selectionEnd = box.selectionStart + selRange.text.length;
}
catch (x) {
box.selectionStart = 0;
box.selectionEnd = 0;
}
}

if (typeof(box.selectionStart) == "undefined")
return null;

var range = new Object;
range.start = box.selectionStart;
range.end = box.selectionEnd;
range.toString = function()
{
return "{" + this.start + ":" + this.end + "}";
};

return range;
}


function replaceInputSelection(box, newValue)
{
if (document.selection)
{
var range = getInputSelectionInfo(box);

var value = box.value + "";

box.value = value.substring(0, range.start) + newValue + value.substring(range.end, value.length);

scheduleEventUnattached(function ()
{
var trange = box.createTextRange();
trange.moveStart('character', range.start + newValue.length);
trange.collapse(true);
trange.select();
}, 10);
}
else if (typeof(box.selectionStart) != "undefined")
{
var range = getInputSelectionInfo(box);

var val = box.value + "";
box.value = val.substring(0, range.start) + newValue + val.substring(range.end, val.length);

scheduleEventUnattached(function ()
{
box.focus();
box.selectionStart = box.selectionEnd = range.start + newValue.length;
}, 10);
}
}


function addCSSClass(elem, newClass)
{
if (!elem || !newClass)
return;

var className = elem.className;

if (className.match("([ \\t\\n]+|^)"+newClass+"([ \\t\\n]+|$)"))
return;

elem.className = className + " " + newClass;
}


function removeCSSClass(elem, newClass)
{
if (!elem || !newClass)
return;

elem.className = elem.className.toString().replace(new RegExp("(([ \\t\\n]+|^)"+newClass+"([ \\t\\n]+|$))"), " ");
}


function getElementPosition(obj)
{
var pos = new Point(0, 0);

if (obj.offsetParent)
{
while (obj.offsetParent)
{
pos.x += obj.offsetLeft;
pos.y += obj.offsetTop;

obj = obj.offsetParent;
}
}
else if (obj.x) 
{
pos.x = parseInt(obj.x);
pos.y = parseInt(obj.y);
}

return pos;
}

function ElemTemplate()
{
this.__elemTemplate = true;
this.rootNode = createDiv();
this.insertionPoints = new Array;
this.markPoints = new Array;
}


function ElemBuilder(parent)
{
if (typeof(parent) == "undefined")
parent = document.body;

this.parent = parent;
this.curElem = parent;
this.template = null;

if (parent && parent.__elemTemplate != window.undefined && parent.__elemTemplate==true)
{
this.template = parent;
this.parent = this.template.rootNode;

this.mark = ElemBuilder.mark;
this.insertion = ElemBuilder.insertion;
}
}

ElemBuilder.mark = function(name)
{
this.template.markPoints[name] = curElem;
}
ElemBuilder.insertion = function(name)
{
this.template.insertionPoints[name] = curElem;
}




function px(val)
{
if (typeof val == "string" && val.substring(val.length-2) == "px")
return val;

return val + "px";
}


ElemBuilder.prototype.elem = function(type)
{
this.curElem = createElem(type, null, this.curElem);
}


ElemBuilder.prototype.end = function()
{
while (this.curElem != this.parent && this.curElem._ebSkip)
this.curElem = this.curElem.parentNode;

if (this.curElem != this.parent)
this.curElem = this.curElem.parentNode;
}


ElemBuilder.prototype.attr = ElemBuilder.prototype.attribute = function(name, value)
{
this.curElem.setAttribute(name, value);
}


ElemBuilder.prototype.style = function(name, value)
{
if (typeof(name) != "string")
name = "" + name;

var i = name.indexOf('-');
while (i > 0)
{
name = name.substring(0, i) + name.substring(i+1, i+2).toUpperCase() + name.substring(i+2, name.length);
i = name.indexOf('-');
}

this.curElem.style[name] = value;
}


ElemBuilder.prototype.text = ElemBuilder.prototype.content = function(value1, value2)
{
if (this.curElem.customButton)
this.curElem.customButton.setText(value1, value2);
else
this.curElem.innerHTML = value1;
}

var g_shortcutElems = ["table", "tbody", "td", "th", "strong", "em", "big", "small", "a", "div", "span", "hr", "img", "form",
"select", "option", "textarea", "button", "iframe", "button"];
var g_shortcutAttributes = ["href", "value", "type", "name", "id", "src", "align", "valign", "alt"];
var g_shortcutStyles = ["border", "width", "height", "left", "right", "top", "bottom", "position", "display", "visibility", "zIndex", "margin", "borderLeft", "borderRight", "borderTop", "borderBottom"];
var g_shortcutEvents = ["onclick", "onmouseover", "onmouseout", "onkeyup", "onkeydown", "onkeypress", "onload", "onerror", "onchange"];

for (var i in g_shortcutElems)
eval("ElemBuilder.prototype."+g_shortcutElems[i]+" = function() { this.elem(\""+g_shortcutElems[i]+"\"); }");
for (var i in g_shortcutAttributes)
eval("ElemBuilder.prototype."+g_shortcutAttributes[i]+" = function(value) { this.attr(\""+g_shortcutAttributes[i]+"\", value); }");
for (var i in g_shortcutStyles)
eval("ElemBuilder.prototype."+g_shortcutStyles[i]+" = function(value) { this.style(\""+g_shortcutStyles[i]+"\", value); }");
for (var i in g_shortcutEvents)
eval("ElemBuilder.prototype."+g_shortcutEvents[i]+" = function(handler) { hookEventUnattached(this.curElem, \""+g_shortcutEvents[i]+"\", handler); }");

ElemBuilder.prototype.cursor = function(value)
{
if (value == "default")
this.style("cursor", value);
else
{
this.style("cursor", "pointer");
this.style("cursor", value);
}
}
ElemBuilder.prototype.italic = function()
{
this.elem("i");
}
ElemBuilder.prototype.bold = function()
{
this.elem("b");
}
ElemBuilder.prototype.underline = function()
{
this.elem("u");
}

ElemBuilder.prototype.tr = function()
{
if (this.curElem.nodeName.toLowerCase() != "tbody")
{
this.elem("tbody");
this.curElem._ebSkip = true;
}

this.elem("tr");
}

ElemBuilder.prototype.input = function(type)
{
var input = createElem("input");
input.type = type;
this.curElem.appendChild(input);
this.curElem = input;
}

ElemBuilder.prototype.ilrnButton = function(style, text, overText)
{
if (typeof style == "undefined")
style = "white";

var cb = new CustomButton(style, this.curElem, text, overText);
cb.render();
cb.table.customButton = cb;

this.curElem = cb.table;
}

ElemBuilder.prototype.colspan = function(val)
{
this.attr("colspan", val);
this.curElem.colSpan = val;
}

ElemBuilder.prototype.rowspan = function(val)
{
this.attr("rowspan", val);
this.curElem.rowSpan = val;
}

ElemBuilder.prototype.cellpadding = function(val)
{
this.attr("cellpadding", val);
this.curElem.cellPadding = val;
}

ElemBuilder.prototype.cellspacing = function(val)
{
this.attr("cellspacing", val);
this.curElem.cellSpacing = val;
}

ElemBuilder.prototype.pos = function(x, y)
{
if (!isNaN(x))
x = x + "px";

if (!isNaN(y))
y = y + "px";

this.left(x);
this.top(y);
}

ElemBuilder.prototype.size = function(width, height)
{
this.width(width);
this.height(height);
}

ElemBuilder.prototype.oversrc = function(value)
{
this.attr("oversrc", value);
setupRollover(this.curElem);
}

ElemBuilder.prototype.background = ElemBuilder.prototype.bg = function(value)
{
this.style("background", value);
}

ElemBuilder.prototype.cssClass = ElemBuilder.prototype.className = ElemBuilder.prototype.css = function(value)
{
this.attribute("class", value);
this.curElem.className = value;
}



function createTh(parent)
{
return createElem("th", null, parent);
}


function createDiv(parent)
{
return createElem("div", null, parent);
}


function createSpan(parent)
{
return createElem("span", null, parent);
}


function createTable(parent)
{
return createElem("table", null, parent);
}


function createTBody(parent)
{
return createElem("tbody", null, parent);
}


function createTr(parent)
{
return createElem("tr", null, parent);
}


function createImg(src, parent)
{
return createElem("img", [["src", src], ["border", 0]], parent);
}


function elem()
{
if (arguments.length == 1)
return document.getElementById(arguments[0]);

var elems = [];
for (var i=0; i<arguments.length; i++)
elems[i] = document.getElementById(arguments[i]);

return elems;
}
var $ = elem;

function $v()
{
if (arguments.length == 1)
{
var el = document.getElementById(arguments[0]);
if (el && typeof el.value != "undefined")
return el.value;
else
return null;
}

var values = [];
for (var i=0; i<arguments.length; i++)
{
var el = document.getElementById(arguments[i]);

if (el && el.value != "undefined")
values[i] = el.value;
else
values[i] = null;
}

return values;
}


function alertObj(o, substr)
{
var res = "Of object " + o + "\n";

for (var i in o)
{
if (!substr || (i+"").toLowerCase().indexOf(substr.toLowerCase()) >= 0)        
res += "o[" + i + "] = " + o[i] + "\n";
}

alert(res);
}


function storeObject(obj)
{
if (typeof(obj["_soID"]) != "undefined")
return obj._soID;

var id = g_globalObjects.length;
g_globalObjects[id] = obj;

obj._soID = id; 

return id;
}


function retriveObject(id)
{
return g_globalObjects[id];
}


function unstoreObject(id)
{
g_globalObjects[id] = null;
}


function elem(name)
{
return document.getElementById(name);
}


function parsePx(value)
{
value += "";
if (value.substring(value.length-2, value.length) == "px")
value = parseInt(value.substring(0, value.length-2));
else
value = parseInt(value);
return value;
}



function getIframeDocument(ID)
{
var iFrame = document.getElementById(ID);
var data = null;

if (iFrame.contentDocument)
{
data = iFrame.contentDocument;
}
else if (iFrame.contentWindow)
{
data = iFrame.contentWindow.document;
}
else if (document.all)
{

if (document.frames[ID])
data = document.frames[ID].document;
}
return data;
}


function getIframeWindow(ID)
{
if (typeof(ID) != "string" && ID)
{
var id2 = "__tmpIframe_" + (Math.random() * 10000);
ID.id = id2;
ID = id2;
}
else
{
return null;
}

var iFrame = document.getElementById(ID);
var data = null;

if (iFrame.contentWindow)
{
data = iFrame.contentWindow;
}
if (document.all)
{
data = document.frames[ID];
}
return data;
}


function showIFrame(iframe, show)
{
if (!iframe)
return;

if (isSafari())
{
iframe.style.visibility = show ? "visible" : "hidden";
}
else
{
iframe.style.display = show ? "" : "none";
iframe.style.visibility = "visible";
}
}


function isIFrameShown(iframe)
{

return iframe.style.display != "none" && iframe.style.visibility != "hidden";
}




function runEvent(oElem, strEventName, ev)
{
var eventTable = null;
if (!oElem._eventTable || !(eventTable=oElem._eventTable[strEventName]))
return;


var len = eventTable.length;
var rval = null;
var hasRVal = false;
for ( var i=0; i<len; i++ )
{
if (!eventTable[i] || i == "return")
continue;

var res = eventTable[i](ev, oElem);
if (typeof(res) != "undefined")
{
rval = res;
hasRVal = true;
}
}

if (eventTable["return"])
{
var rval = null;
rval = eventTable['return'](ev, oElem);
return rval;
}
else if (hasRVal)
{
return rval;
}
}


function hookEventReturn(oElem, strEventName, objTarget, strCallbackName)
{
if (!oElem)
return false;

hookEvent(oElem, strEventName, objTarget, strCallbackName);
var tableEntry = oElem._eventTable[strEventName];
tableEntry["return"] = tableEntry[tableEntry.length-1];
tableEntry[tableEntry.length-1] = null;

return true;
}

function returnThisDotValue()
{
return this.v;
}


function hookEventReturnValue(oElem, strEventName, value)
{
return hookEventReturn(oElem, strEventName, {v: value, handler: returnThisDotValue}, "handler");
}


function hookEventReturnUnattached(oElem, strEventName, func)
{
return hookEventReturn(oElem, strEventName, {handler: func}, "handler");
}
hookEventReturnFunction = hookEventReturnUnattached;


function hookEvent(oElem, strEventName, objTarget, strCallbackName)
{
if (!oElem)
return false;

var callbackFunction = null;
if (typeof(objTarget) == "function" && typeof(strCallbackName) != "string")
{
callbackFunction = objTarget;
gc(callbackFunction);
}
else
{
if (typeof(strCallbackName) != "string")
strCallbackName = strEventName;

callbackFunction = callback(objTarget, strCallbackName);
}

if (oElem == window && strEventName.toLowerCase() == "onunload")
{
g_onunloadQueue[g_onunloadQueue.length] = callbackFunction;
return;
}

var eventTable = null;
if (!(eventTable=oElem._eventTable))
eventTable = oElem._eventTable = [];

var tableEntry = null;
if (!(tableEntry=eventTable[strEventName]))
{
tableEntry = eventTable[strEventName] = [];

try
{
oElem[strEventName] = new Function("return typeof(runEvent)=='function' ? runEvent(this, \""+strEventName+"\", getEvent(arguments[0])) : null;");
}
catch (x)
{
return false;
}
}

tableEntry[tableEntry.length] = callbackFunction;

return true;
}

function setGPageLoadedToTrue()
{
g_pageLoaded = true;
}

function safariHack()
{
hookEventUnattached(window, "onload", setGPageLoadedToTrue);
}

runOnce(safariHack);


function hookEventUnattached(oElem, strEventName, funcHandler)
{
hookEvent(oElem, strEventName, funcHandler);
}


function unhookEvent(oElem, strEventName, objTarget, strCallbackName)
{
var eventTable = null;
if (oElem == null || typeof(oElem._eventTable) == "undefined" || !oElem._eventTable || !(eventTable=oElem._eventTable[strEventName]))
return false

var callbackFunction = null;
if (typeof(objTarget) == "function" && typeof(strCallbackName) != "string")
callbackFunction = objTarget;
else
{
if (typeof(strCallbackName) != "string")
strCallbackName = strEventName;

callbackFunction = callback(objTarget, strCallbackName);
}

var removed = false;

for (var i in eventTable)
{
if (eventTable[i] == callbackFunction ||
(eventTable[i] != null &&
eventTable[i].equals &&
eventTable[i].equals(callbackFunction)))
{

eventTable[i] = null;
delete eventTable[i];

removed = true;
}
}

return removed;
}



function checkEnterAndReturnEnterHandler(ev, element)
{
if (ev.keyCode == 13)
return this.enterHandler(ev, element);

return true;
}


function hookEnterPressEvent(target, handlerFunction, allowReturn)
{
if (!handlerFunction)
return;

if (!allowReturn && (allowReturn != false))
allowReturn = true;

var handler = {
enterHandler: handlerFunction,
handler: checkEnterAndReturnEnterHandler
};

if (allowReturn)
hookEventReturn(target, "onkeypress", handler, "handler");
else
hookEvent(target, "onkeypress", handler, "handler");
}




function initObjStore(data)
{
eval(data);
g_objData = data;
}

function escapeString(str)
{
str = str.split("\\").join("\\\\");
str = str.split("\"").join("\\\"");
str = str.split("'").join("\\'");
str = str.split("\n").join("\\n");
str = str.split("\t").join("\\t");
str = str.split("\r").join("\\r");

return str;
}

function addObjectSerialization()
{
Object.prototype.convertToString = function()
{
var str = "{";
for (var i in this)
{
str += "'" + i + "':" + objToString(this[i]) + ", ";
}

if (str.length > 1)
str = str.substring(0, str.length - 1);

str += "}";

return str;
}

Array.prototype.convertToString = function()
{
var str = "[";
for (var i=0; i<this.length; i++)
{
str += objToString(this[i]);

if (i < this.length - 1)
str += ",";
}

str += "]";

return str;
}
}

function removeObjectSerialization()
{
delete Array.prototype.convertToString;
delete Object.prototype.convertToString;
}


function objToString(obj)
{
addObjectSerialization();
var stringObj = "null";

if (typeof(obj) == "number")
{
stringObj = obj + "";
}
else if (typeof(obj) == "string")
{
stringObj = '"'+escapeString(obj)+'"';
}
else if (obj)
{
if (obj.convertToString != window.undefined)
{
stringObj = obj.convertToString();
}
else
{
var str = "";
for (var i in obj)
{
str += i + ":" + objToString(obj[i]) + ",";
}
stringObj = "{"+str.substr(0, str.length-1)+"}";
}
}

removeObjectSerialization();
return stringObj;
}


function restoreObject(obj, name)
{
g_objsToStore[name] = obj;
if (g_objData[name] && obj.loadState) 
{
obj.loadState(g_objData[name]);
}
}

function storeObjects()
{
var data = new Array;
for ( var i in g_objsToStore )
{
var obj = g_objsToStore[i];
if (obj.saveState)
{
data[i] = obj.saveState(data[i]);
}
}

return "var data="+objToString(data);
}




function handleRollovers()
{
setupOversrc(document.getElementsByTagName("IMG"));

setupOversrc(document.getElementsByTagName("INPUT"));

setupOverpeers(getElementsByTagNames(["A", "SPAN"]));

debugMessage("Automagical image rollover handlers have been setup.");
}


function setupOversrc(list)
{
for (var i=0; i<list.length; i++)
{
var el = list[i]; 
setupRollover(el);
}
}


function setupRollover(el)
{
var oversrc = el.getAttribute("oversrc");

if (oversrc != null)
{
el.overImg = new Image();
el.overImg.src = oversrc;

el.offImg = new Image();
el.offImg.src = el.src + "";

hookEventUnattached(el, "onmouseover", rollover_mouseover);
hookEventUnattached(el, "onmouseout", rollover_mouseout);
}
}



function setupOverpeers(list)
{
}



function rollover_mouseover(e, target)
{
if (target.overImg || target.getAttribute("oversrc") != null)
{
var oversrc = target.getAttribute("oversrc");
if (oversrc && oversrc != target.overImg.src)
target.overImg.src = oversrc;

if (target.overImg.src)
target.src = target.overImg.src;
}
}


function rollover_mouseout(e, target)
{
if (target.offImg)
target.src = target.offImg.src;
}





function resetEventIdSeedAndSchedule()
{
g_futureEvents = [null];
}

runOnce(resetEventIdSeedAndSchedule);

function _dumpFutureEvents()
{
var report = "<b>" + g_futureEvents.length + " Future Events</b><br/><ul>";
for (var i=0; i<g_futureEvents.length; i++)
{
var fe = g_futureEvents[i];
if (fe == null)
continue;

report += "<li><b>"+i+"</b>: " + fe.action + "</li>";
}

report += "</ul>";

dm(report);
}


function FutureEvent(action)
{
this.action = action;
this.id = g_futureEvents.length;

this.scheduled = false;
this.timeoutId = null;


g_futureEvents[this.id] = this;
}


FutureEvent.prototype.execute = function()
{
this.scheduled = false;
this.action();

if (!this.scheduled)
this.cancel();
}

FutureEvent.prototype.toString = function()
{
return this.id ? this.id.toString() : "&lt;unscheduled&gt;";
}


FutureEvent.prototype.schedule = function(timeout)
{
if (this.scheduled)
clearTimeout(this.timeoutId);
else
this.scheduled = true;

this.timeoutId = setTimeout(callback(this, "execute"), timeout);
}


FutureEvent.prototype.cancel = function()
{
if (this.scheduled)
clearTimeout(this.timeoutId);

g_futureEvents[this.id] = null;

this.scheduled = false;
this.action = null;
this.id = null;
}


FutureEvent.fromId = function(obj)
{
if (obj && obj.prototype == FutureEvent.prototype)
return obj;

return obj ? g_futureEvents[obj.toString()] : null;
}


function scheduleEventUnattached(action, timeout)
{
return scheduleEvent(action, timeout);
}


function scheduleEvent()
{
var timeout, func;

if (arguments.length == 3)
{
func = callback(arguments[0], arguments[1]);
timeout = arguments[2];
}
else if (arguments.length == 2)
{
func = arguments[0];
timeout = arguments[1];
}

var futureEvent = new FutureEvent(func);
futureEvent.schedule(timeout);

return futureEvent;
}


function rescheduleEvent(id, timeout)
{
var futureEvent = FutureEvent.fromId(id);

if (futureEvent != null)
{
futureEvent.schedule(timeout);
return futureEvent.id;
}

return null;
}


function unscheduleEvent(id)
{
var futureEvent = FutureEvent.fromId(id);

if (futureEvent != null)
futureEvent.cancel();
}




function hookOnloadUnattached(action)
{
hookEventUnattached(window, "onload", action);
}
function doOnload(action)
{
if (isPageLoaded())
{
action();
}
else
{
hookOnloadUnattached(action);
}
}
function doOnunload(action)
{
hookEventUnattached(window, "onunload", action);
}




function Point(x, y)
{
this.x = (arguments.length > 0 ? x : 0);
this.y = (arguments.length > 1 ? y : 0);
}


Point.prototype.toString = function()
{
return "{"+this.x+","+this.y+"}";
}


Point.prototype.minus = function(otherPoint)
{
return new Point(this.x - otherPoint.x, this.y - otherPoint.y);
}


Point.prototype.plus = function(otherPoint)
{
return new Point(this.x + otherPoint.x, this.y + otherPoint.y);
}


Point.prototype.clone = function()
{
return new Point(this.x, this.y);
}


Point.fromEvent = function(ev)
{
return new Point(ev.clientX, ev.clientY);
}


Point.fromElement = function(elem)
{
if (elem == window.undefined || !elem)
return new Point(0, 0);

return new Point(parsePx(elem.style.left), parsePx(elem.style.top));
}


Point.fromCursorPos = function()
{
if (g_mousePosition == null)
{
if (window.event)
{
g_mousePosition = Point.fromEvent(window.event);
return g_mousePosition;
}
return new Point(0, 0);
}

return g_mousePosition.clone();
}


Point.fromElementSize = function(obj)
{
var size = new Point(0, 0);

var props = [["width", "height"], ["clientWidth", "clientHeight"], ["scrollWidth", "scrollHeight"]];
for (var i in props)
if (obj[props[i][0]])
{
size.x = obj[props[i][0]];
size.y = obj[props[i][1]];

return size;
}

if (obj.style.width)
{
size.x = parsePx(obj.style.width);
size.y = parsePx(obj.style.height);
}

return size;
}


function getDocumentScroll()
{
var pos = new Point();
pos.x = document.body.scrollLeft;
pos.y = document.body.scrollTop;

return pos;
}


function setDocumentScroll(pos)
{
if (document.documentElement)
{
document.documentElement.scrollLeft = pos.x;
document.documentElement.scrollTop = pos.y;
}

document.body.scrollLeft = pos.x;
document.body.scrollTop = pos.y;


return pos;
}


function Stack()
{
this.stack = [];
this.top = 0;
}


Stack.prototype.push = function(obj)
{
this.stack[this.top ++] = obj;
}


Stack.prototype.peek = function()
{
if (this.top == 0)
throw "Cannot peek from empty stack";

return this.stack[this.top - 1];
}


Stack.prototype.pop = function()
{
var obj = this.peek();
this.top --;
this.stack[this.top] = null;

return obj;
}


Stack.prototype.getSize = function()
{
return this.top;
}


Stack.prototype.isEmpty = function()
{
return this.getSize() < 1;
}


function URL(url, args)
{
if (typeof(args) == "undefined")
args = new Array;

url = url ? url.toString() : "";

this.url = url;
this.args = args;

if (url.indexOf('?') >= 0)
{
var as = url.substring(url.indexOf('?')+1, url.length);
this.url = url.substring(0, url.indexOf('?'));

var targs = as.split("&");
for (var i in targs)
{
var name, value;
var targ = targs[i];

if (targ.indexOf('=') > 0)
{
var targ = targs[i].split("=");
name = targ[0];
value = targ[1];
}
else
name = targs[i];

this.putArg(name, value);
}
}
}


URL.prototype.hasArg = function(name)
{
return this.getArg(name) != null;
}


URL.prototype.getProtocall = function(name)
{
var i = this.url.indexOf("://");
if (i < 0)
return "";

return this.url.substring(0, i);
}


URL.prototype.toString = function()
{
var url = this.url;
if (this.args)
url = appendQueryStringToURL(url, convertObjectToQueryString(this.args));

return url;
}


URL.prototype.getArg = function(name)
{
var arg = this.args[name];
if (!arg)
return null;

if (typeof(arg) == "object")
{
if (arg.length == 0)
return null;
if (arg.length == 1)
return realUnescape(arg[0]);
}

if (typeof(arg) != "string")
arg = "" + arg;

return realUnescape(arg);
}


URL.prototype.putArg = function(name, value)
{
if (typeof(value) == "object")
{
for (var i in value)
{
this.putArg(name, value[i]);
}
return;
}

var dest = this.args[name];

if (typeof(dest) == "object")
dest[dest.length] = value;

else if (typeof(dest) != "undefined" && dest)
this.args[name] = [dest+"", value];

else
this.args[name] = [value];
}


URL.prototype.putArgs = function(args)
{
if (typeof(args) != "object")
return;

for (var i in args)
{
this.putArg(i + "", args[i]);
}
}




function IFrameDestroyer(iframe)
{
this.iframe = iframe;
iframe.ifd = this;

hookEvent(iframe, "onload", this, "onload");
}
IFrameDestroyer.prototype.onload = function()
{
scheduleEvent(this, "destroyFrame", 5000);
}
IFrameDestroyer.prototype.destroyFrame = function()
{
if (this.iframe)
{
this.iframe.parentNode.removeChild(this.iframe);
this.iframe = null;
}
}


function realEscape(string)
{
return escape(string).split("+").join("%2B");
}


function realUnescape(string)
{
return unescape(string.split("+").join(" "));
}


function convertObjectToQueryString(args)
{
var argString = "";
if (typeof(args) == "string" || typeof(args) == "number")
{
argString = args;
}
else
{
for (var i in args)
{
var arg = args[i];

if (typeof(arg) == "array" || typeof(arg) == "object")
{
for (var j in arg)
argString += realEscape(i) + "=" + realEscape(arg[j]) + "&";
}
else
argString += realEscape(i) + "=" + realEscape(arg) + "&";
}
}

if (argString.substring(argString.length-1, argString.length) == "&")
argString = argString.substring(0, argString.length-1);

return argString;
}


function appendQueryStringToURL(url, queryString)
{
if (url.indexOf('?') > 0)
url += "&" + queryString;
else
url += "?" + queryString;

return url;
}


function hiddenPostBack(url, args, docuOverride)
{
if (args)
{
var argString = convertObjectToQueryString(args);

if (url.indexOf("?") >= 0)
url += "&" + argString;
else
url += "?" + argString;
}

if (!docuOverride)
docuOverride = document;

var iframe = createElem("iframe", [["style", "width:0; height:0; visibility:hidden;"], ["src", url], ["onload", "this.ifd.onload()"]], docuOverride.body);
iframe.style.width = "0px";
iframe.style.height = "0px";
new IFrameDestroyer(iframe);
}


function newHTTPXMLRequestHandler()
{


var handler = null;

if (window.XMLHttpRequest)
handler = new XMLHttpRequest();
else if (window.ActiveXObject)
handler = new ActiveXObject("Microsoft.XMLHTTP");

return handler;
}


function deleteHTTPXMLRequestHandler(handler)
{

}


function HTTPRequest(url, async)
{
url = "" + url;

this.url = url;
this.params = null;

var paramIndex = url.indexOf('?');
if (paramIndex >= 0)
{
this.params = url.substring(paramIndex + 1);
this.url = url.substring(0, paramIndex);
}

this.async = async;
this.request = null;
this.onerror = null;
this.onload = null;
this.objId = -1;

this.contentText = null;
this.contentDocument = null;

this.status = 0;
this.message = "";
}


HTTPRequest.prototype.onStateChange = function()
{
if (this.request.readyState == 4)
{
delete this.request.onreadystatechange;
this.handleLoad();
}
}


HTTPRequest.prototype.handleLoad = function()
{
if (this.request == null)
return;

this.status = this.request.status;
this.message = this.request.statusText;

this.contentDocument = this.request.responseXML;
this.contentText = this.request.responseText;

if (this.status == 200)
{
if (this.onload)
this.onload(this);
}
else
{
if (this.onerror)
this.onerror(this);
}

delete this.request;
this.request = null;
}


HTTPRequest.prototype.send = function()
{
this.request = newHTTPXMLRequestHandler();

if (this.request == null)
return false;

this.objId = storeObject(this);


var requestRef = this;
this.request.onreadystatechange = function()
{
requestRef.onStateChange();
}

this.request.open("POST", this.url, this.async);
this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

if (typeof this.request.overrideMimeType == "function")
this.request.overrideMimeType('text/xml');


this.request.send(this.params);

if (!this.async)
{
this.handleLoad();
return this.request.responseText;
}
else
return true;
}


function hiddenPostbackNoReturn(url, args)
{
if (args)
{
var argString = convertObjectToQueryString(args);

if (url.indexOf("?") >= 0)
url += "&" + argString;
else
url += "?" + argString;
}

var request = new HTTPRequest(url, true);
if (!request.send())
{
hiddenPostBack(url);
}
}


function sendHTTPRequest(url, onload, onerror)
{
var request = new HTTPRequest(url, true);

if (typeof(onload) != "undefined")
{
hookEventUnattached(request, "onload", onload);

if (typeof(onerror) != "undefined")
{
hookEventUnattached(request, "onerror", onerror);
}
}

request.send();
}


function setLocation(location)
{
if (exitOK())
self.location = location;
}


function getLocation()
{
return window.location;
}


function scrollToElement(element, position, doc)
{
if (position != "middle")
position = "top";



var oldPosition = element.style.position;

element.style.position = "absolute";

var offsetTop = element.offsetTop;

element.style.position = oldPosition;

if (typeof(doc) == 'undefined')
{
doc = document;
}

if (position == "middle")
{
if (offsetTop != doc.body.scrollTop + doc.body.clientHeight/2)
{
doc.body.scrollTop = offsetTop - doc.body.clientHeight/2 + element.offsetHeight/2;
}
}
else if (position == "top")
{
if (offsetTop != doc.body.scrollTop)
{
var oldScrollTop = doc.body.scrollTop;

doc.body.scrollTop = offsetTop;

if (oldScrollTop == doc.body.scrollTop)
doc.body.parentNode.scrollTop = offsetTop;
}
}

doc.body.scrollLeft = 0;
}


function findTextWithContext(text, find, beforeLength, afterLength)
{
var results = [];
var found = text.split(find);

if (typeof(beforeLength) != "number" && typeof(beforeLength) != "string")
beforeLength = 20;
if (typeof(afterLength) != "number" && typeof(afterLength) != "string")
afterLength = 20;

for (var i=0; i<found.length-1; i++)
{
var before = found[i].substring(found[i].length - beforeLength, found[i].length);
var after = found[i+1].substring(0, afterLength);

results[results.length] = [before, find, after];
}

return results;
}


function appendAll(array1, array2)
{
for (var i in array2)
array1[array1.length] = array2[i];
}


function mergeObject(target, additional, overwrite)
{
if (typeof(overwrite) == "undefined")
overwrite = true;

for (var i in additional)
{
if (overwrite || typeof(target[i]) == "undefined")
target[i] = additional[i];
}
}


function floatingAlert(title, html)
{
if (arguments.length == 2)
okDialog(title, html);
else
okDialog("Floating Alert", title);
}
fAlert = floatingAlert;

function _doCall(func, args)
{
var estring = "func(";

for (var i=0; i<args.length; i++)
{
estring += "args[" + i + "]";
if (i < args.length - 1)
estring += ",";
}

estring += ")";

return eval(estring);
}

function _doCallback(obj, method, args)
{
var estring = "obj."+method+"("

for (var i=0; i<args.length; i++)
{
estring += "args[" + i + "]";
if (i < args.length - 1)
estring += ",";
}

estring += ")";

return eval(estring);
}

function callback(object, methodName)
{
var func = function()
{
var a = arguments;
if (a.length > 8)
return _doCallback(object, methodName, a);
else
return object[methodName](a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
}

func.cbObject = object;
func.cbMethod = methodName;
func.equals = callback.equals;

return func;
}

callback.equals = function(f)
{
return f && f.cbObject == this.cbObject && f.cbMethod == this.cbMethod;
}


function getViewportSize()
{
var size = new Point(0, 0);
if (window.innerHeight != window.undefined)
{
size.x = window.innerWidth;
size.y = window.innerHeight;
}
else if (document.compatMode == "CSS1Compat")
{
size.x = document.documentElement.clientWidth;
size.y = document.documentElement.clientHeight;
}
else if (document.body)
{
size.x = document.body.clientWidth;
size.y = document.body.clientHeight;
}

return size;
}


function getDocumentElement()
{
if (document.all)
return document.body;

return document.documentElement;
}

function removeElem(elem)
{
elem.parentNode.removeChild(elem);
}

function formatPercent(value, dots)
{
if (dots == window.undefined)
dots = 2;

return formatFloat(value, 2) + "%";
}


function escapeHTML(html, convertLineBreaks)
{
html = html.split("&").join("&amp;");
html = html.split("<").join("&lt;");
html = html.split(">").join("&gt;");
html = html.split("\n").join("<br/>");

return html;
}

function formatFloat(number, places)
{
if (places == 0)
places = -1;

number = number.toString();
var i = number.indexOf('.');
if (i < 0)
return number;

return number.substring(0, i+places+1);
}

function padNumber(number, len)
{
number = number + "";
while (number.length < len)
number = "0" + number;

return number;
}


function formatFileSize(size)
{
var unitsList = ["B", "KB", "MB", "GB", "TB"];

var unitsIndex = 0;
while (size >= 1024 && unitsIndex < unitsList.length)
{
size /= 1024;
unitsIndex++;
}

return formatFloat(size, 2) + " " + unitsList[unitsIndex];
}


function parseBool(string)
{
string = ("" + string).toLowerCase();
return string == "1" || string == "yes" || string == "true" || string == "on";
}


function handleLinkClick(ev, link)
{
if (allowExit)
return;

try
{
link = ev.target;
}
catch (x)
{
return;
}


if (link.tagName != "A")
{
while (link && (link.tagName != "BODY" && link.tagName != "INPUT" && link.tagName != "TEXTAREA" && link.tagName != "SELECT") && link.tagName != "A") link = link.parentNode;

if (link.tagName != "A")
return;
}

if (link.getAttribute("confirm") != null && !parseBool(link.getAttribute("confirm")))
return true;

var href = link.getAttribute("href");
var baseLocation = getLocation().toString();

var pound = baseLocation.lastIndexOf('#');

if (pound >= 0)
{
baseLocation = baseLocation.substring(0, pound);
}

if (href!= null && href!="" && href != (baseLocation+"#") && href != "#" && href.substring(0, 11) != "javascript:" && href.substring(0,7) != "mailto:")
{
dm("Intercepting link to " + href);
setLocation(href);
return false;
}

return true;
}

function checkForJavascriptLocationRef()
{
if (isDebugMode())
{
var text = (document.body.innerHTML + "").toLowerCase();
if (text.indexOf("self.location") >= 0 || text.indexOf("window.location") >= 0)
{
var list = [];
appendAll(list, findTextWithContext(text, "self.location", 40, 80));
appendAll(list, findTextWithContext(text, "window.location", 40, 80));

var message = "This page uses a deprecated method of javascript navigation.<br/>Please do not set or get window<span>.</span>location or self<span>.</span>location directly. Use setLocation and getLocation instead.";
message += "<pre><h3>Offending Code:</h3><hr>"
for (var i in list)
{
message += "<nobr>" + escapeHTML(list[i][0]) + "<font color='red'>" + escapeHTML(list[i][1]) + "</font>" + escapeHTML(list[i][2]) + "</nobr><hr>";
}

message += "</pre>"
floatingAlert("Developer Warning", message);
}
else
{
dm("Found no uses of window.location or self.location");
}
}
}

function setupHandleLinkClick()
{
hookEventUnattached(document.body, "onclick", handleLinkClick);
hookEnterPressEvent(document.body, handleLinkClick, false);
}

function debugMessageWarning()
{
g_debugKeyPressString = "";

if (typeof ComplexCookie != "undefined")
{
g_debugCookie = new ComplexCookie("debugModeSwitch");

if (g_debugCookie.get("on") == "true")
{
DEBUG = true;
dm("<b>Debug mode activated from cookie.</b>");
}
}
else
{
g_debugCookie = null;
}

hookEvent(document.all ? document : window, "onkeyup", handleDebugKeyEvents);

dm("<b style='color: red;'>WARNING: This page is running in debug mode.</b>");

var files = "<b>Included JS files:</b><ul>";
for (var i in window)
{
var ii = i + "";
if (ii.substring(0, 9) == "g_jsFile_" && ii.substring(ii.length - 3, ii.length) == "_js")
{
var file = ii.substring(9, ii.length);
file = file.substring(0, file.indexOf("_js")) + ".js";

files += "<li style='color: blue;'>" + file + "</li>"
}
}

files += "</ul>"

dm(files);
}

function handleDebugKeyEvents(e)
{
var desired = "activate debug mode";

var c = String.fromCharCode(e.keyCode).toLowerCase();
g_debugKeyPressString += c;

if (desired.substring(0, g_debugKeyPressString.length) != g_debugKeyPressString)
g_debugKeyPressString = c;

if (g_debugKeyPressString == desired)
{
g_debugKeyPressString = "";

DEBUG = true;
dm("<b>Debug mode activated from user request</b>");

if (g_debugCookie)
g_debugCookie.set("on", true);
}
}

function globalMouseMoveHandler(ev)
{
if (g_mousePosition == null)
g_mousePosition = Point.fromEvent(ev);
else
{
g_mousePosition.x = ev.clientX;
g_mousePosition.y = ev.clientY;
}
}

function setupOnload()
{

doOnload(checkForJavascriptLocationRef);

doOnload(setupHandleLinkClick);

doOnload(debugMessageWarning);

doOnload(setupDWR);

hookEvent(window, "onmousemove", globalMouseMoveHandler);

hookEventUnattached(window, "onunload", storeObjects);
hookEventUnattached(window, "onload", handleRollovers);
}

runOnce(setupOnload);



if(typeof(OOP) == 'undefined')
{
OOP = function(){}
OOP.defineClass = function(clazz,superClass)
{
if (superClass)
extendClass(clazz,superClass);
else
defineClass(clazz);
}
}


function getApplet(appletName)
{
var applet;
if (isSafari())
{
applet = document.applets[appletName];	
}
else 
{
applet = document.getElementById(appletName);
}

return applet;
}
