// jhm_support.js
// Javascript functions and definitions for jhm_ mapping application.
// Part of the JH Map system

// Copyright 2007, 2009, Jeff Hennick jhm_system AT jeff-h.com

// See jhm_inc.php for GPL license details.

// 5/11/10 msrmaps.com was terraserver.microsoft.com.
// 10/16/09 NoParkingMarker.
// 10/14/09 moved vars WMS_TOPO_MAP WMS_DOQ_MAP out of function so they work with HMapType('Topo');


function say(a) {GLog.write(a)}

 var HTrailLists = [];
 var map = '';
 var Hiframe = '';

 var HmapId = 'HmapDiv';
 var HonLoadListB = new Array; // functions to be called onLoad BEFORE the map
 var HonLoadListA = new Array; // functions to be called onLoad AFTER the map
 var HonUnloadList = new Array; // functions to be called onUnLoad
 var HMapTypes = new Array();

 var HMapWidth = '400px';
 var HMapHeight = '300px';

 var HFlag = '!';

 var HShowSizeControl = 0;

 var MapFile = "{$_SERVER['PHP_SELF']}";

 var HNumM = new Array;

 HonLoadListA[0]= new Function ("HLoadMap()"); // Loads the Google map
 HonUnloadList[0]= new Function ("GUnload()"); // UnLoads the Google map


 ////////////////////////////////  API Functions JS ////////////////////

 function HOnLoadJ(n, f) {  // n is the name of a function to be called, no "()" or parameters allowed
                           // The function will be called AFTER the page is loaded
                           // and the Google Map is displayed.  If f is TRUE, it will be called BEFORE the map
  var m = n + "()";
  if (f) HonLoadListB[HonLoadListB.length] = new Function (m);
  else HonLoadListA[HonLoadListA.length] = new Function (m);
 }

 function HOnUnload(n) {  // n is the name of a function to be called, no "()" or parameters allowed
  var m = n + "()";
  HonUnloadList[HonUnloadList.length] = new Function (m);
 }


 function HShowCopyrightJ(m) {
  alert(m);
 }

 ////////////////////////////// Data Loading Functions JS ///////////////

 function HMakeTrailInfoJ(info) {
  HTrailInfo = info;
 }

 function HMakeMarkerJ(num,y,x,type,msg){
  if(y!=0) {
   if (!type) type = HInfoMarker;
   var np = new GMarker(new GPoint(x, y),{icon: type, draggable: true, dragCrossMove: false, bouncy: false});
   np.disableDragging();
//   var but = (type == HTrailMarker && HShowDetails !== null && HPedDisp) ? '<br><button onclick=HMakeProf(' + HPrev +')>Profile</button>' : '';
   var but = '';
   if (msg!='') GEvent.addListener(np, "click", function(overlay,point) {if(!HeditTr)HMarkerClick(np,num,msg,but,point)});
   HOverlayList[num] = np;
   GEvent.addListener(np, "mouseover", function(overlay,point) {HMove(num)});
   GEvent.addListener(np, "mouseout", function(overlay,point) {HMouseOutMk(num)});
  }
  HsegNum = num;
 }

 function HMakeSegJ(num,pathpoints,color,opacity,width,info) {
  width = width || 5;
  opacity = opacity || 1;
  var p = HPts(pathpoints);
  if (p[1][0] != undefined) {
   HWP[num] = p[1];
   HWPId[num] = p[2];
  }
  var p = p[0];
  HOverlayList[num] = new GPolyline(p, "#" + color,width,opacity);
  GEvent.addListener(HOverlayList[num], "click", function(point) {HTrailClick(point,num,info)})
  GEvent.addListener(HOverlayList[num], "mouseover", function() {}) // gives pointer cursor
  HPrev = num;
  HsegNum = num;
 }

 function HMakePolygonJ(num,pathpoints,color,opacity,width,fillColor,fillOpacity,info) {
  width = width || 5;
  opacity = opacity || 1;
  var p = HPts(pathpoints);
  if (p[1][0] != undefined) {
   HWP[num] = p[1];
   HWPId[num] = p[2];
  }
  var p = p[0];
  var len = p.length - 1;
  if (p[0] != p[len-1] || p[1] != p[len]) {  // close the polygon if start and stop not the same, so border goes all around
   p[len+1] = p[0];
   p[len+2] = p[1];
  }
  HOverlayList[num] = new GPolygon(p, "#" + color,width,opacity,"#" + fillColor,fillOpacity);
  if (info != '') GEvent.addListener(HOverlayList[num], "click", function(point) {
    if (HClickProc) map.openInfoWindowHtml(point,'<div style="white-space: nowrap;">' +  info + '<\/div>');
    else HAddSegPoint(point);
   })
  GEvent.addListener(HOverlayList[num], "mouseover", function() {}) // gives pointer cursor
  HPrev = num;
  HsegNum = num;
 }

 function HMakeEncodedSegJ(num,pathpoints,levels,color,opacity,width,info) {
  width = width || 5;
  opacity = opacity || 1;
  color = '#' + color;
  HOverlayList[num] = new GPolyline.fromEncoded({
   color: color,
   weight: width,
   opacity: opacity,
   points: pathpoints,
   levels: levels,
   zoomFactor: 32,
   numLevels: 4
        });
  GEvent.addListener(HOverlayList[num], "click", function(point) {HTrailClick(point,num,info)})
  GEvent.addListener(HOverlayList[num], "mouseover", function() {}) // gives pointer cursor
  HPrev = num;
  HsegNum = num;
 }

 ////////////////////////////// Internal Functions JS //////////////////

 function HWindowSize(what) {
  // mod from: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if (what == 'width') return myWidth;
  else return myHeight;
}

 function HLoadMap() {
  var mapdiv = document.getElementById(HmapId);
  if (typeof(GIcon) == 'undefined') mapdiv.innerHTML = "<span style='color:red'>Sorry, there seems to be no connection to Google Maps.</span>";
  else if (GBrowserIsCompatible() && mapdiv) {
   HAddTopo();
   if (HMapWidth != '') mapdiv.style.width = HMapWidth;
   if (HMapHeight.substr(HMapHeight.length -1) == '%') HMapHeight = HWindowSize() * .01 * HMapHeight.substring(0,HMapHeight.length -1) + 'px';
   if (HMapHeight != '') mapdiv.style.height = HMapHeight;
   map = new GMap2(mapdiv, { mapTypes: HMapTypes });
   map.setCenter(new GLatLng(HMCLatIni, HMCLonIni), HZoomIni);
   var HMTypeIniL = HMTypeIni.toLowerCase();
   if (HMTypeIniL == 'map') HMTypeIni = G_NORMAL_MAP;
   if (HMTypeIniL == 'terrain') HMTypeIni = G_PHYSICAL_MAP;
   if (HMTypeIniL == 'hybrid') HMTypeIni = G_HYBRID_MAP;
   if (HMTypeIniL == 'topo') HMTypeIni = WMS_TOPO_MAP;
   if (HMTypeIniL == 'topo - ms') HMTypeIni = WMS_TOPO_MAP;
   if (HMTypeIniL == 'topo-ms') HMTypeIni = WMS_TOPO_MAP;
   if (HMTypeIniL == 'satellite') HMTypeIni = G_SATELLITE_MAP;
   if (HMTypeIniL == 'satellite - ms') HMTypeIni = WMS_DOQ_MAP;
   if (HMTypeIniL == 'satellite-ms') HMTypeIni = WMS_DOQ_MAP;
   map.setMapType(HMTypeIni);
   HAddControls();
   HFixCheckBox();
  }
 }

 function HRemove() {
  var kids = window.document.body.childNodes;
  for (var i = 0; i < kids.length; i++) {
   var id = kids[i].id;
   if (id){
    if (id == 'HmapDiv') continue;
    if (id == 'HmapDivCaption') {
     kids[i].style.display = 'block';
     continue;
    }
   }
   if (kids[i].style) kids[i].style.display = 'none';
  }
 }

 function HPortrait() {
  map.getContainer().style.height = '1000px';
  map.getContainer().style.width = '700px';
 }

 function HLandscape() {
  map.getContainer().style.height = '700px';
  map.getContainer().style.width = '1000px';
 }

 function HNewCaption(t) {
  var tx = t.value;
  document.getElementById('HmapDivCaption').innerHTML = tx;
 }
 var o = ''

 function HshowProfile(page, name) {
  if (!name) name = '';
  openPopup(page, name, 920, 600);
 }

 function HMarkerClick(np,num,msg,but,point) {
  if (HeditTr) HMove(num);
  else if (HClickProc) np.openInfoWindowHtml('<div style="white-space: nowrap;">' +  msg + but + '<\/div>');
    else HAddSegPoint(point);
 }

 function HTrailClick(point,num,info) {
   if (num == 0) {
    HPLine.enableEditing();
    return;
   }
   if (HeditTr) HEdit(num)
   else if (info != '')
    if (HClickProc) map.openInfoWindowHtml(point,'<div style="white-space: nowrap;">' +  info + '<\/div>');
    else HAddSegPoint(point);
 }

