
		
	

	// 01-24-05 - most of the time, with most browsers, you can't get a selection from a form
	// input with a function triggered with a form control like a button, because clicking the 
	// button shifts the focus to the button and destroys the selection. So I'm thinking that 
	// perhaps we can have a global variable that is set with setFieldSelectionValue() which
	// can be called onMouseUp(). This sets the value and insertAtCursor() can check to see
	// if that value is there. 
	var fieldValue = ""; 
	
	function setFieldSelectionValue(myField) {
		// 01-24-05 - this next line is meant to ensure that we don't 
		// carry an old value forward. 
		fieldValue = "";
		
		if (document.selection) {
			if (document.selection.createRange) {
				var range = document.selection.createRange();
				var fieldText = range.text; 
			} else if (document.selection.getRangeAt) {
				// 01-24-05 - this next bit may work in Mozilla
				var range = document.selection.getRangeAt(0); 
				if (range) {
					if (range.text) {
						var fieldText = range.text; 
					} else if (range.value) {
						var fieldText = range.value; 
					}
				}
			} else if (document.selection.toString) {
				var fieldText = document.selection.toString(); 
			}	
		} else if ('number' == typeof myField.selectionStart) {
			// MOZILLA/NETSCAPE support
			// myField.value.substring(myField.selectionStart,myField.selectionEnd)
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			if (myField.value.substring) {
				if (endPos != 0) {
					var fieldText = myField.value.substring(startPos, endPos);
				}
			} 
		}				
		if (fieldText != "") fieldValue = fieldText; 
	}
				
	
	function insertAtCursor(thisField, tag) {
		var myField = document.getElementById(thisField);
		// 01-24-05 - this first if() block is for Microsoft IE on PC
		if (document.selection && document.selection.createRange) {
			var range = document.selection.createRange();
			if (range.text == '') {
				alert("You haven't selected any text to change.");  
			} else {
				range.text = '<' + tag + '>' + range.text + '<\/' + tag + '>';
			}
		} else if ('number' == typeof myField.selectionStart) {
			// this next bit is for Netscape/Mozilla
			// myField.value.substring(myField.selectionStart,myField.selectionEnd)
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			if (endPos != 0) {
				var mySelection = myField.value.substring(myField.selectionStart, myField.selectionEnd);
				mySelection =  '<' + tag + '>' + mySelection + '<\/' + tag +	'>';
				myField.value = myField.value.substring(0, startPos) + mySelection + myField.value.substring(endPos, myField.value.length);
			} else {
				alert("You haven't selected any text to change."); 
			}
		} else {
			// 01-24-05 - the above methods work in IE and Firefox on the PC. For other 
			// browsers we try to use the fieldValue variable and append to the end of the
			// textarea. fieldValue is global and set onmouseup by setSelectionFieldValue().
			var fieldValue = prompt("Type what text you want surrounded by this tag:", ""); 
			myField.value += '<' + tag + ' >' + fieldValue + '<\/' + tag + '>';
		}
		updateLivePreview(); 
	}




	function insertAtCursorSpan(myField, styleColor) {
		if (styleColor) {
			if (styleColor.value) {
				var inputColor = styleColor.value; 
			} else if (styleColor.toString) {
				var inputColor = styleColor.toString(); 
			} else if (styleColor.text) {
				var inputColor = styleColor.text;
			} else if ('string' == typeof styleColor) {
				var inputColor = styleColor; 
			}
			
			if (inputColor) {		
				if (document.selection && document.selection.createRange) {
					var range = document.selection.createRange();
					if (range.text == '') {
						alert("You haven't selected any text to change.");  
					} else {
						range.text = '<span style=\"color:#' + inputColor + ';\">' + range.text + '<\/span>';
					}
				} else if ('number' == typeof myField.selectionStart) {
					// MOZILLA/NETSCAPE support
					// myField.value.substring(myField.selectionStart,myField.selectionEnd)
					var startPos = myField.selectionStart;
					var endPos = myField.selectionEnd;
					if (endPos != 0) {
						var mySelection = myField.value.substring(myField.selectionStart, myField.selectionEnd);
						mySelection =  '<span style=\"color:#' + inputColor + ';\">' + mySelection + '<\/span>';
						myField.value = myField.value.substring(0, startPos) + mySelection + myField.value.substring(endPos, myField.value.length);
					} else {
						alert("You haven't selected any text to change."); 
					}
				} else {
					var fieldValue = prompt("Type what text you want with this color:", ""); 
					myField.value += '<span style=\"color:#' + inputColor + ';\">' + fieldValue + '<\/span>';
				}
			} else {
				alert("Awful sorry, but for some reason we weren't able to detect what the chosen color was."); 	
			}
		} else {
			alert("No color choosen."); 	
		}		
		updateLivePreview(); 
	}								    
		   

	function insertAtCursorDiv(myField, styleColor) {
		if (styleColor) {
			if (styleColor.value) {
				var inputColor = styleColor.value; 
			} else if (styleColor.toString) {
				var inputColor = styleColor.toString(); 
			} else if (styleColor.text) {
				var inputColor = styleColor.text;
			} else if ('string' == typeof styleColor) {
				var inputColor = styleColor; 
			}
			
			if (inputColor) {
				if (document.selection && document.selection.createRange) {
					var range = document.selection.createRange();
					if (range.text == '') {
						alert("You haven't selected any text to change.");  
					} else {
						range.text = '<div style=\"background-color:#' + inputColor + ';\">' + range.text + '<\/div>';
					}
				} else if ('number' == typeof myField.selectionStart) {
					// MOZILLA/NETSCAPE support
					// myField.value.substring(myField.selectionStart,myField.selectionEnd)
					var startPos = myField.selectionStart;
					var endPos = myField.selectionEnd;
					if (endPos != 0) {
						var mySelection = myField.value.substring(myField.selectionStart, myField.selectionEnd);
						mySelection =  '<div style=\"background-color:#' + inputColor + ';\">' + mySelection + '<\/div>';
						myField.value = myField.value.substring(0, startPos) + mySelection + myField.value.substring(endPos, myField.value.length);
					} else {
						alert("You haven't selected any text to change."); 
					}
				} else {
					var fieldValue = prompt("Type what text you want with this color:", ""); 
					myField.value += '<div style=\"background-color:#' + inputColor + ';\">' + fieldValue + '<\/div>';
				}
			} else {
				alert("Awful sorry, but for some reason we could not detect what color was choosen."); 	
			}
		} else {
			alert("No color choosen."); 	
		}
		updateLivePreview(); 
	}			
					    
		   
	function insertAtCursorLink (thisField) {
		var myField = document.getElementById(thisField);
		address = prompt('What is the address you want to link to?', 'http://');
		if (document.selection && document.selection.createRange) {
			var range = document.selection.createRange();
			if (range.text == '') {
				alert("You haven't selected any text to change.");  
			} else {
				range.text = '<a href=\"' + address + '\">' + range.text + '<\/a>';
			}
		} else if ('number' == typeof myField.selectionStart) {
			// MOZILLA/NETSCAPE support
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			if (endPos != 0) {
				var mySelection = myField.value.substring(myField.selectionStart, myField.selectionEnd);
				mySelection =  '<a href=\"' + address + '\">' + mySelection + '<\/a>';
				myField.value = myField.value.substring(0, startPos) + mySelection + myField.value.substring(endPos, myField.value.length);
			} else {
				alert("You haven't selected any text to change."); 
			}
		} else {
			var mySelection = prompt("What text would you like for this link?", "");
			if (mySelection == "") mySelection = ' Webpage ';
			mySelection =  '<a href=\"' + address + '\">' + mySelection + '<\/a>';
			myField.value += mySelection;
		}
		updateLivePreview(); 
	}

					   
	function insertAtCursorImage (myField) {
		var address = prompt('Add an address for an image. Use this for images on other sites. Use the drop down box for images that have already been uploaded to your server.', 'http://');
	    if (address != '') {
		    address = '<img src=\"' + address + '\">';
		    
			if (document.selection && document.selection.createRange) {
   					var range = document.selection.createRange();
				    if (range.parentElement() == element) range.text = range.text + address;
			} else if ('number' == typeof myField.selectionStart) {
				var startPos = myField.selectionStart;
				var endPos = myField.selectionEnd;
				if (endPos != 0) {
					var mySelection = myField.value.substring(myField.selectionStart, myField.selectionEnd);
					mySelection += address;
					myField.value = myField.value.substring(0, startPos) + mySelection + myField.value.substring(endPos, myField.value.length);
				} else {
					myField.value += address;
					alert("You haven't selected any text to change so we put the image at the end of your text."); 
				}
			} else {
				myField.value += address; 
			}
		} else {
			alert('Awful sorry, but you did not put in the address of an image.');    
	    }
	}
	
	

	function insertImageFromSelect (myImage, myField) {
		var imageName = myImage.value;
		if (imageName != '') {
			var imageString = pathToImage + imageName; 
		    address = '<img src=\"' + imageString + '\">';
				
			if (document.selection && document.selection.createRange) {
					var range = document.selection.createRange();
			    if (range.parentElement() == element) range.text = range.text + address;
			} else if ('number' == typeof myField.selectionStart) {
				var startPos = myField.selectionStart;
				var endPos = myField.selectionEnd;
				if (endPos != 0) {
					var mySelection = myField.value.substring(startPos, endPos);
					mySelection += address;
					myField.value = myField.value.substring(0, startPos) + mySelection + myField.value.substring(endPos, myField.value.length);
				} else {
					myField.value += address;
					alert("You haven't selected any text to change so we put the image at the end of your text."); 
				}
			} else {
				myField.value += address; 
			}
		}
	}



		
	// 11-28-04 - one thing I hate is when I write a long email using a service like Hotmail, then
	// I hit submit, and then I lose everything I wrote because while I was writing the email 
	// I unknowingly lost my internet connection. So now we are offering this mild protection, 
	// which is to gather the text of the form and output it to t separate window. 	

	function openInNewWindowString(windowText) {
		// 02-19-06 - note to self - 
		// window.open returns a reference to a window. 
		// window.write() - I'm not sure waht it does
		// window.document.write() - writes to the document inside of the window. 
		// window.close() closes the window
		// window.document.close() tells the browser that you are done wrting to the document in the window

		var docWindow = window.open("", 'userSubmission', 'width=300,height=400,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes');
		docWindow.focus();
     	docWindow.document.write(windowText);
		docWindow.document.close();
		return docWindow;
	}
		
		
	function nl2br_js(myString){
		// 02-18-06 - this function imitates the PHP command nl2br, which finds newlines in a string
		// and replaces them with newlines plus HTML BR tags. Is the easiest way to create the 
		// appearance of paragraphs when people are creating web pages by typing text into a form. 
		var regXString =  "\\n"
		var regX = new RegExp(regXString, "g");
		var replaceString = "<br> \n";
		return myString.replace(regX, replaceString);
	} 
  
	function saveYourWork(idOfElement) {
		// 02-19-06 - hopefully, the control panel template has loaded a public page with the 
		// default template for this site into an iframe. We want to get the innerHtml of 
		// that frame and use if for previewing.
		var previewFrame = window.frames[0];
		var previewDocument = previewFrame.document;
		var innerHtmlOfPreviewPage = previewDocument.documentElement.innerHTML; 
	
		// 02-18-06 - this next line should get the vaule of the TEXTAREA that we use on most forms.
		var fieldText = document.getElementById(idOfElement).value;
		if (fieldText != '' &&  fieldText !=  undefined) {
			fieldText = nl2br_js(fieldText); 
			if (innerHtmlOfPreviewPage != "" && innerHtmlOfPreviewPage != undefined) {
				var regXString =  "<div class=\"weblogPagesWhole\">";
				var regX = new RegExp(regXString, "g");
				var replaceString = regXString + fieldText;
				innerHtmlOfPreviewPage.replace(regX, replaceString);
			}
			// 02-18-06 - jesus, this is complicated. Look in pdsAjax.js for getHtmlForPreviewPage
			// to see how innerHtmlOfPreviewPage gets set. It is a global variable. 
			innerHtmlOfPreviewPage = "<html>" + innerHtmlOfPreviewPage + "</html>";
			openInNewWindowString(innerHtmlOfPreviewPage);
		} else {
			alert("There was no nothing to show. The field is empty."); 	
		}
	}
								

		
	
	
	// 01-24-05 - can't get this undo stuff to work, so this is not in use for now.
	//
	// 12-04-04 - our form functions, especially McFormsPrintNow, will output text boxes and textareas
	// that call addToArrayOfPastWork() whenever the event onkeypress is called. 
	// Then elementsAdminShowFormattingButtons() contains an undo and a 
	// redo button that lets users step through the array and bring back
	// previous versions of their work. 
	pastFormWork = new Object();
	
	function addToArrayOfPastWork(myField) {			
		// 12-17-04 - this needs to happen here and not in the function undoFormWork()
		// because you don't want to erase future states of work until a new state
		// is being added. A user should be able to type 10 things, then hit the undo
		// button 10 times, then hit the redo button 10 times, but they can't do that
		// if the undo button erases all the stuff the redo button would want to redo. 

		// 12-29-04 - to simplify my life, I got rid of redo, and now these functions
		// are much simpler. 
	
//			var id = myField.id; 
		
		// 01-08-05 - if pastForWork already has a variable of id value added to it, 
		// then we simply work with the array. Otherwise, we create the array. 
//			if (pastFormWork.id) {
//				var arrayToAddTo = pastFormWork.id.value; 
		
		
//			} else {
//				var arrayOfPastWork = new Array(); 
//				arrayOfPastWork[0] = myField.value; 
//				pastFormWork.id = arrayOfPastWork; 
//			}
	
	
		
//			var newElementIndex = arrayOfPastFormWork.length;
//			arrayOfPastFormWork[newElementIndex] = myField.value; 
//			currentFormIndexValue = newElementIndex; 
	}

		
	function undoFormWork(myField) {
		// 12-09-04 - this next line should take us back one step
		// in the array of work done so far. It should also force a cast to an
		// integer, good in case this variable has somehow been turned into
		// a string. 
		
		// 12-29-04 - to simplify my life, I got rid of redo, and now these functions
		// are much simpler. 
		currentFormIndexValue = currentFormIndexValue - 1;
		
		var maxIndex = arrayOfPastFormWork.length;
		maxIndex = maxIndex - 1;
		if (currentFormIndexValue < 0) currentFormIndexValue = 0; 
		if (currentFormIndexValue > maxIndex) currentFormIndexValue = maxIndex; 
		myField.value = arrayOfPastFormWork[currentFormIndexValue];
	}

