﻿var pagerTop = 0;
var extendfilename = "aspx";
var currid = 0;
var params = {eventTarget:null,keyVale:null,textV:"",noteText:""};
$().ready(
		function()
		{
		     $(window).scroll(ChangePagePosition);
		     
		     $("#postbook").click(OpenPostBook);
		     
		     $("#seeallbook").click(GotoIndex);
		     
		     $("#manage").click(ManagerLogin);
		     
		     $("#editinfo").click(EditInfomation);
		     
		     $(".optop").click(OPTop);
		     
		     $(".opreplay").click(OPReplay);
		     
		     $(".ophid").click(OPHidden);
		     
		     $(".opdel").click(OPDelete);
		     
		     if($('body').attr('autojs')=="login")
		         ManagerLogin()
		     
		     if(parseInt($("#Pagination").attr("totalcount"))>0)
             {
                    $(".pagination").pagination(parseInt($("#Pagination").attr("totalcount")), {
                    items_per_page:parseInt($("#Pagination").attr("pagesize")),
					num_edge_entries: 2,
					num_display_entries: 5,
					prev_text:"上一页",
					next_text:"下一页",
					current_page:parseInt($("#Pagination").attr("currentpage")),
					link_to:"?page=__id__",
                    callback: pageselectCallback
                });
                }
		}
)
function pageselectCallback(){}
function OPDelete()
{
    var e = $.getEvent();
    currid=$(e.target).parent().attr("currid");
    $.ShowWindow("loading","信息中心","正在删除",100,180,true,false,null,"color:#00088c;");
    
    NgBook.Web.Index.DeleteBookAndReplay(currid,DeleteCallBack);
}

function DeleteCallBack(val)
{
    if(val.value.indexOf("true,")>=0)
    {
       $.ShowWindow("success","信息中心","删除成功,2秒后返回第一页",100,200,true,false,null,"color:#00088c;");
       setTimeout("window.location.href = './index."+extendfilename+"';",2000);
    }
    else
    {
       $.ShowWindow("error","信息中心","删除消息失败,请重试",100,180,false,false,null,"color:#00088c;"); 
    }
}
function OPHidden()
{
    var e = $.getEvent();
    currid=$(e.target).parent().attr("currid");
    params.eventTarget = e.target;

    if($(e.target).parent().attr("hidV").toLowerCase()=="true")
    {
        params.textV = "显示";
        params.noteText = "隐藏";
        params.keyValue = false;
    }
    else
    {
        params.textV = "隐藏";
        params.noteText = "显示";
        params.keyValue=true;
    }
    
    $.ShowWindow("loading","信息中心","正在设置为:"+params.noteText,100,180,true,false,null,"color:#00088c;");
    NgBook.Web.Index.HidBook(currid,params.keyValue,HiddenCallBack);
}

function HiddenCallBack(val)
{
    if(val.value.indexOf("true,")>=0)
    {
       $.ShowWindow("success","信息中心","设置"+params.noteText+"成功",100,180,false,false,null,"color:#00088c;");
       $(params.eventTarget).parent().attr("hidV",(params.keyValue).toString());
       $(params.eventTarget).text(params.textV);
       if(params.keyValue)
       {
            $("#ngtr"+currid.toString()).removeClass("hidclass");
       }
       else
       {
            $("#ngtr"+currid.toString()).addClass("hidclass");
       }
       
    }
    else
    {
       $.ShowWindow("error","信息中心","设置"+params.noteText+"失败,请重试",100,180,false,false,null,"color:#00088c;"); 
    }
}

function OPReplay()
{
    var e = $.getEvent();
    currid=$(e.target).parent().attr("currid");
    tb_show("回复","Replay."+extendfilename+"?bid="+currid.toString()+"&keepThis=true&TB_iframe=true&height=150&width=300",false);
}

function UpdateReplayContent(content)
{
    if($("#re"+currid.toString()).html()==null)
    {
        $("<div class='reContent' id='re"+currid.toString()+"'></div>").appendTo("#content"+currid.toString());
    }
    $("#re"+currid.toString()).html(content);
    tb_remove();
}

function OPTop()
{
    var e = $.getEvent();
    currid=$(e.target).parent().attr("currid");
    params.eventTarget = e.target;

    if($(e.target).parent().attr("topV").toLowerCase()=="1")
    {
        params.textV = "置顶";
        params.noteText = "普通";
        params.keyValue = 0;
    }
    else
    {
        params.textV = "普通";
        params.noteText = "置顶";
        params.keyValue=1;
    }
    
    $.ShowWindow("loading","信息中心","正在设置为:"+params.noteText,100,180,true,false,null,"color:#00088c;");
    NgBook.Web.Index.TopBook(currid,params.keyValue,TopCallBack);
    
}

function TopCallBack(val)
{
    if(val.value.indexOf("true,")>=0)
    {
        $.ShowWindow("./success","信息中心","设置"+params.noteText+"成功,2秒后返回第一页",100,220,false,false,null,"color:#00088c;");
        setTimeout("window.location.href = './index."+extendfilename+"';",2000);
    }
    else
    {
       $.ShowWindow("error","信息中心","设置"+params.noteText+"失败,请重试",100,180,false,false,null,"color:#00088c;"); 
    }
}
function OpenPostBook()
{
    tb_show("发表留言","./PostBook."+extendfilename+"?keepThis=true&TB_iframe=true&height=450&width=450",false);
}
function GotoIndex()
{
    window.location.href = "./index."+extendfilename;
}
function ChangePagePosition()
{
    var pager = $("#Pagination");
   
    if(pagerTop ==0)
    {
        pagerTop = pager.offset().top;
    }
    $("#Pagination").css("top",(pagerTop+$(window).scrollTop()).toString()+"px");
}
function ManagerLogin()
{
    try
    {
        var e = $.getEvent();
        
        if($(e.target).text()=="退出")
        {
            window.location.href="./logout."+extendfilename;
			GotoIndex();
            return;
        }
    }
    catch(ex)
    {
        
    }
    tb_show("管理登陆","./AdminLogin."+extendfilename+"?keepThis=true&TB_iframe=true&height=200&width=300",false);
}
function EditInfomation()
{
    tb_show("修改管理员信息","./ChangeInfo."+extendfilename+"?keepThis=true&TB_iframe=true&height=280&width=350",false);
}
