function ascii(str){
	return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\&#x$2;")});
}
function unicode(str){
	return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")});
}

function reconvert(str){ 
	str = str.replace(/(\\u)(\w{4})/gi,function($0){
	return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{4})/g,"$2")),16)));});
				
	str = str.replace(/(&#x)(\w{4});/gi,function($0){
	return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{4})(%3B)/g,"$2"),16));});            
	return str;
}
function trim(){
	return this.replace(/(^\s*)|(\s*$)/g,""); 
}
//==========头 head=================================================================================================
function sotj(){
	if($("key").value.length<2){ alert('请输入长度大于等于2的关键字.');$("key").focus();return false; }
	if($("key").value=="看小说来八神小说站"){ alert('请输入您要查询的书籍名称.');
	$("key").select();return false; }
	return true;
}
function sotj_hc(){
	if(event.keyCode==13){
		return sotj();
	}else{
		return true;
	}
}
function sochick(obj,i){
	if(i==1){
		if(obj.value=='')obj.value='看小说来八神小说站';
	}else{
		if(obj.value=='看小说来八神小说站')obj.value='';
	}
}
function sq_shou(lb){
	switch(lb){
		case 1:
			javascript:window.open('http://shuqian.qq.com/post?from=3&jumpback=2&noui=1&title='+encodeURIComponent(document.title)+'&uri='+encodeURIComponent(document.location.href)+'','qqsq','width=930,height=470,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes');
		break;
		case 2:
			window.open('http://cang.baidu.com/do/add?it='+encodeURIComponent(document.title.substring(0,76))+'&iu='+encodeURIComponent(location.href)+'&fr=ien#nw=1','baidusq','scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes'); 
		break;
		case 3:
			window.open('http://myweb.cn.yahoo.com/popadd.html?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title), 'Yahoosq','scrollbars=yes,width=780,height=550,left=80,top=80,status=yes,resizable=yes');
		break;
		default: return ""; break;
	}
}
function addCookie(){　 // 加入收藏夹  
    if (document.all){   
        window.external.addFavorite(window.location.href,document.title);   
    }else if (window.sidebar){   
        window.sidebar.addPanel(document.title, window.location.href, "");   
    }   
}  
function setHomepage(){　 // 设为首页  
    if (document.all){   
        document.body.style.behavior = 'url(#default#homepage)';   
        document.body.setHomePage(window.location.href);   
    }else if (window.sidebar){   
        if (window.netscape){   
            try {   
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
            }catch (e) {   
                alert("该操作被游览器拒絕，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该项值设置为true");   
            }   
        }   
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);   
        prefs.setCharPref('browser.startup.homepage',window.location.href);   
    }   
}    
function jrsj(id,title,root){
	where = "&id="+id+"&title="+title;
	url = root+"count.php?a=jrsj"+where;  
	Ajax.Request(url,{onComplete:show_jrsq});
}
function show_jrsq(){
	code=this.response;
	alert(code);
}
//===========zhong jian=======================================================================================
function subfx(){
	$("nr").value = $("nr").value.trim();
	if($("nr").value.length<4){
		alert('请输入分享说明,至少4个字的说明.');
		$("nr").focus();
		return false;
	}
	if($("lb").value=="" || $("lb").value.length<2 || $("lb").value.length>4){
		alert('请输入本书,你认为应该属于的类别?(2-4个字)');
		$("lb").focus();
		return false;
	}
	return true;
}
function fx_ok(id){
	alert("该书已经被您,推荐给别人观看了.");
	$("ckfx").src="about:blank";
	top.window.location="sox_"+id+".shtml";
}
function fx_cf(user){
	alert('您('+user+')已经分享过本书了,请不要重复分享.');	
}
function xsdown(id,lb,tt){
	url="";
	switch(lb){
		case "yunxuange_com":
			id = id.replace(".html","");
			url = "http://www.yxg.cc/down_file.asp?id="+id;
			//url = "http://a.yxg.cc/down.php?id="+id+"&s=txt&un=201051";
		break;
		case "aishu5_com":
			id = id.replace(".html","");
			url = "http://www.aishu5.com/modules/article/txtarticle.php?id="+id;
		break;
		case "xiaoshuola_com":
			id = id.replace(/.html/g,"");
			url = "http://www.xiaoshuola.com/huoban/txt"+id;
		break;
		case "sodu5_com":
			id = id.replace(/.html/g,"");
			url = "http://www.sodu5.com/modules/article/packdown.php?id="+id+"&type=txt&fname="+tt;
		break;
		case "zhen1_com":
			id = id.replace(/.html/g,"");
			url = "http://www.zhen1.com/book/"+id+"/txt.html";
		break;
		case "kywxw_com":
			id = id.replace(/.html/g,"");
			url = "http://www.kywxw.com/modules/article/packdown.php?id="+id+"&type=txt";
		break;
		default:
			alert('稍后开放');
			return "";
		break;
	}	
	window.open(url,"donws", "height=350, width=650, top=50, left=255, toolbar=no,menubar=no, scrollbars=no, resizable=no,location=no, status=no");
}

