dojo.declare("com.mgh.EventsCategories",[com.mgh.Categories], {
	constructor : function(configParams) 
	{
		
	},
		
	updateQuery : function()
	{
		var m = this.queryParams;
		this.query = m.href + '?az=' + m.az + '&age=' + m.age + '&cat=' + m.cat +  '&subcat=' + m.subcat + '&type=' + m.type + '&query=' + m.query + 
		'&month=' + (m.month + 1) + '&audience=' + m.audience + '&eventType=' + m.eventType + '&mediaType=' + m.mediaType + '&newsType=' + m.newsType +
		'&year=' + m.year + '&topic=' + m.topic;
		//alert(this.query);
	}, 
		
 	buildCategories : function ()
 	{
		var i;
		//removes all category names from display
		var regEx = /\(.*\)/;
		var myCategories = this.categories.getElementsByTagName("NAME");
		var myCatIds = this.categories.getElementsByTagName("ID");
		var output = '<h3>Topic:</h3>';
	    
		if (this.linksToDisplay > myCategories.length){
			this.linksToDisplay = myCategories.length;
		}
		
	    var trimmed = '';
	    var rows = 0;

		var sortedCats = new Array();

		//first store the category and its ids and sort this new array
		for (i=0; i<myCategories.length; i++){
			sortedCats[i] = myCategories[i].childNodes[0].nodeValue + '|' + myCatIds[i].childNodes[0].nodeValue;
		}
			
		sortedCats = sortedCats.sort();
			
        // now with the ids sorted, use the sorted categories arrray to get an alphabetized list. use the 
        // sortedCats array instead of the original nodeList elements myCats and myCatIds
        for (var x=0; x < 3; x++){
	    	output += '<td width="33%" valign="top">';
	    	output += '<ul>';        	
	        for (i=rows; i < (this.linksToDisplay * (x+1)); i++){
				try {
		        	trimmed = sortedCats[i].split('|')[0].replace(regEx,'');
		        	output += '<li><a href="#" onclick="filterEventsByCategory(\''+
		        	sortedCats[i].split('|')[1] + '\'); updateEventsCategories(\'' + 
		        	sortedCats[i].split('|')[1] +'\',\'' + 
		        	trimmed + '\')">' + 
		        	trimmed + '</a></li>';
		        	rows +=1;
		        	if (i > (this.linksToDisplay *3)-1){
						output += '<li><a href="#" class="goBack" onclick="buildHiddenPanel(\'categoriesContent\',\'categories\'); dijit.byId(\'categoriesDialog\').show()">Display All</a></li>';		        		
		        	}
				} catch (e) {
					break;
				} 
	        }	        
        }
		dojo.byId('categories1').innerHTML = output;	
	},
	
	updateCategories : function (id,nodeName)
	{
		var output = '<h3>Select a Topic:</h3>';
        output += '<ul>';
		var nodes = dojo.query('li', id);
		output += '<li id="' + nodeName + '" class="active"><strong>' + nodeName + '</strong></li>';
		output += '<li><a href="#" class="goBack" onclick="removeFilter(\'eventsCategories1\')">Show all topics</a></li>';
		output += '</ul>'
		dojo.byId('categories1').innerHTML = output;
		this.previousCat = id;
	},
	
	buildFilter1 : function (){
		var filter1 = ['General Public','Medical Professionals','Researchers','Media'];
		var ids = [257,258,260,259];
		var output = '<h3>View Events For:</h3>';
		for (var i = 0; i < filter1.length; i++){
			output += '<li id="' + filter1[i] + '" class="active"><a href="#" onclick="updateEventsFilter1(\'' + ids[i]+ '\')">' + filter1[i] + '</a></li>';			
		}
		dojo.byId('filter1').innerHTML = output;
	},
	
	updateFilter1 : function (id){
		var filter = new Array();
		filter["257"] = 'General Public';
		filter["258"] = 'Medical Professionals';
		filter["260"] = 'Researchers';
		filter["259"] = 'Media';
		var output = '<H3>View Events For:</H3>';
		output += '<li id="' + id + '" class="active"><strong>' + filter[id] + '</strong></li>';
		output += '<li><a href="#" class="goBack" onclick="removeFilter(\'eventsFilter1\')">Show all events</a></li>';
		dojo.byId('filter1').innerHTML = output;
	}		
});