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);
            $("#bottom_categories").html(data);

            // Select home tab if neccesary...
            if($(".current").get(0) == null) {//top
                setSelectedCategory('0');
            }
            if($(".current").get(1) == null) {//bottom
                setSelectedCategory('0');
            }
			
			//Select photo story or video
			/*if(window.location.pathname == '/_fotostory/list' || window.location.pathname.indexOf('/_fotostory') != -1){
			   unselectCategory();
			   $("#fotostoryCell").get(0).previousSibling.className = "tab_left";
	           $("#fotostoryCell").get(0).className = "tab_centar";
	           $("#fotostoryCell").get(0).nextSibling.className = "tab_right";
			}
			if(window.location.pathname == '/_video/gallery' || window.location.pathname.indexOf('/_video') != -1){
			   unselectCategory();
			   $("#videoCell").get(0).previousSibling.className = "tab_left";
	           $("#videoCell").get(0).className = "tab_centar";
			}*/
        },
        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 getHeaderDossiers(){
	$.ajax({
        type: "GET",
        url: encodeURI('/_layout/headerDossiers'),
        contentType: 'text/text; charset=utf-8',
        scriptCharset: 'utf-8',
        success: function(data) {
            $("#headerDossiers").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 getNumberOfNewArticleComments() {
	commentServiceImpl.getNumberOfNewArticleComments(function(result) {
		dwr.util.setValue("numberOfNewArticleComments", result);
	});
}

function getNumberOfNewBlogArticleComments() {
	commentServiceImpl.getNumberOfNewBlogArticleComments(function(result) {
		dwr.util.setValue("numberOfNewBlogArticleComments", 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(contentId, contentType, communityId) {
	//var getNumberOfCommunityCommentsFn = null;
	
	if (contentType == 'com.seavus.newsroom.model.Article') {
		//getNumberOfCommunityCommentsFn = commentServiceImpl.getNumberOfArticleCommunityComments;
	} else if (contentType == 'com.seavus.newsroom.model.BlogArticle') {
		//getNumberOfCommunityCommentsFn = commentServiceImpl.getNumberOfBlogCommunityComments;
	}
	
	//if (getNumberOfCommunityCommentsFn != null) {
		//getNumberOfCommunityCommentsFn(contentId, communityId, function(result) {
		//	dwr.util.setValue("commentCount" + communityId, " (" + result + ")");
		//});
	//} else {
		dwr.util.setValue("commentCount" + communityId, "");
	//}
}
