// JavaScript Document
var winarr=new Array();
function createwin(tit,con,width,height,obj,e){
   if(!winarr[obj]){
	   var tx='<div id="'+obj+'">';
	   tx+='<div class="title"><h1>'+tit+'</h1><span>关闭</span></div>';
	   tx+='<div class="con">'+con+'</div>';
	   tx+='</div>';
	   $("body").append(tx);
	   winarr[obj]=1;
	   var evt = e || window.event;
	   var x = parseInt($(document).scrollLeft())+parseInt(evt.clientX);
	   var y = parseInt($(document).scrollTop())+parseInt(evt.clientY);
	   var left=x-parseInt(width);
	   var top=y+10;
       if(left<1) left=30;
	   $("#"+obj).css({'position':'absolute','z-index':'10000','width':width,'height':height,'top':top,'left':left,'padding':'10px','border':'#000 5px solid','background-color':'#EFEFEF'});
	   $("#"+obj+' .title').css({'height':'23px','padding':'7px 10px 0','background':'#000','color':'#fff'});
	   $("#"+obj+' .title h1').css({'float':'left','padding':'0','margin':'0','font-size':'14px','line-height':'16px'});
       $("#"+obj+' .title span').css({'float':'right','cursor':'pointer'});
	   $("#"+obj+' .con').css({'float':'left','width':'100%'});
	   $("#"+obj+' .title span').bind('click',function(){
		    $("#"+obj).hide();  
	   });
   }else  $("#"+obj).show(); 
}
function setCookie(name, value,times) {  
  var today = new Date();
  var expires = new Date();
  expires.setTime(today.getTime() + times);
  document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString()+";path=/";
}
function getCookie(Name) {
 var search = Name + "=";
 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;
     }
     return unescape(document.cookie.substring(offset, end));
    } else {
     return ("");
    }
 } else {
    return ("");
 }
}
var sid=getCookie('sid');
var uid=getCookie('uid');
function reg(e){
	createwin('快速注册','','440px','180px','regdiv',e);
	$("#regdiv .con").html('<div id="regdivcon" style="margin-top:10px;">  帐号:<input type="text" name="ruid" id="ruid"  style="width:150px" /> 5-20位，由数字或字母组成！<br /><br />  密码:<input type="password" name="rpass" id="rpass" style="width:150px" /> 5-20位！<br /><br />  邮箱:<input type="text" name="remail" id="remail" style="width:150px" /> 请填写正确的邮箱，本站不会公开。<br /><br />  <input type="button" name="remailxx" value="确定注册" onclick="postreg()" /></div>');
}
function login(e){
	createwin('用户登陆','','240px','150px','logindiv',e);
	$("#logindiv .con").html('<div id="regdivcon" style="margin-top:10px;">  帐号:<input type="text" name="luid" id="luid"  style="width:150px" /><br /><br />  密码:<input type="password" name="lpass" id="lpass" style="width:150px" /><br /><br /><input type="button" name="remailxx" value="确定登陆" onclick="postlog()" /></div>');
}
function oldmybook(e){
	createwin('导入旧书架','','240px','200px','olbookdiv',e);
	$("#olbookdiv .con").html('<div id="regdivcon" style="margin-top:10px;">请输入你原帐号，只要密码正确即可导入！<br/><br/>  帐号:<input type="text" name="oluid" id="oluid"  style="width:150px" /><br /><br />  密码:<input type="password" name="olpass" id="olpass" style="width:150px" /><br /><br /><input type="button" name="remailxx" value="确定导入" onclick="remybook()" /></div>');
}
function remybook(){
	if(sid && uid){
		$.post('/ujob.php',{act:'oldbook',sid:sid,uoid:$('#oluid').val(),uops:$('#olpass').val(),t:Math.random()},function(da){
														   alert(da);
														   },'html');
	}else alert('请先登陆！');
}
var ifchange=false;
function reportErr(e){
	if(sid && uid){
	createwin('错误报告','','400px','260px','errdiv',e);
	$("#errdiv .con").html('<br/>地址:<span id="eRRurl">'+location.href+'</span><br/><br/>标题:<span id="eRRtit">'+document.title.replace('诺秋网','')+'</span><br/><br/>出错说明:<br/><textarea name="textarea" cols="40" rows="5" id="eRRcon"></textarea><br/><br/><input type="button" onclick="postErr()" name="Submit" value="提交" />');
	if(!ifchange){
	var top=parseInt($("#errdiv").css('top'));
	var left=parseInt($("#errdiv").css('left'));
	var newt=top-350;
	var newl=left-250;
	if(newt<1) newt=1;
	if(newl<1) newl=1;
	$("#errdiv").css({'top':newt+'px','left':newl+'px'});
	ifchange=true;
	}
	}else alert('请先登陆！');
}
function postErr(){
	if($('#eRRcon').val()==''){alert('请输入报错说明');return;}
    if(sid && uid){
		$.post('/ujob.php',{act:'rerr',sid:sid,tit:$('#eRRtit').html(),url:$('#eRRurl').html(),say:$('#eRRcon').val()},function(da){
														   alert(da);
														   },'html');
	}else alert('请先登陆！');
}
var actcode=new Array();
actcode[0]='注册成功！';
actcode[1]='帐号输入有误！';
actcode[2]='帐号输入有误！';
actcode[3]='密码输入有误！';
actcode[4]='邮箱输入有误！';
actcode[5]='帐号已存在！';
actcode[6]='操作失败！请稍后再试！';
function postreg(){
   $.post('/ujob.php',{act:'reg',uid:$('#ruid').val(),pass:$('#rpass').val(),email:$('#remail').val()},function(da){
																									  if(da.scode==0){
																										 alert('注册成功！请记住你的注册密码！');
																										 setCookie('sid',da.sid,360*24*3600000);
																										 setCookie('uid',da.uid,360*24*3600000);
																										 location.reload();
																									  }else{
																										 alert('注册失败！'+actcode[da.scode]);  
																									  }
																									  },'json');
}
function postlog(){
   $.post('/ujob.php',{act:'log',uid:$('#luid').val(),pass:$('#lpass').val()},function(da){
																									  if(da.scode==0){
																										 alert('登陆成功！');
																										 setCookie('sid',da.sid,360*24*3600000);
																										 
																										 setCookie('uid',da.uid,360*24*3600000);
																										 
																										 location.reload();
																									  }else{
																										 alert('登陆失败！帐号或密码有误');  
																									  }
																									  },'json');
}
$(document).ready(
				  function(){
					$('body').beforede();  
				  }
				  );


