function startMenuChange(linkID, enableAnimation) {
	/*	If linkID is already activated, don't do anything	*/
	if(isActivated(linkID)) {
		return false;
	}
		
	/*	Assign a default value to enableAnimation if it wasn't passed	*/
  enableAnimation = typeof(enableAnimation) != 'undefined' ? enableAnimation : true;

	/*	Attach a timer to the window that will fade in the new link after 500ms	*/
	window.timer = window.setTimeout("alertMe('" + linkID + "', '"+ enableAnimation + "')", 500);
}

function stopMenuChange() {
	/*	Cancel any timers attached to this menu	*/
	if(window.timer) {
		clearTimeout(window.timer);	
	}
}

function setGlobalTimer() {
	/*	Start a timer attached to the window
			When it expires, change the menu settings back to the current page
	*/
	window.globalTimer = window.setTimeout("activateBasePage(true)", 1000);
}

function cancelGlobalTimer() {
	/*	Cancel a timer created with setGlobalTimer()	*/
	if(window.globalTimer) {
		clearTimeout(window.globalTimer);
	}
}

function alertMe(linkID, enableAnimation) {
	/*	IMPORTANT: This is the code for the submenus.
			Quotes don't need to be escaped since we're using single quotes at the beginning of the strings.
	*/
	var homeMenu = '<li><a href="/" id="welcomeLink">Welcome</a></li><li><a href="/enf">Elks National Foundation</a></li><li><a href="/vets" id="vets">Veterans Services</a></li><li><a href="/memorial">Veterans Memorial</a></li><li><a href="/elksmag" id="elksmag">Magazine</a></li><li><a href="/convention">National Convention</a></li><li><a href="/locator.cfm">Lodge Locator</a></li>';
	var aboutMenu = '<li><a href="/AboutTheElks.cfm">Who We Are</a></li><li><a href="/about/membership.cfm">How To Join</a></li><li><a href="/lodges">Local Lodges</a></li><li><a href="/states" id="states">State Associations</a></li><li><a href="/SearchFAQ.cfm">FAQ</a></li><li><a href="/careers.cfm">Careers</a></li><li><a href="/sitemap.cfm">Site Map</a></li><li><a href="/ContactUs.cfm">Contact Us</a></li>';
	var serviceMenu = '<li><a href="/OurPrograms.cfm">Programs Home</a></li><li><a href="/enf/scholars">Scholarships</a></li><li><a href="/hoopshoot" id="hoopshoot">Hoop Shoot</a></li><li><a href="/dap">Drug Awareness</a></li><li><a href="/youthActivities.cfm">Youth Activities</a></li><li><a href="/vetPrograms.cfm">Veterans Programs</a></li>';
	var membersMenu = '<li><a href="/members" id="members">News of the Order</a></li><li><a href="/ChicagoLMS">CLMS</a></li><li><a href="/grandlodge" id="grandlodge">Grand Lodge</a></li><li><a href="/messageboard/menu.cfm" id="messageboard">Message Boards</a></li><li><a href="/shopping" id="shopping">Licensed Vendors</a></li><li><a href="/members/extended.cfm">Extended Access</a></li><li><a href="/services" id="services">Services</a></li><li><a href="/elkshome" id="elkshome">National Home</a></li>';
	
	/*	Activate (turn red and underline) the linkID that was passed	*/
	activateLink(linkID);

	/*	Figure out which of the four links to deactivate	*/
	if(linkID != 'homeLink') {
		deactivateLink('homeLink');
	}

	if(linkID != 'aboutLink') {
		deactivateLink('aboutLink');
	}

	if(linkID != 'serviceLink') {
		deactivateLink('serviceLink');
	}

	if(linkID != 'membersLink') {
		deactivateLink('membersLink');
	}

	/*	Figure out which of the four submenus to use	*/
	switch(linkID) {
		case 'homeLink':
			menuCode = homeMenu;
			break;

		case 'aboutLink':
			menuCode = aboutMenu;
			break;

		case 'serviceLink':
			menuCode = serviceMenu;
			break;
	
		case 'membersLink':
			menuCode = membersMenu;
			break;
	}

	/*	If animation is on, fade in the new submenu	*/
	if(enableAnimation) {
		Effect.Fade('subNav', { duration:0.3, afterFinish: function() {
			$('subNav').update(menuCode);
			/*	Run the highlighting routine to highlight the current page	*/
			currentPageCheck();
			Effect.Appear('subNav', { duration:0.3});
		}
		});
	} else {
		/*	Just flash in the new submenu	*/
		if($('subNav') && typeof(menuCode) != 'undefined') { $('subNav').update(menuCode) };
		/*	...and run the highlighting routine again	*/
		currentPageCheck();
	}
}

