/*
 * imaptools.js
 * $Id: $
 *
 * Some additional utilities used by the iMaptools.com Demo Application.
 *
 * Copyright 2006, Stephen Woodbridge, All Rights Reserved.
 * info@imaptools.com
 * http://imaptools.com/
 *
*/
        var last = '';
        
        function updateMap(mf, map) {
            var myMap = eval(map);
            myMap.setMapFile( '/u/data/maps/'+mf+'.map');
            myMap.setBookmark('bookmark', mf);
            if (mf == 'phila') {
                last = mf;
                myMap.setFullExtent( 2582172.1, 2840936.3, 187185.8 );
                //myMap.setFullExtent( 2660574.997, 2750112.778, 204651.048, 304942.428 );
            }
            else if (mf == 'vmap0-1') {
                last = mf;
                myMap.setFullExtent( -180.0, 180.0, -90.0, 90.0 );
                //myMap.setExtent( -180.0, 180.0, -90.0, 90.0 );
            }
            else if (last == 'phila' || last == 'vmap0-1') {
                myMap.setFullExtent( -160.0, -60.0, 15.0, 75.0 );
                //myMap.setExtent( -160.0, -60.0, 15.0, 75.0 );
            }
            last = mf;
            myMap.redraw();
        }

        function getget(name) {
          var q = document.location.search;
          var i = q.indexOf(name + '=');

          if (i == -1) {
            return false;
          }

          var r = q.substr(i + name.length + 1, q.length - i - name.length - 1);

          i = r.indexOf('&');

          if (i != -1) {
            r = r.substr(0, i);
          }

          return r.replace(/\+/g, ' ');
        }

    // add a function to parse the url into a hash

    jQuery.query = function(q) {
        var r = {};
        q = q || location.search;    
        q = q.replace(/^\?/,''); // remove the leading ?    
        q = q.replace(/\&$/,''); // remove the trailing &
        if (q.indexOf('#') != -1) {
            r['#'] = q.substr(q.indexOf('#')+1, q.length - q.indexOf('#') - 1);
            q = q.substr(0, q.indexOf('#'));
        }
        jQuery.each(q.split('&'), function(){
            var key = this.split('=')[0];
            var val = this.split('=')[1];
            // convert floats
            if(/^[0-9.]+$/.test(val))
                val = parseFloat(val);
            // ingnore empty values
            if(val)
                r[key] = val;
        });
        return r;
    };

    // function to dump contents of an object

    var MAX_DUMP_DEPTH = 10;
    function dumpObj(obj, name, indent, depth) {
        if (depth > MAX_DUMP_DEPTH) {
            return indent + name + ": <Maximum Depth Reached>\n";
        }
        if (typeof(obj) == "object") {
            var child = null;
            var output = indent + name + "\n";
            indent += "\t";
            for (var item in obj)
            {
                  try {
                      child = obj[item];
                  } catch (e) {
                      child = "<Unable to Evaluate>";
                  }
                  if (typeof(child) == "object") {
                      output += dumpObj(child, item, indent, depth + 1);
                  } else {
                      output += indent + item + ": " + child + "\n";
                  }
            }
            return output;
        } else {
            return obj;
        }
    }

    function dumpObjLog(obj, name, indent, depth) {
        if (depth > MAX_DUMP_DEPTH) {
            console.log(indent + name + ": <Maximum Depth Reached>");
        }
        if (typeof(obj) == "object") {
            var child = null;
            console.log(indent + name);
            indent += "\t";
            for (var item in obj)
            {
                  try {
                      child = obj[item];
                  } catch (e) {
                      child = "<Unable to Evaluate>";
                  }
                  if (typeof(child) == "object") {
                      dumpObjLog(child, item, indent, depth + 1);
                  } else {
                      console.log(indent + item + ": " + child);
                  }
            }
            console.log(obj);
        }
    }

