
/*===============================================================================
	calendar.js
	John Larson
	3/32/08
	
	All page-specific JavaScript for calendar.asp

===============================================================================*/


window.addEvent('domready', function() {
	
	dbug.enable();
	
	gigListingPopUp = new PopUpWindow('Search Results', 
		{injectLocation: $('gigListingInjectDiv'),
		 width: '312px', left: '-70px', top: '-190px'});
	
	gigDetailsPopUp = new PopUpWindow('Event Details',
		{injectLocation: $('gigDetailsInjectDiv'),
		 width: '312px', left: '-400px', top: '130px'});
	
	
	
	new Autocompleter.Ajax.Grid($('bandName'), 
		'includes/autosuggest/bandSuggest.asp', {
		delay: 100,
		inheritWidth: false,
		dropDownWidth: '250px',
		injectChoice: function(choice) {
			choiceText = choice[1];
			var el = new Element('li').setHTML(this.markQueryValue(choiceText));
			el.inputValue = choiceText;
			this.addChoiceEvents(el).injectInside(this.choices);
		}
	});
	
	new Autocompleter.Ajax.Grid($('venueName'), 
		'includes/autosuggest/venueSuggest.asp', {
		delay: 100,
		inheritWidth: false,
		dropDownWidth: '250px',
		
		injectChoice: function(choice) {
			choiceText = choice[1];
			var el = new Element('li').setHTML(this.markQueryValue(choiceText));
			el.inputValue = choiceText;
			this.addChoiceEvents(el).injectInside(this.choices);
		}
	});
	
	$('gigDateInput').addEvent('change', function() {
		$('dateSearchOptionCheckbox').checked = 
			(isDate($('gigDateInput').value));
	});
	
	
	$('bandName').addEvent('focus', function() {
		$('bandSearchOptionName').checked = true;
	});
	
	$('GenreID').addEvent('focus', function() {
		$('bandSearchOptionGenre').checked = true;
	});
	
	$('venueName').addEvent('focus', function() {
		$('venueSearchOptionName').checked = true;
	});
	
	$('NeighborhoodID').addEvent('focus', function() {
		$('venueSearchOptionNeighborhood').checked = true;
	});
	
	gigSearchCalendar = new Calendar({ gigDateInput: 'm/d/Y' }, 
	  {tweak: { x: 6, y: 0 }});
	
});

	

/****************************************************************************
//	SECTION::Gig Search Auto-Suggest
*/
	
	
	function searchGigs() {
		showLoad();
		new Ajax('AJAXLoad.asp?l=loadGigSearchResults', {
			method: 'post',
			data: $('gigSearchForm'),
			update: gigListingPopUp.getContentDiv(),
			evalScripts: true,
			onComplete: function() {
				gigListingPopUp.open();
				hideLoad();
			}
		}).request();
	}
	
	function loadGigsPage(pageNumber) {
		showLoad();
		new Ajax('AJAXLoad.asp?l=loadGigSearchResultsPage&pageNumber=' + pageNumber, {
			method: 'post',
			data: $('gigSearchForm'),
			update: $('gigSearchResultsCurrentPage'),
			evalScripts: true,
			onComplete: hideLoad
		}).request();
	}
	
	
	function makeListingGigsClickable() {
		$$('.listingGig').each(function(theGig) {
			var thisID = theGig.id.substring(10);
			theGig.addEvent('click', function() {
				loadGigDetails(thisID);
			});
		});
	}
	
	function loadGigDetails(GigID) {
		showLoad();
		new Ajax('AJAXLoad.asp?l=loadGigDetails', {
			method: 'post',
			data: 'GigID=' + GigID,
			update: gigDetailsPopUp.getContentDiv(),
			evalScripts: true,
			onComplete: function() {
				gigDetailsPopUp.open();
				hideLoad();
			}
		}).request();
	
	}
	
	
	
/*
//	End SECTION::Gig Search Auto-Suggest
****************************************************************************/





/****************************************************************************
//	SECTION::Calendar Grid Interaction
*/

	function loadNewMonth(thisMonth, thisYear) {
		showLoad();
		new Ajax('AJAXLoad.asp?l=loadCalendarMonth', {
			method: 'post',
			data: 'thisMonth=' + thisMonth + '&thisYear=' + thisYear,
			update: 'calendarMonth',
			evalScripts: true,
			onComplete: hideLoad
		}).request();
	}
	
	
	function loadGigDayListing(gigDate) {
		showLoad();
		new Ajax('AJAXLoad.asp?l=loadGigSearchResults', {
			method: 'post',
			data: 'dateSearchOption=true&gigDate=' + gigDate,
			update: gigListingPopUp.getContentDiv(),
			evalScripts: true,
			onComplete: function() {
				gigListingPopUp.open();
				hideLoad();
			}
		}).request();
	}
	
/*
//	End SECTION::Calendar Grid Interaction
****************************************************************************/