﻿
Type.registerNamespace('Infragistics.Web.UI');

/******************************************LayoutPaneProps ENUM************************************/
$IG.LayoutPaneProps = new function()
{
    var count = $IG.ControlObjectProps.Count;
    this.ScrollLeft = [count++, 0];
    this.ScrollTop = [count++, 0];
    this.ScrollBars = [count++, 1];
    this.Count = count; 
};
/******************************************END LayoutPaneProps ENUM********************************/

/******************************************ContentPaneProps ENUM************************************/
$IG.ContentPaneProps = new function()
{
    var count = $IG.LayoutPaneProps.Count;
    this.ContentUrl = [count++, ''];
    this.Count = count;
};
/******************************************END ContentPaneProps ENUM********************************/

$IG.LayoutPane = function(adr, element, props, control, csm, collection, parent)
{
	/// <summary>Base class used by objects of WebSplitter and WebDialogWindow.</summary>
	if(!csm)
		csm = new $IG.ObjectClientStateManager(props[0]);
	$IG.LayoutPane.initializeBase(this, [adr, element, props, control, csm, collection, parent]);
}

$IG.LayoutPane.prototype =
{
	get_scrollLeft:function()
	{
		/// <summary>Gets sets scroll left of pane's content as Number.</summary>
		return this._get_value($IG.LayoutPaneProps.ScrollLeft);
	},
	set_scrollLeft:function(value)
	{
		this._set_value($IG.LayoutPaneProps.ScrollLeft, value);
		this.getBody().scrollLeft = value;
	},
	
	get_scrollTop:function()
	{
		/// <summary>Gets sets scroll top of pane's content as Number.</summary>
		return this._get_value($IG.LayoutPaneProps.ScrollTop);
	},
	set_scrollTop:function(value)
	{
		this._set_value($IG.LayoutPaneProps.ScrollTop, value);
		this.getBody().scrollTop = value;
	},
	
	get_scrollBars:function()
	{
		/// <summary>Gets sets overflow for pane's content as Number. Value should match with server's ContentOverflow enum. 0: visible, 1: auto, 2: scroll, 3: hidden.</summary>
		return this._get_value($IG.LayoutPaneProps.ScrollBars);
	},
	set_scrollBars:function(value)
	{
		this._set_value($IG.LayoutPaneProps.ScrollBars, value);
		if(value == 3) value = 'hidden';
		else if(value == 2) value = 'scroll';
		else if(value == 1) value = 'auto';
		else value = '';
		this.getBody().style.overflow = value;
	},
	
	get_contentUrl:function()
	{
		/// <summary>Gets sets name of url used for pane's iframe. Note: set method has effect only if value for ContentUrl was set on server.</summary>
		return this._get_value($IG.ContentPaneProps.ContentUrl);
	},
	set_contentUrl:function(value)
	{
		this._set_value($IG.ContentPaneProps.ContentUrl, value);
		var frame = this.get_iframe();
		if(frame)
			frame.src = value;
	},
	
	findChild:function(id)
	{
		/// <summary>Gets reference to child element from its id.</summary>
		/// <param name="id" type="String">The id of html element to find. That can be a partial value with which id of element ends up.</param>
		/// <returns type="Object" mayBeNull="true">Reference to child html element or null.</returns>
		return $util.findChild(this.getBody(), id);
	},

	get_iframe:function()
	{
		/// <summary>Gets reference to iframe element located in pane or null. It should be first child in pane.</summary>
		var elem = this.getBody();
		var nodes = elem ? elem.childNodes : null;
		elem = nodes ? nodes[0] : null;
		if(elem && elem.nodeName == '#text')
			elem = nodes[1];
		return (elem && elem.nodeName == 'IFRAME') ? elem : null;
	},

	getClientWidth:function()
	{
		/// <summary>That function is designed for internal usage only (part of LayoutManager).</summary>
		/// <returns type="Number">Client width.</returns>
		if(this._width) return this._width;
		var elem = this.getBody();
		var width = elem.offsetWidth - $util.getOffset($util.getRuntimeStyle(elem), true);
		return (width > 0) ? width : 0;
	},

	getClientHeight:function()
	{
		/// <summary>That function is designed for internal usage only (part of LayoutManager).</summary>
		/// <returns type="Number">Client height.</returns>
		if(this._height) return this._height;
		var elem = this.getBody();
		var height = elem.offsetHeight - $util.getOffset($util.getRuntimeStyle(elem));
		return (height > 0) ? height : 0;
	},

	getBody:function()
	{
		/// <summary>That function is designed for internal usage only (part of LayoutManager).</summary>
		/// <returns type="Object">Container of child elements.</returns>
		return this._DIV ? this._DIV : this._element;
	},
	/* initialize scrollLeft and scrollTop */
	_onInit:function()
	{
		var x = this.get_scrollLeft(), y = this.get_scrollTop(), div = this.getBody();
		if(x > 0)
			div.scrollLeft = x;
		if(y > 0)
			div.scrollTop = y;
	},
	/* save scrollLeft and scrollTop to next session */
	_onSubmit:function()
	{
		this._set_value($IG.LayoutPaneProps.ScrollLeft, this.getBody().scrollLeft);
		this._set_value($IG.LayoutPaneProps.ScrollTop, this.getBody().scrollTop);
	}
}

$IG.LayoutPane.registerClass('Infragistics.Web.UI.LayoutPane', $IG.UIObject);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();