var LinkLineMode={ShowArrow:0,OnlyLine:1,Invisible:2,Unvisible:2};
var SchedulerItemAllows={None:0,ChangeResource:1,ChangeTime:2,ChangePeriod:4,TextEdit:8,All:15};
SchedulerRegion.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
this.collapsed=t[idx[0]++]!=0;
this.dateBegin=1000*t[idx[0]++];
this.dateEnd=1000*t[idx[0]++];
this.firstColumn=t[idx[0]++];
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new ResourceRow().Load(t,idx);
}
else obj=t[n-1];
this.firstRow=obj;
this.lastColumn=t[idx[0]++];
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new ResourceRow().Load(t,idx);
}
else obj=t[n-1];
this.lastRow=obj;
var ris=t[idx[0]++];
this.style=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.temporary=t[idx[0]++]!=0;
return this;
}

SchedulerRegion.prototype.Serialize = function(map) {
if(!map) map=[];
var r=(this.collapsed)?"T`":"`";
r+=(((this.dateBegin)/1000)+"`");
r+=(((this.dateEnd)/1000)+"`");
var obj=this.firstRow;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
r+=(iobj);
var obj=this.lastRow;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
r+=(iobj);
r+=((this.style).Serial());
return r;
}

Scheduler.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
this.GoControl_Load(t,idx);
if(31618723!=t[idx[0]++])alert(ss+'An invalid version of the script: ComponentGo.Web.Schedulers. Reload a page, please.');
this.behaviorOptions=t[idx[0]++];
var ris=t[idx[0]++];
this.bodyStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.BodyClick_serialize=function(args,map){
var s="d`";
s+=args.Action+"`";
return s;
}
this.caption=go.DeserStr(t,idx[0]++);
var ris=t[idx[0]++];
this.captionStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.CaptionClick_serialize=function(args,map){
var s="e`";
s+=args.Action+"`";
return s;
}
this.cellWidth=t[idx[0]++];
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new ResourceColumn().Load(t,idx);
}
else obj=t[n-1];
this.clickedColumn=obj;
this.clickedDateTime=1000*t[idx[0]++];
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new SchedulerItem().Load(t,idx);
}
else obj=t[n-1];
this.clickedItem=obj;
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new ResourceRow().Load(t,idx);
}
else obj=t[n-1];
this.clickedRow=obj;
this.collapsedCellWidth=t[idx[0]++];
var arr=[];
for(var length=t[idx[0]++]; --length>=0;) {
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new ResourceColumn().Load(t,idx);
}
else obj=t[n-1];
arr.push(obj);
}
this.columns=arr;
var ris=t[idx[0]++];
this.defaultItemStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.DefaultItemClick_serialize=function(args,map){
var s="f`";
s+=args.Action+"`";
return s;
}
var ris=t[idx[0]++];
this.defaultRegionStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.DefaultRegionClick_serialize=function(args,map){
var s="g`";
s+=args.Action+"`";
return s;
}
this.ButtonPressed=t[idx[0]++];
if(typeof(this.ButtonPressed)=='undefined')this.ButtonPressed=this.callback;
this.ButtonPressed_serialize=function(args,map){
var s="h`";
s+=args.Button+"`";
return s;
}
this.ColumnWidthChanged=t[idx[0]++];
if(typeof(this.ColumnWidthChanged)=='undefined')this.ColumnWidthChanged=this.callback;
this.ColumnWidthChanged_serialize=function(args,map){
var s="i`";
var obj=args.Column;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
s+=args.NewWidth+"`";
return s;
}
this.FirstDateTimeChanged=t[idx[0]++];
if(typeof(this.FirstDateTimeChanged)=='undefined')this.FirstDateTimeChanged=this.callback;
this.FirstDateTimeChanged_serialize=function(args,map){
return "j`";
}
this.ItemDragged=t[idx[0]++];
if(typeof(this.ItemDragged)=='undefined')this.ItemDragged=this.callback;
this.ItemDragged_serialize=function(args,map){
var s="k`";
s+=args.Mode+"`";
var obj=args.DraggingItem;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
var obj=args.Item;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
s+=((args.OldBegin)/1000)+"`";
s+=((args.OldEnd)/1000)+"`";
var obj=args.OldRow;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
s+=((args.NewBegin)/1000)+"`";
s+=((args.NewEnd)/1000)+"`";
var obj=args.NewRow;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
return s;
}
this.ItemDragging=t[idx[0]++];
if(typeof(this.ItemDragging)=='undefined')this.ItemDragging=null;
this.ItemTextEdited=t[idx[0]++];
if(typeof(this.ItemTextEdited)=='undefined')this.ItemTextEdited=this.callback;
this.ItemTextEdited_serialize=function(args,map){
var s="m`";
var obj=args.Item;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
s+=go.SerializeStr(args.NewText);
s+=go.SerializeStr(args.OldText);
s+=(args.Cancel)?"T`":"`";
return s;
}
this.ItemTextEditing=t[idx[0]++];
if(typeof(this.ItemTextEditing)=='undefined')this.ItemTextEditing=null;
this.NumberOfColsChanged=t[idx[0]++];
if(typeof(this.NumberOfColsChanged)=='undefined')this.NumberOfColsChanged=this.callback;
this.NumberOfColsChanged_serialize=function(args,map){
return "o`";
}
this.ResourcesWidthChanged=t[idx[0]++];
if(typeof(this.ResourcesWidthChanged)=='undefined')this.ResourcesWidthChanged=this.callback;
this.ResourcesWidthChanged_serialize=function(args,map){
return "p`";
}
this.RowExpandedChanged=t[idx[0]++];
if(typeof(this.RowExpandedChanged)=='undefined')this.RowExpandedChanged=this.callback;
this.RowExpandedChanged_serialize=function(args,map){
var s="q`";
var obj=args.Row;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
s+=(args.NewExpanded)?"T`":"`";
return s;
}
this.RowExpandedChanging=t[idx[0]++];
if(typeof(this.RowExpandedChanging)=='undefined')this.RowExpandedChanging=null;
this.RowTextEdited=t[idx[0]++];
if(typeof(this.RowTextEdited)=='undefined')this.RowTextEdited=this.callback;
this.RowTextEdited_serialize=function(args,map){
var s="s`";
var obj=args.Row;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
var obj=args.Column;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
s+=go.SerializeStr(args.NewText);
s+=go.SerializeStr(args.OldText);
s+=(args.Cancel)?"T`":"`";
return s;
}
this.RowTextEditing=t[idx[0]++];
if(typeof(this.RowTextEditing)=='undefined')this.RowTextEditing=null;
this.firstDateTime=1000*t[idx[0]++];
this.firstVisibleCell=t[idx[0]++];
this.firstVisibleRow=t[idx[0]++];
this.freeTimeMode=t[idx[0]++];
this.horizontalHeaderLine=go.DeserStr(t,idx[0]++);
this.horizontalLine=go.DeserStr(t,idx[0]++);
this.itemStyle=t[idx[0]++];
this.lastDateTime=1000*t[idx[0]++];
this.linkLine=go.DeserStr(t,idx[0]++);
this.linkLineMode=t[idx[0]++];
this.nextButton=go.DeserStr(t,idx[0]++);
var ris=t[idx[0]++];
this.nowIndicatorStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.NowIndicatorClick_serialize=function(args,map){
var s="u`";
s+=args.Action+"`";
return s;
}
this.numberOfCols=t[idx[0]++];
this.previousButton=go.DeserStr(t,idx[0]++);
var arr=[];
for(var length=t[idx[0]++]; --length>=0;) {
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new SchedulerRegion().Load(t,idx);
}
else obj=t[n-1];
arr.push(obj);
}
this.regions=arr;
var ris=t[idx[0]++];
this.resourceHeaderStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.ResourceHeaderClick_serialize=function(args,map){
var s="v`";
s+=args.Action+"`";
return s;
}
var ris=t[idx[0]++];
this.resourceListStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.ResourceListClick_serialize=function(args,map){
var s="w`";
s+=args.Action+"`";
return s;
}
this.resourcesWidth=t[idx[0]++];
this.rowHeight=t[idx[0]++];
var arr=[];
for(var length=t[idx[0]++]; --length>=0;) {
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new ResourceRow().Load(t,idx);
}
else obj=t[n-1];
arr.push(obj);
}
this.rows=arr;
this.splitterColor=t[idx[0]++];
var ris=t[idx[0]++];
this.timeLineStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.TimeLineClick_serialize=function(args,map){
var s="x`";
s+=args.Action+"`";
return s;
}
this.verticalLine0=go.DeserStr(t,idx[0]++);
this.verticalLine1=go.DeserStr(t,idx[0]++);
this.verticalLine2=go.DeserStr(t,idx[0]++);
this.verticalResourceLine=go.DeserStr(t,idx[0]++);
this.viewOptions=t[idx[0]++];
this.workHourBegin=t[idx[0]++];
this.workHourEnd=t[idx[0]++];
this.nSubCells=t[idx[0]++];
this.useLastDateTime=t[idx[0]++]!=0;
this.mapCol=t[idx[0]++];
this.calcDT=t[idx[0]++];
return this;
}

Scheduler.prototype.Serialize = function(map) {
if(!map) map=[];
var r=this.GoControl_Serialize(map);
r+=("31618723`");
r+=(go.SerializeStr(this.caption));
var obj=this.clickedColumn;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
r+=(iobj);
r+=(((this.clickedDateTime)/1000)+"`");
var obj=this.clickedItem;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
r+=(iobj);
var obj=this.clickedRow;
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
r+=(iobj);
var s="`";
var arr=this.columns;
if(arr!=null && arr.length>0) {
s=arr.length+"`";
for(var idx=0; idx<arr.length; ++idx) {
var obj=arr[idx];
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
}
}
r+=(s);
r+=(((this.firstDateTime)/1000)+"`");
r+=(this.firstVisibleCell+"`");
r+=(this.firstVisibleRow+"`");
r+=(((this.lastDateTime)/1000)+"`");
r+=(this.numberOfCols+"`");
var s="`";
var arr=this.regions;
if(arr!=null && arr.length>0) {
s=arr.length+"`";
for(var idx=0; idx<arr.length; ++idx) {
var obj=arr[idx];
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
}
}
r+=(s);
r+=(this.resourcesWidth+"`");
var s="`";
var arr=this.rows;
if(arr!=null && arr.length>0) {
s=arr.length+"`";
for(var idx=0; idx<arr.length; ++idx) {
var obj=arr[idx];
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
}
}
r+=(s);
r+=((this.workHourBegin)+"`");
r+=((this.workHourEnd)+"`");
r+=((this.useLastDateTime)?"T`":"`");
return r;
}

var SchedulerViewOptions={None:0,ShowFirstTimeline:1,ShowCaption:2,OverlappedBesideSelf:4,HandCursorOnItem:8,HideVerticalScrollbar:16,InvisibleVerticalScrollBar:16,InvisibleHorizontalScrollBar:32,HideHorizontalScrollBar:32,HideExpandedRowSum:64,ShowNowIndicatorInTimeline:128,Default:135,ShowNowIndicatorInBody:256};
var SchedulerButton={PreviousPage:0,NextPage:1};
var SchedulerItemChangeMode={ChangeBegin:0,ChangeEnd:1,Move:2};
var SchedulerBehaviorOptions={None:0,EditableItemText:1,EditableResourceText:2,AllowOverlapItems:4,AllowChangeLevelItem:8,AllowDraggingOutside:16,ResizeableResourcesPanel:32,ResizeableResourceColumns:64,Default:115,EncodeItemDisplayText:256,EncodeResourceDisplayText:512,CustomFirstDayOfWeek:1024};
var FreeTimeMode={Visible:0,Hidden:1,Collapsed:2};
SchedulerItem.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
this.allows=t[idx[0]++];
this.dateBegin=1000*t[idx[0]++];
this.dateEnd=1000*t[idx[0]++];
this.displayText=go.DeserStr(t,idx[0]++);
this.firstColumn=t[idx[0]++];
this.itemID=go.DeserStr(t,idx[0]++);
this.lastColumn=t[idx[0]++];
this.layer=t[idx[0]++];
var len=t[idx[0]++];
var ts=null;
if(typeof(len)!="undefined"){
ts=[];
while(--len>=0)ts.push(go.DeserStr(t,idx[0]++));
}
this.linkToIDs=ts;
var ris=t[idx[0]++];
this.style=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.text=go.DeserStr(t,idx[0]++);
this.tooltip=go.DeserStr(t,idx[0]++);
this.nItem=t[idx[0]++];
this.nCount=t[idx[0]++];
return this;
}

SchedulerItem.prototype.Serialize = function(map) {
if(!map) map=[];
var r=this.allows+"`";
r+=(((this.dateBegin)/1000)+"`");
r+=(((this.dateEnd)/1000)+"`");
r+=(go.SerializeStr(this.displayText));
r+=(go.SerializeStr(this.itemID));
r+=(this.layer+"`");
var tsres;
var ts=this.linkToIDs;
if(ts==null)tsres="`";
else{
tsres=ts.length+"`";
for(var i=0;i<ts.length;++i)tsres+=go.SerializeStr(ts[i]);
}
r+=(tsres);
r+=((this.style).Serial());
r+=(go.SerializeStr(this.text));
r+=(go.SerializeStr(this.tooltip));
return r;
}

var SchedulerItemStyle={WithText:0,SmallBox:1};
var ResourceRowSumMode={None:0,OneLevel:1,AllLevels:2};
ResourceRow.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
this.allowDrag=t[idx[0]++]!=0;
this.allowEdit=t[idx[0]++]!=0;
var ris=t[idx[0]++];
this.bodyStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
var arr=[];
for(var length=t[idx[0]++]; --length>=0;) {
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new ResourceRow().Load(t,idx);
}
else obj=t[n-1];
arr.push(obj);
}
this.childRows=arr;
var len=t[idx[0]++];
var ts=null;
if(typeof(len)!="undefined"){
ts=[];
while(--len>=0)ts.push(go.DeserStr(t,idx[0]++));
}
this.displayTexts=ts;
this.expanded=t[idx[0]++]!=0;
var ris=t[idx[0]++];
this.headerStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.height=t[idx[0]++];
var arr=[];
for(var length=t[idx[0]++]; --length>=0;) {
var n=t[idx[0]++];
var obj;
if(n<0)obj=null;
else if(n==0) {
obj=new SchedulerItem().Load(t,idx);
}
else obj=t[n-1];
arr.push(obj);
}
this.items=arr;
this.resourceID=go.DeserStr(t,idx[0]++);
this.sumItemsIntoOne=t[idx[0]++]!=0;
this.sumMode=t[idx[0]++];
var ris=t[idx[0]++];
this.sumStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.sumText=go.DeserStr(t,idx[0]++);
this.sumTooltip=go.DeserStr(t,idx[0]++);
var len=t[idx[0]++];
var ts=null;
if(typeof(len)!="undefined"){
ts=[];
while(--len>=0)ts.push(go.DeserStr(t,idx[0]++));
}
this.texts=ts;
this.visible=t[idx[0]++]!=0;
this.hItems=t[idx[0]++];
return this;
}

