
function makeCommentFormAppear() {
	if (document.getElementById("community_post_form")) {
		document.getElementById("community_post_form").style.display = 'block'; 
	}	
	if (document.getElementById("logout")) {
		document.getElementById("logout").style.display = 'none'; 
	}	
	if (document.getElementById("login")) {
		document.getElementById("login").className = 'comments'; 
	}	
	return false;
}




function makeGratitudeFormAppear() {
	if (document.getElementById("gratitudes")) {	
		if (document.getElementById("gratitudes_edit")) {
			if (document.getElementById("gratitudes").style.display == 'none') { 
				document.getElementById("gratitudes").style.display = 'block'; 
				document.getElementById("gratitudes_edit").style.display = 'none'; 
				if (document.getElementById("view")) document.getElementById("view").style.display = 'none'; 
				if (document.getElementById("edit")) document.getElementById("edit").style.display = 'block'; 
			} else {
				document.getElementById("gratitudes").style.display = 'none'; 
				document.getElementById("gratitudes_edit").style.display = 'block'; 				
				if (document.getElementById("view")) document.getElementById("view").style.display = 'block'; 				
				if (document.getElementById("edit")) document.getElementById("edit").style.display = 'none'; 				
			}
		}
	}	
	return false;
}





function makeFavoritesAppear() {
	if (document.getElementById("favorites")) {	
		if (document.getElementById("favorites_edit")) {
			if (document.getElementById("favorites").style.display == 'none') { 
				document.getElementById("favorites").style.display = 'block'; 
				document.getElementById("favorites_edit").style.display = 'none'; 
				if (document.getElementById("view1")) document.getElementById("view1").style.display = 'none'; 
				if (document.getElementById("edit1")) document.getElementById("edit1").style.display = 'block'; 
			} else {
				document.getElementById("favorites").style.display = 'none'; 
				document.getElementById("favorites_edit").style.display = 'block'; 				
				if (document.getElementById("view1")) document.getElementById("view1").style.display = 'block'; 				
				if (document.getElementById("edit1")) document.getElementById("edit1").style.display = 'none'; 				
			}
		}
	}	
	return false;
}










addLoadEvent(function() {
	// 09-08-07 - TSR pointed out to me that the category name was remaining visible, after
	// the cursor had moused out of the form that posts to the sharing wall. This is fairly confusing,
	// as it shows the last thing moused over, instead of the choosen category (if any). In the long
	// term, this should be set to the selected category. In the short term, lets just set it to 
	// nothing, when someone mouses out of the commnity_post_form. 
	if (document.getElementById("community_post_form")) {
		var referenceToSharingWallForm = document.getElementById("community_post_form"); 
		referenceToSharingWallForm.onmouseout = function() {
			if (document.getElementById("visible_category_text")) {
				var referenceToSpanThatShowsCategoryName = document.getElementById("visible_category_text");	
				referenceToSpanThatShowsCategoryName.innerHTML = ""; 
			}
		}
	}	
});








function replaceCommunityPostOnSharingWall(numberOfItem) {
	// 09-10-07 - you might be wondering why this function is so crazy complicated. 
	// Turns out I could not simply use the Ajax.Updater method of the Prototype
	// library, as it was having a conflict with the lightbox script that we are
	// using. Specifically, each new link needs to be initialized through the 
	// initialize() method of the Lightbox object. The lightbox script does this
	// for us when the page first loads, but after that, if we load new links
	// onto the page, we have to initialize each one. That is why we are using
	// Ajax.Request. We then create a closure so that some of the information
	// made available to this function can be remembered till the Ajax call
	// returns. 
	//
	//
	// 11-24-07 - it turns out the above comment was wholly wrong. The lightbox
	// script began to fail because I was an idiot and had HTML that was referencing
	// boxes that had not yet appeared on the Sharing Wall, or was referencing them 
	// after they had ceased to exist. However, it is possible this function still
	// does something, so I won't delete it just yet. 
	
	idOfItemToBeReplaced = "sharingWall" + numberOfItem;
	
	if (document.getElementById(idOfItemToBeReplaced)) {
		var url = 'api.php';
		var pars = 'choiceMade[]=showRandomCommunityPost';
		pars += '&rowId=' + numberOfItem;
		pars += '&PHPSESSID=' + sessionId;
			
		var showNewPostOnSharingWall = function (originalRequest) {
			var newHtmlForTheSharingWall = originalRequest.responseText;
			document.getElementById(idOfItemToBeReplaced).innerHTML = newHtmlForTheSharingWall;	
				
			var idOfThisLink = "lightboxLink" + numberOfItem; 
			var thisNewBoxShouldBecomeALightbox = document.getElementById(idOfThisLink); 
			valid = new lightbox(thisNewBoxShouldBecomeALightbox);
		}
	}

	var myAjax = new Ajax.Request(
		  url,
		  {method: 'get', parameters: pars, onComplete: showNewPostOnSharingWall}
	);
}









addLoadEvent(function() {
	// 09-08-07 - a crucial idea is that the community posts which appear on the sharing
	// wall will fade in and out. We need this to be staggered. To do this, we need to 
	// set up 6 timers, using setInterval(), for each of the 6 posts on the sharing wall.
	// We need for these timers to be staggered, that is, they can't fade out and 
	// replace their contents all at once. To stagger them, we will use setTimeout
	// to stagger the initial call to replaceCommunityPostOnSharingWall(). We are
	// using closures for everything because we have information (the ids of the 
	// posts to be replaced) that needs to preserved into the future.
	
	var sharingWallFunction1 = function() {
		var functionToActuallyReplaceSharingWallPosts = function() {
			replaceCommunityPostOnSharingWall("1");
		}		
		setInterval(functionToActuallyReplaceSharingWallPosts, 16000);
	}
	setTimeout(sharingWallFunction1, 1);
	
	
	var sharingWallFunction2 = function() {
		var functionToActuallyReplaceSharingWallPosts = function() {
			replaceCommunityPostOnSharingWall("2");
		}		
		setInterval(functionToActuallyReplaceSharingWallPosts, 16000)		
	}
	setTimeout(sharingWallFunction2, 6000);
	
	
	var sharingWallFunction3 = function() {
		var functionToActuallyReplaceSharingWallPosts = function() {
			replaceCommunityPostOnSharingWall("3");
		}		
		setInterval(functionToActuallyReplaceSharingWallPosts, 16000)		
	}
	setTimeout(sharingWallFunction3, 12000);
	
	
	var sharingWallFunction4 = function() {
		var functionToActuallyReplaceSharingWallPosts = function() {
			replaceCommunityPostOnSharingWall("4");
		}		
		setInterval(functionToActuallyReplaceSharingWallPosts, 16000)		
	}
	setTimeout(sharingWallFunction4, 18000);
	
	
	var sharingWallFunction5 = function() {
		var functionToActuallyReplaceSharingWallPosts = function() {
			replaceCommunityPostOnSharingWall("5");
		}		
		setInterval(functionToActuallyReplaceSharingWallPosts, 16000)		
	}
	setTimeout(sharingWallFunction5, 24000);
	
	
	var sharingWallFunction6 = function() {
		var functionToActuallyReplaceSharingWallPosts = function() {
			replaceCommunityPostOnSharingWall("6");
		}		
		setInterval(functionToActuallyReplaceSharingWallPosts, 16000)		
	}
	setTimeout(sharingWallFunction6, 30000);
	


});





