﻿function sendRequest(method, url, args, async, onReadyStateChangeFunction) {
	var http = getXmlHttpObject();
	
	if (http == null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	if (typeof(onReadyStateChangeFunction) == "function") http.onreadystatechange = onReadyStateChangeFunction;
	method = method.toUpperCase();
	switch (method) {
		case "GET" :
			if (args != '') {
				if (url.indexOf('?') > 0) {
					url += '&' + args;
				}
				else {
					url += '?' + args;
				}
			}
			http.open(method, url, async);
			http.send(null);
			break;
		case "POST"	:
			http.open(method, url, async);
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.send(args);
			break;
	}
	return http;
}

function getXmlHttpObject() { 
	var objXMLHttp = null;
	if (window.XMLHttpRequest) {
		objXMLHttp = new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

function isRequestComplete(state) {
	if (state == 4 || state == "complete") {
		return true;
	}
	else {
		return false;
	}
}


