
var on_ajax_failure_count=0;
function on_ajax_failure(r)
{
	if (on_ajax_failure_count<10)
	{
		on_ajax_failure_count++;
		new Ajax.Request(r.request.url, r.request.options);
	} else {
		var error_string=$H({"status":r.status,"statusText":r.statusText,"responseText":r.responseText,"headers":r.getAllHeaders(),"url":r.request.url,"method":r.request.method,"location":document.location,"cookies":document.cookie}).toQueryString() ;
		var ifrm=document.createElement("iframe");
		ifrm.setAttribute("id","error_reporting_ifrm");
		ifrm.setAttribute("src","error_reporting.php?"+error_string);
		ifrm.src="error_reporting.php?"+error_string;
		document.body.appendChild(ifrm);
	//	Event.observe(ifrm,"load",on_ajax_failure_succ);
		alert("Hiba történt a kommunikációban!\nA hibáról a rendszer automatikusan értesíti az adminisztrátort, melynek sikerességét külön üzenet jelzi.\nAmennyiben az utóbbi elmarad, kérem  írjon e-mailt a megadott elérhetőségek egyikére!");
		on_ajax_failure_count=0;
	}
}
function check_response_code(response)
{
	if (response.response.error_code==2)
	{//átirányítás
		if (response.response.location!=undefined)
		{
			document.location=response.response.location;
			exit();
		}

	} else if (response.response.error_code==500) {
		//jogosultsági probléma
		alert(response.response.message);
		//exit();
	} else if (response.response.error_code>=100 && response.response.error_code<=199) {
		//üzenet
		alert(response.response.message);
	}	
	return response.response.error_code;
}


function ajax_load_icon(dest)
{
	this.add=add;
	this.remove=remove;
	this.stop=stop;
	this.add();
	
	function add(dest)
	{
		if (dest==undefined || !Object.isElement(dest))
		{
			dest=$(document.body);
		}
		var i=document.createElement('img');
		$(i).src='/skins/'+skin+'/cmsimages/ajax-loader-black.gif';
		
		vp=document.viewport.getDimensions();
		offset_x=(vp.width-50)/2;
		offset_y=(vp.height-50)/2;

		var di=document.createElement('div');
		$(di).setStyle({
			position:'fixed',
			zIndex:findHighestZ()+1,
			top:offset_y+'px',
			left:offset_x+'px',
			width:'50px',
			height:'50px',
			textAlign: 'center'
		});
		
		var a=document.createElement('a');
		$(a).href="#";
		$(a).innerHTML='Leállít';
		Element.observe($(a),'click',this.stop.bindAsEventListener(this));
		
		this.gray=new overlay();
		this.gray.add();
		
		$(di).insert($(i));
		$(di).insert($(a));
		$(document.body).insert($(di));
		this.obj=$(di);
		return this;
	}
	
	function stop(event)
	{
		if (event!=undefined)
			Event.stop(event);
		alert("Folyamat megszakítva, de elképzelhető, hogy a művelet már végrehajtódott! Kérem ellenőrizze!");
		this.remove();
	}
	
	function remove()
	{
		this.obj.hide();
		$(this).gray.remove();
		$(this).obj.remove();	
	}
}
