﻿
Syncfusion.Web.UI.INotifyResizing = function()
{
    throw Error.notImplemented();
}
Syncfusion.Web.UI.INotifyResizing.prototype =
{
    onSetParentSize : function(){
        throw Error.notImplemented();
    },
    onSetChildSize : function(){
        throw Error.notImplemented();
    },
    
    GetIsUpdateOnParentResize : function(){
        throw Error.notImplemented();
    },
    
    GetIsUpdateOnChildResize : function(){
        throw Error.notImplemented();
    }
}
Syncfusion.Web.UI.INotifyResizing.registerInterface('Syncfusion.Web.UI.INotifyResizing');

Syncfusion.Web.UI.LayoutControlBase = function( element )
{
    this._originalWidth = "";
    this._originalHeight = "";
    
    this._minWidth = 50;
    this._minHeight = 50;
	this._maxWidth = 0x7FFFFFFF;
	this._maxHeight = 0x7FFFFFFF;
    
    this.UTIL = new SF_Util();
	this.DOM = new SF_DOM( { UTIL: this.UTIL } );
	this.CSS = new SF_CSS( { DOM: this.DOM } );     
    Syncfusion.Web.UI.LayoutControlBase.initializeBase(this, [element]);    
}
Syncfusion.Web.UI.LayoutControlBase.prototype = 
{    
    addToControlManager: function(){        
        Syncfusion.Web.UI.LayoutControlBase.callBaseMethod(this, "addToControlManager");        
        Syncfusion.Web.UI.LayoutManager.Add( this );
    },
    
    dispose : function(){
        Syncfusion.Web.UI.LayoutManager.Remove( this );
        Syncfusion.Web.UI.LayoutControlBase.callBaseMethod(this, "dispose");
    },
    
    set_originalWidth : function(sVal){
        this._originalWidth = sVal;
    },
    get_originalWidth : function(){
        return this._originalWidth;
    },
    set_originalHeight : function(sVal){
        this._originalHeight = sVal;
    },
    get_originalHeight : function(){
        return this._originalHeight;
    },
    set_minWidth : function( nVal ){
	    this._minWidth = nVal;
	},
	get_minWidth : function(){
	    return this._minWidth;
	},
	set_minHeight : function( nVal ){
	    this._minHeight = nVal;
	},
	get_minHeight : function(){
	    return this._minHeight;
	},
	set_maxWidth : function( nVal ){
	    this._maxWidth = nVal;
	},
	get_maxWidth : function(){
	    return this._maxWidth;
	},
	set_maxHeight : function( nVal ){
	    this._maxHeight = nVal;
	},
	get_maxHeight : function(){
	    return this._maxHeight;
	},
    
	_isSizeInPercentage : function( bWidth ){
	    var sVal = bWidth ? this.get_originalWidth() : this.get_originalHeight();
	    return sVal &&( "%" == Syncfusion.Web.UI.Utility.parseUnit( sVal ).type )
	},
    
    onSetParentSize : function(){
        this.setOriginalSize();
        if( this.get_originalHeight() )
        {
            this.setContentHeight(false);
        }
        if( this.get_originalWidth() )
        {
            this.setContentWidth(false);
        }
    },
    onSetChildSize : function(){
        if( !this.get_originalWidth() )
        {
            this.setContentWidth(true);
        }
        if( !this.get_originalHeight() )
        {
            this.setContentHeight(true);
        }
        this._setSizeInPixels();
        var el = this.get_element();
        var nWidth = el.offsetWidth;
        var nHeight = el.offsetHeight;
        this._checkLimiteSize();
        if( nWidth != el.offsetWidth  )
        {
            this.setContentWidth(false);
        }
        if( nHeight != el.offsetHeight )
        {
            this.setContentHeight(false);
        }
    },
    GetIsUpdateOnParentResize : function(){    
        return this._isSizeInPercentage( true ) || this._isSizeInPercentage( false );
    },
    
    GetIsUpdateOnChildResize : function(){
        return !this.get_originalWidth() || !this.get_originalHeight();
    },

    setOriginalSize : function()
    {
        var el = this.get_element();
        el.style.width = this.get_originalWidth();
        el.style.height = this.get_originalHeight();
        this._checkLimiteSize();
    },

    _setSizeInPixels : function()
    {
        var el = this.get_element();
        this.setElHeight( el, el.offsetHeight );
        this.setElWidth( el, el.offsetWidth );
    },
    
    _checkLimiteSize : function()
    {
        this._checkLimiteWidth();
        this._checkLimiteHeight();
    },
    
    _checkLimiteWidth : function(){
        var el = this.get_element();
        var nOffsetWidth = el.offsetWidth;
        var nWidth = Math.max( Math.min( nOffsetWidth, this.get_maxWidth() ), this.get_minWidth() );
        if( nWidth != nOffsetWidth )
        {
            this.setElWidth( el, nWidth );
        }
    },    
    _checkLimiteHeight : function(){
        var el = this.get_element();
        var nOffsetHeight = el.offsetWidth;
        var nHeight = Math.max( Math.min( nOffsetHeight, this.get_maxHeight() ), this.get_minHeight() );
        if( nHeight != nOffsetHeight )
        {
            this.setElHeight( el, nHeight );
        }        
    },
    
    setContentHeight : function( bRelChild ){
        this.setContentWidthHeight( false, bRelChild );
    },
    setContentWidth : function( bRelChild ){
        this.setContentWidthHeight( true, bRelChild );
    },
    setContentWidthHeight : function( bWidth, bRelChild ){
    },
        
    // events
    add_resize : function(handler) {
        this.get_events().addHandler("resize", handler);
    },
    remove_resize : function(handler) {
        this.get_events().removeHandler("resize", handler);
    },
    raiseResize : function() {
        var bRes = true;
        var handler = this.get_events().getHandler("resize");
        if (handler) {
            bRes = ( false != handler(this, Sys.EventArgs.Empty) );
        }
        return bRes;
    },
    
    add_resizeend : function(handler) {
        this.get_events().addHandler("resizeend", handler);
    },
    remove_resizeend : function(handler) {
        this.get_events().removeHandler("resizeend", handler);
    },
    raiseresizeend : function() {
        var bRes = true;
        var handler = this.get_events().getHandler("resizeend");
        if (handler) {
            bRes = ( false != handler(this, Sys.EventArgs.Empty) );
        }
        return bRes;
    },
    
    //DOM util methods    
    setElHeight : function( oEl, nHeight ){        
        if( oEl && oEl.style &&( 0 < nHeight ) ){
	        if( oEl.tagName == "TABLE" ){
	            oEl.style.height = nHeight + "px";
	        }else{
	            this.DOM.SetHeight( oEl, nHeight );
	        }
	    }
    },    
    setElWidth : function( oEl, nWidth )
    {        
        if( oEl && oEl.style &&( 0 < nWidth ) ){
	        if( oEl.tagName == "TABLE" ){
	            oEl.style.width = nWidth + "px";
	        }else{
	            this.DOM.SetWidth( oEl, nWidth );
	        }
	    }
    },
    
    getExtSize : function( oEl, bWidth )
    {
        var fnGetExtSize = bWidth ? this.DOM.GetElementExtWidth : this.DOM.GetElementExtHeight;
        var nRes = fnGetExtSize( oEl, true ) + fnGetExtSize( oEl, false );
        return nRes;
    }    
}
Syncfusion.Web.UI.LayoutControlBase.registerClass('Syncfusion.Web.UI.LayoutControlBase', Syncfusion.Web.UI.ControlBase,
    Syncfusion.Web.UI.INotifyResizing );
    
