var element_cache = {};
function $(id) {
  return element_cache[id] || (element_cache[id] = document.getElementById(id));
}
function trim_both(s) {
  return s.replace(/^[\s　]+|[\s　]+$/g, "");
}
function escape_html(s) { 
  return s.
    replace(/&/g, "&amp;").
    replace(/"/g, "&quot;").
    replace(/'/g, "&#039;").
    replace(/</g, "&lt;").
    replace(/>/g, "&gt;");
}
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();
  if (!http) return;
  http.open(method, url, async);
  if (method == "POST") {
    http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
  }
  if (callback) {
    http.onreadystatechange = function() {
      if (http.readyState == 4 && http.status == 200) {
        callback(http);
      }
    };
  }
  http.send(data);
}
function get_form_data(form) {
  var value = "";
  for(var i = 0; i < form.elements.length; i++) {
    var e = form.elements[i];
    if (!e.type.match(/^(radio|checkbox)$/) || e.checked) {
      value += ("&" + form.elements[i].name + "=" + form.elements[i].value);
    }
  }
  return value.substring(1);
}
// overture
function overture_ad(id, cat, keyword, count) {
  var url = [
    "http://im.ov.yahoo.co.jp/js_flat/?",
    "source=", "eigacom_jp_cat_ctxt",
    "&type=", cat,
    "&ctxtKeywords=", encodeURIComponent(keyword),
    "&ctxtId=", cat,
	"&ctxtUrl=", encodeURI(window.location.href),
    "&keywordCharEnc=", "utf8",
    "&outputCharEnc=", "utf8",
    "&maxCount=", count.toString()
  ].join("");
  document.write('<' + 'script type="text/javascript" src="' + url + '"><' + '/script>');
  setTimeout('overture_im("' + id + '")', 200);
}
function overture_keyword_ad(id, keyword, count) {
  var url = "/ad/query_overture_keyword?url=" + encodeURIComponent(window.location.href) + "&keyword=" + encodeURIComponent(keyword) + "&count=" + encodeURIComponent(count);
  do_request(url, "GET", null, true, function(http) {
    $(id).innerHTML = http.responseText;
  });
}
function overture_im(id, cnt) {
  var a = new Array();
  var j = 0;
  a[j++] = '<div><a href="http://listing.yahoo.co.jp/service/int/index.html" target="_blank">Ads by Yahoo! JAPAN</a></div>';
  a[j++] = '<p>';
  if (typeof zSr != "undefined") {
    var i = 6;
    while (i < zSr.length) {
      var descr = zSr[i++];
      var unused1 = zSr[i++];
      var clickURL = zSr[i++];
      var title = zSr[i++];
      var sitehost = zSr[i++];
      var unused2 = zSr[i++];
      
      a[j++] = '<a href="';
      a[j++] = clickURL;
      a[j++] = '" target="_blank"><em>';
      a[j++] = title;
      a[j++] = '</em><cite>';
      a[j++] = sitehost;
      a[j++] = '</cite><span>';
      a[j++] = descr;
      a[j++] = '</span></a>';
      if (cnt && --cnt <= 0) {
        break;
      }
    }
  }
  a[j++] = "</p>";
  $(id).innerHTML = a.join("");
}
