/**
 * @category mines
 * @package admin
 * @copyright Copyright (c) 2006-2009 dm72.
 * @version $Id: rongshuxia.js 1001 2009-11-09 22:45 Renling Lin $
 */
/**
 * 正则匹配
 */
function regTest(reg, content) {
	eval(reg);
	return reg.test(content);
}
//计算包含英文与汉字的字符串长度
function strLength(str) {
	var totalCount = 0;
	for ( var i = 0; i < str.length; i++) {
		var c = str.charCodeAt(i);
		if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
			totalCount++;
		} else {
			totalCount += 2;
		}
	}
	return totalCount;
}
function DispalySelect(val) {//ie6 bug  elect z-index
	var aType = [ "hidden", "visible" ];
	var aSelect = document.getElementsByTagName("select");
	for (i = 0; i < aSelect.length; i++) {
		aSelect[i].style.visibility = aType[val];
	}
}
function removePop() {
	$(".popBoxBg").remove();
	$(".popBoxContainer").remove();
}
function ajaxLogin(container, fnSucc, fnFail) {
	var username = $(container).find("[name=username]").val();
	var password = $(container).find("[name=password]").val();
	var autologin = "";
	try {
		if ($("#autologin").attr("checked")) {
			autologin = "yes";
		}
	} catch (err) {
	}
	$.post("/user/ajaxloginpost", {
		username : username,
		password : password,
		autologin : autologin
	}, function(re) {
		if (re != "true") {
			$('body').append(re);
			$(".closePOP").click( function() {
				removePop();
				if (fnFail instanceof Function)
					fnFail(container, re);
			});
			$("#pop_cancel").click( function() {
				removePop();
				if (fnFail instanceof Function)
					fnFail(container, re);
			});
		} else {
			try {
				fnSucc(username);
			} catch (err) {
				$("#login_form_1").html(username);
			}
		}
	})
}
function compatibleImgSrc(elFile) {
	var ret = null;
	if (!elFile.value.match(/\.jpg$/i)) {
		return;
	}
	if (elFile.files) {
		ret = elFile.files[0].getAsDataURL();
	} else if (elFile.value.indexOf("\\") > -1
			|| elFile.value.indexOf("\/") > -1) {
		ret = elFile.value;
	}
	return ret;
}
function auto_save_chapter() {
	var chapter_title = $("#title").val();
	var chapter_content = $("#content").val();
	if (chapter_title == "") {
		chapter_title = "您还没有写标题";
	}
	if (chapter_content == "") {
		chapter_content = "您还没有写内容";
	}
	$.post(url_start + "/user/autosavechapter/", {
		title : chapter_title,
		content : chapter_content,
		notes : $("#notes").val(),
		book_id : $("#book_id").val(),
		volume_id : $("#volume_id").val(),
		chapter_id : $("#chapter_id").val(),
		ajaxsave : "yes"
	}, function(re) {
		if (re != "false" && re != "") {
			$("#chapter_id").val(re);
		}
	});
	setTimeout(auto_save_chapter, 120000);
}
$( function() {
	try {
		$("#go_sort1").change( function() {
			$("#sort1").val($(this).val());
			$("#sortSearchForm").submit();
		})
		$("#go_sort2").change( function() {
			$("#sort2").val($(this).val());
			$("#sortSearchForm2").submit();
		})
		$(".deleteShelfCat").click( function() {
			if (confirm("删除分类同时删除分类下的所有收藏，确认要删除?")) {
				$.post('/user/shelfcatdelete', {
					cat_id : $(this).attr('id')
				}, function(re) {
					if (re != 'false') {
						self.document.location = re;
					} else {
						alert('删除失败。');
					}
				});
			} else {
				return false;
			}
			return false;
		});
		$("#booksheldelete").click( function() {
			var checked_num = $("input:checked").length;
			if ($("#checkAll").attr("checked")) {
				checked_num--;
			}
			if (checked_num < 1) {
				alert("请先选择要删除的作品。");
				return false;
			}
		})
		$("#bookshelfmoveto").change( function() {
			var checked_num = $("input:checked").length;
			if ($("#checkAll").attr("checked")) {
				checked_num--;
			}
			if (checked_num < 1) {
				alert("请先选择要移动的作品。");
				return false;
			}
			if (confirm("您将移动" + checked_num + "部作品到选定的分类?")) {
				$("#act").val("move");
				$("#bookshelfForm").submit();
			} else {
				return false;
			}
		});
		$("#uploadBookPic")
				.click(
						function() {
            if($("#bookpic").val()==""){return false};
			var f = document.getElementById('commitForm');
			var act = f.action;
			var target= f.target;
			f.action = '/user/filepost';
			f.target = 'ifm';
			f.submit();
			f.action = act;
			f.target= '_self';
            $("#loading").show();

			
			/*
							jQuery('#crop_big').Jcrop = function() {
							}
							var src = compatibleImgSrc(this);
							if (!src) {
								return;
							}
							$("#photo").attr('src', src);
							init_pic();
							*/
						});
		$("#commentForm").submit( function() {
			if ($("#comment_content").val() == "") {
				alert("请输入评论内容。");
				$("#comment_content").focus();
				return false;
			}
			if ($("#checkcode").val() == "") {
				alert("请输入验证码。");
				$("#checkcode").focus();
				return false;
			}
			$("#commentForm input[type='submit']").attr('disabled', true);
			$.post('/user/ajaxgetstate',null,function(r){
				if(typeof(r.success)!='undefined'){
					if(r.success==1){
						$("#commentForm").get(0).submit();
					}else{
						switch(r.error){
							case 1001:{alert('您尚未登录，请先登录。');$(window).scrollTop(0);break;}
							case 1011:{location.replace('/user/profile/?backurl='+escape(document.URL));break;}
						}
					}
					$("#commentForm input[type='submit']").attr('disabled', false);
				}
			},'json');
			return false;
		});
		$("#chapterForm").submit( function() {
			if ($("#title").val() == "") {
				alert("您还没有写标题。");
				$("#title").focus();
				return false;
			} else if ($("#title").val().length > 25) {
				msg += "<li>标题不能超过25字。</li>";
			}
			if ($("#content").val() == "") {
				alert("您还没有写内容。");
				return false;
			} else if ($("#content").val().length > 20000) {
				alert("您的作品已超过20000字，请新建作品或改创建专辑作品。");
				return false;
			}
		});
		$("#chapter_autosave").click( function() {
			if ($(this).attr("attr", "checked")) {
				auto_save_chapter();
			}
		});
		$(".category_choose").click( function() {
			$(".subWords").css("display", "none");
			$(".channel_" + $(this).attr("id")).css("display", "block");
			$(".category_choose").attr("class", "category_choose");
			$(this).attr("class", "category_choose st");
		});
		$(".ajaxlogin")
				.click(
						function() {
							removePop();
							var fnSucc = window[$(this).attr("onloginsucc")];
							var fnFail = window[$(this).attr("onloginfail")];
							var nDeep = 5;
							var container = this.parentNode
							while (nDeep--) {
								if ($(container).find("[name=username]").length
										&& $(container).find("[name=password]").length) {
									break;
								}
								container = container.parentNode;
							}
							ajaxLogin(container, fnSucc, fnFail)
							return false;
						})
		$("#shelf_title").keyup( function() {
			$("#pop_cat_err").html("");
		})
		$(".topmenu").click( function() {
			var obj = $("#" + $(this).attr("subid"));
			if (obj.css("display") == "none") {
				obj.css("display", "block");
			} else {
				obj.css("display", "none");
			}
		});
		$(".closePOP").click( function() {
			DispalySelect(1)
			$(".popBoxBg").css("display", "none");
			$(".popBoxContainer").css("display", "none");
		});
		$("#pop_cancel").click( function() {
			DispalySelect(1)
			$(".popBoxBg").css("display", "none");
			$(".popBoxContainer").css("display", "none");
		});
		$("#add_bookshel_category").click( function() {
			DispalySelect(0)
			$(".popBoxBg").css("display", "block");
			$(".popBoxContainer").css("display", "block");
			return false;
		});
		$("#recode").click( function() {
			var src_url = $("#codeimg").attr("src") + "?" + Math.random();
			$("#codeimg").attr("src", src_url);
		});
		$(".show_category_sud").click( function() {
			$("#book_category").val($(this).attr("id"));
			redirect($id($(this).attr("id")));
		});
		$('#applyNext').click( function() {//添加
					var book_category = $('#fli li.selected').text();
					var book_type = $('#subStage1 li.selected').text();
					if ($('#subStage2 li').length != 0) {
						book_type = $('#subStage2 li.selected').text();
					}
					$.post(url_start + '/user/commit/', {
						'book_category' : book_category,
						'book_type' : book_type
					}, function() {
						window.location.href = '/user/commit';
					})
				});
		$(".favorite_btn").click( function() {
			favor_book($(this));
			return false;
		});
		$(".share_to_friend").click( function() {
			$("#share_to_friend_bg").css("display", "block");
			$("#share_to_friend_container").css("display", "block");
		});
		$("#addbookshelfForm").submit( function() {
			$.post(url_start + "/user/addshelfpost", {
				title : $("#shelf_title").val()
			}, function(re) {
				if (re != "true") {
					$("#pop_cat_err").html(re);
				} else {
					self.document.location.reload();
				}
			});
			return false;
		});
		$("#userEliteForm").submit( function() {
			var msg = "";
			if ($("#book_id").val() == "") {
				msg += "<li>请输入作品编号。</li>";
			} else if (!regTest(/^[\d]+$/, $("#book_id").val())) {
				msg += "<li>作品编号只能为数字。</li>";
			}
			if (msg != "") {
				$("#popbox_title").html("提示信息");
				msg = "<li><b>填写信息错误：</b></li>" + msg;
				$("#pop_msg_content").html(msg);
				$(".popBoxBg").css("display", "block");
				$(".popBoxContainer").css("display", "block");
				return false;
			} else {
				$.post(url_start + "/user/elitepost/", {
					book_id : $("#book_id").val()
				}, function(re) {
					if (re == "true") {
						self.document.location.reload();
					} else {
						$("#popbox_title").html("提示信息");
						msg = "<li><b>填写信息错误：</b></li><li>" + re + "</li>";
						$("#pop_msg_content").html(msg);
						$(".popBoxBg").css("display", "block");
						$(".popBoxContainer").css("display", "block");
					}
				});
			}
			return false;
		});
		try {
			var cur_num = $("#user_intro").val();
			$("#user_intro_err").html(cur_num.length);
		} catch (err) {
		}
		try {
			var checked_title = true;
			$("#title").blur( function() {
				$.post(url_start + "/user/booktitlecheck", {
					title : $("#title").val(),
					bookid : $('input[name="bookid"]').val()
				}, function(re) {
					if (re == "false") {
						checked_title = true;
					} else {
						checked_title = false;
					}
				})
			});
		} catch (err) {
		}
		$("#commitForm").submit(
				function() {
					var msg = "";
					var book_id = $("#bookid").val();
					var imgsrc = $("#bookpic").val();
					if (imgsrc != "" && !(/\.jpg$/i.test(imgsrc))) {
						msg += "<li>作品封面图应为jpg格式。</li>";
					}
					if (book_id == "" && $("#title").val() == "") {
						msg += "<li>请输入作品名称。</li>";
					} else if ($("#title").val().length > 25) {
						msg += "<li>请输入作品名称不能超过25字。</li>";
					} else if (!checked_title) {
						msg += "<li>您已经发布了该标题的作品。</li>";
					}
					if ($("#pinyin").val() == "0" || $("#pinyin").val() == "") {
						msg += "<li>请选择拼音索引。</li>";
					}
					if ($("#tags").val() == "") {
						msg += "<li>请输入关键字。</li>";
					}
					if ($("#intro").val() == "") {
						msg += "<li>请输入作品介绍。</li>";
					}
					if ($("#shorttype").val() == 'Y'
							&& $("#shorttype").val().length > 20000) {
						msg += "<li>文章内容请控制在20000以内。</li>";
					}
					if (msg != "") {
						$("#popbox_title").html("提示信息");
						msg = "<li><b>填写信息错误：</b></li>" + msg;
						$("#pop_msg_content").html(msg);
						$(".popBoxContainer").css("display", "block");
						DispalySelect(0);
						return false;
					}
					return true;
				});
		var checked_penname = false;
		$("#penname").blur( function() {
			$.post(url_start + "/user/pennamecheck", {
				field : "penname",
				val : $("#penname").val()
			}, function(re) {
				if (re == "false") {
					checked_penname = true;
				} else {
					checked_penname = false;
				}
			})
		})
		$("#modifyinfoForm").submit(
				function() {
					var msg = "";
					if ($('input[name="penname"]').val() == "") {
						msg += "<li>请输入笔名。</li>";
					}
					if ($("#penname").val() == undefined) {
						checked_penname = true;
					}
					if ($("#mobile").val() == "") {
						msg += "<li>请输入手机。</li>";
					} else if (!/\d{11}/.test($("#mobile").val())) {
						alert($("#mobile").val());
						msg += "<li>请输入11位手机号码。</li>";
					}
					if ($("#msn").val() == "" && $("#qq").val() == "") {
						msg += "<li>常用联系方式：（以下联系方式请至少填写一项）。</li>";
					}
					if ($("#msn").val() != ""
							&& !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
									.test($("#msn").val())) {
						msg += "<li>msn格式不正确</li>";
					}
					if ($("#qq").val() != ""
							&& !/^[1-9]\d{3,15}$/.test($("#qq").val())) {
						msg += "<li>qq格式不正确</li>";
					}
					if ($("#user_intro").val() == "") {
						msg += "<li>请输入个人简介。</li>";
					} else if ($("#user_intro").val().length > 300) {
						msg += "<li>个人介绍最多只能输入300字。</li>";
					}
					if (!checked_penname) {
						msg += "<li>笔名已经被使用，请更换。</li>";
					}
					if (msg != "") {
						$("#popbox_title").html("提示信息");
						msg = "<li><b>填写信息错误：</b></li>" + msg;
						$("#pop_msg_content").html(msg);
						$(".popBoxContainer").css("display", "block");
						DispalySelect(0);
						return false;
					} else {
						return checked_penname;
					}
				});
	} catch (er) {
	}
})
/* globe js function */
var Rsx = {};
function load_event_monitor(root) {
	var re = /a_(\w+)/;
	var fns = {};
	$(".j", root).each( function(i) {
		var m = re.exec(this.className);
		if (m) {
			var f = fns[m[1]];
			if (!f) {
				f = eval("Rsx.init_" + m[1]);
				fns[m[1]] = f;
			}
			f && f(this);
		}
	});
}
$( function() {
	load_event_monitor(document);
})
// user commit
Rsx.init_commitshort_val = function(form) {
	try {
		var checked_title = true;
		$("#title").blur( function() {
			$.post(url_start + "/user/booktitlecheck", {
				title : $("#title").val(),
				bookid : $('input[name="bookid"]').val()
			}, function(re) {
				if (re == "false") {
					checked_title = true;
				} else {
					checked_title = false;
				}
			})
		});
	} catch (err) {
	} 
	$(form).submit( function() {
		var title = $('input[name="title"]');
		var pinyin = $('select[name="pinyin"]');
		var tags = $('input[name="tags"]');
		var content = $('#content');
		var msg = "";
		if (!$.trim(title.val())) {
			msg += "<li>请输入作品名称。</li>";
		} else if ($("#title").val().length > 25) {
			msg += "<li>请输入作品名称不能超过25字。</li>";
		} else if (!checked_title) {
			msg += "<li>您已经发布了该标题的作品。</li>";
		}
		if (pinyin.val() == "0" || pinyin.val() == "") {
			msg += "<li>拼音索引为作品名的首字母，请选择，便于文章搜索。</li>";
		}
		if (!$.trim(tags.val())) {
			msg += "<li>请填写关键字。</li>";
		}
		if (!$.trim(content.val())) {
			msg += "<li>请填写作品内容。</li>";
		} else if (content.val().length < 20) {
			msg += "<li>对不起，单篇作品不得少于20字。</li>";
		}
		if (msg != "") {
			DispalySelect(0);
			$("#popbox_title").html("提示信息");
			msg = "<li><b>温馨提示：</b></li>" + msg;
			$("#pop_msg_content").html(msg);
			$(".popBoxContainer").show();
			return false;
		}
	})
}
// user commit
Rsx.init_commit_val = function(form) {
	$(form).submit( function() {
		var title = $('input[name="title"]');
		var type = $('select[name="type"]');
		var pinyin = $('select[name="pinyin"]');
		var tags = $('input[name="tags"]');
		var intro = $('#intro');
		var msg = "";
		if (!$.trim(title.val())) {
			msg += "<li>请输入作品名称。</li>";
		}
		if (type.val() == "0") {
			msg += "<li>请选择作品类别。</li>";
		}
		if (pinyin.val() == "0" || pinyin.val() == "") {
			msg += "<li>请选择拼音索引。</li>";
		}
		if (!$.trim(tags.val())) {
			msg += "<li>请填写关键字。</li>";
		}
		if (!$.trim(intro.val())) {
			msg += "<li>请填写作品简介。</li>";
		}
		if (msg != "") {
			$("#popbox_title").html("提示信息");
			msg = "<li><b>填写信息错误：</b></li>" + msg;
			$("#pop_msg_content").html(msg);
			$(".popBoxContainer").show();
			return false;
		}
	})
}
//user favor
Rsx.init_favor_val = function(form) {
	$(form).submit( function() {
		var cat = $('input[name="favor_cat[]"]:checked');
		var life = $('input[name="favor_life[]"]:checked');
		var author = $('#favor_author');
		var book = $('#favor_book');
		var msg = "";
		if (cat.length == 0) {
			msg += "<li>请选择喜欢的类型。</li>";
		}
		if (life.length == 0) {
			msg += "<li>请选择喜欢的题材。</li>";
		}
		if (!$.trim(author.val())) {
			msg += "<li>请填写喜欢的作家。</li>";
		}
		if (!$.trim(book.val())) {
			msg += "<li>请填写喜欢的作品。</li>";
		}
		if (msg != "") {
			$("#popbox_title").html("提示信息");
			msg = "<li><b>填写信息错误：</b></li>" + msg;
			$("#pop_msg_content").html(msg);
			$(".popBoxContainer").show();
			return false;
		}
	})
}
//user volume
Rsx.init_volume_val = function(form) {
	$(form).submit( function() {
		var title = $('input[name="title"]');
		var intro = $('#intro');
		var msg = "";
		if (!$.trim(title.val())) {
			msg += "<li>请填写分卷名。</li>";
		}
		if (!$.trim(intro.val())) {
			msg += "<li>请填写分卷简介。</li>";
		}
		if (msg != "") {
			$("#popbox_title").html("提示信息");
			msg = "<li><b>填写信息错误：</b></li>" + msg;
			$("#pop_msg_content").html(msg);
			$(".popBoxContainer").show();
			return false;
		}
	})
}
Rsx.init_status_tip = function(o) {
	$(':radio', o).click( function() {
		var arrtext = [ '作品正在创造中。', '作品已完成。', '作品已出版。', '作品暂停更新。' ];
		switch ($(this).val()) {
		case 'SERIES':
			$('.ft_content p', o).text(arrtext[0]);
			$('.formTip', o).css( {
				'padding-left' : '0px'
			});
			break;
		case 'FINISH':
			$('.ft_content p', o).text(arrtext[1]);
			$('.formTip', o).css( {
				'padding-left' : '60px'
			});
			break;
		case 'PUBLISHED':
			$('.ft_content p', o).text(arrtext[2]);
			$('.formTip', o).css( {
				'padding-left' : '122px'
			});
			break;
		case 'PAUSE':
			$('.ft_content p', o).text(arrtext[3]);
			$('.formTip', o).css( {
				'padding-left' : '183px'
			});
			break;
		default:
			$('.ft_content p', o).text(arrtext[0]);
			$('.formTip', o).css( {
				'padding-left' : '0px'
			});
			break;
		}
	})
}
Rsx.init_radio_tip = function(o) {
	$(':radio', o)
			.click(
					function() {
						var arrtext = [
								'A 级授权：我保证此稿件系首发于《榕树下》，我同意《榕树下》编辑部作为此稿件版权的独家代理人。在撤销本委托之前，我保证不再将此稿件投给其他媒体，有关此稿件发表和转载等任何事宜，由 《榕树下》编辑部全权负责。 ',
								'B 级授权：我同意《榕树下》发表此稿件，同意《榕树下》编辑部向其他出版社、媒体推荐此稿件，或向其他媒体颁发转载使用许可。一旦传统媒体决定刊用，请《榕树下》及时通知我。在不发生重复授权的前提下，我保留个人向其他媒体的直接投稿权利。',
								'C 级授权：此稿件供《榕树下》及其合作的网站、平台和媒体发表，未经作者本人同意，其他媒体也一律不得转载。 ' ];

						$('.ft_content p', o).text(arrtext[$(this).val() - 1]);
						switch ($(this).val()) {
						case '1':
							$('.formTip', o).css( {
								'padding-left' : '0px'
							});
							break;
						case '2':
							$('.formTip', o).css( {
								'padding-left' : '70px'
							});
							break;
						case '3':
							$('.formTip', o).css( {
								'padding-left' : '140px'
							});
							break;
						default:
							$('.ft_content p', o).text(arrtext[0]);
							$('.formTip', o).css( {
								'padding-left' : '0px'
							});
							break;
						}
					})
}
Rsx.init_maxlength = function(o) {
	$('textarea[maxlength]')
			.keyup(
					function() {
						var max = parseInt($(this).attr('maxlength'));
						if ($(this).val().length > max) {
							$(this).val(
									$(this).val().substr(0,
											$(this).attr('maxlength')));
							alert('字数超出限制，超出部分将会被自动去掉。');
						}
						$(this).parent().find('em').html(
								"&nbsp;" + $(this).val().length + "&nbsp;");
					});
}
Rsx.init_vloume_move = function(o) {
	$(o).click( function() {
		var v = $(this).val();
		if (v == '移动卷') {
			$(this).parent().next().show();
			$(this).parent().hide()
		} else {
			$(this).parent().prev().show();
			$(this).parent().hide()
		}
	})
}
Rsx.init_chapter_del = function(o) {
	$(o).click( function() {
		var v = $(this).val();
		if (v == '移动') {
			$(this).parent().next().show();
			$(this).parent().hide()
		} else {
			$(this).parent().prev().show();
			$(this).parent().hide()
		}
	})
}
//right tab
Rsx.init_tab_r = function(o) {
	$('li', o).click( function() {
		var _ = this.id.split('_')[1];
		var p = $(o).parent().next();
		$('li', o).removeClass('selected');
		$(this).addClass('selected');
		$('ul', p).hide();
		$('ul', p).eq(_).show();
		return false;
	})
}
//left tab
Rsx.init_tab_l = function(o) {
	$('b', o).click( function() {
		var _ = this.id.split('_')[1];
		var p = $(o).next();
		$('b', o).removeClass('selected');
		$(this).addClass('selected');
		p.find('ul').hide();
		p.find('ul').eq(_).show();
		return false;
	})
}
//chapter --left right keyboard
Rsx.init_prevnext_hook = function(o) {
	document.onkeydown = function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		var R_prev = $('a:first', '.ac_boot').attr('href');
		var R_next = $('a:last', '.ac_boot').attr('href');
		if (keycode == 37 && document.activeElement.id !== "comment_content") { // display previous image
			if (R_next != "") {
				document.onkeydown = "";
				window.location.href = R_prev;
			}
		} else if (keycode == 39 && document.activeElement.id !== "comment_content") { // display next image
			if (R_next != "") {
				document.onkeydown = "";
				window.location.href = R_next;
			}
		}
	}
}
function favor_book(obj) {
	$.post(
		url_start + "/book/favoratecat",
		{
			bookid : obj.attr("bookid")
		},
		function(re) {
			$('body').append(re);
			$('#pop_cancel').click( function() {
				try {
					$("#pop_book_favorate_bg").remove();
					$("#pop_book_favorate_container").remove();
					$("#pop_msg_bg").remove();
					$("#pop_msg_container").remove();
				} catch (err) {
				}
			});
			$('.closePOP').click( function() {
				try {
					$("#pop_book_favorate_bg").remove();
					$("#pop_book_favorate_container").remove();
					$("#pop_msg_bg").remove();
					$("#pop_msg_container").remove();
				} catch (err) {
				}
			});
			$("#favorate_sub").click(function() {
				$.post(url_start+ "/book/favoratepost",{
						bookid : $("#bookid").val(),
						catid : $("#cat_id").val()
					},function(check) {
						var obj = $("#pop_book_favorate_container");
						$(".content",obj).html(check);
						$(".bootLine",obj).html('<input type="button" class="btn_yellow_s" value="关闭"/>');
						$(".btn_yellow_s",obj).click(function(){
							$("#pop_book_favorate_container").remove();
							return false;
						});
				});
			});
	});
	return false;
}
//chapter --contextmenu  自定义右键
Rsx.init_contextmenu_hook = function(o) {
	$('body').contextMenu( {
		menu : 'Rsx_menu'
	}, function(action) {
		switch (action) {
		case "menu_favorite":
			favor_book($("#menu_favorite"));
			break;
		case "menu_comment":
			window.location.href = $("#menu_comment").attr("href");
			break;
		case "menu_volume":
			window.location.href = $("#menu_volume").attr("href");
			break;
		case "menu_bbs":
			window.location.href = $("#menu_bbs").attr("href");
			break;
		case "menu_share":
			$("#share_to_friend_bg").css("display", "block");
			$("#share_to_friend_container").css("display", "block");
			break;
		default:
			break;
		}
		return false;
	});
}
//chapter --fontsize
Rsx.init_fontsize_hook = function(o) {
	$('a', o).click( function() {
		var index = $('a', o).index(this);
		if (index == 0) {
			$('.body > p').css( {
				'font-size' : '16px',
				'font-weight' : 'bold'
			});
		} else if (index == 1) {
			$('.body > p').css( {
				'font-size' : '14px',
				'font-weight' : 'normal'
			});
		} else {
			$('.body > p').css( {
				'font-size' : '12px',
				'font-weight' : 'normal'
			});
		}
		return false
	})
}
//book -- top10
Rsx.init_top10 = function(o) {
	$('a', o).click( function() {
		var index = $('a', o).index(this);
		$('a', o).removeClass('selected');
		$(this).addClass('selected');
		var par = $(o).parent();
		par.find('ul').hide();
		par.find('ul').eq(index).show();
		return false
	})
}
//chapter full screen 全屏
Rsx.init_full_screen = function(o) {
$(o).click(function(){
	var fs;
	if(this.tagName=="INPUT")
		fs=$(this).val();
	else
		fs=$(this).text();
	if(fs=="全屏阅读"){
		$('.rs_uniTop, .rsa_right, .commentBox, .uni_footer').hide();
		$('.navigator').hide();
		$('.rsa_left').css('width','950px');
		$('.rmb_r > input:last-child').val('取消全屏');
		$('.a_full_screen').text('取消全屏');
	}else{
		$('.rs_uniTop, .rsa_right, .commentBox, .uni_footer').show();
		$('.rsa_left').css('width','700px');
		$('.navigator').show();
		$('.rmb_r > input:last-child').val('全屏阅读');
		$('.a_full_screen').text('全屏阅读');
	}
	});
}

