      var wd = 350;
      var ht = 120;


function doQuery(evt) {
        click = query.geometry = evt.mapPoint;
        queryTask.execute(query);
//alert(layer.defaultVisibility);

      }

      function getChart(featureSet) {
//alert(featureSet.features.length);
        map.graphics.clear();


        var features = featureSet.features;
        var attributes, under5, age_5_17, age_18_21, age_22_29, age_30_39, age_40_49, age_50_64, age_64_up, total, fips;
        for (var i=0; i<features.length; i++) {
          feature = features[i];

          attributes = feature.attributes;
          under5 = parseInt(attributes.AGE_UNDER5);
          age_5_17 = parseInt(attributes.AGE_5_17);
          age_18_21 = parseInt(attributes.AGE_18_21);
          age_22_29 = parseInt(attributes.AGE_22_29);
          age_30_39 = parseInt(attributes.AGE_30_39);
		  age_40_49 = parseInt(attributes.AGE_40_49);
		  age_50_64 = parseInt(attributes.AGE_50_64);
		  age_64_up = parseInt(attributes.AGE_65_UP);
		  fips = parseInt(attributes.FIPS);
		  var title = attributes.TRACT;

          total = under5 + age_5_17 + age_18_21 + age_22_29 + age_30_39 + age_40_49 + age_50_64 + age_64_up;
// dojo.byId("info").innerHTML = total;
          under5 = (under5 / total) * 100;
          age_5_17 = (age_5_17 / total) * 100;
          age_18_21 = (age_18_21 / total) * 100;
          age_22_29 = (age_22_29 / total) * 100;
          age_30_39 = (age_30_39 / total) * 100;
		  age_40_49 = (age_40_49 / total) * 100;
		  age_50_64 = (age_50_64 / total) * 100;
		  age_64_up = (age_64_up / total) * 100;
		  
		  var u5 = under5.toFixed(2);
		  var a5to17 = age_5_17.toFixed(2);
		  var a18to21 = age_18_21.toFixed(2);
		  var a22to29 = age_22_29.toFixed(2);
		  var a30to39 = age_30_39.toFixed(2);
		  var a40to49 = age_40_49.toFixed(2);
		  var a50to64 = age_50_64.toFixed(2);
		  var a64up = age_64_up.toFixed(2);
		  
//alert(white.toFixed(2));
		  
 var chartParams = { chco:"bd4d70,dcabde,fdc689,dedede,003366,f89838,6599cd,80b44d", cht:"p", chl:"Under 5(" + u5 + "%)|Age 5 to 17(" + a5to17 + "%)|Age 18 to 21(" + a18to21 + "%)|Age 22 to 29(" + a22to29 + "%)|Age 30 to 39(" + a30to39 + "%)|Age 40 to 49(" + a40to49 + "%)|Age 50 to 64(" + a50to64 + "%)|Age 64 up(" + a64up + "%)" };
          var params = dojo.mixin({
              chf:"bg,s,FFFFFF50",
              chs:wd + "x" + ht,
              chd: "t:" + under5 + "," + age_5_17 + "," + age_18_21 + "," + age_22_29 + "," + age_30_39 + "," + age_40_49 + "," + age_50_64 + "," + age_64_up
            }, chartParams);

          
		  var mySymbol = new esri.symbol.SimpleFillSymbol("none", new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255,0,0]), 3.5), new dojo.Color([255,255,0,0.25]));

          
		  
		  feature.setSymbol(mySymbol);

          //map.infoWindow.setTitle("Ethnic background of Census Tract: " + title);  
		  map.infoWindow.setTitle("Breakdown by age group in census tract");  
          map.infoWindow.setContent("<img src=\"" + "http://chart.apis.google.com/chart?"
                                     + decodeURIComponent(dojo.objectToQuery(params)) + "\" />");

         // censusLayer = new esri.layers.GraphicsLayer();
		 // map.addLayer(censusLayer);
		  //censusLayer.add(feature);
		 map.graphics.add(feature);
         map.infoWindow.show(map.toScreen(click),map.getInfoWindowAnchor(map.toScreen(click)));
		 
		
			
//alert(featureSet.features.length);
//alert(fips);
		 //schoolQuery.geometry = feature.geometry;
		 //schoolQuery.spatialRelationship = esri.tasks.Query.SPATIAL_REL_OVERLAPS;
		 
		 schoolQuery.where = "FIPS = '" + fips + "'";
         schoolQueryTask.execute(schoolQuery);
		 	
        }
      }
	  

