// JS library
// Copyright - FREEFORUMZONE SNC - www.freeforumzone.com

// --------- Drag ---------
var Drag_status=false;
var Drag_ox;
var Drag_oy;
var Drag_dx;
var Drag_dy;
var Drag_avoid=false;
var Drag_mdown=false;

function Drag_end()
{
    try
    {
        Drag_status=false;
        Drag_mdown=false;
        document.onmousemove = null;
        document.onmouseup = null;
        Drag_Window.style.border=Drag_border;
    }
    catch(e)
    {    
    }
}

var Drag_Window=null;
var Drag_border=null;

function Drag_onmousemove(e) {
 if (Drag_mdown == true) {
  if (!e) { e = window.event; }
  Drag_Window.style.left = (Drag_ox - Drag_dx) + e.clientX + 'px';
  Drag_Window.style.top = (Drag_oy - Drag_dy) + e.clientY + 'px';

  Drag_Window.focus();
  if(!Drag_status)
  {
    document.onmouseup = Drag_end;
    Drag_status=true;
  }
 }
 
}

function Drag_onmousedown(e) 
{
  if (!e) { e = window.event; }
  if(Drag_mdown) 
  { 
    Drag_end();
    return; 
  }
  if (Drag_avoid == false) { Drag_mdown = true; }
  else { Drag_mdown = false; Drag_avoid=false; }
  Drag_ox = ffz_GetInt(Drag_Window.style.left.replace('px',''),0);
  Drag_oy = ffz_GetInt(Drag_Window.style.top.replace('px',''),0);
  Drag_dx = e.clientX;
  Drag_dy = e.clientY;
  Drag_start();
  Drag_status=false;
}

function Drag_start()
{
    Drag_mdown=true;
    document.onmousemove = Drag_onmousemove;
    Drag_border=Drag_Window.style.border;
    Drag_Window.style.border="solid 2px #FF0000 ";
}
function Draggable(DragObj, DragWindow, defaultBorder)
{
    Drag_Window=DragWindow;
    DragObj.onmousedown =  Drag_onmousedown;
    DragObj.style.cursor="move";
    DragWindow.style.border=defaultBorder;
}

 
// --------- FAQLink ---------

function FAQLink(QuestionID)
{
    this.TypeName="FAQLink";
    
    var T=this;

    this.QuestionObj=ffz_GetObj(QuestionID);
    this.AlternateObj=this.QuestionObj.nextSibling;
    this.ResultObj=this.QuestionObj.nextSibling.nextSibling;
    this.isActive=false;
    
    this.Attiva = function()
    {
        T.isActive=true;
        T.AlternateObj.style.visibility="hidden";
        T.AlternateObj.style.display="none";
        T.ResultObj.style.visibility="visible";
        T.ResultObj.style.display="block";
    }
    
    this.Disattiva = function()
    {
        T.isActive=false;
        T.AlternateObj.style.visibility="visible";
        T.AlternateObj.style.display="block";
        T.ResultObj.style.visibility="hidden";
        T.ResultObj.style.display="none";
    }
    
    this.Swap = function()
    {
        if(T.isActive) T.Disattiva();
        else T.Attiva();
    }
    
    this.QuestionObj.onclick=T.Swap;
    this.QuestionObj.style.cursor='pointer';
}

// --------- State Button ---------

function StateButton(SelectObject)
{
    // Proprieta
    this.ID=1;
    this.TypeName="StateButton";
    
    SelectObject.style.cursor='pointer';
    this.obj=SelectObject;
    this.isHover=false;
    this.isActive=false;
    this.AutoHideOnClick=true;
    this.CssClassbase='TabSelect1';
    SelectObject.StateButton=this;
    
    // Eventi
    this.onClick=null;
    this.onMouseOver=null;
    this.onMouseOut=null;
    
    var T=this;
    
    // Metodi
    this.Attiva = function()
    {
        T.isActive=true;
        T.obj.style.visibility="";
        T.obj.style.display="";
    }
    
    this.Disattiva = function()
    {
        T.isActive=true;
        T.obj.style.visibility="hidden";
        T.obj.style.display="none";
    }
    
    this.HoverButtonIn = function()
    {
        T.isHover=true;

        T.RefreshCss();
        
        if(T.onMouseOver!=null)
            T.onMouseOver();
    }
    
    this.HoverButtonOut = function()
    {
        T.isHover=false;
        
        T.RefreshCss();
        
        if(T.onMouseOut!=null)
            T.onMouseOut();
    }
    
    this.ClickHide = function()
    {
        if(T.AutoHideOnClick)
        {
            T.Disattiva();
        }
    }
    
    this.Click = function()
    {
        if(!T.isActive) 
            return;
        
        if(T.onClick!=null)
            T.onClick();
        
        T.ClickHide();
    }
    
    this.RefreshCss = function()
    {
        if(T.isHover)
        {
            T.obj.className=T.CssClassbase+'_Hover';
        }
        else
        {
            T.obj.className=T.CssClassbase+'';
        }
    }
    
    this.ChangeCommandText = function(CommandText)
    {
        while (T.obj.hasChildNodes()) {
		    T.obj.removeChild(T.obj.firstChild);
	    }
	    
        var value=CommandText;
        if(isFunction(value))
        {
            value=value();
        }
        
		if(isString(value))
            T.obj.appendChild(document.createTextNode( value ));
        else if(isObject(value))
            T.obj.appendChild( value );
        else 
            T.obj.appendChild(document.createTextNode( "" ));
    }
    
    this.Setup = function()
    {
        T.obj.onclick=T.Click;
        T.obj.onmouseover=T.HoverButtonIn;
        T.obj.onmouseout=T.HoverButtonOut;
    }
    
    this.Setup();
}

// --------- MULTI-TAB ---------

