﻿var Tant_Common = new Object();
Tant_Common._state = new Array();
Tant_Common.ConvertHsvColorToRgbColor = function(hsv) {
    var h = hsv[0];
    var s = hsv[1];
    var v = hsv[2];
    var r;
    var g;
    var b;
    if (s == 0)
        return new Array(v, v, v);
    var htemp;
    if (h == 360)
        htemp = 0;
    else
        htemp = h;
    htemp = htemp / 60;
    var i = Math.floor(htemp);
    var f = htemp - i;
    var p = v * (1 - s);
    var q = v * (1 - (s * f));
    var t = v * (1 - (s * (1 - f)));
    if (i == 0) {
        r = v;
        g = t;
        b = p;
    }
    if (i == 1) {
        r = q;
        g = v;
        b = p;
    }
    if (i == 2) {
        r = p;
        g = v;
        b = t;
    }
    if (i == 3) {
        r = p;
        g = q;
        b = v;
    }
    if (i == 4) {
        r = t;
        g = p;
        b = v;
    }
    if (i == 5) {
        r = v;
        g = p;
        b = q;
    }
    r = Math.round(r);
    g = Math.round(g);
    b = Math.round(b);
    return new Array(r, g, b);
}
Tant_Common.ConvertRgbColorToHsvColor = function(rgb) {
    var r = rgb[0];
    var g = rgb[1];
    var b = rgb[2];
    var h;
    var s;
    var v = Math.max(Math.max(r, g), b);
    var min = Math.min(Math.min(r, g), b);
    var delta = v - min;
    if (v == 0)
        s = 0
    else
        s = delta / v;
    if (s == 0)
        h = 0;
    else {
        if (r == v)
            h = 60 * (g - b) / delta;
        else if (g == v)
            h = 120 + 60 * (b - r) / delta;
        else if (b == v)
            h = 240 + 60 * (r - g) / delta;
    }
    if (h < 0)
        h += 360;
    return new Array(h, s, v);
}
Tant_Common.ConvertDecimalToHexadecimal = function(d, digits) {
    var chars = "0123456789abcdef";
    var h = '';
    var mod;
    while (d > 0) {
        mod = d % 16;
        h = chars.substr(mod, 1) + h;
        d -= mod;
        d /= 16;
    }
    if (digits) {
        while (h.length < digits) {
            h = "0" + h;
        }
    }
    return h;
}
Tant_Common.ConvertHtmlColorToRgbColor = function(html) {
    html = html.replace(/[^0-9a-f]/ig, '');
    if (html.length == 3)
        return new Array(parseInt(html.substr(0, 1) + html.substr(0, 1), 16), parseInt(html.substr(1, 1) + html.substr(1, 1), 16), parseInt(html.substr(2, 1) + html.substr(2, 1), 16));
    else if (html.length == 6)
        return new Array(parseInt(html.substr(0, 2), 16), parseInt(html.substr(2, 2), 16), parseInt(html.substr(4, 2), 16));
    else
        return new Array(255, 255, 255);
}
Tant_Common.ConvertRgbColorToHtmlColor = function(rgbColor) {
    return "#" + Tant_Common.ConvertDecimalToHexadecimal(rgbColor[0], 2) + Tant_Common.ConvertDecimalToHexadecimal(rgbColor[1], 2) + Tant_Common.ConvertDecimalToHexadecimal(rgbColor[2], 2);
}
Tant_Common.GetContrastingHtmlColorForRgbColor = function(rgb) {
    var illuminance = (rgb[0] * 2) + (rgb[1] * 5) + (rgb[2]);
    if (illuminance > 1024)
        return "#000000";
    else
        return "#ffffff";
}
Tant_Common.GetElementInfo = function(element) {
    var curleft = 0;
    var curtop = 0;
    var obj = element;
    var leftComplete = false;
    var topComplete = false;
    var isIE = Tant_Common.IsIE();
    while (obj) {
        if (!leftComplete)
            curleft += obj.offsetLeft;
        if (!topComplete)
            curtop += obj.offsetTop;
        if (isIE && obj.offsetParent && obj.offsetParent.style.position == 'relative') {
            if (!obj.offsetParent.style.width) {
                leftComplete = true;
                if ((obj.offsetParent.style.top || obj.offsetParent.style.bottom)) {
                    curtop += obj.offsetHeight;
                    topComplete = true;
                }
            }
        }
        obj = obj.offsetParent;
    }
    var elementInfo = new Object();
    elementInfo.Left = curleft;
    elementInfo.Top = curtop;
    elementInfo.Width = element.offsetWidth;
    elementInfo.Height = element.offsetHeight;
    return elementInfo;
}
Tant_Common.GetWindowInfo = function() {
    var scrollX = 0, scrollY = 0, width = 0, height = 0;
    if (typeof (window.pageXOffset) == 'number') {
        scrollX = window.pageXOffset;
        scrollY = window.pageYOffset;
    }
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        scrollX = document.body.scrollLeft;
        scrollY = document.body.scrollTop;
    }
    else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        scrollX = document.documentElement.scrollLeft;
        scrollY = document.documentElement.scrollTop;
    }
    if (typeof (window.innerWidth) == 'number') {
        width = window.innerWidth;
        height = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
    if (document.documentElement && (document.documentElement.scrollHeight || document.documentElement.offsetHeight)) {
        if (document.documentElement.scrollHeight > document.documentElement.offsetHeight) {
            contentWidth = document.documentElement.scrollWidth;
            contentHeight = document.documentElement.scrollHeight;
        }
        else {
            contentWidth = document.documentElement.offsetWidth;
            contentHeight = document.documentElement.offsetHeight;
        }
    }
    else if (document.body && (document.body.scrollHeight || document.body.offsetHeight)) {
        if (document.body.scrollHeight > document.body.offsetHeight) {
            contentWidth = document.body.scrollWidth;
            contentHeight = document.body.scrollHeight;
        }
        else {
            contentWidth = document.body.offsetWidth;
            contentHeight = document.body.offsetHeight;
        }
    }
    else {
        contentWidth = width;
        contentHeight = height;
    }
    if (height > contentHeight)
        height = contentHeight;
    if (width > contentWidth)
        width = contentWidth;
    var rect = new Object();
    rect.ScrollX = scrollX;
    rect.ScrollY = scrollY;
    rect.Width = width;
    rect.Height = height;
    rect.ContentWidth = contentWidth;
    rect.ContentHeight = contentHeight;
    return rect;
}
Tant_Common.GetCurrentStyleValue = function(element, styleRule, jsStyleRule, defaultValue) {
    var value = '';
    try {
        if (document.defaultView && document.defaultView.getComputedStyle)
            value = document.defaultView.getComputedStyle(element, "").getPropertyValue(styleRule);
        else if (element.currentStyle)
            value = element.currentStyle[jsStyleRule];
    } catch (e) { }
    if ((value == 'inherit' || value == 'transparent') && element.parentNode != null)
        return Tant_Common.GetCurrentStyleValue(element.parentNode, styleRule, jsStyleRule, defaultValue);
    else if (value != '' && value != undefined && value != 'rgba(0, 0, 0, 0)')
        return value;
    else
        return defaultValue;
}
Tant_Common.GetStyleOffset = function(element) {
    var result = new Object();
    result.Height = Tant_Common.IsNanDefault(parseInt(Tant_Common.GetCurrentStyleValue(element, 'border-top-width', 'borderTopWidth', '0')), 0) +
Tant_Common.IsNanDefault(parseInt(Tant_Common.GetCurrentStyleValue(element, 'border-bottom-width', 'borderBottomWidth', '0')), 0) +
Tant_Common.IsNanDefault(parseInt(Tant_Common.GetCurrentStyleValue(element, 'padding-top', 'paddingTop', '0')), 0) +
Tant_Common.IsNanDefault(parseInt(Tant_Common.GetCurrentStyleValue(element, 'padding-bottom', 'paddingBottom', '0')), 0);
    result.Width = Tant_Common.IsNanDefault(parseInt(Tant_Common.GetCurrentStyleValue(element, 'border-left-width', 'borderLeftWidth', '0')), 0) +
Tant_Common.IsNanDefault(parseInt(Tant_Common.GetCurrentStyleValue(element, 'border-right-width', 'borderRightWidth', '0')), 0) +
Tant_Common.IsNanDefault(parseInt(Tant_Common.GetCurrentStyleValue(element, 'padding-left', 'paddingLeft', '0')), 0) +
Tant_Common.IsNanDefault(parseInt(Tant_Common.GetCurrentStyleValue(element, 'padding-right', 'paddingRight', '0')), 0);
    return result;
}
Tant_Common.IsNanDefault = function(value, defaultValue) {
    if (isNaN(value))
        return defaultValue;
    else
        return value;
}
Tant_Common.EscapeForRegExp = function(value) {
    return value.replace(/([\\\(\^\$\*\+\?\{\}\.\)\|\-])/g, '\\$1');
}
Tant_Common.GetSelectedHtmlInElement = function(element, includeAllContentIfNoSelection, includeAllContentIfInvalidSelection, invalidSelectionMessage) {
    var selectionIsValid = true;
    var content = null;
    if (window.getSelection) {
        var selection = window.getSelection();
        if (selection && selection.rangeCount > 0 && selection.toString().length > 0) {
            selectionIsValid = false;
            var selectedRange = selection.getRangeAt(0);
            var availableRange = document.createRange();
            availableRange.selectNode(element);
            if (availableRange.compareBoundaryPoints(Range.START_TO_START, selectedRange) <= 0 && availableRange.compareBoundaryPoints(Range.END_TO_END, selectedRange) >= 0) {
                var temp = document.createElement('div');
                temp.appendChild(selectedRange.cloneContents());
                content = temp.innerHTML;
            }
            else if (invalidSelectionMessage)
                alert(invalidSelectionMessage);
        }
    }
    else if (document.selection) {
        var range = document.selection.createRange();
        if (range && range.text) {
            selectionIsValid = false;
            var parent = range.parentElement();
            if (parent != null && Tant_Common.ElementContainsElement(element, parent))
                content = range.htmlText;
            else if (invalidSelectionMessage)
                alert(invalidSelectiTant_modalonMessage);
        }
    }
    if (content == null && ((selectionIsValid && includeAllContentIfNoSelection) || includeAllContentIfInvalidSelection))
        content = element.innerHTML;
    return content;
}
Tant_Common.ElementContainsElement = function(parent, child) {
    if (!parent || !child)
        return false;
    if (parent == child)
        return true;
    if (parent && parent.childNodes) {
        for (var i = 0;
i < parent.childNodes.length;
i++) {
            if (parent.childNodes[i] == child || Tant_Common.ElementContainsElement(parent.childNodes[i], child))
                return true;
        }
    }
    return false;
}
Tant_Common.GetCurrentCursorIndex = function(inputElement) {
    var index = 0;
    if (inputElement.selectionStart || inputElement.selectionStart == '0')
        index = inputElement.selectionStart;
    else if (document.selection) {
        var originalValue = inputElement.value;
        var range = document.selection.createRange();
        var escapeChar = String.fromCharCode(1);
        range.text = escapeChar;
        index = inputElement.value.indexOf(escapeChar);
        inputElement.value = originalValue;
    }
    return index;
}
Tant_Common._delayedSetCurrentCursorSelection = function(stateId) {
    var state = Tant_Common.GetStateByStateId(stateId, 'Tant_Common_SetCurrentCursorSelection');
    if (state) {
        Tant_Common.SetCurrentCursorSelection(state.InputElement, state.StartIndex, state.EndIndex, false, state.PersistedValue);
        Tant_Common.ClearStateByStateId(stateId, 'Tant_Common_SetCurrentCursorSelection');
    }
}
Tant_Common.IsSafari = function() {
    return navigator.userAgent.indexOf('Safari') != -1;
}
Tant_Common.IsOpera = function() {
    return window.opera != null;
}
Tant_Common.IsIE = function() {
    return document.getElementsByTagName('body')[0].currentStyle != null;
}
Tant_Common.CreateSafeFunction = function(instance, func) {
    return function() {
        return func.apply(instance, arguments);
    }
}
Tant_Common.DisposeContent = function(parentElement) {
    if (parentElement && parentElement.childNodes && parentElement.childNodes.length > 0) {
        for (var i = 0;
i < parentElement.childNodes.length;
i++) {
            if (parentElement.childNodes[i].dispose) {
                try {
                    parentElement.childNodes[i].dispose();
                }
                catch (e) { }
            }
            Tant_Common.DisposeContent(parentElement.childNodes[i]);
        }
    }
}
Tant_Common.SetCurrentCursorSelection = function(inputElement, startIndex, endIndex, functionKeyWasHandled, persistedValue) {
    if (Tant_Common.IsSafari() || Tant_Common.IsOpera()) {
        if (functionKeyWasHandled) {
            var state = Tant_Common.GetStateByKey(inputElement, 'Tant_Common_SetCurrentCursorSelection');
            if (state && state.CursorTimeout)
                window.clearTimeout(state.CursorTimeout);
            state = new Object();
            state.InputElement = inputElement;
            state.StartIndex = startIndex;
            state.EndIndex = endIndex;
            state.PersistedValue = persistedValue;
            var stateId = Tant_Common.SaveStateByKey(inputElement, 'Tant_Common_SetCurrentCursorSelection', state);
            state.CursorTimeout = window.setTimeout(new Function('Tant_Common._delayedSetCurrentCursorSelection(' + stateId + ');'), 9);
            Tant_Common.SaveStateByKey(inputElement, 'Tant_Common_SetCurrentCursorSelection', state);
            return;
        }
        else {
            inputElement.focus();
            if (persistedValue)
                inputElement.value = persistedValue;
        }
    }
    try {
        if (document.selection) {
            var range = inputElement.createTextRange();
            range.move('character', startIndex);
            range.moveEnd('character', endIndex - startIndex);
            range.select();
        }
        else if (inputElement.setSelectionRange) {
            inputElement.setSelectionRange(startIndex, endIndex);
            inputElement.focus();
        }
        else if (inputElement.selectionStart || inputElement.selectionStart == '0') {
            inputElement.selectionStart = startIndex;
            inputElement.selectionEnd = endIndex;
        }
    } catch (e) { }
}
Tant_Common.GetStateByStateId = function(stateId, processId) {
    if (Tant_Common._state.length > stateId && stateId >= 0 && Tant_Common._state[stateId] && Tant_Common._state[stateId]._stateProcessId == processId)
        return Tant_Common._state[stateId]._state;
    else
        return null;
}
Tant_Common.GetStateByKey = function(key, processId) {
    for (var i = 0;
i < Tant_Common._state.length;
i++) {
        if (Tant_Common._state[i] && Tant_Common._state[i]._stateKey == key && Tant_Common._state[i]._stateProcessId == processId)
            return Tant_Common._state[i]._state;
    }
    return null;
}
Tant_Common.SaveStateByStateId = function(stateId, processId, state) {
    if (Tant_Common._state.length > stateId && stateId >= 0 && Tant_Common._state[stateId] && Tant_Common._state[stateId]._stateProcessId == processId)
        Tant_Common._state[stateId]._state = state;
}
Tant_Common.SaveStateByKey = function(key, processId, state) {
    var emptyIndex = -1;
    for (var i = 0;
i < Tant_Common._state.length;
i++) {
        if (!Tant_Common._state[i])
            emptyIndex = i;
        else if (Tant_Common._state[i]._stateKey == key && Tant_Common._state[i]._stateProcessId == processId) {
            Tant_Common._state[i]._state = state;
            return i;
        }
    }
    var stateBucket = new Object();
    stateBucket._stateKey = key;
    stateBucket._stateProcessId = processId;
    stateBucket._state = state;
    if (emptyIndex != -1) {
        Tant_Common._state[emptyIndex] = stateBucket;
        return emptyIndex;
    }
    else {
        Tant_Common._state[Tant_Common._state.length] = stateBucket;
        return Tant_Common._state.length - 1;
    }
}
Tant_Common.ClearStateByStateId = function(stateId, processId) {
    if (Tant_Common._state.length > stateId && stateId >= 0 && Tant_Common._state[stateId] && Tant_Common._state[stateId]._stateProcessId == processId)
        Tant_Common._state[stateId] = null;
}
Tant_Common._hiddenSelects = new Array();
Tant_Common._elementsHidingSelects = new Array();
Tant_Common._addHiddenSelect = function(elementHidingSelect, selectElement) {
    var hiddenSelect = null;
    var emptyIndex = -1;
    for (var i = 0;
i < Tant_Common._hiddenSelects.length && hiddenSelect == null;
i++) {
        if (Tant_Common._hiddenSelects[i]) {
            if (Tant_Common._hiddenSelects[i].SelectElement == selectElement)
                hiddenSelect = Tant_Common._hiddenSelects[i];
        }
        else
            emptyIndex = i;
    }
    if (hiddenSelect == null) {
        hiddenSelect = new Object();
        hiddenSelect.SelectElement = selectElement;
        hiddenSelect.ElementsHidingSelectsIndeces = new Array();
        hiddenSelect.OriginalVisibility = selectElement.style.visibility;
        hiddenSelect.SelectElement.style.visibility = 'hidden';
        if (emptyIndex == -1) {
            Tant_Common._hiddenSelects[Tant_Common._hiddenSelects.length] = hiddenSelect;
            hiddenSelect.Index = Tant_Common._hiddenSelects.length - 1;
        }
        else {
            Tant_Common._hiddenSelects[emptyIndex] = hiddenSelect;
            hiddenSelect.Index = emptyIndex;
        }
    }
    var ignore = false;
    for (var i = 0;
i < hiddenSelect.ElementsHidingSelectsIndeces.length && !ignore;
i++) {
        if (hiddenSelect.ElementsHidingSelectsIndeces[i] == elementHidingSelect.Index)
            ignore = true;
    }
    if (!ignore) {
        elementHidingSelect.HiddenSelectsIndeces[elementHidingSelect.HiddenSelectsIndeces.length] = hiddenSelect.Index;
        hiddenSelect.ElementsHidingSelectsIndeces[hiddenSelect.ElementsHidingSelectsIndeces.length] = elementHidingSelect.Index;
    }
}
Tant_Common._addElementHidingSelect = function(element) {
    var elementHidingSelect = null;
    var emptyIndex = -1;
    for (var i = 0;
i < Tant_Common._elementsHidingSelects.length && elementHidingSelect == null;
i++) {
        if (Tant_Common._elementsHidingSelects[i]) {
            if (Tant_Common._elementsHidingSelects[i].Element == element)
                elementHidingSelect = Tant_Common._elementsHidingSelects[i];
        }
        else
            emptyIndex = i;
    }
    if (elementHidingSelect == null) {
        elementHidingSelect = new Object();
        elementHidingSelect.Element = element;
        elementHidingSelect.HiddenSelectsIndeces = new Array();
        if (emptyIndex == -1) {
            Tant_Common._elementsHidingSelects[Tant_Common._elementsHidingSelects.length] = elementHidingSelect;
            elementHidingSelect.Index = Tant_Common._elementsHidingSelects.length - 1;
        }
        else {
            Tant_Common._elementsHidingSelects[emptyIndex] = elementHidingSelect;
            elementHidingSelect.Index = emptyIndex;
        }
    }
    return elementHidingSelect;
}
Tant_Common.HideSelectBoxes = function(element, hideAll) {
    if (element.getClientRects) {
        var selectBoxes = document.getElementsByTagName('select');
        var elementRect = element.getClientRects()[0];
        var elementHidingSelect = null;
        for (var i = 0;
i < selectBoxes.length;
i++) {
            if (selectBoxes[i].getClientRects) {
                var rects = selectBoxes[i].getClientRects();
                for (var j = 0;
j < rects.length;
j++) {
                    if (hideAll || (rects[j].top < elementRect.bottom && elementRect.top < rects[j].bottom && rects[j].left < elementRect.right && elementRect.left < rects[j].right)) {
                        var inElement = false;
                        var selectParent = selectBoxes[i].offsetParent;
                        while (selectParent != null) {
                            if (selectParent == element) {
                                inElement = true;
                                break;
                            }
                            selectParent = selectParent.offsetParent;
                        }
                        if (!inElement) {
                            if (elementHidingSelect == null)
                                elementHidingSelect = Tant_Common._addElementHidingSelect(element);
                            Tant_Common._addHiddenSelect(elementHidingSelect, selectBoxes[i]);
                            selectBoxes[i].style.visibility = 'hidden';
                        }
                        break;
                    }
                }
            }
        }
    }
}
Tant_Common.ShowSelectBoxes = function(element) {
    var elementHidingSelect = null;
    for (var i = 0;
i < Tant_Common._elementsHidingSelects.length && elementHidingSelect == null;
i++) {
        if (Tant_Common._elementsHidingSelects[i]) {
            if (Tant_Common._elementsHidingSelects[i].Element == element)
                elementHidingSelect = Tant_Common._elementsHidingSelects[i];
        }
    }
    if (elementHidingSelect == null)
        return;
    var hiddenSelect;
    for (var i = 0;
i < elementHidingSelect.HiddenSelectsIndeces.length;
i++) {
        hiddenSelect = Tant_Common._hiddenSelects[elementHidingSelect.HiddenSelectsIndeces[i]];
        if (hiddenSelect) {
            if (hiddenSelect.ElementsHidingSelectsIndeces.length == 1) {
                if (hiddenSelect.SelectElement.style.visibility == 'hidden')
                    hiddenSelect.SelectElement.style.visibility = hiddenSelect.OriginalVisibility;
                Tant_Common._hiddenSelects[hiddenSelect.Index] = null;
            }
            else {
                var elementsHidingSelects = new Array();
                for (var j = 0;
j < hiddenSelect.ElementsHidingSelectsIndeces.length;
j++) {
                    if (hiddenSelect.ElementsHidingSelectsIndeces[j] != elementHidingSelect.Index)
                        elementsHidingSelects[elementsHidingSelects.length] = hiddenSelect.ElementsHidingSelectsIndeces[i];
                }
                hiddenSelect.ElementsHidingSelectsIndeces = elementsHidingSelects;
            }
        }
    }
    Tant_Common._elementsHidingSelects[elementHidingSelect.Index] = null;
}
Tant_Modal = new Object();
Tant_Modal._variableName = 'Tant_Modal';
Tant_Modal.LoadingHtmlUrl = '\script\loading.htm';
Tant_Modal.WindowCssClasses = ['Modal'];
Tant_Modal.WindowTitleCssClasses = ['ModalTitle'];
Tant_Modal.WindowCloseCssClasses = ['ModalClose'];
Tant_Modal.WindowContentCssClasses = ['ModalContent'];
Tant_Modal.WindowMaskCssClasses = ['ModalMask'];
Tant_Modal.WindowFooterCssClasses = ['ModalFooter'];
Tant_Modal.WindowResizeCssClasses = ['ModalResize'];
Tant_Modal.ZIndex = 100;
Tant_Modal._isShown = false;
Tant_Modal._initialized = false;
Tant_Modal._modal = null;
Tant_Modal._modalTitle = null;
Tant_Modal._modalClose = null;
Tant_Modal._modalAnimationMask = null;
Tant_Modal._modalMask = null;
Tant_Modal._modalIframe = null;
Tant_Modal._modalResize = null;
Tant_Modal._modalFooter = null;
Tant_Modal._modalContent = null;
Tant_Modal._animationHandle = null;
Tant_Modal._isOpening = false;
Tant_Modal._checkForScrollResizeHandle = null;
Tant_Modal._lastModalInfo = null;
Tant_Modal._lastWindowInfo = null;
Tant_Modal._isDragging = false;
Tant_Modal._moveModalInfo = null;
Tant_Modal._resizeModalInfo = null;
Tant_Modal._isResizing = false;
Tant_Modal.Configure = function(loadingHtmlUrl, windowCssClasses, windowTitleCssClasses, windowCloseCssClasses, windowContentCssClasses, windowFooterCssClasses, windowResizeCssClasses, windowMaskCssClasses, zIndex) {
    this.LoadingHtmlUrl = loadingHtmlUrl;
    this.WindowCssClasses = windowCssClasses;
    this.WindowTitleCssClasses = windowTitleCssClasses;
    this.WindowCloseCssClasses = windowCloseCssClasses;
    this.WindowContentCssClasses = windowContentCssClasses;
    this.WindowMaskCssClasses = windowMaskCssClasses;
    this.WindowFooterCssClasses = windowFooterCssClasses;
    this.WindowResizeCssClasses = windowResizeCssClasses;
    this.ZIndex = zIndex;
}
Tant_Modal.IsShown = function() {
    return this._isShown;
}
Tant_Modal.Open = function(url, width, height, onCloseFunction, x, y, ignoreCloseAndAnimation) {
    if (!ignoreCloseAndAnimation && this._isShown)
        this.Close();
    else if (this._hiddenSelects)
        Tant_Common.ShowSelectBoxes(this._modalAnimationMask)
    if (!this._initialized)
        this._initialize();
    try {
        this._modalTitle.childNodes[1].innerHTML = this._modalIframe.contentWindow.document.title;
    }
    catch (err)
{ }
    if (!ignoreCloseAndAnimation)
        this._modalIframe.src = url;
    try {
        this._modalIframe.contentWindow.opener = window;
    }
    catch (err)
{ }
    this._modalAnimationMask.style.display = 'none';
    this._modalMask.style.display = 'none';
    this._lastWindowInfo = Tant_Common.GetWindowInfo();
    this._modalAnimationMask.style.display = 'block';
    if (width > this._lastWindowInfo.Width)
        width = this._lastWindowInfo.Width;
    this._modalAnimationMask.style.position = 'absolute';
    this._modalAnimationMask.style.zIndex = this.ZIndex;
    this._modalAnimationMask.style.display = 'block';
    this._modalAnimationMask.style.visibility = 'hidden';
    this._modalAnimationMask.style.overflow = 'hidden';
    this._modalAnimationMask.style.width = width + 'px';
    this._modalContent.style.width = width + 'px';
    this._modal.style.position = 'absolute';
    this._modal.style.display = 'block';
    this._modal.style.visibility = 'hidden';
    this._modal.style.left = '0px';
    this._modal.style.top = '0px';
    this._modalMask.style.position = 'absolute';
    this._modalMask.style.display = 'block';
    this._modalMask.style.zIndex = this.ZIndex;
    this._modalMask.style.visibility = 'visible';
    var modalContentOffset = Tant_Common.GetStyleOffset(this._modalContent);
    var offset = (this._modal.offsetHeight - this._modalContent.offsetHeight) - modalContentOffset.Height;
    if (height + offset > this._lastWindowInfo.Height)
        height = this._lastWindowInfo.Height - offset;
    if (width < this._modalResize.offsetWidth * 2)
        width = this._modalResize.offsetWidth * 2;
    if (width < this._modalClose.offsetWidth * 2)
        width = this._modalClose.offsetWidth * 2;
    if (height < this._modalTitle.offsetHeight + this._modalFooter.offsetHeight)
        height = this._modalTitle.offsetHeight + this._modalFooter.offsetHeight;
    this._modalIframe.style.height = height + 'px';
    this._modalContent.style.height = height + 'px';
    this._modalContent.style.width = (width - (this._modal.offsetWidth - this._modalContent.offsetWidth) - modalContentOffset.Width) + 'px';
    this._modalAnimationMask.style.width = width + 'px';
    this._modalAnimationMask.style.height = this._modal.offsetHeight + 'px';
    this._modalMask.style.left = '0px';
    this._modalMask.style.top = '0px';
    this._modalMask.style.width = this._lastWindowInfo.ContentWidth + 'px';
    this._modalMask.style.height = this._lastWindowInfo.ContentHeight + 'px';
    this._lastWindowInfo = Tant_Common.GetWindowInfo();
    var panelWidth = this._modal.offsetWidth;
    var panelHeight = this._modal.offsetHeight;
    var animatePropertyName, animateTargetValue, animateNextValue;
    if (typeof (x) == 'undefined' || isNaN(parseInt(x, 10)))
        x = ((this._lastWindowInfo.Width - panelWidth) / 2) + this._lastWindowInfo.ScrollX;
    if (x + panelWidth > this._lastWindowInfo.Width + this._lastWindowInfo.ScrollX)
        x = this._lastWindowInfo.Width + this._lastWindowInfo.ScrollX - panelWidth;
    if (x < this._lastWindowInfo.ScrollX)
        x = this._lastWindowInfo.ScrollX;
    if (typeof (y) == 'undefined' || isNaN(parseInt(y, 10)))
        y = ((this._lastWindowInfo.Height - panelHeight) / 2) + this._lastWindowInfo.ScrollY;
    if (y + panelHeight > this._lastWindowInfo.Height + this._lastWindowInfo.ScrollY)
        y = this._lastWindowInfo.Height + this._lastWindowInfo.ScrollY - panelHeight;
    if (y < this._lastWindowInfo.ScrollY)
        y = this._lastWindowInfo.ScrollY;
    this._modalAnimationMask.style.left = x + 'px';
    this._modalAnimationMask.style.top = y + 'px';
    animateTargetValue = 0;
    animateNextValue = -panelHeight;
    this._modal.style.visibility = 'visible';
    this._modalAnimationMask.style.visibility = 'visible';
    this._modalAnimationMask.style.overflow = 'hidden';
    Tant_Common.HideSelectBoxes(this._modalAnimationMask, true);
    this._isOpening = true;
    if (ignoreCloseAndAnimation)
        this._animationHandle = window.setTimeout(new Function(this._variableName + '._animate(0,0,0,0);'), 9);
    else {
        this._modalIframe.style.display = 'none';
        this._animate(0, -panelHeight, panelHeight / 3, .67);
    }
    this._lastModalInfo = { Url: this._modalIframe.src, OnCloseFunction: onCloseFunction, X: x, Y: y, Width: parseInt(width, 10), Height: parseInt(height, 10) };
    this._isShown = true;
}
Tant_Modal._checkForScrollResize = function() {
    if (this._checkForScrollResizeHandle)
        window.clearTimeout(this._checkForScrollResizeHandle);
    if (this._isShown && !this._isOpening && this._lastWindowInfo) {
        try {
            this._modalTitle.childNodes[1].innerHTML = this._modalIframe.contentWindow.document.title;
        }
        catch (err)
{ }
        var windowInfo = Tant_Common.GetWindowInfo();
        if (windowInfo.ScrollX != this._lastWindowInfo.ScrollX || windowInfo.ScrollY != this._lastWindowInfo.ScrollY || windowInfo.Width != this._lastWindowInfo.Width || windowInfo.Height != this._lastWindowInfo.Height)
            this.Open(null, this._lastModalInfo.Width, this._lastModalInfo.Height, this._lastModalInfo.OnCloseFunction, this._lastModalInfo.X, this._lastModalInfo.Y, true);
        else
            this._checkForScrollResizeHandle = window.setTimeout(new Function('window.' + this._variableName + '._checkForScrollResize();'), 999);
    }
}
Tant_Modal.Close = function(returnValue) {
    if (this._isShown) {
        if (!this._initialized)
            this._initialize();
        this._modal.style.position = 'absolute';
        this._modal.style.display = 'none';
        this._modalAnimationMask.style.position = 'absolute';
        this._modalAnimationMask.style.display = 'none';
        this._modalMask.style.position = 'absolute';
        this._modalMask.style.display = 'none';
        this._modalIframe.src = this.LoadingHtmlUrl;
        var onCloseFunction = this._lastModalInfo.OnCloseFunction;
        this._isShown = false;
        this._lastModalInfo = null;
        this._windowInfo = null;
        Tant_Common.ShowSelectBoxes(this._modalAnimationMask)
        if (onCloseFunction)
            onCloseFunction(returnValue);
        this.Dispose();
    }
}
Tant_Modal.Refresh = function() {
    if (this._animationHandle)
        window.clearTimeout(this._animationHandle);
    this.Dispose();
    if (this._isShown && this._lastModalInfo)
        this.Open(this._lastModalInfo.Url, this._lastModalInfo.Width, this._lastModalInfo.OnCloseFunction, this._lastModalInfo.Height, this._lastModalInfo.OnCloseFunction, this._lastModalInfo.X, this._lastModalInfo.Y);
}
Tant_Modal._initialize = function() {
    this._modalMask = document.createElement('div');
    this._modalMask.style.width = 'auto';
    this._modalMask.style.height = 'auto';
    this._modalMask.style.position = 'absolute';
    this._modalMask.style.display = 'none';
    this._modalMask.dispose = new Function('Tant_Modal.Dispose();');
    var mm = this._modalMask;
    if (this.WindowMaskCssClasses.length > 0) {
        mm.className = this.WindowMaskCssClasses[0];
        for (var i = 1;
i < this.WindowMaskCssClasses.length;
i++) {
            mm.appendChild(document.createElement('div'));
            mm = mm.childNodes[0];
            mm.className = this.WindowMaskCssClasses[i];
            mm.style.width = 'auto';
            mm.style.height = 'auto';
        }
    }
    document.body.appendChild(this._modalMask);
    this._modalAnimationMask = document.createElement('div');
    this._modalAnimationMask.style.position = 'absolute';
    this._modalAnimationMask.style.display = 'none';
    this._modalAnimationMask.style.overflow = 'hidden';
    this._modal = document.createElement('div');
    this._modal.style.width = 'auto';
    this._modal.style.height = 'auto';
    this._modal.style.position = 'absolute';
    this._modal.style.display = 'none';
    var m = this._modal;
    if (this.WindowCssClasses.length > 0) {
        m.className = this.WindowCssClasses[0];
        for (var i = 1;
i < this.WindowCssClasses.length;
i++) {
            m.appendChild(document.createElement('div'));
            m = m.childNodes[0];
            m.className = this.WindowCssClasses[i];
            m.style.width = 'auto';
            m.style.height = 'auto';
        }
    }
    this._modalTitle = document.createElement('div');
    m.appendChild(this._modalTitle);
    if (this.WindowTitleCssClasses.length > 0) {
        this._modalTitle.className = this.WindowTitleCssClasses[0];
        for (var i = 1;
i < this.WindowTitleCssClasses.length;
i++) {
            this._modalTitle.appendChild(document.createElement('div'));
            this._modalTitle = this._modalTitle.childNodes[0];
            this._modalTitle.className = this.WindowTitleCssClasses[i];
        }
    }
    this._modalTitle.onmousedown = new Function('event', 'window.' + this._variableName + '._startDrag(event);return false;');
    this._modalClose = document.createElement('div');
    this._modalTitle.appendChild(this._modalClose);
    var mc = this._modalClose;
    if (this.WindowCloseCssClasses.length > 0) {
        mc.className = this.WindowCloseCssClasses[0];
        for (var i = 1;
i < this.WindowCloseCssClasses.length;
i++) {
            mc.appendChild(document.createElement('div'));
            mc = mc.childNodes[0];
            mc.className = this.WindowCloseCssClasses[i];
        }
    }
    this._modalClose.onclick = new Function('window.' + this._variableName + '.Close();');
    this._modalTitle.appendChild(document.createElement('span'));
    var e = document.createElement('div');
    e.style.clear = 'both';
    this._modalTitle.appendChild(e);
    this._modalContent = document.createElement('div');
    m.appendChild(this._modalContent);
    if (this.WindowContentCssClasses.length > 0) {
        this._modalContent.className = this.WindowContentCssClasses[0];
        for (var i = 1;
i < this.WindowContentCssClasses.length;
i++) {
            this._modalContent.appendChild(document.createElement('div'));
            this._modalContent = this._modalContent.childNodes[0];
            this._modalContent.className = this.WindowContentCssClasses[i];
        }
    }
    this._modalIframe = document.createElement('iframe');
    this._modalIframe.src = this.LoadingHtmlUrl;
    this._modalIframe.width = '100%';
    this._modalIframe.border = '0';
    this._modalIframe.frameBorder = 'no';
    this._modalIframe.style.borderLeftWidth = '0px';
    this._modalIframe.style.borderRightWidth = '0px';
    this._modalIframe.style.borderTopWidth = '0px';
    this._modalIframe.style.borderBottomWidth = '0px';
    this._modalContent.appendChild(this._modalIframe);
    this._modalFooter = document.createElement('div');
    m.appendChild(this._modalFooter);
    var mf = this._modalFooter;
    if (this.WindowFooterCssClasses.length > 0) {
        mf.className = this.WindowFooterCssClasses[0];
        for (var i = 1;
i < this.WindowFooterCssClasses.length;
i++) {
            mf.appendChild(document.createElement('div'));
            mf = mf.childNodes[0];
            mf.className = this.WindowFooterCssClasses[i];
        }
    }
    this._modalResize = document.createElement('div');
    mf.appendChild(this._modalResize);
    var e = document.createElement('div');
    e.style.clear = 'both';
    mf.appendChild(e);
    var mr = this._modalResize;
    if (this.WindowResizeCssClasses.length > 0) {
        mr.className = this.WindowResizeCssClasses[0];
        for (var i = 1;
i < this.WindowResizeCssClasses.length;
i++) {
            mr.appendChild(document.createElement('div'));
            mr = mr.childNodes[0];
            mr.className = this.WindowResizeCssClasses[i];
        }
    }
    this._modalResize.onmousedown = new Function('event', 'window.' + this._variableName + '._startResize(event);return false;');
    this._modalAnimationMask.appendChild(this._modal);
    document.body.appendChild(this._modalAnimationMask);
    this._initialized = true;
}
Tant_Modal.Dispose = function() {
    if (this._initialized) {
        if (this._animationHandle)
            window.clearTimeout(this._animationHandle);
        this._isShown = false;
        this._isOpening = false;
        if (document && document.body) {
            document.body.removeChild(this._modalAnimationMask);
            document.body.removeChild(this._modalMask);
            this._modalClose.onclick = null;
            this._modalTitle.onmousedown = null;
            this._modalResize.onmousedown = null;
            this._modal = null;
            this._modalTitle = null;
            this._modalClose = null;
            this._modalAnimationMask = null;
            this._modalMask = null;
            this._modalIframe = null;
            this._modalResize = null;
            this._modalFooter = null;
            this._modalContent = null;
        }
        this._initialized = false;
    }
}
Tant_Modal._animate = function(targetValue, nextValue, step, acceleration) {
    if (this._animationHandle)
        window.clearTimeout(this._animationHandle);
    if (!this._isOpening)
        return;
    var currValue = parseInt(this._modal.style.top, 10);
    if ((step < 0 && currValue < targetValue) || (step > 0 && currValue > targetValue) || Math.abs(step) < 1) {
        this._modal.style.top = targetValue + 'px';
        this._modal.style.position = 'static';
        this._modalAnimationMask.style.overflow = 'visible';
        this._animationHandle = null;
        if (!this._isResizing && !this._isDragging)
            this._modalIframe.style.display = 'block';
        this._isOpening = false;
        this._lastWindowInfo = Tant_Common.GetWindowInfo();
        this._checkForScrollResizeHandle = window.setTimeout(new Function('window.' + this._variableName + '._checkForScrollResize();'), 999);
    }
    else {
        this._modal.style.top = nextValue + 'px';
        nextValue = nextValue + step;
        if (step > 0 && nextValue > targetValue)
            nextValue = targetValue;
        else if (step < 0 && nextValue < targetValue)
            nextValue = targetValue;
        step = step * acceleration;
        this._animationHandle = window.setTimeout(new Function(this._variableName + '._animate(' + targetValue + ',' + nextValue + ',' + step + ',' + acceleration + ');'), 19);
    }
}
Tant_Modal._startDrag = function(event) {
    if (!this._initialized)
        this._initialize();
    if (!event)
        event = window.event;
    this._moveModalInfo = new Object();
    this._moveModalInfo.StartMouseX = event.pageX ? event.pageX : event.screenX;
    this._moveModalInfo.StartMouseY = event.pageY ? event.pageY : event.screenY;
    this._moveModalInfo.StartModalX = this._lastModalInfo.X;
    this._moveModalInfo.StartModalY = this._lastModalInfo.Y;
    this._moveModalInfo.Button = event.button;
    document.onmouseup = new Function('event', 'window.' + this._variableName + '._endDrag(event);return false;');
    document.onmousemove = new Function('event', 'window.' + this._variableName + '._drag(event);return false;');
    this._modalIframe.style.display = 'none';
    this._isDragging = true;
}
Tant_Modal._endDrag = function(event) {
    if (!this._initialized)
        this._initialize();
    this._isDragging = false;
    this._moveModalInfo = null;
    document.onmouseup = null;
    document.onmousemove = null;
    this._modalIframe.style.display = 'block';
}
Tant_Modal._drag = function(event) {
    if (!this._initialized)
        this._initialize();
    if (!event)
        event = window.event;
    if (event.button != this._moveModalInfo.Button) {
        this._endDrag(event);
        return;
    }
    var eventX = typeof (event.pageX) != 'undefined' ? event.pageX : event.screenX;
    var eventY = typeof (event.pageY) != 'undefined' ? event.pageY : event.screenY;
    var xChange = eventX - this._moveModalInfo.StartMouseX;
    var yChange = eventY - this._moveModalInfo.StartMouseY;
    this.Open(null, this._lastModalInfo.Width, this._lastModalInfo.Height, this._lastModalInfo.OnCloseFunction, this._moveModalInfo.StartModalX + xChange, this._moveModalInfo.StartModalY + yChange, true);
}
Tant_Modal._startResize = function(event) {
    if (!this._initialized)
        this._initialize();
    if (!event)
        event = window.event;
    this._resizeModalInfo = new Object();
    this._resizeModalInfo.StartMouseX = event.pageX ? event.pageX : event.screenX;
    this._resizeModalInfo.StartMouseY = event.pageY ? event.pageY : event.screenY;
    this._resizeModalInfo.StartModalWidth = this._lastModalInfo.Width;
    this._resizeModalInfo.StartModalHeight = this._lastModalInfo.Height;
    this._resizeModalInfo.Button = event.button;
    document.onmouseup = new Function('event', 'window.' + this._variableName + '._endResize(event);return false;');
    document.onmousemove = new Function('event', 'window.' + this._variableName + '._resize(event);return false;');
    this._modalIframe.style.display = 'none';
    this._isResizing = true;
}
Tant_Modal._endResize = function(event) {
    if (!this._initialized)
        this._initialize();
    this._isResizing = false;
    this._resizeModalInfo = null;
    document.onmouseup = null;
    document.onmousemove = null;
    this._modalIframe.style.display = 'block';
}
Tant_Modal._resize = function(event) {
    if (!this._initialized)
        this._initialize();
    if (!event)
        event = window.event;
    if (event.button != this._resizeModalInfo.Button) {
        this._endResize(event);
        return;
    }
    var eventX = typeof (event.pageX) != 'undefined' ? event.pageX : event.screenX;
    var eventY = typeof (event.pageY) != 'undefined' ? event.pageY : event.screenY;
    var xChange = eventX - this._resizeModalInfo.StartMouseX;
    var yChange = eventY - this._resizeModalInfo.StartMouseY;
    this.Open(null, this._resizeModalInfo.StartModalWidth + xChange, this._resizeModalInfo.StartModalHeight + yChange, this._lastModalInfo.OnCloseFunction, this._lastModalInfo.X, this._lastModalInfo.Y, true);
}