function Status(){
	this.council = false;
	this.school = false;
	this.road = false;
	this.trash = false;
	this.police = false;
	this.fire = false;
	this.nearest = false;
	this.currentTab = "";
	this.welcome = false;
	this.res = false;
	this.addressLoaded = false;
	this.streetDialog = false;		
	this.helpFlag = false;
	this.specsFlag = false;
	this.paramDisplay = decodeURI(getRequestParameter('display'));
	if(!this.paramDisplay){
		this.paramDisplay = "none";
	}
	var paramWelcome = decodeURI(getRequestParameter('welcome'));
	if(paramWelcome){
		 this.welcome = true;
	}
}

function StatusPrototype(){	
	Status.prototype.checkStatus = function(item){
		//alert("checkStatus:" + item + ":" + this.council + this.road + this.trash + this.police + this.fire + this.nearest);
		if (this.council == true && this.school == true && this.road == true && this.trash == true && this.police == true && this.fire == true && this.nearest == true){
			if(this.paramDisplay != "cleared" && this.paramDisplay != "none"){						 
				//This code will be executed on initial load when a display parameter is passed
				document.getElementById(this.paramDisplay).style.display = "inline";
				var screenPoint = genMap.map.toScreen(selectedAddress.genGraphic.graphic.geometry);
				genMap.map.infoWindow.setTitle(selectedAddress.genGraphic.graphic.getTitle());
				genMap.map.infoWindow.setContent(selectedAddress.genGraphic.graphic.getContent());	
				genMap.map.infoWindow.show(screenPoint,genMap.map.getInfoWindowAnchor(screenPoint));	
				setCursors();
				YAHOO.loading.container.wait.hide();
				if(!loadStatus.welcome){
					checkConfig();		
				}
			}
			//This code will be executed on initial load when a display parameter is not passed
			else if(this.paramDisplay == "none"){
				document.getElementById('council').style.display = "inline";
				YAHOO.loading.container.wait.hide();
				var screenPoint = genMap.map.toScreen(selectedAddress.genGraphic.graphic.geometry);
				genMap.map.infoWindow.setTitle(selectedAddress.genGraphic.graphic.getTitle());
				genMap.map.infoWindow.setContent(selectedAddress.genGraphic.graphic.getContent());	
				genMap.map.infoWindow.show(screenPoint,genMap.map.getInfoWindowAnchor(screenPoint));	
				setCursors();
				if(!loadStatus.welcome){
					checkConfig();	
				}	
			}
			//This code will be executed on subsequent loads			
			else if(this.paramDisplay == "cleared"){
				var screenPoint = genMap.map.toScreen(selectedAddress.genGraphic.graphic.geometry);
				genMap.map.infoWindow.setTitle(selectedAddress.genGraphic.graphic.getTitle());
				genMap.map.infoWindow.setContent(selectedAddress.genGraphic.graphic.getContent());	
				genMap.map.infoWindow.show(screenPoint,genMap.map.getInfoWindowAnchor(screenPoint));	
				setCursors();
				YAHOO.loading.container.wait.hide();		  					
			}	
		}			
	}
		
	
	Status.prototype.clear = function(){
		this.council = false;
		this.school = false;
		this.road = false;
		this.trash = false;
		this.police = false;
		this.fire = false;
		this.nearest = false;
		this.paramDisplay = "cleared";
		this.annapolis = false;
		this.streetName = "";
		this.aaid = "";
		this.latitude = "";
		this.longitude = "";
	}
}

function checkConfig(){
	//Resolution Detection Code 
	if (loadStatus.res){
		javascript:YAHOO.ui.container.resDialog.show();
	}
	else{
		javascript:YAHOO.ui.container.welcomeDialog.show();
	}
}

function checkBrowser(){
	//initialize browser dialog
	
	YAHOO.namespace("ui.browser");
	
	var browserContinue = function() {
		YAHOO.ui.browser.browserDialog.hide();
	}	
			
	document.getElementById("browserDialog").style.display="block";
	YAHOO.ui.browser.browserDialog = new YAHOO.widget.Dialog("browserDialog", 
								{ width : "500px",
								  fixedcenter : true,
								  visible : false, 
								  close: true,
								  zindex:99,
								  modal:true,
								  draggable:true,
								  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.15},
								  constraintoviewport : true,
								  buttons : [ { text:"Continue to Application", handler:browserContinue }]
								});
		YAHOO.ui.browser.browserDialog.hideEvent.subscribe(function(){
			dojo.addOnLoad(loadingInit);
			dojo.addOnLoad(mapInit);
			dojo.addOnLoad(uiInit);
			dojo.addOnLoad(queryInit);
			//YAHOO.ui.container.welcomeDialog.show();			 
		});  
		
		// Render the Dialog
		YAHOO.ui.browser.browserDialog.render();
		YAHOO.ui.browser.browserDialog.hide();	
	
	
	//Browser Detection Code
	if (BrowserDetect.browser == 'Internet Explorer' && BrowserDetect.version >= 7){
		return true;
	}
	else if (BrowserDetect.browser == 'Firefox' && BrowserDetect.version >= 3){
		return true;
	}
	else{
		javascript:YAHOO.ui.browser.browserDialog.show();
		return false;
	}
}

function setCursors(){
	dojo.byId("genMapDiv_layers").style.cursor = "url('/MyAA/images/Hand.cur'),default";
	dojo.byId("genMapDiv_infowindow").style.cursor = 'default';
	

    dojo.connect(genMap.map, "onMouseDown", function(evt) {
        if(document.getElementById('genNavPan').className == 'navbarSelected'){
        	dojo.byId("genMapDiv_layers").style.cursor = "url('/MyAA/images/MoveHand.cur'),default";
        }	
    });
    
    dojo.connect(genMap.map, "onMouseUp", function(evt) {
    	if(document.getElementById('genNavPan').className == 'navbarSelected'){ 	
        	dojo.byId("genMapDiv_layers").style.cursor = "url('/MyAA/images/Hand.cur'),default";
        }	
    });
    
    dojo.connect(genMap.map.graphics, "onMouseOver", function(evt) {
	   	if(document.getElementById('genNavPan').className == 'navbarSelected'){
	   		dojo.byId("genMapDiv_layers").style.cursor = 'pointer';
	   	    
	   		dojo.connect(genMap.map, "onMouseDown", function(evt) {
	   	    	if(document.getElementById('genNavPan').className == 'navbarSelected'){
	   	    		dojo.byId("genMapDiv_layers").style.cursor = 'pointer';
	   	    	}
	   	     });
	   	    
	   	    dojo.connect(genMap.map, "onMouseUp", function(evt) {
	   	     if(document.getElementById('genNavPan').className == 'navbarSelected'){
	   	        dojo.byId("genMapDiv_layers").style.cursor = 'pointer';	
	   	     } 
	   	    });   	
	   	}
	});
    
    
    dojo.connect(genMap.map.graphics, "onMouseOut", function(evt) {
    	if(document.getElementById('genNavPan').className == 'navbarSelected'){
    		dojo.byId("genMapDiv_layers").style.cursor = "url('/MyAA/images/Hand.cur'),default";
    		
    		dojo.connect(genMap.map, "onMouseDown", function(evt) {
    			if(document.getElementById('genNavPan').className == 'navbarSelected'){
    				dojo.byId("genMapDiv_layers").style.cursor = "url('/MyAA/images/MoveHand.cur'),default";
    			}	
   			});
    		
    		dojo.connect(genMap.map, "onMouseUp", function(evt) {
    			if(document.getElementById('genNavPan').className == 'navbarSelected'){
    				dojo.byId("genMapDiv_layers").style.cursor = "url('/MyAA/images/Hand.cur'),default";
    			}	
    		}); 
    	}	
    });
       
}

function SelectedAddress(address, city, zip, x, y, type){
	this.address = address;
	this.city = city;
	this.zip = zip; 
	this.x = x;
	this.y = y;
	this.point = new esri.geometry.Point(x,y, new esri.SpatialReference({ wkid: 2248 }));
	this.type = type;
	this.annapolis = false;
}

function loadingInit() {
	loadStatus = new Status();
    YAHOO.namespace("loading.container");
    if (!YAHOO.loading.container.wait) {
        YAHOO.loading.container.wait = 
                new YAHOO.widget.Panel("wait",  
                                                { width: "240px", 
                                                  fixedcenter: true, 
                                                  close: false, 
                                                  draggable: false, 
                                                  zindex:110,
                                                  modal: true,
                                                  visible: false
                                                } 
                                            );

        YAHOO.loading.container.wait.setHeader("Content Loading, Please Wait...");
        YAHOO.loading.container.wait.setBody("<img src='/MyAA/images/loading.gif'>");
        YAHOO.loading.container.wait.render(document.body);
        YAHOO.loading.container.wait.show();

    }  
}


function setMapSize(){
	var dataWidth;
	var mapWidth;
	var screenWidth = screen.width;
	var screenHeight = screen.height;
	
	//alert("screen.width:" + screen.width);
	
	if (screenWidth < 1024 && screenHeight < 768){
		loadStatus.res = true;
	}
	
	if (screenWidth > 1200){
		dataWidth = (screenWidth * .30) + 'px';
		mapWidth = (screenWidth * .70) + 'px';
	}
	else if (screenWidth > 1000){
		dataWidth = (screenWidth * .35) + 'px';
		mapWidth = (screenWidth * .65) + 'px';
	}
	else{
		dataWidth = (screenWidth * .45) + 'px';
		mapWidth = (screenWidth * .55) + 'px';
	}

	var contentHeight = (screenHeight * .70) + 'px';
	//alert(document.body.offsetWidth + "x" + screen.height + ":" + dataWidth + ":" + mapWidth);	

	document.getElementById('genData').style.width = dataWidth;
	document.getElementById('genData').style.height = contentHeight;
	document.getElementById('genMapDiv').style.width = mapWidth;
	document.getElementById('genMapDiv').style.height = contentHeight;
}	

function mapInit() {
//alert("browser detect:" + BrowserDetect.browser + ", " + BrowserDetect.version);
//Set up proxy
	esriConfig.defaults.io.proxyUrl = esriProxyURL;
	esriConfig.defaults.io.alwaysUseProxy = false;
		
//Set Map Size
	setMapSize();
	
//Show the divs	
	document.getElementById('genDiv').style.display = 'inline';

//Load Prototypes
	MapPrototype();
	DynamicLayerPrototype();
	TiledLayerPrototype();
	DrawbarPrototype();
	NavbarPrototype();
	QueryPrototype();
	GraphicPrototype();
	StatusPrototype();

		
//Load Map
	genMap = new Map("genMapDiv","genMap");	
	
//Load Ortho layer 
	genOrtho = new TiledLayer(genMap.map,orthoURL,{displayLevels:[9,8,7]});
	
//Load BaseMap Layer
//	var opt = "{\"opacity\":0.25}";
   	genBase = new TiledLayer(genMap.map,basemapURL,{displayLevels:[6,5,4,3,2,1,0]});		   
   	
//Load MyAA Layer
	var visibleGenLayers = [4];
	genMyaa = new DynamicLayer(genMap.map,"genMyaa",myaaURL,"",visibleGenLayers);
	
	dojo.connect(genMyaa.layer, "onUpdate", hideLoading);
	dojo.connect(genMap.map, "onZoomStart", showLoading);

   	
  	//Check the map level on zoom end to toggle Street Labels
   	dojo.connect(genMap.map, "onZoomEnd", function(fset) {
   		var mapLevel = genMap.map.getLevel();
    	//alert("mapLevel:" + mapLevel);
    	if (document.getElementById("genAddressBanner").innerHTML != "None"){
    		if(mapLevel == '0' || mapLevel == '1' || mapLevel == '2' || mapLevel == '3' || mapLevel == '4' || mapLevel == '5' || mapLevel == '6'){
    			genBase.layer.show();
    			genMyaa.removeVisibleLayer(streetLabelLayerNum);
    		}
    		else{
    			genBase.layer.hide();
				genMyaa.addVisibleLayer(streetLabelLayerNum);
			}        				
    	}
    });
    
    dojo.connect(genMap.map, "onPanStart", showLoading);                 
	
	//connect to window's resize event
	dojo.connect(window, "onresize", function() { 	
	//clear any existing resize timer
	clearTimeout(timer); 
	//create new resize timer with delay of 500 milliseconds
		timer = setTimeout(function() {
	 		genMap.map.resize();
			genMap.map.reposition();		 		
			}, 500);
 	 });
}

