var BASE_ADDRESS                  = 'http://livesteamtracks.info';
var CLUB_EXACT_ICON               = 'images/icons/club-exact.png';
var CLUB_ICON                     = 'images/icons/club.png';
var HISTORICAL_SOCIETY_EXACT_ICON = 'images/icons/historical-society-exact.png';
var HISTORICAL_SOCIETY_ICON       = 'images/icons/historical-society.png';
var MUSEUM_EXACT_ICON             = 'images/icons/museum-exact.png';
var MUSEUM_ICON                   = 'images/icons/museum.png';
var PARK_EXACT_ICON               = 'images/icons/park-exact.png';
var PARK_ICON                     = 'images/icons/park.png';
var PRIVATE_EXACT_ICON            = 'images/icons/private-exact.png';
var PRIVATE_ICON                  = 'images/icons/private.png';
var SUPPLIER_ICON                 = 'images/icons/supplier.png';
var TBD_ICON                      = 'images/icons/tbd.png';
var MENU_TIMEOUT                  = 2000;
var VIEW_EXACT_ICON               = 'images/icons/view-exact.png';

var adMinimized      = false;
var allGauges        = true;
var debug            = false;
var gaugeChangeMade  = false;
var groupLineLength  = 60;
var initialID        = 'US';
var initialSelectID  = -1;
var initialSelectSID = -1;
var map              = null;
var names            = new Array();
var sequence         = 0;
var suppliersOption  = false;
var topBar1          = '';
var trackCount       = 0;
var values           = new Array();
var variables        = '';
var xmlDoc           = null;
//var zoomInEnabled    = true;
var zoomOut          = 0;

var ad  = 0;
var ads = new Array();
ads[ad++] = new objAd('ad1','bryterails',false);
ads[ad++] = new objAd('ad2','homerailwayjournal',true);
ads[ad++] = new objAd('ad3','bryterails2',false);
ads[ad++] = new objAd('ad4','bryterails',false);
ads[ad++] = new objAd('ad5','homerailwayjournal',true);
ads[ad++] = new objAd('ad6','bryterails2',false);

var button  = 0;
var buttons = new Array();
buttons[button++] = new objButton('contactUs','contactus');
buttons[button++] = new objButton('linklist','links');
buttons[button++] = new objButton('list','list');
buttons[button++] = new objButton('logo','logo');
buttons[button++] = new objButton('minMax','minmax');
buttons[button++] = new objButton('update1','update');
buttons[button++] = new objButton('update2','update');
//buttons[button++] = new objButton('zoomIn','zoomin');
//buttons[button++] = new objButton('zoomOut','zoomout');

var country   = 0;
var countries = new Array();
countries[country++] = new objCountry('af','AF');  // Africa
countries[country++] = new objCountry('au','AU');  // Australia
countries[country++] = new objCountry('at','AT');  // Austria
countries[country++] = new objCountry('be','BE');  // Belgium
countries[country++] = new objCountry('ca','CA');  // Canada
countries[country++] = new objCountry('fr','FR');  // France
countries[country++] = new objCountry('gr','GR');  // Germany
countries[country++] = new objCountry('hu','HU');  // Hungary
countries[country++] = new objCountry('in','IN');  // India
countries[country++] = new objCountry('jp','JP');  // Japan
countries[country++] = new objCountry('nl','NL');  // Netherlands
countries[country++] = new objCountry('nz','NZ');  // New Zealand
countries[country++] = new objCountry('es','ES');  // Spain
countries[country++] = new objCountry('ch','CH');  // Switzerland
countries[country++] = new objCountry('uk','UK');  // United Kingdom
countries[country++] = new objCountry('us','US');  // United States

var gauge  = 0;
var gauges = new Array();
gauges[gauge++] = new objGauge('g2p5','2&frac12;','2&frac12;');
gauges[gauge++] = new objGauge('g3p5','3&frac12;','3&frac12;');
gauges[gauge++] = new objGauge('g4p75','4&frac34;','4&frac34;');
gauges[gauge++] = new objGauge('g5p0','5','5');
gauges[gauge++] = new objGauge('g7p25','7&frac14;','7&frac14;');
gauges[gauge++] = new objGauge('g7p5','7&frac12;','7&frac12;');
gauges[gauge++] = new objGauge('g8p25','8&frac14;','8&frac14;');
gauges[gauge++] = new objGauge('g8p75','8&frac34;','8&frac34;');
gauges[gauge++] = new objGauge('g10p0','10','10');
gauges[gauge++] = new objGauge('g10p25','10&frac14;','10&frac14;');
gauges[gauge++] = new objGauge('g10p5','10&frac12;','10&frac12;');
gauges[gauge++] = new objGauge('g12p0','12','12');
gauges[gauge++] = new objGauge('g14p0','14','14');
gauges[gauge++] = new objGauge('g15p0','&gt;15','15');

var legend  = 0;
var legends = new Array();
legends[legend++] = new objLegend('club-exact.png','Club (Exact location)');
legends[legend++] = new objLegend('club.png','Club (Approximate location)');
legends[legend++] = 
   new objLegend(
      'historical-society-exact.png','Historical Society (Exact location)');
legends[legend++] = 
   new objLegend(
      'historical-society.png','Historical Society (Approximate location)');
legends[legend++] = new objLegend('museum-exact.png','Museum (Exact location)');
legends[legend++] = new objLegend('museum.png','Museum (Approximate location)');
legends[legend++] = new objLegend('park-exact.png','Park (Exact location)');
legends[legend++] = new objLegend('park.png','Park (Approximate location)');
legends[legend++] = 
   new objLegend('private-exact.png','Privately Owned (Exact location)');
legends[legend++] = 
   new objLegend('private.png','Privately Owned (Approximate location)');
legends[legend++] = new objLegend('supplier.png','Supplier');
legends[legend++] = new objLegend('view-exact.png','Viewing (Exact location)');
legends[legend++] = new objLegend('tbd.png','Unknown');

var markerInfos = new Array();

function addGauge(gauge,gaugeLength) {
   var string = '';

   if(gaugeLength.length > 0) {
      string = 
         '<tr><td><table cellpadding="0" cellspacing="0"><tbody>' + 
         '<tr>' + 
         '<td class="popupGauge"><img src="images/icons/bullet.gif"/></td>' + 
         '<td class="popupGauge">' + gauge + ' -- ' + gaugeLength + 
         '</td></tr>' + 
         '</tbody></table></td></tr>';
   }

   return(string);
}

function addLink(text,link,target) {
   return(
      '<tr>' + 
      '<td class="borderMiddle1"/>' + 
      '<td class="links">' + 
      '<img src="images/icons/bullet.gif"/>' + 
      '<a href="' + link + '" target="' + target + '">' + text + '</a></td>' + 
      '<td class="borderMiddle3"/></tr>');
}