ResourceRow.prototype.Serialize = function(map) {
if(!map) map=[];
var r=(this.allowDrag)?"T`":"`";
r+=((this.allowEdit)?"T`":"`");
r+=((this.bodyStyle).Serial());
var s="`";
var arr=this.childRows;
if(arr!=null && arr.length>0) {
s=arr.length+"`";
for(var idx=0; idx<arr.length; ++idx) {
var obj=arr[idx];
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
}
}
r+=(s);
var tsres;
var ts=this.displayTexts;
if(ts==null)tsres="`";
else{
tsres=ts.length+"`";
for(var i=0;i<ts.length;++i)tsres+=go.SerializeStr(ts[i]);
}
r+=(tsres);
r+=((this.expanded)?"T`":"`");
r+=((this.headerStyle).Serial());
r+=(this.height+"`");
var s="`";
var arr=this.items;
if(arr!=null && arr.length>0) {
s=arr.length+"`";
for(var idx=0; idx<arr.length; ++idx) {
var obj=arr[idx];
var iobj=go.FindArr(map,obj);
if(iobj!=="") iobj+="`";
else {
iobj="`"+obj.Serialize(map);
map.push(obj);
}
s+=iobj;
}
}
r+=(s);
r+=(go.SerializeStr(this.resourceID));
r+=((this.sumItemsIntoOne)?"T`":"`");
r+=(this.sumMode+"`");
r+=((this.sumStyle).Serial());
r+=(go.SerializeStr(this.sumText));
r+=(go.SerializeStr(this.sumTooltip));
var tsres;
var ts=this.texts;
if(ts==null)tsres="`";
else{
tsres=ts.length+"`";
for(var i=0;i<ts.length;++i)tsres+=go.SerializeStr(ts[i]);
}
r+=(tsres);
r+=((this.visible)?"T`":"`");
return r;
}

ResourceColumn.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
this.allowEdit=t[idx[0]++]!=0;
var svobj=go.DeserStr(t,idx[0]++);
this.collapseImageUrl_serv=svobj;
if(t[idx[0]++]==1){
svobj=go.DeserStr(t,idx[0]++);
}
this.collapseImageUrl=this.collapseImageUrl_prev=svobj;
this.dataIndex=t[idx[0]++];
var svobj=go.DeserStr(t,idx[0]++);
this.expandImageUrl_serv=svobj;
if(t[idx[0]++]==1){
svobj=go.DeserStr(t,idx[0]++);
}
this.expandImageUrl=this.expandImageUrl_prev=svobj;
var ris=t[idx[0]++];
this.headerStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.noExpandImageUrl=go.DeserStr(t,idx[0]++);
var ris=t[idx[0]++];
this.rowsStyle=typeof(ris)=='undefined'?RegionInfo_Empty:new RegionInfo(ris);
this.showTree=t[idx[0]++]!=0;
this.text=go.DeserStr(t,idx[0]++);
this.treeIndent=t[idx[0]++];
this.width=t[idx[0]++];
return this;
}

ResourceColumn.prototype.Serialize = function(map) {
if(!map) map=[];
var r=(this.allowEdit)?"T`":"`";
var svobj=this;
r+=(go.SerializeStr(svobj.collapseImageUrl==svobj.collapseImageUrl_prev?svobj.collapseImageUrl_serv:svobj.collapseImageUrl));
r+=(this.dataIndex+"`");
var svobj=this;
r+=(go.SerializeStr(svobj.expandImageUrl==svobj.expandImageUrl_prev?svobj.expandImageUrl_serv:svobj.expandImageUrl));
r+=((this.headerStyle).Serial());
var urls=this.noExpandImageUrl;
if(urls!=null){
var urli=urls.indexOf("|@");
urls=urli>=0 ? urls.substr(urli+2) : urls;
}
r+=(go.SerializeStr(urls));
r+=((this.rowsStyle).Serial());
r+=((this.showTree)?"T`":"`");
r+=(go.SerializeStr(this.text));
r+=(this.treeIndent+"`");
r+=(this.width+"`");
return r;
}

/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

//
// ResourceRow
//

ResourceRow.prototype.RefreshSums = function() {
    var i, j;
    if (this.sumRedunt!=null) {
        for (i = this.sumRedunt.length; --i>=0;)
            this.sumRedunt[i].Resync(true);
        this.sumRedunt = null;
    }
    
    if (this.sumItems==null) return; 
   
    this.sumRedunt = [];
    for (i = this.sumItems.length; --i>=0;) {
        var it = this.sumItems[i];
        var isVisible = it.row.visibleIndex>=0;
        var r = null;
        for (j = this.sumRedunt.length; --j>=0;) {
            var rr = this.sumRedunt[j];
            if (this.sumItemsIntoOne || !(rr.lastColumn<it.firstColumn || rr.firstColumn>it.lastColumn)) {
                if (r==null) {
                    r = rr;
                    rr = it;
                    if (this.sumText==null)
                        r.text = go.ConcatStr(r.text, rr.text, " | ");
                }
                else {
                    this.sumRedunt.splice(j, 1);
                    if (this.sumText==null)
                        r.text = go.ConcatStr(rr.text, r.text, " | ");
                    for (var k = rr.sumableItems.length; --k>=0;)
                        rr.sumableItems[k].sumItem = r;
                    if (rr.linkToIDs!=null)
                        r.linkToIDs = r.linkToIDs.concat(rr.linkToIDs);
                    r.sumableItems = r.sumableItems.concat(rr.sumableItems);
                }
                if (!isVisible) {
                    it.sumItem = r;
                    if (it.linkToIDs!=null)
                        r.linkToIDs = r.linkToIDs.concat(it.linkToIDs);
                    r.sumableItems.push(it);
                }
                if (r.firstColumn>rr.firstColumn) r.firstColumn = rr.firstColumn;
                if (r.lastColumn<rr.lastColumn) r.lastColumn = rr.lastColumn;
            }
        }
        
        if (r==null) {
            r = new SchedulerItem();
            this.sumRedunt.push(r);
            r.text = this.sumText==null ? it.text : this.sumText;
            r.tooltip = this.sumTooltip;
            r.firstColumn = it.firstColumn;
            r.lastColumn = it.lastColumn;
            r.style = this.sumStyle;//this.sumStyleEx;
            r.allows = 0;
            r.itemID = "";
            r.dateBegin = r.dateEnd = 0;
            r.linkToIDs = [];
            r.layer = 0;
            if (!isVisible) {
                it.sumItem = r;
                if (it.linkToIDs!=null)
                    r.linkToIDs = r.linkToIDs.concat(it.linkToIDs);
                r.sumableItems = [it];
            }
            else
                r.sumableItems = [];
        }
    }

    for (j = this.sumRedunt.length; --j>=0;)
        this.sumRedunt[j].Init(this);
}

ResourceRow.prototype.RenderRedunt = function() {
    this.RefreshSums();
    if (this.sumRedunt==null) return;
    for (var i = this.sumRedunt.length; --i>=0;)
        this.sumRedunt[i].Resync();
}

ResourceRow.prototype.get_ResourceID = function() {
    return this.resourceID;
}

ResourceRow.prototype.get_AllowDrag = function() {
    return this.allowDrag;
}

ResourceRow.prototype.get_AllowEdit = function() {
    return this.allowEdit;
}

ResourceRow.prototype.get_Visible = function() {
    return this.visible;
}

ResourceRow.prototype.set_Visible = function(value) {
    this.visible = value;
}

ResourceRow.prototype.get_Height = function() {
    return this.height;
}

ResourceRow.prototype.set_Height = function(value) {
    this.height = value;
    if (this.hItems!=1 || this.height!=null && this.height!="") {
        var h = this.height!=null && this.height!="" ? this.height : this.scheduler.rowHeight;
        this.realHeight = go.MulUnit(h, this.hItems);
    }
    else
        this.realHeight = null;
}

ResourceRow.prototype.GetText = function(index) {
    if (index<0) throw new GoError(GoError_IndexOutOfRange);
    if (this.editColumn!=null)
        if (this.editColumn.dataIndex==index)
            return this.editElement.value;
    if (this.texts!=null && index<this.texts.length && this.texts[index]!=null)
        return this.texts[index];
    return "";
}

ResourceRow.prototype.SetText = function(index, value) {
    if (index<0) throw new GoError(GoError_IndexOutOfRange);
    if (this.editColumn!=null) {
        if (this.editColumn.dataIndex==index) {
            this.editElement.value = value;
            return;
        }
    }
    
    while (index>=this.texts.length) this.texts.push("");
    if (this.texts[index]==value) return;
    
    this.texts[index] = value;
    this.scheduler.Render();
}

ResourceRow.prototype.GetDisplayText = function(index) {
    if (index<0) throw new GoError(GoError_IndexOutOfRange);
    if (this.displayTexts!=null && index<this.displayTexts.length)
        return this.displayTexts[index];
    return "";
}

ResourceRow.prototype.SetDisplayText = function(index, value) {
    if (index<0) throw new GoError(GoError_IndexOutOfRange);
    
    while (index>=this.displayTexts.length) this.displayTexts.push("");
    if (this.displayTexts[index]==value) return;
    
    this.displayTexts[index] = value;
    this.scheduler.Render();
}

ResourceRow.prototype.CalcText = function(index) {
    if (index<0) throw new GoError(GoError_IndexOutOfRange);
    var t = go.HtmlDecode(this.GetText(index));
    if (this.displayTexts!=null && index<this.displayTexts.length) {
        var s = this.displayTexts[index];
        if (s!=null && s!="") {
            var i = s.indexOf("|");
            if (i<0) return s;
            return s.substring(0, i)+t+s.substr(i+1);
        }
    }
    return t;
}

ResourceRow.prototype.get_Scheduler = function() {
    return this.scheduler;
}

ResourceRow.prototype.HasChildren = function() {
    return this.childRows!=null && this.childRows.length>0;
}

ResourceRow.prototype.get_ChildRows = function() {
    if (this.childRows==null) this.childRows = [];
    return this.childRows;
}

ResourceRow.prototype.get_Expanded = function() {
    return this.expanded;
}

ResourceRow.prototype.set_Expanded = function(value) {
    if (this.expanded==value) return;
    var args = {Row: this, NewExpanded: value, Cancel: false};
    this.scheduler.InvokeClientEvent("RowExpandedChanging", args);    
    if (!args.Cancel) {
        this.expanded = value;
        this.scheduler.InvokeNewEvent("RowExpandedChanged", {Row: this, NewExpanded: value});
//        this.scheduler.Render();
    }
}

ResourceRow.prototype.get_SumItemsIntoOne = function() {
    return this.sumItemsIntoOne;
}

ResourceRow.prototype.get_Deep = function() {
    return this.deep;
}

ResourceRow.prototype.get_Parent = function() {
    return this.parent;
}

ResourceRow.prototype.get_VisibleIndex = function() {
    return this.visibleIndex;
}

ResourceRow.prototype.get_Editing = function() {
    return this.editElement!=null;
}

ResourceRow.prototype.getTD = function(index) {
    var td = this.scheduler.resList.rows[this.visibleIndex].cells[index];
    if (this.scheduler.columns[index].IsTree()) {
        var table = td.getElementsByTagName("TABLE")[0];
        if (table==null) return;
        td = table.rows[0].cells[table.rows[0].cells.length-1];
    }
    return td;
}

ResourceRow.prototype.Edit = function(index) {
    if (this.editColumn!=null)
        if (this.editColumn.index==index) return;
    if (!this.allowEdit) return;
    if (this.visibleIndex<0) return;
    if (!this.scheduler.CloseEditor(false)) return;
    if ((this.scheduler.behaviorOptions & SchedulerBehaviorOptions.EditableResourceText)==0) return;
   
    var col = this.scheduler.columns[index];
    if (!col.allowEdit) return;

    var s = this.GetText(col.dataIndex);
   
    var args = {Row: this, Column: col, Text: s, Cancel: false};
    this.scheduler.InvokeClientEvent("RowTextEditing", args);
    if (args.Cancel) return;

    var html = "<input type=text style='overflow: hidden; width: 99%; height: 100%; border: 0px; font-size: x-small; font-family: Arial'>";
    html += "</input>";
    
    var td = this.getTD(index);
    td.innerHTML = html;
   
    this.editColumn = col;
    this.editElement = td.getElementsByTagName("INPUT")[0];
    this.editElement.value = args.Text;
    this.scheduler.Attach(this, "input_KeyDown", this.editElement);
    this.editElement.focus();
    this.editElement.select();
    this.scheduler.editor = this;
}

ResourceRow.prototype.CloseEditor = function(cancel, element) {
    if (this.editElement==null) return true;
    if (element) {
        if (element==this.editElement) return false;
    }

    if (!cancel) {
        var idx = this.editColumn.dataIndex;
        if (this.texts==null) this.texts = [];
        while (idx>=this.texts.length) this.texts.push("");
        
        var args = {Row: this, Column: this.editColumn, 
            NewText: this.editElement.value, OldText: this.texts[idx],
            Cancel: false};
            
        if (args.NewText!=args.OldText) {
            this.scheduler.InvokeEvent("RowTextEdited", args);
            if (args.Cancel) return false;
        }
        
        this.texts[idx] = args.NewText;
    }

    this.scheduler.editor = null;
    this.editElement = null;
    this.editColumn = null;
    this.scheduler.Render();

    return true;
}

ResourceRow.prototype.input_KeyDown = function(e) {
    if (e.KeyCode==13) {
        this.CloseEditor(false);
        return false;
    }
    else if (e.KeyCode==27) {
        this.CloseEditor(true);
    }
}

