AjaxClass = {
	request : 
	{
		action : String('')
		, method : String('GET')
		, parameters : {}
			 
	}
	, response : 
	{
		status : Number(0)
		, content : String('')
		, type : String('') /*[html,json,js,text]*/
	}
	, onComplete 	: function(){}
	, onSuccess 	: function(){}
	, onFailure		: function(){}
	, execute 		: function()
	{
		this.xmlHttp = null;
		
		try{this.xmlHttp=new XMLHttpRequest();/*Firefox, Opera 8.0+, Safari*/}
		catch (e)
		{/*Internet Explorer*/
			try {this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e)
			{
				try {this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;        
				}
			}
		}
		
		this.xmlHttp.onreadystatechange = this.onStateChange.bind(this);

		
		var requestBody = [];
		//encodeURIComponent
		for (prop in this.request.parameters)
		{
			//requestBody.push(encodeURIComponent(prop) + '=' + encodeURIComponent(this.request.parameters[prop]));
			requestBody.push(prop + '=' + this.request.parameters[prop]);
		}
		requestBody = requestBody.join('&');
		
		switch(this.request.method.toUpperCase())
		{
			case 'POST' : 
				//alert(requestBody);
				//xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
				//xmlHttp.setRequestHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
				this.xmlHttp.open(this.request.method, this.request.action, true);
				this.xmlHttp.send(requestBody);
				break;
			case 'GET' : 
				this.xmlHttp.open(this.request.method, this.request.action + (this.request.action.indexOf('?') == -1 ? '?' : '&') + requestBody, true);
				this.xmlHttp.send(null);
				break;
		}
	}	
	, onStateChange : function()
	{
		if(this.xmlHttp.readyState == 4) 
		{
			this.response.status = this.xmlHttp.status;
			this.response.content = this.xmlHttp.responseText;
			if (this.xmlHttp.status >= 200 &&  this.xmlHttp.status < 300){this.onSuccess()}
			else{this.onFailure();}
			this.onComplete();
			this.xmlHttp.onreadystatechange = function(){} 
			this.xmlHttp = null;
		}

	}
}



function newAjax()
{
	function cloneObject(objRef) {
		for (member in objRef) {
			if (typeof objRef[member] == 'object') {
				this[member] = new cloneObject(objRef[member]);
			}
			else
				this[member] = objRef[member];
		}
		return this;
	}
	
	return cloneObject(AjaxClass);
}




