var __aspxCallBackSeparator = ":";
var __aspxItemIndexSeparator = "-";

// Debug 
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).toString();
			    if(value.indexOf("function") < 0)
				    array.push(" " + key + " = " + value);
		    }
		    catch(e){
		    }
		}
	}
	array.sort();
	return array.join("\t");
}
// Browsers
var __aspxAgent = navigator.userAgent.toLowerCase();
var __aspxOpera = (__aspxAgent.indexOf("opera") > -1);
var __aspxOpera9 = (__aspxAgent.indexOf("opera/9") > -1);
var __aspxSafari = __aspxAgent.indexOf("safari") > -1;
var __aspxIE55 = (__aspxAgent.indexOf("msie 5.5") > -1 && !__aspxOpera);
var __aspxIE = (__aspxAgent.indexOf("msie") > -1 && !__aspxOpera);
var __aspxNS = (__aspxAgent.indexOf("mozilla") > -1 || __aspxAgent.indexOf("netscape") > -1 || __aspxAgent.indexOf("firefox") > -1) && !__aspxSafari && !__aspxIE && !__aspxOpera;
// Array
function _aspxArrayPush(array, element){
    if(_aspxIsExists(array.push))
	    array.push(element);
    else	 
        array[array.length] = 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;
}
// Utils
function _aspxIsExists(obj){
	return (typeof(obj) != "undefined") && (obj != null);
}
function _aspxIsFunction(obj){
	return typeof(obj) == "function";
}

function _aspxGetElementById(id){
    if(_aspxIsExists(document.getElementById))
	    return document.getElementById(id);
	else
	    return document.all[id];
}
function _aspxGetParentNode(element){
	return element.parentNode;
}
function _aspxGetIsParent(parentElement, element){
	while(element != null){
		if(element.tagName == "BODY") return false;
		if(element == parentElement) return true;
		element = _aspxGetParentNode(element);
	}
	return false;
}
function _aspxGetParentById(element, id){
	element = _aspxGetParentNode(element);
	while(element != null){
		if(element.id == id) return element;
		element = _aspxGetParentNode(element);
	}
	return null;
}
function _aspxGetParentByTagName(element, tagName) {
    tagName = tagName.toUpperCase();
    while(element != null) {
        var name = element.tagName.toUpperCase();
        if(name == "BODY") return null;
        if(name == tagName) return element;
        element = _aspxGetParentNode(element);
    }
    return null;
}
function _aspxGetChildById(element, id){
	return __aspxIE ? element.all[id] : _aspxGetElementById(id);
}
function _aspxGetChildByTagName(element, tagName, index){
	if(element != null){		
		tagName = tagName.toUpperCase();
		var collection = (element.all) ? element.all.tags(tagName) : element.getElementsByTagName(tagName);
		if(collection != null){
			if(index < collection.length)
				return collection[index];
		}
	}
	return null;
}

function _aspxGetEventSource(evt){
    if(!_aspxIsExists(evt)) return null; 
	return __aspxIE ? evt.srcElement : evt.target;
}
function _aspxGetIsLeftButtonPressed(evt){
    if(!_aspxIsExists(evt)) return false;
	if(__aspxIE)
	    return evt.button == 1;
	else if(__aspxNS || __aspxSafari)
	    return evt.which == 1;
    return true;	    
}

function _aspxGetServerForm() {
    var form = _aspxIsExists(__dxServerFormID) ? document.forms[__dxServerFormID] : null;
    return (form != null) ? form : document.forms[0];
}
			
function _aspxDelCookie(name, value){
    _aspxSetCookieInternal(name, value, new Date(1999, 11, 31))
}
function _aspxSetCookie(name, value){
    var date = new Date();
    date.setFullYear(date.getFullYear() + 1);
    _aspxSetCookieInternal(name, value, date)
}
function _aspxSetCookieInternal(name, value, date){
    document.cookie = name + "=" + escape(value) + "; expires=" + date.toGMTString();
}

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 _aspxGetCurrentStyle(element){
    return __aspxIE ? element.currentStyle : window.getComputedStyle(element, null);
}
function _aspxGetStyleSheetRules(styleSheet){
    return __aspxIE ? styleSheet.rules : styleSheet.cssRules;
}

