﻿function TryThese(){
	for (i = 0; i < arguments.length; i++){
		try{
			return arguments[i]();
		}catch(e){}
	}
	return false;
}

function CreateXMLHTTP(){
	return TryThese(
		function() {return new ActiveXObject("Msxml2.XMLHTTP");},
		function() {return new ActiveXObject("Microsoft.XMLHTTP");},
		function() {return new XMLHttpRequest();}
	) || false;
}

function SendRequest(url, param, method, echofun) {
	var xmlHTTP = CreateXMLHTTP();
	if (xmlHTTP){
		xmlHTTP.onreadystatechange = function()
		{
			if (xmlHTTP.readyState == 4 && xmlHTTP.status == 200){
				if (echofun!= null){
					echofun(xmlHTTP.responseText.replace(/&amp;/g, "&"));
				}
			}
		}
		xmlHTTP.open(method, url, true);
		xmlHTTP.setRequestHeader("Content-Length",param.length); 
		xmlHTTP.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
		xmlHTTP.send(encodeURI(param));	
	}else{
		NoXMLHTTP();
	}
}

function NoXMLHTTP(){
	alert("Sorry, your browser doesn't support XMLHTTP");
}