function popwin(urltogoto){
	myRef = window.open(urltogoto,'mywin','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=50, left=50,width=350,height=250');
	myRef.focus();
}
function ValidateSearchForm()
{
	var name_search_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
	var location_search_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -";
	var pcode_search_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
	var alpha_search_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var alphabet_only_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var legal_char_count = 0;
	var i;
	var formobj;
	formobj=document.searchform;
	formobj.name.text = remove_XS_whitespace(formobj.name.text);
	if (formobj.name.value == "") {
		if (formobj.location.value == "") {
			if (formobj.postcode.value == "") {
				alert("Please enter something in at least 1 of the first 3 the search fields.");
				formobj.location.focus();
				return false;
			}
		}
	}
	if (formobj.name.value != "") {
		for (i=0; i < formobj.name.value.length; i++) {
			if (name_search_chars.indexOf(formobj.name.value.substring(i, i+1)) == -1) {
				alert("Please only enter the letters A-Z or 0-9 in the name");
				formobj.name.focus();
				return false;
			}
			else if (alpha_search_chars.indexOf(formobj.name.value.substring(i, i+1)) != -1) {
				legal_char_count++;
			}
		}
		if (legal_char_count < 2) {
			alert("The name must contain at least two letters (A-Z, 0-9) to search on");
			formobj.name.focus();
			return false;
		}
	}
	if (formobj.location.value != "") {
		for (i=0; i < formobj.location.value.length; i++) {
			if (location_search_chars.indexOf(formobj.location.value.substring(i, i+1)) == -1) {
				alert("Please only enter the letters A-Z in the location");
				formobj.location.focus();
				return false;
			}
			else if (alpha_search_chars.indexOf(formobj.location.value.substring(i, i+1)) != -1) {
				legal_char_count++;
			}
		}
		if (legal_char_count < 2) {
			alert("The location must contain at least 2 letters (A-Z, 0-9) to search on");
			formobj.location.focus();
			return false;
		}
	}
	legal_char_count = 0;
	if (formobj.postcode.value != "") {
		if (alphabet_only_chars.indexOf(formobj.postcode.value.substring(0, 1)) == -1) {
			alert("The first letter of the postcode MUST be a letter A-Z only");
			formobj.postcode.focus();
			return false;
		}
		for (i=0; i < formobj.postcode.value.length; i++) {
			if (pcode_search_chars.indexOf(formobj.postcode.value.substring(i, i+1)) == -1) {
				alert("Please only enter the letters A-Z, 0-9 or spaces in the postcode");
				formobj.postcode.focus();
				return false;
			}
			else if (alpha_search_chars.indexOf(formobj.postcode.value.substring(i, i+1)) != -1) {
				legal_char_count++;
			}
		}
		if (legal_char_count == 0) {
			alert("The postcode must contain at least one letter A-Z or one number 0-9 to search on");
			formobj.postcode.focus();
			return false;
		}
	}
}

function remove_XS_whitespace(inputstring)
{
	var tmp = "";
	if (inputstring == null)
	{
		inputstring = "";
	}
	var item_length = inputstring.length;
	var item_length_minus_1 = inputstring.length - 1;
	if (item_length > 0)
	{
		for (index = 0; index < item_length; index++)
		{
			if (inputstring.charAt(index) != ' ')
			{
				tmp += inputstring.charAt(index);
			}
			else
			{
				if (tmp.length > 0)
				{
					if (inputstring.charAt(index+1) != ' ' && index != item_length_minus_1)
					{
						tmp += inputstring.charAt(index);
					}
				}
			}
		}
	}
	inputstring = tmp;
}

window.status = "competentperson.co.uk";