function SingleTab(TabSelectObject, TabDivObject)
{
    this.ID=1;
    this.TypeName="SingleTab";
    
    // Tab
    this.Desc="SingleTab";
    this.Multi=false;
    this.DefaultOpen=false;
    this.Container=null;
    this.isSelected=false;
    
    // SingleTab
    this.CssClassbase=null;
    this.CanHide=false;
    this.obj=TabSelectObject;
    this.div=TabDivObject;
    this.isContentTab=(TabDivObject!=null);
    this.isHover=false;
    this.onOpen=null;
    this.onClose=null;
    this.onClick=null;
    this.onMouseOver=null;
    this.onMouseOut=null;
    TabSelectObject.SingleTab=this;
    var T=this;
    
    // Metodi Tab
    this.Show = function()
    {
        if(T.CanHide)
        {
            T.obj.style.visibility="";
            T.obj.style.display="";
        }
    }
    
    this.Hide = function()
    {
        if(T.CanHide)
        {
            T.obj.style.visibility="hidden";
            T.obj.style.display="none";
        }
    }

    this.HideDiv = function()
    {
        if(T.isContentTab)
        {
            T.div.style.visibility="hidden";
            T.div.style.display="none";
        }
    }

    this.Open = function()
    {
        T.isSelected=true;
        T.RefreshCss();
        
        if(T.isContentTab)
        {
            T.div.style.visibility="";
            T.div.style.display="";
        }
        
        if(T.onOpen!=null) 
            T.onOpen();
    }
    
    this.Close = function()
    {
        T.isSelected=false;
        T.RefreshCss();
        
        if(T.isContentTab)
        {
            T.div.style.visibility="hidden";
            T.div.style.display="none";
        }
        
        if(T.onClose!=null) 
            T.onClose();
    }

    // Metodi SingleTab
    this.RefreshCss = function()
    {
        var ClassBase=(T.CssClassbase==null) ? T.Container.CssClassbase : T.CssClassbase ;
        if(T.isHover)
        {
            if(T.isSelected)
                T.obj.className=ClassBase+'_Selected_Hover';
            else
                T.obj.className=ClassBase+'_Hover';
        }
        else
        {
            if(T.isSelected)
                T.obj.className=ClassBase+'_Selected';
            else
                T.obj.className=ClassBase+'';
        }
    }
    
    this.HoverTabIn = function()
    {
        T.isHover=true;
        
        T.RefreshCss();

        if(T.onMouseOver!=null)
            T.onMouseOver(T);
    }
    
    this.HoverTabOut = function()
    {
        T.isHover=false;
        
        T.RefreshCss();

        if(T.onMouseOut!=null)
            T.onMouseOut(T);
    }

    this.Click = function()
    {
        if(T.isSelected) 
            return;

        if(T.onClick!=null)
            T.onClick();
        
        T.Container.ChangingTabTo(T);
    }
    
    this.obj.onclick=this.Click;
    this.obj.onmouseover=this.HoverTabIn;
    this.obj.onmouseout=this.HoverTabOut;

}

function MultiTab()
{
    this.ID=1;
    this.TypeName="MultiTab";
    
    // Tab
    this.Desc="MultiTab";
    this.Multi=true;
    this.DefaultOpen=false;
    this.Container=null;
    this.isSelected=false;

    // MultiTab
    this.CssClassbase='TabSelect1';
    this.InnerTab=new Array();
    this.OpenedTab=null;
    this.OpenedTabDefault=null;
    this.OpenedTabInitial=null;
    var T=this;

    // Metodi Tab
    this.Show = function()
    {
        for(var i=0;i<T.InnerTab.length;i++)
        {
            T.InnerTab[i].Show();
        }
    }
    
    this.Hide = function()
    {
        for(var i=0;i<T.InnerTab.length;i++)
        {
            T.InnerTab[i].Hide();
        }
    }
    
    this.Open = function()
    {
        T.Show();

        if(T.OpenedTab!=null)
        {
            T.OpenedTab.Open();
        }
        
        T.isSelected=true;
    }
    
    this.Close = function()
    {     
        if(T.OpenedTabInitial!=null)
        {
            T.OpenedTabInitial.Close();
            T.OpenedTabInitial=null;
        }

        if(T.OpenedTab!=null)
        {
            T.OpenedTab.Close();
        }
        T.OpenedTab=null;
        
        T.Hide();
        
        T.isSelected=false;
    }
    
    // Metodi MultiTab
    this.Add_Tab = function(Tab)
    {
        Tab.Container=T;
        T.InnerTab[T.InnerTab.length]=Tab;
        if(Tab.DefaultOpen)
            T.OpenedTabDefault=Tab;
    }
    
    this.Add_Tab_Array = function(TabArray)
    {
        for(var i=0;i<TabArray.length;i++)
        {
            T.Add_Tab(TabArray[i]);
        }
    }
    
    // Metodi MultiTab / Container
    this.ChangingTabTo = function(obj)
    {
        if(T.isSelected)
        {
            if(T.OpenedTab!=null)
            {
                T.OpenedTab.Close();
            }
        }
        else
        {
            T.Container.ChangingTabTo(T);
        }
        
        if(obj.Multi)
        {
            T.OpenedTab=obj;
            T.OpenedTab.Open();
        }
        else
        {
            if(obj.isContentTab)
            {
                T.OpenedTab=obj;
                T.OpenedTab.Open();
            }
            else
            {
                T.OpenedTab=T.OpenedTabDefault;
                T.OpenedTabDefault.Open();
                T.OpenedTabInitial=obj;
                T.OpenedTabInitial.Open();
            }
        }
    }
}

// --------- GRID ---------

function GridRow(Item, Row, CommandButton)
{
    this.ID=Item.ID;
    this.TypeName="GridRow";
    
    var T=this;
    var RowLoaded=false;
    this.RowIndex=0;

    // Proprieta
    this.isEditMode=false;
    this.isHover=false;
    this.CanHover=true;
    this.CanClick=true;
    this.CssClassbase='Grid1';
    this.CssClassbaseStandard='Grid1';
    this.Container=null;
    
    // Oggetti
    this.DataItem=Item;
    this.RowObj=Row;
    this.CommandObj1=CommandButton;
    this.CommandObj2=null;
    this.CommandObj3=null;
    this.CommandObj4=null;
    this.Enabled=true;
    this.CheckBox=null;
    
    // Eventi
    this.onClick=null;
    this.onCommand=null;
    this.onCommand2=null;
    this.onCommand3=null;
    this.onCommand4=null;
    this.onMouseOver=null;
    this.onMouseOut=null;
    this.onEditMode=null;
    this.onViewMode=null;
    this.onCellClick=null;
    
    // Events Handlers
    
    this.HoverRowIn = function()
    {
        if(T.Container.onRowOver!=null)
            T.Container.onRowOver(T);
            
        if(!T.CanHover)
            return;

        T.isHover=true;

        T.RefreshCss();
        
        if(T.onMouseOver!=null)
            T.onMouseOver();
    }
    
    this.HoverRowOut = function()
    {
        if(T.Container.onRowOut!=null)
            T.Container.onRowOut(T);
            
        if(!T.CanHover)
            return;

        T.isHover=false;
        
        T.RefreshCss();
        
        if(T.onMouseOut!=null)
            T.onMouseOut();
    }
    
    this.RefreshCss = function()
    {
        var ClassBase=T.CssClassbase;
        var ClassbaseStandard=T.CssClassbaseStandard
        if(!T.Enabled)
        {
            var s=T.RowObj.className=ClassbaseStandard;
            s=s.replace("_Alt","");
            T.RowObj.className=s+'_Disabled';
            return;
        }
        if(T.isHover && T.CanHover)
        {
            if(T.isEditMode)
                T.RowObj.className=ClassBase+'_Selected_Hover';
            else
                T.RowObj.className=ClassBase+'_Hover';
        }
        else
        {
            if(T.isEditMode)
                T.RowObj.className=ClassBase+'_Selected';
            else
                T.RowObj.className=ClassbaseStandard+'';
        }
    }

    this.RowClick = function()
    {
        if(!T.CanClick)
            return;
            
        if(T.onClick!=null)
            T.onClick();
        
        if(T.Container.onRowClick!=null)
            T.Container.onRowClick(T);
    }
    
    this.CellClick = function()
    {
        if(T.onCellClick!=null)
            T.onCellClick();
    }
    
    this.SetupRow = function()
    {
        var step=0;
        if(T.RowObj!=null)
        {
            T.RowObj.onclick=T.RowClick;
            T.RowObj.onmouseover=T.HoverRowIn;
            T.RowObj.onmouseout=T.HoverRowOut;
            step++;
        }
        if(T.CommandObj1!=null)
        {
            T.CommandObj1.onClick=T.onCommand;
            T.CommandObj1.Container=T;
            step++;
        }
        if(T.CommandObj2!=null)
        {
            T.CommandObj2.onClick=T.onCommand2;
            T.CommandObj2.Container=T;
            step++;
        }
        if(T.CommandObj3!=null)
        {
            T.CommandObj3.onClick=T.onCommand3;
            T.CommandObj3.Container=T;
            step++;
        }
        if(T.CommandObj4!=null)
        {
            T.CommandObj4.onClick=T.onCommand4;
            T.CommandObj4.Container=T;
            step++;
        }
        if(step>=2) RowLoaded=true;
    }
    
    this.SetupRow();

    // Metodi
    
    this.DisableRow = function()
    {
        T.CanHover=false;
        T.isHover=false;
        T.isEditMode=false;
        T.Enabled=false;
        if(T.CommandObj1!=null)
        {
            T.CommandObj1.Disattiva();
            T.CommandObj1.RefreshCss();
        }
        if(T.CommandObj2!=null)
        {
            T.CommandObj2.Disattiva();
            T.CommandObj2.RefreshCss();
        }
        if(T.CommandObj3!=null)
        {
            T.CommandObj3.Disattiva();
            T.CommandObj3.RefreshCss();
        }
        if(T.CommandObj4!=null)
        {
            T.CommandObj4.Disattiva();
            T.CommandObj4.RefreshCss();
        }
        T.RefreshCss();
    }
    
    this.EnableRow = function()
    {
        T.CanHover=true;
        T.isHover=true;
        T.isEditMode=false;
        T.Enabled=true;
        if(T.CommandObj1!=null)
        {
            T.CommandObj1.Attiva();
            T.CommandObj1.RefreshCss();
        }
        if(T.CommandObj2!=null)
        {
            T.CommandObj2.Attiva();
            T.CommandObj2.RefreshCss();
        }
        if(T.CommandObj3!=null)
        {
            T.CommandObj3.Attiva();
            T.CommandObj3.RefreshCss();
        }
        if(T.CommandObj4!=null)
        {
            T.CommandObj4.Attiva();
            T.CommandObj4.RefreshCss();
        }
        T.RefreshCss();
    }
    
    this.ToEditMode = function()
    {
        if(T.isEditMode) return;
        
        T.isEditMode=true;
        
        T.RefreshCss();
        
        if(T.onEditMode!=null)
            T.onEditMode();
    }
    
    this.ToViewMode = function()
    {
        if(!T.isEditMode) return;
        
        T.isEditMode=false;
        
        T.RefreshCss();
        
        if(T.onViewMode!=null)
            T.onViewMode();
    }
}