function currentPageCheck() {
	/*	Figures out which page is currently loaded and highlights any links to it on the menus	*/
	/*	Target all anchors inside list items inside the subnavigation	*/
	var subNavOptions = $$('ul#subNav li a');

	/*	Get the URL of the current page	*/
	var currentPage = window.location.href;

	/*	Doing things the right (Ruby) way	*/
	/*	Iterate over every item in the currently loaded submenu	*/
	subNavOptions.length.times(function(i) {
		/*	If a link's href in the submenu matches the current page's URL...	*/
		if(currentPage == subNavOptions[i].href) {
			/*	...change it to red and underline it.	*/
			activateLink(subNavOptions[i]);
			//subNavOptions[i].setStyle({ 'text-decoration':'underline' });
			return true;
		}
	});

	/*	Lastly look for special cases of pages to highlight	*/
	specialCheckCases(currentPage);
}

function specialCheckCases(currentPage) {
	/*	This routine handles highlighting of submenu links on pages that are not at the root level...	*/
	/*	Meaning it takes care of www.elks.org/vets, etc.	*/
	var specialLinks = new Array('vets', 'members', 'grandlodge', 'elksmag', 'hoopshoot', 'messageboard', 'elkshome', 'services', 'states', 'shopping');
	var dev = ".23/";
	var prod = "elks.org/";

	specialLinks.length.times(function(i) {
		if(currentPage.include(dev + specialLinks[i]) || currentPage.include(dev + specialLinks[i] + '/') || currentPage.include(prod + specialLinks[i]) || currentPage.include(prod + specialLinks[i] + '/')) {
				/*	Make sure the link exists before activating it	*/
				if($(specialLinks[i])) {
					activateLink(specialLinks[i]);
					return true;
				}
		}
	});

	/*	If we're not on the very front page, deactivate the welcome link which is a special case in itself	*/
	if(!isRootPage() && $('welcomeLink')) {
		deactivateLink('welcomeLink');
	}
}

function subMenuCheck() {
	/*	Check for the existence of a submenu	*/
	if($$('.sideNav')) {
		/*	Start crawling the links like in the main function	*/
		/*	THIS IS REPETITIVE WITH LINES 59-67 AND SHOULD BE FUNCTIONIFIED	*/
		/*	actually, it's not completely repetitive anymore thanks to the || currentPage == whatever	*/
			var subNavOptions = $$('div.sideNav ul li a');
			var currentPage = window.location.href;
		
			/*	Doing things the right (Ruby) way	*/
			subNavOptions.length.times(function(i) {
				//	Adding the slash compensates for links to /vets or whatever

				if(currentPage == subNavOptions[i].href || currentPage == subNavOptions[i].href + '/') {
					activateLink(subNavOptions[i]);
					subNavOptions[i].setStyle({ 'text-decoration':'underline' });
					return true;
				}
			});		
	}
}

function activateLink(linkID) {
	if($(linkID)) {
		$(linkID).setStyle({ 'color':'red' });
	}
}

function deactivateLink(linkID) {
	$(linkID).setStyle({ 'color':'#434dbf', 'background-color':'#fff' });
}

function toggleMap() {
	$('collapsibleMap').toggle();
}

function toggleSearch() {
	/*	If the text of the searchBox is Keyword Search... then clear it, otherwise
			if it's blank then set it back
	*/
	if($('keyword')) {
		if($F('keyword') == 'Keyword Search...' || $F('keyword') == 'Search...') {
			$('keyword').clear();
		} else if($F('keyword') == '' && screen.width > 800) {
			$('keyword').value = 'Keyword Search...';
		}
			else if($F('keyword') == '' && screen.width <= 800) {
			$('keyword').value = 'Search...';
		}
	}
}

function isActivated(menu) {
	/*	If it's activated, it's red.
			A more bulletproof way would be to assign a variable to the window
	*/
	
	if($(menu) && $(menu).style.color == 'red') {
		return true;
	} else {
		return false;
	}
}

function isRootPage() {
	if((window.location.pathname.split('/').length - 1) == 1) {
		return true;
	} else {
		return false;
	}
}

