// JavaScript Document
//
function menuChange() {
	if (document.accordionSection >= 0) {
		document.accordion.showThisHideOpen(document.accordionSection);
	}
}
function userMenuChange() {
	if (document.userAccordionSection >= 0) {
		document.userAccordion.showThisHideOpen(document.userAccordionSection);
	}
}
//
function focusLoginEmail() {
	$('username').setStyle('color', '#000000');
	if ($('username').value == 'email') {
		$('username').value = '';
	}
}
function blurLoginEmail() {
	if ($('username').value == '') {
		$('username').value = 'email';
	}
	if ($('username').value == 'email') {
		$('username').setStyle('color', '#B2B2B2');
	}
}
function focusLoginPassword() {
	$('password').setStyle('color', '#000000');
	if ($('password').value == 'password') {
		$('password').value = '';
	}
}
function blurLoginPassword() {
	if ($('password').value == '') {
		$('password').value = 'password';
	}
	if ($('password').value == 'password') {
		$('password').setStyle('color', '#B2B2B2');
	}
}
function submitLogin() {
	if ($('username').value != '' && $('password').value != '') {
		$('login').value = 1;
		return true;
	}
	return false;
}
function logout() {
	document.logoutForm.submit();
}
// Search Area
function focusMainNavSearch() {
	$('mainNavSearchInput').setStyle('color', '#000000');
	if ($('mainNavSearchInput').value == 'search') {
		$('mainNavSearchInput').value = '';
	}
}
function blurMainNavSearch() {
	if ($('mainNavSearchInput').value == '') {
		$('mainNavSearchInput').value = 'search';
	}
	if ($('mainNavSearchInput').value == 'search') {
		$('mainNavSearchInput').setStyle('color', '#B2B2B2');
	}
}
function submitMainNavSearch() {
	if ($('mainNavSearchInput').value != 'search') {
		$('headerSearchForm').submit();
	}
}
function focusAdvancedSearch() {
	$('menuSearch').setStyle('color', '#000000');
	if ($('menuSearch').value == 'search site') {
		$('menuSearch').value = '';
	}
}
function blurAdvancedSearch() {
	if ($('menuSearch').value == '') {
		$('menuSearch').value = 'search site';
	}
	if ($('menuSearch').value == 'search site') {
		$('menuSearch').setStyle('color', '#666666');
	}
}
function submitMenuSearch() {
	if ($('menuSearch').value != 'search site') {
		$('menuSearchForm').submit();
	}
}
// Get Directions
function focusAddress() {
	var address = $('directionsAddress');
	if (address.value == 'Address') {
		address.value = '';
		address.setStyle('color', '#000000');
	}
}
function blurAddress() {
	var address = $('directionsAddress');
	if (address.value == '') {
		address.value = 'Address';
		address.setStyle('color', '#666666');
	}
}
function focusCity() {
	var city = $('directionsCity');
	if (city.value == 'City') {
		city.value = '';
		city.setStyle('color', '#000000');
	}
}
function blurCity() {
	var city = $('directionsCity');
	if (city.value == '') {
		city.value = 'City';
		city.setStyle('color', '#666666');
	}
}
function focusState() {
	var state = $('directionsState');
	if (state.value == 'State') {
		state.value = '';
		state.setStyle('color', '#000000');
	}
}
function blurState() {
	var state = $('directionsState');
	if (state.value == '') {
		state.value = 'State';
		state.setStyle('color', '#666666');
	}
}
function mapSlideIn() {
	document.mapSlide.slideIn().chain( function () { 
		if (navigator.appVersion.indexOf("Win") != -1) {
			$('mapDiv').setStyle('visibility', 'visible');
		}
		// open address if only one
		if (document.addressPoint != undefined) {
			document.map.openInfoWindowHtml(document.addressPoint, document.addressHTML);
		}
	});
	$('rightSubHeadline').setHTML('<a href="javascript: mapSlideOut();">hide directions</a>');
	// clear and add marker if directions were asked for
	if (document.addressPoint != undefined) {
		document.map.clearOverlays();
		//document.map.setCenter(new GLatLng(45.464946600971466, -98.48075866699219), 12);
		document.map.addOverlay(document.marker);
	} else {
		resetMapMarkers();
	}
	// google analytics event tracking
	pageTracker._trackEvent('directions', 'open', 'show map');
}
function mapSlideOut() {
	if (navigator.appVersion.indexOf("Win") != -1) {
		$('mapDiv').setStyle('visibility', 'hidden');
	}
	document.mapSlide.slideOut();
	document.directionsSlide.slideOut();
	$('rightSubHeadline').setHTML('<a href="javascript: mapSlideIn();">get directions</a>');
	// google analytics event tracking
	pageTracker._trackEvent('directions', 'close', 'hide map');
}
function setDirections() {
	document.map.clearOverlays();
	document.gdir.load("from: " + $('directionsAddress').value + ', ' + $('directionsCity').value + ', ' + $('directionsState').value + " to: " + document.directionsCoordinates);
	// google analytics event tracking
	pageTracker._trackEvent('directions', 'get', 'get directions');
}
function onGDirectionsLoad() {
	document.directionsSlide.slideIn().chain( function() {
		$('directions').getParent().setStyle('height',  $('directions').getStyle('height')+10);
	 });
}
function resetMapMarkers() {
	if (document.addressPoint0 != undefined) {
		document.map.clearOverlays();
		var mapBounds = new GLatLngBounds();
		// loop through needed addresses
		var i = 0;
		while(document['marker'+i] != undefined) {
			mapBounds.extend(document['addressPoint'+i]);
			document.map.addOverlay(document['marker'+i]);
			//
			i++;
		}
		var mapMaxZoom = 16;
		var mapZoom = document.map.getBoundsZoomLevel(mapBounds)-1;
		if (mapZoom > mapMaxZoom) {
			mapZoom = mapMaxZoom;
		}
		document.map.setCenter(mapBounds.getCenter(), mapZoom);
	}
}
function handleErrors() {
	if (document.gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + document.gdir.getStatus().code);
	else if (document.gdir.getStatus().code == G_GEO_SERVER_ERROR)
		alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + document.gdir.getStatus().code);
	else if (document.gdir.getStatus().code == G_GEO_MISSING_QUERY)
		alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + document.gdir.getStatus().code);
