function validEmail(addr)
{
	invalidChars = " /:,;"
	if(addr == "") 
	{
		return false
	}
	for (i = 0; i < invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i)
		if(addr.indexOf(badChar, 0) != -1) 
		{
			return false
		}
	}
	atPos = addr.indexOf("@", 1)
	if(atPos == -1) 
	{
		return false
	}
	if(addr.indexOf("@", atPos + 1) != -1)
	{
		return false
	}
	periodPos = addr.indexOf(".", atPos)
	if(periodPos == -1) 
	{
		return false
	}
	if(periodPos + 3 > addr.length) 
	{
		return false
	}
	return true
}

function validPhone(id) 
{
	if(document.getElementById(id).value.length > 0)
	{
		return true;
 	} 
	else 
	{
		alert("Please ensure that you enter a valid phone number");
 		return false;
 	}
}

function noHttp(form)
{
	httpPos = form.firstname.value.indexOf("http://", 0)
	if(httpPos != -1)
	{
		return false
	}
	httpPos = form.surname.value.indexOf("http://", 0)
	if(httpPos != -1)
	{
		return false
	}
	httpPos = form.position.value.indexOf("http://", 0)
	if(httpPos != -1)
	{
		return false
	}
	httpPos = form.company.value.indexOf("http://", 0)
	if(httpPos != -1)
	{
		return false
	}
      return true
}

function doValidate(form)
{
	
	if(form.username.value.length < 6 || form.username.value.length > 20)
	{
		alert("Please ensure that you choose a username with between 6 and 20 characters")
		return false
	}
	if(form.username.value.indexOf(" ", 0) != -1) 
	{
		alert("Please ensure that you choose a username which contains no spaces")
		return false
	}
	if(form.password.value.length < 6)
	{
		alert("Please ensure that you choose a password with more than 6 characters")
		return false
	}
	if(form.password.value != form.password_confirm.value)
	{
		alert("Please ensure that you type your password correctly twice")
		return false
	}
	if(form.firstname.value.length < 1)
	{
		alert("Please tell us your first name")
		return false
	}
	if(form.surname.value.length < 1)
	{
		alert("Please tell us your last name")
		return false
	}
	if(form.position.value.length < 1)
	{
		alert("Please tell us your job title")
		return false
	}
	if(form.company.value.length < 1)
	{
		alert("Please tell us the organisation you work for")
		return false
	}
	if(!noHttp(form))
	{
		alert("In order to prevent spam you are prohibited from entering URL text into form fields")
		return false
	}
	if(!validEmail(form.email.value))
	{
		alert("Please ensure that your supplied email address is written correctly, e.g. john.doe@anon.com")
		return false
	}
	return true
}

function doValidate_change(form)
{
	if(form.pwd.value != form.old_pwd.value)
	{
		if(form.pwd.value.length < 6)
		{
			alert("Please ensure that you choose a password with more than 6 characters")
			return false
		}
		if(form.pwd.value != form.password_confirm.value)
		{
			alert("Please ensure that you type your password correctly twice")
			return false
		}
	}
	if(!validEmail(form.email.value))
	{
		alert("Please ensure that your supplied email address is written correctly, e.g. john.doe@anon.com")
		return false
	}
	return true
}
