function spy(obj)
    {if (!obj) {alert('Obiekt typu false lub null');return;}	for (i in obj) {ans = confirm('obj['+i+'] = '+ obj[i]);	if (ans==false)	return;}}

function ZwinRozwin(l_id)
{
	var div = $("#tx_komentarze_level_"+l_id);
	if (div.is(":hidden"))
		div.slideDown("slow", function() {$("#tx_komentarze_a_zwin_rozwin_"+l_id).html("- zwiń");});
	else
 		div.slideUp("slow", function() {$("#tx_komentarze_a_zwin_rozwin_"+l_id).html("+ rozwiń");});
}

function tx_komentarze_form(uid, parent_id, kotwica, action, formType, callback, hideCancelButton)
{
	tx_komentarze_hide_form('tx_komentarze_naduzycie_form');
	tx_komentarze_hide_form('tx_komentarze_usun_form');
	var form = $("#tx_komentarze_dodaj_form");
	if (form.parent('div').attr('id')==kotwica && form.is(":visible") && form.attr('my_action')==formType)
		tx_komentarze_hide_form('tx_komentarze_dodaj_form');
	else
        {
            form.attr('my_action', formType);
			$("#tx_komentarze_form_uid").val(uid);
			$("#tx_komentarze_form_parent_uid").val(parent_id);
			$("#tx_komentarze_form_action").val(action);
			$("#tx_komentarze_form_tresc").val('');
			if (hideCancelButton)
				$('#tx_komentarze_form_anulujBtn').hide();
            form.slideUp('normal',function()
            {
				if (!hideCancelButton)
					$('#tx_komentarze_form_anulujBtn').show();
				form.remove();
                $("#"+kotwica).append(form);
                form.slideDown('normal', callback);
				maxlength();
            });
        }
}
function tx_komentarze_odpowiedz(uid, parent_id, kotwica, ukryj_anuluj)
{
    tx_komentarze_form(uid, parent_id, kotwica, 'dodaj', 'odpowiedz', undefined, ukryj_anuluj);
}

function tx_komentarze_hide_form(id)
{
	var form = $("#"+id);
	form.slideUp('normal');
	$('#tx_komentarze_walidacja_komentarzy').slideUp('fast');
}

function tx_komentarze_cancel(id)
{
	tx_komentarze_hide_form(id);
	tx_komentarze_odpowiedz(0, 0, 'tx_komentarze_kotwica_main', 1);
}

function tx_komentarze_cytuj(uid, parent_uid, kotwica)
{
    var f = function() {
        $("#tx_komentarze_form_tresc").val('<blockquote>'+$("#tx_komentarze_tresc_"+uid).val()+'</blockquote>\n');
    }
	tx_komentarze_form(uid, parent_uid, kotwica, 'dodaj', 'cytuj', f);
	tx_komentarze_rta(document.getElementById('tx_komentarze_form_tresc'));
}

function tx_komentarze_edytuj(uid, parent_uid, kotwica)
{
    var f = function() {
        $("#tx_komentarze_form_tresc").val($("#tx_komentarze_tresc_"+uid).val());
    }
	tx_komentarze_form(uid, parent_uid, kotwica, 'edytuj', 'edytuj', f);
	tx_komentarze_rta(document.getElementById('tx_komentarze_form_tresc'));
}

function tx_komentarze_usun(uid, kotwica)
{
	tx_komentarze_hide_form('tx_komentarze_dodaj_form');
	tx_komentarze_hide_form('tx_komentarze_naduzycie_form');
	var form = $("#tx_komentarze_usun_form");
	if (form.parent('div').attr('id')==kotwica && form.is(":visible"))
		tx_komentarze_hide_form('tx_komentarze_usun_form');
	else
        {
			$("#tx_komentarze_usun_uid").val(uid);
            form.slideUp('normal',function()
            {
                form.remove();
                $("#"+kotwica).append(form);
                form.slideDown();
            });
        }
}

function tx_komentarze_naduzycie(uid, kotwica)
{
	tx_komentarze_hide_form('tx_komentarze_dodaj_form');
	tx_komentarze_hide_form('tx_komentarze_usun_form');
	var form = $("#tx_komentarze_naduzycie_form");
	if (form.parent('div').attr('id')==kotwica && form.is(":visible"))
		tx_komentarze_hide_form('tx_komentarze_naduzycie_form');
	else
		form.slideUp('normal',function()
		{
			form.remove();
			$("#"+kotwica).append(form);
			form.slideDown();
			$("#tx_komentarze_abuse_uid").val(uid);
			$("#tx_komentarze_abuse_tresc").val('');
		});
}

function tx_komentarze_validuj_komentarz()
{
    return true;
}

function tx_komentarz_wyczysc_formularz()
{
	$("#tx_komentarze_autor_name").val('');
	$("#tx_komentarze_autor_email").val('');
	$("#tx_komentarze_tresc").val('');
}

function tx_komentarze_rta(ta) 
{
    if (ta)
    {
        var n = ta.value.split('\n');
        var rows = n.length;
        var old_rows = ta.cols;
        for (i = 0; i<n.length; i++)
        {
            linia = n[i];
            if (linia.length>=ta.cols)
                rows += Math.floor(linia.length / ta.cols);
        }
        if (rows > ta.rows)
            ta.rows = rows;
        if (rows < ta.rows)
            ta.rows = Math.max(5, rows);
    }
}
