var TS = {

  init: function() {
    if (!document.getElementById) {
      TS.warn('Sorry, but your browser does not support this application');
      return;
    }

    TS.addEvent(document.getElementById('trackselect'), 'change', TS.selectTrack, false);
   },

  // Cross-browser add event listener to element
  addEvent: function(elm, evType, callback, useCapture) {
    if (elm.addEventListener) {
      elm.addEventListener(evType, callback, useCapture);
      return true;
    } else if (elm.attachEvent) {
      var r = elm.attachEvent('on' + evType, callback);
      return r;
    } else {
      elm['on' + evType] = callback;
    }
  },

  selectTrack: function(e) {
      var target = window.event ? window.event.srcElement : e ? e.target : null;
      if (!target) {
        return;
      }

  	  var gpxPath = target.value;

  	  if (gpxPath == 'none') {
  	    return;
  	  }
      // alert(gpxPath);
      // getGPX(gpxPath);
      document.location.href='catalunya-2005.html?url=' + gpxPath;
      if (window.event) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
        return;
      }

      if (e) {
        e.stopPropagation();
        e.preventDefault();
      }

  },

 warn: function(msg) {
    alert('WARNING: ' + msg);
  }

}

TS.addEvent(window, 'load', TS.init, false);
