//String object prototypes
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
};

String.prototype.replaceAll = function (regex, replacement) {
    var sb = '';
    var index = this.indexOf(regex);
    var index2 = 0;

    while (index != -1) {
        sb += this.substring(index2, index);
        sb += replacement;
        index2 = index + regex.length;
        index = this.indexOf(regex, index2);
    }
    sb += this.substring(index2);
    return sb;
};

String.prototype.capitalize = function() {
    if (!this || this == "") {
        return this;
    }

    return this.substr(0, 1).toUpperCase() + this.substr(1);
}


//Array object prototypes
Array.prototype.removeByIndex = function (index) {
    if (index < 0 || index >= this.length) {
        alert("Index out of bound");
        return;
    }
    if (index != -1) {
        this.splice(index, 1);
    }
};

Array.prototype.indexOf = function (o) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == o) {
            return i;
        }
    }
    return -1;
};

Array.prototype.lastIndexOf = function (o) {
    for (var i = this.length - 1; i >= 0; i--) {
        if (this[i] == o) return i;
    }
    return -1;
};

Array.prototype.contains = function (o) {
    return this.indexOf(o) != -1;
};

Array.prototype.copy = function () {
    return this.concat();
};

Array.prototype.insertAt = function (o, i) {
    this.splice(i, 0, o);
};

Array.prototype.insertBefore = function (o, o2) {
    var i = this.indexOf(o2);
    if (i == -1) {
        this.push(o);
    } else {
        this.splice(i, 0, o);
    }
};

Array.prototype.removeAt = function (i) {
    this.splice(i, 1);
};

Array.prototype.remove = function (o) {
    var i = this.indexOf(o);
    if (i != -1) {
        this.splice(i, 1);
    }
};

Array.prototype.replace = function (o, o2) {
    var i = this.indexOf(o);
    if (i != -1) {
        this[i] = o2;
    }
};

Array.prototype.replaceByIndex = function (i, o2) {
    this[i] = o2;
};

Array.prototype.findIf = function (predicate) {
    try {
        var l = this.length;
        var item = null;
        for (var i = 0; i < l; i++) {
            item = this[i];
            if (predicate(item)) {
                return item;
            }
        }
    } catch (ex) {
        return null;
    }
};

Array.prototype.findAllIf = function (predicate) {
    var result = new Array();
    try {
        var l = this.length;
        var item = null;
        for (var i = 0; i < l; i++) {
            item = this[i];
            if (predicate(item)) {
                result.push(item);
            }
        }
    } catch (ex) {
        result.length = 0;
    }

    return result;
};

Array.prototype.removeIf = function (predicate) {
    var result = false;
    try {
        var l = this.length;
        var item = null;
        for (var i = l - 1; i >= 0; i--) {
            item = this[i];
            if (predicate(item)) {
                result = true;
                this.removeAt(i);
            }
        }
        return result;
    } catch (ex) {
        return false;
    }
};

Array.prototype.clear = function() {
    this.splice(0, this.length);
};

Array.prototype.empty = function () {
    return (this.length == 0);
}

Array.prototype.get = function (index) {
    return this[index];
}

//Check formats
function numberParseInt(str) {
    if (str != "") {
        var result = parseInt(str, 10);
        return Math.min(2147483647, Math.max(-2147483648, result));
    } else {
        return NaN;
    }
}

function numberParseLong(str) {
    if (str != "") {
        var result = parseInt(str, 10);
        return Math.min(9223372036854775807, Math.max(-9223372036854775808, result));
    } else {
        return NaN;
    }
}

function numberParseFloat(str) {
    if (str != "") {
        return parseFloat(str);
    } else {
        return NaN;
    }
}

function numberParseBoolean(str) {
	if (!str) {
		return false;
	}

	str = str.toString().toLowerCase();
	return (str == "true" || str == "t" || str == "1");
}

function parsePercent(str) {
    if (!str) {
        return "";
    }
    var s = str.trim();
    if (s.indexOf("%") == s.length - 1) {
        return s.slice(0, -1);
    }

    return numberParseInt(s);
}

//XML Tree navigation functions
function findChildNode(node, predicate) {
	if (node == null || typeof node == "undefined") {
		return null;
	}
    if (predicate(node)) {
        return node;
    }
    var item = null;
    var l = node.childNodes.length;
    for (var i = 0; i < l; i++) {
        var childNode = node.childNodes[i];
        if (childNode.nodeType != 1) {
            continue;
        }
        item = findChildNode(childNode, predicate);
        if (item != null) {
            return item;
        }
    }
    return null;
}

