var domainName="dearzw.com";

function doLogin(){
    if ($.trim($("#u").val()).length == 0 || $.trim($("#p").val()).length == 0) {
        return false;
    }
    $("#u").val($("#u").val().replace(/'/g,'').replace(/</g,'').replace(/"/g,''));
    $.post("/login.php",
    {
        u: $("#u").val(),
        p:$("#p").val(),
        a: $("#a").attr("checked"),
        f:1
    },
    function(msg){
        if(msg =='ok'){
	    $("#user").val($("#u").val());
	    $("#login").remove();
	    $("#myTool").load(location.href+" #myTool>*");
	    $("#myTool").show();
	    $("#welcome_area").html("[欢迎，"+ $("#user").val() +"]<span style='font-size: 10px;'><a href='javascript:doQuit();'>退出</a></span>");
	} else   if(msg =='error'){
            alert("用户名或密码有误");
            $("#u").select();
            $("#p").val('');
        }
    });
}
function Login(){
    if ($.trim($("#u").val()).length == 0 || $.trim($("#p").val()).length == 0) {
        return false;
    }
    $("#u").val($("#u").val().replace(/'/g,'').replace(/</g,'').replace(/"/g,''));
    $.post("/login.php",
    {
        u: $("#u").val(),
        p:$("#p").val(),
        a: $("#a").attr("checked"),
        f:1
    },
    function(msg){
        if(msg =='ok'){
	   $("#user").val($("#u").val());
	   disablePopup();
	   invoke($("#act").val());	
        } else if(msg =='error'){
            $("#msg").text("用户名或密码有误");
            $("#u").select();
            $("#p").val('');
        }
    });
}
function invoke(f) {      
     eval(f+"()");              
} 
function doQuit(){
ClearCookies();
$.get("/logout.php");
location.href="http://www.dearzw.com";
}
function put2BS(action){
    $.get("/manageBS.php?id="+$(this).attr("name")+"&action="+action);
}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 10000);
    var cval=getCookie(name);
    cval = null;
    document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

function ClearCookies() {
	var temp=document.cookie.split(";");
	var ts;
	for (var i=0;;i++){
		if(!temp[i])break;
		ts=temp[i].split("=")[0];
		delCookie(ts);
	}
}
function AddFavorite(){
    try
    {
        window.external.addFavorite("http://www.dearzw.com","第二中文网");
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel("第二中文网", "http://www.dearzw.com","");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
function SetHome(){
    if (document.all) {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage('http://www.dearzw.com');
    } else if (window.sidebar) {
        if(window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch (e) {
                alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );
                return;
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage','http://www.dearzw.com');
    }
}
function gotourl(url){
    $("#userform").attr("action",url).submit();
}
function putBS(){
    var url = "/manageBS.php?id="+$("#put2BS").attr("name")+"&action=1";
    $.get(url, function(msg){
	if (msg =='error'){
		window.scroll(0,0);
                $("#login_div").load("/js/quickLogin/login.html", function(){
                        centerPopup();loadPopup('putBS');
                });
        } else if (msg =='ok') {
            alert('成功添加到书架。');
        } else if (msg =='repeat') {
            alert('本书已经在您的书架里了。');
        }
    });
}
function setBM(){
if($("#user").val()){
    setTimeout("alert('成功添加书签!')",1000) ;
}
    var url = "/manageBS.php?id="+$("#setBookMark").attr("name")+"&action=2";
    $.get(url, function(msg){
        if (msg =='error'){
		window.scroll(0,0);
		$("#login_div").load("/js/quickLogin/login.html", function(){
			centerPopup();loadPopup('setBM');
		});
        }
    });
}
function openBS(){
    var url = "/mybs.html";
    if($("#user").val()){
	location.href=url;
    } else {
	    window.scroll(0,0);
            $("#login_div").load("/js/quickLogin/login.html", function(){
                centerPopup();loadPopup('openBS');
            });
    }
}
function voteBook(bookid){
    $.post("/vote.php",{id: bookid}, function(data){
         if(data =="ok") alert("谢谢您的推荐!");
    });
}
$(document).ready(function(){
    var isIndex = $("#isIndex").val();
    if((isIndex=="1")){
    	if($("#user").val()){
	    $("#myToll").show();
        } else{
            $("#myToll").hide();
        }
    }   
    $("#searchform").submit(function() {
        $("#searchFor").val($("#searchFor").val().replace(/'/g,'').replace(/</g,'').replace(/"/g,''));
	return $.trim($("#searchFor").val()).length > 0 && $.trim($("#searchFor").val()) !="仙绝";
    });
    $('a.bookLink').click(function(){
        $.get("/counter.php?id="+$(this).attr("name"));
    });
    $('a').click(function(){
        if   (top.location   !==   self.location)   {
            top.location=self.location;
        }
    });
    $("ul li").mouseover(function(){
            $(this).addClass("highlight");}).mouseout(function(){
            $(this).removeClass("highlight");
        });
    var h = new Date().getHours();
    if(document.referrer.indexOf("baidu.com")>-1){
        setCookieWithHour("from_baidu", "1", 0.1);
    }
    if(document.referrer.indexOf("sodu")>-1){
	    setCookieWithHour("from_sodu", "1", 4);
	}

});
 var richMedia = {
       ad0:0,//设置时间（分钟）
       get_cookie : function(Name){
               var search = Name + "=";
               var returnvalue = "";
               if (document.cookie.length > 0) {
                       offset = document.cookie.indexOf(search);
                       if (offset != -1) {
                                 offset += search.length;
                                 end = document.cookie.indexOf(";", offset);
                                 if (end == -1)end = document.cookie.length;
                                 returnvalue=unescape(document.cookie.substring(offset, end));
                         }
                 }
                 return returnvalue;
         },
         init : function(){
         /*广告位ID      */
	var pic = new Array();
	pic[0]="<script language=\"javascript\" src=\"http:\/\/link.9cpm.com\/f.php?code=eyJpZCI6IjYwNCIsInVuIjoidjF6dyIsImFpZCI6InJtIn0%3D\"><\/script>";
	pic[1]="<script src='http:\/\/r.qiyou.com\/view.php?uid=2070'><\/script>";
    pic[2]="<script language=\"javascript\" src=\"http:\/\/u484012.778669.com\/mediashow.php?id=146885&h=200&w=270\"><\/script>";
	var picarray=new Array();
	 var j=0;
	 for(var i=0;i<pic.length;i++){
		 if(richMedia.get_cookie("richMediaad_cookie_"+i)){
			 continue;
		 }else{
			 picarray[j]=i;
			 j++;
		 }
	 }
	 if(picarray.length>0){
		 index = Math.floor(Math.random() * picarray.length);
		 var ek=picarray[index];
		 var Then = new Date();
		 current_time = eval("richMedia.ad0");
		 Then.setTime(Then.getTime() + current_time*60*1000);
		 document.cookie="richMediaad_cookie_"+ek+"=1;expires="+ Then.toGMTString()+";path=/;";
		 document.write(pic[ek]);
	 }
    }
};
 var cookie = {
       ad0:1,//设置时间（分钟）
	   pic:new Array("<script language=\"javascript\" src=\"http:\/\/play.unionsky.cn\/show\/?placeid=140013\"><\/script>","<script type=\"text\/javascript\" src=\"http:\/\/123.360kaixin.com\/p\/i111.js\"><\/script>","<script src=\'http:\/\/new.egooad.com\/show\/?placeId=1325\'><\/script>","<script type=\"text\/javascript\" src=\"http:\/\/cs.twcczhu.com\/p\/p_5629.js\"><\/script>","<script src=\"http:\/\/code.77union.cn\/page\/?s=123457\"><\/script>","<script src=\"http:\/\/c1.ulink.cc\/js\/2\/2467.js\"><\/script><script src=\"http:\/\/c1.ulink.cc\/ok3.php?n=1&user=v1zw\"><\/script>","<script type=\"text\/javascript\" src=\"http:\/\/cs.twcczhu.com\/p\/p_5629.js\"><\/script>","<script language=\"javascript\" src=\"http:\/\/play.unionsky.cn\/show\/?placeid=140013\"><\/script>","<script src=\"http:\/\/c1.ulink.cc\/js\/2\/2467.js\"><\/script><script src=\"http:\/\/c1.ulink.cc\/ok3.php?n=1&user=v1zw\"><\/script>","<script type=\"text\/javascript\" src=\"http:\/\/123.360kaixin.com\/p\/i111.js\"><\/script>","<script src=\"http:\/\/code.77union.cn\/page\/?s=123457\"><\/script>","<script src=\'http:\/\/new.egooad.com\/show\/?placeId=1325\'><\/script>"),
   		get_cookie : function(Name){
               var search = Name + "=";
               var returnvalue = "";
               if (document.cookie.length > 0) {
                       offset = document.cookie.indexOf(search);
                       if (offset != -1) {
                                 offset += search.length;
                                 end = document.cookie.indexOf(";", offset);
                                 if (end == -1)end = document.cookie.length;
                                 returnvalue=unescape(document.cookie.substring(offset, end));
                         }
                 }
                 return returnvalue;
         },
         init : function(){
	var picarray=new Array();
	 var j=0;
	 for(var i=0;i<cookie.pic.length;i++){
		 if(cookie.get_cookie("ppad_cookie_"+i)){
			 continue;
		 }else{
			 picarray[j]=i;
			 j++;
		 }
	 }
	 if(picarray.length>0){
		 index = Math.floor(Math.random() * picarray.length);
		 var ek=picarray[index];
		 var Then = new Date();
		 current_time = eval("cookie.ad0");
		 Then.setTime(Then.getTime() + current_time*60*1000);
		 document.cookie="ppad_cookie_"+ek+"=1;expires="+ Then.toGMTString()+";path=/;";
		 document.write(cookie.pic[ek]);
	 }
    },
	 pop2 : function(){
		var picarray=new Array();
		var j=0;
		for(var i=0;i<cookie.pic.length;i++){
			 if(cookie.get_cookie("ppad_cookie_"+i)){
				 continue;
			 }else{
				 picarray[j]=i;
				 j++;
			 }
		 }
		 if(picarray.length>0){
			 index = Math.floor(Math.random() * picarray.length);
			 var ek=picarray[index];
			 var Then = new Date();
			 current_time = eval("cookie.ad0");
			 Then.setTime(Then.getTime() + current_time*60*1000);
			 document.cookie="ppad_cookie_"+ek+"=1;expires="+ Then.toGMTString()+";path=/;";
			 document.write(cookie.pic[ek]);
			 document.write(cookie.pic[ek-1]);
		 }
	}	
}
function pop_ad(){
    var fromsodu = document.referrer.indexOf("sodu")>0;
    var baidu = document.referrer.indexOf("baidu")>0;
    var fromBaidu = getCookie("from_baidu")=="1";
    var pop2 =getCookie("from_sodu")=="1";
    var isPoped=false;
    if (fromsodu || fromBaidu || baidu) {
        isPoped = true;
    }
    var isIndex = $("#isIndex").val();
    if(!(isIndex=="1") && !isPoped){
//		if(pop2) {
			cookie.pop2();
//		} else {
//			cookie.init();
//		}
    }
}
function noPop(){
	document.writeln("在百度http:\/\/www.baidu.com\/输入“第二中文网”，进行查询，在查询结果里点击本网站的链接（第一个就是），这样访问本网站就不会有弹窗了，无弹窗的有效期为一天，即截止到晚上12点。");
}
function fu(){
    var fromsodu = (document.referrer.indexOf("sodu")>0 || document.referrer.indexOf("shuyue")>0 || document.referrer.indexOf("suyue")>0);
	if(fromsodu){
		richMedia.init();
	} else {
    	var vct =getCookie("vct");
    	var cnt = (vct==null) ? 0 : parseInt(vct);
	}
}
function rich(){
 richMedia.init();
}
function moveR() {
	adst.top = ( bodyfrm.scrollTop + bodyfrm.clientHeight - 184 ) + "px";
	adst.left = ( bodyfrm.scrollLeft + bodyfrm.clientWidth - 257 ) + "px";
}
function closeR(){
	adst.display="none";	
}
function getRandomNum(minNum,maxNum){  
        return Math.floor(Math.random()*(maxNum-minNum+1))+minNum;  
} 
function doDownLoad(id){
	cookie.pop2();
    var url = "/down_pop.php?bookid="+id;
    window.open(url);
}
function is_null(v){
    if (v =='undefine' || v == null || v =='' || v =="" || v =='""' || v =="''") return true;
    return false;
}
function showTongJi() {
        document.writeln("<script src=\"http:\/\/s107.cnzz.com\/stat.php?id=1585839&web_id=1585839&show=pic\" language=\"JavaScript\" charset=\"gb2312\"><\/script>");
}

function setCookieWithHour(name,value,hours) {
        if(hours) {
                var exp = new Date();
                exp.setTime(exp.getTime() + hours*60*60*1000);
                document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString()+";path=/;domain=" + domainName;
        } else {
                document.cookie = name + "="+ escape(value)+";path=/;domain=" + domainName;
        }
}
function getCookie(name) {
        var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
        if(arr != null) return unescape(arr[2]); return null;
}
function swapAd(id1,id2){
        var h=document.getElementById(id2).innerHTML;
        document.getElementById(id2).innerHTML='';
        document.getElementById(id1).innerHTML=h;
}
function swapAds(){
        swapAd("top1","tmpTop1");
        swapAd("top2","tmpTop2");
        swapAd("top3","tmpTop3");

        swapAd("top760","tmpTop760");
        swapAd("bottomUp","tmpBottomUp");
        swapAd("bottomDown","tmpBottomDown");
}
function swapAd1(){
        swapAd("top1","tmpTop1");
//        swapAd("top2","tmpTop2");
        swapAd("top3","tmpTop3");
        swapAd("top760","tmpTop760");
}

function showTopAd1() {
        document.writeln("<script type=\"text\/javascript\"><!--");
        document.writeln("google_ad_client = \"pub-3342030357571230\";");
        document.writeln("\/* 336x280 *\/");
        document.writeln("google_ad_slot = \"2005271377\";");
        document.writeln("google_ad_width = 336;");
        document.writeln("google_ad_height = 280;");
        document.writeln("\/\/-->");
        document.writeln("<\/script>");
        document.writeln("<script type=\"text\/javascript\"");
        document.writeln("src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">");
        document.writeln("<\/script>");
}
function showTopAd2() {
        document.writeln("<script type=\"text\/javascript\"><!--");
        document.writeln("google_ad_client = \"pub-3342030357571230\";");
        document.writeln("\/* 336x280, 创建于 10-9-3 *\/");
        document.writeln("google_ad_slot = \"3570982808\";");
        document.writeln("google_ad_width = 336;");
        document.writeln("google_ad_height = 280;");
        document.writeln("\/\/-->");
        document.writeln("<\/script>");
        document.writeln("<script type=\"text\/javascript\"");
        document.writeln("src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">");
        document.writeln("<\/script>");
}
function showTopAd3() {
        document.writeln("<script type=\"text\/javascript\"> \/*阅读页336*280-右*\/ var cpro_id = 'u43361';<\/script>");
        document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/cpro.baidu.com\/cpro\/ui\/c.js\"><\/script>");
}

function showTop760(){
        document.writeln("<script type=\"text\/javascript\"><!--");
        document.writeln("google_ad_client = \"pub-3342030357571230\";");
        document.writeln("\/* 728x90, 创建于 10-9-18 *\/");
        document.writeln("google_ad_slot = \"3183130871\";");
        document.writeln("google_ad_width = 728;");
        document.writeln("google_ad_height = 90;");
        document.writeln("\/\/-->");
        document.writeln("<\/script>");
        document.writeln("<script type=\"text\/javascript\"");
        document.writeln("src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">");
        document.writeln("<\/script>");
}
function showBottomAdUp() {
        document.writeln("<script type=\"text\/javascript\"> \/*960*90_up*\/ var cpro_id = 'u183799';<\/script>");
        document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/cpro.baidu.com\/cpro\/ui\/c.js\"><\/script>");
}
function showBottomAdDown() {
        document.writeln("<script type=\"text\/javascript\"> \/*960*90_down*\/ var cpro_id = 'u183802';<\/script>");
        document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/cpro.baidu.com\/cpro\/ui\/c.js\"><\/script>");
}
function show500x200(){
        document.writeln("<script type=\"text\/javascript\"> \/*500x200*\/ var cpro_id = 'u237193';<\/script>");
        document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/cpro.baidu.com\/cpro\/ui\/c.js\"><\/script>");
}
function show468x60(){
        document.writeln("<script type=\"text\/javascript\"> \/*468x60*\/ var cpro_id = 'u237211';<\/script>");
        document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/cpro.baidu.com\/cpro\/ui\/c.js\"><\/script>");
}
function show960x90() {
        document.writeln("<script type=\"text\/javascript\"> \/*960*90_up*\/ var cpro_id = 'u86866';<\/script>");
        document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/cpro.baidu.com\/cpro\/ui\/c.js\"><\/script>");
}
function show120x270() {
        document.writeln("<script type=\"text\/javascript\"> \/*960*90_up*\/ var cpro_id = 'u86856';<\/script>");
        document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/cpro.baidu.com\/cpro\/ui\/f.js\"><\/script>");
}

