var jpf = {
VERSION:'1.0rc1',
CDN            : "",
READY          : false,
NODE_HIDDEN    : 101,
NODE_VISIBLE   : 102,
NODE_MEDIAFLOW : 103,
NODE_ELEMENT                : 1,
NODE_ATTRIBUTE              : 2,
NODE_TEXT                   : 3,
NODE_CDATA_SECTION          : 4,
NODE_ENTITY_REFERENCE       : 5,
NODE_ENTITY                 : 6,
NODE_PROCESSING_INSTRUCTION : 7,
NODE_COMMENT                : 8,
NODE_DOCUMENT               : 9,
NODE_DOCUMENT_TYPE          : 10,
NODE_DOCUMENT_FRAGMENT      : 11,
NODE_NOTATION               : 12,
KEYBOARD       : 2,
KEYBOARD_MOUSE : true,
SUCCESS : 1,
TIMEOUT : 2,
ERROR   : 3,
OFFLINE : 4,
debug         : false,
includeStack  : [],
initialized   : false,
autoLoadSkin  : false,
crypto        : {}, 
_GET          : {},
basePath      : "./",
ns : {
jpf    : "http://www.javeline.com/2005/jml",
jml    : "http://www.javeline.com/2005/jml",
xsd    : "http://www.w3.org/2001/XMLSchema",
xhtml  : "http://www.w3.org/1999/xhtml",
xslt   : "http://www.w3.org/1999/XSL/Transform",
xforms : "http://www.w3.org/2002/xforms",
ev     : "http://www.w3.org/2001/xml-events"
},
browserDetect : function(){
if (this.$bdetect)
return;
this.$bdetect = true;
var sAgent = navigator.userAgent.toLowerCase();
this.isOpera = sAgent.indexOf("opera") != -1;
this.isKonqueror = sAgent.indexOf("konqueror") != -1;
this.isSafari    = !this.isOpera && ((navigator.vendor
&& navigator.vendor.match(/Apple/) ? true : false)
|| sAgent.indexOf("safari") != -1 || this.isKonqueror);
this.isSafariOld = false;
if (this.isSafari) {
var matches  = sAgent.match(/applewebkit\/(\d+)/);
if (matches)
this.isSafariOld = parseInt(matches[1]) < 420;
}
this.isChrome    = sAgent.indexOf("chrome/") != -1;
this.isGecko     = !this.isOpera && !this.isSafari && sAgent.indexOf("gecko") != -1;
this.isGecko3    = this.isGecko && sAgent.indexOf("firefox/3") != -1;
var found;
this.isIE        = document.all && !this.isOpera && !this.isSafari ? true : false;
this.isIE8       = this.isIE && sAgent.indexOf("msie 8.") != -1 && (found = true);
this.isIE7       = this.isIE && !found && sAgent.indexOf("msie 7.") != -1 && (found = true);
this.isIE6       = this.isIE && !found && sAgent.indexOf("msie 6.") != -1 && (found = true);
this.isIE55      = this.isIE && !found && sAgent.indexOf("msie 5.5") != -1 && (found = true);
this.isIE50      = this.isIE && !found && sAgent.indexOf("msie 5.0") != -1 && (found = true);
this.isWin       = sAgent.indexOf("win") != -1 || sAgent.indexOf("16bit") != -1;
this.isMac       = sAgent.indexOf("mac") != -1;
this.isAIR       = sAgent.indexOf("adobeair") != -1;
},
setCompatFlags : function(){
this.TAGNAME                   = jpf.isIE ? "baseName" : "localName";
this.supportVML                = jpf.isIE;
this.supportCanvas             = !jpf.isIE;
this.supportSVG                = !jpf.isIE;
this.styleSheetRules           = jpf.isIE ? "rules" : "cssRules";
this.brokenHttpAbort           = jpf.isIE6;
this.canUseHtmlAsXml           = jpf.isIE;
this.supportNamespaces         = !jpf.isIE;
this.cannotSizeIframe          = jpf.isIE;
this.supportOverflowComponent  = jpf.isIE;
this.hasEventSrcElement        = jpf.isIE;
this.canHaveHtmlOverSelects    = !jpf.isIE6 && !jpf.isIE5;
this.hasInnerText              = jpf.isIE;
this.hasMsRangeObject          = jpf.isIE;
this.hasContentEditable        = jpf.isIE || jpf.isOpera;
this.descPropJs                = jpf.isIE;
this.hasClickFastBug           = jpf.isIE;
this.hasExecScript             = window.execScript ? true : false;
this.canDisableKeyCodes        = jpf.isIE;
this.hasTextNodeWhiteSpaceBug  = jpf.isIE;
this.hasCssUpdateScrollbarBug  = jpf.isIE;
this.canUseInnerHtmlWithTables = !jpf.isIE;
this.hasSingleResizeEvent      = !jpf.isIE;
this.hasStyleFilters           = jpf.isIE;
this.supportOpacity            = !jpf.isIE;
this.supportPng24              = !jpf.isIE6 && !jpf.isIE5;
this.cantParseXmlDefinition    = jpf.isIE50;
this.hasDynamicItemList        = !jpf.isIE || jpf.isIE7;
this.canImportNode             = jpf.isIE;
this.hasSingleRszEvent         = !jpf.isIE;
this.hasXPathHtmlSupport       = !jpf.isIE;
this.hasFocusBug               = jpf.isIE;
this.hasReadyStateBug          = jpf.isIE50;
this.dateSeparator             = jpf.isIE ? "-" : "/";
this.canCreateStyleNode        = !jpf.isIE;
this.supportFixedPosition      = !jpf.isIE || jpf.isIE7;
this.hasHtmlIdsInJs            = jpf.isIE || jpf.isSafari;
this.needsCssPx                = !jpf.isIE;
this.hasAutocompleteXulBug     = jpf.isGecko;
this.mouseEventBuffer          = jpf.isIE ? 20 : 6;
this.hasComputedStyle          = typeof document.defaultView != "undefined"
&& typeof document.defaultView.getComputedStyle != "undefined";
this.locale                    = (this.isIE
? navigator.userLanguage
: navigator.language).toLowerCase();
this.maxHttpRetries = this.isOpera ? 0 : 3;
this.dynPropMatch = new RegExp();
this.dynPropMatch.compile("^[{\\[].*[}\\]]$");
this.percentageMatch = new RegExp();
this.percentageMatch.compile("([\\-\\d\\.]+)\\%", "g");
},
extend : function(dest, src){
var prop, i, x = !dest.notNull;
if (arguments.length == 2) {
for (prop in src) {
if (x || src[prop])
dest[prop] = src[prop];
}
return dest;
}
for (i = 1; i < arguments.length; i++) {
src = arguments[i];
for (prop in src) {
if (x || src[prop])
dest[prop] = src[prop];
}
}
return dest;
},
start : function(){
this.started = true;
var sHref = location.href.split("#")[0].split("?")[0];
this.host     = location.hostname && sHref.replace(/(\/\/[^\/]*)\/.*$/, "$1");
this.hostPath = sHref.replace(/\/[^\/]*$/, "") + "/";
this.CWD      = sHref.replace(/^(.*\/)[^\/]*$/, "$1") + "/";
this.browserDetect();
this.setCompatFlags();
if (this.isIE) jpf.runIE();
if (this.isSafari) jpf.runSafari();
if (this.isOpera) jpf.runOpera();
if (this.isGecko || !this.isIE && !this.isSafari && !this.isOpera)
jpf.runGecko();
this.oHttp = new this.http();
this.Init.addConditional(this.loadIncludes, jpf, ['body', 'xmldb']);
try {
if (jpf.isIE)
document.execCommand("BackgroundImageCache", false, true);
}
catch(e) {};
this.root = true;
},
startDependencies : function(){
if (location.protocol != "file:") {
jpf.console.warn("You are serving multiple files from a (local)\
webserver - please consider using the file:// protocol to \
load your files, because that will make your application \
load several times faster.\
On a webserver, we recommend using a release or debug build \
of Javeline Platform.");
}
jpf.console.info("Loading Dependencies...");
var i;
for (i = 0; i < this.KernelModules.length; i++)
jpf.include("core/" + this.KernelModules[i], true);
for (i = 0; i < this.TelePortModules.length; i++)
jpf.include("elements/teleport/" + this.TelePortModules[i], true);
for (i = 0; i < this.Elements.length; i++) {
var c = this.Elements[i];
jpf.include("elements/" + c + ".js", true);
}
jpf.Init.interval = setInterval(
"if (jpf.checkLoadedDeps()) {\
clearInterval(jpf.Init.interval);\
jpf.start();\
}", 100);
},
nsqueue   : {},
namespace : function(name, oNamespace){
try{
eval("jpf." + name + " = oNamespace");
delete this.nsqueue[name];
for (var ns in this.nsqueue) {
if (ns.indexOf(name) > -1) {
this.namespace(ns, this.nsqueue[ns]);
}
}
return true;
}catch(e){
this.nsqueue[name] = oNamespace;
return false;
}
},
findPrefix : function(xmlNode, xmlns){
var docEl;
if (xmlNode.nodeType == 9) {
if (!xmlNode.documentElement) return false;
if (xmlNode.documentElement.namespaceURI == xmlns)
return xmlNode.prefix || xmlNode.scopeName;
docEl = xmlNode.documentElement;
}
else {
if (xmlNode.namespaceURI == xmlns)
return xmlNode.prefix || xmlNode.scopeName;
docEl = xmlNode.ownerDocument.documentElement;
if (docEl && docEl.namespaceURI == xmlns)
return xmlNode.prefix || xmlNode.scopeName;
while (xmlNode.parentNode) {
xmlNode = xmlNode.parentNode;
if (xmlNode.namespaceURI == xmlns)
return xmlNode.prefix || xmlNode.scopeName;
}
}
if (docEl) {
for (var i=0; i<docEl.attributes.length; i++) {
if (docEl.attributes[i].nodeValue == xmlns)
return docEl.attributes[i][jpf.TAGNAME]
}
}
return false;
},
importClass : function(ref, strip, win){
if (!ref)
throw new Error(jpf.formatErrorString(1018, null,
"importing class",
"Could not load reference. Reference is null"));
if (!strip)
return jpf.exec(ref.toString(), win);
var q = ref.toString().replace(/^\s*function\s*\w*\s*\([^\)]*\)\s*\{/, "");
q = q.replace(/\}\s*$/, "");
return jpf.exec(q, win);
},
toString : function(){
return "[Javeline (jpf)]";
},
all : [],
inherit : function(classRef){
for (var i=0; i<arguments.length; i++) {
arguments[i].call(this);
}
return this;
},
makeClass : function(oBlank){
if (oBlank.inherit) return;
oBlank.inherit = this.inherit;
oBlank.inherit(jpf.Class);
oBlank.uniqueId = this.all.push(oBlank) - 1;
},
uniqueHtmlIds : 0,
setUniqueHtmlId : function(oHtml){
oHtml.setAttribute("id", "q" + this.uniqueHtmlIds++);
},
getUniqueId : function(oHtml){
return this.uniqueHtmlIds++;
},
register : function(o, tagName, nodeFunc){
o.tagName  = tagName;
o.nodeFunc = nodeFunc || jpf.NODE_HIDDEN;
o.$domHandlers  = {"remove" : [], "insert" : [], "reparent" : [], "removechild" : []};
o.$propHandlers = {}; 
if (nodeFunc != jpf.NODE_HIDDEN) {
o.$booleanProperties = {
"visible"          : true,
"focussable"       : true,
"disabled"         : true,
"disable-keyboard" : true
}
o.$supportedProperties = [
"draggable", "resizable",
"focussable", "zindex", "disabled", "tabindex",
"disable-keyboard", "contextmenu", "visible", "autosize",
"loadjml", "actiontracker", "alias"];
}
else {
o.$booleanProperties = {}; 
o.$supportedProperties = []; 
}
if (!o.inherit) {
o.inherit = this.inherit;
o.inherit(jpf.Class);
o.uniqueId = this.all.push(o) - 1;
}
},
lookup : function(uniqueId){
return this.all[uniqueId];
},
findHost : function(o){
while (o && !o.host && o.parentNode)
o = o.parentNode;
return (o && o.host && typeof o.host != "string") ? o.host : false;
},
setReference : function(name, o){
return self[name] && self[name].hasFeature
? 0
: (self[name] = o);
},
console : {
debug : function(msg, subtype, data){
},
time : function(msg, subtype, data){
},
log : function(msg, subtype, data){
},
info : function(msg, subtype, data){
},
warn : function(msg, subtype, data){
},
error : function(msg, subtype, data){
},
dir : function(obj){
this.info(jpf.vardump(obj, null, false).replace(/ /g, "&nbsp;").replace(/</g, "&lt;"));
}
},
formatErrorString : function(number, control, process, message, jmlContext, outputname, output){
jpf.lastErrorMessage = message;
return message;
},
include : function(sourceFile, doBase, type){
jpf.console.info("including js file: " + sourceFile);
var sSrc = doBase ? (jpf.basePath || "") + sourceFile : sourceFile;
if (jpf.isSafariOld || jpf.isSafari && !jpf.started) {
document.write('<script type="text/javascript" src="' + sSrc + '"><\/script>');
}
else {
var head     = document.getElementsByTagName("head")[0];
var elScript = document.createElement("script");
elScript.defer = true;
if (type)
elScript.setAttribute("_jpf_type", type);
elScript.src   = sSrc;
head.appendChild(elScript);
}
},
Init : {
queue : [],
cond  : {
combined : []
},
done  : {},
add   : function(func, o){
if (this.inited)
func.call(o);
else if (func)
this.queue.push([func, o]);
},
addConditional : function(func, o, strObj){
if (typeof strObj != "string") {
if (this.checkCombined(strObj))
return func.call(o);
this.cond.combined.push([func, o, strObj]);
}
else if (self[strObj]) {
func.call(o);
}
else {
if (!this.cond[strObj])
this.cond[strObj] = [];
this.cond[strObj].push([func, o]);
this.checkAllCombined();
}
},
checkAllCombined : function(){
for (var i=0; i<this.cond.combined.length; i++) {
if (!this.cond.combined[i]) continue;
if (this.checkCombined(this.cond.combined[i][2])) {
this.cond.combined[i][0].call(this.cond.combined[i][1])
this.cond.combined[i] = null;
}
}
},
checkCombined : function(arr){
for (var i=0; i<arr.length; i++) {
if (!this.done[arr[i]])
return false;
}
return true;
},
run : function(strObj){
this.inited = this.done[strObj] = true;
this.checkAllCombined();
var data = strObj ? this.cond[strObj] : this.queue;
if (!data) return;
for (var i = 0; i < data.length; i++)
data[i][0].call(data[i][1]);
}
},
getJmlDocFromString : function(xmlString){
var str = xmlString.replace(/\<\!DOCTYPE[^>]*>/, "").replace(/&nbsp;/g, " ")
.replace(/^[\r\n\s]*/, "").replace(/<\s*\/?\s*(?:\w+:\s*)[\w-]*[\s>\/]/g,
function(m){ return m.toLowerCase(); });
if (!this.supportNamespaces)
str = str.replace(/xmlns\=\"[^"]*\"/g, "");
var xmlNode = jpf.getXmlDom(str, null, jpf.debug);
var nodes = xmlNode.selectNodes("//@*[not(contains(local-name(), '.')) and not(translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = local-name())]");
for (var i=0; i<nodes.length; i++) {
(nodes[i].ownerElement || nodes[i].selectSingleNode(".."))
.setAttribute(nodes[i].nodeName.toLowerCase(), nodes[i].nodeValue);
}
return xmlNode;
},
parseStrategy : 0,
loadIncludes : function(docElement){
var isEmptyDocument = false;
if (this.parseStrategy == 21 || !this.parseStrategy && !docElement) {
return jpf.oHttp.get((document.body.getAttribute("xmlurl") || location.href).split(/#/)[0],
function(xmlString, state, extra){
if (state != jpf.SUCCESS) {
var oError;
if (extra.tpModule.retryTimeout(extra, state, null, oError) === true)
return true;
throw oError;
}
var xmlNode = jpf.getJmlDocFromString(xmlString);
if (jpf.isIE)
document.body.innerHTML ="";
else {
var nodes = document.body.childNodes;
for (var i=nodes.length-1; i>=0; i--)
nodes[i].parentNode.removeChild(nodes[i]);
}
return jpf.loadIncludes(xmlNode);
}, {ignoreOffline: true});
}
var prefix = jpf.findPrefix(docElement, jpf.ns.jml);
if (jpf.isSafariOld || true)
prefix = "j";
jpf.AppData = jpf.supportNamespaces
? docElement.createElementNS(jpf.ns.jml, prefix + ":application")
: docElement.createElement(prefix + ":application");
var i, nodes;
var head = $xmlns(docElement, "head", jpf.ns.xhtml)[0];
if (head) {
nodes = head.childNodes;
for (i = nodes.length-1; i >= 0; i--)
if (nodes[i].namespaceURI && nodes[i].namespaceURI != jpf.ns.xhtml)
jpf.AppData.insertBefore(nodes[i], jpf.AppData.firstChild);
}
var body = (docElement.body
? docElement.body
: $xmlns(docElement, "body", jpf.ns.xhtml)[0]);
for (i = 0; i < body.attributes.length; i++)
jpf.AppData.setAttribute(body.attributes[i].nodeName,
body.attributes[i].nodeValue);
nodes = body.childNodes;
for (i = nodes.length - 1; i >= 0; i--)
jpf.AppData.insertBefore(nodes[i], jpf.AppData.firstChild);
docElement.documentElement.appendChild(jpf.AppData); 
jpf.loadJmlIncludes(jpf.AppData);
if ($xmlns(jpf.AppData, "loader", jpf.ns.jml).length) {
jpf.loadScreen = {
show : function(){
this.oExt.style.display = "block";
},
hide : function(){
this.oExt.style.display = "none";
}
}
if (jpf.isGecko || jpf.isSafari)
document.body.innerHTML = "";
if (jpf.isSafariOld) {
var q = jpf.getFirstElement(
$xmlns(jpf.AppData, "loader", jpf.ns.jml)[0]).serialize();
document.body.insertAdjacentHTML("beforeend", q);
jpf.loadScreen.oExt = document.body.lastChild;
}
else
{
var htmlNode = jpf.getFirstElement(
$xmlns(jpf.AppData, "loader", jpf.ns.jml)[0]);
if (htmlNode.ownerDocument == document)
jpf.loadScreen.oExt = document.body.appendChild(
htmlNode.cloneNode(true));
else {
document.body.insertAdjacentHTML("beforeend", htmlNode.xml
|| htmlNode.serialize());
jpf.loadScreen.oExt = document.body.lastChild;
}
}
}
document.body.style.display = "block"; 
if (!self.ERROR_HAS_OCCURRED) {
jpf.Init.interval = setInterval(function(){
if (jpf.checkLoaded())
jpf.initialize()
}, 20);
}
},
checkForJmlNamespace : function(xmlNode){
if (!xmlNode.ownerDocument.documentElement)
return false;
var nodes = xmlNode.ownerDocument.documentElement.attributes;
for (var found = false, i=0; i<nodes.length; i++) {
if (nodes[i].nodeValue == jpf.ns.jml) {
found = true;
break;
}
}
return found;
},
loadJmlIncludes : function(xmlNode, doSync){
var i, nodes, path;
var basePath = jpf.getDirname(xmlNode.getAttribute("filename")) || jpf.hostPath;
nodes = $xmlns(xmlNode, "include", jpf.ns.jml);
if (nodes.length) {
xmlNode.setAttribute("loading", "loading");
for (i = nodes.length - 1; i >= 0; i--) {
path = jpf.getAbsolutePath(basePath, nodes[i].getAttribute("src"));
jpf.loadJmlInclude(nodes[i], doSync, path);
}
}
else
xmlNode.setAttribute("loading", "done");
nodes = $xmlns(xmlNode, "skin", jpf.ns.jml);
for (i = 0; i < nodes.length; i++) {
if (!nodes[i].getAttribute("src") && !nodes[i].getAttribute("name")
|| nodes[i].childNodes.length)
continue;
path = nodes[i].getAttribute("src")
? jpf.getAbsolutePath(basePath, nodes[i].getAttribute("src"))
: jpf.getAbsolutePath(basePath, nodes[i].getAttribute("name")) + "/index.xml";
jpf.loadJmlInclude(nodes[i], doSync, path, true);
nodes[i].setAttribute("j_preparsed", "9999")
}
if (!nodes.length && !jpf.skins.skins["default"] && jpf.autoLoadSkin) {
jpf.console.warn("No skin file found, attempting to autoload the \
default skin file: skins.xml");
jpf.loadJmlInclude(null, doSync, "skins.xml", true);
}
return true;
},
loadJmlInclude : function(node, doSync, path, isSkin){
this.oHttp.get(path || jpf.getAbsolutePath(jpf.hostPath, node.getAttribute("src")),
function(xmlString, state, extra){
if (state != jpf.SUCCESS) {
var oError;
if (extra.tpModule.retryTimeout(extra, state, null, oError) === true)
return true;
if (!node) {
jpf.console.warn("Could not autload skin.");
jpf.includeStack[extra.userdata[1]] = true;
return;
}
throw oError;
}
var xmlNode, isTeleport;
if (!isSkin) {
xmlNode = jpf.getJmlDocFromString(xmlString).documentElement;
var tagName = xmlNode[jpf.TAGNAME];
if (tagName == "skin")
isSkin = true;
else if (tagName == "teleport")
isTeleport = true;
else if(tagName != "application") {
throw new Error(jpf.formatErrorString(0, null,
"Loading Includes",
"Could not find handler to parse include file for '"
+ xmlNode[jpf.TAGNAME]
+ "' expected 'skin' or 'application'", node));
}
}
if (isSkin) {
if (xmlString.indexOf('xmlns="http://www.w3.org/1999/xhtml"') > -1){
xmlString = xmlString.replace('xmlns="http://www.w3.org/1999/xhtml"', '');
}
xmlNode = jpf.getJmlDocFromString(xmlString).documentElement;
jpf.skins.Init(xmlNode, node, path);
jpf.includeStack[extra.userdata[1]] = true;
if (jpf.isOpera && extra.userdata[0] && extra.userdata[0].parentNode) 
extra.userdata[0].parentNode.removeChild(extra.userdata[0]);
}
else if (isTeleport) {
jpf.teleport.loadJml(xmlNode);
jpf.includeStack[extra.userdata[1]] = true;
}
else {
jpf.includeStack[extra.userdata[1]] = xmlNode;
extra.userdata[0].setAttribute("iid", extra.userdata[1]);
}
xmlNode.setAttribute("filename", extra.url);
jpf.loadJmlIncludes(xmlNode); 
}, {
async         : !doSync,
userdata      : [node, jpf.includeStack.push(false) - 1],
ignoreOffline : true
});
},
checkLoaded : function(){
for (var i = 0; i < jpf.includeStack.length; i++) {
if (!jpf.includeStack[i]) {
jpf.console.info("Waiting for: [" + i + "] " + jpf.includeStack[i]);
return false;
}
}
if (!document.body) return false;
jpf.console.info("Dependencies loaded");
return true;
},
initialize : function(){
jpf.console.info("Initializing...");
clearInterval(jpf.Init.interval);
jpf.Init.run(); 
{
if (jpf.JmlParser && jpf.AppData)
jpf.JmlParser.parse(jpf.AppData);
if (jpf.loadScreen && jpf.appsettings.autoHideLoading)
jpf.loadScreen.hide();
}
},
addDomLoadEvent: function(func) {
if (!this.$bdetect)
this.browserDetect();
var load_events = [],
load_timer,
done   = arguments.callee.done,
exec,
init   = function () {
if (done) return;
clearInterval(load_timer);
load_timer = null;
done       = true;
var len = load_events.length;
while (len--) {
(load_events.shift())();
}
};
if (func && !load_events[0]) {
if (document.addEventListener && !jpf.isOpera) {
window.addEventListener("DOMContentLoaded", init, false);
}
else if (jpf.isIE && window == top) {
load_timer = setInterval(function() {
try {
document.documentElement.doScroll("left");
}
catch(error) {
setTimeout(arguments.callee, 0);
return;
}
init();
}, 10);
}
else if (jpf.isOpera) {
document.addEventListener( "DOMContentLoaded", function () {
load_timer  = setInterval(function() {
for (var i = 0; i < document.styleSheets.length; i++) {
if (document.styleSheets[i].disabled)
return;
}
init();
}, 10);
}, false);
}
else if (jpf.isSafari) {
var aSheets = documents.getElementsByTagName("link");
for (var i = aSheets.length; i >= 0; i++) {
if (!aSheets[i] || aSheets[i].getAttribute("rel") != "stylesheet")
aSheets.splice(i, 0);
}
var iSheets = aSheets.length;
load_timer  = setInterval(function() {
if (/loaded|complete/.test(document.readyState)
&& document.styleSheets.length == iSheets)
init(); 
}, 10);
}
else {
var old_onload = window.onload;
window.onload  = function () {
init();
if (old_onload)
old_onload();
};
}
}
load_events.push(func);
},
destroy : function(exclude){
this.isDestroying = true;
this.popup.destroy();
for (i = 0; i < this.all.length; i++) {
if (this.all[i] && this.all[i] != exclude && this.all[i].destroy)
this.all[i].destroy(false);
}
for (i = this.$jmlDestroyers.length - 1; i >= 0; i--)
this.$jmlDestroyers[i].call(this);
this.$jmlDestroyers = undefined;
jpf.teleport.destroy();
if (jpf.xmldb)
jpf.xmldb.unbind(jpf.window);
this.isDestroying = false;
}
};
var $xmlns = function(xmlNode, tag, xmlns, prefix){
if (!jpf.supportNamespaces) {
if (!prefix)
prefix = jpf.findPrefix(xmlNode, xmlns);
if (xmlNode.style || xmlNode == document)
return xmlNode.getElementsByTagName(tag)
else {
if (prefix)
(xmlNode.nodeType == 9 ? xmlNode : xmlNode.ownerDocument)
.setProperty("SelectionNamespaces",
"xmlns:" + prefix + "='" + xmlns + "'");
return xmlNode.selectNodes(".//" + (prefix ? prefix + ":" : "") + tag);
}
}
else
return xmlNode.getElementsByTagNameNS(xmlns, tag);
}
jpf.Init.run('jpf');
jpf.XmlDatabase = function(){
this.xmlDocTag    = "j_doc";
this.xmlIdTag     = "j_id";
this.xmlListenTag = "j_listen";
this.htmlIdTag    = "id";
var xmlDocLut     = [];
this.getElementById = function(id, doc){
if (!doc)
doc = xmlDocLut[id.split("\|")[0]];
if (!doc)
return false;
return doc.selectSingleNode("descendant-or-self::node()[@"
+ this.xmlIdTag + "='" + id + "']");
};
this.getNode = function(htmlNode){
if (!htmlNode || !htmlNode.getAttribute(this.htmlIdTag))
return false;
return this.getElementById(htmlNode.getAttribute(this.htmlIdTag)
.split("\|", 2).join("|"));
};
this.getNodeById = function(id, doc){
var q = id.split("\|");
q.pop();
return this.getElementById(q.join("|"), doc);
};
this.getDocumentById = function(id){
return xmlDocLut[id];
};
this.getDocument = function(node){
return xmlDocLut[node.getAttribute(this.xmlIdTag).split("\|")[0]];
};
this.getID = function(xmlNode, o){
return xmlNode.getAttribute(this.xmlIdTag) + "|" + o.uniqueId;
};
this.getChildNumber = function(node){
var p = node.parentNode;
for (var i = 0; i < p.childNodes.length; i++)
if (p.childNodes[i] == node)
return i;
};
this.isChildOf = function(pNode, childnode, orItself){
if (!pNode || !childnode)
return false;
if (childnode.nodeType == 2)
childnode = childnode.selectSingleNode("..");
if (orItself && pNode == childnode)
return true;
var loopnode = childnode.parentNode;
while(loopnode){
if(loopnode == pNode)
return true;
loopnode = loopnode.parentNode;
}
return false;
};
this.isOnlyChild = function(node, nodeType){
if (!node || !node.parentNode || nodeType && nodeType.indexOf(node.nodeType) == -1)
return false;
var i, l, cnode, nodes = node.parentNode.childNodes;
for (i = 0, l = nodes.length; i < l; i++) {
cnode = nodes[i];
if (cnode.nodeType == 1 && cnode != node)
return false;
if (cnode.nodeType == 3 && !cnode.nodeValue.trim())
return false;
}
return true;
};
this.findHTMLNode = function(xmlNode, oComp){
do {
if (xmlNode.nodeType == 1 && xmlNode.getAttribute(this.xmlIdTag)) {
return oComp.getNodeFromCache(xmlNode.getAttribute(this.xmlIdTag)
+ "|" + oComp.uniqueId);
}
if (xmlNode == oComp.xmlRoot)
return null;
xmlNode = xmlNode.parentNode;
}
while (xmlNode && xmlNode.nodeType != 9)
return null;
};
this.findXMLNode = function(htmlNode){
if (!htmlNode)
return false;
while (htmlNode && htmlNode.nodeType == 1
&& htmlNode.tagName.toLowerCase() != "body"
&& !htmlNode.getAttribute("id")
|| htmlNode && htmlNode.nodeType == 1
&& htmlNode.getAttribute(this.htmlIdTag)
&& htmlNode.getAttribute(this.htmlIdTag).match(/^q/)) {
if (htmlNode.host && htmlNode.host.oExt == htmlNode)
return htmlNode.host.xmlRoot;
htmlNode = htmlNode.parentNode;
}
if (!htmlNode || htmlNode.nodeType != 1)
return false;
if (htmlNode.tagName.toLowerCase() == "body")
return false;
return this.getNode(htmlNode);
};
this.getElement = function(parent, nr){
var nodes = parent.childNodes;
for (var j = 0, i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1)
continue;
if (j++ == nr)
return nodes[i];
}
};
this.getModel = function(name){
return jpf.nameserver.get("model", name);
};
this.setModel = function(model){
jpf.nameserver.register("model", model.data.ownerDocument
.documentElement.getAttribute(this.xmlDocTag), model);
};
this.findModel = function(xmlNode){
return this.getModel(xmlNode.ownerDocument
.documentElement.getAttribute(this.xmlDocTag));
};
this.getXml = function(strXml, noError, preserveWhiteSpace){
return jpf.getXmlDom(strXml, noError, preserveWhiteSpace).documentElement;
};
this.getXmlId = function(xmlNode){
return xmlNode.getAttribute(this.xmlIdTag) ||
this.nodeConnect(jpf.xmldb.getXmlDocId(xmlNode), xmlNode);
}
this.nodeCount = {};
this.nodeConnect = function(documentId, xmlNode, htmlNode, o){
if (!this.nodeCount[documentId])
this.nodeCount[documentId] = 0;
var xmlId;
xmlId = xmlNode.getAttribute(this.xmlIdTag)
|| xmlNode.setAttribute(this.xmlIdTag, (xmlId = documentId
+ "|" + ++this.nodeCount[documentId])) || xmlId;
if (!o)
return xmlId;
var htmlId = xmlId + "|" + o.uniqueId;
if (htmlNode)
htmlNode.setAttribute(this.htmlIdTag, htmlId);
return htmlId;
};
this.addNodeListener = function(xmlNode, o){
var listen = xmlNode.getAttribute(this.xmlListenTag);
var nodes  = (listen ? listen.split(";") : []);
var id = String(o.uniqueId);
if (!nodes.contains(id)) {
nodes.push(id);
xmlNode.setAttribute(this.xmlListenTag, nodes.join(";"));
}
return xmlNode;
};
this.removeNodeListener = function(xmlNode, o){
var listen = xmlNode.getAttribute(this.xmlListenTag);
var nodes = (listen ? listen.split(";") : []);
for (var newnodes = [], i = 0; i < nodes.length; i++) {
if (nodes[i] != o.uniqueId)
newnodes.push(nodes[i]);
}
xmlNode.setAttribute(this.xmlListenTag, newnodes.join(";"));
return xmlNode;
};
this.integrate = function(XMLRoot, parentNode, options){
if (typeof parentNode != "object")
parentNode = getElementById(parentNode);
if (options && options.clearContents) {
var node, j, i, nodes = parentNode.selectNodes("descendant::node()[@" + this.xmlListenTag + "]");
for (i = nodes.length - 1; i >= 0; i--) {
var s = nodes[i].getAttribute(this.xmlListenTag).split(";");
for (j = s.length - 1; j >= 0; j--) {
node = jpf.all[s[j]];
if (node.dataParent && node.dataParent.xpath)
node.dataParent.parent.signalXmlUpdate[node.uniqueId] = true;
else if (node.$model) {
node.$listenRoot = jpf.xmldb.addNodeListener(parentNode, node);
node.xmlRoot = null; 
}
}
}
var nodes = parentNode.childNodes;
for (var i = nodes.length - 1; i >= 0; i--)
parentNode.removeChild(nodes[i]);
}
{
beforeNode = jpf.getNode(parentNode, [0]);
nodes      = XMLRoot.childNodes;
if (parentNode.ownerDocument.importNode) {
doc = parentNode.ownerDocument;
for (i = 0, l = nodes.length; i < l; i++)
parentNode.insertBefore(doc.importNode(nodes[i], true), beforeNode);
}
else
for (i = nodes.length - 1; i >= 0; i--)
parentNode.insertBefore(nodes[0], beforeNode);
}
if (options && options.copyAttributes) {
var attr = XMLRoot.attributes;
for (i = 0; i < attr.length; i++)
if (attr[i].nodeName != this.xmlIdTag)
parentNode.setAttribute(attr[i].nodeName, attr[i].nodeValue);
}
return parentNode;
};
this.synchronize = function(){
this.forkRoot.parentNode.replaceChild(this.root, this.forkRoot);
this.parent.applyChanges("synchronize", this.root);
};
this.copyNode = function(xmlNode){
return this.clearConnections(xmlNode.cloneNode(true));
};
this.setNodeValue = function(xmlNode, nodeValue, applyChanges, options){
var undoObj, xpath, newNodes;
if (options) {
undoObj  = options.undoObj;
xpath    = options.xpath;
newNodes = options.newNodes;
undoObj.extra.oldValue = options.forceNew
? ""
: jpf.getXmlValue(xmlNode, xpath);
undoObj.xmlNode        = xmlNode;
if (xpath)
xmlNode = jpf.xmldb.createNodeFromXpath(xmlNode, xpath, newNodes, options.forceNew);
undoObj.extra.appliedNode = xmlNode;
}
if (xmlNode.nodeType == 1) {
if (!xmlNode.firstChild)
xmlNode.appendChild(xmlNode.ownerDocument.createTextNode("-"));
xmlNode.firstChild.nodeValue = jpf.isNot(nodeValue) ? "" : nodeValue;
if (applyChanges)
jpf.xmldb.applyChanges("synchronize", xmlNode, undoObj);
}
else {
xmlNode.nodeValue = jpf.isNot(nodeValue) ? "" : nodeValue;
if (applyChanges)
jpf.xmldb.applyChanges("synchronize", xmlNode.parentNode
|| xmlNode.ownerElement || xmlNode.selectSingleNode(".."),
undoObj);
}
};
this.getNodeValue = function(xmlNode){
if (!xmlNode)
return "";
return xmlNode.nodeType == 1
? (!xmlNode.firstChild ? "" : xmlNode.firstChild.nodeValue)
: xmlNode.nodeValue;
};
this.getInheritedAttribute = function(xml, attr, func){
var result;
while (xml && xml.nodeType != 11 && xml.nodeType != 9
&& !(result = attr && xml.getAttribute(attr) || func && func(xml))) {
xml = xml.parentNode;
}
return !result && attr && jpf.appsettings
? jpf.appsettings.tags[attr]
: result;
};
this.setTextNode = function(pNode, value, xpath, undoObj){
var tNode;
if (xpath) {
tNode = pNode.selectSingleNode(xpath);
if (!tNode)
return;
pNode = tNode.nodeType == 1 ? tNode : null;
}
if (pNode || !tNode) {
tNode = pNode.selectSingleNode("text()");
if (!tNode)
tNode = pNode.appendChild(pNode.ownerDocument.createTextNode(""));
}
if (undoObj)
undoObj.extra.oldValue = tNode.nodeValue;
tNode.nodeValue = value;
this.applyChanges("text", tNode.parentNode, undoObj);
};
this.setAttribute = function(xmlNode, name, value, xpath, undoObj){
(xpath ? xmlNode.selectSingleNode(xpath) : xmlNode).setAttribute(name, value);
this.applyChanges("attribute", xmlNode, undoObj);
};
this.removeAttribute = function(xmlNode, name, xpath, undoObj){
if (undoObj) undoObj.name = name;
(xpath ? xmlNode.selectSingleNode(xpath) : xmlNode).removeAttribute(name);
this.applyChanges("attribute", xmlNode, undoObj);
};
this.replaceNode = function(oldNode, newNode, xpath, undoObj){
if (xpath)
oldNode = oldNode.selectSingleNode(xpath);
if (undoObj)
undoObj.oldNode = oldNode;
oldNode.parentNode.replaceChild(newNode, oldNode);
this.copyConnections(oldNode, newNode);
this.applyChanges("replacechild", newNode, undoObj);
};
this.addChildNode = function(pNode, tagName, attr, beforeNode, undoObj){
var xmlNode = pNode.insertBefore(pNode.ownerDocument
.createElement(tagName), beforeNode);
for (var i = 0; i < attr.length; i++)
xmlNode.setAttribute(attr[i][0], attr[i][1]);
if (undoObj)
undoObj.extra.addedNode = xmlNode;
this.applyChanges("add", xmlNode, undoObj);
return xmlNode;
};
this.appendChild = function(pNode, xmlNode, beforeNode, unique, xpath, undoObj){
if (unique && pNode.selectSingleNode(xmlNode.tagName))
return false;
if (undoObj)
this.clearConnections(xmlNode);
if (jpf.isSafari && pNode.ownerDocument != xmlNode.ownerDocument)
xmlNode = pNode.ownerDocument.importNode(xmlNode, true); 
if (xpath) {
var addedNodes = [];
var pNode = this.createNodeFromXpath(pNode, xpath, addedNodes);
if (addedNodes.length) {
pNode.appendChild(xmlNode);
while(addedNodes.length) {
if (pNode == addedNodes.pop() && addedNodes.length)
pNode = pNode.parentNode;
}
}
}
pNode.insertBefore(xmlNode, beforeNode);
this.applyChanges("add", xmlNode, undoObj);
return xmlNode;
};
this.moveNode = function(pNode, xmlNode, beforeNode, xpath, undoObj){
if (!undoObj)
undoObj = {extra:{}};
undoObj.extra.oldParent  = xmlNode.parentNode;
undoObj.extra.beforeNode = xmlNode.nextSibling;
undoObj.extra.parent     = (xpath ? pNode.selectSingleNode(xpath) : pNode);
this.applyChanges("move-away", xmlNode, undoObj);
if (!jpf.isSafari
&& jpf.xmldb.getXmlDocId(xmlNode) != jpf.xmldb.getXmlDocId(pNode)) {
xmlNode.removeAttributeNode(xmlNode.getAttributeNode(this.xmlIdTag));
this.nodeConnect(jpf.xmldb.getXmlDocId(pNode), xmlNode);
}
if (jpf.isSafari && pNode.ownerDocument != xmlNode.ownerDocument)
xmlNode = pNode.ownerDocument.importNode(xmlNode, true); 
undoObj.extra.parent.insertBefore(xmlNode, beforeNode);
this.applyChanges("move", xmlNode, undoObj);
};
this.removeNode = function(xmlNode, xpath, undoObj){
if (xpath)
xmlNode = xmlNode.selectSingleNode(xpath);
if (undoObj) {
undoObj.extra.parent      = xmlNode.parentNode;
undoObj.extra.removedNode = xmlNode;
undoObj.extra.beforeNode  = xmlNode.nextSibling;
}
this.applyChanges("remove", xmlNode, undoObj);
var p = xmlNode.parentNode;
p.removeChild(xmlNode);
this.applyChanges("redo-remove", xmlNode, null, p);
};
this.removeNodeList = function(xmlNodeList, undoObj){
for (var rData = [], i = 0; i < xmlNodeList.length; i++) { 
if (undoObj) {
rData.push({
pNode      : xmlNodeList[i].parentNode,
removedNode: xmlNodeList[i],
beforeNode : xmlNodeList[i].nextSibling
});
}
this.applyChanges("remove", xmlNodeList[i], undoObj);
var p = xmlNodeList[i].parentNode;
p.removeChild(xmlNodeList[i]);
this.applyChanges("redo-remove", xmlNodeList[i], null, p);
}
if (undoObj)
undoObj.extra.removeList = rData;
};
var notifyQueue = {}, notifyTimer;
this.applyChanges = function(action, xmlNode, undoObj, nextloop){
if (undoObj && !undoObj.xmlNode) 
undoObj.xmlNode = xmlNode;
var oParent  = nextloop;
var loopNode = (xmlNode.nodeType == 1 ? xmlNode : xmlNode.parentNode);
var xmlId = xmlNode.getAttribute(this.xmlIdTag);
if (!this.delayUpdate && "|remove|move-away|".indexOf("|" + action + "|") > -1)
this.notifyQueued(); 
var listen, uIds, i, j, hash, info, jmlNode, runTimer, found;
while (loopNode && loopNode.nodeType != 9) {
listen = loopNode.getAttribute(this.xmlListenTag);
if (listen) {
uIds = listen.split(";");
for (i = 0; i < uIds.length; i++) {
hash = notifyQueue[uIds[i]];
if (!hash)
notifyQueue[uIds[i]] = hash = [];
if ("|update|attribute|text|".indexOf("|"
+ action + "|") > -1) {
found = false;
for (j = 0; j < hash.length; j++) {
if (hash[j] && xmlNode == hash[j][1]
&& "|update|attribute|text|"
.indexOf("|" + hash[j][0] + "|") > -1) {
hash[j] = null;
found = true;
continue;
}
}
hash.push(["update", xmlNode, loopNode, undoObj, oParent]);
runTimer = true;
continue;
}
if (!this.delayUpdate && "|remove|move-away|add|".indexOf("|" + action + "|") > -1) {
jmlNode = jpf.lookup(uIds[i]);
if (jmlNode)
jmlNode.$xmlUpdate(action, xmlNode,
loopNode, undoObj, oParent);
}
else {
hash.push([action, xmlNode, loopNode, undoObj, oParent]);
runTimer = true;
}
}
}
loopNode = loopNode.parentNode || nextloop;
if (loopNode == nextloop)
nextloop = null;
}
if (undoObj && !this.delayUpdate) {
jpf.xmldb.notifyQueued();
}
else if (runTimer) {
clearTimeout(notifyTimer);
notifyTimer = setTimeout(function(){
jpf.xmldb.notifyQueued();
});
}
};
this.notifyQueued = function(){
clearTimeout(notifyTimer);
for (var uId in notifyQueue) {
var q = notifyQueue[uId];
jmlNode = jpf.lookup(uId);
if (!jmlNode || !q)
continue;
if (jmlNode.$listenRoot) {
var model = jmlNode.getModel();
var xpath   = model.getXpathByJmlNode(jmlNode);
var xmlRoot = xpath
? model.data.selectSingleNode(xpath)
: model.data;
if (xmlRoot) {
jpf.xmldb.removeNodeListener(jmlNode.$listenRoot, jmlNode);
jmlNode.$listenRoot = null;
jmlNode.load(xmlRoot);
}
continue;
}
for (var i = 0; i < q.length; i++) {
if (!q[i])
continue;
jmlNode.$xmlUpdate.apply(jmlNode, q[i]);
}
}
notifyQueue = {}; 
}
this.notifyListeners = function(xmlNode){
var listen = xmlNode.getAttribute(jpf.xmldb.xmlListenTag);
if (listen) {
listen = listen.split(";");
for (var j = 0; j < listen.length; j++) {
jpf.lookup(listen[j]).$xmlUpdate("synchronize", xmlNode, xmlNode);
}
}
};
this.copyConnections = function(fromNode, toNode){
try {
toNode.setAttribute(this.xmlListenTag, fromNode.getAttribute(this.xmlListenTag));
toNode.setAttribute(this.xmlIdTag, fromNode.getAttribute(this.xmlIdTag));
}
catch (e) {}
};
this.clearConnections = function(xmlNode){
try {
var i, nodes = xmlNode.selectNodes("descendant-or-self::node()[@" + this.xmlListenTag + "]");
for (i = nodes.length - 1; i >= 0; i--)
nodes[i].removeAttribute(this.xmlListenTag);
nodes = xmlNode.selectNodes("descendant-or-self::node()[@" + this.xmlIdTag + "]");
for (i = nodes.length - 1; i >= 0; i--)
nodes[i].removeAttribute(this.xmlIdTag);
nodes = xmlNode.selectNodes("descendant-or-self::node()[@" + this.xmlDocTag + "]");
for (i = nodes.length - 1; i >= 0; i--)
nodes[i].removeAttribute(this.xmlDocTag);
nodes = xmlNode.selectNodes("descendant-or-self::node()[@j_loaded]");
for (i = nodes.length - 1; i >= 0; i--)
nodes[i].removeAttribute("j_loaded");
}
catch (e) {}
return xmlNode;
};
this.serializeNode = function(xmlNode){
var xml = this.clearConnections(xmlNode.cloneNode(true));
return xml.xml || xml.serialize();
};
this.unbind = function(frm){
for (var lookup = {}, i = 0; i < frm.jpf.all.length; i++)
if (frm.jpf.all[i] && frm.jpf.all[i].unloadBindings)
lookup[frm.jpf.all[i].unloadBindings()] = true;
for (var k = 0; k < xmlDocLut.length; k++) {
if (!xmlDocLut[k]) continue;
var Nodes = xmlDocLut[k].selectNodes("//self::node()[@"
+ this.xmlListenTag + "]");
for (var i = 0; i < Nodes.length; i++) {
var listen = Nodes[i].getAttribute(this.xmlListenTag).split(";");
for (var nListen = [], j = 0; j < listen.length; j++)
if (!lookup[listen[j]])
nListen.push(listen[j]);
if (nListen.length != listen.length)
Nodes[i].setAttribute(this.xmlListenTag, nListen.join(";"));
}
}
};
this.selectNodes = function(sExpr, contextNode){
if (contextNode && (jpf.hasXPathHtmlSupport && contextNode.selectSingleNode || !contextNode.style))
return contextNode.selectNodes(sExpr); 
return jpf.XPath.selectNodes(sExpr, contextNode)
};
this.selectSingleNode = function(sExpr, contextNode){
if (contextNode && (jpf.hasXPathHtmlSupport && contextNode.selectSingleNode || !contextNode.style))
return contextNode.selectSingleNode(sExpr); 
var nodeList = this.selectNodes(sExpr + (jpf.isIE ? "" : "[1]"),
contextNode ? contextNode : null);
return nodeList.length > 0 ? nodeList[0] : null;
};
this.createNodeFromXpath = function(contextNode, xPath, addedNodes, forceNew){
var xmlNode, foundpath = "", paths = xPath.split("\|")[0].split("/");
if (!forceNew && (xmlNode = contextNode.selectSingleNode(xPath)))
return xmlNode;
var len = paths.length -1;
if (forceNew) {
if (paths[len].trim().match(/^\@(.*)$|^text\(\)$/))
len--;
}
for (var addedNode, isAdding = false, i = 0; i < len; i++) {
if (!isAdding && contextNode.selectSingleNode(foundpath
+ (i != 0 ? "/" : "") + paths[i])) {
foundpath += (i != 0 ? "/" : "") + paths[i];
continue;
}
var isAddId = paths[i].match(/(\w+)\[@([\w-]+)=(\w+)\]/);
if (isAddId)
paths[i] = isAddId[1];
isAdding = true;
addedNode = contextNode.selectSingleNode(foundpath || ".")
.appendChild(contextNode.ownerDocument.createElement(paths[i]));
if (isAddId) {
addedNode.setAttribute(isAddId[2], isAddId[3]);
foundpath += (foundpath ? "/" : "") + isAddId[0];
}
else
foundpath += (foundpath ? "/" : "") + paths[i];
if (addedNodes)
addedNodes.push(addedNode);
}
if (!foundpath)
foundpath = ".";
var newNode, lastpath = paths[len];
do {
if (lastpath.match(/^\@(.*)$/)) {
(newNode || contextNode.selectSingleNode(foundpath))
.setAttributeNode(newNode = contextNode.ownerDocument.createAttribute(RegExp.$1));
}
else if (lastpath.trim() == "text()") {
newNode = (newNode || contextNode.selectSingleNode(foundpath))
.appendChild(contextNode.ownerDocument.createTextNode(""));
}
else {
var hasId = lastpath.match(/(\w+)\[@([\w-]+)=(\w+)\]/);
if (hasId) lastpath = hasId[1];
newNode = (newNode || contextNode.selectSingleNode(foundpath))
.appendChild(contextNode.ownerDocument.createElement(lastpath));
if (hasId)
newNode.setAttribute(hasId[2], hasId[3]);
if (addedNodes)
addedNodes.push(newNode);
}
foundpath += (foundpath ? "/" : "") + paths[len];
} while((lastpath = paths[++len]));
return newNode;
};
this.getXmlDocId = function(xmlNode, model){
var docEl = xmlNode.ownerDocument.documentElement;
if (!this.isChildOf(docEl, xmlNode))
docEl = xmlNode;
var docId = (docEl || xmlNode).getAttribute(this.xmlDocTag)
|| xmlDocLut.indexOf(docEl || xmlNode.ownerDocument || xmlNode);
if (docId && docId > -1)
return docId;
docId = xmlDocLut.push(docEl || xmlNode.ownerDocument || xmlNode) - 1;
if (docEl)
docEl.setAttribute(this.xmlDocTag, docId);
if (model)
jpf.nameserver.register("model", docId, model);
return xmlDocLut.length - 1;
};
this.getBindXmlNode = function(xmlRootNode){
if (typeof xmlRootNode != "object")
xmlRootNode = jpf.getXmlDom(xmlRootNode);
if (xmlRootNode.nodeType == 9)
xmlRootNode = xmlRootNode.documentElement;
if (xmlRootNode.nodeType == 3 || xmlRootNode.nodeType == 4)
xmlRootNode = xmlRootNode.parentNode;
if (xmlRootNode.nodeType == 2)
xmlRootNode = xmlRootNode.ownerElement 
|| xmlRootNode.parentNode 
|| xmlRootNode.selectSingleNode("..");
return xmlRootNode;
};
this.convertMethods = {
"json": function(xml){
var result = {}, filled = false, nodes = xml.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1)
continue;
var name = nodes[i].tagName;
filled = true;
var sameNodes = xml.selectNodes(x);
if (sameNodes.length > 1) {
var z = [];
for (var j = 0; j < sameNodes.length; j++) {
z.push(this.json(sameNodes[j], result));
}
result[name] = z;
}
else 
result[name] = this.json(sameNodes[j], result);
}
return filled ? result : jpf.getXmlValue(xml, "text()");
},
"cgivars": function(xml, basename){
if (!basename) 
basename = "";
var str = [], value, nodes = xml.childNodes, done = {};
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1)
continue;
var name = nodes[i].tagName;
if (done[name])
continue;
var sameNodes = xml.selectNodes(name);
if (sameNodes.length > 1) {
done[name] = true;
for (var j = 0; j < sameNodes.length; j++) {
value = this.cgivars(sameNodes[j],
basename + name + "[" + j + "]");
if (value)
str.push(value);
}
}
else { 
value = this.cgivars(nodes[i], basename + name);
if (value)
str.push(value);
}
}
var attr = xml.attributes;
for (i = 0; i < attr.length; i++) {
if (attr[i].nodeValue) {
if (basename) 
str.push(basename + "[" + attr[i].nodeName + "]="
+ encodeURIComponent(attr[i].nodeValue));
else
str.push(attr[i].nodeName + "="
+ encodeURIComponent(attr[i].nodeValue));
}
}
if (str.length)
return str.join("&");
value = jpf.getXmlValue(xml, "text()");
if (basename && value)
return basename + "=" + encodeURIComponent(value);
},
"cgiobjects": function(xml, basename, isSub){
if (!basename)
basename = "";
var str = [], value, nodes = xml.childNodes, done = {};
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if (node.nodeType != 1)
continue;
var name = node.tagName; 
if (name == "revision")
continue;
var isOnlyChild = jpf.xmldb.isOnlyChild(node.firstChild, [3,4]);
var count       = 0;
if (!node.attributes.length && !isOnlyChild) {
var lnodes = node.childNodes;
for (var nm, j = 0, l = lnodes.length; j < l; j++) {
if (lnodes[j].nodeType != 1)
continue;
nm = basename + (isSub ? "[" : "") + name + (isSub ? "]" : "") + "[" + count++ + "]";
value = this.cgiobjects(lnodes[j], nm, true);
if (value)
str.push(value);
if (jpf.xmldb.isOnlyChild(lnodes[j].firstChild, [3,4]))
str.push(nm + "[" + lnodes[j].tagName + "]" + "=" 
+ encodeURIComponent(lnodes[j].firstChild.nodeValue));
var a, attr = lnodes[j].attributes;
for (k = 0; k < attr.length; k++) {
if (!(a = attr[k]).nodeValue)
continue;
str.push(nm + "[" + a.nodeName + "]=" 
+ encodeURIComponent(a.nodeValue));
}
}
}
else {
if (isOnlyChild)
str.push(basename + (isSub ? "[" : "") + name + (isSub ? "]" : "") + "=" 
+ encodeURIComponent(node.firstChild.nodeValue));
var a, attr = node.attributes;
for (j = 0; j < attr.length; j++) {
if (!(a = attr[j]).nodeValue)
continue;
str.push(basename + (isSub ? "[" : "") + name + "_" + a.nodeName + (isSub ? "]" : "") + "=" 
+ encodeURIComponent(a.nodeValue));
}
}
}
if (!isSub && xml.getAttribute("id"))
str.push("id=" + encodeURIComponent(xml.getAttribute("id")));
if (str.length)
return str.join("&");
}
};
this.convertXml = function(xml, to){
return this.convertMethods[to](xml);
};
this.getTextNode = function(x){
for (var i = 0; i < x.childNodes.length; i++) {
if (x.childNodes[i].nodeType == 3 || x.childNodes[i].nodeType == 4)
return x.childNodes[i];
}
return false;
};
this.getBoundValue = function(jmlNode, xmlRoot, applyChanges){
if (!xmlRoot && !jmlNode.xmlRoot)
return "";
var xmlNode = !jmlNode.nodeFunc
? xmlRoot.selectSingleNode(jmlNode.getAttribute("ref"))
: jmlNode.getNodeFromRule("value", jmlNode.xmlRoot);
return xmlNode ? this.getNodeValue(xmlNode) : "";
};
this.getArrayFromNodelist = function(nodelist){
for (var nodes = [], j = 0; j < nodelist.length; j++)
nodes.push(nodelist[j]);
return nodes;
};
};
jpf.getXml = function(){
return jpf.xmldb.getXml.apply(jpf.xmldb, arguments);
};
jpf.Init.run('XmlDatabase');
jpf.namespace("datainstr", {
"call" : function(xmlContext, options, callback){
var parsed = options.parsed || this.parseInstructionPart(
options.instrData.join(":"), xmlContext, options.args, options);
if (options.preparse) {
options.parsed = parsed;
options.preparse = -1;
return;
}
var retvalue = self[parsed.name].apply(null, parsed.arguments);
if (callback)
callback(retvalue, jpf.SUCCESS, options);
},
"eval" : function(xmlContext, options, callback){
var parsed = options.parsed
|| this.parseInstructionPart(
"(" + options.instrData.join(":") + ")", xmlContext,
options.args, options);
if (options.preparse) {
options.parsed = parsed;
options.preparse = -1;
return;
}
try {
var retvalue = eval(parsed.arguments[0]);
}
catch(e) {
}
if (callback)
callback(retvalue, jpf.SUCCESS, options);
}
});
jpf.saveData = function(instruction, xmlContext, options, callback){
if (!instruction) return false;
if (!options) options = {};
options.instrData = instruction.split(":");
options.instrType = options.instrData.shift();
var instrType = options.instrType.indexOf("url.") == 0
? "url"
: options.instrType;
options.instruction = instruction;
this.datainstr[instrType].call(this, xmlContext, options, callback);
};
jpf.getData = function(instruction, xmlContext, options, callback){
var instrParts = instruction.match(/^(.*?)(?:\!\{(.*)$|$)/);
var operators  = instrParts[2] ? instrParts[2].splitSafe("\}\s*,|,") : "";
var gCallback  = function(data, state, extra){
if (state != jpf.SUCCESS)
return callback(data, state, extra);
operators[2] = data;
if (operators[0] && data) {
if (typeof data == "string")
data = jpf.xmldb.getXml(data);
extra.data = data;
data = data.selectSingleNode(operators[0]);
if (!data) {
throw new Error(jpf.formatErrorString(0, null,
"Loading new data", "Could not load data by doing \
selection on it using xPath: '" + operators[0] + "'."));
}
}
extra.userdata = operators;
return callback(data, state, extra);
}
if (!options) options = {};
options.isGetRequest = true;
options.userdata     = operators;
if (this.saveData(instrParts[1], xmlContext, options, gCallback) !== false)
return;
var data      = instruction.split(":");
var instrType = data.shift();
if (instrType.substr(0, 1) == "#") {
instrType = instrType.substr(1);
var retvalue, oJmlNode = self[instrType];
if (!oJmlNode.value)
retvalue = null;
else
retvalue = data[2]
? oJmlNode.value.selectSingleNode(data[2])
: oJmlNode.value;
}
else {
var model = jpf.nameserver.get("model", instrType);
if (!model.data)
retvalue = null;
else
retvalue = data[1]
? model.data.selectSingleNode(data[1])
: model.data;
}
if (callback)
gCallback(retvalue, jpf.SUCCESS, {userdata:operators});
else {
jpf.console.warn("Returning data directly in jpf.getData(). \
This means that all callback communication ends in void!");
return retvalue;
}
};
jpf.setModel = function(instruction, jmlNode, isSelection){
if (!instruction) return;
var data      = instruction.split(":");
var instrType = data[0];
var model = isSelection
? jmlNode.$getMultiBind().getModel()
: jmlNode.getModel && jmlNode.getModel();
if(model)
model.unregister(jmlNode);
if (jpf.datainstr[instrType]) {
jmlNode.setModel(new jpf.model().loadFrom(instruction));
}
else if (instrType.substr(0,1) == "#") {
instrType = instrType.substr(1);
if (isSelection) {
var sb2 = jpf.isParsing
? jpf.JmlParser.getFromSbStack(jmlNode.uniqueId, 1)
: jmlNode.$getMultiBind().smartBinding;
if (sb2)
sb2.$model = new jpf.model().loadFrom(instruction);
}
else if (!self[instrType] || !jpf.JmlParser.inited) {
jpf.JmlParser.addToModelStack(jmlNode, data)
}
else {
var oConnect = eval(instrType);
if (oConnect.connect)
oConnect.connect(jmlNode, null, data[2], data[1] || "select");
else
jmlNode.setModel(new jpf.model().loadFrom(instruction));
}
jmlNode.connectId = instrType;
}
else {
var instrType = data.shift();
model = instrType == "@default"
? jpf.globalModel
: jpf.nameserver.get("model", instrType);
if (isSelection) {
var sb2 = jpf.isParsing
? jpf.JmlParser.getFromSbStack(jmlNode.uniqueId, 1)
: jmlNode.$getMultiBind().smartBinding;
if (sb2) {
sb2.$model = model;
sb2.$modelXpath[jmlNode.uniqueId] = data.join(":");
}
}
else
jmlNode.setModel(model, data.join(":"));
}
};
jpf.parseInstructionPart = function(instrPart, xmlNode, arg, options){
var parsed  = {}, s = instrPart.split("(");
parsed.name = s.shift();
if (!arg) {
arg = s.join("(");
function getXmlValue(xpath){
var o = xmlNode ? xmlNode.selectSingleNode(xpath) : null;
if (!o)
return null;
else if (o.nodeType >= 2 && o.nodeType <= 4)
return o.nodeValue;
else if (jpf.xmldb.isOnlyChild(o.firstChild, [3, 4]))
return o.firstChild.nodeValue;
else
return o.xml || o.serialize();
}
arg = arg.slice(0, -1);
var depth, lastpos = 0, result = ["["];
arg.replace(/\\[\{\}\'\"]|(["'])|([\{\}])/g,
function(m, chr, cb, pos){
chr && (!depth && (depth = chr)
|| depth == chr && (depth = null));
if (!depth && cb) {
if (cb == "{") {
result.push(arg.substr(lastpos, pos - lastpos));
lastpos = pos + 1;
}
else {
result.push("getXmlValue('", arg
.substr(lastpos, pos - lastpos)
.replace(/([\\'])/g, "\\$1"), "')");
lastpos = pos + 1;
}
}
});
result.push(arg.substr(lastpos), "]");
(function(){
try{
with (options) {
arg = eval(result.join(""));
}
}
catch(e) {
arg = [];
}
})();
}
parsed.arguments = arg;
return parsed;
};
jpf.Class = function(){
this.$jmlLoaders   = [];
this.$addJmlLoader = function(func){
if (!this.$jmlLoaders)
func.call(this, this.$jml);
else
this.$jmlLoaders.push(func);
};
this.$jmlDestroyers   = [];
this.$regbase         = 0;
this.hasFeature       = function(test){
return this.$regbase&test;
};
var boundObjects       = {};
var myBoundPlaces      = {};
if (!this.$handlePropSet) {
this.$handlePropSet    = function(prop, value){
this[prop] = value;
};
}
this.bindProperty = function(myProp, bObject, bProp, strDynamicProp){
if (!boundObjects[myProp])
boundObjects[myProp] = {};
if (!boundObjects[myProp][bObject.uniqueId])
boundObjects[myProp][bObject.uniqueId] = [];
if (boundObjects[myProp][bObject.uniqueId].contains(bProp)) {
return;
}
if (strDynamicProp)
boundObjects[myProp][bObject.uniqueId].push([bProp, strDynamicProp]);
else
boundObjects[myProp][bObject.uniqueId].pushUnique([bProp]); 
bObject.$handlePropSet(bProp, strDynamicProp ? eval(strDynamicProp) : this[myProp]);
};
this.unbindProperty = function(myProp, bObject, bProp){
boundObjects[myProp][bObject.uniqueId].remove(bProp);
};
this.unbindAllProperties = function(){
var prop;
for (prop in myBoundPlaces) {
if (myBoundPlaces[prop] && typeof myBoundPlaces[prop] != "function") {
for (var i = 0; i < myBoundPlaces[prop].length; i++) {
if (!self[myBoundPlaces[prop][i][0]]) continue;
self[myBoundPlaces[prop][i][0]]
.unbindProperty(myBoundPlaces[prop][i][1], this, prop);
}
}
}
};
this.getAvailableProperties = function(){
return this.$supportedProperties.slice();
};
this.setDynamicProperty = function(prop, pValue){
var pStart = pValue.substr(0,1);
if (myBoundPlaces[prop]) {
for (var i = 0; i < myBoundPlaces[prop].length; i++) {
self[myBoundPlaces[prop][i][0]].unbindProperty(myBoundPlaces[prop][i][1], this, prop);
}
}
if (pStart == "[") {
var p = pValue.substr(1,pValue.length-2).split(".");
if (!self[p[0]]) return;
if (!p[1])
p[1] = self[p[0]].$supportedProperties[0]; 
self[p[0]].bindProperty(p[1], this, prop);
myBoundPlaces[prop] = [p];
this.bindProperty(prop, self[p[0]], p[1]);
}
else if (pStart == "{") { 
var o, node, bProp, p, matches = {};
pValue = pValue.substr(1, pValue.length - 2);
pValue.replace(/["'](?:\\.|[^"']+)*["']|\\(?:\\.|[^\\]+)*\/|(?:\W|^)([a-z]\w*\.\w+(?:\.\w+)*)(?!\()(?:\W|$)/gi,
function(m, m1){
if(m1) matches[m1] = true;
});
pValue = pValue.replace(/\Wand\W/g, "&&").replace(/\Wor\W/g, "||");  
myBoundPlaces[prop] = [];
var found = false;
for (p in matches) {
if (typeof matches[p] == "function")
continue;
o = p.split(".");
if (o.length > 2) { 
bProp = o.pop();
node  = eval(o.join("."));
if (typeof node != "object" || !node.$regbase) {
bProp = o[1];
node  = self[o[0]];
}
else
o.push(bProp);
}
else {
bProp = o[1];
node  = self[o[0]];
}
if (!node || !node.bindProperty)
continue;  
node.bindProperty(bProp, this, prop, pValue);
myBoundPlaces[prop].push(o);
found = true;
}
var value = eval(pValue);
this[prop] = !value;
this.setProperty(prop, value);
}
else {
var value = eval(pValue);
this[prop] = !value;
this.setProperty(prop, eval(pValue));
}
}
this.setProperty = function(prop, value, reqValue, forceOnMe){
if (reqValue && !value || !jpf || this.$ignoreSignals)
return;
if (String(this[prop]) !== String(value) || typeof value == "object") {
var oldvalue = this[prop];
if (this.$handlePropSet(prop, value, forceOnMe) === false) {
this[prop] = oldvalue;
return false;
}
}
var nodes = boundObjects[prop];
if (!nodes) return;
var id, ovalue = this[prop];
for (id in nodes) {
if (jpf.isSafari && (typeof nodes[id] != "object" || !nodes[id]))
continue;
for (var o = jpf.lookup(id), i = nodes[id].length - 1; i >= 0; --i) {
try {
value = nodes[id][i][1] ? eval(nodes[id][i][1]) : ovalue;
}
catch(e) {
throw new Error(jpf.formatErrorString(0, this,
"Property-binding",
"Could not execute binding test: " + nodes[id][i][1]));
}
if (typeof o != "undefined" && o[nodes[id][i][0]] != value)
o.setProperty(nodes[id][i][0], value);
}
}
return value;
};
this.getProperty = function(prop){
return this[prop];
};
var capture_stack = {}, events_stack = {};
this.dispatchEvent = function(eventName, options, e){
var arr, result, rValue;
if (options && options.name)
e = options;
else if (!e)
e = new jpf.Event(eventName, options);
if (!e.originalElement) {
e.originalElement = this;
if (arr = capture_stack[eventName]) {
for (var i = 0; i < arr.length; i++) {
rValue = arr[i].call(this, e);
if (rValue != undefined)
result = rValue;
}
}
}
if (options && options.captureOnly)
return e.returnValue || rValue;
else if (this.disabled)
result = false;
else {
if (this["on" + eventName])
result = this["on" + eventName].call(this, e); 
if (arr = events_stack[eventName]) {
for (var i = 0; i < arr.length; i++) {
rValue = arr[i].call(this, e);
if (rValue != undefined)
result = rValue;
}
}
}
return e.returnValue !== undefined ? e.returnValue : result;
};
this.addEventListener = function(eventName, callback, useCapture){
if (eventName.indexOf("on") == 0)
eventName = eventName.substr(2);
var stack = useCapture ? capture_stack : events_stack;
if (!stack[eventName])
stack[eventName] = [];
stack[eventName].pushUnique(callback);
}
this.removeEventListener = function(eventName, callback, useCapture){
var stack = useCapture ? capture_stack : events_stack;
if (stack[eventName])
stack[eventName].remove(callback);
};
this.hasEventListener = function(eventName){
return (events_stack[eventName] && events_stack[eventName].length > 0);
};
this.destroy = this.destroy || function(deep){
if (!this.$jmlDestroyers) 
return;
if (this.$destroy)
this.$destroy();
for (var i = this.$jmlDestroyers.length - 1; i >= 0; i--)
this.$jmlDestroyers[i].call(this);
this.$jmlDestroyers = undefined;
if (typeof this.uniqueId == "undefined")
return;
jpf.all[this.uniqueId] = undefined;
if (!this.nodeFunc) { 
if (this.name)
self[this.name] = null;
return;
}
if (this.oExt && !this.oExt.isNative && this.oExt.nodeType == 1) {
this.oExt.oncontextmenu = this.oExt.host = null;
}
if (this.oInt && !this.oExt.isNative && this.oInt.nodeType == 1)
this.oInt.host = null;
this.$jml = null;
if (this.parentNode)
this.removeNode();
if (this.$focussable && this.focussable)
jpf.window.$removeFocus(this);
this.unbindAllProperties();
if (deep && this.childNodes) {
var i, l, nodes = this.childNodes;
for (i = 0, l = nodes.length; i < l; i++) {
if (nodes[i].destroy)
nodes[i].destroy(true);
}
this.childNodes = null;
}
if (this.name)
self[this.name] = null;
};
};
jpf.Event = function(name, data){
this.name = name;
this.preventDefault = function(){
this.returnValue = false;
}
this.stopPropagation = function(){
this.cancelBubble = true;
}
this.isCharacter = function(){
return (this.keyCode < 112 || this.keyCode > 122) 
&& (this.keyCode < 33  && this.keyCode > 31 || this.keyCode > 42 || this.keyCode == 8);
}
jpf.extend(this, data);
};
jpf.inherit(jpf.Class);
jpf.Init.run('class');
jpf.component = function(nodeFunc, oBase) {
var fC = function() {
this.$init.apply(this, arguments);
};
if (oBase) {
if (typeof oBase == "function")
fC.prototype.base = oBase;
else
fC.prototype = oBase;
}
fC.prototype.nodeFunc = nodeFunc || jpf.NODE_HIDDEN;
fC.prototype.inherit = jpf.inherit;
if (typeof fC.prototype['$init'] != "function") {
var aImpl = [];
fC.implement = function() {
aImpl = aImpl.concat(Array.prototype.slice.call(arguments));
return fC;
}
fC.prototype.$init = function(pHtmlNode, sName){
if (typeof sName != "string") 
throw new Error(jpf.formatErrorString(0, this, 
"Error creating component",
"Dependencies not met, please provide a component name when \
instantiating it (ex.: new jpf.tree(oParent, 'tree') )"));
this.tagName       = sName;
this.pHtmlNode     = pHtmlNode || document.body;
this.pHtmlDoc      = this.pHtmlNode.ownerDocument;
this.uniqueId      = jpf.all.push(this) - 1;
this.$propHandlers = {}; 
this.$domHandlers  = {
"remove"      : [],
"insert"      : [],
"reparent"    : [],
"removechild" : []
};
if (nodeFunc != jpf.NODE_HIDDEN) {
if (typeof this.$focussable == "undefined")
this.$focussable = jpf.KEYBOARD_MOUSE; 
this.$booleanProperties = {
"disable-keyboard" : true,
"visible"          : true,
"focussable"       : true,
"disabled"         : true
};
this.$supportedProperties = [
"draggable", "resizable",
"focussable", "zindex", "disabled", "tabindex",
"disable-keyboard", "contextmenu", "visible", "autosize", 
"loadjml", "actiontracker", "alias"];
} 
else {
this.$booleanProperties   = {}; 
this.$supportedProperties = []; 
}
this.inherit(jpf.Class);
this.inherit.apply(this, aImpl);
this.inherit(jpf.JmlElement, this.base || jpf.K);
if (typeof this['init'] == "function")
this.init();
}
}
return fC;
};
jpf.subnode = function(nodeFunc, oBase) {
var fC = function() {
this.$init.apply(this, arguments);
};
if (oBase) {
if (typeof oBase == "function")
fC.prototype.base = oBase;
else
fC.prototype = oBase;
}
fC.prototype.nodeFunc = nodeFunc || jpf.NODE_HIDDEN;
fC.prototype.inherit  = jpf.inherit;
if (typeof fC.prototype['$init'] != "function") {
var aImpl = [];
fC.implement = function() {
aImpl = aImpl.concat(Array.prototype.slice.call(arguments));
return fC;
}
fC.prototype.$init = function(pHtmlNode, sName, parentNode){
if (typeof sName != "string") 
throw new Error(jpf.formatErrorString(0, this, 
"Error creating component",
"Dependencies not met, please provide a component name when \
instantiating it (ex.: new jpf.tree(oParent, 'tree') )"));
this.tagName      = sName;
this.pHtmlNode    = pHtmlNode || document.body;
this.pHtmlDoc     = this.pHtmlNode.ownerDocument;
this.parentNode   = parentNode;
this.$domHandlers = {
"remove"      : [],
"insert"      : [],
"reparent"    : [],
"removechild" : []
};
this.uniqueId     = jpf.all.push(this) - 1;
this.inherit(jpf.Class);
this.inherit.apply(this, aImpl);
this.inherit(jpf.JmlDom, this.base || jpf.K);
if (typeof this['init'] == "function")
this.init();
}
}
return fC;
};
jpf.windowManager = {
destroy: function(frm){
},
userdata: [],
forms   : new Array(),
addForm: function(xmlFormNode){
var x = {
jml: xmlFormNode,
show: function(){
alert("not implemented");
}
};
this.forms.push(jpf.setReference(x.name, x, true));
return x;
},
getForm: function(value){
for (var i = 0; i < this.forms.length; i++)
if (this.forms[i].name == value)
return this.forms[i];
return this.forms.length ? this.forms[0] : false;
},
closeAll: function(){
for (var i = 0; i < this.forms.length; i++)
if (this.forms[i].name != "main" && this.forms[i].type != "modal")
this.forms[i].hide();
}
};
jpf.WindowImplementation = function(){
jpf.register(this, "window", jpf.NODE_HIDDEN);
this.jpf = jpf;
this.toString = function(){
return "[Javeline Component : " + (this.name || "") + " (jpf.window)]";
};
this.getActionTracker = function(){
return this.$at
};
this.loadCodeFile = function(url){
if (self[url])
jpf.importClass(self[url], true, this.win);
else
jpf.include(url);
};
this.show = function(){
if (jpf.isDeskrun)
jdwin.Show();
};
this.hide = function(){
if (jpf.isDeskrun)
jdwin.Hide();
else {
this.loaded = false;
if (this.win)
this.win.close();
}
};
this.focus = function(){
if (jpf.isDeskrun)
jdwin.SetFocus();
else
window.focus();
};
this.setIcon = function(url){
if (jpf.isDeskrun)
jdwin.icon = parseInt(url) == url ? parseInt(url) : url;
};
this.setTitle = function(value){
this.title = value || "";
if (jpf.isDeskrun)
jdwin.caption = value;
else
document.title = (value || "");
};
this.loadJml = function(x){
if (x[jpf.TAGNAME] == "deskrun")
this.loadDeskRun(x);
else {
}
};
this.$tabList = [];
this.$addFocus = function(jmlNode, tabindex, isAdmin){
if (!isAdmin) {
if (jmlNode.$domHandlers) {
jmlNode.$domHandlers.reparent.push(moveFocus);
jmlNode.$domHandlers.remove.push(removeFocus);
}
if (jmlNode.isWindowContainer > -1) {
jmlNode.addEventListener("focus", trackChildFocus);
if (!jmlNode.$tabList) {
jmlNode.$tabList = [jmlNode];
}
jmlNode.$focusParent = jmlNode;
this.$tabList.push(jmlNode);
return;
}
}
var fParent = findFocusParent(jmlNode);
var list    = fParent.$tabList;
jmlNode.$focusParent = fParent;
if (list[tabindex])
list.insertIndex(jmlNode, tabindex);
else
list.push(jmlNode);
};
this.$removeFocus = function(jmlNode){
if (!jmlNode.$focusParent)
return;
jmlNode.$focusParent.$tabList.remove(jmlNode);
if (!jmlNode.isWindowContainer && jmlNode.$domHandlers) {
jmlNode.$domHandlers.reparent.remove(moveFocus);
jmlNode.$domHandlers.remove.remove(removeFocus);
}
if (jmlNode.isWindowContainer > -1)
jmlNode.removeEventListener("focus", trackChildFocus);
};
this.$focus = function(jmlNode, e, force){
if (this.focussed == jmlNode && !force)
return; 
this.$settingFocus = jmlNode;
if (this.focussed && this.focussed != jmlNode) {
this.focussed.blur(true, e);
}
(this.focussed = jmlNode).focus(true, e);
this.$settingFocus = null;
jpf.dispatchEvent("movefocus", {
toElement : this.focussed
});
};
this.$blur = function(jmlNode){
if (this.focussed != jmlNode)
return false;
jpf.window.focussed.$focusParent.$lastFocussed = null;
this.focussed = null;
jpf.dispatchEvent("movefocus", {
fromElement : jmlNode
});
};
var lastFocusParent;
this.addEventListener("focus", function(e){
if (!jpf.window.focussed && lastFocusParent) {
jpf.window.$focusLast(lastFocusParent);
}
});
this.addEventListener("blur", function(e){
if (!jpf.window.focussed)
return;
jpf.window.focussed.blur(true, {srcElement: this});
lastFocusParent = jpf.window.focussed.$focusParent;
jpf.window.focussed = null;
});
this.$focusDefault = function(jmlNode, e){
var fParent = findFocusParent(jmlNode);
this.$focusLast(fParent, e);
}
this.$focusRoot = function(e){
var docEl = jpf.document.documentElement;
if (this.$focusLast(docEl, e) === false) {
}
};
this.$focusLast = function(jmlNode, e, ignoreVisible){
var lf = jmlNode.$lastFocussed;
if (lf && lf.parentNode && lf.$focussable === true
&& (ignoreVisible || lf.oExt.offsetHeight)) {
this.$focus(lf, e, true);
}
else { 
var str, x, node = jmlNode;
while (node) {
if (node.focussable !== false && node.$focussable === true
&& (ignoreVisible || node.oExt.offsetHeight)) {
this.$focus(node, e, true);
break;
}
if (node.firstChild || node.nextSibling) {
node = node.firstChild || node.nextSibling;
}
else {
do {
node = node.parentNode;
} while (node && !node.nextSibling && node != jmlNode)
if (node == jmlNode)
return; 
if (node)
node = node.nextSibling;
}
}
if (!node)
this.$focus(jpf.document.documentElement);
}
};
function trackChildFocus(e){
if (e.srcElement == this || e.trackedChild) {
e.trackedChild = true;
return;
}
this.$lastFocussed = e.srcElement;
if (this.tagName.indexOf("window") > -1)
e.trackedChild = true;
}
function findFocusParent(jmlNode){
var node = jmlNode;
do {
node = node.parentNode;
} while(node && !node.isWindowContainer);
return node || jpf.document.documentElement;
}
function moveFocus(){
if (this.isWindowContainer)
jpf.window.$tabIndex.push(this);
else
jpf.window.$addFocus(this, this.tabindex, true)
}
function removeFocus(doOnlyAdmin){
if (this.isWindowContainer) {
jpf.window.$tabList.remove(this);
return;
}
if (!this.$focusParent)
return;
this.$focusParent.$tabList.remove(this);
}
this.hasFocus = function(jmlNode){
return this.focussed == jmlNode;
};
this.moveNext = function(shiftKey, relObject, switchWindows, e){
var dir, start, next;
if (switchWindows && jpf.window.focussed) {
var p = jpf.window.focussed.$focusParent;
if (p.visible && p.modal)
return false;
}
var jmlNode = relObject || jpf.window.focussed;
var fParent = jmlNode
? (switchWindows && jmlNode.isWindowContainer
? jpf.window
: jmlNode.$focusParent)
: jpf.document.documentElement;
var list    = fParent.$tabList;
if (jmlNode && (switchWindows || jmlNode != jpf.document.documentElement)) {
start   = (list || []).indexOf(jmlNode);
if (start == -1) {
return;
}
}
else
start = -1;
if (this.focussed && this.focussed == jmlNode
&& list.length == 1 || list.length == 0)
return false;
dir  = (shiftKey ? -1 : 1);
next = start;
if (start < 0)
start = 0;
do {
next += dir;
if (next >= list.length)
next = 0;
else if (next < 0)
next = list.length - 1;
if (start == next)
return false; 
jmlNode = list[next];
}
while (!jmlNode
|| jmlNode.disabled
|| jmlNode == jpf.window.focussed
|| (switchWindows ? !jmlNode.visible : jmlNode.oExt && !jmlNode.oExt.offsetHeight)
|| jmlNode.focussable === false
|| switchWindows && !jmlNode.$tabList.length);
if (fParent == jpf.window)
this.$focusLast(jmlNode, {mouse:true}, switchWindows);
else
this.$focus(jmlNode, e);
};
this.focusDefault = function(){
if (this.moveNext() === false) {
this.moveNext(null, jpf.document.documentElement, true)
}
};
window.onbeforeunload = function(){
return jpf.dispatchEvent("exit");
};
window.onunload = function(){
jpf.window.isExiting = true;
jpf.window.destroy();
};
var timer, state = "", last = "";
this.$focusfix = function(){
state += "a";
clearTimeout(timer);
setTimeout("window.focus();");
timer = setTimeout(determineAction);
}
this.$focusfix2 = function(){
state += "b";
clearTimeout(timer);
timer = setTimeout(determineAction);
}
this.$blurfix = function(){
state += "c";
clearTimeout(timer);
timer = setTimeout(determineAction);
}
function determineAction(){
clearTimeout(timer);
if (state == "e" || state == "c"
|| state.charAt(0) == "x" && !state.match(/eb$/)
|| state == "ce" || state == "de") { 
if (last != "blur") {
last = "blur";
jpf.window.dispatchEvent("blur");
}
}
else {
if (last != "focus") {
last = "focus";
jpf.window.dispatchEvent("focus");
}
}
state = "";
timer = null;
}
window.onfocus = function(){
if (jpf.hasFocusBug) {
state += "d";
clearTimeout(timer);
timer = setTimeout(determineAction);
}
else {
clearTimeout(iframeFixTimer)
iframeFix.newState = "focus";
iframeFixTimer = setTimeout(iframeFix, 10);
}
};
window.onblur = function(){
if (jpf.hasFocusBug) {
state += "e";
clearTimeout(timer);
timer = setTimeout(determineAction);
}
else {
clearTimeout(iframeFixTimer)
iframeFix.newState = "blur";
iframeFixTimer = setTimeout(iframeFix, 10);
}
};
var iframeFixTimer;
function iframeFix(){
clearTimeout(iframeFixTimer);
var newState = iframeFix.newState;
if (last == newState)
return;
last = newState;
jpf.window.dispatchEvent(last);
}
this.hasFocus = function(){
return last == "focus";
}
document.oncontextmenu = function(e){
if (!e)
e = event;
if (jpf.appsettings.disableRightClick)
return false;
};
var ta = {"INPUT":1, "TEXTAREA":1, "SELECT":1};
document.onmousedown = function(e){
if (!e) e = event;
var jmlNode = jpf.findHost(e.srcElement || e.target);
if (jpf.popup.last && jpf.popup.last != jmlNode.uniqueId)
jpf.popup.forceHide();
var p;
if ((!jmlNode || !jmlNode.$focussable || jmlNode.focussable === false)
&& jpf.appsettings.allowBlur) {
lastFocusParent = null;
if (jpf.window.focussed)
jpf.window.focussed.blur();
}
else if ((p = jpf.window.focussed && jpf.window.focussed.$focusParent || lastFocusParent)
&& p.visible && p.modal && jmlNode.$focusParent != p) {
jpf.window.$focusLast(p, {mouse: true});
}
else if (!jmlNode && jpf.window.focussed) {
jpf.window.$focusRoot();
}
else if (!jmlNode.disabled && jmlNode.focussable !== false) {
if (jmlNode.$focussable === jpf.KEYBOARD_MOUSE)
jpf.window.$focus(jmlNode, {mouse: true});
else if (jmlNode.canHaveChildren == 2) {
if (!jpf.appsettings.allowBlur)
jpf.window.$focusLast(jmlNode, {mouse: true});
}
else
jpf.window.$focusDefault(jmlNode, {mouse: true});
}
else
jpf.window.$focusDefault(jmlNode, {mouse: true});
if (jpf.hasFocusBug) {
var isContentEditable = ta[(e.srcElement || e.target).tagName]
&& !(e.srcElement || e.target).disabled || jmlNode.$isContentEditable
&& jmlNode.$isContentEditable(e) && !jmlNode.disabled;
if (!jmlNode || !isContentEditable)
jpf.window.$focusfix();
}
else if (!last) {
window.onfocus();
}
jpf.dispatchEvent("mousedown", {
htmlEvent : e,
jmlNode   : jmlNode
});
if (!jpf.isIE && (jpf.JmlParser && !jpf.appsettings.allowSelect
&& (!jpf.isParsingPartial || jmlNode)
|| jpf.dragmode.mode
) && !ta[e.target.tagName])
return false;
};
document.onselectstart = function(e){
if (!e) e = event;
if (jpf.JmlParser && !jpf.appsettings.allowSelect
|| jpf.dragmode.mode
|| jpf.dragmode.isDragging
)
return false;
};
document.onkeyup = function(e){
if (!e) e = event;
if (jpf.window.focussed
&& !jpf.window.focussed.disableKeyboard
&& jpf.window.focussed.dispatchEvent("keyup", {
keyCode  : e.keyCode,
ctrlKey  : e.ctrlKey,
shiftKey : e.shiftKey,
altKey   : e.altkey,
htmlEvent: e
}) === false) {
return false;
}
jpf.dispatchEvent("keyup", null, e);
};
document.onkeydown = function(e){
if (!e)
e = event;
if (jpf.appsettings.useUndoKeys && e.ctrlKey) {
if (e.keyCode == 90) {
var o = jpf.window.focussed;
if (!o || !o.getActionTracker)
o = jpf.window;
o.getActionTracker().undo();
}
else if (e.keyCode == 89) {
var o = jpf.window.focussed;
if (!o || !o.getActionTracker)
o = jpf.window;
o.getActionTracker().redo();
}
}
var eInfo = {
ctrlKey   : e.ctrlKey,
shiftKey  : e.shiftKey,
altKey    : e.altKey,
keyCode   : e.keyCode,
htmlEvent : e,
bubbles   : true
};
if (jpf.window.focussed && !jpf.window.focussed.disableKeyboard
&& jpf.window.focussed.dispatchEvent("keydown", eInfo) === false) {
e.returnValue  = false;
e.cancelBubble = true;
if (jpf.canDisableKeyCodes) {
try {
e.keyCode = 0;
}
catch(e) {}
}
return false;
}
else if ((!jpf.appsettings.disableTabbing || jpf.window.focussed) && e.keyCode == 9) {
if (e.ctrlKey) {
if (jpf.window.focussed) {
jpf.window.moveNext(e.shiftKey,
jpf.window.focussed.$focusParent, true);
var w = jpf.window.focussed.$focusParent;
if (w && w.bringToFront)
w.bringToFront();
}
}
else if(!jpf.window.focussed || jpf.window.focussed.tagName != "menu")
jpf.window.moveNext(e.shiftKey);
e.returnValue = false;
return false;
}
if (jpf.appsettings.disableBackspace
&& (e.keyCode == 8 || e.altKey && (e.keyCode == 37 || e.keyCode == 39))
&& !ta[(e.srcElement || e.target).tagName]) {
if (jpf.canDisableKeyCodes) {
try {
e.keyCode = 0;
}
catch(e) {}
}
e.returnValue = false;
}
if (jpf.appsettings.disableF5 && (e.keyCode == 116 || e.keyCode == 117)) {
if (jpf.canDisableKeyCodes) {
try {
e.keyCode = 0;
}
catch(e) {}
}
else {
e.preventDefault();
e.stopPropagation();
}
}
if (e.keyCode == 27) { 
e.returnValue = false;
}
if (!jpf.appsettings.allowSelect
&& e.shiftKey && (e.keyCode > 32 && e.keyCode < 41)
&& !ta[(e.explicitOriginalTarget || e.srcElement || e.target).tagName]
&& (!e.srcElement || e.srcElement.contentEditable != "true")) {
e.returnValue = false;
}
return e.returnValue;
};
this.destroy = function(){
this.$at = null;
jpf.destroy(this);
jpf.windowManager.destroy(this);
jpf           =
this.win      =
this.window   =
this.document = null;
window.onfocus        =
window.onerror        =
window.onunload       =
window.onbeforeunload =
window.onbeforeprint  =
window.onafterprint   =
window.onmousewheel   =
window.onblur         = null;
document.oncontextmenu =
document.onmousedown   =
document.onmousemove   =
document.onmouseup     =
document.onselectstart =
document.onmousewheel  =
document.onkeyup       =
document.onkeydown     = null
document.body.onmousedown =
document.body.onmousemove =
document.body.onmouseup   = null;
document.body.innerHTML = "";
};
};
jpf.DocumentImplementation = function(){
jpf.makeClass(this);
this.inherit(jpf.JmlDom); 
this.nodeType   = jpf.NODE_DOCUMENT;
this.nodeFunc   = jpf.NODE_HIDDEN;
this.$jmlLoaded = true;
this.documentElement = {
uniqueId      : jpf.all.push(this) - 1,
nodeType      :  1,
nodeFunc      : jpf.NODE_HIDDEN,
tagName       : "application",
parentNode    : this,
ownerDocument : this,
pHtmlNode     : document.body,
$jml          : jpf.JmlParser.$jml,
$tabList      : [], 
$jmlLoaded    : true,
$focussable   : jpf.KEYBOARD,
focussable    : true,
isWindowContainer : true,
canHaveChildren   : true,
focus : function(){
this.dispatchEvent("focus");
},
blur  : function(){
this.dispatchEvent("blur");
}
};
this.appendChild  =
this.insertBefore = function(){
this.documentElement.insertBefore.apply(this.documentElement, arguments);
};
jpf.inherit.call(this.documentElement, jpf.Class);
jpf.window.$addFocus(this.documentElement);
jpf.inherit.call(this.documentElement, jpf.JmlDom);
this.getElementById = function(id){
return self[id];
};
this.createElement = function(tagName){
var x, o;
if (tagName.nodeType) {
x = tagName;
}
else if (tagName.indexOf("<") > -1) {
x = jpf.getXml(tagName)
}
else {
var prefix = jpf.findPrefix(jpf.JmlParser.$jml, jpf.ns.jml);
var doc = jpf.JmlParser.$jml.ownerDocument;
if(jpf.JmlParser.$jml && doc.createElementNS) {
x = doc.createElementNS(jpf.ns.jml, prefix + ":" + tagName);
}
else {
x = jpf.getXml("<" + prefix + ":" + tagName + " xmlns:"
+ prefix + "='" + jpf.ns.jml + "' />", true);
}
}
if (jpf.isIE) {
if (!prefix)
prefix = x.prefix;
x.ownerDocument.setProperty("SelectionNamespaces",
"xmlns:" + prefix + "='" + jpf.ns.jml + "'");
}
tagName = x[jpf.TAGNAME];
var initId;
if (typeof jpf[tagName] != "function") { 
o = new jpf.JmlDom(tagName, null, jpf.NODE_HIDDEN, x);
if (jpf.JmlParser.handler[tagName]) {
initId = o.$domHandlers["reparent"].push(function(b, pNode){
this.$domHandlers.reparent[initId] = null;
if (!pNode.$jmlLoaded)
return; 
o = jpf.JmlParser.handler[tagName](this.$jml,
pNode, pNode.oInt);
if (o) jpf.extend(this, o); 
if (o && this.name)
jpf.nameserver.register(tagName, this.name, o);
if (this.name)
jpf.setReference(name, o);
o.$jmlLoaded = true;
}) - 1;
}
}
else {
o = new jpf[tagName](null, tagName, x);
if (o.loadJml) {
initId = o.$domHandlers["reparent"].push(function(b, pNode){
this.$domHandlers.reparent[initId] = null;
if (!pNode.$jmlLoaded) 
return;
function loadJml(o, pHtmlNode){
if (!o.$jmlLoaded) {
var length = o.childNodes.length;
o.pHtmlNode = pHtmlNode || document.body;
o.loadJml(o.$jml);
o.$jmlLoaded = false; 
if (length) {
for (var i = 0, l = o.childNodes.length; i < l; i++) {
if (o.childNodes[i].loadJml) {
loadJml(o.childNodes[i], o.canHaveChildren
? o.oInt
: document.body);
}
else
o.childNodes[i].$jmlLoaded = true;
}
}
}
if (o.$reappendToParent) {
o.$reappendToParent();
}
o.$jmlLoaded = true;
o.$reappendToParent = null;
}
var parsing = jpf.isParsing;
jpf.isParsing = true;
jpf.JmlParser.parseFirstPass([x]);
loadJml(o, pNode && pNode.oInt || document.body);
if (pNode.pData)
jpf.layout.activateRules(pNode.oInt || document.body);
jpf.JmlParser.parseLastPass();
jpf.isParsing = parsing;
}) - 1;
}
}
if (o.name)
jpf.setReference(o.name, o);
o.$jml = x;
return o;
};
this.createDocumentFragment = function(){
return new jpf.JmlDom(jpf.NODE_DOCUMENT_FRAGMENT)
}
};
jpf.sanitizeTextbox = function(oTxt){
oTxt.onfocus = function(){
jpf.window.$focusfix2();
};
oTxt.onblur = function(){
jpf.window.$blurfix();
};
}
var __INTERACTIVE__ = 1 << 21;
jpf.Interactive = function(){
var nX, nY, rX, rY, startPos, lastCursor = null, l, t, lMax, tMax, 
w, h, we, no, ea, so, rszborder, rszcorner, marginBox,
verdiff, hordiff, _self = this, posAbs, oX, oY, overThreshold,
dragOutline, resizeOutline;
this.$regbase = this.$regbase | __INTERACTIVE__;
this.$propHandlers["draggable"] = function(value){
if (jpf.isFalse(value))
this.draggable = value = false;
else if (jpf.isTrue(value))
this.draggable = value = true;
var o = this.oDrag || this.oExt;
if (o.interactive & 1) 
return;
var mdown = o.onmousedown;
o.onmousedown = function(){
if (mdown && mdown.apply(this, arguments) === false)
return;
dragStart.apply(this, arguments);
}
o.interactive = (o.interactive||0)+1;
};
this.$propHandlers["resizable"] = function(value){
if (jpf.isFalse(value))
this.resizable = value = false;
else if (jpf.isTrue(value))
this.resizable = value = true;
var o = this.oResize || this.oExt;
if (o.interactive & 2) 
return;
var mdown = o.onmousedown;
var mmove = o.onmousemove;
o.onmousedown = function(){
if (mdown && mdown.apply(this, arguments) === false)
return;
resizeStart.apply(this, arguments);
};
o.onmousemove = function(){
if (mmove && mmove.apply(this, arguments) === false)
return;
resizeIndicate.apply(this, arguments);
};
o.interactive = (o.interactive||0)+2;
rszborder = this.$getOption && parseInt(this.$getOption("Main", "resize-border")) || 3;
rszcorner = this.$getOption && parseInt(this.$getOption("Main", "resize-corner")) || 12;
marginBox = jpf.getBox(jpf.getStyle(this.oExt, "borderWidth"));
};
function dragStart(e){
if (!e) e = event;
if (!_self.draggable || jpf.dragmode.isDragging)
return;
dragOutline = false;        
jpf.dragmode.isDragging = true;
overThreshold           = false;
jpf.popup.forceHide();
posAbs = "absolute|fixed".indexOf(jpf.getStyle(_self.oExt, "position")) > -1;
if (!posAbs)
_self.oExt.style.position = "relative";
if (posAbs && !_self.aData) {
jpf.plane.show(dragOutline
? oOutline
: _self.oExt);
}
var pos = posAbs 
? jpf.getAbsolutePosition(_self.oExt, _self.oExt.offsetParent) 
: [parseInt(_self.oExt.style.left) || _self.oExt.offsetLeft || 0, 
parseInt(_self.oExt.style.top) || _self.oExt.offsetTop || 0];
nX = pos[0] - (oX = e.clientX);
nY = pos[1] - (oY = e.clientY);
if (_self.hasFeature && _self.hasFeature(__ANCHORING__))
_self.disableAnchoring();
jpf.dragmode.mode = true;
document.onmousemove = dragMove;
document.onmouseup   = function(){
document.onmousemove = document.onmouseup = null;
jpf.dragmode.mode = false;
if (posAbs && !_self.aData)
jpf.plane.hide();
if (overThreshold) {
if (_self.setProperty) {
if(l) _self.setProperty("left", l);
if(t) _self.setProperty("top", t);
}
else if (dragOutline) {
_self.oExt.style.left = l + "px";
_self.oExt.style.top  = t + "px";
}
}
if (!posAbs)
_self.oExt.style.position = "relative";
if (_self.showdragging)
jpf.setStyleClass(_self.oExt, "", ["dragging"]);
if (posAbs && dragOutline)
oOutline.style.display = "none";
jpf.dragmode.isDragging = false;
if (_self.dispatchEvent)
_self.dispatchEvent("drag");
};
if (jpf.isIE)
document.onmousedown();
return false;
};
function dragMove(e){
if(!e) e = event;
if (!overThreshold && _self.showdragging)
jpf.setStyleClass(_self.oExt, "dragging");
var dx = e.clientX - oX,
dy = e.clientY - oY,
distance; 
if (!overThreshold 
&& (distance = dx*dx > dy*dy ? dx : dy) * distance < 2)
return;
else if (!overThreshold && dragOutline 
&& oOutline.style.display != "block")
oOutline.style.display = "block";
var oHtml = dragOutline
? oOutline
: _self.oExt;
oHtml.style.left = (l = e.clientX + nX) + "px";
oHtml.style.top  = (t = e.clientY + nY) + "px";
overThreshold = true;
};
function resizeStart(e){
if (!e) e = event;
if (!_self.resizable)
return;
resizeOutline = false;        
if (!resizeOutline) {
var diff = jpf.getDiff(_self.oExt);
hordiff  = diff[0];
verdiff  = diff[1];
}
startPos = jpf.getAbsolutePosition(_self.oExt);
startPos.push(_self.oExt.offsetWidth);
startPos.push(_self.oExt.offsetHeight);
var sLeft = document.documentElement.scrollLeft;
var sTop = document.documentElement.scrollTop;
var x = (oX = e.clientX) - startPos[0] + sLeft;
var y = (oY = e.clientY) - startPos[1] + sTop;
var resizeType = getResizeType.call(_self.oExt, x, y);
rX = x;
rY = y;
if (!resizeType)
return;
if (_self.dispatchEvent && _self.dispatchEvent("resizestart", {
type : resizeType
}) === false)
return;
jpf.popup.forceHide();
if (_self.hasFeature && _self.hasFeature(__ANCHORING__))
_self.disableAnchoring();
jpf.dragmode.isDragging = true;
overThreshold           = false;
var r = "|" + resizeType + "|"
we = "|w|nw|sw|".indexOf(r) > -1;
no = "|n|ne|nw|".indexOf(r) > -1;
ea = "|e|se|ne|".indexOf(r) > -1;
so = "|s|se|sw|".indexOf(r) > -1;
if (!_self.minwidth)  _self.minwidth  = 0;
if (!_self.minheight) _self.minheight = 0;
if (!_self.maxwidth)  _self.maxwidth  = 10000;
if (!_self.maxheight) _self.maxheight = 10000;
if (posAbs) {
lMax = startPos[0] + startPos[2] - _self.minwidth;
tMax = startPos[1] + startPos[3] - _self.minheight;
lMin = startPos[0] + startPos[2] - _self.maxwidth;
tMin = startPos[1] + startPos[3] - _self.maxheight;
}
if (posAbs) {
jpf.plane.show(resizeOutline
? oOutline
: _self.oExt);
}
if (lastCursor === null)
lastCursor = document.body.style.cursor;
document.body.style.cursor = resizeType + "-resize";
jpf.dragmode.mode = true;
document.onmousemove = resizeMove;
document.onmouseup   = function(e){
document.onmousemove = document.onmouseup = null;
jpf.dragmode.mode = false;
if (posAbs)
jpf.plane.hide();
if (resizeOutline) {
var diff = jpf.getDiff(_self.oExt);
hordiff  = diff[0];
verdiff  = diff[1];
}
doResize(e || event, true);
if (_self.setProperty) {
if (posAbs) {
if (l) _self.setProperty("left", l);
if (t) _self.setProperty("top", t);
}
if (w) _self.setProperty("width", w + hordiff) 
if (h) _self.setProperty("height", h + verdiff); 
}
l = t = w = h = null;
document.body.style.cursor = lastCursor;
lastCursor = null;
if (resizeOutline)
oOutline.style.display = "none";
jpf.dragmode.isDragging = false;
if (_self.dispatchEvent)
_self.dispatchEvent("resize");
};
if (jpf.isIE)
document.onmousedown();
return false;
};
var min = Math.min, max = Math.max, lastTime;
function resizeMove(e){
if(!e) e = event;
if (lastTime && new Date().getTime() 
- lastTime < (resizeOutline ? 6 : jpf.mouseEventBuffer))
return;
lastTime = new Date().getTime();
doResize(e);
};
function doResize(e, force){
var oHtml = resizeOutline && !force
? oOutline
: _self.oExt;
var sLeft = document.documentElement.scrollLeft;
var sTop = document.documentElement.scrollTop;
if (we) {
oHtml.style.left = (l = max(lMin, min(lMax, e.clientX - rX + sLeft))) + "px";
oHtml.style.width = (w = min(_self.maxwidth - hordiff, 
max(hordiff, _self.minwidth, 
startPos[2] - (e.clientX - startPos[0]) + rX + sLeft
) - hordiff) + sLeft) + "px"; 
}
if (no) {
oHtml.style.top = (t = max(tMin, min(tMax, e.clientY - rY + sTop))) + "px";
oHtml.style.height = (h = min(_self.maxheight - verdiff, 
max(verdiff, _self.minheight, 
startPos[3] - (e.clientY - startPos[1]) + rY + sTop
) - verdiff)) + "px"; 
}
if (ea)
oHtml.style.width  = (w = min(_self.maxwidth - hordiff, 
max(hordiff, _self.minwidth, 
e.clientX - startPos[0] + (startPos[2] - rX) + sLeft)
- hordiff)) + "px";
if (so)
oHtml.style.height = (h = min(_self.maxheight - verdiff, 
max(verdiff, _self.minheight, 
e.clientY - startPos[1] + (startPos[3] - rY) + sTop)
- verdiff)) + "px";
if (jpf.hasSingleRszEvent)
jpf.layout.forceResize(_self.oInt);
}
function getResizeType(x, y){
var cursor  = "", 
tcursor = "";
posAbs = "absolute|fixed".indexOf(jpf.getStyle(_self.oExt, "position")) > -1;
if (_self.resizable == true || _self.resizable == "vertical") {
if (y < rszborder + marginBox[0])
cursor = posAbs ? "n" : "";
else if (y > this.offsetHeight - rszborder) 
cursor = "s";
else if (y > this.offsetHeight - rszcorner) 
tcursor = "s";
}
if (_self.resizable == true || _self.resizable == "horizontal") {
if (x < (cursor ? rszcorner : rszborder))  
cursor += tcursor + (posAbs ? "w" : "");
else if (x > this.offsetWidth - (cursor || tcursor ? rszcorner : rszborder)) 
cursor += tcursor + "e";
}
return cursor;
}
var originalCursor;
function resizeIndicate(e){
if(!e) e = event;
if (!_self.resizable || document.onmousemove)
return;
var pos = jpf.getAbsolutePosition(_self.oExt);
var sLeft = document.documentElement.scrollLeft;
var sTop = document.documentElement.scrollTop;
var x = e.clientX - pos[0] + sLeft;
var y = e.clientY - pos[1] + sTop;
if (!originalCursor)
originalCursor = jpf.getStyle(this, "cursor");
var cursor = getResizeType.call(_self.oExt, x, y);
this.style.cursor = cursor 
? cursor + "-resize" 
: originalCursor || "default";
};
if (!this.pHtmlDoc)
this.pHtmlDoc = window.document;
};
var __MEDIA__ = 1 << 20;
var __DELAYEDRENDER__ = 1 << 11
var __DATABINDING__ = 1 << 1;
jpf.DataBinding = function(){
var loadqueue;
var cXmlOnLoad = [];
var cXmlSelect = [];
var cXmlChoice = [];
this.$regbase  = this.$regbase | __DATABINDING__;
this.mainBind  = "value";
var _self      = this;
this.getMainBindXpath = function(){
if (this.hasFeature(__MULTIBINDING__))
return this.$getMultiBind().getMainBindXpath();
var m = this.getModel(true);
return (m && m.connect
? m.connect.select + "/"
: (this.dataParent
? this.dataParent.xpath + "/"
: "")) + this.smartBinding.bindings[this.mainBind][0].getAttribute("select");
};
this.isBoundComplete = function(){
if (!this.smartBinding) return true;
if (!this.xmlRoot) return false;
if (this.hasFeature(__MULTIBINDING__) && !this.$getMultiBind().xmlRoot)
return false;
return true;
};
this.queryValue = function(xpath, type){
return jpf.getXmlValue(this[type || 'xmlRoot'], xpath );
};
	
this.queryValues = function(xpath, type){
return jpf.getXmlValues(this[type || 'xmlRoot'], xpath );
};
	
this.queryNode = function(xpath, type){
var n = this[type||'xmlRoot'];
		return n?n.selectSingleNode(xpath):null;
};
this.queryNodes = function(xpath, type){
var n = this[type||'xmlRoot'];
		return n?n.selectNodes(xpath):null;
};
	
this.loadBindings = function(rules, node){
if (this.bindingRules)
this.unloadBindings();
this.bindingRules = rules;
if (this.$loaddatabinding)
this.$loaddatabinding();
if (this.bindingRules["traverse"])
this.parseTraverse(this.bindingRules["traverse"][0]);
this.$checkLoadQueue();
};
this.$checkLoadQueue = function(){
if (loadqueue) {
if (this.load(loadqueue[0], loadqueue[1]) != loadqueue)
loadqueue = null;
}
};
this.unloadBindings = function(){
if (this.$unloaddatabinding)
this.$unloaddatabinding();
var node = this.xmlBindings;
if (!node || !node.getAttribute("connect"))
return;
try {
var o = eval(node.getAttribute("connect"));
o.disconnect(this, node.getAttribute("type"));
}
catch(e) {}
this.bindingRules = null;
return this.uniqueId;
};
this.loadActions = function(rules, node){
if (this.actionRules)
this.unloadActions();
this.actionRules = rules;
};
this.getActionTracker = function(ignoreMe){
if (!jpf.JmlDom)
return jpf.window.$at;
var pNode = this, tracker = ignoreMe ? null : this.$at;
if (!tracker && this.connectId)
tracker = self[this.connectId].$at;
while (!tracker) {
if (!pNode.parentNode)
return jpf.window.$at;
tracker = (pNode = pNode.parentNode).$at;
}
return tracker;
};
this.unloadActions = function(){
this.xmlActions  = null;
this.actionRules = null;
if (this.$at) {
this.$at = null;
}
};
var actions = {};
this.$startAction = function(name, xmlContext, fRollback){
if (this.disabled)
return false;
var actionRule = this.getNodeFromRule(name, xmlContext, true);
if (jpf.appsettings.autoDisableActions && !this.actionRules 
|| this.actionRules && !actionRule)
return false;
var bHasOffline = typeof jpf.offline != "undefined";
if (this.dispatchEvent(name + "start", {
xmlContext: xmlContext
}) === false)
return false;
actions[name] = xmlContext;
return true;
};
this.$stopAction = function(name, isCancelled, curLock){
delete actions[name];
};
this.executeAction = function(atAction, args, action, xmlNode, noevent, contextNode, multiple){
if (this.disabled) return; 
var rules = this.actionRules
? this.actionRules[action]
: (!action.match(/change|select/) && jpf.appsettings.autoDisableActions
? false
: []);
if (!rules)
return false;
for (var node, i = 0; i < (rules.length || 1); i++) {
if (!rules[i] || !rules[i].getAttribute("select")
|| xmlNode.selectSingleNode(rules[i].getAttribute("select"))) {
var ev = new jpf.Event("before" + action.toLowerCase(), {
action        : atAction,
args          : args,
xmlActionNode : rules[i],
jmlNode       : this,
selNode       : contextNode,
multiple      : multiple || false
});
if (!noevent) {
if (this.dispatchEvent(ev.name, null, ev) === false)
return false;
}
var UndoObj = this.getActionTracker().execute(ev);
ev.xmlNode = UndoObj.xmlNode;
ev.undoObj = UndoObj;
if (!noevent) {
ev.name         = "after" + action.toLowerCase();
ev.cancelBubble = false;
delete ev.returnValue;
this.dispatchEvent(ev.name, null, ev);
}
return UndoObj;
}
}
return false;
};
this.executeActionByRuleSet = function(atName, setName, xmlNode, value){
var xpath, args, selInfo = this.getSelectFromRule(setName, xmlNode);
var shouldLoad = false, atAction, node = selInfo[1];
if (node) {
if (jpf.xmldb.getNodeValue(node) == value) return; 
atAction = (node.nodeType == 1 || node.nodeType == 3
|| node.nodeType == 4) ? "setTextNode" : "setAttribute";
args = (node.nodeType == 1)
? [node, value]
: (node.nodeType == 3 || node.nodeType == 4
? [node.parentNode, value]
: [node.ownerElement || node.selectSingleNode(".."), node.nodeName, value]);
}
else {
if (!this.createModel)
return false;
atAction = "setValueByXpath";
xpath    = selInfo[0];
if (!xmlNode) {
var model   = this.getModel();
if (model) {
if (!model.data)
model.load("<data />");
xpath   = (model.getXpathByJmlNode(this) || ".")
+ (xpath && xpath != "." ? "/" + xpath : "");
xmlNode = model.data;
}
else {
if (!this.dataParent)
return false;
xmlNode = this.dataParent.parent.selected;
xpath = this.dataParent.xpath;
shouldLoad = true;
}
}
args = [xmlNode, value, xpath];
}
this.executeAction(atAction, args, atName, xmlNode);
if (shouldLoad)
this.load(xmlNode.selectSingleNode(xpath));
};
this.connect = function(o, dataOnly, xpath, type, noselect){
if (o.dataParent)
o.dataParent.parent.disconnect(o);
if (!this.signalXmlUpdate)
this.signalXmlUpdate = {};
o.dataParent = {
parent: this,
xpath : xpath
};
if (dataOnly) {
if (cXmlOnLoad)
return cXmlOnLoad.push([o, xpath]);
else
return o.load(xpath ? this.xmlRoot.selectSingleNode(xpath) : this.selected);
}
if (!dataOnly)
(!type || type == "select")
? cXmlSelect.push({o:o,xpath:xpath})
: cXmlChoice.push({o:o,xpath:xpath});
if (type != "choice" && !noselect) {
if (this.selected || !this.traverse && this.xmlRoot) {
var xmlNode = this.selected || this.xmlRoot;
if (xpath) {
xmlNode = xmlNode.selectSingleNode(xpath);
if (!xmlNode) {
this.addEventListener("xmlupdate", function(){
this.connect(o, false, xpath, type);
this.removeEventListener("xmlupdate", arguments.callee);
});
}
}
if (xmlNode)
o.load(xmlNode);
}
else {
if (o.clear && !o.hasFeature(__MULTIBINDING__))
o.clear(); 
if (o.disable && o.createModel)
o.disable();
}
}
};
this.disconnect = function(o, type){
var ar = (!type || type == "select") ? cXmlSelect : cXmlChoice; 
if (this.signalXmlUpdate) {
this.signalXmlUpdate[o.uniqueId] = null;
delete this.signalXmlUpdate[o.uniqueId];
}
o.dataParent = null;
for (var i = 0; i < ar.length; i++){
if (ar[i].o != o) continue;
for (var j = i; j < ar.length; j++)
ar[j] = ar[j + 1];
ar.length--;
i--;
}
};
this.setConnections = function(xmlNode, type){
var a = type == "both"
? cXmlChoice.concat(cXmlSelect)
: (type == "choice" ? cXmlChoice : cXmlSelect);
for (var x, o, i = 0; i < a.length; i++) {
o     = a[i].o;
xpath = a[i].xpath;
o.load((xpath && xmlNode)
? xmlNode.selectSingleNode(xpath)
: xmlNode);
if (xmlNode && o.disabled && o.createModel)
o.enable();
}
if (!cXmlOnLoad) return;
for (var i = 0; i < cXmlOnLoad.length; i++)
cXmlOnLoad[i][0].load(cXmlOnLoad[i][1]
? this.xmlRoot.selectSingleNode(cXmlOnLoad[i][1])
: this.selected);
cXmlOnLoad = null;
};
this.importConnections = function(x){
cXmlSelect = x;
};
this.getConnections = function(){
return cXmlSelect;
};
this.removeConnections = function(){
cXmlSelect = [];
};
this.applyRuleSetOnNode = function(setname, cnode, def){
if (!cnode) return "";
var rules = typeof setname == "string"
? (this.bindingRules || {})[setname]
: setname;
if (!rules) {
if (setname == "value") setname = "valuerule";
return typeof this[setname] == "string" && setname != "value"
&& jpf.getXmlValue(cnode, this[setname])
|| def && cnode.selectSingleNode(def) || false;
}
var node = null, sel, i, o, v, rule;
for (i = 0; i < rules.length; i++) {
rule = rules[i];
sel  = jpf.parseExpression(rule.getAttribute("select")) || ".";
o    = cnode.selectSingleNode(sel);
if (o) {
this.lastRule = rule;
if (v = rule.getAttribute("value")){ 
return v;
}
else if(v = rule.getAttribute("method")){
if(!self[v]){
return false;
}
return self[v](o, this);
}
else if(v = rule.getAttribute("eval")){
var func = new Function('xmlNode', 'control', "return " + v);
var value = func.call(this, o, this);
if (!value) continue;
return value;
}
else {
var value;
if (o.nodeType == 2) {
try {
value = unescape(decodeURI(o.nodeValue));
}
catch(e) {
value = unescape(o.nodeValue);
}
}
else {
if (o.nodeType == 1) {
if (!o.firstChild || o.firstChild.nodeType == 1 || o.firstChild.nodeType > 4)
return "";
value = o.firstChild.nodeValue;
}
else                        
value = o.nodeValue;
}
return value;
}
}
}
return false;
};
this.setSmartBinding = function(sb){
this.$propHandlers["smartbinding"].call(this, sb);
};
this.removeSmartBinding = function(){
this.setProperty("smartbinding", null);
};
this.getSmartBinding = function(){
return this.smartBinding;
};
this.getModel = function(doRecur){
if(doRecur && !this.$model)
return this.dataParent ? this.dataParent.parent.getModel(true) : null;
return this.$model;
};
this.setModel = function(model, xpath){
if (this.$model)
this.$model.unregister(this);
if (typeof model == "string")
model = jpf.nameserver.get("model", model);
this.$model = model;
model.register(this, xpath);
};
this.getNodeFromRule = function(setname, cnode, isAction, getRule, createNode){
var rules = ((isAction ? this.actionRules : this.bindingRules) || {})[setname];
if (!rules) {
if (setname == "value") setname = "valuerule";
if (!isAction && !getRule && typeof this[setname] == "string") {
return cnode.selectSingleNode(this[setname]) || (createNode
? jpf.xmldb.createNodeFromXpath(cnode, this[setname])
: false);
}
return false;
}
for(var i = 0; i < rules.length; i++) {
if (!rules[i]) continue;
var sel = jpf.parseExpression(rules[i].getAttribute("select")) || ".";
if (!sel)
return getRule ? rules[i] : false;
if (!cnode) return false;
var o = cnode.selectSingleNode(sel);
if (o)
return getRule ? rules[i] : o;
if (createNode || rules[i].getAttribute("create") == "true") {
var o = jpf.xmldb.createNodeFromXpath(cnode, sel);
return getRule ? rules[i] : o;
}
}
return false;
};
this.getSelectFromRule = function(setname, cnode){
var rules = this.bindingRules && this.bindingRules[setname];
if (!rules || !rules.length) {
if (setname == "value") setname = "valuerule";
return typeof this[setname] == "string" && [this[setname]] || ["."];
}
for (var first, i = 0; i < rules.length; i++) {
var sel = jpf.parseExpression(rules[i].getAttribute("select")) || ".";
if (!cnode) return [sel];
if (i == 0)
first = sel;
var o = cnode.selectSingleNode(sel);
if (o)
return [sel, o];
}
return [first];
};
this.reload = function(){
var sb = this.getSmartBinding();
if (sb && sb.$isMarkedForUpdate(this)) {
sb.$updateMarkedItems();
}
else
this.load(this.xmlRoot, this.cacheID, true);
};
this.load = function(xmlRootNode, cacheID, forceNoCache, noClearMsg){
if (jpf.popup.isShowing(this.uniqueId))
jpf.popup.forceHide(); 
if ((!this.bindingRules && this.$jml
&& (!this.smartBinding || jpf.JmlParser.stackHasBindings(this.uniqueId))
&& !this.traverse) || (this.$canLoadData && !this.$canLoadData())) {
return loadqueue = [xmlRootNode, cacheID];
}
if (xmlRootNode)
xmlRootNode = jpf.xmldb.getBindXmlNode(xmlRootNode);
if (this.dataParent && this.dataParent.xpath)
this.dataParent.parent.signalXmlUpdate[this.uniqueId] = !xmlRootNode;
if (!xmlRootNode && (!cacheID || !this.isCached(cacheID))) {
this.clear(noClearMsg, true);
if (jpf.appsettings.autoDisable && !this.createModel)
this.disable();
this.setConnections();
return;
}
var disabled = this.disabled;
this.disabled = false;
if (this.$listenRoot) {
jpf.xmldb.removeNodeListener(this.$listenRoot, this);
this.$listenRoot = null;
}
if (this.dispatchEvent("beforeload", {xmlNode : xmlRootNode}) === false)
return false;
if (this.caching && !forceNoCache && xmlRootNode && xmlRootNode == this.xmlRoot)
return;
if (!cacheID) {
cacheID = xmlRootNode.getAttribute(jpf.xmldb.xmlIdTag) ||
jpf.xmldb.nodeConnect(jpf.xmldb.getXmlDocId(xmlRootNode), xmlRootNode);
}
if (this.$removeClearMessage)
this.$removeClearMessage();
var fromCache;
if (this.caching && !forceNoCache && (fromCache = this.getCache(cacheID, xmlRootNode))) {
if (fromCache == -1)
return;
if (!this.hasFeature(__MULTISELECT__))
this.setConnections(this.xmlRoot, "select");
else {
var nodes = this.getTraverseNodes();
if (nodes.length && this.autoselect)
this.select(nodes[0], null, null, null, true);
else
this.setConnections();
if (!nodes.length)
this.$setClearMessage(this.emptyMsg, "empty");
}
if (this.hasFeature(__MULTISELECT__) && nodes.length != this.length)
this.setProperty("length", nodes.length);
this.dispatchEvent('afterload', {XMLRoot : xmlRootNode});
return;
}
else
this.clear(true);
this.documentId = jpf.xmldb.getXmlDocId(xmlRootNode);
this.cacheID    = cacheID;
this.xmlRoot    = xmlRootNode;
this.$load(xmlRootNode);
this.$loadSubData(xmlRootNode);
if (!this.createModel) {
this.disabled = true;
this.enable();
}
else
this.disabled = disabled;
if (!this.hasFeature(__MULTISELECT__))
this.setConnections(this.xmlRoot);
this.dispatchEvent('afterload', {XMLRoot : xmlRootNode});
};
this.$loadSubData = function(xmlRootNode){
if (this.hasLoadStatus(xmlRootNode)) return;
var loadNode, rule = this.getNodeFromRule("load", xmlRootNode, false, true);
var sel = (rule && rule.getAttribute("select"))
? rule.getAttribute("select")
: ".";
if (rule && (loadNode = xmlRootNode.selectSingleNode(sel))) {
this.setLoadStatus(xmlRootNode, "loading");
if (this.$setClearMessage)
this.$setClearMessage(this.loadingMsg, "loading");
var mdl = this.getModel(true);
var jmlNode = this;
if (mdl.insertFrom(rule.getAttribute("get"), loadNode, {
insertPoint : xmlRootNode, 
jmlNode     : this
}, function(){
jmlNode.setConnections(xmlRootNode);
}) === false
) {
this.clear(true);
if (jpf.appsettings.autoDisable)
this.disable();
this.setConnections(null, "select"); 
}
}
};
this.setLoadStatus = function(xmlNode, state, remove){
var ostatus = xmlNode.getAttribute("j_loaded");
ostatus = ostatus
? ostatus.replace(new RegExp("\\|\\w+\\:" + this.uniqueId + "\\|", "g"), "")
: "";
if (!remove)
ostatus += "|" + state + ":" + this.uniqueId + "|";
xmlNode.setAttribute("j_loaded", ostatus);
};
this.removeLoadStatus = function(xmlNode){
this.setLoadStatus(xmlNode, null, true);
};
this.hasLoadStatus = function(xmlNode, state){
var ostatus = xmlNode.getAttribute("j_loaded");
if (!ostatus) return false;
return (ostatus.indexOf((state || "") + ":" + this.uniqueId + "|") != -1)
};
this.insert = function(XMLRoot, parentXMLElement, options){
if (typeof XMLRoot != "object")
XMLRoot = jpf.getXmlDom(XMLRoot).documentElement;
if (!parentXMLElement)
parentXMLElement = this.xmlRoot;
if (this.dispatchEvent("beforeinsert", {xmlParentNode : parentXMLElement}) === false)
return false;
var newNode = jpf.xmldb.integrate(XMLRoot, parentXMLElement,
jpf.extend(options, {copyAttributes: true}));
jpf.xmldb.applyChanges("insert", parentXMLElement);
if (this.selectable && this.autoselect) {
if (this.xmlRoot == newNode)
this.$selectDefault(this.xmlRoot);
}
else if (this.xmlRoot == newNode)
this.setConnections(this.xmlRoot, "select");
if (this.hasLoadStatus(parentXMLElement, "loading"))
this.setLoadStatus(parentXMLElement, "loaded");
this.dispatchEvent("afterinsert");
};
this.inherit(this.hasFeature(__MULTISELECT__)
? jpf.MultiselectBinding
: jpf.StandardBinding);
function findModel(x, isSelection) {
return x.getAttribute((isSelection
? "ref"
: "") + "model") || jpf.xmldb.getInheritedAttribute(x, null,
function(xmlNode){
if (isSelection && x == xmlNode)
return false;
if (xmlNode.getAttribute("model")) {
return xmlNode.getAttribute("model");
}
if (xmlNode.getAttribute("smartbinding")) {
var bclass = x.getAttribute("smartbinding").split(" ")[0];
if (jpf.nameserver.get("model", bclass))
return bclass + ":select";
}
return false
});
}
var initModelId = [];
this.$addJmlLoader(function(x){
if (initModelId[0])
jpf.setModel(initModelId[0], this);
if (initModelId[1])
jpf.setModel(initModelId[1], this, true);
var hasModel = initModelId.length;
if ((!this.ref || this.hasFeature(__MULTISELECT__)) && !this.xmlRoot) {
var sb = jpf.JmlParser.sbInit[this.uniqueId]
&& jpf.JmlParser.sbInit[this.uniqueId][0];
if (this.traverse && (sb && !sb.model
|| !sb && this.hasFeature(__MULTISELECT__))
|| !initModelId[0] && sb) {
initModelId = findModel(x);
if (initModelId) {
if (!sb)
this.smartBinding = true; 
jpf.setModel(initModelId, this, 0);
}
}
}
initModelId = null;
if (this.hasFeature(__MULTISELECT__) || this.$hasStateMessages) {
var defProps = ["empty-message", "loading-message", "offline-message"];
for (var i = 0, l = defProps.length; i < l; i++) {
if (!x.getAttribute(defProps[i]))
this.$propHandlers[defProps[i]].call(this);
}
}
if (!x.getAttribute("create-model"))
this.$propHandlers["create-model"].call(this);
var hasInitSb = jpf.JmlParser.sbInit[this.uniqueId] ? true : false;
if ((!hasInitSb || !hasModel) && this.$setClearMessage
&& (!loadqueue && !this.xmlRoot && (this.hasFeature(__MULTISELECT__)
|| this.ref || hasInitSb)))
this.$setClearMessage(this.emptyMsg, "empty");
});
this.$jmlDestroyers.push(function(){
if (this.dataParent)
this.dataParent.parent.disconnect(this);
if (this.hasFeature(__DATABINDING__)) {
this.unloadBindings();
this.unloadActions();
}
});
this.$booleanProperties["render-root"] = true;
this.$supportedProperties.push("empty-message", "loading-message",
"offline-message", "render-root", "smartbinding", "create-model",
"bindings", "actions", "dragdrop");
this.$propHandlers["render-root"] = function(value){
this.renderRoot = value;
}
this.$propHandlers["empty-message"] = function(value){
this.emptyMsg = value
|| jpf.xmldb.getInheritedAttribute(this.$jml, "empty-message")
|| "No items";
if (!jpf.isParsing) 
this.$updateClearMessage(this.emptyMsg, "empty");
};
this.$propHandlers["loading-message"] = function(value){
this.loadingMsg = value
|| jpf.xmldb.getInheritedAttribute(this.$jml, "loading-message")
|| "Loading...";
if (!jpf.isParsing)
this.$updateClearMessage(this.loadingMsg, "loading");
};
this.$propHandlers["offline-message"] = function(value){
this.offlineMsg = value
|| jpf.xmldb.getInheritedAttribute(this.$jml, "offline-message")
|| "You are currently offline...";
if (!jpf.isParsing)
this.$updateClearMessage(this.offlineMsg, "offline");
};
this.$propHandlers["create-model"] = function(value){
this.createModel = !jpf.isFalse(
jpf.xmldb.getInheritedAttribute(this.$jml, "create-model"));
var mb;
if (this.getMultibinding && (mb = this.getMultibinding()))
mb.createModel = this.createModel;
};
this.$propHandlers["smartbinding"] = function(value, forceInit){
var sb;
if (value && typeof value == "string") {
sb = jpf.JmlParser.getSmartBinding(value);
}
else
sb = value;
if (this.smartBinding && this.smartBinding.deinitialize)
this.smartBinding.deinitialize(this)
if (jpf.isParsing) {
if (forceInit === true)
return (this.smartBinding = sb.initialize(this));
return jpf.JmlParser.addToSbStack(this.uniqueId, sb);
}
return (this.smartBinding = sb.markForUpdate(this));
};
this.$propHandlers["bindings"] = function(value){
var sb = this.smartBinding || (jpf.isParsing
? jpf.JmlParser.getFromSbStack(this.uniqueId)
: this.$propHandlers["smartbinding"].call(this, new jpf.smartbinding()));
if (!value) {
throw new Error("Not Implemented"); 
return;
}
sb.addBindings(jpf.nameserver.get("bindings", value));
};
this.$propHandlers["actions"] = function(value){
var sb = this.smartBinding || (jpf.isParsing
? jpf.JmlParser.getFromSbStack(this.uniqueId)
: this.$propHandlers["smartbinding"].call(this, new jpf.smartbinding()));
if (!value) {
throw new Error("Not Implemented"); 
return;
}
sb.addActions(jpf.nameserver.get("actions", value));
};
function refModelPropSet(strBindRef){
var isSelection = this.hasFeature(__MULTISELECT__) ? 1 : 0;
var o = isSelection
? this.$getMultiBind()
: this;
var sb = hasRefBinding && o.smartBinding || (jpf.isParsing
? jpf.JmlParser.getFromSbStack(this.uniqueId, isSelection, true)
: this.$propHandlers["smartbinding"].call(this, new jpf.smartbinding()))
if (!hasRefBinding) {
if (o.bindingRules)
o.unloadBindings();
o.bindingRules = {};
}
var bindRule = (o.bindingRules[o.mainBind] ||
(o.bindingRules[o.mainBind]
= [jpf.getXml("<" + (o.mainBind || "value") + " />")]))[0];
((sb.bindings || (sb.bindings = o.bindingRules))[o.mainBind])
|| (sb.bindings[o.mainBind] = [bindRule]);
var model, modelId;
if (!jpf.isParsing)
model = o.getModel();
if (!model) {
modelId = o.lastModelId =
o.model || findModel(this.$jml, isSelection);
if (!modelId) {
if (jpf.globalModel) {
modelId = "@default";
}
}
}
strBindRef.match(/^(.*?)((?:\@[\w-_\:]+|text\(\))(\[.*?\])?|[\w-_\:]+\[.*?\])?$/);
var valuePath   = RegExp.$1;
var valueSelect = RegExp.$2 || ".";
if (valuePath === null) {
return;
}
if (modelId) {
if (modelId == "@default") {
valueSelect = strBindRef;
}
else if (valuePath) {
var modelIdParts = modelId.split(":", 3);
modelId = modelIdParts.shift();
if (modelId.indexOf("#") == 0) {
modelId += (modelIdParts[0]
? ":" + modelIdParts.shift()
: ":select")
}
modelId += ":" + ((modelIdParts[0] ? modelIdParts[0] + "/" : "")
+ (valuePath || "."))
.replace(/\/$/, "")
.replace(/\/\/+/, "/");
}
if (jpf.isParsing && initModelId)
initModelId[isSelection] = modelId
else
setModelQueue(modelId, isSelection);
}
else {
var m = (o.lastModelId || "").split(":");
var modelIdPart = ((m.shift().indexOf("#") == 0
&&  m.shift() && m.shift() || m.shift()) || "");
model.$register(this, ((modelIdPart ? modelIdPart + "/" : "")
+ (valuePath || "."))
.replace(/\/$/, "")
.replace(/\/\/+/, "/")); 
sb.markForUpdate(this, "model");
}
bindRule.setAttribute("select", valueSelect);
}
var timer = [];
function setModelQueue(modelId, isSelection){
clearTimeout(timer[isSelection ? 1 : 0]);
timer[isSelection ? 1 : 0] = setTimeout(function(){
jpf.setModel(modelId, _self, isSelection);
});
}
this.$propHandlers["model"] = function(value){
if (!value) {
this.clear();
this.$model.unregister(this);
this.$model = null;
this.lastModelId = "";
return;
}
this.lastModelId = value;
if (!this.hasFeature(__MULTISELECT__)) {
if (jpf.isParsing && this.$jml.getAttribute("ref")) 
return; 
if (this.ref) {
refModelPropSet.call(this, this.ref);
return;
}
}
if (jpf.isParsing)
initModelId[0] = value;
else
setModelQueue(value, this.hasFeature(__MULTISELECT__));
};
var hasRefBinding;
this.$propHandlers["ref"] = function(value){
if (!value) {
this.unloadBindings();
hasRefBinding = false;
return;
}
refModelPropSet.call(this, value);
hasRefBinding = value ? true : false;
};
};
jpf.StandardBinding = function(){
if (!this.defaultValue) 
this.defaultValue = "";
this.$load = function(XMLRoot){
jpf.xmldb.addNodeListener(XMLRoot, this);
var lrule, rule;
for (rule in this.bindingRules) {
lrule = rule.toLowerCase();
if (this.$supportedProperties.contains(lrule))
this.setProperty(lrule, this.applyRuleSetOnNode(rule,
this.xmlRoot) || "", null, true);
}
if (this.errBox && this.isValid())
this.clearError();
};
this.$xmlUpdate = function(action, xmlNode, listenNode, UndoObj){
if (action == "redo-remove") {
var testNode = this.xmlRoot;
while (testNode && testNode.nodeType != 9)
testNode = testNode.parentNode;
if (!testNode) {
var model = this.getModel(true);
if (!model)
return;
return model.loadInJmlNode(this, model.getXpathByJmlNode(this));
}
}
if (UndoObj && !UndoObj.xmlNode)
UndoObj.xmlNode = this.xmlRoot;
var lrule, rule;
for (rule in this.bindingRules) {
lrule = rule.toLowerCase();
if (this.$supportedProperties.contains(lrule)) {
var value = this.applyRuleSetOnNode(rule, this.xmlRoot) || "";
if (this[lrule] != value)
this.setProperty(lrule, value, null, true);
}
}
if (this.errBox && this.isValid())
this.clearError();
};
if (!this.clear) {
this.clear = function(nomsg, do_event){
this.documentId = this.xmlRoot = this.cacheID = null;
if (this.$clear)
this.$clear(nomsg, do_event);
};
}
};
jpf.MultiselectBinding = function(){
this.length = 0;
this.parseTraverse = function (xmlNode){
this.traverse = xmlNode.getAttribute("select");
};
this.getTraverseNodes = function(xmlNode){
return (xmlNode || this.xmlRoot).selectNodes(this.traverse);
};
this.getFirstTraverseNode = function(xmlNode){
return (xmlNode || this.xmlRoot).selectSingleNode(this.traverse);
};
this.getLastTraverseNode = function(xmlNode){
var nodes = this.getTraverseNodes(xmlNode || this.xmlRoot);
return nodes[nodes.length-1];
};
this.isTraverseNode = function(xmlNode){
var nodes = this.getTraverseNodes(this.isTreeArch
? this.getTraverseParent(xmlNode) || this.xmlRoot
: this.xmlRoot);
for (var i = 0; i < nodes.length; i++)
if (nodes[i] == xmlNode)
return true;
return false;
};
this.getNextTraverseSelected = function(xmlNode, up, count){
if (!xmlNode)
xmlNode = this.selected;
if (!count)
count = 1;
var i = 0;
var nodes = this.getTraverseNodes(this.getTraverseParent(xmlNode) || this.xmlRoot);
while (nodes[i] && nodes[i] != xmlNode)
i++;
var node = (up == null)
? nodes[i + count] || nodes[i - count]
: (up ? nodes[i + count] : nodes[i - count]);
return node || arguments[2] && (i < count || (i + 1) > Math.floor(nodes.length / count) * count)
? node
: (up ? nodes[nodes.length-1] : nodes[0]);
};
this.getNextTraverse = function(xmlNode, up, count){
if (!count)
count = 1;
if (!xmlNode)
xmlNode = this.selected;
var i = 0;
var nodes = this.getTraverseNodes(this.getTraverseParent(xmlNode) || this.xmlRoot);
while (nodes[i] && nodes[i] != xmlNode)
i++;
return nodes[i + (up ? -1 * count : count)];
};
this.getTraverseParent = function(xmlNode){
if (!xmlNode.parentNode || xmlNode == this.xmlRoot) return false;
var x, id = xmlNode.getAttribute(jpf.xmldb.xmlIdTag);
if (!id) {
xmlNode.setAttribute(jpf.xmldb.xmlIdTag, "temp");
id = "temp";
}
if (jpf.isSafari) {
var y = this.traverse.split("\|");
for (var i = 0; i < y.length; i++) {
x = xmlNode.selectSingleNode("ancestor::node()[("
+ y[i] + "/@" + jpf.xmldb.xmlIdTag + "='" + id + "')]");
break;
}
} else {
x = xmlNode.selectSingleNode("ancestor::node()[(("
+ this.traverse + ")/@" + jpf.xmldb.xmlIdTag + ")='"
+ id + "']");
}
if (id == "temp")
xmlNode.removeAttribute(jpf.xmldb.xmlIdTag);
return x;
};
this.$load = function(XMLRoot){
jpf.xmldb.addNodeListener(XMLRoot, this);
var length = this.getTraverseNodes(XMLRoot).length;
if (!this.renderRoot && !length)
return this.clearAllTraverse();
var nodes = this.$addNodes(XMLRoot, null, null, this.renderRoot);
this.$fill(nodes);
if (this.selectable) {
if (this.autoselect) {
if (this.value) {
var value = this.value;
this.value = !this.value;
this.setProperty("value", value);
}
if (!this.selected) {
if (this.renderRoot)
this.select(XMLRoot);
else if (nodes.length)
this.$selectDefault(XMLRoot);
else
this.setConnections();
}
}
else {
this.clearSelection(null, true);
var xmlNode = this.renderRoot
? this.xmlRoot
: this.getFirstTraverseNode(); 
if (xmlNode)
this.setIndicator(xmlNode);
this.setConnections(null, "both");
}
}
if (this.focussable)
jpf.window.focussed == this ? this.$focus() : this.$blur();
if (length != this.length)
this.setProperty("length", length);
};
var selectTimer = {}, _self = this;
var actionFeature = {
"insert"      : 127,
"add"         : 123,
"remove"      : 47, 
"redo-remove" : 79, 
"synchronize" : 127,
"move-away"   : 105,
"move"        : 77  
};
this.$xmlUpdate = function(action, xmlNode, listenNode, UndoObj, lastParent){
if (!this.xmlRoot)
return; 
var result, startNode = xmlNode, length;
if (!listenNode)
listenNode = this.xmlRoot;
if (action == "redo-remove") {
lastParent.appendChild(xmlNode); 
var traverseNode = this.isTraverseNode(xmlNode);
lastParent.removeChild(xmlNode);
if (!traverseNode)
xmlNode = lastParent;
}
do {
if (action == "add" && this.isTraverseNode(xmlNode)
&& startNode == xmlNode)
break; 
if (xmlNode.getAttribute(jpf.xmldb.xmlIdTag)) {
var htmlNode = this.getNodeFromCache(
xmlNode.getAttribute(jpf.xmldb.xmlIdTag)
+ "|" + this.uniqueId);
if (htmlNode
&& (startNode != xmlNode || xmlNode == this.xmlRoot)
&& actionFeature[action] & 1)
action = "update";
if (xmlNode == listenNode) {
if (xmlNode == this.xmlRoot && action != "insert")
return;
break;
}
if (htmlNode && actionFeature[action] & 2
&& !this.isTraverseNode(xmlNode))
action = "remove"; 
if (!htmlNode && actionFeature[action] & 4
&& this.isTraverseNode(xmlNode)){
action = "add";
break;
}
if (htmlNode  || action == "move")
break;
}
else if (actionFeature[action] & 8 && this.isTraverseNode(xmlNode)){
action = "add";
break;
}
if (xmlNode == listenNode) break;
xmlNode = xmlNode.parentNode;
}
while(xmlNode && xmlNode.nodeType != 9);
var foundNode = xmlNode;
if (xmlNode && xmlNode.nodeType == 9)
xmlNode = startNode;
if (action == "replacechild"
&& (UndoObj ? UndoObj.args[0] == this.xmlRoot : !this.xmlRoot.parentNode)) {
return this.load(UndoObj ? UndoObj.args[1] : listenNode); 
}
if (UndoObj && xmlNode && !UndoObj.xmlNode)
UndoObj.xmlNode = xmlNode;
if (action == "move" && foundNode == startNode) {
var isInThis  = jpf.xmldb.isChildOf(this.xmlRoot, xmlNode.parentNode, true);
var wasInThis = jpf.xmldb.isChildOf(this.xmlRoot, UndoObj.extra.parent, true);
if (isInThis && wasInThis)
this.$moveNode(xmlNode, htmlNode);
else if (isInThis) 
action = "add";
else if (wasInThis) 
action = "remove";
}
else if (action == "move-away") {
var goesToThis = jpf.xmldb.isChildOf(this.xmlRoot, UndoObj.extra.parent, true);
if (!goesToThis)
action = "remove";
}
if (this.$removeClearMessage && this.$setClearMessage) {
if (this.getFirstTraverseNode())
this.$removeClearMessage();
else
this.$setClearMessage(this.emptyMsg, "empty")
}
if (action == "insert" && (this.isTreeArch || xmlNode == this.xmlRoot)) {
if (this.hasLoadStatus(xmlNode) && this.$removeLoading)
this.$removeLoading(htmlNode);
if (this.oInt.firstChild && !jpf.xmldb.getNode(this.oInt.firstChild)) {
this.oInt.innerHTML = "";
if (!this.renderRoot) {
length = this.getTraverseNodes().length;
if (!length)
this.clearAllTraverse();
}
}
result = this.$addNodes(xmlNode, (this.$getParentNode
? this.$getParentNode(htmlNode)
: htmlNode), true, false);
this.$fill(result);
if (this.selectable && (length === 0 || !this.xmlRoot.selectSingleNode(this.traverse)))
return;
}
else if (action == "add") {
var parentHTMLNode = xmlNode.parentNode == this.xmlRoot
? this.oInt
: this.getNodeFromCache(xmlNode.parentNode.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId); 
if (!parentHTMLNode)
parentHTMLNode = this.getCacheItem(xmlNode.parentNode.getAttribute(jpf.xmldb.xmlIdTag)
|| (xmlNode.parentNode.getAttribute(jpf.xmldb.xmlDocTag)
? "doc" + xmlNode.parentNode.getAttribute(jpf.xmldb.xmlDocTag)
: false))
|| this.oInt; 
if (parentHTMLNode || jpf.xmldb.isChildOf(this.xmlRoot, xmlNode)) {
parentHTMLNode = (this.$findContainer && parentHTMLNode
? this.$findContainer(parentHTMLNode)
: parentHTMLNode) || this.oInt;
result = this.$addNodes(xmlNode, parentHTMLNode, true, true,
this.getNodeByXml(this.getNextTraverse(xmlNode)));
if (parentHTMLNode)
this.$fill(result);
}
}
else if ((action == "remove") && (!xmlNode || foundNode == xmlNode && xmlNode.parentNode)) { 
if (!xmlNode)
return;
if (htmlNode)
this.$deInitNode(xmlNode, htmlNode);
else if (xmlNode == this.xmlRoot) {
return this.load(null, null, null,
!this.dataParent || !this.dataParent.autoselect);
}
}
else if (htmlNode) {
this.$updateNode(xmlNode, htmlNode);
if (action == "replacechild" && this.hasFeature(__MULTISELECT__)
&& this.selected && xmlNode.getAttribute(jpf.xmldb.xmlIdTag)
== this.selected.getAttribute(jpf.xmldb.xmlIdTag)) {
this.selected = xmlNode;
}
}
else if (action == "redo-remove") { 
var testNode = this.xmlRoot;
while (testNode && testNode.nodeType != 9)
testNode = testNode.parentNode;
if (!testNode) {
var model = this.getModel(true);
return model.loadInJmlNode(this, model.getXpathByJmlNode(this));
}
}
var pNode = xmlNode ? xmlNode.parentNode : lastParent;
if (this.isTreeArch && pNode && pNode.nodeType == 1) {
do {
var htmlNode = this.getNodeFromCache(pNode.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId);
if (htmlNode)
this.$updateNode(pNode, htmlNode);
}
while ((pNode = this.getTraverseParent(pNode)) && pNode.nodeType == 1);
}
if (actionFeature[action] & 32 && this.selectable
&& startNode == xmlNode
&& (action != "insert" || xmlNode == this.xmlRoot)) {
clearTimeout(selectTimer.timer);
if (action == "remove" && xmlNode == this.selected
|| xmlNode == selectTimer.nextNode)
selectTimer.nextNode = this.getDefaultNext(xmlNode);
selectTimer.timer = setTimeout(function(){
_self.$checkSelection(selectTimer.nextNode);
selectTimer.nextNode = null;
});
}
if (actionFeature[action] & 64) {
if (!length)
length = this.xmlRoot.selectNodes(this.traverse).length;
if (length != this.length)
this.setProperty("length", length);
}
if (this.signalXmlUpdate && actionFeature[action] & 16) {
var uniqueId;
for (uniqueId in this.signalXmlUpdate) {
if (parseInt(uniqueId) != uniqueId) continue; 
var o = jpf.lookup(uniqueId);
if (!this.selected) continue;
var xmlNode = this.selected.selectSingleNode(o.dataParent.xpath);
if (!xmlNode) continue;
o.load(xmlNode);
}
}
this.dispatchEvent("xmlupdate", {
action : action,
xmlNode: xmlNode,
result : result
});
};
this.$addNodes = function(xmlNode, parent, checkChildren, isChild, insertBefore){
var htmlNode, lastNode;
isChild          = (isChild && (this.renderRoot && xmlNode == this.xmlRoot
|| this.isTraverseNode(xmlNode)));
var nodes        = isChild ? [xmlNode] : this.getTraverseNodes(xmlNode);
var loadChildren = nodes.length && (this.bindingRules || {})["insert"]
? this.applyRuleSetOnNode("insert", xmlNode)
: false;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1) continue;
if (checkChildren)
htmlNode = this.getNodeFromCache(nodes[i].getAttribute(jpf.xmldb.xmlIdTag)
+ "|" + this.uniqueId);
if (!htmlNode) {
var Lid = jpf.xmldb.nodeConnect(this.documentId, nodes[i], null, this);
var beforeNode = isChild ? insertBefore : (lastNode ? lastNode.nextSibling : null);
var parentNode = this.$add(nodes[i], Lid, isChild ? xmlNode.parentNode : xmlNode,
beforeNode ? parent || this.oInt : parent, beforeNode,
!beforeNode && i==nodes.length-1);
if (parentNode === false) {
for (var i = i; i < nodes.length; i++)
jpf.xmldb.nodeConnect(this.documentId, nodes[i],
null, this);
break;
}
}
if (checkChildren)
lastNode = htmlNode;
}
return nodes;
};
this.addEventListener("beforeselect", function(e){
var combinedvalue = null;
if (this.indicator == this.selected || e.list && e.list.length > 1
&& this.getConnections().length) {
if (e.list && e.list.length > 1 && this.getConnections().length) {
var oEl  = this.xmlRoot.ownerDocument.createElement(this.selected.tagName);
var attr = {};
var nodes = e.list[0].attributes;
for (var j = 0; j < nodes.length; j++)
attr[nodes[j].nodeName] = nodes[j].nodeValue;
for (var i = 1; i < e.list.length; i++) {
for (prop in attr) {
if (typeof attr[prop] != "string") continue;
if (!e.list[i].getAttributeNode(prop))
attr[prop] = undefined;
else if(e.list[i].getAttribute(prop) != attr[prop])
attr[prop] = "";
}
}
for (prop in attr) {
if (typeof attr[prop] != "string") continue;
oEl.setAttribute(prop, attr[prop]);
}
oEl.setAttribute(jpf.xmldb.xmlIdTag, this.uniqueId);
jpf.MultiSelectServer.register(oEl.getAttribute(jpf.xmldb.xmlIdTag),
oEl, e.list, this);
jpf.xmldb.addNodeListener(oEl, jpf.MultiSelectServer);
combinedvalue = oEl;
}
}
this.$chained = true;
if (!this.dataParent || !this.dataParent.parent.$chained) {
var _self = this;
setTimeout(function(){
_self.setConnections(combinedvalue || _self.selected);
delete _self.$chained;
}, 10);
}
else {
this.setConnections(combinedvalue || this.selected);
delete this.$chained;
}
});
this.addEventListener("afterdeselect", function(){
var _self = this;
setTimeout(function(){
_self.setConnections(null);
}, 10);
});
this.$loadInlineData = function(x){
if (!$xmlns(x, "item", jpf.ns.jml).length)
return jpf.JmlParser.parseChildren(x, null, this);
var parent = x;
var prefix = jpf.findPrefix(x, jpf.ns.jml);
x.ownerDocument.setProperty("SelectionNamespaces", "xmlns:"
+ prefix + "='" + jpf.ns.jpf + "'");
this.icon      = "@icon";
this.image     = "@image";
this.caption   = "label/text()|text()|@caption";
this.valuerule = "value/text()|@value|text()";
this.traverse  = prefix + ":item";
this.load(x);
};
var timer;
this.$handleBindingRule = function(value, f, prop){
if (!value)
this[prop] = null;
if (this.xmlRoot && !timer && !jpf.isParsing) {
timer = setTimeout(function(){
_self.reload();
timer = null;
});
}
};
this.$propHandlers["traverse"] =
this.$propHandlers["caption"]  =
this.$propHandlers["valuerule"]  =
this.$propHandlers["icon"]     =
this.$propHandlers["tooltip"]  =
this.$propHandlers["select"]   = this.$handleBindingRule;
};
var __VIRTUALVIEWPORT__ = 1 << 19;
var __PRESENTATION__ = 1 << 9;
jpf.skins = {
skins  : {},
css    : [],
events : ["onmousemove", "onmousedown", "onmouseup", "onmouseout",
"onclick", "ondragmove", "ondragstart"],
Init: function(xmlNode, refNode, path){
var name      = (refNode ? refNode.getAttribute("id") : null)
|| xmlNode.getAttribute("id");
var base      = (refNode ? refNode.getAttribute("src").match(/\//) || path : "")
? (path || refNode.getAttribute("src")).replace(/\/[^\/]*$/, "") + "/"
: "";
var mediaPath = (xmlNode.getAttribute("media-path")
? jpf.getAbsolutePath(base || jpf.hostPath, xmlNode.getAttribute("media-path"))
: (refNode ? refNode.getAttribute("media-path") : null));
var iconPath  = (xmlNode.getAttribute("icon-path")
? jpf.getAbsolutePath(base || jpf.hostPath, xmlNode.getAttribute("icon-path"))
: (refNode ? refNode.getAttribute("icon-path") : null));
if (!name)
name = "default";
if (xmlNode.getAttribute("id"))
document.body.className += " " + xmlNode.getAttribute("id");
if (!this.skins[name] || name == "default") {
this.skins[name] = {
base     : base,
name     : name,
iconPath : (iconPath === null)  ? "icons/" : iconPath,
mediaPath: (mediaPath === null) ? "images/" : mediaPath,
templates: {},
originals: {},
xml      : xmlNode
}
}
if (!this.skins["default"])
this.skins["default"] = this.skins[name];
var nodes = xmlNode.childNodes;
for (var i = nodes.length - 1; i >= 0; i--) {
if (nodes[i].nodeType != 1)
continue;
this.skins[name].templates[nodes[i].getAttribute("name")] = nodes[i];
if (nodes[i].ownerDocument)
this.importSkinDef(nodes[i], base, name);
}
this.purgeCss(mediaPath || base + "images/", iconPath || base + "icons/");
},
loadStylesheet: function(filename, title){
with (o = document.getElementsByTagName("head")[0].appendChild(document.createElement("LINK"))) {
rel   = "stylesheet";
type  = "text/css";
href  = filename;
title = title;
}
return o;
},
importSkinDef: function(xmlNode, basepath, name){
var i, l, nodes = $xmlns(xmlNode, "style", jpf.ns.jml), tnode, node;
for (i = 0, l = nodes.length; i < l; i++) {
node = nodes[i];
if (node.getAttribute("src"))
this.loadStylesheet(node.getAttribute("src").replace(/src/, basepath + "/src"));
else {
var test = true;
if (node.getAttribute("condition")) {
try {
test = eval(node.getAttribute("condition"));
}
catch (e) {
test = false;
}
}
if (test) {
tnode = node.firstChild;
while (tnode) {
this.css.push(tnode.nodeValue);
tnode = tnode.nextSibling;
}
}
}
}
nodes = $xmlns(xmlNode, "alias", jpf.ns.jpf);
for (i = 0; i < nodes.length; i++) {
if (!nodes[i].firstChild)
continue;
this.skins[name].templates[nodes[i].firstChild.nodeValue.toLowerCase()] = xmlNode;
}
},
loadedCss : "",
purgeCss: function(imagepath, iconpath){
if (!this.css.length)
return;
var cssString = this.css.join("\n").replace(/images\//g, imagepath).replace(/icons\//g, iconpath);
jpf.importCssString(document, cssString);
this.css = [];
},
loadCssInWindow : function(skinName, win, imagepath, iconpath){
this.css = [];
var name = skinName.split(":");
var skin = this.skins[name[0]];
var template = skin.templates[name[1]];
this.importSkinDef(template, skin.base, skin.name);
var cssString = this.css.join("\n").replace(/images\//g, imagepath).replace(/icons\//g, iconpath);
jpf.importCssString(win.document, cssString);
this.css = [];
},
setSkinPaths: function(skinName, jmlNode){
skinName = skinName.split(":");
var name = skinName[0];
var type = skinName[1];
jmlNode.iconPath  = this.skins[name].iconPath;
jmlNode.mediaPath = this.skins[name].mediaPath;
},
getTemplate: function(skinName, cJml){
skinName = skinName.split(":");
var name = skinName[0];
var type = skinName[1];
if (!this.skins[name].templates[type])
return false;
var skin      = this.skins[name].templates[type];
var originals = this.skins[name].originals[type];
if (!originals) {
originals = this.skins[name].originals[type] = {};
var nodes = $xmlns(skin, "presentation", jpf.ns.jml)[0].childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1) continue;
originals[nodes[i].baseName || nodes[i][jpf.TAGNAME]] = nodes[i];
}
}
return originals;
},
getCssString : function(skinName){
return jpf.getXmlValue($xmlns(this.skins[skinName.split(":")[0]].xml,
"style", jpf.ns.jml)[0], "text()");
},
changeSkinset : function(value){
var node = jpf.document.documentElement;
while (node) {
if (node && node.nodeFunc == jpf.NODE_VISIBLE
&& node.hasFeature(__PRESENTATION__) && !node.skinset) {
node.$propHandlers["skinset"].call(node, value);
node.skinset = null;
}
if (node.firstChild || node.nextSibling) {
node = node.firstChild || node.nextSibling;
}
else {
do {
node = node.parentNode;
} while (node && !node.nextSibling)
if (node)
node = node.nextSibling;
}
}
},
setIcon : function(oHtml, strQuery, iconPath){
if (!strQuery) {
oHtml.style.backgroundImage = "";
return;
}
if (oHtml.tagName.toLowerCase() == "img") {
oHtml.setAttribute("src", strQuery
? (iconPath || "") + strQuery
: "");
return;
}
{
oHtml.style.backgroundImage = "url(" + (iconPath || "")
+ strQuery + ")";
}
}
};
jpf.Presentation = function(){
var pNodes, originalNodes;
this.$regbase = this.$regbase | __PRESENTATION__;
this.skinName = null;
var _self     = this;
var skinTimer;
this.$supportedProperties.push("skin");
this.$propHandlers["skinset"] =
this.$propHandlers["skin"] = function(value){
if (!this.$jmlLoaded) 
return;
if (!skinTimer) {
clearTimeout(skinTimer);
skinTimer = setTimeout(function(){
changeSkin.call(_self);
skinTimer = null;
});
}
}
this.$propHandlers["style"] = function(value){
if (!jpf.isParsing)
this.oExt.setAttribute("style", value);
}
var oldClass;
this.$propHandlers["class"] = function(value){
this.$setStyleClass(this.oExt, value, [oldClass || ""])
}
this.$forceSkinChange = function(skin, skinset){
changeSkin.call(this, skin, skinset);
}
function changeSkin(skin, skinset){
clearTimeout(skinTimer);
var skinName = (skinset || this.skinset || jpf.appsettings.skinset)
+ ":" + (skin || this.skin || this.tagName);
if (this.selectable)
var valueList = this.getSelection();
var oExt = this.oExt;
var beforeNode = oExt.nextSibling;
var id         = this.oExt.getAttribute("id");
var oldBase    = this.baseCSSname;
if (oExt.parentNode)
oExt.parentNode.removeChild(oExt);
if (this.$destroy)
this.$destroy(true);
this.$loadSkin(skinName);
this.$draw();
if (id)
this.oExt.setAttribute("id", id);
if (beforeNode)
this.oExt.parentNode.insertBefore(this.oExt, beforeNode);
var i, l, newclasses = [],
classes    = (oExt.className || "").splitSafe("\s+");
for (i = 0; i < classes; i++) {
if (classes[i] && classes[i] != oldBase)
newclasses.push(classes[i].replace(oldBase, this.baseCSSname));
}
jpf.setStyleClass(this.oExt, newclasses.join(" "));
var en, ev = jpf.skins.events;
for (i = 0, l = ev.length; i < l; i++) {
en = ev[i];
if (typeof oExt[en] == "function" && !this.oExt[en])
this.oExt[en] = oExt[en];
}
this.oExt.style.left     = oExt.style.left;
this.oExt.style.top      = oExt.style.top;
this.oExt.style.width    = oExt.style.width;
this.oExt.style.height   = oExt.style.height;
this.oExt.style.right    = oExt.style.right;
this.oExt.style.bottom   = oExt.style.bottom;
this.oExt.style.zIndex   = oExt.style.zIndex;
this.oExt.style.position = oExt.style.position;
this.oExt.style.display  = oExt.style.display;
if (this.$loadJml)
this.$loadJml(this.$jml);
if (this.disabled)
this.$disable();
if (this.$focussable && jpf.window.focussed == this)
this.$focus();
if (this.hasFeature(__DATABINDING__) && this.xmlRoot)
this.reload();
else
if (this.value)
this.$propHandlers["value"].call(this, this.value);
if (this.hasFeature(__MULTISELECT__)) {
if (this.selectable)
this.selectList(valueList, true);
}
if (this.draggable)
this.$propHandlers["draggable"].call(this, this.draggable);
if (this.resizable)
this.$propHandlers["resizable"].call(this, this.resizable);
if (this.$skinchange)
this.$skinchange();
};
this.$setStyleClass = jpf.setStyleClass;
this.$loadSkin = function(skinName){
this.baseSkin = skinName || this.skinName || (this.skinset || this.$jml
&& this.$jml.getAttribute("skinset") || jpf.appsettings.skinset)
+ ":" + (this.skin || this.$jml
&& this.$jml.getAttribute("skin") || this.tagName);
if (this.skinName) {
this.$blur();
this.baseCSSname = null;
}
this.skinName = this.baseSkin; 
pNodes = {}; 
originalNodes = jpf.skins.getTemplate(this.skinName, this.$jml);
if (!originalNodes) {
this.baseName = this.skinName = "default:" + this.tagName;
originalNodes = jpf.skins.getTemplate(this.skinName, this.$jml);
if (!originalNodes) {
throw new Error(jpf.formatErrorString(1077, this,
"Presentation",
"Could not load skin: " + this.skinName, this.$jml));
}
}
if (originalNodes)
jpf.skins.setSkinPaths(this.skinName, this);
};
this.$getNewContext = function(type, jmlNode){
pNodes[type] = originalNodes[type].cloneNode(true);
};
this.$hasLayoutNode = function(type){
return originalNodes[type] ? true : false;
};
this.$getLayoutNode = function(type, section, htmlNode){
var node = pNodes[type] || originalNodes[type];
if (!node) {
return false;
}
if (!section)
return jpf.getFirstElement(node);
var textNode = node.selectSingleNode("@" + section);
if (!textNode) {
return null;
}
return (htmlNode
? jpf.xmldb.selectSingleNode(textNode.nodeValue, htmlNode)
: jpf.getFirstElement(node).selectSingleNode(textNode.nodeValue));
};
this.$getOption = function(type, section){
type = type.toLowerCase(); 
var node = pNodes[type] || originalNodes[type];
if (!section)
return node;
var option = node.selectSingleNode("@" + section);
return option ? option.nodeValue : "";
};
this.$getExternal = function(tag, pNode, func, jml){
if (!pNode)
pNode = this.pHtmlNode;
if (!tag)
tag = "main";
if (!jml)
jml = this.$jml;
tag = tag.toLowerCase(); 
this.$getNewContext(tag);
var oExt = this.$getLayoutNode(tag);
if (jml && jml.getAttributeNode("style"))
oExt.setAttribute("style", jml.getAttribute("style"));
if (jml && (jml.getAttributeNode("class") || jml.className)) {
this.$setStyleClass(oExt,
(oldClass = jml.getAttribute("class") || jml.className));
}
if (func)
func.call(this, oExt);
oExt = jpf.xmldb.htmlImport(oExt, pNode);
oExt.host = this;
if (jml && jml.getAttribute("bgimage"))
oExt.style.backgroundImage = "url(" + jpf.getAbsolutePath(
this.mediaPath, jml.getAttribute("bgimage")) + ")";
if (!this.baseCSSname)
this.baseCSSname = oExt.className.trim().split(" ")[0];
return oExt;
};
this.$focus = function(){
if (!this.oExt)
return;
this.$setStyleClass(this.oFocus || this.oExt, this.baseCSSname + "Focus");
};
this.$blur = function(){
if (this.renaming)
this.stopRename(null, true);
if (!this.oExt)
return;
this.$setStyleClass(this.oFocus || this.oExt, "", [this.baseCSSname + "Focus"]);
};
if (jpf.hasCssUpdateScrollbarBug) {
this.$fixScrollBug = function(){
if (this.oInt != this.oExt)
this.oFocus = this.oInt;
else {
this.oFocus =
this.oInt   =
this.oExt.appendChild(document.createElement("div"));
this.oInt.style.height = "100%";
}
};
}
if (this.hasFeature(__MULTISELECT__)) {
this.$select = function(o){
if (this.renaming)
this.stopRename(null, true);
if (!o || !o.style)
return;
return this.$setStyleClass(o, "selected");
};
this.$deselect = function(o){
if (this.renaming) {
this.stopRename(null, true);
if (this.ctrlselect)
return false;
}
if (!o)
return;
return this.$setStyleClass(o, "", ["selected", "indicate"]);
};
this.$indicate = function(o){
if (this.renaming)
this.stopRename(null, true);
if (!o)
return;
return this.$setStyleClass(o, "indicate");
};
this.$deindicate = function(o){
if (this.renaming)
this.stopRename(null, true);
if (!o)
return;
return this.$setStyleClass(o, "", ["indicate"]);
};
}
};
var __ALIGNMENT__ = 1 << 12;
var __VALIDATION__ = 1 << 6;
jpf.Validation = function(){
this.isActive = true;
this.$regbase = this.$regbase | __VALIDATION__;
this.isValid = function(checkRequired){
var value = this.getValue();
if (checkRequired && this.required) {
if (!value || value.toString().trim().length == 0) {
return false;
}
}
var isValid = (vRules.length
? eval("!value || (" + vRules.join(") && (") + ")")
: true);
return isValid;
};
this.showMe = function(){
var p = this.parentNode;
while (p) {
if (p.show)
p.show();
p = p.parentNode;
}
};
this.validate = function(ignoreReq, nosetError, force){
if (force || !this.isValid(!ignoreReq) && !nosetError) {
this.setError();
return false;
}
else {
this.clearError();
return true;
}
};
this.setError = function(value){
if (!this.$validgroup)
this.$propHandlers["validgroup"].call(this, "vg" + this.parentNode.uniqueId);
var errBox = this.$validgroup.getErrorBox(this);
if (!this.$validgroup.allowMultipleErrors)
this.$validgroup.hideAllErrors();
errBox.setMessage(this.invalidmsg);
jpf.setStyleClass(this.oExt, this.baseCSSname + "Error");
this.showMe(); 
if (this.$validgroup) {
var refHtml = 
this.oExt;
document.body.appendChild(errBox.oExt);
var pos = jpf.getAbsolutePosition(refHtml, document.body);
if (document != refHtml.ownerDocument) {
var pos2 = jpf.getAbsolutePosition(refHtml.ownerDocument.parentWindow.frameElement, document.body);
pos[0] += pos2[0];
pos[1] += pos2[1];
}
errBox.oExt.style.left = (pos[0] + parseFloat(this.$getOption("main", "erroffsetx") || 0)) + "px"; 
errBox.oExt.style.top  = (pos[1] + parseFloat(this.$getOption("main", "erroffsety") || 0)) + "px"; 
errBox.host = this;
}
errBox.show();
if (jpf.window.focussed && jpf.window.focussed != this)
this.focus(null, {mouse:true}); 
};
this.clearError = function(value){
if (this.$setStyleClass)
this.$setStyleClass(this.oExt, "", [this.baseCSSname + "Error"]);
if (this.$validgroup) {
var errBox = this.$validgroup.getErrorBox(null, true);
if (!errBox || errBox.host != this)
return;
errBox.hide();
}
};
this.$jmlDestroyers.push(function(){
if (this.$validgroup)
this.$validgroup.remove(this);
});
var vRules = ["true"];
var vIds   = {};
this.addValidationRule = function(rule){
vRules.push(rule);
};
this.$addJmlLoader(function(x){
if (!this.form) {
var y = this.$jml;
do {
y = y.parentNode;
}
while (y && y.tagName && !y.tagName.match(/submitform|xforms$/)
&& y.parentNode && y.parentNode.nodeType != 9);
if (y && y.tagName && y.tagName.match(/submitform|xforms$/)) {
this.form = eval(y.getAttribute("id"));
this.form.addInput(this);
}
}
if (!this.form && !x.getAttribute("validgroup")) {
var vgroup = jpf.xmldb.getInheritedAttribute(x, "validgroup");
if (vgroup)
this.$propHandlers["validgroup"].call(this, vgroup);
}
});
this.$booleanProperties["required"] = true;
this.$supportedProperties.push("validgroup", "required", "datatype",
"pattern", "min", "max", "maxlength", "minlength", "valid-test",
"notnull", "checkequal", "invalidmsg", "requiredmsg");
this.$fValidate = function(){ this.validate(true); };
this.$propHandlers["validgroup"] = function(value){
this.removeEventListener("blur", this.$fValidate);
if (value) {
this.addEventListener("blur", this.$fValidate);
var vgroup;
if (typeof value != "string") {
this.$validgroup = value.name;
vgroup = value;
}
else {
vgroup = jpf.nameserver.get("validgroup", value);
}
this.$validgroup = vgroup || new jpf.ValidationGroup(value);
this.$validgroup.add(this);
}
else {
this.$validgroup.remove(this);
this.$validgroup = null;
}
};
this.$setRule = function(type, rule){
var vId = vIds[type];
if (!rule) {
if (vId)
vRules[vId] = "";
return;
}
if (!vId)
vIds[type] = vRules.push(rule) - 1;
else
vRules[vId] = rule;
}
this.$propHandlers["pattern"] = function(value){
if (!value)
return this.$setRule("pattern");
if (value.match(/^\/.*\/(?:[gim]+)?$/))
this.reValidation = eval(value);
this.$setRule("pattern", this.reValidation
? "value.match(this.reValidation)" 
: "(" + value + ")"); 
};
this.$propHandlers["min"] = function(value){
this.$setRule("min", value
? "parseInt(value) >= " + value
: null);
};
this.$propHandlers["max"] = function(value){
this.$setRule("max", value
? "parseInt(value) <= " + value
: null);
};
this.$propHandlers["maxlength"] = function(value){
this.$setRule("maxlength", value
? "value.toString().length <= " + value
: null);
};
this.$propHandlers["minlength"] = function(value){
this.$setRule("minlength", value
? "value.toString().length >= " + value
: null);
};
this.$propHandlers["notnull"] = function(value){
this.$setRule("notnull", value
? "value.toString().length > 0"
: null);
};
this.$propHandlers["checkequal"] = function(value){
if (!this.required)
this.required = 2;
else if (!value && this.required == 2)
this.required = false;
this.$setRule("checkequal", value
? "!" + value + ".isValid() || " + value + ".getValue() == value"
: null);
};
this.$propHandlers["valid-test"] = function(value){
var _self = this, rvCache = {};
this.removeValidationCache = function(){
rvCache = {};
}
this.$checkRemoteValidation = function(){
var value = this.getValue();
if(typeof rvCache[value] == "boolean") return rvCache[value];
if(rvCache[value] == -1) return true;
rvCache[value] = -1;
var instr = this.$jml.getAttribute('valid-test').split("==");
jpf.getData(instr[0], this.xmlRoot, {
value : this.getValue() 
}, function(data, state, extra){
if (state != jpf.SUCCESS) {
if (state == jpf.TIMEOUT && extra.retries < jpf.maxHttpRetries)
return extra.tpModule.retry(extra.id);
else {
var commError = new Error(jpf.formatErrorString(0, _self, 
"Validating entry at remote source", 
"Communication error: \n\n" + extra.message));
if (_self.dispatchEvent("error", jpf.extend({
error : commError, 
state : status
}, extra)) !== false)
throw commError;
return;
}
}
rvCache[value] = instr[1] ? data == instr[1] : jpf.isTrue(data);
if(!rvCache[value]){
if (!_self.hasFocus())
_self.setError();
}
else _self.clearError();
});
return true;
}
this.$setRule("valid-test", value
? "this.$checkRemoteValidation()"
: null);
};
};
jpf.ValidationGroup = function(name){
jpf.makeClass(this);
this.validateVisibleOnly = false;
this.allowMultipleErrors = false;
this.childNodes = [];
this.add        = function(o){ this.childNodes.push(o); };
this.remove     = function(o){ this.childNodes.remove(o); };
if (name)
jpf.setReference(name, this);
this.name = name || "validgroup" + this.uniqueId;
jpf.nameserver.register("validgroup", this.name, this);
this.toString = function(){
return "[Javeline Validation Group]";
};
var errbox; 
this.getErrorBox = function(o, no_create){
if (this.allowMultipleErrors || !errbox && !no_create) {
errbox           = new jpf.errorbox(null, "errorbox");
errbox.pHtmlNode = o.oExt.parentNode;
var cNode        = o.$jml.ownerDocument.createElement("errorbox");
errbox.loadJml(cNode);
}
return errbox;
};
this.hideAllErrors = function(){
if (errbox && errbox.host)
errbox.host.clearError();
};
function checkValidChildren(oParent, ignoreReq, nosetError){
var found;
for (var v, i = 0; i < oParent.childNodes.length; i++) {
var oEl = oParent.childNodes[i];
if (!oEl)
continue;
if (!oEl.disabled
&& (!this.validateVisibleOnly && oEl.visible || !oEl.oExt || oEl.oExt.offsetHeight)
&& (oEl.hasFeature(__VALIDATION__) && oEl.isValid && !oEl.isValid(!ignoreReq))) {
if (!nosetError) {
if (!found) {
oEl.validate(true, null, true);
found = true;
if (!this.allowMultipleErrors)
return true; 
}
else if (oEl.errBox && oEl.errBox.host == oEl)
oEl.errBox.hide();
}
else if (!this.allowMultipleErrors)
return true;
}
if (oEl.canHaveChildren && oEl.childNodes.length) {
found = checkValidChildren.call(this, oEl, ignoreReq, nosetError) || found;
if (found && !this.allowMultipleErrors)
return true; 
}
}
return found;
}
this.validate =
this.isValid = function(ignoreReq, nosetError, page){
var found = checkValidChildren.call(this, page || this, ignoreReq,
nosetError);
if (page) {
if (page.validation && !eval(page.validation)) {
alert(page.invalidmsg);
found = true;
}
}
if (!found)
found = this.dispatchEvent("validation");
return !found;
};
};
var __CACHE__ = 1 << 2;
jpf.Cache = function(){
var cache     = {};
var subTreeCacheContext;
this.caching  = true;
this.$regbase = this.$regbase | __CACHE__;
this.getCache = function(id, xmlNode){
if (id == this.cacheID) return -1;
if (xmlNode && this.hasFeature(__MULTISELECT__)) {
var cacheItem = this.getCacheItemByHtmlId(
xmlNode.getAttribute(jpf.xmldb.xmlIdTag) + "|" + this.uniqueId);
if (cacheItem && !cache[id]) {
this.clear(true);
var oHtml = this.getNodeFromCache(
xmlNode.getAttribute(jpf.xmldb.xmlIdTag) + "|" + this.uniqueId);
subTreeCacheContext = {
oHtml      : oHtml,
parentNode : oHtml.parentNode,
beforeNode : oHtml.nextSibling,
cacheItem  : cacheItem
};
this.documentId = jpf.xmldb.getXmlDocId(xmlNode);
this.cacheID    = id;
this.xmlRoot    = xmlNode;
if (this.renderRoot)
this.oInt.appendChild(oHtml);
else {
while (oHtml.childNodes.length)
this.oInt.appendChild(oHtml.childNodes[0]);
}
return true;
}
}
if (!cache[id]) return false;
if (this.cacheID)
this.clear(true);
var fragment    = cache[id];
this.documentId = fragment.documentId;
this.cacheID    = id;
this.xmlRoot    = fragment.xmlRoot;
this.clearCacheItem(id);
this.$setCurrentFragment(fragment);
return true;
};
this.setCache = function(id, fragment){
if (!this.caching) return;
cache[id] = fragment;
};
this.getNodeFromCache = function(id){
var node = this.$findNode(null, id);
if (node) return node;
for (var prop in cache) {
if (cache[prop] && cache[prop].nodeType) {
node = this.$findNode(cache[prop], id);
if (node) return node;
}
}
return null;
};
this.$findNode = function(cacheNode, id){
if (!cacheNode)
return this.pHtmlDoc.getElementById(id);
return cacheNode.getElementById(id);
};
this.getNodeByXml = function(xmlNode){
return xmlNode
? (this.getNodeFromCache((typeof xmlNode == "object"
? xmlNode.getAttribute(jpf.xmldb.xmlIdTag)
: xmlNode) + "|" + this.uniqueId))
: null;
};
this.getCacheItemByHtmlId = function(id){
var node = this.$findNode(null, id);
if (node) return this.oInt;
for (var prop in cache) {
if (cache[prop] && cache[prop].nodeType) {
node = this.$findNode(cache[prop], id);
if (node) return cache[prop];
}
}
return null;
};
this.clear = function(nomsg, doEvent){
if (this.clearSelection)
this.clearSelection(null, !doEvent);
if (this.caching) {
if (this.hasFeature(__MULTISELECT__)
&& subTreeCacheContext && subTreeCacheContext.oHtml) {
if (this.renderRoot)
subTreeCacheContext.parentNode.insertBefore(subTreeCacheContext.oHtml, subTreeCacheContext.beforeNode);
else {
while (this.oInt.childNodes.length)
subTreeCacheContext.oHtml.appendChild(this.oInt.childNodes[0]);
}
this.documentId = this.xmlRoot = this.cacheID = subTreeCacheContext = null;
}
else{
if (this.loadedWhenOffline) {
this.loadedWhenOffline = false;
}
else {
var fragment = this.$getCurrentFragment();
if (!fragment) return;
fragment.documentId = this.documentId;
fragment.xmlRoot    = this.xmlRoot;
}
}
}
else if (this.$clear)
this.$clear();
else
this.oInt.innerHTML = "";
if (typeof nomsg == "string") {
var msgType = nomsg;
nomsg = false;
}
if (!nomsg)
this.$setClearMessage(msgType ? this[msgType + "Msg"] : this.emptyMsg, msgType || "empty");
else if(this.$removeClearMessage)
this.$removeClearMessage();
if (this.caching && (this.cacheID || this.xmlRoot))
this.setCache(this.cacheID || this.xmlRoot.getAttribute(jpf.xmldb.xmlIdTag) || "doc"
+ this.xmlRoot.getAttribute(jpf.xmldb.xmlDocTag), fragment);
this.documentId = this.xmlRoot = this.cacheID = null;
if (!nomsg && this.hasFeature(__MULTISELECT__)) 
this.setProperty("length", 0);
};
this.clearAllTraverse = function(msg, className){
if (this.clearSelection)
this.clearSelection(null, true);
this.oInt.innerHTML = "";
this.$setClearMessage(msg || this.emptyMsg, className || "empty");
this.setConnections();
this.setProperty("length", 0);
};
this.clearCacheItem = function(id, remove){
cache[id].documentId = cache[id].cacheID = cache[id].xmlRoot = null;
if (remove)
jpf.removeNode(cache[id]);
cache[id] = null;
};
this.clearAllCache = function(){
for (var prop in cache) {
if (cache[prop])
this.clearCacheItem(prop, true);
}
};
this.getCacheItem = function(id){
return cache[id];
};
this.isCached = function(id){
return cache[id] || this.cacheID == id ? true : false;
}
this.$booleanProperties["caching"] = true;
this.$supportedProperties.push("caching");
if (this.hasFeature(__MULTISELECT__))
this.inherit(jpf.MultiselectCache);
this.$jmlDestroyers.push(function(){
this.clearAllCache();
});
};
jpf.MultiselectCache = function(){
this.$getCurrentFragment = function(){
var fragment = this.oInt.ownerDocument.createDocumentFragment();
while (this.oInt.childNodes.length) {
fragment.appendChild(this.oInt.childNodes[0]);
}
return fragment;
};
this.$setCurrentFragment = function(fragment){
this.oInt.appendChild(fragment);
if (!jpf.window.hasFocus(this))
this.blur();
};
this.$findNode = function(cacheNode, id){
if (!cacheNode)
return this.pHtmlDoc.getElementById(id);
return cacheNode.getElementById(id);
};
var oEmpty;
this.$setClearMessage = function(msg, className){
if (!oEmpty) {
this.$getNewContext("empty");
var xmlEmpty = this.$getLayoutNode("empty");
if (!xmlEmpty) return;
oEmpty = jpf.xmldb.htmlImport(xmlEmpty, this.oInt);
}
else {
this.oInt.appendChild(oEmpty);
}
var empty = this.$getLayoutNode("empty", "caption", oEmpty);
if (empty)
jpf.xmldb.setNodeValue(empty, msg || "");
oEmpty.setAttribute("id", "empty" + this.uniqueId);
jpf.setStyleClass(oEmpty, className, ["loading", "empty", "offline"]);
};
this.$updateClearMessage = function(msg, className) {
if (!oEmpty || oEmpty.parentNode != this.oInt
|| oEmpty.className.indexOf(className) == -1)
return;
var empty = this.$getLayoutNode("empty", "caption", oEmpty);
if (empty)
jpf.xmldb.setNodeValue(empty, msg || "");
}
this.$removeClearMessage = function(){
if (!oEmpty)
oEmpty = document.getElementById("empty" + this.uniqueId);
if (oEmpty && oEmpty.parentNode)
oEmpty.parentNode.removeChild(oEmpty);
};
};
var __JMLNODE__    = 1 << 15;
var __VALIDATION__ = 1 << 6;
jpf.JmlElement = function(){
this.$regbase = this.$regbase | __JMLNODE__;
var _self     = this;
if (this.nodeFunc == jpf.NODE_VISIBLE) {
this.setWidth = function(value){
this.setProperty("width", value);
};
this.setHeight = function(value){
this.setProperty("height", value);
};
this.setLeft   = function(value){
this.setProperty("left", value);
};
this.setTop    = function(value){
this.setProperty("top", value);
};
this.$noAlignUpdate = false;
if (!this.show)
this.show = function(s){
this.$noAlignUpdate = s;
this.setProperty("visible", true);
this.$noAlignUpdate = false;
};
if (!this.hide)
this.hide = function(s){
this.$noAlignUpdate = s;
this.setProperty("visible", false);
this.$noAlignUpdate = false;
};
this.getWidth  = function(){
return (this.oExt || {}).offsetWidth;
};
this.getHeight = function(){
return (this.oExt || {}).offsetHeight;
};
this.getLeft   = function(){
return (this.oExt || {}).offsetLeft;
};
this.getTop    = function(){
return (this.oExt || {}).offsetTop;
};
this.enable  = function(){
this.setProperty("disabled", false);
};
this.disable = function(){
this.setProperty("disabled", true);
};
this.sendToBack    =
this.sentToBack    = function(){
this.setProperty("zindex", 0);
};
this.bringToFront  = function(){
this.setProperty("zindex", jpf.all.length + 1);
};
this.sendBackwards =
this.sentBackwards = function(){
this.setProperty("zindex", this.zindex - 1);
};
this.bringForward  = function(){
this.setProperty("zindex", this.zindex + 1);
};
if (this.$focussable) {
this.setTabIndex = function(tabindex){
jpf.window.$removeFocus(this);
jpf.window.$addFocus(this, tabindex);
};
this.focus = function(noset, e, nofix){
if (!noset) {
if (this.isWindowContainer) {
jpf.window.$focusLast(this, e, true);
}
else {
jpf.window.$focus(this, e);
if (!nofix && jpf.hasFocusBug)
jpf.window.$focusfix();
}
return;
}
if (this.$focus)
this.$focus(e);
this.dispatchEvent("focus", {
srcElement : this,
bubbles    : true
});
};
this.blur = function(noset, e){
if (jpf.popup.isShowing(this.uniqueId))
jpf.popup.forceHide(); 
if (this.$blur)
this.$blur(e);
if (!noset)
jpf.window.$blur(this);
this.dispatchEvent("blur", {
srcElement : this,
bubbles    : !e || !e.cancelBubble
});
};
this.hasFocus = function(){
return jpf.window.focussed == this || this.isWindowContainer
&& (jpf.window.focussed || {}).$focusParent == this;
};
}
}
if (!this.hasFeature(__WITH_JMLDOM__))
this.inherit(jpf.JmlDom); 
this.loadJml = function(x, pJmlNode, ignoreBindclass, id){
this.name = x.getAttribute("id");
if (this.name)
jpf.setReference(this.name, this);
if (!x)
x = this.$jml;
if (this.parentNode || pJmlNode)
this.$setParent(this.parentNode || pJmlNode);
this.$jml = x;
if (this.nodeFunc != jpf.NODE_HIDDEN) {
this.inherit(jpf.MultiLang); 
if (this.$loadSkin)
this.$loadSkin();
if (this.$draw)
this.$draw();
if (id)
this.oExt.setAttribute("id", id);
var pTagName = x.parentNode && x.parentNode[jpf.TAGNAME] || "";
if (this.$positioning != "basic") {
this.inherit(jpf.Anchoring); 
this.enableAnchoring();
}
if (this.visible === undefined && !x.getAttribute("visible"))
this.visible = true;
this.$drawn = true;
}
else if (this.$draw)
this.$draw();
if (!ignoreBindclass) { 
if (!this.hasFeature(__DATABINDING__) && x.getAttribute("smartbinding")) {
this.inherit(jpf.DataBinding);
this.$xmlUpdate = this.$load = function(){};
}
}
this.$noAlignUpdate = true;
var value, name, type, l, a, i, attr = x.attributes;
for (i = 0, l = attr.length; i < l; i++) {
a     = attr[i];
value = a.nodeValue;
name  = a.nodeName;
if (value && jpf.dynPropMatch.test(value)) {
jpf.JmlParser.stateStack.push({
node  : this,
name  : name,
value : value
});
} else
{
if (name == "disabled") {
jpf.JmlParser.stateStack.push({
node  : this,
name  : name,
value : value
});
}
if (a.nodeName.indexOf("on") === 0) {
this.addEventListener(name, new Function('event', value));
continue;
}
if (!value)
value = this.defaults && this.defaults[name] || value;
if (this.$booleanProperties[name])
value = jpf.isTrue(value);
this[name] = value;
(this.$propHandlers && this.$propHandlers[name]
|| jpf.JmlElement.propHandlers[name] || jpf.K).call(this, value)
}
}
this.$noAlignUpdate = false;
if (this.$focussable && this.focussable === undefined)
jpf.JmlElement.propHandlers.focussable.call(this);
if (this.$loadJml && !this.$isSelfLoading)
this.$loadJml(x);
for (i = this.$jmlLoaders.length - 1; i >= 0; i--)
this.$jmlLoaders[i].call(this, x);
this.$jmlLoaded = true;
return this;
};
this.$handlePropSet = function(prop, value, force){
if (!force && !this.hasFeature(__MULTISELECT__) && this.xmlRoot && this.bindingRules
&& this.bindingRules[prop] && !this.ruleTraverse) {
return jpf.xmldb.setNodeValue(this.getNodeFromRule(
prop.toLowerCase(), this.xmlRoot, null, null, true),
value, !this.$onlySetXml);
}
if (this.$booleanProperties[prop])
value = jpf.isTrue(value);
this[prop] = value;
if(this.$onlySetXml)
return;
return (this.$propHandlers && this.$propHandlers[prop]
|| jpf.JmlElement.propHandlers[prop]
|| jpf.K).call(this, value, force, prop);
};
this.replaceJml = function(jmlDefNode, oInt, oIntJML, isHidden){
for (var i = 0; i < this.childNodes.length; i++) {
var oItem = this.childNodes[i];
var nodes = oItem.childNodes;
for (var k = 0; k < nodes.length; k++)
if (nodes[k].destroy)
nodes[k].destroy();
if (oItem.$jml && oItem.$jml.parentNode)
oItem.$jml.parentNode.removeChild(oItem.$jml);
oItem.destroy();
if (oItem.oExt != this.oInt)
jpf.removeNode(oItem.oExt);
}
this.childNodes.length = 0;
this.oExt.innerHTML = "";
this.insertJml(jmlDefNode, oInt, oIntJML, isHidden);
};
this.insertJml = function(jmlDefNode, oInt, oIntJml, isHidden){
var callback = function(data, state, extra){
if (state != jpf.SUCCESS) {
var oError;
if (extra.tpModule.retryTimeout(extra, state, _self, oError) === true)
return true;
throw oError;
}
var jml = oIntJml || _self.$jml;
if (jml.insertAdjacentHTML)
jml.insertAdjacentHTML(jml.getAttribute("insert") || "beforeend",
(typeof data != "string" && data.length) ? data[0] : data);
else {
if (typeof data == "string")
data = jpf.xmldb.getXml("<j:jml xmlns:j='"
+ jpf.ns.jml +"'>" + data + "</j:jml>");
for (var i = data.childNodes.length - 1; i >= 0; i--)
jml.insertBefore(data.childNodes[i], jml.firstChild);
}
jpf.JmlParser.parseMoreJml(jml, oInt || _self.oInt, _self,
(isHidden && (oInt || _self.oInt).style.offsetHeight)
? true : false);
}
if (typeof jmlDefNode == "string") {
if (jpf.datainstr[jmlDefNode]){
return jpf.getData(jmlDefNode, null, {
ignoreOffline : true
}, callback);
}
else
jmlDefNode = jpf.xmldb.getXml(jmlDefNode);
}
return callback(jmlDefNode, jpf.SUCCESS);
};
if (
this.hasFeature(__DATABINDING__) &&
!this.hasFeature(__MULTISELECT__) && !this.change) {
this.change = function(value){
if (this.errBox && this.errBox.visible && this.isValid())
this.clearError();
if ((!this.createModel || !this.$jml.getAttribute("ref")) && !this.xmlRoot) {
if (value === this.value 
|| this.dispatchEvent("beforechange", {value : value}) === false)
return;
this.setProperty("value", value);
return this.dispatchEvent("afterchange", {value : value});
}
if (this.value === value)
return false;
this.executeActionByRuleSet("change", this.mainBind, this.xmlRoot, value);
};
}
if (this.setValue && !this.clear) {
this.clear = function(nomsg){
if (this.$setClearMessage) {
if (!nomsg)
this.$setClearMessage(this.emptyMsg, "empty");
else if (this.$removeClearMessage)
this.$removeClearMessage();
}
this.value = -99999; 
this.$propHandlers && this.$propHandlers["value"]
? this.$propHandlers["value"].call(this, "")
: this.setValue("");
};
}
};
jpf.JmlElement.propHandlers = {
"id": function(value){
if (this.name == value)
return;
if (self[this.name] == this)
self[this.name] = null;
jpf.setReference(value, this);
this.name = value;
},
"focussable": function(value){
if (typeof value == "undefined")
this.focussable = true;
if (this.focussable) {
jpf.window.$addFocus(this, this.tabindex
|| this.$jml.getAttribute("tabindex"));
}
else {
jpf.window.$removeFocus(this);
}
},
"zindex": function(value){
this.oExt.style.zIndex = value;
},
"visible": function(value){
if (this.tagName == "modalwindow") 
return; 
if (jpf.isFalse(value) || typeof value == "undefined") {
this.oExt.style.display = "none";
if (this.$hide && !this.$noAlignUpdate)
this.$hide();
if (jpf.window.focussed == this
|| this.canHaveChildren
&& jpf.xmldb.isChildOf(this, jpf.window.focussed, false)) {
if (jpf.appsettings.allowBlur)
this.blur();
else
jpf.window.moveNext();
}
}
else if (jpf.isTrue(value)) {
this.oExt.style.display = "block"; 
if (this.$show && !this.$noAlignUpdate)
this.$show();
if (jpf.hasSingleRszEvent)
jpf.layout.forceResize();
}
},
"disabled": function(value){
if (this.canHaveChildren) {
function loopChildren(nodes){
for (var node, i = 0, l = nodes.length; i < l; i++) {
node = nodes[i];
if (node.nodeFunc == jpf.NODE_VISIBLE)
node.setProperty("disabled", value);
if (node.childNodes.length)
loopChildren(node.childNodes);
}
}
loopChildren(this.childNodes);
return;
}
if (value) {
this.disabled = false;
if (jpf.window.focussed == this) {
jpf.window.moveNext(true); 
if (jpf.window.focussed == this)
this.$blur();
}
if (this.hasFeature(__PRESENTATION__))
this.$setStyleClass(this.oExt, this.baseCSSname + "Disabled");
if (this.$disable)
this.$disable();
this.disabled = true;
}
else {
if (this.hasFeature(__DATABINDING__) && jpf.appsettings.autoDisable
& !this.isBoundComplete())
return false;
this.disabled = false;
if (jpf.window.focussed == this)
this.$focus();
if (this.hasFeature(__PRESENTATION__))
this.$setStyleClass(this.oExt, null, [this.baseCSSname + "Disabled"]);
if (this.$enable)
this.$enable();
}
},
"enabled" : function(value){
this.setProperty("disabled", !value);
},
"disable-keyboard": function(value){
this.disableKeyboard = jpf.isTrue(value);
},
"left": function(value){
this.oExt.style.position = "absolute";
this.oExt.style.left = value + "px";
},
"top": function(value){
this.oExt.style.position = "absolute";
this.oExt.style.top = value + "px";
},
"right": function(value){
this.oExt.style.position = "absolute";
this.oExt.style.right = value + "px";
},
"bottom": function(value){
this.oExt.style.position = "absolute";
this.oExt.style.bottom = value + "px";
},
"width": function(value){
this.oExt.style.width = Math.max(0, value
- jpf.getWidthDiff(this.oExt)) + "px";
},
"height": function(value){
this.oExt.style.height = Math.max(0,
value - jpf.getHeightDiff(this.oExt)) + "px";
},
"contextmenu": function(value){
this.contextmenus = [value];
},
"resizable": function(value){
this.inherit(jpf.Interactive);
this.$propHandlers["resizable"].apply(this, arguments);
},
"draggable": function(value){
this.inherit(jpf.Interactive);
this.$propHandlers["draggable"].apply(this, arguments);
},
"actiontracker": function(value){
if (!value)
this.$at = null;
else if (value.tagName == "actiontracker")
this.$at = value;
else {
this.$at = typeof value == "string" && self[value]
? jpf.JmlParser.getActionTracker(value)
: jpf.setReference(value,
jpf.nameserver.register("actiontracker",
value, new jpf.actiontracker()));
}
},
"jml": function(value){
this.insertJml(value);
this.$isSelfLoading = true;
},
"alias" : function(value){
if (!value) 
return;
var cg = jpf.nameserver.get("alias", value);
if (!cg) {
cg = jpf.nameserver.register("alias", value, {
name  : value,
props : {},
$handlePropSet : function(prop, value, forceOnMe){
if (prop == "alias") return;
this.props[prop] = value;
this[prop] = value;
if (!forceOnMe)
this.active.setProperty(prop, value);
},
$propchange : function(e){
cg.setProperty(e.name, e.value, null, true);
},
data : [],
connect : function(o, dataOnly, xpath, type, noselect){
this.data.push([o, dataOnly, xpath, type, noselect]);
if (this.active)
this.active.connect(o, dataOnly, xpath, type, noselect);
},
disconnect : function(o, type){
for (var data, i = 0, l = this.data.length; i < l; i++) {
if (this.data[i][0] == o && this.data[i][3] == type)
this.data.removeIndex(i);
}
if (this.active)
this.active.disconnect(o, type);
},
set : function(jmlNode){
if (this.active == jmlNode)
return;
if (this.active) {
for (var name in events) {
var ev = events[name];
for (var i = 0; i < ev.length; i++) {
this.active.removeEventListener(name, ev[i]);
}
}
for (var name in events_capture) {
var ev = events_capture[name];
for (var i = 0; i < ev.length; i++) {
this.active.removeEventListener(name, ev[i], true);
}
}
this.active.removeEventListener("propertychange", this.$propchange);
for (var i = 0, l = this.data.length; i < l; i++)
this.active.disconnect(this.data[i][0], this.data[i][3]);
this.active.setProperty("alias", false);
}
this.active = jmlNode;
for (var name in events) {
var ev = events[name];
for (var i = 0; i < ev.length; i++) {
this.active.addEventListener(name, ev[i]);
}
}
for (var name in events_capture) {
var ev = events_capture[name];
for (var i = 0; i < ev.length; i++) {
this.active.addEventListener(name, ev[i], true);
}
}
for (var prop in this.props)
this.setProperty(prop, this.active[prop]);
this.active.addEventListener("propertychange", this.$propchange);
for (var i = 0, l = this.data.length; i < l; i++)
this.active.connect.apply(this.active, this.data[i]);
jmlNode.$alias = this;
}
});
jpf.makeClass(cg);
jpf.setReference(value, cg);
var events = {}, events_capture = {};
cg.addEventListener = function(eventName, callback, useCapture){
var ev = useCapture ? events_capture : events;
(ev[eventName] || (ev[eventName] = [])).pushUnique(callback);
this.active.addEventListener(eventName, callback, useCapture);
}
cg.removeEventListener = function(eventName, callback, useCapture){
var ev = useCapture ? events_capture : events;
(ev[eventName] || (ev[eventName] = [])).remove(callback);
this.active.addEventListener(eventName, callback, useCapture);
}
cg.dispatchEvent = function(eventName, options){
this.active.dispatchEvent(eventName, options);
}
}
cg.set(this);
}
};
var __WITH_JMLDOM__ = 1 << 14;
jpf.JmlDom = function(tagName, parentNode, nodeFunc, jml, content){
this.nodeType      = jpf.NODE_ELEMENT;
this.$regbase      = this.$regbase | __WITH_JMLDOM__;
this.childNodes    = [];
var _self          = this;
if (!this.$domHandlers)
this.$domHandlers = {"remove" : [], "insert" : [],
"reparent" : [], "removechild" : []};
if (jpf.document)
this.ownerDocument = jpf.document;
if (tagName) {
if (typeof tagName == "number") {
if (tagName == jpf.NODE_DOCUMENT_FRAGMENT) {
this.nodeType = jpf.NODE_DOCUMENT_FRAGMENT;
this.hasFeature = function(){
return false;
}
}
}
else {
this.parentNode = parentNode;
this.$jml        = jml;
this.nodeFunc   = nodeFunc;
this.tagName    = tagName;
this.name       = jml && jml.getAttribute("id");
this.content    = content;
}
}
this.appendChild =
this.insertBefore = function(jmlNode, beforeNode){
if (jmlNode.nodeType == jpf.NODE_DOCUMENT_FRAGMENT) {
var nodes = jmlNode.childNodes.slice(0);
for (var i = 0, l = nodes.length; i < l; i++) {
this.insertBefore(nodes[i], beforeNode);
}
return;
}
var isMoveWithinParent = jmlNode.parentNode == this;
var oldParentHtmlNode  = jmlNode.pHtmlNode;
if (jmlNode.parentNode)
jmlNode.removeNode(isMoveWithinParent);
jmlNode.parentNode = this;
var index;
if (beforeNode) {
index = this.childNodes.indexOf(beforeNode);
if (index < 0) {
return false;
}
jmlNode.nextSibling = beforeNode;
jmlNode.previousSibling = beforeNode.previousSibling;
beforeNode.previousSibling = jmlNode;
if (jmlNode.previousSibling)
jmlNode.previousSibling.nextSibling = jmlNode;
}
if (index)
this.childNodes = this.childNodes.slice(0, index).concat(jmlNode,
this.childNodes.slice(index));
else {
index = this.childNodes.push(jmlNode) - 1;
jmlNode.nextSibling = null;
if (index > 0) {
jmlNode.previousSibling = this.childNodes[index - 1];
jmlNode.previousSibling.nextSibling = jmlNode;
}
else
jmlNode.previousSibling = null;
}
this.firstChild = this.childNodes[0];
this.lastChild  = this.childNodes[this.childNodes.length - 1];
function triggerUpdate(){
jmlNode.pHtmlNode = _self.canHaveChildren
? _self.oInt
: document.body;
var i, callbacks = jmlNode.$domHandlers["reparent"];
for (i = 0, l = callbacks.length; i < l; i++) {
if (callbacks[i])
callbacks[i].call(jmlNode, beforeNode,
_self, isMoveWithinParent, oldParentHtmlNode);
}
callbacks = _self.$domHandlers["insert"];
for (i = 0, l = callbacks.length; i < l; i++) {
if (callbacks[i])
callbacks[i].call(_self, jmlNode,
beforeNode, isMoveWithinParent);
}
var containsIframe = jmlNode.oExt.getElementsByTagName("iframe").length > 0;
if (jmlNode.oExt && !jpf.isGecko && !containsIframe) {
jmlNode.pHtmlNode.insertBefore(jmlNode.oExt,
beforeNode && beforeNode.oExt || null);
}
}
if (!this.$jmlLoaded) {
jmlNode.$reappendToParent = triggerUpdate;
return;
}
triggerUpdate();
};
this.removeNode = function(doOnlyAdmin){
if (!this.parentNode || !this.parentNode.childNodes)
return;
this.parentNode.childNodes.remove(this);
if (this.$jmlLoaded && !jpf.isDestroying) {
if (this.oExt && this.oExt.parentNode)
this.oExt.parentNode.removeChild(this.oExt);
var i, l, callbacks = this.$domHandlers["remove"];
if (callbacks) {
for (i = 0, l = callbacks.length; i < l; i++) {
callbacks[i].call(this, doOnlyAdmin);
}
}
callbacks = (this.parentNode.$domHandlers || {})["removechild"];
if (callbacks) {
for (i = 0, l = callbacks.length; i < l; i++) {
callbacks[i].call(this.parentNode, this, doOnlyAdmin);
}
}
}
if (this.parentNode.firstChild == this)
this.parentNode.firstChild = this.nextSibling;
if (this.parentNode.lastChild == this)
this.parentNode.lastChild = this.previousSibling;
if (this.nextSibling)
this.nextSibling.previousSibling = this.previousSibling;
if (this.previousSibling)
this.previousSibling.nextSibling = this.nextSibling;
this.pHtmlNode       =
this.parentNode      =
this.previousSibling =
this.nextSibling     = null;
return this;
};
this.removeChild = function(childNode) {
childNode.removeNode();
};
this.getElementsByTagName = function(tagName, norecur){
tagName = tagName.toLowerCase();
for (var result = [], i = 0; i < this.childNodes.length; i++) {
if (this.childNodes[i].tagName == tagName || tagName == "*")
result.push(this.childNodes[i]);
if (!norecur)
result = result.concat(this.childNodes[i].getElementsByTagName(tagName));
}
return result;
};
this.cloneNode = function(deep){
var jml = this.serialize(true, true, !deep);
return jpf.document.createElement(jml);
};
this.serialize = function(returnXml, skipFormat, onlyMe){
var node = this.$jml.cloneNode(false);
for (var name, i = 0; i < (this.$supportedProperties || []).length; i++) {
name = this.$supportedProperties[i];
if (this.getProperty(name) !== undefined)
node.setAttribute(name, String(this.getProperty(name)).toString());
}
if (!onlyMe) {
var l, nodes = this.childNodes;
for (i = 0, l = nodes.length; i < l; i++) {
node.appendChild(nodes[i].serialize(true));
}
}
return returnXml
? node
: (skipFormat
? node.xml || node.serialize()
: jpf.formatXml(node.xml || node.serialize()));
};
this.setAttribute = function(name, value) {
if (this.$jml)
this.$jml.setAttribute(name, (value || "").toString());
if (name.indexOf("on") === 0) { 
this.addEventListener(name, typeof value == "string"
? new Function(value)
: value);
return;
}
if (this.nodeFunc == jpf.NODE_VISIBLE && !this.oExt)
return;
if (jpf.dynPropMatch.test(value))
this.setDynamicProperty(name, value);
else if (this.setProperty)
this.setProperty(name, value);
else
this[name] = value;
};
this.removeAttribute = function(name){
this.setProperty(name, null);
};
this.getAttribute = this.getProperty || function(name){
return this[name];
};
this.getAttributeNode = function(name){
return this.attributes.getNamedItem(name);
}
this.attributes = {
getNamedItem    : function(name){
return {
nodeType  : 2,
nodeName  : name,
nodeValue : _self[name] || ""
}
},
setNamedItem    : function(node){
_self.setAttribute(node.name, node.value);
},
removeNamedItem : function(name){
_self.removeAttribute(name);
},
length          : function(){
return _self.$jml && _self.$jml.attributes.length
|| (_self.$supportedProperties || {length:0}).length; 
},
item            : function(i){
if (_self.$jml && _self.$jml.attributes)
return _self.$jml.attributes[i];
var collection = _self.$supportedProperties;
if (!collection[i])
return false;
return this.getNamedItem(collection[i]);
}
};
this.nodeValue    = "";
this.namespaceURI = jpf.ns.jml;
this.$setParent = function(pNode){
if (pNode && pNode.childNodes.indexOf(this) > -1)
return;
this.parentNode = pNode;
var nodes = this.parentNode.childNodes;
var id = nodes.push(this) - 1;
if (id === 0)
this.parentNode.firstChild = this;
else {
var n = nodes[id - 1];
if (n) {
n.nextSibling = this;
this.previousSibling = n || null;
}
this.parentNode.lastChild = this;
}
};
if (this.parentNode && this.parentNode.hasFeature
&& this.parentNode.hasFeature(__WITH_JMLDOM__))
this.$setParent(this.parentNode);
};
var __MULTISELECT__ = 1 << 8;
jpf.MultiSelect = function(){
var noEvent;
var selSmartbinding;
var valueList    = [];
var selectedList = [];
var _self        = this;
this.$regbase    = this.$regbase|__MULTISELECT__;
this.selected     = null;
this.$selected    = null;
this.indicator    = null;
this.$indicator   = null;
this.useindicator = true;
this.remove = function(nodeList){
if (!nodeList)
nodeList = valueList;
if (nodeList.nodeType)
nodeList = [nodeList];
if (!nodeList || !nodeList.length)
return;
var rValue;
if (nodeList.length > 1 && (!this.actionRules
|| this.actionRules["removegroup"] || !this.actionRules["remove"])) {
rValue = this.executeAction("removeNodeList", nodeList,
"removegroup", nodeList[0]);
}
else {
for (var i = 0; i < nodeList.length; i++) {
rValue = this.executeAction("removeNode",
[nodeList[i]], "remove", nodeList[i], null, null, true);
if (rValue === false)
return false;
}
}
return rValue;
};
this.add = function(xmlNode, pNode, beforeNode){
var node;
if (this.actionRules) {
if (xmlNode && xmlNode.nodeType)
node = this.getNodeFromRule("add", xmlNode, true);
else if (typeof xmlNode == "string") {
if (xmlNode.trim().charAt(0) == "<") {
xmlNode = jpf.getXml(xmlNode);
node = this.getNodeFromRule("add", xmlNode, true);
}
else {
var rules = this.actionRules["add"];
for (var i = 0, l = rules.length; i < l; i++) {
if (rules[i].getAttribute("type") == xmlNode) {
xmlNode = null;
node = rules[i];
break;
}
}
}
}
if (!node && this.actionRules["add"])
node = this.actionRules["add"][0];
}
else
node = null;
var refNode  = this.isTreeArch ? this.selected || this.xmlRoot : this.xmlRoot;
var jmlNode  = this; 
var callback = function(addXmlNode, state, extra){
if (state != jpf.SUCCESS) {
var oError;
if (extra.tpModule.retryTimeout(extra, state, jmlNode, oError) === true)
return true;
throw oError;
}
if (typeof addXmlNode != "object")
addXmlNode = jpf.getXmlDom(addXmlNode).documentElement;
if (addXmlNode.getAttribute(jpf.xmldb.xmlIdTag))
addXmlNode.setAttribute(jpf.xmldb.xmlIdTag, "");
var actionNode = jmlNode.getNodeFromRule("add", jmlNode.isTreeArch
? jmlNode.selected
: jmlNode.xmlRoot, true, true);
if (!pNode) {
if (actionNode && actionNode.getAttribute("parent")) {
pNode = jmlNode.xmlRoot
.selectSingleNode(actionNode.getAttribute("parent"));
}
else {
pNode = jmlNode.isTreeArch
? jmlNode.selected || jmlNode.xmlRoot
: jmlNode.xmlRoot
}
}
if (!pNode)
pNode = jmlNode.xmlRoot;
if (jpf.isSafari && pNode.ownerDocument != addXmlNode.ownerDocument)
addXmlNode = pNode.ownerDocument.importNode(addXmlNode, true); 
if (jmlNode.executeAction("appendChild",
[pNode, addXmlNode, beforeNode], "add", addXmlNode) !== false
&& jmlNode.autoselect)
jmlNode.select(addXmlNode);
return addXmlNode;
}
if (xmlNode)
return callback(xmlNode, jpf.SUCCESS);
else {
if (node.getAttribute("get"))
return jpf.getData(node.getAttribute("get"), refNode, null, callback)
else if (node.firstChild) {
var node = jpf.getNode(node, [0]);
if (jpf.supportNamespaces && node.namespaceURI == jpf.ns.xhtml) {
node = jpf.getXml(node.xml.replace(/xmlns\=\"[^"]*\"/g, ""));
}
else node = node.cloneNode(true);
return callback(node, jpf.SUCCESS);
}
}
return addXmlNode;
};
if (!this.setValue) {
this.setValue = function(value, disable_event){
noEvent = disable_event;
this.setProperty("value", value);
noEvent = false;
};
}
this.findXmlNodeByValue = function(value){
var nodes = this.getTraverseNodes();
var bindSet = this.bindingRules && this.bindingRules[this.mainBind]
? this.mainBind
: (this.valuerule ? "value" : "caption");
for (var i = 0; i < nodes.length; i++) {
if (this.applyRuleSetOnNode(bindSet, nodes[i]) == value)
return nodes[i];
}
};
if (!this.getValue) {
this.getValue = function(xmlNode){
if (!this.bindingRules && !this.caption) 
return false;
if (!this.multiselect && !this.xmlRoot && selSmartbinding && selSmartbinding.xmlRoot)
return selSmartbinding.applyRuleSetOnNode(selSmartbinding.mainBind,
selSmartbinding.xmlRoot, null, true);
return this.applyRuleSetOnNode(this.mainBind, xmlNode || this.selected, null, true)
|| this.applyRuleSetOnNode("caption", xmlNode || this.selected, null, true);
};
}
this.$setMultiBind = function(smartbinding, part){
if (!selSmartbinding)
selSmartbinding = new jpf.MultiLevelBinding(this);
selSmartbinding.setSmartBinding(smartbinding, part);
this.dispatchEvent("initselbind", {smartbinding : selSmartbinding});
};
this.getMultibinding = function(){
return selSmartbinding;
}
this.$getMultiBind = function(){
return (selSmartbinding
|| (selSmartbinding = new jpf.MultiLevelBinding(this)));
};
this.reselect = function(){
if (this.selected) this.select(this.selected, null, this.ctrlselect,
null, true);
};
var buffered = null;
this.select  = function(xmlNode, ctrlKey, shiftKey, fakeselect, force, noEvent){
if (!this.selectable || this.disabled) return;
if (this.ctrlselect && !shiftKey)
ctrlKey = true;
if (!this.xmlRoot) {
buffered        = [arguments, this.autoselect];
this.autoselect = true;
return;
}
if (buffered) {
var x    = buffered;
buffered = null;
if (this.autoselect)
this.autoselect = x[1];
return this.select.apply(this, x[0]);
}
var htmlNode;
if (!xmlNode) {
return false;
}
if (typeof xmlNode != "object") {
var str = xmlNode;
xmlNode = jpf.xmldb.getNodeById(xmlNode);
if (!xmlNode) {
xmlNode = this.findXmlNodeByValue(str);
if (!xmlNode) {
this.clearSelection(null, noEvent);
return;
}
}
}
if (!xmlNode.style)
htmlNode = this.caching
? this.getNodeFromCache(xmlNode.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId)
: document.getElementById(xmlNode.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId); 
else {
var id = (htmlNode = xmlNode).getAttribute(jpf.xmldb.htmlIdTag);
while (!id && htmlNode.parentNode)
id = (htmlNode = htmlNode.parentNode).getAttribute(
jpf.xmldb.htmlIdTag);
xmlNode = jpf.xmldb.getNodeById(id, this.xmlRoot);
}
if(this.dispatchEvent('beforeselect', {
xmlNode     : xmlNode,
htmlNode    : htmlNode,
ctrlKey     : ctrlKey,
shiftKey    : shiftKey,
captureOnly : noEvent
}) === false)
return false;
var lastIndicator = this.indicator;
this.indicator    = xmlNode;
if (shiftKey && this.multiselect) {
var range = this.$calcSelectRange(valueList[0] || lastIndicator,
xmlNode);
if (this.$indicator)
this.$deindicate(this.$indicator);
this.selectList(range);
this.$selected  =
this.$indicator = this.$indicate(htmlNode);
}
else if (ctrlKey && this.multiselect) { 
if (valueList.contains(xmlNode)) {
if (!fakeselect) {
selectedList.remove(htmlNode);
valueList.remove(xmlNode);
}
if (this.selected == xmlNode) {
var ind = this.$indicator;
this.clearSelection(true, true);
this.$deindicate(ind);
if (valueList.length && !fakeselect) {
this.selected = valueList[0];
}
}
else
this.$deselect(htmlNode, xmlNode);
if (htmlNode != this.$indicator)
this.$deindicate(this.$indicator);
this.$selected  =
this.$indicator = this.$indicate(htmlNode);
}
else {
if (this.$indicator)
this.$deindicate(this.$indicator);
this.$indicator = this.$indicate(htmlNode);
this.$selected   = this.$select(htmlNode);
this.selected     = xmlNode;
if (!fakeselect) {
selectedList.push(htmlNode);
valueList.push(xmlNode);
}
}
}
else if (htmlNode && selectedList.contains(htmlNode) && fakeselect) 
return;
else { 
if (!force && htmlNode && this.$selected == htmlNode
&& valueList.length <= 1 && !this.reselectable
&& selectedList.contains(htmlNode))
return;
if (this.$selected)
this.$deselect(this.$selected);
if (this.$indicator)
this.$deindicate(this.$indicator);
if (this.selected)
this.clearSelection(null, true);
this.$indicator = this.$indicate(htmlNode, xmlNode);
this.$selected  = this.$select(htmlNode, xmlNode);
this.selected    = xmlNode;
selectedList.push(htmlNode);
valueList.push(xmlNode);
}
if (this.delayedselect){
var jNode = this;
setTimeout(function(){
jNode.dispatchEvent("afterselect", {
list        : valueList,
xmlNode     : xmlNode,
captureOnly : noEvent
});
}, 10);
}
else
this.dispatchEvent("afterselect", {
list        : valueList,
xmlNode     : xmlNode,
captureOnly : noEvent
});
return true;
};
this.choose = function(xmlNode){
if (!this.selectable || this.disabled) return;
if (this.dispatchEvent("beforechoose", {xmlNode : xmlNode}) === false)
return false;
if (xmlNode && !xmlNode.style)
this.select(xmlNode);
if (this.hasFeature(__DATABINDING__)
&& this.dispatchEvent("afterchoose", {xmlNode : this.selected}) !== false)
this.setConnections(this.selected, "choice");
};
this.clearSelection = function(singleNode, noEvent){
if (!this.selectable || this.disabled) return;
var clSel = singleNode ? this.selected : valueList;
if (!noEvent && this.dispatchEvent("beforedeselect", {
xmlNode : clSel
}) === false)
return false;
var htmlNode;
if (this.selected) {
htmlNode = this.caching
? this.getNodeFromCache(this.selected.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId)
: document.getElementById(this.selected.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId); 
this.$deselect(htmlNode);
}
this.$selected = this.selected = null;
if (!singleNode) {
for (var i = valueList.length - 1; i >= 0; i--) {
htmlNode = this.caching
? this.getNodeFromCache(valueList[i].getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId)
: document.getElementById(valueList[i].getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId); 
this.$deselect(htmlNode);
}
selectedList = [];
valueList    = [];
}
if (this.indicator) {
htmlNode = this.caching
? this.getNodeFromCache(this.indicator.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId)
: document.getElementById(this.indicator.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId); 
this.$selected  =
this.$indicator = this.$indicate(htmlNode);
}
if (!noEvent)
this.dispatchEvent("afterdeselect", {xmlNode : clSel});
};
this.selectList = function(xmlNodeList, noEvent, selected){
if (!this.selectable || this.disabled) return;
if (this.dispatchEvent("beforeselect", {
xmlNode     : selected,
captureOnly : noEvent
}) === false)
return false;
this.clearSelection(null, true);
for (var sel, i=0;i<xmlNodeList.length;i++) {
if (!xmlNodeList[i] || xmlNodeList[i].nodeType != 1) continue; 
var xmlNode = xmlNodeList[i];
if (typeof xmlNode != "object")
xmlNode = jpf.xmldb.getNodeById(xmlNode);
if (!xmlNode.style)
htmlNode = this.$findNode(null, xmlNode.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId); 
else {
htmlNode = xmlNode;
xmlNode  = jpf.xmldb.getNodeById(htmlNode.getAttribute(
jpf.xmldb.htmlIdTag));
}
if (!xmlNode) {
continue;
}
if (htmlNode) {
if (!sel && selected == htmlNode)
sel = htmlNode;
this.$select(htmlNode);
selectedList.push(htmlNode);
}
valueList.push(xmlNode);
}
this.$selected = sel || selectedList[0];
this.selected   = selected || valueList[0];
this.dispatchEvent("afterselect", {
list        : valueList,
xmlNode     : this.selected,
captureOnly : noEvent
});
};
this.setIndicator = function(xmlNode){
if (!xmlNode) {
if (this.$indicator)
this.$deindicate(this.$indicator);
this.indicator  =
this.$indicator = null;
return;
}
var htmlNode;
if (typeof xmlNode != "object")
xmlNode = jpf.xmldb.getNodeById(xmlNode);
if (!xmlNode.style)
htmlNode = this.caching
? this.getNodeFromCache(xmlNode.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId)
: document.getElementById(xmlNode.getAttribute(
jpf.xmldb.xmlIdTag) + "|" + this.uniqueId); 
else {
var id = (htmlNode = xmlNode).getAttribute(jpf.xmldb.htmlIdTag);
while (!id && htmlNode.parentNode)
id = (htmlNode = htmlNode.parentNode).getAttribute(
jpf.xmldb.htmlIdTag);
xmlNode = jpf.xmldb.getNodeById(id);
}
if (this.$indicator)
this.$deindicate(this.$indicator);
this.indicator  = xmlNode;
this.$indicator = this.$indicate(htmlNode);
this.dispatchEvent("indicate");
};
this.setTempSelected = function(xmlNode, ctrlKey, shiftKey){
clearTimeout(this.timer);
if (ctrlKey || this.ctrlselect) {
if (this.$tempsel) {
this.select(this.$tempsel);
this.$tempsel = null;
}
this.setIndicator(xmlNode);
}
else if (shiftKey){
if (this.$tempsel) {
this.$deselect(this.$tempsel);
this.$tempsel = null;
}
this.select(xmlNode, null, shiftKey);
}
else if (!this.bufferselect) {
this.select(xmlNode);
}
else {
var id = jpf.xmldb.getID(xmlNode, this);
this.$deselect(this.$tempsel || this.$selected);
this.$deindicate(this.$tempsel || this.$indicator);
this.$tempsel = this.$indicate(document.getElementById(id));
this.$select(this.$tempsel);
this.timer = setTimeout(function(){
_self.selectTemp();
}, 400);
}
};
this.selectTemp = function(){
if (!this.$tempsel)
return;
clearTimeout(this.timer);
this.select(this.$tempsel);
this.$tempsel = null;
this.timer    = null;
};
this.selectAll = function(){
if (!this.multiselect || !this.selectable
|| this.disabled || !this.$selected)
return;
var nodes = this.getTraverseNodes();
this.selectList(nodes);
};
this.getSelection = function(xmldoc){
var i, r;
if (xmldoc) {
r = this.xmlRoot
? this.xmlRoot.ownerDocument.createDocumentFragment()
: jpf.getXmlDom().createDocumentFragment();
for (i = 0; i < valueList.length; i++)
jpf.xmldb.clearConnections(r.appendChild(
valueList[i].cloneNode(true)));
}
else
for (r = [], i = 0; i < valueList.length; i++)
r.push(valueList[i]);
return r;
};
this.defaultSelectNext = function(xmlNode, isTree){
var next = this.getNextTraverseSelected(xmlNode);
if (next || !isTree)
this.select(next ? next : this.getTraverseParent(xmlNode));
else
this.clearSelection(null, true);
};
this.selectNext = function(){
var xmlNode = this.getNextTraverse();
if (xmlNode)
this.select(xmlNode);
};
this.selectPrevious = function(){
var xmlNode = this.getNextTraverse(null, -1);
if (xmlNode)
this.select(xmlNode);
};
this.getDefaultNext = function(xmlNode, isTree){
var next = this.getNextTraverseSelected(xmlNode);
return (next && next != xmlNode)
? next
: (isTree
? this.getTraverseParent(xmlNode)
: null); 
};
this.isSelected = function(xmlNode){
if (!xmlNode) return false;
for (var i = 0; i < valueList.length; i++) {
if (valueList[i] == xmlNode)
return true;
}
return false;
};
this.$checkSelection = function(nextNode){
if (valueList.length > 1) {
for (var lst = [], i = 0, l = valueList.length; i < l; i++) {
if (jpf.xmldb.isChildOf(this.xmlRoot, valueList[i]))
lst.push(valueList[i]);
}
if (lst.length > 1) {
this.selectList(lst);
if(this.indicator
&& !jpf.xmldb.isChildOf(this.xmlRoot, this.indicator)) {
this.setIndicator(nextNode || this.selected);
}
return;
}
else if (lst.length) {
nextNode = lst[0];
}
}
if (!nextNode) {
if (this.selected
&& !jpf.xmldb.isChildOf(this.xmlRoot, this.selected)) {
nextNode = this.getFirstTraverseNode();
}
else if(this.selected && this.indicator
&& !jpf.xmldb.isChildOf(this.xmlRoot, this.indicator)) {
this.setIndicator(this.selected);
}
else if (!this.selected){
nextNode = this.xmlRoot
? this.getFirstTraverseNode()
: null;
}
else {
return; 
}
}
if (nextNode) {
if (this.autoselect) {
this.select(nextNode);
}
else {
if (!this.multiselect)
this.clearSelection();
this.setIndicator(nextNode);
}
}
else
this.clearSelection();
};
this.selectable = true;
if (this.ctrlselect === undefined)
this.ctrlselect = false;
if (this.multiselect === undefined)
this.multiselect = true;
if (this.autoselect === undefined)
this.autoselect = true;
if (this.delayedselect === undefined)
this.delayedselect = true;
if (this.allowdeselect === undefined)
this.allowdeselect = true;
this.reselectable = false;
this.$booleanProperties["selectable"]    = true;
this.$booleanProperties["multiselect"]   = true;
this.$booleanProperties["autoselect"]    = true;
this.$booleanProperties["delayedselect"] = true;
this.$booleanProperties["allowdeselect"] = true;
this.$booleanProperties["reselectable"]  = true;
this.$supportedProperties.push("selectable", "ctrlselect", "multiselect",
"autoselect", "delayedselect", "allowdeselect", "reselectable", 
"value", "default");
this.$propHandlers["value"] = function(value){
if (!this.bindingRules && !this.caption || !this.xmlRoot)
return;
if (jpf.isNot(value))
return this.clearSelection(null, noEvent);
if (!this.xmlRoot)
return this.select(value);
var xmlNode = this.findXmlNodeByValue(value);
if (xmlNode)
this.select(xmlNode, null, null, null, null, noEvent);
else
return this.clearSelection(null, noEvent);
};
this.$propHandlers["allowdeselect"] = function(value){
if (value) {
var _self = this;
this.oInt.onmousedown = function(e){
if (!e) e = event;
if (e.ctrlKey || e.shiftKey)
return;
var srcElement = e.srcElement || e.target;
if (_self.allowdeselect && (srcElement == this
|| srcElement.getAttribute(jpf.xmldb.htmlIdTag)))
_self.clearSelection(); 
}
}
else {
this.oInt.onmousedown = null;
}
};
this.$propHandlers["ctrlselect"] = function(value){
if (value != "enter")
this.ctrlselect = jpf.isTrue(value);
}
function fAutoselect(){this.selectAll();}
this.$propHandlers["autoselect"] = function(value){
if (value == "all" && this.multiselect) {
this.addEventListener("afterload", fAutoselect);
}
else {
this.removeEventListener("afterload", fAutoselect);
}
};
this.$propHandlers["multiselect"] = function(value){
if (!value && valueList.length > 1) {
this.select(this.selected);
}
if (value)
this.bufferselect = false; 
};
this.addEventListener("beforeselect", function(e){
if (this.applyRuleSetOnNode("select", e.xmlNode, ".") === false)
return false;
}, true);
this.addEventListener("afterselect", function (e){
if (this.bindingRules && (this.bindingRules["value"]
|| this.bindingRules["caption"]) || this.caption) {
this.value = this.applyRuleSetOnNode(this.bindingRules && this.bindingRules["value"] || this.valuerule
? "value"
: "caption", e.xmlNode);
this.setProperty("value", this.value);
}
if (this.sellength != valueList.length)
this.setProperty("sellength", valueList.length);
}, true);
};
jpf.MultiSelectServer = {
objects : {},
register : function(xmlId, xmlNode, selList, jNode){
if (!this.uniqueId)
this.uniqueId = jpf.all.push(this) - 1;
this.objects[xmlId] = {
xml   : xmlNode,
list  : selList,
jNode : jNode
};
},
$xmlUpdate : function(action, xmlNode, listenNode, UndoObj){
if (action != "attribute") return;
var data = this.objects[xmlNode.getAttribute(jpf.xmldb.xmlIdTag)];
if (!data) return;
var nodes = xmlNode.attributes;
for (var j = 0; j < data.list.length; j++) {
jpf.xmldb.setAttribute(data.list[j], UndoObj.name,
xmlNode.getAttribute(UndoObj.name));
}
}
};
var __TRANSACTION__ = 1 << 3;
var __RENAME__ = 1 << 10;
jpf.Rename = function(){
this.$regbase     = this.$regbase|__RENAME__;
this.canrename    = true;
var renameSubject = null;
var renameTimer   = null;
var lastCursor;
this.$booleanProperties["canrename"] = true;
this.$booleanProperties["autorename"] = true;
this.$supportedProperties.push("canrename", "autorename");
this.$propHandlers["autorename"] = function(value){
if (value) {
this.reselectable = true;
this.bufferselect = false;
this.addEventListener("afterselect", $afterselect);
this.addEventListener("keydown", $keydown);
}
else {
this.removeEventListener("afterselect", $afterselect);
this.removeEventListener("keydown", $keydown);
}
}
var _self = this;
function $afterselect(){
setTimeout(function(){
if (_self.hasFocus())
_self.startRename();
}, 20);
}
function $keydown(e){
if (!this.renaming && e.isCharacter())
this.startRename();
}
this.$isContentEditable = function(e){
if (this.renaming && this.autorename)
return true;
}
this.rename = function(xmlNode, value){
if (!xmlNode)
xmlNode = this.indicator || this.selected;
if (!xmlNode) return;
this.executeActionByRuleSet("rename", "caption", xmlNode, value);
};
this.startDelayedRename = function(e, time){
if (e && (e.button == 2 || e.ctrlKey || e.shiftKey))
return;
clearTimeout(renameTimer);
renameTimer = setTimeout('jpf.lookup('
+ this.uniqueId + ').startRename()', time || 400);
};
this.startRename = function(force, startEmpty){
if (!force && (this.renaming || !this.canrename 
|| !this.$startAction("rename", this.indicator 
|| this.selected, this.stopRename)))
return false;
if (!this.hasFocus())
this.focus(null, null, true);
clearTimeout(renameTimer);
this.renaming = true;
renameSubject = this.indicator || this.selected;
var elCaption = this.$getCaptionElement
? this.$getCaptionElement()
: this.$indicator || this.$selected;
if (!elCaption) 
return this.stopRename();
var wdt = elCaption.offsetWidth;
lastCursor = elCaption.style.cursor;
elCaption.style.cursor = "text";
elCaption.parentNode.replaceChild(this.oTxt, elCaption);
elCaption.host = this;
if (jpf.isTrue(this.$getOption("main", "scalerename"))) {
var diff = jpf.getWidthDiff(this.oTxt);
this.oTxt.style.width = (wdt - diff) + "px";
}
this.replacedNode = elCaption;
var xmlNode       = this.$getCaptionXml
? this.$getCaptionXml(renameSubject)
: this.getNodeFromRule("caption", renameSubject);
this.oTxt[jpf.hasContentEditable ? "innerHTML" : "value"] = startEmpty || !xmlNode
? ""
: (xmlNode.nodeType >= 2 && xmlNode.nodeType <= 4
? unescape(decodeURI(xmlNode.nodeValue))
: (jpf.xmldb.isOnlyChild(xmlNode.firstChild, [3,4])
? jpf.xmldb.getNodeValue(xmlNode)
: this.applyRuleSetOnNode("caption", renameSubject))) || "";
this.oTxt.unselectable = "Off";
this.oTxt.host         = this;
this.oTxt.focus();
this.oTxt.select();
};
this.stopRename = function(contextXml, success){
clearTimeout(renameTimer);
if (!this.renaming || contextXml && contextXml != renameSubject)
return false;
if (this.oTxt.parentNode && this.oTxt.parentNode.nodeType == 1)
this.oTxt.parentNode.replaceChild(this.replacedNode, this.oTxt);
this.renaming = false;
if (this.replacedNode) {
this.replacedNode.style.cursor = lastCursor || "";
this.replacedNode.host = null;
}
if (!success) {
this.dispatchEvent("stoprename");
this.$stopAction("rename");
}
else {
this.replacedNode.innerHTML = this.oTxt[jpf.hasContentEditable
? "innerHTML"
: "value"];
this.rename(renameSubject,
this.oTxt[jpf.hasContentEditable ? "innerHTML" : "value"]
.replace(/<.*?nobr>/gi, ""));
}
if (!this.renaming) {
renameSubject         = null;
this.replacedNode     = null;
this.oTxt.style.width = "";
}
return true;
};
this.addEventListener("keydown", function(e){
var key = e.keyCode;
if (this.renaming) {
if (key == 27 || key == 13) {
this.stopRename(null, key == 13 && !this.$autocomplete);
return false;
}
return;
}
if (key == 113) {
if (this.$tempsel)
this.selectTemp();
if (this.indicator != this.selected) {
if (this.multiselect || this.isSelected(this.indicator)) {
this.selected  = this.indicator;
this.$selected = this.$indicator;
}
else
this.select(this.indicator, true);
}
this.startRename();
return false;
}
}, true);
if (!(this.oTxt = this.pHtmlDoc.getElementById("txt_rename"))) {
if (jpf.hasContentEditable) {
this.oTxt = this.pHtmlDoc.createElement("DIV");
this.oTxt.contentEditable = true;
if (jpf.isIE6)
this.oTxt.style.width = "1px";
}
else {
this.oTxt              = this.pHtmlDoc.createElement("input");
this.oTxt.id           = "txt_rename";
this.oTxt.autocomplete = false;
}
this.oTxt.refCount         = 0;
this.oTxt.id               = "txt_rename";
this.oTxt.style.whiteSpace = "nowrap";
this.oTxt.onselectstart    = function(e){
(e || event).cancelBubble = true;
};
jpf.sanitizeTextbox(this.oTxt);
this.oTxt.onmouseover = this.oTxt.onmouseout = this.oTxt.oncontextmenu =
this.oTxt.onmousedown = function(e){ (e || event).cancelBubble = true; };
this.oTxt.onkeyup = function(){
if (!this.host.$autocomplete)
return;
this.host.$lookup(this[jpf.hasContentEditable ? "innerHTML" : "value"]);
}
this.oTxt.select = function(){
if (!jpf.hasMsRangeObject)
return this.focus();
var r = document.selection.createRange();
try {
r.moveToElementText(this);
if (jpf.isFalse(this.host.$getOption("main", "selectrename")) 
|| typeof this.host.$renameStartCollapse != "undefined") 
r.collapse(this.host.$renameStartCollapse);
} catch(e) {} 
r.select();
};
this.oTxt.onfocus = function(){
if (jpf.hasFocusBug)
jpf.window.$focusfix2();
};
this.oTxt.onblur = function(){
if (jpf.isGecko)
return; 
if (jpf.hasFocusBug)
jpf.window.$blurfix();
if (this.host.$autocomplete)
return;
this.host.stopRename(null, true);
};
}
this.oTxt.refCount++;
this.$jmlDestroyers.push(function(){
this.oTxt.refCount--;
if (!this.oTxt.refCount) {
this.oTxt.host        =
this.oTxt.onmouseover =
this.oTxt.onmousedown =
this.oTxt.select      =
this.oTxt.onfocus     =
this.oTxt.onblur      = null;
}
});
};
var __XFORMS__ = 1 << 17;
var __EDITMODE__  = 1 << 15;
var __MULTILANG__ = 1 << 16;
jpf.language = {
automatch : false,
prefix    : "sub.main.",
words     : {},
texts     : {},
elements  : {},
count     :  0,
loadXml   : function(xmlNode, prefix){
if (typeof xmlNode == "string")
xmlNode = jpf.getXmlDom(xmlNode).documentElement;
this.parseSection(xmlNode, prefix);
},
loadForm  : function(instruction) {
jpf.setModel(instruction, {
load: function(xmlNode){
if (!xmlNode || this.isLoaded) return;
jpf.language.loadXml(xmlNode);
this.isLoaded = true;
},
setModel: function(model, xpath){
if (typeof model == "string")
model = jpf.nameserver.get("model", model);
model.register(this, xpath);
}
});
},
parseSection: function(xmlNode, prefix){
if (!prefix)
prefix = "";
if (xmlNode.tagName == "key") {
prefix += "." + xmlNode.getAttribute("id");
this.update(prefix, xmlNode.firstChild ? xmlNode.firstChild.nodeValue : "");
return;
}
if (xmlNode.tagName == "group")
prefix += (prefix ? "." : "") + xmlNode.getAttribute("id");
var nodes = xmlNode.childNodes;
for (var i = 0; i < nodes.length; i++)
this.parseSection(nodes[i], prefix);
},
update: function(key, value){
this.words[key] = value;
if (!this.elements[key])
return;
for (var i = 0; i < this.elements[key].length; i++) {
if (this.elements[key][i].htmlNode.nodeType == 1)
this.elements[key][i].htmlNode.innerHTML = value;
else
this.elements[key][i].htmlNode.nodeValue = value;
}
},
addElement: function(key, oEl){
if (!this.elements[key])
this.elements[key] = [];
return this.elements[key].push(oEl) - 1;
},
removeElement: function(key, id){
this.elements[key].removeIndex(id);
},
getWord: function(key){
return this.words[key];
}
};
jpf.MultiLang = function(){
this.$regbase = this.$regbase | __MULTILANG__;
var reggedItems = [];
this.$makeEditable = function(type, htmlNode, jmlNode){
if (jmlNode.prefix != "j")
return;
var config = this.editableParts[type];
for (var i = 0; i < config.length; i++) {
var subNode = this.$getLayoutNode(type, config[i][0], htmlNode);
if (!subNode)
continue;
var xmlNode = config
? jpf.xmldb.selectSingleNode(config[i][1], jmlNode)
: jpf.xmldb.getTextNode(jmlNode);
if (!xmlNode)
continue;
var key = xmlNode.nodeValue.match(/^\$(.*)\$$/); 
if (key) {
subNode = subNode.nodeType == 1
? subNode
: (subNode.nodeType == 3 || subNode.nodeType == 4
? subNode.parentNode
: subNode); 
reggedItems.push([key[1], jpf.language.addElement(key[1], {
htmlNode: subNode
})]);
}
}
};
this.$removeEditable = function(){
for (var i = 0; i < reggedItems.length; i++) {
jpf.language.removeElement(reggedItems[i][0], reggedItems[i][1]);
}
reggedItems = [];
};
this.$jmlDestroyers.push(function(){
this.$removeEditable();
});
};
var __DOCKING__ = 1 << 18;
var __ANCHORING__ = 1 << 13;
jpf.Anchoring = function(){
this.$regbase = this.$regbase | __ANCHORING__;
this.$anchors = [];
var VERTICAL   = 1;
var HORIZONTAL = 2;
var l = jpf.layout, inited = false, updateQueue = 0,
hordiff, verdiff, rule_v = "", rule_h = "", rule_header,
id, inited, parsed, disabled;
this.disableAnchoring = function(activate){
if (!parsed || !inited || disabled)
return;
l.removeRule(this.pHtmlNode, this.uniqueId + "_anchors");
if (l.queue)
l.queue(this.pHtmlNode);
this.$propHandlers["anchors"] =
this.$propHandlers["left"]   =
this.$propHandlers["width"]  =
this.$propHandlers["right"]  =
this.$propHandlers["top"]    =
this.$propHandlers["height"] =
this.$propHandlers["bottom"] = null;
this.$domHandlers["remove"].remove(remove);
this.$domHandlers["reparent"].remove(reparent);
if (this.right)
this.oExt.style.left = this.oExt.offsetLeft;
if (this.bottom)
this.oExt.style.top = this.oExt.offsetTop;
this.$hide = null;
this.$show = null;
inited   = false;
disabled = true; 
};
this.enableAnchoring = function(){
if (inited) 
return;
this.$supportedProperties.push("right", "bottom", "width",
"left", "top", "height");
this.$propHandlers["anchors"]  = function(value){
this.$anchors = value.splitSafe("(?:, *| )");
if (!updateQueue && jpf.loaded)
l.queue(this.pHtmlNode, this);
updateQueue = updateQueue | HORIZONTAL | VERTICAL;
};
this.$propHandlers["left"]  =
this.$propHandlers["width"] =
this.$propHandlers["right"] = function(value){
if (!updateQueue && (!jpf.isParsing || jpf.parsingFinalPass))
l.queue(this.pHtmlNode, this);
updateQueue = updateQueue | HORIZONTAL;
};
this.$propHandlers["top"]    =
this.$propHandlers["height"] =
this.$propHandlers["bottom"] = function(value){
if (!updateQueue && (!jpf.isParsing || jpf.parsingFinalPass))
l.queue(this.pHtmlNode, this);
updateQueue = updateQueue | VERTICAL;
};
this.$domHandlers["remove"].push(remove);
this.$domHandlers["reparent"].push(reparent);
this.$hide = function(){
if (!(rule_header || rule_v || rule_h))
return;
l.removeRule(this.pHtmlNode, this.uniqueId + "_anchors");
l.queue(this.pHtmlNode)
};
this.$show = function(){
if (!(rule_header || rule_v || rule_h))
return;
if (rule_v || rule_h) {
rules = rule_header + "\n" + rule_v + "\n" + rule_h;
l.setRules(this.pHtmlNode, this.uniqueId + "_anchors", rules);
this.oExt.style.display = "none";
l.queue(this.pHtmlNode, this);
}
l.processQueue();
};
inited   = true;
};
function remove(doOnlyAdmin){
if (doOnlyAdmin)
return;
if (l.queue) {
l.removeRule(this.pHtmlNode, this.uniqueId + "_anchors");
l.queue(this.pHtmlNode)
}
}
function reparent(beforeNode, pNode, withinParent, oldParent){
if (!this.$jmlLoaded)
return;
if (!withinParent && !disabled && parsed) 
this.$moveAnchoringRules(oldParent);
}
this.$moveAnchoringRules = function(oldParent, updateNow){
var rules = l.removeRule(oldParent, this.uniqueId + "_anchors");
if (rules)
l.queue(oldParent);
if (!rule_v && !rule_h)
return;
rule_header = getRuleHeader.call(this);
rules = rule_header + "\n" + rule_v + "\n" + rule_h;
this.oExt.style.display = "none";
l.setRules(this.pHtmlNode, this.uniqueId + "_anchors", rules);
l.queue(this.pHtmlNode, this);
};
this.$hasAnchorRules = function(){
return rule_v || rule_h ? true : false;
};
this.$setAnchoringEnabled = function(){
disabled = false;
};
function getRuleHeader(){
return "try{\
var oHtml = " + (jpf.hasHtmlIdsInJs
? this.oExt.getAttribute("id")
: "document.getElementById('"
+ this.oExt.getAttribute("id") + "')") + ";\
\
var pWidth = " + (this.pHtmlNode == this.pHtmlDoc.body
? (jpf.isIE
? "document.documentElement.offsetWidth"
: "window.innerWidth")
: "oHtml.parentNode.offsetWidth") + ";\
\
var pHeight = " + (this.pHtmlNode == this.pHtmlDoc.body
? (jpf.isIE
? "document.documentElement.offsetHeight"
: "window.innerHeight")
: "oHtml.parentNode.offsetHeight") + ";\
}catch(e){\
}";
}
function setPercentage(expr, value){
return String(expr).replace(jpf.percentageMatch, "((" + value + " * $1)/100)");
}
this.$updateLayout = function(){
if (!parsed) {
if (!this.oExt.getAttribute("id"))
jpf.setUniqueHtmlId(this.oExt);
var diff    = jpf.getDiff(this.oExt);
hordiff     = diff[0];
verdiff     = diff[1];
rule_header = getRuleHeader.call(this);
parsed      = true;
}
if (!updateQueue) {
if (this.visible)
this.oExt.style.display = "block";
return;
}
if (this.left || this.top || this.right || this.bottom || this.$anchors.length)
this.oExt.style.position = "absolute";
var rules;
if (updateQueue & HORIZONTAL) {
rules = [];
var left  = this.left || this.$anchors[3];
var right = this.right || this.$anchors[1];
var width = this.width;
if (right && typeof right == "string")
right = setPercentage(right, "pWidth");
if (left) {
if (parseInt(left) != left) {
left = setPercentage(left,  "pWidth");
rules.push("oHtml.style.left = (" + left + ") + 'px'");
}
else
this.oExt.style.left = left + "px";
}
if (!left && right) {
if (parseInt(right) != right) {
right = setPercentage(right, "pWidth");
rules.push("oHtml.style.right = (" + right + ") + 'px'");
}
else
this.oExt.style.right = right + "px";
}
if (width) {
if (parseInt(width) != width) {
width = setPercentage(width, "pWidth");
rules.push("oHtml.style.width = ("
+ width + " - " + hordiff + ") + 'px'");
}
else
this.oExt.style.width = (width - hordiff) + "px";
}
if (right != null && left != null) {
rules.push("oHtml.style.width = (pWidth - (" + right
+ ") - (" + left + ") - " + hordiff + ") + 'px'");
}
rule_h = (rules.length
? "try{" + rules.join(";}catch(e){};try{") + ";}catch(e){};"
: "");
}
if (updateQueue & VERTICAL) {
rules = [];
var top    = this.top || this.$anchors[0];
var bottom = this.bottom || this.$anchors[2];
var height = this.height;
if (bottom && typeof bottom == "string")
bottom = setPercentage(bottom, "pHeight");
if (top) {
if (parseInt(top) != top) {
top = setPercentage(top, "pHeight");
rules.push("oHtml.style.top = (" + top + ") + 'px'");
}
else
this.oExt.style.top = top + "px";
}
if (!top && bottom) {
if (parseInt(bottom) != bottom) {
rules.push("oHtml.style.bottom = (" + bottom + ") + 'px'");
}
else
this.oExt.style.bottom = bottom + "px";
}
if (height) {
if (parseInt(height) != height) {
height = setPercentage(height, "pHeight");
rules.push("oHtml.style.height = (" + height + " - " + verdiff + ") + 'px'");
}
else
this.oExt.style.height = (height - verdiff) + "px";
}
if (bottom != null && top != null) {
rules.push("oHtml.style.height = (pHeight - (" + bottom +
") - (" + top + ") - " + verdiff + ") + 'px'");
}
rule_v = (rules.length
? "try{" + rules.join(";}catch(e){};try{") + ";}catch(e){};"
: "");
}
if (rule_v || rule_h) {
l.setRules(this.pHtmlNode, this.uniqueId + "_anchors",
rule_header + "\n" + rule_v + "\n" + rule_h, true);
}
else {
l.removeRule(this.pHtmlNode, this.uniqueId + "_anchors");
}
updateQueue = 0;
disabled = false;
};
this.$addJmlLoader(function(){
if (updateQueue)
this.$updateLayout();
});
this.$jmlDestroyers.push(function(){
this.disableAnchoring();
});
};
var __MULTIBINDING__ = 1 << 7;
jpf.MultiLevelBinding = function(jmlNode){
this.uniqueId = jpf.all.push(this) - 1;
this.nodeFunc = jpf.NODE_HIDDEN;
this.tagName  = "MultiBinding";
this.name     = jmlNode.name + "_multibinding";
this.$propHandlers = {}; 
this.$domHandlers  = {
"remove"      : [],
"insert"      : [],
"reparent"    : [],
"removechild" : []
};
this.$booleanProperties = {};
this.$supportedProperties = [];
jmlNode.$regbase = jmlNode.$regbase | __MULTIBINDING__;
jpf.makeClass(this);
this.inherit(jpf.DataBinding); 
this.getActionTracker = function(ignoreMe){
return jmlNode.getActionTracker(ignoreMe);
};
this.getHost = function(){
return jmlNode;
};
this.changeSelection = function(list){
var i, k, addList, removeList, xmlNode,
selNodes      = this.getSelectionNodes(),
traverseNodes = jmlNode.getTraverseNodes();
for (removeList = [], i = 0; i < selNodes.length; i++) {
for (k = 0; k < traverseNodes.length; k++) {
xmlNode = null;
if (this.compareNodes(selNodes[i], traverseNodes[k])) {
xmlNode = traverseNodes[k];
break;
}
}
if (!xmlNode || !list.contains(xmlNode)) 
removeList.push(selNodes[i]);
}
for (addList = [], i = 0; i < list.length; i++) {
var found = false;
for (k = 0; k < selNodes.length; k++) {
if (this.compareNodes(selNodes[k], list[i])) {
found = true;
break;
}
}
if (!found) 
addList.push(mlNode.createSelectionNode(list[i]));
}
this.executeAction("addRemoveNodes", [this.xmlRoot, addList, removeList],
"changeselection", jmlNode.selected);
};
this.change = function(value){
if (this.errBox && this.errBox.visible && this.isValid())
this.clearError();
if (!this.createModel && !this.xmlRoot) { 
if (this.dispatchEvent("beforechange", {value : value}) === false)
return;
this.setProperty("value", value);
return this.dispatchEvent("afterchange", {value : value});
}
this.executeActionByRuleSet("change", this.mainBind, this.xmlRoot, value);
};
if (jmlNode.hasFeature(__VALIDATION__)) {
this.addEventListener("beforechange", function(){
jmlNode.dispatchEvent("beforechange")
});
this.addEventListener("afterchange", function(){
jmlNode.dispatchEvent("afterchange")
});
}
this.clear = function(nomsg, do_event){
this.documentId = this.xmlRoot = this.cacheID = subTreeCacheContext = null;
if (jmlNode.$showSelection) 
jmlNode.$showSelection("");
};
this.disable = function(){
jmlNode.disable();
this.disabled = true
};
this.enable = function(){
jmlNode.enable();
this.disabled = false
};
this.$xmlUpdate = function(action, xmlNode, listenNode, UndoObj){
if (UndoObj) 
UndoObj.xmlNode = this.xmlRoot;
this.$updateSelection();
if (jmlNode["default"] && !jmlNode.getValue())
jmlNode.setValue(jmlNode["default"]);
this.dispatchEvent("xmlupdate", {
action    : action,
xmlNode   : xmlNode,
listenNode: listenNode
});
};
this.$load = function(XMLRoot){
jpf.xmldb.addNodeListener(XMLRoot, this);
this.$updateSelection();
if (jmlNode["default"] && !jmlNode.getValue())
jmlNode.setValue(jmlNode["default"]);
if (!this.createModel && this.disabled != jmlNode.disabled)
jmlNode.setProperty("disabled", this.disabled);
};
this.$updateSelection = function(){
if (!jmlNode.xmlRoot || !mlNode.xmlRoot) 
return;
var i, k, xmlNode;
if (jmlNode.multiselect) {
var selNodes      = this.getSelectionNodes();
var traverseNodes = jmlNode.getTraverseNodes();
for (i = 0; i < selNodes.length; i++) {
for (k = 0; k < traverseNodes.length; k++) {
xmlNode = null;
if (this.compareNodes(selNodes[i], traverseNodes[k])) {
xmlNode = traverseNodes[k];
break;
}
}
if (xmlNode && !jmlNode.isSelected(xmlNode)) 
jmlNode.select(xmlNode, null, null, null, null, true);
}
var jSelNodes = jmlNode.getSelection();
for (i = 0; i < jSelNodes.length; i++) {
for (k = 0; k < selNodes.length; k++) {
xmlNode = false;
if (this.compareNodes(selNodes[k], jSelNodes[i])) {
xmlNode = true;
break;
}
}
if (!xmlNode) 
jmlNode.select(jSelNodes[i], null, null, null, null, true);
}
}
else {
if (!jmlNode.xmlRoot) {
if (jmlNode.$showSelection) 
jmlNode.$showSelection();
return;
}
xmlNode = jmlNode.findXmlNodeByValue(this.applyRuleSetOnNode(this.mainBind, this.xmlRoot));
if (xmlNode) {
if (jmlNode.$showSelection) 
jmlNode.$showSelection(jmlNode.applyRuleSetOnNode("caption", xmlNode));
if (jmlNode.selected != xmlNode) {
jmlNode.select(xmlNode, null, null, null, null, true);
jmlNode.dispatchEvent("updateselect");
jmlNode.setConnections(xmlNode);
}
}
else if (jmlNode.clearOnNoSelection) 
jmlNode.clearSelection(null, true);
}
};
this.getSelectionNodes = function(){
return this.xmlRoot 
? this.xmlRoot.selectNodes(jmlNode.$jml.getAttribute("ref"))
: [];
};
this.getSelectionValue = function(xmlNode){
return jpf.getXmlValue(xmlNode, "text()")
};
this.getSelectionNodeByValue = function(value, nodes){
if (!nodes) 
nodes = this.getSelectionNodes();
for (var i = 0; i < nodes.length; i++) {
if (this.getSelectionValue(nodes[i]) == value) 
return nodes[i];
}
return false;
};
this.mode  = "default";
this.xpath = "text()";
this.createSelectionNode = function(xmlNode){
if (this.mode == "copy") {
return jpf.xmldb.clearConnections(xmlNode.cloneNode(true));
}
else if (this.xmlRoot) {
var value   = jmlNode.applyRuleSetOnNode(jmlNode.mainBind, xmlNode);
var selNode = this.xmlRoot.ownerDocument.createElement(jmlNode.$jml.getAttribute("ref"));
jpf.xmldb.createNodeFromXpath(selNode, this.xpath);
jpf.xmldb.setNodeValue(selNode.selectSingleNode(this.xpath), value);
return selNode;
}
};
this.compareNodes = function(selNode, traverseNode){
if (this.mode == "copy") {
return jmlNode.applyRuleSetOnNode(jmlNode.mainBind, traverseNode)
== jmlNode.applyRuleSetOnNode(jmlNode.mainBind, selNode);
}
else {
return jmlNode.applyRuleSetOnNode(jmlNode.mainBind, traverseNode)
== this.getSelectionValue(selNode);
}
};
var mlNode = this;
jmlNode.addEventListener("afterselect", function(e){
if (!mlNode.xmlRoot && (!this.createModel || !mlNode.$model)) {
if (this.value)
mlNode.change(this.value);
return;
}
if (this.multiselect)
mlNode.changeSelection(e.list);
else
mlNode.change(this.applyRuleSetOnNode(this.mainBind, e.xmlNode));
});
jmlNode.addEventListener("afterload", function(){
if (this.multiselect) {
}
else {
var xmlNode = this.findXmlNodeByValue(mlNode.applyRuleSetOnNode(
mlNode.mainBind, mlNode.xmlRoot));
if (xmlNode) {
if (jmlNode.$showSelection) 
jmlNode.$showSelection(jmlNode.applyRuleSetOnNode("caption", xmlNode));
jmlNode.select(xmlNode, null, null, null, null, true);
jmlNode.setConnections(xmlNode);
}
else if (jmlNode.clearOnNoSelection) {
xmlNode = mlNode.getNodeFromRule(mlNode.mainBind,
mlNode.xmlRoot, null, null, true);
jpf.xmldb.setNodeValue(xmlNode, "");
if (this.$updateOtherBindings) 
this.$updateOtherBindings();
if (this.$showSelection) 
this.$showSelection();
}
}
});
jmlNode.addEventListener("afterdeselect", function(){
if (!mlNode.xmlRoot) 
return;
if (this.multiselect) {
}
else
if (jmlNode.clearOnNoSelection) {
this.$updateOtherBindings();
jpf.xmldb.setNodeValue(jpf.xmldb.createNodeFromXpath(mlNode.xmlRoot,
mlNode.bindingRules[mlNode.mainBind][0].getAttribute("select")),
"", true);
}
});
};
var __DRAGDROP__ = 1 << 5;
jpf.offline = {
onLine : true
}
jpf.auth = {
services   : {},
cache      : {},
retry      : true,
queue      : [],
loggedIn   : false,
needsLogin : false,
autoStart  : true,
inProcess  : 0,
init : function(jml){
jpf.makeClass(this);
this.inited = true;
if (!jml)
return;
this.$jml   = jml;
if (jml.getAttribute("login")) {
this.services["default"] = jml;
this.needsLogin          = true;
}
if (jml.getAttribute("retry"))
this.retry = jpf.isTrue(jml.getAttribute("retry"));
if (jml.getAttribute("autostart"))
this.autoStart = jpf.isTrue(jml.getAttribute("autostart"));
var loginWindow  = jml.getAttribute("window");
var waitingState = jml.getAttribute("waiting-state");
var loginState   = jml.getAttribute("login-state");
var failState    = jml.getAttribute("fail-state");
var errorState   = jml.getAttribute("error-state");
var logoutState  = jml.getAttribute("logout-state");
var modelLogin   = jml.getAttribute("model");
if (loginWindow || loginState || failState || logoutState) {
this.addEventListener("authrequired", function(){
if (loginWindow) {
var win = self[loginWindow];
if (win) {
win.show();
return false;
}
}
});
this.addEventListener("beforelogin", function(){
if (waitingState) {
var state = self[waitingState];
if (state) state.activate();
}
});
function failFunction(e){
var st = (e.state == jpf.TIMEOUT
? errorState
: failState) || failState
if (st) {
var state = self[st];
if (state) {
state.activate();
return false;
}
}
}
this.addEventListener("loginfail", failFunction);
this.addEventListener("logoutfail", failFunction);
this.addEventListener("logoutsuccess", function(){
if (logoutState) {
var state = self[logoutState];
if (state) state.activate();
}
});
this.addEventListener("loginsuccess", function(e){
if (loginWindow) {
var win = self[loginWindow];
if (win) win.hide();
}
if (loginState) {
var state = self[loginState];
if (state) state.activate();
}
if (e.data && modelLogin) {
var model = jpf.nameserver.get("model", modelLogin);
if (model) model.load(e.data);
}
});
}
var i, nodes = jml.childNodes;
for (i = 0; i < nodes.length; i++) {
if(nodes[i].nodeType != 1)
continue;
this.services[nodes[i].getAttribute("name")] = nodes[i];
this.needsLogin = true;
}
var attr = jml.attributes;
for (i = 0; i < attr.length; i++) {
if (attr[i].nodeName.substr(0,2) == "on")
this.addEventListener(attr[i].nodeName,
new Function(attr[i].nodeValue));
}
if (this.autoStart) {
jpf.addEventListener("load", function(){
jpf.auth.authRequired();
});
}
},
login : function(username, password, callback, options){
if (!options) options = {};
options.username = username;
options.password = password;
if (this.dispatchEvent("beforelogin", options) === false)
return false;
this.inProcess = 1; 
var pos = 0, len = 0;
var doneCallback = function (){
if (len != ++pos)
return;
jpf.auth.inProcess = 0; 
jpf.auth.loggedIn  = true;
jpf.auth.clearQueue();
if (callback)
callback();
}
if (!options.service) {
var s = options.services || this.services;
for (var name in s) {
len++;
this.$do(name, options, "in", null, doneCallback);
}
}
else if (options.service) {
len = 1;
this.$do(options.service, options, "in", null, doneCallback);
}
},
relogin : function(){
if (this.dispatchEvent("beforerelogin") === false)
return false;
var pos = 0, len = 0;
var doneCallback = function (){
if (len != ++pos)
return;
jpf.auth.inProcess = 0; 
jpf.auth.loggedIn  = true;
jpf.auth.clearQueue();
}
for (var name in this.services) {
if (!this.cache[name])
return false;
len++;
this.$do(name, this.cache[name], "in", true, doneCallback);
}
return true;
},
$do : function(service, options, type, isRelogin, callback){
var xmlNode = this.services[service];
var _self   = options.userdata = this;
jpf.saveData(xmlNode.getAttribute("log" + type), null, options,
function(data, state, extra){
if (state == jpf.TIMEOUT && extra.retries < jpf.maxHttpRetries)
return extra.tpModule.retry(extra.id);
var result = _self.dispatchEvent("log" + type + "check",
jpf.extend({
state   : state,
data    : data,
bubbles : true
}, extra));
var loginFailed = typeof result == "boolean"
? !result
: !(state == jpf.SUCCESS || type == "out" && extra.http.status == 401);
if (loginFailed) {
jpf.auth.inProcess = 0; 
if (isRelogin) 
return _self.authRequired();
var commError = new Error(jpf.formatErrorString(0, null,
"Logging " + type, "Error logging in: " + extra.message));
if (_self.dispatchEvent("log" + type + "fail", jpf.extend({
error   : commError,
state   : state,
bubbles : true
}, extra)) !== false)
throw commError; 
return;
}
if (type == "in") {
if (!isRelogin && _self.retry) {
var cacheItem = {};
for (var prop in options) {
if ("object|array".indexOf(typeof options[prop]) == -1)
cacheItem[prop] = options[prop];
}
_self.cache[service || "default"] = cacheItem;
}
}
else {
if (_self.cache[service || "default"])
_self.cache[service || "default"] = null;
jpf.auth.authRequired();
}
if (callback)
callback();
_self.dispatchEvent("log" + type + "success", jpf.extend({
state   : state,
data    : data,
bubbles : true
}, extra));
});
},
clearQueue : function(){
if (!this.loggedIn) 
return;
var queue = this.queue.slice();
this.queue.length = 0;
for (var i = 0; i < queue.length; i++) {
var qItem = queue[i];
if (!this.loggedIn) {
this.queue.push(qItem);
continue;
}
if (qItem.retry)
qItem.retry.call(qItem.object);
else if (qItem.id)
qItem.tpModule.retry(qItem.id);
}
if (this.queue.length)
this.clearQueue();
},
logout : function(callback, options){
if (!options) options = {};
if (this.dispatchEvent("beforelogout", options) === false)
return;
this.loggedIn = false;
if (!options.service) {
for (var name in this.services) {
this.$do(name, options, "out", null, callback);
}
}
else if (options.service)
this.$do(options.service, options, "out", null, callback);
},
authRequired : function(options, forceNoRetry){
if (!this.inited)
this.init();
if (options && options.userdata == this)
return;
if (this.loggedIn && !forceNoRetry && this.retry && this.relogin()) {
var result = false;
}
else if (this.inProcess != 1) { 
var result = this.dispatchEvent("authrequired", jpf.extend({
bubbles : true
}, options));
}
this.loggedIn = false;
if (result === false) {
if (options) 
this.queue.push(options);
return true; 
}
}
};
jpf.uirecorder = {
actionStack : [],
playStack   : [],
isPlaying   : false,
isRecording : false,
inited      : false,
init : function() {
if (jpf.uirecorder.inited)
return;
jpf.uirecorder.inited = true;
document.documentElement.onselect = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onselect",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onchange = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onchange",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onsubmit = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onsubmit",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onreset = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onreset",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onfocus = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onfocus",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onblur = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onblur",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onclick = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onclick",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.ondblclick = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "ondblclick",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onmousedown = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onmousedown",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onmouseup = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onmouseup",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onmousemove = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onmousemove",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onmouseover = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onmouseover",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onmouseout = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onmouseout",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onkeyup = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onkeyup",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onkeydown = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onkeydown",
e.srcElement || e.target, jpf.extend({}, e)]);
}
document.documentElement.onkeypress = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([new Date().getTime(), "onkeypress",
e.srcElement || e.target, jpf.extend({}, e)]);
}
var mEvents = ["DOMSubtreeModified", "DOMNodeInserted", "DOMNodeRemoved", "DOMNodeRemovedFromDocument",
"DOMNodeInsertedIntoDocument", "DOMAttrModified", "DOMCharacterDataModified", "DOMActivate"];
if(document.addEventListener) {
document.addEventListener("DOMMouseScroll", function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([
new Date().getTime(),
"DOMMouseScroll",
e.target,
jpf.extend({}, jpf.uirecorder.createMouseWheelEvent(e))
]);
}, false);
}
else {
document.onmousewheel = function(e) {
if (jpf.uirecorder.isPlaying || !jpf.uirecorder.isRecording)
return;
e = e || event;
jpf.uirecorder.actionStack.push([
new Date().getTime(),
"onmousewheel",
e.srcElement,
jpf.extend({}, jpf.uirecorder.createMouseWheelEvent(e))
]);
};
}
},
createMouseWheelEvent : function(e) {
var delta = null;
if (e.wheelDelta) {
delta = e.wheelDelta / 120;
if (jpf.isOpera)
delta *= -1;
}
else if (e.detail)
delta = -e.detail / 3;
return {
type : jpf.isGecko ? "DOMMouseScroll" : (jpf.isIE ? "mousewheel" : "DOMMouseScroll"),
delta : delta
}
},
record : function() {
jpf.uirecorder.isRecording = true;
jpf.uirecorder.init();
},
play : function() {
jpf.uirecorder.isRecording = false;
jpf.uirecorder.isPlaying   = true;
jpf.uirecorder.playStack   = jpf.uirecorder.actionStack.slice(0);
if (jpf.uirecorder.playStack.length)
playFrame();
},
stop : function() {
jpf.uirecorder.isRecording = false;
jpf.uirecorder.isPlaying   = false;
},
reset : function() {
jpf.uirecorder.isRecording = false;
jpf.uirecorder.isPlaying   = false;
jpf.uirecorder.playStack   = [];
jpf.uirecorder.actionStack = [];
}
};
var timeout;
function playFrame() {
var frame = jpf.uirecorder.playStack.shift();
if(!frame || !jpf.uirecorder.isPlaying)
return;
var lastTime = frame[0];
var simulate = false;
var src = frame[3], e;
if (jpf.isIE) {
e = document.createEventObject();
for (prop in frame[3]) {
if (frame[3][prop]) {
e[prop] = frame[3][prop];
}
}
e.target = frame[2];
switch (src.type) {
case "mousewheel":
fireScroll(frame);
break;
default:
frame[2].fireEvent(frame[1], e);
break;
}
}
else {
switch(src.type) {
case "mousemove":
case "mouseup":
case "mousedown":
case "click":
case "dblclick":
case "mouseover":
case "mouseout":
e = document.createEvent("MouseEvents");
e.initMouseEvent(src.type, src.bubbles, src.cancelable, src.view, src.detail, src.screenX,
src.screenY, src.clientX, src.clientY, src.ctrlKey, src.altKey,
src.shiftKey, src.metaKey, src.button, src.relatedTarget
);
jpf.event.layerX = src.layerX
jpf.event.layerY = src.layerY
break;
case "keyup":
case "keydown":
case "keypress":
e = document.createEvent("KeyboardEvent");
e.initKeyEvent(src.type, src.bubbles, true, window, 
src.ctrlKey, src.altKey, src.shiftKey, src.metaKey, 
src.keyCode, src.charCode); 
break;
case "select":
case "change":
case "submit":
case "reset":
e = document.createEvent("HTMLEvents");
e.initEvent(src.type, src.bubbles, src.cancelable);
break;
case "DOMActivate":
case "resize":
case "focus":
case "blur":
e = document.createEvent("UIEvents");
e.initUIEvent(src.type, src.bubbles, src.cancelable, e.view, e.detail);
break;
case "DOMMouseScroll": 
fireScroll(frame);
simulate = true;
break;
default:
jpf.console.info("default: " + src.type);
simulate = true;
break;
}
if (!simulate) {
frame[2].dispatchEvent(e);
}
}
if (jpf.uirecorder.playStack.length && jpf.uirecorder.isPlaying) {
timeout = setTimeout(function() {
playFrame();
}, jpf.uirecorder.playStack[0][0] - lastTime);
}
else {
jpf.uirecorder.stop();
clearInterval(timeout);
}
};
function fireScroll(frame) {
var el = frame[2];
while (el != document.body && el.scrollHeight == el.offsetHeight) {
el = el.parentNode || el.parentElement;
}
el.scrollTop = el.scrollTop - (jpf.isGecko
? 39
: (jpf.isChrome
? 120
: (jpf.isIE
? Math.round(el.offsetHeight / 6.73)
: 20))) * frame[3].delta;
}
jpf.layout = {
timer : null,
qlist : {},
dlist : [],
queue : function(oHtml, obj, compile){
if (this.qlist[oHtml.getAttribute("id")]) {
if (obj)
this.qlist[oHtml.getAttribute("id")][2].push(obj);
return;
}
this.qlist[oHtml.getAttribute("id")] = [oHtml, compile, [obj]];
if(!this.timer)
this.timer = setTimeout("jpf.layout.processQueue()");
},
processQueue : function(){
clearTimeout(this.timer);
this.timer = null;
var i, id, l, qItem, list;
for (i = 0; i < this.dlist.length; i++) {
if (this.dlist[i].hidden)
this.dlist[i].hide();
else
this.dlist[i].show();
}
for (id in this.qlist) {
qItem = this.qlist[id];
if (qItem[1])
jpf.layout.compileAlignment(qItem[1]);
list = qItem[2];
for (i = 0, l = list.length; i < l; i++) {
if (list[i])
list[i].$updateLayout();
}
jpf.layout.activateRules(qItem[0]);
}
if (jpf.hasSingleRszEvent)
jpf.layout.forceResize();
this.qlist = {};
this.dlist = [];
},
rules     : {},
onresize  : {},
getHtmlId : function(oHtml){
return oHtml.getAttribute ? oHtml.getAttribute("id") : 1;
},
setRules : function(oHtml, id, rules, overwrite){
if (!this.getHtmlId(oHtml))
jpf.setUniqueHtmlId(oHtml);
if (!this.rules[this.getHtmlId(oHtml)])
this.rules[this.getHtmlId(oHtml)] = {};
var ruleset = this.rules[this.getHtmlId(oHtml)][id];
if (!overwrite && ruleset) {
this.rules[this.getHtmlId(oHtml)][id] = rules + "\n" + ruleset;
}
else
this.rules[this.getHtmlId(oHtml)][id] = rules;
},
getRules : function(oHtml, id){
return id
? this.rules[this.getHtmlId(oHtml)][id]
: this.rules[this.getHtmlId(oHtml)];
},
removeRule : function(oHtml, id){
if (!this.rules[this.getHtmlId(oHtml)])
return;
var ret = this.rules[this.getHtmlId(oHtml)][id] ||  false;
delete this.rules[this.getHtmlId(oHtml)][id];
var prop;
for (prop in this.rules[this.getHtmlId(oHtml)]) {
}
if (!prop)
delete this.rules[this.getHtmlId(oHtml)]
return ret;
},
activateRules : function(oHtml, no_exec){
if (!oHtml) { 
var prop, obj;
for(prop in this.rules) {
obj = document.getElementById(prop);
if (!obj || obj.onresize) 
continue;
this.activateRules(obj);
}
if (jpf.hasSingleRszEvent && window.onresize)
window.onresize();
return;
}
var rsz, id, rule, rules, strRules = [];
if (!jpf.hasSingleRszEvent) {
rules = this.rules[this.getHtmlId(oHtml)];
if (!rules){
oHtml.onresize = null;
return false;
}
for (id in rules) { 
if (typeof rules[id] != "string")
continue;
strRules.push(rules[id]);
}
rsz = jpf.needsCssPx
? new Function(strRules.join("\n"))
: new Function(strRules.join("\n").replace(/ \+ 'px'|try\{\}catch\(e\)\{\}\n/g,""))
oHtml.onresize = rsz;
if (!no_exec)
rsz();
}
else {
var htmlId = this.getHtmlId(oHtml);
rules = this.rules[htmlId];
if (!rules){
return false;
}
for (id in rules) { 
if (typeof rules[id] != "string")
continue;
strRules.push(rules[id]);
}
var p = oHtml.parentNode;
while (p && p.nodeType == 1 && !this.onresize[p.getAttribute("id")]) {
p = p.parentNode;
}
var f = new Function(strRules.join("\n"));
if (this.onresize[htmlId])
f.children = this.onresize[htmlId].children;
if (p && p.nodeType == 1) {
var x = this.onresize[p.getAttribute("id")];
(x.children || (x.children = {}))[htmlId] = f;
}
else this.onresize[htmlId] = f;
if (!no_exec)
f();
if (!window.onresize) {
var rsz = function(f){
var c = [];
for (var name in f)
c.unshift(f[name]);
for (var i = 0; i < c.length; i++){
c[i]();
if (c[i].children) {
rsz(c[i].children);
}
}
}
window.onresize = function(){
rsz(jpf.layout.onresize);
}
}
}
},
forceResize : function(oHtml){
if (jpf.hasSingleRszEvent)
return window.onresize && window.onresize();
var rsz = oHtml.onresize;
if (rsz)
rsz();
},
paused : {},
pause  : function(oHtml, replaceFunc){
if (jpf.hasSingleRszEvent) {
var htmlId = this.getHtmlId(oHtml);
this.paused[htmlId] = this.onresize[htmlId] || true;
if (replaceFunc) {
this.onresize[htmlId] = replaceFunc;
this.onresize[htmlId].children = this.paused[htmlId].children;
replaceFunc();
}
else
delete this.onresize[htmlId];
}
else {
this.paused[this.getHtmlId(oHtml)] = oHtml.onresize || true;
if (replaceFunc) {
oHtml.onresize = replaceFunc;
replaceFunc();
}
else
oHtml.onresize = null;
}
},
play : function(oHtml){
if (!this.paused[this.getHtmlId(oHtml)])
return;
if (jpf.hasSingleRszEvent) {
var htmlId = this.getHtmlId(oHtml);
var oldFunc = this.paused[htmlId];
if (typeof oldFunc == "function") {
this.onresize[htmlId] = oldFunc;
}
else
delete this.onresize[htmlId];
if (window.onresize)
window.onresize();
this.paused[this.getHtmlId(oHtml)] = null;
}
else {
var oldFunc = this.paused[this.getHtmlId(oHtml)];
if (typeof oldFunc == "function") {
oHtml.onresize = oldFunc;
oldFunc();
}
else
oHtml.onresize = null;
this.paused[this.getHtmlId(oHtml)] = null;
}
}
};
jpf.formatXml = function(strXml){
if (!strXml) return "";
strXml = strXml.trim();
var lines = strXml.split("\n");
for (var i = 0; i < lines.length; i++)
lines[i] = lines[i].trim();
lines = lines.join("\n").replace(/\>\n/g, ">").replace(/\>/g, ">\n")
.replace(/\n\</g, "<").replace(/\</g, "\n<").split("\n");
lines.removeIndex(0);
lines.removeIndex(lines.length);
for (var depth = 0, i = 0; i < lines.length; i++)
lines[i] = "\t".repeat((lines[i].match(/^\s*\<\//)
? --depth
: (lines[i].match(/^\s*\<[^\?][^>]+[^\/]\>/) ? depth++ : depth))) + lines[i];
return lines.join("\n");
};
jpf.highlightXml = function(str){
return str.replace(/^[\r\n]/g,"").replace(/</g, "_@A@_")
.replace(/>/g, "_@B@_")
.replace(/(\s[\w-]+)(\s*=\s*)("[^"]*")/g, '<span style="color:#e61414">$1</span>$2<span style="color:black">$3</span>')
.replace(/(\s[\w-]+)(\s*=\s*)('[^']*')/g, "<span style='color:#e61414'>$1</span>$2<span style='color:black'>$3</span>")
.replace(/\t/g, "&nbsp;&nbsp;&nbsp;")
.replace(/\n/g, "<br />")
.replace(/_@B@_/g, "<span style='color:#0866ab'>&gt;</span>")
.replace(/_@A@_([\-\!\[\\/\w:\.]+)?/g, "<span style='color:#0866ab'>&lt;$1</span>");
}
jpf.highlightCode = function(strCode){
return strCode.replace(/^[\r\n]/g,"").replace(/</g, "_@A@_")
.replace(/>/g, "_@B@_")
.replace(/((?:\s|^)[\w-]+)(\s*=\s*)("[^"]*")/g, '<span style="color:red">$1</span>$2<span style="color:black">$3</span>')
.replace(/((?:\s|^)[\w-]+)(\s*=\s*)('[^']*')/g, "<span style='color:red'>$1</span>$2<span style='color:black'>$3</span>")
.replace(/(_@A@_[\s\S]*?_@B@_|<[\s\S]*?>)|(\/\/.*)$|("(?:[^"]+|\\.)*")|('(?:[^']+|\\.)*')|(\W)(break|continue|do|for|import|new|this|void|case|default|else|function|in|return|typeof|while|comment|delete|export|if|label|switch|var|with|abstract|implements|protected|boolean|instanceOf|public|byte|int|short|char|interface|static|double|long|synchronized|false|native|throws|final|null|transient|float|package|true|goto|private|catch|enum|throw|class|extends|try|const|finally|debugger|super)(\W)|(\W)(\w+)(\s*\()/gm,
function(m, tag, co, str1, str2, nw, kw, nw2, fW, f, fws) {
if (tag) return tag;
else if (f)
return fW + '<span style="color:#ff8000">' + f + '</span>' + fws;
else if (co)
return '<span style="color:green">' + co + '</span>';
else if (str1 || str2)
return '<span style="color:#808080">' + (str1 || str2) + '</span>';
else if (nw)
return nw + '<span style="color:#127ac6">' + kw + '</span>' + nw2;
})
.replace(/_@A@_(!--[\s\S]*?--)_@B@_/g, '<span style="color:green">&lt;$1&gt;</span>')
.replace(/\t/g, "&nbsp;&nbsp;&nbsp;")
.replace(/\n/g, "<br />")
.replace(/_@B@_/g, "<span style='color:#127ac6'>&gt;</span>")
.replace(/_@A@_([\-\!\[\\/\w:\.]+)?/g, "<span style='color:#127ac6'>&lt;$1</span>")
}
jpf.highlightCode2 = function(strCode){
var comment=[];
return strCode
.replace(/(\/\*[\s\S]*?\*\/|\/\/.*)/g, function(a){ comment.push(a); return '###n'+(comment.length-1)+'###';})        
.replace(/(\<)|(\>)/g,function(n,a,b){ return "<span stylecolorwhite>"+(a?'@lt@':'@gt@')+"</span>"})
.replace(/(\'.*?\'|\".*?\")/g, "<span stylecolorgray>$1</span>")
.replace(/(\W)-?([\d\.]+)(\W)/g, "$1<span stylecolor#127ac6>$2</span>$3")
.replace(/([\|\&\=\;\,\:\?\+\*\-]+)/g, "<span stylecolorwhite>$1</span>")
.replace(/(\W)(break|continue|do|for|import|new|this|void|case|default|else|function|in|return|typeof|while|comment|delete|export|if|label|switch|var|with|abstract|implements|protected|boolean|instanceOf|public|byte|int|short|char|interface|static|double|long|synchronized|false|native|throws|final|null|transient|float|package|true|goto|private|catch|enum|throw|class|extends|try|const|finally|debugger|super)(\W)/g,
"$1<span stylecolorgreen>$2</span>$3")
.replace(/([\(\)\{\}\[\]])/g, "<span stylecoloryellow>$1</span>")
.replace(/###n(\d+)###/g,function(a,b){ return "<span stylecolorpurple>"+comment[b]+"</span>"; } )
.replace(/stylecolor(.*?)\>/g,"style='color:$1'>")
.replace(/@(.*?)@/g,"&$1;");
}
jpf.formatJS = function(strJs){
var d = 0, r = 0;
var comment=[];
return strJs
.replace(/(\/\*[\s\S]*?\*\/|\/\/.*)/g, function(a){ comment.push(a); return '###n'+(comment.length-1)+'###';})    
.replace(/;+/g, ';').replace(/{;/g, '{').replace(/({)|(})|(\()|(\))|(;)/g,
function(m, co, cc, ro, rc, e){
if (co) d++;
if (cc) d--;
if (ro){ r++; return ro;}
if (rc){ r--; return rc;}
var o = '';
for (var i = 0; i < d; i++)
o += '\t';
if (co) return '{\n' + o;
if (cc) return '\n' + o + '}';
if (e) return (r>0)?e:(';\n' + o);
}).replace(/;\s*\n\s*\n/g, ';\n').replace(/}var/g, '}\nvar').replace(/([\n\s]*)###n(\d+)###[\n\s]*/g,function(a,b,c){ return b+comment[c]+b; } );
};
jpf.pasteWindow = function(str){
var win = window.open("about:blank");
win.document.write(str);
};
jpf.xmlEntityMap = {
'quot': '34', 'amp': '38', 'apos': '39', 'lt': '60', 'gt': '62',
'nbsp': '160', 'iexcl': '161', 'cent': '162', 'pound': '163', 'curren': '164',
'yen': '165', 'brvbar': '166', 'sect': '167', 'uml': '168', 'copy': '169',
'ordf': '170', 'laquo': '171', 'not': '172', 'shy': '173', 'reg': '174', 'macr': '175',
'deg': '176', 'plusmn': '177', 'sup2': '178', 'sup3': '179', 'acute': '180',
'micro': '181', 'para': '182', 'middot': '183', 'cedil': '184', 'sup1': '185',
'ordm': '186', 'raquo': '187', 'frac14': '188', 'frac12': '189', 'frac34': '190',
'iquest': '191', 'Agrave': '192', 'Aacute': '193', 'Acirc': '194', 'Atilde': '195',
'Auml': '196', 'Aring': '197', 'AElig': '198', 'Ccedil': '199', 'Egrave': '200',
'Eacute': '201', 'Ecirc': '202', 'Euml': '203', 'Igrave': '204', 'Iacute': '205',
'Icirc': '206', 'Iuml': '207', 'ETH': '208', 'Ntilde': '209', 'Ograve': '210',
'Oacute': '211', 'Ocirc': '212', 'Otilde': '213', 'Ouml': '214', 'times': '215',
'Oslash': '216', 'Ugrave': '217', 'Uacute': '218', 'Ucirc': '219', 'Uuml': '220',
'Yacute': '221', 'THORN': '222', 'szlig': '223', 'agrave': '224', 'aacute': '225',
'acirc': '226', 'atilde': '227', 'auml': '228', 'aring': '229', 'aelig': '230',
'ccedil': '231', 'egrave': '232', 'eacute': '233', 'ecirc': '234', 'euml': '235',
'igrave': '236', 'iacute': '237', 'icirc': '238', 'iuml': '239', 'eth': '240',
'ntilde': '241', 'ograve': '242', 'oacute': '243', 'ocirc': '244', 'otilde': '245',
'ouml': '246', 'divide': '247', 'oslash': '248', 'ugrave': '249', 'uacute': '250',
'ucirc': '251', 'uuml': '252', 'yacute': '253', 'thorn': '254', 'yuml': '255',
'OElig': '338', 'oelig': '339', 'Scaron': '352', 'scaron': '353', 'Yuml': '376',
'fnof': '402', 'circ': '710', 'tilde': '732', 'Alpha': '913', 'Beta': '914',
'Gamma': '915', 'Delta': '916', 'Epsilon': '917', 'Zeta': '918', 'Eta': '919',
'Theta': '920', 'Iota': '921', 'Kappa': '922', 'Lambda': '923', 'Mu': '924',
'Nu': '925', 'Xi': '926', 'Omicron': '927', 'Pi': '928', 'Rho': '929', 'Sigma': '931',
'Tau': '932', 'Upsilon': '933', 'Phi': '934', 'Chi': '935', 'Psi': '936', 'Omega': '937',
'alpha': '945', 'beta': '946', 'gamma': '947', 'delta': '948', 'epsilon': '949',
'zeta': '950', 'eta': '951', 'theta': '952', 'iota': '953', 'kappa': '954',
'lambda': '955', 'mu': '956', 'nu': '957', 'xi': '958', 'omicron': '959', 'pi': '960',
'rho': '961', 'sigmaf': '962', 'sigma': '963', 'tau': '964', 'upsilon': '965',
'phi': '966', 'chi': '967', 'psi': '968', 'omega': '969', 'thetasym': '977', 'upsih': '978',
'piv': '982', 'ensp': '8194', 'emsp': '8195', 'thinsp': '8201', 'zwnj': '8204',
'zwj': '8205', 'lrm': '8206', 'rlm': '8207', 'ndash': '8211', 'mdash': '8212',
'lsquo': '8216', 'rsquo': '8217', 'sbquo': '8218', 'ldquo': '8220', 'rdquo': '8221',
'bdquo': '8222', 'dagger': '8224', 'Dagger': '8225', 'bull': '8226', 'hellip': '8230',
'permil': '8240', 'prime': '8242', 'Prime': '8243', 'lsaquo': '8249', 'rsaquo': '8250',
'oline': '8254', 'frasl': '8260', 'euro': '8364', 'image': '8465', 'weierp': '8472',
'real': '8476', 'trade': '8482', 'alefsym': '8501', 'larr': '8592', 'uarr': '8593',
'rarr': '8594', 'darr': '8595', 'harr': '8596', 'crarr': '8629', 'lArr': '8656',
'uArr': '8657', 'rArr': '8658', 'dArr': '8659', 'hArr': '8660', 'forall': '8704',
'part': '8706', 'exist': '8707', 'empty': '8709', 'nabla': '8711', 'isin': '8712',
'notin': '8713', 'ni': '8715', 'prod': '8719', 'sum': '8721', 'minus': '8722',
'lowast': '8727', 'radic': '8730', 'prop': '8733', 'infin': '8734', 'ang': '8736',
'and': '8743', 'or': '8744', 'cap': '8745', 'cup': '8746', 'int': '8747', 'there4': '8756',
'sim': '8764', 'cong': '8773', 'asymp': '8776', 'ne': '8800', 'equiv': '8801', 'le': '8804',
'ge': '8805', 'sub': '8834', 'sup': '8835', 'nsub': '8836', 'sube': '8838',
'supe': '8839', 'oplus': '8853', 'otimes': '8855', 'perp': '8869', 'sdot': '8901',
'lceil': '8968', 'rceil': '8969', 'lfloor': '8970', 'rfloor': '8971', 'lang': '9001',
'rang': '9002', 'loz': '9674', 'spades': '9824', 'clubs': '9827', 'hearts': '9829',
'diams': '9830'
};
jpf.htmlentities = function(str){
return str.escapeHTML();
};
jpf.xmlentities = function(str) {
return str.replace(/&([a-z]+);/gi, function(a, m) {
if (jpf.xmlEntityMap[m])
return '&#' + jpf.xmlEntityMap[m] + ';';
return a;
});
};
jpf.html_entity_decode = function(str){
return (str || "").replace(/\&\#38;/g, "&").replace(/&lt;/g, "<")
.replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&nbsp;/g, " ");
};
jpf.randomGenerator = {
d: new Date(),
seed: null,
A: 48271,
M: 2147483647,
Q: null,
R: null,
oneOverM: null,
generate: function(lnr, unr) {
if (this.seed == null)
this.seed = 2345678901 + (this.d.getSeconds() * 0xFFFFFF) + (this.d.getMinutes() * 0xFFFF);
this.Q = this.M / this.A;
this.R = this.M % this.A;
this.oneOverM = 1.0 / this.M;
return Math.floor((unr - lnr + 1) * this.next() + lnr);
},
next: function() {
var hi = this.seed / this.Q;
var lo = this.seed % this.Q;
var test = this.A * lo - this.R * hi;
if (test > 0)
this.seed = test;
else
this.seed = test + this.M;
return (this.seed * this.oneOverM);
}
};
jpf.getNoCacheUrl = function(url){
return url
+ (url.indexOf("?") == -1 ? "?" : "&")
+ "nocache=" + new Date().getTime();
};
jpf.parseExpression = function(str){
if (!jpf.parseExpression.regexp.test(str))
return str;
return eval(RegExp.$1);
};
jpf.parseExpression.regexp = /^\{(.*)\}$/;
jpf.formatNumber = function(num, prefix){
var nr = parseFloat(num);
if (!nr) return num;
var str = new String(Math.round(nr * 100) / 100).replace(/(\.\d?\d?)$/, function(m1){
return m1.pad(3, "0", jpf.PAD_RIGHT);
});
if (str.indexOf(".") == -1)
str += ".00";
return prefix + str;
};
// Serialize Objects
jpf.JSONSerialize = {
object: function(o){
//XML support - NOTICE: Javeline PlatForm specific
if (o.nodeType && o.cloneNode)
return "jpf.xmldb.getXml("
+ this.string(jpf.xmldb.serializeNode(o)) + ")";
//Normal JS object support
var str = [];
for (var prop in o) {
str.push('"' + prop.replace(/(["\\])/g, '\\$1') + '": '
+ jpf.serialize(o[prop]));
}
return "{" + str.join(", ") + "}";
},
string: function(s){
s = '"' + s.replace(/(["\\])/g, '\\$1') + '"';
return s.replace(/(\n)/g, "\\n").replace(/\r/g, "");
},
number: function(i){
return i.toString();
},
"boolean": function(b){
return b.toString();
},
date: function(d){
var padd = function(s, p){
s = p + s;
return s.substring(s.length - p.length);
};
var y   = padd(d.getUTCFullYear(), "0000");
var m   = padd(d.getUTCMonth() + 1, "00");
var D   = padd(d.getUTCDate(), "00");
var h   = padd(d.getUTCHours(), "00");
var min = padd(d.getUTCMinutes(), "00");
var s   = padd(d.getUTCSeconds(), "00");
var isodate = y + m + D + "T" + h + ":" + min + ":" + s;
return '{"jsonclass":["sys.ISODate", ["' + isodate + '"]]}';
},
array: function(a){
for (var q = [], i = 0; i < a.length; i++)
q.push(jpf.serialize(a[i]));
return "[" + q.join(", ") + "]";
}
};
jpf.serialize = function(args){
if (typeof args == "function" || jpf.isNot(args))
return "null";
return jpf.JSONSerialize[args.dataType || "object"](args);
};
jpf.unserialize = function(str, secure){
if (!str) return str;
if (secure && !(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/)
.test(str.replace(/\\./g, '@').replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, '')))
return str;
return eval('(' + str + ')');
};
jpf.exec = function(str, win){
if (!str)
return str;
if (!win)
win = self;
if (jpf.hasExecScript) {
win.execScript(str);
}
else {
var head = win.document.getElementsByTagName("head")[0];
if (head) {
var script = win.document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.text = str;
head.appendChild(script);
head.removeChild(script);
} else
eval(str, win);
}
return str;
};
jpf.K = function(){};
jpf.isNull = function(value){
if (value)
return false;
return (value == null || !String(value).length);
};
jpf.isNumber = function(value){
return parseFloat(value) == value;
};
jpf.isArray = function(value) {
return Object.prototype.toString.call(value) === "[object Array]";
};
jpf.isTrue = function(c){
return (c === true || c === "true" || c === "on" || typeof c == "number" && c > 0 || c === "1");
};
jpf.isFalse = function(c){
return (c === false || c === "false" || c === "off" || c === 0 || c === "0");
};
jpf.isNot = function(c){
return (!c && typeof c != "string" && c !== 0 || (typeof c == "number" && !isFinite(c)));
};
jpf.getDirname = function(url){
return ((url || "").match(/^(.*\/)[^\/]*$/) || {})[1]; 
};
jpf.getFilename = function(url){
return ((url || "").split("?")[0].match(/(?:\/|^)([^\/]+)$/) || {})[1];
};
jpf.getAbsolutePath = function(base, url){
return !url || url.match(/^\w+\:\/\//) ? url : base + url;
};
jpf.removePathContext = function(base, url){
if (!url)  return "";
if (url.indexOf(base) > -1)
return url.substr(base.length);
return url;
};
jpf.cancelBubble = function(e, o){
e.cancelBubble = true;
if (o.$focussable && !o.disabled)
jpf.window.$focus(o);
};
jpf.getXmlValue = function (xmlNode, xpath){
if (!xmlNode) return "";
xmlNode = xmlNode.selectSingleNode(xpath);
if (xmlNode && xmlNode.nodeType == 1)
xmlNode = xmlNode.firstChild;
return xmlNode ? xmlNode.nodeValue : "";
};
jpf.getXmlValues = function(xmlNode, xpath){
var out = [];
if (!xmlNode) return out;
var nodes = xmlNode.selectNodes(xpath);
if (!nodes.length) return out;
for (var i = 0; i < nodes.length; i++) {
var n = nodes[i];
if (n.nodeType == 1)
n = n.firstChild;
out.push(n.nodeValue || "");
}
return out;
};
jpf.removeNode = function (element) {
if (!element) return;
if (!jpf.isIE || element.ownerDocument != document) {
if (element.parentNode)
element.parentNode.removeChild(element);
return;
}
var garbageBin = document.getElementById('IELeakGarbageBin');
if (!garbageBin) {
garbageBin    = document.createElement('DIV');
garbageBin.id = 'IELeakGarbageBin';
garbageBin.style.display = 'none';
document.body.appendChild(garbageBin);
}
garbageBin.appendChild(element);
garbageBin.innerHTML = '';
};
jpf.getRules = function(node){
var rules = {};
for (var w = node.firstChild; w; w = w.nextSibling){
if (w.nodeType != 1)
continue;
else {
if (!rules[w[jpf.TAGNAME]])
rules[w[jpf.TAGNAME]] = [];
rules[w[jpf.TAGNAME]].push(w);
}
}
return rules;
};
jpf.getBox = function(value, base){
if (!base) base = 0;
if (value == null || (!parseInt(value) && parseInt(value) != 0))
return [0, 0, 0, 0];
var x = value.split(" ");
for (var i = 0; i < x.length; i++)
x[i] = parseInt(x[i]) || 0;
switch (x.length) {
case 1:
x[1] = x[0];
x[2] = x[0];
x[3] = x[0];
break;
case 2:
x[2] = x[0];
x[3] = x[1];
break;
case 3:
x[3] = x[1];
break;
}
return x;
};
jpf.getNode = function(data, tree){
var nc = 0;
if (data != null) {
for (var i = 0; i < data.childNodes.length; i++) {
if (data.childNodes[i].nodeType == 1) {
if (nc == tree[0]) {
data = data.childNodes[i];
if (tree.length > 1) {
tree.shift();
data = this.getNode(data, tree);
}
return data;
}
nc++
}
}
}
return null;
};
jpf.getFirstElement = function(xmlNode){
return xmlNode.firstChild.nodeType == 1
? xmlNode.firstChild
: xmlNode.firstChild.nextSibling;
};
jpf.getLastElement = function(xmlNode){
return xmlNode.lastChild.nodeType == 1
? xmlNode.lastChild
: xmlNode.lastChild.previousSibling;
};
jpf.selectTextHtml = function(oHtml){
if (!jpf.hasMsRangeObject) return;
var r = document.selection.createRange();
try {r.moveToElementText(oHtml);} catch(e){}
r.select();
};
jpf.popup = {
cache      : {},
focusFix   : {"INPUT":1,"TEXTAREA":1,"SELECT":1},
setContent : function(cacheId, content, style, width, height){
if (!this.popup) this.init();
this.cache[cacheId] = {
content : content,
style   : style,
width   : width,
height  : height
};
content.style.position = "absolute";
content.onmousedown  = function(e) {
if (!e) e = event;
if (jpf.hasFocusBug 
&& !jpf.popup.focusFix[(e.srcElement || e.target).tagName]) {
jpf.window.$focusfix();
}
(e || event).cancelBubble = true;
};
return content.ownerDocument;
},
removeContent : function(cacheId){
this.cache[cacheId] = null;
delete this.cache[cacheId];
},
init : function(){
this.popup = {};
jpf.addEventListener("hotkey", function(e){
if (e.keyCode == "27" || e.altKey) 
jpf.popup.forceHide();
});
},
show : function(cacheId, options){
options = jpf.extend({
x            : 0,
y            : 0,
animate      : false,
ref          : null,
width        : null,
height       : null,
callback     : null,
draggable    : false,
resizable    : false,
allowTogether: false
}, options);
if (!this.popup)
this.init();
if ((!options.allowTogether || options.allowTogether != this.last) && this.last != cacheId)
this.hide();
var o = this.cache[cacheId];
o.options = options;
var popup = o.content;
if (!o.content.style.zIndex)
o.content.style.zIndex = 10000000;
if (o.content.style.display && o.content.style.display.indexOf('none') > -1)
o.content.style.display = "";
if (options.ref) {
var pos    = jpf.getAbsolutePosition(options.ref, 
o.content.offsetParent || o.content.parentNode);
var top    = (options.y || 0) + pos[1];
var p      = jpf.getOverflowParent(o.content); 
if (options.width || o.width)
popup.style.width = ((options.width || o.width) - 3) + "px";
var moveUp = false;
if (moveUp)
popup.style.top = (pos[1] - (options.height || o.height || o.content.offsetHeight)) + "px"
else
popup.style.top = top + "px";
popup.style.left = ((options.x || 0) + pos[0]) + "px";
}
if (options.animate) {
if (options.animate == "fade") {
jpf.tween.single(popup, {
type  : 'fade',
from  : 0,
to    : 1,
anim  : jpf.tween.NORMAL,
steps : jpf.isIE ? 5 : 10
});
}
else { 
var iVal, steps = 7, i = 0;
iVal = setInterval(function(){
var value = ++i * ((options.height || o.height) / steps);
popup.style.height = value + "px";
if (moveUp)
popup.style.top = (top - value - options.y) + "px";
else
popup.scrollTop = 10000;
popup.style.display = "block";
if (i >= steps) {
clearInterval(iVal)
if (options.callback)
options.callback(popup);
}
}, 10);
}
}
else {
if (options.height || o.height)
popup.style.height = (options.height || o.height) + "px";
if (options.callback)
options.callback(popup);
}
setTimeout(function(){
jpf.popup.last = cacheId;
});
if (options.draggable) {
options.id = cacheId;
this.makeDraggable(options);
}
},
hide : function(){
if (this.isDragging) return;
var o = this.cache[this.last];
if (o) {
if (o.content)
o.content.style.display = "none";
if (o.options.onclose) {
o.options.onclose(jpf.extend(o.options, {htmlNode: o.content}));
o.options.onclose = false;
}
}
},
isShowing : function(cacheId){
return this.last && this.last == cacheId 
&& this.cache[this.last]
&& this.cache[this.last].content.style.display != "none";
},
isDragging   : false,
makeDraggable: function(options) {
if (!jpf.Interactive || this.cache[options.id].draggable) 
return;
var oHtml = this.cache[options.id].content;
this.cache[options.id].draggable = true;
var o = {
$propHandlers : {},
minwidth      : 10,
minheight     : 10,
maxwidth      : 10000,
maxheight     : 10000,
dragOutline   : false,
resizeOutline : false,
draggable     : true,
resizable     : options.resizable,
oExt          : oHtml,
oDrag         : oHtml.firstChild
};
oHtml.onmousedown =
oHtml.firstChild.onmousedown = function(e){
if (!e) e = event;
if (jpf.hasFocusBug
&& !jpf.popup.focusFix[(e.srcElement || e.target).tagName]) {
jpf.window.$focusfix();
}
(e || event).cancelBubble = true;
}
jpf.inherit.call(o, jpf.Interactive);
o.$propHandlers["draggable"].call(o, true);
o.$propHandlers["resizable"].call(o, true);
},
forceHide : function(){
if (this.last && !jpf.plane.current && this.isShowing(this.last)) {
var o = jpf.lookup(this.last);
if (!o)
this.last = null;
else if (o.dispatchEvent("popuphide") !== false)
this.hide();
}
},
destroy : function(){
for (var cacheId in this.cache) {
if (this.cache[cacheId]) {
this.cache[cacheId].content.onmousedown = null;
jpf.removeNode(this.cache[cacheId].content);
this.cache[cacheId].content = null;
this.cache[cacheId] = null;
}
}
if (!this.popup) return;
}
}
if (typeof isFinite == "undefined") {
function isFinite(val){
return val + 1 != val;
}
}
Array.prototype.dataType    = "array";
Number.prototype.dataType   = "number";
Date.prototype.dataType     = "date";
Boolean.prototype.dataType  = "boolean";
String.prototype.dataType   = "string";
RegExp.prototype.dataType   = "regexp";
Function.prototype.dataType = "function";
jpf.getCgiString = function(args, multicall, mcallname){
var vars = [];
function recur(o, stack) {
if (jpf.isArray(o)) {
for (var j = 0; j < o.length; j++)
recur(o[j], stack + "%5B%5D");
} 
else if (typeof o == "object") {
for (prop in o) {
if (jpf.isSafariOld && (!o[prop] || typeof p[prop] != "object"))
continue;
if (typeof o[prop] == "function")
continue;
recur(o[prop], stack + "%5B" + encodeURIComponent(prop) + "%5D");
}
}
else
vars.push(stack + "=" + encodeURIComponent(o));
};
if (multicall) {
vars.push("func=" + mcallname);
for (var i = 0; i < args[0].length; i++)
recur(args[0][i], "f%5B" + i + "%5D");
} else {
for (prop in args) {
if (jpf.isSafariOld && (!args[prop] || typeof args[prop] == "function"))
continue;
recur(args[prop], prop);
}
}
return vars.join("&");
}
jpf.fromCgiString = function(args) {
if (!args)
return false;
var obj = {};
args = args.split("&");
for (var data, i = 0; i < args.length; i++) {
data = args[i].split("=");
data[0] = decodeURIComponent(data[0]);
var path = data[0].replace(/\]/g, "").split("[");
var spare = obj;
for (var j = 0; j < path.length; j++) {
if (spare[path[j]])
spare = spare[path[j]];
else if (path.length == j+1) {
if (path[j])
spare[path[j]] = decodeURIComponent(data[1]);
else
spare.push(decodeURIComponent(data[1]));
break; 
}
else{
spare[path[j]] = !path[j+1] ? [] : {};
spare = spare[path[j]];
}
}
}
return obj;
}
Function.prototype.extend = function() {
jpf.extend.apply(this, [this].concat(Array.prototype.slice.call(arguments)));
return this;
};
Function.prototype.bindWithEvent = function() {
var __method = this, args = Array.prototype.slice.call(arguments), 
o  = args.shift(),
ev = args.shift();
return function(event) {
if (!event) event = window.event;
return __method.apply(o, [event].concat(args)
.concat(Array.prototype.slice.call(arguments)));
}
};
Array.prototype.copy = function(){
var ar = [];
for (var i = 0, j = this.length; i < j; i++)
ar[i] = this[i] && this[i].copy ? this[i].copy() : this[i];
return ar;
};
Array.prototype.merge = function(){
for (var i = 0, k = arguments.length; i < k; i++) {
for (var j = 0, l = arguments[i].length; j < l; j++) {
this.push(arguments[i][j]);
}
}
};
Array.prototype.arrayAdd = function(){
var s = this.copy();
for (var i = 0, k = arguments.length; i < k; i++) {
for (var j = 0, l = s.length; j < l; j++) {
s[j] += arguments[i][j];
}
}
return s;
};
Array.prototype.equals = function(obj){
for (var i = 0, j = this.length; i < j; i++)
if (this[i] != obj[i])
return false;
return true;
};
Array.prototype.makeUnique = function(){
var i, length, newArr = [];
for (i = 0, length = this.length; i < length; i++)
if (newArr.indexOf(this[i]) == -1)
newArr.push(this[i]);
this.length = 0;
for (i = 0, length = newArr.length; i < length; i++)
this.push(newArr[i]);
return this;
};
Array.prototype.contains = function(obj, from){
return this.indexOf(obj, from) != -1;
};
Array.prototype.indexOf = Array.prototype.indexOf || function(obj, from){
var len = this.length;
for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++) {
if (this[i] === obj)
return i;
}
return -1;
};
Array.prototype.lastIndexOf = Array.prototype.lastIndexOf || function(obj, from) {
var len = this.length;
for (var i = (from >= len) ? len - 1 : (from < 0) ? from + len : len - 1; i >= 0; i--) {
if (this[i] === obj)
return i;
}
return -1;
};
Array.prototype.pushUnique = function(item){
if (this.indexOf(item) == -1)
this.push(item);
return this;
};
Array.prototype.search = function(){
for (var i = 0, length = arguments.length; i < length; i++) {
if (typeof this[i] != "array")
continue;
for (var j = 0; j < length; j++) {
if (this[i][j] != arguments[j])
break;
else if (j == (length - 1))
return this[i];
}
}
};
Array.prototype.each =
Array.prototype.forEach = Array.prototype.forEach || function(fn) {
for (var i = 0, l = this.length; i < l; i++)
fn.call(this, this[i], i, this);
return this;
}
Array.prototype.remove = function(obj){
for (var i = this.length - 1; i >= 0; i--) {
if (this[i] != obj)
continue;
this.splice(i, 1);
}
return this;
};
Array.prototype.removeIndex = function(i){
if (!this.length) return;
return this.splice(i, 1);
};
Array.prototype.insertIndex = function(obj, i){
this.splice(i, 0, obj);
};
Array.prototype.invert =
Array.prototype.reverse = Array.prototype.reverse || function(){
var l = this.length - 1;
for (var temp, i = 0; i < Math.ceil(0.5 * l); i++) {
temp        = this[i];
this[i]     = this[l - i]
this[l - i] = temp;
}
return this;
};
Number.prototype.toPrettyDigit = Number.prototype.toPrettyDigit || function() {
var n = this.toString();
return (n.length == 1) ? "0" + n : n;
};
Array.prototype.filter = Array.prototype.filter || function(fn, bind){
var results = [];
for (var i = 0, l = this.length; i < l; i++) {
if (fn.call(bind, this[i], i, this))
results.push(this[i]);
}
return results;
};
Array.prototype.every = Array.prototype.every || function(fn, bind){
for (var i = 0, l = this.length; i < l; i++) {
if (!fn.call(bind, this[i], i, this))
return false;
}
return true;
};
Array.prototype.map = Array.prototype.map || function(fn, bind){
var results = [];
for (var i = 0, l = this.length; i < l; i++)
results[i] = fn.call(bind, this[i], i, this);
return results;
};
Array.prototype.some = Array.prototype.some || function(fn, bind){
for (var i = 0, l = this.length; i < l; i++) {
if (fn.call(bind, this[i], i, this))
return true;
}
return false;
};
Math.hexlist  = "0123456789ABCDEF";
Math.decToHex = function(value){
var hex = this.floor(value / 16);
hex = (hex > 15 ? this.decToHex(hex) : this.hexlist.charAt(hex));
return hex + "" + this.hexlist.charAt(this.floor(value % 16));
};
Math.hexToDec = function(value){
if (!/(.)(.)/.exec(value.toUpperCase()))
return false;
return this.hexlist.indexOf(RegExp.$1) * 16 + this.hexlist.indexOf(RegExp.$2);
};
RegExp.prototype.getNativeFlags = function() {
return (this.global     ? "g" : "") +
(this.ignoreCase ? "i" : "") +
(this.multiline  ? "m" : "") +
(this.extended   ? "x" : "") +
(this.sticky     ? "y" : "");
};
RegExp.prototype.addFlags = function(flags){
return new RegExp(this.source, (flags || "") + this.getNativeFlags());
};
String.prototype.uCaseFirst = function(){
return this.substr(0, 1).toUpperCase() + this.substr(1)
};
String.prototype.trim = function(){
return this.replace(/[\s\n\r]*$/, "").replace(/^[\s\n\r]*/, "");
};
String.prototype.repeat = function(times){
return Array(times + 1).join(this);
};
String.prototype.count = function(str){
return this.split(str).length - 1;
};
String.prototype.stripTags = function() {
return this.replace(/<\/?[^>]+>/gi, '');
};
String.prototype.escape = function() {
return escape(this);
};
String.prototype.escapeHTML = function() {
var div  = document.createElement('div');
var text = document.createTextNode(this);
div.appendChild(text);
return div.innerHTML;
};
String.prototype.unescapeHTML = function() {
var div = document.createElement('div');
div.innerHTML = this.stripTags();
if (div.childNodes[0]) {
if (div.childNodes.length > 1) {
var out = [];
for (var i = 0; i < div.childNodes.length; i++)
out.push(div.childNodes[i].nodeValue);
return out.join('');
}
else
return div.childNodes[0].nodeValue;
}
return "";
};
String.prototype.truncate = function(nr, ellipsis){
return this.length >= nr
? this.substring(0, nr - (ellipsis ? 4 : 1)) + (ellipsis ? "..." : "")
: this;
};
String.prototype.pad = function(len, pad, dir) {
return dir ? (this + Array(len).join(pad)).slice(0, len)
: (Array(len).join(pad) + this).slice(-len);
};
jpf.PAD_LEFT  = false;
jpf.PAD_RIGHT = true;
String.prototype.splitSafe = function(separator, limit, bLowerCase) {
return (bLowerCase && this.toLowerCase() || this)
.replace(/(?:^\s+|\n|\s+$)/g, "")
.split(new RegExp("[\\s ]*" + separator + "[\\s ]*", "g"), limit || 999);
};
var _oldSplit = String.prototype.split;
String.prototype.appendRandomNumber = function(length) {
var source = this.toString();
for (var i = 1; i <= length; i++) {
source += jpf.randomGenerator.generate(1, 9);
}
return source;
};
String.prototype.prependRandomNumber = function(length) {
var source = this.toString();
for (var i = 1; i <= length; i++) {
source = jpf.randomGenerator.generate(1, 9) + source;
}
return source;
};
String.prototype.sprintf = function() {
var str = this.toString();
var i = 0, inx = str.indexOf('%s');
while (inx >= 0) {
var replacement = arguments[i++] || ' ';
str = str.substr(0, inx) + replacement + str.substr(inx + 2);
inx = str.indexOf('%s');
}
return str;
};
jpf.dragmode = {
modes : {},
removeMode : function(mode){
this.modes[mode] = null;
},
defineMode : function(mode, struct){
this.modes[mode] = struct;
},
setMode : function(mode){
for (var prop in this.modes[mode])
if (prop.match(/^on/))
document[prop] = this.modes[mode][prop];
this.mode = mode;
},
clear : function(){
for (var prop in this.modes[this.mode])
if (prop.match(/^on/))
document[prop] = null;
this.mode = null;
}
};
jpf.Init.run('jpf.dragmode');
jpf.namespace("nameserver", {
lookup : {},
add : function(type, item){
if (!this.lookup[type])
this.lookup[type] = [];
return this.lookup[type].push(item) - 1;
},
register : function(type, id, item){
if (!this.lookup[type])
this.lookup[type] = {};
return (this.lookup[type][id] = item);
},
get : function(type, id){
return this.lookup[type] ? this.lookup[type][id] : null;
},
getAll : function(type){
var name, arr = [];
for (name in this.lookup[type]) {
if (jpf.isSafariOld
&& (!this.lookup[type][name]
|| typeof this.lookup[type][name] != "object"))
continue;
arr.push(this.lookup[type][name]);
}
return arr;
}, 
getAllNames : function(type){
var name, arr = [];
for (name in this.lookup[type]){
if (parseInt(name) == name) continue;
arr.push(name);
}
return arr;
}
});
jpf.setStyleRule = function(name, type, value, stylesheet, win){
var rules = (win || self).document.styleSheets[stylesheet || 0][jpf.styleSheetRules];
for (var i = 0; i < rules.length; i++) {
if (rules.item(i).selectorText == name) {
rules.item(i).style[type] = value;
return true;
}
}
return false;
};
jpf.setStyleClass = function(oHtml, className, exclusion, special){
if (!oHtml || this.disabled)
return;
if (!className) className = " ";
if (exclusion)
exclusion.push(className);
else
exclusion = [className];
var re = new RegExp("(?:(^| +)" + exclusion.join("|") + "($| +))", "gi");
oHtml.className != null
? (oHtml.className = oHtml.className.replace(re, " ") + " " + className)
: oHtml.setAttribute("class", (oHtml.getAttribute("class") || "")
.replace(re, " ") + " " + className);
return oHtml;
};
jpf.importCssString = function(doc, cssString, media){
var htmlNode = doc.getElementsByTagName("head")[0];
if (jpf.canCreateStyleNode) {
var style = document.createElement("style");
style.appendChild(document.createTextNode(cssString));
htmlNode.appendChild(style);
}
else {
htmlNode.insertAdjacentHTML("beforeend", ".<style media='"
+ (media || "all") + "'>" + cssString + "</style>");
}
};
jpf.getStyleRecur = function(el, prop) {
var value = jpf.hasComputedStyle
? document.defaultView.getComputedStyle(el,'').getPropertyValue(
prop.replace(/([A-Z])/g, function(m, m1){
return "-" + m1.toLowerCase();
}))
: el.currentStyle[prop]
return ((!value || value == "transparent" || value == "inherit")
&& el.parentNode && el.parentNode.nodeType == 1)
? this.getStyleRecur(el.parentNode, prop)
: value;
};
jpf.isInRect = function(oHtml, x, y){
var pos = this.getAbsolutePosition(oHtml);
if (x < pos[0] || y < pos[1] || x > oHtml.offsetWidth + pos[0] - 10
|| y > oHtml.offsetHeight + pos[1] - 10)
return false;
return true;
};
jpf.getOverflowParent = function(o){
o = o.offsetParent;
while (o && (this.getStyle(o, "overflow") != "hidden"
|| "absolute|relative".indexOf(this.getStyle(o, "position")) == -1)) {
o = o.offsetParent;
}
return o || document.documentElement;
};
jpf.getPositionedParent = function(o){
o = o.offsetParent;
while (o && o.tagName.toLowerCase() != "body"
&& "absolute|relative".indexOf(this.getStyle(o, "position")) == -1) {
o = o.offsetParent;
}
return o || document.documentElement;
};
jpf.getAbsolutePosition = function(o, refParent, inclSelf){
var wt = inclSelf ? 0 : o.offsetLeft, ht = inclSelf ? 0 : o.offsetTop;
o = inclSelf ? o : o.offsetParent;
var z, bw, bh, foundPosRel = 0;
while (o && o != refParent) {
bw = jpf.isOpera ? 0 : this.getStyle(o, jpf.descPropJs
? "borderLeftWidth" : "border-left-width");
wt += (jpf.isIE && o.currentStyle.borderLeftStyle != "none" && bw == "medium"
? 2
: parseInt(bw) || 0) + o.offsetLeft;
bh = jpf.isOpera ? 0 : this.getStyle(o, jpf.descPropJs
? "borderTopWidth" : "border-top-width");
ht += (jpf.isIE && o.currentStyle.borderTopStyle != "none" && bh == "medium"
? 2
: parseInt(bh) || 0) + o.offsetTop;
wt -= o.scrollLeft;
ht -= o.scrollTop;
if (o.tagName.toLowerCase() == "table") {
ht -= parseInt(o.border || 0) + parseInt(o.cellSpacing || 0);
wt -= parseInt(o.border || 0) + parseInt(o.cellSpacing || 0) * 2;
}
else if (o.tagName.toLowerCase() == "tr") {
ht -= (cp = parseInt(o.parentNode.parentNode.cellSpacing));
while (o.previousSibling)
ht -= (o = o.previousSibling).offsetHeight + cp;
}
if (!o.offsetParent && o.parentNode.nodeType == 1) {
wt -= o.parentNode.scrollLeft;
ht -= o.parentNode.scrollTop;
}
o = o.offsetParent;
}
return [wt, ht];
};
jpf.plane = {
init : function(){
if (!this.plane) {
this.plane                  = document.createElement("DIV");
document.body.appendChild(this.plane);
this.plane.style.background = "url(images/spacer.gif)";
this.plane.style.position   = "absolute";
this.plane.style.zIndex     = 100000000;
this.plane.style.left       = 0;
this.plane.style.top        = 0;
}
},
lastCursor : null,
show : function(o, dontAppend, copyCursor){
this.init();
var plane    = this.plane;
this.current = o;
if (!dontAppend) {
this.lastZ = this.current.style.zIndex;
this.current.style.zIndex = 100000;
}
else {
this.plane.appendChild(o);
}
var pWidth = (plane.parentNode == document.body
? (jpf.isIE 
? document.documentElement.offsetWidth 
: window.innerWidth)
: plane.parentNode.offsetWidth);
var pHeight = (plane.parentNode == document.body
? (jpf.isIE 
? document.documentElement.offsetHeight
: window.innerHeight)
: plane.parentNode.offsetHeight);
if (copyCursor) {
if (this.lastCursor === null)
this.lastCursor = document.body.style.cursor;
document.body.style.cursor = jpf.getStyle(o, "cursor");
}
this.plane.style.display = "block";
var diff = jpf.getDiff(plane.parentNode);
this.plane.style.width  = (pWidth - diff[0]) + "px";
this.plane.style.height = (pHeight - diff[1]) + "px";
return plane;
},
hide : function(){
var isChild = jpf.xmldb.isChildOf(this.plane, document.activeElement);
if (this.lastZ) {
if (this.current.style.zIndex == 100000)
this.current.style.zIndex = this.lastZ;
this.lastZ = null;
}
if (this.current.parentNode == this.plane)
this.plane.parentNode.appendChild(this.current);
this.plane.style.display  = "none";
if (isChild) {
if (!jpf.isIE)
document.activeElement.focus();
jpf.window.focussed.$focus();
}
this.current = null;
if (this.lastCursor !== null) {
document.body.style.cursor = this.lastCursor;
this.lastCursor = null;
}
return this.plane;
}
};
jpf.runOpera = function (){
var x = new DOMParser();
XMLDocument = DOMParser.constructor;
x = null;
Node.prototype.serialize        = 
XMLDocument.prototype.serialize =
Element.prototype.serialize     = function(){
return (new XMLSerializer()).serializeToString(this);
};
Document.prototype.selectNodes     = 
XMLDocument.prototype.selectNodes  =
HTMLDocument.prototype.selectNodes = function(sExpr, contextNode){
var oResult = this.evaluate(sExpr, (contextNode ? contextNode : this),
this.createNSResolver(this.documentElement),
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var nodeList = new Array(oResult.snapshotLength);
nodeList.expr = sExpr;
for (var i = 0; i < nodeList.length; i++) 
nodeList[i] = oResult.snapshotItem(i);
return nodeList;
};
Element.prototype.selectNodes = function(sExpr){
var doc = this.ownerDocument;
if (!doc.selectSingleNode) {
doc.selectSingleNode = HTMLDocument.prototype.selectSingleNode;
doc.selectNodes = HTMLDocument.prototype.selectNodes;
}
if (doc.selectNodes) 
return doc.selectNodes(sExpr, this);
else 
throw new Error(jpf.formatErrorString(1047, null, "XPath Selection", "Method selectNodes is only supported by XML Nodes"));
};
Document.prototype.selectSingleNode     =
XMLDocument.prototype.selectSingleNode  =
HTMLDocument.prototype.selectSingleNode = function(sExpr, contextNode){
var nodeList = this.selectNodes(sExpr + "[1]", contextNode ? contextNode : null);
return nodeList.length > 0 ? nodeList[0] : null;
};
Element.prototype.selectSingleNode = function(sExpr){
var doc = this.ownerDocument;
if (!doc.selectSingleNode) {
doc.selectSingleNode = HTMLDocument.prototype.selectSingleNode;
doc.selectNodes = HTMLDocument.prototype.selectNodes;
}
if (doc.selectSingleNode) 
return doc.selectSingleNode(sExpr, this);
else 
throw new Error(jpf.formatErrorString(1048, null, "XPath Selection", "Method selectSingleNode is only supported by XML Nodes. \nInfo : " + e));
};
if (jpf.runNonIe)
jpf.runNonIe();
}
jpf.runIE = function(){
var hasIE7Security = hasIESecurity = false;
if (hasIESecurity)
jpf.include(jpf.basePath + "teleport/iframe.js");
jpf.getHttpReq = hasIESecurity
? function(){
if (jpf.teleport.availHTTP.length)
return jpf.teleport.availHTTP.pop();
return new XMLHttpRequest();
}
: function(){
if (jpf.teleport.availHTTP.length)
return jpf.teleport.availHTTP.pop();
return new ActiveXObject("microsoft.XMLHTTP");
};
jpf.getXmlDom = hasIESecurity
? function(message, noError){
var xmlParser = getDOMParser(message, noError);
return xmlParser;
}
: function(message, noError, preserveWhiteSpaces){
var xmlParser = new ActiveXObject("microsoft.XMLDOM");
xmlParser.setProperty("SelectionLanguage", "XPath");
if (preserveWhiteSpaces)
xmlParser.preserveWhiteSpace = true;
if (message) {
if (jpf.cantParseXmlDefinition)
message = message.replace(/\] \]/g, "] ]").replace(/^<\?[^>]*\?>/, "");
xmlParser.loadXML(message);
if (!noError)
this.xmlParseError(xmlParser);
}
return xmlParser;
};
jpf.xmlParseError = function(xml){
var xmlParseError = xml.parseError;
if (xmlParseError != 0) {
throw new Error(jpf.formatErrorString(1050, null, "XML Parse error on line " + xmlParseError.line, xmlParseError.reason + "Source Text:\n" + xmlParseError.srcText.replace(/\t/gi, " ")));
}
return xml;
};
jpf.getStyle = function(el, prop) {
return el.currentStyle[prop];
};
if (jpf.XmlDatabase) {
jpf.XmlDatabase.prototype.htmlImport = function(xmlNode, htmlNode, beforeNode, pre, post){
var id;
if (xmlNode.length != null && !xmlNode.nodeType) {
var str, i, l;
for (str = [], i = 0, l = xmlNode.length; i < l; i++)
str.push(xmlNode[i].xml);
str = str.join("");
str = jpf.html_entity_decode(str)
.replace(/style="background-image:([^"]*)"/g, "find='$1' style='background-image:$1'");
if (pre) {
(beforeNode || htmlNode).insertAdjacentHTML(beforeNode
? "beforebegin"
: "beforeend", pre + str + post);
}
try {
(beforeNode || htmlNode).insertAdjacentHTML(beforeNode
? "beforebegin"
: "beforeend", str);
}
catch (e) {
document.body.insertAdjacentHTML("beforeend", "<table><tr>"
+ str + "</tr></table>");
var x = document.body.lastChild.firstChild.firstChild;
for (i = x.childNodes.length - 1; i >= 0; i--)
htmlNode.appendChild(x.childNodes[jpf.hasDynamicItemList ? 0 : i]);
}
if (!this.nodes)
this.nodes = [];
id = this.nodes.push(htmlNode.getElementsByTagName("*")) - 1;
setTimeout('jpf.xmldb.doNodes(' + id + ')');
return null;
}
if (htmlNode.ownerDocument && htmlNode.ownerDocument != document
&& xmlNode.ownerDocument == htmlNode.ownerDocument)
return htmlNode.insertBefore(xmlNode, beforeNode);
var strHTML = jpf.html_entity_decode(xmlNode.outerHTML || xmlNode.xml || xmlNode.nodeValue);
var pNode = (beforeNode || htmlNode);
if (pNode.nodeType == 11) {
id = xmlNode.getAttribute("id");
if (!id)
throw new Error(jpf.formatErrorString(1049, null, "xmldb", "Inserting Cache Item in Document Fragment without an ID"));
document.body.insertAdjacentHTML(beforeNode ? "beforebegin" : "beforeend", strHTML);
pNode.appendChild(document.getElementById(id));
}
else
pNode.insertAdjacentHTML(beforeNode ? "beforebegin" : "beforeend", strHTML);
return beforeNode ? beforeNode.previousSibling : htmlNode.lastChild;
};
jpf.XmlDatabase.prototype.doNodes = function(id){
var nodes = this.nodes[id];
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].getAttribute("find"))
nodes[i].style.backgroundImage = nodes[i].getAttribute("find");
}
this.nodes[id] = null;
};
jpf.xmldb = new jpf.XmlDatabase();
}
if (!hasIESecurity)
jpf.Init.run('xmldb');
jpf.getHorBorders = function(oHtml){
return Math.max(0,
(parseInt(jpf.getStyle(oHtml, "borderLeftWidth")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderRightWidth")) || 0))
};
jpf.getVerBorders = function(oHtml){
return Math.max(0,
(parseInt(jpf.getStyle(oHtml, "borderTopWidth")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderBottomWidth")) || 0))
};
jpf.getWidthDiff = function(oHtml){
return Math.max(0, (parseInt(jpf.getStyle(oHtml, "paddingLeft")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "paddingRight")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderLeftWidth")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderRightWidth")) || 0))
};
jpf.getHeightDiff = function(oHtml){
return Math.max(0, (parseInt(jpf.getStyle(oHtml, "paddingTop")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "paddingBottom")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderTopWidth")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderBottomWidth")) || 0))
};
jpf.getDiff = function(oHtml){
return [Math.max(0, (parseInt(jpf.getStyle(oHtml, "paddingLeft")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "paddingRight")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderLeftWidth")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderRightWidth")) || 0)),
Math.max(0, (parseInt(jpf.getStyle(oHtml, "paddingTop")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "paddingBottom")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderTopWidth")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "borderBottomWidth")) || 0))]
};
jpf.popup2 = {
cache: {},
setContent: function(cacheId, content, style, width, height){
if (!this.popup)
this.init();
this.cache[cacheId] = {
content: content,
style  : style,
width  : width,
height : height
};
if (content.parentNode)
content.parentNode.removeChild(content);
if (style)
jpf.importCssString(this.popup.document, style);
return this.popup.document;
},
removeContent: function(cacheId){
this.cache[cacheId] = null;
delete this.cache[cacheId];
},
init: function(){
this.popup = window.createPopup();
this.popup.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:j=' + jpf.ns.jml + ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\
<head>\
<script>\
var jpf = {\
all: [],\
lookup:function(uniqueId){\
return this.all[uniqueId] || {\
$setStyleClass:function(){}\
};\
}\
};\
function destroy(){\
jpf.all=null;\
}\
</script>\
<style>\
HTML{border:0;overflow:hidden;margin:0}\
BODY{margin:0}\
</style>\
</head>\
<body onmouseover="if(!self.jpf) return;if(this.c){jpf.all = this.c.all;this.c.Popup.parentDoc=self;}"></body>\
</html>');
var c = jpf;
this.popup.document.body.onmousemove = function(){
this.c = c
}
},
show: function(cacheId, x, y, animate, ref, width, height, callback){
if (!this.popup)
this.init();
var o = this.cache[cacheId];
this.popup.document.body.innerHTML = o.content.outerHTML;
if (animate) {
var iVal, steps = 7, i = 0, popup = this.popup;
iVal = setInterval(function(){
var value = ++i * ((height || o.height) / steps);
popup.show(x, y, width || o.width, value, ref);
popup.document.body.firstChild.style.marginTop
= (i - steps - 1) * ((height || o.height) / steps);
if (i > steps) {
clearInterval(iVal)
callback(popup.document.body.firstChild);
}
}, 10);
}
else {
this.popup.show(x, y, width || o.width, height || o.height, ref);
}
this.last = cacheId;
},
hide: function(){
if (this.popup)
this.popup.hide();
},
forceHide: function(){
if (this.last)
jpf.lookup(this.last).dispatchEvent("popuphide");
},
destroy: function(){
if (!this.popup)
return;
this.popup.document.body.c = null;
this.popup.document.body.onmouseover = null;
}
};
jpf.importClass(jpf.runXpath, true, self);
}
jpf.runGecko = function(){
if (jpf.runNonIe)
jpf.runNonIe();
HTMLDocument.prototype.selectNodes = XMLDocument.prototype.selectNodes = function(sExpr, contextNode){
var oResult = this.evaluate(sExpr, (contextNode || this),
this.createNSResolver(this.documentElement),
7, null);
var nodeList = new Array(oResult.snapshotLength);
nodeList.expr = sExpr;
for (var i = nodeList.length - 1; i >= 0; i--) 
nodeList[i] = oResult.snapshotItem(i);
return nodeList;
};
Element.prototype.selectNodes = function(sExpr){
return this.ownerDocument.selectNodes(sExpr, this);
};
HTMLDocument.prototype.selectSingleNode = XMLDocument.prototype.selectSingleNode = function(sExpr, contextNode){
var nodeList = this.selectNodes(sExpr + "[1]", contextNode || null);
return nodeList[0] || null;
};
Element.prototype.selectSingleNode = function(sExpr){
return this.ownerDocument.selectSingleNode(sExpr, this);
};
function Error(nr, msg){
this.message = msg;
this.nr = nr;
}
}
jpf.runNonIe = function (){
DocumentFragment.prototype.getElementById = function(id){
return this.childNodes.length ? this.childNodes[0].ownerDocument.getElementById(id) : null;
};
if (XMLDocument.prototype.__defineGetter__) {
XMLDocument.prototype.__defineGetter__("xml", function(){
return (new XMLSerializer()).serializeToString(this);
});
XMLDocument.prototype.__defineSetter__("xml", function(){
throw new Error(jpf.formatErrorString(1042, null, "XML serializer", "Invalid assignment on read-only property 'xml'."));
});
Node.prototype.__defineGetter__("xml", function(){
if (this.nodeType == 3 || this.nodeType == 4 || this.nodeType == 2) 
return this.nodeValue;
return (new XMLSerializer()).serializeToString(this);
});
Element.prototype.__defineGetter__("xml", function(){
return (new XMLSerializer()).serializeToString(this);
});
}
if (typeof HTMLElement!="undefined") {
if (!HTMLElement.prototype.insertAdjacentElement) {
HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode){
switch (where.toLowerCase()) {
case "beforebegin":
this.parentNode.insertBefore(parsedNode,this);
break;
case "afterbegin":
this.insertBefore(parsedNode,this.firstChild);
break;
case "beforeend":
this.appendChild(parsedNode);
break;
case "afterend":
if (this.nextSibling)
this.parentNode.insertBefore(parsedNode,this.nextSibling);
else
this.parentNode.appendChild(parsedNode);
break;
}
};
}
if (!HTMLElement.prototype.insertAdjacentHTML) {
HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr){
var r = this.ownerDocument.createRange();
r.setStartBefore(jpf.isSafari ? document.body : (self.document ? document.body : this));
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where, parsedHTML);
};
}
if (jpf.isSafari || jpf.isChrome)
HTMLBodyElement.prototype.insertAdjacentHTML = HTMLElement.prototype.insertAdjacentHTML;
if (!HTMLElement.prototype.insertAdjacentText) {
HTMLElement.prototype.insertAdjacentText = function(where,txtStr){
var parsedText = document.createTextNode(txtStr);
this.insertAdjacentElement(where,parsedText);
};
}
HTMLElement.prototype.removeNode = function(){
if (!this.parentNode) return;
this.parentNode.removeChild(this);
};
if (HTMLElement.prototype.__defineSetter__) {
HTMLElement.prototype.__defineSetter__("innerText", function(sText){
var s = "" + sText;
this.innerHTML = s.replace(/\&/g, "&amp;")
.replace(/</g, "&lt;").replace(/>/g, "&gt;");
});
HTMLElement.prototype.__defineGetter__("innerText", function(){
return this.innerHTML.replace(/<[^>]+>/g,"")
.replace(/\s\s+/g, " ").replace(/^\s*|\s*$/g, " ")
});
HTMLElement.prototype.__defineGetter__("outerHTML", function(){
return (new XMLSerializer()).serializeToString(this);
});
}
}
var ASYNCNOTSUPPORTED = false;
try {
XMLDocument.prototype.async = true;
ASYNCNOTSUPPORTED           = true;
} catch(e) {} 
Document.prototype.onreadystatechange = null;
Document.prototype.parseError         = 0;
Array.prototype.item = function(i){return this[i];};
Array.prototype.expr = "";
XMLDocument.prototype.readyState = 0;
XMLDocument.prototype.$clearDOM = function(){
while (this.hasChildNodes())
this.removeChild(this.firstChild);
};
XMLDocument.prototype.$copyDOM = function(oDoc){
this.$clearDOM();
if (oDoc.nodeType == 9 || oDoc.nodeType == 11) {
var oNodes = oDoc.childNodes;
for (var i = 0; i < oNodes.length; i++)
this.appendChild(this.importNode(oNodes[i], true));
} else if(oDoc.nodeType == 1)
this.appendChild(this.importNode(oDoc, true));
};
XMLDocument.prototype.loadXML = function(strXML){
jpf.xmldb.setReadyState(this, 1);
var sOldXML = this.xml || this.serialize();
var oDoc    = (new DOMParser()).parseFromString(strXML, "text/xml");
jpf.xmldb.setReadyState(this, 2);
this.$copyDOM(oDoc);
jpf.xmldb.setReadyState(this, 3);
jpf.xmldb.loadHandler(this);
return sOldXML;
};
Node.prototype.getElementById = function(id){};
HTMLElement.prototype.replaceNode = 
Element.prototype.replaceNode     = function(xmlNode){
if (!this.parentNode) return;
this.parentNode.insertBefore(xmlNode, this);
this.parentNode.removeChild(this);
};
XMLDocument.prototype.$load = XMLDocument.prototype.load;
XMLDocument.prototype.load  = function(sURI){
var oDoc = document.implementation.createDocument("", "", null);
oDoc.$copyDOM(this);
this.parseError = 0;
jpf.xmldb.setReadyState(this, 1);
try {
if (this.async == false && ASYNCNOTSUPPORTED) {
var tmp = new XMLHttpRequest();
tmp.open("GET", sURI, false);
tmp.overrideMimeType("text/xml");
tmp.send(null);
jpf.xmldb.setReadyState(this, 2);
this.$copyDOM(tmp.responseXML);
jpf.xmldb.setReadyState(this, 3);
} else
this.$load(sURI);
}
catch (objException) {
this.parseError = -1;
}
finally {
jpf.xmldb.loadHandler(this);
}
return oDoc;
};
Element.prototype.transformNodeToObject = function(xslDoc, oResult){
var oDoc = document.implementation.createDocument("", "", null);
oDoc.$copyDOM(this);
oDoc.transformNodeToObject(xslDoc, oResult);
};
Document.prototype.transformNodeToObject = function(xslDoc, oResult){
var xsltProcessor = null;
try {
xsltProcessor = new XSLTProcessor();
if (xsltProcessor.reset) {
xslDoc = jpf.getXmlDom(xslDoc.xml || xslDoc.serialize());
xsltProcessor.importStylesheet(xslDoc);
var newFragment = xsltProcessor.transformToFragment(this, oResult);
oResult.$copyDOM(newFragment);
}
else {
xsltProcessor.transformDocument(this, xslDoc, oResult, null);
}
}
catch(e) {
if (xslDoc && oResult)
throw new Error(jpf.formatErrorString(1043, null, "XSLT Transformation", "Failed to transform document. \nInfo : " + e));
else if (!xslDoc)
throw new Error(jpf.formatErrorString(1044, null, "XSLT Transformation", "No Stylesheet Document was provided. \nInfo : " + e));
else if (!oResult)
throw new Error(jpf.formatErrorString(1045, null, "XSLT Transformation", "No Result Document was provided. \nInfo : " + e));
else if (xsltProcessor == null)
throw new Error(jpf.formatErrorString(1046, null, "XSLT Transformation", "Could not instantiate an XSLTProcessor object. \nInfo : " + e));
else
throw e;
}
};
Element.prototype.transformNode = function(xslDoc){
return jpf.getXmlDom(this.xml || this.serialize())
.transformNode(xslDoc);
};
Document.prototype.transformNode = function(xslDoc){
var xsltProcessor = new XSLTProcessor();
xslDoc        = jpf.getXmlDom(xslDoc.xml || xslDoc.serialize());
xsltProcessor.importStylesheet(xslDoc);
var newFragment   = xsltProcessor.transformToFragment(this,
document.implementation.createDocument("", "", null));
return newFragment.xml || newFragment.serialize()
};
jpf.getStyle = function(el, prop) {
return window.getComputedStyle(el, '').getPropertyValue(prop);
};
HTMLDocument.prototype.setProperty = 
XMLDocument.prototype.setProperty  = function(x,y){};
jpf.getHttpReq = function(){
if (jpf.teleport.availHTTP.length)
return jpf.teleport.availHTTP.pop();
return new XMLHttpRequest();
};
jpf.getXmlDom = function(message, noError){
var xmlParser;
if (message) {
xmlParser = new DOMParser();
xmlParser     = xmlParser.parseFromString(message, "text/xml");
if (!noError)
this.xmlParseError(xmlParser);
}
else {
xmlParser = document.implementation.createDocument("", "", null);
}
return xmlParser;
};
jpf.xmlParseError = function(xml){
if (xml.documentElement.tagName == "parsererror") {
var str     = xml.documentElement.firstChild.nodeValue.split("\n");
var linenr  = str[2].match(/\w+ (\d+)/)[1];
var message = str[0].replace(/\w+ \w+ \w+: (.*)/, "$1");
var srcText = xml.documentElement.lastChild.firstChild.nodeValue.split("\n")[0];
throw new Error(jpf.formatErrorString(1050, null, 
"XML Parse Error on line " +  linenr, message + 
"\nSource Text : " + srcText.replace(/\t/gi, " ")));
}
return xml;
};
if (jpf.XmlDatabase) {
jpf.XmlDatabase.prototype.htmlImport = function(xmlNode, htmlNode, beforeNode, test){
if (!htmlNode)
alert("No HTML node given in htmlImport:" + this.htmlImport.caller);
if (xmlNode.length != null && !xmlNode.nodeType) {
for (var str = [], i = 0, l = xmlNode.length; i < l; i++) 
str.push(xmlNode[i].xml || xmlNode[i].serialize());
str = str.join("").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&")
.replace(/<([^>]+)\/>/g, "<$1></$1>");
(beforeNode || htmlNode).insertAdjacentHTML(beforeNode 
? "beforebegin" 
: "beforeend", str);
return null;
}
if (htmlNode.ownerDocument && htmlNode.ownerDocument != document
&& xmlNode.ownerDocument == htmlNode.ownerDocument)
return htmlNode.insertBefore(xmlNode, beforeNode);
var strHTML = jpf.html_entity_decode(xmlNode.outerHTML || xmlNode.xml || xmlNode.nodeValue);
var pNode = (beforeNode || htmlNode);
if (pNode.nodeType == 11){
var id = xmlNode.getAttribute("id");
if (!id)
throw new Error(jpf.formatErrorString(1049, null, "xmldb", "Inserting Cache Item in Document Fragment without an ID"));
document.body.insertAdjacentHTML(beforeNode ? "beforebegin" : "beforeend", strHTML);
pNode.appendChild(document.getElementById(id));
}
else {
if (xmlNode.tagName.match(/tbody|td|tr/))
pNode.insertBefore(pNode.ownerDocument
.createElement(xmlNode.tagName.toLowerCase()), beforeNode || null);
else {
pNode.insertAdjacentHTML(beforeNode ? "beforebegin" : "beforeend", strHTML);
}
}
return beforeNode ? beforeNode.previousSibling : htmlNode.lastChild;
};
jpf.XmlDatabase.prototype.setReadyState = function(oDoc, iReadyState) {
oDoc.readyState = iReadyState;
if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function")
oDoc.onreadystatechange();
};
jpf.XmlDatabase.prototype.loadHandler = function(oDoc){
if (!oDoc.documentElement || oDoc.documentElement.tagName == "parsererror")
oDoc.parseError = -1;
jpf.xmldb.setReadyState(oDoc, 4);
};
jpf.xmldb = new jpf.XmlDatabase();
}
jpf.Init.add(function(){
var i, nodes = document.getElementsByTagName("form");
for (i = 0; i < nodes.length; i++)
nodes[i].removeNode();
nodes = document.getElementsByTagName("xml");
for(i = 0; i < nodes.length; i++)
nodes[i].removeNode();
nodes = null;
});
var MAXMSG      = 3;
var ERROR_COUNT = 0;
if (document.body)
document.body.focus = function(){};
if (!document.elementFromPoint) {
Document.prototype.elementFromPointRemove = function(el){
if (!this.RegElements) return;
this.RegElements.remove(el);
};
Document.prototype.elementFromPointAdd = function(el){
if (!this.RegElements)
this.RegElements = [];
this.RegElements.push(el);
};
Document.prototype.elementFromPointReset = function(RegElements){
FoundValue   = [];
FoundNode    = null;
LastFoundAbs = document.documentElement;
};
Document.prototype.elementFromPoint = function(x, y){
document.elementFromPointReset();
if (this.RegElements) {
for (var calc_z = -1, calc, i = 0; i < this.RegElements.length; i++) {
var n = this.RegElements[i];
if (getStyle(n, "display") == "none") continue;
var sx = getElementPosX(n); 
var sy = getElementPosY(n);
var ex = sx + n.offsetWidth;
var ey = sy + n.offsetHeight;
if (x > sx && x < ex && y > sy && y < ey) {
var z = getElementZindex(n);
if (z > calc_z) { 
calc   = [n, x, y, sx, sy];
calc_z = z;
}
}
}
if (calc) {
efpi(calc[0], calc[1], calc[2], 0, FoundValue, calc[3], calc[4]);
if (!FoundNode) {
FoundNode    = calc[0];
LastFoundAbs = calc[0];
FoundValue   = [calc_z];
}
}
}
if (!this.RegElements || !this.RegElements.length)
efpi(document.body, x, y, 0, [], getElementPosX(document.body),
getElementPosY(document.body));
return FoundNode;
};
function getStyle(el, prop) {
return document.defaultView.getComputedStyle(el,'').getPropertyValue(prop);
}
function efpi(from, x, y, CurIndex, CurValue, px, py){
var StartValue = CurValue;
var StartIndex = CurIndex;
var nodes = from.childNodes;
for(var n, i = 0; i < from.childNodes.length; i++) {
n = from.childNodes[i];
if (n.nodeType == 1 && getStyle(n, 'display') != 'none' && n.offsetParent) {
var sx = px + n.offsetLeft - n.offsetParent.scrollLeft;
var sy = py + n.offsetTop - n.offsetParent.scrollTop;
var ex = sx + n.offsetWidth;
var ey = sy + n.offsetHeight;
var isAbs    = getStyle(n, "position");
isAbs        = (isAbs == "absolute") || (isAbs == "relative");
var isHidden = getStyle(n, "overflow") == "hidden";
var inSpace  = (x > sx && x < ex && y > sy && y < ey);
if (isAbs && isHidden && !inSpace) continue;
CurIndex = StartIndex;
CurValue = StartValue.copy();
var z = parseInt(getStyle(n, "z-index")) || 0;
if (isAbs && (z || z == 0) || isHidden) {
if (!isAbs) z = 0;
if (z >= (FoundValue[CurIndex] || 0)) {
if (z > (CurValue[CurIndex] || 0)) {
CurValue[CurIndex] = z;
}
CurIndex++;
if (inSpace && CurIndex >= FoundValue.length) {
FoundNode = n;
FoundValue = CurValue;
LastFoundAbs = n;
}
}
else
continue; 
}
else if(inSpace && CurIndex >= FoundValue.length){
FoundNode = n;
FoundValue = CurValue;
}
efpi(n, x, y, CurIndex, CurValue, isAbs ? sx : px, isAbs ? sy : py)
}
}
}
function getElementPosY(myObj){
return myObj.offsetTop + parseInt(jpf.getStyle(myObj, "border-top-width"))
+ (myObj.offsetParent ? getElementPosY(myObj.offsetParent) : 0);
}
function getElementPosX(myObj){
return myObj.offsetLeft + parseInt(jpf.getStyle(myObj, "border-left-width"))
+ (myObj.offsetParent ? getElementPosX(myObj.offsetParent) : 0);
}
function getElementZindex(myObj){
var z = 0, n, p = myObj;
while(p && p.nodeType == 1){
z = Math.max(z, parseInt(getStyle(p, "z-index")) || -1);
p = p.parentNode;
}
return z;
}
}
jpf.getHorBorders = function(oHtml){
return Math.max(0, 
(parseInt(jpf.getStyle(oHtml, "border-left-width")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "border-right-width")) || 0));
};
jpf.getVerBorders = function(oHtml){
return Math.max(0, 
(parseInt(jpf.getStyle(oHtml, "border-top-width")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "border-bottom-width")) || 0));
};
jpf.getWidthDiff = function(oHtml){
return Math.max(0, (parseInt(jpf.getStyle(oHtml, "padding-left")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "padding-right")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "border-left-width")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "border-right-width")) || 0));
};
jpf.getHeightDiff = function(oHtml){
return Math.max(0, (parseInt(jpf.getStyle(oHtml, "padding-top")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "padding-bottom")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "border-top-width")) || 0)
+ (parseInt(jpf.getStyle(oHtml, "border-bottom-width")) || 0));
};
jpf.getDiff = function(oHtml){
return [Math.max(0, parseInt(jpf.getStyle(oHtml, "padding-left"))
+ parseInt(jpf.getStyle(oHtml, "padding-right"))
+ parseInt(jpf.getStyle(oHtml, "border-left-width"))
+ parseInt(jpf.getStyle(oHtml, "border-right-width")) || 0),
Math.max(0, parseInt(jpf.getStyle(oHtml, "padding-top"))
+ parseInt(jpf.getStyle(oHtml, "padding-bottom"))
+ parseInt(jpf.getStyle(oHtml, "border-top-width"))
+ parseInt(jpf.getStyle(oHtml, "border-bottom-width")) || 0)];
};
jpf.Init.run('xmldb');
}
jpf.runSafari = function(){
if (!jpf.isChrome) {
var setTimeoutSafari = window.setTimeout;
lookupSafariCall = [];
window.setTimeout = function(call, time){
if (typeof call == "string") 
return setTimeoutSafari(call, time);
return setTimeoutSafari("lookupSafariCall["
+ (lookupSafariCall.push(call) - 1) + "]()", time);
}
if (jpf.isSafariOld) {
HTMLHtmlElement = document.createElement("html").constructor;
Node            = HTMLElement = {};
HTMLElement.prototype = HTMLHtmlElement.__proto__.__proto__;
HTMLDocument    = Document = document.constructor;
var x           = new DOMParser();
XMLDocument     = x.constructor;
Element         = x.parseFromString("<Single />", "text/xml").documentElement.constructor;
x               = null;
}
if (!XMLDocument.__defineGetter__) {
Document.prototype.serialize    = 
Node.prototype.serialize        =
XMLDocument.prototype.serialize = function(){
return (new XMLSerializer()).serializeToString(this);
};
}
}
if (jpf.isSafariOld || jpf.isSafari || jpf.isChrome) {
HTMLDocument.prototype.selectNodes =
XMLDocument.prototype.selectNodes  = function(sExpr, contextNode){
return jpf.XPath.selectNodes(sExpr, contextNode || this);
};
Element.prototype.selectNodes = function(sExpr, contextNode){
return jpf.XPath.selectNodes(sExpr, contextNode || this);
};
HTMLDocument.prototype.selectSingleNode =
XMLDocument.prototype.selectSingleNode  = function(sExpr, contextNode){
return jpf.XPath.selectNodes(sExpr, contextNode || this)[0];
};
Element.prototype.selectSingleNode = function(sExpr, contextNode){
return jpf.XPath.selectNodes(sExpr, contextNode || this)[0];
};
jpf.importClass(jpf.runXpath, true, self);
jpf.importClass(jpf.runXslt, true, self);
}
if (jpf.runNonIe)
jpf.runNonIe();
}
jpf.JmlParser = {
sbInit     : {},
stateStack : [],
modelInit  : [],
parse : function(x){
this.$jml = x;
jpf.isParsing = true;
jpf.window          = new jpf.WindowImplementation();
jpf.document        = new jpf.DocumentImplementation();
jpf.window.document = jpf.document;
jpf.window.$at      = new jpf.actiontracker();
jpf.window.$at.name = "default";
jpf.nameserver.register("actiontracker", "default", jpf.window.$at);
for (var docs = [x], i = 0; i < jpf.includeStack.length; i++) {
if (jpf.includeStack[i].nodeType)
docs.push(jpf.includeStack[i]);
}
this.docs = docs;
this.parseSettings(docs);
if (!this.shouldWait)
this.continueStartup();
},
continueStartup : function(){
this.parseFirstPass(this.docs);
jpf.JmlParser.parseChildren(this.$jml, document.body, jpf.document.documentElement);
setTimeout('jpf.JmlParser.parseLastPass();', 1);
this.inited = true;
},
parseSettings : function(xmlDocs) {
for (var i = 0; i < xmlDocs.length; i++)
this.preLoadRef(xmlDocs[i], ["appsettings"]);
},
parseFirstPass: function(xmlDocs){
for (var i = 0; i < xmlDocs.length; i++)
this.preLoadRef(xmlDocs[i], ["teleport", "settings",
"skin[not(@j_preparsed=9999)]", "bindings[@id]", "actions[@id]", "dragdrop[@id]", "remote"]);
for (var i = 0; i < xmlDocs.length; i++)
this.preLoadRef(xmlDocs[i], ["model[@id]",
"smartbinding[@id]", "iconmap"], true);
},
preparsed : [],
preLoadRef : function(xmlNode, sel, parseLocalModel){
var prefix = jpf.findPrefix(xmlNode, jpf.ns.jml);
if (prefix) prefix += ":";
var nodes  = jpf.xmldb.selectNodes(".//" + prefix + sel.join("|.//"
+ prefix) + (parseLocalModel ? "|" + prefix + "model" : ""), xmlNode);
var i, o, name, tagName, x, l;
for (i = 0, l = nodes.length; i < l; i++) {
x = nodes[i];
if (jpf.xmldb.getInheritedAttribute(x, "render") == "runtime")
continue;
var tagName = x[jpf.TAGNAME];
if (this.handler[tagName]) {
o = this.handler[tagName](x);
name = x.getAttribute("id"); 
if (o && name)
jpf.nameserver.register(tagName, name, o);
if (!o || !o.nodeType)
o = new jpf.JmlDom(tagName, null, jpf.NODE_HIDDEN, x, o);
o.$jmlLoaded = true;
if (name) jpf.setReference(name, o);
x.setAttribute("j_preparsed", this.preparsed.push(o) - 1);
}
else if (x.parentNode) {
x.parentNode.removeChild(x);
}
}
},
parseMoreJml : function(x, pHtmlNode, jmlParent, noImpliedParent, parseSelf, beforeNode){
var parsing = jpf.isParsing;
jpf.isParsing = true;
if (!jpf.window) {
jpf.window          = new jpf.WindowImplementation();
jpf.document        = new jpf.DocumentImplementation();
jpf.window.document = jpf.document;
jpf.window.$at      = new jpf.actiontracker();
jpf.nameserver.register("actiontracker", "default", jpf.window.$at);
}
if (!jmlParent)
jmlParent = jpf.document.documentElement;
this.parseFirstPass([x]);
if (parseSelf) {
if (jmlParent.loadJml)
jmlParent.loadJml(x, jmlParent.parentNode);
jmlParent.$jmlLoaded = true;
if (jmlParent.pData || jmlParent.tagName == "grid")
jpf.layout.activateRules(pNode.oInt || document.body);
}
else {
var lastChild = pHtmlNode.lastChild;
this.parseChildren(x, pHtmlNode, jmlParent, false, noImpliedParent);
if (beforeNode) {
var loop = pHtmlNode.lastChild;
while (lastChild != loop) {
pHtmlNode.insertBefore(loop, beforeNode);
loop = pHtmlNode.lastChild;
}
}
}
jpf.layout.activateRules();
this.parseLastPass();
jpf.isParsing = parsing;
},
reWhitespaces : /[\t\n\r]+/g,
parseChildren : function(x, pHtmlNode, jmlParent, checkRender, noImpliedParent){
if (pHtmlNode == jmlParent.oInt && jmlParent.childNodes.length
&& jmlParent != jpf.document.documentElement)
return pHtmlNode;
if (checkRender && jmlParent && jmlParent.hasFeature(__DELAYEDRENDER__)
&& jmlParent.$checkDelay(x)) {
return pHtmlNode;
}
if (jmlParent)
jmlParent.isRendered = true;
if (x.namespaceURI == jpf.ns.jml || x.tagUrn == jpf.ns.jml)
this.lastNsPrefix = x.prefix || x.scopeName;
for (var oCount = 0,i = 0; i < x.childNodes.length; i++) {
var q = x.childNodes[i];
if (q.nodeType == 8) continue;
if (q.nodeType != 1) {
if (!pHtmlNode) continue;
if (jpf.isIE && !q.nodeValue.trim())
continue;
if (q.nodeType == 3 || pHtmlNode.style && q.nodeType == 4) {
pHtmlNode.appendChild(pHtmlNode.ownerDocument
.createTextNode(!jpf.hasTextNodeWhiteSpaceBug
? q.nodeValue
: q.nodeValue.replace(this.reWhitespaces, " ")));
}
else if (q.nodeType == 4) {
pHtmlNode.appendChild(pHtmlNode.ownerDocument
.createCDataSection(q.nodeValue));
}
jpf.language.addElement(q.nodeValue.replace(/^\$(.*)\$$/,
"$1"), {htmlNode : pHtmlNode});
continue;
}
if (!this.nsHandler[q.namespaceURI || q.tagUrn || jpf.ns.xhtml])
continue; 
this.nsHandler[q.namespaceURI || q.tagUrn || jpf.ns.xhtml].call(
this, q, pHtmlNode, jmlParent, noImpliedParent);
}
if (pHtmlNode) {
if (!jpf.hasSingleRszEvent)
jpf.layout.activateRules(pHtmlNode);
}
return pHtmlNode;
},
addNamespaceHandler : function(xmlns, func){
this.nsHandler[xmlns] = func;
},
nsHandler : {
"http://www.javeline.com/2005/jml" : function(x, pHtmlNode, jmlParent, noImpliedParent){
var tagName = x[jpf.TAGNAME];
if (tagName == "include") {
var xmlNode = jpf.includeStack[x.getAttribute("iid")];
this.parseChildren(xmlNode, pHtmlNode, jmlParent, null, true);
}
else
if (this.handler[tagName]) {
var o, id, name;
if (id = x.getAttribute("j_preparsed")) {
x.removeAttribute("j_preparsed");
o = this.preparsed[id];
delete this.preparsed[id];
if (o && !o.parentNode) {
if (jmlParent.hasFeature && jmlParent.hasFeature(__WITH_JMLDOM__))
o.$setParent(jmlParent);
else {
o.parentNode = jmlParent;
jmlParent.childNodes.push(o);
}
}
return o;
}
o = this.handler[tagName](x, (noImpliedParent
? null
: jmlParent), pHtmlNode);
name = x.getAttribute("id"); 
if (o && name)
jpf.nameserver.register(tagName, name, o);
if (!o || !o.nodeType)
o = new jpf.JmlDom(tagName, jmlParent, jpf.NODE_HIDDEN, x, o);
else if(noImpliedParent)
o.$setParent(jmlParent);
o.$jmlLoaded = true;
if (name)
jpf.setReference(name, o);
}
else if (pHtmlNode) {
if (!jpf[tagName])
throw new Error("Could not find class " + tagName);
var objName = tagName;
var o = new jpf[objName](pHtmlNode, tagName, x);
if (x.getAttribute("id"))
jpf.setReference(x.getAttribute("id"), o);
if (o.loadJml)
o.loadJml(x, jmlParent);
o.$jmlLoaded = true;
}
return o;
}
,"http://www.w3.org/1999/xhtml" :  function(x, pHtmlNode, jmlParent, noImpliedParent){
var parseWhole = x.tagName.match(/table|object|embed/i) ? true : false;
if (x.tagName == "script") {
return;
}
else if (x.tagName == "option") {
var o = pHtmlNode.appendChild(pHtmlNode.ownerDocument.createElement("option"));
if (x.getAttribute("value"))
o.setAttribute("value", x.getAttribute("value"));
}
else if (jpf.isIE) {
var o = (x.ownerDocument == pHtmlNode.ownerDocument)
? pHtmlNode.appendChild(x.cloneNode(false))
: jpf.xmldb.htmlImport(x.cloneNode(parseWhole), pHtmlNode);
}
else if (jpf.isSafari) { 
var o = (x.ownerDocument == pHtmlNode.ownerDocument)
? pHtmlNode.appendChild(x)
: jpf.xmldb.htmlImport(x.cloneNode(parseWhole), pHtmlNode);
}
else {
var o = (x.ownerDocument == pHtmlNode.ownerDocument)
? pHtmlNode.appendChild(x.cloneNode(false))
: jpf.xmldb.htmlImport(x.cloneNode(false), pHtmlNode);
}
var tagName;
var prefix = this.lastNsPrefix || jpf.findPrefix(x.parentNode, jpf.ns.jml) || "";
if (prefix && !x.style) {
if (!jpf.supportNamespaces)
x.ownerDocument.setProperty("SelectionNamespaces", "xmlns:"
+ prefix + "='" + jpf.ns.jml + "'");
prefix += ":";
}
if ((jpf.canUseInnerHtmlWithTables || !parseWhole) && x.tagName.toUpperCase() != "IFRAME")
this.parseChildren(x, o, jmlParent);
else {
}
if (jpf.xmldb.getTextNode(x)) {
var data = {
jmlNode  : x,
htmlNode : o
}
jpf.language.addElement(jpf.xmldb.getTextNode(x)
.nodeValue.replace(/^\$(.*)\$$/, "$1"), data);
}
return o;
}
},
invalidJml : function(jml, message){
},
handler : {
"script" : function(q){
if (q.getAttribute("src")) {
if (jpf.isOpera) {
setTimeout(function(){
jpf.window.loadCodeFile(jpf.hostPath
+ q.getAttribute("src"));
}, 1000);
}
else {
jpf.window.loadCodeFile(jpf.hostPath
+ q.getAttribute("src"));
}
}
else if (q.firstChild) {
var scode = q.firstChild.nodeValue;
jpf.exec(scode);
}
},
"state-group" : function(q, jmlParent){
var name = q.getAttribute("name") || "stategroup" + jpf.all.length;
var pState = jpf.StateServer.addGroup(name, null, jmlParent);
var nodes = q.childNodes, attr = q.attributes, al = attr.length;
for (var j, i = 0, l = nodes.length; i < l; i++){
var node = nodes[i];
if (node.nodeType != 1 || node[jpf.TAGNAME] != "state")
continue;
for (j = 0; j < al; j++) {
if (!node.getAttribute(attr[j].nodeName))
node.setAttribute(attr[j].nodeName, attr[j].nodeValue);
}
node.setAttribute("group", name);
new jpf.state(jmlParent ? jmlParent.pHtmlNode : document.body, "state", node)
.loadJml(node, pState);
}
return pState;
},
"window" : function(q, jmlParent, pHtmlNode){
var o = new jpf.modalwindow(pHtmlNode, "window", q);
o.loadJml(q, jmlParent);
return o;
},
"style" : function(q){
jpf.importCssString(document, q.firstChild.nodeValue);
},
"comment" : function (q){
},
"presentation" : function(q){
var name = "skin" + Math.round(Math.random() * 100000);
q.parentNode.setAttribute("skin", name);
jpf.skins.skins[name] = {name:name,templates:{}}
var t    = q.parentNode[jpf.TAGNAME];
var skin = q.ownerDocument.createElement("skin"); skin.appendChild(q);
jpf.skins.skins[name].templates[t] = skin;
},
"skin" : function(q, jmlParent){
if (jmlParent) {
var name = "skin" + Math.round(Math.random() * 100000);
q.parentNode.setAttribute("skin", name);
jpf.skins.skins[name] = {name: name, templates: {}};
jpf.skins.skins[name].templates[q.parentNode[jpf.TAGNAME]] = q;
}
else if (q.childNodes.length) {
jpf.skins.Init(q);
}
else {
var path = q.getAttribute("src")
? jpf.getAbsolutePath(jpf.hostPath, q.getAttribute("src"))
: jpf.getAbsolutePath(jpf.hostPath, q.getAttribute("name")) + "/index.xml";
jpf.loadJmlInclude(q, true, path);
}
},
"model" : function(q, jmlParent){
var model = new jpf.model().loadJml(q, jmlParent);
if (jmlParent && jmlParent.hasFeature(__DATABINDING__)) {
modelId = "model" + jmlParent.uniqueId;
jmlParent.$jml.setAttribute("model", modelId);
model.register(jmlParent);
jpf.nameserver.register("model", modelId, model);
}
return model;
},
"smartbinding" : function(q, jmlParent){
var bc = new jpf.smartbinding(q.getAttribute("id"), q, jmlParent);
if (jmlParent && jmlParent.hasFeature(__DATABINDING__))
jpf.JmlParser.addToSbStack(jmlParent.uniqueId, bc);
return bc;
},
"ref" : function(q, jmlParent){
if (!jmlParent || !jmlParent.hasFeature(__DATABINDING__))
return jpf.JmlParser.invalidJml(q);
jpf.JmlParser.getFromSbStack(jmlParent.uniqueId)
.addBindRule(q, jmlParent);
}, 
"bindings" : function(q, jmlParent){
var rules = jpf.getRules(q);
if (jmlParent && jmlParent.hasFeature(__DATABINDING__))
jpf.JmlParser.getFromSbStack(jmlParent.uniqueId)
.addBindings(rules, q);
return rules;
},
"action" : function(q, jmlParent){
if (!jmlParent || !jmlParent.hasFeature(__DATABINDING__))
return jpf.JmlParser.invalidJml(q);
jpf.JmlParser.getFromSbStack(jmlParent.uniqueId)
.addActionRule(q, jmlParent);
}, 
"actions" : function(q, jmlParent){
var rules = jpf.getRules(q);
if (jmlParent && jmlParent.hasFeature(__DATABINDING__)) {
jpf.JmlParser.getFromSbStack(jmlParent.uniqueId)
.addActions(rules, q);
}
return rules;
},
"actiontracker" : function(q, jmlParent){
var at = new jpf.actiontracker(jmlParent);
at.loadJml(q);
if (jmlParent)
jmlParent.$at = at;
return at;
},
"teleport" : function(q, jmlParent){
return jpf.teleport.loadJml(q, jmlParent);
},
"appsettings" : function(q, jmlParent){
return jpf.appsettings.loadJml(q, jmlParent);
}
, "loader" : function(q){
}
},
getSmartBinding : function(id){
return jpf.nameserver.get("smartbinding", id);
},
getActionTracker : function(id){
var at = jpf.nameserver.get("actiontracker", id);
if (at)
return at;
if (self[id])
return self[id].getActionTracker();
},
replaceNode : function(newNode, oldNode){
var nodes = oldNode.childNodes;
for (var i = nodes.length - 1; i >= 0; i--) {
if (nodes[i].host) {
nodes[i].host.pHtmlNode = newNode;
}
newNode.insertBefore(nodes[i], newNode.firstChild);
}
newNode.onresize = oldNode.onresize;
return newNode;
},
parseLastPass : function(){
jpf.parsingFinalPass = true;
while (this.hasNewSbStackItems) {
var sbInit              = this.sbInit;
this.sbInit             = {};
this.hasNewSbStackItems = false;
for (var uniqueId in sbInit) {
if (parseInt(uniqueId) != uniqueId)
continue;
var jNode = jpf.lookup(uniqueId);
if (sbInit[uniqueId][0]) {
jNode.$propHandlers["smartbinding"]
.call(jNode, sbInit[uniqueId][0], true);
}
if (sbInit[uniqueId][1])
jNode.$setMultiBind(sbInit[uniqueId][1]);
}
}
this.sbInit = {};
var s = this.stateStack;
for (var i = 0; i < s.length; i++) {
s[i].node.setDynamicProperty(s[i].name, s[i].value);
}
this.stateStack = [];
while (this.hasNewModelStackItems) {
var jmlNode, modelInit     = this.modelInit;
this.modelInit             = {};
this.hasNewModelStackItems = false;
for (var data,i = 0; i < modelInit.length; i++) {
data    = modelInit[i][1];
data[0] = data[0].substr(1);
jmlNode = eval(data[0]);
if (jmlNode.connect)
jmlNode.connect(modelInit[i][0], null, data[2], data[1] || "select");
else
jmlNode.setModel(new jpf.model().loadFrom(data.join(":")));
}
}
this.modelInit = [];
if (!jpf.loaded)
jpf.dispatchEvent("load");
jpf.loaded = true;
jpf.layout.activateRules();
if (!this.loaded) {
if (!jpf.window.focussed)
jpf.window.focusDefault();
this.loaded = true;
}
jpf.isParsing = false;
jpf.parsingFinalPass = false;
}
,
addToSbStack : function(uniqueId, sNode, nr){
this.hasNewSbStackItems = true;
return ((this.sbInit[uniqueId]
|| (this.sbInit[uniqueId] = []))[nr||0] = sNode);
},
getFromSbStack : function(uniqueId, nr, create){
this.hasNewSbStackItems = true;
if (nr) {
if (!create)
return (this.sbInit[uniqueId] || {})[nr];
return this.sbInit[uniqueId]
&& (this.sbInit[uniqueId][nr]
|| (this.sbInit[uniqueId][nr] = new jpf.smartbinding()))
|| ((this.sbInit[uniqueId] = [])[nr] = new jpf.smartbinding());
}
return !this.sbInit[uniqueId]
&& (this.sbInit[uniqueId] = [new jpf.smartbinding()])[0]
|| this.sbInit[uniqueId][0]
|| (this.sbInit[uniqueId][0] = new jpf.smartbinding());
},
stackHasBindings : function(uniqueId){
return (this.sbInit[uniqueId] && this.sbInit[uniqueId][0]
&& this.sbInit[uniqueId][0].bindings);
}
,
addToModelStack : function(o, data){
this.hasNewModelStackItems = true;
this.modelInit.push([o, data]);
}
};
jpf.Init.run('jpf.JmlParser');
jpf.runXslt = function(){
jpf.XSLTProcessor = function(){
this.templates = {};
this.p = {
"value-of": function(context, xslNode, childStack, result){
var xmlNode = jpf.XPath.selectNodes(xslNode.getAttribute("select"), context)[0];
if (!xmlNode)
value = "";
else {
if (xmlNode.nodeType == 1)
value = xmlNode.firstChild ? xmlNode.firstChild.nodeValue : "";
else
value = typeof xmlNode == "object" ? xmlNode.nodeValue : xmlNode;
}
result.appendChild(this.xmlDoc.createTextNode(value));
},
"copy-of": function(context, xslNode, childStack, result){
var xmlNode = jpf.XPath.selectNodes(xslNode.getAttribute("select"), context)[0];
if (xmlNode)
result.appendChild(jpf.canImportNode
? result.ownerDocument.importNode(xmlNode, true)
: xmlNode.cloneNode(true));
},
"if": function(context, xslNode, childStack, result){
if (jpf.XPath.selectNodes(xslNode.getAttribute("test"), context)[0]) {
this.parseChildren(context, xslNode, childStack, result);
}
},
"for-each": function(context, xslNode, childStack, result){
var nodes = jpf.XPath.selectNodes(xslNode.getAttribute("select"), context);
for (var i = 0; i < nodes.length; i++) {
this.parseChildren(nodes[i], xslNode, childStack, result);
}
},
"choose": function(context, xslNode, childStack, result){
var nodes = xslNode.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (!nodes[i].tagName)
continue;
if (nodes[i][jpf.TAGNAME]  == "otherwise"
|| nodes[i][jpf.TAGNAME] == "when"
&& jpf.XPath.selectNodes(nodes[i].getAttribute("test"), context)[0])
return this.parseChildren(context, nodes[i], childStack[i][2], result);
}
},
"output": function(context, xslNode, childStack, result){},
"param": function(context, xslNode, childStack, result){},
"attribute": function(context, xslNode, childStack, result){
var nres = this.xmlDoc.createDocumentFragment();
this.parseChildren(context, xslNode, childStack, nres);
result.setAttribute(xslNode.getAttribute("name"), nres.xml);
},
"apply-templates": function(context, xslNode, childStack, result){
if (!xslNode) {
var t = this.templates["/"] || this.templates[context.tagName];
if (t)
this.parseChildren(t == this.templates["/"]
? context.ownerDocument : context, t[0], t[1], result);
}
else {
if (xslNode.getAttribute("select")) {
var t = this.templates[xslNode.getAttribute("select")];
if (t) {
if (xslNode.getAttribute("select") == "/")
return alert("Something went wrong. The / template was executed as a normal template");
var nodes = context.selectNodes(xslNode.getAttribute("select"));
for (var i = 0; i < nodes.length; i++)
this.parseChildren(nodes[i], t[0], t[1], result);
}
}
else {
if (xslNode.getAttribute("name")) {
var t = this.templates[xslNode.getAttribute("name")];
if (t)
this.parseChildren(context, t[0], t[1], result);
}
else {
var ncontext = context.cloneNode(true); 
var nres = this.xmlDoc.createDocumentFragment();
var nodes = ncontext.childNodes;
for (var tName, i = nodes.length - 1; i >= 0; i--) {
if (nodes[i].nodeType == 3 || nodes[i].nodeType == 4) {
continue;
}
if (!nodes[i].nodeType == 1)
continue;
var n = nodes[i];
for (tName in this.templates) {
if (tName == "/")
continue;
var t = this.templates[tName];
var snodes = n.selectNodes("self::" + tName);
for (var j = snodes.length - 1; j >= 0; j--) {
var s = snodes[j], p = s.parentNode;
this.parseChildren(s, t[0], t[1], nres);
if (nres.childNodes) {
for (var k = nres.childNodes.length - 1; k >= 0; k--)
p.insertBefore(nres.childNodes[k], s);
}
p.removeChild(s);
}
}
if (n.parentNode) {
var p = n.parentNode;
this.p["apply-templates"].call(this, n, xslNode, childStack, nres);
if (nres.childNodes) {
for (var k = nres.childNodes.length - 1; k >= 0; k--)
p.insertBefore(nres.childNodes[k], n);
}
p.removeChild(n);
}
}
for (var i = ncontext.childNodes.length - 1; i >= 0; i--)
result.insertBefore(ncontext.childNodes[i], result.firstChild);
}
}
}
},
cache   : {},
"import": function(context, xslNode, childStack, result){
var file = xslNode.getAttribute("href");
if (!this.cache[file]) {
var data = new jpf.http().get(file);
this.cache[file] = data;
}
},
"include"  : function(context, xslNode, childStack, result){},
"when"     : function(){},
"otherwise": function(){},
"copy-clone": function(context, xslNode, childStack, result){
result = result.appendChild(jpf.canImportNode ? result.ownerDocument.importNode(xslNode, false) : xslNode.cloneNode(false));
if (result.nodeType == 1) {
for (var i = 0; i < result.attributes.length; i++) {
var blah = result.attributes[i].nodeValue; 
if (!jpf.isSafariOld && result.attributes[i].nodeName.match(/^xmlns/))
continue;
result.attributes[i].nodeValue = result.attributes[i].nodeValue.replace(/\{([^\}]+)\}/g, function(m, xpath){
var xmlNode = jpf.XPath.selectNodes(xpath, context)[0];
if (!xmlNode) {
value = "";
}
else {
if (xmlNode.nodeType == 1)
value = xmlNode.firstChild ? xmlNode.firstChild.nodeValue : "";
else
value = typeof xmlNode == "object" ? xmlNode.nodeValue : xmlNode;
}
return value;
});
result.attributes[i].nodeValue; 
}
}
this.parseChildren(context, xslNode, childStack, result);
}
}
this.parseChildren = function(context, xslNode, childStack, result){
if (!childStack)
return;
for (var i = 0; i < childStack.length; i++) {
childStack[i][0].call(this, context, childStack[i][1], childStack[i][2], result);
}
};
this.compile = function(xslNode){
var nodes = xslNode.childNodes;
for (var stack = [], i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1 && nodes[i].nodeType != 3 && nodes[i].nodeType != 4)
continue;
if (nodes[i][jpf.TAGNAME] == "template") {
this.templates[nodes[i].getAttribute("match") || nodes[i].getAttribute("name")] = [nodes[i], this.compile(nodes[i])];
}
else {
if (nodes[i][jpf.TAGNAME] == "stylesheet") {
this.compile(nodes[i])
}
else {
if (nodes[i].prefix == "xsl") {
var func = this.p[nodes[i][jpf.TAGNAME]];
if (!func)
alert("xsl:" + nodes[i][jpf.TAGNAME] + " is not supported at this time on this platform");
else
stack.push([func, nodes[i], this.compile(nodes[i])]);
}
else {
stack.push([this.p["copy-clone"], nodes[i], this.compile(nodes[i])]);
}
}
}
}
return stack;
};
this.importStylesheet = function(xslDoc){
this.xslDoc = xslDoc.nodeType == 9 ? xslDoc.documentElement : xslDoc;
xslStack = this.compile(xslDoc);
this.xslStack = [[this.p["apply-templates"], null]];
};
this.transformToFragment = function(doc, newDoc){
this.xmlDoc = newDoc.nodeType != 9 ? newDoc.ownerDocument : newDoc;
var docfrag = this.xmlDoc.createDocumentFragment();
if (!jpf.isSafariOld && doc.nodeType == 9)
doc = doc.documentElement;
var result = this.parseChildren(doc, this.xslDoc, this.xslStack, docfrag);
return docfrag;
};
};
self.XSLTProcessor = jpf.XSLTProcessor;
}
jpf.url = function(str) {
var base;
if (str.indexOf(":") == -1 && (base = window.location.toString()).indexOf(":") != -1) {
base = new jpf.url(base);
str = jpf.getAbsolutePath("http://" + base.host + "/"
+ (base.directory.charAt(base.directory.length - 1) == "/"
? base.directory
: base.directory + '/'), str);
}
var o    = jpf.url.options,
m        = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
i        = 14;
this.uri = str.toString(); 
while (i--)
this[o.key[i]] = m[i] || "";
this[o.q.name] = {};
var _self = this;
this[o.key[12]].replace(o.q.parser, function($0, $1, $2){
if ($1)
_self[o.q.name][$1] = $2;
});
};
jpf.url.prototype = {
isSameLocation: function(){
if (this.uri.length && this.uri.charAt(0) == "#")
return false;
if (!this.protocol && !this.port && !this.host)
return true;
if (!this.protocol && this.host && this.port
&& window.location.hostname == this.host
&& window.location.port     == this.port) {
return true;
}
if (!this.protocol && this.host && !this.port
&& window.location.hostname == this.host
&& window.location.port     == 80) {
return true;
}
return window.location.protocol == (this.protocol + ":")
&& window.location.hostname == this.host
&& (window.location.port    == this.port || !window.location.port && !this.port);
}
};
jpf.url.options = {
strictMode: false,
key: ["source", "protocol", "authority", "userInfo", "user", "password",
"host", "port", "relative", "path", "directory", "file", "query",
"anchor"],
q  : {
name  : "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose : /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};
jpf.XSDImplementation = function(){
var typeHandlers = {
"xsd:dateTime": function(value){
value = value.replace(/-/g, "/");
value.match(/^(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2}):(\d{2})$/);
if (!RegExp.$3 || RegExp.$3.length < 4)
return false;
var dt = new Date(value);
if (dt.getFullYear() != parseFloat(RegExp.$3))
return false;
if (dt.getMonth() != parseFloat(RegExp.$2) - 1)
return false;
if (dt.getDate() != parseFloat(RegExp.$1))
return false;
if (dt.getHours() != parseFloat(RegExp.$4))
return false;
if (dt.getMinutes() != parseFloat(RegExp.$5))
return false;
if (dt.getSeconds() != parseFloat(RegExp.$5))
return false;
return true;
},
"xsd:time": function(value){
value.match(/^(\d{2}):(\d{2}):(\d{2})$/);
var dt = new Date(value);
if (dt.getHours() != parseFloat(RegExp.$1))
return false;
if (dt.getMinutes() != parseFloat(RegExp.$2))
return false;
if (dt.getSeconds() != parseFloat(RegExp.$3))
return false;
return true;
},
"xsd:date": function(value){
value = value.replace(/-/g, "/");
value.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
if (!RegExp.$3 || RegExp.$3.length < 4)
return false;
var dt = new Date(RegExp.$2 + "/" + RegExp.$1 + "/" + RegExp.$3); 
if (dt.getFullYear() != parseFloat(RegExp.$3))
return false;
if (dt.getMonth() != parseFloat(RegExp.$2) - 1)
return false;
if (dt.getDate() != parseFloat(RegExp.$1))
return false;
return true;
},
"xsd:gYearMonth": function(value){
value = value.replace(/-/g, "/");
value.match(/^\/?(\d{4})(?:\d\d)?\/(\d{2})(?:\w|[\+\-]\d{2}:\d{2})?$/);
if (!RegExp.$1 || RegExp.$1.length < 4)
return false;
var dt = new Date(value);
if (dt.getFullYear() != parseFloat(RegExp.$))
return false;
if (dt.getMonth() != parseFloat(RegExp.$2) - 1)
return false;
return true;
},
"xsd:gYear": function(value){
value.match(/^\/?(\d{4})(?:\d\d)?(?:\w|[\+\-]\d{2}:\d{2})?$/);
if (!RegExp.$1 || RegExp.$1.length < 4)
return false;
var dt = new Date(value);
if (dt.getFullYear() != parseFloat(RegExp.$1))
return false;
return true;
},
"xsd:gMonthDay": function(value){
value = value.replace(/-/g, "/");
value.match(/^\/\/(\d{2})\/(\d{2})(?:\w|[\+\-]\d{2}:\d{2})?$/);
var dt = new Date(value);
if (dt.getMonth() != parseFloat(RegExp.$1) - 1)
return false;
if (dt.getDate() != parseFloat(RegExp.$2))
return false;
return true;
},
"xsd:gDay": function(value){
value = value.replace(/-/g, "/");
value.match(/^\/{3}(\d{2})(?:\w|[\+\-]\d{2}:\d{2})?$/);
var dt = new Date(value);
if (dt.getDate() != parseFloat(RegExp.$1))
return false;
return true;
},
"xsd:gMonth": function(value){
value = value.replace(/-/g, "/");
value.match(/^\/{2}(\d{2})(?:\w|[\+\-]\d{2}:\d{2})?$/);
var dt = new Date(value);
if (dt.getMonth() != parseFloat(RegExp.$1) - 1)
return false;
return true;
},
"xsd:string": function(value){
return typeof value == "string";
},
"xsd:boolean": function(value){
return /^(true|false)$/i.test(value);
},
"xsd:base64Binary": function(value){
return true;
},
"xsd:hexBinary": function(value){
return /^(?:0x|x|#)?[A-F0-9]{0,8}$/i.test(value);
},
"xsd:float": function(value){
return parseFloat(value) == value;
},
"xsd:decimal": function(value){
return /^[0-9\.\-,]+$/.test(value);
},
"xsd:double": function(value){
return parseFloat(value) == value;
},
"xsd:anyURI": function(value){
return /^(?:\w+:\/\/)?(?:(?:[\w\-]+\.)+(?:[a-z]+)|(?:(?:1?\d?\d?|2[0-4]9|25[0-5])\.){3}(?:1?\d\d|2[0-4]9|25[0-5]))(?:\:\d+)?(?:\/([^\s\\\%]+|%[\da-f]{2})*)?$/i
.test(value);
},
"xsd:QName": function(value){
return true;
},
"xsd:normalizedString": function(value){
return true;
},
"xsd:token": function(value){
return true;
},
"xsd:language": function(value){
return true;
},
"xsd:Name": function(value){
return true;
},
"xsd:NCName": function(value){
return true;
},
"xsd:ID": function(value){
return true;
},
"xsd:IDREF": function(value){
return true;
},
"xsd:IDREFS": function(value){
return true;
},
"xsd:NMTOKEN": function(value){
return true;
},
"xsd:NMTOKENS": function(value){
return true;
},
"xsd:integer": function(value){
return parseInt(value) == value;
},
"xsd:nonPositiveInteger": function(value){
return parseInt(value) == value && value <= 0;
},
"xsd:negativeInteger": function(value){
return parseInt(value) == value && value < 0;
},
"xsd:long": function(value){
return parseInt(value) == value && value >= -2147483648
&& value <= 2147483647;
},
"xsd:int": function(value){
return parseInt(value) == value;
},
"xsd:short": function(value){
return parseInt(value) == value && value >= -32768 && value <= 32767;
},
"xsd:byte": function(value){
return parseInt(value) == value && value >= -128 && value <= 127;
},
"xsd:nonNegativeInteger": function(value){
return parseInt(value) == value && value >= 0;
},
"xsd:unsignedLong": function(value){
return parseInt(value) == value && value >= 0 && value <= 4294967295;
},
"xsd:unsignedInt": function(value){
return parseInt(value) == value && value >= 0;
},
"xsd:unsignedShort": function(value){
return parseInt(value) == value && value >= 0 && value <= 65535;
},
"xsd:unsignedByte": function(value){
return parseInt(value) == value && value >= 0 && value <= 255;
},
"xsd:positiveInteger": function(value){
return parseInt(value) == value && value > 0;
},
"xforms:listItem": function(value){
return true;
},
"xforms:listItems": function(value){
return true;
},
"xforms:dayTimeDuration": function(value){
return true;
},
"xforms:yearMonthDuration": function(value){
return true;
},
"jpf:url": function(value){
return /^\w+:\/\/([\w-]+\.)+\w{2,4}$/.test(value.trim());
},
"jpf:website": function(value){
return /^(?:http:\/\/)?([\w-]+\.)+\w{2,4}$/.test(value.trim());
},
"jpf:email": function(value){
return /^[A-Z0-9\.\_\%\-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}$/i
.test(value.trim());
},
"jpf:creditcard": function(value){
value = value.replace(/ /g, "");
value = value.pad(21, "0", jpf.PAD_LEFT);
for (var total = 0, r, i = value.length; i >= 0; i--) {
r = value.substr(i, 1) * (i % 2 + 1);
total += r > 9 ? r - 9 : r;
}
return total % 10 === 0;
},
"jpf:expdate": function(value){
value = value.replace(/-/g, "/");
value = value.split("/");
var dt = new Date(value[0] + "/01/" + value[1]);
if (dt.getYear() != parseFloat(value[1]))
return false;
if (dt.getMonth() != parseFloat(value[0]) - 1)
return false;
return true;
},
"jpf:wechars": function(value){
return /^[0-9A-Za-z\xC0-\xCF\xD1-\xD6\xD8-\xDD\xDF-\xF6\xF8-\xFF -\.',]+$/
.test(value)
},
"jpf:phonenumber": function(value){
return /^[\d\+\- \(\)]+$/.test(value)
},
"jpf:faxnumber": function(value){
return /^[\d\+\- \(\)]+$/.test(value)
},
"jpf:mobile": function(value){
return /^[\d\+\- \(\)]+$/.test(value)
}
};
var custumTypeHandlers = {};
this.parse = function(xmlNode){
if (xmlNode[jpf.TAGNAME] == "complextype")
this.parseComplexType(xmlNode);
else
if (xmlNode[jpf.TAGNAME] == "simpletype")
this.parseSimpleType(xmlNode);
else {
var i, nodes = $xmlns(xmlNode, "complextype", jpf.ns.xsd);
for (i = 0; i < nodes.length; i++)
this.parseComplexType(nodes[i]);
nodes = $xmlns(xmlNode, "simpletype", jpf.ns.xsd);
for (i = 0; i < nodes.length; i++)
this.parseSimpleType(nodes[i]);
}
};
this.getValue = function(xmlNode){
return xmlNode.nodeType == 1
? jpf.getXmlValue(xmlNode, "text()")
: xmlNode.nodeValue;
};
this.matchType = function(value, type){
if (typeHandlers[type])
return typeHandlers[type](value);
return true;
};
this.parseComplexType = function(xmlNode){
var func;
custumTypeHandlers[xmlNode.getAttribute("name")] = func;
};
var simpleTypeHandler = {
"restriction": function(xmlNode, func){
func.push("if (!jpf.XSDParser.matchType(value, '"
+ xmlNode.getAttribute("base") + "')) return false;");
var nodes = xmlNode.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (simpleTypeHandler[nodes[i][jpf.TAGNAME]])
simpleTypeHandler[nodes[i][jpf.TAGNAME]](nodes[i], func);
}
},
"list": function(xmlNode, func){},
"union": function(xmlNode, func){},
"mininclusive": function(xmlNode, func){
func.push("if (parseFloat(value) < " + xmlNode.getAttribute("value")
+ ") return false;");
},
"maxinclusive": function(xmlNode, func){
func.push("if (parseFloat(value) > " + xmlNode.getAttribute("value")
+ ") return false;");
},
"minexclusive": function(xmlNode, func){
func.push("if (parseFloat(value) => " + xmlNode.getAttribute("value")
+ ") return false;");
},
"maxexclusive": function(xmlNode, func){
func.push("if (parseFloat(value) =< " + xmlNode.getAttribute("value")
+ ") return false;");
},
"maxlength": function(xmlNode, func){
func.push("if (value.length > " + xmlNode.getAttribute("value")
+ ") return false;");
},
"minlength": function(xmlNode, func){
func.push("if (value.length < " + xmlNode.getAttribute("value")
+ ") return false;");
},
"length": function(xmlNode, func){
func.push("if (value.length != " + xmlNode.getAttribute("value")
+ ") return false;");
},
"fractiondigits": function(xmlNode, func){
func.push("if (parseFloat(value) == value && value.split('.')[1].length != "
+ xmlNode.getAttribute("value") + ") return false;");
},
"totaldigits": function(xmlNode, func){
func.push("if (new String(parseFloat(value)).length == "
+ xmlNode.getAttribute("value") + ") return false;");
},
"pattern": function(xmlNode, func){
func.push("if (!/^" + xmlNode.getAttribute("value")
.replace(/(\/|\^|\$)/g, "\\$1") + "$/.test(value)) return false;");
},
"enumeration": function(xmlNode, func){
if (func.enum_done) return;
var enum_nodes = $xmlns(xmlNode.parentNode, "enumeration", jpf.ns.xsd);
func.enum_done = true;
for (var re = [], k = 0; k < enum_nodes.length; k++)
re.push(enum_nodes[k].getAttribute("value"));
func.push("if (!/^(?:" + re.join("|") + ")$/.test(value)) return false;");
},
"maxscale": function(xmlNode, func){
},
"minscale": function(xmlNode, func){
}
};
this.parseSimpleType = function(xmlNode){
var func = [];
func.push("var value = jpf.XSDParser.getValue(xmlNode);");
var nodes = xmlNode.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (simpleTypeHandler[nodes[i][jpf.TAGNAME]])
simpleTypeHandler[nodes[i][jpf.TAGNAME]](nodes[i], func);
}
func.push("return true;");
custumTypeHandlers[xmlNode.getAttribute("name")] =
new Function('xmlNode', func.join("\n"));
};
this.checkType = function(type, xmlNode){
if (typeHandlers[type]) {
var value = this.getValue(xmlNode);
return typeHandlers[type](value);
}
else {
if (custumTypeHandlers[type]) {
return custumTypeHandlers[type](xmlNode);
}
else {
}
}
};
};
jpf.XSDParser = new jpf.XSDImplementation();
jpf.JSImplementation = function(){
var types = ['[', '{', '(', 'text', 'xpath', 'word', 'sep', 'ws', 'semi', 'sh', 'op', 'col', 'str', 'regex', 'comment'];
var closes = [']', '}', ')'];
var reParse = new RegExp();
reParse.compile("([\\w_\\.]+)|([\\s]*,[\\s]*)|([\\s]*;[\\s]*)|(\\/\\*)|(\\*\\/)|(\\/\\/)|([\\r\\n])|((?:[\\s]*)[\\$\\@\\#\\%\\^\\&\\*\\?\\!](?:[\\s]*))|([\\s]*[\\+\\-\\<\\>\\|\\=]+[\\s]*)|(\\s*\\:\\s*)|(\\s+)|(\\\\[\\\\\\{\\}\\[\\]\\\"\\'\\/])|(\\[)|(\\])|([\\s]*\\([\\s]*)|([\\s]*\\)[\\s]*)|([\\s]*\\{[\\s]*)|([\\s]*\\}[\\s]*)|(\\')|(\\\")|(\\/)", "g");
this.dump_tree = function(n, s, w){
for (var i = 0; i < n.length; i++) {
var m = n[i], t = m[0];
if (t < 3) {
s.push(w + types[t]);
this.dump_tree(m[1], s, '  ' + w);
s.push(closes[t]);
s.push('\n');
}
else {
s.push(w + types[t] + ': ' + m[1] + '\n');
}
}
return s;
};
this.parse = function(str, trim_startspace){
var err    = []; 
var tree   = []; 
var stack  = []; 
var node   = tree;
var blevel = 0, tpos = 0;
var istr   = 0, icc = 0;
var lm     = 0;
var count  = [0, 0, 0];
str.replace(reParse, function(m, word, sep, semi, c1, c2, c3, nl, sh,
op, col, ws, bs1, bo, bc, po, pc, co, cc, q1, q2, re, pos){
function add_track(t){
var txt = trim_startspace
? str.substr(tpos, pos - tpos)
.replace(/[\r\n]\s*/, '').replace(/^\s*[\r\n]/, '')
.replace(/[\r\n\t]/g, '')
: str.substr(tpos, pos - tpos).replace(/[\r\n\t]/g, '');
if (txt.length > 0) {
node[node.length] = [t, txt, tpos, pos];
}
}
function add_node(t, data){
node[node.length] = [t, data, pos];
}
function add_sub(t){
count[t]++;
var n = [];
node[node.length] = [t, n, pos];
stack[stack.length] = node;
node = n;
}
function pop_sub(t){
count[t]--;
if (stack.length == 0) {
err[err.length] = ["extra " + closes[t], pos];
}
else {
node = stack.pop();
var ot = node[node.length - 1][0];
if (ot != t) {
err[err.length] = ["scope mismatch " + types[ot] + " with " + types[t], pos];
}
}
}
if (!istr) {
if (word) {
add_node(5, m);
if (m == 'macro') 
lm = 1;
else 
if (lm) 
macros[m] = 1, lm = 0;
}
if (sep) 
add_node(6, ',');
if (ws) 
add_node(7, m);
if (semi) 
add_node(8, m);
if (sh) 
add_node(9, m);
if (op) 
add_node(10, m);
if (col) 
add_node(11, m);
if (bo) {
add_sub(0);
}
if (bc) {
pop_sub(0);
}
if (co) 
add_sub(1);
if (cc) 
pop_sub(1);
if (po) 
add_sub(2);
if (pc) 
pop_sub(2);
}
if (c3) {
if (istr == 0) {
istr = 5;
tpos = pos + 2;
}
};
if (nl) {
if (istr == 5) {
istr = 0;
pos += 1;
add_track(14);
}
}
if (q1) {
if (istr == 0) {
istr = 1;
tpos = pos;
} else 
if (istr == 1) {
istr = 0;
pos += 1;
add_track(12);
}
}
if (q2) {
if (istr == 0) {
istr = 2;
tpos = pos;
} else 
if (istr == 2) {
istr = 0;
pos += 1;
add_track(12);
}
}
if (c1) {
if (istr == 0) {
istr = 4;
tpos = pos + 2;
};
}
if (c2) {
if (istr == 4) {
istr = 0;
add_track(14);
}
}
if (re) {
if (istr == 0) {
if (node.length == 0 || node[node.length - 1][0] == 6) {
istr = 3;
tpos = pos;
} else 
add_node(10, m);
}
else 
if (istr == 3) {
istr = 0;
pos += 1;
add_track(13);
}
}
return m;
});
if (stack.length > 0) 
for (var i = stack.length - 1; i >= 0; i--) {
var j = stack[i][stack[i].length - 1];
err[err.length] = ["unclosed tag " + types[j[0]], j[2]];
}
return {
'tree' : tree,
'stack': stack,
'err'  : err,
'count': count
};
};
};
jpf.JavascriptParser = new jpf.JSImplementation();
jpf.JsltImplementation = function(){
var bigRegExp = /([\w_\.]+)|(\s*,\s*)|(\s*;\s*)|((?:\s*)[\$\@\#\%\^\&\*\?\!](?:\s*))|(\s*[\+\-\<\>\|\=]+\s*)|(\s*\:\s*)|(\\[\\\{\}\[\]\"\'\/])|(\[)|(\])|(\s*\(\s*)|(\s*\)\s*)|(\s*\{\s*)|(\s*\}\s*)|(\')|(\")|(\/)|(\s+)/g;
function isString(){
if (typeof arguments[0] == 'string') 
return true;
if (typeof arguments[0] == 'object' && arguments[0].constructor) 
return (arguments[0].constructor.toString().match(/string/i) != null);
return false;
}
function jesc(s, esc){
if (!esc) 
return s;
if (!s) 
return '';
if (esc.toLowerCase() == 'q') 
return s.replace(/&/g, "&amp;").replace(/\'/g, "\\&squot")
.replace(/\"/g, "\\&quot").replace(/\r?\n/g, "\\n");
return s;
}
function jcpy(s, n, p){
if (!n) 
return;
if (p) {
var t = n.selectNodes(p);
if (!t || t.length == 0) 
return;
for (var i = 0; i < t.length; i++) 
s[s.length] = t[i].xml;
}
else 
s[s.length] = n.xml;
}
function jxml(n, p){
if (!n) 
return;
if (p) {
var o = [];
var t = n.selectNodes(p);
if (!t || t.length == 0) 
return;
for (var i = 0; i < t.length; i++) 
o[o.length] = t[i].xml;
}
else 
return n.xml;
return o.join('');
}
function jval(n, p){
if (!n) 
return '';
if (p) 
n = n.selectSingleNode(p);
if (!n) 
return '';
if (n.nodeType == 1) 
n = n.firstChild;
return n ? n.nodeValue : '';
}
function jloc(n, f, p){
if (!n || !p) 
return;
n = isString(p) ? n.selectSingleNode(p) : p;
if (!n) 
return;
f(n);
}
function jdbg(a){
jpf.console.info(a)
}
function jnod(n, p){
if (!n) 
return '';
if (p) 
n = n.selectSingleNode(p);
if (!n) 
return null;
return n;
}
function jnds(n, p){
if (!n) 
return '';
if (p) 
n = n.selectNodes(p);
if (!n) 
return null;
return n;
}
function jexs(n, p){
if (!n) 
return false;
if (p) 
n = n.selectSingleNode(p);
return n != null;
}
function jemp(n, p){
if (!n) 
return false;
if (p) 
n = n.selectSingleNode(p);
if (!n) 
return true;
if (n.nodeType == 1) 
n = n.firstChild;
return (n ? n.nodeValue : '').match(/^[\s\r\n\t]*$/) != null;
}
function jcnt(n, p){
if (!n) 
return 0;
var t = n.selectNodes(p);
return t ? t.length : 0;
}
function jpak(n, f, p){
var s = [];
f(s, n);
return s.join('');
}
function jstore(n, pk, f, p){
if (!p) 
p = 'def';
if (!pk[p]) 
pk[p] = [];
f(pk[p], n);
return;
}
function jfetch(pk, p){
if (!p) 
p = 'def';
if (pk[p]) 
return pk[p].join('');
return '';
}
function jfra(f, t, sp, ep){
if (!t) 
return;
var end = ep == null ? t.length : Math.min(t.length, (sp + ep));
for (var i = (sp == null) ? 0 : sp; i < end; i++) 
f(i, end, t[i]);
}
function jvls(n, p){
var r = [];
if (!n) 
return r;
var t = n.selectNodes(p);
if (!t) 
return r;
for (var i = 0; i < t.length; i++) {
n = t[i];
if (n.nodeType == 1) 
n = n.firstChild;
r[i] = n ? n.nodeValue : '';
}
return r;
}
function jpar(f, str){
f ((typeof str != "string")
? str
: parseXML(str).documentElement);
}
function jfor(n, f, p, sp, ep){
if (!n) 
return;
var t = n.selectNodes(p);
var end = ep == null ? t.length : Math.min(t.length, (sp + ep));
for (var i = (sp == null) ? 0 : sp; i < end; i++) 
f(i, end, t[i]);
}
var sort_intmask = ["", "0", "00", "000", "0000", "00000", "000000",
"0000000", "00000000", "000000000", "0000000000", "00000000000",
"000000000000", "0000000000000", "00000000000000"];
var sort_dateFmtStr;
var sort_dateFormat;
var sort_dateReplace;
function sort_dateFmt(str){
sort_dateFmtStr = str;
var result = str.match(/(D+|Y+|M+|h+|m+|s+)/g);
if (!result) 
return;
for (var pos = {}, i = 0; i < result.length; i++) 
pos[result[i].substr(0, 1)] = i + 1;
sort_dateFormat = new RegExp(str.replace(/[^\sDYMhms]/g, '\\$1')
.replace(/YYYY/, "(\\d\\d\\d\\d)")
.replace(/(DD|YY|MM|hh|mm|ss)/g, "(\\d\\d)"));
sort_dateReplace = "$" + pos["M"] + "/$" + pos["D"] + "/$" + pos["Y"];
if (pos["h"]) 
sort_dateReplace += " - $" + pos["h"] + ":$" + pos["m"] + ":$" + pos["s"];
}
function sort_alpha(n){
if (!n) 
return '';
if (n.nodeType == 1) 
n = n.firstChild;
return n ? n.nodeValue : '';
}
function sort_number(n){
var t = sort_alpha(n);
return (t.length < sort_intmask.length
? sort_intmask[sort_intmask.length - t.length]
: "") + t;
}
function sort_date(n, args){
if (!sort_dateFormat || (args && sort_dateFmtStr != args[0])) 
sort_dateFmt(args ? args[0] : "*");
var t = sort_alpha(n), d;
if (sort_dateFmtStr == '*') 
d = Date.parse(t);
else 
d = (new Date(t.replace(sort_dateFormat, sort_dateReplace))).getTime();
t = "" + parseInt(d);
if (t == "NaN") 
t = "0";
return (t.length < sort_intmask.length
? sort_intmask[sort_intmask.length - t.length]
: "") + t;
}
function jsort(n, f, p, ps, sm, desc, sp, ep){
sm = sm ? sm : sort_alpha;
var sa = [], t = n.selectNodes(p), i = t.length, args = null;
if (typeof sm != "function") {
var m = sm.shift();
args = sm;
sm = m;
}
while (i--) {
n = t[i].selectSingleNode(ps);
if (n) 
sa[sa.length] = {
toString: function(){
return this.v;
},
pn: t[i],
v: sm(n, args)
};
else 
sa[sa.length] = {
toString: function(){
return this.v;
},
pn: t[i],
v: ''
};
}
sa.sort();
var end = ep == null ? sa.length : Math.min(sa.length, (sp + ep));
var start = (sp == null) ? 0 : sp;
if (desc) {
for (i = end - 1; i >= start; i--) 
f(end - i - 1, end, sa[i].pn, sa[i].v);
}
else {
for (i = start; i < end; i++) 
f(i, end, sa[i].pn, sa[i].v);
}
}
function japl(s, n, ma, p){
if (!n) 
return;
var m = n.selectNodes(p || 'node()');
for (var i = 0; i < m.length; i++) {
n = m[i];
var f = ma[0][n.tagName];
if (f) 
f(s, n);
else {
for (var k = 1; k < ma.length; k++) {
var sn = n.selectSingleNode(ma[k][0]);
if (sn) {
ma[k][1](s, sn);
break;
}
}
}
}
}
function jmat(ma, f, p){
var s = p.split(/\|/), all = true;
for (var i = 0; i < s.length; i++) {
if (!s[i].match(/^[\w_]+$/)) 
all = false;
ma[0][s[i]] = f;
}
if (!all) {
p = "self::" + p.replace(/\|/g, "|self::");
ma[ma.length] = [p, f];
}
}
function joff(n){
for (var p = n.parentNode.childNodes, i = p.length-1; i>=0; i--)
if (p[i] == n)
return i;
return '';
}
var types = ['[', '{', '(', 'text', 'xpath', 'word', 'sep', 'ws', 'semi',
'sh', 'op', 'col', 'str', 'regex'];
var closes = [']', '}', ')'];
var func = {
'last'    : [0, '(i==len-1)'],
'first'   : [0, '(i==0)'],
'offset'  : [0, 'joff(n)'],
'out'     : [0, 's[s.length]'],
'apply'   : [1, ';japl(s,n,ma,', ');'],
'copy'    : [1, ';jcpy(s,n,', ');'],
'xml'     : [1, 'jxml(n,', ')'],
'value'   : [1, 'jval(n,', ')'],
'exists'  : [1, 'jexs(n,', ')'],
'empty'   : [1, 'jemp(n,', ')'],
'values'  : [1, 'jvls(n,', ')'],
'node'    : [1, 'jnod(n,', ')'],
'nodes'   : [1, 'jnds(n,', ')'],
'count'   : [1, 'jcnt(n,', ')'],
'context' : [1, '(n=n.selectSingleNode(', '))'],
'foreach' : [2, ';jfor(n,function(i,len,n){', '},', ');'],
'sort'    : [2, ';jsort(n,function(i,len,n,sv){', '},', ');'],
'local'   : [2, ';jloc(n,function(n){', '},', ');'],
'match'   : [2, ';jmat(ma,function(s,n){', '},', ');'],
'pack'    : [2, 'jpak(n,function(s,n){', '},', ')'],
'store'   : [2, 'jstore(n,os,function(s,n){', '},', ');'],
'fetch'   : [1, 'jfetch(os,', ')'],
'parse'   : [2, 'jpar(function(n){', '},', ');'],
'forarray': [3],
'macro'   : [4],
'pragma'  : [5],
'_'       : [6]
};
var short_0 = {
'%': 's[s.length]='
};
var short_1 = {
'$': ['jval(n,', ')'],
'&': ['jnod(n,', ')'],
'@': ['(n=n.selectSingleNode(', '))'],
'~': ['jexs(n,', ')'],
'!': ['!jexs(n,', ')'],
'#': ['jcnt(n,', ')'],
'^': [';japl(s,n,ma,', ');']
};
var short_2 = {
'*': [';jfor(n,function(i,len,n){', '},', ')']
};
function dump_tree(n, s, w){
for (var i = 0; i < n.length; i++) {
var m = n[i], t = m[0];
if (t < 3) {
s.push(w + types[t]);
dump_tree(m[1], s, '&nbsp;&nbsp;' + w);
s.push(closes[t]);
s.push('\n');
} else {
s.push(w + types[t] + ': ' + m[1] + '\n');
}
}
}
this.jslt_inline = [];  
this.compile = function(str, trim_startspace){
var pre;
if (pre=str.match(/^var s\=\[(\d*)\]/)){
if (pre[1] != '')
return [this.jslt_inline[pre[1]], str];
try {
eval("var f = function(n){" + str + "};");
} catch (e) {
jpf.console.info(jpf.formatJS(str));
throw new Error("Could not parse Precompiled JSLT with: " + e.message);
}
return [f, str];
}
var err    = []; 
var tree   = []; 
var stack  = []; 
var node   = tree;
var blevel = 0, tpos = 0;
var istr   = 0, icc = 0;
var lm     = 0;
var macros = {};
str        = str.replace(/\/\*[\s\S]*?\*\//gm, "");
str.replace(bigRegExp,
function(m, word, sep, semi, sh, op, col, bs1, bo, bc, po, pc, co, cc, q1, q2, re, ws, pos){
function add_track(t){
var txt = trim_startspace ? str.substr(tpos, pos - tpos).replace(/[\r\n]\s*/, '').replace(/^\s*[\r\n]/, '').replace(/\\s/g, ' ').replace(/[\r\n\t]/g, '') : str.substr(tpos, pos - tpos).replace(/[\r\n\t]/g, '');
if (txt.length > 0) {
node[node.length] = [t, txt, tpos, pos];
}
}
function add_node(t, data){
node[node.length] = [t, data, pos];
}
function add_sub(t){
var n = [];
node[node.length] = [t, n, pos];
stack[stack.length] = node;
node = n;
}
function pop_sub(t){
if (stack.length == 0) {
err[err.length] = ["extra " + closes[t], pos];
}
else {
node = stack.pop();
var ot = node[node.length - 1][0];
if (ot != t) {
err[err.length] = ["scope mismatch " + types[ot] + " with " + types[t], pos];
}
}
}
if (blevel == 0 || (bc && blevel == 1 && !istr)) {
if (icc == 0) {
if (bo) {
add_track(3);
blevel++;
} 
if (bc) {
if (blevel == 0) 
err[err.length] = ["extra ]", pos];
else {
blevel--;
tpos = pos + 1;
}
} 
}
if (co) {
					pos+=co.indexOf('{');
add_track(3);
tpos = pos + 1;
icc++;
} 
if (cc) {
add_track(4);
tpos = pos + cc.indexOf('}') + 1;
icc--;
if (icc < 0) 
err[err.length] = ["extra }", pos];
} 
}
else {
if (!istr) {
if (word) {
add_node(5, m);
if (m == 'macro') 
lm = 1;
else 
if (lm) 
macros[m] = 1, lm = 0;
}
if (sep) 
add_node(6, ',');
if (ws) 
add_node(7, m);
if (semi) 
add_node(8, m);
if (sh) 
add_node(9, m);
if (op) 
add_node(10, m);
if (col) 
add_node(11, m);
if (bo) {
blevel++;
add_sub(0);
}
if (bc) {
blevel--;
pop_sub(0);
}
if (co) 
add_sub(1);
if (cc) 
pop_sub(1);
if (po) 
add_sub(2);
if (pc) 
pop_sub(2);
}
if (q1) {
if (istr == 0) {
istr = 1;
tpos = pos;
}
else 
if (istr == 1) {
istr = 0;
pos += 1;
add_track(12);
}
}
if (q2) {
if (istr == 0) {
istr = 2;
tpos = pos;
}
else 
if (istr == 2) {
istr = 0;
pos += 1;
add_track(12);
}
}
if (re) {
if (istr == 0) {
if (node.length == 0 || node[node.length - 1][0] == 6) {
istr = 3;
tpos = pos;
} else 
add_node(10, m);
}
else 
if (istr == 3) {
istr = 0;
pos += 1;
add_track(13);
}
}
}
return m;
});
if (blevel == 0) {
var txt = str.substr(tpos, str.length - tpos).replace(/[\r\n\t]/g, '');
if (txt.length > 0) {
node[node.length] = [3, txt, tpos, str.length];
}
}
if (stack.length > 0) 
for (var i = stack.length - 1; i >= 0; i--) {
var j = stack[i][stack[i].length - 1];
err[err.length] = ["unclosed tag " + types[j[0]], j[2]];
}
var s = ['var s=[],ma=[{}],os={};'];
var pragma_trace = 0;
function line_pos(cpos){
var l = 0;
str.replace(/\n/g, function(m, pos){
if (pos < cpos) 
l++;
return m;
});
return l;
}
function compile_recur(s, n, offset){
var k = n.length;
var d, e;
for (var i = ((offset == null) ? 0 : offset); i < k; i++) {
var t = n[i][0];
if (t == 5) {
var nt1 = (i < k - 1) ? n[i + 1][0] : -1, nt2 = (i < k - 2) ? n[i + 2][0] : -1;
var m = n[i][1];
var d = func[m];
if (d) {
switch (d[0]) {
case 0:
s[s.length] = d[1];
break;
case 1: 
if (nt1 != 2) {
err[err.length] = ["Function " + m + " syntax error", n[i][2]];
}
else {
s[s.length] = d[1];
if (!compile_recur(s, n[i + 1][1])) 
s[s.length] = 'null';
s[s.length] = d[2];
i++;
}
break;
case 2: 
if (nt1 != 2 || nt2 != 1) {
err[err.length] = ["Function " + m + " syntax error", n[i][2]];
}
else {
s[s.length] = d[1];
compile_recur(s, n[i + 2][1]);
s[s.length] = d[2];
if (!compile_recur(s, n[i + 1][1])) 
s[s.length] = 'null';
s[s.length] = d[3];
i += 2;
}
break;
case 3:
var o, ok;
if (i > k - 3 || n[i + 1][0] != 2 || n[i + 2][0] != 1 || (o = n[i + 1][1])[0][0] != 5 ||
(ok = o.length) < 5 ||
o[1][0] != 7 ||
o[2][0] != 5 ||
o[2][1] != 'in') {
err[err.length] = ["forarray syntax error", n[i][2]];
}
else {
s[s.length] = ';jfra(function(i,len,' + o[0][1] + '){';
compile_recur(s, n[i + 2][1]);
s[s.length] = '},';
compile_recur(s, o, 3);
s[s.length] = ');';
i += 2;
}
break;
case 4:
if (i >= k - 4 || n[i + 1][0] != 7 || n[i + 2][0] != 5 || n[i + 3][0] != 2 || n[i + 4][0] != 1) {
err[err.length] = ["macro syntax error at", n[0][2]];
}
else {
s[s.length] = 'function ' + n[i + 2][1] + '(s,n,';
if (!compile_recur(s, n[i + 3][1])) 
s[s.length] = 'null';
s[s.length] = '){';
compile_recur(s, n[i + 4][1]);
s[s.length] = '}';
i += 4;
}
break;
case 5:
{
if (i >= k - 3 || n[i + 1][0] != 7 || n[i + 2][0] != 5 || n[i + 3][0] != 2) {
err[err.length] = ["macro syntax error at", n[0][2]];
}
else {
switch (n[i + 2][1]) {
case 'trace':{
var ts = [];
compile_recur(ts, n[i + 3][1]);
pragma_trace = eval(ts.join(''));
}
break;
}
}
i += 3;
}
case 6:
{
s[s.length] = ';alert("Trace: ' + line_pos(n[i][2]) + '");';
}
}
}
else {
if (macros[m] && nt1 == 2) {
s[s.length] = m + '(s,n,';
if (!compile_recur(s, n[i + 1][1])) 
s[s.length] = 'null';
s[s.length] = ')';
i++;
}
else 
s[s.length] = m;
}
}
else 
if (t == 9) {
var nt1 = (i < k - 1) ? n[i + 1][0] : -1, nt2 = (i < k - 2) ? n[i + 2][0] : -1;
var m = n[i][1];
if (nt1 == 12) {
if (nt2 == 1) {
if (d = short_2[m]) {
s[s.length] = d[0];
compile_recur(s, n[i + 2][1]);
s[s.length] = d[1] + n[i + 1][1] + d[2];
i += 2;
lt = 1;
} else 
s[s.length] = m;
}
else {
if (d = short_1[m]) {
if (nt2 == 11) 
s[s.length] = m;
else {
s[s.length] = d[0] + n[i + 1][1] + d[1];
i++;
}
} else {
if (d = short_0[m]) 
s[s.length] = d;
else 
s[s.length] = m;
}
}
}
else {
if (d = short_0[m]) 
s[s.length] = d;
else 
s[s.length] = m;
}
}
else { 
if (t < 3) {
s[s.length] = types[t];
compile_recur(s, n[i][1]);
s[s.length] = closes[t];
if ((t == 1 && i < k - 1 && n[i + 1][0] == 5 && n[i + 1][1] != 'else') || 
(t == 2 && i < k - 1 && n[i + 1][0] == 5 && !n[i + 1][1].match(/^\./) && 
(i == 0 || n[i - 1][0] != 5 || !n[i - 1][1].match(/^(if|for)$/)))) {
s[s.length] = ';';
}
}
else {
if (t == 3) 
s[s.length] = ';s[s.length]="' + n[i][1]
.replace(/\"/g, "\\\"").replace(/\n/g, "\\n") + '";';
else 
if (t == 4) {
var m = n[i][1].match(/^\^([\w])\s?/);
if (m) {
s[s.length] = ';s[s.length]=jesc(jval(n,"'
+ n[i][1].substr(2)
.replace(/"/g, "\\\"") + '"),"' + m[1] + '");';
} else {
s[s.length] = ';s[s.length]=jval(n,"'
+ n[i][1].replace(/"/g, "\\\"") + '");';
}
}
else 
s[s.length] = n[i][1];
}
}
//lt = n[i][0];
}
return k;
}
if (err.length == 0) 
compile_recur(s, tree);
// return all parse errors
if (err.length > 0) {
var e = [];
for (var i = 0; i < err.length; i++) {
e[e.length] = 'Parse error(' + line_pos(err[i][1]) + '): ' + err[i][0] + '\n';
}
// lets spit out our parse tree
//var out=[];
//dump_tree(tree,out,'');
throw new Error("Could not parse JSLT with: " + e.join('') + "\n");
}
s[s.length] = ";return s.join('');";
var strJS = s.join('');
try {
eval("var f = function(n){" + strJS + "};");
}
catch (e) {
//var treedump=[];
//dump_tree(tree,treedump,'');	
jpf.console.info(jpf.formatJS(strJS));
throw new Error("Could not parse JSLT with: " + e.message );
}
return [f, strJS];
};
this.cache = [];
this.apply = function(jsltNode, xmlNode){
var jsltFunc, cacheId, jsltStr, doTest;
//Type detection xmlNode
xmlNode = jpf.xmldb.getBindXmlNode(xmlNode);
//Type detection jsltNode
if (typeof jsltNode == "object") {
//check the jslt node for cache setting
cacheId = jsltNode.getAttribute("cache");
jsltFunc = this.cache[cacheId];
if (!jsltFunc) {
var jsltStr = [], textNodes = jsltNode.selectNodes('text()');
for (var i = 0; i < textNodes.length; i++) {
jsltStr = textNodes[i].nodeValue;
if (jsltStr.trim()) 
break;
}
}
}
else {
cacheId = jsltNode;
jsltFunc = this.cache[cacheId];
if (!jsltFunc) {
jsltStr = jsltNode;
cacheId = null;
}
}
//Compile string
if (!jsltFunc) 
jsltFunc = this.compile(jsltStr);
this.lastJslt = jsltStr;
this.lastJs   = jsltFunc[0]; //if it crashes here there is something seriously wrong
//Invalid code - Syntax Error
if (!jsltFunc[0]) 
return false;
//Caching
if (!cacheId) {
if (typeof jsltNode == "object") {
cacheId = this.cache.push(jsltFunc) - 1
jsltNode.setAttribute("cache", cacheId);
}
else 
this.cache[jsltStr] = jsltFunc;
}
//Execute JSLT
try {
if (!xmlNode) 
return '';
return jsltFunc[0](xmlNode);
}
catch (e) {
jpf.console.info(jpf.formatJS(jsltFunc[1]));
throw new Error(jpf.formatErrorString(0, null, "JSLT parsing", "Could not execute JSLT with: " + e.message));
}
};
};
jpf.JsltInstance = new jpf.JsltImplementation();
jpf.runXpath = function(){
jpf.XPath = {
cache : {},
getSelf : function(htmlNode, tagName, info, count, num, sResult){
var numfound = 0, result = null, data = info[count];
if (data)
data[0](htmlNode, data[1], info, count + 1, numfound++ , sResult);
else
sResult.push(htmlNode);
},
getChildNode : function(htmlNode, tagName, info, count, num, sResult){
var numfound = 0, result = null, data = info[count];
var nodes = htmlNode.childNodes;
if (!nodes) return; //Weird bug in Safari
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1)
continue;
if (tagName && (tagName != nodes[i].tagName) && (nodes[i].style
? nodes[i].tagName.toLowerCase()
: nodes[i].tagName) != tagName)
continue;// || numsearch && ++numfound != numsearch
if (data)
data[0](nodes[i], data[1], info, count + 1, numfound++ , sResult);
else
sResult.push(nodes[i]);
}
//commented out :  && (!numsearch || numsearch == numfound)
},
doQuery : function(htmlNode, qData, info, count, num, sResult){
var result = null, data = info[count];
var query = qData[0];
var returnResult = qData[1];
try {
var qResult = eval(query);
}catch(e){
return;
}
if (returnResult)
return sResult.push(qResult);
if (!qResult) return;
if (data)
data[0](htmlNode, data[1], info, count + 1, 0, sResult);
else
sResult.push(htmlNode);
},
getTextNode : function(htmlNode, empty, info, count, num, sResult){
var result = null, data = info[count];
var nodes = htmlNode.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 3 && nodes[i].nodeType != 4)
continue;
if (data)
data[0](nodes[i], data[1], info, count + 1, i, sResult);
else
sResult.push(nodes[i]);
}
},
getAnyNode : function(htmlNode, empty, info, count, num, sResult){
var result = null, data = info[count];
var sel = [], nodes = htmlNode.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (data)
data[0](nodes[i], data[1], info, count + 1, i, sResult);
else
sResult.push(nodes[i]);
}
},
getAttributeNode : function(htmlNode, attrName, info, count, num, sResult){
if (!htmlNode || htmlNode.nodeType != 1) return;
var result = null, data = info[count];
var value = htmlNode.getAttributeNode(attrName);//htmlNode.attributes[attrName];//
if (data)
data[0](value, data[1], info, count + 1, 0, sResult);
else if (value)
sResult.push(value);
},
getAllNodes : function(htmlNode, x, info, count, num, sResult){
var result   = null, data = info[count];
var tagName  = x[0];
var inclSelf = x[1];
var prefix   = x[2];
if (inclSelf && (htmlNode.tagName == tagName || tagName == "*")) {
if (data)
data[0](htmlNode, data[1], info, count + 1, 0, sResult);
else
sResult.push(htmlNode);
}
var nodes = htmlNode.getElementsByTagName((prefix
&& (jpf.isGecko || jpf.isOpera) ? prefix + ":" : "") + tagName);
for (var i = 0; i < nodes.length; i++) {
if (data)
data[0](nodes[i], data[1], info, count + 1, i, sResult);
else
sResult.push(nodes[i]);
}
},
getAllAncestorNodes : function(htmlNode, x, info, count, num, sResult){
var result   = null, data = info[count];
var tagName  = x[0];
var inclSelf = x[1];
var prefix   = x[2];
var i = 0, s = inclSelf ? htmlNode : htmlNode.parentNode;
while (s && s.nodeType == 1) {
if (s.tagName == tagName || tagName == "*" || tagName == "node()") {
if (data)
data[0](s, data[1], info, count + 1, ++i, sResult);
else
sResult.push(s);
}
s = s.parentNode
}
},
getParentNode : function(htmlNode, empty, info, count, num, sResult){
var result = null, data = info[count];
var node   = htmlNode.parentNode;
if (data)
data[0](node, data[1], info, count + 1, 0, sResult);
else if (node)
sResult.push(node);
},
//precsiblg[3] might not be conform spec
getPrecedingSibling : function(htmlNode, tagName, info, count, num, sResult){
var result = null, data = info[count];
var node = htmlNode.previousSibling;
while (node) {
if (tagName != "node()" && (node.style
? node.tagName.toLowerCase()
: node.tagName) != tagName){
node = node.previousSibling;
continue;
}
if (data)
data[0](node, data[1], info, count+1, 0, sResult);
else if (node) {
sResult.push(node);
break;
}
}
},
//flwsiblg[3] might not be conform spec
getFollowingSibling : function(htmlNode, tagName, info, count, num, sResult){
var result = null, data = info[count];
var node = htmlNode.nextSibling;
while (node) {
if (tagName != "node()" && (node.style
? node.tagName.toLowerCase()
: node.tagName) != tagName) {
node = node.nextSibling;
continue;
}
if (data)
data[0](node, data[1], info, count+1, 0, sResult);
else if (node) {
sResult.push(node);
break;
}
}
},
multiXpaths : function(contextNode, list, info, count, num, sResult){
for (var i = 0; i < list.length; i++) {
info = list[i][0];
var rootNode = (info[3]
? contextNode.ownerDocument.documentElement
: contextNode);//document.body
info[0](rootNode, info[1], list[i], 1, 0, sResult);
}
sResult.makeUnique();
},
compile : function(sExpr){
var isAbsolute = sExpr.match(/^\//);//[^\/]/
sExpr = sExpr.replace(/\[(\d+)\]/g, "/##$1");
sExpr = sExpr.replace(/\|\|(\d+)\|\|\d+/g, "##$1");
sExpr = sExpr.replace(/\.\|\|\d+/g, ".");
sExpr = sExpr.replace(/\[([^\]]*)\]/g, function(match, m1){
return "/##" + m1.replace(/\|/g, "_@_");
}); //wrong assumption think of |
if(sExpr == "/" || sExpr == ".") return sExpr;
//Mark // elements
//sExpr = sExpr.replace(/\/\//g, "/[]/self::");
sExpr = sExpr.replace(/\/\//g, "descendant::");
//Check if this is an absolute query
return this.processXpath(sExpr, isAbsolute);
},
processXpath : function(sExpr, isAbsolute){
var results = new Array();
sExpr = sExpr.replace(/('[^']*)\|([^']*')/g, "$1_@_$2");
sExpr = sExpr.split("\|");
for (var i = 0; i < sExpr.length; i++)
sExpr[i] = sExpr[i].replace(/_\@\_/g, "|");//replace(/('[^']*)\_\@\_([^']*')/g, "$1|$2");
if (sExpr.length == 1)
sExpr = sExpr[0];
else {
for (var i = 0; i < sExpr.length; i++)
sExpr[i] = this.processXpath(sExpr[i]);
results.push([this.multiXpaths, sExpr]);
return results;
}
var sections   = sExpr.split("/");
for (var i = 0; i < sections.length; i++) {
if (sections[i] == "." || sections[i] == "")
continue;
else if (sections[i] == "..")
results.push([this.getParentNode, null]);
else if (sections[i].match(/^[\w-_\.]+(?:\:[\w-_\.]+){0,1}$/))
results.push([this.getChildNode, sections[i]]);//.toUpperCase()
else if (sections[i].match(/^\#\#(\d+)$/))
results.push([this.doQuery, ["num+1 == " + parseInt(RegExp.$1)]]);
else if (sections[i].match(/^\#\#(.*)$/)) {
//FIX THIS CODE
var query = RegExp.$1;
var m = [query.match(/\(/g), query.match(/\)/g)];
if (m[0] || m[1]) {
while (!m[0] && m[1] || m[0] && !m[1]
|| m[0].length != m[1].length){
if (!sections[++i]) break;
query += "/" + sections[i];
m = [query.match(/\(/g), query.match(/\)/g)];
}
}
results.push([this.doQuery, [this.compileQuery(query)]]);
}
else if (sections[i] == "*")
results.push([this.getChildNode, null]); //FIX - put in def function
else if (sections[i].substr(0,2) == "[]")
results.push([this.getAllNodes, ["*", false]]);//sections[i].substr(2) ||
else if (sections[i].match(/descendant-or-self::node\(\)$/))
results.push([this.getAllNodes, ["*", true]]);
else if (sections[i].match(/descendant-or-self::([^\:]*)(?:\:(.*)){0,1}$/))
results.push([this.getAllNodes, [RegExp.$2 || RegExp.$1, true, RegExp.$1]]);
else if (sections[i].match(/descendant::([^\:]*)(?:\:(.*)){0,1}$/))
results.push([this.getAllNodes, [RegExp.$2 || RegExp.$1, false, RegExp.$1]]);
else if (sections[i].match(/ancestor-or-self::([^\:]*)(?:\:(.*)){0,1}$/))
results.push([this.getAllAncestorNodes, [RegExp.$2 || RegExp.$1, true, RegExp.$1]]);
else if (sections[i].match(/ancestor::([^\:]*)(?:\:(.*)){0,1}$/))
results.push([this.getAllAncestorNodes, [RegExp.$2 || RegExp.$1, false, RegExp.$1]]);
else if (sections[i].match(/^\@(.*)$/))
results.push([this.getAttributeNode, RegExp.$1]);
else if (sections[i] == "text()")
results.push([this.getTextNode, null]);
else if (sections[i] == "node()")
results.push([this.getAnyNode, null]);//FIX - put in def function
else if (sections[i].match(/following-sibling::(.*)$/))
results.push([this.getFollowingSibling, RegExp.$1.toLowerCase()]);
else if (sections[i].match(/preceding-sibling::(.*)$/))
results.push([this.getPrecedingSibling, RegExp.$1.toLowerCase()]);
else if (sections[i] == "self::node()")
results.push([this.getSelf, null]);
else if (sections[i].match(/self::(.*)$/))
results.push([this.doQuery, ["jpf.XPath.doXpathFunc('local-name', htmlNode) == '" + RegExp.$1 + "'"]]);
else {
var query = sections[i];
//@todo FIX THIS CODE
//add some checking here
var m = [query.match(/\(/g), query.match(/\)/g)];
if (m[0] || m[1]) {
while (!m[0] && m[1] || m[0] && !m[1] || m[0].length != m[1].length) {
if (!sections[++i]) break;
query += "/" + sections[i];
m = [query.match(/\(/g), query.match(/\)/g)];
}
}
results.push([this.doQuery, [this.compileQuery(query), true]])
//throw new Error("---- Javeline Error ----\nMessage : Could not match XPath statement: '" + sections[i] + "' in '" + sExpr + "'");
}
}
results[0][3] = isAbsolute;
return results;
},
compileQuery : function(code){
var c = new jpf.CodeCompilation(code);
return c.compile();
},
doXpathFunc : function(type, arg1, arg2, arg3){
switch(type){
case "not":
return !arg1;
case "position()":
return num == arg1;
case "format-number":
return jpf.formatNumber(arg1); //@todo this should actually do something
case "floor":
return Math.floor(arg1);
case "ceiling":
return Math.ceil(arg1);
case "starts-with":
return arg1 ? arg1.substr(0, arg2.length) == arg2 : false;
case "string-length":
return arg1 ? arg1.length : 0;
case "count":
return arg1 ? arg1.length : 0;
case "last":
return arg1 ? arg1[arg1.length-1] : null;
case "local-name":
return arg1 ? arg1.tagName : "";//[jpf.TAGNAME]
case "substring":
return arg1 && arg2 ? arg1.substring(arg2, arg3 || 0) : "";
case "contains":
return arg1 && arg2 ? arg1.indexOf(arg2) > -1 : false;
case "concat":
for (var str="", i = 1; i < arguments.length; i++) {
if (typeof arguments[i] == "object") {
str += getNodeValue(arguments[i][0]);
continue;
}
str += arguments[i];
}
return str;
}
},
selectNodeExtended : function(sExpr, contextNode, match){
var sResult = this.selectNodes(sExpr, contextNode);
if (sResult.length == 0) return null;
if (!match) return sResult[0];
for (var i = 0; i < sResult.length; i++) {
if(getNodeValue(sResult[i]) == match)
return sResult[i];
}
return null;
},
selectNodes : function(sExpr, contextNode){
if (!this.cache[sExpr])
this.cache[sExpr] = this.compile(sExpr);
if (typeof this.cache[sExpr] == "string"){
if (this.cache[sExpr] == ".")
return [contextNode];
if (this.cache[sExpr] == "/")
return [(contextNode.nodeType == 9
? contextNode
: contextNode.ownerDocument).documentElement];
}
if (typeof this.cache[sExpr] == "string" && this.cache[sExpr] == ".")
return [contextNode];
var info = this.cache[sExpr][0];
var rootNode = (info[3]
? (contextNode.nodeType == 9
? contextNode
: contextNode.ownerDocument).documentElement
: contextNode);//document.body*/
var sResult = [];
info[0](rootNode, info[1], this.cache[sExpr], 1, 0, sResult);
return sResult;
}
};
function getNodeValue(sResult){
if (sResult.nodeType == 1)
return sResult.firstChild ? sResult.firstChild.nodeValue : "";
if (sResult.nodeType > 1 || sResult.nodeType < 5)
return sResult.nodeValue;
return sResult;
}
jpf.CodeCompilation = function(code){
this.data = {
F : [],
S : [],
I : [],
X : []
};
this.compile = function(){
code = code.replace(/ or /g, " || ");
code = code.replace(/ and /g, " && ");
code = code.replace(/!=/g, "{}");
code = code.replace(/=/g, "==");
code = code.replace(/\{\}/g, "!=");
// Tokenize
this.tokenize();
// Insert
this.insert();
code = code.replace(/, \)/g, ", htmlNode)");
return code;
};
this.tokenize = function(){
//Functions
var data = this.data.F;
code = code.replace(/(format-number|contains|substring|local-name|last|node|position|round|starts-with|string|string-length|sum|floor|ceiling|concat|count|not)\s*\(/g,
function(d, match){
return (data.push(match) - 1) + "F_";
}
);
//Strings
var data = this.data.S;
code = code.replace(/'([^']*)'/g, function(d, match){
return (data.push(match) - 1) + "S_";
});
code = code.replace(/"([^"]*)"/g, function(d, match){
return (data.push(match) - 1) + "S_";}
);
var data = this.data.X;
code = code.replace(/(^|\W|\_)([\@\.\/A-Za-z][\.\@\/\w]*(?:\(\)){0,1})/g,
function(d, m1, m2){
return m1 + (data.push(m2) - 1) + "X_";
});
code = code.replace(/(\.[\.\@\/\w]*)/g, function(d, m1, m2){
return (data.push(m1) - 1) + "X_";
});
var data = this.data.I;
code = code.replace(/(\d+)(\W)/g, function(d, m1, m2){
return (data.push(m1) - 1) + "I_" + m2;
});
};
this.insert = function(){
var data = this.data;
code = code.replace(/(\d+)X_\s*==\s*(\d+S_)/g, function(d, nr, str){
return "jpf.XPath.selectNodeExtended('"
+  data.X[nr].replace(/'/g, "\\'") + "', htmlNode, " + str + ")";
});
code = code.replace(/(\d+)([FISX])_/g, function(d, nr, type){
var value = data[type][nr];
if (type == "F") {
return "jpf.XPath.doXpathFunc('" + value + "', ";
}
else if (type == "S") {
return "'" + value + "'";
}
else if (type == "I") {
return value;
}
else if (type == "X") {
return "jpf.XPath.selectNodeExtended('"
+ value.replace(/'/g, "\\'") + "', htmlNode)";
}
});
};
};
}
jpf.profiler = {
stackTrace     : {},    
previousStack  : null,  
isRunning      : false, 
pointers       : {},    
hasPointers    : false, 
precision      : 3,     
runs           : 0,     
sortMethod     : 2,     
startBusy      : false, 
startQueue     : [],    
startQueueTimer: null,  
endBusy        : false, 
endQueue       : [],    
endQueueTimer  : null,  
init: function() {
var i, j, obj, objName, pName, canProbe;
for (i = 0; i < arguments.length; i += 2) {
if (typeof arguments[i] == "object") {
obj = arguments[i];
if (obj == this) 
continue;
if (!obj || (typeof obj['__profilerId'] != "undefined" && (!obj.prototype
|| obj.prototype.$profilerId != obj.$profilerId))) 
continue;
if (obj.nodeType) 
continue;
obj.$profilerId = this.recurDetect.push(obj) - 1;
objName = arguments[(i + 1)];
if (objName.indexOf('contentDocument') > -1)
alert(1);
for (j in obj) {
pName = objName + "." + j;
canProbe = false;
try {
var tmp  = typeof obj[j];
canProbe = true;
}
catch(e) {}
if (canProbe === false)
continue;
if (typeof obj[j] == "function" && typeof obj[j]['nameSelf'] == "undefined") {
obj[j].nameSelf = pName;
this.pointers['pointer_to_' + pName] = obj[j];
var k, props = {};
for (k in obj[j]) props[k] = obj[j][k];
var _proto = obj[j].prototype ? obj[j].prototype : null;
obj[j] = Profiler_functionTemplate();
for (k in props) obj[j][k] = props[k];
if (_proto) {
obj[j].prototype = _proto;
this.init(_proto, pName + '.prototype');
}
obj[j].nameSelf = pName;
if (!this.hasPointers)
this.hasPointers = true;
}
else if (typeof obj[j] == "object") {
this.init(obj[j], pName);
}
}
}
}
},
recurDetect : [],
uniqueNumber: 0,
wrapFunction: function(func){
var pName = "anonymous" + this.uniqueNumber++;
func.nameSelf = pName;
this.pointers['pointer_to_' + pName] = func;
func = Profiler_functionTemplate();
func.nameSelf = pName;
},
reinit: function() {
this.stackTrace     = {}
this.previousStack  = null;
this.isRunning      = false;
this.startBusy      = this.endBusy = false;
this.startQueue     = [];
this.endQueue       = [];
this.endQueueTimer  = this.startQueueTimer = null;
this.init.apply(this, arguments);
},
isInitialized: function() {
return (this.hasPointers === true);
},
registerStart: function(sName) {
if (this.isRunning) {
if (this.startBusy) {
if (sName) this.startQueue.push(sName);
this.startQueueTimer = setTimeout("jpf.profiler.registerStart()", 200);
}
else {
this.startBusy = true;
clearTimeout(this.startQueueTimer);
var todo = (this.startQueue.length) ? this.startQueue : [];
this.startQueue = [];
if (sName) todo.push(sName);
for (var i = 0; i < todo.length; i++) {
if (!this.stackTrace[todo[i]]) {
this.stackTrace[todo[i]] = {
called      : 1,
fullName    : sName,
internalExec: 0,
executions  : [[new Date(), null]]
};
}
else {
this.stackTrace[todo[i]].called++;
this.stackTrace[todo[i]].executions.push([new Date(), null]);
}
}
this.startBusy = false;
}
}
},
registerEnd: function(sName) {
if (this.isRunning) {
if (!this.stackTrace[sName]) return;
if (this.endBusy) {
if (sName)
this.endQueue.push([sName, arguments.callee.caller.caller
? arguments.callee.caller.caller.nameSelf
: null]);
this.endQueueTimer = setTimeout("jpf.profiler.registerEnd()", 200);
}
else {
this.endBusy = true;
clearTimeout(this.endQueueTimer);
var todo = (this.endQueue.length) ? this.endQueue : [];
this.endQueue = [];
if (sName)
todo.push([sName, arguments.callee.caller.caller
? arguments.callee.caller.caller.nameSelf
: null]);
for (var i = 0; i < todo.length; i++) {
iLength = this.stackTrace[todo[i][0]].executions.length - 1;
if (this.stackTrace[todo[i][0]].executions[iLength][1] == null) {
this.stackTrace[todo[i][0]].executions[iLength][1] = new Date();
if (todo[i][1] && this.stackTrace[todo[i][1]]) {
this.stackTrace[todo[i][1]].internalExec += 
this.stackTrace[todo[i][0]].executions[iLength][1]
- this.stackTrace[todo[i][0]].executions[iLength][0];
}
}
}
this.endBusy = false;
}
}
},
start: function() {
this.reset();
this.isRunning = true;
},
stop: function() {
if (this.isRunning) this.runs++;
this.isRunning = false;
return this.report();
},
reset: function() {
delete this.stackTrace;
this.stackTrace = {};
this.isRunning  = false;
},
report: function() {
var i, j, dur, stack, trace, callsNo;
this.stackTrace.totalCalls = this.stackTrace.totalAvg = this.stackTrace.totalDur = 0;
for (i in this.stackTrace) {
if (!this.stackTrace[i].fullName) continue;
stack = this.stackTrace[i];
callsNo = stack.executions.length;
stack.time = stack.max = 0;
stack.min = Infinity;
for (j = 0; j < stack.executions.length; j++) {
trace = stack.executions[j];
dur   = (trace[1] - trace[0]);
if (isNaN(dur) || !isFinite(dur) || dur < 0) dur = 0;
if (stack.max < dur)
stack.max = dur;
if (stack.min > dur)
stack.min = dur;
else if (stack.min == Infinity && stack.max > 0)
stack.min = stack.max;
stack.time += dur;
}
stack.avg = stack.time / callsNo;
stack.avg = parseFloat(((isNaN(stack.avg) || !isFinite(stack.avg)) ? 0 : stack.avg).toFixed(this.precision));
stack.min = parseFloat(((isNaN(stack.min) || !isFinite(stack.min)) ? 0 : stack.min).toFixed(this.precision));
stack.max = parseFloat(stack.max.toFixed(this.precision));
this.stackTrace.totalCalls += callsNo;
this.stackTrace.totalDur   += stack.time;
}
this.stackTrace.totalDur = parseFloat(this.stackTrace.totalDur.toFixed(this.precision));
this.stackTrace.totalAvg = parseFloat(this.stackTrace.totalDur / this.stackTrace.totalCalls);
this.stackTrace.totalAvg = parseFloat(this.stackTrace.totalAvg.toFixed(this.precision));
return this.buildReport(this.stackTrace);
},
buildReport: function(stackTrace, withContainer) {
if (typeof wihContainer == "undefined") withContainer = true;
var out = withContainer ? ['<div id="profiler_report_' + this.runs + '">'] : [''];
var row0      = '#fff';
var row1      = '#f5f5f5';
var funcColor = '#006400';
var active    = "background: url(./core/debug/resources/tableHeaderSorted.gif) repeat-x top left;";
out.push('<table border="0" style="border: 1px solid #d7d7d7; width: 100%; margin: 0 4px 0 0; padding: 0;" cellpadding="2" cellspacing="0">\
<tr style="\
background:#d9d9d9 url(./core/debug/resources/tableHeader.gif) repeat-x top left;\
height: 16px;\
cursor: hand;\
cursor: pointer;\
">\
<th style="\
border-right: 1px solid #9c9c9c;\
border-left: 1px solid #d9d9d9;\
border-bottom: 1px solid #9c9c9c;\
padding: 0; margin: 0;',
(this.sortMethod == jpf.profiler.SORT_BY_FUNCTIONNAME ? active : ""),
'" rel="3" \
onclick="jpf.debugwin.resortResult(this);" \
title="" width="110">Function</th>\
<th style="\
border-right: 1px solid #9c9c9c;\
border-left: 1px solid #d9d9d9;\
border-bottom: 1px solid #9c9c9c;\
padding: 0; margin: 0;',
(this.sortMethod == jpf.profiler.SORT_BY_CALLS ? active : ""),
'" rel="1" \
onclick="jpf.debugwin.resortResult(this);"\
title="Number of times function was called.">Calls</th>\
<th style="\
border-right: 1px solid #9c9c9c;\
border-left: 1px solid #d9d9d9;\
border-bottom: 1px solid #9c9c9c;\
padding: 0; margin: 0;',
(this.sortMethod == jpf.profiler.SORT_BY_PERCENTAGE ? active : ""),
'" rel="2" \
onclick="jpf.debugwin.resortResult(this);" \
title="Percentage of time spent on this function.">Percentage</th>\
<th style="\
border-right: 1px solid #9c9c9c;\
border-left: 1px solid #d9d9d9;\
border-bottom: 1px solid #9c9c9c;\
padding: 0; margin: 0;',
(this.sortMethod == jpf.profiler.SORT_BY_OWNTIME ? active : ""),
'" rel="8" \
onclick="jpf.debugwin.resortResult(this);" \
title="Time spent in function, excluding nested calls.">Own Time</th>\
<th style="\
border-right: 1px solid #9c9c9c;\
border-left: 1px solid #d9d9d9;\
border-bottom: 1px solid #9c9c9c;\
padding: 0; margin: 0;',
(this.sortMethod == jpf.profiler.SORT_BY_TIME ? active : ""),
'" rel="4" \
onclick="jpf.debugwin.resortResult(this);" \
title="Time spent in function, including nested calls.">Time</th>\
<th style="\
border-right: 1px solid #9c9c9c;\
border-left: 1px solid #d9d9d9;\
border-bottom: 1px solid #9c9c9c;\
padding: 0; margin: 0;',
(this.sortMethod == jpf.profiler.SORT_BY_AVERAGE ? active : ""),
'" rel="5" \
onclick="jpf.debugwin.resortResult(this);" \
title="Average time, including function calls.">Avg</th>\
<th style="\
border-right: 1px solid #9c9c9c;\
border-left: 1px solid #d9d9d9;\
border-bottom: 1px solid #9c9c9c;\
padding: 0; margin: 0;',
(this.sortMethod == jpf.profiler.SORT_BY_MINIMUM ? active : ""),
'" rel="6" \
onclick="jpf.debugwin.resortResult(this);" \
title="Minimum time, including function calls.">Min</th>\
<th style="\
border-right: 1px solid #9c9c9c;\
border-left: 1px solid #d9d9d9;\
border-bottom: 1px solid #9c9c9c;\
padding: 0; margin: 0;',
(this.sortMethod == jpf.profiler.SORT_BY_MAXIMUM ? active : ""),
'" rel="7" \
onclick="jpf.debugwin.resortResult(this);" \
title="Maximum time, including function calls.">Max</th>\
</tr>');
var rowColor, sortedStack = this.sortStack(stackTrace);
for (i = 0; i < sortedStack.length; i++) {
stack = stackTrace[sortedStack[i][0]];
rowColor = (i % 2 == 0) ? row0 : row1;
out.push('<tr style="background-color: ', rowColor, '; padding: 0; margin: 0; ">\
<td class="functionname" style="\
color: ', funcColor, ';\
font-family: Monaco, Courier New;\
font-size: 10px;\
">' + stack.fullName + '</td>\
<td class="callscount">' + stack.executions.length + '</td>\
<td class="duration_percentage">' + stack.perc + '%</td>\
<td class="duration_owntime">' + (stack.time - stack.internalExec) + 'ms</td>\
<td class="duration_time">' + stack.time + 'ms</td>\
<td class="duration_average">' + stack.avg + 'ms</td>\
<td class="duration_min">' + stack.min + 'ms</td>\
<td class="duration_max">' + stack.max + 'ms</td>\
</tr>');
}
out.push('</table>');
if (withContainer)
out.push('</div>');
this.previousStack = stackTrace;
return {
html    : out.join(''),
total   : stackTrace.totalCalls,
duration: stackTrace.totalDur
};
},
sortStack: function(stackTrace) {
var i, stack, aSorted = [];
for (i in stackTrace) {
if (!stackTrace[i].fullName) continue;
stack = stackTrace[i];
stack.perc = 100 - Math.round((Math.abs(stack.time - stackTrace.totalDur) / stackTrace.totalDur) * 100);
switch (this.sortMethod) {
case jpf.profiler.SORT_BY_CALLS :
aSorted.push([i, (stack.executions.length - 1)]);
break;
default:
case jpf.profiler.SORT_BY_PERCENTAGE :
aSorted.push([i, stack.perc]);
break;
case jpf.profiler.SORT_BY_FUNCTIONNAME :
aSorted.push([i, stack.fullName.toLowerCase()]);
break;
case jpf.profiler.SORT_BY_TIME :
aSorted.push([i, stack.time]);
break;
case jpf.profiler.SORT_BY_AVERAGE :
aSorted.push([i, stack.avg]);
break;
case jpf.profiler.SORT_BY_MINIMUM :
aSorted.push([i, stack.min]);
break;
case jpf.profiler.SORT_BY_MAXIMUM :
aSorted.push([i, stack.max]);
break;
case jpf.profiler.SORT_BY_OWNTIME :
aSorted.push([i, (stack.time - stack.internalExec)]);
break;
}
}
return aSorted.sort((this.sortMethod == jpf.profiler.SORT_BY_FUNCTIONNAME)
? this.sortingHelperAsc
: this.sortingHelperDesc);
},
resortStack: function(sortMethod) {
if (this.previousStack) {
this.sortMethod = parseInt(sortMethod);
return this.buildReport(this.previousStack, false);
}
return "";
},
sortingHelperAsc: function(a, b) {
if (a[1] < b[1])
return -1;
else if (a[1] > b[1])
return 1;
else
return 0;
},
sortingHelperDesc: function(a, b) {
if (a[1] > b[1])
return -1;
else if (a[1] < b[1])
return 1;
else
return 0;
},
getFunctionName: function(funcPointer) {
var regexpResult = funcPointer.toString().match(/function(\s*)(\w*)/);
if (regexpResult && regexpResult.length >= 2 && regexpResult[2]) {
return regexpResult[2];
}
return 'anonymous';
}
};
jpf.profiler.SORT_BY_CALLS        = 1;
jpf.profiler.SORT_BY_PERCENTAGE   = 2;
jpf.profiler.SORT_BY_FUNCTIONNAME = 3;
jpf.profiler.SORT_BY_TIME         = 4;
jpf.profiler.SORT_BY_AVERAGE      = 5;
jpf.profiler.SORT_BY_MINIMUM      = 6;
jpf.profiler.SORT_BY_MAXIMUM      = 7;
jpf.profiler.SORT_BY_OWNTIME      = 8;
jpf.profiler.BLACKLIST = {
'jpf.profiler' : 1
};
var Profiler_functionTemplate = function() {
return function() {
jpf.profiler.registerStart(arguments.callee.nameSelf);
var ret = jpf.profiler.pointers['pointer_to_' + arguments.callee.nameSelf].apply(this, arguments);
jpf.profiler.registerEnd(arguments.callee.nameSelf);
return ret;
};
};
jpf.BaseButton = function(pHtmlNode){
var refKeyDown   = 0;     
var refMouseDown = 0;     
var mouseOver    = false; 
var mouseLeft    = false; 
var _self        = this;
this.$propHandlers["background"] = function(value){
var oNode = this.$getLayoutNode("main", "background", this.oExt);
if (!oNode) return;
if (value) {
var b = value.split("|");
this.$background = b.concat(["vertical", 2, 16].slice(b.length - 1));
oNode.style.backgroundImage  = "url(" + this.mediaPath + b[0] + ")";
oNode.style.backgroundRepeat = "no-repeat";
}
else {
oNode.style.backgroundImage  = "";
oNode.style.backgroundRepeat = "";
this.$background = null;
}
}
this.addEventListener("keydown", function(e){
var key      = e.keyCode;
var ctrlKey  = e.ctrlKey;
var shiftKey = e.shiftKey;
switch (key) {
case 13:
if (this.tagName != "checkbox")
this.oExt.onmouseup(e.htmlEvent, true);
break;
case 32:
if (!e.htmlEvent.repeat) { 
refKeyDown++;
return this.$updateState(e.htmlEvent);
} else
return false;
}
}, true);
this.addEventListener("keyup", function(e){
var key = e.keyCode;
switch (key) {
case 32:
refKeyDown--;
if (refKeyDown < 0) {
refKeyDown = 0;
return;
}
if (refKeyDown + refMouseDown == 0 && !this.disabled) {
this.oExt.onmouseup(e, true);
}
return this.$updateState(e);
}
}, true);
this.states = {
"Out"   : 1,
"Over"  : 2,
"Down"  : 3
};
this.$updateState = function(e, strEvent) {
if (this.disabled || e.reset) {
refKeyDown   = 0;
refMouseDown = 0;
mouseOver    = false;
return false;
}
if (refKeyDown > 0
|| (refMouseDown > 0 && mouseOver)
|| (this.isBoolean && this.value)) {
this.$setState ("Down", e, strEvent);
}
else if (mouseOver)
this.$setState ("Over", e, strEvent);
else
this.$setState ("Out", e, strEvent);
}
this.$setupEvents = function() {
this.oExt.onmousedown = function(e) {
if (!e) e = event;
if (_self.$notfromext && (e.srcElement || e.target) == this)
return;
refMouseDown = 1;
mouseLeft    = false;
_self.$updateState(e, "mousedown");
};
this.oExt.onmouseup = function(e, force) {
if (!e) e = event;
if (!force && (!mouseOver || !refMouseDown))
return;
refMouseDown = 0;
_self.$updateState (e, "mouseup");
if (_self.disabled || (e && e.type == "click" && mouseLeft == true))
return false;
if (refMouseDown + _self.refKeyDown)
return false;
if (_self.$clickHandler && _self.$clickHandler())
_self.$updateState (e || event, "click");
else
_self.dispatchEvent("click", {htmlEvent : e});
return false;
};
this.oExt.onmousemove = function(e) {
if (!mouseOver) {
if (!e) e = event;
if (_self.$notfromext && (e.srcElement || e.target) == this)
return;
mouseOver = true;
_self.$updateState(e, "mouseover");
}
};
this.oExt.onmouseout = function(e) {
if(!e) e = event;
var tEl = e.explicitOriginalTarget || e.toElement;
if (this == tEl || jpf.xmldb.isChildOf(this, tEl))
return;
mouseOver    = false;
refMouseDown = 0;
mouseLeft    = true;
_self.$updateState (e || event, "mouseout");
};
if (jpf.hasClickFastBug)
this.oExt.ondblclick = this.oExt.onmouseup;
}
this.$doBgSwitch = function(nr){
if (this.bgswitch && (this.$background[2] >= nr || nr == 4)) {
if (nr == 4)
nr = this.$background[2] + 1;
var strBG = this.$background[1] == "vertical"
? "0 -" + (parseInt(this.$background[3]) * (nr - 1)) + "px"
: "-" + (parseInt(this.$background[3]) * (nr - 1)) + "px 0";
this.$getLayoutNode("main", "background",
this.oExt).style.backgroundPosition = strBG;
}
}
this.$focus = function(){
if (!this.oExt)
return;
this.$setStyleClass(this.oExt, this.baseCSSname + "Focus");
}
this.$blur = function(oBtn){
if (!this.oExt)
return; 
this.$setStyleClass(this.oExt, "", [this.baseCSSname + "Focus"]);
if (oBtn)
this.$updateState(oBtn);
}
this.$destroy = function(skinChange){
if (!skinChange) {
this.oExt.onmousedown = this.oExt.onmouseup = this.oExt.onmouseover =
this.oExt.onmouseout = this.oExt.onclick = this.oExt.ondblclick = null;
}
}
}
jpf.BaseSimple = function(){
this.inherit(jpf.Presentation);
this.inherit(jpf.DataBinding); 
this.getValue = function(){
return this.value;
}
}
jpf.actiontracker = function(parentNode){
jpf.makeClass(this);
var _self       = this;
var stackDone   = [];
var stackUndone = [];
var execStack   = [];
var lastExecStackItem;
this.realtime   = true;
this.undolength = 0;
this.redolength = 0;
this.tagName    = "actiontracker";
if (parentNode)
this.parentNode = parentNode;
this.inherit(jpf.JmlDom); 
this.$booleanProperties = {};
this.$booleanProperties["realtime"] = true;
this.$supportedProperties = ["realtime", "undolength", "redolength", "alias"];
this.$handlePropSet = function(prop, value, force){
switch (prop) {
case "undolength":
this.undolength = stackDone.length;
break;
case "redolength":
this.redolength = stackUndone.length;
break;
case "alias":
jpf.JmlElement.propHandlers.alias.call(this, value);
default:
this[prop] = value;
}
};
this.loadJml = function(x){
this.$jml = x;
var value, a, i, attr = x.attributes;
for (i = 0; i < attr.length; i++) {
a = attr[i];
if (a.nodeName.indexOf("on") == 0) {
this.addEventListener(a.nodeName, new Function(a.nodeValue));
}
else {
value = this.$booleanProperties[a.nodeName]
? jpf.isTrue(a.nodeValue)
: a.nodeValue;
this.setProperty(a.nodeName, value);
}
}
}
this.define = function(action, func){
jpf.actiontracker.actions[action] = func;
};
this.getParent = function(){
return this.parentNode && this.parentNode.getActionTracker
? this.parentNode.getActionTracker(true)
: (jpf.window.$at != this
? jpf.window.$at
: null);
};
this.execute = function(options){
if (this.dispatchEvent("beforechange", options) === false)
return;
var UndoObj = new jpf.UndoData(options, this);
if (options.action)
jpf.actiontracker.actions[options.action](UndoObj, false, this);
UndoObj.id = stackDone.push(UndoObj) - 1;
this.setProperty("undolength", stackDone.length);
this.$addToQueue(UndoObj, false);
stackUndone.length = 0;
this.setProperty("redolength", stackUndone.length);
return UndoObj;
};
this.$addActionGroup = function(done, rpc){
var UndoObj = new jpf.UndoData("group", null, [
jpf.copyArray(done, UndoData), jpf.copyArray(rpc, UndoData)
]);
stackDone.push(UndoObj);
this.setProperty("undolength", stackDone.length);
this.dispatchEvent("afterchange", {action: "group", done: done});
};
this.purge = function(nogrouping, forcegrouping){
if (true) {
if (execStack.length) {
execStack[0].undoObj.saveChange(execStack[0].undo, this);
lastExecStackItem = execStack[execStack.length - 1];
}
}
else if (parent) {
this.reset();
}
};
this.reset = function(){
stackDone.length = stackUndone.length = 0;
this.setProperty("undolength", 0);
this.setProperty("redolength", 0);
this.dispatchEvent("afterchange", {action: "reset"});
};
this.undo = function(id, single, rollback){
change.call(this, id, single, true, rollback);
};
this.redo = function(id, single, rollback){
change.call(this, id, single, false, rollback);
};
function change(id, single, undo, rollback){
var undoStack = undo ? stackDone : stackUndone; 
var redoStack = undo ? stackUndone : stackDone; 
if (!undoStack.length) return;
if (single) {
var UndoObj = undoStack[id];
if (!UndoObj) return;
undoStack.length--;
redoStack.push(UndoObj); 
if (UndoObj.action)
jpf.actiontracker.actions[UndoObj.action](UndoObj, undo, this);
if (!rollback)
this.$addToQueue(UndoObj, undo);
this.setProperty("undolength", stackDone.length);
this.setProperty("redolength", stackUndone.length);
return UndoObj;
}
if (id == -1)
id = undoStack.length;
if (!id)
id = 1;
var i = 0;
while (i < id && undoStack.length > 0) {
if (!undoStack[undoStack.length - 1]) {
undoStack.length--;
stackDone = [];
stackUndone = [];
return false;
}
else {
change.call(this, undoStack.length - 1, true, undo);
i++;
}
}
this.dispatchEvent("afterchange", {
action   : undo ? "undo" : "redo",
rollback : rollback
})
}
this.$receive = function(data, state, extra, UndoObj, callback){
if (state == jpf.TIMEOUT
&& extra.tpModule.retryTimeout(extra, state, this) === true)
return true;
if (state != jpf.SUCCESS) {
if (this.dispatchEvent("actionfail", jpf.extend(extra, {
state   : state,
message : "Could not sent Action RPC request for control "
+ this.name
+ "[" + this.tagName + "] \n\n"
+ extra.message,
bubbles : true
})) === false) {
return true; 
}
if (typeof jpf.offline != "undefined" && !jpf.offline.reloading)
this.undo(UndoObj.id, extra.userdata, true);
if (callback)
callback(!extra.userdata);
if (!extra.userdata) {
execStack = [];
throw new Error(jpf.formatErrorString(0, this, 
"Executing action",
"Error sending action to the server:\n"
+ (extra.url ? "Url:" + extra.url + "\n\n" : "") 
+ extra.message));
return;
}
}
else {
this.dispatchEvent("actionsuccess", jpf.extend(extra, {
state   : state,
bubbles : true
}, extra));
UndoObj.processRsbQueue();
if (callback)
callback();
}
this.$queueNext(UndoObj, callback);
};
this.$addToQueue = function(UndoObj, undo, isGroup){
if (execStack.length && !UndoObj.state
&& execStack[execStack.length - 1].undoObj == UndoObj) {
execStack.length--;
UndoObj.clearRsbQueue();
return;
}
if (isGroup) { 
var qItem = execStack.shift();
for (var i = 0; i < UndoObj.length; i++) {
execStack.unshift({
undoObj : UndoObj[i],
undo   : undo
});
}
if (qItem)
execStack.unshift(qItem);
return;
}
var qItem = {
undoObj : UndoObj.preparse(undo, this),
undo   : undo
};
execStack.push(qItem) - 1;
if (execStack.length == 1 && this.realtime)
UndoObj.saveChange(undo, this);
};
this.$queueNext = function(UndoObj, callback){
if (execStack[0].undoObj != UndoObj){
throw new Error(jpf.formatErrorString(0, this, "Executing Next \
action in queue", "The execution stack was corrupted. This is \
a fatal error. The application should be restarted. You will \
lose all your changes. Please contact the administrator."));
}
UndoObj.state = null;
var lastItem = execStack.shift();
if (!execStack[0] || lastItem == lastExecStackItem)
return;
execStack[0].undoObj.saveChange(execStack[0].undo, this, callback);
};
};
jpf.UndoData = function(settings, at){
this.tagName = "UndoData";
this.extra   = {};
jpf.extend(this, settings);
if (at)
this.at = at;
else if (settings && settings.tagName == "UndoData") {
this.args    = settings.args.slice();
this.rsbArgs = settings.rsbArgs.slice();
}
else {
this.selNode = this.selNode || (this.action == "removeNode"
? this.args[0]
: (this.jmlNode
? this.jmlNode.selected
: null));
}
var options, _self = this;
this.getActionXmlNode = function(undo){
if (!this.xmlActionNode)  return false;
if (!undo) return this.xmlActionNode;
var xmlNode = $xmlns(this.xmlActionNode, "undo", jpf.ns.jml)[0];
if (!xmlNode)
xmlNode = this.xmlActionNode;
return xmlNode;
};
this.processRsbQueue = function(){
if (this.rsbModel)
this.rsbModel.rsb.processQueue(this);
};
this.clearRsbQueue = function(){
this.rsbQueue = null;
this.rsbModel = null;
};
this.saveChange = function(undo, at, callback){
if (this.action == "group") {
var rpcNodes = this.args[1];
at.$addToQueue(rpcNodes, undo, true);
return at.$queueNext(this);
}
var xmlActionNode = this.getActionXmlNode(undo);
if (!xmlActionNode || !xmlActionNode.getAttribute("set"))
return at.$queueNext(this);
this.state = undo ? "restoring" : "saving";
options.preparse = false;
jpf.saveData(xmlActionNode.getAttribute("set"), null, options,
function(data, state, extra){
return at.$receive(data, state, extra, _self, callback);
}, {ignoreOffline: true});
};
this.preparse = function(undo, at, multicall){
var xmlActionNode = this.getActionXmlNode(undo);
if (!xmlActionNode || !xmlActionNode.getAttribute("set"))
return this;
options = jpf.extend({
userdata  : jpf.isTrue(xmlActionNode.getAttribute("ignore-fail")),
multicall : multicall,
preparse  : true
}, this.extra);
jpf.saveData(xmlActionNode.getAttribute("set"),
this.selNode || this.xmlNode, options); 
return this;
};
};
jpf.actiontracker.actions = {
"setTextNode" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo)
jpf.xmldb.setTextNode(q[0], q[1], q[2], UndoObj);
else 
jpf.xmldb.setTextNode(q[0], UndoObj.extra.oldValue, q[2]);
},
"setAttribute" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo) {
UndoObj.extra.name = q[1];
UndoObj.extra.oldValue = q[0].getAttribute(q[1]);
jpf.xmldb.setAttribute(q[0], q[1], q[2], q[3], UndoObj);
}
else {
if (!UndoObj.extra.oldValue)
jpf.xmldb.removeAttribute(q[0], q[1]);
else
jpf.xmldb.setAttribute(q[0], q[1], UndoObj.extra.oldValue, q[3]);
}
},
"removeAttribute" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo) {
UndoObj.extra.name = q[1];
UndoObj.extra.oldValue = q[0].getAttribute(q[1]);
jpf.xmldb.removeAttribute(q[0], q[1], q[2], UndoObj);
}
else
jpf.xmldb.setAttribute(q[0], q[1], UndoObj.extra.oldValue, q[2]);
},
"setAttributes" : function(UndoObj, undo){
var prop, q = UndoObj.args;
if (!undo) {
var oldValues = {};
for (prop in q[1]) {
oldValues[prop] = q[0].getAttribute(prop);
q[0].setAttribute(prop, q[1][prop]);
}
UndoObj.extra.oldValues = oldValues;
jpf.xmldb.applyChanges("attribute", q[0], UndoObj);
}
else {
for (prop in UndoObj.oldValues) {
if (!UndoObj.extra.oldValues[prop])
q[0].removeAttribute(prop);
else
q[0].setAttribute(prop, UndoObj.extra.oldValues[prop]);
}
jpf.xmldb.applyChanges("attribute", q[0], UndoObj);
}
},
"replaceNode" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo)
jpf.xmldb.replaceNode(q[0], q[1], q[2], UndoObj);
else
jpf.xmldb.replaceNode(q[1], q[0], q[2]);
},
"addChildNode" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo)
jpf.xmldb.addChildNode(q[0], q[1], q[2], q[3], UndoObj);
else
jpf.xmldb.removeNode(UndoObj.extra.addedNode);
},
"appendChild" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo)
jpf.xmldb.appendChild(q[0], q[1], q[2], q[3], q[4], UndoObj);
else
jpf.xmldb.removeNode(q[1]);
},
"moveNode" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo)
jpf.xmldb.moveNode(q[0], q[1], q[2], q[3], UndoObj);
else
jpf.xmldb.moveNode(UndoObj.extra.parent, q[1],
UndoObj.extra.beforeNode, q[3]);
},
"removeNode" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo)
jpf.xmldb.removeNode(q[0], q[1], UndoObj);
else
jpf.xmldb.appendChild(UndoObj.extra.parent,
UndoObj.extra.removedNode, UndoObj.extra.beforeNode);
},
"removeNodeList" : function(UndoObj, undo){
if (undo) {
var d = UndoObj.extra.removeList;
for (var i = d.length - 1; i >= 0; i--) {
jpf.xmldb.appendChild(d[i].pNode,
d[i].removedNode, d[i].beforeNode);
}
}
else
jpf.xmldb.removeNodeList(UndoObj.args, UndoObj);
},
"setUndoObject" : function(UndoObj, undo){
var q = UndoObj.args;
UndoObj.xmlNode = q[0];
},
"group" : function(UndoObj, undo, at){
if (!UndoObj.stackDone) {
var done = UndoObj.args[0];
UndoObj.stackDone = done;
UndoObj.stackUndone = [];
}
at[undo ? "undo" : "redo"](UndoObj.stackDone.length, false,
UndoObj.stackDone, UndoObj.stackUndone);
},
"setValueByXpath" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo) {
if (UndoObj.extra.newNode) {
jpf.xmldb.appendChild(UndoObj.extra.parentNode, UndoObj.extra.newNode);
}
else {
var newNodes = [];
jpf.xmldb.setNodeValue(q[0], q[1], true, {
undoObj  : UndoObj,
xpath    : q[2],
newNodes : newNodes,
forceNew : q[3]
});
UndoObj.extra.newNode = newNodes[0];
}
}
else {
if (UndoObj.extra.newNode) {
UndoObj.extra.parentNode = UndoObj.extra.newNode.parentNode;
jpf.xmldb.removeNode(UndoObj.extra.newNode);
}
else
jpf.xmldb.setNodeValue(UndoObj.extra.appliedNode, UndoObj.extra.oldValue, true);
}
},
"multicall" : function(UndoObj, undo, at){
var prop, q = UndoObj.args;
var dUpdate = jpf.xmldb.delayUpdate;
jpf.xmldb.delayUpdate = true;
if (!undo) {
for(var i = 0; i < q.length; i++) {
if (!q[i].extra)
q[i].extra = {}
jpf.actiontracker.actions[q[i].func](q[i], false, at);
}
}
else {
for (var i = q.length - 1; i >= 0; i--)
jpf.actiontracker.actions[q[i].func](q[i], true, at);
}
jpf.xmldb.delayUpdate = dUpdate;
},
"addRemoveNodes" : function(UndoObj, undo){
var q = UndoObj.args;
if (!undo) {
for (var i = 0; i < q[1].length; i++){
jpf.xmldb.appendChild(q[0], q[1][i],
null, null, null, UndoObj);
}
for (var i = 0; i < q[2].length; i++)
jpf.xmldb.removeNode(q[2][i], null, UndoObj);
}
else {
for (var i = 0; i < q[2].length; i++)
jpf.xmldb.appendChild(q[0], q[2][i]);
for (var i = 0; i < q[1].length; i++)
jpf.xmldb.removeNode(q[1][i]);
}
}
};
jpf.model = function(data, caching){
jpf.register(this, "model", jpf.NODE_HIDDEN);
this.data    = data;
this.caching = caching;
this.cache   = {};
var _self    = this;
if (!jpf.globalModel)
jpf.globalModel = this;
this.saveOriginal = true;
this.loadInJmlNode = function(jmlNode, xpath){
if (this.data && xpath) {
if (!jpf.supportNamespaces && (this.data.prefix || this.data.scopeName))
(this.data.nodeType == 9 ? this.data : this.data.ownerDocument)
.setProperty("SelectionNamespaces", "xmlns:"
+ (this.data.prefix || this.data.scopeName) + "='"
+ this.data.namespaceURI + "'");
var xmlNode = this.data.selectSingleNode(xpath);
if (!xmlNode)
jmlNode.$listenRoot = jpf.xmldb.addNodeListener(this.data, jmlNode);
}
else
xmlNode = this.data || null;
jmlNode.load(xmlNode);
};
var jmlNodes = {};
this.register = function(jmlNode, xpath){
if (!jmlNode)
return this;
jmlNodes[jmlNode.uniqueId] = [jmlNode, xpath];
jmlNode.$model = this;
if (this.connect) {
if (this.connect.type)
this.connect.node.connect(jmlNode, null, this.connect.select, this.connect.type);
else
this.connect.node.connect(jmlNode, true, this.connect.select);
}
else {
if (this.data)
this.loadInJmlNode(jmlNode, xpath);
}
return this;
};
this.$register = function(jmlNode, xpath){
jmlNodes[jmlNode.uniqueId][1] = xpath;
};
this.unregister = function(jmlNode){
if(jmlNode.dataParent)
jmlNode.dataParent.parent.disconnect(jmlNode);
delete jmlNodes[jmlNode.uniqueId]
};
this.getXpathByJmlNode = function(jmlNode){
var n = jmlNodes[jmlNode.uniqueId];
if (!n)
return false;
return n[1];
};
this.toString = function(){
var xml = jpf.xmldb.clearConnections(this.data.cloneNode(true));
return this.data
? jpf.formatXml(xml.xml || xml.serialize())
: "Model has no data.";
};
this.getXml = function(){
return this.data
? jpf.xmldb.clearConnections(this.data.cloneNode(true))
: false;
};
this.setQueryValue = function(xpath, value){
var node = jpf.xmldb.createNodeFromXpath(this.data, xpath);
if (!node)
return null;
jpf.xmldb.setTextNode(node, value);
return node;
};
this.queryValue = function(xpath){
return jpf.getXmlValue(this.data, xpath);
};
	
	
this.queryValues = function(xpath){
return jpf.getXmlValue(this.data, xpath);
};
	
this.queryNode = function(xpath){
return this.data.selectSingleNode(xpath)
};
this.queryNodes = function(xpath){
return this.data.selectNodes(xpath);
};
this.appendXml = function(xmlNode){
if (typeof xmlNode == "string")
xmlNode = jpf.getXml(xmlNode);
xmlNode = !model.nodeType 
? model.getXml()
: jpf.xmldb.copyNode(xmlNode);
if(!xmlNode) return;
jpf.xmldb.appendChild(this.data, xmlNode);
};
this.clear = function(){
this.load(null);
doc = null; 
};
this.reset = function(){
this.load(this.copy);
};
this.savePoint = function(){
this.copy = jpf.xmldb.copyNode(this.data);
};
this.reloadJmlNode = function(uniqueId){
if (!this.data)
return;
var xmlNode = jmlNodes[uniqueId][1] ? this.data.selectSingleNode(jmlNodes[uniqueId][1]) : this.data;
jmlNodes[uniqueId][0].load(xmlNode);
};
var bindValidation = [], defSubmission, submissions = {}, 
loadProcInstr, loadProcOptions;
this.loadJml = function(x, parentNode){
this.name = x.getAttribute("id");
this.$jml  = x;
this.parentNode = parentNode;
this.inherit(jpf.JmlDom); 
var attr  = x.attributes;
for (var i = 0, l = attr.length; i < l; i++) {
if (attr[i].nodeName.indexOf("on") == 0)
this.addEventListener(attr[i].nodeName, new Function(attr[i].nodeValue));
}
if (x.getAttribute("save-original") == "true")
this.saveOriginal = true;
var oSub;
if (!defSubmission)
defSubmission = x.getAttribute("submission"); 
this.submitType    = x.getAttribute("submittype");
this.useComponents = x.getAttribute("useComponents");
this.session = x.getAttribute("session");
var instanceNode;
loadProcInstr = jpf.parseExpression(x.getAttribute("load") || x.getAttribute("get"));
if (!loadProcInstr) {
var prefix = jpf.findPrefix(x, jpf.ns.jml);
if (!jpf.supportNamespaces)
if (prefix)
(x.nodeType == 9
? x
: x.ownerDocument).setProperty("SelectionNamespaces",
"xmlns:" + prefix + "='" + jpf.ns.jml + "'");
if (prefix)
prefix += ":";
var loadNode = x.selectSingleNode(prefix + "load");
if (loadNode)
loadProcInstr = loadNode.getAttribute("get");
}
if (!oSub && !loadProcInstr) {
var xmlNode = instanceNode || x;
if (xmlNode.childNodes.length && jpf.getNode(xmlNode, [0])) {
this.load((xmlNode.xml || xmlNode.serialize())
.replace(new RegExp("^<" + xmlNode.tagName + "[^>]*>"), "")
.replace(new RegExp("<\/\s*" + xmlNode.tagName + "[^>]*>$"), "")
.replace(/xmlns=\"[^"]*\"/g, ""));
}
}
if (oSub && !this.data && !instanceNode)
this.load("<data />");
if (!jpf.isFalse(x.getAttribute("init")))
this.init();
if (x.getAttribute("remote")) {
this.rsb = jpf.nameserver.get("remote", x.getAttribute("remote"));
this.rsb.models.push(this);
}
return this;
};
this.setConnection = function(jmlNode, type, select){
if (!this.connect)
this.connect = {};
var oldNode = this.connect.node;
this.connect.type   = type;
this.connect.node   = jmlNode;
this.connect.select = select;
for (var uniqueId in jmlNodes) {
if (oldNode)
oldNode.disconnect(jmlNodes[uniqueId][0]);
this.register(jmlNodes[uniqueId][0]);
}
};
this.init = function(callback){
if (this.session) {
this.loadFrom(this.session, null, {isSession: true});
}
else {
if (loadProcInstr)
this.loadFrom(loadProcInstr, null, {callback: callback});
}
};
this.loadFrom = function(instruction, xmlContext, options, callback){
var data      = instruction.split(":");
var instrType = data.shift();
if (!options || !options.isSession) {
loadProcInstr   = instruction;
loadProcOptions = [instruction, xmlContext, options, callback];
}
if (!callback && options)
callback = options.callback;
if (instrType.substr(0, 1) == "#") {
instrType = instrType.substr(1);
try {
eval(instrType).test
}
catch (e) {
throw new Error(jpf.formatErrorString(1031, null,
"Model Creation", "Could not find object reference to \
connect databinding: '" + instrType + "'", dataNode))
}
this.setConnection(eval(instrType), data[0] || "select", data[1]);
return this;
}
this.dispatchEvent("beforeretrieve");
jpf.getData(instruction, xmlContext, options, function(data, state, extra){
_self.dispatchEvent("afterretrieve");
if (state != jpf.SUCCESS) {
var oError;
if (extra.tpModule.retryTimeout(extra, state, _self, oError) === true)
return true;
throw oError;
}
if (options && options.isSession && !data) {
if (loadProcInstr)
return _self.loadFrom(loadProcInstr);
}
else {
if (options && options.cancel)
return;
_self.load(data);
_self.dispatchEvent("receive", {
data: data
});
if (callback)
callback.apply(this, arguments);
}
});
return this;
};
this.reload = function(){
if (!this.data)
return;
if (loadProcOptions)
this.loadFrom.apply(this, loadProcOptions);
else if (loadProcInstr)
this.loadFrom(loadProcInstr);
}
var doc;
this.load = function(xmlNode, nocopy){
if (this.dispatchEvent("beforeload") === false)
return false;
if (typeof xmlNode == "string")
xmlNode = jpf.getXmlDom(xmlNode).documentElement;
doc = xmlNode ? xmlNode.ownerDocument : null; 
if (xmlNode) {
jpf.xmldb.nodeConnect(
jpf.xmldb.getXmlDocId(xmlNode, this), xmlNode, null, this);
if (!nocopy && this.saveOriginal)
this.copy = jpf.xmldb.copyNode(xmlNode);
}
this.data = xmlNode;
var uniqueId;
for (uniqueId in jmlNodes) {
if (!jmlNodes[uniqueId] || !jmlNodes[uniqueId][0])
continue;
this.loadInJmlNode(jmlNodes[uniqueId][0], jmlNodes[uniqueId][1]);
}
this.dispatchEvent("afterload");
return this;
};
this.insertFrom = function(instruction, xmlContext, options, callback){
if (!instruction) return false;
this.dispatchEvent("beforeretrieve");
jpf.getData(instruction, xmlContext, options, function(data, state, extra){
_self.dispatchEvent("afterretrieve");
if (state != jpf.SUCCESS) {
var oError;
if (extra.tpModule.retryTimeout(extra, state, 
_self, oError) === true)
return true;
throw oError;
}
if (typeof options.insertPoint == "string")
insertPoint = _self.data.selectSingleNode(options.insertPoint);
(options.jmlNode || _self).insert(data, options.insertPoint, jpf.extend({
clearContents: jpf.isTrue(extra.userdata[1])
}, options));
if (callback)
callback.call(this, extra.data);
});
};
this.insert = function(XMLRoot, parentXMLNode, options, jmlNode){
if (typeof XMLRoot != "object")
XMLRoot = jpf.getXmlDom(XMLRoot).documentElement;
if (!parentXMLNode)
parentXMLNode = this.data;
var newNode = jpf.xmldb.integrate(XMLRoot, parentXMLNode,
jpf.extend({copyAttributes: true}, options));
jpf.xmldb.applyChanges("insert", parentXMLNode);
return XMLRoot;
};
this.getJsonObject = function(){
var data = {};
for (var p in this.elements) {
var name = this.elements[p].$jml.getAttribute("name") || this.elements[p].name;
if (name)
data[name] = this.elements[p].getValue();
}
return data;
};
this.getCgiString = function(){
var uniqueId, k, sel, oJmlNode, name, value, str = [];
for (uniqueId in jmlNodes) {
oJmlNode = jmlNodes[uniqueId][0];
if (oJmlNode.disabled || !oJmlNode.change && !oJmlNode.hasFeature(__MULTISELECT__))
continue;
if (oJmlNode.tagName == "MultiBinding")
oJmlNode = oJmlNode.getHost();
if (oJmlNode.multiselect) {
sel = oJmlNode.getSelection();
for (k = 0; k < sel.length; k++) {
name = oJmlNode.$jml.getAttribute("name");
if (!name && oJmlNode.$jml.getAttribute("ref"))
name = oJmlNode.$jml.getAttribute("ref").replace(/[\/\]\[@]/g, "_");
if (!name)
name = sel[k].tagName;
if (!name.match(/\]$/))
name += "[]";
value = oJmlNode.applyRuleSetOnNode("value", sel[k])
|| oJmlNode.applyRuleSetOnNode("caption", sel[k]);
if (value)
str.push(name + "=" + encodeURIComponent(value));
}
}
else {
name = oJmlNode.$jml.getAttribute("name")
|| oJmlNode.$jml.getAttribute("id");
if (!name && oJmlNode.$jml.getAttribute("ref"))
name = oJmlNode.$jml.getAttribute("ref").replace(/[\/\]\[@]/g, "_");
if (!name && oJmlNode.xmlRoot)
name = oJmlNode.xmlRoot.tagName;
if (!name)
continue;
value = oJmlNode.getValue();
if (value)
str.push(name + "=" + encodeURIComponent(value));
}
}
return str.join("&");
};
this.submit = function(instruction, xmlNode, type, useComponents, xSelectSubTree){
if (!instruction && !defSubmission)
return false;
if (!xmlNode)
xmlNode = this.data;
if (!instruction && typeof defSubmission == "string")
instruction = defSubmission;
var sub;
if (submissions[instruction] || !instruction && defSubmission) {
sub = submissions[instruction] || defSubmission;
useComponents  = false;
type           = sub.getAttribute("method")
.match(/^(?:urlencoded-post|get)$/) ? "native" : "xml";
xSelectSubTree = sub.getAttribute("ref") || "/";
instruction    = (sub.getAttribute("method")
.match(/post/) ? "url.post:" : "url:") + sub.getAttribute("action");
var file       = sub.getAttribute("action");
}
else
if (instruction) {
if (!type)
type = this.submitType || "native";
if (!useComponents)
useComponents = this.useComponents;
}
else {
}
if (this.dispatchEvent("beforesubmit", {
instruction: instruction
}) === false)
return false;
var model = this;
function cbFunc(data, state, extra){
if ((state == jpf.TIMEOUT 
|| (_self.retryOnError && state == jpf.ERROR))
&& extra.retries < jpf.maxHttpRetries)
return extra.tpModule.retry(extra.id);
else
if (state != jpf.SUCCESS) {
model.dispatchEvent("submiterror", extra);
}
else {
model.dispatchEvent("submitsuccess", jpf.extend({
data: data
}, extra));
}
}
if (type == "array" || type == "xml") {
var data = type == "array"
? this.getJsonObject()
: jpf.xmldb.serializeNode(xmlNode);
jpf.saveData(instruction, xmlNode, {args : [data]}, cbFunc);
}
else {
var data = useComponents
? this.getCgiString()
: jpf.xmldb.convertXml(jpf.xmldb.copyNode(xmlNode), type != "native" ? type : "cgivars");
if (instruction.match(/^rpc\:/)) {
rpc = rpc.split(".");
var oRpc = self[rpc[0]];
oRpc.callWithString(rpc[1], data, cbFunc);
}
else {
if (instruction.match(/^url/))
instruction += (instruction.match(/\?/) ? "&" : "?") + data;
jpf.saveData(instruction, xmlNode, null, cbFunc);
}
}
this.dispatchEvent("aftersubmit");
};
this.$destroy = function(){
if (this.session && this.data)
jpf.saveData(this.session, this.getXml());
};
};
jpf.smartbinding = function(name, xmlNode, parentNode){
this.xmlbindings = null;
this.xmlactions  = null;
this.xmldragdrop = null;
this.bindings    = null;
this.actions     = null;
this.dragdrop    = null;
this.jmlNodes    = {};
this.$modelXpath = {};
this.name        = name;
var _self        = this;
this.tagName    = "smartbinding";
this.nodeFunc   = jpf.NODE_HIDDEN;
this.parentNode = parentNode;
jpf.inherit.call(this, jpf.JmlDom); 
var parts        = {
bindings: 'loadBindings',
actions : 'loadActions',
dragdrop: 'loadDragDrop'
};
this.initialize = function(jmlNode, part){
this.jmlNodes[jmlNode.uniqueId] = jmlNode;
if (part)
return jmlNode[parts[part]](this[part], this["xml" + part]);
if (jmlNode.$jml && this.name) 
jmlNode.$jml.setAttribute("smartbinding", this.name);
for (part in parts) {
if (typeof parts[part] != "string") continue;
if (!this[part]) continue;
jmlNode[parts[part]](this[part], this["xml" + part]);
}
if (this.$model) {
this.$model.register(jmlNode, this.$modelXpath[jmlNode.getHost
? jmlNode.getHost().uniqueId
: jmlNode.uniqueId] || this.modelBaseXpath); 
}
else if (jmlNode.$model && (jmlNode.smartBinding && jmlNode.smartBinding != this))
jmlNode.$model.reloadJmlNode(jmlNode.uniqueId);
return this;
};
this.deinitialize = function(jmlNode){
this.jmlNodes[jmlNode.uniqueId] = null;
delete this.jmlNodes[jmlNode.uniqueId];
for (part in parts) {
if (typeof parts[part] != "string") continue;
if (!this[part]) continue;
jmlNode["un" + parts[part]]();
}
if (this.model)
this.model.unregister(jmlNode);
};
var timer, queue = {};
this.markForUpdate = function(jmlNode, part){
(queue[jmlNode.uniqueId] 
|| (queue[jmlNode.uniqueId] = {}))[part || "all"] = jmlNode;
if (!this.jmlNodes[jmlNode.uniqueId])
this.jmlNodes[jmlNode.uniqueId] = jmlNode;
if (!timer) {
timer = setTimeout(function(){
_self.$updateMarkedItems();
});
}
return this;
};
this.$isMarkedForUpdate = function(jmlNode){
return queue[jmlNode.uniqueId] ? true : false;
}
this.$updateMarkedItems = function(){
clearTimeout(timer);
var jmlNode, model, q = queue; timer = null; queue = {}
for (var id in q) {
if (!this.jmlNodes[id])
continue;
if (q[id]["all"]) {
jmlNode = q[id]["all"];
for (part in parts) {
if (!this[part]) continue;
jmlNode[parts[part]](this[part], this["xml" + part]);
}
model = jmlNode.getModel();
if (model)
model.reloadJmlNode(jmlNode.uniqueId);
else
jmlNode.reload();
}
else {
for (part in q[id]) {
jmlNode = q[id][part];
if (part == "model") {
jmlNode.getModel().reloadJmlNode(jmlNode.uniqueId);
continue;
}
jmlNode[parts[part]](this[part], this["xml" + part]);
if (part == "bindings")
jmlNode.reload();
}
}
}
};
this.addBindRule = function(xmlNode, jmlParent){
var str = xmlNode[jpf.TAGNAME] == "ref"
? jmlParent ? jmlParent.mainBind : "value"
: xmlNode.tagName;
if (!this.bindings)
this.bindings = {};
if (!this.bindings[str])
this.bindings[str] = [xmlNode];
else
this.bindings[str].push(xmlNode);
};
this.addBindings = function(rules){
this.bindings    = rules;
this.xmlbindings = xmlNode;
if (!jpf.isParsing) {
}
if (!jpf.isParsing)
this.markForUpdate(null, "bindings");
};
this.addActionRule = function(xmlNode){
var str = xmlNode[jpf.TAGNAME] == "action" ? "Change" : xmlNode.tagName;
if (!this.actions)
this.actions = {};
if (!this.actions[str])
this.actions[str] = [xmlNode];
else
this.actions[str].push(xmlNode);
};
this.addActions = function(rules, xmlNode){
this.actions    = rules;
this.xmlactions = xmlNode;
if (!jpf.isParsing)
this.markForUpdate(null, "bindings");
};
this.addDropRule = 
this.addDragRule = function(xmlNode){
if (!this.dragdrop)
this.dragdrop = {};
if (!this.dragdrop[xmlNode[jpf.TAGNAME]])
this.dragdrop[xmlNode[jpf.TAGNAME]] = [xmlNode];
else
this.dragdrop[xmlNode[jpf.TAGNAME]].push(xmlNode);
};
this.addDragDrop = function(rules, xmlNode){
this.dragdrop    = rules;
this.xmldragdrop = xmlNode;
if (!jpf.isParsing)
this.markForUpdate(null, "dragdrop");
};
this.setModel = function(model, xpath){
if (typeof model == "string")
model = jpf.nameserver.get("model", model);
this.model          = jpf.nameserver.register("model", this.name, model);
this.modelBaseXpath = xpath;
for (var uniqueId in this.jmlNodes) {
this.model.unregister(this.jmlNodes[uniqueId]);
this.model.register(jmlNode, this.$modelXpath[jmlNode.getHost
? jmlNode.getHost().uniqueId
: jmlNode.uniqueId] || this.modelBaseXpath); 
}
};
this.load = function(xmlNode){
this.setModel(new jpf.model().load(xmlNode));
};
var known = {
actions  : "addActions",
bindings : "addBindings",
dragdrop : "addDragDrop"
};
this.loadJml = function(xmlNode){
this.name = xmlNode.getAttribute("id");
this.$jml  = xmlNode;
var name, attr = xmlNode.attributes, l = attr.length;
for (var i = 0; i < l; i++) {
name = attr[i].nodeName;
if (name == "model")
continue;
if (!known[name])
continue;
var cNode = jpf.nameserver.get(name, attr[i].nodeValue);
this[known[name]](jpf.getRules(cNode), cNode);
}
var data_node, nodes = xmlNode.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1) continue;
switch (nodes[i][jpf.TAGNAME]) {
case "model":
data_node = nodes[i];
break;
case "bindings":
this.addBindings(jpf.getRules(nodes[i]), nodes[i]);
break;
case "actions":
this.addActions(jpf.getRules(nodes[i]), nodes[i]);
break;
case "dragdrop":
this.addDragDrop(jpf.getRules(nodes[i]), nodes[i]);
break;
case "ref":
this.addBindRule(nodes[i]);
break;
case "action":
this.addActionRule(nodes[i]);
break;
default:
throw new Error(jpf.formatErrorString(1039, this, 
"setSmartBinding Method", 
"Could not find handler for '" 
+ nodes[i].tagName + "' node."));
break;
}
}
if (data_node)
this.setModel(new jpf.model().loadJml(data_node));
else if (xmlNode.getAttribute("model"))
jpf.setModel(xmlNode.getAttribute("model"), this);
};
if (xmlNode)
this.loadJml(xmlNode);
};
jpf.WinServer = {
count : 9000,
wins  : [],
setTop : function(win){
this.count += 2;
win.setProperty("zindex", this.count);
this.wins.remove(win);
this.wins.push(win);
return win;
},
setNext : function(){
if (this.wins.length < 2) return;
var nwin, start = this.wins.shift();
do {
if (this.setTop(nwin || start).visible)
break;
nwin = this.wins.shift();
} while (start != nwin);
},
setPrevious : function(){
if (this.wins.length < 2) return;
this.wins.unshift(this.wins.pop());
var nwin, start = this.wins.pop();
do {
if (this.setTop(nwin || start).visible)
break;
nwin = this.wins.pop();
} while (start != nwin);
},
remove : function(win){
this.wins.remove(win);
}
}
jpf.modalwindow = jpf.component(jpf.NODE_VISIBLE, function(){
this.isWindowContainer = true;
this.canHaveChildren   = 2;
this.animate           = true;
this.visible           = false;
this.showdragging      = false;
this.buttons           = "min|max|close";
this.$focussable       = jpf.KEYBOARD;
this.state             = "normal";
this.edit              = false;
var _self              = this;
this.editableParts = {"main" : [["title","@title"]]};
this.setTitle = function(caption){
this.setProperty("title", caption);
};
this.setIcon = function(icon){
this.setProperty("icon", icon);
};
this.close = function(){
this.setProperty("state", this.state.split("|")
.pushUnique("closed").join("|"));
};
this.minimize = function(){
this.setProperty("state", this.state.split("|")
.remove("maximized")
.remove("normal")
.pushUnique("minimized").join("|"));
};
this.maximize = function(){
this.setProperty("state", this.state.split("|")
.remove("minimized")
.remove("normal")
.pushUnique("maximized").join("|"));
};
this.restore = function(){
this.setProperty("state", this.state.split("|")
.remove("minimized")
.remove("maximized")
.pushUnique("normal").join("|"));
};
this.edit = function(value){
this.setProperty("state", this.state.split("|")
.pushUnique("edit").join("|"));
};
this.closeedit = function(value){
this.setProperty("state", this.state.split("|")
.remove("edit").join("|"));
};
this.bringToFront = function(){
jpf.WinServer.setTop(this);
};
var actions  = {
"min"   : ["minimized", "minimize", "restore"],
"max"   : ["maximized", "maximize", "restore"],
"edit"  : ["edit", "edit", "closeedit"],
"close" : ["closed", "close", "show"]
};
this.$toggle = function(type){
var c = actions[type][0];
this[actions[type][this.state.indexOf(c) > -1 ? 2 : 1]]();
};
this.$booleanProperties["modal"]        = true;
this.$booleanProperties["center"]       = true;
this.$booleanProperties["transaction"]  = true;
this.$booleanProperties["hideselects"]  = true;
this.$booleanProperties["animate"]      = true;
this.$booleanProperties["showdragging"] = true;
this.$supportedProperties.push("title", "icon", "modal", "minwidth",
"minheight", "hideselects", "center", "buttons", "state",
"maxwidth", "maxheight", "animate", "showdragging", "transaction");
this.$propHandlers["modal"] = function(value){
if (value && !this.oCover) {
var oCover = this.$getLayoutNode("cover");
if (oCover) {
this.oCover = jpf.xmldb.htmlImport(oCover, this.pHtmlNode);
if (!this.visible)
this.oCover.style.display = "none";
this.oCover.style.zIndex = this.zindex;
}
}
if (!value && this.oCover) {
this.oCover.style.display = "none";
}
};
this.$propHandlers["center"] = function(value){
this.oExt.style.position = "absolute"; 
};
this.$propHandlers["title"] = function(value){
this.oTitle.nodeValue = value;
};
this.$propHandlers["icon"] = function(value){
if (!this.oIcon) return;
this.oIcon.style.display = value ? "block" : "none";
jpf.skins.setIcon(this.oIcon, value, this.iconPath);
};
var hEls = [], wasVisible;
this.$propHandlers["visible"] = function(value){
if (jpf.isTrue(value)){
if (this.oCover){
this.oCover.style.display = "block";
}
this.state = this.state.split("|").remove("closed").join("|");
this.oExt.style.display = "block"; 
if (jpf.layout && this.oInt)
jpf.layout.forceResize(this.oInt); 
if (this.center) {
this.oExt.style.left = Math.max(0, ((
(jpf.isIE
? document.documentElement.offsetWidth
: window.innerWidth)
- this.oExt.offsetWidth)/2)) + "px";
this.oExt.style.top  = Math.max(0, ((
(jpf.isIE
? document.documentElement.offsetHeight
: window.innerHeight)
- this.oExt.offsetHeight)/3)) + "px";
}
if (!this.isRendered) {
this.addEventListener("afterrender", function(){
this.dispatchEvent("display");
this.removeEventListener("display", arguments.callee);
});
}
else
this.dispatchEvent("display");
if (!jpf.canHaveHtmlOverSelects && this.hideselects) {
hEls = [];
var nodes = document.getElementsByTagName("select");
for (var i = 0; i < nodes.length; i++) {
var oStyle = jpf.getStyle(nodes[i], "display");
hEls.push([nodes[i], oStyle]);
nodes[i].style.display = "none";
}
}
if (wasVisible != true && this.$show)
this.$show();
if (this.modal) {
this.bringToFront();
this.focus(false, {mouse:true});
}
}
else if (jpf.isFalse(value)) {
if (this.oCover)
this.oCover.style.display = "none";
this.oExt.style.display = "none";
if (!jpf.canHaveHtmlOverSelects && this.hideselects) {
for (var i = 0; i < hEls.length; i++) {
hEls[i][0].style.display = hEls[i][1];
}
}
if (this.$hide)
this.$hide();
if (this.hasFocus())
jpf.window.moveNext(null, this, true)
this.dispatchEvent("close");
}
wasVisible = value;
};
this.$propHandlers["zindex"] = function(value){
this.oExt.style.zIndex = value + 1;
if (this.oCover)
this.oCover.style.zIndex = value;
};
var lastheight = null;
var lastpos    = null;
var lastzindex = null;
var lastState  = {"normal":1};
this.$propHandlers["state"] = function(value, noanim){
var i, o = {}, s = value.split("|");
for (i = 0; i < s.length; i++)
o[s[i]] = true;
var styleClass = [];
if (!o.maximized && !o.minimized)
o.normal = true;
if (o.closed == this.visible) {
this.setProperty("visible", !o["closed"]);
}
if (o.normal != lastState.normal
|| !o.normal && (o.minimized != lastState.minimized
|| o.maximized != lastState.maximized)) {
if (lastheight) { 
this.oExt.style.height = (lastheight
- jpf.getHeightDiff(this.oExt)) + "px";
}
if (lastpos) {
if (this.animate && !noanim) {
_self.animstate = 1;
jpf.tween.multi(this.oExt, {
steps    : 5,
interval : 10,
tweens   : [
{type: "left",   from: this.oExt.offsetLeft,   to: lastpos[0]},
{type: "top",    from: this.oExt.offsetTop,    to: lastpos[1]},
{type: "width",  from: this.oExt.offsetWidth,  to: lastpos[2]},
{type: "height", from: this.oExt.offsetHeight, to: lastpos[3]}
],
oneach   : function(){
if (jpf.hasSingleRszEvent)
jpf.layout.forceResize(_self.oInt);
},
onfinish : function(){
_self.$propHandlers["state"].call(_self, value, true);
}
});
return;
}
this.oExt.style.left   = lastpos[0] + "px";
this.oExt.style.top    = lastpos[1] + "px";
this.oExt.style.width  = lastpos[2] + "px";
this.oExt.style.height = lastpos[3] + "px";
var pNode = (this.oExt.parentNode == document.body
? document.documentElement
: this.oExt.parentNode);
pNode.style.overflow = lastpos[4];
}
if (jpf.layout)
jpf.layout.play(this.pHtmlNode);
if (lastzindex) {
this.oExt.style.zIndex = lastzindex[0];
if (this.oCover)
this.oCover.style.zIndex = lastzindex[1];
}
lastheight = lastpos = lastzindex = null;
if (o.normal)
styleClass.push("",
this.baseCSSname + "Max",
this.baseCSSname + "Min");
}
if (o.minimized != lastState.minimized) {
if (o.minimized) {
styleClass.unshift(
this.baseCSSname + "Min",
this.baseCSSname + "Max",
this.baseCSSname + "Edit");
if (!this.aData || !this.aData.minimize) {
lastheight = this.oExt.offsetHeight;
this.oExt.style.height = Math.max(0, this.collapsedHeight
- jpf.getHeightDiff(this.oExt)) + "px";
}
if (this.hasFocus())
jpf.window.moveNext(null, this, true);
}
else {
styleClass.push(this.baseCSSname + "Min");
setTimeout(function(){
jpf.window.$focusLast(_self);
});
}
}
if (o.maximized != lastState.maximized) {
if (o.maximized) {
styleClass.unshift(
this.baseCSSname + "Max",
this.baseCSSname + "Min",
this.baseCSSname + "Edit");
var pNode = (this.oExt.parentNode == document.body
? document.documentElement
: this.oExt.parentNode);
lastpos = [this.oExt.offsetLeft, this.oExt.offsetTop,
this.oExt.offsetWidth - hordiff, this.oExt.offsetHeight - verdiff,
pNode.style.overflow];
pNode.style.overflow = "hidden";
_self.animstate = 0;
var hasAnimated = false, htmlNode = this.oExt;
function setMax(){
var w = !jpf.isIE && pNode == document.documentElement
? window.innerWidth
: pNode.offsetWidth;
var h = !jpf.isIE && pNode == document.documentElement
? window.innerHeight
: pNode.offsetHeight;
if (_self.animate && !hasAnimated) {
_self.animstate = 1;
hasAnimated = true;
jpf.tween.multi(htmlNode, {
steps    : 5,
interval : 10,
tweens   : [
{type: "left",   from: htmlNode.offsetLeft,   to: -1 * marginBox[3]},
{type: "top",    from: htmlNode.offsetTop,    to: -1 * marginBox[0]},
{type: "width",  from: htmlNode.offsetWidth,  to: (w - hordiff + marginBox[1] + marginBox[3])},
{type: "height", from: htmlNode.offsetHeight, to: (h - verdiff + marginBox[0] + marginBox[2])}
],
oneach   : function(){
if (jpf.hasSingleRszEvent)
jpf.layout.forceResize(_self.oInt);
},
onfinish : function(){
_self.animstate = 0;
}
});
}
else if (!_self.animstate) {
htmlNode.style.left = (-1 * marginBox[3]) + "px";
htmlNode.style.top  = (-1 * marginBox[0]) + "px";
htmlNode.style.width  = (w
- hordiff + marginBox[1] + marginBox[3]) + "px";
htmlNode.style.height = (h
- verdiff + marginBox[0] + marginBox[2]) + "px";
}
}
if (jpf.layout)
jpf.layout.pause(this.pHtmlNode, setMax);
lastzindex = [
this.oExt.style.zIndex || 1, 
this.oCover && this.oCover.style.zIndex || 1
];
if (this.oCover)
this.oCover.style.zIndex = jpf.WinServer.count + 1;
this.oExt.style.zIndex = jpf.WinServer.count + 2;
}
else {
styleClass.push(this.baseCSSname + "Max");
}
}
if (o.edit != lastState.edit) {
if (o.edit) {
styleClass.unshift(
this.baseCSSname + "Edit",
this.baseCSSname + "Max",
this.baseCSSname + "Min");
if (this.btnedit)
oButtons.edit.innerHTML = "close"; 
this.dispatchEvent('editstart');
}
else {
if (this.dispatchEvent('editstop') === false)
return false;
styleClass.push(this.baseCSSname + "Edit");
if (styleClass.length == 1)
styleClass.unshift("");
if (this.btnedit)
oButtons.edit.innerHTML = "edit"; 
}
}
if (styleClass.length) {
this.$setStyleClass(this.oExt, styleClass.shift(), styleClass);
this.dispatchEvent('statechange', o);
lastState = o;
if (!this.animate && jpf.hasSingleRszEvent && jpf.layout)
jpf.layout.forceResize(_self.oInt);
}
};
var oButtons = {}
this.$propHandlers["buttons"] = function(value){
var buttons = value.split("|");
var nodes   = this.oButtons.childNodes;
var re      = new RegExp("(" + value + ")");
var found   = {};
var idleNodes = [];
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1 || nodes[i].tagName != "DIV") 
continue;
if (!nodes[i].className || !nodes[i].className.match(re)) {
nodes[i].style.display = "none";
this.$setStyleClass(nodes[i], "", ["min", "max", "close", "edit"]);
idleNodes.push(nodes[i]);
}
else
found[RegExp.$1] = nodes[i];
}
for (i = 0; i < buttons.length; i++) {
if (found[buttons[i]]) {
this.oButtons.insertBefore(found[buttons[i]], this.oButtons.firstChild);
continue;
}
var btn = idleNodes.pop();
if (!btn) {
this.$getNewContext("button");
btn = this.$getLayoutNode("button");
setButtonEvents(btn);
btn = jpf.xmldb.htmlImport(btn, this.oButtons);
}
this.$setStyleClass(btn, buttons[i], ["min", "max", "close", "edit"]);
btn.onclick = new Function("jpf.lookup(" + this.uniqueId + ").$toggle('"
+ buttons[i] + "')");
btn.style.display = "block";
oButtons[buttons[i]] = btn;
this.oButtons.insertBefore(btn, this.oButtons.firstChild);
}
};
this.addEventListener("keydown", function(e){
var key      = e.keyCode;
var ctrlKey  = e.ctrlKey;
var shiftKey = e.shiftKey;
if (key > 36 && key < 41) {
if (_self.hasFeature && _self.hasFeature(__ANCHORING__))
_self.disableAnchoring();
}
switch (key) {
case 27:
if (this.buttons.indexOf("close") > -1 && !this.aData)
this.close();
return;
case 38:
if (shiftKey && this.resizable)
this.setProperty("height", Math.max(this.minheight || 0,
this.oExt.offsetHeight - (ctrlKey ? 50 : 10)));
else if (this.draggable)
this.setProperty("top",
this.oExt.offsetTop - (ctrlKey ? 50 : 10));
break;
case 37:
if (shiftKey && this.resizable)
this.setProperty("width", Math.max(this.minwidth || 0,
this.oExt.offsetWidth - (ctrlKey ? 50 : 10)));
else if (this.draggable)
this.setProperty("left",
this.oExt.offsetLeft - (ctrlKey ? 50 : 10));
break;
case 39:
if (shiftKey && this.resizable)
this.setProperty("width", Math.min(this.maxwidth || 10000,
this.oExt.offsetWidth + (ctrlKey ? 50 : 10)));
else if (this.draggable)
this.setProperty("left",
this.oExt.offsetLeft + (ctrlKey ? 50 : 10));
break;
case 40:
if (shiftKey && this.resizable)
this.setProperty("height", Math.min(this.maxheight || 10000,
this.oExt.offsetHeight + (ctrlKey ? 50 : 10)));
else if (this.draggable)
this.setProperty("top",
this.oExt.offsetTop + (ctrlKey ? 50 : 10));
break;
default:
return;
}
if (jpf.hasSingleRszEvent)
jpf.layout.forceResize(this.oInt);
}, true);
function setButtonEvents(btn){
btn.setAttribute("onmousedown",
"jpf.setStyleClass(this, 'down');\
event.cancelBubble = true; \
jpf.findHost(this).oExt.onmousedown(event);\
document.onmousedown(event);");
btn.setAttribute("onmouseup",
"jpf.setStyleClass(this, '', ['down'])");
btn.setAttribute("onmouseover",
"jpf.setStyleClass(this, 'hover')");
btn.setAttribute("onmouseout",
"jpf.setStyleClass(this, '', ['hover', 'down'])");
}
var marginBox, hordiff, verdiff;
this.$draw = function(){
this.popout = jpf.isTrue(this.$jml.getAttribute("popout"));
if (this.popout)
this.pHtmlNode = document.body;
this.oExt = this.$getExternal(null, null, function(oExt){
var oButtons = this.$getLayoutNode("main", "buttons", oExt);
if (!oButtons)
return;
var len = (this.$jml.getAttribute("buttons") || "").split("|").length;
for (var btn, i = 0; i < len; i++) {
this.$getNewContext("button");
btn = oButtons.appendChild(this.$getLayoutNode("button"));
setButtonEvents(btn);
}
});
this.oTitle   = this.$getLayoutNode("main", "title", this.oExt);
this.oIcon    = this.$getLayoutNode("main", "icon",  this.oExt);
this.oDrag    = this.$getLayoutNode("main", "drag",  this.oExt);
this.oButtons = this.$getLayoutNode("main", "buttons",  this.oExt);
this.oDrag.host = this;
if (this.oIcon)
this.oIcon.style.display = "none";
this.oDrag.onmousedown = function(e){
if (!e) e = event;
if (!_self.isWidget && (!_self.aData || !_self.dockable || _self.aData.hidden == 3))
jpf.WinServer.setTop(_self);
if (lastState.maximized)
return false;
};
this.oExt.onmousedown = function(){
if (!_self.isWidget && (!_self.aData || !_self.dockable || _self.aData.hidden == 3))
jpf.WinServer.setTop(_self);
if (!lastState.normal)
return false;
}
this.oExt.onmousemove = function(){
if (!lastState.normal)
return false;
}
var diff = jpf.getDiff(this.oExt);
hordiff  = diff[0];
verdiff  = diff[1];
marginBox = jpf.getBox(jpf.getStyle(this.oExt, "borderWidth"));
if (this.hasFeature(__MULTILANG__))
this.$makeEditable("main", this.oExt, this.$jml);
};
this.$loadJml = function(x){
jpf.WinServer.setTop(this);
var oInt = this.$getLayoutNode("main", "container", this.oExt);
this.oInt = this.oInt
? jpf.JmlParser.replaceNode(oInt, this.oInt)
: jpf.JmlParser.parseChildren(this.$jml, oInt, this, true);
(this.oTitle.nodeType != 1
? this.oTitle.parentNode
: this.oTitle).ondblclick = function(e){
if (_self.state.indexOf("normal") == -1)
_self.restore();
else if (_self.buttons.indexOf("max") > -1)
_self.maximize();
else if (_self.buttons.indexOf("min") > -1)
_self.minimize();
}
if (this.draggable === undefined) {
(this.$propHandlers.draggable
|| jpf.JmlElement.propHandlers.draggable).call(this, true);
this.draggable = true;
}
if (this.modal === undefined && this.oCover) {
this.$propHandlers.modal.call(this, true);
this.modal = true;
}
if (!this.visible) {
this.oExt.style.display = "none";
if (this.oCover)
this.oCover.style.display = "none";
}
this.collapsedHeight = this.$getOption("Main", "collapsed-height");
if (this.minwidth === undefined)
this.minwidth  = this.$getOption("Main", "min-width");
if (this.minheight === undefined)
this.minheight = this.$getOption("Main", "min-height");
if (this.maxwidth === undefined)
this.maxwidth  = this.$getOption("Main", "max-width");
if (this.maxheight === undefined)
this.maxheight = this.$getOption("Main", "max-height");
if (this.center && this.visible) {
this.visible = false;
this.oExt.style.display = "none"; 
jpf.JmlParser.stateStack.push({
node  : this,
name  : "visible",
value : "true"
});
}
if (!this.hasFeature(__DATABINDING__)
&& !this.transaction && (this.$jml.getAttribute("smartbinding")
|| this.$jml.getAttribute("actions"))) {
this.$propHandlers.transaction.call(this, true);
}
};
this.$destroy = function(skinChange){
if (this.oDrag) {
this.oDrag.host = null;
this.oDrag.onmousedown = null;
jpf.removeNode(this.oDrag);
this.oDrag = null;
}
this.oTitle =  this.oIcon = this.oCover = null;
for (var name in oButtons) {
oButtons[name].onclick = null;
}
if (this.oExt && !skinChange) {
this.oExt.onmousedown = null;
this.oExt.onmousemove = null;
}
};
}).implement(
jpf.Presentation
);
jpf.errorbox = jpf.component(jpf.NODE_VISIBLE, function(){
this.editableParts = {"main" : [["container","@invalidmsg"]]};
var _self = this;
this.setMessage = function(value){
if(value && value.indexOf(";")>-1){
value = value.split(";");
value = "<strong>" + value[0] + "</strong>" + value[1];
}
this.oInt.innerHTML = value || "";
};
this.$draw = function(){
this.oExt   = this.$getExternal(); 
this.oInt   = this.$getLayoutNode("main", "container", this.oExt);
this.oClose = this.$getLayoutNode("main", "close", this.oExt);
if (this.oClose) {
this.oClose.onclick = function(){
_self.hide();
if (_self.host)
_self.host.focus(null, {mouse:true});
};
}
this.oExt.onmousedown = function(e){
(e || event).cancelBubble = true;
if (jpf.hasFocusBug)
jpf.window.$focusfix();
}
this.hide();
};
this.$loadJml = function(x){
jpf.JmlParser.parseChildren(this.$jml, this.oInt, this);
};
this.$destroy = function(){
if (this.oClose)
this.oClose.onclick = null;
this.oExt.onmousedown = null;
}
}).implement(
jpf.Presentation
);
jpf.input    =
jpf.secret   =
jpf.textarea =
jpf.textbox  = jpf.component(jpf.NODE_VISIBLE, function(){
this.$focussable       = true; 
var masking            = false;
var _self              = this;
this.value             = "";
this.isContentEditable = true;
this.multiline         = this.tagName == "textarea" ? true : false;
this.$booleanProperties["focusselect"] = true;
this.$booleanProperties["realtime"]    = true;
this.$supportedProperties.push("value", "mask", "initial",
"focusselect", "realtime", "type");
this.$propHandlers["value"] = function(value, initial){
if (this.isHTMLBox) {
if (this.oInt.innerHTML != value)
this.oInt.innerHTML = value;
}
else if (this.oInt.value != value)
this.oInt.value = value;
if (this.oButton)
this.oButton.style.display = value && !initial ? "block" : "none";
};
this.$propHandlers["maxlength"] = function(value){
this.$setRule("maxlength", value
? "value.toString().length <= " + value
: null);
if (this.oInt.tagName.toLowerCase().match(/input|textarea/))
this.oInt.maxLength = parseInt(value) || null;
};
this.$propHandlers["mask"] = function(value){
if (jpf.hasMsRangeObject || this.mask == "PASSWORD")
return;
if (!value) {
throw new Error("Not Implemented");
}
if (!masking) {
masking = true;
this.inherit(jpf.textbox.masking); 
this.focusselect = false;
this.realtime    = false;
}
this.setMask(this.mask);
};
this.$propHandlers["initial-message"] = function(value){
this.initialMsg = value
|| jpf.xmldb.getInheritedAttribute(this.$jml, "initial-message");
if (this.initialMsg) {
this.oInt.onblur();
this.$propHandlers["value"].call(this, this.initialMsg, true);
}
};
this.$propHandlers["realtime"] = function(value){
this.realtime = typeof value == "boolean"
? value
: jpf.isTrue(jpf.xmldb.getInheritedAttribute(this.$jml, "realtime")) || false;
};
this.$propHandlers["focusselect"] = function(value){
this.oInt.onmousedown = function(){
_self.focusselect = false;
};
this.oInt.onmouseup  =
this.oInt.onmouseout = function(){
_self.focusselect = value;
};
};
this.$propHandlers["type"] = function(value){
if (value && "password|username".indexOf(value) > -1
&& typeof this.focusselect == "undefined") {
this.focusselect = true;
this.$propHandlers["focusselect"].call(this, true);
}
};
this.setValue = function(value){
return this.setProperty("value", value);
};
this.getValue = function(){
var v = this.isHTMLBox ? this.oInt.innerHTML : this.oInt.value;
return v == this.initialMsg ? "" : v.replace(/\r/g, "");
};
this.select   = function(){ this.oInt.select(); };
this.deselect = function(){ this.oInt.deselect(); };
this.$enable  = function(){ this.oInt.disabled = false; };
this.$disable = function(){ this.oInt.disabled = true; };
this.$insertData = function(str){
return this.setValue(str);
};
this.insert = function(text){
if (jpf.hasMsRangeObject) {
try {
this.oInt.focus();
}
catch(e) {}
var range = document.selection.createRange();
if (this.oninsert)
text = this.oninsert(text);
range.pasteHTML(text);
range.collapse(true);
range.select();
}
else {
this.oInt.value += text;
}
};
this.$clear = function(){
this.value = "";
if (this.initialMsg && jpf.window.focussed != this) {
this.$propHandlers["value"].call(this, this.initialMsg, true);
jpf.setStyleClass(_self.oExt, _self.baseCSSname + "Initial");
}
else {
this.$propHandlers["value"].call(this, "");
}
if (!this.oInt.tagName.toLowerCase().match(/input|textarea/i)) {
if (jpf.hasMsRangeObject) {
try {
var range = document.selection.createRange();
range.moveStart("sentence", -1);
range.select();
}
catch(e) {}
}
}
this.dispatchEvent("clear");
};
this.$keyHandler = function(key, ctrlKey, shiftKey, altKey, e){
if (this.dispatchEvent("keydown", {
keyCode   : key,
ctrlKey   : ctrlKey,
shiftKey  : shiftKey,
altKey    : altKey,
htmlEvent : e}) === false)
return false;
if (false && jpf.isIE && (key == 86 && ctrlKey || key == 45 && shiftKey)) {
var text = window.clipboardData.getData("Text");
if ((text = this.dispatchEvent("keydown", {
text : this.onpaste(text)}) === false))
return false;
if (!text)
text = window.clipboardData.getData("Text");
this.oInt.focus();
var range = document.selection.createRange();
range.text = "";
range.collapse();
range.pasteHTML(text.replace(/\n/g, "<br />").replace(/\t/g, "&nbsp;&nbsp;&nbsp;"));
return false;
}
};
var fTimer;
this.$focus = function(e){
if (!this.oExt || this.oExt.disabled)
return;
this.$setStyleClass(this.oExt, this.baseCSSname + "Focus");
if (this.initialMsg && this.oInt.value == this.initialMsg) {
this.$propHandlers["value"].call(this, "", true);
jpf.setStyleClass(this.oExt, "", [this.baseCSSname + "Initial"]);
}
function delay(){
try {
if (!fTimer || document.activeElement != _self.oInt) {
_self.oInt.focus();
}
else {
clearInterval(fTimer);
return;
}
}
catch(e) {}
if (masking)
_self.setPosition();
if (_self.focusselect)
_self.select();
};
if ((!e || e.mouse) && jpf.isIE) {
clearInterval(fTimer);
fTimer = setInterval(delay, 1);
}
else
delay();
};
this.$blur = function(e){
if (!this.oExt)
return;
if (!this.realtime)
this.change(this.getValue());
this.$setStyleClass(this.oExt, "", [this.baseCSSname + "Focus"]);
if (this.initialMsg && this.oInt.value == "") {
this.$propHandlers["value"].call(this, this.initialMsg, true);
jpf.setStyleClass(this.oExt, this.baseCSSname + "Initial");
}
try {
if (jpf.isIE || !e || e.srcElement != jpf.window)
this.oInt.blur();
}
catch(e) {}
if (this.oContainer) {
setTimeout("var o = jpf.lookup(" + this.uniqueId + ");\
o.oContainer.style.display = 'none'", 100);
}
clearInterval(fTimer);
};
this.$draw = function(){
this.oExt = this.$getExternal(null, null, function(oExt){
if (this.$jml.getAttribute("mask") == "PASSWORD"
|| "secret|password".indexOf(this.tagName) > -1
|| this.$jml.getAttribute("type") == "password") {
this.$jml.removeAttribute("mask");
this.$getLayoutNode("main", "input").setAttribute("type", "password");
}
oExt.setAttribute("onmousedown", "this.host.dispatchEvent('mousedown', {htmlEvent : event});");
oExt.setAttribute("onmouseup",   "this.host.dispatchEvent('mouseup', {htmlEvent : event});");
oExt.setAttribute("onclick",     "this.host.dispatchEvent('click', {htmlEvent : event});");
});
this.oInt    = this.$getLayoutNode("main", "input", this.oExt);
this.oButton = this.$getLayoutNode("main", "button", this.oExt);
if (!jpf.hasContentEditable && "input|textarea".indexOf(this.oInt.tagName.toLowerCase()) == -1) {
var node  = this.oInt;
this.oInt = node.parentNode.insertBefore(document.createElement("textarea"), node);
node.parentNode.removeChild(node);
this.oInt.className = node.className;
if (this.oExt == node)
this.oExt = this.oInt;
}
if (this.oInt.tagName.toLowerCase() == "textarea") {
this.addEventListener("focus", function(e){
});
}
this.oInt.onselectstart = function(e){
if (!e) e = event;
e.cancelBubble = true;
}
this.oInt.host = this;
this.oInt.onkeydown = function(e){
if (this.disabled) return false;
e = e || window.event;
if (!_self.realtime) {
var value = _self.getValue();
if (e.keyCode == 13 && value != this.value)
_self.change(value);
}
else if (jpf.isSafari && _self.xmlRoot && _self.getValue() != this.value) 
setTimeout("var o = jpf.lookup(" + _self.uniqueId + ");\
o.change(o.getValue())");
if (_self.multiline == "optional" && e.keyCode == 13 && !e.ctrlKey)
return false;
if (e.ctrlKey && (e.keyCode == 66 || e.keyCode == 73
|| e.keyCode == 85))
return false;
if (_self.oContainer) {
var oTxt    = _self;
var keyCode = e.keyCode;
setTimeout(function(){
oTxt.fillAutocomplete(keyCode);
});
}
if (!_self.mask) {
return _self.$keyHandler(e.keyCode, e.ctrlKey,
e.shiftKey, e.altKey, e);
}
};
this.oInt.onkeyup = function(e){
if (!e)
e = event;
var keyCode = e.keyCode;
if (_self.oButton)
_self.oButton.style.display = this.value ? "block" : "none";
if (_self.realtime) {
setTimeout(function(){
if (!_self.mask && _self.getValue() != _self.value)
_self.change(_self.getValue()); 
_self.dispatchEvent("keyup", {keyCode : keyCode});
});
}
else {
_self.dispatchEvent("keyup", {keyCode : keyCode});
}
if (_self.isValid() && e.keyCode != 13 && e.keyCode != 17)
_self.clearError();
};
this.oInt.onfocus = function(){
if (jpf.hasFocusBug)
jpf.window.$focusfix2();
};
this.oInt.onblur = function(){
if (jpf.hasFocusBug)
jpf.window.$blurfix();
};
if (jpf.hasAutocompleteXulBug)
this.oInt.setAttribute("autocomplete", "off");
if (!this.oInt.tagName.toLowerCase().match(/input|textarea/)) {
this.isHTMLBox = true;
this.oInt.unselectable    = "Off";
this.oInt.contentEditable = true;
this.oInt.style.width     = "1px";
this.oInt.select = function(){
var r = document.selection.createRange();
r.moveToElementText(this);
r.select();
}
};
this.oInt.deselect = function(){
if (!document.selection) return;
var r = document.selection.createRange();
r.collapse();
r.select();
};
};
this.$loadJml = function(x){
var ac = $xmlns(x, "autocomplete", jpf.ns.jml)[0];
if (ac) {
this.inherit(jpf.textbox.autocomplete); 
this.initAutocomplete(ac);
}
if (typeof this.realtime == "undefined")
this.$propHandlers["realtime"].call(this);
if (jpf.xmldb.isOnlyChild(x.firstChild, [3,4]))
this.$handlePropSet("value", x.firstChild.nodeValue.trim());
else if (!ac)
jpf.JmlParser.parseChildren(this.$jml, null, this);
};
this.$destroy = function(){
this.oInt.onkeypress    =
this.oInt.onmouseup     =
this.oInt.onmouseout    =
this.oInt.onmousedown   =
this.oInt.onkeydown     =
this.oInt.onkeyup       =
this.oInt.onselectstart = null;
};
}).implement(
jpf.DataBinding,
jpf.Validation,
jpf.Presentation
);
jpf.submit  =
jpf.trigger =
jpf.reset   =
jpf.button  = jpf.component(jpf.NODE_VISIBLE, function(){
var useExtraDiv;
var _self = this;
this.editableParts = {
"main": [["caption", "text()"]]
};
this.$focussable = true; 
this.value       = null;
this.$booleanProperties["default"] = true;
this.$supportedProperties.push("icon", "value", "tooltip", "state",
"color", "caption", "action", "target", "default", "submenu");
this.$propHandlers["icon"] = function(value){
if (!this.oIcon) return;
if (value)
this.$setStyleClass(this.oExt, this.baseCSSname + "Icon");
else
this.$setStyleClass(this.oExt, "", [this.baseCSSname + "Icon"]);
jpf.skins.setIcon(this.oIcon, value, this.iconPath);
};
this.$propHandlers["value"] = function(value){
if (value === undefined)
value = !this.value;
this.value = value;
if (this.value)
this.$setState("Down", {});
else
this.$setState("Out", {});
};
this.$propHandlers["tooltip"] = function(value){
this.oExt.setAttribute("title", value);
};
this.$propHandlers["state"] = function(value){
this.$setStateBehaviour(value == 1);
};
this.$propHandlers["color"] = function(value){
if (this.oCaption)
this.oCaption.parentNode.style.color = value;
};
this.$propHandlers["caption"] = function(value){
if (value)
this.$setStyleClass(this.oExt, "", [this.baseCSSname + "Empty"]);
else
this.$setStyleClass(this.oExt, this.baseCSSname + "Empty");
if (this.oCaption)
this.oCaption.nodeValue = (value || "").trim();
};
var forceFocus;
this.$propHandlers["default"] = function(value){
if (!this.focussable && value || forceFocus)
this.setAttribute("focussable", forceFocus = value);
this.parentNode.removeEventListener("focus", setDefault);
this.parentNode.removeEventListener("blur", removeDefault);
if (!value)
return;
this.parentNode.addEventListener("focus", setDefault);
this.parentNode.addEventListener("blur", removeDefault);
};
function setDefault(e){
if (e.defaultButtonSet || e.returnValue === false)
return;
e.defaultButtonSet = true;
if (useExtraDiv)
_self.oExt.appendChild(jpf.button.$extradiv);
_self.$setStyleClass(_self.oExt, _self.baseCSSname + "Default");
if (e.srcElement != _self && _self.$focusParent) {
_self.$focusParent.addEventListener("keydown", btnKeyDown);
}
}
function removeDefault(e){
if (useExtraDiv && jpf.button.$extradiv.parentNode == _self.oExt)
_self.oExt.removeChild(jpf.button.$extradiv);
_self.$setStyleClass(_self.oExt, "", [_self.baseCSSname + "Default"]);
if (e.srcElement != _self && _self.$focusParent) {
_self.$focusParent.removeEventListener("keydown", btnKeyDown);
}
}
function btnKeyDown(e){
var ml;
var f = jpf.window.focussed;
if (f) {
if (f.hasFeature(__MULTISELECT__))
return;
ml = f.multiline;
}
if (ml && ml != "optional" && e.keyCode == 13
&& e.ctrlKey || (!ml || ml == "optional")
&& e.keyCode == 13 && !e.ctrlKey && !e.shiftKey && !e.altKey)
_self.oExt.onmouseup(e.htmlEvent, true);
}
this.addEventListener("focus", setDefault);
this.addEventListener("blur", removeDefault);
this.setValue = function(value){
this.setProperty("value", value);
};
this.setCaption = function(value){
this.setProperty("caption", value);
};
this.setIcon = function(url){
this.setProperty("icon", url);
};
this.$enable = function(){
if (this["default"]) {
setDefault({});
if (jpf.window.focussed)
jpf.window.focussed.focus(true);
}
if (this.state && this.value) {
this.$setState("Down", {});
}
this.$doBgSwitch(1);
};
this.$disable = function(){
if (this["default"])
removeDefault({});
this.$doBgSwitch(4);
this.$setStyleClass(this.oExt, "",
[this.baseCSSname + "Over", this.baseCSSname + "Down"]);
};
this.$setStateBehaviour = function(value){
this.value     = value || false;
this.isBoolean = true;
this.$setStyleClass(this.oExt, this.baseCSSname + "Bool");
if (this.value) {
this.$setStyleClass(this.oExt, this.baseCSSname + "Down");
this.$doBgSwitch(this.states["Down"]);
}
};
this.$setNormalBehaviour = function(){
this.value     = null;
this.isBoolean = false;
this.$setStyleClass(this.oExt, "", [this.baseCSSname + "Bool"]);
};
this.$setState = function(state, e, strEvent){
if (this.disabled)
return;
if (strEvent && this.dispatchEvent(strEvent, {htmlEvent: e}) === false)
return;
this.$doBgSwitch(this.states[state]);
var bs = this.baseCSSname;
this.$setStyleClass(this.oExt, (state != "Out" ? bs + state : ""),
[(this.value ? "" : bs + "Down"), bs + "Over"]);
if (this.submenu) {
bs = this.baseCSSname + "menu";
this.$setStyleClass(this.oExt, (state != "Out" ? bs + state : ""),
[(this.value ? "" : bs + "Down"), bs + "Over"]);
}
};
this.$clickHandler = function(){
if (this.isBoolean && !this.submenu) {
this.setProperty("value", !this.value);
return true;
}
};
this.$domHandlers["reparent"].push(
function(beforeNode, pNode, withinParent){
if (!this.$jmlLoaded)
return;
var skinName;
if (isUsingParentSkin && !withinParent
&& this.skinName != pNode.skinName
|| !isUsingParentSkin && (skinName = this.parentNode.$getOption
&& this.parentNode.$getOption("main", "button-skin"))) {
isUsingParentSkin = true;
this.$forceSkinChange(this.parentNode.skinName.split(":")[0] + ":" + skinName);
}
});
var inited = false, isUsingParentSkin = false;
this.$draw  = function(){
if (typeof this.focussable == "undefined") {
if (this.parentNode.parentNode
&& this.parentNode.parentNode.tagName == "toolbar"
&& !this.$jml.getAttribute("focussable"))
this.focussable = false;
}
var skinName;
if (this.parentNode && (skinName = this.parentNode.$getOption
&& this.parentNode.$getOption("main", "button-skin"))) {
isUsingParentSkin = true;
skinName = this.parentNode.skinName.split(":")[0] + ":" + skinName;
if (this.skinName != skinName)
this.$loadSkin(skinName);
this.$focussable = jpf.KEYBOARD;
}
else if(isUsingParentSkin){
isUsingParentSkin = false;
this.$loadSkin();
this.$focussable = true;
}
this.oExt     = this.$getExternal();
this.oIcon    = this.$getLayoutNode("main", "icon", this.oExt);
this.oCaption = this.$getLayoutNode("main", "caption", this.oExt);
useExtraDiv = jpf.isTrue(this.$getOption("main", "extradiv"));
if (!jpf.button.$extradiv && useExtraDiv) {
(jpf.button.$extradiv = document.createElement("div"))
.className = "extradiv"
}
if (this.tagName == "submit")
this.action = "submit";
else if (this.tagName == "reset")
this.action = "reset";
this.$setupEvents();
};
this.$loadJml = function(x){
if (!this.caption && x.firstChild)
this.setProperty("caption", x.firstChild.nodeValue);
else if (typeof this.caption == "undefined")
this.$propHandlers["caption"].call(this, "");
this.$makeEditable("main", this.oExt, this.$jml);
if (!inited) {
jpf.JmlParser.parseChildren(this.$jml, null, this);
inited = true;
}
};
this.addEventListener("click", function(e){
var action = this.action;
if (!action)
action = this.tagName;
setTimeout(function(){
(jpf.button.actions[action] || jpf.K).call(_self);
});
});
}).implement(jpf.Presentation, jpf.BaseButton);
jpf.button.actions = {
"undo" : function(action){
var tracker;
if (this.target && self[this.target]) {
tracker = self[this.target].getActionTracker()
}
else {
var at, node = this;
while(node.parentNode)
at = (node = node.parentNode).$at;
}
(tracker || jpf.window.$at)[action || "undo"]();
},
"redo" : function(){
jpf.button.actions.undo.call(this, "redo");
},
"remove" : function(){
if (this.target && self[this.target])
self[this.target].remove()
},
"add" : function(){
if (this.target && self[this.target])
self[this.target].add()
},
"rename" : function(){
if (this.target && self[this.target])
self[this.target].startRename()
},
"login" : function(){
var parent = this.target && self[this.target]
? self[this.target]
: this.parentNode;
var vg = parent.$validgroup || new jpf.ValidationGroup();
if (!vg.childNodes.length)
vg.childNodes = parent.childNodes.slice();
var vars = {};
function loopChildren(nodes){
for (var node, i = 0, l = nodes.length; i < l; i++) {
node = nodes[i];
if (node.hasFeature(__VALIDATION__)
&& !node.$validgroup && !node.form) {
node.setProperty("validgroup", vg);
}
if (node.$jml.getAttribute("type"))
vars[node.$jml.getAttribute("type")] = node.getValue();
if (vars.username && vars.password)
return;
if (node.childNodes.length)
loopChildren(node.childNodes);
}
}
loopChildren(parent.childNodes);
if (!vg.isValid())
return;
if (!vars.username || !vars.password) {
return;
}
jpf.auth.login(vars.username, vars.password);
},
"logout" : function(){
jpf.auth.logout();
},
"submit" : function(doReset){
var vg, model;
var parent = this.target && self[this.target]
? self[this.target]
: this.parentNode;
if (parent.tagName == "model")
model = parent;
else {
if (!parent.$validgroup) {
parent.$validgroup = parent.validgroup
? self[parent.validgroup]
: new jpf.ValidationGroup();
}
vg = parent.$validgroup;
if (!vg.childNodes.length)
vg.childNodes = parent.childNodes.slice();
function loopChildren(nodes){
for (var node, i = 0, l = nodes.length; i < l; i++) {
node = nodes[i];
if (node.getModel) {
model = node.getModel();
if (model)
return false;
}
if (node.childNodes.length)
if (loopChildren(node.childNodes) === false)
return false;
}
}
loopChildren(parent.childNodes);
if (!model) {
return;
}
}
if (doReset) {
model.reset();
return;
}
if (vg && !vg.isValid())
return;
model.submit();
},
"reset" : function(){
jpf.button.actions["submit"].call(this, true);
},
"close" : function(){
var parent = this.target && self[this.target]
? self[this.target]
: this.parentNode;
while(parent && !parent.close)
parent = parent.parentNode;
if (parent && parent.close)
parent.close();
}
};
jpf.grid = jpf.component(jpf.NODE_VISIBLE, function(){
var id;
var update  = false;
var l       = jpf.layout;
var _self   = this;
var updater = {
$updateLayout : function(){
_self.$updateGrid();
}
};
this.canHaveChildren = true;
this.$focussable     = false;
this.columns    = "100,*";
this.padding    = 2;
this.margin     = "5 5 5 5";
this.cellheight = 22;
this.$supportedProperties.push("columns", "padding", "margin", 
"cellheight", "span");
var jmlHideShow                  =
this.$updateTrigger              =
this.$propHandlers["columns"]    =
this.$propHandlers["padding"]    =
this.$propHandlers["margin"]     =
this.$propHandlers["cellheight"] = function(value){
if (!update && jpf.loaded)
l.queue(_self.oExt, updater);
update = true;
};
this.$domHandlers["removechild"].push(function(jmlNode, doOnlyAdmin){
if (doOnlyAdmin)
return;
jmlNode.$propHandlers["width"]  = 
jmlNode.$propHandlers["height"] = 
jmlNode.$propHandlers["span"]   = null;
jmlNode.$hide = jmlNode.$_hide;
jmlNode.$show = jmlNode.$_show;
if (jmlNode.hasFeature(__ANCHORING__) && jmlNode.$hasAnchorRules())
jmlNode.$setAnchoringEnabled();
l.queue(this.oExt, updater);
update = true;
});
this.$domHandlers["insert"].push(function(jmlNode, bNode, withinParent){
if (withinParent)
return;
else if (jmlNode.hasFeature(__ANCHORING__) && jmlNode.$hasAnchorRules())
jmlNode.disableAnchoring();
jmlNode.$propHandlers["width"]  = 
jmlNode.$propHandlers["height"] = 
jmlNode.$propHandlers["span"]   = updateTrigger;
jmlNode.$_hide = jmlNode.$hide;
jmlNode.$_show = jmlNode.$show;
jmlNode.$hide = jmlHideShow;
jmlNode.$show = jmlHideShow;
l.queue(this.oExt, updater);
update = true;
});
function propChange(e){
if (update && e.name == "visible" && e.value == true && _self.oExt.offsetHeight) {
_self.$updateGrid();
jpf.layout.activateRules(_self.oExt);
var p = _self;
while (p) {
p.removeEventListener(propChange);
p = p.parentNode;
}
}
};
function setPercentage(expr, value){
return typeof expr == "string" 
? expr.replace(jpf.percentageMatch, "((" + value + " * $1)/100)")
: expr;
}
var timer;
this.$updateGrid = function(){
if (!update)
return;
var pWidth  = "pWidth";
var pHeight = "pHeight";
this.cellheight = parseInt(this.cellheight);
var cols        = setPercentage(this.columns, pWidth).split(/\s*,\s*/);
var collength   = cols.length;
var margin      = jpf.getBox(this.margin);
var rowheight   = [];
this.padding    = parseInt(this.padding);
var oCols   = [];
var col, row, oExt, diff, j, m, cellInfo;
this.ids = [this.oExt];
var span, jNode, jNodes = this.childNodes;
for (var nodes = [], c = 0, i = 0, l = jNodes.length; i < l; i++) {
jNode = jNodes[i];
if (jNode.nodeFunc != jpf.NODE_VISIBLE || !jNode.visible)
continue;
if (jNode.hasFeature(__ANCHORING__))
jNode.disableAnchoring();
m = jpf.getBox(jNode.getAttribute("margin"));
diff = jpf.getDiff(jNode.oExt);
oExt = jNode.oExt;
if (!oExt.getAttribute("id")) 
jpf.setUniqueHtmlId(oExt);
if (jpf.isIE)
oExt.style.position = "absolute"; 
span = jNode.getAttribute("span");
cellInfo = {
span    : span == "*" ? collength : parseInt(span) || 1,
m       : m,
height  : setPercentage(jNode.height, pHeight),
width   : jNode.width,
oHtml   : oExt,
hordiff : diff[0],
verdiff : diff[1],
id      : (jpf.hasHtmlIdsInJs 
? oExt.getAttribute("id")
: "document.getElementById('" + oExt.getAttribute("id") + "')")
}
nodes.push(cellInfo);
row = Math.floor(c / collength);
c += cellInfo.span; 
if (cellInfo.height == "*" || rowheight[row] == "*") {
rowheight[row] = "*";
cellInfo.height = null;
}
else if(cellInfo.height && parseInt(cellInfo.height) != cellInfo.height) {
rowheight[row] = cellInfo.height;
}
else if(typeof rowheight[row] != "string") {
rowheight[row] = Math.max(rowheight[row] || 0, 
parseFloat(cellInfo.height || this.cellheight) 
+ cellInfo.m[0] + cellInfo.m[2]);
}
}
var dt = new Date().getTime();
if (nodes.length == 0) 
return;
var total, combCol, fillCol = null, fillRow = null;
var rule = [
"var ids = jpf.all[" + this.uniqueId + "].ids",
"var total = 0, pHeight = ids[0].offsetHeight - " 
+ ((rowheight.length - 1) * this.padding + margin[0] + margin[2]),
"var pWidth  = ids[0].offsetWidth - " 
+ ((collength - 1) * this.padding + margin[1] + margin[3]) 
];
for (total = 0, i = 0; i < collength; i++) {
if (cols[i] == "*")
fillCol = i;
else {
if (parseFloat(cols[i]) != cols[i]) {
rule.push("var colw" + i + "; total += colw" 
+ i + " = " + cols[i]);
cols[i] = "colw" + i;
}
else
total += cols[i] = parseFloat(cols[i]);
}
}
if (fillCol !== null) {
rule.push("var colw" + fillCol + " = " + pWidth 
+ " - total - " + total);
cols[fillCol] = "colw" + fillCol;
}
var colstart = [margin[3]];
rule.push("var coll0 = " + margin[3]);
for (i = 1; i < collength; i++) {
if (typeof colstart[i-1] == "number" && typeof cols[i-1] == "number") {
colstart[i] = colstart[i-1] + cols[i-1] + this.padding;
}
else {
rule.push("var coll" + i + " = coll" + (i - 1) + " + colw" 
+ (i - 1) + " + " + this.padding);
colstart[i] = "coll" + i;
}
}
rule.push("total = 0");
var needcalc = false;
for (total = 0, i = 0; i < rowheight.length; i++) {
if (rowheight[i] == "*")
fillRow = i;
else {
if (parseFloat(rowheight[i]) != rowheight[i]) {
needcalc = true;
rule.push("var rowh" + i + "; total += rowh" 
+ i + " = " + rowheight[i]);
rowheight[i] = "rowh" + i;
}
else
total += rowheight[i] = parseFloat(rowheight[i]);
}
}
if (fillRow !== null) {
needcalc = true;
rule.push("var rowh" + fillRow + " = " + pHeight 
+ " - total - " + total);
rowheight[fillRow] = "rowh" + fillRow;
}
if (!needcalc)
this.oExt.style.height = (total + ((rowheight.length-1) * this.padding) + margin[0] + margin[2]) + "px";
var rowstart = [margin[0]];
rule.push("var rowt0 = " + margin[0]);
for (i = 1; i < rowheight.length; i++) {
if (typeof rowstart[i-1] == "number" && typeof rowheight[i-1] == "number") {
rowstart[i] = rowstart[i-1] + rowheight[i-1] + this.padding;
}
else {
rule.push("var rowt" + i + " = rowt" + (i - 1) + " + rowh" 
+ (i - 1) + " + " + this.padding);
rowstart[i] = "rowt" + i;
}
}
for (c = 0, i = 0; i < nodes.length; i++) {
cellInfo = nodes[i]
col      = c % collength;
row      = Math.floor(c / collength);
c       += cellInfo.span; 
id       = cellInfo.id;
if (typeof rowstart[row] == "number")
cellInfo.oHtml.style.top = (rowstart[row] + cellInfo.m[0]) + "px";
else
rule.push(id + ".style.top    = rowt" 
+ row + " + " + cellInfo.m[0] + " + 'px'");
if (typeof colstart[col] == "number")
cellInfo.oHtml.style.left = (colstart[col] + cellInfo.m[3]) + "px";
else
rule.push(id + ".style.left   = coll" 
+ col + " + " + cellInfo.m[3] + " + 'px'");
if (cellInfo.span && cellInfo.span > 1 && !cellInfo.width) {
var cTotal = 0;
for (combCol = [], j = 0; j < cellInfo.span; j++) {
if (typeof cols[col + j] == "number") {
cTotal += cols[col + j];
}
else {
combCol.push("colw" + (col + j));
cTotal -= 1000000;
}
if (j != cellInfo.span - 1)
cTotal += this.padding;
}
var spanPadding = (cellInfo.span - 1) * this.padding;
if (cTotal > 0) {
cellInfo.oHtml.style.width = (cTotal 
- (cellInfo.m[1] + cellInfo.m[3] + cellInfo.m[3] 
+ cellInfo.hordiff)) + "px";
}
else {
if (cTotal > -1000000)
combCol.push(cTotal + 1000000);
rule.push(id + ".style.width = (" + combCol.join(" + ") 
+ " + " + spanPadding + " - " + (cellInfo.m[1] + cellInfo.m[3] 
+ cellInfo.hordiff) + ") + 'px'");
}
}
else {
if (parseFloat(cellInfo.width) == cellInfo.width
|| typeof cols[col] == "number")
cellInfo.oHtml.style.width = ((cellInfo.width || cols[col]) 
- (cellInfo.m[1] + cellInfo.m[3] + cellInfo.hordiff)) + "px";
else
rule.push(id + ".style.width = (" 
+ (cellInfo.width || "colw" + col) + " - " 
+ (cellInfo.m[1] + cellInfo.m[3] + cellInfo.hordiff) 
+ ") + 'px'");
}
if (parseFloat(cellInfo.height) == cellInfo.height
|| typeof rowheight[row] == "number")
cellInfo.oHtml.style.height = ((cellInfo.height || rowheight[row]) 
- (cellInfo.m[0] + cellInfo.m[2] + cellInfo.verdiff)) + "px";
else
rule.push(id + ".style.height = (" 
+ (cellInfo.height || "rowh" + row) + " - " 
+ (cellInfo.m[0] + cellInfo.m[2] + cellInfo.verdiff)
+ ") + 'px'");
}
jpf.layout.setRules(this.oExt, "grid", (rule.length 
? "try{" + rule.join(";}catch(e){};\ntry{") + ";}catch(e){};" 
: ""), true);
update = false;
};
this.$draw = function(){
this.oExt = this.pHtmlNode.appendChild(document.createElement("div"));
this.oExt.className = "grid " + (this.$jml.getAttributeNode("class") || "");
this.oInt = this.oExt;
if (!this.oExt.getAttribute("id")) 
jpf.setUniqueHtmlId(this.oExt);
id = jpf.hasHtmlIdsInJs 
? this.oExt.getAttribute("id")
: "document.getElementById('" + this.oExt.getAttribute("id") + "')";
this.oExt.style.top    = 0;
this.oExt.style.position = "relative";
if (this.$jml.getAttribute("class")) 
jpf.setStyleClass(this.oExt, this.$jml.getAttribute("class"));
if (!jpf.isIE && !jpf.grid.$initedcss) {
jpf.importCssString(document, ".grid>*{position:absolute}");
jpf.grid.$initedcss = true;
}
};
this.$loadJml = function(x){
jpf.JmlParser.parseChildren(x, this.oInt, this, true);
var jmlNode, nodes = this.childNodes;
for (var i = 0, l = nodes.length; i < l; i++) {
jmlNode = nodes[i];
jmlNode.$_hide = jmlNode.$hide;
jmlNode.$_show = jmlNode.$show;
jmlNode.$hide = jmlHideShow;
jmlNode.$show = jmlHideShow;
}
this.$updateGrid();
};
});
jpf.teleport = {
tagName  : "teleport",
nodeFunc : jpf.NODE_HIDDEN,
modules: new Array(),
named: {},
register: function(obj){
var id = false, data = {
obj: obj
};
return this.modules.push(data) - 1;
},
getModules: function(){
return this.modules;
},
getModuleByName: function(defname){
return this.named[defname]
},
loadJml: function(x, parentNode){
this.$jml        = x;
this.parentNode = parentNode;
jpf.inherit.call(this, jpf.JmlDom); 
var id, obj, nodes = this.$jml.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1) 
continue;
obj = new jpf.BaseComm(nodes[i]);
if (id = nodes[i].getAttribute("id"))
jpf.setReference(id, obj);
}
this.loaded = true;
if (this.onload) 
this.onload();
return this;
},
availHTTP  : [],
releaseHTTP: function(http){
if (jpf.brokenHttpAbort) 
return;
if (self.XMLHttpRequestUnSafe && http.constructor == XMLHttpRequestUnSafe) 
return;
http.onreadystatechange = function(){};
http.abort();
this.availHTTP.push(http);
},
destroy: function(){
for (var i = 0; i < this.availHTTP.length; i++) {
this.availHTTP[i] = null;
}
}
};
jpf.BaseComm = function(x){
jpf.makeClass(this);
this.uniqueId = jpf.all.push(this) - 1;
this.$jml      = x;
this.toString = function(){
return "[Javeline Teleport Component : " + (this.name || "")
+ " (" + this.type + ")]";
}
if (this.$jml) {
this.name = x.getAttribute("id");
this.type = x[jpf.TAGNAME];
if (!jpf[this.type]) 
throw new Error(jpf.formatErrorString(1023, null, "Teleport baseclass", "Could not find Javeline Teleport Component '" + this.type + "'", this.$jml));
this.inherit(jpf[this.type]);
if (this.useHTTP) {
if (!jpf.http) 
throw new Error(jpf.formatErrorString(1024, null, "Teleport baseclass", "Could not find Javeline Teleport HTTP Component", this.$jml));
this.inherit(jpf.http);
}
if (this.$jml.getAttribute("protocol")) {
var proto = this.$jml.getAttribute("protocol").toLowerCase();
if (!jpf[proto]) 
throw new Error(jpf.formatErrorString(1025, null, "Teleport baseclass", "Could not find Javeline Teleport RPC Component '" + proto + "'", this.$jml));
this.inherit(jpf[proto]);
}
}
if (this.$jml) 
this.load(this.$jml);
};
jpf.Init.run('Teleport');
jpf.convertIframe = function(iframe, preventSelect){
var win = iframe.contentWindow;
var doc = win.document;
var pos;
if (!jpf.isIE)
jpf.importClass(jpf.runNonIe, true, win);
if (this.isSafari) 
this.importClass(jpf.runSafari, true, win);
if (this.isOpera) 
this.importClass(jpf.runOpera, true, win);
if (this.isGecko || !this.isIE && !this.isSafari && !this.isOpera)
this.importClass(jpf.runGecko, true, win);
doc.onkeydown = function(e){
if (!e) e = win.event;
if (document.onkeydown) 
return document.onkeydown.call(document, e);
};
doc.onmousedown = function(e){
if (!e) e = win.event;
var q = {
offsetX       : e.offsetX,
offsetY       : e.offsetY,
x             : e.x + pos[0],
y             : e.y + pos[1],
button        : e.button,
clientX       : e.x + pos[0],
clientY       : e.y + pos[1],
srcElement    : iframe,
target        : iframe,
targetElement : iframe
}
if (document.body.onmousedown)
document.body.onmousedown(q);
if (document.onmousedown)
document.onmousedown(q);
if (preventSelect && !jpf.isIE)
return false;
};
if (preventSelect) {
doc.onselectstart = function(e){
return false;
};
}
doc.onmouseup = function(e){
if (!e) e = win.event;
if (document.body.onmouseup)
document.body.onmouseup(e);
if (document.onmouseup)
document.onmouseup(e);
};
doc.onclick = function(e){
if (!e) e = win.event;
if (document.body.onclick)
document.body.onclick(e);
if (document.onclick)
document.onclick(e);
};
doc.documentElement.oncontextmenu = function(e){
if (!e) e = win.event;
if (!pos)
pos = jpf.getAbsolutePosition(iframe);
var q = {
offsetX       : e.offsetX,
offsetY       : e.offsetY,
x             : e.x + pos[0],
y             : e.y + pos[1],
button        : e.button,
clientX       : e.x + pos[0],
clientY       : e.y + pos[1],
srcElement    : e.srcElement,
target        : e.target,
targetElement : e.targetElement
};
if (document.body.oncontextmenu)
document.body.oncontextmenu(q);
if (document.oncontextmenu)
document.oncontextmenu(q);
return false;
};
doc.documentElement.onmouseover = function(e){
pos = jpf.getAbsolutePosition(iframe);
};
doc.documentElement.onmousemove = function(e){
if (!e) e = win.event;
if (!pos)
pos = jpf.getAbsolutePosition(iframe);
var q = {
offsetX       : e.offsetX,
offsetY       : e.offsetY,
x             : e.x + pos[0],
y             : e.y + pos[1],
button        : e.button,
clientX       : e.x + pos[0],
clientY       : e.y + pos[1],
srcElement    : e.srcElement,
target        : e.target,
targetElement : e.targetElement
}
if (iframe.onmousemove)
iframe.onmousemove(q);
if (document.body.onmousemove)
document.body.onmousemove(q);
if (document.onmousemove)
document.onmousemove(q);
return e.returnValue;
};
return doc;
};
jpf.label = jpf.component(jpf.NODE_VISIBLE, function(){
var _self = this;
this.$focussable = false;
this.editableParts = {
"main": [["caption", "text()"]]
};
this.setValue = function(value){
this.setProperty("value", value);
};
this.getValue = function(){
return this.value;
}
this.$supportedProperties.push("value", "for");
this.$propHandlers["value"] = function(value){
this.oInt.innerHTML = value;
};
this.$draw = function(){
this.oExt = this.$getExternal();
this.oInt = this.$getLayoutNode("main", "caption", this.oExt);
if (this.oInt.nodeType != 1) 
this.oInt = this.oInt.parentNode;
this.oExt.onmousedown = function(){
var forElement = self[this["for"]];
if (forElement && forElement.$focussable && forElement.focussable)
forElement.focus();
}
};
this.$loadJml = function(x){
if (jpf.xmldb.isOnlyChild(x.firstChild, [3,4]))
this.$handlePropSet("value", x.firstChild.nodeValue.trim());
else
jpf.JmlParser.parseChildren(this.$jml, this.oInt, this);
this.$makeEditable("main", this.oExt, this.$jml);
};
}).implement(
jpf.DataBinding,
jpf.BaseSimple
)
jpf.StateServer = {
states: {},
groups: {},
locs  : {},
removeGroup: function(name, elState){
this.groups[name].remove(elState);
if (!this.groups[name].length) {
if (self[name]) {
self[name].destroy();
self[name] = null;
}
delete this.groups[name];
}
},
addGroup: function(name, elState, pNode){
if (!this.groups[name]) {
this.groups[name] = [];
var pState = new jpf.state(null, "state");
pState.parentNode = pNode;
pState.inherit(jpf.JmlDom);
pState.name   = name;
pState.toggle = function(){
for (var next = 0, i = 0; i < jpf.StateServer.groups[name].length; i++) {
if (jpf.StateServer.groups[name][i].active) {
next = i + 1;
break;
}
}
jpf.StateServer.groups[name][
(next == jpf.StateServer.groups[name].length) ? 0 : next
].activate();
}
this.groups[name].pState = self[name] = pState;
}
if (elState)
this.groups[name].push(elState);
return this.groups[name].pState;
},
removeState: function(elState){
delete this.states[elState.name];
},
addState: function(elState){
this.states[elState.name] = elState;
}
}
jpf.state = jpf.component(jpf.NODE_HIDDEN, function(){
this.$supportedProperties.push("active");
this.$propHandlers["active"] = function(value){
if (jpf.isTrue(value)) {
if (this.group) {
var nodes = jpf.StateServer.groups[this.group];
for (var i = 0; i < nodes.length; i++) {
if (nodes[i] != this && nodes[i].active !== false)
nodes[i].deactivate();
}
}
var q = this.$signalElements;
for (var i = 0; i < q.length; i++) {
self[q[i][0]].setProperty(q[i][1], this[q[i].join(".")]);
}
if (this.group) {
var attr = this.$jml.attributes;
for (var i = 0; i < attr.length; i++) {
if (attr[i].nodeName.match(/^on|^(?:group|id)$|^.*\..*$/))
continue;
self[this.group].setProperty(attr[i].nodeName,
attr[i].nodeValue);
}
}
this.dispatchEvent("change");
}
else {
this.setProperty("active", false);
this.dispatchEvent("change");
}
};
this.setValue = function(value){
this.active = 9999;
this.setProperty("active", value);
};
this.activate = function(){
this.active = 9999;
this.setProperty("active", true);
};
this.deactivate = function(){
this.setProperty("active", false);
};
this.$signalElements = [];
this.$loadJml = function(x){
jpf.StateServer.addState(this);
this.group = x.getAttribute("group");
if (this.group)
jpf.StateServer.addGroup(this.group, this);
if (x.getAttribute("location"))
jpf.StateServer.locs[x.getAttribute("location")] = this;
var attr = x.attributes;
for (var s, i = 0; i < attr.length; i++) {
if (attr[i].nodeName.match(/^on|^(?:group|id)$/))
continue;
s = attr[i].nodeName.split(".");
if (s.length == 2)
this.$signalElements.push(s);
this[attr[i].nodeName] = attr[i].nodeValue;
}
};
this.$destroy = function(){
this.$signalElements = null;
jpf.StateServer.removeState(this);
if (this.group)
jpf.StateServer.removeGroup(this.group, this);
};
});
jpf.appsettings = {
tagName            : "appsettings",
nodeType           : jpf.NODE_ELEMENT,
nodeFunc           : jpf.NODE_HIDDEN,
disableRightClick  : false,
allowSelect        : false,
allowBlur          : false,
autoDisableActions : false,
autoDisable        : false, 
disableF5          : true,
autoHideLoading    : true,
disableSpace       : true,
disableBackspace   : true,
useUndoKeys        : false,
outline            : false,
dragOutline        : false,
resizeOutline      : false,
disableTabbing     : false,
skinset            : "default",
name               : "",
tags               : {},
defaults           : {},
baseurl            : "",
init : function(){
},
getDefault : function(type, prop){
var d = this.defaults[type];
if (!d)
return;
for (var i = d.length - 1; i >= 0; i--) {
if (d[i][0] == prop)
return d[i][1];
}
},
setProperty : function(name, value){
if (name == "outline") {
this.dragOutline   =
this.resizeOutline =
this.outline       = value;
}
else if (name == "skinset") {
this.skinset = value;
jpf.skins.changeSkinset(value);
}
},
loadJml: function(x, parentNode){
this.$jml = x;
this.parentNode = parentNode;
jpf.inherit.call(this, jpf.JmlDom); 
jpf.debug = jpf.isTrue(x.getAttribute("debug"));
if (x.getAttribute("debug-type"))
jpf.debugType = x.getAttribute("debug-type");
var nodes = x.attributes;
for (var i = 0, l = nodes.length; i < l; i++) {
this.tags[nodes[i].nodeName] = nodes[i].nodeValue;
}
this.name               = x.getAttribute("name")
|| window.location.href.replace(/[^0-9A-Za-z_]/g, "_");
this.baseurl            = jpf.parseExpression(x.getAttribute("baseurl") || "");
this.disableRightClick  = jpf.isTrue(x.getAttribute("disable-right-click"));
this.allowSelect        = jpf.isTrue(x.getAttribute("allow-select"));
this.allowBlur          = !jpf.isFalse(x.getAttribute("allow-blur"));
this.autoDisableActions = jpf.isTrue(x.getAttribute("auto-disable-actions"));
this.autoDisable        = jpf.isTrue(x.getAttribute("auto-disable")); 
this.disableF5          = jpf.isTrue(x.getAttribute("disable-f5"));
this.autoHideLoading    = !jpf.isFalse(x.getAttribute("auto-hide-loading"));
this.disableSpace       = !jpf.isFalse(x.getAttribute("disable-space"));
this.disableBackspace   = jpf.isTrue(x.getAttribute("disable-backspace"));
this.useUndoKeys        = jpf.isTrue(x.getAttribute("undokeys"));
if (x.getAttribute("outline")) {
this.dragOutline    =
this.resizeOutline  =
this.outline        = jpf.isTrue(jpf.parseExpression(x.getAttribute("outline")));
}
else {
this.dragOutline    = x.getAttribute("drag-outline")
? jpf.isTrue(jpf.parseExpression(x.getAttribute("drag-outline")))
: false;
this.resizeOutline  = x.getAttribute("resize-outline")
? !jpf.isFalse(jpf.parseExpression(x.getAttribute("resize-outline")))
: false;
}
this.layout  = x.getAttribute("layout") || null;
this.skinset = x.getAttribute("skinset") || "default";
if (x.getAttribute("login"))
jpf.auth.init(x);
var oFor, attr, d, j, i, l, node, nodes = x.childNodes;
for (i = 0, l = nodes.length; i < l; i++) {
node = nodes[i];
if (node.nodeType != 1)
continue;
var tagName = node[jpf.TAGNAME];
switch(tagName){
case "auth":
case "authentication":
this.auth = node;
jpf.auth.init(node);
break;
default:
break;
}
}
return this;
}
};
jpf.rpc = function(){
if (!this.supportMulticall)
this.multicall = false;
this.stack   = {};
this.urls    = {};
this.tagName = "rpc";
this.useHTTP = true;
this.TelePortModule = true;
this.routeServer    = jpf.host + "/cgi-bin/rpcproxy.cgi";
this.autoroute      = false;
this.namedArguments = false;
var _self = this;
this.addMethod = function(name, callback, names, async, caching, ignoreOffline){
this[name] = function(){
return this.call(name, arguments);
}
this[name].async         = async;
this[name].caching       = caching;
this[name].names         = names;
this[name].ignoreOffline = ignoreOffline;
if (callback)
this[name].callback = callback;
return true;
}
this.setCallback = function(name, func){
this[name].callback = func;
}
this.$convertArgs = function(name, args){
if (!this.namedArguments)
return args.slice();
var nodes = this[name].names;
if (!nodes || !nodes.length)
return {};
var name, value, result = {};
for (var j = 0, i = 0; i < nodes.length; i++) {
name = nodes[i].getAttribute("name");
if (nodes[i].getAttribute("value"))
value = jpf.parseExpression(nodes[i].getAttribute("value"));
else {
value = args[j++];
if (jpf.isNot(value) && nodes[i].getAttribute("default"))
value = jpf.parseExpression(nodes[i].getAttribute("default"));
}
value = jpf.isTrue(nodes[i].getAttribute("encoded"))
? encodeURIComponent(value)
: value;
result[name] = value;
}
return result;
}
this.call = function(name, args, options){
args = this.$convertArgs(name, args);
if (this.multicall) {
if (!this.stack[this.url])
this.stack[this.url] = this.getMulticallObject
? this.getMulticallObject()
: new Array();
this.getSingleCall(name, args, this.stack[this.url])
return true;
}
var callback = (typeof this[name].callback == "string"
? self[this[name].callback]
: this[name].callback) || function(){};
var data = this.serialize(name, args); 
function pCallback(data, state, extra){
extra.data = data;
if(state != jpf.SUCCESS)
callback(null, state, extra);
else if (_self.isValid && !_self.isValid(extra))
callback(null, jpf.ERROR, extra);
else
callback(_self.unserialize(extra.data), state, extra);
}
var url  = jpf.getAbsolutePath(this.baseurl, this.url);
var info = this.get(url, pCallback, jpf.extend({
async    : this[name].async,
userdata : this[name].userdata,
nocache  : true,
data     : data,
useXML   : this.useXML,
caching  : this[name].caching,
ignoreOffline : this[name].ignoreOffline
}, options));
return info;
}
this.purge = function(callback, userdata, async, extradata){
var data = this.serialize("multicall", [this.stack[this.url]]); 
var url  = jpf.getAbsolutePath(this.baseurl, this.url);
if (extradata) {
for (var vars = [], i = 0; i < extradata.length; i++) {
vars.push(encodeURIComponent(extradata[i][0]) + "="
+ encodeURIComponent(extradata[i][1] || ""))
}
url = url + (url.match(/\?/) ? "&" : "?") + vars.join("&");
}
var info = this.get(url, callback, {
async    : async,
userdata : userdata,
nocache  : true,
data     : data,
useXML   : this.useXML
});
this.stack[this.url] = this.getMulticallObject
? this.getMulticallObject()
: [];
}
this.revert = function(modConst){
this.stack[modConst.url] = this.getMulticallObject
? this.getMulticallObject()
: [];
}
this.getStackLength = function(){
return this.stack[this.url] ? this.stack[this.url].length : 0;
}
this.load = function(x){
this.$jml       = x;
this.timeout   = parseInt(x.getAttribute("timeout")) || this.timeout;
this.url       = jpf.parseExpression(x.getAttribute("url"))
this.baseurl   = jpf.parseExpression(
jpf.xmldb.getInheritedAttribute(
this.$jml, "baseurl")) || "";
this.multicall = x.getAttribute("multicall") == "true";
this.autoroute = x.getAttribute("autoroute") == "true";
if (this.url)
this.server = this.url.replace(/^(.*\/\/[^\/]*)\/.*$/, "$1") + "/";
if (this.$load)
this.$load(x);
var q = x.childNodes;
for (var url, i = 0; i < q.length; i++) {
if (q[i].nodeType != 1)
continue;
url = jpf.parseExpression(q[i].getAttribute("url"));
if (url)
this.urls[q[i].getAttribute("name")] = url;
this.addMethod(q[i].getAttribute("name"),
q[i].getAttribute("receive") || x.getAttribute("receive"),
q[i].getElementsByTagName("*"), 
!jpf.isFalse(q[i].getAttribute("async")),
jpf.isTrue(q[i].getAttribute("caching")),
jpf.isTrue(q[i].getAttribute("ignore-offline")));
}
}
}
jpf.datainstr.rpc = function(xmlContext, options, callback){
var parsed = options.parsed || this.parseInstructionPart(
options.instrData.join(":"), xmlContext, options.args, options);
if (options.preparse) {
options.parsed = parsed;
options.preparse = -1;
return;
}
var args   = parsed.arguments;
var q      = parsed.name.split(".");
var obj    = eval(q[0]);
var method = q[1];
if (options.multicall)
obj.forceMulticall = true;
if (options.userdata)
obj[method].userdata = options.userdata;
if (!obj.multicall)
obj[method].callback = callback; 
var retvalue = obj.call(method, args, options);
if (obj.multicall)
return obj.purge(callback, "&@^%!@"); 
else if (options.multicall) {
obj.forceMulticall = false;
return obj;
}
if (!obj.multicall && !obj[method].async && callback)
callback(retvalue);
}
jpf.http = function(){
this.queue     = [null];
this.callbacks = {};
this.cache     = {};
this.timeout   = 10000; 
if (!this.uniqueId)
this.uniqueId = jpf.all.push(this) - 1;
var _self = this;
jpf.teleport.register(this);
this.toString = this.toString || function(){
return "[Javeline TelePort Component : (HTTP)]";
}
this.getXml = function(url, callback, options){
if(!options) options = {};
options.useXML = true;
return this.get(url, callback, options);
};
this.get = function(url, callback, options, id){
if(!options)
options = {};
var async = options.async
|| typeof options.async == "undefined" || jpf.isOpera;
if (jpf.isSafari)
url = jpf.html_entity_decode(url);
var data = options.data || "";
if (jpf.isNot(id)) {
var http = jpf.getHttpReq();
id = this.queue.push({
http     : http,
url      : url,
callback : callback,
retries  : 0,
options  : options
}) - 1;
}
else {
var http = this.queue[id].http;
http.abort();
}
if (async) {
{
http.onreadystatechange = function(){
if (!_self.queue[id] || http.readyState != 4)
return;
_self.receive(id);
}
}
}
var autoroute = this.autoroute && jpf.isOpera
? true 
: (options.autoroute || this.shouldAutoroute);
var httpUrl = autoroute ? this.routeServer : url;
var errorFound = false;
try {
if (options.nocache)
httpUrl = jpf.getNoCacheUrl(httpUrl);
http.open(this.method || options.method || "GET", httpUrl,
async, options.username || null, options.password || null);
http.setRequestHeader("User-Agent", "Javeline TelePort 2.0"); 
http.setRequestHeader("X-Requested-With", "XMLHttpRequest");
http.setRequestHeader("Content-type", this.contentType
|| (this.useXML || options.useXML ? "text/xml" : "text/plain"));
if (autoroute) {
http.setRequestHeader("X-Route-Request", url);
http.setRequestHeader("X-Proxy-Request", url);
http.setRequestHeader("X-Compress-Response", "gzip");
}
}
catch (e) {
errorFound = true;
}
if (errorFound) {
var useOtherXH = false;
if (self.XMLHttpRequestUnSafe) {
try {
http = new XMLHttpRequestUnSafe();
http.onreadystatechange = function(){
if (!_self.queue[id] || http.readyState != 4)
return;
_self.receive(id);
}
http.open(this.method || options.method || "GET", (options.nocache
? jpf.getNoCacheUrl(httpUrl)
: httpUrl), async);
this.queue[id].http = http;
options.async     = true; 
useOtherXH        = true;
}
catch (e) {}
}
if (!useOtherXH && this.autoroute && !autoroute) {
this.shouldAutoroute = true;
options.autoroute = true;
return this.get(url, receive, options, id);
}
if (!useOtherXH) {
var noClear = callback ? callback(null, jpf.ERROR, {
userdata: options.userdata,
http    : http,
url     : url,
tpModule: this,
id      : id,
message : "Permission denied accessing remote resource: " + url
}) : false;
if (!noClear)
this.clearQueueItem(id);
return;
}
}
if (this.$HeaderHook)
this.$HeaderHook(http);
if (options.headers) {
for (var name in options.headers)
http.setRequestHeader(name, options.headers[name]);
}
function send(isLocal){
var hasError;
if (isLocal)
http.send(data);
else {
try{
http.send(data);
}
catch(e){
hasError = true;
}
}
if (hasError) {
var msg = window.navigator.onLine
? "File or Resource not available " + url
: "Browser is currently working offline";
var state = window.navigator.onLine
? jpf.ERROR
: jpf.TIMEOUT;
var noClear = callback ? callback(null, state, {
userdata : options.userdata,
http     : http,
url      : url,
tpModule : this,
id       : id,
message  : msg
}) : false;
if(!noClear) this.clearQueueItem(id);
return;
}
}
if (!async) {
send.call(this);
return this.receive(id);
}
else {
if (jpf.isIE && location.protocol == "file:"
&& url.indexOf("http://") == -1) {
setTimeout(function(){
send.call(_self, true);
});
}
else
send.call(_self);
return id;
}
};
this.receive = function(id){
if (!this.queue[id])
return false;
var qItem    = this.queue[id];
var http     = qItem.http;
var callback = qItem.callback;
if (window.navigator.onLine === false && (location.protocol != "file:"
|| qItem.url.indexOf("http://") > -1))
return false;
try {
if (http.status) {}
}
catch (e) {
return setTimeout(function(){
_self.receive(id)
}, 10);
}
var errorMessage = [];
var extra = {
tpModule : this,
http     : http,
url      : qItem.url,
callback : callback,
id       : id,
retries  : qItem.retries || 0,
userdata : qItem.options.userdata
}
if (http.status > 600)
return this.$timeout(id); 
extra.data = http.responseText; 
if (http.status >= 400 && http.status < 600) {
if (http.status == 401) {
var wasDelayed = qItem.isAuthDelayed;
qItem.isAuthDelayed = true;
if (jpf.auth.authRequired(extra, wasDelayed) === true)
return;
}
errorMessage.push("HTTP error [" + id + "]:" + http.status + "\n" + http.responseText);
}
if (qItem.options.useXML || this.useXML) {
if ((http.responseText || "").replace(/^[\s\n\r]+|[\s\n\r]+$/g, "") == "")
errorMessage.push("Received an empty XML document (0 bytes)");
else {
try {
var xmlDoc = (http.responseXML && http.responseXML.documentElement)
? jpf.xmlParseError(http.responseXML)
: jpf.getXmlDom(http.responseText);
if (!jpf.supportNamespaces)
xmlDoc.setProperty("SelectionLanguage", "XPath");
extra.data = xmlDoc.documentElement;
}
catch(e){
errorMessage.push("Received invalid XML\n\n" + e.message);
}
}
}
if (errorMessage.length) {
extra.message = errorMessage.join("\n");
if (!callback || !callback(null, jpf.ERROR, extra))
this.clearQueueItem(id);
return;
}
if (!callback || !callback(extra.data, jpf.SUCCESS, extra))
this.clearQueueItem(id);
return extra.data;
};
this.$timeout = function(id){
if (!this.queue[id])
return false;
var qItem = this.queue[id];
var http  = qItem.http;
try {
if (http.status) {}
}
catch (e) {
return setTimeout(function(){
_self.$timeout(id)
}, 10);
}
var callback = qItem.callback;
http.abort();
var noClear = callback ? callback(null, jpf.TIMEOUT, {
userdata: qItem.options.userdata,
http    : http,
url     : qItem.url,
tpModule: this,
id      : id,
message : "HTTP Call timed out",
retries : qItem.retries || 0
}) : false;
if (!noClear)
this.clearQueueItem(id);
};
this.retryTimeout = function(extra, state, jmlNode, oError, maxRetries){
if (state == jpf.TIMEOUT
&& extra.retries < (maxRetries || jpf.maxHttpRetries))
return extra.tpModule.retry(extra.id);
if ((jmlNode || jpf).dispatchEvent("error", jpf.extend({
error   : oError,
state   : state,
bubbles : true
}, extra)) === false)
return true;
};
this.clearQueueItem = function(id){
if (!this.queue[id])
return false;
jpf.teleport.releaseHTTP(this.queue[id].http);
this.queue[id] = null;
delete this.queue[id];
return true;
};
this.retry = function(id){
if (!this.queue[id])
return false;
var qItem = this.queue[id];
qItem.retries++;
this.get(qItem.url, qItem.callback, qItem.options, id);
return true;
};
this.cancel = function(id){
if (id === null)
id = this.queue.length - 1;
if (!this.queue[id])
return false;
this.clearQueueItem(id);
};
if (!this.load) {
this.load = function(x){
var receive = x.getAttribute("receive");
for (var i = 0; i < x.childNodes.length; i++) {
if (x.childNodes[i].nodeType != 1)
continue;
var url      = x.childNodes[i].getAttribute("url");
var callback = self[x.childNodes[i].getAttribute("receive") || receive];
var options  = {
useXML  : x.childNodes[i].getAttribute("type") == "XML",
async   : !jpf.isFalse(x.childNodes[i].getAttribute("async"))
}
this[x.childNodes[i].getAttribute("name")] = function(data, userdata){
options.userdata = userdata;
options.data     = data;
return this.get(url, callback, options);
}
}
};
this.instantiate = function(x){
var url     = x.getAttribute("src");
var options = {
async   : x.getAttribute("async") != "false",
nocache : true
}
this.getURL = function(data, userdata){
options.data     = data;
options.userdata = userdata;
return this.get(url, this.callbacks.getURL, options);
}
var name = "http" + Math.round(Math.random() * 100000);
jpf.setReference(name, this);
return name + ".getURL()";
};
this.call = function(method, args){
this[method].call(this, args);
};
}
};
jpf.Init.run('http');
jpf.Init.run('XmlDatabase');
jpf.cgi = function(){
this.supportMulticall = false;
this.namedArguments   = true;
jpf.teleport.register(this);
if (!this.uniqueId) {
jpf.makeClass(this);
this.inherit(jpf.BaseComm, jpf.http, jpf.rpc);
}
this.unserialize = function(str){
return str;
}
this.getSingleCall = function(name, args, obj){
obj.push(args);
}
this.serialize = function(functionName, args){
var vars    = [];
function recur(o, stack){
if (o && o.dataType == "array") {
for (var j = 0; j < o.length; j++)
recur(o[j], stack + "%5B" + j + "%5D");
}
else if (typeof o == "object") {
for (prop in o) {
if (jpf.isSafariOld && (!o[prop] || typeof p[prop] != "object"))
continue;
if (typeof o[prop] == "function")
continue;
recur(o[prop], stack + "%5B" + encodeURIComponent(prop) + "%5D");
}
}
else {
if (typeof o != "undefined" && o !== null) 
vars.push(stack + "=" + encodeURIComponent(o));
}
};
if (this.multicall) {
vars.push("func" + "=" + this.mcallname);
for (var i = 0; i < args[0].length; i++)
recur(args[0][i], "f%5B" + i + "%5D");
}
else {
for (prop in args) {
if (jpf.isSafariOld && (!args[prop] || typeof args[prop] == "function"))
continue;
recur(args[prop], prop);
}
}
if (!this.baseUrl)
this.baseUrl = this.url;
this.url = this.urls[functionName]
? this.urls[functionName]
: this.baseUrl;
if (this.method != "GET")
return vars.join("&");
this.url = this.url + (vars.length
? (this.url.indexOf("?") > -1 ? "&" : "?") + vars.join("&")
: "");
return "";
}
this.$load = function(x){
this.method      = (x.getAttribute("http-method") || "GET").toUpperCase();
this.contentType = this.method == "GET"
? null
: "application/x-www-form-urlencoded";
if (x.getAttribute("method-name")) {
var mName = x.getAttribute("method-name");
var nodes = x.childNodes;
for (var v, i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType != 1)
continue;
v = nodes[i].insertBefore(x.ownerDocument.createElement("variable"),
nodes[i].firstChild);
v.setAttribute("name",  mName);
v.setAttribute("value", nodes[i].getAttribute("name"));
}
}
}
this.submitForm = function(form, callback){
if (!this['postform'])
this.addMethod('postform', callback);
var args = [];
for (var i = 0; i < form.elements.length; i++) {
if (!form.elements[i].name)
continue;
if (form.elements[i].tagname = 'input'
&& (form.elements[i].type == 'checkbox'
|| form.elements[i].type == 'radio')
&& !form.elements[i].checked)
continue;
if (form.elements[i].tagname = 'select' && form.elements[i].multiple) {
for (j = 0; j < form.elements[i].options.length; j++) {
if (form.elements[i].options[j].selected)
args.push(form.elements[i].name
+ "="
+ encodeURIComponent(form.elements[i].options[j].value));
}
}
else {
args.push(form.elements[i].name
+ "="
+ encodeURIComponent(form.elements[i].value));
}
}
var loc               = (form.action || location.href);
this.urls['postform'] = loc + (loc.indexOf("?") > -1 ? "&" : "?") + args.join("&");
this['postform'].call(this);
return false;
}
}
jpf.namespace("datainstr.url", function(xmlContext, options, callback){
if (!options.parsed) {
var url = options.instrData.join(":");
if (xmlContext) {
url = url.replace(/\{(.*?)\}/g,
function(m, xpath){
var o = xmlContext.selectSingleNode(xpath);
return o
? (o.nodeType >= 2 && o.nodeType <= 4
? o.nodeValue
: jpf.xmldb.convertXml(o, "cgivars"))
: ""
});
}
var split    = url.split("?");
url      = split.shift();
var query    = split.join("?");
var args     = options.args;
var httpBody = (args && args.length)
? (args[0].nodeType
? args[0].xml || args[0].serialize()
: jpf.serialize(args[0]))
: query;
if (options.preparse) {
options.parsed = [url, query, httpBody];
options.preparse = -1;
return;
}
}
else {
var url      = options.parsed[0];
var query    = options.parsed[1];
var httpBody = options.parsed[2];
}
var oHttp = new jpf.http();
oHttp.contentType = "application/x-www-form-urlencoded";
oHttp.method = (options.instrType.replace(/url.?/, "") || "GET").toUpperCase();
oHttp.get(jpf.getAbsolutePath(jpf.appsettings.baseurl, url + (oHttp.method == "GET" ? "?" + query : "")), callback,
jpf.extend({data : httpBody}, options));
});
jpf.Init.addConditional(function(){
jpf.dispatchEvent("domready");
}, null, ["body", "class"]);
jpf.addDomLoadEvent(function(){jpf.Init.run('body');});
jpf.start();