ResourceRow.prototype.addVisibleRow = function(visible, scheduler, deep, parent) {
    var i;
    this.scheduler = scheduler;
    this.deep = deep;
    this.parent = parent;
    this.set_Height(this.height);
   
    if (!this.visible)
        visible = false;

    this.sumRedunt = null;
    if (visible) {
        this.visibleIndex = this.scheduler.visibleRows.push(this)-1;
        if (this.sumMode!=ResourceRowSumMode.None)
            this.scheduler.isSum = true;
    }
    else
        this.visibleIndex = -1;

    if (this.childRows!=null) {
        for (i = 0; i<this.childRows.length; ++i)
            if (this.childRows[i]!=null)
                this.childRows[i].addVisibleRow(visible && this.expanded, scheduler, deep+1, this);
    }

    if (this.items!=null) 
        for (i = 0; i<this.items.length; ++i) 
            this.items[i].Init(this);
}

RegisterType("ResourceRow");

function ResourceRow() {
    this.realHeight = null;
    this.visibleIndex = -1;
    this.editElement = null;
    this.editColumn = null;
    this.sumRedunt = null;
    return this;
}

/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

//
// ResourceColumn
//

ResourceColumn.prototype.get_Scheduler = function() {
    return this.scheduler;
}

ResourceColumn.prototype.get_Index = function() {
    return this.index;
}

ResourceColumn.prototype.get_Text = function() {
    return this.text;
}

ResourceColumn.prototype.set_Text = function(value) {
    if (this.text==value) return;
    this.text = value;
}

ResourceColumn.prototype.IsTree = function() {
    return this.showTree;
}

ResourceColumn.prototype.get_ShowTree = function() {
    return this.showTree;
}

ResourceColumn.prototype.get_TreeIndent = function() {
    return this.treeIndent;
}

ResourceColumn.prototype.set_TreeIndent = function(value) {
    if (this.treeIndent==value) return;
    this.treeIndent = value;
}

ResourceColumn.prototype.get_CollapseImageUrl = function() {
    return this.collapseImageUrl;
}

ResourceColumn.prototype.set_CollapseImageUrl = function(value) {
    if (this.collapseImageUrl==value) return;
    this.collapseImageUrl = value;
}

ResourceColumn.prototype.get_ExpandImageUrl = function() {
    return this.expandImageUrl;
}

ResourceColumn.prototype.set_ExpandImageUrl = function(value) {
    if (this.expandImageUrl==value) return;
    this.expandImageUrl = value;
}

ResourceColumn.prototype.get_NoExpandImageUrl = function() {
    if (this.noExpandImageUrl==null) return null;
    var i = this.noExpandImageUrl.indexOf("|@");
    return i>=0 ? this.noExpandImageUrl.substr(0, i) : this.noExpandImageUrl;
}

ResourceColumn.prototype.set_NoExpandImageUrl = function(value) {
    if (this.noExpandImageUrl==value) return;
    this.noExpandImageUrl = value;
}

ResourceColumn.prototype.get_DataIndex = function() {
    return this.dataIndex;
}

ResourceColumn.prototype.set_DataIndex = function(value) {
    if (this.dataIndex==value) return;
    this.dataIndex = value;
}

ResourceColumn.prototype.get_Width = function() {
    return this.width;
}

ResourceColumn.prototype.set_Width = function(value) {
    if (this.width==value) return;
    this.width = value;
    this.setColumnWidth(this.scheduler.resHeader, 4);
    this.setColumnWidth(this.scheduler.resList, 0);
    this.scheduler.InvokeEvent("ColumnWidthChanged", {Column: this, NewWidth: value});
}

ResourceColumn.prototype.setColumnWidth = function(table, delta) {
    var cols = table.getElementsByTagName("COL");
    cols[this.index].width = this.width;
    for (var row = table.rows.length; --row>=0;) {
        var td = table.rows[row].cells[this.index];
        var div = td.getElementsByTagName("DIV")[0];
        div.style.width = go.SubPx(this.width, delta);
    }
}

ResourceColumn.prototype.get_AllowEdit = function() {
    return this.allowEdit;
}

RegisterType("ResourceColumn");

function ResourceColumn(scheduler) {
    this.scheduler = null;
    this.index = 0;
    return this;
}

/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

//
// SchedulerItem
//

SchedulerItem.prototype.Resync = function(remove) {
    if (!this.scheduler.IsRenderingPossible()) return;
    this.CloseEditor(true);

    if (!this.initBackLinks) {
        this.initBackLinks = true;
        if (this.linkToIDs != null) {
            for (var i = this.linkToIDs.length; --i >= 0; ) {
                var next = this.scheduler.itemsByID[this.linkToIDs[i]];
                if (next.backLinks == null) next.backLinks = [];
                next.backLinks.push(this);
            }
        }
    }

    if (this.row.visibleIndex < 0 || this.lastColumn < 0 || this.firstColumn >= this.scheduler.numberOfCols || remove) {
        if (this.div != null) {
            this.scheduler.bodyDiv.removeChild(this.div);
            this.div = null;
        }
    }
    else {
        var divAdded = false;
        if (this.div == null) {
            this.div = document.createElement("DIV");
            divAdded = true;
            this.scheduler.defaultItemStyle.InitElement(this.scheduler, this.div);
            this.style.InitElement(this.scheduler, this.div);
            this.div.style.position = "absolute";
            this.div.style.overflow = "hidden";
            this.div.style.zIndex = 11;
            this.scheduler.Attach(this, "divItem_MouseDown", this.div);
            this.scheduler.Attach(this, "divItem_MouseUp", this.div);
            this.scheduler.Attach(this, "divItem_Click", this.div);
            this.scheduler.Attach(this, "divItem_DblClick", this.div);
            this.scheduler.Attach(this, "divItem_MouseMove", this.div);
            this.scheduler.Attach(this, "divItem_ContextMenu", this.div);
            this.saveBorderLeft = this.div.style.borderLeft;
            this.saveBorderRight = this.div.style.borderRight;
        }
        var l = go.GetPx(this.div.style.borderWidth);
        if (go.IsChrome) l = 0;
        var x = this.scheduler.GetColX(this.firstColumn < 0 ? 0 : this.firstColumn);
        var x2 = this.scheduler.GetColX(this.lastColumn >= this.scheduler.numberOfCols + 0.2 ? this.scheduler.numberOfCols + 0.2 : this.lastColumn, true);
        var y = this.scheduler.GetRowY(this.row.visibleIndex);
        var h = this.scheduler.GetRowY(this.row.visibleIndex, true) - y - 2 * (l + this.scheduler.smallHeightPx);
        x = Math.floor(x);
        x2 = Math.floor(x2);

        if (this.lastColumn == Math.floor(this.lastColumn))
            x2 -= this.firstColumn < 0 ? l : 2 * l;
        if (x2 <= x) x2 = x + 1;

        if (this.firstColumn < 0)
            this.div.style.borderLeft = "";
        else if (this.saveBorderLeft == "") {
            if (this.div.style.removeAttribute) // Chrome does not support removeAttribute
                this.div.style.removeAttribute("border-left");
            //            else
            //                this.div.style.borderLeft = null;
        }
        else
            this.div.style.borderLeft = this.saveBorderLeft;
        if (this.lastColumn > this.scheduler.numberOfCols)
            this.div.style.borderRight = "";
        else if (this.saveBorderRight == "") {
            if (this.div.style.removeAttribute) // Chrome does not support removeAttribute
                this.div.style.removeAttribute("border-right");
            //            else
            //                this.div.style.borderRight = null;
        }
        else
            this.div.style.borderRight = this.saveBorderRight;

        if (go.IsChrome) {
            h -= 2;
        }
        else if (go.IsSafari) {
            x2 += 2;
        }
        else if (go.IsIE8) {
            --y;
        }
        if (this.row.hItems > 1) {
            ++h;
            h /= this.nCount;
            var n = this.nItem;
            if (n >= this.nCount) n = this.nCount - 1;
            y += Math.floor(n * h);
            h = Math.floor((n + 1) * h) - Math.floor(n * h);
            h--;
        }
        this.div.style.left = x + "px";
        this.div.style.top = (y + this.scheduler.smallHeightPx) + "px";
        this.div.style.width = (x2 - x) + "px";
        this.div.style.height = h + "px";
        if (this.scheduler.itemStyle == SchedulerItemStyle.WithText)
            this.div.innerHTML = this.CalcDisplayText();
        if (this.tooltip != null)
            this.div.title = this.tooltip;
        else
            this.div.title = "";
        if (divAdded)
            this.scheduler.bodyDiv.appendChild(this.div);
    }
}

SchedulerItem.prototype.addLine = function(left, top, width, height) {
    if (width<0 || height<0) return;
    var d = document.createElement("DIV");
    d.style.left = left+"px";
    d.style.top = top+"px";
    d.style.width = width+"px";
    d.style.height = height+"px";
    d.style.zIndex = 12;
    if (height==0)
        d.style.borderTop = this.scheduler.linkLine;
    else
        d.style.borderLeft = this.scheduler.linkLine;

    d.style.position = "absolute";
    d.style.overflow = "hidden";
    if (this.linkDivs==null) this.linkDivs = [];
    this.linkDivs.push(d);
    this.scheduler.bodyDiv.appendChild(d);
}

SchedulerItem.prototype.addImage = function(left, top, img) {
    if (this.scheduler.linkLineMode!=LinkLineMode.ShowArrow) return;
    var p = document.createElement("IMG");
    p.style.left = left+"px";
    p.style.top = top+"px";
    p.src = img;
    p.style.position = "absolute";
    p.style.width = "7px";
    p.style.height = "7px";
    p.style.zIndex = 12;
    this.linkDivs.push(p);
    this.scheduler.bodyDiv.appendChild(p);
}

SchedulerItem.prototype.ResyncLinks = function() {
    if (this.linkDivs!=null) {
        for (var i = this.linkDivs.length; --i>=0;)
            this.scheduler.bodyDiv.removeChild(this.linkDivs[i]);
        this.linkDivs = null;
    }
    if (this.div==null) return;
    if (this.scheduler.linkLineMode==LinkLineMode.Invisible) return;
   
    var y = this.div.offsetTop+this.div.offsetHeight/2;
    var x = this.div.offsetLeft+this.div.offsetWidth;
    
    if (this.backLinks!=null) {
        for (var i = this.backLinks.length; --i>=0;) {
            if (this.backLinks[i].div==null && this.backLinks[i].sumItem==null) {
                this.addLine(this.div.offsetLeft-this.scheduler.cellWidthPx-3, y, this.scheduler.cellWidthPx+3, 0);
                this.addImage(this.div.offsetLeft-7, y-3, this.scheduler.arrowRight);
                break;
            }
        }
    }

    if (this.linkToIDs==null) return;
    
    for (var i = this.linkToIDs.length; --i>=0;) {
        var next = this.scheduler.itemsByID[this.linkToIDs[i]];
        if (next.sumItem!=null) next = next.sumItem;
        if (next==this) continue;
        
        if (next.div==null) { // next.row.visibleIndex<0) {
            this.addLine(x, y, this.scheduler.cellWidthPx, 0);
            this.addImage(x+this.scheduler.cellWidthPx, y-3, this.scheduler.arrowRight);
        }
        else {
            var x2 = next.div.offsetLeft+this.scheduler.cellWidthPx/2-1;
            var max2 = next.div.offsetLeft+next.div.offsetWidth/2;
            if (x2>max2) x2 = max2;

            if (next.firstColumn>=this.lastColumn) {
                //
                // Next after first
                //
                if (next.div.offsetTop==this.div.offsetTop) {
                    x2 = next.div.offsetLeft-x;
                    if (x2<1) x2 = 1;
                    this.addLine(x, y, x2, 0);
                    this.addImage(next.div.offsetLeft-7, y-3, this.scheduler.arrowRight);
                }
                else {
                    if (x>=x2) x = x2-1;
                    this.addLine(x, y, x2-x, 0);
                    if (next.div.offsetTop>this.div.offsetTop) {
                        this.addLine(x2, y, 0, next.div.offsetTop-y);
                        this.addImage(x2-3, next.div.offsetTop-7, this.scheduler.arrowDown);
                    }
                    else if (next.div.offsetTop<this.div.offsetTop) {
                        var h = y-next.div.offsetTop-next.div.offsetHeight;
                        this.addLine(x2, y-h, 0, h);
                        this.addImage(x2-3, y-h, this.scheduler.arrowUp);
                    }
                }
            }
            else {
                //
                // Next before first
                //
                var xx = x+this.scheduler.cellWidthPx/2-1;
                var yy = (this.div.offsetTop+next.div.offsetTop+this.div.offsetHeight)/2;
                if (x2>=xx) x2 = xx-1;
                
                this.addLine(x, y, xx-x, 0);

                if (next.div.offsetTop==this.div.offsetTop) {
                    yy += this.div.offsetHeight;
                    var h = yy-next.div.offsetTop-next.div.offsetHeight;
                
                    this.addLine(xx, y, 0, yy-y);
                    this.addLine(x2, yy-h, 0, h);
                    this.addImage(x2-3, yy-h, this.scheduler.arrowUp);
                }
                else {
                    if (this.scheduler.itemStyle==SchedulerItemStyle.WithText) {
                        var p1_ni = this.nItem+1;
                        var p1_vi = this.row.visibleIndex;
                        if (p1_ni>=this.row.hItems) { p1_ni = 0; ++p1_vi; }
                        var m1_ni = this.nItem-1;
                        var m1_vi = this.row.visibleIndex;
                        if (m1_ni<0) { --m1_vi; m1_ni = m1_vi<0 ? 0 : this.scheduler.visibleRows[m1_vi].hItems-1; }

                        if (next.row.visibleIndex==p1_vi && next.nItem==p1_ni)
                            yy = y+2*this.div.offsetHeight;
                        else if (next.row.visibleIndex==m1_vi && next.nItem==m1_ni)
                            yy = y+this.div.offsetHeight;
                    }
                    if (yy>y) {
                        --yy;
                        this.addLine(xx, y, 0, yy-y);
                    }
                    else {
                        ++yy;
                        this.addLine(xx, yy, 0, y-yy);
                    }
                }
                if (yy<next.div.offsetTop) {
                    this.addLine(x2, yy, 0, next.div.offsetTop-yy);
                    this.addImage(x2-3, next.div.offsetTop-7, this.scheduler.arrowDown);
                }
                else {
                    var h = yy-next.div.offsetTop-next.div.offsetHeight;
                    if (h<=0) h = 1;
                    this.addLine(x2, yy-h, 0, h);
                    this.addImage(x2-3, yy-h, this.scheduler.arrowUp);
                }
                this.addLine(x2, yy, xx-x2, 0);
            }
        }
    }
}

SchedulerItem.prototype.ResyncBackLinks = function() {
    if (this.backLinks==null) return;
    for (var i = this.backLinks.length; --i>=0;)
        this.backLinks[i].ResyncLinks();
}