function uiInit(){
	//Load Navbar 	
	themesInit();
	genNavbar = new Navbar(genMap.map);
	genNavbar.pan;

	//menuDiaolog init
	YAHOO.namespace("ui.container");
	
	document.getElementById("categoryDialog").style.display="block";
	YAHOO.ui.container.categoryDialog = new YAHOO.widget.Dialog("categoryDialog", 
								{ width : "500px",
								  fixedcenter : false,
								  visible : false, 
								  close: true,
								  zindex:99,
								  draggable:false,
								  context:["menuCell","tl","br",["beforeShow", "windowResize"]],
								  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.15},
								  constraintoviewport : true
								});
				
		YAHOO.ui.container.categoryDialog.hideEvent.subscribe(function(){

			document.getElementById('categoryMenuImg').src = "/MyAA/images/greenPlus.png";		});  
		
		// Render the Dialog
		YAHOO.ui.container.categoryDialog.render();
		YAHOO.ui.container.categoryDialog.hide();
	
			
	document.getElementById("menuDialog").style.display="block";
	YAHOO.ui.container.menuDialog = new YAHOO.widget.Dialog("menuDialog", 
								{ width : "250px",
								  fixedcenter : false,
								  visible : false, 
								  close: true,
								  zindex:99,
								  draggable:false,
								  context:["menuTD","tl","bl",["beforeShow", "windowResize"]],
								  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.15},
								  constraintoviewport : true
								});
		YAHOO.ui.container.menuDialog.hideEvent.subscribe(function(){						
			document.getElementById('menuTD').style.backgroundColor = "#D9DABB";
			document.getElementById('menuTag').style.color ="#4C4545";
			document.getElementById('menuIcon').src = "/MyAA/images/arrowBrown.gif";
		});  
		
		// Render the Dialog
		YAHOO.ui.container.menuDialog.render();
		YAHOO.ui.container.menuDialog.hide();	
	
	var welcomeContinue = function() {
		YAHOO.ui.container.welcomeDialog.hide();
		this.submit();
	}	
			
	document.getElementById("welcomeDialog").style.display="block";
	YAHOO.ui.container.welcomeDialog = new YAHOO.widget.Dialog("welcomeDialog", 
								{ width : "500px",
								  fixedcenter : true,
								  visible : false, 
								  close: true,
								  zindex:99,
								  modal:true,
								  draggable:true,
								  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.15},
								  constraintoviewport : true,
								  buttons : [ { text:"Continue to Application", handler:welcomeContinue }]
								});
		YAHOO.ui.container.welcomeDialog.hideEvent.subscribe(function(){						
			if (loadStatus.helpFlag){
				YAHOO.ui.container.helpDialog.show();
			}
			else if (loadStatus.specsFlag){
				YAHOO.ui.container.helpDialog.show();
				toggleHelp('specs');
			}
			else{
				if(document.getElementById('genAddressBanner').innerHTML == "None"){
					YAHOO.structAddr.container.structAddrDialog.show();
				}			
		 	}
		});  
		
		// Render the Dialog
		YAHOO.ui.container.welcomeDialog.render();
		YAHOO.ui.container.welcomeDialog.hide();			
		
		
		var resContinue = function() {
			YAHOO.ui.container.resDialog.hide();
		}	
	
		
		document.getElementById("resDialog").style.display="block";
		YAHOO.ui.container.resDialog = new YAHOO.widget.Dialog("resDialog", 
									{ width : "400px",
									  fixedcenter : true,
									  visible : false, 
									  close: true,
									  zindex:99,
									  modal:true,
									  draggable:true,
									  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.15},
									  constraintoviewport : true,
									  buttons : [ { text:"Continue to Application", handler:resContinue }]
									});
			YAHOO.ui.container.resDialog.hideEvent.subscribe(function(){
				YAHOO.ui.container.welcomeDialog.show();			 
			});  
			
			// Render the Dialog
			YAHOO.ui.container.resDialog.render();
			YAHOO.ui.container.resDialog.hide();	
	
			
	document.getElementById("helpDialog").style.display="block";
	YAHOO.ui.container.helpDialog = new YAHOO.widget.Dialog("helpDialog", 
								{ width : "600px",
								  height: "500px",
								  fixedcenter : true,
								  visible : false, 
								  close: true,
								  zindex:99,
								  modal:true,
								  draggable:true,
								  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.15},
								  constraintoviewport : true
								});
		YAHOO.ui.container.helpDialog.hideEvent.subscribe(function(){
			closeAllHelp();												
			if(document.getElementById('genAddressBanner').innerHTML == "None"){
				YAHOO.structAddr.container.structAddrDialog.show();
			}			
		});  
		
		// Render the Dialog
		YAHOO.ui.container.helpDialog.render();
		YAHOO.ui.container.helpDialog.hide();	
	
	var handleFeedbackSubmit = function() {
		var data = this.getData();
		if (isEmpty(data.emailName) || isEmpty(data.emailSearch) || isEmpty(data.emailSubject)){
			alert("Please enter a value for all required fields"); 
		} 
		else if (data.emailName == data.emailSearch && data.emailName == data.emailEmail){				
				alert("Please enter valid feedback before submitting.");
		}
		else {	
			this.submit();			
			alert("An email has been submitted.  Thanks for your feedback.");
		}
	};
	var handleFeedbackCancel = function() {	this.cancel(); };
	
	var handleFeedbackSuccess = function(o) {
		document.emailForm.emailName.value = "";
		document.emailForm.emailSearch.value = "";
		document.emailForm.emailSubject.value = "";
		document.emailForm.emailEmail.value = "";
		document.emailForm.emailPhone.value = "";
		document.emailForm.emailComments.value = "";
	};
	var handleFeedbackFailure = function(o) { alert("Submission failed: " + o.status); };
		
	document.getElementById("feedbackDialog").style.display="block";
	YAHOO.ui.container.feedbackDialog = new YAHOO.widget.Dialog("feedbackDialog", 
								{ width : "500px",
								  fixedcenter : true,
								  visible : false, 
								  close: true,
								  modal:true,
								  zindex:99,
								  draggable:true,
								  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.15},
								  constraintoviewport : true,
								  buttons : [ { text:"Submit", handler:handleFeedbackSubmit },
							      { text:"Cancel", handler:handleFeedbackCancel } ]
								});

	YAHOO.ui.container.feedbackDialog.callback = { success: handleFeedbackSuccess, failure: handleFeedbackFailure };
	// Render the Dialog
	YAHOO.ui.container.feedbackDialog.render();
	YAHOO.ui.container.feedbackDialog.hide();	
}	
			
	

function updateSelectedAddress(type){
	if(type == "structureAddress"){
		selectedAddress = new SelectedAddress(structureAddressMapped.address, structureAddressMapped.city, structureAddressMapped.zip, structureAddressMapped.x, structureAddressMapped.y,"structureAddress");
		document.getElementById('genAddressBanner').innerHTML = "<a  style='font-size:10pt;font-weight:bold;color:#52B2D2;' title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + selectedAddress.x  + "," + selectedAddress.y + ",1000);showInfoWindowOnZoom(\"selectedAddress.genGraphic\");'>" + selectedAddress.address + "</a>";
		document.getElementById('genZoom').href  = 'javascript:genMap.changeExtentByXY(selectedAddress.x ,selectedAddress.y,1000);showInfoWindowOnZoom("selectedAddress.genGraphic");';		
		document.getElementById('genAddressBanner2').innerHTML = "<span style='font-size:8pt;color:#4C4545''>" + selectedAddress.city +   ", MD " + selectedAddress.zip + "</span>";		
		
		//Clear out street data on Theme form
		document.getElementById('genThemeStreetName').value = "";
		document.getElementById('genThemeStreetNumber').value = "";
		document.getElementById('crimeThemeStreetName').value = "";
		document.getElementById('crimeThemeStreetNumber').value = "";
		
		//Update address on Theme form 
		document.getElementById('genThemeAddr').value = selectedAddress.address;
		document.getElementById('genThemeCity').value = selectedAddress.city;
		document.getElementById('genThemeZip').value = selectedAddress.zip;
		document.getElementById('genThemeX').value = selectedAddress.x;
		document.getElementById('genThemeY').value = selectedAddress.y;
		document.getElementById('crimeThemeAddr').value = selectedAddress.address;
		document.getElementById('crimeThemeCity').value = selectedAddress.city;
		document.getElementById('crimeThemeZip').value = selectedAddress.zip;
		document.getElementById('crimeThemeX').value = selectedAddress.x;
		document.getElementById('crimeThemeY').value = selectedAddress.y;

	}
	else{
		var streetAddress = "[" + streetCenterlineMapped.from + "-" + streetCenterlineMapped.to + "] " + streetCenterlineMapped.streetName;
		selectedAddress = new SelectedAddress(streetAddress, "", streetCenterlineMapped.zip,streetCenterlineMapped.x,streetCenterlineMapped.y, "streetCenterline");
		selectedAddress.streetName = streetCenterlineMapped.streetName;
		document.getElementById('genAddressBanner').innerHTML = "<a  style='font-size:10pt;font-weight:bold;color:#52B2D2;' title='Zoom Here' title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + selectedAddress.x  + "," + selectedAddress.y + ",1000);showInfoWindowOnZoom(\"selectedAddress.genGraphic\");'>" + selectedAddress.address + "</a>";
		document.getElementById('genZoom').href  = 'javascript:genMap.changeExtentByXY(selectedAddress.x ,selectedAddress.y,1000);showInfoWindowOnZoom("selectedAddress.genGraphic");';		
		document.getElementById('genAddressBanner2').innerHTML = "<span style='font-size:8pt;color:#4C4545''>Zip Code: " + selectedAddress.zip + "</span>";		
		
		//Clear address data on Theme form 
		document.getElementById('genThemeAddr').value = "";
		document.getElementById('genThemeCity').value = "";
		document.getElementById('genThemeZip').value = "";
		document.getElementById('genThemeX').value = "";
		document.getElementById('genThemeY').value = "";
		document.getElementById('crimeThemeAddr').value = "";
		document.getElementById('crimeThemeCity').value = "";
		document.getElementById('crimeThemeZip').value = "";
		document.getElementById('crimeThemeX').value = "";
		document.getElementById('crimeThemeY').value = "";
		
		//Update street name and # on Theme form 
		document.getElementById('genThemeStreetName').value = streetCenterlineMapped.streetName;
		document.getElementById('genThemeStreetNumber').value = streetCenterlineMapped.streetNumber;
		document.getElementById('crimeThemeStreetName').value = streetCenterlineMapped.streetName;
		document.getElementById('crimeThemeStreetNumber').value = streetCenterlineMapped.streetNumber;
	}
	loadStatus.addressLoaded = true;
	genMap.changeExtentByXY(selectedAddress.x,selectedAddress.y,1000);
}	