function GridItem(_id)
{
    var T=this;
    
    // Proprieta:
    this.ID=_id;
    this.TypeName="GridItem";
    
    this.SL_Used_Index=_id;
    this.SheetListIndex=new Array();
    this.SheetListDisabled=new Array();
    this.SheetListRow=new Array();
    
    // Metodi:
    this.PropValue = function(objPropName, Tobj)
    {
        if(objPropName=="")
        {
            return "";
        }
        var propValue;
        if(Tobj)
            eval("try { propValue=Tobj."+objPropName+"; } catch(e) {}");
        else
            eval("try { propValue=T."+objPropName+"; } catch(e) {}");
        return propValue;
    }
    this.PropHeader = function(objPropName)
    {
        return objPropName;
    }
    this.PropPrint = function(msg)
    {
        return msg;
    }
}

function SetGridItem(item, _id)
{
    item.T=item;
    item.ID=_id;
    item.TypeName="GridItem";
    
    item.SL_Used_Index=_id;
    item.SheetListIndex=new Array();
    item.SheetListDisabled=new Array();
    item.SheetListRow=new Array();
    
    // Metodi:
    item.PropValue = function(objPropName, Tobj)
    {
        if(objPropName=="")
        {
            return "";
        }
        var propValue;
        if(Tobj)
            eval("try { propValue=Tobj."+objPropName+"; } catch(e) {}");
        else
            eval("try { propValue=T."+objPropName+"; } catch(e) {}");
        return propValue;
    }
    item.PropHeader = function(objPropName)
    {
        return objPropName;
    }
    item.PropPrint = function(msg)
    {
        return msg;
    }
}

function GridPage(_id)
{
    var T=this;
    
    this.ID=_id;
    this.TypeName="GridPage";
    
    this.RowsArray=null;
    this.ItemsArray=null;
    
    this.GVTable=null;
    this.GVTHead=null;
    this.GVTrHead=null;
    this.GVTh=new Array();
    this.GVTBody=null;    
}

