function EventChartController(defaultView,defaultSpan,defaultEventType){
	this.defaultView=defaultView
	this.defaultSpan=defaultSpan
	this.defaultEventType=defaultEventType
	
	var barGraph=document.getElementById('barGraph')
	
	this.restore=function restore(){
		restoreMain('restore')
	}
	
	this.main=function main(){
	    setViewMenu(this.defaultView)
	    setSpanMenu(this.defaultSpan)
		restoreMain('main')
	}
	
	this.setView=function setView(viewType){
		if(viewType==undefined){
			viewType=defaultViewType
		}
		if(barGraph!=null){
			setViewMenu(viewType)
			setViewButton(viewType)
			if(!(viewType==0 || viewType==1)){
				setSpanMenu()
			}
		}
		redirect('view',viewType)
	}
	
	this.setMonthSpan=function setMonthSpan(monthSpan){
		if(monthSpan==undefined){
			monthSpan=defaultSpan
		}
		if(barGraph!=null){
			setSpanMenu(monthSpan)
		}
		redirect('monthspan',monthSpan)		
	}

	this.setGroupByType=function setGroupByType(groupByType, typeCaption){
		setGroupByTypeMenu(groupByType, typeCaption)
		redirect('groupbytype',(groupByType==true) ? "1" : "0")
	}
	
	this.monthZoom=function monthZoom(year,month){
		if(year==undefined || month==undefined){
			var today=new Date()
			year=today.getFullYear()
			month=today.getMonth+1
		}
		setSpanMenu(0,parent.document)
		var parameter=month + '/1/' + year
		var url=redirectUrl('zoom',parameter) + '&IFrame=1'
		document.location=url
	}

	this.filter=function filter(eventType){
		if(eventType==undefined){
			eventType=defaultEventType
		}
		redirect('filter',eventType)
	}

	this.moveNext=function moveNext(){
		redirect('forward')
	}
	
	this.movePrevious=function movePrevious(){
		redirect('back')
	}

	this.subPlanner=function subPlanner(parentId,inChart){
		if(inChart){
			parent.document.location=redirectUrl('subplanner',parentId) + '&IFrame=1'
		}
		else{
			redirect('subplanner',parentId)
		}
	}

	this.upOneLevel = function upOneLevel() {
		var doc;
		var command = "uponelevel";
		
		if(barGraph != null) {
			doc = parent.document;
		} else {
			doc = document;
		}	

		doc.location = redirectUrl(command);
	}

	function restoreMain(command) {
		if(barGraph != null) {
			parent.document.location=redirectUrl(command);
		} else {
			Nav.GoTo(redirectUrl(command));
		}
	}

	
	function redirect(command, parameter) {
		var url=redirectUrl(command,parameter)
		if(barGraph == null) {
			Nav.GoTo(url);
		} else {
			barGraph.src = url + "&IFrame=1";
		}
	}
		
	function setViewMenu(viewType){
		switch(viewType){
			case '0',0: 
				document.getElementById('mnuViewConsolidated').innerHTML='Consolidated View &radic;';
				document.getElementById('mnuViewChronological').innerHTML='Chronological View';
				document.getElementById('mnuViewCalendar').innerHTML='Calendar View';
				//document.getElementById('mnuViewReport').innerHTML='List View';
				break;
			case '1',1: 
				document.getElementById('mnuViewConsolidated').innerHTML='Consolidated View';
				document.getElementById('mnuViewChronological').innerHTML='Chronological View &radic;';
				document.getElementById('mnuViewCalendar').innerHTML='Calendar View';
				//document.getElementById('mnuViewReport').innerHTML='List View';								
				break;
			case '5',5:
				document.getElementById('mnuViewConsolidated').innerHTML='Consolidated View';
				document.getElementById('mnuViewChronological').innerHTML='Chronological View';
				document.getElementById('mnuViewCalendar').innerHTML='Calendar View &radic;';
				//document.getElementById('mnuViewReport').innerHTML='List View';								
				break;
			//case '2': 
				//document.getElementById('mnuViewChronological').innerHTML='Chronological View';
				//document.getElementById('mnuViewConsolidated').innerHTML='Consolidated View';
				//document.getElementById('mnuViewReport').innerHTML='List View &radic;';
				//break;
			default:
				document.getElementById('mnuViewChronological').innerHTML='Chronological View';
				document.getElementById('mnuViewConsolidated').innerHTML='Consolidated View';
				//document.getElementById('mnuViewReport').innerHTML='List View';
		}
	}

	function setGroupByTypeMenu(groupByType, typeCaption){
		if(groupByType){
			document.getElementById('mnuGroupNone').innerHTML='No Grouping';
			document.getElementById('mnuGroupByType').innerHTML='Group By ' + typeCaption + ' &radic;';
		} else {
			document.getElementById('mnuGroupNone').innerHTML='No Grouping &radic;';
			document.getElementById('mnuGroupByType').innerHTML='Group By ' + typeCaption;
		}
	}

	this.setButton=setViewButton
	
	function setViewButton(viewType){
		if(!document.getElementById('viewPanel'))
			return;

		// if this is the calendar view or the event list, hide the view options panel
		if(viewType == 5 || viewType == 3) {
			document.getElementById('viewPanel').style.visibility = "hidden";
			return;
		} else {
			document.getElementById('viewPanel').style.visibility = "visible";
		}
		if(!viewType){
			viewType=-1
		}
		viewType=new Number(viewType)
		document.getElementById('imgViewButton00').style.display=((viewType==0)? 'inline':'none')
		document.getElementById('imgViewButton01').style.display=((viewType==1)? 'inline':'none')
		document.getElementById('imgViewButton0').style.display=((viewType==-1)? 'inline':'none')
		document.getElementById('imgViewButton10').style.display=((viewType==0)? 'inline':'none')
		document.getElementById('imgViewButton11').style.display=((viewType==1)? 'inline':'none')
		document.getElementById('imgViewButton1').style.display=((viewType==-1)? 'inline':'none')
	}

	function setSpanMenu(spanType,doc){
		if(doc==undefined){
			doc=document
		}
		switch(spanType){
			case 6:
				doc.getElementById('mnu6Month').innerHTML='6 Month Span &radic;';
				doc.getElementById('mnu12Month').innerHTML='12 Month Span';
				doc.getElementById('mnu18Month').innerHTML='18 Month Span';
				doc.getElementById('mnu24Month').innerHTML='24 Month Span';				
				break;
			case 12:
				doc.getElementById('mnu6Month').innerHTML='6 Month Span';
				doc.getElementById('mnu12Month').innerHTML='12 Month Span &radic;';
				doc.getElementById('mnu18Month').innerHTML='18 Month Span';
				doc.getElementById('mnu24Month').innerHTML='24 Month Span';				
				break;
			case 18:
				doc.getElementById('mnu6Month').innerHTML='6 Month Span';
				doc.getElementById('mnu12Month').innerHTML='12 Month Span';
				doc.getElementById('mnu18Month').innerHTML='18 Month Span &radic;';
				doc.getElementById('mnu24Month').innerHTML='24 Month Span';			
				break;
			case 24:
				doc.getElementById('mnu6Month').innerHTML='6 Month Span';
				doc.getElementById('mnu12Month').innerHTML='12 Month Span';
				doc.getElementById('mnu18Month').innerHTML='18 Month Span';
				doc.getElementById('mnu24Month').innerHTML='24 Month Span &radic;';				
				break;
			default:
				doc.getElementById('mnu6Month').innerHTML='6 Month Span';
				doc.getElementById('mnu12Month').innerHTML='12 Month Span';
				doc.getElementById('mnu18Month').innerHTML='18 Month Span';
				doc.getElementById('mnu24Month').innerHTML='24 Month Span';	
		}
	}
	
	function redirectUrl(command,parameter){
		var url='ChartPersist.asp?Command=' + command
		if(parameter!=null){
			url+='&Parameter=' + parameter
		}
		return url
	}	
}
