﻿var showAddressBuffer = false;
var showPanel = true;

var gmap;
var geocoder = null;
var centerx = -76.2569; //-73.5569;
var centery = 42.7818;
var defaultZoomLevel = 6;

var gSelectedResults = [];
var gCurrentResults = [];
var gSearchForm;
var myOverviewControl;

var trailInfos = [];

var curtrail = "------------ Pick a Trail ------------";

//var iconOptions = {};
//iconOptions.width = 12;
//iconOptions.height = 25;
//iconOptions.primaryColor = "#66834EFF";
//iconOptions.cornerColor = "#C2DCADFF";
//iconOptions.strokeColor = "#0C0101FF";
//var icon = MapIconMaker.createMarkerIcon(iconOptions);

//var iconOptions2 = {};
//iconOptions2.width = 12;
//iconOptions2.height = 25;
//iconOptions2.primaryColor = "#FFFF00FF";
//iconOptions2.cornerColor = "#C2DCADFF";
//iconOptions2.strokeColor = "#0C0101FF";
//var icon2 = MapIconMaker.createMarkerIcon(iconOptions2);

    
var BBIcon = new GIcon();
BBIcon.image = "images/BB.png";
BBIcon.iconSize = new GSize(17, 20);
BBIcon.shadowSize = new GSize(10, 10);
BBIcon.iconAnchor = new GPoint(10, 12);
BBIcon.infoWindowAnchor = new GPoint(9, 1);
BBIcon.infoShadowAnchor = new GPoint(9, 1);

var TrailHeadIcon = new GIcon();
TrailHeadIcon.image = "images/Trailhead.png";
TrailHeadIcon.iconSize = new GSize(20, 20);
TrailHeadIcon.shadowSize = new GSize(10, 10);
TrailHeadIcon.iconAnchor = new GPoint(10, 0);
TrailHeadIcon.infoWindowAnchor = new GPoint(10, 1);
TrailHeadIcon.infoShadowAnchor = new GPoint(10, 1);

var trailIcon = new GIcon();
trailIcon.image = "images/star.png";
trailIcon.iconSize = new GSize(17, 17);
trailIcon.shadowSize = new GSize(8, 8);
//trailIcon.iconSize = new GSize(26, 26);
//trailIcon.shadowSize = new GSize(10, 10);
trailIcon.iconAnchor = new GPoint(8, 8);
trailIcon.infoWindowAnchor = new GPoint(8, 1);
trailIcon.infoShadowAnchor = new GPoint(8, 1);

var trailIconMO = new GIcon();
trailIconMO.image = "images/starMO.png";
trailIconMO.iconSize = new GSize(17, 17);
trailIconMO.shadowSize = new GSize(8, 8);
trailIconMO.iconAnchor = new GPoint(8, 8);
trailIconMO.infoWindowAnchor = new GPoint(8, 1);
trailIconMO.infoShadowAnchor = new GPoint(8, 1);

var trailIconSelect = new GIcon();
trailIconSelect.image = "images/starSELECT.png";
trailIconSelect.iconSize = new GSize(17, 17);
trailIconSelect.shadowSize = new GSize(8, 8);
trailIconSelect.iconAnchor = new GPoint(8, 8);
trailIconSelect.infoWindowAnchor = new GPoint(8, 1);
trailIconSelect.infoShadowAnchor = new GPoint(8, 1);

var gdir;
      
var mgr_Trails;
var mgr_TrailHead;
var mgr_BB;

var bbMarkers = [];
var bbInfos = [];
var bbNames = [];
var side_bar_html = "";
var to_htmls2 = [];
var from_htmls2 = [];

var mgr_TrailHead;
var trailHeadMarkers = [];
var trailHeadInfos = [];
var to_htmls3 = [];
var from_htmls3 = [];

var tooltip = document.createElement("div");
var tooltipBB = document.createElement("div");

//var debug = null;

function initialize() { 

 //   debug= false;
//    if(debug) {
//        jslog.info("initialize()");
//    }
	
    if (GBrowserIsCompatible()) { 
    
        myOverviewControl = new GOverviewMapControl();
        
        geocoder = new GClientGeocoder();

        var centerPoint = new GLatLng(centery,centerx);
        	
        gmap = new GMap2(document.getElementById("map"),{draggableCursor:"pointer"});

	    gmap.addMapType(G_PHYSICAL_MAP);
	    gmap.addMapType(G_SATELLITE_3D_MAP);
        gmap.setMapType(G_PHYSICAL_MAP);
	    gmap.addControl(new GLargeMapControl(),new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 80)));	
        gmap.setCenter(new GLatLng(centery, centerx), defaultZoomLevel);
	    gmap.enableDoubleClickZoom();
	    gmap.enableContinuousZoom();	
	    gmap.addControl(new GScaleControl());
	    gmap.addControl(new GMapTypeControl());
	    gmap.addControl(new ToolbarControl());
        gmap.addControl(new ToolbarControl2());
        gmap.addControl(new ToolbarControl3());
        //gmap.addControl(new ToolbarControl3());
        //gmap.addControl(new ToolbarControl4());
	    
	    mgr_Trails = new MarkerManager(gmap, {trackMarkers:true});
	    mgr_TrailsSelected = new MarkerManager(gmap, {trackMarkers:true});
	    mgr_TrailHead = new MarkerManager(gmap, {trackMarkers:true});
	    mgr_BB = new MarkerManager(gmap, {trackMarkers:true});
    
        GEvent.addListener(gmap, "maptypechanged", function() { 
          if (gmap.getCurrentMapType() == G_SATELLITE_3D_MAP) { 
            gmap.closeInfoWindow();
          } 
        });
         
	    gmap.addControl(new GOverviewMapControl());
	
        GEvent.addListener(gmap, "zoomend", function(oldzoom, zoom) {
            testZoomLevel(zoom);
            testZoomLevel3(zoom);
            testZoomLevel4(zoom);
        });
        
//        GEvent.addListener(gmap, "dragend", function() {
//            testZoomLevel2();
//        });
        
        gdir=new GDirections(gmap, document.getElementById("div_directions"));
      // === Array for decoding the failure codes ===
      var reasons=[];
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
      reasons[G_GEO_BAD_REQUEST]        = "A directions request could not be successfully parsed.";
      reasons[G_GEO_MISSING_QUERY]      = "No query was specified in the input.";
      reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";

      // === catch Directions errors ===
      GEvent.addListener(gdir, "error", function() {
        var code = gdir.getStatus().code;
        var reason="Code "+code;
        if (reasons[code]) {
          reason = reasons[code];
        } 

        alert("Failed to obtain directions, "+reason);
      });
            
        // Initialize the local searcher
        gLocalSearch = new GlocalSearch();
        gLocalSearch.setSearchCompleteCallback(null, OnLocalSearch);
        gLocalSearch.setResultSetSize(google.search.Search.LARGE_RESULTSET);

        
        var geoXml = new GGeoXml("http://whereshappening.com/PTNY/PTNYc.kml");
        gmap.addOverlay(geoXml);
        
      setTrailMarkers();
      //setTrailHeadMarkers();
        
      document.getElementById("map").appendChild(tooltip);
      tooltip.style.visibility="hidden";
      
      document.getElementById("map").appendChild(tooltipBB);
      tooltipBB.style.visibility="hidden";
    } 
    
     setTimeout(fixCenter, 250);
     
//for(var j=0;j<document.forms.length;j++) {
//    for (var i=0;i<arguments.length;i++) {
//        document.forms[j].elements[arguments[i]].tabIndex=-1;
//    }
//} 
     
     //setTrails();
}

function fixCenter() {

//    if(debug) {
//        jslog.info("fixCenter()");
//    }
    
    gmap.checkResize();
    gmap.setCenter(new GLatLng(centery, centerx), defaultZoomLevel);
}

function testZoomLevel(level) {

//    if(debug) {
//        jslog.info("testZoomLevel()");
//    }
    
    if((level < 13) && (sv_enabled)) {
        stopStreetView();
    }

//    if(level < 11) {
//        removeTrails();        
//    } else {
//        addTrails();
//    }
}

function testZoomLevel4(level) {

//    if(debug) {
//        jslog.info("testZoomLevel4()");
//    }
    
    if(level < 6) {
        document.getElementById('cbBandBs').checked = false;
        document.getElementById('bbDiv').style.display = "none";
        mgr_BB.clearMarkers();
    }
}

