﻿var uname = "";
var login_status = "";
var logout_status = "";
var error_no = "000";
var is_login = -1;

var VipBookPP = {
	//Member Variebles Declaration
	loginUrl: "/userinfo/login.php",
	registerUrl:"http://login.sina.com.cn/cgi/register/reg_sso.php?entry=vipbook",
	recoverUrl: "http://login.sina.com.cn/getpass.html",
	
	loginLoop: false,
	loginCounter: 0,
	maxTrial: 20,
	
	pannelItem: false,
	
	Ajax:null,
	ResultCode:null,
	
	UId: "",
	UserName: "",
	Passwd: "",
	
	//Member Function Declaration
	trim: function(str)
	{
		return str.replace(/(^\s*)|(\s*$)/g, "");
	},
	
	create_js: function(id, src)
	{
		var js = document.getElementById(id);       
		if (js != null && js.tagName.toLowerCase() == "script")
		{
			document.getElementsByTagName("head").item(0).removeChild(js);
		}
		js = document.createElement('script');
		js.type = "text/javascript";
		js.id = id;
		js.src = src;
		document.getElementsByTagName("head").item(0).appendChild(js);
	},
	
	showMsg: function(msgCode)
	{
		var msg='';
		switch(msgCode)
		{
			case '1':
				msg+='请输入用户名';
				break;
			case '2':
				msg+='请输入密码';
				break;
			case '3':
				msg+='用户名或密码错误';
				break;
			case '4':
				msg+='很抱歉，你的帐号已被禁用';
				break;
			case '5':
				msg+='登录超时，请稍后重试';
				break;
			case '6':
				msg+='请输入验证码';
				break;
			case '7':
				msg+='验证码错误，请重新输入';
				break;
			case '10':
				msg+='浏览器禁用Cookie，无法登录，请更改浏览器设置后再登录';
				break;
			default:msg+='登录错误，请稍后重试'
		}
		alert(msg);
	},
	
	changeCode:function(start)
	{
		if(start)
		{
			if(this.loginLoop == false)
			{
				this.loginLoop = setInterval(function(){GetObj('authimg').src="/iframe/authimg.php?t=" + new Date().getTime();}, 180000);//每两分钟变一次验证码
			}
			return;
		}
		clearInterval(this.loginLoop);
		this.loginLoop = false;
	},
		
	buildLoginForm: function(element)
	{
		login_status = "";
		element = document.getElementById(element);
		if(typeof(element) != 'object')
		{
			return;
		}
		this.pannelItem = element;
		//<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1" height="1" id="mp3_player" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/images/mp3.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<param name="FlashVars" value="mp3URL=/iframe/audio.php" /><embed src="/images/mp3.swf" FlashVars="mp3URL=/iframe/audio.php" quality="high" bgcolor="#ffffff" width="1" height="1" name="mp3_player" id="mp3_player" swLiveConnect="true" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>

		var login_html = ' 用户名：<input name="loginname" id="loginname" type="text" size="9" value="" tabindex="1" class="blkccc" /> 密码：<input name="passwd" id="passwd" type="password" size="9" tabindex="2" class="blkccc" /> <img width="15" id="play_img" name="play_img" src="http://image2.sina.com.cn/blog/tmpl/v3/images/blank.gif"><input type="submit" class="btn" name="login_button" id="login_button" onClick="VipBookPP.doLogin();return false;" value="登录"  tabindex="3"  />&nbsp;&nbsp;<a href="' + this.recoverUrl + '" target="_blank">找回密码</a> | <a href="' + this.registerUrl + '" target="_blank">注册帐号</a>';
		
		this.pannelItem.innerHTML = login_html;
		
		//this.changeCode(true);
	},
	
	showWaitMsg: function(msg)
	{
		this.pannelItem.innerHTML = '<div style="text-align:center;">' + msg + '</div>';
	},
	
	doLogin: function(mod)
	{
		//if(login_status == "processing")return;
		switch (mod)
		{
			case 'auto_collect':
				var uidInput = document.getElementById('loginname_ac');
				var pwdInput = document.getElementById('passwd_ac');
				break;
			default:
				var uidInput = document.getElementById('loginname');
				var pwdInput = document.getElementById('passwd');
				break;
		}
		
		//var vCode = document.getElementById('checkwd');
		
		if(this.trim(uidInput.value) == "")
		{
			this.showMsg('1');
			uidInput.value = "";
			uidInput.focus();
			return false;
		}
		
		if(pwdInput.value == "")
		{
			this.showMsg('2');
			pwdInput.focus();
			return false;
		}
		
		/*
		if(this.trim(vCode.value) == "")
		{
			this.showMsg('6');
			vCode.focus();
			return false;
		}*/
		
		var d = new Date;
		
		this.Ajax = new class_ajax();
		this.Ajax.init();
		this.Ajax.set_method('POST');
		this.Ajax.set_event(VipBookPP.AjaxLoginProc);
		this.Ajax.set_url(this.loginUrl + "?action=loginjs");
		this.Ajax.add_param("loginname", uidInput.value);
		this.Ajax.add_param("passwd", pwdInput.value);
		//this.Ajax.add_param("checkwd", vCode.value);
		this.Ajax.add_param("t", d.getTime());
		switch(mod)
		{
			case 'auto_collect':
				this.Ajax.add_param("mod", mod);
				break;
		}
		this.Ajax.submit();
		
		//var url = this.loginUrl + "?action=loginjs&loginname=" + uidInput.value + "&passwd=" + pwdInput.value + "&checkwd=" + vCode.value + "&t=" + d.getTime();
		//this.create_js("vipbook_login", url);
		//this.showWaitMsg("正在登录，请稍候...");
		//this.loginLoop = setInterval(function(){VipBookPP.loginProc(VipBookPP.loginSuccessCall, VipBookPP.loginFaildCall)}, 100);
		
		//清除定时刷新验证码
		//this.changeCode(false);
		
		//login_status = "processing";
		
		return false;
	},
	
	loginProc: function(lsc, lfc)
	{
		if(login_status == "" && this.loginCounter < this.maxTrial)
		{
			this.loginCounter++;
			return;
		}
		clearInterval(this.loginLoop);
		this.loginLoop = false;
		this.loginCounter = 0;
		
		if(login_status != "success" || this.loginCounter >= this.maxTrial)
		{
			lfc();
			return;
		}
		lsc();
	},
	
	AjaxLoginProc: function()
	{
		if(VipBookPP.Ajax.complete() && VipBookPP.Ajax.success())
		{
			VipBookPP.ResultCode = VipBookPP.Ajax.get_content();
			eval(VipBookPP.ResultCode);
			if(login_status != "success")
			{
				VipBookPP.loginFaildCall();
				return;
			}
			switch (mod)
			{
				case 'auto_collect':
					VipBookBook.addToFavorites(book_id, chapter_id);
					closeDetail(book_id);
					break;
				default:
					VipBookPP.loginSuccessCall();
					break;					
			}
		}
	},
	
	loginSuccessCall: function()
	{
		eval(VipBookPP.ResultCode);
		var url = '/userinfo/myhome.php';
		var title = '进入我的个人中心';
		var u_title = '个人中心';
		if(AUTHOR != 0)
		{
			url = "/book/mybooks.php";
			title = "管理我的作品";
			u_title = '作品管理';
		}
		var login_html = ' <strong style="color:#f60;font-size:14px;">'+ UNAME +'</strong> \n';
        login_html += '你好！ <a href="' + url + '" class="ico_link" title="' + title + '">' + u_title + '</a> &nbsp;<a href="/sms/list.php" class="ico_link" style="background:url(http://www.sinaimg.cn/book/vipbook/book_mj_001.gif) no-repeat 0 40%;">消息</a> \n';
        login_html += '<a href="/bookcase/index.php" class="ico_link" style="background:url(http://www.sinaimg.cn/book/vipbook/book_mj_002.gif) no-repeat 2px 40%;">我的书架</a> \n';
        login_html += '| 等级：' + CAREER;
        login_html += '<span id="fav_span" style="display:none"> | 收藏：<strong>' + FAV + '</strong> 本</span>';
        login_html += '<span id="sina_email"> | 邮件读取中</span>';
        login_html += ' <input type="image" src="http://www.sinaimg.cn/book/vipbook/book_mj_003.gif" width="74" height="20" alt="退出登录" align="absmiddle" onclick="VipBookPP.doLogout(\'VipBookPP_Login\')" /> \n';
		
		VipBookPP.pannelItem.innerHTML = login_html;
		//复位状态
		VipBookPP.loginCounter = 0;
		login_status = "";
		//读取新浪邮箱
		VipBookPP.loadEmail();
		//document.getElementsByTagName("head").item(0).removeChild(document.getElementById("vipbook_login"));
		return;
	},
	
	loginFaildCall: function()
	{
		VipBookPP.showMsg(error_no);
		//chg_img();
		//VipBookPP.buildLoginForm(VipBookPP.pannelItem.id);
		return false;
	},
	
	doLogout: function(element)
	{
		//if(logout_status == "processing")return;
		document.cookie="SINAPRO=; " + "domain=sina.com.cn; path=/; ";
		var d = new Date;
		this.pannelItem = element;
		
		this.Ajax = new class_ajax();
		this.Ajax.init();
		this.Ajax.set_method('POST');
		this.Ajax.set_event(VipBookPP.logoutCallBack);
		this.Ajax.set_url(this.loginUrl + "?action=logoutjs");
		this.Ajax.add_param("t", d.getTime());
		this.Ajax.submit();
		//logout_status = "processing";
		//var url = this.loginUrl + "?action=logoutjs&t=" + d.getTime();
		//this.create_js("vipbook_logout", url);
		//this.buildLoginForm(element);
		//return false;
	},
	
	logoutCallBack:function()
	{
		if(VipBookPP.Ajax.complete() && VipBookPP.Ajax.success())
		{
			VipBookPP.ResultCode = VipBookPP.Ajax.get_content();
			eval(VipBookPP.ResultCode);
			if(logout_status == "success")
			{
				deleteCookie("SINAPRO");
				VipBookPP.buildLoginForm(VipBookPP.pannelItem);
			}
			logout_status = "";
		}
	},
	
	loadEmail:function()
	{
		sinamailinfo = null;
		this.loginCounter = 0;
		this.maxTrial = 30;
		var url = "http://hint.sinamail.sina.com.cn/mailproxy/mail.php?t=" + new Date().getTime();
		this.create_js("mail_js", url);
		this.loginLoop = setInterval(function(){VipBookPP.loadEmailProc()}, 200);
	},
	
	loadEmailProc:function()
	{
		if(typeof(sinamailinfo) == 'undefined' || sinamailinfo == null)
		{
			if(this.loginCounter < this.maxTrial)
			{
				this.loginCounter++;
			}
			else
			{
				clearInterval(this.loginLoop);
				document.getElementById("sina_email").style.display = "none";
				var fav_span = document.getElementById("fav_span");
				if(fav_span != null)
				{
					fav_span.style.display = "";
				}
			}
			return;
		}
		
		clearInterval(this.loginLoop);
		this.loginLoop = false;
		
		var email = "";
		var url = sinamailinfo["url"];
        if(sinamailinfo.result)
        {
        	//url += "?_from=vipbook" + new Date().getTime();
        	email = "我的邮箱";
        	if(sinamailinfo["unreadmail"] > 0)
        	{
        		email = '<span style="color:red;font-weight:bold;">' + sinamailinfo["unreadmail"] + "</span>封未读邮件";
        	}
        }
        else
        {
        	email = '<font color="red">激活邮箱</font>';
        }
        email = '<a href="http://mail.sina.com.cn" target="_blank">' + email + '</a>';
        document.getElementById("sina_email").innerHTML = " | " + email;
	}
};

