﻿// JScript File

Type.registerNamespace('Intrafinity.Web.Controls');

Intrafinity.Web.Controls.ServerCalendarPicker = function(element){
    Intrafinity.Web.Controls.ServerCalendarPicker.initializeBase(this, [element]);
    this._serverId = null;
    this._serverName = null; 
    this._workspaceParentId = null;
    this._lmsParentId = null; 
    this._workspaceRootId = null;
    this._eregRootId = null; 
    this._lmsRootId = null;   
    this._isCollapse = null;
    this._isCmsDataLoaded = null;
    this._isWorkspaceDataLoaded = null;
    this._isLmsDataLoaded = null;  
    this._tvCms = null;    
    this._tblContent = null; 
    this._imgUrlCollapse = null;
    this._imgUrlExpand = null;  
    this._iconCollapse = null; 
    this._imgUrlCalendar = null;
    this._imgUrlPortal = null;
    this._imgUrlPage = null;   
    this._imgUrlDelete = null; 
    this._category = null; 
    this._selectedCalendarList = null; 
    this._isPostBack = null; 
    this._hfSelectedCalendarList = null;
    this._tdRight = null;
    this._lblServerName = null;  
    this._tab = null;    
    this._rgWorkspaceItems = null;
    this._rgLmsItems = null;    
    this._loadingPanel = null;      
    this._divNavLms = null; 
    this._divNavWorkspace = null;
    this._showWorkspace = null;
    this._showLms = null;  
    this._showEreg = null; 
    this._cbEregCalendar = null; 
}

