﻿var pWinNewItem=null;
var iClassID=0;
function NewNews(ID){
    if (pWinNewItem!=null){
        pWinNewItem.show();
        return ;
    }

    iClassID=ID;
    jQuery.facebox("正在打开......");
    var url="./HTML/NewNews.html";
    var options = {};
    
    var ajax = {
        url: url, type: 'GET', dataType: 'html', cache: false, 
        success: function(html) {
            html = jQuery(html);
            if (options.filter) html = jQuery(options.filter, html);
            options.title='提问';
            pWinNewItem=new Boxy(html, options);
            
            KE.init({
                id : 'NewNews_Content',
                cssPath : './../Common/kindeditor-3.3.1/examples/index.css'
            });
              KE.create('NewNews_Content');
            KE.util.setData('NewNews_Content');
            jQuery.facebox.close();
        }
    };
    
    jQuery.each(['type', 'cache'], function() {
        if (this in options) {
            ajax[this] = options[this];
            delete options[this];
        }
    });    
    jQuery.ajax(ajax);
}


function saveNews(){
    if ($("#Name").val()==""){
        alert("请输入标题！");
        return ;
    }
    
    var strContent=KE.util.getData('NewNews_Content');
    if (strContent==""){
        alert("请输入内容");
        return ;
    }
    $("#ButtonOK").attr("diable","diable");
    jQuery.facebox("正在提交......");
    
    $.post("SaveNews.aspx", 
        {
            action: "post",
            Name: $("#Name").val(),
            Content: strContent,
            ClassID:iClassID
        },
        function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
            pWinNewItem.hide();
        });
}
var pWinEdit=null;
function EditNews(ID){
    if (pWinEdit!=null){
        pWinEdit.show();
        $("#EditID").val(ID);
        KE.remove('EditQuestion_Content');
        GetEditContent(ID);
        return ;
    }
    
    var url="./HTML/EditNews.html";
    var options = {};
    
    var ajax = {
        url: url, type: 'GET', dataType: 'html', cache: false, 
        success: function(html) {
            html = jQuery(html);
            if (options.filter) html = jQuery(options.filter, html);
            pWinEdit=new Boxy(html, options);
            
            $("#EditID").val(ID);
            GetEditContent(ID);
        }
    };
    
    jQuery.each(['type', 'cache'], function() {
        if (this in options) {
            ajax[this] = options[this];
            delete options[this];
        }
    });
    
    jQuery.ajax(ajax);
}

function GetEditContent(ID)
{
    jQuery.facebox("读取内容...");
    $.post("../Node/ReadNode.aspx", 
        {
            action: "post",
            ID: ID,
            Field: "Content"
        },
        function(data){
            $("#EditNews_Content").val(data);
            GetEditTitle(ID);
            
            KE.init({
                id : 'EditNews_Content',
                cssPath : './../Common/kindeditor-3.3.1/examples/index.css'
            });
            KE.create('EditNews_Content');
            KE.util.setData('EditNews_Content')
        });
}

function GetEditTitle(ID)
{
    jQuery.facebox("读取标题...");
    $.post("../Node/ReadNode.aspx", 
        {
            action: "post",
            ID: ID,
            Field: "Name"
        },
        function(data){
            $("#EditNews_Title").val(data);
            jQuery.facebox.close();
        });
}

function saveEditNews(){
    var strContent=KE.util.getData('EditNews_Content');
    if (strContent==""){
        alert("请输入内容");
        return ;
    }
    
    $("#EditNews_ButtonOK").hide();
    jQuery.facebox("正在提交......");

    $.post("SaveNews.aspx", 
        {
            action: "post",
            ID: $("#EditID").val(),
            Name: $("#EditNews_Title").val(),
            Content: strContent,
            Point: $("#TxPoint").val()
        },
        function(data){
            $("#EditNews_ButtonOK").show();
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
        });
}
function ReplySave(){
    var strContent=$('#Reply_Content').val();
    if (strContent==""){
        alert("请输入评论内容");
        return ;
    }
    if ($('#Reply_Name').val()==""){
        alert("请输入评论标题");
        return ;
    }
    jQuery.facebox("正在提交......");    
    $.post("CommentSave.aspx", 
        {
            action: "post",
            Name: $("#Reply_Name").val(),
            ID: $("#Reply_ID").val(),
            Content: strContent
        },
        function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
        });
}
function saveAudit(ID,iAudit){
    jQuery.facebox("正在提交......");
    
    $.post("CommentAudit.aspx", 
        {
            action: "post",
            ID:ID,
            Audit:iAudit
        },
        function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
        });
}
function SaveAllowComment(ID,iType){
    jQuery.facebox("正在提交......");
    $.post("SaveAllowComment.aspx", 
        {
            action: "post",
            ID:ID,Type:iType
        },
        function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
        });
}
function RemoveNews(ID){
    jQuery.facebox("正在删除......");
    $.post("NewsRemove.aspx", 
        {
            action: "post",
            ID:ID
        },
        function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
        });
}