﻿if(!window.c1_popup_loaded)
{
    //===Constants==============================
	var c1_dock_lefttop = 0;
	var c1_dock_leftbottom = 1;
	var c1_dock_topleft = 2;
	var c1_dock_topright = 3;
	var c1_dock_righttop = 4;
	var c1_dock_rightbottom = 5;
	var c1_dock_bottomleft = 6;
	var c1_dock_bottomright = 7;
	
	var c1_popup_state_collapsed = 0;
	var c1_popup_state_expanding = 1;
	var c1_popup_state_expanded = 2;
	var c1_popup_state_collapsing = 3;
	
	var c1_slidedirection_up = -1;
    var c1_slidedirection_down = -2;
	var c1_slidedirection_left = 1;
	var c1_slidedirection_right = 2;
	


    //===PopupSetting=====================
    function PopupSetting(owner)
    {
        this.Owner = owner;
        this.AutoCollapse = true;
        this.Dock = c1_dock_bottomright;
        this.State = c1_popup_state_collapsed;
        this.ShadowEnabled = true;
        this.ShadowOffset = 6;
        this.ShadowColor = 'Gray';
        this.Offset = 4;
        this.SlideDuration = 100;
        this.PopupState = c1_popup_state_collapsed;
        this.Width = 400;
        this.Height = 280;
        this.LayerIndex = 1999;
        this.IgnoreFirstUp = false;
        
        this.ExpandDuration = 300;
        this.CollapseDuration = 300;
        this.ExpandDirection = c1_slidedirection_down;
        this.CollapseDirection = c1_slidedirection_up;
        
        this.ExpandType = c1_slidetype_expaccelerate;
        this.CollapseType = c1_slidetype_expaccelerate;
        this.ExpandTransition = c1_transtype_none;
        this.CollapseTransition = c1_transtype_none;
    }
    
    PopupSetting.prototype.GetProperty=function(propName){ return this[propName]; };
    PopupSetting.prototype.SetProperty=function(propName,propValue) { this[propName]=propValue; };

    PopupSetting.prototype.CreateContainer = function(zIndex)
    {
        var body=(document.forms!=null&&document.forms[0]!=null
		                &&document.forms[0].parentNode!=null
		                &&document.forms[0].parentNode.tagName=='BODY')?
		                document.forms[0]:document.getElementsByTagName('BODY')[0];
    		
        var container = body.appendChild(document.createElement('div'));
        container.style.position = 'absolute';
	    container.style.zIndex = zIndex;
		container.style.left = '0px';
		container.style.top = '0px';
		container.style.visibility='hidden';
		container.style.backgroundColor = 'white';
		    
	    return container;
    }


    PopupSetting.prototype.Init = function() {

    var id = this.Owner.UniqueID+ "_pop";

        if (!this.FilterContainer) {
            this.FilterContainer = this.CreateContainer(this.LayerIndex);
            window[id] = this.FilterContainer;
        }

        if (this.Overlay == null && window.c1_browser_overlays) {
            this.OverlayContainer = this.CreateContainer(this.LayerIndex - 1);
            this.OverlayContainer.innerHTML = '<iframe style="visibility:hidden;filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)" scrolling="no" frameborder="0" src="javascript:false"></iframe>';
            this.Overlay = this.OverlayContainer.firstChild;
        };

        this.OverlayContainerStyle = this.OverlayContainer ? this.OverlayContainer.style : new Object();
        this.OverlayStyle = this.Overlay ? this.Overlay.style : new Object();

        if (this.CssClass)
            this.FilterContainer.className = this.CssClass;

        if (this.ShadowEnabled && c1_browser_shadows && c1_browser_filters) {
            var shadowFilter = 'progid:DXImageTransform.Microsoft.Shadow(color="' + this.ShadowColor + '",Direction=135,Strength=' + this.ShadowOffset + ')';
            this.FilterContainer.runtimeStyle.filter = this.FilterContainer.currentStyle.filter + ' ' + shadowFilter;
        }

        if (c1_browser_filters) {
            var transExpand = C1_GetTransitionString(this.ExpandTransition, this.ExpandTransitionCustomFilter);
            if (transExpand) {
                this.FilterContainer.ExpandTransitionIndex = this.FilterContainer.filters.length;
                this.FilterContainer.runtimeStyle.filter = this.FilterContainer.currentStyle.filter + ' ' + transExpand;
                this.FilterContainer.filters[this.FilterContainer.ExpandTransitionIndex].enabled = false;
            };

            var transCollapse = C1_GetTransitionString(this.CollapseTransition, this.CollapseTransitionCustomFilter);
            if (transCollapse) {
                this.FilterContainer.CollapseTransitionIndex = this.FilterContainer.filters.length;
                this.FilterContainer.runtimeStyle.filter = this.FilterContainer.currentStyle.filter + ' ' + transCollapse;
                this.FilterContainer.filters[this.FilterContainer.CollapseTransitionIndex].enabled = false;
            };
        }

        this.EffectiveShadowOffset = (this.ShadowEnabled && c1_browser_shadows && c1_browser_filters) ? this.ShadowOffset : 0;
    }
    
    PopupSetting.prototype.SetContent = function(content)
    {
        if (!this.FilterContainer)
            this.Init();
            
        content = '<div style="width:1px; height:1px">' + content + '</div>';
        this.FilterContainer.innerHTML = content;
        this.LayoutContainer = this.FilterContainer.firstChild;
        this.ContentElement = this.LayoutContainer.firstChild;
        
        if (c1_browser_ie)
        {
		    this.FilterContainerStyle=this.FilterContainer.runtimeStyle;
		    this.LayoutContainerStyle=this.LayoutContainer.runtimeStyle;
		    this.ContentElementStyle=this.ContentElement.runtimeStyle;
		}else
		{
			this.FilterContainerStyle=this.FilterContainer.style;
		    this.LayoutContainerStyle=this.LayoutContainer.style;
		    this.ContentElementStyle=this.ContentElement.style;
		}
        
        var borders = C1_GetElementBounds(this.ContentElement);
        this.LeftSpacing = borders[0];
        this.TopSpacing = borders[1];
        this.RightSpacing = borders[2];
        this.BottomSpacing = borders[3];
        
        if (this.Width)
            this.ContentElementStyle.width = this.Width + 'px';

        if (this.Height)
            this.ContentElementStyle.height = this.Height + 'px';
		
        this.ContentWidth = this.ContentElement.offsetWidth;
        this.ContentHeight = this.ContentElement.offsetHeight;
        
        this.LayoutContainerStyle.width = this.ContentWidth;
        this.LayoutContainerStyle.height = this.ContentHeight;
        
        if(c1_browser_backcompat)
		{
			this.ContentWidth+=this.LeftSpacing+this.RightSpacing;
			this.ContentHeight+=this.TopSpacing+this.BottomSpacing;
		};
    }
    
    PopupSetting.prototype.RemoveContent = function()
    {
        if (this.FilterContainer)
            this.FilterContainer.innerHTML = '';
    }
    
    PopupSetting.prototype.ExpandStart = function()
	{
	    this.EffectiveShadowOffset = (this.ShadowEnabled && c1_browser_shadows && c1_browser_filters) ? this.ShadowOffset : 0;
	    
		this.FilterContainer.onfilterchange=null;
		clearInterval(this.SlideTimerID);
		
		this.OverlayStyle.overflow = this.FilterContainerStyle.overflow='hidden';
		this.OverlayStyle.visibility = this.FilterContainerStyle.visibility='hidden';
		this.OverlayStyle.position = this.FilterContainerStyle.position='absolute';
		//this.FilterContainerStyle.zIndex=2000;
   	    this.OverlayStyle.left = this.FilterContainerStyle.left = this._x+'px';
	    this.OverlayStyle.top = this.FilterContainerStyle.top = this._y+'px';
	    this.FilterContainerStyle.width = this.ContentWidth + 'px';
	    this.FilterContainerStyle.height = this.ContentHeight + 'px';

		this.LayoutContainerStyle.position='static';
		this.LayoutContainerStyle.top='0px';
		this.LayoutContainerStyle.left='0px';			
		
		this.PopupState=c1_popup_state_expanding;
		if(this.StateChangeEvent!=null)
		{
			this.StateChangeEvent(this);
		};
		
		var expandTransition=(this.FilterContainer.ExpandTransitionIndex!=null)?this.FilterContainer.filters[this.FilterContainer.ExpandTransitionIndex]:null;
		var collapseTransition=(this.FilterContainer.CollapseTransitionIndex!=null)?this.FilterContainer.filters[this.FilterContainer.CollapseTransitionIndex]:null;

		if(this.ExpandDuration>0&&(expandTransition!=null||this.ExpandType!=c1_slidetype_none))
		{
			if(expandTransition)
			{
				if(collapseTransition){collapseTransition.stop();};
			    
			    this.FilterContainer.popObj = this;
				this.FilterContainer.onfilterchange=this.OnFilterChange;
				expandTransition.apply();
				
				this.FilterContainerStyle.visibility=this.OverlayStyle.visibility='visible';
				expandTransition.play(this.ExpandDuration/1000);
			};
			
			if(this.ExpandType!=c1_slidetype_none)
			{
				this.FilterContainer.onfilterchange=null;
				this.FilterContainerStyle.visibility = this.OverlayStyle.visibility = 'visible';
				this.SlideStartTime=new Date().getTime();
				var slideStepCommand=this.Id+'.ExpandStep()';
				eval(slideStepCommand);
				this.SlideTimerID=setInterval(slideStepCommand,this.SlideDuration);
			};
		}else
		{
			this.FilterContainerStyle.position = this.OverlayStyle.position = 'absolute';
			this.FilterContainerStyle.left=this.OverlayStyle.left=this._x+'px';
			this.FilterContainerStyle.top=this.OverlayStyle.top=this._y+'px';
			this.FilterContainerStyle.visibility=this.OverlayStyle.visibility='visible';
		};
	}; 
	
	PopupSetting.prototype.ExpandStep = function()
	{
		var duration=new Date().getTime()-this.SlideStartTime;
		if(duration>this.ExpandDuration)
		{
			clearInterval(this.SlideTimerID);
			this.ExpandEnd();
			return;
		};
		
		var ratio = window.C1_CalcVisibleRatio(duration, this.ExpandDuration, this.ExpandType);
		var fullSize = (this.ExpandDirection < 0 ? this.ContentHeight : this.ContentWidth);
		var visibleSize = Math.max(Math.ceil(ratio * fullSize), 1); 
		
		if (this.ExpandDirection < 0)
		{
		    this.FilterContainerStyle.height=visibleSize+'px';
		    this.OverlayStyle.height=(c1_browser_backcompat?0:this.TopSpacing+this.BottomSpacing)+visibleSize+this.EffectiveShadowOffset+'px';
	    
	        if (this.ExpandDirection == c1_slidedirection_up)
	        {
	            this.OverlayStyle.top = this.FilterContainerStyle.top=this._y+this.ContentHeight-visibleSize+'px';
	        }else
	        {
	            this.LayoutContainerStyle.top=visibleSize-this.ContentHeight+'px';
	        }
		}else
		{
			this.FilterContainerStyle.width=visibleSize+'px';
			this.OverlayStyle.width=(c1_browser_backcompat?0:this.LeftSpacing+this.RightSpacing)+visibleSize+this.EffectiveShadowOffset+'px';
			
			if (this.ExpandDirection == c1_slidedirection_left)
			{
			    this.OverlayStyle.left = this.FilterContainerStyle.left=this._x+this.ContentWidth-visibleSize+'px';
			}else
			{
		        this.LayoutContainerStyle.left=visibleSize-this.ContentWidth+'px';
		    }
		}
	};
	
	PopupSetting.prototype.ExpandEnd = function()
	{
	    this.LayoutContainerStyle.left='0px';
		this.LayoutContainerStyle.top='0px';
		this.LayoutContainerStyle.width=(this.ContentWidth-this.LeftSpacing - this.RightSpacing)+'px';
		this.LayoutContainerStyle.height=(this.ContentHeight-this.TopSpacing - this.BottomSpacing)+'px';
		this.LayoutContainerStyle.position='relative';
		
	    this.FilterContainerStyle.left=this._x + 'px';
	    this.FilterContainerStyle.top=this._y + 'px';
	    this.FilterContainerStyle.width=Math.max(this.ContentWidth, 1)+'px';
	    this.OverlayStyle.width=(c1_browser_backcompat?0:this.LeftSpacing+this.RightSpacing)+this.ContentWidth+this.EffectiveShadowOffset+'px';
	    this.FilterContainerStyle.height=Math.max(this.ContentHeight, 1)+'px';
	    this.OverlayStyle.height=(c1_browser_backcompat?0:this.TopSpacing+this.BottomSpacing)+this.ContentHeight+this.EffectiveShadowOffset+'px';
		this.FilterContainerStyle.overflow = 'visible';
		
		this.PopupState=c1_popup_state_expanded;
		if(this.StateChangeEvent!=null)
		{
			this.StateChangeEvent(this);
		};
	};

	PopupSetting.prototype.CollapseStart = function() {
	    this.FilterContainer.onfilterchange = null;
	    clearInterval(this.SlideTimerID);

	    this.OverlayStyle.overflow = this.FilterContainerStyle.overflow = 'hidden';
	    this.OverlayStyle.visibility = this.FilterContainerStyle.visibility = 'hidden';
	    this.OverlayStyle.position = this.FilterContainerStyle.position = 'absolute';

	    this.OverlayStyle.left = this.FilterContainerStyle.left = this._x + 'px';
	    this.OverlayStyle.top = this.FilterContainerStyle.top = this._y + 'px';
	    this.OverlayStyle.position = this.LayoutContainerStyle.position = 'relative';

	    this.LayoutContainerStyle.position = 'static';
	    this.LayoutContainerStyle.top = '0px';
	    this.LayoutContainerStyle.left = '0px';

	    this.PopupState = c1_popup_state_collapsing;
	    if (this.StateChangeEvent != null) {
	        this.StateChangeEvent(this);
	    };

	    var expandTransition = (this.FilterContainer.ExpandTransitionIndex != null) ? this.FilterContainer.filters[this.FilterContainer.ExpandTransitionIndex] : null;
	    var collapseTransition = (this.FilterContainer.CollapseTransitionIndex != null) ? this.FilterContainer.filters[this.FilterContainer.CollapseTransitionIndex] : null;

	    if (this.CollapseDuration > 0 && (collapseTransition != null || this.CollapseType != c1_slidetype_none)) {
	        if (collapseTransition) {
	            if (expandTransition) {
	                expandTransition.stop();
	                expandTransition.enabled = false;
	            };

	            this.FilterContainer.popObj = this;
	            this.FilterContainer.onfilterchange = this.OnFilterChange;
	            collapseTransition.apply();

	            this.FilterContainerStyle.visibility = this.OverlayStyle.visibility = 'visible';
	            collapseTransition.play(this.CollapseDuration / 1000);
	        };

	        if (this.CollapseType != c1_slidetype_none) {
	            this.FilterContainer.onfilterchange = null;
	            this.OverlayStyle.visibility = this.FilterContainerStyle.visibility = 'visible';
	            this.SlideStartTime = new Date().getTime();
	            var slideStepCommand = this.Id + '.CollapseStep()';
	            eval(slideStepCommand);
	            this.SlideTimerID = setInterval(slideStepCommand, this.SlideDuration);
	            var timerid = this.Owner.UniqueID + "_timer";
	            window[timerid] = this.SlideTimerID;
	        };
	    } else {
	        this.OverlayStyle.visibility = this.FilterContainerStyle.visibility = 'hidden';
	    };
	};

	PopupSetting.prototype.CollapseStep = function() {
	    var duration = new Date().getTime() - this.SlideStartTime;
	    if (duration > this.CollapseDuration) {
	        clearInterval(this.SlideTimerID);
	        this.CollapseEnd();
	        return;
	    };

	    if (!this.FilterContainer) {
	        var popid = this.Owner.UniqueID + "_pop";
	        if (window[popid]) {
	            window[popid].parentNode.removeChild(window[popid]);
	            window[popid] = null;
	        }

	        var timerid = this.Owner.UniqueID + "_timer";
	        if (window[timerid])
	            clearInterval(window[timerid]);

	        return;
	    }

	    var ratio = 1 - window.C1_CalcVisibleRatio(duration, this.CollapseDuration, this.CollapseType);
	    var fullSize = (this.CollapseDirection < 0 ? this.ContentHeight : this.ContentWidth);
	    var visibleSize = Math.ceil(ratio * fullSize);

	    if (this.CollapseDirection < 0) {
	        this.FilterContainerStyle.height = visibleSize + 'px';
	        this.OverlayStyle.height = (c1_browser_backcompat ? 0 : this.TopSpacing + this.BottomSpacing) + visibleSize + this.EffectiveShadowOffset + 'px';

	        if (this.CollapseDirection == c1_slidedirection_down) {
	            this.OverlayStyle.top = this.FilterContainerStyle.top = this._y + this.ContentHeight - visibleSize + 'px';
	            this.LayoutContainerStyle.top = visibleSize - this.ContentHeight + 'px';
	        }
	    } else {
	        this.FilterContainerStyle.width = visibleSize + 'px';
	        this.OverlayStyle.width = (c1_browser_backcompat ? 0 : this.LeftSpacing + this.RightSpacing) + visibleSize + this.EffectiveShadowOffset + 'px';

	        if (this.CollapseDirection == c1_slidedirection_right) {
	            this.OverlayStyle.left = this.FilterContainerStyle.left = this._x + this.ContentWidth - visibleSize + 'px';
	            this.LayoutContainerStyle.left = visibleSize - this.ContentWidth + 'px';
	        }
	    }
	};
	
	PopupSetting.prototype.CollapseEnd = function()
	{
		this.OverlayStyle.visibility=this.FilterContainerStyle.visibility='hidden';
		
		this.PopupState=c1_popup_state_collapsed;
		if(this.StateChangeEvent!=null)
		{
			this.StateChangeEvent(this);
		};
	};
	
	PopupSetting.prototype.OnFilterChange = function()
	{
	    if (this.popObj != null)
	    {
	        if (this.popObj.PopupState == c1_popup_state_collapsing)
	        {
	            if (this.popObj.FilterContainer.filters[this.popObj.FilterContainer.CollapseTransitionIndex].status==0)
	            {
	                this.popObj.CollapseEnd();
	            }
	        }else
	        {
	            if (this.popObj.PopupState == c1_popup_state_expanding)
	            {
	                if (this.popObj.FilterContainer.filters[this.popObj.FilterContainer.ExpandTransitionIndex].status==0)
	                {
	                    this.popObj.ExpandEnd();
	                }
	            }
	        }
	    }
	}
	
	PopupSetting.prototype.IsShowing = function()
	{
	    return (this.PopupState != c1_popup_state_collapsed)
	}
    
    PopupSetting.prototype.ShowBeside = function(dockElement, dockType)
    {
        var x = 0;
        var y = 0;

        if (dockElement)
        {
			var dockX = C1_GetPageOffsetLeft(dockElement);
			var dockY = C1_GetPageOffsetTop(dockElement);
			
			var dockWidth = dockElement.offsetWidth;
			var dockHeight = dockElement.offsetHeight;
			
			var ieStandards=c1_browser_ie&&c1_browser_css1compat;
			var docElement=ieStandards?document.documentElement:document.body;
			var operaOrMozilla=c1_browser_opera||c1_browser_mozilla;
			var pageScrollLeft=operaOrMozilla?window.pageXOffset:docElement.scrollLeft;
			var pageScrollTop=operaOrMozilla?window.pageYOffset:docElement.scrollTop;
			var pageRight=pageScrollLeft+(operaOrMozilla?window.innerWidth:docElement.clientWidth);
			var pageBottom=pageScrollTop+(operaOrMozilla?window.innerHeight:docElement.clientHeight);
			
	        var points = [];
            points[points.length] = [dockX - this.ContentWidth - this.Offset, dockY];
            points[points.length] = [dockX - this.ContentWidth - this.Offset, dockY + dockHeight - this.ContentHeight];
            points[points.length] = [dockX, dockY - this.ContentHeight - this.Offset];
            points[points.length] = [dockX + dockWidth - this.ContentWidth, dockY - this.ContentHeight- this.Offset];
            points[points.length] = [dockX + dockWidth + this.Offset, dockY];
            points[points.length] = [dockX + dockWidth + this.Offset, dockY + dockHeight - this.ContentHeight];
            points[points.length] = [dockX, dockY + dockHeight + this.Offset];
            points[points.length] = [dockX + dockWidth - this.ContentWidth, dockY + dockHeight + this.Offset ];
            
            var dock = this.Dock;
            if (dockType != undefined)
                dock = dockType;
            
            x = points[dock][0];
            y = points[dock][1];
            
            if (dock == c1_dock_lefttop || dock == c1_dock_leftbottom || dock == c1_dock_righttop || dock == c1_dock_rightbottom)
            {
			    if (( x < pageScrollLeft) || ( x + this.ContentWidth > pageRight))
			    {
			        dock = (dock + 4) % 8;

                    x = points[dock][0];
                    y = points[dock][1];
			    }
            }else
            {
			    if (( y < pageScrollTop) || ( y + this.ContentHeight > pageBottom))
			    {
			        dock = (dock + 4) % 8;

                    x = points[dock][0];
                    y = points[dock][1];
			    }
			}
	
			x = (x < pageScrollLeft) ? pageScrollLeft : x;
			if (x + this.ContentWidth > pageRight)
			    x = pageRight - this.ContentWidth;
			    
		    y = (y < pageScrollTop) ? pageScrollTop : y;
			if (y + this.ContentHeight > pageBottom)
			    y = pageBottom - this.ContentHeight;
        }
        
        this.ShowAt(x, y);
    }
    
    PopupSetting.prototype.ShowAt = function(x, y)
    {
        if (this.OnBeforePopup != null)
	    {
	        if (!this.OnBeforePopup(this))
	            return;
	    }
	    
	    var e = this.GetMouseEvent();
   
	    if (e != null && (e.type=="mouseup" || e.type=="mousedown"))
	        this.IgnoreFirstUp = true;
	        
        this._x = x;
        this._y = y;
        
	    switch(this.PopupState)
		{
			case c1_popup_state_expanding:
			case c1_popup_state_expanded:
				return;
			case c1_popup_state_collapsing:
				this.CollapseEnd();
			case c1_popup_state_collapsed:
				this.ExpandStart();
		};
		
		if (this.AutoCollapse)
		    this.HookEvents();
		    
		if (this.OnAfterPopup != null)
		    this.OnAfterPopup(this);
    }

    PopupSetting.prototype.Hide = function() {
        if (this.OnBeforeClose != null) {
            if (!this.OnBeforeClose(this))
                return;
        }

        this.UnHookEvents();

        switch (this.PopupState) {
            case c1_popup_state_collapsing:
            case c1_popup_state_collapsed:
                return;

            case c1_popup_state_expanding:
                this.ExpandEnd();
            case c1_popup_state_expanded:
                this.CollapseStart();
        };

        if (this.OnAfterClose != null)
            this.OnAfterClose(this);

        this.RemoveContent();
    };
	
	PopupSetting.prototype.GetMouseEvent=function()
    {
	    //IE
	    if(document.all)
		    return window.event;
    		
	    var func=this.GetMouseEvent.caller;
	    while(func!=null)
	    {
		    var arg0=func.arguments[0];
		    if(arg0)
		    {
			    if(arg0.constructor==MouseEvent)
				    return arg0;
		    }
		    func=func.caller;
	    }
	    return null;
    }

	
    PopupSetting.prototype.OnDocumentMouseUp = function(e)
    {
	    if(!e){e=window.event;};
	    
	    if (this.IgnoreFirstUp)
	    {
	        this.IgnoreFirstUp = false;
	        return;
	    }

	    var srcElement=e["target"]?e["target"]:e.srcElement;
	    
	    if (this.IsShowing() && this.AutoCollapse)
	    {
	        if (!window.C1_ElementContains(this.FilterContainer, srcElement))
	        {
	            this.Hide();
	        }
	    }
    };
	
    PopupSetting.prototype.HookEvents = function()
    {
        this.DocumentMouseUpHandler=new Function('event', this.Id + '.OnDocumentMouseUp(event)');
        window.C1_AddEventHandler(document,'mouseup',this.DocumentMouseUpHandler);
    }
    
    PopupSetting.prototype.UnHookEvents = function()
    {
        if (this.DocumentMouseUpHandler != null)
        {
            window.C1_RemoveEventHandler(document,'mouseup',this.DocumentMouseUpHandler);
            this.DocumentMouseUpHandler = null;
        }
    }


    window.c1_popup_loaded=true;
}


if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();