function addMarker(marker) {
   var address1    = getMarkerAttribute(marker,"a1","");
   var address2    = getMarkerAttribute(marker,"a2","");
   var child       = '';
   var children    = marker.childNodes;
   var city        = getMarkerAttribute(marker,"ci","");
   var country1    = getMarkerAttribute(marker,"co","");
   var country2    = '';
   var description = '';
   var email       = '';
   var exact       = getMarkerAttribute(marker,"e","");
   var g2p5inch    = '';
   var g3p5inch    = '';
   var g4p75inch   = '';
   var g5p0inch    = '';
   var g7p25inch   = '';
   var g7p5inch    = '';
   var g8p25inch   = '';
   var g8p75inch   = '';
   var g10p0inch   = '';
   var g10p25inch  = '';
   var g10p5inch   = '';
   var g12p0inch   = '';
   var g14p0inch   = '';
   var g15p0inch   = '';
   var g16p0inch   = '';
   var g18p0inch   = '';
   var g18p5inch   = '';
   var g19p0inch   = '';
   var g20p0inch   = '';
   var g24p0inch   = '';
   var g30p0inch   = '';
   var g36p0inch   = '';
   var gfs         = '';
   var groupLine1  = '';
   var groupLine2  = '';
   var gs          = 'false';
   var icon        = '';
   var id1         = '';
   var id2         = '';
   var include     = (allGauges) ? true : false;
   var label1      = '';
   var label2      = '';
   var lat         = parseFloat(getMarkerAttribute(marker,"lat",""));
   var length      = 0;
   var logo1       = 'TBD';
   var logo2       = 'TBD';
   var lng         = parseFloat(getMarkerAttribute(marker,"lng",""));
   var name1       = '';
   var name2       = '';
   var name3       = '';
   var name4       = '';
   var nodeName    = '';
   var nodeValue   = '';
   var notes       = '';
   var phone       = '';
   var s1p0inch    = '';
   var s1p5inch    = '';
   var s2p5inch    = '';
   var shape       = '';
   var state1      = getMarkerAttribute(marker,"s1","");
   var state2      = getMarkerAttribute(marker,"s2","");
   var state3      = '';
   var title       = '';
   var type1       = '';
   var type2       = '';
   var url1        = '';
   var url2        = '';
   var zip         = getMarkerAttribute(marker,"zi","");
   var zoomIn      = getMarkerAttribute(marker,"zo","18");

   //----- Parse out the XML components
   for(var x=0; x<children.length; x++) {
      child    = children[x];
      nodeName = child.nodeName;

//    if(debug) {
//       if(nodeName == 'id1') {
//          if(getMarkerAttribute(marker,"logo","false") == "true") {
//             doAlert("logo=" + getMarkerAttribute(marker,"logo","false"));
//          }
//       }
//    }

      if(children[x].firstChild != null) {
         child     = children[x];
         nodeName  = child.nodeName;
         nodeValue = child.firstChild.nodeValue;

         if(nodeName == 'a1') {
            address1 = nodeValue;
         }
         else if(nodeName == 'a2') {
            address2 = nodeValue;
         }
         else if(nodeName == 'e') {
            email = nodeValue;
         }
         else if(nodeName == 'g2p5') {
            g2p5inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g3p5') {
            g3p5inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g4p75') {
            g4p75inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g5p0') {
            g5p0inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g7p25') {
            g7p25inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g7p5') {
            g7p5inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g8p25') {
            g8p25inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g8p75') {
            g8p75inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g10p0') {
            g10p0inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g10p25') {
            g10p25inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g10p5') {
            g10p5inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g12p0') {
            g12p0inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g14p0') {
            g14p0inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g15p0') {
            g15p0inch = nodeValue;
            if(getGauge(nodeName).option) {
               include = true;
            }
         }
         else if(nodeName == 'g16p0') {
            g16p0inch = nodeValue;
            if(getGauge('g15p0').option) {
               include = true;
            }
         }
         else if(nodeName == 'g18p0') {
            g18p0inch = nodeValue;
            if(getGauge('g15p0').option) {
               include = true;
            }
         }
         else if(nodeName == 'g18p5') {
            g18p5inch = nodeValue;
            if(getGauge('g15p0').option) {
               include = true;
            }
         }
         else if(nodeName == 'g19p0') {
            g19p0inch = nodeValue;
            if(getGauge('g15p0').option) {
               include = true;
            }
         }
         else if(nodeName == 'g20p0') {
            g20p0inch = nodeValue;
            if(getGauge('g15p0').option) {
               include = true;
            }
         }
         else if(nodeName == 'g24p0') {
            g24p0inch = nodeValue;
            if(getGauge('g15p0').option) {
               include = true;
            }
         }
         else if(nodeName == 'g30p0') {
            g30p0inch = nodeValue;
            if(getGauge('g15p0').option) {
               include = true;
            }
         }
         else if(nodeName == 'g36p0') {
            g36p0inch = nodeValue;
            if(getGauge('g15p0').option) {
               include = true;
            }
         }
         else if(nodeName == 'gfs') {
            gfs = nodeValue;
            if(getGauge('g15p0').option) {
               include = true;
            }
         }
         else if(nodeName == 'gs') {
            gs = nodeValue;
         }
         else if(nodeName == 'id1') {
            id1 = nodeValue;
            if(getMarkerAttribute(child,'l','0') == '1') {
               logo1 = id1;
            }
         }
         else if(nodeName == 'id2') {
            id2 = nodeValue;
            if(getMarkerAttribute(child,'l','0') == '1') {
               logo2 = id2;
            }
         }
         else if(nodeName == 'l1') {
            label1 = nodeValue;
         }
         else if(nodeName == 'l2') {
            label2 = nodeValue;
         }
         else if(nodeName == 'n1') {
            name1 = nodeValue;
         }
         else if(nodeName == 'n2') {
            name2 = nodeValue;
         }
         else if(nodeName == 'n3') {
            name3 = nodeValue;
         }
         else if(nodeName == 'n4') {
            name4 = nodeValue;
         }
         else if(nodeName == 'n') {
            notes = nodeValue;
         }
         else if(nodeName == 'p') {
            phone = nodeValue;
         }
         else if(nodeName == 's1p0') {
            s1p0inch = nodeValue;
         }
         else if(nodeName == 's1p5') {
            s1p5inch = nodeValue;
         }
         else if(nodeName == 's2p5') {
            s2p5inch = nodeValue;
         }
         else if(nodeName == 't') {
            type1 = nodeValue;
            if(type1 == 'country' || type1 == 'group' || type1 == 'state') {
               include = true;
            }
         }
         else if(nodeName == 'u1') {
            url1 = nodeValue;
         }
         else if(nodeName == 'u2') {
            url2 = nodeValue;
         }
      }
   }

   if(state2 != '') {
      state1 = state2;
   }

   if(type1 == 'supplier') {
      include = (suppliersOption) ? true : false;
   }

   //----- Translate the state and country from the abbreviations
   country2 = translateCountry(country1);
   state3   = translateState  (state1,country2);

   //----- Add to the pulldown menu
   if(include) {
      topBar1 += '<option value="' + sequence + '"';
      if(id1 == initialID || id2 == initialID) {
         topBar1 += ' selected="selected"';
      }
      topBar1 += '>';
      if(type1 == 'country' || type1 == 'group' || type1 == 'state') {
         groupLine2 = '';
         groupLine1 = ' ' + country2;
         if(state1 != '_' && state3.length > 0) {
            groupLine1 += ' - ' + state3;
         }
         groupLine1 += ' ';

         if((length = groupLineLength - groupLine1.length) > 0) {
            length = Math.round(length / 2);
            for(var x=0; x<length; x++) {
               groupLine2 += '-';
            }
            groupLine2 += groupLine1;
            if((length = groupLineLength - groupLine2.length) > 0) {
               for(var x=0; x<length; x++) {
                  groupLine2 += '-';
               }
            }
         }
         topBar1 += groupLine2;
      }
      else if(type1 == 'view') {
         topBar1 += '*** ' + name1 + ' ***';
      }
      else {
         topBar1 += name1;
      }
      topBar1 += '</option>';
   }

   if(type1 != 'country' && type1 != 'group' && type1 != 'state' && include) {
      if(type1 == 'supplier') {
         type2 = 'Supplier';
         icon  = SUPPLIER_ICON;
      }
      else if(type1 == 'view') {
         type2 = 'Train Viewing';
         icon  = VIEW_EXACT_ICON;
      }
      else {
         if(type1 == 'club') {
            type2 = 'Club Track';
            if(exact == '1') {
               if(gs == 'true') {
                  icon = CLUB_EXACT_ICON;
               }
               else {
                  icon = CLUB_EXACT_ICON;
               }
            }
            else {
               if(gs == 'true') {
                  icon = CLUB_ICON;
               }
               else {
                  icon = CLUB_ICON;
               }
            }
         }
         else if(type1 == 'hs') {
            type2 = 'Historical Society';
            if(exact == '1') {
               icon = HISTORICAL_SOCIETY_EXACT_ICON;
            }
            else {
               icon = HISTORICAL_SOCIETY_ICON;
            }
         }
         else if(type1 == 'museum') {
            type2 = 'Museum';
            if(exact == '1') {
               icon = MUSEUM_EXACT_ICON;
            }
            else {
               icon = MUSEUM_ICON;
            }
         }
         else if(type1 == 'park') {
            type2 = 'Park Track';
            if(exact == '1') {
               icon = PARK_EXACT_ICON;
            }
            else {
               icon = PARK_ICON;
            }
         }
         else if(type1 == 'private') {
            type2 = 'Privately Owned Track';
            if(exact == '1') {
               icon = PRIVATE_EXACT_ICON;
            }
            else {
               icon = PRIVATE_ICON;
            }
         }
         else {
            type2 = type1;
            icon  = TBD_ICON;
         }

//       window.status = (++trackCount) + ' tracks loaded';
         trackCount++;
      }

      //----- Build the title
      title += '<table class="popup">';
      if(logo1 != 'TBD') {
         title += 
            '<tr><td>' + 
            '<table cellpadding="0" cellspacing="0">' + 
            '<tr><td><img height="75" src="logos/' + logo1 + 
            '.jpg" width="75"/></td>';
         if(logo2 != 'TBD') {
            title += 
               '<td><img height="75" src="logos/' + logo2 + 
               '.jpg" width="75"/></td>';
         }
         title += '</tr></table></td></tr>';
      }
      if(type2.length > 0) {
         title += '<tr><td class="popupType">' + type2 + '</td></tr>';
      }
      title += '<tr><td class="gap" nowrap="1"/></tr>';
      title += '<tr><td class="popupTitle">';
      if(url1.length > 0) {
         title += 
            '<a href="http://' + url1 + '" target="' + 
            ((id1.length > 0) ? id1 : 'zzz') + '2">';
      }
      title += name1;
      if(label1.length > 0) {
         title += ' (' + label1 + ')';
      }
      if(url1.length > 0) {
         title += '</a>';
      }
      if(url2.length > 0) {
         title += 
            '<br/>(<a href="http://' + url2 + '" target="' + 
            ((id1.length > 0) ? id1 : 'zzz') + '2">Alternate Link</a>)';
      }
      if(name2.length > 0) {
         title += '<br/>' + name2;
      }
      if(name3.length > 0) {
         title += '<br/>' + name3;
      }
      if(name4.length > 0) {
         title += '<br/>' + name4;
      }
      title += '</td></tr></table>';

      //----- Build the description
      description = '<table class="popup">';
      if(address1.length > 0) {
         description += 
            '<tr><td class="popupAddress">' + address1 + '</td></tr>';
         if(address2.length > 0) {
            description += 
               '<tr><td class="popupAddress">' + address2 + '</td></tr>';
         }
      }
      if(city.length > 0 || state3.length > 0 || zip.length > 0) {
         description += '<tr><td class="popupAddress">';
         if(city.length > 0) {
            description += city;
            if(state1 != '_' && state3.length > 0) {
               description += ', ';
            }
         }
         if(state1 != '_' && state3.length > 0) {
            description += state3;
         }
         if((city.length > 0 || state3.length > 0) && zip.length > 0) {
            description += '  ';
         }
         if(zip.length > 0) {
            description += zip;
         }
         if(country2.length > 0) {
            description += ' ' + country2;
         }
         description += '</td></tr>';
      }
      if(email.length > 0) {
         description += 
            '<tr><td class="gap" nowrap="1"/></tr>' + 
            '<tr><td class="popupExtra"><img src="images/icons/email.gif"/>' + 
            '<a href="mailto:' + email + '">' + email + '</a></td></tr>';
      }
      if(phone.length > 0) {
         description += 
            '<tr><td class="gap" nowrap="1"/></tr>' + 
            '<tr><td class="popupExtra"><img src="images/icons/phone.jpg"/>' + 
            phone + '</td></tr>';
      }
      description += '<tr><td class="gap" nowrap="1"/></tr>';
      description += 
         addGauge(
            '2&frac12;&quot; (1/5) scale',s2p5inch);
      description += 
         addGauge(
            '1&frac12;&quot; (1/8) scale',s1p5inch);
      description += 
         addGauge(
            '1&quot; (1/12) scale',s1p0inch);
      description += 
         addGauge(
            'full size',gfs);
      description += 
         addGauge(
            '36&quot; gauge',g36p0inch);
      description += 
         addGauge(
            '30&quot; gauge',g30p0inch);
      description += 
         addGauge(
            '24&quot; gauge',g24p0inch);
      description += 
         addGauge(
            '20&quot; gauge',g20p0inch);
      description += 
         addGauge(
            '19&quot; gauge',g19p0inch);
      description += 
         addGauge(
            '18&frac12;&quot; gauge',g18p5inch);
      description += 
         addGauge(
            '18&quot; gauge',g18p0inch);
      description += 
         addGauge(
            '16&quot; gauge',g16p0inch);
      description += 
         addGauge(
            '15&quot; gauge (1/4)',g15p0inch);
      description += 
         addGauge(
            '14&quot; gauge (1/4)',g14p0inch);
      description += 
         addGauge(
            '12&quot; gauge',g12p0inch);
      description += 
         addGauge(
            '10&frac12;&quot; gauge',g10p5inch);
      description += 
         addGauge(
            '10&frac14;&quot; gauge',g10p25inch);
      description += 
         addGauge(
            '10&quot; gauge',g10p0inch);
      description += 
         addGauge(
            '8&frac34;&quot; gauge',g8p75inch);
      description += 
         addGauge(
            '8&frac14;&quot; gauge',g8p25inch);
      description += 
         addGauge(
            '7&frac12;&quot; gauge (1/8 or 1&frac12;&quot; scale)',
            g7p5inch);
      description += 
         addGauge(
            '7&frac14;&quot; gauge (1/8 or 1&frac12;&quot; scale)',
            g7p25inch);
      description += 
         addGauge(
            '5&quot; gauge (1/12)',g5p0inch);
      description += 
         addGauge(
            '4&frac34;&quot; gauge (1/12 or 1&quot; scale)',g4p75inch);
      description += 
         addGauge(
            '3&frac12;&quot; gauge (1/16 or &frac34;&quot; scale)',
            g3p5inch);
      description += 
         addGauge(
            '2&frac12;&quot; gauge (1/24 or &frac12;&quot; scale)',
            g2p5inch);
      if(notes.length > 0) {
         description += 
            '<tr><td class="gap" nowrap="1"/></tr>' + 
            '<tr><td class="popupExtra">(<b>' + notes + '</b>)</td></tr>';
      }
      if(exact == '1' || exact == '2') {
         if(exact == '2') {
            description += 
               '<tr><td class="gap" nowrap="1"/></tr>' + 
               '<tr><td class="popupExact">' + 
               '(<b>This location is marked as the start for ' + 
               'directions</b>)</td></tr>';
         }

         description += 
            '<tr><td class="gap" nowrap="1"/></tr>' + 
            '<tr><td class="popupHeading">Direct:</td></tr>' + 
            '<tr><td class="popupExact">' + 
            '<input class="popupDirectURL" type="text" value="' + 
            BASE_ADDRESS + '/?markerid=' + id1 + '"/></td></tr>' + 
            '<tr><td class="gap" nowrap="1"/></tr>' + 
            '<tr><td class="popupHeading">GPS:</td></tr>' + 
            '<tr><td class="popupExact">' + 
            '<input class="popupGPS" readonly type="text" value="' + 
            lat + ',' + lng + '"/></td></tr>' + 
            '<tr><td class="gap" nowrap="1"/></tr>' + 
            '<tr><td valign="top">' + 
            '<input class="popupButton" onclick="selectItem(' + sequence + 
            ');"' + 
            ' onmouseout="this.style.cursor = \'Auto\';"' + 
            ' onmouseover="this.style.cursor = \'Hand\';"' + 
            ' title="Zoom down to this marker" type="button"' + 
            ' value="Zoom In"/>';

         if(exact == '1' && type1 != 'view') {
            description += 
               '&nbsp;' + 
               '<input class="popupButton"' + 
               ' onclick="openGE(\'' + BASE_ADDRESS + '/ge/' + country1 + 
               '.kmz\');"' + 
               ' onmouseout="this.style.cursor = \'Auto\';"' + 
               ' onmouseover="this.style.cursor = \'Hand\';"' + 
               ' title="Opens this map in Google Earth" type="button"' + 
               ' value="Google Earth"/>';
         }

//         if(exact == '1' || exact == '2') {
//            description += 
//               '&nbsp;' + 
//               '<input class="popupButton"' + 
//               ' onclick="openGM(' + lat + ',' + lng + ',' + zoomIn + ');"' + 
//               ' onmouseout="this.style.cursor = \'Auto\';"' + 
//               ' onmouseover="this.style.cursor = \'Hand\';"' + 
//               ' title="Opens this map in Google Maps" type="button"' + 
//               ' value="Google Maps"/>';
//         }

//         if(exact == '1' && (country1 == 'US' || country1 == 'USS')) {
//            description += 
//               '&nbsp;' + 
//               '<input class="popupButton"' + 
//               ' onclick="openTS(' + lat + ',' + lng + ');"' + 
//               ' onmouseout="this.style.cursor = \'Auto\';"' + 
//               ' onmouseover="this.style.cursor = \'Hand\';"' + 
//               ' title="Opens this map in TerraServer" type="button"' + 
//               ' value="TerraServer"/>';
//         }

         if(exact == '1') {
            description += 
               '&nbsp;' + 
               '<input class="popupButton"' + 
               ' onclick="openWM(' + lat + ',' + lng + ');"' + 
               ' onmouseout="this.style.cursor = \'Auto\';"' + 
               ' onmouseover="this.style.cursor = \'Hand\';"' + 
               ' title="Opens this map in WikiMapia" type="button"' + 
               ' value="WikiMapia"/>';

            description += 
               '&nbsp;' + 
               '<input class="popupButton"' + 
               ' onclick="openPOI(\'' + country1 + '\',\'' + state1 + '\',\'' + 
               name1 + '\');"' + 
               ' onmouseout="this.style.cursor = \'Auto\';"' + 
               ' onmouseover="this.style.cursor = \'Hand\';"' + 
               ' title="Opens/downloads a POI file" type="button"' + 
               ' value="POI"/>';
         }

         description += '</td></tr>';
      }
      else {
         description += 
            '<tr><td class="gap" nowrap="1"/></tr>' + 
            '<tr><td class="popupExact">' + 
            '(<b>Exact map location unknown</b>)</td></tr>';
      }
      description += '</table>';

      //----- Add the image to the map
      shape = new VEShape(VEShapeType.Pushpin,new VELatLong(lat,lng));
//    shape.SetPhotoURL("http://dev.live.com/Themes/default/images/Mix08/service/logo_virtualearth.jpg");
      shape.SetCustomIcon(
         '<div><img height="24"' + 
         ' src="http://livesteamtracks.info/' + icon + '" width="12"></div>');
      shape.SetTitle(title);
      shape.SetDescription(description);
      shape.SetLineColor(new VEColor(0,150,100,1.0));
      shape.SetFillColor(new VEColor(0,100,150,0.5));
//    shape.SetMoreInfoURL('http://www.discoverlivesteam.com');
//    if(logo1 != 'TBD') {
//       shape.SetPhotoURL(
//          'http://livesteamtracks.info/logos/' + logo1 + '.jpg');
//    }
      shape.ShowIcon();
      if(map != null) {
         map.AddShape(shape);
      }
   }

   if(include) {
      markerInfos[sequence] = 
         new objMarker(
            (type1 == 'country') ? true : false,(exact == '1') ? true : false,
            id1,id2,lat,lng,(exact == '2') ? true : false,
            (type1 == 'state') ? true : false,type1,type2,
            (zoomIn.length > 0) ? zoomIn : 18,zoomOut);

      if(type1 == 'country' || type1 == 'group' || type1 == 'state') {
         if(initialSelectID == -1) {
            initialSelectSID = sequence;
         }
         zoomOut = zoomIn;
      }
      if(id1 == initialID || id2 == initialID) {
         initialSelectID = sequence;
      }

      sequence++;
   }
}