/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

//
// SchedulerItem
//

SchedulerItem.prototype.get_Scheduler = function() {
    return this.scheduler;
}

SchedulerItem.prototype.get_Index = function() {
    return this.index;
}

SchedulerItem.prototype.get_Layer = function() {
    return this.layer;
}

SchedulerItem.prototype.set_Layer = function(value) {
    this.layer = value;
}

SchedulerItem.prototype.get_Row = function() {
    return this.row;
}

SchedulerItem.prototype.set_Row = function(value) {
    if (this.row==value) return;

    if (this.dragChange(function(This) { This.draggingArgs.NewRow = value; }))
        return;
    
    var r = this.row;
    this.row = value;
    this.Resync();
    this.UpdateSums(r);
    this.ResyncLinks();
    this.ResyncBackLinks();
}

SchedulerItem.prototype.get_FirstColumn = function() {
    return this.firstColumn;
}

SchedulerItem.prototype.set_FirstColumn = function(value) {
    if (this.firstColumn==value) return;
   
    if (this.dragChange(function(This) { This.draggingArgs.NewBegin = This.scheduler.CalcDateTime(value); }))
        return;
    this.firstColumn = value;
    this.Resync();
    this.UpdateSums(this.row);
    this.ResyncLinks();
    this.ResyncBackLinks();
}

SchedulerItem.prototype.get_LastColumn = function() {
    return this.lastColumn;
}

SchedulerItem.prototype.set_LastColumn = function(value) {
    if (this.lastColumn == value) return;

    if (this.dragChange(function(This) { This.draggingArgs.NewEnd = This.scheduler.CalcDateTime(value, true); })) 
        return;

    this.lastColumn = value;
    this.Resync();
    this.UpdateSums(this.row);
    this.ResyncLinks();
    this.ResyncBackLinks();
}

SchedulerItem.prototype.get_DateBegin = function() {
    return new Date(this.dateBegin);
}

SchedulerItem.prototype.set_DateBegin = function(value) {
    if (typeof(value)!="number") value = value.getTime();
    this.dateBegin = value;
    this.set_FirstColumn(this.scheduler.CalcColumnExact(value));
}

SchedulerItem.prototype.get_DateEnd = function() {
    return new Date(this.dateEnd);
}

SchedulerItem.prototype.set_DateEnd = function(value) {
    if (typeof(value)!="number") value = value.getTime();
    this.dateEnd = value;
    this.set_LastColumn(this.scheduler.CalcColumnExact(value));
}

SchedulerItem.prototype.MoveTo = function(firstColumn, lastColumn, row) {
    if (this.row==row && this.firstColumn==firstColumn && this.lastColumn==lastColumn) return;

    var fn = function(This) {
        This.draggingArgs.NewBegin = This.scheduler.CalcDateTime(firstColumn);
        This.draggingArgs.NewEnd = This.scheduler.CalcDateTime(lastColumn, true);
        This.draggingArgs.NewRow = row;
    };
    if (this.dragChange(fn))
        return;
        
    var r = this.row;
    this.firstColumn = firstColumn;
    this.lastColumn = lastColumn;
    this.row = row;
    this.Resync();
    this.UpdateSums(r);
    this.ResyncLinks();
    this.ResyncBackLinks();
}

SchedulerItem.prototype.get_ItemID = function() {
    return this.itemID;
}

SchedulerItem.prototype.get_Text = function() {
    if (this.editElement!=null)
        return this.editElement.value;
    return this.text;
}

SchedulerItem.prototype.set_Text = function(value) {
    if (this.editElement!=null) {
        this.editElement.value = value;
    }
    else {
        if (this.text==value) return;
        this.text = value;
        this.Resync();
    }
}

SchedulerItem.prototype.get_DisplayText = function() {
    return this.displayText;
}

SchedulerItem.prototype.set_DisplayText = function(value) {
    if (this.displayText == value) return;
    this.displayText = value;
    this.Resync();
}

SchedulerItem.prototype.CalcDisplayText = function() {
    if (this.displayText==null) return go.HtmlEncode(this.text);
    var s = this.displayText;
	if ((this.scheduler.behaviorOptions & SchedulerBehaviorOptions.EncodeItemDisplayText)!=0)
	    s = go.HtmlEncode(s);
    
    var i = s.indexOf("|");
    if (i<0) return s;
   
    return s.substring(0, i)+go.HtmlEncode(this.text)+s.substr(i+1);
}

SchedulerItem.prototype.get_Allows = function() {
    return this.allows;
}

SchedulerItem.prototype.UpdateSums = function(r) {
    if (!this.scheduler.isSum) return;
    if (r.parent!=this.row.parent) {
        this.scheduler.resyncSums();
        for (r = r.parent; r!=null; r = r.parent)
            r.RenderRedunt();
    }
    for (r = this.row.parent; r!=null; r = r.parent)
        r.RenderRedunt();
}

SchedulerItem.prototype.divItem_MouseMove = function(e) {
    this.scheduler.hoverItem = this;

    var pos = e.SenderPt();
    if (pos.X <= 4 && this.firstColumn >= 0
        && (this.allows & SchedulerItemAllows.ChangePeriod) != 0
        && this.scheduler.resizeFirstItemMode != this.scheduler.resizeItemNoneMode) {
        this.div.style.cursor = "e-resize";
        return;
    }
    else if (pos.X >= this.div.offsetWidth - 4 && this.lastColumn <= this.scheduler.numberOfCols
        && (this.allows & SchedulerItemAllows.ChangePeriod) != 0
        && this.scheduler.resizeLastItemMode != this.scheduler.resizeItemNoneMode) {
        this.div.style.cursor = "e-resize";
        return;
    }
    else {
        if ((this.scheduler.viewOptions & SchedulerViewOptions.HandCursorOnItem) != 0) {
            if (go.IsFirefox)
                this.div.style.cursor = "pointer";
            else
                this.div.style.cursor = "hand";
            return;
        }
        if ((this.allows & SchedulerItemAllows.TextEdit) != 0) {
            this.div.style.cursor = "text";
            return;
        }
        if ((this.allows & SchedulerItemAllows.ChangeResource) != 0 || (this.allows & SchedulerItemAllows.ChangeTime) != 0) {
            this.div.style.cursor = "pointer";
            return;
        }
    }
    this.div.style.cursor = "default";
}

SchedulerItem.prototype.divItem_MouseUp = function(e) {
    e.CancelBubble();
    go.Window_MouseUp(e);
}

SchedulerItem.prototype.divItem_Click = function(e) {
    e.CancelBubble();
}

SchedulerItem.prototype.divItem_DblClick = function(e) {
    e.CancelBubble();
}

SchedulerItem.prototype.divItem_ContextMenu = function(e) {
    e.CancelBubble();
}

SchedulerItem.prototype.divItem_MouseDown = function(e) {
    this.scheduler.clickedItem = this;
    this.scheduler.clickedRow = this.row;
    this.scheduler.clickedColumn = null;
    this.scheduler.clickedDateTime = 0;
    e.CancelBubble();

    if (this.editElement == null && this.div != null && !go.duringPostback) {
        if (this.scheduler.CloseEditor(false)) {
            var pos = e.SenderPt();
            if (pos.X >= this.div.offsetWidth - 4 && (this.allows & SchedulerItemAllows.ChangePeriod) != 0 && this.lastColumn <= this.scheduler.numberOfCols)
                this.resize(e, false);
            else if (pos.X <= 4 && (this.allows & SchedulerItemAllows.ChangePeriod) != 0 && this.firstColumn >= 0)
                this.resize(e, true);
            else
                this.drag(e);
        }
    }
    go.Window_MouseDown(e);
}

SchedulerItem.prototype.dragChange = function(fnSet) {
    if (this.scheduler.draggingArgs!=null) {
        this.draggingArgs = go.Clone(this.scheduler.draggingArgs);
        this.draggingArgs.OldBegin = this.scheduler.CalcDateTime(this.firstColumn);
        this.draggingArgs.OldEnd = this.scheduler.CalcDateTime(this.lastColumn, true);
        this.draggingArgs.OldRow = this.row;
        fnSet(this);
        this.draggingArgs.Item = this;
        this.scheduler.InvokeClientEvent("ItemDragging", this.draggingArgs);
        if (this.draggingArgs.Cancel) this.scheduler.draggingArgs.Cancel = true;
        if (this.scheduler.draggingArgs.Cancel || !this.draggingArgs.Valid)
            return true;
    }
    return false;
}

SchedulerItem.prototype.createDragArgs = function(e, mode) {
    var This = this;
    this.scheduler.draggingArgs = {
        DraggingItem: this,
        Mode: mode,
        OldBegin: this.scheduler.CalcDateTime(this.firstColumn),
        OldEnd: this.scheduler.CalcDateTime(this.lastColumn, true),
        OldRow: this.row,
        Cancel: false,
        Valid: true
    };
    this.scheduler.draggingArgs.NewRow = this.scheduler.draggingArgs.OldRow;
    this.scheduler.draggingArgs.NewBegin = this.scheduler.draggingArgs.OldBegin;
    this.scheduler.draggingArgs.NewEnd = this.scheduler.draggingArgs.OldEnd;

    return {
        Item: This,
        pt: e.GetPt(This.scheduler.bodyDiv),
        saveFirst: This.firstColumn,
        saveLast: This.lastColumn,
        saveRow: This.row,

        StartEdit: function() { This.Edit(); },
        AcceptDragging: function() {
            if (This.draggingArgs != null && This.draggingArgs.Valid) {
                This.scheduler.InvokeNewEvent("ItemDragged", This.draggingArgs);
                if (This.draggingArgs.Cancel)
                    this.CancelDragging();
                else {
                    for (var i = This.scheduler.items.length; --i >= 0; ) {
                        var it = This.scheduler.items[i];
                        if (it != This && it.draggingArgs != null)
                            This.scheduler.InvokeNewEvent("ItemDragged", it.draggingArgs);
                    }
                }
            }
        },
        StopDragging: function() {
            This.scheduler.draggingArgs = null;
            for (var i = This.scheduler.items.length; --i >= 0; )
                This.scheduler.items[i].draggingArgs = null;
        }
    }
}

SchedulerItem.prototype.resize = function(e, changeFirst) {
    var args = this.createDragArgs(e, changeFirst ? SchedulerItemChangeMode.ChangeBegin : SchedulerItemChangeMode.ChangeEnd);
    var This = this;

    args.chgFirst = changeFirst;
    args.Element = this.scheduler.bodyDiv;
    args.Dragging = function(e) {
        var x = This.scheduler.GetColIndex(this.pt.X + e.DeltaX);

        if ((This.scheduler.behaviorOptions & SchedulerBehaviorOptions.AllowDraggingOutside) == 0) {
            if (x < 0) x = 0;
            if (x >= This.scheduler.numberOfCols) x = This.scheduler.numberOfCols - 1;
        }

        this.first = this.saveFirst;
        this.last = this.saveLast;

        if (changeFirst) {
            if (x > This.lastColumn) x = This.lastColumn;
            this.first = x;
            this.delta = x - This.firstColumn;
            This.scheduler.resizeFirstItemMode(this);
        }
        else {
            if (x < This.firstColumn) x = This.firstColumn;
            x += 1 / This.scheduler.nSubCells;
            this.last = x;
            this.delta = x - This.lastColumn;
            This.scheduler.resizeLastItemMode(this);
        }
        return !This.scheduler.draggingArgs.Cancel;
    };
    args.CancelDragging = function() {
        this.first = this.saveFirst;
        this.last = this.saveLast;

        if (changeFirst)
            This.scheduler.resizeFirstItemMode(this);
        else
            This.scheduler.resizeLastItemMode(this);
    }

    go.SetCapture(args);
}

SchedulerItem.prototype.drag = function(e) {
    var args = this.createDragArgs(e, SchedulerItemChangeMode.Move);
    var This = this;
    this.div.style.cursor = "pointer";
   
    args.saveDelta = this.scheduler.GetColIndex(args.pt.X)-this.firstColumn;
    args.linked = this;
    args.Element = this.scheduler.bodyDiv;
    args.Dragging = function(e) {
        this.row = this.saveRow;
        if ((This.allows & SchedulerItemAllows.ChangeResource)!=0) {
            var y = This.scheduler.GetRowIndex(this.pt.Y+e.DeltaY);
            if (0<=y && y<This.scheduler.visibleRows.length) {
                this.row = This.scheduler.visibleRows[y];
                if (!this.row.allowDrag
                    || (This.scheduler.behaviorOptions & SchedulerBehaviorOptions.AllowChangeLevelItem)==0 && this.row.parent!=this.saveRow.parent) 
                        this.row = this.saveRow;
            }
        }

        var allowDO = (This.scheduler.behaviorOptions & SchedulerBehaviorOptions.AllowDraggingOutside)!=0;
        var first = this.saveFirst;
        if ((This.allows & SchedulerItemAllows.ChangeTime)!=0) {
            var x = This.scheduler.GetColIndex(this.pt.X+e.DeltaX)-this.saveDelta;
            if (!allowDO && x<0) x = 0;
            if (allowDO || 0<=x && x<This.scheduler.numberOfCols) {
                first = x;
                if (!allowDO) {
                    var delta = (this.saveLast-this.saveFirst+first)-(This.scheduler.numberOfCols-1);
                    if (delta>0)
                        first -= delta;
                }
            }
        }
        this.delta = first-This.firstColumn;
        
        if (!This.scheduler.dragItemMode(this, 0))
            return;
        This.scheduler.dragItemMode(this, 1);

        return !This.scheduler.draggingArgs.Cancel;
    };
    args.CancelDragging = function() {
        this.delta = this.saveFirst - This.firstColumn;
        this.row = this.saveRow;
        if (This.scheduler.dragItemMode(this, 0))
            This.scheduler.dragItemMode(this, 1);
    }
    
    go.SetCapture(args);
}

SchedulerItem.prototype.get_Editing = function() {
    return this.editElement!=null;
}

