
/*===============================================================================
	public.js
	John Larson
	3/10/09
	
	All page-specific JavaScript for public pages.
	
	
===============================================================================*/


window.addEvent('domready', function() {
	
	PN = { };
	PN.roar = new Roar();
	PN.UserID = 1;
	
	PN.popUp = new PopUpWindow('', {width: '400px' });
	
	PG.overTexts = []
	PG.overTexts[0] = new OverText($('Contact0Name'));
	PG.overTexts[1] = new OverText($('Contact0Email'));
});



/****************************************************************************
//	SECTION::Contact Submission
*/
	
	function populateLastName(theForm) {
		var name = theForm.name.value;
		if(name == '') {
			alert('Please enter your name.');
			theForm.name.focus();
			return false;
		}
		if(!isValidEmailAddress(theForm.Contact0Email.value)) {
			alert('Please enter a valid email address.');
			theForm.Contact0Email.focus();
			return false;
		}
		if(name.indexOf(' ') != -1) {
			var nameSet = name.split(' ');
			theForm.Contact0FirstName.value = nameSet[0];
			theForm.Contact0LastName.value = nameSet.splice(1).join(' ');
		}
		else {
			theForm.Contact0FirstName.value = name;
			theForm.Contact0LastName.value = '';
		}
		return true;
	}
	
	function deliver101Ways() {
		window.open('downloads/101Ways.pdf');
	}
	
	function submitContactForm(theForm) {
		showLoad();
		new Ajax('AJAX.asp?a=submitContactForm', {
			method: 'post',
			data: theForm,
			evalScripts: true,
			onComplete: function() {
				hideLoad();
				swapSections(theForm, 'thankYouMessage');
				var windowScroller = new Fx.Scroll(window);
				windowScroller.start(0, 200);
			//	PG.roar.alert('Your information has been submitted, thank you!');
			}
		}).request();
	}
/*
//	End SECTION::Contact Submission
****************************************************************************/




/****************************************************************************
//	SECTION::Free Stuff
*/
	function loadFreeStuff(type, theButton) {
		if(!theButton.hasClass('clickable')) return;
		
		new Ajax('AJAX.asp?a=loadFreeStuff', {
			method: 'post',
			data: 'type=' + type,
			update: 'freeContent',
			evalScripts: true,
			onComplete: setFreeStuffSection.pass([theButton])
		}).request();
		
		return false;
	}
	
	function setFreeStuffSection(theButton) {
		dbug.log(theButton);
		$$('.sectionButton').each(function(button) {
			if(button == theButton) {
				button.removeClass('clickable');
				swapToHoverSrc(button);
				button.removeEvent('mouseout', button.myMouseout);
			}
			else {
				button.addClass('clickable');
				swapFromHoverSrc(button);
				button.addEvent('mouseout', button.myMouseout);
			}
		});
	}
/*
//	End SECTION::Free Stuff
****************************************************************************/


/****************************************************************************
//	SECTION::Events
*/


function showEventPopUp(EventID) {
	
	PN.popUp.setPosition({
		relativeTo	: 'upcomingEvents',
		position	: { x: 'top', y: 'left' },
		offset		: { x: 150, y: -50 }
	} );
	PN.popUp.openURL('AJAX.asp?a=loadEvent&EventID=' + EventID,
		'Events Details');
}


function showDayEventPopUp(theDate, eventCount) {
	if(eventCount==0) return;
	
	PN.popUp.setPosition({
		relativeTo	: 'calendar-container',
		position	: { x: 'top', y: 'left' },
		offset		: { x: 100, y: -50 }
	} );
	PN.popUp.openURL('events.asp?a=getDayEvents&theDate=' + theDate.format('%m/%d/%Y'),
		'Events & Classes: ' + theDate.format('%B %d, %Y'));
	
	dbug.log('show the ' + eventCount + ' events!');
}

/*
//	End SECTION::Events
****************************************************************************/