function showLoading() {
	esri.show(document.getElementById('genLoadingImg'));
}

 function hideLoading() {
 	esri.hide(document.getElementById('genLoadingImg'));
 }


function queryInit() {
    structAddrDialogInit(processStructureAddress);
	streetDialogInit(streetCenterLineQueryExec);	
	
	YAHOO.structAddr.container.structAddrDialog.hideEvent.subscribe(function(){						
		if (!loadStatus.addressLoaded && document.getElementById('structAddr').value == "" && loadStatus.streetDialog == false){
			alert("An address must be entered to proceed.");
			YAHOO.structAddr.container.structAddrDialog.show();		
		}

	});  

	YAHOO.street.container.streetDialog.showEvent.subscribe(function(){
		loadStatus.streetDialog = true;
	});  


	YAHOO.street.container.streetDialog.hideEvent.subscribe(function(){
		loadStatus.streetDialog = false;
		if (!loadStatus.addressLoaded && document.getElementById('streetName').value == ""){
			alert("An address must be entered to proceed.");	
			YAHOO.structAddr.container.structAddrDialog.show();
		}
	});  
	
	YAHOO.streetResults.container.streetResultsDialog.hideEvent.subscribe(function(){
		if (!loadStatus.addressLoaded){
			alert("An address must be entered to proceed.");	
			YAHOO.structAddr.container.structAddrDialog.show();
		}
	});  
	
	var paramAddress = decodeURI(getRequestParameter('address'));
	if (paramAddress != ""){
		var paramZip = getRequestParameter('zip');
		var paramCity = decodeURI(getRequestParameter('city'));
		var paramX = getRequestParameter('x');
		var paramY = decodeURI(getRequestParameter('y'));		
		document.getElementById('addr').value = paramAddress;
		document.getElementById('zip').value = paramZip;
		document.getElementById('city').value = paramCity;
		document.getElementById('x').value = paramX;
		document.getElementById('y').value = paramY;
		dojo.connect(genMap.map, "onLoad", processStructureAddress);
	}
	else{
		var paramStreetName = decodeURI(getRequestParameter('streetName'));		
		if (paramStreetName != ""){
			//alert("got here:" + paramStreetName);
			var paramStreetNum = getRequestParameter('streetNum');
			document.getElementById('streetName').value = paramStreetName;
			document.getElementById('streetNum').value = paramStreetNum;
			dojo.connect(genMap.map, "onLoad", streetCenterLineQueryExec);
		}
		else{	
			YAHOO.loading.container.wait.hide();
			javascript:YAHOO.ui.container.welcomeDialog.show();
			loadStatus.welcome = true;
		}
	}
}

function processStructureAddress() { 
	structureAddressMapped = new StructureAddress(document.getElementById('addr').value,document.getElementById('city').value,document.getElementById('zip').value,Math.round(document.getElementById('x').value),Math.round(document.getElementById('y').value));
	if(document.getElementById('genAddressBanner').innerHTML  != "None"){
		clearGraphics();
		loadStatus.clear();
	}
	YAHOO.structAddr.container.structAddrDialog.hide();
	YAHOO.structAddrResults.container.structAddrResultsDialog.hide();
	document.getElementById('structAddr').value = "";
	document.getElementById('addr').value = "";
	document.getElementById('city').value = "";
	document.getElementById('zip').value = ""; 
	document.getElementById('x').value = "";
	document.getElementById('y').value = "";
	updateSelectedAddress('structureAddress');
	loadGenContent();
}

function streetCenterLineQueryExec() {
	//alert("got to streetCenterLineExec" + document.getElementById('streetName').value);
	if(document.getElementById('genAddressBanner').innerHTML  != "None"){
		clearGraphics();
		loadStatus.clear();
	}
	YAHOO.street.container.streetDialog.hide();
	streetCenterlineQuery(processSelectedStreet,"processSelectedStreet");
}

function clearGraphics(){
	genMap.map.graphics.clear(); 
	genMap.parcelGraphicsLayer.clear();
	genMap.roadGraphicsLayer.clear();
	genMyaa.removeVisibleLayer(roadDistrictLayerNum); 
	genMap.councilGraphicsLayer.clear();
 	genMyaa.removeVisibleLayer(councilLayerNum); 
	genMap.pdGraphicsLayer.clear();
	genMyaa.removeVisibleLayer(policeDistrictLayerNum);
	document.getElementById('roadMapTxt').innerHTML = "Show Road Districts";
	document.getElementById('councilMapTxt').innerHTML = "Show Council Districts";
}

function processSelectedStreet() { 
	YAHOO.streetResults.container.streetResultsDialog.hide();
	document.getElementById('streetNum').value = "";
	document.getElementById('streetName').value = "";
	updateSelectedAddress('streetCenterline');
	loadGenContent();
}
	
function loadGenContent(){	
	//alert(selectedAddress.x + ", " + selectedAddress.y + ", " + selectedAddress.address);
	YAHOO.loading.container.wait.show();
	var genAddrSymbol = new esri.symbol.PictureMarkerSymbol("/MyAA/images/green-dot.png", 20, 20);
	genPoint = new esri.geometry.Point(selectedAddress.x,selectedAddress.y, new esri.SpatialReference({ wkid: 2248 }));
	var genAddrGraphic = new esri.Graphic(genPoint,genAddrSymbol);
	selectedAddress.genGraphic = new Graphic(genAddrGraphic,genMap.map.graphics,true,genAddrSymbol);	
	genMap.map.infoWindow.resize(280,200);
	genMap.map.infoWindow.hide();
	if(selectedAddress.type == "structureAddress"){
		getAAID();
	}
	else{
		getTrash(100,esri.tasks.BufferParameters.UNIT_FOOT);
	}
	checkAnnapolis();
	getCouncil();
	getElemSchool();
	getFire();
	getRoadDistrict();
	getNearest(selectedAddress.x, selectedAddress.y);	
}

