    var map = null;
    var geocoder = null;
    var startPoint;
    
    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GScaleControl());
        map.setCenter(new GLatLng(39.10, -94.58), 1);
        geocoder = new GClientGeocoder();
      }
    }

function createMarker(point, label)
{
var marker = new GMarker(point);
// Show this markers index in the info window when it is clicked
var html = label;
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
return marker;
};

    function showAddress(address,label) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
//              alert(address + " not found");
            } else {
              var newPoint = new GLatLng(point.lat()+((Math.floor(Math.random()*10)-5)/1000),point.lng()+((Math.floor(Math.random()*10)-5)/1000));
              var marker = new GMarker(newPoint);
              map.addOverlay(marker);
	      var html = label;
	      GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml(html);});
            }
          }
        );
      }
    }

function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"none";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"none";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"none";
	}
}

function setCookie(c_name,value)
{
  document.cookie=c_name+ "=" +escape(value);
}

function markAllRows( container_id, status ) {
		var rows = document.getElementById(container_id).getElementsByTagName('div');
    var checkbox;
    for ( var i = 0; i < rows.length; i++ ) {
        checkbox = rows[i].getElementsByTagName( 'input' )[0];
        if ( checkbox && checkbox.type == 'checkbox' ) {
            if ( checkbox.disabled == false ) {
               checkbox.checked = status;
            }
        }
    }
    return true;
}

function shCard(card_id, p_id, offset)
{
  var card = _myGetElById(card_id);
  var p = _myGetElById(p_id);
	offset = offset || 150;
  card.style.display = "";
  pos = findPos(p);
  pos_l = pos[0]+offset;
  pos_t = pos[1];
  card.style.left = pos_l+'px';
  card.style.top = pos_t+'px';
}

function hCard(card_id)
{
  var card = _myGetElById(card_id);
  card.style.display = "none";
}

function _myGetElById(el_id)
{
  if (document.getElementById)
	{
		// this is the way the standards work
		var obj = document.getElementById(el_id);
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var obj = document.all[el_id];
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var obj = document.layers[el_id];
	}
	return obj;
}

function getAddrMarker(intType)
{
  intBMarker = 30; //size in pixels of the big marker
  intSMarker = 20; //size in pixels of the small marker
  icon_path = '../assets/images/'; //path to icon image files
  
  if (intType == 1)
  {
    icon_f = 'small.gif';
    icon_size = intSMarker;
  }
  else
  {
    icon_f = 'big.gif';
    icon_size = intBMarker;
  }
  
  icon_path +=icon_f; //determine icon path
  icon_center = icon_size / 2; //determine anchor center
  
  icon = new GIcon();
  icon.image = icon_path;
  icon.iconSize = new GSize(icon_size, icon_size);
  icon.iconAnchor = new GPoint(icon_center, icon_center); //anchor is in the center
  icon.infoWindowAnchor = new GPoint(icon_center, icon_center); //window anchor is in the center
  return icon;
}

function putP(address, label, icn, booStart, weight, opacity)
{
  var pIcon = getAddrMarker(icn);
  geocoder.getLatLng(
        address,
        function(point) 
        {
          if (point) 
          {
            var newPoint = new GLatLng(point.lat()+((Math.floor(Math.random()*10)-5)/1000),point.lng()+((Math.floor(Math.random()*10)-5)/1000));
            var marker = new GMarker(newPoint,pIcon);
            map.addOverlay(marker);
            GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml(label);});
            //check if this is the start point
            if (booStart) 
            {
              startPoint = newPoint;
            }
            else
            {
              //we have to draw a line
              var l_points = new Array(startPoint, newPoint);
              var l_color = (opacity == 0.5) ? "#CCCC33" : "#000000"; 
              var polyline = new GPolyline(l_points, l_color, weight, opacity);
              map.addOverlay(polyline);
            }
          }
        }
      );
}

function putPlaces(arrPlaces, booStart)
{
  if (geocoder) 
  {
    var arr_l = arrPlaces.length; 
    for (i=0;i<arr_l;i++)
    {
      var address = arrPlaces[i][0];
      var label = arrPlaces[i][1];
      var icn = arrPlaces[i][2]; 
      var weight = arrPlaces[i][3];
      var opacity = arrPlaces[i][4];
      putP(address, label, icn, booStart, weight, opacity);
    }
  }
}

function loadNet(arrStart, arrEnd) {        
    load(); //- load the basic map
    //put the start point on the map
    map.clearOverlays();
    putPlaces(arrStart, true);        
    //put other places
    putPlaces(arrEnd, false);
}

function panToLocation(location)
{
	// alert(location);
	if (geocoder) {
		geocoder.getLatLng(
			location,
			function(point) 
			{
				if (point) 
				{
					var newPoint = new GLatLng(point.lat()+((Math.floor(Math.random()*10)-5)/1000),point.lng()+((Math.floor(Math.random()*10)-5)/1000));
					// alert(point.lat());
					map.panTo(newPoint);
				}
			}
		);
	}
}
