/**
 * events.js
 * JavaScript functions for searching for public events
 * @author Arthur McLean
 * @author Copyright 2007, Live Oak Interactive
 */


var EV = {
	/**
	 * Send an AJAX request to get the events for a particular day
	 * @return void
	 */
	get_events : function(calendar) {
		date_object = new Date($F('e_date'));
		var y = date_object.getFullYear();
		var m = date_object.getMonth() + 1; // getMonth returns 0-11; I want 1-12
		var d = date_object.getDate();
		
		var date = y + '-' + m + '-' + d; // parsable format for the server script
		
		// send the AJAX request
		new Ajax.Updater('results', '/whats_on/events/ajax_search/', {
			parameters: {
				event_value: date,
				category: $F('category')
			},
			method: 'post'
		});
	},
	
	
	/**
	 * date manipulation
	 * @return void
	 */
	public_status: function(date, y, m, d){
		date.setHours(0,0,0,0); // Date at midnight
		
		var date_timestamp = date.getTime();
		
		var today = new Date();
		today.setHours(0,0,0,0); // today at midnight
		var today_timestamp = today.getTime();
		
		if(date_timestamp < today_timestamp){
			// True disables the date
			return true;
		} else {
			return false;
		}
	},
	
	activate_refresh: function(cal) {
		if ($('event_refresh')) {
			Event.observe($('event_refresh'), 'click', function(ev) {
				Event.stop(ev);
				EV.get_events(cal);
			});
		}
	}
}