		function showAlert(URL) {
			
			alert('value is : ' + URL );
			}
			
		function getParameter( 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 showFeature2(feature,evt) {
            map.graphics.clear();
  			 
  			curFeature = feature;
            var fExtent = feature.geometry.getExtent();
  			var centerPt = fExtent.getCenter();
  			var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
  			feature.setSymbol(symbol);

            map.graphics.add(feature);
            centerPt = fExtent.getCenter();
            map.centerAt(centerPt);
        }  
	  	
		function centerMap(feature, ddValue){
		   
            var fExtent = feature.geometry.getExtent();
            var centerPt = new esri.geometry.Point;
            //toggleProgressBar();
			centerPt = fExtent.getCenter();
           // map.centerAt(centerPt);
			map.setExtent(fExtent);		
			 
        } 
	
		function FindMBL(searchText){
				       			
			//build query task
			
			//queryTask_MBL = new esri.tasks.QueryTask("http://74.93.16.209:5555/ArcGIS/rest/services/Southington/Southington_Base/MapServer/1");			 
            //zero out the query Geometry
  			
  			 
  			//build query filter
			query = new esri.tasks.Query();
			query.geometry = null;
			query.returnGeometry = true;
			query.outFields = ["VIS_ID"];
			//query_MBL.where = "MBL = '110-125'";
			//query.where = "VIS_ID = '" + searchText + "'";
			query.where = "VIS_ID = " + searchText ;
  			//alert (query.where)
  				//show the progress bar.
    			//dojo.byId("progresstext").innerHTML = "Locating Parcel...";
                // toggleProgressBar();
  			 
  			    //Execute the queryTask and call showResults on completion
  			queryTask.execute(query, function(fset) {
  			    if (fset.features.length === 1) {
				centerMap(fset.features[0],searchText);
  				showFeature2(fset.features[0], null);
  				download();
  			    } else if (fset.features.length !== 0) {
                showFeatureSet(fset,null);
  			    } else{
  				alert ("No features returned from server.")}
  			    });
				dijit.byId("search_results").hide();
        }
		
		function showMBLSearchResults(searchMBL) {
		    //the synchronous call to a GP service automatically sends all messages and results to a pre-defined function.
  			var reportURL = "./searchMBL.asp" + "?mbl="+ searchMBL;
  	 	    dojo.byId("resultFrame").src = reportURL;
            dijit.byId("search_results").show();
			//toggleProgressBar();
        }
		
		function showNameSearchResults(searchName) {
		    //the synchronous call to a GP service automatically sends all messages and results to a pre-defined function.
  			var reportURL = "./searchName.asp" + "?name="+ searchName;
  	 	    dojo.byId("resultFrame").src = reportURL;
            dijit.byId("search_results").show();
			//toggleProgressBar();
        }
		
		function showAddrSearchResults(searchAddr) {
		    //the synchronous call to a GP service automatically sends all messages and results to a pre-defined function.
  			var reportURL = "./searchAddr.asp" + "?addr="+searchAddr;
  	 	    dojo.byId("resultFrame").src = reportURL;
            dijit.byId("search_results").show();
			//toggleProgressBar();
        }
		
		function showWebDetail(PARID) {
		    //alert('value is : ' + PARID );
  			
			var reportURL = "http://www.southingtongis.com/detail.asp?parid="+ PARID;
  	 	    dojo.byId("resultFrame2").src = reportURL;
            dijit.byId("WebDetail").show();
			
        }
		
		function showVEDetail(LAT,LON) {
		    //alert('value is : ' + PARID );
  			
			var reportURL = "http://74.93.16.209/DOJO/vemap.asp?lat=+"+LAT+"+&lon="+LON;
						
  	 	    dojo.byId("VEFRAME").src = reportURL;
            dijit.byId("VE").show();
			
        }
		
		function showAbutterDetail(PARID,FULL_ADDR,X,Y,DIST) {
		    //alert('value is : ' + DIST );
  			
			var reportURL = "./abutter_dynamic.asp?parid="+ PARID + "&buffer="+DIST+"&loc=WHERE_YOU_CLICKED&x="+X+"&y="+Y+"&zoomx=1";
  	 	   //alert('value is : ' + reportURL );
			dojo.byId("AbutterResult").src = reportURL;
            dijit.byId("AbutterDetail").show();
		
		
		
        }
		
		function showPropertyCard(parid) {
		    //the synchronous call to a GP service automatically sends all messages and results to a pre-defined function.
  			var reportURL = "http://74.93.16.209/southington/property_card.asp?parid=" + parid;
  	 	    //dojo.byId("resultFrame").src = reportURL;
            //dijit.byId("search_results").show();
			//toggleProgressBar();
        }
	
		function setinfoclickon (){
				
				objectconnections[0] = dojo.connect(map, "onClick", executeQueryTask);
				}

		function setinfoclickoff (){
				dojo.disconnect(objectconnections[0]);
				}
	
		function executeQueryTask(evt) {
        
		map.infoWindow.hide();
		map.graphics.clear();
        featureSet = null;

 			 
  			//build query filter
			query = new esri.tasks.Query();
			query.geometry = null;
			query.returnGeometry = true;
			query.outFields = ["OWNER_NAME", "LOCATION", "ACRES", "ZONINGPZ", "MBLU_1", "MBLU_2", "VIS_ID", "LAT", "LON", "TTL_TAX", "TTL_VALUE", "DATE_REVAL", "STATUS_REVAL", "LAND_USE" ];
			//alert('initial value is : ' );
		
		//onClick event returns the evt point where the user clicked on the map.
        //This is contains the mapPoint (esri.geometry.point) and the screenPoint (pixel xy where the user clicked).
        //set query geometry = to evt.mapPoint Geometry
        query.geometry = evt.mapPoint;

        //Execute task and call showResults on completion
        queryTask.execute(query, function(fset) {
          if (fset.features.length === 1) {
            showFeature(fset.features[0],evt);
          } else if (fset.features.length !== 0) {
            showFeatureSet(fset,evt);
          }
        });
		
		
      }

		function showFeature(feature,evt) {
        map.graphics.clear();
		
        //set symbol 'javascript:showWebDetail(" + attr.parid +")'
        var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.5]));
        feature.setSymbol(symbol);
		
        //construct infowindow title and content
        var attr = feature.attributes;
		var LAT = attr.LAT;
		var LON = attr.LON;
		var TITLE = attr.LOCATION;
        var LOCATION = attr.LOCATION;
		
		var MBLU_1 = attr.MBLU_1;
		var MBLU_1 = attr.MBLU_1;
		//var MAP = attr.MAP
		//var LOT = attr.LOT
		//alert('initial value is : ' + LOCATION);
        var content = "<b>Owner: " + attr.OWNER_NAME +"</b>"
					+ "<br /><br />2008 Appraisal Value: " + attr.TTL_VALUE
					+ "<br />2008 Assessed Value: " + attr.TTL_TAX
					+ "<br /><br />Reval Status: " + attr.STATUS_REVAL
					+ "<br />Reval Visit Date: " + attr.DATE_REVAL
					+ "<br /> <br />" + "<a href=javascript:showWebDetail('" + MBLU_1 + "')>Parcel Details</a>" 
					+ "&nbsp;&nbsp;&nbsp;" + "<a href=http://www.branford-ct.gov/parcelmapgis/" + attr.MBLU_2 + ".pdf TARGET='_blank' >Quick Map</a>"
					+ "&nbsp;&nbsp;&nbsp;" + "<a href=http://www.branford-ct.gov/ParcelPDF/" + attr.VIS_ID + ".PDF TARGET='_blank' >2007 Prop Card </a>"
					+ "<br /><br /><a href=javascript:showVEDetail('" + LAT + "','"+ LON +"')>Birds Eye Photo</a>"

					
							
        map.graphics.add(feature);
		
		map.infoWindow.resize(295,200);
		
        map.infoWindow.setTitle(TITLE);
		
        map.infoWindow.setContent(content);
		

        (evt) ? map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint)) : null;
		
      }

		function showFeatureSet(fset,evt) {
        //remove all graphics on the maps graphics layer
        map.graphics.clear();
        var screenPoint = evt.screenPoint;

        featureSet = fset;

        var numFeatures = featureSet.features.length;

        //QueryTask returns a featureSet.  Loop through features in the featureSet and add them to the infowindow.
        var title = "You have selected " + numFeatures + " fields.";
        var content = "Please select desired field from the list below.<br />";

        for (var i=0; i<numFeatures; i++) {
          var graphic = featureSet.features[i];
          content = content + graphic.attributes.FIELD_NAME + " Field (<A href='javascript:showFeature(featureSet.features[" + i + "]);'>show</A>)<br/>";
        }
        map.infoWindow.setTitle(title);
        map.infoWindow.setContent(content);
        map.infoWindow.show(screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
      }
	  
		function Print_I(MI) {
		
		var URL, scale, layers, mwidth, mheight, mwidth2, mheight2, percentw, percenth, centerx, centery, extentXmax, extentXmin, extentYmax, extentYmin
		
		//print map size: 720x750
		 URL = MI.href
		 scale = MI.scale
		 layers = map.layerIds
		
		
		mwidth = map.extent.xmax - map.extent.xmin
		mheight = map.extent.ymax - map.extent.ymin
		
		mwidth2 = map.width
		mheight2 = map.height
		
		percentw = 720/mwidth2
		percenth = 750/mheight2
		
		centerx = map.extent.xmax - (mwidth/2)
		centery = map.extent.ymax - (mheight/2)
		
		extentXmax = centerx + ((mwidth*percentw)/2)
		extentXmin = centerx - ((mwidth*percentw)/2)
		extentYmax = centery + ((mheight*percenth)/2)
		extentYmin = centery - ((mheight*percenth)/2)
		
		//alert (extentXmin);
		//alert (extentXmax);
		//alert (extentYmin);
		//alert (extentYmax);
		
		//alert('value is : ' + mwidth );
		//alert('value is : ' + scale );
		//alert('value is : ' + map.width );
		//alert('value is : ' + map.height );
		//alert('value is : ' + map.extent.xmax );
		//alert('value is : ' + map.extent.xmin );
		//alert('value is : ' + map.extent.ymin );
		//alert('value is : ' + map.extent.ymax );
		
		
		var PrintURL = "./printmap.asp?extentYmin="+ extentYmin +"&extentXmin=" + extentXmin +"&extentXmax="+ extentXmax +"&extentYmax=" + extentYmax;
		//alert('value is : ' + PrintURL ); 	
			
			dojo.byId("printframe").src = PrintURL;
            dijit.byId("printdialog").show();		
		}
		
		function Export_I(MI) {
		
		sbip = new esri.layers.ImageParameters()
		
		//sbip.bbox = startExtent;
		//sbip.height = 300;
		//sbip.width= 300;
		
		sbip.bbox = map.extent
		sbip.height = map.height
		sbip.width = map.width
		//sbip.layerIds = [7]
		//sbip.layerOption = 'LAYER_OPTION_SHOW'
		
		SouthbaseLayer.exportMapImage(sbip);
		
		}
	  
	    function showCoordinates(evt) {
        //get mapPoint from event
        var mp = evt.mapPoint;
        //display mouse coordinates
        dojo.byId("info").innerHTML = mp.x + ", " + mp.y;
      }
	  
		function updateLayerVisibility() {
        var inputs = dojo.query(".list_item"), input;
        //these are the layers which will always be on unless controlled by scale factors
        visible = [];
        for (var i=0, il=inputs.length; i<il; i++) {
          if (inputs[i].checked) {
            visible.push(inputs[i].id);
          }
        }
        //mydynamicMapServiceLayer.setVisibleLayers(visible);
		SouthbaseLayer.setVisibleLayers(visible);
      }
	  	  		
        function changeMap(layerid) {
		//Switch between the basemap layers, or toggle the parcel layer
		
  		    var curLayer = map.getLayer(layerid);
  			toggleLayer(curLayer);
			//alert('initial value is : ' + curLayer );
        }

		function toggleLayer(layer) {
		//if the layer is visible, turn it off and update the control panel. If invisible, do the same.
         		 
  			switch (layer.id)
  			{
  			    case "photo":
  				if(dojo.byId("rdphoto").Checked){
                    //do nothing
                }
  			else{
                if (layer.visible){
                    layer.hide();
  				    map.getLayer("basemap").show();
  				    dojo.byId("rdbase").Checked = true;
  				    dojo.byId("rdphoto").Checked = false;
                }
   			    else{
                    layer.show();
   				    map.getLayer("basemap").hide();
					map.getLayer("anno").hide();
					
					
   				    dojo.byId("rdbase").Checked = false;
   				    dojo.byId("rdphoto").Checked = true;
                }
            }
             
                break;
  			    case "basemap":
  				if(dojo.byId("rdbase").Checked){
                    //do nothing
  				}
  				else{
                    if (layer.visible){
						layer.hide();
                        map.getLayer("photo").show();
    				    dojo.byId("rdphoto").Checked = true;
                        dojo.byId("rdbase").Checked = false;
    				    
                    }
    				else{
                    layer.show();
					map.getLayer("anno").show();
   				    map.getLayer("photo").hide();
   				    dojo.byId("rdphoto").Checked = false;
   				    dojo.byId("rdbase").Checked = true;
    				    
                    }
                }
                break;
  			    
  			}
        }
		
		function toggleProgressBar() {
		    var progressbar_container = dojo.byId("progressbar_container");
			//var control_panel = dojo.byId("control_panel");
				
			if (progressbar_container.style.display=="block") {
			    progressbar_container.style.display="none";
            }
            else {
                progressbar_container.style.display="block";
            }
        }
		
        function download(){
            // Split up bar into 5% segments
			       
            numParts = Math.floor(100/2);
            jsProgress.update({ maximum: numParts, progress:0 });
            for (var i=0; i<=numParts; i++){
                // This plays update({progress:0}) at 1nn milliseconds,
                // update({progress:1}) at 2nn milliseconds, etc.
                setTimeout("jsProgress.update({ progress: " + i + " })",(i+1)*100 + Math.floor(Math.random()*100));
            }	
			numParts = Math.floor(100/2);
			jsProgress.update({ maximum: numParts, progress:0 });

			
        }
	
	    function initMeasure(map,tb) {
        
		dojo.disconnect(objectconnections[0]);
		dojo.disconnect(objectconnections[1]);
		
        //on draw end add graphic, project it, and get new length
        objectconnections[1] = dojo.connect(tb, "onDrawEnd", function(geometry) {
          map.graphics.clear();
          var graphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleLineSymbol()));
          //add graphic to the map and then call GeometryService.project() to get graphic into a coordinate system that
          //can be used to generate an accurate length.
          geometryService.project([graphic],new esri.SpatialReference({"wkid":2234}));
        });
        tb.activate(esri.toolbars.Draw.POLYLINE);
      }
	  
		function initArea(map,tb) {
        
		dojo.disconnect(objectconnections[0]);
		dojo.disconnect(objectconnections[1]);
		
        //on draw end add graphic, project it, and get new length
        objectconnections[1] = dojo.connect(tb, "onDrawEnd", function(geometry) {
          map.graphics.clear();
          var graphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleFillSymbol()));
		  geometryService.simplify([graphic], function(graphics) {
          geometryService.areasAndLengths(graphics);
			});
        });
        tb.activate(esri.toolbars.Draw.FREEHAND_POLYGON);
      }

		function outputDistance(result) {
        dojo.byId("distance").innerHTML = dojo.number.format(result.lengths[0] ) + " Feet";
      }
	  
	    function outputAreaAndLength(result) {
        //console.log(dojo.toJson(result));
        dojo.byId("distance").innerHTML = result.areas[0]/43560 + " Acres";
        //dojo.byId("length").innerHTML = result.lengths[0] + " feet";
      }
		
		function endFunctionality(map,tb) {
		
		map.graphics.clear();
		dojo.disconnect(objectconnections[1]);
		tb.deactivate();
		objectconnections[0] = dojo.connect(map, "onClick", executeQueryTask);
		}

		