function testZoomLevel3(level) {
    
//    if(debug) {
//        jslog.info("testZoomLevel3()");
//    }

    if(gmap.getZoom() == 11) {
        setTrailHeadMarkers();
    }
    
    if(gmap.getZoom() == 6) {
        
        trailIcon.iconSize = new GSize(17, 17);
        trailIconSelect.iconSize = new GSize(17, 17);
 //       trailIcon.shadowSize = new GSize(8, 8);
          TrailHeadIcon.iconAnchor = new GPoint(8, 8);
//        TrailHeadIcon.infoWindowAnchor = new GPoint(5, 1);
//        TrailHeadIcon.infoShadowAnchor = new GPoint(5, 1);

        mgr_Trails.refresh();
        mgr_TrailsSelected.refresh();
    } else if(gmap.getZoom() == 7) {
        
        trailIcon.iconSize = new GSize(23, 23);
        trailIconSelect.iconSize = new GSize(23, 23);
//        trailIcon.shadowSize = new GSize(9, 9);
        TrailHeadIcon.iconAnchor = new GPoint(12, 12);
//        TrailHeadIcon.infoWindowAnchor = new GPoint(5, 1);
//        TrailHeadIcon.infoShadowAnchor = new GPoint(5, 1);
        mgr_Trails.refresh();
        mgr_TrailsSelected.refresh();
    } else if(gmap.getZoom() == 8) {
    
        trailIcon.iconSize = new GSize(29, 29);
        trailIconSelect.iconSize = new GSize(29, 29);
//        trailIcon.shadowSize = new GSize(10, 10);
        TrailHeadIcon.iconAnchor = new GPoint(13, 13);
//        TrailHeadIcon.infoWindowAnchor = new GPoint(5, 1);
//        TrailHeadIcon.infoShadowAnchor = new GPoint(5, 1);
        mgr_Trails.refresh();
        mgr_TrailsSelected.refresh();
    } else if(gmap.getZoom() == 9) {
    
        trailIcon.iconSize = new GSize(29, 29);
        trailIconSelect.iconSize = new GSize(29, 29);
 //       trailIcon.shadowSize = new GSize(11, 11);
          TrailHeadIcon.iconAnchor = new GPoint(13, 13);
//        TrailHeadIcon.infoWindowAnchor = new GPoint(5, 1);
//        TrailHeadIcon.infoShadowAnchor = new GPoint(5, 1);
        mgr_Trails.refresh();
        mgr_TrailsSelected.refresh();
    } else if(gmap.getZoom() >= 10) {
    
        trailIcon.iconSize = new GSize(29, 29);
        trailIconSelect.iconSize = new GSize(29, 29);
//        trailIcon.shadowSize = new GSize(12, 12);
          TrailHeadIcon.iconAnchor = new GPoint(13, 13);
//        TrailHeadIcon.infoWindowAnchor = new GPoint(5, 1);
//        TrailHeadIcon.infoShadowAnchor = new GPoint(5, 1);
        mgr_Trails.refresh();
        mgr_TrailsSelected.refresh();
    }
}

function myzoom(id) {
    CallServer4("zoomNow=" + id, "");
}

function myzoom2(name) {
    CallServer3("zoomNow2=" + name, "");
}

function openList() {
        
//    if(debug) {
//        jslog.info("openList()");
//    }
    
    // Is open
    if(bAC.isContainerOpen()) {
        bAC.collapseContainer();
    }
    // Is closed
    else {
        bAC.getInputEl().focus(); // Needed to keep widget active
        setTimeout(function() { // For IE
            bAC.sendQuery("");
        },0);
    }
}


String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
};

function runQuery2() {

//    if(debug) {
//        jslog.info("runQuery2()");
//    }

    var trailName = document.getElementById('bInput').value;
    
    if(curtrail.trim() == trailName.trim()) {
        return false;
    }
    
    curtrail = trailName.trim();
    
    document.getElementById("busy").style.display = "block";
    
    if((trailName.trim() !== "") && (trailName.trim() != "------------ Pick a Trail ------------")) {
        if(trailName.indexOf("&") != -1) {
            trailName = trailName.replace(/&/g, "x99x");
        }
        //CallServer3("trailName=" + trailName, "");
        myzoom2(trailName);
    } else {
        document.getElementById("busy").style.display = "none";
    }
}

function runQuery() {
    
//    if(debug) {
//        jslog.info("runQuery()");
//    }
    
    document.getElementById("busy").style.display = "block";
    
    var newCenterPoint;

    var addressFound = false;
   
    if (geocoder) {
      
        var address = document.getElementById('myaddress').value;
        var useTypes = document.getElementById('use');
        var surfaceType = document.getElementById('surface');
        var lengthType = document.getElementById('lengthType').value;
        //var miles = 5; //document.getElementById('miles').value;
        //var trailName = document.getElementById('bInput').value;
        
          var selectedArray = [];
          var i;
          var count = 0;
          for (i=0; i<useTypes.options.length; i++) {
            if (useTypes.options[i].selected) {
            
              if(useTypes.options[i].value == "All") {
                selectedArray = [];
                selectedArray.push("0");
                selectedArray.push("1");
                selectedArray.push("2");
                selectedArray.push("3");
                selectedArray.push("4");
                selectedArray.push("5");
                selectedArray.push("6");
                selectedArray.push("8");
                break;
              }
              selectedArray[count] = useTypes.options[i].value;
              count++;
            }
          }
          
          if(selectedArray.length === 0) {
            selectedArray.push("0");
            selectedArray.push("1");
            selectedArray.push("2");
            selectedArray.push("3");
            selectedArray.push("4");
            selectedArray.push("5");
            selectedArray.push("6");
            selectedArray.push("8");
          }
          
          var selectedArray2 = [];
          var ii;
          var count2 = 0;
          for (ii=0; ii<surfaceType.options.length; ii++) {
            if (surfaceType.options[ii].selected) {

              if(surfaceType.options[ii].value == "All") {
                selectedArray2 = [];
                selectedArray2.push("0");
                selectedArray2.push("1");
                selectedArray2.push("2");
                selectedArray2.push("3");
                selectedArray2.push("4");
                selectedArray2.push("5");
                selectedArray2.push("6");
                break;
              }
              selectedArray2[count2] = surfaceType.options[ii].value;
              count2++;
            }
          }
          
          if(selectedArray2.length === 0) {
            selectedArray2.push("0");
            selectedArray2.push("1");
            selectedArray2.push("2");
            selectedArray2.push("3");
            selectedArray2.push("4");
            selectedArray2.push("5");
            selectedArray2.push("6");
          }

        

        minLng2 = ""; 
        maxLng2 = "";
        minLat2 = "";
        maxLat2 = "";
      
//        if((trailName.trim() != "") && (trailName.trim() != "------------ Pick a Trail ------------")) {
//            if(trailName.indexOf("&") != -1) {
//                trailName = trailName.replace("&", "x99x");
//            }
//            CallServer2("trailName=" + trailName, "");
//        } else if(address.trim() != "") {

        if(address.trim() !== "") {
            geocoder.getLatLng(
                address,
                function(point) {
                    if (!point) {
                        alert(address + " not found");
                    } else {
               
                        var oRadius = document.getElementById('radiusInput');
                        //oRadius.value = oRadius.value ? oRadius.value : 500;
                        
                        if(oRadius.value === "") {
                            document.getElementById("busy").style.display = "none";
                            alert('Please enter the number of miles from this zipcode you like to find trails within.');
                            return false;
                        }
                        
                        gmap.setCenter(point);                 
            	
                        //if (oRadius.value.match(/[^\d.]/)) {
	                    //    alert("Don't be silly. Enter a number for radius");
	                    //    return;
                        //}

                        circleRadius = oRadius.value;
                        doDrawCircle(point);
                        
                        //setTimeout("findTrailsInBounds()", 250);
    	
                        //var bounds = map.getBounds();  
                   
                        //var northEast = bounds.getNorthEast();
                        //var southWest = bounds.getSouthWest();  
                   
                        //minLng = southWest.x; 
                        //maxLng = northEast.x;
                        //minLat = southWest.y;
                        //maxLat = northEast.y;
                    }
                    
                    CallServer("minLng=" + minLng2 + "&maxLng=" + maxLng2 + "&minLat=" + minLat2 + "&maxLat=" + maxLat2 + "&useType=" + selectedArray + "&surfaceType=" + selectedArray2 + "&lengthType=" + lengthType, "");
                }
            );
        } else {
            CallServer("minLng=&maxLng=&minLat=&maxLat=&useType=" + selectedArray + "&surfaceType=" + selectedArray2 + "&lengthType=" + lengthType, "");
        }
    }
}

findTrailsInBounds = function() {

    var bounds = map.getBounds();
    
    
    bounds.containsLatLng();
};


function resetForm() {

//    if(debug) {
//        jslog.info("resetForm()");
//    }
    
    document.getElementById('use').value = "";
    document.getElementById('surface').value = "";
    document.getElementById('lengthType').value = "";
    //document.getElementById('miles').value = "";
    document.getElementById('radiusInput').value = "";
    document.getElementById('myaddress').value = "";
    document.getElementById('bInput').value = " ------------ Pick a Trail ------------";
    
    document.getElementById("trailsdiv").innerHTML = "";
    gmap.closeInfoWindow();
    
    //changeToUnselected();
    mgr_TrailsSelected.clearMarkers();
}