//==============================================================================================================================
function first(){
	alert('这已经是第一页了,别乱点老.');
}
function nexting(){
	alert('这已经是最新章节了,去起点吹作者写快点哈,写出来了再来看哈.');
}

function correctPNG()       
{     
	for(var    i=0;    i<document.images.length;    i++)     
	{     
		var    img    =    document.images[i]     
		var    imgName    =    img.src.toUpperCase()     
		if(imgName.substring(imgName.length-3,    imgName.length)    ==    "PNG"){     
		var    imgID    =    (img.id)    ?    "id='"    +    img.id    +    "'    "    :    ""     
		var    imgClass    =    (img.className)    ?    "class='"    +    img.className    +    "'    "    :    ""     
		var    imgTitle    =    (img.title)    ?    "title='"    +    img.title    +    "'    "    :    "title='"    +    img.alt    +    "'    "     
		var    imgStyle    =    "display:inline-block;"    +    img.style.cssText       
		if    (img.align    ==    "left")    imgStyle    =    "float:left;"    +    imgStyle     
		if    (img.align    ==    "right")    imgStyle    =    "float:right;"    +    imgStyle     
		if    (img.parentElement.href)    imgStyle    =    "cursor:hand;"    +    imgStyle                     
		var    strNewHTML    =    "<span    "    +    imgID    +    imgClass    +    imgTitle     
		+    "    style=\""    +    "width:"    +    img.width    +    "px;    height:"    +    img.height    +    "px;"    +    imgStyle    +    ";"     
		+    "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"     
		+    "(src=\'"    +    img.src    +    "\',    sizingMethod='scale');\"></span>"       
		img.outerHTML    =    strNewHTML     
		i    =    i-1     
		}     
	}     
} 

//取得一个对象，相当于getElementById()
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') element = document.getElementById(element);
	Method.Element.apply(element);
    if (arguments.length == 1) return element;
    elements.push(element);
  }
  return elements;
}