Syncfusion.Web.UI.LayoutPanel = function( element )
{
    this._headerPosition = 0;
    this._showHeader = true;
    this._fullScreen = false;
    this._collapsed = false;
    this._contentElement = null;
    
    this.collapsible = false;
    this.expandImgUrl = "";
    this.collapseImgUrl = "";
    
    this._collapseImgClickHandler = null;
    
    Syncfusion.Web.UI.LayoutPanel.initializeBase(this, [element]);
}

Syncfusion.Web.UI.LayoutPanel.prototype = 
{
    initialize : function(){        
        Syncfusion.Web.UI.LayoutPanel.callBaseMethod(this, "initialize");
        
        if( this.get_fullScreen() )
        {
            this.DOM.GetTopmostLayoutEl().style.overflow = "hidden";
        }
        
        if( this.collapsible && this.get_showHeader() )
        {
            this._collapseImgClickHandler = Function.createDelegate(this, this._collapseImgClick);
        }
        this.attachEvents( true );
        this.set_images( [ this.expandImgUrl, this.collapseImgUrl ] );
    },
    
    dispose : function(){
        this.attachEvents( false );
        this._collapseImgClickHandler = null;
        Syncfusion.Web.UI.LayoutPanel.callBaseMethod(this, "dispose");
    },    
    
    attachEvents : function(bAttach){
        var handler = bAttach ? $addHandler : $removeHandler;        
        if( null != this._collapseImgClickHandler )
        {
            var oCollapseImg = this.get_collapseImage();
            handler(oCollapseImg, "click", this._collapseImgClickHandler);
        }
    },
    
    set_headerPosition : function(nVal){
        this._headerPosition = nVal;
    },
    get_headerPosition : function(){
        return this._headerPosition;
    },
    get_isLeftHeader : function(){
        return this._headerPosition == 1;
    },
    set_showHeader : function(bVal){
        this._showHeader = bVal;
    },
    get_showHeader : function(){
        return this._showHeader;
    },
    set_fullScreen : function(bVal){
        this._fullScreen = bVal;
    },
    get_fullScreen : function(){
        return this._fullScreen;
    },
    
    set_collapsed : function(bVal){
        bVal = this.UTIL.IsTrue(bVal);
        if( this._initialized &&( this._collapsed != bVal ) )
        {
            this.collapse();
        }
        else
        {
            this._collapsed = bVal;
        }
    },
    get_collapsed : function(){
        return this._collapsed;
    },
    
    get_contentCell : function(){
        var res = null;
        var tbl = this.get_element();
        if( this.get_showHeader() )
        {
            res = this.get_isLeftHeader() ? tbl.rows[0].cells[1] : tbl.rows[1].cells[0];
        }
        else
        {
            res = tbl.rows[0].cells[0];
        }
        return res;
    },
    get_contentContainer : function(){
        if( null === this._contentElement )
        {
            this._contentElement = this.DOM.GetElById( this.get_id() + "_content", this.get_contentCell() )
        }
        return this._contentElement;
    },
    get_collapseHostElement : function(){
        return this.collapsible ? this.DOM.GetParentEl( this.get_contentContainer() ) : null;
    },   
    get_textContainer : function(){
        return this.get_showHeader() ? this.DOM.GetElById( this.get_id() + "_text", this.get_element() ) : null;
    },    
    get_headerCell : function(){
        var tblRoot = this.get_element();
        var oHeaderCell = this.get_showHeader() ? tblRoot.rows[0].cells[0] : null;
        return oHeaderCell;
    },
    get_collapseImage : function(){
        return this.DOM.GetElById( this.get_id() + "_collapse", this.get_element() );
    },
    
    setContentHeight : function( bRelChild ){
        if( !this.get_collapsed() ||
            ( !this._isCollapseDirectionTop() &&( this._isSizeInPercentage( false ) || this.isInitiallySizeSetProcess ) ) )
        {
            Syncfusion.Web.UI.LayoutPanel.callBaseMethod(this, "setContentHeight", [bRelChild]);
        }
    },
    setContentWidth : function( bRelChild ){
        if( !this.get_collapsed() ||
            ( this._isCollapseDirectionTop() &&( this._isSizeInPercentage( true )|| this.isInitiallySizeSetProcess ) ) )
        {
            Syncfusion.Web.UI.LayoutPanel.callBaseMethod(this, "setContentWidth", [bRelChild]);
        }
    },
    
    onSetParentSize : function(){
        var oContEl = this.get_contentContainer();
        oContEl.style.width = "";
        oContEl.style.height = "";
        if( this.get_collapsed() && this.isInitiallySizeSetProcess &&
            ( ( this._isCollapseDirectionTop() && !this.get_originalHeight() )||
            ( !this._isCollapseDirectionTop() && !this.get_originalWidth() ) ) )
        {
            this._doExpantCollapse( true );
        }
        Syncfusion.Web.UI.LayoutPanel.callBaseMethod(this, "onSetParentSize");
    },
    onSetChildSize : function(){
        Syncfusion.Web.UI.LayoutPanel.callBaseMethod(this, "onSetChildSize");
        if( this.get_collapsed() && this.isInitiallySizeSetProcess &&
            ( ( this._isCollapseDirectionTop() && !this.get_originalHeight() )||
            ( !this._isCollapseDirectionTop() && !this.get_originalWidth() ) ) )
        {
            this._doExpantCollapse( false );
            this.setOriginalSize();
            this._setSizeInPixels();
        }
    },
    
    setOriginalSize : function(){
        var tblRoot = this.get_element();
        var sWidth = tblRoot.style.width;
        var sHeight = tblRoot.style.height;
        Syncfusion.Web.UI.LayoutPanel.callBaseMethod(this, "setOriginalSize");
        if( this.get_fullScreen() )
        {
            var oRootStyle = tblRoot.style;
            oRootStyle.height = Math.max( this.DOM.GetWindowClientHeight(), 1 ) + "px";
            oRootStyle.width = Math.max( this.DOM.GetWindowClientWidth(), 1 ) + "px";
            this._checkLimiteSize();
        }
        else if( this.get_collapsed() )
        {
            if( this._isCollapseDirectionTop() )
            {
                tblRoot.style.height = "1px";
                if( !this.get_originalWidth() )
                {
                    tblRoot.style.width = sWidth;
                }
            }
            else
            {
                tblRoot.style.width = "1px";
                if( !this.get_originalHeight() )
                {
                    tblRoot.style.height = sHeight;
                }
            }
        }
    },
    
    _isCollapseDirectionTop : function(){
        var bRes = !this.get_showHeader() || !this.get_isLeftHeader();
        return bRes;
    },
    
    _checkLimiteWidth : function(){
        if( !this.get_collapsed() || this._isCollapseDirectionTop() )
        {
            Syncfusion.Web.UI.LayoutPanel.callBaseMethod(this, "_checkLimiteWidth");
        }
    },
    _checkLimiteHeight : function(){
        if( !this.get_collapsed() || !this._isCollapseDirectionTop() )
        {
            Syncfusion.Web.UI.LayoutPanel.callBaseMethod(this, "_checkLimiteHeight");
        }
    },
    
    setContentWidthHeight : function( bWidth, bRelChild ){
        var tblRoot = this.get_element();
        var oContCell = this.get_contentCell();
        var oContEl = this.get_contentContainer();
        var oTextEl = this.get_textContainer();
        var propOffsetSize = bWidth ? "offsetWidth" : "offsetHeight";
        var propSize = bWidth ? "width" : "height";
        var bUpdateTextElSize = ( null != oTextEl ) &&
            ( ( bWidth && !this.get_isLeftHeader() )||
                ( !bWidth && this.get_isLeftHeader() ) );
        
        var bUpdateContent = !this.get_collapsed();
        if( bUpdateTextElSize )
        {
            oTextEl.style[propSize] = bRelChild ? "" : "1px";
        }
        if( bUpdateContent )
        {
            oContEl.style[propSize] = bRelChild ? "" : "1px";
            
            var bRefreshCollapseHost = this.collapsible && !bRelChild;
            var oCollapseHost = this.get_collapseHostElement();
            if( bRefreshCollapseHost )
            {
                oCollapseHost.style[propSize] = "1px";
            }
        var nContSize = oContEl[propOffsetSize];
        if( bRelChild )
        {
            if( ( !this.DOM.IsIE() && bWidth )||
                ( this.DOM.IsIE() && !bWidth ) )
            {
                nContSize += this.DOM.GetScrollbarWidth( oContEl, !bWidth );
            }
        }
        else
        {       
            nContSize = oContCell[propOffsetSize]; 
            if( !bWidth )
            {
                nContSize = tblRoot[propOffsetSize] - this.getExtSize( tblRoot, bWidth );
                if( this.get_showHeader() && !this.get_isLeftHeader() )
                {
                    oContCell.style.height = "100%";
                    var oHeaderCell = this.get_headerCell();
                    nContSize -= oHeaderCell[propOffsetSize];
                    oContCell.style.height = "";
                }
            }
            nContSize -= this.getExtSize( oContCell, bWidth );
        }
        if( bWidth )
        {
            this.setElWidth( oContEl, nContSize );
        }
        else
        {
            this.setElHeight( oContEl, nContSize );
        }
            if( bRefreshCollapseHost )
            {
                oCollapseHost.style[propSize] = "100%";
            }
        }
        if( bUpdateTextElSize )
        {
            var oParTD = this.DOM.GetParentEl( oTextEl );
            var oHeaderCell = this.get_headerCell();
            var oParTbl = Syncfusion.Web.UI.Utility.getFirstChildByTagName( "table", oHeaderCell );            
            var oTextCont = /*this.get_isLeftHeader() ? this.DOM.GetParentEl( oParTD ) :*/ oParTD;
            oParTbl.style[propSize]="";
            this.CSS.SetDisplay( oTextCont, this.CSS.DisplayNone );
            var nVal = oHeaderCell[propOffsetSize];
            nVal -=  this.getExtSize( oHeaderCell, bWidth );
            nVal -= this.getExtSize( oParTbl, bWidth );
            var arrChildEls = this.get_isLeftHeader() ? oParTbl.rows : oParTbl.rows[0].cells;
            for( var i = 0; i < arrChildEls.length; ++i )
            {
                var child = arrChildEls[i];
                var childTD = (child.tagName == "TR") ? child.cells[0] : child;
                nVal -= childTD[propOffsetSize];
            }
            if( this.get_isLeftHeader() && this.DOM.IsIE() )
            {
                nVal -= 4;
            }
            this.CSS.SetDisplay( oTextCont, this.CSS.DisplayEmpty );
            nVal -= this.getExtSize( oParTD, bWidth )
            if( bWidth )
            {
                this.setElWidth( oTextEl, nVal );
            }
            else
            {
                this.setElHeight( oTextEl, nVal );
            }
        }
    },    
    
    _collapseImgClick : function( args ){
        this.toggleExpand();
    },
    
    _updateExpCollImgSrc : function(){
        var oImg = this.get_collapseImage();
        if( null != oImg )
                {   
            oImg.src = this.get_collapsed() ? this.expandImgUrl : this.collapseImgUrl;
                }
    },
    
    collapse : function(){
        if( this.collapsible && !this._collapsed )
        {
            var eventArgs = new Sys.CancelEventArgs();
            this.raiseCollapsing(eventArgs);
            if (eventArgs.get_cancel()) {
                return;
            }
            
            this._doExpantCollapse( false );            
            this._collapsed = true;
            this.setOriginalSize();
            this._setSizeInPixels();
            Syncfusion.Web.UI.LayoutManager.refreshParents( this.get_element() );
            this._updateExpCollImgSrc();
            this._updateControlData();
            this._updateControlData();
            
            this.raiseCollapsed(Sys.EventArgs.Empty)
        }
    },
    
    expand : function(){
        if( this.collapsible && this._collapsed )
        {
            var eventArgs = new Sys.CancelEventArgs();
            this.raiseExpanding(eventArgs);
            if (eventArgs.get_cancel()) {
                return;
            }
            
            this._doExpantCollapse( true );
            this._collapsed = false;            
            this.onSetParentSize();
            Syncfusion.Web.UI.LayoutManager._onResizeRecursive(this.get_element());
            this.onSetChildSize();            
            Syncfusion.Web.UI.LayoutManager.refreshParents( this.get_element() );            
            this._updateExpCollImgSrc();
            this._updateControlData();
            
            this.raiseExpanded(Sys.EventArgs.Empty)
        }
    },
    
    _updateControlData : function(){
        var oHdnEl = this.DOM.GetElById( this.get_id() + "_hidden", this.get_contentCell() );
        if(null != oHdnEl)
        {
            oHdnEl.value = this.get_collapsed() ? "1" : "0";
        }
    },
    
    _doExpantCollapse : function( bExpand ){    
        var oSlHost = this.get_collapseHostElement();
        var oContCell = this.get_contentCell();
        var oHideEl = this._isCollapseDirectionTop() ? this.DOM.GetParentEl( oContCell ) : oContCell;
                    
        this.CSS.SetVisible( oSlHost, bExpand );
        this.CSS.SetDisplay( oHideEl, bExpand ? this.CSS.DisplayEmpty : this.CSS.DisplayNone );        
    },
    
    toggleExpand : function(){
        if( this._initialized && this.collapsible )
        {
            if( this.get_collapsed() )
            {
                this.expand();
            }
            else
            {
                this.collapse();
            }
        }
    },
    
    // events
    add_collapsing : function(handler) {
        this.get_events().addHandler("collapsing", handler);
    },
    remove_collapsing : function(handler) {
        this.get_events().removeHandler("collapsing", handler);
    },
    raiseCollapsing : function(eventArgs) {
        var bRes = true;
        var handler = this.get_events().getHandler("collapsing");
        if (handler) {
            bRes = ( false != handler(this, eventArgs) );
        }
        return bRes;
    },
    
    add_expanding : function(handler) {
        this.get_events().addHandler("expanding", handler);
    },
    remove_expanding : function(handler) {
        this.get_events().removeHandler("expanding", handler);
    },
    raiseExpanding : function(eventArgs) {
        var bRes = true;
        var handler = this.get_events().getHandler("expanding");
        if (handler) {
            bRes = ( false != handler(this, eventArgs) );
        }
        return bRes;
    },
    
    add_collapsed : function(handler) {
        this.get_events().addHandler("collapsed", handler);
    },
    remove_collapsed : function(handler) {
        this.get_events().removeHandler("collapsed", handler);
    },
    raiseCollapsed : function(eventArgs) {
        var bRes = true;
        var handler = this.get_events().getHandler("collapsed");
        if (handler) {
            bRes = ( false != handler(this, eventArgs) );
            }
        return bRes;
    },
    
    add_expanded : function(handler) {
        this.get_events().addHandler("expanded", handler);
    },
    remove_expanded : function(handler) {
        this.get_events().removeHandler("expanded", handler);
    },
    raiseExpanded : function(eventArgs) {
        var bRes = true;
        var handler = this.get_events().getHandler("expanded");
        if (handler) {
            bRes = ( false != handler(this, eventArgs) );
        }
        return bRes;
    }
}