SchedulerItem.prototype.Edit = function() {
    if (this.editElement!=null || this.div==null) return;
    if (!this.scheduler.CloseEditor(false)) return;
    if ((this.scheduler.behaviorOptions & SchedulerBehaviorOptions.EditableItemText)==0) return;
    if ((this.allows & SchedulerItemAllows.TextEdit)==0) return;
    if (go.duringPostback) return;
   
    var args = {Item: this, Text: this.text, Cancel: false};
    this.scheduler.InvokeClientEvent("ItemTextEditing", args);
    if (args.Cancel) return;

    var html = "<input type=text style='text-align: ";
    html += this.align;
    html += "; overflow: hidden; width: 100%; height: 100%; border: 0px; font-size: x-small; font-family: Arial'>";
    html += "</input>";
    this.div.innerHTML = html;
   
    this.editElement = this.div.getElementsByTagName("INPUT")[0];
    this.editElement.value = args.Text;
    this.scheduler.Attach(this, "input_KeyDown", this.editElement);
    this.editElement.focus();
    this.editElement.select();
    this.scheduler.editor = this;
}

SchedulerItem.prototype.CloseEditor = function(cancel, element) {
    if (this.editElement==null) return true;
    if (element) {
        if (element==this.editElement) return false;
    }
    if (!cancel) {
        var text = this.editElement.value;

        var args = {Item: this, 
            NewText: this.editElement.value, OldText: this.text,
            Cancel: false};
            
        if (args.NewText!=args.OldText) {
            this.scheduler.InvokeEvent("ItemTextEdited", args);
            if (args.Cancel) return false;

            this.text = args.NewText;
        }
    }

    this.div.removeChild(this.editElement);
    this.editElement = null;
    this.Resync();
    this.scheduler.editor = null;
    return true;
}

SchedulerItem.prototype.input_KeyDown = function(e) {
    if (e.KeyCode==13) {
        this.CloseEditor(false);
        return false;
    }
    else if (e.KeyCode==27)
        this.CloseEditor(true);
}

SchedulerItem.prototype.isOverlapped = function(first, last, row, excludes) {
    for (var i = this.scheduler.items.length; --i>=0;) {
        var it = this.scheduler.items[i];
        if (it!=this && it.row==row && last>it.firstColumn && it.lastColumn>first)
            if (it.findItem(excludes)<0)
                return true;
    }
    return false;
}

SchedulerItem.prototype.GetAllLinked = function(children) {
    var arr = [];
    if (typeof(children)=="undefined" || children)
        this.collectChildren(arr);
    else
        arr.push(this);
    if (typeof(children)=="undefined" || !children)
        this.collectParents(arr);
    return arr;
}

SchedulerItem.prototype.collectChildren = function(arr) {
    if (this.findItem(arr)>=0) return;
    arr.push(this);
    if (this.linkToIDs!=null)
        for (var i = this.linkToIDs.length; --i>=0;)
            this.scheduler.itemsByID[this.linkToIDs[i]].collectChildren(arr);
}

SchedulerItem.prototype.collectParents = function(arr) {
    if (this.backLinks!=null) {
        for (var i = this.backLinks.length; --i>=0;) {
            var it = this.backLinks[i];
            if (it.findItem(arr)<0) {
                arr.push(it);
                it.collectParents(arr);
            }
        }
    }
}

SchedulerItem.prototype.findItem = function(arr) {
    for (var i = arr.length; --i>=0;)
        if (arr[i]==this) return i;
    return -1;
}

SchedulerItem.prototype.Init = function(row) {
    this.scheduler = row.scheduler;
    this.row = row;
    this.index = this.scheduler.items.length;
    this.scheduler.items.push(this);
    this.scheduler.itemsByID[this.itemID] = this;
    this.initBackLinks = false;
}

RegisterType("SchedulerItem");

function SchedulerItem() {
    this.div = null;
    this.linkDivs = null;
    this.backLinks = null;
    this.editElement = null;
    this.draggingArgs = null;
    this.nItem = 0;
    this.initBackLinks = false;
    return this;
}

/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

//
// Events
//

Scheduler.prototype.splitter_MouseDown = function(e) {
    if (!this.CloseEditor(false)) return;
    if ((this.behaviorOptions & SchedulerBehaviorOptions.ResizeableResourcesPanel)==0) return;
    if (go.duringPostback) return;

    var cols = this.main.getElementsByTagName("COL");
    var w0start = cols[0].width;
    var This = this;
    go.SetCapture(function(e) {
        This.set_ResourcesWidth(go.AddPx(w0start, e.DeltaX));
    });
}

Scheduler.prototype.getScrollResHeader = function(e) {
    var x = e.SenderPt().X;
    for (var col = 0; col<this.resHeader.rows[0].cells.length; ++col) {
        var td = this.resHeader.rows[0].cells[col];
        var colx = td.offsetLeft+td.offsetWidth;
        if (colx-2<=x && x<=colx+2)
            return this.columns[col];
    }
    return null;
}

Scheduler.prototype.resHeader_MouseMove = function(e) {
    if ((this.behaviorOptions & SchedulerBehaviorOptions.ResizeableResourceColumns)!=0) 
        this.resHeader.style.cursor = this.getScrollResHeader(e)!=null ? "w-resize" : "";
}

Scheduler.prototype.resHeader_MouseDown = function(e) {
    if (go.duringPostback) return;
    
    var pt = e.SenderPt();
    this.clickedItem = null;
    this.clickedRow = null;
    this.clickedDateTime = 0;
    var x = this.GetResourceColIndex(pt.X);
    if (x>=0)
        this.clickedColumn = this.columns[x];
    else
        this.clickedColumn = null;

    if (!this.CloseEditor(false)) return;
    if ((this.behaviorOptions & SchedulerBehaviorOptions.ResizeableResourceColumns)==0) return;

    var col = this.getScrollResHeader(e);
    if (col==null) return;
    
    var orgWidth = this.resHeader.getElementsByTagName("COL")[col.index].width;

    go.SetCapture({
        Dragging : function(e) {
            var width = go.AddPx(orgWidth, e.DeltaX);
            if (go.ComparePx(width, 0)>0) 
                col.set_Width(width);
        },
        Cursor : "w-resize"
    });
}

Scheduler.prototype.bodyDiv_Scroll = function() {
    this.timeLineDiv.scrollLeft = this.bodyDiv.scrollLeft;
    if (!this.insideScroll) {
        try {
            this.insideScroll = true;
            this.resListDiv.scrollTop = this.bodyDiv.scrollTop;
        }
        finally {
            this.insideScroll = false;
        }
    }
    this.firstVisibleRow = -this.bodyDiv.scrollTop;
    this.firstVisibleCell = -this.bodyDiv.scrollLeft;
}

Scheduler.prototype.bodyDiv_MouseDown = function(e) {
    var pt = e.SenderPt();
    this.clickedItem = null;
    var row = this.GetRowIndex(pt.Y);
    if (0<=row && row<this.visibleRows.length)
        this.clickedRow = this.visibleRows[row];
    else
        this.clickedRow = null;
    this.clickedColumn = null;
    var x = this.GetColIndex(pt.X);
    if (x<0)
        this.clickedDateTime = 0;
    else
        this.clickedDateTime = this.CalcDateTime(x).getTime();
}

Scheduler.prototype.timeLine_MouseDown = function(e) {
    var pt = e.SenderPt();
    this.clickedItem = null;
    this.clickedRow = null;
    this.clickedColumn = null;
    var x = this.GetColIndex(pt.X);
    if (x<0)
        this.clickedDateTime = 0;
    else
        this.clickedDateTime = this.CalcDateTime(x).getTime();
}

Scheduler.prototype.resListDiv_Scroll = function() {
     this.resHeaderDiv.scrollLeft = this.resListDiv.scrollLeft;
     if (!this.insideScroll) {
        try {
            this.insideScroll = true;
            this.bodyDiv.scrollTop = this.resListDiv.scrollTop;
        }
        finally {
            this.insideScroll = false;
        }
     }
}

Scheduler.prototype.treeImage_MouseDown = function(e) {
    if (go.duringPostback) return;
    if (!this.CloseEditor(false)) return;

    var i = 2;
    var ele = e.Sender;
    while (i>0) {
        ele = ele.parentNode;
        if (ele==null) return;
        if (ele.tagName=="TR") --i;
    }
    var index = ele.rowIndex;
    var row = this.visibleRows[index];
    row.set_Expanded(!row.get_Expanded());
}

Scheduler.prototype.resList_MouseDown = function(e) {
    if (go.duringPostback) return;
    var pt = e.SenderPt();
    var col = this.GetResourceColIndex(pt.X);
    var row = this.GetRowIndex(pt.Y);

    this.clickedItem = null;
    if (0<=row && row<this.visibleRows.length)
        this.clickedRow = this.visibleRows[row];
    else
        this.clickedRow = null;
    this.clickedDateTime = 0;
    if (col>=0)
        this.clickedColumn = this.columns[col];
    else
        this.clickedColumn = null;

    if (!(0<=col && col<this.columns.length)) return;
    if (!(0<=row && row<this.visibleRows.length)) return;
    
    var resRow = this.visibleRows[row];
    var resCol = this.columns[col];
    if (resCol.IsTree()) {
        var td = this.resList.rows[row].cells[col];
        var table = td.getElementsByTagName("TABLE")[0];
        if (table==null) return;
        var td2 = table.rows[0].cells[table.rows[0].cells.length-1];
        var x = e.GetPt(td2).X;
        if (x<0) return;
    }
    
    setTimeout(function() { resRow.Edit(col); }, 100);
}

Scheduler.prototype.main_MouseDown = function(e) {
    this.CloseEditor(false, e.Source);
}

Scheduler.prototype.ResizeControl = function() {
    this.CloseEditor(true);
    var h;
    if ((this.viewOptions & SchedulerViewOptions.InvisibleVerticalScrollBar) != 0) {
        h = this.bodyRows.offsetHeight + this.timeLineDiv.parentNode.offsetHeight;
        var sh = this.resListDiv.offsetHeight - this.resListDiv.clientHeight;
        if (this.captionTable != null) {
            h += this.captionTable.offsetHeight;
            if (sh != 0) sh += 4;
        }
        h += sh;
        this.mainElement.style.height = h + "px";
    }
    h = this.mainElement.offsetHeight - this.timeLine.offsetHeight;
    if (this.captionTable != null)
        h -= this.captionTable.offsetHeight;
    if (h > 0) {
        this.resListDiv.style.height = h + "px";
        this.resList.parentNode.style.height = h + "px"; // required for opera
        this.bodyDiv.style.height = h + "px";
    }

    var w;
    if ((this.viewOptions & SchedulerViewOptions.InvisibleHorizontalScrollBar) != 0) {
        w = this.bodyCols.offsetWidth + this.resListDiv.parentNode.offsetWidth;
        var cells = this.bodyCols.rows[0].cells;
        w -= cells[cells.length - 1].offsetWidth;
        w += this.main.rows[0].cells[1].offsetWidth;
        var sw = this.bodyDiv.offsetWidth - this.bodyDiv.clientWidth;
        w += sw;
        this.mainElement.style.width = w + "px";
    }
    //    else {
    w = this.mainElement.clientWidth;
    w -= this.resListDiv.clientWidth;
    w -= this.main.rows[0].cells[1].offsetWidth;
    if (w > 0) {
        if (!go.IsChrome)
            this.bodyDiv.style.width = w + "px";
        this.timeLineDiv.style.width = w + "px";
        this.timeLineDiv.width = w + "px";

        if ((this.viewOptions & SchedulerViewOptions.ShowCaption) != 0)
            this.main.rows[0].cells[2].getElementsByTagName("TABLE")[0].style.width = w + "px";
    }
    //    }
    //XX    this.timeLineDiv.style.height = this.timeLineDiv.getElementsByTagName("TABLE")[0].clientHeight-1 + "px";
    
    w = this.bodyDiv.offsetWidth - this.bodyDiv.parentNode.clientWidth;
    if (w <= 0) w = 1;
    var cols = this.main.getElementsByTagName("COL");
    if (go.ComparePx(cols[3].style.width, w) != 0) {
        cols[3].style.width = w + "px";
        var td;
        if (this.mainFirstCell != 0)
            td = this.main.rows[1].cells[1];
        else
            td = this.main.rows[0].cells[3];
        td.style.width = w + "px";
    }
    this.bodyDiv_Scroll();
}

Scheduler.prototype.resyncSums = function() {
    if (!this.isSum) return;
    
    for (var i = this.visibleRows.length; --i>=0;)
        this.visibleRows[i].sumItems = null;
    for (i = this.items.length; --i>=0;) {
        var it = this.items[i];
        var r = it.row.parent;
        if (r!=null) {
            var showExpanded = (this.viewOptions & SchedulerViewOptions.HideExpandedRowSum)==0;
            if (r.visibleIndex>=0 && r.sumMode!=ResourceRowSumMode.None && (showExpanded || !r.expanded)) {
                if (r.sumItems==null) r.sumItems = [];
                r.sumItems.push(it);
            }
            for (r = r.parent; r!=null; r = r.parent) {
                if (r.visibleIndex>=0 && r.sumMode==ResourceRowSumMode.AllLevels && (showExpanded || !r.expanded)) {
                    if (r.sumItems==null) r.sumItems = [];
                    r.sumItems.push(it);
                }
            }
        }
    }
}

Scheduler.prototype.GetColX = function(col, end) {
    if (this.bodyCols.rows.length <= 0) return 0;

    var cells = this.bodyCols.rows[0].cells;
    var c = Math.floor(col);
    if (c < 0) c = 0;
    else if (c >= cells.length) c = cells.length - 1;
    var cell = cells[c];
    var x = cell.offsetLeft;
    if (!go.IsFirefox)
        ++x;
    if (c != col)
        x += (cell.offsetWidth) * (col - c);
    else if (typeof (end) != "undefined" && end)
        --x;
    return x;
}

Scheduler.prototype.GetResourceColX = function(col, end) {
    var cell = this.resHeader.rows[0].cells[col];
    var x = cell.offsetLeft;
    if (typeof(end)!="undefined" && end)
        x += cell.offsetWidth-(go.IsFirefox ? 1 : 0);
    else if (!go.IsFirefox)
        ++x;
    return x;
}

Scheduler.prototype.GetRowY = function(row, end) {
    var cell = this.bodyRows.rows[row];
    var y = cell.offsetTop;
    if (typeof(end)!="undefined" && end)
        y += cell.offsetHeight-(go.IsFirefox ? 1 : 0);
    else if (!go.IsFirefox)
        ++y;
    return y;
}

Scheduler.prototype.GetColIndex = function(x, involveOffset) {
    if (involveOffset)
        x += this.bodyDiv.scrollLeft;
    var t = this.bodyCols.rows[0].cells;
    for (var i = t.length; --i>=0;) {
        var x1 = t[i].offsetLeft;
        if (x1<=x && i<t.length-1) {
            var delta = t[i+1].offsetLeft-x1;
            delta = (x-x1)/delta;
            delta = Math.floor(this.nSubCells*delta);
            if (this.nSubCells>0)
                delta /= this.nSubCells;
            return i+delta;
        }
    }
    return -1;
}