function getRequestParameter(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";	 
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

function closeAll(){
	 document.getElementById('council').style.display = 'none' ;
	 document.getElementById('schools').style.display = 'none' ;
	 document.getElementById('roadDistrict').style.display = 'none' ;
	 document.getElementById('trash').style.display = 'none' ;
	 document.getElementById('fireDept').style.display = 'none' ;
	 document.getElementById('policeDept').style.display = 'none' ;
	 document.getElementById('pay').style.display = 'none' ;
	 document.getElementById('library').style.display = 'none' ;
	 document.getElementById('senior').style.display = 'none' ;
	 document.getElementById('hospital').style.display = 'none' ;
	 document.getElementById('farm').style.display = 'none' ;
	 document.getElementById('marc').style.display = 'none' ;
	 //document.getElementById('mta').style.display = 'none' ;
	 document.getElementById('mva').style.display = 'none' ;
	 document.getElementById('parkride').style.display = 'none' ;
	 document.getElementById('post').style.display = 'none' ;
	 document.getElementById('veip').style.display = 'none' ;
	 document.getElementById('wm').style.display = 'none' ;
}

function clearAll(){
    document.getElementById('repName').innerHTML = ""; 
	document.getElementById('roadDistrictName').innerHTML = "";
	document.getElementById('trashDay').innerHTML = "";
	document.getElementById('fireDeptName').innerHTML = "";
	document.getElementById('policeDeptName').innerHTML = "";
	document.getElementById('routeStreet').innerHTML = "";
}	

function toggleTool(toolDiv){
	//alert(toolDiv + ":" + document.getElementById(toolDiv).style.display);
	if(document.getElementById("genAddressBanner").innerHTML == 'none'){
		alert("An address must be mapped before this information can be retrieved");
		javascript:YAHOO.structAddr.container.structAddrDialog.show();
	} 
	else{
		closeAll();
		if(roadGraphic && toolDiv != "roadDistrict"){
			roadGraphic.hide();
			genMyaa.removeVisibleLayer(roadDistrictLayerNum);
			document.getElementById('roadMapTxt').innerHTML = "Show Road Districts";
		}
		if(councilGraphic && toolDiv != "council"){
			councilGraphic.hide();
			genMyaa.removeVisibleLayer(councilLayerNum);
			document.getElementById('councilMapTxt').innerHTML = "Show Council Districts";
		}
		if(pdGraphic && toolDiv != "policeDept"){
			pdGraphic.hide();
			genMyaa.removeVisibleLayer(policeDistrictLayerNum);
			document.getElementById('policeMapTxt').innerHTML = "Show Police Districts";
		}
		document.getElementById(toolDiv).style.display = "inline";			
	}
}	

function toggleCategoryMenu(){
	if(document.getElementById('categoryMenuImg').src.search('greenPlus.png') != -1){		YAHOO.ui.container.categoryDialog.show();		document.getElementById('categoryMenuImg').src = "/MyAA/images/redX.png";	}
	else{
		YAHOO.ui.container.categoryDialog.hide();	
		document.getElementById('categoryMenuImg').src = "/MyAA/images/greenPlus.png";	}		
}

function toggleMenuIcon(){
	if(document.getElementById('menuIcon').src.search('arrowBrown.gif') != -1){
		document.getElementById('menuIcon').src = "/MyAA/images/arrowWhite.gif";
		document.getElementById('menuTD').style.backgroundColor = "#4C4545";
		document.getElementById('menuTag').style.color = "white";
		YAHOO.ui.container.menuDialog.show();
	}
	else{
		//document.getElementById('menuIcon').src = "/MyAA/images/arrowBrown.gif";
		YAHOO.ui.container.menuDialog.hide();	
	}		
}


function loadPrintLayout(){
	printMap(genMap.map,"gen");
}

function getParcel() {
	//alert("got to parcel:" + selectedAddress.annapolis);
	gsvc = new esri.tasks.GeometryService(geometryServiceURL);
    var outSR = new esri.SpatialReference({ wkid: 4326});

    gsvc.project([selectedAddress.genGraphic.graphic], outSR, function(features) {
      results = features[0].geometry;
      selectedAddress.latitude = Math.round(results.y * 10000)/10000;
      selectedAddress.longitude = Math.round(results.x * 10000)/10000;  
      //alert("lat/long: "  + selectedAddress.latitude + "/" + selectedAddress.longitude); 

		if (selectedAddress.annapolis && selectedAddress.type == "structureAddress"){
			var infoTemplate = new esri.InfoTemplate("<a title='Zoom Here' href='javascript:genMap.changeExtentByXY(" + selectedAddress.x  + "," + selectedAddress.y + ",1000);genMap.map.infoWindow.hide();'><b>" + selectedAddress.address + "</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>City:</b></td><td width='75%'>" + selectedAddress.city + "</td></tr><tr><td width='25%'><b>Zip:</b></td><td width='75%'>" + selectedAddress.zip + "</td></tr><tr><td colspan='2'><br><img src='/MyAA/images/page_go.png'>&nbsp;&nbsp;<a href='http://aacoprod.aacounty.org/MyAA/pages/birdsEyeView.html?lat=" + selectedAddress.latitude + "&long=" + selectedAddress.longitude + "' target='_blank'>Bird's Eye View</a></td></tr></table>");
			selectedAddress.genGraphic.graphic.infoTemplate = infoTemplate;
			selectedAddress.genGraphic.graphic.setInfoTemplate(infoTemplate);
			selectedAddress.genGraphic.show();
			genMap.parcelGraphicsLayer = new esri.layers.GraphicsLayer();
		}
		else if (selectedAddress.type == "streetCenterline"){
			var infoTemplate = new esri.InfoTemplate("<a title='Zoom Here' href='javascript:genMap.changeExtentByXY(" + selectedAddress.x  + "," + selectedAddress.y + ",1000);genMap.map.infoWindow.hide();'><b>" + selectedAddress.address + "</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Zip:</b></td><td width='75%'>" + selectedAddress.zip + "</td></tr><tr><td colspan='2'><br><img src='/MyAA/images/page_go.png'>&nbsp;&nbsp;<a href='http://aacoprod.aacounty.org/MyAA/pages/birdsEyeView.html?lat=" + selectedAddress.latitude + "&long=" + selectedAddress.longitude + "' target='_blank'>Bird's Eye View</a></td></tr></table>");
			selectedAddress.genGraphic.graphic.infoTemplate = infoTemplate;
			selectedAddress.genGraphic.graphic.setInfoTemplate(infoTemplate);
			selectedAddress.genGraphic.show();
			genMap.parcelGraphicsLayer = new esri.layers.GraphicsLayer();
		}
		else{
			parcelQuery = new Query(parcelQueryURL, ["ACCOUNT_NO"]);
			parcelQuery.query.geometry = selectedAddress.point;
			parcelQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
			dojo.connect(parcelQuery.queryTask, "onComplete", function(fset) {
				var featureAttributes = fset.features[0].attributes;
				var accountNo = "";
				for (att in featureAttributes) {
					if (att == "ACCOUNT_NO"){
						accountNo = featureAttributes[att];
						//alert("accountNo:" + accountNo);
					}
				}
	
				var parcelSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100,100,100]), 2), new dojo.Color([82,178,209,0.20]));
				genMap.parcelGraphicsLayer = new esri.layers.GraphicsLayer();
				genMap.map.addLayer(genMap.parcelGraphicsLayer);
	        	
	        	parcelsQuery = new Query(parcelQueryURL, ["PIN","ACCOUNT_NO"]);
				parcelsQuery.query.where = "ACCOUNT_NO = '" + accountNo + "'"; 
	
				
				dojo.connect(parcelsQuery.queryTask, "onComplete", function(parcels) {				
					parcelGraphics =[];
					for (var i=0, il=parcels.features.length; i<il; i++) {
						var featureAttributes = parcels.features[i].attributes;
						parcelGraphics.push(new Graphic(parcels.features[i],genMap.parcelGraphicsLayer,false,parcelSymbol));		
						
						var pin = "";
						var acctNo = "";
						
						for (att in featureAttributes) {											
	
							if(att == "PIN"){
								pin =  featureAttributes[att]; 
								//alert("pin:" + pin);
							}
							if (att == "ACCOUNT_NO"){
								acctNo = featureAttributes[att];
								//alert("accountNo:" + acctNo);
							}
						}
			        }
			   
					var district  = "0" + acctNo.substring(0,1);
					var subdivision  = acctNo.substring(1,4);
	          		var acct  = acctNo.substring(4,12);
	          		//alert("sdat:" + district + ":" + subdivision + ":" + acct);
	         		var url = "http://sdatcert3.resiusa.org/rp_rewrite/details.aspx?County=02&SearchType=ACCT&District=" + district + "&AccountNumber=" + acct + "&subDiv=" + subdivision;
			    	var showTemplate = new esri.InfoTemplate("<a title='Zoom Here' href='javascript:genMap.changeExtentByXY(" + selectedAddress.x  + "," + selectedAddress.y + ",1000);genMap.map.infoWindow.hide();'><b>" + selectedAddress.address + "</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>City:</b></td><td width='75%'>" + selectedAddress.city + "</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>" + selectedAddress.zip + "</td></tr></table><br/><br/><img src='/MyAA/images/page_go.png'>&nbsp;&nbsp;<a target='_blank' href='" + url + "'>Md SDAT Real Property Data Search</a><br/><br/><img src='/MyAA/images/world.png'>&nbsp;&nbsp;<a id='parcelLink' href='javascript:toggleParcel();'>Show Parcel(s)</a><br><br><img src='/MyAA/images/page_go.png'>&nbsp;&nbsp;<a href='http://aacoprod.aacounty.org/MyAA/pages/birdsEyeView.html?lat=" + selectedAddress.latitude + "&long=" + selectedAddress.longitude + "' target='_blank'>Bird's Eye View</a>");
					var hideTemplate = new esri.InfoTemplate("<a title='Zoom Here' href='javascript:genMap.changeExtentByXY(" + selectedAddress.x  + "," + selectedAddress.y + ",1000);genMap.map.infoWindow.hide();'><b>" + selectedAddress.address + "</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>City:</b></td><td width='75%'>" + selectedAddress.city + "</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>" + selectedAddress.zip + "</td></tr></table><br/><br/><img src='/MyAA/images/page_go.png'>&nbsp;&nbsp;<a target='_blank' href='" + url + "'>Md SDAT Real Property Data Search</a><br/><br/><img src='/MyAA/images/world.png'>&nbsp;&nbsp;<a id='parcelLink' href='javascript:toggleParcel();'>Hide Parcel(s)</a><br><br><img src='/MyAA/images/page_go.png'>&nbsp;&nbsp;<a href='http://aacoprod.aacounty.org/MyAA/pages/birdsEyeView.html?lat=" + selectedAddress.latitude + "&long=" + selectedAddress.longitude + "' target='_blank'>Bird's Eye View</a>");
			    	selectedAddress.showTemplate = showTemplate;
					selectedAddress.hideTemplate = hideTemplate;
					selectedAddress.parcelGraphics = parcelGraphics;				
					selectedAddress.genGraphic.graphic.setInfoTemplate(showTemplate);
					selectedAddress.genGraphic.show();		
				});   	        	
				parcelsQuery.executeQuery();		
			});	
			parcelQuery.executeQuery();
		}
    });
}

function toggleParcel(){
	//alert("parcelGraphics.length:" + selectedAddress.parcelGraphics.length);
	if (selectedAddress.parcelGraphics[0].visible == false){
		selectedAddress.genGraphic.graphic.setInfoTemplate(selectedAddress.hideTemplate);
		roadGraphic.hide();
		genMyaa.removeVisibleLayer(roadDistrictLayerNum);
		councilGraphic.hide();
		genMyaa.removeVisibleLayer(councilLayerNum);
		document.getElementById('councilMapTxt').innerHTML = "Show Council Districts";
		document.getElementById('roadMapTxt').innerHTML = "Show Road Districts";
		for (var i=0, il=selectedAddress.parcelGraphics.length; i<il; i++) {						
			selectedAddress.parcelGraphics[i].show();
		}
		var xmin = selectedAddress.parcelGraphics[0].graphic.geometry.getExtent().xmin - 500;
		var xmax = selectedAddress.parcelGraphics[0].graphic.geometry.getExtent().xmax + 500;
		var ymin = selectedAddress.parcelGraphics[0].graphic.geometry.getExtent().ymin - 500;
		var ymax = selectedAddress.parcelGraphics[0].graphic.geometry.getExtent().ymax + 500;
		
		genMap.changeExtentByCoords(xmin,xmax,ymin,ymax);
		genMap.map.infoWindow.hide();			
	}
	else{
		for (var i=0, il=selectedAddress.parcelGraphics.length; i<il; i++) {
			selectedAddress.parcelGraphics[i].hide();
		}
		selectedAddress.genGraphic.graphic.setInfoTemplate(selectedAddress.showTemplate);
		genMap.map.infoWindow.hide();
	}	
}
	
		

function getCouncil() {
		councilQuery = new Query(councilQueryURL, ["COUNCILS","CNCLDIST"]);
		councilQuery.query.geometry = selectedAddress.point;
		councilQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
		dojo.connect(councilQuery.queryTask, "onComplete", function(fset) {
		var featureAttributes = fset.features[0].attributes;
			var councilDistrict = "";
			var councilRep = "";
			for (att in featureAttributes) {
				if(att == "CNCLDIST"){
					councilDistrict =  featureAttributes[att];
				}
				if (att == "COUNCILS"){
					councilRep = featureAttributes[att];
				}
			}
			//alert(councilDistrict + councilRep);
			document.getElementById('repName').innerHTML = councilRep;
			document.getElementById('repDistrict').innerHTML = councilDistrict;
			if(councilDistrict == "District 1"){
				document.getElementById('repImg').innerHTML = "<img src=" + district1ImgURL + " border='1' height='85' width='60'>";
				document.getElementById('repSite').innerHTML = "<a id='repSiteLink' href=" + district1URL + " target='_blank'>More Information</a>";
			}
			else if(councilDistrict == "District 2"){
				document.getElementById('repImg').innerHTML = "<img src=" + district2ImgURL + " border='1' height='85' width='60'>";
				document.getElementById('repSite').innerHTML = "<a id='repSiteLink' href=" + district2URL + " target='_blank'>More Information</a>";
			}
			else if(councilDistrict == "District 3"){
				document.getElementById('repImg').innerHTML = "<img src=" + district3ImgURL + " border='1' height='85' width='60'>";
				document.getElementById('repSite').innerHTML = "<a id='repSiteLink' href=" + district3URL + " target='_blank'>More Information</a>";
			}		
			else if(councilDistrict == "District 4"){
				document.getElementById('repImg').innerHTML = "<img src=" + district4ImgURL + " border='1' height='85' width='60'>";
				document.getElementById('repSite').innerHTML = "<a id='repSiteLink' href=" + district4URL + " target='_blank'>More Information</a>";
			}
			else if(councilDistrict == "District 5"){
				document.getElementById('repImg').innerHTML = "<img src=" + district5ImgURL + " border='1' height='85' width='60'>";
				document.getElementById('repSite').innerHTML = "<a id='repSiteLink' href=" + district5URL + " target='_blank'>More Information</a>";
			}
			else if(councilDistrict == "District 6"){
				document.getElementById('repImg').innerHTML = "<img src=" + district6ImgURL + " border='1' height='85' width='60'>";
				document.getElementById('repSite').innerHTML = "<a id='repSiteLink' href=" + district6URL + " target='_blank'>More Information</a>";
			}
			else if(councilDistrict == "District 7"){
				document.getElementById('repImg').innerHTML = "<img src=" + district7ImgURL + " border='1' height='85' width='60'>";
				document.getElementById('repSite').innerHTML = "<a id='repSiteLink' href=" + district7URL + " target='_blank'>More Information</a>";
			}
			
			var councilSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,0,0,0.20]));
          	//var councilTemplate = new esri.InfoTemplate("Council District: ${CNCLDIST}" ,"Representative:  ${COUNCILS}");
			genMap.councilGraphicsLayer = new esri.layers.GraphicsLayer();
			genMap.map.addLayer(genMap.councilGraphicsLayer);
			councilGraphic = new Graphic(fset.features[0],genMap.councilGraphicsLayer,false,councilSymbol);
			loadStatus.council = true;
			loadStatus.checkStatus("council");
		});
		councilQuery.executeQuery();
}