function GridView(DivElement, _id)
{
    this.ID=_id;
    this.TypeName="GridView";
    
    var T=this;

    // Proprieta
    this.BindRequired=true;
    this.DataBound=false;
    this.ShowCommandColumn=true;
    this.ShowHeader=true;
    this.CommandText="Esegui";
    this.CommandText2="X";
    this.CommandText3="X";
    this.CommandText4="X";
    this.CommandCssClass="CommandGV";
    this.CssClass="GridViewStyle1";
    this.CurEditRow=null;
    this.Columns=new Array(); 
    this.ColumnsHeader=new Array(); 
    this.RowCanHover=true;
    
    // Oggetti
    this.RowsArray=null;
    this.ItemsArray=null;
    this.DivElementObj=DivElement;
    
    // Eventi
    this.onDataBound=null;
    this.onItemPrinting=null;
    this.onCommand=null;
    this.onCommand2=null;
    this.onCommand3=null;
    this.onCommand4=null;
    this.CustomRowBindHtml=null;
    this.CustomRowBindDOM=null;
    this.onRowOver=null;
    this.onRowOut=null;
    this.onRowClick=null;
    this.onRowSwap=null;
    this.onCellClick=null;
    this.onRowChkClick=null;
    this.CustomCommand=null;
    this.CustomCommand2=null;
    this.CustomCommand3=null;
    this.CustomCommand4=null;
    
    
    // paging
    this.Paging=false;
    this.PageCache=new Array();
    this.page=0;
    this.totpage=0;
    this.totrecord=0;
    this.pagesize=20;
    this.PGIndietro;
    this.PGNum;
    this.PGAvanti;
    this.onDataBindPageCall=null;
    this.RequirePageCallBackEvent=null;
    this.RequirePageCallBackEventArgs=null;
        
    // bing objs
    this.GVTable=null;
    this.GVTHead=null;
    this.GVTrHead=null;
    this.GVTh=new Array();
    this.GVTBody=null;    
    this.LastTR=null;
    this.TRSpawn=0;
    this.TRSpawnIndex=-1;
    
    // BIND METHODS
    
    this.UnBind = function()
    {
        T.DataBound = false;
        if(T.Paging)
        {
            T.PageCache=new Array();
            T.RowsArray=new Array();
            T.ItemsArray=new Array();
            T.page=0;
            T.totpage=0;
            T.totrecord=0;
        }
    }
    
    this.Clear = function()
    {
        while (T.DivElementObj.hasChildNodes()) {
		    T.DivElementObj.removeChild(T.DivElementObj.firstChild);
	    }
    }
    
    this.DataBind_End = function()
    {
        T.DataBound=true;
        
        if(T.Paging)
        {
            var CurPage=new GridPage(T.page);
           
            CurPage.RowsArray=T.RowsArray;
            CurPage.ItemsArray=T.ItemsArray;
            
            CurPage.GVTable=T.GVTable;
            CurPage.GVTHead=T.GVTHead;
            CurPage.GVTrHead=T.GVTrHead;
            CurPage.GVTh=T.GVTh;
            CurPage.GVTBody=T.GVTBody;
           
            T.PageCache[T.page]=CurPage;
            
            T.PageBind();
        }
        
        if(T.onDataBound!=null)
            T.onDataBound();

        T.BindRequired=false;
        
        return true;
    }

    this.DataBindPage = function()
    {
        var CurPage=T.PageCache[T.page];
        
        if(CurPage && CurPage!=null)
        {
            T.RowsArray=CurPage.RowsArray;
            T.ItemsArray=CurPage.ItemsArray;
            
            T.GVTable=CurPage.GVTable;
            T.GVTHead=CurPage.GVTHead;
            T.GVTrHead=CurPage.GVTrHead;
            T.GVTh=CurPage.GVTh;
            T.GVTBody=CurPage.GVTBody;
            
            T.DataBindHtml();
            
            T.PageBind();
            if(T.RequirePageCallBackEvent!=null)
            {
                T.RequirePageCallBackEvent(T.RequirePageCallBackEventArgs);
            }
        }
        else
        {
            T.DataBindPageCall();
        }
    }
    
    this.DataBindPageCallBack = function(itemsArr, totrecord)
    {
        T.totrecord=totrecord;
        T.DataBind(itemsArr);
        if(T.RequirePageCallBackEvent!=null)
        {
            T.RequirePageCallBackEvent(T.RequirePageCallBackEventArgs);
        }
    }
    
    this.DataBindPageCall = function()
    {
        if(T.onDataBindPageCall!=null)
        {
            T.onDataBindPageCall(T.page*T.pagesize, T.pagesize, T.DataBindPageCallBack);
        }
    }
    
    this.DataBindHtml = function()
    {
        while (T.DivElementObj.hasChildNodes()) {
		    T.DivElementObj.removeChild(T.DivElementObj.firstChild);
	    }
	    
	    T.DivElementObj.appendChild(T.GVTable);
    }

    this.DataBind = function(itemsArr)
    {
        if(itemsArr==null) return false;
        
        var i,j;
        
        T.GVTable=document.createElement("table");
        T.GVTable.className=T.CssClass;
        T.GVTable.id='GVTable'+T.ID;
        T.LastTR=null;
        T.TRSpawnIndex=-1;
        
        if(itemsArr.length==0 || T.Columns.length==0)
        {
            var thead=document.createElement("thead");
            var tr=document.createElement("tr");
            tr.className=T.CssClass;
            tr.id='GVTrHead'+T.ID;
            
            var th = document.createElement("th");
            th.className=T.CssClass;
            th.appendChild( document.createTextNode( " - " ) );
            
            tr.appendChild(th);
            thead.appendChild(tr);
            T.GVTable.appendChild(thead);
            
            T.DataBindHtml();

            T.ItemsArray=itemsArr;
            T.DataBind_End();
            return false;    
        }
        
        
        if(T.ShowHeader)
        {
            T.GVTHead=document.createElement("thead");
            
            T.GVTrHead=document.createElement("tr");
            T.GVTrHead.className=T.CssClass;
            T.GVTrHead.id='GVTrHead'+T.ID;
            for(j=0;j<T.Columns.length;j++)
            {
                if(T.Columns[j]==null) 
                    continue;
                    
                T.GVTh[i]=document.createElement("th");
                T.GVTh[i].className=T.CssClass;
                T.GVTh[i].id='GVTh'+T.ID+'_C'+j;

                var printed=false;
                if(j<T.ColumnsHeader.length)
                    if(T.ColumnsHeader[j]!=null)
                    {
                        T.GVTh[i].appendChild(document.createTextNode( T.ColumnsHeader[j] ));
                        printed=true;
                    }
                if(!printed)
                {
                    if(T.Columns[j]=="_COMMAND1_" || T.Columns[j]=="_COMMAND2_" || T.Columns[j]=="_COMMAND3_" || T.Columns[j]=="_COMMAND4_" )
                        ;
                    else
                        T.GVTh[i].appendChild(document.createTextNode( itemsArr[0].PropHeader(T.Columns[j]) ));
                }
                
                T.GVTrHead.appendChild(T.GVTh[i]);
            }
            T.GVTHead.appendChild(T.GVTrHead);
            
            T.GVTable.appendChild(T.GVTHead);
        }
        
        T.RowsArray = new Array();
        
        T.GVTBody=document.createElement("tbody");
        for(i=0;i<itemsArr.length;i++)
        {
            if(itemsArr[i]==null)
                continue;

            T.RowBindDOM(itemsArr[i],i);
        }
        T.GVTable.appendChild(T.GVTBody);
        
        T.DataBindHtml();
        
        T.ItemsArray=itemsArr;
        
        T.BindRequired=false;
        
        return T.DataBind_End();
    }
    
    
    this.RowBindDOM = function(item, i)
    {
        if(item==null)
            return;
            
        if(T.onItemPrinting!=null)
            T.onItemPrinting(item);

        if(T.CustomRowBindDOM!=null)
        {
            T.CustomRowBindDOM(T,item,i);
            return;
        }
        
        var tr;
        var td;
        var span;
        var cmd1=null,cmd2=null,cmd3=null,cmd4=null;

        var tr=null;
        if(T.TRSpawnIndex>=T.TRSpawn || T.TRSpawnIndex<0 || T.LastTR==null)
        {
            tr=T.GVTable.insertRow(-1);
            tr.className=T.CssClass;
            tr.id='GVTr'+T.ID+'_'+i;
            T.LastTR=tr;
            T.TRSpawnIndex=0;
        }
        else
        {
            tr=T.LastTR;
            T.TRSpawnIndex++;
        }
        
        var gRow=new GridRow(item, tr, null );
        tr.gRow=gRow;
        
        for(j=0;j<T.Columns.length;j++)
        {
            if(T.Columns[j]==null) 
                continue;
                
            td=tr.insertCell(-1);
            td.className=T.CssClass+'_'+j;
            td.id='GVTd'+T.ID+'_C'+j+'_'+i;
            
            if(T.Columns[j]=="_COMMAND1_")
            {
                if(T.ShowCommandColumn)
                {
                    span = document.createElement("span");
		        	span.id = 'GVCmd1_'+T.ID+'_'+i;

                    var value=T.CommandText;
                    if(isFunction(value))
                    {
                        value=value();
                    }
                    
        			if(isString(value))
                        span.appendChild(document.createTextNode( value ));
                    else if(isObject(value))
                        span.appendChild( value );
                    else 
                        span.appendChild(document.createTextNode( "" ));
        			
        			cmd1=span;
        			td.appendChild(span);
                }
            }
            else if(T.Columns[j]=="_COMMAND2_")
            {
                if(T.ShowCommandColumn)
                {
                    span = document.createElement("span");
		        	span.id = 'GVCmd2_'+T.ID+'_'+i;
		        	
        			var value=T.CommandText2;
                    if(isFunction(value))
                    {
                        value=value();
                    }
                    
        			if(isString(value))
                        span.appendChild(document.createTextNode( value ));
                    else if(isObject(value))
                        span.appendChild( value );
                    else 
                        span.appendChild(document.createTextNode( "" ));
        			
        			cmd2=span;
        			td.appendChild(span);
                }
            }
            else if(T.Columns[j]=="_COMMAND3_")
            {
                if(T.ShowCommandColumn)
                {
                    span = document.createElement("span");
		        	span.id = 'GVCmd3_'+T.ID+'_'+i;
        			
        			var value=T.CommandText3;
                    if(isFunction(value))
                    {
                        value=value();
                    }
                    
        			if(isString(value))
                        span.appendChild(document.createTextNode( value ));
                    else if(isObject(value))
                        span.appendChild( value );
                    else 
                        span.appendChild(document.createTextNode( "" ));
        			
        			cmd3=span;
        			td.appendChild(span);
                }
            }
            else if(T.Columns[j]=="_COMMAND4_")
            {
                if(T.ShowCommandColumn)
                {
                    span = document.createElement("span");
		        	span.id = 'GVCmd4_'+T.ID+'_'+i;
		        	
        			var value=T.CommandText4;
                    if(isFunction(value))
                    {
                        value=value();
                    }
                    
        			if(isString(value))
                        span.appendChild(document.createTextNode( value ));
                    else if(isObject(value))
                        span.appendChild( value );
                    else 
                        span.appendChild(document.createTextNode( "" ));
        			
        			cmd4=span;
        			td.appendChild(span);
                }
            }
            else
            {
                var value=item.PropValue(T.Columns[j], item);
                if(value)
                {
                    if(isFunction(value))
                    {
                        value=value();
                    }
                    
                    if(isString(value))
                        td.appendChild(document.createTextNode( value ));
                    else if(isObject(value))
                    {
                        td.appendChild( value );
                        if(value.CellClick)
                        {
                            td.onclick=gRow.CellClick;
                            td.style.cursor='pointer';
                        }
                    }
                    else 
                        td.appendChild(document.createTextNode( "" ));
                }
                else
                {
                    td.appendChild(document.createTextNode( "" ));
                }
            }
            
        }
        
        
        var cmdbut1=null;
        var cmdbut2=null;
        var cmdbut3=null;
        var cmdbut4=null;
        
        var Disabled=item.SheetListDisabled[T.ID];
        
        if(cmd1!=null) 
        {
            cmdbut1 = new StateButton(cmd1);
            cmdbut1.AutoHideOnClick=false;
            cmdbut1.CssClassbase=T.CommandCssClass;
        }
        
        gRow.CommandObj1=cmdbut1;
        gRow.RowIndex=i;
        gRow.CssClassbase=T.CssClass;
        gRow.CanHover=T.RowCanHover;
        item.SheetListRow[T.ID]=gRow;
        
        if(cmd2!=null)
        {
            cmdbut2 = new StateButton(cmd2);
            cmdbut2.AutoHideOnClick=false;
            cmdbut2.CssClassbase=T.CommandCssClass;
            
            gRow.CommandObj2=cmdbut2;
            gRow.onCommand2=T.onCommand2;
        }
        if(cmd3!=null)
        {
            cmdbut3 = new StateButton(cmd3);
            cmdbut3.AutoHideOnClick=false;
            cmdbut3.CssClassbase=T.CommandCssClass;
            
            gRow.CommandObj3=cmdbut3;
            gRow.onCommand3=T.onCommand3;
        }
        if(cmd4!=null)
        {
            cmdbut4 = new StateButton(cmd4);
            cmdbut4.AutoHideOnClick=false;
            cmdbut4.CssClassbase=T.CommandCssClass;
            
            gRow.CommandObj4=cmdbut4;
            gRow.onCommand4=T.onCommand4;
        }
        
        if(Disabled==true)
        {
            gRow.DisableRow();
        }
        else
        {
            if(cmdbut1!=null) 
            {   
                cmdbut1.Attiva();
                cmdbut1.RefreshCss();
            }
            if(cmdbut2!=null) 
            {   
                cmdbut2.Attiva();
                cmdbut2.RefreshCss();
            }
            if(cmdbut3!=null) 
            {   
                cmdbut3.Attiva();
                cmdbut3.RefreshCss();
            }
            if(cmdbut4!=null) 
            {   
                cmdbut4.Attiva();
                cmdbut4.RefreshCss();
            }
        
            if(i%2==0) 
                gRow.CssClassbaseStandard=T.CssClass;
            else
                gRow.CssClassbaseStandard=T.CssClass+'_Alt';
        }
        gRow.Container=T;
        gRow.onCommand=T.onCommand;
        gRow.onCellClick=T.onCellClick;
        gRow.SetupRow();
        gRow.RefreshCss();            
        if(cmdbut1!=null)
            cmdbut1.Setup();
            
        if(T.RowsArray==null) T.RowsArray=new Array();
        T.RowsArray[i] = gRow;
        
    }
        
    
    this.AddRow = function(item)
    {
        if(T.Paging)
        {
            T.totrecord++;
            
            if(T.ItemsArray.length>=T.pagesize)
            {
                T.page++;
                var itemarray=new Array();
                itemarray[0]=item;
                
                T.DataBind(itemarray);
                
                return 0;
            }
        }
                
        var index=T.ItemsArray.length;
        
        T.ItemsArray[index]=item;
        
        T.RowBindDOM(item, index);
        
        return index;
    }
    
    this.GetLastRow = function()
    {
        if(T.RowsArray==null) 
            return null;
            
        var index=T.RowsArray.length-1;
        
        if(index<0)
            return null;
        
        return T.RowsArray[index];
    }
    
    // ----------
    
    this.EditThisRow = function(gRow)
    {
        if(T.CurEditRow!=null)
            T.CurEditRow.ToViewMode();
        
        T.CurEditRow=gRow;
        T.CurEditRow.ToEditMode();
    }
    
    this.DisableRow = function(cssTag, sheetList)
    {
        try{
            T.RowsArray[cssTag.SheetListIndex[sheetList.ID]].DisableRow();
        } 
        catch(e) {}
    }
    
    this.EnableRow = function(cssTag, sheetList)
    {
        try{
            T.RowsArray[cssTag.SheetListIndex[sheetList.ID]].EnableRow();
        } 
        catch(e) {}
    }
    
    
    this.UnEditCurEditRow = function()
    {
        if(T.CurEditRow!=null)
            T.CurEditRow.ToViewMode();
        T.CurEditRow=null;
    }
  
    this.Show = function()
    {
        T.DivElementObj.style.visibility="";
        T.DivElementObj.style.display="";
    }

    this.Hide = function()
    {
        T.DivElementObj.style.visibility="hidden";
        T.DivElementObj.style.display="none";
    }
    
    this.SetRowCanHover = function(value)
    {
        T.RowCanHover=value;
        for(var i=0;i<T.RowsArray.length;i++)
        {
            T.RowsArray[i].CanHover=T.RowCanHover;
        }
    }

    // row positioning 
    
    this.RowUp = function(gRow)
    {
        if(gRow.RowIndex==0)
        {
            T.RequirePageCallBackEvent=T.RowSwapNextPage;
            T.RequirePageCallBackEventArgs=T.page-1;
            
            
            T.PageIn();
        }
        else
        {
            T.RowShift(gRow,-1);
        }
    }
    
    this.RowDown = function(gRow)
    {
        if(gRow.RowIndex>=T.ItemsArray.length-1)
        {
            T.RequirePageCallBackEvent=T.RowSwapNextPage;
            T.RequirePageCallBackEventArgs=T.page;

            T.PageAv();
        }
        else
        {
            T.RowShift(gRow,1);
        }

    }
    
    this.RowSwapNextPage = function(pgindex)
    {
        T.RequirePageCallBackEvent=null;
        
        var CurPage=T.PageCache[pgindex];
        var NextPage=T.PageCache[pgindex+1];
        
        if(CurPage && NextPage)
        {
            var tmp;
            var index = CurPage.ItemsArray.length-1;

            tmp=CurPage.ItemsArray[index];
            CurPage.ItemsArray[index]=NextPage.ItemsArray[0];
            NextPage.ItemsArray[0]=tmp;
            
            tmp=CurPage.RowsArray[index];
            CurPage.RowsArray[index]=NextPage.RowsArray[0];
            NextPage.RowsArray[0]=tmp;
            
            CurPage.RowsArray[index].RowIndex=index;
            NextPage.RowsArray[0].RowIndex=0;
            
            var row1=CurPage.GVTable.rows[index+1];
            var row2=NextPage.GVTable.rows[1];
            
            DOM_swap(row1,row2);
            
            if(T.onRowSwap!=null)
                T.onRowSwap(CurPage.RowsArray[index],NextPage.RowsArray[0]);
        }
        
    }
    
    this.RowMove = function(gRow, gRowEnd)
    {
        var index1=gRow.RowIndex;
        var index2=gRowEnd.RowIndex;
        var value=index2-index1;
        
        T.RowShift(gRow, value);
    }
    
    this.RowShift = function(gRow, value)
    {
        if(value==0) return false;
        var index=gRow.RowIndex;
        
        if(index>=0 && index<=T.ItemsArray.length)
        {
            var tmp;
            var p=1;
            if(value<0) 
            { 
                p=-1; 
                value=value*p; 
            }
            
            for(var i=0;i<value;i++)
            {
                var index0=index+p;
                
                if(index0<0 || index0>=T.ItemsArray.length) continue;
                
                tmp=T.ItemsArray[index0];
                T.ItemsArray[index0]=T.ItemsArray[index];
                T.ItemsArray[index]=tmp;
                
                tmp=T.RowsArray[index0];
                T.RowsArray[index0]=T.RowsArray[index];
                T.RowsArray[index]=tmp;
                
                T.RowsArray[index0].RowIndex=index0;
                T.RowsArray[index].RowIndex=index;
                
                var row=T.GVTable.rows[index+1];
                
                if(p<0)
                    DOM_moveUp(row);
                else
                    DOM_moveDown(row);
                
                if(T.onRowSwap!=null)
                    T.onRowSwap(T.RowsArray[index],T.RowsArray[index0]);
                
                index=index0;
	        }
	        return true;
        }
        return false;
    }
    
    
    // paging
    
    this.PageSetup = function(idin, idav, idinfo, cssclass)
    {
        T.PGIndietro = new StateButton(ffz_GetObj(idin));
        T.PGIndietro.CssClassbase=cssclass;
        T.PGIndietro.AutoHideOnClick=false;
        T.PGIndietro.onClick=T.PageIn;
        T.PGIndietro.Disattiva();
        
        T.PGAvanti = new StateButton(ffz_GetObj(idav));
        T.PGAvanti.CssClassbase=cssclass;
        T.PGAvanti.AutoHideOnClick=false;
        T.PGAvanti.onClick=T.PageAv;
        T.PGAvanti.Disattiva();
        
        if(idinfo!='')
            T.PGNum = ffz_GetObj(idinfo);
        else
            T.PGNum=null;
    }
    
    this.PageBind = function()
    {
        T.totpage=parseInt(""+(T.totrecord-1)/T.pagesize);
        
        if(T.page<0) T.page=0;
        if(T.page>T.totpage) T.page=T.totpage;
                
        if(T.page>0)
            T.PGIndietro.Attiva();
        else
            T.PGIndietro.Disattiva();
        if(T.page<T.totpage) 
            T.PGAvanti.Attiva();
        else
            T.PGAvanti.Disattiva();
        
        if(T.PGNum!=null)
        {
            while (T.PGNum.hasChildNodes()) {
		        T.PGNum.removeChild(T.PGNum.firstChild);
	        }
    	    
	        T.PGNum.appendChild(document.createTextNode( " | "+(T.page+1)+" / "+(T.totpage+1)+" | " ));    
	    }

    }
    this.PageIn = function()
    {
        if(T.page<=0) 
        {
            T.page=0;
            return false;
        }
        T.page--;

        T.DataBindPage();
        return true;
    }
    this.PageAv = function()
    {
        if(T.page>=T.totpage) 
        {
            T.page=T.totpage;
            return false;
        }
        T.page++;

        T.DataBindPage();
        return true;
    }
    this.PageLast = function()
    {       
        T.page=T.totpage;
        
        if(T.page<0) 
            T.page=0;
            
        T.DataBindPage();
        return true;
    }
    
    // Parse DIV Element
    
    this.ParseDivDOM = function(itemObj)
    {
        T.GVTable=ffz_GetObj('GVTable'+T.ID);
        
        T.RowsArray = new Array();
        T.ItemsArray = new Array();
        
        var found=true;
                
        var i=0;
        while(found)
        {
            if(!itemObj || itemObj==null)
                found=T.ParseRowDOM(i, GridItem);
            else
                found=T.ParseRowDOM(i, itemObj);
            i++;
            
        }

        T.BindRequired=false;
            
        return true;
    }
    
    
    this.ParseRowDOM = function(i, itemObj)
    {
        var tr;
        var td;
        var span;
        var cmd1=null,cmd2=null,cmd3=null,cmd4=null;
    
        var tr=ffz_GetObj('GVTr'+T.ID+'_'+i);

        if(tr==null) return false;
    
        var itemid=ffz_GetObj('GVID'+T.ID+'_'+i);

        var item;
        if(itemid==null)
            item=new itemObj(0);
        else
            item=new itemObj(itemid.value);
        
        item.Data1=ffz_GetObj('GVData1'+T.ID+'_'+i);
        item.Data2=ffz_GetObj('GVData2'+T.ID+'_'+i);
        item.Data3=ffz_GetObj('GVData3'+T.ID+'_'+i);
        
        var gRow=new GridRow(item, tr, null );
        tr.gRow=gRow;
        
        for(j=0;j<T.Columns.length;j++)
        {
            td=ffz_GetObj('GVTd'+T.ID+'_C'+j+'_'+i);
            
            if(td==null) 
                continue;
            if(T.Columns[j]==null) 
                continue;
            
            T.CssClass=td.className;
            
            if(T.Columns[j]=="_COMMAND_CHK_")
            {
                var chk = document.createElement("input");
                chk.type='checkbox';
                chk.id='GVCHK'+T.ID+'_'+i
                
                if(T.onRowChkClick!=null)
                {
                    chk.onchange=T.onRowChkClick;
                    chk.onclick=chk.onchange;
                }

                gRow.CheckBox=chk;
                
                td.appendChild(chk);
            }
            else if(T.Columns[j]=="_COMMAND1_")
            {
                if(T.ShowCommandColumn)
                {
                    if(T.CustomCommand!=null)
                    {
                        span = T.CustomCommand(T.ID, i, gRow);
		        	    span.id = 'GVCmd1_'+T.ID+'_'+i;
                    }
                    else
                    {
                        span = document.createElement("span");
		        	    span.id = 'GVCmd1_'+T.ID+'_'+i;
                    }
                    
                    var value=T.CommandText;
                    if(isFunction(value))
                    {
                        value=value();
                    }
                    
        			if(isString(value))
                        span.appendChild(document.createTextNode( value ));
                    else if(isObject(value))
                        span.appendChild( value );
                    else 
                        span.appendChild(document.createTextNode( "" ));
        			
        			cmd1=span;
        			td.appendChild(span);
                }
            }
            else if(T.Columns[j]=="_COMMAND2_")
            {
                if(T.ShowCommandColumn)
                {
                    if(T.CustomCommand2!=null)
                    {
                        span = T.CustomCommand2(T.ID, i, gRow);
		        	    span.id = 'GVCmd2_'+T.ID+'_'+i;
                    }
                    else
                    {
                        span = document.createElement("span");
		        	    span.id = 'GVCmd2_'+T.ID+'_'+i;
                    }
                    
        			var value=T.CommandText2;
                    if(isFunction(value))
                    {
                        value=value();
                    }
                    
        			if(isString(value))
                        span.appendChild(document.createTextNode( value ));
                    else if(isObject(value))
                        span.appendChild( value );
                    else 
                        span.appendChild(document.createTextNode( "" ));
        			
        			cmd2=span;
        			td.appendChild(span);
                }
            }
            else if(T.Columns[j]=="_COMMAND3_")
            {
                if(T.ShowCommandColumn)
                {
                    if(T.CustomCommand3!=null)
                    {
                        span = T.CustomCommand3(T.ID, i, gRow);
		        	    span.id = 'GVCmd3_'+T.ID+'_'+i;
                    }
                    else
                    {
                        span = document.createElement("span");
		        	    span.id = 'GVCmd3_'+T.ID+'_'+i;
                    }
                    
        			var value=T.CommandText3;
                    if(isFunction(value))
                    {
                        value=value();
                    }
                    
        			if(isString(value))
                        span.appendChild(document.createTextNode( value ));
                    else if(isObject(value))
                        span.appendChild( value );
                    else 
                        span.appendChild(document.createTextNode( "" ));
        			
        			cmd3=span;
        			td.appendChild(span);
                }
            }
            else if(T.Columns[j]=="_COMMAND4_")
            {
                if(T.ShowCommandColumn)
                {
                    if(T.CustomCommand4!=null)
                    {
                        span = T.CustomCommand4(T.ID, i, gRow);
		        	    span.id = 'GVCmd4_'+T.ID+'_'+i;
                    }
                    else
                    {
                        span = document.createElement("span");
		        	    span.id = 'GVCmd4_'+T.ID+'_'+i;
                    }
		        	
        			var value=T.CommandText4;
                    if(isFunction(value))
                    {
                        value=value();
                    }
                    
        			if(isString(value))
                        span.appendChild(document.createTextNode( value ));
                    else if(isObject(value))
                        span.appendChild( value );
                    else 
                        span.appendChild(document.createTextNode( "" ));
        			
        			cmd4=span;
        			td.appendChild(span);
                }
            }
            else
            {
                if(T.Columns[j])
                {
                    var value=item.PropValue(T.Columns[j], item);
                    if(value)
                    {
                        if(isFunction(value))
                        {
                            value=value();
                        }
                        
                        if(isString(value))
                            td.appendChild(document.createTextNode( value ));
                        else if(isObject(value))
                        {
                            td.appendChild( value );
                            if(value.CellClick)
                            {
                                td.onclick=gRow.CellClick;
                                td.style.cursor='pointer';
                            }
                        }
                        else 
                            td.appendChild(document.createTextNode( "" ));
                    }
                    else
                    {
                        td.appendChild(document.createTextNode( "" ));
                    }
                }
            }
            
        }
        
        var cmdbut1=null;
        var cmdbut2=null;
        var cmdbut3=null;
        var cmdbut4=null;
        
        var Disabled=item.SheetListDisabled[T.ID];
        
        if(cmd1!=null) 
        {
            cmdbut1 = new StateButton(cmd1);
            cmdbut1.AutoHideOnClick=false;
            cmdbut1.CssClassbase=T.CommandCssClass;
        }
        
        gRow.CommandObj1=cmdbut1;
        gRow.RowIndex=i;
        gRow.CssClassbase=tr.className;
        gRow.CanHover=T.RowCanHover;
        item.SheetListRow[T.ID]=gRow;
        
        if(cmd2!=null)
        {
            cmdbut2 = new StateButton(cmd2);
            cmdbut2.AutoHideOnClick=false;
            cmdbut2.CssClassbase=T.CommandCssClass;
            
            gRow.CommandObj2=cmdbut2;
            gRow.onCommand2=T.onCommand2;
        }
        if(cmd3!=null)
        {
            cmdbut3 = new StateButton(cmd3);
            cmdbut3.AutoHideOnClick=false;
            cmdbut3.CssClassbase=T.CommandCssClass;
            
            gRow.CommandObj3=cmdbut3;
            gRow.onCommand3=T.onCommand3;
        }
        if(cmd4!=null)
        {
            cmdbut4 = new StateButton(cmd4);
            cmdbut4.AutoHideOnClick=false;
            cmdbut4.CssClassbase=T.CommandCssClass;
            
            gRow.CommandObj4=cmdbut4;
            gRow.onCommand4=T.onCommand4;
        }
        
        if(Disabled==true)
        {
            gRow.DisableRow();
        }
        else
        {
            if(cmdbut1!=null) 
            {   
                cmdbut1.Attiva();
                cmdbut1.RefreshCss();
            }
            if(cmdbut2!=null) 
            {   
                cmdbut2.Attiva();
                cmdbut2.RefreshCss();
            }
            if(cmdbut3!=null) 
            {   
                cmdbut3.Attiva();
                cmdbut3.RefreshCss();
            }
            if(cmdbut4!=null) 
            {   
                cmdbut4.Attiva();
                cmdbut4.RefreshCss();
            }
        
            if(i%2==0) 
                gRow.CssClassbaseStandard=tr.className;
            else
                gRow.CssClassbaseStandard=tr.className+'_Alt';
        }
        gRow.Container=T;
        gRow.onCommand=T.onCommand;
        gRow.onCellClick=T.onCellClick;
        gRow.SetupRow();
        gRow.RefreshCss();            
        if(cmdbut1!=null)
            cmdbut1.Setup();
        T.RowsArray[i] = gRow;
        T.ItemsArray[i] = item;
        
        return true;
    }






}

    


















