function loadLgas(target, option, lgaLet)
{
	// get the appropriate XML file from server	to load as options
	var parts = option.split(':');
	var file = "inc/"+parts[0]+".xml";
	var query="?"+new Date().getTime();

	// now go and fetch the data from the various list of options on the server
	ajaxRequest = loadXml(file, query);
	if (ajaxRequest == null) {alert ("No points available");  return false; }
	var selOptions = ajaxRequest.responseXML.getElementsByTagName("Option");
	if (selOptions.length == 0){return false;}
	
	// all OK so now get the target element for the new select box
	selectDiv = document.getElementById(target);
	var parts = target.split(':');
	selBx = 'lgaList:'+parts[1];
	checkRemoveObject(selBx);
	
	// create a new Select element
	var select = document.createElement('select');
	select.id = selBx;  select.setAttribute('id',selBx);
	select.style.maxWidth='210px';
	select.style.minWidth='190px';
	select.style.position='relative';
	if(browser == 'msie') {select.style.top='0px';}
	else {select.style.top='0px'};
	//select.style.Width='200px';
	//select.style.margin="5px 0 5px 0;";
	//"onfocus="javascript: this.style.width='auto';" onblur="javascript: this.style.width=125;"
	select.style.fontSize="10px";
	select.style.height='19px';
	select.style.fontSize='10px';
	select.style.backgroundColor='#FFFFFF';
	//select.style.border='1px solid gray';
	select.setAttribute('title','select an LGA by first selecting the alphabet group');
	select.title='select an LGA by first selecting the alphabet group'
	
	// this binds the 'go-to' LGA function to this element
	if(selBx == 'lgaList:1' ){	bindEvent(select, 'change', gotoLGA, 'false'); }
	
	//this binds the 'get' LGA geometry to this element
	if(selBx == 'lgaList:2' || selBx == 'lgaList:4')
	{	
		select.setAttribute('disabled', 'disabled');
		select.disabled='disabled';
		bindEvent(select, 'change', getLGA, 'false');
	}
	
	//this binds the 'get' LGA geometry to this element
	if(selBx == 'lgaList:3'){	bindEvent(select, 'change', getLGA, 'false'); }
	
	// create the first Option tag as instructional info
	var option01 = document.createElement('option');
	option01.setAttribute('selected', 'selected');
	var data="... LGAs starting "+lgaLet+" ...";
	var text = document.createTextNode(data);
	option01.appendChild(text);
	select.appendChild(option01);
	
	// build up the options list for the select
	for (var i=0; i<selOptions.length ; i++)
	{
		var value = selOptions[i].getAttribute('value');
		select.options[select.options.length] = new Option(value, value);
	}
	selectDiv.appendChild(select); 
}

//----------------------- function to jump to an entered LGA ----------------------//
function gotoLGA(evt)
{
	var e_out = getThisId(evt)
	//alert(getThisId(evt))
	//alert ('this id = '+e_out)
	// Kill off andy existing mask
	//if (maskSld){deleteit(maskSld)}
	
	// set up the parameters
	var uri = meshBlocksBase;
	var layerObject= e_out;
	var dataStore="ABS";
	var typeName = "COUNCILS";
	var attName =  "LGA_NAME";
	var areaObj = document.getElementById(layerObject);
	var point = areaObj.selectedIndex;
	//alert('point = '+point)

	// look thru layers array for 'Local Govt Councils' layer
	for (var i=0; i<LayerObj.length ; i++)
	{	//alert(TitleText[i]);
		if(TitleText[i] == 'Local Govt Councils') {var layerNumber = i; break;}	
	}

	// if no local govt was selected
	if (point == 0 ) 
	{
		// this basically reinitialises the layer
		LayerObj[layerNumber].mergeNewParams({'sld':lgaSld});
		LayerObj[layerNumber].addOptions({'displayInLayerSwitcher': false}); // decativate from layerSwitcher
		LayerObj[layerNumber].setVisibility(false);
		if(masklayer){maskLayer.setVisibility(false);}
		if(polyLayer){polygonLayer.setVisibility(false);}
		if(labelLayer){labelLayer.setVisibility(false);}
		LabelObj[layerNumber].setVisibility(false);
		document.getElementById('layers:'+layerNumber).checked=false;
		document.getElementById('label:'+layerNumber).checked=false;
		document.getElementById('label:'+layerNumber).disabled=true;
		return false;
	}
	
	// OK turn on the delete me button
	var buttonId = 'electButt';
	if (layerObject == 'lgaList:1'){	buttonId = 'lgaButt'; }
	document.getElementById(buttonId).style.display='block';
	
	// set up the filter for the getfeature request
	var areaName = areaObj.options[areaObj.selectedIndex].value;
	var filter = "<Filter><PropertyIsEqualTo><PropertyName>"+attName+"</PropertyName><Literal>"+areaName+"</Literal></PropertyIsEqualTo></Filter>";
	
	// call function to load GML into the DOM
	ajaxRequest = getFeatureRequest (uri, 'GetFeature','WFS', srs, dataStore, typeName, filter, 'BXFS');

	// OK we now want to parse the GetFeature GML
	if (!getAreaFeatures(ajaxRequest, dataStore, typeName, attName, areaName, layerNumber)){ return false;}
	
	// activate the mask layers
	if(maskLayer){maskLayer.setVisibility(true);}
	if(polygonLayer){polygonLayer.setVisibility(true);}
	if(labelLayer){labelLayer.setVisibility(true);}
	resetZlevels();
	
	Event.stop(evt);
	return true;
}

