/**********************************************????????????*************************************/
/*
trim??????: trim() ltrim() rtrim()
???????????????????????????????????????????????????: realLength()
???????????????????????????: chkIsNotNull(str)
????????????????????????????????????????????????: chkIsNumeric
??????????????????????????????: chkIsInteger(str)
?????????????????????: chkIntegerMinValue(str,val)
?????????????????????: chkIntegerMaxValue(str,val) 
?????????????????????????????????: chkIsDate(str)
????????????????????????email???: chkIsEmail(str)
??????????????????????????????: chkIsChinese(str)
????????????????????????????????????: chkIsTel(str)
????????????????????????????????????: chkIsMobile(str)
??????????????????????????????: chkIsZip(str)
*/

/******************************************************????????????****************************/
/**
* ????????????????????????
* trim:?????????????????? ltrim:??????????????? rtrim: ???????????????
* ?????????
* var str = " hello ";
* str = str.Trim();
*/

String.prototype.trim  = function(){
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function(){
	return this.replace(/^\s+/g, "");
}
String.prototype.rtrim = function(){
	return this.replace(/\s+$/g, "");
}
/***************************************************************************/
/**
* ???????????????????????????????????????????????????
*/
String.prototype.realLength = function()
{
	var i,sum;
    sum=0;
    for(i=0;i<this.length;i++)
    {
        if ((this.charCodeAt(i)>=0) && (this.charCodeAt(i)<=255))
            sum=sum+1;
        else
            sum=sum+2;
    }
    return sum;
}

/********************************** chkIsNotNull **************************************/
/**
*???????????????????????????
*????????????
*	?????????????????????????????????????????????true
*	???????????????????????????????????????false 
*?????????????????????????????????????????????
*/
function chkIsNotNull(str)
{
	if(str.trim() == "")
		return false;
	else
		return true;
}

/********************************** chkIsNumeric ***********************************************/
/**
*????????????????????????????????????????????????
*????????????
*	???????????????????????????????????????????????????true
*	???????????????????????? ??????false 
*????????????????????????????????????????????????
*/

function chkIsNumeric(str)
{
	return (str.search(/^\d+(\.\d+)?$/)!=-1);
}
/********************************** chkIsInteger ***********************************************/
/**
*??????????????????????????????
*????????????
*	?????????????????????????????????????????????true
*	???????????????????????? ??????false 
*????????????????????????????????????????????????
*/
function chkIsInteger(str)
{
	return (str.search(/^[1-9]+(\d+)?$/)!=-1);
}
/********************************** chkIntegerMinValue ******************************************/
/**
*?????????????????????
*str????????????????????? val???????????????
*
*????????????
*	??????????????????????????????????????????????????????????????????true
*	???????????????????????? ??????false 
*??????????????????????????????????????????????????????
*/
function chkIntegerMinValue(str,val)
{
	if(typeof(val) != "string")
		val = val + "";
	if(chkIsInteger(str) == true)
	{
		if(parseInt(str,10)>=parseInt(val,10))
			return true;
	else
		return false;
	}
	else
		return false;
}
/********************************** chkIntegerMaxValue ******************************************/
/**
*?????????????????????
*str????????????????????? val???????????????
*
*????????????
*	??????????????????????????????????????????????????????????????????true
*	???????????????????????? ??????false 
*??????????????????????????????????????????????????????
*/
function chkIntegerMaxValue(str,val)
{
	if(typeof(val) != "string")
		val = val + "";
	if(chkIsInteger(str) == true)
	{
		if(parseInt(str,10)<=parseInt(val,10))
			return true;
		else
			return false;
	}
	else
		return false;
}

/********************************** chkIsDate ******************************************/
/**
*?????????????????????????????????
*????????????
*	?????????????????????????????????????????? ??????true
*	???????????????????????? ??????false 
*??????????????????????????????????????????????????????yyyy-MM-dd???
*/
function chkIsDate(str)
{
	var strSeparator = "-"; //???????????????
	var strDateArray;
	var intYear;
	var intMonth;
	var intDay;
	var boolLeapYear;
	strDateArray = str.split(strSeparator);
	if(strDateArray.length!=3) 
		return false;
		
	if(strDateArray[0].length!=4)
		return false;
	intYear = parseInt(strDateArray[0],10);
	intMonth = parseInt(strDateArray[1],10);
	intDay = parseInt(strDateArray[2],10);

	if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) 
		return false;
	if(intYear<1 || intYear>2500)
		return false;
	if(intMonth>12||intMonth<1) 
		return false;

	if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1)) 
		return false;
	if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1)) 
		return false;
	if(intMonth==2){
		if(intDay<1) 
			return false;

		boolLeapYear = false;
		if((intYear%100)==0){
			if((intYear%400)==0) 
				boolLeapYear = true;
		}
		else{
			if((intYear%4)==0) 
				boolLeapYear = true;
		}

		if(boolLeapYear){
			if(intDay>29) 
				return false;
		}
		else{
			if(intDay>28) 
				return false;
		}
	}
	return true;
}

/********************************** chkEmail *****************************************/
/**
*????????????????????????email???
*????????????
*	???????????????email????????????????????? ??????true
*	??????email???????????? ??????false 
*?????????????????????Email?????????????????????
*/
function chkIsEmail(str)
{
	var re = new RegExp(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
	return re.test(str);
}
/********************************** chkIsChinese ***************************************/
/**
*????????????????????????????????????
*????????????
*	??????????????????????????????????????? ??????true
*	??????????????????????????? ??????false 
*???????????????????????????????????????
*/
function chkIsChinese(str)
{
	var re = new RegExp(/^[\u4E00-\u9FA5]*$/);
	return re.test(str);
}
/********************************** chkIsTel ***************************************/
/**
*????????????????????????????????????
*????????????
*	????????????????????????????????????????????? ??????true
*	????????????????????????????????? ??????false 
*???????????????????????????????????????????????????
*/
function chkIsTel(str)
{
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    
    return patrn.test(str);
}
/********************************** chkIsMobile ***************************************/
/**
*????????????????????????????????????
*????????????
*	????????????????????????????????????????????? ??????true
*	????????????????????????????????? ??????false 
*???????????????????????????????????????????????????
*/
function chkIsMobile(str)
{
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    return patrn.test(str);
}
/********************************** chkIsZip ***************************************/
/**
*??????????????????????????????
*????????????
*	??????????????????????????????????????? ??????true
*	??????????????????????????? ??????false 
*?????????????????????????????????????????????
*/
function CheckZip( str )
{
 var reg = /^\d{6}$/;
 return  reg.test(str);
}

function  ChkIsMoney( str ){   
var regu = "^[0-9]+[\.]{0,1}[0-9]{0,3}$"; 
var re = new RegExp(regu); 
if (re.test(str)) { 
return true; 
} else { 
return false; 
} 
} 