function activateBasePage(enableAnimation) {
  /*	Default enableAnimation to false	*/
	enableAnimation = typeof(enableAnimation) != 'undefined' ? enableAnimation : false;
	/*	Pass a variable to a JavaScript file via a pseudo-querystring. Jacked from script.aculo.us	*/
    $A(document.getElementsByTagName("script")).findAll( function(s) {
      return (s.src && s.src.match(/handlers\.js(\?.*)?$/))
    }).each( function(s) {
      var path = s.src.replace(/handlers\.js(\?.*)?$/,'');
      var includes = s.src.match(/\?.*p=([a-z,]*)/);
				var theElement = $(includes[1] + 'Link');
					if(!isActivated(theElement)) {
						alertMe(includes[1] + 'Link', enableAnimation);
					}
    });
}

function getFilename() {
	/*	Gets only the filename of the current page
			http://elks.org/vets/whatever.cfm becomes 'whatever'
	*/
	return window.location.pathname.substring(1, (window.location.pathname.indexOf('.cfm')));
}

function trim(str) {
	/*	Generic regular expression to trim whitespace from a string	*/
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function getMenu() {
	/*	Retrieves the menu via AJAX and loads it into an array	*/
	var url = 'includes/incNavigation.cfm?fromAJAX=true';
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
			var trimmedText = trim(transport.responseText);	
			splitMenu = trimmedText.split("\n")
			
			window.homeMenu = splitMenu[0];
			window.aboutMenu = splitMenu[1];
			window.serviceMenu = splitMenu[2];
			window.membersMenu = splitMenu[3];
	}
});
}

function toggleHelp(what) {
	/*	Figure out what state the top box is in based on the visibility of the boxes	*/
	if(what == 'helpSheet') {
		//	If helpSheet is invisible then loginForm is showing. Hide it.
		$('loginForm').style.display = 'none';
		$('helpLink').setStyle("text-decoration: none");
		$('loginLink').setStyle("text-decoration: underline");

		//	Show helpSheet
		//$('helpSheet').style.display = 'visible';

		//	And fade in via script.aculo.us the helpSheet
		Effect.Appear('helpSheet', { duration:0.3 });
	} else {
		//	Reverse it.
		$('helpSheet').style.display = 'none';
		$('loginLink').setStyle("text-decoration: none");
		$('helpLink').setStyle("text-decoration: underline");
		//	And fade in via script.aculo.us the helpSheet
		Effect.Appear('loginForm', { duration:0.3 });
	}

	/*	return false so that if JS is enabled, the link doesn't go anywhere.
			If JS is disabled then the link will go to the page specified in the href property	*/
	return false;
}

function disableSubmit() {
	if($('submit')) {
		$('submit').disable();
	}
}

function validateZIP(zipcode) {
		/*	regex from http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256F6B005294C2 */
   	var re = /^\d{5}/;
   	return (re.test(zipcode));
}

function lodgeLookup(lodgeNumber) {
	if(!validateZIP($F('lodgeZIP'))) {
		$('locatorError').show();
		$('locatorError').update('Error: Zip code must be five digits.');
		return false;
	}

	/*	If it got past the validation where it's needed, hide it	*/
	$('locatorError').hide();

	$('lodgeLocator').update('<img src="/images/spinner.gif" />');
	var url = '/lodges/FindNearestLodge.cfm?theZipCode=' + lodgeNumber;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
			var lodgeObject = trim(transport.responseText).evalJSON(true);
			
			/*	Start assembling update text	*/
			var updateText = '<p>The nearest lodge to ' + lodgeNumber + ' is:</p>';
			updateText += '<p><strong><a href="/lodges/home.cfm?LodgeNumber=' + lodgeObject.data.lodgenum[0] + '">' + lodgeObject.data.lodgename[0] + '</a> (' + lodgeObject.data.miles[0] + ' miles)</strong>.</p>';
			updateText += '<p><a href="#locator" id="listMoreLodges">More...</a></p>';
			updateText += '<p><a href="#locator" id="reset">Search again</a></p>';

			$('lodgeLocator').update(updateText);
			
			/*	Attach event handler to the new links	*/
			Event.observe($('listMoreLodges'), 'click', function() { expandLodgeTable(); return false; });
			Event.observe($('reset'), 'click', function() { resetLocator(); return false; });

			/*	Hide the lodge table until it's requested	*/
			$('lodgeTable').hide();

			$('lodgeTable').update('<h2>Others nearby:</h2>');

				/*	No more bullshit. Clean, straightforward DOM-created table	*/
				var myTable = document.createElement("table");
				myTable.setAttribute('id', 'locatorTable');

				var myTbody = document.createElement("tbody");
				myTable.appendChild(myTbody);

						for(x = 1; x < lodgeObject.recordcount; x++) {
							var myRow = document.createElement("tr");
							var myCell = document.createElement("td");
							var myCell2 = document.createElement("td");
							myCell.innerHTML = '<a href="/lodges/home.cfm?LodgeNumber=' + lodgeObject.data.lodgenum[x] + '">' + lodgeObject.data.lodgename[x] + '</a>';
							myCell2.innerHTML = lodgeObject.data.miles[x] + ' mi';
							myTbody.appendChild(myRow);
							myRow.appendChild(myCell);
							myRow.appendChild(myCell2);
						}						
				$('lodgeTable').appendChild(myTable);
	}
});
}

