String.prototype.trim = function() {
  return this.replace(/(^\s*)|(\s*$)/g, "");   
};

String.prototype.replaceAll = function (AFindText,ARepText) {
	raRegExp = new RegExp(AFindText, "g");
	return this.replace(raRegExp,ARepText);
};

String.prototype.startsWith = function(prefix) {
	return (this.indexOf(prefix) == 0);
};

String.prototype.toJSON = function() {
	return eval("(" + this + ")");
}

var week = ['日','一','二','三','四','五','六']; 
Date.prototype.toString = function() {
	return this.getFullYear()+"年"+
	      (this.getMonth()+1)+"月"+
	       this.getDate()+"日 星期"+
	       week[this.getDay()]+" " +
	       this.getHours()+":"+
	       this.getMinutes()+":"+
	       this.getSeconds();
}

function setClass(element, cls) {
	if (element) {
		element.className = cls;
		element.setAttribute("class", cls);
	}
}

function clearClass(element) {
	if (element) {
		element.className = "";
		element.removeAttribute("class");
	}
}

function getXMLHttpRequest() {
	return window.ActiveXObject ? 
		new ActiveXObject("Microsoft.XMLHTTP") : 
		new XMLHttpRequest();
}

function getMillis() {
	return new Date().getTime();
}

function toJSON(text) {
	return eval("(" + text + ")");
}
var count_regex = /^\+?[1-9][0-9]*$/;
var accept_pic = "gif,jpg,jpeg,bmp,png";
var number_regex = /^(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/;
var zipCode_regex = /^[0-9]{6}$/;
var mobile_regex = new RegExp("^\\d{11}(/\\d{11})*$");
var email_regex = /^[a-zA-Z0-9]([a-zA-Z0-9]*[-_.]?[a-zA-Z0-9]+)+@([\w-]+\.)+[a-zA-Z]{2,}$/;
var date_regex = /^(\d){4}-(\d){2}-(\d){2}$/;
var time_regex = /^\d{2}(:\d{2}){2}$/;
var isIE = document.uniqueID ? true : false; 
var url_regex = new RegExp("^((https|http|ftp|rtsp|mms)?://)" 
        + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@ 
      + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 
      + "|" // 允许IP和DOMAIN（域名）
      + "([0-9a-z_!~*'()-]+\.)*" // 域名- www. 
      + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 
      + "[a-z]{2,6})" // first level domain- .com or .museum 
      + "(:[0-9]{1,4})?" // 端口- :80 
      + "((/?)|" // a slash isn't required if there is no file name 
      + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$");

function isValidEmail(email) {
  return email_regex.test(email);
}

function isDate(value) {
	return date_regex.test(value);
}

function isTime(value) {
	return time_regex.test(value);
}

function isEmail(value) {
	return email_regex.test(value);
}

function isEmpty(value) {
	return (value == undefined || value.trim() == "");
}

function isNotNumber(value) {
	var value = value.trim();
	return (value == "" || isNaN(value));
}

function isNotPositiveNumber(value) {
	var value = value.trim();
	return (isNotNumber(value) || parseInt(value) < 0);
}

function notEmpty(str) {
	return (typeof(str) != "undefined" && str.trim() != "");
}

function setCookie(name, value) {
	var args = setCookie.arguments;
	var len = setCookie.arguments.length;
	var expires = "";
	if (len > 2) {
		var millis = args[2]*1000;
		var expDate = new Date();
		expDate.setTime(expDate.getTime() + millis);
		expires = ";expires="+expDate.toGMTString();
	}
	var path = (len>3) ? args[3] : "";
	var domain = (len>4) ? args[4] : "";
	var secure = (len>5) ? args[5] : false;
	document.cookie = name+"="+escape(value) + expires +
		((path=="") ? "" : (";path="+path)) + 
		((domain=="") ? "" : (";domain="+domain)) +
		(secure ? ";secure" : "");
}

function getCookie(name) {
	var mycookie = unescape(document.cookie);
	var cindex = mycookie.indexOf(name + "=");
	if (cindex != -1) {
	    var cstart = cindex+name.length + 1;
	    var cend = mycookie.indexOf(";", cstart);
	    if (cend == -1) 
	        cend = mycookie.length;
	    return mycookie.substring(cstart, cend);
	}
	return null;
}

function delCookie(name) { 
	var time = new Date(); 
	time.setTime(time.getTime() - 1); 
	var value = getCookie(name); 
	document.cookie = name + "=" + value + ";expires=" + time.toGMTString(); 
}

//for validate
var ispassed = true;
function required(id, msg) {
	if (isEmpty(document.getElementById(id).value))
		showErrorMsg(id, msg)
	else
		hideErrorMsg(id);
}

function isNotNumber(id, msg) {
	var value = document.getElementById(id).value;
	if (value != "") {
		var val = 0;
		try {
			val = parseInt(value);
		} catch(e) {
			showErrorMsg(id, msg);
		}
	}
}

function showErrorMsg(id, msg) {
	ispassed = false;
	var span = document.getElementById("err_" + id);
	span.innerHTML = msg;
	setClass(span, "error");
	document.getElementById(id).focus();
	try {
		document.getElementById(id).select();
	} catch(e) {}
}

function hideErrorMsg(id) {
	var span = document.getElementById("err_" + id);
	span.innerHTML = "";
	clearClass(span);
}
	
function createOption(name, value) {
	var option = document.createElement("option");
	option.setAttribute("value", value);
	option.appendChild(document.createTextNode(name));
	return option;
}

function clearOptions(selectId, leaveNum) {
	if (leaveNum == undefined)
		leaveNum = 0;
	var select = document.getElementById(selectId);
	if(select!=null){
		while (select.options.length > leaveNum)
			select.removeChild(select.options[leaveNum]);
	}
}

function createTd(text) {
	var td = document.createElement("td");
	td.innerHTML = text;
	return td;
}

function clearRows(tbodyId, leaveNum) {
	if (leaveNum == undefined)
		leaveNum = 0;
	var tbody = document.getElementById(tbodyId);
	var rows = tbody.getElementsByTagName("TR");
	while (rows.length > leaveNum)
		tbody.removeChild(rows[leaveNum]);
}

function changeCode() {
    document.getElementById("changeCode").onclick = function() {
		document.getElementById("captcha").src = "captcha.do?ran=" + Math.random();
	};
}

	 
function hiddenTipDiv(tip) {
	document.getElementById(tip).style.display="none";
}

//in order to compatible IE6 and jquery
function auto() {}	 
