﻿var hal = "";

window.onload = function() {
    getArticleList(page);
}

function getArticleList(page) {
    document.getElementById("articleList").innerHTML = '<center><img src="'+rootPath+'webTemplate/images/ajax/loading1.gif"></center>'
    WCFContent.JSON_getTrArticleList(mc, smc, page, getArticleListOnComplete);
    hal = page;
} 

function getArticleListOnComplete(StringResult) {
    var temp = "";
    var result ="";
    eval("result = " + StringResult)

    for (var i = 1; i < result.data.length  ; i++) {
        temp=temp + "<div class=\"articleSynopsis\">";
        temp=temp + "<div class=\"synopsisImage\">";
        temp=temp + "<div style='overflow:hidden; width:120px; height:120px;'><a href=\"" + rootPath + "news/" + converStrToParam(MyURLDecode(result.data[i].title)) + "/" + mc + "/" + smc + "/" + hal + "/" + result.data[i].articleRef + "\"><img src=\"" + rootPath + "images/article/" + result.data[i].entityCode + "/" + result.data[i].moduleCode + "/" + result.data[i].subModuleCode + "/" + result.data[i].articleRef + "/T\" width=\"120\" alt=\"\" border=\"0\"></a></div>"
        temp=temp + "</div>";
        temp=temp + "<div class=\"synopsisItem\">";
        temp=temp + "<a href=\"" + rootPath + "news/" + converStrToParam(MyURLDecode(result.data[i].title)) + "/" + mc + "/" + smc + "/" + hal + "/" + result.data[i].articleRef + "\" class=\"alinkBigArticle\">" + MyURLDecode(result.data[i].title2) + "</a><br><br />";
        temp=temp + MyURLDecode(result.data[i].synopsis) + "&nbsp;<a href=\"" + rootPath + "news/" + converStrToParam(MyURLDecode(result.data[i].title)) + "/" + mc + "/" + smc + "/" + hal + "/" + result.data[i].articleRef + "\" class=\"alink\">selengkapnya</a>";
        temp=temp + "</div>";
        temp=temp + "</div>";
    }
    document.getElementById("articleList").innerHTML = temp;
    
        total = result.data[0].total;
        pageNo = result.data[0].pageNo;
        rowNum = result.data[0].rowNum;
        var tempPaging="";
    if (result.data[0].total != 0){
    var prev = (pageNo * 1) - 1;
    var next = (pageNo * 1) + 1;
        if (pageNo == 1){
            prev = 1;
        }
        else if (pageNo == total){
            next = total;
        } 
        if (total == 1){
            next = 1;
            prev = 1;
        } 
        tempPaging += "<a href=\"javascript:getArticleList("+ prev +")\"><img src=\"" + rootPath + "webTemplate/images/button_prevnext.gif\" width=\"14\" height=\"14\" alt=\"\" border=\"0\" id=\"prev\" onmouseover=\"MM_swapImage('prev','','" + rootPath + "webTemplate/images/button_prevnext_o.gif',1)\" onmouseout=\"MM_swapImgRestore()\"></a>";
        tempPaging += "&nbsp;&nbsp;";
        tempPaging += "<a href=\"javascript:getArticleList("+ next +")\"><img src=\"" + rootPath + "webTemplate/images/button_prevnext.gif\" width=\"14\" height=\"14\" alt=\"\" border=\"0\" id=\"next\" onmouseover=\"MM_swapImage('next','','" + rootPath + "webTemplate/images/button_prevnext_o.gif',1)\" onmouseout=\"MM_swapImgRestore()\"></a>";
        document.getElementById("pressPaging").innerHTML = tempPaging;
    }
}
