function addListener(elem, eventType, func, cap)
{
    if(elem.addEventListener)
    {
        elem.addEventListener(eventType, func, cap);
    }
    else if(elem.attachEvent)
    {
        elem.attachEvent('on' + eventType, func);
    }
}

function httpXmlRequest(target_url, method, data, success_func, error_func) {
	try {
		if(window.XMLHttpRequest) {
			var httpObj = new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			var httpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			var httpObj = false;
		}
	} catch(e) {
		httpObj = false;
	}
	if(! httpObj) alert('Error');
	var timeout_sec=10;
	var timerId = setInterval(function (){
		timeout_sec--;
		if(timeout_sec<=0){
			clearInterval(timerId);
			httpObj.abort();
			alert('time out !');
		}
	}, 1000);
	httpObj.open(method, target_url, true);
	httpObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');//for POST to PHP
	httpObj.onreadystatechange = function() {
		if (httpObj.readyState == 4) {
			clearInterval(timerId);
			if (httpObj.status == 200) {
				success_func(httpObj);
			} else {
				error_func(httpObj.status + ' : ' + httpObj.statusText);
				return false;
			}
		}
	}
    	httpObj.send(data);
}

function ef(error){alert(error);}
