﻿//var jq = jQuery.noConflict();

var S = function(){return document.getElementById(arguments[0]);}

S.apply = function(o, c, defaults){
    if(!o) return o;
    if(defaults){S.apply(o, defaults);}
    if(o && c && typeof c == 'object'){for(var p in c){o[p] = c[p];}}
     return o;
};

S.testStr = {
    string  :"^[^<>=\"\'\\\/]{1,LEN}$",
    tel     :"(^[0-9]{3,4}\\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^0[0-9]{10})|(^\\([0-9]{3,4}\\)[0-9]{3,8}$)|(^1[3|5][0-9]{9}$)",
    email   :"^[_a-zA-Z0-9]+@([_a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,3}$",
    same    :"^STR$"
};
S.config = function(config){
    config.pm = S.apply({dirs:-1,author:-1,dept:-1,topic:-1,pageSize:9,pageNo:1},config.pm);
    config.cp = S.apply({type:1,len:22},config.cp);
    S.apply(this,config,{
        ns:'syz',
        service:'art',
        method:'getArticle',
        getFileName:function(){
            var str = FileName[this.ns][this.service][this.method];
            if(!str) return '';
            return String.format(str,this.pm);
        }
    });
}
S.apply(S,{
    Request : function(name){return location.getParm(name);},
    findCookie : function(key){
        var content = decodeURI(document.cookie).split(";");
        for(var i=content.length - 1;i>=0 ;i--){
            if(content[i].indexOf(key)!=-1) return content[i];
        }
        return null;
    },
    getCookie : function(key){
        key = key.split(".");
        var content = this.findCookie(key[0]);
        if(!content) return null;
        if(!key[1]) return content.substring(content.indexOf("=")+1,content.length);
        content = content.substring(content.indexOf("=")+1,content.length).split("&");
        var str = null;
        for(var i=0;i<content.length;i++)if(content[i].indexOf(key[1]) != -1) str = content[i].split("=");
        if(!str) return null;
        else if(str[1].toLowerCase()=="false") return false;
        else if(str[1].toLowerCase()=="true") return true;
        else if(!isNaN(parseInt(str[1])))return parseInt(str[1]);
        else return str[1];
    },
    setCookie : function(key,value){
        key = key.split(".");
        var content = null;
        if(key[1]){
            content = this.findCookie(key[0]);
            if(!content) content = key[0]+"="+key[1]+"="+value;
            else if(content.indexOf(key[1])!=-1){
                    var cookies = content.substring(content.indexOf("=")+1,content.length).split("&");
                    for(i=0;i<cookies.length;i++){ 
                    if(cookies[i].indexOf(key[1])!=-1)
                    content = content.replace((cookies[i]),cookies[i].replace(/\=[\w|\W]+/,"="+value));}
                }
            else content +="&"+key[1]+"="+value;
        }
        else content = key[0]+"="+value;
        document.cookie = encodeURI(content);
    },
    Enum : function(config){
        S.apply(this,config,{
            Name : function(value){
                for(j in this) if(this[j]==value) return j;
            },
            toArray : function(){
                var ar = [];
                for(j in this) if(typeof(this[j])!='function' && typeof(this[j])!='object') ar.push([this[j],j]);
                return ar;
            }
        });
    },
    JSON : new(function(){
        var useHasOwn = !!{}.hasOwnProperty;
        var m = {"\b": '\\b',"\t": '\\t',"\n": '\\n',"\f": '\\f',"\r": '\\r','"' : '\\"',"\\": '\\\\'};
        var encodeString = function(s){
            if (/["\\\x00-\x1f]/.test(s)) {
            return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                var c = m[b];
                if(c) return c;
                c = b.charCodeAt();
                return "\\u00" +Math.floor(c / 16).toString(16) +(c % 16).toString(16);}) + '"';
            }
            return '"' + s + '"';
        };
        var encodeArray = function(o){
            var a = ["["], b, i, l = o.length, v;
            for (i = 0; i < l; i += 1) {
                v = o[i];
                switch (typeof v) {
                    case "undefined":
                    case "function":
                    case "unknown":
                    break;
                    default:
                    if (b) a.push(',');
                    a.push(v === null ? "null" : S.JSON.encode(v));
                    b = true;
                }
            }
            a.push("]");
            return a.join("");
        };
        this.encodeDate = function(o){return "\"\\/Date("+o.getTime()+")\\/\"";};
        this.encode = function(o){
            if(typeof o == "undefined" || o === null){
                return "null";
            }else if(Object.prototype.toString.apply(o) === '[object Array]'){
                return encodeArray(o);
            }else if(Object.prototype.toString.apply(o) === '[object Date]'){
                return S.JSON.encodeDate(o);
            }else if(typeof o == "string"){
                return encodeString(o);
            }else if(typeof o == "number"){ 
                return isFinite(o) ? String(o) : "null"; 
            }else if(typeof o == "boolean"){
                return String(o);
            }else {
                var a = ["{"], b, i, v; 
                for (i in o) {
                    if(!useHasOwn || o.hasOwnProperty(i)) 
                    {
                        v = o[i];
                        switch (typeof v) { 
                        case "undefined":
                        case "function": 
                        case "unknown":
                        break;
                        default:
                            if(b) a.push(',');
                            a.push(this.encode(i), ":", v === null ? "null" : this.encode(v));
                            b = true;
                        }
                    }
                }
                a.push("}");
                return a.join("");
            }
        };
        this.transDate = function(value){
            var t = new RegExp(/\/Date\((\d*)\)\//);
            for(var i in value){
                if(typeof(value[i])=='object')this.transDate(value[i]);
                else if(t.test(value[i]))
                    value[i] = eval("new "+eval(value[i]).source);
            }
            return value;
        }
        this.decode = function(json){
            var obj = eval("(" + json + ')');
            return this.transDate(obj.d || obj);
        };

    })()
});

