function updateSelectField(select_form, current_field) {
	var field_found = 0;
	
	for (x = 0; x <= select_form.length; x++) {
		if (select_form.options[x].value == current_field) {
		field_found = x;
		break;
		}
	}
	select_form.options.selectedIndex = field_found;
}

function validate_activity_selection(theform) {
	
	var age = theform.age_group.options[theform.age_group.options.selectedIndex].value;
	var subject = theform.subject_specific.options[theform.subject_specific.options.selectedIndex].value;
	
	if (age == "") {
		alert("Please select an age group");
		theform.age_group.focus();
		return false;
	}
	else if (subject == "") {
		alert("Please select a topic");
		theform.subject_specific.focus();
		return false;
	}
	else return true;

}

function validateComment(theform) {

var comment = theform.comment.value;

//g = perform a global match
//cleaning empty space and emoticons code
var comment_cleaned = comment.replace(/\s+/g, '');
var real_comment_length = comment_cleaned.length;

if (comment == "") {
	alert("Please insert your comment");
	theform.comment.focus();
	return false;
}
else if ((real_comment_length < 15) || (comment.length < 15)) {
	alert("Your comment has " + real_comment_length + " characters, the minimum is 15.\nPlease compose a more complete sentence.");
	theform.comment.focus();
	return false;
}
else if (comment == comment.toUpperCase()) { //avoiding all upper case posts

	alert("Please don't post in all uppercase, it is considered shouting");
	theform.comment.focus();
	return false;	
}

return true;
}

function add_starter(theform) {
	
if (theform.starters.value) { 
	if (theform.comment.value == "") theform.comment.value = theform.starters.value;
	else theform.comment.value = theform.comment.value + "\n\n" + theform.starters.value;
	theform.comment.focus();
}

}


function validate_registration(theform) {
	
	var username = theform.username.value;
	var emailaddress = theform.emailaddress.value;
	var password = theform.password.value;
	var password2 = theform.password2.value;
	var timezone = theform.timezone.options[theform.timezone.options.selectedIndex].value;
	var terms=theform.terms;
	
	if ((username == "" ) || (username.length > 30 )) {
		alert("Your username is empty or over the maximum of 30 characters");
		theform.username.focus();
		return false;
	} 
	else if ((emailaddress == "") || (emailaddress.length > 100 )) {
		alert("Your email address is empty or over the maximum of 100 characters");
		theform.emailaddress.focus();
		return false;
	}
	
	else if ((password == "") || (password.length > 20 )) {
		alert("Your password is empty or over the maximum of 20 characters");
		theform.password.focus();
		return false;
	} 
	
	else if (password != password2) {
		alert("Your password confirmation is not identical to your first password");
		theform.password2.focus();
		return false;
	}
	
	else if (timezone == "") {
		alert("Please select your timezone");
		theform.timezone.focus();
		return false;
	}
	
	else if (terms.checked == false) {
		alert("You must read and agree to our terms and conditions before signing up");
		theform.terms.focus();
		return false;
	}
	
	else return true;
	
}

function toggleDisplay(divID) {
	if (divID.style.display == "none") divID.style.display = "block";
	else divID.style.display = "none";
}