Intrafinity.Web.Controls.ServerCalendarPicker.prototype = {
   Reset : function(si){
        this._serverId = si.ServerId;
        this._serverName = si.ServerName;
        this._workspaceRootId = si.WorkspaceRootId;
        this._workspaceParentId = si.WorkspaceRootId;
        this._lmsRootId = si.LmsRootId;
        this._lmsParentId = si.LmsRootId;
        this._showWorkspace = si.WorkspaceEnabled;
        this._showLms = si.LmsEnabled;
        this._showereg = si.EregEnabled;
        this._eregRootId = si.EregRootId;
        this.set_isCmsDataLoaded(false);
        this.set_isWorkspaceDataLoaded(false);
        this.set_isLmsDataLoaded(false);
        this.set_isCollapse(true);        
        this.get_tab().get_tabs().getTab(1).set_visible(this._showWorkspace);
        this.get_tab().get_tabs().getTab(2).set_visible(this._showLms);
        this.get_tab().get_tabs().getTab(3).set_visible(this._showEreg);
        
   },
    
   get_serverId : function(){
        return this._serverId;
   },
   set_serverId : function(value){
        if(value!=this._serverId){
            this._serverId = value;
            this.raisePropertyChanged("serverId");
        }
   },
   
   get_serverName : function(){
        return this._serverName;
   },
   set_serverName : function(value){
        if(value!=this._serverName){
            this._serverName = value;
            this.raisePropertyChanged("serverName");
        }    
   },
   
   get_showWorkspace : function(){
        return this._showWorkspace;
   },
   set_showWorkspace : function(value){
        if(value!=this._showWorkspace){
            this._showWorkspace = value;
            this.raisePropertyChanged("showWorkspace");
        }
   },
   
   get_showLms : function(){
        return this._showLms;
   },   
   set_showLms : function(value){   
        if(value!=this._showLms){
            this._showLms = value;
            this.raisePropertyChanged("showLms");
        }
   },
   
   get_lblServerName : function(){
        return this._lblServerName;
   },
   set_lblServerName : function(value){
        if(value!=this._lblServerName){
            this._lblServerName = value;
            this.raisePropertyChanged("lblServerName");
        }
   },
   
   get_lmsParentId : function(){
        return this._lmsParentId;
   },
   set_lmsParentId : function(value){
        this._lmsParentId = value;
   },
    
  get_workspaceParentId : function(){
        return this._workspaceParentId;
  },  
  set_workspaceParentId : function(value){
    this._workspaceParentId = value;
  },
  
  get_workspaceRootId : function(){
        return this._workspaceRootId;
  },
  set_workspaceRootId : function(value){
        this._workspaceRootId = value;
  },
  
  get_lmsRootId : function(){
        return this._lmsRootId;
  },
  set_lmsRootId : function(value){
        this._lmsRootId = value;
  },
  
   get_isCollapse : function(){
        return this._isCollapase;
   },
   set_isCollapse : function(value){
        if(value!=this._isCollapase){
            this._isCollapse = value;
            this.raisePropertyChanged("isCollapse");
        }
   },
   
   get_isCmsDataLoaded : function(){
        return this._isCmsDataLoaded;
   },
   set_isCmsDataLoaded : function(value){
        if(value!=this._isCmsDataLoaded){
            this._isCmsDataLoaded = value;
            this.raisePropertyChanged("isCmsDataLoaded");
        }
   },
   
   get_isWorkspaceDataLoaded : function(){
        return this._isWorkspaceDataLoaded;
   },
   set_isWorkspaceDataLoaded : function(value){
        if(value!=this._isWorkspaceDataLoaded){
            this._isWorkspaceDataLoaded = value;
            this.raisePropertyChanged("isWorkspaceDataLoaded");
        }
   },
   
   get_isLmsDataLoaded : function(){
        return this._isLmsDataLoaded;
   },
   set_isLmsDataLoaded : function(value){
        if(value!=this._isLmsDataLoaded){
            this._isLmsDataLoaded = value;
            this.raisePropertyChanged("isLmsDataLoaded");
        }
   },
   
   get_tblContent : function(){
        return this._tblContent;
   },
   set_tblContent : function(value){
        if(value!=this._tblContent){
            this._tblContent = value;
            this.raisePropertyChanged("tblContent");
        }
   },
   
   get_tvCms : function(){
        return this._tvCms;
   },
   set_tvCms : function(value){
        if(value!=this._tvCms){
            this._tvCms = value;
            this.raisePropertyChanged("tvCms");
        }
   },
   
   get_imgUrlCollapse : function(){
        return this._imgUrlCollapse;
   },
   set_imgUrlCollapse : function(value){
        if(value!=this._imgUrlCollapse){
            this._imgUrlCollapse = value;
            this.raisePropertyChanged("imgUrlCollapse");
        }
   },
   
   get_imgUrlExpand : function(){
        return this._imgUrlExpand;
   },
   set_imgUrlExpand : function(value){
        if(value!=this._imgUrlExpand){
            this._imgUrlExpand = value;
            this.raisePropertyChanged("imgUrlExpand");
        }
   },
   
   get_imgUrlCalendar : function(){
        return this._imgUrlCalendar;
   },
   set_imgUrlCalendar : function(value){
        this._imgUrlCalendar = value;
   },
   
   get_imgUrlPage : function(){
        return this._imgUrlPage;
   },
   set_imgUrlPage : function(value){
        this._imgUrlPage = value;
   },
   
   get_imgUrlPortal : function(){
        return this._imgUrlPortal;
   },
   set_imgUrlPortal : function(value){
        this._imgUrlPortal = value;
   },
   
   get_imgUrlDelete : function(){
        return this._imgUrlDelete;
   },
   set_imgUrlDelete : function(value){
        this._imgUrlDelete = value;
   },
   
   get_iconCollapse : function(){
        return this._iconCollapse;
   },
   set_iconCollapse :function(value){
        if(value!=this._iconCollapse){
            this._iconCollapse = value;
            this.raisePropertyChanged("iconCollapse");
        }
   },
   
   get_category : function(){
        return this._category;
   },
   set_category : function(value){
        if(value!=this._category){
            this._category = value;
            this.raisePropertyChanged("category");
        }
   },
   
   get_selectedCalendarList : function(){
        return this._selectedCalendarList;
   },
   set_selectedCalendarList : function(value){
        if(value!=this._selectedCalendarList){
            this._selectedCalendarList = value;
        }
   },
   
   get_isPostBack : function(){
        return this._isPostBack;
   },
   set_isPostBack : function(value){
        if(value!=this._isPostBack){
            this._isPostBack = value;
            this.raisePropertyChanged("isPostBack");
        }
   },
   
   get_hfSelectedCalendarList : function(){
        return this._hfSelectedCalendarList;
   },
   set_hfSelectedCalendarList : function(value){
        if(value!=this._hfSelectedCalendarList){
            this._hfSelectedCalendarList= value;
            this.raisePropertyChanged("hfSelectedCalendarList");
        }
   },
   
   get_tdRight : function(){
        return this._tdRight;
   },
   set_tdRight : function(value){
        if(value!=this._tdRight){
            this._tdRight = value;
        }
   },
   
   get_rcbCategory : function(){
        return this._rcbCategory;
   },
   set_rcbCategory : function(value){
        this._rcbCategory = value;
   },   

   
   get_tab : function(){
        return this._tab;
   },
   set_tab : function(value){
        this._tab = value;
   },
   
   get_rgWorkspaceItems : function(){
        return this._rgWorkspaceItems;
   },
   set_rgWorkspaceItems : function(value){
        if(value!=this._rgWorkspaceItems){
            this._rgWorkspaceItems = value;
            this.raisePropertyChanged("rgWorkspaceItems");
        }    
   },
   
   get_rgLmsItems : function(){
        return this._rgLmsItems;
   },
   set_rgLmsItems : function(value){
        this._rgLmsItems = value;
   },
   
   get_loadingPanel : function(){
        return this._loadingPanel;
   },
   set_loadingPanel : function(value){
        if(value!=this._loadingPanel){
            this._loadingPanel = value;
            this.raisePropertyChanged("loadingPanel");
        }
   },
   
   get_divNavWorkspace : function(){
        return this._divNavWorkspace;
   },
   set_divNavWorkspace : function(value){
        if(value!=this._divNavWorkspace){
            this._divNavWorkspace = value;
            this.raisePropertyChanged("divNavWorkspace");
        }    
   },
   
   get_divNavLms : function(){
        return this._divNavLms;
   },
   set_divNavLms : function(value){
        this._divNavLms = value;
   },
   
   get_showEreg : function(){
        return this._showEreg;
   },
   set_showEreg : function(value){
        this._showEreg = value;
   },
   
   get_cbEregCalendar : function(){
        return this._cbEregCalendar;   
   },
   set_cbEregCalendar : function(value){
        this._cbEregCalendar = value;
   },
   
   get_eregRootId : function(){
        return this._eregRootId;
   },
   set_eregRootId : function(value){
        this._eregRootId = value;
   },
   
   /// events
   add_onTreeNodeChecked : function(handler){
        this.get_events().addHandler("onTreeNodeChecked", handler);
   },
   remove_onTreeNodeChecked : function(handler){
        this.get_events().removeHandler("onTreeNodeChecked", handler);
   },
   
   add_refreshSelectedCalendar : function(handler){
        this.get_events().addHandler ("refreshSelectedCalendar", handler);        
   },
   remove_refreshSelectedCalendar : function(handler){
        this.get_events().removeHandler("refreshSelectedCalendar", handler);
   },
   
   loadData : function(){
        if(this._category =="cms"){        
            this.set_isCmsDataLoaded(true);
            this._loadingPanel.show(this._tvCms.get_id());
            Intrafinity.Web.Services.CalendarPickerWS.GetCalendarPageList(this._serverId, Function.createDelegate(this, this._callBackSucceed), Function.createDelegate(this, this._callBackFail));
        }
        else if(this._category == "workspace"){        
            this.set_isWorkspaceDataLoaded(true);
            var tbl = this.get_rgWorkspaceItems().get_masterTableView();
            var pageSize = tbl.get_pageSize();
            var pageIndex = tbl.get_currentPageIndex();
            this._loadingPanel.show(this.get_id());
            Intrafinity.Web.Services.CalendarPickerWS.GetCalendarRelatedItemList(this._workspaceParentId, this._category, pageIndex, pageSize, Function.createDelegate(this, this._callBackSucceed), Function.createDelegate(this, this._callBackFail));
            if(this._workspaceParentId != this._workspaceRootId){
                Intrafinity.Web.Services.CalendarPickerWS.GetNavItemList(this._workspaceRootId, this._workspaceParentId, Function.createDelegate(this, this._callBackSucceed), Function.createDelegate(this, this._callBackFail));
                //this._divNavWorkspace.style.display = "";
            }    
            else
                this._divNavWorkspace.style.display = "none";
        }   
        else if(this._category == "lms"){
            this.set_isLmsDataLoaded(true);
            var tbl = this.get_rgLmsItems().get_masterTableView();
            var pageSize = tbl.get_pageSize();
            var pageIndex = tbl.get_currentPageIndex();
            this._loadingPanel.show(this.get_id());
            Intrafinity.Web.Services.CalendarPickerWS.GetCalendarRelatedItemList(this._lmsParentId, this._category, pageIndex, pageSize, Function.createDelegate(this, this._callBackSucceed), Function.createDelegate(this, this._callBackFail));
            if(this._lmsParentId != this._lmsRootId)
                Intrafinity.Web.Services.CalendarPickerWS.GetNavItemList(this._lmsRootId, this._lmsParentId, Function.createDelegate(this, this._callBackSucceed), Function.createDelegate(this, this._callBackFail));
            else
                this._divNavLms.style.display = "none"; 
        }
        //alert(String.format("{0} {1} {2} {3}",this._serverId, this._serverName, this._workspaceRootId, this._lmsRootId));
   },
   
   folder_click : function(e, itemId){
        if(this._category == "workspace"){
            this.set_workspaceParentId(itemId);
            this.loadData();
        }    
        else if(this._category == "lms"){
            this.set_lmsParentId(itemId);
            this.loadData();
        }    
   },
   
   checkbox_click : function(e, cal){
        //alert(Sys.Serialization.JavaScriptSerializer.serialize(cal));
        var isSelected = e.target.checked;
        if(isSelected){
            this.selectCalendar(cal.CalendarId, cal.DisplayName, cal.Category);
        }
        else{
            this.unselectCalendar(cal.CalendarId, cal.Category);
        }
        this.refreshSelectedCalendar();
   },
   
   bindNav : function(data){
    if(data.length > 0){
            var div = null;
            if(this._category=="workspace")
                div = this.get_divNavWorkspace();
            else if(this._category == "lms")
                div = this._divNavLms;

            if(div){
                div.innerHTML = "";
                div.style.display = "";
                var t = data.length;
                
                for(var i=0; i<t-1; i++){
                    var pair = data[i];
                    var hl = $Utility.createHyperLink(pair.Value);
                    hl.style.color = "#000000";
                    $addHandler(hl, "click", Function.createCallback(Function.createDelegate(this, this.folder_click), pair.Key)); 
                    div.appendChild(hl);
                    div.appendChild(document.createTextNode(" > "));                   
                }
                div.appendChild(document.createTextNode(" " + data[t-1].Value));
            }
        }
   },
   
   bindGrid : function(data, totalCount){       
        var tableView = null;
        if(this._category == "workspace")
            tableView = this.get_rgWorkspaceItems().get_masterTableView();
        else if(this._category == "lms")
            tableView = this.get_rgLmsItems().get_masterTableView();
            
        tableView.set_dataSource(data);
        tableView.set_virtualItemCount(totalCount);
        tableView.dataBind();
        tableView.clearSelectedItems();        
        
        this._loadingPanel.hide(this.get_id());        
   },
   
   rg_RowDataBound : function(sender, args){
        var ci = args.get_dataItem();
        var ri = args.get_item();
        
        /// find control
        var imgIcon = ri.findElement("imgIcon"); 
        var hlName = ri.findElement("hlName"); 
        var cbSelected = ri.findElement("cbSelected");
        if(hlName){
            hlName.innerHTML = ci.Name ;
            hlName.style.display = "";
            $clearHandlers(hlName);            
            if(ci.ObjectType != "workspace_calendar"){
                $addHandler(hlName, "click", Function.createCallback(Function.createDelegate(this, this.folder_click), ci.ItemId));                
                cbSelected.style.display = "none"; 
            }
            else{
                //$addHander(hlName, "click", Function.createCallback(Function.createDelegate(this, this.selectCalendar), {ci.ItemId, ci.Name, this._category}));
                cbSelected.style.display = "";
                cbSelected.checked = this.isInSelectedList(ci.ItemId);                
                var cal = new Intrafinity.Web.Classes.ClientCalendar();
                cal.CalendarId = ci.ItemId;
                cal.DisplayName = ci.Name;
                cal.Category = this._category;    
                cal.ServerName = this._serverName; 
                $clearHandlers(cbSelected); 
                $addHandler(cbSelected, "click",  Function.createCallback(Function.createDelegate(this, this.checkbox_click), cal));
            }    
//            else if(ci.ObjectType == "content_item"){
//                $addHandler(hlName, "click", Function.createCallback(Function.createDelegate(this, this.file_click), ci.ItemId));                                                               
//            }            
//            else{
//                $addHandler(hlName, "click", Function.createCallback(Function.createDelegate(this, this.item_click), ci.ItemId));                                                
//            }
        }    
        if(imgIcon){
            imgIcon.src = ci.Icon;
            imgIcon.style.display = "";
        }    
   },
   
   rg_Command : function(sender, args){
         args.set_cancel(true);                
        if(args.get_commandName()=="Page" ){
               this.loadData();
        }    
   },
   
   bindCmsTree : function(data){
      var tv = this.get_tvCms();
      tv.trackChanges();
      tv.get_nodes().clear();
      for(var i=0,t=data.length;i<t;i++){
          var dataNode = data[i];  
          var rNode = this.createRadNode(dataNode);
          tv.get_nodes().add(rNode);
      }
      tv.commitChanges();    
      this._loadingPanel.hide(this._tvCms.get_id());
   },
   
   createRadNode : function(dataNode){
        var radNode = new Telerik.Web.UI.RadTreeNode();
        radNode.set_text(dataNode.Name);
        radNode.set_value(dataNode.CalendarId.toString());
        
        if(dataNode.CalendarId > 0 && this.isInSelectedList(dataNode.CalendarId))
            radNode.set_checked(true);
        
        if(dataNode.ObjectType=="ptl_portal"){
            radNode.set_imageUrl(this._imgUrlPortal);
            radNode.set_checkable(false);
        }
        else if(dataNode.CalendarId==0)
            radNode.set_imageUrl(this._imgUrlPage);
        else
            radNode.set_imageUrl(this._imgUrlCalendar);
        if(dataNode.ChildNodes && dataNode.ChildNodes.length>0){
            for(var i=0,t=dataNode.ChildNodes.length;i<t;i++){
                var radChildNode = this.createRadNode(dataNode.ChildNodes[i]);
                radNode.get_nodes().add(radChildNode); 
            }
        }     
        return radNode;
   },
   
   isInSelectedList : function(calendarId){
        if(!this._selectedCalendarList)
            return false;
        else{
            for(var i=0,t=this._selectedCalendarList.length;i<t;i++){
                if(this._selectedCalendarList[i].CalendarId==calendarId){
                    return true;
                }               
            }
            return false; 
        }
   },
   
   getSelectedIndex : function(calendarId){
        if(!this._selectedCalendarList)
            return -1;
        else{
            for(var i=0,t=this._selectedCalendarList.length;i<t;i++){
                if(this._selectedCalendarList[i].CalendarId==calendarId){
                    return i;
                }               
            }
            return -1; 
        }
   },
   
   selectCalendar : function(calId, label, category){
        if(!this.isInSelectedList(calId)){
            if(!this._selectedCalendarList)
                this._selectedCalendarList = new Array();
            var cal = new Intrafinity.Web.Classes.ClientCalendar();
            cal.ServerId = this._serverId;
            cal.CalendarId = calId;            
            cal.DisplayName = label;
            cal.Category = category;
            cal.ServerName = this._serverName;
            this._selectedCalendarList.push(cal);
        }
   },
   
   unselectCalendar : function(calId, category){
        var index = this.getSelectedIndex(calId);
        if(index>=0)
            this._selectedCalendarList.splice(index, 1);
            
        if(category == "cms"){            
            var node = this._tvCms.findNodeByValue(calId.toString())
            if(node)
                node.set_checked(false);
        }
        else if(category == "ereg")
            this._cbEregCalendar.checked = false;
        else{
            var tableView = null;
            if(category == "workspace")
                tableView = this.get_rgWorkspaceItems().get_masterTableView();
            else if(category == "lms")
                tableView = this.get_rgLmsItems().get_masterTableView();
            var items = tableView.get_dataItems();
            for(var i=0,t=items.length;i<t;i++){
                 var item = items[i];
                 var data = item.get_dataItem();
                 if(item && data.ItemId == calId){
                    var cb = item.findElement("cbSelected");
                    if(cb){
                        cb.checked = false;
                        break;
                    }
                 }
            }                
        }            
   },
   
   /// This method is used to the hidden field (this._hfSelectedCalendarList), from which the server side can get the updated value
   refreshSelectedCalendar : function(){        
        this._hfSelectedCalendarList.value = Sys.Serialization.JavaScriptSerializer.serialize(this._selectedCalendarList);
        
        /// invoke handle
        var h = this.get_events().getHandler("refreshSelectedCalendar");
        if(h)
             h(this, this._selectedCalendarList);
            
        /// display selected on the right part
        this._tdRight.innerHTML = "";
        var sl = this._selectedCalendarList;
        if(sl && sl.length>0){
            var tbl = $Utility.createTable(this._tdRight);
            tbl.className ="tbl";
            var row = $Utility.createRow(tbl);
            row.className = "tbl_header";
            var cell = $Utility.createCell(row);
            cell  = $Utility.createCell(row);
            cell.innerHTML = "Calendar Name";
            cell = $Utility.createCell(row);
            cell.innerHTML = "Category";
            cell = $Utility.createCell(row);
            cell.innerHTML = "Action";
            
            for(var i=0,t=sl.length;i<t;i++){
                var cal = sl[i];
                row = $Utility.createRow(tbl);
                cell = $Utility.createCell(row);
                var img = $Utility.createImage("img_sl_calendar_" + cal.CalendarId, this._imgUrlCalendar); 
                cell.appendChild(img); 
                
                cell = $Utility.createCell(row);
                cell.innerHTML= cal.DisplayName;
               
                cell = $Utility.createCell(row);
                cell.innerHTML = cal.Category;
               
                cell = $Utility.createCell(row);
                cell.style.textAlign="center"; 
                var img = $Utility.createImage("img_sl_calendar_del_"+cal.CalendarId, this._imgUrlDelete);
                img.style.cursor = "pointer"; 
                $addHandler(img, "click", Function.createCallback(Function.createDelegate(this, this._imgUnselectedClick), cal)); 
                cell.appendChild(img);
            }
        }
        else{
            this._tdRight.style.textAlign = "center";
            this._tdRight.style.fontSize = "12px";
            this._tdRight.innerHTML = "No calendar selected."
        }         
   },
    
   propertyChanged : function(sender, args){
        var propertyName = args.get_propertyName();
        if(propertyName == "isCollapse"){            
            this._iconCollapse.src = this._isCollapse ? this._imgUrlCollapse : this._imgUrlExpand;
            this._tblContent.style.display = this._isCollapse ? "none" : "";
            if((!this._isCollapse && !this._isCmsDataLoaded) && ((!this._isPostBack)||(this._isPostBack && this._tvCms.get_nodes().get_count()==0)))
                this.loadData();
            else if(!this._isCollapse && this._isPostBack && this._category !="cms")
                this.loadData(); 
            //alert(this._category);    
        }
        else if(propertyName == "category"){
            if((this._category == "workspace" && !this._isWorkspaceDataLoaded) ||(this._category=="lms" && !this._isLmsDataLoaded))
                this.loadData();
        }
   },
   
   
   iconCollapse_click : function(e){
        this.set_isCollapse(!this._isCollapse);        
   },
   
   _callBackSucceed : function(result, context, methodName){
        if(methodName == "GetCalendarPageList"){
            if(result.IsSuccessful){
                this.bindCmsTree(result.Result);                
            }
            else
                alert(result.Message);
                
        }
        else if(methodName == "GetCalendarRelatedItemList"){
            if(result.IsSuccessful){
                this.bindGrid(result.Result, result.TotalCount);               
            }
            else
                alert(result.Message);
        }
        else if(methodName == "GetNavItemList"){
            if(result.IsSuccessful){
                this.bindNav(result.Result);
            }
            else{
                alert(result.Message);
            }
        }
   },
   
   _callBackFail : function(error){
   
   },
   
   
   ///event
   
   _imgUnselectedClick : function(e, cal){
        this.unselectCalendar(cal.CalendarId, cal.Category);
        this.refreshSelectedCalendar();
   },
   
   tvCmsNodeChecked : function(sender, args){
        this.set_checkedAll(args.get_node());
        this.refreshSelectedCalendar();
        
        var h = this.get_events().getHandler("onTreeNodeChecked");
        if(h)
            h(this, args);
   },
   
   tabSelecting : function(object, args){
        var tab = args.get_tab();
        this.set_category(tab.get_value());
   },
   
   set_checkedAll : function(node){
        var checked = node.get_checked();
        var calId = parseInt(node.get_value());
        if(calId > 0){
            if(checked)
                this.selectCalendar(calId, node.get_text(), "cms");
            else{
                this.unselectCalendar(calId, "cms");  
            }    
        }
                
        if(checked)
            node.expand();
        for(var i=0,t=node.get_nodes().get_count();i<t;i++){                
            var childNode = node.get_nodes().getNode(i);
            childNode.set_checked(checked);          
            this.set_checkedAll(childNode);                        
        }
        
   },
   
    
   initialize : function(){
        Intrafinity.Web.Controls.ServerCalendarPicker.callBaseMethod(this, "initialize");        
        $addHandler(this.get_iconCollapse(), "click", Function.createDelegate(this, this.iconCollapse_click));
        $addHandler(this.get_lblServerName(), "click", Function.createDelegate(this, this.iconCollapse_click));        
        this.get_tvCms().add_nodeChecked(Function.createDelegate(this, this.tvCmsNodeChecked));        
        this.add_propertyChanged(Function.createDelegate(this, this.propertyChanged)); 
        this.get_tab().add_tabSelecting(Function.createDelegate(this, this.tabSelecting));       
        this.get_rgWorkspaceItems().add_rowDataBound( Function.createDelegate(this, this.rg_RowDataBound));
        this.get_rgWorkspaceItems().add_command(Function.createDelegate(this, this.rg_Command));              
        this.get_rgLmsItems().add_rowDataBound( Function.createDelegate(this, this.rg_RowDataBound));
        this.get_rgLmsItems().add_command(Function.createDelegate(this, this.rg_Command));
        this.get_tab().get_tabs().getTab(1).set_visible(this._showWorkspace);
        this.get_tab().get_tabs().getTab(2).set_visible(this._showLms);
        this.get_tab().get_tabs().getTab(3).set_visible(this._showEreg);
        
        if(this._showEreg){
            var eregCal = new Intrafinity.Web.Classes.ClientCalendar();
            eregCal.ServerId = this._serverId;
            eregCal.CalendarId = this._eregRootId
            eregCal.EmbedPageId = 0;
            eregCal.DisplayName = 'Event Registration Calendar';
            eregCal.Category =  'ereg';
            $addHandler(this._cbEregCalendar, "click", Function.createCallback(Function.createDelegate(this, this.checkbox_click), eregCal));
        }    
        this.refreshSelectedCalendar();        
   },
   
   dispose : function(){
        Intrafinity.Web.Controls.ServerCalendarPicker.callBaseMethod(this, "dispose");
   } 

}

Intrafinity.Web.Controls.ServerCalendarPicker.registerClass("Intrafinity.Web.Controls.ServerCalendarPicker", Sys.UI.Control);