function getElemSchool() {
		elemSchoolQuery = new Query(elemSchoolQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
		elemSchoolQuery.query.geometry = selectedAddress.point;
		elemSchoolQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
		dojo.connect(elemSchoolQuery.queryTask, "onComplete", function(fset) {
			var featureAttributes = fset.features[0].attributes;
			var elemSchoolName = "";
			var elemSchoolAddr = "";
			var elemSchoolCity = "";
			var elemSchoolZip = "";
			for (att in featureAttributes) {
				if(att == "FEATURE_NA"){
					elemSchoolName =  featureAttributes[att];
					//alert(elemSchoolName);
				}
				if (att == "ADDRESS"){
					elemSchoolAddr = featureAttributes[att];
				}	
				if(att == "CITY"){
					elemSchoolCity =  featureAttributes[att];
				}
				if (att == "ZIP_CODE"){
					elemSchoolZip = featureAttributes[att];
				}	
			}		
			document.getElementById('eSchoolName').innerHTML = elemSchoolName;
			getSchoolPOI("eSchool", elemSchoolAddr, elemSchoolCity, elemSchoolZip);
		});
		elemSchoolQuery.executeQuery();			
}

function getMiddleSchool() {
		middleSchoolQuery = new Query(middleSchoolQueryURL, ["FEATURE_NA","ADDRESS","CITY","ZIP_CODE"]);
		middleSchoolQuery.query.geometry = selectedAddress.point;
		middleSchoolQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
		dojo.connect(middleSchoolQuery.queryTask, "onComplete", function(fset) {
			var featureAttributes = fset.features[0].attributes;
			var middleSchoolName = "";
			var middleSchoolAddr = "";
			var middleSchoolCity = "";
			var middleSchoolZip = "";
			for (att in featureAttributes) {
				if(att == "FEATURE_NA"){
					middleSchoolName =  featureAttributes[att];
					//alert(middleSchoolName);
				}
				if (att == "ADDRESS"){
					middleSchoolAddr = featureAttributes[att];
					//alert(middleSchoolName + ":" + middleSchoolAddr);
				}	
				if(att == "CITY"){
					middleSchoolCity =  featureAttributes[att];
				}
				if (att == "ZIP_CODE"){
					middleSchoolZip = featureAttributes[att];
				}	
			}		
			document.getElementById('mSchoolName').innerHTML = middleSchoolName;
			getSchoolPOI("mSchool", middleSchoolAddr,middleSchoolCity,middleSchoolZip);
		});
		middleSchoolQuery.executeQuery();			
}
					
function getHighSchool() {
		highSchoolQuery = new Query(highSchoolQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
		highSchoolQuery.query.geometry = selectedAddress.point;
		highSchoolQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
		dojo.connect(highSchoolQuery.queryTask, "onComplete", function(fset) {
			var featureAttributes = fset.features[0].attributes;
			var highSchoolName = "";
			var highSchoolAddr = "";
			var highSchoolCity = "";
			var highSchoolZip = "";
			for (att in featureAttributes) {
				if(att == "feature_na"){
					highSchoolName =  featureAttributes[att];
				}
				if (att == "ADDRESS"){
					highSchoolAddr = featureAttributes[att];
					//alert(highSchoolName + ":" + highSchoolAddr);
				}	
				if(att == "CITY"){
					highSchoolCity =  featureAttributes[att];
				}
				if (att == "ZIP_CODE"){
					highSchoolZip = featureAttributes[att];
				}	
			}		
			document.getElementById('hSchoolName').innerHTML = highSchoolName;
			getSchoolPOI("hSchool", highSchoolAddr,highSchoolCity,highSchoolZip);
			loadStatus.school = true;
			loadStatus.checkStatus("school");
		});
		highSchoolQuery.executeQuery();			
}

function getSchoolPOI(type, schoolAddress, schoolCity, schoolZip){
		schoolPOIQuery = new Query(poiQueryURL, ["CATEGORY","feature_na","ADDRESS","CITY","ZIP_CODE","POINT_X","POINT_Y"]);
		schoolPOIQuery.query.where =  "ADDRESS = '" + schoolAddress + "'"; 
		dojo.connect(schoolPOIQuery.queryTask, "onComplete", function(featureSet) {
			
			var schoolCategory = "";
			var schoolName = "";
			var schoolAddr = "";
			var schoolCity = "";
			var schoolZip = "";
			var schoolX = "";
			var schoolY = "";
			var schoolGraphic;
			var found = "N";
			
			for (var i=0, il=featureSet.features.length; i<il; i++) {
				var schoolAttributes = featureSet.features[i].attributes;
				for (att in schoolAttributes) {
				    if (att == "CATEGORY"){
				    	schoolCategory = schoolAttributes[att];
				    }
				    else if(att == "feature_na"){
						schoolName = schoolAttributes[att];
						if((type == "eSchool" && schoolCategory == "SCHOOL_ELEMENTARY") || 
							(type == "mSchool" && schoolCategory == "SCHOOL_MIDDLE") ||
							(type == "hSchool" && schoolCategory == "SCHOOL_HIGH")){
							schoolGraphic = featureSet.features[i];
							found = "Y"
						}								 
					}
					else if(att == "ADDRESS" && found == "Y"){
						schoolAddr = schoolAttributes[att];
					}
					else if(att == "CITY"  && found == "Y"){
						schoolCity = schoolAttributes[att];
					}
					else if(att == "ZIP_CODE" && found == "Y"){
						schoolZip = schoolAttributes[att];
					}
					else if(att == "POINT_X" && found == "Y"){
						schoolX = schoolAttributes[att];
					}
					else if(att == "POINT_Y" && found == "Y"){
						schoolY = schoolAttributes[att];
					}	
				}
			}
			
			if(found == "Y"){	
				populateZoomLink(type,schoolX,schoolY);
				var symbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/school.png', 25, 25);
				var template = new esri.InfoTemplate("<a  title='Zoom Here' title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + schoolX  + "," + schoolY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				if (type == "eSchool"){
					document.getElementById('eSchoolDirections').innerHTML = getDirectionsURL(schoolAddr + ", " + schoolCity + ", MD " + schoolZip);					
					document.getElementById('eSchoolAddr').innerHTML = schoolAddr + "<br>" + schoolCity + ", MD " + schoolZip;
					eSchoolGraphic = new Graphic(schoolGraphic,genMap.map.graphics,true,symbol,template);	
				}
				if (type == "mSchool"){
					document.getElementById('mSchoolDirections').innerHTML = getDirectionsURL(schoolAddr + ", " + schoolCity + ", MD " + schoolZip);					
					document.getElementById('mSchoolAddr').innerHTML = schoolAddr + "<br>" + schoolCity + ", MD " + schoolZip;
					mSchoolGraphic = new Graphic(schoolGraphic,genMap.map.graphics,true,symbol,template);
				}
				if (type == "hSchool"){
					document.getElementById('hSchoolDirections').innerHTML = getDirectionsURL(schoolAddr + ", " + schoolCity + ", MD " + schoolZip);					
					document.getElementById('hSchoolAddr').innerHTML = schoolAddr + "<br>" + schoolCity + ", MD " + schoolZip;
					hSchoolGraphic = new Graphic(schoolGraphic,genMap.map.graphics,true,symbol,template);
				}
				
			}
			else{
				if (type == "eSchool"){
					document.getElementById('eSchoolName').innerHTML = 'Not Found';
					document.getElementById('eSchoolAddr').innerHTML = 'Not Found';
					document.getElementById('eSchoolDirections').innerHTML = "";
					document.getElementById('eSchoolZoom').innerHTML = " ";
				}
				if (type == "mSchool"){
					document.getElementById('mSchoolName').innerHTML = 'Not Found';
					document.getElementById('mSchoolAddr').innerHTML = 'Not Found';
					document.getElementById('mSchoolDirections').innerHTML = "";
					document.getElementById('mSchoolZoom').innerHTML = " ";
				}
				if (type == "hSchool"){
					document.getElementById('hSchoolName').innerHTML = 'Not Found';
					document.getElementById('hSchoolAddr').innerHTML = 'Not Found';
					document.getElementById('hSchoolDirections').innerHTML = "";
					document.getElementById('hSchoolZoom').innerHTML = " ";
				}
			}
			
			if (type == "eSchool"){getMiddleSchool();}			
			else if (type == "mSchool"){getHighSchool();}				
		});
		schoolPOIQuery.executeQuery();
}

function checkAnnapolis(){
		annapolisQuery = new Query(annapolisQueryURL, ["NAME"]);
		annapolisQuery.query.geometry = selectedAddress.point;
		annapolisQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
		dojo.connect(annapolisQuery.queryTask, "onComplete", function(fset) {	
			if (fset.features.length > 0){
				var featureAttributes = fset.features[0].attributes;
				for (att in featureAttributes) {
					if(att == "NAME"){
						selectedAddress.annapolis = true;
					}
				}
			}
			getParcel();
			getPolice();
		});
		annapolisQuery.executeQuery();

}

function getAAID(){
	aaidQuery = new Query(structAddrURL, ["AAID"]);
	aaidQuery.query.where = "FULL_ADDRE = '" + selectedAddress.address + "'"; 
	dojo.connect(aaidQuery.queryTask, "onComplete", function(fset) {	
		if (fset.features.length > 0){
			var featureAttributes = fset.features[0].attributes;
			for (att in featureAttributes) {
				if(att == "AAID"){
					//alert("AAID:" + featureAttributes[att]);
					selectedAddress.AAID = featureAttributes[att];
				}
			}
			streetNameQuery = new Query(streetCenterlineURL, ["NAMEFULL"]);
			streetNameQuery.query.where = "AAID = '" + selectedAddress.AAID + "'"; 
			dojo.connect(streetNameQuery.queryTask, "onComplete", function(fset) {	
				if (fset.features.length > 0){
					var featureAttributes = fset.features[0].attributes;
					for (att in featureAttributes) {
						if(att == "NAMEFULL"){
							//alert("streetName:" + featureAttributes[att]);
							selectedAddress.streetName = featureAttributes[att];
							getTrash(100,esri.tasks.BufferParameters.UNIT_FOOT);
						}
					}
				}
				else{
					selectedAddress.streetName = "not found";
					getTrash(100,esri.tasks.BufferParameters.UNIT_FOOT);
				}
			});
			streetNameQuery.executeQuery();
		}
		else{
			selectedAddress.streetName = "not found";
			getTrash(100,esri.tasks.BufferParameters.UNIT_FOOT);
		}
	});
	aaidQuery.executeQuery();
}

function getRoadDistrict() {
		roadQuery = new Query(roadQueryURL, ["District"]);
		roadQuery.query.geometry = selectedAddress.point;
		roadQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
		dojo.connect(roadQuery.queryTask, "onComplete", function(fset) {

			var featureAttributes = fset.features[0].attributes;
			var roadDistrict = "";
			for (att in featureAttributes) {
				if(att == "District"){
					roadDistrict =  featureAttributes[att];
					//alert("district:" + roadDistrict);
				}
			}
			document.getElementById('roadDistrictName').innerHTML = roadDistrict;
			
			if (roadDistrict == "Northern"){
				document.getElementById('roadDistrictPhone').innerHTML  = bohNorthernPhone;
			}
			else if (roadDistrict == "Central"){
				document.getElementById('roadDistrictPhone').innerHTML  = bohCentralPhone;
			}
			else if (roadDistrict == "Southern"){
				document.getElementById('roadDistrictPhone').innerHTML  = bohSouthernPhone;
			}
			else if (roadDistrict == "City of Annapolis"){
				document.getElementById('roadDistrictPhone').innerHTML  = bohAnnapolisPhone;
			}
			
			var roadSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,0,0,0.20]));
          	//var roadTemplate = new esri.InfoTemplate("Road District: ${District}" ,"Contact Number:" + document.getElementById('roadDistrictPhone').innerHTML);
			genMap.roadGraphicsLayer = new esri.layers.GraphicsLayer();
			genMap.map.addLayer(genMap.roadGraphicsLayer);
			roadGraphic = new Graphic(fset.features[0],genMap.roadGraphicsLayer,false,roadSymbol);
			loadStatus.road = true;
			loadStatus.checkStatus("road");
		});
		roadQuery.executeQuery();
}