//----------------------- function to get Geometry for an entered LGA ----------------------//
function getLGA(evt)
{
	// set up the parameters for accessing LGA layer 
	var uri = meshBlocksBase;
	var dataStore ="ABS";
	var typeName = "COUNCILS";
	var attName =  "LGA_NAME";
	
	// set up the polygon name search filter 
	var areaObj = document.getElementById(getThisId(evt));
	var areaName = areaObj.options[areaObj.selectedIndex].value;
	LGAfilter = "<Filter><PropertyIsEqualTo><PropertyName>"+attName+"</PropertyName><Literal>"+areaName+"</Literal></PropertyIsEqualTo></Filter>";
	
	// call function to get the ploygon's GetFeature GML into the DOM
	ajaxRequest = getFeatureRequest (uri, 'GetFeature','WFS', srs, dataStore, typeName, LGAfilter, 'BXFS');

	// OK we now want to parse the GetFeature GML
	if (!getAreaGeometry(ajaxRequest, filterTol)){ return false;}
	
	Event.stop(evt);
	return true;
}

function getAreaGeometry(ajaxRequest, filterTol)
{
	if(ajaxRequest.responseXML != null)
	{
		allX=new Array();
		allY=new Array();
		var pt=new Array();
		var k=0;
		if(filterTol == null || filterTol < 0) {var filterTol = 0;}	// this is the tolerance for excluding points of polygon
		// Parse the resultant xml-delivered DOM object
		var featureObj = ajaxRequest.responseXML.getElementsByTagName("FeatureSet");
		if (featureObj.length == 0){alert("No attributes available for selected Area"); return false;}
		
		// read the Features
		var features = featureObj[0].getElementsByTagName("Feature");
		var element = prefix+'exterior';
		var exterior = features[0].getElementsByTagName(element);
		//alert('number of exteriors = '+exterior.length)
		var element = prefix+'LinearRing';
		var LinearRing = features[0].getElementsByTagName(element);
		//alert('number of linestrings = '+LinearRing.length)


		// get the attribute names and attribute values for this feature
		var element = prefix+'posList';
		//alert(element)
		var posList = LinearRing[0].getElementsByTagName(element);
		//alert('number of PostList = '+posList.length);

		// step thru all the postList elements
		for (var dd = 0; dd < posList.length; dd++)
		{
			if (browser == 'msie') 
			{ var points = posList[dd].firstChild.nodeValue;}
			else
			{var points = posList[dd].textContent; }
			//alert(points);

			// split off points into polygon arrays
			pt = points.split(" ");			// NB there is a space between each coordinate values and each point
			var lastX = pt[0]; var lastY = pt[1];
			var ni=0;

			// step thru each coordinate pcking of x & y values filtering as we go [filterTol]
			for (var e = 0; e < pt.length ; e=e+2)
			{
				if(e > 0 ) {var vect = Math.sqrt(((pt[e]-lastX)*(pt[e]-lastX)) + ((pt[e+1]-lastY)*(pt[e+1]-lastY)));}
				if(vect > filterTol)
				{
					allX[k] = pt[e]; 
					allY[k] = pt[e+1];
					//alert(allX[k]+", "+allY[k]);
					lastX = pt[e]; 
					lastY = pt[e+1];
					k++;
				}
				else
				{
					//ni++
					//alert('number ignored = '+ ni)
				}
			}
		}
		var no = k-1;
		//alert('Number of polygon points = '+no);
		document.getElementById("sendButt2").disabled=false;
		return true;
	}
	else 
	{return false;}
}

