    //<![CDATA[

//BEGIN DECLARE VARIABLES
//START ATTRIBUTE VARIABLES
    var side_bar_htmlGrS = "";
      var gmarkersGrS = [];
      var htmlsGrS = [];
      var iiGrS = 0;
    var side_bar_htmlGWY = "";
      var gmarkersGWY = [];
      var htmlsGWY = [];
      var iiGWY = 0;
//END ATTRIBUTE VARIABLES
    var iconGreen = new GIcon();
    iconGreen.image = 'http://labs.google.com/ridefinder/images/mm_20_green.png';
    iconGreen.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconGreen.iconSize = new GSize(12, 20);
    iconGreen.shadowSize = new GSize(22, 20);
    iconGreen.iconAnchor = new GPoint(6, 20);
    iconGreen.infoWindowAnchor = new GPoint(5, 1);

    var iconBridge = new GIcon(); 
    iconBridge.image = '/IMAGES/ICONS/iconBridge.gif';
    iconBridge.iconSize = new GSize(16, 25);
    iconBridge.iconAnchor = new GPoint(8, 12);
    iconBridge.infoWindowAnchor = new GPoint(5, 1);

    var iconMap = new GIcon(); 
    iconMap.image = '/IMAGES/ICONS/icon_map.gif';
    iconMap.iconSize = new GSize(30, 28);
    iconMap.iconAnchor = new GPoint(15, 14);
    iconMap.infoWindowAnchor = new GPoint(5, 1);

    var iconPlan = new GIcon(); 
    iconPlan.image = '/IMAGES/ICONS/icon_plan.gif';
    iconPlan.iconSize = new GSize(41, 33);
    iconPlan.iconAnchor = new GPoint(20, 16);
    iconPlan.infoWindowAnchor = new GPoint(5, 1);

    var iconNeeded = new GIcon(); 
    iconNeeded.image = '/IMAGES/ICONS/iconNeeded.gif';
    iconNeeded.iconSize = new GSize(16, 25);
    iconNeeded.iconAnchor = new GPoint(8, 12);
    iconNeeded.infoWindowAnchor = new GPoint(5, 1);

    var iconBlue = new GIcon(); 
    iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconBlue.iconSize = new GSize(12, 20);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);

    var iconRed = new GIcon();
iconRed.image = '/IMAGES/ICONS/iconFatality.gif';

    //iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
    iconRed.shadow = 'images/iconReddot.gif';
//http://labs.google.com/ridefinder/images/mm_20_shadow.png
    iconRed.iconSize = new GSize(21, 20);
 //   iconRed.shadowSize = new GSize(26, 26);
    iconRed.iconAnchor = new GPoint(0, 7);
    iconRed.infoWindowAnchor = new GPoint(5, 1);


    var iconInjured = new GIcon();
    iconInjured.image = 'http://www.fishsniffer.com/forumsyabb2006/Smilies/seestars.gif';
    iconInjured.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconInjured.iconSize = new GSize(35, 29);
    iconInjured.shadowSize = new GSize(22, 20);
    iconInjured.iconAnchor = new GPoint(0, 15);
    iconInjured.infoWindowAnchor = new GPoint(5, 1);

    var iconYellow = new GIcon(); 
    iconYellow .image = 'http://labs.google.com/ridefinder/images/mm_20_yellow.png';
    iconYellow .shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconYellow .iconSize = new GSize(12, 20);
    iconYellow .shadowSize = new GSize(22, 20);
    iconYellow .iconAnchor = new GPoint(6, 20);
    iconYellow .infoWindowAnchor = new GPoint(5, 1);

    var customIcons = [];
    customIcons["Existing"] = iconBridge;
    customIcons["Needed"] = iconNeeded;
    customIcons["BicyclistFatal"] = iconRed;
    customIcons["BicyclistInjury"] = iconInjured;
    customIcons["PedestrianFatal"] = iconRed;
    customIcons["PedestrianInjury"] = iconInjured;
    customIcons["1"] = iconMap;
    customIcons["2"] = iconPlan;
//END DECLARE VARIABLES