function mybook(e){
    if(sid && uid){
	  	createwin('我的书架，每个书架最多能存放30本书！','<img src="/images/l.gif" />正在载入....','700px','auto','mybookdiv',e);
		$.post('/ujob.php',{act:'mybook',sid:sid,t:Math.random()},function(da){
														   $("#mybookdiv .con").html(da);
														   },'html');
	}else alert('请先登陆！');
}
function delmybook(id){
    if(sid && uid){
		if(!confirm('你确定要删除吗？')) return;
		$.post('/ujob.php',{act:'delmybook',id:id,sid:sid},function(da){
														   if(da.scode==0){
															   $('#mybookdiv'+id).hide();
														   }
														   alert(da.info);
														   },'json');
	}else alert('请先登陆！');
}
function loginout(){
	 setCookie('sid','',-3600);
	 setCookie('uid','',-3600);
	 location.reload();	
}
function uact(act,id,pid){
		$.post('/ujob.php',{act:act,id:id,pid:pid,sid:sid},function(da){
														   alert(da);
														   },'html');
}
function copy(url){
   window.clipboardData.setData('Text',url);
   alert("已复制链接，你可以通过QQ，MSN，邮箱等方式发送给你的好友！");
}
function dojs(){
  return;	
}

function showstatus(){
   document.write('<div style="position:absolute;left:0px;top:0px;width:3000px;height:10000px;z-index:1005;background-color:#FFFFFF;padding-left:200px;padding-top:200px;">');
   document.write('<p>本章正在手打中..........</p>');
   document.write('<p>一般都是十五钟内，无需关掉此窗口，稍后刷新即可，如果您看到此面长时间没有显示正确章节，请<a href="javascript:void(0)" onclick="reportErr(event)">报错</a>。</p>');
   document.write('<p>您可以把<a href="javascript:void(0)" onclick="uact(\'gxbook\','+this_bid+','+this_id+')">本章更新到书签</a>，方便查看。如果你没有登陆请选<a href="javascript:void(0)" onclick="login(event)">登陆</a>或<a href="javascript:void(0)" onclick="reg(event)">注册</a>！</p>');
   document.write('<p><a href="/">返回首页</a> <a href="javascript:void(0)" onclick="location=gotobook">本书目录</a> <a href="javascript:void(0)" onclick="location=prevpage">上一章</a> <a href="javascript:void(0)" onclick="location=nextpage">下一章</a> </p>');
   document.write('</div>');
}