function callTrash(distance){
	//alert("callTrash:" + distance);
	newDistance = distance + 50;
	getTrash(newDistance, esri.tasks.BufferParameters.UNIT_FOOT);
	
	//if (distance == 100){
	//	newDistance = 200;
	//	getTrash(newDistance, esri.tasks.BufferParameters.UNIT_FOOT);
	//}
	//else if (distance == 200){
	//	newDistance = 300;
	//	getTrash(newDistance, esri.tasks.BufferParameters.UNIT_FOOT);
	//}
	//else if (distance == 300){
	//	newDistance = 1000;
	//	getTrash(newDistance, esri.tasks.BufferParameters.UNIT_FOOT);
	//}
	//else{
	//	alert("A nearby trash route on your street could not be located.");
	//	document.getElementById('trashDay').innerHTML = "Route not found";
	//	document.getElementById('recycleDay').innerHTML = "Route not found";
	///	document.getElementById('trashSite').innerHTML = "";
	//	loadStatus.trash = true;
	//	loadStatus.checkStatus("trash");
	//}	
}

function trim(str) {	
    return str.replace(/\s+/g,'');
}

function getTrash(distance, unit) {
		//genMyaa.addVisibleLayer(2);
		document.getElementById('nearestRoute').style.display = 'none';
		document.getElementById('nearestRouteMessage').style.display = 'none';
		document.getElementById('routeStreet').innerHTML = "";
		var testAddress ="";
		if(selectedAddress.streetName == "not found"){
			testAddress = trim(selectedAddress.address);
		}
		else{
			testAddress = trim(selectedAddress.streetName);
		}
		//alert("getTrash StreetName:" + testAddress);
		geometryService = new esri.tasks.GeometryService(geometryServiceURL);
		var addrSymbol = new esri.symbol.SimpleMarkerSymbol();
        //var addrGraphic = new esri.Graphic(selectedAddress.point, addrSymbol);
        var params = new esri.tasks.BufferParameters();
        params.features = [selectedAddress.genGraphic.graphic];
        params.distances = [distance];
              
		dojo.connect(geometryService, "onBufferComplete", function(graphics) {
		    //alert("Buffer Completed @" + distance);
	        var bufferSymbol = new esri.symbol.SimpleFillSymbol("none", new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
	        var bufferGraphic = new esri.Graphic(graphics[0].geometry,bufferSymbol);
	        //genMap.map.graphics.add(bufferGraphic);
	        trashQuery = new Query(trashQueryURL, ["NAMEFULL","PICKUP","REC_DAY"]);  
	        trashQuery.query.geometry = graphics[0].geometry;
	        trashQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;

			dojo.connect(trashQuery.queryTask, "onError", function(error) {
				alert("error");
			});

			
			dojo.connect(trashQuery.queryTask, "onComplete", function(fset) {
				//alert(fset.features.length + " intersecting routes found @ " + distance);
				if(fset.features.length == 0){
					//alert("no intersecting routes found @ " + distance + " feet");
					callTrash(distance);		
				}
				else if(fset.features.length == 1){
					//alert("1 Result");
					var featureAttributes = fset.features[0].attributes;
					var trashDay = "";
					var recycleDay = "";
					var streetName = "";
					var trimName = "";
					var annapolis = false;
					
					for (att in featureAttributes) {
						if(att == "NAMEFULL"){ 
							streetName = featureAttributes[att];
							trimName = trim(featureAttributes[att]);					
						}
						else if(att == "PICKUP"){ 
							if(featureAttributes[att] == "ANNAPOLIS"){
								annapolis = true;
								trashDay = "City of Annapolis";
							}
							else{
								trashDay = featureAttributes[att];	
							}
						}
						else if(att == "REC_DAY"){
							if(featureAttributes[att] == "ANNAPOLIS"){
								recycleDay = "City of Annapolis";
							}
							else{
								recycleDay = featureAttributes[att];	
							}
						}
					}	
					if(testAddress.search(trimName) != -1){
						//alert("1 Result w/ Matching Street: " + streetName);
						if(annapolis){
							document.getElementById('trashSite').innerHTML = "<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A id='trashSiteLink' HREF=" + annapolisTrashURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">More Information</A>";
						}
						else{
							document.getElementById('trashSite').innerHTML = "<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A id='trashSiteLink' HREF=" + aacoTrashHolidayURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Holiday Collection Schedule</A><br><br>" + 
							"<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A HREF=" + aacoHHWURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Household Hazardous Waste Info</A><br><br>" + 
							"<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A HREF=" + aacoRecycleURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Recycle.More.Often</A>";
						}
						document.getElementById('trashDay').innerHTML = trashDay;
						document.getElementById('recycleDay').innerHTML = recycleDay;
						loadStatus.trash = true;
						loadStatus.checkStatus("trash");
					}
					else{
						//alert("1 Result w/ NonMatching Street: " + streetName);
						document.getElementById('nearestRoute').style.display = 'inline';
						document.getElementById('nearestRouteMessage').style.display = 'inline';
						document.getElementById('routeStreet').innerHTML = streetName;
						if(annapolis){
							document.getElementById('trashSite').innerHTML = "<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A id='trashSiteLink' HREF=" + annapolisTrashURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">More Information</A>";
						}
						else{
							document.getElementById('trashSite').innerHTML = "<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A id='trashSiteLink' HREF=" + aacoTrashHolidayURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Holiday Collection Schedule</A><br><br>" + 
							"<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A HREF=" + aacoHHWURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Household Hazardous Waste Info</A><br><br>" + 
							"<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A HREF=" + aacoRecycleURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Recycle.More.Often</A>";
						}
						document.getElementById('trashDay').innerHTML = trashDay;
						document.getElementById('recycleDay').innerHTML = recycleDay;
						loadStatus.trash = true;
						loadStatus.checkStatus("trash");
					}			
				}
				else{
					var streetMatch = false;
					for (var i=0, il=fset.features.length; i<il; i++) {
						var featureAttributes = fset.features[i].attributes;
						var trashDay = "";
						var recycleDay = "";
						var trimName = "";
						var streetName = "";
						var annapolis = false;
						
						for (att in featureAttributes) {
							if(att == "NAMEFULL"){
								streetName = featureAttributes[att];
								trimName = trim(featureAttributes[att]);	
							}
							else if(att == "PICKUP"){ 
								if(featureAttributes[att] == "ANNAPOLIS"){
									annapolis = true;
									trashDay = "City of Annapolis";
								}
								else{
									trashDay = featureAttributes[att];	
								}
							}
							else if(att == "REC_DAY"){
								if(featureAttributes[att] == "ANNAPOLIS"){
									recycleDay = "City of Annapolis";
								}
								else{
									recycleDay = featureAttributes[att];	
								}
							}
						
							if (streetName != "" && trashDay != "" && recycleDay !=""){
								if(testAddress.search(trimName) != -1 && streetMatch == false){
									if(annapolis){
										document.getElementById('trashSite').innerHTML = "<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A id='trashSiteLink' HREF=" + annapolisTrashURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">More Information</A>";
									}
									else{
										document.getElementById('trashSite').innerHTML = "<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A id='trashSiteLink' HREF=" + aacoTrashHolidayURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Holiday Collection Schedule</A><br><br>" + 
										"<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A HREF=" + aacoHHWURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Household Hazardous Waste Info</A><br><br>" + 
										"<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A HREF=" + aacoRecycleURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Recycle.More.Often</A>";
									}
									//alert("Result w/ Matching Street:" + streetName);
									document.getElementById('trashDay').innerHTML = trashDay;
									document.getElementById('recycleDay').innerHTML = recycleDay;
									streetMatch = true;
								}
								else if(document.getElementById('routeStreet').innerHTML == "" && streetMatch == false){
									document.getElementById('routeStreet').innerHTML = streetName;
									if(annapolis){
										document.getElementById('trashSite').innerHTML = "<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A id='trashSiteLink' HREF=" + annapolisTrashURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">More Information</A>";
									}
									else{
										document.getElementById('trashSite').innerHTML = "<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A id='trashSiteLink' HREF=" + aacoTrashHolidayURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Holiday Collection Schedule</A><br><br>" + 
										"<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A HREF=" + aacoHHWURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Household Hazardous Waste Info</A><br><br>" + 
										"<IMG SRC='/MyAA/images/page_go.png'>&nbsp;&nbsp;<A HREF=" + aacoRecycleURL + " TARGET='_blank' STYLE=\"font-size: 8pt; font-weight: bold;\">Recycle.More.Often</A>";
									}
									//alert("Result w/ NonMatching Street:" + streetName);
									document.getElementById('trashDay').innerHTML = trashDay;
									document.getElementById('recycleDay').innerHTML = recycleDay;
								}
							}		
						}												
					}
					
					if (streetMatch){
						document.getElementById('nearestRoute').style.display = 'none';
						document.getElementById('nearestRouteMessage').style.display = 'none';
						document.getElementById('routeStreet').innerHTML = "";
					}
					else{
						document.getElementById('nearestRouteMessage').style.display = 'inline';
						document.getElementById('nearestRoute').style.display = 'inline';
					}
					loadStatus.trash = true;
					loadStatus.checkStatus("trash");
				}			
			});
			trashQuery.executeQuery();
        });	
        geometryService.buffer(params);	
}

function getFire(){
		//myaa.addVisibleLayer(8);
		fireQuery = new Query(fireQueryURL, ["COMPANY","Company_na"]);
		fireQuery.query.geometry = selectedAddress.point;
		fireQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
		dojo.connect(fireQuery.queryTask, "onComplete", function(fset) {
		var featureAttributes = fset.features[0].attributes;
			var name = "";
			var company = "";
			for (att in featureAttributes) {
				if(att == "Company_na"){
					name = featureAttributes[att];
					//alert("FireDept:" + name);
				}
				else if(att == "COMPANY"){
					company = "Co. " + featureAttributes[att];
					companyImg = featureAttributes[att];
					//alert("FireDept:" + company);
				}
			}
			firePOIQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE","POINT_X","POINT_Y"]);
			firePOIQuery.query.text =  "FIRE_DEPT"; 
			dojo.connect(firePOIQuery.queryTask, "onComplete", function(featureSet) {
				var fireName = "";
				var fireAddr = "";
				var fireCity = "";
				var fireZip = "";
				var fireX = "";
				var fireY = "";
				var fireGraphic;
									
				var found = "N";
				
				for (var i=0, il=featureSet.features.length; i<il; i++) {
					var fireAttributes = featureSet.features[i].attributes;
					for (att in fireAttributes) {		
					    if(att == "feature_na"){
							fireName = fireAttributes[att];
							//alert(fireName);
							if (fireName.search(company)!= -1){
								var index = fireName.search(company);
								//alert(company + ":" + company.length + ":" + index);
								if(company.length == 5){
									if(fireName.length == (index + 5)){
										fireGraphic = featureSet.features[i];
										found = "Y";
									}
								}
								else if(company.length == 6){
									if(fireName.length == (index + 6)){
										fireGraphic = featureSet.features[i]
										found = "Y";
									}
								}
							}
						}
						else if(att == "ADDRESS" && found == "Y"){
							fireAddr = fireAttributes[att];
						}
						else if(att == "CITY"  && found == "Y"){
							fireCity = fireAttributes[att];
						}
						else if(att == "ZIP_CODE" && found == "Y"){
							fireZip = fireAttributes[att];
						}
						else if(att == "POINT_X" && found == "Y"){
							fireX = fireAttributes[att];
						}
						else if(att == "POINT_Y" && found == "Y"){
							fireY = fireAttributes[att];
						}
					
						if(found == "Y" && fireY != ""){	
							document.getElementById('fireDeptName').innerHTML = fireName;
							document.getElementById('fireDeptAddress').innerHTML = fireAddr + "<br>" + fireCity + ", MD " + fireZip;
							populateZoomLink('fireDept',fireX,fireY);
							document.getElementById('fireDeptDirections').innerHTML = getDirectionsURL(fireAddr + " " + fireCity + ", MD " + fireZip);					
							var symbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/firemen.png', 25, 25);
							var template = new esri.InfoTemplate("<a  title='Zoom Here' title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + fireX  + "," + fireY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table><br/><center><img height='80' onerror='this.style.display=\"none\"' width='140' src='/MyAA/images/" + companyImg + ".jpg'/></center>");
							fireDeptGraphic = new Graphic(fireGraphic,genMap.map.graphics,true,symbol,template);
							loadStatus.fire = true;
							loadStatus.checkStatus("fire");
							i = il + 1;
							break;
						}
					}
				}
				if(found == "N"){
					document.getElementById('fireDeptName').innerHTML = 'Not Found';
					document.getElementById('fireDeptAddress').innerHTML = 'Not Found';
					document.getElementById('fireDeptDirections').innerHTML = "";
					document.getElementById('fireDeptZoom').innerHTML = " ";
					loadStatus.fire = true;
					loadStatus.checkStatus("fire");
				} 
			});
			firePOIQuery.executeQuery();
		});
		fireQuery.executeQuery();
}

function getPolice(){
	//alert("roadDistrict for Police:" + roadDistrict);
		policeQuery = new Query(policeQueryURL, ["DIST"]);
		policeQuery.query.geometry = selectedAddress.point;
		policeQuery.query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
		dojo.connect(policeQuery.queryTask, "onComplete", function(fset) {
			var featureAttributes = fset.features[0].attributes;
			var name = "";
			for (att in featureAttributes) {
				if(att == "DIST"){
					name = featureAttributes[att];
				}
			}

			var pdSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,0,0,0.20]));
			genMap.pdGraphicsLayer = new esri.layers.GraphicsLayer();
			genMap.map.addLayer(genMap.pdGraphicsLayer);
			pdGraphic = new Graphic(fset.features[0],genMap.pdGraphicsLayer,false,pdSymbol);
			
	    	if (selectedAddress.annapolis){
	    		name = "Annapolis";
	    	}
			
			policePOIQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE","POINT_X","POINT_Y"]);
			policePOIQuery.query.text =  "POLICE_DEPT"; 
			dojo.connect(policePOIQuery.queryTask, "onComplete", function(featureSet) {
				var policeName = "";
				var policeAddr = "";
				var policeCity = "";
				var policeZip = "";
				var policeX = "";
				var policeY = "";
				var policeGraphic;
									
				var found = "N";
				
				for (var i=0, il=featureSet.features.length; i<il; i++) {
					var policeAttributes = featureSet.features[i].attributes;
					for (att in policeAttributes) {		
					    if(att == "feature_na"){
					    	policeName = policeAttributes[att];
							//alert("names:" + policeName);
							if (policeName.search(name)!= -1){
								//alert("match:" + policeAttributes[att]);
								policeGraphic = featureSet.features[i];
								found = "Y";
							}
						}
						else if(att == "ADDRESS" && found == "Y"){
							policeAddr = policeAttributes[att];
						}
						else if(att == "CITY"  && found == "Y"){
							policeCity = policeAttributes[att];
						}
						else if(att == "ZIP_CODE" && found == "Y"){
							policeZip = policeAttributes[att];
						}
						else if(att == "POINT_X" && found == "Y"){
							policeX = policeAttributes[att];
						}
						else if(att == "POINT_Y" && found == "Y"){
							policeY = policeAttributes[att];
						}
					
						if(found == "Y" && policeY != ""){	
							document.getElementById('policeDeptName').innerHTML = policeName;
							document.getElementById('policeDeptAddress').innerHTML = policeAddr + "<br>" + policeCity + ", MD " + policeZip;
							populateZoomLink('policeDept',policeX,policeY);
							if (selectedAddress.annapolis){
								document.getElementById('policeDeptSite').innerHTML = "&nbsp;<A ID='policeLink' TARGET='_blank' HREF=" + annapolisPoliceSiteURL + " STYLE='font-size: 8pt; font-weight: bold; vertical-align: middle;'>More Information</A>";
							}
							else{
								document.getElementById('policeDeptSite').innerHTML = "&nbsp;<A ID='policeLink' TARGET='_blank' HREF=" + aacoPoliceSiteURL + " STYLE='font-size: 8pt; font-weight: bold; vertical-align: middle;'>More Information</A>";
							}
							document.getElementById('policeDeptDirections').innerHTML = getDirectionsURL(policeAddr + " " + policeCity + ", MD " + policeZip);					
							var symbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/police.png', 25, 25);
							var template = new esri.InfoTemplate("<a  title='Zoom Here' title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + policeX  + "," + policeY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table><br/><center><img height='80' onerror='this.style.display=\"none\"' width='140' src='/MyAA/images/" + name + ".jpg'/></center>");
							policeDeptGraphic = new Graphic(policeGraphic,genMap.map.graphics,true,symbol,template);							
													
							loadStatus.police = true;
							loadStatus.checkStatus("police");
							i = il + 1;
							break;
						}
					}
				}
				if(found == "N"){ 
					document.getElementById('policeDeptName').innerHTML = 'Not Found';
					document.getElementById('policeDeptAddress').innerHTML = 'Not Found';
					document.getElementById('policeDeptDirections').innerHTML = " ";
					document.getElementById('policeDeptZoom').innerHTML = " ";
					loadStatus.police = true;
					loadStatus.checkStatus("police");
				} 
			});
			policePOIQuery.executeQuery();
		});		
		policeQuery.executeQuery();
}


