Cnepub=new Object();
var trace=function (b) {
	if(!/^http:\/\/www/.test(location.href)&&window.console&&window.console.info) {
		console.info(arguments)
	}
};
var report=function (b) {
	$.get("/j/report?e="+b)
};
Cnepub.EventMonitor=function () {
	this.listeners=new Object()
};
Cnepub.EventMonitor.prototype.broadcast=function (c,f,d) {
	var b=this.listeners[f];
	if(b!=null) {
		for(var e in b) {
			b[e](c,d)
		}
	}
};
Cnepub.EventMonitor.prototype.subscribe=function (c,d) {
	var b=this.listeners[c];
	if(b) {
		b.push(d)
	}else {
		this.listeners[c]=[d]
	}
};
Cnepub.EventMonitor.prototype.unsubscribe=function (c,d) {
	var b=this.listener[c];
	if(b!=null) {
		b=b.filter(function (g,f,e) {
			return g!=d
		})
	}
};
var event_monitor=new Cnepub.EventMonitor();
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("Cnepub.init_"+m[1]);
				fns[m[1]]=f
			}f&&f(this)
		}
	})
}function request_log_ad_displays() {
	$('div[@id^="daslot"]').each(function (b) {
		var c=$(this).attr("id");
		params=c.split("-");
		$.get("/j/da/view?da="+params[1]+"&dag="+params[2]+"&dac="+params[3]+"&p="+params[4]+"&kws="+params[5])
	})
}$(function () {
	load_event_monitor(document)
});

//美化搜索表单
Cnepub.prettify_form=function (b) {
	$("input:submit",b).each(function (d) {
		var c=$('<a href="#" class="butt"></a>').text($(this).val());
		c.click(function () {
			if(clean_tip()) {
				b.submit()
			}return false
		});
		$(this).hide().after(c)
	})
};
var get_form_fields=function (b) {
	var c={
	};
	$(":input",b).each(function (e) {
		var d=this.name;
		if(this.type=="radio") {
			if(this.checked) {
				c[d]=this.value
			}
		}else {
			if(this.type=="checkbox") {
				if(this.checked) {
					c[d]=this.value
				}
			}else {
				if(this.type=="submit") {
					if(/selected/.test(this.className)) {
						c[d]=this.value
					}
				}else {
					if(d) {
						c[d]=this.value
					}
				}
			}
		}if(/notnull/.test(this.className)&&this.value=="") {
			$(this).prev().addClass("errnotnull");
			c.err="notnull"
		}
	});
	return c
};
var remote_submit_json=function (form,func,disable,action) {
	var fvalue=get_form_fields(form);
	if(fvalue.err!=undefined) {
		return
	}$(":submit,:input",form).attr("disabled",disable==false?0:1);
	var act=action||form.action;
	$.post_withck(act,fvalue,function (ret) {
		var json=eval("("+ret+")");
		func(json)
	})
};

Cnepub.init_view_audit_sum=function (b) {
	$(b).click(function () {	
			pop_win.load("/book_audit/popup_audit_sum.php?seed="+Math.random);
		return false
	})
};

Cnepub.init_view_error=function (b) {
	$(b).click(function () {	
			var e=$(this).attr("name").split("-"),id=e[1];
			pop_win.load("/book_detail/popup_view_error.php?id="+id+"&amp;seed="+Math.random);
		return false
	})
};

Cnepub.init_view_donate_log=function (b) {
	$(b).click(function () {	
			pop_win.load("/myspace/popup_view_donate_log.php?seed="+Math.random);
		return false
	})
};

Cnepub.init_review_position=function (b) {
	$(b).click(function () {	
			var e=$(this).attr("name").split("-"),id=e[1],p=e[2];
			pop_win.load("/book_detail/popup_review_position.php?id="+id+"&p="+p+"&seed="+Math.random);
		return false
	})
};