function getAreaFeatures(ajaxRequest, dataStore, typeName, attName, area, layerNumber)
{
	if(ajaxRequest.responseXML != null)
	{
		// Parse the resultant xml-delivered DOM object
		var featureObj = ajaxRequest.responseXML.getElementsByTagName("FeatureSet");
		if (featureObj.length == 0){alert("No attributes available for selected Area"); return false;}
		var feature = featureObj[0].getElementsByTagName("Feature");
		var value = feature[0].getElementsByTagName("Value");
		
		// get the attribute names and attribute values for this feature
		var properties = featureObj[0].getElementsByTagName("Properties");
		var property = featureObj[0].getElementsByTagName("Property");
					
			// Loop through each attribute definition for this feature
			for (var i=0; i<property.length; i++)
			{
				var propertyName = property[i].getAttribute("name");
				if (propertyName == 'BBOX')
				{
					var bbox = value[i].firstChild.nodeValue;

					// now split the string into ordinates
					var p = [];
					var pts = bbox.split(" ");

					if (srs == 'EPSG:900913') 
					{
						p = [pts[0],pts[1]];
						var llPoint = geogs2google(p)
						llPoint = decodePoint(llPoint);
						p = [pts[2],pts[3]];
						var trPoint = geogs2google(p)
						trPoint = decodePoint(trPoint);
						var bounds = new OpenLayers.Bounds(llPoint[0], llPoint[1], trPoint[0], trPoint[1]);
					}
					else
					{	var bounds = new OpenLayers.Bounds(pts[0],pts[1],pts[2],pts[3]);	}
					
					// get the new sld file name and path
					var parts = Sld[layerNumber].split('/');
					var fileParts = parts[parts.length-1].split('.')
					var cleanArea = area.replace(/ /g, "_");
					newTempSldFile = 'mask_'+cleanArea+'.xml';
					var filePath = Sld[layerNumber].replace(fileParts[0]+'.xml', "");
					newTempSldPath = filePath.replace(/inc\//, "");

					// apply a mask over map here
					var fullLayerName = typeName+":"+dataStore;
					maskOtherPolygons(fullLayerName, attName, area, '#FFFFFF', '0.7', '#FF0000', '5')
					maskLayer.setVisibility(true);
					polygonLayer.setVisibility(true);
					labelLayer.setVisibility(true);
						
					// jump to the local government area and apply mask
					map.setCenter(bounds.getCenterLonLat(),map.getZoomForExtent(bounds));
					gotoLayerNumber = layerNumber;
				}
			}
			//resetZlevels();
			return true;
		}
		else 	
		{return false;}
}

function removeFilter(id)
{
	//alert(id)
	if(maskLayer != null)
	{
		if(maskLayer){maskLayer.destroy(); maskLayer = null; }
		if(polygonLayer){polygonLayer.destroy();polygonLayer = null;}
		if(labelLayer){labelLayer.destroy();labelLayer = null;}
	}

	// also get rid of LGA boundaries and labels
	if(LayerObj[gotoLayerNumber] && document.getElementById('layers:'+gotoLayerNumber).checked == true) 
	{	
		LayerObj[gotoLayerNumber].setVisibility(false);
		document.getElementById('layers:'+gotoLayerNumber).checked = false;
	}
	if(LabelObj[gotoLayerNumber] && document.getElementById('label:'+gotoLayerNumber).checked == true)
	{
		LabelObj[gotoLayerNumber].setVisibility(false);
		document.getElementById('label:'+gotoLayerNumber).checked=false;
	}
	document.getElementById("lgaList:1").selectedIndex=0;

	// remove the kill button
	document.getElementById(id).style.display='none';
	//resetZlevels();
}