location.getParm = function(name){var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");var r = this.search.substr(1).match(reg);if (r!=null) return unescape(r[2]); return null;},
location.getPage = function(){return this.pathname;}

Date.prototype.format = function(fmt) {
    var week = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; 
    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(), //毫秒 
    "w+" : week[this.getDay()]    
    };
    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;         
}
String.prototype.Limit = function(len){
    var ss = [];k = 0;flag=false;
    for(l=0;l<this.length;l++){ss.push(this.charAt(l));
        if( this.charCodeAt(l) > 255) k++; else{if(flag) k++;flag = !flag;}
        if (k > len - 1){ss.push("..");break;}}
    return ss.join('');
}
String.format = function(str,os){for(var i in os){str = str.replace('{'+i+'}',os[i]);}return str;}

S.Base = new S.Enum({
    web     : './',
    temp    : '/temp/',
    files   : '/Files/'
});
ZPGStatus = new S.Enum({
    准备:0,
    公告:1,
    挂牌:2,
    结束:3,
    转拍:4,
    成交:5,
    流拍:6,
    无:7,  
    Name : function(value){
        for(j in this) if(this[j]==value) switch(value){
            case 1: return '<span style="color:blue;">'+j+'</span>';
            case 2: return '<span style="color:green;">'+j+'</span>';
            default: return '<span style="color:red;">'+j+'</span>';
        }
    }
});
GKZJtype = new S.Enum({
    身份证:0,
    其他证件:1
});
 GKGetMode = new S.Enum({
    邮寄:0,
    快递:1,
    电子邮件:2,
    传真:3,
    自行领取:4
});
GKType = new S.Enum({
    纸面:0,
    电子邮件:1,
    光盘:2,
    磁盘:3
});
DataType = new S.Enum({
    网站目录:0,
    部门目录:1,
    专题目录:2,
    管理目录:3,
    普通文章:4,
    咨询回复:5,
    调查投票:6,
    附件信息:7,
    交易信息:8,
    农土流转:9,
    其他信息:10
});
ArticleType = new S.Enum({
    普通文章:0,
    图片新闻:1,
    文件下载:2,
    视频新闻:3
});
ArticleStatus = new S.Enum({
    草稿:0,
    待审核:1,
    退稿:2,
    待发布:3,
    已发布:4,
    下线归档:5,
    无:6
});
ReferStatus = new S.Enum({
    待回复:0,
    待发布:1,
    已发布:2,
    无:3
});