Cnepub.init_write_review=function(b){//添加新评论
	$(b).click(function () {
			var s=$('input[@type=radio][@name="rev_rating"][@checked]').val();
																  
			if (isNaN(s)){
			alert("请选择您的评价！");	
			return false;
			}
			
			var minl=10;
			var r=$("#rev_text").attr("value");
			if (r==""){
				alert("请输入您要评论的内容！");	
				return false;
			}
			if (r.length<minl){
				alert("您的书评小于"+minl+"个字，希望您能发表有意义的书评哦！");	
				return false;
			}
			
			var e=$(this).attr("name").split("-"),id=e[1];
			r=encodeURIComponent(r.replace(/\+/g, '%20')); 
			pop_win.load("/book_reviews/popup_new_review.php?id="+id+"&star="+s+"&review="+r+"&seed="+Math.random);
			var f=setTimeout(function () {
				window.location="/book_detail?id="+id;
			},2000);
		return false
	})	
}

Cnepub.init_error_report=function(b){//提交错误报告
	$(b).click(function () {
			var s=$('input[@type=radio][@name="err_type"][@checked]').val();
																  
			if (isNaN(s)){
			alert("请选择错误类型！");	
			return false;
			}
			
			var minl=10;
			var r=$("#err_description").attr("value");
			if (r==""){
				alert("请输入错误描述！");	
				return false;
			}

			
			var e=$(this).attr("name").split("-"),id=e[1];
			r=encodeURIComponent(r.replace(/\+/g, '%20')); 
			pop_win.load("/book_detail/popup_error_report.php?id="+id+"&t="+s+"&d="+r+"&seed="+Math.random);
			var f=setTimeout(function () {
				window.location="/book_detail?id="+id;
			},2000);
		return false
	})	
}

Cnepub.init_book_audit=function (b) {//书籍审核操作
	$(b).click(function () {	
			pop_win.load("/myspace/popup_view_donate_log.php?seed="+Math.random);
		return false
	})
};

Cnepub.init_claim_shubi=function (b) {//领取书币
	$(b).click(function () {	
			var id=$("#device_id").attr("value");
			pop_win.load("/myspace/popup_claim_shubi.php?id="+id+"&seed="+Math.random);
			
		return false
	})
};


Cnepub.init_set_online_read_pri=function (b) {
	$(b).click(function () {	
			var e=$(this).attr("name").split("-"),v=e[1];
			pop_win.load("/myspace/popup_set_online_read_pri.php?v="+v+"&seed="+Math.random);
			var f=setTimeout(function () {
				window.location.reload();
			},1000);	
		return false
	})
};

Cnepub.init_delete_favor=function (b) {//从“我的收藏夹”中删除
	$(b).click(function () {
		if (confirm("您确定要从“我的收藏夹”中删除这本书吗？")){				 
			var e=$(this).attr("name").split("-"),id=e[1];
			pop_win.load("/myspace/popup_delete_favor.php?id="+id+"&seed="+Math.random);
			var f=setTimeout(function () {
				window.location.reload();
			},500);
			
		return false
		}
	})
};

Cnepub.init_delete_myupload=function (b) {//删除我上传的书
	$(b).click(function () {
		if (confirm("您确定要删除这本书吗？")){				 
			var e=$(this).attr("name").split("-"),id=e[1];
			show_dialog();
			pop_win.load("/myspace/popup_delete_myupload.php?id="+id+"&seed="+Math.random);
			var f=setTimeout(function () {
				window.location.reload();
			},1000);
			
		return false
		}
	})
};

Cnepub.init_delete_privacy=function (b) {//从“我的藏书阁”中删除
	$(b).click(function () {
		if (confirm("您确定要删除这本书吗？")){							 
			var e=$(this).attr("name").split("-"),id=e[1];
			show_dialog();
			pop_win.load("/myspace/popup_delete_privacy.php?id="+id+"&seed="+Math.random);
			
			var f=setTimeout(function () {
				window.location.reload();
			},1000);
		return false
		}
	})
};