addLoadEvent(function() {
	// 09-19-07 - this next block is for this page: 
	//
	// http://www.thesecondroad.org/profile.php?formName=view_my_private_journal.htm
	//
	// This is for the 5 buttons along the top, which have these for HTML ids: 
	//
	//	"my_story_link_rollover"
	//	"posts_link_rollover" 
	//	"journal_link_rollover"
	//	"groups_link_rollover"
	//	"photos_link_rollover"
	//	
	// Lark wants one of these to be on rollover status if we happen to be on the page
	// the link links to. 


	// we will start by getting the actual page the user is on. 
	var actualUrl = document.location.href; 

	// the image and rollover image are just background-images for the 
	// link, so that is all we need to change
	if (document.getElementById("my_story_link_rollover")) {
		var refToLink = document.getElementById("my_story_link_rollover")
		var hrefOfLink = refToLink.href; 
		if (actualUrl.indexOf(hrefOfLink) != -1) {
			refToLink.style.backgroundImage = "url(../graphics/my_story_green.gif)";
		}
	}

	if (document.getElementById("posts_link_rollover")) {
		var refToLink = document.getElementById("posts_link_rollover")
		var hrefOfLink = refToLink.href; 
		if (actualUrl.indexOf(hrefOfLink) != -1) {
			refToLink.style.backgroundImage = "url(../graphics/posts_green.gif)";
		}
	}

	if (document.getElementById("journal_link_rollover")) {
		var refToLink = document.getElementById("journal_link_rollover")
		var hrefOfLink = refToLink.href; 
		if (actualUrl.indexOf(hrefOfLink) != -1) {
			refToLink.style.backgroundImage = "url(../graphics/journal_green.gif)";
		}
	}

	if (document.getElementById("groups_link_rollover")) {
		var refToLink = document.getElementById("groups_link_rollover")
		var hrefOfLink = refToLink.href; 
		if (actualUrl.indexOf(hrefOfLink) != -1) {
			refToLink.style.backgroundImage = "url(../graphics/groups_green.gif)";
		}
	}

	if (document.getElementById("photos_link_rollover")) {
		var refToLink = document.getElementById("photos_link_rollover")
		var hrefOfLink = refToLink.href; 
		if (actualUrl.indexOf(hrefOfLink) != -1) {
			refToLink.style.backgroundImage = "url(../graphics/photos_green.gif)";
		}
	}



	// 09-19-07 - what happens when you first arrive on the "My Page"?
	if (document.getElementById("journal_link_rollover")) {
		var refToLink = document.getElementById("journal_link_rollover")
		var hrefOfLink = refToLink.href; 
		if (actualUrl.indexOf("view_my_private_journal.htm") != -1) {
			refToLink.style.backgroundImage = "url(../graphics/journal_green.gif)";
		}
	}
	
	
	// 09-19-07 - what happens when you first arrive on the public journal page?
	if (document.getElementById("journal_link_rollover")) {
		var refToLink = document.getElementById("journal_link_rollover")
		var hrefOfLink = refToLink.href; 
		if (actualUrl.indexOf("view_my_public_journal.htm") != -1) {
			refToLink.style.backgroundImage = "url(../graphics/journal_green.gif)";
		}
	}
});







/*

10-30-07 - we must try to add lots of sponsors to the map from within the PHP code, I think, 
	so I'm taking this bit out. 
	
addLoadEvent(function() {
	// 09-20-07 - this is to trigger the Google code on sponsors.php

	
	var first_name = ""; 
	var last_name = "The Second Road";
	var street = ""; 
	var city = "Charlottesville"; 
	var region = "VA"; 
	var regional_code = "22902";
	var country = "US"; 
	var aas_description = "Our home! Well, we placed ourselves <br />in our whole town because we wanted the<br /> world to see where we're all from.<br /> Let us see where you're from <br />now... ";
	
	if (typeof showSponsor != 'undefined') showSponsor(first_name, last_name, street, city, region, regional_code, country, aas_description);
	
});


*/
















function getElementsByClass(searchClass,node,tag) {
	// 10-07-07 - this function is from here:
	//
	// http://www.dustindiaz.com/getelementsbyclass/
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}





function expandThisDivWithContent(i) {
	// 10-07-07 - assigned to the onclick event of divs that are given the 
	// CSS class of "more". See the call to addLoadEvent below. 

	var idOfLinkMakingThisCall = arrayOfLinksAndIds[i];
	alert(idOfLinkMakingThisCall);
	if (document.getElementById(idOfLinkMakingThisCall)) {
		var referenceToALinkWhichHasTheClassOfMore = document.getElementById(idOfLinkMakingThisCall);
		var idOfDivToBeAffected = referenceToALinkWhichHasTheClassOfMore.getAttribute("rel"); 	
		var refToDiv = document.getElementById(idOfDivToBeAffected); 

		if (refToDiv.style.height == "auto") {
			refToDiv.style.height = "250px"; 
		} else {
			refToDiv.style.height = "auto"; 
		}
	}
	return false; 
}



/*


10-14-07 - couldn't get it right, trying again below.
			
			addLoadEvent(function() {
				// 10-07-07 - Laura wants to fit a lot of content onto the profile.php page. 
				// She intends for each section to have a small box (I mean a div) and when 
				// these boxes fill up, the PHP code will ensure a "more" button appears at the
				// end. All these divs have a fixed height assigned by the CSS, but when the
				// "more" button is clicked, the div should have height:auto, and an AJAX 
				// call should fill it. The "more" buttons will all have a class of "more", 
				// and their rel attributes will indicate which div we need to resize and fill. 
			
			
				var arrayOfAllLinksWithTheClassOfMore = getElementsByClass("more"); 
			
				for (var i=0; i < arrayOfAllLinksWithTheClassOfMore.length; i++) {
					var referenceToALinkWhichHasTheClassOfMore = arrayOfAllLinksWithTheClassOfMore[i];
					var idOfLinkMakingThisCall = referenceToALinkWhichHasTheClassOfMore.id; 
								
					var functionThatReturnsId = function() {
						return idOfLinkMakingThisCall;
					}
					
					referenceToALinkWhichHasTheClassOfMore.onclick = function() {
						var idOfLink = functionThatReturnsId();
						
						var idOfDivToBeAffected = document.getElementById(idOfLink).getAttribute("rel"); 	
						var refToDiv = document.getElementById(idOfDivToBeAffected); 
							
			//			alert(idOfDivToBeAffected);
						
						if (refToDiv.style.height == "auto") {
							refToDiv.style.height = "2500px"; 
						} else {
							refToDiv.style.height = "10px"; 
						}
					
						return false; 
					}
					
			//		alert(referenceToALinkWhichHasTheClassOfMore.onclick);
				}
				return false; 
			});


*/