/* 12-29-04 - deprecated for now			
	function redoFormWork(myField) {
		currentFormIndexValue = currentFormIndexValue + 1; 
		myField.value = arrayOfPastFormWork[currentFormIndexValue];
	}
*/
		

	isVisible = false; 			
	function makeOptionalDivVisible() {				
		if (document.getElementById('optionalDiv')) {
			var optionDiv = document.getElementById('optionalDiv');
			
			if (isVisible == true) {
		     	optionDiv.style.height='1px';
		     	optionDiv.style.display='none';
		     	isVisible = false; 
			} else {
		     	optionDiv.style.height='auto';
		     	optionDiv.style.display='block';
		     	optionDiv.style.visibility='visible';
		     	isVisible = true; 
	     	}
     	}
	}
	
	


	function hideOrShowDiv(optionDiv) {				
		if (optionDiv != undefined) {
			if (optionDiv.style.display == 'block') {
		     	optionDiv.style.display='none';		
			} else {
				optionDiv.style.height='auto';
		     	optionDiv.style.display='block';
		     	optionDiv.style.visibility='visible';
			}
		} else {
			alert("In hideOrShowDiv, we got no reference, but instead, we got this: " + optionDiv); 	
		}
 	}

 	


	function hideOrShowDivById(optionDivId) {	
		if (document.getElementById(optionDivId)) {
			var optionDiv = document.getElementById(optionDivId);
			if (optionDiv.style.display == 'block') {
		     	optionDiv.style.display='none';
			} else {
		     	optionDiv.style.display='block';
			}
		} else {
			alert("There was no item on the page called " + optionDivId);
		}
 	}

 	
 	
 	
 	
 	function changeChoiceMade(newChoiceMade, newControlPanelCbId, formName) {
	 	// 03-10-06 - we'll be using this in the PHP command showAllNewslettersForSending()
	 	// to change what should happen after the form submits, and to make sure the 
	 	// form submits onClick(). 
	 	if (document.getElementById("choiceMade")) {
	 		var refToChoiceMade = document.getElementById("choiceMade");
	 		refToChoiceMade.value = newChoiceMade; 
 		}
	 	if (document.getElementById("controlPanelCbId")) {
	 		var refToChoiceMade = document.getElementById("controlPanelCbId");
	 		refToChoiceMade.value = newControlPanelCbId; 
 		}
 		submitAnyForm(formName); 		
 	}
 	
 	
 	
 	
 	function changeChoiceMadeForNewsletters(newChoiceMade, newControlPanelCbId, formId) {
	 	// 03-10-06 - we'll be using this in the PHP command showAllNewslettersForSending()
	 	// to change what should happen after the form submits, and to make sure the 
	 	// form submits onClick(). 
	 	// 
	 	// 05-23-06 - on this page:
	 	// 
	 	// http://www.monkeyclaus.org/artists/mcControlPanel.php?arrangement=sendEmail
	 	//
	 	// We use this function to call CommandUpdateMailList, which takes a new list of emails, which should have been
	 	// stored in a hidden input of id listOfEmails and we store this list in cbModifier19. 
	 	// 
	 	// 
	 	if (newChoiceMade != "" && newChoiceMade != undefined) {
		 	if (newControlPanelCbId != "" && newControlPanelCbId != undefined) {
			 	if (document.getElementById(formId)) {
				 	if (document.getElementById("choiceMade")) {
						// 01-06-07 - I thought this was a bug at first. Two inputs on that page have the name
						// "choiceMade" so I thought there was a conflict. However, only one has the id of 
						// choiceMade, so there is no conflict. The difference is the difference between a name
						// and an id when you're dealing with HTML forms. 
				 		var refToChoiceMade = document.getElementById("choiceMade");
				 		refToChoiceMade.value = newChoiceMade; 
				 		
					 	if (document.getElementById("controlPanelCbId")) {
					 		var refToId = document.getElementById("controlPanelCbId");
					 		refToId.value = newControlPanelCbId; 
					 		
						 	if (document.getElementById("listOfEmails")) {
							 	// 05-23-06- listOfEmails is a hidden input, it stores a new list of emails that are then put
							 	// in cbModifier19 if this form calls the PHP command CommandUpdateMailList.
								//
								// 01-06-07 - an example of a textarea entry looks like this:
								//
								//			<li><input  class="textareaOfEmailsForNewletters" type="checkbox" name="newslettersToUse[]" value="2227" /> Erich Schiffmann (<a href="mcControlPanel.php" onClick="hideOrShowDivById('emailList2227'); return false;">See emails?</a>)
								//			<div id="emailList2227" class="showhide"><textarea name="emailLists[2227]" cols="100%" rows="5" id="emailLists[2227]">,  etterkmc@sbcglobal.net,  sandyj@calcru.com</textarea> 
								//			<br />	
								//			<input type="submit" value="Save Emails" class="button" onClick="changeChoiceMadeForNewsletters('updateMailList', 2227, 'sendEmailForm2'); return false;" />
								//			</div></li>
						 		var refToList = document.getElementById("listOfEmails");
							 	var idOfList = "emailLists[" + newControlPanelCbId + "]";
							 	if (document.getElementById(idOfList)) {
								 	var refToEmailList = document.getElementById(idOfList);
							 		refToList.value = refToEmailList.value;
							 		submitAnyForm(formId);
							 	} else {
								 	alert("There was no item with id of " + idOfList);	
							 	}
					 		} else {
						 		alert("There was no item called listOfEmails"); 	
					 		}
				 		} else {
					 		alert("There was no item called 'controlPanelCbId'");
				 		}
			 		} else {
				 		alert("There was no item called choiceMade");
			 		}
				} else {
			 		alert("There was no form with the id of " + formId + ", parameter 3 of changeChoiceMadeForNewsletters");	
				}			 				 	
			} else {
		 		alert("We were not told what the new control panel page id was suppose to be, parameter 2 of changeChoiceMadeForNewsletters");	
		 		return false;
			}			 	
		} else {
	 		alert("We were not told what the new 'choice made' was suppose to be, parameter 1 of changeChoiceMadeForNewsletters");	
	 		return false; 
		}
	}
 	
 	