function addMenuStart(id) {
   return(
      '<div id="' + id + '" onmouseout="doMenuOut(this);"' + 
      ' onmouseover="doMenuOver(this);">' + 
      '<table cellpadding="0" cellspacing="0">' + 
      '<tr>' + 
      '<td class="menuTop1"/>' + 
      '<td class="menuTop2"/>' + 
      '<td class="menuTop3"/></tr>' + 
      '<tr>' + 
      '<td class="menuMiddle1"/>' + 
      '<td>' + 
      '<table cellpadding="0" cellspacing="0" width="100%">' + 
      '<tr>');
}

function addMenuState(start,stop,state,id) {
   var html = '';

   if(start) {
      html += '<td class="menuTable"><table class="menuTable">';
   }

   html += 
      '<tr>' + 
      '<td class="menuText" nowrap="1" onclick="goMarker(\'' + id + '\');"' + 
      ' onmouseover="doMenuOptionOver(this)"' + 
      ' onmouseout="doMenuOptionOut(this)">' + state + '</td></tr>';

   if(stop) {
      html += '</table></td>';
   }

   return(html);
}

function addMenuStateSection(section,columns) {
   var html = '';

   html += 
      '<tr>' + 
      '<td class="menuSection" colspan="' + columns + '" nowrap="1">' + section + 
      '</td></tr>' + 
      '<tr>';

   return(html);
}

function addMenuStop() {
   return(
      '</tr></table></td>' + 
      '<td class="menuMiddle3"/></tr>' + 
      '<tr>' + 
      '<td class="menuBottom1"/>' + 
      '<td class="menuBottom2"/>' + 
      '<td class="menuBottom3"/></tr>' + 
      '</table></div>');
}

function addShim(el,id) {
   var shim = document.getElementById('alertShim');

   if(!shim)
      shim = document.createElement("iframe"); 
   shim.id = id;         
   shim.frameBorder = "0"; 
   shim.style.position = "absolute";
   shim.style.zIndex = "1";
   shim.style.top  = el.offsetTop + "px";
   shim.style.left = el.offsetLeft + "px";
   shim.style.width  = el.offsetWidth + "px";
   var h = 
      parseInt(document.getElementById("alertTitle").offsetHeight) +
      parseInt(document.getElementById("alertText").offsetHeight);
   if(h > 0) {
      shim.style.height = h + "px";
   }
   else {
      shim.style.height = 
         parseInt(document.getElementById("alertTitle").style.height) +
         parseInt(document.getElementById("alertText").style.height) + "px";
   }

   el.shimElement = shim; 
   el.parentNode.insertBefore(shim,el);
}

function adjustLegendSize(over) {
   var element = null;

   try {
      if((element = document.getElementById("legend")) != null) {
         if(isWindowsIE()) {
            element.style.left = 
               document.body.clientWidth - ((over) ? 220 : 25);
         }
//       else if(isNetscape()) {
         else {
            element.style.left = 
               (window.innerWidth - ((over) ? 220 : 25)) + "px";
         }
      }

      successful = true;
   }
   catch(exception) {
      alert(
         'Exception: ' + exception.toString()  + '\n\n' + 
         'Platform: '  + navigator.platform    + '\n\n' + 
         'AppName: '   + navigator.appName     + '\n\n' + 
         'CodeName: '  + navigator.appCodeName + '\n\n' + 
         'Version: '   + navigator.appVersion);
   }

   return(successful);
}

function adjustPageSize(initial) {
   var adsHeight  = 0;
   var element    = null;
   var height     = 0;
   var successful = false;
   var width      = 0;

   try {
      if((element = document.getElementById("topBar1")) != null) {
         if(isWindowsIE()) {
            element.style.width = document.body.clientWidth - 64;
         }
//       else if(isNetscape()) {
         else {
            element.style.width = (window.innerWidth - 64) + "px";
         }
      }

      if((element = document.getElementById("sideBar")) != null) {
         if(isWindowsIE()) {
            element.style.height = document.body.clientHeight - 38;
         }
//       else if(isNetscape()) {
         else {
            element.style.height = (window.innerHeight - 38) + "px";
         }
      }

      adsHeight = ((adMinimized) ? 20 : 122);

      if((element = document.getElementById("ads")) != null) {
         if(isWindowsIE()) {
            element.style.top = document.body.clientHeight - adsHeight;
         }
//       else if(isNetscape()) {
         else {
            height = window.innerHeight - adsHeight;
            element.style.top = height + "px";
         }
      }

      if(map != null) {
         if(isWindowsIE()) {
            height = document.body.clientHeight - adsHeight - 18;
            width  = document.body.clientWidth  - 75;
         }
//       else if(isNetscape()) {
         else {
            height = window.innerHeight - adsHeight - 18;
            width  = window.innerWidth  - 75;
         }

         map.Resize(width,height);
      }

      if(initial) {
//       if(isWindowsIE()) {
//          window.onresize = function() {
//             adjustPageSize(false);
//          }
//       }
      }

      adjustLegendSize(false);

      successful = true;
   }
   catch(exception) {
      alert(
         'Exception: ' + exception.toString()  + '\n\n' + 
         'Platform: '  + navigator.platform    + '\n\n' + 
         'AppName: '   + navigator.appName     + '\n\n' + 
         'CodeName: '  + navigator.appCodeName + '\n\n' + 
         'Version: '   + navigator.appVersion);
   }

   return(successful);
}

function clearMenuTimeout(element) {
   var object = null;

   if(isCountryMenu(element)) {
      object = getCountryByMenu(element);
      if(object.timerID > 0) {
         clearTimeout(object.timerID);
         object.timerID = 0;
      }
   }
}

function closeAllMenus() {
   for(country in countries) {
      closeFlagMenu(countries[country].abbreviation1 + 'Menu');
   }
}

function closeFlagMenu(menu) {
   enableDisableMenu(menu,false);
}

function displayLoadingWindow() {
   var x = 0;
   var y = 0;

   if(isWindowsIE()) {
      y = document.body.clientHeight / 2;
      x = document.body.clientWidth / 2;
   }
// else if(isNetscape()) {
   else {
      y = window.innerHeight / 2;
      x = window.innerWidth / 2;
   }

   if(x > 0 && y > 0) {
      x -= 100;
      y -= 25;

      w('<div id="loading" style="display:block; position:absolute; top:' + y + 
        'px; left:' + x + 'px;">');
      w('<img src="images/loading.gif"/>');
      w('</div>');
   }
}

function doAlert(text) {
   var element1 = null;
   var element2 = null;

   if((element1 = document.getElementById("alertDiv")) != null) {
      element1.style.visibility = "visible";

      if((element2 = document.getElementById("alertText")) != null) {
         element2.innerHTML = text;
      }

//    addShim(element1,'alertShim');
   }
}

