dojo.declare("com.mgh.CentersController", null, {
	constructor : function (id,url){
		this.allCentersId = id;
		this.url = url;
	},
	
	
	// this method should not be aware of a query string.
	GetData : function(id,name,type){	
		var qs = new com.mgh.QueryString(null);
		var centerId;
		try {
			id = id == '' ? this.allCentersId : id;
			dojo.xhrGet({
				url: this.url + 'GetCenters.ashx?id=' + id,
				handleAs: "json",				
				load : function (response,ioArgs){	
					centerId = qs.params['center'];
					if(centerId != undefined){			
						dojo.publish('preSelectedCentersDataReady',[centerId,response,type]);							
						//dojo.publish('getPreSelectedPrograms',[centerId,name,type]);
					} else {
						dojo.publish('centersDataReady',[response,type]);						
					}													
				},
				error : function(response, ioArgs){
					alert("An error occurred, with response: " + response);					
				}
			});
		} catch (e) {
			console.log('CentersController.GetData Error: ' + e);			
		}
	},
			
	GetCentersByLocation : function(id,name,type){
		try {
			var qs = new com.mgh.QueryString(null);
			var center = qs.params['center'];
			// Retrieve data only if center is not pre-selected.
			if ( center == undefined){
				dojo.xhrGet({
					url: this.url + "GetCentersByLocation.ashx?id=" + id,
					handleAs: "json",
					load : function (response,ioArgs){					
						dojo.publish('centersDataReady',[response]);
					},
					error : function(response, ioArgs){
						//alert("CentersController.GetCentersByLocation. An error occurred, with response: " + response);
						//for some reason when a location has state and showAllLocations is invoked this method is called
						//creates an error.
					}
				});
			}
		} catch (e) {
			console.log('LocationsController.GetLocationsByCenter Error: ' + e);			
		}		
	},	
	
	Filter : function(id,name){
		showTimer();
		mySearch.queryParams.center = id;
		mySearch.getXmlString();	
	}
});