// --------- SheetList ---------

function SheetList(CssTagList, Index)
{
  var T = this;
  if(!CssTagList) CssTagList=new Array();
  if(CssTagList==null) CssTagList=new Array();
  
  this.ID=Index;
  this.List=CssTagList;
  
  this.MoveElementTo = function(cssTag, sheetList)
  {
    T.RemoveElement(cssTag);
    sheetList.SetElement(cssTag);
  }
  this.CopyElementTo = function(cssTag, sheetList)
  {
    sheetList.SetElement(cssTag);
  }
  this.CopyElementToAndDisable = function(cssTag, sheetList)
  {
    if( T.DisableElement(cssTag) == false ) return false;
    if( sheetList.SetElement(cssTag) < 0) return false;
    return true;
  }
  
  
  this.EnableElement = function(cssTag)
  {
    var Pos=cssTag.SheetListIndex[T.ID];
    if(Pos<0) return;
    cssTag.SheetListDisabled[T.ID]=false;
  }
  
  this.DisableElement = function(cssTag)
  {
    var Pos=cssTag.SheetListIndex[T.ID];
    if(Pos<0) return false;
    cssTag.SheetListDisabled[T.ID]=true;
    return true;
  }
  
  this.RemoveElement = function(cssTag)
  {
    var Pos=cssTag.SheetListIndex[T.ID];
    if(Pos<0) return;
    T.List[Pos]=null;
    cssTag.SheetListIndex[T.ID]=-1;
  }
  
  this.SetElement = function(cssTag)
  {
    var Pos=cssTag.SheetListIndex[T.ID];
    if(Pos>=0) return -1;
    Pos=T.List.length;
    T.List[Pos]=cssTag;
    cssTag.SheetListIndex[T.ID]=Pos;
    return Pos;
  }
  
  this.Add = function(cssTag)
  {
    return T.SetElement(cssTag);
  }
  
  this.Length = function()
  {
    return T.List.length;
  }
  
  this.GetItemByValue = function(PropName, PropValue)
  {
    var i;
    var Value=null;
    //eval("found=false;");
    var found=false;
    
    for(i=0;i<T.List.length;i++)
    {
        var obj=T.List[i];

        try 
        {
            eval("if( ''+obj."+PropName+" == '"+PropValue+"' ) found=true; else found=false;");
        }
        catch(e) { }
        
        if(found)
            return obj;
    }
    return Value;
  }

  this.AT = function(tagName, tagSource, tag_ApplyTag, tag_ApplyArea, tag_Description)
  {
    var tag=new CssTag(-1);
    tag.tagName=tagName;
    tag.tagSource=tagSource;
    tag.tag_ApplyTag=tag_ApplyTag;
    tag.tag_ApplyArea=tag_ApplyArea;
    tag.tag_Description=tag_Description;
    if( T.SetElement(tag) <0) return null;
    return tag;
  }
}