Cnepub.init_delete_review=function (b) {//删除书评
	$(b).click(function () {
		if (confirm("您确定要删除该书评吗？")){							 
			var e=$(this).attr("name").split("-"),id=e[1];
			pop_win.load("/book_audit/popup_delete_review.php?id="+id+"&seed="+Math.random);
			
			var f=setTimeout(function () {
				window.location.reload();
			},1000);
		return false
		}
	})
};

Cnepub.init_share_privacy=function (b) {//共享我的藏书
	$(b).click(function () {
			var e=$(this).attr("name").split("-"),id=e[1],sm=e[2];
			pop_win.load("/myspace/popup_share_privacy.php?id="+id+"&sm="+sm+"&seed="+Math.random);
			var f=setTimeout(function () {
				window.location.reload();
			},1000);
		return false
	})
};

Cnepub.init_audit_log=function (b) {//显示审核记录
	$(b).click(function () {
			var e=$(this).attr("name").split("-"),id=e[1];
			return pop_win.load("/myspace/popup_audit_log.php?id="+id+"&seed="+Math.random)
	})
};

Cnepub.init_add_to_myfavor=function (b) {//添加到我的收藏
	$(b).click(function () {
			var e=$(this).attr("name").split("-"),id=e[1];
			return pop_win.load("/book_detail/popup_add_to_myfavor.php?id="+id+"&seed="+Math.random)
	})
};

Cnepub.init_rate_book=function (b) {//评价
	$(b).click(function () {
			var e=$(this).attr("name").split("-"),id=e[1],star=e[2];
			pop_win.load("/book_detail/popup_rate.php?id="+id+"&star="+star+"&seed="+Math.random);
			var f=setTimeout(function () {
				pop_win.close();
			},3000);
			return false;
	})
};


Cnepub.init_myspace=function (b) {//我的书房
	$(b).click(function () {
			var e=$(this).attr("name").split("-"),v=e[0],p=e[1];
			if (isNaN(p)) p=1;
			if (v=="myinfo"){
				$.get("/myspace/myinfo.php?seed="+Math.random,function(data){
					$("#article").html(data);
				});
				$.get("/myspace/ajax_aside_myinfo.php?seed="+Math.random,function(data){
					$("#aside").html(data);
				});
			}
			else{
				$.get("/myspace/ajax_content.php?view="+v+"&page="+p+"&seed="+Math.random,function(data){
					$("#article").html(data);
				});
				$.get("/myspace/ajax_aside_norm.php?seed="+Math.random,function(data){
					$("#aside").html(data);
				});
			}
			
			c=$("#left_menu li");
			c.each(function (v1) {
				var n=$(this).attr("name").split("-"),en=n[1];
				if (en==v) $(this).addClass("on");
				else $(this).removeClass("on");
			});
		return false
	})
};


function ext_links() {
	es=$(".entry-summary");
	es.each(function (c) {
		var b=$(es[c]).find("a");
		b.each(function (d) {
			b[d].target="_blank"
		})
	})
}

var populate_tag_btns=function (g,h,b,e) {
	if(b.length) {
		var c=$("<dl><dt>"+g+"</dt></dl>"),f=$("<dd></dd>");
		$.each(b,function (k,d) {
			var j=$('<span class="tagbtn"/>').addClass(e[d.toLowerCase()]?"rdact":"gract").text(d);
			f.append(j).append(" &nbsp; ")
		});
		c.append(f);
		h.append(c)
	}
};

Cnepub.init_stars=function (e) {
	var b={
		1:"很差",2:"较差",3:"还行",4:"推荐",5:"力荐"
	},g=$("#n_rating"),c=$("#stars img"),d=function (f) {
		var h=g.val()||0;
		c.each(function (k) {
			var i=this.src.replace(/\w*\.gif$/,((k<f)?"sth":((k<h)?"st":"nst"))+".gif");
			this.src=i
		});
		if(f) {
			$("#rateword").text(b[f])
		}else {
			$("#rateword").text(h?b[h]:"")
		}
	};
	c.hover(function () {
		d(this.id.charAt(4))
	},function () {
		d(0)
	});
	if(g.attr("name")) {
		c.click(function () {
			var f=this.id.charAt(4);
			g.val(f);
			d(f)
		})
	}d()
};

