dojo.require("dojo.lang.*");

function clearOffCatSel(thisSelector)
{
	if (lastLeftNavCat != null)
		lastLeftNavCat.style.textDecoration = "none";
		
	if (thisSelector == null)
	{
		selector.value = "";
	}
}

var selector = null;	

function changeCategory(selectorID)
{
	var lUpdater = new listUpdater("CalendarTabManager", "calendar");
	
	selector = document.getElementById(selectorID);
	
	clearOffCatSel(selector);
		
	lUpdater.changeCategory(selector.value);
}

var lastLeftNavCat = null;

function changeCategoryByName(catName, leftNavCat)
{
	clearOffCatSel();
	
	lastLeftNavCat = leftNavCat;
	
	lastLeftNavCat.style.textDecoration = "underline";	
	
	var lUpdater = new listUpdater("CalendarTabManager", "calendar");
	
	lUpdater.changeCategory(catName);
}

function dodat(selection)
{
	var selectedItem = selection;
	alert(selectedItem);
}

function flipMonth(offSet)
{		
	if (lUpdater == null)
		lUpdater = new listUpdater("CalendarTabManager", "calendar");
	
	curDate = lUpdater.tabContainerWidget.dateFlip(offSet, "monthViewTab");
}

function switchYear(month, date)
{
	var year = document.getElementById("yearSelector").value;
	
	changeDate(year, month, date);
}

function changeDate(year, month, date)
{	
	if (lUpdater == null)
		lUpdater = new listUpdater("CalendarTabManager", "calendar");
	lUpdater.changeDate (year, month, date);
}

var lUpdater = null;

//list updated class
var listUpdater = function (listingId, calendarID)
{

	this.tabContainerWidget = null;

	
	var listContentEle = document.getElementById(listingId);
	
	if (listContentEle != null)
	{
		this.tabContainerWidget = dojo.widget.manager.getWidgetByNode(listContentEle);
	

	}
};

dojo.lang.extend( listUpdater, {


				
		changeDate: function (year, month, date)
		{
			year = parseInt(year, 10);
			month = parseInt(month, 10);
			date = parseInt(date, 10);
			
			//refresh the listing
			this.tabContainerWidget.dateChange(year, month, date, true);
			
		},
		
		changeCategory: function (category)
		{
			
			this.tabContainerWidget.categoryChange(category);
		}
		
		
	}
);
