function validUsername(str) {
	var re_username = /^\w[\w\.\-_]*$/;
	return re_username.test(str);
}

function validHostname(str) {
	var re_hostname = /^(\w[\w\-]*\.)+[A-Za-z]{2,4}$/;
	return re_hostname.test(str);
}

function validEmail(str) {
	if (str == "") return false;
	var match = str.match(/^([^@]+)@([^@]+)$/);
	if (!match) return false;
	return validUsername(match[1]) && (validHostname(match[2]) || validIPAddress(match[2]));
}

function checkForm(dform) {
	var canSubmit = true;
	var errors = "The following fields must be filled in:\n";
	
	if (dform.vname.value == '') {
		errors += "Your name.\n";
		canSubmit = false;
	}
	
	if (!validEmail(dform.emailaddress.value)) {
		errors += "Your email address.\n";
		canSubmit = false;
	}
	
	if (dform.phonenum.value == '') {
		errors += "Your phone number.\n";
		canSubmit = false;
	}
	
	if (dform.volunteer.selectedIndex == 0) {
		errors += "You must select a volunteer option.\n";
		canSubmit = false;
	}
	
	if (canSubmit == false) {
		alert(errors);
		return false;
	} else {
		return true;
	}
}

var currentDescription = 0;

function displayDescription(obj) {
	if (currentDescription != 0) {
		document.getElementById("desc" + currentDescription).style.display = 'none';
	}
	
	if (obj.options[obj.selectedIndex].value != "na") {
		document.getElementById("desc" + obj.options[obj.selectedIndex].value).style.display = 'block';
		currentDescription = obj.options[obj.selectedIndex].value;
	} else {
		currentDescription = 0;
	}
}
