﻿Type.registerNamespace('Infragistics.Web.UI');



$IG.DialogWindowProps = new function()
{
    var count = $IG.LayoutControlProps.Count;
    this.WindowState = [count++, 0];
    this.Left = [count++, ''];
    this.Top = [count++, ''];
    this.Width = [count++, ''];
    this.Height = [count++, ''];
    this.InitialLocation = [count++, 0];
    this.Moveable = [count++, 1];
    this.MaintainLocationOnScroll = [count++, 0];
    this.Modal = [count++, 0];
    this.AsyncUpdate = [count++, 1];
    this.LastWindowState = [count++, 0];
    this.Count = count;
};

$IG.HeaderProps = new function()
{
    var count = $IG.ControlObjectProps.Count;
    this.CaptionText = [count++, ''];
    this.ImageUrl = [count++, ''];
    this.MinimizedWidth = [count++, 100];
    this.Count = count;
};



$IG.DialogWindowState = function () {}
$IG.DialogWindowState.prototype = 
{
   Normal:0, 
   Minimized:1,
   Maximized:2,
   Hidden:3
};
$IG.DialogWindowState.registerEnum("Infragistics.Web.UI.DialogWindowState");




$IG.WebDialogWindow = function(elem)
{
	/// <summary>Class which implements client side functionality of WebDialogWindow.</summary>
	/// <param name="elem" type="Object">Reference to html element.</param>
	$IG.WebDialogWindow.initializeBase(this, [elem]);
}

