var __ctlInvalidDimension = -10000;
var __ctlInvalidPosition = -10000;
var __ctlAbsoluteLeftPosition = -10000;
var __ctlAbsoluteRightPosition = 10000;
var __ctlMenuZIndex = 20000;
var __ctlPopupControlZIndex = 10000;

var __ctlCallBackSeparator = ":";
var __ctlItemIndexSeparator = "i";
var __ctlCallBackErrorPrefix = "####";

var __ctlItemClassName = "dxi";

var __ctlHTMLLoaded = false;

var __ctlDateFormatInfo = {
    twoDigitYearMax: 2029,
    ts: ":",    ds: "/",
    am: "AM",   pm: "PM"
};

// Debug 
function _ctlGetActiveElement() {
    try{
        return document.activeElement;    
    }
    catch(e) { 
    }
    return null;
}
function _ctlInsp(obj) {
	alert(_ctlGetObjInfo(obj));
}
function _ctlGetObjInfo(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");
}
// Browsers
var __ctlAgent = navigator.userAgent.toLowerCase();
var __ctlOpera = (__ctlAgent.indexOf("opera") > -1);
var __ctlOpera9 = (__ctlAgent.indexOf("opera/9") > -1 || __ctlAgent.indexOf("opera 9") > -1);
var __ctlSafari = __ctlAgent.indexOf("safari") > -1;
var __ctlSafariMacOS = __ctlSafari && __ctlAgent.indexOf("macintosh") > -1;
var __ctlIE = (__ctlAgent.indexOf("msie") > -1 && !__ctlOpera);
var __ctlIE55 = (__ctlAgent.indexOf("5.5") > -1 && __ctlIE);
var __ctlIE7 = (__ctlAgent.indexOf("7.") > -1 && __ctlIE);
var __ctlNotIEOperaSafari = !__ctlSafari && !__ctlIE && !__ctlOpera;
var __ctlFirefox = (__ctlAgent.indexOf("firefox") > -1) && __ctlNotIEOperaSafari;
var __ctlMozilla = (__ctlAgent.indexOf("mozilla") > -1) && __ctlNotIEOperaSafari;
var __ctlNetscape = (__ctlAgent.indexOf("netscape") > -1) && __ctlNotIEOperaSafari;
var __ctlNS = __ctlFirefox  || __ctlMozilla || __ctlNetscape;
// Array
function _ctlArrayPush(array, element){
    if(_ctlIsExists(array.push))
	    array.push(element);
    else	 
        array[array.length] = element;
}
function _ctlArrayInsert(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
	    _ctlArrayPush(array, element);
}

