function AjaxForm_Post(el,context)
{		
	var array = new Array();
	// zebranie danych z formularza		
	$(el.form).find('input,select,textarea').each(function(){
		var obj = new Object();
		obj.name = this.name;
		
		if (obj.name == '_context' && context != '')
		{
			obj.value = context;			
		}
		else
		{		
			if (this.tagName=='INPUT' && this.type=='checkbox')
				obj.value = this.checked ? this.value : '';
			else
				obj.value = this.name == '_ajax' ? 'true' : this.value;
		}			
		array.push(obj);
	});
			
	return !$.post(
		window.location.href, 
		array,
		function(data) 
		{
			var json = eval("(" + data + ")");
			if (json.error > 0)
			{
				if (json.error == 1)
					alert(json.description);
				if (json.error == 2)
					$('#TB_ajaxContent').load(json.description.replace(/&amp;/g,'&'),null,window[json.initFunction]);					
			}
			else
				window.location.reload();
		}
	);
}

function ForumInsertAtCursor(myValue) 
		{
			myField	= document.getElementById('_val_tresc');
			//IE support
			if (document.selection) 
			{
				myField.focus();
				sel = document.selection.createRange();
				sel.text = myValue;
			}
			//MOZILLA/NETSCAPE support
			else if (myField.selectionStart || myField.selectionStart == '0') 
			{
				var startPos = myField.selectionStart;
				var endPos = myField.selectionEnd;
				myField.value = myField.value.substring(0, startPos)
				+ myValue
				+ myField.value.substring(endPos, myField.value.length);

				myField.selectionStart = startPos + myValue.length;
				myField.selectionEnd = startPos + myValue.length;
			} 
			else 
			{
				myField.value += myValue;
			}
			myField.focus();
			return false;
		}

function ForumEditPost_Init()
{
	$('#TB_window a.button').each(function(){
		$(this).bind('click',function(){
			ForumInsertAtCursor(this.title);
			return false;
		});
	});
	$('_val_tresc').focus();
}
function ForumAddPost_Init()
{
	$('#TB_window a.button').each(function(){
		$(this).bind('click',function(){
			ForumInsertAtCursor(this.title);
			return false;
		});
	});
	$('_val_tresc').focus();
}
function ForumAddTopicPost_Init()
{
	$('#TB_window a.button').each(function(){
		$(this).bind('click',function(){
			ForumInsertAtCursor(this.title);
			return false;
		});
	});
	$('_val_tresc').focus();
}