/**
 * 写入Cookie
 *
 * @param name string
 * @param value mixed
 * @param seconds int
 * 
 * @return	none
 */
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, seconds)
{

  var expire = "";
  if(seconds != null)
  {
    expire = new Date((new Date()).getTime() + seconds * 1000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

/**
 * 读出Cookie
 *
 * @param name string
 *
 * @return	mixed
 */
// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

/**
 * 删除名称为name的Cookie 
 *
 * @param name string
 *
 * @return	mixed
 */
function deleteCookie(name)
{
    var exp = new Date();
    exp.setTime (exp.getTime() - 1000*60);
    var cval = readCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


function $id(objId)
{
	return document.getElementById(objId);
}

var DOMObj = {
	Obj:function(objId)
	{
		return document.getElementById(objId);
	},
	
	Objs:function(objName)
	{
		return document.getElementsByName(objName);
	},
	
	TagObjs:function(tagName)
	{
		return document.getElementsByTagName(tagName);
	},
	
	countChildsByTagName:function(Obj, tagName)
	{
		var j = 0;
		for(i = 0; i < Obj.childNodes.length; i++)
		{
			if(typeof(Obj.childNodes[i].tagName) != 'undefined' && Obj.childNodes[i].tagName == tagName)
			{
				j++;
			}
		}
		return j;
	}
};

var DForm = {
	Id:null,
	Action:null,
	Method:null,
	Target:"_self",
	Param:null,
	Element:null,
	Func:null,
	
	init:function()
	{
		this.Id = '';
		this.Action = '';
		this.Method = '';
		this.Param = new Array();
		this.Element = null;
	},
	
	setForm:function(element, id, method, action)
	{
		this.Element = document.getElementById(element);
		this.Id = id;
		this.Action = action;
		this.Method = method;
	},
	
	addParam:function(name, value)
	{
		this.Param.push(Array(name, value));
	},
	
	create:function()
	{
		var formhtml = '<form name="' + this.Id + '" id="' + this.Id + '" method="' + this.Method + '" action="' + this.Action + '" target="' + this.Target + '">';
		/*for(i = 0; i < this.Param.length; i++)
		{
			formhtml += '<input type="hidden" name="' + this.Param[i][0] + '" id="' + this.Param[i][0] + '" value="' + this.Param[i][1]  + '" />';
		}*/
		this.Element.innerHTML = formhtml + '</form>';
		var frm = document.getElementById(this.Id);
		for(i = 0; i < this.Param.length; i++)
		{
			var p = document.createElement("INPUT");
			p.name =  p.id = this.Param[i][0];
			p.type = "hidden";
			p.value = this.Param[i][1];
			frm.appendChild(p);
		}
		formhtml += frm.innerHTML;
		formhtml += '</form>';
		return formhtml;
	},
	
	setFunc:function(fnc)
	{
		
	},
	
	submit:function()
	{
		document.getElementById(this.Id).submit();
	}
};

var VipBookBook = {
	
	Ajax:null,
	AjaxQueue:new Array(),
	ParamQueue:new Array(),
	
	goFunction:function(fnc)
	{
		if(DOMObj.Objs("book").length < 1)
		{
			alert("您尚未发表任何作品");
			return;
		}
		var BookId = get_sel_value("book");
		if(BookId == null)
		{
			alert("请选择需要操作的作品");
			return;
		}
		eval("VipBookBook." + fnc + "(" + BookId + ")");
	},
	
	goModify:function(BookId)
	{
		location.href = "book_manage.php?action=modify&book=" + BookId;
	},
	
	goBookIndex:function(BookId)
	{
		window.open("/book/index_" + BookId + ".html", BookId);
	},
	
	goContentManage:function(BookId)
	{
		location.href = "content_manage.php?book=" + BookId;
	},
	
	goBookNews:function(BookId)
	{
		location.href = "/book/news_man.php?book=" + BookId;
	},
	
	goBookBar: function(BookId)
	{
		if(bar_name != null && bar_name[BookId] != null)
		{
			DForm.init();
			DForm.Target = "_blank";
			DForm.setForm("post_form", "bar_form", "GET", "http://bar.sina.com.cn/bar.php");
			DForm.addParam("name", bar_name[BookId][0]);
			DForm.create();
			DForm.submit();
		}
		else
		{
			alert("很抱歉，未通过审核作品没有书吧！");
		}
	},
	
	goBookBarMaster: function(BookId)
	{
		if(bar_name != null && bar_name[BookId] != null)
		{
			if(bar_name[BookId][1] != "0")
			{
				alert("您已经是本书吧的吧主！");
			}
			else
			{
				if(!confirm("确定申请本书吧的吧主吗？"))
				{
					return;
				}
				
				//提交申请
				this.Ajax = new class_ajax();
				this.Ajax.init();
				this.Ajax.set_method('POST');
				this.Ajax.set_event(VipBookBook.applyBarMasterCallBack);   //参数不能加引号
				this.Ajax.set_url("/iframe/sinabar/sinabar.php?action=applymaster");
				this.Ajax.add_param("book", BookId);
				this.Ajax.add_param("t", new Date().getTime());
				this.Ajax.submit();
			}
		}
		else
		{
			alert("很抱歉，未通过审核作品没有书吧！");
		}
	},
	
	goPublishApply: function(BookId)
	{
		location.href = "book_manage.php?action=pubapply&book=" + BookId;
	},
	
	applyBarMasterCallBack: function()
	{
		if(VipBookBook.Ajax.complete() && VipBookBook.Ajax.success())
		{
			var Result = VipBookBook.Ajax.get_content();
			//alert(Result);
			Result = Result.split("|");
			switch(Result[0])
			{
				case "-1":
				{
					alert("很抱歉，该书吧不存在，申请失败！");
					break;
				}
				case "0-1":
				{
					alert("很抱歉，该书吧已有吧主，申请失败！");
					break;
				}
				case "0-2":
				{
					alert("很抱歉，您不是本作品的作者，无法申请！");
					break;
				}
				case "0-999":
				{
					alert("申请失败！请确认您提交的信息是否正确！");
					break;
				}
				case "0-3":
				{
					alert("申请失败！" + Result[1] + "。您可以从“个人中心”修改这些信息！");
					break;
				}
				case "1":
				{
					var book_id = Result[1];
					bar_name[book_id][1] = Result[2];
					alert("申请成功！");
					break;
				}
				case "1-0":
				{
					alert("服务器处理失败！请稍后再试。");
					break;
				}
			}
		}
	},
	
	validPenname:function(penname)
	{
		penname = DOMObj.Obj(penname);
		if(penname != null && typeof(penname) != 'undefined')
		{
			if(penname.value.trim() == "")
			{
				alert("请填写使用笔名");
				penname.focus();
				return false;
			}
			var len = penname.value.trim().ByteCount();
			if(len > 20 || len < 2)
			{
				alert("笔名字数限制1~10个汉字");
				penname.focus();
				return false;
			}
		}
		return true;
	},
	
	validTag:function(obj)
	{
		var tags = obj.value;
		if(tags.trim() == "")
		{
			//alert("请设置作品标签");
			//return false;
			return true;
		}
		tags = tags.replace(/\s+/g, ",");
		tags = tags.replace(/，+/g, ",");
		tags = tags.replace(/,+/g, ",");
		var tag = tags.split(",");
		/*var sp_list = [" ", ",", ";"];
		for(sp in sp_list)
		{
			var tag = tags.split(sp_list[sp]);
			if(tag.length > 1)
			{
				break;
			}
		}*/
		if(tag.length > 1 && tag[tag.length - 1].trim() == "")
		{
			tag.pop();
		}
		if(tag.length > 10)
		{
			alert("关键字个数不能超过10个");
			//DOMObj.Obj("tag").focus();
			return false;
		}
		for(i = 0; i < tag.length; i++)
		{
			tag[i] = tag[i].trim();
			if(tag[i] == "")
			{
				alert("关键字不能为空");
				//DOMObj.Obj("tag").focus();
				return false;
			}
			if(!is_hz_char(tag[i]))
			{
				alert("请使用汉字或字母设置关键字");
				//DOMObj.Obj("tag").focus();
				return false;
			}
			if(tag[i].ByteCount() > 10)
			{
				alert("每个关键字最多允许5个汉字");
				//DOMObj.Obj("tag").focus();
				return false;
			}
		}
		obj.value = tag.join(",");
		return true;
	},
	
	setModifyMode:function()
	{
		DOMObj.Obj("title").readOnly = true;
		var chk = DOMObj.Objs("license");
		for(i = 0; i < chk.length; i++)
		{
			if(chk[i].checked)continue;
			chk[i].disabled = true;
		}
	},
	
	confirmDelete:function(title)
	{
		return confirm('确定删除名称为"' + title + '"的作品吗？');
	},
	
	addToFavorites:function(bookId, chapterId, auto)
	{
		this.Ajax = new class_ajax();
		this.Ajax.init();
		this.Ajax.set_method('GET');
		this.Ajax.set_event(VipBookBook.favoritesCallBack);   //参数不能加引号
		this.Ajax.set_url("/iframe/server/favorite.php");
        this.Ajax.add_param("action","fav_add");
		this.Ajax.add_param("book_id", bookId);
		this.Ajax.add_param("chapter_id", chapterId);
        
		this.Ajax.submit();
	},
	
	favoritesCallBack:function()
	{
		if(VipBookBook.Ajax.complete())
		{
			if(VipBookBook.Ajax.success())
			{
                response  = VipBookBook.Ajax.get_content('txt');
                var data = eval('('+response+')');
				if (data.result == "success")
				{
					alert(data.msg);
				}
				else
				{
					alert(data.msg);
				}
			}
		}
	},
		
	printMark:function(Ques)
	{
		if(Ques == 999)
		{
			document.write(Math.floor(InfoScore / 5 * 100));
			return;
		}
		var str = "<tr>\n";
		var loop = 1;
		for(j in Question)
		{
			str += '<td width="82" height="20"> ';
			if(typeof(Question[j]) != 'undefined')
			{
				str += Question[j];
				Ques = Math.floor(QuestionScore[j]);
				for(i = 0; i < Ques; i++)
				{
					str += '<img src="http://www.sinaimg.cn/book/vipbook/book_mj_040.gif" width="10" height="9" />';
				}
			}
			str += '</td>\n';
			if(loop % 2 == 0)
			{
				str += "</tr>\n<tr>\n";
			}
			loop++;
		}
		str += "</tr>\n";
		document.write(str);
	},
		
	printMarkPro:function(Ques)
	{
		if(Ques == 999)
		{
			document.write(Math.floor(InfoScore / 5 * 100));
			return;
		}
		var str = "";
		for(j in Question)
		{
			if(typeof(Question[j]) != 'undefined')
			{
				str += Question[j] + " ";
				Ques = Math.floor(QuestionScore[j]);
				for(i = 0; i < Ques; i++)
				{
					str += '<img src="http://www.sinaimg.cn/book/vipbook/book_mj_040.gif" width="10" height="9" />';
				}
			}
			str += '　　　';
		}
		document.write(str);
	},
	
	setPClass:function()
	{
		var div = DOMObj.Objs("volume_div");
		for(i = 0; i < div.length; i++)
		{
			for(j = 0; j < div[i].childNodes.length; j++)
			{
				var tmp = div[i].childNodes[j];
				if(typeof(tmp.tagName) != 'undefined' && tmp.tagName.toUpperCase() == "P")
				{
					tmp.className = "memo";
				}
			}
		}
	},
	
	loadChapterList: function(BookId, mod)
	{
		this.Ajax = new class_ajax();
		this.Ajax.init();
		this.Ajax.set_method('GET');
		this.Ajax.set_event(VipBookBook.loadChapterListCallBack);   //参数不能加引号
		this.Ajax.set_url("/iframe/book_srv.php");
		if(typeof(mod) == 'undefined')
		{
			mod = "idxls";
		}
		this.Ajax.add_param("mod", mod);
		this.Ajax.add_param("book", BookId);
		this.Ajax.add_param("_t", new Date().getTime());
		this.Ajax.submit();
	},
	
	loadChapterListCallBack: function()
	{
		if(VipBookBook.Ajax.complete())
		{
			if(VipBookBook.Ajax.success())
			{
				var html = VipBookBook.Ajax.get_content();
				var e = DOMObj.Obj("C_List");
				if(html != "")
				{
					e.style.display = "none";
					e.innerHTML = html;
					VipBookBook.setPClass();
					e.style.display = "";
				}
				else
				{
					e.innerHTML = '<div class="SP_H10"></div><div class="blk_07" style="text-align:center">本作品尚未添加任何章节！</div>';
				}
			}
		}
	},
	
	applyVip:function(bookId)
	{
		this.Ajax = new class_ajax();
		this.Ajax.init();
		this.Ajax.set_method('GET');
		this.Ajax.set_event(VipBookBook.applyVipCallBack);   //参数不能加引号
		this.Ajax.set_url("book_edit.php");
		this.Ajax.add_param("action", "appvip");
		this.Ajax.add_param("book", bookId);
		this.Ajax.submit();
	},
	
	applyVipCallBack:function()
	{
		if(VipBookBook.Ajax.complete() && VipBookBook.Ajax.success())
		{
			var v = VipBookBook.Ajax.get_content();
			v = v.split("|");
			if(v[0] == 1)
			{
				DOMObj.Obj("app_vip_" + v[1]).style.display = "none";
				DOMObj.Obj("applied_" + v[1]).style.display = "";
				alert("申请提交成功");
				return;
			}
			alert("申请失败，请稍后再试");
		}
	},
	
	reApply:function(bookId)
	{
		this.Ajax = new class_ajax();
		this.Ajax.init();
		this.Ajax.set_method('GET');
		this.Ajax.set_event(VipBookBook.reApplyCallBack);   //参数不能加引号
		this.Ajax.set_url("/iframe/book_mng_srv.php?action=reapp&book=" + bookId);
		//this.Ajax.add_param("action", "reapp");
		//this.Ajax.add_param("book", bookId);
		this.Ajax.submit();
	},
	
	reApplyCallBack:function()
	{
		if(VipBookBook.Ajax.complete() && VipBookBook.Ajax.success())
		{
			var v = VipBookBook.Ajax.get_content();
			v = v.split("|");
			if(v[0] == 1)
			{
				DOMObj.Obj("reapp_pan_" + v[1]).style.display = "none";
				DOMObj.Obj("status_" + v[1]).innerHTML = "未经审核";
				alert("申请提交成功");
				return;
			}
			alert("申请失败，请稍后再试");
		}
	},
	
	showIntro:function(obj)
	{
		var show = DOMObj.Obj("intro_hide").style.display == "none" ? true : false;
		var text = show ? "<<<作品简介" : ">>>作品简介";
		var display = show ? "" : "none";
		DOMObj.Obj("intro_hide").style.display = display;
		obj.innerHTML = text;
	},
	
	//-------------------------------------- 原创大赛 ---------------------------------------
	ApplyYcds:function(BookId, postfix, ycdsName)
	{
		if(!confirm("确定提交本作品参加“" + ycdsName + "”吗？"))
		{
			return;
		}
		var Ajax = new class_ajax();
		Ajax.init();
		Ajax.set_method('POST');
		Ajax.set_event(VipBookBook.ApplyYcdsCallBack);   //参数不能加引号
		Ajax.set_url("/iframe/book_mng_srv.php?action=ycds&book=" + BookId + "&postfix=" + postfix);
		Ajax.submit();
		this.AjaxQueue.push(Ajax);
		Ajax = null;
	},
	
	ApplyYcdsCallBack:function()
	{
		for(i in VipBookBook.AjaxQueue)
		{
			if(VipBookBook.AjaxQueue[i].complete() && VipBookBook.AjaxQueue[i].success())
			{
				//alert(VipBookBook.AjaxQueue[i].get_content());
				var v = Math.floor(VipBookBook.AjaxQueue[i].get_content());
				if(v > 0)
				{
					alert("申请提交成功！");
					//DOMObj.Obj("ycds_" + v).innerHTML = "申请大赛作品";
				}
				else
				{
					alert("申请失败，请稍候再试！");					
				}
				setTimeout('location.reload();', 500)
			}
		}
		return;		
	},
	//-------------------------------------- End ---------------------------------------
	
	
	//贴吧发帖
	
	setReply: function(checked, commentid, title)
	{
		var frm = document.forms["post_form"];
		DOMObj.Obj("replay_chk").style.display = checked ? "" : "none";
		DOMObj.Obj("title_tip").style.display = checked ? "none" : "";
		frm.reply.checked = checked;
		frm.bar_title.value = title;
		frm.bar_title.disabled = checked;
		frm.commentid.value = commentid;
		if(checked)
		{
			DOMObj.Obj("cmsg_content").focus();
		}
		return false;
	},
	
	sendBar: function(frm)
	{
		if(frm.cmsg_content.value.trim() == "")
		{
			alert("请输入内容！");
			frm.cmsg_content.focus();
			return false;
		}
		
		if(frm.vcode.value.trim() == "")
		{
			alert("请输入验证码！");
			frm.vcode.focus();
			return false;
		}
		
		if(!frm.reply.checked)
		{
			if(frm.bar_title.value.trim() == "")
			{
				/*alert("请输入标题！");
				frm.bar_title.focus();
				return false;*/
				
				frm.bar_title.value = frm.cmsg_content.value.cn_substr(0, 22, '');
			}
			
			if(frm.bar_title.value.ByteCountPro() > 24)
			{
				alert("标题字数太长！");
				frm.bar_title.focus();
				return false;
			}
		}
		
		this.Ajax = new class_ajax();
		this.Ajax.init();
		this.Ajax.set_method('POST');
		this.Ajax.set_event(VipBookBook.sendBarCallBack);   //参数不能加引号
		this.Ajax.set_url("/iframe/sinabar/sinabar.php?action=comment");
		this.Ajax.add_param("book", frm.book.value);
		this.Ajax.add_param("title", frm.bar_title.value);
		this.Ajax.add_param("content", frm.cmsg_content.value);
		this.Ajax.add_param("commentid", frm.commentid.value);
		this.Ajax.add_param("vcode", frm.vcode.value);
		this.Ajax.add_param("ccode", frm.ccode.value);
		if(!frm.anonymous.checked)
		{
			this.Ajax.add_param("uname", frm.user.value);
			this.Ajax.add_param("uid", frm.uid.value);
		}
		this.Ajax.submit();
		
		return true;
	},
	
	sendBarCallBack: function()
	{
		if(VipBookBook.Ajax.complete() && VipBookBook.Ajax.success())
		{
			var Result = VipBookBook.Ajax.get_content();
			//alert(Result);
		}
	},
	
	loadBarComment: function(BookId)
	{
		var Ajax = new class_ajax();
		Ajax.init();
		Ajax.set_method('GET');
		Ajax.set_event(VipBookBook.loadBarCommentCallBack);   //参数不能加引号
		Ajax.set_url("/iframe/sinabar/sinabar.php");
		Ajax.add_param("action", "list");
		Ajax.add_param("book", BookId);
		Ajax.add_param("t", new Date().getTime());
		Ajax.submit();
		this.AjaxQueue.push(Ajax);
		Ajax = null;
	},
	
	loadBarCommentCallBack: function()
	{
		for(i in VipBookBook.AjaxQueue)
		{
			if(VipBookBook.AjaxQueue[i].complete() && VipBookBook.AjaxQueue[i].success())
			{
				var Result = VipBookBook.AjaxQueue[i].get_content();
				eval(Result);
				load_sinabar_callback();
			}
		}
	}
};

var VipBookVolume = {
	move:function(obj, save, VolumeId, BookId)
	{
		var idx = (save !=0 ? 2 : 0);
		obj = obj.parentNode;
		obj = obj.parentNode;
		if(save == 2)
		{
		}
		else if(save == 0)
		{
			var sel = obj.childNodes[2].childNodes[2];
			var vid = obj.childNodes[2].childNodes[1].value;
			sel.innerHTML = "";
			with(sel)
			{
				var i = 0;
				for(j in Volume)
				{
					if(Volume[j][2] != vid)
					{
						options[i++] = new Option(Volume[j][0], Volume[j][2] + "_" + Volume[j][3]);
					}
				}
			}
			//var pos = obj.childNodes[2].childNodes[2];
			fill_vpos_list(sel);
		}
		obj.childNodes[idx].style.display = "none";
		obj.childNodes[2-idx].style.display = "";
	},
	
	modifyVolume:function(obj, save, VolumeId, BookId)
	{
		var idx = (save >=1 ? 1 : 0);
		obj = obj.parentNode;
		var title = obj.firstChild.innerHTML;
		obj = obj.parentNode;
		if(save == 2)
		{
			var title = obj.childNodes[idx].firstChild;
			if(title.value.trim() == "")
			{
				alert("请输入卷名！");
				title.focus();
				return;
			}
			if(title.value.length > 32)
			{
				alert("卷名请控制在32字以内！");
				title.focus();
				return;
			}
			var old_title = obj.childNodes[idx].childNodes[1];
			if(title.value.trim() != old_title.value.trim())
			{
				DForm.init();
				DForm.setForm("post_form", "volume_form", "POST", "?action=modv&do=1&book=" + BookId + "&volume=" + VolumeId);
				DForm.addParam("title", title.value);
				DForm.create();
				DForm.submit();
				return;
			}
		}
		else if(save == 0)
		{
			obj.childNodes[1-idx].firstChild.value = title;
		}
		obj.childNodes[idx].style.display = "none";
		obj.childNodes[1-idx].style.display = "";
	},
	
	deleteVolume:function(obj, VolumeId, BookId)
	{
		var v = DOMObj.Obj("v_filed_" + VolumeId);
		if(v != null && DOMObj.countChildsByTagName(v, "TBODY") > 0)
		{
			alert("请先删除卷中的章节后再删除该卷");
			return;
		}
		obj = obj.parentNode.firstChild;
		if(confirm("确定删除卷“" + obj.innerHTML + "”吗？"))
		{
			v = "?action=delv&book=" + BookId + "&volume=" + VolumeId;
			location.href = v;
		}
	},
	
	setStatus:function(volumeId, modify)
	{
		var normals = document.getElementsByName("v_normal_" + volumeId);
		var edits = document.getElementsByName("v_edit_" + volumeId);
		for(i = 0; i < normals.length; i++)
		{
			if(modify)
			{
				normals[i].style.display = "none";
				edits[i].style.display = "";
			}
			else
			{
				normals[i].style.display = "";
				edits[i].style.display = "none";
			}
		}
	},
	
	modify:function(volumeId)
	{
		this.setStatus(volumeId, true);
	},
	
	save:function(volumeId, bookId, addNew)
	{
		var title = document.getElementById("v_title_" + volumeId);
		var sequence = document.getElementById("v_sequence_" + volumeId);
		if(title.value.trim() == "")
		{
			alert("请输入卷名");
			title.focus();
			return;
		}
		/*if(!is_hz_char(title.value, true))
		{
			alert("卷名请使用汉字或字母");
			title.focus();
			return false;
		}*/
		if(!valid_repeat_chars(title.value, 12))
		{
			alert("请使用正确的汉字或单词");
			title.focus();
			return;
		}
		
		if(addNew)
		{
			formhtml = 'volume_edit.php?action=add&do=1&book=' + bookId;
		}
		else
		{
			if(sequence.value.trim() == "")
			{
				alert("请输入顺序");
				sequence.focus();
				return;
			}
			formhtml = 'volume_edit.php?action=edit&do=1&book=' + bookId +'&volume=' + volumeId;
		}
		
		DForm.init();
		DForm.setForm("post_form", "volume_form", "POST", formhtml);
		DForm.addParam("title", title.value);
		if(!addNew)DForm.addParam("sequence", sequence.value);
		DForm.create();
		DForm.submit();
	},
	
	cancel:function(volumeId)
	{
		this.reset(volumeId);
		this.setStatus(volumeId, false);
	},
	
	reset:function(volumeId)
	{
		var title = document.getElementById("v_title_" + volumeId);
		var p_title = title.parentNode;
		p_title = p_title.parentNode;
		title.value = p_title.firstChild.firstChild.innerHTML;
		
		var sequence = document.getElementById("v_sequence_" + volumeId);
		var p_sequence = sequence.parentNode;
		p_sequence = p_sequence.parentNode;
		sequence.value = p_sequence.firstChild.innerHTML;
	},
	
	confirmDelete:function(title)
	{
		return confirm('确定删除卷名为"' + title + '"的卷吗？');
	}
};

var VipBookChapter = {
	
	Element:null,
	Ajax:null,
	VolumeId:null,
	
	AjaxQueue:new Array(),
	ParamQueue:new Array(),
	
	goFunction:function(fnc, BookId)
	{
		if(DOMObj.Objs("chapter").length < 1)
		{
			alert("该作品尚未添加任何章节");
			return;
		}
		var ChapterId = get_sel_value("chapter");
		if(ChapterId == null)
		{
			alert("请选择需要操作的章节");
			return;
		}
		//eval("VipBookChapter." + fnc + "(" + ChapterId + ", " + BookId + ")");
		eval("VipBookChapter." + fnc + "(" + ChapterId + ", BookId)");
	},
	
	goDelete:function(ChapterId, BookId)
	{
		if(DOMObj.Obj("pub_" + ChapterId).value == "1" && DOMObj.Obj("vip_" + ChapterId).value == "1")
		{
			alert("该章节为VIP章节，且已发布，不能执行删除，如需删除，请联系客服。");
			return;
		}
		var p = DOMObj.Obj("chapter_" + ChapterId).parentNode.childNodes[2];
		if(confirm("确定删除章节‘" + p.innerHTML + "’吗？"))
		{
			location.href = "?action=delc&book=" + BookId + "&chapter=" + ChapterId;
		}
	},
	
	goFree:function(ChapterId, BookId)
	{
		if(DOMObj.Obj("vip_" + ChapterId).value != "1")
		{
			alert("该章节为非VIP章节，无需解禁。");
			return;
		}
		if(DOMObj.Obj("pub_" + ChapterId).value == "0")
		{
			alert("该章节尚未发布，请先发布章节。");
			return;
		}
		var p = DOMObj.Obj("chapter_" + ChapterId).parentNode.childNodes[2];
		if(confirm("确定解禁章节‘" + p.innerHTML + "’吗？"))
		{
			location.href = "?action=freec&book=" + BookId + "&chapter=" + ChapterId;
		}
	},
	
	goPub:function(ChapterId, BookId)
	{
		if(DOMObj.Obj("pub_" + ChapterId).value != "0")
		{
			alert("该章节已发布。");
			return;
		}
		var p = DOMObj.Obj("chapter_" + ChapterId).parentNode.childNodes[2];
		if(confirm("确定发布章节‘" + p.innerHTML + "’吗？"))
		{
			location.href = "?action=pubc&book=" + BookId + "&chapter=" + ChapterId;
		}
	},
	
	goMove:function(ChapterId, Param)
	{
		var VolumeId = Param[2];
		var idx = findVolumeIdx(VolumeId);
		var Chapter = Volume[idx][1];
		for(i in Chapter)
		{
			if(Chapter[i] == ChapterId)
			{
				this.move(Param[0], Param[1], ChapterId);
				return true;
			}
		}
		alert("请选择本卷中要移动的章节！");
		return false;
	},
	
	switchMinLimit:function(minLimit, maxLimit)
	{
		var span = DOMObj.Obj("min_count");
		var chk = DOMObj.Obj("vip");
		if(chk.checked)
		{
			span.innerHTML = maxLimit;
			return;
		}
		span.innerHTML = minLimit;
	},
	
	validSubmit:function(theform)
	{
		if(theform.title.value.trim() == "")
		{
			alert("请填写章节名称");
			theform.title.focus();
			return false;
		}
		/*if(!is_hz_char(theform.title.value, true))
		{
			alert("章节标题请使用汉字或字母");
			theform.title.focus();
			return false;
		}*/
		if(!valid_repeat_chars(theform.title.value, 12))
		{
			alert("请使用正确的汉字或单词");
			theform.title.focus();
			return false;
		}
		/*if(!check_length(theform.title, "章节标题", 2, 128))
		{
			alert("章节标题字数请控制在64个汉字内");
			theform.title.focus();
			return false;
		}*/
		if(theform.title.length > 64)
		{
			alert("章节标题字数请控制在64个汉字内");
			theform.title.focus();
			return false;
		}
		var display = theform.content.style.display;
		display = display == "none" ? oHTML : theform.content;
		if(theform.content.value.trim() == "")
		{
			alert("请填写章节内容");
			display.focus();
			//theform.content.focus();
			return false;
		}
		var tmp_content = theform.content.value;
		tmp_content = tmp_content.replace(/<IMG.+?>/ig, " ");
		if(!valid_repeat_chars(tmp_content, 20))
		{
			alert("请使用正确的汉字或单词");
			display.focus();
			//theform.content.focus();
			return false;
		}
		var chk = DOMObj.Obj("vip");
		var min = Math.floor(DOMObj.Obj("min_count").innerHTML);
		len = tmp_content.ByteCountPro();
		if(len > 20000)
		{
			alert("章节内容字数不能大于20000字");
			display.focus();
			//theform.content.focus();
			return false;
		}
		if(len < min)
		{
			alert("章节内容字数不能小于" + min +"字");
			display.focus();
			//theform.content.focus();
			return false;
		}
		
		var tmp_reltopic = theform.reltopic.value;
		lenreltopic = tmp_reltopic.ByteCountPro();
		if(lenreltopic > 300)
		{
			alert("题外话字数不能大于300字");
			theform.reltopic.focus();
			return false;
		}
		
		/*if(typeof(theform.vip) != 'undefined')
		{
			theform.vip.value = theform.vip.checked ? "2" : "1";
		}
		if(typeof(theform.pub) != 'undefined')
		{
			theform.pub.value = theform.pub.checked ? "2" : "1";
		}*/
		
		/*if(theform.sequence.value.trim() == "")
		{
			alert("请填写章节顺序");
			theform.sequence.focus();
			return false;
		}*/
		return true;
	},
		
	showElement:function()
	{
		Element = this.Element.parentNode;
		Element = Element.parentNode.parentNode;
		Element.style.display = Element.style.display == "none" ? "" : "none";
	},
	
	listChapter:function(bookId, volumeId)
	{
		this.Element = document.getElementById("c_list_" + volumeId);
		this.showElement();
		if(this.Element.innerHTML.trim() != "")
		{
			return;
		}
		this.VolumeId = volumeId;
		
		this.Ajax = new class_ajax();
		this.Ajax.init();
		this.Ajax.set_method('GET');
		this.Ajax.set_event(VipBookChapter.listCallBack);   //参数不能加引号
		this.Ajax.set_url("chapter_edit.php");
		this.Ajax.add_param("action", "list");
		this.Ajax.add_param("book", bookId);
		this.Ajax.add_param("volume", volumeId);
		this.Ajax.submit();
		
		this.Element.innerHTML = "正在获取章节，请稍候...";
	},
	
	listCallBack:function()
	{
		if(VipBookChapter.Ajax.complete() && VipBookChapter.Ajax.success())
		{
			var re = VipBookChapter.Ajax.get_content();
			if(re == "-999")
			{
				re = "与服务器连接失败，请重新登录";
			}
			VipBookChapter.Element.innerHTML = re;
			VipBookChapter.Ajax = null;
		}
	},
	
	confirmDelete:function(title)
	{
		return confirm('确定删除标题为"' + title + '"的章节吗？');
	},
	
	modifySequence:function(bookId, chapterId, object, mode)
	{
		var sequence = document.getElementById("c_seq_" + chapterId);
		if(mode == 1)//转换为修改状态
		{
			var p = object.parentNode;
			p.style.display = "none";
			p = p.parentNode;
			p.childNodes[1].style.display = "";
		}
		else if(mode == 2)//保存
		{
			DForm.init();
			DForm.setForm("post_form", "chapter_form", "POST", "chapter_edit.php?action=mseq&book=" + bookId + "&chapter=" + chapterId);
			DForm.addParam("sequence", sequence.value);
			DForm.create();
			DForm.submit();
		}
		else if(mode == 3)//取消
		{
			var p = object.parentNode;
			p.style.display = "none";
			p = p.parentNode;
			p.firstChild.style.display = "";
			p = p.parentNode;
			sequence.value = p.firstChild.innerHTML;
		}
	},
		
	jumpVolume:function(bookId, chapterId, object, mode)
	{
		if(mode == 1)//转换为修改状态
		{
			var p = object.parentNode;
			p.style.display = "none";
			p = p.parentNode;
			var div = DOMObj.Obj("_v_list").innerHTML;
			div = div.replace(/jumpVolume\(\'#book_id#\', \'#chapter_id#\'/g, ("jumpVolume(" + bookId + ", " + chapterId));
			var vlist = "volume_" + chapterId;
			div = div.replace(/#volume_list#/g, vlist);
			p.childNodes[2].innerHTML = div;
			p.childNodes[2].style.display = "";
			var vid = DOMObj.Obj("cur_vid_" + chapterId);
			set_select(vlist, vid.value);
		}
		else if(mode == 2)//保存
		{
			var vid = DOMObj.Obj("cur_vid_" + chapterId);
			var sel = DOMObj.Obj("volume_" + chapterId);
			if(vid.value == sel.value)
			{
				this.jumpVolume(bookId, chapterId, object, 3);
				return;
			}
			DForm.init();
			DForm.setForm("post_form", "chapter_form", "POST", "chapter_edit.php?action=mvol&book=" + bookId + "&chapter=" + chapterId);
			DForm.addParam("volume", sel.value);
			DForm.create();
			DForm.submit();
		}
		else if(mode == 3)//取消
		{
			var p = object.parentNode;
			p.style.display = "none";
			p = p.parentNode;
			p.firstChild.style.display = "";
		}
	},
	
	pub:function(bookId, chapterId, title)
	{
		if(confirm('确定发布章节"' + title + '"吗？'))
		{
			this.Ajax = new class_ajax();
			this.Ajax.init();
			this.Ajax.set_method('GET');
			this.Ajax.set_event(VipBookChapter.pubCallBack);   //参数不能加引号
			this.Ajax.set_url("chapter_edit.php");
			this.Ajax.add_param("action", "pub");
			this.Ajax.add_param("book", bookId);
			this.Ajax.add_param("chapter", chapterId);
			this.Ajax.submit();
		}
	},
	
	pubCallBack:function()
	{
		if(VipBookChapter.Ajax.complete() && VipBookChapter.Ajax.success())
		{
			var re = VipBookChapter.Ajax.get_content();
			if(re == "-999")
			{
				alert("与服务器连接失败，请重新登录");
				return;
			}
			re = re.split("|");
			if(re[0] != "0")
			{
				if(re[0] == "-1")
				{
					alert("发布失败！\nVIP章节字数必须 3000 字以上！");
					return;
				}
				alert("发布成功");
				DOMObj.Obj("pub_pannel_" + re[0]).style.display = "none";
				if(re[1] == 1)
				{
					DOMObj.Obj("mod_pannel_" + re[0]).style.display = "none";
					DOMObj.Obj("free_pannel_" + re[0]).style.display = "";
				}
				return;
			}
			alert("发布失败");
			VipBookChapter.Ajax = null;
		}
	},
	
	free:function(bookId, chapterId, title)
	{
		if(confirm('确定解禁章节"' + title + '"吗？'))
		{
			this.Ajax = new class_ajax();
			this.Ajax.init();
			this.Ajax.set_method('GET');
			this.Ajax.set_event(VipBookChapter.freeCallBack);   //参数不能加引号
			this.Ajax.set_url("chapter_edit.php");
			this.Ajax.add_param("action", "free");
			this.Ajax.add_param("book", bookId);
			this.Ajax.add_param("chapter", chapterId);
			this.Ajax.submit();
		}
	},
	
	freeCallBack:function()
	{
		if(VipBookChapter.Ajax.complete() && VipBookChapter.Ajax.success())
		{
			var re = VipBookChapter.Ajax.get_content();
			if(re == "-999")
			{
				alert("与服务器连接失败，请重新登录");
				return;
			}
			if(re != "0")
			{
				alert("解禁成功");
				DOMObj.Obj("free_pannel_" + re).style.display = "none";
				return;
			}
			alert("解禁失败");
			VipBookChapter.Ajax = null;
		}
	},
	
	del:function(bookId, volumeId, chapterId, title, obj)
	{
		if(confirm('确定删除章节"' + title + '"吗？'))
		{
			obj.onclick = "alert('正在处理，请稍候')";
			
			this.ParamQueue.push({"bookId":bookId, "volumeId":volumeId, "chapterId":chapterId});
			
			var Ajax = new class_ajax();
			Ajax.init();
			Ajax.set_method('GET');
			Ajax.set_event(VipBookChapter.delCallBack);   //参数不能加引号
			Ajax.set_url("chapter_edit.php");
			Ajax.add_param("action", "del");
			Ajax.add_param("book", bookId);
			Ajax.add_param("chapter", chapterId);
			Ajax.submit();
			
			this.AjaxQueue.push(Ajax);
		}
	},
	
	delCallBack:function()
	{
		for(i in VipBookChapter.AjaxQueue)
		{
			if(VipBookChapter.AjaxQueue[i].complete() && VipBookChapter.AjaxQueue[i].success())
			{
				var re = VipBookChapter.AjaxQueue[i].get_content();
				var param = VipBookChapter.ParamQueue[i];
				delete VipBookChapter.AjaxQueue[i];
				delete VipBookChapter.ParamQueue[i];
				if(re == "-999")
				{
					alert("与服务器连接失败，请重新登录");
					return;
				}
				if(re != "0" && re == param["chapterId"])
				{
					alert("删除成功");
					var pobj = DOMObj.Obj("c_table_" + param["volumeId"]);
					var obj = pobj.childNodes[0];
					if(typeof(obj.tagName) == 'undefined')
					{
						obj = pobj.childNodes[1];
					}
					obj.removeChild(DOMObj.Obj("c_tr_" + re));
					if(DOMObj.countChildsByTagName(obj, "TR") <= 1)
					{
						DOMObj.Obj("c_list_" + param["volumeId"]).innerHTML = "该卷尚未添加章节";
					}
					return;
				}
				alert("删除失败");
			}
		}
	},
	
	move:function(obj, save, ChapterId, BookId)
	{
		var idx = (save !=0 ? 1 : 0);
		obj = obj.parentNode;
		obj = obj.parentNode;
		if(save == 2)
		{
		}
		else if(save == 0)
		{
			var sel = obj.childNodes[1].childNodes[2];
			var vid = obj.childNodes[1].childNodes[1].value;
			sel.innerHTML = "";
			with(sel)
			{
				var i = 0;
				for(j in Volume)
				{
					if(Volume[j][2] == vid && Volume[j][1].length <= 1)
					{
						continue;
					}
					options[i++] = new Option(Volume[j][0], Volume[j][2]);
				}
			}
			fill_chapter(sel);
			//var pos = obj.childNodes[1].childNodes[2];
			/*vidx = findVolumeIdx(vid);
			var Chapters = Volume[vidx][1];
			sel = obj.childNodes[1].childNodes[4];
			sel.innerHTML = "";
			with(sel)
			{
				var i = 0;
				for(j in Chapters)
				{
					if(ChapterId != Chapters[j])
					{
						vidx = findChapterIdx(Chapters[j]);
						options[i++] = new Option(Chapter[vidx][1], Chapter[vidx][0] + "_" + Chapter[vidx][3]);
					}
				}
			}*/
			//fill_vpos_list(sel);
		}
		obj.childNodes[idx].style.display = "none";
		obj.childNodes[1-idx].style.display = "";
	},
	
	closeMoveDlg:function()
	{
		var btn = document.getElementsByName("chm_btn");
		for(i = 0; i < btn.length; i++)
		{
			btn[i].click();
		}
	}
};

var VipBookRead = {
	findArray:function(chapterId, start)
	{
		start = typeof(start) == 'undefined' ? 0 : start;
		for(k = start; k < Chapter.length; k++)
		{
			if(Chapter[k][0] == chapterId)
			{
				return k;
			}
		}
	},
	
	bulidNav:function(bookId, chapterId, previewKey, comment_newsid)
	{
		indexUrl = 'book_read.php?book=' + bookId;
		var previewKeyStr='';
		if (previewKey!='' && previewKey!=undefined)
		{
			previewKeyStr = '&_k=' + previewKey;
			pageName = 'chapter_preview.php';
		}
		else
		{
			pageName = 'book_read.php';
		}
		document.write('<a href="' + pageName + '?book=' + bookId + previewKeyStr +  '">[返回作品目录]</a> ');
		var idx = this.findArray(chapterId);		
		if(idx > 0)
		{
			preUrl = pageName + '?book=' + bookId + '&chapter=' + Chapter[idx - 1][0] + previewKeyStr;
			document.write('<a href="' + preUrl + '" title="' + Chapter[idx - 1][1] + '">[上一章]</a> ');
		}
		if(idx < Chapter.length - 1)
		{
			nextUrl = pageName + '?book=' + bookId + '&chapter=' + Chapter[idx + 1][0] + previewKeyStr;
			document.write('<a href="' + nextUrl + '" title="' + Chapter[idx + 1][1] + '">[下一章]</a> ');
		}
		document.write('<a href="#comment" onclick="if(FS.fSTag===\'true\'){FS.UnFullScreen();}">[发表评论]</a>');
		//document.write('<a href="#" onClick="showDetail();return false;">[发表评论]</a>');
		document.write('<a href="http://comment4.news.sina.com.cn/comment/skin/default.html?channel=dushu&newsid=' + comment_newsid + '" target=_blank>[查看评论]</a>');
		document.write(' <a href="javascript:void(null);" onclick="VipBookBook.addToFavorites(' + bookId + ', ' + chapterId + ');">[加入书签]</a>');
		//document.write('<a href="#comment" onclick="if(FS.fSTag===\'true\'){FS.UnFullScreen();}">[发表评论]</a>');
	},
	
	bulidNavPro:function(bookId, chapterId, previewKey, comment_newsid)
	{
		indexUrl = 'book_read.php?book=' + bookId;
		var previewKeyStr='';
		if (previewKey!='' && previewKey!=undefined)
		{
			previewKeyStr = '&_k=' + previewKey;
			pageName = 'chapter_preview.php';
		}
		else
		{
			pageName = 'book_read.php';
		}
		var html = '';
		var idx = this.findArray(chapterId);		
		if(idx > 0)
		{
			preUrl = pageName + '?book=' + bookId + '&chapter=' + Chapter[idx - 1][0] + previewKeyStr;
			html += '<a href="' + preUrl + '" title="' + Chapter[idx - 1][1] + '">[上一章]</a> ';
		}
		if(idx < Chapter.length - 1)
		{
			nextUrl = pageName + '?book=' + bookId + '&chapter=' + Chapter[idx + 1][0] + previewKeyStr;
			html += '<a href="' + nextUrl + '" title="' + Chapter[idx + 1][1] + '">[下一章]</a> ';
		}
		var span = DOMObj.TagObjs("SPAN");
		for(i = 0; i < span.length; i++)
		{
			if(span[i].id == "NavPannel")
			{
				span[i].innerHTML = html;
			}
		}
	},
	
	buildStruct:function(bookId, cur_volumeId, cur_chapterId)
	{
		var str ='';
		var tmp = '';
		for(vidx = 0; vidx < Volume.length; vidx++)
		{
			var selected = false;
			str += '<h4 onclick="VipBookRead.showTab(' + vidx + ')" title="' + Volume[vidx][0] + '">' + Volume[vidx][0].cn_substr(0, 28, "") + '</h4>\n';
			str += '<ul id="VolumeTab" name="VolumeTab" #STYLE#>\n';
			var c = Volume[vidx][1];
			for(j = 0; j < c.length; j++)
			{
				var idx = this.findArray(c[j]);
				c[j] = Chapter[idx][0];
				if(c[j] == cur_chapterId)
				{
					selected = true;
					str += '<li class="selectd"><a href="book_read.php?book=' + bookId + '&chapter=' + c[j] + '" title="' + Chapter[idx][1] + '">' + Chapter[idx][1].cn_substr(0, 20, "...") + '</a>';
				}
				else
				{
					str += '<li><a href="book_read.php?book=' + bookId + '&chapter=' + c[j] + '" title="' + Chapter[idx][1] + '">' + Chapter[idx][1].cn_substr(0, 22, "...") + '</a>';
				}
				str += Chapter[idx][2] == 1 ? '\n<img src="http://www.sinaimg.cn/book/vipbook/book_mj_011.gif" width="21" height="9" alt="VIP章节" title="VIP章节" />' : '';
				str += '</li>\n';
			}
			str += '</ul>\n';
			//str = str.replace("#STYLE#", " style=\"display:none\"");
			if(selected)
			{
				str = str.replace("#STYLE#", "");
			}
			else
			{
				str = str.replace("#STYLE#", " style=\"display:none\"");
			}
		}
		document.write(str);
	},
	
	buildStructPro:function(bookId, cur_volumeId, cur_chapterId)
	{
		var str ='';
		var tmp = '';
		var start = 0;
		for(vidx = 0; vidx < Volume.length; vidx++)
		{
			var selected = false;
			str += '<h4 onclick="VipBookRead.showTab(' + vidx + ')" title="' + Volume[vidx][0] + '">' + Volume[vidx][0].cn_substr(0, 28, "") + '</h4>\n';
			str += '<ul id="VolumeTab" name="VolumeTab" #STYLE#>\n';
			var c = Volume[vidx][1];
			for(j = 0; j < c.length; j++)
			{
				var idx = this.findArray(c[j], start++);
				c[j] = Chapter[idx][0];
				if(c[j] == cur_chapterId)
				{
					selected = true;
					str += '<li class="selectd"><a href="book_read.php?book=' + bookId + '&chapter=' + c[j] + '" title="' + Chapter[idx][1] + '">' + Chapter[idx][1].cn_substr(0, 20, "...") + '</a>';
				}
				else
				{
					str += '<li><a href="book_read.php?book=' + bookId + '&chapter=' + c[j] + '" title="' + Chapter[idx][1] + '">' + Chapter[idx][1].cn_substr(0, 22, "...") + '</a>';
				}
				str += Chapter[idx][2] == 1 ? '\n<img src="http://www.sinaimg.cn/book/vipbook/book_mj_011.gif" width="21" height="9" alt="VIP章节" title="VIP章节" />' : '';
				str += '</li>\n';
			}
			str += '</ul>\n';
			//str = str.replace("#STYLE#", " style=\"display:none\"");
			if(selected)
			{
				str = str.replace("#STYLE#", "");
			}
			else
			{
				str = str.replace("#STYLE#", " style=\"display:none\"");
			}
		}
		DOMObj.Obj("IndexPanel").innerHTML = str;
	},
	
	showTab:function(tab)
	{
		tabs = DOMObj.Objs("VolumeTab");
		var display = tabs[tab].style.display;
		/*if(tabs[tab].style.display == 'block')
		{
			return;
		}*/
		for(i = 0; i < tabs.length; i++)
		{
			tabs[i].style.display = 'none';
		}
		tabs[tab].style.display = display == 'block' ? 'none' : 'block';
	},
	
	setCss:function(div)
	{
		div = DOMObj.Obj(div);
		for(i = 0; i < div.childNodes.length; i++)
		{
			var child = div.childNodes[i];
			if(typeof(child) == 'undefined')continue;
			child.className = div.className;
		}
	},
	
	setFontSize:function(div, size)
	{
		div = DOMObj.Obj(div);
		for(i = 0; i < div.childNodes.length; i++)
		{
			var child = div.childNodes[i];
			if(typeof(child) == 'undefined' || child.tagName != "P")continue;
			child.style.fontSize = size;
		}
		writeCookie('fontSize', size, 9000);
	}
};

var VipBookSms = {
	AjaxQueue:new Array(),
	ParamQueue:new Array(),
	
	setReaded:function(smsid, uid)
	{
		var Ajax = new class_ajax();
		Ajax.init();
		Ajax.set_method('GET');
		Ajax.set_event(VipBookSms.setReadedCallBack);   //参数不能加引号
		Ajax.set_url("/sms/server.php");
		Ajax.add_param("smsid", smsid);
		Ajax.add_param("uid", uid);
		Ajax.add_param("act", "read");
		Ajax.submit();
		this.AjaxQueue.push(Ajax);
		Ajax = null;
	},
	
	setReadedCallBack:function()
	{
		for(i in VipBookSms.AjaxQueue)
		{
			return;
			if(VipBookSms.AjaxQueue[i].complete() && VipBookSms.AjaxQueue[i].success())
			{
				return;
			}
		}
	}
};

var VipBookIFrame = {
	Flip:null,
	Ajax:null,
	Param:null,
	
	AjaxQueue:new Array(),
	ParamQueue:new Array(),
	
	cut:function(template, str, reg)
	{
		reg = new RegExp(reg);
		if(reg.exec(template) == null)return str;
		reg = Math.floor(RegExp.$1);
		return str.ByteCount() > reg ? str.cn_substr(0, reg, '') : str;
	},
	
	print:function(mod, zone, template, col, tr, start, end)
	{
		var tmp = 'top_' + mod + '_' + zone;
		var top = null;
		var script = 'if(typeof(' + tmp + ') == "object"){top = ' + tmp + ';}';
		eval(script);
		if(top == null)return;
		start = (start < 0 || typeof(start) == 'undefined') ? 0 : start;
		end = (end > 0 && end < top.length) ? end : top.length;
		var flip_flag = 0;
		for(i = start; i < end; i++)
		{
			var str = template;
			
			if(this.Flip != null && typeof(this.Flip) == 'object')
			{
				var f = flip_flag % this.Flip.length;
				str = str.replace(/#交替输出#/g, this.Flip[f]);
				flip_flag++;
			}
			
			str = str.replace(/#作品ID#/g, top[i]['book_id']);
			str = str.replace(/#作品名称\|截取(\d+)#/g, this.cut(str, top[i]['title'], /#作品名称\|截取(\d+)#/));
			str = str.replace(/#作品名称#/g, top[i]['title']);
			str = str.replace(/#作品简介#/g, top[i]['intro']);
			str = str.replace(/#作品封面#/g, top[i]['cover']);
			
			if(typeof(top[i]['tags']) == 'object')
			{
				var j = 0;
				var tags = new Array();
				while(typeof(top[i]['tags'][j]) != 'undefined')
				{
					tags[j] = '<a href="http://vip.book.sina.com.cn/s.php?k=' + top[i]['tags'][j] + '" target=_blank>' + top[i]['tags'][j] + '</a>';
					j++;
				}
				tags = tags.join(" ");
				str = str.replace(/#作品标签#/g, tags);
			}
			
			str = str.replace(/#更新日期\|截取(\d+)#/g, this.cut(str, top[i]['updatetime'], /#更新日期\|截取(\d+)#/));
			str = str.replace(/#更新日期#/g, top[i]['updatetime']);
			
			str = str.replace(/#分类ID#/g, top[i]['type']);
			str = str.replace(/#分类名称\|截取(\d+)#/g, this.cut(str, top[i]['type_name'], /#分类名称\|截取(\d+)#/));
			str = str.replace(/#分类名称#/g, top[i]['type_name']);
			
			str = str.replace(/#作者ID#/g, top[i]['uid']);
			str = str.replace(/#作者笔名\|截取(\d+)#/g, this.cut(str, top[i]['penname'], /#作者笔名\|截取(\d+)#/));
			str = str.replace(/#作者笔名#/g, top[i]['penname']);
			str = str.replace(/#作者头像#/g, top[i]['photo']);
			
			str = str.replace(/#门派ID#/g, top[i]['organization']);
			str = str.replace(/#门派名称\|截取(\d+)#/g, this.cut(str, top[i]['org_name'], /#门派名称\|截取(\d+)#/));
			str = str.replace(/#门派名称#/g, top[i]['org_name']);
			
			str = str.replace(/#点击数#/g, top[i]['read_count']);
			str = str.replace(/#推荐数#/g, top[i]['recommend_count']);
			str = str.replace(/#收藏数#/g, top[i]['fav_count']);
			str = str.replace(/#投票数#/g, top[i]['vote_count']);
			str = str.replace(/#评论数#/g, top[i]['comment_count']);
			str = str.replace(/#综合指数#/g, top[i]['fix_count']);
			
			str = str.replace(/#VIP图标#/g, (top[i]['book_vip'] == "Y" ? ' <img src="http://www.sinaimg.cn/book/vipbook/book_mj_011.gif" width="21" height="9" alt="VIP作品" />' : ''));
			/*if(typeof(top[i]['indicators']) == 'object')
			{
				str = str.replace(/#点击数#/g, top[i]['indicators']['read_count']);
				str = str.replace(/#收藏数#/g, top[i]['indicators']['fav_count']);
				str = str.replace(/#投票数#/g, top[i]['indicators']['vote_count']);
				str = str.replace(/#评论数#/g, top[i]['indicators']['comment_count']);
				str = str.replace(/#综合指数#/g, top[i]['indicators']['fix_count']);
			}*/
			if(col > 0)
			{
				if(i == 0)
				{
					str = tr + "\n" + str;
				}
				else if(((i + 1) % col) == 0)
				{
					str += "</tr>";
				}
				else if(i == top.length - 1)
				{
					colume = ((i + 1) % col);
					tmp = new RegExp(/(<td.*?>)/);
					tmp.exec(template);
					tmp = RegExp.$1;
					for(k = 0; k < colume; k++)
					{
						str += tmp + "&nbsp;</td>\n";
					}
					str += "</tr>";
				}
			}
			str = "\n" + str;
			document.write(str);
		}
		this.Flip = null;
	},
	
	printRank:function(rank, sortby, template, col, tr, start, end)
	{
		var tmp = 'Rank_' + rank;
		var Rank = null;
		var script = 'if(typeof(' + tmp + ') == "object"){Rank = ' + tmp + ';}';
		eval(script);
		if(Rank == null)return;
		
		start = (start < 0 || typeof(start) == 'undefined') ? 0 : start;
		end = (end > 0 && end < Rank.length) ? end : Rank.length;
		sortby += "_";
		for(i = start; i < Rank.length; i++)
		{
			var str = template;
			
			str = str.replace(/#排名#/g, (i + 1));
			
			str = str.replace(/#作品ID#/g, Rank[i]['book_id']);
			str = str.replace(/#作品名称\|截取(\d+)#/g, this.cut(str, Rank[i]['title'], /#作品名称\|截取(\d+)#/));
			str = str.replace(/#作品名称#/g, Rank[i]['title']);
			str = str.replace(/#作品封面#/g, Rank[i]['cover']);
			
			str = str.replace(/#作者ID#/g, Rank[i]['uid']);
			str = str.replace(/#作者笔名\|截取(\d+)#/g, this.cut(str, Rank[i]['penname'], /#作者笔名\|截取(\d+)#/));
			str = str.replace(/#作者笔名#/g, Rank[i]['penname']);
			
			str = str.replace(/#门派ID#/g, Rank[i]['organization']);
			str = str.replace(/#门派名称\|截取(\d+)#/g, this.cut(str, Rank[i]['org_name'], /#门派名称\|截取(\d+)#/));
			str = str.replace(/#门派名称#/g, Rank[i]['org_name']);
			
			str = str.replace(/#积分#/g, Rank[i]['point']);
			
			str = str.replace(/#点击数#/g, Rank[i]['read_' + sortby + 'count']);
			str = str.replace(/#收藏数#/g, Rank[i]['fav_' + sortby + 'count']);
			str = str.replace(/#投票数#/g, Rank[i]['vote_' + sortby + 'count']);
			str = str.replace(/#推荐数#/g, Rank[i]['recommend_' + sortby + 'count']);
			str = str.replace(/#评论数#/g, Rank[i]['comment_count']);
			
			if(col > 0)
			{
				if(i == 0)
				{
					str = tr + "\n" + str;
				}
				else if(((i + 1) % col) == 0)
				{
					str += "</tr>";
				}
				else if(i == Rank.length - 1)
				{
					colume = ((i + 1) % col);
					tmp = new RegExp(/(<td.*?>)/);
					tmp.exec(template);
					tmp = RegExp.$1;
					for(k = 0; k < colume; k++)
					{
						str += tmp + "&nbsp;</td>\n";
					}
					str += "</tr>";
				}
			}
			str = "\n" + str;
			document.write(str);
		}
	},
	
	printTop:function(mod, zone, num, template, Element, ex, from)
	{
		this.ParamQueue.push({"mod":mod, "zone":zone, "template":template, "Element":Element, "ex":ex, "from":from});
		var Ajax = new class_ajax();
		Ajax.ID = "printTop";
		Ajax.init();
		Ajax.set_method('GET');
		
		
		Ajax.set_event(VipBookIFrame.printTopCallBack);   //参数不能加引号
		Ajax.set_url("/iframe/top_js.php");
		Ajax.add_param("mod", mod);
		Ajax.add_param("zone", zone);
		Ajax.add_param("num", num);
		Ajax.add_param("ex", ex);
		Ajax.add_param("from", from);
		if(mod == "relate")
		{
			var t = Math.floor(new Date().getTime()/1000);
			t = t % 80;
			Ajax.add_param("_t", t);
		}
		Ajax.add_param("dpc", 1);
		Ajax.submit();
		this.AjaxQueue.push(Ajax);
		DOMObj.Obj(Element).innerHTML = "<div style=\"padding:8px;text-align:center\"><img src=\"http://www.sinaimg.cn/book/vipbook/progress.gif\" />\n<br />\n<br />\n正在加载内容...</div>";
	},

	printTopCallBack:function()
	{
		for(i in VipBookIFrame.AjaxQueue)
		{
			if(VipBookIFrame.AjaxQueue[i].complete())
			{
				if(VipBookIFrame.AjaxQueue[i].success())
				{
					if(VipBookIFrame.AjaxQueue[i].ID == "printTop")
					{
						var p = VipBookIFrame.ParamQueue[i];
						eval(VipBookIFrame.AjaxQueue[i].get_content());
						var tmp = 'top_' + p["mod"] + '_' + p["zone"];
						if(VipBookIFrame.ParamQueue[i]["from"] != "")
						{
							tmp = 'top_' + p["mod"] + '_' + p["from"];
						}
						var output = "";
						var script = 'if(typeof(' + tmp + ') == "object" && ' + tmp + '.length > 0){output = VipBookIFrame.output(' + tmp + ', p["template"]);}';
						eval(script);
						DOMObj.Obj(p["Element"]).innerHTML = output;
					}
				}
			}
		}
		
	},
	
	printRelate: function(param)
	{
		//param = [bookid, 标题长度, 简介长度]
		var zone = "top_relate_" + param[0];
		var zone_data = null;
		var str = "if(typeof(" + zone + ")!='undefined'){zone_data=" + zone + "}";
		eval(str);
		if(zone_data != null && zone_data.length > 0)
		{
			str = "";
			for(var i = 0; i < zone_data.length; i++)
			{
				var title = zone_data[i]["title"];
				var url = "/book/index_" + zone_data[i]["book_id"] + ".html";
				str += '<div class="imgBookBox">\n<a href="' + url + '" title="' + title + '" target="_blank"><img src="' + zone_data[i]["cover"] + '" width="63" height="88" alt="' + title + '" onerror="show_img(this, \'small_bookcover\')"/></a>\n<div class="des">\n<h2><a href="' + url + '" title="' + title + '" target="_blank">' + title.cn_substr(0, param[1], '') + '</a></h2>\n<p>' + zone_data[i]["intro"].cn_substr(0, param[2], '') + '[<a href="' + url + '" target="_blank">阅读全文</a>]</p>\n</div>\n</div>\n';
			}
			document.write(str);
		}
	},
	
	printZone:function(zone, sortby, Element)
	{
		/*var tmp = new Array("zone":zone, "Element":Element);
		tmp["zone"] = zone;
		tmp["Element"] = Element;*/
		this.ParamQueue.push({"zone":zone, "Element":Element});
		var Ajax = new class_ajax();
		Ajax.init();
		Ajax.ID = "printZone";
		Ajax.set_method('GET');
		Ajax.set_event(VipBookIFrame.printZoneCallBack);   //参数不能加引号
		Ajax.set_url("/iframe/rank_iframe.php");
		Ajax.add_param("rank", zone);
		Ajax.add_param("num", 1);
		Ajax.add_param("sortby", sortby);
		Ajax.add_param("_t", new Date().getTime());
		Ajax.submit();
		this.AjaxQueue.push(Ajax);
		
		DOMObj.Obj(Element).innerHTML = "<div style=\"padding:8px;text-align:center\"><img src=\"http://www.sinaimg.cn/book/vipbook/progress.gif\" />\n<br />\n<br />\n正在加载内容...</div>";
	},
	
	printZoneCallBack:function()
	{
		for(i in VipBookIFrame.AjaxQueue)
		{
			if(VipBookIFrame.AjaxQueue[i].complete() && VipBookIFrame.AjaxQueue[i].success() && VipBookIFrame.AjaxQueue[i].ID == "printZone")
			{
				output = VipBookIFrame.AjaxQueue[i].get_content();
				DOMObj.Obj(VipBookIFrame.ParamQueue[i]["Element"]).innerHTML = output;
			}
		}
	},
	
	printZonePro: function(param)
	{
		//param = [zoneid, 标题长度, 是否显示vip图]
		var zone = "topzone_" + param[0];
		var zone_data = null;
		var str = "if(typeof(" + zone + ")!='undefined'){zone_data=" + zone + "}";
		eval(str);
		if(zone_data != null && zone_data.length > 0)
		{
			str = "";
			param[2] = param[2] == 1 ? '<img src="http://www.sinaimg.cn/book/vipbook/book_mj_011.gif" width="21" height="9" alt="VIP作品" />' : '';
			for(var i = 0; i < zone_data.length; i++)
			{
				str += '<li><span class="num">' + (i + 1) + '</span> <a href="/book/index_' + zone_data[i][0] + '.html" title="' + zone_data[i][1] + '" target="_blank">' + zone_data[i][1].cn_substr(0, param[1], '') + '</a>';
				str += zone_data[i][2] == 1 ? param[2] : '';
				str += '</li>';
			}
			document.write(str);
		}
	},
	
	output:function(top, template)
	{
		var html = "";
		for(i = 0; i < top.length; i++)
		{
			var str = template;
			if(i > 0)
			{
				str = '<div class="line"></div>\n' + str;
			}
			
			str = str.replace(/#作品ID#/g, top[i]['book_id']);
			str = str.replace(/#作品URL#/g, "http://vip.book.sina.com.cn/book/index_" + top[i]['book_id'] + ".html");
			str = str.replace(/#作品名称\|截取(\d+)#/g, this.cut(str, top[i]['title'], /#作品名称\|截取(\d+)#/));
			str = str.replace(/#作品名称#/g, top[i]['title']);
			str = str.replace(/#作品简介\|截取(\d+)#/g, this.cut(str, top[i]['intro'], /#作品简介\|截取(\d+)#/));
			str = str.replace(/#作品简介#/g, top[i]['intro']);
			str = str.replace(/#作品封面#/g, top[i]['cover']);
			
			/*if(typeof(top[i]['tags']) == 'object')
			{
				var j = 0;
				var tags = new Array();
				while(typeof(top[i]['tags'][j]) != 'undefined')
				{
					tags[j] = '<a href="http://vip.book.sina.com.cn/s.php?k=' + top[i]['tags'][j] + '" target=_blank>' + top[i]['tags'][j] + '</a>';
					j++;
				}
				tags = tags.join(" ");
				str = str.replace(/#作品标签#/g, tags);
			}
			
			str = str.replace(/#更新日期\|截取(\d+)#/g, this.cut(str, top[i]['updatetime'], /#更新日期\|截取(\d+)#/));
			str = str.replace(/#更新日期#/g, top[i]['updatetime']);
			*/
			str = str.replace(/#分类ID#/g, top[i]['type']);
			str = str.replace(/#分类名称\|截取(\d+)#/g, this.cut(str, top[i]['type_name'], /#分类名称\|截取(\d+)#/));
			str = str.replace(/#分类名称#/g, top[i]['type_name']);
			
			str = str.replace(/#作者ID#/g, top[i]['uid']);
			str = str.replace(/#作者笔名\|截取(\d+)#/g, this.cut(str, top[i]['penname'], /#作者笔名\|截取(\d+)#/));
			str = str.replace(/#作者笔名#/g, top[i]['penname']);
			str = str.replace(/#作者头像#/g, top[i]['photo']);
			
			str = str.replace(/#门派ID#/g, top[i]['organization']);
			str = str.replace(/#门派名称\|截取(\d+)#/g, this.cut(str, top[i]['org_name'], /#门派名称\|截取(\d+)#/));
			str = str.replace(/#门派名称#/g, top[i]['org_name']);
			
			//str = str.replace(/#VIP图标#/g, (top[i]['book_vip'] == "Y" ? ' <img src="http://www.sinaimg.cn/book/vipbook/book_mj_011.gif" width="21" height="9" alt="VIP作品" />' : ''));
			html += str + "\n";
		}
		return html;
	},
	
	printReco:function(author_id, cur_book_id)
	{
		var rAjax = new class_ajax();
		rAjax.init();
		rAjax.set_method('GET');
		rAjax.set_event(printRecoCallBack);   //参数不能加引号
		rAjax.set_url("/iframe/recommend_server.php");
		rAjax.add_param("action", "listbook");
		rAjax.add_param("author_id", author_id);
		rAjax.add_param("cur_book_id", cur_book_id);
		rAjax.submit();
		
		function printRecoCallBack()
		{
			var elm_box = document.getElementById('box_recommend_author');
			var elm_dix = document.getElementById('dix_recommend_author');
			if (rAjax.success())
			{
				var response = rAjax.get_content("text");
				var jsonoutput = eval(response);
				if (jsonoutput)
				{
					var count = jsonoutput.length;
					if (count>0)
					{
						var output = '';
						var rbooks = 0;
						for(var k=0;k<count;k++)
						{
							if (cur_book_id != jsonoutput[k].book_id)
							{
								rbooks++;
								
								output += '<a href="/book/index_' + jsonoutput[k].book_id + '.html" target="_blank"><font';
								if (jsonoutput[k].style==1)
								{
									output += ' color="red"';
								}
								output += '>' + jsonoutput[k].title + '</font></a>';
							}
						}
						
						if (rbooks==0)
						{
							elm_box.style.display = 'none';
							elm_dix.style.display = 'none';
						}
						else
						{
							document.getElementById('book_recommend_author').innerHTML = output;
						}
					}
					else
					{
						elm_box.style.display = 'none';
						elm_dix.style.display = 'none';
					}
				}
				else
				{
					elm_box.style.display = 'none';
					elm_dix.style.display = 'none';
				}
			}
		}
	}
};

var AutoSave = {
	Ajax:null,
	Loop:null,
	Seconds:null,
	IntervalTime:300,
	Status:null,
	
	process:function(checked)
	{
		DOMObj.Obj("submit_btn").disabled = false;
		if(checked)
		{
			DOMObj.Obj("autosave_pan").style.display = "";
			this.Seconds = this.IntervalTime;
			this.autoTime();
			return;
		}
		DOMObj.Obj("autosave_pan").style.display = "none";
		clearTimeout(this.Loop);
		this.Loop = null;
	},
	
	autoTime:function()
	{
		clearTimeout(this.Loop);
		if(this.Seconds <= 0)
		{
			this.autoEvent();
			return;
		}
		var tmp = this.Seconds;
		var h = Math.floor(tmp / 3600);
		tmp -= h * 3600;
		h = h < 10 ? "0" + h : h;
		var m = Math.floor(tmp / 60);
		m = m < 10 ? "0" + m : m;
		var s = tmp - m * 60;
		s = s < 10 ? "0" + s : s
		DOMObj.Obj("auto_time").innerHTML = h + ":" + m + ":" + s;
		this.Seconds--;
		this.Loop = setTimeout(function(){AutoSave.autoTime()}, 1000);
	},
	
	autoEvent:function()
	{
		if(this.Ajax != null)return;
		DOMObj.Obj("submit_btn").disabled = true;
		var theform = document.forms["chapter_form"];
		var min = Math.floor(DOMObj.Obj("min_count").innerHTML);
		var tmp_content = theform.content.value;
		tmp_content = tmp_content.replace(/<IMG.+?>/ig, " ");
		var len = tmp_content.ByteCountPro();
		if(theform.title.value.trim() == "" || !valid_repeat_chars(theform.title.value, 12) || theform.title.length > 64 || len < min || len > 20000 || !valid_repeat_chars(tmp_content, 20))
		{
			DOMObj.Obj("status_tip").innerHTML = "章节不完整，未做保存！";
			this.process(true);
			return;
		}
		this.Ajax = new class_ajax();
		this.Ajax.init();
		this.Ajax.set_method("POST");
		this.Ajax.set_event(AutoSave.evevtCallBack);   //参数不能加引号
		this.Ajax.set_url("/iframe/book_mng_srv.php?action=autosave&book=" + theform.book.value);
		this.Ajax.add_param("_action", theform._action.value);
		this.Ajax.add_param("_chapter", theform._chapter.value);
		//this.Ajax.add_param("book", theform.book.value);
		this.Ajax.add_param("volume", theform.volume.value);
		//this.Ajax.add_param("chapter", 1);
		this.Ajax.add_param("title", theform.title.value);
		this.Ajax.add_param("content", theform.content.value);
		if(typeof(theform.vip) != 'undefined')
		{
			this.Ajax.add_param("vip", (theform.vip.checked ? "2" : "1"));
		}
		var d = new Date();
		this.Ajax.add_param("t", d.getTime());
		this.Ajax.submit();
		
		DOMObj.Obj("auto_time").innerHTML = "正在保存...";
		DOMObj.Obj("status_tip").innerHTML = "";
	},
	
	evevtCallBack:function()
	{
		if(AutoSave.Ajax.complete() && AutoSave.Ajax.success())
		{
			var result = AutoSave.Ajax.get_content();
			AutoSave.Ajax = null;
			result = result.split("|");
			if(result[0] == "1")
			{
				DOMObj.Obj("status_tip").innerHTML = "保存成功！";
				if(result[1] == "1")
				{
					DOMObj.Obj("_action").value = "modc";
					DOMObj.Obj("_chapter").value = result[2];
				}
				if(result[4] != "")
				{
					showCode(true);
					oTXT.value = result[4];
					showCode(false);
				}
				AutoSave.process(true);
			}
			else
			{
				var html = "未知错误";
				if(result[1] == "-1")
				{
					DOMObj.Obj("status_tip").innerHTML = "章节不完整,未做保存！";
					AutoSave.process(true);
					return;
				}
				//if(result[1] == "1")html = "章节信息不完整";
				if(result[1] == "2")html = "章节名称与现有章节重复";
				if(result[1] == "3")html = "操作失败";
				if(result[1] == "4")html = "章节标题含有非法词语";
				if(result[1] == "999")html = "未知错误";
				if(result[0] == "-999")html = "与服务器连接丢失，请重新登录";
				DOMObj.Obj("auto_time").innerHTML = html;
				DOMObj.Obj("autosave").checked = false;
				DOMObj.Obj("submit_btn").disabled = false;
			}
		}
	}
};

var VipBookCheckLogs = {
	TotalRecords:0,
	TotalPages:0,
	RecordsPerPage:0,
	RequestParam:null,
	
	getHashParam:function(name)
	{
		var hash = location.hash.toString().substring(1);
		if(typeof(hash) == 'undefined')return null;
		hash = hash.split("|");
		for(i = 0; i < hash.length; i++)
		{
			var param = hash[i].split("=");
			if(param[0] == name)
			{
				return param[1];
			}
		}
		return null;
	},
	
	setHashParam:function(name, value, hashstr)
	{
		if(!hashstr)
		{
			hash = location.hash.toString();
		}
		else
		{
			hash = hashstr;
		}
		var reg = new RegExp("(" + name + "=(?:[^\|]*$|.*?\|))");
		var match = hash.match(reg);
		if(match == null || typeof(match) == 'undefined')
		{
			var tmp = hash.split("|");
			if(tmp.length  > 1)
			{
				hash += "|" + name + "=" + value;
			}
			else
			{
				hash += name + "=" + value;
			}
		}
		else
		{
			hash = hash.replace(match[1], name + "=" + value);
		}
		if(!hashstr)location.hash = hash;
		return hash;
	},
	
	showLogs:function()
	{
		var p = Math.floor(this.getHashParam("p"));
		p = p < 1 ? 1 : p;
		p = p > this.TotalPages ? this.TotalPages : p;
		
		DOMObj.Obj("log_list").innerHTML = this.listHtml(p);
		DOMObj.Obj("list_nav").innerHTML = this.navHtml(p);
	},
	
	changePage:function(p)
	{
		this.setHashParam("p", p);
		this.showLogs();
	},
	
	listHtml:function(p)
	{
		var content = BookCheckLogs;
		var html = "";
		for(i = (p - 1) * this.RecordsPerPage; i < p * this.RecordsPerPage; i++)
		{
			if(i >= this.TotalRecords)
			{
				break;
			}
			html += '<div>\n\t<div style="background-color:#F0F0F0;padding:2px;">' + content[i][1] + ' [' + content[i][4] + ']</div>\n\t<div style="padding:2px;padding-bottom:6px;"><b>编辑建议：</b> ' + content[i][3] + '</div>\n</div>\n';
		}
		return html;
	},
	
	navHtml:function(p)
	{
		var hash = location.hash;
		var html = '<td width="80">&nbsp;共 <font color="#FF0000">' + this.TotalRecords + '</font> 条记录</td>\n<td align="right">';
		//var html = "<div>共 " + this.TotalRecords + " 条记录&nbsp;&nbsp;\n";
		for(i = 1; i <= this.TotalPages; i++)
		{
			if(i == p)
			{
				html += "[" + i +"]\n";
				continue;
			}
			html += "[<a href=\"" + this.setHashParam("p", i, hash) + "\" onclick=\"VipBookCheckLogs.changePage(" + i + ")\">" + i + "</a>]\n";
		}
		//html += "</div>\n";
		html += "</td>\n";
		return html;
	}
};

function setPageTitle(title)
{
	DOMObjs.TagObjs("title")[0].innerHTML = title;
}