function createHttpRequest() {
 var xmlhttp = false;

 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  xmlhttp = new XMLHttpRequest();
 }
 return xmlhttp;
}

function set_calendar(y, m) {
 var path = "http://hzk.sytes.net/hblog/modules/calendar?calendar_year="+y+"&calendar_month="+m+"&move=1";
 var xmlhttp = createHttpRequest();
 xmlhttp.open("GET", path, true);

 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
   document.getElementById("calendar").innerHTML = xmlhttp.responseText;
  }
 }
 xmlhttp.send(null)
}

function go_prev(y, m) {
 if (m == 1) {
  y = y - 1;
  m = 12;
 } else {
  m = m - 1;
 }
 
 set_calendar(String(y), String(m));
}

function go_next(y, m) {
 if (m == 12) {
  y = y + 1;
  m = 1;
 } else {
  m = m + 1;
 }
 
 set_calendar(String(y), String(m));
}

function show_topics(y, m, d, aid) {
 var topics = '<div align="right"><a href="javascript:close_topics()" title="ÊÄ¤¸¤ë">¡ß</a></div>';
 var path = 'http://matatabi.homeip.net/blog/setomits/daylist_xml?year='+y+'&amp;month='+m+'&amp;day='+d;
 var xmlhttp = createHttpRequest();
 xmlhttp.open("GET", path, true);

 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
   var entries = xmlhttp.responseXML.getElementsByTagName('entry');
   topics += '<div style="margin: 0px 1em 0px">';
   for (var i=0; i<entries.length; i++) {
    var e = entries[i];
    topics += '- <a href="'+e.getAttribute('link')+'">'+e.getAttribute("title")+'</a><br />';
   }
   topics += '</div>';

   var l = 0, t = 0;
   for (var obj = document.getElementById(String(aid)); obj != null; obj = obj.offsetParent) {
    l += obj.offsetLeft;
    t += obj.offsetTop;
   }
   var wwidth = window.innerWidth ? window.innerWidth : document.body.clientWidth;
   if (l + 160 > wwidth)
    l = wwidth - 175;

   document.getElementById("topics").innerHTML = topics;
   document.getElementById("topics").style.top = t + 10+"px";
   document.getElementById("topics").style.left = l +10 +"px";
   document.getElementById("topics").style.visibility = "visible";
  }
 }
 xmlhttp.send(null)
}

function close_topics() {
 document.getElementById("topics").style.visibility ="hidden";
}

function get_hb_count(u) {
 var path = "http://matatabi.homeip.net/blog/setomits/get_sbm_count?url=" + u;
 var xmlhttp = createHttpRequest();
 xmlhttp.open("GET", path, true);

 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
   alert(xmlhttp.responseText);
  }
 }
 xmlhttp.send(null)
}