function findFirstChild(parent) {
    if (!parent) return null;
    var l = parent.childNodes.length;
    for (var i = 0; i < l; i++) {
        var node = parent.childNodes[i];
        if (node.nodeType == 1) {
            return node;
        }
    }
    return null;
}

function findChildNodeByType(node, type) {
    return findChildNode(node, function (o) {
    	if (o == null || typeof o == "undefined") return false;
        return o.getAttribute("mcfType") == type;
    });
}

function findChildNodes(node, predicate) {
    function _findChildNodes(node, predicate) {
        if (predicate(node)) {
            result.push(node);
        }
        var l = node.childNodes.length;
        for (var i = 0; i < l; i++) {
            var childNode = node.childNodes[i];
            if (childNode.nodeType != 1) {
                continue;
            }
            _findChildNodes(childNode, predicate);
        }
    }

    var result = new Array();
    _findChildNodes(node, predicate);
    return result;
}

function findChildNodesByType(node, type) {
    return findChildNodes(node, function (o) {
        return o.getAttribute("mcfType") == type;
    });
}

function findChildNodesByAttribute(node, type, attr) {
    return findChildNodes(node, function (o) {
        return o.getAttribute(attr) == type;
    });
}

function findChildNodesByNodeName(node, nodeName) {
    return findChildNodes(node, function (o) {
        return o.nodeName.toLowerCase() == nodeName;
    });
}

function findFirstChildTag(node) {
    var children = node.childNodes;
    var l = children.length;
    for (var i = 0; i < l; i++) {
        if (children[i].nodeType == 1) {
            return children[i];
        }
    }
    return null;
}

function findParentNode(node, predicate) {
    try {
        while (node && !predicate(node)) {
            node = node.parentNode;
        }
        return node;
    } catch (ex) {
        return null;
    }
}

function findParentNodeByType(node, type) {
    return this.findParentNode(node, function(o) {
        return o.getAttribute("mcfType") == type;
    });
}

function getNodeText(node) {
    if (node.text != undefined) {
        return node.text;
    } else if (node.textContent != undefined) {
        return node.textContent;
    } else if (node.innerText != undefined) {
        return htmlUnescape(node.innerText);
    } else {
        return "";
    }
}

function getTextNodeValue(node) {
    var tn;
    if (node && (tn = node.firstChild) && tn && tn.nodeType == 3) {
        return tn.nodeValue.trim();
    }
    return "";
}

function setTextNodeValue(node, value) {
    if (!(node && value)) {
        return;
    }
    var tn = node.firstChild;
    if (tn && tn.nodeType == 3) {
        tn.nodeValue = value.trim();
    } else {
        var textNode = document.createTextNode(value.trim());
        node.appendChild(textNode);
    }
}

function appendNodeValue(node, value) {
    node.innerHTML += value + "<br />";
}

function hasChildTagNodes(node) {
    if (!node.hasChildNodes()) {
        return false;
    }
    var children = node.childNodes;
    for (var i = 0; i < children.length; i++) {
        if (children[i].nodeType == 1) {
            return true;
        }
    }
    return false;
}

var toluna = new Object();

toluna.components = new Array();

function createObject(clazz) {
    var p = clazz.prototype;
    if (!p["superConstructor"]) {
        throw "Cannot locate <superConstructor> method for class [" + clazz + "]";
    }
    var o = p["superConstructor"].apply(new clazz(), Array.prototype.slice.apply(arguments, [1]));
    toluna.components.push(o);
    return o;
}

function assert(condition, message, comment) {
    if (!condition) {
        alert("Assertion failed!" + (message ? "\n" + message : ""));
        if (comment) {
            alert(comment);
        }
        throw message;
    }
}

function finalizeComponents() {
//    alert(toluna.components.length);
    for (var i = 0; i < toluna.components.length; i++) {
//        alert(toluna.components[i]);
        if (toluna.components[i].cleanUp) {
            toluna.components[i].cleanUp();
        }
    }
}

toluna.createObject = createObject;
toluna.assert = assert;

