// originally by Tim Morgan <http://snippets.dzone.com/posts/show/2025>
// $(e)はjQueryと同時に使用するとトラブルになるので変更しています
//function $(e){if(typeof e=='string')e=document.getElementById(e);return e};
function _elem(e){if(typeof e=='string')e=document.getElementById(e);return e};
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n};
ajax={};
ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}};
ajax.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');};
ajax.send=function(u,f,m,a){var x=ajax.x();x.open(m,u,true);x.onreadystatechange=function(){if(x.readyState==4)f(x.responseText)};if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(a)};
ajax.get=function(url,func){ajax.send(url,func,'GET')};
ajax.gets=function(url){var x=ajax.x();x.open('GET',url,false);x.send(null);return x.responseText};
ajax.post=function(url,func,args){ajax.send(url,func,'POST',args)};
ajax.update=function(url,elm){var e=_elem(elm);var f=function(r){e.innerHTML=r};ajax.get(url,f)};
ajax.submit=function(url,elm,frm){var e=_elem(elm);var f=function(r){e.innerHTML=r};ajax.post(url,f,ajax.serialize(frm))};
// お知らせの表示
function detail_info(id)
{
	var url = './infocms.php?act=set_infoid&id=' + id;
	ret = ajax.gets(url);
	location = detail_html;
}
var news = document.getElementById('new');
news.innerHTML = "";
var url = './infocms.php?act=get_infolist&max=' + max_info;
ret = ajax.gets(url);
eval("var ary=" + ret + ";");
for (i in ary) {
	var item = ary[i];
	if (item.date) {
		var dtTag = document.createElement('dt');
		dtTag.innerHTML = `${item.date}<span>${item.kind}</span>`
		var ddTag = document.createElement('dd');
		if (item.link == "") {
			if (detail_html == "") {
				ddTag.innerHTML = `${item.title}`;
			} else {
				ddTag.innerHTML = `<a href="javascript:detail_info(${item.id})">${item.title}</a>`;
			}
		} else {
			ddTag.innerHTML = `<a href="${item.link}">${item.title}</a>`;
		}
		news.appendChild(dtTag);
		news.appendChild(ddTag);
	}
}