//======= FOLLOWING 2 FUNCTIONS WERE BORROWED FROM http://www.osu.edu/map/google.php ====
function itemChanged(e) {
	e = e || event;
	var obj = e.target || e.srcElement;
	var theValue = obj.value;
	var switcher = e.type + '/' + obj.tagName +(obj.tagName == 'INPUT' ? '/' + obj.type : '');

	switch (switcher) {
		case 'click/INPUT/checkbox':
			if(obj.checked==true){
				if(theValue=="GWExisting"){
					//alert('Greenway mapping coming soon!');
					//addMarkersBus(busMarkerL);
refreshMAP("Yes")
				}else if(theValue=="GWPotential"){
					//alert('(Potential) Greenways coming soon!');
					//addMarkersBusCota(busMarkerL);
refreshMAP("Yes")
				}else if(theValue=="Trails"){
					//alert('Trails mapping coming soon!');
				}else if(theValue=="Bike Lanes"){
					//alert('Bike Lane mapping coming soon!');
				}else if(theValue=="Side Paths"){
					//alert('Side Path mapping coming soon!');
				}else if(theValue=="BikeFat"){
					//alert('BikeFat mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="BikeInj"){
					//alert('BikeInj mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="PedFat"){
					//alert('PedFat mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="PedInj"){
					//alert('PedInj mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="GradeSepEx"){
					//alert('GradeSepEx mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="GradeSepNd"){
					//alert('GradeSepNd mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="Counties"){
					//alert('Counties mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="Communities"){
					//alert('Communities mapping coming soon!');
refreshMAP("Yes")
				}else{
					//alert('This will eventually be the only one processes.\nIt will refresh the map!');
				}
			}else{
				if(theValue=="GWExisting"){
					//removeMarkersBus();
refreshMAP("Yes")
				}else if(theValue=="GWPotential"){
					//removeMarkersBusCota();
refreshMAP("Yes")
				}else if(theValue=="BikeFat"){
					//alert('BikeFat mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="BikeInj"){
					//alert('BikeInj mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="PedFat"){
					//alert('PedFat mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="PedInj"){
					//alert('PedInj mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="GradeSepEx"){
					//alert('GradeSepEx mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="GradeSepNd"){
					//alert('GradeSepNd mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="Counties"){
					//alert('Counties mapping coming soon!');
refreshMAP("Yes")
				}else if(theValue=="Communities"){
					//alert('Communities mapping coming soon!');
refreshMAP("Yes")
				}else{
					//alert('Layer is now off!');
				}
			}
			break;			
	}
	return true;
}

function checkboxListen() {
	if (! document.getElementById)
		return;
	var f = document.getElementById ('firstform');
	f.onclick = itemChanged;
	
}

	//onload function for browser compatibility 	
function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function'){ 
		window.onload = func
	} else { 
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
addLoadEvent(checkboxListen);

    function createMarker(layer, point, name, address, type, corridorlink, planlink) {
      var marker = new GMarker(point, {icon:customIcons[type],title:name+" with an "+address});
//ADD FOR INFO WINDOW:  
     var html = "<b>" + name + "</b><br/>" + address + "<br />" + corridorlink + "<br />" + planlink;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
     });
//END INFO WINDOW

//START ATTRIBUTES
if (layer == "gradeSep")
{
        gmarkersGrS[iiGrS] = marker;
        htmlsGrS[iiGrS] = html;
        side_bar_htmlGrS += '<a href="javascript:gradeSep(' + iiGrS + ')">' + name + '</a><br>';
        iiGrS++;
}
else
{
        gmarkersGWY[iiGWY] = marker;
        htmlsGWY[iiGWY] = html;
        side_bar_htmlGWY += '<a href="javascript:greenway(' + iiGWY + ')">' + name + '</a><br>';
        iiGWY++;
}
//END ATTRIBUTES
      return marker;
    }

      // This function picks up the click and opens the corresponding info window
      function gradeSep(iGrS) {
        gmarkersGrS[iGrS].openInfoWindowHtml(htmlsGrS[iGrS]);
      }
      function greenway(iGWY) {
        gmarkersGWY[iGWY].openInfoWindowHtml(htmlsGWY[iGWY]);
      }

