﻿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 prevpage;
var nextpage;
var bookpage;
var 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
var 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;
var isShowing = false;
var currentmouse = null;
var curNav;
var 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);
};
//last 200909010 by zhouyao
var Snda=window.Snda={};
(function(){
Snda.QiDian={version:"1.0.0"};
Snda.QiDian.Utility={//通用工具
    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;
       }
    },
    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;
    },
    StopDefault:function(e){//阻止浏览器默认行为
        if(e&&e.preventDefault) e.prefentDefault();
        else                    window.event.returnValue=false;
        return false;
    },
    Postion:{
        scrollX:function(){//拖动条移动x轴距离
            var de=document.documentElement;
            return self.pageXOffset||(de&&de.scrollLeft)|| document.body.scrollLeft;
        },
        scrollY:function(){//拖动条移动y轴距离
            var de=document.documentElement;
            return self.pageYOffset||(de&&de.scrollTop)|| document.body.scrollTop;
        },
        widthWidth: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;
        }
    }
};
Snda.QiDian.Tools={//工具
    Layer:function(){//层
        var ARR_DIAlOG={};
        var that=this;
        var $HREF={
            login:      {url:'LoginDomain.aspx',title:'登录'},
            reg:        {url:'Reg.aspx',        title:'注册'},
            nickname:   {url:'NickName.aspx',   title:'昵称提示'},
            alert1:     {url:'alert1.aspx',     title:'提示'},
            alert2:     {url:'alert2.aspx',     title:'提示'}
        };
        var $path='/Pop/Login/';
        return {
            Push:function(boxId){//插入单个散列组对象
                ARR_DIAlOG[boxId+'']=boxId;
                return this;
            },
            Delete:function(boxId){//删除单个散列组对象
                delete ARR_DIAlOG[boxId];
                return this;
            },
            GetIdArr:function(){//获取散列组对象
                return ARR_DIAlOG;
            },
            Close:function(o){//隐藏散列组中的元素
                for(var i in ARR_DIAlOG){
                    var $o=document.getElementById(ARR_DIAlOG[i]);
                    $o&&($o.style.display='none');
                };
                if(o) __CheckLogin();
                this.ReSet();
            },
            Show:function(arr,b){//显示指定散列值中的对象,b:空或false显示arr中,否则显示所有
                this.ReSet();
                arr=!b?this.GetIdArr():(arr||{});
                for(var i in arr){
                    var $o=document.getElementById(arr[i]);
                    $o&&($o.style.display='');
                };
            },
            GoTo:function(name){//变更iframe地址
                var $IFR=document.getElementById('pop_content');
                var $Title=document.getElementById('pop_title');
                if(!$HREF[name])    alert('页面不存在!');
                else{
                   $IFR.src=$path+$HREF[name].url;
                   $Title.innerHTML=$HREF[name].title;
                   this.Show();
                };
            },
            ReSet:function(){//重置位置
                if(!ARR_DIAlOG['$dialog'])  return false;
                var $o=document.getElementById(ARR_DIAlOG.$dialog);
                $o.style.top=(Snda.QiDian.Utility.Postion.scrollY()+140)+"px";
                $o.style.left=(Snda.QiDian.Utility.Postion.widthWidth()/2-220)+'px';
            }
        };
    }(),
    Login:function(){
       return {
            Check:function(e){//监控键盘回车事件
                e=e||window.event;
                if(e.keyCode === 13) return this.GoIn();
            },
            GoIn:function(){//登录
                  __CheckLogin();
            }
        };
    }(),
    Drag:function(o,root,minX,minY){//移动
        var $filter=0.5;
        !o.$Root&&(o.$Root=root||o);
        o.$minX	= typeof minX != 'undefined' ? minX : null;
        o.$minY	= typeof minY != 'undefined' ? minY : null;
        o.onselectstart = function() { return false; };
        var x,y;
        o.onmousedown = function(e){
            e = e||window.event;
            x=e.layerX||e.offsetX;
            y=e.layerY||e.offsetY;
            o.$Root.style.filter="alpha(opacity="+($filter*100)+")";
            o.$Root.style.opacity = $filter;
            document['onmousemove'] = null;
            setTimeout(function(){document.onmousemove=move},100);
            o.$Root["onmouseout"]=end;
            document['onmouseup']=end;
            return false;
        };
        function drag(){
            o.$Root.style['left']=o.$temp.left+"px";
            o.$Root.style['top']=o.$temp.top+"px";
        };
        function end(e){//结束
             e=e||window.event;
             o.$Root.style.filter="alpha(opacity=100)";
             o.$Root.style.opacity = 1;
             document.onmousemove=null;
             Snda.QiDian.Utility.StopDefault(e)
        };
        function compare(){//比较
            var bool=false;
            if(o.$minX!=null){
                o.$temp.left =Math.max(o.$temp.left , o.$minX);
                o.$temp.left===o.$minX&&(bool=true)
            };
            if(o.$minY!=null){
                o.$temp.top  =Math.max(o.$temp.top  , o.$minY);
                o.$temp.top===o.$minY&&(bool=true)
            }; 
            return bool;
        };
        function move(e){//移动
             e=e||window.event;
            (function(left,top){
                o.$temp={left:left,top:top};
                compare()&&end();
                drag();
            })(e.clientX-x,e.clientY-y);
        };
    },
    Follow:function(o){//跟随
        if(!o||!o.$Root)    return false;
        if(typeof o.$temp=='undefined'){
            o.$temp={
                left:o.$Root.style['left'].replace('px','')>>0,
                top:o.$Root.style['top'].replace('px','')>>0
            };
        };
        o.$Root.style['left']=o.$temp.left+Snda.QiDian.Utility.Postion.scrollX()+"px";
        o.$Root.style['top']=o.$temp.top+Snda.QiDian.Utility.Postion.scrollY()+"px";
    }
};
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(chapterId=='0')  MyAjax.AddBookCase(bookId,ShowCallBack);
    else                MyAjax.AddBookMark(bookId,chapterId,ShowCallBack);
    return false; 
};
function recomBook(bookId){
   MyAjax.RecomBook(bookId,ShowCallBack)
   return false; 
};
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 ScrollDiv(){
    return false;
};