function _aspxGetAbsoluteX(curEl){
    return _aspxGetAbolutePosition(curEl, true);
}
function _aspxGetAbsoluteY(curEl){
    return _aspxGetAbolutePosition(curEl, false);
}
function _aspxGetAbolutePosition(curEl, isX){
    var pos = 0;
    while(curEl != null) {
        pos += isX ? curEl.offsetLeft : curEl.offsetTop;
        if(curEl.offsetParent != null) {
            pos -= isX ? curEl.scrollLeft : curEl.scrollTop;
        }
        curEl = curEl.offsetParent;
    }
    return pos;
}
function _aspxGetDocumentScrollTop(){
    return __aspxSafari || __aspxIE55 ? document.body.scrollTop : document.documentElement.scrollTop;
}
function _aspxGetDocumentScrollLeft(){
    return __aspxSafari || __aspxIE55 ? document.body.scrollLeft : document.documentElement.scrollLeft;
}
function _aspxGetDocumentClientWidth(){
    if(__aspxSafari || __aspxIE55 || document.documentElement.clientWidth == 0)
        return document.body.clientWidth;
    return document.documentElement.clientWidth;
}
function _aspxGetDocumentClientHeight(){
    if(__aspxSafari || __aspxIE55 || document.documentElement.clientHeight == 0)
        return document.body.clientHeight;
    return document.documentElement.clientHeight;
}