//END DECLARE FUNCTIONS

//================ PREPARE USGS TOPO MAPS ==================//
	CustomGetTileUrl=function(a,b,c) {
		var lULP = new GPoint(a.x*256,(a.y+1)*256);
		var lLRP = new GPoint((a.x+1)*256,a.y*256);
		var lUL = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lULP,b,c);
		var lLR = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lLRP,b,c);
		var lBbox=lUL.x+","+lUL.y+","+lLR.x+","+lLR.y;
		var lSRS="EPSG:4326";
		var lURL=this.myBaseURL;
		lURL+="&REQUEST=GetMap";
		lURL+="&SERVICE=WMS";
		lURL+="&reaspect=false&VERSION=1.1.1";
		lURL+="&LAYERS="+this.myLayers;
		lURL+="&STYLES=default"; 
		lURL+="&FORMAT="+this.myFormat;
		lURL+="&BGCOLOR=0xFFFFFF";
		lURL+="&TRANSPARENT=TRUE";
		lURL+="&SRS="+lSRS;
		lURL+="&BBOX="+lBbox;
		lURL+="&WIDTH=256";
		lURL+="&HEIGHT=256";
		lURL+="&GroupName="+this.myLayers;
		return lURL;
	}
	var tileDRG= new GTileLayer(new GCopyrightCollection(""),1,17);
	tileDRG.myLayers='DRG';
	tileDRG.myFormat='image/jpeg';
	tileDRG.myBaseURL='http://www.terraserver-usa.com/ogcmap6.ashx?';
	tileDRG.getTileUrl=CustomGetTileUrl;
	var topoLayer=[tileDRG];
	var topoMap = new GMapType(topoLayer, G_SATELLITE_MAP.getProjection(), "Topo", G_SATELLITE_MAP);


//================== COOKIE PREPARE =====================//

      // === Default values to use if there is no cookie ===
      var lat = 42;
      var lng = -88;
      var zoom = 13;

      // === Some cookie parameters ===
      var cookiename = "mapinfo";  // name for this cookie
      var expiredays = 100;          // number of days before cookie expiry


      // === Look for the cookie ===
      if (document.cookie.length>0) {
        cookieStart = document.cookie.indexOf(cookiename + "=");
        if (cookieStart!=-1) {
          cookieStart += cookiename.length+1; 
          cookieEnd=document.cookie.indexOf(";",cookieStart);
          if (cookieEnd==-1) {
            cookieEnd=document.cookie.length;
          }
          cookietext = document.cookie.substring(cookieStart,cookieEnd);
          // == split the cookie text and create the variables ==
          bits = cookietext.split("|");
          lat = parseFloat(bits[0]);
          lng = parseFloat(bits[1]);
          zoom = parseInt(bits[2]);
        } 
      }


//================== END COOKIE PREPARE =================//
      var map = new GMap2(document.getElementById("map"));

      // ====== Restricting the range of Zoom Levels =====
      // Get the list of map types      
      var mt = map.getMapTypes();
      // Overwrite the getMinimumResolution() and getMaximumResolution() methods
      for (var i=0; i<mt.length; i++) {
        mt[i].getMinimumResolution = function() {return 7;}
        mt[i].getMaximumResolution = function() {return 17;}
      }

      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());

//========== ADD USGS TOPO MAPS ==============//
map.addMapType(topoMap);

      map.setCenter(new GLatLng(lat,lng),zoom);



//==================== COOKIE - SET ======================//
      // === Set the cookie before exiting ===
      function setCookie() {

        var cookietext = cookiename+"="+map.getCenter().lat()+"|"+map.getCenter().lng()+"|"+map.getZoom()+"|";
        if (expiredays) {
          var exdate=new Date();
          exdate.setDate(exdate.getDate()+expiredays);
          cookietext += ";expires="+exdate.toGMTString();
        }
        // == write the cookie ==
        document.cookie=cookietext;
        // == Call GUnload() on exit ==
        GUnload();
      }
