﻿
window.onload = function() {
    hideIndicator();
    getCommentList(1);
}


function saveComment() {
    var comment = "";
    comment = document.getElementById("txtComment").value;
    
    if (comment == "") {
        alert("Silahkan isi komentar terlebih dahulu");
        document.getElementById("txtComment").focus();
        return;
    }

    //alert(_blogRef);
    document.getElementById("divIndComment").style.display = "";
    document.getElementById("divButtonComment").style.display = "none";
    document.getElementById("divStatusComment").innerHTML = "";
    WCFProfile.JSON_insertBlogComment(_blogLoginName, _blogRef, _frLoginName, _frName, _frEmail, comment, saveCommentOnComplete, saveCommentOnError);
}

function saveCommentOnComplete(result) { 
    
    document.getElementById("divIndComment").style.display = "none";
    document.getElementById("divButtonComment").style.display = "";
    if (result == "1") {
        document.getElementById("divStatusComment").innerHTML = "Comment sent, Waiting Approval";
        document.getElementById("txtComment").value = "";
    } else {
        alert(result);
        document.getElementById("divStatusComment").innerHTML = "send comment failed, please <a href='" + _rootPathDot + "login'>login</a> first and try again.";
        }
} 

function saveCommentOnError(result) { 
    document.getElementById("divIndComment").style.display = "none";
    document.getElementById("divButtonComment").style.display = "";
    //alert(result.get_message()); 
} 

function getCommentList(p) {
    if (document.getElementById("divIndCommentList") != null) {
        document.getElementById("divIndCommentList").style.display = "";
        WCFProfile.JSON_getBlogCommentListPaging(_blogLoginName, _blogRef, "A", p, getCommentListOnComplete, getCommentListOnError);
    }
}   

function getCommentListOnComplete(result) {
    var temp = "";
    var ds;
    eval("ds = " + result);
    //alert(result);
    //alert(result.length);
    
    for (var i = 0; i < ds.data.length  ; i++) {
        //alert(ds.data[i].screenName);
        temp=temp + "<div style=\"width: 450px; margin-left: 5px; float: left; margin-bottom:10px; \"> ";
        temp=temp + "<div style=\"width: 57px; height: 57px; float: left; margin-right: 6px;\"> ";
        //alert(MyURLDecode(ds.data[i].screenName))
        if (ds.data[i].screenName != '') {
            temp=temp + "<div><a href='" + _rootPathDot + "profile/" + ds.data[i].screenName + "'><img border=\"0\" onerror=\"noSMPic(this);\" src=\"" + _rootPathDot + "support/gambar.member/A/" + MyURLDecode(ds.data[i].screenName) + "/0\" /></a></div> ";
        } else {
            temp=temp + "<div><img border=\"0\" onerror=\"noSMPic(this);\" src=\"" + _rootPathDot + "support/gambar.member/A/-/0\" /></div> ";
        }
        temp=temp + "</div> ";
        temp=temp + "<div style=\"float: left; width:380px;\"> ";
        temp=temp + "<div class=\"calendarDay\"> ";
        temp=temp + "Post : " + MyURLDecode(ds.data[i].commentDateConvert);
        temp=temp + "</div> ";
        temp=temp + "<div style=\"\" class=\"text0\"> ";
        temp=temp + MyURLDecode(ds.data[i].comment);
        temp=temp + "<div class=\"textBold06\"> ";
        temp=temp + MyURLDecode(ds.data[i].frName);
        temp=temp + "</div> ";
        temp=temp + "</div> ";
        temp=temp + "</div> ";
        temp=temp + "</div>";
        
    }
    
    if (ds.paging[0].total > 1) {
        temp = temp + "<div class=\"navSub01\" style=\"float:right; width: 450px; overflow:hidden; margin-bottom:10px;\">Page : ";
        for (i=1;i<=ds.paging[0].total;i++) {
            if (i==ds.paging[0].page) {
                temp = temp + "<b>" + i + "</b> ";
            } else {
                temp = temp + "<a href=\"javascript:getCommentList(" + i.toString() + ");\">" + i + "</a> ";
            }
        }
        temp = temp + "</div>";
    }
    
    document.getElementById("divIndCommentList").style.display = "none";
    document.getElementById('divComment').innerHTML = temp;
}

function getCommentListOnError(result) {
    document.getElementById("divIndCommentList").style.display = "none";
    alert(result.get_message()); 
}