﻿var pWinMathML=null;
var pWinForgetPassword=null;
var pWinNewPassword=null;
var pWinNewKeyWord=null;
var pWinEditTag=null;
function EditTag(ID){
if (pWinEditTag!=null){
    pWinEditTag.show();
    $("#EditTag_ID").val(ID);
    return ;
}
jQuery.get('/Question/HTML/EditTag.html', function(data) {
   pWinEditTag=new Boxy(data, {title:"标注信息"});
$("#EditTag_ID").val(ID);
});
}
function saveEditTag(){
jQuery.facebox("正在提交......");
$.post("SaveFunnyNodeTag.aspx",
        {
            action: "post",
            ID: $("#EditTag_ID").val(),
Tag: $("#EditQuestion_Tag").val()
        },
        function(data){
            $("#EditTag_ButtonOK").show();
jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
pWinEditTag.hide();
        }
);
}
function FileTagRemove(id,strTag)
{
    $.post("./../Node/RemoveTag.aspx", 
        {ID: id,Tag:strTag},
        function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
        });
}
function GetNewQuestionKey(){
return GetQuestionKey("NewQuestion_Key");
}
function GetQuestionKey(strName){
var strKey="";
$("input[name='"+strName+"']").each(function() {
    if (this.checked){
        strKey+=this.value+" ";
    }
});
//strKey=strKey.trim(); //IE有错
return strKey;
}
function NewKeyWord(ID){
if (pWinNewKeyWord!=null){
    pWinNewKeyWord.show();
    $("#EditKeyWord_ID").val(ID);
    $("#EditKeyWord_Word").val(strQuestionTags);
    return ;
}
jQuery.get('/Question/HTML/EditKeys.html', function(data) {
   pWinNewKeyWord=new Boxy(data,{title:'增加Tag'});
$("#EditKeyWord_ID").val(ID);
$("#EditKeyWord_Word").val(strQuestionTags);
});
}
function saveNewKeyWord(){
    $("#EditTag_ButtonOK").hide();
    jQuery.facebox("正在提交......");
    $.post("SaveNewKeywords.aspx", 
        {
            action: "post",
            ID: $("#EditKeyWord_ID").val(),
            Tag: $("#EditKeyWord_Word").val()
        },
        function(data){
            $("#EditKeyWord_ButtonOK").attr("style","block");
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
            pWinNewKeyWord.hide();
        });
}

var strQuestionTags="";
var strMathKeys=",时间,距离,";
function MathTags(strTags){
    strTags=strTags.replace("\r\n","");
    var strSplit=strTags.split(" ");
    var strReturn="";
    for (var i=0;i<strSplit.length;i++){
        if (strSplit[i]!="" && strMathKeys.indexOf(","+strSplit[i]+",")>0){
            strReturn+=" "+strSplit[i];
        }
    }
    return strReturn;
}
function TagLink(strTags,ID){
var strSplit=strTags.split(" ");
var strReturn="";
for (var i=0;i<strSplit.length;i++)
{
    strReturn+='<a class="tag" href="/Question/List.aspx?Key='
+encodeURI(strSplit[i])+'">'+strSplit[i]+'</a>&nbsp;';
    if (ID>0){
        strReturn+="<a style=\"color:red;\" "
+"href=\"javascript:FileTagRemove("+ID+",'"+strSplit[i]+"');\">x</a> ";
    }
}
return strReturn;
}
function ShowPoint(strID,strMoney){
if (strMoney==""){
    document.writeln("");
}else if (strMoney=="0"){
    document.writeln("");
}else{
    var dbMoney=parseFloat(strMoney);
    document.writeln("<a href=\"javascript:AboutPoint("+strID+")\">"
        +"<span style='color:red'><B>P:" +dbMoney+"</B></span></a>");
}
}
function AboutPoint(strID){
var pWinPoint=null;
jQuery.get('/Question/HTML/AboutPoint.html', function(data) {
   html=data.replace("{Point.Link}",
	"<br><a href='../Point/GetPointFromNodeID.aspx?ID="+strID+"'>领取ID="+strID+"的奖励</>");
html = jQuery(html);
pWinPoint=new Boxy(html, {title:"关于Point"});
});
}
function ShowSetPoint(strID){
    var strHTML="如果你有Point，你也可以给这个题目设置一些Point.<br>"+
"支持的人越多，Point越高，被解决概率也就越大，被解决速度也更快！<br/>"+
"<table>"+
"<tr><td>题目ID</td><td><input id=\"ShowPoint_ID\" readonly value=\""+strID+"\"/></td></tr>"+
"<tr><td>Point</td><td><input id=\"ShowPoint_Point\" value=\"0\"/></td></tr></table>"+
"<input type=\"button\" onclick=\"Set_Point_To_The_Question()\" value=\"转移Point\"/>";
    jQuery.facebox(strHTML);
}
function Set_Point_To_The_Question(){
    $.post("./../Point/SetPoint.aspx", 
    {
            action: "post",
            ID: $("#ShowPoint_ID").val(),
            Point: $("#ShowPoint_Point").val()
    },
    function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
    });
}
function WinNewPassword(){
jQuery.get('/Question/HTML/NewPassword.html', function(data) {
   pWinNewPassword=new Boxy(data,{title:'修改密码'});
});
}
function NewPassword(){
jQuery.facebox("正在提交......");
$.post("/Login/NewPassword.aspx",
        {
            action: "post",
            Password: $("#Password1").val(),
Password2: $("#Password2").val()
        },
        function(data){
            jQuery.facebox(data+",密码已经修改!");
pWinNewPassword.hide();
        }
);
}
function ForgetPassword(){
jQuery.facebox("正在提交......");
$.post("./../Login/SendPassword.aspx", 
    {
        action: "post",
        Email: $("#ForgetPassword_Email").val()
    },
    function(data){
        jQuery.facebox(data);
        WinForgetPassword.hide();
    });
}
function WinForgetPassword(strID){
jQuery.get('/Question/HTML/ForgetPassword.html', function(data) {
   WinForgetPassword=new Boxy(data,{title:'忘记密码'});
});
}

function WinMathML(){
jQuery.get('/Question/HTML/WinMathML.html', function(data) {
   pWinMathML=new Boxy(data,
{title:'数学公式输入方法，注意修改为$$开头，$$结尾'});
});
}
function Win_MathDraw(){
jQuery.get('/Question/HTML/WinDraw.html', function(data) {
   pWinMathML=new Boxy(data,{title:'数学画图'});
});
}
function CancelFav(strID){
jQuery.facebox("正在提交......");
    $.post("/User/CancelFav.aspx", {
            action: "post",ID: strID
        },function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
        });
}
function removeNode(id){
if (confirm("确认删除"+id)){
    $.post("./RemoveQuestion.aspx", { ID: id },
       function(data){
            jQuery.facebox(data+"<a href='javascript:Web_Refresh()'>刷新</a>");
       });
}
}
function Logout(){
var strURL="/Question/Logout.aspx";
window.location=strURL;
}
function Web_Refresh(){
window.location.reload(true);
}
function TimeHello(){
var now = new Date();
    var hours = now.getHours();
    if(hours < 6){document.write("起得太早!")}
    else if (hours < 9){document.write("早上好!")}
    else if (hours < 12){document.write("上午好!")}
    else if (hours < 14){document.write("中午好!")}
    else if (hours < 17){document.write("下午好!")}
    else if (hours < 19){document.write("傍晚好!")}
    else if (hours < 22){document.write("晚上好!")}
    else {document.write("可以睡觉了!")}
}