//常用函数扩展
var Method = {
	Element	: function(){
		this.hide = function(){this.style.display="none"; return this;};
		this.show = function(){this.style.display=""; return this;};
		this.getValue = function(){if(this.value===undefined) return this.innerHTML; else return this.value;};
		this.setValue = function(s){if(this.value === undefined) this.innerHTML = s; else this.value = s;};
		this.subTag = function(){return $A(this.getElementsByTagName(arguments[0])).each(function(n){$(n);});};
		this.remove = function(){return this.parentNode.removeChild(this);};
		this.nextElement = function(){var n = this;	for(var i=0,n; n = n.nextSibling; i++) if(n.nodeType==1) return $(n); return null;};
		this.previousElement = function(){var n = this;	for (var i=0,n; n = n.previousSibling; i++) if(n.nodeType==1) return $(n); return null;};
		this.getPosition =  function(){var e = this; var t=e.offsetTop; var l=e.offsetLeft; while(e=e.offsetParent){if($(e).getStyle('position') == 'absolute' || $(e).getStyle('position') == 'relative') break; t+=e.offsetTop; l+=e.offsetLeft;} return {x:l, y:t};};
		this.getStyle = function(name){ if(this.style[name]) return this.style[name]; else if(this.currentStyle) return this.currentStyle[name]; else if(document.defaultView && document.defaultView.getComputedStyle){ name = name.replace(/([A-Z])/g,"-$1").toLowerCase(); var s = document.defaultView.getComputedStyle(this,""); return s && s.getPropertyValue(name); } else return null;};
		this.setInnerHTML = function(s){var ua = navigator.userAgent.toLowerCase();if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0){ s = '<div style="display:none">for IE</div>' + s;	s = s.replace(/<script([^>]*)>/gi,'<script$1 defer>');	this.innerHTML = '';
		this.innerHTML = s;	this.removeChild(this.firstChild);}else{var el_next = this.nextSibling; var el_parent = this.parentNode; el_parent.removeChild(this); this.innerHTML = s; if(el_next) el_parent.insertBefore(this, el_next); else el_parent.appendChild(this);}};
	},
	Array :	function(){
		this.indexOf = function(){for (i=0; i<this.length; i++) if (this[i]==arguments[0]) return i; return -1;};
		this.each = function(fn){for (var i=0,len=this.length; i<len; i++){	fn(this[i],i);} return this;};
	},
	String : function(){
		this.trim = function(){var _re,_argument = arguments[0] || " ";	typeof(_argument)=="string"?(_argument == " "?_re = /(^\s*)|(\s*$)/g : _re = new RegExp("(^"+_argument+"*)|("+_argument+"*$)","g")) : _re = _argument; return this.replace(_re,"");};
		this.stripTags = function(){return this.replace(/<\/?[^>]+>/gi, '');};
		this.cint = function(){return this.replace(/\D/g,"")*1;};
		this.hasSubString = function(s,f){if(!f) f="";return (f+this+f).indexOf(f+s+f)==-1?false:true;};
	}
};

Method.Array.apply(Array.prototype);
Method.String.apply(String.prototype);


//ajax处理
function bsw_ajax() {
	this.init = function() {
		this.handler = null;
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
		this.requestFile = null;
		this.vars = new Object();
		this.responseStatus = new Array(2);
		this.failed = false;
		this.response = "";
		this.asynchronous = true;

		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onComplete = function() { };
  		this.onError = function() { };
		this.onFail = function() { };

		try {
			this.handler = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				this.handler = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				this.handler = null;
			}
		}

		if (! this.handler) {
			if (typeof XMLHttpRequest != "undefined") {
				this.handler = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
  	};
	this.setVar = function(name, value, encoded){
		this.vars[name] = Array(value, encoded);
	};
	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	};
	this.processURLString = function(string, encode) {
		//regexp = new RegExp(this.argumentSeparator + "|" + encodeURIComponent(this.argumentSeparator));
		regexp = new RegExp(this.argumentSeparator);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1], false);
			} else {
				this.setVar(urlVars[0], urlVars[1], true);
			}
		}
	};
	this.createURLString = function(urlstring) {
		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}
		this.setVar("ajax_request", new Date().getTime(), false);
		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}
			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	};
	this.runResponse = function() {
		eval(this.response);
	};
	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			if(this.requestFile.indexOf(this.queryStringSeparator) > 0){
				var spoint = this.requestFile.indexOf(this.queryStringSeparator);
				this.processURLString(this.requestFile.substr(spoint + this.queryStringSeparator.length), false);
				this.requestFile = this.requestFile.substr(0, spoint);
			}
			this.createURLString(urlstring);
			if (this.handler) {
				var self = this;
				
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.handler.open(this.method, totalurlstring, this.asynchronous);
				} else {
					this.handler.open(this.method, this.requestFile, this.asynchronous);
					try {
						this.handler.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					} catch (e) { }
				}

				this.handler.onreadystatechange = function() {
					switch (self.handler.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.handler.responseText;
							self.responseXML = self.handler.responseXML;
							self.responseStatus[0] = self.handler.status;
							self.responseStatus[1] = self.handler.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.responseStatus[0] == "200") {
								self.onComplete();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				}
				this.handler.send(this.method == "GET" ? null : this.URLString);
			}
		}
	};
	this.submitForm = function(form) {
		if(this.requestFile == null) this.requestFile = $(form).attributes["action"].value;
		this.runAJAX(Form.serialize(form));
	};
	this.init();
}

