﻿Date.prototype.format = function(format){
 var o = {
 "M+" : this.getMonth()+1, //month
 "d+" : this.getDate(), //day
 "h+" : this.getHours(), //hour
 "m+" : this.getMinutes(), //minute
 "s+" : this.getSeconds(), //second
 "q+" : Math.floor((this.getMonth()+3)/3), //quarter
 "S" : this.getMilliseconds() //millisecond
 };
 if(/(y+)/.test(format)) 
 format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
 for(var k in o)
 if(new RegExp("("+ k +")").test(format))
 format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] :("00"+ o[k]).substr((""+ o[k]).length));
 return format;
};
String.prototype.Format = function(){//字符串格式
	var tmpStr = this;
	var iLen = arguments.length;
	for(var i=0;i<iLen;i++)
		tmpStr = tmpStr.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
	return tmpStr;
};

function eventBind(elem, eventName, handler,bool){
 if(elem.addEventListener) elem.addEventListener(eventName, handler, bool);
 else if (elem.attachEvent) elem.attachEvent("on" + eventName, handler); 
 else elem["on" + eventName] = handler; 
};
var isShowRightMenu = false; //当前是否显示右键菜单
function A(id){ return document.getElementById(id);};
var prevpag, nextpage,bookpage, enableEnter = true;
function pageEvent(evt){
 evt = evt ||window.event;
 var key=evt.which||evt.keyCode;
 if (key == 13){
 if (enableEnter){
 location = bookpage
 return false;
 };
 };
 if (key == 37) location = prevpage
 if (key == 39) location = nextpage
};
var menuskin = 1, display_url = 0;
function showmenuie5(event){//readchapter页显示右键菜单
 isShowRightMenu = true;
 event = event ? event : (window.event ? window.event : null);
 var menu = $("ie5menu");
 menu.style.display = "";
 var rightedge = document.body.clientWidth - event.clientX;
 var bottomedge = document.body.clientHeight - event.clientY;
 if (rightedge < menu.offsetWidth) menu.style.left = document.body.scrollLeft + event.clientX - menu.offsetWidth;
 else menu.style.left = document.body.scrollLeft + event.clientX;
 if (bottomedge < menu.offsetHeight) menu.style.top = document.body.scrollTop + event.clientY - menu.offsetHeight;
 else menu.style.top = document.body.scrollTop + event.clientY;
 return false;
};
function hidemenuie5(){ var menu = $("ie5menu"); menu.style.display = "none"; isShowRightMenu = false;};
function myover(obj){ obj.className = "itemshovor";};
function myout(obj){ obj.className = "menuitems";};
function highlightie5(){
 window.event.cancelBubble = false
 if (event.srcElement.className == "menuitems"){
 event.srcElement.className = "itemshovor";
 if (event.srcElement.url.indexOf("mail") == -1) display_url = 1;
 else display_url = 0;
 if (display_url == 1) window.status = event.srcElement.url
 }else display_url = 0;
}
function lowlightie5(){
 if (event.srcElement.className == "itemshovor"){
 event.srcElement.className = "menuitems";
 window.status = '';
 };
};
function jumptoie5(){
 if (event.srcElement.className == "menuitems")
 if (event.srcElement.target != null) window.open(event.srcElement.url)
 else window.location = event.srcElement.url
};
function toolBar(){
 if (A('showTD').style.display == "none"){ //设置cookies 是否显示
 SetCookie("mmsideBar", "1");
 A('showTD').style.display = "";
 A('showTD').width = "193"
 A('showTB').width = "209";
 A('toolDiv').className = "bk_read06";
 var _frame=A('frmBar');
 if(_frame.src.length===0){
 _frame.src=toolBarUrl+'&random='+Math.random();
 };
 }else{//设置cookies 是否显示
 SetCookie("mmsideBar", "0");
 A('showTD').style.display = "none";
 A('showTD').width = "209"
 A('showTB').width = "31";
 A('toolDiv').className = "bk_read07";
 };
};
function initSidebar(){
 var showToolBar = GetCookie("mmsideBar");
 if (showToolBar == "0"){
 A('showTD').style.display = "none";
 A('showTD').width = "209"
 A('showTB').width = "31";
 A('toolDiv').className = "bk_read07";
 } else{
 A('frmBar').src = toolBarUrl;
 A('showTD').style.display = "";
 A('showTD').width = "193"
 A('showTB').width = "209";
 A('toolDiv').className = "bk_read06"; //show
 };
};
lastScrollX = 0; lastScrollY = 0;
function heartBeat(objectid){
 diffY = document.body.scrollTop;
 diffX = document.body.scrollLeft;
 if (diffY != lastScrollY){
 percent = .1 * (diffY - lastScrollY);
 if (percent > 0) percent = Math.ceil(percent);
 else percent = Math.floor(percent);
 eval("document.all." + objectid).style.pixelTop += percent;
 lastScrollY = lastScrollY + percent;
 };
 if (diffX != lastScrollX){
 percent = .1 * (diffX - lastScrollX);
 if (percent > 0) percent = Math.ceil(percent);
 else percent = Math.floor(percent);
 eval("document.all." + objectid).style.pixelLeft += percent;
 lastScrollX = lastScrollX + percent;
 };
};
function showTitle(obj){ obj.title = "点击隐藏或显示控制面板";}; 
function setFocus(){//和flash抢焦点 
 var span = A("content");
 if (span != null){
 if (!isShowRightMenu) span.focus();
 try{
 if (!isShowRightMenu) span.click();
 }catch (e) {}
 };
 window.setTimeout(setFocus, 1000);
};
function show(id){ var obj = A(id); if (obj != null) obj.style.display = "";};
function hide(id){ var obj = A(id); if (obj != null) obj.style.display = "none";};
function HideParentIframe(){//隐藏父iframe
 obj = document.getElementById("loginDiv")
 obj.style.display = "none";
 obj = A("ActionStatus");
 obj.value = "Close";
 A('maskDiv').style.display = '';
};
function SubmitClick(){ login(); };
function showResult(res){ alert(res.value); if (res.value.indexOf("成功") >= 0) Hideframe();};
function login(){
 var ptId = $("user_name").value;
 var password = $("pass_word").value;
 var token = $('txttoken').value;
 MyAjax.LoginUser(ptId, password, token, "", false, showResult);
};
function Hideframe(){ obj = window.parent.document.getElementById("loginDiv"); obj.style.display = "none";};
function showLogin(msg, registerUser){ ShowLoginDiv();};
function hideLogin(){ var div = A("loginDiv"); if (div) div.style.display = "none";};
function showValidCode(){ var imgpath = " /Validator/check" + Math.random() + ".aspx"; A("codeImage").src = imgpath;};
function setStyle(){
 var colorIndex = GetCookie("rc");
 var fontIndex = GetCookie("rf");
 var sltColor = A("ColorSetting");
 var sltColor2 = A("ColorSetting2");
 if (sltColor != null){
 sltColor.selectedIndex = colorIndex;
 sltColor2.selectedIndex = colorIndex;
 };
 var sltFont = A("FontSetting");
 var sltFont2 = A("FontSetting2");
 if (sltFont != null){
 sltFont.selectedIndex = fontIndex;
 sltFont2.selectedIndex = fontIndex;
 };
};
function getClientColor(){
 var colorIndex = GetCookie("rc");
 switch (colorIndex){
 case "0":
 if (typeof IsMM != 'undefined' && IsMM) return "#FCEFFF";
 else return "#E7F4FE";
 case "1":
 if (typeof IsMM != 'undefined' && IsMM) return "#FCEFFF";
 else return "#E7F4FE";
 case "2": return "#E9FAFF";
 case "3": return "#FFFFED";
 case "4": return "#eefaee";
 case "5": return "#FCEFFF";
 case "6": return "#ffffff";
 case "7": return "#efefef";
 default:
 if (typeof IsMM != 'undefined' && IsMM) return "#FCEFFF";
 else return "#E7F4FE";
 };
};
function setFontSize(){
 var fontIndex = GetCookie("rf");
 switch (fontIndex){
 case "0": return "10.5";
 case "1": return "10.5";
 case "2": return "9";
 case "3": return "10.5";
 case "4": return "12";
 case "5": return "14";
 case "6": return "16";
 case "7": return "18"; 
 default: return "10.5";
 };
};
function ClickBook(){
 var readedBook = GetCookie("bc");
 if (readedBook == null || readedBook == "") MyAjax.AddBookClick(bookId, AddClickBack);
 else{
 var bookArray = readedBook.split(',');
 var isAddedClick = false;
 if (bookArray.length > 0){
 for (var i = 0; i < bookArray.length; i++){
 if (bookArray[i] == bookId){
 isAddedClick = true;
 break;
 };
 };
 if (isAddedClick == false) MyAjax.AddBookClick(bookId, AddClickBack);
 };
 };
};
function AddClickBack(res){ return;};
function regMatch(m){
 if (m.charAt(0) == "," && m.charAt(m.length - 1) == ',') return ',';
 else return "";
};
function RecentRead(){
 var readedBook = GetCookie("rcr");
 return (readedBook == null||readedBook.indexOf(bookId)<0) && MyAjax.SetRecentReadBookCookie(bookId);
};
var t = null, isShowing = false,currentmouse = null, curNav, curImg;
function DelayShowDiv(obj, nav, img){
 currentmouse = obj;
 curNav = nav;
 curImg = img;
 var t2 = window.setTimeout(showDiv, 500);
};
function showDiv(obj, nav, img){
 document.getElementById("iframeAdv").src = "/BookReader/AdOver.aspx?img=" + curImg + "&nav=" + curNav;
 var linkDiv = document.getElementById("linkDiv");
 linkDiv.style.left = getPosition(currentmouse).x;
 linkDiv.style.top = getPosition(currentmouse).y + currentmouse.offsetHeight;
 linkDiv.style.position = "absolute";
 linkDiv.style.display = '';
 linkDiv.onmouseover = function() { window.clearTimeout(t); isShowing = true; }
 linkDiv.onmouseleave = function() { document.getElementById("linkDiv").style.display = 'none'; isShowing = false };
};
function getPosition(el){
 for (var lx = 0, ly = 0; el != null; lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
 return { x: lx, y: ly }
};
function setTime(){ var t = window.setTimeout(hide, 1000);};
function hide(){
 if (isShowing){
 if (t != null) { window.clearTimeout(t); }
 return;
 };
 isShowing = false;
 document.getElementById("linkDiv").style.display = 'none';
 if (t != null) window.clearTimeout(t);
};
if(!window.Snda) var Snda=window.Snda={};
(function(){
var userAgent = navigator.userAgent.toLowerCase();
Snda.browser = {
 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
 safari: /webkit/.test( userAgent ),
 opera: /opera/.test( userAgent ),
 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
Snda.Utility={//通用工具
 fadeIn:function( elem, to, speed ) {//淡进
 Snda.Utility.setOpacity( elem, 0 );
 Snda.Utility.show( elem );
 for ( var i = 0; i <= 100; i += 5 ) {
 (function(){
 		 var opacity = i;
 setTimeout(function(){
 Snda.Utility.setOpacity( elem, ( opacity / 100 ) * to );
 }, ( i + 1 ) * speed );
 })();
 };
 },
 fadeOut:function ( elem, speed, remove,callBack ) {//淡出
 for ( var i = 0; i < 100; i += 2 ) {
 (function(){
 		 var opacity = i;
 setTimeout(function(){
 Snda.Utility.setOpacity( elem, 100 - opacity );
			 if ( opacity == 98 ){
			 if(!remove) Snda.Utility.hide( elem );
			 else Snda.Utility.removeNode( elem );
			 callBack();
			 };
 }, ( i + 1 ) * speed );
 })();
 };
 },
 getStyle:function( elem, name ) {//获取样式值
 if (elem.style[name]) return elem.style[name];
 else if (elem.currentStyle) return elem.currentStyle[name];
 else if (document.defaultView && document.defaultView.getComputedStyle) {
 name = name.replace(/([A-Z])/g,"-$1");
 name = name.toLowerCase();
 var s = document.defaultView.getComputedStyle(elem,"");
 return s && s.getPropertyValue(name);
 }else return null;
 },
 hide:function( elem ) {//隐藏
 var curDisplay = Snda.Utility.getStyle( elem, "display" );
 if ( curDisplay != "none" ) elem.$oldDisplay = curDisplay;
 elem.style.display = "none";
 return Snda.Utility;
 },
 show:function(elem){//显示
 elem.style.display = elem.$oldDisplay || "block";
 return Snda.Utility;
 },
 removeNode:function(elem){//移除元素
 elem.parentNode && elem.parentNode.removeChild(elem);
 return Snda.Utility;
 },
 setOpacity:function( elem, level ) {//设置透明度
 if ( elem.filters ) elem.style.filter= "alpha(opacity="+level+")";
 else elem.style.opacity = level / 100;
 return Snda.Utility;
 },
 setX:function(elem, pos) {
 elem.style.left = pos + "px";
 return Snda.Utility;
 },
 setY:function(elem, pos){
 elem.style.top = pos + "px";
 return Snda.Utility;
 },
 StopDefault:function(e){//阻止浏览器默认行为
 if(e&&e.preventDefault) e.prefentDefault();
 else window.event.returnValue=false;
 return false;
 },
 cancelBubble:function(evt){//取消冒泡
 evt = evt|| window.event; 
 if (window.event) evt.cancelBubble=true; 
 else evt.stopPropagation(); 
 },
 Event:{//事件
 addEventHandler :function (oTarget, sEventType, fnHandler,bool){//事件绑定
 if(oTarget.addEventListener) oTarget.addEventListener(sEventType, fnHandler, bool); //FF方法
 else if (oTarget.attachEvent) oTarget.attachEvent("on" + sEventType, fnHandler); //IE方法
 else oTarget["on" + sEventType] = fnHandler; //其他未知浏览器
 },
 removeEventHandler:function(obj,EventType,Handler,bool){
 if(obj.removeEventListener) obj.removeEventListener(EventType,Handler,bool);
 else if(obj.detachEvent) obj.detachEvent('on'+EventType,Handler); 
 else obj['on'+EventType] = null;
 },
 getCurrentElem:function(evt){//获取事件元素
 evt = evt || window.event ; 
 return evt.srcElement || evt.target; 
 }
 },
 Postion:{
 scrollX:function(){//拖动条移动x轴距离
 var de=document.documentElement;
 return self.pageXOffset||(de&&de.scrollLeft)|| document.body.scrollLeft || 0;
 },
 scrollY:function(){//拖动条移动y轴距离
 var de=document.documentElement;
 return self.pageYOffset||(de&&de.scrollTop)|| document.body.scrollTop || 0;
 },
 windowWidth:function(){//屏幕宽
 var de = document.documentElement;
 return self.innerWidth ||( de && de.clientWidth ) || document.body.clientWidth;
 },
 windowHeight:function(){//屏幕高
 var de = document.documentElement;
 return self.innerHeight ||( de && de.clientHeight ) || document.body.clientHeight;
 },
 pageWidth:function() {//页面高
 return document.body.scrollHeight;
 },
 pageHeight:function() {//页面宽
 return document.body.scrollWidth;
 }
 }
};
Snda.Layer={
 zIndex:2009,
 Hash:{},
 Config:{
 bg:'<iframe id="pop_bg2_{0}" scrolling=0 frameborder=0 class="pop_BackGround" ></iframe>'+
 '<div id="pop_bg1_{0}" class="pop_BackGround" ></div>',
 con:'<div class="pop_Content" id="{3}{0}">'+
 '<h1 id="{4}{0}"><span id="pop_title_{0}" class="pop_Title">{6}</span></h1><span id="{5}{0}" class="pop_close" title="关闭"></span>'+
 '<div class="pop_Main"><iframe id="pop_frame_{0}" frameborder="0" scrolling="no" haslayout="-1" src="{1}"></iframe></div>'+
 '<div class="pop_Footer" id="pop_footer_{0}">{2}</div></div>'
 },
 Show:function(config){//显示
 if(!config) throw {msg:'请输入参数'};
 var _json={
 title: config.title||'', //标题
 tid: config.title||'pop_title_', //标题id
 cid: config.cid||'pop_cont_', //主内容id
 hid: config.hid||'pop_head_', //拖动id
 clid: config.clid||'pop_close_', //关闭id
 src: config.src||'', //iframe地址
 fcon: config.fcon||'', //底部内容
 follow: !!config.follow||false, //跟随
 move: !!config.move||false , //移动
 sSpeed: config.sSpeed||5, //淡进
 cSpeed: config.cSpeed||0, //关闭速度
 callBack: config.callBack|| function(){}, //结束回调函数
 firstFun: config.firstFun|| function(){} //预先执行函数
 };
 var _temdId=Math.floor(Math.random()*10000000000);
 Snda.Layer.Hash[_temdId+'']=_json.cid+_temdId;
 var _div=document.createElement('div');
 _div.id='pop_container_'+_temdId;
 _div.style.display='none';
 _div.$sndaId=_temdId;
 _div.$cSpeed=_json.cSpeed;
 _div.$callBack=_json.callBack;
 if(_json.src.indexOf('?')>0) _json.src=_json.src+'&rand='+_temdId;
 else _json.src=_json.src+'?rand='+_temdId;
 _div.innerHTML=Snda.Layer.Config.bg.Format(_temdId)+Snda.Layer.Config.con.Format(_temdId,_json.src,_json.fcon,_json.cid,_json.hid,_json.clid,_json.title);
 document.body.appendChild(_div);
 _json.firstFun();
 Snda.Layer.SetBackGround("pop_bg2_"+_temdId,"pop_bg1_"+_temdId);
 var _close=document.getElementById(_json.clid+_temdId);
 if(_close){//绑定关闭
 Snda.Utility.Event.addEventHandler(_close,'click',Snda.Layer.Close,false);
 _close.$sndaId=_temdId;
 };
 Snda.Layer.BeMiddle(_temdId);//设置居中
 if(_json.follow) Snda.Layer.Follow();//设置跟随
 if(_json.move){//设置拖动
 var _m=document.getElementById(_json.cid+_temdId);
 var _h=document.getElementById(_json.hid+_temdId);
 Snda.Layer.Drag(_h,_m,0,0);
 };
 Snda.Utility.fadeIn(_div,100,_json.sSpeed);
 },
 Close:function(evt){//关闭
 var num;
 var _elem= Snda.Utility.Event.getCurrentElem(evt);
 if(!_elem.$sndaId) return false;
 else num=_elem.$sndaId;
 if(!Snda.Layer.Hash[num+'']) return false;
 var _o=document.getElementById('pop_container_'+num);
 var _con=document.getElementById(Snda.Layer.Hash[num+'']);
 var callBack=function(){
 Snda.Utility.removeNode(_o);
 _o.$callBack();
 };
 delete Snda.Layer.Hash[num+''];
 if(_o && _con) Snda.Utility.fadeOut(_con,_o.$cSpeed,true,callBack);
 Snda.Utility.cancelBubble(evt)
 },
 Follow:function(){//跟随
 var scollEvent=function(){
 var _winWidth = Snda.Utility.Postion.windowWidth();
 var _winHeight = Snda.Utility.Postion.windowHeight();
 for(var o in Snda.Layer.Hash){ 
 if(!o) continue;
 var _div=document.getElementById(Snda.Layer.Hash[o+'']);
 (function(w,h,sX,sY){
 _div && Snda.Utility.setX(_div,sX + (_winWidth-w)/2).setY(_div,sY +(_winHeight-h)/2);
 })(Snda.Utility.getStyle( _div , 'width').replace('px','')>>0, 
 Snda.Utility.getStyle( _div , 'height').replace('px','')>>0,
 Snda.Utility.Postion.scrollX(),
 Snda.Utility.Postion.scrollY());
 };
 };
 Snda.Utility.Event.addEventHandler(window,'scroll',scollEvent,false);
 Snda.Utility.Event.addEventHandler(window,'resize',scollEvent,false);
 Snda.Utility.Event.addEventHandler(window,'load',scollEvent,false);
 },
 BeMiddle:function(id){//居中
 var _div=document.getElementById(Snda.Layer.Hash[id+'']);
 var _width = Snda.Utility.getStyle( _div , 'width' );
 var _height = Snda.Utility.getStyle( _div , 'height');
 _div.style.left =( Snda.Utility.Postion.windowWidth()/2 - (_width.replace('px','')>>0)/2 + Snda.Utility.Postion.scrollX()) + 'px';
 _div.style.top =( Snda.Utility.Postion.windowHeight()/2 - (_height.replace('px','')>>0)/2 + Snda.Utility.Postion.scrollY()) + 'px';
 Snda.Layer.zIndex+=1;
 _div.style.zIndex= Snda.Layer.zIndex;
 },
 SetBackGround:function(){//设置背景宽度
 for(var i=0,j=arguments.length;i<j;i+=1) {
 (function(o,h,w){
 if(o){ o.style.height=h; o.style.width=w; };
 })(document.getElementById(arguments[i]),
 (Math.max(document.body.scrollHeight,document.body.offsetHeight)) + "px",
 (Math.max(document.body.scrollWidth,document.body.offsetWidth)) + "px");
 };
 },
 Drag:function(o,root,minX,minY,opacity){//移动
 !o.$Root&&(o.$Root=root||o);
 opacity = opacity||0.3;
 var x,y,_cloneItem = ['height','width','left','top'];
 var DragEvent={
 mousedown:function(evt){//拖动开始
 evt = evt || window.event;
 x = evt.layerX || evt.offsetX;
 y = evt.layerY || evt.offsetY;
 document.body.appendChild(_clone);
 Snda.Utility.Event.addEventHandler(document,'mousemove',DragEvent.move,false);
 Snda.Utility.Event.addEventHandler(document,'mouseup',DragEvent.end,false);
 Snda.Utility.hide(root);
 return false;
 },
 clone:function(e,opacity){//克隆对象样式
 var _div = document.createElement('div');
 _div.$handle = o;
 _div.$root = root;
 _div.className = 'clone';
 _div.style.filter = 'alpha(opacity='+(opacity * 100)+')';
 _div.style.opacity = opacity;
 for(var i=0;i<_cloneItem.length;i+=1) _div.style[_cloneItem[i]]=Snda.Utility.getStyle(e,_cloneItem[i]);
 return _div;
 },
 end:function(evt){//结束拖动
 evt = evt || window.event;
 _clone.$temp && Snda.Utility.setX(_clone.$root,_clone.$temp.left).setY(_clone.$root,_clone.$temp.top);
 Snda.Utility.Event.removeEventHandler(document,'mousemove',DragEvent.move,false);
 Snda.Utility.removeNode(_clone).show(root);
 },
 compare:function(){//比较
 if(_clone.$minX != null) _clone.$temp.left = Math.max(_clone.$temp.left , _clone.$minX) + Snda.Utility.Postion.scrollX();
 if(_clone.$minY != null) _clone.$temp.top = Math.max(_clone.$temp.top , _clone.$minY) + Snda.Utility.Postion.scrollY(); 
 },
 move:function(evt){//移动
 evt = evt|| window.event;
 (function(left,top){
 _clone.$temp = {left:left,top:top};
 DragEvent.compare();
 Snda.Utility.setX(_clone,_clone.$temp.left).setY(_clone,_clone.$temp.top);
 })(evt.clientX- x ,evt.clientY- y )
 },
 zIndex:function(){//多窗体样式
 }
 };
 var _clone = DragEvent.clone(o.$Root,opacity);//克隆
 _clone.$minX	= typeof minX != 'undefined' ? minX : null;
 _clone.$minY	= typeof minY != 'undefined' ? minY : null;
 Snda.Utility.Event.addEventHandler(o,'mousedown',DragEvent.mousedown,false);
 }
 };
 Snda.QiDian={
 Tools:{
 Layer:{
 GoTo:function(name){
 var _name=_title='';
 switch(name.toLowerCase()){
 case 'reg': _name='/Pop/Login/RegDomain.aspx',_title='注册'; break;
 case 'login': _name='/Pop/Login/LoginDomain.aspx',_title='登录'; break;
 default: return false;
 };
 for(var i in Snda.Layer.Hash){
 document.getElementById('pop_frame_'+i).src=_name+'?rand='+i;
 document.getElementById('pop_title_'+i).innerHTML=_title;
 };
 },
 Close:function(){
 location.href=location.href;
 }
 }
 }
 };
Snda.QiDian.ReadChapter={//章节阅读页
 Config:{//配置信息
 login:'/Pop/BookReadPage/PopIndex.aspx',
 Tip:'/Pop/BookReadPage/PopTip.aspx',
 loginId:'popDiv_090910',
 frameId:'prpFrame_090910',
 frameHTML:"<iframe id=\"{0}\" frameborder=\"0\" scrolling=\"no\" src=\"{1}\" />"
 },
 spaceTime:10,//间隔时间
 CheckLogin:function(){//判断是否需要显示登入框
 var _login = GetCookie("cmfuToken");
 if(!_login){
 var _preDate = GetCookie("QiDianReadPageUnLogin");
 if(_preDate){
 var _startDate=new Date(Date.parse(_preDate.replace(/-/g,"/")));
 var _endDate=new Date();
 if(Math.floor((_endDate-_startDate)/(1000 * 60))>=Snda.QiDian.ReadChapter.spaceTime){//超过则显示
 SetCookie('QiDianReadPageUnLogin',new Date().format('yyyy-MM-dd hh:mm:ss'));
 Snda.QiDian.ReadChapter.Login(bookId);
 };
 }else{
 SetCookie('QiDianReadPageUnLogin',new Date().format('yyyy-MM-dd hh:mm:ss'));
 Snda.QiDian.ReadChapter.Login(bookId);
 };
 };
 },
 Disp:function(url){//显示或关闭
 var _o=document.getElementById(Snda.QiDian.ReadChapter.Config.loginId);
 if(_o) _o.parentNode.removeChild(_o);
 else{
 var _div=document.createElement('div');
 _div.id=Snda.QiDian.ReadChapter.Config.loginId;
 _div.className='readChapter_login';
 _div.style.left=Snda.QiDian.ReadChapter.GetLeft();
 _div.style.top=Snda.QiDian.ReadChapter.GetTop();
 _div.innerHTML=Snda.QiDian.ReadChapter.Config.frameHTML.Format(Snda.QiDian.ReadChapter.Config.frameId,url||'');
 document.body.appendChild(_div);
 document.getElementById(Snda.QiDian.ReadChapter.Config.frameId).scr=url+'&a=090910';
 Snda.QiDian.ReadChapter.FollowWin(_div);
 };
 },
 Login:function(bId){//显示登入框
 var _url=Snda.QiDian.ReadChapter.Config.login + '?bookid='+ bId+'&t='+Math.random();
 Snda.QiDian.ReadChapter.Disp(_url);
 },
 GetLeft:function(){
 return document.body.clientWidth/2 + Snda.QiDian.Utility.Postion.scrollX() - 160;
 },
 GetTop:function(){
 return Snda.QiDian.Utility.Postion.scrollY() + 220;
 },
 FollowWin:function(o){//滚动跟随
 var scollEvent=function(){
	 if(!o) return false;
	 o.style.left = Snda.QiDian.ReadChapter.GetLeft();
	 o.style.top = Snda.QiDian.ReadChapter.GetTop();
 }; 
 Snda.QiDian.Utility.Event.addEventHandler(window,'scroll',scollEvent,false);
 Snda.QiDian.Utility.Event.addEventHandler(window,'resize',scollEvent,false);
 Snda.QiDian.Utility.Event.addEventHandler(window,'load',scollEvent,false);
 },
 GoTo:function(name){//跳转地址
 var _f = document.getElementById(Snda.QiDian.ReadChapter.Config.frameId);
 var _path = Snda.QiDian.ReadChapter.Config[name];
 if(_f && _path) _f.src=_path+ '?bookid='+ bookId;
 }
};
})();
//part II
function document_onkeydown(){ document.focus(); document.onkeydown=pageEvent;};
function setBgColor(){ colorbg=getClientColor(); document.bgColor = colorbg;};
function showLogin(msg, registerUser){
 Snda.QiDian.Tools.Layer.GoTo('login');
};
function writeCSS(){
 var fontString="";
 fontString+="<style>#content{";
 fontString+= "font-size:"+ setFontSize()+"pt; color: black; line-height: 180%; padding-left: 30px; padding-right: 10px";
 fontString+="}</style>";
 return fontString;
};
function goNext(){ window.location.href=nextpage; return false; };
function IBWLoginCas(){
 var fulllink = window.location.href.toLowerCase();
 var curLink = fulllink.substring(fulllink.indexOf("com/")+4);
 if (curLink.indexOf('?')<=-1) curLink=curLink;
 else curLink =curLink.substring(0,curLink.indexOf("?"));
 if (ibw.userIsLogin && !checkLoginByCookie() && (GetCookie('ibwcas')==null || GetCookie('ibwcas').length==0)){
 SetCookie('ibwcas',curLink); 
 window.location.href="/casindex.aspx";
 };
};
function OnSelectText(event){ return false; };
function addBookMark(bookId,chapterId){
 if(!checkLoginByCookie())
 {
 Snda.Layer.Show({title:'登录',src:'/Pop/Login/LoginDomain.aspx',follow:true,move:true,callBack:function(){}});
 return false;
 }
 if(chapterId=='0') MyAjax.AddBookCase(bookId,ShowCallBack);
 else MyAjax.AddBookMark(bookId,chapterId,ShowCallBack);
 return false; 
};
function recomBook(bookId){ 
 if(!checkLoginByCookie()){
 Snda.Layer.Show({title:'登录',src:'/Pop/Login/LoginDomain.aspx',follow:true,move:true});
 return false;
 };
 if (enableCommendPopWin){
 Snda.Layer.Show({
 title:'我要投女生推荐票',
 src:'/BookReader/DivCommendBookTipping.aspx?bookId=' + bookId,
 follow:true,move:true,
 firstFun:function(){
 for(var i in Snda.Layer.Hash) document.getElementById('pop_cont_'+i).style.height='230px';
 }
});
if (event) {
 Snda.Utility.StopDefault(event);
}
return false;
 }else MyAjax.RecomBook(bookId, ShowCallBack);
 return false;
};

function ShowLoginDiv(callBack) {
 Snda.Layer.Show({
 title: '登录', src: '/Pop/Login/LoginDomain.aspx', follow: true, move: true, cSpeed: 5,
 callBack: callBack
 });
};

function CommendBook(bookId) {
 if (!checkLoginByCookie()) {
 ShowLoginDiv();
 return false;
 };
 if (enableCommendPopWin) {
 Snda.Layer.Show({
 title: '我要投推荐票', src: '/BookReader/DivCommendBookTipping.aspx?bookId=' + bookId, follow: true, move: true,
 firstFun: function() {
 for (var i in Snda.Layer.Hash) document.getElementById('pop_cont_' + i).style.height = '230px';
 }
 });
 } else MyAjax.RecomBook(bookId, ShowServerMessage);
}



function mobileAwake(bookId){ MyAjax.AddUpdateAwake(bookId ,ShowCallBack); return false; };
function monthVote(bookId){ MyAjax.MonthVote(bookId,ShowMonthVote); return false; };
function ShowMonthVote(res){
 if(res!=null){
 var returnValue = res.value.toLowerCase();
 if(! checkLogin(returnValue,"您还没有登录系统，或者登录已过期，请登录后再进行操作") ) {
 return;
 };
 if(returnValue.indexOf('vip') > -1){//非VIP用户 显示非VIP的消息提示窗体
 var obj = $("AddMark");
 $("MonthVoteTip").style.left = getPosition(obj).x - 360 + "px";
 $("MonthVoteTip").style.top = getPosition(obj).y - obj.offsetHeight + "px";
 $("MonthVoteTip").innerHTML = monthIframe;
 return;
 };
 if(returnValue.indexOf('成功') > -1) { //默认为VIP用户 显示VIP的消息提示窗体
 var obj = $("AddMark");
 $("MonthVoteTip").style.left = getPosition(obj).x - 360 + "px";
 $("MonthVoteTip").style.top = getPosition(obj).y - obj.offsetHeight + "px";
 $("MonthVoteTip").innerHTML = vipMonthIframe;
 $("VipMonthIframe").src="/BookReader/Tips/VipMonthVote.aspx?name=" + $("inputBookName").value + "&left=";
 };
 var value = returnValue.replace("\n","");
 try{eval(value);}catch(e){}; 
 };
};
function ShowCallBack(res){
 if(res!=null){
 var returnValue = res.value.toLowerCase();
 if(! checkLogin(returnValue,"您还没有登录系统，或者登录已过期，请登录后再进行操作") ) return;
 var value = returnValue.replace("\n","");
 try{eval(value);}catch(e){};
 };
};
function HideMonthIframe(){
 if($("monthIframe")) $("monthIframe").style.display="none";
 if($("VipMonthIframe")) $("VipMonthIframe").style.display="none";
};
function checkLogin(result,msg){//查看是否登录，未登录则弹出登录框
 if(result.indexOf("登录")>=0){
 showLogin(msg,true);
 return false; 
 };
 return true; 
};
function checkAuth(){
 if(checkLoginByCookie()) return true;
 else{
 showLogin(msg,true);
 return false; 
 }; 
};

function iframeFitHeight(oIframe) {
 try { 
 var oWin = oIframe.name ? window.frames[oIframe.name] : oIframe.contentWindow; 
 oIframe.style.height = oWin.document.body.scrollHeight + "px"; 
 }catch(e){};
};
function findLink(key){
	for( var k in keywords.list)
		if(	keywords.list[k].key==key) return	keywords.list[k];
};
function GetKeywords(){
	var pattern = "";
	for( var k in keywords.list) pattern+= keywords.list[k].key+"|";
	return pattern.substring(0,pattern.length-1);
};
function checkMatched(m){
	for(var i=0;i<matched.length;i++){
		if(matched[i]==m){
		 var num= Math.random();
		 var intNum=Math.round(num*10);
		 if(intNum==1|| intNum==3 || intNum==5|| intNum==8) return false;
			return true;
	 };
	};
	return false;
};
function capText(m){
 if(checkMatched(m)) return m;
 matched.push(m);
 var words=m;
 if(m=="www.cmfu.com") return "www.qidian.com";
 var dict = findLink(m);
 if(typeof dict.img !='undefined' && dict.img.length>0){ 
 var href= "<a class='bluelink' target='_blank' href='"+ dict.link +"' onmouseover=\"DelayShowDiv(this,'"+dict.link+"','"+dict.img+"')\" onmouseout='setTime();'>"+words+"</a>";
 return href; 
 };
 return "<a class='bluelink' target='_blank' href='"+ dict.link +"' >"+words+"</a>";
};
function AddUrl(text){ var regEx = new RegExp("(" + GetKeywords() + ")",'gim'); return text.replace(regEx, capText);};
function GetCode(){
 var mask="";
 for(var p=0;p<=16;p++){
 var rd = Math.round(Math.random()*code.length-1);
 if(rd<0) rd=0;
 mask+=code[rd];
 };
 return mask;
};
function closeTipsWin(){ document.getElementById("TipsWin").style.display="none";};
function checkInput(){
 var txtUserId = document.getElementById("txtUserName");
 var txtPassword = document.getElementById("txtPwd"); 
 if(txtUserId!=null ){
 if(txtUserId.value==null || txtUserId.value.length == 0){
 alert("请输入用户名");
 txtUserId.focus(); 
 return false; 
 };
 if(txtUserId.value.length>30){
 alert("您输入的用户名太长");
 return false; 
 };
 };
 if(txtPassword!=null ){
 if(txtPassword.value==null || txtPassword.value.length == 0){
 alert("请输入密码");
 txtPassword.focus(); 
 return false;
 };
 if(txtPassword.value.length>30){
 alert("您输入的密码太长");
 return false; 
 };
 };
 return true; 
};
function Login(){
 if(checkInput())
 MyAjax.LoginUserWithInfo($('txtUserName').value,$('txtPwd').value,$('txtToken').value, '123456',$('chbSaveCookie').checked,ShowLoginCallBack); 
};
function Logout(){ MyAjax.SignOut(ShowLogoutCallBack);};
function ShowLogoutCallBack(){
 $('divRight').style.display = '';
 $('divMidd').style.display = 'none'; 
 window.location.reload();
};
function __CheckLogin(){
 if(checkLoginByCookie()) MyAjax.CheckLoginWithInfo(ShowAutoLoginCallBask);
 else{
 var fromFriendId="";
 if (fromFriendId!=null & fromFriendId>0){
 $('btnMasterRegister').onclick=function MasterRegClick(){window.parent.location.href = readChapterDate.pathI + fromFriendId; }
 };
 $('divRight').style.display = '';
 $('divMidd').style.display = 'none';
 };
};
function ShowAutoLoginCallBask(result){ FullLoginInfo(result);}
function ShowLoginCallBack(result){
 if(result)
 if(result.value.Code != 0) alert(result.value.LoginMessage);
 else alert("登录成功！");
};
function FullLoginInfo(result){
 var retInfo = result.value;
 var messageCount = vip = 0;
 var NickName = userId = "";
 if(retInfo.Code == 0){
 messageCount = retInfo.MessageCount;
 NickName = retInfo.NickName;
 userId = retInfo.userId;
 vip=retInfo.VIP;
 $('divRight').style.display = 'none';
 $('divMidd').style.display = '';
 if(navigator.appName.indexOf("Explorer") > -1){ 
 $('spanNewMsgCount').innerText = messageCount;
 $('spanUserName').innerText = NickName; 
 }else{ 
 $('spanNewMsgCount').textContent = messageCount;
 $('spanUserName').textContent = NickName; 
 };
 if(messageCount != 0) setInterval("Spark()", 500);
 $('linkMySpace').href = readChapterDate.pathII+userId+".aspx";
 if(vip == '1' || vip == '2') $('divVIP').style.display = 'inline';
 if( typeof retInfo.IsThreeMonth!="undefined" && retInfo.IsThreeMonth ){//3个月未登录提示
 var IsTips = GetCookie("IsTips");
 if(IsTips!="1"){ 
 var divTop=document.body.clientHeight-330;
 var divLeft = document.body.clientWidth-355;
 var frame = "<div id='TipsWin' style='z-index: 999; position: absolute; filter: alpha(opacity=93); left: "+divLeft+"px; top: "+divTop+"px'><iframe id='TipsFrame' frameborder=no height='188' width='355' src='/BookReader/Tips/TipsUnLogin3Mon.aspx'></iframe></div>";
 $("divMidd").innerHTML+= frame;
 SetCookie("IsTips","1"); //记录弹出框是否已经弹出过
 };
 };
 }else{
 $('divRight').style.display = '';
 $('divMidd').style.display = 'none';
 };
};
var i_Spark = 0;
function Spark(){
 var obj = $('spanNewMsgCount');
 var color = "";
 switch(i){
 case 0:color = "red";break;
 case 1:color = "blue";break;
 };
 i_Spark +=1;
 obj.style.color = color;
 if(i_Spark >= 2) i_Spark = 0;
};
function TabSearch(){ if(event.keyCode === 13) go();};
function opwin(keywords,type){ window.open("http://sosu.qidian.com/search.aspx?k="+escape(keywords)+"&t="+type); };
function go(){
 var key = $("txtwords").value.replace(/</g, "").replace(/>/g, "");
 var index = $("searchtype").selectedIndex; 
 var type= $("searchtype").options[index].value; 
 if(key == null || key.length==0){
 alert("请输入搜索关键字"); 
 return false;
 }else if(type.indexOf('ft') != -1 && key.length < 2){
 alert("请输入2个或以上字符");
 return;
 };
 opwin(key,type);
};
function AlertUser(){
 if ($("chbSaveCookie").checked == true)
 if (!confirm("帐号保存一月，这台电脑所有用户都能使用您的帐号，请慎重考虑。\n\n并且，你不能再进行登录加分、宠物加爱心、藏书提示等功能。\n\n但，您可以通过每天退出登录一次来恢复使用上述功能。"))
 $("chbSaveCookie").checked=false;
 else Login();
};
function ClickLogin(evt){
 evt=evt||window.event;
 if(evt.keyCode == 13){
 enableEnter = false;
 evt.keyCode = 0;
 $("btnLogin").click();
 };
};
function CheckVipDiscount(){//VIP扶持
 if (typeof isDuringVipDiscount!='undefined'){
 var now=new Date();
 var isVipDiscountTips = GetCookie("isVipDiscountTips");
 if (isVipDiscountTips!=null){
 var lastRegDate=new Date(2008,06,10);
 var regtvalue=GetCookie("rt");
 if (regtvalue!=null){
 var arr=new Array();
 arr=regtvalue.substring(0,10).split("-"); 
 var regTime=new Date(arr[0],arr[1],arr[2]);
 if (regTime<=lastRegDate) MyAjax.DoVipDiscount(ShowVipDiscount)
 };
 };
 };
};
function ShowVipDiscount(result,content){
 var divTop=document.body.clientHeight-200;
 var divLeft = 0;
 var value=result.value;
 if (value=="1"){
 var frame = "<div id='VipPlanTipsWin' style='z-index: 998; position: absolute; filter: alpha(opacity=93); left: "+divLeft+"px; top: "+divTop+"px;'><iframe id='VipPlanTipsFrame' frameborder=no scrolling='no' width='225' src='/bookreader/tips/vipplanwarning.html'></iframe></div>";
 $("divMidd").innerHTML+= frame;
 }else if (value=="2"){
 var frame = "<div id='VipPlanTipsWin' style='z-index: 998; position: absolute; filter: alpha(opacity=93); left: "+divLeft+"px; top: "+divTop+"px'><iframe id='VipPlanTipsFrame' frameborder=no scrolling='no' width='235' src='/bookreader/tips/vipplansuccess.html'></iframe></div>";
 $("divMidd").innerHTML+= frame;
 };
};
function closeVipPlanTipsWin(){ document.getElementById("VipPlanTipsWin").style.display="none";};
function ShowGetUpdateChapterIdCallBack(result){
 if(result!=null && typeof(result)!=undefined){
 var arrResult=result.value.split("|");
 if(arrResult.length==2){
 var preChapterId=arrResult[0];
 var nextChapterId=arrResult[1];
 var menuPreLink=document.getElementById("menuPreLink");
 var menuNextLink=document.getElementById("menuNextLink");
 var spanPreLink=document.getElementById("spanPreLink");
 var spanNextLink=document.getElementById("spanNextLink");
 if(preChapterId!=0){
 if(menuPreLink!=null && typeof(menuPreLink)!=undefined)
 menuPreLink.href="/bookReader/"+bookId+","+preChapterId+".aspx";
 if(spanPreLink!=null && typeof(spanPreLink)!=undefined)
 spanPreLink.innerHTML="<a href=/bookReader/"+bookId+","+preChapterId+".aspx >上一页</a>";
 };
 if(nextChapterId!=0){
 if(menuNextLink!=null && typeof(menuNextLink)!=undefined)
 menuNextLink.href="/bookReader/"+bookId+","+nextChapterId+".aspx";
 if(spanNextLink!=null && typeof(spanNextLink)!=undefined)
 spanNextLink.innerHTML="<a href=/bookReader/"+bookId+","+nextChapterId+".aspx >下一页</a>";
 };
 };
 };
};

function ReplaceBookHref(article) {
 var _bookNameHtml = '<a style="color:#0000ff" href="/book/$1.aspx" target="_blank">$2</a>'
 var bookInfoRegex = /\[\s*bookid\s*=\s*(\d*)\s*,\s*bookname\s*=\s*(《[^》]*》)]/i;
 var arrMactches = bookInfoRegex.exec(article);
 while (arrMactches != null) {
 article = article.replace(bookInfoRegex, _bookNameHtml.format(arrMactches[1], arrMactches[2]));
 arrMactches = bookInfoRegex.exec(article);
 }
 return article;
};

function ScrollDiv() { return false; };
 
function ShowTippingDiv() {Snda.Layer.Show({ title: '我要打赏', src: '/BookReader/DivAuthorTipping.aspx?bookId=' + bookId + "&authorId=" + authorId + "&authorName=" + authorName, follow: true, move: true, callBack: function() { } });return false;};