if ($("form").length > 0 && $("input#event_location_name").length > 0) {
	if($("input#event_location_name")[0].value.length > 3) {
		$('input#event_location_name').keydown(function() { 
			$.ajax({
				type: "GET",
				url: '/venue/find/'+$("input#event_location_name").val(),
				success: function(data){
					alert(data);
				}
			});
		});
	}
}

function setupCalendars(){
  var calendars = $('.date-picker');

	calendars.each(function(i){
		$(this).width('28em');
		var img = document.createElement('img');
		img.src = '/images/calendar.png';
    img.setAttribute('alt', 'Pick a date');
    img.id = 'calendar_' + i;
		$(this).after(img);
		
		Calendar.setup({
			firstDay: 1,
			showsTime: $(this).is(".show-time"),
			inputField: this.id,
			ifFormat: '%B %d %Y' + ($(this).is(".show-time") ? ' %H:%M' : ''),
			button: 'calendar_' + i
		});
	});
}	

$(document).ready(function(){
	setupCalendars();
});

$(document).ready(function($) {
  $('div.pagination a').livequery('click', function() {
    $('ul#events').load(this.href, {format: 'js'});
		return false;
  });
});
