﻿$(document).ready(function(){
    //forums
    $("#show_new_forum").click(function(){$("#show_new_forum_wrp").fadeIn("fast");return false;});
    $("#show_new_hide").click(function(){$("#show_new_forum_wrp").fadeOut("fast"); return false;});
    $("#add_new_thread").click(function(){
        var ThrTitle = $("#forum_thread_title").val();
        var ThrBody = $("#forum_thread_body").val();
        var ThrCat = $("#forum_thread_category option:selected").val();
        var arrS = $(this).attr("id").split("-");
        
        if (ThrTitle == "")
        {alert("Zadej nadpis!");}
        else
        {
            if (ThrBody == "")
            {alert("Zadej text!");}
            else
            {
                $.post("ajax_post.aspx",
                { m: "PostNewThread", 
                p: ThrTitle, 
                p2: ThrBody, 
                p3: ThrCat,
                p4: ForumSettings.forumType,
                p5: ForumSettings.refId}, 
                function(data){
                    if (data == "povedlo se")
                    {   
                        m.AlertMessage(data);
                        $("#show_new_forum_wrp").fadeOut("fast");
                        $("#forum_thread_title").val("");
                        $("#forum_thread_body").val("");
                        $("#forum_theads_wrp").prepend("<h3>" + ThrTitle + "</h3><p>" + ThrBody + "</p><hr />");
                    }
                    else
                    {m.AlertMessage("chyba");}
                }
                );
            }
        }
        return false;
    });
    $(".forum_comment a").click(function(){
        var IdArr = $(this).attr("id").split("-");
        var strId = IdArr[1];
        var CommBody = $("#wrp-" + strId + " textarea").val();
        if (CommBody == "")
        {alert("Zadej text!");}
        else
        {
            $.post("ajax_post.aspx",
            { m: "PostNewThreadComment", 
            p: CommBody, 
            p2: strId,
            p3: IdArr[2]}, 
            function(data){
                if (data == "povedlo se")
                {   
                    m.AlertMessage(data);
                    $("#wrp-" + strId).fadeOut("fast");
                    $("#wrp-" + strId + " textarea").val("");
                    $("#forum_comments_wrp").prepend("<p>" + CommBody + "</p><hr />");
                }
                else
                {m.AlertMessage("chyba");}
            }
            );
        }
        return false;
    });
    $(".show_forum_com").click(function(){
        var IdArr = $(this).attr("id").split("-");
        var strId = IdArr[1];
        //alert("hi");
        $("#wrp-" + strId).fadeIn("fast");
        return false;
    });
    
    
    $(".vote_forum").click(function(){
        var arrS = $(this).attr("id").split("-");
        var intNumb = parseInt(arrS[1]);
        if(arrS[0] == "plus")
        {
	        if ($("#v_vrp_" + arrS[2] + " .v1").text() == arrS[1])
	        {
	            m.GPost(arrS[3], arrS[0], intNumb, arrS[2]);
	            $("#v_vrp_" + arrS[2] + " .v1").addClass("alpha");
	            $("#dg_vrp_" + arrS[2] + "").addClass("alpha");
	        }
	        else
	        {alert("co co?")}
	            $("#v_vrp_" + arrS[2] + " .v1").empty(); 
	            $("#dg_vrp_" + arrS[2] + " .dg_v1").empty();
	        if (arrS[2] == 0)
	        {$("#v_vrp_" + arrS[2] + " .v1").append(1);}
	        else
	        {   
	            $("#v_vrp_" + arrS[2] + " .v1").append(intNumb + 1); 
	            $("#dg_vrp_" + arrS[2] + " .dg_v1").append(intNumb + 1); 
	        }
        }
        else
        {
	        if ($("#v_vrp_" + arrS[2] + " .v2").text() == intNumb)
	        {
	            m.GPost(arrS[3], arrS[0], intNumb, arrS[2]);
	            $("#v_vrp_" + arrS[2] + " .v2").addClass("alpha");
	        }
	        else
	        {alert("co co?")}
	        $("#v_vrp_" + arrS[2] + " .v2").empty();
	        if (intNumb == 0)
	        {$("#v_vrp_" + arrS[2] + " .v2").append(1);}
	        else
	        {$("#v_vrp_" + arrS[2] + " .v2").append(intNumb + 1);}
        }
        return false;
    });
    

}); //end doc ready