function checkAllCheckBoxInputs(formId) {
	if (document.getElementById(formId)) {
		var refToForm = document.getElementById(formId);
		var elementsArray = refToForm.elements;
		var howManyElements = elementsArray.length;

		if (howManyElements > 0) {
			for (r=0; r < elementsArray.length; r++) {
				field = elementsArray[r];
				var fieldName = field.name;
				if (fieldName == "emailToSend[]") {
					if (field.checked == false) {
						field.checked = true;
					} else {
						field.checked = false; 
					}
				}
			}
		} else {
			alert("Sorry, but the form " +  formId + " had no elements"); 
		}
	} else {
		alert("Sorry, we could not find a form named " + formId);
	}
}



 	
 	
 	
 	
 	function popUpDiv(itemId) {
	 	if (document.getElementById(itemId)) {
			var optionDiv = document.getElementById(itemId);
			if (optionDiv.style.display == 'block') {
		     	optionDiv.style.display='none';
			} else {
		     	optionDiv.style.display='block';
		     	optionDiv.style.visibility='visible';
			}
		} else {
			alert("No item by the name of " + itemId);	
		}
 	}
	
	
	
	
	
	// Pass the selectorText (c), property to change (p) and new value (v)
	function modStyle(c,p,v) {
		if (document.styleSheets) {
			// get the stylesheets
			var rules = document.styleSheets[0].cssRules;
			if (rules == false) {
				var rules = document.styleSheets[0].rules;
			}
			// Now the rules...
			var rl = rules.length;
			for (var j=0; j < rl; j++) {
				// Check selectorText is same as c
				// Allow for IE putting a * in front of selectorText
				// Could just remove * but chose to use || instead
				// var r = rules[j].selectorText.replace(/^\*/,'');
				var thisRule = rules[j];
				alert("property to change is " + p);
				alert("selector is " + c );
				if (thisRule.selectorText == c || thisRule.selectorText == '*'+c ||  thisRule.selectorText == '.'+c) {	
					// Now set the property to the value
					alert(thisRule);
					thisRule.style.p = v;
				}
			}
		}
	}
	
	

	
	// 12-30-04 - we should generalize this next command so it takes a class as an argument and 
	// closes any DIV with that class. 			
	function closeDropDownNav(makeVisibleId) {
		for (var i=0; i < 200; i++) {
			var elem = 'hiddenNavSection' + i;
			if (document.getElementById(elem)) {
				var thisElem = document.getElementById(elem);
				thisElem.style.display='none';		
			}
		}
		hideOrShowDiv(makeVisibleId);
	}

	
	
	function pausecomp(Amount) {
		d = new Date() //today's date
		while (1) {
			mill=new Date() // Date Now
			diff = mill-d //difference in milliseconds
			if( diff > Amount ) {break;}
		}
	}
	
	
	
	// 12-07-04 - this is called in McFormsPrintNow by the the textarea method. It's 
	// purpose is to make a text area larger and smaller. 
	function makeBigger(myField) {				
		if (myField.style.height == '800px') {
			myField.style.height='150px';		
		} else {
		   	myField.style.height='800px';
		}
	}	
	
	
	
	function saveYourWorkReminder() {
		// alert("It's been 15 minutes. We suggest you click the 'Save' button and save a copy of your work to your harddrive. Web browsers are buggy and crash often. Protect yourself."); 	
	}

	

	
	
	
	
	var currentRef = ""; 
	var currentDeleteRef = "";
	var globalReferenceToCurrentElementToBeFadedIn = "";
	
	document.onmousemove= getMouseXY; // getMouseXY(event) implied on NS, getMouseXY(null) implied on IE
	document.onclick= getMouseXY;
	document.onmouseover= moveDeleteControls; 
	var tempX = 0;
	var tempY = 0;

	function getMouseXY(e) {
		// works on IE6,FF,Moz,Opera7
		
		// works on IE, but not NS (we rely on NS passing us the event)
		if (!e) e = window.event; 
		if (e) { 
		    if (e.pageX || e.pageY) {
			     // this doesn't work on IE6!! (works on FF,Moz,Opera7)
				tempX = e.pageX;
				tempY = e.pageY;
		    } else if (e.clientX || e.clientY) { 
			    // works on IE6,FF,Moz,Opera7
				tempX = e.clientX + document.body.scrollLeft;
				tempY = e.clientY + document.body.scrollTop;
		    }  
		}
	}
	
	
	function addLoadEvent(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      oldonload(); 
	      func(); 
	    } 
	  } 
	} 
	
	

	
	function addToOnClick(idOfElementToBeAddedTo, functionToHaveAddedReference) {
		// 07-08-06 - this function is styled after the addLoadEvent function, but this
		// adds a new function to an elements onclick element. The first parameter is the id
		// of the element whose onclick event we are adding to. The second parameter is 
		// the function reference we are adding.
		//
		// Look here for more info on addLoadEvent:
		//
		// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
		
		if (document.getElementById && document.getElementById(idOfElementToBeAddedTo)) {
			var elementReference = document.getElementById(idOfElementToBeAddedTo);
			var oldOnClick = elementReference.onclick;
			
			if (typeof elementReference.onclick != 'function') { 
				elementReference.onclick = functionToHaveAddedReference; 
			} else { 
				elementReference.onclick = function() { 
					oldOnClick(); 
					functionToHaveAddedReference(); 
				} 
			}
		} 
	}
	
	
	
	
	function storeReferencesToHTMLSafely() {
		// 02-10-06 - I was hoping to create a singleton by doing this, but I guess I'm
		// creating what will become another global variable. At least this way, storing
		// all references to html blocks in an array, there is no risk that I'll 
		// destroy the last reference to an HTML block by using removeChild() on it. 
		// If I tried to use removeChild on the object function returned from this
		// function, then I'd get an error. This function relies on closures, see
		// this page for info on Javascript closures:
		//
		// http://jibbering.com/faq/faq_notes/closures.html
		
		var arrayOfReferencesToHtmlBlocks = new Object(); 
		var setAndGetReferenceToHtml = new Object(); 

		setAndGetReferenceToHtml.get = function (idOfHtmlBlock) {
			var htmlBlockRef = arrayOfReferencesToHtmlBlocks[idOfHtmlBlock];
			if (!htmlBlockRef || htmlBlockRef == "" || htmlBlockRef == undefined) {
				arrayOfReferencesToHtmlBlocks[idOfHtmlBlock] = document.getElementById(idOfHtmlBlock);
				var htmlBlockRef =  arrayOfReferencesToHtmlBlocks[idOfHtmlBlock];
			}
			return htmlBlockRef;
		}
		
		// 02-13-06 - this next method is a mask for removeChild and helps protect against 
		// the possibility that the very last reference to an elment will be deleted. So
		// removeChild() should never be used in the code, outside of this method. Instead,
		// we should always remove things like this:
		//
		// allHtmlReferencesObject.remove(elementReference); 
		//
		setAndGetReferenceToHtml.remove = function (referenceToElement) {
			var idOfHtmlBlock = referenceToElement.id;
			var newReference =  referenceToElement.cloneNode(true); 
			referenceToElement.parentNode.removeChild(referenceToElement); 
			arrayOfReferencesToHtmlBlocks[idOfHtmlBlock] = newReference;
		}
		
		return setAndGetReferenceToHtml;
	}
	
	var allHtmlReferencesObject = storeReferencesToHTMLSafely(); 

	
	function getArrayOfElementsForCommunicationBox() {
		// 02-12-06 - I'm thinking it would be nice to have a global object that contains two
		// arrays, plus get and set methods for those arrays. Functions like setText() can use
		// these methods to specify what the dialog box should look like, and then setText() 
		// can call askForInput() which will show the dialog box. These two arrays, below
		// specify what HTML elements should be placed in the communication box. 
		//
		// 02-13-06 - PLEASE NOTE - this function is different from storeReferencesToHTMLSafely
		// in that manages references to HTML blocks whereas this carries strings of ids and
		// initial text that should fill in the communication box form. 
		
		var objectForAccessingArrayOfItemsForCommunicationBox = new Object();
		var singletonArrayToHoldElementsForTheNextRenderingOfTheCommunicationBox = new Object(); 
		var singletonCallBackAction = new Object(); 
		
		objectForAccessingArrayOfItemsForCommunicationBox.set = function(idOfElement, initialValue) {
			singletonArrayToHoldElementsForTheNextRenderingOfTheCommunicationBox[idOfElement] = initialValue;	
		}
		
		objectForAccessingArrayOfItemsForCommunicationBox.get = function() {			
			return singletonArrayToHoldElementsForTheNextRenderingOfTheCommunicationBox;
		}
		
		objectForAccessingArrayOfItemsForCommunicationBox.reset = function() {
			singletonArrayToHoldElementsForTheNextRenderingOfTheCommunicationBox = new Object(); 		
		}
		
		
		objectForAccessingArrayOfItemsForCommunicationBox.setCallBack = function(callBack) {
			singletonCallBackAction["callBack"] = callBack;
		}
		
		objectForAccessingArrayOfItemsForCommunicationBox.getCallBack = function() {
			var callBack = singletonCallBackAction["callBack"];
			return callBack; 
		}
		
		return objectForAccessingArrayOfItemsForCommunicationBox;
	}
	
	var arrayOfElementsForCommunicationBox = getArrayOfElementsForCommunicationBox(); 
	
	
	
	
	function setLink() {
		var newUrl = prompt("Copy and paste the URL you'd like to link to:", ""); 
		var newLinkText = prompt("What should the visible text of this link be?", ""); 
		var newLink = document.createElement("a");
		newLink.href = newUrl; 
		newLink.className = "deleteable";
		var newLinkTextNode = document.createTextNode(newLinkText);
		newLink.appendChild(newLinkTextNode);
		currentRef.appendChild(newLink); 		
		return false; 
	}
	
	
	function setText() {
		// 02-14-06 - this is called when the user opens the controller box and clicks 
		// "Add paragraph". The function sets up what the intro text should be, what the
		// initial text in the TEXTAREA should be, and then what function should be called
		// when the SUBMIT button is clicked. Then we call askInput which renders all this
		// info on screen as a dialog box. 
		arrayOfElementsForCommunicationBox.set("typeYourText", "Type your text here:"); 
		arrayOfElementsForCommunicationBox.set("inputBox", "You're the greatest"); 
		arrayOfElementsForCommunicationBox.setCallBack("setTextAction"); 
		askForInput(); 
		return false;
	}
	
	function setTextAction() {
		// 02-14-06 - this is what is called after the user has clicked "Add Paragraph" and 
		// the setText() function has fired and set up a dialog box. When the user clicks 
		// the SUBMIT button in that dialog box, the function runs. getInput() get's us 
		// whatever text the user typed into the TEXTAREA in that dialog box, and then
		// the code creates a new paragraph elements and adds it to whatever box was 
		// last clicked in, whose CSS class name was "wonderful". 
		var inputResults = getInput(); 
		hideDiv("communicationBox"); 
		var newTextNode = document.createTextNode(inputResults); 
		var newLiterature = document.createElement("p");
		newLiterature.className = "deleteable";
		newLiterature.appendChild(newTextNode);
		currentRef.appendChild(newLiterature); 		
	}

	function setImage() {
		arrayOfElementsForCommunicationBox.set("typeYourText", "Put the link to your image here:"); 
		arrayOfElementsForCommunicationBox.set("inputBox", "http://www.shrisaibabasansthan.org/main_English/saibaba/devotees/images/shimpi.jpg"); 
		arrayOfElementsForCommunicationBox.setCallBack("setImageAction"); 
		askForInput(); 
		return false; 
	}
	
	function setImageAction() {
		var inputResults = getInput(); 
		hideDiv("communicationBox"); 
		var newImage = document.createElement("img");
		newImage.className = "deleteable";
		newImage.src = inputResults; 	
		currentRef.appendChild(newImage); 		
	}

	function setHtml() {
		// 02-14-06 - this sets up the dialog box whose input is then fed to the function setHtmlAction().
		// This allows arbitrary HTML to be input. I assume it allows people to add their own Javascript.
		// Part of me wonders if this is a security risk, but then I don't see how, as it will only effect
		// the pages that the user theirselves create. 
		arrayOfElementsForCommunicationBox.set("typeYourText", "If you know HTML, you can write it here:"); 
		arrayOfElementsForCommunicationBox.set("inputBox", "<h7>Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety.</h7>"); 
		arrayOfElementsForCommunicationBox.setCallBack("setHtmlAction"); 
		askForInput(); 
		return false; 
	}
	
	function setHtmlAction() {
		// 02-07-06 - sadly, if the user adds any block level html, then the 
		// onMouseOver event no longer reports the className as "deleteable".
		// So we need to rewrite any input HTML, to make sure that the class
		// is added. 
		// not working --- inputResults.replace(/>/g, " class='deleteable'>"); 
		//
		// 02-14-06 - we will add 6px of padding, which creates enough space that
		// we now mouseover the edge and find something that we can delete. 
		//
		// 02-14-06 - this function is called when the submit is clicked in the 
		// dialog box established by the function setHtml(). 
		
		var inputResults = getInput(); 
		hideDiv("communicationBox"); 
		var newBox = document.createElement("div");
		newBox.className = "deleteable";
		currentRef.appendChild(newBox); 
		newBox.style.padding = "6px";
		newBox.innerHTML = inputResults; 
	}

	function setBackgroundColor() {
		arrayOfElementsForCommunicationBox.set("backgroundColorPicker", "none"); 
		arrayOfElementsForCommunicationBox.set("typeYourText", "Choose a color above, or put the hex value for a color below (don't include pound sign: f0f000 is sufficient for yellow"); 
		arrayOfElementsForCommunicationBox.set("inputBox", "882222"); 
		arrayOfElementsForCommunicationBox.setCallBack("setBackgroundColorAction"); 
		askForInput();
		return false; 
	}

	function setBackgroundColorAction() {
		var inputResults = getInput(); 
		hideDiv("communicationBox"); 
		var color = "#" + inputResults; 
		currentRef.style.backgroundColor = color; 		
	}
	
	function setColor() {
		arrayOfElementsForCommunicationBox.set("colorPicker", "none"); 
		arrayOfElementsForCommunicationBox.set("typeYourText", "Choose a color above, or put the hex value for a color below (don't include pound sign: f0f000 is sufficient for yellow"); 
		arrayOfElementsForCommunicationBox.set("inputBox", "660000"); 
		arrayOfElementsForCommunicationBox.setCallBack("setColorAction"); 
		askForInput();
		return false; 
	}
	
	function setColorAction() {
		var inputResults = getInput(); 
		hideDiv("communicationBox"); 
		var color = "#" + inputResults; 
		currentRef.style.color = color;		
	}


	function changeColor(referenceToElementJustClicked) {
		// 02-07-06 - first, let's make the communications box disappear.
		var referenceToTheCommunicationsBox = allHtmlReferencesObject.get("communicationBox");	
		referenceToTheCommunicationsBox.style.display = "none"; 
		
		// 02-07-06 - now we will get the color of whatever was just clicked, and then
		// we will assign that to whatever box was last clicked in (which should have set
		// the currentRef to that box). 
		var color = referenceToElementJustClicked.style.backgroundColor;
		currentRef.style.color = color;		
		return false; 
	}
	

	function changeBackgroundColor(referenceToElementJustClicked) {
		// 02-07-06 - first, let's make the communications box disappear.
		var referenceToTheCommunicationsBox = allHtmlReferencesObject.get("communicationBox");	
		referenceToTheCommunicationsBox.style.display = "none"; 
		
		// 02-07-06 - now we will get the color of whatever was just clicked, and then
		// we will assign that to whatever box was last clicked in (which should have set
		// the currentRef to that box). 
		var color = referenceToElementJustClicked.style.backgroundColor;
		currentRef.style.backgroundColor = color;		
		return false; 
	}
	
	
	function setElementInCommunicationBox(idOfElementToSet) {
		var refToCommunicationBox = allHtmlReferencesObject.get("communicationBox");
		var refToElement = allHtmlReferencesObject.get(idOfElementToSet);
		refToCommunicationBox.appendChild(refToElement); 
		refToElement.style.display = "block"; 	
	}

	
	
		
	function askForInput() {
		// 02-12-06 - for clarity's sake, the first thing we do is remove all the boxes
		// inside of the communicationBox. I originally tried managing this by adding
		// and removing elements one at a time, but this is quite difficult. For instance,
		// FireFox counts white space as a text node, and IE does not, to the two 
		// browsers end up with different counts regarding how many child nodes there
		// are. So it is best to delete them all, and then rebuilt the dialog box
		// you'd like to present, from scratch. 
		
		clearCommunicationBox();
		var referenceToCommunicationsBox = allHtmlReferencesObject.get("communicationBox"); 
		
		var callBack = arrayOfElementsForCommunicationBox.getCallBack(); 
		var elementsToGoInCommunicationBox = arrayOfElementsForCommunicationBox.get(); 
		arrayOfElementsForCommunicationBox.reset(); 
	
		for (var idOfElement in elementsToGoInCommunicationBox) {
			var initialValueForElement = elementsToGoInCommunicationBox[idOfElement];
			var referenceToElementToBeAdded = allHtmlReferencesObject.get(idOfElement); 
			
			// 02-12-06 - if this item has a child, let's assume we are dealing with a 
			// paragraph and must set the intitial value in its child text node. Otherwise, 
			// let's assume we are dealing with a textarea and set its value directly. 
			//
			// 02-14-06 - maybe there is a more elegant way to do this, but I'm worried about
			// the value of backgroundColorPicker and colorPicker getting wiped out if we assign
			// a value to their element or the child element (which should be their text node?).
			// So we need a way to say "do not assign an initial value" and so I'm going to go 
			// with the word "none" and I'll place this next if block here to watch for it. You
			// can see me using the word "none" as the initial value in the function setBackgroundColor().
			if (initialValueForElement != "none") {
				if (referenceToElementToBeAdded.firstChild) {
					referenceToElementToBeAdded.firstChild.nodeValue = initialValueForElement;
				} else {
					referenceToElementToBeAdded.value = initialValueForElement;
				}
			}
			referenceToCommunicationsBox.appendChild(referenceToElementToBeAdded); 
		}
		if (callBack != "" && callBack != undefined) {
			var submitButton = "<input type=\"button\" value=\"submit\" onClick=\"" +  callBack   + "(); return false;\"> ";
			var cancelButton = "<input type=\"button\" value=\"cancel\" onClick=\"hideDiv('communicationBox'); return false;\">";
			var paragraphNodeForButtons = document.createElement("p");
			paragraphNodeForButtons.id = "submitCancelButtons"; 
			paragraphNodeForButtons.innerHTML = submitButton + cancelButton; 
			referenceToCommunicationsBox.appendChild(paragraphNodeForButtons); 
		}
		makeCommunicationBoxElementsVisible();
	}

	
	function makeCommunicationBoxElementsVisible() {
		// 02-14-06 -this is called at the end of askForInput() and it makes the communicationBox
		// visible, plus all the elements inside of the communication box. 
		var referenceToCommunicationsBox = allHtmlReferencesObject.get("communicationBox"); 
		var howManyChildren = referenceToCommunicationsBox.childNodes.length; 
		
		for (i=0; i < howManyChildren; i++) {
			var refToChild = referenceToCommunicationsBox.childNodes[i];
			if (refToChild.nodeName.toLowerCase() == "div") refToChild.style.display = "block"; 
			if (refToChild.nodeName.toLowerCase() == "p") refToChild.style.display = "block"; 
			if (refToChild.nodeName.toLowerCase() == "textarea") refToChild.style.display = "inline"; 
			if (refToChild.nodeName.toLowerCase() == "input") refToChild.style.display = "inline"; 
		}
		
		referenceToCommunicationsBox.style.display = "block"; 
	}
	
	
	function getInput() {
		// 02-13-06 - most of the time when users input some info, they'll be using the TEXTAREA with
		// the id of "inputBox". This function is the default function for getting info out of that
		// textarea. You can see it used in functions like setTextAction, which is what is called 
		// if you click the "submit" button after setText() creates a dialog box.
		var area = allHtmlReferencesObject.get("inputBox");
		var input = area.value; 
		area.value = "";
		return input; 
	}

	function moveController(divReference) {
		// 02-13-06 - the main divs that create the page have "moveController" as their function to call
		// onClick(), so any time there is click in one of those boxes, this fires and moves the control box.
		currentRef = divReference; 
		var newId = currentRef.id; 
		moveBoxToMouseCoordinates("controller");
		return false; 
	}
	
	function moveDeleteControls(e) {
		if (!e) var e = window.event;
		var eventTargetRef = e.target; 
		if (!eventTargetRef) eventTargetRef = e.srcElement;
		var targetsClassName = eventTargetRef.className;
		window.status = targetsClassName; 
		if (targetsClassName == "deleteable") {
			currentDeleteRef = eventTargetRef;
			moveBoxToMouseCoordinates('deleteBox');
		}
	}
	
	function deleteItem() {
		// 02-13-06 - when the user mouses over an element of the class "deletable" then the 
		// variable currentDeleteRef is set to be a reference to the item just moused over. Also,
		// the delete control box is moved to where the cursor is. The user can click the "delete"
		// link in the control box if they wish to remove the element they've just moused over.
		// Clicking the link calls this function, which deletes the element moused over and
		// then makes the delete controls invisible again. 
		allHtmlReferencesObject.remove(currentDeleteRef);
		var refDeleteBox = allHtmlReferencesObject.get("deleteBox");
		refDeleteBox.style.display = "none"; 
	}

	function moveBoxToMouseCoordinates(boxName) {
		var newTop = tempY + 3;
		var newLeft = tempX + 3;
		var controllerRef = allHtmlReferencesObject.get(boxName);
		if (!controllerRef.parentNode) {
			document.body.appendChild(controllerRef);	
		}
		controllerRef.style.opacity = "0"; 
		controllerRef.style.display = "block"; 
		controllerRef.style.top = newTop + "px";
		controllerRef.style.left = newLeft + "px";
		fadeInElement(controllerRef); 
	}

	
	function clearCommunicationBox() {
		// 02-14-06 - this is suppose to delete all the elements in the communicationBox, so that the 
		// next dialog box can be built anew using the values in arrayOfElementsForCommunicationBox.
		// If this function ever seems to be failing, give a careful look at arrayOfElementsForCommunicationBox
		// and see if somehow a value in it is surviving till the next iteration. 
		if (document.getElementById) {
			var refToCommunicationBox = allHtmlReferencesObject.get("communicationBox");
			if 	(refToCommunicationBox) {
				var howManyNodes = refToCommunicationBox.childNodes.length; 
				for (i=0; i < howManyNodes; i++) {
					var refToFirstChild = refToCommunicationBox.firstChild;
					var newId = refToFirstChild.id; 
					refToCommunicationBox.removeChild(refToFirstChild); 	
				}
			} else {
				alert("Sorry, but this page has no communication box.");	
			}
		} else {
			alert("So sorry, but your web browser doesn't support features that this page needs to run."); 	
		}
	}
	
	

 
	function hideDiv(divId) {
		var divRef = allHtmlReferencesObject.get(divId);
		divRef.style.display = "none"; 
		return false; 
	}
	
	function hideAllExtras() {
		hideDiv('deleteBox');
		// hideDiv('communicationBox');	
	}
	
	function removeItem(itemId) {
		var referenceToItem = allHtmlReferencesObject.get(itemId);
		var referenceToParent = referenceToItem.parentNode;
		referenceToParent.removeChild(referenceToItem); 		
	}
	
	function addItem(idOfParentItem, typeOfItem) {
		// 02-14-06 - we use this to quickly add something to a box. I'm not
		// sure we should really be doing this, but as an example, we add 
		// a div to communication box in savePage(), but doing this:
		//
		// referenceToNewDiv = addItem("communicationBox", "div");
		//
		var referenceToParentItem = allHtmlReferencesObject.get(idOfParentItem);
		var referenceToNewItem = document.createElement(typeOfItem);
		referenceToParentItem.appendChild(referenceToNewItem);
		return referenceToNewItem;
	}
	
	
	function savePage() {
		hideDiv("communicationBox");
		hideDiv("controller");
		hideDiv("deleteBox");
		var pageContent = document.documentElement.innerHTML; 
		
		// 02-07-06 - right the page is only saving till the first ampersand, then
		// it dies. As near as I can figure out, Prototype breaks the parameters
		// apart based on the ampersand. So I'll need to replace the ampersands 
		// with some special string and then reconvert that string in the PHP. 
		pageContent = encodeURIComponent(pageContent);
	
		askForInput(); 
		referenceToNewDiv = addItem("communicationBox", "div");
		referenceToNewDiv.id = "showSaveResults";
		
		var url = 'savePage.php';
		var pars = 'pageText=' + pageContent;
		var target = 'showSaveResults';
		var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars});
		
		return false; 
	}
	
	
	function seeAllPages() {
		// 02-08-06 - we want people to be able to see all the other pages that
		// other people have done. So we will close some boxes, then add a new
		// div with the name "showAllPages" and then we will call our PHP script
		// again, with variable set to get back a list of all the files in the 
		// axajText folder. The PHP script should return a big string, all
		// the files wrapped in the HTML needed to make the path names into
		// links. 
		askForInput(); 
		referenceToNewDiv = addItem("communicationBox", "div");
		referenceToNewDiv.id = "showAllPages";
		referenceToNewDiv.style.fontSize = "15px";
		
		var url = 'savePage.php';
		var pars = 'showAllPages=all';
		var target = 'showAllPages';
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
		
		return false; 
	}

	
	function callLater(paramA, paramB, paramC) {
		// 02-12-06 - I'm taking this code from jibbering.com's essay on closures. You
		// can use it to hand a function reference to setTimeout(), so as to have
		// some value set in the future. An example would be:
		//
		// var functRef = callLater(elementReference, "display", "none"); 
		// hideMenu = setTimeout(functRef, 500);	
		
		return (function() {
			paramA[paramB] = paramC; 	
		})
	}
	
	function callFadeToElement() {
		var referenceToElement = globalReferenceToCurrentElementToBeFadedIn; 
		fadeInElement(referenceToElement);
	} 
	
	function fadeInElement(referenceToElement) {
		var currentOpacity = referenceToElement.style.opacity;
		referenceToElement.style.display = "block"; 
	//	alert(referenceToElement.id);
		if (parseFloat(currentOpacity) < 1) {
			var newValue = parseFloat(currentOpacity) + parseFloat(.2);
			currentOpacity = newValue;
			referenceToElement.style.opacity = currentOpacity; 
			globalReferenceToCurrentElementToBeFadedIn = referenceToElement;
			setTimeout("callFadeToElement()", 140);
		} 
	}
	
	
	
		
	function fadeOutElement(referenceToElement) {
		var currentOpacity = referenceToElement.style.opacity;
		if (parseFloat(currentOpacity) > 0) {
			var newValue = parseFloat(currentOpacity) - parseFloat(.1);
			currentOpacity = newValue;
			referenceToElement.style.opacity = currentOpacity; 
			globalReferenceToCurrentElementToBeFadedIn = referenceToElement;
			setTimeout("callFadeOutElement()", 230);
		} else {
			referenceToElement.style.display = "none";
		}
	}
	
	
	
	function callFadeOutElement() {
		var referenceToElement = globalReferenceToCurrentElementToBeFadedIn; 
		fadeOutElement(referenceToElement);
	}
		
	
	function deleteThisItem(idOfEntry, idOfHtmlContainer) {
		// 05-14-06 - we use this function on arrangements like adminlistPagesToEditNav.php, it's 
		// called onClick and should use AJAX to call CommandStandardDelete on output.php and delete 
		// the item in question. 
		//
		// idOfEntry, the first parameter, is the id of the record in the database that needs to be deleted
		//
		// idOfHtmlContainer is the id of the thing on the page we'd like to make invisible.
		//
		// I've tested this linke and it successfully deleted an item from the trash and gave a
		// message back to the user: 
		//
		// output.php?command[]=standardDelete&cbIdDel[]=102&command[]=showUserMessages
		//
		// We will want to use this link to delete the item and return a message to the user. 	
		//
		// 05-15-06 - we are changing the url, we want to now use a command that deletes an item
		// and all the items that belong to it: 
		//
		// output.php?command[]=DeleteAllChildPages&cbIdDel[]=163&command[]=showUserMessages
		//		
		
		
		var targetDiv = "targetForPublic" + idOfEntry; 

		if (document.getElementById(idOfEntry)) {
			// 08-22-06 - I read this next line and went, what? Like I've really got an 
			// item with an id that's just a number? But apparently I do: 
			//
			// <a title="Trash this item" href="#" onClick="deleteThisItem('530', 'mainFieldSet33');"><img src="/images/cms/icon_trash.gif" alt="Trash this item" /></a>
			// <input type="hidden" id="530" value="Are you sure you want to delete 'Gabriel Goldstein'?" />
			//
			var alertMessageInputReference = document.getElementById(idOfEntry);
			var alertMessageString = alertMessageInputReference.value; 
			var answer = confirm(alertMessageString);
			
			if (answer) {
				var url = 'output.php';
				var pars = 'command[]=DeleteAllChildPages&command[]=UpdateRssForEntry&formInputs[cbId]=' + idOfEntry + '&cbIdDel[]=' + idOfEntry + '&command[]=showUserMessages';
				var target = targetDiv;
				var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
		//		alert (pars);
				
				var referenceToItemToFade = document.getElementById(idOfHtmlContainer); 
				referenceToItemToFade.style.opacity = 1;
				fadeOutElement(referenceToItemToFade);
			}
		} else {
			alert("Error: we were suppose to find item " + idOfEntry + " on this page, but we could not."); 	
		}
	}	
	
	
		
		
			
	
	
	function checkLogin() {
		// 05-21-06 - I did this in March for that nightmare at bluecasts.com. Peter
		// wanted every screen for Digitial Distributor in that damn light box. 
		
		if (!document.getElementById) {
			alert("So sorry, but your browser doesn't support parts of Javascript that this page depends on"); 
			return false; 	
		}
		
		if (document.getElementById("output-div")) {
			var refToOutputDiv = document.getElementById("output-div");
		} else {
			alert("This page has no DIV called 'output-div'"); 	
			return false; 
		}
		
		if (document.getElementById("username")) {
			var refToUsername = document.getElementById("username");
		} else {
			alert("This page has no DIV called 'username'"); 	
			return false; 
		}
		
				
		if (document.getElementById("password")) {
			var refToPassword = document.getElementById("password");
		} else {
			alert("This page has no DIV called 'password'"); 	
			return false; 
		}
		
		
		var possibleUsername = refToUsername.value; 
		var possibilePassword = refToPassword.value; 
		
		if (possibleUsername != "" && possibilePassword != "") {
			var url = 'http://www.bluecasts.com/checkLogin.php';
			var pars = "username=" + possibleUsername + "&password=" + possibilePassword;
			
			new Ajax.Request(url, {
				 onSuccess : function(resp) {	 			
					var outputDivContentsString = resp.responseText;
					if (outputDivContentsString.match(/Sorry/ig)) {
						refToOutputDiv.innerHTML = outputDivContentsString;
						return false; 	
					} else {
						location.href = outputDivContentsString;
						return false; 
					}
				 },
				 onFailure : function(resp) {
				   alert("Oops, there's been an error.");
				 },
				 parameters : pars
				}
			);
			
		} else {
			refToOutputDiv.innerHTML = "<p>Sorry, please fill in both the username and the password.</p>";
			return false; 
		}
		return false; 
	}
	
	
	
	
	
	
	
	
	
	
	function checkFormForEmtptyFields(field1, field2, field3, field4, field5, field6, field7, field8) {
		// 02-24-06 - add the names of the fields you want checked by passing in the id of the 
		// field as one of the parameters to this function. 
		var listOfFieldsToCheck = new Array(); 
		
		// 02-25-06 - this will be the warning to the user if they've left blank fields. 
		var warning = "";

		if (field1 != "" && field1 != undefined) listOfFieldsToCheck.push(field1); 
		if (field2 != "" && field2 != undefined) listOfFieldsToCheck.push(field2); 
		if (field3 != "" && field3 != undefined) listOfFieldsToCheck.push(field3); 
		if (field4 != "" && field4 != undefined) listOfFieldsToCheck.push(field4); 
		if (field5 != "" && field5 != undefined) listOfFieldsToCheck.push(field5); 
		if (field6 != "" && field6 != undefined) listOfFieldsToCheck.push(field6); 
		if (field7 != "" && field7 != undefined) listOfFieldsToCheck.push(field7); 
		if (field8 != "" && field8 != undefined) listOfFieldsToCheck.push(field8); 
		
		// 02-24-06 - we start off with the assumption that the form will be submitted. 
		// Only if one of the fields is blank will we set submitTheForm to false. 
		var submitTheForm = true; 
		var howMany = listOfFieldsToCheck.length;
		
		for (i=0; i < howMany; i++) {
			// 02-24-06 - we loop through the list, going in this circle for as
			// many times as the length of the list. If there are 6 items in 
			// the list, then we loop 6 times. We use the variable "i" to keep
			// track of how many times we've looped, and which item we should 
			// be getting out of the list. 
			var idOfField = listOfFieldsToCheck[i];

			// 02-24-06 - we want to get the vaule of the element in the form that
			// we happen to be looping over just now. So we get a reference to that
			// element, by using its id, and then we get the value. 
			var inputReference = document.getElementById(idOfField);
			if (inputReference != "" && inputReference != undefined) {
				var inputValue = inputReference.value; 
	
				// 02-24-06 - if the value of this field is empty or undefined, we 
				// don't want to submit the form. So the variable submitTheForm should
				// be set to false, and the name of this item should be stored in a 
				// a variable so we can use it in the error message that we will be 
				// flashing on screen for the user. 
				if (inputValue == "" || inputValue == undefined) {
					submitTheForm = false; 
					warning += " You left the '" + idOfField + "' field empty. "; 
				}
			} else {
				alert(idOfField + "didn't match any fields on this form. Please warn the website owner of this error."); 	
			}
		}
		
		if (submitTheForm == true) {
			submitAnyForm(formId);
		} else {
			warning += introText; 
			alert(warning); 			
		}
		return submitTheForm; 
	}
	

	function submitAnyForm(myform) {
		if (document.getElementById(myform)) {
			var formReference = document.getElementById(myform); 
			if (formReference) {
		//		if (formReference.elements["choiceMade"]) {
		//			var choiceMade = formReference.elements["choiceMade"];
		//			var choiceValue = choiceMade.value;
		//			alert(choiceValue); 
		//		}
				// 03-23-06 - getting a weird error - "Error: [Exception... "'Permission denied to set 
				// property XULElement.selectedIndex' when calling method: 
				// [nsIAutoCompletePopup::selectedIndex]"  
				// nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)"  
				// location: "JS frame :: http://www.bluecasts.com/pdsIncludes/pdsAjax.js :: submitAnyForm :: line 626"  data: no]
				// Source File: http://www.bluecasts.com/pdsIncludes/pdsAjax.js
				// Line: 626
				// so I'm adding this next check to make sure the reference has a method called "submit".
				if (formReference.submit) {
					formReference.submit();
				} else {
					alert("There is no submit method for the form " + myform); 
				}
			} else {
				alert("The element" + myform + " was not a form. We got this: " + formReference);	
			}
		} else {
			alert("We could not find a form called " + myform);	
		}
	}

	

	
	
	/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassNameNyman(oElm, strTagName, strClassName){
	// To get all elements within in the document with a click-me class.
	//    getElementsByClassNameNyman(document, "*", "click-me");
	
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}






