/**
 * Business Delegate
 * @param serviceLocator
 * @param responder
 */
function ScheduleDelegate(serviceLocator, responder){
	this.serviceLocator = serviceLocator;
	this.responder = responder;
}

/**
 * @param String feed 
 * @param Date dateFrom
 * @param Date dateTo (optional). If null dateFrom + 1 day will be retrieved.
 */
ScheduleDelegate.prototype.getSchedule = function(feed, dateFrom, dateTo){
	var urlRequest = this.serviceLocator.scheduleService.url; 
	
	if(!dateTo){
		urlRequest += "?date="+ParseHelper.dateToString(dateFrom); 
	}else{
		urlRequest += "?from="+ParseHelper.dateToString(dateFrom)+"&to="+ParseHelper.dateToString(dateTo); 
	}
	
	urlRequest += "&feed="+feed+"&output=json";
	
	$.ajax({
		url:urlRequest, 
		success:this.scheduleResult,
		error:this.fault,
		context:this,
		timeout:this.serviceLocator.scheduleService.timeout
		});
}

/**
 * @param Number id 
 */
ScheduleDelegate.prototype.getShow = function(id){
	var urlRequest = this.serviceLocator.showService.url + 
	"?id="+id+ 
	"&output=json";
	
	$.ajax({
		url:urlRequest, 
		success:this.showResult,
		error:this.fault,
		context:this,
		timeout:this.serviceLocator.showService.timeout
		});
}

/**
 * @private
 */
ScheduleDelegate.prototype.scheduleResult = function(data, textStatus, XMLHttpRequest){
	var jsResult = $.parseJSON(data);
	var dto = jsResult["com.turner.dmtla.schedule.dto.ScheduleDTO"];
	this.responder.result(dto);
}


/**
 * @private
 */
ScheduleDelegate.prototype.showResult = function(data, textStatus, XMLHttpRequest){
	var jsResult = $.parseJSON(data);
	var dto = jsResult["com.turner.dmtla.schedule.dto.ShowDetailDTO"];
	this.responder.result(dto);
}

/**
 * @private
 */
ScheduleDelegate.prototype.fault = function(XMLHttpRequest, textStatus, errorThrown){
	this.responder.fault(errorThrown);
}