function resetLocator() {
	/*	Retract the div and delete the extended lodge table	*/
	/*	If the table is visible then we know we need to retract	*/

	if($('lodgeTable').style.display == 'none') {
		if($('locatorTable')) {
			$('locatorTable').remove();
		}

		$('lodgeLocator').update('<p class="clear">Enter your zip code to find the Elks lodge closest to you.</p><input type="text" id="lodgeZIP" class="zipSubmit" maxlength="5" /><input type="submit" id="lodgeSubmit" class="goButton submitButton" value="Go" /><p id="locatorError"></p></div>');
		$('locatorError').hide();

		/*	Reattach the event handlers	*/
		if($('lodgeSubmit') && $('lodgeTable')) {	/*	only attach this event if the element exists on the page	*/
			Event.observe($('lodgeSubmit'), 'click', function() { lodgeLookup($F('lodgeZIP')); return false; });
		}

	} else {
		/*	Retract the rest of the div and delete the table from the DOM when the animation finishes	*/
		//Effect.SlideUp('lodgeTable', { duration:1.5, afterFinish: function() { $('locatorTable').remove(); } });
		$('lodgeTable').hide();

		if($('locatorTable')) {
			$('locatorTable').remove();
		}
	
		/*	Reset the innerHTML to the form code	*/
		$('lodgeLocator').update('<p class="clear">Enter your zip code to find the Elks lodge closest to you.</p><input type="text" id="lodgeZIP" class="zipSubmit" maxlength="5" /><input type="submit" id="lodgeSubmit" class="goButton submitButton" value="Go" /><p id="locatorError"></p></div>');
		$('locatorError').hide();

		/*	Reattach the event handlers	*/
		if($('lodgeSubmit') && $('lodgeTable')) {	/*	only attach this event if the element exists on the page	*/
			Event.observe($('lodgeSubmit'), 'click', function() { lodgeLookup($F('lodgeZIP')); return false; });
		}
	}
}

function expandLodgeTable() {
	if($('listMoreLodges').innerHTML == 'More...') {
		$('listMoreLodges').update('Less...');
		//Effect.SlideDown('lodgeTable', { duration:0.3 });
		$('lodgeTable').show();

	} else {
		$('listMoreLodges').update('More...');
		//Effect.SlideUp('lodgeTable', { duration:0.3 });
		$('lodgeTable').hide();
	}
}

function roundCorners() {
	/*	Rounds every box that's supposed to be rounded	*/
	if($('lodgeDirectory')) {
		Nifty("div#lodgeDirectory", "big");
	}

	if($('google')) {
		Nifty('div#google', 'big');
	}

	if($('LodgeLocatorWidget')) {
		Nifty("div#LodgeLocatorWidget", "medium");
	}

	if($('collapsibleMap')) {
		Nifty('div#collapsibleMap', 'big');
	}

	Nifty("div.sideNav", "big");
	Nifty("div.sideContent", "big");
	Nifty("div.MessageBoard div.header", "medium");
	Nifty("form.NewMessageForm", "big");
	Nifty("div.DropdownWidget", "big");
	Nifty("div.magForm", "big");
	Nifty("form.registerForm", "big");
	Nifty('form.resetForm', 'big');
	Nifty('form.dapForm', 'big');
	Nifty('div.profileResult', 'big');
	Nifty('div.vendorResult', 'big');
	Nifty('form.gallerySearch', 'big');
	Nifty('form.photoForm', 'big');
	Nifty('div.sideMap', 'big');
	Nifty('div#contactBox', 'big');
	Nifty('form.gbForm', 'big');
}