Scheduler.prototype.GetResourceColIndex = function(x, involveOffset) {
    if (involveOffset)
        x += this.resHeaderDiv.scrollLeft;
    var t = this.resHeader.rows[0].cells;
    for (var i = t.length; --i>=0;)
        if (t[i].offsetLeft<=x)
            return i;
    return -1;
}

Scheduler.prototype.GetRowIndex = function(y, involveOffset) {
    var t = this.bodyRows.rows;
    if (involveOffset)
        y += this.bodyDiv.scrollTop;
    if (t.length>0) {
        if (t[t.length-1].offsetTop+t[t.length-1].offsetHeight<=y)
            return -1;
        for (var i = t.length; --i>=0;)
            if (t[i].offsetTop<=y)
                return i;
    }
    return -1;
}

Scheduler.prototype.CloseEditor = function(cancel, element) {
    if (this.editor!=null)
        return this.editor.CloseEditor(cancel, element);
    return true;
}

Scheduler.prototype.IsEditing = function() {
    return this.editor!=null;
}

//
// Properties
//

Scheduler.prototype.get_Columns = function() {
    return this.columns;
}

Scheduler.prototype.get_Rows = function() {
    return this.rows;
}

Scheduler.prototype.get_VisibleRows = function() {
    return this.visibleRows;
}

Scheduler.prototype.get_Items = function() {
    return this.items;
}

Scheduler.prototype.get_Regions = function() {
    return this.regions;
}

Scheduler.prototype.get_CellWidth = function() {
    return this.cellWidth;
}

Scheduler.prototype.get_CollapsedCellWidth = function() {
    return this.collapsedCellWidth;
}

Scheduler.prototype.get_RowHeight = function() {
    return this.rowHeight;
}

Scheduler.prototype.get_ResourcesWidth = function() {
    return this.resourcesWidth;
}

Scheduler.prototype.set_ResourcesWidth = function(value) {
    this.resourcesWidth = value;
    
    if (go.ComparePx(value, 0)>0) {
        var cols = this.main.getElementsByTagName("COL");
        cols[0].width = value;
        var td;
        
        td = this.main.rows[0].cells[0];
        td.style.width = value;
        td.getElementsByTagName("DIV")[0].style.width = value;
        
        td = this.main.rows[this.mainFirstCell+1].cells[0];
        td.style.width = value;
        td.getElementsByTagName("DIV")[0].style.width = value;
        
        if (go.IsOpera || go.IsNetscape)
            this.RenderOpera(false);
    }

    this.InvokeEvent("ResourcesWidthChanged");
}

Scheduler.prototype.get_BehaviorOptions = function() {
    return this.behaviorOptions;
}

Scheduler.prototype.get_ViewOptions = function() {
    return this.viewOptions;
}

//
// Date and times
//

Scheduler.prototype.CalcColumn = function(dt) {
    if (typeof(dt)!="number") dt = dt.getTime();
    if (this.firstDateTime==dt) return 0;
    var v;
    if (this.firstDateTime<=dt) {
        for (v = 1; v<1000; ++v)
            if (dt<this.CalcDateTime(v).getTime())
                return v-1;
        return v;
    }
    else {
        for (v = -1; v>-1000; --v)
            if (dt>=this.CalcDateTime(v).getTime())
                return v;
        return -1000;
    }
}

Scheduler.prototype.CalcColumnExact = function(dt) {
    if (typeof(dt)!="number") dt = dt.getTime();
    var col = this.CalcColumn(dt);
    var t1 = this.CalcDateTime(col).getTime();
    if (t1==dt) return col;
    var t2 = this.CalcDateTime(col+1).getTime();
    return col+(dt-t1)/(t2-t1);
}

Scheduler.prototype.get_FirstDateTime = function() {
    return new Date(this.firstDateTime);
}

Scheduler.prototype.set_FirstDateTime = function(value) {
    if (typeof(value)!="number") value = value.getTime();
    this.firstDateTime = value;
    this.InvokeEvent("FirstDateTimeChanged");
}

Scheduler.prototype.get_NumberOfCols = function() {
    return this.numberOfCols;
}

Scheduler.prototype.set_NumberOfCols = function(value) {
    this.numberOfCols = value;
    this.InvokeEvent("NumberOfColsChanged");
}

Scheduler.prototype.get_CellTimeSpan = function() {
    var t1 = this.CalcDateTime(0).getTime();
    var t2 = this.CalcDateTime(1).getTime();
    return new Date(t2-t1);
}

Scheduler.prototype.SetDateAndNCols = function(date, ncol) {
    try {
        this.LockEvent();
        this.set_FirstDateTime(date);
        this.set_NumberOfCols(ncol);
    }
    finally {
        this.UnlockEvent();
    }
}

Scheduler.prototype.get_Caption = function() {
    return this.caption;
}

Scheduler.prototype.set_Caption = function(value) {
    this.caption = value;
    this.captionTable.rows[0].cells[1].innerHTML = value;
}

Scheduler.prototype.PressNextPage = function() {
    if (go.duringPostback) return;
    this.InvokeEvent("ButtonPressed", {Button: SchedulerButton.NextPage});
}

Scheduler.prototype.PressPreviousPage = function() {
    if (go.duringPostback) return;
    this.InvokeEvent("ButtonPressed", {Button: SchedulerButton.PreviousPage});
}

Scheduler.prototype.get_ClickedItem = function() {
    return this.clickedItem;
}

Scheduler.prototype.get_ClickedRow = function() {
    return this.clickedRow;
}

Scheduler.prototype.get_ClickedColumn = function() {
    return this.clickedColumn;
}

Scheduler.prototype.get_ClickedDateTime = function() {
    return new Date(this.clickedDateTime);
}

Scheduler.prototype.get_FirstVisibleRow = function() {
    return this.firstVisibleRow;
}

Scheduler.prototype.set_FirstVisibleRow = function(value) {
    this.firstVisibleRow = value;
    var y = 0;
    if (value > 0) {
        if (value >= this.bodyRows.rows.length) value = this.bodyRows.rows.length-1;
        if (value < 0) return;
        y = this.GetRowY(value, false);
    }
    else
        y = -value;
    this.bodyDiv.scrollTop = y;
}

Scheduler.prototype.get_FirstVisibleCell = function() {
    return this.firstVisibleCell;
}

Scheduler.prototype.set_FirstVisibleCell = function(value) {
    this.firstVisibleCell = value;
    var x = 0;
    if (value>0)
        x = this.GetColX(value, false);
    else
        x = -value;
    this.bodyDiv.scrollLeft = x;
}

Scheduler.prototype.get_HoverItem = function() {
    return this.hoverItem;
}

Scheduler.prototype.get_FreeTimeMode = function() {
    return this.freeTimeMode;
}

Scheduler.prototype.get_LinkLineMode = function() {
    return this.linkLineMode;
}

//
// Initialize
//

Scheduler.prototype.CalcDateTime = function(c, rightAlign) {
    var col = this.mapCol(c);
    if (typeof (rightAlign) != "undefined" && rightAlign) {
        for (var c2 = c - 1; c2 >= 0; --c2) {
            var col2 = this.mapCol(c2);
            if (col2 < col) {
                col = col2 + 1;
                break;
            }
        }
    }
    return this.calcDT(col);
}

Scheduler.prototype.InitArrows = function(arrowRight, arrowUp, arrowDown) {
    this.arrowRight = arrowRight;
    this.arrowUp = arrowUp;
    this.arrowDown = arrowDown;
}

Scheduler.prototype.InitRuler = function(l0Expr, l1Expr) {
    this.level0Expr = l0Expr;
    this.level1Expr = l1Expr;
}

Scheduler.prototype.AfterSerializing = function(isCallback) {
    this.GoControl_AfterSerializing(isCallback);
    if ((this.viewOptions & SchedulerViewOptions.InvisibleVerticalScrollBar) != 0)
        if (this.mainElement.offsetHeight == 0)
            this.mainElement.style.height = "10px";
}

Scheduler.prototype.Loaded = function(isCallback) {
    this.mainFirstCell =
        (this.viewOptions & SchedulerViewOptions.ShowFirstTimeline) != 0 &&
        (this.viewOptions & SchedulerViewOptions.ShowCaption) != 0 ?
        1 : 0;

    this.bodyCols = this.timeLine = this.resList = this.resHeader = null;

    this.editor = null;
    this.draggingArgs = null;

    this.isSum = false;
    this.visibleRows = [];
    this.items = [];
    this.itemsByID = {};
    this.regions2 = [];
    for (var i = 0; i < this.rows.length; ++i)
        this.rows[i].addVisibleRow(true, this, 0, null);
    for (i = 0; i < this.columns.length; ++i) {
        var col = this.columns[i];
        col.index = i;
        col.scheduler = this;
    }
    for (i = 0; i < this.regions.length; ++i) {
        var r = this.regions[i];
        r.Init(i, this);
        if (r.temporary) {
            this.regions2.push(r);
            this.regions.splice(i--, 1);
        }
    }

    this.GoControl_Loaded(isCallback);

//    if (!isCallback)
//        if (go.IsOpera || go.IsNetscape)
//        setInterval(go.Delegate(this, "opera_Timer"), 50);
}

RegisterType("Scheduler", "GoControl");

function Scheduler() {
    this.GoControl();
    this.RenderDoubleBuffer = true;
    this.insideScroll = false;
    this.hoverItem = null;
    this.nSubCells = 1; 
    this.dragItemMode = this.dragItemOnlyMeMode;
    this.resizeFirstItemMode = this.resizeItemOnlyMeMode;
    this.resizeLastItemMode = this.resizeItemOnlyMeMode;

    this.clickedDateTime = 0;
    this.clickedItem = null;
    this.clickedRow = null;
    this.clickedColumn = null;
}

/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

Scheduler.prototype.InitRender = function() {
    this.level0 = [];
    this.level1 = [];
    this.areBoldLines = true;

    for (var col = 0; col<this.numberOfCols; ++col) {
        if (this.IsCollapsed(col))
            this.level0.push("");
        else
            this.level0.push(this.level0Expr(this, col));
        var s = this.level1Expr(this, col);
        this.level1.push(s);
        if (this.areBoldLines && s!=null && s.indexOf('`')>=0) this.areBoldLines = false;
    }
    this.level0.push("");
    this.level1.push("");
}

Scheduler.prototype.CalcColSpan = function(arr, idx) {
    var n = 1;
    while (++idx<arr.length) {
        if (arr[idx]!=null) break;
        ++n;
    }
    return n;
}

Scheduler.prototype.RenderMain = function() {
    var cpt = (this.viewOptions & SchedulerViewOptions.ShowCaption) != 0;
    var html = [];
    html.push("<table border=0 cellpadding=0 cellspacing=0 style='border-collapse: collapse; table-layout: fixed'>");
    html.push("<col width=");
    html.push(this.resourcesWidth);
    html.push("/><col width=4px /><col /><col width=0px />");
    html.push("<tr>");
    this.resourceHeaderStyle.EmitElement(html, "td", "valign=bottom" + (cpt ? " rowspan=2" : ""), null);
    html.push("<div style='width:");
    html.push(this.resourcesWidth);
    html.push("; overflow: hidden;'></div></td>");
    html.push("<td rowspan=");
    html.push(this.mainFirstCell!=0 ? "3" : "2");
    html.push("bgcolor=");
    html.push(this.splitterColor);
    if ((this.behaviorOptions & SchedulerBehaviorOptions.ResizeableResourcesPanel)!=0) 
        html.push("style='cursor: w-resize;'");
    html.push("><div style='width:4px'></div></td>");
    if (cpt) {
        html.push("<td colspan=2>");
        this.captionStyle.EmitElement(html, "table", "border=0 cellspacing=0", null);
        html.push("<tr><td width=1px>");
        html.push(this.previousButton);
        html.push("</td><td>");
        html.push(this.caption);
        html.push("</td><td width=1px>");
        html.push(this.nextButton);
        html.push("</td>");
        html.push("</tr></table></td></tr>");
        html.push("<tr>");
    }
    this.timeLineStyle.EmitElement(html, "td", "valign=bottom", "overflow:hidden");
    html.push("<div style='overflow: hidden;position:relative'></div></td>");
//    html.push("<div style='overflow: hidden'></div></td>"); // ie7 ie8-compatibility mode
    html.push("<td></td></tr>");

    var scrollBody = "overflow: scroll";
    var scrollRes = "overflow-x: scroll; overflow-y: hidden";
    if ((this.viewOptions & SchedulerViewOptions.InvisibleHorizontalScrollBar)!=0) {
        scrollRes = "overflow: hidden";
        if ((this.viewOptions & SchedulerViewOptions.InvisibleVerticalScrollBar)!=0)
            scrollBody = "overflow: hidden";
        else
            scrollBody = "overflow-x: hidden; overflow-y: scroll";
    }
    else {
        if ((this.viewOptions & SchedulerViewOptions.InvisibleVerticalScrollBar)!=0)
            scrollBody = "overflow-x: scroll; overflow-y: hidden";
    }

    html.push("<tr>");
    this.resourceListStyle.EmitElement(html, "td", null, null);
    html.push("<div style='width:");
    html.push(this.resourcesWidth);
    html.push(";");
    html.push(scrollRes);
    html.push(";'></div></td>");
    this.bodyStyle.EmitElement(html, "td", "colspan=2", null);
    
    html.push("<div style='");
    html.push(scrollBody);
    html.push("; position: relative; left: 0px; top: 0px;'></div></td>");
    html.push("</tr></table>");

    return html.join(" ");
}

Scheduler.prototype.calcCellWidth = function(col) {
    if (this.IsCollapsed(col))
        return this.collapsedCellWidth;
    return this.cellWidth;
}

Scheduler.prototype.IsCollapsed = function(col) {
    if (this.freeTimeMode==FreeTimeMode.Collapsed) {
        for (var i = this.regions.length; --i>=0;)
            if (this.regions[i].collapsed && this.regions[i].firstColumn<=col && col<this.regions[i].lastColumn)
                return true;
        for (var i = this.regions2.length; --i>=0;)
            if (this.regions2[i].collapsed && this.regions2[i].firstColumn<=col && col<this.regions2[i].lastColumn)
                return true;
    }
    return false;
}