function importNode(doc, node) {
    function _import(node) {
        if (!node) {
            return null;
        }
        var n;
        if (node.nodeType == 1) {
            n = doc.createElement(node.nodeName);
            copyAttributes(node, n, true);

        } else if (node.nodeType == 3) {
            n = doc.createTextNode(node.nodeValue);
        }

        var l = node.childNodes.length;
        for (var i = 0; i < l; i++) {
            var nn = _import(node.childNodes[i]);
            if (!nn) {
                continue;
            }
            n.appendChild(nn);
        }

        return n;
    }
    if (!(doc && node)) {
        return null;
    }

    return _import(node);
}

function copyAttributes(fromNode, toNode, ignoreEmptyAttributes) {
    var attributes = fromNode.attributes;
    for (var i = 0; i < attributes.length; i++) {
        var attribute = attributes.item(i);
        var name = attribute.name;
        var value = attribute.value;
        if (value != null && value != "null" && name != "disabled" && name != "class") {
            if (!ignoreEmptyAttributes || value != "") {
                toNode.setAttribute(name, value);
            }
        }
    }

    toNode.className = fromNode.className;
    toNode.style.cssText = fromNode.style.cssText;
}

function clearChildNodes(node) {
    while (node.hasChildNodes()) {
        node.removeChild(node.firstChild);
    }
}

function fireEvent(eventType, obj) {
    if (document.createEvent) {
        var evt = document.createEvent("Events");
        evt.initEvent(eventType, true, true);
        obj.dispatchEvent(evt);
    } else if (document.createEventObject) {
        var evt = document.createEventObject();
        obj.fireEvent('on' + eventType, evt);
    }
}

// for firefox
function showHint(obj) {
    obj.title = getTextNodeValue(obj);
}