// --------- StringBuilder ---------

// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
function StringBuilder(value)
{
    this.strings = new Array("");
    this.append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
    if (value)
    {
        this.strings.push(value);
    }
}

StringBuilder.prototype.a = function (value)
{
    if (value)
    {
        this.strings.push(value);
    }
}

// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
    this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
    return this.strings.join("");
}

// --------- HashTable ---------

Hashtable.prototype.hash	 	= null;
Hashtable.prototype.keys		= null;
Hashtable.prototype.location	= null;

function Hashtable(){
	this.hash = new Array();
	this.keys = new Array();

	this.location = 0;
}

Hashtable.prototype.put = function (key, value){
	if (value == null)
		return;

	if (this.hash[key] == null)
		this.keys[this.keys.length] = key;

	this.hash[key] = value;
}

Hashtable.prototype.get = function (key){
		return this.hash[key];
}

Hashtable.prototype.remove = function (key){
	for (var i = 0; i < this.keys.length; i++){
		if (key == this.keys[i]){
			this.hash[this.keys[i]] = null;
			this.keys.splice(i ,1);
			return;
		}
	}
}

Hashtable.prototype.size = function (){
    return this.keys.length;
}

Hashtable.prototype.next = function (){
	if (++this.location < this.keys.length)
		return true;
	else
		return false;
}

