/**
 * @author YangChao
 */
/**
 * 时间获取
 * @param {Object} formatStr yyyy|YYYY|yy|YY|MM|M|w|W|dd|DD|d|D|hh|HH|h|mm|m|ss|SS|s|S
 */
Date.prototype.Format = function(formatStr){
	var str = formatStr;
	var Week = ['日', '一', '二', '三', '四', '五', '六'];
	
	str = str.replace(/yyyy|YYYY/, this.getFullYear());
	str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100));
	
	str = str.replace(/MM/, (this.getMonth()+1) > 9 ? (this.getMonth()+1).toString() : '0' + (this.getMonth()+1));
	str = str.replace(/M/g, (this.getMonth()+1));
	
	str = str.replace(/w|W/g, Week[this.getDay()]);
	
	str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
	str = str.replace(/d|D/g, this.getDate());
	
	str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
	str = str.replace(/h|H/g, this.getHours());
	str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
	str = str.replace(/m/g, this.getMinutes());
	
	str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
	str = str.replace(/s|S/g, this.getSeconds());
	
	return str;
}

var Cookie={
    set:function(name,value,daysToExpire){
        var expire = '';
        if (daysToExpire != undefined) {
          var d = new Date();
          d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
          expire = '; expires=' + d.toGMTString();
        }
        return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
    },
    get:function(name){
        var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
        return (cookie ? unescape(cookie[2]) : null);
    },
    erase:function(){
        var cookie = Cookie.get(name) || true;
        Cookie.set(name, '', -1);
        return cookie;
    },
    accept: function() {
        if (typeof navigator.cookieEnabled=='boolean') {
              return navigator.cookieEnabled;
        }
        Cookie.set('_test', '1');
        return (Cookie.erase('_test')=='1');
      }
}

function h(s){$(s).hide();}
function s(s){$(s).show();}
/**
 * 时间戳
 */
function getTimeSpan()
{
	return (new Date()).getTime();
}
/**		
* 去除多余空格函数
* 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, "");
}

function isNumber(oNum){
	if (!oNum) 
		return false;
	var strP = /^\d+(\.\d+)?$/;
	if (!strP.test(oNum)) 
		return false;
	try {
		if (parseFloat(oNum) != oNum) 
			return false;
	} 
	catch (ex) {
		return false;
	}
	return true;
}

/**
 * 判断是否手机号码
 * @param {Object} account
 */
function isTelecom(account){
	if(!(account.length==11 || account.length==12 || account.length==8)) return false;
    var reg0 = /^13\d{9}$/; //130--139。至少7位
    var reg1 = /^15\d{9}$/; //联通153。至少7位
    var reg2 = /^18\d{9}$/; //联通153。至少7位
    var reg3 = /\d{12}$/; //小灵通
    var reg4 = /\d{8}$/; //本地固话
    return reg0.test(account) || reg1.test(account)|| reg2.test(account)|| reg3.test(account)|| reg4.test(account);
}

 function IsMobile(mobile)
 {
         if(mobile.length==0)
         {
            return false;
         }    
         if(mobile.length!=11 || mobile.length!=12)
         {
             return false;
         }
        
         var myreg = /^(((13[0-9]{1})|15)+\d{9})$/;
         if(!myreg.test(mobile))
         {
             return false;
         }
		 return true;
}
 
 function isMobile(account)
 {
		if(!(account.length==11 || account.length==12 || account.length==8)) return false;
	    var reg0 = /^13\d{9}$/; //130--139。至少7位
	    var reg1 = /^15\d{9}$/; //联通153。至少7位
	    var reg2 = /^18\d{9}$/; //联通153。至少7位
	    var reg3 = /\d{12}$/; //小灵通
	    var reg4 = /\d{8}$/; //本地固话
	    return reg0.test(account) || reg1.test(account)|| reg2.test(account)|| reg3.test(account)|| reg4.test(account);
}
 
 /**
  * 判断是否EMAIL地址
  * @param {Object} emailStr
  */
 function isEmail(emailStr){
     var emailPat = /^(.+)@(.+)$/;
     var matchArray = emailStr.match(emailPat);
     if (matchArray == null) 
         return false;
     else 
         return true;
 }