//===================== COOKIE STOP SET =====================//


//========== Check or uncheck to toggle scroll wheel zoom =================//
map.enableScrollWheelZoom();
map.enableContinuousZoom();
///prevent page scroll

function wheelevent(e)
{
 if (!e){
 e = window.event
 }
 if (e.preventDefault){
 e.preventDefault()
 }
 e.returnValue = false;
}
GEvent.addDomListener(map.getContainer(), "DOMMouseScroll", wheelevent);
map.getContainer().onmousewheel = wheelevent; 



	// Listen for right clicks
	GEvent.addListener(map,"singlerightclick",
		function(point, src, overlay)
		{
		var message = "Coordinates:  ";
		message += map.fromDivPixelToLatLng(point).toUrlValue();
message += "\n (the name of the closest greenway to your click will soon be shown here.)";
		alert(message);
		});


      // Add a move & zoom listeners to refresh map.
      GEvent.addListener(map, "dragend", function() {

				        refreshMAP("Yes");

      });

      GEvent.addListener(map, "zoomend", function() {

				        refreshMAP("Yes");

      });


function refreshMAP(mapHasMoved){
	document.getElementById('status').innerHTML = '<img src="http://www.osu.edu/map/images/google/workingSpin.gif" alt="Working" align="left"/>';

//=====BEGIN RETREIVE DATA FOR VIEW
            // hide the info window, otherwise it still stays open
            map.getInfoWindow().hide();
            map.clearOverlays();

      // ===== Start with an empty GLatLngBounds object =====
      var bounds = new GLatLngBounds();


//BEGIN LIST SELECTED GREENWAYS IN SQL WHERE
  var selectedArrayGWY = new Array();
  var selObjGWY = document.getElementById('subgwy');
  var h;
  var javaarrayGWY;
  var countGWY = 0;
  for (h=0; h<selObjGWY.options.length; h++) {
    if (selObjGWY.options[h].selected) {
var g = selObjGWY.options[h].value;
var tempGWY = new Array();
tempGWY = g.split('|');
var pointNEGWY = new GLatLng(tempGWY[2],tempGWY[1]);
            // ==== Each time a point is found, extent the bounds ato include it =====
bounds.extend(pointNEGWY);
var pointSWGWY = new GLatLng(tempGWY[4],tempGWY[3]);
            // ==== Each time a point is found, extent the bounds ato include it =====
bounds.extend(pointSWGWY);
var setBoundsFlag = "Yes";
      selectedArrayGWY[countGWY] = tempGWY[0];
if (typeof(javaarrayGWY)=="undefined"){
javaarrayGWY='Corridor="' + selectedArrayGWY[countGWY]+ '"';}
else {javaarrayGWY=javaarrayGWY +' OR Corridor="' + selectedArrayGWY[countGWY] + '"';}
//END JAVAARRAYGWY IF
      countGWY++;
    }//END IF OPTIONS[h] SELECTED
  }//END FOR EACH OPTION IN SELECT
//END LIST SELECTED GREENWAYS IN SQL WHERE

		var thisDiv = document.getElementById("selectcom");
		if (thisDiv) {
			if (thisDiv.style.display != 'none') {
				        

//BEGIN LIST SELECTED COMMUNITIES IN SQL WHERE
  var selectedArray = new Array();
  var selObj = document.getElementById('submap');
  var i;
  var javaarrayCOM;
  var count = 0;
  for (i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].selected) {
var b = selObj.options[i].value;
var temp = new Array();
temp = b.split('|');
var pointNE = new GLatLng(temp[2],temp[1]);
            // ==== Each time a point is found, extent the bounds ato include it =====
bounds.extend(pointNE);
var pointLowerLeft = new GLatLng(temp[4],temp[3]);
            // ==== Each time a point is found, extent the bounds ato include it =====
bounds.extend(pointLowerLeft);
var setBoundsFlag = "Yes";
      selectedArray[count] = temp[0];
if (typeof(javaarrayCOM)=="undefined"){
javaarrayCOM="Community = '" + selectedArray[count]+ "'";}
else {javaarrayCOM=javaarrayCOM +" OR Community = '" + selectedArray[count] + "'";}
      count++;
    }//END IF OPTIONS[i] SELECTED
  }//END FOR EACH OPTION IN SELECT
//END LIST SELECTED COMMUNITIES IN SQL WHERE

			}//END IF COMMUNITY SELECT != NONE
		}//END IF COMMUNITY SELECT EXISTS