Hashtable.prototype.moveFirst = function (){
	try {
		this.location = -1;
	} catch(e) {}
}

Hashtable.prototype.moveLast = function (){
	try {
		this.location = this.keys.length - 1;
	} catch(e) {}
}

Hashtable.prototype.getKey = function (){
	try {
		return this.keys[this.location];
	} catch(e) {
		return null;
	}
}

Hashtable.prototype.getValue = function (){
	try {
		return this.hash[this.keys[this.location]];
	} catch(e) {
		return null;
	}
}

Hashtable.prototype.getKeyOfValue = function (value){
	for (var i = 0; i < this.keys.length; i++)
		if (this.hash[this.keys[i]] == value)
			return this.keys[i]
	return null;
}

Hashtable.prototype.toString = function (){

	try {
		var s = new Array(this.keys.length);
		s[s.length] = "{";

		for (var i = 0; i < this.keys.length; i++){
			s[s.length] = this.keys[i];
			s[s.length] = "=";
			var v = this.hash[this.keys[i]];
			if (v)
				s[s.length] = v.toString();
			else
				s[s.length] = "null";

			if (i != this.keys.length-1)
				s[s.length] = ", ";
		}
	} catch(e) {

	}finally{
		s[s.length] = "}";
	}

	return s.join("");
}