function doButtonOut(element) {
   var object = null;

   element.style.cursor = 'Auto';

// if(element.id == "zoomIn") {
//    element.src = 
//       (zoomInEnabled) 
//    ? getButton(element.id).buttonOutImage.src 
//    : getButton(element.id).buttonDisabledImage.src;
// }
   if(isAd(element.id)) {
      object = getAd(element.id);
      if(object.animated == false) {
         element.src = object.buttonOutImage.src;
      }
   }
   else if(isButton(element.id)) {
      element.src = getButton(element.id).buttonOutImage.src;
   }
   else if(isCountryFlag(element.id)) {
      element.src = getCountryByFlag(element.id).buttonOutImage.src;
   }
}

function doButtonOver(element) {
   var object = null;

   element.style.cursor = 'Hand';

// if(element.id == "zoomIn") {
//    if(zoomInEnabled) {
//       element.style.cursor = 'Hand';
//       element.src          = getButton(element.id).buttonOverImage.src;
//    }
//    else {
//       element.style.cursor = 'Auto';
//       element.src          = getButton(element.id).buttonDisabledImage.src;
//    }
// }
   if(isAd(element.id)) {
      object = getAd(element.id);
      if(object.animated == false) {
         element.src = object.buttonOverImage.src;
      }
   }
   else if(isButton(element.id)) {
      element.src = getButton(element.id).buttonOverImage.src;
   }
   else if(isCountryFlag(element.id)) {
      element.src = getCountryByFlag(element.id).buttonOverImage.src;
   }
}

function doFlagButtonOut(element) {
   doButtonOut(element);

// if(isCountryFlag(element.id)) {
//    enableDisableMenu(
//       getCountryByFlag(element.id).abbreviation1 + 'Menu',false);
// }
}

function doFlagButtonOver(element) {
   doButtonOver(element);

   if(isCountryFlag(element.id)) {
      enableDisableMenu(
         getCountryByFlag(element.id).abbreviation1 + 'Menu',true);
   }
}

function doMenuOptionOut(element) {
   element.style.cursor          = 'Auto';
   element.style.backgroundColor = '#e3e3fd';
}

function doMenuOptionOver(element) {
   element.style.cursor          = 'Hand';
   element.style.backgroundColor = 'yellow';
}

function doMenuOut(element) {
   setMenuTimeout(element.id);
}

function doMenuOver(element) {
   clearMenuTimeout(element.id);
}

function doMinMaxAd() {
   adMinimized = ((adMinimized) ? false : true);
   adjustPageSize(false);
}

function doOnLoad() {
   onLoad();
}

function doSelectOut(element) {
   var element1 = null;
   var element2 = null;
   var element3 = null;

   element.style.cursor = 'Auto';

   if((element1 = document.getElementById("list1")) != null) {
      if((element2 = document.getElementById("list2")) != null) {
         if((element3 = document.getElementById("list3")) != null) {
            element1.style.background = 
               'url(images/backgrounds/list-out-1.gif)';
            element2.style.background = 
               'url(images/backgrounds/list-out-2.gif)';
            element3.style.background = 
               'url(images/backgrounds/list-out-3.gif)';
         }
      }
   }
}

function doSelectOver(element) {
   var element1 = null;
   var element2 = null;
   var element3 = null;

   element.style.cursor = 'Hand';

   if((element1 = document.getElementById("list1")) != null) {
      if((element2 = document.getElementById("list2")) != null) {
         if((element3 = document.getElementById("list3")) != null) {
            element1.style.background = 
               'url(images/backgrounds/list-over-1.gif)';
            element2.style.background = 
               'url(images/backgrounds/list-over-2.gif)';
            element3.style.background = 
               'url(images/backgrounds/list-over-3.gif)';
         }
      }
   }
}

function doShowLinks(show) {
   var element = null;

   if((element = document.getElementById('links')) != null) {
      element.style.display = ((show) ? 'block' : 'none');
   }
}

function doUpdate() {
   var url1 = BASE_ADDRESS + "/?";
   var url2 = "";

   if(gaugeChangeMade) {
      for(gauge in gauges) {
         if(gauges[gauge].option) {
            url2 += "&" + gauges[gauge].id;
         }
      }

      if(suppliersOption) {
         url2 += "&supp";
      }

      if(url2.length > 0) {
         url2 = url2.substring(1);
      }

      go(url1 + url2);
   }
   else {
      alert("No changes made");
   }
}

function enableDisableMenu(menu,enable) {
   var element = null;

   if((element = document.getElementById(menu)) != null) {
      if(enable) {
         closeAllMenus();
      }
      else {
         clearMenuTimeout(menu);
      }

      element.style.display = (enable) ? 'block' : 'none';

      if(enable) {
         setMenuTimeout(menu);
      }
   }
}

function getAd(id) {
   var object = null;

   for(ad in ads) {
      if(ads[ad].id == id) {
         object = ads[ad];
      }
   }

   return object;
}

function getButton(id) {
   var object = null;

   for(button in buttons) {
      if(buttons[button].id == id) {
         object = buttons[button];
      }
   }

   return object;
}

function getCountryByAbbrev(abbreviation1) {
   var object = null;

   for(country in countries) {
      if(countries[country].abbreviation1 == abbreviation1) {
         object = countries[country];
      }
   }

   return object;
}

function getCountryByFlag(flag) {
   var object = null;

   for(country in countries) {
      if(countries[country].abbreviation1 + 'Flag' == flag) {
         object = countries[country];
      }
   }

   return object;
}

function getCountryByMenu(menu) {
   var object = null;

   for(country in countries) {
      if(countries[country].abbreviation1 + 'Menu' == menu) {
         object = countries[country];
      }
   }

   return object;
}

function getGauge(id) {
   var object = null;

   for(gauge in gauges) {
      if(gauges[gauge].id == id) {
         object = gauges[gauge];
      }
   }

   return object;
}

function getMarkerAttribute(marker,attribute,defaultValue) {
   var value = marker.getAttribute(attribute);

   return(
      (value == null) ? defaultValue : 
      ((value.length == 0) ? defaultValue : value));
}

function go(url) {
   top.location = url;
}

function goEmail() {
   parent.location = 
      'mailto:dale@livesteamtracks.info?cc=allison@livesteamtracks.info';
}

function goHome() {
   go(BASE_ADDRESS);
}

function goList() {
   go(BASE_ADDRESS + '/tracks.xml');
}

function goMarker(newID) {
   var element = null;

   closeAllMenus();

   for(var x=0,found=false; x<markerInfos.length && found==false; x++) {
      if(markerInfos[x].id1 == newID || markerInfos[x].id2 == newID) {
         found = true;

         if((element = document.getElementById("list")) == null) {
            found = false;
         }
         else {
            element.selectedIndex = x;
         }

         if(found) {
            selectTrack();
         }
      }
   }
}

function hideAlert() {
   var element = null;
   var shim    = null;

   if((element = document.getElementById('alertDiv')) != null) {
      element.style.visibility = 'hidden';
      if((shim = document.getElementById("alertShim")) != null) {
         shim.parentNode.removeChild(shim);
         shim = null;
      }
   }
}

function isAd(id) {
   var adFlag = false;

   for(ad in ads) {
      if(ads[ad].id == id) {
         adFlag = true;
      }
   }

   return adFlag;
}

function isButton(id) {
   var buttonFlag = false;

   for(button in buttons) {
      if(buttons[button].id == id) {
         buttonFlag = true;
      }
   }

   return buttonFlag;
}

function isChrome() {
   return((navigator.appVersion.indexOf('Chrome') >= 0) ? true : false);
}

function isCountry(abbreviation1) {
   var countryFlag = false;

   for(country in countries) {
      if(countries[country].abbreviation1 == abbreviation1) {
         countryFlag = true;
      }
   }

   return countryFlag;
}

function isCountryFlag(flag) {
   var countryFlag = false;

   for(country in countries) {
      if(countries[country].abbreviation1 + 'Flag' == flag) {
         countryFlag = true;
      }
   }

   return countryFlag;
}

function isCountryMenu(menu) {
   var countryMenu = false;

   for(country in countries) {
      if(countries[country].abbreviation1 + 'Menu' == menu) {
         countryMenu = true;
      }
   }

   return countryMenu;
}

function isGauge(id) {
   var gaugeFlag = false;

   for(gauge in gauges) {
      if(gauges[gauge].id == id) {
         gaugeFlag = true;
      }
   }

   return gaugeFlag;
}

function isNetscape() {
   return((navigator.appName == 'Netscape') ? true : false);
}

function isSafari() {
   return((navigator.appVersion.indexOf('Safari') >= 0) ? true : false);
}

function isWindowsIE() {
   return(((navigator.platform == 'Win32' && 
            navigator.appName == 'Microsoft Internet Explorer') || 
           (navigator.platform == 'WinCE' && 
            navigator.appName == 'Microsoft IE Mobile')) ? true : false);
}

function objAd(id,label,animated) {
   var object = new Object();

   object.id = id;
   object.label = label;
   object.animated = animated;

   if(animated) {
      object.buttonOutImage = new Image();
      object.buttonOutImage.src = 'ads/ad-' + label + '.gif';
   }
   else {
      object.buttonOverImage = new Image();
      object.buttonOverImage.src  = 'ads/ad-' + label + '-over.jpg';
      object.buttonOutImage = new Image();
      object.buttonOutImage.src = 'ads/ad-' + label + '-out.jpg';
   }

   return object;
}

function objButton(id,label) {
   var object = new Object();

   object.id = id;
   object.label = label;

// if(id == 'zoomIn') {
//    object.buttonDisabledImage = new Image();
//    object.buttonDisabledImage.src = 
//       'images/buttons/' + label + '-disabled.gif';
// }

   object.buttonOverImage = new Image();
   object.buttonOverImage.src = 'images/buttons/' + label + '-over.gif';
   object.buttonOutImage = new Image();
   object.buttonOutImage.src = 'images/buttons/' + label + '-out.gif';

   return object;
}

function objCountry(abbreviation1,abbreviation2) {
	var object = new Object();

   object.abbreviation1 = abbreviation1;
   object.abbreviation2 = abbreviation2;
   object.name          = translateCountry(abbreviation2);
   object.timerID       = 0;

	object.buttonOverImage = new Image();
	object.buttonOverImage.src = 
      "images/buttons/" + abbreviation1 + "-flag-over.gif";
	object.buttonOutImage = new Image();
	object.buttonOutImage.src  = 
      "images/buttons/" + abbreviation1 + "-flag-out.gif";

	return object;
}

function objGauge(id,label,text) {
   var object = new Object();

   object.id     = id;
   object.label  = label;
   object.text   = text;
   object.option = false;

   return object;
}

function objLegend(image,description) {
   var object = new Object();

   object.image       = 'images/icons/' + image;
   object.description = description;

   return object;
}

function objMarker(country,exact,id1,id2,lat,lng,mapStart,state,type1,
                   type2,zoomIn,zoomOut) {
   var object = new Object();

   object.country  = country;
   object.exact    = exact;
   object.id1      = id1;
   object.id2      = id2;
   object.lat      = lat;
   object.lng      = lng;
   object.mapStart = mapStart;
   object.state    = state;
   object.type1    = type1;
   object.type2    = type2;
   object.updated  = false;
   object.zoomIn   = zoomIn;
   object.zoomOut  = zoomOut;

   return object;
}

