/*cmfu main javascript*/ var domainName = '.qidian.com',tophref,thishref; try{ thishref=this.location.href; tophref=top.location.href; }catch(e){}; if(this != top && tophref!=null && tophref.indexOf("localhost") < 0 || thishref!=null && thishref.indexOf("localhost") < 0){ try{ if(this != top && tophref.indexOf("qidian.com") < 0 && tophref.indexOf("qidianmm.com") < 0 && tophref.toLowerCase().indexOf("qdmm.com") < 0 && tophref.indexOf("cache.baidu.com") < 0) top.location.href="http://www.qidian.com";}catch(e){}; if(this.location.href.toLowerCase().indexOf("qidian.com") < 0) top.location.href="http://www.qidian.com/Default.aspx"; } if (document.location.host.toLowerCase().indexOf("qidian.com")>0){document.domain = "qidian.com";} else if (document.location.host.toLowerCase().indexOf("qidianmm.com")>0){document.domain = "qidianmm.com";} else if (document.location.host.toLowerCase().indexOf("qdmm.com")>0){document.domain = "qdmm.com";} else if (document.location.host.toLowerCase().indexOf("qdwenxue.com")>0){document.domain = "qdwenxue.com";} String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.trimEnd = function(trimString){ var re = new RegExp(trimString+"*$","g");return this.replace(re, "");}; String.prototype.len=function(){ return this.replace(/[^\x00-\xff]/g,'aa').length; }; function StringBuilder(value){ this.strings = new Array(""); this.append(value);}; StringBuilder.prototype.append = function(value){ if(value) this.strings.push(value);}; StringBuilder.prototype.clear = function (){ this.strings.length = 1;} StringBuilder.prototype.toString = function (){ return this.strings.join("");} if (!String._FORMAT_SEPARATOR){ String._FORMAT_SEPARATOR = String.fromCharCode(0x1f); String._FORMAT_ARGS_PATTERN = new RegExp('^[^' + String._FORMAT_SEPARATOR + ']*'+ new Array(100).join('(?:.([^' + String._FORMAT_SEPARATOR + ']*))?')); }; if (!String.format){ String.format = function (s){ return Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR).replace(String._FORMAT_ARGS_PATTERN, s);}; }; if (!''.format){ String.prototype.format = function (){ return (String._FORMAT_SEPARATOR +Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR)).replace(String._FORMAT_ARGS_PATTERN, this); }; }; function checkLoginByCookie(){ var cookieId="AUTHTEST"; if(window.location.href.toLowerCase().indexOf("qidian.com") > -1 || window.location.href.toLowerCase().indexOf("qidianmm.com") > -1 || window.location.href.toLowerCase().indexOf("qdmm.com") > -1) cookieId="cmfuToken"; if((GetCookie(cookieId)!=null && GetCookie(cookieId).length > 0 )) return true; return false; }; function getUrlParam(a){var b=new RegExp("(^|&)"+a+"=([^&]*)(&|$)","i");var r=window.location.search.substr(1).match(b);if(r!=null)return unescape(r[2]);else return null}; function $(a){if(document.getElementById)return document.getElementById(a);else if(document.layers)return eval("document.layers['"+a+"']");else return eval('document.all.'+a)}; function eventBind(a,b,c){if(a.addEventListener)a.addEventListener(b,c,false);else if(a.attachEvent)a.attachEvent("on"+b,c)}; function DateAdd(a,b,c){var d=new Date(a.replace("-",","));var e=1;var f=e*1000;var g=f*60;var h=g*60;var i=h*24;var j=i*365;var k;var l=new Date(d);var l=l.valueOf();switch(c){case"ms":k=new Date(l+e*b);break;case"s":k=new Date(l+f*b);break;case"mi":k=new Date(l+g*b);break;case"h":k=new Date(l+h*b);break;case"d":k=new Date(l+i*b);break;case"y":k=new Date(l+j*b);break;default:return escape("日期格式不对")};k=new Date(k);return k.getFullYear()+"-"+(k.getMonth()+1)+"-"+k.getDate()}; Date.prototype.AddDays=function(a){var b=this;var c=1;var d=c*1000;var e=d*60;var f=e*60;var g=f*24;var h=g*365;var i;var j=new Date(b);var j=j.valueOf();i=new Date(j+g*a);i=new Date(i);return i}; function SetCookie(name, value) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2 && argv[2] != null) ? argv[2].toGMTString() : (new Date()).AddDays(30).toGMTString(); var path = (argc > 3 && argv[3] != null) ? argv[3] : '/'; var domain = (argc > 4 && argv[4] != null) ? argv[4] : null; var secure = (argc > 5 && argv[5] != null) ? argv[5] : false; var content = name + "=" + escape(value) + ";"; if (expires != null) { content += " expires=" + expires + ";"; } if (path != null) { content += " path=" + path + ";"; } if (domain != null) { content += " domain=" + domain + ";"; } if (secure) { content += " secure;" } document.cookie = content; } function GetCookie(cookieName) { var cookieString = document.cookie; var start = cookieString.indexOf(cookieName + '='); if (start == -1) return null; // 加上等号的原因是避免在某些 Cookie 的值里有与cookieName一样的字符串 start += cookieName.length + 1; var end = cookieString.indexOf(';', start); if (end == -1) return unescape(cookieString.substring(start)); return unescape(cookieString.substring(start, end)); }; SetCookie.sName='_qd_s'; SetCookie.session=function(name,value,domain){ var i,_name=SetCookie.sName,_s=GetCookie(_name),_d={},_sA=[],_str=''; try{_s && (_d=eval(_s))}catch(e){ throw {code:-1,msg:'格式化出错'}}; _d[name]=encodeURIComponent(value); _str+=_name+'='; _sA.push('({'); for(i in _d){ _sA.push(i); _sA.push(':"'); _sA.push(_d[i]); _sA.push('"'); _sA.push(','); }; if(_sA.length>2) _sA.pop(); _sA.push('})'); _str+=encodeURIComponent(_sA.join(''))+';path=/;' if(domain) _str+=(domain); document.cookie = _str; return SetCookie.session; }; GetCookie.session=function(name){ var _name=SetCookie.sName,_s=GetCookie(_name),_d={}; if(_s){ try{ _d=eval(_s);}catch(e){} return decodeURIComponent(_d[name]); }; return _s; }; function GetAdSettingCookie(cookieName){//获取广告条件cookie 有汉字避免乱码 var cookieString = document.cookie; var start = cookieString.indexOf(cookieName + '='); if (start == -1) return null; start += cookieName.length + 1; var end = cookieString.indexOf(';', start); if (end == -1) return decodeURIComponent(cookieString.substring(start)); return decodeURIComponent(cookieString.substring(start, end)); }; function ShowConditionAd(conditionId,notConditionId,adType,areaList,channelIdList,bookIdList,sex,startAge,endAge,vip) {//显示条件广告逻辑---符合条件广告设置的条件显示否则显示下一个广告 var showConditionAd=false,cSettings; var adCookieValue=GetAdSettingCookie("userInfoForAd"); if(typeof(adCookieValue)!='undefined' && adCookieValue!=null){ cSettings=adCookieValue.split(",");//区域、性别、年龄、是否vip if(cSettings.length==4){ if((areaList=='无' || areaList.indexOf(cSettings[0])>=0) && (sex=='无' || sex==cSettings[1]) && ((startAge==0 && endAge==0) || (endAge>cSettings[2] && startAge<=cSettings[2])) && (vip==-1 || vip==cSetting[3])){ showConditionAd=true; }; }; }; if(typeof(JChannelId)!='undefined'){ if(channelIdList!='无' && channelIdList.indexOf(JChannelId)>=0) showConditionAd=true; }; if(typeof(JBookId)!='undefined'){ if(bookIdList!='无' && bookIdList.indexOf(JBookId)>=0) showConditionAd=true; }; if(adType==1){//弹窗广告 var objName; if(showConditionAd==true) objName="QidianBackPop"+conditionId;//显示条件广告 else objName="QidianBackPop"+notConditionId; ExcutePop(objName);//在admanager.cs 426行定义 }else{ if(showConditionAd==true){//显示条件广告 document.getElementById(conditionId).style.display=""; document.getElementById(notConditionId).style.display="none"; }else{ document.getElementById(conditionId).style.display="none"; document.getElementById(notConditionId).style.display=""; }; }; }; function TextBoxOnFocus(txtControl,strDefaultText){ if (txtControl.value==strDefaultText) txtControl.value=""; };//文本框得到焦点 function TextBoxOnBlur(txtControl,strDefaultText){ if (txtControl.value.replace(/(^[\s]*)|([\s]*$)/g,"")=="") txtControl.value=strDefaultText;}; //文本框失去焦点 function GetCurrentRawUrl(){//获取当前请求的相对路径 var retUrl= document.location.href,retDomain=document.location.host; retUrl=retUrl.replace(retDomain,""); retUrl=retUrl.replace("http://",""); return escape(retUrl); }; function MultiSendWin(subject,content){//弹出群发消息窗口 var win =window.open(uploadURL+"?subject=" + subject + "&content=" +content,"","menubar=no,width=480,height=550,resizeable=no",""); return false; }; function ShowServerMessage(result){ try{eval(result.value);}catch(e){}; }; function KeydownSubmitForm(btnId){//回车提交表单 var btn=document.getElementById(btnId); if (btn!=null&& event.keyCode== 13){ event.returnValue=false; event.keyCode=9; btn.click(); }; }; function MDown(Object){//ReadChapter -抵用券js Obj=Object.id; document.all(Obj).setCapture(); pX=event.x-document.all(Obj).style.pixelLeft; pY=event.y-document.all(Obj).style.pixelTop; }; function MMove(){ if(Obj!=''){ document.all(Obj).style.left=event.x-pX; document.all(Obj).style.top=event.y-pY; }; }; function MUp(){ if(Obj!=''){ document.all(Obj).releaseCapture(); Obj=''; };}; function LayerClose(divDiscount){ document.getElementById(divDiscount).style.visibility="hidden"; };//关闭抵用券信息 function LayerShow(divDiscount,discountPrize){/*显示抵用券信息*/ var prizeUI = document.getElementById(divDiscount); prizeUI.style.left = screen.width-530; prizeUI.style.top = screen.Height - 480; prizeUI.style.visibility="visible"; document.getElementById("lblPrize1").innerHTML=document.getElementById("lblPrize2").innerHTML=discountPrize; window.setInterval("LayerClose('" + divDiscount + "')",15000); }; function HideMenu(menuid){//帮助masterpage用 var obj = document.getElementById(menuid); if(obj.style.display == "none") obj.style.display = ""; else obj.style.display = "none"; if(obj.style.display == ""){ var tmpId = "M0"; for(var i =1 ;i<= 9; i++){ var myid = tmpId + i; if(myid != menuid) document.getElementById(myid).style.display = "none"; }; }; }; function ShowLoginDiv() { top.window.location.href='http://me.qidian.com/Login.aspx?ReturnUrl='+encodeURIComponent(location.href);}; function $$echo(msg){ try{ console.log(msg);}catch(e){} }; function HideLoginMask() { $("DivMask").style.display = "none"; $("DivLogin").style.display = "none";}; function ScrollDiv() {//随屏幕滚动 var eDivLogin = $("DivLogin"); var eAddMark = $("AddMark"); var eDivMask = $("DivMask"); var eLoginBar = $("LoginBar"); var eMonthVoteTip = $("MonthVoteTip"); var eVipPlanTipsWin = $("VipPlanTipsWin"); if (eDivLogin) { var offsetHeight,offsetWidth; if (typeof DivLoginoffsetHeight != 'undefined') offsetHeight = DivLoginoffsetHeight; else offsetHeight = eDivLogin.clientHeight; if (typeof DivLoginoffsetWidth != 'undefined') offsetWidth = DivLoginoffsetWidth; else offsetWidth = eDivLogin.clientWidth; eDivLogin.style.top = ((document.documentElement.scrollTop + document.body.scrollTop) +(document.documentElement.clientHeight - offsetHeight) / 2) + "px"; eDivLogin.style.left = ((document.documentElement.scrollLeft + document.body.scrollLeft) +(document.documentElement.clientWidth - offsetWidth) / 2) + "px"; }; if (eLoginBar) { eLoginBar.style.top = (document.body.scrollTop +(document.body.clientHeight - eLoginBar.offsetHeight) - 3) + "px"; eLoginBar.style.left = (-3) + "px"; eLoginBar.style.width = (document.body.clientWidth - 2) + "px"; document.body.focus(); }; if (eAddMark) { eAddMark.style.top = document.body.clientHeight + document.body.scrollTop - 200; eAddMark.style.left = document.body.clientWidth - 56; eAddMark.style.display = ''; if (eMonthVoteTip) eMonthVoteTip.style.top = (getPosition(eAddMark).y - eAddMark.offsetHeight) + "px"; }; if (eVipPlanTipsWin) eVipPlanTipsWin.style.top = (document.body.clientHeight + document.body.scrollTop - 200) + 'px'; }; function AutoScroll() { eventBind(window, 'load', ScrollDiv); eventBind(window, 'resize', ScrollDiv); eventBind(window, 'scroll', ScrollDiv); }; function getPosition(a){for(var b=0,ly=0;a!=null;b+=a.offsetLeft,ly+=a.offsetTop,a=a.offsetParent);return{x:b,y:ly}}; function subString(a,b,c){var d=0,newStr="",chineseRegex=/[^\x00-\xff]/g,singleChar="";var e=a.replace(chineseRegex,"**").length;for(var i=0;ib)break;newStr+=singleChar};if(c&&e>b)newStr+="...";return newStr}; function GetStringLength(strObj){ return strObj.replace(/[^\x00-\xff]/g,"**").length; }; function addMark(title,url) { try{ if (window.sidebar&&window.sidebar.addPanel) window.sidebar.addPanel(title, url,""); else if( document.all&&window.external.AddFavorite) window.external.AddFavorite( url, title); else{alert("抱歉,您所使用的浏览器无法完成此操作。\n\n加入收藏失败,请使用Ctrl+D进行添加");return true;} }catch(e){alert("您的浏览器安全设置不允许该项操作");} }; function AdLinkAct(a){try{var b=GetCookie("rk");if(b!=null&&b!="")MyAjax.UseAdLinkView(a,AfterUseAdLinkView)}catch(e){}}; function AfterUseAdLinkView(result){}; var __matchedforbid = []; function capForbidText(m){__matchedforbid.push(m);return '□';} function ReplaceForbidKeyword(text){ if (typeof __forbidKeywords == 'undefined' || __forbidKeywords == null || __forbidKeywords =="") return text; var regEx = new RegExp("("+unescape(__forbidKeywords)+")","gim"); return text.replace(regEx, capForbidText); }; function CheckUserIP(){ return true;/*暂时不用*/ var value; var curIP=GetCookie("cui"); if (curIP==null || curIP==""){ if (typeof MyAjax!="undefined") MyAjax.GetUserIP(SetUserIP); return false; }; value=parseInt(curIP)%16777216; value=parseInt(value)-parseInt(value) % 65536; value=parseInt(value)/65536; return true; }; function SetUserIP(res){ var value=res.value; var arr=new Array(); var cookieValue; var nextHour = new Date(); if (nextHour.getHours()<23) nextHour.setHours(nextHour.getHours() + 1); else nextHour.setDate(nextHour.getDate() + 1); if (value!=null && value!=""){ arr=value.split("."); if (arr.length>=4){ cookieValue=parseInt(arr[0]) * 16777216 + parseInt(arr[1]) * 65536 + parseInt(arr[2]) * 256 + parseInt(arr[3]); SetCookie("cui",cookieValue,nextHour); }; }; }; function ReplaceUnsafeKeyword(text){//替换不安全的字符 var unsafeString; var regEx = new RegExp("("+unsafeString+")","gim"); unsafeString="&#\\d+"; regEx = new RegExp("("+unsafeString+")","gim"); return text.replace(regEx, function ($1){return "&#"+$1.substring(2);}); }; function AttachScriptAd(adPublishId){ var obj = document.getElementById("div_"+adPublishId); if (obj==null) return; if(window.addEventListener) obj.addEventListener("click", MyAjax.SendAdClick(adPublishId,null), false); else obj.attachEvent("onclick", function() {MyAjax.SendAdClick(adPublishId,null);}); }; var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]; var FFextraHeight=getFFVersion>=0.1? 16 : 0; function dyniframesize(iframename) { var pTar = null; if (document.getElementById) pTar = document.getElementById(iframename); else eval('pTar = ' + iframename + ';'); if (pTar && !window.opera){ pTar.style.display="block"; if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) pTar.height = pTar.contentDocument.body.offsetHeight+FFextraHeight; else if (pTar.Document && pTar.Document.body.scrollHeight) pTar.height = pTar.Document.body.scrollHeight; else{}; }; }; function showPMD(a, b, c, d) { var e = $(c); e.innerHTML = a[b]; if (b + 1 >= a.length) b = 0; else b++; function startNext() { showPMD(a, b, c, d) }; setTimeout(startNext, d) }; /*temp bookshelf begin */ var enableTempBookshelf = true; /*add*/ function tbsAddBook(bookId,bookName){ if(!window.enableTempBookshelf)return false; var _cookieName = 'tbsb'; var tbsBooks = GetCookie(_cookieName); var addValue = bookId+'|'+bookName; if (tbsBooks == null || tbsBooks.trim().length === 0) {/*cookie 空*/ SetCookie(_cookieName,addValue, (new Date()).AddDays(30), "/", document.domain); tbsShowMsgPop(2,'本书已成功加入书架中。'); tbsLoadBookshelf(); }else{ var tbsBooksArr = tbsBooks.split(';'); if (tbsBooksArr.length >= 5) { tbsShowMsgPop(1,'书架满啦,注册 或 登录 后即可获得超大容量书架,还可保存当前书架内的所有作品。');} else { var _booksLen = tbsBooksArr.length; var _isAdded = false; for(var i=0;i<_booksLen;i++){ if(tbsBooksArr[i].indexOf(bookId+'|') > -1) { _isAdded = true;break; } } if(_isAdded){tbsShowMsgPop(3,'本书已在您的书架,无需重复添加。'); }else{ SetCookie(_cookieName, tbsBooks+';'+addValue, (new Date()).AddDays(30), "/", document.domain); tbsShowMsgPop(2,'本书已成功加入书架中。'); }; tbsLoadBookshelf(); }; } return false; }; function tbsShowMsgPop(type,msg){ if(Snda && Snda.Layer && Snda.Layer.Show){ var popHeight = 122; var popWidth = 400; Snda.Layer.Show({ title: '加入书架', src: '/Pop/Tips/ShowMessage.php?type=' + type, follow: true, panel: 'p3', cSpeed: 0, callBack: function() { }, firstFun: function() { for (var i in Snda.Layer.Hash) {var o = $('pop_cont_' + i); o.style.width = popWidth+'px';o.style.height = popHeight+'px'; o.firstChild.style.height = (popHeight-2)+'px'; o.firstChild.style.overflow = 'hidden'; }} }); }else{ alert(msg); } } /*delete*/ function tbsDeleteBook(bookId){ if(!window.enableTempBookshelf)return false; var _cookieName = 'tbsb'; var tbsBooks = GetCookie(_cookieName); if (tbsBooks != null && tbsBooks.trim().length > 0) { var tbsBooksArr = tbsBooks.split(';'); var _booksLen = tbsBooksArr.length; var _isDelete = false; for(var i=0;i<_booksLen;i++){ if(tbsBooksArr[i].indexOf(bookId+'|') > -1){ _isDelete = true; tbsBooksArr.splice(i,1); break; } } if(_isDelete){ SetCookie(_cookieName, tbsBooksArr.join(';'), (new Date()).AddDays(30), "/", document.domain); tbsLoadBookshelf(); } } return false; } /*load*/ function tbsLoadBookshelf(){ if(!window.enableTempBookshelf)return false; var _objShowList = document.getElementById('tbsBookListShowInfo'); var _objShowTxt = document.getElementById('tbsBNShowTxt'); var _booksLen = 0; var _bookListHTML = ''; if(_objShowList){ var tbsBooks = GetCookie('tbsb'); if (tbsBooks != null && tbsBooks.trim().length > 0) { var tbsBooksArr = tbsBooks.split(';'); var _bookListHTMLTP = "
  • 下架\"{1}\"{1}
  • "; _booksLen = tbsBooksArr.length; for(var i=0;i<_booksLen;i++){ var _bookInfo = tbsBooksArr[i].trim(); if(_bookInfo.length>0){ var _bookInfoArr = _bookInfo.split('|'); if(_bookInfoArr.length>1){ _bookListHTML+=_bookListHTMLTP.Format(_bookInfoArr[0],_bookInfoArr[1]).replace('data-url', 'src'); } } } } if(_bookListHTML.trim().length == 0) _bookListHTML = "
  • 您的书架没有任何作品!
  • "; _objShowList.innerHTML = _bookListHTML; } if(_objShowTxt){ _objShowTxt.innerHTML = "您的书架("+_booksLen.toString()+"/5)"; } }; /*temp bookshelf end */