addLoadEvent(function() {
	// 10-07-07 - Laura wants to fit a lot of content onto the profile.php page. 
	// She intends for each section to have a small box (I mean a div) and when 
	// these boxes fill up, the PHP code will ensure a "more" button appears at the
	// end. All these divs have a fixed height assigned by the CSS, but when the
	// "more" button is clicked, the div should have height:auto, and an AJAX 
	// call should fill it. The "more" buttons will all have a class of "more", 
	// and their rel attributes will indicate which div we need to resize and fill. 
	//
	//
	// 10-14-07 - got advice on comp.lang.javascript, visible here: 
	//
	// http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/524045c33ddc9913/8853ececf11d7ca3#8853ececf11d7ca3
	//
	//
	// David Mark suggests the following: 
	//
	//	
	//				How about something like this:
	//					
	//					referenceToALinkWhichHasTheClassOfMore.onclick =
	//					function() {
	//					                         var idOfDivToBeAffected =
	//					 this.getAttribute("rel");
	//					                         var refToDiv =
	//					document.getElementById(idOfDivToBeAffected);
	//					
	//					                         alert(idOfDivToBeAffected);
	//					
	//					...
	//					
	//					And when the loop ends, set referenceToALinkWhichHasTheClassOfMore
	//					(and the array) to null.  Alternatively, move the onclick handler
	//					function outside the load function as you don't need to create
	//					closures. 
	// 
	// 
	// 
	// 
	// 10-22-07 - I'm really not as smart as I look. The original code, from 10-07-07, worked
	// wonderfully when you were logged into your own page. However, if you go to someone
	// else's public page and click "more", you end up seeing your own content, because the 
	// content is being fetched for YOU, the logged in member, using your session id. I'm 
	// going to have to write completely separate code for the public pages, and I'm going
	// to rely on them using a different CSS class: more_public. 
	// 
	// 
	// 
	// 

	var arrayOfAllLinksWithTheClassOfMore = getElementsByClass("more"); 

	for (var i=0; i < arrayOfAllLinksWithTheClassOfMore.length; i++) {
		var referenceToALinkWhichHasTheClassOfMore = null; 
		referenceToALinkWhichHasTheClassOfMore = arrayOfAllLinksWithTheClassOfMore[i];
		var idOfLinkMakingThisCall = referenceToALinkWhichHasTheClassOfMore.id; 
					
		var functionThatReturnsId = function() {
			return idOfLinkMakingThisCall;
		}
		
		referenceToALinkWhichHasTheClassOfMore.onclick = function() {
			var idOfDivToBeAffected = this.getAttribute("rel");
			var refToDiv = document.getElementById(idOfDivToBeAffected);
			
			if (refToDiv.title == "full") {
				refToDiv.setAttribute("title", "short"); 

				if (idOfDivToBeAffected == "my_story") {		
					var textForMyStory = document.getElementById("my_story").innerHTML;
					document.getElementById("my_story").innerHTML = null;
					for (var i=0; i <  textForMyStory.length && i < 400; i++) {
						document.getElementById("my_story").innerHTML += textForMyStory[i]; 
					}				
					refToDiv.style.height = "200px"; 	
				}
				
				if (idOfDivToBeAffected == "fave_quote") {							
					var textForMyStory = document.getElementById("fave_quote").innerHTML;
					document.getElementById("fave_quote").innerHTML = null;
					for (var i=0; i <  textForMyStory.length && i < 100; i++) {
						document.getElementById("fave_quote").innerHTML += textForMyStory[i]; 
					}
					refToDiv.title = "short"; 
					refToDiv.style.height = "50px"; 	
				}
				
				if (idOfDivToBeAffected == "journal") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getAllFromTableForThisFieldForThisUser';
					pars += '&whichTable=user_private_journal';
					pars += '&whichField=*';
					pars += '&whichArrangement=user_private_journal_list_each.htm';
					pars += '&limit=3';
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'journal';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});

					refToDiv.title = "short"; 											
					refToDiv.style.height = "200px"; 	
				}
			} else {
				refToDiv.style.height = "auto"; 
				refToDiv.setAttribute("title", "full"); 
				
				if (idOfDivToBeAffected == "my_story") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getAllFromTableForThisFieldForThisUser';
					pars += '&whichTable=users';
					pars += '&whichField=description';
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'my_story';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
				}
				
				if (idOfDivToBeAffected == "fave_quote") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getAllFromTableForThisFieldForThisUser';
					pars += '&whichTable=users';
					pars += '&whichField=my_fave_quote';
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'fave_quote';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
				}
				
				if (idOfDivToBeAffected == "journal") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getAllFromTableForThisFieldForThisUser';
					pars += '&whichTable=user_private_journal';
					pars += '&whichField=*';
					pars += '&whichArrangement=user_private_journal_list_full.htm';
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'journal';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
				}
				
				if (idOfDivToBeAffected == "posts") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getFavoriteCommunityPostsForThisUser';
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'posts';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
				}
				
				if (idOfDivToBeAffected == "my_posts") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getAllFromTableForThisFieldForThisUser';
					pars += '&whichTable=community_post';
					pars += '&whichField=*';
					pars += '&whichArrangement=community_post_list_each_public_interior.htm';
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'my_posts';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
				}
				
				
				
				if (idOfDivToBeAffected == "gratitude") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getGratitudeList';
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'gratitude';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
				}
				
				
				
			}
		
			
			return false; 
		}
	}
	return false; 
});












addLoadEvent(function() {
	// 10-22-07 - most of this is explained in the fuction above, where
	// the onclick event handler is set for all links that have the 
	// class of "more". Laura Denyes wants something similar to happen
	// on the public pages, but here we have to enforce more security
	// checks, so we will write similar code for a different CSS
	// class: more_public. The idea is to find every link with the class
	// of more_public and get more info that can go into the related 
	// div, using an Ajax call. The related div is specified in the rel
	// tag of the link. 


	var arrayOfAllLinksWithTheClassOfMore = getElementsByClass("more_public"); 

	for (var i=0; i < arrayOfAllLinksWithTheClassOfMore.length; i++) {
		var referenceToALinkWhichHasTheClassOfMore = null; 
		referenceToALinkWhichHasTheClassOfMore = arrayOfAllLinksWithTheClassOfMore[i];
		var idOfLinkMakingThisCall = referenceToALinkWhichHasTheClassOfMore.id; 
					
		var functionThatReturnsId = function() {
			return idOfLinkMakingThisCall;
		}
		
		referenceToALinkWhichHasTheClassOfMore.onclick = function() {
			var idOfDivToBeAffected = this.getAttribute("rel");
			var refToDiv = document.getElementById(idOfDivToBeAffected);
			
			if (refToDiv.title == "full") {
				refToDiv.setAttribute("title", "short"); 

				if (idOfDivToBeAffected == "my_story") {		
					var textForMyStory = document.getElementById("my_story").innerHTML;
					document.getElementById("my_story").innerHTML = null;
					for (var i=0; i <  textForMyStory.length && i < 400; i++) {
						document.getElementById("my_story").innerHTML += textForMyStory[i]; 
					}				
					refToDiv.style.height = "200px"; 	
				}
				
				if (idOfDivToBeAffected == "fave_quote") {							
					var textForMyStory = document.getElementById("fave_quote").innerHTML;
					document.getElementById("fave_quote").innerHTML = null;
					for (var i=0; i <  textForMyStory.length && i < 100; i++) {
						document.getElementById("fave_quote").innerHTML += textForMyStory[i]; 
					}
					refToDiv.title = "short"; 
					refToDiv.style.height = "50px"; 	
				}
				
				if (idOfDivToBeAffected == "journal") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getAllFromTableForThisFieldForThePublic';
					pars += '&whichTable=user_private_journal';
					pars += '&whichField=*';
					pars += '&whichArrangement=user_private_journal_list_each.htm';
					pars += '&limit=3';
					pars += '&location=' + location.href;
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'journal';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});

					refToDiv.title = "short"; 											
					refToDiv.style.height = "200px"; 	
				}
			} else {
				refToDiv.style.height = "auto"; 
				refToDiv.setAttribute("title", "full"); 

				// 10-22-07 - apparently, location.href gives the whole URL.
				//
				// This: 
				//
				// alert(location.href); 
				//
				// gives this: 
				//
				// http://www.teamlalala.com/tsr/profile_public.php?id=11
				//
				// So we could pass this whole thing along to the PHP script and figure 
				// it out there, especially since splicing up a URL is a little easier in PHP.
				// No regex needed. 
				
				if (idOfDivToBeAffected == "my_story") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getAllFromTableForThisFieldForThePublic';
					pars += '&whichTable=users';
					pars += '&whichField=description';
					pars += '&location=' + location.href;
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'my_story';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
				}
				
				if (idOfDivToBeAffected == "fave_quote") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getAllFromTableForThisFieldForThePublic';
					pars += '&whichTable=users';
					pars += '&whichField=my_fave_quote';
					pars += '&location=' + location.href;
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'fave_quote';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
				}
				
				if (idOfDivToBeAffected == "journal") {		
					var url = 'api.php';
					var pars = 'choiceMade[]=getAllFromTableForThisFieldForThePublic';
					pars += '&whichTable=user_private_journal';
					pars += '&whichField=*';
					pars += '&whichArrangement=user_private_journal_list_full.htm';
					pars += '&location=' + location.href;
					pars += '&PHPSESSIONID=' + sessionId;
					var target = 'journal';	
					var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
				}
			}
			return false; 
		}
	}
	return false; 
});










function loadNewVideo(nameOfVideo) {
	// 10-13-07 - this is a replacement for all the code that Cameron wrote. This 
	// makes a video appear in the video player, when you click on an image. 
	if (document.getElementById("video_player") || document.getElementById("video_player2")) {	
		var flashString = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='322' height='241' id='tsrPlayer' align='middle'>";
	flashString += "<param name='allowScriptAccess' value='sameDomain' />";
	flashString += "<param name='allowFullScreen' value='true' />";
	flashString += "<param name='movie' value='tsrPlayer.swf?movie=site_specific_files/" + nameOfVideo + "' />";
	flashString += "<param name='quality' value='high' />";
	flashString += "<param name='bgcolor' value='#ffffff' />";
	flashString += "<embed src='tsrPlayer.swf?movie=site_specific_files/" + nameOfVideo + "' quality='high' bgcolor='#ffffff' width='322' height='241' name='tsrPlayer' align='middle' allowScriptAccess='sameDomain' allowFullScreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'  />";
	flashString += "</object>";
		
		
		
		if (document.getElementById("video_player")) document.getElementById("video_player").innerHTML = flashString; 
		if (document.getElementById("video_player2")) document.getElementById("video_player2").innerHTML = flashString; 
	
	}
	return false; 
}