function checkFormForEmptyFields() {
	var requiredInputsArray = getElementsByClassNameNyman(document, "*", "requiredfield");
	var numberOfFieldsToCheck = requiredInputsArray.length; 
	
	var submitFormBool = true; 
	var errorMessageString = "";
	
	for (var i=0; i < numberOfFieldsToCheck; i++) {
		var inputIdString = requiredInputsArray[i];
		var idOfInputToCheckString = inputIdString.value; 
		var inputToCheckReference = document.getElementById(idOfInputToCheckString);
		if (inputToCheckReference != false && inputToCheckReference != undefined) {
			var theTypeOfTheInputString = inputToCheckReference.type; 
			if (theTypeOfTheInputString == "select-one") {
				var valueOfInputToCheckString = inputToCheckReference.options[inputToCheckReference.selectedIndex].value;
			} else {
				var valueOfInputToCheckString = inputToCheckReference.value; 		
			}			
			
			var nameOfInputToCheckString = inputIdString.name; 
			
			if (valueOfInputToCheckString == "" || valueOfInputToCheckString == undefined) {
				submitFormBool = false; 
				errorMessageString += "\nYou forgot to fill in " + nameOfInputToCheckString;
			}
		} else {
			alert(idOfInputToCheckString + " does not exist "); 
		}
	}
	
	if (submitFormBool) {
		return true;
	} else {
		alert(errorMessageString);
		return false;
	}
	
	return false; 
}

	