Syncfusion.Web.UI.LayoutPanel.registerClass('Syncfusion.Web.UI.LayoutPanel', Syncfusion.Web.UI.LayoutControlBase);

Syncfusion.Web.UI.LayoutTable = function( element )
{    
    Syncfusion.Web.UI.LayoutTable.initializeBase(this, [element]);
}
Syncfusion.Web.UI.LayoutTable.prototype = 
{    
    GetIsUpdateOnChildResize : function(){
        return false;
    },
    
    setContentHeight : function(bRel){
        var el = this.get_element();
        var oRootTbl = Syncfusion.Web.UI.Utility.getFirstChildByTagName( "table", el );        
        var nPercentRowCount = 0;
        if( null == oRootTbl.PercentRowCount )
        {
            for( var i = 0, len = oRootTbl.rows.length; i < len; ++i )
            {
                var row = oRootTbl.rows[i];
                var sfRow = Syncfusion.Web.UI.LayoutManager.Get( row.id );
                var sHeight = sfRow.get_originalHeight();
                if( !sHeight ||( "%" == Syncfusion.Web.UI.Utility.parseUnit( sHeight ).type ) )
                {
                    nPercentRowCount++;
                }
                oRootTbl.PercentRowCount = nPercentRowCount;
            }
        }
        else
        {
            nPercentRowCount = oRootTbl.PercentRowCount;
        }        
        var oLastPercentRow = null;
        for( var i = 0, len = oRootTbl.rows.length; i < len; ++i )
        {                
            var row = oRootTbl.rows[i];
            var sfRow = Syncfusion.Web.UI.LayoutManager.Get( row.id );            
            var sHeight = sfRow.get_originalHeight();
            if( !sHeight && !bRel )
            {
                sHeight = Math.max( parseInt( 100 / nPercentRowCount, 10 ), 1 ) + "%";
            }
            if( sHeight &&( "%" == Syncfusion.Web.UI.Utility.parseUnit( sHeight ).type ) )
            {
                oLastPercentRow = row;
            }
            row.style.height = sHeight;            
            for( var j = 0, cell_len = row.cells.length; j < cell_len; ++j )
            {
                var cell = row.cells[j];
                var sfCell = Syncfusion.Web.UI.LayoutManager.Get( cell.id );
                cell.style.height = sfCell.get_originalHeight();                
                var oContDiv = Syncfusion.Web.UI.Utility.getFirstChildByTagName( "div", cell );
                oContDiv.style.height = sfCell.get_minHeight() + "px"; // - cell GetExtHeight
            }
            var oLastCell = row.insertCell(row.cells.length);
            var div = document.createElement("div");
            oLastCell.appendChild( div );
            div.style.overflow = "hidden";
            div.style.height = sfRow.get_minHeight() + "px"; // - cell GetExtHeight
        }        
        var nTblHeight = el.offsetHeight - this.getExtSize( el, false );
        oRootTbl.style.height = nTblHeight + "px";        
        var nLostDelta = 0;
        if( !bRel )
        {
            var nNewHeight = nTblHeight;
            var nPrevSize = 0;
            var nStableSizeCount = 0;
            while( nStableSizeCount != oRootTbl.rows.length /* ( nPrevSize != oRootTbl.offsetHeight ) */&&
                (( null == oLastPercentRow ) || ( oRootTbl.offsetHeight > nTblHeight ) ) )
            {
                nPrevSize = oRootTbl.offsetHeight;
                var nDelta = Math.max( parseInt( nTblHeight - ( nTblHeight * nTblHeight )/oRootTbl.offsetHeight, 10 ), 1 );
                nNewHeight -= nDelta;
                oRootTbl.style.height = Math.max( nNewHeight, 0 ) + "px";
                if( ( null != oLastPercentRow ) &&( oRootTbl.offsetHeight < nTblHeight ) )
                {
                    nLostDelta = nTblHeight - oRootTbl.offsetHeight;
                    break;
                }
                else if( nNewHeight <= 0 )
                {
                    break;
                }                
                if( nPrevSize == oRootTbl.offsetHeight )
                {
                    nStableSizeCount++;
                }
                else
                {
                    nStableSizeCount = 0;
                }
            }
        }            
        var nHeight = oRootTbl.offsetheight;        
        for( var i = 0, len = oRootTbl.rows.length; i < len; ++i )
        {
            var row = oRootTbl.rows[i];
            var bIsLstPercentRow = row === oLastPercentRow;
            for( var j = 0, cell_len = row.cells.length - 1; j < cell_len; ++j )
            {
                var cell = row.cells[j];
                cell.CurrHeight = cell.offsetHeight;
                if( bIsLstPercentRow )
                {
                    cell.CurrHeight += nLostDelta;
                }
            }
        }        
        for( var i = 0, len = oRootTbl.rows.length; i < len; ++i )
        {
            var row = oRootTbl.rows[i];
            row.style.height = "";
            for( var j = 0, cell_len = row.cells.length - 1; j < cell_len; ++j )
            {
                var cell = row.cells[j];
                this.setElHeight( cell, cell.CurrHeight );
                
                var nCellInsideHeight = cell.CurrHeight - this.getExtSize( cell, false );
                var oContDiv = Syncfusion.Web.UI.Utility.getFirstChildByTagName( "div", cell );
                oContDiv.style.height = nCellInsideHeight + "px";
            }
            row.removeChild( row.cells[ row.cells.length - 1 ] );
        }        
        this.setElHeight( oRootTbl, nHeight );
        this.setElHeight( el, oRootTbl.offsetHeight + this.DOM.GetHeightDifference( el ) );
    },
    
    setContentWidth : function(bRel){
        var el = this.get_element();
        var oRootTbl = Syncfusion.Web.UI.Utility.getFirstChildByTagName( "table", el );        
        var oLastPercentRow = null;
        for( var i = 0, len = oRootTbl.rows.length; i < len; ++i )
        {                
            var row = oRootTbl.rows[i];
            var sfRow = Syncfusion.Web.UI.LayoutManager.Get( row.id );            
            for( var j = 0, cell_len = row.cells.length; j < cell_len; ++j )
            {                
                var cell = row.cells[j];
                var sfCell = Syncfusion.Web.UI.LayoutManager.Get( cell.id );                
                var sWidth = sfCell.get_originalWidth();
                cell.style.width = sWidth;                                
                var oContDiv = Syncfusion.Web.UI.Utility.getFirstChildByTagName( "div", cell );
                if( !sWidth ||( "%" == Syncfusion.Web.UI.Utility.parseUnit( sWidth ).type ) )
                {
                    sWidth = sfCell.get_minWidth() + "px";  // - cell GetExtHeight
                }
                oContDiv.style.width = sWidth;
            }
        }        
        var nTblWidth = el.offsetWidth - this.getExtSize( el, true );
        oRootTbl.style.width = nTblWidth + "px";
        var nWidth = oRootTbl.offsetWidth;        
        for( var i = 0, len = oRootTbl.rows.length; i < len; ++i )
        {
            var row = oRootTbl.rows[i];
            var bIsLstPercentRow = row === oLastPercentRow;
            for( var j = 0, cell_len = row.cells.length; j < cell_len; ++j )
            {
                var cell = row.cells[j];
                cell.CurrWidth = cell.offsetWidth;
            }
        }        
        for( var i = 0, len = oRootTbl.rows.length; i < len; ++i )
        {
            var row = oRootTbl.rows[i];
            row.style.width = "";
            for( var j = 0, cell_len = row.cells.length; j < cell_len; ++j )
            {
                var cell = row.cells[j];
                this.setElWidth( cell, cell.CurrWidth );                
                var nCellInsideWidth = cell.CurrWidth - this.getExtSize( cell, true );
                var oContDiv = Syncfusion.Web.UI.Utility.getFirstChildByTagName( "div", cell );
                oContDiv.style.width = nCellInsideWidth + "px";
            }
        }        
        this.setElWidth( oRootTbl, nWidth );
        this.setElWidth( el, oRootTbl.offsetWidth + this.DOM.GetWidthDifference( el ) );
    }
}
Syncfusion.Web.UI.LayoutTable.registerClass('Syncfusion.Web.UI.LayoutTable', Syncfusion.Web.UI.LayoutControlBase);

