function submitComm(bkm_id, comm_id)
{
	 var commentForm = $("#commentFormId-" + comm_id).get();
	 var raspundeId = $("#raspundeId-" + comm_id).get();
	 var submitCommResultId = $('#submitCommResultId-'+ comm_id).get();
	 var comm_desc = $('textarea#comm_desc').val();
	 var vercode = $('input#contact-verificare').val();
	 //var vercodeimg = $().get();

	$.ajax({
        type: "POST",
        url: "/ajax.php",
        data: {
            ajaxAcces: 'submitComm',
            bkm_id: bkm_id,
            comm_id_parent: comm_id,
            comm_desc: comm_desc,
            vercode: vercode,
            submit_comment: true
        },
        success: function(msg){ 
        //	alert(msg);
        	//$(commentForm).fadeOut("slow");
        	$(submitCommResultId).html(msg);
        	if($('#warn').size() == "0")
        	{
        		//$(comm_desc).html = '';
        		$(raspundeId).fadeOut("slow");
        		setTimeout("sortareComentarii('" + bkm_id + "')",2500);
        		var nrCommentarii = $("#nrCommentarii").get(0);
        		
        		$("#nrCommentarii").get(0);
        		//nrCommentarii.html = nrCommentarii.html + 1;
           		$(nrCommentarii).html(parseInt($(nrCommentarii).html()) + 1);
				
        	}
        	else
        	{
        		//alert('img#vercode-' + comm_id);
        		reloadVercode('img#vercode-' + comm_id);
        	}
        	
        }
	 });
     
     return false;
}


function voteazaComm(comm_id, action)
{
    $.ajax({
        type: "POST",
        url: "/ajax.php",
        data: {
            ajaxAcces: 'voteComm',
            action: action,
            comm_id: comm_id
        },
        success: function(msg){ 
            $('#c-voturi-'+comm_id).html(msg);
        }
	 });
     
     return false;
}

function raspundeComm(comm_id, LVLComm)
{
 
	 var commentForm = $("#commentFormId-" + comm_id).get(0);
	 
	 if(commentForm.style.display == 'none')
	 {
	 $.ajax({
	        type: "GET",
	        url: "/ajax.php",
	        data: {
	            ajaxAcces: 'commentForm',
	            LVLComm: LVLComm,
	            comm_id: comm_id
	        },
	        success: function(msg){ 
	        	//$('li.comentarii.raspuns').hide('slow', function() { $(this).remove(); });
	        	//$(commentForm).show('slow');
	        	$(commentForm).html(msg);
	        	
	        	$(commentForm).slideDown('slow');
	        	$(commentForm).scrollTo(100, {offset:-10});
	        	//alert(commentForm);
	        }
		 });
	 }
	 else
	 {
		 $(commentForm).fadeOut("slow");
	 }
	     return false;

} // function raspundeComm(comm_id)


// sortare comentarii
function sortareComentarii(bkm_id)
{
	var tip_sortare = $('#c-sortare').get(0);
    $.ajax({
        type: "GET",
        url: "/ajax.php",
        data: {
            ajaxAcces: 'listareComentarii',
             bkm_id: bkm_id,
             tip_sortare: tip_sortare.value
        },
        success: function(msg){ 
            $('#listareComentarii').html(msg);
        }
	 });
     
     return false;
}


function commAutori(bkm_id, comm_autori)
{
    $.ajax({
        type: "GET",
        url: "/ajax.php",
        data: {
            ajaxAcces: 'listareComentarii',
             bkm_id: bkm_id,
             comm_autori: comm_autori
        },
        success: function(msg){ 
            $('#listareComentarii').html(msg);
            $("#meniu-c").find("a").attr("class", "normal");
                 var commAutoriLink = document.getElementById(comm_autori);
             commAutoriLink.className = "inactiv";
            //alert($(comm_autori).get(0));

        }
	 });
     
     return false;
}



/*
 * ScrollToElement 1.0
 * Copyright (c) 2009 Lauri Huovila, Neovica Oy
 *  lauri.huovila@neovica.fi
 *  http://www.neovica.fi
 *  
 * Dual licensed under the MIT and GPL licenses.
 */

(function($) {
    $.scrollToElement = function( $element, speed ) {

        speed = speed || 750;

        $("html, body").animate({
            scrollTop: $element.offset().top,
            scrollLeft: $element.offset().left
        }, speed);
        return $element;
    };

    $.fn.scrollTo = function( speed ) {
        speed = speed || "normal";
        return $.scrollToElement( this, speed );
    };
})(jQuery);


/* Votare comentarii */
function voteazaComm(comm_id, action)
{
    $.ajax({
        type: "POST",
        url: "/ajax.php",
        data: {
            ajaxAcces: 'voteComm',
            action: action,
            comm_id: comm_id
        },
        success: function(msg){ 
            $('#c-voturi-'+comm_id).html(msg);
        }
	 });
     
     return false;
}

$(document).ready(function(){
    $('a.c-link-rasp').click(function(){
        $('#comm_desc').focus();
        return false;
    });
    
    
    $('a.afiseaza').click(function(){
        var comentariu = $(this).closest('div.comentariu');
        $(comentariu).toggleClass('gri');
        if ((comentariu).hasClass('gri')) {
            $(this).html('Afiseaza');
        } else {
            $(this).html('Ascunde');
        }
        
        return false;
    });
});

/* Filtrare comentarii */
function filtruComm(bkm_id) {
	if($("#spanCommFilter").html() == 'false') {
		$("#spanCommFilter").html("true");
		$("div.comentariu.negativ").addClass("gri");
		$("div.comentariu.negativ p.c-body-gri").hide();
		$("div.comentariu.negativ p.c-body").addClass("c-body-gri");
		$("div.comentariu.negativ p.c-body").removeClass("c-body");
		$("div.comentariu.negativ p.c-body-gri").html("Comentariu ascuns.");
	}
	else {
		sortareComentarii(bkm_id);
	}

}

