

	//	determines what goes in the help popup
	function openHelpPage(help_do) {
	
//		alert("help_do: " + help_do);	
	
		var help_text = "";
		var help_header = "";
		switch(help_do) {
		
			case "advanced_search":
				help_header = "Advanced Search";
				help_text = "Using an Advanced Search allows you to override your Search Settings for a specific search without having to change your overall search preferences.";
			break;
		
			case "search_settings":
				help_header = "Search Settings";
				help_text = "Search Settings allow you to customize your search results for your specific writing needs, search style and computer capabilities.  Choose the material (eg. Main Stylebook, Sports Guidelines, Business, etc.) you are interested in to refine the results. In addition, you can control the number of results per page so if your computer is slow, you can limit the number of results per page to make pages load quicker.";
			break;
		
			case "new_user_entry":
				help_header = "New User Entry";
				help_text = "APStylebook.com also allows you to store and search your own style entries and examples as part of this searchable online system. This is valuable if you follow style guidelines you want to keep track of and search as part of this Web-based system.";
			break;
		
			case "my_stylebook":
				help_header = "My Stylebook";
				help_text = "Build your own custom stylebook illustrated with your own examples and references to maintain your personal or organization's specialized stylebook.";
			break;
		
			case "my_stylebook_notes":
				help_header = "My AP Stylebook Notes";
				help_text = "Customize the AP Stylebook with your own examples and notes without \"writing in the margins.\" Your notes will then appear at the bottom of the AP Stylebook entry itself for quick retrieval.";
			break;
		
			case "categories":
				help_header = "Style Categories";
				help_text = "Find the style material you desire with this listing of popular entries from the AP Stylebook. Quickly find listings by chapter or view all prefixes, suffixes or punctuation marks.";
			break;
		
			case "settings":
				help_header = "Site Settings";
				help_text = "Site Settings allow you to control the appearance of stylebook material to accommodate your computer, monitor and text size preferences. If italic type is difficult to read on your computer, simply change to an alternative format. Change font faces, sizes and colors.<br><br>NOTE: Changing Anti-Aliasing settings in ATM Control Panel can also help control text appearance.";
			break;
		
			case "account":
				help_header = "Account Manager";
				help_text = "The Account Manager lets you make changes to your username, password, email and more. Use this area when you need to update your contact information. In addition, you can Opt Out of receiving emails from apstylebook.com.";
			break;
		
			case "search_results":
				help_header = "Search Results";
				help_text = "Your search results are sorted with the highest scoring results at the beginning.  If you search returns more results than the number of results per page (see <b></b>), you have the option to narrow or expand the results by filtering case sensitivity and whether your search looks inside words or matches your search words exactly.";
			break;
		
			case "notes":
				help_header = "AP Stylebook Notes";
				help_text = "Customize the AP Stylebook with your own examples and notes without \"writing in the margins.\" Your notes will then appear at the bottom of the AP Stylebook entry itself for quick retrieval.";
			break;
			case "entry":
				help_header = "AP Stylebook Entry";
				help_text = "AP Stylebook entries appear much like they do in the stylebook, along with any notes you've added.  You can also remove or edit these notes at anytime.";
			break;
		
			case "limited_html":
				help_header = "Limited HTML OK";
				help_text = "If you are familiar with <HTML> coding, you can incorporate some commands to add links, images and text effects to your entries. Acceptable <HTML> commands include anchors, image calls (hosted elsewhere), line breaks, paragraph marks, etc. For more information on HTML, please visit <b><a href='http://hotwired.lycos.com/webmonkey/authoring/html_basics/' target='_blank'>Webmonkey</a></b>.";
			break;
		
			case "user_entry":
				help_header = "User Entry";
				help_text = "Build your own custom stylebook illustrated with your own examples and references to maintain your personal or organization's specialized stylebook.";
			break;
				
			case "":
				help_header = "Home Page";
				help_text = "The home page allows you to browse the various site sections and navigate to where you want to go.";
			break;
				
			
			
			default:
				help_header = "AP Stylebook Online";
				help_text = "There is no Help text for this page.";
			
			break;

		}
		//	end switch


		var ret_html = "<div class='ap_help_image'><div class='ap_help_text'><div class='ap_help_close'><a href='javascript:closeHelpPage(\"ap_help\")'><img src='/images/close_icon.gif' alt='close' /></a></div><span class='ap_help_header'>" + help_header + "</span><br />" + help_text + "</div></div>";

		updatePageClasses("ap_help");
		document.getElementById("ap_help").innerHTML = ret_html;

	}








	/**
	 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
	 */
	
	function echeck(str) {
	
			var at="@"
			var dot="."
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			   alert("Invalid E-mail ID")
			   return false
			}
	
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			   alert("Invalid E-mail ID")
			   return false
			}
	
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
				alert("Invalid E-mail ID")
				return false
			}
	
			 if (str.indexOf(at,(lat+1))!=-1){
				alert("Invalid E-mail ID")
				return false
			 }
	
			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
				alert("Invalid E-mail ID")
				return false
			 }
	
			 if (str.indexOf(dot,(lat+2))==-1){
				alert("Invalid E-mail ID")
				return false
			 }
			
			 if (str.indexOf(" ")!=-1){
				alert("Invalid E-mail ID")
				return false
			 }
	
			 return true					
	}
	


	
	function validNewQ() {

		//	confirm question submission
		var question = document.submit_question.style_question.value;
		if (question == "") {
			alert("Please submit a question -- the question text area was left blank.");
			document.submit_question.style_question.focus();
			return false;
		}

		var email = document.submit_question.email.value;
		if (email == "") {
			alert("You must enter an e-mail address.");
			document.submit_question.email.focus();
			return false;
		}

	
		if (echeck(document.submit_question.email.value)==false) {
			document.submit_question.email.focus();
			return false;
		}
		
	}
	





	function clearLoginText(f,t,d){
	  if(d == ""){ d = 0; }
	  var doc = document.forms[d];
	  var ele = doc.elements[f].value;
	  
	  if (d=="editor_login" && f=="user_name" && t=="username") {
	  	window.document.editor_login.user_name.value = "";
	  }
	  if (d=="editor_login" && f=="password" && t=="********") {
	  	window.document.editor_login.password.value = "";
	  }

	  if (d=="ind_login" && f=="user_name" && t=="username") {
	  	window.document.ind_login.user_name.value = "";
	  }
	  if (d=="ind_login" && f=="password" && t=="********") {
	  	window.document.ind_login.password.value = "";
	  }
	  
	  if(ele == t){
//		doc.elements[f].value = "";
	  }
	}
	
	






	//	top-window name