//functions for book control
Rsx.Book = {
	pop_msg:function(e, disabled){
		var msg = '<b>操作失败，请稍后再重试。</b>';
		switch(e){
			case '1000':
				break;
			case '1001':
				msg = '<li><b>操作成功！</b></li>';
				break;
			case '1002':
				msg = '<li><b>参数错误！</b></li>';
				break;
			case '1003':
				msg = '未登录，请点此 [<b><a href="/user/login.html">登录</a></b>] 系统';
				break;
			case 'waiting':
				msg = '<b>正在操作，请稍候...</b>';
				break;
			default:
				if(e != ''){
					msg = e;
				}
				break;
		}
		var display = disabled ? 'none' : '';
		$(".closePOP").css("display", display);
		$('#pop_cancel').attr('disabled', disabled);
		$("#popbox_title").html("提示信息");
		$("#pop_msg_content").html(msg);
		$("#pop_msg_container").css("display", "block");
	},
	reapply_book:function(o, bookid){
		$(o).attr('disabled', true);
		Rsx.Book.pop_msg('waiting', true);
		
		$.post('/user/reapplybook', {
			'xajax' : 1,
			'bookid' : bookid
			}, function(e){
				$(o).attr('disabled', false);
				if(e == '1001'){
					location.reload();
					return true;
				}
				Rsx.Book.pop_msg(e, false);
		});
	},
	delete_book:function(o, title, bookid){
		if(!confirm("确定删除作品 《" + title + "》 吗？\n提示：删除后不可恢复。")){
			return;
		}
		$(o).attr('disabled', true);
		Rsx.Book.pop_msg('waiting', true);
		
		$.post('/user/deletebook', {
			'xajax' : 1,
			'bookid' : bookid
			}, function(e){
				$(o).attr('disabled', false);
				if(e == '1001'){
					$(o).parent().parent().remove();
					if($('.favBooks tr').length == 1){
						var html = '<tr>\
							<td align="center" colspan="3">\
							  <div class="colBook">还没有发布该类作品，<a href="/user/bookapply">马上发布</a>。</div>\
							</td>\
						</tr>';
						$('.favBooks').append(html);
					}
				}
				Rsx.Book.pop_msg(e, false);
		});
	}
};