var Ajax = {
	Request	: function(vname, vars){
		var ajax = new bsw_ajax();
		var param = {method:"",parameters:"",asynchronous:true,onLoading:function(){},onLoaded:function(){},onInteractive:function(){},onComplete:function(){},onError:function(){},onFail:function(){}};
		for (var key in vars) param[key] = vars[key];
		if(param["parameters"] != "") ajax.processURLString(param["parameters"], false);
		ajax.asynchronous = param["asynchronous"];
		ajax.onLoading = param["onLoading"];
		ajax.onLoaded = param["onLoaded"];
		ajax.onInteractive = param["onInteractive"];
		ajax.onError = param["onError"];
		ajax.onFail = param["onFail"];
		ajax.onComplete = param["onComplete"];
		if($(vname) != null && $(vname).tagName.toLowerCase() == "form"){
			ajax.method = param["method"]=="" ? "POST" : param["method"];
			ajax.submitForm(vname);
		}else{
			ajax.method = param["method"]=="" ? "GET" : param["method"];
			ajax.requestFile = vname;
			ajax.runAJAX();
		}
	},
	Update : function(vname, vars){
		var param = {outid:"",tipid:"",onLoading:"", outhide:0, cursor:"wait", parameters:""};
		for (var key in vars) param[key] = vars[key];

		var isform = ($(vname) != null && $(vname).tagName.toLowerCase() == "form") ? true : false;

		if(typeof param["onLoading"] == 'function'){
			var doLoading = param["onLoading"];
		}else{
			var doLoading = function(){
				if(param["cursor"] != "") document.body.style.cursor=param["cursor"];
				if(param["tipid"] != "") {$(param["tipid"]).setValue(param["onLoading"]);$(param["tipid"]).show();}
				if(isform) Form.disable(vname);
			}
		}
		var doComplete = function(){
			if(param["cursor"] != "") document.body.style.cursor="auto";
			if(param["tipid"] != "") {$(param["tipid"]).setValue("");$(param["tipid"]).hide();}
			if(param["outid"] != "") {$(param["outid"]).setValue(this.response);$(param["outid"]).show();}
			if(param["outhide"] != "") {setTimeout(function(){$(param["outid"]).hide()},param["outhide"]);}
			if(isform) Form.enable(vname);
		}
		var doError = function(){
			if(param["outid"] != "")  $(param["outid"]).setValue("ERROR:"+this.responseStatus[1]+"("+this.responseStatus[0]+")");
			if(isform) Form.enable(vname);
		}
		var doFail = function() {
			alert("Your browser does not support AJAX!");
			if(isform) Form.enable(vname);
		}
		
		Ajax.Request(vname, {onLoading:doLoading, onComplete:doComplete, onError:doError, onFail:doFail, parameters:param["parameters"]});
	},
	Tip : function(event, url, timeout){
		event = event ? event : (window.event ? window.event : null);
		timeout = timeout ? timeout : 3000;
		var eid = event.srcElement ? event.srcElement.id : event.target.id;
		var tid = eid + "_tip";
		var ele = $(eid);
		var pos = ele.getPosition();
		var atip  = $(tid);
		if(!atip) {
			atip = document.createElement("div");
			atip.id = tid;
			atip.style.display = "none";
			atip.className = "ajaxtip";
			document.body.appendChild(atip);
			atip.onclick = function(){$(tid).hide();};
		}
		atip.style.top = (pos.y + ele.offsetHeight + 2)  + "px";
		atip.style.left = pos.x + "px";
		atip.innerHTML = "";
		atip.style.display="";
		this.Update(url, {outid:tid, tipid:tid, onLoading:"Loading...", outhide:timeout, cursor:"wait"});
	}
}