function validateRegistration() {
	if($F('FirstName') == '' || $F('LastName') == '' || $F('LodgeNum') == '' || $F('MemberNum') == '') {
		$('submitReg').disable();
		$('LastNameLabel').setStyle({'color':'red'});
		$('InterestsLabel').setStyle({'color':'red'});
		$('UsernameLabel').setStyle({'color':'red'});
		
		alert('Last name, Interests and Username are required.');

		$('submitReg').enable();
		return false;
	}
}

function createTip() {
	if($('rssIcon')) {
		new Tip('rssIcon', 'Click this button to subscribe to the Elks RSS news feed. Using a tool like <a href="http://reader.google.com">Google Reader</a>, you can have the latest news delivered to you automatically, without having to visit this page.<br/><br/><a href="/rss.cfm">Learn more about RSS</a>', { className: 'darktip', title: 'What\'s this?', effect: 'appear', hideOn: false, hideAfter: .5, hook: {target: 'topLeft', tip: 'bottomRight'}});
	}

	if($('helpLink')) {
		new Tip('helpLink', '<ul><li>Forgot your username or password? <a href="http://elks.org/members/password.cfm">Click here</a> to have it emailed to you.</li><li> If you\'re a member of the Elks but don\'t yet have an Elks.Org password, <a href="http://elks.org/members/registration.cfm">please register now</a>.</li></ul>', { className: 'darktip', title: 'Elks.org Help', effect: 'appear', hideOn: false, hideAfter: .5, hook: {target: 'bottomLeft', tip: 'topRight'}});
	}
}

/*	AHOY! Legacy code on the horizon!	*/
function OpenHelpWindow(url) { 
	var windowURL      = url;
	var windowFeatures = 'width=516,height=350,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1'; 
	var HelpWindow  =  window.open( windowURL, "HelpWindow", windowFeatures );
	HelpWindow.focus();

	}

function activateLabel(formElement) {
//	$(formElement).setStyle({ background:'#fff2cc' });

	if(formElement == 'SortByName' || formElement == 'SortByNumber') {
		formElement = 'SortBy';
	}

	$(formElement + 'Label').setStyle({ color:'blue' });
}

function deactivateLabel(formElement) {
//	$(formElement).setStyle({ background:'white' });

	if(formElement == 'SortByName' || formElement == 'SortByNumber') {
		formElement = 'SortBy';
	}

	$(formElement + 'Label').setStyle({ color:'gray' });
}

function expandAlert() {
	if($('MoreInfo')) {
		$('expandAlert').hide();
		Effect.toggle('MoreInfo', 'appear', { duration:0.3 });
		
		return false;		
	}
}

function createMap() {
	if($('mapContainer')) {
		$('mapContainer').update('<img src="/images/spinner.gif"> Loading State Associations map...');

		if(window.useMap == 'lores') {
			var url = 'includes/incUSMap.cfm?res=lo';
		} else {
			var url = 'includes/incUSMap.cfm?res=normal';
		}
	
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) { $('mapContainer').update(trim(transport.responseText)); }});
	}
}

function hideElements() {	/*	hide all unnecessary page elements before the page renders	*/
	if($('MoreInfo')) {
		$('MoreInfo').hide();
	}
}

function widenContent() {
	if(!($('vhpEdit')) && !($('vhpPage'))) {
		if($$('.sideBox').length == 0 && $$('.sideNav').length == 0) {
			if($('content')) { $('content').setStyle({ 'width':'auto'}); }
		} else {
			/*	check for the existence of a narrow sidebar and widen the content if need be */
			if($$('.narrow').length > 0) {
				/*	it's narrow - change the size of the content	*/
				if($('content')) {
					if(screen.width > 800) {
						$('content').setStyle({ 'width':'680px' });
					} else {
						$('content').setStyle({ 'width':'500px' });
					}
				}
			}
		}
	
		if(screen.width <= 800) {
			if($('conHeader')) {
				$('conHeader').src = '/images/convention_narrow.jpg';
			}
		}
	}
}