function Hsh(n) {  // Show / Hide group
 sym = document.getElementById('HE' + n);
 d = document.getElementById('Hdd' + n).style;
 if (sym.alt == '-') { // showing
  sym.src = 'icons/box+.gif';
  sym.alt = '+';
  d.display = 'none';
 }
 else { // hidden
  sym.src = 'icons/box-.gif';
  sym.alt = '-';
  d.display = 'block';
 }
}

/////////////
// from:  http://www.captain.at/howto-ajax-form-post-request.php

   var Hhttp_request = false;

   function HmakePOSTRequest(url, parameters) {
      Hhttp_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         Hhttp_request = new XMLHttpRequest();
         if (Hhttp_request.overrideMimeType) {
                // set type accordingly to anticipated content type
            //Hhttp_request.overrideMimeType('text/xml');
            Hhttp_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            Hhttp_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               Hhttp_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!Hhttp_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      Hhttp_request.onreadystatechange = HalertContents;
      Hhttp_request.open('POST', url, true);
      Hhttp_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      Hhttp_request.setRequestHeader("Content-length", parameters.length);
      Hhttp_request.setRequestHeader("Connection", "close");
      Hhttp_request.send(parameters);
   }

   function HalertContents() {
      if (Hhttp_request.readyState == 4) {
         if (Hhttp_request.status == 200) {
            //alert(Hhttp_request.responseText);
            result = Hhttp_request.responseText;
            document.getElementById('HMailResponse').innerHTML = result;
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

   function HAjaxPost(urla,ids) {
      var url = arguments[0];
      var poststr = '';
      for (var i = 1;i < arguments.length; i++) {
        poststr += arguments[i] + '=' + encodeURIComponent(document.getElementById(arguments[i]).value ) + "&";
      }
      HmakePOSTRequest(url, poststr);
   }


 //////////// Map Types   ////////////////////////////
 // Web Map Service map types.  Jef Poskanzer

 function WMSCreateMap( name, copyright, baseUrl, layer, minResolution, maxResolution, urlArg ) {
  var tileLayer = new GTileLayer( new GCopyrightCollection( copyright ), minResolution, maxResolution );
  tileLayer.baseUrl = baseUrl;
  tileLayer.layer = layer;
  tileLayer.getTileUrl = WMSGetTileUrl;
  tileLayer.getCopyright = function () { return copyright; };
  var tileLayers = [ tileLayer ];
  return new GMapType( tileLayers, G_SATELLITE_MAP.getProjection(), name, {urlArg: 'o' } );
 }

 function WMSGetTileUrl( tile, zoom ) {
  var southWestPixel = new GPoint( tile.x * 256, ( tile.y + 1 ) * 256);
  var northEastPixel = new GPoint( ( tile.x + 1 ) * 256, tile.y * 256);
  var southWestCoords = G_NORMAL_MAP.getProjection().fromPixelToLatLng( southWestPixel, zoom );
  var northEastCoords = G_NORMAL_MAP.getProjection().fromPixelToLatLng( northEastPixel, zoom );
  var bbox = southWestCoords.lng() + ',' + southWestCoords.lat() + ',' + northEastCoords.lng() + ',' + northEastCoords.lat();
  return this.baseUrl + '?VERSION=1.1.1&REQUEST=GetMap&LAYERS=' + this.layer + '&STYLES=&SRS=EPSG:4326&BBOX=' + bbox + '&WIDTH=256&HEIGHT=256&FORMAT=image/jpeg&BGCOLOR=0xCCCCCC&EXCEPTIONS=INIMAGE';
 }
   /////////////////////////////////////////

 var WMS_TOPO_MAP;
 var WMS_DOQ_MAP;

 function HAddTopo(){
  WMS_TOPO_MAP = WMSCreateMap( 'Topo - MS', 'Imagery by USGS / Web Service by TerraServer',
   'http://msrmaps.com/ogcmap6.ashx', 'DRG', 4, 17, 't' );
//   'http://www.terraserver-usa.com/ogcmap6.ashx', 'DRG', 4, 17, 't' );
  WMS_DOQ_MAP = WMSCreateMap( 'Satellite - MS', 'Imagery by USGS / Web Service by TerraServer',
   'http://msrmaps.com/ogcmap6.ashx', 'DOQ', 4, 18, 'o' );
//   'http://www.terraserver-usa.com/ogcmap6.ashx', 'DOQ', 4, 18, 'o' );

  HMapTypes.push(G_NORMAL_MAP);
  HMapTypes.push(G_PHYSICAL_MAP);
  HMapTypes.push(G_HYBRID_MAP);
  HMapTypes.push(G_SATELLITE_3D_MAP);
  HMapTypes.push(WMS_TOPO_MAP);
  //   HMapTypes.push(USGSMapUrban('Urban'));
  HMapTypes.push(G_SATELLITE_MAP);
  HMapTypes.push(WMS_DOQ_MAP);
 }
   //////////// Map Types End /////////////////////////////

 function HAddControls() {
  map.addControl(new GLargeMapControl3D());
  map.addControl(new GMapTypeControl());
  scale = new GScaleControl();
  scale.printable=function(){return true};
  map.addControl(scale);

  if (typeof(HShowSizeControl) != undefined && typeof(HSizeControl) == 'function') map.addControl(new HSizeControl(null, 'icons'));
 }

 function HOnLoadList() {
  for (var i=0; i < HonLoadListB.length; i++) {
   HonLoadListB[i]();
  }
  for (var i=0; i < HonLoadListA.length; i++) {
   HonLoadListA[i]();
  }
 }

 window.onload = HOnLoadList;
 window.onunload = HonUnloadList;

 function HFixCheckBox(){ // I don't know why, but Firefox 2 seems to need these when page reloaded after displaying a graph.  Also it moves the check from one trail to the next????
  var b = document.getElementById('HDet');
  if (b) b.checked = 0;
  var b = document.getElementById('HMiles');
  if (b) b.checked = 1;
 }
//hmar = createMarker({"latitude":43.0067, "longitude":-77.4747, "abbr":"Hello!"}); //??????testing
//map.addOverlay(hmar);                                                             //??????
 function createMarker(pointData) {
  var latlng = new GLatLng(pointData.latitude, pointData.longitude);
  var icon = new GIcon();
  icon.iconAnchor = new GPoint(16, 16);
  icon.infoWindowAnchor = new GPoint(25, 7);

  opts = {
   "icon": icon,
   "labelText": pointData.abbr,
   "labelOffset": new GSize(-16, -16)
  };
  var marker = new LabeledMarker(latlng, opts);

  return marker;
 }

 function Hjscss(a,o,c1,c2) {
  switch (a){
   case 'swap':
    o.className=!Hjscss('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
   break;
   case 'add':
    if(!Hjscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
   break;
   case 'remove':
    var rep=o.className.match(' '+c1)?' '+c1:c1;
     o.className=o.className.replace(rep,'');
   break;
   case 'check':
     return new RegExp('\\b'+c1+'\\b').test(o.className)
   break;
  }
 }

////// Trails ////////

var HNNum = 0;
var HOverlayList = [];
var HTrails = [];
var HMarkerMsg = [];
var HOverlayDisplay = [];
var HPoiList = [];
var HTrailInfo = '';
var HLastClickPoint= '';

function HPts(a1,a2) {  // from (string of lat, lon,[waypoint,] ...) or arguments, returns arrays of Gpoints, waypoints, waypoint number to point number
 var r = new Array;
 var p = new Array;
 var wp = new Array;
 var n = new Array;
 var np = 0;
 var nwp = 0;
 if (!a2) {
  a = a1.split(",");
  for(i=0;i<a.length;i++){
   if(isNaN(a[i])) {
    wp[nwp]=np;
    n[nwp] = a[i];
    nwp++;
    continue;
   }
   p[np] = new GLatLng(parseFloat(a[i]), parseFloat(a[++i]));
   np++;
  }
 }
 else for(i=0;i<arguments.length;i++){
  if(isNaN(arguments[i])) continue;
  p[np] = new GLatLng(parseFloat(arguments[i]), parseFloat(arguments[++i]));
  np++;
 }
 r[0] = p;
 r[1] = wp;
 r[2] = n;
 return r;
}

function HAddSeg(path,seg,lhtml) {
 lhtml = lhtml || 1;
 var t = '';
 var told = '';
 HFlag = "!";
 for (var i=0;i<path.length;i++) {
  told = t;
  t += '["' + path[i] + '"]';
  f = 'HTrailLists' + t;
  try {
   eval (f  + " += ['" + HFlag + "']")
  }
  catch(e) {
   eval ('HTrailLists' + told + "= []")
   eval (f  + " += ['" + HFlag + "']")
  }
 }
 f[f.length] = seg;
 HTrails[seg] = path[path.length-1];
}

function HAddOverlays(off) {
 if (off == undefined) off = 1;

 for(var i in HOverlayList){
  HOverlayDisplay[i]=0;
  if(!off) map.addOverlay(HOverlayList[i]);
  if(HMarkerMsg[i])HAddMsg(i);
 }
}

function HShowAll(start) {
 for (var trail in HOverlayList) {
  if (!HOverlayDisplay[trail]) map.addOverlay(HOverlayList[trail]);
  HOverlayDisplay[trail] = 1;
 }

 var c = document.getElementsByName('showt');
 for (var i=0;i<c.length;i++) {
  c.item(i).checked = 1;
 }
 for (var p in HPoiList) {
  if (!HOverlayDisplay[p]) map.addOverlay(HPoiList[p]);
  HOverlayDisplay[p] = 1;
 }
 if (start == 1) {
  for (var i=0;i<c.length;i++) {
   if (c.item(i).className == 'cb_POI') c.item(i).click();
  }
 }
}

////// Markers /////

var HInfoMarker = new GIcon();
HInfoMarker.image = "./icons/marker_i.png";
HInfoMarker.shadow = "./icons/shadow50.png";
HInfoMarker.transparent = "./icons/marker_transparent.png";
HInfoMarker.imageMap = [1,8, 4,4, 1,8, 1,14, 18,4, 20,8, 20,13, 12,24, 8,24, 1,13];
HInfoMarker.iconSize = new GSize(20, 34);
HInfoMarker.shadowSize = new GSize(37, 34);
HInfoMarker.iconAnchor = new GPoint(10, 34);
HInfoMarker.infoWindowAnchor = new GPoint(10, 10);

var HParkingMarker = new GIcon();
HParkingMarker.image = "./icons/p_green.png";
HParkingMarker.shadow = "./icons/p_shadow.png";
HParkingMarker.transparent = "./icons/marker_transparent.png";
HParkingMarker.imageMap = [1,8, 4,4, 1,8, 1,14, 18,4, 20,8, 20,13, 12,24, 8,24, 1,13];
HParkingMarker.iconSize = new GSize(20, 20);
HParkingMarker.shadowSize = new GSize(30, 20);
HParkingMarker.iconAnchor = new GPoint(10, 20);
HParkingMarker.infoWindowAnchor = new GPoint(10, 10);

var HNoParkingMarker = new GIcon();
HNoParkingMarker.image = "./icons/p_green-no.png";
HNoParkingMarker.shadow = "./icons/p_shadow.png";
HNoParkingMarker.transparent = "./icons/marker_transparent.png";
HNoParkingMarker.imageMap = [1,8, 4,4, 1,8, 1,14, 18,4, 20,8, 20,13, 12,24, 8,24, 1,13];
HNoParkingMarker.iconSize = new GSize(20, 20);
HNoParkingMarker.shadowSize = new GSize(30, 20);
HNoParkingMarker.iconAnchor = new GPoint(10, 20);
HNoParkingMarker.infoWindowAnchor = new GPoint(10, 10);

var HxMarker = new GIcon();
HxMarker.image = "./icons/marker_x_yellow.png";
HxMarker.iconSize = new GSize(20, 20);
HxMarker.iconAnchor = new GPoint(10, 10);
HxMarker.infoWindowAnchor = new GPoint(10, 10);

var HSqMarker = new GIcon();
HSqMarker.image = "./icons/rmarker_blank.png";
HSqMarker.shadow = "./icons/rmarker_shadow.png";
HSqMarker.transparent = "./icons/rmarker_transparent.png";
HSqMarker.imageMap = [3,1, 27,1, 27,20, 3,20];
HSqMarker.iconSize = new GSize(28, 28);
HSqMarker.shadowSize = new GSize(40, 28);
//HSqMarker.iconAnchor = new GPoint(10, 34);
HSqMarker.iconAnchor = new GPoint(10, 28);
HSqMarker.infoWindowAnchor = new GPoint(10, 10);


function HCreateMarker(name,image,base) {
 if(base == null || base == '') base = "HInfoMarker";
 eval(name + " = new GIcon(" + base + ");");
 eval(name + ".image = './icons/" + image + "';");
}

HCreateMarker("HTrailMarker","marker_t.png");
HCreateMarker("HOtherMarker","marker_o.png");
HCreateMarker("HParkMarker","marker_p.png");
HCreateMarker("HSponsorMarker","marker_s.png");
HCreateMarker("HHikeMarker","marker_h.png");

HCreateMarker("HParkingMarker","p_green.png",'HParkingMarker');
HCreateMarker("HNoParkingMarker","p_green-no.png",'HNoParkingMarker');

HCreateMarker("HRedXMarker","flat_x_red.png",'HxMarker');
HCreateMarker("HYellowXMarker","flat_x_yellow.png",'HxMarker');

HCreateMarker("HEMarker","iconE.png");
HCreateMarker("HWPMarker","marker_w.png");
HCreateMarker("HQmMarker","marker_qm.png");

HCreateMarker("HStopMarker","marker_stop.png");
HCreateMarker("HCautionMarker","marker_caution.png");

HCreateMarker("HGreenMarker","marker_green.png");

HCreateMarker("HWaterTrailMarker","marker_t_light_blue.png");
HCreateMarker("HLaunchMarker","marker_l_light_blue.png");

HCreateMarker("HCrossMarker","marker_intersection.png");
HCreateMarker("HRightMarker","marker_right.png");
HCreateMarker("HLeftMarker","marker_left.png");
HCreateMarker("HTeeMarker","marker_tee.png");
HCreateMarker("HStraightMarker","marker_straight.png");

////// Numeric Markers /////

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon();
 baseIcon.shadow = "./icons/shadow50.png";
 baseIcon.transparent = "./icons/marker_transparent.png";
 baseIcon.imageMap = [1,8, 4,4, 1,8, 1,14, 18,4, 20,8, 20,13, 12,24, 8,24, 1,13];
 baseIcon.iconSize = new GSize(20, 34);
 baseIcon.shadowSize = new GSize(37, 34);
 baseIcon.iconAnchor = new GPoint(9, 34);
 baseIcon.infoWindowAnchor = new GPoint(9, 2);
 baseIcon.infoShadowAnchor = new GPoint(18, 25);

var HLastIndex = -1;

function HCreateNumMarker(point, index, preload) {
  // Create a numbered icon for this point using our icon class
  if (index==='') index = HLastIndex++;
  if (index > 99) {
   if (index % 100 == 0) index = '00'
   else index = index % 100
  }
  if (index > 10) {
   var u = index % 10
   if (u != 0) index = u
  }
  var image = "./icons/icon" + index + ".png";
  var marker;
  if (!preload) {
   var icon = new GIcon(baseIcon);
   icon.image = image
   HLastIndex = index;
   marker = new GMarker(point, {icon: icon, clickable: false});
   HNumM[index] = marker;
   HCreateNumMarker(point, index+1, 1);
  }
  else {
   document.getElementById('HPreLoad').src = image
   marker = '';
  }
  return marker;
}

 ///////// PRINT BUTTON ////////
function HPrintShow(){
 Hjscss('remove',document.getElementById("HRemoveMe"),'HHide');
 Hjscss('remove',document.getElementById("HmapDivCaption"),'HHide');
 Hjscss('add',document.getElementById("HPrintB"),'HHide');
 HLandscape();
 Hjscss('add',document.getElementById("HPrintIt"),'HSolidBorder');
}
function HPrintHide(){
 Hjscss('add',document.getElementById("HRemoveMe"),'HHide');
 Hjscss('add',document.getElementById("HmapDivCaption"),'HHide');
 Hjscss('remove',document.getElementById("HPrintB"),'HHide');
 Hjscss('remove',document.getElementById("HPrintIt"),'HSolidBorder');
}
