/*
	HTTP Request-eket kezelo objektum (AJAX, SJAX)
	=====================================
*/

//Ready State lehetseges ertekei - konstansok
HTTP_RS_ALL = -1;
HTTP_RS_UNITIALIZED = 0;
HTTP_RS_LOADING = 1;
HTTP_RS_LOADED = 2;
HTTP_RS_INTERACTIVE= 3;
HTTP_RS_COMPLETE = 4;


//Factory
function HTTPRequestObjectFactory(_instance)
{
	eval(_instance + " = new HTTPRequestObject(\"" + _instance + "\");");
}

//konstruktor
function HTTPRequestObject(_instance)
{
	this.instance=_instance;
}

//adat lekero fuggveny
HTTPRequestObject.prototype.getData = function()
{
	return this.HTTPReq;
}

//adatfeldolgozo fuggveny
HTTPRequestObject.prototype.manageResponse = function(_parent)
{
	
	try{
		
		if(_parent.readyState==-1 || _parent.HTTPReq.readyState == _parent.readyState || ((_parent.readyState==null || _parent.readyState==undefined) && _parent.HTTPReq.readyState==4))
		{
			
			eval(_parent.func);
			
		}
		
		
	}catch(e){}

}


//Aszinkron POST kuldo fuggveny - az eredmény a feldolgozó függvény által lesz elérhető
HTTPRequestObject.prototype.sendAsyncPost = function(_params, _function, _readyState, _attrib) 
{
	this.attrib=_attrib;
	this.HTTPReq=null;
	this.readyState=_readyState
	this.func = "new Function("+ _function + "("+ _attrib +"))";
	if( window.XMLHttpRequest ) {

		//Gecko, Safari 1.2+, Opera 7.6+, Firefox 1.5+
		try{

			this.HTTPReq = new XMLHttpRequest();
			
			if (this.HTTPReq.overrideMimeType)
			{
				this.HTTPReq.overrideMimeType("text/xml");
			}

			eval(this.instance+".HTTPReq.onreadystatechange = function () { " + this.instance + ".manageResponse("+this.instance+"); }");

			this.HTTPReq.open("POST", "./index.php", true);

			this.HTTPReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

			this.HTTPReq.send(_params);

			
			return true;

		}catch(e){}
	}
	if( !navigator.__ice_version && window.ActiveXObject ) {

		//IE 5+/Win
		try {
				
				//régebbiekhez
				try
				{					
					var tho = new ActiveXObject( 'Microsoft.XMLHTTP' ); 
				}
				catch(er) 
				{
				 	var tho = new ActiveXObject( 'Msxml2.XMLHTTP' ); 
				}
				this.HTTPReq = tho;
				
				eval("this.HTTPReq.onreadystatechange = function () {  " + this.instance + ".manageResponse("+this.instance+"); }");
				
				this.HTTPReq.open("POST", "./index.php",true);
				
				this.HTTPReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
				this.HTTPReq.send(_params);
				
				//eval(this.func);

				return true;
			


			

		} catch(e) {}
	}
	return false;
}



//Szinkron post küldő függvény, az eredményt adja vissza
HTTPRequestObject.prototype.sendSyncPost = function(_params) 
{
		if(!window.XMLHttpRequest)
			//IE használata esetén a Microsoft library-kból kell építkeznünk
			var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		else{
			//más esetben szabványosan is eljárhatunk
			var httpRequest = new XMLHttpRequest();
		}

		try{
			//POST az index.php-ra
			httpRequest.open("POST", "./index.php", false);
			httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			//httpRequest.setRequestHeader("cache-control", "must-revalidate");
			//paraméterek sorozata
			httpRequest.send(_params);

			//Auto mentéskor visszaállítjuk az állapotot


			if(httpRequest.status == 200)
			{

				return httpRequest.responseText;
			}
			else
			{

				return httpRequest.status + " " + httpRequest.statusText;
			}
		} catch(e) {

			return e;
		}

}










