function Ajax()
{
//	version 1.1.0
	this.request=null;
	this.response=null;
	this.callingMethod='POST';
	this.responseType='responseText';  // it can be also responseXML
	this.onDone = null;
	
	this.onStartLoading = function()
	{
		if(this.showLoading && this.loadingDiv)
		{
			this.loadingDiv.style.display = 'block';
		}
	}
	
	this.onDoneLoading = function()
	{
		if(this.showLoading && this.loadingDiv)
		{
			this.loadingDiv.style.display = 'none';
		}
	}
	
	this.loadingDiv = null;
	this.showLoading = true;

	/********* M E T H O D *********/
	this.initialize=function()
	{
		this.response=null;
		if(!this.request)
		{
			if(window['XMLHttpRequest'])
			{/*IE7, Mozillas*/ 
				try
				{
					this.request = new XMLHttpRequest();
				}
				catch(e)
				{
					this.request = null;
				}
			}
			else if(window['ActiveXObject'])
			{/*IE<IE7*/
				var ajaxMSversions=[
										/*'Msxml2.DOMDocument.5.0', 
										 * 'Msxml2.DOMDocument.4.0', 
										 * 'Msxml2.DOMDocument.3.0', 
										 * 'MSXML2.DOMDocument',*/ 
										 'Msxml2.XMLHTTP',
										 'Microsoft.XMLHTTP'
									];
				for(var v=0; v<ajaxMSversions.length; v++)
				{
					try
					{
						this.request=new ActiveXObject(ajaxMSversions[v]); 
						return this.request;
					}
					catch(e)
					{
						this.request=null;
					};
				}
			}
			else if(window['createRequest'])
			{
				try
				{
					this.request=window.createRequest();
				}
				catch(e)
				{
					this.request=null;
				}; 
			}
			else
			{
				alert('XMLHTTP not enabled. Impossible to proceed.');
			}
		};
		
		this.loadingDiv = document.getElementById('oLoading') || this.loadingDiv;
		
		return this.request;
	}
	
	/********* M E T H O D *********/
	this.get = function(sUrl, sVariables, onDone, sResponseType)
	{
		if(!sUrl || !this.initialize())
		{
			return false;
		};
		this.callingMethod='GET';
		this.onDone = onDone || this.onDone;
		this.responseType = responseType || "responseText";
		sVariables = sVariables || '';
		sVariables = sVariables.replace(/\?/, '');
		
		/** variable sent to indicate an ajax action */
		sVariables += '&bAjaxClassVariable=1';
		
		sVariables = unescape(sVariables);
		this.request.open('GET', (sUrl+'?'+sVariables), true);
		this.request.setRequestHeader('Content-Type', 'text/xml');
		
		this.request.onreadystatechange = this.process;
		
		this.onStartLoading();
		
		this.request.send(null);
	}
	
	/********* M E T H O D *********/
	this.post = function(sUrl, sVariables, onDone, sResponseType)
	{
		if(!sUrl || !this.initialize())
		{
			return false;
		};
		this.callingMethod='POST';
		this.onDone = onDone || this.onDone;
		this.responseType = sResponseType || "responseText";
		sVariables = sVariables || '';
		sVariables = unescape(sVariables);

		/** variable sent to indicate an ajax action */
		sVariables += '&bAjaxClassVariable=1';

		this.request.open('POST', sUrl, true);
		this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		
		var oAjax = this;
		this.request.onreadystatechange = function(){ oAjax.process() };
		
		this.onStartLoading();
		
		this.request.send(sVariables);
	}
	
	/********* M E T H O D *********/
	this.submitForm = function(sUrl, onDone, sFormId, oDocument, sVariables, sResponseType)
	{
		try
		{
			if(!sUrl || !this.initialize())
			{
				return false;
			};
			var oDocument = (oDocument) ? oDocument : document;
			var oForm = (sFormId) ? oDocument.getElementById(sFormId) : oDocument.forms[0];
			var sVariables = (sVariables) ? sVariables : '';
			/** parsing elements to get values */
			var arrInputs = oForm.getElementsByTagName('input');
			for(var i=0;i<arrInputs.length;i++)
			{
				var oInput = arrInputs[i];
				if(oInput.type == 'button' || !oInput.name || ((oInput.type == 'checkbox' || oInput.type == 'radio') && !oInput.checked))
				{
					continue;
				}
				sVariables += '&' + escape(oInput.name) + '=' + escape(oInput.value);
			}
			
			var arrTextAreas = oForm.getElementsByTagName('textarea');
			for(var i=0;i<arrTextAreas.length;i++)
			{
				var oInput = arrTextAreas[i];
				sVariables += '&' + escape(oInput.name) + '=' + escape(oInput.value);
			}
			
			var arrSelects = oForm.getElementsByTagName('select');
			for(var i in arrSelects)
			{
				var oSelect = arrSelects[i];
				if(!oSelect.name)
				{
					continue;
				}
				/** if select is multiple send values in array */
				if(oSelect.multiple)
				{
					/** sending only selected options */
					for(var j=0, iLen=oSelect.options.length; j<iLen; j++)
					{
						var oOption = oSelect.options[j];
						if(oOption.selected)
						{
							sVariables += '&' + escape(oSelect.name) + '[]=' + escape(oOption.value);
						}
					}
				}
				else
				{
					sVariables += '&' + escape(oSelect.name) + '=' + escape(oSelect.value);
				}
			}
			this.post(sUrl, sVariables, onDone, sResponseType);
		}
		catch(oEx)
		{
			alert("error on ajax.submitForm FUNCTION: "+oEx.description)
		}
	}
	
	/********* M E T H O D *********/
	this.head=function(sUrl, sVariables, onDone)
	{
		if(!sUrl || !this.initialize())
		{
			return false;
		};
		this.callingMethod='HEAD';
		this.onDone = onDone || this.onDone;
		sVariables = sVariables || null;

		/** variable sent to indicate an ajax action */
		sVariables += '&bAjaxClassVariable=1';

		this.request.open('HEAD', sUrl, true);
		this.request.setRequestHeader('Content-Type', 'text/xml');
		
		this.request.onreadystatechange = this.process;
		
		this.onStartLoading();
		
		this.request.send(sVariables);
	}
	
	/********* M E T H O D *********/
	this.error = function(iStatusError)
	{
		if(iStatusError)
		{
			this.response = (this.request && this.request.status)? 
				'Ajax Error: '+this.request.status+': '+this.request.statusText: 
				'Ajax Error: Requested document may be temporarily unavailable';
	//		alert(this.response);
			if(this.showLoading && this.loadingDiv)
			{
				this.loadingDiv.style.display = 'none';
			}
		}
	}
	
	/********* M E T H O D *********/
	this.process = function()
	{	
		if(this.request.readyState==4 || this.request.readyState=='complete')
		{
			if(this.request.status==200)
			{
				/** uncomment this to see what ajax instance returned */
				//alert(this.request.responseText);
				
				if(this.responseType == 'responseXML')
				{
					try
					{
						var oXMLDom;
						if (window.ActiveXObject)
						{
							oXMLDom = new ActiveXObject('Microsoft.XMLDOM'); 
							oXMLDom.loadXML(this.request.responseText);
						}
						else
						{
							oXMLDom = new DOMParser().parseFromString(this.request.responseText, 'text/xml');
						}
						this.response = oXMLDom;
					}
					catch(oEx)
					{
						alert(this.request.responseText);
					}
				}
				else
				{
					this.response = this.request.responseText;
				}
				if(typeof(this.onDone)=='function')
				{
					this.onDone(this.response);
				}
				else
				{
					eval(this.response);
				}

				this.onDoneLoading();
			}
			else
			{
				this.error(1);
			}
		}
		else
		{
			this.error(0);
		}
	}
/*class ends - Keep this comment to reuse freely: http://www.unitedscripters.com/ */
}