$IG.WebDialogWindow.prototype =
{
	_thisType:'dialog',

	
	_responseComplete:function(cb, response)
	{
		
		var cont = response ? response.context : null;
		if(!cont || cont.length < 2)
			return;
		
		var div = document.createElement('DIV');
		div.innerHTML = cont[1];
		var id = this.get_id(), name = this.get_name(), i = div.childNodes.length;
		while(i-- > 0)
		{
			var node = div.childNodes[i];
			
			if(node.id == id)
			{
				
				var body = this._get_asyncUpdate() ? null : this._findBody(node);
				if(body)
				{
					var elem, old = null, elems = body.childNodes;
					i = elems ? elems.length : 0;
					
					if(i != 1 || elems[0].nodeName != 'IFRAME')
					{
						
						while(i-- > 0)
							body.removeChild(elems[i]);
						elems = this._body2.childNodes;
						i = elems.length;
						
						while(i-- > 0)
						{
							this._body2.removeChild(elem = elems[i]);
							body.insertBefore(elem, old);
							old = elem;
						}
					}
				}
				
				this._element.swapNode(node);
				break;   
			}
		}
		
		this.dispose();
		$create($IG.WebDialogWindow, {'id':id, 'name':name, 'props':eval(cont[0])}, null, null, $get(id));
	},
	
	_findBody:function(elem)
	{
		if(elem.id && elem.id.indexOf(':mkr:16') > 0)
			return elem;
		var elems = elem.childNodes;
		var i = elems ? elems.length : 0;
		while(i-- > 0)
			if((elem = this._findBody(elems[i])) != null)
				return elem;
		return null;
	},
	
	initialize:function()
	{
		/// <summary>Initializes instance of WebDialogWindow.</summary>
		$IG.WebDialogWindow.callBaseMethod(this, 'initialize');
		
		
		
		this._body2 = this._elements[16];
		this._ie = Sys.Browser.agent == Sys.Browser.InternetExplorer;
		this._safari = Sys.Browser.agent === Sys.Browser.Safari;
		
		this._suspendVis = this._isVis();
		this._modalCss = this._get_clientOnlyValue("mbc");
		if(this._contentPane)
			this._contentPane._DIV = this._body2;
		if(this._onTimer(true))
			delete this._onTimer;
		else
			ig_ui_timer(this);				
	},
	
	_get_modal:function(){return this._get_value($IG.DialogWindowProps.Modal);},
	_get_asyncUpdate:function(){return this._get_value($IG.DialogWindowProps.AsyncUpdate);},
	get_enabled:function()
	{
		/// <summary>Checks if control is enabled.</summary>
		/// <returns type="Boolean">Value of true means that dialog is enabled.</returns>
		return this._getFlags().getEnabled();
	},
	
	_isVis:function(){return this._element ? this._element.style.display != 'none' : false;},
	
	_setVis:function(show)
	{
		var elem = this._element;
		
		if(!this._suspendVis || !show || !elem)
			$util.display(elem, !show);
		else
			elem.style.display = '';
	},
	_onTimer:function(init, play)
	{
		if(this._painted)
			return true;		
		var elem = this._element;
		var width = elem ? elem.offsetWidth : 0;
		if(width == 0)
			return false;
		this._painted = true;		
		if(!this._header)
			this._header = new $IG.Header(null, null, null, this);
		
		
		
		
		
		
		
		this._header._init(this._elements, elem);		
		var rp = this._get_clientOnlyValue('rp');
		if(rp && rp.length > 1)
		{
			rp = this._resizer = $create($IG.ResizeBehavior,{'pairs':rp,'id':this.get_id()+'.r','control':this},null,null,elem);
			rp._prefix = 'Resizer';
			if(rp.get_minimumWidth() == 0)
				rp.set_minimumWidth(this._header._minWidth);
			if(rp.get_minimumHeight() == 0)
				rp.set_minimumHeight(this._header.get_height() + (this._elements[15] ? 25 : 15));
		}
		else if(!this._get_isMinimized() && !this._get_isMaximized() && !this._get_isClosed())
			this.onResize(2, null, play);
		//
		this._headerMoveable(true);
		if(!this._get_isClosed())
			this.set_windowState(this.get_windowState())
		
		if(this._suspendVis && this._isVis())
			this._element.style.visibility = 'visible';
		
		this._suspendVis = false;
		this._inModal = false;
		this._ready = true;				
		if(this._thisType == 'dialog')
			this._raiseClientEvent('Initialize');
		return true;			
	},
	_play:function()
	{
		
	},

	_addHandlers:function() 
	{
		$IG.WebDialogWindow.callBaseMethod(this, '_addHandlers');
	},

	_createObject:function(element, obj)
	{
		if(obj == 'header')
		{
			this._header = new $IG.Header(obj, element, this._objectsManager.get_objectProps(0), this);
			this._objectsManager.register_object(0, this._header);
		}
		if(obj == 'body')
		{
			this._body = element;
			this._contentPane = new $IG.LayoutPane(obj, element, this._objectsManager.get_objectProps(1), this);
			this._objectsManager.register_object(1, this._contentPane);
		}
	},
	
	get_contentPane:function()
	{
		/// <summary>Gets reference to content pane.</summary>
		/// <returns type="Infragistics.Web.UI.LayoutPane">Reference to pane.</returns>
		return this._contentPane;
	},
	
	_get_resizeAreaElem:function()
	{
	    var pane = this.get_contentPane();
	    if(pane != null)
	        return pane._DIV;
	
	}, 
	
	get_header:function()
	{
		/// <summary>Gets reference to header.</summary>
		/// <returns type="Infragistics.Web.UI.Header" mayBeNull="true">Reference to header.</returns>
		return this._ready ? this._header : null;
	},

	
	get_resizer:function()
	{
		/// <summary>Gets reference to resizer if resizing is enabled.</summary>
		/// <returns type="Infragistics.Web.UI.ResizeBehavior" mayBeNull="true">Reference to resizer.</returns>
		return this._resizer;
	},
	
	
	canResize:function()
	{
		/// <summary>Checks if control can be resized.</summary>
		/// <returns type="Boolean">True: dialog in normal state and it can be resized.</returns>
		return (this.get_windowState() == $IG.DialogWindowState.Normal)
	},	
	
	set_initialLocation:function(val)
	{
		/// <summary>Sets initial location of WebDialogWindow relative to window of browser.</summary>
		/// <param name="val" type="Number">Value of 0 means manual, value of 1 means centered.</param>
		this._set_value($IG.DialogWindowProps.InitialLocation, val);
		if(val == 1 && this._painted && this._header._mover &&  !this._get_isMaximized())
			this._header._mover.setAbsPos(this.get_left(), this.get_top(), true, this.get_maintainLocationOnScroll(), this._get_modal());
	},
	get_initialLocation:function()
	{ 
		/// <summary>Gets the initial location of WebDialogWindow relative to window of browser.</summary>
		/// <returns type="Number">Value of 0 means manual, value of 1 means centered.</returns>
		return this._get_value($IG.DialogWindowProps.InitialLocation);
	},

	set_moveable:function(value)
	{
		/// <summary>Sets the ability to drag control by mouse.</summary>
		/// <param name="value" type="Boolean">True: dialog can be moved by mouse.</param>
		this._set_value($IG.DialogWindowProps.Moveable, value);
		this._headerMoveable(value);
	},
	get_moveable:function()
	{ 
		/// <summary>Gets/sets the ability to drag control by mouse.</summary>
		/// <returns type="Boolean">True: dialog can be moved by mouse.</returns>
		return this._get_value($IG.DialogWindowProps.Moveable, true) && this.get_enabled();
	},

	set_maintainLocationOnScroll:function(value)
	{
		/// <summary>Sets the ability to keep relative location of dialog while window is resized or scrolled.</summary>
		/// <param name="value" type="Boolean">True: location of dialog is kept relative while scroll.</param>
		this._set_value($IG.DialogWindowProps.MaintainLocationOnScroll, value);
		this._headerMoveable(value);
	},
	get_maintainLocationOnScroll:function()
	{ 
		/// <summary>Gets the ability to keep relative location of dialog while window is resized or scrolled.</summary>
		/// <returns type="Boolean">True: location of dialog is kept relative while scroll.</returns>
		return this._get_value($IG.DialogWindowProps.MaintainLocationOnScroll) == 1;
	},

	get_width:function()
	{
		/// <summary>Gets width of dialog.</summary>
		/// <returns type="String">Width of dialog.</returns>
		return this._get_value($IG.DialogWindowProps.Width);
	},
	set_width:function(val)
	{
		/// <summary>Sets width of dialog.</summary>
		/// <param name="val" type="String">Width of dialog as pixels or percents.</param>
		this.setSize(val);
	},
	get_height:function()
	{
		/// <summary>Gets height of dialog.</summary>
		/// <returns type="String">Height of dialog.</returns>
		return this._get_value($IG.DialogWindowProps.Height);
	},
	set_height:function(val)
	{
		/// <summary>Sets height of dialog.</summary>
		/// <param name="val" type="String">Height of dialog as pixels or percents.</param>
		this.setSize(null, val);
	},
	setSize:function(width, height, evt)
	{
		/// <summary>Sets width and height of dialog.</summary>
		/// <param name="height" type="String" optional="true" mayBeNull="true">Height of dialog as pixels or percents.</param>
		/// <param name="width" type="String" optional="true" mayBeNull="true">Width of dialog as pixels or percents.</param>
		/// <param name="evt" type="Object" optional="true" mayBeNull="true">Request to do not adjust appearance.</param>
		if(width)
			this._set_value($IG.DialogWindowProps.Width, width);
		if(height)
			this._set_value($IG.DialogWindowProps.Height, height);
		if(evt)
			return;
		var elem = this._element;
		if(width)
			elem.style.width = width;
		if(height)
			elem.style.height = height;
		if(!this._painted)
			return;
		if(this._resizer)
			this._resizer.setSize(elem.offsetWidth, elem.offsetHeight);
		else
			this.onResize();
		if(this._header._mover)
			this._header._mover._onScrollSize();
	},
	get_left:function()
	{
		/// <summary>Gets left edge of dialog.</summary>
		/// <returns type="String">Left edge of dialog.</returns>
		return this._get_value($IG.DialogWindowProps.Left);
	},
	set_left:function(val, mouse)
	{
		/// <summary>Sets left edge of dialog.</summary>
		/// <param name="val" type="String">Left edge of dialog.</param>
		/// <param name="mouse" type="Boolean" optional="true" mayBeNull="true">Request to do not adjust appearance.</param>
		this._set_value($IG.DialogWindowProps.Left, val);
		if(!mouse)
			this._element.style.left = val;
	},
	get_top:function()
	{
		/// <summary>Gets top edge of dialog.</summary>
		/// <returns type="String">Top edge of dialog.</returns>
		return this._get_value($IG.DialogWindowProps.Top);
	},
	set_top:function(val, mouse)
	{
		/// <summary>Sets top edge of dialog.</summary>
		/// <param name="val" type="String">Top edge of dialog.</param>
		/// <param name="mouse" type="Boolean" optional="true" mayBeNull="true">Request to do not adjust appearance.</param>
		this._set_value($IG.DialogWindowProps.Top, val);
		if(!mouse)
			this._element.style.top = val;
	},

	
	
	onResize:function(e, height, play)
	{
		/// <summary>Implementation of IResizable. Internal use only.</summary>
		/// <param name="e">Internal use.</param>
		/// <param name="height">Internal use.</param>
		/// <param name="play">Internal use.</param>
		var body = this._body, elem = this._element;
		if(!body || !elem)
			return;
		var v, dif, width, style = elem.style;
		
		
		if(height)
		{
			style.width = e;
			style.height = height;
			e = null;
		}
		if(e == 2 && this._clientWidth != null)
			return;
		height = elem.offsetHeight;
		if(height == 0)
			return;
		
		if(e)
			this.setSize(style.width, style.height, true);
		var fire = this._shift1h == null;
		
		if(fire)
		{
			this._ready = true;
			style = $util.getRuntimeStyle(elem);
			
			this._shift1w = $util.getOffset(style, true);
			this._shift1h = $util.getOffset(style);
			this._shift2h = this._shift2w = 0;
			
			
			var i = 9, elems = this._elements;
			while(++i < 16)
			{
				style = $util.getRuntimeStyle(elem = this._elements[i]);
				
				if(i == 11)
				{
					this._bodyTD = elem;
					continue;
				}
				if(!style)
					continue;
				elem.style.margin = '0px';
				
				if(i == 10 || i == 12)
				{
					v = $util.toIntPX(style, 'width');
					
//					elem.style.width = elems[i + 3].style.width = v + 'px';
					this._shift2w += v;
					this._shift2w += $util.getOffset(style, true);
				}
				
				if(i == 13)
				{
					v = $util.toIntPX(style, 'height');
					if(v < 5 && this._safari)
						v = elem.offsetHeight;
					
//					elem.style.height = elems[i + 1].style.height = elems[i + 2].style.height = v + 'px';
					this._shift2h += v;
					this._shift2h += $util.getOffset(style);
				}
			}
			
			elem = this._body2;
			style = $util.getRuntimeStyle(elem);
			this._shift3h = $util.toIntPX(style, 'marginTop') + $util.toIntPX(style, 'marginBottom');
			this._shift3w = $util.toIntPX(style, 'marginLeft') + $util.toIntPX(style, 'marginRight');
			this._shift4h = $util.getOffset(style);
			this._shift4w = $util.getOffset(style, true);
		}
		
		height -= this._shift1h + this._header.get_height();
		if(height < 0)
			height = 0;
		
		if((width = elem.offsetWidth - this._shift1w) < 0)
			width = 0;
		body.style.height = height + 'px';
		
		elem = this._bodyTD;
		body = this._body2;
		
		if((height -= this._shift2h) < 0)
			height = 0;
		elem.style.height = height + 'px';
		
		if((height -= this._shift3h) < 0)
			height = 0;
		v = this._shift4h;
		var heightS = height - v;
		if(heightS < 0)
			heightS = 0;
		body.style.height = heightS + 'px';
		
		if(v > 0 && body.offsetHeight < height)
		{
			body.style.height = height + 'px';
			if((dif = elem.offsetHeight - body.offsetHeight) > 0)
			{
				body.style.height = (height += dif) + 'px';
			}
		}
		height = body.offsetHeight - v;
		
		if((width -= this._shift2w) < 0)
			width = 0;
		elem.style.width = width + 'px';
		var widthTD = elem.offsetWidth;
		
		v = this._shift4w;
		body.style.width = '';
		if((dif = body.offsetWidth - widthTD) > 0)
		{
			body.style.width = '100%';
			if((dif = body.offsetWidth - widthTD) > 0)
				body.style.width = Math.floor(100 - dif / widthTD * 100) + '%';
		}
		
		if(v > 0 && (body.offsetWidth + this._shift3w) < width)
		{
			body.style.width = width + 'px';
		}
		width = body.offsetWidth - v;
		if(height < 0)
			height = 0;
		if(width < 0)
			width = 0;
		
		if(this._clientWidth === width && this._clientHeight === height)
			return;
		this._clientWidth = width;
		this._clientHeight = height;
		if(fire)
			this._contentPane._onInit();
		if(play)
			this._play();
		
		$util.raiseLayoutEvent(this);
	},

	
	getLayoutManager:function()
	{
		/// <summary>Implementation of LayoutManager. Internal use only.</summary>
		/// <returns type="Object">Reference to this.</returns>
		return this;
	},
	
	getClientWidth:function()
	{
		/// <summary>Implementation of LayoutManager. Internal use only.</summary>
		/// <returns type="Number">Width of client area.</returns>
		return this._clientWidth;
	},
	
	getClientHeight:function()
	{
		/// <summary>Implementation of LayoutManager. Internal use only.</summary>
		/// <returns type="Number">Height of client area.</returns>
		return this._clientHeight;
	},
	
	getBody:function()
	{
		/// <summary>Implementation of LayoutManager. Internal use only.</summary>
		/// <returns type="Object">Reference to div element which used as content pane.</returns>
		var v = this._body2; return v ? v : this._body;
	},
	
	
	findChild:function(id)
	{
		/// <summary>Find html element which id ends-up with "id".</summary>
		/// <param name="id" type="String">The trailing part of id of element to search for.</param>
		/// <returns type="Object" mayBeNull="true">Reference to html element or null.</returns>
		return $util.findChild(this.getBody(), id);
	},
	
	_get_isMinimized:function(){return (this.get_windowState() == $IG.DialogWindowState.Minimized);},
	_get_isMaximized:function(){return (this.get_windowState() == $IG.DialogWindowState.Maximized);},
	_get_isClosed:function(){return (this.get_windowState() == $IG.DialogWindowState.Hidden);},
	get_windowState:function()
	{
		/// <summary>Gets the current state of dialog.</summary>
		/// <returns type="Number">Value which corresponds to WindowState enum on server.</returns>
		return this._get_value($IG.DialogWindowProps.WindowState);
	},	    
	set_windowState:function(state, fire)
	{   
		/// <summary>Sets the current state of dialog.</summary>
		/// <param name="state" type="Number">Window state.</param>
		/// <param name="fire" type="Boolean">Request to raise client event.</param>
	    var lastState = this._get_lastWindowState(), newState = state, restoreMax = restoreMin = false;
	    var currentState = this._get_value($IG.DialogWindowProps.WindowState);	    
	    if(state == $IG.DialogWindowState.Normal)
	    {
	        if(currentState ==  $IG.DialogWindowState.Hidden)
	        {
	            if(lastState == $IG.DialogWindowState.Maximized)
	            {
                    state = $IG.DialogWindowState.Maximized;		        
                    restoreMax = true;
                }
                else if(lastState == $IG.DialogWindowState.Minimized)
                {
                    restoreMin = true;
                    state = $IG.DialogWindowState.Minimized;	
                }
            }
	        else if(currentState == $IG.DialogWindowState.Minimized && lastState == $IG.DialogWindowState.Maximized)
	            state = $IG.DialogWindowState.Maximized;		        
	    }
	    
	    if(state != currentState)   
	    {
	        if(fire)
	        {
	            var args =  this._raiseClientEvent('WindowStateChanging', 'WindowStateCancel', null, null, currentState, state);
	            if(args == null || !args.get_cancel())
	            {
	                this._updateWindowState(state, currentState, lastState, restoreMax, restoreMin);	            
	                this._raiseClientEvent("WindowStateChanged", "PostBack", null, null);
	            }
	            return;
	        }	            
	    }
	    this._updateWindowState(state, currentState, lastState, restoreMax, restoreMin);	            
	},
	
	show:function()
	{
		///<summary>
	    /// Displays the WebDialogWindow by adjusting the WindowState to $IG.DialogWindowState.Normal
	    ///</summary>
	    this.set_windowState($IG.DialogWindowState.Normal);
	},
	hide:function()
	{
		///<summary>
	    /// Hides the WebDialogWindow by adjusting the WindowState to $IG.DialogWindowState.Hidden
	    ///</summary>
	    this.set_windowState($IG.DialogWindowState.Hidden);
	},	
	_updateWindowState:function(state, currentState, lastState, restoreMax, restoreMin)
	{
	    if(restoreMax || restoreMin)
            this._setNormal(state, restoreMax, restoreMin);
        
        this._set_value($IG.DialogWindowProps.WindowState, state);
        
        if(state == $IG.DialogWindowState.Maximized)
            this._setMaximized(currentState);
        else if(state == $IG.DialogWindowState.Minimized)
            this._setMinimized(currentState);
        else if(state == $IG.DialogWindowState.Hidden)
            this._setClosed(); 
        else if(state == $IG.DialogWindowState.Normal)
        {		        
            if(currentState == $IG.DialogWindowState.Maximized)
                this._setRestoreMax();
            else if(currentState == $IG.DialogWindowState.Minimized)
                this._setRestoreMin(lastState);
            else
                this._setNormal(state);
        }
        
        if(state != currentState)
            this._set_lastWindowState(currentState)
	    
        for(var i = 0; i < this._header._buttons.length; i++)
            this._header._buttons[i]._ensureState();
	    
        if(this._resizer)
            this._resizer.enabled = (state == $IG.DialogWindowState.Normal);
	},
	
	_get_lastWindowState:function(){return this._get_value($IG.DialogWindowProps.LastWindowState);},	
	_set_lastWindowState:function(val){this._set_value($IG.DialogWindowProps.LastWindowState, val);},	
	 
	_setRestoreMax:function(isTemp)
	{
	    var max = this._maxOld;
	    if(max)
		{
		    var htm = max.htm;
		    this._header._resizeLsnr(false);
		    var style = this._element.style;
		    style.width = max.w;
		    style.height = max.h;
		    var pos = max.pos;
		    if(pos == null)
			    pos = 'absolute';
		    style.position = pos;
		    style.left = max.x;
		    style.top = max.y;
		    style.zIndex = max.zi;
		    htm.scrollLeft = max.x2;
		    htm.scrollTop = max.y2;
		    if(htm.style)
			    htm.style.overflow = max.over;
			if(!isTemp)
		        this._maxOld = null;
		    this.onResize();
		    this._headerMoveable(true);
		}
		
		this._hideResizer(false);		
	},
	
	_setRestoreMin:function(lastState)	
	{
	    $util.display(this._body);
	    var style = this._element.style;
	    	        
	    if(lastState != $IG.DialogWindowState.Maximized)
	    {
	        style.width = this._header._ownerWidth;
		    style.height = this._header._ownerHeight;		    
		    this._hideResizer(false);	    
		    this.onResize();
	        this._header._ownerSize();	  	        
		    this._headerMoveable(true);
		}
	},
	
	_setMaximized:function(currentState)
	{   
	    if(currentState == $IG.DialogWindowState.Minimized)
	        this._setRestoreMin();
	    var body = this._body;
	    if(!body)
			return;
		var style = this._element.style;
		this._hideResizer(true);

        this._headerMoveable(false);
			
		var htm = $util.getHTML();
		
		if(!this._maxOld)
		{
		    if(currentState == $IG.DialogWindowState.Minimized)
		        this._maxOld = max = {x:this.get_left(), y:this.get_top(), w:this.get_width(), h:this.get_height(), pos:null, zi:style.zIndex, htm:htm, x2:htm.scrollLeft, y2:htm.scrollTop};
		    else
		        this._maxOld = max = {x:style.left, y:style.top, w:style.width, h:style.height, pos:style.position, zi:style.zIndex, htm:htm, x2:htm.scrollLeft, y2:htm.scrollTop};
		 }   
		
		htm.scrollLeft = htm.scrollTop = 0;
		if(htm.style)
		{
			max.over = htm.style.overflow;
			htm.style.overflow = 'hidden';
		}
		style.position = 'absolute';
		style.left = style.top = '0px';
		style.zIndex = 100000;
		var point = $util.getPosition(this._element);
		if(point.x != 0)
			style.left = (-point.x) + 'px';
		if(point.y != 0)
			style.top = (-point.y) + 'px';
		this._header._onResize();
		this._header._resizeLsnr(true);		
	},
	
	_setMinimized:function(currentState)
	{   
		if(currentState == $IG.DialogWindowState.Maximized)
			this._setRestoreMax(true)
		var body = this._body;
		this._header._ownerSize();
		$util.display(body, true);
		var style = this._element.style;
		this._hideResizer(true);
		style.width = this._header._minWidth + 'px';
		style.height = this._header.get_height() + 'px';				
	},
	
	_setClosed:function()
	{
		this._setVis(false);
		this._headerMoveable(false);	
	},
	
	_setNormal:function(newState, restoreMax, restoreMin)
	{
		this._setVis(true);
		this._onTimer(true, true);
		if(restoreMax)
			this._setRestoreMax();
		if(restoreMin)
			this._setRestoreMin();
		if(newState == $IG.DialogWindowState.Normal) 
		{
			this.onResize();
			this._headerMoveable(true);
			this._hideResizer(false);	
		}
		this._play();
	},
	
	_hideResizer:function(hide)
	{   
		if(this._resizer)
			$util.display(this._resizer._handDad, hide);
	},
	
	_headerMoveable:function(moveable)
	{
		this._header._moveable(moveable, this._get_isMaximized());
	},
	
	
	_onSubmitOtherHandler:function(e)
	{
		if(this._contentPane)
			this._contentPane._onSubmit();
		$IG.WebDialogWindow.callBaseMethod(this, '_onSubmitOtherHandler', [e]);
	},

	dispose:function()
	{
		/// <summary>Disposes object and event handlers.</summary>
		$IG.WebDialogWindow.callBaseMethod(this, 'dispose');
		this._header = this._resizer = this._contentPane = null;
	}
}

