﻿//新定义String方法
String.prototype.trim = function(){
	return this.replace(/(^[ \s]+)|([ \s]+$)/g, '');
}
String.prototype.clshtml = function(){
	return this.replace(/<(.+?)>/gi, '');
}
String.prototype.exp = function(e){
	var reVal = false;
	try{
		reVal = e.test(this);
	} catch(e) { reVal = false;alert(['正则表达式错误：', e.description].join("\n"));}
	return reVal;
}

//////////////////////////////////////////////
	//构造取值
	$.Request = {
	 QueryString : function(item){
	  var val = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
	  return val ? val[1] : val;
	 }
	}
//=================================
	$.mid = function (str,strnum,endnum){
		return (str.length>=0)?str.substr(strnum,(typeof(endnum)=='undefined')?str.length:endnum):'';
	},
	$.right = function (str,lnglen){
		return (str.length - lnglen>=0 && str.length>=0 && str.length - lnglen <= str.length)?str.substring(str.length-lnglen,str.length):'';
	}
	$.left = function (str,lnglen){
		return (str.length>0 && lnglen>0)?str.substring(0,lnglen):'';
	}
	//cookie操作
	$.cookie = function(name, value, options) {
		if (typeof value != 'undefined') { // name and value given, set cookie
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			}
			var expires = '';
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
			}
			// CAUTION: Needed to parenthesize options.path and options.domain
			// in the following expressions, otherwise they evaluate to undefined
			// in the packed version for some reason...
			var path = options.path ? '; path=' + (options.path) : '';
			var domain = options.domain ? '; domain=' + (options.domain) : '';
			var secure = options.secure ? '; secure' : '';
			document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
		} else { // only name given, get cookie
			var cookieValue = null;
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = $.trim(cookies[i]);
					// Does this cookie string begin with the name we want?
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
						break;
					}
				}
			}
			return cookieValue;
		}
	}
	
	$.Regex = {
		Require : /.+/,
		Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
		Phone : /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/,
		Mobile : /^((\(\d{2,3}\))|(\d{3}\-))?((13\d{9})|(15[389]\d{8}))$/,
		Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
		IP : /^(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])$/,
		Currency : /^\d+(\.\d+)?$/,
		Number : /^\d+$/,
		Zip : /^[1-9]\d{5}$/,
		QQ : /^[1-9]\d{4,8}$/,
		Integer : /^[-\+]?\d+$/,
		Double : /^[-\+]?\d+(\.\d+)?$/,
		English : /^[A-Za-z]+$/,
		Chinese :  /^[\u0391-\uFFE5]+$/,
		Username : /^[a-z]\w{3,19}$/i,
		UnSafe : /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/
	}
	
	$.BitAnd = function (val1,val2){
	return val1&val2; //按位与
	}