var globalCounterForMeasuringTheAdvanceOfVideos = 6; 

function rewindToPreviousVideo() {
	// 10-14-07 - this will be used on the front page of wwww.thesecondroad.org. This gets a
	// the HTML that will allow a video to be loaded. Since the current design shows 3 videos
	// at a time, in two strips, we will update all 6 videos. That is, we will update the 
	// 2 strips. We will use Ajax to get the new HTML that we need. The 2 divs that we need
	// to update are "l_carousel" and "r_carousel". We will use the global variable 
	// globalCounterForMeasuringTheAdvanceOfVideos to keep track of how many times we've advanced
	// the videos. 
	
	
	globalCounterForMeasuringTheAdvanceOfVideos = globalCounterForMeasuringTheAdvanceOfVideos - 1; 
	if (globalCounterForMeasuringTheAdvanceOfVideos < 0) globalCounterForMeasuringTheAdvanceOfVideos = 0;  

	if (document.getElementById("firstVideoGroup")) {	
		var url = 'api.php';
		var pars = 'choiceMade[]=showVideoIcons';
		pars += '&oddOrEven=odd';
		pars += '&start=' + globalCounterForMeasuringTheAdvanceOfVideos;
		pars += '&limit=6';
		var target = 'firstVideoGroup';	
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
	}
		
	if (document.getElementById("secondVideoGroup")) {	
		var url = 'api.php';
		var pars = 'choiceMade[]=showVideoIcons';
		pars += '&oddOrEven=even';
		pars += '&start=' + globalCounterForMeasuringTheAdvanceOfVideos;
		pars += '&limit=6';
		var target = 'secondVideoGroup';	
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
	}
	
	return false; 
}


function advanceToNextVideo() {
	// 10-14-07 - this will be used on the front page of wwww.thesecondroad.org. This gets a
	// the HTML that will allow a video to be loaded. Since the current design shows 3 videos
	// at a time, in two strips, we will update all 6 videos. That is, we will update the 
	// 2 strips. We will use Ajax to get the new HTML that we need. The 2 divs that we need
	// to update are "l_carousel" and "r_carousel". We will use the global variable 
	// globalCounterForMeasuringTheAdvanceOfVideos to keep track of how many times we've advanced
	// the videos. 
	
	globalCounterForMeasuringTheAdvanceOfVideos = globalCounterForMeasuringTheAdvanceOfVideos + 1; 
	
	// 10-14-07 - howManyVideosAreThere is a global variable set in header.php, it is set by a PHP script
	// that checks the database to see how many videos there are. 
	if (globalCounterForMeasuringTheAdvanceOfVideos + 6 > howManyVideosAreThere) globalCounterForMeasuringTheAdvanceOfVideos = howManyVideosAreThere - 6;
	
	
	if (document.getElementById("firstVideoGroup")) {	
		var url = 'api.php';
		var pars = 'choiceMade[]=showVideoIcons';
		pars += '&oddOrEven=odd';
		pars += '&start=' + globalCounterForMeasuringTheAdvanceOfVideos;
		pars += '&limit=6';
		var target = 'firstVideoGroup';	
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
	}
		
	if (document.getElementById("secondVideoGroup")) {	
		var url = 'api.php';
		var pars = 'choiceMade[]=showVideoIcons';
		pars += '&oddOrEven=even';
		pars += '&start=' + globalCounterForMeasuringTheAdvanceOfVideos;
		pars += '&limit=6';
		var target = 'secondVideoGroup';	
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
	}
	
	return false; 	
}
	
	
	
	
addLoadEvent(function() {	
	/*
	
		10-13-07 - we've got to write Javascript that allows these next and previous buttons to delete one of these video icons and
			replace it with another. This is on the front page of www.secondroad.org. This is the HTML we are dealing with:
	
				<div class="title">recovery videos
					<br class="clearleft" />
					<div id="l_carousel" class="mycarousel">
						<a title="Maxine" href="#" onclick="loadNewVideo('Maxine-A-Message-of-Hope.flv');" class="list-item-image"><img src="site_specific_files/maxine.gif" alt="Maxine" /></a> <br />
						<a title="Andrew" href="#" onclick="loadNewVideo('andrew-texas-teens.flv');" class="list-item-image"><img src="site_specific_files/andrew.gif" alt="Andrew" /></a> <br />
						<a title="Henry" href="#" onclick="loadNewVideo('Henry-Lozano.flv');" class="list-item-image"><img src="site_specific_files/henry.gif" alt="Henry" /></a> <br />
			
										
						<a id="carousel_prev" href="">prev</a>
					</div>
					<div id="video_player">	
						<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab// - version=7,0,0,0" width="320" height="255" name="ba211192299404937" id="ba211192299404937">
						<param name="movie" value="ba21.swf?theFile=site_specific_files/promo_320x240.flv&popUpHelp=no&defaultImage=site_specific_files/video_play.jpg" />
						<param name="loop" value="false" />
						<param name="menu" value="false" />
						<param name="quality" value="high" />
						<param name="scale" value="noscale" />
			
						<param name="salign" value="lt" />
						<param name="bgcolor" value="#FFFFFF" />
						<param name="flashvars" value="lcId=ba211192299404937"/><embed src="ba21.swf?theFile=site_specific_files/promo_320x240.flv&popUpHelp=no&defaultImage=site_specific_files/video_play.jpg" width="320" height="255" bgcolor="#FFFFFF" loop="false" menu="false" quality="high" scale="noscale" salign="lt" id="ba211192299404938" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="lcId=ba211192299404937" /></object>
					</div>
					<div id="r_carousel" class="mycarousel">
						<a title="Rachel" href="#" onclick="loadNewVideo('Rachel-Intro-Adoption-DUI.flv');" class="list-item-image"><img src="site_specific_files/rachel.gif" alt="Rachel" /></a> <br />
						<a title="Marvin" href="#" onclick="loadNewVideo('marvin_amends.flv');" class="list-item-image"><img src="site_specific_files/marvin_amends.gif" alt="Marvin" /></a> <br />
						<a title="Olivia" href="#" onclick="loadNewVideo('Olivia_320x240.flv');" class="list-item-image"><img src="site_specific_files/olivia.jpg" alt="Olivia" /></a> <br />
			
										
						<a class="fr" id="carousel_next" href="">next</a>
					</div>
				</div>
					
	*/
	
	if (document.getElementById("carousel_prev")) {
		var refToLink = document.getElementById("carousel_prev"); 
		refToLink.onclick = function() {
			// 12-08-07 - it's been requested that all 6 images change, if possible.
			rewindToPreviousVideo(); 
			rewindToPreviousVideo(); 
			rewindToPreviousVideo(); 
			rewindToPreviousVideo(); 
			rewindToPreviousVideo(); 
			rewindToPreviousVideo(); 
			return false; 
		}
	}
	
	
	if (document.getElementById("carousel_next")) {
		var refToLink = document.getElementById("carousel_next"); 
		refToLink.onclick = function() {
			// 12-08-07 - it's been requested that all 6 images change, if possible.
			advanceToNextVideo(); 
			advanceToNextVideo(); 
			advanceToNextVideo(); 
			advanceToNextVideo(); 
			advanceToNextVideo(); 
			advanceToNextVideo(); 
			return false; 
		}
	}
});








function showHide(idOfDiv) {
	// 10-23-07 - common function for toggling visibility of a div
	
	
	if (document.getElementById(idOfDiv)) {
		var refToDiv = document.getElementById(idOfDiv); 
		
		if (refToDiv.style.display == "none") {
			refToDiv.style.display = "block";
		} else {
			refToDiv.style.display = "none";
		}
	}
	
	return false;
}


