<!--

	/*
	
		Ajax Library
		version 0.5.2
	
		--------------
		beYond Visions
		--------------
		
	*/
	
	var SERVER_GET = 1;
	var SERVER_POST = 2;
	var AjaxRequestPointer = new Array();
	var AjaxIndice = new Number(0);
	
	function AjaxAddVariable(name, value)
	{
		var pos = this.variablearray.length;
		
		this.variablearray[pos] = new Array();
		this.variablearray[pos]['name'] = name;
		this.variablearray[pos]['value'] = value;
	}
	
	function AjaxAddRequestHeader(name, value)
	{
		var pos = this.requestedHeaders.length;
		
		this.requestedHeaders[pos] = new Array();
		this.requestedHeaders[pos]['name'] = name;
		this.requestedHeaders[pos]['value'] = value;
	}
	
	function AjaxChangeVariable(name, value)
	{
		var i;
		
		for(i=0;i<this.requestedHeaders.length;i++)
		{
			if(this.requestedHeaders[i]['name'] == name)
			{
				this.requestedHeaders[i]['value'] = value;
				
				return true;
			}
		}
		
		this.addVariable(name, value);
	}
	
	function AjaxConnection(url, method)
	{
		this.variablearray = new Array();
		this.requestedHeaders = new Array();
		
		this.addVariable=AjaxAddVariable;
		this.changeVariable=AjaxChangeVariable;
		this.execute=AjaxExecute;
		this.addRequestHeader=AjaxAddRequestHeader;
		this.setOnReadyStateChange=null;
		this.setOnError=null;
		this.setOnLoad=null;
		this.setOnProgress=null;
		this.setOnSuccess=null;
		
		this.server = url;
		this.username = null;
		this.password = null;
		this.async = true;
		this.sendBodyContent = null;
		this.requestType = SERVER_GET;
		this.pointerIndice = AjaxIndice++;
		
		this.resultAsXML = true;
		this.loadingFunction = null;
		this.successFunction = null;
		
		if(method)
		{
			this.requestType=method;
		}
		
		if(!url)
		{
			return false;
		}
	}
	
	function AjaxProcessRequestChange(server, indice, resultAsXML, loadingFunction, successFunction)
	{
		if (AjaxRequestPointer[indice].readyState == 1 || AjaxRequestPointer[indice].readyState == 2 || AjaxRequestPointer[indice].readyState == 3)
		{
			if(loadingFunction)
			{
				loadingFunction();
			}
		}
		
		if (AjaxRequestPointer[indice].readyState == 4)
		{
			if (AjaxRequestPointer[indice].status == 200)
			{
				if(resultAsXML)
				{
					AjaxReturnValue = AjaxRequestPointer[indice].responseXML;
				}
				else
				{
					AjaxReturnValue = AjaxRequestPointer[indice].responseText;
				}
				
				if(successFunction)
				{
					successFunction(AjaxReturnValue);
				}
				else
				{
					alert("Indice: " + indice + "\nServer status: " + AjaxRequestPointer[indice].statusText + "\nReturn value: " + AjaxReturnValue);
				}
			}
			else
			{
				alert("There was a problem retrieving the XML data:\nServer: " + server + "\nServer status: " + AjaxRequestPointer[indice].status + "\nServer message: " + AjaxRequestPointer[indice].statusText);
			}
		}
	}
	
	function AjaxExecute()
	{
		if(!this.server)
		{
			return false;
		}
		
		if(window.XMLHttpRequest)
		{
			try
			{
				AjaxRequestPointer[this.pointerIndice] = new XMLHttpRequest();
			}
			catch(e)
			{
				AjaxRequestPointer[this.pointerIndice] = false;
			}
		}
		else if(window.ActiveXObject)
		{
			try
			{
				AjaxRequestPointer[this.pointerIndice] = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					AjaxRequestPointer[this.pointerIndice] = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e)
				{
					AjaxRequestPointer[this.pointerIndice] = false;
				}
			}
		}
		
		if(AjaxRequestPointer[this.pointerIndice])
		{
			try
			{
				var txt = "";
				var i = new Number(0);
				
				for(i=0;i<this.variablearray.length;i++)
				{
					txt = txt + '&' + (this.variablearray[i]['name']) + '=' + escape(this.variablearray[i]['value']);
				}
				
				if(this.setOnReadyStateChange)	{	AjaxRequestPointer[this.pointerIndice].onreadystatechange = new Function(this.setOnReadyStateChange + "(" + this.pointerIndice + ", " + this.resultAsXML + ", " + this.loadingFunction + ", " + this.successFunction + ")");		}
				else							{	AjaxRequestPointer[this.pointerIndice].onreadystatechange = new Function("AjaxProcessRequestChange('" + this.server + "', " + this.pointerIndice + ", " + this.resultAsXML + ", " + this.loadingFunction + ", " + this.successFunction + ")");	}
//				if(this.setOnError)				{	AjaxRequestPointer[this.pointerIndice].onerror = this.setOnError;						}
				if(this.setOnProgress)			{	AjaxRequestPointer[this.pointerIndice].onprogress = this.setOnProgress;					}
				if(this.setOnLoad)				{	AjaxRequestPointer[this.pointerIndice].onload = this.setOnLoad;							}
				
				if(this.requestType == SERVER_GET)
				{
					AjaxRequestPointer[this.pointerIndice].open("GET", this.server + ((txt.length>0)?'?' + txt:''), this.async, this.username, this.password);
					
					for(var i=0;i<this.requestedHeaders.length;i++)
					{
						AjaxRequestPointer[this.pointerIndice].setRequestHeader(this.requestedHeaders[i]['name'], this.requestedHeaders[i]['value']);
					}
					
	//				prompt("", "http://clients.emotionconcept.ro/burkeins/insuretheoffice/" + this.server + '?' + txt);
					AjaxRequestPointer[this.pointerIndice].send(null);
				}
				else
				{
					AjaxRequestPointer[this.pointerIndice].open("POST", this.server, this.async, this.username, this.password);  
					AjaxRequestPointer[this.pointerIndice].setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
					
					for(var i=0;i<this.requestedHeaders.length;i++)
					{
						AjaxRequestPointer[this.pointerIndice].setRequestHeader(this.requestedHeaders[i]['name'], escape(this.requestedHeaders[i]['value']));
					}
					
					AjaxRequestPointer[this.pointerIndice].send(txt);
				}
			}	
			catch (e)
			{
				alert('An error has occured calling the external site:\nErrorName: ' + e.name + '\nErrorMessage: ' + e.message);
				return false;
			}
		}
		else
		{
			alert('Unable to create AJAX object.\nYour browser may not be compatible with this method.');
			
			return false;
		}
	}

//-->