function AE4Me()
{
	this.request=false;
	this.method="post"; 
	this.url=""; 
	this.query=""; 
	this.addquery=false;
	this.cache=false;
	this.headers=new Array();
	this.formelement=""; 
	this.readyState1=function(){};
	this.readyState2=function(){};
	this.readyState3=function(){};
	this.readyState4=function()
	{
		if(this.request.status==200)
		{
			this.functionresponse(this.request.responseText);
		}
		else
		{
			this.functionerror();
		}
	};
	this.functionresponse=function(ntext){};
	this.functionerror=function(){};
	this.loading=function(){};
	this.createAjax=function()
	{
		if(window.XMLHttpRequest)
		{
			this.request=new XMLHttpRequest();
			if(this.request.overrideMimeType)
			this.request.overrideMimeType('text/xml');
		}
		else if(window.ActiveXObject)
		{
			try
			{
				this.request=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					this.request=new ActiveXObject("Microsoft.XMLHTTP"); 
				}
				catch(e){}
			}
		}
		if(!this.request)
			alert("مرورگر شما توانایی کار با اجکس را ندارد");
	};          
	this.makeQuery=function()
	{
		var a=this.formelement.elements,q="";
		for(var i=0;i < a.length;i+=1)
			if(a[i].type == 'checkbox')
			{
				q+=a[i].name+"=";
				if(a[i].checked == false)
					q+= "no&";
				else
					q+= "yes&";
			}
            else if(a[i].type=='radio')
            {
                if(a[i].checked==true)
                {
    				q+=a[i].name+"="+ encodeURIComponent(a[i].value) +"&";
                }
            }
			else
			{
				q+=a[i].name+"="+ encodeURIComponent(a[i].value) +"&";
			}
		q=q.slice(0,(q.length-1));
		this.query=q;
	};
	this.getText=function()
	{
		return this.request.responseText;
	};
	this.getXML=function()
	{
		return this.request.responseXML;
	};
	this.setHeader=function(n,v)
	{
		this.headers.push(new Array(n,v));
	};
	this.sendHeaders=function()
	{
		var i;for(i=0;i<this.headers.length;i++)
			this.request.setRequestHeader(this.headers[i][0],this.headers[i][1]);
	};
	this.runonly=function(nurl,nresponse,nerror,nloading,refre)
	{
		if(refre)
			this.createAjax();
		this.url=nurl;
		this.method="get";
		this.addquery=false;
		this.cache=false;
		this.functionresponse=nresponse;
		this.functionerror=nerror;
		this.loading=nloading;
		this.run();
		
	}
	this.runform=function(nurl,nformelement,nmethod,nresponse,nerror,nloading,refre)
	{
		if(refre)
			this.createAjax();
		this.url=nurl;
		this.method=nmethod;
		this.addquery=true;
		this.cache=false;
		this.formelement=nformelement;
        this.makeQuery();
		this.functionresponse=nresponse;
		this.functionerror=nerror
		this.loading=nloading;
		this.run();
	}
	this.rundata=function(nurl,ndata,nresponse,nerror,nloading,refre)
	{
		if(refre)
			this.createAjax();
		this.url=nurl;
		this.method="post";
		this.addquery=true;
		this.cache=false;
		this.query=ndata;
		this.functionresponse=nresponse;
		this.functionerror=nerror
		this.loading=nloading;
		this.run();
	}
		
	this.run=function()
	{
		var self=this;
		this.request.onreadystatechange=function()
		{
			switch(self.request.readyState)
			{
				case(0):
					self.readyState0();
					break;
				case(1):
					self.loading();
					break;
				case(2):
					self.readyState2();
					break;
				case(3):
					self.readyState3();
					break;
				case(4):
					self.readyState4();
					break;
			}
		};
		if(this.method.toLowerCase()=="get")
		{ 
			if(this.addquery) 
			{
				if(this.url.indexOf("?") == -1) 
					this.request.open("GET", this.url +"?"+ this.query + "&sid=" + Math.random()  , true); 
				else
					this.request.open("GET", this.url +"&"+ this.query + "&sid=" + Math.random(), true);
			}
			else
			{
				if(this.url.indexOf("?") == -1) 
					this.request.open("GET", this.url +"?sid=" + Math.random(), true); 
				else
					this.request.open("GET", this.url +"&sid=" + Math.random(), true);
			}
		}
		else
		{
				if(this.url.indexOf("?") == -1) 
					this.request.open("POST", this.url +"?sid=" + Math.random(), true); 
				else
					this.request.open("POST", this.url +"&sid=" + Math.random(), true);
			this.setHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		}
		if(!this.cache)
			this.setHeader("Cache-Control", "no-cache"); 
		this.sendHeaders();
		if(this.method.toLowerCase()=="get") 
			this.request.send(null);
		else
			this.request.send(this.query);
	};
	this.createAjax();
}	
	