function checkFormForOneOfARangeOfNeededCharacters() {
	var requiredInputsArray = getElementsByClassNameNyman(document, "*", "controlledRange");
	var numberOfFieldsToCheck = requiredInputsArray.length; 
	
	var submitFormBool = true; 
	var errorMessageString = "";
	
	for (var i=0; i < numberOfFieldsToCheck; i++) {
		
		
	}
	
	if (submitFormBool) {
		return true;
	} else {
		alert(errorMessageStoredInThisInputString);
		return false;
	}	
}
	



function getAllFormElementsWithACertainClass(formId, desiredClassName) {
// document.forms[number].elements[number]	
	if (document.getElementById) {
		if (document.getElementById(formId)) {
			var formReference = document.getElementById(formId);
			var formElementsArray = formReference.elements;
			var howManyElementsInFormInteger = formElementsArray.length;
			var elementsWithCertainClassArray = new Array(); 
			
			for (var i=0; i < howManyElementsInFormInteger; i++) {
				var thisElementFromForm = formElementsArray[i];
				var classOfThisElementString = thisElementFromForm.className;
				if (desiredClassName == classOfThisElementString) {
					elementsWithCertainClassArray.push(thisElementFromForm); 
				}
			}
			
			return elementsWithCertainClassArray;
		}	
	}
}



