﻿var pWinAsk=null;

function NewQuestion(){
    if (pWinAsk!=null){
        pWinAsk.show();
	    return ;
    }
    
    jQuery.facebox("正在打开......");
    var url="./HTML/NewQuestion.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='提问';
	        pWinAsk=new Boxy(html, options);
	        
	        KE.init({
                id : 'Ask_Content',
                cssPath : './../Common/kindeditor-3.3.1/examples/index.css',
                items : [
        'undo', 'redo', 'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
        'removeformat', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
        'insertunorderedlist']

            });
            //KE.remove('Content');
	        KE.create('Ask_Content');
	        KE.util.setData('Ask_Content');
	        jQuery.facebox.close();
        }
    };
	
    jQuery.each(['type', 'cache'], function() {
        if (this in options) {
	        ajax[this] = options[this];
	        delete options[this];
        }
    });
	
    jQuery.ajax(ajax);
}


function saveQuestion(){
    if ($("#Diff").val()=="0"){
        alert("请选择难度！");
        return ;
    }
    
    if ($("#Name").val()==""){
        alert("请输入标题！");
        return ;
    }
    
    var strContent=KE.util.getData('Ask_Content');
    if (strContent==""){
        alert("请输入内容");
        return ;
    }
    
    $("#ButtonOK").attr("diable","diable");
    jQuery.facebox("正在提交......");
    
    $.post("SaveQuestion.aspx", 
        {
            action: "post",
            Name: $("#Name").val(),
            Key: "Diff:"+$("#Diff").val()+" "+GetNewQuestionKey(),
            Content: strContent,
            Point: $("#TxPoint").val()
        },
        function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
            pWinAsk.hide();
        });
}


function saveEditQuestion(){
    var strContent=KE.util.getData('EditQuestion_Content');
    if (strContent==""){
        alert("请输入内容");
        return ;
    }
    
    $("#EditQuestion_ButtonOK").hide();
    
    $("#Msg").show();
    $("#Msg").html("正在提交......");
    
    
    //sendToSeg(strContent);
    $.post("SaveQuestion.aspx", 
        {
            action: "post",
            ID: $("#EditID").val(),
            Name: $("#EditQuestion_Title").val(),
            Content: strContent,
            Point: $("#TxPoint").val()
        },
        function(data){
            $("#EditQuestion_ButtonOK").attr("style","block");
            $("#Msg").html(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
            $("#Msg").attr("style","block");
            pWinAsk.hide();
            setTimeout("Web_Refresh()",2000);
        });
}


var pWinReply=null;

function ReplyQuestion(ID){
    if (pWinReply!=null){
        pWinReply.show();
        $("#TxID").val(ID);
	    return ;
    }
    
    jQuery.facebox("准备回复......");
    
    var url="./HTML/ReplyQuestion.html";
    var options = {};
	
    var ajax = {
        url: url, type: 'GET', dataType: 'html', cache: false, success: function(html) {
	        hideMsg();
	        
	        html = jQuery(html);
	        if (options.filter) html = jQuery(options.filter, html);
	        options.title='回复';
	        pWinReply=new Boxy(html, options);
	        
	        $("#ReplyQuestion_Name").val("Re:"+$("#Question_Title").val());
            $("#TxID").val(ID);
            
            KE.init({
                id : 'Reply_Content',
                cssPath : './../Common/kindeditor-3.3.1/examples/index.css'
            });
            //KE.remove('Content');
	        KE.create('Reply_Content');
	        KE.util.setData('Reply_Content');
	        
	        jQuery.facebox.close();
        }
    };
	
    jQuery.ajax(ajax);
    
}


function saveQuestion_Reply(){
    var strContent=KE.util.getData('Reply_Content');
    if (strContent==""){
        alert("请输入内容");
        return ;
    }
    
    $("#ButtonOK").attr("diable","diable");

    jQuery.facebox("正在提交......");
    
    $.post("ReplyQuestion.aspx", 
        {
            action: "post",
            Name: $("#ReplyQuestion_Name").val(),
            ID: $("#TxID").val(),
            Content: strContent
        },
        function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
            pWinReply.hide();
            //setTimeout("Web_Refresh()",2000);
        });
}

function hideMsg(){
    $("#Msg").attr("style","display:none");
}

function Web_Refresh(){
    window.location.reload(true)
}

var pWinEdit=null;
function EditQuestion(ID){
    if (pWinEdit!=null){
        pWinEdit.show();
        $("#EditID").val(ID);
        KE.remove('EditQuestion_Content');
	    GetEditContent(ID);
	    return ;
    }
    
    var url="./HTML/EditQuestion.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)
{
    $("#Msg").html("读取内容...");
    $("#Msg").show();
    $.post("../Node/ReadNode.aspx", 
        {
            action: "post",
            ID: ID,
            Field: "Content"
        },
        function(data){
            $("#EditQuestion_Content").val(data);
	        GetEditTitle(ID);
	        
	        KE.init({
                id : 'EditQuestion_Content',
                cssPath : './../Common/kindeditor-3.3.1/examples/index.css'
            });
	        KE.create('EditQuestion_Content');
	        KE.util.setData('EditQuestion_Content')
        });
}

function GetEditTitle(ID)
{
    $("#Msg").html("读取标题...");
    $("#Msg").show();
    $.post("../Node/ReadNode.aspx", 
        {
            action: "post",
            ID: ID,
            Field: "Name"
        },
        function(data){
            $("#EditQuestion_Title").val(data);
            $("#Msg").hide();
        });
}

