<!-- Hide from browsers without JavaScript support
  var commentTimeout;
  var commentPosition = 0;
  var commentLoopCount = 0;
  var commentMaxLoops = 3;
  var commentStatus = 1;
  var comments;

  // *********************************************************************** //
  // CORE AJAX ************************************************************* //
  // *********************************************************************** //
  function ajaxInit() {
    var xmlHttp;

    try {  
      // Firefox, Opera 8.0+, Safari  
      xmlHttp=new XMLHttpRequest();  

    } catch (e) {  
      // Internet Explorer  
      try {
        // Internet Explorer 6.0+
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  

      } catch (e) {    
        try {  
          // Internet Explorer 5.5+
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");   

        } catch (e) {  
          //alert("We're sorry, your browser security settings do not support XML HTTP which is required to fully use this page.");
          return false;  

        }    
      }  
    } 

    return xmlHttp;
  }

  // *********************************************************************** //
  function ajaxGetXmlNodeValue(node, index, userAgent) {
    var nodeVal; 
    var nodeIndex;

    if (userAgent.indexOf("Firefox") != -1){
      // Firefox
      nodeIndex = 2 * index + 1;
    } else if (userAgent.indexOf("Safari") != -1){
      // Safari
      nodeIndex = 2 * index + 1;
    } else {
      // Internet Explorer or other
      nodeIndex = index;
    }

    if (node.childNodes[nodeIndex].childNodes[0] != null) {
      nodeVal = node.childNodes[nodeIndex].childNodes[0].nodeValue;
    } else {
      nodeVal = "";
    }

    return nodeVal;
  }

  // *********************************************************************** //
  // MISCELLANEOUS ********************************************************* //
  // *********************************************************************** //
  function hideContent(d) {document.getElementById(d).style.display = "none";}

  function showContent(d) {document.getElementById(d).style.display = "";}

  function toggleContent(d) {
    if (document.getElementById(d).style.display == "") {
      hideContent(d);
    } else {
      showContent(d);
    }
  }

  // *********************************************************************** //
  // COMMENT SIDEBAR ******************************************************* //
  // *********************************************************************** //
  function scrollComments(action) {
    try {
      if (action == "start") {
        commentPosition = 6;
        commentStatus = 1;
        ajaxRequestComment(6, 5);
        commentTimeout = setTimeout("scrollComments('scroll')", 5000);

      } else if (action == "scroll") {
        if (commentLoopCount <= commentMaxLoops) {
          commentPosition--;
          if (commentPosition == 0) {
            // Restart loop
            commentPosition = 10;
            commentLoopCount++;
          }

          ajaxRequestComment(commentPosition, 1);
          commentTimeout = setTimeout("scrollComments('scroll')", 5000);

        } else {
          // Stop scrolling
          toggleComments();
        }

      } else if (action =="stop") {
        commentStatus = 0;
        clearTimeout(commentTimeout);
      }
    } catch(err) {
      // Ignore error
    }
  }

  // *********************************************************************** //
  function ajaxRequestComment(pos, recs) {
    // Initialize the XMLHttpRequest
    xmlHttp = ajaxInit();

    // Add the results handler
    xmlHttp.onreadystatechange=function() {ajaxCommentHandler()};

    // Query the database
    var url = "ajax-comment-query.do?position=" + pos + "&recs=" + recs;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }

  // *********************************************************************** //
  function ajaxCommentHandler() {
    if(xmlHttp.readyState==4) {
      if (xmlHttp.status == 200) {
        // Get the XML document
        var xmlDoc = xmlHttp.responseXML.documentElement;
        var userAgent = navigator.userAgent;
        //alert(xmlHttp.responseText);

        if (xmlDoc == null) {
          return false;              
        }

        // Get the comments
        comments = xmlDoc.getElementsByTagName("comment");
        if (comments == null) {
          return false;
        }

        // Refresh the displayed comments 
        refreshComments();
      }
    }
  }

  function refreshComments() {
    var i;
    for (i=comments.length - 1; i >= 0; i--) {
      // Get the comment frames
      var f1 = document.getElementById("commentsInnerFrame1");
      var f2 = document.getElementById("commentsInnerFrame2");
      var f3 = document.getElementById("commentsInnerFrame3");
      var f4 = document.getElementById("commentsInnerFrame4");
      var f5 = document.getElementById("commentsInnerFrame5");

      // Move the comments down
      f5.innerHTML = f4.innerHTML;
      f4.innerHTML = f3.innerHTML;
      f3.innerHTML = f2.innerHTML;
      f2.innerHTML = "<hr />" + f1.innerHTML;

      // Add the new first comment
      f1.innerHTML = "<a href='recent-comments.do' class='commentsInnerFrame'>" +
                     "Business: " + ajaxGetXmlNodeValue(comments[i], 0, navigator.userAgent) + "<br />" +
                     "Date: " + ajaxGetXmlNodeValue(comments[i], 5, navigator.userAgent) + "<br />" + 
                     "Name: " + ajaxGetXmlNodeValue(comments[i], 2, navigator.userAgent) + "<br />" +
                     "Rating: " + ajaxGetXmlNodeValue(comments[i], 3, navigator.userAgent) + "<br />" +
                     "Comments: " + ajaxGetXmlNodeValue(comments[i], 4, navigator.userAgent) + "<br />" +
                     "</a>";
    }
  }

  function toggleComments() {
    if (commentStatus == 1) {
      // Pause the comments
      document.getElementById("commentControl").innerHTML = "(Play)";
      scrollComments("stop");

    } else {
      // Play the comments
      document.getElementById("commentControl").innerHTML = "(Stop)";
      scrollComments("start");

    }

    return true;
  }

  // *********************************************************************** //
  // iPHONE COMMON ********************************************************* //
  // *********************************************************************** //
  function ajaxRequestComments(registryId, addressId) {
    // Initialize the XMLHttpRequest
    //document.getElementById("message").innerHTML = "Initializing request...";
    xmlHttp = ajaxInit();

    // Add the results handler
    xmlHttp.onreadystatechange=function() {ajaxCommentsHandler()};

    // Query the database
    //document.getElementById("message").innerHTML = "Requesting comments. Please wait...";
    var url = "ajax-comments-query.do?registryId=" + registryId + "&addressId=" + addressId;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }

  // *********************************************************************** //
  function ajaxCommentsHandler() {
    if(xmlHttp.readyState==4) {
      if (xmlHttp.status == 200) {
        // Get the XML document
        //document.getElementById("message").innerHTML = "Receiving comments...";
        var xmlDoc = xmlHttp.responseXML.documentElement;
        var userAgent = navigator.userAgent;

        if (xmlDoc == null) {
          document.getElementById("message").innerHTML = "Could not load results. Please try again.";
          return false;              
        }

        // Get the comments
        comments = xmlDoc.getElementsByTagName("comment");
        if (comments == null) {
          document.getElementById("message").innerHTML = "No comments found";
          return false;
        }

        // Update the message
        //document.getElementById("message").innerHTML = comments.length + " comments received. ";

        // Update the page
        commentIndex = 1;
        hideContent("mapBody");
        showContent("commentBody");
        displayComment(commentIndex);

      } else {
        alert ( "Not able to retrieve data: status = " + xmlHttp.status );
      }
    }
  }
  
  // *********************************************************************** //
  function displayComment(i) {
    // Check if scrolling past beginning or end
    if (i > comments.length) {
      // Go to the beginning
      i = 1;
    } else if (i < 1) {
      // Go to end
      i = comments.length;      
    }

    // Update the comment index
    commentIndex = i;

    // Update the display
    document.getElementById("cBusinessName").innerHTML = ajaxGetXmlNodeValue(comments[i - 1], 0, navigator.userAgent);

    if (ajaxGetXmlNodeValue(comments[i - 1], 1, navigator.userAgent) == "1") {
      document.getElementById("cLocation").innerHTML = "(this location)";
    } else {
      document.getElementById("cLocation").innerHTML = "(different location)";
    }

    document.getElementById("cDate").innerHTML = "Date: " + ajaxGetXmlNodeValue(comments[i - 1], 5, navigator.userAgent);
    document.getElementById("cDisplayName").innerHTML = "Name: " + ajaxGetXmlNodeValue(comments[i - 1], 2, navigator.userAgent);
    
    if (ajaxGetXmlNodeValue(comments[i - 1], 3, navigator.userAgent) == "0") {
      document.getElementById("cRating").innerHTML = "Rating: Not Rated";
     } else {
      document.getElementById("cRating").innerHTML = "Rating: " + ajaxGetXmlNodeValue(comments[i - 1], 3, navigator.userAgent);
    }

    document.getElementById("cComment").innerHTML = ajaxGetXmlNodeValue(comments[i - 1], 4, navigator.userAgent);
    document.getElementById("cPosition").innerHTML = "Comment: " + i + " of " + comments.length;
  }

-->