Hashtable.prototype.add = function(ht){
	try {
		ht.moveFirst();
		while(ht.next()){
			var key = ht.getKey();
			this.hash[key] = ht.getValue();
			if (this.get(key) != null){
				this.keys[this.keys.length] = key;
			}
		}
	} catch(e) {

	} finally {
		return this;
	}
};


// --------- DOM ---------

function DOM_swap(elem1, elem2)
{
    var elem0=elem1.previousSibling;
    elem2.parentNode.insertBefore(elem1, elem2);
    elem0.parentNode.insertBefore(elem2, elem0.nextSibling);
    
}

function DOM_moveUp(elem)
{
    if (elem.previousSibling) {  
        elem.parentNode.insertBefore(elem,elem.previousSibling);
    }
}

function DOM_moveDown(elem)
{
    if (elem.nextSibling) {  
        elem.parentNode.insertBefore(elem,elem.nextSibling.nextSibling);
    }
}

function DOM_moveLeft(columntd) {
  if (columntd.parentNode.previousSibling) {
    var n = columntd.parentNode.cellIndex;
    var i = 0;
    while (i < columntd.parentNode.parentNode.parentNode.childNodes.length) {
      var r = columntd.parentNode.parentNode.parentNode;
      r.childNodes[i].insertBefore(r.childNodes[i].childNodes[n],r.childNodes[i].childNodes[n].previousSibling);
      i++;
    }
  }
}

function moveRight(columntd) {
  if (columntd.parentNode.nextSibling) {
    var n = columntd.parentNode.cellIndex;
    var i = 0;
    while (i < columntd.parentNode.parentNode.parentNode.childNodes.length) {
      var r = columntd.parentNode.parentNode.parentNode;
      r.childNodes[i].insertBefore(r.childNodes[i].childNodes[n],r.childNodes[i].childNodes[n].nextSibling.nextSibling);
      i++;
    }
  }
}