$IG.WebDialogWindow.registerClass('Infragistics.Web.UI.WebDialogWindow', $IG.ControlMain);


$IG.Header = function(obj, element, props, control)
{
	var csm = obj ? new $IG.ObjectClientStateManager(props[0]) : null;
	$IG.Header.initializeBase(this, [obj, element, props, control, csm]);
	this._elems = this._buttons = [];
}

$IG.Header.prototype =
{
	_height:null,

	get_minimizedWidth:function()
	{
		/// <summary>Gets the width of the header when control is minimized.</summary>
		/// <returns type="Number">Width of control in minimized state.</returns>
		return this._get_value($IG.HeaderProps.MinimizedWidth);
	},
	set_minimizedWidth:function(val)
	{
		/// <summary>Sets the width of the header when control is minimized.</summary>
		/// <param name="val" type="Number">Width of control in minimized state.</param>
		this._set_value($IG.HeaderProps.MinimizedWidth, val);
		this.__updateMinWidth(); 
		if(this._owner._get_isMinimized())
		    this._owner._setMinimized();
	},

	
	_ownerSize:function()
	{
		var ctl = this._owner;
		var elem = ctl._element;
		var v = ctl.get_height();
		if(v == '' && !this._ownerHeight)
		{
			if((v = elem.offsetHeight) == 0)
				v = 300;
			v = v + 'px';
		}
		if(v != '')
			this._ownerHeight = v;
		v = ctl.get_width();
		if(v == '' && !this._ownerWidth)
		{
			if((v = elem.offsetWidth) == 0)
				v = 400;
			v = v + 'px';
		}
		if(v != '')
			this._ownerWidth = v;
	},
	
	get_height:function()
	{
		/// <summary>Gets the height of the header.</summary>
		/// <returns type="Number">Height of header.</returns>
		var height = this._height;
		if(height !== null)
			return height;
		height = this._element;
		if(!height)
			return this._height = 0;
		return ((height = height.offsetHeight) != 0) ? (this._height = height) : 0;
	},
	
	getCaptionText:function()
	{
		/// <summary>Gets the text that will be displayed in the caption area of the header.</summary>
		/// <returns type="String">Text of header.</returns>
		return this._get_value($IG.HeaderProps.CaptionText);
	},
	
	setCaptionText:function(val)
	{
		/// <summary>Sets the text that will be displayed in the caption area of the header.</summary>
		/// <param name="val" type="String">Text of header.</param>
		var elem = this._getElem(1);
		if(!elem)
		{
			if(!val)return;
			this._elems[7].appendChild(this._elems[1] = elem = document.createElement('SPAN'));
		}
		elem.innerHTML = val; 
		this._set_value($IG.HeaderProps.CaptionText, val);
	},
	
	getImageUrl:function()
	{
		/// <summary>Gets the image url that will be displayed in the header.</summary>
		/// <returns type="String">Image url for header.</returns>
		return this._get_value($IG.HeaderProps.ImageUrl);
	},
	
	setImageUrl:function(val)
	{
		/// <summary>Sets the image url that will be displayed in the header.</summary>
		/// <param name="val" type="String">Image url for header.</param>
		var elem = this._getElem(0);
		if(!elem)
		{
			if(!val)return;
			this._elems[7].appendChild(this._elems[0] = elem = document.createElement('IMG'));
		}
		elem.src = val; 
		this._set_value($IG.HeaderProps.ImageUrl, val);
	},
	
	_moveable:function(val, max)
	{
		var move = this._mover, ctl = this._owner;
		if(!move)
		{
			move = this._element;
			if(!val || !move) return;
			move = this._mover = $create($IG.DialogMoveBehavior,{"targetElement":ctl._element, "owner":this, "control":ctl}, null, null, move);
			move._ie = this._ie;
			move._prefix = 'Header';
		    move._img = this._elems[0];
		    move._lbl = this._elems[1];
		}
		move.enabled = val && ctl.get_moveable();
		if(!val)
		{
			move.restore(max);
		}
		if(val)
			move.setAbsPos(ctl.get_left(), ctl.get_top(), ctl.get_initialLocation() > 0, ctl.get_maintainLocationOnScroll(), ctl._get_modal(), max);
	},
	
	_getElem:function(i)
	{
		var elem = this._elems;
		if(elem) elem = elem[i];
		return (elem && elem.nodeName) ? elem : null;
	},
	
	_setupButtons:function()
	{ 
	    this._buttons = [];
	    this._closeButton = new $IG.DialogButton("Close", this._elems["Close"], this._objectManager.get_objectProps(0), this, null, $IG.DialogWindowState.Hidden);
		this._objectManager.register_object(0, this._closeButton);
		this._buttons.push(this._closeButton);
		
		this._maxButton = new $IG.DialogButton("Maximize", this._elems["Maximize"], this._objectManager.get_objectProps(1), this, null,  $IG.DialogWindowState.Maximized);
		this._objectManager.register_object(1, this._maxButton);
		this._buttons.push(this._maxButton);
		
		this._minButton = new $IG.DialogButton("Minimize", this._elems["Minimize"], this._objectManager.get_objectProps(2), this, null,  $IG.DialogWindowState.Minimized);
		this._objectManager.register_object(2, this._minButton);
		this._buttons.push(this._minButton);
	},

	
	
	
	_init:function(elems, elem)
	{
	    this._elems = elems;   
	    if(this._objectManager)
	        this._setupButtons();
	    else
	        return;
		
		var ctl = this._owner;
		this._ownerSize();
				 
		this.__updateMinWidth();
	},
	
	__updateMinWidth:function()
	{
	    var width = 2;
	    var elem = this._element;
	    var elems = this._elems;
	    var td = null;
	    var buttonCount = this._buttons.length;
		for(var i = 0; i < buttonCount; i++)
		{
		    var img = this._buttons[i].get_element();
		    if(!img)continue;
			var ow = img.offsetWidth;
			width += ((ow == 0) ? 15 : ow) + $util.toIntPX(null, 'marginLeft', 0, img) + $util.toIntPX(null, 'marginRight', 0, img);
		    if(!td)
			    td = img.parentNode;
		}
	    
	    var minWidth = this.get_minimizedWidth();
		
		if(td)
		{
			
			td.style.width = width + 'px';
			
			width += $util.getOffset($util.getRuntimeStyle(elem), true);
			width += $util.getOffset($util.getRuntimeStyle(this._element), true) + 1;
			
			if(elems[8])
				width += elems[8].offsetWidth + elems[9].offsetWidth;
			
			if(!minWidth || minWidth < width)
				minWidth = width;
		}
		this._minWidth = minWidth ? minWidth : 0;
	},
	
	
	_onResize:function(e)
	{
		var max = this._maxOld, ctl = this._owner;
		if(!max && !ctl)
			return;
		var win = $util.getWinRect();
		ctl.onResize((win.width - 2) + 'px', (win.height - 2) + 'px');
	},

	
	_resizeLsnr:function(on)
	{
		if(!on && !this._resizeOn)
			return;
		if(!this._onResizeFn)
			this._onResizeFn = Function.createDelegate(this, this._onResize);
		if(on === this._resizeOn)
			return;
		this._resizeOn = on;
		if(on)
			$addHandler(window, 'resize', this._onResizeFn);
		else
			$removeHandler(window, 'resize', this._onResizeFn);
	},

	getImageElement:function()
	{
		/// <summary>Gets the reference to html element which shows image in the header.</summary>
		/// <returns type="Object" mayBeNull="true">Reference to html element or null.</returns>
		return this._getElem(0);
	},
	getCaptionElement:function()
	{
		/// <summary>Gets the reference to html element which shows caption text in the header.</summary>
		/// <returns type="Object" mayBeNull="true">Reference to html element or null.</returns>
		return this._getElem(1);
	},
	getContentElement:function()
	{
		/// <summary>Gets the reference to html element which shows content of header.</summary>
		/// <returns type="Object" mayBeNull="true">Reference to html element or null.</returns>
		return this._getElem(7);
	},
	
	_createObjects:function(objectManager)
    {
        this._objectManager = objectManager;
        if(this._elems)
            this._setupButtons();
    },

	dispose:function()
	{
		/// <summary>Disposes object and event handlers.</summary>
		if(this._resizeLsnr)
			this._resizeLsnr(false);
		$IG.Header.callBaseMethod(this, 'dispose');
		this._mover = null;
	}
}
$IG.Header.registerClass('Infragistics.Web.UI.Header', $IG.UIObject);



