// JavaScript Document
var request=null;
/* Prameters:
reqType: The HTTP request type, such as GET or POST.
url: The URL of the server program
asynch: Whether send request asynchronously or not.
resHandle: The name of the function that will handle the response
Any fifth parameters, represented as arguments[4],are the data a POST request is designed to send.*/
function httpRequest(reqType,url,asynch,respHandle){
	//Mozilla-based browsers
	if(window.XMLHttpRequest){
		request = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		request = new ActiveXObject("Msxml2.XMLHttp");
		if(! request){
			request=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	//very Unlikely, but we test for a null request
	//if neither ActiveXObject was initialized
	if(request){
		//if the reqType is POST, then the 5th argument to the function is the POSTED data
		if(reqType.toLowerCase()!="post"){
			initReq(reqType,url,asynch,respHandle);	
		}else {
			//the POSTED data
			var args=arguments[4];
			if(args!=null && args.length>0){
				initReq(reqType,url,asynch,respHandle,args);
			}
		}
	}else {
		alert("!! مرورگر شما اجازه استفاده از این سایت را نمی دهد");	
	}
}
/*Initialize a request object that is already constructed*/
function initReq(reqType,url,bool,respHandle){
	try{
		/*Specify the function that will handle the HTTP response*/	
		request.onreadystatechange=respHandle;
		request.open(reqType,url,bool);
		//if the reqType is POST, then the 5th argument to the function is the POSTED data
		if(reqType.toLowerCase()=="post"){
			request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			request.send(arguments[4]);
		}else {
			request.send(null);	
		}
	}catch(errv){
		alert(".سرور مرکزی اشغال می باشد، لطفا دوباره سعی کنید");	
	}
}