changeToSelected = function(sTrails) {

    mgr_TrailsSelected.clearMarkers();
    
    var aTrails = [];
    aTrails = sTrails.split(',');
    
    var trailMarkers_Selected = [];
    
    for(var i=0; i<aTrails.length; i++) {
    
      var sTrailID1 = aTrails[i];
    
      for (var j = 1; j < trailInfos.length; j++) {
      
        if(trailInfos[j] == null) {
            continue;
        }
        
      
        var sTrailID2 = trailInfos[j].trailid;
        
        if(sTrailID1 == sTrailID2) {
        
            var obj1 = createTrailMarker2(trailInfos[j].marker.getLatLng(), trailInfos[j].trailid, trailInfos[j].name);
            //obj1.setImage(trailIconSelect.image);
        
            trailMarkers_Selected.push(obj1);
            
            //trailInfos[j].marker.setImage(trailIconSelect.image);
            
            //setTimeout("changeImage(" + sTrailID1 + ")", 1);
            
            break;
        }
    
      } 
    }
    mgr_TrailsSelected.addMarkers(trailMarkers_Selected, 6);
    mgr_TrailsSelected.refresh();
};

//changeImage = function(id) {
//      for (var j = 1; j < trailInfos.length; j++) {
//      
//        var sTrailID2 = trailInfos[j].trailid;
//        
//        if(id == sTrailID2) {
//            
//            GEvent.addListener(trailInfos[j].marker, "mouseout", function(){
//                trailInfos[j].marker.setImage(trailIconSelect.image);   
//            });
//            break;
//        }
//        
//      }
//};

//changeToUnselected = function() {
//    for (var j = 1; j < trailInfos.length-1; j++) {
//        trailInfos[j].marker.setImage(trailIcon.image);
//    }
//    
//    setTimeout("changeImage2()", 50);
//};

//changeImage2 = function() {
//  for (var j = 1; j < trailInfos.length-1; j++) {  
//    GEvent.addListener(trailInfos[j].marker, "mouseout", function(){
//        trailInfos[j].marker.setImage(trailIcon.image);   
//    });        
//  }
//};

function ReceiveServerData(arg, context) {

//    if(debug) {
//        jslog.info("ReceiveServerData()");
//    }
        
    var sTrails = "";
    
    var index = arg.indexOf("<script>");
    var index1 = arg.indexOf("$");
    var index2 = arg.lastIndexOf("$");
    
    sTrails = arg.substring(index1+1, index2);
    arg = arg.substring(0, index);
    
    if(arg !== "") {
        document.getElementById('trailsdiv').innerHTML = arg;
    }
    
    document.getElementById("busy").style.display = "none";
    
    changeToSelected(sTrails);    
    
    var address = document.getElementById('myaddress').value;
    
    if(address == "") {
        //alert("address is blank");
        gmap.setCenter(new GLatLng(centery, centerx), defaultZoomLevel);
    }
}

function ReceiveServerData2(arg, context) {
    
    if(arg !== "") {
        var points = arg.split(',');
        var bounds = new GLatLngBounds();
        
        //zoomToFeature(points[0], points[1], points[2], points[3], points[4]);
        zoomToFeature(points[4]);
        
        if(gmap.getZoom() >= 11) {
            setTrailHeadMarkers();
        }
    }
    
    document.getElementById("busy").style.display = "none";
    //changeToSelected(sTrails);
}

zoomToFeature = function(myTrailID) {

    var minx = trailInfos[myTrailID].minx;
    var maxx = trailInfos[myTrailID].maxx;
    var miny = trailInfos[myTrailID].miny;
    var maxy = trailInfos[myTrailID].maxy;
        
    var sw = new GLatLng(miny,minx);
    var ne = new GLatLng(maxy,maxx);
    var tempbounds = new GLatLngBounds(sw,ne);
    var tempcenter = tempbounds.getCenter();

    gmap.setCenter(tempcenter);
    gmap.setZoom(gmap.getBoundsZoomLevel(tempbounds));
   // highlightTrail(myTrailID);
    
    setTimeout("openTrailWindow(" + myTrailID + ")", 250);
};


function doDrawCircle(newCenterPoint){
        
//    if(debug) {
//        jslog.info("doDrawCircle()");
//    }
    
	var center = gmap.getCenter();

	var bounds = new GLatLngBounds();

	
	var circlePoints = Array();

	with (Math) {
		var d = circleRadius/3963.189;	// radians

		var lat1 = (PI/180)* newCenterPoint.lat(); // radians
		var lng1 = (PI/180)* newCenterPoint.lng(); // radians

		for (var a = 0 ; a < 361 ; a++ ) {
			var tc = (PI/180)*a;
			var y = asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc));
			var dlng = atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(y));
			var x = ((lng1-dlng+PI) % (2*PI)) - PI ; // MOD function
			var point = new GLatLng(parseFloat(y*(180/PI)),parseFloat(x*(180/PI)));
			circlePoints.push(point);
			bounds.extend(point);
		}
		
		if(showAddressBuffer) {
            if (d < 1.5678565720686044) {             
                circle = new GPolygon(circlePoints, '#051b2d', 2, 1, '#7688a0', 0.3);         
            }        
            else {             
                circle = new GPolygon(circlePoints, '#000000', 2, 1);         
            }         
	        
            gmap.addOverlay(circle); 
		}
		
		var ne = bounds.getNorthEast();
		var sw = bounds.getSouthWest();
		
		maxLat2 = ne.y
		minLat2 = sw.y
		
		maxLng2 = ne.x;
		minLng2 = sw.x;
		
		
//		maxLat2 = bounds.ca.hi / (PI/180);
//		minLat2 = bounds.ca.lo / (PI/180);
//		
//		maxLng2 = bounds.V.hi / (PI/180);
//		minLng2 = bounds.V.lo / (PI/180); 

		gmap.setZoom(gmap.getBoundsZoomLevel(bounds));
	}
}

function setTrailInfo3(trailid, marker) {

//    if(debug) {
//        jslog.info("setTrailInfo3()");
//    }
    
    uses = [];

      // Read the data from example.xml
      var request = GXmlHttp.create();
      request.open("GET", "TrailXML3.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          // obtain the array of markers and loop through it
          var trails = xmlDoc.documentElement.getElementsByTagName("marker");
          
          for (var i = 0; i < trails.length; i++) {
          
            var sTrailID = trails[i].getAttribute("trailID");
            
            if(sTrailID == trailid) {

                var html = trails[i].getAttribute("html");
                var contact = trails[i].getAttribute("contact");
                var gps = trails[i].getAttribute("GPS");
                
                var name = trails[i].getAttribute("name");
                
                var minx = trails[i].getAttribute("minx");
                var maxx = trails[i].getAttribute("maxx");
                var miny = trails[i].getAttribute("miny");
                var maxy = trails[i].getAttribute("maxy");
        
                var bWalking = false;
                var bInlineSkating = false;
                var bBiking = false;
                var bMountainBiking = false;
                var bXCountrySkiing = false;
                var bBoating = false;
                var bFishing = false;
                var bHorsebackRiding = false;
                var bSnowmobiling = false;
                
                
                
                if(trails[i].getAttribute("Walking")) {
                    bWalking = true;
                }
                if(trails[i].getAttribute("In-line_Skating")) {
                    bInlineSkating = true;
                }
                if(trails[i].getAttribute("Bicycling")) {
                    bBiking = true;
                }
                if(trails[i].getAttribute("Mountain_Biking")) {
                    bMountainBiking = true;
                }
                if(trails[i].getAttribute("XC_Skiing")) {
                    bXCountrySkiing = true;
                }
                if(trails[i].getAttribute("Boating")) {
                    bBoating = true;
                }
                if(trails[i].getAttribute("Fishing")) {
                    bFishing = true;
                }
                if(trails[i].getAttribute("Horseback_Riding")) {
                    bHorsebackRiding = true;
                }
                if(trails[i].getAttribute("Snowmobiling")) {
                    bSnowmobiling = true;
                }
                
                trailInfos[sTrailID] = {"trailid":sTrailID, "name":name, "marker":marker, "html":html,"contact":contact, "gps":gps, "walking":bWalking, "inlineskating":bInlineSkating, "biking":bBiking, "mountainbiking":bMountainBiking, "xcountryskiing":bXCountrySkiing, "boating": bBoating, "fishing": bFishing, "horsebackriding":bHorsebackRiding, "snowmobiling":bSnowmobiling, "minx":minx, "miny":miny, "maxx":maxx, "maxy":maxy};
                break;
            }
          }
        }
      };
      request.send(null); 
      
}

