// v1.1 by txdnet.cn 2011.03.06
Date.prototype.Pattern=function(fmt){
    var o = {
    "M+" : this.getMonth()+1, //月份
    "d+" : this.getDate(), //日
    "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
    "H+" : this.getHours(), //小时
    "m+" : this.getMinutes(), //分
    "s+" : this.getSeconds(), //秒
    "q+" : Math.floor((this.getMonth()+3)/3), //季度
    "S" : this.getMilliseconds() //毫秒
    };
    var week = {"0" : "\u65e5","1" : "\u4e00","2" : "\u4e8c","3" : "\u4e09","4" : "\u56db","5" : "\u4e94","6" : "\u516d"};
    if(/(y+)/.test(fmt)){fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));}
    if(/(E+)/.test(fmt)){fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\u661f\u671f" : "\u5468") : "")+week[this.getDay()+""]);}
    for(var k in o){
      if(new RegExp("("+ k +")").test(fmt)){
         fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
      }
    }
    return fmt;
};
var ut = {
    e:function(id){var obj = document.getElementById(id);if(va.isnull(obj)){return null;}return obj;},
    n:function(na){return document.getElementsByName(na);},
    v:function(id){return ut.trim(ut.e(id).value);},
    h:function(id){return ut.e(id).innerHTML;},
    html:function(id,s){ut.e(id).innerHTML=s;},
    show:function(s){var ida=s.toString().split(' ');for(var i=0; i<ida.length; i++)this.e(ida[i]).style.display='block';},
    hide:function(s){var ida=s.toString().split(' ');for(var i=0; i<ida.length; i++)this.e(ida[i]).style.display='none';},
    swap:function(b){var v=ut.e(b).style.display;ut.e(b).style.display=(v=='block')?'none':'block';},
    trim:function(s){return s.replace(/^\s+|\s+$/g,"");},
    cutstr:function(s,m){return (s.length>m)?(s.substring(0,m-2)+'...'):(s);},
    dec:function(s){return decodeURIComponent(s);},
    enc:function(s){return encodeURIComponent(s);},
    reload:function(s){ if(va.isnull(s)){location.reload();}else{location.replace(s);} },
    gopage:function(s){top.location.replace(s);return;/* location.href=s; */},
    get:function(q){var v="";var s = location.href;s = s.replace("?","?&").split("&");for(i=1;i<s.length;i++){if(s[i].indexOf(q+"=")==0)v = s[i].replace(q+"=","");}v = ( typeof(v) == "undefined" )?'':v;if( v.indexOf("#")>=0)v = v.substring(0,v.indexOf("#"));return v;},
    delay:function(f){setTimeout(f,600);},
    wait:function(f,ms){setTimeout(f,ms);},
    swapsel:function(na){var ds = ut.n(na);for(var i=0; i<ds.length; i++){ds[i].checked=ds[i].checked==true?false:true;}},
    getselv:function(na){var ds = ut.n(na);var sm =[];for(var i=0; i<ds.length; i++){if(ds[i].checked){sm.push(ds[i].value);}}return sm.join('-');},
    getselv1:function(na){var ds = ut.n(na);var sm =[];for(var i=0; i<ds.length; i++){if(ds[i].checked){alert('bb');sm.push(document.getElementById('parent'+ds[i].value).value);}}return sm.join('-');},
    lower:function(s){return s.toLowerCase();},
    upper:function(s){return s.toUpperCase();},
    parseMs:function(datestr){
        var d  = new Date();var d1 =  datestr.split(' ');var a = d1[0].split('-');var b = d1[1].split(':');
        d.setFullYear(Number(a[0]), Number(a[1])-1, Number(a[2]));d.setHours(Number(b[0]), Number(b[1]), Number(b[2]), 1);
        return d.getTime();
    },
parseDate:function(ms){return (new Date(ms)).Pattern("yyyy-MM-dd HH:mm:ss");},
getTime:function(){
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
month=(parseInt(month)<10)?('0'+month.toString()):month;
var day = now.getDate();
day=(parseInt(day)<10)?('0'+day.toString()):day;
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
return year+"年" + month + "月" + day + "日 "+weekday[now.getDay()];
},
expdate:function(days, hours, minutes){
var expDate = new Date();
if(typeof(days) == "number" && typeof(hours) == "number" && typeof(hours) == "number"){
expDate.setDate(expDate.getDate() + parseInt(days));
expDate.setHours(expDate.getHours() + parseInt(hours));
expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
return expDate.toGMTString();}},
    setCookie:function(name, value, expires, path, domain, secure){
document.cookie = name + "=" + encodeURIComponent(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") +((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    },
getCookie:function(name){
var cookies = document.cookie.split( ';' );var cookie = '';
for(var i=0; i<cookies.length; i++){
cookie = cookies[i].split('=');
if(cookie[0].replace(/^\s+|\s+$/g, '') == name) {return (cookie.length <= 1) ? "" : decodeURIComponent(cookie[1].replace(/^\s+|\s+$/g, ''));}}
return null;},
delCookie:function(name){ut.setCookie(name,"", ut.expdate(0, 0, 0), '/', def.domain);},
copy:function(o){var el = ut.e(o);var rng = document.body.createTextRange();rng.moveToElementText(el);rng.scrollIntoView();rng.select();rng.execCommand("Copy");rng.collapse(false);alert("复制成功!");},
outpage:function(pn,r,cmd,pgid,ls,step){
        var rn = Number(r);
        var pc =(rn%ls==0)?parseInt(rn/ls):parseInt(rn/ls)+1;
        if(pn>pc || pn<1 || pc==1){ut.html(pgid, '');return;}
        var p1 = (pn==1)?1:(pn-1);
        var p2 = (pn<pc)?(pn+1):pc;
        var fp = (pn<2)?'':'<a href="#gopage" onclick="'+cmd+'(1,'+rn+');">首页</a> ';
        var pre = (pn<=2)?'':'<a href="#gopage" onclick="'+cmd+'('+p1+','+rn+');">上一页</a> ';
        var nex = (pn>pc-2)?'':' <a href="#gopage" onclick="'+cmd+'('+p2+','+rn+');">下一页</a> ';
        var ep = (pn>=pc)?'':'<a href="#gopage" onclick="'+cmd+'('+pc+','+rn+');">末页</a> ';
        var rt ='';
        var u ='<a href="#gopage" onclick="'+cmd+'(@pno,'+rn+');">[@pno]</a> ';
        if ( (pn<=pc) && (pn>=1) ){
        var k =(parseInt(pn/step))*step +1;
        if( k+step-1 <= pc ){
            for (var j=0 ;j<step; j++){rt += u.replace(/@pno/g,k);k++;}
        }else{
            for(var i=k ; i<= pc ; i++){rt += u.replace(/@pno/g,i);}
        }
         }
       var pt =[fp,pre,'第',pn,'页 ',rt,' 共',pc,'页', nex,ep].join('') ;
        ut.html(pgid, pt);
},
r:function(){return Math.random();},
rndint:function(b,e){return parseInt( b + parseInt( Math.random()*(e-b) ) );},
doxCall:function(u,p,c,f){
$.ajax({type:"GET",cache:c,url:u,dataType:"script",success:function(){var x= (new Function("return "+p))();f(x);}});
},
chkWn:function(e,v){var out = $('#'+v);var ct = $('#'+e);ct.keyup(function(){out.html('当前有:'+ct.val().length+'个字符');});}
};
var va={
    tint:function(s){return (/^[0-9]{1,2}$/).test(s);},
    mint:function(s){return (/^[0-9\-]{1,6}$/).test(s);},
    id:function(s){return (/^[0-9]{1,20}$/).test(s);},
    isInt:function(s){return (/^[1-9][0-9]{1,20}$/).test(s);},
    price:function(s){return (/^([0-9]{1,4})\.([0-9]{1,2})$/).test(s);},
    email:function(s){return (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(s);},
    key:function(s){return (/^[a-zA-Z0-9_\-]{6,20}$/).test(s);},
    name:function(s){return (/^[a-zA-Z0-9\s,\/\-\u4E00-\u9FA5]{2,16}$/).test(s);},
    title:function(s){return (/^[a-zA-Z0-9，：•·。\s,“”《》——、\.\/\-\u4E00-\u9FA5]{2,32}$/).test(s);},
    phone:function(s){return (/^[0-9\-]{10,16}$/).test(s);},
    nick:function(s){return (/^[a-zA-Z0-9\u4E00-\u9FA5]{2,16}$/).test(s);},
    code:function(s){return (/^[a-zA-Z0-9]{4,}$/).test(s);},
    date:function(s){return (/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/).test(s);},
    dateTime:function(s){return (/^([0-9]{4})-([0-9]{2})-([0-9]{2})\s([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})$/).test(s);},
    pic:function(s){return (/^.+.(jpg|png)$/i).test(s);},
    url:function(s){return (/^http[s]?:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/i).test(s);},
    isnull:function(exp){if(exp===0 ){return false;}else if(exp==null || typeof(exp)=="undefined" || !exp  || exp=='' || exp=='null'){return true;}else{return false;}},
    keyrank:function(s){return s.replace(/^(?:(?=.{4})(?=.*([a-z])|.)(?=.*([A-Z])|.)(?=.*(\d)|.)(?=.*(\W)|.).*|.*)$/, "$1$2$3$4").length;}
};
var filter={
    html:function(s){
        if(va.isnull(s))return '';
        var t=ut.trim(s);
        return t.replace(/&/g,'&amp;').replace(/[“”‘’']{1,}/g,'"').replace(/。/g,'.').replace(/[，、]{1,}/g,',').replace(/…/g,'.')
        .replace(/；/g,';').replace(/：/g,':').replace(/？/g,'?').replace(/（/g,'(').replace(/）/g,')').replace(/！/g,'!').replace(/[〈<（]{1,}/g,'&lt;').replace(/[〉>）]{1,}/g,'&gt;')
        .replace(/[\r\f\t]{1,}/g,'').replace(/[\n]{1,}/g,'<br>');
    },
    txt:function(s){
      if(va.isnull(s))return '';
      var t=ut.trim(s);
      return t.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/<br>/g,'\n');
    },
    script:function(s){
        if(va.isnull(s))return '';
        var t=ut.trim(s);
	return t.replace(/<\/?script[^>]*>/g,"").replace(/(javascript|jscript|vbscript|vbs):/g,"").replace(/on(.{3,9})=/g,"").replace(/[\r\n\f\t\b]{1,}/g,"");
    },
    clrXml:function(s){
        if(va.isnull(s))return '';var t=ut.trim(s);
        return t.replace(/<[^>]+>/g,"").replace(/[\r\n\f\t\b]{1,}/g,"");
    }
};
var def = {
    chr:'-',
    at:'@',
    limitnum:200,
    listsize:20,
    pagestep:10,
    domain:'.habays.com'
};
var win={open:function(s){window.open(s, '_blank', 'height=620, width=970, top=20, left=90, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');},
    close:function(){var ua=navigator.userAgent;var ie=(navigator.appName=="Microsoft Internet Explorer")?(true):(false);
if(ie){var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
if(IEversion< 5.5){var str  = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
str += '<param name="Command" value="Close"></object>';document.body.insertAdjacentHTML("beforeEnd", str);
document.all.noTipClose.Click();document.all.WinCls.Click();
}else{window.opener ='me';window.close();}
}else{window.close();}
    },
    topcls:function(){window.parent.window.close();},
    chk:function(){
    ut.setCookie('ts','1001',ut.expdate(0, 0, 1),'/',def.domain);
    var s = ut.getCookie('ts');
    ut.delCookie('ts');
    if(va.isnull(s)){alert('您的浏览器不支持cookie,部分功能将无法使用.');return false;}else{return true;}
    }
};
var J = {
    StrToJSON: function(str) {var a;if(va.isnull(str)){return null;}else{eval('a=' + str.toString() + ';');return a;}},
    JsonToStr: function(obj) {
        switch(typeof(obj))
        {
            case 'object':
                var ret = [];
                if (obj instanceof Array){
                    for (var i = 0, len = obj.length; i < len; i++){ret.push(J.JsonToStr(obj[i]));}
                    return '[' + ret.join(',') + ']';
                }
                else if (obj instanceof RegExp){
                    return obj.toString();
                }else{
                    for (var a in obj){
                        ret.push(a + ':' + J.JsonToStr(obj[a]));
                    }
                    return '{' + ret.join(',') + '}';
                }
            case 'function':return 'function() {}';
            case 'number':return obj.toString();
            case 'string':return "\"" + obj.replace(/(\\|\")/g, "\\$1").replace(/\n|\r|\t/g, function(a) {return ("\n"==a)?"\\n":("\r"==a)?"\\r":("\t"==a)?"\\t":"";}) + "\"";
            case 'boolean':return obj.toString();
            default:return obj.toString();
        }
    }
};
var LdShow = function(msg,sl) {
    if(!va.isnull(sl) && window.top.location.href.indexOf(sl)<0){return;}
    var obj = document.getElementById("jq_lddiv");
    if (va.isnull(obj)) {
        var width = 250;
        var height = 34;
        var top = document.documentElement.scrollTop + ($(window).height() - height) / 2;
        var left = ($(window).width() - width) / 2;
        var jqWin = $("<div id='jq_lddiv'>" + msg + "</div>");
        var _css = {"background": "#E8F3FF", "position": "absolute", "overflow": "hidden", "z-index": "9", "width": width + "px", "height": height + "px", "top": top, "left": left, "border": "1px solid #B9DCFF", "text-align": "center", "line-height": "30px", "font-size": "12px", "display": "none", "color": "#005BB7"};
        jqWin.css(_css);
        jqWin.appendTo("body");
        jqWin.show();
    }else{
        $('#jq_lddiv').html(msg);
    }
};
var LdClose = function() {ut.wait(function(){$('#jq_lddiv').remove();},1000);};
var goTab = function(m,n){
var menu=document.getElementById("tab"+m).getElementsByTagName("li");
var showli=document.getElementById("tablist"+m).getElementsByTagName("li");
	for(i=0;i<menu.length;i++)
	{
		menu[i].className=i==n?"c":"";
		showli[i].style.display=i==n?"block":"none";
	}
};
