﻿writeToElem = function(elem,text)
{
    try
    {
        if(elem!=null)
            elem.innerHTML = text
    }
    catch(e)
    {
        alert(e);
    }
}

writeToElemById = function(elemId,text)
{
    try
    {
        var container = document.getElementById(elemId);
        if(container!=null)
        {
            container.innerHTML = text;
        }
    }
    catch(ex)
    {
        alert(ex);
    }
}

//GetArticleId
GetATC = function()
{
    return document.getElementById("atcid").value;
}

setComments = function(startindex,maxrows)
{
    try
    {
        var text=AjaxPortal.GetComments(GetATC(),startindex,maxrows);
        writeToElemById("latestComments",text.value);
    }
    catch(ex)
    {
        alert(ex)
    }
}

//最新文章
setLatest=function()
{
    var text= AjaxPortal.GetLatestArticle(5);
    writeToElemById("latestArticles",text.value);
}

//提交评论
postComment=function()
{
    if(!checkRequire("commenter"))
    {
        alert("请填写您的姓名");
        return;
    }
    if(!checkRequire("txcontent"))
    {
        alert("请填写评论内容");
        return;
    }
    var user =  document.getElementById("commenter").value;
    var content = document.getElementById("txcontent").value;
	var text= AjaxPortal.PostComments(GetATC(),user,content);
    writeToElemById("latestComments",text.value);
    document.getElementById("commenter").value = "";
    document.getElementById("txcontent").value = "";
}

//热门文章
setNewsTop = function()
{
    var text = AjaxPortal.GetTopArticle(10);
    writeToElemById("newsTop",text.value);
}

//更新点击量
visitArticle = function()
{
    var text = AjaxPortal.VisitArticle(GetATC());
    var num = Number(text.value);
    
    if(num<0)
    {
        if(num==-1)alert("没有权限访问");
        else if(num==-2)alert("抛异常了！！");
     //   window.location.href="information/AccessDeny.htm";
    }
    
    writeToElemById("clickCount",text.value);
}
//设置通讯员
setAtcAuthor = function()
{
    var AtcAuthor =  document.getElementById("AtcAuthor").innerText
    var text = AjaxPortal.GetCountAuthor(AtcAuthor);
    writeToElemById("AtcAuthor",text.value);
}

//图库
SetAlbumsTop = function()
{
    var text = AjaxPortal.GetGalleryAlbums(2);
    writeToElemById("gallery",text.value);
}

//获取评论条数
setCommentCount = function()
{
    var text = AjaxPortal.GetArticleCommentCount(GetATC());
           
    writeToElemById("commentCount",text.value);
}