function setTrailMarkers() {

//    if(debug) {
//        jslog.info("setTrailMarkers()");
//    }
    
    var trailMarkers = [];
    mgr_Trails.clearMarkers();
    mgr_TrailsSelected.clearMarkers();
          
      
    // Read the data from example.xml
      var request = GXmlHttp.create();
      request.open("GET", "TrailXML3.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          // obtain the array of markers and loop through it
          var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          
          for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var sTrailID = parseFloat(markers[i].getAttribute("trailID"));
            var name = markers[i].getAttribute("name");
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
           
             var marker = createTrailMarker(point, sTrailID, name);
             trailMarkers.push(marker);
             
       
                var html = markers[i].getAttribute("html");
                var contact = markers[i].getAttribute("contact");
                var gps = markers[i].getAttribute("GPS");
                
                var minx = markers[i].getAttribute("minx");
                var maxx = markers[i].getAttribute("maxx");
                var miny = markers[i].getAttribute("miny");
                var maxy = markers[i].getAttribute("maxy");
        
                var bWalking = false;
                var bInlineSkating = false;
                var bBiking = false;
                var bMountainBiking = false;
                var bXCountrySkiing = false;
                var bBoating = false;
                var bFishing = false;
                var bHorsebackRiding = false;
                var bSnowmobiling = false;
                
                
                
                if(markers[i].getAttribute("Walking")) {
                    bWalking = true;
                }
                if(markers[i].getAttribute("In-line_Skating")) {
                    bInlineSkating = true;
                }
                if(markers[i].getAttribute("Bicycling")) {
                    bBiking = true;
                }
                if(markers[i].getAttribute("Mountain_Biking")) {
                    bMountainBiking = true;
                }
                if(markers[i].getAttribute("XC_Skiing")) {
                    bXCountrySkiing = true;
                }
                if(markers[i].getAttribute("Boating")) {
                    bBoating = true;
                }
                if(markers[i].getAttribute("Fishing")) {
                    bFishing = true;
                }
                if(markers[i].getAttribute("Horseback_Riding")) {
                    bHorsebackRiding = true;
                }
                if(markers[i].getAttribute("Snowmobiling")) {
                    bSnowmobiling = true;
                }
                
                trailInfos[sTrailID] = {"trailid":sTrailID, "name":name, "marker":marker, "html":html,"contact":contact, "gps":gps, "walking":bWalking, "inlineskating":bInlineSkating, "biking":bBiking, "mountainbiking":bMountainBiking, "xcountryskiing":bXCountrySkiing, "boating": bBoating, "fishing": bFishing, "horsebackriding":bHorsebackRiding, "snowmobiling":bSnowmobiling, "minx":minx, "miny":miny, "maxx":maxx, "maxy":maxy};
          }
          
          mgr_Trails.addMarkers(trailMarkers, 6);
          
          mgr_Trails.refresh();          
        }
      };
      request.send(null);
      
}

    function createTrailMarker(latlng, id, name) {
    
//    if(debug) {
//        jslog.info("createTrailMarker()");
//    }
    
        var marker = new GMarker(latlng, {icon:trailIcon});
        marker.tooltip = '<div class="tooltip">'+name+'<\/div>';
        
        //myclick5a(marker, id, false);
        
        GEvent.addListener(marker, "click", function(latlng){ 
            myclick5(marker, id, latlng, false);  
            marker.setImage(trailIcon.image); 
		    tooltip.style.visibility="hidden";   
        });
        
        GEvent.addListener(marker, "mouseover", function(latlng){ 
            //mymouseover(marker, name); 
            marker.setImage(trailIconMO.image);   
            showTooltip(marker);  
        }); 
        
        GEvent.addListener(marker, "mouseout", function(latlng){ 
            //mymouseover(marker, name); 
            marker.setImage(trailIcon.image); 
		    tooltip.style.visibility="hidden";    
        });  
         
      return marker;
    }
    
    function createTrailMarker2(latlng, id, name) {
    
//    if(debug) {
//        jslog.info("createTrailMarker()");
//    }
    
        var marker = new GMarker(latlng, {icon:trailIconSelect});
        marker.tooltip = '<div class="tooltip">'+name+'<\/div>';
        
        //myclick5a(marker, id, false);
        
        GEvent.addListener(marker, "click", function(latlng){ 
            myclick5(marker, id, latlng, false);  
            marker.setImage(trailIconSelect.image); 
		    tooltip.style.visibility="hidden";   
        });
        
        GEvent.addListener(marker, "mouseover", function(latlng){ 
            //mymouseover(marker, name); 
            marker.setImage(trailIconMO.image);   
            showTooltip(marker);  
        }); 
        
        GEvent.addListener(marker, "mouseout", function(latlng){ 
            //mymouseover(marker, name); 
            marker.setImage(trailIconSelect.image);
            //marker.OriginalImage = trailIcon.image;
            //marker.SelectedImage = trailIconSelect.image; 
		    tooltip.style.visibility="hidden";    
        });  
         
      return marker;
    }
    
  function showTooltip(marker) {
  
//    if(debug) {
//        jslog.info("showTooltip()");
//    }
    
  	tooltip.innerHTML = marker.tooltip;
	var point=gmap.getCurrentMapType().getProjection().fromLatLngToPixel(gmap.getBounds().getSouthWest(),gmap.getZoom());
	var offset=gmap.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),gmap.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
	pos.apply(tooltip);
	tooltip.style.visibility="visible";
  }
  
  function showTooltipBB(marker) {
    
  	tooltipBB.innerHTML = marker.tooltip;
	var point=gmap.getCurrentMapType().getProjection().fromLatLngToPixel(gmap.getBounds().getSouthWest(),gmap.getZoom());
	var offset=gmap.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),gmap.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
	pos.apply(tooltipBB);
	tooltipBB.style.visibility="visible";
  }
    
function myclick5(marker, myTrailID, latlng, loading) {
  
//    if(debug) {
//        jslog.info("myclick5()");
//    }
          
    if(!trailInfos[myTrailID]) {
        if(!loading) {
            setTrailInfo3(myTrailID, marker);
        }
        setTimeout(function() { myclick5(marker, myTrailID, latlng, true)}, 200);
    } else {
        
        var name = trailInfos[myTrailID].name;
        var html = trailInfos[myTrailID].html;
        var contact = trailInfos[myTrailID].contact;
        var gps = trailInfos[myTrailID].gps;
        var bWalking = trailInfos[myTrailID].walking;
        var bInlineSkating = trailInfos[myTrailID].inlineskating;
        var bBiking = trailInfos[myTrailID].biking;
        var bMountainBiking = trailInfos[myTrailID].mountainbiking;
        var bXCountrySkiing = trailInfos[myTrailID].xcountryskiing;
        var bBoating = trailInfos[myTrailID].boating;
        var bFishing = trailInfos[myTrailID].fishing;
        var bHorsebackRiding = trailInfos[myTrailID].horsebackriding;
        var bSnowmobiling = trailInfos[myTrailID].snowmobiling;
        var minx = trailInfos[myTrailID].minx;
        var maxx = trailInfos[myTrailID].maxx;
        var miny = trailInfos[myTrailID].miny;
        var maxy = trailInfos[myTrailID].maxy;
        
         
        var myTab1 = getTab1(name, html, myTrailID, bWalking, bInlineSkating, bBiking, bMountainBiking, bXCountrySkiing, bBoating, bFishing, bHorsebackRiding, bSnowmobiling, true, minx, miny, maxx, maxy);
        var myTab2 = getTab2(name, contact, myTrailID);
        var myTab3 = getTab3(name, gps, myTrailID);
    

        var tabs = [];
        var tab1 = new GInfoWindowTab("Details", myTab1);
        var tab2 = new GInfoWindowTab("Contacts",myTab2);
        var tab3 = new GInfoWindowTab("Accessibility",myTab3);
        tabs.push(tab1);
        tabs.push(tab2);
        tabs.push(tab3);

        marker.openInfoWindowTabsHtml(tabs);    
    }
}

//function myclick5a(marker, myTrailID, loading) {
//  
//    if(debug) {
//        jslog.info("myclick5a()");
//    }
//          
//    if(!trailInfos[myTrailID]) {
//        if(!loading) {
//            setTrailInfo3(myTrailID, marker);
//        }
//        setTimeout(function() { myclick5a(marker, myTrailID, true)}, 200);  
//    } 

//}