function showDiv(idOfDiv) {
	if (document.getElementById(idOfDiv)) {
		var refToDiv = document.getElementById(idOfDiv); 
		refToDiv.style.display = "block";
	}	
	
	return false;
}


function hideDiv(idOfDiv) {
	if (document.getElementById(idOfDiv)) {
		var refToDiv = document.getElementById(idOfDiv); 
		refToDiv.style.display = "none";
	}	
	
	return false; 
}





























function setClickOnLightboxLinksToMakeVideoInvisible() {
	// 10-29-07 - we have a problem, that on the front page of the site we are
	// using a Lightbox script, but when people click the link that opens the 
	// lightbox, the Flash video player (which is on the front page) shows through the div
	// that holds the lightbox content. So we need to make that Flash player invisible onclick.	

	var arrayOfAllLinksWithTheClassOfLBON = getElementsByClass("lbOn"); 

	for (var i=0; i < arrayOfAllLinksWithTheClassOfLBON.length; i++) {
		var refToLink = arrayOfAllLinksWithTheClassOfLBON[i];
		
		var oldonclick = refToLink.onclick;
		if (typeof refToLink.onclick != 'function') {
			refToLink.onclick = function() {
				if (document.getElementById("video_player")) {
					var refToVideoDiv = document.getElementById("video_player");
					refToVideoDiv.style.visibility = "hidden"; 
				}	
				return false; 
			}
		} else {
			refToLink.onclick = function() {
				if (document.getElementById("video_player")) {
					var refToVideoDiv = document.getElementById("video_player");
					refToVideoDiv.style.visibility = "hidden"; 
				}
			
				if (oldonclick) {
					oldonclick();
				}
				return false; 
			}

		}
	}	
	
	return false; 
}



addLoadEvent(function() {	
	setClickOnLightboxLinksToMakeVideoInvisible()
});
setInterval("setClickOnLightboxLinksToMakeVideoInvisible()", 5000);






/*

05-05-08 - um, didn't we figure out a better way to do this? 

Oh, wait, this is for the Lightbox, not the navbar - both have problems with the 
Flash video player.

*/
function makeFlashVideoPlayerVisible() {
	if (document.getElementById("lightbox")) {
		var refToLightboxDiv = document.getElementById("lightbox"); 
//		alert(refToLightboxDiv.style.display);
		if (refToLightboxDiv.style.display != "block") {
			if (document.getElementById("video_player")) {
				var refToVideoPlayer = document.getElementById("video_player"); 
				refToVideoPlayer.style.visibility = "visible"; 
			}
		}
	}	
}

addLoadEvent(function() {
	setInterval("makeFlashVideoPlayerVisible()", 2000);
});




// 10-29-07 - this is to make Google happy on the sponsor.php page
// where we use the Google Map API. 
if (typeof GUnload != "undefined") {
	window.onunload="GUnload()";
}




function deleteThisItem(address) {
	// 01-10-08 - in use for the forms where a user can delete things, such as here:
	//
	// http://www.cyberbitten.com/profile_form.php?id=5&formName=my_story.htm
	//
	// I'm trying to get the link to not work if the user cancels out of it.

	var result = confirm('Are you sure you want to delete this?');

	if (result) {
		window.location = address; 
	} 

	return false; 
}





// 03-13-08 - this is a toggle to be used by makeFlashVideoInvisibleAndReplaceItWithAnImage
// and makeFlashVideoVisibleAgain
var globalVideoStatusBoolean = "visible"; 

function makeFlashVideoInvisibleAndReplaceItWithAnImage() {
	// 03-13-08 - We are having a problem with the Flash video player that is on
	// the front page of www.thesecondroad.org. The drop down menu bar appears behind
	// it. We've created the function makeFlashVideoInvisibleAndReplaceItWithAnImage
	// to make the Flash player invisible. We need to make sure this is triggered
	// whenever a visitor mousesover the nav bar. 

	if (document.getElementById("video_player") || document.getElementById("video_player2")) {
		if (document.getElementById("video_player")) var referenceToVideoDiv = document.getElementById("video_player");
		if (document.getElementById("video_player2")) var referenceToVideoDiv = document.getElementById("video_player2");
		referenceToVideoDiv.innerHTML = "<img id=\"video_play_image\" src=\"/graphics/dummy_vid_player.jpg\" alt=\"Would you like to see a video?\" />";

		globalVideoStatusBoolean = "invisible"; 
	}
}



function makeFlashVideoVisibleAgain() {
	// 03-13-08 - We are having a problem with the Flash video player that is on
	// the front page of www.thesecondroad.org. The drop down menu bar appears behind
	// it. We've created the function makeFlashVideoInvisibleAndReplaceItWithAnImage
	// to make the Flash player invisible. We need to make sure this is triggered
	// whenever a visitor mousesover the nav bar. 
	//
	// 05-25-08 - we need to give Ginger a way to control what video appears on the 
	// front page of the site, so instead of hardcoding the video, it will become a
	// variable. The name of the video is actually set in header_lid.php, in global
	// space. 

	if (globalVideoStatusBoolean == "invisible") {
		if (document.getElementById("video_player") || document.getElementById("video_player2")) {
			var htmlString = ""; 				
			htmlString +=	"<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"322\" height=\"241\" id=\"tsrPlayer\" align=\"middle\">";
			htmlString +=	"<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
			htmlString +=	"<param name=\"allowFullScreen\" value=\"true\" />";
			htmlString +=	"<param name=\"movie\" value=\"tsrPlayer.swf?movie=site_specific_files/" + videoFile  + "\" />";
			htmlString +=	"<param name=\"quality\" value=\"high\" />";
			htmlString +=	"<param name=\"bgcolor\" value=\"#ffffff\" />";
			htmlString +=	"<embed src=\"tsrPlayer.swf?movie=site_specific_files/" + videoFile  + "\" quality=\"high\" bgcolor=\"#ffffff\" width=\"322\" height=\"241\" name=\"tsrPlayer\" align=\"middle\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"  />";
			htmlString +=	"</object>";

			if (document.getElementById("video_player")) var referenceToVideoDiv = document.getElementById("video_player");
			if (document.getElementById("video_player2")) var referenceToVideoDiv = document.getElementById("video_player2");
			referenceToVideoDiv.innerHTML = htmlString;

			globalVideoStatusBoolean = "visible"; 
		}
	}
}






/*

07-31-08 - this is awful. now TSR wants the video back, so I've got to revert the Javascript. 

addLoadEvent(function() {
	// 06-19-08 - taking out all the code below, regarding the navbar and 
	// Flash video player, but adding in something to allow people
	// to override the animation in the "drive in theater" - people 
	// need to be able to watch the videos in full. 
	
	// on click: 
	if (document.getElementById("video_player")) {
		var menuReference = document.getElementById("video_player");
		menuReference.onclick = function() {
			makeFlashVideoVisibleAgain();
		}
	}

	if (document.getElementById("drive_in3")) {
		var menuReference = document.getElementById("drive_in3");
		menuReference.onclick = function() {
			makeFlashVideoVisibleAgain();
		}
	}
}); 

*/