function _ctlArrayRemove(array, element){
    var index = _ctlArrayIndexOf(array, element);
    if(index > -1) _ctlArrayRemoveAt(array, index);
}
function _ctlArrayRemoveAt(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 _ctlArrayClear(array){
	while(array.length > 0)
		array.pop();
}
function _ctlArrayIndexOf(array, element){
	for(var i = 0; i < array.length; i++){
		if(array[i] == element)
			return i;
	} 
	return -1;
}
var __ctlDefaultBinarySearchComparer = function(arrayElement, value) { if(arrayElement == value) return 0; else return arrayElement < value ? -1 : 1; };
function _ctlArrayBinarySearch(array, value, binarySearchComparer, startIndex, length) {
    if(!_ctlIsExists(binarySearchComparer))
        binarySearchComparer = __ctlDefaultBinarySearchComparer;
    if(!_ctlIsExists(startIndex))
        startIndex = 0;
    if(!_ctlIsExists(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);
}

// Timer
function _ctlSetTimeout(callString, timeout){
    return window.setTimeout(callString, timeout);
}
function _ctlClearTimer(timerID){
    if(timerID > -1)
        window.clearTimeout(timerID);
    return -1;
}
// Interval
function _ctlSetInterval(callString, interval){
    return window.setInterval(callString, interval);
}
function _ctlClearInterval(timerID){
    if(timerID > -1)
        window.clearInterval(timerID);
    return -1;
}
// Utils
function _ctlCloneObject(srcObject) {
  if(typeof(srcObject) != 'object') return srcObject;
  if (srcObject == null) return srcObject;
    
  var newObject = new Object();
 
  for(var i in srcObject) 
    newObject[i] = srcObject[i];
 
  return newObject;
}
function _ctlIsExistsType(type){
	return (type != "undefined");
}
function _ctlIsExists(obj){
	return (typeof(obj) != "undefined") && (obj != null);
}
function _ctlIsFunction(obj){
	return typeof(obj) == "function";
}
function _ctlGetDefinedValue(value, defaultValue){
    return (typeof(value) != "undefined") ? value : defaultValue;
}

function _ctlSetInputSelection(input, startPos, endPos){
    startPos = _ctlGetDefinedValue(startPos, 0);
    endPos = _ctlGetDefinedValue(endPos, input.value.length);
    if (__ctlIE) {
        var range = input.createTextRange();
        range.collapse(true);
        range.moveStart("character", startPos);
        range.moveEnd("character", endPos - startPos);
        range.select();
    } else
        input.setSelectionRange(startPos, endPos);
}
function  _ctlHasInputSelection(input){
    var selectionStart = 0;
    var selectionEnd = 0;
    if(__ctlIE){
        var curRange = document.selection.createRange();
        var copyRange = curRange.duplicate();
        
        curRange.move('character', - input.value.length);
        curRange.setEndPoint('EndToStart', copyRange);
        
        var selectionStart = curRange.text.length;
        var selectionEnd = selectionStart + copyRange.text.length;
    } else{
        selectionStart = input.selectionStart;
        selectionEnd = input.selectionEnd;
    }
    return (selectionStart == selectionEnd);
}

function _ctlPreventElementDragAndSelect(element, isSkipMouseMove){
    if(__ctlIE){
        _ctlAttachEventToElement(element, "selectstart", new function(){ return false;});
        if(!isSkipMouseMove)
            _ctlAttachEventToElement(element, "mousemove", _ctlClearSelectionOnMouseMove);
        _ctlAttachEventToElement(element, "dragstart", _ctlPreventDragStart);
    }
}
function _ctlClearSelection(){
    try{
        if (_ctlIsExists(window.getSelection)){
            if (__ctlSafari)
                window.getSelection().collapse();
            else
                window.getSelection().removeAllRanges();
        }
        else if (_ctlIsExists(document.selection)){
            if(_ctlIsExists(document.selection.empty))
                document.selection.empty();
		    else if(_ctlIsExists(document.selection.clear))
			    document.selection.clear();
	    }
	}
	catch(e){
	}
}
function _ctlClearSelectionOnMouseMove(evt){
    if (!__ctlIE || (evt.button != 0)) 
        _ctlClearSelection();
}
function _ctlPreventDragStart(evt){
    evt = _ctlGetEvent(evt);
    var element = _ctlGetEventSource(evt);
    element.releaseCapture(); 
    return false;
}

function _ctlGetElementById(id){
    if(_ctlIsExists(document.getElementById))
	    return document.getElementById(id);
	else
	    return document.all[id];
}
function _ctlGetParentNode(element){
	return element.parentNode;
}
function _ctlGetIsParent(parentElement, element){
	while(element != null){
		if(element.tagName == "BODY") return false;
		if(element == parentElement) return true;
		element = _ctlGetParentNode(element);
	}
	return false;
}
function _ctlGetParentById(element, id){
	element = _ctlGetParentNode(element);
	while(element != null){
		if(element.id == id) return element;
		element = _ctlGetParentNode(element);
	}
	return null;
}
function _ctlGetParentByTagName(element, tagName) {
    tagName = tagName.toUpperCase();
    while(element != null) {
        var name = element.tagName.toUpperCase();
        if(name == "BODY") return null;
        if(name == tagName) return element;
        element = _ctlGetParentNode(element);
    }
    return null;
}
function _ctlGetParentByClassName(element, className) {
    while(element != null) {
        if(element.tagName.toUpperCase() == "BODY") return null;
        if(element.className.indexOf(className) != -1) return element;
        element = _ctlGetParentNode(element);
    }
    return null;
}
function _ctlGetChildById(element, id){
	return __ctlIE ? element.all[id] : _ctlGetElementById(id);
}
function _ctlGetElementsByTagName(element, tagName){
	if(element != null){		
		tagName = tagName.toUpperCase();
		return _ctlIsExists(element.all) ? element.all.tags(tagName) : element.getElementsByTagName(tagName);
	}
	return null;
}
function _ctlGetChildByTagName(element, tagName, index) {
	if(element != null){				
		var collection = _ctlGetElementsByTagName(element, tagName);
		if(collection != null){
			if(index < collection.length)
				return collection[index];
		}
	}
	return null;
}
function _ctlGetChildTextNode(element, index) {
	if(element != null){
	    var collection = new Array();
	    _ctlGetChildTextNodeCollection(element, collection);
		if(index < collection.length)
			return collection[index];
	}
	return null;
}
function _ctlGetChildTextNodeCollection(element, collection) {
    for(var i = 0; i < element.childNodes.length; i ++){
        var childNode = element.childNodes[i];
        if(_ctlIsExists(childNode.nodeValue))
            _ctlArrayPush(collection, childNode);
        _ctlGetChildTextNodeCollection(childNode, collection);
    }
}
function _ctlGetChildsByClassName(element, className) {
	var collection = _ctlIsExists(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 _ctlGetParentByPartialId(element, idPart){
	while(element != null){
	    if(_ctlIsExists(element.id)) {
		    if(element.id.indexOf(idPart) > -1) return element;
		}
		element = _ctlGetParentNode(element);
	}
	return null;
}
function _ctlGetElementsByPartialId(element, partialName, list) {
    if(!_ctlIsExists(element.id)) return;
    if(element.id.indexOf(partialName) > -1) {
        list.push(element);
    }
    for(var i = 0; i < element.childNodes.length; i ++) {
        _ctlGetElementsByPartialId(element.childNodes[i], partialName, list);
    }
}
function _ctlRemoveElement(element) {
	if(_ctlIsExistsElement(element)) {	
		var parent = element.parentNode;
		if(_ctlIsExistsElement(parent))
			parent.removeChild(element);
	}
	element = null;
}
function _ctlGetEvent(evt){
    return (typeof(event) != "undefined") ? event : evt; 
}
function _ctlPreventEvent(evt){
    if (__ctlNS)
        evt.preventDefault();
    else
		evt.returnValue = false;
    return false;
}
function _ctlPreventEventAndBubble(evt){
    _ctlPreventEvent(evt);
    if (__ctlNS)
        evt.stopPropagation();
    evt.cancelBubble = true;
    return false;
}

function _ctlGetEventSource(evt){
    evt = _ctlGetEvent(evt);
    if(!_ctlIsExists(evt)) return null; 
	return __ctlIE ? evt.srcElement : evt.target;
}
function _ctlGetEventX(evt){
    return evt.clientX  - _ctlGetIEDocumentClientOffset(true) + (__ctlSafari ? 0 : _ctlGetDocumentScrollLeft());
}
function _ctlGetEventY(evt){
    return evt.clientY - _ctlGetIEDocumentClientOffset(false) + (__ctlSafari ? 0 : _ctlGetDocumentScrollTop());
}
function _ctlGetIEDocumentClientOffset(IsX){
    var clientOffset = 0;
    if(__ctlIE){
        if(_ctlIsExists(document.documentElement))
            clientOffset = IsX ? document.documentElement.clientLeft : document.documentElement.clientTop;
        if(clientOffset == 0 && _ctlIsExists(document.body))
            var clientOffset = IsX ? document.body.clientLeft : document.body.clientTop;
    }
    return clientOffset;
}
function _ctlGetIsLeftButtonPressed(evt){
    evt = _ctlGetEvent(evt);
    if(!_ctlIsExists(evt)) return false;
	if(__ctlIE)
	    return evt.button == 1;
	else if(__ctlNS || __ctlSafari)
	    return evt.which == 1;
	else if (__ctlOpera)
	    return evt.button == 0;	    
    return true;	    
}
function _ctlGetWheelDelta(evt){
    var ret = __ctlNS ? -evt.detail : evt.wheelDelta;
    if (__ctlOpera)
        ret = -ret;
    return ret;
}

function _ctlDelCookie(name, value){
    _ctlSetCookieInternal(name, value, new Date(1999, 11, 31));
}
function _ctlSetCookie(name, value){
    var date = new Date();
    date.setFullYear(date.getFullYear() + 1);
    _ctlSetCookieInternal(name, value, date);
}
function _ctlSetCookieInternal(name, value, date){
    document.cookie = name + "=" + escape(value) + "; expires=" + date.toGMTString();
}

function _ctlGetElementDisplay(element){
	return element.style.display != "none";
}
function _ctlSetElementDisplay(element, value){
	element.style.display = value ? "" : "none";
}
function _ctlGetElementVisibility(element){
	return element.style.visibility != "hidden";
}
function _ctlSetElementVisibility(element, value){
	element.style.visibility = value ? "" : "hidden";
}

function _ctlGetCurrentStyle(element){
    if (__ctlIE)
        return element.currentStyle;
    else if (__ctlOpera && !__ctlOpera9)
        return window.getComputedStyle(element, null);
    else
        return document.defaultView.getComputedStyle(element, null);
}
function _ctlCreateStyleSheet(){
    if(__ctlIE)
        return document.createStyleSheet();
    else{
        var styleSheet = document.createElement("STYLE");
        document.body.appendChild(styleSheet);
        return document.styleSheets[document.styleSheets.length - 1];
    }
}
function _ctlGetStyleSheetRules(styleSheet){
    return __ctlIE ? styleSheet.rules : styleSheet.cssRules;
}
function _ctlGetStyleSheetRule(className){
    for(var i = 0; i < document.styleSheets.length; i ++){
        var styleSheet = document.styleSheets[i];
        var rules = _ctlGetStyleSheetRules(styleSheet);
        for(var j = 0; j < rules.length; j ++){
            if(rules[j].selectorText == "." + className)
                return rules[j];
        }
    }
    return null;
}

function _ctlRemoveStyleSheetRule(styleSheet, index){
    var rules = _ctlGetStyleSheetRules(styleSheet);
    if (rules.length > 0 && rules.length >= index){
        if(__ctlIE)
            styleSheet.removeRule(index);
        else            
            styleSheet.deleteRule(index);     
    }                
}

function _ctlAddStyleSheetRule(styleSheet, selector, cssText){
    if(!_ctlIsExists(cssText) || cssText == "") return;
    if(__ctlIE)
        styleSheet.addRule(selector, cssText);
    else
        styleSheet.insertRule(selector + " { " + cssText + " }", styleSheet.cssRules.length);
}
function _ctlSetPointerCursor(element) {
    if(element.style.cursor == "")
        element.style.cursor = __ctlIE ? "hand" : "pointer";
}

function _ctlGetIsValidPosition(pos){
    return pos != __ctlInvalidPosition && pos != -__ctlInvalidPosition;
}
function _ctlGetAbsoluteX(curEl){
    return _ctlGetAbsolutePositionX(curEl);
}
function _ctlGetAbsoluteY(curEl){
    return _ctlGetAbsolutePositionY(curEl);
}
function _ctlGetAbsolutePositionX(curEl){
    if (__ctlIE)
        return _ctlGetAbsolutePositionX_IE(curEl);
    if (__ctlOpera)
        return _ctlGetAbsolutePositionX_Opera(curEl);
    return _ctlGetAbsolutePositionX_Other(curEl);
}
function _ctlGetAbsolutePositionX_Opera(curEl){
    var pos = 0;
    while (curEl != null) {
        pos += curEl.offsetLeft;
        curEl = curEl.offsetParent;
    }
    return pos;
}
function _ctlGetAbsolutePositionX_IE(curEl){
    var pos = 0;
    var isFirstCycle = true;
    while (curEl != null) {
        pos += curEl.offsetLeft;
        if (!isFirstCycle && curEl.offsetParent != null)
            pos -= curEl.scrollLeft;
        var tagName = curEl.tagName.toUpperCase();
        if (!isFirstCycle && tagName != "TABLE")
            pos += curEl.clientLeft;
        isFirstCycle = false;
        
        curEl = curEl.offsetParent;
    }
    return pos;
}
function _ctlGetAbsolutePositionX_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 _ctlGetAbsolutePositionY(curEl){
    if (__ctlIE)
        return _ctlGetAbsolutePositionY_IE(curEl);
    if (__ctlOpera)
        return _ctlGetAbsolutePositionY_Opera(curEl);
    return _ctlGetAbsolutePositionY_Other(curEl);
}

function _ctlGetAbsolutePositionY_Opera(curEl){
    var pos = 0;
    while (curEl != null) {
        pos += curEl.offsetTop;
        curEl = curEl.offsetParent;
    }
    return pos;
}

function _ctlGetAbsolutePositionY_IE(curEl){
    var pos = 0;
    var isFirstCycle = true;
    while (curEl != null) {
        pos += curEl.offsetTop;
        if (!isFirstCycle && curEl.offsetParent != null)
            pos -= curEl.scrollTop;
        var tagName = curEl.tagName.toUpperCase();
        if (!isFirstCycle && tagName != "TABLE")
            pos += curEl.clientTop;
        isFirstCycle = false;
        
        curEl = curEl.offsetParent;
    }
    return pos;
}

function _ctlGetAbsolutePositionY_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 _ctlGetPositionElementOffset(element, isX){
    var curEl = element.offsetParent;
    var offset = 0;
    var position = "";
        while(curEl != null) {
        var tagName = _ctlIsExists(curEl.tagName) ? curEl.tagName.toLowerCase() : "";
        if(tagName != "td" && tagName != "tr"){
            var style = _ctlGetCurrentStyle(curEl);
            if (style.position == "absolute" || style.position == "fixed" || style.position == "relative") {
                offset += isX ? curEl.offsetLeft : curEl.offsetTop;
                if (__ctlIE || __ctlOpera9 || __ctlSafariMacOS)
                    offset += _ctlPxToInt(isX ? style.borderLeftWidth : style.borderTopWidth);
            }
        }
        curEl = curEl.offsetParent;
    }
    return offset;
}
function _ctlPxToInt(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 _ctlGetClearClientWidth(element) {
    var currentStyle = _ctlGetCurrentStyle(element);
    return element.offsetWidth - _ctlPxToInt(currentStyle.paddingLeft) - _ctlPxToInt(currentStyle.paddingRight) -
        _ctlPxToInt(currentStyle.borderLeftWidth) - _ctlPxToInt(currentStyle.borderRightWidth);
}
function _ctlGetClearClientHeight(element) {
    var currentStyle = _ctlGetCurrentStyle(element);
    return element.offsetHeight - _ctlPxToInt(currentStyle.paddingTop) - _ctlPxToInt(currentStyle.paddingBottom) -
        _ctlPxToInt(currentStyle.borderTopWidth) - _ctlPxToInt(currentStyle.borderBottomWidth);
}
function _ctlSetOffsetWidth(element, widthValue) {
    var currentStyle = _ctlGetCurrentStyle(element);
    element.style.width = (widthValue - _ctlPxToInt(currentStyle.marginLeft) - _ctlPxToInt(currentStyle.marginRight)) + "px";
}
function _ctlSetOffsetHeight(element, heightValue) {
    var currentStyle = _ctlGetCurrentStyle(element);
    element.style.height = (heightValue - _ctlPxToInt(currentStyle.marginTop) - _ctlPxToInt(currentStyle.marginBottom)) + "px";
}
function _ctlFindOffsetParent(element) {
    if (__ctlIE)
        return element.offsetParent;
    var currentElement = element.parentNode;
    while(_ctlIsExistsElement(currentElement) && currentElement.tagName.toUpperCase() != "BODY") {
        if (currentElement.offsetWidth > 0 && currentElement.offsetHeight > 0)
            return currentElement;
        currentElement = currentElement.parentNode;
    }
    return document.body;
}
function _ctlGetDocumentScrollTop(){
    if(__ctlSafari || __ctlIE55 || document.documentElement.scrollTop == 0)
        return document.body.scrollTop;
    return document.documentElement.scrollTop;
}
function _ctlGetDocumentScrollLeft(){
    if(__ctlSafari || __ctlIE55 || document.documentElement.scrollLeft == 0)
        return document.body.scrollLeft;
    return document.documentElement.scrollLeft;
}
function _ctlGetDocumentClientWidth(){
    if(__ctlSafari || __ctlIE55 || document.documentElement.clientWidth == 0)
        return document.body.clientWidth;
    return document.documentElement.clientWidth;
}
function _ctlGetDocumentClientHeight(){
    if (__ctlSafari) 
        return window.innerHeight;
    if(__ctlIE55 || __ctlOpera || document.documentElement.clientHeight == 0)
        return document.body.clientHeight;
    return document.documentElement.clientHeight;
}
function _ctlGetClientLeft(element){
    return _ctlIsExists(element.clientLeft) ? element.clientLeft : (element.offsetWidth - element.clientWidth) / 2;
}
function _ctlGetClientTop(element){
    return _ctlIsExists(element.clientTop) ? element.clientTop : (element.offsetHeight - element.clientHeight) / 2;
}
function _ctlSetFocus(element) {
    try {
        element.focus();
    }
    catch (e) {
    }
}
function _ctlIsFocusableCore(element, skipContainerVisibilityCheck) {
    var current = element;
    while(_ctlIsExists(current)) {
        if (current == element || !skipContainerVisibilityCheck(current)) {
            if (current.tagName.toLowerCase() == "body")
                return true;
            if (current.disabled || !_ctlGetElementDisplay(current) || !_ctlGetElementVisibility(current))
                return false;
        }
        current = current.parentNode;
    }
    return true;
}
function _ctlIsFocusable(element) {  
    return _ctlIsFocusableCore(element, function(o) { return false; });
}
function _ctlAttachEventToElement(element, eventName, func) {
    if(__ctlNS || __ctlSafari)
        element.addEventListener(eventName, func, true);
    else {
        if(eventName.toLowerCase().indexOf("on") != 0) 
            eventName = "on"+eventName;
        element.attachEvent(eventName, func);
    }
}
function _ctlDetachEventFromElement(element, eventName, func) {
    if(__ctlNS || __ctlSafari)
        element.removeEventListener(eventName, func, true);
    else {
        if(eventName.toLowerCase().indexOf("on") != 0) 
            eventName = "on"+eventName;
        element.detachEvent(eventName, func);
    }
}
function _ctlAttachEventToDocument(eventName, func) {
    _ctlAttachEventToElement(document, eventName, func);
}
function _ctlCreateEventHandlerFunction(funcName, controlName, withHtmlEventArg) {
    return withHtmlEventArg ? new Function("event", funcName + "('" + controlName + "', event);") :
								new Function(funcName + "('" + controlName + "');");
}

function _ctlCreateClass(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(_ctlIsExists(parentClass)) {
        parentClass.preparing = true;
        ret.prototype = new parentClass;
        ret.prototype.constructor = parentClass;
        ret.constr = parentClass;
    }
    if(_ctlIsExists(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
var __ctlEmptyAttributeValue = "DXEmpty";
function _ctlGetAttribute(obj, attrName){
    if(_ctlIsExists(obj.getAttribute))
        return obj.getAttribute(attrName);
    else if(_ctlIsExists(obj.getPropertyValue))
        return obj.getPropertyValue(attrName);
    return null;
}
function _ctlSetAttribute(obj, attrName, value){
    if(_ctlIsExists(obj.setAttribute))
        obj.setAttribute(attrName, value);
    else if(_ctlIsExists(obj.setProperty))
        obj.setProperty(attrName, value, "");
}
function _ctlRemoveAttribute(obj, attrName){
    if(_ctlIsExists(obj.removeAttribute))
        obj.removeAttribute(attrName);
    else if(_ctlIsExists(obj.removeProperty))
        obj.removeProperty(attrName);
}
function _ctlIsExistsAttribute(obj, attrName){
    var value = _ctlGetAttribute(obj, attrName);
    return (value != null) && (value != "");
}
function _ctlChangeAttributeExtended(obj, attrName, savedObj, savedAttrName, newValue){
    if(!_ctlIsExistsAttribute(savedObj, savedAttrName)){
        var oldValue = _ctlIsExistsAttribute(obj, attrName) ? _ctlGetAttribute(obj, attrName) : __ctlEmptyAttributeValue;
        _ctlSetAttribute(savedObj, savedAttrName, oldValue);
    }
    _ctlSetAttribute(obj, attrName, newValue);
}
function _ctlChangeAttribute(obj, attrName, newValue){
    _ctlChangeAttributeExtended(obj, attrName, obj, "saved" + attrName, newValue);
}
function _ctlChangeStyleAttribute(obj, attrName, newValue){
    _ctlChangeAttributeExtended(obj.style, attrName, obj, "saved" + attrName, newValue);
}
function _ctlResetAttributeExtended(obj, attrName, savedObj, savedAttrName){
    if(!_ctlIsExistsAttribute(savedObj, savedAttrName)){
        var oldValue = _ctlIsExistsAttribute(obj, attrName) ? _ctlGetAttribute(obj, attrName) : __ctlEmptyAttributeValue;
        _ctlSetAttribute(savedObj, savedAttrName, oldValue);
     }
    _ctlSetAttribute(obj, attrName, "");
    _ctlRemoveAttribute(obj, attrName);
}
function _ctlResetAttribute(obj, attrName){
    _ctlResetAttributeExtended(obj, attrName, obj, "saved" + attrName);
}
function _ctlResetStyleAttribute(obj, attrName){
    _ctlResetAttributeExtended(obj.style, attrName, obj, "saved" + attrName);
}
function _ctlRestoreAttributeExtended(obj, attrName, savedObj, savedAttrName){
    if(_ctlIsExistsAttribute(savedObj, savedAttrName)){
        var oldValue = _ctlGetAttribute(savedObj, savedAttrName);
        if(oldValue != __ctlEmptyAttributeValue)
            _ctlSetAttribute(obj, attrName, oldValue);
        else
            _ctlRemoveAttribute(obj, attrName);
        _ctlRemoveAttribute(savedObj, savedAttrName);
    }
}
function _ctlRestoreAttribute(obj, attrName){
    _ctlRestoreAttributeExtended(obj, attrName, obj, "saved" + attrName);
}
function _ctlRestoreStyleAttribute(obj, attrName){
    _ctlRestoreAttributeExtended(obj.style, attrName, obj, "saved" + attrName);
}
// String Utils
function _ctlLTrim(value) {	
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");	
}
function _ctlRTrim(value) {	
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");	
}
function _ctlTrim(value) {	
    return _ctlLTrim(_ctlRTrim(value));	
}
//Url utils
function _ctlNavigateUrl(url, target) {
    var javascriptPrefix = "javascript:";
	if(url == "")
		return;
	else if(url.indexOf(javascriptPrefix) != -1) 
	    eval(url.substr(javascriptPrefix.length));
	else {
		if(target != "") {
			if(_ctlIsSpecialTarget(target))
				_ctlNavigateSpecialTarget(url, target);
			else {
				var frame = _ctlGetFrame(top.frames, target);
				if(frame != null)
					frame.location.href = url; 
			}
		}
		else
		    location.href = url;
	}
}
function _ctlIsSpecialTarget(target) {
	var targets = ["_blank", "_media", "_parent", "_search", "_self", "_top"];
	return _ctlArrayIndexOf(targets, target.toLowerCase()) > -1;
}
function _ctlNavigateSpecialTarget(url, target) {
	target = target.toLowerCase();
	if("_top" == target)
		top.location.href = url;
	else if("_self" == target)
		location.href = url;
	else if("_search" == target)
		window.open(url, 'blank');
	else if("_media" == target)
		window.open(url, 'blank');
	else if("_parent" == target)
		window.parent.location.href = url;
	else if("_blank" == target)
		window.open(url, 'blank');
}
function _ctlGetFrame(frames, name) {
	for(var i = 0; i < frames.length; i++) {
	    try {
		    var frame = frames[i];
		    if(frame.name == name) 
		        return frame;	

		    frame = _ctlGetFrame(frame.frames, name);
		    if(frame != null)   
		        return frame;	
	    }
		catch(e) {
		}	
	}
	return null;
}

// Callbacks
function _ctlIsValidElement(element){
    return _ctlIsExists(element.parentNode) && _ctlIsExists(element.parentNode.tagName);
}
function _ctlIsValidElements(elements){
    if (!_ctlIsExists(elements)) return false;    
    for(var i = 0; i < elements.length; i ++){
        if(_ctlIsExists(elements[i]) && !_ctlIsValidElement(elements[i]))
            return false;
    }
    return true;
}
function _ctlIsExistsElement(element){
    return _ctlIsExists(element) && _ctlIsValidElement(element);
}
// event
ctlClientEvent = _ctlCreateClass(null, {
    constructor: function(){
	    this.handlerList = [];
	},
	AddHandler: function (handler) {
		_ctlArrayPush(this.handlerList, handler);
	},
	RemoveHandler: function (handler) {
	    _ctlArrayRemove(this.handlerList, handler);
	},
	ClearHandlers: function () {
	    _ctlArrayClear(this.handlerList);
	},
	FireEvent: function (obj, args) {
		for(var i = 0; i < this.handlerList.length; i ++)
			this.handlerList[i](obj, args);
	},
    IsEmpty: function () {
		return (this.handlerList.length == 0);
	}
});
// collection
__ctlCheckSizeCorrectedFlag = true;

ctlClientCollection = _ctlCreateClass(null, {
    constructor: function(){
	    this.elements = new Object();
	},
	
	Add: function(element){
		this.elements[element.name] = element;
	},
	Get: function(name){
	    return this.elements[name];
	},
	
	// controls group operations
	AdjustControlsSize: function(container, checkSizeCorrectedFlag) {
	    this.ProcessControlsInConatiner(container, function(control) {
	        control.CorrectSize(checkSizeCorrectedFlag);
	    });
	},
	CollapseControls: function(container, checkSizeCorrectedFlag) {
	    this.ProcessControlsInConatiner(container, function(control) {
	        control.CollapseControl(checkSizeCorrectedFlag);
	    });
	},
	
	AtlasInitialize: function(){
	    _ctlProcessScripts();
	    _ctlProcessLinks();
	},
	Initialize: function(){
	    this.InitializeElements();
	    if(_ctlIsExistsType(typeof(Sys)) && _ctlIsExistsType(typeof(Sys.Application)))
            Sys.Application.add_load(ctlCAInit);
	},
	InitializeElements: function(){
        for(var name in this.elements) {
	        if (_ctlIsExists(this.elements[name].isInitialized) && _ctlIsFunction(this.elements[name].Initialize)) {
	            var control = this.elements[name];
	            if (!control.isInitialized)
	                control.Initialize();
	        }
	    }
	    this.AfterInitializeElements(true);
	    this.AfterInitializeElements(false);
	},
	AfterInitializeElements: function(leadingCall) {
	    for(var name in this.elements){
	        if (this.elements[name].leadingAfterInitCall && leadingCall || !this.elements[name].leadingAfterInitCall && !leadingCall) {
	            if(_ctlIsExists(this.elements[name].isInitialized) && _ctlIsFunction(this.elements[name].AfterInitialize)){
	                if(!this.elements[name].isInitialized)
                        this.elements[name].AfterInitialize();
                }
	        }
	    }
	},
	ProcessControlsInConatiner: function(container, processingProc) {
	    for (var controlName in this.elements) {
	        var control = this.elements[controlName];
	        if (_ctlIsExists(container) && _ctlIsExists(control.GetMainElement)) {
	            var mainElement = control.GetMainElement();
	            if (_ctlIsExists(mainElement) && !_ctlGetIsParent(container, mainElement))
	                continue;
	        }
	        processingProc(control);
	    }
	}
});
// control
ctlClientControl = _ctlCreateClass(null, {
    constructor: function(name){
        this.name = name;
        this.uniqueID = name;

        this.autoPostBack = false;
        this.callBack = null;
        this.allowMultipleCallbacks = true;
        this.requestCount = 0;

        this.isInitialized = false;
        this.leadingAfterInitCall = false; // AfterInitialize call will be displaced to the begining of call queue
        this.sizeCorrectedOnce = false;
        this.serverEvents = [];
        
        this.mainElement = null;
        
        this.Init = new ctlClientEvent();
        this.BeginCallback = new ctlClientEvent();
        this.EndCallback = new ctlClientEvent();
        
        ctlGetControlCollection().Add(this);        
    },
    Initialize: function(){
        if(this.callBack != null)
            this.InitializeCallBackData();
    },
    AfterInitialize: function(){
        this.isInitialized = true;
        if(_ctlIsExists(this.RaiseInit))
            this.RaiseInit();
    },
    InitializeCallBackData: function(){
    },
    
    // Size correction
    CollapseControl: function(checkSizeCorrectedFlag) {
    
    },
    CorrectSize: function(checkSizeCorrectedFlag) {

    },
    
    RegisterServerEventAssigned: function(eventNames){
        for(var i = 0; i < eventNames.length; i++)
            this.serverEvents[eventNames[i]] = true;
    },
    IsServerEventAssigned: function(eventName){
        return _ctlIsExists(this.serverEvents[eventName]);
    },
    
    GetChild: function(idPostfix){
        var mainElement = this.GetMainElement();
        return _ctlIsExists(mainElement) ? _ctlGetChildById(this.GetMainElement(), this.name + idPostfix) : null;
    },
    GetItemElementName: function(element) {
        var name = "";
        if (_ctlIsExists(element.id))
            name = element.id.substring(this.name.length + 1);
        return name;
    },
    GetLinkElement: function(element) {
        if (element != null) {
            if (element.tagName.toUpperCase() == "A")
                return element;
            else
                return _ctlGetChildByTagName(element, "A", 0);
        }
        return null;
    },
    GetMainElement: function(){
        if(!_ctlIsExistsElement(this.mainElement))
            this.mainElement = _ctlGetElementById(this.name);
        return this.mainElement;
    },

    OnControlClick: function(clickedElement, htmlEvent) {
    },
    // CallBack
    GetLoadingPanelElement: function(){
        return _ctlGetElementById(this.name + "_LP");
    },
    CreateLoadingPanelClone: function(element, parentElement){
        var cloneElement = element.cloneNode(true);
        cloneElement.id = element.id + "V";
        parentElement.appendChild(cloneElement);
        return cloneElement;
    },
    CreateLoadingPanelInsideContainer: function(parentElement){
        if(parentElement == null) return;
        
        var element = this.GetLoadingPanelElement();
        if (element != null){
            var itemsTable = _ctlGetChildByTagName(parentElement, "TABLE", 0);
            var width = (itemsTable != null) ? itemsTable.offsetWidth : parentElement.clientWidth;
            var height = (itemsTable != null) ? itemsTable.offsetHeight : 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 + "px";
            table.style.width = width + "px";
            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.CreateLoadingPanelClone(element, td);
            _ctlSetElementDisplay(element, true);
            return element;
        }
        else
            parentElement.innerHTML = "&nbsp;";
        return null;
    },
    CreateLoadingPanelWithAbsolutePosition: function(parentElement, offsetElement){
        if(parentElement == null) return;
        
        if(!_ctlIsExists(offsetElement))
            offsetElement = parentElement;
        var element = this.GetLoadingPanelElement();
        if(element != null){
            element = this.CreateLoadingPanelClone(element, parentElement);
            element.style.position = "absolute";
            _ctlSetElementDisplay(element, true);
            this.SetLoadingPanelLocation(offsetElement, element);
            return element;
        }
        return null;
    },
    CreateLoadingPanelInline: function(parentElement){
        if(parentElement == null) return;

        var element = this.GetLoadingPanelElement();
        if(element != null){
            element = this.CreateLoadingPanelClone(element, parentElement);
            _ctlSetElementDisplay(element, true);
            return element;
        }
        return null;
    },
    SetLoadingPanelLocation: function(element, loadingPanel) {
        var ptX = this.GetElementScrollLocationAndSize(_ctlGetAbsoluteX(element), element.offsetWidth, _ctlGetDocumentScrollLeft(), _ctlGetDocumentClientWidth());
        var ptY = this.GetElementScrollLocationAndSize(_ctlGetAbsoluteY(element), element.offsetHeight, _ctlGetDocumentScrollTop(), _ctlGetDocumentClientHeight());
        
        loadingPanel.style.left = ptX.pos + ((ptX.size - loadingPanel.offsetWidth) / 2) - _ctlGetOffset(element, true) + "px";
        loadingPanel.style.top = ptY.pos +((ptY.size - loadingPanel.offsetHeight) / 2) - _ctlGetOffset(element, false) + "px";
    },
    GetElementScrollLocationAndSize: function(abs, size, scrollPos, scrollSize) {
        var pt = new Object();
        pt.pos = abs;
        pt.size = size;
        if(abs < scrollPos + scrollSize) {
            if(abs < scrollPos) {
                pt.pos = scrollPos;
                pt.size -= scrollPos - abs;
            }
            if(pt.size + pt.pos > scrollPos + scrollSize) {
                pt.size = scrollSize - (pt.pos - scrollPos);
            }
        }
        return pt;
    },
    GetLoadingDiv: function(){
        return _ctlGetElementById(this.name + "_LD");
    },
    CreateLoadingDiv: function(parentElement, offsetElement){
        if(parentElement == null) return;
    
        if(!_ctlIsExists(offsetElement))
            offsetElement = parentElement;
        var div = this.GetLoadingDiv();
        if(div != null){
            div = div.cloneNode(true);
            parentElement.appendChild(div);
            div.style.position = "absolute";
            div.style.left = _ctlGetRelevantX(offsetElement, parentElement) + "px";
            div.style.top = _ctlGetRelevantY(offsetElement, parentElement) + "px";
            div.style.width = offsetElement.offsetWidth + "px";
            div.style.height = offsetElement.offsetHeight + "px";
            _ctlSetElementDisplay(div, true);
            return div;
        }
        return null;
    },
        
    InCallback: function() {
        return this.requestCount > 0;
    },
    DoBeginCallback: function(command) {
        if (_ctlIsExists(this.RaiseBeginCallback)) {
            if(!_ctlIsExists(command)) {
                command = "";
            }
            this.RaiseBeginCallback(command);    
        }
	    if(_ctlIsExists(WebForm_InitCallback)) {
	        __theFormPostData = "";
            __theFormPostCollection = new Array();
            WebForm_InitCallback();
        }
    },
    CreateCallback: function(arg, command) {
        if(!this.CanCreateCallback()) 
            return;
        
        this.requestCount++;
        this.DoBeginCallback(command);
        this.callBack(arg);    
    },
    CanCreateCallback: function() {
        return this.allowMultipleCallbacks || !this.InCallback();
    },
    DoEndCallback: function(){
        _ctlSetTimeout(_ctlProcessScripts, 1);
        _ctlSetTimeout(_ctlProcessLinks, 1);
        
        if (_ctlIsExists(this.RaiseEndCallback))
            this.RaiseEndCallback();        
    },
    DoCallback: function(result){
        this.requestCount--;
        if(result.indexOf(__ctlCallBackErrorPrefix) > -1)
            this.DoCallbackError(result);
        else {            
            this.OnCallback(result);
        }        
        this.DoEndCallback();
    },
    DoCallbackError: function(result){
        var pos = result.indexOf(__ctlCallBackErrorPrefix);
        if(pos > -1) 
            result = result.substr(pos + __ctlCallBackErrorPrefix.length);
        else
            result = "A server error has occurred while a callBack has being processed on the server.";
        this.OnCallbackError(result);
    },
    DoControlClick: function(evt){
        var clickedElement = __ctlIE ? evt.srcElement : evt.target;
        this.OnControlClick(clickedElement, evt);
    },
    OnCallback: function(result){
    },    
    OnCallbackError: function(result){
    },
    SendPostBack: function(params){
        __doPostBack(this.uniqueID, params);
    }
});

var __ctlControlCollection = null;
function ctlGetControlCollection(){
    if(__ctlControlCollection == null)
        __ctlControlCollection = new ctlClientCollection();
    return __ctlControlCollection;
}

function ctlCAInit(){
    ctlGetControlCollection().AtlasInitialize();
}
function ctlCallback(result, context){
    var control = ctlGetControlCollection().Get(context);
    if(control != null)
        control.DoCallback(result);
}
function ctlCallbackError(result, context){
    var control = ctlGetControlCollection().Get(context);
    if(control != null)
        control.DoCallbackError(result);    
}

function ctlCClick(name, evt) {
    var control = ctlGetControlCollection().Get(name);
    if(control != null) control.DoControlClick(evt);
}

//StateController
var __ctlHoverStyleSheet = null;
var __ctlPressedStyleSheet = null;
var __ctlSelectedStyleSheet = null;
var __ctlDisabledStyleSheet = null;
var __ctlHoverItemKind = "HoverStateItem";
var __ctlPressedItemKind = "PressedStateItem";
var __ctlSelectedItemKind = "SelectedStateItem";
var __ctlDisabledItemKind = "DisabledStateItem";
var __ctlStyleCount = 0;

ctlStateItem = _ctlCreateClass(null, {
    constructor: function(name, className, cssText, postfixes, imageUrls, imagePostfixes, kind){
        this.name = name;
        this.className = className;
        this.customClassName = "";
        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(){
        var styleSheet = this.GetStyleSheet();
        if(_ctlIsExists(styleSheet) && this.cssText != ""){
            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" + __ctlStyleCount;
            _ctlAddStyleSheetRule(styleSheet, "." + className, cssText);
            __ctlStyleCount++;
            return className;
        }
        return "";
    },
    GetClassName: function(){
        if(this.customClassName == "")
            this.customClassName = this.CreateStyleRule();
        var className = this.className;
        if(this.customClassName != ""){
            if(className != "")
                className += " ";
            className += this.customClassName;
        }
        return className;
    },
    GetStyleSheet: function(){
        if(!_ctlIsExists(__ctlDisabledStyleSheet))
            __ctlDisabledStyleSheet = _ctlCreateStyleSheet();
        if(!_ctlIsExists(__ctlSelectedStyleSheet))
            __ctlSelectedStyleSheet = _ctlCreateStyleSheet();
        if(!_ctlIsExists(__ctlHoverStyleSheet))
            __ctlHoverStyleSheet = _ctlCreateStyleSheet();
        if(!_ctlIsExists(__ctlPressedStyleSheet))
            __ctlPressedStyleSheet = _ctlCreateStyleSheet();
        switch(this.kind){
            case __ctlDisabledItemKind:
                return __ctlDisabledStyleSheet;
            case __ctlHoverItemKind:
                return __ctlHoverStyleSheet;
            case __ctlPressedItemKind:
                return __ctlPressedStyleSheet;
            case __ctlSelectedItemKind:
                return __ctlSelectedStyleSheet;
        }
        return null;
    },
    GetElements: function(element){
        if(!_ctlIsExists(this.elements) || !_ctlIsValidElements(this.elements)){
            if(_ctlIsExists(this.postfixes) && this.postfixes.length > 0){
                this.elements = new Array();
                var parentNode = _ctlGetParentNode(element);
                if(_ctlIsExists(parentNode)){
                    for(var i = 0; i < this.postfixes.length; i++){
                        var id = this.name + this.postfixes[i];
                        this.elements[i] = _ctlGetChildById(parentNode, id);
                    }
                }
            }
            else
                this.elements = [element];
        }
        return this.elements;
    },
    GetImages: function(element){
        if(!_ctlIsExists(this.images) || !_ctlIsValidElements(this.images)){
            this.images = new Array();
            if(_ctlIsExists(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(!_ctlIsExists(elements[j])) continue;
                        
                        this.images[i] = _ctlGetChildById(elements[j], id);
                        if(_ctlIsExists(this.images[i]))
                            break;
                    }
                }
            }
        }
        return this.images;
    },
    
    Apply: function(element){        
        this.ApplyStyle(element);
        if(_ctlIsExists(this.imageUrls) && this.imageUrls.length > 0)
            this.ApplyImage(element);
    },
    ApplyStyle: function(element){
        var elements = this.GetElements(element);
        for(var i = 0; i < elements.length; i++){
            if(!_ctlIsExists(elements[i])) continue;

            var className = _ctlTrim(elements[i].className.replace(this.GetClassName(), ""));
            elements[i].className = className + " " + this.GetClassName();
            if(!__ctlOpera || __ctlOpera9)
                this.ApplyStyleToLinks(elements, i);
        }
    },
    ApplyStyleToLinks: function(elements, index){
        var linkCount = 0;
        do{
            var link = _ctlGetChildByTagName(elements[index], "A", linkCount);
            if(link != null) this.ApplyStyleToLinkElement(link);
            linkCount++;
        }
        while(link != null)
    },
    ApplyStyleToLinkElement: function(link){
        if(this.GetLinkColor() != "")
            _ctlChangeAttributeExtended(link.style, "color", link, "saved" + this.kind + "Color", this.GetLinkColor());
        if(this.GetLinkTextDecoration() != "")
            _ctlChangeAttributeExtended(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(!_ctlIsExists(images[i]) || !_ctlIsExists(this.imageUrls[i]) || this.imageUrls[i] == "") continue;
            if(_ctlIsAlphaFilterUsed(images[i]))            
                _ctlChangeAttributeExtended(images[i].style, "filter", images[i], "saved" + this.kind + "Filter", 
                    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + this.imageUrls[i] + ", sizingMethod=scale)");                
            else
                _ctlChangeAttributeExtended(images[i], "src", images[i], "saved" + this.kind + "Src", this.imageUrls[i]);
        }
    },
    Cancel: function(element){
        this.CancelStyle(element);
        this.CancelImage(element);
    },
    CancelStyle: function(element){
        var elements = this.GetElements(element);
        for(var i = 0; i < elements.length; i++){
            if(!_ctlIsExists(elements[i])) continue;
            
            var className = _ctlTrim(elements[i].className.replace(this.GetClassName(), ""));
            elements[i].className = className;
            if(!__ctlOpera || __ctlOpera9)
                this.CancelStyleFromLinks(elements, i);
        }
    },
    CancelStyleFromLinks: function(elements, index){
        var linkCount = 0;
        do{
            var link = _ctlGetChildByTagName(elements[index], "A", linkCount);
            if(link != null) this.CancelStyleFromLinkElement(link);
            linkCount++;
        }
        while(link != null)
    },
    CancelStyleFromLinkElement: function(link){
        if(this.GetLinkColor() != "")
            _ctlRestoreAttributeExtended(link.style, "color", link, "saved" + this.kind + "Color");
        if(this.GetLinkTextDecoration() != "")
            _ctlRestoreAttributeExtended(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(!_ctlIsExists(images[i]) || !_ctlIsExists(this.imageUrls[i]) || this.imageUrls[i] == "") continue;
            if(_ctlIsAlphaFilterUsed(images[i]))
                _ctlRestoreAttributeExtended(images[i].style, "filter", images[i], "saved" + this.kind + "Filter");
            else
                _ctlRestoreAttributeExtended(images[i], "src", images[i], "saved" + this.kind + "Src");
        }
    },
    Clone: function(){
        return new ctlStateItem(this.name, this.className, this.cssText, this.postfixes, 
            this.imageUrls, this.imagePostfixes, this.kind);
    },
    
    GetLinkColor: function(){
        if(!_ctlIsExists(this.linkColor)){
            var rule = _ctlGetStyleSheetRule(this.customClassName);
            this.linkColor = _ctlIsExists(rule) ? rule.style.color : null;
            if(!_ctlIsExists(this.linkColor)){
                var rule = _ctlGetStyleSheetRule(this.className);
                this.linkColor = _ctlIsExists(rule) ? rule.style.color : null;
            }
            if(this.linkColor == null) 
                this.linkColor = "";
        }
        return this.linkColor;
    },
    GetLinkTextDecoration: function(){
        if(!_ctlIsExists(this.linkTextDecoration)){
            var rule = _ctlGetStyleSheetRule(this.customClassName);
            this.linkTextDecoration = _ctlIsExists(rule) ? rule.style.textDecoration : null;
            if(!_ctlIsExists(this.linkTextDecoration)){
                var rule = _ctlGetStyleSheetRule(this.className);
                this.linkTextDecoration = _ctlIsExists(rule) ? rule.style.textDecoration : null;
            }
            if(this.linkTextDecoration == null) 
                this.linkTextDecoration = "";
        }
        return this.linkTextDecoration;
    }
});

ctlClientStateEventArgs = _ctlCreateClass(null, {
    constructor: function(item, element){
        this.item = item;
        this.element = element;
    }
});

ctlStateController = _ctlCreateClass(null, {
    constructor: function(){
        this.hoverItems = new Object();
        this.pressedItems = new Object();
        this.selectedItems = new Object();
        this.disabledItems = new Object();
        
        this.currentHoverElement = null;
        this.currentHoverItemName = null;
        this.currentPressedElement = null;
        this.currentPressedItemName = null;
        this.savedCurrentPressedElement = null;
        
        this.AfterSetHoverState = new ctlClientEvent();
        this.AfterClearHoverState = new ctlClientEvent();
        this.AfterSetPressedState = new ctlClientEvent();
        this.AfterClearPressedState = new ctlClientEvent();
        this.AfterDisabled = new ctlClientEvent();
        this.AfterEnabled = new ctlClientEvent();
        this.BeforeSetHoverState = new ctlClientEvent();
        this.BeforeClearHoverState = new ctlClientEvent();
        this.BeforeSetPressedState = new ctlClientEvent();
        this.BeforeClearPressedState = new ctlClientEvent();
        this.BeforeDisabled = new ctlClientEvent();
        this.BeforeEnabled = new ctlClientEvent();
    },    
    AddHoverItem: function(name, className, cssText, postfixes, imageUrls, imagePostfixes){
        this.AddItem(this.hoverItems, name, className, cssText, postfixes, imageUrls, imagePostfixes, __ctlHoverItemKind);
    },
    AddPressedItem: function(name, className, cssText, postfixes, imageUrls, imagePostfixes){
        this.AddItem(this.pressedItems, name, className, cssText, postfixes, imageUrls, imagePostfixes, __ctlPressedItemKind);
    },
    AddSelectedItem: function(name, className, cssText, postfixes, imageUrls, imagePostfixes){
        this.AddItem(this.selectedItems, name, className, cssText, postfixes, imageUrls, imagePostfixes, __ctlSelectedItemKind);
    },
    AddDisabledItem: function(name, className, cssText, postfixes, imageUrls, imagePostfixes){
        this.AddItem(this.disabledItems, name, className, cssText, postfixes, imageUrls, imagePostfixes, __ctlDisabledItemKind);
    },
    AddItem: function(items, name, className, cssText, postfixes, imageUrls, imagePostfixes, kind){
        if(_ctlIsExists(postfixes) && postfixes.length > 0){
            for(var i = 0; i < postfixes.length; i ++){
                var elementName = name + postfixes[i];
                items[elementName] = new ctlStateItem(name, className, cssText, postfixes, imageUrls, imagePostfixes, kind);
            }
        }
        else
            items[name] = new ctlStateItem(name, className, cssText, postfixes, imageUrls, imagePostfixes, kind);
    },
    
    GetHoverElement: function(element){
        return this.GetItemElement(element, this.hoverItems, __ctlHoverItemKind);
    },
    GetPressedElement: function(element){
        return this.GetItemElement(element, this.pressedItems, __ctlPressedItemKind);
    },
    GetSelectedElement: function(element){
        return this.GetItemElement(element, this.selectedItems, __ctlSelectedItemKind);
    },
    GetDisabledElement: function(element){
        return this.GetItemElement(element, this.disabledItems, __ctlDisabledItemKind);
    },
    GetItemElement: function(element, items, kind){
        while(element != null) {
            if(_ctlIsExists(element.tagName) && element.tagName.toUpperCase() == "BODY") return null;
            if(_ctlIsExists(element.id) &&  (!__ctlIE || (_ctlIsExists(element.disabled) && !element.disabled))){
                var item = items[element.id];
                if(_ctlIsExists(item) && item.enabled){
                    element[kind] = item;
                    return element;
                }
            }
            element = _ctlGetParentNode(element);
        }
        return null;
    },
        
    DoSetHoverState: function(element){
        var item = element[__ctlHoverItemKind];
        if(_ctlIsExists(item)){
            var args = new ctlClientStateEventArgs(item, element);
            this.BeforeSetHoverState.FireEvent(this, args);
            item.Apply(element);
            this.AfterSetHoverState.FireEvent(this, args);
        }
    },
    DoClearHoverState: function(element){
        var item = element[__ctlHoverItemKind];
        if(_ctlIsExists(item)){
            var args = new ctlClientStateEventArgs(item, element);
            this.BeforeClearHoverState.FireEvent(this, args);
            item.Cancel(element);
            this.AfterClearHoverState.FireEvent(this, args);
        }
    },
    DoSetPressedState: function(element){
        var item = element[__ctlPressedItemKind];
        if(_ctlIsExists(item)){
            var args = new ctlClientStateEventArgs(item, element);
            this.BeforeSetPressedState.FireEvent(this, args);
            item.Apply(element);
            this.AfterSetPressedState.FireEvent(this, args);
        }
    },
    DoClearPressedState: function(element){
        var item = element[__ctlPressedItemKind];
        if(_ctlIsExists(item)){
            var args = new ctlClientStateEventArgs(item, element);
            this.BeforeClearPressedState.FireEvent(this, args);
            item.Cancel(element);
            this.AfterClearPressedState.FireEvent(this, args);
        }
    },
    SetCurrentHoverElement: function(element){
        if(_ctlIsExists(this.currentHoverElement) && !_ctlIsValidElement(this.currentHoverElement)){
            this.currentHoverElement = null;
            this.currentHoverItemName = "";
        }
        if(this.currentHoverElement != element){
            var item = (element != null) ? element[__ctlHoverItemKind] : null;
            var itemName = (item != null) ? item.name : "";
            if(this.currentHoverItemName != itemName){
                if(this.currentHoverElement != null)
                    this.DoClearHoverState(this.currentHoverElement);
                this.currentHoverElement = element;
                item = (element != null) ? element[__ctlHoverItemKind] : null;
                this.currentHoverItemName = (item != null) ? item.name : "";
                if(this.currentHoverElement != null)
                    this.DoSetHoverState(this.currentHoverElement);
            }
        }
    },
    SetCurrentPressedElement: function(element){
        if(_ctlIsExists(this.currentPressedElement) && !_ctlIsValidElement(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[__ctlPressedItemKind] : null;
            this.currentPressedItemName = (item != null) ? item.name : "";
            if(this.currentPressedElement != null)
                this.DoSetPressedState(this.currentPressedElement);
        }
    },
    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[__ctlSelectedItemKind];
        if(_ctlIsExists(item))
            item.Apply(element);
    },    
    SelectElementBySrcElement: function(srcElement){
        var element = this.GetSelectedElement(srcElement);
        if(element != null) this.SelectElement(element);
    },    
    DeselectElement: function(element){
        var item = element[__ctlSelectedItemKind];
        if(_ctlIsExists(item))
            item.Cancel(element);
    },    
    DeselectElementBySrcElement: function(srcElement){
        var element = this.GetSelectedElement(srcElement);
        if(element != null) this.DeselectElement(element);
    },
    DisableElement: function(element){
        var element = this.GetDisabledElement(element);
        if(element != null) {
            var item = element[__ctlDisabledItemKind];
            if(_ctlIsExists(item)){
                var args = new ctlClientStateEventArgs(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[__ctlDisabledItemKind];
            if(_ctlIsExists(item)){
                var args = new ctlClientStateEventArgs(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(_ctlIsExists(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(_ctlIsExists(items[name])) items[name].enabled = enabled;
    },
    
    OnMouseMove: function(evt){
        if(__ctlIE && !_ctlGetIsLeftButtonPressed(evt) && this.savedCurrentPressedElement != null){
            this.savedCurrentPressedElement = null;
            this.SetCurrentPressedElement(null);
        }
             
        var srcElement = _ctlGetEventSource(evt);
        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(!_ctlGetIsLeftButtonPressed(evt)) return;
        var srcElement = _ctlGetEventSource(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 = _ctlGetEventSource(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 = _ctlGetEventSource(evt);
        if (_ctlIsExists(element) && element.tagName == "IFRAME")
            this.OnMouseMove(evt);
    },
    OnSelectStart: function(evt){
        if ((this.savedCurrentPressedElement != null) && 
            (!_ctlIsExists(this.savedCurrentPressedElement.needClearSelection)))  {
            _ctlClearSelection();
            return false;
        }
    }
});

var __ctlStateController = null;
function ctlGetStateController(){
    if(__ctlStateController == null)
        __ctlStateController = new ctlStateController();
    return __ctlStateController;
}

function ctlAddStateItems(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(_ctlIsExists(classes[i][2][j]) && classes[i][2][j] != "")
                name += "_" + classes[i][2][j];
            var postfixes = _ctlIsExists(classes[i][3]) ? classes[i][3] : null;
            var imageUrls = _ctlIsExists(classes[i][4]) && _ctlIsExists(classes[i][4][j]) ? classes[i][4][j] : null;
            var imagePostfixes =  _ctlIsExists(classes[i][5]) ? classes[i][5] : null;
            method.call(ctlGetStateController(), name, classes[i][0], classes[i][1], postfixes, imageUrls, imagePostfixes);
        }
    }
}
function ctlAddHoverItems(namePrefix, classes){
    ctlAddStateItems(ctlGetStateController().AddHoverItem, namePrefix, classes);
}
function ctlAddPressedItems(namePrefix, classes){
    ctlAddStateItems(ctlGetStateController().AddPressedItem, namePrefix, classes);
}
function ctlAddSelectedItems(namePrefix, classes){
    ctlAddStateItems(ctlGetStateController().AddSelectedItem, namePrefix, classes);
}
function ctlAddDisabledItems(namePrefix, classes){
    ctlAddStateItems(ctlGetStateController().AddDisabledItem, namePrefix, classes);
}

function ctlAddAfterClearHoverState(handler){
    ctlGetStateController().AfterClearHoverState.AddHandler(handler);
}
function ctlAddAfterSetHoverState(handler){
    ctlGetStateController().AfterSetHoverState.AddHandler(handler);
}
function ctlAddAfterClearPressedState(handler){
    ctlGetStateController().AfterClearPressedState.AddHandler(handler);
}
function ctlAddAfterSetPressedState(handler){
    ctlGetStateController().AfterSetPressedState.AddHandler(handler);
}
function ctlAddAfterDisabled(handler){
    ctlGetStateController().AfterDisabled.AddHandler(handler);
}
function ctlAddAfterEnabled(handler){
    ctlGetStateController().AfterEnabled.AddHandler(handler);
}
function ctlAddBeforeClearHoverState(handler){
    ctlGetStateController().BeforeClearHoverState.AddHandler(handler);
}
function ctlAddBeforeSetHoverState(handler){
    ctlGetStateController().BeforeSetHoverState.AddHandler(handler);
}
function ctlAddBeforeClearPressedState(handler){
    ctlGetStateController().BeforeClearPressedState.AddHandler(handler);
}
function ctlAddBeforeSetPressedState(handler){
    ctlGetStateController().BeforeSetPressedState.AddHandler(handler);
}
function ctlAddBeforeDisabled(handler){
    ctlGetStateController().BeforeDisabled.AddHandler(handler);
}
function ctlAddBeforeEnabled(handler){
    ctlGetStateController().BeforeEnabled.AddHandler(handler);
}

_ctlAttachEventToElement(window, "load", ctlClassesWindowOnLoad);
function ctlClassesWindowOnLoad(evt){
	ctlGetControlCollection().Initialize();
	__ctlHTMLLoaded = true;
	_ctlInitializeScripts();
	_ctlProcessLinks();
	
}

_ctlAttachEventToDocument("mousemove", ctlClassesDocumentMouseMove);
function ctlClassesDocumentMouseMove(evt){
    if(__ctlHTMLLoaded)
	    ctlGetStateController().OnMouseMove(evt);
}
_ctlAttachEventToDocument("mousedown", ctlClassesDocumentMouseDown);
function ctlClassesDocumentMouseDown(evt){
    if(__ctlHTMLLoaded)
	    ctlGetStateController().OnMouseDown(evt);
}
_ctlAttachEventToDocument("mouseup", ctlClassesDocumentMouseUp);
function ctlClassesDocumentMouseUp(evt){
    if(__ctlHTMLLoaded)
	    ctlGetStateController().OnMouseUp(evt);
}
_ctlAttachEventToDocument("mouseover", ctlClassesDocumentMouseOver);
function ctlClassesDocumentMouseOver(evt){
    if(__ctlHTMLLoaded)
	    ctlGetStateController().OnMouseOver(evt);
}
_ctlAttachEventToDocument("selectstart", ctlClassesDocumentSelectStart);
function ctlClassesDocumentSelectStart(evt){
    return ctlGetStateController().OnSelectStart(evt);	
}

function ctlFireDefaultButton(evt, buttonID){
    if (evt.keyCode == 13 && 
        !(_ctlIsExists(evt.srcElement) && (evt.srcElement.tagName.toLowerCase() == "textarea"))) {
        var defaultButton = _ctlGetElementById(buttonID);
        if (_ctlIsExists(defaultButton) && _ctlIsExists(defaultButton.click)) {
            if (_ctlIsFocusable(defaultButton))
                defaultButton.focus();
            defaultButton.click();
            evt.cancelBubble = true;
            if (_ctlIsFunction(evt.stopPropagation)) 
                evt.stopPropagation();
            return false;
        }
    }
    return true;
}

function _ctlSweepDuplicateElements(collection, attributeName) {
    var hash = { };
    for(var i = 0; i < collection.length; i++) {
        var item = collection[i];
        var value = item[attributeName];
        if(!_ctlIsExists(value) || value == "")
            continue;
        if(_ctlIsExists(hash[value]) && _ctlIsExistsElement(item.parentNode)) {
            if(!__ctlIE || __ctlIE7 || item.tagName != "LINK")
                item.parentNode.removeChild(item);
        } else
            hash[value] = 1;
    }
}

function _ctlProcessLinks() {
    var links = document.getElementsByTagName("LINK");
    var head = document.getElementsByTagName("HEAD")[0];
    _ctlMoveStyleLinksToHead(links, head);
    _ctlSweepDuplicateElements(links, "href");
}

// Style links processing
function _ctlMoveStyleLinksToHead(pageLinksCollection, head) {
    if (!_ctlIsExists(pageLinksCollection) || pageLinksCollection.length == 0)
        return;
    var linksToMove = [ ];
    for(var i = 0; i < pageLinksCollection.length; i++) {
        var link = pageLinksCollection[i];
        if (_ctlIsExists(link.parentNode) && _ctlIsExists(link.parentNode.tagName) && link.parentNode.tagName.toUpperCase() != "HEAD")
            linksToMove.push(link);
    }
    for(var i = 0; i < linksToMove.length; i++)
        _ctlMoveStyleLinkToHead(linksToMove[i], head);
}
function _ctlMoveStyleLinkToHead(link, head) {
    var href = link.href;
    link.parentNode.removeChild(link);
    var existentHeadLink = _ctlGetHeadLinkByHref(head, href);
    if (existentHeadLink == null)
        head.appendChild(_ctlCreateStyleLink(href));
}
function _ctlCreateStyleLink(href) {
    var link = document.createElement("LINK");
    link.type = "text/css";
    link.rel = "Stylesheet";
    link.href = href;
    return link;
}
function _ctlGetHeadLinkByHref(head, href) {
    for(var i = 0; i < head.childNodes.length; i++) {
        var headLink = head.childNodes[i];
        if (_ctlIsExists(headLink.tagName) && headLink.tagName.toUpperCase() == "LINK" && 
            _ctlIsExists(headLink.type) && headLink.type.toUpperCase() == "TEXT/CSS" && headLink.href == href)
            return headLink;
    }
    return null;
}

// Javascript manager
var __ctlIncludeScriptPrefix = "dxis_";
var __ctlStartupScriptPrefix = "dxss_";
var __ctlIncludeScriptsCache = {};
var __ctlCreatedIncludeScripts;
var __ctlAppendedScriptsCount;
var __ctlScriptsRestartHandlers = { };

function _ctlGetScriptCode(script) {
    var text = __ctlSafari ? script.firstChild.data : script.text;
    var comment = "<!--";
    var pos = text.indexOf(comment);
    if(pos > -1)
        text = text.substr(pos + comment.length);
    return text;
}
function _ctlAppendScript(script) {
    var parent = document.getElementsByTagName("head")[0];
    if(!_ctlIsExists(parent))
        parent = document.body;        
    if(_ctlIsExists(parent)) {
        parent.appendChild(script);
    }        
}

function _ctlIsAlphaFilterUsed(img){
    return (__ctlIE && img.style.filter.indexOf("progid:DXImageTransform.Microsoft.AlphaImageLoader") > -1);
}
function _ctlIsKnownIncludeScript(script) {
    return _ctlIsExists(__ctlIncludeScriptsCache[script.src]);
}
function _ctlCacheIncludeScript(script) {
    __ctlIncludeScriptsCache[script.src] = 1;
}


function _ctlGetStartupScripts() {
    return _ctlGetScriptsCore(__ctlStartupScriptPrefix);
}
function _ctlGetIncludeScripts() {
    return _ctlGetScriptsCore(__ctlIncludeScriptPrefix);
}
function _ctlGetScriptsCore(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 _ctlInitializeScripts() {
    var scripts = _ctlGetIncludeScripts();
    for(var i = 0; i < scripts.length; i++)
        _ctlCacheIncludeScript(scripts[i]);            
        
    scripts = _ctlGetStartupScripts();
    for(var i = 0; i < scripts.length; i++)
        scripts[i].executed = true;    
}
function _ctlProcessScripts() {
    __ctlCreatedIncludeScripts = [];
    __ctlAppendedScriptsCount = 0;
    
    var scripts = _ctlGetIncludeScripts();
    var immediate = false;
    var waitCount = 0;
    
    for(var i = 0; i < scripts.length; i++) {
        if(!_ctlIsKnownIncludeScript(scripts[i])) {
            waitCount++;
            var createdScript = document.createElement("script");
            __ctlCreatedIncludeScripts.push(createdScript);                       
            createdScript.type = "text/javascript";
            createdScript.src = scripts[i].src;                        
            
            if(__ctlIE) {                
                createdScript.onreadystatechange = _ctlOnScriptReadyStateChangedCallback;                
            } else {                
                if(__ctlNS)
                    createdScript.onload = _ctlOnScriptLoadCallback;
                else
                    immediate = true;
                _ctlAppendScript(createdScript);
                _ctlCacheIncludeScript(createdScript);
            }                                                                                                   
        }    
    }
    if(immediate || !waitCount)
       _ctlSetTimeout(_ctlFinalizeScriptProcessing, 1);        
}

function _ctlFinalizeScriptProcessing() {    
    var scripts = _ctlGetIncludeScripts();
    _ctlSweepDuplicateElements(scripts, "src");
    _ctlRunStartupScripts();
}

function _ctlRunStartupScripts() {
    var scripts = _ctlGetStartupScripts();
    var code;
    for(var i = 0; i < scripts.length; i++){
        if(!scripts[i].executed) {
            code = _ctlGetScriptCode(scripts[i]);                
            eval(code);
            scripts[i].executed = true;
        }
    }
    ctlGetControlCollection().InitializeElements();
    
    for(var key in __ctlScriptsRestartHandlers)
        __ctlScriptsRestartHandlers[key]();
}

function _ctlOnScriptReadyStateChangedCallback() {
    if(this.readyState == "loaded") {
        _ctlCacheIncludeScript(this);

        for(var i = 0; i < __ctlCreatedIncludeScripts.length; i++) {
            var script = __ctlCreatedIncludeScripts[i];
            if(_ctlIsKnownIncludeScript(script)) {
                if(!script.executed) {
                    script.executed = true;
                    _ctlAppendScript(script);
                    __ctlAppendedScriptsCount++;
                }
            } else
                break; 
        }    

        if(__ctlCreatedIncludeScripts.length == __ctlAppendedScriptsCount)
            _ctlFinalizeScriptProcessing();
    }    
}
function _ctlOnScriptLoadCallback() {
    __ctlAppendedScriptsCount++;
    if(__ctlCreatedIncludeScripts.length == __ctlAppendedScriptsCount)
        _ctlFinalizeScriptProcessing();
}

function _ctlAddScriptsRestartHandler(objectName, handler) {
    __ctlScriptsRestartHandlers[objectName] = handler;
}

function _ctlGetOffset(element, IsX) {
	var elementOffset = _ctlGetPositionElementOffset(element, IsX);
	return elementOffset != 0 ? elementOffset + _ctlGetIEDocumentClientOffset(IsX) : 0;
}
function _ctlGetRelevantX(element, parentElement) {
	if(!_ctlIsExists(parentElement))
		parentElement = element;
	return _ctlGetAbsoluteX(element) - _ctlGetOffset(parentElement, true);
}

function _ctlGetRelevantY(element, parentElement) {
	if(!_ctlIsExists(parentElement))
		parentElement = element;
	return _ctlGetAbsoluteY(element) - _ctlGetOffset(parentElement, false);
}