//---------------------------------String???????------------------------------------------
//	author:	???

//	trim()				??????
//	lTrim()				?????
//	rTrim()				?????
//	realLength()		????????,?????????
//	isInteger()			?????		????true	?????false
//	isDouble()			??????	????true	?????false
//	isDate()			???????	????true	?????false
//	isEmpty()			????		????true	?????false
//	isEmail)			??Email????
//	isAllChinese()		????????????
//  isLetterOrNumber()	????????????????????? 	 ????true   ?????false
//	toDate()				???????Date
//--------------------------------------------------------------------------------------------------
/**
* ????
*/
function isValidDay(strYear, strmonth, strDay) {
  var year = parseInt(strYear,10);
  var month = parseInt(strmonth,10);
  var day = parseInt(strDay,10);
  if (month < 1 || month > 12) {
    return false;
  }
  if (day < 1 || day > 31) {
    return false;
  }
  if ((month == 4 || month == 6 || month == 9 || month == 11) && (day == 31)) {
    return false;
  }
  if (month == 2) {
    var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day>29 || (day == 29 && !leap)) {
      return false;
    }
  }
  return true;
}

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()
{
  return this.replace(/[^\x00-\xff]/g,"***").length;
}

/**
*??????????
*????
*????????????      ??true
*?????????????????true
*????????              ??false     ????????????????
*/
String.prototype.isInteger = function()
{
    //??????????
    if(this == "")
        return true;
    if(/^(\-?)(\d+)$/.test(this))
        return true;
    else
        return false;
}

/**
*???????????
*????
*????????????      ??true
*??????????????  ??true
*????????              ??false     ???????????????????
*/
String.prototype.isDouble = function()
{
    //??????????
    if(this == "")
        return true;
    //???????????????
    if(this.indexOf(".") == -1)
    {
        if(this.isInteger(this) == true)
            return true;
        else
            return false;
    }
    else
    {
        if(/^(\-?)(\d+)(.{1})(\d+)$/g.test(this))
            return true;
        else
            return false;
    }
}

/**
*???????????
*????
*????????????           ??true
*??????????????       ??true
*????????                   ??false    ??????????????????yyyy-MM-dd?
*/
String.prototype.isDate = function()
{
   //??????????
    if(this == "")
        return true;
    if(!(/^(\d{4})-(\d{1,2})-(\d{1,2})$/.test(this))){
        return false;
     }
    var nums=this.split("-");
	var year = parseInt(nums[0],10);
	  var month = parseInt(nums[1].replace(/^0/,""),10);
	  var day = parseInt(nums[2].replace(/^0/,""),10);
	  if (month < 1 || month > 12) {
	    return false;
	  }
	  if (day < 1 || day > 31) {
	    return false;
	  }
	  if ((month == 4 || month == 6 || month == 9 || month == 11) && (day == 31)) {
	    return false;
	  }
	  if (month == 2) {
	    var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	    if (day>29 || (day == 29 && !leap)) {
	      return false;
	    }
	  }
	  return true;
	    

}

/**
*?????????
*????
*???????????????true
*?????????????false               ???????????????
*/
String.prototype.isEmpty = function()
{
    if(this.trim() == "")
        return true;
    else
        return false;
}


/**
*????????email?
*????
*????????????           ??true
*?????email???????      ??true
*??email????                  ??false    ???????Email???????
*/
String.prototype.isEmail = function()
{
		if(this == "")
        return false;
        
     if(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this))
        return true;
    else
        return false;
}

/**
*??????????
*????
*????????????           ??true
*?????????????         ??true
*?????????             	??false    ?????????????
*/
String.prototype.isAllChinese = function()
{
    //??????????
    if (this == "")
        return true;
    var pattern = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])*$/gi;
    if (pattern.test(this))
        return true;
    else
        return false;
}

/**
*??????????
*????
*????????????           ??true
*?????????????         ??true
*?????????             	??false    ?????????????
*/
String.prototype.isLetterOrNumber = function()
{
    //??????????
    if (this == "")
        return true;
    var pattern = /^\w+$/gi;
    if (pattern.test(this))
        return true;
    else
        return false;
		
}

String.prototype.toDate = function()
{
	if(this.isDate()){
    var arrDate = this.split("-");
    if(parseInt(arrDate[0],10) < 100)
        arrDate[0] = 2000 + parseInt(arrDate[0],10) + "";
    return  new Date(arrDate[0],(parseInt(arrDate[1],10) -1)+"",arrDate[2]);
	}
	return null;
}
String.prototype.isMobile = function()
{
		if(this == "")
        return false;
        
     if(/^\d{11}$/.test(this))
        return true;
    else
        return false;
}
String.prototype.isTel=function()
{ 
	
	/*var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; 
	if (!patrn.test(this)) return false;
	*/
	return true;
}
String.prototype.isPostalCode=function() 
{ 
	/*
	var patrn=/^[a-zA-Z0-9 ]{3,12}$/; 
	if (!patrn.test(this)) return false */
	return true
}

