HJ.CalendarDashboard = Class.create();

HJ.CalendarDashboard.prototype = {


	initialize: function() {
		this.url = basePageURL + "CalendarOnlyDashboard.htm";
		this.targetContainerId = "MainArea";
		this.data = null;
	},
	
	cleanup:function() {
	    this.singOutLink = null;
	    this.inputBoxSubmit  = null;
	},

	
	init: function (svcName, svcMethod, UUID) {
		this.svcName = svcName;
		this.svcMethod = svcMethod;
		this.UUID = UUID;
		if(this.tl == null) {
			showModalMessageDialog("Initializing Dashboard ... please wait", 300, 40);
			this.tl = new Af.TemplateLoader(this.url, this.targetContainerId, "wrapper");
			this.tl.listener = this;
			this.tl.loadTemplate();
		} else {
			this.tl.reAttachElement();
		}
	},
	
	
	templateLoaded: function() {
	  
	   // Current code calls 3 initialize steps of HJ.App:
	   // Login.js calls initialize1(), Dashboard.templateLoaded calls initialize2(), and
	   // Dashboard.requestWorkspaceLoadCompleted() calls initialize3();
	   // Sed app.db as follows instead of invoking app.initialize1() which creates a 
	   // HJ.Dashboard instance and invokes its init() method
	   app.db = this;
	   app.initialize2(); 
	   app.initialize3();
	   
	   this.scribbleTitlePane = new Af.HtmlTitlePane2("scribbleTitlePane", "scribbleTitle", "openClose", "openClose", this);
	   this.scheduleTitlePane = new Af.HtmlTitlePane2("scheduleTitleInternalPane", "scheduleTitle", "openClose", "openClose", this);
	   this.myListsTitlePane = new Af.HtmlTitlePane2("myListsTable", "myListsTitle", "openClose", "openClose", this);
	   this.peopleTitlePane = new Af.HtmlTitlePane2("peopleTitlePane", "peopleTitle", "openClose", "openClose", this);
	   this.communityTitlePane = new Af.HtmlTitlePane2("communityTitlePane", "communityTitle", "openClose", "openClose", this);
	   this.myScheduleTitlePane = new Af.HtmlTitlePane2("scheduleTable", "myScheduleTitle", "boxLink open", "boxLink closed", this);
	   this.sharedScheduleTitlePane = new Af.HtmlTitlePane2("sharedScheduleTable", "sharedScheduleTitle", "boxLink open", "boxLink closed", this);
	   this.invitationTitlePane = new Af.HtmlTitlePane2("invitationTable", "invitationTitle", "boxLink open", "boxLink closed", this);

       this.communityResourcesTitle = document.getElementById("communityResourcesTitle");
	   this.mhmTitle = document.getElementById("MHMTitle");
	   this.myInfo = document.getElementById("myInfoLink");
	   this.planningTitle = document.getElementById("planningTitle");
	   this.communityCalendarTitle = document.getElementById("communityCalenderTitle"); 
 	   this.holidayTitle = document.getElementById("holidayTitle");
 	          
	   this.planningDiv = document.getElementById("planningDiv");
	   this.pageBottom = document.getElementById("pageBottom");
	   this.leftNavPlanningDiv = document.getElementById("leftNavPlanningDiv")
	   this.calenderTop = document.getElementById("calenderTop");
	   this.scribbles = document.getElementById("scribblePaneDiv");
	   this.calendarTabs = document.getElementById("tabsII");
	   this.topNav = document.getElementById("topNav2");

       this.loadWorkspace();	   
	},
	
	loadWorkspace: function() {
		
	   var req = new Af.DataRequest(svcURL,
			this.requestWorkspaceLoadCompleted.bind(this), this.requestFailedCommon.bind(this), null, this.requestTimedoutCommon.bind(this));
	   req.addService(this.svcName, this.svcMethod);
	   req.addParameter("UUID", this.UUID);
	   ajaxEngine.processRequest(req);
	  
	},
	
	
	requestWorkspaceLoadCompleted: function(response) {
	
	   //debugA(response.responseText);
	   var xds = new Af.XMLToDataSet(response.responseXML);
	   this.workspace = xds.data;
	   
	   app.workspace = this.workspace;
	   this.completeWorkspace(this.workspace);	   
	   app.schedule.setWorkspace(this.workspace);
	   this.tl.element.style.display = "";
	   
	   hideModalMessageDialog();
	   
	   this.leftNavPlanningDiv.style.display = "none";
	   this.leftNavPlanningDiv.style.width = 0;
	   this.communityResourcesTitle.style.display = "none";
	   this.mhmTitle.style.display = "none";
	   this.myInfo.style.display = "none";
	   this.planningTitle.style.display = "none";
	   this.communityCalendarTitle.style.display = "none";
	   this.holidayTitle.style.display = "none";
	   this.scribbles.style.display = "none";
	   this.calendarTabs.style.display = "none";
	   this.topNav.style.display = "none";
	},
	
	
	requestFailedCommon: function(dataRequest, msg) {
	    hideDialogWin();
	    showMessageDialog("We are currently unable to create this display. Please try again.", "Excuse us!", 350, 100);
    },

    requestTimedoutCommon: function() {
        hideDialogWin();
        showMessageDialog("We are currently unable to create this display. Please try again.", "Excuse us!", 350, 100);
    },
    
    paneStateChanged: function(pane) {
		var openCloseImg = document.getElementById(pane.titleId+"Img");		
		if(!pane.open) {			
				if(openCloseImg != null) {
					openCloseImg.src = "img/plus.gif";				
				}
		}else {
			if(openCloseImg != null) {
				openCloseImg.src = "img/minus.gif";				
			}
		}		
		return;
        if (this.scribbleTitlePane == null) {
           return false;
        }
	    this.updateScribbleState();
        this.updateAnnounceState();
        this.updateCalendarState();
		return false;
    },
    
    
    updateCalendarState: function() {
        var e = document.getElementById("scribbleTitleContaner");
        var e2 = document.getElementById("miniCalContaner");
        var e3 = document.getElementById("leftBar");
        if (this.scribbleTitlePane.open && this.miniCalTitlePane.open) {
           e2.className = "box miniCal"
           e.parentNode.insertBefore(e2, e3);
        } else {
           e2.className = "box soloCal";
           var e4 = document.getElementById("scheduleTitlePane");
           e3.insertBefore(e2, e4);
        }   
    },
    
	loadCommunityResourcesTemplate: function() {	
		
		this.planningDiv.style.display="none";
        this.pageBottom.style.display="inline";	  
		app.resource.loadCommunityResourcesTemplate();

		return false;
	},

	loadMHMTemplate: function() {
		
		this.planningDiv.style.display="none";
    	this.pageBottom.style.display="inline";
		app.question.loadQATemplate();

		return false;
	},

    loadMyInfoTemplate: function() {		
	    this.planningDiv.style.display="none";
	    this.pageBottom.style.display="inline";		
		app.myInfo.loadMyInfoTemplate();
		return false;
	},

	loadSeeingStarPubProfile: function(userUUID) {
	    this.planningDiv.style.display="none";
	    this.pageBottom.style.display="inline";
		app.memberProfile.loadMemberProfileTemplate(userUUID);
		return;
	},

  loadCalendarTemplate: function() {    
	  
	    app.schedule.monthlyCalendarSelected();
	    app.schedule.viewSelected(this);	 
		this.calenderTop.style.display = "block";
    
		this.planningDiv.style.display="inline";
	    this.pageBottom.style.display="none";				
		
		return false;
  },

	loadCommCalendarTemplate: function() {
	    app.communityCalendar.viewSelected(this);	  
    	this.calenderTop.style.display = "none";
	    this.planningDiv.style.display="inline";
		this.pageBottom.style.display="none";		
		
		return false;
	},


	loadAboutLinkTemplate:function(){
		app.about.loadAboutTemplate();
	},

	loadSeeingStarTemplate:function(){		
		app.seeingStar.loadSeeingStarTemplate();
		return false;
	},
	
	completeWorkspace: function(ws) {

	   if (ws["schedule"] == null) {
	      createOneToManyAssoc(ws, "schedule", "Schedule");
	   }
	   if (ws["sharedSchedule"] == null) {
	      createOneToManyAssoc(ws, "sharedSchedule", "Schedule");
	   }
	   if (ws["communitySchedule"] == null) {
	      createOneToManyAssoc(ws, "communitySchedule", "Schedule");
	   }
	   
	   // DailyCalendar view requires notes to be set
	   if (ws["notes"] == null) {
	      createOneToManyAssoc(ws, "notes", "Note");
	   }
	   

	   var schList = ws["schedule"];
	   
	   for (var i=0; i<schList.length; i++) {
	      var eventList = schList[i]["event"];
	      if (eventList == null) {
	         continue;
	      }
	      for (var j=0; j<eventList.length; j++) {
	         var e = eventList[j];
	         app.updateEventReferences(ws, e);
	      }
	   }
	   
	   this.drefAssociations(ws, "schedule", "myPeople", "people");
	   this.drefAssociations(ws, "schedule", "myPeople", "people2");
	   this.drefAssociations(ws, "schedule", "myGroup", "group");
	   this.drefAssociations(ws, "schedule", "myGroup", "group2");
	   
	},
	
	
	drefAssociations: function(ws, target, src, targetRel) {
	   l1 = ws[target];
	   l2 = ws[src];
	  
       
       for (var i=0; i<l1.length; i++) {
          var l3 = l1[i][targetRel];
          if (l3 == null) {
             continue;
          }
          var l = new Array();
		  l.__parent = l3.__parent; 
		  l.__className = l3.__className;
          
          for (j=0; j<l3.length; j++) {
             var idx = findObjIndex(l2, l3[j]);
             if (idx > -1) {
                l.push(l2[idx]);
             }
          }
           l1[i][targetRel] = l;
       }

	},

	doShowHelp:function(){
		if(this.hp == null){
			this.hp = new HJ.Hompage();
		}
		this.hp.loadHelpTemplate();		
	},	

	doShowFeedBack:function(){
		if(this.hp == null){
			this.hp = new HJ.Hompage();
		}
		this.hp.loadFeedBackTemplate();		
	}

}

function seqComparator(o1, o2) {
   var s1 = parseInt(o1["seq"]);
   var s2 = parseInt(o2["seq"]);
   return s1 - s2;
}

//  GLOBAL VARIALBLE TO SHOW AND HIDE CALENDAR'S HEADER 
var calenderTop;