$IG.DialogButton = function(obj, element, props, owner, csm, state)
{   
    this._state = state;    
    if(!csm)csm = new $IG.ObjectClientStateManager(props[0]);    
    $IG.DialogButton.initializeBase(this, [obj, element, props, owner, csm]);
    this._control = this._owner._owner;
    if(this._element)
        this._setupImage();   
}

$IG.DialogButton.prototype = 
{
    get_altText:function()
    {
        ///<summary>
	    /// Gets the alt text of the button.
	    ///</summary>
        var alt = this._get_clientOnlyValue("a");
        return (alt == null)? "" : alt;
    },
    
    get_restoreAltText:function()
    {
        ///<summary>
	    /// Gets the restore alt text of the button.
	    ///</summary>
        var alt = this._get_clientOnlyValue("ra");
        return (alt == null)? "" : alt;
    },
    _setupImage:function()
    {
		if(this._element)
        if(this._element.nodeName && this._control.get_enabled())
        {
			$addHandlers(this._element, {'mousedown':this._onMouseDown, 'mouseover':this._onMouseOver, 'mouseout':this._onMouseOut}, this);
			this._onMouseUpFn = Function.createDelegate(this, this._onMouseUp);
		    $addHandler(document, 'mouseup', this._onMouseUpFn);
		}
    },
    
    _ensureState:function()
    {
        this.setState((this._control.get_windowState() == this._state) ? "r" : $IG.ImageState.Normal);
    },
    _updateState:function(val1, val2)
    {
        var state = (this._control.get_windowState() == this._state);
        this._updateAlt(state);
		this.setState(state ? val2 : val1);
    },
    _updateAlt:function(state)
    {
		if(this._element)
        this._element.alt = state ? this.get_restoreAltText(): this.get_altText();
    },
    
    _changeState:function()
    { 
        this._control.set_windowState( (this._control.get_windowState() == this._state) ? $IG.DialogWindowState.Normal :this._state, true);
    },  
    
    _onMouseDown:function(e)
	{
	    if(e.button == 0)
	    {
		    $util.cancelEvent(e);
		    this._updateState($IG.ImageState.Pressed, "rp");
		}
	},
	_onMouseOver:function(e)
	{
	    this._updateState($IG.ImageState.Hover, "rh");
	},
	_onMouseOut:function(e)
	{
	    this._updateState($IG.ImageState.Normal, "r");
	},
	_onMouseUp:function(e)
	{
	    if(e.button == 0)
	    {
		    if(e.target == this._element)
		    {
		        this._changeState();
	            this._updateState($IG.ImageState.Hover, "rh");
	        }
	        else
	            this._updateState($IG.ImageState.Normal, "r");
	    }
	},
	dispose:function()
	{
		if(this._element)
			$clearHandlers(this._element);
		if(this._onMouseUpFn)
			$removeHandler(document, 'mouseup', this._onMouseUpFn);
		$IG.DialogButton.callBaseMethod(this, 'dispose');
		this._onMouseUpFn = null;
	}
}
$IG.DialogButton.registerClass('Infragistics.Web.UI.DialogButton', $IG.ImageObject);





