
Object.extend = function (destination, source) {
	for (property in source) {
		destination[property] = source[property];
	}
	return destination;
};
Object.extend(String.prototype, {LTrim:function () {
	/*
===========================================
//去除左边的空格
===========================================

*/
	return this.replace(/(^\s*)/g, "");
}, Rtrim:function () {
	/*
===========================================
//去除右边的空格
===========================================
*/
	return this.replace(/(\s*$)/g, "");
}, Trim:function () {
	/*
===========================================
//去除前后空格
===========================================
*/
	return this.replace(/(^\s*)|(\s*$)/g, "");
}, Left:function (len) {
	/*
===========================================
//得到左边的字符串
===========================================
*/
	if (isNaN(len) || len == null) {
		len = this.length;
	} else {
		if (parseInt(len) < 0 || parseInt(len) > this.length) {
			len = this.length;
		}
	}
	return this.substr(0, len);
}, Right:function (len) {
	/*
===========================================
//得到右边的字符串
===========================================
*/
	if (isNaN(len) || len == null) {
		len = this.length;
	} else {
		if (parseInt(len) < 0 || parseInt(len) > this.length) {
			len = this.length;
		}
	}
	return this.substring(this.length - len, this.length);
}, Mid:function (start, len) {
	/*
===========================================
//得到中间的字符串,注意从0开始
===========================================
*/
	return this.substr(start, len);
}, InStr:function (str) {
	/*
===========================================
//在字符串里查找另一字符串:位置从0开始
===========================================
*/
	if (str == null) {
		str = "";
	}
	return this.indexOf(str);
}, InStrRev:function (str) {
	/*
===========================================
//在字符串里反向查找另一字符串:位置0开始
===========================================
*/
	if (str == null) {
		str = "";
	}
	return this.lastIndexOf(str);
}, LengthW:function () {
	/*
===========================================
//计算字符串打印长度
===========================================
*/
	return this.replace(/[^\x00-\xff]/g, "**").length;
}, isIP:function () {
	/*
===========================================
//是否是正确的IP地址
===========================================
*/
	var reSpaceCheck = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
	if (reSpaceCheck.test(this)) {
		this.match(reSpaceCheck);
		if (RegExp.$1 <= 255 && RegExp.$1 >= 0 && RegExp.$2 <= 255 && RegExp.$2 >= 0 && RegExp.$3 <= 255 && RegExp.$3 >= 0 && RegExp.$4 <= 255 && RegExp.$4 >= 0) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}, isLongDate:function () {
	/*
===========================================
//是否是正确的长日期
===========================================
*/
	var r = this.replace(/(^\s*)|(\s*$)/g, "").match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
	if (r == null) {
		return false;
	}
	var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
	return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
}, isShortDate:function () {
	/*
===========================================
//是否是正确的短日期
===========================================
*/
	var r = this.replace(/(^\s*)|(\s*$)/g, "").match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
	if (r == null) {
		return false;
	}
	var d = new Date(r[1], r[3] - 1, r[4]);
	return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]);
}, isDate:function () {
	/*
===========================================
//是否是正确的日期
===========================================
*/
	return this.isLongDate() || this.isShortDate();
}, isMobile:function () {
	/*
===========================================
//是否是手机
===========================================
*/
	return /^0{0,1}13[0-9]{9}$/.test(this);
}, isEmail:function () {
	/*
===========================================
//是否是邮件
===========================================
*/
	return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(this);
}, isZipCode:function () {
	/*
===========================================
//是否是邮编(中国)
===========================================
*/
	return /^[\\d]{6}$/.test(this);
}, existChinese:function () {
	/*
===========================================
//是否是有汉字
===========================================
*/
        //[u4E00-u9FA5]為漢字﹐[uFE30-uFFA0]為全角符號
	return /^[u4E00-u9FA5\s]*$/.test(this);
}, isFileName:function () {
	/*
===========================================
//是否是合法的文件名/目录名
===========================================
*/
	return !/[\\\/\*\?\|:"<>]/g.test(this);
}, isIDCard:function () {
	/*
===========================================
//是否是有效的身份证(中国)
===========================================
*/
	var iSum = 0;
	var info = "";
	var sId = this;
	var aCity = {11:"\u5317\u4eac", 12:"\u5929\u6d25", 13:"\u6cb3\u5317", 14:"\u5c71\u897f", 15:"\u5185\u8499\u53e4", 21:"\u8fbd\u5b81", 22:"\u5409\u6797", 23:"\u9ed1\u9f99\u6c5f", 31:"\u4e0a\u6d77", 32:"\u6c5f\u82cf", 33:"\u6d59\u6c5f", 34:"\u5b89\u5fbd", 35:"\u798f\u5efa", 36:"\u6c5f\u897f", 37:"\u5c71\u4e1c", 41:"\u6cb3\u5357", 42:"\u6e56\u5317", 43:"\u6e56\u5357", 44:"\u5e7f\u4e1c", 45:"\u5e7f\u897f", 46:"\u6d77\u5357", 50:"\u91cd\u5e86", 51:"\u56db\u5ddd", 52:"\u8d35\u5dde", 53:"\u4e91\u5357", 54:"\u897f\u85cf", 61:"\u9655\u897f", 62:"\u7518\u8083", 63:"\u9752\u6d77", 64:"\u5b81\u590f", 65:"\u65b0\u7586", 71:"\u53f0\u6e7e", 81:"\u9999\u6e2f", 82:"\u6fb3\u95e8", 91:"\u56fd\u5916"};
	if (!/^\d{17}(\d|x)$/i.test(sId)) {
		return false;
	}
	sId = sId.replace(/x$/i, "a");
        //非法地区
	if (aCity[parseInt(sId.substr(0, 2))] == null) {
		return false;
	}
	var sBirthday = sId.substr(6, 4) + "-" + Number(sId.substr(10, 2)) + "-" + Number(sId.substr(12, 2));
	var d = new Date(sBirthday.replace(/-/g, "/"));
       
        //非法生日
	if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())) {
		return false;
	}
	for (var i = 17; i >= 0; i--) {
		iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11);
	}
	if (iSum % 11 != 1) {
		return false;
	}
	return true;
}, isPhoneCall:function () {
	/*
===========================================
//是否是有效的电话号码(中国)
===========================================
*/
	return /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/.test(this);
}, isNumeric:function (flag) {
	/*
===========================================
//是否是数字
//验证是否是数字
===========================================
*/
	if (isNaN(this)) {
		return false;
	}
	switch (flag) {
	  case null:        //数字
	  case "":
		return true;
	  case "+":        //正数
		return /(^\+?|^\d?)\d*\.?\d+$/.test(this);
	  case "-":        //负数
		return /^-\d*\.?\d+$/.test(this);
	  case "i":        //整数
		return /(^-?|^\+?|\d)\d+$/.test(this);
	  case "+i":        //正整数
		return /(^\d+$)|(^\+?\d+$)/.test(this);
	  case "-i":        //负整数
		return /^[-]\d+$/.test(this);
	  case "f":        //浮点数
		return /(^-?|^\+?|^\d?)\d*\.\d+$/.test(this);
	  case "+f":        //正浮点数
		return /(^\+?|^\d?)\d*\.\d+$/.test(this);
	  case "-f":        //负浮点数
		return /^[-]\d*\.\d$/.test(this);
	  default:        //缺省
		return true;
	}
}, IsColor:function () {
	/*
===========================================
//是否是颜色(#FFFFFF形式)
===========================================
*/
	var temp = this;
	if (temp == "") {
		return true;
	}
	if (temp.length != 7) {
		return false;
	}
	return (temp.search(/\#[a-fA-F0-9]{6}/) != -1);
}, toCase:function () {
	/*
===========================================
//转换成全角
===========================================
*/
	var tmp = "";
	for (var i = 0; i < this.length; i++) {
		if (this.charCodeAt(i) > 0 && this.charCodeAt(i) < 255) {
			tmp += String.fromCharCode(this.charCodeAt(i) + 65248);
		} else {
			tmp += String.fromCharCode(this.charCodeAt(i));
		}
	}
	return tmp;
}, toHtmlEncode:function () {
	/*
===========================================
//对字符串进行Html编码
===========================================
*/
	var str = this;
	str = str.replace(/&/g, "&amp;");
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt;");
	str = str.replace(/\'/g, "&apos;");
	str = str.replace(/\"/g, "&quot;");
	str = str.replace(/\n/g, "<br>");
	str = str.replace(/\ /g, "&nbsp;");
	str = str.replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;");
	return str;
}, toDate:function () {
	/*
===========================================
//转换成日期
===========================================
*/
	try {
		return new Date(this.replace(/-/g, "/"));
	}
	catch (e) {
		return null;
	}
}, isEN:function () {
	var str = this;
	var reg = /^[a-zA-Z0-9&\-\(\)\/、\'\.\",\s]+$/;
	if (reg.test(str)) {
		return true;
	} else {
		return false;
	}
}, isPY:function () {
	var str = this;
	var reg = /^[a-zA-Z\s]+$/;
	if (reg.test(str)) {
		return true;
	} else {
		return false;
	}
},isDateTime:function() {
	var str=this;
	var reg=/^(\d+)-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
	if (reg.test(str)){
		return true;
	} else {
		return false;
	}
}});

