ReportGenerator = {
	events : function(){
		var ids = this.ids('ulEvents')
		if(ids.length == 0){alert('Please select at least one event');return}
		window.open("/reports/events/" + ids.join(','), 'events')
	},
	performances : function(){
		var ids = this.ids('ulPerformances')
     	if(ids.length == 0){alert('Please select at least one performance');return}
     	$('id').value = ids
     	$('frmPerformances').submit()
		//window.open("/reports/performances/" + ids.join(','), 'events')
	},
	ids : function(cls){
		var ids = []
		$$('ul.' + cls + ' li').each(function(li){
		   var box = li.getElementsByTagName('input')[0]
		   if(box.checked){
				ids.push(box.value)
			}			
		})
		return ids		
	},
	updateField : function(id){
		new Ajax.Request("/reports/update_report_field/" + id)
	}	
}

function toggleCurrentVenue(that){
  var opt = that.options[that.selectedIndex]
  $('venue_title').update(opt.text)
  new Ajax.Request("/reports/update_current_venue/" + opt.value)
  clearCols()
}
function clearCols(){
  $('second_column').update('')
  $('third_column').update('')
}
// advanced search by date - both are required
function isValidDates(){
  if($F("search_from").empty() || $F("search_to").empty()){
    alert("Please select a valid start and end date")
    return false
  }else{
    return true
  }
}
// update performances list
function updatePerformances(that, eventId){
  if(that.checked) addEvent(eventId)
  else removeEvent(eventId)
}
function addEvent(eventId){
  $('waiter').show()
  new Ajax.Request("/reports/performances_list/" + eventId)
}
function removeEvent(eventId){
  $('eventPerformances' + eventId).update('')
}