// Copyright : IDOY Co., Ltd.
// 2008-06-30 01:19
// 2008-07-14 22:22

/* var imgloading = new Image();
imgloading.src = "images/loader.gif";
idoy.loading = '<img src="'+ imgloading.src +'" /> ...Loading';
idoy.loading = '...Loading';
*/

function iHTTP() {
	var iHttp=false;
	if (window.XMLHttpRequest) {
		iHttp = new XMLHttpRequest(  );
	} else {
		try {
			iHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				iHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return iHttp;
}

// 2009-11-12 19:54
function iLoading(id, load) {
	var width = $i(id).offsetWidth;
	var height = $i(id).offsetHeight;
	var divTag = document.createElement("div");
	divTag.id = "div-loading";
	divTag.setAttribute("align","center");
	divTag.style.position = "relative";
	divTag.style.top =  parseInt(-($i(id).offsetHeight/2)-30)+"px";
	divTag.style.width = $i(id).offsetWidth+"px";
	divTag.style.height = $i(id).offsetHeight+"px";
	divTag.innerHTML = load;
	$i(id).appendChild(divTag);
}

// 2008-07-11 00:20
function iGetReturnText(to, id, url, cache, ajax, parameters) {
	var iHttp = iHTTP();
	if(iHttp){
		if (to == 'innerHTML') {
			if(typeof idoy.loading == 'undefined') {
				if($i(id).offsetHeight < 30) {
					$i(id).innerHTML = '<img src="'+ idoy.jspath +'/loader.gif"/> ...loading';
				} else {
					idoy.loading = '<img src="'+ idoy.jspath +'/loader2.gif"/><br /><br />...loading';
					iLoading(id, idoy.loading);
				}
			} else {
				iLoading(id, idoy.loading);
			}
		}
		url = encodeURI(url);
		if(ajax == 'POST') {
			iHttp.open("POST", url, false);
			iHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		} else {
			if(cache != 'cache') url+=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
			iHttp.open("GET", url);
		}
		iHttp.onreadystatechange = function() {
			if (iHttp.readyState == 4 && iHttp.status == 200) {
				if (to == 'innerHTML') {
					document.getElementById(id).innerHTML = iHttp.responseText;
				} else if (to == 'value') {
					document.getElementById(id).value = iHttp.responseText;
				} else if (to == 'JSON') {
					idoy[id] = eval('(' +iHttp.responseText+ ')');
				} else if (to == 'iVar') {
					idoy[id] = iHttp.responseText;
				} else if (to == 'iFunc') {
					$i(iHttp.responseText);
				}
				delete iHttp;
				iHttp = null;
				if(typeof iFrame == 'function') iFrameRefresh();
			}
		}
		if(ajax == 'POST') {
			iHttp.send(parameters);
		} else {
			iHttp.send(null);
		}
	}
}

// 2008-08-10 02:16
function iPostReturnText(to, id, url, parameters) {
	iGetReturnText(to, id, url, '', 'POST', parameters)
}

// 2008-09-02 00:03
function iGetCookie(name) {
	var gc = document.cookie;
	if (gc.length>0) {
		var begin = gc.indexOf(name + "=");
		if (begin != -1) {
			begin += name.length+1;
			var end = gc.indexOf(";", begin);
			if (end == -1) end=document.cookie.length;
			return unescape(gc.substring(begin,end));
		}
	}
	return "";
}

// 2008-10-03 00:44
function iTree(e) {
	if (!e) var e=window.event;
	var ie; if (e.target) ie=e.target;
	else if (e.srcElement) ie=e.srcElement;
	if (ie.nodeType==3)ie=ie.parentNode;
	if(ie.tagName == 'LI'){
		if (ie.className == 'n') {
			ie.className = 'o';
			$i('ul-'+ie.id).style.display = '';
			var tid = ie.id.split("-")[1];
			iGetReturnText('innerHTML', 'ul-'+ie.id, idoy.tree_url+tid);
		} else if (ie.className == 'c') {
			ie.className = 'o';
			$i('ul-'+ie.id).style.display = '';
		} else if (ie.className == 'o') {
			ie.className = 'c';
			$i('ul-'+ie.id).style.display = 'none';
		}
	}
}

// 2009-11-12 09:27
function iGet(div, func) {
	iGetReturnText('innerHTML', div, document.URL+'&e='+func, 'cache');
}

// 2009-11-10 18:15
function iContent(url) {
	if(typeof url == 'object') {
		var go = url.href;
		url.href = 'javascript:void(0)';
		url.onclick = function(){ iContent(go); };
	} else {
		var go = url;
	}
	iGetReturnText('innerHTML', 'content-main', go+'&e=content', 'cache');
}

// 2009-10-28 01:25
function iPage(url) {
	var go = url.href;
	iGetReturnText('innerHTML', 'content-page', go+'&e=process', 'cache');
	url.href = 'javascript:void(0)';
}

// 2009-10-28 01:25
function iPageof() {
	var url = $i('_base').value+'&page='+$i('_page').value+$i('_ext').value+'&e=process';
	iGetReturnText('innerHTML', 'content-page', url, 'cache');
	return false;
}