//	window.document.name = "apstylebook_main";



	//	build the XMLHttpRequest
	var request = false;
	
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = false;
			}  
		}
	}

	if (!request) {
		alert("Error initializing XMLHttpRequest! You will need to use another browser to use this site.");
	}
	//	end the XMLHttpRequest




	//	FUNCTIONS FOR SENDING REQUEST

	//	search the system
	function openPage(page, target, offset, chapter) {
	
		var url = "/ajax_requests.php?do=" + escape(page) + "&target=" + escape(target) + "&offset=" + escape(offset) + "&chapter=" + escape(chapter);
		request.open("GET", url, true);
		request.onreadystatechange = updatePage;
		request.send(null);
	
	}




	//	orig: ask-the-editor functions

	//	view a single question
	function question(qid) {
//		var question_id = qid;
		var url = "ask_editor_requests.php?do=question&question_id=" + escape(qid);
		request.open("GET", url, true);
		request.onreadystatechange = updatePage;
		request.send(null);
	}


	//	update a single question
	function questionUpdate(qid) {
		var msg = "Update this question?";
		if (confirm(msg)) {
			var question = document.getElementById("question").value;
			var response = document.getElementById("response").value;
			var email = document.getElementById("email").value;
			var location = document.getElementById("location").value;
			
			var category_index = document.getElementById("category").selectedIndex;
			var category = document.getElementById("category").options[category_index].value;

			var publish_it = "N";
			if (document.getElementById("publish_it").checked) {
				publish_it = "Y";
			}
			var faq = "N";
			if (document.getElementById("faq").checked) {
				faq = "Y";
			}
			
			var url = "ask_editor_requests.php?do=update_question&question_id=" + escape(qid) + "&question=" + escape(question) + "&response=" + escape(response) + "&email=" + escape(email) + "&location=" + escape(location) + "&publish_it=" + escape(publish_it) + "&category=" + escape(category) + "&faq=" + escape(faq) + "";

			request.open("GET", url, true);
			request.onreadystatechange = updatePage;
			request.send(null);
		}
	}


	//	delete a single question
	function questionDelete(qid) {
		var msg = "Really delete this Ask the Editor question?";
		if (confirm(msg)) {
			var url = "ask_editor_requests.php?do=delete_question&question_id=" + escape(qid);
			request.open("GET", url, true);
			request.onreadystatechange = updatePage;
			request.send(null);
		}
	}


	//	search the system
	function searchQuestions() {
	
		var search_term = document.getElementById("search_term").value;
		var url = "ask_editor_requests.php?do=search&search_term=" + escape(search_term);
		request.open("GET", url, true);
		request.onreadystatechange = updatePage;
		request.send(null);
	
	}



	//	view a list of questions, with type, offset and results_count (limit)
	function viewList(type, offset, total) {
		
		//	get results count per page from select
		var results_count_index = document.getElementById("results_count").selectedIndex;
		var results_count = document.getElementById("results_count").options[results_count_index].value;
		
		var url = "ask_editor_requests.php?do=list&type=" + escape(type) + "&offset=" + escape(offset) + "&results_count=" + escape(results_count) + "&total=" + escape(total) + "";
		request.open("GET", url, true);
		request.onreadystatechange = updatePage;
		request.send(null);
	}


	//	view all from an e-mail
	function userEntries(email) {
		var url = "ask_editor_requests.php?do=user_entries&email=" + escape(email);
		request.open("GET", url, true);
		request.onreadystatechange = updatePage;
		request.send(null);
	}





	//	get server response
	function updatePage() {

		if (request.readyState == 4) {
			if (request.status == 200) {

//	alert(request.responseText);

				//	get the text and the target
				var response = request.responseText.split("|||");
	
				var nav_text = response[0];
				var target = response[1];

				document.getElementById("nav_bread_crumbs").innerHTML = response[0];
				document.getElementById(target).innerHTML = response[2];
				

			} else if (request.status == 404) {
				alert ("Requested URL was not found.");
			} else if (request.status == 403) {
				alert ("Access Denied.");			
			} else {
//				alert("Status is " + request.status);
				alert("There was an error connecting your request. Status is (" + request.status + ")");
			}
		}
	}
   //	end updatePage()





	function askCategoryPage() {
	
		var cat = window.document.ask_search.category.value;
		
		window.document.location = "index.php?do=ask_editor&category=" + cat;
	
	}

	function proCategoryPage() {
	
		var cat = window.document.pro_search.category.value;
		
		window.document.location = "index.php?do=pronunciation&category=" + cat;
	
	}



	function viewChapterPage(offset, chapter, result_count) {

		var new_offset = ((window.document.result_page.page.value)-0 * (result_count)-0);
		
		window.document.location = "index.php?do=chapter&offset=" + new_offset + "&chapter=" + chapter + "";
	
	}


	function viewResultPage(page_do, offset, chapter, category, search_term) {

		window.document.location = "index.php?do=" + page_do + "&offset=" + offset + "&chapter=" + chapter + "&category=" + category + "&search_term=" + search_term;
	
	}





	//	highlight on/off
	var allPageTags = new Array(); 
	function updatePageClasses(theClass) {
	
		//Populate the array with all the page tags
		var allPageTags=document.getElementsByTagName("*");
	
		//Cycle through the tags using a for loop
		for (i=0; i<allPageTags.length; i++) {
	
			//Pick out the tags with our class name
			if (allPageTags[i].className==theClass) {
	

				if (theClass=="hlt") {	

					var highlight_val = window.document.search_results.highlight.checked;
					 if (highlight_val == true) {
						allPageTags[i].style.backgroundColor="CCCCCC";
					 } else {
						allPageTags[i].style.backgroundColor="FFFFFF";
					 }

					//Manipulate this in whatever way you want
//					allPageTags[i].style.display='none';
				}


				if (theClass=="ap_help") {	
					allPageTags[i].style.visibility="visible";
				}



			}
		}
	
	}
	
	
	
	

	function closeHelpPage(theClass) {
	
		//Populate the array with all the page tags
		var allPageTags=document.getElementsByTagName("*");
	
		//Cycle through the tags using a for loop
		for (i=0; i<allPageTags.length; i++) {
	
			//Pick out the tags with our class name
			if (allPageTags[i].className==theClass) {
	

				if (theClass=="ap_help") {	
					allPageTags[i].style.visibility="hidden";
				}



			}
		}
	
	}	
