function getCategories() {
    $.ajax({
        type: "GET",
        url: encodeURI('/_layout/categories_top'),
        contentType: 'text/text; charset=utf-8',
        scriptCharset: 'utf-8',
        success: function(data) {
            $("#categories").html(data);
            $("#categories_bottom").html(data);
  
            
            // Select home tab if neccesary...
            if($(".current").length == 0) {
            	$("#categoryMenu0").addClass('current');
            }
			
            if(window.location.pathname.indexOf('/photo') != -1){
            	$(".current").removeClass('current')
				$("#categoryMenuPhoto").addClass('current');
			}
            if(window.location.pathname.indexOf('/audio') != -1){
            	$(".current").removeClass('current')
				$("#categoryMenuAudio").addClass('current');
			}
			if(window.location.pathname.indexOf('/video') != -1){
				$(".current").removeClass('current')
				$("#categoryMenuVideo").addClass('current');
			}
			if(window.location.pathname.indexOf('/weather') != -1){
				$(".current").removeClass('current')
				$("#categoryMenuWeather").addClass('current');
			}
        },
        async: true,
        cache: true
    });
//    $.ajax({
//        type: "GET",
//        url: encodeURI('/_layout/categories_footer'),
//        contentType: 'text/text; charset=utf-8',
//        scriptCharset: 'utf-8',
//        success: function(data) {
//            $("#footer_categories").html(data);
//        },
//        async: true,
//        cache: true
//    });
}

function createHomePageItem() {
	var categories = document.getElementById("categories");
	var footer_categores = document.getElementById("footer_categories");

    var catTd = document.createElement('td');
    catTd.id = "categoryMenuHomePage";

    var catDiv = document.createElement('div');
    catDiv.className = "pan_3";

    var newA = document.createElement('a');
    newA.href = "/";

    var aText = document.createTextNode("Naslovna");

    newA.appendChild(aText);
    catDiv.appendChild(newA);
    catTd.appendChild(catDiv);
    categories.appendChild(catTd);

    var spaceTd = document.createElement('td');
    spaceTd.className = "menu_spacer_line";

    categories.appendChild(spaceTd);

    var newAF = document.createElement('a');
    newAF.href = "/";
    
    var aTextF = document.createTextNode(result[i].name);
    newAF.appendChild(aTextF);

    footer_categores.appendChild(newAF);

    return false;
}

function getSubCategories(categoryId) {
//    hideSubCategories();
	showSubCategories();
    $.ajax({
        type: "GET",
        url: encodeURI('/_layout/categories_sub?parentId=' + categoryId),
        contentType: 'text/text; charset=utf-8',
        scriptCharset: 'utf-8',
        success: function(data) {
            $("#subcategories").html(data);
            
//            if(data != null && data != '') {
//                showSubCategories();
//            }
        },
        async: true,
        cache: false
    });
    
}

function getNumberOfNewUsers() {
	userServiceImpl.dwrFindNumberOfNewUsers(function(result) {
		dwr.util.setValue("numberOfNewUsers", result);
	});
}

function getNumberOfNewArticles() {
	articleServiceImpl.getNumberOfNewArticles(function(result) {
		dwr.util.setValue("numberOfNewArticles", result);
	});
}

function getNumberOfNewComments() {
	commentServiceImpl.getNumberOfNewComments(function(result) {
		dwr.util.setValue("numberOfNewComments", result);
	});
}

function getNumberOfNewGroups() {
	communityServiceImpl.findNumberOfPending(function(result) {
		dwr.util.setValue("numberOfNewGroups", result);
	});
}

function rateCommentPositive(commentId) {
	document.getElementById("positiveRateLink" + commentId).onclick = function() {};
	document.getElementById("negativeRateLink" + commentId).onclick = function() {};
	commentServiceImpl.ratePositive(commentId, function(result) {
		dwr.util.setValue("positiveRate" + commentId, result);
	});
}

function rateCommentNegative(commentId) {
	document.getElementById("positiveRateLink" + commentId).onclick = function() {};
	document.getElementById("negativeRateLink" + commentId).onclick = function() {};
	commentServiceImpl.rateNegative(commentId, function(result) {
		dwr.util.setValue("negativeRate" + commentId, result);
	});
}

function getNumberOfCommunityArticleComments(articleId, communityId) {
	commentServiceImpl.findNumberOfArticleCommunityComments(articleId, communityId, function(result) {
		dwr.util.setValue("commentCount" + communityId, " (" + result + ")");
	});
}
