(function(win, J, undefined) {
    if (win[J] === undefined) win[J] = {};
    J = win[J];
    J.version = "1.1.0"; (function() {
        var initializing = false,
        fnTest = /xyz/.test(function() {
            xyz;
        }) ? /\b_super\b/: /.*/;
        function Class() {}
        Class.extend = function(prop) {
            var _super = this.prototype;
            initializing = true;
            var prototype = new this();
            initializing = false;
            for (var name in prop) {
                prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn) {
                    return function() {
                        var tmp = this._super;
                        this._super = _super[name];
                        var ret = fn.apply(this, arguments);
                        this._super = tmp;
                        return ret;
                    };
                })(name, prop[name]) : prop[name];
            }
            function Klass() {
                if (!initializing && this.init) this.init.apply(this, arguments);
            }
            Klass.prototype = prototype;
            Klass.constructor = Class;
            Klass.extend = arguments.callee;
            return Klass;
        };
        J.Class = Class;
    })();
})(window, "J16");
J16.util = window.J16.util || {
    console: function(type, message) {
        if (window.console) window.console[type](message);
    },
    getType: function(o) {
        var s = Object.prototype.toString,
        t = {
            'undefined': 'undefined',
            'number': 'number',
            'boolean': 'boolean',
            'string': 'string',
            "[object Function]": "function",
            "[object RegExp]": "regexp",
            "[object Array]": "array",
            "[object Date]": "date",
            "[object Error]": "error"
        };
        return t[typeof o] || t[s.call(o)] || (o ? 'object': 'null');
    },
    getDomain: function() {
        return "." + location.host.split(".").slice( - 2).join(".");
    },
    setHome: function(o, r) {
        o.target = "_self";
        var a = "url(#default#homepage)",
        b = "http://bbs.1616.net/thread-1913-1-4.html";
        try {
            if (document.all && !external.max_version) {
                o.style.behavior = a;
                o.setHomePage(r ? r: "http://www" + this.getDomain());
            } else window.open(b);
        } catch(e) {
            if (document.all) {
                o.style.behavior = a;
                o.setHomePage(r ? r: "http://www" + this.getDomain());
            } else window.open(b);
        }
        return false;
    },
    getQueryString: function(name) {
        var reg = new RegExp("[?&]" + name + "=([^&]*)");
        var r = location.search.match(reg);
        return r ? r[1] : "";
    },
    hitTest: function(elem1, elem2) {
        var pos1 = elem1.getBoundingClientRect(),
        pos2 = elem2.getBoundingClientRect(),
        x1 = pos1.left,
        y1 = pos1.top,
        x2 = pos2.left,
        y2 = pos2.top,
        w1 = elem1.offsetWidth,
        h1 = elem1.offsetHeight,
        w2 = elem2.offsetWidth,
        h2 = elem2.offsetHeight;
        return (x1 < x2 ? x1 + w1 > x2: x1 < x2 + w2) && (y1 < y2 ? y1 + h1 > y2: y1 < y2 + h2);
    },
    mt: (function() {
        function parse(s) {
            var a = [];
            var re_t = /\{\$((?:[^\\}]|\\[\s\S])+)\}/;
            var re_s = /\\([\s\S])/g;
            var esc = function(s) {
                return s.replace(re_s, '$1');
            };
            var re_c = /(?:^|[^\\])(?:\\\\)*$/;
            var t, m, n;
            while (t = re_t.exec(s)) {
                n = (m = t.index) + t[0].length;
                if (re_c.test(s.substr(0, m))) {
                    a.push(esc(s.substr(0, m)));
                    a.push([esc(t[1])]);
                } else a.push(esc(s.substr(0, n)));
                s = s.substr(n);
            }
            return a;
        }
        function show(s, o) {
            var a = parse(s);
            for (var i = 0; i < a.length; i++) if (typeof a[i] == 'object') a[i] = o[a[i]] || '';
            return a.join('');
        }
        function show2(s, o) {
            return s.replace(/\{\$([^}]+)\}/g,
            function(a, b) {
                return o[b] || '';
            });
        }
        return function(template, data, adv) {
            var f = adv ? show: show2;
            if (! (data instanceof Array)) return f(template, data);
            var s = '';
            for (var i = 0; i < data.length; i++) s += f(templet, data[i]);
            return s;
        };
    })(),
    guid: (function() {
        if (typeof document.documentElement.uniqueID !== 'undefined') {
            return function(element) {
                return element.uniqueID;
            };
        }
        var uid = 0;
        return function(element) {
            return element.__uniqueID || (element.__uniqueID = 'uniqueID__' + uid++);
        };
    })()
};
J16.util.cookie = {
    set: function(n, v, e, p, d, s) {
        if (!e) e = 365;
        if (!p) p = '/';
        e = e * 1000 * 60 * 60 * 24;
        var e_date = new Date(new Date().getTime() + (e));
        document.cookie = n + '=' + encodeURIComponent(v) + ((e) ? ';expires=' + e_date.toGMTString() : '') + ((p) ? ';path=' + p: '') + ((d) ? ';domain=' + d: '') + ((s) ? ';secure': '');
    },
    get: function(n) {
        var c = document.cookie.split("; ");
        for (var i = 0; i < c.length; i++) {
            var p = c[i].split("=");
            if (n == p[0]) try {
                return decodeURIComponent(p[1])
            } catch(e) {
                return null
            }
        }
        return null;
    },
    del: function(name, path, domain) {
        document.cookie = name + "=1" + ((path) ? ";path=" + path: "") + ((domain) ? ";domain=" + domain: "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
};
J16.util.json = {
    obj2str: function(o) {
        var r = [];
        if (typeof o == "string") return quote(o);
        if (typeof o == "undefined") return "undefined";
        if (typeof o == "object") {
            if (o === null) return "null";
            else if (!o.sort) {
                for (var i in o) r.push(this.obj2str(i) + ":" + this.obj2str(o[i]));
                r = "{" + r.join() + "}";
            } else {
                for (var i = 0; i < o.length; i++) r.push(this.obj2str(o[i]));
                r = "[" + r.join() + "]";
            }
            return r;
        }
        return o.toString();
        function quote(string) {
            var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
            var meta = {
                '\b': '\\b',
                '\t': '\\t',
                '\n': '\\n',
                '\f': '\\f',
                '\r': '\\r',
                '"': '\\"',
                '\\': '\\\\'
            };
            escapable.lastIndex = 0;
            return escapable.test(string) ? '"' + string.replace(escapable,
            function(a) {
                var c = meta[a];
                return typeof c === 'string' ? c: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice( - 4);
            }) + '"': '"' + string + '"';
        }
    },
    str2obj: function(str) {
        var undefined;
        try {
            if (str) {
                return eval('(' + str + ')');
            }
        } catch(ex) {}
        return null;
    }
};
J16.util.string = {
    cut: function(s, length, postfix) {
        if (typeof(s) != "string") return s;
        postfix = postfix || "";
        if (!s || !length) {
            return "";
        }
        var len = 0,
        temp = "";
        for (var i = 0; i < s.length; i++) {
            if (s.charCodeAt(i) > 255) {
                len += 2;
            } else {
                len++;
            }
            if (len > length) {
                return temp + postfix;
            }
            temp += s.charAt(i);
        }
        return s;
    }
};
J16.util.array = {
    removeItem: function(array, dx) {
        if (isNaN(dx) || dx > array.length || dx < 0) {
            return false;
        }
        return array.splice(dx, 1);
    }
}; (function(win, undefined) {
    var Dialog = J16.Class.extend({
        options: {
            html: '',
            iframe: '',
            title: '标题',
            isShowLoading: 0,
            width: 200,
            height: 80,
            onshow: function() {},
            onIframeLoaded: function() {},
            onclose: function() {},
            top: -1,
            left: -1,
            opacity: '.5',
            hideType: 'display',
            temp: "<div id='alert1616_main'><table  cellspacing=\"0\"><tr class=\"alert_top\"><td class=\"lt\">&nbsp;</td><td class=\"ct\"><h2 id=\"alert1616_title\"></h2></td><td class=\"rt\">&nbsp;</td></tr><tr class=\"alert_content\"><td class=\"lc\">&nbsp;</td><td class=\"cc\"><div id=\"alert1616_content\"></div></td><td class=\"rc\">&nbsp;</td></tr><tr class=\"alert_bottom\"><td class=\"lb\">&nbsp;</td><td class=\"cb\"></td><td class=\"rb\">&nbsp;</td></tr></table><div id=\"alert1616_closer\" title=\"关闭\"></div></div>"
        },
        init: function(opt) {
            this.setOpt(opt);
        },
        setOpt: function(opt) {
            $.extend(this.options, opt)
        },
        runOnce: function(inner) {
            var op = this.options.opacity;
            $('<div id="alert1616_cover" style="opacity:' + op + '; filter:alpha(opacity=' + (op * 100) + ');"></div>').appendTo($('body'));
            $(inner).appendTo($('body'));
            this.destroy(1);
        },
        render: function() {
            var opt = this.options;
            if (opt.iframe != '') {
                var loading = opt.isShowLoading ? "<img style='position:absolute;top:50%;margin-top:-40px;left:50%; margin-left:-40px;' src='http://r.9533.com/iplatform/img/loading2.gif'/>": "";
                $('#alert1616_content').html(loading + "<iframe frameborder='0' scrolling='no' style='height:100%; width:100%;' src=\"" + opt.iframe + "\"></iframe>");
            } else {
                $('#alert1616_content').html(opt.html);
            }
            $('#alert1616_title').html(opt.title);
            $('#alert1616_content').height(opt.height).width(opt.width);
        },
        _setCoverWH: function() {
            $("#alert1616_cover").css({
                height: "100%",
                width: "100%"
            })
        },
        _setPos: function(opt) {
            var _h = win.innerHeight || document.documentElement.clientHeight;
            var _w = document.documentElement.offsetWidth;
            this.posRecord = document.all && navigator.userAgent.indexOf('MSIE 6') != -1 ? {
                left: opt.left == -1 ? (_w - opt.width - 28) / 2 + document.documentElement.scrollLeft: opt.left,
                top: opt.top == -1 ? (_h - opt.height - 36) / 2 + document.documentElement.scrollTop: opt.top,
                zIndex: 10000
            }: {
                left: opt.left == -1 ? (_w - opt.width - (document.all ? 28 : 12)) / 2 : opt.left,
                top: opt.top == -1 ? (_h - opt.height - (document.all ? 36 : 54)) / 2 : opt.top,
                zIndex: 10000
            };
            $('#alert1616_main').css(this.posRecord);
        },
        bindEvents: function() {
            var opt = this.options,
            _this = this;
            $("#alert1616_closer").unbind("click").click(function() {
                _this.destroy()
            });
            if (opt.iframe != '') {
                $('#alert1616_content iframe').unbind("load").bind('load',
                function() {
                    $('#alert1616_content img').hide();
                    var _win = $(this)[0].contentWindow;
                    opt.onIframeLoaded && opt.onIframeLoaded.call(_win);
                    var link = _win.document.links,
                    len = link.length;
                    setTimeout(function() {
                        for (var i = 0; i < len; i++) {
                            if (link[i].className.toLowerCase().indexOf('alert1616') != -1) {
                                document.all ? link[i].attachEvent("onclick", setEvent) : link[i].addEventListener("click", setEvent, false);
                            }
                        }
                    },
                    10);
                })
            }
            function setEvent(e) {
                $('#alert1616_content img').show();
                var e = e || win.event;
                var tar = e.target || e.srcElement,
                t = tar.getAttribute("title"),
                h = tar.getAttribute("_height"),
                w = tar.getAttribute("_width");
                t && $('#alert1616_title').html(t);
                h && $('#alert1616_content').height(h);
                w && $('#alert1616_content').width(w);
            }
            if (navigator.userAgent.indexOf('MSIE 6') != -1) {
                $(win).unbind("scroll").scroll(function() {
                    _this._setPos(opt)
                });
            }
            $(win).unbind("resize").resize(function() {
                _this._setPos(opt);
                _this._setCoverWH();
            });
        },
        show: function(opt) {
            if (!$('#alertstyle')[0]) {
                var link = document.createElement('link');
                link.setAttribute('rel', 'stylesheet');
                link.setAttribute('type', 'text/css');
                link.id = 'alertstyle';
                link.href = 'http://r.9533.com/iplatform/img/tc.css';
                $('head')[0].appendChild(link);
            }
            if (opt) this.setOpt(opt);
            if (!$('#alert1616_cover')[0]) {
                this.runOnce(this.options.temp);
            }
            this.render();
            this.display();
            this.bindEvents();
        },
        display: function() {
            this._setPos(this.options);
            $('#alert1616_main').show();
            $('#alert1616_cover').show();
            this.options.onshow.call(this);
        },
        destroy: function(notRunClose) {
            if (this.options.hideType != 'display') {
                $('#alert1616_main').css({
                    top: '-999px'
                });
            } else {
                $('#alert1616_main').hide();
            }
            $('#alert1616_cover').hide();
            notRunClose || this.options.onclose.call(this);
        }
    });
    J16.util.dialog = win.J16.util.dialog || {
        show: function(opt) {
            var d = arguments.callee.Al || (arguments.callee.Al = new Dialog());
            opt ? d.show(opt) : d.display();
            if (!J16.util.dialog.hide) {
                J16.util.dialog.hide = function(b) {
                    d.destroy(b)
                }
            }
        }
    }
})(window);
var cfg = {
    view: 'summ',
    pagesize: 4,
    order: 'createtime',
    hmsj: 0,
    weibo: 0,
    autosave: 0,
    _email: '',
    _emailLimit: {
        date: 0,
        note: 0,
        attach: 0
    }
};
var appName = 'notebook2';
var theView = null;
var updated = 3;
var jsList1;
var jsList2;
var jsCount;
var jsObj;
var page = 1;
var schk;
var gp_n;
var stk = [];
var busy = false;
var hasJs = false;
var swHeight = 200;
var swWidth = 400;
var lastSave = '';
var isLogin;
var showLoginWindow;
if (self == parent) {
    isLogin = true;
    showLoginWindow = function() {
        alert('请先登录');
    };
} else {
    isLogin = parent.qtcms_login.isLogin;
    showLoginWindow = function() {
		parent.User_login();
        //parent.showLoginWindow("请先登录再进行操作:");
    };
}
function showWindow(opts) {
    J16.util.dialog.show(opts);
}
function hideWindow() {
    J16.util.dialog.hide();
}
function updateHeight() {
    if (self != parent) {
        getIns(appName).__updateHeight(true);
    }
}
function calcTop() {
    return $(parent.document).scrollTop() + 20;
}
function ajaxPost(url, data, cb) {
    if (busy) return;
    busy = true;
    $.post(url, data, cb);
}
function ajaxGet(url, cb) {
    if (busy) return;
    busy = true;
    $.get(url + (url.indexOf('?') < 0 ? '?': '&') + 'r=' + ( + new Date), cb);
}
function $id(s) {
    return document.getElementById(s);
}
function htmlEncode(s) {
    return (s + '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
function br(s) {
    return s.replace(/\r?\n/g, '<br>');
}
function getCookie(name) {
    var re = new RegExp('(?:^| )' + name + '=([^;]*)');
    var a = document.cookie.match(re);
    if (!a) return '';
    return unescape(a[1]);
}
function setCookie(name, value, days) {
    var d = new Date;
    d.setDate(d.getDate() + days);
    document.cookie = name + '=' + escape(value) + '; expires=' + d.toGMTString();
}
function needLogin() {
    showLoginWindow();
    return false;
}
function returnFalse() {
    return false;
}
function json_decode(s) {
    return eval('0,' + s);
}
function cut(s) {
    var N = 40;
    var r = '',
    i, L = s.length;
    if (L <= N / 2) return s;
    for (var n = i = 0; n < N && i < L; i++) n += s.charCodeAt(i) > 255 ? 2 : 1;
    return s.substring(0, i) + (n >= N && i < L ? '...': '');
}
function updCfg(s) {
    if (!s) return;
    cfg = s;
    if (s.autosave) fireAutosave();
    theView = cfg.view;
    togglePan(s.hmsj);
    if (s._email) document.fmexport.email.value = s._email;
    $('#dateh').text(s.order == 'createtime' ? '创建时间': '修改时间');
}
function updCfgForm() {
    var f = document.fmcfg;
    f.view[cfg.view == 'summ' ? 1 : 0].checked = true;
    var sel = f.pagesize;
    var b = false;
    for (var i = sel.length,
    n = cfg.pagesize; i--;) if (sel.options[i].value == n) {
        sel.selectedIndex = i;
        b = true;
        break;
    }
    if (!b) {
        sel.options.add(new Option(n, n));
        sel.selectedIndex = sel.length - 1;
    }
    f.order[cfg.order == 'modifytime' ? 1 : 0].checked = true;
    f.hmsj[1 - cfg.hmsj].checked = true;
    f.autosave[1 - cfg.autosave].checked = true;
}
function cbAutosave(r) {
    busy = false;
    if ( + r) {
        $(document['fm' + gp_n])[0].nid.value = r;
        updated = 3;
    }
}
function Autosave() {
    var f = document['fm' + gp_n];
    var s = f.content.value;
    if (s && s != lastSave && $.trim(s) && s.length < 10000) {
        lastSave = s;
        ajaxPost('update.php?type=autosave', $(f).serialize(), cbAutosave);
    }
}
void function() {
    var ms = 15000;
    var t = 0;
    var b = false;
    function start() {
        if (!b) {
            b = true;
            t = setInterval(Autosave, ms);
        }
    }
    function stop() {
        b = false;
        clearInterval(t);
    }
    Autosave.start = start;
    Autosave.stop = stop;
} ();
function fireAutosave() {
    $('[name=content]').keyup(Autosave.start);
}
function goPage(n, b) {
    Autosave.stop();
    if (!b) if (gp_n == 1 || gp_n == 2) {
        var tmp = $(document['fm' + gp_n]).serialize();
        if (schk != tmp) {
            if (!confirm('内容已改变，是否离开？')) return;
        }
        clrForm(gp_n);
    }
	
    gp_n = n;
    if (n != 1) $('#tssave').empty();
    for (var i = 1; i <= 6; i++) $id('page' + i).style.display = 'none';
    $id('page' + n).style.display = '';
    if (n == 1 || n == 2) {
        schk = $(document['fm' + n]).serialize();
        lastSave = document['fm' + n].content.value;
    }
    for (i = 1; i <= 3; i++) $id('tab' + i).className = '';
    $('#cntts')[n == 1 && !document.fm1.content.value ? 'show': 'hide']();
    $('#ttts')[n == 2 && !document.fm2.elements.title.value ? 'show': 'hide']();
    switch (n) {
    case 1:
        stk = [1];
        if (updated & 1) get1();
    case 2:
        n = 1;
        $('#fmt2').show();
        break;
    case 3:
        stk = [3];
        if (updated & 2) {
            page = 1;
            getJsList('s=0&l=' + cfg.pagesize);
        }
    case 4:
        n = 2;
        break;
    case 5:
        stk = [];
        n = 3;
        break;
    case 6:
        updCfgForm();
        break;
    }
    if (1 <= n && n <= 3) $id('tab' + n).className = 'app_bt_sc';
    updateHeight();
}
function GoPage(i) {
    return function() {
        goPage(i);
        return false;
    };
}
void function(insert) {
    var isdef = true;
    function def() {
        isdef = true;
        $('#haoma').addClass('cm').val(ts);
    }
    function undef() {
        isdef = false;
        $('#haoma').removeClass('cm').val('');
    }
    var haoma = $('#haoma');
    var ts = haoma.focus(function() {
        if (this.value == ts) undef();
    }).blur(function() {
        if (this.value == '') def();
    }).val();
    haoma = haoma[0];
    $('#haomaA1').click(function() {
        if (!isdef) def();
        return false;
    });
    $('#haomaA2').click(function() {
        if (!isdef) {
            var s = haoma.value;
            if (s) {
                s = s.slice(0, -1);
                haoma.value = s;
            }
            if (!s) def();
        }
        return false;
    });
    $('#haomaA3').click(function() {
        if (!isdef) {
            insert(haoma.value);
            def();
        }
        return false;
    });
    $('#haomaNum a').click(function() {
        if (isdef) undef();
        haoma.value += this.innerHTML;
        return false;
    });
} 
(function(s) {
    document.fm1.content.value += s;
    $('#cntts').hide();
    if (cfg.autosave) Autosave.start();
});
function togglePan(bShow) {
    $('#bar').parent()[bShow ? 'addClass': 'removeClass']('show');
}
function setView() {
    var s = theView == 'list' ? 'summ': 'list';
    render[theView = s](jsList2);
    updateHeight();
    return false;
}
function clrForm(n) {
    var f = document['fm' + n];
    f.reset();
    if (n == 2) {
        setBg('yl_blue', f);
        setIcon('jsicon01', f);
    }
}
function CbSubmit(f) {
    return function(s) {		
        busy = false;
        updated = 3;
        hasJs = true;
        clrForm( + f.name.substr(2));
        schk = $(f).serialize();
        cbView(s);
    };
}
function cbExport(r) {
    busy = false;
    if (r == 'ok') {
        alert('发送成功！');
        addml('attach');
        $('#msg').empty();
    } else alert('发送失败：' + r);
}
function cbCfg(r) {
    busy = false;
    if (r == 'ok') {
        alert('保存成功！');
        location.reload();
    } else alert('保存失败：' + r);
}
function getPrevNext(n) {
    var a = jsList2,
    i = a.length;
    for (; i--;) if (a[i].nid == n) return {
        next: a[i - 1] && a[i - 1].nid,
        prev: a[i + 1] && a[i + 1].nid
    };
}
function _item(obj) {
    var t = new Date(obj.time * 1000);
    return '<div class=item><a href="#" id=sa' + obj.nid + '>' + htmlEncode(obj.title) + '</a> &nbsp;<span>' + t.getFullYear() + '/' + ('0' + (t.getMonth() + 1)).slice( - 2) + '/' + ('0' + t.getDate()).slice( - 2) + '</span></div>';
}
function cbGet1(r) {
    busy = false;
    updated &= ~1;
    r = json_decode(r);
    var a = jsList1 = r.list,
    i;
    hasJs = !!(r.list.length + r.impor.length);
    var d1 = $('#list1')[0];
    var d2 = $('#list2')[0];
    var s = '';
    for (i = 0; i < a.length; i++) s += _item(a[i]);
    d1.innerHTML = i ? s: '您还没有添加任何记事';
    a = r.impor;
    s = '';
    for (i = 0; i < a.length; i++) s += _item(a[i]);
    d2.innerHTML = i ? s: '您没有重要记事';
    updCfg(r.opt);
    updateHeight();
}
function isEmail(s) {
    return /^[0-9a-z]+(?:[._-]+[0-9a-z]+)*@(?:[0-9a-z]+(?:-[0-9a-z]+)*\.)+[a-z]{2,4}$/i.test(s);
}
function get1() {
    ajaxGet(G_dirUrl+'images/notebook/Ajax_value.asp?v=get1', cbGet1);
}
var render = {
    list: renderList,
    summ: renderSumm
};
function renderList(a) {
    $('#summd').empty().hide();
    $('#chkall,#batchdel,#dateh').show();
    var s;
    if (a.length) {
        s = '<table width=775 cellspacing=0 style="margin-left:12px">';
        for (var i = 0; i < a.length; i++) {
            s += '<tr><td width=30 height=30><input type=checkbox name=js value=' + a[i].nid + '></td>';
            s += '<td width=400><div class="tit' + (a[i].important == 1 ? ' imp': '') + '"><a href="#">' + htmlEncode(a[i].title) + '</a></div></td>';
            s += '<td width=150><div class=ctl><a href="#" class=view>查看</a> <a href="#" class=edit>编辑</a> <a href="#" class=del>删除</a></div></td>';
            s += '<td><div class=dtm>' + n2dstr(a[i].time) + '</div></td></tr>';
        }
        s += '</table>';
    } else s = '<div class=nojs>您还没有添加任何记事</div>';
    $('#listd').show().html(s);
    $('#chkall')[0].checked = false;
    $('#tog').attr('class', 's').find('a').text('切换到预览');
}
function renderSumm(a) {
    $('#listd').empty().hide();
    $('#chkall,#batchdel,#dateh').hide();
    var s = '';
    if (a.length) {
        for (var i = 0; i < a.length; i++) {
            s += '<div id="js_' + a[i].nid + '" class="js_tag ' + (a[i].background || 'yl_blue') + '">\
    <div class="yl_c">\
     <div class="yl_c_bd"></div>\
     <dl>\
      <dt><b class="' + (a[i].icon || 'jsicon01') + '"></b><span class="jsdate">' + n2dstr(a[i].time) + '</span></dt>\
      <dd><a href="#" class="listcc">' + br(htmlEncode(a[i].content)) + '</a></dd>\
     </dl>\
    </div>\
    <div class="yl_b">\
     <a class="bwbt_ck" href="#">查看</a>\
     <a class="bwbt_bj" href="#">编辑</a>\
     <a class="bwbt_sc" href="#">删除</a>\
    </div>\
   </div>';
        }
        s += '<div style="clear:both"></div>';
    } else s = '<div class=nojs>您还没有添加任何记事</div>';
    $('#summd').show().html(s);
    $('#tog').attr('class', '').find('a').text('切换到列表');
}
function n2dstr(d) {
    d = new Date(d * 1000);
    return d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice( - 2) + '-' + ('0' + d.getDate()).slice( - 2) + ' ' + ('0' + d.getHours()).slice( - 2) + ':' + ('0' + d.getMinutes()).slice( - 2);
}
function pageTo(n) {
    if (1 <= n && n <= pageCount) {
        page = n;
        getJsList('s=' + ((n - 1) * cfg.pagesize) + '&l=' + cfg.pagesize);
    }
}
function cbGetJsList(s) {
    busy = false;
    s = json_decode(s);
    updated &= ~2;
    jsCount = +s.total;
    hasJs = !!jsCount;
    render[theView](jsList2 = s.list);
    pageCount = Math.ceil(jsCount / cfg.pagesize);
    $('#psp').text(page + '/' + Math.ceil(jsCount / cfg.pagesize));
    if (pageCount > 1) {
        $('#app_pages').show();
        var sel = $('#psel')[0];
        sel.options.length = 0;
        for (var i = 1,
        n = pageCount; i <= n; i++) sel.options.add(new Option('第' + i + '页', i));
        sel.selectedIndex = page - 1;
    }
    updateHeight();
}
function getJsList(s) {
    $('#app_pages').hide();
    ajaxGet(G_dirUrl+'images/notebook/Ajax_value.asp?v=list&' + s, cbGetJsList);
}
function getSelected() {
    var r = [];
    var a = $('[name=js]');
    for (var i = 0; i < a.length; i++) if (a[i].checked) r.push(a[i].value);
    return r.length ? r: null;
}
function getId(a) {
    a = $(a).parents('tr')[0];
    return a.getElementsByTagName('input')[0].value;
}
function setBg(s, f) {
    f.background.value = s;
    $('#cBg a.cur').removeClass('cur');
    $('#' + s).addClass('cur');
}
function setIcon(s, f) {
    f.icon.value = s;
    $('#cIcon a.cur').removeClass('cur');
    $('#' + s).addClass('cur');
}
function goEdit(obj) {
    var f = document.fm2;
    f.nid.value = obj.nid;
    f.content.value = obj.content;
    f.elements.title.value = obj.title || '';
    f.important.checked = obj.important == 1;
    setBg(obj.background || 'yl_blue', f);
    setIcon(obj.icon || 'jsicon01', f);
    goPage(2);
    $('#fmt2').hide();
}
function del(id, m) {
    if (confirm('确定要删除' + (m ? '所选': '') + '吗？')) ajaxPost(G_dirUrl+'images/notebook/Ajax_value.asp?v=del', 'nids=' + id, cbDel);
}
function cbDel(r) {
    busy = false;
    if ( + r > 0) {
        updated = 3;
        goPage(3);
    } else alert('删除出错：' + r);
}
function cbView_edit(r) {
    busy = false;
    goEdit(jsObj = json_decode(r));
    updateHeight();
}
function cbView(r) {
    busy = false;
    jsObj = r = json_decode(r);
    $('#jsdtm').text(n2dstr(r.createtime));
    $('#jstit').text(r.title || cut(r.content));
    $('#jscnt').html(br(htmlEncode(r.content)));
    goPage(4);
    $('#jsprev')[0].className = r.prev ? '': 'dis';
    $('#jsnext')[0].className = r.next ? '': 'dis';
    $('#p4dy')[0].href = G_dirUrl+'images/notebook/print.asp?nid=' + r.nid;
    updateHeight();
}
function getJs(id, cb, p, n) {
    ajaxGet(G_dirUrl+'images/notebook/Ajax_value.asp?v=fm2&nid=' + id + (p ? '&prev=' + p: '') + (n ? '&next=' + n: ''), cb);
}
function view(id, pn) {
    for (var i = stk.length; i--;) if (stk[i] == 4) {
        stk = stk.slice(0, i);
        break;
    }
    if (!pn) pn = getPrevNext(id);
    getJs(id, cbView, pn.prev, pn.next);
}
function pageFirst() {
    pageTo(1);
    return false;
}
function pagePrev() {
    pageTo(page - 1);
    return false;
}
function pageNext() {
    pageTo(page + 1);
    return false;
}
function pageLast() {
    pageTo(pageCount);
    return false;
}
function addml(s) {
    getml(s);
    cfg._emailLimit[s]++;
}
function getml(s) {
    if (!cfg._emailLimit.date) return - 1;
    var d = new Date;
    var t = d.getFullYear() * 10000 + d.getMonth() * 100 + 100 + d.getDate();
    if (t != cfg._emailLimit.date) {
        cfg._emailLimit.date = t;
        return 0;
    }
    return cfg._emailLimit[s];
}
function okJsMail() {
    addml('note');
    hideWindow();
}
function jsMail() {
    var n = getml('note');
    if (n >= 3) {
        alert('您今天已经发了3次，不能再发了！');
        return false;
    }
    showWindow({
        title: '发送到邮箱',
        top: calcTop(),
        height: swHeight,
        width: swWidth,
        iframe: 'mail.htm',
        opacity: 0,
        onIframeLoaded: function() {
            this.init(cfg._email, jsObj.nid, n, okJsMail);
        }
    });
    return false;
}
function checkForm(f) {
    var s = f.content.value;
    if (!s) {
        alert('内容不能为空');
        return false;
    }
    if (s.length > 10000) {
        alert('当前输入' + s.length + '字，系统限制最多允许输入1万字。');
        return false;
    }
    return true;
}
function events_common() {
    $('form').each(function() {
        this.reset();
    });
    $('[name=content]').eq(0).focus(function() {
        $('#cntts').hide();
    }).blur(function() {
        if (!this.value) $('#cntts').show();
    });
    $('#cntts').click(function() {
        $('[name=content]').eq(0).focus();
    });
    $('#bar').click(function() {
        togglePan(!$(this).parent().hasClass('show'));
        this.blur();
        return false;
    });
}
function events_logout() {
    $('#tab1').click(returnFalse);
    $('#tab2').click(needLogin);
    $('#tab3').click(needLogin);
    $('#cfg').click(needLogin);
    $('#fmt1').click(needLogin);
    $(document.fm1).submit(function() {
        var s = this.content.value;
        if (s) setCookie('content', s, 2);
        showLoginWindow();
        return false;
    });
}
function events_login() {
    var s = getCookie('content');
    if (s) {
        setCookie('content', '1', -1);
        $(document.fm1)[0].content.value = s;
        $('#tssave').html('请再次点击进行保存');
    }
    $('[name=title]').focus(function() {
        $('#ttts').hide();
    }).blur(function() {
        if (!this.value) $('#ttts').show();
    });
    $('#ttts').click(function() {
        $('[name=title]').focus();
    });
    $('#pa0').click(pageFirst);
    $('#pa1').click(pagePrev);
    $('#pa2').click(pageNext);
    $('#pa3').click(pageLast);
    $('#psel').change(function() {
        pageTo( + this.value);
        this.blur();
    });
    $('#back').click(function() {
        var n = 0;
        for (var i = stk.length; i--&&!n;) switch (stk[i]) {
        case 1:
            n = 1;
            break;
        case 3:
            n = 3;
            break;
        }
        goPage(n || 3);
        return false;
    });
    $('#tab1').click(GoPage(1));
    $('#tab2').click(GoPage(3));
    $('#tab3').click(GoPage(5));
    $('#cfg').click(GoPage(6));
    $('#listd tr').live('mouseover',
    function() {
        $(this).addClass('over');
    }).live('mouseout',
    function() {
        $(this).removeClass('over');
    });
    $('#tog a').click(setView);
    $('#fmt1').click(function() {
        document.fm2.nid.value = '0';
        goPage(2);
        return false;
    });
    $('#fmt2').click(function() {
        goPage(1);
        return false;
    });
    $('#cBg a').click(function() {
        $('#cBg .cur').removeClass('cur');
        $(this).addClass('cur');
        $(this).parents('form')[0].background.value = this.id;
        return false;
    });
    $('#cIcon a').click(function() {
        $('#cIcon .cur').removeClass('cur');
        $(this).addClass('cur');
        $(this).parents('form')[0].icon.value = this.id;
        return false;
    });
    var fmexp = document.fmexport;
    $(fmexp).submit(function() {
        if (!hasJs) {
            alert('您还没有记事！');
            return false;
        }
        if (this.destination[1].checked) {
            if (getml('attach') >= 3) {
                alert('您今天已经发了3次，不能再发了！');
                return false;
            }
            var s = this.email.value;
            if (!s) {
                alert('请输入Email！');
                return false;
            }
            if (!isEmail(s)) {
                alert('请输入正确的Email！');
                return false;
            }
            try {
                ajaxPost(this.action, $(this).serialize(), cbExport);
            } catch(e) {
                throw e;
            } finally {
                return false;
            }
        }
    });
    fmexp.destination[0].onclick = function() {
        fmexp.email.disabled = true;
        $('#msg').empty();
    };
    fmexp.destination[1].onclick = function() {
        fmexp.email.disabled = false;
        if (!fmexp.email.value) fmexp.email.focus();
        var n = getml('attach');
        $('#msg').html('&nbsp;<font color=gray>这是您第<font color=red>' + (n + 1) + '</font>次将内容保存到邮箱，今天还可保存<font color=red>' + (3 - n) + '</font>次。</font>');
    };
    function jsSubmit() {
        if (!checkForm(this)) return false;
        try {
            var a = this.name == 'fm1' && jsList1 && jsList1[0];
            a = a ? '&prev=' + a.nid: '';
			
            ajaxPost(G_dirUrl+'images/notebook/Ajax_value.asp?v=fm1', $(this).serialize() + a, CbSubmit(this));
        } catch(e) {
            throw e;
        } finally {
            return false;
        }
    }
    $('[name=fm1]').submit(jsSubmit);
    $('[name=fm2]').submit(jsSubmit);
    $(document.fmcfg).submit(function() {
        try {
            ajaxPost('update.php?type=opt', $(this).serialize(), cbCfg);
        } catch(e) {
            throw e;
        } finally {
            return false;
        }
    });
    $('#cfgreset').click(function() {
        updCfgForm();
        return false;
    });
    $('#slist a').live('click',
    function() {
        var a = $(this).parent();
        var p = a.next();
        p = p.length && p.find('a')[0].id.substr(2);
        var n = a.prev();
        n = n.length && n.find('a')[0].id.substr(2);
        getJs(this.id.substr(2), cbView, p, n);
        return false;
    });
    $('#batchdel').click(function() {
        var a = getSelected();
        if (!a) {
            alert('请先选择记事');
            return false;
        }
        del(a.join(','), 1);
        return false;
    });
    $('#listd').delegate('.tit a', 'click',
    function() {
        view(getId(this));
        return false;
    }).delegate('.ctl a', 'click',
    function() {
        var id = getId(this);
        switch (this.className) {
        case 'view':
            view(id);
            break;
        case 'edit':
            var pn = getPrevNext(id);
            getJs(id, cbView_edit, pn.prev, pn.next);
            break;
        case 'del':
            del(id);
            break;
        }
        return false;
    });
    $('#summd').delegate('.listcc', 'click',
    function() {
        view($(this).parents('.js_tag')[0].id.substr(3));
        return false;
    });
    $('#summd').delegate('.yl_b a', 'click',
    function(e) {
        var id = $(this).parents('.js_tag')[0].id.substr(3);
        switch (this.className.substr(5)) {
        case 'ck':
            view(id);
            break;
        case 'bj':
            var pn = getPrevNext(id);
            getJs(id, cbView_edit, pn.prev, pn.next);
            break;
        case 'sc':
            del(id);
            break;
        }
        return false;
    });
    $('div.js_tag').live('mouseover',
    function() {
        $(this).find('.yl_b a').show();
    }).live('mouseout',
    function() {
        $(this).find('.yl_b a').hide();
    });
    $('#p4m').click(jsMail);
    $('#jsclose').click(function() {
        for (var i = stk.length; i--;) switch (stk[i]) {
        case 1:
            goPage(1);
            return;
        case 3:
            goPage(3);
            return;
        }
        goPage(3);
    });
    $('#jsnext').click(function() {
        if (jsObj.next) view(jsObj.next, {
            prev: jsObj.nid
        });
        return false;
    });
    $('#jsprev').click(function() {
        if (jsObj.prev) view(jsObj.prev, {
            next: jsObj.nid
        });
        return false;
    });
    $('#jsedit').click(function() {
        goEdit(jsObj);
        return false;
    });
    $('#jsdel').click(function() {
        del(jsObj.nid);
        return false;
    });
    $('#chkall').click(function() {
        var b = this.checked;
        var a = $('[name=js]');
        for (var i = 0; i < a.length; i++) a[i].checked = b;
    });
    $('[name=js]').live('click',
    function() {
        var a = $('[name=js]'),
        b = true;
        for (var i = 0; i < a.length; i++) if (!a[i].checked) {
            b = false;
            break;
        }
        $('#chkall')[0].checked = b;
    });
}
function init() {
    events_common();
    if (isLogin) {
		
        goPage(1, 1);
        events_login();
    } else events_logout();
}
if (self != parent) parent.J.add(appName, {},
window);
init();