var set_cookie=function (f,e) {
	e=e||30;
	var c=new Date();
	c.setTime(c.getTime()+(e*24*60*60*1000));
	var b="; expires="+c.toGMTString();
	for(var d in f) {
		document.cookie=d+"="+f[d]+b+"; path=/"
	}
};
function get_cookie(d) {
	var f=d+"=";
	var b=document.cookie.split(";");
	for(var e=0;e<b.length;e++) {
		var g=b[e];
		while(g.charAt(0)==" ") {
			g=g.substring(1,g.length)
		}if(g.indexOf(f)==0) {
			return g.substring(f.length,g.length).replace(/\"/g,"")
		}
	}return null
}Cnepub.init_hideme=function (b) {
	$(b).click(function () {
		$(this).parent().parent().parent().hide()
	})
};

Cnepub.init_search_text=function (b) {
	if(!b.value||b.value==b.title) {
		$(b).addClass("greyinput");
		b.value=b.title
	}$(b).focus(function () {
		$(b).removeClass("greyinput");
		if(b.value==b.title) {
			b.value=""
		}
	});
	$(b).blur(function () {
		if(!b.value) {
			$(b).addClass("greyinput");
			b.value=b.title
		}
	})
};
Cnepub.init_click_tip=function (c) {
	var b=$(c).next(".blocktip");
	$(c).click(function () {
		b.show().blur_hide();
		m=b.width()+b.pos().x-$.viewport_size()[0]>0?-b.width():0;
		b.css("margin-left",m)
	});
	$(".hideme",b).click(function () {
		b.hide()
	})
};
function clean_tip() {
	var b=$("#page_focus")[0];
	return b&&b.value!=b.title
}Cnepub.init_submit_link=function (b) {
	$(b).click(function () {
		$(b).parent().submit()
	})
};
var nowmenu=null;
var hidemenu=function (b) {
	b.find(".down").css("display","inline");
	b.find(".up").hide();
	b.next().hide();
	nowmenu=null;
	$("body").unbind("mousedown")
};
var openmenu=function (b) {
	if(nowmenu!=null) {
		hidemenu(nowmenu)
	}b.find(".up").css("display","inline");
	b.find(".down").hide();
	b.next().show();
	nowmenu=b;
	$("body").mousedown(function () {
		if(b.parent().attr("rel")!="on") {
			hidemenu(b)
		}
	})
};


var show_dialog=function (c,b) {
	if($("#dialog").length) {
		return
	}
	$("body").prepend('<div id="overlay"></div><div id="dialog" style="width:'+(b||550)+'px;"></div>');
	$("#overlay").unbind("click");
	if(c!=null) {
		$("#dialog").html(c)
	}else {
		$("#dialog").html("<div class='loadpop'>正在载入，请稍候...</div>")
	}set_overlay()
};

var set_overlay=function () {
	var d=($.browser.msie?11:26),c=$("#dialog")[0],b=c.offsetWidth,e=(document.body.offsetWidth-b)/2+"px";
	$("#overlay").css({
		height:c.offsetHeight+d,width:b+26,left:e
	});
	c.style.left=e
};
var close_dialog=function () {
	$("#overlay").unbind("click");
	$("#dialog,#overlay,.bgi").remove();
	if(typeofdocument.body.style.maxHeight=="undefined") {
		$("body","html").css({
			height:"auto",width:"auto"
		});
		$("html").css("overflow","")
	}document.onkeydown="";
	return false
};
var refine_dialog=function () {
	if(!$("#dialog").length) {
		return
	}var b=navigator.userAgent.toLowerCase();
	var c=0.5*($.viewport_size()[1]-$("#dialog")[0].offsetHeight)+140;
	$("#dialog,#overlay").css("top",c);
	set_overlay()
};
Cnepub.init_show_full=function (b) {
	$(b).click(function () {
		$(b).parents(".short").hide();
		$(b).parents(".short").next().show()
	})
};
Cnepub.init_show_short=function (b) {
	$(b).click(function () {
		$(b).parents(".all").hide();
		$(b).parents(".all").prev().show()
	})
};


$.viewport_size=function () {
	var b=[0,0];
	if(typeofwindow.innerWidth!="undefined") {
		b=[window.innerWidth,window.innerHeight]
	}else {
		if(typeofdocument.documentElement!="undefined"&&typeofdocument.documentElement.clientWidth!="undefined"&&document.documentElement.clientWidth!=0) {
			b=[document.documentElement.clientWidth,document.documentElement.clientHeight]
		}else {
			b=[document.body.clientWidth,document.body.clientHeight]
		}
	}return b
};
$.ajax_withck=function (b) {
	if(b.type=="POST") {
		b.data=$.extend(b.data||{
		},{
			ck:get_cookie("ck")
		})
	}return $.ajax(b)
};
$.postJSON_withck=function (b,c,d) {
	$.post_withck(b,c,d,"json")
};
$.post_withck=function (b,d,e,c) {
	if($.isFunction(d)) {
		e=d;
		d={
		}
	}return $.ajax({
		type:"POST",url:b,data:$.extend(d,{
			ck:get_cookie("ck")
		}),success:e,dataType:c
	})
};

var check_form=function (b) {
	var c=true;
	$(":input",b).each(function () {
		if((/notnull/.test(this.className)&&this.value=="")||(/most/.test(this.className)&&this.value&&this.value.length>/most(\d*)/.exec(this.className)[1])) {
			$(this).next().show();
			c=false
		}else {
			if(/attn/.test($(this).next().attr("className"))) {
				$(this).next().hide()
			}
		}
	});
	return c
};
var paras=function (s) {
	var o={
	};
	if(s.indexOf("?")==-1) {
		return {
		}
	}var vs=s.split("?")[1].split("&");
	for(var i=0;i<vs.length;i++) {
		if(vs[i].indexOf("=")!=-1) {
			var k=vs[i].split("=");
			eval("o."+k[0]+'="'+k[1]+'"')
		}
	}return o
};
function delete_reply_notify(b) {
	if(!delete_reply_notify.id) {
		delete_reply_notify.id=b;
		show_dialog($("#confirm_delete").html(),280);
		$("#overlay").css("z-index",100)
	}return false
}

function close_delete(b) {
	if(b) {
		var c=delete_reply_notify.id;
		$.get("/j/remove_notify?id="+c);
		$("#reply_notify_"+c).fadeOut()
	}delete_reply_notify.id=null;
	close_dialog()
}function moreurl(b,e) {
	var d=["ref="+encodeURIComponent(location.pathname)];
	for(var c in e) {
		d.push(c+"="+e[c])
	}set_cookie({
		report:d.join("&")
	})
}
function tip_win(b) {
	$(b).next(".blocktip").show().blur_hide()
}tip_win.hide=function (b) {
	$(b).parents(".blocktip").hide()
};
function js_parser(htm) {
	var tag="script>",begin="<"+tag,end="</"+tag,pos=pos_pre=0,result=script="";
	while((pos=htm.indexOf(begin,pos))+1) {
		result+=htm.substring(pos_pre,pos);
		pos+=8;
		pos_pre=htm.indexOf(end,pos);
		if(pos_pre<0) {
			break
		}script+=htm.substring(pos,pos_pre)+";";
		pos_pre+=9
	}result+=htm.substring(pos_pre,htm.length);
	return {
		htm:result,js:function () {
			eval(script)
		}
	}
}function center(b) {
	return {
		left:(document.documentElement.offsetWidth-b.offsetWidth)/2+"px",top:(document.documentElement.clientHeight-b.offsetHeight)*0.45+"px"
	}
}

function pop_win(f,e) {
	if(!window.__pop_win) {
		var h=document.createElement("div");
		h.className="pop_win_bg";
		document.body.appendChild(h);
		var j=document.createElement("div");
		j.className="pop_win";
		document.body.appendChild(j);
		__pop_win={
			bg:h,body:j,body_j:$(j),bg_j:$(h)
		}
	}var c=__pop_win.body,d=__pop_win.body_j,i=js_parser(f);
	if(e!==true) {
		i.htm='<a onclick="pop_win.close()" href="javascript:;" class="pop_win_close">X</a>'+i.htm
	}c.innerHTML=i.htm;
	var g=center(c);
	if(document.documentElement.clientHeight<c.offsetHeight) {
		g.top="0";
		g.height=document.documentElement.clientHeight-40+"px";
		g.overflow="auto"
	}d.css({
		display:"block"
	}).css(g).css({
		visibility:"visible",zIndex:101
	});
	i.js();
	pop_win.fit();
	if(!window.XMLHttpRequest) {
		__pop_win.bg.style.top=""
	}
}pop_win.fit=function () {
	if(window.__pop_win) {
		var c=__pop_win.body;
		__pop_win.bg_j.css({
			height:c.offsetHeight+20+"px",width:c.offsetWidth+20+"px",left:c.offsetLeft-10+"px",top:c.offsetTop-10+"px",zIndex:100
		}).show()
	}
};
pop_win.close=function () {
	$(__pop_win.bg).remove();
	$(__pop_win.body).remove();
	window.__pop_win=null
};

pop_win.load=function (c,b) {
	pop_win("加载中,请稍等...");
	$.ajax({
		url:c,success:pop_win,cache:b||false
	});
	return false
};

function event_init_tab() {
	$("#tongcheng_tab").click(function () {
		if($("#tongcheng_tab_block").is(":hidden")) {
			show_tongcheng_tab();
			$().click(function () {
				hide_tongcheng_tab();
				$().unbind("click",arguments.callee)
			})
		}else {
			hide_tongcheng_tab()
		}return false
	})
}function show_tongcheng_tab() {
	$("#tongcheng_tab_block").show();
	$("#tongcheng_tab span").addClass("up")
}function hide_tongcheng_tab() {
	$("#tongcheng_tab_block").hide();
	$("#tongcheng_tab span").removeClass("up")
}__load_bk=$.fn.load;
$.fn.load_withck=function (b,c,d) {
	if($.isFunction(c)) {
		d=c;
		c={
		}
	}return __load_bk.call(this,b,$.extend(c,{
		ck:get_cookie("ck")
	}),d)
};
function exp_dialog(b) {
	var c=document.documentElement;
	return 0-parseInt(b.offsetHeight/2)+(TBWindowMargin=c&&c.scrollTop||document.body.scrollTop)+"px"
}function exp_overlay(b) {
	return 0-parseInt(b.offsetHeight/2)+(TBWindowMargin=document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop)+"px"
}function exp_sort_h2_over() {
	this.style.backgroundColor="#eeffee"
}function exp_sort_h2_out() {
	this.style.backgroundColor=""
}function getslider(g,j,d,b,i) {
	var c=5,e=100,k=5,h=0,f=function (l) {
		if(c+l>e) {
			c=e;
			g[0].className="dis"
		}else {
			if(c+l<5) {
				c=5;
				j[0].className="dis"
			}else {
				c+=l
			}
		}j[0].className=c==5?"dis":"";
		g[0].className=c==e?"dis":"";
		h=(5-c)*105;
		d.animate({
			marginLeft:h+"px"
		},{
			duration:250*Math.abs(l),easing:$.easing.easeOutCirc
		})
	};
	return function (l) {
		if(c+l>k&&k<e) {
			$.postJSON_withck(b,{
				start:k,pp:i
			},function (n) {
				if(n.err) {
					e=n.total;
					k+=n.num;
					l=n.num;
					d.html(d.html()+n.more_html);
					f(l)
				}
			})
		}else {
			f(l)
		}
	}
}

Cnepub.init_popup=function (b) {
	$(b).click(function () {
		var c=/(\d+)x(\d+)$/.exec(b.className);
		if(!window.open(b.href,"popup","height="+c[2]+",width="+c[1]+",toolbar=no,menubar=no,scrollbars=no,location=no,status=no")) {
			location.href=b.href
		}return false
	})
};