Syncfusion.Web.UI.LayoutTableRow = function( element )
{    
    Syncfusion.Web.UI.LayoutTableRow.initializeBase(this, [element]);
}
Syncfusion.Web.UI.LayoutTableRow.prototype = 
{ 
    onSetParentSize : function(){
    },
    onSetChildSize : function(){        
    },    
    GetIsUpdateOnParentResize : function(){
        return true;
    },
    GetIsUpdateOnChildResize : function(){
        return false;
    }
}
Syncfusion.Web.UI.LayoutTableRow.registerClass('Syncfusion.Web.UI.LayoutTableRow', Syncfusion.Web.UI.LayoutControlBase);

Syncfusion.Web.UI.LayoutTableCell = function( element )
{    
    Syncfusion.Web.UI.LayoutTableCell.initializeBase(this, [element]);
}
Syncfusion.Web.UI.LayoutTableCell.prototype = 
{
    onSetParentSize : function(){
    },
    onSetChildSize : function(){        
    },    
    GetIsUpdateOnParentResize : function(){
        return true;
    },
    GetIsUpdateOnChildResize : function(){
        return false;
    }
}
Syncfusion.Web.UI.LayoutTableCell.registerClass('Syncfusion.Web.UI.LayoutTableCell', Syncfusion.Web.UI.LayoutControlBase);