function _aspxAttachEventToElement(element, eventName, func) {
    if(__aspxNS || __aspxSafari)
        element.addEventListener(eventName, func, true);
    else {
        if(eventName.toLowerCase().indexOf("on") != 0) 
            eventName = "on"+eventName;
        element.attachEvent(eventName, func);
    }
}
function _aspxAttachEventToDocument(eventName, func) {
    _aspxAttachEventToElement(document, eventName, func);
}

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;
}
//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 != "") {
			if(_aspxIsSpecialTarget(target))
				_aspxNavigateSpecialTarget(url, target);
			else {
				var frame = _aspxGetFrame(top.frames, target);
				if(frame != null)
					frame.location.href = url; 
			}
		}
		else
		    location.href = url;
	}
}
function _aspxIsSpecialTarget(target) {
	var targets = ["_blank", "_media", "_parent", "_search", "_self", "_top"];
	return _aspxArrayIndexOf(targets, target.toLowerCase()) > -1;
}
function _aspxNavigateSpecialTarget(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 _aspxGetFrame(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;
}
// event
ASPxClientEvent = _aspxCreateClass(null, {
    constructor: function(){
	    this.handlerList = [];
	},
	AddHandler: function (handler) {
		_aspxArrayPush(this.handlerList, handler);
	},
	RemoveHandler: function (handler) {
	    _aspxArrayRemove(this.handlerList, handler);
	},
	ClearHandlers: function () {
	    _aspxArrayClear(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
ASPxClientCollection = _aspxCreateClass(null, {
    constructor: function(){
	    this.elements = new Object();
	},
	Initialize: function(){
	    for(var name in this.elements)
	        this.elements[name].Initialize();
	},
	
	Get: function (name){
	    return this.elements[name];
	},
	Add: function (element){
		this.elements[element.name] = element;
	}
});
// control
ASPxClientControl = _aspxCreateClass(null, {
    constructor: function(name){
        this.name = name;
        this.uniqueID = name;

        this.autoPostBack = false;
        this.callBack = null;
        
        this.mainElement = null;
        
        this.Init = new ASPxClientEvent();
        
        aspxGetControlCollection().Add(this);
    },
    Initialize: function(){
        if(this.callBack != null)
            this.InitializeCallBackData();
        if(_aspxIsExists(this.RaiseInit))
            this.RaiseInit();
    },
    InitializeCallBackData: function(){
    },
    
    GetMainElement: function(){
        if(this.mainElement == null)
            this.mainElement = _aspxGetElementById(this.name);
        return this.mainElement;
    },
    SendPostBack: function(params){
        __doPostBack(this.uniqueID, params);
    }
});

var __aspxControlCollection = null;
function aspxGetControlCollection(){
    if(__aspxControlCollection == null)
        __aspxControlCollection = new ASPxClientCollection();
    return __aspxControlCollection;
}

_aspxAttachEventToElement(window, "load", aspxClassesWindowOnLoad);
function aspxClassesWindowOnLoad(evt){
	aspxGetControlCollection().Initialize();
	__aspxAllowHotTrack = true;
}
//StyleController
var __aspxAllowHotTrack = false;

ASPxStyleItem = _aspxCreateClass(null, {
    constructor: function(name, className, postfixes){
        this.name = name;
        this.className = className;
        this.classNameAddon = " " + className + " ";
        this.postfixes = postfixes;
        
        this.prevClasses = [];
        this.prevLinkColors = [];
        this.prevLinkTextDecorations = [];
        this.elements = null;
        this.cssStyle = null;
    },    
    GetElements: function(element){
        if(this.elements == null){
            if(_aspxIsExists(this.postfixes)){
                this.elements = new Array();
                var parentNode = _aspxGetParentNode(element);
                if(parentNode != null){
                    for(var i = 0; i < this.postfixes.length; i++){
                        var id = this.name + this.postfixes[i];
                        this.elements[i] = _aspxGetChildById(parentNode, id);
                    }
                }
            }
            else
                this.elements = [element];
        }
        return this.elements;
    },
    GetCssStyle: function(){
        if(this.cssStyle == null){
            for(var i = 0; i < document.styleSheets.length; i ++){
                var styleSheet = document.styleSheets[i];
                var rules = _aspxGetStyleSheetRules(styleSheet);
                for(var j = 0; j < rules.length; j ++){
                    if(rules[j].selectorText == "." + this.className){
                        this.cssStyle = rules[j].style;
                        break;
                    }
                }
                if(this.cssStyle != null)
                    break;
            }
        }
        return this.cssStyle;
    },
    Apply: function(element){
        var elements = this.GetElements(element);
        for(var i = 0; i < elements.length; i++){
            if(elements[i] != null){
                this.prevClasses[i] = elements[i].className;
                elements[i].className = elements[i].className + this.classNameAddon;
                if(!__aspxOpera)
                    this.ApplyToLink(elements, i);
            }
        }
    },
    ApplyToLink: function(elements, index){
        var link = _aspxGetChildByTagName(elements[index], "A", 0);
        if(link != null && this.GetCssStyle() != null){
            if(this.GetCssStyle().color != ""){
                this.prevLinkColors[index] = link.style.color;
                link.style.color = this.GetCssStyle().color;
            }
            if(this.GetCssStyle().textDecoration != ""){
                this.prevLinkTextDecorations[index] = link.style.textDecoration;
                link.style.textDecoration = this.GetCssStyle().textDecoration;
            }
        }
    },
    Cancel: function(element){
        var elements = this.GetElements(element);
        for(var i = 0; i < elements.length; i++){
            if(elements[i] != null && _aspxIsExists(this.prevClasses[i])){
                elements[i].className = this.prevClasses[i];
                if(!__aspxOpera)
                    this.CancelFromLink(elements, i);
            }
        }
        this.prevClasses = [];
        this.prevLinkColors = [];
        this.prevLinkTextDecorations = [];
    },
    CancelFromLink: function(elements, index){
        var link = _aspxGetChildByTagName(elements[index], "A", 0);
        if(link != null){
            if(_aspxIsExists(this.prevLinkColors[index]))
                link.style.color = this.prevLinkColors[index];
            if(_aspxIsExists(this.prevLinkTextDecorations[index]))
                link.style.textDecoration = this.prevLinkTextDecorations[index];
        }                
    },
    Clone: function(){
        return new ASPxStyleItem(this.name, this.className, this.postfixes);
    }
});

ASPxClientHoverEventArgs = _aspxCreateClass(null, {
    constructor: function(item, element){
        this.item = item;
        this.element = element;
    }
});

ASPxStyleController = _aspxCreateClass(null, {
    constructor: function(){
        this.hoverItems = new Object();
        this.selectedItems = new Object();
        this.currentHoverElement = null;
        this.currentHoverItemName = null;
        
        this.AfterSetHoverState = new ASPxClientEvent();
        this.AfterClearHoverState = new ASPxClientEvent();
        this.BeforeSetHoverState = new ASPxClientEvent();
        this.BeforeClearHoverState = new ASPxClientEvent();
    },
    AddHoverItem: function(name, className, postfixes){
        this.AddItem(this.hoverItems, name, className, postfixes);
    },
    AddSelectedItem: function(name, className, postfixes){
        this.AddItem(this.selectedItems, name, className, postfixes);
    },
    AddItem: function(items, name, className, postfixes){
        if(_aspxIsExists(postfixes)){
            for(var i = 0; i < postfixes.length; i ++){
                var elementName = name + postfixes[i];
                items[elementName] = new ASPxStyleItem(name, className, postfixes);
            }
        }
        else
            items[name] = new ASPxStyleItem(name, className, postfixes);
    },
    GetHoverElement: function(element){
        return this.GetStyleItemElement(element, this.hoverItems);
    },
    GetSelectedElement: function(element){
        return this.GetStyleItemElement(element, this.selectedItems);
    },
    GetStyleItemElement: function(element, items){
        while(element != null) {
            if(_aspxIsExists(element.tagName) && element.tagName.toUpperCase() == "BODY") return null;
            if(_aspxIsExists(element.id) && (!__aspxIE || (_aspxIsExists(element.disabled) && !element.disabled))){
                var styleItem = items[element.id];
                if(_aspxIsExists(styleItem)){
                    element.styleItem = styleItem;
                    return element;
                }
            }
            element = _aspxGetParentNode(element);
        }
        return null;
    },
    
    DoSetHoverState: function(element){
        if(_aspxIsExists(element.styleItem)){
            var args = new ASPxClientHoverEventArgs(element.styleItem, element);
            this.BeforeSetHoverState.FireEvent(this, args);
            element.styleItem.Apply(element);
            this.AfterSetHoverState.FireEvent(this, args);
        }
    },
    DoClearHoverState: function(element){
        if(_aspxIsExists(element.styleItem)){
            var args = new ASPxClientHoverEventArgs(element.styleItem, element);
            this.BeforeClearHoverState.FireEvent(this, args);
            element.styleItem.Cancel(element);
            this.AfterClearHoverState.FireEvent(this, args);
        }
    },
    SetCurrentHoverElement: function(element){
        if(this.currentHoverElement != element){
            var hoverItemName = (element != null) ? element.styleItem.name : "";
            if(this.currentHoverItemName != hoverItemName){
                if(this.currentHoverElement != null)
                    this.DoClearHoverState(this.currentHoverElement);
                this.currentHoverElement = element;
                this.currentHoverItemName = (element != null) ? element.styleItem.name : "";
                if(this.currentHoverElement != null)
                    this.DoSetHoverState(this.currentHoverElement);
            }
        }
    },
    SetCurrentHoverElementBySrcElement: function(srcElement){
        var element = this.GetHoverElement(srcElement);
        this.SetCurrentHoverElement(element);
    },
    SelectElement: function(element){
        if(_aspxIsExists(element.styleItem))
            element.styleItem.Apply(element);
    },    
    SelectElementBySrcElement: function(srcElement){
        var element = this.GetSelectedElement(srcElement);
        if(element != null) this.SelectElement(element);
    },    
    DeselectElement: function(element){
        if(_aspxIsExists(element.styleItem))
            element.styleItem.Cancel(element);
    },    
    DeselectElementBySrcElement: function(srcElement){
        var element = this.GetSelectedElement(srcElement);
        if(element != null) this.DeselectElement(element);
    },
    OnMouseMove: function(evt){
        var srcElement = _aspxGetEventSource(evt);
        this.SetCurrentHoverElementBySrcElement(srcElement);
    }
});

var __aspxStyleController = null;
function aspxGetStyleController(){
    if(__aspxStyleController == null)
        __aspxStyleController = new ASPxStyleController();
    return __aspxStyleController;
}

function aspxAddHoverItem(name, className, postfixes){
    aspxGetStyleController().AddHoverItem(name, className, postfixes);
}
function aspxAddHoverClasses(namePrefix, classes){
    for(var i = 0; i < classes.length; i ++){
        for(var j = 0; j < classes[i][1].length; j ++)
            aspxAddHoverItem(namePrefix + "_" + classes[i][1][j], classes[i][0], classes[i][2])
    }
}
function aspxAddSelectedItem(name, className, postfixes){
    aspxGetStyleController().AddSelectedItem(name, className, postfixes);
}
function aspxAddSelectedClasses(namePrefix, classes){
    for(var i = 0; i < classes.length; i ++){
        for(var j = 0; j < classes[i][1].length; j ++)
            aspxAddSelectedItem(namePrefix + "_" + classes[i][1][j], classes[i][0], classes[i][2])
    }
}
function aspxAddAfterClearHoverState(handler){
    aspxGetStyleController().AfterClearHoverState.AddHandler(handler);
}
function aspxAddAfterSetHoverState(handler){
    aspxGetStyleController().AfterSetHoverState.AddHandler(handler);
}
function aspxAddBeforeClearHoverState(handler){
    aspxGetStyleController().BeforeClearHoverState.AddHandler(handler);
}
function aspxAddBeforeSetHoverState(handler){
    aspxGetStyleController().BeforeSetHoverState.AddHandler(handler);
}

_aspxAttachEventToDocument("mousemove", aspxClassesDocumentMouseMove);
function aspxClassesDocumentMouseMove(evt){
    if(__aspxAllowHotTrack)
	    aspxGetStyleController().OnMouseMove(evt);
}