function checkFormForNeededCharacters() {
	// 08-13-06 - we use this on pages like this: 
	//
	// http://www.monkeyclaus.org/artists/mcControlPanel.php?arrangement=createBandsForm
	//
	// for instance, we check the 'biopic' input for the string '.jpg': 
	//
	// <input type="hidden" value=".jpg" class="needed" rel="biopic" errormessage="Your bio picture must be in .jpg format" />
	//
	
	var requiredInputsArray = getElementsByClassNameNyman(document, "*", "needed");
	var numberOfFieldsToCheck = requiredInputsArray.length; 
	
	var submitFormBool = true; 
	var errorMessageString = "";
	
	for (var i=0; i < numberOfFieldsToCheck; i++) {
		var hiddenInputIdString = requiredInputsArray[i];
		var idOfInputToCheckString = hiddenInputIdString.getAttribute('rel');
		var errorMessageStoredInThisInputString = hiddenInputIdString.getAttribute('errormessage');

		var stringOfManyCharactersThatArePossiblyNeededForThisField = hiddenInputIdString.value; 
		var arrayOfStringsWeShouldCheckFor = stringOfManyCharactersThatArePossiblyNeededForThisField.split(",");
		var howManyStringsToCheckFor = arrayOfStringsWeShouldCheckFor.length; 
		
		
		// 08-15-06 - Abel just called me and complained that he could not upload an image that ended with
		// ".jpg", only with ".JPG". Yet on the page for creating bands, we'v this: 
		// 
		// <input type="hidden" value=".jpg,.JPG" class="needed" rel="biopic" errormessage="Your bio picture must be in .jpg format" />
		// 
		// why is only the last ".JPG" working, and not the first ".jpg"? because we keep looping below
		// checking every part of the arrayOfStringsWeShouldCheckFor. I'm going to add a flag 
		// called thisItemChecksOutFine, which will stop the below loop as soon as we have a match. 
		// 

		var thisItemChecksOutFine = false; 
		for (var r=0; r < howManyStringsToCheckFor; r++) {
			if (thisItemChecksOutFine == false) {
				var characterThatsNeededForThisField = arrayOfStringsWeShouldCheckFor[r];
				
				var idsOfInputsWeShouldCheckArray = idOfInputToCheckString.split(",");
				var idOfFirstInputThatWeShouldCheckString = idsOfInputsWeShouldCheckArray[0];
				
				var inputToCheckReference = document.getElementById(idOfFirstInputThatWeShouldCheckString);
				if (inputToCheckReference != false && inputToCheckReference != undefined) {
					var theTypeOfTheInputString = inputToCheckReference.type; 
					if (theTypeOfTheInputString == "select-one") {
						var valueOfInputToCheckString = inputToCheckReference.options[inputToCheckReference.selectedIndex].value;
					} else {
						var valueOfInputToCheckString = inputToCheckReference.value; 		
					}
					
					// 08-13-06 - this next line is where we look and see if the characters that are needed in this 
					// field actually show up in this field. 
					if (valueOfInputToCheckString.indexOf(characterThatsNeededForThisField) == -1){ 
						submitFormBool = false; 
						var nameOfInputToCheckString = inputToCheckReference.id; 
						errorMessageString += "\nIn " + nameOfInputToCheckString + " we expected to see '" + characterThatsNeededForThisField + "'";
						
						// 08-15-06 - I forget what all the rest of this is for. We're checking a second input? 
						var idOfSecondInputThatWeShouldCheckString = idsOfInputsWeShouldCheckArray[1];
						
						var inputToCheckReference = document.getElementById(idOfSecondInputThatWeShouldCheckString);
						if (inputToCheckReference != false && inputToCheckReference != undefined) {
							var theTypeOfTheInputString = inputToCheckReference.type; 
							if (theTypeOfTheInputString == "select-one") {
								var valueOfInputToCheckString = inputToCheckReference.options[inputToCheckReference.selectedIndex].value;
							} else {
								var valueOfInputToCheckString = inputToCheckReference.value; 		
							}
							
							if (valueOfInputToCheckString.indexOf(characterThatsNeededForThisField) == -1){ 
								submitFormBool = false; 
								var nameOfInputToCheckString = inputToCheckReference.id; 
								errorMessageString += "\n" + errorMessageStoredInThisInputString;
							} else {
								submitFormBool = true; 
							}
						} else {			
							// 06-01-06 - this is not an error if there is no second item.
							//
						//	alert("Neither " + idOfFirstInputThatWeShouldCheckString + " nor " + idOfSecondInputThatWeShouldCheckString + "  exist "); 
						//	submitFormBool = false; 
						}
					} else {
						thisItemChecksOutFine = true; 
						submitFormBool = true; 
					}
				} else {
					submitFormBool = false;
					alert(idOfFirstInputThatWeShouldCheckString + " did not exist"); 
				} 
			} // closes if() statement for thisItemChecksOutFine
		} // for loop ends
	}
	
	if (submitFormBool) {
		return true;
	} else {
		alert(errorMessageStoredInThisInputString);
		return false;
	}	
}