function getNearest(x,y){
	var url = getPOIsURL + '?x=' + x + '&y=' + y;
	var meth = "GET";
	
	var onSuccessFunc = function (req) { 
		var response = req.responseText;
		
		if (window.DOMParser){
		  parser=new DOMParser();
		  var doc=parser.parseFromString(response,"text/xml");
		}
		else{ // Internet Explorer
		  var doc=new ActiveXObject("Microsoft.XMLDOM");
		  doc.async="false";
		  doc.loadXML(response); 
		} 
	
		var z=doc.getElementsByTagName('item');	
		
		for (i=0;i<z.length;i++) {
			//alert(z[i].childNodes[0].childNodes[0].nodeValue + ": " + z[i].childNodes[1].childNodes[0].nodeValue);
			
			if(z[i].childNodes[0].childNodes[0].nodeValue == "PAYMENT CENTER"){
				getNearestContent('pay');
				var paySymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/countyPayment.png', 25, 25);
				var payX = z[i].childNodes[6].childNodes[0].nodeValue;
				var payY = z[i].childNodes[7].childNodes[0].nodeValue;
				var payTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + payX + "," + payY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + payX + " and POINT_Y = " + payY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					payGraphic = new Graphic(results.features[0],genMap.map.graphics,true,paySymbol,payTemplate);
					populateZoomLink('pay', payX,payY);
				});
				graphicQuery.executeQuery();															
			}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "LIBRARY"){
				getNearestContent('library');
				var librarySymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/library.png', 25, 25);			
				var libraryX = z[i].childNodes[6].childNodes[0].nodeValue;
				var libraryY = z[i].childNodes[7].childNodes[0].nodeValue;
				var libraryTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + libraryX + "," + libraryY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + libraryX + " and POINT_Y = " + libraryY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					libraryGraphic = new Graphic(results.features[0],genMap.map.graphics,true,librarySymbol,libraryTemplate);
					populateZoomLink('library', libraryX,libraryY);
				});
				graphicQuery.executeQuery();				
			}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "SENIOR CENTER"){
				getNearestContent('senior');	
				var seniorSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/seniorsite.png', 25, 25);
				var seniorX = z[i].childNodes[6].childNodes[0].nodeValue;
				var seniorY = z[i].childNodes[7].childNodes[0].nodeValue;
				var seniorTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + seniorX + "," + seniorY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + seniorX + " and POINT_Y = " + seniorY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					seniorGraphic = new Graphic(results.features[0],genMap.map.graphics,true,seniorSymbol,seniorTemplate);
					populateZoomLink('senior', seniorX,seniorY);
				});
				graphicQuery.executeQuery();				
			}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "HOSPITAL"){
				getNearestContent('hospital');
				var hospitalSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/hospital.png', 25, 25);
				var hospitalX = z[i].childNodes[6].childNodes[0].nodeValue;
				var hospitalY = z[i].childNodes[7].childNodes[0].nodeValue;
				var hospitalTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + hospitalX + "," + hospitalY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + hospitalX + " and POINT_Y = " + hospitalY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					hospitalGraphic = new Graphic(results.features[0],genMap.map.graphics,true,hospitalSymbol,hospitalTemplate);
					populateZoomLink('hospital', hospitalX, hospitalY);
				});
				graphicQuery.executeQuery();	
			}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "FARMERS MARKET"){
				//alert(z[i].childNodes[0].childNodes[0].nodeValue + ": " + z[i].childNodes[1].childNodes[0].nodeValue+ ": " + z[i].childNodes[2].childNodes[0].nodeValue);
				getNearestContent('farm');
				var farmSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/farm.png', 25, 25);
				var farmX = z[i].childNodes[6].childNodes[0].nodeValue;
				var farmY = z[i].childNodes[7].childNodes[0].nodeValue;
				var farmTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + farmX + "," + farmY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + farmX + " and POINT_Y = " + farmY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					farmGraphic = new Graphic(results.features[0],genMap.map.graphics,true,farmSymbol,farmTemplate);
					populateZoomLink('farm', farmX, farmY);
				});
				graphicQuery.executeQuery();				
			}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "MARC STATION"){
				//alert(z[i].childNodes[0].childNodes[0].nodeValue + ": " + z[i].childNodes[1].childNodes[0].nodeValue+ ": " + z[i].childNodes[2].childNodes[0].nodeValue);
				getNearestContent('marc');
				var marcSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/marc.png', 25, 25);
				var marcX = z[i].childNodes[6].childNodes[0].nodeValue;
				var marcY = z[i].childNodes[7].childNodes[0].nodeValue;
				var marcTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + marcX + "," + marcY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + marcX + " and POINT_Y = " + marcY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					marcGraphic = new Graphic(results.features[0],genMap.map.graphics,true,marcSymbol,marcTemplate);
					populateZoomLink('marc', marcX, marcY);
				});
				graphicQuery.executeQuery();	
			}
			//else if(z[i].childNodes[0].childNodes[0].nodeValue == "MTA STATION"){
				//alert(z[i].childNodes[0].childNodes[0].nodeValue + ": " + z[i].childNodes[1].childNodes[0].nodeValue+ ": " + z[i].childNodes[2].childNodes[0].nodeValue);
				//getNearestContent('mta');
				//var mtaSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/mta.png', 25, 25);
				//var mtaX = z[i].childNodes[6].childNodes[0].nodeValue;
				//var mtaY = z[i].childNodes[7].childNodes[0].nodeValue;
				//var mtaTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + mtaX + "," + mtaY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				//graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				//graphicQuery.query.where =  "POINT_X = " + mtaX + " and POINT_Y = " + mtaY;
				//dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
				//	mtaGraphic = new Graphic(results.features[0],genMap.map.graphics,true,mtaSymbol,mtaemplate);
				//	populateZoomLink('mta', mtaX,mtaY);
				//});
				//graphicQuery.executeQuery();	
			//}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "MVA"){
				//alert(z[i].childNodes[0].childNodes[0].nodeValue + ": " + z[i].childNodes[1].childNodes[0].nodeValue+ ": " + z[i].childNodes[2].childNodes[0].nodeValue);
				getNearestContent('mva');
				var mvaSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/mva.png', 25, 25);
				var mvaX = z[i].childNodes[6].childNodes[0].nodeValue;
				var mvaY = z[i].childNodes[7].childNodes[0].nodeValue;
				var mvaTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + mvaX + "," + mvaY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + mvaX + " and POINT_Y = " + mvaY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					mvaGraphic = new Graphic(results.features[0],genMap.map.graphics,true,mvaSymbol,mvaTemplate);
					populateZoomLink('mva', mvaX, mvaY);
				});
				graphicQuery.executeQuery();
			}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "PARK / RIDE"){
				//alert(z[i].childNodes[0].childNodes[0].nodeValue + ": " + z[i].childNodes[1].childNodes[0].nodeValue+ ": " + z[i].childNodes[2].childNodes[0].nodeValue);
				getNearestContent('parkride');
				var parkrideSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/parkride.png', 25, 25);
				var parkrideX = z[i].childNodes[6].childNodes[0].nodeValue;
				var parkrideY = z[i].childNodes[7].childNodes[0].nodeValue;
				var parkrideTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + parkrideX + "," + parkrideY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + parkrideX + " and POINT_Y = " + parkrideY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					parkrideGraphic = new Graphic(results.features[0],genMap.map.graphics,true,parkrideSymbol,parkrideTemplate);
					populateZoomLink('parkride', parkrideX,parkrideY);
				});
				graphicQuery.executeQuery();				
			}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "POST OFFICE"){
				//alert(z[i].childNodes[0].childNodes[0].nodeValue + ": " + z[i].childNodes[1].childNodes[0].nodeValue+ ": " + z[i].childNodes[2].childNodes[0].nodeValue);
				getNearestContent('post');
				var postSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/post.png', 25, 25);
				var postX = z[i].childNodes[6].childNodes[0].nodeValue;
				var postY = z[i].childNodes[7].childNodes[0].nodeValue;
				var postTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + postX + "," + postY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + postX + " and POINT_Y = " + postY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					postGraphic = new Graphic(results.features[0],genMap.map.graphics,true,postSymbol,postTemplate);
					populateZoomLink('post', postX, postY);
				});
				graphicQuery.executeQuery();				
			}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "VEIP"){
				//alert(z[i].childNodes[0].childNodes[0].nodeValue + ": " + z[i].childNodes[1].childNodes[0].nodeValue+ ": " + z[i].childNodes[2].childNodes[0].nodeValue);
				getNearestContent('veip');
				var veipSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/veip.png', 25, 25);
				var veipX = z[i].childNodes[6].childNodes[0].nodeValue;
				var veipY = z[i].childNodes[7].childNodes[0].nodeValue;
				var veipTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + veipX + "," + veipY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + veipX + " and POINT_Y = " + veipY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					veipGraphic = new Graphic(results.features[0],genMap.map.graphics,true,veipSymbol,veipTemplate);
					populateZoomLink('veip', veipX, veipY);
				});
				graphicQuery.executeQuery();
			}
			else if(z[i].childNodes[0].childNodes[0].nodeValue == "WM CONVENIENCE CENTER"){
				//alert(z[i].childNodes[0].childNodes[0].nodeValue + ": " + z[i].childNodes[1].childNodes[0].nodeValue+ ": " + z[i].childNodes[2].childNodes[0].nodeValue);
				getNearestContent('wm');
				var wmSymbol = new esri.symbol.PictureMarkerSymbol('/MyAA/images/wm.png', 25, 25);
				var wmX = z[i].childNodes[6].childNodes[0].nodeValue;
				var wmY = z[i].childNodes[7].childNodes[0].nodeValue;
				var wmTemplate = new esri.InfoTemplate("<a  title='Zoom Here' href ='javascript:genMap.changeExtentByXY(" + wmX + "," + wmY + ",1000);genMap.map.infoWindow.hide();'><b>${feature_na}</b></a>" ,"<table style='font-size:8pt;'><tr><td width='25%'><b>Address:</b></td><td width='75%'>${ADDRESS}</td></tr><tr><td width='25%'><b>City:</b></td><td width='75%'>${CITY}</td></tr></td><tr><td width='25%'><b>Zip:</b></td><td width='75%'>${ZIP_CODE}</td></tr></table>");
				graphicQuery = new Query(poiQueryURL, ["feature_na","ADDRESS","CITY","ZIP_CODE"]);
				graphicQuery.query.where =  "POINT_X = " + wmX + " and POINT_Y = " + wmY;
				dojo.connect(graphicQuery.queryTask, "onComplete", function(results){		
					wmGraphic = new Graphic(results.features[0],genMap.map.graphics,true,wmSymbol,wmTemplate);
					populateZoomLink('wm', wmX, wmY);
				});
				graphicQuery.executeQuery();	
			}
		}
		loadStatus.nearest = true;
		loadStatus.checkStatus("nearest");

		function getNearestContent(name){
			document.getElementById(name + 'Name').innerHTML =  z[i].childNodes[1].childNodes[0].nodeValue;
			if(z[i].childNodes[2].childNodes[0].nodeValue == "none"){
				document.getElementById(name + 'Addr').innerHTML = "Not Available";
			}
			else{
				document.getElementById(name + 'Addr').innerHTML =  z[i].childNodes[2].childNodes[0].nodeValue + "<br>" + z[i].childNodes[3].childNodes[0].nodeValue + ", MD " + z[i].childNodes[4].childNodes[0].nodeValue;	
				document.getElementById(name + 'Directions').innerHTML = getDirectionsURL(z[i].childNodes[2].childNodes[0].nodeValue + " " + z[i].childNodes[3].childNodes[0].nodeValue + ", MD " + z[i].childNodes[4].childNodes[0].nodeValue); 
			}			
		}

	};
	
	var onErrorFunc = function (status) { 
		alert("AJAX error: " + status + ":" + url); 
	};
			
	var myAjax = new AJAXRequest(url, meth);
	myAjax.makeRequest(onSuccessFunc, onErrorFunc);
}