Syncfusion.Web.UI._LayoutManager = function()
{
    this._resizingprocess = true;
    this._initialized = false;
    this._windowResizeHandler = null;
    Syncfusion.Web.UI._LayoutManager.initializeBase(this);    
    this.initialize();    
}
Syncfusion.Web.UI._LayoutManager.prototype =
{
    initialize : function()
    {
        this._windowResizeHandler = Function.createDelegate(this, this._windowResize);
        this.attachEvents( true );
        this._initialized = true;
    },
    attachEvents : function(bAttach)
    {
        var handler = bAttach ? $addHandler : $removeHandler;
        if( null != this._windowResizeHandler )
        {
            handler(window, "resize", this._windowResizeHandler);
        }
    },
    dispose : function()
    {
        this.attachEvents( false );
        this._windowResizeHandler = null;
        Syncfusion.Web.UI._LayoutManager.callBaseMethod(this, "dispose");
    },    
    Add : function(obj)
    {        
        Syncfusion.Web.UI._LayoutManager.callBaseMethod(this, "Add", [obj] );
        if( Syncfusion.Web.UI.INotifyResizing.isInstanceOfType(obj) )
        {
            obj.WaitingSizeSet = true;
            this._setInitiallySize(obj);
        }
    },
    
    _windowResize : function( arg )
    {
        if( !this._resizingprocess )
        {
            this._resizingprocess = true;
            this._onResizeRecursive( document.body );
            this._resizingprocess = false;
        }        
    },    
    _onResizeRecursive : function(el)
    {
        var arrChilds = el.childNodes;
        if( null != arrChilds )
        {
            for( var i = 0, len = arrChilds.length; i < len; ++i )
            {
                var child = arrChilds[i];
                if( child && child.tagName )
                {
                    this.refreshElement( child );                    
                }
            }
        }
    },
    
    _isNeededToRefresh : function( sfObj ){
        var bRes = false;
        if( ( null != sfObj ) && Syncfusion.Web.UI.INotifyResizing.isInstanceOfType(sfObj) )
        {
            if( sfObj.isInitiallySizeSetProcess )
            {
                bRes = true;
            }
            else
            {
                if( 0 < sfObj.get_element().offsetHeight )
                {
                    if( sfObj.WaitingSizeSet )
                    {
                        bRes = true;
                        this._clearInitiallyWaitingTimer( sfObj );
                    }
                    else
                    {
                        bRes = sfObj.GetIsUpdateOnParentResize();
                    }
                }
            }
        }
        return bRes;
    },
    
    refreshElement : function( el ){
        var sfObj = Syncfusion.Web.UI.ControlManager.Get( el.id );
        var bImplNotifyResizing = ( null != sfObj ) && Syncfusion.Web.UI.INotifyResizing.isInstanceOfType(sfObj);
        var bNotifyResizing = bImplNotifyResizing && this._isNeededToRefresh( sfObj );
        if( bNotifyResizing )
        {
            sfObj.onSetParentSize.apply(sfObj);
        }
        if( !bImplNotifyResizing || bNotifyResizing )
        {
            this._onResizeRecursive(el);
        }                        
        if( bNotifyResizing )
        {
            sfObj.onSetChildSize.apply(sfObj);
        }
    },
    
    refreshParents : function( el ){
        this._refreshParentRecursive( el.parentNode );
    },
    
    _refreshParentRecursive : function( el ){
        var bRefreshParent = false;
        var sfObj = Syncfusion.Web.UI.ControlManager.Get( el.id );
        var bImplNotifyResizing = ( null != sfObj ) && Syncfusion.Web.UI.INotifyResizing.isInstanceOfType(sfObj);        
        if( bImplNotifyResizing )
        {
            if( sfObj.GetIsUpdateOnChildResize() )
            {
                sfObj.onSetParentSize.apply(sfObj);
                sfObj.onSetChildSize.apply(sfObj);
                bRefreshParent = true;                    
            }
        }
        else
        {
            bRefreshParent = true;
        }
        if( bRefreshParent )
        {
            var par = el.parentNode;
            if( par &&( par.tagName != "BODY" )&&( par.tagName != "HTML" ) )
            {
                this._refreshParentRecursive( par );
            }
        }            
    },
    
    _clearInitiallyWaitingTimer : function( obj ){
        if( obj.WaitingSizeSet )
        {
            delete obj.WaitingSizeSet;
            if( obj.InitiallyWaitingTimer )
            {
                window.clearTimeout( obj.InitiallyWaitingTimer );
                delete obj.InitiallyWaitingTimer;
            }
        }
    },
    
    _setInitiallySize : function( obj ){
        if( !this._disposed && obj && !obj._disposed )
        {
            var el = obj.get_element();
            if( el &&( 0 < el.offsetHeight ) )
            {
                obj.isInitiallySizeSetProcess = true;                
                this.refreshElement( el );
                delete obj.isInitiallySizeSetProcess;
                this._clearInitiallyWaitingTimer( obj );
            }
            else
            {
                obj.InitiallyWaitingTimer = window.setTimeout( Function.createDelegate( this, function(){
                    this._setInitiallySize( obj );
                }), 10 );
            }
        }            
    }
}
Syncfusion.Web.UI._LayoutManager.registerClass("Syncfusion.Web.UI._LayoutManager", Syncfusion.Web.UI.ControlCollection );
Syncfusion.Web.UI.LayoutManager = new Syncfusion.Web.UI._LayoutManager();
Sys.Application.add_init(function() {window.setTimeout( function fn(){Syncfusion.Web.UI.LayoutManager._resizingprocess=false;}, 0 );});
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();