var curZoom = map.getZoom()



if (setBoundsFlag == "Yes" && mapHasMoved != "Yes")
{
          //===== determine the zoom level from the bounds =====
          map.setZoom(map.getBoundsZoomLevel(bounds));

          //===== determine the centre from the bounds ======
          map.setCenter(bounds.getCenter());
        var EastLng = -50;
        var NortLat = 50;
        var WestLng = -90;
        var SoutLat = 20;
}
else
{
var curBounds = map.getBounds();

        var EastLng = curBounds.getNorthEast().lng();
        var NortLat = curBounds.getNorthEast().lat();
        var WestLng = curBounds.getSouthWest().lng();
        var SoutLat = curBounds.getSouthWest().lat();
}

setBoundsFlag = "No";//CLEAR FLAG FOR NEXT TIME
	var f = document.getElementById ('firstform');
	//f.onclick = itemChanged;
      //alert("Existing Greenways is " + f.GWExisting.checked);
	

if (curZoom >= 13)
{
document.firstform.BikeInj.disabled=false;
document.firstform.PedInj.disabled=false;
document.firstform.GradeSepNd.disabled=false;
document.firstform.Communities.disabled=false;
}
else
{
//alert ("Current Zoom = " + curZoom)
document.firstform.BikeInj.disabled=true;
document.firstform.PedInj.disabled=true;
document.firstform.GradeSepNd.disabled=true;
document.firstform.Communities.disabled=true;
}

if(f.GWExisting.checked || f.GWPotential.checked)
{
refreshSegments(EastLng,NortLat,WestLng,SoutLat,f.GWExisting.checked,f.GWPotential.checked,escape(javaarrayCOM),escape(javaarrayGWY),map);
}

if(f.GradeSepEx.checked || f.GradeSepNd.checked)
{
refreshGradeSep(EastLng,NortLat,WestLng,SoutLat,f.GradeSepEx.checked,f.GradeSepNd.checked,escape(javaarrayCOM),escape(javaarrayGWY),curZoom);
}

if(f.BikeFat.checked || f.BikeInj.checked || f.PedFat.checked || f.PedInj.checked)
{
refreshCrashes(EastLng,NortLat,WestLng,SoutLat,f.BikeFat.checked,f.BikeInj.checked,f.PedFat.checked,f.PedInj.checked,escape(javaarrayCOM),curZoom);
}

javaarrayCOMtoreplace = ""+ javaarrayCOM + "";
var JWHERECOM = javaarrayCOMtoreplace.replace(/Community/gi, "GIS_Community.Community");
javaarrayGWYtoreplace = ""+ javaarrayGWY + "";
var JWHEREGWY = javaarrayGWYtoreplace.replace(/Corridor/gi, "GIS_Segment.Corridor");


if(f.Communities.checked)
{
refreshCommunities(EastLng,NortLat,WestLng,SoutLat,escape(JWHERECOM),escape(JWHEREGWY),curZoom);
}




if(f.Counties.checked || f.Counties.checked)
{
refreshCounties(EastLng,NortLat,WestLng,SoutLat,escape(JWHERECOM),escape(JWHEREGWY));
}

if ( typeof( javaarrayCOM ) != "undefined" || typeof( javaarrayGWY ) != "undefined" ){
//alert("COMMUNITY:" + JWHERECOM + "GREENWAY:" + JWHEREGWY);
showATTRIBUTES(JWHERECOM,JWHEREGWY);
}

}//END REFRESH FUNCTION

function refreshDefQryMap()
{

}//END REFRESH MAP & ATTRIBUTES


refreshMAP();//INITIAL MAP ZOOM



    //]]>