function getDirectionsURL(toAddress){
	fromAddress = selectedAddress.address + " " + selectedAddress.city + ", MD " + selectedAddress.zip;
	var url = "<img src='/MyAA/images/car.jpg' border='0'>&nbsp;&nbsp;<a target='_blank' href='http://maps.google.com/maps?f=d&source=s_d&saddr="+ fromAddress + "&daddr=" + toAddress + "'>Get Directions</a>";
	return url;
}

function populateZoomLink(name,x,y){
	var part1 = "javascript:genMap.changeExtentByXY(" + x + "," + y + ",1000);"; 
	var part2 = "showInfoWindowOnZoom(\"" + name + "Graphic\")";
	href = part1 + part2; 
	//"javascript:genMap.changeExtentByXY(" + x + "," + y + ",1000);setTimeout(" + "\"" + showInfo + "\"" + ",2000);\"
	document.getElementById(name + 'Zoom').innerHTML = "<img src='/MyAA/images/world.png'>&nbsp;&nbsp;<a style='font-size:8pt;font-weight:bold;vertical-align:middle;' href='" + href + "'>Zoom Here</a>&nbsp;&nbsp;";
}

function showInfoWindowOnZoom(name){
	setTimeout("showWindow(" + name + ")",1500);
}

function showWindow(name){
	graphicName = eval(name);
	var screenPoint = genMap.map.toScreen(graphicName.graphic.geometry);
	genMap.map.infoWindow.setTitle(graphicName.graphic.getTitle());
	genMap.map.infoWindow.setContent(graphicName.graphic.getContent());	
	genMap.map.infoWindow.show(screenPoint,genMap.map.getInfoWindowAnchor(screenPoint));		
}

function showCouncilDistricts(){
	if(document.getElementById('councilMapTxt').innerHTML == "Show Council Districts"){
		document.getElementById('councilMapTxt').innerHTML = "Hide Council Districts";
		if(!selectedAddress.annapolis && !selectedAddress.type == "streetCenterline"){
			for (var i=0, il=selectedAddress.parcelGraphics.length; i<il; i++) {
				selectedAddress.parcelGraphics[i].hide();
			}
			selectedAddress.genGraphic.graphic.setInfoTemplate(selectedAddress.showTemplate);
		}
		pdGraphic.hide();
		roadGraphic.hide();
		genMyaa.addVisibleLayer(councilLayerNum);
		councilGraphic.show();
		genMap.map.setLevel(2);
	}
	else {
		document.getElementById('councilMapTxt').innerHTML = "Show Council Districts";
		genMyaa.removeVisibleLayer(councilLayerNum);
		councilGraphic.hide();
	}
}

function showRoadDistricts(){
	if(document.getElementById('roadMapTxt').innerHTML == "Show Road Districts"){
		document.getElementById('roadMapTxt').innerHTML = "Hide Road Districts";
		if(!selectedAddress.annapolis && !selectedAddress.type == "streetCenterline"){
			for (var i=0, il=selectedAddress.parcelGraphics.length; i<il; i++) {
				selectedAddress.parcelGraphics[i].hide();
			}
			selectedAddress.genGraphic.graphic.setInfoTemplate(selectedAddress.showTemplate);
		}
		pdGraphic.hide();
		councilGraphic.hide();
		roadGraphic.show();
		genMyaa.addVisibleLayer(roadDistrictLayerNum);
		genMap.map.setLevel(2);
		
	}
	else {
		document.getElementById('roadMapTxt').innerHTML = "Show Road Districts";
		roadGraphic.hide();
		genMyaa.removeVisibleLayer(roadDistrictLayerNum);
	}
}

function showPoliceDistricts(){
	if(document.getElementById('policeMapTxt').innerHTML == "Show Police Districts"){
		document.getElementById('policeMapTxt').innerHTML = "Hide Police Districts";
		if(!selectedAddress.annapolis && !selectedAddress.type == "streetCenterline"){
			for (var i=0, il=selectedAddress.parcelGraphics.length; i<il; i++) {
				selectedAddress.parcelGraphics[i].hide();
			}
			selectedAddress.genGraphic.graphic.setInfoTemplate(selectedAddress.showTemplate);
		}
		councilGraphic.hide();
		roadGraphic.hide();
		pdGraphic.show();
		genMyaa.addVisibleLayer(policeDistrictLayerNum);
		genMap.map.setLevel(2);
		
	}
	else {
		document.getElementById('policeMapTxt').innerHTML = "Show Police Districts";
		pdGraphic.hide();
		genMyaa.removeVisibleLayer(policeDistrictLayerNum);
	}
}