//functions for volume control
Rsx.Volume = {
	recover:function(o, bookid, volumeid){
		$(o).attr('disabled', true);
		Rsx.Book.pop_msg('waiting', true);
		
		var volumes = [];
		volumes.push(volumeid);
		$.post('/user/volumerecover', {
			'xajax' : 1,
			'bookid' : bookid,
			'volumes[]' : volumes
			}, function(e){
				$(o).attr('disabled', false);
				if(e == '1001'){
					var p = $(o).parent().parent();
					$(o).parent().remove();
					p.find('span').show();
				}
				Rsx.Book.pop_msg(e, false);
		});
	}
};

//functions for chapter control
Rsx.Chapter = {
	recover:function(o, bookid, chapterid){
		$(o).attr('disabled', true);
		Rsx.Book.pop_msg('waiting', true);
		
		var chapters = [];
		chapters.push(chapterid);
		$.post('/user/chapterrecover', {
			'xajax' : 1,
			'bookid' : bookid,
			'chapters[]' : chapters
			}, function(e){
				$(o).attr('disabled', false);
				if(e == '1001'){
					$(o).parent().remove();
				}
				Rsx.Book.pop_msg(e, false);
		});
	}
};

//user bookshelf
var checkall = function(obj, tarForm) {
	var c = $(obj).is(':checked');
	$(':checkbox', '.' + tarForm).each( function() {
		$(this).attr('checked', c);
	})
}
