

var __aspxInvalidDimension = -10000;
var __aspxInvalidPosition = -10000;
var __aspxAbsoluteLeftPosition = -10000;
var __aspxAbsoluteRightPosition = 10000;
var __aspxMenuZIndex = 21998;
var __aspxPopupControlZIndex = 11998;

var /* const */ __aspxCheckSizeCorrectedFlag = true;
var __aspxCallbackSeparator = ":";
var __aspxItemIndexSeparator = "i";
var __aspxCallbackResultPrefix = "/*^^^DX^^^*/";
var __aspxItemClassName = "dxi";
var __aspxAccessibilityEmptyUrl = "javascript:;";

var __aspxClassesScriptParsed = false; // [Victor] Renamed from __aspxHTMLLoaded
var __aspxDocumentLoaded = false; 

var __aspxEmptyAttributeValue = new Object();
var __aspxEmptyCachedValue = new Object();
var __aspxCachedRules = new Object();

var __aspxCultureInfo = {
    twoDigitYearMax: 2029,
    ts: ":",
    ds: "/",
    am: "AM",
    pm: "PM",
	monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ""],
	genMonthNames: null,
	abbrGenMonthNames: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ""],
	abbrDayNames: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
	dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
	numDecimalPoint: ".",
	numGroupSeparator: ",",
	currency: "$"
};
__aspxCultureInfo.genMonthNames = __aspxCultureInfo.monthNames;

function _aspxGetInvariantDateString(date) {
    if(!date)
        return "01/01/0001";
    var day = date.getDate();
    var month = date.getMonth() + 1;
    var year = date.getFullYear();
    var result = "";
    if(month < 10)
        result += "0";
    result += month.toString() + "/";
    if(day < 10)
        result += "0";
    result += day.toString() + "/" + year.toString();
    return result;
}
function _aspxGetInvariantDateTimeString(date) {
    var dateTimeString = _aspxGetInvariantDateString(date);
    
    var time = {
        h: date.getHours(),
        m: date.getMinutes(),
        s: date.getSeconds()
    };
    for(var key in time) {
        var str = time[key].toString();
        if(str.length < 2)
            str = "0" + str;
        time[key] = str;
    }
    dateTimeString += " " + time.h + ":" + time.m + ":" + time.s;
    
    var msec = date.getMilliseconds();
    if(msec > 0)
        dateTimeString += "." + msec.toString();

    return dateTimeString;
}
function _aspxExpandTwoDigitYear(value) {
    value += 1900;
    if(value + 99 < __aspxCultureInfo.twoDigitYearMax)
        value += 100;
    return value;	    
}

var ASPxKey = {
    F1           : 112,
    F2           : 113,
    F3           : 114,
    F4           : 115,
    F5           : 116,
    F6           : 117,
    F7           : 118,
    F8           : 119,
    F9           : 120,
    F10          : 121,
    F11          : 122,
    F12          : 123,
    Ctrl         : 17,
    Shift        : 16,
    Alt          : 18,
    Enter        : 13,
    Home         : 36,
    End          : 35,
    Left         : 37,
    Right        : 39,
    Up           : 38,
    Down         : 40,
    PageUp       : 33,
    PageDown     : 34,
    Esc          : 27,
    Space        : 32,
    Tab          : 9,
    Backspace    : 8,
    Delete       : 46,
    Insert       : 45,
    ContextMenu  : 93,
    Windows      : 91,
    Decimal      : 110
};

var __aspxServerForm = null;
function _aspxGetServerForm() {
    if(typeof(window.__aspxServerFormID) == "undefined")
        return null;
    if(!_aspxIsExistsElement(__aspxServerForm))
        __aspxServerForm = _aspxGetElementById(window.__aspxServerFormID);
    return __aspxServerForm;
}

function _aspxGetActiveElement() {
    try{
        return document.activeElement;
    } catch(e) {

    }
    return null;
}

// Browsers
var __aspxAgent = navigator.userAgent.toLowerCase();
var __aspxOpera = (__aspxAgent.indexOf("opera") > -1);
var __aspxOpera9 = (__aspxAgent.indexOf("opera/9") > -1 || __aspxAgent.indexOf("opera 9") > -1);
var __aspxOperaVersion = __aspxOpera ? parseFloat(__aspxAgent.slice("opera/".length)) : -1;
var __aspxOperaVersionGreaterThan95 = __aspxOperaVersion >= 9.6;
var __aspxSafariFamily = __aspxAgent.indexOf("safari") > -1;
var __aspxChrome = __aspxSafariFamily && __aspxAgent.indexOf("chrome/") > -1;
var __aspxSafari = __aspxSafariFamily && !__aspxChrome;
var __aspxSafari3 = __aspxSafari && __aspxAgent.indexOf("version/3") > -1;
var __aspxSafariVersionNonLessThan3 = __aspxSafari && Boolean(function() {
    var matches = __aspxAgent.match(new RegExp("version\\/(\\d+)\\.", "i"));
    return matches && matches.length > 1 && parseInt(matches[1]) >= 3;
}());
var __aspxSafariMacOS = __aspxSafari && __aspxAgent.indexOf("macintosh") > -1;
var __aspxIE = (__aspxAgent.indexOf("msie") > -1 && !__aspxOpera);
var __aspxIE55 = (__aspxAgent.indexOf("5.5") > -1 && __aspxIE);
var __aspxIE6 = (__aspxIE && __aspxAgent.indexOf("msie 6.") > -1);
var __aspxIE7 = (__aspxIE && __aspxAgent.indexOf("msie 7.") > -1);
var __aspxIE8 = (__aspxIE && __aspxAgent.indexOf("msie 8.") > -1);
var __aspxNotIEOperaSafari = !__aspxSafariFamily && !__aspxIE && !__aspxOpera;
var __aspxFirefox = (__aspxAgent.indexOf("firefox") > -1) && __aspxNotIEOperaSafari;
var __aspxFirefox2 = (__aspxAgent.indexOf("firefox/2.") > -1) && __aspxNotIEOperaSafari;
var __aspxFirefox3 = (__aspxAgent.indexOf("firefox/3.") > -1) && __aspxNotIEOperaSafari;
var __aspxMozilla = (__aspxAgent.indexOf("mozilla") > -1) && __aspxNotIEOperaSafari;
var __aspxNetscape = (__aspxAgent.indexOf("netscape") > -1) && __aspxNotIEOperaSafari;
var __aspxNS = __aspxFirefox  || __aspxMozilla || __aspxNetscape;
// Array
function _aspxArrayPush(array, element){
    if(_aspxIsExists(array.push))
        array.push(element);
    else     
        array[array.length] = element;
}
function _aspxArrayInsert(array, element, position){
    if(0 <= position && position < array.length){
        for(var i = array.length; i > position; i --)
            array[i] = array[i - 1];
        array[position] = element;
    }
    else
        _aspxArrayPush(array, element);
}

function _aspxArrayRemove(array, element){
    var index = _aspxArrayIndexOf(array, element);
    if(index > -1) _aspxArrayRemoveAt(array, index);
}
function _aspxArrayRemoveAt(array, index){
    if(index >= 0  && index < array.length){
        for(var i = index; i < array.length - 1; i++)
            array[i] = array[i + 1];
        array.pop();
    }
}
function _aspxArrayClear(array){
    while(array.length > 0)
        array.pop();
}
function _aspxArrayIndexOf(array, element){
    for(var i = 0; i < array.length; i++){
        if(array[i] == element)
            return i;
    } 
    return -1;
}

function _aspxCreateHashTableFromArray(array) {
    var hash = [];
    for(var i = 0; i < array.length; i++)
        hash[array[i]] = 1;
    return hash;
}
function _aspxCreateIndexHashTableFromArray(array) {
    var hash = [];
    for(var i = 0; i < array.length; i++)
        hash[array[i]] = i;
    return hash;
}

var __aspxDefaultBinarySearchComparer = function(arrayElement, value) {
    if(arrayElement == value)
        return 0;
    else
        return arrayElement < value ? -1 : 1;
};
function _aspxArrayBinarySearch(array, value, binarySearchComparer, startIndex, length) {
    if(!_aspxIsExists(binarySearchComparer))
        binarySearchComparer = __aspxDefaultBinarySearchComparer;
    if(!_aspxIsExists(startIndex))
        startIndex = 0;
    if(!_aspxIsExists(length))
        length = array.length - startIndex;        
    var endIndex = (startIndex + length) - 1;
    while (startIndex <= endIndex) {
        var middle =  (startIndex + ((endIndex - startIndex) >> 1));
        var compareResult = binarySearchComparer(array[middle], value);
        if (compareResult == 0)
            return middle;
        if (compareResult < 0)
            startIndex = middle + 1;
        else
            endIndex = middle - 1;
    }
    return -(startIndex + 1);
}
function _aspxApplyReplacement(text, replecementTable) {
    for(var i = 0; i < replecementTable.length; i++) {
        var replacement = replecementTable[i];
        text = text.replace(replacement[0], replacement[1]);
    }
    return text;
}
function _aspxEncodeHtml(html) {
    return _aspxApplyReplacement(html, [
        [ /&quot;/g, '&quotx;' ], [ /"/g, '&quot;' ],
        [ /&amp;/g,  '&ampx;'  ], [ /&/g, '&amp;'  ],
        [ /&lt;/g,   '&ltx;'   ], [ /</g, '&lt;'   ],
        [ /&gt;/g,   '&gtx;'   ], [ />/g, '&gt;'   ]
    ]);
}
function _aspxDecodeHtml(html) {
    return _aspxApplyReplacement(html, [
        [ /&gt;/g,   '>' ], [ /&gtx;/g,  '&gt;'   ],
        [ /&lt;/g,   '<' ], [ /&ltx;/g,  '&lt;'   ],
        [ /&amp;/g,  '&' ], [ /&ampx;/g, '&amp;'  ],
        [ /&quot;/g, '"' ], [ /&quotx;/g,'&quot;' ]
    ]);
}
// ** Keyboard support utils **
// for ex. CTRL+SHIFT+Z
function _aspxParseShortcutString(shortcutString) {
    if(!_aspxIsExists(shortcutString))
        return 0;

    var isCtrlKey = false;
    var isShiftKey = false;
    var isAltKey = false;
    var keyCode = null;
    
    var shcKeys = shortcutString.toString().split("+");
    
    if (shcKeys.length > 0) {
        for (var i = 0; i < shcKeys.length; i++) {
            var key = _aspxTrim(shcKeys[i].toUpperCase());
            switch (key) {
                case "CTRL":
                    isCtrlKey = true;
                    break;
                case "SHIFT":
                    isShiftKey = true;
                    break;
                case "ALT":
                    isAltKey = true;
                    break;

                case "F1":    keyCode = ASPxKey.F1; break;
                case "F2":    keyCode = ASPxKey.F2; break;
                case "F3":    keyCode = ASPxKey.F3; break;
                case "F4":    keyCode = ASPxKey.F4; break;
                case "F5":    keyCode = ASPxKey.F5; break;
                case "F6":    keyCode = ASPxKey.F6; break;
                case "F7":    keyCode = ASPxKey.F7; break;
                case "F8":    keyCode = ASPxKey.F8; break;
                case "F9":    keyCode = ASPxKey.F9; break;
                case "F10":   keyCode = ASPxKey.F10; break;
                case "F11":   keyCode = ASPxKey.F11; break;
                case "F12":   keyCode = ASPxKey.F12; break;

                case "ENTER": keyCode = ASPxKey.Enter; break;
                case "HOME":  keyCode = ASPxKey.Home; break;
                case "END":   keyCode = ASPxKey.End; break;
                case "LEFT":  keyCode = ASPxKey.Left; break;
                case "RIGHT": keyCode = ASPxKey.Right; break;
                case "UP":    keyCode = ASPxKey.Up; break;
                case "DOWN":  keyCode = ASPxKey.Down; break;
                case "PAGEUP": keyCode = ASPxKey.PageUp; break;
                case "PAGEDOWN": keyCode = ASPxKey.PageDown; break;
                case "SPACE": keyCode = ASPxKey.Space; break;
                case "TAB":   keyCode = ASPxKey.Tab; break;
                case "BACK":  keyCode = ASPxKey.Backspace; break;
                case "CONTEXT": keyCode = ASPxKey.ContextMenu; break;

                case "ESCAPE":
                case "ESC":
                    keyCode = ASPxKey.Esc;
                    break;

                case "DELETE":
                case "DEL":
                    keyCode = ASPxKey.Delete;
                    break;

                case "INSERT":
                case "INS":
                    keyCode = ASPxKey.Insert;
                    break;

                case "PLUS":
                    keyCode = "+".charCodeAt(0);
                    break;
                default:
                    keyCode = key.charCodeAt(0);
                    break;
            }
        }
    } else
        alert("Invalid shortcut");
    return _aspxGetShortcutCode(keyCode, isCtrlKey, isShiftKey, isAltKey);
}
function _aspxGetShortcutCode(keyCode, isCtrlKey, isShiftKey, isAltKey) {
    var value = keyCode & 0xFFFF;
    var flags = 0;
    flags |= isCtrlKey ? 1 << 0 : 0;
    flags |= isShiftKey ? 1 << 2 : 0;
    flags |= isAltKey ? 1 << 4 : 0;
    value |= flags << 16;
    return value;
}
function _aspxGetShortcutCodeByEvent(evt) {
    return _aspxGetShortcutCode(_aspxGetKeyCode(evt), evt.ctrlKey, evt.shiftKey, evt.altKey);
}
var ASPxImageUtils = {
    IsAlphaFilterNeed: function(src){
        // B136174 (IE8)
        return (__aspxIE55 || __aspxIE6) && this.IsPng(src);
    },
    IsPng: function(src){
        return src.slice(-3).toLowerCase() == "png";
    },
    GetImageFilterStyle: function(src){
        return "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + src + ", sizingMethod=scale)";
    },
    GetImageSrc: function (image){
        if(_aspxIsAlphaFilterUsed(image)){ // TODO move _aspxIsAlphaFilterUsed  to ASPxImageUtils
            var filter = image.style.filter;
            var regSrc = new RegExp("src=", "g");
            var regPng = new RegExp(".png", "g");
            var beginIndex = regSrc.exec(filter).lastIndex;
            var endIndex = regPng.exec(filter).lastIndex;
            return filter.substring(beginIndex, endIndex);
        } 
        return image.src;
    },
    SetImageSrc: function(image, src){
        var isAlphaFilterNeed = this.IsAlphaFilterNeed(src);
        if(isAlphaFilterNeed){
            image.src = __aspxEmptyImageUrl;
            image.style.filter = this.GetImageFilterStyle(src);
        } else {
            image.src = src;
            image.style.filter = "";
        }
    },
    SetSize: function(image, width, height){
        image.style.width = width + "px";
        image.style.height = height + "px";
    },
    GetSize: function(image, isWidth){
        return (isWidth ? image.offsetWidth : image.offsetHeight);
    }
};

function _aspxAddAlphaImageLoaderTarget(id, imageUrl) {
    if(!window._aspxAlphaImageLoaderTargets)
        window._aspxAlphaImageLoaderTargets = [];
    window._aspxAlphaImageLoaderTargets.push({ elementId: id, bgImageUrl: imageUrl });
}
function _aspxEnsureAlphaImageLoaderApplierRegistered() {
    if(!window._aspxPostponedAlphaImageLoaderApplierAdded) {
        var handler = function() {
            if(window._aspxAlphaImageLoaderTargets) {
                for(var i = 0; i < window._aspxAlphaImageLoaderTargets.length; i++) {
                    var target = window._aspxAlphaImageLoaderTargets[i];
                    _aspxApplyAlphaImageLoaderToBackground(target.elementId, target.bgImageUrl);
                }
                window._aspxAlphaImageLoaderTargets = [];
            }
        };
        if(typeof(aspxGetControlCollection) == "function")
            aspxGetControlCollection().ControlsInitialized.AddHandler(handler);
        else
            window.attachEvent("onload", handler);
        window._aspxPostponedAlphaImageLoaderApplierAdded = true;
    }
}
function _aspxApplyAlphaImageLoaderToBackground(elementId, bgImageUrl) {
    var element = document.all[elementId];
    if(element && element.length)
        element = document.getElementById(elementId);
    element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + bgImageUrl + ", sizingMethod=crop)";
}
function _aspxApplyAlphaImageLoaderToImage(image) {
    if(image.alphaImageLoaderApplied)
        return;

    if(window.__aspxEmptyImageUrl) {
        image.alphaImageLoaderApplied = true;
        var imageUrl = image.src;
        image.src = window.__aspxEmptyImageUrl;
        image.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + imageUrl + ", sizingMethod=scale)";
    } else {
        var token = window.setInterval(function() {
            if(window.__aspxEmptyImageUrl) {
                _aspxApplyAlphaImageLoaderToImage(image);
                window.clearInterval(token);
            }
        }, 100);
    }
}
function _aspxGetVerticalOverflow(element) {
    if(__aspxIE || __aspxSafariVersionNonLessThan3 || __aspxChrome)
        return element.style.overflowY;
    return element.style.overflow;
}
function _aspxSetVerticalOverflow(element, value) {
    if(__aspxIE || __aspxSafariVersionNonLessThan3 || __aspxChrome)
        element.style.overflowY = value;
    else
        element.style.overflow = value;
}

// StringBuilder
ASPxStringBuilder = _aspxCreateClass(null, {
    constructor: function(str) {
        this.Initialize();
        if (str != null)
            this.Append(str);
    },
    Append: function(str) {
        this.value = null;
        this.length += (this.parts[this.partsCount++] = String(str)).length;
        return this;
    },
    Clear: function() {
        this.Initialize();
    },
    Initialize: function() {
        this.parts = [ ];
        this.partsCount = 0;
        this.length = 0;
        this.value = null;
    },
    ToString: function() {
        if (this.value != null)
            return this.value;
        var aggregate = this.parts.join('');
        this.partsCount = (this.parts = [ aggregate ]).length;
        this.length = aggregate.length;
        return (this.value = aggregate);
    }
});
// Timer
function _aspxSetTimeout(callString, timeout){
    return window.setTimeout(callString, timeout);
}
function _aspxClearTimer(timerID){
    if(timerID > -1)
        window.clearTimeout(timerID);
    return -1;
}
// Interval
function _aspxSetInterval(callString, interval){
    return window.setInterval(callString, interval);
}
function _aspxClearInterval(timerID){
    if(timerID > -1)
        window.clearInterval(timerID);
    return -1;
}
// Utils

// [Victor] Simple innerHTML property assignation doesn't affect the node
// inner HTML in IE when the insertable markup begins with the SCRIPT tag
// (or any other "special processing"-tags like STYLE or LINK
function _aspxSetInnerHtml(element, html) {
    if(__aspxIE) {
        element.innerHTML = "<em>&nbsp;</em>" + html;
        element.removeChild(element.firstChild);
    } else
        element.innerHTML = html;
}
function _aspxGetInnerText(container) {
    if (__aspxMozilla)
        return container.textContent;
    else if (__aspxSafariFamily) {
        var filter = _aspxGetHtml2PlainTextFilter();
        filter.innerHTML = container.innerHTML;
        _aspxSetElementDisplay(filter, true);
        var innerText = filter.innerText;
        _aspxSetElementDisplay(filter, false);
        return innerText;
    } else
        return container.innerText;
}
var __aspxHtml2PlainTextFilter = null;
function _aspxGetHtml2PlainTextFilter() {
    if (__aspxHtml2PlainTextFilter == null) {
        __aspxHtml2PlainTextFilter = document.createElement("DIV");
        __aspxHtml2PlainTextFilter.style.width = "0";
        __aspxHtml2PlainTextFilter.style.height = "0";
        _aspxSetElementDisplay(__aspxHtml2PlainTextFilter, false);
        document.body.appendChild(__aspxHtml2PlainTextFilter);
    }
    return __aspxHtml2PlainTextFilter;
}
function _aspxCreateHiddenField(name, id) {
    var input = document.createElement("INPUT");
    input.setAttribute("type", "hidden");
    if(_aspxIsExists(name))
        input.setAttribute("name", name);
    if(_aspxIsExists(id))
        input.setAttribute("id", id);
    return input;
}
function _aspxCloneObject(srcObject) {
  if(typeof(srcObject) != 'object' || srcObject == null)
    return srcObject;
  var newObject = new Object();
  for(var i in srcObject) 
    newObject[i] = srcObject[i];
  return newObject;
}
function _aspxIsExistsType(type){
    return type != "undefined";
}
function _aspxIsExists(obj){
    return (typeof(obj) != "undefined") && (obj != null);
}
function _aspxIsFunction(obj){
    return typeof(obj) == "function";
}
function _aspxGetDefinedValue(value, defaultValue){
    return (typeof(value) != "undefined") ? value : defaultValue;
}
function _aspxGetKeyCode(srcEvt) {
    return __aspxNS ? srcEvt.which : srcEvt.keyCode;
}
function _aspxSetInputSelection(input, startPos, endPos){
    startPos = _aspxGetDefinedValue(startPos, 0);
    endPos = _aspxGetDefinedValue(endPos, input.value.length);
    if (__aspxIE) {
        var range = input.createTextRange();
        range.collapse(true);
        range.moveStart("character", startPos);
        range.moveEnd("character", endPos - startPos);
        range.select();
    } else
        input.setSelectionRange(startPos, endPos);
}
function _aspxGetSelectionInfo(input) {
    var start, end;
    if(__aspxIE){
        var range = document.selection.createRange();
        var rangeCopy = range.duplicate();
        range.move('character', -input.value.length);
        range.setEndPoint('EndToStart', rangeCopy);
        start = range.text.length;
        end = start + rangeCopy.text.length;
    } else {
        start = input.selectionStart;
        end = input.selectionEnd;
    }
    return { startPos: start, endPos: end };
}
function  _aspxHasInputSelection(input){
    var selectionInfo = _aspxGetSelectionInfo(input);
    return selectionInfo.startPos == selectionInfo.endPos;
}

function _aspxPreventElementDragAndSelect(element, isSkipMouseMove){
    if(__aspxSafariFamily)
        _aspxAttachEventToElement(element, "selectstart", _aspxPreventEventAndBubble);
    if(__aspxIE){
        _aspxAttachEventToElement(element, "selectstart", new function(){ return false;});
        if(!isSkipMouseMove)
            _aspxAttachEventToElement(element, "mousemove", _aspxClearSelectionOnMouseMove);
        _aspxAttachEventToElement(element, "dragstart", _aspxPreventDragStart);
    }
}
function _aspxSetElementAsUnselectable(element, isWithChild) {
    if (_aspxIsExists(element) && (element.nodeType == 1)) {
        element.unselectable = "on";
        if (__aspxNS)
            element.onmousedown = new function() { return false; };
        if(isWithChild === true){
            for(var j = 0; j < element.childNodes.length; j ++)
                _aspxSetElementAsUnselectable(element.childNodes[j]);
        }
    }
}
function _aspxClearSelection() {
    try{
        if (_aspxIsExists(window.getSelection)) {
            if (__aspxSafariFamily)
                window.getSelection().collapse();
            else
                window.getSelection().removeAllRanges();
        }
        else if (_aspxIsExists(document.selection)) {
            if(_aspxIsExists(document.selection.empty))
                document.selection.empty();
            else if(_aspxIsExists(document.selection.clear))
                document.selection.clear();
        }
    } catch(e) {

    }
}
function _aspxClearSelectionOnMouseMove(evt) {
    if (!__aspxIE || (evt.button != 0)) 
        _aspxClearSelection();
}
function _aspxPreventDragStart(evt) {
    evt = _aspxGetEvent(evt);
    var element = _aspxGetEventSource(evt);
    element.releaseCapture(); 
    return false;
}

function _aspxGetElementById(id) {
    if(_aspxIsExists(document.getElementById))
        return document.getElementById(id);
    else
        return document.all[id];
}
function _aspxGetInputElementById(id) {
    var elem = _aspxGetElementById(id);
    if(!__aspxIE)
        return elem;

    if(_aspxIsExists(elem)) {
        if(elem.id == id)
            return elem;
        else {
            for(var i = 1; i < document.all[id].length; i++) {
                if(document.all[id][i].id == id)
                    return document.all[id][i];
            }
        }
    }
    return null;
}
function _aspxGetElementByIdInDocument(documentObj, id) {
    if(_aspxIsExists(documentObj.getElementById))
        return documentObj.getElementById(id);
    else
        return documentObj.all[id];
}
function _aspxGetIsParent(parentElement, element) {
    while(element != null){
        if(element.tagName == "BODY")
            return false;
        if(element == parentElement)
            return true;
        element = element.parentNode;
    }
    return false;
}
function _aspxGetParentById(element, id) {
    element = element.parentNode;
    while(element != null){
        if(element.id == id)
            return element;
        element = element.parentNode;
    }
    return null;
}
function _aspxGetParentByTagName(element, tagName) {
    tagName = tagName.toUpperCase();
    while(element != null) {
        if(element.tagName == "BODY")
            return null;
        if(element.tagName == tagName)
            return element;
        element = element.parentNode;
    }
    return null;
}
function _aspxGetParentByClassName(element, className) {
    while(element != null) {
        if(element.tagName == "BODY")
            return null;
        if(element.className.indexOf(className) != -1)
            return element;
        element = element.parentNode;
    }
    return null;
}
function _aspxGetParentByTagNameAndAttributeValue(element, tagName, attrName, attrValue) {
    tagName = tagName.toUpperCase();
    while(element != null) {
        if(element.tagName == "BODY")
            return null;
        if(element.tagName == tagName && _aspxIsExists(element[attrName]) && element[attrName] == attrValue)
            return element;
        element = element.parentNode;
    }
    return null;
}
function _aspxGetChildById(element, id) {
    if(!__aspxIE)
        return _aspxGetElementById(id);
    else{
        var element = element.all[id];
        if(!_aspxIsExists(element))
            return null;
        else if(!_aspxIsExists(element.length)) // fix two element with the same name and id
            return element;
        else
            return _aspxGetElementById(id);
    }
}
function _aspxGetElementsByTagName(element, tagName) {
    tagName = tagName.toUpperCase();
    if(element != null){        
        if (_aspxIsExists(element.all) && !__aspxFirefox3)
            return __aspxNetscape ? element.all.tags[tagName] : element.all.tags(tagName);
        else
            return element.getElementsByTagName(tagName);
    }
    return null;
}
function _aspxGetChildByTagName(element, tagName, index) {
    if(element != null){                
        var collection = _aspxGetElementsByTagName(element, tagName);
        if(collection != null){
            if(index < collection.length)
                return collection[index];
        }
    }
    return null;
}
function _aspxGetChildTextNode(element, index) {
    if(element != null){
        var collection = new Array();
        _aspxGetChildTextNodeCollection(element, collection);
        if(index < collection.length)
            return collection[index];
    }
    return null;
}
function _aspxGetChildTextNodeCollection(element, collection) {
    for(var i = 0; i < element.childNodes.length; i ++){
        var childNode = element.childNodes[i];
        if(_aspxIsExists(childNode.nodeValue))
            _aspxArrayPush(collection, childNode);
        _aspxGetChildTextNodeCollection(childNode, collection);
    }
}
function _aspxGetChildsByClassName(element, className) {
    var collection = _aspxIsExists(element.all) ? element.all : element.getElementsByTagName('*');
    
    var ret = new Array();
    if(collection != null) {
        for(var i = 0; i < collection.length; i ++) {
            if (collection[i].className.indexOf(className) != -1)
                ret.push(collection[i]);
        }
    }
    return ret;
}
function _aspxGetParentByPartialId(element, idPart){
    while(element != null){
        if(_aspxIsExists(element.id)) {
            if(element.id.indexOf(idPart) > -1) return element;
        }
        element = element.parentNode;
    }
    return null;
}
function _aspxGetElementsByPartialId(element, partialName, list) {
    if(!_aspxIsExists(element.id)) return;
    if(element.id.indexOf(partialName) > -1) {
        list.push(element);
    }
    for(var i = 0; i < element.childNodes.length; i ++) {
        _aspxGetElementsByPartialId(element.childNodes[i], partialName, list);
    }
}
function _aspxIFrameWindow(name) {
    if(__aspxIE)
        return window.frames[name].window;
    else{
        var frameElement = document.getElementById(name);
        return (frameElement != null) ? frameElement.contentWindow : null;
    }
}
function _aspxIFrameDocument(name) {
    if(__aspxIE)
        return window.frames[name].document;
    else{
        var frameElement = document.getElementById(name);
        return (frameElement != null) ? frameElement.contentDocument : null;
    }
}
function _aspxIFrameDocumentBody(name) {
    var doc = _aspxIFrameDocument(name);
    return (doc != null) ? doc.body : null;
}
function _aspxIFrameElement(name) {
    if(__aspxIE)
        return window.frames[name].window.frameElement;
    else
        return document.getElementById(name);
}

function _aspxRemoveElement(element) {
    if(_aspxIsExists(element)) {    
        var parent = element.parentNode;
        if(_aspxIsExists(parent))
            parent.removeChild(element);
    }
    element = null;
}
function _aspxReplaceTagName(element, newTagName) {
    if (__aspxIE) {
        element.insertAdjacentHTML( 'beforeBegin', "<" + newTagName + ">" + element.innerHTML + "</" + newTagName + ">" ) ;
        _aspxRemoveElement(element);
    } else {
        var docFragment = element.ownerDocument.createDocumentFragment();
        var newElem = element.ownerDocument.createElement(newTagName);
        docFragment.appendChild(newElem);
        for (var i = 0; i < element.childNodes.length; i++)
            newElem.appendChild(element.childNodes[i].cloneNode(true));
        element.parentNode.replaceChild(docFragment, element);
    }
}
function _aspxRemoveOuterTags(element) {
    if (__aspxIE) {
        element.insertAdjacentHTML( 'beforeBegin', element.innerHTML ) ;
        _aspxRemoveElement(element);
    } else {
        var docFragment = element.ownerDocument.createDocumentFragment();
        for (var i = 0; i < element.childNodes.length; i++)
            docFragment.appendChild(element.childNodes[i].cloneNode(true));
        element.parentNode.replaceChild(docFragment, element);
    }
}
function _aspxWrapElementInNewElement(element, newElementTagName) {    
    var wrapElement = null;
    if (__aspxIE) {
        var wrapElement = element.ownerDocument.createElement(newElementTagName);
        wrapElement.appendChild(element.cloneNode(true));
        element.parentNode.insertBefore(wrapElement, element);
        element.parentNode.removeChild(element);
    } else {
        var docFragment = element.ownerDocument.createDocumentFragment();
        wrapElement = element.ownerDocument.createElement(newElementTagName);
        docFragment.appendChild(wrapElement);
        wrapElement.appendChild(element.cloneNode(true));
        element.parentNode.replaceChild(docFragment, element);
    }
    return wrapElement;
}

function _aspxGetEvent(evt){
    return (typeof(event) != "undefined" && event != null) ? event : evt; 
}
function _aspxPreventEvent(evt){
    if (__aspxNS)
        evt.preventDefault();
    else
        evt.returnValue = false;
    return false;
}
function _aspxPreventEventAndBubble(evt){
    _aspxPreventEvent(evt);
    if (__aspxNS)
        evt.stopPropagation();
    evt.cancelBubble = true;
    return false;
}
function _aspxCancelBubble(evt){
    evt.cancelBubble = true;
    return false;
}

function _aspxGetEventSource(evt){
    evt = _aspxGetEvent(evt);
    if(!_aspxIsExists(evt)) return null; 
    return __aspxIE ? evt.srcElement : evt.target;
}
function _aspxGetEventX(evt){
    return evt.clientX  - _aspxGetIEDocumentClientOffsetInternal(true) + ((__aspxSafari && !__aspxSafariVersionNonLessThan3) ? 0 : _aspxGetDocumentScrollLeft());
}
function _aspxGetEventY(evt){
    return evt.clientY - _aspxGetIEDocumentClientOffsetInternal(false) + ((__aspxSafari && !__aspxSafariVersionNonLessThan3) ? 0 : _aspxGetDocumentScrollTop());
}
function _aspxGetIEDocumentClientOffset(IsX){
    return 0;
}
function _aspxGetIEDocumentClientOffsetInternal(IsX){
    var clientOffset = 0;
    if(__aspxIE){
        if(_aspxIsExists(document.documentElement))
            clientOffset = IsX ? document.documentElement.clientLeft : document.documentElement.clientTop;
        if(clientOffset == 0 && _aspxIsExists(document.body))
            var clientOffset = IsX ? document.body.clientLeft : document.body.clientTop;
    }
    return clientOffset;
}
function _aspxGetIsLeftButtonPressed(evt){
    evt = _aspxGetEvent(evt);
    if(!_aspxIsExists(evt)) return false;
    if(__aspxIE)
        return evt.button == 1;
    else if(__aspxNS || __aspxSafariFamily)
        return evt.which == 1;
    else if (__aspxOpera)
        return evt.button == 0;        
    return true;        
}
function _aspxGetWheelDelta(evt){
    var ret = __aspxNS ? -evt.detail : evt.wheelDelta;
    if (__aspxOpera && !__aspxOpera9)
        ret = -ret;
    return ret;
}

function _aspxDelCookie(name){
    _aspxSetCookieInternal(name, "", new Date(1970, 1, 1));
}
function _aspxGetCookie(name) {
    name = escape(name);
    var cookies = document.cookie.split(';');
    for(var i = 0; i < cookies.length; i++) {
        var cookie = _aspxTrim(cookies[i]);
        if(cookie.indexOf(name + "=") == 0)
            return unescape(cookie.substring(name.length + 1, cookie.length));
        else if(cookie.indexOf(name + ";") == 0 || cookie === name)
            return "";
    }
    return null;
}
function _aspxSetCookie(name, value, expirationDate){
    if(!_aspxIsExists(value)) {
        _aspxDelCookie(name);
        return;
    }

    if(!ASPxIdent.IsDate(expirationDate)) {
        expirationDate = new Date();
        expirationDate.setFullYear(expirationDate.getFullYear() + 1);
    }
    _aspxSetCookieInternal(name, value, expirationDate);
}
function _aspxSetCookieInternal(name, value, date){
    document.cookie = escape(name) + "=" + escape(value.toString()) + "; expires=" + date.toGMTString() + "; path=/";
}

function _aspxGetElementDisplay(element){
    return element.style.display != "none";
}
function _aspxSetElementDisplay(element, value){
    element.style.display = value ? "" : "none";
}
function _aspxGetElementVisibility(element){
    return element.style.visibility != "hidden";
}
function _aspxSetElementVisibility(element, value){
    element.style.visibility = value ? "" : "hidden";
}
function _aspxAddStyleSheetLinkToDocument(doc, linkUrl) {
    var newLink = _aspxCreateStyleLink(doc, linkUrl);
    var head = _aspxGetHeadElementOrCreateIfNotExist(doc);
    head.appendChild(newLink);
}
function _aspxGetHeadElementOrCreateIfNotExist(doc) {
    var elements = _aspxGetElementsByTagName(doc, "head");
    var head = null;
    // The Head element might not exist in the Safari browser, if the document content 
    // was created via the document.write() method. In this situation, we must create it.
    if (elements.length == 0) {
        head = doc.createElement("head");
        head.visibility = "hidden";
        doc.insertBefore(head, doc.body);
    } else
        head = elements[0];
    return head;
}
function _aspxCreateStyleLink(doc, url) {
    var newLink = doc.createElement("link");
    _aspxSetAttribute(newLink, "href", url);
    _aspxSetAttribute(newLink, "type", "text/css");
    _aspxSetAttribute(newLink, "rel", "stylesheet");
    return newLink;
}
function _aspxGetCurrentStyle(element){
    if (__aspxIE)
        return element.currentStyle;
    else if (__aspxOpera && !__aspxOpera9)
        return window.getComputedStyle(element, null);
    else
        return document.defaultView.getComputedStyle(element, null);
}
function _aspxIsElementRigthToLeft(element) {
    var style = _aspxGetCurrentStyle(element);
    if (__aspxIE)
        style.writingMode.toUpperCase().indexOf("RL") > -1;
    return style.direction.toUpperCase().indexOf("RTL") > -1;
}
function _aspxCreateStyleSheetInDocument(doc) {
    if(__aspxIE)
        return doc.createStyleSheet();
    else {
        var styleSheet = doc.createElement("STYLE");
        _aspxGetChildByTagName(doc, "HEAD", 0).appendChild(styleSheet);
        return doc.styleSheets[doc.styleSheets.length - 1];
    }
}
function _aspxCreateStyleSheet(){
    return _aspxCreateStyleSheetInDocument(document);
}
function _aspxGetStyleSheetRules(styleSheet){
    try {
        return __aspxIE ? styleSheet.rules : styleSheet.cssRules;
    }
    catch(e) {
        return null;
    }
}

function _aspxGetStyleSheetRule(className){
    if(_aspxIsExists(__aspxCachedRules[className])){
        if(__aspxCachedRules[className] != __aspxEmptyCachedValue)
            return __aspxCachedRules[className];
        return null;
    }
    for(var i = 0; i < document.styleSheets.length; i ++){
        var styleSheet = document.styleSheets[i];
        var rules = _aspxGetStyleSheetRules(styleSheet);
        if(rules != null){
            for(var j = 0; j < rules.length; j ++){
                if(rules[j].selectorText == "." + className){
                    __aspxCachedRules[className] = rules[j];
                    return rules[j];
                }
            }
        }
    }
    __aspxCachedRules[className] = __aspxEmptyCachedValue;
    return null;
}

function _aspxRemoveStyleSheetRule(styleSheet, index){
    var rules = _aspxGetStyleSheetRules(styleSheet);
    if(rules != null && rules.length > 0 && rules.length >= index){
        if(__aspxIE)
            styleSheet.removeRule(index);
        else            
            styleSheet.deleteRule(index);     
    }                
}

function _aspxAddStyleSheetRule(styleSheet, selector, cssText){
    if(!_aspxIsExists(cssText) || cssText == "") return;
    if(__aspxIE)
        styleSheet.addRule(selector, cssText);
    else
        styleSheet.insertRule(selector + " { " + cssText + " }", styleSheet.cssRules.length);
}
function _aspxGetPointerCursor() {
    return __aspxIE ? "hand" : "pointer";
}
function _aspxSetPointerCursor(element) {
    if(element.style.cursor == "")
        element.style.cursor = _aspxGetPointerCursor();
}

var _aspxWebKit3TDRealInfo = {
    GetOffsetTop: function(tdElement){
        switch(_aspxGetCurrentStyle(tdElement).verticalAlign){
            case "middle":
                return Math.round(tdElement.offsetTop - (tdElement.offsetHeight - tdElement.clientHeight )/2 + tdElement.clientTop);
            case "bottom":
                return tdElement.offsetTop - tdElement.offsetHeight + tdElement.clientHeight + tdElement.clientTop;
        }
        return tdElement.offsetTop;
    },
    GetClientHeight: function(tdElement){
        var valign = _aspxGetCurrentStyle(tdElement).verticalAlign;
        switch(valign){
            case "middle":
                return tdElement.clientHeight + tdElement.offsetTop * 2;
            case "top":
                return tdElement.offsetHeight - tdElement.clientTop * 2;
            case "bottom":
                return tdElement.clientHeight + tdElement.offsetTop;
        }
        return tdElement.clientHeight;
    }
}
function _aspxGetIsValidPosition(pos){
    return pos != __aspxInvalidPosition && pos != -__aspxInvalidPosition;
}
function _aspxGetAbsoluteX(curEl){
    return _aspxGetAbsolutePositionX(curEl);
}
function _aspxGetAbsoluteY(curEl){
    return _aspxGetAbsolutePositionY(curEl);
}
function _aspxSetAbsoluteX(element, x){
    element.style.left = _aspxPrepareClientPosForElement(x, element, true) + "px";
}
function _aspxSetAbsoluteY(element, y){
    element.style.top = _aspxPrepareClientPosForElement(y, element, false) + "px";
}
function _aspxGetAbsolutePositionX(element){
    if (__aspxIE)
        return _aspxGetAbsolutePositionX_IE(element);
    else if (__aspxFirefox3)
        return _aspxGetAbsolutePositionX_FF3(element);
    else if (__aspxOpera)
        return _aspxGetAbsolutePositionX_Opera(element);
    else if(__aspxNS && !__aspxFirefox3)
        return _aspxGetAbsolutePositionX_NS(element);
    else if(__aspxSafariFamily)
        return _aspxGetAbsolutePositionX_Safari(element);
    else
        return _aspxGetAbsolutePositionX_Other(element);
}
function _aspxGetAbsolutePositionX_Opera(curEl){
    var isFirstCycle = true;
    var pos = _aspxGetAbsoluteOffsetX_OperaFFSafari(curEl);
    while (curEl != null) {
        pos += curEl.offsetLeft;
        if(!isFirstCycle)
            pos -= curEl.scrollLeft;
        curEl = curEl.offsetParent;
        isFirstCycle = false;
    }
    pos += document.body.scrollLeft;
    return pos;
}
function _aspxGetAbsolutePositionX_IE(element){
    if(element == null || __aspxIE && element.parentNode == null) return 0; // B96664
    return element.getBoundingClientRect().left + _aspxGetDocumentScrollLeft() - _aspxGetIEDocumentClientOffsetInternal(true);
}
function _aspxGetAbsolutePositionX_FF3(element){
    if(element == null) return 0;
    var x = element.getBoundingClientRect().left + _aspxGetDocumentScrollLeft() - _aspxGetIEDocumentClientOffsetInternal(true);
    return Math.round(x);
}
function _aspxGetAbsolutePositionX_NS(curEl){
    var pos = _aspxGetAbsoluteOffsetX_OperaFFSafari(curEl);
    var isFirstCycle = true;
    while (curEl != null) {
        pos += curEl.offsetLeft;
        if (!isFirstCycle && curEl.offsetParent != null)
            pos -= curEl.scrollLeft;
        if (!isFirstCycle && __aspxFirefox){
            var style = _aspxGetCurrentStyle(curEl);
            if(curEl.tagName == "DIV" && style.overflow != "visible")
                pos += _aspxPxToInt(style.borderLeftWidth);
        }
        isFirstCycle = false;
        curEl = curEl.offsetParent;
    }
    return pos;
}
function _aspxGetAbsolutePositionX_Safari(curEl){
    var pos = _aspxGetAbsoluteOffsetX_OperaFFSafari(curEl);
	var isSafariVerNonLessThan3OrChrome = __aspxSafariVersionNonLessThan3 || __aspxChrome;
    if(curEl != null){
        var isFirstCycle = true;
        if(isSafariVerNonLessThan3OrChrome && curEl.tagName == "TD") {
            pos += curEl.offsetLeft;
            curEl = curEl.offsetParent;
            isFirstCycle = false;
        }
        while (curEl != null) {
            pos += curEl.offsetLeft;
            if(isSafariVerNonLessThan3OrChrome && !isFirstCycle && (curEl.tagName == "TD" || curEl.tagName == "TABLE"))
                pos += curEl.clientLeft;
            isFirstCycle = false;
            curEl = curEl.offsetParent;
        }
    }
    return pos;
}
// B91523
function _aspxGetAbsoluteOffsetX_OperaFFSafari(curEl) {
    var pos = 0;
    var isFirstCycle = true;
    while (curEl != null) {
        if(curEl.tagName == "BODY")
            break;
        var style = _aspxGetCurrentStyle(curEl);
        if(!__aspxSafariFamily && style.position == "absolute")
            break;
        if(!isFirstCycle && curEl.tagName == "DIV" && (__aspxSafariFamily || style.position == "" || style.position == "static"))
            pos -= curEl.scrollLeft;
        curEl = curEl.parentNode;
        isFirstCycle = false;
    }
    return pos;
}
function _aspxGetAbsolutePositionX_Other(curEl){
    var pos = 0;
    var isFirstCycle = true;
    while (curEl != null) {
        pos += curEl.offsetLeft;
        if (!isFirstCycle && curEl.offsetParent != null)
            pos -= curEl.scrollLeft;
        isFirstCycle = false;
        curEl = curEl.offsetParent;
    }
    return pos;
}
function _aspxGetAbsolutePositionY(element){
    if (__aspxIE)
        return _aspxGetAbsolutePositionY_IE(element);
    else if (__aspxFirefox3)
        return _aspxGetAbsolutePositionY_FF3(element);
    else if (__aspxOpera)
        return _aspxGetAbsolutePositionY_Opera(element);
    else if(__aspxNS && !__aspxFirefox3)
        return _aspxGetAbsolutePositionY_NS(element);
    else if(__aspxSafariFamily)
        return _aspxGetAbsolutePositionY_Safari(element);
    else
        return _aspxGetAbsolutePositionY_Other(element);
}
function _aspxGetAbsolutePositionY_Opera(curEl){
    var isFirstCycle = true;
    if(curEl && curEl.tagName == "TR" && curEl.cells.length > 0)
        curEl = curEl.cells[0];
    var pos = _aspxGetAbsoluteOffsetY_OperaFFSafari(curEl);
    while (curEl != null) {
        pos += curEl.offsetTop;
        if(!isFirstCycle)
            pos -= curEl.scrollTop;
        curEl = curEl.offsetParent;
        isFirstCycle = false;
    }
    pos += document.body.scrollTop;
    return pos;
}
function _aspxGetAbsolutePositionY_IE(element){
    if(element == null || __aspxIE && element.parentNode == null) return 0; // B96664
    return element.getBoundingClientRect().top + _aspxGetDocumentScrollTop() - _aspxGetIEDocumentClientOffsetInternal(false);
}
function _aspxGetAbsolutePositionY_FF3(element){
    if(element == null) return 0;
    var y = element.getBoundingClientRect().top + _aspxGetDocumentScrollTop() - _aspxGetIEDocumentClientOffsetInternal(false);
    return Math.round(y);
}
function _aspxGetAbsolutePositionY_NS(curEl){
    var pos = _aspxGetAbsoluteOffsetY_OperaFFSafari(curEl);
    var isFirstCycle = true;
    while (curEl != null) {
        pos += curEl.offsetTop;
        if (!isFirstCycle && curEl.offsetParent != null)
            pos -= curEl.scrollTop;
        if (!isFirstCycle && __aspxFirefox){
            var style = _aspxGetCurrentStyle(curEl);
            if(curEl.tagName == "DIV" && style.overflow != "visible")
                pos += _aspxPxToInt(style.borderTopWidth);
        }
        isFirstCycle = false;
        curEl = curEl.offsetParent;
    }
    return pos;
}
function _aspxGetAbsolutePositionY_Safari(curEl){
    var pos = _aspxGetAbsoluteOffsetY_OperaFFSafari(curEl);
    var isSafariVerNonLessThan3OrChrome = __aspxSafariVersionNonLessThan3 || __aspxChrome;
    if(curEl != null){
        var isFirstCycle = true;
        if(isSafariVerNonLessThan3OrChrome && curEl.tagName == "TD") {
            pos += _aspxWebKit3TDRealInfo.GetOffsetTop(curEl);
            curEl = curEl.offsetParent;
            isFirstCycle = false;
        }
        while (curEl != null) {
            pos += curEl.offsetTop;
            if(isSafariVerNonLessThan3OrChrome && !isFirstCycle && (curEl.tagName == "TD" || curEl.tagName == "TABLE"))
                pos += curEl.clientTop;
            isFirstCycle = false;
            curEl = curEl.offsetParent;
        }
    }
    return pos;
}
// B91523
function _aspxGetAbsoluteOffsetY_OperaFFSafari(curEl) {
    var pos = 0;   
    var isFirstCycle = true;
    while (curEl != null) {
        if(curEl.tagName == "BODY")
            break;
        var style = _aspxGetCurrentStyle(curEl);
        if(!__aspxSafariFamily && style.position == "absolute")
            break;
        if(!isFirstCycle && curEl.tagName == "DIV" && (__aspxSafariFamily || style.position == "" || style.position == "static"))
            pos -= curEl.scrollTop;
        curEl = curEl.parentNode;
        isFirstCycle = false;
    }
    return pos; 
}
function _aspxGetAbsolutePositionY_Other(curEl){
    var pos = 0;
    var isFirstCycle = true;
    while (curEl != null) {
        pos += curEl.offsetTop;
        if (!isFirstCycle && curEl.offsetParent != null)
            pos -= curEl.scrollTop;
        
        isFirstCycle = false;
        curEl = curEl.offsetParent;
    }
    return pos;
}

function _aspxPrepareClientPosForElement(pos, element, isX) {
    pos -= _aspxGetPositionElementOffset(element, isX);
    return pos;
}
function _aspxGetPositionElementOffset(element, isX) {
    var curEl = element.offsetParent;
    var offset = 0;
    var scroll = 0;
    var isThereFixedParent = false;
    var isFixed = false;
    var position = "";
    while(curEl != null) {
        var tagName = curEl.tagName;
        if(tagName == "HTML" || tagName == "BODY")
            break;
        if(tagName != "TD" && tagName != "TR") {
            var style = _aspxGetCurrentStyle(curEl);
            isFixed = style.position == "fixed";
            if(isFixed)
                isThereFixedParent = true;
            
            if (style.position == "absolute" || isFixed || style.position == "relative") {
                offset += isX ? curEl.offsetLeft : curEl.offsetTop;
                if (__aspxIE || __aspxOpera9 || __aspxSafariMacOS)
                    offset += _aspxPxToInt(isX ? style.borderLeftWidth : style.borderTopWidth);
            }
        }
        scroll += isX ? curEl.scrollLeft : curEl.scrollTop;
        curEl = curEl.offsetParent;
    }
    offset -= scroll; // Bug B92105
    if((__aspxIE7 ||__aspxFirefox3) && isThereFixedParent) 
        offset += isX ? _aspxGetDocumentScrollLeft() : _aspxGetDocumentScrollTop();
    return offset;
}
function _aspxPxToInt(px) {
    var result = 0;
    if (px != null && px != "") {
        try {
            var indexOfPx = px.indexOf("px");
            if (indexOfPx > -1)
                result = parseInt(px.substr(0, indexOfPx));
        } catch(e) { }
    }
    return result;
}
function _aspxGetClearClientWidth(element) {
    var currentStyle = _aspxGetCurrentStyle(element);
    return element.offsetWidth - _aspxPxToInt(currentStyle.paddingLeft) - _aspxPxToInt(currentStyle.paddingRight) -
        _aspxPxToInt(currentStyle.borderLeftWidth) - _aspxPxToInt(currentStyle.borderRightWidth);
}
function _aspxGetClearClientHeight(element) {
    var currentStyle = _aspxGetCurrentStyle(element);
    return element.offsetHeight - _aspxPxToInt(currentStyle.paddingTop) - _aspxPxToInt(currentStyle.paddingBottom) -
        _aspxPxToInt(currentStyle.borderTopWidth) - _aspxPxToInt(currentStyle.borderBottomWidth);
}
function _aspxSetOffsetWidth(element, widthValue) {
    var currentStyle = _aspxGetCurrentStyle(element);
    var value = widthValue - _aspxPxToInt(currentStyle.marginLeft) - _aspxPxToInt(currentStyle.marginRight);
    if(__aspxIE)
        value -= _aspxPxToInt(currentStyle.paddingLeft) + _aspxPxToInt(currentStyle.paddingRight) +
            _aspxPxToInt(currentStyle.borderLeftWidth) + _aspxPxToInt(currentStyle.borderRightWidth);
    // B90988
    if(value > -1)
        element.style.width = value + "px";
}
function _aspxSetOffsetHeight(element, heightValue) {
    var currentStyle = _aspxGetCurrentStyle(element);
    var value = heightValue - _aspxPxToInt(currentStyle.marginTop) - _aspxPxToInt(currentStyle.marginBottom);
    if(__aspxIE)
        value -= _aspxPxToInt(currentStyle.paddingTop) + _aspxPxToInt(currentStyle.paddingBottom) +
            _aspxPxToInt(currentStyle.borderTopWidth) + _aspxPxToInt(currentStyle.borderBottomWidth);    
    // B90988
    if(value > -1)
        element.style.height = value + "px";
}
function _aspxFindOffsetParent(element) {
    if (__aspxIE)
        return element.offsetParent;
    var currentElement = element.parentNode;
    while(_aspxIsExistsElement(currentElement) && currentElement.tagName != "BODY") {
        if (currentElement.offsetWidth > 0 && currentElement.offsetHeight > 0)
            return currentElement;
        currentElement = currentElement.parentNode;
    }
    return document.body;
}
function _aspxGetDocumentScrollTop(){
    if(__aspxSafariFamily || __aspxIE55 || document.documentElement.scrollTop == 0)
        return document.body.scrollTop;
    else
        return document.documentElement.scrollTop;
}
function _aspxGetDocumentScrollLeft(){
    if(__aspxSafariFamily || __aspxIE55 || document.documentElement.scrollLeft == 0)
        return document.body.scrollLeft;
    else
        return document.documentElement.scrollLeft;
}
function _aspxGetDocumentClientWidth(){
    if(__aspxSafariFamily || __aspxIE55 || document.documentElement.clientWidth == 0)
        return document.body.clientWidth;
    else
        return document.documentElement.clientWidth;
}
function _aspxGetDocumentClientHeight(){
    if(__aspxSafariFamily)
        return window.innerHeight;
    else if(__aspxOpera ) // B33854
        return __aspxOperaVersionGreaterThan95 ? document.documentElement.clientHeight : document.body.clientHeight;
    else if(__aspxIE55 ||  document.documentElement.clientHeight == 0)
        return document.body.clientHeight;
    else
        return document.documentElement.clientHeight;
}
function _aspxSetStylePosition(element, x, y){
    element.style.left = x + "px";
    element.style.top = y + "px";
}
function _aspxSetStyleSize(element, width, height){
    element.style.width = width + "px";
    element.style.height = height + "px";
}
function _aspxGetDocumentWidthWithoutScroll(){
    if(__aspxIE){
        var bodyWidth = document.body.offsetWidth;
        var bodyScrollWidth = document.body.scrollWidth;
        return _aspxGetMaxDimensionOf(bodyWidth, bodyScrollWidth);
    }
    return _aspxGetDocumentWidth();
}
function _aspxGetDocumentWidth(){
    if(__aspxIE6)
        return _aspxGetDocumentClientWidth();  // B132119 & B36649
		    
    var bodyWidth = document.body.offsetWidth;
    var docWidth = document.documentElement.offsetWidth;
    var bodyScrollWidth = document.body.scrollWidth;
    var docScrollWidth = document.documentElement.scrollWidth;
    return _aspxGetMaxDimensionOf(bodyWidth, docWidth, bodyScrollWidth, docScrollWidth);
}
function _aspxGetDocumentHeight(){
    var bodyHeight = document.body.offsetHeight;
    var docHeight = document.documentElement.offsetHeight;
    var bodyScrollHeight = document.body.scrollHeight;
    var docScrollHeight = document.documentElement.scrollHeight;
    var maxHeight = _aspxGetMaxDimensionOf(bodyHeight, docHeight, bodyScrollHeight, docScrollHeight);

    if(__aspxOpera && __aspxOperaVersionGreaterThan95)
        maxHeight = _aspxGetMaxDimensionOf(window.outerHeight, maxHeight);

    return maxHeight;
}
function _aspxGetDocumentMaxClientWidth(){
    var bodyWidth = document.body.offsetWidth;
    var docWidth = document.documentElement.offsetWidth;
    return _aspxGetMaxDimensionOf(bodyWidth, docWidth);
}
function _aspxGetDocumentMaxClientHeight(){
    var bodyHeight = document.body.offsetHeight;
    var docHeight = document.documentElement.offsetHeight;
    return _aspxGetMaxDimensionOf(bodyHeight, docHeight);
}
function _aspxGetMaxDimensionOf(){
    var max = __aspxInvalidDimension;
    for (var i = 0; i < arguments.length; i++){
        if(max < arguments[i])
            max = arguments[i];
    }
    return max;
}
function _aspxGetClientLeft(element){
    return _aspxIsExists(element.clientLeft) ? element.clientLeft : (element.offsetWidth - element.clientWidth) / 2;
}
function _aspxGetClientTop(element){
    return _aspxIsExists(element.clientTop) ? element.clientTop : (element.offsetHeight - element.clientHeight) / 2;
}
function _aspxRemoveBorders(element) {
    if(!_aspxIsExists(element))
        return;
    element.style.borderWidth = 0;
    for(var i = 0; i < element.childNodes.length; i++) {
        var child = element.childNodes[i];
        if(_aspxIsExists(child.style))
            child.style.border = "0";
    }
}
function _aspxSetBackground(element, background) {
    if(!_aspxIsExists(element))
        return;
    element.style.backgroundColor = background;
    for(var i = 0; i < element.childNodes.length; i++) {
        var child = element.childNodes[i];
        if(_aspxIsExists(child.style))
            child.style.backgroundColor = background;
    }
}
function _aspxSetFocus(element) {
    try {
        element.focus();
        if(__aspxIE && document.activeElement != element)
            element.focus(); // fix for IE
    } catch (e) {

    }
}
function _aspxIsFocusableCore(element, skipContainerVisibilityCheck) {
    var current = element;
    while(_aspxIsExists(current)) {
        if (current == element || !skipContainerVisibilityCheck(current)) {
            if (current.tagName == "BODY")
                return true;
            if (current.disabled || !_aspxGetElementDisplay(current) || !_aspxGetElementVisibility(current))
                return false;
        }
        current = current.parentNode;
    }
    return true;
}
function _aspxIsFocusable(element) {  
    return _aspxIsFocusableCore(element, function() { return false; });
}
function _aspxAttachEventToElement(element, eventName, func) {
    if(__aspxNS || __aspxSafariFamily)
        element.addEventListener(eventName, func, true);
    else {
        if(eventName.toLowerCase().indexOf("on") != 0) 
            eventName = "on" + eventName;
        element.attachEvent(eventName, func);
    }
}
function _aspxDetachEventFromElement(element, eventName, func) {
    if(__aspxNS || __aspxSafariFamily)
        element.removeEventListener(eventName, func, true);
    else {
        if(eventName.toLowerCase().indexOf("on") != 0) 
            eventName = "on" + eventName;
        element.detachEvent(eventName, func);
    }
}
function _aspxAttachEventToDocument(eventName, func) {
    _aspxAttachEventToElement(document, eventName, func);
}
function _aspxDetachEventFromDocument(eventName, func) {
    _aspxAttachEventToElement(document, eventName, func);
}
function _aspxCreateEventHandlerFunction(funcName, controlName, withHtmlEventArg) {
    return withHtmlEventArg ?
        new Function("event", funcName + "('" + controlName + "', event);") :
        new Function(funcName + "('" + controlName + "');");
}

function _aspxCreateClass(parentClass, properties) {
    var ret = function() {
        if (ret.preparing) 
            return delete(ret.preparing);
        if (ret.constr) {
            this.constructor = ret;
            ret.constr.apply(this, arguments);
        }
    }
    ret.prototype = {};
    if(_aspxIsExists(parentClass)) {
        parentClass.preparing = true;
        ret.prototype = new parentClass;
        ret.prototype.constructor = parentClass;
        ret.constr = parentClass;
    }
    if(_aspxIsExists(properties)) {
        var constructorName = "constructor";
        for(var name in properties){
            if (name != constructorName) 
                ret.prototype[name] = properties[name];
        }
        if (properties[constructorName] && properties[constructorName] != Object)
            ret.constr = properties[constructorName];
    }
    return ret;
}
// Attributes
function _aspxGetAttribute(obj, attrName){
    if(_aspxIsExists(obj.getAttribute))
        return obj.getAttribute(attrName);
    else if(_aspxIsExists(obj.getPropertyValue))
        return obj.getPropertyValue(attrName);
    return null;
}
function _aspxSetAttribute(obj, attrName, value){
    if(_aspxIsExists(obj.setAttribute))
        obj.setAttribute(attrName, value);
    else if(_aspxIsExists(obj.setProperty))
        obj.setProperty(attrName, value, "");
}
function _aspxRemoveAttribute(obj, attrName){
    if(_aspxIsExists(obj.removeAttribute))
        obj.removeAttribute(attrName);
    else if(_aspxIsExists(obj.removeProperty))
        obj.removeProperty(attrName);
}
function _aspxIsExistsAttribute(obj, attrName){
    var value = _aspxGetAttribute(obj, attrName);
    return (value != null) && (value != "");
}
function _aspxSetOrRemoveAttribute(obj, attrName, value) {
    if (!value)
        _aspxRemoveAttribute(obj, attrName);
    else
        _aspxSetAttribute(obj, attrName, value);
}
function _aspxChangeAttributeExtended(obj, attrName, savedObj, savedAttrName, newValue){
    if(!_aspxIsExistsAttribute(savedObj, savedAttrName)){
        var oldValue = _aspxIsExistsAttribute(obj, attrName) ? _aspxGetAttribute(obj, attrName) : __aspxEmptyAttributeValue;
        _aspxSetAttribute(savedObj, savedAttrName, oldValue);
    }
    _aspxSetAttribute(obj, attrName, newValue);
}
function _aspxChangeAttribute(obj, attrName, newValue){
    _aspxChangeAttributeExtended(obj, attrName, obj, "saved" + attrName, newValue);
}
function _aspxChangeStyleAttribute(obj, attrName, newValue){
    _aspxChangeAttributeExtended(obj.style, attrName, obj, "saved" + attrName, newValue);
}
function _aspxResetAttributeExtended(obj, attrName, savedObj, savedAttrName){
    if(!_aspxIsExistsAttribute(savedObj, savedAttrName)){
        var oldValue = _aspxIsExistsAttribute(obj, attrName) ? _aspxGetAttribute(obj, attrName) : __aspxEmptyAttributeValue;
        _aspxSetAttribute(savedObj, savedAttrName, oldValue);
     }
    _aspxSetAttribute(obj, attrName, "");
    _aspxRemoveAttribute(obj, attrName);
}
function _aspxResetAttribute(obj, attrName){
    _aspxResetAttributeExtended(obj, attrName, obj, "saved" + attrName);
}
function _aspxResetStyleAttribute(obj, attrName){
    _aspxResetAttributeExtended(obj.style, attrName, obj, "saved" + attrName);
}
function _aspxRestoreAttributeExtended(obj, attrName, savedObj, savedAttrName){
    if(_aspxIsExistsAttribute(savedObj, savedAttrName)){
        var oldValue = _aspxGetAttribute(savedObj, savedAttrName);
        if(oldValue != __aspxEmptyAttributeValue)
            _aspxSetAttribute(obj, attrName, oldValue);
        else
            _aspxRemoveAttribute(obj, attrName);
        _aspxRemoveAttribute(savedObj, savedAttrName);
    }
}
function _aspxRestoreAttribute(obj, attrName){
    _aspxRestoreAttributeExtended(obj, attrName, obj, "saved" + attrName);
}
function _aspxRestoreStyleAttribute(obj, attrName){
    _aspxRestoreAttributeExtended(obj.style, attrName, obj, "saved" + attrName);
}

function _aspxRemoveAllAttributes(element, excludedAttributes) {
    var excludedAttributesHashTable = {};
    if (_aspxIsExists(excludedAttributes))
        excludedAttributesHashTable = _aspxCreateHashTableFromArray(excludedAttributes);
        
    if (_aspxIsExists(element.attributes)) {
        var attrArray = element.attributes;
        for (var i = 0; i < attrArray.length; i++) {
            var attrName = attrArray[i].name;
            if (!_aspxIsExists(excludedAttributesHashTable[attrName.toLowerCase()]))
                attrArray.removeNamedItem(attrName);
        }
    }
}
function _aspxRemoveStyleAttribute(element, attrName) {
    if (_aspxIsExists(element.style)) {
        if (__aspxFirefox && element.style[attrName]) // attribute isn't removed if it isn't empty
            element.style[attrName] = "";
        if (_aspxIsExists(element.style.removeAttribute) && element.style.removeAttribute != "")
            element.style.removeAttribute(attrName);
        else if (_aspxIsExists(element.style.removeProperty) && element.style.removeProperty != "")
            element.style.removeProperty(attrName);
    }
}
function _aspxRemoveAllStyles(element) {
    if (_aspxIsExists(element.style)) {
        for(var key in element.style)
            _aspxRemoveStyleAttribute(element, key);
       _aspxRemoveAttribute(element, "style");
    }
}

function _aspxChangeAttributesMethod(enabled){
    return enabled ? _aspxRestoreAttribute : _aspxResetAttribute;
}
function _aspxInitiallyChangeAttributesMethod(enabled){
    return enabled ? _aspxChangeAttribute : _aspxResetAttribute;
}
function _aspxChangeStyleAttributesMethod(enabled){
    return enabled ? _aspxRestoreStyleAttribute : _aspxResetStyleAttribute;
}
function _aspxInitiallyChangeStyleAttributesMethod(enabled){
    return enabled ? _aspxChangeStyleAttribute : _aspxResetStyleAttribute;
}
function _aspxChangeEventsMethod(enabled){
    return enabled ? _aspxAttachEventToElement : _aspxDetachEventFromElement;
}
function _aspxChangeDocumentEventsMethod(enabled){
    return enabled ? _aspxAttachEventToDocument : _aspxDetachEventFromDocument;
}
// String Utils
function _aspxLTrim(str) {    
    var re = /\s*((\S+\s*)*)/;
    return str.replace(re, "$1");    
}
function _aspxRTrim(str) {    
    var re = /((\s*\S+)*)\s*/;
    return str.replace(re, "$1");    
}
function _aspxTrim(str) {    
    return _aspxLTrim(_aspxRTrim(str));    
}
function _aspxInsert(str, subStr, index) {    
    var leftText = str.slice(0, index);
    var rightText = str.slice(index);
    return leftText + subStr + rightText;
}
function _aspxInsertEx(str, subStr, startIndex, endIndex) {    
    var leftText = str.slice(0, startIndex);
    var rightText = str.slice(endIndex);
    return leftText + subStr + rightText;
}

//Url utils
function _aspxNavigateUrl(url, target) {
    var javascriptPrefix = "javascript:";
    if(url == "")
        return;
    else if(url.indexOf(javascriptPrefix) != -1) 
        eval(url.substr(javascriptPrefix.length));
    else {
        if(target != "")
            _aspxNavigateTo(url, target);
        else
            location.href = url;
    }
}

function _aspxNavigateTo(url, target) {
    var lowerCaseTarget = target.toLowerCase();
    if("_top" == lowerCaseTarget)
        top.location.href = url;
    else if("_self" == lowerCaseTarget)
        location.href = url;
    else if("_search" == lowerCaseTarget)
        window.open(url, 'blank');
    else if("_media" == lowerCaseTarget)
        window.open(url, 'blank');
    else if("_parent" == lowerCaseTarget)
        window.parent.location.href = url;
    else if("_blank" == lowerCaseTarget)
        window.open(url, 'blank');
    else {
        var frame = _aspxGetFrame(top.frames, target);
        if(frame != null)
            frame.location.href = url;
        else
            window.open(url, 'blank');
    }
}
function _aspxGetFrame(frames, name) {
    if(_aspxIsExists(frames[name]))
        return frames[name];
    for(var i = 0; i < frames.length; i++) {
        try {
            var frame = frames[i];
            if(frame.name == name) 
                return frame;    

            frame = _aspxGetFrame(frame.frames, name);
            if(frame != null)   
                return frame;    
        } catch(e) {
        
        }    
    }
    return null;
}
// Color utils
function _aspxToHex(d) {
    return (d < 16) ? ("0" + d.toString(16)) : d.toString(16);
}
function _aspxColorToHexadecimal(colorValue) {
    if (typeof(colorValue) == "number") {
        var r = colorValue & 0xFF;
        var g = (colorValue >> 8) & 0xFF;
        var b = (colorValue >> 16) & 0xFF;
        return "#" + _aspxToHex(r) + _aspxToHex(g) + _aspxToHex(b);
    }
    if (colorValue && (colorValue.substr(0, 3) == "rgb")) {
        // in rgb(...) form -- Mozilla
        var re = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/;
        var regResult = colorValue.match(re);
        if (regResult) {
            var r = parseInt(regResult[1]);
            var g = parseInt(regResult[2]);
            var b = parseInt(regResult[3]);
            return "#" + _aspxToHex(r) + _aspxToHex(g) + _aspxToHex(b);
        }
        return null;
    }    
    if (colorValue && (colorValue.charAt(0) == "#"))
        return colorValue;
    return null;
}

// Callbacks
function _aspxFormatCallbackArg(prefix, arg) {
    // [Victor] TODO: refactor HtmlEditor->Dialogs.js and remove this logics (only simple data types are expected)
    if(prefix == null || prefix == "" || arg == null)
        return "";
    if(arg != null && !_aspxIsExists(arg.length) && _aspxIsExists(arg.value))
        arg = arg.value;
    arg = arg.toString();
    return [prefix, '|', arg.length, '|' , arg].join('');
}
function _aspxFormatCallbackArgs(callbackData) {
    var sb = new ASPxStringBuilder();
    for(var i = 0; i < callbackData.length; i++)
        sb.Append(_aspxFormatCallbackArg(callbackData[i][0], callbackData[i][1]));
    return sb.ToString();
}

function _aspxIsValidElement(element){
    if(__aspxIE)
        return _aspxIsExists(element.parentNode) && _aspxIsExists(element.parentNode.tagName);
    else {
        if(!__aspxOpera && element.offsetParent != null)
            return true;
        while(element != null){
            if(_aspxIsExists(element.tagName) && element.tagName == "BODY")
                return true;
            element = element.parentNode;
        }
        return false;
    }
}
function _aspxIsValidElements(elements) {
    if (!_aspxIsExists(elements))
        return false;    
    for(var i = 0; i < elements.length; i++) {
        if(_aspxIsExists(elements[i]) && !_aspxIsValidElement(elements[i]))
            return false;
    }
    return true;
}
function _aspxIsExistsElement(element) {
    return _aspxIsExists(element) && _aspxIsValidElement(element);
}
ASPxClientEvent = _aspxCreateClass(null, {
    constructor: function() {
        this.handlerInfoList = [];
    },
    AddHandler: function(handler, executionContext) {
        if(typeof(executionContext) == "undefined")
            executionContext = null;
        var handlerInfo = ASPxClientEvent.CreateHandlerInfo(handler, executionContext);
        this.handlerInfoList.push(handlerInfo);
    },
    RemoveHandler: function(handler, executionContext) {
        for(var i = this.handlerInfoList.length - 1; i >= 0; i--) {
            var handlerInfo = this.handlerInfoList[i];
            if(handlerInfo.handler == handler && (!executionContext || handlerInfo.executionContext == executionContext)) {
                _aspxArrayRemoveAt(this.handlerInfoList, i);
                return;
            }
        }
    },
    ClearHandlers: function() {
        this.handlerInfoList.length = 0;
    },
    FireEvent: function(obj, args) {
        for(var i = 0; i < this.handlerInfoList.length; i++) {
            var handlerInfo = this.handlerInfoList[i];
            handlerInfo.handler.call(handlerInfo.executionContext, obj, args);
        }
    },
    IsEmpty: function() {
        return this.handlerInfoList.length == 0;
    }
});
ASPxClientEvent.CreateHandlerInfo = function(handler, executionContext) {
    var info = new Object();
    info.handler = handler;
    info.executionContext = executionContext;
    return info;
};
ASPxClientEventArgs = _aspxCreateClass(null, {
    constructor: function() {

    }
});
ASPxClientEventArgs.Empty = new ASPxClientEventArgs();
ASPxClientProcessingModeEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
    constructor: function(processOnServer){
        this.constructor.prototype.constructor.call(this);
        this.processOnServer = processOnServer;
    }
});
ASPxClientCancelEventArgs = _aspxCreateClass(ASPxClientProcessingModeEventArgs, {
    constructor: function(processOnServer){
        this.constructor.prototype.constructor.call(this, processOnServer);
        this.cancel = false;
    }
});
ASPxClientBeginCallbackEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
    constructor: function(command){
        this.constructor.prototype.constructor.call(this);
        this.command = command;
    }
});
ASPxClientEndCallbackEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
    constructor: function(){
        this.constructor.prototype.constructor.call(this);
    }
});
ASPxClientCallbackErrorEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
    constructor: function(message){
        this.constructor.prototype.constructor.call(this);
        this.message = message;
        this.handled = false;
    }
});

ASPxPostHandler = _aspxCreateClass(null, {
    constructor: function() {
        this.Post = new ASPxClientEvent();

        this.ReplaceGlobalPostFunctions();
        this.HandleDxCallbackBeginning();
        this.HandleMSAjaxRequestBeginning();
    },
    OnPost: function() {
        this.Post.FireEvent(this, ASPxClientEventArgs.Empty);
    },
    ReplaceGlobalPostFunctions: function() {
        if(_aspxIsFunction(window.__doPostBack))
            this.ReplaceDoPostBack();
        if(_aspxIsFunction(window.WebForm_DoCallback))
            this.ReplaceDoCallback();
        var form = _aspxGetServerForm();
        if(form.submit)
            this.ReplaceFormSubmit(form);
        this.ReplaceFormOnSumbit(form);
        form = null;
    },
    HandleDxCallbackBeginning: function() {
        aspxGetControlCollection().BeforeInitCallback.AddHandler(function() {
            _aspxRaisePostHandlerOnPost(false, true);
        });
    },
    HandleMSAjaxRequestBeginning: function() {
        if(window.Sys && Sys.WebForms && Sys.WebForms.PageRequestManager && Sys.WebForms.PageRequestManager.getInstance) {
            var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
            if(pageRequestManager != null && ASPxIdent.IsArray(pageRequestManager._onSubmitStatements)) {
                pageRequestManager._onSubmitStatements.unshift(function() {
                    _aspxRaisePostHandlerOnPost(true); return true;
                });
            }
        }
    },
    ReplaceDoPostBack: function() {
        var original = __doPostBack;
        __doPostBack = function(eventTarget, eventArgument) {
            _aspxRaisePostHandlerOnPost();
            original(eventTarget, eventArgument);
        };
    },
    ReplaceDoCallback: function() {
        var original = WebForm_DoCallback;
        WebForm_DoCallback = function(eventTarget, eventArgument, eventCallback, context, errorCallback, useAsync) {
            var postHandler = aspxGetPostHandler();
            
            if(postHandler.dxCallbackHandled)
                delete postHandler.dxCallbackHandled;
            else
                _aspxRaisePostHandlerOnPost();
            
            return original(eventTarget, eventArgument, eventCallback, context, errorCallback, useAsync);
        };
    },
    ReplaceFormSubmit: function(form) {
        var original = form.submit;
        form.submit = function() {
            _aspxRaisePostHandlerOnPost();
            var callee = arguments.callee;
            this.submit = original;
            var submitResult = this.submit();
            this.submit = callee;
            return submitResult;
        };
    },
    ReplaceFormOnSumbit: function(form) {
        var original = form.onsubmit;
        form.onsubmit = function() {
            var postHandler = aspxGetPostHandler();

            if(postHandler.msAjaxRequestBeginningHandled)
                delete postHandler.msAjaxRequestBeginningHandled;
            else
                _aspxRaisePostHandlerOnPost();

            return _aspxIsFunction(original) ? original() : true;
        };
        form = null;
    }
});

function _aspxRaisePostHandlerOnPost(isMSAjaxRequestBeginninging, isDXCallbackBeginning) {
    var postHandler = aspxGetPostHandler();
    if(_aspxIsExists(postHandler)) {
        if(isMSAjaxRequestBeginninging)
            postHandler.msAjaxRequestBeginningHandled = true;
        else if(isDXCallbackBeginning)
            postHandler.dxCallbackHandled = true;
        postHandler.OnPost();
    }
}
function aspxGetPostHandler() {
    if (!_aspxIsExistsType(typeof(window.__aspxPostHandler)))
        window.__aspxPostHandler = new ASPxPostHandler();
    return window.__aspxPostHandler;
}
ASPxClientControlCollection = _aspxCreateClass(null, {
    constructor: function(){
        this.elements = new Object();

        this.BeforeInitCallback = new ASPxClientEvent();
        this.ControlsInitialized = new ASPxClientEvent();
    },
    
    Add: function(element){
        this.elements[element.name] = element;
    },    
    Get: function(name){
        return this.elements[name];
    },
    
    // controls group operations
    AdjustControls: function(container, checkSizeCorrectedFlag) {
        window.setTimeout(function() {
            var collection = aspxGetControlCollection();
            collection.ProcessControlsInConatiner(container, checkSizeCorrectedFlag, function(control, check) { control.AdjustControl(check); });
        }, 0);
    },
    CollapseControls: function(container, checkSizeCorrectedFlag) {
        this.ProcessControlsInConatiner(container, checkSizeCorrectedFlag, function(control, check) {
            control.CollapseControl(check);
        });
    },
    
    AtlasInitialize: function(){
        _aspxProcessScriptsAndLinks("");
    },
    Initialize: function(){
        this.InitializeElements();
        if(_aspxIsExistsType(typeof(Sys)) && _aspxIsExistsType(typeof(Sys.Application)))
            Sys.Application.add_load(aspxCAInit);
    },
    InitializeElements: function(){
        for(var name in this.elements) {
            var control = this.elements[name];
            if(!ASPxIdent.IsASPxClientControl(control))
                continue;
            if (!control.isInitialized)
                control.Initialize();
        }
        this.AfterInitializeElements(true);
        this.AfterInitializeElements(false);
        this.RaiseControlsInitialized();
    },
    AfterInitializeElements: function(leadingCall) {
        for(var name in this.elements){
            var control = this.elements[name];
            if(!ASPxIdent.IsASPxClientControl(control))
                continue;
            if (control.leadingAfterInitCall && leadingCall || !control.leadingAfterInitCall && !leadingCall) {
                if(!this.elements[name].isInitialized)
                    this.elements[name].AfterInitialize();
            }
        }
    },
    DoFinalizeCallback: function() {
        for(var name in this.elements){
            var control = this.elements[name];
            if(!ASPxIdent.IsASPxClientControl(control))
                continue;
            control.DoFinalizeCallback();
        }
    },
    ProcessControlsInConatiner: function(container, checkSizeCorrectedFlag, processingProc) {
        for (var controlName in this.elements) {
            var control = this.elements[controlName];
            if(!ASPxIdent.IsASPxClientControl(control))
                continue;
            if (_aspxIsExists(container) && _aspxIsExists(control.GetMainElement)) {
                var mainElement = control.GetMainElement();
                if (_aspxIsExists(mainElement) && !_aspxGetIsParent(container, mainElement))
                    continue;
            }
            processingProc(control, checkSizeCorrectedFlag);
        }
    },
    RaiseControlsInitialized: function(){
        if(!this.ControlsInitialized.IsEmpty()){
            var args = new ASPxClientEventArgs();
            this.ControlsInitialized.FireEvent(this, args);
        }
    },
    Before_WebForm_InitCallback: function(){
        var args = new ASPxClientEventArgs();
        this.BeforeInitCallback.FireEvent(this, args);
    }
});
ASPxClientControl = _aspxCreateClass(null, {
    constructor: function(name){
        this.isASPxClientControl = true;    
        this.name = name;
        this.uniqueID = name;

        this.enabled = true;
        this.clientEnabled = true;
        this.clientVisible = true;

        this.autoPostBack = false;
        this.allowMultipleCallbacks = true;
        this.callBack = null;
        this.savedCallbacks = null;
        this.isNative = false;
        this.requestCount = 0;

        this.isInitialized = false;
        this.initialFocused = false;
        this.leadingAfterInitCall = false; // AfterInitialize call will be displaced to the beginning of call queue
        this.sizeCorrectedOnce = false;
        this.serverEvents = [];
        
        this.dialogContentHashTable = { };
        
        this.sizeCorrectedOnce = false;
        
        this.loadingPanelElement = null;
        this.loadingDivElement = null;        
        this.mainElement = null;
        this.renderIFrameForPopupElements = false;
        this.Init = new ASPxClientEvent();
        this.BeginCallback = new ASPxClientEvent();
        this.EndCallback = new ASPxClientEvent();
        this.CallbackError = new ASPxClientEvent();
        
        aspxGetControlCollection().Add(this);        
    },
    Initialize: function() {
        if(this.callBack != null)
            this.InitializeCallBackData();
    },
    InlineInitialize: function() {

    },
    InitailizeFocus: function() {
        if(this.initialFocused && this.IsVisible())
            this.Focus();
    },
    AfterInitialize: function() {
        this.AdjustControl(__aspxCheckSizeCorrectedFlag);
        this.InitailizeFocus();
        this.isInitialized = true;
        this.RaiseInit();
            
        if(_aspxIsExists(this.savedCallbacks)) {
            for(var i = 0; i < this.savedCallbacks.length; i++) 
                this.CreateCallbackInternal(this.savedCallbacks[i][0], this.savedCallbacks[i][1], false);
            this.savedCallbacks = null;
        }
    },
    InitializeCallBackData: function() {

    },
    
    // Size correction
    CollapseControl: function(checkSizeCorrectedFlag) {
    
    },
    AdjustControl: function(checkSizeCorrectedFlag) {
        if (checkSizeCorrectedFlag && this.sizeCorrectedOnce)
            return;
        var mainElement = this.GetMainElement();
        if (!_aspxIsExists(mainElement) || !this.IsDisplayed())
            return;
        this.AdjustControlCore();
        this.sizeCorrectedOnce = true;
    },
    AdjustControlCore: function() {

    },
    
    RegisterServerEventAssigned: function(eventNames){
        for(var i = 0; i < eventNames.length; i++)
            this.serverEvents[eventNames[i]] = true;
    },
    IsServerEventAssigned: function(eventName){
        return _aspxIsExists(this.serverEvents[eventName]);
    },
    
    GetChild: function(idPostfix){
        var mainElement = this.GetMainElement();
        return _aspxIsExists(mainElement) ? _aspxGetChildById(this.GetMainElement(), this.name + idPostfix) : null;
    },
    GetItemElementName: function(element) {
        var name = "";
        if (_aspxIsExists(element.id))
            name = element.id.substring(this.name.length + 1);
        return name;
    },
    GetLinkElement: function(element) {
        if (element == null) return null;
        return (element.tagName == "A") ? element : _aspxGetChildByTagName(element, "A", 0);
    },
    GetMainElement: function(){
        if(!_aspxIsExistsElement(this.mainElement))
            this.mainElement = _aspxGetElementById(this.name);
        return this.mainElement;
    },
    IsRightToLeft: function() {
        return _aspxIsElementRigthToLeft(this.GetMainElement());
    },

    OnControlClick: function(clickedElement, htmlEvent) {

    },
    // Callback
    GetLoadingPanelElement: function(){
        return _aspxGetElementById(this.name + "_LP");
    },
    CloneLoadingPanel: function(element, parent) {
        var clone = element.cloneNode(true);
        clone.id = element.id + "V";
        parent.appendChild(clone);
        return clone;
    },
    CreateLoadingPanelInsideContainer: function(parentElement) {
        if(parentElement == null) return null;
        this.HideLoadingPanel();

        var element = this.GetLoadingPanelElement();
        if (element != null){
            var width = 0;
            var height = 0;
            var itemsTable = _aspxGetChildByTagName(parentElement, "TABLE", 0);
            if(itemsTable != null) {
                width = itemsTable.offsetWidth;
                height = itemsTable.offsetHeight;
            } else if(parentElement.childNodes.length == 0){
                var dummyDiv = document.createElement("DIV");
                parentElement.appendChild(dummyDiv);
                width = dummyDiv.offsetWidth;
            } else {
                width = parentElement.clientWidth;
                height = parentElement.clientHeight;
            }
            parentElement.innerHTML = "";
            
            var table = document.createElement("TABLE");
            parentElement.appendChild(table);
            table.border = 0;
            table.cellPadding = 0;
            table.cellSpacing = 0;
            table.style.height = (height > 0) ? height + "px" : "100%";
            table.style.width = (width > 0) ? width + "px" : "100%";
            var tbody = document.createElement("TBODY");
            table.appendChild(tbody);
            var tr = document.createElement("TR");
            tbody.appendChild(tr);
            var td = document.createElement("TD");
            tr.appendChild(td);
            td.align = "center";
            td.vAlign = "middle";
            
            element = this.CloneLoadingPanel(element, td);
            _aspxSetElementDisplay(element, true);
            this.loadingPanelElement = element;
            return element;
        } else
            parentElement.innerHTML = "&nbsp;";
        return null;
    },
    CreateLoadingPanelWithAbsolutePosition: function(parentElement, offsetElement) {
        if(parentElement == null) return null;
        this.HideLoadingPanel();
        
        if(!_aspxIsExists(offsetElement))
            offsetElement = parentElement;
        var element = this.GetLoadingPanelElement();
        if(element != null) {
            element = this.CloneLoadingPanel(element, parentElement);
            element.style.position = "absolute";
            _aspxSetElementDisplay(element, true);
            this.SetLoadingPanelLocation(offsetElement, element);
            this.loadingPanelElement = element;
            return element;
        }
        return null;
    },
    CreateLoadingPanelInline: function(parentElement){
        if(parentElement == null) return null;
        this.HideLoadingPanel();

        var element = this.GetLoadingPanelElement();
        if(element != null) {
            element = this.CloneLoadingPanel(element, parentElement);
            _aspxSetElementDisplay(element, true);
            this.loadingPanelElement = element;
            return element;
        }
        return null;
    },
    HideLoadingPanel: function() {
        if(_aspxIsExistsElement(this.loadingPanelElement)) {
            _aspxRemoveElement(this.loadingPanelElement);
            this.loadingPanelElement = null;
        }
    },
    SetLoadingPanelLocation: function(offsetElement, loadingPanel, x, y, offsetX, offsetY) {
        if(!_aspxIsExists(x) || !_aspxIsExists(y)){
            var x1 = _aspxGetAbsoluteX(offsetElement) - _aspxGetIEDocumentClientOffset(true);
            var y1 = _aspxGetAbsoluteY(offsetElement) - _aspxGetIEDocumentClientOffset(false);
            var x2 = x1;
            var y2 = y1;
            if(offsetElement == document.body){
                x2 += _aspxGetDocumentMaxClientWidth();
                y2 += _aspxGetDocumentMaxClientHeight();
            }
            else{
                x2 += offsetElement.offsetWidth;
                y2 += offsetElement.offsetHeight;
            }
            if(x1 < _aspxGetDocumentScrollLeft())
                x1 = _aspxGetDocumentScrollLeft();
            if(y1 < _aspxGetDocumentScrollTop())
                y1 = _aspxGetDocumentScrollTop();
            if(x2 > _aspxGetDocumentScrollLeft() + _aspxGetDocumentClientWidth())
                x2 = _aspxGetDocumentScrollLeft() + _aspxGetDocumentClientWidth();
            if(y2 > _aspxGetDocumentScrollTop() + _aspxGetDocumentClientHeight())
                y2 = _aspxGetDocumentScrollTop() + _aspxGetDocumentClientHeight();

            x = x1 + ((x2 - x1 - loadingPanel.offsetWidth) / 2);
            y = y1 + ((y2 - y1 - loadingPanel.offsetHeight) / 2);
        }
        if(_aspxIsExists(offsetX) && _aspxIsExists(offsetY)){
            x += offsetX;
            y += offsetY;
        }
        loadingPanel.style.left = _aspxPrepareClientPosForElement(x, loadingPanel, true) + "px";
        loadingPanel.style.top = _aspxPrepareClientPosForElement(y, loadingPanel, false) + "px";
    },
    
    GetLoadingDiv: function(){
        return _aspxGetElementById(this.name + "_LD");
    },
    CreateLoadingDiv: function(parentElement, offsetElement){
        if(parentElement == null) return null;
        this.HideLoadingDiv();
    
        if(!_aspxIsExists(offsetElement))
            offsetElement = parentElement;
        var div = this.GetLoadingDiv();
        if(div != null){
            div = div.cloneNode(true);
            parentElement.appendChild(div);
            _aspxSetElementDisplay(div, true);
            this.SetLoadingDivBounds(offsetElement, div);
            this.loadingDivElement = div;
            return div;
        }
        return null;
    },
    SetLoadingDivBounds: function(offsetElement, loadingDiv) {
        var absX = (offsetElement == document.body) ? 0 : _aspxGetAbsoluteX(offsetElement);
        var absY = (offsetElement == document.body) ? 0 : _aspxGetAbsoluteY(offsetElement);
        loadingDiv.style.left = _aspxPrepareClientPosForElement(absX, loadingDiv, true) + "px";
        loadingDiv.style.top = _aspxPrepareClientPosForElement(absY, loadingDiv, false) + "px";
        var width = (offsetElement == document.body) ? _aspxGetDocumentWidthWithoutScroll() : offsetElement.offsetWidth;
        var height = (offsetElement == document.body) ? _aspxGetDocumentHeight() : offsetElement.offsetHeight;
        _aspxSetStyleSize(loadingDiv, width, height);    
        var correctedWidth = 2 * width - loadingDiv.offsetWidth;
        if(correctedWidth <= 0) correctedWidth = width;
        var correctedHeight = 2 * height - loadingDiv.offsetHeight;
        if(correctedHeight <= 0) correctedHeight = height;
        _aspxSetStyleSize(loadingDiv, correctedWidth, correctedHeight);
    },
    HideLoadingDiv: function() {
        if(_aspxIsExistsElement(this.loadingDivElement)){
            _aspxRemoveElement(this.loadingDivElement);
            this.loadingDivElement = null;
        }
    },

    RaiseInit: function(){
        if(!this.Init.IsEmpty()){
            var args = new ASPxClientEventArgs();
            this.Init.FireEvent(this, args);
        }
    },
    RaiseBeginCallback: function(command){
        if(!this.BeginCallback.IsEmpty()){
            var args = new ASPxClientBeginCallbackEventArgs(command);
            this.BeginCallback.FireEvent(this, args);
        }
        if(_aspxIsExistsType(typeof(aspxGetGlobalEvents)))
            aspxGetGlobalEvents().OnBeginCallback(this, command);
    },
    RaiseEndCallback: function(){
        if(!this.EndCallback.IsEmpty()){
            var args = new ASPxClientEndCallbackEventArgs();
            this.EndCallback.FireEvent(this, args);
        }
        if(_aspxIsExistsType(typeof(aspxGetGlobalEvents)))
            aspxGetGlobalEvents().OnEndCallback(this);
    },
    RaiseCallbackError: function(message) {
        if(!this.CallbackError.IsEmpty()) {
            var args = new ASPxClientCallbackErrorEventArgs(message);
            this.CallbackError.FireEvent(this, args);
            if(args.handled)
                return { isHandled: true, errorMessage: args.message };
        }
        if(_aspxIsExistsType(typeof(aspxGetGlobalEvents))) {
            var args = new ASPxClientCallbackErrorEventArgs(message);
            aspxGetGlobalEvents().OnCallbackError(this, args);
            if(args.handled)
                return { isHandled: true, errorMessage: args.message };
        }
        return { isHandled: false, errorMessage: message };
    },
    IsVisible: function() {
        var element = this.GetMainElement();
        while(_aspxIsExists(element) && element.tagName != "BODY") {
            if (!_aspxGetElementVisibility(element) || !_aspxGetElementDisplay(element))
                return false;
            element = element.parentNode;
        }
        return true;
    },
    IsDisplayed: function() {
        var element = this.GetMainElement();
        while(_aspxIsExists(element) && element.tagName != "BODY") {
            if(!_aspxGetElementDisplay(element)) 
                return false;
            element = element.parentNode;
        }
        return true;
    },
    Focus: function() {
    
    },    
    GetClientVisible: function(){
        return this.GetVisible();
    },
    SetClientVisible: function(visible){
        this.SetVisible(visible);
    },    
    GetVisible: function(){
        return this.clientVisible;
    },
    SetVisible: function(visible){
        if(this.clientVisible != visible){
            this.clientVisible = visible;
            _aspxSetElementDisplay(this.GetMainElement(), visible);
            if (visible) {
                this.AdjustControl(__aspxCheckSizeCorrectedFlag);
                
                var mainElement = this.GetMainElement();
                if (_aspxIsExists(mainElement))
                    aspxGetControlCollection().AdjustControls(mainElement, __aspxCheckSizeCorrectedFlag);
            }
        }
    },        
    InCallback: function() {
        return this.requestCount > 0;
    },
    DoBeginCallback: function(command) {
        if(!_aspxIsExists(command)) command = "";
        this.RaiseBeginCallback(command);    

        aspxGetControlCollection().Before_WebForm_InitCallback();
        if(_aspxIsExistsType(typeof(WebForm_InitCallback)) && _aspxIsExists(WebForm_InitCallback)) {
            __theFormPostData = "";
            __theFormPostCollection = new Array();
            this.ClearPostBackEventInput("__EVENTTARGET");
            this.ClearPostBackEventInput("__EVENTARGUMENT");
            WebForm_InitCallback();
            this.savedFormPostData = __theFormPostData;            
            this.savedFormPostCollection = __theFormPostCollection;
        }
    },
    ClearPostBackEventInput: function(id){
        var element = _aspxGetElementById(id);
        if(element != null) element.value = "";
    },
    CreateCallback: function(arg, command) {
        if(_aspxIsExistsType(typeof(WebForm_DoCallback)) && _aspxIsExists(WebForm_DoCallback)) 
            this.CreateCallbackInternal(arg, command, true);
        else {
            if(!_aspxIsExists(this.savedCallbacks))
                this.savedCallbacks = [];
            this.savedCallbacks.push([arg, command]);
        }
    },
    CreateCallbackInternal: function(arg, command, viaTimer) {
        if(!this.CanCreateCallback()) 
            return;

        this.requestCount++;
        this.DoBeginCallback(command);
        
        if(typeof(arg) == "undefined")
            arg = "";
        if(typeof(command) == "undefined")
            command = "";
            
        if(viaTimer)
            window.setTimeout("aspxCreateCallback('" + this.name + "', '" + escape(arg) + "', '" + escape(command) + "');", 0);
        else
            this.CreateCallbackCore(arg, command);
    },
    CreateCallbackCore: function(arg, command) {
        __theFormPostData = this.savedFormPostData;
        __theFormPostCollection = this.savedFormPostCollection;
        this.callBack(arg);    
    },
    CanCreateCallback: function() {
        return this.allowMultipleCallbacks || !this.InCallback();
    },
    DoLoadCallbackScripts: function() {
        _aspxProcessScriptsAndLinks(this.name);
    },
    DoEndCallback: function(){
        this.RaiseEndCallback();
    },
    DoFinalizeCallback: function() {
    },
    HideLoadingPanelOnCallback: function() {
        return true;
    },
    DoCallback: function(result) {
        this.requestCount--;
        if(this.HideLoadingPanelOnCallback()) {
            this.HideLoadingDiv();
            this.HideLoadingPanel();
        }
        if(result.indexOf(__aspxCallbackResultPrefix) != 0) 
            this.ProcessCallbackGeneralError(result);
        else {
            var resultObj = null;
            try {
                resultObj = eval(result);
            } 
            catch(e) {
                // B36430
            }
            if(_aspxIsExists(resultObj)){
                if(_aspxIsExists(resultObj.redirect))
                    window.location.href = resultObj.redirect;
                else if(_aspxIsExists(resultObj.generalError))
                    this.ProcessCallbackGeneralError(resultObj.generalError);
                else {
                    var errorObj = resultObj.error;
                    if(_aspxIsExists(errorObj))
                        this.ProcessCallbackError(errorObj);
                    else {
                        if(resultObj.cp) {
                            for(var name in resultObj.cp)
                                this[name] = resultObj.cp[name];
                        }
                        this.ProcessCallback(resultObj.result);
                    }
                    this.DoLoadCallbackScripts();
                }
            } 
        }
    },
    DoCallbackError: function(result) {
        this.HideLoadingDiv();
        this.HideLoadingPanel();
        this.OnCallbackGeneralError(result);
    },
    DoControlClick: function(evt) {
        this.OnControlClick(_aspxGetEventSource(evt), evt);
    },
    ProcessCallback: function(result) {
        this.OnCallback(result);
    },
    OnCallback: function(result) {

    },
    ProcessCallbackError: function(errorObj) {
        var data = _aspxIsExists(errorObj.data) ? errorObj.data : null;
        var result = this.RaiseCallbackError(errorObj.message);
        if(!result.isHandled)
            this.OnCallbackError(result.errorMessage, data);
    },
    OnCallbackError: function(errorMessage, data) {
        if(errorMessage)
            alert(errorMessage);
    },
    ProcessCallbackGeneralError: function(errorMessage) {
        var result = this.RaiseCallbackError(errorMessage);
        if(!result.isHandled)
            this.OnCallbackGeneralError(result.errorMessage);
    },
    OnCallbackGeneralError: function(errorMessage) {
        this.OnCallbackError(errorMessage, null);
    },

    SendPostBack: function(params) {
        __doPostBack(this.uniqueID, params);
    }
});

// Identification

ASPxIdent = { };

ASPxIdent.IsDate = function(obj) {
    return _aspxIsExists(obj) && obj.constructor == Date;
};
ASPxIdent.IsRegExp = function(obj) {
    return _aspxIsExists(obj) && obj.constructor === RegExp;
};
ASPxIdent.IsArray = function(obj) {
    return _aspxIsExists(obj) && obj.constructor == Array;
};
ASPxIdent.IsASPxClientControl = function(obj) {
    return obj != null && _aspxIsExists(obj.isASPxClientControl) && obj.isASPxClientControl;
};
ASPxIdent.IsASPxClientEdit = function(obj) {
    return _aspxIsExists(obj.isASPxClientEdit) && obj.isASPxClientEdit;
};
ASPxClientControl.GetControlCollection = function(){
    return aspxGetControlCollection();
}

var __aspxControlCollection = null;
function aspxGetControlCollection(){
    if(__aspxControlCollection == null)
        __aspxControlCollection = new ASPxClientControlCollection();
    return __aspxControlCollection;
}

function aspxCAInit(){
    aspxGetControlCollection().AtlasInitialize();
}
function aspxCreateCallback(name, arg, command){
    var control = aspxGetControlCollection().Get(name);
    if(control != null)
        control.CreateCallbackCore(unescape(arg), unescape(command));
}
function aspxCallback(result, context){
    var collection = aspxGetControlCollection();
    collection.DoFinalizeCallback();
    var control = collection.Get(context);
    if(control != null)
        control.DoCallback(result);
}
function aspxCallbackError(result, context){
    var control = aspxGetControlCollection().Get(context);
    if(control != null)
        control.DoCallbackError(result, false);
}

function aspxCClick(name, evt) {
    var control = aspxGetControlCollection().Get(name);
    if(control != null) control.DoControlClick(evt);
}

//StateController
var __aspxStateItemsExist = false;
var __aspxHoverStyleSheet = null;
var __aspxPressedStyleSheet = null;
var __aspxSelectedStyleSheet = null;
var __aspxDisabledStyleSheet = null;
var __aspxFocusedItemKind = "FocusedStateItem";
var __aspxHoverItemKind = "HoverStateItem";
var __aspxPressedItemKind = "PressedStateItem";
var __aspxSelectedItemKind = "SelectedStateItem";
var __aspxDisabledItemKind = "DisabledStateItem";
var __aspxStyleCount = 0;
var __aspxStyleNameCache = new Object();

ASPxStateItem = _aspxCreateClass(null, {
    constructor: function(name, className, cssText, postfixes, imageUrls, imagePostfixes, kind){
        this.name = name;
        this.className = className;
        this.customClassName = "";
        this.resultClassName = "";
        this.cssText = cssText;
        this.postfixes = postfixes;
        this.imageUrls = imageUrls;
        this.imagePostfixes = imagePostfixes;
        this.kind = kind;
        this.enabled = true;
        
        this.elements = null;
        this.images = null;
        this.linkColor = null;
        this.lintTextDecoration = null;
    },
    
    CreateStyleRule: function(){
        if(this.cssText == "") return "";
        
        var styleSheet = this.GetStyleSheet();
        if(_aspxIsExists(styleSheet)){
            if(_aspxIsExists(__aspxStyleNameCache[this.cssText]))
                return __aspxStyleNameCache[this.cssText];
            else{ 
                var cssText = "";
                var attributes = this.cssText.split(";");
                for(var i = 0; i < attributes.length; i++){
                    if(attributes[i] != "")
                        cssText += attributes[i] + " !important;";
                }
                var className = "dxh" + __aspxStyleCount;
                _aspxAddStyleSheetRule(styleSheet, "." + className, cssText);
                __aspxStyleCount++;
                __aspxStyleNameCache[this.cssText] = className;
                return className;
            }
        }
        return ""; 
    },
    GetResultClassName: function(){
        if(this.resultClassName == ""){
        if(this.customClassName == "")
            this.customClassName = this.CreateStyleRule();
            if(this.className != "" && this.customClassName != "")
                this.resultClassName = this.className + " " + this.customClassName;
            else if(this.className != "")
                this.resultClassName = this.className;
            else if(this.customClassName != "")
                this.resultClassName = this.customClassName;
        }
        return this.resultClassName;
    },
    GetStyleSheet: function(){
        if(!_aspxIsExists(__aspxDisabledStyleSheet))
            __aspxDisabledStyleSheet = _aspxCreateStyleSheet();
        if(!_aspxIsExists(__aspxSelectedStyleSheet))
            __aspxSelectedStyleSheet = _aspxCreateStyleSheet();
        if(!_aspxIsExists(__aspxHoverStyleSheet))
            __aspxHoverStyleSheet = _aspxCreateStyleSheet();
        if(!_aspxIsExists(__aspxPressedStyleSheet))
            __aspxPressedStyleSheet = _aspxCreateStyleSheet();
        switch(this.kind){
            case __aspxDisabledItemKind:
                return __aspxDisabledStyleSheet;
            case __aspxHoverItemKind:
                return __aspxHoverStyleSheet;
            case __aspxPressedItemKind:
                return __aspxPressedStyleSheet;
            case __aspxSelectedItemKind:
                return __aspxSelectedStyleSheet;
        }
        return null;
    },
    GetElements: function(element){
        if(!_aspxIsExists(this.elements) || !_aspxIsValidElements(this.elements)){
            if(_aspxIsExists(this.postfixes) && this.postfixes.length > 0){
                this.elements = new Array();
                var parentNode = element.parentNode;
                if(_aspxIsExists(parentNode)){
                    for(var i = 0; i < this.postfixes.length; i++){
                        var id = this.name + this.postfixes[i];
                        this.elements[i] = _aspxGetChildById(parentNode, id);
                        if(!_aspxIsExists(this.elements[i]))
                            this.elements[i] = _aspxGetElementById(id);
                    }
                }
            }
            else
                this.elements = [element];
        }
        return this.elements;
    },
    GetImages: function(element){
        if(!_aspxIsExists(this.images) || !_aspxIsValidElements(this.images)){
            this.images = new Array();
            if(_aspxIsExists(this.imagePostfixes) && this.imagePostfixes.length > 0){
                var elements = this.GetElements(element);
                for(var i = 0; i < this.imagePostfixes.length; i++){
                    var id = this.name + this.imagePostfixes[i];
                    for(var j = 0; j < elements.length; j++){
                        if(!_aspxIsExists(elements[j])) continue;
                        
                        this.images[i] = _aspxGetChildById(elements[j], id);
                        if(_aspxIsExists(this.images[i]))
                            break;
                    }
                }
            }
        }
        return this.images;
    },
    
    Apply: function(element){
        if(!this.enabled) return;
        try{
            this.ApplyStyle(element);
            if(_aspxIsExists(this.imageUrls) && this.imageUrls.length > 0)
                this.ApplyImage(element);
        }
        catch(e){
            // fix FF bug
        }
    },
    ApplyStyle: function(element){
        var elements = this.GetElements(element);
        for(var i = 0; i < elements.length; i++){
            if(!_aspxIsExists(elements[i])) continue;

            var className = elements[i].className.replace(this.GetResultClassName(), "");
            elements[i].className = _aspxTrim(className) + " " + this.GetResultClassName();
            if(!__aspxOpera || __aspxOpera9)
                this.ApplyStyleToLinks(elements, i);
        }
    },
    ApplyStyleToLinks: function(elements, index){
        var linkCount = 0;
        var savedLinkCount = -1;
        if(_aspxIsExists(elements[index]["savedLinkCount"]))
            savedLinkCount = parseInt(elements[index]["savedLinkCount"]);
        do{
            if(savedLinkCount > -1 && savedLinkCount <= linkCount)
                break;
            var link = elements[index]["link" + linkCount];
            if(!_aspxIsExists(link)){
                link = _aspxGetChildByTagName(elements[index], "A", linkCount);
                if(!_aspxIsExists(link))
                    link = _aspxGetChildByTagName(elements[index], "SPAN", linkCount); // see InternalHyperLink
                if(_aspxIsExists(link))
                    elements[index]["link" + linkCount] = link;
            }
            if(_aspxIsExists(link))
                this.ApplyStyleToLinkElement(link);
            else
                elements[index]["savedLinkCount"] = linkCount;
            linkCount++;
        }
        while(link != null)
    },
    ApplyStyleToLinkElement: function(link){
        if(this.GetLinkColor() != "")
            _aspxChangeAttributeExtended(link.style, "color", link, "saved" + this.kind + "Color", this.GetLinkColor());
        if(this.GetLinkTextDecoration() != "")
            _aspxChangeAttributeExtended(link.style, "textDecoration", link, "saved" + this.kind + "TextDecoration", this.GetLinkTextDecoration());
    },
    ApplyImage: function(element){
        var images = this.GetImages(element);
        for(var i = 0; i < images.length; i++){
            if(!_aspxIsExists(images[i]) || !_aspxIsExists(this.imageUrls[i]) || this.imageUrls[i] == "") continue;
            if(_aspxIsAlphaFilterUsed(images[i]))            
                _aspxChangeAttributeExtended(images[i].style, "filter", images[i], "saved" + this.kind + "Filter", 
                    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + this.imageUrls[i] + ", sizingMethod=scale)");                
            else
                _aspxChangeAttributeExtended(images[i], "src", images[i], "saved" + this.kind + "Src", this.imageUrls[i]);
        }
    },
    Cancel: function(element){
        if(!this.enabled) return;
        try{        
            this.CancelStyle(element);
            if(_aspxIsExists(this.imageUrls) && this.imageUrls.length > 0)
            this.CancelImage(element);
        }
        catch(e){
            // fix FF bug
        }
    },
    CancelStyle: function(element){
        var elements = this.GetElements(element);
        for(var i = 0; i < elements.length; i++){
            if(!_aspxIsExists(elements[i])) continue;
            
            var className = _aspxTrim(elements[i].className.replace(this.GetResultClassName(), ""));
            elements[i].className = className;
            if(!__aspxOpera || __aspxOpera9)
                this.CancelStyleFromLinks(elements, i);
        }
    },
    CancelStyleFromLinks: function(elements, index){
        var linkCount = 0;
        var savedLinkCount = -1;
        if(_aspxIsExists(elements[index]["savedLinkCount"]))
            savedLinkCount = parseInt(elements[index]["savedLinkCount"]);
        do{
            if(savedLinkCount > -1 && savedLinkCount <= linkCount)
                break;
            var link = elements[index]["link" + linkCount];
            if(!_aspxIsExists(link)){
                link = _aspxGetChildByTagName(elements[index], "A", linkCount);
                if(!_aspxIsExists(link))
                    link = _aspxGetChildByTagName(elements[index], "SPAN", linkCount); // see InternalHyperLink
                if(_aspxIsExists(link))
                    elements[index]["link" + linkCount] = link;
            }
            if(_aspxIsExists(link))
                this.CancelStyleFromLinkElement(link);
            else
                elements[index]["savedLinkCount"] = linkCount;
            linkCount++;
        }
        while(link != null)
    },
    CancelStyleFromLinkElement: function(link){
        if(this.GetLinkColor() != "")
            _aspxRestoreAttributeExtended(link.style, "color", link, "saved" + this.kind + "Color");
        if(this.GetLinkTextDecoration() != "")
            _aspxRestoreAttributeExtended(link.style, "textDecoration", link, "saved" + this.kind + "TextDecoration");
    },
    CancelImage: function(element){
        var images = this.GetImages(element);
        for(var i = 0; i < images.length; i++){
            if(!_aspxIsExists(images[i]) || !_aspxIsExists(this.imageUrls[i]) || this.imageUrls[i] == "") continue;
            if(_aspxIsAlphaFilterUsed(images[i]))
                _aspxRestoreAttributeExtended(images[i].style, "filter", images[i], "saved" + this.kind + "Filter");
            else
                _aspxRestoreAttributeExtended(images[i], "src", images[i], "saved" + this.kind + "Src");
        }
    },
    Clone: function(){
        return new ASPxStateItem(this.name, this.className, this.cssText, this.postfixes, 
            this.imageUrls, this.imagePostfixes, this.kind);
    },
    IsChildElement: function(element){
        if(element != null){
            var elements = this.GetElements(element);
            for(var i = 0; i < elements.length; i++){
                if(!_aspxIsExists(elements[i])) continue;
                if(_aspxGetIsParent(elements[i], element)) 
                    return true;
            }
        }
        return false;
    },
    
    GetLinkColor: function(){
        if(!_aspxIsExists(this.linkColor)){
            var rule = _aspxGetStyleSheetRule(this.customClassName);
            this.linkColor = _aspxIsExists(rule) ? rule.style.color : null;
            if(!_aspxIsExists(this.linkColor)){
                var rule = _aspxGetStyleSheetRule(this.className);
                this.linkColor = _aspxIsExists(rule) ? rule.style.color : null;
            }
            if(this.linkColor == null) 
                this.linkColor = "";
        }
        return this.linkColor;
    },
    GetLinkTextDecoration: function(){
        if(!_aspxIsExists(this.linkTextDecoration)){
            var rule = _aspxGetStyleSheetRule(this.customClassName);
            this.linkTextDecoration = _aspxIsExists(rule) ? rule.style.textDecoration : null;
            if(!_aspxIsExists(this.linkTextDecoration)){
                var rule = _aspxGetStyleSheetRule(this.className);
                this.linkTextDecoration = _aspxIsExists(rule) ? rule.style.textDecoration : null;
            }
            if(this.linkTextDecoration == null) 
                this.linkTextDecoration = "";
        }
        return this.linkTextDecoration;
    }
});

ASPxClientStateEventArgs = _aspxCreateClass(null, {
    constructor: function(item, element){
        this.item = item;
        this.element = element;
        this.toElement = null;
        this.fromElement = null;
        this.htmlEvent = null;
    }
});

ASPxStateController = _aspxCreateClass(null, {
    constructor: function(){
        this.focusedItems = new Object();
        this.hoverItems = new Object();
        this.pressedItems = new Object();
        this.selectedItems = new Object();
        this.disabledItems = new Object();
        
        this.currentFocusedElement = null;
        this.currentFocusedItemName = null;
        this.currentHoverElement = null;
        this.currentHoverItemName = null;
        this.currentPressedElement = null;
        this.currentPressedItemName = null;
        this.savedCurrentPressedElement = null;
        this.savedCurrentMouseMoveSrcElement = null;
        
        this.AfterSetFocusedState = new ASPxClientEvent();
        this.AfterClearFocusedState = new ASPxClientEvent();
        this.AfterSetHoverState = new ASPxClientEvent();
        this.AfterClearHoverState = new ASPxClientEvent();
        this.AfterSetPressedState = new ASPxClientEvent();
        this.AfterClearPressedState = new ASPxClientEvent();
        this.AfterDisabled = new ASPxClientEvent();
        this.AfterEnabled = new ASPxClientEvent();
        this.BeforeSetFocusedState = new ASPxClientEvent();
        this.BeforeClearFocusedState = new ASPxClientEvent();
        this.BeforeSetHoverState = new ASPxClientEvent();
        this.BeforeClearHoverState = new ASPxClientEvent();
        this.BeforeSetPressedState = new ASPxClientEvent();
        this.BeforeClearPressedState = new ASPxClientEvent();
        this.BeforeDisabled = new ASPxClientEvent();
        this.BeforeEnabled = new ASPxClientEvent();
        this.FocusedItemKeyDown = new ASPxClientEvent();
    },    
    AddHoverItem: function(name, className, cssText, postfixes, imageUrls, imagePostfixes){
        this.AddItem(this.hoverItems, name, className, cssText, postfixes, imageUrls, imagePostfixes, __aspxHoverItemKind);
        this.AddItem(this.focusedItems, name, className, cssText, postfixes, imageUrls, imagePostfixes, __aspxFocusedItemKind);
    },
    AddPressedItem: function(name, className, cssText, postfixes, imageUrls, imagePostfixes){
        this.AddItem(this.pressedItems, name, className, cssText, postfixes, imageUrls, imagePostfixes, __aspxPressedItemKind);
    },
    AddSelectedItem: function(name, className, cssText, postfixes, imageUrls, imagePostfixes){
        this.AddItem(this.selectedItems, name, className, cssText, postfixes, imageUrls, imagePostfixes, __aspxSelectedItemKind);
    },
    AddDisabledItem: function(name, className, cssText, postfixes, imageUrls, imagePostfixes){
        this.AddItem(this.disabledItems, name, className, cssText, postfixes, imageUrls, imagePostfixes, __aspxDisabledItemKind);
    },
    AddItem: function(items, name, className, cssText, postfixes, imageUrls, imagePostfixes, kind){
        var stateItem = new ASPxStateItem(name, className, cssText, postfixes, imageUrls, imagePostfixes, kind);
        if(_aspxIsExists(postfixes) && postfixes.length > 0){
            for(var i = 0; i < postfixes.length; i ++){
                items[name + postfixes[i]] = stateItem;
            }
        }
        else
            items[name] = stateItem;
        __aspxStateItemsExist = true;
    },
    
    GetFocusedElement: function(srcElement){
        return this.GetItemElement(srcElement, this.focusedItems, __aspxFocusedItemKind);
    },
    GetHoverElement: function(srcElement){
        return this.GetItemElement(srcElement, this.hoverItems, __aspxHoverItemKind);
    },
    GetPressedElement: function(srcElement){
        return this.GetItemElement(srcElement, this.pressedItems, __aspxPressedItemKind);
    },
    GetSelectedElement: function(srcElement){
        return this.GetItemElement(srcElement, this.selectedItems, __aspxSelectedItemKind);
    },
    GetDisabledElement: function(srcElement){
        return this.GetItemElement(srcElement, this.disabledItems, __aspxDisabledItemKind);
    },
    GetItemElement: function(srcElement, items, kind){
        if(_aspxIsExists(srcElement) && _aspxIsExists(srcElement["cached" + kind])){
            var cachedElement = srcElement["cached" + kind];
            if(cachedElement != __aspxEmptyCachedValue)
                return cachedElement;
            return null;
        }
            
        var element = srcElement;
        while(element != null) {
            var item = items[element.id];
            if(_aspxIsExists(item)){
                this.CacheItemElement(srcElement, kind, element);
                element[kind] = item;
                return element;
            }
            element = element.parentNode;
        }
        this.CacheItemElement(srcElement, kind, __aspxEmptyCachedValue);
        return null;
    },
    CacheItemElement: function(srcElement, kind, value){
        if(_aspxIsExists(srcElement) && !_aspxIsExists(srcElement["cached" + kind]))
            srcElement["cached" + kind] = value;
    },
        
    DoSetFocusedState: function(element, fromElement){
        var item = element[__aspxFocusedItemKind];
        if(_aspxIsExists(item)){
            var args = new ASPxClientStateEventArgs(item, element);
            args.fromElement = fromElement;
            this.BeforeSetFocusedState.FireEvent(this, args);
            item.Apply(element);
            this.AfterSetFocusedState.FireEvent(this, args);
        }
    },
    DoClearFocusedState: function(element, toElement){
        var item = element[__aspxFocusedItemKind];
        if(_aspxIsExists(item)){
            var args = new ASPxClientStateEventArgs(item, element);
            args.toElement = toElement;
            this.BeforeClearFocusedState.FireEvent(this, args);
            item.Cancel(element);
            this.AfterClearFocusedState.FireEvent(this, args);
        }
    },
    DoSetHoverState: function(element, fromElement){
        var item = element[__aspxHoverItemKind];
        if(_aspxIsExists(item)){
            var args = new ASPxClientStateEventArgs(item, element);
            args.fromElement = fromElement;
            this.BeforeSetHoverState.FireEvent(this, args);
            item.Apply(element);
            this.AfterSetHoverState.FireEvent(this, args);
        }
    },
    DoClearHoverState: function(element, toElement){
        var item = element[__aspxHoverItemKind];
        if(_aspxIsExists(item)){
            var args = new ASPxClientStateEventArgs(item, element);
            args.toElement = toElement;
            this.BeforeClearHoverState.FireEvent(this, args);
            item.Cancel(element);
            this.AfterClearHoverState.FireEvent(this, args);
        }
    },
    DoSetPressedState: function(element){
        var item = element[__aspxPressedItemKind];
        if(_aspxIsExists(item)){
            var args = new ASPxClientStateEventArgs(item, element);
            this.BeforeSetPressedState.FireEvent(this, args);
            item.Apply(element);
            this.AfterSetPressedState.FireEvent(this, args);
        }
    },
    DoClearPressedState: function(element){
        var item = element[__aspxPressedItemKind];
        if(_aspxIsExists(item)){
            var args = new ASPxClientStateEventArgs(item, element);
            this.BeforeClearPressedState.FireEvent(this, args);
            item.Cancel(element);
            this.AfterClearPressedState.FireEvent(this, args);
        }
    },
    SetCurrentFocusedElement: function(element){
        if(_aspxIsExists(this.currentFocusedElement) && !_aspxIsValidElement(this.currentFocusedElement)){
            this.currentFocusedElement = null;
            this.currentFocusedItemName = "";
        }
        if(this.currentFocusedElement != element){
            var oldCurrentFocusedElement = this.currentFocusedElement;
            var item = (element != null) ? element[__aspxFocusedItemKind] : null;
            var itemName = (item != null) ? item.name : "";
            if(this.currentFocusedItemName != itemName){
                if(this.currentHoverItemName != "")
                    this.SetCurrentHoverElement(null);
                    
                if(this.currentFocusedElement != null)
                    this.DoClearFocusedState(this.currentFocusedElement, element);
                this.currentFocusedElement = element;
                item = (element != null) ? element[__aspxFocusedItemKind] : null;
                this.currentFocusedItemName = (item != null) ? item.name : "";
                if(this.currentFocusedElement != null)
                    this.DoSetFocusedState(this.currentFocusedElement, oldCurrentFocusedElement);
            }
        }
    },
    SetCurrentHoverElement: function(element){
        if(_aspxIsExists(this.currentHoverElement) && !_aspxIsValidElement(this.currentHoverElement)){
            this.currentHoverElement = null;
            this.currentHoverItemName = "";
        }
        if(this.currentHoverElement != element){
            var oldCurrentHoverElement = this.currentHoverElement;
            var item = (element != null) ? element[__aspxHoverItemKind] : null;
            var itemName = (item != null) ? item.name : "";
            if(this.currentHoverItemName != itemName){
                if(this.currentFocusedItemName != "")
                    this.SetCurrentFocusedElement(null);

                if(this.currentHoverElement != null)
                    this.DoClearHoverState(this.currentHoverElement, element);
                this.currentHoverElement = element;
                item = (element != null) ? element[__aspxHoverItemKind] : null;
                this.currentHoverItemName = (item != null) ? item.name : "";
                if(this.currentHoverElement != null)
                    this.DoSetHoverState(this.currentHoverElement, oldCurrentHoverElement);
            }
        }
    },
    SetCurrentPressedElement: function(element){
        if(_aspxIsExists(this.currentPressedElement) && !_aspxIsValidElement(this.currentPressedElement)){
            this.currentPressedElement = null;
            this.currentPressedItemName = "";
        }
            
        if(this.currentPressedElement != element){
            if(this.currentPressedElement != null)
                this.DoClearPressedState(this.currentPressedElement);
            this.currentPressedElement = element;
            var item = (element != null) ? element[__aspxPressedItemKind] : null;
            this.currentPressedItemName = (item != null) ? item.name : "";
            if(this.currentPressedElement != null)
                this.DoSetPressedState(this.currentPressedElement);
        }
    },
    SetCurrentFocusedElementBySrcElement: function(srcElement){
        var element = this.GetFocusedElement(srcElement);
        this.SetCurrentFocusedElement(element);
    },
    SetCurrentHoverElementBySrcElement: function(srcElement){
        var element = this.GetHoverElement(srcElement);
        this.SetCurrentHoverElement(element);
    },
    SetCurrentPressedElementBySrcElement: function(srcElement){
        var element = this.GetPressedElement(srcElement);
        this.SetCurrentPressedElement(element);
    },
    SelectElement: function(element){
        var item = element[__aspxSelectedItemKind];
        if(_aspxIsExists(item))
            item.Apply(element);
    },    
    SelectElementBySrcElement: function(srcElement){
        var element = this.GetSelectedElement(srcElement);
        if(element != null) this.SelectElement(element);
    },    
    DeselectElement: function(element){
        var item = element[__aspxSelectedItemKind];
        if(_aspxIsExists(item))
            item.Cancel(element);
    },    
    DeselectElementBySrcElement: function(srcElement){
        var element = this.GetSelectedElement(srcElement);
        if(element != null) this.DeselectElement(element);
    },
    
    SetElementEnabled: function(element, enable){
        if(enable)
            this.EnableElement(element);
        else
            this.DisableElement(element);
    },
    DisableElement: function(element){
        var element = this.GetDisabledElement(element);
        if(element != null) {
            var item = element[__aspxDisabledItemKind];
            if(_aspxIsExists(item)){
                var args = new ASPxClientStateEventArgs(item, element);
                this.BeforeDisabled.FireEvent(this, args);
                if(item.name == this.currentPressedItemName)
                    this.SetCurrentPressedElement(null);
                if(item.name == this.currentHoverItemName)
                    this.SetCurrentHoverElement(null);
                item.Apply(element);
                this.SetMouseStateItemsEnabled(item.name, item.postfixes, false);
                this.AfterDisabled.FireEvent(this, args);
            }
        }
    },    
    EnableElement: function(element){
        var element = this.GetDisabledElement(element);
        if(element != null) {
            var item = element[__aspxDisabledItemKind];
            if(_aspxIsExists(item)){
                var args = new ASPxClientStateEventArgs(item, element);
                this.BeforeEnabled.FireEvent(this, args);
                item.Cancel(element);
                this.SetMouseStateItemsEnabled(item.name, item.postfixes, true);
                this.AfterEnabled.FireEvent(this, args);
            }
        }
    },    
    SetMouseStateItemsEnabled: function(name, postfixes, enabled){   
        if(_aspxIsExists(postfixes) && postfixes.length > 0){
            for(var i = 0; i < postfixes.length; i ++){
                this.SetItemsEnabled(this.hoverItems, name + postfixes[i], enabled);
                this.SetItemsEnabled(this.pressedItems, name + postfixes[i], enabled);
            }
        }
        else{
            this.SetItemsEnabled(this.hoverItems, name, enabled);
            this.SetItemsEnabled(this.pressedItems, name, enabled);
        }        
    },
    SetItemsEnabled: function(items, name, enabled){   
        if(_aspxIsExists(items[name])) items[name].enabled = enabled;
    },
    
    OnFocusMove: function(evt){
        var element = _aspxGetEventSource(evt);
        aspxGetStateController().SetCurrentFocusedElementBySrcElement(element);
    },
    OnMouseMove: function(evt, checkElementChanged){
        var srcElement = _aspxGetEventSource(evt);
        if(checkElementChanged && srcElement == this.savedCurrentMouseMoveSrcElement) return;
        this.savedCurrentMouseMoveSrcElement = srcElement;
        
        if(__aspxIE && !_aspxGetIsLeftButtonPressed(evt) && this.savedCurrentPressedElement != null){
            this.savedCurrentPressedElement = null;
            this.SetCurrentPressedElement(null);
        }
             
        if(this.savedCurrentPressedElement == null)
            this.SetCurrentHoverElementBySrcElement(srcElement);
        else{
            var element = this.GetPressedElement(srcElement);
            if(element != this.currentPressedElement){
                if(element == this.savedCurrentPressedElement)
                    this.SetCurrentPressedElement(this.savedCurrentPressedElement);
                else
                    this.SetCurrentPressedElement(null);
            }
        }
    },
    OnMouseDown: function(evt){
        if(!_aspxGetIsLeftButtonPressed(evt)) return;
        var srcElement = _aspxGetEventSource(evt);
        this.OnMouseDownOnElement(srcElement);
    },
    OnMouseDownOnElement: function(element){
        if(this.GetPressedElement(element) == null) return;
        
        this.SetCurrentHoverElement(null);
        this.SetCurrentPressedElementBySrcElement(element);
        this.savedCurrentPressedElement = this.currentPressedElement;
    },
    OnMouseUp: function(evt){
        var srcElement = _aspxGetEventSource(evt);
        this.OnMouseUpOnElement(srcElement);
    },
    OnMouseUpOnElement: function(element){
        if(this.savedCurrentPressedElement == null) return;
        this.savedCurrentPressedElement = null;
        this.SetCurrentPressedElement(null);
        this.SetCurrentHoverElementBySrcElement(element);
    },
    OnMouseOver: function(evt){
        var element = _aspxGetEventSource(evt);
        if (_aspxIsExists(element) && element.tagName == "IFRAME")
            this.OnMouseMove(evt, true);
    },
    OnKeyDown: function(evt){
        var element = this.GetFocusedElement(_aspxGetEventSource(evt));
        if(element != null && element == this.currentFocusedElement) {
            var item = element[__aspxFocusedItemKind];
            if(_aspxIsExists(item)){
                var args = new ASPxClientStateEventArgs(item, element);
                args.htmlEvent = evt;
                this.FocusedItemKeyDown.FireEvent(this, args);
            }
        }
    },
    OnSelectStart: function(evt){
        if ((this.savedCurrentPressedElement != null) && 
            (!_aspxIsExists(this.savedCurrentPressedElement.needClearSelection)))  {
            _aspxClearSelection();
            return false;
        }
    }
});

var __aspxStateController = null;
function aspxGetStateController(){
    if(__aspxStateController == null)
        __aspxStateController = new ASPxStateController();
    return __aspxStateController;
}

function aspxAddStateItems(method, namePrefix, classes){
    for(var i = 0; i < classes.length; i ++){
        for(var j = 0; j < classes[i][2].length; j ++) {
            var name = namePrefix;
            if(_aspxIsExists(classes[i][2][j]) && classes[i][2][j] != "")
                name += "_" + classes[i][2][j];
            var postfixes = _aspxIsExists(classes[i][3]) ? classes[i][3] : null;
            var imageUrls = _aspxIsExists(classes[i][4]) && _aspxIsExists(classes[i][4][j]) ? classes[i][4][j] : null;
            var imagePostfixes =  _aspxIsExists(classes[i][5]) ? classes[i][5] : null;
            method.call(aspxGetStateController(), name, classes[i][0], classes[i][1], postfixes, imageUrls, imagePostfixes);
        }
    }
}
function aspxAddHoverItems(namePrefix, classes){
    aspxAddStateItems(aspxGetStateController().AddHoverItem, namePrefix, classes);
}
function aspxAddPressedItems(namePrefix, classes){
    aspxAddStateItems(aspxGetStateController().AddPressedItem, namePrefix, classes);
}
function aspxAddSelectedItems(namePrefix, classes){
    aspxAddStateItems(aspxGetStateController().AddSelectedItem, namePrefix, classes);
}
function aspxAddDisabledItems(namePrefix, classes){
    aspxAddStateItems(aspxGetStateController().AddDisabledItem, namePrefix, classes);
}

function aspxAddAfterClearFocusedState(handler){
    aspxGetStateController().AfterClearFocusedState.AddHandler(handler);
}
function aspxAddAfterSetFocusedState(handler){
    aspxGetStateController().AfterSetFocusedState.AddHandler(handler);
}
function aspxAddAfterClearHoverState(handler){
    aspxGetStateController().AfterClearHoverState.AddHandler(handler);
}
function aspxAddAfterSetHoverState(handler){
    aspxGetStateController().AfterSetHoverState.AddHandler(handler);
}
function aspxAddAfterClearPressedState(handler){
    aspxGetStateController().AfterClearPressedState.AddHandler(handler);
}
function aspxAddAfterSetPressedState(handler){
    aspxGetStateController().AfterSetPressedState.AddHandler(handler);
}
function aspxAddAfterDisabled(handler){
    aspxGetStateController().AfterDisabled.AddHandler(handler);
}
function aspxAddAfterEnabled(handler){
    aspxGetStateController().AfterEnabled.AddHandler(handler);
}
function aspxAddBeforeClearFocusedState(handler){
    aspxGetStateController().BeforeClearFocusedState.AddHandler(handler);
}
function aspxAddBeforeSetFocusedState(handler){
    aspxGetStateController().BeforeSetFocusedState.AddHandler(handler);
}
function aspxAddBeforeClearHoverState(handler){
    aspxGetStateController().BeforeClearHoverState.AddHandler(handler);
}
function aspxAddBeforeSetHoverState(handler){
    aspxGetStateController().BeforeSetHoverState.AddHandler(handler);
}
function aspxAddBeforeClearPressedState(handler){
    aspxGetStateController().BeforeClearPressedState.AddHandler(handler);
}
function aspxAddBeforeSetPressedState(handler){
    aspxGetStateController().BeforeSetPressedState.AddHandler(handler);
}
function aspxAddBeforeDisabled(handler){
    aspxGetStateController().BeforeDisabled.AddHandler(handler);
}
function aspxAddBeforeEnabled(handler){
    aspxGetStateController().BeforeEnabled.AddHandler(handler);
}
function aspxAddFocusedItemKeyDown(handler){
    aspxGetStateController().FocusedItemKeyDown.AddHandler(handler);
}

function aspxSetHoverState(element){
    aspxGetStateController().SetCurrentHoverElementBySrcElement(element);
}
function aspxClearHoverState(evt){
    aspxGetStateController().SetCurrentHoverElementBySrcElement(null);
}
function aspxUpdateHoverState(evt){
    aspxGetStateController().OnMouseMove(evt, false);
}
function aspxSetFocusedState(element){
    aspxGetStateController().SetCurrentFocusedElementBySrcElement(element);
}
function aspxClearFocusedState(evt){
    aspxGetStateController().SetCurrentFocusedElementBySrcElement(null);
}
function aspxUpdateFocusedState(evt){
    aspxGetStateController().OnFocusMove(evt);
}

_aspxAttachEventToElement(window, "load", aspxClassesWindowOnLoad);
function aspxClassesWindowOnLoad(evt){
    __aspxDocumentLoaded = true;
    aspxGetControlCollection().Initialize();
    _aspxInitializeScripts();
    _aspxInitializeLinks();
}

_aspxAttachEventToDocument("mousemove", aspxClassesDocumentMouseMove);
function aspxClassesDocumentMouseMove(evt){
    if(__aspxClassesScriptParsed && __aspxStateItemsExist)
        aspxGetStateController().OnMouseMove(evt, true);
}
_aspxAttachEventToDocument("mousedown", aspxClassesDocumentMouseDown);
function aspxClassesDocumentMouseDown(evt){
    if(__aspxClassesScriptParsed && __aspxStateItemsExist)
        aspxGetStateController().OnMouseDown(evt);
}
_aspxAttachEventToDocument("mouseup", aspxClassesDocumentMouseUp);
function aspxClassesDocumentMouseUp(evt){
    if(__aspxClassesScriptParsed && __aspxStateItemsExist)
        aspxGetStateController().OnMouseUp(evt);
}
_aspxAttachEventToDocument("mouseover", aspxClassesDocumentMouseOver);
function aspxClassesDocumentMouseOver(evt){
    if(__aspxClassesScriptParsed && __aspxStateItemsExist)
        aspxGetStateController().OnMouseOver(evt);
}
_aspxAttachEventToDocument("keydown", aspxClassesDocumentKeyDown);
function aspxClassesDocumentKeyDown(evt){
    if(__aspxClassesScriptParsed && __aspxStateItemsExist)
        aspxGetStateController().OnKeyDown(evt);
}
_aspxAttachEventToDocument("selectstart", aspxClassesDocumentSelectStart);
function aspxClassesDocumentSelectStart(evt){
    if(__aspxClassesScriptParsed && __aspxStateItemsExist)
        return aspxGetStateController().OnSelectStart(evt);    
}

function aspxFireDefaultButton(evt, buttonID) {
    if(_aspxIsDefaultButtonEvent(evt, buttonID)) {
        var defaultButton = _aspxGetElementById(buttonID);
        if(_aspxIsExists(defaultButton) && _aspxIsExists(defaultButton.click)) {
            if(_aspxIsFocusable(defaultButton))
                defaultButton.focus();
            defaultButton.click();
            _aspxPreventEventAndBubble(evt);
            return false;
        }
    }
    return true;
}
function _aspxIsDefaultButtonEvent(evt, defaultButtonID) {
    if(evt.keyCode != ASPxKey.Enter)
        return false;
    var srcElement = _aspxGetEventSource(evt);
    if(!_aspxIsExists(srcElement) || srcElement.id === defaultButtonID)
        return true;
    var tagName = srcElement.tagName;
    var type = srcElement.type;
    return tagName != "TEXTAREA" && tagName != "BUTTON" && tagName != "A" &&
        (tagName != "INPUT" || type != "checkbox" && type != "radio" && type != "button" && type != "submit" && type != "reset");
}

// Javascript manager
var __aspxIncludeScriptPrefix = "dxis_";
var __aspxStartupScriptPrefix = "dxss_";
var __aspxIncludeScriptsCache = {};
var __aspxCreatedIncludeScripts;
var __aspxAppendedScriptsCount;
var __aspxScriptsRestartHandlers = { };

function _aspxGetScriptCode(script) {
    var text = __aspxSafariFamily ? script.firstChild.data : script.text;
    var comment = "<!--";
    var pos = text.indexOf(comment);
    if(pos > -1)
        text = text.substr(pos + comment.length);
    return text;
}
function _aspxAppendScript(script) {
    var parent = document.getElementsByTagName("head")[0];
    if(!_aspxIsExists(parent))
        parent = document.body;        
    if(_aspxIsExists(parent)) {
        parent.appendChild(script);
    }        
}

function _aspxIsAlphaFilterUsed(img){
    return (__aspxIE && img.style.filter.indexOf("progid:DXImageTransform.Microsoft.AlphaImageLoader") > -1);
}
function _aspxIsKnownIncludeScript(script) {
    return _aspxIsExists(__aspxIncludeScriptsCache[script.src]);
}
function _aspxCacheIncludeScript(script) {
    __aspxIncludeScriptsCache[script.src] = 1;
}

function _aspxProcessScriptsAndLinks(ownerName) {
    if(!__aspxDocumentLoaded) return; // Q206563
    _aspxProcessScripts(ownerName);
    _aspxSweepDuplicatedLinks();
    _aspxMoveLinkElements();
    __aspxCachedRules = { };
}
function _aspxGetStartupScripts() {
    return _aspxGetScriptsCore(__aspxStartupScriptPrefix);
}
function _aspxGetIncludeScripts() {
    return _aspxGetScriptsCore(__aspxIncludeScriptPrefix);
}
function _aspxGetScriptsCore(prefix) {
    var result = [];
    var scripts = document.getElementsByTagName("SCRIPT");
    for(var i = 0; i < scripts.length; i++) {
        if (scripts[i].id.indexOf(prefix) == 0)
            result.push(scripts[i]);
    }
    return result;
}
function _aspxGetLinks() {
    var result = [];
    var links = document.getElementsByTagName("LINK");;
    for(var i = 0; i < links.length; i++) 
        result[i] = links[i];
    return result;
}

function _aspxInitializeLinks() {
    var links = _aspxGetLinks();
    for(var i = 0; i < links.length; i++)
        links[i].loaded = true;    
}
function _aspxInitializeScripts() {
    var scripts = _aspxGetIncludeScripts();
    for(var i = 0; i < scripts.length; i++)
        _aspxCacheIncludeScript(scripts[i]);            
        
    var startupScripts = _aspxGetStartupScripts();
    for(var i = 0; i < startupScripts.length; i++)
        startupScripts[i].executed = true;    
}
function _aspxSweepDuplicatedLinks() {
    if(__aspxIE && !__aspxIE7) return;

    var hash = { };
    var links = _aspxGetLinks();
    for(var i = 0; i < links.length; i++) {
        var href = links[i].href;
        if(!_aspxIsExists(href) || href == "") continue;
            
        if(_aspxIsExists(hash[href])){
            if(!hash[href].loaded && links[i].loaded){
                _aspxRemoveElement(hash[href]);
                hash[href] = links[i];
            }
            else
                _aspxRemoveElement(links[i]);
                    
        }
        else
            hash[href] = links[i];
    }
}
function _aspxSweepDuplicatedScripts() {
    var hash = { };
    var scripts = _aspxGetIncludeScripts();
    for(var i = 0; i < scripts.length; i++) {
        var src = scripts[i].src;
        if(!_aspxIsExists(src) || src == "") continue;
        
        if(_aspxIsExists(hash[src]))
            _aspxRemoveElement(scripts[i]);
        else
            hash[src] = scripts[i];
    }
}
function _aspxProcessScripts(ownerName) {
    __aspxCreatedIncludeScripts = [];
    __aspxAppendedScriptsCount = 0;

    var scripts = _aspxGetIncludeScripts();
    var scriptsLoading = false;
    var previousCreatedScript = null;
    var firstCreatedScript = null;

    for(var i = 0; i < scripts.length; i++) {
        var script = scripts[i];
        if(script.src == "") continue; // B134651
        if(_aspxIsKnownIncludeScript(script))
            continue;

        scriptsLoading = true;

        var createdScript = document.createElement("script");
        __aspxCreatedIncludeScripts.push(createdScript);
        createdScript.type = "text/javascript";
        createdScript.src = script.src;

        if(__aspxIE) {
            createdScript.onreadystatechange = new Function("_aspxOnScriptReadyStateChangedCallback(this, \"" + ownerName + "\");");
        } else if(__aspxSafariFamily) {
            // Organizing scripts into a linked list to perform their loading and execution sequentially
            createdScript.onload = new Function("_aspxOnScriptLoadCallback(this, \"" + ownerName + "\");");
            if(firstCreatedScript == null)
                firstCreatedScript = createdScript;
            createdScript.nextCreatedScript = null;
            if(previousCreatedScript != null)
                previousCreatedScript.nextCreatedScript = createdScript;
            previousCreatedScript = createdScript;
        } else {
            // Immediate script loading
            createdScript.onload = new Function("_aspxOnScriptLoadCallback(this, \"" + ownerName + "\");");
            _aspxAppendScript(createdScript);
            _aspxCacheIncludeScript(createdScript);
        }
    }

    // If a scripts linked list was organized, start script loading and executing from the first list element
    if(firstCreatedScript != null) {
        _aspxAppendScript(firstCreatedScript);
        _aspxCacheIncludeScript(firstCreatedScript);
    }

    if(!scriptsLoading)
        _aspxFinalizeScriptProcessing(ownerName);
}
function _aspxFinalizeScriptProcessing(ownerName) {
    _aspxSweepDuplicatedScripts();
    _aspxRunStartupScripts();
    var owner = aspxGetControlCollection().Get(ownerName);
    if(owner != null)
        owner.DoEndCallback();
}

function _aspxRunStartupScripts() {
    var scripts = _aspxGetStartupScripts();
    var code;
    for(var i = 0; i < scripts.length; i++){
        if(!scripts[i].executed) {
            code = _aspxGetScriptCode(scripts[i]);
            eval(code);
            scripts[i].executed = true;
        }
    }
    if(__aspxDocumentLoaded) // B133784
        aspxGetControlCollection().InitializeElements();
    
    for(var key in __aspxScriptsRestartHandlers)
        __aspxScriptsRestartHandlers[key]();
}

function _aspxOnScriptReadyStateChangedCallback(scriptElement, ownerName) {
    if(scriptElement.readyState == "loaded") {
        _aspxCacheIncludeScript(scriptElement);

        for(var i = 0; i < __aspxCreatedIncludeScripts.length; i++) {
            var script = __aspxCreatedIncludeScripts[i];
            if(_aspxIsKnownIncludeScript(script)) {
                if(!script.executed) {
                    script.executed = true;
                    _aspxAppendScript(script);
                    __aspxAppendedScriptsCount++;
                }
            } else
                break;
        }

        if(__aspxCreatedIncludeScripts.length == __aspxAppendedScriptsCount)
            _aspxFinalizeScriptProcessing(ownerName);
    }
}
function _aspxOnScriptLoadCallback(scriptElement, ownerName) {
    __aspxAppendedScriptsCount++;

    if(_aspxIsExists(scriptElement.nextCreatedScript)) {
        _aspxAppendScript(scriptElement.nextCreatedScript);
        _aspxCacheIncludeScript(scriptElement.nextCreatedScript);
    }

    if(__aspxCreatedIncludeScripts.length == __aspxAppendedScriptsCount)
        _aspxFinalizeScriptProcessing(ownerName);
}

function _aspxAddScriptsRestartHandler(objectName, handler) {
    __aspxScriptsRestartHandlers[objectName] = handler;
}

function _aspxMoveLinkElements() {
    if(__aspxIE)
        return;
    var head = _aspxGetElementsByTagName(document, "head")[0];
    var bodyLinks = _aspxGetElementsByTagName(document.body, "link");
    for(var i = 0; i < bodyLinks.length; i++)
        head.appendChild(bodyLinks[i]);
}
__aspxClassesScriptParsed = true;
var __aspxMenuAnimationAccelerator = 1/10;
var __aspxPCAnimationAccelerator = 1/3;
var __aspxAnimationDiscardPixels = 3;

var __aspxNotSetAlignIndicator = "NotSet";
var __aspxInnerAlignIndicator = "Sides";

function _aspxIsAlignNotSet(align){
    return align == __aspxNotSetAlignIndicator;
}
function _aspxIsInnerAlign(align){
    return align.indexOf(__aspxInnerAlignIndicator) != -1;
}
function _aspxIsOuterAlign(align){
    return (!this.IsInnerAlign(align)) && (!_aspxIsAlignNotSet(align));
}

function _aspxPopupPosition(position, isInverted){
    this.position = position;
    this.isInverted = isInverted;
}
function _aspxSegment(pos, len){
    this.pos = pos;
    this.len = len;
}
function _aspxRect(left, top, width, height){
    this.left = left;
    this.top = top;
    this.width = width;
    this.height = height;
}
function _aspxSize(width, height){
    this.width = width;
    this.height = height;
}

function _aspxFindPopupElementById(id){
    if(id == "") return null; // FIX Opera return element with id=""
    
    var popupElement = _aspxGetElementById(id);
    if(!_aspxIsExistsElement(popupElement)){
        var idParts = id.split("_");
        var uniqueId = idParts.join("$");
        popupElement = _aspxGetElementById(uniqueId);
    }
    return popupElement;
}
function _aspxFindEventSourceParentByTestFunc(evt, testFunc){
    return _aspxFindParentByTestFunc(_aspxGetEventSource(evt), testFunc);
}
function _aspxFindParentByTestFunc(element, testFunc){
    if (!_aspxIsExists(testFunc)) return null;
    
    while(element != null && element.tagName != "BODY"){
		if(testFunc(element))
		    return element;
        element = element.parentNode;  		    
	}
    return null;
}
function _aspxPreventContextMenu(evt){
    if (__aspxSafariFamily){
        if(evt.stopPropagation)
		    evt.stopPropagation();
		evt.returnValue = false;
		if(evt.preventDefault)
		    evt.preventDefault();
	} else if (__aspxNS)
	    evt.preventDefault();
}
function _aspxIsExistsAbsolutePosParent(element){
    return _aspxIsExistsParentWithSpecPosition(element, ["absolute"])
}
function _aspxIsExistsAbsoluteOrRelativePosParent(element){
    return _aspxIsExistsParentWithSpecPosition(element, ["absolute", "relative"])
}
function _aspxIsExistsParentWithSpecPosition(element, positions){
    var curEl = element.offsetParent;
    while(curEl != null) {
        for(var i = 0; i < positions.length; i ++){
		    if (_aspxGetCurrentStyle(curEl).position == positions[i])
		        return true;
		}
		curEl = curEl.offsetParent;
    }
    return false;
}
function _aspxAdjustPositionToClientScreen(element, shadowSize, pos, isX){
    var min = isX ? _aspxGetDocumentScrollLeft() : _aspxGetDocumentScrollTop();
    var max = min + (isX ? _aspxGetDocumentClientWidth() : _aspxGetDocumentClientHeight());
    max -= (isX ? element.offsetWidth + shadowSize : element.offsetHeight + shadowSize);
    
    if (pos > max) pos = max;
    if (pos < min) pos = min;
    return pos;
}
function _aspxGetPopupAbsoluteX(element, shadowWidth, popupElement, hAlign, hOffset, x, left){
    var width = element.offsetWidth;
    var bodyWidth = _aspxGetDocumentClientWidth();
    var elementX = _aspxGetAbsoluteX(popupElement);
    var scrollX = _aspxGetDocumentScrollLeft();

    if (hAlign == "WindowCenter"){
        var showAtPos = x != __aspxInvalidPosition && !_aspxIsExists(popupElement);
        if(showAtPos)
            hAlign = "";
        else
            return new _aspxPopupPosition(Math.ceil(bodyWidth / 2 - width / 2) + scrollX + hOffset, false);
    }

    if (_aspxIsExists(popupElement)){
        var leftX = elementX - width;
        var rightX = elementX + popupElement.offsetWidth;
        var innerLeftX = elementX;
        var innerRightX = elementX + popupElement.offsetWidth - width;
        var isMoreFreeSpaceLeft = bodyWidth - (rightX + width) < leftX - 2 * scrollX;
    }
    else
        hAlign = "";
    
    var isInverted = false;    
    if (hAlign == "OutsideLeft"){
        isInverted = !(leftX - scrollX > 0 || isMoreFreeSpaceLeft);
        if(isInverted)
            x = rightX - hOffset;
        else
            x = leftX + hOffset;
    }
    else if (hAlign == "LeftSides"){
        x =  innerLeftX + hOffset;
        x = _aspxAdjustPositionToClientScreen(element, shadowWidth, x, true);
    }
    else if (hAlign == "Center"){
        x =  elementX + Math.round((popupElement.offsetWidth  - width) / 2) + hOffset;
    }
    else if (hAlign == "RightSides"){
        x = innerRightX + hOffset;
        x = _aspxAdjustPositionToClientScreen(element, shadowWidth, x, true);
    }
    else if (hAlign == "OutsideRight"){
        isInverted = !(rightX + width < bodyWidth + scrollX || !isMoreFreeSpaceLeft);
        if(isInverted)
            x = leftX - hOffset;
        else
            x = rightX + hOffset;
    }
    else{
        if (!_aspxGetIsValidPosition(x))
            x = (_aspxIsExists(popupElement)) ? _aspxGetAbsoluteX(popupElement) : left;
        isInverted = x - scrollX + width > bodyWidth && x - scrollX > bodyWidth / 2;
        if(isInverted)
            x = x - width - hOffset;
        else
            x = x + hOffset;
    }
    if(__aspxIE55)
        x -= _aspxGetIEDocumentClientOffset(true);
    return new _aspxPopupPosition(x, isInverted);
}
function _aspxGetPopupAbsoluteY(element, shadowHeight, popupElement, vAlign, vOffset, y, top){
    var height = element.offsetHeight;
    var bodyHeight = _aspxGetDocumentClientHeight(); 
    var elementY = _aspxGetAbsoluteY(popupElement);
    var scrollY = _aspxGetDocumentScrollTop();
    
    if (vAlign == "WindowCenter"){
        var showAtPos = y != __aspxInvalidPosition && !_aspxIsExists(popupElement);
        if(showAtPos)
            hAlign = "";
        else
            return new _aspxPopupPosition(Math.ceil(bodyHeight / 2 - height / 2) + scrollY + vOffset, false);
    }
    
    if (_aspxIsExists(popupElement)){
        var bottomY = elementY + popupElement.offsetHeight;
        var topY = elementY - height;
        var innerBottomY = elementY + popupElement.offsetHeight - height;
        var innerTopY = elementY;
        var isMoreFreeSpaceAbove = bodyHeight - (bottomY + height) < topY - 2 * scrollY;
    }
    else
        vAlign = "";
    
    var isInverted = false;
    if (vAlign == "Above"){
        isInverted = !(topY - scrollY > 0 || isMoreFreeSpaceAbove);
        if(isInverted)
            y = bottomY - vOffset;
        else
            y = topY + vOffset;
    }
    else if (vAlign == "TopSides"){
        y = innerTopY + vOffset;
        y = _aspxAdjustPositionToClientScreen(element, shadowHeight, y, false);
    }
    else if (vAlign == "Middle"){
        y =  elementY + Math.round((popupElement.offsetHeight  - height) / 2) + vOffset;
    }
    else if (vAlign == "BottomSides"){
        y = innerBottomY + vOffset;
        y = _aspxAdjustPositionToClientScreen(element, shadowHeight, y, false);
    }
    else if (vAlign == "Below"){
        isInverted = !(bottomY + height < bodyHeight + scrollY || !isMoreFreeSpaceAbove);
        if(isInverted)
            y = topY - vOffset;
        else
            y = bottomY + vOffset;
    }
    else{
        if (!_aspxGetIsValidPosition(y))
            y = (_aspxIsExists(popupElement)) ? _aspxGetAbsoluteY(popupElement) : top;
        isInverted = y - _aspxGetDocumentScrollTop() + height > bodyHeight && y - _aspxGetDocumentScrollTop() > bodyHeight / 2;
        if(isInverted)
            y = y - height - vOffset;
        else
            y = y + vOffset;
    }
    if(__aspxIE55)
        y -= _aspxGetIEDocumentClientOffset(false);
    return new _aspxPopupPosition(y, isInverted);
}
function _aspxGetIntersectionRect(left1, top1, left2, top2, width, height){
    var segment1 = _aspxGetIntersectionSegment(left1, left2, width);
    var segment2 = _aspxGetIntersectionSegment(top1, top2, height);
    if (segment1 != null && segment2 != null){
        var left = segment1.pos;
        var top = segment2.pos;
        var width = segment1.len;
        var height = segment2.len;
        return new _aspxRect(left, top, width, height);
    }
    return null;
}
function _aspxGetIntersectionSegment(pos1, pos2, len){
    var posDifferense = Math.abs(pos1 - pos2);
    if (posDifferense <= len){
        var pos = pos1 > pos2 ? pos1 : pos2;
        var len = len - posDifferense;
        return new _aspxSegment(pos, len);
    }
    return null;
}

function _aspxInitAnimationDiv(element, x, y, onTimerString, onAnimStopCallString){
    element.animationStart = new Date();
    element.absoluteLeft = x;
    element.absoluteTop = y;
    element.popuping = true;
    element.onTimerString = onTimerString;
    element.onAnimStopCallString = onAnimStopCallString;
    element.style.overflow = "hidden";
    element.style.position = "absolute";
    
    _aspxSetStylePosition(element, x,y);
    _aspxSetStyleSize(element, element.offsetWidth, element.offsetHeight);
}
function _aspxOnAnimationTimer(animationDivElement, element, mainCell, iframeElement, animationDelay, animationMaxDelay, animationAccelerator){
    animationDivElement.timerID = _aspxClearTimer(element.timerID);

    var timeExpired = new Date() - animationDivElement.animationStart > animationMaxDelay;
    if(timeExpired)
        _aspxAnimationFinished(animationDivElement);
        
    var left = animationDivElement.popuping ? _aspxGetNextAnimationPosInternal(element.offsetLeft, animationAccelerator) : 0;
    var top = animationDivElement.popuping ? _aspxGetNextAnimationPosInternal(element.offsetTop, animationAccelerator) : 0;
    
    if (left == 0 && top == 0)
        _aspxAnimationFinished(animationDivElement);
    
    element.style.top = top + "px";
    element.style.left = left + "px";
    
    var rect = _aspxGetIntersectionRect(animationDivElement.offsetLeft, animationDivElement.offsetTop, 
        element.offsetLeft + animationDivElement.offsetLeft, element.offsetTop + animationDivElement.offsetTop,
        mainCell.offsetWidth, mainCell.offsetHeight);
    if (_aspxIsExists(rect) && _aspxIsExists(iframeElement)){
        _aspxSetStylePosition(iframeElement, rect.left, rect.top);
        _aspxSetStyleSize(iframeElement, rect.width, rect.height);
    }
    
    if (!timeExpired && animationDivElement.popuping)
        animationDivElement.timerID = window.setTimeout(animationDivElement.onTimerString, animationDelay);
}
function _aspxGetNextAnimationPosInternal(pos, animationAccelerator){
    pos = Math.round(pos * animationAccelerator);
    if (Math.abs(pos) < __aspxAnimationDiscardPixels)
        pos = 0;
    return pos;
}
function _aspxAnimationFinished(element){
    if(_aspxStopAnimation(element) && _aspxIsExists(element.onAnimStopCallString) && 
        element.onAnimStopCallString !== ""){
        eval(element.onAnimStopCallString);
    }
}
function _aspxStopAnimation(element){
    if(element.popuping){
        element.popuping = false;
        element.onTimerString = "";
	    element.style.overflow = "visible";
	    return true;
	}
	return false;
}
function _aspxGetAnimationHorizontalDirection(popupPosition, horizontalAlign, verticalAlign){
    if (_aspxIsInnerAlign(horizontalAlign) 
        && !_aspxIsInnerAlign(verticalAlign) 
        && !_aspxIsAlignNotSet(verticalAlign))
        return 0;
    var toTheLeft = (horizontalAlign == "OutsideLeft" || horizontalAlign == "RightSides") ^ popupPosition.isInverted;
    return toTheLeft ? 1 : -1;
}
function _aspxGetAnimationVerticalDirection(popupPosition, horizontalAlign, verticalAlign){
    if (_aspxIsInnerAlign(verticalAlign) 
        && !_aspxIsInnerAlign(horizontalAlign) 
        && !_aspxIsAlignNotSet(horizontalAlign))
        return 0;
    var toTheTop = (verticalAlign == "Above" || verticalAlign == "BottomSides") ^ popupPosition.isInverted;
    return toTheTop ? 1 : -1;
}
var __aspxHideBodyScrollCount = 0;
function _aspxHideBodyScroll(){
    __aspxHideBodyScrollCount++;
    if(__aspxHideBodyScrollCount > 1) //B34911
        return;
    if(__aspxIE){
        _aspxChangeAttribute(document.body, "scroll", "no");
        _aspxChangeStyleAttribute(document.documentElement, "overflow", "hidden");
    } else if(__aspxFirefox && !__aspxFirefox3) { //Q109177
        var scrollTop = document.documentElement.scrollTop;
        _aspxChangeStyleAttribute(document.body, "overflow", "hidden");
        document.documentElement.scrollTop = scrollTop;
    } else
        _aspxChangeStyleAttribute(document.body, "overflow", "hidden");
   _aspxChangeStyleAttribute(document.body, "marginRight", "16px");
}
function _aspxRestoreBodyScroll(){
    __aspxHideBodyScrollCount--;
    if(__aspxHideBodyScrollCount > 0) //B34911
        return;
    if(__aspxIE){
        _aspxRestoreAttribute(document.body, "scroll");
        _aspxRestoreStyleAttribute(document.documentElement, "overflow");
    }
    else
        _aspxRestoreStyleAttribute(document.body, "overflow");
    _aspxRestoreStyleAttribute(document.body, "marginRight");
    
    if(__aspxSafariFamily){ // B96454
        var scrollTop = document.body.scrollTop;
        document.body.scrollTop ++;
        document.body.scrollTop --;
        document.body.scrollTop = scrollTop;
    }
}
// DragHelper
var __aspxDragHelper = null;

ASPxClientDragHelper = _aspxCreateClass(null, {
	constructor: function(e, root, clone){
	    if(__aspxDragHelper != null) __aspxDragHelper.cancelDrag();
        this.dragArea = 5;
        this.lastX = e.clientX + _aspxGetDocumentScrollLeft();
        this.lastY = e.clientY + _aspxGetDocumentScrollTop();
        this.canDrag = true; 
        if(typeof(root) == "string") 
            root = _aspxGetParentByTagName(_aspxGetEventSource(e), root);
        this.obj = root && root != null ? root : _aspxGetEventSource(e);
        this.clone = clone;
        this.dragObj = null; 
        this.additionalObj = null;
        //events
        this.onDoClick = new Function();
        this.onEndDrag = new Function();
        this.onCancelDrag = new Function();
        this.onDragDivCreating = new Function();
        this.onCloneCreating = null;
        this.onCloneCreated = new Function();
        
        this.dragDiv = null;
        __aspxDragHelper = this;
    },    
    drag: function(e) {
        if(!this.canDrag) return;
        if(!this.isDragging()) {
            if(!this.isOutOfDragArea(e.clientX, e.clientY)) 
                return;
            this.startDragCore(e);
        }
        if(__aspxIE && !_aspxGetIsLeftButtonPressed(e)) {
            this.cancelDrag(e);
            return;
        }
        this.clearSelection();
        this.dragCore(e);
    },
    clearSelection: function() {
        if(!window.getSelection) return;
        var sel = window.getSelection(); 
        if(sel && sel.removeAllRanges) {
            sel.removeAllRanges() ; 
        }
    },
    startDragCore: function(e) {        
        this.dragObj = this.clone != true ? this.obj : this.createClone();
    },
    dragCore: function(e) {                
		var x = e.clientX + _aspxGetDocumentScrollLeft();
        var y = e.clientY + _aspxGetDocumentScrollTop();        
        var nx = this.dragObj.offsetLeft + x - this.lastX;
        var ny = this.dragObj.offsetTop + y - this.lastY;
        this.dragObj.style.left = nx + "px";
        this.dragObj.style.top = ny + "px";
        this.lastX = x;
        this.lastY = y;
    },
    endDrag: function(e) {    
        if(!this.isDragging() && !this.isOutOfDragArea(e.clientX, e.clientY)) 
            this.onDoClick(this);
        else this.onEndDrag(this);
        this.cancelDrag();
    },
    cancelDrag: function() {
        if(this.dragDiv != null) {
            document.body.removeChild(this.dragDiv);
            this.dragDiv = null;
        }
        this.onCancelDrag(this);
        __aspxDragHelper = null;
    },
    isDragging: function() {
       //this function overrides in: ASPxScheduler        
        return this.dragObj != null;
    },
    createClone: function() {
        this.dragDiv = document.createElement("div");
        this.onDragDivCreating(this, this.dragDiv);
        this.dragDiv.style.position = "absolute";
        this.dragDiv.style.cursor = "move";
        this.dragDiv.style.left = _aspxGetAbsoluteX(this.obj) + "px";
        this.dragDiv.style.top = _aspxGetAbsoluteY(this.obj) + "px";
        this.dragDiv.style.width = this.obj.offsetWidth + "px";
        this.dragDiv.style.height = this.obj.offsetHeight + "px";
        this.dragDiv.select = DragHelper_onselectstart;
        this.dragDiv.style.zIndex = 20000; //TODO
        this.dragDiv.style.padding = "0px";
        this.dragDiv.style.margin = "0px";
        this.dragDiv.style.borderStyle = "none";
        this.dragDiv.style.borderWidth = "0px";
        this.dragDiv.style.backgroundColor = "transparent";
        var clone = this.creatingClone();
        this.onCloneCreated(clone);
        this.dragDiv.appendChild(clone);
        document.body.appendChild(this.dragDiv);
        return this.dragDiv;
    },
    creatingClone: function() {
        var clone = this.obj.cloneNode(true);
        if(!_aspxIsExists(this.onCloneCreating)) return clone;
        return this.onCloneCreating(clone);
    },
    addElementToDragDiv: function(element) {
        if(this.dragDiv == null) return;
        this.additionalObj = element.cloneNode(true);
        this.additionalObj.style.visibility = "visible";
        this.additionalObj.style.display = "";
        this.dragDiv.appendChild(this.additionalObj);
    },
    removeElementFromDragDiv: function() {
        if(this.additionalObj == null || this.dragDiv == null) return;
        this.dragDiv.removeChild(this.additionalObj);
        this.additionalObj = null;
    },
    isOutOfDragArea: function(newX, newY) {
        return Math.max(
			Math.abs(newX + _aspxGetDocumentScrollLeft() - this.lastX), 
			Math.abs(newY + _aspxGetDocumentScrollTop() - this.lastY)) >= this.dragArea;
    }
});

function DragHelper_onmouseup(e) {
    if(__aspxDragHelper != null) {
        __aspxDragHelper.endDrag(e);
        return true;
    }
}
function DragHelper_onmousemove(e) {
    if(__aspxDragHelper != null) {
        __aspxDragHelper.drag(e);
        return true;
    }
}
function DragHelper_onkeydown(e) {
    if(__aspxDragHelper == null) return;
    if(e.keyCode == ASPxKey.Esc) {
        if(_aspxIsExists(__aspxDragHelper.onEscKeyDown))
            __aspxDragHelper.onEscKeyDown();
        else
            __aspxDragHelper.cancelDrag();
    }
    return true;
}
function DragHelper_onselectstart(e) {
    if(__aspxDragHelper != null) {
		if(!__aspxDragHelper.canDrag)
			return true;
		try {
		    document.selection.empty();
        } catch(e) {
            // B37797
        }
        return false;
    }
}

_aspxAttachEventToDocument("mouseup", DragHelper_onmouseup);
_aspxAttachEventToDocument("mousemove", DragHelper_onmousemove);
_aspxAttachEventToDocument("keydown", DragHelper_onkeydown);
_aspxAttachEventToDocument("selectstart", DragHelper_onselectstart);

// CursorTargets
var __aspxCursorTargets = null;

ASPxClientCursorTargets = _aspxCreateClass(null, {
    constructor: function() {
        this.list = new Array();
        this.starttargetElement = null;
        this.starttargetTag = 0;
        this.oldtargetElement = null;
        this.oldtargetTag = 0;
        this.targetElement = null;
        this.targetTag = 0;
        this.x = 0;
        this.y = 0;
        this.removedX = 0;
        this.removedY = 0;
        this.removedWidth = 0;
        this.removedHeight = 0;
        //events
        this.onTargetChanging = new Function();
        this.onTargetChanged = new Function();
        this.onTargetAdding = null;
        __aspxCursorTargets = this;
    },
    addElement: function(element) {
        if(!this.canAddElement(element)) return null;
        var target = new ASPxClientCursorTarget(element);
        this.list.push(target);
        return target;
    },
    removeElement: function(element) {
		for(var i = 0; i < this.list.length; i++)
			if(this.list[i].element == element) {
				this.list.splice(i, 1);
				return;
			}
    },
    addParentElement: function(parent, child) {
        var target = this.addElement(parent);
        if(target != null) {
            target.targetElement = child;
        }
        return target;
    },
    RegisterTargets: function(element, idPrefixArray) {
		this.addFunc = this.addElement;
		this.RegisterTargetsCore(element, idPrefixArray);
    },
    UnregisterTargets: function(element, idPrefixArray) {
		this.addFunc = this.removeElement;
		this.RegisterTargetsCore(element, idPrefixArray);
    },
    RegisterTargetsCore: function(element, idPrefixArray) {
		if(element == null) return;		
        for(var i = 0; i < idPrefixArray.length; i++) 
            this.RegisterTargetCore(element, idPrefixArray[i]);
    },
    RegisterTargetCore: function(element, idPrefix) {
        if(!_aspxIsExists(element.id)) return;
        if(element.id.indexOf(idPrefix) > -1) 
            this.addFunc(element);
        for(var i = 0; i < element.childNodes.length; i ++) 
            this.RegisterTargetCore(element.childNodes[i], idPrefix);
    },
    canAddElement: function(element) {
        if(element == null) return false;
        for(var i = 0; i < this.list.length; i ++) {
            if(this.list[i].targetElement == element) return false;
        }
        if(this.onTargetAdding != null && !this.onTargetAdding(this, element)) return false;
        return element.style.visibility != "hidden";
    },
    removeInitialTarget: function(x, y) {
        var el = this.getTarget(x  + _aspxGetDocumentScrollLeft(), y  + _aspxGetDocumentScrollTop());
        if(el == null) return;
        this.removedX = _aspxGetAbsoluteX(el);
        this.removedY = _aspxGetAbsoluteY(el);
        this.removedWidth = el.offsetWidth;
        this.removedHeight = el.offsetHeight;
    },
    getTarget: function(x, y) {
        for(var i = 0; i < this.list.length; i ++) {
            if(this.list[i].contains(x, y))
                return this.list[i].targetElement;
        }
        return null;
    },
    targetChanged: function(element, tag) {
        this.targetElement = element;
        this.targetTag = tag; 
        this.onTargetChanging(this);
        if(this.oldtargetElement != this.targetElement || this.oldtargetTag != this.targetTag) {
            this.onTargetChanged(this);
            this.oldtargetElement = this.targetElement;
            this.oldtargetTag = this.targetTag;
        }
    },
    cancelChanging: function() {
		this.targetElement = this.oldtargetElement;
		this.targetTag = this.oldtargetTag;
    },
    isLeftPartOfElement: function() {
        if(this.targetElement == null) return true;
        var left = this.x - this.targetElementX();
        return left < this.targetElement.offsetWidth / 2; 
    },
    isTopPartOfElement: function() {
        if(this.targetElement == null) return true;
        var top = this.y - this.targetElementY();
        return top < this.targetElement.offsetHeight / 2; 
    },
    targetElementX: function() {
        return this.targetElement != null ? _aspxGetAbsoluteX(this.targetElement) : 0;
    },
    targetElementY: function() {
        return this.targetElement != null ? _aspxGetAbsoluteY(this.targetElement) : 0;
    },
    onmousemove: function(e) {
        this.doTargetChanged(e); 
    },
    onmouseup: function(e) {    
        this.doTargetChanged(e); 
        __aspxCursorTargets = null;    
    },
    doTargetChanged: function(e) {
        this.x = e.clientX + _aspxGetDocumentScrollLeft();
        this.y = e.clientY + _aspxGetDocumentScrollTop();
        if(this.inRemovedBounds(this.x, this.y)) return; 
        this.targetChanged(this.getTarget(this.x, this.y), 0); 
    },
    inRemovedBounds: function(x, y) {
        if(this.removedWidth == 0) return false;
        return x > this.removedX && x < (this.removedX + this.removedWidth) &&
            y > this.removedY && y < (this.removedY + this.removedHeight);
    }
});

ASPxClientCursorTarget = _aspxCreateClass(null, {
    constructor: function(element) {
        this.element = element;
        this.targetElement = element;
        this.absoluteX = _aspxGetAbsoluteX(element);
        this.absoluteY = _aspxGetAbsoluteY(element);
    },
    contains: function(x, y) {
        return x >= this.absoluteX && x <= this.absoluteX + this.element.offsetWidth &&
            y >= this.absoluteY && y <= this.absoluteY + this.element.offsetHeight;
    }
});

function CursorTarget_onmouseup(e) {
    if(__aspxCursorTargets != null) {
        __aspxCursorTargets.onmouseup(e);
        return true;
    }
}

function CursorTarget_onmousemove(e) {
    if(__aspxCursorTargets != null) {
        __aspxCursorTargets.onmousemove(e);
        return true;
    }
}

_aspxAttachEventToDocument("mouseup", CursorTarget_onmouseup);
_aspxAttachEventToDocument("mousemove", CursorTarget_onmousemove);

var __aspxDialogFormCallbackStatus = "DialogForm";
var __aspxCurrentControlNameInDialog = "";
var __aspxAreKeyboardEventsInitialized = false;

function aspxAdjustControlsSizeInDialogWindow() {
    var control = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);    
    var curDialog = control != null ? ASPxDialog.GetLastDialog(control) : null;
    if (curDialog != null)
        ASPxClientControl.GetControlCollection().AdjustControls(curDialog.GetDialogPopup().GetMainElement());
}

ASPxDialog = _aspxCreateClass(null, {
	constructor: function(name) {
	    this.name = name;
	    this.initInfo = null;	 
	    this.editorKeyDownProccesed = false;
	    
	    this.keyDownHandlers = {};
        this.InitializeKeyHandlers();
    },
    // Keyboard support
    InitializeKeyHandlers: function() {
        this.AddKeyDownHandler("ESC", "HideDialog");
    },
    AddKeyDownHandler: function(shortcutString, handler) {
        this.keyDownHandlers[_aspxParseShortcutString(shortcutString)] = handler;
    },
    // virtual
    DoCustomAction: function(result, params) {
    },
    GetDialogCaptionText: function() {
        return "";
    },
    GetInitInfoObject: function() {
        return null;
    },
    InitializeDialogFields: function(initInfo) {
    },
    SetFocusInField: function() {
    },
    // Internal function
    Execute: function(ownerControl, popupElementID) {
	    this.ownerControl = ownerControl;
        __aspxCurrentControlNameInDialog = this.ownerControl.name;
        ASPxDialog.PushDialogToCollection(this.ownerControl, this);
	    
	    this.InitializePopupEvents();
        this.GetDialogPopup().SetHeaderText(this.GetDialogCaptionText());        
        if (_aspxIsExists(popupElementID))
            this.GetDialogPopup().ShowAtElementByID(popupElementID);
        else
            this.GetDialogPopup().Show();
        
	    if (this.GetDialogContent(this.name) == null) {
            this.SendCallbackForDialogContent();
            this.ShowLoadingPanelInDialogPopup();
        }
        else {
            this.ExecuteInternal(this.GetDialogContent(this.name));
            _aspxRunStartupScripts();
            this.OnInitComplete();
        }
    },
    ExecuteInternal: function(result) {
        this.initInfo = this.GetInitInfoObject();
        this.GetDialogPopup().SetContentHtml(result);
        if (this.GetDialogPopup().IsVisible())
            this.GetDialogPopup().UpdatePosition();
    },
    GetDialogPopup: function() {
        if (_aspxIsExists(this.ownerControl.GetDialogPopupControl))
            return this.ownerControl.GetDialogPopupControl();
        return null;
    },
    
    AddDialogContentToHash: function(name, content) {
        this.GetDialogContentHashTable()[this.name] = content;
    },
    GetDialogContent: function(name) {    
        return _aspxIsExists(this.GetDialogContentHashTable()[this.name]) ? 
                    this.GetDialogContentHashTable()[this.name] : null;
    },
    GetDialogContentHashTable: function() {
        if (_aspxIsExists(this.ownerControl.dialogContentHashTable))
            return this.ownerControl.dialogContentHashTable;
        return null;
    },
    InitializePopupEvents: function() {
	    if (this.GetDialogPopup().CloseButtonClick.IsEmpty()) {
	        var func = _aspxCreateEventHandlerFunction("aspxOnDialogCloseButtonClick", this.ownerControl.name, false);
	        this.GetDialogPopup().CloseButtonClick.AddHandler(func);
	        
	        func = _aspxCreateEventHandlerFunction("aspxOnDialogClose", this.ownerControl.name, false);
	        this.GetDialogPopup().CloseUp.AddHandler(func);
	    }
    },
    InitCustomKeyboardHandling: function() {
        if (!__aspxAreKeyboardEventsInitialized) {
            __aspxAreKeyboardEventsInitialized = true;                        
            _aspxAttachEventToDocument(__aspxSafariFamily ? "keydown" : "keypress", aspxDialogDocumentKeypress);
            if (__aspxNS)
                this.ReplaceKBSIKeyDown();
        }
    },
    ReplaceKBSIKeyDown: function() { // hack for FireFox
        var original = aspxKBSIKeyDown;
        aspxKBSIKeyDown = function(name, evt) {
            var isProcessed = original(name, evt);
            var ownerControl = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
            var curDialog = ownerControl != null ? ASPxDialog.GetLastDialog(ownerControl) : null;
	        if (curDialog != null) curDialog.OnInnerEditorKeyDown(evt, isProcessed);
            return isProcessed;
        };
    },
    SendCallbackForDialogContent: function() {
        this.ownerControl.callbackOwner = this;
        this.ownerControl.SendCallback(__aspxDialogFormCallbackStatus, this.name, false);
    },
    ShowLoadingPanelInDialogPopup: function() {
        this.GetDialogPopup().SetContentHtml("");
        var contentElement = this.GetDialogPopup().GetWindowContentElement(-1);        
        this.ownerControl.CreateLoadingDiv(contentElement);
        this.ownerControl.CreateLoadingPanelInsideContainer(contentElement);
    },
    ShowLoadingPanelOverDialogPopup: function() {
        var offsetElement = _aspxGetParentByTagName(this.GetDialogPopup().GetWindowContentElement(-1), "table");
        
        this.ownerControl.CreateLoadingDiv(document.body, offsetElement);
        this.ownerControl.CreateLoadingPanelWithAbsolutePosition(document.body, offsetElement);
    },
    HideLoadingPanelOverDialogPopup: function() {
        this.ownerControl.HideLoadingDiv();
        this.ownerControl.HideLoadingPanel();
    },    
    HideDialog: function() {
  	    this.GetDialogPopup().Hide();
  	    // emulation PopupControl events sequence
  	    this.OnCloseButtonClick();
  	    this.OnClose();
    },

    //Events
  	OnCallback: function(result) {
	    this.ExecuteInternal(result);
  	    this.AddDialogContentToHash(this.name, result);  	    
  	},
    OnCallbackError: function(result, data) {
        this.ownerControl.callbackOwner = null;
    },
    OnEndCallback: function() {
        this.ownerControl.callbackOwner = null;
  	    this.OnInitComplete();
    },
    OnClose: function() {
        ASPxDialog.RemoveLastDialog(this.ownerControl);
    },
    OnCloseButtonClick: function() {
    },
  	OnComplete: function(result, params) {
  	    this.GetDialogPopup().Hide();
	    this.DoCustomAction(result, params);
  	},
    OnDocumentKeyPress: function(evt) {
        if (!this.editorKeyDownProccesed) {
            var handler = this.keyDownHandlers[_aspxGetShortcutCode(evt.keyCode, evt.ctrlKey, evt.shiftKey, evt.altKey)];
            if(_aspxIsExists(handler))
                this[handler](evt);
        }
        this.editorKeyDownProccesed = false;
    },
    // hack for FireFox
    OnInnerEditorKeyDown: function(evt, isProcessed) {
        this.editorKeyDownProccesed = _aspxIsExists(isProcessed) ? !isProcessed : false;
    },
    
    OnInitComplete: function() {
	    this.InitCustomKeyboardHandling();
        this.InitializeDialogFields(this.initInfo);
        this.SetFocusInField();
    }
});

// DialogUtils
ASPxDialog.PushDialogToCollection = function(ownerControl, dialog) {
    if (!_aspxIsExists(ownerControl.dialogArray))
        ownerControl.dialogArray = new Array();
    _aspxArrayPush(ownerControl.dialogArray, dialog);
}
ASPxDialog.GetLastDialog = function(ownerControl) {
    if (_aspxIsExists(ownerControl.dialogArray)) {
        var length = ownerControl.dialogArray.length;
        return length > 0 ? ownerControl.dialogArray[length - 1] : null;
    }
    return null;
}
ASPxDialog.RemoveLastDialog = function(ownerControl) {
    var array = ownerControl.dialogArray;
    if (_aspxIsExists(array) && array.length > 0)
        _aspxArrayRemoveAt(array, array.length - 1);
}

// ---------------------------------------------------------------------------------------------------
function aspxOnDialogCloseButtonClick(name) {
    var ownerControl = aspxGetControlCollection().Get(name);
    var curDialog = ownerControl != null ? ASPxDialog.GetLastDialog(ownerControl) : null;
	if (curDialog != null)
	    return curDialog.OnCloseButtonClick();
}
function aspxOnDialogClose(name) {
    var ownerControl = aspxGetControlCollection().Get(name);    
    var curDialog = ownerControl != null ? ASPxDialog.GetLastDialog(ownerControl) : null;
	if (curDialog != null) 
	    return curDialog.OnClose();
}

function aspxDialogComplete(result, params) {
    var ownerControl = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
    var curDialog = ownerControl != null ? ASPxDialog.GetLastDialog(ownerControl) : null;
	if (curDialog != null)
	    return curDialog.OnComplete(result, params);
}
function aspxDialogDocumentKeypress(evt) {
    var ownerControl = aspxGetControlCollection().Get(__aspxCurrentControlNameInDialog);
    var curDialog = ownerControl != null ? ASPxDialog.GetLastDialog(ownerControl) : null;
	if (curDialog != null)
	    ASPxDialog.GetLastDialog(ownerControl).OnDocumentKeyPress(evt);
}
var __aspxWindowResizer = null;
var __aspxClientPopupFilterWindow = null;

ASPxClientWindowResizer = _aspxCreateClass(null, {
	constructor: function(e, resizedEl){
        __aspxWindowResizer = this;
        this.resizedEl = resizedEl;
        this.minWidth = 50;
        this.minHeight = 50;
        this.lastX = e.clientX;
        this.lastY = e.clientY;    
        this.newWidth = resizedEl.offsetWidth;
        this.newHeight = resizedEl.offsetHeight;
        this.startWidth = this.newWidth;
        this.startHeight = this.newHeight;
        this.virtWidth = this.newWidth;
        this.virtHeight = this.newHeight;
        
        this.onSetSize = null;
        this.onEndResizing = new Function();
    },    
    doResizing: function(e) {
        this.virtWidth = this.virtWidth + e.clientX - this.lastX;
        this.virtHeight = this.virtHeight + e.clientY - this.lastY;
        this.lastX = e.clientX;
        this.lastY = e.clientY;        
        this.newWidth = this.virtWidth;
        this.newHeight = this.virtHeight;
        if(this.newWidth < this.minWidth)
            this.newWidth = this.minWidth;
        if(this.newHeight < this.minHeight)
            this.newHeight = this.minHeight;
        this.doSetSize();
    },
    cancel: function() {
        this.newWidth = this.startWidth;
        this.newHeight = this.startHeight;
        this.stop();
    },
    endResizing: function(e) {
        this.onEndResizing(e);
        this.stop();    
    },
    stop: function() {
        this.doSetSize();
        __aspxWindowResizer = null;
    },
    doSetSize : function() {
        if(this.onSetSize == null || this.onSetSize(this)) {
            this.setSize();  
        }
    },
    setSize: function() {
        this.resizedEl.style.width = this.newWidth + "px";
        this.resizedEl.style.height = this.newHeight + "px";
    }
});

ASPxClientPopupFilterWindow = _aspxCreateClass(null, {
	constructor: function(name){
	    this.name = name;
	    this.onHidden = null;
	    _aspxAttachEventToElement(this.GetWindowResizer(), "dragstart", _aspxPreventDragStart);	    
    },
    GetWindow: function() { return _aspxGetElementById(this.name + "_FPW"); },
    GetElement: function() { return _aspxGetElementById(this.name + "_FPC"); },
    GetWindowResizer: function() { return _aspxGetElementById(this.name + "_FPWR"); },
    IsShowing: function() {
        if(!_aspxIsExists(this.window)) return false;
        return _aspxGetElementDisplay(this.window);
    },
    Hide: function() {
        if(!_aspxIsExists(this.window)) return;
        __aspxClientPopupFilterWindow = null;
        _aspxSetElementDisplay(this.window, false);
        this.header = null;
        if(_aspxIsExists(this.onHidden))
            this.onHidden(this);
    },
    Show: function(element, mainElement) {
        __aspxClientPopupFilterWindow = this;
        this.window = this.GetWindow();
        if(!_aspxIsExists(this.window)) return;
        
        _aspxSetElementDisplay(this.window, true);
        var left = _aspxGetAbsoluteX(element, mainElement);
        var top = _aspxGetAbsoluteY(element, mainElement) + element.offsetHeight;
        left = _aspxPrepareClientPosForElement(left, this.window, true);
        top = _aspxPrepareClientPosForElement(top, this.window, false);
        
        this.window.style.left = left + "px";
        this.window.style.top = top + "px";
        this.header = element;
    },
    SetDefaultWidth: function() {
        this.GetWindow().style.width = "";
        this.GetElement().style.width = "";
    },
    onMouseDown: function(e) {
		var e = _aspxGetEvent(e);
		var element = _aspxGetEventSource(e);
		if(element.DXFilterPopupButton) return true;    
        if(this.IsShowing() && !_aspxGetIsParent(this.window, _aspxGetEventSource(e))) {
            this.Hide();
        }
        return true;
    },
    onResizerMouseDown: function(e) {
        var resizer = new ASPxClientWindowResizer(e, this.GetElement());
        resizer.onSetSize = this.ResizerSetSize;
        resizer.resizedWindow = this.window;        
        return _aspxCancelBubble(e);
    },
    ResizerSetSize: function(resizer) {
        var oldElWidth = resizer.resizedEl.style.width;
        var oldWindowWidth = resizer.resizedWindow.style.width;
        var difEl = resizer.resizedEl.offsetWidth;
        var difWindow = resizer.resizedWindow.offsetWidth;
        resizer.resizedWindow.style.width = resizer.newWidth + "px";
        resizer.resizedEl.style.width = resizer.newWidth + "px";
        difEl = resizer.resizedEl.offsetWidth - difEl;
        difWindow = resizer.resizedWindow.offsetWidth - difWindow;
        if(difEl != difWindow) {
            resizer.resizedEl.style.width = oldElWidth;
            resizer.resizedWindow.style.width = oldWindowWidth;
        }
	    if(__aspxNS) {
            resizer.resizedWindow.style.width = resizer.resizedEl.style.width;
	        if(resizer.resizedWindow.offsetWidth < resizer.resizedEl.offsetWidth) {
		       resizer.resizedWindow.style.width = "";
	        }
	    }
	    resizer.resizedWindow.style.height = resizer.newHeight + "px";
        resizer.resizedEl.style.height = resizer.newHeight + "px";
        return false;
    }
});

function WindowResizer_onmouseup(e) {
    if(__aspxWindowResizer != null)
        __aspxWindowResizer.endResizing(e);
    return true;
}
function WindowResizer_onmousemove(e) {
    if(__aspxWindowResizer != null) {
        __aspxWindowResizer.doResizing(e);
    }
    return true;
}
function WindowResizer_onkeydown(e) {
    if(__aspxWindowResizer == null) return;
    if(e.keyCode == ASPxKey.Esc)
        __aspxWindowResizer.cancel();
    return true;
}
function WindowResizer_onselectstart(e) {
    if(__aspxWindowResizer == null) return;
    document.selection.empty();
    return false;
}

 
var __aspxClientPopupFilterWindowShowAgain = false;
function PopupFilterWindow_DocumentOnMouseDown(e){
    if(__aspxClientPopupFilterWindow == null) return;
    var src = _aspxGetEventSource(e),
		header = __aspxClientPopupFilterWindow.header;
    var onclickText = _aspxIsExists(src.onclick) ? src.onclick.toString() : "";
    if(onclickText.indexOf("_ShowFilterPopup") >= 0 && __aspxClientPopupFilterWindow.IsShowing() && _aspxGetIsParent(header, src)) {
		__aspxClientPopupFilterWindowShowAgain = true;
	}
    return __aspxClientPopupFilterWindow.onMouseDown(e);
}
function PopupFilterWindow_WindowOnResize(e){
    if(__aspxClientPopupFilterWindow == null) return;
	__aspxClientPopupFilterWindow.Hide();
}

function PopupFilterWindow_WindowOnLoad(e) {
    _aspxAttachEventToDocument("mousedown", PopupFilterWindow_DocumentOnMouseDown);
    _aspxAttachEventToElement(window, "resize", PopupFilterWindow_WindowOnResize);
}


_aspxAttachEventToDocument("mouseup", WindowResizer_onmouseup);
_aspxAttachEventToDocument("mousemove", WindowResizer_onmousemove);
_aspxAttachEventToDocument("keydown", WindowResizer_onkeydown);
_aspxAttachEventToDocument("selectstart", WindowResizer_onselectstart);
_aspxAttachEventToElement(window, "load", PopupFilterWindow_WindowOnLoad);
ASPxDateFormatter = _aspxCreateClass(null, {
    constructor: function() {
        this.date = new Date(2000, 0, 1);
        this.mask;
        
        this.specifiers = {};           // pos => "d", pos => "M", ...
        this.spPositions = [];          // sorted descending
        
        this.knownSpecifiers = ["d", "M", "y", "H", "h", "m", "s", "f", "F", "g", "t"];
        
        this.savedYear = -1;
        this.isYearParsed = false;
        this.parsedMonth = -1;
    	
	    this.replacers = {
		    "d": this.ReplaceDay,
		    "M": this.ReplaceMonth,
		    "y": this.ReplaceYear,
		    
		    "H": this.ReplaceHours23,
		    "h": this.ReplaceHours12,
		    "m": this.ReplaceMinutes,
		    "s": this.ReplaceSeconds,
		    "F": this.ReplaceMsTrimmed,
		    "f": this.ReplaceMs,
		    "g": this.ReplaceEra,
		    "t": this.ReplaceAmPm
	    };
	    this.parsers = {
	        "d": this.ParseDay,
	        "M": this.ParseMonth,
	        "y": this.ParseYear,
	        
	        "H": this.ParseHours,
	        "h": this.ParseHours,
	        "m": this.ParseMinutes,
	        "s": this.ParseSeconds,
	        "F": this.ParseMs,
	        "f": this.ParseMs,
	        "g": this.ParseEra,
	        "t": this.ParseAmPm
	    };
    },
			
    Format: function(date) {
        this.date = date;
        var sp;
        var pos;
        var replacerKey;
        var result = this.mask;
        for(var i = 0; i < this.spPositions.length; i++) {
            pos = this.spPositions[i];
            sp = this.specifiers[pos];
            replacerKey = sp.substr(0, 1);
            if(this.replacers[replacerKey]) {
                result = result.substr(0, pos) + this.replacers[replacerKey].call(this, sp.length) + result.substr(pos + sp.length);
            }
        }
		return result;
    },    
    Parse: function(str) {
		var now = new Date();        
        this.savedYear = now.getFullYear();
        this.isYearParsed = false;
        this.parsedMonth = -1;
		this.date = new Date(2000, 0, now.getDate());                
        
        this.strToParse = str;
        this.catchNumbers(str);        
        var parserKey;
        var sp;
        var pos;
        var parseResult;
        var error = false;
        this.hasAmPm = false;

        for(var i = 0; i < this.spPositions.length; i++) {
            pos = this.spPositions[i];
            sp = this.specifiers[pos];
            parserKey = sp.substr(0, 1);
            if(this.parsers[parserKey]) {
                parseResult = this.parsers[parserKey].call(this, sp.length);
                if(!parseResult) {
                    error = true;
                    break;
                }
            }
        }
        
        if(error)
            return false;
        if(this.hasAmPm) {
            if(!this.fixHours())
				return false;
		}
        if(!this.isYearParsed)
			this.date.setYear(this.savedYear);
		if(this.parsedMonth > -1)
			this.date.setMonth(this.parsedMonth);
		else
			this.date.setMonth(now.getMonth());
        return this.date;        
    },
    
    SetFormatString: function(mask) {
        if(mask.length == 2 && mask.charAt(0) == "%")
            mask = mask.charAt(1);
    
        this.specifiers = {};	
        this.spPositions = [];
        this.mask = "";

        var subt = 0;
        var pos = 0;
        var startPos = 0;
        var ch;
        var prevCh = "";
        var skip = false;
        var backslash = false;
        var sp = "";          
        while(true) {
            ch = mask.charAt(pos);
            if(ch == "") {
                if(sp.length > 0)
                    this.RegisterSpecifier(startPos, sp);
                break;
            }
                                                
            if(ch == "\\" && !backslash) {
                backslash = true;
                subt++;
            } else {
                if(!backslash && (ch == "'" || ch == '"')) {
                    skip = !skip;
                    subt++;
                } else {                    
                    if(!skip) {
                        if(ch == "/")
                            ch = __aspxCultureInfo.ds;                            
                        else if(ch == ":")
                            ch = __aspxCultureInfo.ts;
                        else if(this.IsKnownSpecifier(ch)) {
                            if(prevCh.length == 0)
                                prevCh = ch;
                            if(ch == prevCh)
                                sp += ch;
                            else {
                                if(sp.length > 0)
                                    this.RegisterSpecifier(startPos, sp);
                                sp = ch;
                                startPos = pos - subt;
                            }
                        }
                    }                    
                    this.mask += ch;
                }                        
                backslash = false;
            }                                                
            prevCh = ch;
            pos++;
        }
		this.spPositions.reverse();
    },
    RegisterSpecifier: function(pos, sp) {
        this.spPositions.push(pos);
        this.specifiers[pos] = sp;    
    },
			
    // replacers
	ReplaceDay: function(length) {
	    if(length < 3) {
		    var value = this.date.getDate().toString();
		    return length == 2 ? this.padLeft(value, 2) : value;	    
	    } else if(length == 3) {
	        return __aspxCultureInfo.abbrDayNames[this.date.getDay()];
	    } else {
	        return __aspxCultureInfo.dayNames[this.date.getDay()];
	    }
	},	
	ReplaceMonth: function(length) {
	    var value = 1 + this.date.getMonth();
	    switch(length) {
	        case 1:
	            return value.toString();
	        case 2:
	            return this.padLeft(value.toString(), 2);
	        case 3:
	            return __aspxCultureInfo.abbrGenMonthNames[value - 1];
	        default:
	            return __aspxCultureInfo.genMonthNames[value - 1];
	    }
	},
	ReplaceYear: function(length) {
	    var value = this.date.getFullYear();
	    if(length <= 2)
	        value = value % 100;
        return this.padLeft(value.toString(), length);
	},
	ReplaceHours23: function(length) {
	    var value = this.date.getHours().toString();
        return length > 1 ? this.padLeft(value, 2) : value;
	},
	ReplaceHours12: function(length) {
	    var value = this.date.getHours() % 12;
	    if(value == 0)
	        value = 12;
	    value = value.toString();
	    return length > 1 ? this.padLeft(value, 2) : value;
	},
	ReplaceMinutes: function(length) {
	    var value = this.date.getMinutes().toString();
        return length > 1 ? this.padLeft(value, 2) : value;
	},
	ReplaceSeconds: function(length) {
	    var value = this.date.getSeconds().toString();
	    return length > 1 ? this.padLeft(value, 2) : value;
	},
	ReplaceMsTrimmed: function(length) {	  
	    return this.formatMs(length, true);
	},
	ReplaceMs: function(length) {	
	    return this.formatMs(length, false);
	},
	ReplaceEra: function(length) {
	    return "A.D.";
	},
	ReplaceAmPm: function(length) {
	    var value = this.date.getHours() < 12 ? __aspxCultureInfo.am : __aspxCultureInfo.pm;
	    return length < 2 ? value.charAt(0) : value;
	},
	
	/////////////////////////////////////////////////////////////////////////////////////////
	// Parsing 
	catchNumbers: function(str) {
	    this.parseNumbers = [];	    
		var regex = /\d+/g;		
		var match;
		for(;;) {
            match = regex.exec(str);
            if(!match)
                break;
            this.parseNumbers.push(this.parseDecInt(match[0]));
        }        
        var spCount = 0;
        var now = new Date();
        for(var i in this.specifiers) {
			var sp = this.specifiers[i];
            if(sp.constructor != String || !this.IsNumericSpecifier(sp)) continue;
            spCount++;
            if(this.parseNumbers.length < spCount) {				
				var defaultValue = 0;
				if(sp.charAt(0) == "y") defaultValue = now.getFullYear(); 
				this.parseNumbers.push(defaultValue);
			}
        }
        var excess = this.parseNumbers.length - spCount;
        if(excess > 0)
			this.parseNumbers.splice(spCount, excess);        
		this.currentParseNumber = this.parseNumbers.length - 1;
	},
	popParseNumber: function() {
	    return this.parseNumbers[this.currentParseNumber--];
	},
	
	// Textual month finder
	findAbbrMonth: function() {
	    return this.findMonthCore(__aspxCultureInfo.abbrGenMonthNames);
	},
	findFullMonth: function() {
	    return this.findMonthCore(__aspxCultureInfo.genMonthNames);
	},	
	findMonthCore: function(monthNames) {
		var inputLower = this.strToParse.toLowerCase();
	    for(var i = 0; i < monthNames.length; i++) {
	        var monthName = monthNames[i].toLowerCase();
	        if(monthName.length > 0 &&  inputLower.indexOf(monthName) > -1) {
				var empty = "";
				for(var j = 0; j < monthName.length; j++) empty += " ";
				this.strToParse = this.strToParse.replace(new RegExp(monthName, "gi"), empty);
	            return 1 + parseInt(i);
            }
        }
	    return false;
	},
	
	ParseDay: function(length) {
	    if(length < 3) {
	        var value = this.popParseNumber();
	        if(value < 1 || value > 31)
	            return false;
	        this.date.setDate(value);
        }
        return true;
	},
	ParseMonth: function(length) {
	    var value;
	    switch(length){
	        case 1:
	        case 2:
	            value = this.popParseNumber();
	            break;    
	        case 3:
	            value = this.findAbbrMonth();
	            break;
	        default:
	            value = this.findFullMonth();
	            break;
	    }
        if(value < 1 || value > 12)
            return false;
	    this.parsedMonth = value - 1;
	    return true;
	},	
	ParseYear: function(length) {	    
	    var value = this.popParseNumber();
	    if(value > 9999)
	        return false;
        if(value < 100)
            value = _aspxExpandTwoDigitYear(value);
        this.date.setFullYear(value);
        this.isYearParsed = true;
        return true;
	},
	ParseHours: function(length) {
	    var value = this.popParseNumber();
	    if(value > 23)
	        return false;
        this.date.setHours(value);
        return true;
	},
	ParseMinutes: function(length) {
	    var value = this.parseMinSecCore();
	    if(value == -1)
	        return false;
        this.date.setMinutes(value);
        return true;
	},
	ParseSeconds: function(length) {
	    var value = this.parseMinSecCore();
	    if(value == -1)
	        return false;
        this.date.setSeconds(value);
        return true;
	},
	ParseMs: function(length) {
	    if(length > 3)
	        length = 3;
	    var thr = 1;
	    for(var i = 0; i < length; i++)
	        thr *= 10;
	    thr -= 1;
	    var value = this.popParseNumber();
	    while(value > thr)
	        value /= 10;
        this.date.setMilliseconds(Math.round(value));
        return true;
	},
	ParseEra: function(length) {
	    return true;
	},
	ParseAmPm: function(length) {
		this.hasAmPm = __aspxCultureInfo.am.length > 0 && __aspxCultureInfo.pm.length > 0;
	    return true;
	},
			
	parseDecInt: function(str) {
	    return parseInt(str, 10);
	},
	padLeft: function(str, length) {
	    while(str.length < length)
	        str = "0" + str;
        return str;
	},
	formatMs: function(length, trim) {
	    var value = Math.floor(this.date.getMilliseconds() * Math.pow(10, length - 3));
        value = this.padLeft(value.toString(), length);	            
        if(trim) {
            var pos = value.length - 1;
            var req = false;
            while(value.charAt(pos) == "0") {
                req = true;
                pos--;
            }
            if(req)
                value = value.substring(0, pos + 1);   
        }
	    return value;
	},
	parseMinSecCore: function() {
	    var value = this.popParseNumber();
	    return value > 59 ? -1 : value;
	},
	fixHours: function() {
		var am = __aspxCultureInfo.am.charAt(0).toLowerCase();
		var	pm = __aspxCultureInfo.pm.charAt(0).toLowerCase();
		var str = this.strToParse.toLowerCase();
		var state = null;
		if(str.indexOf(am) > -1)
			state = "A";
		else if(str.indexOf(pm) > -1)
			state = "P";
		if(!state) return true;
        var h = this.date.getHours();
        switch(state) {
			case "P":
				if(h > 12) return false;
				if(h < 12)
					this.date.setHours(12 + h);
				break;
			case "A":
				if(h == 12)
					this.date.setHours(0);
        }
        return true;
	},
	IsNumericSpecifier: function(sp) {
	    var ch = sp.charAt(0);
	    if(ch == "g" || ch == "t" || ((ch == "M" || ch == "d") && sp.length > 2))
	        return false;
	    return true;
	},
	IsKnownSpecifier: function(sp) {
	    if(sp.length > 1)
	        sp = sp.charAt(0);
	    for(var i = 0; i < this.knownSpecifiers.length; i++) {
	        if(this.knownSpecifiers[i] == sp)
	            return true;
        }
	    return false;
	}
});
ASPxDateFormatter.Create = function(format) {
	var instance = new ASPxDateFormatter();
	instance.SetFormatString(format);
	return instance;
};
ASPxClientUtils = {};
ASPxClientUtils.agent = __aspxAgent;
ASPxClientUtils.opera = __aspxOpera;
ASPxClientUtils.opera9 = __aspxOpera9;
ASPxClientUtils.safari = __aspxSafari;
ASPxClientUtils.safari3 = __aspxSafari3;
ASPxClientUtils.safariMacOS = __aspxSafariMacOS;
ASPxClientUtils.chrome = __aspxChrome;
ASPxClientUtils.ie = __aspxIE;
ASPxClientUtils.ie55 = __aspxIE55;
ASPxClientUtils.ie7 = __aspxIE7;
ASPxClientUtils.firefox = __aspxFirefox;
ASPxClientUtils.firefox3 = __aspxFirefox3;
ASPxClientUtils.mozilla = __aspxMozilla;
ASPxClientUtils.netscape = __aspxNetscape;
ASPxClientUtils.ArrayInsert = _aspxArrayInsert;
ASPxClientUtils.ArrayRemove = _aspxArrayRemove;
ASPxClientUtils.ArrayRemoveAt = _aspxArrayRemoveAt;
ASPxClientUtils.ArrayClear = _aspxArrayClear;
ASPxClientUtils.ArrayIndexOf = _aspxArrayIndexOf;
ASPxClientUtils.AttachEventToElement = _aspxAttachEventToElement;
ASPxClientUtils.DetachEventFromElement = _aspxDetachEventFromElement;
ASPxClientUtils.GetEventSource = _aspxGetEventSource;
ASPxClientUtils.GetEventX = _aspxGetEventX;
ASPxClientUtils.GetEventY = _aspxGetEventY;
ASPxClientUtils.GetKeyCode = _aspxGetKeyCode;
ASPxClientUtils.PreventEvent = _aspxPreventEvent;
ASPxClientUtils.PreventEventAndBubble = _aspxPreventEventAndBubble;
ASPxClientUtils.PreventDragStart = _aspxPreventDragStart;
ASPxClientUtils.ClearSelection = _aspxClearSelection;
ASPxClientUtils.IsExists = _aspxIsExists;
ASPxClientUtils.IsFunction = _aspxIsFunction;
ASPxClientUtils.GetAbsoluteX = _aspxGetAbsoluteX;
ASPxClientUtils.GetAbsoluteY = _aspxGetAbsoluteY;
ASPxClientUtils.SetAbsoluteX = _aspxSetAbsoluteX;
ASPxClientUtils.SetAbsoluteY = _aspxSetAbsoluteY;
ASPxClientUtils.GetDocumentScrollTop = _aspxGetDocumentScrollTop;
ASPxClientUtils.GetDocumentScrollLeft = _aspxGetDocumentScrollLeft;
ASPxClientUtils.GetDocumentClientWidth = _aspxGetDocumentClientWidth;
ASPxClientUtils.GetDocumentClientHeight = _aspxGetDocumentClientHeight;
ASPxClientUtils.GetIsParent = _aspxGetIsParent;
ASPxClientUtils.GetParentById = _aspxGetParentById;
ASPxClientUtils.GetParentByTagName = _aspxGetParentByTagName;
ASPxClientUtils.GetParentByClassName = _aspxGetParentByClassName;
ASPxClientUtils.GetChildById = _aspxGetChildById;
ASPxClientUtils.GetChildByTagName = _aspxGetChildByTagName;
ASPxClientUtils.SetCookie = _aspxSetCookie;
ASPxClientUtils.GetCookie = _aspxGetCookie;
ASPxClientUtils.DeleteCookie = _aspxDelCookie;
ASPxClientUtils.GetShortcutCode = _aspxGetShortcutCode;
ASPxClientUtils.GetShortcutCodeByEvent = _aspxGetShortcutCodeByEvent;
ASPxClientUtils.StringToShortcutCode = _aspxParseShortcutString;
function _aspxInsp(obj) {
	alert(_aspxGetObjInfo(obj));
}

function _aspxGetObjInfo(obj) {
	var array = new Array();
	for(var key in obj) {
	    if(key.indexOf("on") != 0 && key.indexOf("outer") != 0 && key.indexOf("inner") != 0) {
	        try{
			    var value = "" + eval("obj." + key);
			    if(value.indexOf("function") < 0)
				    array.push(" " + key + " = " + value);
		    }
		    catch(e){
		    }
		}
	}
	array.sort();
	return array.join("\t");
}

var ASPxJSProfilerCallInfo = function(procName, args) {
    this.procName = procName;
    this.argumentsList = (typeof(args) != "undefined" && args != null && args.length > 0) ? args : [ ];
    this.callDate = new Date();
    this.exitDate = null;
    
    this.Exit = function() {
        this.exitDate = new Date();
    }
    this.GetEnterInfo = function() {
        return this.GetInfo(">>");
    }
    this.GetExitInfo = function() {
        if (this.exitDate == null)
            throw 'JSProfilerCallInfo Exit() method was not called.';
        return this.GetInfo("<<", true);
    }
    this.GetInfo = function(prefix, writeExecutionTime) {
        var info = "";
        info += prefix;
        info += "&nbsp;";
        info += "<span style=\"color: blue;\">";
        info += this.procName;
        info += "(";
        info += "<span style=\"color: #F757FA;\">";
        for(var i = 0; i < this.argumentsList.length; i++) {
            info += this.argumentsList[i];
            if (i < this.argumentsList.length - 1)
                info += ", ";
        }
        info += "</span>";
        info += ")";
        info += "</span>";
        if (writeExecutionTime)
            info += "&nbsp; (execution time: <span style=\"color: blue\">" + this.GetExecutionSeconds(this.callDate, this.exitDate) + " sec</span>)";
        return info;
    }
    this.GetExecutionTime = function() {
        return this.GetExecutionSeconds(this.callDate, this.exitDate);
    }    
    this.GetExecutionSeconds = function(callDate, exitDate) {
        return (exitDate.getTime() - callDate.getTime()) / 1000.0;
    }
}

var ASPxJSProfiler = {
    callStack: [ ],
    
    // API
    Enter: function(procName, args, needWriteResultToBody) {
        needWriteResultToBody = _aspxIsExists(needWriteResultToBody) ? needWriteResultToBody : true;
        var callInfo = new ASPxJSProfilerCallInfo(procName, args);
        if (needWriteResultToBody)
            ASPxJSProfiler.WriteMessage(callInfo.GetEnterInfo());
        ASPxJSProfiler.callStack.push(callInfo);
    },
    Exit: function(needWriteResultToBody) {
        needWriteResultToBody = _aspxIsExists(needWriteResultToBody) ? needWriteResultToBody : true;
        if (ASPxJSProfiler.callStack.length == 0)
            throw "CallStack is empty.";
        var callInfo = ASPxJSProfiler.callStack[ASPxJSProfiler.callStack.length - 1];
        callInfo.Exit();
        ASPxJSProfiler.callStack.pop();
        var exitInfo = callInfo.GetExitInfo();
        if (needWriteResultToBody)
            ASPxJSProfiler.WriteMessage(exitInfo);
        else
            return { message: exitInfo, executionTime: callInfo.GetExecutionTime() };
    },
    
    // Utils
    CreateIndentString: function() {
        var indent = "";
        for (var i = 0; i < ASPxJSProfiler.callStack.length; i++)
            indent += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        return indent;
    },
    WriteError: function(message) {
        ASPxJSProfiler.WriteMessageCore(message, "red");
    },
    WriteWarning: function(message) {
        ASPxJSProfiler.WriteMessageCore(message, "#E8DD44");
    },
    Write: function(message) {
        ASPxJSProfiler.WriteMessage(message);
    },
    WriteMessage: function(message) {
        ASPxJSProfiler.WriteMessageCore(message, "green");
    },
    WriteMessageCore: function(message, colorStr) {
        var para = document.createElement("P");
        para.style.fontSize = "12px";
        para.style.margin = "1px 0";
        para.style.color = colorStr;
        para.style.whiteSpace = "nowrap";
        para.style.fontFamily = "Consolas, Arial, Tahoma";
        para.innerHTML = ASPxJSProfiler.CreateIndentString() + message;
        document.body.appendChild(para);
    }
};

var __aspxMIIdSuffix = "_DXI";
var __aspxMMIdSuffix = "_DXM";

ASPxClientMenuItemInfo = _aspxCreateClass(null, {
	constructor: function(menu, indexPath){
        this.clientHeight = 0;
        this.clientWidth = 0;
        this.clientTop = 0;
        this.clientLeft = 0;
        this.offsetHeight = 0;
        this.offsetWidth = 0;
        this.offsetTop = 0;
        this.offsetLeft = __aspxAbsoluteRightPosition;
        
        var imageElement = (indexPath != "") ? menu.GetItemImageCell(indexPath) : null;
        if(imageElement != null){
            this.clientWidth += imageElement.clientWidth;
            this.offsetWidth += imageElement.offsetWidth;
            if(this.clientLeft == 0) 
                this.clientLeft = _aspxGetClientLeft(imageElement);
            if(this.offsetLeft > imageElement.offsetLeft)
                this.offsetLeft = imageElement.offsetLeft;
        }
        var indentElement = (indexPath != "") ? menu.GetItemIndentCell(indexPath) : null;
        if(indentElement != null){
            this.clientWidth += indentElement.clientWidth;
            this.offsetWidth += indentElement.offsetWidth;
        }
        var textElement = (indexPath != "") ? menu.GetItemTextCell(indexPath) : null;
        if(textElement != null){ 
            this.clientWidth += textElement.clientWidth;
            this.offsetWidth += textElement.offsetWidth;
            if(this.clientLeft == 0) 
                this.clientLeft = _aspxGetClientLeft(textElement);
            if(this.offsetLeft > textElement.offsetLeft)
                this.offsetLeft = textElement.offsetLeft;

            this.clientTop = _aspxGetClientTop(textElement);
            this.offsetHeight += textElement.offsetHeight;
            this.offsetTop = textElement.offsetTop;
            
            this.clientHeight = textElement.clientHeight;
            if(__aspxSafariVersionNonLessThan3 || __aspxChrome){ // FIX B130641
                if(!menu.IsVertical(indexPath))
                    this.clientHeight = _aspxWebKit3TDRealInfo.GetClientHeight(textElement);
                if(imageElement != null && this.clientHeight < imageElement.clientHeight) 
                    this.clientHeight = imageElement.clientHeight;
            }
        }
        var popOutImageElement = (indexPath != "") ? menu.GetItemPopOutImageCell(indexPath) : null;
        if(popOutImageElement != null){
            this.clientWidth += popOutImageElement.clientWidth;
            this.offsetWidth += popOutImageElement.offsetWidth;
            if(this.clientLeft == 0) 
                this.clientLeft = _aspxGetClientLeft(popOutImageElement);
            if(this.offsetLeft > popOutImageElement.offsetLeft)
                this.offsetLeft = popOutImageElement.offsetLeft;
        }
    }
});
ASPxClientMenuBase = _aspxCreateClass(ASPxClientControl, {
	constructor: function(name){
		this.constructor.prototype.constructor.call(this, name);

        this.allowSelectItem = false;
        this.allowCheckItems = false;
        this.appearAfter = 300;
        this.animationDelay = 30;
        this.animationMaxDelay = 400;
        this.disappearAfter = 500;
        this.enableAnimation = true;
        this.checkedItems = new Array();
        this.itemCheckedGroups = new Array();
        this.lockHoverEvents = false;
        this.popupToLeft = false;
        this.popupCount = 0;
        this.rootItem = null;
        this.showSubMenus = false;
        this.savedCallbackHoverItem = null;
        this.savedCallbackHoverElement = null;
        
        this.rootSubMenuFIXOffset = 0;
        this.rootSubMenuFIYOffset = 0;
        this.rootSubMenuLIXOffset = 0;
        this.rootSubMenuLIYOffset = 0;
        this.rootSubMenuXOffset = 0;
        this.rootSubMenuYOffset = 0;
        this.subMenuFIXOffset = 0;
        this.subMenuFIYOffset = 0;
        this.subMenuLIXOffset = 0;
        this.subMenuLIYOffset = 0;
        this.subMenuXOffset = 0;
        this.subMenuYOffset = 0;
        this.ItemClick = new ASPxClientEvent();
        this.ItemMouseOver = new ASPxClientEvent();
        this.ItemMouseOut = new ASPxClientEvent();
        this.PopUp = new ASPxClientEvent();
        this.CloseUp = new ASPxClientEvent();
        
        aspxGetMenuCollection().Add(this);
    },
    InlineInitialize: function(){
        this.InitializeInternal(true);
        if(this.IsCallbacksEnabled()){
            this.showSubMenus = this.GetLoadingPanelElement() != null;
            this.CreateCallback();
        }
        else
            this.showSubMenus = true;
    },
    InitializeInternal: function(inline){
        this.InitializeCheckedItems();
        this.InitializeSelectedItem();
        this.InitializeEnabledAndVisible(!inline || !this.IsCallbacksEnabled());
    },
	InitializeEnabledAndVisible: function(recursive){
	    if(this.rootItem == null) return;

        for(var i = 0; i < this.rootItem.items.length; i++)
            this.rootItem.items[i].InitializeEnabledAndVisible(recursive);
	},
	IsCallbacksEnabled: function(){
	    return _aspxIsFunction(this.callBack);
	},
	
    GetMenuElement: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMMIdSuffix + indexPath + "_");
    },
    GetMenuIFrameElement: function(indexPath){
        var level = this.GetMenuLevel(indexPath);
        return _aspxGetElementById(this.name + "_DXMIF" + level);
    },
    GetMenuBorderCorrectorElement: function(indexPath){
        return _aspxGetElementById(this.name + "_DXMBC" + indexPath + "_");
    },
    GetMenuMainCell: function(element){
        return this.GetMenuMainTable(element).rows[0].cells[0];
    },
    GetMenuMainTable: function(element){
        var indexPath = this.GetIndexPathById(element.id, true);
        var shadowTable = _aspxGetElementById(this.name + "_DXMST" + indexPath + "_");
        return shadowTable != null ? shadowTable : element;
    },    
    
    GetItemElement: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMIIdSuffix + indexPath + "_");
    },
    GetItemTemplateCell: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMIIdSuffix + indexPath + "_ITC");
    },
    GetItemImageCell: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMIIdSuffix + indexPath + "_I");
    },
    GetItemIndentCell: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMIIdSuffix + indexPath + "_N");
    },
    GetItemTextCell: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMIIdSuffix + indexPath + "_T");
    },
    GetItemPopOutImageCell: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMIIdSuffix + indexPath + "_P");
    },
    GetItemTextOrImageCell: function(indexPath){
        var element = this.GetItemTextCell(indexPath);
        if(element == null)
            element = this.GetItemImageCell(indexPath);
        return element;
    },
    
    GetSelectedItemInputElement: function(){
        return _aspxGetElementById(this.name + "SI");
    },
    GetCheckedItemsInputElement: function(){
        return _aspxGetElementById(this.name + "CI");
    },
        
    GetSubMenuXPosition: function(indexPath, menuElement){
        var position = 0;
        var element = null;
        var imageElement = this.GetItemImageCell(indexPath);
        var textElement = this.GetItemTextCell(indexPath);
        var popOutImageElement = this.GetItemPopOutImageCell(indexPath);
        var imagePos = _aspxGetAbsoluteX(imageElement);
        var textPos = _aspxGetAbsoluteX(textElement);
        var popOutImagePos = _aspxGetAbsoluteX(popOutImageElement);
        
        if(imageElement != null || textElement != null || popOutImageElement != null){
            if(this.IsVertical(indexPath)){
                position = __aspxAbsoluteLeftPosition;
                if(imageElement != null && position < imagePos){
                    position = imagePos;
                    element = imageElement;
                }
                if(textElement != null && position < textPos){
                    position = textPos;
                    element = textElement;
                }
                if(popOutImageElement != null && position < popOutImagePos){
                    position = popOutImagePos;
                    element = popOutImageElement;
                }
                position = _aspxGetAbsoluteX(element) + element.clientWidth;
            }
            else{
                position = __aspxAbsoluteRightPosition;
                if(imageElement != null && position > imagePos){
                    position = imagePos;
                    element = imageElement; 
                }
                if(textElement != null && position > textPos){
                    position = textPos;
                    element = textElement;
                }
                if(popOutImageElement != null && position > popOutImagePos){
                    position = popOutImagePos;
                    element = popOutImageElement;
                }
            }
            if (element != null && _aspxIsExistsAbsolutePosParent(element))
                position -= _aspxGetIEDocumentClientOffset(true);
        }
        return position;
    },
    GetSubMenuYPosition: function(indexPath, menuElement){
        var position = 0;
        var element = this.GetItemTextOrImageCell(indexPath);
        if(element != null){
            if(this.IsVertical(indexPath)){
                position = _aspxGetAbsoluteY(element); // The best solution
            }
            else{
                if(__aspxNS || __aspxOpera9 || __aspxSafariVersionNonLessThan3 || __aspxChrome)
                    position = _aspxGetAbsoluteY(element) + element.offsetHeight - _aspxGetClientTop(element);
                else if(__aspxSafariFamily)
                    position = _aspxGetAbsoluteY(element) + element.offsetHeight + element.offsetTop - _aspxGetClientTop(element);
                else
                    position = _aspxGetAbsoluteY(element) + element.clientHeight + _aspxGetClientTop(element);
            }
            if (_aspxIsExistsAbsolutePosParent(element))
                position -= _aspxGetIEDocumentClientOffset(false);
        }
        return position;
    },
    GetClientSubMenuXPosition: function(element, x, indexPath){
        var itemInfo = new ASPxClientMenuItemInfo(this, indexPath);
        var itemWidth = itemInfo.clientWidth;
        var itemOffsetWidth = itemInfo.offsetWidth;
        var menuWidth = this.GetMenuMainCell(element).offsetWidth;
        var bodyWidth = _aspxGetDocumentClientWidth();
        
        if(this.IsVertical(indexPath)){
            var left = x - _aspxGetDocumentScrollLeft();
            var right = left + menuWidth;
            var toLeftX = x - menuWidth - itemWidth;
            var toLeftLeft = left - menuWidth - itemWidth;
            var toLeftRight = right - menuWidth - itemWidth;
            if(this.popupToLeft){
                if(toLeftLeft < 0 && toLeftLeft < bodyWidth - right){
                    this.popupToLeft = false;
                    return x;
                }
                else
                    return toLeftX;
            }
            else{
                if(bodyWidth - right < 0 && bodyWidth - right < toLeftLeft){
                    this.popupToLeft = true;
                    return toLeftX;
                }
                else
                    return x;
            }
        }
        else{
            var left = x - _aspxGetDocumentScrollLeft();
            var right = left + menuWidth;
            var toLeftX = x - menuWidth + itemOffsetWidth;
            var toLeftLeft = left - menuWidth + itemOffsetWidth;
            var toLeftRight = right - menuWidth + itemOffsetWidth;
            if(this.popupToLeft){
                if(toLeftLeft < 0 && toLeftLeft < bodyWidth - right){
                    this.popupToLeft = false;
                    return x;
                }
                else
                    return toLeftX;
            }
            else{
                if(bodyWidth - right < 0 && bodyWidth - right < toLeftLeft){
                    this.popupToLeft = true;
                    return toLeftX;
                 }
                 else
                    return x;
            }
        }
    },
    GetClientSubMenuYPosition: function(element, y, indexPath){
        var itemInfo = new ASPxClientMenuItemInfo(this, indexPath);
        var itemHeight = itemInfo.clientHeight;
        var itemOffsetHeight = itemInfo.offsetHeight;
        var menuHeight = this.GetMenuMainCell(element).offsetHeight;
        
        var top = y - _aspxGetDocumentScrollTop();
        var bottom = top + menuHeight;
        var bodyHeight = _aspxGetDocumentClientHeight();
            
        if(this.IsVertical(indexPath)){
            menuHeight -= itemOffsetHeight - itemHeight;
            if(bottom > bodyHeight && top - menuHeight + itemHeight > bodyHeight - bottom)
                return y - menuHeight + itemHeight;
        }
        else{
            if(bottom > bodyHeight && top - menuHeight - itemHeight > bodyHeight - bottom)
                return y - menuHeight - itemHeight;
        }
        return y;
    },
        
    HasChildren: function(indexPath){
        return (this.GetMenuElement(indexPath) != null);
    },
    IsVertical: function(indexPath){
        return true;
    },
    IsRootItem: function(indexPath){
        return this.GetMenuLevel(indexPath) <= 1;
    },
    IsParentElementPositionStatic: function(indexPath){
        return this.IsRootItem(indexPath);
    },
    
    GetItemIndexPath: function(indexes){
        return aspxGetMenuCollection().GetItemIndexPath(indexes);
    },
    GetItemIndexes: function(indexPath){
        return aspxGetMenuCollection().GetItemIndexes(indexPath);
    },
    GetItemIndexPathById: function(id){
        return aspxGetMenuCollection().GetIndexPathById(id, false);
    },
    GetMenuIndexPathById: function(id){
        return aspxGetMenuCollection().GetIndexPathById(id, true);
    },
    GetIndexPathById: function(id, checkMenu){
        var indexPath = this.GetItemIndexPathById(id);
        if(indexPath == "" && checkMenu) 
            indexPath = this.GetMenuIndexPathById(id);
        return indexPath;
    },
    GetMenuLevel: function(indexPath){
        return aspxGetMenuCollection().GetMenuLevel(indexPath);
    },
    
    GetParentIndexPath: function(indexPath){
        var indexes = this.GetItemIndexes(indexPath);
        indexes.length --;
        return (indexes.length > 0) ? this.GetItemIndexPath(indexes) : ""; 
    },
    GetFirstChildIndexPath: function(indexPath){
        var indexes = this.GetItemIndexes(indexPath);
        indexes[indexes.length] = 0;
        var newIndexPath = this.GetItemIndexPath(indexes); 
        return this.GetFirstSiblingIndexPath(newIndexPath);
    },
    GetFirstSiblingIndexPath: function(indexPath){
        var indexes = this.GetItemIndexes(indexPath);
        var i = 0;
        while(true){
            indexes[indexes.length - 1] = i;
            var newIndexPath = this.GetItemIndexPath(indexes); 
            if(!this.IsItemExist(newIndexPath))
                return null;
            if(this.IsItemExistAndEnabled(newIndexPath))
                return newIndexPath;
            i++;
        }
        return null;
    },
    GetLastSiblingIndexPath: function(indexPath){
        var indexes = this.GetItemIndexes(indexPath);
        var newIndexPath = null;
        var i = indexes[indexes.length - 1] + 1;
        while(true){        
            indexes[indexes.length - 1] = i;
            var nextIndexPath = this.GetItemIndexPath(indexes); 
            if(!this.IsItemExist(nextIndexPath))
                return newIndexPath;
            if(this.IsItemExistAndEnabled(nextIndexPath))
                newIndexPath = nextIndexPath;
            i++;
        }
        return null;
    },
    GetNextSiblingIndexPath: function(indexPath){
        if(this.IsLastItem(indexPath)) return null;
        var indexes = this.GetItemIndexes(indexPath);
        var i = indexes[indexes.length - 1] + 1;
        while(true){        
            indexes[indexes.length - 1] = i;
            var newIndexPath = this.GetItemIndexPath(indexes); 
            if(!this.IsItemExist(newIndexPath))
                return null;
            if(this.IsItemExistAndEnabled(newIndexPath))
                return newIndexPath;
            i++;
        }
        return null;
    },
    GetPrevSiblingIndexPath: function(indexPath){
        if(this.IsFirstItem(indexPath)) return null;
        var indexes = this.GetItemIndexes(indexPath);
        var i = indexes[indexes.length - 1] - 1;
        while(true){        
            indexes[indexes.length - 1] = i;
            var newIndexPath = this.GetItemIndexPath(indexes); 
            if(!this.IsItemExist(newIndexPath))
                return null;
            if(this.IsItemExistAndEnabled(newIndexPath))
                return newIndexPath;
            i--;
        }
        return null;
    },
    IsLastElement: function(element){
        return _aspxIsExists(element) && (!_aspxIsExists(element.nextSibling) || !_aspxIsExists(element.nextSibling.tagName));
    },
    IsLastItem: function(indexPath){
        if(this.IsVertical(indexPath)){
            var itemElement = this.GetItemElement(indexPath);
            return this.IsLastElement(itemElement);
        }    
        else{
            var imageCell = this.GetItemImageCell(indexPath);
            if(this.IsLastElement(imageCell))
                return true;
            var textCell = this.GetItemTextCell(indexPath);
            if(this.IsLastElement(textCell))
                return true;
            var popOutImageCell = this.GetItemPopOutImageCell(indexPath);
            if(this.IsLastElement(popOutImageCell))
                return true;
            return false;
        }
    },
    IsFirstElement: function(element){
        return _aspxIsExists(element) && (!_aspxIsExists(element.previousSibling) || !_aspxIsExists(element.previousSibling.tagName));
    },
    IsFirstItem: function(indexPath){
        if(this.IsVertical(indexPath)){
            var itemElement = this.GetItemElement(indexPath);
            return this.IsFirstElement(itemElement);
        }    
        else{
            var imageCell = this.GetItemImageCell(indexPath);
            if(this.IsFirstElement(imageCell))
                return true;
            var textCell = this.GetItemTextCell(indexPath);
            if(this.IsFirstElement(textCell))
                return true;
            var popOutImageCell = this.GetItemPopOutImageCell(indexPath);
            if(this.IsFirstElement(popOutImageCell))
                return true;
            return false;
        }
    },
    IsItemExist: function(indexPath){
        return _aspxIsExists(this.GetItemTextOrImageCell(indexPath));
    },
    IsItemExistAndEnabled: function(indexPath){
        var cell = this.GetItemTextOrImageCell(indexPath);
        if(_aspxIsExists(cell)){
            var link = _aspxGetChildByTagName(cell, "A", 0);
            if(link != null)
                return !_aspxIsExists(cell.enabled) || cell.enabled;
        }
        return false;
    },
    
    GetClientSubMenuPos: function(element, indexPath, pos, isXPos){
        if (!_aspxGetIsValidPosition(pos)){
            pos = isXPos ? this.GetSubMenuXPosition(indexPath, element) : 
                this.GetSubMenuYPosition(indexPath, element);
            if(__aspxSafariFamily){
                if(!this.IsParentElementPositionStatic(indexPath))
                    pos -= isXPos ? document.body.offsetLeft : document.body.offsetTop;
            }    
        }
        
        var clientPos = isXPos ? this.GetClientSubMenuXPosition(element, pos, indexPath) :
            this.GetClientSubMenuYPosition(element, pos, indexPath);
        var isInverted = pos != clientPos;
        var offset = isXPos ? this.GetSubMenuXOffset(indexPath) : this.GetSubMenuYOffset(indexPath);
        clientPos += isInverted ? - offset : offset;
		clientPos -= _aspxGetPositionElementOffset(this.GetMenuElement(indexPath), isXPos);
        return new _aspxPopupPosition(clientPos, isInverted);
    },
    GetSubMenuXOffset: function(indexPath){
        if(indexPath == "")
            return 0;
        else if(this.IsRootItem(indexPath)){
            if(this.IsFirstItem(indexPath))
                return this.rootSubMenuFIXOffset;
            else if(this.IsLastItem(indexPath))
                return this.rootSubMenuLIXOffset;
            else
                return this.rootSubMenuXOffset;
        }
        else{
            if(this.IsFirstItem(indexPath))
                return this.subMenuFIXOffset;
            else if(this.IsLastItem(indexPath))
                return this.subMenuLIXOffset;
            else
                return this.subMenuXOffset;
        }
    },
    GetSubMenuYOffset: function(indexPath){
        if(indexPath == "")
            return 0;
        else if(this.IsRootItem(indexPath)){
            if(this.IsFirstItem(indexPath))
                return this.rootSubMenuFIYOffset;
            else if(this.IsLastItem(indexPath))
                return this.rootSubMenuLIYOffset;
            else
                return this.rootSubMenuYOffset;
        }
        else{
            if(this.IsFirstItem(indexPath))
                return this.subMenuFIYOffset;
            else if(this.IsLastItem(indexPath))
                return this.subMenuLIYOffset;
            else
                return this.subMenuYOffset;
        }
    },
    
    ClearAppearTimer: function(){
        aspxGetMenuCollection().ClearAppearTimer();
    },
    ClearDisappearTimer: function(){
        aspxGetMenuCollection().ClearDisappearTimer();
    },
    IsAppearTimerActive: function(){
        return aspxGetMenuCollection().IsAppearTimerActive();
    },
    IsDisappearTimerActive: function(){
        return aspxGetMenuCollection().IsDisappearTimerActive();
    },
    SetAppearTimer: function(indexPath){
        aspxGetMenuCollection().SetAppearTimer(this.name, indexPath, this.appearAfter);
    },
    SetDisappearTimer: function(){
        aspxGetMenuCollection().SetDisappearTimer(this.name, this.disappearAfter);
    },
    
    DoItemClick: function(indexPath, hasItemLink, htmlEvent){
        var processOnServer = this.RaiseItemClick(indexPath, htmlEvent);
        if(processOnServer && !hasItemLink)
            this.SendPostBack("CLICK:" + indexPath);
        else{
            this.ClearDisappearTimer();
            this.ClearAppearTimer();
            if(!this.HasChildren(indexPath))
                aspxGetMenuCollection().DoHidePopupMenus(null, -1, this.name, false, "");
            else if(this.IsItemEnabled(indexPath))
                this.ShowSubMenu(indexPath);
        }
    },
    DoShowPopupMenu: function(element, x, y, indexPath){
        if(element != null && this.IsCallbacksEnabled()){
            var mainCell = this.GetMenuMainCell(element);
            if(mainCell != null && mainCell.innerHTML == "")
                this.CreateLoadingPanelInsideContainer(mainCell);
        }
        
        if(__aspxNS)
            _aspxSetStylePosition(element, -1000, -1000);
        _aspxSetElementDisplay(element, true);

        if(this.popupCount == 0) this.popupToLeft = false;
        var horizontalPopupPosition = this.GetClientSubMenuPos(element, indexPath, x, true);
        var verticalPopupPosition = this.GetClientSubMenuPos(element, indexPath, y, false);
        var clientX = horizontalPopupPosition.position;
        var clientY = verticalPopupPosition.position;
        var toTheLeft = horizontalPopupPosition.isInverted;
        var toTheTop = verticalPopupPosition.isInverted;

        if (this.enableAnimation){
            this.StartAnimation(element, indexPath, horizontalPopupPosition, verticalPopupPosition);
        }
        else{
            _aspxSetStylePosition(element, clientX, clientY);
            _aspxSetElementVisibility(element, true);
            
            this.DoShowPopupMenuIFrame(element, clientX, clientY, __aspxInvalidDimension, __aspxInvalidDimension, indexPath);
            this.DoShowPopupMenuBorderCorrector(element, clientX, clientY, indexPath, toTheLeft, toTheTop);
        }
        aspxGetMenuCollection().RegisterVisiblePopupMenu(this.name, element.id);
        this.popupCount ++;
        
        this.RaisePopUp(indexPath);
    },
    DoShowPopupMenuIFrame: function(element, x, y, width, height, indexPath){    
        if (!this.renderIFrameForPopupElements) return;
        
        var iFrame = element.overflowElement;
        if(!_aspxIsExists(iFrame)){
            iFrame = this.GetMenuIFrameElement(indexPath);
            element.overflowElement = iFrame;
        }
        if(_aspxIsExists(iFrame)){
            var cell = this.GetMenuMainCell(element);
            if (width < 0)
                width = cell.offsetWidth;
            if (height < 0)
                height = cell.offsetHeight;
            _aspxSetStyleSize(iFrame, width, height);
            _aspxSetStylePosition(iFrame, x, y);
            _aspxSetElementDisplay(iFrame, true);
        }
    },
    DoShowPopupMenuBorderCorrector: function(element, x, y, indexPath, toTheLeft, toTheTop){
        var borderCorrectorElement = this.GetMenuBorderCorrectorElement(indexPath);
        if(_aspxIsExists(borderCorrectorElement)){
            var itemInfo = new ASPxClientMenuItemInfo(this, indexPath);
            var menuXOffset = _aspxGetClientLeft(this.GetMenuMainCell(element));
            var menuYOffset = _aspxGetClientTop(this.GetMenuMainCell(element));
            var menuClientWidth = this.GetMenuMainCell(element).clientWidth;
            var menuClientHeight = this.GetMenuMainCell(element).clientHeight;
            var width = 0, height = 0, left = 0, top = 0;
            if(this.IsVertical(indexPath)){
                var commonClientHeight = itemInfo.clientHeight < menuClientHeight ? itemInfo.clientHeight : menuClientHeight;
                width = menuXOffset;
                height = commonClientHeight + itemInfo.clientTop - menuYOffset;
                left = toTheLeft ? x + menuClientWidth + menuXOffset : x;
                top = toTheTop ? y + menuClientHeight - height + menuYOffset : y + menuYOffset;
            }
            else{
                var commonClientWidth = itemInfo.clientWidth < menuClientWidth ? itemInfo.clientWidth : menuClientWidth;
                width = commonClientWidth + itemInfo.clientLeft - menuXOffset;
                height = menuYOffset;
                left = toTheLeft ? x + menuClientWidth - width + menuXOffset : x + menuXOffset;
                top = toTheTop ? y + menuClientHeight + menuYOffset : y;
                if(__aspxSafariFamily && itemInfo.offsetLeft > 0)
                    width += itemInfo.clientLeft;
            }
            _aspxSetStyleSize(borderCorrectorElement, width, height);
            _aspxSetStylePosition(borderCorrectorElement, left, top);
            _aspxSetElementVisibility(borderCorrectorElement, true);
            _aspxSetElementDisplay(borderCorrectorElement, true);
            
            element.borderCorrectorElement = borderCorrectorElement;
        }
    },
    DoHidePopupMenu: function(evt, element){
        this.DoHidePopupMenuBorderCorrector(element);
        this.DoHidePopupMenuIFrame(element);

        _aspxStopAnimation(element);
        
        _aspxSetElementVisibility(element, false);
        _aspxSetElementDisplay(element, false);        

        this.CancelSubMenuItemHoverItem(element);
        aspxGetMenuCollection().UnregisterVisiblePopupMenu(this.name, element.id);
        this.popupCount --;

        var indexPath = this.GetIndexPathById(element.id, true);
        this.RaiseCloseUp(indexPath);
    },
    DoHidePopupMenuIFrame: function(element){
        if (!this.renderIFrameForPopupElements) return;

        var iFrame = element.overflowElement;
        if(_aspxIsExists(iFrame))
            _aspxSetElementDisplay(iFrame, false);        
    },
    DoHidePopupMenuBorderCorrector: function(element){
        var borderCorrectorElement = element.borderCorrectorElement;
        if(_aspxIsExists(borderCorrectorElement)){
            _aspxSetElementVisibility(borderCorrectorElement, false);
            _aspxSetElementDisplay(borderCorrectorElement, false);
            element.borderCorrectorElement = null;
        }
    },

    SetHoverElement: function(element){
        this.lockHoverEvents = true;
        aspxGetStateController().SetCurrentHoverElementBySrcElement(element);
        this.lockHoverEvents = false;
    },
    ApplySubMenuItemHoverItem: function(element, hoverItem, hoverElement){
        if(_aspxGetElementDisplay(element) && !_aspxIsExists(element.hoverItem)){
        
            var newHoverItem = hoverItem.Clone();
            element.hoverItem = newHoverItem;
            element.hoverElement = hoverElement;
            newHoverItem.Apply(hoverElement);
        }
    },
    CancelSubMenuItemHoverItem: function(element){
        if(_aspxIsExists(element.hoverItem)){
            element.hoverItem.Cancel(element.hoverElement);
            element.hoverItem = null;
            element.hoverElement = null;
        }
    },
    ShowSubMenu: function(indexPath){
        var element = this.GetMenuElement(indexPath);
        if(element != null){
            var level = this.GetMenuLevel(indexPath);
            aspxGetMenuCollection().DoHidePopupMenus(null, level - 1, this.name, false,  element.id);

            if (!_aspxGetElementDisplay(element))
                this.DoShowPopupMenu(element, __aspxInvalidPosition, __aspxInvalidPosition, indexPath);
        }    
        this.ClearAppearTimer();
    },
    
    SelectItem: function(indexPath){
        var element = this.GetItemTextOrImageCell(indexPath);
        if(element != null)
            aspxGetStateController().SelectElementBySrcElement(element);
    },
    DeselectItem: function(indexPath){
        var element = this.GetItemTextOrImageCell(indexPath);
        if(element != null){
            var hoverItem = null;
            var hoverElement = null;
            var menuElement = this.GetMenuElement(indexPath);
            if (menuElement != null && _aspxIsExists(menuElement.hoverItem)){
                hoverItem = menuElement.hoverItem;
                hoverElement = menuElement.hoverElement;
                this.CancelSubMenuItemHoverItem(menuElement);
            }
            aspxGetStateController().DeselectElementBySrcElement(element);
            if(menuElement != null && hoverItem != null)
                this.ApplySubMenuItemHoverItem(menuElement, hoverItem, hoverElement);
        }
    },
    InitializeSelectedItem: function(){
        if(!this.allowSelectItem) return;
    
        var inputElement = this.GetSelectedItemInputElement();
        if(inputElement != null)
            this.SelectItem(inputElement.value);
    },
    SetSelectedItemInternal: function(indexPath, modifyHotTrackSelection){
        if(modifyHotTrackSelection)
            this.SetHoverElement(null);
        var inputElement = this.GetSelectedItemInputElement();
        if(inputElement != null){
            this.DeselectItem(inputElement.value);
            inputElement.value = indexPath;
            this.SelectItem(inputElement.value);
        }
        if(modifyHotTrackSelection){
            var element = this.GetItemTextOrImageCell(indexPath);
            if(element != null) 
                this.SetHoverElement(element);
        }
    },
    InitializeCheckedItems: function(){
        if(!this.allowCheckItems) return;
        
        var inputElement = this.GetCheckedItemsInputElement();
        if(inputElement != null){
            var indexPathes = inputElement.value.split(";");
            for(var i = 0; i < indexPathes.length; i ++){
                if(indexPathes[i] != ""){
                    _aspxArrayPush(this.checkedItems, indexPathes[i]);
                    this.SelectItem(indexPathes[i]);
                }
            }
        }
    },
    ChangeCheckedItem: function(indexPath){
        this.SetHoverElement(null);
        
        var inputElement = this.GetCheckedItemsInputElement();
        if(inputElement != null){
            var itemsGroup = this.GetItemsGroup(indexPath);
            if(itemsGroup != null){
                if(itemsGroup.length > 1){
                    if(!this.IsCheckedItem(indexPath)){
                        for(var i = 0; i < itemsGroup.length; i ++){
                            if(itemsGroup[i] == indexPath) continue;
                            if(this.IsCheckedItem(itemsGroup[i])){
                                _aspxArrayRemove(this.checkedItems, itemsGroup[i]);
                                this.DeselectItem(itemsGroup[i]);
                            }
                        }
                        this.SelectItem(indexPath);
                        _aspxArrayPush(this.checkedItems, indexPath);
                    }
                }
                else{
                    if(this.IsCheckedItem(indexPath)){
                        _aspxArrayRemove(this.checkedItems, indexPath);
                        this.DeselectItem(indexPath);
                    }
                    else{
                        this.SelectItem(indexPath);
                        _aspxArrayPush(this.checkedItems, indexPath);
                    }
                }
                this.UpdateCheckedInputElement(inputElement);
            }
        }
        
        var element = this.GetItemTextOrImageCell(indexPath);
        if(element != null) 
            this.SetHoverElement(element);
    },
    GetItemsGroup: function(indexPath){
        for(var i = 0; i < this.itemCheckedGroups.length; i ++){
            if(_aspxArrayIndexOf(this.itemCheckedGroups[i], indexPath) > -1)
                return this.itemCheckedGroups[i];
        }
        return null;
    },
    IsCheckedItem: function(indexPath){
        return _aspxArrayIndexOf(this.checkedItems, indexPath) > -1;
    },
    UpdateCheckedInputElement: function(inputElement){
        var state = "";
        for(var i = 0; i < this.checkedItems.length; i ++){
            state += this.checkedItems[i];
            if(i < this.checkedItems.length - 1)
                state += ";";
        }
        inputElement.value = state;
    },
    
    GetAnimationVerticalDirection: function(indexPath, popupPosition){
        var verticalDirection = (this.IsRootItem(indexPath) && !this.IsVertical(indexPath)) ? -1 : 0;
        if (popupPosition.isInverted) verticalDirection *= -1;
        return verticalDirection;
    },
    GetAnimationHorizontalDirection: function(indexPath, popupPosition){
        var horizontalDirection = (this.IsRootItem(indexPath) && !this.IsVertical(indexPath)) ? 0 : -1;
        if (popupPosition.isInverted) horizontalDirection *= -1;
        return horizontalDirection;
    },
    StartAnimation: function(animationDivElement, indexPath, horizontalPopupPosition, verticalPopupPosition){
        var element = this.GetMenuMainTable(animationDivElement);

        var clientX = horizontalPopupPosition.position;
        var clientY = verticalPopupPosition.position;
      
        _aspxInitAnimationDiv(animationDivElement, clientX, clientY, "aspxMATimer(\"" + this.name + "\", " + "\"" + indexPath + "\")", "");
      
        var verticalDirection = this.GetAnimationVerticalDirection(indexPath, verticalPopupPosition);
        var horizontalDirection = this.GetAnimationHorizontalDirection(indexPath, horizontalPopupPosition);
        var yPos = verticalDirection * element.offsetWidth;
        var xPos = horizontalDirection * element.offsetHeight;
      
        _aspxSetStylePosition(element, xPos, yPos);
        
        _aspxSetElementVisibility(animationDivElement, true);
        this.DoShowPopupMenuIFrame(animationDivElement, clientX, clientY, 0, 0, indexPath);
        this.DoShowPopupMenuBorderCorrector(animationDivElement, clientX, clientY, indexPath, 
            horizontalPopupPosition.isInverted, verticalPopupPosition.isInverted);

        animationDivElement.timerID = window.setTimeout(animationDivElement.onTimerString, this.animationDelay);
    },
    OnAnimationTimer: function(indexPath){
        var animationDivElement = this.GetMenuElement(indexPath);
        if(_aspxIsExists(animationDivElement)){
            var element = this.GetMenuMainTable(animationDivElement);
            var mainCell = this.GetMenuMainCell(element);   
            var iframeElement = this.GetMenuIFrameElement(indexPath);
        
            _aspxOnAnimationTimer(animationDivElement, element, mainCell, iframeElement, this.animationDelay, this.animationMaxDelay, __aspxMenuAnimationAccelerator);
        }
    },
    
    OnItemClick: function(indexPath, evt){
        var clickedLinkElement = _aspxGetParentByTagName(_aspxGetEventSource(evt), "A");
        var isLinkClicked = (clickedLinkElement != null && clickedLinkElement.href != __aspxAccessibilityEmptyUrl);
        var element = this.GetItemTextOrImageCell(indexPath);
        var linkElement = (element != null) ? _aspxGetChildByTagName(element, "A", 0) : null;
        if(linkElement != null && linkElement.href == __aspxAccessibilityEmptyUrl)
            linkElement = null;

        if(this.allowSelectItem)
            this.SetSelectedItemInternal(indexPath, true); 
        if(this.allowCheckItems)
            this.ChangeCheckedItem(indexPath); 
        this.DoItemClick(indexPath, isLinkClicked || (linkElement != null), evt);
        
        if(!isLinkClicked && linkElement != null) 
            _aspxNavigateUrl(linkElement.href, linkElement.target);
    },
    OnAfterItemOver: function(hoverItem, hoverElement){
        if(hoverItem.name == "" || this.lockHoverEvents) return;
        
        if(!this.showSubMenus) {
            this.savedCallbackHoverItem = hoverItem;
            this.savedCallbackHoverElement = hoverElement;
            return;
        }

        this.ClearDisappearTimer();
        this.ClearAppearTimer();

        var indexPath = this.GetMenuIndexPathById(hoverItem.name, false);
        if(indexPath == ""){
            indexPath = this.GetIndexPathById(hoverItem.name, true);
            var level = this.GetMenuLevel(indexPath);
            var menuElement = this.GetMenuElement(indexPath);
            var id = (menuElement != null) ? menuElement.id : "";
            aspxGetMenuCollection().DoHidePopupMenus(null, level - 1, this.name, false, id);

            if(hoverItem.enabled && hoverItem.kind == __aspxHoverItemKind){
                this.SetAppearTimer(indexPath);
                this.RaiseItemMouseOver(indexPath);
            }
        }
    },
    OnBeforeItemOver: function(hoverItem, hoverElement){
        if (__aspxNS && _aspxIsExists(hoverElement.offsetParent) && 
                hoverElement.offsetParent.style.borderCollapse == "collapse") {
            hoverElement.offsetParent.style.borderCollapse = "separate";
            hoverElement.offsetParent.style.borderCollapse = "collapse";
        }

        var indexPath = this.GetItemIndexPathById(hoverItem.name);
        var element = this.GetMenuElement(indexPath);
        if(_aspxIsExists(element)) this.CancelSubMenuItemHoverItem(element);  
    },
    OnItemOverTimer: function(indexPath){
        if(this.IsAppearTimerActive()){
            this.ClearAppearTimer();
            if(this.GetItemImageCell(indexPath) != null || this.GetItemIndentCell(indexPath) != null ||
                this.GetItemTextCell(indexPath) != null || this.GetItemPopOutImageCell(indexPath) != null){
                this.ShowSubMenu(indexPath);
            }
        }
    },
    OnBeforeItemDisabled: function(disabledItem, disabledElement){
        this.ClearAppearTimer();
        var indexPath = this.GetIndexPathById(disabledElement.id, false);
        if(indexPath != ""){
            var element = this.GetMenuElement(indexPath);
            if(element != null) this.DoHidePopupMenu(null, element);
        }
    },
    OnAfterItemOut: function(hoverItem, hoverElement, newHoverElement){
        if(!this.showSubMenus) {
            this.savedCallbackHoverItem = null;
            this.savedCallbackHoverElement = null;
        }
        
        if(hoverItem.name == "" || this.lockHoverEvents) return;
        if(hoverItem.IsChildElement(newHoverElement)) return;
        
        var indexPath = this.GetItemIndexPathById(hoverItem.name);
        var element = this.GetMenuElement(indexPath);
        
        this.ClearDisappearTimer();
        this.ClearAppearTimer();
        if(element == null || !_aspxGetIsParent(element, newHoverElement)) 
            this.SetDisappearTimer();
        
        if(element != null) 
            this.ApplySubMenuItemHoverItem(element, hoverItem, hoverElement);
            
        if(indexPath != "")
            this.RaiseItemMouseOut(indexPath);
    },
    OnItemOutTimer: function(){
        if(this.IsDisappearTimerActive()){
            this.ClearDisappearTimer();
            if(aspxGetMenuCollection().CheckFocusedElement())
                this.SetDisappearTimer();
            else
                aspxGetMenuCollection().DoHidePopupMenus(null, 0, this.name, true, "");
        }
    },
    OnFocusedItemKeyDown: function(evt, focusedItem, focusedElement){
        var handled = false;
        var indexPath = this.GetItemIndexPathById(focusedItem.name);
        switch(evt.keyCode){
            case ASPxKey.Tab: {
                handled = this.FocusNextTabItem(indexPath, evt.shiftKey);
                break;
            }
            case ASPxKey.Down: {
                if(this.IsVertical(indexPath)){
                    this.FocusNextItem(indexPath);
                }
                else{
                    this.ShowSubMenu(indexPath);
                    this.FocusItemByIndexPath(this.GetFirstChildIndexPath(indexPath));
                }
                handled = true;
                break;
            }
            case ASPxKey.Up: {
                if(this.IsVertical(indexPath)){
                    this.FocusPrevItem(indexPath);
                }
                else{
                    this.ShowSubMenu(indexPath);
                    this.FocusItemByIndexPath(this.GetFirstChildIndexPath(indexPath));
                }
                handled = true;
                break;
            }
            case ASPxKey.Left: {
                if(this.IsVertical(indexPath)){
                    var parentIndexPath = this.GetParentIndexPath(indexPath);
                    if(this.IsVertical(parentIndexPath)){
                        this.FocusItemByIndexPath(parentIndexPath);
                    }
                    else{
                        this.FocusPrevItem(parentIndexPath);
                    }
                }
                else{
                    this.FocusPrevItem(indexPath);
                }
                handled = true;
                break;
            }
            case ASPxKey.Right: {
                if(this.IsVertical(indexPath)){
                    if(this.HasChildren(indexPath)){
                        this.ShowSubMenu(indexPath);
                        this.FocusItemByIndexPath(this.GetFirstChildIndexPath(indexPath));
                    }
                    else{
                        while(!this.IsRootItem(indexPath))
                            indexPath = this.GetParentIndexPath(indexPath);
                        this.FocusNextItem(indexPath);
                    }
                }
                else{
                    this.FocusNextItem(indexPath);
                }
                handled = true;
                break;
            }
            case ASPxKey.Esc: {
                var parentIndexPath = this.GetParentIndexPath(indexPath);
                this.FocusItemByIndexPath(parentIndexPath);
                var element = this.GetMenuElement(parentIndexPath);
                if(element != null) {
                    this.DoHidePopupMenu(null, element);
                    handled = true;
                }
            }
        }
        if(handled)
            _aspxPreventEventAndBubble(evt);
    },
    FocusItemByIndexPath: function(indexPath){
        var element = this.GetItemTextOrImageCell(indexPath);
        var link = _aspxGetChildByTagName(element, "A", 0);
        if(link != null) _aspxSetFocus(link);
    },
    FocusNextTabItem: function(indexPath, shiftKey){
        if(this.IsRootItem(indexPath)) return false;
        while(true){
            if(this.IsRootItem(indexPath)) {
                if(!shiftKey){
                    if(this.GetNextSiblingIndexPath(indexPath) != null){
                        this.FocusNextItem(indexPath);
                        return true;
                    }
                }
                else{
                    if(this.GetPrevSiblingIndexPath(indexPath) != null){
                        this.FocusPrevItem(indexPath);
                        return true;
                    }
                }
                break;
            }
            else {
                if(!shiftKey){
                    if(this.GetNextSiblingIndexPath(indexPath) == null)
                        indexPath = this.GetParentIndexPath(indexPath);
                    else{
                        this.FocusNextItem(indexPath);
                        return true;
                    }
                }
                else{
                    if(this.GetPrevSiblingIndexPath(indexPath) == null)
                        indexPath = this.GetParentIndexPath(indexPath);
                    else{
                        this.FocusPrevItem(indexPath);
                        return true;
                    }
                }
            }
        }
        return false;
    },
    FocusNextItem: function(indexPath){
        var newIndexPath = this.GetNextSiblingIndexPath(indexPath);
        if(newIndexPath == null)
            newIndexPath = this.GetFirstSiblingIndexPath(indexPath);
        if(indexPath != newIndexPath)
            this.FocusItemByIndexPath(newIndexPath);
    },
    FocusPrevItem: function(indexPath){
        var newIndexPath = this.GetPrevSiblingIndexPath(indexPath);
        if(newIndexPath == null)
            newIndexPath = this.GetLastSiblingIndexPath(indexPath);
        if(indexPath != newIndexPath)
            this.FocusItemByIndexPath(newIndexPath);
    },
    Focus: function(){
        this.FocusNextItem("-1");
    },
    FocusLastItem: function(){
        this.FocusPrevItem(this.GetItemCount() - 1);
    },    
    OnCallback: function(result){
        _aspxInitializeScripts(); // to prevent double scripts loading and executing
        
        for(var indexPath in result){
            var menuElement = this.GetMenuElement(indexPath);
            if(_aspxIsExists(menuElement)){
                var mainCell = this.GetMenuMainCell(menuElement);   
                _aspxSetInnerHtml(mainCell, result[indexPath]);
            }
        }
        this.InitializeInternal(false);
        if(!this.showSubMenus){
            this.showSubMenus = true;
            if(this.savedCallbackHoverItem != null && this.savedCallbackHoverElement != null)
                this.OnAfterItemOver(this.savedCallbackHoverItem, this.savedCallbackHoverElement);
            this.savedCallbackHoverItem = null;
            this.savedCallbackHoverElement = null;
        }
    },
    
    // API
    CreateItems: function(itemsProperties){
        var itemType = this.GetClientItemType();
        this.rootItem = new itemType(this, null, 0, "");
        this.rootItem.CreateItems(itemsProperties);
    },
    GetClientItemType: function(){
        return ASPxClientMenuItem;
    },
    GetItemByIndexPath: function(indexPath){
        var item = this.rootItem;
        if(indexPath != "" && item != null){
            var indexes = this.GetItemIndexes(indexPath);
            for(var i = 0; i < indexes.length; i ++)
                item = item.GetItem(indexes[i]);
        }
        return item;
    },
    CheckSelectedItem: function(indexPath){
        var selectedItem = this.GetSelectedItem();
        if(selectedItem != null && selectedItem.GetIndexPath() == indexPath)
            this.SetSelectedItem(null);
    },
    SetItemChecked: function(indexPath, checked){
        var inputElement = this.GetCheckedItemsInputElement();
        if(inputElement != null){
            var itemsGroup = this.GetItemsGroup(indexPath);
            if(itemsGroup != null){
                if(!checked && this.IsCheckedItem(indexPath)){
                    _aspxArrayRemove(this.checkedItems, indexPath);
                    this.DeselectItem(indexPath);
                }
                else if(checked && !this.IsCheckedItem(indexPath)){
                    if(itemsGroup.length > 1){
                        for(var i = 0; i < itemsGroup.length; i ++){
                            if(itemsGroup[i] == indexPath) continue;
                            if(this.IsCheckedItem(itemsGroup[i])){
                                _aspxArrayRemove(this.checkedItems, itemsGroup[i]);
                                this.DeselectItem(itemsGroup[i]);
                            }
                        }
                    }
                    this.SelectItem(indexPath);
                    _aspxArrayPush(this.checkedItems, indexPath);
                }
                this.UpdateCheckedInputElement(inputElement);
            }
        }
    },
	ChangeEnabledAttributes: function(indexPath, method, styleMethod){
	    var itemElement = this.IsVertical(indexPath) ? this.GetItemElement(indexPath) : null;
        if(_aspxIsExists(itemElement))
            method(itemElement, "onclick");
        var templateElement = this.GetItemTemplateCell(indexPath);
        if(_aspxIsExists(templateElement))
            method(templateElement, "onclick");
        var imageElement = this.GetItemImageCell(indexPath);
        if(_aspxIsExists(imageElement)){
            method(imageElement, "onclick");
            styleMethod(imageElement, "cursor");
   	        var link = _aspxGetChildByTagName(imageElement, "A", 0);
   	        if(link != null){
   	            method(link, "onclick");
   	            method(link, "href");
            }
        }
        var textElement = this.GetItemTextCell(indexPath);
        if(_aspxIsExists(textElement)){
            method(textElement, "onclick");
            styleMethod(textElement, "cursor");
   	        var link = _aspxGetChildByTagName(textElement, "A", 0);
   	        if(link != null){
   	            method(link, "onclick");
   	            method(link, "href");
            }
   	        link = _aspxGetChildByTagName(textElement, "A", 1);
   	        if(link != null){
   	            method(link, "onclick");
   	            method(link, "href");
            }
        }
        var popOutImageElement = this.GetItemPopOutImageCell(indexPath);
        if(_aspxIsExists(popOutImageElement)){
            method(popOutImageElement, "onclick");
            styleMethod(popOutImageElement, "cursor");
        }
        var indentElement = this.GetItemIndentCell(indexPath);
        if(_aspxIsExists(indentElement)){
            method(indentElement, "onclick");
            styleMethod(indentElement, "cursor");
        }
	},
    IsItemEnabled: function(indexPath){
        var item = this.GetItemByIndexPath(indexPath);
        return (item != null) ? item.GetEnabled() : true;
    },
	SetItemEnabled: function(indexPath, enabled, initialization){
	    if(indexPath == "" || !this.GetItemByIndexPath(indexPath).enabled) return;

        if(!initialization || !enabled)
            this.ChangeItemEnabledStateItems(indexPath, enabled);
        this.ChangeItemEnabledAttributes(indexPath, enabled);
	},
	ChangeItemEnabledStateItems: function(indexPath, enabled){
	    var element = this.GetItemTextOrImageCell(indexPath);
	    if(element != null)
            aspxGetStateController().SetElementEnabled(element, enabled);
	},
	ChangeItemEnabledAttributes: function(indexPath, enabled){
	    var element = this.GetItemTextOrImageCell(indexPath);
	    if(element != null){
	        element.enabled = enabled;
	        if(!enabled)
	            this.CheckSelectedItem(indexPath);
	        this.ChangeEnabledAttributes(indexPath, _aspxChangeAttributesMethod(enabled), 
	            _aspxChangeStyleAttributesMethod(enabled));
	    }
	},
	GetItemImageUrl: function(indexPath){
        var element = this.GetItemImageCell(indexPath);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            return img.src;
        }
        element = this.GetItemTextCell(indexPath);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            return img.src;
        }
        return "";
	},
	SetItemImageUrl: function(indexPath, url){
        var element = this.GetItemImageCell(indexPath);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            img.src = url;
        }
        element = this.GetItemTextCell(indexPath);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            img.src = url;
        }
	},
	GetItemNavigateUrl: function(indexPath){
	    var element = this.GetItemTextCell(indexPath);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            return link.href;
	    }
	    element = this.GetItemImageCell(indexPath);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            return link.href;
	    }
	    return "";
	},
	SetItemNavigateUrl: function(indexPath, url){
	    var element = this.GetItemTextCell(indexPath);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            link.href = url;
	        link = _aspxGetChildByTagName(element, "A", 1);
	        if(link != null)
	            link.href = url;
	    }
	    element = this.GetItemImageCell(indexPath);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            link.href = url;
	    }
	},
	GetItemText: function(indexPath){
	    var element = this.GetItemTextCell(indexPath);
	    if(element != null){
	        var textNode = _aspxGetChildTextNode(element, 0);
	        if(textNode != null)
	            return textNode.nodeValue;
	    }
	    return "";
	},
	SetItemText: function(indexPath, text){
	    var element = this.GetItemTextCell(indexPath);
	    if(element != null){
	        var textNode = _aspxGetChildTextNode(element, 0);
	        if(textNode != null)
	            textNode.nodeValue = text;
	    }
	},
	SetItemVisible: function(indexPath, visible, initialization){
	    if(indexPath == "" || !this.GetItemByIndexPath(indexPath).visible) return;
	    if(visible && initialization) return;
	    
	    if(!visible)
            this.CheckSelectedItem(indexPath);
            
	    var element = null;
	    if(this.IsVertical(indexPath)){
	        element = this.GetItemElement(indexPath);
	        if(element != null)
	            _aspxSetElementDisplay(element, visible);
	    }
	    else{
	        element = this.GetItemTemplateCell(indexPath);
	        if(element != null)
	            _aspxSetElementDisplay(element, visible);
	        element = this.GetItemImageCell(indexPath);
	        if(element != null)
	            _aspxSetElementDisplay(element, visible);
	        element = this.GetItemTextCell(indexPath);
	        if(element != null)
	            _aspxSetElementDisplay(element, visible);
	        element = this.GetItemPopOutImageCell(indexPath);
	        if(element != null)
	            _aspxSetElementDisplay(element, visible);
	    }
        this.SetIndentsVisiblility(indexPath);
        this.SetSeparatorsVisiblility(indexPath);
	},
	SetIndentsVisiblility: function(indexPath){
	    var parent = this.GetItemByIndexPath(indexPath).parent;
        for(var i = 0; i < parent.GetItemCount(); i++){
            var item = parent.GetItem(i);
            var separatorVisible = item.GetVisible() && this.HasNextVisibleItems(parent, i);
            var element = this.GetItemIndentElement(item.GetIndexPath());
            if(element != null) _aspxSetElementDisplay(element, separatorVisible);
        }
	},
	SetSeparatorsVisiblility: function(indexPath){
	    var parent = this.GetItemByIndexPath(indexPath).parent;
        for(var i = 0; i < parent.GetItemCount(); i++){
            var item = parent.GetItem(i);
            var separatorVisible = item.GetVisible() && this.HasPrevVisibleItems(parent, i);
            var element = this.GetItemSeparatorElement(item.GetIndexPath());
            if(element != null) _aspxSetElementDisplay(element, separatorVisible);
            element = this.GetItemSeparatorIndentElement(item.GetIndexPath());
            if(element != null) _aspxSetElementDisplay(element, separatorVisible);
        }
	},
	HasNextVisibleItems: function(parent, index){
        for(var i = index + 1; i < parent.GetItemCount(); i++){
            if(parent.GetItem(i).GetVisible())
                return true;
        }
        return false;
	},
	HasPrevVisibleItems: function(parent, index){
        for(var i = index - 1; i >= 0; i--){
            if(parent.GetItem(i).GetVisible())
                return true;
        }
        return false;
	},

    GetItemIndentElement: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMIIdSuffix + indexPath + "_II");
    },
    GetItemSeparatorElement: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMIIdSuffix + indexPath + "_IS");
    },
    GetItemSeparatorIndentElement: function(indexPath){
        return _aspxGetElementById(this.name + __aspxMIIdSuffix + indexPath + "_ISI");
    },
    
    RaiseItemClick: function(indexPath, htmlEvent){
        var processOnServer = this.autoPostBack || this.IsServerEventAssigned("ItemClick");
        if(!this.ItemClick.IsEmpty()){
            var item = this.GetItemByIndexPath(indexPath);
            var htmlElement = this.GetItemTextOrImageCell(indexPath);
            var args = new ASPxClientMenuItemClickEventArgs(processOnServer, item, htmlElement, htmlEvent);
            this.ItemClick.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    },    
    RaiseItemMouseOver: function(indexPath){
        if(!this.ItemMouseOver.IsEmpty()){
            var item = this.GetItemByIndexPath(indexPath);
            var htmlElement = this.GetItemTextOrImageCell(indexPath);
            var args = new ASPxClientMenuItemMouseEventArgs(item, htmlElement);
            this.ItemMouseOver.FireEvent(this, args);
        }
    },
    RaiseItemMouseOut: function(indexPath){
        if(!this.ItemMouseOut.IsEmpty()){
            var item = this.GetItemByIndexPath(indexPath);
            var htmlElement = this.GetItemTextOrImageCell(indexPath);
            var args = new ASPxClientMenuItemMouseEventArgs(item, htmlElement);
            this.ItemMouseOut.FireEvent(this, args);
        }
    },
    RaisePopUp: function(indexPath){
        var item = this.GetItemByIndexPath(indexPath);
        if(!this.PopUp.IsEmpty()){
            var args = new ASPxClientMenuItemEventArgs(false, item);
            this.PopUp.FireEvent(this, args);
        }
    },
    RaiseCloseUp: function(indexPath){
        var item = this.GetItemByIndexPath(indexPath);
        if(!this.CloseUp.IsEmpty()){
            var args = new ASPxClientMenuItemEventArgs(false, item);
            this.CloseUp.FireEvent(this, args);
        }
    },
    GetItemCount: function(){
        return (this.rootItem != null) ? this.rootItem.GetItemCount() : 0;
    },
    GetItem: function(index){
        return (this.rootItem != null) ? this.rootItem.GetItem(index) : null;
    },
    GetItemByName: function(name){
        return (this.rootItem != null) ? this.rootItem.GetItemByName(name) : null;
    },
	GetSelectedItem: function(){
        var inputElement = this.GetSelectedItemInputElement();
        if(inputElement != null && inputElement.value != "")
            return this.GetItemByIndexPath(inputElement.value);
        return null;
	},
	SetSelectedItem: function(item){
	    var indexPath = (item != null) ? item.GetIndexPath() : "";
	    this.SetSelectedItemInternal(indexPath, false);
	}
});
ASPxClientMenuBase.GetMenuCollection = function(){
    return aspxGetMenuCollection();
}
ASPxClientMenuCollection = _aspxCreateClass(ASPxClientControlCollection, {
	constructor: function(){
		this.constructor.prototype.constructor.call(this);
        
        this.appearTimerID = -1;
        this.disappearTimerID = -1;
        this.visibleSubMenusMenuName = "";
        this.visibleSubMenuIds = new Array();
        this.overXPos = -1;
		this.overYPos = -1;
    },
    RegisterVisiblePopupMenu: function(name, id){
        _aspxArrayPush(this.visibleSubMenuIds, id);
        this.visibleSubMenusMenuName = name;
    },
    UnregisterVisiblePopupMenu: function(name, id){
        _aspxArrayRemove(this.visibleSubMenuIds, id);
        if(this.visibleSubMenuIds.length == 0)
            this.visibleSubMenusMenuName = "";
    },

    GetMenu: function(id){
        return this.Get(this.GetMenuName(id));
    },
    GetMenuName: function(id){
        var pos = id.lastIndexOf(__aspxMMIdSuffix);
        if(pos == -1) 
            pos = id.lastIndexOf(__aspxMIIdSuffix);
        if(pos > -1) 
            return id.substring(0, pos);
        return id;
    },
    GetMenuLevel: function(indexPath){
        if(indexPath == "")
            return 0;
        else{
            var indexes = this.GetItemIndexes(indexPath);
            return indexes.length;
        }
    },
    GetMenuLevelById: function(id, isMenu){    
        var indexPath = this.GetIndexPathById(id, isMenu);
        return this.GetMenuLevel(indexPath);
    },
    GetIndexPathById: function(id, isMenu){
        var idSuffix = isMenu ? __aspxMMIdSuffix : __aspxMIIdSuffix;
        var pos = id.lastIndexOf(idSuffix);
        if(pos > -1){
            id = id.substring(pos + idSuffix.length);
            pos = id.lastIndexOf("_");
            if(pos > -1) 
                return id.substring(0, pos);
        }
        return "";
    },
    GetItemIndexPath: function(indexes){
        var indexPath = "";
        for(var i = 0; i < indexes.length; i ++){
            indexPath += indexes[i];
            if(i < indexes.length - 1)
                indexPath += __aspxItemIndexSeparator;
        }
        return indexPath;
    },
    GetItemIndexes: function(indexPath){
        var indexes = indexPath.split(__aspxItemIndexSeparator);
        for(var i = 0; i < indexes.length; i ++)
            indexes[i] = parseInt(indexes[i]);
        return indexes;
    },
    ClearAppearTimer: function(){
        this.appearTimerID = _aspxClearTimer(this.appearTimerID);
    },
    ClearDisappearTimer: function(){
        this.disappearTimerID = _aspxClearTimer(this.disappearTimerID);
    },
    IsAppearTimerActive: function(){
        return this.appearTimerID > -1;
    },
    IsDisappearTimerActive: function(){
        return this.disappearTimerID > -1;
    },
    SetAppearTimer: function(name, indexPath, timeout){
        this.appearTimerID = _aspxSetTimeout("aspxMIMOverTimer(\"" + name + "\", \"" + indexPath + "\")", timeout);
    },
    SetDisappearTimer: function(name, timeout){
        this.disappearTimerID = _aspxSetTimeout("aspxMIMOutTimer(\"" + name + "\")", timeout);
    },
    
    GetMouseDownMenuLevel: function(evt){
        var srcElement = _aspxGetEventSource(evt);
        if(this.visibleSubMenusMenuName != ""){
            var element = _aspxGetParentById(srcElement, this.visibleSubMenusMenuName);
            if(element != null) return 1;
        }
        for(var i = 0; i < this.visibleSubMenuIds.length; i ++){
            var element = _aspxGetParentById(srcElement, this.visibleSubMenuIds[i]);
            if(element != null)
                return this.GetMenuLevelById(this.visibleSubMenuIds[i], true) + 1;
        }
        return -1;
    },
    CheckFocusedElement: function(){
        try {
            if(document.activeElement != null) {
                for(var i = 0; i < this.visibleSubMenuIds.length; i ++) {
                    var menuElement = _aspxGetElementById(this.visibleSubMenuIds[i]);
                    if(menuElement != null && _aspxGetIsParent(menuElement, document.activeElement)) {
                        var tagName = document.activeElement.tagName;
                        if (!__aspxIE || tagName == "INPUT" || tagName == "TEXTAREA" || tagName == "SELECT")
                            return true;                
                    }
                }
            }
	    } catch(e) {

	    }
        return false;
    },
    DoHidePopupMenus: function(evt, level, name, leavePopups, exceptId){
        for(var i = this.visibleSubMenuIds.length - 1; i >=0 ; i --){
            var menu = this.GetMenu(this.visibleSubMenuIds[i]);
            if(menu != null){
                var menuLevel = this.GetMenuLevelById(this.visibleSubMenuIds[i], true);
                if((!leavePopups || menuLevel > 0) && exceptId != this.visibleSubMenuIds[i]){
                    if(menuLevel > level || (menu.name != name && name != "")){
                        var element = _aspxGetElementById(this.visibleSubMenuIds[i]);
                        if(element != null)
                            menu.DoHidePopupMenu(evt, element);
                    }
                }
            }
        }
    },
    DoShowAtCurrentPos: function(name, indexPath){
        var pc = this.Get(name);
        var element = pc.GetMainElement();
        if(pc != null && !_aspxGetElementDisplay(element))
            pc.DoShowPopupMenu(element, this.overXPos, this.overYPos, indexPath);
    },
    SaveCurrentMouseOverPos: function(evt){
        this.overXPos = _aspxGetEventX(evt);
        this.overYPos = _aspxGetEventY(evt);
    },
    
    OnMouseDown: function(evt){
        var menuLevel = this.GetMouseDownMenuLevel(evt);
        this.DoHidePopupMenus(evt, menuLevel, "", false, "");
    },
    HideAll: function(){
        this.DoHidePopupMenus(null, -1, "", false, "");
    }
});

var __aspxMCollection = null;
function aspxGetMenuCollection(){
    if(__aspxMCollection == null)
        __aspxMCollection = new ASPxClientMenuCollection();
    return __aspxMCollection;
}
ASPxClientMenuItem = _aspxCreateClass(null, {
	constructor: function(menu, parent, index, name){
	    this.menu = menu;
	    this.parent = parent;
        this.index = index;
        this.name = name;
        
        this.enabled = true;
        this.clientEnabled = true;
        this.visible = true;
        this.clientVisible = true;
        this.items = []; 
        this.indexPath = null; 
    },
    CreateItems: function(itemsProperties){
        var itemType = this.menu.GetClientItemType();
        for(var i = 0; i < itemsProperties.length; i ++){
            var itemName = _aspxIsExists(itemsProperties[i][0]) ? itemsProperties[i][0] : "";
            var item = new itemType(this.menu, this, i, itemName);
            if(_aspxIsExists(itemsProperties[i][1]))
                item.enabled = itemsProperties[i][1];
            if(_aspxIsExists(itemsProperties[i][2]))                
                item.clientEnabled = itemsProperties[i][2];
            if(_aspxIsExists(itemsProperties[i][3]))
                item.visible = itemsProperties[i][3];
            if(_aspxIsExists(itemsProperties[i][4]))
                item.clientVisible = itemsProperties[i][4];
            _aspxArrayPush(this.items, item);
            item.CreateItems(itemsProperties[i][5]);
        }
    },
    GetIndexPath: function(){
        if(this.indexPath == null){
            this.indexPath = "";
            var item = this;
            while(item.parent != null){
                this.indexPath = (this.indexPath != "") ? item.index.toString() + __aspxItemIndexSeparator + this.indexPath : item.index.toString();
                item = item.parent;
            }
        }
        return this.indexPath;
    },
    GetItemCount: function(){
        return this.items.length;
    },
    GetItem: function(index){
        return (0 <= index && index < this.items.length) ? this.items[index] : null;
    },
    GetItemByName: function(name){
        for(var i = 0; i < this.items.length; i ++)
            if(this.items[i].name == name) return this.items[i];
        for(var i = 0; i < this.items.length; i ++){
            var item = this.items[i].GetItemByName(name);
            if(item != null) return item;
        }
        return null;
    },
	GetChecked: function(){
	    var indexPath = this.GetIndexPath();
	    return this.menu.IsCheckedItem(indexPath);
	},
	SetChecked: function(value){
	    var indexPath = this.GetIndexPath();
	    this.menu.SetItemChecked(indexPath, value);
	},
	GetEnabled: function(){
        return this.enabled && this.clientEnabled;
	},
	SetEnabled: function(value){
        if (this.clientEnabled != value) {
            this.clientEnabled = value;
	        this.menu.SetItemEnabled(this.GetIndexPath(), value, false);
	    }
	},
	GetImageUrl: function(){
	    var indexPath = this.GetIndexPath();
	    return this.menu.GetItemImageUrl(indexPath);
	},
	SetImageUrl: function(value){
	    var indexPath = this.GetIndexPath();
	    this.menu.SetItemImageUrl(indexPath, value);
	},
	GetNavigateUrl: function(){
	    var indexPath = this.GetIndexPath();
	    return this.menu.GetItemNavigateUrl(indexPath);
	},
	SetNavigateUrl: function(value){
	    var indexPath = this.GetIndexPath();
	    this.menu.SetItemNavigateUrl(indexPath, value);
	},
	GetText: function(){
	    var indexPath = this.GetIndexPath();
	    return this.menu.GetItemText(indexPath);
	},
	SetText: function(value){
	    var indexPath = this.GetIndexPath();
	    this.menu.SetItemText(indexPath, value);
	},
	GetVisible: function(){
	    return this.visible && this.clientVisible;
	},
	SetVisible: function(value){
        if (this.clientVisible != value) {
            this.clientVisible = value;
	        this.menu.SetItemVisible(this.GetIndexPath(), value, false);
	    }
	},
	
	InitializeEnabledAndVisible: function(recursive){
	    this.menu.SetItemEnabled(this.GetIndexPath(), this.clientEnabled, true);
	    this.menu.SetItemVisible(this.GetIndexPath(), this.clientVisible, true);
	    if(recursive) {
	        for(var i = 0; i < this.items.length; i++)
	            this.items[i].InitializeEnabledAndVisible(recursive);
	    }
	}
});
ASPxClientMenu = _aspxCreateClass(ASPxClientMenuBase, {
	constructor: function(name){
		this.constructor.prototype.constructor.call(this, name);
        this.isVertical = false;
    },

    IsVertical: function(indexPath){
        return this.isVertical || (indexPath.indexOf(__aspxItemIndexSeparator) > -1);
    }
});
ASPxClientMenuItemEventArgs = _aspxCreateClass(ASPxClientProcessingModeEventArgs, {
    constructor: function(processOnServer, item) {
        this.constructor.prototype.constructor.call(this, processOnServer);
        this.item = item;
    }
});
ASPxClientMenuItemMouseEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
    constructor: function(item, htmlElement) {
        this.constructor.prototype.constructor.call(this);
        this.item = item;
        this.htmlElement = htmlElement;
    }
});
ASPxClientMenuItemClickEventArgs = _aspxCreateClass(ASPxClientMenuItemEventArgs, {
    constructor: function(processOnServer, item, htmlElement, htmlEvent) {
        this.constructor.prototype.constructor.call(this, processOnServer, item);
        this.htmlElement = htmlElement;
        this.htmlEvent = htmlEvent;        
    }
});

function aspxMIClick(evt, name, indexPath){
    var menu = aspxGetMenuCollection().Get(name);
    if(menu != null) menu.OnItemClick(indexPath, evt);
    if(!__aspxNS)
        evt.cancelBubble = true;
    return true;
}
function aspxAMIMOver(source, args){
    var menu = aspxGetMenuCollection().GetMenu(args.item.name);
    if(menu != null) menu.OnAfterItemOver(args.item, args.element);
}
function aspxBMIMOver(source, args){
    var menu = aspxGetMenuCollection().GetMenu(args.item.name);
    if(menu != null) menu.OnBeforeItemOver(args.item, args.element);
}
function aspxMIMOverTimer(name, indexPath){
    var menu = aspxGetMenuCollection().Get(name);
    if(menu != null) menu.OnItemOverTimer(indexPath);
}
function aspxBIDisabled(source, args){
    var menu = aspxGetMenuCollection().GetMenu(args.item.name);
    if(menu != null) menu.OnBeforeItemDisabled(args.item, args.element);
}
function aspxFIKeyDown(source, args){
    var menu = aspxGetMenuCollection().GetMenu(args.item.name);
    if(menu != null) menu.OnFocusedItemKeyDown(args.htmlEvent, args.item, args.element);
}
function aspxAMIMOut(source, args){
    var menu = aspxGetMenuCollection().GetMenu(args.item.name);
    if(menu != null) menu.OnAfterItemOut(args.item, args.element, args.toElement);
}
function aspxMIMOutTimer(name){
    var menu = aspxGetMenuCollection().Get(name);
    if(menu != null) menu.OnItemOutTimer();
}
function aspxMContextMenu(evt){
    return _aspxCancelBubble(evt);
}

_aspxAttachEventToDocument("mousedown", aspxMenuDocumentMouseDown);
function aspxMenuDocumentMouseDown(evt){
    return aspxGetMenuCollection().OnMouseDown(evt);	
}

function aspxMATimer(name, indexPath){
    var menu = aspxGetMenuCollection().Get(name);
    if(menu != null) menu.OnAnimationTimer(indexPath);
}

aspxAddAfterSetFocusedState(aspxAMIMOver);
aspxAddAfterClearFocusedState(aspxAMIMOut);
aspxAddAfterSetHoverState(aspxAMIMOver);
aspxAddAfterClearHoverState(aspxAMIMOut);
aspxAddBeforeSetFocusedState(aspxBMIMOver);
aspxAddBeforeSetHoverState(aspxBMIMOver);
aspxAddBeforeDisabled(aspxBIDisabled);
aspxAddFocusedItemKeyDown(aspxFIKeyDown);
ASPxClientPopupMenu = _aspxCreateClass(ASPxClientMenuBase, {
	constructor: function(name){
		this.constructor.prototype.constructor.call(this, name);
        
        this.popupAction = "RightMouseClick";
        this.popupElementID = "";
        this.popupElement = null;
        this.popupHorizontalOffset = 0;
        this.popupVerticalOffset = 0;
        this.popupHorizontalAlign = __aspxNotSetAlignIndicator;
        this.popupVerticalAlign = __aspxNotSetAlignIndicator;
        this.left = 0;
        this.top = 0;
        this.shadowHeight = 5;
        this.shadowWidth = 5;
    },    
    Initialize: function(){
        this.GetPopupElement();
        ASPxClientMenuBase.prototype.Initialize.call(this);
    },
    
    GetPopupElement: function(){
        if(!_aspxIsExistsElement(this.popupElement)){
            this.popupElement = _aspxFindPopupElementById(this.popupElementID);
            if(_aspxIsExistsElement(this.popupElement)){
                this.popupElement.DXMenu = this;
                if(this.popupAction == "LeftMouseClick")
                    _aspxAttachEventToElement(this.popupElement, "mouseup", aspxMEvent);
                else if(this.popupAction == "RightMouseClick")
                    _aspxAttachEventToElement(this.popupElement, "contextmenu", aspxMEvent);
                else if(this.popupAction == "MouseOver"){
                    _aspxAttachEventToElement(this.popupElement, "mouseover", aspxMEvent);
                    _aspxAttachEventToElement(this.popupElement, "mouseout", aspxMEvent);
                }
                
                if (this.popupAction == "LeftMouseClick"){
                    _aspxAttachEventToElement(this.popupElement, "mousedown", aspxMEvent);
                    this.popupElement.isPopuped = false;
                }
            }
        }
        return this.popupElement;
    },
    IsMenuVisible: function(){
        var element = this.GetMainElement();
        return (element != null) ? _aspxGetElementDisplay(element) : false;
    },
    IsParentElementPositionStatic: function(indexPath){
        return false;
    },
    GetClientSubMenuPos: function(element, indexPath, pos, isXPos){
        if (indexPath == "") {
            var popupPosition = null;
            if (isXPos){
                popupPosition = _aspxGetPopupAbsoluteX(this.GetMenuMainCell(this.GetMainElement()),
                    this.shadowWidth, this.GetPopupElement(), this.popupHorizontalAlign, this.popupHorizontalOffset, pos, this.left);
            }
            else{
                popupPosition = _aspxGetPopupAbsoluteY(this.GetMenuMainCell(this.GetMainElement()), 
                    this.shadowHeight, this.GetPopupElement(), this.popupVerticalAlign, this.popupVerticalOffset, pos, this.top);
            }
            popupPosition.position -= _aspxGetPositionElementOffset(element, isXPos);
            return popupPosition;
        }
        return ASPxClientMenuBase.prototype.GetClientSubMenuPos.call(this, element, indexPath, pos, isXPos);
    },
    GetMenuElement: function(indexPath){
        if (indexPath == "")
            return this.mainElement;
        return ASPxClientMenuBase.prototype.GetMenuElement.call(this, indexPath);
    },

    OnItemOverTimer: function(indexPath){
        if(indexPath == ""){
            aspxGetMenuCollection().DoHidePopupMenus(null, -1, this.name, false, "");
            aspxGetMenuCollection().DoShowAtCurrentPos(this.name, indexPath);
        }
        else
            ASPxClientMenuBase.prototype.OnItemOverTimer.call(this, indexPath);
    },
    DoShow: function(x, y){
        var element = this.GetMainElement();
        if(element != null && !_aspxGetElementDisplay(element)){
            aspxGetMenuCollection().DoHidePopupMenus(null, -1, this.name, false, "");

            this.DoShowPopupMenu(element, x, y, "");
        }
    },
    DoShowByAPI: function(x, y){
        var enableAnimationBackup = this.enableAnimation;
        this.enableAnimation = false;
        this.DoShow(x, y);
        this.enableAnimation = enableAnimationBackup;
    },
    DoHidePopupMenu: function(evt, element){
        if ((__aspxNS || __aspxSafariFamily) && _aspxIsExists(evt) && this.GetPopupElement() != null 
            && _aspxIsExists(this.GetPopupElement().isPopuped)){
            if (_aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupMenuElement) == this.GetPopupElement()) {
                this.GetPopupElement().isPopuped = true;
            }
        }
        ASPxClientMenuBase.prototype.DoHidePopupMenu.call(this, evt, element);
    },
    DoShowPopupMenuBorderCorrector: function(element, x, y, indexPath, toTheLeft, toTheTop){
        if (indexPath != "")
            ASPxClientMenuBase.prototype.DoShowPopupMenuBorderCorrector.call(this, element, x, y, indexPath, toTheLeft, toTheTop);
    },
    ShowInternal: function(evt){
        var x = _aspxGetEventX(evt);
        var y = _aspxGetEventY(evt);
        if (evt.type == "mouseover")
            aspxGetMenuCollection().SetAppearTimer(this.name, "", this.appearAfter);
        else
            this.DoShow(x, y);
    },
    GetAnimationHorizontalDirection: function(indexPath, popupPosition){
        if (this.GetMenuLevel(indexPath) == 0)
            return _aspxGetAnimationHorizontalDirection(popupPosition, this.popupHorizontalAlign, this.popupVerticalAlign);
        else 
            return popupPosition.isInverted ? 1 : -1;
    },
    GetAnimationVerticalDirection: function(indexPath, popupPosition){
        if (this.GetMenuLevel(indexPath) == 0)
            return _aspxGetAnimationVerticalDirection(popupPosition, this.popupHorizontalAlign, this.popupVerticalAlign);
        else 
            return 0;
    },
    // API
    ReplacePopupElementID: function(newPopupElementID){
        var popupElementIDBackup = this.popupElementID;
        this.popupElementID = newPopupElementID;
        this.popupElement = null;
        this.GetPopupElement();
        return popupElementIDBackup;
    },
    Hide: function(){
        var element = this.GetMainElement();
        if(element != null) this.DoHidePopupMenu(null, element);
    },
    Show: function(){
        this.DoShowByAPI(__aspxInvalidPosition, __aspxInvalidPosition);
    },
    ShowAtElement: function(htmlElement){
        var popupElementBackup = this.popupElement;
        this.popupElement = htmlElement;
        this.DoShowByAPI(__aspxInvalidPosition, __aspxInvalidPosition);
        this.popupElement = popupElementBackup;
    },
    ShowAtElementByID: function(id){
        var htmlElement = document.getElementById(id);
        this.ShowAtElement(htmlElement);
    },
    ShowAtPos: function(x, y){
        var popupElementIDBackup = this.ReplacePopupElementID("");
        this.DoShowByAPI(x, y);
        this.ReplacePopupElementID(popupElementIDBackup);
    },
    
    GetVisible: function(){
        return this.IsMenuVisible();
    },
    SetVisible: function(visible){
        if(visible && !this.IsMenuVisible())
            this.Show();
        else if(!visible && this.IsMenuVisible())
            this.Hide();
    }
});

function aspxMEvent(evt){
    var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupMenuElement);
	if(element != null) {
        if (evt.type == "mouseout")
            return aspxPMOnMouseOut(evt, element);
        else if (evt.type == "mouseover")
            return aspxPMOnMouseOver(evt, element);
        else if (evt.type == "mousedown")
            return aspxPMOnMouseDown(evt, element);
        else
            return aspxPMOnMouseUp(evt, element);
    }
}
function aspxPMOnMouseDown(evt, element){
    if (!__aspxNS && !__aspxSafariFamily && _aspxIsExists(element.isPopuped))
        element.isPopuped = element.DXMenu.IsMenuVisible();
}
function aspxPMOnMouseUp(evt, element){
    if (element.DXMenu.popupAction=="RightMouseClick" || _aspxGetIsLeftButtonPressed(evt)) {
        if (element.DXMenu.popupAction=="RightMouseClick")
            _aspxPreventContextMenu(evt);
        if (element.isPopuped != true)
            element.DXMenu.ShowInternal(evt);
        else if ((__aspxNS || __aspxSafariFamily) && _aspxIsExists(element.isPopuped))
            element.isPopuped = false;
        return _aspxCancelBubble(evt);
    }
}
function aspxPMOnMouseOver(evt, element){
    if(!element.DXMenu.IsMenuVisible())
        element.DXMenu.ShowInternal(evt);
}
function aspxPMOnMouseOut(evt, element){
    if(!element.DXMenu.IsMenuVisible())
        aspxGetMenuCollection().ClearAppearTimer();
}

function aspxTestPopupMenuElement(element){
    return _aspxIsExists(element.DXMenu);
}
_aspxAttachEventToDocument("mousemove", aspxPopupControlDocumentMouseMove);
function aspxPopupControlDocumentMouseMove(evt){
    if (aspxGetMenuCollection().IsAppearTimerActive()){
        var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupMenuElement);
	    if(element != null && !element.DXMenu.IsMenuVisible())
	        aspxGetMenuCollection().SaveCurrentMouseOverPos(evt);
	}
}
ASPxClientTabControlBase = _aspxCreateClass(ASPxClientControl, {
	constructor: function(name){
		this.constructor.prototype.constructor.call(this, name);

        this.activeTabIndex = 0;
        this.callbackCount = 0;
        this.cookieName = "";
        this.emptyHeight = false;
        this.emptyWidth = false;
        this.tabAlign = "Left";
        this.tabPosition = "Top";
        this.tabCount = 0;
        this.tabs = [];
        this.tabsContentRequest = [];
        this.handleClickOnWholeTab = true;
        this.TabClick = new ASPxClientEvent();
        this.ActiveTabChanged = new ASPxClientEvent();
        this.ActiveTabChanging = new ASPxClientEvent();
        
        this.InitializeOnResize();
	},
    Initialize: function(){
        this.constructor.prototype.Initialize.call(this);
        this.CorrrectCellsBounds(true); // if the size depends on layout
    },
    InlineInitialize: function(){
        this.InitializeEnabledAndVisible();
        this.CorrrectCellsBounds(true);
    },
    InitializeEnabledAndVisible: function(){
        for(var i = 0; i < this.tabs.length; i++){
            this.SetTabVisible(i, this.tabs[i].clientVisible, true);
            this.SetTabEnabled(i, this.tabs[i].clientEnabled, true);
        }    
	},
    InitializeCallBackData: function(){
        var element = this.GetContentElement(this.activeTabIndex);
        if(element != null) element.loaded = true;
    },
    InitializeOnResize: function(){
        var element = this.GetMainElement();
        if(_aspxIsExists(element))
            element.onresize = new Function("aspxTCResize(\"" + this.name + "\");");	
    },

    GetTabsCell: function(){
        return this.GetChild("_TC");
    },
    GetTabElement: function(index, active){
        return this.GetChild("_" + (active ? "A" : "") + "T" + index);
    },
    GetContentsCell: function(){
        return this.GetChild("_CC");
    },
    GetContentElement: function(index){
        return this.GetChild("_C" + index);
    },
    GetSeparatorElement: function(index){
        return this.GetChild("_T" + index + "S");
    },
    GetLeftAlignCellElement: function(){
        return this.GetChild("_LAC");
    },
    GetRightAlignCellElement: function(){
        return this.GetChild("_RAC");
    },
    GetTabLayoutElement: function(element){
        if(!this.IsTopBottomTabPosition())
            return element.parentNode;
        return element;
    },

    GetActiveTabIndexInputElement: function(index){
        return _aspxGetElementById(this.name + "ATI");
    },

    IsTopBottomTabPosition: function(){
        return (this.tabPosition == "Top" || this.tabPosition == "Bottom");
    },

    CorrrectCellsBounds: function(initialization){
        if(this.isInitialized || initialization)
            window.setTimeout("aspxTCCorrectBounds(\"" + this.name + "\");", 1);
    },
    CorrrectCellsBoundsTimer: function(){
        var mainElement = this.GetMainElement();
        if(mainElement == null || mainElement.offsetWidth == 0 || mainElement.offsetHeight == 0) return;

        mainElement.corrected = true;
   	    if(__aspxIE && !this.emptyHeight && this.tabAlign != "Justify"){
            if(this.IsTopBottomTabPosition())
                this.CorrectContentCellHeight();
            else
                this.CorrectAlignCellsHeight();
        }
        if(this.emptyHeight && !this.IsTopBottomTabPosition()){
            this.CorrectTabsCellHeight();
            if(__aspxIE)
                this.CorrectAlignCellsHeight();
        }
        if(this.emptyWidth && this.IsTopBottomTabPosition() && this.tabAlign != "Justify")
            this.CorrectTabsCellWidth();
        this.CorrectOperaTabsCellAlignment();
        this.CorrectOperaTabCellsAlignment();
    },
    CorrectTabsCellHeight: function(){
        var mainElement = this.GetMainElement();
        var tabsCell = this.GetTabsCell();
        if(mainElement != null && tabsCell){
            var leftAlignCell = this.GetLeftAlignCellElement();
            if(leftAlignCell != null)
                leftAlignCell.style.height = "auto";
            var rightAlignCell = this.GetRightAlignCellElement();
            if(rightAlignCell != null)
                rightAlignCell.style.height = "auto";
                
            tabsCell.style.height = "auto";
            tabsCell.style.height = mainElement.offsetHeight + "px";
            
            if(leftAlignCell != null && rightAlignCell == null)
                leftAlignCell.style.height = "100%";
            if(leftAlignCell == null && rightAlignCell != null)
                rightAlignCell.style.height = "100%";
            if(leftAlignCell != null && rightAlignCell != null){
                leftAlignCell.style.height = "50%";
                rightAlignCell.style.height = "50%";
            }
        }
    },
    CorrectTabsCellWidth: function(){
        var mainElement = this.GetMainElement();
        var tabsCell = this.GetTabsCell();
        if(mainElement != null && tabsCell){
            var leftAlignCell = this.GetLeftAlignCellElement();
            if(leftAlignCell != null)
                leftAlignCell.style.width = "auto";
            var rightAlignCell = this.GetRightAlignCellElement();
            if(rightAlignCell != null)
                rightAlignCell.style.width = "auto";
                
            tabsCell.style.width = "auto";
            tabsCell.style.width = mainElement.clientWidth;
            
            if(leftAlignCell != null && rightAlignCell == null)
                leftAlignCell.style.width = "100%";
            if(leftAlignCell == null && rightAlignCell != null)
                rightAlignCell.style.width = "100%";
            if(leftAlignCell != null && rightAlignCell != null){
                leftAlignCell.style.width = "50%";
                rightAlignCell.style.width = "50%";
            }
        }
    },
    CorrectContentCellHeight: function(){
        var mainElement = this.GetMainElement();
        var tabsCell = this.GetTabsCell();
        var contentsCell = this.GetContentsCell();
        if(mainElement != null && tabsCell != null && contentsCell != null){
            var tabsHeight = tabsCell.clientHeight;
            tabsCell.style.height = tabsHeight + "px";
            contentsCell.style.height = "auto";
            contentsCell.style.height = (mainElement.clientHeight - tabsHeight) + "px";
        }
    },
    CorrectAlignCellsHeight: function(){
        var mainElement = this.GetMainElement();
        var tabsCell = this.GetTabsCell();
        if(mainElement != null && tabsCell != null){
            var leftAlignCell = this.GetLeftAlignCellElement();
            var rightAlignCell = this.GetRightAlignCellElement();
            var tabsTable = tabsCell.firstChild;
            if(tabsTable != null){
                if(leftAlignCell != null || rightAlignCell != null){
                    var tabsHeight = 0;
                    for(var i = 0; i < tabsTable.rows.length; i ++){
                        var cell = tabsTable.rows[i].cells[0];
                        if(cell != leftAlignCell && cell != rightAlignCell)
                            tabsHeight += cell.offsetHeight;
                    }
                    if(leftAlignCell != null)
                        leftAlignCell.style.height = "auto";
                    if(rightAlignCell != null)
                        rightAlignCell.style.height = "auto";
                    var correctionHeight = mainElement.clientHeight - tabsHeight;
                    if(leftAlignCell != null)
                        leftAlignCell.style.height = ((rightAlignCell != null) ? Math.round(correctionHeight / 2) : correctionHeight) + "px";
                    if(rightAlignCell != null)
                        rightAlignCell.style.height = ((leftAlignCell != null) ? Math.round(correctionHeight / 2) : correctionHeight) + "px";
                }
            }
        }
    },
    CorrectOperaTabsCellAlignment: function(){ // Fix for __aspxOpera bug
        if(!__aspxOpera || this.tabAlign != "Justify") return;
        if(!this.IsTopBottomTabPosition() && !this.emptyHeight) return;
        
        var element = this.GetTabsCell();
        _aspxSetElementDisplay(element, false);
        _aspxSetElementDisplay(element, true);
    },
    CorrectOperaTabCellsAlignment: function(){ // Fix for __aspxOpera bug
        if(!__aspxOpera || !this.IsTopBottomTabPosition()) return;

        var element = this.GetLeftAlignCellElement();
        if(element != null){ 
            _aspxSetElementDisplay(element, false);
            _aspxSetElementDisplay(element, true);
        }
        element = this.GetRightAlignCellElement();
        if(element != null){ 
            _aspxSetElementDisplay(element, false);
            _aspxSetElementDisplay(element, true);
        }
        for(var i = 0; i < this.tabCount; i ++){
            if(this.activeTabIndex == i) continue;
            element = this.GetTabElement(i, false);
            if(element != null){
                _aspxSetElementDisplay(element, false);
                _aspxSetElementDisplay(element, true);
            }
        }
    },
    
    FixControlSize: function(){
        this.FixElementSize(this.GetMainElement());
        this.FixElementSize(this.GetContentsCell());
    },
    UnfixControlSize: function(){
        this.UnfixElementSize(this.GetMainElement());
        this.UnfixElementSize(this.GetContentsCell());
    },
    FixElementSize: function(element){
        if(element == null) return;
        _aspxChangeStyleAttribute(element, "width", (__aspxIE ? element.clientWidth : element.offsetWidth) + "px");
        _aspxChangeStyleAttribute(element, "height", (__aspxIE ? element.clientHeight : element.offsetHeight) + "px");
    },
    UnfixElementSize: function(element){
        if(element == null) return;
        _aspxRestoreStyleAttribute(element, "width");
        _aspxRestoreStyleAttribute(element, "height");
    },
    
    ChangeTabState: function(index, active){
        var element = this.GetTabElement(index, true);
        if(element != null) _aspxSetElementDisplay(this.GetTabLayoutElement(element), active);
        element = this.GetTabElement(index, false);
        if(element != null) _aspxSetElementDisplay(this.GetTabLayoutElement(element), !active);
        element = this.GetContentElement(index);
        if(element != null) _aspxSetElementDisplay(element, active);
    },
    ChangeActiveTab: function(index, hasLink){
        var processingMode = this.RaiseActiveTabChanging(index);
        if(processingMode == "Client" || processingMode == "ClientWithReload"){
            var element = this.GetContentElement(index);
            if(_aspxIsFunction(this.callBack) && element != null && (!element.loaded || processingMode == "ClientWithReload")){
                if(this.callbackCount == 0)
                    this.FixControlSize();
                this.DoChangeActiveTab(index);
                if(!element.loading){
                    this.callbackCount++;
                    element.loading = true;
                    
                    this.CreateLoadingPanelWithAbsolutePosition(element, this.GetContentsCell());
                    this.CreateCallback(index);
                    _aspxArrayPush(this.tabsContentRequest, index);
                }
                this.CorrectOperaTabCellsAlignment();
            }
            else{
                this.DoChangeActiveTab(index);

                this.CorrrectCellsBounds(false);
                this.CorrectOperaTabCellsAlignment();
                
                var activeContentElement = this.GetContentElement(this.activeTabIndex);
                var collection = aspxGetControlCollection();
                collection.AdjustControls(activeContentElement, __aspxCheckSizeCorrectedFlag);

                this.RaiseActiveTabChanged(index);
            }
        }
        else if(processingMode == "Server"  && !hasLink)
            this.SendPostBack("ACTIVATE:" + index);
    },
    DoChangeActiveTab: function(index){
        if(__aspxFirefox3){ // FIX flicks
            var contentsCell = this.GetContentsCell();
            var isContentsCellExists = _aspxIsExistsElement(contentsCell);
            if(isContentsCellExists)
                _aspxSetElementVisibility(contentsCell, false);
            this.ChangeTabState(index, true);
            this.ChangeTabState(this.activeTabIndex, false);
            this.activeTabIndex = index;
            if(isContentsCellExists)
                _aspxSetElementVisibility(contentsCell, true);
        } else {
            this.ChangeTabState(this.activeTabIndex, false);
            this.activeTabIndex = index;
            this.ChangeTabState(this.activeTabIndex, true);
        }
       
        this.UpdateActiveTabIndexInputElement();
        this.UpdateActiveTabIndexCookie();
    },
    SetActiveTabIndexInternal: function(index, hasLink){
        if(this.activeTabIndex == index) return;
        
        var lastScrollYPos = _aspxGetDocumentScrollTop();
        this.ChangeActiveTab(index, hasLink);
        var scrollY = _aspxGetDocumentScrollTop();
        if (lastScrollYPos != scrollY)
            window.scrollTo(_aspxGetDocumentScrollLeft(), lastScrollYPos);
        this.UpdateHoverState(index);            
    },
    
    UpdateActiveTabIndexCookie: function(){
        if(this.cookieName == "") return;

        _aspxDelCookie(this.cookieName);
        _aspxSetCookie(this.cookieName, this.activeTabIndex);
    },
    UpdateActiveTabIndexInputElement: function(){
        var element = this.GetActiveTabIndexInputElement();
        if(element != null) element.value = this.activeTabIndex;
    },
    
    UpdateHoverState: function(index){
        var element = this.GetTabElement(index, true);
        if(element != null) aspxGetStateController().SetCurrentHoverElementBySrcElement(element);
    },
    
    OnResize: function(){
        var mainElement = this.GetMainElement();
        if(mainElement != null && !_aspxIsExists(mainElement.corrected))
            this.CorrrectCellsBounds(false);
    },
    OnTabClick: function(evt, index){            
        var processingMode = this.RaiseTabClick(index, evt);
        
        var clickedLinkElement = _aspxGetParentByTagName(_aspxGetEventSource(evt), "A");
        var isLinkClicked = (clickedLinkElement != null && clickedLinkElement.href != __aspxAccessibilityEmptyUrl);
        var element = this.GetTabElement(index, false);
        var linkElement = (element != null) ? _aspxGetChildByTagName(element, "A", 0) : null;
        if(linkElement != null && linkElement.href == __aspxAccessibilityEmptyUrl)
            linkElement = null;
        
        if (processingMode != "Handled"){
            var hasLink = isLinkClicked || linkElement != null;
            if (processingMode == "Server" && !hasLink)
                this.SendPostBack("CLICK:" + index);
            else
                this.SetActiveTabIndexInternal(index, hasLink);
                
            if(this.handleClickOnWholeTab && !isLinkClicked && linkElement != null) 
                _aspxNavigateUrl(linkElement.href, linkElement.target);
                
            return true;
        }
        return false;
    },
    OnCallbackInternal: function(html, index, isError){
        this.SetCallbackContent(html, index, isError);
        if(!isError)
            this.RaiseActiveTabChanged(index);

        _aspxArrayRemoveAt(this.tabsContentRequest, 0);
    },
    OnCallback: function(result){
        this.OnCallbackInternal(result.html, result.index, false);
    },
    OnCallbackError: function(result, data){
        this.OnCallbackInternal(result, data, true);
    },
    OnCallbackGeneralError: function(result){
        var callbackTabIndex = (this.tabsContentRequest.length > 0) ? this.tabsContentRequest[0] : this.activeTabIndex;
        this.SetCallbackContent(result, callbackTabIndex, true);
        _aspxArrayRemoveAt(this.tabsContentRequest, 0);
    },
    SetCallbackContent: function(html, index, isError) {
        var element = this.GetContentElement(index);
        if(element != null) {
            if(!isError)
                element.loaded = true;
            element.loading = false;
            _aspxSetInnerHtml(element, html);
            
            this.callbackCount--;
            if(this.callbackCount == 0){
                this.UnfixControlSize();
                this.CorrrectCellsBounds(false);
                this.CorrectOperaTabCellsAlignment();
            }
        }
    },
    // API
    CreateTabs: function(tabsProperties){
        for(var i = 0; i < tabsProperties.length; i ++){
            var tabName = _aspxIsExists(tabsProperties[i][0]) ? tabsProperties[i][0] : "";
            var tab = new ASPxClientTab(this, i, tabName);
            if(_aspxIsExists(tabsProperties[i][1]))
                tab.enabled = tabsProperties[i][1];
            if(_aspxIsExists(tabsProperties[i][2]))                
                tab.clientEnabled = tabsProperties[i][2];
            if(_aspxIsExists(tabsProperties[i][3]))
                tab.visible = tabsProperties[i][3];
            if(_aspxIsExists(tabsProperties[i][4]))
                tab.clientVisible = tabsProperties[i][4];
            _aspxArrayPush(this.tabs, tab);
        }
    },
    RaiseTabClick: function(index, htmlEvent){
        var processingMode = this.autoPostBack || this.IsServerEventAssigned("TabClick") ? "Server" : "Client";
        if(!this.TabClick.IsEmpty()){   
            var htmlElement = this.GetTabElement(index, this.activeTabIndex == index);
            var args = new ASPxClientTabControlTabClickEventArgs(processingMode == "Server", this.GetTab(index), htmlElement, htmlEvent);
            this.TabClick.FireEvent(this, args);
            if(args.cancel)
                processingMode = "Handled";
            else 
                processingMode = args.processOnServer ? "Server" : "Client";            
        }
        return processingMode;
    },
    RaiseActiveTabChanged: function(index){
        if(!this.ActiveTabChanged.IsEmpty()){
            var args = new ASPxClientTabControlTabEventArgs(this.GetTab(index));
            this.ActiveTabChanged.FireEvent(this, args);
        }
    },
    RaiseActiveTabChanging: function(index){    
        var processingMode = this.autoPostBack ? "Server" : "Client";
        if(!this.ActiveTabChanging.IsEmpty()){
            var args = new ASPxClientTabControlTabCancelEventArgs(processingMode == "Server", this.GetTab(index));
            this.ActiveTabChanging.FireEvent(this, args);
            if(args.cancel)
                processingMode = "Handled";
            else if(args.processOnServer)
                processingMode = "Server";
            else
                processingMode = args.reloadContentOnCallback ? "ClientWithReload" : "Client";
        }
        return processingMode;
    },
    GetActiveTab: function(){
        return (this.activeTabIndex > -1) ? this.GetTab(this.activeTabIndex) : null;
    },
    SetActiveTab: function(tab){
        if(this.IsTabVisible(tab.index))
            this.SetActiveTabIndexInternal(tab.index, false);
    },
    GetTabCount: function(){
        return this.tabs.length;
    },
    GetTab: function(index){
        return (0 <= index && index < this.tabs.length) ? this.tabs[index] : null;
    },
    GetTabByName: function(name){
        for(var i = 0; i < this.tabs.length; i ++)
            if(this.tabs[i].name == name) return this.tabs[i];
        return null;
    },
    
    IsTabEnabled: function(index){
        return this.tabs[index].GetEnabled();
    },
	SetTabEnabled: function(index, enabled, initialization){
	    if(!this.tabs[index].enabled) return;
	    
        if(!initialization || !enabled)
            this.ChangeTabEnabledStateItems(index, enabled);
        this.ChangeTabEnabledAttributes(index, enabled);
	},
    ChangeTabEnabledAttributes: function(index, enabled){
        if(enabled){
            this.ChangeTabElementsEnabledAttributes(index, _aspxRestoreAttribute, _aspxRestoreStyleAttribute);
            if(!this.IsTabEnabled(this.activeTabIndex) && this.IsTabVisible(index))
                this.SetActiveTabIndexInternal(index, false);
         }
        else{
            if(this.activeTabIndex == index){
                for(var i = 0; i < this.GetTabCount(); i ++){
                    if(this.IsTabVisible(i) && this.IsTabEnabled(i) && i != index){
                        this.SetActiveTabIndexInternal(i, false);
                        break;
                    }
                }
            }
            this.ChangeTabElementsEnabledAttributes(index, _aspxResetAttribute, _aspxResetStyleAttribute);
        }
    },
    ChangeTabElementsEnabledAttributes: function(index, method, styleMethod){
        var element = this.GetTabElement(index, false);
        if(_aspxIsExists(element)){
            method(element, "onclick");
            styleMethod(element, "cursor");
   	        var link = _aspxGetChildByTagName(element, "A", 0);
   	        if(link != null){
   	            method(link, "href");
   	            styleMethod(link, "cursor");
            }
   	        link = _aspxGetChildByTagName(element, "A", 1);
   	        if(link != null){
   	            method(link, "href");
   	            styleMethod(link, "cursor");
            }
        }
        var activeElement = this.GetTabElement(index, true);
        if(_aspxIsExists(activeElement)){
            method(activeElement, "onclick");
            styleMethod(activeElement, "cursor");
        }
    },
    ChangeTabEnabledStateItems: function(index, enabled){
	    var element = this.GetTabElement(index, false);
	    if(element != null)
            aspxGetStateController().SetElementEnabled(element, enabled);
	    var activeElement = this.GetTabElement(index, true);
	    if(activeElement != null)
            aspxGetStateController().SetElementEnabled(activeElement, enabled);
    },	
    
    GetTabTextCell: function(index, active){
        return this.GetChild("_" + (active ? "A" : "") + "T"  + index + "T");
    },
    GetTabImageCell: function(index, active){
        return this.GetChild("_" + (active ? "A" : "") + "T"  + index + "I");
    },
	GetTabImageUrl: function(index, active){
        var element = this.GetTabImageCell(index, active);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            return img.src;
        }
        return "";
	},
	SetTabImageUrl: function(index, active, url){
        var element = this.GetTabImageCell(index, active);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            img.src = url;
        }
	},
	GetTabNavigateUrl: function(index){
	    var element = this.GetTabTextCell(index, false);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            return link.href;
	    }
        element = this.GetTabImageCell(index, false);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            return link.href;
	    }
	    return "";
	},
	SetTabNavigateUrl: function(index, url){
	    var element = this.GetTabTextCell(index, false);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            link.href = url;
	    }
	    var element = this.GetTabImageCell(index, false);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            link.href = url;
	    }
	},
	GetTabText: function(index){
	    var element = this.GetTabTextCell(index, false);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            return link.innerHTML;
	        else{
	            var span = _aspxGetChildByTagName(element, "SPAN", 0);
	            if(span != null)
	                return span.innerHTML;
	            else
	                return element.innerHTML;
	        }
	    }
	    return "";
	},
	SetTabText: function(index, text){
	    var element = this.GetTabTextCell(index, false);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            link.innerHTML = text;
	        else{
	            var span = _aspxGetChildByTagName(element, "SPAN", 0);
	            if(span != null)
	                span.innerHTML = text;
	            else
	                element.innerHTML = text;
	        }
	    }
	    element = this.GetTabTextCell(index, true);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            link.innerHTML = text;
	        else{
	            var span = _aspxGetChildByTagName(element, "SPAN", 0);
	            if(span != null)
	                span.innerHTML = text;
	            else
	                element.innerHTML = text;
	        }
	    }
	},
	IsTabVisible: function(index){
	    return this.tabs[index].GetVisible();
	},
	SetTabVisible: function(index, visible, initialization){
	    if(!this.tabs[index].visible) return;	
	    if(visible && initialization) return;
	    
        var element = this.GetTabElement(index, false);
        if(element != null) element = this.GetTabLayoutElement(element);
        var activeElement = this.GetTabElement(index, true);
        if(activeElement != null) activeElement = this.GetTabLayoutElement(activeElement);
        var contentElement = this.GetContentElement(index);
        if(!visible){
            if(this.activeTabIndex == index){
                for(var i = 0; i < this.GetTabCount(); i ++){
                    if(this.IsTabVisible(i) && this.IsTabEnabled(i) && i != index){
                        this.SetActiveTabIndexInternal(i, false);
                        break;
                    }
                }
                for(var i = 0; i < this.GetTabCount(); i ++){
                    if(this.IsTabVisible(i) && i != index){
                        this.SetActiveTabIndexInternal(i, false);
                        break;
                    }
                }
                if(this.activeTabIndex == index){
                    this.activeTabIndex = -1;
                    _aspxSetElementDisplay(this.GetMainElement(), false);
                }
            }

            if(element != null)
                _aspxSetElementDisplay(element, false);
            if(activeElement != null)
                _aspxSetElementDisplay(activeElement, false);
            if(contentElement != null)
                _aspxSetElementDisplay(contentElement, false);
        }
        else{
            if(element != null)
                _aspxSetElementDisplay(element, this.activeTabIndex != index);
            if(activeElement != null)
                _aspxSetElementDisplay(activeElement, this.activeTabIndex == index);
            if(contentElement != null)
                _aspxSetElementDisplay(contentElement, this.activeTabIndex == index);
                
            if(this.activeTabIndex == -1){
                _aspxSetElementDisplay(this.GetMainElement(), true);
                this.SetActiveTabIndexInternal(index, false);
            }
            else if(!this.IsTabEnabled(this.activeTabIndex) && this.IsTabEnabled(index))
                this.SetActiveTabIndexInternal(index, false);
        }
        this.SetSeparatorsVisiblility();
        this.CorrrectCellsBounds(false);
	},
	SetSeparatorsVisiblility: function(){
        for(var i = 0; i < this.tabs.length; i++){
            var separatorVisible = this.tabs[i].GetVisible() && this.HasNextVisibleTabs(i);
            var separatorElement = this.GetSeparatorElement(i);
            if(separatorElement != null) {
                separatorElement = this.GetTabLayoutElement(separatorElement);
                _aspxSetElementDisplay(separatorElement, separatorVisible);
            }
        }
	},
	HasNextVisibleTabs: function(index){
	    for(var i = index + 1; i < this.tabs.length; i++){
            if(this.tabs[i].GetVisible())
                return true;
        }
        return false;
	}
});
ASPxClientTabControl = _aspxCreateClass(ASPxClientTabControlBase, {
});
ASPxClientPageControl = _aspxCreateClass(ASPxClientTabControlBase, {
	constructor: function(name){
		this.constructor.prototype.constructor.call(this, name);
        this.handleClickOnWholeTab = false;
    },
	GetTabContentHTML: function(tab){
	    var element = this.GetContentElement(tab.index);
	    return (element != null) ? element.innerHTML : "";
	},
	SetTabContentHTML: function(tab, html){
	    var element = this.GetContentElement(tab.index);
	    if(element != null) {
	        _aspxSetInnerHtml(element, html);
            this.CorrrectCellsBounds(false);
	    }
	}
});
ASPxClientTab = _aspxCreateClass(null, {
	constructor: function(tabControl, index, name){
	    this.tabControl = tabControl;
        this.index = index;
        this.name = name;
        
        this.enabled = true;
        this.clientEnabled = true;
        this.visible = true;
        this.clientVisible = true;
	},
	GetEnabled: function(){
        return this.enabled && this.clientEnabled;
	},
	SetEnabled: function(value){
        if (this.clientEnabled != value) {
            this.clientEnabled = value;
	        this.tabControl.SetTabEnabled(this.index, value, false);
	    }
	},
	GetImageUrl: function(active){
	    if(!_aspxIsExists(active)) active = false; //for backward capability
	    return this.tabControl.GetTabImageUrl(this.index, active);
	},
	SetImageUrl: function(value, active){
	    if(!_aspxIsExists(active)) active = false; //for backward capability
	    this.tabControl.SetTabImageUrl(this.index, active, value);
	},
	GetActiveImageUrl: function(){
	    return this.tabControl.GetTabImageUrl(this.index, true);
	},
	SetActiveImageUrl: function(value){
	    this.tabControl.SetTabImageUrl(this.index, true, value);
	},
	GetNavigateUrl: function(){
	    return this.tabControl.GetTabNavigateUrl(this.index);
	},
	SetNavigateUrl: function(value){
	    this.tabControl.SetTabNavigateUrl(this.index, value);
	},
	GetText: function(){
	    return this.tabControl.GetTabText(this.index);
	},
	SetText: function(value){
	    this.tabControl.SetTabText(this.index, value);
	},
	GetVisible: function(){
	    return this.visible && this.clientVisible;
	},
	SetVisible: function(value){
        if (this.clientVisible != value) {
            this.clientVisible = value;
	        this.tabControl.SetTabVisible(this.index, value, false);
	    }
	}    
});
ASPxClientTabControlTabEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
	constructor: function(tab, htmlElement, htmlEvent){
	    this.constructor.prototype.constructor.call(this);
        this.tab = tab;
	}
});
ASPxClientTabControlTabCancelEventArgs = _aspxCreateClass(ASPxClientCancelEventArgs, {
	constructor: function(processOnServer, tab){
	    this.constructor.prototype.constructor.call(this, processOnServer);
        this.tab = tab;
        this.reloadContentOnCallback = false;
	}
});
ASPxClientTabControlTabClickEventArgs = _aspxCreateClass(ASPxClientTabControlTabCancelEventArgs, {
	constructor: function(processOnServer, tab, htmlElement, htmlEvent){
	    this.constructor.prototype.constructor.call(this, processOnServer, tab);
        this.htmlElement = htmlElement;
        this.htmlEvent = htmlEvent;        
	}
});

function aspxTCResize(name){
    var tc = aspxGetControlCollection().Get(name);
    if(tc != null) tc.OnResize();
}
function aspxTCCorrectBounds(name){
    var tc = aspxGetControlCollection().Get(name);
    if(tc != null) tc.CorrrectCellsBoundsTimer();
}
function aspxTCTClick(evt, name, index){
    var tc = aspxGetControlCollection().Get(name);
    if(tc != null) {
        if(!__aspxNS)
            evt.cancelBubble = true;
        return tc.OnTabClick(evt, index);
    }
    return true;
}
ASPxClientNavBar = _aspxCreateClass(ASPxClientControl, {
	constructor: function(name){
		this.constructor.prototype.constructor.call(this, name);
    
        this.animationOffset = 10;
        this.animationDelay = 10;
        this.animationMaxDelay = 400;
        this.autoCollapse = false;
        this.allowExpanding = true;
        this.allowSelectItem = false;
        this.cookieName = "";
        this.groupCount = 0;
        this.enableAnimation = false;
        this.groups = [];
        this.groupsExpanding = new Array();
        this.groupsExpandingRequest = [];    
        this.ItemClick = new ASPxClientEvent();    
        this.ExpandedChanged = new ASPxClientEvent();
        this.ExpandedChanging = new ASPxClientEvent();    
        this.HeaderClick = new ASPxClientEvent();
    },    
    InlineInitialize: function(){
        this.InitializeSelectedItem();
        this.InitializeEnabledAndVisible();
    },
    InitializeEnabledAndVisible: function(){
        for(var i = 0; i < this.groups.length; i++){
            var group = this.groups[i];
            for(var j = 0; j < group.items.length; j++){
                this.SetItemEnabled(i, j, group.items[j].clientEnabled, true);
                this.SetItemVisible(i, j, group.items[j].clientVisible, true);
            }
            this.SetGroupVisible(i, group.clientVisible, true);
        }
    },
    InitializeSelectedItem: function(){
        if(!this.allowSelectItem) return;

        var inputElement = this.GetSelectedItemInputElement();
        if(inputElement != null){
            var element = this.GetItemTextElementByIndexPath(inputElement.value);
            if(element != null)
                aspxGetStateController().SelectElementBySrcElement(element);
        }
    },
    InitializeCallBackData: function(){
        for(var i = 0; i < this.GetGroupCountCore(); i ++){
            if(this.groupsExpanding[i]){
                var element = this.GetGroupContentElement(i);
                if(element != null) element.loaded = true;
            }
        }
    },    
    GetClickableGroupHeaderElement: function(index) {
        var isDisplayed = false;
        var element = this.GetGroupHeaderExpandedElement(index);
        if (element != null) isDisplayed = !_aspxGetElementDisplay(element) || !this.allowExpanding ;
        
        if (!isDisplayed)
            element = this.GetGroupHeaderCollapsedElement(index);
        return element;
    },
    GetGroupHeaderExpandedElement: function(index){
        return this.GetChild("_GHE" + index);
    },
    GetGroupHeaderCollapsedElement: function(index){
        return this.GetChild("_GHC" + index);
    },
    GetGroupContentElement: function(index){
        return this.GetChild("_GC" + index);
    },
    GetGroupContentAnimationElement: function(index){
        return this.GetChild("_GCA" + index);
    },
    GetRowElement: function(cellElement){
        return cellElement.parentNode;
    },
    GetItemElement: function(groupIndex, itemIndex){
        return this.GetChild("_I" + this.GetIndexPath(groupIndex, itemIndex) + "_");
    },
    GetItemSeparatorElement: function(groupIndex, itemIndex){
        return this.GetChild("_I" + this.GetIndexPath(groupIndex, itemIndex) + "S");
    },
    GetItemTextElementByIndexPath: function(indexPath){
        return this.GetChild("_I" + indexPath + "_T");
    },
    GetItemImageElementByIndexPath: function(indexPath){
        return this.GetChild("_I" + indexPath + "_I");
    },
	GetGroupRow: function(groupIndex){
	    return this.GetChild("_GR" + groupIndex);
    },
    GetGroupSeparatorRow: function(groupIndex){
	    return this.GetChild("_GSR" + groupIndex);
    },

    GetGroupStateInputElement: function(index){
        return _aspxGetElementById(this.name + "GS");
    },
    GetSelectedItemInputElement: function(){
        return _aspxGetElementById(this.name + "SI");
    },
    
    DoItemClick: function(groupIndex, itemIndex, hasItemLink, htmlEvent){
        var processOnServer = this.RaiseItemClick(groupIndex, itemIndex, htmlEvent);
        if(processOnServer && !hasItemLink)
            this.SendPostBack("CLICK:" + this.GetIndexPath(groupIndex, itemIndex));
    },
    SetExpandedInternal: function(groupIndex, expanded){
        if(expanded == this.groupsExpanding[groupIndex]) return;
        
        var processingMode = this.RaiseExpandedChanging(groupIndex);
        if(processingMode == "Client"){
            if(expanded || !this.autoCollapse){
                if(this.autoCollapse){
                    for(var i = 0; i < this.GetGroupCountCore(); i ++){
                        if(i != groupIndex && this.groupsExpanding[i])
                            this.ChangeExpanding(i, false);
                    }
                }
                this.ChangeExpanding(groupIndex, expanded);
            }
        }
        else if(processingMode == "Server")
            this.SendPostBack("EXPAND:" + groupIndex);
    },
    ChangeExpanding: function(groupIndex, expanded){
        var element = this.GetGroupContentElement(groupIndex);
        if(expanded && _aspxIsFunction(this.callBack)  && element != null && !element.loaded){
            this.DoChangeExpanding(groupIndex, expanded, false);
            if(!element.loading){
                element.loading = true;
                this.CreateLoadingPanelInsideContainer(this.GetGroupContentElement(groupIndex));
                this.CreateCallback(groupIndex);
                _aspxArrayPush(this.groupsExpandingRequest, groupIndex);
            }
        }
        else{
            this.DoChangeExpanding(groupIndex, expanded, this.enableAnimation);
            
            if(!this.enableAnimation)
                this.RaiseExpandedChanged(groupIndex);
        }
    },
    DoChangeExpanding: function(groupIndex, expanded, doAnimation){
        if(doAnimation){
            var element = this.GetGroupContentAnimationElement(groupIndex);
            var contentElement = this.GetGroupContentElement(groupIndex);
            if(element != null && contentElement != null){
                if(expanded){
                    element.style.height = "0px";
                    _aspxSetElementDisplay(this.GetRowElement(contentElement), true);
                    if(__aspxNS && !__aspxFirefox){
                        var innerElement = _aspxGetChildByTagName(element, "TABLE", 0);
                        if(innerElement != null)
                            element.style.width = innerElement.offsetWidth + "px";
                        else{
                            innerElement = _aspxGetChildByTagName(element, "UL", 0);
                            if(innerElement != null)
                                element.style.width = element.clientWidth + "px";
                        }
                    }
                }
                else{
                    element.style.height = element.offsetHeight + "px";
                }
                element.style.overflow = "hidden";
                element.expanding = expanded;
                element.animationCount = 1;
                element.animationStart = new Date();
                element.timerID = window.setTimeout("aspxNBAnimT(\"" + this.name + "\", " + groupIndex + ")", this.animationDelay);
            }
            else
                this.ChangeGroupExpandState(groupIndex, expanded);
        }
        else
            this.ChangeGroupExpandState(groupIndex, expanded);
    },
    ChangeGroupExpandState: function(groupIndex, expanded){
        this.DoChangeGroupExpandState(groupIndex, expanded);
        if (expanded)
            aspxGetControlCollection().AdjustControls(this.GetGroupContentElement(groupIndex), __aspxCheckSizeCorrectedFlag);
    },
    DoChangeGroupExpandState: function(groupIndex, expanded) {
        var element = this.GetGroupContentElement(groupIndex);
        if(element != null) _aspxSetElementDisplay(this.GetRowElement(element), expanded);
        element = this.GetGroupHeaderExpandedElement(groupIndex);
        if(element != null) _aspxSetElementDisplay(this.GetRowElement(element), expanded);
        element = this.GetGroupHeaderCollapsedElement(groupIndex);
        if(element != null) _aspxSetElementDisplay(this.GetRowElement(element), !expanded);
        
        this.groupsExpanding[groupIndex] = expanded;
        this.UpdateGroupStateInputElement();
        this.UpdateGroupStateCookie();
    },
    
    GetGroupCountCore: function(){
        return (this.groups.length > 0) ? this.groups.length : this.groupCount;
    },
    GetIndexPath: function(groupIndex, itemIndex){
        return (groupIndex != -1 && itemIndex != -1) ? groupIndex + __aspxItemIndexSeparator + itemIndex : "";
    },
    GetGroupIndex: function(indexPath){
        var indexes = indexPath.split(__aspxItemIndexSeparator);
        return (indexes.length > 0) ? indexes[0] : -1;
    },
    GetItemIndex: function(indexPath){
        var indexes = indexPath.split(__aspxItemIndexSeparator);
        return (indexes.length > 1) ? indexes[1] : -1;
    },
    
    GetGroupState: function(){
        var state = "";
        for(var i = 0; i < this.GetGroupCountCore(); i ++) {
            state += this.groupsExpanding[i] ? "1" : "0";
            if(i < this.GetGroupCountCore() - 1) state += ";";
        }
        return state;
    },
    UpdateGroupStateCookie: function(){
        if(this.cookieName == "") return;
        
        _aspxDelCookie(this.cookieName);
        _aspxSetCookie(this.cookieName, this.GetGroupState());
    },
    UpdateGroupStateInputElement: function(){
        var element = this.GetGroupStateInputElement();
        if(element != null) element.value = this.GetGroupState();
    },
    
    SetSelectedItemInternal: function(groupIndex, itemIndex){
        var indexPath = this.GetIndexPath(groupIndex, itemIndex);
        if(this.allowSelectItem){
            var inputElement = this.GetSelectedItemInputElement();
            if(inputElement != null){
                var element = this.GetItemTextElementByIndexPath(inputElement.value);
                if(element != null)
                    aspxGetStateController().DeselectElementBySrcElement(element);
                inputElement.value = indexPath;
                element = this.GetItemTextElementByIndexPath(inputElement.value);
                if(element != null)
                    aspxGetStateController().SelectElementBySrcElement(element);
            }
        }
    },
    
    OnAnimationTimer: function(groupIndex){
        var element = this.GetGroupContentAnimationElement(groupIndex);
        if(element != null){
            window.clearTimeout(element.timerID);
            
            var animationOffset = this.animationOffset * element.animationCount;
            var height = element.offsetHeight + (element.expanding ? animationOffset : -animationOffset);
            var innerElement = _aspxGetChildByTagName(element, "TABLE", 0);
            if(innerElement == null)
                innerElement = _aspxGetChildByTagName(element, "UL", 0);
            var finished = (element.expanding ? (height >= innerElement.offsetHeight) : (height <= 0)) ||
                (new Date() - element.animationStart > this.animationMaxDelay);
            if(finished){
                this.ChangeGroupExpandState(groupIndex, element.expanding);
                    
                element.style.overflow = "";
                element.style.height = "";
                element.style.width = "";
            
                this.RaiseExpandedChanged(groupIndex);
            }
            else{
                element.style.height = height + "px";
                element.animationCount ++;
                element.timerID = window.setTimeout("aspxNBAnimT(\"" + this.name + "\", " + groupIndex + ")", this.animationDelay);
            }
        }
    },
    OnHeaderClick: function(groupIndex, evt){
        var processingMode = this.RaiseHeaderClick(groupIndex, evt);

        var linkElement = _aspxGetParentByTagName(_aspxGetEventSource(evt), "A");
        if(linkElement == null || linkElement.href == __aspxAccessibilityEmptyUrl){
            if(processingMode == "Client" && this.allowExpanding){
                var expanded = this.groupsExpanding[groupIndex];
                this.SetExpandedInternal(groupIndex, !expanded);
                aspxUpdateHoverState(evt);
            }
            else if(processingMode == "Server")
                this.SendPostBack("HEADERCLICK:" + groupIndex);
        }
    },
    OnItemClick: function(groupIndex, itemIndex, evt){
        var element = this.GetItemElement(groupIndex, itemIndex);
        var clickedLinkElement = _aspxGetParentByTagName(_aspxGetEventSource(evt), "A");
        var isLinkClicked = (clickedLinkElement != null && clickedLinkElement.href != __aspxAccessibilityEmptyUrl);
        var linkElement = (element != null) ? _aspxGetChildByTagName(element, "A", 0) : null;
        if(linkElement != null && linkElement.href == __aspxAccessibilityEmptyUrl)
            linkElement = null;

        aspxClearHoverState();
        this.SetSelectedItemInternal(groupIndex, itemIndex);
        aspxUpdateHoverState(evt);
        
        this.DoItemClick(groupIndex, itemIndex, isLinkClicked || (linkElement != null), evt);

        if(!isLinkClicked && linkElement != null) 
            _aspxNavigateUrl(linkElement.href, linkElement.target);
    },
    
    OnCallbackInternal: function(html, index, isError){
        this.SetCallbackContent(html, index, isError);
        if(!isError)
            this.RaiseExpandedChanged(index);

        _aspxArrayRemoveAt(this.groupsExpandingRequest, 0);
    },
    OnCallback: function(result){
        this.OnCallbackInternal(result.html, result.index, false);
    },
    OnCallbackError: function(result, data){
        this.OnCallbackInternal(result, data, true);
    },
    OnCallbackGeneralError: function(result){
        var callbackGroupIndex = (this.groupsExpandingRequest.length > 0) ? this.groupsExpandingRequest[0] : 0;
        this.SetCallbackContent(result, callbackGroupIndex, true);
        _aspxArrayRemoveAt(this.groupsExpandingRequest, 0);
    },
    SetCallbackContent: function(html, index, isError) {
        var element = this.GetGroupContentElement(index);
        if(element != null) {
            _aspxSetInnerHtml(element, html);
            if(!isError)
                element.loaded = true;
            element.loading = false;
        }
    },
    // API
    CreateGroups: function(groupsProperties){
        for(var i = 0; i < groupsProperties.length; i ++){
            var groupName = _aspxIsExists(groupsProperties[i][0]) ? groupsProperties[i][0] : "";
            var group = new ASPxClientNavBarGroup(this, i, groupName);
            if(_aspxIsExists(groupsProperties[i][1]))
                group.enabled = groupsProperties[i][1];
            if(_aspxIsExists(groupsProperties[i][2]))
                group.visible = groupsProperties[i][2];
            if(_aspxIsExists(groupsProperties[i][3]))
                group.clientVisible = groupsProperties[i][3];
            _aspxArrayPush(this.groups, group);
            group.CreateItems(groupsProperties[i][4]);
        }
    },
    RaiseItemClick: function(groupIndex, itemIndex, htmlEvent){
        var processOnServer = this.autoPostBack || this.IsServerEventAssigned("ItemClick");
        if(!this.ItemClick.IsEmpty()){
            var htmlElement = this.GetItemElement(groupIndex, itemIndex);            
            var args = new ASPxClientNavBarItemEventArgs(processOnServer, this.GetGroup(groupIndex).GetItem(itemIndex), htmlElement, htmlEvent);
            this.ItemClick.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    },
    RaiseExpandedChanged: function(groupIndex){
        if(!this.ExpandedChanged.IsEmpty()){
            var args = new ASPxClientNavBarGroupEventArgs(this.GetGroup(groupIndex));
            this.ExpandedChanged.FireEvent(this, args);
        }
    },
    RaiseExpandedChanging: function(groupIndex){
        var processingMode = this.autoPostBack ? "Server" : "Client";
        if(!this.ExpandedChanging.IsEmpty()){
            var args = new ASPxClientNavBarGroupCancelEventArgs(processingMode == "Server", this.GetGroup(groupIndex));
            this.ExpandedChanging.FireEvent(this, args);
            if(args.cancel)
                processingMode = "Handled";
            else 
                processingMode = args.processOnServer ? "Server" : "Client";
        }
        return processingMode;
    },
    RaiseHeaderClick: function(groupIndex, htmlEvent){
        var processingMode = this.autoPostBack || this.IsServerEventAssigned("HeaderClick") ? "Server" : "Client";
        if(!this.HeaderClick.IsEmpty()){
            var htmlElement = this.GetClickableGroupHeaderElement(groupIndex);
            var args = new ASPxClientNavBarGroupClickEventArgs(processingMode == "Server", this.GetGroup(groupIndex), htmlElement, htmlEvent);
            this.HeaderClick.FireEvent(this, args);
            if(args.cancel)
                processingMode = "Handled";
            else 
                processingMode = args.processOnServer ? "Server" : "Client";
        }
        return processingMode;
    },
	GetGroupCount: function(){
	    return this.groups.length;
	},
	GetGroup: function(index){
        return (0 <= index && index < this.groups.length) ? this.groups[index] : null;
	},
	GetGroupByName: function(name){
        for(var i = 0; i < this.groups.length; i ++)
            if(this.groups[i].name == name) return this.groups[i];
        return null;
	},
	GetActiveGroup: function(){
	    if(this.autoCollapse) {
            for(var i = 0; i < this.groups.length; i ++){
                if(this.groups[i].GetExpanded())
                    return this.groups[i];
            }
        }
        return null;
	},
	SetActiveGroup: function(group){
	    if(this.autoCollapse && group != null) 
	        group.SetExpanded(true);
	},
	GetItemByName: function(name){
        for(var i = 0; i < this.groups.length; i ++){
            var item = this.groups[i].GetItemByName(name);
            if(item != null) return item;
        }
        return null;
	},
	GetSelectedItem: function(){
        var inputElement = this.GetSelectedItemInputElement();
        if(inputElement != null && inputElement.value != ""){
             var groupIndex = this.GetGroupIndex(inputElement.value);
             var itemIndex = this.GetItemIndex(inputElement.value);
             if(groupIndex > -1 && itemIndex > -1)
                return this.GetGroup(groupIndex).GetItem(itemIndex);
        }
        return null;
	},
	SetSelectedItem: function(item){
	    var groupIndex = (item != null) ? item.group.index : -1;
	    var itemIndex = (item != null) ? item.index : -1;
	    this.SetSelectedItemInternal(groupIndex, itemIndex);
	},
	CollapseAll: function(){
	    for(var i = 0; i < this.groupsExpanding.length; i++){
	        if(this.groupsExpanding[i])
	            this.SetExpandedInternal(i, false);
        }	            
	},
	ExpandAll: function(){
	    for(var i = 0; i < this.groupsExpanding.length; i++){
	        if(!this.groupsExpanding[i])
	            this.SetExpandedInternal(i, true);
        }	            
	},
	
    CheckSelectedItem: function(groupIndex, itemIndex){
        var selectedItem = this.GetSelectedItem();
        if(selectedItem != null && selectedItem.group.index == groupIndex && selectedItem.index == itemIndex)
            this.SetSelectedItem(null);
    },
	ChangeItemElementsEnabledAttributes: function(groupIndex, itemIndex, method, styleMethod){
	    var indexPath = this.GetIndexPath(groupIndex, itemIndex);
        var imageElement = this.GetItemImageElementByIndexPath(indexPath);
        if(_aspxIsExists(imageElement)){
            method(imageElement, "onclick");
            styleMethod(imageElement, "cursor");
   	        var link = _aspxGetChildByTagName(imageElement, "A", 0);
   	        if(link != null)
   	            method(link, "href");
        }
        var textElement = this.GetItemTextElementByIndexPath(indexPath);
        if(_aspxIsExists(textElement)){
            method(textElement, "onclick");
            styleMethod(textElement, "cursor");
   	        var link = _aspxGetChildByTagName(textElement, "A", 0);
   	        if(link != null)
   	            method(link, "href");
   	        link = _aspxGetChildByTagName(textElement, "A", 1);
   	        if(link != null)
   	            method(link, "href");
        }
	    var itemElement = this.GetItemElement(groupIndex, itemIndex);
        if(_aspxIsExists(itemElement)){
            method(itemElement, "onclick");
            if(imageElement == null && textElement == null){
                styleMethod(itemElement, "cursor");
   	            var link = _aspxGetChildByTagName(itemElement, "A", 0);
   	            if(link != null)
   	                method(link, "href");
   	        }
        }
	},
	SetItemEnabled: function(groupIndex, itemIndex, enabled, initialization){
	    if(!this.groups[groupIndex].items[itemIndex].enabled) return;
        
        if(!initialization || !enabled)
            this.ChangeItemEnabledStateItems(groupIndex, itemIndex, enabled);
        this.ChangeItemEnabledAttributes(groupIndex, itemIndex, enabled);
	},
    ChangeItemEnabledAttributes: function(groupIndex, itemIndex, enabled){
        if(!enabled)
            this.CheckSelectedItem(groupIndex, itemIndex);
        this.ChangeItemElementsEnabledAttributes(groupIndex, itemIndex, _aspxChangeAttributesMethod(enabled), 
            _aspxChangeStyleAttributesMethod(enabled));
	},
    ChangeItemEnabledStateItems: function(groupIndex, itemIndex, enabled){
	    var indexPath = this.GetIndexPath(groupIndex, itemIndex);
	    var element = this.GetItemTextElementByIndexPath(indexPath);
	    if(element == null)
	        element = this.GetItemImageElementByIndexPath(indexPath);
	    if(element == null)
	        element = this.GetItemElement(groupIndex, itemIndex);
	    if(element != null)
            aspxGetStateController().SetElementEnabled(element, enabled);
    },
	GetItemImageUrl: function(groupIndex, itemIndex){
	    var indexPath = this.GetIndexPath(groupIndex, itemIndex);
        var element = this.GetItemImageElementByIndexPath(indexPath);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            return img.src;
        }
        element = this.GetItemTextElementByIndexPath(indexPath);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            return img.src;
        }
        return "";
	},
	SetItemImageUrl: function(groupIndex, itemIndex, url){
	    var indexPath = this.GetIndexPath(groupIndex, itemIndex);
        var element = this.GetItemImageElementByIndexPath(indexPath);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            img.src = url;
        }
        element = this.GetItemTextElementByIndexPath(indexPath);
        if(element != null){
	        var img = _aspxGetChildByTagName(element, "IMG", 0);
	        if(img != null)
	            img.src = url;
        }
	},
	GetItemNavigateUrl: function(groupIndex, itemIndex){
	    var indexPath = this.GetIndexPath(groupIndex, itemIndex);
	    var element = this.GetItemTextElementByIndexPath(indexPath);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            return link.href;
	    }
        element = this.GetItemImageElementByIndexPath(indexPath);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            return link.href;
	    }
	    return "";
	},
	SetItemNavigateUrl: function(groupIndex, itemIndex, url){
	    var indexPath = this.GetIndexPath(groupIndex, itemIndex);
	    var element = this.GetItemTextElementByIndexPath(indexPath);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            link.href = url;
	        link = _aspxGetChildByTagName(element, "A", 1);
	        if(link != null)
	            link.href = url;
	    }
	    var element = this.GetItemImageElementByIndexPath(indexPath);
	    if(element != null){
	        var link = _aspxGetChildByTagName(element, "A", 0);
	        if(link != null)
	            link.href = url;
	    }
	},
	GetItemText: function(groupIndex, itemIndex){
	    var indexPath = this.GetIndexPath(groupIndex, itemIndex);
	    var element = this.GetItemTextElementByIndexPath(indexPath);
	    if(element != null){
	        var textNode = _aspxGetChildTextNode(element, 0);
	        if(textNode != null)
	            return textNode.nodeValue;
	    }
	    return "";
	},
	SetItemText: function(groupIndex, itemIndex, text){
	    var indexPath = this.GetIndexPath(groupIndex, itemIndex);
	    var element = this.GetItemTextElementByIndexPath(indexPath);
	    if(element != null){
	        var textNode = _aspxGetChildTextNode(element, 0);
	        if(textNode != null)
	            textNode.nodeValue = text;
	    }
	},
	SetItemVisible: function(groupIndex, itemIndex, visible, initialization){
	    if(!this.groups[groupIndex].items[itemIndex].visible) return;
	    if(visible && initialization) return;
	    
        if(!visible)
            this.CheckSelectedItem(groupIndex, itemIndex);

        var element = this.GetItemElement(groupIndex, itemIndex);
        if(element != null) _aspxSetElementDisplay(element, visible);
        
        this.SetItemSeparatorsVisiblility(groupIndex);
	},
	SetItemSeparatorsVisiblility: function(groupIndex){
	    var group = this.groups[groupIndex];
        for(var i = 0; i < group.items.length; i++){
            var separatorVisible = group.items[i].GetVisible() && this.HasNextVisibleItems(group, i);
            var separatorElement = this.GetItemSeparatorElement(groupIndex, i);
            if(separatorElement != null) _aspxSetElementDisplay(separatorElement, separatorVisible);
        }
	},
	HasNextVisibleItems: function(group, index){
	    for(var i = index + 1; i < group.items.length; i++){
            if(group.items[i].GetVisible())
                return true;
        }
        return false;
	},
	SetGroupVisible: function(groupIndex, visible, initialization){
	    if(!this.groups[groupIndex].visible) return;
	    if(visible && initialization) return;
	    
        var element = this.GetGroupRow(groupIndex);
        if(element != null) _aspxSetElementDisplay(element, visible);
        
        this.SetGroupSeparatorsVisiblility();
	},
	SetGroupSeparatorsVisiblility: function(){
        for(var i = 0; i < this.groups.length; i++){
            var separatorVisible = this.groups[i].GetVisible() && this.HasNextVisibleGroups(i);
            var separatorElement = this.GetGroupSeparatorRow(i);
            if(separatorElement != null) _aspxSetElementDisplay(separatorElement, separatorVisible);
        }
	},
	HasNextVisibleGroups: function(index){
	    for(var i = index + 1; i < this.groups.length; i++){
            if(this.groups[i].GetVisible())
                return true;
        }
        return false;
	}
});
ASPxClientNavBarGroup = _aspxCreateClass(null, {
	constructor: function(navBar, index, name){
	    this.navBar = navBar;
        this.index = index;
        this.name = name;
        
        this.enabled = true;
        this.visible = true;
        this.clientVisible = true;
        this.items = []; 
	},
    CreateItems: function(itemsProperties){
        for(var i = 0; i < itemsProperties.length; i ++){
            var itemName = _aspxIsExists(itemsProperties[i][0]) ? itemsProperties[i][0] : "";
            var item = new ASPxClientNavBarItem(this.navBar, this, i, itemName);
            if(_aspxIsExists(itemsProperties[i][1]))
                item.enabled = itemsProperties[i][1];
            if(_aspxIsExists(itemsProperties[i][2]))                
                item.clientEnabled = itemsProperties[i][2];
            if(_aspxIsExists(itemsProperties[i][3]))
                item.visible = itemsProperties[i][3];
            if(_aspxIsExists(itemsProperties[i][4]))
                item.clientVisible = itemsProperties[i][4];
            _aspxArrayPush(this.items, item);
        }
    },
	GetEnabled: function(){
	    return this.enabled;
	},
	GetExpanded: function(){
	    return this.navBar.groupsExpanding[this.index];
	},
	SetExpanded: function(value){
        this.navBar.SetExpandedInternal(this.index, value);
	},
	GetVisible: function(){
	    return this.visible && this.clientVisible;
	},
	SetVisible: function(value){
        if (this.clientVisible != value) {
            this.clientVisible = value;
	        this.navBar.SetGroupVisible(this.index, value, false);
	    }
	},
	GetItemCount: function(groupIndex){
        return this.items.length;
	},
	GetItem: function(index){
        return (0 <= index && index < this.items.length) ? this.items[index] : null;
	},
	GetItemByName: function(name){
        for(var i = 0; i < this.items.length; i ++)
            if(this.items[i].name == name) return this.items[i];
        return null;
	}
});
ASPxClientNavBarItem = _aspxCreateClass(null, {
	constructor: function(navBar, group, index, name){
	    this.navBar = navBar;
	    this.group = group;
        this.index = index;
        this.name = name;
        
        this.enabled = true;
        this.clientEnabled = true;
        this.visible = true;
        this.clientVisible = true;
	},
	GetEnabled: function(){
	    return this.enabled && this.clientEnabled;
	},
	SetEnabled: function(value){
        if (this.clientEnabled != value) {
            this.clientEnabled = value;
	        this.navBar.SetItemEnabled(this.group.index, this.index, value, false);
	    }
	},
	GetImageUrl: function(){
	    return this.navBar.GetItemImageUrl(this.group.index, this.index);
	},
	SetImageUrl: function(value){
	    this.navBar.SetItemImageUrl(this.group.index, this.index, value);
	},
	GetNavigateUrl: function(){
	    return this.navBar.GetItemNavigateUrl(this.group.index, this.index);
	},
	SetNavigateUrl: function(value){
	    this.navBar.SetItemNavigateUrl(this.group.index, this.index, value);
	},
	GetText: function(){
	    return this.navBar.GetItemText(this.group.index, this.index);
	},
	SetText: function(value){
	    this.navBar.SetItemText(this.group.index, this.index, value);
	},
	GetVisible: function(){
	    return this.visible && this.clientVisible;
	},
	SetVisible: function(value){
        if (this.clientVisible != value) {
            this.clientVisible = value;
	        this.navBar.SetItemVisible(this.group.index, this.index, value, false);
	    }
	}    
});
ASPxClientNavBarItemEventArgs = _aspxCreateClass(ASPxClientProcessingModeEventArgs, {
	constructor: function(processOnServer, item, htmlElement, htmlEvent){
	    this.constructor.prototype.constructor.call(this, processOnServer);
        this.item = item;
        this.htmlElement = htmlElement;
        this.htmlEvent = htmlEvent;
    }
});
ASPxClientNavBarGroupEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
	constructor: function(group){
        this.group = group;
    }
});
ASPxClientNavBarGroupCancelEventArgs = _aspxCreateClass(ASPxClientCancelEventArgs, {
	constructor: function(processOnServer, group){
	    this.constructor.prototype.constructor.call(this, processOnServer);
        this.group = group;
    }
});
ASPxClientNavBarGroupClickEventArgs = _aspxCreateClass(ASPxClientNavBarGroupCancelEventArgs, {
	constructor: function(processOnServer, group, htmlElement, htmlEvent){
	    this.constructor.prototype.constructor.call(this, processOnServer, group);
        this.htmlElement = htmlElement;
        this.htmlEvent = htmlEvent;        
    }
});

function aspxNBAnimT(name, groupIndex){
    var nb = aspxGetControlCollection().Get(name);
    if(nb != null) nb.OnAnimationTimer(groupIndex);
}
function aspxNBHClick(evt, name, groupIndex){
    var nb = aspxGetControlCollection().Get(name);
    if(nb != null) nb.OnHeaderClick(groupIndex, evt);
    if(!__aspxNS)
        evt.cancelBubble = true;
    return true;
}
function aspxNBIClick(evt, name, groupIndex, itemIndex){
    var nb = aspxGetControlCollection().Get(name);
    if(nb != null) nb.OnItemClick(groupIndex, itemIndex, evt);
    if(!__aspxNS)
        evt.cancelBubble = true;
    return true;
}
ASPxClientCallback = _aspxCreateClass(ASPxClientControl, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);
        this.CallbackComplete = new ASPxClientEvent();        
    },
    SendCallback: function(parameter) {        
        this.PerformCallback(parameter);
    },
    PerformCallback: function(parameter) {
        if(!_aspxIsExists(parameter)) parameter = "";
        this.CreateCallback(parameter);
    },
    OnCallback: function(result) {
        var args = new ASPxClientCallbackCompleteEventArgs(result.parameter, result.data);
        this.CallbackComplete.FireEvent(this, args);
    }
});
ASPxClientCallbackCompleteEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
    constructor: function(parameter, result){
        this.constructor.prototype.constructor.call(this);
        this.parameter = parameter;
        this.result = result;
    }
});
ASPxClientObjectContainer = _aspxCreateClass(ASPxClientControl, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);
        this.needFixObjectBounds = false;            
        this.FlashScriptCommand = new ASPxClientEvent();
    },
    Initialize: function() {
        if(this.needFixObjectBounds)
            this.FixObjectBounds();
        if (__aspxSafariFamily && !this.GetVisible())
            this.SetVisible_Safari(false);
        this.constructor.prototype.Initialize.call(this);
    },
    DoFlashScriptCommand: function(command, args) {
        this.RaiseFlashScriptCommand(command, args);
    },
    FixObjectBounds: function() {
        var mainElement = this.GetMainElement();
        if (mainElement != null && mainElement.body != null && 
                mainElement.body.style != null) {
            mainElement.body.style.border = "none";
            mainElement.body.style.margin = "0px";
            mainElement.body.style.padding = "0px";
            mainElement.body.style.overflow = "hidden";
        }
    },
    SetVisible: function(visible){
        ASPxClientControl.prototype.SetVisible.call(this, visible);
        if (__aspxSafariFamily) //B32204
            this.SetVisible_Safari(visible);
    },
    SetVisible_Safari: function(visible) {
        var mainElement = this.GetMainElement();
        var method = visible ? _aspxRestoreStyleAttribute : _aspxChangeStyleAttribute;
        method(mainElement, "width", "0px");
        method(mainElement, "height", "0px");
    },
    // API
    RaiseFlashScriptCommand: function(command, args) {
        if(!this.FlashScriptCommand.IsEmpty()) {
            var eventArgs = new ASPxClientFlashScriptCommandEventArgs(command, args);
            this.FlashScriptCommand.FireEvent(this, eventArgs);
        }
    },
    /* Flash API */
    Back: function() {
        this.GetMainElement().Back();
    },
    GetVariable: function(name) {
        return this.GetMainElement().GetVariable(name);
    },
    Forward: function() {
        this.GetMainElement().Forward();
    },
    GotoFrame: function(frameNumber) {
        this.GetMainElement().GotoFrame(frameNumber);
    },
    IsPlaying: function() {
        return __aspxIE ? this.GetMainElement().Playing : this.GetMainElement().IsPlaying();
    },
    LoadMovie: function(layerNumber, url) {
        this.GetMainElement().LoadMovie(layerNumber, url);
    },
    Pan: function(x, y, mode) {
        this.GetMainElement().Pan(x, y, mode);
    },
    PercentLoaded: function() {
        this.GetMainElement().PercentLoaded();
    },
    Play: function() {
        this.GetMainElement().Play();
    },
    Rewind: function() {
        this.GetMainElement().Rewind();
    },
    SetVariable: function(name, value) {
        this.GetMainElement().SetVariable(name, value);
    },
    SetZoomRect: function(left, top, right, bottom) {
        this.GetMainElement().SetZoomRect(left, top, right, bottom);
    },
    StopPlay: function() {
        if (__aspxIE)
            this.GetMainElement().Stop();
        else
            this.GetMainElement().StopPlay();
    },
    TotalFrames: function() {
        return __aspxIE ? this.GetMainElement().TotalFrames : this.GetMainElement().TotalFrames();
    },
    Zoom: function(percent) {
        this.GetMainElement().Zoom(percent);
    },
    /* QuickTime API */
    QTPlay: function() {
        this.GetMainElement().Play();
    },
    QTStopPlay: function() {
        this.GetMainElement().Stop();
    },
    QTRewind: function() {
        this.GetMainElement().Rewind();
    },
    QTStep: function(count) {
        this.GetMainElement().Step(count);
    }
});
ASPxClientFlashScriptCommandEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
    constructor: function(command, args){
        this.command = command;
        this.args = args;
    }
});

var __aspxPCWIdSuffix = "_PW";

function ASPxPCResizeCursorInfo(horizontalDirection, verticalDirection, horizontalOffset, verticalOffset){
    this.horizontalDirection = horizontalDirection;
    this.verticalDirection = verticalDirection;
    this.horizontalOffset = horizontalOffset;
    this.verticalOffset = verticalOffset;
    this.course = verticalDirection + horizontalDirection;
}
ASPxClientPopupControl = _aspxCreateClass(ASPxClientControl, {
    constructor: function(name){
        this.constructor.prototype.constructor.call(this, name);

        this.leadingAfterInitCall = true; // popup container must correct size before it's content
        this.adjustInnerControlsSizeOnShow = true;

        this.animationDelay = 30;
        this.animationMaxDelay = 400;        
        this.appearAfter = 300;
        this.disappearAfter = 500;
        this.allowResize = false;
        this.enableAnimation = true;
        
        this.allowCorrectYOffsetPosition = true; // Used by ASPxDropDownEdit
        this.contentUrl = "";
        this.contentUrlArray = [];
        this.cookieName = "";
        this.closeAction = "OuterMouseClick";
        this.popupAction = "LeftMouseClick";
        this.popupElementID = "";
        this.popupElementIDArray = [];
        this.showOnPageLoad = false;
        this.showOnPageLoadArray = [];
        this.popupHorizontalAlign = __aspxNotSetAlignIndicator;
        this.popupVerticalAlign = __aspxNotSetAlignIndicator;
        this.popupHorizontalOffset = 0;
        this.popupVerticalOffset = 0;
        this.shadowHeight = 5;
        this.shadowWidth = 5;
        this.windows = []; 
        this.windowCount = 0;
        this.isDragged = false;
        this.isResized = false;
        this.zIndex = -1;
        this.left = 0;
        this.top = 0;
        this.isDraggedArray = [];
        this.isResizedArray = [];
        this.zIndexArray = [];
        this.leftArray = [];
        this.topArray = [];
        this.height = 0;
        this.width = 0;
        this.heightArray = [];
        this.widthArray = [];
        this.isLiveResizingMode = true;
        this.isPopupPositionCorrectionOn = true;
        this.SSLSecureBlankUrl = "";
        this.windowElements = new Object();
        this.hideBodyScrollWhenModal = true;
        this.autoUpdatePosition = false;
        this.isNeedPopupedSet = false;
        this.cachedSize = null;
        this.cachedSizeArray = [];
        this.fakeDragDiv = null;
        
        this.popupElement = null;
        this.popupElements = [];
        this.headerHeight = 0;
        this.headerHeightArray = [];
        this.footerHeight = 0;
        this.footerHeightArray = [];
        this.ResizeBorderSize = 6;
        this.ResizeCornerBorderSize = 20;
        
        this.CloseButtonClick = new ASPxClientEvent();
        this.CloseUp = new ASPxClientEvent();
        this.Closing = new ASPxClientEvent();
        this.PopUp = new ASPxClientEvent();
        this.Resize = new ASPxClientEvent();
        this.Shown = new ASPxClientEvent();
        this.BeforeResizing = new ASPxClientEvent();
        this.AfterResizing = new ASPxClientEvent();
        
        aspxGetPopupControlCollection().Add(this);
    },
    Initialize: function(){
        this.InitializeArrays();
        if (this.HasDefaultWindow())
            this.InitializeWindow(-1);
        for(var i = 0; i < this.popupElementIDArray.length; i ++) 
            this.InitializeWindow(i);

        this.constructor.prototype.Initialize.call(this);
    },
    AfterInitialize: function(){
        if (this.HasDefaultWindow())
            this.AfterInitializeWindow(-1);
        for(var i = 0; i < this.popupElementIDArray.length; i ++) 
            this.AfterInitializeWindow(i);
        this.constructor.prototype.AfterInitialize.call(this);
    },
    
    InitializeArrays: function(){
        if (this.GetWindowCountCore() > 0){
            if (this.contentUrlArray.length == 0)
                this.InitializeArray(this.contentUrlArray, "");
            if (this.popupElementIDArray.length == 0)
                this.InitializeArray(this.popupElementIDArray, "");
            if (this.showOnPageLoadArray.length == 0)
                this.InitializeArray(this.showOnPageLoadArray, false);
            if (this.isDraggedArray.length == 0)
                this.InitializeArray(this.isDraggedArray, false);
            if (this.isResizedArray.length == 0)
                this.InitializeArray(this.isResizedArray, false);
            if (this.zIndexArray.length == 0)
                this.InitializeArray(this.zIndexArray, -1);                
            if (this.leftArray.length == 0)
                this.InitializeArray(this.leftArray, 0);
            if (this.topArray.length == 0)
                this.InitializeArray(this.topArray, 0);
            if (this.widthArray.length == 0)
                this.InitializeArray(this.widthArray, 0);
            if (this.heightArray.length == 0)
                this.InitializeArray(this.heightArray, 0);
            if (this.cachedSizeArray.length == 0)
                this.InitializeArray(this.cachedSizeArray, null);
            if (__aspxIE){
                if (this.headerHeightArray.length == 0)
                    this.InitializeArray(this.headerHeightArray, -1);
                if (this.footerHeightArray.length == 0)
                    this.InitializeArray(this.footerHeightArray, -1);
            }
        }
    },
    InitializeArray: function(array, value){
        for (var i = 0; i < this.GetWindowCountCore(); i++)
            array[i] = value;
    },
    InitializeWindow: function(index){
        this.GetPopupElement(index);
        var element = this.GetWindowElement(index);
        if (element != null){
            element.onresize = new Function("aspxPWResize(\""+ this.name + "\",\"" + element.id + "\");");
            if (__aspxIE)
                this.AttachOnDragStartEventToWindowImages(index);

            element.isHiding = false;
            element.isIEContentHeightInit = false;
            element.isPopupPositionCorrectionOn = this.isPopupPositionCorrectionOn || !this.GetShowOnPageLoad(index);
            if (this.GetShowOnPageLoad(index) && this.GetZIndex(index) > 0){
                this.FirstShowWindow(index, false);
                aspxGetPopupControlCollection().SetWindowElementZIndex(element, this.GetZIndex(index));
                element.isPopupPositionCorrectionOn = true;
            }
        }
    },
    AfterInitializeWindow: function(index){
        if (this.GetShowOnPageLoad(index) && this.GetZIndex(index) < 0){
            this.FirstShowWindow(index, true);
            
            var element = this.GetWindowElement(index);
            if (element != null)
                element.isPopupPositionCorrectionOn = true;     
            
        }
    },
    // fix: ondragstart event is not valid for XHTML
    AttachOnDragStartEventToWindowImages: function(index) {            
        this.AttachChildImagesPreventDragStartEvent(this.GetWindowHeaderElement(index));
        this.AttachChildImagesPreventDragStartEvent(this.GetWindowFooterElement(index));
    },
    AttachChildImagesPreventDragStartEvent: function(parentElem) {
        var images = parentElem == null ? null : _aspxGetElementsByTagName(parentElem, "img");
        if (images != null) {        
            for(var i = 0; i < images.length; i ++)
                images[i].ondragstart = new Function("return _aspxPreventDragStart(event)");        
         }    
    },
    
    FirstShowWindow: function(index, allowChangeZIndex){
        var isFreeWindow = this.GetIsDragged(index);
        var x = __aspxInvalidPosition;
        var y = __aspxInvalidPosition;
        if (isFreeWindow){
            x = this.GetWindowLeft(index);
            y = this.GetWindowTop(index);
            var popupHorizontalOffsetBackup = this.popupHorizontalOffset;
            var popupVerticalOffsetBackup = this.popupVerticalOffset;
            this.popupHorizontalOffset = 0;
            this.popupVerticalOffset = 0;
        }
        var enableAnimationBackup = this.enableAnimation;
        this.enableAnimation = false;
        
        this.DoShowWindowAtPos(index, x, y, isFreeWindow, false, allowChangeZIndex);
        
        this.enableAnimation = enableAnimationBackup;
        if (isFreeWindow){
            this.popupHorizontalOffset = popupHorizontalOffsetBackup ;
            this.popupVerticalOffset = popupVerticalOffsetBackup;
        }
    },
    GetIsDragged: function(index){
        if(0 <= index && index < this.isDraggedArray.length)
            return this.isDraggedArray[index];
        return this.isDragged;
    },
    SetIsDragged: function(index, value){
        if(0 <= index && index < this.isDraggedArray.length)
            this.isDraggedArray[index]=value;
        else            
            this.isDragged=value;
    },
    GetIsResized: function(index){
        if(0 <= index && index < this.isResizedArray.length)
            return this.isResizedArray[index];
        return this.isResized;
    },
    SetIsResized: function(index, value){
        if(0 <= index && index < this.isResizedArray.length)
            this.isResizedArray[index]=value;
        else            
            this.isResized=value;
    },
    HasDefaultWindow: function() {
        return this.GetWindowCountCore() == 0;
    },
    GetCurrentLeft: function(index){
        return this.GetPosition(index, true);
    },
    GetCurrentTop: function(index){
        return this.GetPosition(index, false);
    },
    GetHeaderHeight: function(index){
        if(0 <= index && index < this.headerHeightArray.length)
            return this.headerHeightArray[index];
        return this.headerHeight;
    },
    GetFooterHeight: function(index){
        if(0 <= index && index < this.footerHeightArray.length)
            return this.footerHeightArray[index];
        return this.footerHeight;
    },
    SetHeaderHeight: function(index, height){
        if(0 <= index && index < this.headerHeightArray.length)
            this.headerHeightArray[index] = height;
        else
            this.headerHeight = height;
    },
    SetFooterHeight: function(index, height){
        if(0 <= index && index < this.footerHeightArray.length)
            return this.footerHeightArray[index] = height;
        else 
            this.footerHeight = height;
    },
    GetPosition: function(index, isLeft){
        if(0 <= index && index < this.GetWindowCountCore())
            return  isLeft ? this.leftArray[index] : this.topArray[index];
        return  isLeft ? this.left : this.top;
    },
    GetPopupElement: function(index){
        var popupElement = this.GetPopupElementInternal(index);
        var modalElement = this.GetWindowModalElement(index);
        if(_aspxIsExists(modalElement))
            _aspxAttachEventToElement(modalElement, "mousedown", aspxPWMEMDown);
                        
        if(!_aspxIsExistsElement(popupElement)){
            var popupElement = _aspxFindPopupElementById(this.GetPopupElementID(index));
            if(_aspxIsExistsElement(popupElement)) {
                popupElement.DXPopupControl = this;
                popupElement.DXPopupWindowIndex = index;
                popupElement.isPopuped = false;
                
                if (this.popupAction == "LeftMouseClick")
                    _aspxAttachEventToElement(popupElement, "mouseup", aspxPEMEvent);
                else if (this.popupAction == "RightMouseClick")
                    _aspxAttachEventToElement(popupElement, "contextmenu", aspxPEMEvent);
                else if (this.popupAction == "MouseOver"){
                    _aspxAttachEventToElement(popupElement, "mouseover", aspxPEMOver);            
                    _aspxAttachEventToElement(this.GetWindowElement(index), "mouseover", aspxPWEMOver);
                }                    
                if (this.popupAction == "LeftMouseClick" || this.popupAction == "RightMouseClick"){
                    _aspxAttachEventToElement(popupElement, "mousedown", aspxPEMEvent);
                    this.isNeedPopupedSet = true;
                }
                
                this.SetPopupElementInternal(index, popupElement);
            }
        }
        return popupElement;
    },
    GetPopupElementInternal: function(index){
        if(0 <= index && index < this.GetWindowCountCore())
            return this.popupElements[index];
        return this.popupElement;
    },
    SetPopupElementInternal: function(index, element){
        if(0 <= index && index < this.GetWindowCountCore())
            this.popupElements[index] = element;
        else
            this.popupElement = element;
    },
    GetPopupElementID: function(index){
        if(0 <= index && index < this.GetWindowCountCore())
            return this.popupElementIDArray[index];
        return this.popupElementID;
    },
    GetShowOnPageLoad: function(index){
        if(0 <= index && index < this.showOnPageLoadArray.length)
            return this.showOnPageLoadArray[index];
        return this.showOnPageLoad;
    },
    GetWindowCountCore: function(){
        return (this.windows.length > 0) ? this.windows.length : this.windowCount;
    },
    GetWindowIFrame: function(index){
        var element = this.GetWindowElement(index);
        var iFrame = element.overflowElement;
        if(!_aspxIsExists(iFrame)){
            iFrame = this.FindWindowIFrame(index);
            element.overflowElement = iFrame;
        }
        return iFrame;
    },
    FindWindowIFrame: function(index){
        return _aspxGetElementById(this.name + "_DXPWIF" + index);
    },
    GetWindowModalElement: function(index){
        var element = this.GetWindowElement(index);
        if(!_aspxIsExists(element)) return;
        
        var modalElement = element.modalElement;
        if(!_aspxIsExists(modalElement)){
            modalElement = this.FindWindowModalElement(index);
            element.modalElement = modalElement;
            if(_aspxIsExists(modalElement)){
                modalElement.DXModalPopupControl = this;
                modalElement.DXModalPopupWindowIndex = index;
            }
        }
        return modalElement;
    },
    FindWindowModalElement: function(index){
        return _aspxGetElementById(this.name + "_DXPWMB" + index);
    },
    GetWindowElementId: function(index){
        return this.name + __aspxPCWIdSuffix + index;
    },
    GetWindowElement: function(index){
        if(!_aspxIsExistsElement(this.windowElements[index]))
            this.windowElements[index] = _aspxGetElementById(this.GetWindowElementId(index));
        return this.windowElements[index];
    },
    GetWindowChild: function(index, idPostfix){
        return _aspxGetChildById(this.GetWindowElement(index), this.name + idPostfix);
    },
    GetWindowContentIFrameDivElementID: function(index){
        return this.name + "_CIFD" + index;
    },
    GetWindowContentIFrameDivElement: function(index){
        return this.GetWindowChild(index, "_CIFD" + index);
    },
    GetWindowContentIFrameElementId: function(index){
        return this.name + "_CIF" + index;
    },
    GetWindowContentIFrameElement: function(index){
        return this.GetWindowChild(index, "_CIF" + index);
    },
    GetWindowContentIFrameUrl: function(index){
        if(0 <= index && index < this.contentUrlArray.length)
            return this.contentUrlArray[index];
        return this.contentUrl;
    },
    SetWindowContentIFrameUrl: function(index, url){
        if(0 <= index && index < this.contentUrlArray.length)
            this.contentUrlArray[index] = url;
        else
            this.contentUrl = url;
    },
    ShowWindowContentUrl: function(index){
        if(__aspxMozilla || __aspxSafariFamily){
            var contentIFrameDiv = this.GetWindowContentIFrameDivElement(index);
            var contentIFrame = this.GetWindowContentIFrameElement(index);
            if(_aspxIsExists(contentIFrameDiv))
                contentIFrameDiv.style.height = "100%";
            if(_aspxIsExists(contentIFrame))
                contentIFrame.style.height = contentIFrameDiv.clientHeight + "px";
        }
        this.LoadWindowContentUrl(index);
    },
    LoadWindowContentUrl: function(index){
        var url = this.GetWindowContentIFrameUrl(index);
        this.LoadWindowContentFromUrl(index, url);
    },
    LoadWindowContentFromUrl: function(index, url){
        var element = this.GetWindowContentIFrameElement(index);
        if(_aspxIsExists(element) && element.src != url && element.DXSrcRaw != url){
            this.SetSrcToIframeElement(element, url);
            this.SetWindowContentIFrameUrl(index, element.src); // B130888
        }
    },
    SetSrcToIframeElement: function(iframeElement, src){
        iframeElement.src = src;
	    iframeElement.DXSrcRaw = src;
    },
    GetWindowContentElement: function(index){
        return this.GetWindowChild(index, "_PWC" + index);
    },
    GetWindowHeaderElement: function(index){
        return this.GetWindowChild(index, "_PWH" + index);
    },
    GetWindowHeaderGripElement: function(index){
        return this.GetWindowChild(index, "_FGRP" + index);
    },
    GetWindowFooterElement: function(index){
        return this.GetWindowChild(index, "_PWF" + index);
    },
    GetWindowIndex: function(element){
        var id = element.id;
        var pos = id.lastIndexOf(__aspxPCWIdSuffix);
        return parseInt(id.substr(pos + __aspxPCWIdSuffix.length));
    },
    GetWindowMainCell: function(element){
        return this.GetWindowMainTable(element).rows[0].cells[0];
    },
    GetWindowMainTable: function(element){
        var index = this.GetWindowIndex(element);
        var shadowTable = this.GetWindowChild(index, "_PWST" + index);
        return shadowTable != null ? shadowTable : element;
    },
    GetWindowClientTable: function(index){
        return this.GetWindowChild(index, "_CLW" + index);
    },
    GetWindowLeft: function(index){
        if(0 <= index && index < this.leftArray.length)
            return this.leftArray[index];
        return this.left;
    },
    SetWindowLeft: function(index, left){
        if(0 <= index && index < this.leftArray.length)
            this.leftArray[index] = left;
        else
            this.left = left;
    },
    GetWindowHeightInternal: function(index){
        if(0 <= index && index < this.heightArray.length)
            return this.heightArray[index];
        return this.height;
    },
    SetWindowHeight: function(index, height){
        if(0 <= index && index < this.heightArray.length)
            this.heightArray[index] = height;
        else 
            this.height = height;
    },
    GetWindowWidthInternal: function(index){
        if(0 <= index && index < this.widthArray.length)
            return this.widthArray[index];
        return this.width;
    },
    SetWindowWidth: function(index, width){
        if(0 <= index && index < this.widthArray.length)
            this.widthArray[index] = width;
        else 
            this.width = width;
    },
    GetWindowTop: function(index){
        if(0 <= index && index < this.topArray.length)
            return this.topArray[index];
        return this.top;
    },
    SetWindowTop: function(index, top){
        if(0 <= index && index < this.topArray.length)
            return this.topArray[index] = top;
        else
            return this.top = top;
    },
    GetWindowsStateInputElement: function(){
        return _aspxGetElementById(this.name + "WS");
    },
    GetZIndex: function(index){
        if (0 <= index && index < this.zIndexArray.length)
            return this.zIndexArray[index];
        return this.zIndex;
    },
    GetCurrentZIndex: function(index){
        var element = this.GetWindowElement(index);
        if(element != null) {
            if(element.style.zIndex != "") 
                return element.style.zIndex;
            if(0 <= index && index < this.GetWindowCountCore())
                return  this.zIndexArray[index];
            return this.zIndex;
        }
    },
    GetCurrentWindowWidth: function(index){
        var element = this.GetWindowElement(index);
        if(element != null) {
            var mainCell = this.GetWindowMainCell(element);
            if(mainCell.firstChild.offsetWidth > 0)
                return mainCell.firstChild.offsetWidth;
            return this.GetWindowWidthInternal(index);
        }
    },
    GetCurrentWindowHeight: function(index){
        var element = this.GetWindowElement(index);
        if(element != null) {
            var mainCell = this.GetWindowMainCell(element);
            if(mainCell.firstChild.offsetHeight > 0)
                return mainCell.firstChild.offsetHeight;
            return this.GetWindowHeightInternal(index);
        }
    },
    
    GetClientPopupPos: function(element, popupElement, pos, isX, isDragged){
        var index = this.GetWindowIndex(element);
        var popupPosition = null;
        
        if (isDragged)
            popupPosition = new _aspxPopupPosition(this.GetPosition(index, isX), false);
        else
            popupPosition = isX ? this.GetClientPopupPosX(element, popupElement, pos) : this.GetClientPopupPosY(element, popupElement, pos);
        popupPosition.position = _aspxPrepareClientPosForElement(popupPosition.position, element, isX);
        
        if(__aspxFirefox && !__aspxFirefox3 && _aspxIsExists(this.GetWindowModalElement(index)))
            popupPosition.position -= isX ? _aspxGetDocumentScrollLeft() : _aspxGetDocumentScrollTop();
        if(__aspxIE && !__aspxIE55 && popupElement != null && _aspxIsExistsAbsoluteOrRelativePosParent(popupElement))
            popupPosition.position -= _aspxGetIEDocumentClientOffset(isX);
        return popupPosition;
    },
    GetClientPopupPosX: function(element, popupElement, x){
        var mainElement = this.GetWindowMainCell(element);
        var popupPosition = _aspxGetPopupAbsoluteX(mainElement, this.shadowWidth,popupElement, this.popupHorizontalAlign, this.popupHorizontalOffset, 
            x, this.GetWindowLeft(this.GetWindowIndex(element)));
        return this.CorrectPopupPositionForClientWindow(element, popupPosition, true);
    },
    GetClientPopupPosY: function(element, popupElement, y){
        var mainElement = this.GetWindowMainCell(element);
        var popupPosition = _aspxGetPopupAbsoluteY(mainElement, this.shadowHeight, popupElement, this.popupVerticalAlign, this.popupVerticalOffset, 
            y, this.GetWindowTop(this.GetWindowIndex(element)));
        return (this.allowCorrectYOffsetPosition ? this.CorrectPopupPositionForClientWindow(element, popupPosition, false) : popupPosition);
    },
    CorrectPopupPositionForClientWindow: function(element, popupPosition, isX){
        if (element.isPopupPositionCorrectionOn){
            popupPosition.position = _aspxAdjustPositionToClientScreen(element, 
                isX ? this.shadowWidth : this.shadowHeight, popupPosition.position, isX);
        }
        return popupPosition;
    },
    DoShowWindow: function(index, evt){
        if (!this.InternalIsWindowVisible(index)){
            var x = _aspxGetEventX(evt);
            var y = _aspxGetEventY(evt);
            this.DoShowWindowAtPos(index, x, y, false, true, true);
        }
    },
    DoShowWindowAtPos: function(index, x, y, ignorePopupElement, closeOtherWindows, allowChangeZIndex){
        var element = this.GetWindowElement(index);
        if(element != null){
            if (this.adjustInnerControlsSizeOnShow) {
                var windowContent = this.GetWindowContentElement(index);
                var collection = aspxGetControlCollection();
                collection.CollapseControls(windowContent, __aspxCheckSizeCorrectedFlag);
            }
            
            this.FFTextCurFixShow(index, true);
            if (closeOtherWindows)
                aspxGetPopupControlCollection().DoHideAllWindows(null, this.GetWindowElementId(index), false);
        
            var isMoving = this.InternalIsWindowVisible(index);
            _aspxSetElementDisplay(element, true);
            
            if(__aspxIE && !element.isIEContentHeightInit){
                element.isIEContentHeightInit = true;
                this.GetWindowContentElement(index).style.height = "0px";
                this.CorrectContentCellHeight(element, false); //Header and footer height initialization for resizing
            }
            
            var cachedSize = this.GetWindowCachedSize(index);
            if(cachedSize != null){
                this.SetWindowSize(this.GetWindow(index), cachedSize.width, cachedSize.height);
                this.ResetWindowCachedSize(index);
            }
            
            var popupElement = ignorePopupElement ? null : this.GetPopupElement(index);
            var isDragged = this.GetIsDragged(index);
            var horizontalPopupPosition = this.GetClientPopupPos(element, popupElement, x, true, isDragged);
            var verticalPopupPosition = this.GetClientPopupPos(element, popupElement, y, false, isDragged);

            var clientX = horizontalPopupPosition.position;
            var clientY = verticalPopupPosition.position;
            this.SetWindowPos(index, element, clientX, clientY);

            this.DoShowWindowModalElement(index);
            var isAnimationNeed = this.enableAnimation && !isMoving;
            if (isAnimationNeed)
                this.StartAnimation(element, index, horizontalPopupPosition, verticalPopupPosition);
            else
                _aspxSetElementVisibility(element, true);

            if (!isMoving){
                aspxGetPopupControlCollection().RegisterVisibleWindow(element);
                this.RaisePopUp(index);
                if(!this.enableAnimation)
                    this.RaiseShowen(index);
            }
            if (allowChangeZIndex){
                aspxGetPopupControlCollection().ActivateWindowElement(element);
            }
            
            // Prevent bug in Netscape. First window showing, window is under its modalelement undependet on zIndex
            if(!isAnimationNeed && __aspxNetscape && _aspxIsExists(this.GetWindowModalElement(index))){
                _aspxSetElementDisplay(element, false);
                _aspxSetElementDisplay(element, true);
            }
            
            this.ShowWindowContentUrl(index);

            if (this.adjustInnerControlsSizeOnShow) {
                collection.AdjustControls(windowContent, __aspxCheckSizeCorrectedFlag);
            }
        }
    },
    DoShowWindowIFrame: function(index, x, y, width, height){
        if (!this.renderIFrameForPopupElements) return;
        
        var element = this.GetWindowElement(index);
        var iFrame = this.GetWindowIFrame(index);
        if(_aspxIsExists(element) && _aspxIsExists(iFrame)){
            var cell = this.GetWindowMainCell(element);
            if (width < 0)
                width = cell.offsetWidth;
            if (height < 0)
                height = cell.offsetHeight;
            _aspxSetStyleSize(iFrame, width, height);
            if (x != __aspxInvalidPosition && y != __aspxInvalidPosition)
                _aspxSetStylePosition(iFrame, x, y);
            _aspxSetElementDisplay(iFrame, true);
        }
    },
    DoShowWindowModalElement: function(index){
        var modalElement = this.GetWindowModalElement(index);
        if(_aspxIsExists(modalElement)){
            if(this.hideBodyScrollWhenModal && !this.IsWindowVisible(this.GetWindow(index)))
                _aspxHideBodyScroll();
            _aspxSetElementDisplay(modalElement, true);
            aspxGetPopupControlCollection().AdjustModalElementBounds(modalElement);
            _aspxSetElementVisibility(modalElement, true);
            aspxGetPopupControlCollection().RegisterVisibleModalElement(modalElement);
        }
    },
    DoHideWindowCore: function(index){
        this.FFTextCurFixHide(index, true);
        var element = this.GetWindowElement(index);
        if(element != null){
            element.isHiding = true;
            this.SetIsDragged(index, false);
            this.UpdateWindowsStateInputElement();
            this.UpdateWindowsStateCookie();
            element.isHiding = false;
            
            _aspxStopAnimation(element);
            
            _aspxSetElementVisibility(element, false);
            _aspxSetElementDisplay(element, false);
            
            this.DoHideWindowModalElement(element);
            this.DoHideWindowIFrame(element);
            
            aspxGetPopupControlCollection().UnregisterVisibleWindow(element);
        }
    },
    DoHideWindow: function(index){
        if (!this.InternalIsWindowVisible(index)) return;
        
        var cancel = this.RaiseClosing(index);

        if(!cancel){
            this.DoHideWindowCore(index);
            this.RaiseCloseUp(index);
        }
        return cancel;
    },
    DoHideWindowIFrame: function(element){
        if (!this.renderIFrameForPopupElements) return;

        var iFrame = element.overflowElement;
        if(_aspxIsExists(iFrame))
            _aspxSetElementDisplay(iFrame, false);
    },
    DoHideWindowModalElement: function(element){
        var modalElement = element.modalElement;
        if(_aspxIsExists(modalElement)){
            aspxGetPopupControlCollection().UnregisterVisibleModalElement(modalElement);
            if(this.hideBodyScrollWhenModal)
                _aspxRestoreBodyScroll();
            _aspxSetStyleSize(modalElement, 1, 1);
            _aspxSetElementVisibility(modalElement, false);
            _aspxSetElementDisplay(modalElement, false);
        }
    },
    SetWindowDisplay: function(index, value){
        var pcwElement = this.GetWindowElement(index);
        this.SetFFTextCurFixShowing(index, value, false);
        _aspxSetElementDisplay(pcwElement, value);
    },
    GetTextCurFixDiv: function(index){
        return _aspxGetElementById(this.name + "_" + "TCFix" + index);
    },
    FFTextCurFixShow: function(index, isSetVisibility){
        this.SetFFTextCurFixShowing(index, true, isSetVisibility);
    },
    FFTextCurFixHide: function(index, isSetVisibility){
        this.SetFFTextCurFixShowing(index, false, isSetVisibility);
    },
    IsFFTextCurFixRequired: function(index){
        return __aspxFirefox && _aspxIsExists(this.GetWindowModalElement(index));
    },
    SetFFTextCurFixShowing: function(index, value, isSetVisibility){
        if(this.IsFFTextCurFixRequired(index)){
            var fixDiv = this.GetTextCurFixDiv(index);
            if(_aspxIsExists(fixDiv)){
                if(isSetVisibility)
                    _aspxSetElementVisibility(fixDiv, value);
                _aspxSetElementDisplay(fixDiv, value);
            }
        }        
    },
    SetWindowPos: function(index, element, x, y){
        _aspxSetStylePosition(element, x, y);
        this.DoShowWindowIFrame(index, x, y, __aspxInvalidDimension, __aspxInvalidDimension);

        this.SetIsDragged(index, true);
        this.SetWindowLeft(index, _aspxGetAbsoluteX(element));
        this.SetWindowTop(index, _aspxGetAbsoluteY(element));
        this.UpdateWindowsStateInputElement();
        this.UpdateWindowsStateCookie();
    },

    CorrectContentCellHeight: function(element, isResizing){
        if (__aspxIE){
            var index = this.GetWindowIndex(element);
            var clientTable = this.GetWindowClientTable(index);
            var headerCell = this.GetWindowHeaderElement(index);
            var contentCell = this.GetWindowContentElement(index);
            var footerCell = this.GetWindowFooterElement(index);
            
            var windowMainCell = this.GetWindowMainCell(element);
            var mainCellHeight = windowMainCell.clientHeight - this.GetTwoVerticalPaddingSize(windowMainCell);
            var headerHeight = _aspxIsExists(headerCell) ? headerCell.offsetHeight : 0;
            var footerHeight = _aspxIsExists(footerCell) ? footerCell.offsetHeight : 0;
            if (isResizing){
                headerHeight = this.GetHeaderHeight(index);
                footerHeight = this.GetFooterHeight(index);
            }
            else{
                this.SetHeaderHeight(index, headerHeight);
                this.SetFooterHeight(index, footerHeight);
            }
            var correctedHeight = mainCellHeight - headerHeight - footerHeight;
            
            contentCell.style.height = correctedHeight + "px";
            var verticalsPaddings = contentCell.offsetHeight - correctedHeight;
            contentCell.style.height = correctedHeight - verticalsPaddings + "px";
        }
    },
    GetTwoVerticalPaddingSize: function(element){
        var heightWithBorders = element.clientHeight;
        var paddingTopBackup = element.style.paddingTop;
        var paddingBottomBackup = element.style.paddingBottom;
        element.style.paddingTop = "0px";
        element.style.paddingBottom = "0px";
        var heightWithoutBorders = element.clientHeight;
        element.style.paddingTop = paddingTopBackup;
        element.style.paddingBottom = paddingBottomBackup;
        return (heightWithBorders - heightWithoutBorders);
    },
    InternalIsWindowVisible: function(index){
        var element = this.GetWindowElement(index);
        return (element != null) ? _aspxGetElementVisibility(element) : false;
    },
    InternalIsWindowDisplayed: function(index){
        var element = this.GetWindowElement(index);
        return (element != null) ? _aspxGetElementDisplay(element) : false;
    },
    OnActivate: function(index){
        var element = this.GetWindowElement(index);
        if (element != null)
            aspxGetPopupControlCollection().ActivateWindowElement(element);
    },
    OnAnimationTimer: function(index){
        var animationDivElement = this.GetWindowElement(index);
        if(_aspxIsExists(animationDivElement)){
            var element = this.GetWindowMainTable(animationDivElement);
            var mainCell = this.GetWindowMainCell(animationDivElement);
            var iframeElement = this.GetWindowIFrame(index);
            
            _aspxOnAnimationTimer(animationDivElement, element, mainCell, iframeElement, this.animationDelay, this.animationMaxDelay,__aspxPCAnimationAccelerator);
        }
    },
    OnAnimationStop: function(index){
        this.RaiseShowen(index);
    },
    OnDragStart: function(evt, index){
        this.SetIsDragged(index, true);
        this.ShowDragCursor(index);
        var element = this.GetWindowElement(index);
        if(_aspxIsExists(this.GetWindowContentIFrameElement(index)))
            this.HideIframeElementBeforeDragging(index);        
        var gragXOffset = _aspxGetAbsoluteX(element) - _aspxGetEventX(evt) - _aspxGetIEDocumentClientOffset(true);
        var gragYOffset = _aspxGetAbsoluteY(element) - _aspxGetEventY(evt) - _aspxGetIEDocumentClientOffset(false);
        var xClientCorrection = _aspxGetPositionElementOffset(element, true);
        var yClientCorrection = _aspxGetPositionElementOffset(element, false);
        gragXOffset -= xClientCorrection;
        gragYOffset -= yClientCorrection;
        aspxGetPopupControlCollection().InitDragObject(this, index, gragXOffset, gragYOffset, xClientCorrection, yClientCorrection);
    },
    OnDrag: function(index, x, y, xClientCorrection, yClientCorrection) {
        var element = this.GetWindowElement(index);
        if(element != null){
            _aspxSetStylePosition(element, x, y);        
            this.SetWindowLeft(index, x + xClientCorrection);
            this.SetWindowTop(index, y + yClientCorrection);
                        
            var iFrame = element.overflowElement;
            if(_aspxIsExists(iFrame))
                _aspxSetStylePosition(iFrame, x, y);
            if (__aspxOpera) 
                _aspxClearSelection();
        }
    },
    OnDragStop: function(index) {
        var element = this.GetWindowElement(index);
        this.HideDragCursor(index);
        this.UpdateWindowsStateInputElement();
        this.UpdateWindowsStateCookie();
        if(_aspxIsExists(this.GetWindowContentIFrameElement(index)))
            this.ShowIframeElementAfterDragging(index);
    },
    HideIframeElementBeforeDragging: function(index){
        var iframeElement = this.GetWindowContentIFrameElement(index);
        if(__aspxIE){
            this.CreateFakeDragDiv(iframeElement);
            _aspxSetElementDisplay(iframeElement, false);
        } else
            _aspxSetElementVisibility(iframeElement, false);
    },
    ShowIframeElementAfterDragging: function(index){
        var iframeElement = this.GetWindowContentIFrameElement(index);
        if(this.fakeDragDiv != null){
            this.RemoveFakeDragDiv(iframeElement);
            _aspxSetElementDisplay(iframeElement, true);
        } else
            _aspxSetElementVisibility(iframeElement, true);
    },
    CreateFakeDragDiv: function(iframe) {
        this.fakeDragDiv = document.createElement("div");
        _aspxSetStyleSize(this.fakeDragDiv, iframe.offsetWidth, iframe.offsetHeight);        
        iframe.parentElement.appendChild(this.fakeDragDiv);
    },
    RemoveFakeDragDiv: function(iframe) {
        iframe.parentElement.removeChild(this.fakeDragDiv);
        this.fakeDragDiv = null;
    },
    CreateResizePanel: function(index){
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var resizePanel = document.createElement("DIV");
        element.parentNode.appendChild(resizePanel);
        resizePanel.style.overflow = "hidden";
        resizePanel.style.position = "absolute";
        resizePanel.style.zIndex = __aspxPopupControlZIndex + aspxGetPopupControlCollection().visiblePopupWindowIds.length * 2 + 2;
        if (!this.isLiveResizingMode)
            resizePanel.style.border = "black 1px dotted";
        return resizePanel;
    },
    OnResizeStart: function(evt, index){
            if (!aspxGetPopupControlCollection().IsResizeInint()){
            this.SetIsResized(index, true);
            var cursor = this.CreateResizeCursorInfo(evt, index);
            if (cursor.course != ""){
                var resizePanel = this.CreateResizePanel(index);
                this.UpdateResizeCursor(resizePanel, cursor.verticalDirection, cursor.horizontalDirection);
                aspxGetPopupControlCollection().InitResizeObject(this, index, cursor, resizePanel);
                this.OnResize(evt, index, cursor, resizePanel);
            }
        }
        return aspxGetPopupControlCollection().IsResizeInint();
    },
    OnResize: function(evt, index, cursor, resizePanel){
        this.OnResizePanel(evt, index, cursor, resizePanel);
        if (this.isLiveResizingMode)
            this.OnResizeWindow(index, cursor, resizePanel);
        if (!__aspxIE) 
            _aspxClearSelection();
    },
    OnResizePanel: function(evt, index, cursor, resizePanel){
        var x = _aspxGetEventX(evt);
        var y = _aspxGetEventY(evt);
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var clientWindow = this.GetWindowClientTable(index);
        
        var left = _aspxGetAbsoluteX(mainCell);
        var top = _aspxGetAbsoluteY(mainCell);
        var newLeft = _aspxGetAbsoluteX(element);
        var newTop  = _aspxGetAbsoluteY(element);
        var newHeight = mainCell.offsetHeight;
        var newWidth = mainCell.offsetWidth;

        if(cursor.horizontalDirection == "e")
            newWidth = x - newLeft + cursor.horizontalOffset + 1;
        if(cursor.verticalDirection == "s")
            newHeight = y - newTop + cursor.verticalOffset + 1;
        if(cursor.horizontalDirection == "w") {
            newLeft = _aspxPrepareClientPosForElement(x, element, true) - cursor.horizontalOffset;
            newWidth = newWidth - (x - left) + cursor.horizontalOffset;
        }else
            newLeft = _aspxPrepareClientPosForElement(newLeft, element, true);
        if(cursor.verticalDirection == "n"){
            newTop =_aspxPrepareClientPosForElement(y, element, false) - cursor.verticalOffset;
            newHeight = newHeight - (y - top) + cursor.verticalOffset;
        }else
            newTop = _aspxPrepareClientPosForElement(newTop, element, false);

        if(!this.isLiveResizingMode){// Correction for both side border size
            newWidth -= 2; 
            newHeight -= 2;
        }
        
        if(newWidth > 0 && newHeight > 0) {
            _aspxSetStylePosition(resizePanel, newLeft - _aspxGetIEDocumentClientOffset(true), newTop - _aspxGetIEDocumentClientOffset(false));
            _aspxSetStyleSize(resizePanel, newWidth, newHeight);
            
            this.SetWindowLeft(index, _aspxGetAbsoluteX(element));
            this.SetWindowTop(index, _aspxGetAbsoluteY(element));
        }
    },
    OnResizeWindow: function(index, cursor, resizePanel){
        this.SetClientWindowSize(index, resizePanel.offsetWidth, resizePanel.offsetHeight);
        
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var heightCorrection = mainCell.offsetHeight - resizePanel.offsetHeight;
        var widthCorrection = mainCell.offsetWidth - resizePanel.offsetWidth;
        var left = _aspxGetAbsoluteX(resizePanel) - (cursor.horizontalDirection == "w" ? widthCorrection : 0) - _aspxGetIEDocumentClientOffset(true);
        var top  = _aspxGetAbsoluteY(resizePanel) - (cursor.verticalDirection == "n" ?  heightCorrection : 0) - _aspxGetIEDocumentClientOffset(false);
        left = _aspxPrepareClientPosForElement(left, element, true);
        top = _aspxPrepareClientPosForElement(top, element, false);
        
        _aspxSetStylePosition(element, left, top);
        this.DoShowWindowIFrame(index, left, top, __aspxInvalidDimension, __aspxInvalidDimension);
    },
    OnResizeStop: function(evt, index, cursor, resizePanel){
        if(this.allowResize){
            if (!this.isLiveResizingMode) {
                var collection = aspxGetControlCollection();
                var windowElement = this.GetWindowElement(index);
                collection.CollapseControls(windowElement);
                this.OnResizeWindow(index, cursor, resizePanel);
            }
            this.CreateResizeCursorInfo(evt, index);
            this.UpdateWindowsStateInputElement();
            this.UpdateWindowsStateCookie();
            this.RaiseResize(index);
            if (!this.isLiveResizingMode)
                collection.AdjustControls(windowElement);
        }
    },
    OnMouseDownModalElement: function(evt, index) {
        aspxGetPopupControlCollection().DoHideAllWindows(_aspxGetEventSource(evt), "", false);
        if (this.isNeedPopupedSet) {
            var popupElement = this.GetPopupElement(index);
            popupElement.isPopuped = true;
        }
    },
    SetClientWindowSize: function(index, width, height){
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var clientWindow = this.GetWindowClientTable(index);
        var windowHorizontalTwoBorderSize = mainCell.offsetWidth - clientWindow.offsetWidth;
        var windowVerticalTwoBorderSize = mainCell.offsetHeight - clientWindow.offsetHeight;
        
        var contentIFrameDiv = this.GetWindowContentIFrameDivElement(index);
        var contentIFrame = this.GetWindowContentIFrameElement(index);
        
        width -= windowHorizontalTwoBorderSize;
        height -= windowVerticalTwoBorderSize;
	    if (width >= 0 && height >= 0){
	        this.RaiseBeforeResizing(index);
            if (__aspxIE){
                this.GetWindowContentElement(index).style.height = "0px";
                mainCell.style.height = "0px"; // Prevent some time mainCell height persistance and increase PC whole height
            } else {
                if (_aspxIsExists(contentIFrame))
                    contentIFrame.style.height = "0px";
                if(_aspxIsExists(contentIFrameDiv)) 
                    contentIFrameDiv.style.height = "0px";
            }
            _aspxSetStyleSize(clientWindow, width, height);

            _aspxSetStyleSize(mainCell, width, height);
            if (__aspxMozilla){// Prevent Mozilla invalid horizontal resizing panel in ContentControl
                _aspxSetElementDisplay(element, false);
                _aspxSetElementDisplay(element, true);
            }
            _aspxSetStyleSize(element, clientWindow.offsetWidth + this.shadowWidth + windowHorizontalTwoBorderSize, clientWindow.offsetHeight + this.shadowHeight + windowVerticalTwoBorderSize);
            this.CorrectContentCellHeight(element, true);
            
            this.SetWindowWidth(index, clientWindow.offsetWidth);
            this.SetWindowHeight(index, clientWindow.offsetHeight);
            
            if(_aspxIsExists(contentIFrameDiv))
                contentIFrameDiv.style.height = "100%";
            if(_aspxIsExists(contentIFrame))
                contentIFrame.style.height = "100%";
            this.RaiseAfterResizing(index);
        }
    },
    SetWindowCachedSize: function(index, width, height) {
        if(0 <= index && index < this.heightArray.length)
            this.cachedSizeArray[index] = new _aspxSize(width, height);
        else 
            this.cachedSize = new _aspxSize(width, height);
    },
    GetWindowCachedSize: function(index) {
        if(0 <= index && index < this.heightArray.length)
            return this.cachedSizeArray[index];
        else 
            return this.cachedSize;
    },
    ResetWindowCachedSize: function(index) {
        if(0 <= index && index < this.heightArray.length)
            this.cachedSizeArray[index] = null;
        else 
            this.cachedSize = null;
    },
    CreateResizeCursorInfo: function(evt, index){
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var clientWindow = this.GetWindowClientTable(index);
        var headerElement = this.GetWindowHeaderElement(index);
        var left = _aspxGetAbsoluteX(mainCell);
        var top = _aspxGetAbsoluteY(mainCell);
        var x = _aspxGetEventX(evt);
        var y = _aspxGetEventY(evt);

        var leftOffset = Math.abs(x - left);
        var rightOffset = Math.abs(x - left - mainCell.offsetWidth + 1);
        var topOffset = Math.abs(y - top);
        var bottomOffset = Math.abs(y - top - mainCell.offsetHeight + 1);

        var cursorInfo = this.CreateResizeBorderCursorInfo(index, leftOffset, rightOffset, topOffset, bottomOffset);
        
        var gripCell = this.GetWindowHeaderGripElement(index);
        if (gripCell) {
            var gripCursorInfo = this.CreateGripCursorInfo(index, mainCell, gripCell, rightOffset, bottomOffset);
            if (_aspxIsExists(gripCursorInfo))
                cursorInfo = gripCursorInfo;
        }
        this.UpdateResizeCursor(clientWindow, cursorInfo.verticalDirection, cursorInfo.horizontalDirection);
        this.UpdateResizeCursor(mainCell, cursorInfo.verticalDirection, cursorInfo.horizontalDirection);
        
        if (_aspxIsExists(headerElement))
            this.UpdateResizeCursor(headerElement, cursorInfo.verticalDirection, cursorInfo.horizontalDirection);
        return cursorInfo;
    },
    CreateGripCursorInfo: function(index, mainCell, gripCell, rightOffset, bottomOffset){
        var gripWidth  = mainCell.offsetWidth - (_aspxGetAbsoluteX(gripCell) - _aspxGetAbsoluteX(mainCell));
        var gripHeight = mainCell.offsetHeight - (_aspxGetAbsoluteY(gripCell) - _aspxGetAbsoluteY(mainCell));
        
        if (gripHeight > bottomOffset && gripWidth > rightOffset) 
            return new ASPxPCResizeCursorInfo("e", "s", rightOffset, bottomOffset);
        return null;
    },
    CreateResizeBorderCursorInfo: function(index, leftOffset, rightOffset, topOffset, bottomOffset){
        var ResizeBorderSize = this.ResizeBorderSize;
        var verticalDirection = this.GetResizeVerticalCourse(ResizeBorderSize, topOffset, bottomOffset);
        
        ResizeBorderSize = verticalDirection != "" ? this.ResizeCornerBorderSize : this.ResizeBorderSize;
        var horizontalDirection = this.GetResizeHorizontalCourse(ResizeBorderSize, leftOffset, rightOffset);
        
        if (verticalDirection == "" && horizontalDirection != "")
            verticalDirection = this.GetResizeVerticalCourse(this.ResizeCornerBorderSize, topOffset, bottomOffset);
        
        var horizontalOffset = leftOffset < rightOffset ? leftOffset : rightOffset;
        var verticalOffset = topOffset < bottomOffset ? topOffset : bottomOffset;
        return new ASPxPCResizeCursorInfo(horizontalDirection, verticalDirection, horizontalOffset, verticalOffset);
    },
    GetResizeVerticalCourse: function(ResizeBorderSize, topOffset, bottomOffset){
        if (ResizeBorderSize > topOffset) return "n";
        if (ResizeBorderSize > bottomOffset) return "s";
        return "";
    },
    GetResizeHorizontalCourse: function(ResizeBorderSize, leftOffset, rightOffset){
        if (ResizeBorderSize > leftOffset) return "w";
        if (ResizeBorderSize > rightOffset) return "e";
        return "";
    },
    UpdateResizeCursor: function(element, verticalDirection, horizontalDirection){
        var cursor = verticalDirection +  horizontalDirection;
        if (cursor != ""){
            cursor += "-resize";
            this.ShowTemporaryCursor(element, cursor);
        }
        else
            this.HideTemporaryCursor(element);
    },
    ShowTemporaryCursor: function(element, cursor){
        _aspxChangeStyleAttribute(element, "cursor", cursor);
    },
    HideTemporaryCursor: function(element){
        _aspxRestoreStyleAttribute(element, "cursor");
    },
    ResizeWindowIFrame: function(index){
        if (!this.renderIFrameForPopupElements) return;
        if (!this.InternalIsWindowVisible(index)) return;
        
        var iFrame = this.GetWindowIFrame(index);
        if(_aspxIsExists(iFrame)){    
            var cell = this.GetWindowMainCell(this.GetWindowElement(index));
            _aspxSetStyleSize(iFrame, cell.offsetWidth, cell.offsetHeight);
        }
    },
    
    ShowDragCursor: function(index){
        var dragElement = this.GetDragElement(index);
        if (dragElement)
            this.ShowTemporaryCursor(dragElement, "move");
    },
    HideDragCursor: function(index){
        var dragElement = this.GetDragElement(index);
        if(dragElement != null)
            this.HideTemporaryCursor(dragElement);
    },
    GetDragElement: function(index){
        var headerElement = this.GetWindowHeaderElement(index);
        var element = this.GetWindowElement(index);
        if (element != null)
            return (headerElement != null ? headerElement : this.GetWindowMainCell(element));
        return null;
    },
    
    OnActivateMouseDown: function(evt, index){
        this.OnActivate(index);
    },
    OnCloseButtonClick: function(index){
        this.RaiseCloseButtonClick(index);
        if(this.closeAction != "None")
            this.DoHideWindow(index);
    },
    OnMouseDown: function(evt, index, isDraggingAllowed){
        if(_aspxGetIsLeftButtonPressed(evt)){
            _aspxClearSelection();
            var isResizing = false;
            if (this.allowResize)
                isResizing = this.OnResizeStart(evt, index);
            if (isDraggingAllowed && !isResizing)
                this.OnDragStart(evt, index);

        }
    },
    OnMouseMove: function(evt, index){
        this.CreateResizeCursorInfo(evt, index);
    },
    
    StartAnimation: function(animationDivElement, index, horizontalPopupPosition, verticalPopupPosition){
        var element = this.GetWindowMainTable(animationDivElement);

        var clientX = horizontalPopupPosition.position;
        var clientY = verticalPopupPosition.position;
        
        var args = "(\"" + this.name + "\", " + index + ")";
        var onTimerString = "aspxPCATimer" + args;
        var onAnimStopCallString = "aspxPCAStop" + args;
        _aspxInitAnimationDiv(animationDivElement, clientX, clientY, onTimerString, onAnimStopCallString);
        
        var horizontalDirection = _aspxGetAnimationHorizontalDirection(horizontalPopupPosition, this.popupHorizontalAlign, this.popupVerticalAlign);
        var verticalDirection = _aspxGetAnimationVerticalDirection(verticalPopupPosition, this.popupHorizontalAlign, this.popupVerticalAlign);
        
        var xPos = horizontalDirection * animationDivElement.offsetHeight;
        var yPos = verticalDirection * animationDivElement.offsetWidth;
        
        _aspxSetStylePosition(element, xPos, yPos);
            
        _aspxSetElementVisibility(animationDivElement, true);
        this.DoShowWindowIFrame(index, clientX, clientY, 0, 0);

        animationDivElement.timerID = window.setTimeout(animationDivElement.onTimerString, this.animationDelay);
    },
    GetWindowsState: function(){
        var state = "";
        if (this.HasDefaultWindow()){
            state += this.GetWindowState(-1);
        }
        for(var i = 0; i < this.GetWindowCountCore(); i ++) {
            state += this.GetWindowState(i);
            if(i < this.GetWindowCountCore() - 1) state += ";";
        }
        return state;
    },
    GetWindowState: function(index){
        var element = this.GetWindowElement(index);
        if (element != null){
            var mainCell = this.GetWindowMainCell(element);
            var visibleFlag = (!this.InternalIsWindowVisible(index) || element.isHiding) ? "0" : "1";
            var isDraggedFlag = this.GetIsDragged(index) ? "1" : "0";
            var zIndex = this.GetCurrentZIndex(index);
            var isResized = this.GetIsResized(index);
            var isResizedFlag = isResized ? "1" : "0";
            var width = isResized ? this.GetCurrentWindowWidth(index) : 0;
            var height = isResized ? this.GetCurrentWindowHeight(index) : 0;
            var state = visibleFlag + ":" + isDraggedFlag + ":" + zIndex + ":" + 
                this.GetCurrentLeft(index) + ":" + this.GetCurrentTop(index) + ":" + isResizedFlag + ":" +
                width + ":" + height;
            return state;
        }
        return "";
    },
    UpdateWindowsStateCookie: function(){
        if(this.cookieName == "") return;
        
        _aspxDelCookie(this.cookieName);
        _aspxSetCookie(this.cookieName, this.GetWindowsState());
    },
    UpdateWindowsStateInputElement: function(){
        var element = this.GetWindowsStateInputElement();
        if(element != null) element.value = this.GetWindowsState();
    },
    // API
    CreateWindows: function(windowsNames){
        for (var i = 0; i < windowsNames.length; i ++){
            var window = new ASPxClientPopupWindow(this, i, windowsNames[i]);
            _aspxArrayPush(this.windows, window);
        }
    },
    RaiseCloseButtonClick: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.CloseButtonClick.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.CloseButtonClick.FireEvent(this, args);
        }
    },
    RaiseClosing: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        var cancel = false;
        if(!this.Closing.IsEmpty()){
            var args = new ASPxClientPopupWindowCancelEventArgs(false, window);
            this.Closing.FireEvent(this, args);
            cancel = args.cancel;
        }
        return cancel;
    },
    RaiseCloseUp: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.CloseUp.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.CloseUp.FireEvent(this, args);
        }
    },
    RaisePopUp: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.PopUp.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.PopUp.FireEvent(this, args);
        }
    },
    RaiseResize: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.Resize.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.Resize.FireEvent(this, args);
        }
    },
    RaiseBeforeResizing: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.BeforeResizing.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.BeforeResizing.FireEvent(this, args);
        }
    },
    RaiseAfterResizing: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.AfterResizing.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.AfterResizing.FireEvent(this, args);
        }
    },
    RaiseShowen: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.Shown.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.Shown.FireEvent(this, args);
        }
    },
    GetHeight: function(){
        return this.GetWindowHeight(null);
    },
    GetWidth: function(){
        return this.GetWindowWidth(null);
    },
    SetSize: function(width, height){
        this.SetWindowSize(null, width, height);
    },
    GetWindowHeight: function(window){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        return mainCell.offsetHeight;
    },
    GetWindowWidth: function(window){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        return mainCell.offsetWidth;
    },
    SetWindowSize: function(window, width, height){
        var index = (window != null) ? window.index : -1;
        if(this.InternalIsWindowDisplayed(index)) {
            this.SetClientWindowSize(index, width, height);
            var iFrame = this.GetWindowIFrame(index);
            if(_aspxIsExists(iFrame))
                _aspxSetStyleSize(iFrame, width, height);
        } else
            this.SetWindowCachedSize(index, width, height);
    },
    IsVisible: function(){
        return this.InternalIsWindowVisible(-1);
    },
    GetContentHTML: function(){
        return this.GetContentHtml();
    },
    SetContentHTML: function(html){
        this.SetContentHtml(html);
    },
    GetContentHtml: function(){
        return this.GetWindowContentHtml(null);
    },
    SetContentHtml: function(html){
        this.SetWindowContentHtml(null, html);
    },
    GetContentIFrame: function(window){
        return this.GetWindowContentIFrame(null);
    },
    GetContentUrl: function(){
        return this.GetWindowContentUrl(null);
    },
    SetContentUrl: function(url){
        this.SetWindowContentUrl(null, url);
    },
    RefreshContentUrl: function(){
        this.RefreshWindowContentUrl(null);
    },
    Show: function(){
        this.ShowWindow(null);
    },
    ShowAtElement: function(htmlElement){
        this.ShowWindowAtElement(null, htmlElement);
    },
    ShowAtElementByID: function(id){
        var htmlElement = document.getElementById(id);
        this.ShowWindowAtElement(null, htmlElement);
    },
    ShowAtPos: function(x, y){
        this.ShowWindowAtPos(null, Math.round(x), Math.round(y));
    },
    BringToFront: function(){
        this.BringWindowToFront(null);
    },
    Hide: function(){
        this.HideWindow(null);
    },
    IsWindowVisible: function(window){
        var index = (window != null) ? window.index : -1;
        return this.InternalIsWindowVisible(index);
    },
    GetWindow: function(index){
        return (0 <= index && index < this.windows.length) ? this.windows[index] : null;
    },
    GetWindowByName: function(name){
        for(var i = 0; i < this.windows.length; i ++)
            if(this.windows[i].name == name) return this.windows[i];
        return null;
    },
    GetWindowCount: function(){
        return this.GetWindowCountCore();
    },
    ShowWindow: function(window){
        var index = (window != null) ? window.index : -1;
        this.DoShowWindowAtPos(index, __aspxInvalidPosition, __aspxInvalidPosition, false, false, true);
    },
    ShowWindowAtElement: function(window, htmlElement){
        var index = (window != null) ? window.index : -1;
        var popupElementBackup = this.GetPopupElement(index);
        this.SetPopupElementInternal(index, htmlElement);
        this.ShowWindow(window);
        this.SetPopupElementInternal(index, popupElementBackup);
    },
    ShowWindowAtElementByID: function(window, id){
        var htmlElement = document.getElementById(id);
        this.ShowWindowAtElement(window, htmlElement);
    },
    ShowWindowAtPos: function(window, x, y){
        var index = (window != null) ? window.index : -1;
        this.DoShowWindowAtPos(index, x, y, true, false, true);
    },
    BringWindowToFront: function(window){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowElement(index); 
        aspxGetPopupControlCollection().ActivateWindowElement(element);
    },
    HideWindow: function(window){
        var index = (window != null) ? window.index : -1;
        this.DoHideWindow(index);
    },
    GetWindowContentHTML: function(window){
        return this.GetWindowContentHtml(window);
    },
    SetWindowContentHTML: function(window, html){
        this.SetWindowContentHtml(window, html);
    },
    GetWindowContentHtml: function(window){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowContentElement(index);
        return (element != null) ? element.innerHTML : "";
    },
    SetWindowContentHtml: function(window, html){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowContentElement(index);
        if(element != null){
            _aspxSetInnerHtml(element, html);
            this.ResizeWindowIFrame(index);
        }
    },
    GetWindowContentIFrame: function(window){
        var index = (window != null) ? window.index : -1;
        return this.GetWindowContentIFrameElement(index);
    },
    GetWindowContentUrl: function(window){
        var index = (window != null) ? window.index : -1;
        if(!this.IsWindowVisible(window))
            return this.GetWindowContentIFrameUrl(index);
        var element = this.GetWindowContentIFrameElement(index);
        return (element != null) ? element.src : "";
    },
    SetWindowContentUrl: function(window, url){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowContentIFrameElement(index);
        var windowVisible = this.IsWindowVisible(window);
        if(windowVisible && element != null)
            this.ShowIframeElementAfterDragging(index);
        this.SetWindowContentIFrameUrl(index, url);
        var src = (__aspxIE && !windowVisible) ? this.SSLSecureBlankUrl : url;
        if (element == null)
            this.CreateWindowContentIFrameElement(index, src);
        else
            this.SetSrcToIframeElement(element, src);
    },
    RefreshWindowContentUrl: function(window){
        var index = (window != null) ? window.index : -1;
        var iframe = this.GetWindowContentIFrameElement(index);
        if(_aspxIsExists(iframe))
            iframe.contentWindow.location.reload();
    },
    UpdatePosition: function(){
        this.UpdatePositionAtElement(this.GetPopupElement(-1));
    },
    UpdatePositionAtElement: function(popupElement){
        this.UpdateWindowPositionAtElement(null, popupElement);
    },
    UpdateWindowPosition: function(window){
        var index = (window != null) ? window.index : -1;
        this.UpdateWindowPositionAtElement(window, this.GetPopupElement(index));
    },
    UpdateWindowPositionAtElement: function(window, popupElement){
        var index = (window != null) ? window.index : -1;
        this.UpdateWindowPositionInternal(index, popupElement);
    },
    
    UpdateWindowPositionInternal: function(index, popupElement){
        var element = this.GetWindowElement(index);
        if(this.InternalIsWindowVisible(index) && element != null){
            var horizontalPopupPosition = this.GetClientPopupPos(element, popupElement, __aspxInvalidPosition, true, false);
            var verticalPopupPosition = this.GetClientPopupPos(element, popupElement, __aspxInvalidPosition, false, false);
            this.SetWindowPos(index, element, horizontalPopupPosition.position, verticalPopupPosition.position);
        } else
            this.DoShowWindowAtPos(index, __aspxInvalidDimension, __aspxInvalidDimension, false, false, false);
        
    },
    TryAutoUpdatePosition: function(){
        if(this.autoUpdatePosition) 
            this.UpdatePosition();   
    },
    CreateWindowContentIFrameElement: function(index, src){
        var content = this.GetWindowContentElement(index);
        var iframeParent = content;
        content.innerHTML = "";

        var iframe = this.CreateContentIFrameElement(index, src);
        var iframeDiv = null;
        if(!__aspxIE){
            iframeDiv = this.CreateContentIFrameDivElement(index);
            content.appendChild(iframeDiv);
            iframeParent = iframeDiv;
        }
        iframeParent.appendChild(iframe);
        if(!__aspxIE){
            if(__aspxOpera)
                iframe.style.height = "100%";
            else
                iframe.style.height = iframeDiv.clientHeight + "px";
        }
        return iframe;
    },
    CreateContentIFrameElement: function(index, src){
        var iframe = document.createElement("IFRAME");
        iframe.id = this.GetWindowContentIFrameElementId(index);
        iframe.scrolling = "auto";
        iframe.frameBorder = 0;
        iframe.style.width = "100%";
        iframe.style.height = __aspxIE ? "100%" : "0px";
        this.SetSrcToIframeElement(iframe, src);
        return iframe;
    },
    CreateContentIFrameDivElement: function(index){
        var iframeDiv = document.createElement("DIV");
        iframeDiv.id = this.GetWindowContentIFrameDivElementID(index);
        iframeDiv.style.width = "100%";
        iframeDiv.style.height = "100%";
        return iframeDiv;
    },
    GetWindowHeaderTextCell: function(index){
        return this.GetWindowChild(index, "_PWH" + index + "T");
    },
    GetWindowHeaderImageCell: function(index){
        return this.GetWindowChild(index, "_PWH" + index + "I");
    },
    GetWindowFooterTextCell: function(index){
        return this.GetWindowChild(index, "_PWF" + index + "T");
    },
    GetWindowFooterImageCell: function(index){
        return this.GetWindowChild(index, "_PWF" + index + "I");
    },
    GetWindowHeaderImageUrl: function(index){
        var element = this.GetWindowHeaderImageCell(index);
        if(element != null){
            var img = _aspxGetChildByTagName(element, "IMG", 0);
            if(img != null)
                return img.src;
        }
        return "";
    },
    SetWindowHeaderImageUrl: function(index, url){
        var element = this.GetWindowHeaderImageCell(index);
        if(element != null){
            var img = _aspxGetChildByTagName(element, "IMG", 0);
            if(img != null)
                img.src = url;
        }
    },
    GetWindowFooterImageUrl: function(index){
        var element = this.GetWindowFooterImageCell(index);
        if(element != null){
            var img = _aspxGetChildByTagName(element, "IMG", 0);
            if(img != null)
                return img.src;
        }
        return "";
    },
    SetWindowFooterImageUrl: function(index, url){
        var element = this.GetWindowFooterImageCell(index);
        if(element != null){
            var img = _aspxGetChildByTagName(element, "IMG", 0);
            if(img != null)
                img.src = url;
        }
    },
    GetWindowHeaderNavigateUrl: function(index){
        var element = this.GetWindowHeaderTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.href;
        }
        element = this.GetWindowHeaderImageCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.href;
        }
        return "";
    },
    SetWindowHeaderNavigateUrl: function(index, url){
        var element = this.GetWindowHeaderTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.href = url;
        }
        var element = this.GetWindowHeaderImageCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.href = url;
        }
    },
    GetWindowFooterNavigateUrl: function(index){
        var element = this.GetWindowFooterTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.href;
        }
        element = this.GetWindowFooterImageCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.href;
        }
        return "";
    },
    SetWindowFooterNavigateUrl: function(index, url){
        var element = this.GetWindowFooterTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.href = url;
        }
        var element = this.GetWindowFooterImageCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.href = url;
        }
    },
    GetWindowHeaderText: function(index){
        var element = this.GetWindowHeaderTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.innerHTML;
            else
                return element.innerHTML;
        }
        return "";
    },
    SetWindowHeaderText: function(index, text){
        var element = this.GetWindowHeaderTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.innerHTML = text;
            else
                element.innerHTML = text;
        }
    },
    GetWindowFooterText: function(index){
        var element = this.GetWindowFooterTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.innerHTML;
            else
                return element.innerHTML;
        }
        return "";
    },
    SetWindowFooterText: function(index, text){
        var element = this.GetWindowFooterTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.innerHTML = text;
            else
                element.innerHTML = text;
        }
    },
    GetHeaderImageUrl: function(){
        return this.GetWindowHeaderImageUrl(-1);
    },
    SetHeaderImageUrl: function(value){
        this.SetWindowHeaderImageUrl(-1, value);
    },
    GetFooterImageUrl: function(){
        return this.GetWindowFooterImageUrl(-1);
    },
    SetFooterImageUrl: function(value){
        this.SetWindowFooterImageUrl(-1, value);
    },
    GetHeaderNavigateUrl: function(){
        return this.GetWindowHeaderNavigateUrl(-1);
    },
    SetHeaderNavigateUrl: function(value){
        this.SetWindowHeaderNavigateUrl(-1, value);
    },
    GetFooterNavigateUrl: function(){
        return this.GetWindowFooterNavigateUrl(-1);
    },
    SetFooterNavigateUrl: function(value){
        this.SetWindowFooterNavigateUrl(-1, value);
    },
    GetHeaderText: function(){
        return this.GetWindowHeaderText(-1);
    },
    SetHeaderText: function(value){
        this.SetWindowHeaderText(-1, value);
    },
    GetFooterText: function(){
        return this.GetWindowFooterText(-1);
    },
    SetFooterText: function(value){
        this.SetWindowFooterText(-1, value);
    },

    GetVisible: function(){
        return this.IsVisible();
    },
    SetVisible: function(visible){
        if(visible && !this.IsVisible())
            this.Show();
        else if(!visible && this.IsVisible())
            this.Hide();
    }
});
ASPxClientPopupControl.GetPopupControlCollection = function(){
    return aspxGetPopupControlCollection();
}
ASPxClientPopupControlCollection = _aspxCreateClass(ASPxClientControlCollection, {
    constructor: function(){
        this.constructor.prototype.constructor.call(this);
        
        this.draggingControl = null;
        this.draggingWindowIndex = -1;
        this.gragXOffset = 0;
        this.gragYOffset = 0;
        this.visibleModalElements = new Array();
        this.visiblePopupWindowIds = new Array();
        this.zIndex = __aspxPopupControlZIndex;
        
        this.overControl = null;
        this.overWindowIndex = -1;
        this.overXPos = __aspxInvalidPosition;
        this.overYPos = __aspxInvalidPosition;
        this.appearTimerID = -1;
        this.disappearTimerID = -1;
        
        this.resizeControl = null;
        this.resizeIndex = -2;
        this.resizeCursor = "";
        this.resizePanel = null;
        
        this.selectBanned = false;
        
        this.SaveScrollState();
    },
    GetPopupWindowFromID: function(id){
        var pos = id.lastIndexOf(__aspxPCWIdSuffix);
        var name = id.substring(0, pos);
        var index = id.substr(pos + __aspxPCWIdSuffix.length);
        var popupControl = aspxGetPopupControlCollection().Get(name);
        return new _aspxPopupWindow(popupControl, index);
    },

    DoHideAllWindows: function(srcElement, excptId, applyToAll){
        for(var i = this.visiblePopupWindowIds.length - 1; i >= 0 ; i --){
            var id = this.visiblePopupWindowIds[i];

            if(id == excptId) continue;
            if(srcElement != null && _aspxGetParentById(srcElement, id) != null) continue;

            var popupWindow = this.GetPopupWindowFromID(id);
            if(popupWindow.popupControl != null && (
             (popupWindow.popupControl.closeAction != "CloseButton" && popupWindow.popupControl.closeAction != "None") || applyToAll)){
                popupWindow.popupControl.DoHideWindow(parseInt(popupWindow.windowIndex));
            }
        }
    },
    DoShowAtCurrentPos: function(name, index){
        var pc = this.Get(name);
        if(pc != null && !pc.InternalIsWindowVisible(index))
            pc.DoShowWindowAtPos(index, this.overXPos, this.overYPos, false, true, true);
    },
    
    ActivateWindowElement: function(element){
        var visibleWindowsCount = this.visiblePopupWindowIds.length;
        if (__aspxPopupControlZIndex <= element.style.zIndex && element.style.zIndex != visibleWindowsCount * 2 + __aspxPopupControlZIndex){
            this.DeleteWindowFromZIndexOrder(element);
        }
        this.SetWindowElementZIndex(element, __aspxPopupControlZIndex + visibleWindowsCount * 2);
    },
    DeleteWindowFromZIndexOrder: function(element){
        for(var i = this.visiblePopupWindowIds.length - 1; i >= 0 ; i--){
            var windowElement = _aspxGetElementById(this.visiblePopupWindowIds[i]);
            if(!_aspxIsExists(windowElement))
                _aspxArrayRemoveAt(this.visiblePopupWindowIds, i);
            else if (windowElement.style.zIndex > element.style.zIndex) 
                this.SetWindowElementZIndex(windowElement, windowElement.style.zIndex - 2);
        }
    },
    SetWindowElementZIndex: function(element, zIndex){
        element.style.zIndex = zIndex;
        var iFrame = element.overflowElement;
        if(_aspxIsExists(iFrame))
            iFrame.style.zIndex = zIndex - 1;
        var modalElement = element.modalElement;
        if(_aspxIsExists(modalElement))
            modalElement.style.zIndex = zIndex - 1;
        this.UpdateWindowsStateInputElement(element.id);
        this.UpdateWindowsStateCookie(element.id);
    }, 
    AdjustModalElementsBounds: function(){
        for(var i = 0; i < this.visibleModalElements.length; i++)
            this.AdjustModalElementBounds(this.visibleModalElements[i]);
    },
    AdjustModalElementBounds: function(element){
        if(!_aspxIsExistsElement(element)) return;
        var x = _aspxPrepareClientPosForElement(0, element, true);
        var y = _aspxPrepareClientPosForElement(0, element, false);
        _aspxSetStylePosition(element, x, y);
        if(__aspxNS) _aspxSetStyleSize(element, 1, 1);
        _aspxSetStyleSize(element, _aspxGetDocumentWidth(), _aspxGetDocumentHeight());
    },
    ClearAppearTimer: function(){
        this.appearTimerID = _aspxClearTimer(this.appearTimerID);
    },
    ClearDisappearTimer: function(){
        this.disappearTimerID = _aspxClearTimer(this.disappearTimerID);    
    },
    IsAppearTimerActive: function(){
        return this.appearTimerID > -1;
    },
    IsDisappearTimerActive: function(){
        return this.disappearTimerID > -1;
    },
    SetAppearTimer: function(name, index, timeout){
        this.appearTimerID = _aspxSetTimeout("aspxPEMOverTimer(\"" + name + "\", " + index + ")", timeout);
    },
    SetDisappearTimer: function(name, index, timeout){
        this.disappearTimerID = _aspxSetTimeout("aspxPWDisappearTimer(\"" + name + "\", " + index + ")", timeout);
    },
    GetDocScrollDifference: function(){
        return new _aspxScrollDifference(_aspxGetDocumentScrollLeft() - this.docScrollLeft, _aspxGetDocumentScrollTop() - this.docScrollTop);
    },
    IsDocScrolled: function(scroll){
        return scroll.horizontal != 0 || scroll.vertical != 0;
    },
    SaveScrollState: function(){
        this.docScrollLeft = _aspxGetDocumentScrollLeft();
        this.docScrollTop = _aspxGetDocumentScrollTop();
    },
    
    InitDragObject: function(control, index, x, y, xClientCorrection, yClientCorrection){
        this.draggingControl = control;
        this.draggingWindowIndex = index;
        this.gragXOffset = x;
        this.gragYOffset = y;
        this.xClientCorrection = xClientCorrection;
        this.yClientCorrection = yClientCorrection;
        this.selectBanned = true;
    },
    InitOverObject:  function(control, index, evt){
        this.overControl = control;
        this.overWindowIndex = index;
        this.SaveCurrentMouseOverPos(evt);    
    },
    InitResizeObject:  function(control, index, cursor, resizePanel){
        this.resizeControl = control;
        this.resizeIndex = index;
        this.resizeCursor = cursor;
        this.resizePanel = resizePanel;
        this.selectBanned = true;
    },
    IsResizeInint : function(){
        return this.resizeControl != null;
    },
    ClearDragObject: function(){
        this.draggingControl = null;
        this.draggingWindowIndex = -1;
        this.gragXOffset = 0;
        this.gragYOffset = 0;
        this.selectBanned = this.resizeControl != null;
    },
    ClearResizeObject: function(){
        this.resizeControl = null;
        this.resizeIndex = -2;
        this.resizeCursor = "";
        this.selectBanned = this.draggingControl != null;
        this.resizePanel.parentNode.removeChild(this.resizePanel);
    },
    Drag: function(evt){
        var x = _aspxGetEventX(evt) + this.gragXOffset;
        var y = _aspxGetEventY(evt) + this.gragYOffset;
        this.draggingControl.OnDrag(this.draggingWindowIndex, x, y, this.xClientCorrection, this.yClientCorrection);
    },
    DragStop: function(){
        this.draggingControl.OnDragStop(this.draggingWindowIndex);
        this.ClearDragObject();
    },
    ResizeStop: function(evt){
        this.resizeControl.OnResizeStop(evt, this.resizeIndex, this.resizeCursor, this.resizePanel);
        aspxGetPopupControlCollection().ClearResizeObject();
    },
    
    OnPWMouseMove: function(evt, name, index){
        if (this.draggingControl == null && 
            this.overControl == null && 
            this.resizeControl == null){
            var pc = aspxGetPopupControlCollection().Get(name);
            if(pc != null) pc.OnMouseMove(evt, index);
        }
    },
    OnPWMouseOver: function(evt){
        if (!_aspxIsExists(this.overControl) || _aspxIsExists(this.draggingControl)) return;
        if(this.IsOverPopupWindow(evt))
            this.ClearDisappearTimer();
    },
    IsOverPopupWindow: function(evt){
        return _aspxFindEventSourceParentByTestFunc(evt, aspxTestOverPopupWindowElement) != null;
    },
    
    OnDocumentMouseDown: function(evt){
        var popupElement = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupControlElement);
        var excptId = popupElement == null ? "" :
            popupElement.DXPopupControl.GetWindowElementId(popupElement.DXPopupWindowIndex);
        this.OnMouseDownCore(evt, excptId);
    },
    OnMouseDown: function(evt){
        this.OnMouseDownCore(evt, "");
    },
    OnMouseDownCore: function(evt, excptId){
        if(this.IsDocumentIsCoveredByModalElement())
            return;
        var srcElement = _aspxGetEventSource(evt);
        this.DoHideAllWindows(srcElement, excptId, false);
        aspxGetPopupControlCollection().ClearAppearTimer();
    },
    OnMouseMove: function(evt){
        if(this.draggingControl != null){
            if(__aspxIE && !_aspxGetIsLeftButtonPressed(evt)) 
                return this.DragStop();
            else
                this.Drag(evt);
        }
        else if(this.overControl != null){
            this.OnMouseOver(evt);
        }
        else if(this.resizeControl != null){
            if(__aspxIE && !_aspxGetIsLeftButtonPressed(evt)) 
                this.ResizeStop(evt);
            else
                this.resizeControl.OnResize(evt, this.resizeIndex, this.resizeCursor, this.resizePanel);
        }
    },
    OnMouseOver: function(evt){
        var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupControlOverElement);
        if (element != null){
            this.ClearDisappearTimer();
            this.SaveCurrentMouseOverPos(evt);
            return _aspxCancelBubble(evt);
        }
        this.OnMouseOut();
    },
    OnMouseOut: function(){
        if (!_aspxIsExists(this.overControl) || _aspxIsExists(this.draggingControl)) return;
        this.ClearAppearTimer();
        if(this.overControl.closeAction == "MouseOut"  && this.overControl.InternalIsWindowVisible(this.overWindowIndex)){
            if (!this.IsDisappearTimerActive())
                this.SetDisappearTimer(this.overControl.name, this.overWindowIndex, this.overControl.disappearAfter);
        }
        else
            this.OverStop();
    },
    OnMouseUp: function(evt){
        if(this.draggingControl != null)        
            this.DragStop();
        if(this.resizeControl != null)        
            this.ResizeStop(evt);
    },
    OnResize: function(evt){
        this.AutoUpdateElementsPosition();
        this.AdjustModalElementsBounds();
    },
    OnScroll: function(evt){
        var scroll = this.GetDocScrollDifference();
        if(this.IsDocScrolled(scroll)){ // B33975
            this.CorrectPositionAtScroll(scroll);
            this.AdjustModalElementsBounds();
            this.SaveScrollState();
        }
    },
    CorrectPositionAtScroll: function(scroll){
        for(var i = 0; i < this.visiblePopupWindowIds.length; i++){
             var popupWindow = this.GetPopupWindowFromID(this.visiblePopupWindowIds[i]);
             var popupControl = popupWindow.popupControl;
             if(popupControl != null){
                 var isNeedFix = popupControl.IsFFTextCurFixRequired(popupWindow.windowIndex);
                 if(popupControl.autoUpdatePosition && !isNeedFix) 
                    popupWindow.popupControl.TryAutoUpdatePosition();   
                 else if(!popupControl.autoUpdatePosition && isNeedFix) // B131803
                    this.FFScrollEmulation(scroll, popupWindow);
             }
        } 
    },
    FFScrollEmulation: function(scroll, popupWindow){
        var windowElement = popupWindow.popupControl.GetWindowElement(popupWindow.windowIndex);
        windowElement.style.left = (windowElement.offsetLeft - scroll.horizontal) + "px";
        windowElement.style.top = (windowElement.offsetTop - scroll.vertical) + "px";
    },
    OnSelectStart: function(){
        return !this.selectBanned;
    },
    OverStop: function(){
        this.overControl = null;
        this.overWindowIndex = -1;
    },
    OnPWDisappearTimer: function(name, index){
        var pc = this.Get(name);
        if(pc != null){
            if(!pc.DoHideWindow(index))
                this.OverStop();        
            else
                this.ClearDisappearTimer();
        }
    },
    SaveCurrentMouseOverPos: function(evt){
        this.overXPos = _aspxGetEventX(evt);
        this.overYPos = _aspxGetEventY(evt);
    },
    RegisterVisibleModalElement: function(element){
        if(_aspxArrayIndexOf(this.visibleModalElements, element) == -1)
            _aspxArrayPush(this.visibleModalElements, element);
    },
    UnregisterVisibleModalElement: function(element){
        _aspxArrayRemove(this.visibleModalElements, element);
    },
    RegisterVisibleWindow: function(element){
        if(_aspxArrayIndexOf(this.visiblePopupWindowIds, element.id) == -1)
            _aspxArrayPush(this.visiblePopupWindowIds, element.id);
    },
    UnregisterVisibleWindow: function(element){
        this.DeleteWindowFromZIndexOrder(element);
        _aspxArrayRemove(this.visiblePopupWindowIds, element.id);
    },
    
    UpdateWindowsStateCookie: function(id){
        var pos = id.lastIndexOf(__aspxPCWIdSuffix);
        var name = id.substring(0, pos);
        var popupControl = aspxGetPopupControlCollection().Get(name);
        if(popupControl != null)
           popupControl.UpdateWindowsStateCookie(false);                
    },
    UpdateWindowsStateInputElement: function(id){
        var pos = id.lastIndexOf(__aspxPCWIdSuffix);
        var name = id.substring(0, pos);
        var popupControl = aspxGetPopupControlCollection().Get(name);
        if(popupControl != null)
           popupControl.UpdateWindowsStateInputElement(false);                
    },
    AutoUpdateElementsPosition: function() {
          for(var i = 0; i < this.visiblePopupWindowIds.length; i++){
                var popupWindow = this.GetPopupWindowFromID(this.visiblePopupWindowIds[i]);
                var popupControl = popupWindow.popupControl;
                if(popupControl != null && popupControl.InternalIsWindowVisible(popupWindow.windowIndex))
                    popupControl.TryAutoUpdatePosition();
          }
    },
    IsDocumentIsCoveredByModalElement: function() {
        for(var i = 0; i < this.visiblePopupWindowIds.length; i++){
                var popupWindow = this.GetPopupWindowFromID(this.visiblePopupWindowIds[i]);
                var popupControl = popupWindow.popupControl;
                if(popupControl != null && _aspxIsExists(popupControl.GetWindowModalElement(popupWindow.windowIndex)))
                    return true;
        }
        return false;
    },
    HideAllWindows: function(){
        this.DoHideAllWindows(null, "", true);
    }
});

var __aspxPopupControlCollection = null;
function aspxGetPopupControlCollection(){
    if(__aspxPopupControlCollection == null)
        __aspxPopupControlCollection  = new ASPxClientPopupControlCollection();
    return __aspxPopupControlCollection;
}
ASPxClientPopupWindow = _aspxCreateClass(null, {
    constructor: function(popupControl, index, name){
        this.popupControl = popupControl;
        this.index = index;
        this.name = name;
    },
    GetHeaderImageUrl: function(){
        return this.popupControl.GetWindowHeaderImageUrl(this.index);
    },
    SetHeaderImageUrl: function(value){
        this.popupControl.SetWindowHeaderImageUrl(this.index, value);
    },
    GetFooterImageUrl: function(){
        return this.popupControl.GetWindowFooterImageUrl(this.index);
    },
    SetFooterImageUrl: function(value){
        this.popupControl.SetWindowFooterImageUrl(this.index, value);
    },
    GetHeaderNavigateUrl: function(){
        return this.popupControl.GetWindowHeaderNavigateUrl(this.index);
    },
    SetHeaderNavigateUrl: function(value){
        this.popupControl.SetWindowHeaderNavigateUrl(this.index, value);
    },
    GetFooterNavigateUrl: function(){
        return this.popupControl.GetWindowFooterNavigateUrl(this.index);
    },
    SetFooterNavigateUrl: function(value){
        this.popupControl.SetWindowFooterNavigateUrl(this.index, value);
    },
    GetHeaderText: function(){
        return this.popupControl.GetWindowHeaderText(this.index);
    },
    SetHeaderText: function(value){
        this.popupControl.SetWindowHeaderText(this.index, value);
    },
    GetFooterText: function(){
        return this.popupControl.GetWindowFooterText(this.index);
    },
    SetFooterText: function(value){
        this.popupControl.SetWindowFooterText(this.index, value);
    }
});
ASPxClientPopupWindowEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
    constructor: function(processOnServer, window){
        this.constructor.prototype.constructor.call(this);
        this.window = window;
    }
});
ASPxClientPopupWindowCancelEventArgs = _aspxCreateClass(ASPxClientCancelEventArgs, {
    constructor: function(processOnServer, window){
        this.constructor.prototype.constructor.call(this, processOnServer);
        this.window = window;
    }
});

function _aspxPopupWindow(popupControl, windowIndex){
    this.popupControl = popupControl;
    this.windowIndex = windowIndex;
}
function _aspxScrollDifference(horizontal, vertical){
    this.horizontal = horizontal;
    this.vertical = vertical;
}

function aspxPEMOverTimer(name, index){
    aspxGetPopupControlCollection().DoShowAtCurrentPos(name, index);
}
function aspxPWDisappearTimer(name, index){
    aspxGetPopupControlCollection().OnPWDisappearTimer(name, index);
}

function aspxPWCBClick(name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) pc.OnCloseButtonClick(index);
}
function aspxPWCBMDown(evt){
    return _aspxCancelBubble(evt);
}
function aspxPEMOver(evt){
    var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupControlElement);
    if (element != null) {
        var popupControl = element.DXPopupControl;
        var index = element.DXPopupWindowIndex;
        if (!popupControl.InternalIsWindowVisible(index)){
            aspxGetPopupControlCollection().SetAppearTimer(popupControl.name, index, popupControl.appearAfter);
            aspxGetPopupControlCollection().InitOverObject(popupControl, index, evt);
        }
    }
}
function aspxPWEMOver(evt){
    aspxGetPopupControlCollection().OnPWMouseOver(evt);
}
function aspxPWMEMDown(evt){
    var element = _aspxGetEventSource(evt);
    if (element != null) // Prevent re-popup after ModalElement MouseDown + PopupElemen MouseUp
        element.DXModalPopupControl.OnMouseDownModalElement(evt, element.DXModalPopupWindowIndex);
}
function aspxPEMEvent(evt){
    var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupControlElement);
    if (element != null){
        if (evt.type == "mousedown"){
            if (element.DXPopupControl.InternalIsWindowVisible(element.DXPopupWindowIndex))
                element.isPopuped = true;
            else
                element.isPopuped = false;
            aspxGetPopupControlCollection().OnMouseDown(evt);                    
        }
        else{
            if (element.DXPopupControl.popupAction=="RightMouseClick" || _aspxGetIsLeftButtonPressed(evt)){
                if (element.DXPopupControl.popupAction=="RightMouseClick")
                    _aspxPreventContextMenu(evt);
                if (!(element.isPopuped && element.DXPopupControl.closeAction == "OuterMouseClick"))
                    element.DXPopupControl.DoShowWindow(element.DXPopupWindowIndex, evt);
                if (element.DXPopupControl.closeAction == "MouseOut")
                    aspxGetPopupControlCollection().InitOverObject(element.DXPopupControl, element.DXPopupWindowIndex, evt);
                return false;
            }
        }
    }
}
function aspxPWDGMDown(evt, name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) {
        pc.OnActivateMouseDown(evt, index);
        pc.OnMouseDown(evt, index, true);
    }
    if (!__aspxIE) // Prevent image dragging
        evt.preventDefault();
    return aspxPWCBMDown(evt);
}
function aspxPWGripMDown(evt, name, index){
    aspxPWMDown(evt, name, index, false);
    return aspxPWCBMDown(evt);
}
function aspxPWMDown(evt, name, index, isDraggingAllowed){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) {
        pc.OnActivateMouseDown(evt, index);
        pc.OnMouseDown(evt, index, isDraggingAllowed);    
    }
}
function aspxPWResize(name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) pc.ResizeWindowIFrame(index);
}
function aspxPWMMove(evt, name, index){
    aspxGetPopupControlCollection().OnPWMouseMove(evt, name, index);
}
function aspxPCATimer(name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) pc.OnAnimationTimer(index);
}
function aspxPCAStop(name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) pc.OnAnimationStop(index);
}


_aspxAttachEventToDocument("mousedown", aspxPopupControlDocumentMouseDown);
function aspxPopupControlDocumentMouseDown(evt){
    aspxGetPopupControlCollection().OnDocumentMouseDown(evt);
}
_aspxAttachEventToDocument("mouseup", aspxPopupControlDocumentMouseUp);
function aspxPopupControlDocumentMouseUp(evt){
    return aspxGetPopupControlCollection().OnMouseUp(evt);    
}
_aspxAttachEventToDocument("mousemove", aspxPopupControlDocumentMouseMove);
function aspxPopupControlDocumentMouseMove(evt){
    if(typeof(aspxGetPopupControlCollection) != "undefined")
        aspxGetPopupControlCollection().OnMouseMove(evt);    
}
_aspxAttachEventToDocument("mouseout", aspxPopupControlDocumentMouseOut);
function aspxPopupControlDocumentMouseOut(){
    if(typeof(aspxGetPopupControlCollection) != "undefined")
        aspxGetPopupControlCollection().OnMouseOut();    
}
_aspxAttachEventToElement(window, "resize", aspxPopupControlWindowResize);
function aspxPopupControlWindowResize(evt){
    aspxGetPopupControlCollection().OnResize(evt);    
}
_aspxAttachEventToElement(window, "scroll", aspxPopupControlWindowScroll);
function aspxPopupControlWindowScroll(evt){
    aspxGetPopupControlCollection().OnScroll(evt);    
}
_aspxAttachEventToDocument("selectstart", aspxPopupControlDocumentSelectStart);
function aspxPopupControlDocumentSelectStart(evt){
    var ret = aspxGetPopupControlCollection().OnSelectStart(evt);    
    if(!ret) return false; // B95132 returning true can affect another control handler result. So we have to return false/undefined
}
function aspxTestPopupControlElement(element){
    return (_aspxIsExists(element.DXPopupControl) && _aspxIsExists(element.DXPopupWindowIndex));
}
function aspxTestPopupControlOverElement(element){
    var collection = aspxGetPopupControlCollection();
    var windowId = collection.overControl.GetWindowElementId(collection.overWindowIndex);
    var popupElementId = collection.overControl.GetPopupElement(collection.overWindowIndex).id;
    return (element.id == windowId || element.id == popupElementId);
}
function aspxTestOverPopupWindowElement(element){
    var collection = aspxGetPopupControlCollection();
    var windowId = collection.overControl.GetWindowElementId(collection.overWindowIndex);
    var popupWindowElementId = collection.overControl.GetWindowElementId(collection.overWindowIndex);
    return (element.id == popupWindowElementId);
}

var __aspxTINonProcessingSymbols = ["^", "\\", "\'"];
var __aspxTIWildCards = ["*", "?"];

var __aspxTIGroupElementClassName = "dxg";
var __aspxTIItemElementClassName = "dxtxi";
var __aspxTITextElementClassName = "dxtxt";

var __aspxTIDefaultFilterIntervalDelay = 200;
ASPxClientTitleIndex = _aspxCreateClass(ASPxClientControl, {
	constructor: function(name){
		this.constructor.prototype.constructor.call(this, name);
		
		this.allowMultipleCallbacks = false;
	    this.autoFocus = false;
	    this.columnCount = 1;
	    this.filterDelay = 0;
	    this.rowCount = -1;
	    this.showBackToTop = false;
	    
	    this.groupSpacing = 0;
	    this.groupContentPaddingBottom = 0;
	    this.groupContentPaddingTop = 0;
	            
	    this.lastFilterMask = "";	    
	    this.pasteTimerID = -1;
	    this.filterTimerID = -1;
	    this.mainCellWidth = 0;
	    
	    this.columnElements = new Object();	    	    
	    this.groupElements = new Object();
	    this.itemElements = new Object();    
        this.ItemClick = new ASPxClientEvent();
        
        this.InitializeAutoComplete();
    },
    
    Initialize: function(){
        if (_aspxIsExists(this.GetFilterInputElement())) {
            this.CleanWhitespaceInControl();
                        
            if (this.filterDelay > __aspxTIDefaultFilterIntervalDelay)
                __aspxTIDefaultFilterIntervalDelay = this.filterDelay;
        }
        if (this.autoFocus && _aspxIsExists(this.GetFilterInputElement()) && 
                        _aspxIsFocusable(this.GetFilterInputElement()))
            this.GetFilterInputElement().focus();
            
        this.constructor.prototype.Initialize.call(this);
    },
    InitializeAutoComplete: function(){
        var element = this.GetFilterInputElement();
        if (_aspxIsExists(element)) element.autocomplete = "off";
    },
    
    GetCategoryHeaderElement: function(rowIndex){
        return this.GetChild("_CH" + rowIndex);
    },
    GetColumnElement: function(index, rowIndex){
        var columnId = (this.rowCount > 0) ? "_C" + index + "_" + rowIndex : "_C" + index;
        if(!_aspxIsExistsElement(this.columnElements[columnId]))
            this.columnElements[columnId] = this.GetChild(columnId);
        return this.columnElements[columnId];
    },
    GetContentTDWidth: function() {
        return _aspxGetParentByTagName(this.GetCategoryHeaderElement(0), 'td').clientWidth;        
    },
    GetEmptyResultCaptionElement: function() {
        return this.GetChild("_TI_E");
    },
    GetFilterInputElement: function() {
        return this.GetChild("_FI");
    },
    GetGroupElements: function(columnElement) {    
        if(!_aspxIsValidElements(this.groupElements[columnElement.id]))
            this.groupElements[columnElement.id] = _aspxGetChildsByClassName(columnElement, __aspxTIGroupElementClassName);
        return this.groupElements[columnElement.id];
    },
    GetItemText: function(nodeElement) {
        var textElem = this.GetItemTextElement(nodeElement);
        if (_aspxIsExists(textElem) && _aspxIsExists(textElem.nodeValue))
            return _aspxTrim(textElem.nodeValue);
        else        
            return "";
    },
    GetItemElements: function(groupElement) {
        var groupText = this.GetItemText(groupElement);
        if(!_aspxIsValidElements(this.itemElements[groupText]))
            this.itemElements[groupText] = _aspxGetChildsByClassName(groupElement, __aspxTIItemElementClassName);
        return this.itemElements[groupText];
    },
    GetItemTextElement: function(nodeElement){    
        var textElement = _aspxGetChildsByClassName(nodeElement, __aspxTITextElementClassName)[0];
        return _aspxIsExists(textElement) ? _aspxGetChildTextNode(textElement, 0) : null;
    },
    GetIndexPanelIndexInputElement: function(){
        return _aspxGetElementById(this.name + "PI");
    },
    GetContentCell: function(){
        return this.GetChild("_CCell");
    }, 
    GetTreeViewCell: function(){
        return this.GetChild("_ICell");
    },
    SetPrevFilterMask: function(filterMask) {
        if(!_aspxIsExists(this.lastFilterMask))
             this.lastFilterMask = "";
        this.lastFilterMask = filterMask;    
    },        
    // Timer
    SetFilterTimer: function(fi, timeout) {
        var str = "aspxSFilterTimer(\"" + this.name + "\")";
        if(timeout == 0)
            eval(str);
        else
            this.filterTimerID = _aspxSetTimeout(str, timeout);
    },
    SetPasteTimer: function() {
        var str = "aspxSPasteTimer(\"" + this.name + "\")";
        this.pasteTimerID = _aspxSetInterval(str, __aspxTIDefaultFilterIntervalDelay);
    },
    ClearFilterTimer: function() {
        this.filterTimerID = _aspxClearTimer(this.filterTimerID);
    },
    ClearPasteTimer: function() {
        this.pasteTimerID = _aspxClearInterval(this.pasteTimerID);
    },
    
    CleanWhitespaceInControl: function() {
        if (this.rowCount > 0)
            this.CleanWhitespace(_aspxGetParentByTagName(this.GetCategoryHeaderElement(0), "table"));
        else {
              for (var j = 0; j < this.columnCount; j ++)
                    this.CleanWhitespace(this.GetColumnElement(j, -1));
        }
    },
    CleanWhitespace: function(element) {
        if (element.hasChildNodes()) {            
            var i = 0;
            while (i < element.childNodes.length) {
                var node = element.childNodes[i];
                if(node.nodeType == 3 && !/\S/.test(node.nodeValue))
                    node.parentNode.removeChild(node);
                else{
                    i++;
                    if(node.nodeType != 3)
                        this.CleanWhitespace(node);
                }
             }
        }
    },
    CreateFilterRegEx: function(filterMask) {
        var regExString = "^";
        for (var i=0; i<filterMask.length; i++){
            var index = _aspxArrayIndexOf(__aspxTIWildCards, filterMask.charAt(i));
            if (index > -1){
                switch(index) {
                    case 0: regExString += ".*"; break; // * - wildCard
                    case 1: regExString += ".{1}"; break; // ? - wildCard
                }
            }
            else {
                var index = _aspxArrayIndexOf(__aspxTINonProcessingSymbols, filterMask.charAt(i));
                if (index == -1)
                    regExString += "[" + filterMask.charAt(i) + "]";
            }
        }
        regExString += ".*";
        return new RegExp(regExString, 'i'); // todo optional
    },    
    OnCallback: function(result) {
        var inputElement = this.GetIndexPanelIndexInputElement();
        if(inputElement != null) 
            inputElement.value = result.index;
        var element = this.GetContentCell();
        if(element != null) 
            _aspxSetInnerHtml(element, result.html);
    },
            
    IsAllowableKeyCode: function(keyCode) {
	    return (((keyCode >= 48) && (keyCode <= 57)) || 
	            ((keyCode >= 186) && (keyCode <= 192)) || 
	            ((keyCode >= 219) && (keyCode <= 226)) || 
	            ((keyCode >= 65)&&(keyCode <= 90)) ||
	            ((keyCode >= 65)&&(keyCode <= 90)) || 
	            ((keyCode >= 96)&&(keyCode <= 107)) || 
	            ((keyCode >= 109)&&(keyCode <= 111)) || 
	              keyCode == 8 || keyCode == 45 || keyCode == 46);
    },
    IsFirstCategoryTR: function(categoryElem) {
        var spacingElem = categoryElem.parentNode.previousSibling;
        return !_aspxIsExists(spacingElem);
    },
    IsFirstCategory: function(categoryElem, index) {
        var i = index - 1;
        while (i >= 0) {        
            if (_aspxGetElementDisplay(this.GetCategoryHeaderElement(i).parentNode))
                return false;
            i--;
        }
        return true;
    },
    IsFirstGroupInColumn: function(groupIndex, columnElem) {
        var groupElements = this.GetGroupElements(columnElem);        
        var i = groupIndex - 1;
                        
        while (i >= 0) {
            if (_aspxGetElementDisplay(groupElements[i]))
                return false;
            i--;
        }
        return true;    
    },    
    IsFilterTimerActive: function() {
        return this.filterTimerID > -1;
    },
    IsFilterMaskChanged: function(filterMask) {
        if(!_aspxIsExists(this.lastFilterMask))
            this.lastFilterMask = "";
         return this.lastFilterMask.toUpperCase() != filterMask.toUpperCase();
    },
    CorrectCategorySpacing: function(categoryElem, index) {
        var headerTR = categoryElem.parentNode;        
        if (!this.IsFirstCategoryTR(categoryElem) && 
            (this.groupSpacing != 0) &&  this.IsFirstCategory(categoryElem, index))            
            _aspxSetElementDisplay(headerTR.previousSibling, false);
    },
    CorrectNodesPaddings: function(columnIndex, rowIndex) {
        var columnElem = this.GetColumnElement(columnIndex, rowIndex);
        var groupElements = this.GetGroupElements(columnElem);        
                       
        for (var i = 0; i < groupElements.length; i ++) {
            if (_aspxGetElementDisplay(groupElements[i])) {                    
                if (this.IsFirstGroupInColumn(i, columnElem)) // first group
                    _aspxChangeStyleAttribute(groupElements[i], "paddingTop", 0);
                else 
                    _aspxRestoreStyleAttribute(groupElements[i], "paddingTop");
                this.CorrectGroupContentPadding(groupElements[i]);
            }
        }
    },
    CorrectGroupContentPadding: function(groupElement) {
        var itemElements = this.GetItemElements(groupElement);        
        
        for (var i = 0; i < itemElements.length; i++) {
            if (_aspxGetElementDisplay(itemElements[i])) {
                if (i == 0)  // First Item
                    _aspxChangeStyleAttribute(itemElements[i], "paddingTop", 0);
                else 
                    _aspxRestoreStyleAttribute(itemElements[i], "paddingTop");
            }
        }
    },
    DoIndexPanelItemClick: function(value) {
        var inputElement = this.GetIndexPanelIndexInputElement();
        if(inputElement != null) {
            if (_aspxIsExists(this.GetFilterInputElement()))
                this.GetFilterInputElement().disabled = true;
            this.CreateCallback(value + __aspxCallbackSeparator + value);
        }
    },
    DoBeginCallback: function(command){
        this.CreateLoadingPanelWithAbsolutePosition(this.GetTreeViewCell());
        ASPxClientControl.prototype.DoBeginCallback.call(this, command);
    },
    OnControlClick: function(clickedElement, htmlEvent) {
        var itemElement = _aspxGetParentByClassName(clickedElement, __aspxItemClassName);        
        if(_aspxIsExists(itemElement)) {
            var processOnServer = this.RaiseItemClick(itemElement, htmlEvent);     
                   
            var hasItemLink = this.GetLinkElement(itemElement) != null;
            if(processOnServer && !hasItemLink) {
                var name = this.GetItemElementName(itemElement);
                this.SendPostBack("CLICK:" + name);
            }
        }
    },
    RaiseItemClick: function(itemElement, htmlEvent){
        var processOnServer = this.autoPostBack || this.IsServerEventAssigned("ItemClick");
        if(!this.ItemClick.IsEmpty()){
            var name = this.GetItemElementName(itemElement);
            var args = new ASPxClientTitleIndexItemEventArgs(processOnServer, name, itemElement, htmlEvent);
            this.ItemClick.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    },
    DoFilter: function (filterMask){
        filterMask = _aspxTrim(filterMask);
                
        if(this.IsFilterMaskChanged(filterMask)){                       
            this.SetPrevFilterMask(filterMask);            
            var filterRegEx = this.CreateFilterRegEx(filterMask);
            var isData = false;
            
            if (this.rowCount > 0) { // Categorized = true;
                var categoryCount = 0;
                
                if (this.GetContentTDWidth() != 0)
                    this.mainCellWidth = this.GetContentTDWidth();
                    
                for(var i = 0; i < this.rowCount; i ++) {
                    var categoryElem = this.GetCategoryHeaderElement(i);                    
	                // Columns
		            var visibleColCount = 0;
                    for(var j = 0; j < this.columnCount; j ++) {
                         var visibleItemCount = this.FilterColumnInCategory(j, i, filterMask, filterRegEx);
                         if (visibleItemCount != 0)
                             visibleColCount ++;
                     }
                     if (visibleColCount != 0) {                        
                         this.ShowCategory(categoryElem);
                         this.CorrectCategorySpacing(categoryElem, i);
                                                  
		                 categoryCount ++;
                     }
                     else
                         this.HideCategory(categoryElem);
                }
                isData = categoryCount != 0;
            }
            else { // Categorized = false;
                var visibleColCount = 0;
                for (var i = 0; i < this.columnCount; i ++) {
                    var visibleCategoryNodeCount = this.FilterColumn(i, -1, filterMask, filterRegEx);
                    this.CorrectNodesPaddings(i, -1);
                                    
                    if (visibleCategoryNodeCount != 0)
                        visibleColCount ++;
                }
                isData = visibleColCount != 0;
            }
            // NoDataPanel
            if(isData)
                this.HideEmptyResultCaption();
            else
                this.ShowEmptyResultCaption();            
        }
    },
    DoFilterInternal: function() {
        this.DoFilter(this.GetFilterInputElement().value);
    },
    FilterColumn: function(columnIndex, rowIndex, filterMask, filterRegEx) {
        var columnElem = this.GetColumnElement(columnIndex, rowIndex);
        
        var groupElements = this.GetGroupElements(columnElem);        
        var visibleGroupCount = 0;
        
        // Category Node
        for(var i = 0; i < groupElements.length; i ++) {
            // Items
            visibleItemsCount = this.FilterItems(groupElements[i], filterRegEx);
            if(visibleItemsCount > 0) {
                visibleGroupCount ++;
                this.ShowGroup(groupElements[i]);
            }
            else
                this.HideGroup(groupElements[i]);
        }
        // Column
        if(visibleGroupCount != 0) {
            _aspxSetElementVisibility(columnElem, true);
            this.SetColumnSeparatorDisplay(columnElem, true, columnIndex, rowIndex);            
        }
        else {
            _aspxSetElementVisibility(columnElem, false);
            this.SetColumnSeparatorDisplay(columnElem, false, columnIndex, rowIndex);
        }
        return visibleGroupCount;
    },
    FilterColumnInCategory: function(columnIndex, rowIndex, filterMask, filterRegEx) {
        var columnElem = this.GetColumnElement(columnIndex, rowIndex);
        var visibleItemCount = 0;
                                
        if (_aspxIsExists(columnElem)) {
            var itemElements = this.GetItemElements(columnElem);
                    
            for (var i = 0; i < itemElements.length; i++) {
                var itemText = this.GetItemText(itemElements[i]);
                if (!filterRegEx.test(itemText))
                    _aspxSetElementDisplay(itemElements[i], false);
                else {
                    _aspxSetElementDisplay(itemElements[i], true);
                    visibleItemCount ++;
                }
            }
            
            if(visibleItemCount != 0) {
                this.SetColumnSeparatorDisplay(columnElem, true, columnIndex, rowIndex);
            }
            else {
                this.SetColumnSeparatorDisplay(columnElem, false, columnIndex, rowIndex);
            }
        }
        return visibleItemCount;
    },
    FilterItems: function(parentNodeElem, filterRegEx) {
        var itemElements = this.GetItemElements(parentNodeElem);        
        var visibleNodeCount = 0;
        
        for (var i = 0; i < itemElements.length; i++) {
            var itemText = this.GetItemText(itemElements[i]);
            if(filterRegEx.test(itemText)) {
                _aspxSetElementDisplay(itemElements[i], true);
                visibleNodeCount ++;
            }
            else
                _aspxSetElementDisplay(itemElements[i], false);
        }
        return visibleNodeCount;
    },
    ShowCategory: function(categoryElement) {
        var headerTR = categoryElement.parentNode;    
        _aspxSetElementDisplay(headerTR, true);
        // GroupSpacing
        if ((this.groupSpacing != 0) && !this.IsFirstCategoryTR(categoryElement)) 
            _aspxSetElementDisplay(headerTR.previousSibling, true);

        var categoryContentElem = null;
        if (this.groupContentPaddingTop == 0) {// GroupContentPadding.PaddingTop == 0
            categoryContentElem = headerTR.nextSibling;
            _aspxSetElementDisplay(headerTR.nextSibling, true);
        }
        else {
            // GroupContentPadding.PaddingTop TR
            _aspxSetElementDisplay(headerTR.nextSibling, true);
            // CategoryContent TR
            categoryContentElem = headerTR.nextSibling.nextSibling;
            _aspxSetElementDisplay(headerTR.nextSibling.nextSibling, true);
        }
        
        // GroupContentPadding.PaddingBottom TR
        if (this.groupContentPaddingBottom != 0)
            _aspxSetElementDisplay(categoryContentElem.nextSibling, true);
        if (this.showBackToTop) {
            if (this.groupContentPaddingBottom != 0)
                _aspxSetElementDisplay(categoryContentElem.nextSibling.nextSibling, true);
            else
                _aspxSetElementDisplay(categoryContentElem.nextSibling, true);                    
        }     
    },
    HideCategory: function(categoryElement) {
        var headerTR = categoryElement.parentNode;    
        _aspxSetElementDisplay(headerTR, false);
        // GroupSpacing
        if ((this.groupSpacing != 0) && !this.IsFirstCategoryTR(categoryElement)) 
            _aspxSetElementDisplay(headerTR.previousSibling, false);
        
        var categoryContentElem = null;
        if (this.groupContentPaddingTop == 0) { // GroupContentPadding.PaddingTop == 0
            categoryContentElem = headerTR.nextSibling;
            _aspxSetElementDisplay(headerTR.nextSibling, false);
        }
        else {
            // GroupContentPadding.PaddingTop TR
            _aspxSetElementDisplay(headerTR.nextSibling, false);
            // CategoryContent TR
            categoryContentElem = headerTR.nextSibling.nextSibling;
            _aspxSetElementDisplay(headerTR.nextSibling.nextSibling, false);
        }        
        // GroupContentPadding.PaddingBottom TR
        if (this.groupContentPaddingBottom != 0)
            _aspxSetElementDisplay(categoryContentElem.nextSibling, false);
        if (this.showBackToTop) {
            if (this.groupContentPaddingBottom != 0)
                _aspxSetElementDisplay(categoryContentElem.nextSibling.nextSibling, false);
            else
                _aspxSetElementDisplay(categoryContentElem.nextSibling, false);
        }            
    },
    ShowEmptyResultCaption: function() {
        var elem = this.GetEmptyResultCaptionElement();
        if (this.rowCount > 0 && (this.mainCellWidth > 0)) 
            elem.style.width = this.mainCellWidth + "px";
        _aspxSetElementDisplay(elem, true);
    },
    HideEmptyResultCaption: function() {
        var elem = this.GetEmptyResultCaptionElement();
        _aspxSetElementDisplay(elem, false);
    },
    ShowGroup: function(nodeElement) {
	    if(!_aspxGetElementDisplay(nodeElement))
            _aspxSetElementDisplay(nodeElement, true);
    },
    HideGroup: function(nodeElement) {
        _aspxSetElementDisplay(nodeElement, false);        
    },
    
    SetColumnSeparatorDisplay: function(columnElem, value, columnIndex, rowIndex){
        if(columnIndex != this.columnCount - 1)
            this.SetRightColumnSeparatorDisplay(columnElem, value);        
        else{ // Last column
            var prevColumn = this.GetColumnElement(columnIndex - 1, rowIndex);
            if((prevColumn != null) && (_aspxGetElementDisplay(prevColumn))){
                this.SetLeftColumnSeparatorDisplay(columnElem, value);
            }
        }
    },
    SetLeftColumnSeparatorDisplay: function(columnElem, value){
        var curElem = columnElem.previousSibling;
        while((curElem != null) && (curElem.id == "")){
            _aspxSetElementVisibility(curElem, value);
            curElem = curElem.previousSibling;
        }
    },
    SetRightColumnSeparatorDisplay: function(columnElem, value){
        var curElem = columnElem.nextSibling;
        while((curElem != null) && (curElem.id == "")){
            _aspxSetElementVisibility(curElem, value);
            curElem = curElem.nextSibling;
        }
    },
    
    // Events
    OnFilterInputBlur: function(evt) {
        this.ClearPasteTimer();
    },
    OnFilterInputChange: function(evt) {
        if(this.GetFilterInputElement().value != ""){
            if(this.IsFilterTimerActive())
                this.ClearFilterTimer();
            this.DoFilter(this.GetFilterInputElement().value); // problem with OnBlur
        }
    },
    OnFilterInputFocus: function() {
        this.SetPasteTimer();
    },
    OnFilterInputKeyUp: function(evt) {
        if(this.IsAllowableKeyCode(evt.keyCode)){
            if(this.IsFilterTimerActive())
                this.ClearFilterTimer();
            this.SetFilterTimer(this.GetFilterInputElement(), this.filterDelay);
        }
    },           
    OnFilterInputKeyPress: function(evt) {    
        if (evt.keyCode == ASPxKey.Enter) // Disable Enter
            return false;
    }
});
ASPxClientTitleIndexItemEventArgs = _aspxCreateClass(ASPxClientProcessingModeEventArgs, {
	constructor: function(processOnServer, name, htmlElement, htmlEvent){
	    this.constructor.prototype.constructor.call(this, processOnServer);
        this.name = name;
        this.htmlElement = htmlElement;
        this.htmlEvent = htmlEvent;
    }
});

function aspxSIFBlur(name) {
    var si = aspxGetControlCollection().Get(name);
    if(si != null) si.OnFilterInputBlur();
    return true;
}
function aspxSIFChange(evt, name) {
    var si = aspxGetControlCollection().Get(name);
    if(si != null) si.OnFilterInputChange(evt);
    return true;
}
function aspxSIFFocus(name) {
    var si = aspxGetControlCollection().Get(name);
    if(si != null) si.OnFilterInputFocus();
    return true;
}
function aspxSIFKeyUp(evt, name) {
    var si = aspxGetControlCollection().Get(name);
    if(si != null) si.OnFilterInputKeyUp(evt);
    return true;
}
function aspxSIFKeyPress(evt, name) {
    var si = aspxGetControlCollection().Get(name);
    if(si != null) return si.OnFilterInputKeyPress(evt);
    return true;
}
function aspxSFilterTimer(name){
    var si = aspxGetControlCollection().Get(name);
    if(si != null){
        si.DoFilter(si.GetFilterInputElement().value);
        si.ClearFilterTimer();
    }
}
function aspxSPasteTimer(name) {
    var si = aspxGetControlCollection().Get(name);
    if(si != null) si.DoFilterInternal();
}
// IndexPanel
function aspxIPItemClick(name, value) {
    var ti = aspxGetControlCollection().Get(name);
    if(ti != null) ti.DoIndexPanelItemClick(value);
}
ASPxClientTimer = _aspxCreateClass(ASPxClientControl, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);
        
        this.interval = 60000;
        this.clientEnabled = true;
        this.timerID = -1;                    
        this.Tick = new ASPxClientEvent();
    },    
    Initialize: function() {
        if (this.clientEnabled)
            this.Start();                    
        this.constructor.prototype.Initialize.call(this);
    },
    
    GetStateInputElement: function(index){
        return _aspxGetElementById(this.name + "S");
    },        
    
    Start: function() {        
        this.Stop();
        this.timerID = _aspxSetInterval("aspxTTick(\"" + this.name + "\")", this.interval);
    },
    Stop: function() {         
        if(this.timerID == -1) return;
        this.timerID = _aspxClearInterval(this.timerID);
    },    
    DoTick: function() {        
        var processOnServer = this.RaiseTick();               
        if(processOnServer)
            this.SendPostBack("TICK");
    },    
    GetStateString: function(){
        return (this.clientEnabled ? "1" : "0") + ";" + this.interval;
    },
    UpdateState: function() {
        var element = this.GetStateInputElement();
        if (element != null) 
            element.value = this.GetStateString();
    },
    // API
    RaiseTick: function() {
        var processOnServer = this.IsServerEventAssigned("Tick");
        if(!this.Tick.IsEmpty()) {
            var args = new ASPxClientProcessingModeEventArgs(processOnServer);
            this.Tick.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    },
    GetEnabled: function() {
        return this.clientEnabled;
    },
    SetEnabled: function(enabled) {    
        if (enabled == this.clientEnabled) return;
         if (enabled)
            this.Start();
         else 
            this.Stop();                    
         this.clientEnabled = enabled;
         this.UpdateState();
    },
    GetInterval: function() {
        return this.interval;
    },
    SetInterval: function(interval) {
        if (interval < 1) return;
        this.interval = interval;    
        if (this.clientEnabled) {
            this.Stop();
            this.Start();
        }                    
        this.UpdateState();
    }    
});

function aspxTTick(name){
    var timer = aspxGetControlCollection().Get(name);
    if(timer != null) timer.DoTick();
}
ASPxClientDataView = _aspxCreateClass(ASPxClientControl, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);

        this.allowMultipleCallbacks = false;
    },    
    
    GetPageIndexInputElement: function(){
        return _aspxGetElementById(this.name + "PI");
    },
    GetContentCell: function(){
        return this.GetChild("_CCell");
    }, 
    GetItemsCell: function(){
        return this.GetChild("_ICell");
    },
    DoPagerClick: function(value) {
        var inputElement = this.GetPageIndexInputElement();
        if(inputElement != null)
            this.CreateCallback(inputElement.value + __aspxCallbackSeparator + value, "PAGERCLICK");
    },
    CustomCallback: function(args) {
        if(!_aspxIsExists(this.callBack)) {
            if(this.isInitialized)
                this.SendPostBack(args);
            return;
        }
        this.CreateCallback(args, "CUSTOMCALLBACK");
    },
    OnCallback: function(result) {
        var inputElement = this.GetPageIndexInputElement();
        if(inputElement != null) 
            inputElement.value = result.index;
        var element = this.GetContentCell();
        if(element != null) 
            _aspxSetInnerHtml(element, result.html);
    },
    DoBeginCallback: function(command){
        this.CreateLoadingPanelWithAbsolutePosition(this.GetContentCell());
        ASPxClientControl.prototype.DoBeginCallback.call(this, command);
    },
    PerformCallback: function(parameter) {
        this.CustomCallback(parameter);
    }
});

function aspxDVPagerClick(name, value) {
    var dv = aspxGetControlCollection().Get(name);
    if(dv != null) dv.DoPagerClick(value);
}
ASPxClientCloudControl = _aspxCreateClass(ASPxClientControl, {
	constructor: function(name){
		this.constructor.prototype.constructor.call(this, name);    
        this.ItemClick = new ASPxClientEvent();	    
    },
    RaiseItemClick: function(itemElement, htmlEvent){
        var processOnServer = this.autoPostBack || this.IsServerEventAssigned("ItemClick");
        if(!this.ItemClick.IsEmpty()){
            var name = this.GetItemElementName(itemElement);
            var args = new ASPxClientCloudControlItemEventArgs(processOnServer, name, itemElement, htmlEvent);
            this.ItemClick.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    },
    OnControlClick: function(clickedElement, htmlEvent) {
        var itemElement = _aspxGetParentByClassName(clickedElement, __aspxItemClassName);        
        if(_aspxIsExists(itemElement)) {
            var processOnServer = this.RaiseItemClick(itemElement, htmlEvent);
                   
            var hasItemLink = this.GetLinkElement(itemElement) != null;
            if(processOnServer && !hasItemLink) {
                var name = this.GetItemElementName(itemElement);
                this.SendPostBack("CLICK:" + name);
            }
        }
    }
});
ASPxClientCloudControlItemEventArgs = _aspxCreateClass(ASPxClientProcessingModeEventArgs, {
	constructor: function(processOnServer, name, htmlElement, htmlEvent){
	    this.constructor.prototype.constructor.call(this, processOnServer);
        this.name = name;
        this.htmlElement = htmlElement;
        this.htmlEvent = htmlEvent;
    }
});
ASPxClientNewsControl = _aspxCreateClass(ASPxClientDataView, {
	constructor: function(name){
		this.constructor.prototype.constructor.call(this, name);
        this.TailClick = new ASPxClientEvent();	    
    },
    DoTailClick: function(itemName, evt){
        var clickedElement = _aspxGetEventSource(evt);
        this.OnTailClick(clickedElement, itemName, evt);
    },    
    OnTailClick: function(clickedElement, itemName, htmlEvent) {
        var itemElement = clickedElement;        
        if(_aspxIsExists(itemElement)) {
            var processOnServer = this.RaiseTailClick(itemElement, itemName, htmlEvent);     
                   
            var hasItemLink = this.GetLinkElement(itemElement) != null;
            if(processOnServer && !hasItemLink) {               
                this.SendPostBack("CLICK:" + itemName);
            }
        }
    },
    RaiseTailClick: function(tailElement, itemName, htmlEvent){
        var processOnServer = this.autoPostBack || this.IsServerEventAssigned("TailClick");
        if(!this.TailClick.IsEmpty()){
            var args = new ASPxClientNewsControlItemEventArgs(processOnServer, itemName, tailElement, htmlEvent);
            this.TailClick.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    }
});
ASPxClientNewsControlItemEventArgs = _aspxCreateClass(ASPxClientProcessingModeEventArgs, {
	constructor: function(processOnServer, name, htmlElement, htmlEvent){
	    this.constructor.prototype.constructor.call(this, processOnServer);
        this.name = name;
        this.htmlElement = htmlElement;
        this.htmlEvent = htmlEvent;
    }
});

function aspxHLTClick(evt, name, itemName) {
    var control = aspxGetControlCollection().Get(name);
    if(control != null) control.DoTailClick(itemName, evt);
}
ASPxRelatedControlManager = {

    // Master-Related info storage
    storage: { },
    GetRelatedCollection: function(masterName) {
        if(!_aspxIsExists(this.storage[masterName]))
            this.storage[masterName] = [ ];
        return this.storage[masterName];
    },
    RegisterRelatedControl: function(masterName, name) {
        this.GetRelatedCollection(masterName)[name] = name;
    },
    RegisterRelatedControls: function(masterName, names) {
        var relatedCollection = this.GetRelatedCollection(masterName);
        var name;
        for(var i = 0; i < names.length; i++) {
            name = names[i];
            relatedCollection[name] = name;
        }
    },
    GetLinkedControls: function(masterControl) {
        var result = [ masterControl ];
        for(var name in this.GetRelatedCollection(masterControl.name)) {
            var control = aspxGetControlCollection().Get(name);
            if(_aspxIsExists(control))
                result.push(control);
        }
        return result;
    },
        
    // Shading
    coverCache: { },
    panelCache: { },
    timers: { },
    
    Shade: function(masterControl) {		
		this.ShadeCore(masterControl, true);
		var name = masterControl.name;
		this.timers[name] = _aspxSetTimeout("ASPxRelatedControlManager.ShadeTransition('" + name + "')", 750);
    },
    ShadeCore: function(masterControl, isTransparent) {
		if(!isTransparent)    {
			var panel = masterControl.CreateLoadingPanelWithAbsolutePosition(document.body, masterControl.GetMainElement());
			this.panelCache[masterControl.name] = panel;
		}    
        var controls = this.GetLinkedControls(masterControl);
        for(var i = 0; i < controls.length; i++) {
            var control = controls[i];
            var cover = control.CreateLoadingDiv(document.body, control.GetMainElement());
            if(_aspxIsExistsElement(cover)) {
				if(isTransparent) {
					cover.className = "";
					cover.style.background = "white";									
					if(__aspxIE)
					    cover.style.filter = "alpha(opacity=1)";
					else
					    cover.style.opacity = "0.01";
				}
				this.coverCache[control.name] = cover;
			}
        }		
    },
    ShadeTransition: function(masterName) {
		var obj = aspxGetControlCollection().Get(masterName);
		if(_aspxIsExists(obj)) {
			this.Unshade(obj);
			this.ShadeCore(obj, false);
		}
    },
    Unshade: function(masterControl) {
		var masterName = masterControl.name;
		_aspxClearTimer(this.timers[masterName]);
		delete this.timers[masterName];
		
		var panel = this.panelCache[masterName];
		if(_aspxIsExistsElement(panel))
			_aspxRemoveElement(panel);
		delete this.panelCache[masterName];
    
        var controls = this.GetLinkedControls(masterControl);
        for(var i = 0; i < controls.length; i++) {
            var control = controls[i];
            var cover = this.coverCache[control.name];
            if(_aspxIsExistsElement(cover))
				_aspxRemoveElement(cover);                
            delete this.coverCache[control.name];
        }
    },
    
    // Response processing
    CreateInfo: function() {
        return { 
            clientObjectName:   "",
            elementId:          "",
            innerHtml:          "",
            parameters:         ""
        };    
    },
    ProcessInfo: function(info) {
        var control = aspxGetControlCollection().Get(info.clientObjectName);        
        if(!_aspxIsExists(control) || !_aspxIsFunction(control.ProcessCallbackResult))
            this.ProcessCallbackResultDefault(info.elementId, info.innerHtml, info.parameters);
        else
            control.ProcessCallbackResult(info.elementId, info.innerHtml, info.parameters);
    },
    ProcessCallbackResultDefault: function(elementId, innerHtml, parameters) {
        var element = _aspxGetElementById(elementId);
        if(_aspxIsExistsElement(element))
            element.innerHTML = innerHtml;        
    },
    // TODO: refactor
    ParseResult: function(result) {        
        var prevIndex = 0;
        var index;
        var lens;
        var info;
        
        while(true) {
            var remm = result.substring(prevIndex);
            index = result.indexOf("|", prevIndex);
            if(index < 0)
                break;
            lens = result.substring(prevIndex, index).split(",");
            
            prevIndex = index + 1;

            info = this.CreateInfo();
            info.clientObjectName = result.substr(prevIndex, lens[0]);
            prevIndex += parseInt(lens[0]);
            info.elementId = result.substr(prevIndex, lens[1]);
            prevIndex += parseInt(lens[1]);
            info.innerHtml = result.substr(prevIndex, lens[2]);
            prevIndex += parseInt(lens[2]);
            info.parameters = result.substr(prevIndex, lens[3]);
            prevIndex += parseInt(lens[3]);
            this.ProcessInfo(info);            
        }
    }
};
function _aspxPGNav(evt) {
    var element = _aspxGetEventSource(evt);
    if(element != null) {
        if(element.tagName != "A") {
            var linkElement = _aspxGetChildByTagName(element, "A", 0);
            if(linkElement != null) 
                _aspxNavigateUrl(linkElement.href, linkElement.target);
        }
    }
    if(!__aspxNS)
        evt.cancelBubble = true;
}
ASPxClientCallbackPanel = _aspxCreateClass(ASPxClientControl, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);

        this.allowMultipleCallbacks = false;
    },
	GetContentElement: function() {
	    var element = this.GetMainElement();
	    return element.tagName == "TABLE" ? element.rows[0].cells[0] : element;
	},
    OnCallback: function(result) {
        _aspxSetInnerHtml(this.GetContentElement(), result);
    },
    DoBeginCallback: function(command){
        ASPxClientControl.prototype.DoBeginCallback.call(this, command);
        this.CreateLoadingPanel();
    },
    CreateLoadingPanel: function(){
        var element = this.GetContentElement();
        var mainElement = (element.tagName == "TD") ? this.GetMainElement() : element;
        var elementWidth = mainElement.style.width;
        var elementHeight = mainElement.style.height;

        var div = this.CreateLoadingDiv(element);
        if(div == null)
            element.innerHTML = "";

        if(div != null) {
            this.CreateLoadingPanelWithAbsolutePosition(element, mainElement);
        } else {
            if(elementWidth != "" && elementHeight != "")
                this.CreateLoadingPanelWithAbsolutePosition(element, mainElement);
            else
                this.CreateLoadingPanelInsideContainer(element);
        }
    },
    PerformCallback: function(parameter) {
        this.CreateCallback(parameter);
    }
});

ASPxClientUploadControlIDSuffix = {
    FlagHiddenInput: "_dxeUpload",
    ProgressKeyHiddenName: "DXUploadingKey", 
    ErrorRow: "_ErrR_",
    ErrorRowTemplate: "_ErrR_RT",
    UploadIFrame: "_UploadIframe",
    FileInput: "_Input_",
    FileInputTemplate: "_Input_T",
    AddUploadButtonsSeparator: "_AddUploadR",
    AddUploadButtonsPanelRow: "_AddUploadPanelR",
    InputCountHidden: "_IC",
    AddButtonCell: "_Add",
    UploadButtonCell: "_Upload",
    RemoveButtonCell: "_Remove_",
    CancelButtonCell: "_Cancel",
    CommonErrorDiv: "_CErr",
    ButtonImageIdPostfix: "Img",
    UploadInputsTable: "_UploadInputs",
    ProgressPanel: "_ProgressPanel",
    ProgressControl: "_UCProgress"
};
var __aspxErrorTextResponsePrefix = "DXER:";
var __aspxRemoveButtonCellClassName = "dxRB";

// For progress
var __aspxHandlerPage = "ASPxUploadProgressHandlerPage.ashx";
var __aspxProgressInfoQueryParamName = "DXProgressInfo";
var __aspxUploadingCallbackQueryParamName = "DXUploadingCallback";
var __aspxProgressHandlerKeyQueryParamName = "DXProgressHandlerKey";

var __aspxCancelUploadFakeQueryParamName = "DXFakeQueryParam";
ASPxClientUploadControl = _aspxCreateClass(ASPxClientControl, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);
        // from server
        this.generalErrorText = "";
        this.invalidWindowsPathErrorText = "";
        this.fileInputSpacing = "";
        this.uploadingKey = null;

        this.isInCallback = false;
        this.isCancel = false;
        this.uploadingTimerID = null;
        this.isProgressWaiting = false;
        this.templateDisabledRemoveItem = null;
        this.FileUploadComplete = new ASPxClientEvent();
        this.FilesUploadComplete = new ASPxClientEvent();
        this.FileUploadStart = new ASPxClientEvent();
        this.UploadingProgressChanged = new ASPxClientEvent();
        this.TextChanged = new ASPxClientEvent();
        this.FileInputCountChanged = new ASPxClientEvent();
    },

    /*region* * * * * * * * * * * * * * *  Initialization  * * * * * * * * * * * * * * * */

    Initialize: function() {
        ASPxClientControl.prototype.Initialize.call(this);

        if (__aspxFirefox)
            this.CorrectFileInputSize();

        this.CreateClearFileInput();
        if (__aspxOpera && !_aspxIsExists(frames[this.GetFakeIframeName()]))
            this.ReinitializeIFrame(this.GetFakeIframe());

        _aspxAttachEventToElement(__aspxIE ? this.GetFakeIframeElement() : this.GetFakeIframe(), "load",
                    new Function("aspxFakeUploadIframeOnLoad('" + this.name + "');"));
        this.InitializeForm();
        this.InitializeTemplates();
        this.GetIFrameUrl();

    },
    InitializeTemplates: function() {
        this.fileInputRowTemplateNode = this.GetFileInputRowTemplate().cloneNode(true);
        this.errorRowTemplateNode = this.GetErrorRowTemplate().cloneNode(true);
        this.fileInputSeparatorTemplateNode = this.GetFileInputSeparatorRowTemplate().cloneNode(true);

        _aspxSetElementDisplay(this.fileInputRowTemplateNode, true);
        _aspxSetElementDisplay(this.fileInputSeparatorTemplateNode, true);
    },
    InitializeForm: function() {
        var form = _aspxGetParentByTagName(this.GetMainElement(), "FORM");
        form.enctype = form.encoding = "multipart/form-data";
    },
    ReinitializeIFrame: function(iframe) {
        var divElem = document.createElement("DIV");
        _aspxSetElementDisplay(divElem, false);
        document.body.appendChild(divElem);
        // TODO: Remove
        divElem.appendChild(iframe);
        divElem.appendChild(iframe);
    },

    CreateClearFileInput: function() {
        this.clearFileInputTempalteHtml = _aspxGetChildByTagName(this.GetFileInputRowTemplate(), "TD", 0).innerHTML;
    },
    CorrectFileInputSize: function() {
        var width = this.GetInputWidth();
        var fontSize = this.GetInputFontSize();
        var size = this.FindInputSize(width, fontSize);

        this.GetFileInputElement("T").size = size;
        var fileInputCount = this.GetFileInputCountInternal();
        for (var i = 0; i < fileInputCount; i++)
            this.GetFileInputElement(i).size = size;

    },
    GetInputWidth: function() {
        var width = 0;
        if (this.GetFileInputCountInternal() > 0)
            width = this.GetFileInputElement(0).clientWidth;
        else {
            _aspxSetElementDisplay(this.GetFileInputRowTemplate(), true);
            width = this.GetFileInputElement("T").clientWidth;
            _aspxSetElementDisplay(this.GetFileInputRowTemplate(), false);
        }
        return width;
    },
    GetInputFontSize: function() {
        if (this.GetFileInputCountInternal() > 0)
            return _aspxGetCurrentStyle(this.GetFileInputElement(0)).fontSize;
        else
            return _aspxGetCurrentStyle(this.GetFileInputElement("T")).fontSize;
    },
    FindInputSize: function(width, fontSize) {
        var spanInput = document.createElement("SPAN");
        document.body.appendChild(spanInput);

        var fakeInput = document.createElement("INPUT");
        fakeInput.type = "file";
        fakeInput.size = 0;
        fakeInput.style.fontSize = fontSize;
        spanInput.appendChild(fakeInput);

        var stepSize = 1;
        while (true) {
            fakeInput.size += stepSize;

            if (spanInput.offsetWidth == width)
                break;
            else if (spanInput.offsetWidth > width) {
                if (stepSize > 1) {
                    fakeInput.size -= stepSize;
                    stepSize = 1;
                } else {
                    fakeInput.size -= 1;
                    break;
                }
            }
            else
                stepSize *= 2;
        }

        var inputSize = fakeInput.size;
        _aspxRemoveElement(fakeInput);
        _aspxRemoveElement(spanInput);

        return inputSize;
    },

    /*region* * * * * * * * * * * * * * *  Get/Set  * * * * * * * * * * * * * * * */

    GetSelectedInputFileCount: function() {
        if (!_aspxIsExists(this.selectedInputFileCount)) {
            this.selectedInputFileCount = 0;
            var fileInputCount = this.GetFileInputCountInternal();
            for (var i = 0; i < fileInputCount; i++)
                if (this.GetFileInputElement(i).value != "")
                this.selectedInputFileCount++;
        }
        return this.selectedInputFileCount;
    },
    GetFileInputCountInternal: function() {
        var element = this.GetInputCountHiddenField();
        return parseInt(element.value, 10);
    },
    SetFileInputCountInternal: function(value) {
        this.GetInputCountHiddenField().value = value;
    },

    GetInputCountHiddenField: function() {
        if (!_aspxIsExists(this.inputCountHiddenField)) {
            var id = this.name + ASPxClientUploadControlIDSuffix.InputCountHidden;
            this.inputCountHiddenField = _aspxGetElementById(id);
        }
        return this.inputCountHiddenField;
    },
    GetProgressInfoKeyHiddenField: function() {
        if (!_aspxIsExists(this.progressKeyHiddenField)) {
            this.progressKeyHiddenField = _aspxGetElementById(ASPxClientUploadControlIDSuffix.ProgressKeyHiddenName);
            if (!_aspxIsExists(this.progressKeyHiddenField) && this.uploadingKey) {                
                this.progressKeyHiddenField = _aspxCreateHiddenField(ASPxClientUploadControlIDSuffix.ProgressKeyHiddenName,
                                                                        ASPxClientUploadControlIDSuffix.ProgressKeyHiddenName);
                this.progressKeyHiddenField.value = this.uploadingKey;
                document.appendChild(this.progressKeyHiddenField);
            }
        }
        return this.progressKeyHiddenField;
    },
    GetIFrameUrl: function() {
        if (!_aspxIsExists(this.iframeUrl)) {
            var iframe = __aspxIE ? this.GetFakeIframeElement() : this.GetFakeIframe();
            this.iframeUrl = iframe.attributes["src"].value;
        }
        return this.iframeUrl;
    },
    SetIFrameUrl: function(url) {
        var iframe = __aspxIE ? this.GetFakeIframeElement() : this.GetFakeIframe();
        iframe.attributes["src"].value = url;
    },
    GetProgressInfoKey: function() {
        var field = this.GetProgressInfoKeyHiddenField();
        return _aspxIsExists(field) ? field.value : null;
    },
    GetErrorRow: function(index) {
        return this.GetChild(ASPxClientUploadControlIDSuffix.ErrorRow + index);
    },
    GetErrorCell: function(index) {
        return _aspxGetElementsByTagName(this.GetErrorRow(index), "td")[0];
    },
    GetErrorRowTemplate: function() {
        return this.GetChild(ASPxClientUploadControlIDSuffix.ErrorRowTemplate);
    },
    GetFakeIframe: function() {
        var name = this.GetFakeIframeName();
        return __aspxIE ? frames[name] : _aspxGetElementById(name);
    },
    GetFakeIframeName: function() {
        return this.name + ASPxClientUploadControlIDSuffix.UploadIFrame;
    },
    GetFakeIframeElement: function() {
        return this.GetFakeIframe().frameElement;
    },
    GetFakeIframeDocument: function() {
        return __aspxIE ? this.GetFakeIframe().document : this.GetFakeIframe().contentDocument;
    },
    GetFakeIframeResponseString: function() {
        return _aspxDecodeHtml(this.GetFakeIframeDocument().body.innerHTML);
    },
    GetFileInputElement: function(index) {
        return _aspxGetInputElementById(this.name + ASPxClientUploadControlIDSuffix.FileInput + index);
    },
    GetFileInputRow: function(index) {
        return _aspxGetParentByTagName(this.GetFileInputElement(index), "TR");
    },
    GetFileInputRowTemplate: function() {
        var inputTemplate = this.GetChild(ASPxClientUploadControlIDSuffix.FileInputTemplate);
        return _aspxGetParentByTagName(inputTemplate, "TR");
    },
    GetFileInputsTBody: function() {
        if (!_aspxIsExists(this.tbody))
            this.tbody = _aspxGetParentByTagName(this.GetFileInputRowTemplate(), "TBODY");
        return this.tbody;
    },
    GetUploadInputsTable: function() {
        return this.GetChild(ASPxClientUploadControlIDSuffix.UploadInputsTable);
    },
    GetProgressPanel: function() {
        return this.GetChild(ASPxClientUploadControlIDSuffix.ProgressPanel);
    },
    GetProgressControl: function() {
        if (!_aspxIsExists(this.progressControl)) {
            var name = this.name + ASPxClientUploadControlIDSuffix.ProgressControl;
            this.progressControl = aspxGetControlCollection().Get(name);
        }
        return this.progressControl;
    },
    GetRemoveButtonCell: function(index) {
        return this.GetRemoveButtonCellByInput(this.GetFileInputElement(index));
    },
    GetRemoveButtonCellByInput: function(input) {
        return _aspxGetChildsByClassName(_aspxGetParentByTagName(input, "TR"), __aspxRemoveButtonCellClassName)[0];
    },
    GetAddButtonCell: function() {
        return this.GetChild(ASPxClientUploadControlIDSuffix.AddButtonCell);
    },
    GetUploadButtonCell: function() {
        return this.GetChild(ASPxClientUploadControlIDSuffix.UploadButtonCell);
    },
    GetCancelButtonCell: function() {
        return this.GetChild(ASPxClientUploadControlIDSuffix.CancelButtonCell);
    },
    GetAddButtonLink: function() {
        return _aspxGetChildByTagName(this.GetAddButtonCell(), "A", 0);
    },
    GetUploadButtonLink: function() {
        return _aspxGetChildByTagName(this.GetUploadButtonCell(), "A", 0);
    },
    GetAddUploadButtonsSeparatorRow: function() {
        return this.GetChild(ASPxClientUploadControlIDSuffix.AddUploadButtonsSeparator);
    },
    GetAddUploadButtonsPanelRow: function() {
        return this.GetChild(ASPxClientUploadControlIDSuffix.AddUploadButtonsPanelRow);
    },
    GetFileInputSeparatorRow: function(index) {
        if (this.fileInputSpacing == "" || this.GetFileInputCountInternal() == 1)
            return null;

        if (!_aspxIsExists(index))
            index = 0;
        var ret = null;
        var firstErrorRow = this.GetErrorRow(index);
        if (_aspxIsExists(firstErrorRow)) {
            var parent = firstErrorRow.parentNode;

            var rowIndex = _aspxArrayIndexOf(parent.childNodes, firstErrorRow);
            var element = parent.childNodes[rowIndex + 1];
            if (!_aspxIsExists(element.id) || (element.id == ""))
                ret = parent.childNodes[rowIndex + 1];
        }
        return ret;
    },
    GetFileInputSeparatorRowTemplate: function() {
        if (this.fileInputSpacing == "")
            return null;

        var errRowTemplate = this.GetErrorRowTemplate();
        var parent = errRowTemplate.parentNode;
        var errRowIndex = _aspxArrayIndexOf(parent.childNodes, errRowTemplate);
        return parent.childNodes[errRowIndex + 1];
    },
    GetCommonErrorDivElement: function() {
        return this.GetChild(ASPxClientUploadControlIDSuffix.CommonErrorDiv);
    },
    SetEnabledInternal: function(enabled) {
        for (var i = 0; i < this.GetFileInputCountInternal(); i++) {
            this.GetFileInputElement(i).disabled = !enabled;
            this.SetButtonEnabled(this.GetRemoveButtonCell(i), enabled);
        }
        this.SetButtonEnabled(this.GetAddButtonCell(), enabled);
        this.SetButtonEnabled(this.GetUploadButtonCell(), enabled);
    },
    SetButtonEnabled: function(element, enabled) {
        this.ChangeButtonEnabledState(element, enabled);
        this.ChangeButtonEnabledAttributes(element, _aspxChangeAttributesMethod(enabled), enabled);
    },

    /*region* * * * * * * * * * * * * * *  Main  * * * * * * * * * * * * * * * */
    GetIsResponseValid: function() {
        var ret = false;
        try {
            if (eval(this.GetFakeIframeResponseString()) != null)
                ret = true;
        }
        catch (e) {
            if (__aspxIE)
                this.GetFakeIframe().window.location = this.GetIFrameUrl(); // hack B35365
        }
        return ret;
    },
    GetValue: function(index) {
        return this.GetFileInputElement(index).value;
    },

    ChangeButtonEnabledState: function(element, enabled) {
        if (_aspxIsExists(element))
            aspxGetStateController().SetElementEnabled(element, enabled);
    },
    ChangeButtonEnabledAttributes: function(element, method, enabled) {
        if (_aspxIsExists(element)) {
            method(element, "onclick");
            if (!__aspxIE && enabled)
                element.onclick = new Function(element.getAttribute("onclick"));
        }
    },
    AddFileInput: function() {
        var tBody = this.GetFileInputsTBody();
        var addUploadButtonsElement = this.GetAddUploadButtonsSeparatorRow();
        if (addUploadButtonsElement == null)
            addUploadButtonsElement = this.GetAddUploadButtonsPanelRow();

        if (this.fileInputSpacing != "" && this.GetFileInputCountInternal() != 0) {
            var separatorRow = this.fileInputSeparatorTemplateNode.cloneNode(true);
            tBody.insertBefore(separatorRow, addUploadButtonsElement);
        }

        tBody.insertBefore(this.CreateFileInputRow(this.GetFileInputCountInternal()), addUploadButtonsElement);
        tBody.insertBefore(this.CreateErrorRow(this.GetFileInputCountInternal()), addUploadButtonsElement);

        this.SetFileInputCountInternal(this.GetFileInputCountInternal() + 1);

        var element = this.GetAddUploadButtonsSeparatorRow();
        if (_aspxIsExists(element) && this.GetFileInputCountInternal() > 0 && !_aspxGetElementDisplay(element))
            _aspxSetElementDisplay(element, true);

        this.RaiseFileInputCountChanged();
    },
    RemoveFileInput: function(index) {
        var tBody = this.GetFileInputsTBody();

        _aspxRemoveElement(this.GetFileInputSeparatorRow((index == 0) ? index : index - 1));
        _aspxRemoveElement(this.GetFileInputRow(index));
        _aspxRemoveElement(this.GetErrorRow(index));

        this.RedefineAttributtes(index + 1);

        this.SetFileInputCountInternal(this.GetFileInputCountInternal() - 1);

        var element = this.GetAddUploadButtonsSeparatorRow();
        if (_aspxIsExists(element) && this.GetFileInputCountInternal() == 0 && _aspxGetElementDisplay(element))
            _aspxSetElementDisplay(element, false);

        this.RaiseFileInputCountChanged();
    },
    RedefineAttributtes: function(startIndex) {
        var tBody = this.GetFileInputsTBody();
        for (var index = startIndex; index < this.GetFileInputCountInternal(); index++) {
            var newIndex = index - 1;
            var fileInput = this.GetFileInputElement(index);

            var removeButton = this.GetRemoveButtonCell(index);
            var errorRow = this.GetErrorRow(index);

            this.RedefineInputAttributes(fileInput, newIndex);
            this.RedefineRemoveAttributes(removeButton, newIndex);
            errorRow.id = this.name + ASPxClientUploadControlIDSuffix.ErrorRow + newIndex;
        }
    },
    RedefineInputAttributes: function(inputElement, index) {
        inputElement.id = this.name + ASPxClientUploadControlIDSuffix.FileInput + index;
        inputElement.name = inputElement.id;
        inputElement.onchange = new Function("aspxUTextChanged('" + this.name + "'," + index + ");");
    },
    RedefineRemoveAttributes: function(removeButton, newIndex) {
        if (_aspxIsExists(removeButton)) {
            var newId = this.name + ASPxClientUploadControlIDSuffix.RemoveButtonCell + newIndex;
            removeButton.id = newId;
            var onclick = "aspxURemoveFileInputClick('" + this.name + "'," + newIndex + ");";
            removeButton.setAttribute("onclick", onclick);
            removeButton.onclick = new Function(onclick);

            var img = _aspxGetChildByTagName(removeButton, "IMG", 0);
            if (_aspxIsExists(img))
                img.id = newId + ASPxClientUploadControlIDSuffix.ButtonImageIdPostfix;
        }
    },
    SetAddButtonTextInternal: function(text) {
        var link = this.GetAddButtonLink();
        if (_aspxIsExists(link))
            link.innerHTML = text;
    },
    SetUploadButtonTextInternal: function(text) {
        var link = this.GetUploadButtonLink();
        if (_aspxIsExists(link))
            link.innerHTML = text;
    },
    GetAddButtonTextInternal: function() {
        var link = this.GetAddButtonLink();
        if (_aspxIsExists(link))
            return link.innerHTML;
        return null;
    },
    GetUploadButtonTextInternal: function() {
        var link = this.GetUploadButtonLink();
        if (_aspxIsExists(link))
            return link.innerHTML;
        return null;
    },
    CreateFileInputRow: function(index) {
        var row = this.fileInputRowTemplateNode.cloneNode(true);

        var fileInput = _aspxGetChildByTagName(row, "INPUT", 0);
        fileInput.id = this.name + ASPxClientUploadControlIDSuffix.FileInput + index;
        fileInput.name = fileInput.id;

        if (_aspxIsExists(fileInput.onchange))
            fileInput.onchange = new Function("aspxUTextChanged('" + this.name + "'," + index + ");");

        var removeButton = this.GetRemoveButtonCellByInput