function onClickCB(element) {
   if(element.id == 'suppliers') {
      suppliersOption = (element.checked) ? true : false;
   }
   else if(isGauge(element.id)) {
      getGauge(element.id).option = (element.checked) ? true : false;
   }

   gaugeChangeMade = true;
}

function onLoad() {
   if(debug) {
      alert(
         'Platform: '    + navigator.platform    + '\n\n' + 
         'AppName: '     + navigator.appName     + '\n\n' + 
         'CodeName: '    + navigator.appCodeName + '\n\n' + 
         'Version: '     + navigator.appVersion  + '\n\n' + 
         'isChrome: '    + isChrome()            + '\n' + 
         'isNetscape: '  + isNetscape()          + '\n' + 
         'isSafari: '    + isSafari()            + '\n' + 
         'isWindowsIE: ' + isWindowsIE());
   }

   if(allGauges) {
      for(gauge in gauges) {
         gauges[gauge].option = true;
      }

      suppliersOption = true;
   }

   if(adjustPageSize(true)) {
      try {
//       window.status = 'Creating instances of VEMap ...';
         map = new VEMap('map');
//       map.onLoadMap = function(){ doAlert('The map has loaded'); };
         map.LoadMap();
//       map.AttachEvent('onclick',updateZoomLevelDisplay);
         map.AttachEvent('onchangeview',updateZoomLevelDisplay);

//       window.status = 'Setting the map initial centers ...';
//       map.SetCenter(new VELatLong(39.027893,-95.881907));
//       map.SetZoomLevel(5);
//       map.SetMapStyle(VEMapStyle.Aerial);

//       window.status = 'Loading the marker files ...';
         processTracks();

         adjustPageSize(false);
         adjustLegendSize(false);
      }
      catch(exception) {
         alert(
            'Exception: ' + exception.toString()  + '\n\n' + 
            'Platform: '  + navigator.platform    + '\n\n' + 
            'AppName: '   + navigator.appName     + '\n\n' + 
            'CodeName: '  + navigator.appCodeName + '\n\n' + 
            'Version: '   + navigator.appVersion);
      }
   }
}

function openGE(ge) {
   parent.location = ge;
}

function openGM(lat,lng,zoomIn) {
//   parent.location = 
//      'http://maps.google.com/maps?f=q&hl=en&q=&sll=' + lat + ';' + lng + 
//      '&ie=UTF8&cd=1&z=' + zoomIn + '&t=h';
   parent.location = 
      'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=' + lat + 
      ',' + lng + '&ie=UTF8&t=h&z=18';
}

function openPOI(country1,state1,name1) {
   parent.location = 
      'poi/zip/' + country1 + '/' + country1 + '-' + state1 + '-' + name1 + 
      '.zip';
}

function openTS(lat,lng) {
   parent.location = 
      'http://www.terraserver.com/image.aspx?Lon=' + lng + '&Lat=' + lat + 
      '&w=3';
}

function openWM(lat,lng) {
   parent.location = 
      'http://wikimapia.org/#lat=' + lat + '&lon=' + lng + '&z=19&l=0&m=a&v=2';
}

function parseURL() {
   var character = "";
   var element   = 0;
   var location  = String(parent.location);
   var position  = 0;
   var word      = "";

   if(location.length == 0) {
      return;
   }

   // Check if there are any variables
   if(location.indexOf('?') == -1) {
      return;
   }

   variables = 
      String(location.substring(location.indexOf('?') + 1,location.length));

   // Parse
   while(position < variables.length) {
      character = variables.substring(position,position + 1);

      if(character == "=") {
         names[element] = word;
         word           = "";
      }
      else if(character == "&") {
         values[element++] = word;
         word              = "";
      }
      else if(position == variables.length - 1) {
         word             += variables.substring(position,position + 1);
         values[element++] = word;
         word              = "";
      }
      else {
         word += character;
      }

      position++;
   }
}

function processTracks() {
   var objXMLHTTP = null;

   try {
      if(document.implementation && document.implementation.createDocument) {
         xmlDoc = document.implementation.createDocument("","",null);
         if(isWindowsIE()) {
            xmlDoc.onload = createTable;
         }
//       else if(isNetscape()) {
         else {
            xmlDoc.onload = processXML;
         }
      }
   	else if(window.ActiveXObject) {
         if(isWindowsIE()) {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
//          xmlDoc.async = "false";
            xmlDoc.onreadystatechange = function () {
               if(xmlDoc.readyState == 4) {
                  processXML();
               }
            };
         }
      }
      else {
   		alert('Your browser can\'t handle this script');
   		return;
   	}

      if(isChrome() || isSafari()) {
         objXMLHTTP = new XMLHttpRequest();
         objXMLHTTP.open("GET","tracks.xml",false);
         objXMLHTTP.send(null);
         xmlDoc = objXMLHTTP.responseXML;
         processXML();
      }
      else {
         if(debug) {
            xmlDoc.loadXML(
               '<markers><marker c="" state1="" state2="" zi="" co="US" ' + 
               'lat="39.027893" lng="-95.881907" zo="5" e="true">' + 
               '<id1>US</id1><t>country</t></marker> ' + 
               '<marker c="" state1="NC" state2="" zi="" co="US" ' + 
               'lat="35.257880" lng="-79.727900" zo="7" e="true">' + 
               '<id1>US-NC</id1><t>state</t></marker> ' + 
               '<marker c="Harrisburg" state1="NC" state2="" zi="28075" ' + 
               'co="US" lat="35.316666" lng="-80.653494" zo="" e="true">' + 
               '<n1>Triad Live Steamers (Harrisburg Division)</n1>' + 
               '<l1>TLS-H</l1><id1>US-NC-TLS-H</id1><logo1>US-NC-TLS</logo1>' + 
               '<t>club</t><u1>www.matson.us/triad/harrisburg/index.htm</u1>' + 
               '<address1>6960 Robinson Church Road</address1>' + 
               '<g7p5inch>610+ feet (new railroad)</g7p5inch></marker>' + 
               '</markers>');
         }
         else {
            xmlDoc.load("tracks.xml");
         }
      }
   }
   catch(exception) {
      alert(
         'Exception: ' + exception.toString()  + '\n\n' + 
         'Platform: '  + navigator.platform    + '\n\n' + 
         'AppName: '   + navigator.appName     + '\n\n' + 
         'CodeName: '  + navigator.appCodeName + '\n\n' + 
         'Version: '   + navigator.appVersion);
   }
}