function checkFormForForbiddenCharacters() {
	var requiredInputsArray = getElementsByClassNameNyman(document, "*", "forbidden");
	var numberOfFieldsToCheck = requiredInputsArray.length; 
	
	var submitFormBool = true; 
	var errorMessageString = "";
	
	for (var i=0; i < numberOfFieldsToCheck; i++) {
		var hiddenInputIdString = requiredInputsArray[i];
		var idOfInputToCheckString = hiddenInputIdString.getAttribute('rel');
		var errorMessageStoredInThisInputString = hiddenInputIdString.getAttribute('errormessage');

		var characterThatsNeededForThisField = hiddenInputIdString.value; 
		
		var idsOfInputsWeShouldCheckArray = idOfInputToCheckString.split(",");
		var idOfFirstInputThatWeShouldCheckString = idsOfInputsWeShouldCheckArray[0];
		
		var inputToCheckReference = document.getElementById(idOfFirstInputThatWeShouldCheckString);
		if (inputToCheckReference != false && inputToCheckReference != undefined) {
			var theTypeOfTheInputString = inputToCheckReference.type; 
			if (theTypeOfTheInputString == "select-one") {
				var valueOfInputToCheckString = inputToCheckReference.options[inputToCheckReference.selectedIndex].value;
			} else {
				var valueOfInputToCheckString = inputToCheckReference.value; 		
			}
			
			if (valueOfInputToCheckString.indexOf(characterThatsNeededForThisField) != -1){ 
				submitFormBool = false; 
				var nameOfInputToCheckString = inputToCheckReference.id; 
				errorMessageString += "\nIn " + nameOfInputToCheckString + " we don't expect to see '" + characterThatsNeededForThisField + "'";
				
							
				var idOfSecondInputThatWeShouldCheckString = idsOfInputsWeShouldCheckArray[1];
				
				var inputToCheckReference = document.getElementById(idOfSecondInputThatWeShouldCheckString);
				if (inputToCheckReference != false && inputToCheckReference != undefined) {
					var theTypeOfTheInputString = inputToCheckReference.type; 
					if (theTypeOfTheInputString == "select-one") {
						var valueOfInputToCheckString = inputToCheckReference.options[inputToCheckReference.selectedIndex].value;
					} else {
						var valueOfInputToCheckString = inputToCheckReference.value; 		
					}
					
					if (valueOfInputToCheckString.indexOf(characterThatsNeededForThisField) != -1){ 
						submitFormBool = false; 
						var nameOfInputToCheckString = inputToCheckReference.id; 
						errorMessageString += "\nIn " + nameOfInputToCheckString + " we don't expect to see '" + characterThatsNeededForThisField + "'";
					} else {
						submitFormBool = true; 
					}
				} else {
					// 05-31-06 - this isn't an error if there is no second item
					//			
				//	alert("Neither " + idOfFirstInputThatWeShouldCheckString + " nor " + idOfSecondInputThatWeShouldCheckString + "  exist "); 
				//	submitFormBool = false; 
				}
			} else {
				submitFormBool = true; 
			}
		} else {
			submitFormBool = false;
			alert(idOfFirstInputThatWeShouldCheckString + " did not exist"); 
		} 
	}
	
	if (submitFormBool) {
		return true;
	} else {
		alert(errorMessageStoredInThisInputString);
		return false;
	}	
}





function addImageToDiv(imageName, divId) {
	var divReference = document.getElementById(divId);
	var imageTagString = "<img src='" + imageName + "'>";
	divReference.innerHTML = imageTagString;
}




function showEntriesForThisPage(idOfInputToGetInfoFrom, idOfTargetDiv, whichType, arrangementToUse) {
	// 05-15-06 - the first parameter names the form element we are suppose to get
	// a value from. 	
	//
	// The second parameter is the type of information we are suppose to get back from the
	// database.
	//
	// This link has been tested and it works: 
	//
	// output.php?command[]=GetEntriesWithCertainValue&certainField=cbBelongsToWhichPage&certainValue=182&certainArrangement=listPagesToEdit&certainType=weblogEntries
	//
	//
	//
	 
	addImageToDiv("/images/cms/loading.gif", "pageEntries");
	
	var refToInput = document.getElementById(idOfInputToGetInfoFrom); 
	var inputValue = refToInput.value; 

	var url = 'output.php';
	var pars = 'command[]=GetEntriesWithCertainValue&certainField=cbBelongsToWhichPage&certainValue=' + inputValue + '&certainArrangement=' + arrangementToUse + '&certainType=' + whichType ;
	var target = idOfTargetDiv;
	var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
	
	var referenceToElement = document.getElementById(idOfTargetDiv); 
	fadeInElement(referenceToElement);
	
}
		



function updateLivePreview() {
	if (document.getElementById && document.getElementById('cmsform')) {
		var cmsFormReference = document.getElementById('cmsform');
		var allElementsInFormArray = cmsFormReference.elements; 
		var parametersToBeSentString = "";
		parametersToBeSentString += "command[]=GetArrangement&getWhatArrangement="; 
					
		if (document.getElementById('previewArrangement')) {
			var previewArrangementReference = document.getElementById('previewArrangement'); 
			parametersToBeSentString += previewArrangementReference.value; 
			
			for (var i=0; i < allElementsInFormArray.length; i++) {
				var thisInputReference = allElementsInFormArray[i];
				var thisInputType = thisInputReference.type; 
				if (thisInputType == "text" || thisInputType == "textarea" || thisInputType == "select") {
					var thisInputNameString = thisInputReference.name; 
					var thisInputValueString = thisInputReference.value; 
					if (thisInputNameString != "" && thisInputNameString != undefined) {
						// example of string replace s = s.replace(/&/g,"*am*");
						thisInputNameString = thisInputNameString.replace(/formInputs/g, "");
						thisInputNameString = thisInputNameString.replace(/\[/g, "");
						thisInputNameString = thisInputNameString.replace(/\]/g, "");
						
						parametersToBeSentString += "&";
						parametersToBeSentString += thisInputNameString;
						parametersToBeSentString += "=";
						parametersToBeSentString += thisInputValueString;
					}
				}
			}
		}
		
		parametersToBeSentString += "&pageId=xxx"; 
			
		if (document.getElementById("livepreview")) {
			var preLive = document.getElementById("livepreview"); 
			preLive.style.display = "block"; 
			
			//	var testDiv = document.getElementById("testing"); 
			//	testDiv.style.display = "block"; 
			//	testDiv.innerHTML = parametersToBeSentString;
				
			var url = 'output.php';
			var pars = parametersToBeSentString;
			var target = "livepreview";
			var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
		}		
	}
}



