
function changeBg(span) {
	span.style.backgroundImage = "url(images/nav_item_bg_hover.png)";
} //function changeBg -- highlights the navbar item


function returnBg(span) {
	span.style.backgroundImage = "url(images/nav_item_bg.png)";
} //function returnBg -- turns the navbar item back to gray


function validatePollForm(frm) {
	var children = frm.elements; // get an array of the form's elements
	var completed = false;
	for(x=0; x<children.length; x++) {
		if(children[x].type == "radio") {
			var child = children[x];
			if(child.checked == true) {
				openWindow('','poll_window','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,top=200,left=200,width=500,height=320');
				return true;
				break;
			}
		} // check to see if the form child is a text field
	} // loop through the form elements
	alert("Please select an option before voting.");
	return completed;
} //function validatePollForm -- checks to make sure that there is a valid vote option selected before submitting the form


<!--- START THE USER ACCOUNT VALIDATION FORM -->
    function validateUserForm(frm) {
        return (checkRequired(frm) &&
                checkPassword(frm) &&
                checkEmail(frm) &&
                checkPhoneFax(frm.phone)); // run through the necessary validation checks before submitting form data
    } //function validateUserForm
	
	function showError(field, error) {
		alert(error); // alert the user of the specific error
		field.select(); // highlight the field with the error
		return false; // return the false
	} //function showError
	
	function checkRequired(frm) {
		var children = frm.elements; // get an array of the form elements
		var blank;
		for(x=0; x<children.length; x++) { // loop through the form's elements
			<!-- CHECK THIS BY IDs -->
			childname = children[x].name;
			if((childname.substring(0,3) == "req") && ((children[x].value == "") || (children[x].value == null) || (children[x].value == blank))) { // check to see if the required fields are filled
				return showError(children[x], "Please fill in all of the required fields."); // show error message
				break;
			}
		}
		return true; // return if all required forms have data entered
	} /*checkRequired */
	
	function checkPassword(frm) {
		if(frm.password.value != frm.verify_password.value) { // check to see if password and re-entered password match
			return showError(frm.verify_password, "Your passwords do not match.  Please re-enter and verify your password.");
		}
		else { return true; } // return true if the passwords match.
	} /* checkPassword */
	
	function checkEmail(frm) {
		var field = frm.email;
		field.value = field.value.toLowerCase();
		var email = field.value; // get the entered text from the Email field
		var error = "Please enter a valid e-mail address."; // error message to send if email address isn't valid
		if((email.indexOf("@") > 1) && (email.indexOf("@") < (email.length-4))) { // check to see if there is an "@" in the address
			var parts = email.split("@"); // divide the email address into two parts: the username and the domain
			var name = parts[0];
			var domain = parts[1];
			var invalidchars = /[!#$%^&*()+=?~`'"}{|, :;]/; // create a list of invalid characters to use in checks
			if((name.length >= 2) && (domain.length >= 4) && (name.search(invalidchars) == -1)) {
				var domainparts = domain.split("."); // split the domain into as many parts as appropriate
				endingdomain = /(com)|(net)|(edu)|(gov)|(us)|(uk)|(ca)|(mil)|(biz)|(info)|(mx)/; // list of valid top-level domains
				if((domainparts[domainparts.length-1].search(endingdomain) == -1) || (domainparts.length == 1)) { // check the top-level domain
					return showError(field, error);
				}
				else {
				 	for (x=0; x<domainparts.length; x++) {
						if((domainparts[x].length < 2) || (domainparts[x].search(invalidchars) != -1)) { // check to make sure that there are at least second and top-level valid domains
							return showError(field, error);
						}
					} // loop through the parts of the domain
					return true;
				}				
			}
			else { return showError(field, error); }
		}
		else { return showError(field, error); }
	} /* checkEmail */
	
	function checkPhoneFax(field) {
		if((field.name == "phone") || ((field.name == "fax") && (field.value.length > 0))) { // if no Fax number has been entered, skip this check
			var error = "Please enter a valid U.S. phone number (ex. 123-456-7890).";
			var parts = field.value.split("-"); // split the phone number by -'s into an array
			if(parts.length == 3) { // make sure that there are three sets of numbers, area code and two other sets 
				if((parts[0].length != 3) || (parts[0].search(/^\d{3}$/) == -1)) { // check the first number set
					return showError(field, error);
				}
				if((parts[1].length != 3) || (parts[1].search(/^\d{3}$/) == -1)) { // check the second number set
					return showError(field, error);
				}
				if((parts[2].length != 4) || (parts[2].search(/^\d{4}$/) == -1)) { // check the third number set
					return showError(field, error);
				}
				else { return true; }		
			}
			else { return showError(field, error); }
		}
	} /* checkPhoneFax */

<!--- END THE USER ACCOUNT VALIDATION FORM -->


function viewPollResults(pollID) {
	clickpop = window.open("poll_results.php?pollID="+pollID,"poll_window","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,top=200,left=200,width=500,height=330");
	clickpop.focus();
} //function viewPollResults -- pops up the results for a given poll


function openWindow(url, windowname, parameters) {
	//alert(url);
	popup = window.open(url,windowname,parameters);
	popup.focus();
} //function openWindow -- this opens up a window with the given parameters


function emailToAFriend(url) {
	openWindow("email_to_a_friend.php?url="+url,'email_to_a_friend','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,top=200,left=200,width=450,height=450');
} //function emailToAFriend -- sends an email to a friend, with a link to the desired page.


function validateLoginForm(frm) {
	if (frm.userID.value=="") {
		alert("Please enter your User ID.");
		frm.userID.focus();
		return false;
	}
	if (frm.password.value=="") {
		alert("Please enter your password.");
		frm.password.focus();
		return false;
	}
	else { return true; }
} //function validateLoginForm -- makes sure that the user has entered a user ID and password


function validateSendEmailForm(frm) {
	if(frm.sendersEmail.value=="") {
		alert("Please enter your e-mail address.  We respect your privacy, and will not store or keep your e-mail address.");
		frm.sendersEmail.focus();
		return false;
	}
	if(frm.receivingEmail.value=="") {
		alert("Please enter the e-mail addresses of your recipient(s).  We respect their privacy, and will not store or keep their e-mail addresses.");
		frm.receivingEmail.focus();
		return false;
	}
	if(frm.message.value=="") {
		alert("Please enter a message.");
		frm.message.focus();
		return false;
	}
	else { return true; }
} //function validateSendEmailForm -- checks to make sure that the user has completely filled in the send an email form.


function validateNewPoll(frm) {
	if(frm.question.value == "") {
		alert("Please enter in the poll question.");
		frm.question.focus();
		return false
	}
	if(frm.answer1.value == "") {
		alert("Please enter the first possible answer.");
		frm.answer1.focus();
		return false;
	}
	if(frm.answer2.value == "") {
		alert("Please enter the second possible answer.");
		frm.answer2.focus();
		return false;
	}
	else { return true; }
} //function validateNewPoll -- checks to make sure that the new poll has the sufficient information necessary


function validateNewBlog(frm) {
	if(frm.blogtitle.value == "") {
		alert("Please enter a title for your blog.");
		frm.blogtitle.focus();
		return false;
	}
	else { return true; }
}


function validateBlogEntry(frm) {
	if (frm.title.value=="") {
		alert("Please enter a title.");
		frm.title.focus();
		return false;
	}
	if (frm.text.value=="") {
		alert("Did you forget to write something?  The message is blank.");
		frm.text.focus();
		return false;
	}
	else { return true; }
} //validateBlogEntry -- checks to make sure that there is a title and an actual entry written before submitting to the database.


function trimField(field) {
	var value = field.value; // get the text in the field	
	var start = 0; // keeps track of the starting point to trim
	var end = value.length; // get the original string's length
	while(value.charAt(start) == " ") {
		start++; // increase the trim starting point
	}
	while(value.charAt(end-1) == " ") {
		end--; // decrease the length of the string to be trimmed
	}
	if(end == 0) {
		field.value = "";
	} else {
		field.value = value.substring(start,end); // return the trimmed string
	}
} //function trimField


