function validate(requiredform) {
	var why = "";
	why += checkEmail(requiredform.email.value);
	why += checkUsername(requiredform.realname.value);
	why += isEmpty(requiredform.question.value, "Your question");

	if (why != "") {
		alert(why);
		return false;
	}
	return true;
}

function checkEmail (strng) {
	var error="";
	if (strng == "") {
		error = "You didn't enter a contact email address.\n";
	}
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		error = "Please enter a valid contact email address.\n";
	} else {
		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if (strng.match(illegalChars)) {
			error = "The contact email address contains illegal characters.\n";
		}
	}
	return error;    
}

// username - 4-10 chars, uc, lc, and underscore only.
function checkUsername (strng) {
	var error = "";
	if (strng == "") {
		error = "You didn't enter a contact name.\n";
	}
	return error;
}       

// non-empty textbox
function isEmpty(strng, cntrl) {
	var error = "";

	if (strng.length == 0 || strng == "??") {
		error = "You must enter a value for '" + cntrl +"'.\n"
	}
	return error;
}


// Ok, if the source is 'friend' or 'guide', then 
// ensure the 'who' row is visible.
function checksource(source) {
	
	if( source.value == "guide" ) {
		alert("Please enter the name of the guide that referred you to us.");
		
		var x=document.getElementById("referrer_extra");
		x.select();
		
	} else {
		var x=document.getElementById("question");
		x.select();
	}
	
	return true;
}