function simpleLivePreview(blockElementWhoseContentsWeShouldGet, blockElementThatWeShouldWriteTo) {
	// 07-08-06 - this function is much simpler than some of the other live preview functions that we have
	// in this javascript library. This simply takes the value of some form field (the first parameter)
	// and then writes it as the innerHTML of another element (the second parameter). 	

	if (document.getElementById && document.getElementById(blockElementWhoseContentsWeShouldGet)) {
		var elementToGetReference = document.getElementById(blockElementWhoseContentsWeShouldGet);
		var contentsOfElementToGetString = elementToGetReference.value;
		contentsOfElementToGetString = nl2br_js(contentsOfElementToGetString);
		
		if (document.getElementById(blockElementThatWeShouldWriteTo)) {
			var elementToWriteToReference = document.getElementById(blockElementThatWeShouldWriteTo);
			elementToWriteToReference.innerHTML = contentsOfElementToGetString;
		} else {
			alert("Error: there was no element on the page called: " + blockElementThatWeShouldWriteTo);	
		}
	} else {
		alert("Error: there was no element on the page called: " + 	blockElementWhoseContentsWeShouldGet);
	}
}




/*
	05-18-06 - another bit by Robert Nyman - potentially, I could use getElementByName to get
	all inputs and textareas on the on a page and for onkeyup, attach updateLivePreview

				http://www.robertnyman.com/2006/03/23/ajax-javascript-and-accessibility/
				
				window.onload = applyEvents;
				function applyEvents(){
				    if(document.getElementById && document.getElementsByTagName){
				        var arrAllLinks = document.getElementsByTagName("input");
				        var oLink;
				        for(var i=0; i<arrAllLinks.length; i++){
				            oLink = arrAllLinks[i];
				            
			                oLink.onkeyup = function (oEvent){
			                    var oEvent = (typeof oEvent != "undefined")? oEvent : event;
			                    oEvent.returnValue = false;
			                    if(oEvent.preventDefault){
			                        oEvent.preventDefault();
			                    }
			                    document.getElementById("my-details").className = "display-block";
		               		}			            
				        }
				    }
				}
				
*/
				
				

function submitEmailForm() {
	// 08-26-06 - created to deal with the multiple checkbox inputs on this page:
	//
	// http://www.monkeyclaus.org/artists/mcControlPanel.php?arrangement=sendEmail

	// 01-19-07 - I'd just like to say that this is the most insane thing I've ever seen.
	// I'd also like to apologize to whatever programmer needs to come along after me and 
	// clean this thing up. We have a form, at the URL above, that has 3 forms. The submit
	// button for the first form is actually inside of 3rd form. This unusual situation 
	// arose because of my habit of saying "yes" to anyone who makes a request of me. 
	// Darren wanted to keep the form visually looking a certain way. However, I thought 
	// it would be neat if the the email lists (which are listed in the second form) 
	// could be edited live. HTML does not allow forms to be nested. Therefore, if the 
	// email addresses were to be edited live, the middle part of the page needed to be
	// its own form. That means the top part of the page also needed to be its own form
	// and the bottom part of the page also needed to be its own form. That means that
	// when the user clicks the submit button at the bottom of the page, the information
	// from the other two forms need to be captured. The first form contains the subject
	// line, the text of the message, the return address, and whether this email should
	// be plain text or html. The second form on the page contains the email addresses 
	// that we should send to. The third form on the page contains a lot of hidden
	// inputs, plus the submit button. In the file pdsEvents.js we override the default
	// submit function for the third form (the only one that the user can submit). We have
	// this function, submitEmailForm(), called instead. It needs to gather the correct
	// data from the first and second forms, store that data in hidden inputs in the
	// third form, and then submit the form. 

	// 01-19-07 - this is an array of checkboxes, that tell us if we should use 
	// the associated textarea. 
	var arrayOfTextareasWithEmailsToSendTo = getAllFormElementsWithACertainClass("sendEmailForm2", "textareaOfEmailsForNewletters");	
	var howManyTextareasToCheck = arrayOfTextareasWithEmailsToSendTo.length;
	var stringFullOfAllAccumulatedEmails = ""; 
	
	for (var i=0; i < arrayOfTextareasWithEmailsToSendTo.length; i++) {
		var thisCheckboxToExamine = arrayOfTextareasWithEmailsToSendTo[i];
		
		// what we need to check looks like this: 
		// if (box.checked == false) box.checked = true;
		var isThisCheckboxChecked = thisCheckboxToExamine.checked;
		
		if (isThisCheckboxChecked == true) {
			// the textareas we want have ids like id="emailLists[439]"
			var numberWhichWeWillUseToCreateId = thisCheckboxToExamine.value; 
			var idOfTextarea = "emailLists[" + numberWhichWeWillUseToCreateId  +   "]";
			var referenceToTextareaWithEmails = document.getElementById(idOfTextarea); 			
			stringFullOfAllAccumulatedEmails += referenceToTextareaWithEmails.value; 
			
		}
	}
	var referenceToHiddenInputThatListsAllEmails = document.getElementById("listOfEmails"); 
	referenceToHiddenInputThatListsAllEmails.value = stringFullOfAllAccumulatedEmails;

if (document.getElementById("emailSubject")) {
	var referenceToInput = document.getElementById("emailSubject"); 
	var valueToTransfer = referenceToInput.value;
	var newReference = document.getElementById("newEmailSubject");
	newReference.value = valueToTransfer;
} else {
	alert("This form should have an  input with an id of emailSubject but it doesn't."); 
}
	
if (document.getElementById("htmlEmail1") && document.getElementById("htmlEmail2")) {
	var referenceToInput = document.getElementById("htmlEmail1"); 
	var referenceToOtherInput = document.getElementById("htmlEmail2");
	var valueToTransfer = referenceToInput.value;
	var valueToTransfer2 = referenceToOtherInput.value; 
	var newReference = document.getElementById("newHtmlEmail");
	if (valueToTransfer) newReference.value = valueToTransfer;
	if (valueToTransfer2) newReference.value = valueToTransfer2;
} else {
	alert("This form should have an input with an id of htmlEmail1 and htmlEmail2 but it doesn't."); 
}
	
	
if (document.getElementById("mainContentTextarea")) {
	var referenceToInput = document.getElementById("mainContentTextarea"); 
	var valueToTransfer = referenceToInput.value;
	//alert ("we will transfer " + valueToTransfer); 
	var newReference = document.getElementById("newMainContentTextarea");
	newReference.value = valueToTransfer;
} else {
	alert("This form should have an input with an id of mainContentTextarea but it doesn't.") 
}

if (document.getElementById("returnAddress")) {
	var referenceToInput = document.getElementById("returnAddress"); 
	var valueToTransfer = referenceToInput.value;
	var newReference = document.getElementById("newReturnAddress");
	newReference.value = valueToTransfer;
} else {
	alert("This form should have an input with an id of returnAddress but it doesn't."); 	
}
	
if (document.getElementById("tag1")) {
	var referenceToInput = document.getElementById("tag1"); 
	var valueToTransfer = referenceToInput.value;
	var newReference = document.getElementById("newTag1");
	newReference.value = valueToTransfer;
} else {
	alert("This form should have an input with an id of tag1 but it doesn't."); 
}
	
	
	
	submitAnyForm("sendEmailForm2");
	
	return false; 	
}






















function makePublic(idOfEntry, privacy) {
	// 10-03 -06 - this item is based on deleteThisItem, so see that function for more
	// details. 
	//
	// I've tested this linke and it successfully deleted an item from the trash and gave a
	// message back to the user: 
	//
	// output.php?command[]=standardDelete&cbIdDel[]=102&command[]=showUserMessages
	//
	// We will want to use this link to delete the item and return a message to the user. 	
	
	var targetDiv = "targetForPublic" + idOfEntry; 
	var url = 'output.php';
	var pars = 'command[]=UpdateIsRoughDraft&cbId=' + idOfEntry + '&cbIsRoughDraft=' + privacy + '&command[]=UpdateRssForEntry&formInputs[cbId]=' + idOfEntry ;
	
	if (document.getElementById(targetDiv)) {		
		var referenceToItemToFade = document.getElementById(targetDiv); 
		referenceToItemToFade.innerHTML = "";
		referenceToItemToFade.style.display = "block"; 
		referenceToItemToFade.style.opacity = 1; 
		var target = targetDiv;
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
		
		referenceToItemToFade.style.opacity = 1;
		fadeOutElement(referenceToItemToFade);
	} else {
		alert("Error: this page doesn't have a DIV called targetForPublic" + idOfEntry + " but it should so that we have a place to put a message."); 
	}
}	





function makePublicButNoRss(idOfEntry) {
	// 10-11-06 - Abel Okugawa would like it if we could make an item public (so it shows up on a page)
	// yet keep it out of the RSS feeds. Last week I attempted to do this using makePublic. I had two 
	// AJAX calls, one to make sure the item was public, another to force makeRSS to make the feed
	// without the item. However, I was tripped up by the asynchronus nature of AJAX. The calls did not
	// always execute the order I wanted. To make that happen, I will need to drop into synchronous code, 
	// which means I need to do those two calls from PHP. That requires a new Javascript function, which
	// is why I'm writing this. (See the Javascript makePublic() for more detals.)
	
	
	var targetDiv = "targetForPublic" + idOfEntry; 
	var url = 'output.php';
	// var pars = 'command[]=UpdateIsRoughDraft&cbId=' + idOfEntry + '&cbIsRoughDraft=' + privacy + '&noFeed=' + noFeed + '&command[]=UpdateRssForEntry&formInputs[cbId]=' + idOfEntry ;
	var pars = 'command[]=UpdatePublicNoRss&cbId=' + idOfEntry + '&noFeed=noFeed' ;
	
	if (document.getElementById(targetDiv)) {		
		var referenceToItemToFade = document.getElementById(targetDiv); 
		referenceToItemToFade.innerHTML = "";
		referenceToItemToFade.style.display = "block"; 
		referenceToItemToFade.style.opacity = 1; 
		var target = targetDiv;
		var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
		
		referenceToItemToFade.style.opacity = 1;
		fadeOutElement(referenceToItemToFade);
	} else {
		alert("Error: this page doesn't have a DIV called targetForPublic" + idOfEntry + " but it should so that we have a place to put a message."); 
	}
}



