function valSearchOLDER() {
	thereturn = true;
	if (document.getElementById('searchby').value=='Postcode') {
		// POSTCODE SEARCH //
		if (document.getElementById('SearchB').value=='') {
			if (document.getElementById('SearchD').value=='') {
				thereturn = false;
				alert('Please enter a postcode or company name');
			}
		}else{
			if (document.getElementById('SearchB').value.length < 2) {
				thereturn = false;
				alert("Please enter a postcode");
			}
		}
	}else{
		// COUNTY SEARCH //
		if (document.getElementById('SearchA').value=='*' && document.getElementById('SearchD').value.length<4 ) {
			thereturn = false;
			if (document.getElementById('SearchD').value.length>=1 && document.getElementById('SearchD').value.length<4) {
				alert("Please enter at least 4 characters of the name.  Thank you");
			}else{
				alert('Please select a county or enter a company name');
			}
		}
	}
	
	
	return thereturn;
}


function valSearch() {
	thereturn = true;

	if ((document.getElementById('SearchC').value=='' || document.getElementById('SearchC').value.substr(0,4)=='e.g.'|| document.getElementById('SearchC').value.substr(0,3)=='All') && (document.getElementById('SearchB').value=='' || document.getElementById('SearchB').value.substr(0,4)=='e.g.') && (document.getElementById('SearchD').value=='' || document.getElementById('SearchD').value.substr(0,13)=='Business name')) {
		alert('Please enter a location or a business name of at least 4 characters');
		thereturn = false;
	}else{
		
		if (document.getElementById('SearchC').value=='' || document.getElementById('SearchC').value.substr(0,4)=='e.g.' || document.getElementById('SearchC').value.substr(0,3)=='All') {
			// IF ACTIVITY IS BLANK THEN VALIDATE THE OTHER FIELDS //
			if (document.getElementById('SearchB').value=='' || document.getElementById('SearchB').value.substr(0,4)=='e.g.') {
				// IF POSTCODE IS BLANK //
				var trimmed = document.getElementById('SearchD').value.replace(/^\s+|\s+$/g, '') ;
				if (trimmed.length<4) {
					// COMPANY NAME IS TOO SHORT //
					thereturn = false;
					alert('Please enter a location or a business name of at least 4 characters');
				}else{
					// COMPANY NAME IS LONG ENOUGH //
				}
			}else{
				// POSTCODE IS COMPLETED //
			}
		}else{
			// ACTIVITY IS COMPLETED //
		}

	}
	
	return thereturn;
}


function changeCounty(theval,thekids,theschemes,isredsite) {
	if (theval!='') {
		var xmlhttp = false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		// JScript gives us Conditional compilation, we can cope with old IE versions.
		// and security blocked creation of the objects.
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}
		@end @*/

		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		}

		var returnText;
		uri = "/xGetActivities.asp?theval=" + escape(theval) + "&thekids=" + thekids + "&theschemes=" + theschemes + "&isredsite=" + isredsite;
		xmlhttp.open("GET", uri ,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				returnText = xmlhttp.responseText;

				if (returnText == "EOF") {
				} else {
					newText = returnText;
					eval(returnText);
				}
			}
		}
		xmlhttp.send(null);
	}
}

function doPrefs() {
	//read values in//
	var distmin = 0;
	var distmax = 0;
	var refmin = 0;
	var refmax = 0;
	var satmin = 0;
	var satmax = 0;
	var costmin = 0;
	var costmax = 0;
	
	if (document.getElementById('distance_slider')) {
		distmin = $('#distance_slider').slider('value', 0)/10;
		distmax = $('#distance_slider').slider('value', 1)/10;
	}
	if (document.getElementById('references_slider')) {
		refmin = $('#references_slider').slider('value', 0)/10;
		refmax = $('#references_slider').slider('value', 1)/10;
	}
	if (document.getElementById('satisfaction_slider')) {
		satmin = parseFloat($('#satisfaction_slider').slider('value', 0)/10);
		satmax = parseFloat($('#satisfaction_slider').slider('value', 1)/10);
	}
	if (document.getElementById('cost_slider')) {
		costmin = parseInt($('#cost_slider').slider('value', 0)/10);
		costmax = parseInt($('#cost_slider').slider('value', 1)/10);
	}
	
	//bang the values into the search form//
	starvals = distmin + "," + distmax + "," + refmin + "," + refmax + "," + satmin + "," + satmax + "," + costmin + "," + costmax;
	document.getElementById('viewpage').value="1";
	document.getElementById('starvals').value= starvals;
	document.getElementById('orderby').value="StarRating DESC, Distance ASC, Satisfaction DESC";
	document.getElementById('searchform').submit();
}
