function isEmailString(InString)
{
	if(InString.length==0) return false;
	var filter 	= /^.+@.+\..{2,3}$/;
	if (filter.test(InString))return true;
	else
	{
		return false;
	}
}
function isAwkwardString(InString)
{
	if(InString.length==0) return false;
	var RefString="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
	for (Count=0; Count < InString.length; Count++)
	{
		TempChar = InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)
		return false;
	}
	return true;
}
function validateForm(thisForm)
{
	if(isAwkwardString(thisForm.username.value) == 0){
		alert ("Please provide a username, only use letters numbers and underscores");
		thisForm.username.focus();
		return false;
	} else if(thisForm.password != undefined && isAwkwardString(thisForm.password.value) == 0){
		alert ("Please enter a valid password, only use letters numbers and underscores");
		thisForm.password.focus();
		return false;
	} else if(thisForm.password_confirm != undefined && isAwkwardString(thisForm.password_confirm.value) == 0){
		alert ("Please confirm your password, only use letters numbers and underscores");
		thisForm.password_confirm.focus();
		return false;
	} else if(thisForm.password != undefined && thisForm.password_confirm != undefined  && thisForm.password_confirm.value != thisForm.password.value){
		alert ("Please type your password and confirm it again. Your password fields do not match");
		thisForm.password_confirm.focus();
		return false;
	} else if(thisForm.forename.value == ""){
		alert ("Please enter your Forename");
		thisForm.forename.focus();
		return false;
	} else if(thisForm.surname.value == ""){
		alert ("Please enter your Surname");
		thisForm.surname.focus();
		return false;
	} else if (isEmailString (thisForm.email.value) == 0){
		alert ("Please enter a valid email");
		thisForm.email.focus();
		return false;
	} else if(thisForm.profession.value == ""){
		alert ("Please enter your Profession");
		thisForm.profession.focus();
		return false;
	} else if(thisForm.company_name.value == ""){
		alert ("Please enter your Surgery Name");
		thisForm.company_name.focus();
		return false;
	} else if(thisForm.company_address.value == ""){
		alert ("Please enter your Surgery Address");
		thisForm.company_address.focus();
		return false;
	} else if(thisForm.source[3].checked && thisForm.othersource.value == ""){
		alert ("Please enter \"How did you hear about the site?\"");
		thisForm.othersource.focus();
		return false;
	} else {
		return true;
	}
}
function validateFormPt2(thisForm)
{
	if(thisForm.username[2].checked && isAwkwardString(thisForm.othername.value) == 0){
		alert ("Please provide a username, only use letters numbers and underscores");
		thisForm.othername.focus();
		return false;
	} else {
		return true;
	}
}
function validateSettings(thisForm)
{
	if(thisForm.password != undefined && isAwkwardString(thisForm.password.value) == 0){
		alert ("Please enter a valid password, only use letters numbers and underscores");
		thisForm.password.focus();
		return false;
	} else if(thisForm.password_confirm != undefined && isAwkwardString(thisForm.password_confirm.value) == 0){
		alert ("Please confirm your password, only use letters numbers and underscores");
		thisForm.password_confirm.focus();
		return false;
	} else if(thisForm.password != undefined && thisForm.password_confirm != undefined  && thisForm.password_confirm.value != thisForm.password.value){
		alert ("Please type your password and confirm it again. Your password fields do not match");
		thisForm.password_confirm.focus();
		return false;
	} else if(thisForm.forename.value == ""){
		alert ("Please enter your Forename");
		thisForm.forename.focus();
		return false;
	} else if(thisForm.surname.value == ""){
		alert ("Please enter your Surname");
		thisForm.surname.focus();
		return false;
	} else if (isEmailString (thisForm.email.value) == 0){
		alert ("Please enter a valid email");
		thisForm.email.focus();
		return false;
	} else if(thisForm.profession.value == ""){
		alert ("Please enter your Profession");
		thisForm.profession.focus();
		return false;
	} else if(thisForm.company_name.value == ""){
		alert ("Please enter your Surgery Name");
		thisForm.company_name.focus();
		return false;
	} else if(thisForm.company_address.value == ""){
		alert ("Please enter your Surgery Address");
		thisForm.company_address.focus();
		return false;
	} else if(thisForm.source[3].checked && thisForm.othersource.value == ""){
		alert ("Please enter \"How did you hear about the site?\"");
		thisForm.othersource.focus();
		return false;
	} else {
		return true;
	}
}
function validateLogin(thisForm)
{
	if(thisForm.username.value == ""){
		alert ("Please enter your Username");
		thisForm.username.focus();
		return false;
	} else if(thisForm.password.value == ""){
		alert ("Please enter your Password");
		thisForm.password.focus();
		return false;
	} else {
		return true;
	}
}
function validateLostPassword(thisForm)
{
	if(thisForm.username.value == ""){
		alert ("Please enter your Username");
		thisForm.username.focus();
		return false;
	} else {
		return true;
	}
}