function htmlEscape(value) {
    if (value == null) {
        value = "";
    }
    return value.toString().replace(/&/g, "&amp;").replace(/"/g, "&quot;")
            .replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

function htmlUnescape(string) {
    return string.replace(/&quot;/g, "\"").replace(/&nbsp;/g, " ").replace(/&#x00A0;/g, " ")
            .replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
}

function xmlEscape(value) {
    if (value == null) {
        value = "";
    }
    return value.toString().replace(/&/g, "&amp;").replace(/"/g, "&quot;")
                      .replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&apos;")
}

function xmlUnescape(string) {
    return string.replace(/&quot;/g, "\"").replace(/&nbsp;/g, " ").replace(/&#x00A0;/g, " ")
                      .replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&apos;/g, "\'");
}

function setParentHeight(height) {
    var parentDoc = window.parent.document;
    var parentFrame = parentDoc.getElementById('main_frame');
    parentFrame.style.height = height;
}

function setParentWidth(width) {
    var parentDoc = window.parent.document;
    var parentFrame = parentDoc.getElementById('main_frame');
    parentFrame.style.width = width;
}
var helpWnd = null;

function onShowHelp(moduleId, helpId, url) {
    var helpParams = document.getElementById(helpId);
    if (!helpParams) {
        helpParams = 'null';
    }
    else {
        helpParams = helpParams.value;
    }
    var moduleParams = document.getElementById(moduleId);
    if (!moduleParams) {
        moduleParams = 'null';
    }
    else {
        moduleParams = moduleParams.value;
    }
    if (helpWnd) {
        helpWnd.close();
        helpWnd = null;
    }
    helpWnd = window.open(url + '?moduleId=' + moduleParams + '&helpId=' + helpParams);
}

function onMakeHelp(moduleId, helpId) {
    var i = 0;
    var ok = true;
    var currentWin = window;
    var moudleInput = null;
    var helpInput = null;
    while (i < 10 && ok) {
        if (currentWin.document.getElementById('helpId')) {
            if (currentWin.document.getElementById('moduleId')) {
                ok = false;
                currentWin.document.getElementById('helpId').value = helpId;
                currentWin.document.getElementById('moduleId').value = moduleId;
            }
        }
        currentWin = currentWin.parent;
        i++;
    }
}

function unDisableTopWindow() {
    window.top.disableValue = false;
}

function getFrameHeight() {
    var height = window.innerHeight;
    if (!height) height = getScreenHeight();
    return height;
}

function getFrameWidth() {
    var width = window.innerWidth;
    if (!width) width = getScreenWidth();
    return width;
}

function resize() {
/*
    var visibleHeight = 0;
    var visibleWidth = 0;
    try {
        visibleHeight = frameElement.clientHeight - 7;
        visibleWidth = frameElement.clientWidth - 7;
    } catch (Exception) {
        var netscapeScrollWidth = 15;
        visibleWidth = window.innerWidth - 7;
        visibleHeight = window.innerHeight - 7;
    }
*/
    var visibleHeight = getFrameHeight() - 7;
    var visibleWidth = getScreenWidth() - 15;

//    alert([visibleWidth, visibleHeight]);
    mainDiv.setSize(visibleWidth, visibleHeight);
    return mainDiv.resize();
}

function getScreenWidth() {
    var visibleWidth = 0;
    
    visibleWidth = window.innerWidth; // FF
    if (typeof(visibleWidth) == "undefined" || visibleWidth == 0) {
    	visibleWidth = document.documentElement.clientWidth; // IE
        if (typeof(visibleWidth) == "undefined" || visibleWidth == 0) {
            visibleWidth = document.body.clientWidth; // IE old versions
            if (typeof(visibleWidth) == "undefined" || visibleWidth == 0) {
        		visibleWidth = 0;
        	}
        }
    }
    return visibleWidth;
}

function getScreenHeight() {

	var visibleHeight = 0;
	visibleHeight = window.innerHeight; // FF
    if (typeof(visibleHeight) == "undefined" || visibleHeight == 0) {
    	visibleHeight = document.documentElement.clientHeight; // IE
        if (typeof(visibleHeight) == "undefined" || visibleHeight == 0) {
        	visibleHeight = document.body.clientHeight; // IE old versions
        	if (typeof(visibleHeight) == "undefined" || visibleHeight == 0) {
        		visibleHeight = 0;
        	}
        }
    }
    return visibleHeight;
}

function getElementPageXOffset() {
	var xoffset = 0;
    xoffset = document.documentElement.scrollLeft; // IE
    if (typeof(xoffset) == "undefined")  {
    	xoffset = self.pageXOffset; // FF
    	if (typeof(xoffset) == "undefined")  {
    		xoffset = document.body.scrollLeft; // IE old versions
    		if (typeof(xoffset) == "undefined")  {
    			xoffset = 0;
    		}
    	}
    }
    return xoffset;
}

function getElementPageYOffset() {
    var yoffset = 0;
    yoffset = document.documentElement.scrollTop; // IE
    if (typeof(yoffset) == "undefined") {
    	yoffset = self.pageYOffset; // FF
    	if (typeof(yoffset) == "undefined") {
    		yoffset = document.body.scrollTop; // IE old versions
    		if (typeof(yoffset) == "undefined") {
        		yoffset = 0;
        	}
    	}
    }
    return yoffset;
}

function hideNodeByVisibility(node) {
    node.style.visibility = "hidden";
}

function showNodeByVisibility(node) {
    node.style.visibility = "visible";
}

function hideNode(node, simpleDisplay) {
    if (simpleDisplay) {
        node.style.display = "none";
        node.style.zIndex = -1;
        return;
    }

    if (navigator.userAgent.indexOf('Netscape') != -1) {
        node.style.visibility = "hidden";
        node.setAttribute("ownHeight", node.offsetHeight);
        node.style.height = "0px";
    } else {
        node.style.display = "none";
    }
}

function showNode(node, simpleDisplay, zIndex) {
    if (simpleDisplay) {
        node.style.display = "";
        node.style.zIndex = zIndex;
        return;
    }

    if (navigator.userAgent.indexOf('Netscape') != -1) {
        node.style.visibility = "visible";
        if (node.getAttribute("ownHeight")) {
            node.style.height = node.getAttribute("ownHeight");
        }
    } else {
        node.style.display = "";
    }
}

function cancelBubble(e) {
    if (typeof(e) == "undefined") {
        e = event;
    }

    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
        e.cancelBubble = true;
    }
    return false;
}

function preventDefault(e) {
    if (typeof(e) == "undefined") {
        e = event;
    }

    if (e.preventDefault) {
        e.preventDefault();
    } else {
        e.returnValue = false;
    }
    return false;
}

function cancelEvent(e) {
    if (typeof(e) == "undefined") {
        e = event;
    }

    cancelBubble(e);
    preventDefault(e);
    return false;
}

function getTarget(event) {
    return (event.srcElement ? event.srcElement : event.target);
}

function hideIframes() {
    var iframes = document.getElementsByTagName("IFRAME");
    for (var i = 0; i < iframes.length; i++) {
        hideNode(iframes[i]);
    }
}

function showIframes() {
    var iframes = document.getElementsByTagName("IFRAME");
    for (var i = 0; i < iframes.length; i++) {
        showNode(iframes[i]);
    }
}

function getNodeAttribute(node, attrName, defaultValue) {
    if (!node.getAttribute(attrName) || node.getAttribute(attrName) == "null") {
        return defaultValue;
    }
    return node.getAttribute(attrName);
}

function getNodeIntAttribute(node, attrName, defaultValue) {
    var result = numberParseInt(getNodeAttribute(node, attrName, defaultValue));
    assert(result != "NaN", "Attribute <" + attrName + "> is not a number");
    return result;
}

function getNodeBooleanAttribute(node, attrName, defaultValue) {
    var result = getNodeAttribute(node, attrName, defaultValue);
    return (result == "true");
}

function cutUnits(str) {
    if (!str || str == "null") {
        return "";
    }
    var s = str.trim();
    if (s.indexOf("px") == s.length - 2) {
        return s.slice(0, -2);
    } else if (s.indexOf("%") == s.length - 1) {
        return s.slice(0, -1);
    }

    return s;
}

// this is a workaround for FireFox: if we try to get nextSibling of some tr
// simple trNode.nextSibling returns a [Text object] instead of next tr (IE works properly)
function getNextSiblingTr(nextSib) {
    var iter = 0;
    while (nextSib.nodeName != 'TR') {
        nextSib = nextSib.nextSibling;
        iter++;
        if (iter > 5) { break; }
    }
    return nextSib;
}

function checkBrowser() {
    var brw = new Object();
    BrowserCheck(brw);
    return brw;
}

function exec(func, obj, args) {
    var str = "func.call(obj";
    for (var i = 0; i < args.length; i++) {
        str += ", args[" + i + "]";
    }
    str += ");";
    return eval(str);
}

function toggleSelectsVisibility(win, show) {
    toggleSelects(win, show);
    for (var i = 0; i < win.frames.length; i++) {
        var iframe = win.frames[i];

        iframe = iframe.contentWindow;
        if (iframe == null){
            iframe = win.frames[i];
        }

        toggleSelects(iframe, show);
        toggleSelectsVisibility(iframe, show);
    }
}

function toggleSelects(win, show) {
    var selects = win.document.getElementsByTagName("select");
    for (var j = 0; j < selects.length; j++) {
        selects[j].style.visibility = show ? 'visible' : 'hidden';
    }
}

function showSelectsInNode(node) {
    var selects = node.getElementsByTagName("select");
    for (var j = 0; j < selects.length; j++) {
        selects[j].style.visibility = 'visible';
    }
}

function freezeContent() {
    var wnd = window;
    while (!wnd.document.getElementById("split_content")) {
        wnd = wnd.parent;
    }

    wnd.blockUI();

    var doc = wnd.document;
    $("#split_content", doc).addClass("contentDisabled");
}

function unfreezeContent() {
    var wnd = window;
    while (!wnd.document.getElementById("split_content")) {
        wnd = wnd.parent;
    }

    wnd.unblockUI();

    var doc = wnd.document;
    $("#split_content", doc).removeClass("contentDisabled");
}

function debug(msg) {
    var win = window.top;
    if (!win.debugMessageTop) {
        win.debugMessageTop = 50;
        win.debugMessageLeft = 50;
    }
    var doc = window.top.document;
    var el = doc.createElement("SPAN");
    var text = doc.createTextNode(msg);
    el.appendChild(text);

    el.style.position = "absolute";
    el.style.top = win.debugMessageTop;
    el.style.left = win.debugMessageLeft;

    win.debugMessageTop += 14;
    win.debugMessageLeft += 25;

    doc.body.appendChild(el);
}

function BrowserCheck(brw) {
    brw.ua = navigator.userAgent;
    var hasCurrentStyle = (document.documentElement && document.documentElement.currentStyle);

    brw.ie = /msie/i.test(brw.ua) && hasCurrentStyle;
    brw.moz = (navigator.product ? navigator.product == "Gecko" : false);

    brw.isMac = brw.ua.indexOf('Mac') != -1;
    brw.isGecko = brw.ua.indexOf('Gecko') != -1;
    brw.isOpera = brw.ua.indexOf('Opera') != -1;
    brw.isNetscape701 = (navigator.appName == "Netscape" && navigator.vendor == "Netscape" && navigator.vendorSub == "7.01");
    brw.isNetscape7 = brw.ua.indexOf('Netscape/7') != -1;
    brw.isSafari = brw.ua.indexOf('Safari') != -1;
    brw.isChrome = brw.ua.indexOf('Chrome') != -1;

    if (brw.moz) {
        /rv\:([^\);]+)(\)|;)/.test(brw.ua);
        brw.version = RegExp.$1;
        brw.ie55 = false;
        brw.ie6 = false;
        brw.ie7 = false;
        brw.ff3 = /Firefox\/3/i.test(brw.ua);
        brw.ff2 = /Firefox\/2/i.test(brw.ua);
    }
    else if (brw.ie) {
        /MSIE([^\);]+)(\)|;)/.test(brw.ua);
        brw.version = RegExp.$1;
        brw.ie55 = /msie 5\.5/i.test(brw.ua);
        brw.ie6 = /msie 6/i.test(brw.ua);
        brw.ie7 = /msie 7/i.test(brw.ua);
        brw.ff3 = false;
    }

    if (brw.isOpera) {
        brw.ie = true;
        brw.isGecko = false;
        brw.isSafari = false;
    }

    if (brw.isChrome) {
        brw.isSafari = false;
    }
}

