var domainName="shouda8.com";

function Ajax(url, params, callback, method) {
	
	this.createHttpRequest = function() {
		if (window.ActiveXObject) {
			try {
				return new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e) {
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			return new XMLHttpRequest();
		}
	}
	this.url = url;
	this.params = params;
	this.callback = callback;
	this.method = method == null? "post" : method;
	this.xmlHttp = this.createHttpRequest();
	
	window.myAjax = this;
	this.doRequest = function() {
		var query = "";
		for (var param in this.params) {
			if (query != "") {
				query += "&";
			}
			query += param + "=" + this.params[param];
		}
		
		if (this.method == "post") {
			this.xmlHttp.open(this.method, this.url, true);
			this.xmlHttp.onreadystatechange = this.stateChanged;
			this.xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			this.xmlHttp.send(query);
		} else {
			this.url += "?" + query;
			try { 
			this.xmlHttp.open(this.method, this.url, true);
			} catch (err) {}
			this.xmlHttp.send(null);
			return this.xmlHttp.responseText;
		}
	};
	this.stateChanged = function() {
		if (myAjax.xmlHttp.readyState==4 || myAjax.xmlHttp.readyState=="complete") {
			var data = myAjax.xmlHttp.responseText;
			myAjax.callback(data);
		}
	};
	
}
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 showInfoTip(message) {
	alert(message);
}

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");
}


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+)?)/;

if("undefined"!=typeof(re)&&re.test(ua))
	MzBrowser.version = parseFloat(RegExp.$2);

function setBodyFocus() {
	if (MzBrowser.ie && MzBrowser.version == 6) {
		setInterval("document.body.focus()", 1000);
	}
}

