function ServerRequest() {
	//alert("ServerRequest ");
	this.isWorking=false;
	this.req=createXMLHttpRequest();

	/*
	 * Returns a function that waits for the specified XMLHttpRequest
	 * to complete, then passes its XML response
	 * to the given handler function.
	 * req - The XMLHttpRequest whose state is changing
	 * responseXmlHandler - Function to pass the XML response to
	 */
	this.postRequest= function(xmlParseFunction, url, args, async, form, doc) {
		if(this.isWorking == true) {
			alert("Request in progress ignoring ");
			return;
		}
		if(async==true){  // call in asynchronus mode
			
			this.callAsync(xmlParseFunction,url,args);
		}
		else{		// call in synchronus mode
			
			this.callSync(xmlParseFunction,url,args, form, doc);
		}
		
	};

	this.reset= function() {
		this.isWorking=false;
		this.req=this.createXMLHttpRequest();

	};

	this.callAsync=function (xmlParseFunction,url,args) {
	var handlerFunction = getReadyStateHandler(this, xmlParseFunction);
	this.req.onreadystatechange = handlerFunction;
	this.req.open("GET", url, true);
	this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	this.isWorking=true;
	this.req.send(args);
};

this.callSync=function(xmlParseFunction,url,args, form, doc) {
	this.req.open("GET", url, false);
	this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	this.isWorking=true;
	this.req.send(args);
			var request=this.req;
			if (request.readyState == 4) {
				// Check that a successful server response was received
				if (request.status == 200) {
					// Pass the XML payload of the response to the 
					// handler function
					xmlParseFunction(request.responseXML, form, doc);
					this.isWorking=false;
				} else {
					// An HTTP problem has occurred
					//alert("HTTP error: "+this.req.status);
					parent.document.getElementById("nestFRAME").src = "systemUnavailable.html";
				}
			
		}
};
}


function createXMLHttpRequest() {
	var _req;
	// branch for native XMLHttpRequest object (safari/mozilla)
	if (window.XMLHttpRequest) {
	_req = new XMLHttpRequest();
	}
	// branch for IE/Windows ActiveX version
	else if (window.ActiveXObject) {
	_req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return _req;
}

function getReadyStateHandler(obj, responseXmlHandler) {
	var request=obj.req;

	if(request == null) {
		alert("The request IS NULL");
	}
	// Return an anonymous function that listens to the 
	// XMLHttpRequest instance
	return function () {
		// If the request's status is "complete"
		if (request.readyState == 4) {
		// Check that a successful server response was received
		if (request.status == 200) {
			// Pass the XML payload of the response to the 
			// handler function
			responseXmlHandler(request.responseXML);
			obj.isWorking=false;
		} else {
				// An HTTP problem has occurred
				//alert("HTTP error: "+this.req.status);
				parent.document.getElementById("nestFRAME").src = "systemUnavailable.html";
			}
		}
	}
		//alert("End ServerRequest ");
}