function getIframeWindow(iframeName){
    var iframe = document.getElementById(iframeName) ? document.getElementById(iframeName).contentWindow : null;
    return iframe ? iframe : window.frames[iframeName];
}

function TextareaKeyPress(textarea, maxChars, event) {
    var strValue = textarea.value;
    if (strValue.length >= maxChars) {
        var code = (event.which == null)? event.keyCode: event.which;
        var arrAllowedChars = new Array(8, 9, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46);
        return InArray(arrAllowedChars, event.keyCode);
    }
    return true;
}

function InArray(arr, key) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] == key) {
            return true;
        }
    }

    return false;
}

function onCutText(textarea, maxChars) {
    if (textarea.value.length >= maxChars) {
        textarea.value = textarea.value.substring(0, maxChars);
    }
}

function getClientWidth() {
	return t_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function getClientHeight() {
	return t_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function getScrollLeft() {
	return t_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function getScrollTop() {
	return t_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function t_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result < n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result < n_body)) ? n_body : n_result;
}


/*debug utils */
function debugDumpStr(obj) {
    var str = "";
    for (name in obj) {
        if (!(obj[name] != null && obj[name] instanceof Function)) {
        	if (obj[name] && obj[name]['_classObject']) {
            	str += name + " => [object " + obj[name].classObject.className + "] \n";
        	} else {
            	str += name + " => " + obj[name] + "\n";
        	}
        }
    }
    return str;
}

function debugDump(obj) {
    alert(debugDumpStr(obj));
}

function getBooleanValue(val) {
    return (val && val == true) || val == 'true';
}

function blockUI() {
    $.blockUI({ message: null, css: {border : "none"}, overlayCSS: { backgroundColor: '#ECECEC', opacity: '0.5' } });
}

function unblockUI() {
    $.unblockUI();
}


function createCookie(name,value,seconds) {
    var opts = {};
    opts.path = '/';

    if (seconds) {
        var date = new Date();
        date.setTime(date.getTime() + (seconds * 1000));
        opts.expires = date.toGMTString();
    }

    $.cookie(name, value, opts);
}

function readCookie(name) {
    return $.cookie(name);
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function saveSplitterLocation(tab,location) {
    createCookie("SPLITTERLOCATION" + tab, location);
}

function restoreSplitterLocation(tab) {
    return readCookie("SPLITTERLOCATION" + tab);
}

function getTreeDocument() {
    var win = window;
    var treeApplet = null;
    var i = 0;
    while (!treeApplet && i++ < 5) {
        treeApplet = win.document.getElementById('treeApplet');
        win = win.parent;
    }

    var treeDoc = null;

    if (treeApplet) {
        treeDoc = treeApplet.contentWindow;
    }

    return treeDoc;
}

function blockTree() {
    var treeDoc = getTreeDocument();
    if (treeDoc && treeDoc.disableTree) {
        treeDoc.disableTree();
    }
}

function unblockTree() {
    var treeDoc = getTreeDocument();
    if (treeDoc && treeDoc.enableTree) {
        treeDoc.enableTree();
    }
}