function processXML() {
   var element = '';
   var html    = '';
   var markers = xmlDoc.getElementsByTagName('marker');

   if(debug) {
      if(xmlDoc == null) {
         alert("xmlDoc is null");
      }
   }

   topBar1 = 
      '<form id="map"><nobr>' + 
      '<table cellpadding="0" cellspacing="0"><tbody>' + 
      '<tr>' + 
      '<td nowrap="1" valign="middle">&nbsp;&nbsp;&nbsp;' + 
      '<img alt="[Logo]" id="logo" onclick="goHome();"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="images/buttons/logo-out.gif" title="Reload this page"/>' + 
      '&nbsp;&nbsp;</td>' + 
      '<td class="list1" id="list1" nowrap="1" valign="middle"/>' + 
      '<td class="list2" id="list2" nowrap="1" valign="middle">' + 
      '<select name="list" id="list" onChange="selectTrack()"' + 
      ' onmouseover="doSelectOver(this);" onmouseout="doSelectOut(this);"' + 
      ' style="width:350px;">';

   if(markers.length > 0) {
   	for(x=0; x<markers.length; x++) {
         addMarker(markers[x]);
   	}
   }
   else {
      alert('Unfortunately, there was an unknown problem loading the markers.');
   }

   topBar1 += 
      '</select></td>' + 
      '<td class="list3" id="list3" nowrap="1" valign="middle"/>' + 
      '<td nowrap="1" width="5"/>' + 
//    '<td nowrap="1" valign="top">' + 
//    '<img alt="[Zoom In]" id="zoomIn" onclick="selectTrack();"' + 
//    ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
//    ' src="images/buttons/zoomin-out.gif" title="Zoom In"/>' + 
//    '<img src="images/buttons/zoom-separator.gif"/>' + 
//    '<img alt="[Zoom Out]" id="zoomOut" onclick="zoomOutToMap();"' + 
//    ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
//    ' src="images/buttons/zoomout-out.gif" title="Zoom Out"/>' + 
//    '</td>' + 
//    '<td nowrap="1" width="5"/>' + 
      '<td nowrap="1" valign="middle">' + 
      '<img alt="[List]" id="list" onclick="goList();"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="images/buttons/list-out.gif" title="View List"/>' + 
      '</td>' + 
      '<td nowrap="1" width="5"/>' + 
      '<td nowrap="1" valign="middle">' + 
      '<img alt="[Contact Us]" id="contactUs" onclick="goEmail();"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="images/buttons/contactus-out.gif" title="Contact Us"/>' + 
      '</td>' + 
      '<td nowrap="1" width="5"/>' + 
      '<td class="copyright">All rights reserved.  Copyright 2008 Dale' + 
      ' King</td></tr></tbody></table></nobr>';
   if((element = document.getElementById("topBar1")) != null) {
      element.innerHTML = topBar1;
   }

   if(isChrome()) {

      // Top bar #2
      html = 
         '<nobr>' + 
         '<table cellpadding="0" cellspacing="0"><tbody>' + 
         '<tr>' + 
         '<td nowrap="1" width="5"/>' + 
         '<td nowrap="1" title="Track count" valign="middle">' + 
         '<input class="trackCount" disabled="1" id="trackCount"' + 
         ' readonly="1" type="text" value="0"/></td>' + 
         '<td nowrap="1" width="5"/>' + 
         '<td nowrap="1" title="Zoom level" valign="middle">' + 
         '<input class="zoomLevel" disabled="1" id="zoomLevel" readonly="1"' + 
         ' type="text" value="0"/></td>' + 
//       '<img src="http://www.easycounter.com/counter.php?daglek"/>' + 
         '<td nowrap="1" width="5"/></tr>' + 
         '</tbody></table></nobr>';
      if((element = document.getElementById("topBar2")) != null) {
         element.innerHTML = html;
      }

      // Track count
      if((element = document.getElementById("trackCount")) != null) {
         element.value = trackCount;
      }
   }

   // Side bar
   html  = '<nobr>';
   html += 
      '<table cellpadding="0" cellspacing="0" height="100%" width="100%"><tbody>';
   html += '<tr><td height="5" nowrap="1"/></tr>';
   html += 
      '<tr>' + 
      '<td class="gaugeSectionTop1" nowrap="1">Maps</td>' + 
      '<td class="gaugeSectionTop2" nowrap="1"/></tr>' + 
      '<tr>' + 
      '<td class="gaugeSectionMiddle1L" height="3" nowrap="1"/>' + 
      '<td class="gaugeSectionMiddle2" height="3" nowrap="1"/></tr>';
   for(country in countries) {
      html += 
         '<tr>' + 
         '<td class="gaugeSectionMiddle1C" nowrap="1" valign="top">' + 
         '<img alt="[' + countries[country].name + ']" id="' + 
         countries[country].abbreviation1 + 'Flag"' + 
         ' onclick="goMarker(\'' + countries[country].abbreviation2 + '\');"' + 
         ' onmouseover="doFlagButtonOver(this);"' + 
         ' onmouseout="doFlagButtonOut(this);"' + 
         ' src="' + countries[country].buttonOutImage.src + '"' + 
         ' title="Centers the map over ' + countries[country].name + '"/></td>' + 
         '<td class="gaugeSectionMiddle2" nowrap="1"/></tr>';
   }
   html += 
      '<tr>' + 
      '<td class="gaugeSectionBottom1" nowrap="1"/>' + 
      '<td class="gaugeSectionBottom2" nowrap="1"/></tr>';
	html += '<tr><td height="10" nowrap="1"/></tr>';
	html += 
		'<tr>' + 
      '<td class="gaugeSectionTop1" nowrap="1">Gauges</td>' + 
		'<td class="gaugeSectionTop2" nowrap="1"/></tr>' + 
      '<tr>' + 
      '<td class="gaugeSectionMiddle1L" height="3" nowrap="1"/>' + 
      '<td class="gaugeSectionMiddle2" height="3" nowrap="1"/></tr>';
   for(gauge in gauges) {
      html += 
         '<tr>' + 
         '<td class="gaugeSectionMiddle1L" nowrap="1">' + 
         '<input ' + ((gauges[gauge].option) ? 'checked' : '') + 
         ' id="' + gauges[gauge].id + '"' + 
         ' onclick="onClickCB(this);"' + 
         ' title="Include ' + gauges[gauge].text + ' inch gauge ' + 
         ((gauges[gauge].id == 'g15p0') ? "or greater " : "") + 
         'tracks on the map"' + 
         ' type="checkbox">&nbsp;' + gauges[gauge].label + '"</input></td>' + 
         '<td class="gaugeSectionMiddle2" nowrap="1"/></tr>';
   }
   html += 
      '<tr>' + 
      '<td align="right" class="gaugeSectionMiddle1R" nowrap="1">' + 
      '<img alt="[Update]" id="update1" onclick="doUpdate();"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="images/buttons/update-out.gif"' + 
      ' title="The \'Update\' button redisplays the live steam tracks that' + 
      ' have the chosen gauges"/></td>' + 
      '<td class="gaugeSectionMiddle2" nowrap="1"/></tr>';
   html += 
      '<tr>' + 
      '<td class="gaugeSectionBottom1" nowrap="1"/>' + 
      '<td class="gaugeSectionBottom2" nowrap="1"/></tr>';
   html += '<tr><td height="10" nowrap="1"/></tr>';
   html += 
      '<tr>' + 
      '<td class="gaugeSectionTop1" nowrap="1">Options</td>' + 
      '<td class="gaugeSectionTop2" nowrap="1"/></tr>' + 
      '<tr>' + 
      '<td class="gaugeSectionMiddle1L" height="3" nowrap="1"/>' + 
      '<td class="gaugeSectionMiddle2" height="3" nowrap="1"/></tr>';
   html += 
      '<tr>' + 
      '<td class="gaugeSectionMiddle1L" nowrap="1">' + 
      '<input ' + ((suppliersOption) ? 'checked ' : '') + // 'disabled' + 
      ' id="suppliers" onclick="onClickCB(this);"' + 
      ' title="Include suppliers on the map"' + 
      ' type="checkbox">Supplier</input></td>' + 
      '<td class="gaugeSectionMiddle2" nowrap="1"/></tr>';
   html += 
      '<tr>' + 
      '<td align="right" class="gaugeSectionMiddle1R" nowrap="1">' + 
      '<img alt="[Update]" id="update2" onclick="doUpdate();"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="images/buttons/update-out.gif"' + 
      ' title="The \'Update\' button redisplays the live steam tracks that' + 
      ' have the chosen options"/></td>' + 
      '<td class="gaugeSectionMiddle2" nowrap="1"/></tr>';
   html += 
      '<tr>' + 
      '<td class="gaugeSectionBottom1" nowrap="1"/>' + 
      '<td class="gaugeSectionBottom2" nowrap="1"/></tr>';
   html += 
      '<tr><td height="100%" nowrap="1"/></tr>' + 
      '</tbody></table>' + 
      '</nobr></form>';
   if((element = document.getElementById("sideBar")) != null) {
      element.innerHTML = html;
   }

   // Legend
   html = 
      '<table cellpadding="0" cellspacing="0"' + 
      ' onmouseover="adjustLegendSize(true);"' + 
      ' onmouseout="adjustLegendSize(false);">' + 
      '<tr>' + 
      '<td class="borderTop1" nowrap="1"/>' + 
      '<td class="borderTop2" nowrap="1">Legend</td></tr>' + 
      '<tr>' + 
      '<td class="borderMiddle1" nowrap="1"/>' + 
      '<td><table cellpadding="0" cellspacing="0" width="100%">';
   for(legend in legends) {
      html += 
         '<tr>' + 
         '<td class="legendImage">' + 
         '<img height="24" src="' + legends[legend].image + '" width="12"></td>' + 
         '<td class="legend">' + legends[legend].description + '</td></tr>';
   }
   html += 
      '<tr>' + 
      '<td align="right" class="legend" colspan="2" nowrap="1">' + 
      '<img alt="[Links]" id="linklist" onclick="doShowLinks(true);"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="images/buttons/links-out.gif"' + 
      ' title="The \'Links\' button redisplays a list of links to other web' + 
      ' pages"/></td></tr>' + 
      '</table></td></tr>' + 
      '<tr>' + 
      '<td class="borderBottom1" nowrap="1"/>' + 
      '<td class="borderBottom2" nowrap="1"/></tr>' + 
      '</table>';
   if((element = document.getElementById("legend")) != null) {
      element.innerHTML = html;
   }

   // Links
   html = 
      '<table cellpadding="0" cellspacing="0">' + 
      '<tr>' + 
      '<td class="borderTop1" nowrap="1"/>' + 
      '<td class="borderTop2" nowrap="1">Links</td>' + 
      '<td class="borderTop3" onclick="doShowLinks(false);" nowrap="1"/></tr>' + 
      addLink(
         'Association of Railway Museums','http://www.railwaymuseums.org',
         'arm') + 
      addLink('Business Card','tracks.bcf','bcf') + 
      addLink('Discover Live Steam','http://www.discoverlivesteam.com/','dls') + 
      addLink(
         'Frapper Maps','http://www.frappr.com/seventoeightinchrailroads/',
         'fm') + 
      addLink(
         'Latitude And Longitude Lookup',
         'http://www.calculatorcat.com/latitude_longitude.phtml','latlng') + 
      addLink(
         'Latitude And Longitude Lookup (2)',
         'http://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html','latlng2') + 
      addLink('Maps (Google)','http://maps.google.com','gmaps') + 
      addLink('Maps (Live)','http://maps.live.com','lmaps') + 
      addLink(
         'POI',
         'http://www8.garmin.com/products/poiloader/creating_custom_poi_files.jsp',
         'poi') + 
      addLink('POI (2)','http://gpx-poi.com/','poi2') + 
      addLink('Statistics','http://livesteamtracks.info/webalizer/','stats') + 
      addLink('TerraServer (USA)','http://terraserver-usa.com','ts') + 
      '<tr>' + 
      '<td class="borderBottom1" nowrap="1"/>' + 
      '<td class="borderBottom2" nowrap="1"/>' + 
      '<td class="borderBottom3" nowrap="1"/></tr>' + 
      '</table>';
   if((element = document.getElementById("links")) != null) {
      element.innerHTML = html;
   }

   // African menu
   html = 
      addMenuStart('afMenu') + 
      addMenuStateSection('African Tracks',1) + 
      addMenuState(true, true, 'South Africa','AF-SAF') + 
      addMenuStop();
   if((element = document.getElementById("afMenu")) != null) {
      element.innerHTML = html;
   }

   // Australia menu
   html = 
      addMenuStart('auMenu') + 
      addMenuStateSection('Australian Tracks',1) + 
      addMenuState(true, false,'Australian Capital Territory','AU-ACT') + 
      addMenuState(false,false,'New South Wales','AU-NSW') + 
      addMenuState(false,false,'Queensland','AU-QLD') + 
      addMenuState(false,false,'South Australia','AU-SA') + 
      addMenuState(false,false,'Tasmania','AU-TAS') + 
      addMenuState(false,false,'Victoria','AU-VIC') + 
      addMenuState(false,true, 'Western Australia','AU-WA') + 
      addMenuStop();
   if((element = document.getElementById("auMenu")) != null) {
      element.innerHTML = html;
   }

   // Austria menu
   html = 
      addMenuStart('atMenu') + 
      addMenuStateSection('Austrian Tracks',1) + 
      addMenuState(true,true,'Austria','AT-_') + 
      addMenuStop();
   if((element = document.getElementById("atMenu")) != null) {
      element.innerHTML = html;
   }

   // Belgium menu
   html = 
      addMenuStart('beMenu') + 
      addMenuStateSection('Belgium Tracks',1) + 
      addMenuState(true,true,'Antwerp','BE-AW') + 
      addMenuStop();
   if((element = document.getElementById("beMenu")) != null) {
      element.innerHTML = html;
   }

   // Canada menu
   html = 
      addMenuStart('caMenu') + 
      addMenuStateSection('Canadian Tracks',1) + 
      addMenuState(true, false,'Alberta','CA-AB') + 
      addMenuState(false,false,'British Columbia','CA-BC') + 
      addMenuState(false,false,'Manitoba','CA-MB') + 
      addMenuState(false,false,'Nova Scotia','CA-NS') + 
      addMenuState(false,false,'Ontario','CA-ON') + 
      addMenuState(false,true, 'Quebec','CA-QC') + 
      addMenuStateSection('Canadian Suppliers',1) + 
      addMenuState(true, true, 'British Columbia','CA-BC-S') + 
      addMenuStop();
   if((element = document.getElementById("caMenu")) != null) {
      element.innerHTML = html;
   }

   // France menu
   html = 
      addMenuStart('frMenu') + 
      addMenuStateSection('French Tracks',1) + 
      addMenuState(true,true,'France','FR') + 
      addMenuStop();
   if((element = document.getElementById("frMenu")) != null) {
      element.innerHTML = html;
   }

   // Germany menu
   html = 
      addMenuStart('grMenu') + 
      addMenuStateSection('German Tracks',1) + 
      addMenuState(true,true,'Germany','GR') + 
      addMenuStop();
   if((element = document.getElementById("grMenu")) != null) {
      element.innerHTML = html;
   }

   // Hungary menu
   html = 
      addMenuStart('huMenu') + 
      addMenuStateSection('Hungarian Tracks',1) + 
      addMenuState(true,true,'Hungary','HU') + 
      addMenuStop();
   if((element = document.getElementById("huMenu")) != null) {
      element.innerHTML = html;
   }

   // Indian menu
   html = 
      addMenuStart('inMenu') + 
      addMenuStateSection('Indian Tracks',1) + 
      addMenuState(true,true,'Maharashtra','IN-MA') + 
      addMenuStop();
   if((element = document.getElementById("inMenu")) != null) {
      element.innerHTML = html;
   }

   // Japan menu
   html = 
      addMenuStart('jpMenu') + 
      addMenuStateSection('Japanese Tracks',1) + 
      addMenuState(true,true,'Japan','JP') + 
      addMenuStop();
   if((element = document.getElementById("jpMenu")) != null) {
      element.innerHTML = html;
   }

   // Netherlands menu
   html = 
      addMenuStart('nlMenu') + 
      addMenuStateSection('Netherlands Tracks',1) + 
      addMenuState(true,true,'South Holland','NL-SH') + 
      addMenuStop();
   if((element = document.getElementById("nlMenu")) != null) {
      element.innerHTML = html;
   }

   // New Zealand menu
   html = 
      addMenuStart('nzMenu') + 
      addMenuStateSection('New Zealand Tracks',1) + 
      addMenuState(true, false,'North Island','NZ-NI') + 
      addMenuState(false,true, 'South Island','NZ-SI') + 
      addMenuStop();
   if((element = document.getElementById("nzMenu")) != null) {
      element.innerHTML = html;
   }

   // Spain menu
   html = 
      addMenuStart('esMenu') + 
      addMenuStateSection('Spanish Tracks',1) + 
      addMenuState(true,true,'Madrid','ES-MA') + 
      addMenuStop();
   if((element = document.getElementById("esMenu")) != null) {
      element.innerHTML = html;
   }

   // Switzerland menu
   html = 
      addMenuStart('chMenu') + 
      addMenuStateSection('Swiss Tracks',1) + 
      addMenuState(true,true,'Valais','CH-VS') + 
      addMenuStop();
   if((element = document.getElementById("chMenu")) != null) {
      element.innerHTML = html;
   }

   // United Kingdom menu
   html = 
      addMenuStart('ukMenu') + 
      addMenuStateSection('English Tracks',1) + 
      addMenuState(true, false,'England','UK-ENG') + 
      addMenuState(false,false,'Northern Ireland','UK-NIR') + 
      addMenuState(false,false,'Scotland','UK-SCO') + 
      addMenuState(false,true, 'Wales','UK-WAL') + 
      addMenuStateSection('English Suppliers',1) + 
      addMenuState(true, true, 'England','UK-ENG-S') + 
      addMenuStop();
   if((element = document.getElementById("ukMenu")) != null) {
      element.innerHTML = html;
   }

   // United States menu
   html = 
      addMenuStart('usMenu') + 
      addMenuStateSection('American Tracks',5) + 
      addMenuState(true, false,'Alabama','US-AL') + 
      addMenuState(false,false,'Alaska','US-AK') + 
      addMenuState(false,false,'Arizona','US-AZ') + 
      addMenuState(false,false,'Arkansas','US-AR') + 
      addMenuState(false,false,'California','US-CA') + 
      addMenuState(false,false,'Colorado','US-CO') + 
      addMenuState(false,false,'Connecticut','US-CT') + 
      addMenuState(false,false,'Delaware','US-DE') + 
      addMenuState(false,false,'Florida','US-FL') + 
      addMenuState(false,true, 'Georgia','US-GA') + 
      addMenuState(true, false,'Hawaii','US-HI') + 
      addMenuState(false,false,'Idaho','US-ID') + 
      addMenuState(false,false,'Illinois','US-IL') + 
      addMenuState(false,false,'Indiana','US-IN') + 
      addMenuState(false,false,'Iowa','US-IA') + 
      addMenuState(false,false,'Kansas','US-KS') + 
      addMenuState(false,false,'Kentucky','US-KY') + 
      addMenuState(false,false,'Louisiana','US-LA') + 
      addMenuState(false,false,'Maine','US-ME') + 
      addMenuState(false,true, 'Maryland','US-MD') + 
      addMenuState(true, false,'Massachusetts','US-MA') + 
      addMenuState(false,false,'Michigan','US-MI') + 
      addMenuState(false,false,'Minnesota','US-MN') + 
      addMenuState(false,false,'Mississippi','US-MS') + 
      addMenuState(false,false,'Missouri','US-MO') + 
      addMenuState(false,false,'Montana','US-MT') + 
      addMenuState(false,false,'Nebraska','US-NE') + 
      addMenuState(false,false,'Nevada','US-NV') + 
      addMenuState(false,false,'New Hampshire','US-NH') + 
      addMenuState(false,true, 'New Jersey','US-NJ') + 
      addMenuState(true, false,'New Mexico','US-NM') + 
      addMenuState(false,false,'New York','US-NY') + 
      addMenuState(false,false,'North Carolina','US-NC') + 
      addMenuState(false,false,'North Dakota','US-ND') + 
      addMenuState(false,false,'Ohio','US-OH') + 
      addMenuState(false,false,'Oklahoma','US-OK') + 
      addMenuState(false,false,'Oregon','US-OR') + 
      addMenuState(false,false,'Pennsylvania','US-PA') + 
      addMenuState(false,false,'Rhode Island','US-RI') + 
      addMenuState(false,true, 'South Carolina','US-SC') + 
      addMenuState(true, false,'South Dakota','US-SD') + 
      addMenuState(false,false,'Tennessee','US-TN') + 
      addMenuState(false,false,'Texas','US-TX') + 
      addMenuState(false,false,'Utah','US-UT') + 
      addMenuState(false,false,'Vermont','US-VT') + 
      addMenuState(false,false,'Virginia','US-VA') + 
      addMenuState(false,false,'Washington','US-WA') + 
      addMenuState(false,false,'West Virginia','US-WV') + 
      addMenuState(false,false,'Wisconsin','US-WI') + 
      addMenuState(false,true, 'Wyoming','US-WY') + 
      addMenuStateSection('American Suppliers',5) + 
      addMenuState(true, false,'Alabama','US-AL-S') + 
      addMenuState(false,false,'California','US-CA-S') + 
      addMenuState(false,false,'Colorado','US-CO-S') + 
      addMenuState(false,false,'Connecticut','US-CT-S') + 
      addMenuState(false,true, 'Florida','US-FL-S') + 
      addMenuState(true, false,'Georgia','US-GA-S') + 
      addMenuState(false,false,'Illinois','US-IL-S') + 
      addMenuState(false,false,'Massachusetts','US-MA-S') + 
      addMenuState(false,false,'Michigan','US-MI-S') + 
      addMenuState(false,true, 'New Hampshire','US-NH-S') + 
      addMenuState(true, false,'New Mexico','US-NM-S') + 
      addMenuState(false,false,'Ohio','US-OH-S') + 
      addMenuState(false,false,'Oklahoma','US-OK-S') + 
      addMenuState(false,false,'Oregon','US-OR-S') + 
      addMenuState(false,true, 'Pennsylvania','US-PA-S') + 
      addMenuState(true,false, 'South Carolina','US-SC-S') + 
      addMenuState(false,false,'Tennessee','US-TN-S') + 
      addMenuState(false,false,'Texas','US-TX-S') + 
      addMenuState(false,false,'Utah','US-UT-S') + 
      addMenuState(false,true, 'Virginia','US-VA-S') + 
      addMenuState(true,false, 'Washington','US-WA-S') + 
      addMenuState(false,true, 'Wisconsin','US-WI-S') + 
      addMenuStop();
   if((element = document.getElementById("usMenu")) != null) {
      element.innerHTML = html;
   }

   // Ads
   html = 
      '<table cellpadding="0" cellspacing="0">' + 
      '<tr>' + 
      '<td class="adCorner">' + 
      '<img alt="[minimize/maximize]" id="minMax" onclick="doMinMaxAd();"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="images/buttons/minmax-out.gif"' + 
      ' title="This button minimizes/maximizes the advertisements area"/></td>' + 
      '<td class="adTop" colspan="9" nowrap="1"/></tr>' + 
      '<tr>' + 
      '<td class="adSide" nowrap="1"/>' + 
      '<td class="ad" onclick="go(\'http://www.bryterails.com\')">' + 
      '<img alt="[BryteRails]" class="ad" id="ad1"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="' + getAd('ad1').buttonOutImage.src + '"' + 
      ' title="This button opens the BryteRails page."/></td>' + 
      '<td class="adGap" nowrap="1"/>' + 
      '<td class="ad" onclick="go(\'http://homerailwayjournal.com\');">' + 
      '<img alt="[Home Railway Journal]" class="ad" id="ad2"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="' + getAd('ad2').buttonOutImage.src + '"' + 
      ' title="This button opens the Home Railway Journal page."/></td>' + 
      '<td class="adGap" nowrap="1"/>' + 
      '<td class="ad" onclick="go(\'http://www.bryterails.com/index.htm?p=p400\')">' + 
      '<img alt="[BryteRails]" class="ad" id="ad3"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="' + getAd('ad3').buttonOutImage.src + '"' + 
      ' title="This button opens the BryteRails page."/></td>' + 
      '<td class="adGap" nowrap="1"/>' + 
      '<td class="ad" onclick="go(\'http://www.bryterails.com\')">' + 
      '<img alt="[BryteRails]" class="ad" id="ad4"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="' + getAd('ad4').buttonOutImage.src + '"' + 
      ' title="This button opens the BryteRails page."/></td>' + 
      '<td class="adGap" nowrap="1"/>' + 
      '<td class="ad" onclick="go(\'http://homerailwayjournal.com\');">' + 
      '<img alt="[Home Railway Journal]" class="ad" id="ad5"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="' + getAd('ad5').buttonOutImage.src + '"' + 
      ' title="This button opens the Home Railway Journal page."/></td>' + 
      '<td class="adGap" nowrap="1"/>' + 
      '<td class="ad" onclick="go(\'http://www.bryterails.com/index.htm?p=p400\')">' + 
      '<img alt="[BryteRails]" class="ad" id="ad6"' + 
      ' onmouseover="doButtonOver(this);" onmouseout="doButtonOut(this);"' + 
      ' src="' + getAd('ad6').buttonOutImage.src + '"' + 
      ' title="This button opens the BryteRails page."/></td>' + 
      '</tr>' + 
      '</table>';
   if((element = document.getElementById("ads")) != null) {
      element.innerHTML = html;
   }

   if(initialSelectID >= 0) {
      if(markerInfos[initialSelectID].mapStart == true) {
         alert("This marker is only intended for a start of map directions.  " + 
               "This is not the exact location for this live steam track.");
      }
      else if(markerInfos[initialSelectID].exact == false) {
//       zoomInEnabled   = false;
         initialSelectID = initialSelectSID;

         alert("Sorry, but either that live steam track's exact location " + 
               "is unknown or it has been requested that it not be " + 
               "shown.");
      }

//    window.status = 
//       'Setting the initial live steam track coordinates ...';

      map.SetMapMode(VEMapMode.Mode2D);
      map.SetCenterAndZoom(
         new VELatLong(
            markerInfos[initialSelectID].lat,markerInfos[initialSelectID].lng),
         parseInt(markerInfos[initialSelectID].zoomIn));
      if(markerInfos[initialSelectID].country || 
         markerInfos[initialSelectID].state || 
         markerInfos[initialSelectID].mapStart) {
         map.SetMapStyle(VEMapStyle.Road);
      }
      else {
         map.SetMapStyle(VEMapStyle.Aerial);
      }
   }

   updateZoomLevelDisplay();

   if((element = document.getElementById('loadingWindow')) != null) {
      element.style.display = 'none';
   }

// window.status = 'Live steam tracks map loaded';
}

