if (typeof wdk == "undefined")
{
var wdk = new Object();
wdk.dom = new function()
{
this.ELEMENT_NODE = 1;
this.ATTRIBUTE_NODE = 2;
this.TEXT_NODE = 3;
this.CDATA_SECTION_NODE = 4;
this.ENTITY_REFERENCE_NODE = 5;
this.ENTITY_NODE = 6;
this.PROCESSING_INSTRUCTION_NODE = 7;
this.COMMENT_NODE = 8;
this.DOCUMENT_NODE = 9;
this.DOCUMENT_TYPE_NODE = 10;
this.DOCUMENT_FRAGMENT_NODE = 11;
this.NOTATION_NODE = 12;
this.get = function(e)
{
if (e)
{
if (typeof(e) == "string")
{
return document.getElementById(e);
}
else if (e.getElementsByTagName)
{
return  e;
}
else if (e.push)
{
var elems = new Array(e.length);
for (var i = 0;i < e.length; i++)
{
elems[i] = this.get(e[i]);
}
return elems;
}
}
return null;
}
this.hasClass = function(elem, className)
{
if (!regExpCache[className])
{
if (regExpCount > MAX_REGEXP_COUNT) {
regExpCount = 0;
regExpCache = {};
}
regExpCache[className] = new RegExp('(^|\\s+)' + className + '(\\s+|$)');
regExpCount++;
}
return regExpCache[className].test(elem['className']);
}
var regExpCache = {};
var regExpCount = 0;
var MAX_REGEXP_COUNT = 250;
this.findAncestorWithClassName = function(elem, className)
{
for (var node = elem; node != null; node = node.parentNode)
{
if (this.hasClass( node, className ))
{
return node;
}
}
return null;
}
this.findAncestorWithTagName = function(elem, tagName)
{
tagName = tagName.toUpperCase();
for (var node = elem; node != null; node = node.parentNode)
{
if (node.tagName && node.tagName.toUpperCase() == tagName)
{
return node;
}
}
return null;
}
this.getElementsByClassName = function(elem, className, tagName)
{
var elems = new Array();
var parentNode = elem;
if (!parentNode)
{
parentNode = document;
}
tagName = tagName || '*';
var all = parentNode.getElementsByTagName(tagName);
for (var i=0;i < all.length;i++)
{
var _elem = all[i];
if (this.hasClass(_elem, className))
{
elems[elems.length] = _elem;
}
}
return elems;
}
this.addClass = function(elem, className)
{
if (this.hasClass(elem, className))
{
return;
}
if (elem.className)
{
className = elem.className + " " + className;
}
elem.className = className;
}
this.removeClass = function(elem, className)
{
if (elem.className == className)
{
elem.className = null;
return;
}
if (elem.className == null)
{
return;
}
var classes = elem.className.split(" ");
for (var i = classes.length - 1; i >= 0; i--)
{
if (classes[i] == className)
{
classes[i] = '';
// don't break - to account for duplicates
}
}
elem.className = classes.join(" ");
}
var camelized_prop_cache = {};
this.getStyle = function(elem, styleName)
{
var s;
if (elem.currentStyle)
{
var camelStyleName = hyphen2Camel(styleName);
s = elem.currentStyle[camelStyleName];
}
else if (document.defaultView)
{
s = document.defaultView.getComputedStyle(elem, null).getPropertyValue(styleName);
}
return s;
}
function hyphen2Camel(prop)
{
if (!camelized_prop_cache[prop])
{
var t = prop.indexOf('-') != -1;
if(prop.indexOf('-') != -1)
{
var a = prop.split("-");
for (var i = 1; i < a.length; i++)
{
a[i] = a[i].substring(0,1).toUpperCase() + a[i].substring(1,a[i].length);
}
camelized_prop_cache[prop] = a.join("");
}
else
{
camelized_prop_cache[prop] = prop;
}
}
return camelized_prop_cache[prop];
}
this.getElementWindow = function (elem)
{
var targetWindow = null;
if (typeof elem.parentWindow != undefined && elem.parentWindow != null)
{
targetWindow = elem.parentWindow;
}
else if (typeof elem.ownerDocument != undefined && elem.ownerDocument != null)
{
if (typeof elem.ownerDocument.parentWindow != undefined && elem.ownerDocument.parentWindow != null)
{
targetWindow = elem.ownerDocument.parentWindow;
}
else if (typeof elem.ownerDocument.defaultView != undefined && elem.ownerDocument.defaultView != null)
{
targetWindow = elem.ownerDocument.defaultView;
}
}
else if (elem.window == elem)
{
targetWindow = elem;
}
return targetWindow;
}
this.traverseDom = function (elem, visitFunction)
{
visitFunction(elem);
if (elem && elem.childNodes && elem.childNodes.length != 0)
{
for (var i = 0; i < elem.childNodes.length; i++)
{
this.traverseDom(elem.childNodes[i], visitFunction);
}
}
}
}
wdk.pos = new function()
{
var IE_STRICT = document.compatMode && document.compatMode != "BackCompat";
var IE_QUIRKS = document.compatMode && document.compatMode == "BackCompat";
this.Rect = Rect;
this.getElementRect = function(elem, bAccountForScroll)
{
if (typeof bAccountForScroll == "undefined")
{
bAccountForScroll = true;
}
var offsetLeft  = 0;
var offsetTop   = 0;
if (document.documentElement.getBoundingClientRect)
{
var box = elem.getBoundingClientRect();
offsetLeft = box.left;
offsetTop = box.top;
if (!bAccountForScroll)
{
var clRect = wdk.pos.getClientRect();
offsetLeft += clRect.left;
offsetTop += clRect.top;
}
}
else
{
var offsetTrail = elem;
var scrollTop   = 0;
var scrollLeft  = 0;
while(offsetTrail)
{
offsetLeft += offsetTrail.offsetLeft;
offsetTop  += offsetTrail.offsetTop;
if (bAccountForScroll && offsetTrail.tagName != "BODY" && offsetTrail.tagName != "HTML")
{
scrollTop += offsetTrail.scrollTop;
scrollLeft += offsetTrail.scrollLeft;
}
offsetTrail = offsetTrail.offsetParent;
}
if (bAccountForScroll)
{
offsetTop -= scrollTop;
offsetLeft -= scrollLeft;
}
}
return new Rect(offsetTop, offsetLeft, elem.offsetHeight, elem.offsetWidth);
}
this.setElementPosition = function(elem, pageXY)
{
setElementPosition(elem, pageXY, false);
}
function setElementPosition(elem, pageXY, recursed)
{
var posType = wdk.dom.getStyle(elem, 'position');
// to be able to move the element relative to it's current position
if (posType == "static") {
elem.style.position = posType ="relative";
}
var currentPageXY = wdk.pos.getElementRect(elem);
setXOrY(elem, posType, currentPageXY, pageXY[0], "left", "offsetLeft");
setXOrY(elem, posType, currentPageXY, pageXY[1], "top", "offsetTop");
// if last arg is true, we've recursed below already
if (!recursed) {
var newXY = wdk.pos.getElementRect(elem);
if (newXY.left != pageXY[0] || newXY.right != pageXY[1]) {
setElementPosition(elem, pageXY, true);
}
}
}
function setXOrY(elem, posType, pageXY, newPos, topOrLeft, offsetTopOrLeft)
{
if (newPos !== null) {
var elemTopOrLeft = parseInt(wdk.dom.getStyle(elem, topOrLeft), 10);
// Make sure we're dealing with an int value - we may get "auto" instead of pixel value
if (isNaN(elemTopOrLeft)) {
// if we didn't get a number above, we're going to assume current element offset
elemTopOrLeft = (posType == "absolute") ? elem[offsetTopOrLeft] : 0;
}
elem.style[topOrLeft] = newPos - pageXY[topOrLeft] + elemTopOrLeft + "px";
}
}
this.getClientRect = function()
{
var top = 0;
var left = 0;
var width = 0;
var height = 0;
if (typeof self.pageXOffset != 'undefined')
{
top = self.pageXOffset;
left = self.pageYOffset;
width = self.innerWidth;
height = self.innerHeight;
}
else if (IE_STRICT)
{
var docElement = document.documentElement;
top = docElement.scrollTop;
left = docElement.scrollLeft;
width = docElement.clientWidth;
height = docElement.clientHeight;
}
else if(IE_QUIRKS)
{
var body = document.body;
top = body.scrollTop;
left = body.scrollLeft;
width = body.clientWidth;
height = body.clientHeight;
}
return new Rect(top, left, height, width);
}
this.clientLeftToPageLeft = function(clientLeft)
{
if (typeof self.pageXOffset != 'undefined')
{
return clientLeft + self.pageXOffset;
}
else if (IE_STRICT)
{
return clientLeft + document.documentElement.scrollLeft;
}
else if (IE_QUIRKS)
{
return clientLeft + document.body.scrollLeft;
}
return clientLeft;
}
this.clientTopToPageTop = function(clientTop)
{
if (typeof self.pageYOffset != 'undefined')
{
return clientTop + self.pageYOffset;
}
else if (IE_STRICT)
{
return clientTop + document.documentElement.scrollTop;
}
else if (IE_QUIRKS)
{
return clientTop + document.body.scrollTop;
}
return clientTop;
}
this.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
{
cursor.x = e.clientX +
(document.documentElement.scrollLeft ||
document.body.scrollLeft) -
document.documentElement.clientLeft;
cursor.y = e.clientY +
(document.documentElement.scrollTop ||
document.body.scrollTop) -
document.documentElement.clientTop;
}
return cursor;
}
this.intersect = function(rect1, rect2, bReturnIntersection)
{
var intersection = null;
var top = Math.max(rect1.top, rect2.top);
var bottom = Math.min(rect1.bottom, rect2.bottom);
var left = Math.max(rect1.left, rect2.left);
var right = Math.min(rect1.right, rect2.right);
if (top > bottom || left > right)
{
intersection = (bReturnIntersection) ? null : false;
}
else
{
intersection = (bReturnIntersection) ? new Rect(top, left, bottom-top, right-left) : true;
}
return intersection;
}
this.getScrollbarWidth = function()
{
if (typeof this.getScrollbarWidth.width == "undefined")
{
var outer = document.createElement("DIV");
with (outer.style) {
top = "-300px";
left = "0px"
width = height = "100px";
overflow = "scroll";
position = "absolute";
}
var inner = document.createElement("DIV");
with (inner.style) {
width = height = "400px";
}
outer.appendChild(inner);
document.body.appendChild(outer);
var width = outer.offsetWidth - outer.clientWidth;
document.body.removeChild(outer);
outer.removeChild(inner);
outer = inner = null;
this.getScrollbarWidth.width = width;
}
return this.getScrollbarWidth.width;
}
function Rect(top, left, height, width)
{
this.top = top;
this.left = left;
this.height = height;
this.width = width;
this.right = left + width;
this.bottom = top + height;
}
}
wdk.events = new function()
{
var listenerRegistry = new EventListenerRegistry();
this.getEventTarget = function(elem)
{
if (elem.addEventListener)
{
return new EventTargetW3C(elem);
}
else if (elem.attachEvent)
{
return new EventTargetIE(elem);
}
}
this.keycodes =
{
TAB : 9,
ENTER : 13,
LEFT_ARROW : 37,
UP_ARROW : 38,
RIGHT_ARROW : 39,
DOWN_ARROW : 40,
CONTEXT_MENU : 93,
ESC : 27,
SPACEBAR : 20
};
function EventListenerRegistry()
{
this.m_registry = new Array();
}
EventListenerRegistry.prototype.add = function(evtTarget, evtName, func, bCapture)
{
this.m_registry.push({ evtTarget: evtTarget, evtName: evtName, func: func, bCapture : bCapture});
}
EventListenerRegistry.prototype.cleanup = function()
{
var registry = this.m_registry;
for (var i = 0; i < registry.length; i++)
{
var listener = registry[i];
var evtTarget = listener.evtTarget;
if (evtTarget)
{
if (listener.evtName == "dblclick" && navigator.userAgent.toLowerCase().indexOf("safari") != -1)
{
listener.evtTarget.ondblclick = null;
}
else
{
evtTarget.removeEventListener(listener.evtName, listener.func, listener.bCapture);
}
}
}
}
function EventTargetW3C(node)
{
this.m_node = node;
}
EventTargetW3C.prototype.addEventListener = function(evtName, func, bCapture)
{
listenerRegistry.add(this.m_node, evtName, func, bCapture);
if (evtName == "dblclick" && navigator.userAgent.toLowerCase().indexOf("safari") != -1)
{
this.m_node.ondblclick = func;
}
else
{
this.m_node.addEventListener(evtName, func, bCapture);
}
}
EventTargetW3C.prototype.removeEventListener = function(evtName, func, bCapture)
{
this.m_node.removeEventListener(evtName, func, bCapture);
}
EventTargetW3C.prototype.dispatchEvent = function(evt)
{
return this.m_node.dispatchEvent(evt);
}
function EventTargetIE(node)
{
this.m_node = node;
}
EventTargetIE.prototype.addEventListener = function (evtName, func, bCapture)
{
listenerRegistry.add(this, evtName, func, bCapture);
var elem = this.m_node;
// WinIE sets the 'this' object in event handlers to 'window'. Use this proxy
// function to make the 'this' object refer to the handler's element.
var proxy = function()
{
func.call( elem, new EventIE(window.event, elem) );
};
function ProxyHelper(func, proxy)
{
this.m_func = func;
this.m_proxy = proxy;
};
ProxyHelper.prototype.getProxy = function()
{
return this.m_proxy;
}
ProxyHelper.prototype.matches = function(func)
{
return this.m_func === func;
}
var key = evtName + func + bCapture;
if (elem.attachEvent( "on" + evtName, proxy ))
{
if (!elem[key])
{
elem[key] = new Array();
}
var proxyHelperArray = elem[key];
proxyHelperArray.push(new ProxyHelper(func, proxy));
if (bCapture)
{
elem.setCapture(true);
}
}
}
EventTargetIE.prototype.removeEventListener = function(evtName, func, bCapture)
{
var elem = this.m_node;
var key = evtName + func + bCapture;
var proxyHelperArray = elem[key];
var proxy = null;
var arrayIndex;
if (!!proxyHelperArray)
{
for (var arrayIterIndex = 0; arrayIterIndex < proxyHelperArray.length; arrayIterIndex++)
{
var currentProxyHelper = proxyHelperArray[arrayIterIndex];
if (currentProxyHelper.matches(func))
{
arrayIndex = arrayIterIndex;
proxy = currentProxyHelper.getProxy();
break;
}
}
}
if (proxy)
{
elem.detachEvent( "on" + evtName, proxy );
proxyHelperArray.splice(arrayIndex, 1);
if (bCapture)
{
elem.releaseCapture();
}
}
}
EventTargetIE.prototype.dispatchEvent = function(evt)
{
return this.m_node.fireEvent( "on" + evt.type, evt );
}
function EventIE(eventObj, node)
{
EventIE.prototype.CAPTURING_PHASE = 1;
EventIE.prototype.AT_TARGET = 2;
EventIE.prototype.BUBBLING_PHASE = 3;
this.m_event = eventObj;
this.type = eventObj.type;
this.target = eventObj.srcElement;
this.currentTarget = node;
this.eventPhase = EventIE.prototype.BUBBLING_PHASE;
this.bubbles = true;
this.cancelable = true;
this.timeStamp = new Date();
this.view = window;
this.detail = 0;
this.screenX = eventObj.screenX;
this.screenY = eventObj.screenY;
this.clientX = eventObj.clientX;
this.clientY = eventObj.clientY;
this.pageX = wdk.pos.clientLeftToPageLeft( eventObj.clientX );
this.pageY = wdk.pos.clientTopToPageTop( eventObj.clientY );
this.ctrlKey = eventObj.ctrlKey;
this.shiftKey = eventObj.shiftKey;
this.altKey = eventObj.altKey;
this.metaKey = false;
this.keyCode = eventObj.keyCode;
this.relatedTarget = (eventObj.fromElement) ? eventObj.fromElement : eventObj.toElement;
switch (eventObj.button)
{
case 1:
this.button = 0; break;
case 2:
this.button = 2; break;
case 4:
this.button = 1; break;
}
}
EventIE.prototype.stopPropagation = function()
{
this.m_event.cancelBubble = true;
}
EventIE.prototype.preventDefault = function()
{
this.m_event.returnValue = false;
}
EventIE.prototype.initEvent = function(eventTypeArg, canBubbleArg, cancelableArg)
{
this.m_event.type = eventTypeArg;
this.m_event.bubbles = canBubbleArg;
this.m_event.cancelable = cancelableArg;
}
var eTarget = this.getEventTarget(window);
eTarget.addEventListener("unload", function(){listenerRegistry.cleanup();}, false);
}
wdk.forms = new function()
{
var excludedFieldTypes = {
"button":true, "submit":true, "reset":true,
"image":true, "file":true, "fieldset":true};
this.getFormFields = function(formNode, formFilter)
{
var fields = new wdk.lang.MultiMap();
for (var i = 0; i < formNode.elements.length; i++)
{
var node = formNode.elements[i];
if (node != null && formFilter(node))
{
var name = node.name || node.id;
if (!name)
{
continue;
}
var type = node.type.toLowerCase();
if (type == "checkbox" || type == "radio")
{
if (node.checked)
{
fields.add(name, encodeURIComponent(node.value));
}
}
else if (type == "select-multiple")
{
for (var j = 0; j < node.options.length; j++)
{
if (node.options[j].selected)
{
fields.add(name, encodeURIComponent(node.options[j].value));
}
}
}
else
{
fields.add(name, encodeURIComponent(node.value));
}
}
}
return fields;
}
this.isExcludedField = function(node)
{
return (node.tagName.toLowerCase() == "fieldset"
|| excludedFieldTypes[node.type.toLowerCase()] == true);
}
this.filterSystemFields = function(node)
{
var name = node.id || node.name;
var system = !!name.match(/^__dmf/);
var excluded = wdk.forms.isExcludedField(node);
return (system && !excluded);
}
this.filterAllFields = function(node)
{
return !wdk.forms.isExcludedField(node);
}
this.addKeyStates = function(mmap)
{
var wnd = getTopLevelWnd();
if (typeof(wnd.shiftKeyPressed) != "undefined" && wnd.shiftKeyPressed)
{
mmap.add("shiftKeyPressed", "true");
}
if (typeof(wnd.ctrlKeyPressed) != "undefined" && wnd.ctrlKeyPressed)
{
mmap.add("ctrlKeyPressed", "true");
}
if (typeof(wnd.altKeyPressed) != "undefined" && wnd.altKeyPressed)
{
mmap.add("altKeyPressed", "true");
}
}
this.submitInline = function(formNode, prefs, filter)
{
if (typeof filter == "undefined")
{
filter = wdk.forms.filterAllFields;
}
prefs.setMethod(formNode.method);
prefs.setUrl(formNode.action);
prefs.addParameters(wdk.forms.getFormFields(formNode, filter));
InlineRequestEngine.sendRequest(prefs);
}
}
wdk.lang = new function()
{
this.find = function(array, value, identity)
{
var end = array.length;
if (identity)
{
for (var i=0; i<end; i++)
{
if(array[i] === value)
{
return i;
}
}
}
else
{
for (var i=0; i<end; i++)
{
if(array[i] == value)
{
return i;
}
}
}
return -1;
}
this.hitch = function(obj, fun)
{
var newFun = (typeof(fun) == "string" ? obj[fun] : fun) || function(){};
return function() {
return newFun.apply(obj, arguments);
}
}
this.MultiMap = MultiMap;
function MultiMap()
{
this.map = {};
}
MultiMap.prototype.getMap = function()
{
return this.map;
}
MultiMap.prototype.setMap = function(newMap)
{
this.map = {};
this.addMap(newMap);
}
MultiMap.prototype.addMap = function(newMap)
{
// If it's a MultiMap, get the actual map
if (newMap instanceof wdk.lang.MultiMap)
{
newMap = newMap.getMap();
}
for (var key in newMap)
{
var oldValues = this.map[key];
var newValues = newMap[key];
if (typeof oldValues == "undefined")
{
if (!(newValues instanceof Array))
{
newValues = [newValues];
}
this.map[key] = newValues;
}
else
{
if (!(newValues instanceof Array))
{
oldValues.push(newValues);
}
else
{
this.map[key] = oldValues.concat(newValues);
}
}
}
}
MultiMap.prototype.add = function(key, value)
{
var values = this.map[key];
if (!values)
{
values = [];
this.map[key] = values;
}
values.push(value);
}
MultiMap.prototype.set = function(key, value)
{
this.map[key] = [value];
}
MultiMap.prototype.get = function(key)
{
return this.map[key];
}
}
wdk.common = new function()
{
this.getSafeFunction = function(name, value, context)
{
if (typeof context == "undefined" || context == null)
{
context = window;
}
var fn = value;
if (fn && (typeof fn == "string" || fn instanceof String))
{
fn = context[fn];
}
if (fn && (typeof fn == "function" || fn instanceof Function))
{
return fn;
}
if (Trace_INLINEREQUEST)
{
Trace_println("Invalid " + name + " function specified: " + value);
}
return (function() {});
}
this.UrlBuilder = UrlBuilder;
function UrlBuilder (baseUrl)
{
this.baseUrl = baseUrl;
this.parameters = new wdk.lang.MultiMap();
}
UrlBuilder.prototype.setParameters = function(parameters)
{
if (!(parameters instanceof wdk.lang.MultiMap))
{
var map = new wdk.lang.MultiMap();
map.setMap(parameters);
parameters = map;
}
this.parameters = parameters;
}
UrlBuilder.prototype.addParameter = function(name, value)
{
this.parameters.add(name, value);
}
UrlBuilder.prototype.getQueryString = function()
{
var queryString = "";
var map = this.parameters.getMap();
for (var name in map)
{
var values = map[name];
for (var i = 0; i < values.length; i++)
{
queryString += name;
queryString += "=";
queryString += values[i];
queryString += "&";
}
}
return queryString.substr(0, queryString.length - 1);
}
UrlBuilder.prototype.getBaseUrl = function()
{
return this.baseUrl;
}
UrlBuilder.prototype.getUrl = function()
{
var url = this.baseUrl;
var queryString = this.getQueryString();
if (queryString && queryString.length > 0)
{
url += (url.indexOf('?') == -1 ? "?" : "&");
url += queryString;
}
return url;
}
this.Timeout = Timeout;
function Timeout(func, period, bRepeating)
{
this.fn = func;
this.period = period;
this.bRepeating = bRepeating;
this.timerId = null;
}
Timeout.prototype.set = function()
{
this.timerId = (this.bRepeating) ? window.setInterval(this.fn, this.period) : window.setTimeout(this.fn, this.period);
}
Timeout.prototype.cancel = function()
{
if (this.timerId != null)
{
if (this.bRepeating)
{
window.clearInterval(this.timerId);
}
else
{
window.clearTimeout(this.timerId);
}
this.timerId = null;
}
}
Timeout.prototype.isSet = function()
{
return (this.timerId != null);
}
Timeout.prototype.reset = function()
{
if (this.isSet())
{
this.cancel();
}
this.set();
}
this.setProperty = function (obj, prop, val)
{
if (!obj || !prop)
{
return false;
}
var props = prop.split('.');
for (var i=0; i < props.length - 1; i++)
{
obj = obj[props[i]];
if(!obj)
{
return false;
}
}
obj[props[props.length - 1]] = val;
return true;
}
this.getProperty = function (obj, prop)
{
if (!obj || !prop)
{
return false;
}
var props = prop.split('.');
for (var i=0; i < props.length - 1 ; i++)
{
obj = obj[props[i]];
if(!obj)
{
return false;
}
}
return obj[props[props.length - 1]];
}
}
} // end if (typeof wdk == "undefined")
wdk.locale = new function()
{
this.isRightToLeft = function()
{
if(typeof(g_RTLLocale) == "undefined" || g_RTLLocale == null)
{
return false;
}
if(g_RTLLocale == "true")
{
return true;
}
else
{
return false;
}
}
}

