function get_http_request() {
  try {
    return new XMLHttpRequest();
  } catch (e) {
    try {
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e2) {
      try {
        return new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e3) {
        return null;
      }
    }
  }
}

function do_request(url, method, data, async, callback) {
  var http = get_http_request();
  http.open(method, url, async);
  if (callback) {
    http.onreadystatechange = function() {
      if (http.readyState == 4 && http.status == 200) {
        callback(http);
      }
    };
  }
  http.send(data);
}

function overture_ad(pos, cat, keyword, count) {
  var url_base = "/ad/query_overture";
  var param = "url=" + encodeURIComponent(window.location.href) +
              "&category=" + encodeURIComponent(cat) +
              "&keyword=" + encodeURIComponent(keyword) +
              "&count=" + encodeURIComponent(count);
  do_request(url_base + "?" + param, "GET", null, true, function(http) {
    document.getElementById(pos).innerHTML = http.responseText;
  });
}