function checkVHPMenu() {
	if($('vhpMenu')) {
			var css = $('stylesheet').href;
			var stylesheet = css.substring(css.indexOf('screen_') + 7);
			var stylesheet = stylesheet.substring(0, stylesheet.length - 4);

			var subNavOptions = $$('div#sideNav ul li');
			var currentPage = window.location.href;
		
			/*	Doing things the right (Ruby) way	*/
			subNavOptions.length.times(function(i) {
				/*	use element.down to go the next element down	*/
				var currentLink = subNavOptions[i].down();

				if(currentPage == currentLink.href || currentPage == currentLink.href + '/') {
					if(stylesheet == 'classic') {
						subNavOptions[i].setStyle( { 'border':'3px solid #271759' } );
						currentLink.setStyle({ 'color':'white' });
						return true;
					} else {
						currentLink.setStyle({ 'color':'red' });
						return true;
					}
				}
			});
	}
}

/*	Help stuff	*/
function getMouseCoords(e) {
	mouseX = Event.pointerX(e);
 	mouseY = Event.pointerY(e);

	coords[0] = mouseX;
	coords[1] = mouseY;

	return coords;
}

function showHelp(e) {
	/*	create and show help window at correct location	*/
	/*	yea, we're creating elements directly in the dom	*/

	var helpDiv = document.createElement("div");
	helpDiv.setAttribute('id', 'helpBox');


	topCoord = (Event.pointerY(e) - 400) + 'px';
	leftCoord = (Event.pointerX(e) - 500) + 'px';
	
	helpDiv.style.left = leftCoord; 
	helpDiv.style.top =  topCoord;
	helpDiv.style.display = 'none';

	var helpHeading = document.createElement("h2");
	helpDiv.appendChild(helpHeading);

	var helpParagraph = document.createElement("div");
	helpParagraph.setAttribute('id', 'helpText');
	helpDiv.appendChild(helpParagraph);

	var spinner = document.createElement("img");
	spinner.setAttribute('src', '/images/spinner.gif');
	spinner.setAttribute('id', 'spinner');
	helpDiv.appendChild(spinner);

	var closeLink = document.createElement("a");
	closeLink.setAttribute('href', 'javascript:void(0);');
	closeLink.setAttribute('id', 'closeLink');
	closeLink.style.float = 'right';
	helpDiv.appendChild(closeLink);

	/*	Attach it to the body	*/
	document.body.appendChild(helpDiv);

	/*	Set event handlers for elements inside helpDiv	*/
	$('closeLink').update('close help panel');
	Event.observe($('closeLink'), 'click', function() { Effect.Fade('helpBox'); });
	
	/*	Round helpBox for giggles	*/
	Nifty('div#helpBox', 'medium top');

	/*	script.aculo.us effect to puff it in	*/
	Effect.Appear('helpBox');

	/*	TODO: Change dummy topicID	*/
	fetchTopic($('helpButton').rel);	/*	pass it off to fetchTopic	*/
	return false;
}

function hideHelp() {

}

/*	FTM legacy code for /grandlodge/dap/dapannualreport.cfm	*/
function UpdateTotalHours(form,rate)
    {
		form.TotalHours.value = (parseFloat(form.ElksHours.value) + parseFloat(form.NonElksHours.value));
		UpdateValueOfHours(form,rate);
 		    return true;
    }	
function UpdateValueOfHours(form, rate)
    {
		form.ValueOfHours.value = (parseFloat(form.TotalHours.value) * (rate));
 		    return true;
    }

function fetchTopic(topicID) {
	var url = '/help/fetchTopic.cfm?HelpItemID=' + topicID;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
			//var helpObject = trim(transport.responseText).evalJSON(true);
			$('spinner').remove();
			$('helpText').update(trim(transport.responseText));
			
			/*	Start assembling update text	*/
			//helpObject.data.lodgenum[0];
		} });
}

function loader() {
	if(window.location.protocol == 'https:') {
		/*	Rewrite links on page to use http	*/
		var links = $$('a');

		links.each( function(link) {
			if(link.href.startsWith('https:') && link.rel != 'secure') {
				var addition = 'http://elks.org';
				link.href = 'http://' + link.href.substr(8, link.href.length);
			}
		});
	}
}