Scheduler.prototype.RenderTimeLine = function(id) {
    var html = [];
    var ncells = this.numberOfCols + 1;

    html.push("<div style='width:10px'>");
//    html.push("<div style='width:10px;position:relative'>");  ie7 ie8-compatibility mode
//XX    html.push("<div style='position:absolute;left:150px;top:0px;width:100px;height:100px;background-color:yellow;z-index:1'></div>");
//    html.push("<table style='position:absolute;left:0px;top:0px;border-collapse: collapse; table-layout: fixed;z-index:2' cellpadding=0 cellspacing=0>");
    html.push("<table style='border-collapse: collapse; table-layout: fixed;z-index:2' cellpadding=0 cellspacing=0>");
    for (var col = 0; col < ncells; ++col) {
        html.push("<col width=");
        if (col < ncells - 1) {
            var cw = this.calcCellWidth(col);
            if (go.IsIE8) {
                var lineW;
                if (this.areBoldLines && this.level1[col] != null)
                    lineW = go.GetLineWidth(this.verticalLine0);
                else if (this.level0[col] != null)
                    lineW = go.GetLineWidth(this.verticalLine1);
                else
                    lineW = go.GetLineWidth(this.verticalLine2);
                cw = go.AddPx(cw, lineW);
            }
            html.push(cw);
        }
        else
            html.push("1000px");
        html.push("/>");
    }

    if (go.IsIE && !go.IsIE8)
        html.push("<tr style='display: none'>");
    else
        html.push("<tr>");
    for (var col = 0; col < ncells; ++col) {
        var border;
        if (this.areBoldLines && this.level1[col] != null)
            border = this.verticalLine0;
        else {
            if (this.level0[col] != null)
                border = this.verticalLine1;
            else
                border = this.verticalLine2;
        }
        html.push("<td style='border-left:");
        html.push(border);
        html.push("'><div style='width:");
        if (col < ncells - 1)
            html.push(this.calcCellWidth(col));
        else
            html.push("1000px");
        html.push("'></div></td>");
    }
    html.push("</tr>");

    if ((this.viewOptions & SchedulerViewOptions.ShowFirstTimeline) != 0) {
        var forceLeft = false;
        for (var col = 0; col < ncells && !forceLeft; ++col)
            if (this.level1[col] != null)
            forceLeft = this.level1[col].indexOf('`') >= 0;

        html.push("<tr height=1px");
        if (forceLeft)
            html.push("align=left");
        html.push(">");
        for (var col = 0; col < ncells; ++col) {
            if (this.level1[col] != null) {
                var ipx = this.level1[col].indexOf('`');
                html.push("<td colspan=");
                html.push(this.CalcColSpan(this.level1, col));
                html.push("style='overflow: hidden");
                if (ipx < 0) {
                    html.push("; border-left:");
                    html.push(this.verticalLine0);
                }
                if (go.IsIE)
                    html.push("'><span style='display: inline-block; overflow: hidden'><nobr>");
                else
                    html.push("'><span style='display: block; overflow: hidden'><nobr>");
                var s = this.level1[col].substring(ipx + 1);
                if (ipx >= 0) {
                    //                    if (go.IsIE) 
                    html.push("<span style='display: inline-block; width:");
                    //                  else
                    //                       html.push("<span style='width:");
                    html.push(this.level1[col].substring(0, ipx));
                    html.push("; border-right:");
                    html.push(this.verticalLine0);
                    html.push("'>&nbsp;</span></nobr></span></td>");
                }
                else
                    html.push("</nobr></span></td>");
            }
        }
        html.push("</tr>");
    }

    html.push("<tr height=1px>");
    for (var col = 0; col < ncells; ++col) {
        var border;
        if (this.areBoldLines && this.level1[col] != null) border = this.verticalLine0;
        else if (this.level0[col] != null) border = this.verticalLine1;
        else border = null;
        if (border != null) {
            html.push("<td colspan=");
            html.push(this.CalcColSpan(this.level0, col));
            html.push("style='overflow: hidden; border-left:");
            html.push(border);
            html.push(";'><div style='overflow: hidden;'><nobr>");
            html.push(this.level0[col]);
            html.push("</nobr></div></td>");
        }
    }
    html.push("</tr>");

    html.push("<tr height=5px>");
    for (var col = 0; col < ncells; ++col) {
        var border;
        if (this.areBoldLines && this.level1[col] != null) border = this.verticalLine0;
        else if (this.level0[col] != null) border = this.verticalLine1;
        else border = this.verticalLine2;
        html.push("<td style='border-left:");
        html.push(border);
        html.push(";border-bottom:");
        html.push(this.horizontalHeaderLine);
        html.push("'></div></td>");
    }
    html.push("</tr>");

    html.push("</table>");
    if (this.nowColumn >= 0 && (this.viewOptions & SchedulerViewOptions.ShowNowIndicatorInTimeline) != 0) {
        this.nowIndicatorStyle.EmitElement(html, "div", "ID=now1" + id, "position:absolute;left:-10px;top:0px;width:3px;height:100%;background-color:#F3B03E;border-right:1px solid red;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=35);-moz-opacity:0.35;opacity:0.35");
        html.push("</div>");
    }
    html.push("</div>");

    return html.join(" ");
}

Scheduler.prototype.RenderBody = function(id) {
    var html = [];
    var height = this.resList.clientHeight - this.resList.rows[this.resList.rows.length - 1].cells[0].clientHeight;

    html.push("<table cellpadding=0 cellspacing=0 style='border-collapse: collapse; position: absolute; left: 0px; top: 0px; z-index:10'><tr style='height:");
    html.push(height + "px");
    html.push("'>");

    for (var col = 0; col < this.numberOfCols + 1; ++col) {
        html.push("<td valign=bottom style='border-left:");
        if (this.areBoldLines && this.level1[col] != null)
            html.push(this.verticalLine0);
        else if (this.level0[col] != null)
            html.push(this.verticalLine1);
        else
            html.push(this.verticalLine2);
        html.push(";'><div style='width:");
        if (col < this.numberOfCols)
            html.push(this.calcCellWidth(col));
        else
            html.push("3px");
        html.push("; height:");
        html.push(height + "px");
        html.push("'></div></td>");
    }

    html.push("</tr></table>");
    //
    html.push("<table cellpadding=0 cellspacing=0 style='border-collapse: collapse; position: absolute; left: 0px; top: 0px; z-index:9'>");

    var width = this.timeLine.clientWidth - 1000;
    var html2 = "<td style='border-bottom: " + this.horizontalLine + "'><div style='width: " + width + "px";

    for (var j = 0; j < this.visibleRows.length; ++j) {
        var row = this.visibleRows[j];
        var height;
        if (row.realHeight != null)
            height = row.realHeight;
        else
            height = this.rowHeight;
        row.bodyStyle.EmitElement(html, "tr", null, null);
        html.push(html2);
        html.push(";height:");
        html.push(height);
        html.push("'></div></td></tr>");
    }

    html.push("</table>");

    if (go.IsOpera) {
        html.push("<div style='height:");
        html.push((height - 2) + "px");
        html.push("; width:");
        html.push(this.timeLine.clientWidth + "px");
        html.push("'></div>");
    }

    if (this.nowColumn >= 0 && (this.viewOptions & SchedulerViewOptions.ShowNowIndicatorInBody) != 0) {
        this.nowIndicatorStyle.EmitElement(html, "div", "ID=now2" + id, "position:absolute;left:-10px;top:0px;width:3px;height:100%;background-color:#F3B03E;border-right:1px solid red;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=35);-moz-opacity:0.35;opacity:0.35;z-index:10");
        html.push("</div>");
    }

    return html.join(" ");
}

Scheduler.prototype.RenderResHeader = function() {
    var html = [];
    html.push("<div><table style='border-collapse: collapse; table-layout: fixed' cellpadding=0 cellspacing=0>");
    for (var i = 0; i<this.columns.length; ++i) {
        html.push("<col width=");
        html.push(this.columns[i].width);
        html.push("/>");
    }
    html.push("<tr>");
    for (var i = 0; i<this.columns.length; ++i) {
        var col = this.columns[i];
    
        var s = "border-left: "+this.verticalResourceLine;
        if (i==this.columns.length-1)
            s += "; border-right: "+this.verticalResourceLine;
        s += "; border-top: "+this.horizontalHeaderLine+"; border-bottom: "+this.horizontalHeaderLine;
        col.headerStyle.EmitElement(html, "td", null, s);

        var ta = col.headerStyle.get_TextAlign();
        if (ta==null) 
            ta = "";
        else
            ta = " align="+ta;
        html.push("<div");
        html.push(ta);
//        html.push("style='height:");
//        html.push(this.rowHeight);
        //        html.push("; width:");
        html.push("style='padding:2px;width:");
        html.push(go.SubPx(col.width, 4));
        html.push("; overflow: hidden'><nobr>");
        html.push(col.text);
        html.push("</nobr></div></td>");
    }
    html.push("</tr>");
    html.push("</table><div>");
    return html.join(" ");
}

Scheduler.prototype.RenderResList = function() {
    var html = [];
    html.push("<div><table style='border-collapse: collapse; table-layout: fixed' cellpadding=0 cellspacing=0>");
    for (var i = 0; i < this.columns.length; ++i) {
        html.push("<col width=");
        html.push(this.columns[i].width);
        html.push("/>");
    }
    for (var j = 0; j < this.visibleRows.length; ++j) {
        var row = this.visibleRows[j];

        if (row.realHeight != null)
            height = row.realHeight;
        else
            height = this.rowHeight;

        row.headerStyle.EmitElement(html, "tr", "height=" + height, null);
        for (var i = 0; i < this.columns.length; ++i) {
            var col = this.columns[i];

            var s = "border-bottom: " + this.horizontalLine + "; border-left: " + this.verticalResourceLine;
            if (i == this.columns.length - 1)
                s += "; border-right: " + this.verticalResourceLine;

            col.rowsStyle.EmitElement(html, "td", null, s);

            html.push("<div style='width:");
            html.push(col.width);
            html.push("; height:");
            html.push(height);
            //            if (col.showTree && col.treeIndent!=null) {
            html.push("; overflow: hidden;'>");
            var img;
            if (row.HasChildren())
                img = row.get_Expanded() ? col.get_ExpandImageUrl() : col.get_CollapseImageUrl();
            else
                img = col.get_NoExpandImageUrl();
            var deep = row.deep;
            if (img == null)
                ++deep;
            html.push("<table style='width: 100%; height:100%; display: inline; border-collapse: collapse;'><tr>");
            if (col.showTree) {
                for (var k = deep; --k >= 0; ) {
                    html.push("<td><div style='width:");
                    html.push(col.treeIndent);
                    html.push("; overflow: hidden'></div></td>");
                }
                if (img != null) {
                    html.push("<td align=center><div style='width:");
                    html.push(col.treeIndent);
                    html.push("; overflow: hidden'><img name=go_img src='");
                    html.push(img);
                    html.push("' /></div></td>");
                }
            }
            html.push("<td style='width: 100%'><div style='");
            //            }
            html.push("; overflow: hidden'>");
            var s = row.CalcText(col.dataIndex);
            if (s == "")
                html.push("&nbsp;");
            else {
                html.push("<nobr>");
                html.push(s);
                html.push("</nobr>");
            }
            //            if (col.showTree && col.treeIndent!=null)
            html.push("</div></td></tr></table>");
            html.push("</div></td>");
        }
        html.push("</tr>");
    }

    html.push("<tr height=");
    html.push(this.rowHeight);
    html.push(">");
    for (var i = 0; i < this.columns.length; ++i) {
        var col = this.columns[i];
        html.push("<td><div style='width:");
        html.push(col.width);
        html.push("; overflow: hidden;'>&nbsp;</div></td>");
    }
    html.push("</tr>");
    html.push("</table><div>");
    return html.join(" ");
}

Scheduler.prototype.RenderControl = function(mainElement) {
    var now = new Date().getTime();
    var id = this.clientID + now;
    this.nowColumn = -1;
    now -= new Date().getTimezoneOffset() * 60 * 1000;

    if (this.firstDateTime <= now && now <= this.calcDT(this.numberOfCols).getTime())
        this.nowColumn = this.CalcColumnExact(now);

    this.CloseEditor(true);
    mainElement.innerHTML = this.RenderMain();
    this.main = mainElement.getElementsByTagName("TABLE")[0];

    var row1 = this.main.rows[this.mainFirstCell + 1];
    this.bodyDiv = row1.cells[1].getElementsByTagName("DIV")[0];
    this.bodyDiv.style.height = this.main.rows[1].offsetHeight + "px";
    this.resListDiv = row1.cells[0].getElementsByTagName("DIV")[0];
    this.resListDiv.style.height = this.main.rows[1].offsetHeight + "px";
    if (this.mainFirstCell != 0)
        this.timeLineDiv = this.main.rows[1].cells[0].getElementsByTagName("DIV")[0];
    else
        this.timeLineDiv = this.main.rows[0].cells[2].getElementsByTagName("DIV")[0];
    this.resHeaderDiv = this.main.rows[0].cells[0].getElementsByTagName("DIV")[0];
    if (this.mainFirstCell != 0)
        this.captionTable = this.main.rows[0].cells[2].getElementsByTagName("TABLE")[0];
    else
        this.captionTable = null;

    this.Attach(this, "splitter_MouseDown", this.main.rows[0].cells[1]);
    this.Attach(this, "resListDiv_Scroll", this.resListDiv);
    this.Attach(this, "bodyDiv_Scroll", this.bodyDiv);
    this.Attach(this, "bodyDiv_MouseDown", this.bodyDiv);
    this.InitRender();
    this.resyncSums();

    this.resListDiv.innerHTML = this.RenderResList();
    this.resList = this.resListDiv.getElementsByTagName("TABLE")[0];

    this.timeLineDiv.innerHTML = this.RenderTimeLine(id);
    this.timeLine = this.timeLineDiv.getElementsByTagName("TABLE")[0];

    this.resHeaderDiv.innerHTML = this.RenderResHeader();
    this.resHeader = this.resHeaderDiv.getElementsByTagName("TABLE")[0];

    this.bodyDiv.innerHTML = this.RenderBody(id);

    var now1 = document.getElementById("now1" + id);
    var now2 = document.getElementById("now2" + id);

    var tables = this.bodyDiv.getElementsByTagName("TABLE");
    this.bodyCols = tables[0];
    this.bodyRows = tables[1];
    var w0 = this.bodyCols.rows[0].cells[0].offsetWidth;
    var w1 = this.bodyCols.rows[0].cells[1].offsetWidth;
    if (w0 > w1)
        this.cellWidthPx = w0;
    else
        this.cellWidthPx = w1;
    this.smallHeightPx = (this.itemStyle == SchedulerItemStyle.WithText || this.bodyRows.rows.length == 0)
        ? 0 : Math.floor(this.bodyRows.rows[0].cells[0].offsetHeight / 4);

    this.set_FirstVisibleRow(this.firstVisibleRow);
    this.set_FirstVisibleCell(this.firstVisibleCell); // That requires this.bodyCols initializing.

    this.Attach(this, "timeLine_MouseDown", this.timeLine);
    this.Attach(this, "resHeader_MouseMove", this.resHeader);
    this.Attach(this, "resHeader_MouseDown", this.resHeader);
    this.Attach(this, "resList_MouseDown", this.resList); // It cannot be this.resListDiv, because causes horizontal scrolling problems.
    this.Attach(this, "main_MouseDown", this.main);
    var imgs = this.resList.getElementsByTagName("IMG");
    for (var i = imgs.length; --i >= 0; )
        if (imgs[i].name == "go_img")
        this.Attach(this, "treeImage_MouseDown", imgs[i]);

    if ((this.viewOptions & SchedulerViewOptions.ShowFirstTimeline) != 0)
        this.assignFirstLineWidths();

    if (this.nowColumn >= 0 && (now1 != null || now2 != null)) {
        var nowX = this.GetColX(this.nowColumn);
        if (now1 != null) now1.style.left = (nowX - now1.offsetWidth) + "px";
        if (now2 != null) {
            now2.style.left = (nowX - now2.offsetWidth) + "px";
            now2.style.height = this.bodyRows.offsetHeight + "px";
        }
    }

    this.ResizeControl();

//    if (go.IsOpera || go.IsNetscape)
//        this.RenderOpera(true);

    for (var i = this.items.length; --i >= 0; ) {
        var it = this.items[i];
        it.div = null;
        it.linkDivs = null;
        it.sumItem = null;
    }
    for (var i = 0; i < this.regions2.length; ++i) {
        this.regions2[i].div = null;
        this.regions2[i].Resync();
    }
    for (var i = 0; i < this.regions.length; ++i) {
        this.regions[i].div = null;
        this.regions[i].Resync();
    }
    if (this.isSum)
        for (var i = this.visibleRows.length; --i >= 0; )
        this.visibleRows[i].RenderRedunt();

    for (var i = 0; i < this.items.length; ++i)
        this.items[i].Resync();
    for (var i = this.items.length; --i >= 0; )
        this.items[i].ResyncLinks();
}