function setTrailInfo3(trailid, marker) {

//    if(debug) {
//        jslog.info("setTrailInfo3()");
//    }
    
    uses = [];

      // Read the data from example.xml
      var request = GXmlHttp.create();
      request.open("GET", "TrailXML3.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          // obtain the array of markers and loop through it
          var trails = xmlDoc.documentElement.getElementsByTagName("marker");
          
          for (var i = 0; i < trails.length; i++) {
          
            var sTrailID = trails[i].getAttribute("trailID");
            
            if(sTrailID == trailid) {

                var html = trails[i].getAttribute("html");
                var contact = trails[i].getAttribute("contact");
                var name = trails[i].getAttribute("name");
                
                var minx = trails[i].getAttribute("minx");
                var maxx = trails[i].getAttribute("maxx");
                var miny = trails[i].getAttribute("miny");
                var maxy = trails[i].getAttribute("maxy");
        
                var bWalking = false;
                var bInlineSkating = false;
                var bBiking = false;
                var bMountainBiking = false;
                var bXCountrySkiing = false;
                var bBoating = false;
                var bFishing = false;
                var bHorsebackRiding = false;
                var bSnowmobiling = false;
                
                
                
                if(trails[i].getAttribute("Walking")) {
                    bWalking = true;
                }
                if(trails[i].getAttribute("In-line_Skating")) {
                    bInlineSkating = true;
                }
                if(trails[i].getAttribute("Bicycling")) {
                    bBiking = true;
                }
                if(trails[i].getAttribute("Mountain_Biking")) {
                    bMountainBiking = true;
                }
                if(trails[i].getAttribute("XC_Skiing")) {
                    bXCountrySkiing = true;
                }
                if(trails[i].getAttribute("Boating")) {
                    bBoating = true;
                }
                if(trails[i].getAttribute("Fishing")) {
                    bFishing = true;
                }
                if(trails[i].getAttribute("Horseback_Riding")) {
                    bHorsebackRiding = true;
                }
                if(trails[i].getAttribute("Snowmobiling")) {
                    bSnowmobiling = true;
                }
                
                trailInfos[sTrailID] = {"trailid":sTrailID, "name":name, "marker":marker, "html":html,"contact":contact, "walking":bWalking, "inlineskating":bInlineSkating, "biking":bBiking, "mountainbiking":bMountainBiking, "xcountryskiing":bXCountrySkiing, "boating": bBoating, "fishing": bFishing, "horsebackriding":bHorsebackRiding, "snowmobiling":bSnowmobiling, "minx":minx, "miny":miny, "maxx":maxx, "maxy":maxy};
                break;
            }
          }
        }
      };
      request.send(null); 
      
}


function openTrailWindow(myTrailID) {
  
//    if(debug) {
//        jslog.info("openTrailWindow()");
//    }
          
        var name = trailInfos[myTrailID].name;
        var html = trailInfos[myTrailID].html;
        var contact = trailInfos[myTrailID].contact;
        var gps = trailInfos[myTrailID].gps;
        var bWalking = trailInfos[myTrailID].walking;
        var bInlineSkating = trailInfos[myTrailID].inlineskating;
        var bBiking = trailInfos[myTrailID].biking;
        var bMountainBiking = trailInfos[myTrailID].mountainbiking;
        var bXCountrySkiing = trailInfos[myTrailID].xcountryskiing;
        var bBoating = trailInfos[myTrailID].boating;
        var bFishing = trailInfos[myTrailID].fishing;
        var bHorsebackRiding = trailInfos[myTrailID].horsebackriding;
        var bSnowmobiling = trailInfos[myTrailID].snowmobiling;
        var marker = trailInfos[myTrailID].marker;
        var minx = trailInfos[myTrailID].minx;
        var maxx = trailInfos[myTrailID].maxx;
        var miny = trailInfos[myTrailID].miny;
        var maxy = trailInfos[myTrailID].maxy;
        
         
        var myTab1 = getTab1(name, html, myTrailID, bWalking, bInlineSkating, bBiking, bMountainBiking, bXCountrySkiing, bBoating, bFishing, bHorsebackRiding, bSnowmobiling, true, minx, miny, maxx, maxy);
        var myTab2 = getTab2(name, contact, myTrailID);
        var myTab3 = getTab3(name, gps, myTrailID);
        

        var tabs = [];
        var tab1 = new GInfoWindowTab("Details", myTab1);
        var tab2 = new GInfoWindowTab("Contacts",myTab2);
        var tab3 = new GInfoWindowTab("Accessibility",myTab3);
        tabs.push(tab1);
        tabs.push(tab2);
        tabs.push(tab3);

        marker.openInfoWindowTabsHtml(tabs); 

}


//zoomToTrail_ = function(trailid) {

//    if(debug) {
//        jslog.info("zoomToTrail_()");
//    }
//    
//    openTrailWindow(trailid, false, false);
//}


function ToolbarControl() {}

    ToolbarControl.prototype = new GControl();

    ToolbarControl.prototype.initialize = function(gmap) {  

    var button1Div = document.createElement("div");  
    this.setButtonStyle_(button1Div);   
    button1Div.appendChild(document.createTextNode("Zoom Full"));  
    
    GEvent.addDomListener(button1Div, "click", function() {    
        ZoomFullExtent();
    });  
    
    var toolbarDiv = document.createElement("div");  
    toolbarDiv.appendChild(button1Div);  
    
    gmap.getContainer().appendChild(toolbarDiv);  
    
    return toolbarDiv;
};

function ToolbarControl3() {}

    ToolbarControl3.prototype = new GControl();

    ToolbarControl3.prototype.initialize = function(gmap) {  

    var button1Div = document.createElement("div");  
    this.setButtonStyle_(button1Div);   
    button1Div.appendChild(document.createTextNode("Show Legend")); 
    button1Div.id='abcde'; 
    
    GEvent.addDomListener(button1Div, "click", function() {    
        openMyPanel();
    });  
    
    var toolbarDiv = document.createElement("div");  
    toolbarDiv.id='abcde';
    toolbarDiv.appendChild(button1Div);  
    
    gmap.getContainer().appendChild(toolbarDiv);  
    
    return toolbarDiv;
};

ToolbarControl.prototype.getDefaultPosition = function() {  
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7,40));
};

ToolbarControl.prototype.setButtonStyle_ = function(button) {  
    button.style.textDecoration = "none";  
    button.style.color = "#000000";  
    button.style.backgroundColor = "white";  
    button.style.font = "11px verdana";  
    button.style.border = "1px solid black";  
    button.style.padding = "2px";    
    //button.style.marginBottom = "1px";  
    button.style.textAlign = "center";
    //button.style.paddingTop = "6px";    
    button.style.width = "6em";  
    //button.style.height = "1.5em";
    button.style.cursor = "pointer";
};

ToolbarControl3.prototype.getDefaultPosition = function() {  
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7,337));
};

ToolbarControl3.prototype.setButtonStyle_ = function(button) {  
    button.style.textDecoration = "none";  
    button.style.color = "#000000";  
    button.style.backgroundColor = "white";  
    button.style.font = "11px verdana";  
    button.style.border = "1px solid black";  
    button.style.padding = "2px";    
    //button.style.marginBottom = "1px";  
    button.style.textAlign = "center";
    //button.style.paddingTop = "6px";    
    button.style.width = "7em";  
    //button.style.height = "1.5em";
    button.style.cursor = "pointer";
};

function ToolbarControl2() {}

ToolbarControl2.prototype = new GControl();

ToolbarControl2.prototype.initialize = function(gmap) {
    
    var button2Div = document.createElement("div");  
    this.setButtonStyle_(button2Div);  
    button2Div.appendChild(document.createTextNode("Street View"));  
    
    GEvent.addDomListener(button2Div, "click", function() {    
        toggleStreetView();
    }); 
    
    var toolbarDiv = document.createElement("div");  
    toolbarDiv.appendChild(button2Div);
    toolbarDiv.style.border = "1px solid Black";  
    
    gmap.getContainer().appendChild(toolbarDiv);   
    
    return toolbarDiv;
};

ToolbarControl2.prototype.getDefaultPosition = function() {  
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(347,7));
};

ToolbarControl2.prototype.setButtonStyle_ = function(button) {  
    button.style.textDecoration = "none";  
    button.style.color = "#000000";  
    button.style.backgroundColor = "white";  
    button.style.font = "11px verdana";  
    button.style.borderBottom = "1px solid #B0B0B0";  
    button.style.borderRight = "1px solid #B0B0B0";
    button.style.padding = "1px";  
    button.style.paddingBottom = "2px";
    button.style.marginBottom = "0px";  
    button.style.textAlign = "center";  
    button.style.width = "8em";  
    button.style.cursor = "pointer";
};


function ToolbarControl4() {}

ToolbarControl4.prototype = new GControl();

ToolbarControl4.prototype.initialize = function(gmap) {
    
    var button4Div = document.createElement("div");  
    this.setButtonStyle_(button4Div);  
    
    GEvent.addDomListener(button4Div, "click", function() {    
        showHideTrailHeads();
    }); 
    
    var toolbarDiv = document.createElement("div");  
    toolbarDiv.appendChild(button4Div);
    
    gmap.getContainer().appendChild(toolbarDiv);   
    
    return toolbarDiv;
};

ToolbarControl4.prototype.getDefaultPosition = function() {  
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(112,40));
};

ToolbarControl4.prototype.setButtonStyle_ = function(button) {  
    button.style.textDecoration = "none";  
    button.style.color = "#000000";  
    button.style.backgroundColor = "white";  
    button.style.backgroundImage = "url('images/Trailhead.png')";  
    button.style.backgroundPosition = "center center";
    button.style.backgroundRepeat = "no-repeat";
    button.style.font = "11px verdana";  
    button.style.border = "1px solid black";  
    button.style.padding = "2px";  
    button.style.marginBottom = "1px";  
    button.style.textAlign = "center";  
    button.style.width = "2.6em";
    button.style.height = "2em";  
    button.style.cursor = "pointer";
    button.title = "Hide/Show Trail Stops";
};