/*

06-19-08 - we're adding in an animation on the front page, in place of the video player
and it lessens the need to make the navbar work correctly with the Flash player, because
the Flash player will be on screen a lot less than before. 


07-31-08 - this is awful. now TSR wants the video back, so I've got to revert the Javascript. 

08-26-08 - hell's bells. now TSR wants the drive in back. Reverting the previous revert.




addLoadEvent(function() {
	// 03-13-08 - We are having a problem with the Flash video player that is on
	// the front page of www.thesecondroad.org. The drop down menu bar appears behind
	// it. We've created the function makeFlashVideoInvisibleAndReplaceItWithAnImage
	// to make the Flash player invisible. We need to make sure this is triggered
	// whenever a visitor mousesover the nav bar. 

	if (document.getElementById("blog_menu_option")) {
		var menuReference = document.getElementById("blog_menu_option");
		menuReference.onmouseover = function() {
			makeFlashVideoInvisibleAndReplaceItWithAnImage();
		}
	}


	if (document.getElementById("my_page_menu_option")) {
		var menuReference = document.getElementById("my_page_menu_option");
		menuReference.onmouseover = function() {
			makeFlashVideoInvisibleAndReplaceItWithAnImage();
		}
	}


	if (document.getElementById("about_us_menu_option")) {
		var menuReference = document.getElementById("about_us_menu_option");
		menuReference.onmouseover = function() {
			makeFlashVideoInvisibleAndReplaceItWithAnImage();
		}
	}


	if (document.getElementById("help_menu_option")) {
		var menuReference = document.getElementById("help_menu_option");
		menuReference.onmouseover = function() {
			makeFlashVideoInvisibleAndReplaceItWithAnImage();
		}
	}


	if (document.getElementById("linkToChatGroups")) {
		var menuReference = document.getElementById("linkToChatGroups");
		menuReference.onmouseover = function() {
			makeFlashVideoInvisibleAndReplaceItWithAnImage();
		}
	}

	if (document.getElementById("communityDropDownMenu")) {
		var menuReference = document.getElementById("communityDropDownMenu");
		menuReference.onmouseover = function() {
			makeFlashVideoInvisibleAndReplaceItWithAnImage();
		}
	}






	
	// make the video visible again: 


	// on mouse over: 
	if (document.getElementById("video_player")) {
		var menuReference = document.getElementById("video_player");
		menuReference.onmouseover = function() {
			makeFlashVideoVisibleAgain();
		}
	}

	if (document.getElementById("video_play_image")) {
		var menuReference = document.getElementById("video_play_image");
		menuReference.onmouseover = function() {
			makeFlashVideoVisibleAgain();
		}
	}

	if (document.getElementById("videoPage")) {
		var menuReference = document.getElementById("videoPage");
		menuReference.onmouseover = function() {
			makeFlashVideoVisibleAgain();
		}
	}



	// on click: 
	if (document.getElementById("video_player")) {
		var menuReference = document.getElementById("video_player");
		menuReference.onclick = function() {
			makeFlashVideoVisibleAgain();
		}
	}

	if (document.getElementById("video_play_image")) {
		var menuReference = document.getElementById("video_play_image");
		menuReference.onclick = function() {
			makeFlashVideoVisibleAgain();
		}
	}
	if (document.getElementById("videoPage")) {
		var menuReference = document.getElementById("videoPage");
		menuReference.onclick = function() {
			makeFlashVideoVisibleAgain();
		}
	}




	if (document.getElementById("watch")) {
		var menuReference = document.getElementById("watch");
		var oldOnClick = menuReference.onmouseover; 
		menuReference.onmouseover = function() {
			makeFlashVideoVisibleAgain();
			if (oldOnClick) {
				oldOnClick(); 
			}
		}
	}
	if (document.getElementById("journal")) {
		var menuReference = document.getElementById("journal");
		var oldOnClick = menuReference.onmouseover; 
		menuReference.onmouseover = function() {
			makeFlashVideoVisibleAgain();
			if (oldOnClick) {
				oldOnClick(); 
			}
		}
	}
	if (document.getElementById("wall")) {
		var menuReference = document.getElementById("wall");
		var oldOnClick = menuReference.onmouseover; 
		menuReference.onmouseover = function() {
			makeFlashVideoVisibleAgain();
			if (oldOnClick) {
				oldOnClick(); 
			}
		}
	}
	if (document.getElementById("write")) {
		var menuReference = document.getElementById("write");
		var oldOnClick = menuReference.onmouseover; 
		menuReference.onmouseover = function() {
			makeFlashVideoVisibleAgain();
			if (oldOnClick) {
				oldOnClick(); 
			}
		}
	}

});


*/


function addAnswersToPossibleAnswersList() {
	// 03-13-08 - we need a function that can easily add more fields to a UL on the
	// the form that allows for additional questions, when the question is of type
	// 'multiple choice', which is to say, in database terms, type "enum". This in
	// use on pages like this:
	//
	// http://www.cyberbitten.com/custom_forms.php?formName=custom_forms.htm&editId=3

	if (document.getElementById("possible_answers")) {
		var newInput = document.createElement("input");	
		newInput.id = "possible_answer[]";
		newInput.type = "text"; 

		var newListItem = document.createElement("li");
		newListItem.appendChild(newInput);	

		var referenceToAnswersList = document.getElementById("possible_answers"); 
		referenceToAnswersList.appendChild(newListItem);
	}

	return false; 
}







blogFeatureFlip = 1; 
function flipTheBlogFeatureSign() {
	// 03-21-08 - if you go to the front of the TSR site
	// you'll see a sign, it looks like a traffic sign or
	// a billboard, and it features a blog post. There are
	// suppose to be 2 stories that share the same space.
	// We need a Javascript function that toggle between
	// these two divs. 

	if (document.getElementById("blog_entry")) {
		blogFeatureFlip = blogFeatureFlip + 1; 
		if (blogFeatureFlip > 8) blogFeatureFlip = 1; 
		if (blogFeatureFlip < 1) blogFeatureFlip = 8;


		var refToBlogEntry = document.getElementById("blog_entry");
		refToBlogEntry.style.display = "none"; 

		// 04-13-08 - we've been asked to make all 8 blogs rotate through on the
		// front page, so I'm changing this code to work with a number. 

		if (document.getElementById("blog_flip1")) var refToBlogFlip1 = document.getElementById("blog_flip1");
		if (document.getElementById("blog_flip2")) var refToBlogFlip2 = document.getElementById("blog_flip2");
		if (document.getElementById("blog_flip3")) var refToBlogFlip3 = document.getElementById("blog_flip3");
		if (document.getElementById("blog_flip4")) var refToBlogFlip4 = document.getElementById("blog_flip4");
		if (document.getElementById("blog_flip5")) var refToBlogFlip5 = document.getElementById("blog_flip5");
		if (document.getElementById("blog_flip6")) var refToBlogFlip6 = document.getElementById("blog_flip6");
		if (document.getElementById("blog_flip7")) var refToBlogFlip7 = document.getElementById("blog_flip7");

		if (document.getElementById("blog_flip1")) refToBlogFlip1.style.display = "none";  
		if (document.getElementById("blog_flip2")) refToBlogFlip2.style.display = "none";  
		if (document.getElementById("blog_flip3")) refToBlogFlip3.style.display = "none"; 
		if (document.getElementById("blog_flip4")) refToBlogFlip4.style.display = "none"; 
		if (document.getElementById("blog_flip5")) refToBlogFlip5.style.display = "none"; 
		if (document.getElementById("blog_flip6")) refToBlogFlip6.style.display = "none"; 
		if (document.getElementById("blog_flip7")) refToBlogFlip7.style.display = "none"; 

		if (blogFeatureFlip == 1) {
			refToBlogEntry.style.display = "block";
		} 

		if (blogFeatureFlip == 2) {
			if (document.getElementById("blog_flip1")) refToBlogFlip1.style.display = "block";
		} 

		if (blogFeatureFlip == 3) {
			if (document.getElementById("blog_flip2")) refToBlogFlip2.style.display = "block";
		} 

		if (blogFeatureFlip == 4) {
			if (document.getElementById("blog_flip3")) refToBlogFlip3.style.display = "block";
		} 

		if (blogFeatureFlip == 5) {
			if (document.getElementById("blog_flip4")) refToBlogFlip4.style.display = "block";
		} 

		if (blogFeatureFlip == 6) {
			if (document.getElementById("blog_flip5")) refToBlogFlip5.style.display = "block";
		} 

		if (blogFeatureFlip == 7) {
			if (document.getElementById("blog_flip6")) refToBlogFlip6.style.display = "block";
		} 

		if (blogFeatureFlip == 8) {
			if (document.getElementById("blog_flip7")) refToBlogFlip7.style.display = "block";
		} 

	}
}

addLoadEvent(function() {
	flipTheBlogFeaturesSignTimer = setInterval("flipTheBlogFeatureSign()", 9000); 
});