function readCookie(name) {
	 var nameEQ = name + "=";
	 var ca     = document.cookie.split(';');

	 for(var x=0; x<ca.length; x++) {
       var c = ca[x];
       while(c.charAt(0) == ' ')
          c = c.substring(1,c.length);
       if(c.indexOf(nameEQ) == 0)
          return c.substring(nameEQ.length,c.length);
	 }

	 return(" ");
}

function selectItem(itemIndex) {
   var selected = document.forms[0].list.selectedIndex;

   document.forms[0].list.selectedIndex = itemIndex; 
// zoomInEnabled = (markerInfos[selected].exact) ? true : false;
   selectTrack();
}

function selectTrack() {
   var element   = null;
   var selection = document.forms[0].list;

   if(markerInfos[selection.selectedIndex].country || 
      markerInfos[selection.selectedIndex].state) {
      zoomToMap();
   }
   else {
//    zoomInEnabled = (markerInfos[selection.selectedIndex].exact) 
//       ? true : false;
//
//    if((element = document.getElementById('zoomIn')) != null) {
//       element.style.cursor = 'Auto';
//       element.src = 
//          (zoomInEnabled) 
//       ? getButton('zoomIn').buttonOutImage.src 
//       : getButton('zoomIn').buttonDisabledImage.src;
//    }

      map.SetMapMode(VEMapMode.Mode2D);

//    if(zoomInEnabled) {
         map.SetCenterAndZoom(
            new VELatLong(
               markerInfos[selection.selectedIndex].lat,
               markerInfos[selection.selectedIndex].lng),
            parseInt(markerInfos[selection.selectedIndex].zoomIn));
         map.SetMapStyle(VEMapStyle.Aerial);
//    }
//    else {
//       map.SetCenterAndZoom(
//          new VELatLong(
//             markerInfos[selection.selectedIndex].lat,
//             markerInfos[selection.selectedIndex].lng),
//          parseInt(markerInfos[selection.selectedIndex].zoomOut));
//       map.SetMapStyle(VEMapStyle.Road);
//    }
   }

   updateZoomLevelDisplay();
}

