  function AJAX () {
    var http;

    //init the AJAX component
    try {
      // Firefox, Opera 8.0+, Safari
      http = new XMLHttpRequest();
    } catch (e) {
      // Internet Explorer
      try {
        http=new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          http=new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
          return null;
        }
      }
    }

    //sends a get command
    this.get = function(url, callback) {
      http.open("GET", url, true);

      http.onreadystatechange = function() {
        if ((http.readyState == 4) && (http.status == 200)) {
          callback(http.responseText);
        }
      }
      
      http.send(null);      
    }

    //send a post command
    this.post = function(url, message, callback) {
      http.open("POST", url, true);

      http.onreadystatechange = function() {
        if ((http.readyState == 4) && (http.status == 200)) {
          callback(http.responseText);
        }
      }

      http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http.setRequestHeader("Content-length", message.length);
      http.setRequestHeader("Connection", "close");

      http.send(message);
    }
    
    return this;
  }

  function getEventObj(e) {
    var obj;

    if (!e) {
      var e = window.event;
    }

    if (e.target) {
      obj = e.target;
    } else if (e.srcElement) {
      obj = e.srcElement;
    }

    // defeat Safari bug
    if (obj.nodeType == 3) {
      obj = obj.parentNode;
    }

    return obj;
  }  


  //Page feedback system - Rating and comments
  var feedbackId = 0;
  var currentRating = 0;
  var ratingRecorded = false;  
  var commentRecorded = false;

  function rateValue(id) {
    var value = 0;

    if ((id != null) && (id.length > "rating".length)) {
      value = parseInt(id.charAt("rating".length));

      if (isNaN(value)) {
        value = 0;
      }
    }

    return value;
  }

  function updateRating(elementName, marked) {
    if (marked) {
      document.getElementById(elementName).src = "/Graphics/StarBlue.gif";
    } else {
      document.getElementById(elementName).src = "/Graphics/StarGrey.gif";
    }
  }

  function markRating(e) {
    var element, rating;

    if ((e == null) || (ratingRecorded)) {
      rating = currentRating;
    } else {
      element = getEventObj(e);
      if (element != null) {
        rating = rateValue(element.id);
      } else { 
        rating = 0;
      }

      if (rating == 0) {
        rating = currentRating;
      }
    }

    updateRating("rating1", rating >= 1);
    updateRating("rating2", rating >= 2);
    updateRating("rating3", rating >= 3);
    updateRating("rating4", rating >= 4);
    updateRating("rating5", rating >= 5);
  }

  function toggleSendRatingBlock(Show) {
    if (Show) {
      document.getElementById("pageRatingRateBlock").style.display = "none";
      document.getElementById("pageRatingCommentBlock").style.display = "none";
      document.getElementById("pageRatingSendBlock").style.display = "block";
    } else {
      document.getElementById("pageRatingRateBlock").style.display = "block";
      document.getElementById("pageRatingCommentBlock").style.display = "block";
      document.getElementById("pageRatingSendBlock").style.display = "none";
    }
  }

  function showRatingBlocks() {
      document.getElementById("pageRatingBlock").style.display = "block";
  }

  function selectRating(e) {
    if (!ratingRecorded) {
      var element = getEventObj(e);
      currentRating = rateValue(element.id);

      if (currentRating > 0) {
        toggleSendRatingBlock(true);
        var ajaxConn = new AJAX();

        function done(message) {
          feedbackId = parseInt(message);
          ratingRecorded = true;

          document.getElementById("pageRatingRateDone").style.display = "block";

          toggleSendRatingBlock(false);
        }

        ajaxConn.post("pagefeedback.asp", "page=" + escape(window.location.href) + "&id=" + feedbackId + "&rating=" + escape(currentRating), done);
      }
    }
  }

  function sendComment() {
    if (!commentRecorded) {
      var currentComment = document.getElementById("comment").value;

      if (currentComment != "") {
        toggleSendRatingBlock(true);
        var ajaxConn = new AJAX();

        function done(message) {
          feedbackId = parseInt(message);
          commentRecorded = true;

          document.getElementById("comment").readOnly = true;
          document.getElementById("pageRatingSendComment").disabled = true;
          document.getElementById("pageRatingCommentDone").style.display = "block";

          toggleSendRatingBlock(false);
        }

        ajaxConn.post("pagefeedback.asp", "page=" + escape(window.location.href) + "&id=" + feedbackId + "&comment=" + escape(currentComment), done);
      }
    }
  }




