// JavaScript Document
//last mod : 11-07-2007
function xmlHttp(url,method,data,responseHandler){
if (!(method)){method="get"}
/*
IMPORTENT
1.
the xmlHttp.onreadystatechange has to be before the xmlHttp.send 
otherwise is stay null and no event changing is trigered
2.
changing the setRequestHeader requeired for ASP request form to tell the page that has POST data coming 
otherwise ASP request.form will not response
{ PHP can use $GLOBALS['HTTP_RAW_POST_DATA'] without that ;}
*/
try {	
		var xmlHttp = createXMLHttp();
		if (!xmlHttp) return;		
		xmlHttp.open(method, url, false); // false : not asyncronous I.E http://www.webopedia.com/TERM/A/asynchronous.html	
		
		xmlHttp.onreadystatechange = function() 
			{	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 &&	xmlHttp.responseText) 
				{		responseHandler(xmlHttp.responseText)			}
			}
		
		if (method.toLowerCase()=="post"){
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
		xmlHttp.send(data)
			}else{
		xmlHttp.setRequestHeader("Content-Type","text/html")
		xmlHttp.send(null);
		}
		

	}	
	catch (e) {
		console.log("Error accord:"+e)
		}

}

function createXMLHttp() {
	if (!(document.getElementsByTagName || document.all))
		return;		
	var ret = null;
	try {
		ret = new ActiveXObject('Msxml2.XMLHTTP');
	}	catch (e) {
	    try {
	        ret = new ActiveXObject('Microsoft.XMLHTTP');
	    } catch (ee) {
	        ret = null;
	    }
	}
	if (!ret && typeof XMLHttpRequest != 'undefined')
	    ret = new XMLHttpRequest();	
	return ret;
}
