
function reloadPage()
{
	document.thisForm.target='_self';
	document.thisForm.action='searchLifestyle.cfm';
	document.thisForm.submit();
}

function checkSuburbs(o,checkSurRad){
	
	var nr =0;
	var maxnr = document.thisForm.maxSubs.value;//the limit
	for(var i=0;i<o.length;i++){
		nr=(o[i].selected)?nr+1:nr;
	}
	if (document.thisForm.region_id.selectedIndex == 0){
		alert('No suburbs have been selected');
		document.thisForm.surRad.checked = false;
	}
	else if (checkSurRad == true){
		if (document.thisForm.surRad.checked){
			if(nr>maxnr){
				alert('You have selected '+nr+' suburbs. Please limit to '+ document.thisForm.maxSubs.value +' to use the surrounding suburb search');
				document.thisForm.surRad.checked = false;
			}
		}
	}
	else {
		
		if(nr>maxnr){
			alert('You have selected '+nr+' suburbs. Please limit to '+ document.thisForm.maxSubs.value +' to use the surrounding suburb search');
			document.thisForm.surRad.checked = false;
		}
		else if (nr == 0){
			alert('Please select at least one suburb');
			document.thisForm.surRad.checked = false;
		}
	}	
}

function getSuburbs(){
	document.thisForm.selectedSuburb.value = "";
	document.thisForm.suburbID.value = "";
	selected_suburb_id = document.thisForm.suburb_id;
	for(i = 0; i < selected_suburb_id.options.length; i++)
	{
		if (selected_suburb_id.options[i].selected)
		{
			document.thisForm.suburbID.value += ("," + selected_suburb_id.options[i].value);
			selectedSuburb = selected_suburb_id.options[i].text;
			document.thisForm.selectedSuburb.value += ("," + selectedSuburb);
		}
	}
	if (document.thisForm.selectedSuburb.value != ""){
		document.thisForm.selectedSuburb.value = document.thisForm.selectedSuburb.value.substring(1, document.thisForm.selectedSuburb.value.length);
	}
	if (document.thisForm.suburbID.value != ""){
		document.thisForm.suburbID.value = document.thisForm.suburbID.value.substring(1, document.thisForm.suburbID.value.length);
	}
}

function do_submit(){
	searchOK = true;
	
	getSuburbs();
	
	if (document.thisForm.region_id.selectedIndex == 0){
		alert("Please select a region");
		searchOK = false;
	}
	else if ((document.thisForm.selectedSuburb.value.split(",").length > document.thisForm.maxSubs.value) && (document.thisForm.surRad.checked)){
		alert('Please select a maximum of '+ document.thisForm.maxSubs.value +' suburbs to use the surrounding suburb search');
		searchOK = false;
	}
	else if ((document.thisForm.suburb_id.selectedIndex == -1) && (document.thisForm.district_id.selectedIndex > 0)){
		for (i=0;i<document.thisForm.suburb_id.options.length;i++) {
			document.thisForm.suburb_id.options[i].selected = true
		}
	}
	if (searchOK){
		document.thisForm.region_name.value = document.thisForm.region_id[document.thisForm.region_id.selectedIndex].text;
		
		document.thisForm.target = "_parent";
		document.thisForm.action = "listings.cfm?FirstSearch=true";
		document.thisForm.submit();
	}
}
