
APHPRequest = new Object;
APHPRequest.loadedRequisitions = new Array();

//Start phpRequest Object
function Ajax_phpRequest(serverUrl, ID)
{
  //Set some default variables
    this.parms = new Array();
    this.parmsIndex = 0;

  //Set the server url
    this.server = serverUrl;
    this.requestMethod = 'GET';

  //Add two methods
  //this.add = phpRequestAdd;
  // this.execute = phpRequestExecute;
  // this.setHandler = setJSHandler;
  // this.createXMLHttp = createXMLHttp;
  // this.onReadyStateChange = onReadyStateChange;


  // this.httpRequest = null;
  // this.resultXML = null;
    this.id = ID;

    var handler = null;
    var object = null;
    var httpRequest;
    var resultXML;
    var currentObject = this;

    this.execute = function ()
	{
		//Try to create our XMLHttpRequest Object
		try
		{
			this.httpRequest = this.createXMLHttp();
			httpRequest = this.httpRequest;
		}
		catch (e)
		{
			alert('Error creating the connection!');
			return;
		}

		//Make the connection and send our data
		try
		{
			///var txt = "?1";
			var txt = "1";
			for(var i in this.parms)
			{
			  txt = txt + '&'+this.parms[i].name + '=' + this.parms[i].value;
			}

			if (this.requestMethod == 'GET')
			{
			    ///httpRequest.open("GET", this.server + txt, true);
			    ///httpRequest.setRequestHeader('content-type', 'text/xml');

				//13.12.2007
				httpRequest.open("GET", this.server + "?" + txt, true);
			    httpRequest.setRequestHeader('content-type', 'text/xml');
			    httpRequest.onreadystatechange = this.AJAX_PHP_onReadyStateChange;
				httpRequest.send('');
			}
			else
			{
			    ///httpRequest.open("POST", this.server + txt, true);
			    ///httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

				//13.12.2007
                httpRequest.open("POST", this.server, true);
                httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   			    httpRequest.onreadystatechange = this.AJAX_PHP_onReadyStateChange;
                httpRequest.send(txt);
			}

			//alert(this.server + txt);
			///httpRequest.onreadystatechange = this.AJAX_PHP_onReadyStateChange;
			///httpRequest.send('');
		}
		catch (e)
		{
			alert('An error has occured calling the external site: ' + e);
			return false;
		}

	}

	// --- AJAX onreadystatechange handler --- //
		this.AJAX_PHP_onReadyStateChange = function ()
		{
			if (httpRequest.readyState != 4) return;

			if (httpRequest.status == 200)
			{

				// --- create xml document object

			    if (typeof(httpRequest.responseXML.documentElement) != 'undefined')
			    {
			        resultXML = httpRequest.responseXML.documentElement;
			    }
			    else
			    {
			        XMLDocument = new ActiveXObject("Msxml2.DOMDocument");
			        XMLDocument.loadXML(httpRequest.responseText);

			        resultXML = XMLDocument;
			    }

			}
			else
			{
				alert('The server responded with a bad status code: ' + httpRequest.status);
		        return false;
			}

			// --- Load current handler--- //
			currentObject.resultXML = resultXML;
			if (typeof(handler) == 'function') handler(currentObject, object);

			// alert(resultXML.getElementsByTagName('control')[0].firstChild.data);
			return resultXML;
		}
	// --- AJAX onreadystatechange handler --- //

	this.setHandler = function (handlerName, objectName)
	{
		handler = handlerName;
		object = objectName;
	}

	this.setRequestMethod = function (methodName)
	{
	    if (methodName == 'POST')
	    {
	        this.requestMethod = 'POST';
	    }
	    else
	    {
	        this.requestMethod = 'GET';
	    }
	}

	this.add = function (name, value)
	{
	  //Add a new pair object to the params
	  this.parms[this.parmsIndex] = new pair(name,value);
	  this.parmsIndex++;
	}

	this.createXMLHttp = function ()
	{
		// var httpRequest = null;
	    try
	    {
	        httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
	    }
	    catch (e)
	    {
	        try
	        {
	            httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
	        }
	        catch (ee)
	        {
	            httpRequest = null;
	        }
	    }

	    if (!httpRequest && typeof XMLHttpRequest != 'undefined')
	    {
	    	httpRequest = new XMLHttpRequest();
	    }

	    return httpRequest;
	}

}


//Utility pair class
function pair(name, value)
{
  this.name = name;
  this.value = value;
}