function ZoomFullExtent() {

//    if(debug) {
//        jslog.info("ZoomFullExtent()");
//    }
    
	var centerPoint = new GLatLng(centery,centerx);
	gmap.setCenter(centerPoint, defaultZoomLevel);
}


toggleStreetView = function() {

//    if(debug) {
//        jslog.info("toggleStreetView()");
//    }
    
           if(sv_enabled) {
                stopStreetView();
           } else {
                                
                var level = gmap.getZoom();
                if(level < 13) {
                    alert('Please zoom in to at least zoom level 13 to use street view');
                    return;
                }
                loadStreetView();
           }
};

function showHideBandBs() {
//    
//    if(debug) {
//        jslog.info("showHideBandBs()");
//    }
    
    var obj2 = document.getElementById('cbBandBs');
    if(obj2.checked) {
        //document.getElementById("div_bbs").innerHTML = "<br><br>&#160;<b>Loading...</b>"; //"<div><img src='images/callbackActivityIndicator.gif' alt='' /></div>"; 
        
        if(gmap.getZoom() >= 6) {
            setBBMarkers();
            //document.getElementById('bbDiv').style.display = "block";
        } else {
            obj2.checked = false;
            alert('Please zoom in to at least zoom level 6 to see Bed & Breakfasts');
        }
    } else if(!obj2.checked) {
        //document.getElementById("div_bbs").innerHTML = "";
        mgr_BB.clearMarkers();
        //document.getElementById('bbDiv').style.display = "none";
    }
}


function setBBMarkers() {  
    
//    if(debug) {
//        jslog.info("setBBMarkers()");
//    }
    
      if(bbMarkers.length !== 0) {
          mgr_BB.addMarkers(bbMarkers, 6);
          mgr_BB.refresh();
          //document.getElementById("div_bbs").innerHTML = side_bar_html;  
      } else {
          
          mgr_BB.clearMarkers();
         // side_bar_html = "";  
          
          
          // Read the data from example.xml
          var request = GXmlHttp.create();
          request.open("GET", "XMLData.xml", true);
          request.onreadystatechange = function() {
            if (request.readyState == 4) {
              var xmlDoc = GXml.parse(request.responseText);
              var markers = xmlDoc.documentElement.getElementsByTagName("marker");
              
//              side_bar_html = side_bar_html + "<table cellpadding='0' cellspacing='0' border='0' style='height:auto;text-align:left;vertical-align:top;' >";
//              side_bar_html = side_bar_html + "  <tr>";
//              side_bar_html = side_bar_html + "    <td><img src='images/spacer.gif'' alt='' border='0' style='width:10px;height:1px;' /></td>";
//              side_bar_html = side_bar_html + "    <td><img src='images/spacer.gif' alt='' border='0' style='width:350px;height:10px;' /></td>";
//              side_bar_html = side_bar_html + "  </tr>";
              
              for (var i = 0; i < markers.length; i++) {
                var lat = parseFloat(markers[i].getAttribute("lat"));
                var lng = parseFloat(markers[i].getAttribute("lng"));
                var point = new GLatLng(lat,lng);
                var html = markers[i].getAttribute("html");
                var label = markers[i].getAttribute("label");
                var marker = createBBMarker(point,label,html);
                
              }
              mgr_BB.addMarkers(bbMarkers, 6);
              
              mgr_BB.refresh();
              
//              side_bar_html = side_bar_html + "  <tr>";
//              side_bar_html = side_bar_html + "    <td>&#160;</td>";
//              side_bar_html = side_bar_html + "    <td>&#160;</td>";
//              side_bar_html = side_bar_html + "  </tr>";
//              side_bar_html = side_bar_html + "</table>";

//              document.getElementById("div_bbs").innerHTML = side_bar_html;          
            }
          };
          request.send(null);
          
      }
}

   // A function to create the marker and set up the event window
     function createBBMarker(point,name,html) {
     
//    if(debug) {
//        jslog.info("createBBMarker()");
//    }
    
        var htmla = "<div style='width:230px;height:auto;font-weight:normal;font-family:Verdana;background-image:url(images/iw_grad2.jpg);background-repeat: repeat-x;background-position: bottom left;'>";
        htmla = htmla + "<table border='0' style='margin:5px;width:100%;'>";
        htmla = htmla + "<tr>";
        htmla = htmla + "  <td>";
        htmla = htmla + html;
        htmla = htmla + "  </td>";
        htmla = htmla + "</tr>";
        
        htmla = htmla + "<tr>";
        htmla = htmla + "  <td>";
        
     
        var i = bbMarkers.length;
        var marker = new GMarker(point,BBIcon);   
        marker.tooltip = '<div class="tooltip">'+name+'<\/div>';
        
        // The info window version with the "to here" form open
        to_htmls2[i] = htmla + '<br><br>Directions: <b>To here</b> - <a href="javascript:fromhere2(' + i + ')">From here</a>' +
           '<br>Start address:<form action="javascript:getDirections2()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr2" id="saddr2" value="" style="width:200px;" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" id="daddr2" value="'+name+"@"+ point.lat() + ',' + point.lng() + 
           '"/>';
        // The info window version with the "to here" form open
        from_htmls2[i] = htmla + '<br>Directions: <a href="javascript:tohere2(' + i + ')">To here</a> - <b>From here</b>' +
           '<br>End address:<form action="javascript:getDirections2()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr2" id="daddr2" value="" style="width:200px;" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" id="saddr2" value="'+name+"@"+ point.lat() + ',' + point.lng() +
           '"/>';
        // The inactive version of the direction info
        htmla = htmla + '<br>Directions: <a href="javascript:tohere2('+i+')">To here</a> - <a href="javascript:fromhere2('+i+')">From here</a>';

        htmla = htmla + "  </td>";
        htmla = htmla + "</tr>";    
        htmla = htmla + "</table>";
        htmla = htmla + "</div>";
        
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(htmla);
          tooltipBB.style.visibility="hidden";
        });
        
        GEvent.addListener(marker, "mouseover", function(latlng){ 
            //marker.setImage(trailIconMO.image);   
            showTooltipBB(marker);  
        }); 
        
        GEvent.addListener(marker, "mouseout", function(latlng){  
            //marker.setImage(trailIcon.image); 
		    tooltipBB.style.visibility="hidden";    
        }); 
        
        // save the info we need to use later for the side_bar
        bbMarkers[i] = marker;
        bbInfos[i] = htmla;
        bbNames[i] = name;
        // add a line to the side_bar html
        