//   else if (document.gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + document.gdir.getStatus().code);
	else if (document.gdir.getStatus().code == G_GEO_BAD_KEY)
		alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + document.gdir.getStatus().code);
	else if (document.gdir.getStatus().code == G_GEO_BAD_REQUEST)
		alert("A directions request could not be successfully parsed.\n Error code: " + document.gdir.getStatus().code);
	else alert("An unknown error occurred.");
}
// RSVP
function submitRSVP(formID, going) {
	$('rsvp'+formID).value = going;
	var log = $('rsvpBox'+formID);
	$('rsvpForm'+formID).send({ update: log });
}
function highlightRSVP(formID, going) {
	if (going == 1) {
		MM_swapImage('rsvpImg'+formID,'','/images/goingFalseOver.gif',1);
	} else {
		MM_swapImage('rsvpImg'+formID,'','/images/goingTrueOver.gif',1);
	}
}
function clearRSVP(formID, going) {
	if (going == 1) {
		MM_swapImage('rsvpImg'+formID,'','/images/goingFalseUp.gif',1);
	} else {
		MM_swapImage('rsvpImg'+formID,'','/images/goingTrueUp.gif',1);
	}
}
// Coupon Book
function submitClipIt(formID, going) {
	$('clipIt'+formID).value = going;
	var log = $('clipItBox'+formID);
	$('clipItForm'+formID).send({ update: log });
}
function highlightClipIt(formID, going) {
	if (going == 1) {
		MM_swapImage('clipItImg'+formID,'','/images/clipItFalseOver.gif',1);
	} else {
		MM_swapImage('clipItImg'+formID,'','/images/clipItTrueOver.gif',1);
	}
}
function clearClipIt(formID, going) {
	if (going == 1) {
		MM_swapImage('clipItImg'+formID,'','/images/clipItFalseUp.gif',1);
	} else {
		MM_swapImage('clipItImg'+formID,'','/images/clipItTrueUp.gif',1);
	}
}
// Favorites
function submitFavorite(formID) {
	var log = $('favoritesText'+formID);
	$('favoriteForm'+formID).send({ update: log });
}
function submitFavoriteEdit(givenForm) {
	var log = $('favoritesList');
	document.favoriteSlide.slideOut().chain( function() {
		$(givenForm).send({ update: log, onComplete: function() { 
			document.favoriteSlide.slideIn();
			//var log2 = $('favoritesAccordionDiv');
			//var favoriteUpdate = new Ajax('/favorites/accordion/', {method: 'get', update: log2, onComplete: function() { document.accordion.showThisHideOpen(4); } }).request();
		} });
	});
	return false;
}
// List
function changeList(searchType, offset, uniqueID) {
	clearInterval(document.eventScrollerInterval);
	//
	if (offset >= 0 && $('eventsListDiv'+offset) != undefined) {
		query = '?offset=' + offset  + '&uniqueID=' + uniqueID;
		if (searchType) {
			query += '&searchType='+searchType;
		}
		if (document.category != 'todaysEventsList') {
			query += '&category=' + document.category;
		}
		if (document.todaysEvents) {
			if (document.eventsPerList) {
				query += '&eventsPerList='+document.eventsPerList;
			} else {
				query += '&eventsPerList=6';
			}
			query += '&q=1';
		} else {
			query += '&eventsPerList='+document.eventsPerList;
		}
		if ($('eventsListDiv'+offset).hasClass('notLoadedList')) {
			var log = $('eventsListDiv'+offset);
			if (document.scrollEvents == undefined) {
				document.scrollEvents = new Fx.Scroll('eventListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			var eventListAjax = new Ajax('/events/list/'+query, { update: log, onComplete: function() {
				document.scrollEvents.toElement('eventsListDiv'+offset);
			} });
			eventListAjax.request();
			// remove class
			$('eventsListDiv'+offset).removeClass('notLoadedList');
		} else {
			if (document.scrollEvents == undefined) {
				document.scrollEvents = new Fx.Scroll('eventListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			document.scrollEvents.toElement('eventsListDiv'+offset);
		}
		document.eventsOffset = offset;
		// remember offset for history
		var currentLocation = window.location.toString();
		var addHistory = currentLocation.substring(0,currentLocation.lastIndexOf('#'));
		window.location = addHistory+'#eventsOffset='+offset;
	}
}
function scrollList(searchType, offset) {
	if ($('eventsListDiv'+offset) == undefined) {
		offset = 0;
	}
	if (offset >= 0 && $('eventsListDiv'+offset) != undefined) {
		query = '?offset=' + offset;
		query += '&searchType='+searchType;
		query += '&eventsPerList='+document.eventsPerList;
		query += '&q=1';
		//
		if ($('eventsListDiv'+offset).hasClass('notLoadedList')) {
			var log = $('eventsListDiv'+offset);
			if (document.scrollEvents == undefined) {
				document.scrollEvents = new Fx.Scroll('eventListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			var eventListAjax = new Ajax('/events/list/'+query, { update: log, onComplete: function() {
				document.scrollEvents.toElement('eventsListDiv'+offset);
			} });
			eventListAjax.request();
			// remove class
			$('eventsListDiv'+offset).removeClass('notLoadedList');
		} else {
			if (document.scrollEvents == undefined) {
				document.scrollEvents = new Fx.Scroll('eventListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			document.scrollEvents.toElement('eventsListDiv'+offset);
		}
		document.eventsOffset = offset;
	}
}
function changeCouponList(searchType, offset, uniqueID) {
	if (offset >= 0 && $('couponsListDiv'+offset) != undefined) {
		query = '?offset=' + offset  + '&uniqueID=' + uniqueID;
		if (searchType) {
			query += '&searchType='+searchType;
		}
		if (document.category != '') {
			query += '&category=' + document.category;
		}
		query += '&couponsPerList='+document.couponsPerList;
		if ($('couponsListDiv'+offset).hasClass('notLoadedList')) {
			var log = $('couponsListDiv'+offset);
			if (document.scrollCoupons == undefined) {
				document.scrollCoupons = new Fx.Scroll('couponListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			var couponListAjax = new Ajax('/coupons/list/'+query, { update: log, onComplete: function() {
				document.scrollCoupons.toElement('couponsListDiv'+offset);
			} });
			couponListAjax.request();
			// remove class
			$('couponsListDiv'+offset).removeClass('notLoadedList');
		} else {
			if (document.scrollCoupons == undefined) {
				document.scrollCoupons = new Fx.Scroll('couponListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			document.scrollCoupons.toElement('couponsListDiv'+offset);
		}
		document.couponsOffset = offset;
		// remember offset for history
		var currentLocation = window.location.toString();
		var addHistory = currentLocation.substring(0,currentLocation.lastIndexOf('#'));
		window.location = addHistory+'#couponsOffset='+offset;
	}
}
// Calendar
function changeCalendar(query, month, year) {
	if (month) {
		document.viewMonth = month;
	}
	if (year) {
		document.viewYear = year;
	}
	var log = $('calendarDiv');
	if (document.calendarSlide == undefined) {
		document.calendarSlide = new Fx.Slide('calendarDiv', { mode: 'horizontal', duration: 250 });
	}
	var calendarAjax = new Ajax('/events/calendar/'+query, { update: log, onComplete: function() { document.calendarSlide.slideIn().chain(function() { $('calendarDiv').getParent().setStyle('width', 160); calendarTips(); }); } });
	document.calendarSlide.slideOut().chain( function() {
		calendarAjax.request();
	});
}
function changeCalendarList(query, view) {
	if (view) {
		document.viewDate = view;
	}
	var log = $('calendarListDiv');
	if (document.calendarListSlide == undefined) {
		document.calendarListSlide = new Fx.Slide('calendarListDiv', { duration: 300 });
	}
	var calendarListAjax = new Ajax('/events/calendarList/'+query, { update: log, onComplete: function() { 
		$('headlineDiv').removeClass('listLoading');
		document.calendarListSlide.hide().slideIn().chain( function() {
			document.calendarListSlide.show();
		});  
	} });
	document.calendarListSlide.slideOut().chain( function() {
		$('headlineDiv').addClass('listLoading');
		calendarListAjax.request();
	});
}
function calendarTips() {
	// Tips
	var tips = new Tips($$('.calTips'), {	
		showDelay: 0,
		hideDelay: 250,
		className: 'calTool',
		fixed: false,
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
}
// Map View
function changeEventsMap(searchType, offset, uniqueID) {
	if ($('eventsListDiv'+offset) != undefined) {
		query = '?offset=' + offset  + '&uniqueID=' + uniqueID;
		if (searchType) {
			query += '&searchType='+searchType;
		}
		if (document.category != 'todaysEventsList') {
			query += '&category=' + document.category;
		}
		if (document.todaysEvents) {
			if (document.eventsPerList) {
				query += '&eventsPerList='+document.eventsPerList;
			} else {
				query += '&eventsPerList=10';
			}
			query += '&q=1';
		} else {
			query += '&eventsPerList='+document.eventsPerList;
		}
		if ($('eventsListDiv'+offset).hasClass('notLoadedList')) {
			var log = $('eventsListDiv'+offset);
			// create scroll if not existing
			if (document.scrollEvents == undefined) {
				document.scrollEvents = new Fx.Scroll('eventListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			// load new vars
			var mapListAjax = new Ajax('/events/mapList/'+query, { update: log, evalScripts: true, onComplete: function() {
				// remove class
				$('eventsListDiv'+offset).removeClass('notLoadedList');
				showMapItems(offset);
				document.scrollEvents.toElement('eventsListDiv'+offset);
			} });
			mapListAjax.request();
		} else {
			showMapItems(offset);
			// create scroll if not existing
			if (document.scrollEvents == undefined) {
				document.scrollEvents = new Fx.Scroll('eventListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			document.scrollEvents.toElement('eventsListDiv'+offset);
		}
		document.eventsOffset = offset;
		// remember offset for history
		var currentLocation = window.location.toString();
		var addHistory = currentLocation.substring(0,currentLocation.lastIndexOf('#'));
		window.location = addHistory+'#eventsOffset='+offset;
	}
}
function changeCouponsMap(searchType, offset, uniqueID) {
	if ($('couponsListDiv'+offset) != undefined) {
		query = '?offset=' + offset  + '&uniqueID=' + uniqueID;
		if (searchType) {
			query += '&searchType='+searchType;
		}
		query += '&category=' + document.category;
		query += '&couponsPerList='+document.couponsPerList;
		if ($('couponsListDiv'+offset).hasClass('notLoadedList')) {
			var log = $('couponsListDiv'+offset);
			// create scroll if not existing
			if (document.scrollEvents == undefined) {
				document.scrollEvents = new Fx.Scroll('couponListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			// load new vars
			var mapListAjax = new Ajax('/coupons/mapList/'+query, { update: log, evalScripts: true, onComplete: function() {
				// remove class
				$('couponsListDiv'+offset).removeClass('notLoadedList');
				showMapItems(offset);
				document.scrollEvents.toElement('couponsListDiv'+offset);
			} });
			mapListAjax.request();
		} else {
			showMapItems(offset);
			// create scroll if not existing
			if (document.scrollEvents == undefined) {
				document.scrollEvents = new Fx.Scroll('couponListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			document.scrollEvents.toElement('couponsListDiv'+offset);
		}
		document.couponsOffset = offset;
		// remember offset for history
		var currentLocation = window.location.toString();
		var addHistory = currentLocation.substring(0,currentLocation.lastIndexOf('#'));
		window.location = addHistory+'#couponsOffset='+offset;
	}
}
function showMapItems(newOffset) {
	document.map.clearOverlays();
	//
	var mapBounds = new GLatLngBounds();
	//
	var offset = newOffset;
	// check for max num
	if (document.eventsPerList != undefined) {
		var maxPerList = document.eventsPerList;
	} else if (document.couponsPerList != undefined) {
		var maxPerList = document.couponsPerList;
	} else if (document.locationsPerList) {
		var maxPerList = document.locationsPerList;
	}
	while(document['addressPoint'+offset] != undefined && offset < newOffset+maxPerList) {
		mapBounds.extend(document['addressPoint'+offset]);
		document.map.addOverlay(document['marker'+offset]);
		//
		offset++;
	}
	//
	var mapMaxZoom = 14;
	var mapZoom = document.map.getBoundsZoomLevel(mapBounds);
	if (mapZoom > mapMaxZoom) {
		mapZoom = mapMaxZoom;
	}
	document.map.setCenter(mapBounds.getCenter(), mapZoom);
}
function showMapAddress() {
	var addressID = document.mapAddressPoint;
	document.map.openInfoWindowHtml(document['addressPoint'+addressID], document['addressHTML'+addressID]);
}
// Contest
function changeContest(direction) {
	if (document.contestOffset == undefined) {
		document.contestOffset = 0;
	}
	var offset = document.contestOffset + direction;
	if (offset >= 0 && $('contestListDiv'+offset) != undefined) {
		query = '?offset=' + offset;
		if ($('contestListDiv'+offset).hasClass('notLoadedList')) {
			var log = $('contestListDiv'+offset);
			if (document.scrollContests == undefined) {
				document.scrollContests = new Fx.Scroll('contestListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			var contestListAjax = new Ajax('/contests/list/'+query, { update: log, onComplete: function() {
				document.scrollContests.toElement('contestListDiv'+offset);
			} });
			contestListAjax.request();
			// remove class
			$('contestListDiv'+offset).removeClass('notLoadedList');
		} else {
			if (document.scrollContests == undefined) {
				document.scrollContests = new Fx.Scroll('contestListDiv', { wheelStops: false, wait: false, duration: 1000, offset: {'x': 0, 'y': 0}, transition: Fx.Transitions.Quad.easeInOut });
			}
			document.scrollContests.toElement('contestListDiv'+offset);
		}
		document.contestOffset = offset;
	}
}
function enterContest(contestID) {
	$('contestEntryText'+contestID).removeClass('blueLink');
	$('contestEntryText'+contestID).addClass('greyLink');
	$('contestEntryText'+contestID).setHTML('thank you for entering');
	//$('contestEntryDiv'+contestID).removeClass('blueBG');
	//$('contestEntryDiv'+contestID).addClass('orangeBG');
	MM_swapImage('ticketButton'+contestID,'','/images/greyTicketButton.gif',1);
}
// Tab Slides
function showLocationInfo(color, photo) {
	document.locationSentSlide.slideOut();
	if (document.locationPhotoSlide != undefined) {
		document.locationPhotoSlide.slideOut().chain(function() { 
			document.locationInfoSlide.slideIn(); 
			if (photo == true) {
				$('eventTabs').setHTML('<b class="'+color+'Text">info</b> | <a href="javascript: showLocationPhoto(\''+color+'\', true);" class="'+color+'Link">add photo</a>');
			} else {
				$('eventTabs').setHTML('<b class="'+color+'Text">info</b>');
			}
		});
	}
}
function showLocationPhoto(color, photo) {
	document.locationSentSlide.slideOut();
	document.locationInfoSlide.slideOut().chain(function() { 
		document.locationPhotoSlide.slideIn(); 
		$('eventTabs').setHTML('<a href="javascript: showLocationInfo(\''+color+'\', true);" class="'+color+'Link">info</a> | <b class="'+color+'Text">add photo</b>');
	});
}
// Email Event
function emailFromFocus() {
	if ($('emailFrom').value == 'your email') {
		$('emailFrom').value = '';
	}
	$('emailFrom').setStyle('color', '#000000');
}	
function emailFromBlur() {
	if ($('emailFrom').value == '') {
		$('emailFrom').value = 'your email';
		$('emailFrom').setStyle('color', '#666666');
	}
}
function sendToFocus() {
	if ($('sendTo').value == 'email address') {
		$('sendTo').value = '';
	}
	$('sendTo').setStyle('color', '#000000');
}	
function sendToBlur() {
	if ($('sendTo').value == '') {
		$('sendTo').value = 'email address';
		$('sendTo').setStyle('color', '#666666');
	}
}
function checkEmailForm(color, photo, reminder) {
	if ($('emailFrom').value == 'your email') {
		alert('Please enter your email address.');
		return false;
	}
	if ($('sendTo').value == 'email address') {
		alert('Please enter an email address to send to.');
		return false;
	}
	//
	var log = $('emailSent');
	document.eventEmailSlide.slideOut();
	if (reminder == true) {
		$('eventTabs').setHTML('<a href="javascript: showEventInfo(\''+color+'\', true, true);" class="'+color+'Link">info</a> | <a href="javascript: showEventEmail(\''+color+'\', true, true);" class="'+color+'Link">share</a> | <a href="javascript: showEventReminder(\''+color+'\', true, true);" class="'+color+'Link">remind me</a> | <a href="javascript: showEventPhoto(\''+color+'\', true, true);" class="'+color+'Link">add photo</a>');
	} else if (photo == true) {
		$('eventTabs').setHTML('<a href="javascript: showEventInfo(\''+color+'\', true);" class="'+color+'Link">info</a> | <a href="javascript: showEventEmail(\''+color+'\', true);" class="'+color+'Link">share</a> | <a href="javascript: showEventPhoto(\''+color+'\', true);" class="'+color+'Link">add photo</a>');
	} else {
		$('eventTabs').setHTML('<a href="javascript: showEventInfo(\''+color+'\');" class="'+color+'Link">info</a> | <a href="javascript: showEventEmail(\''+color+'\');" class="'+color+'Link">share</a>');
	}
	$('emailEventForm').send({ update: log, onComplete: function() { document.eventSentSlide.slideIn(); } });
	return false;
}
// Photos
function changePhoto(photoID, direction) {
	if (!document.currentPhoto) {
		document.currentPhoto = 0;
	}
	// 
	if (document.photoArray.length > 0) {
		if (!direction || direction == "right") {
			if (document.currentPhoto < document.photoArray.length-1) {
				document.currentPhoto++;
			} else {
				document.currentPhoto = 0;
			}
			var newPhoto = document.photoArray[document.currentPhoto];
		} else {
			if (document.currentPhoto > 0) {
				document.currentPhoto--;
			} else {
				document.currentPhoto = document.photoArray.length-1;
			}
			var newPhoto = document.photoArray[document.currentPhoto];
		}
		//
		MM_swapImage(photoID,'','http://www.alltestcity.net/uploads/'+newPhoto+'P160.jpg',1);
	}
}
function photoPreview() {
	var query = '?id='+$('photoDuplicateSelect').value;
	var log = $('duplicatePhotoPreview');
	var photoAjax = new Ajax('/photos/preview/'+query, { update: log });
	photoAjax.request();
}
function checkPhotoDuplicate() {
	if ($('photoDuplicateSelect').value == '') {
		alert('Please select an existing photo to use for this event.');
		$('photoDuplicateSelect').focus();
		return false;
	}
	return true;
}
// Event Options
function eventOptionOver(name, active) {
	$('eventOptionSelectArrow').setStyle('visibility', 'visible');
	var id = 'eventIcon'+name;
	switch (name) {
		case 'Photo':
			if (active == 1) {
				MM_swapImage(id,'','/images/bluePhotoOver.gif',1);
			}
			$('eventOptionText').setHTML('add a photo');
			$('eventOptionSelectArrow').setStyle('left', 5);
			break;
		case 'Email':
			MM_swapImage(id,'','/images/blueEmailOver.gif',1);
			$('eventOptionText').setHTML('email');
			$('eventOptionSelectArrow').setStyle('left', 34);
			break;
		case 'Print':
			MM_swapImage(id,'','/images/bluePrintOver.gif',1);
			$('eventOptionText').setHTML('print event');
			$('eventOptionSelectArrow').setStyle('left', 63);
			break;
		case 'Favorite':
			if (active == 1) {
				MM_swapImage(id,'','/images/blueFavoriteOver.gif',1);
			}
			$('eventOptionText').setHTML('add to favorites');
			$('eventOptionSelectArrow').setStyle('left', 92);
			break;
		case 'Unfavorite':
			MM_swapImage(id,'','/images/blueUnfavoriteOver.gif',1);
			$('eventOptionText').setHTML('unfavorite');
			$('eventOptionSelectArrow').setStyle('left', 92);
			break;
		case 'Share':
			MM_swapImage(id,'','/images/blueShareOver.gif',1);
			$('eventOptionText').setHTML('share');
			$('eventOptionSelectArrow').setStyle('left', 121);
			break;
	}
}
function eventOptionOut(name, active) {
	$('eventOptionSelectArrow').setStyle('visibility', 'hidden');
	var id = 'eventIcon'+name;
	switch (name) {
		case 'Photo':
			if (active == 1) {
				MM_swapImage(id,'','/images/photoActive.gif',1);
			}
			break;
		case 'Email':
			MM_swapImage(id,'','/images/emailActive.gif',1);
			break;
		case 'Print':
			MM_swapImage(id,'','/images/printActive.gif',1);
			break;
		case 'Favorite':
			if (active == 1) {
				MM_swapImage(id,'','/images/favoriteActive.gif',1);
			}
			break;
		case 'Unfavorite':
			MM_swapImage(id,'','/images/unfavoriteActive.gif',1);
			break;
		case 'Share':
			MM_swapImage(id,'','/images/shareActive.gif',1);
			break;
	}
	$('eventOptionText').setHTML('&nbsp;');
}
// Coupon Options
function couponOptionOver(name, active) {
	$('couponOptionSelectArrow').setStyle('visibility', 'visible');
	var id = 'couponIcon'+name;
	switch (name) {
		case 'Photo':
			if (active == 1) {
				MM_swapImage(id,'','/images/greenPhotoOver.gif',1);
			}
			$('couponOptionText').setHTML('add a photo');
			$('couponOptionSelectArrow').setStyle('left', 5);
			break;
		case 'Email':
			MM_swapImage(id,'','/images/greenEmailOver.gif',1);
			$('couponOptionText').setHTML('email');
			$('couponOptionSelectArrow').setStyle('left', 34);
			break;
		case 'Print':
			MM_swapImage(id,'','/images/greenPrintOver.gif',1);
			$('couponOptionText').setHTML('print coupon');
			$('couponOptionSelectArrow').setStyle('left', 63);
			break;
		case 'Favorite':
			if (active == 1) {
				MM_swapImage(id,'','/images/greenFavoriteOver.gif',1);
			}
			$('couponOptionText').setHTML('add to favorites');
			$('couponOptionSelectArrow').setStyle('left', 92);
			break;
		case 'Unfavorite':
			MM_swapImage(id,'','/images/greenUnfavoriteOver.gif',1);
			$('couponOptionText').setHTML('unfavorite');
			$('couponOptionSelectArrow').setStyle('left', 92);
			break;
		case 'Share':
			MM_swapImage(id,'','/images/greenShareOver.gif',1);
			$('couponOptionText').setHTML('share');
			$('couponOptionSelectArrow').setStyle('left', 121);
			break;
	}
}
function couponOptionOut(name, active) {
	$('couponOptionSelectArrow').setStyle('visibility', 'hidden');
	var id = 'couponIcon'+name;
	switch (name) {
		case 'Photo':
			if (active == 1) {
				MM_swapImage(id,'','/images/photoActive.gif',1);
			}
			break;
		case 'Email':
			MM_swapImage(id,'','/images/emailActive.gif',1);
			break;
		case 'Print':
			MM_swapImage(id,'','/images/printActive.gif',1);
			break;
		case 'Favorite':
			if (active == 1) {
				MM_swapImage(id,'','/images/favoriteActive.gif',1);
			}
			break;
		case 'Unfavorite':
			MM_swapImage(id,'','/images/unfavoriteActive.gif',1);
			break;
		case 'Share':
			MM_swapImage(id,'','/images/shareActive.gif',1);
			break;
	}
	$('couponOptionText').setHTML('&nbsp;');
}
// Business Options
function businessOptionOver(name, active) {
	$('businessOptionSelectArrow').setStyle('visibility', 'visible');
	var id = 'businessIcon'+name;
	switch (name) {
		case 'Photo':
			if (active == 1) {
				MM_swapImage(id,'','/images/photoOver.gif',1);
			}
			$('businessOptionText').setHTML('add a photo');
			$('businessOptionSelectArrow').setStyle('left', 5);
			break;
		case 'Email':
			MM_swapImage(id,'','/images/emailOver.gif',1);
			$('businessOptionText').setHTML('email');
			$('businessOptionSelectArrow').setStyle('left', 34);
			break;
		case 'Print':
			MM_swapImage(id,'','/images/printOver.gif',1);
			$('businessOptionText').setHTML('print');
			$('businessOptionSelectArrow').setStyle('left', 63);
			break;
		case 'Favorite':
			if (active == 1) {
				MM_swapImage(id,'','/images/favoriteOver.gif',1);
			}
			$('businessOptionText').setHTML('add to favorites');
			$('businessOptionSelectArrow').setStyle('left', 92);
			break;
		case 'Unfavorite':
			MM_swapImage(id,'','/images/unfavoriteOver.gif',1);
			$('businessOptionText').setHTML('unfavorite');
			$('businessOptionSelectArrow').setStyle('left', 92);
			break;
		case 'Share':
			MM_swapImage(id,'','/images/shareOver.gif',1);
			$('businessOptionText').setHTML('share');
			$('businessOptionSelectArrow').setStyle('left', 121);
			break;
	}
}
function businessOptionOut(name, active) {
	$('businessOptionSelectArrow').setStyle('visibility', 'hidden');
	var id = 'businessIcon'+name;
	switch (name) {
		case 'Photo':
			if (active == 1) {
				MM_swapImage(id,'','/images/photoActive.gif',1);
			}
			break;
		case 'Email':
			MM_swapImage(id,'','/images/emailActive.gif',1);
			break;
		case 'Print':
			MM_swapImage(id,'','/images/printActive.gif',1);
			break;
		case 'Favorite':
			if (active == 1) {
				MM_swapImage(id,'','/images/favoriteActive.gif',1);
			}
			break;
		case 'Unfavorite':
			MM_swapImage(id,'','/images/unfavoriteActive.gif',1);
			break;
		case 'Share':
			MM_swapImage(id,'','/images/shareActive.gif',1);
			break;
	}
	$('businessOptionText').setHTML('&nbsp;');
}
// Print 
function showPrint(category, getVars) {
	if (!category) {
		category = 'events';
	}
	if (!getVars) {
		var getVars = '';
	}
	window.open('/print/'+category+'/'+getVars, 'allPrint', 'status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=1,width=740,height=600');
}
// Surveys
function submitSurvey(vote) {
	$('voteNum').value = vote;
	var log = $('surveyData');
	var surveySlide = new Fx.Slide('surveyData');
	surveySlide.slideOut().chain( function() {
		$('surveyForm').send({ update: log, onComplete: function() { surveySlide.slideIn(); } });
	});
}
// Site Warnings
function textCounter(field, countfield, maxlimit) {
	if ($(field).value.length > maxlimit) { // if too long...trim it!
		$(field).value = $(field).value.substring(0, maxlimit);
	} else { // otherwise, update 'characters left' counter
		$(countfield).setHTML(maxlimit - $(field).value.length);
	}
}
// allCal
function openAllCal() {
	alert('openAllCal()');
}
// End Time
function updateEndTime() {
	var startHour = $('startHour').selectedIndex;
	var startMinute = $('startMinute').selectedIndex;
	var startTime = $('startTime').selectedIndex;
	if (startTime == 0 && startHour == 11) { // 12:00 am
		$('endHour').selectedIndex = 0;
		$('endTime').selectedIndex = 0;
	} else if (startTime == 0 && startHour == 10) { // 11:00 am
		$('endHour').selectedIndex = startHour+1;
		$('endTime').selectedIndex = 1;
	} else if (startTime == 1 && startHour == 10) { // 11:00 pm
		$('endHour').selectedIndex = startHour+1;
		$('endTime').selectedIndex = 0;
	} else if (startHour == 11) { // 12:00 pm
		$('endHour').selectedIndex = 0;
		$('endTime').selectedIndex = startTime;
	} else {
		$('endHour').selectedIndex = startHour+1;
		$('endTime').selectedIndex = startTime;
	}
	$('endMinute').selectedIndex = startMinute;
}
// End Date
function updateEndDate() {
	var startDate = document.getElementById('startDate-day').selectedIndex;
	var startMonth = document.getElementById('startDate-month').selectedIndex;
	var startYear = document.getElementById('startDate-year').selectedIndex;
	if ((startDate == 28 && startMonth == 1 && document.getElementById('startDate-year').value % 4 == 0) || (startDate == 27 && startMonth == 1 && document.getElementById('startDate-year').value % 4 != 0)) { // february and leap year increase one day
		document.getElementById('endDate-day').selectedIndex = 0;
		document.getElementById('endDate-month').selectedIndex = startMonth+1;
		document.getElementById('endDate-year').selectedIndex = startYear;
	} else if (startDate+1 > 29 && (startMonth == 3 || startMonth == 5 || startMonth == 8 || startMonth == 10)) { // 30 day months increase one day
		document.getElementById('endDate-day').selectedIndex = 0;
		document.getElementById('endDate-month').selectedIndex = startMonth+1;
		document.getElementById('endDate-year').selectedIndex = startYear;
	} else if (startDate == 30 && startMonth == 11) { // increase to next year
		document.getElementById('endDate-day').selectedIndex = 0;
		document.getElementById('endDate-month').selectedIndex = 0;
		document.getElementById('endDate-year').selectedIndex = startYear+1;
	} else if (startDate == 30) {
		document.getElementById('endDate-day').selectedIndex = 0;
		document.getElementById('endDate-month').selectedIndex = startMonth+1;
		document.getElementById('endDate-year').selectedIndex = startYear;
	} else {
		document.getElementById('endDate-day').selectedIndex = startDate+1;
		document.getElementById('endDate-month').selectedIndex = startMonth;
		document.getElementById('endDate-year').selectedIndex = startYear;
	}
}
// Ticket Dates
function updateTicketDates() {
	for (i = 0; i < 4; i++) {
		if (document.getElementById("ticketDesc"+i).value == 'Price Before' || document.getElementById("ticketDesc"+i).value == 'Price After') {
			document.getElementById("ticketChooser"+i).className = 'displayInline';
		} else {
			document.getElementById("ticketChooser"+i).className = 'noDisplay';
		}
	}
}
// Swap Business Info
function swapBusinessLoc(givenID, givenOffset) {
	var query = '?id='+givenID+'&offset='+givenOffset;
	// location info
	var log = $('businessInfo');
	var businessAjax = new Ajax('/pages/swap/'+query, { update: log }).request();
	// location list
	var log = $('businessLocationList');
	var businessAjax = new Ajax('/pages/swapLocation/'+query, { update: log }).request();
}
// Check Number
function checkNumber(givenNum) {
	var ok = "1234567890";
	//
	for(i=0; i < givenNum.length ;i++){
		if(ok.indexOf(givenNum.charAt(i))<0){ 
			//alert('Number contains invalid characters.');
			return false;
		}
	}
	//
	return true;
}
// Check EAN
function checkEAN(ean) {
 	var value = new Array('0','1','2','3','4','5','6','7','8','9');
	var chksum = 0;
    for (i = 0; i < ean.length; i++) {
		var v = -1;
		for (j = 0; j < value.length; j++) {
			if (value[j] == ean.charAt(i)) {
				if (i % 2 == 0) {
					v=j;
        		} else {
					v=3*j;
				}
			}
		}
		chksum += v;
    }
    chksum = chksum % 10;
    chksum = (10 - chksum) % 10;
	// get last digit
	var newEan = (Number(ean) + Number(value[chksum])).toString();
	var lastDigit = newEan.charAt(newEan.length-1);
	//
    var newEan = ean.substring(0,ean.length-1) + lastDigit;
	//alert(Number(ean) + Number(value[chksum]));
	//
	return newEan;
}
// Check Email
function checkEmail(address) {
	var ok = "@1234567890qwertyuiop[]asdfghjklzxcvbnm.-_QWERTYUIOPASDFGHJKLZXCVBNM'";
	//
	for(i=0; i < address.length ;i++){
		if(ok.indexOf(address.charAt(i))<0){ 
			alert('Email contains invalid characters.');
			return false;
		}
	}
	var email_array=address.split("@");
	if (email_array.length != 2) {
		alert('Email should contain 1 @ symbol.');
		return false;
	}
	var siteCheck = email_array[1].split(".");
	if (siteCheck.length > 1) {
		if (siteCheck[(siteCheck.length-1)].length > 4) {
			alert('Email address invalid.');
			return false;
		}
	} else {
		alert('Incomplete email address.');
		return false;
	}
	//return true;
}
// Event Submissions
function editEvent(number, page) {
	$('eventEditID').value = number;
	if (page) {
		$('eventEditPage').value = page;
	}
	$('eventEditForm').submit();
}
function eventStats(number, page) {
	$('eventEditID').value = number;
	if (page) {
		$('eventEditPage').value = page;
	}
	$('eventEditForm').action = '/events/stats/';
	$('eventEditForm').submit();
}
// Coupon Submissions
function editCoupon(number, page) {
	$('eventEditID').value = number;
	if (page) {
		$('eventEditPage').value = page;
	}
	$('eventEditForm').submit();
}
function couponStats(number, page) {
	$('eventEditID').value = number;
	if (page) {
		$('eventEditPage').value = page;
	}
	$('eventEditForm').action = '/coupons/stats/';
	$('eventEditForm').submit();
}
// Macromedia Scripts
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}