///////////////////////////////////Debug functions//////////////////////////////
//
// Use the debug(str) function to create debugging messages. 
// To popup the debug window simply call popupDebug(). If debug
// window never popped up then the debug call is basically a noop.
//
  // For creating debug window
  function popupDebug() {
    window.top.debugWindow =
        window.open("",
                    "Debug",
                    "left=0,top=0,width=800,height=700,scrollbars=yes,"
                    +"status=yes,resizable=yes");
    window.top.debugWindow.opener = self;
    // open the document for writing
    window.top.debugWindow.document.open();
    window.top.debugWindow.document.write(
        "<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY><B><FONT SIZE='+1'>Debug Window</FONT></B><BR><PRE>\n");
  };

  // If the debug window exists, then write to it
  function debug(text) {
    try {
      if (window.top.debugWindow && ! window.top.debugWindow.closed) {
	    var date = new Date();
	    var minutes = "" + date.getMinutes();
	    while (minutes.length < 2) {
	      minutes = "0" + minutes;
	    }
	    var seconds = "" + date.getSeconds();
	    while (seconds.length < 2) {
	      seconds = "0" + seconds;
        }
        var msec = "" + date.getTime() % 1000;
        while (msec.length < 3) {
          msec = "0" + msec;
        }
        var fullTime = date.getHours() + ":" + minutes + ":" +
                       seconds + "." + msec +
	                     " - " + text;
	    window.top.debugWindow.document.write(fullTime + "\n");
      }
    } catch (e) {
      // Don't do anything here. Simply need to handle
      // case where the google map is called by a page
      // from a different domain. For this situation
      // accessing window.top produces a "Permission
      // denied error due to the "Same Origin Policy"
      // for javascript.
    }
  };
  
  
  // For error messages. Calls debug() but causes the
  // text to be displayed in bold.
  function error(text) {
    debug("<b>ERROR: " + text + "</b>");
  }
