
/*	
	======================================================================

	javascript/public.js

	======================================================================
*/



	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  SponsorLinkEventDetails
	//
	/////////////////////////////////////////////////////////
	
 		function SponsorLinkEventDetails (eventID) {

			page = location.href;
			
			page = page.replace (/.*\//, '');
			
			page = page.replace (/=.*/, '');
			
			if ((page == 'month') || (page == '')) {
			
				ShowEventDetails (eventID);
			}
			
			else {
			
				location.href = '/month?displayEvent=' + eventID;
			}
 		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  JoinMailingList
	//
	/////////////////////////////////////////////////////////
	
		function JoinMailingList () {
		
			if (document.topForms.mailing_list_eMail.value != '') {
				
				if (Valid_Email_Address (document.topForms.mailing_list_eMail.value)) {
		
					var processingScript = "/php/join-mailing-list.php";
		
					var eMail = escape (document.topForms.mailing_list_eMail.value);
					
					var ajaxRequestString = processingScript + "?eMail=" + eMail;
		
					AJAX_Make_Request (ajaxRequestString);
				}
			
				else {
				
					alert ("Sorry...that e-mail address was not recognized as valid.");
				}
			}
			
			else {
			
				alert ("Please enter your e-mail address in order to join the mailing list...thanks!");
			}
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  SendToAFriend
	//
	/////////////////////////////////////////////////////////
	
		function SendToAFriend () {
		
			if ((document.topForms.tell_a_friend_name.value != '') && (document.topForms.tell_a_friend_name.value != 'your name')) {
				
				if (Valid_Email_Address (document.topForms.tell_a_friend_eMail.value)) {
		
					var processingScript = "/php/add-friend-to-mailing-list.php";
					
					var yourName = escape (document.topForms.tell_a_friend_name.value);
		
					var friendEmail = escape (document.topForms.tell_a_friend_eMail.value);
					
					var ajaxRequestString = processingScript + "?yourName=" + yourName + "&friendEmail=" + friendEmail;
		
					AJAX_Make_Request (ajaxRequestString);
				}
			
				else {
				
					alert ("Sorry...the second field must contain a valid e-mail address.");
				}
			}
			
			else {
			
				alert ("Please enter your name in the first first so your friend knows who sent this recommendation...thanks!");
			}
		}
		

	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  ShowEventDetails
	//
	/////////////////////////////////////////////////////////
	
		function ShowEventDetails (eventID) {
		
			var processingScript = "/php/get-event-details.php";
			
			var ajaxRequestString = processingScript + "?id=" + eventID;

			AJAX_Make_Request (ajaxRequestString);

			Show_Div ('eventDetail');
		}
		

	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  AJAX_Handle_Response
	//
	/////////////////////////////////////////////////////////
	
		function AJAX_Handle_Response (response) {
		
		// ---------------------------------------------
		// send to a friend return
		// ---------------------------------------------

			if (response == 'send_to_a_friend_return') {
			
				var alertMessage = "Thanks...an e-mail has been sent to " + document.topForms.tell_a_friend_eMail.value;
				
				document.topForms.tell_a_friend_eMail.value = '';
				
				alert (alertMessage);
			}

		// ---------------------------------------------
		// mailing list:  already on list
		// ---------------------------------------------

			else if (response == 'mailing_list_already_on_list') {
			
				var alertMessage = "Your e-mail address (" + document.topForms.mailing_list_eMail.value + ") is already on our mailing list. Please contact us if you're not getting our weekly announcement, and you may also wish to check your junk mail and add us to your white list.";
				
				document.topForms.mailing_list_eMail.value = '';
				
				alert (alertMessage);
			}

		// ---------------------------------------------
		// mailing list:  error adding to list
		// ---------------------------------------------

			else if (response == 'mailing_list_error_adding_to_list') {
			
				var alertMessage = "Sorry...there was an error adding the e-mail address '" + document.topForms.mailing_list_eMail.value + "' to our mailng list. Our staff has been contacted about the error.";
				
				document.topForms.mailing_list_eMail.value = '';
				
				alert (alertMessage);
			}

		// ---------------------------------------------
		// mailing list:  success
		// ---------------------------------------------

			else if (response == 'mailing_list_success') {
			
				var alertMessage = "Thanks...we've added the e-mail address '" + document.topForms.mailing_list_eMail.value + "' to our mailing list.";
				
				document.topForms.mailing_list_eMail.value = '';
				
				alert (alertMessage);
			}

		// ---------------------------------------------
		// event detail error
		// ---------------------------------------------
  		
			else if (response == 'no_event_info') {
			
				SetDivContent ('eventDetailBody', 'Sorry...no information is available for this event');
			}

		// ---------------------------------------------
		// event detail
		// ---------------------------------------------
 			
			else {
		
				SetDivContent ('eventDetailBody', response);
			}
		}
		