Scheduler.prototype.assignFirstLineWidths = function() {
    var idx = 0;
    for (var col = 0; col<this.numberOfCols-1; ++col) {
        if (this.level1[col]!=null) {
            var td = this.timeLine.rows[1].cells[idx++];
            var span = td.getElementsByTagName("span")[0];
            var nobr = span.getElementsByTagName("nobr")[0];
            var s = this.level1[col].substring(this.level1[col].indexOf('`') + 1);
            span.style.width = td.clientWidth+"px";
            nobr.innerHTML = nobr.innerHTML+s;
        }
    }
}

/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

//
// Drag item
//

Scheduler.prototype.dragItemNoneMode = function(drag, route) {
    return false;
}

Scheduler.prototype.dragItemOnlyMeMode = function(drag, route) {
    var it = drag.linked;
    if (route==0) {
        if ((this.behaviorOptions & SchedulerBehaviorOptions.AllowOverlapItems)==0)
            if (it.isOverlapped(it.firstColumn+drag.delta, it.lastColumn+drag.delta, drag.row, []))
                return false;
        return true;
    }
    it.MoveTo(it.firstColumn+drag.delta, it.lastColumn+drag.delta, drag.row);
    return true;
}

Scheduler.prototype.dragItemAllItemsMode = function(drag, route) {
    if (!drag.linked.push)
        drag.linked = drag.linked.GetAllLinked();
    if (route==0) {
        if ((this.behaviorOptions & SchedulerBehaviorOptions.AllowDraggingOutside)==0) {
            for (var i = drag.linked.length; --i>=0;) {
                var it = drag.linked[i];
                if (it.firstColumn+drag.delta<0) return false;
                if (it.lastColumn+drag.delta>=this.numberOfCols) return false;
            }
        }
        if ((this.behaviorOptions & SchedulerBehaviorOptions.AllowOverlapItems)==0) {
            for (var i = drag.linked.length; --i>=0;) {
                var it = drag.linked[i];
                if (it.isOverlapped(
                    it.firstColumn+drag.delta, it.lastColumn+drag.delta, 
                    i==0 ? drag.row : it.row, 
                    drag.linked))
                        return false;
            }
        }
        return true;
    }
    for (var i = drag.linked.length; --i>=0;) {
        var it = drag.linked[i];
        it.MoveTo(it.firstColumn+drag.delta, it.lastColumn+drag.delta, 
            i==0 ? drag.row : it.row);
    }
    return true;
}

Scheduler.prototype.dragItemChildrenMode = function(drag, route) {
    if (!drag.linked.push)
        drag.linked = drag.linked.GetAllLinked(true);
    return this.dragItemAllItemsMode(drag, route);
}

Scheduler.prototype.dragItemChildrenIncrementOrderMode = function(drag, route) {
    if (!drag.linked.push)
        drag.linked = drag.linked.GetAllLinked(true);
    var it = drag.linked[0];
    if (it.backLinks!=null) {
        for (var i = it.backLinks.length; --i>=0;)
            if (it.backLinks[i].lastColumn>it.firstColumn+drag.delta)
                return false;
    }
    return this.dragItemAllItemsMode(drag, route);
}

Scheduler.prototype.dragItemOnlyChangeRowsMode = function(drag, route) {
    var it = drag.linked;
    if (route==0) {
        if ((this.behaviorOptions & SchedulerBehaviorOptions.AllowOverlapItems)==0)
            if (it.isOverlapped(it.firstColumn, it.lastColumn, drag.row, []))
                return false;
        return true;
    }
    it.MoveTo(it.firstColumn, it.lastColumn, drag.row);
    return true;
}

//
// Resize item
//

Scheduler.prototype.resizeItemNoneMode = function(resize) {
}

Scheduler.prototype.resizeItemOnlyMeMode = function(resize) {
    if ((this.behaviorOptions & SchedulerBehaviorOptions.AllowOverlapItems)==0)
        if (resize.Item.isOverlapped(resize.first, resize.last, resize.Item.row, []))
            return;

    if (resize.chgFirst) 
        resize.Item.set_FirstColumn(resize.first);
    else
        resize.Item.set_LastColumn(resize.last);
}

Scheduler.prototype.resizeItemWithNeighbourMode = function(resize) {
    var firstDelta = 0;
    var lastDelta = 0;
    var t = [];
    t.push(resize.Item);
    if (resize.chgFirst) {
        if (resize.Item.backLinks!=null)
            for (var i = resize.Item.backLinks.length; --i>=0;)
                t.push(resize.Item.backLinks[i]);
        
        lastDelta = resize.delta;
    }
    else {
        if (resize.Item.linkToIDs!=null)
            for (var i = resize.Item.linkToIDs.length; --i>=0;)
                t.push(this.itemsByID[resize.Item.linkToIDs[i]]);

        firstDelta = resize.delta;
    }
        
    for (var i = t.length; --i>=1;)
        if (t[i].firstColumn+firstDelta>t[i].lastColumn+lastDelta)
            return;

    if ((this.behaviorOptions & SchedulerBehaviorOptions.AllowOverlapItems)==0) {
        if (resize.Item.isOverlapped(resize.first, resize.last, resize.Item.row, t))
            return;
        for (var i = t.length; --i>=1;)
            if (t[i].isOverlapped(t[i].firstColumn+firstDelta, t[i].lastColumn+lastDelta, t[i].row, t))
                return;
    }

    for (var i = t.length; --i>=1;)
        t[i].MoveTo(t[i].firstColumn+firstDelta, t[i].lastColumn+lastDelta, t[i].row);

    if (resize.chgFirst)
        resize.Item.set_FirstColumn(resize.Item.firstColumn+resize.delta);
    else
        resize.Item.set_LastColumn(resize.Item.lastColumn+resize.delta);
}

Scheduler.prototype.resizeItemIncrementOrderMode = function(resize) {
    if (resize.chgFirst) {
        if (resize.Item.backLinks!=null)
            for (var i = resize.Item.backLinks.length; --i>=0;)
                if (resize.Item.backLinks[i].lastColumn>resize.first)
                    return;
    }
    else {
        if (resize.Item.linkToIDs!=null)
            for (var i = resize.Item.linkToIDs.length; --i>=0;)
                if (this.itemsByID[resize.Item.linkToIDs[i]].firstColumn<resize.last)
                    return;
    }
    this.resizeItemOnlyMeMode(resize);
}

Scheduler.prototype.resizeItemMoveNeighboursMode = function(resize) {
    if (!resize.linked)
        resize.linked = resize.Item.GetAllLinked(!resize.chgFirst);
        
    if ((this.behaviorOptions & SchedulerBehaviorOptions.AllowDraggingOutside)==0) {
        for (var i = resize.linked.length; --i>0;) {
            var it = resize.linked[i];
            if (it.firstColumn+resize.delta<0) return;
            if (it.lastColumn+resize.delta>=this.numberOfCols) return;
        }
    }

    if ((this.behaviorOptions & SchedulerBehaviorOptions.AllowOverlapItems)==0) {
        if (resize.Item.isOverlapped(resize.first, resize.last, resize.Item.row, resize.linked))
            return;

        for (var i = resize.linked.length; --i>0;) {
            var it = resize.linked[i];
            if (it.isOverlapped(
                it.firstColumn+resize.delta, it.lastColumn+resize.delta, it.row, resize.linked))
                    return;
        }
    }

    for (var i = resize.linked.length; --i>0;) {
        var it = resize.linked[i];
        it.MoveTo(it.firstColumn+resize.delta, it.lastColumn+resize.delta, it.row);
    }

    if (resize.chgFirst) 
        resize.Item.set_FirstColumn(resize.first);
    else
        resize.Item.set_LastColumn(resize.last);
}


/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

//
// SchedulerRegion
//

SchedulerRegion.prototype.get_Scheduler = function() {
    return this.scheduler;
}

SchedulerRegion.prototype.get_Index = function() {
    return this.index;
}

SchedulerRegion.prototype.get_FirstRow = function() {
    return this.firstRow;
}

SchedulerRegion.prototype.set_FirstRow = function(value) {
    if (this.firstRow==value) return;

    this.firstRow = value;
    this.Resync();
}

SchedulerRegion.prototype.get_LastRow = function() {
    return this.lastRow;
}

SchedulerRegion.prototype.set_LastRow = function(value) {
    if (this.lastRow==value) return;

    this.lastRow = value;
    this.Resync();
}

SchedulerRegion.prototype.get_FirstColumn = function() {
    return this.firstColumn;
}

SchedulerRegion.prototype.set_FirstColumn = function(value) {
    if (this.firstColumn==value) return;
    this.firstColumn = value;
    this.Resync();
}

SchedulerRegion.prototype.get_LastColumn = function() {
    return this.lastColumn;
}

SchedulerRegion.prototype.set_LastColumn = function(value) {
    if (this.lastColumn==value) return;
    this.lastColumn = value;
    this.Resync();
}

SchedulerRegion.prototype.get_DateBegin = function() {
    return new Date(this.dateBegin);
}

SchedulerRegion.prototype.set_DateBegin = function(value) {
    if (typeof(value)!="number") value = value.getTime();
    this.dateBegin = value;
    this.set_FirstColumn(this.scheduler.CalcColumnExact(value));
}

SchedulerRegion.prototype.get_DateEnd = function() {
    return new Date(this.dateEnd);
}

SchedulerRegion.prototype.set_DateEnd = function(value) {
    if (typeof(value)!="number") value = value.getTime();
    this.dateEnd = value;
    this.set_LastColumn(this.scheduler.CalcColumnExact(value));
}

SchedulerRegion.prototype.Init = function(index, scheduler) {
    this.scheduler = scheduler;
    this.index = index;
}

SchedulerRegion.prototype.Resync = function() {
    if (!this.scheduler.IsRenderingPossible()) return;
    
    var fIndex = 0;
    for (var r = this.firstRow; r!=null; r = r.parent) {
        if (r.visibleIndex>=0) {
            fIndex = r.visibleIndex;
            if (r!=this.firstRow) ++fIndex;
            break;
        }
    }
    
    var lIndex = this.scheduler.visibleRows.length-1;
    for (var r = this.lastRow; r!=null; r = r.parent) {
        if (r.visibleIndex>=0) {
            lIndex = r.visibleIndex;
            break;
        }
    }
    
    if (lIndex<fIndex || this.lastColumn<0 || this.firstColumn>=this.scheduler.numberOfCols || this.lastColumn<this.firstColumn) {
        if (this.div!=null) {
            this.scheduler.bodyDiv.removeChild(this.div);
            this.div = null;
        }
    }
    else {
        var divAdded = false;
        if (this.div==null) {
            this.div = document.createElement("DIV");
            divAdded = true;
            this.scheduler.defaultRegionStyle.InitElement(this.scheduler, this.div);
            this.style.InitElement(this.scheduler, this.div);
            this.div.style.position = "absolute";
            this.div.style.overflow = "hidden";
            this.div.style.zIndex = 8;
        }
        var l = go.GetPx(this.div.style.borderWidth);
        var x = this.scheduler.GetColX(this.firstColumn<0 ? 0 : this.firstColumn);
        var x2 = this.scheduler.GetColX(this.lastColumn>=this.scheduler.numberOfCols+0.2 ? this.scheduler.numberOfCols+0.2 : this.lastColumn, true);
        var y = this.scheduler.GetRowY(fIndex)-1;
        var h = this.scheduler.GetRowY(lIndex, true)-y-2*l;
        x = Math.floor(x);
        x2 = Math.floor(x2);

        if (this.lastColumn==Math.floor(this.lastColumn))
            x2 -= this.firstColumn<0 ? l : 2*l;
        if (x2<=x) x2 = x+1;
        
        if (go.IsIE8) --x2;

        this.div.style.left = x+"px";
        this.div.style.top = y+"px";
        this.div.style.width = (x2-x)+"px";
        this.div.style.height = h+"px";
        if (divAdded)
            this.scheduler.bodyDiv.appendChild(this.div);
    }
}

RegisterType("SchedulerRegion");

function SchedulerRegion() {
    this.div = null;
    return this;
}

