function SBuilder(value) { this.strings = new Array(""); this.append(value); } SBuilder.prototype.append = function(value) { if (value) this.strings.push(value); return this; } SBuilder.prototype.toString = function() { return this.strings.join(""); } /* cmfu main javascript */ var domainName = '.qidian.com'; if (document.location.href.toLowerCase().indexOf("qidianmm.com")>0) { document.domain = "qidianmm.com"; } if (document.location.href.toLowerCase().indexOf("qdmm.com")>0) { document.domain = "qdmm.com"; } if (document.location.href.toLowerCase().indexOf("qidian.com")>0) { document.domain = "qidian.com"; } //try //{alert(top.location.href);}catch(e) //{alert(e.message);} var tophref,thishref; try { tophref=top.location.href.toLowerCase(); thishref=this.location.href.toLowerCase(); } catch(e){} if(this != top && tophref!=null && tophref.indexOf("localhost") < 0 || thishref!=null && thishref.indexOf("localhost") < 0 || top.location.href.toLowerCase().indexOf("qidianmm.com") < 0 || top.location.href.toLowerCase().indexOf("qdmm.com") < 0) { try { if(this != top && top.location.href.toLowerCase().indexOf("qidian.com") < 0 && top.location.href.toLowerCase().indexOf("qidianmm.com") < 0 && top.location.href.toLowerCase().indexOf("qdmm.com") < 0) top.location.href="http://www.qidian.com"; } catch(e){} if(this.location.href.toLowerCase().indexOf("qidian.com") < 0 && top.location.href.toLowerCase().indexOf("qidianmm.com") < 0 && top.location.href.toLowerCase().indexOf("qdmm.com") < 0) top.location.href="http://www.qidian.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; } //cmfu main javascript String.prototype.cformat = function() { var str = this; for (var i = 0; i < arguments.length; i++) { var re = new RegExp('\\{' + (i) + '\\}', 'gm'); str = str.replace(re, arguments[i]); } return str; } function StringBuilder(value) { this.strings = new Array(""); this.append(value); } /* Appends the given value to the end of this instance. */ StringBuilder.prototype.append = function(value) { if (value) { this.strings.push(value); } } /* Clears the string buffer */ StringBuilder.prototype.clear = function() { this.strings.length = 1; } /* Converts this instance to a String. */ StringBuilder.prototype.toString = function() { return this.strings.join(""); } //string format prototype // sample: var test="my name is {0} {2} " ; // alert(test.format('liang','zhonghua'); 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); } } /*end string format*/ function checkLoginByCookie() { var cookieId="AUTHTEST"; if(window.location.href.toLowerCase().indexOf("qidian.com") > -1) { cookieId="cmfuToken"; } if(window.location.href.toLowerCase().indexOf("qidianmm.com") > -1) { cookieId="cmfuToken"; } if(window.location.href.toLowerCase().indexOf("qdmm.com") > -1) { cookieId="cmfuToken"; } if((GetCookie(cookieId)!=null && GetCookie(cookieId).length > 0 )) { return true; } else { if(GetCookie('cmfu_al') != null && GetCookie('cmfu_al').length > 0) { return true; } } return false; } function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } else { return null; } } function CheckPostFromCookie(urlPara, sepSecond, curContent) { var curForumId = getUrlParam(urlPara); var forumId = GetCookie(urlPara); //alert(curForumId + "_" + forumId); if (forumId != null && curForumId != null && forumId == curForumId) { var curTime = new Date(); var lastTime = new Date(GetCookie("pTime")); if (parseInt(Math.abs(curTime - lastTime) / 1000) <= sepSecond) { alert("您发帖速度太快了, 先休息一会吧."); return false; } // var content = GetCookie("content"); // if(curContent.substring(0, 12) == content) // { // alert("不能发表重复帖!"); // return false; // } } return true; } function SetPostCookie(urlPara, curContent) { var urlParaValue = getUrlParam(urlPara); //alert(urlPara + "_" + urlParaValue); SetCookie(urlPara, urlParaValue); SetCookie('pTime', new Date()); SetCookie("content", curContent); } function $(objName) { if (document.getElementById) { return document.getElementById(objName); } else if (document.layers) { return eval("document.layers['" + objName + "']"); } else { return eval('document.all.' + objName); } } //事件多播绑定代码 function eventBind(elem, eventName, handler){ if (elem.addEventListener) { elem.addEventListener(eventName, handler, false); } else if (elem.attachEvent) { elem.attachEvent("on" + eventName, handler); } } function DateAdd(BaseDate, interval, DatePart) { var dateObj = new Date(BaseDate.replace("-",",")); var millisecond=1; var second=millisecond*1000; var minute=second*60; var hour=minute*60; var day=hour*24; var year=day*365; var newDate; var dVal = new Date(dateObj) var dVal=dVal.valueOf(); switch(DatePart) { case "ms": newDate=new Date(dVal+millisecond*interval); break; case "s": newDate=new Date(dVal+second*interval); break; case "mi": newDate=new Date(dVal+minute*interval); break; case "h": newDate=new Date(dVal+hour*interval); break; case "d": newDate=new Date(dVal+day*interval); break; case "y": newDate=new Date(dVal+year*interval); break; default: return escape("日期格式不对"); } newDate = new Date(newDate); return newDate.getFullYear() + "-" + (newDate.getMonth() + 1) + "-" + newDate.getDate() ; } /*Add Current Days*/Date.prototype.AddDays=function (interval) { var dateObj = this; var millisecond=1; var second=millisecond*1000; var minute=second*60; var hour=minute*60; var day=hour*24; var year=day*365; var newDate; var dVal = new Date(dateObj); var dVal=dVal.valueOf(); newDate=new Date(dVal+day*interval); newDate = new Date(newDate); return newDate; } function SetCookie(name, value) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2].toGMTString() : null; var path = (argc > 3) ? argv[3] : "/"; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; var content = name + "=" + escape(value) + ";"; if (expires != null) { content += " expires=" + expires + ";"; } if (path != null) { content += " path=" + path + ";"; } if (domain != null) { domain += " domain=" + domain + ";"; } if (secure != null) { secure += " secure=" + secure + ";" } document.cookie = content; } function GetCookie(cookieName) { var cookieString = document.cookie; var start = cookieString.indexOf(cookieName + '='); // 加上等号的原因是避免在某些 Cookie 的值里有 // 与 cookieName 一样的字符串。 if (start == -1) // 找不到 return null; start += cookieName.length + 1; var end = cookieString.indexOf(';', start); if (end == -1) return unescape(cookieString.substring(start)); return unescape(cookieString.substring(start, end)); } //获取广告条件cookie 有汉字避免乱码 function GetAdSettingCookie(cookieName) { 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; var adCookieValue=GetAdSettingCookie("userInfoForAd"); var cSettings; 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; } /*功能:弹出上传头像窗口*/ //clientImageId:父页面Image控件的Id号 //logoDomainUrl:图片域名服务器地址 //uploadDir:上传图片Directory //clientHddImageId:父页面Hidden控件的Id号 //realImgeName:上传图片的文件名 function UploadImage(clientImageId, logoDomainUrl, uploadDir, clientHddImageId, realImgeName) { var win = window.open(uploadURL + "?clientImageId=" + clientImageId + "&imageurl=" + logoDomainUrl + "&uploadUrl=" + uploadDir + "&clientHddImageId=" + clientHddImageId + "&imagename=" + document.getElementById(clientHddImageId).value + "&realimagename=" + realImgeName, "", "menubar=no,width=450,height=240,resizeable=no", ""); return false; } /*功能:关闭上传头像窗口后,改变父页面clientImageId的图片路径*/ function ChangeImage(clientImageId, imageUrl, newImageName, clientHddImageId) { if (newImageName != null) { var number = Math.random(); document.getElementById(clientImageId).src = imageUrl + newImageName + "?" + number; document.getElementById(clientHddImageId).value = newImageName; } } //获取当前请求的相对路径 function GetCurrentRawUrl() { var retUrl= document.location.href; var 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 Invite2ClubWin(nickName) { var win = window.open(invite2ClubURL + "?nickName=" + nickName, "", "menubar=no,width=500,height=400,resizeable=no", ""); return false; } /*功能:弹出留言窗口*/ function SpaceSendMsg(toUserId) { var win = window.open(spaceSendMsgURL + "?toUserId=" + toUserId, "", "menubar=no,width=500,height=400,resizeable=no", ""); return false; } /* Add By XuJian 2007-11-02 */ /*热评区滚动文字*/ function startmarquee(lh, speed, delay) { var p = false; var t; var o = document.getElementById("marqueebox"); o.innerHTML += o.innerHTML; o.style.marginTop = 0; o.onmouseover = function() { p = true; } o.onmouseout = function() { p = false; } function start() { t = setInterval(scrolling, speed); if (!p) o.style.marginTop = parseInt(o.style.marginTop) - 1 + "px"; } function scrolling() { if (parseInt(o.style.marginTop) % lh != 0) { o.style.marginTop = parseInt(o.style.marginTop) - 1 + "px"; if (Math.abs(parseInt(o.style.marginTop)) >= o.scrollHeight / 2) o.style.marginTop = 0; } else { clearInterval(t); setTimeout(start, delay); } } setTimeout(start, delay); } /*隐藏显示控件*/ function HideObject(obj) { $(obj).style.display = "none"; } function ShowObject(obj) { $(obj).style.display = ""; } function IsHide(obj) { if ($(obj).style.display == "") { return false; } else if ($(obj).style.display == "none") { return true; } } function ShowServerMessage(result) { eval(result.value); } /*回车提交表单*/ function KeydownSubmitForm(btnId) { var btn=document.getElementById(btnId); if (btn!=null&& event.keyCode== 13) { event.returnValue=false; event.keyCode=9; btn.click(); } } /*ReadChapter -抵用券js*/ function MDown(Object){ 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=discountPrize; document.getElementById("lblPrize2").innerHTML=discountPrize; window.setInterval("LayerClose('" + divDiscount + "')",15000); } /*帮助masterpage用*/function HideMenu(menuid) { 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"; } } } } /* div login */ /*function ShowLoginDiv() { var builder = new StringBuilder(); builder.append(""); builder.append(""); builder.append(""); builder.append(""); builder.append(""); builder.append(""); builder.append(""); builder.append(""); builder.append("
"); builder.append("登录"); builder.append(""); builder.append("×"); builder.append("
"); builder.append(""); builder.append("
"); //window.top.scrollTo(0,0); var eDivMask = $("DivMask"); var eDivLogin = $("DivLogin"); if(document.body.clientHeight>document.body.scrollHeight) eDivMask.style.height = document.body.clientHeight + "px"; else eDivMask.style.height = document.body.scrollHeight + "px"; eDivMask.style.width = document.body.scrollWidth + "px"; eDivMask.style.display = 'block'; eDivLogin.style.display = "block"; eDivLogin.innerHTML = builder.toString(); ScrollDiv(); eventBind(window, 'load', ScrollDiv); eventBind(window, 'resize', ScrollDiv); eventBind(window, 'scroll', ScrollDiv); }*/ function ShowLoginDiv() { var strTable = ""; strTable+=""; strTable+=""; strTable+=""; strTable+=""; strTable+=""; strTable+=""; strTable+=""); builder.append(""); builder.append("
"; strTable+="登录"; strTable+=""; strTable+="×"; strTable+="
"; strTable+=""); builder.append("
"); //window.top.scrollTo(0,0); document.getElementById("DivMask").style.height = document.body.scrollHeight; document.getElementById("DivMask").style.width = document.body.scrollWidth; document.getElementById("DivMask").style.display = 'block'; document.getElementById("DivLogin").style.display = "block"; document.getElementById("DivLogin").innerHTML = builder.toString(); ScrollDiv(); window.onscroll = ScrollDiv; window.onresize = ScrollDiv; window.onload = ScrollDiv; } 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; var 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) { // if(!event ) // return; eAddMark.style.top = document.body.clientHeight + document.body.scrollTop - 200; eAddMark.style.left = document.body.clientWidth - 56; eAddMark.style.display = ''; // (document.body.clientHeight-$("AddMark").offsetHeight)/2)+"px"; if (eMonthVoteTip) { //$("MonthVoteTip").style.top=document.body.scrollTop+document.body.clientHeight-$("MonthVoteTip").offsetHeight+"px"; 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 CheckInteger() { if (event.keyCode < 45 || event.keyCode > 57) { event.keyCode = 0; } } 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} } /* 2007-11-28 XuJian */ //截取字符串 包含中文处理 //(串,长度,增加...) function subString(str, len, hasDot) { var newLength = 0; var newStr = ""; var chineseRegex = /[^\x00-\xff]/g; var singleChar = ""; var strLength = str.replace(chineseRegex,"**").length; for(var i = 0;i < strLength;i++) { singleChar = str.charAt(i).toString(); if(singleChar.match(chineseRegex) != null) { newLength += 2; } else { newLength++; } if(newLength > len) { break; } newStr += singleChar; } if(hasDot && strLength > len) { newStr += "..."; } return newStr; } /* 2007-10-26 14:20 Get String Lenth(include chinese character) */ function GetStringLength(strObj) { return strObj.replace(/[^\x00-\xff]/g,"**").length; } function addMark(title,url) { try{ if (window.sidebar) { window.sidebar.addPanel(title, url,""); } else if( document.all ) { window.external.AddFavorite( url, title); } else if( window.opera && window.print ) { return true; } }catch(e) { alert("您的浏览器安全设置不允许该项操作"); } } function AdLinkAct(url) { var referkey; try { referkey = GetCookie("rk"); if (referkey!=null && referkey!="") { MyAjax.UseAdLinkView(url,AfterUseAdLinkView); } } catch(e) {} } function AfterUseAdLinkView(result){} ie = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)); function playSwf(path, style) { document.write(""); } var __matchedforbid = new Array(); 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() { 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;//(parseInt(value)%5>=1 && parseInt(value)%5<=4 || parseInt(value)%10==0); } 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 MM_swapImgRestore() { var i,x,a=document.MM_sr; for(i=0;a&&i0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i //替换不安全的字符 function ReplaceUnsafeKeyword(text) { var unsafeString = "?"; var regEx = new RegExp("(" + unsafeString + ")", "gim"); text = text.replace(regEx, ""); unsafeString = "&#\\d+"; regEx = new RegExp("(" + unsafeString + ")", "gim"); return text.replace(regEx, function($1) { return "&#" + $1.substring(2); }); } function findPosY(obj) { var curtop = 0; if (obj && obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent; } } else if (obj && obj.y) curtop += obj.y; return curtop; } function findPosX(obj) { var curleft = 0; if (obj && obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft; obj = obj.offsetParent; } } else if (obj && obj.x) curleft += obj.x; return curleft; } 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 { } } }