//        side_bar_html = side_bar_html + "<tr style='height:20px;'>";
//        side_bar_html = side_bar_html + "  <td>&#160;</td>";
//        side_bar_html = side_bar_html + "  <td>";
//        side_bar_html = side_bar_html + "    <a href='#' style='color:#395036;text-decoration:none;font-size:12px;font-family:Verdana;' onclick='bbItemClicked(" + i + ");return false;'>" + name + "</a>";
//        side_bar_html = side_bar_html + "  </td>";
//        side_bar_html = side_bar_html + "</tr>";
            
        i++;
        return marker;
      }
      
      function getDirections2() {
      
//    if(debug) {
//        jslog.info("getDirections2()");
//    }
    
        var saddr2 = document.getElementById("saddr2").value;
        var daddr2 = document.getElementById("daddr2").value;
        
        document.getElementById('cur_saddr').value = saddr2;
        document.getElementById('cur_daddr').value = daddr2;
        
        gdir.load("from: "+saddr2+" to: "+daddr2);
        
        //expandPanelDock();
        //switchSiteDesc('directions', 'span3');
      }
      
      // functions that open the directions forms
      function tohere2(i) {
        bbMarkers[i].openInfoWindowHtml(to_htmls2[i]);
      }
      function fromhere2(i) {
        bbMarkers[i].openInfoWindowHtml(from_htmls2[i]);
      } 
      
      function bbItemClicked(i) {
        var obj1 = bbMarkers[i];
        var html = bbInfos[i];
        obj1.openInfoWindowHtml(html);
      }
      
      function ZoomToBB() {
      
        var obj2 = document.getElementById('cbBandBs');
        if(!obj2.checked) {
            //alert('Bed and Breakfast not found on map. You may need to turn the Bed & Breakfasts on.');
            alert("Please click the 'Show/Hide B&Bs' checkbox to see B&Bs on the map.");
            return;
        }
    
      
        var bbName = document.getElementById('bInput2').value;
        var bbIndex = -1;
        for(var i=0; i<bbNames.length; i++) {
            var tempName = bbNames[i].replace('B &amp; B', 'B & B');
            tempName = tempName.replace('B&amp;B', 'B & B');
            tempName = tempName.replace('B & B', 'B&B');
            if(tempName == bbName) {
                bbIndex = i;
                break;
            }
        }
        
        if(bbIndex > -1) {
            var obj1 = bbMarkers[bbIndex];
            var latlng = obj1.getLatLng();
            gmap.setCenter(latlng);
            setTimeout("openBBInfo(" + bbIndex + ")", 500);
        } else {
            //alert('Bed and Breakfast not found on map. You may need to turn the Bed & Breakfasts on.');
            alert("Please click the 'Show/Hide B&Bs' checkbox to see B&Bs on the map.");
        }
      
      }
      
    openBBInfo = function(bbIndex) {
        var obj1 = bbMarkers[bbIndex];
        var html = bbInfos[bbIndex];
        obj1.openInfoWindowHtml(html);
    };
      
    function setTrailHeadMarkers() {
        
//    if(debug) {
//        jslog.info("setTrailHeadMarkers()");
//    }
    
      if(trailHeadMarkers.length !== 0) {
          mgr_TrailHead.addMarkers(trailHeadMarkers, 11);
          mgr_TrailHead.refresh();
      } else {
      
          mgr_TrailHead.clearMarkers();
          
          var request = GXmlHttp.create();
          request.open("GET", "TrailheadXML.xml", true);
          request.onreadystatechange = function() {
            if (request.readyState == 4) {
              var xmlDoc = GXml.parse(request.responseText);
              var markers = xmlDoc.documentElement.getElementsByTagName("marker");
              
              for (var i = 0; i < markers.length; i++) {
                var lat = parseFloat(markers[i].getAttribute("lat"));
                var lng = parseFloat(markers[i].getAttribute("lng"));
                var point = new GLatLng(lat,lng);
                var html = markers[i].getAttribute("html");
                var label = markers[i].getAttribute("label");
                var marker = createTrailHeadMarker(point,label,html);
              }
              
              mgr_TrailHead.addMarkers(trailHeadMarkers, 11);
              
              mgr_TrailHead.refresh();
            }
          };
          request.send(null);
          
      }
}

     function createTrailHeadMarker(point,name,html) {
     
//    if(debug) {
//        jslog.info("createTrailHeadMarker()");
//    }
    
        var i = trailHeadMarkers.length;
        var marker = new GMarker(point,TrailHeadIcon);   
        
        // The info window version with the "to here" form open
        to_htmls3[i] = html + '<br><br><b>Directions: </b>To here - <a href="javascript:fromhere3(' + i + ')">From here</a>' +
           '<br>Start address:<form action="javascript:getDirections3()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr3" id="saddr3" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" id="daddr3" value="'+name+"@"+ point.lat() + ',' + point.lng() + 
           '"/>';
        // The info window version with the "to here" form open
        from_htmls3[i] = html + '<br>Directions: <a href="javascript:tohere3(' + i + ')">To here</a> - <b>From here</b>' +
           '<br>End address:<form action="javascript:getDirections3()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr3" id="daddr3" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" id="saddr3" value="'+name+"@"+ point.lat() + ',' + point.lng() +
           '"/>';
        // The inactive version of the direction info
        html = html + '<br>Directions: <a href="javascript:tohere3('+i+')">To here</a> - <a href="javascript:fromhere3('+i+')">From here</a>';

        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        trailHeadMarkers[i] = marker;
        trailHeadInfos[i] = html;
        i++;
        return marker;
      }
      
      function getDirections3() {
      
//    if(debug) {
//        jslog.info("getDirections3()");
//    }
    
        var saddr3 = document.getElementById("saddr3").value;
        var daddr3 = document.getElementById("daddr3").value;
        
        document.getElementById('cur_saddr').value = saddr3;
        document.getElementById('cur_daddr').value = daddr3;
        
        gdir.load("from: "+saddr3+" to: "+daddr3);
      }
      
      function tohere3(i) {
        trailHeadMarkers[i].openInfoWindowHtml(to_htmls3[i]);
      }
      function fromhere3(i) {
        trailHeadMarkers[i].openInfoWindowHtml(from_htmls3[i]);
      }  

function showHideTrailHeads() {

//    if(debug) {
//        jslog.info("showHideTrailHeads()");
//    }
    
    //var obj = document.getElementById('trailHeads_hidden');
    var obj2 = document.getElementById('cbTrailHeads');
    if(obj2.checked) {
        //obj.value = "true";
        setTrailHeadMarkers();
       
        var level = gmap.getZoom();
        if(level < 11) {
            //alert('Trail stops have been turned on but will not show until trails are visible.'); 
            alert('Zoom in closer to see trail parking areas.');        
        }
    
    } else if(!obj2.checked) {
        //obj.value = "false";
        mgr_TrailHead.clearMarkers();
    }
}

function clearDirections() {

//    if(debug) {
//        jslog.info("clearDirections()");
//    }
    
    gdir.clear();
    document.getElementById('cur_saddr').value = "";
    document.getElementById('cur_daddr').value = "";
}

function printDirections() {

//    if(debug) {
//        jslog.info("printDirections()");
//    }
    
//    http://maps.google.com/maps?
//    daddr=837+Bedford+Rd,+Schenectady,+NY+12308
//    &dirflg=
//    &saddr=137+jay+st+schenectady,+ny
//    &f=d
//    &sll=42.809239,-73.919985
//    &sspn=0.010815,0.01781
//    &ie=UTF8
//    &z=15
//    &layer=c
//    &pw=2

var saddr = document.getElementById("cur_saddr").value;
var daddr = document.getElementById("cur_daddr").value;

if((saddr.trim() === "") || (daddr.trim() === "")) {
    alert('No directions to print.');
    return false;
}

var dirflg = "";

var f = "&f=d";

var sll = gmap.getBounds().getSouthWest().toUrlValue() ;
        
var ne1 = gmap.getBounds().getNorthEast().lat();
var sw1 = gmap.getBounds().getSouthWest().lat();
var ne2 = gmap.getBounds().getNorthEast().lng();
var sw2 = gmap.getBounds().getSouthWest().lng();

var sspn = new GLatLng(ne1-sw1, ne2-sw2).toUrlValue();

var ie = "ie=UTF8";
var z = gmap.getZoom();
var layer = "c";
var pw = "2";

//var fff = new GLatLng((gmap.getBounds().getNorthEast().lat() − gmap.getBounds().getSouthWest().lat()), (gmap.getBounds().getNorthEast().lng() − gmap.getBounds().getSouthWest().lng())).toUrlValue();

window.open('http://maps.google.com/maps?daddr=' + daddr + '&dirflg=&saddr=' + saddr + '&f=d&sll=' + sll + '&sspn=' + sspn + '&ie=UTF8&z=15&layer=c&pw=2', 'print', '' );
}

printMap = function() {
    var ne1 = gmap.getBounds().getNorthEast().lat();
    var sw1 = gmap.getBounds().getSouthWest().lat();
    var ne2 = gmap.getBounds().getNorthEast().lng();
    var sw2 = gmap.getBounds().getSouthWest().lng();

    var sspn = new GLatLng((ne1+sw1)/2, (ne2+sw2)/2).toUrlValue();

    var z = gmap.getZoom();
    
    var showBB = false;
    var obj1 = document.getElementById('cbBandBs');
    if(obj1.checked) {
        showBB = true;
    } 
    
    var showTrailHead = false;
    var obj2 = document.getElementById('cbTrailHeads');
    if(obj2.checked) {
        showTrailHead = true;
    } 
    
    window.open('print.htm?sspn=' + sspn + '&z=' + z + '&showBB=' + showBB + '&showTrailHeads=' + showTrailHead, 'printmap', '' );
};




    //http://maps.google.com/maps?daddr=837+Bedford+Rd,+Schenectady,+NY+12308&dirflg=&saddr=137+jay+st+schenectady,+ny&f=d&sll=&sspn=0.010815,0.01781&ie=UTF8&z=15&layer=c&pw=2
    
    
    
