﻿// JScript 文件

function showMorePost(id)
{
    var divObj = $("divPost_" + id); 
    if(divObj != null)
    {   
        var divLast = findNodeByIdx(divObj.childNodes, 1);
        var divList = findNodeByIdx(divObj.childNodes, 2);
        divLast.style.display = "none";    
        divList.style.display = "";    
        if(divList.innerHTML == "none")
        {    
            divList.innerHTML = "<div class=\"textalign\"><img src=\"/Skin/Images/common/loading.gif\" /></div>";
            var xmlPosts = createDomDoc();
            loadByUrl(xmlPosts, "/ArticleModule/XmlPosts.aspx?idx=" + id, afterLoadPost);
        }
    }
} 

function afterLoadPost(xmlPosts)
{    
    var xsltPosts = createDomDoc();
    xsltPosts.async = false;
    xsltPosts.load("/XmlBase/zh-CN/TranslationPost.xslt");    
    
    var id = selectNodes(xmlPosts, "TranslationPosts/TranslationIdx")[0].text;  
        
    var divObj = $("divPost_" + id);           
    var divList = findNodeByIdx(divObj.childNodes, 2);   
    divList.innerHTML = xmlPosts.transformNode(xsltPosts);
}

function closeMorePost(id)
{    
    var divObj = $("divPost_" + id);           
    if(divObj != null)
    {
        var divList = findNodeByIdx(divObj.childNodes, 2);  
        var divLast = findNodeByIdx(divObj.childNodes, 1);  
        divList.style.display = "none";
        divLast.style.display = "";
    }
}

//============================================

function digArticle(obj, idx)
{   
    obj.disabled = "disabled";
    if(obj.type == "image")
    {
        obj.src = "/skin/images/comment_bgr2.gif";
    }    
    var span = $("DigCount_" + idx);    
    if(span != null)
    {        
        var count = parseInt(span.innerHTML, 10);
        count+=1;
        span.innerHTML = count;
    }
    
    var spanLeft = $("DigCountLeft_" + idx);    
    if(spanLeft != null)
    {        
        var count = parseInt(spanLeft.innerHTML, 10);
        count+=1;
        spanLeft.innerHTML = count;
    }
    
    ElansoArticle.Recommend(idx, OnDigSucceeded);        
}

// This is the callback function that
// processes the Web Service return value.
function OnDigSucceeded(result)
{    
    if(result != "-1")
    {
        var array = result.split(',');
        if(array.length == 2)
        {
            var span = $("DigCount_" + array[1]);            
            if(span != null)
            {
                span.innerHTML = array[0];
            }
        }        
    }    
}

function flowerArticle(obj, idx)
{   
    obj.disabled = "disabled";
     var span = $("FlowersCount_" + idx);
    if(span != null)
    {
        var count = parseInt(span.innerHTML, 10);
        count+=1;
        span.innerHTML = count;
    }
    ElansoArticle.SendFlowers(idx, OnFlowerSucceeded);        
}

function OnFlowerSucceeded(result)
{    
    if(result != "-1")
    {
        var array = result.split(',');
        if(array.length == 3)
        {
            var span = $("FlowersCount_" + array[1]);
            if(span != null)
            {
                span.innerHTML = array[2];
            }
        }        
    }    
}

function unLoginClew(msg, url)
{
    if(confirm(msg))
    {
        window.location = url;
    }
}

function claimArticle(obj, id)
{ 
    var parentObj = $("targetLn_" + id);    
    var ddlObj = findNodeByIdx(parentObj.childNodes, 1);
    if(confirm(confirmTran + Trim(ddlObj.options[ddlObj.selectedIndex].innerHTML) + "?"))
    {
        var targetLn =  ddlObj.value;
        //alert(targetLn);
        ElansoArticle.ClaimArticle(id, targetLn, OnClaimSucceeded);
    }
}

function OnClaimSucceeded(result)
{    
    //alert(result);
    if(result == "0")
    {
       window.location = "/MyBoki/MyTranslatingArticle.aspx";
    }    
    if(result == "30004")
    {
       alert(txtClaimed);
    }    
    if(result == "30007")
    {
       alert(txtUnfinished);
       window.location = "/MyBoki/MyTranslatingArticle.aspx";
    }    
}

function afterGetTranIdx(result)
{
    if(result != "-1")
    {
        window.location = "/ArticleModule/Compare.aspx?ArticleID=" + result;
    }
}

function compareRead(aid, topicid)
{
    var parentObj = $("CompareTranLn_" + aid);
    var targetLn =  findNodeByIdx(parentObj.childNodes, 1).value;
    //alert(targetLn);
    ElansoArticle.GetTranIdx(topicid, targetLn, afterGetTranIdx);
} 