addLoadEvent(function() {
	// 04-13-08 - on the front page of TSR, we are now going to rotate 
	// through a feature, on the image of a sign, of all 8 blogs. We are
	// also going to offer a previous and next button, so people can 
	// advance through the features themselves. 

	if (document.getElementById("blog_feature_prev1")) document.getElementById("blog_feature_prev1").onclick = function() { previousBlogFeature(); return false; }
	if (document.getElementById("blog_feature_prev2")) document.getElementById("blog_feature_prev2").onclick = function() { previousBlogFeature(); return false; }
	if (document.getElementById("blog_feature_prev3")) document.getElementById("blog_feature_prev3").onclick = function() { previousBlogFeature(); return false; }
	if (document.getElementById("blog_feature_prev4")) document.getElementById("blog_feature_prev4").onclick = function() { previousBlogFeature(); return false; }
	if (document.getElementById("blog_feature_prev5")) document.getElementById("blog_feature_prev5").onclick = function() { previousBlogFeature(); return false; }
	if (document.getElementById("blog_feature_prev6")) document.getElementById("blog_feature_prev6").onclick = function() { previousBlogFeature(); return false; }
	if (document.getElementById("blog_feature_prev7")) document.getElementById("blog_feature_prev7").onclick = function() { previousBlogFeature(); return false; }
	if (document.getElementById("blog_feature_prev8")) document.getElementById("blog_feature_prev8").onclick = function() { previousBlogFeature(); return false; }
	
	if (document.getElementById("blog_feature_next1")) document.getElementById("blog_feature_next1").onclick = function() { nextBlogFeature(); return false; }
	if (document.getElementById("blog_feature_next2")) document.getElementById("blog_feature_next2").onclick = function() { nextBlogFeature(); return false; }
	if (document.getElementById("blog_feature_next3")) document.getElementById("blog_feature_next3").onclick = function() { nextBlogFeature(); return false; }
	if (document.getElementById("blog_feature_next4")) document.getElementById("blog_feature_next4").onclick = function() { nextBlogFeature(); return false; }
	if (document.getElementById("blog_feature_next5")) document.getElementById("blog_feature_next5").onclick = function() { nextBlogFeature(); return false; }
	if (document.getElementById("blog_feature_next6")) document.getElementById("blog_feature_next6").onclick = function() { nextBlogFeature(); return false; }
	if (document.getElementById("blog_feature_next7")) document.getElementById("blog_feature_next7").onclick = function() { nextBlogFeature(); return false; }
	if (document.getElementById("blog_feature_next8")) document.getElementById("blog_feature_next8").onclick = function() { nextBlogFeature(); return false; }

}); 



function previousBlogFeature() {
	// 04-13-08 - on the front page of TSR, we are now going to rotate 
	// through a feature, on the image of a sign, of all 8 blogs. We are
	// also going to offer a previous and next button, so people can 
	// advance through the features themselves. This function is tied
	// to the previous button. We cancel the global timer so the user
	// will be in control of which of the 8 divs becomes visible. We 
	// then change the global variable blogFeatureFlip and we call 
	// flipTheBlogFeatureSign so the newly chosen div will become visible. 
	
	clearInterval(flipTheBlogFeaturesSignTimer);
	blogFeatureFlip = blogFeatureFlip - 2; 
	flipTheBlogFeatureSign();
	flipTheBlogFeaturesSignTimer = setInterval("flipTheBlogFeatureSign()", 10000); 

	return false; 
}




function nextBlogFeature() {
	// 04-13-08 - on the front page of TSR, we are now going to rotate 
	// through a feature, on the image of a sign, of all 8 blogs. We are
	// also going to offer a previous and next button, so people can 
	// advance through the features themselves. This function is tied
	// to the next button. We cancel the global timer so the user
	// will be in control of which of the 8 divs becomes visible. We 
	// then change the global variable blogFeatureFlip and we call 
	// flipTheBlogFeatureSign so the newly chosen div will become visible. 
	
	clearInterval(flipTheBlogFeaturesSignTimer);
// 04-13-08 - we don't need to add anything here, because that will be handled by flipTheBlogFeatureSign
//	blogFeatureFlip = blogFeatureFlip + 1; 

	flipTheBlogFeatureSign();
	flipTheBlogFeaturesSignTimer = setInterval("flipTheBlogFeatureSign()", 10000); 

	return false; 
}






var roadWarriorFlip = 1; 
function flipTheRoadWarriorText() {
	// 04-09-08 - if you go to the front of the TSR site
	// you'll see a speech bubble with the heading "Hey,
	// Road Warriors". There are
	// suppose to be 2 stories that share the same space.
	// We need a Javascript function that toggle between
	// the two divs that are inside this bubble. 
	//
	// 05-05-08 - redone to accomodate 8 fields. 



	if (document.getElementById("warrior1")) var refToWarrior1 = document.getElementById("warrior1");
	if (document.getElementById("warrior2")) var refToWarrior2 = document.getElementById("warrior2");
	if (document.getElementById("warrior3")) var refToWarrior3 = document.getElementById("warrior3");
	if (document.getElementById("warrior4")) var refToWarrior4 = document.getElementById("warrior4");
	if (document.getElementById("warrior5")) var refToWarrior5 = document.getElementById("warrior5");
	if (document.getElementById("warrior6")) var refToWarrior6 = document.getElementById("warrior6");
	if (document.getElementById("warrior7")) var refToWarrior7 = document.getElementById("warrior7");
	if (document.getElementById("warrior8")) var refToWarrior8 = document.getElementById("warrior8");



	if (document.getElementById("warrior1"))  refToWarrior1.style.display = "none";
	if (document.getElementById("warrior2"))  refToWarrior2.style.display = "none";
	if (document.getElementById("warrior3"))  refToWarrior3.style.display = "none";
	if (document.getElementById("warrior4"))  refToWarrior4.style.display = "none";
	if (document.getElementById("warrior5"))  refToWarrior5.style.display = "none";
	if (document.getElementById("warrior6"))  refToWarrior6.style.display = "none";
	if (document.getElementById("warrior7"))  refToWarrior7.style.display = "none";
	if (document.getElementById("warrior8"))  refToWarrior8.style.display = "none";

	roadWarriorFlip = roadWarriorFlip + 1;
	if (roadWarriorFlip > 8) roadWarriorFlip = 1; 
	var getThisWarrior = "warrior" + roadWarriorFlip;
	if (document.getElementById(getThisWarrior)) document.getElementById(getThisWarrior).style.display = "block"; 
}



// 09-19-08 - Now Melissa wants the messages returned to the front page, but Laura and
// I don't want another animation, so we will make it so just one message appears, by
// commenting this out. 
//
//addLoadEvent(function() {
//	setInterval("flipTheRoadWarriorText()", 9000); 
//});










var driveInFlip = 0; 
function flipThedriveInText() {
	// 06-19-08 - at TSR's request, we will now used the drive in theater
	// on the front page to showcase a variety of the material inside the site. 

	if (document.getElementById("drive_in_default")) var refTodriveIn1 = document.getElementById("drive_in_default");
	if (document.getElementById("drive_in1")) var refTodriveIn2 = document.getElementById("drive_in1");
	if (document.getElementById("drive_in2")) var refTodriveIn3 = document.getElementById("drive_in2");
	if (document.getElementById("drive_in3")) var refTodriveIn4 = document.getElementById("drive_in3");

	if (document.getElementById("drive_in_default"))  refTodriveIn1.style.display = "none";
	if (document.getElementById("drive_in1"))  refTodriveIn2.style.display = "none";
	if (document.getElementById("drive_in2"))  refTodriveIn3.style.display = "none";
	if (document.getElementById("drive_in3"))  refTodriveIn4.style.display = "none";

	driveInFlip = driveInFlip + 1;
	if (driveInFlip > 3) driveInFlip = 0; 
	var getThisdriveIn = "drive_in" + driveInFlip;
	if (driveInFlip == 0) getThisdriveIn = "drive_in_default";
	if (document.getElementById(getThisdriveIn)) document.getElementById(getThisdriveIn).style.display = "block"; 
}



