/* 文字コードはUTF-8 */

/* XML非同期取得 */
var xmlhttp = new Object();
xmlhttp.req = new Array();
xmlhttp.res = new Array();
xmlhttp.timer = new Array();
xmlhttp.abortTime = 30000;
xmlhttp.dateObj = new Date();
xmlhttp.isWebKit = (navigator.userAgent.match(/WebKit/) ? true : false);
xmlhttp.newRequest = function (){
	var object = null;
	if(window.XMLHttpRequest){
		object = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		try{
			object = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
		}
	}
	return object;
}
xmlhttp.loadDoc = function (xml_url){
	xmlhttp.req[xml_url] = xmlhttp.newRequest();
	var method = (typeof(arguments[1]) != 'undefined' ? arguments[1] : 'get');
	var data = (typeof(arguments[2]) != 'undefined' ? arguments[2] : null);
	var async = (typeof(arguments[3]) != 'undefined' ? arguments[3] : true);
	var atime = (typeof(arguments[4]) != 'undefined' ? arguments[4] : false);
	if(xmlhttp.req[xml_url] != null){
		if(window.ActiveXObject){
			xmlhttp.req[xml_url].onreadystatechange = function(){ xmlhttp.processReqChange(xml_url); };
		}
		else{
			xmlhttp.req[xml_url].onload = function(){ xmlhttp.processOnLoad(xml_url, true); };
		}
		var reqxml_url = xml_url;
		if(atime){
			reqxml_url += (xml_url.indexOf('?') > -1 ? '&' : '?') + 't=' + xmlhttp.dateObj.getTime();
		}
		xmlhttp.req[xml_url].open(method, reqxml_url, async);
		if(window.ActiveXObject && method.toLowerCase() == 'get'){
			xmlhttp.req[xml_url].send();
		}
		else{
			if(method.toLowerCase() == 'post'){
				xmlhttp.req[xml_url].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
			}
			xmlhttp.req[xml_url].send(data);
		}
		if(async){
			xmlhttp.timer[xml_url] = setTimeout(('xmlhttp.checkStatus("' + xml_url + '");'),xmlhttp.abortTime);
		}
	}
}
xmlhttp.checkStatus = function (xml_url){
	if(typeof(xmlhttp.req[xml_url]) != 'undefined' && xmlhttp.req[xml_url].readyState < 4){
		xmlhttp.req[xml_url].abort();
		xmlhttp.processOnLoad(xml_url, false);
	}
}
xmlhttp.processReqChange = function (xml_url){
	if(xmlhttp.req[xml_url].readyState == 4){
		if(xmlhttp.req[xml_url].status < 400){
			xmlhttp.processOnLoad(xml_url, true);
		}
	}
}
xmlhttp.processOnLoad = function (xml_url, success){
	try{
		if(success){
			xmlhttp.res[xml_url].XML = xmlhttp.req[xml_url].responseXML;
			if(typeof(xmlhttp.timer[xml_url]) != "undefined"){
				clearTimeout(xmlhttp.timer[xml_url]);
			}
			xmlhttp.res[xml_url].exec();
		}
		else if(typeof(xmlhttp.res[xml_url].fail) == 'function'){
			xmlhttp.res[xml_url].fail();
		}
		delete xmlhttp.req[xml_url];
	}
	catch(e){
	}
}
xmlhttp.getNodeValue = function (object, tmp_id){
	if(tmp_id.match(/.+:(.+)/) && this.isWebKit){ tmp_id = RegExp.$1; }
	var nod = object.getElementsByTagName(tmp_id);
	if(nod.length > 0 && nod[0].hasChildNodes()){
		var value = '';
		for(var i = 0; i < nod[0].childNodes.length; i++){
			if(nod[0].childNodes.item(i).nodeType == 3 || nod[0].childNodes.item(i).nodeType == 4){
				value += nod[0].childNodes.item(i).nodeValue;
			}
		}
		return value;
	}
	return '';
}

