	
	function Distrito_ShowAnimation(){
		$('distrito_onprocess').innerHTML = "<table width=\"100%\"><tbody><tr><td height=\"23\" align=\"center\"><img src=\"images/wait16trans.gif\" width=\"16\" height=\"16\"/></td></tr></tbody></table>";
		$('distrito_onprocess').style.display = 'block';
		$('distrito_onprocess').style.visibility = 'visible';
		$('distrito_onactive').style.display = 'none';
		$('distrito_onactive').style.visibility = 'hidden';
	}
	function Distrito_HideAnimation(){
		$('distrito_onprocess').style.display = 'none';
		$('distrito_onprocess').style.visibility = 'hidden';
		$('distrito_onactive').style.display = 'block';
		$('distrito_onactive').style.visibility = 'visible';
	}
	
	function Distrito_ShowResponse(transport){
		// get combo target 
		var selectBoxTarget = $('distrito');
		
		// Process response
		if (transport.status == 200){
			// Get response Xml
			var xmlResponse = transport.responseXML;
			// read Xml nodes
			var parentNode = xmlResponse.getElementsByTagName("parent_category")[0];
			var docRoot = xmlResponse.getElementsByTagName("categories")[0];
			// Map coodinates
			if(parentNode != null){
				var parentID = parentNode.attributes[0].value;
				var parentName = parentNode.attributes[1].value;
				var parentLat = parentNode.attributes[2].value;
				var parentLng = parentNode.attributes[3].value;
				var parentZoom = parentNode.attributes[4].value;

				// if map exists in current page
				if($('map')){
					// Set point
					SetMapPoint(parentLat, parentLng, parentZoom);
					// Load google map
					loadMap();
				}
			}
			// Empty SelectBox
			removeAllOptions(selectBoxTarget);
			removeAllOptions($('concelho'));
			removeAllOptions($('location'));
	
			// Add Default SelectBox Options
			addOption(selectBoxTarget, '0', '-- Todos --');
			addOption($('concelho'), '0', '-- Depende do Distrito --');
			addOption($('location'), '0', '-- Depende do Concelho --');
			// Fill SelectBox with a new 
			for(var i=0;i<docRoot.childNodes.length;i++){//percorrendo os filhos do nó
				if(docRoot.childNodes[i].nodeType == 1){//ignorar espaços em branco
					addOption(selectBoxTarget, docRoot.childNodes[i].attributes[0].value, docRoot.childNodes[i].attributes[1].value);
				}
			}
			// Hide animation
			Distrito_HideAnimation();
		} else {
			// Hide animation
			Distrito_HideAnimation();
		}
	}
	
	function RequestDistrito(){
		// Show animation
		Distrito_ShowAnimation();
		// Set ajax call
		var url = wServiceRequesterURL;
		var pars = 'COMMAND=REQUEST_CATEGORY&TARGET=DISTRITO&DISTRITOVALUE=&CONCELHOVALUE=&LOCATIONVALUE=';
		
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'GET', 
				parameters: pars, 
				onComplete: Distrito_ShowResponse
			});
	}
	
	function setDefaultDistrito(pageType){
		RequestDistrito();
		if(pageType.toUpperCase() == 'EDIT' && $('map')){
			// Set Default point (EDIT mode)
			if($('latitude').value.length > 0 && $('longitude').value.length > 0){
				// Get point
				var newLat = parseFloat($('latitude').value);
				var newLng = parseFloat($('longitude').value);
				var newPoint = new GLatLng(newLat, newLng);
				// Create our "tiny" marker icon
				var icon = new GIcon();
				icon.image = 'images/bannercasabranco.gif';
				icon.iconSize = new GSize(16, 16);
				icon.iconAnchor = new GPoint(6, 20);
				icon.infoWindowAnchor = new GPoint(5, 1);
				// Set point
				var marker = new GMarker(newPoint, icon);
				map.addOverlay(marker);
				// Center map
				map.setCenter(newPoint, 16);
			}
		}
	}
