
function Ajax2Div(div,data,scrollto,showloading,chain)
{
	//no & in json string, otherwise the POST string will be destroyed
	data = data.replace(/&/g,'%26');
	data = data.replace(/\+/g,'%2B');
	new Request.HTML(
		{
			url: '/ajax/wrapper.php',
			data: 'data='+data,
			evalScripts : true,
			onRequest : function ()
			{
				if (showloading != 'false')
					$(div).innerHTML = '<br /><table width="100%" height="100%"><tr><td align="center"><img src="/icons/loading.gif" alt="" /></td></tr></table>';
			},	
			onSuccess	: function (responseTree, responseElements, responseHTML, responseJavaScript)
			{
				$(div).innerHTML = '<div>'+responseHTML+'</div>';
				//eval(responseJavaScript);
				if (chain != undefined)
					eval(chain);
				if (scrollto == 'true')
				{
					$('page').scrollTo(0,$(div).offsetTop);
				}
			},
			onFailure : function (xHr)
			{
				alert("ERROR\nPlease try again !\n\n Error Code : "+xHr.status);
			}			
		}
	).post();																
}

function Ajax2Popup(div,data)
{
	//no & in json string, otherwise the POST string will be destroyed
	data = data.replace(/&/g,'%26');
	//attention: output of the wrapper should be the link for the popup !!!
	// popup will be blocked by popup blocker if it's not in the trusted sites
	new Request.HTML(
		{
			url: 'ajax/wrapper.php',
			data: 'header=disabled&data='+data,
			evalScripts : true,
			onComplete	: function (responseTree, responseElements, responseHTML, responseJavaScript)
			{
				window.open(responseHTML, "myServerPopup", "location=no,menubar=no,status=no,toolbar=no");
			}
		}
	).post();																
}

function Ajax2Me(value,data)
{
	//no & in json string, otherwise the POST string will be destroyed
	data = data.replace(/&/g,'%26');
	new Request.HTML(
		{
			url: 'ajax/wrapper.php',
			async : false,
			data: 'header=disabled&data='+data,
			evalScripts : true,
			onComplete	: function (responseTree, responseElements, responseHTML, responseJavaScript)
			{
				value.value = responseHTML;
			}
		}
	).post();																
}

function Ajax2Slider(div,data,chain)
{
	if ($(div).title == 'slidein')
	{
		var slide = new Fx.Slide(div);
		slide.slideOut();
		$(div).title = 'slideout';
	}
	else
	{
		//no & in json string, otherwise the POST string will be destroyed
		data = data.replace(/&/g,'%26');
		new Request.HTML(
			{
				url: 'ajax/wrapper.php',
				data: 'data='+data,
				evalScripts : true,
				onRequest : function ()
				{
					$(div).innerHTML = '<br /><table width="100%" height="100%"><tr><td align="center"><img src="icons/loading.gif" alt="" /></td></tr></table>';
				},	
				onComplete	: function (responseTree, responseElements, responseHTML, responseJavaScript)
				{
					$(div).innerHTML = '<div>'+responseHTML+'</div>';
					$(div).title = 'slidein';
					var slide = new Fx.Slide(div,
					{
							onComplete : function () 
							{
								if (chain != undefined)
									eval(chain);
							}
					});
					slide.hide();
					slide.slideIn();
			
				}
			}
		).post();
	}															
}

function AjaxSliderClose(div)
{
	var slide = new Fx.Slide(div);
	slide.hide();
	$(div).title = 'slideout';
}

function Ajax2Result(div,data,message,chain)
{
	//attention chain has to be an object to pass by reference in order to avoid quote problems
	//
	//no & in json string, otherwise the POST string will be destroyed
	data = data.replace(/&/g,'%26');
	new Request.HTML(
		{
			url: 'ajax/wrapper.php',
			data: 'header=disabled&data='+data,
			evalScripts : true,
			onRequest : function ()
			{
				if (message != '' && message != 'undefined')
					$(div).innerHTML = '<center><br /><img src="/icons/waiting.gif" alt="" /><br/>'+message;
			},	
			onComplete	: function (responseTree, responseElements, responseHTML, responseJavaScript)
			{
				if (responseHTML != 'wait')
				{
					$(div).innerHTML = '<div>'+responseHTML+'</div>';
					if (AjaxChain != undefined && AjaxChain != '')
					{
						var temp = AjaxChain;
						AjaxChain = '';
						eval(temp);
					}
				}
				else
				{
					if (chain != undefined)
						AjaxChain = chain;
					setTimeout("Ajax2Result('"+div+"','"+data+"','"+message+"')",2000);
				}
				new Fx.Morph(div).start({'background-color' : ['#DDD','#FFF']});
			}
		}
	).post();													
}

var AjaxChain = '';