function getTab1(name, html, trailID, bWalking, bInlineSkating, bBiking, bMountainBiking, bXCountrySkiing, bBoating, bFishing, bHorsebackRiding, bSnowmobiling, showZoomTo, minx, miny, maxx, maxy) {
    
//    if(debug) {
//        jslog.info("getTab1() - " + trailID);
//    }
    
    var infoTabHtml = "";
    
    infoTabHtml = infoTabHtml + '<table border="0" cellpadding="0" cellspacing="0" style="width:350px;height:auto;font-weight:normal;font-family:Verdana;background-image:url(images/iw_grad2.jpg);background-repeat: repeat-x;background-position: bottom left;">';
        
    infoTabHtml = infoTabHtml + '  <tr style="">';
    infoTabHtml = infoTabHtml + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';
    infoTabHtml = infoTabHtml + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:75px;height:1px;"></td>';
    infoTabHtml = infoTabHtml + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';
    infoTabHtml = infoTabHtml + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:260px;height:1px;"></td>'; 
    infoTabHtml = infoTabHtml + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';
    infoTabHtml = infoTabHtml + '  </tr>';

    infoTabHtml = infoTabHtml + '  <tr style="">';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td colspan="3" style="font-family:verdana;font-size:16px; font-weight:bolder;color:#43694c;font-style:normal;">' + name + '</td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '  </tr>';
    
    infoTabHtml = infoTabHtml + '  <tr style="height:10px;">';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '  </tr>';
    
    infoTabHtml = infoTabHtml + '  <tr style="height:100px;">';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td colspan="3">';
    infoTabHtml = infoTabHtml + '      <div style="height:110px;vertical-align:top">';
    infoTabHtml = infoTabHtml + '      <table id="mytable" border="0" cellpadding="0" cellspacing="0" style="width:100%;font-family:Verdana;vertical-align:top;">';
    infoTabHtml = infoTabHtml + '        <tr>';
    infoTabHtml = infoTabHtml + '          <td><img src="images/spacer.gif" alt="" border="0" style="width:145px;height:1px;"></td>';
    infoTabHtml = infoTabHtml + '          <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';
    infoTabHtml = infoTabHtml + '          <td><img src="images/spacer.gif" alt="" border="0" style="width:190px;height:1px;"></td>'; 
    infoTabHtml = infoTabHtml + '        </tr>';    
    
    infoTabHtml = infoTabHtml + '          ' + html;    
    
    infoTabHtml = infoTabHtml + '      </table>';
    infoTabHtml = infoTabHtml + '     </div>';
    infoTabHtml = infoTabHtml + '    </td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '  </tr>'; 
    
    infoTabHtml = infoTabHtml + '  <tr style="vertical-align:bottom;">';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td colspan="3">';
    if(bWalking) { infoTabHtml = infoTabHtml + '      <img src="images/walking.png" alt="" title="walking" />'; }
    if(bBiking) { infoTabHtml = infoTabHtml + '      <img src="images/bike.png" alt="" title="bicycling" />'; }
    if(bHorsebackRiding) { infoTabHtml = infoTabHtml + '      <img src="images/horse.png" alt="" title="horseback riding" />'; }
    if(bXCountrySkiing) { infoTabHtml = infoTabHtml + '      <img src="images/XCSkiing.png" alt="" title="cross-country skiing" />'; }
    if(bInlineSkating) { infoTabHtml = infoTabHtml + '      <img src="images/InlineSkating.png" alt="" title="in-line skating" />'; }
    if(bFishing) { infoTabHtml = infoTabHtml + '      <img src="images/fishing.png" alt="" title="fishing" />'; }
    if(bBoating) { infoTabHtml = infoTabHtml + '      <img src="images/Boating.png" alt="" title="boating" />'; }
    if(bMountainBiking) { infoTabHtml = infoTabHtml + '      <img src="images/Mountain Biking.png" alt="" title="mountain biking" />'; }
    if(bSnowmobiling) { infoTabHtml = infoTabHtml + '      <img src="images/Snowmobiling.png" alt="" title="snowmobiling" />'; }
    infoTabHtml = infoTabHtml + '    </td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '  </tr>';
    
    infoTabHtml = infoTabHtml + '  <tr style="height:10px;">';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
    infoTabHtml = infoTabHtml + '  </tr>';
    
    //if(showZoomTo) {
        infoTabHtml = infoTabHtml + '  <tr style="height:15px;">';
        infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
        infoTabHtml = infoTabHtml + '    <td colspan="3" style="text-align:right;padding-bottom:3px;"><img src="images/ZoomTrail.gif" onclick="zoomToFeature(' + trailID + ');return false;" alt="" style="cursor:pointer;" /></td>';
        infoTabHtml = infoTabHtml + '    <td>&#160;</td>';
        infoTabHtml = infoTabHtml + '  </tr>';
    //}
    
    infoTabHtml = infoTabHtml + '</table>';
    
    return infoTabHtml;

}


function getTab2(name, contact, trailID) {

//    if(debug) {
//        jslog.info("getTab2() - " + trailID);
//    }
    
    var infoTabHtml2 = "";
    
    infoTabHtml2 = infoTabHtml2 + '<table border="0" cellpadding="0" cellspacing="0" style="width:350px;height:auto;font-family:Verdana;background-image:url(images/iw_grad2.jpg);background-repeat: repeat-x;background-position: bottom left;">';
        
    infoTabHtml2 = infoTabHtml2 + '  <tr>';
    infoTabHtml2 = infoTabHtml2 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';
    infoTabHtml2 = infoTabHtml2 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:25px;height:1px;"></td>';
    infoTabHtml2 = infoTabHtml2 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';
    infoTabHtml2 = infoTabHtml2 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:310px;height:1px;"></td>'; 
    infoTabHtml2 = infoTabHtml2 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';   
    infoTabHtml2 = infoTabHtml2 + '  </tr>';

    infoTabHtml2 = infoTabHtml2 + '  <tr>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td colspan="3" style="font-family:verdana;font-size:16px; font-weight:bolder;color:#43694c;font-style:normal;">' + name + '</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '  </tr>';
    
    infoTabHtml2 = infoTabHtml2 + '  <tr style="height:20px;">';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '  </tr>';
    
    infoTabHtml2 = infoTabHtml2 + '  <tr style="height:130px;">';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td colspan="3">';
    infoTabHtml2 = infoTabHtml2 + '     <div style="width:340px;height:125px;overflow-x:hidden;overflow-y:hidden;">';
    infoTabHtml2 = infoTabHtml2 + '      <table border="0" cellpadding="0" cellspacing="0" style="height:100%;font-family:Verdana;text-align:left;font-size:9px;">';
    
    infoTabHtml2 = infoTabHtml2 + '         ' + contact;
    
    infoTabHtml2 = infoTabHtml2 + '      </table>';
    infoTabHtml2 = infoTabHtml2 + '     </div>';
    infoTabHtml2 = infoTabHtml2 + '    </td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '  </tr>'; 

    infoTabHtml2 = infoTabHtml2 + '  <tr style="height:20px;">';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '    <td>&#160;</td>';
    infoTabHtml2 = infoTabHtml2 + '  </tr>';
 
    infoTabHtml2 = infoTabHtml2 + '</table>';
    
    return infoTabHtml2;
}


function getTab3(name, gps, trailID) {

//    if(debug) {
//        jslog.info("getTab3() - " + trailID);
//    }
    
    var infoTabHtml3 = "";
    
    infoTabHtml3 = infoTabHtml3 + '<table border="0" cellpadding="0" cellspacing="0" style="width:350px;height:auto;font-family:Verdana;background-image:url(images/iw_grad2.jpg);background-repeat: repeat-x;background-position: bottom left;">';
        
    infoTabHtml3 = infoTabHtml3 + '  <tr>';
    infoTabHtml3 = infoTabHtml3 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';
    infoTabHtml3 = infoTabHtml3 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:25px;height:1px;"></td>';
    infoTabHtml3 = infoTabHtml3 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';
    infoTabHtml3 = infoTabHtml3 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:310px;height:1px;"></td>'; 
    infoTabHtml3 = infoTabHtml3 + '    <td><img src="images/spacer.gif" alt="" border="0" style="width:5px;height:1px;"></td>';   
    infoTabHtml3 = infoTabHtml3 + '  </tr>';

    infoTabHtml3 = infoTabHtml3 + '  <tr>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td colspan="3" style="font-family:verdana;font-size:16px; font-weight:bolder;color:#43694c;font-style:normal;">' + name + '</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '  </tr>';
    
    infoTabHtml3 = infoTabHtml3 + '  <tr style="height:20px;">';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '  </tr>';
    
    infoTabHtml3 = infoTabHtml3 + '  <tr style="height:130px;">';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td colspan="3">';
    infoTabHtml3 = infoTabHtml3 + '     <div style="width:340px;height:125px;overflow-x:hidden;overflow-y:hidden;">';
    infoTabHtml3 = infoTabHtml3 + '      <table border="0" cellpadding="0" cellspacing="0" style="height:100%;font-family:Verdana;text-align:left;font-size:9px;">';
    
    infoTabHtml3 = infoTabHtml3 + '         ' + gps;
    
    infoTabHtml3 = infoTabHtml3 + '      </table>';
    infoTabHtml3 = infoTabHtml3 + '     </div>';
    infoTabHtml3 = infoTabHtml3 + '    </td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '  </tr>'; 

    infoTabHtml3 = infoTabHtml3 + '  <tr style="height:20px;">';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '    <td>&#160;</td>';
    infoTabHtml3 = infoTabHtml3 + '  </tr>';
 
    infoTabHtml3 = infoTabHtml3 + '</table>';
    
    return infoTabHtml3;
}

function _Submit(e, id) {

    if(e.keyCode == "13") {
        if (id == "searchtable") {
            runQuery();
        }
    }
    
    return false;
}


openMyPanel = function() {
    //alert('here');
    YAHOO.example.container.myPanel.show();
    showPanel = true;
};

    function closeMyPanel() {
        showPanel = false;
    }

unloadSplash = function() {
    YAHOO.example.container.wait2.hide();
};

function setMyPanel() {
            YAHOO.example.container.myPanel.render();
            YAHOO.example.container.myPanel.cfg.setProperty('context',['abcde', 'tl', 'bl']);
            
            //if(showPanel) {
                YAHOO.example.container.myPanel.show();
            //} else {
            //    YAHOO.example.container.myPanel.hide();
            //}
}