addLoadEvent(function() {
	setInterval("flipThedriveInText()", 7000); 
});


// Additions by RK to fill mp_removeUsers
//--------------------------------------------------------------------------------------------------------
var iterationCount = 0;
var iterationCountBackSeat = 0;
var mp_letter = "";

// RK 7-2-08 Fills mp_removeUsers with a limited and iterated through number members of the group
function getMembersOfGroup() {
	if (document.getElementById("mp_removeUsers")) {
		var eId = window.location.search
		if(eId.indexOf("editId") != -1) {
			var eIdArray = eId.split("editId")
			var eIdArray = eIdArray[1].split("=")
			var eIdArray = eIdArray[1].split("&")
			
			var editId = eIdArray[0];
			
			var url = 'api.php';
			var pars = 'choiceMade[]=getMembersOfGroup';
			pars += '&editId=' + editId;
			pars += '&iterationCount=' + iterationCount;
			var target = 'mp_removeUsers';	
			var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
		}

	}
}



function mpPreviousClick() {
	if (document.getElementById("mp_previous")) {
		iterationCount = iterationCount + 1;
		getMembersOfGroup();
	}
}

function mpNextClick() {
	if (document.getElementById("mp_next")) {
		iterationCount = iterationCount - 1;
		getMembersOfGroup();
	}
}


addLoadEvent(function() {
	if (document.getElementById("mp_previous")) {
		var referenceToMP_Previous = document.getElementById("mp_previous");
		referenceToMP_Previous.onclick = function() {
			mpPreviousClick(); 	
			return false; 
		}	
	}
});

addLoadEvent(function() {
	if (document.getElementById("mp_next")) {
		var referenceToMP_Next = document.getElementById("mp_next");
		referenceToMP_Next.onclick = function() {
			mpNextClick(); 	
			return false; 
		}	
	}
});


// RK 7-2-08 Fills mp_showBackSeat with a limited and iterated through number members of the group
function getMembersOfBackSeat(txt) {
	if (document.getElementById("mp_showBackSeat")) {
		if ((txt=="") || (txt==null)){
			ANDClause="";
		}
		else {
			iterationCountBackSeat = 0;
			ANDClause="AND users.username LIKE '" + txt + "%' ";
		}
		var url = 'api.php';
		var pars = 'choiceMade[]=getMembersOfBackSeat';
		pars += '&iterationCount=' + iterationCountBackSeat;
		pars += '&ANDClause=' + ANDClause;
		var target = 'mp_showBackSeat';	
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
	}
}


function mpPreviousBackSeatClick() {
	if (document.getElementById("mp_previousBackSeat")) {
		iterationCountBackSeat = iterationCountBackSeat - 1;
		getMembersOfBackSeat("");
	}
}

function mpNextBackSeatClick() {
	if (document.getElementById("mp_nextBackSeat")) {
		iterationCountBackSeat = iterationCountBackSeat + 1;
		getMembersOfBackSeat("");
	}
}


addLoadEvent(function() {
	if (document.getElementById("mp_previousBackSeat")) {
		var referenceToMP_PreviousBackSeat = document.getElementById("mp_previousBackSeat");
		referenceToMP_PreviousBackSeat.onclick = function() {
			mpPreviousBackSeatClick(); 	
			return false; 
		}	
	}
});

addLoadEvent(function() {
	if (document.getElementById("mp_nextBackSeat")) {
		var referenceToMP_NextBackSeat = document.getElementById("mp_nextBackSeat");
		referenceToMP_NextBackSeat.onclick = function() {
			mpNextBackSeatClick(); 	
			return false; 
		}	
	}
});


/*
var letters = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
letterArray = letters.split(",")

// RK 7-2-08 Fills mp_showBackSeat with a Where clause limited query
function mpLetterQuery() {
	if (document.getElementById("mp_showBackSeat")) {
		mp_letter = "a";
		iterationCountBackSeat = 0;
		var url = 'api.php';
		var pars = 'choiceMade[]=getMembersOfBackSeat';
		pars += '&iterationCount=' + iterationCountBackSeat;
		var target = 'mp_showBackSeat';	
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
	}
}
*/

/*
//for (i=0;i<=25;i++) {
//	var referenceToMP_Letter = document.getElementById("mp_" + letterArray[i]);
function mpLetter(this) {
alert(this);*/
/*    var evt = window.event;
	var targ = (evt.target) ? evt.target : evt.srcElement;

    if(targ != null) {
        if(targ.nodeType == 3)
            targ = targ.parentNode;
    }
alert(targ);*/
//		var theElem = getEventTarget(window.event);
//alert(theElem);
		/*if (document.getElementById("mp_nextBackSeat")) {
			iterationCountBackSeat = 0;
			mpLetterQuery();
		}*/
//}
//}
	
/*addLoadEvent(function() {
	if (document.getElementById("mp_A")) {
		for (i=0;i<=25;i++) {
			var referenceToMP_Letter = document.getElementById("mp_" + letterArray[i]);
			referenceToMP_Letter.onclick = function() {
				test(); 	
				return false; 
			}
		}	
	}
});*/

/*addLoadEvent(function() {
	if (document.getElementById("mp_A")) {
		var referenceToMP_Letter = document.getElementById("mp_A");
		referenceToMP_Letter.onclick = function() {
			test(); 	
			return false; 
		}		
	}
});
*/
//--------------------------------------------------------------------------------------------------------











/*

09-07-08 - 

We got this email: 

>> From: Bill O'Luanaigh <skepticbill@mac.com>
>> Hey there Melissa,
>> 
>> We never got a chance to reconnect and I'm sorry to send you this as our
>> first 'contact' in a while. Looks like someone has figured a way to hijack
>> your email list. If not it sure 'feels' that way and folks are going to
>> wonder what is up.
>> 
>> I'd call your tech guys and see if they can figure this one out.


I responded: 

>> It looks to me like someone went to this page:
>>
>> http://www.thesecondroad.org/members_list.php?frontpage=frontpage_classic.htm&
>>
>> And then went down the list, sending a message to each person. Or,
>> possibly, then wrote a script to do exactly that.
>>
>> The person doing this doesn't have people's actual email addresses,
>> otherwise they would use their own software to send the messages.
>> Instead, these messages are being sent from TSR, as you can see from the
>> return address:
>>
>>> From: <doNotReply@thesecondroad.org>


I then suggested captcha, even if the person is logged in. Melissa agreed to that, so I'm now adding captcha to here:

http://www.cyberbitten.com/my_private_page.php?formName=mp_inbox_send_a_new_message.htm&id=404


*/
function checkCaptchaForSendingEmail() {
  if (document.getElementById('formForSendingEmailToOtherMembers')) {
      var refToForm = document.getElementById('formForSendingEmailToOtherMembers');

      if (document.getElementById('captchaCheck')) {
        var refToCaptchaInput = document.getElementById('captchaCheck');
        if (refToCaptchaInput.value == "") {
          alert("Please enter the number into the number field. This protects our members from spam.");
        } else {
          refToForm.submit(); 
        }
    }
  }
  return false; 
}









addLoadEvent(function() {
	// 10-19-08 - we need to get this file: 
	// 
	// http://www.thesecondroad.org/listOfMembers.html
	// 
	// which is created by a cron job. It is for use on this page:
	// 
	// http://www.thesecondroad.org/my_private_page.php?formName=mp_groups.htm
	// 
	// The goal is to make it easier for people to add new members to their 
	// groups. I'm doing this as an Ajax call after the page has loaded, because
	// this could be a huge list and I don't want to slow down the page load. 
	
	if (document.getElementById("emptyDivIntoWhichWeCanPutAListOfMembersUsingAjax")) {
		var url = 'listOfMembers.html';
		var pars = '';
		var target = 'emptyDivIntoWhichWeCanPutAListOfMembersUsingAjax';	
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});

		if (document.getElementById("linkToShowEmptyDivIntoWhichWeCanPutAListOfMembersUsingAjax")) {
			var referenceToDiv = document.getElementById("linkToShowEmptyDivIntoWhichWeCanPutAListOfMembersUsingAjax");
			referenceToDiv.style.display = "block"; 
		}
	}
});


