function showRelatedLinks() {
	document.getElementById("searchForms").style.display = 'none';
	document.getElementById("relatedLinks").style.display = 'block';
	document.getElementById("searchHead").style.backgroundImage = "url('/iqed/images/searchLinksHeader2.gif')";
}

function showSearchForms() {
	document.getElementById("relatedLinks").style.display = 'none';
	document.getElementById("searchForms").style.display = 'block';
	document.getElementById("searchHead").style.backgroundImage = "url('/iqed/images/searchLinksHeader.gif')";
}

function resetSearch() {	
	document.mapForm.search_lot.value = "";
	document.mapForm.search_plan.value = "";
	document.mapForm.search_council.value = "";
	document.mapForm.search_city_town.value = "";
	document.mapForm.search_region.value = "";
	document.mapForm.geo_street_no.value = "";
	document.mapForm.geo_street_name.value = "";
	document.mapForm.geo_locality.value = "";
	document.mapForm.geo_postcode.value = "";
}

function showLoading() {

	window.frames['mapFrame'].document.getElementById('loading').style.display='block';
}

function checkSearch() {

	if (document.mapForm.search.value=="true") {
		resetSearch();
		//i = document.mapForm.loiselect.selectedIndex;
		//val = document.mapForm.loiselect.options[i].value;
		val = document.mapForm.loiselect.value;

		if (val=="regionForm") {
			
			document.mapForm.cmd.value = "search";

			//region search
			if (document.mapForm.region.options[document.mapForm.region.selectedIndex].value!="" && document.mapForm.regionSearchType[0].checked) {

				document.mapForm.search_region.value = document.mapForm.region.options[document.mapForm.region.selectedIndex].value;
				showLoading();
				return true;

			//electorate search
			} else if (document.mapForm.search_electorate.options[document.mapForm.search_electorate.selectedIndex].value!= "" && document.mapForm.regionSearchType[1].checked) {				
				showLoading();
				return true;

			} else {
				alert("Please select a region or electorate in the form provided");
				return false;
			}

		} else if (val=="councilForm") {
			document.mapForm.cmd.value = "search";
			if (document.mapForm.council.options[document.mapForm.council.selectedIndex].value!="") {
				document.mapForm.search_council.value = document.mapForm.council.options[document.mapForm.council.selectedIndex].value;
				showLoading();
				return true;
			}
			else {
				alert("Please select a council in the form provided");
				return false;
			}	
		}
		else if (val=="settlementForm") {
			document.mapForm.cmd.value = "search";
			if (document.mapForm.city_town.options[document.mapForm.city_town.selectedIndex].value!="") {
				document.mapForm.search_city_town.value = document.mapForm.city_town.options[document.mapForm.city_town.selectedIndex].value;
				showLoading();
				return true;
			}
			else {
				alert("Please enter a city / town in the form provided");
				return false;
			}
		}
		else if (val=="suburbForm") {
			document.mapForm.cmd.value = "geocode";
			if (document.mapForm.suburb.value!="") {
				if (isNumeric(document.mapForm.suburb.value)) {
					document.mapForm.geo_postcode.value = document.mapForm.suburb.value;
				}
				else {
					document.mapForm.geo_locality.value = document.mapForm.suburb.value;
				}
				showLoading();
				return true;
			}
			else {
				alert("Please enter a suburb or postcode in the form provided");
				return false;
			}
		}
		else if (val=="propertyForm") {
			selectLOI(5);

			//Lot on Plan search
			if (document.mapForm.propertySearchType[1].checked) {

				if ((document.mapForm.lot.value !="") && (document.mapForm.plan.value !="")) {
					document.mapForm.cmd.value = "search";
					document.mapForm.search_lot.value = document.mapForm.lot.value;
					document.mapForm.search_plan.value = document.mapForm.plan.value;					
					showLoading();
					return true;
				} else {
					alert ("Please enter a lot and plan");
					return false;
				}
			
			//Address search
			} else if (document.mapForm.propertySearchType[0].checked) {
				
				if (document.mapForm.locality.value != "" || document.mapForm.postcode.value != "") {

					document.mapForm.cmd.value = "geocode";
					document.mapForm.geo_street_no.value = document.mapForm.street_no.value;
					document.mapForm.geo_street_name.value = document.mapForm.street_name.value;
					document.mapForm.geo_street_name.value = document.mapForm.geo_street_name.value + " ";
					streettype = document.mapForm.street_type.options[document.mapForm.street_type.selectedIndex].value;
					document.mapForm.geo_street_name.value = document.mapForm.geo_street_name.value + streettype;
					document.mapForm.geo_locality.value = document.mapForm.locality.value;
					postcode = document.mapForm.postcode.value;
					if (!isNumeric(postcode)) {
						alert("Invalid Queensland postcode");
						return false;
					}
					else if (parseInt(postcode)<4000||parseInt(postcode)>4999) {
						alert("Invalid Queensland postcode");
						return false;
					}
					document.mapForm.geo_postcode.value = document.mapForm.postcode.value;
					showLoading();
					return true;
				
				} else {
					alert("Please enter a suburb or postcode");				
					return false;
				}


			} else {
				alert("Please enter an address or a lot on plan");				
				return false;
			}

		}
	}
	else {
		showLoading();
		return true;
	}
}

function isNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function resetCurrentForm () {
	
	val = document.mapForm.loiselect.value;

	switch (val) {
	case "propertyForm":
		document.mapForm.lot.value = "";
		document.mapForm.plan.value = "";
		document.mapForm.street_no.value = "";
		document.mapForm.street_name.value = "";
		document.mapForm.street_type.selectedIndex = 0;
		document.mapForm.locality.value = "";
		document.mapForm.postcode.value = "";
		changePropertySearch('');
		break;
	case "suburbForm":
		document.mapForm.suburb.value = "";
		break;
	case "settlementForm":
		document.mapForm.city_town.selectedIndex = 0;
		break;
	case "councilForm":
		document.mapForm.council.selectedIndex = 0;
		break;
	case "regionForm":
		document.mapForm.region.selectedIndex = 0;
		document.mapForm.search_electorate.selectedIndex = 0;
		changeRegionSearch('');
		break;	
	}

}

function changeRegionSearch(searchType) {
	switch(searchType) {
	case "region":
		document.mapForm.region.disabled = false;
		document.mapForm.search_electorate.disabled = true;
		document.mapForm.regionSearchType[0].checked = true;
		break;
	case "electorate":
		document.mapForm.search_electorate.disabled = false;
		document.mapForm.region.disabled = true;
		document.mapForm.regionSearchType[1].checked = true;
		break;
	default:
		document.mapForm.search_electorate.disabled = false;
		document.mapForm.region.disabled = false;
		document.mapForm.regionSearchType[0].checked = false;
		document.mapForm.regionSearchType[1].checked = false;
	}
}

function changePropertySearch (searchType) {

	switch(searchType) {
	case "lotplan":
		document.mapForm.lot.disabled = false;
		document.mapForm.plan.disabled = false;
		document.mapForm.street_no.disabled = true;
		document.mapForm.street_name.disabled = true;
		document.mapForm.street_type.disabled = true;
		document.mapForm.locality.disabled = true;
		document.mapForm.postcode.disabled = true;
		document.mapForm.propertySearchType[1].checked = true;
		break;
	case "address":
		document.mapForm.street_no.disabled = false;
		document.mapForm.street_name.disabled = false;
		document.mapForm.street_type.disabled = false;
		document.mapForm.locality.disabled = false;
		document.mapForm.postcode.disabled = false;
		document.mapForm.lot.disabled = true;
		document.mapForm.plan.disabled = true;
		document.mapForm.propertySearchType[0].checked = true;
		break;
	default:
		document.mapForm.street_no.disabled = false;
		document.mapForm.street_name.disabled = false;
		document.mapForm.street_type.disabled = false;
		document.mapForm.locality.disabled = false;
		document.mapForm.postcode.disabled = false;
		document.mapForm.lot.disabled = false;
		document.mapForm.plan.disabled = false;
		document.mapForm.propertySearchType[0].checked = false;
		document.mapForm.propertySearchType[1].checked = false;
	}
}