//
function isArray(variable){
	if (variable==null) return(false);
	var reValue=true;
	try {
		reValue=(typeof(variable)=="object"&&variable.constructor==Array)?true:false;
		}
		 catch(para) {
			 try{
				 variable.push(1);variable.pop();reValue=true;
				 }
				catch(para){
					reValue=false;
				}
			}
	return(reValue);
}

function isFunction(fun) {
	if (fun==null) return(false);
	return (typeof(fun)=='function'&&fun.constructor==Function);
}
function isString(str){
	if (str==null) return(false);
	return (typeof(str)=='string'&&str.constructor==String); 
}
function isNumber(obj){
	if (obj==null) return(false);
	return (typeof(obj)=='number'&&obj.constructor==Number); 
}
function isDate(obj){
	if (obj==null) return(false);
	return (typeof(obj)=='object'&&obj.constructor==Date); 
}
function isObject(obj){
	if (obj==null) return(false);
	return (typeof(obj)=='object'&&obj.constructor==Object); 
}
function isNull(a) {
	if (isArray(a)){return(a.length==0);}
	return(a==null || (!a&&a!=0) || (isString(a)&&(a.replace(/(^\s*)|(\s*$)/g, "")=="" || a.toLowerCase()=="null" || a.toLowerCase()=="empty")) || typeof(a)=='undefined');
}
function isBoolean(a){
	if (a==null) return(false);
  return(typeof(a) == 'boolean'&&a.constructor==Boolean);
}


/***string 扩展***/
String.prototype.lcase=function(){//转换成小写字符串
		return(this.toLowerCase());
	};
String.prototype.lcase=function(){//转换成大写字符串
		return(this.toUpperCase());
	};
String.prototype.subByte = function(n)
{
  if(this.getByteLength()<=n) return this;
  for(var i=Math.floor((n=n-2)/2), l=this.length; i<l; i++)
  if(this.substr(0,i).getByteLength()>=n)return this.substr(0,i) +"\u2026";
  return this;
};
String.prototype.getByteLength=function(){return this.replace(/[^\x00-\xff]/g, "mm").length;};
String.prototype.isNone=function(){var s=this.trim();return(s.getByteLength()==0);}
String.prototype.trim=function(){return this.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+$)/g, "")};
String.prototype.zero=function(n){//给不足位的字符串补零,n保证字符串的最少位数
		if (this.length>=n) return(this);
		var zero=this.toString();
		while(zero.length<n) zero="0"+zero.toString();
		return(zero);
	};
String.prototype.isDateTime=function(){
		//1.判断是否符合 yyyy-mm-dd hh:mm:ss的日期格式, 而且闰年闰月等也要正确
		//alert("2002-12-12 10:10:40".isDateTime())  //true
		 try{
			 var arr=(this.length==19)?this.split(/\D/):[];
			 --arr[1];
			 eval("var d=new Date("+arr.join(",")+")")    
			 return     Number(arr[0])==d.getFullYear() && Number(arr[1])==d.getMonth() && Number(arr[2])==d.getDate() && Number(arr[3])==d.getHours() && Number(arr[4])==d.getMinutes() && Number(arr[5])==d.getSeconds();
			 }
			 catch(x){
				 return false;
		}
	};
String.prototype.isDate=function(){//日期正则表达式(yyyy-mm-dd),如闰年,2月等都不能错
		var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
		//var reg1=/^(\d{4})([-])(\d{2})([-])(\d{2})/;//yyyy-mm-dd
		//var reg2=/^(\d{4})([\/])(\d{2})([\/])(\d{2})/;//yyyy/mm/dd
		return(reg.test(this));
	};
String.prototype.isInt=function(){//字符串是否由0-9的数字组成
		return(/^[0-9]+$/.test(this));	
	};
String.prototype.isLetter=function(){//字符串是否由字母组成
		return(/^[a-zA-Z]+$/.test(this));	
	};
String.prototype.isNumberLetter=function(){//字符串是否由数字和字母组成
		return(/^[0-9a-zA-Z]+$/.test(this));	
	};
String.prototype.isNumber=function(){//验证正负整数或正负小数
		return(/(^[-|+]?\d\d*\.\d*$)|(^[-|+]?\d\d*$)|(^[-|+]?\.\d\d*$)/.test(this));
	};
String.prototype.isDecimal=function(){
		return(/(^[0-9]+$)|(^\d*\.\d*$)/.test(this));
	};
String.prototype.isTel=function(){//验证国内电话号码(含分机号(1-5位):0731-8929559-123,分机号可以有或没有)
		return(/^(\d{3}-\d{8}|\d{4}-\d{7,8})(\-\d{1,5})?$/.test(this));
	};
String.prototype.isMobile=function(){//验证手机号
		return(/^1[3|5|8][0-9]\d{8}$/.test(this));
	};
String.prototype.isEmail=function(){//验证Email
		return(/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(this));
	};
String.prototype.isUserName=function(){
			//１、只允许输入中文、英文、数字、下划线或它们的组合 
			//２、只能以中文或者英文开头 
			//３、要求４～１６字节长度（１个汉字＝２字节） 
			//４、不允许出现空白字符（包括全角半角空格、换行符）
		  var len = this.replace(/[^\x00-xff]/g,"xx").length;
		  if(len>16 || len<4)return false;//条件3 没办法判断实际长度只能用这个方法
		  if(/^[A-Za-z\u4e00-\u9fa5][\w\u4e00-\u9fa5]+$/.test(this))return true;//条件1~2
		  return false;
	};
String.prototype.isIp=function(){//验证IP地址/^((\d|[1-9]\d|2[0-4]\d|25[0-5]|1\d\d)(?:\.(\d|[1-9]\d|2[0-4]\d|25[0-5]|1\d\d)){3})$/
		return(/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/.test(this));
	};
String.prototype.isZip=function(){//验证邮政编码
		return(/^\d{4,6}$/.test(this));
	};
String.prototype.isQQ=function(){//验证QQ
		return(/^\d{5,12}$/.test(this));
	};
String.prototype.isIdentity=function(){//验证身份证号
		return(/^\d{15}$|^\d{18}$|^\d{17}x$/.test(this));
	};
String.prototype.isDomain=function(){//验证域名(不含http://)
		try{return(/^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)|(io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp))$/.test(this.lcase()));}
		catch(para){return false;}
	};
String.prototype.isURL=function(){//验证URL
		return(/^((ht|f)tp(s?))\:\/\/([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/.test(this));
	};
String.prototype.isChinese=function(){//校验字符串是否为全部中文(含全角字符)
		return((/^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])*$/gi).test(this));
	}	
String.prototype.format=function()
{
  if(arguments.length==0) return this;
  for(var s=this, i=0; i<arguments.length; i++)
    s=s.replace(new RegExp("\\{"+i+"\\}","g"), arguments[i]);
  return s;
};
String.format=function(str)
{
  if("string"!=typeof(str)||arguments.length<=1) return str;
  for(var i=1; i<arguments.length; i++)
    str=str.replace(new RegExp("\\{"+(i-1)+"\\}","g"), arguments[i]);
  return str;
};



document.Event=function(){
	if(document.all) return(window.event);
	var Fun=document.Event.caller;
	while(Fun!=null){
		var Arg=Fun.arguments[0];
		if(Arg){
			if((Arg.constructor==Event || Arg.constructor ==MouseEvent) || (typeof(Arg)=="object" && Arg.preventDefault && Arg.stopPropagation)) return(Arg);
			}
			Fun=Fun.caller;
	}
	Arg=Fun=null;
	return(Arg);
};
document.This=function(){
	return(document.Event().srcElement || document.Event().target);
	};