function createListeners() {
	if($('lodgeSubmit') && $('lodgeTable')) {	/*	only attach this event if the element exists on the page	*/
		Event.observe($('lodgeSubmit'), 'click', function() { lodgeLookup($F('lodgeZIP')); return false; });
	}
	/*	Hide an element that doesn't need to be shown yet	*/
	if($('locatorError')) {
		$('locatorError').hide();
	}

	/*	Attach event listeners to everything that uses a mouse event	*/
	/*	Test for existence of elements before adding the handlers	*/
	if($('homeLink') && $('aboutLink') && $('serviceLink') && $('membersLink')) {
		Event.observe($('homeLink'), 'mouseover', function() { cancelGlobalTimer(); startMenuChange('homeLink'); });
		Event.observe($('aboutLink'), 'mouseover', function() { cancelGlobalTimer(); startMenuChange('aboutLink'); });
		Event.observe($('serviceLink'), 'mouseover', function() { cancelGlobalTimer(); startMenuChange('serviceLink'); }); 
		Event.observe($('membersLink'), 'mouseover', function() { cancelGlobalTimer(); startMenuChange('membersLink'); });
	
		Event.observe($('homeLink'), 'mouseout', function() { setGlobalTimer(); stopMenuChange('homeLink'); });
		Event.observe($('aboutLink'), 'mouseout', function() { setGlobalTimer(); stopMenuChange('aboutLink'); });
		Event.observe($('serviceLink'), 'mouseout', function() { setGlobalTimer(); stopMenuChange('serviceLink'); }); 
		Event.observe($('membersLink'), 'mouseout', function() { setGlobalTimer(); stopMenuChange('membersLink'); });
	}

	if($('lodgeDirectory')) {
		/*	OPTIMIZE:	Put highlightable elements in an array and loop through that */
		if($('LodgeName')) {
			Event.observe($('LodgeName'), 'focus', function() { activateLabel('LodgeName'); });
			Event.observe($('LodgeName'), 'blur', function() { deactivateLabel('LodgeName'); });
		}

		if($('State')) {
			Event.observe($('State'), 'focus', function() { activateLabel('State'); });
			Event.observe($('State'), 'blur', function() { deactivateLabel('State'); });
		}

		if($('District')) {
			Event.observe($('District'), 'focus', function() { activateLabel('District'); });
			Event.observe($('District'), 'blur', function() { deactivateLabel('District'); });
		}
	
		if($('SortByName')) {
			Event.observe($('SortByName'), 'focus', function() { activateLabel('SortByName'); });
			Event.observe($('SortByName'), 'blur', function() { deactivateLabel('SortByName'); });
		}

		if($('SortByNumber')) {
			Event.observe($('SortByNumber'), 'focus', function() { activateLabel('SortByNumber'); });
			Event.observe($('SortByNumber'), 'blur', function() { deactivateLabel('SortByNumber'); });
		}
	}

	if($('subNav')) {
		Event.observe($('subNav'), 'mouseover', function() { cancelGlobalTimer(); });
		Event.observe($('subNav'), 'mouseout', function() { setGlobalTimer(); });
	}

	if($('keyword')) {
		Event.observe($('keyword'), 'click', toggleSearch);
		Event.observe($('keyword'), 'blur', toggleSearch);

		if(screen.width <= 800) {
			$('keyword').value = 'Search...';
		}
	}

	if($('nav')) {
		activateBasePage();

		currentPageCheck();
		subMenuCheck();
	}

	if($('expandAlert')) {
		Event.observe($('expandAlert'), 'click', expandAlert);
	}

	if($('submit')) {
		//Event.observe($('submit'), 'click', disableSubmit);
	}

	if($('toggleMap')) {
		Event.observe($('toggleMap'), 'click', toggleMap);
	}

	if($('helpButton')) {
		if($('helpButton').rel != 'Popup') {
		Event.observe($('helpButton'), 'click', showHelp);
		}
	}

/*	Configuration snooping	*/
	if($('screenX')) { $('screenX').value = screen.width; }
	if($('screenY')) { $('screenY').value = screen.height; }
	if($('userAgent')) { $('userAgent').value = navigator.userAgent; }


	if($('browser')) { $('browser').update(navigator.userAgent); }
	if($('screen_res')) { $('screen_res').update(screen.width + 'x' + screen.height); }

	var screenSize = document.viewport.getDimensions();

	if($('window_size')) { $('window_size').update(screenSize['width'] + 'x' + screenSize['height']); }


  /*Event.observe(document, 'click', getMouseCoords);*/

}
//Event.observe(window, 'load', function() { roundCorners(); createListeners(); createTip(); });
Event.observe(document, 'dom:loaded', function() { widenContent(); hideElements(); roundCorners(); createMap(); createListeners(); createTip(); loader(); checkVHPMenu(); });