$IG.DialogMoveBehavior = function(elem)
{
	/// <summary>Class which implements move behavior of WebDialogWindow.</summary>
	/// <param name="elem" type="Object">Reference to html element.</param>
	$IG.DialogMoveBehavior.initializeBase(this, [elem]);
}

$IG.DialogMoveBehavior.prototype =
{
	
	enabled:true,
	_fixTabOn:false,
	_scrollOn:false,
	_keyOn:false,
	_isModal:false, 
		
	_addHandlers:function()
	{
		this._mouseMoveHandler = Function.createDelegate(this, this._onMouseMove);
		this._mouseUpHandler = Function.createDelegate(this, this._onMouseUp);
		this._mouseOutHandler = Function.createDelegate(this, this._onDocMouseOut);
		$addHandlers(this.get_element(), {'mousedown':this._onMouseDown, 'mouseover':this._onMouseOver, 'mouseout':this._onMouseOut}, this);
	},

	get_targetElement:function()
	{
		/// <summary>Gets the reference to html element which used as target.</summary>
		/// <returns type="Object">Reference to html element.</returns>
		return this._targetElement;
	},
	set_targetElement:function(val)
	{
		/// <summary>Sets the reference to html element which used as target.</summary>
		/// <param name="val" type="Object">Reference to html element.</param>
		this._targetElement = val;
	},

	_onMouseOver:function(e)
	{
		if(this.enabled)
			
			this._raiseClientEvent(this._prefix + 'MouseOver', null, e);
	},
	_onMouseOut:function(e)
	{
		if(this.enabled)
			
			this._raiseClientEvent(this._prefix + 'MouseOut', null, e);
	},
	
	_onMouseDown:function(e)
	{
	    if(e.button == 0)
	    {
		    if(!this.enabled) return;
		    this._drag = 1;
		    var elem = e.target;
		    if(!elem) return;
		    if(elem != this._element && elem != this._img && elem != this._lbl && elem.nodeName != 'TD')
			    return;
		    e.target.unselectable = 'on';
		    $util.cancelEvent(e);
		    $addHandler(document, 'mousemove', this._mouseMoveHandler); 		    
		    $addHandler(document, 'mouseup', this._mouseUpHandler); 	
		    $addHandler(document, 'mouseout', this._mouseOutHandler);	    
		}
		
		this._raiseClientEvent(this._prefix + 'MouseDown', null, e);
	},
	
	_onDocMouseOut:function(e)
	{
	    var rect = $util.getWinRect(window);
	    var x = e.clientX;
	    var y = e.clientY;
	    if((x < 0 || y < 0) || x > rect.width || y > rect.height)
	        this._onMouseUp(e);
	}, 
	
	
	_onMouseMove:function(e)
	{
		if(!this.enabled || !this._drag) return;
		$util.cancelEvent(e);
		if(this._drag == 2)
		{
		    this.__moved = true;
			this._moveWindow(e);
			return;
		}
		this._drag = 2;
		this.setAbsPos();
		this._mouseX = e.clientX;
		this._mouseY = e.clientY;
	},
	
	
	_onMouseUp:function(e)
	{
		if(!this.enabled || !this._drag) return;
		this._drag = null;
		$removeHandler(document, 'mousemove', this._mouseMoveHandler);
		$removeHandler(document, 'mouseup', this._mouseUpHandler);
		$removeHandler(document, 'mouseout', this._mouseOutHandler);	    
		
		
		this._raiseClientEvent(this._prefix + 'MouseUp', null, e);
		
		var v, fix = null, x = this._x, y = this._y;
		
		
		if(x != null && y != null && (this.__moved))
		{
		    this.__moved =false ;
		    var args = this._raiseClientEvent('Moved', 'Move', e, null, x, y, this._xOld, this._yOld);
		    var cancel = args ? args.get_cancel() : false;
		    if(cancel)
		    {
			    fix = x = this._xOld;
			    y = this._yOld;
		    }
		    else if(args)
		    {
			    if((v = args._x) != null)
				    fix = x = v;
			    if((v = args._y) != null)
				    fix = y = v;
		    }
		    if(fix == null)
		    {
				$util._setTranspFrame(this);
			    return;
		    }
		    this.setLocation(x, y, cancel);						
		}
	},
	
	_onFrameMove:function(e)
	{
		var elem = this._control ? this._control._element : null, head = this._element;
		if(!elem || !head)
			return;
		e.clientY += $util.toInt(elem.style.top, 0) + head.offsetHeight + this._shiftY;
		e.clientX += $util.toInt(elem.style.left, 0);
		this._onMouseMove(e);
	},
	
	
	
	_lsnr:function(scroll, key)
	{
		if(scroll != this._scrollOn)
		{
			this._scrollOn = scroll;
			if(!this._onScrollFn)
			{
				this._onScrollFn = Function.createDelegate(this, this._onScrollSize);
				this._onResizeFn = Function.createDelegate(this, this._onScrollSize);
			}
			if(scroll)
			{
				$addHandler(window, 'scroll', this._onScrollFn);
				$addHandler(window, 'resize', this._onResizeFn);
			}
			else
			{
				$removeHandler(window, 'scroll', this._onScrollFn);
				$removeHandler(window, 'resize', this._onResizeFn);
			}
		}
		if(key == this._keyOn)
			return;
		this._keyOn = key;
		if(!this._onKeyFn)
		{
			this._onKeyFn = Function.createDelegate(this, this._onKey);
			this._onFocusFn = Function.createDelegate(this, this._onFocus);
			this._onDeactFn = Function.createDelegate(this, this._onDeact);
		}
		if(key)
		{
			$addHandler(document, 'keydown', this._onKeyFn);
			$addHandler(document, 'focus', this._onFocusFn);
			$addHandler(document, 'beforedeactivate', this._onDeactFn);
		}
		else
		{
			$removeHandler(document, 'keydown', this._onKeyFn);
			$removeHandler(document, 'focus', this._onFocusFn);
			$removeHandler(document, 'beforedeactivate', this._onDeactFn);
		}
	},
	
	
	
	_onScrollSize:function(flag)
	{
		
		if(this._drag)
			return;
		
		if(this._scroll && flag != 2)
			this.setAbsPos(this._xFixed, this._yFixed, this._center, this._scroll, this._isModal, false);
		var elem = this._targetElement, style = this._lid ? this._lid.style : this._lidStyle;
		if(!style)
			return;
		var rect = $util.getWinRect();
		style.width = Math.max(rect.width + rect.x - 6, rect.maxWidth - 2) + 'px';
		style.height = Math.max(rect.height + rect.y - 6, rect.maxHeight - 2) + 'px';
	},
	
	
	_isChild:function(dad, elem)
	{
		if(!dad || !elem)
			return false;
		if(dad == elem)
			return true;
		var nodes = dad.childNodes;
		if(!nodes)
			return false;
		for(var i = 0; i < nodes.length; i++)
			if(this._isChild(nodes[i], elem))
				return true;
		return false;
	},
	
	
	
	
	_tabFoc:function(e, delay)
	{
		if(e)
			$util.cancelEvent(e);
		
		var elem = this._shiftKey ? this._maxTab2 : this._minTab2;
		
		if(!elem)
			elem = this._shiftKey ? this._maxTabI : this._minTabI;
		
		if(!elem || elem == this._lastTab)
			elem = this._anyTab1;
		
		if(elem == this._lastTab)
			elem = this._anyTab2;
		if(!elem)
			return;
		if(delay)
		{
			$util._tab_foc = elem;
			window.setTimeout('try{$util._tab_foc.focus();}catch(i){}',1);
		}
		else
			try{elem.focus();}catch(elem){}
	},
	
	
	_canTab:function(elem)
	{
		if(parseInt(elem.tabIndex) > 0)
			return true;
		for(var i = 0; i < 5; i++)
			if(elem.nodeName == this._tags[i])
				return true;
		return false;
	},
	
	
	_setTabElem:function(elem, foc)
	{
		var tab = this._lastTab;
		
		if((!tab && !foc) || this._lastTabTime + 100 < (new Date()).getTime())
			return;
		
		if(this._isChild(this._targetElement, elem))
			return;
		
		
		
		if(this._shiftKey)
		{
			
			if(!this._minTab2)
				this._minTab2 = tab;
		}
		
		else if(!this._maxTab2)
			
			this._maxTab2 = tab;
		this._tabFoc(null, foc);
	},
	
	
	_onDeact:function(e)
	{
		var to = e ? e.rawEvent : null;
		if(!to)
			return;
		this._deAct = true;
		
		this._setTabElem(to.toElement);//this._setTabElem(to.toElement, e);
	},
	
	
	_onFocus:function(e)
	{
		var elem = (e && !this._deAct) ? e.target : null;
		if(!elem)
			return;
		this._setTabElem(elem, true);
		this._lastTab = null;
	},
	
	
	_onKey:function(e)
	{
		var div = this._targetElement, elem = e ? e.target : null;
		if(!elem || e.keyCode != 9)
			return;
		this._shiftKey = e.shiftKey;
		this._lastTabTime = (new Date()).getTime();
		if(!this._isChild(div, elem))
			return;
		if(!this._canTab(elem))
		{
			this._tabFoc(e);
			return;
		}
		this._lastTab = null;
		if(e.shiftKey)
		{
			
			if(elem == this._minTab2)
			{
				this._tabFoc(e);
				return;
			}
			
			if(this._isChild(div, elem))
				this._lastTab = elem;
		}
		else
		{
			
			if(elem == this._maxTab2)
			{
				this._tabFoc(e);
				return;
			}
			
			if(this._isChild(div, elem))
				this._lastTab = elem;
		}
	},
	
	
	_onFoc:function(e)
	{
		if(this._me)
			this._me._setTabElem();
	},
	
	
	
	
	_fixTabs:function(on, max, doc)
	{
		var elem, i = -1, stop = this._stop, tabs = this._oldTabs, elem0 = this._targetElement;
		if(on == this._fixTabOn)
			return;
		this._fixTabOn = on;
		if(!on)
		{
			if(!tabs)
				return;
			for(var i = 0; i < tabs.length; i++)
				tabs[i].elem.tabIndex = tabs[i].i;
			if(stop)
				stop.style.display = 'none';
			return;
		}
		if(!tabs)
		{
			tabs = this._oldTabs = new Array();
			this._tags = ['INPUT','SELECT','TEXTAREA','BUTTON','A','IFRAME','AREA','DIV','EMBED','OBJECT'];
		}
		else
			Array.clear(tabs);
		if(!stop && !max)
		{
			this._stop = stop = document.createElement('INPUT');
			var style = stop.style;
			style.padding = style.border = style.width = style.height = '0px';
			style.position = 'absolute';
			stop.tabIndex = 1000;
			elem0.insertBefore(stop, elem0.firstChild);
			stop.onfocus = this._onFoc;
			stop._me = this;
		}
		if(stop)
			stop.style.display = '';
		if(!doc)
			doc = document;
		
		var lenAll, lenMy, ti1 = 0, ti2 = 0, j = i = 0, tags = this._tags;
		
		
		for(var t = 0; t < tags.length; t++)
		{
			var elemsAll = doc.getElementsByTagName(tags[t]);
			if((lenAll = elemsAll ? elemsAll.length : 0) < 1)
				continue;
			var elemsMy = this._targetElement.getElementsByTagName(tags[t]);
			lenMy = elemsMy ? elemsMy.length : 0;
			while(lenAll-- > 0)
			{
				elem = elemsAll[lenAll];
				j = lenMy;
				while(j-- > 0) if(elem == elemsMy[j])
				{
					if(elem == stop || elem.disabled || elem.type == 'hidden')// || !elem.offsetWidth)
						break;
					var ti = elem.tabIndex;
					if(!ti)
						ti = 0;
					else if((ti = parseInt(ti)) < 0)
						break;
					if(t < 5 || ti > 0)
					{
						
						if(!this._anyTab1)
							this._anyTab1 = elem;
						
						
						else if(!this._anyTab2)
							this._anyTab2 = elem;
						
						if(!this._minTabI)
						{
							this._minTabI = elem;
							ti1 = ti;
						}
						if(ti1 > ti) 
						{
							this._minTabI = elem;
							ti1 = ti;
						}
					}
					if(ti < 1)
						break;
					
					if(ti >= ti2)
					{
						ti2 = ti;
						this._maxTabI = elem;
					}
					break;
				}
				
				if(j < 0)
				{
					
					tabs[i++] = {elem:elem,i:elem.tabIndex};
					
					elem.tabIndex = -1;
				}
			}
		}
		
		if(stop && ti2 >= stop.tabIndex)
			stop.tabIndex = ti2 + 1;
	},
	
	_modal:function(on)
	{
		if(!this._isModal)
			return;
		if(this._inModal == on)
			return;
		var style, elem = this._targetElement, lid = this._lid;
		if(!lid)
			lid = $util._modalLid;
		if(this._modalNest(lid, on))
			return;
		var css = this._owner._owner;
		if(css)
			css = css._modalCss;
		var elem2 = null;
		if(on && !lid)
		{
			this._lid = lid = document.createElement($util.IsIE ? 'IFRAME' : 'DIV');
			if(!$util._modalLid)
				$util._modalLid = lid;
			style = lid.style;
			style.position = 'absolute';
			if($util.IsIE)
			{
				lid.frameBorder = 0; 
				lid.scrolling = 'no';
				lid.src = elem2 = 'javascript:new String("<html></html>")';	  	
			}
			else
				lid.innerHTML = '&nbsp;';
			if(css)
				lid.className = css;
			else
			{
				style.filter = 'alpha(opacity:30)';
				style.opacity = 0.3;
			}
			
			lid.unselectable = 'on';
			lid.tabIndex = -1;			
		}
		this._inModal = on;
		var div = elem.parentNode;
		this._fixTabs(on);
		style = lid.style;
		this._lidStyle = on ? style : null;
		lid._first = on ? this : null;
		if(on)
		{
			div.insertBefore(lid, elem);
			if($util.IsIE)
			{
				var doc = lid.contentWindow.document;
				$util.addHandler(doc, 'mousemove', this._mouseMoveHandler);
				$util.addHandler(doc, 'mouseup', this._mouseUpHandler); 	
				if(this._control && this._control._resizer)
				{
					$util.addHandler(doc, 'mousemove', this._control._resizer._onMouseMoveFn);
					$util.addHandler(doc, 'mouseup', this._control._resizer._onMouseUpFn); 	
				}
			}
			lid._z = this._doZ(lid, elem);
			$util.display(lid);
			var pos = $util.getPosition(lid);
			style.marginLeft = -pos.x + 'px';
			style.marginTop = -pos.y + 'px';
			
			this._onScrollSize(2);
			
			if(elem2)
			{
				elem2 = lid.contentWindow.document.createElement('DIV');
				lid.appendChild(elem2);
				
				var style2 = elem2.style;
				style2.width = style2.height = '100%';
				elem2.unselectable = 'on';
				elem2.tabIndex = -1;
				
				
				if(css)
				{
					div = document.createElement('DIV');
					div.style.position = 'absolute';
					div.style.width = div.style.width = '1px';
					div.className = css;
					document.body.appendChild(div);
					css = $util.getStyleValue(null, 'backgroundColor', div);
					document.body.removeChild(div);
					if(css)
						style2.background = css;
				}
			}
		}
		else
		{
			$util.display(lid, false);
			style.marginLeft = style.marginTop = style.width = style.height = '0px';
			div.removeChild(lid);
			elem.style.zIndex = this._oldZ;
		}
	},
	
	
	_doZ:function(lid, elem, lidZ)
	{
		this._newZ = this._oldZ = $util.getStyleValue(null, 'zIndex', elem);
		if(!lidZ)
			lidZ = $util.toInt($util.getStyleValue(null, 'zIndex', lid), 0);
		if(lidZ < 10)
			lid.style.zIndex = lidZ = 99999;
		if($util.toInt(this._oldZ, 0) <= lidZ)
			elem.style.zIndex = this._newZ = lidZ + 1;
		return lidZ;
	},
	
	
	
	
	
	_modalNest:function(lid, on)
	{
		var ctl = lid ? lid._first : null;
		if(!ctl)
			
			return false;
		var nest = lid._nest;
		if(!nest && !on)
			
			return false;
		
		if(!nest)
			lid._nest = nest = [ctl];
		var z, i = nest.length, elem = this._targetElement;
		if(on)
		{
			
			this._doZ(lid, elem, lid._z);
			
			nest[i--] = this;
			z = this._oldZ;
		}
		else
		{
			
			if(--i < 2)
				lid._nest = null;
			
			else
				nest[i] = null;
			
			nest.length = i--;
			z = nest[i]._newZ;
		}
		this._inModal = on;
		
		elem = nest[i]._targetElement;
		
		elem.style.zIndex = z;
		
		
		
		this._fixTabs(on, false, elem);
		
		return true;
	},
	
	
	
	
	
	setAbsPos:function(x, y, center, scroll, modal, max)
	{
		/// <summary>Sets location. Internal use only.</summary>
		var elem = this._targetElement;
		var style = elem.style;
		this._position0 = style.position;
		if(style.position != 'absolute')
			style.position = 'absolute';
		var point = $util.getPosition(elem);
		
		if(!center && scroll && x === '')
		{
			x = point.x + 'px';
			y = point.y + 'px';
		}
		
		this._xFixed = this._leftOld = x;
		this._yFixed = this._topOld = y;
		
		if(center || scroll || modal)
		{
			this._center = center;
			this._scroll = scroll;
			if(modal)
				this._modal(this._isModal = modal);
			else
				this._fixTabs(max, max);
			this._lsnr(scroll || modal, modal);
		}
		else if(max != null)
			this._fixTabs(max, max);
		if(center || (scroll && x && y))
		{
			var win = $util.getWinRect(), len = (x && !center) ? x.length : 0;
			
			var w = win.width, h = win.height;
			
			if(len > 0)
			{
				var perc = x.indexOf('%') > 0;
				x = parseInt(x);
				
				if(perc)
					x = w * x / 100;
			}
			
			else if((x = (w - elem.offsetWidth) / 2) < 0)
				x = 0;
			len = (y && !center) ? y.length : 0;
			
			if(len > 0)
			{
				var perc = y.indexOf('%') > 0;
				y = parseInt(y);
				
				if(perc)
					y = Math.floor(h * y / 100);
			}
			
			else if((y = (h - elem.offsetHeight) / 2) < 0)
				y = 0;
			
			point.x = Math.floor(win.x + x);
			point.y = Math.floor(win.y + y);
		}
		
		if(this._shiftX == null)
		{
			style.left = point.x + 'px';
			style.top = point.y + 'px';
			var p = $util.getPosition(elem);
			
			this._shiftX = p.x - point.x;
			this._shiftY = p.y - point.y;
		}
		this._control.set_left((point.x -= this._shiftX) + 'px', false);
		this._control.set_top((point.y -= this._shiftY) + 'px', false);
		
		this._xOld = point.x;
		this._yOld = point.y;
	},

	restore:function(max)
	{
		/// <summary>Restore location. Internal use only.</summary>
		/// <param name="max" type="Boolean">Maximized flag.</param>
		if(this._isModal)
			this._modal(false);
		else
			this._fixTabs(max, max);
		this._lsnr(false, max && this._isModal);
	},

	
	
	
	setLocation:function(x, y, cancel)
	{
		/// <summary>Sets location. Internal use only.</summary>
		/// <param name="x" type="String">Left edge.</param>
		/// <param name="y" type="String">Top edge.</param>
		/// <param name="cancel" type="Boolean">Request to cancel.</param>
		var style = this._targetElement.style;
		var ctl = this._control;
		style.left = x;
		style.top = y;
		if(ctl && ctl.set_left)
		{
			
			if(cancel)
			{
				x = this._leftOld;
				y = this._topOld;
			}
			
			else if(this._center)
			{
				var win = $util.getWinRect();
				
				x = (parseInt(x) - win.x + this._shiftX) + 'px';
				y = (parseInt(y) - win.y + this._shiftY) + 'px';
			}
			
			ctl.set_left(this._xFixed = x, true);
			ctl.set_top(this._yFixed = y, true);
		}
		if(cancel)
			style.position = this._position0;
	},

	_moveWindow:function(e)
	{
		var x = e.clientX, y = e.clientY;
		if(x < 0 || y < 0)
			return;
		x += this._xOld - this._mouseX;
		y += this._yOld - this._mouseY;
		
		var args = this._raiseClientEvent('Moving', 'Move', e, null, x, y, this._xOld, this._yOld);
		if(args && args.get_cancel())
			return;
		if(!this._onFrameMouseFn)
			this._onFrameMouseFn = Function.createDelegate(this, this._onFrameMove);
		$util._setTranspFrame(this, this._control.get_contentPane()._DIV, this._mouseUpHandler, this._onFrameMouseFn);
		this._center = false;
		this.setLocation((this._x = x) + 'px', (this._y = y) + 'px');
	},

	dispose:function()
	{
		/// <summary>Disposes object and event handlers.</summary>
		if(this._lsnr)
		{
			this._lsnr(false, false);
			this._modal(false);
		}
		$util._setTranspFrame(this);
		$IG.DialogMoveBehavior.callBaseMethod(this, 'dispose');
	}
}
$IG.DialogMoveBehavior.registerClass('Infragistics.Web.UI.DialogMoveBehavior', $IG.Behavior);

$IG.WindowStateCancelEventArgs = function()
{
	/// <summary>Class which used while raising events by WebDialogWindow.</summary>
	$IG.WindowStateCancelEventArgs.initializeBase(this);
}
$IG.WindowStateCancelEventArgs.prototype =
{
	get_currentWindowState: function()
	{
		///<summary>Gets the current window state of the dialog.</summary>
		/// <returns type="Number">Window state.</returns>
		return this._props[2];
	},
	
	get_newWindowState: function()
	{
		///<summary>Gets the new window state of the dialog.</summary>
		/// <returns type="Number">Window state.</returns>
		return this._props[3];
	}
}
$IG.WindowStateCancelEventArgs.registerClass('Infragistics.Web.UI.WindowStateCancelEventArgs', $IG.CancelEventArgs);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();