function setMenuTimeout(element) {
   var object = null;

   clearMenuTimeout(element);

   if(isCountryMenu(element)) {
      object = getCountryByMenu(element);
      object.timerID = 
         setTimeout(
            'closeFlagMenu("' + object.abbreviation1 + 'Menu")',MENU_TIMEOUT);
   }
}

function translateCountry(country) {
	var country2 = country;

	if(country == 'AF')       { country2 = 'Africa'; }
   else if(country == 'AU')  { country2 = 'Australia'; }
   else if(country == 'AT')  { country2 = 'Austria'; }
   else if(country == 'BE')  { country2 = 'Belgium'; }
	else if(country == 'CA')  { country2 = 'Canada'; }
   else if(country == 'CAS') { country2 = 'Canadian Suppliers'; }
   else if(country == 'CH')  { country2 = 'Switzerland'; }
   else if(country == 'ES')  { country2 = 'Spain'; }
	else if(country == 'FR')  { country2 = 'France'; }
   else if(country == 'GR')  { country2 = 'Germany'; }
   else if(country == 'HU')  { country2 = 'Hungary'; }
   else if(country == 'IN')  { country2 = 'India'; }
   else if(country == 'JP')  { country2 = 'Japan'; }
   else if(country == 'NL')  { country2 = 'Neatherlands'; }
   else if(country == 'NZ')  { country2 = 'New Zealand'; }
	else if(country == 'UK')  { country2 = 'United Kingdom'; }
   else if(country == 'UKS') { country2 = 'United Kingdom Suppliers'; }
	else if(country == 'US')  { country2 = 'United States'; }
   else if(country == 'USS') { country2 = 'United States Suppliers'; }

	return(country2);
}

function translateState(state1,country) {
	var state2 = state1;

   if(state1 == 'AB')       { state2 = 'Alberta'; }
	else if(state1 == 'ACT') { state2 = 'Australian Capital Territory'; }
   else if(state1 == 'AK')  { state2 = 'Alaska'; }
   else if(state1 == 'AL')  { state2 = 'Alabama'; }
   else if(state1 == 'AR')  { state2 = 'Arkansas'; }
   else if(state1 == 'AW')  { state2 = 'Antwerp'; }
   else if(state1 == 'AZ')  { state2 = 'Arizona'; }
   else if(state1 == 'BC')  { state2 = 'British Columbia'; }
   else if(state1 == 'CA')  { state2 = 'California'; }
   else if(state1 == 'CO')  { state2 = 'Colorado'; }
   else if(state1 == 'CT')  { state2 = 'Connecticut'; }
   else if(state1 == 'DC')  { state2 = 'District Of Columbia'; }
   else if(state1 == 'DE')  { state2 = 'Delaware'; }
   else if(state1 == 'ENG') { state2 = 'England'; }
   else if(state1 == 'FL')  { state2 = 'Florida'; }
   else if(state1 == 'GA')  { state2 = 'Georgia'; }
   else if(state1 == 'HI')  { state2 = 'Hawaii'; }
   else if(state1 == 'IA')  { state2 = 'Iowa'; }
   else if(state1 == 'ID')  { state2 = 'Idaho'; }
   else if(state1 == 'IL')  { state2 = 'Illinois'; }
   else if(state1 == 'IN')  { state2 = 'Indiana'; }
   else if(state1 == 'KS')  { state2 = 'Kansas'; }
   else if(state1 == 'KY')  { state2 = 'Kentucky'; }
   else if(state1 == 'LA')  { state2 = 'Louisiana'; }
   else if(state1 == 'MA')  { state2 = 'Massachusetts'; }
   else if(state1 == 'MB')  { state2 = 'Manitoba'; }
   else if(state1 == 'MD')  { state2 = 'Maryland'; }
   else if(state1 == 'ME')  { state2 = 'Maine'; }
   else if(state1 == 'MI')  { state2 = 'Michigan'; }
   else if(state1 == 'MN')  { state2 = 'Minnesota'; }
   else if(state1 == 'MO')  { state2 = 'Missouri'; }
   else if(state1 == 'MS')  { state2 = 'Mississippi'; }
   else if(state1 == 'MT')  { state2 = 'Montana'; }
   else if(state1 == 'NC')  { state2 = 'North Carolina'; }
   else if(state1 == 'ND')  { state2 = 'North Dakota'; }
   else if(state1 == 'NE')  { state2 = 'Nebraska'; }
   else if(state1 == 'NH')  { state2 = 'New Hampshire'; }
   else if(state1 == 'NI')  { state2 = 'North Island'; }
   else if(state1 == 'NIR') { state2 = 'Northern Ireland'; }
   else if(state1 == 'NJ')  { state2 = 'New Jersey'; }
   else if(state1 == 'NM')  { state2 = 'New Mexico'; }
   else if(state1 == 'NS')  { state2 = 'Nova Scotia'; }
   else if(state1 == 'NSW') { state2 = 'New South Wales'; }
   else if(state1 == 'NV')  { state2 = 'Nevada'; }
   else if(state1 == 'NY')  { state2 = 'New York'; }
   else if(state1 == 'OH')  { state2 = 'Ohio'; }
   else if(state1 == 'OK')  { state2 = 'Oklahoma'; }
   else if(state1 == 'ON')  { state2 = 'Ontario'; }
   else if(state1 == 'OR')  { state2 = 'Oregon'; }
   else if(state1 == 'PA')  { state2 = 'Pennsylvania'; }
   else if(state1 == 'RI')  { state2 = 'Rhode Island'; }
	else if(state1 == 'QC')  { state2 = 'Quebec'; }
   else if(state1 == 'QLD') { state2 = 'Queensland'; }
   else if(state1 == 'SA')  { state2 = 'South Australia'; }
   else if(state1 == 'SAF') { state2 = 'South Africa'; }
   else if(state1 == 'SC')  { state2 = 'South Carolina'; }
   else if(state1 == 'SD')  { state2 = 'South Dakota'; }
   else if(state1 == 'SH')  { state2 = 'South Holland'; }
   else if(state1 == 'SI')  { state2 = 'South Island'; }
	else if(state1 == 'TAS') { state2 = 'Tasmania'; }
   else if(state1 == 'TN')  { state2 = 'Tennessee'; }
   else if(state1 == 'TX')  { state2 = 'Texas'; }
   else if(state1 == 'UT')  { state2 = 'Utah'; }
   else if(state1 == 'VA')  { state2 = 'Virginia'; }
   else if(state1 == 'VIC') { state2 = 'Victoria'; }
   else if(state1 == 'VS')  { state2 = 'Valais'; }
   else if(state1 == 'VT')  { state2 = 'Vermont'; }
   else if(state1 == 'WA') {
      if(country == 'Australia') {
         state2 = 'Western Australia';
      }
      else if(country == 'United States') {
         state2 = 'Washington';
      }
   }
   else if(state1 == 'WI')  { state2 = 'Wisconsin'; }
   else if(state1 == 'WV')  { state2 = 'West Virginia'; }
   else if(state1 == 'WY')  { state2 = 'Wyoming'; }

	return(state2);
}

function updateZoomLevelDisplay() {
   var element = null;

   if((element = document.getElementById("zoomLevel")) != null) {
      if(map != null) {
         element.value = map.GetZoomLevel();
      }
      else {
         element.value = "?";
      }
   }
}

function w(text) {
	document.write(text);
}

function zoomOutToMap() {
   var selection = document.forms[0].list;

   map.SetMapMode(VEMapMode.Mode2D);
   map.SetCenterAndZoom(
      new VELatLong(
         markerInfos[selection.selectedIndex].lat,
         markerInfos[selection.selectedIndex].lng),
      parseInt(markerInfos[selection.selectedIndex].zoomOut) + 1);
   map.SetMapStyle(VEMapStyle.Road);

   map.SetMapMode(VEMapMode.Mode2D);
   map.SetCenterAndZoom(
      new VELatLong(
         markerInfos[selection.selectedIndex].lat,
         markerInfos[selection.selectedIndex].lng),
      parseInt(markerInfos[selection.selectedIndex].zoomOut));
   map.SetMapStyle(VEMapStyle.Road);

   updateZoomLevelDisplay();
}

function zoomToMap() {
   var selection = document.forms[0].list;

   map.SetMapMode(VEMapMode.Mode2D);
   map.SetCenterAndZoom(
      new VELatLong(
         markerInfos[selection.selectedIndex].lat,
         markerInfos[selection.selectedIndex].lng),
      parseInt(markerInfos[selection.selectedIndex].zoomIn) + 1);
   map.SetMapStyle(VEMapStyle.Road);

   map.SetMapMode(VEMapMode.Mode2D);
   map.SetCenterAndZoom(
      new VELatLong(
         markerInfos[selection.selectedIndex].lat,
         markerInfos[selection.selectedIndex].lng),
      parseInt(markerInfos[selection.selectedIndex].zoomIn));
   map.SetMapStyle(VEMapStyle.Road);
}

if(top.location != self.location) {
   top.location = self.location;
}

try {
   var url1 = top.location.href;
   var url2 = 'www.livesteamtracks.info';
   if(url1.substr(0,7) == 'http://') {
      if((x = url1.indexOf(url2)) >= 0) {
         top.location.href = url1.substr(0,x) + url1.substr(x + 4);
      }
   }

   parseURL();
   var variableList = variables.split("&");

   for(var x=0; x<variableList.length; x++) {
      var pair = variableList[x].split("=");

      if(isCountry(pair[0])) {
         initialID = getCountryByAbbrev(pair[0]).abbreviation2;
      }
      else if(pair[0] == 'debug') {
         debug = true;
      }
      else if(pair[0] == 'markerid') {
         initialID = pair[1];
      }
      else if(pair[0] == 'supp') {
         allGauges       = false;
         suppliersOption = true;
      }
      else if(isGauge(pair[0])) {
         allGauges                = false;
         getGauge(pair[0]).option = true;
      }
   }

// initialID = 'GR-MBC';
// alert("Testing!!! - " + initialID);
}
catch(exception) {
   alert(
      'Exception: ' + exception.toString()  + '\n\n' + 
      'Platform: '  + navigator.platform    + '\n\n' + 
      'AppName: '   + navigator.appName     + '\n\n' + 
      'CodeName: '  + navigator.appCodeName + '\n\n' + 
      'Version: '   + navigator.appVersion);
}

