function Navigation() {
	this.currentURL;
	
	this.update = function(uri) {
		// set the current url
		this.currentURL = uri;
		
		// grab all the nav items
		var items = $('#nav').children('ul').children('li');
		
		for (var i=0; i < items.length; i++) {
			var a = $(items[i]).children('a');
			if (this.currentURL.indexOf($(a).attr('href')) != -1) {
				// for the current item, make it always highlighted
				$(a).css('background-position', '0px -23px');
			} else {
				// for non-current items, make it highlight on mouseover
				$(a).mouseover(function() { $(this).css('background-position', '0px -23px'); });
				$(a).mouseout(function() { $(this).css('background-position', '0px 0px'); });
			}
		}
	};
};

function Newsletter() {
	this.show = function() {
		var pop = window.open("newsletter.php", "newsletter", "");
	}
}

function Volunteer() {
	this.valid = true;
	this.errorMsg = "";
	
	this.validate = function(frm) {
		this.checkExists(frm.firstname.value, "Please enter your first name.");
		this.checkExists(frm.lastname.value, "Please enter your last name.");
		this.checkExists(frm.phone.value, "Please enter your phone number.");
		this.checkExists(frm.email.value, "Please enter your email address.");
		
		// if there are errors, show the message and clear the errors
		if (!this.valid) {
			alert(this.errorMsg);
			this.valid = true;
			this.errorMsg = "";
			return false;
		}

		// no errors, so go ahead and submit
		return true;
	}
	
	this.checkExists = function(val, err) {
		if (val == "")
			this.addError(err);
	}
	
	this.addError = function(errStr) {
		this.errorMsg += errStr + '\n';
		this.valid = false;
	}
}






var nav = new Navigation();
var newsletter = new Newsletter();
var volunteer = new Volunteer();









/* Newsletter sign up code */
function subscribe() {
	if (testInput()) {
		document.inputForm.Mode.value='update';
		document.inputForm.submit();
	}
}

function unsubscribe() {
	if (testInput()) {
		document.inputForm.Mode.value='unsubscribe';
		document.inputForm.submit();
	}
}

function testInput() {
var Email =  new String(document.inputForm.Email.value); 
var Correct = true; 
CharCount=1; 
strLength=Email.length; 
while ((CharCount < strLength) && (Email.charAt(CharCount) != '@')) 
{ 
	CharCount++ 
} 
if ((CharCount>= strLength) || (Email.charAt(CharCount) != '@'))  
{  
	alert ('Email address is not valid.') 
	Correct = false; 
	return false;
} 
else 
{ 
	CharCount += 2; 
} 
while ((CharCount < strLength) && (Email.charAt(CharCount) != '.')) 
{ 
	CharCount++ 
} 
if ((CharCount>= strLength - 1) || (Email.charAt(CharCount) != '.')) 
{ 
	alert ('Email address is not valid.') 
	Correct = false; 
	return false;
} 
return Correct 
} 
