var domainName="soudu.org";
var areas = ["上海", "北京"];
function also(aid) {
	/*var ara = getCookie("ara");
	if (ara != null) {
		var tempara = "," + ara + ",";
		if (tempara.indexOf("," + aid + ",") == -1) {
			document.writeln("<img id=\"also\" src=\"\/article\/also.html?articleId=" + aid + "\" \/>");
			if (ara.length > 512) {
				var index = ara.indexOf(",");
				ara = ara.substring(index + 1);
				ara = ara + "," + aid;
			} else {
				ara = ara + "," + aid;
			}
			setCookie("ara", ara, 365);
		}
	} else {
		ara = aid;
		setCookie("ara", ara, 365);
	}*/
}
function getCookie(name) {
  	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  	if(arr != null) return unescape(arr[2]); return null;
}
function delCookie(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null) document.cookie=name +"="+cval+";expires="+exp.toGMTString() + ";domain=" + domainName;
}
function setCookie(name,value,days) {
	if(days) {
  		var exp = new Date(); 
  		exp.setTime(exp.getTime() + days*24*60*60*1000);
	  	document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString()+";path=/;domain=" + domainName;
	} else {
		document.cookie = name + "="+ escape(value)+";path=/;domain=" + domainName;
	}
}

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 setCookieWithTime(name,value,times) {
	if(times) {
	  	document.cookie = name + "="+ escape(value) +";expires="+ times.toGMTString()+";path=/;domain=" + domainName;
	} else {
		document.cookie = name + "="+ escape(value)+";path=/;domain=" + domainName;
	}
}
function getResetTime() {
	var now = new Date();
	var now2 = new Date();
	now.setHours(0);
	now.setMinutes(0);
	now.setSeconds(0);
	now.setMilliseconds(0);
	return new Date(24 * 3600 * 1000 + now.getTime());
}
function showCommend(id){
	if(id==1){
		document.getElementById("divImport").style.display="block";
		document.getElementById("divICover").style.display="none";
		document.getElementById("spanImport").className="hover_b";
		document.getElementById("spanICover").className="";
	}else if(id==2){
		document.getElementById("divImport").style.display="none";
		document.getElementById("divICover").style.display="block";
		document.getElementById("spanImport").className="";
		document.getElementById("spanICover").className="hover_b";
	}
}
function goBookcase() {
	window.location.href="http://soudu.org/u/";
}
function userinfo() {
	var ui = getCookie("_cui");
	if (ui != null) {
		var uis = ui.split("\t");
		document.writeln("<img src=\"\/static\/images\/t.gif\">&nbsp;<font color=\"#cc0000\">欢迎 " + uis[0] + ",&nbsp;等级：『<b>" + uis[2] + "<\/b> 』 <\/font>┊<a href=\"\/u\/index.html\" target=\"_top\">我的书架<\/a>┊积分：<b>" + uis[1] + "<\/b>┊ <a href=\"javascript:logout();\">退&nbsp;&nbsp;出<\/a>");
	} else {
		document.writeln("欢迎到<a href=\"http:\/\/soudu.org\">搜读<\/a>来阅读小说，您的支持是我们的最大动力，<a href=\"\/login.html\">登陆<\/a> <a href=\"\/regist.html\"><b>注册<\/b><\/a>");
	}
}
function login() {
	var n = $("#loginId").val();
	var pw = md5($("#password").val());
	var a = $("#autoLogin").attr("checked") ? "1":"0";
	$.post("http://soudu.org/u/login.html",{un:n,p:pw,auto:a}, function(data, status) {
		if (data != null && data.flag == "success") {
			window.location.href="/u/";
		} else {
			alert("用户名或密码错误，或用户名输入有误！");
		}
	});
}
function logout() {
	$.post("http://soudu.org/u/logout.html",{}, function(data, status) {
		window.location.href="/";
	});
}
function pl(aid,cid) {
	$.post("/u/pl.html",{aid:aid,cid:cid,t:'n'}, function(data, status) {
		if (data != null && data.flag == "success") {
			alert("添加书签成功！");
		} else {
			alert("添加书签失败！本功能仅对注册用户开发。");
		}
	});
}
function rl(aid) {
	$.post("http://soudu.org/u/rl.html",{aid:aid,t:'n'}, function(data, status) {
		window.location.href="/u/";
	});
}
function nm(type, aid) {
	alert("此功能正在完善！");
}
function downloadTxt(name, author) {
	document.writeln("<a href=\"http:\/\/txt.zhuike.net\/download.html?nm=" + name + "&au=" + author + "\" target=\"_blank\">TXT合集下载<\/a>");
}

function downTxt1(refId) {
	var url = getDownloadUrl(refId);
	document.writeln("<a href=\"" + url + "\" title=\"文字版下载\" target=\"_blank\"><font style=\"color:red;\">　<b>文字版下载</b>　<\/font><\/a>");
}	
function downTxt2(refId) {
	window.location.href = getDownloadUrl(refId);
}
function getDownloadUrl(refId) {
	var subDir = Math.floor(refId / 1000) + 1;
	return "http://txt.zhuike.net/" + subDir + "_" + refId + ".html";
}

function setBackground(color) {
	setCookie("color", color, 30);
	document.body.style.backgroundColor = "#" + color;
}

function setFontSize(fontSize) {
	if (fontSize == null) {
		fontSize = getCookie("fontSize");
		if (fontSize == null) {
			return;
		}
	} else {
		setCookie("fontSize", fontSize, 30);
	}
	var textArea = $("#chapter_content");
	textArea.css("font-size",  fontSize + "px");
}
function getResetTime2() {
	var now = new Date();
	var now2 = new Date();
	now.setHours(0);
	now.setMinutes(0);
	now.setSeconds(0);
	now.setMilliseconds(0);
	return new Date(24 * 3600 * 1000 + now.getTime());
}
var cip = getCookie("cip") == "1";
var ciped = getCookie("ciped") == "1";

if (!cip) {
	//document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/int.dpool.sina.com.cn\/iplookup\/iplookup.php?format=js\"><\/script>");
}
	
window.cl = function() {
	setCookieWithTime("cip", "1", getResetTime2());
	if (window.remote_ip_info) {
		for (var i = 0; i < areas.length; i++) {
			if (window.remote_ip_info.province.indexOf(areas[i]) > -1) {
				setCookieWithTime("ciped", "1", getResetTime2());
				return true;
			}
		}
	}
	return false;
};

window["MzBrowser"]={};
var ua = window.navigator.userAgent;
MzBrowser.platform = window.navigator.platform;

MzBrowser.firefox = ua.indexOf("Firefox")>0;
MzBrowser.opera = typeof(window.opera)=="object";
MzBrowser.ie = !MzBrowser.opera && ua.indexOf("MSIE")>0;
MzBrowser.mozilla = window.navigator.product == "Gecko";
MzBrowser.netscape= window.navigator.vendor=="Netscape";
MzBrowser.safari= ua.indexOf("Safari")>-1;

var re = null;
if(MzBrowser.firefox) re = /Firefox(\s|\/)(\d+(\.\d+)?)/;
else if(MzBrowser.ie) re = /MSIE( )(\d+(\.\d+)?)/;
else if(MzBrowser.opera) re = /Opera(\s|\/)(\d+(\.\d+)?)/;
else if(MzBrowser.netscape) re = /Netscape(\s|\/)(\d+(\.\d+)?)/;
else if(MzBrowser.safari) re = /Version(\/)(\d+(\.\d+)?)/;
else if(MzBrowser.mozilla) re = /rv(\:)(\d+(\.\d+)?)/;
