J1616.www.app = {};
J1616.www.app.note = {
    U: J1616.Util,
    W: J1616.www,
    O: ['haoma', 'haomaNum', 'haomaA1', 'haomaA2', 'haomaA3', '号码速记', 'note-main', 'note-hide', 'note-num', 'note-text', 500, 2000, 'jsb-s', ['note-login', 'note-reg'], 'note-e', 0, ["93%", "96%", "73%", "76%"], ["672px", "700px", "476px", "504px"], 1],
    _input: function(s) {
        var J = J1616.www.app.note;
        var _s = $('#' + J.O[0]).val();
        $('#' + J.O[0]).attr("class", "num-c cc");
        if (_s == '号码速记') {
            $('#' + J.O[0]).val(s);
        } else {
            $('#' + J.O[0]).val(_s + s);
        }
    },
    _insertNote: function() {
        var J = this;
        var _s = $('#' + J.O[0]).val(),
        _s2 = $('#' + J.O[9]).val();
        if (_s != J.O[5]) {
            var _d = (_s2.length > 0) ? "\n": "";
            $('#' + J.O[9]).val(_s2 + _d + _s).scrollTop(document.getElementById(J.O[9]).scrollHeight);
            J._clearNum();
            J._saveNote();
        }
    },
    _clearNum: function() {
        var J = this;
        $('#' + J.O[0]).val(J.O[5]).attr("class", "num-c cm");
    },
    _clearBack: function() {
        var J = this;
        var _s = $('#' + J.O[0]).val();
        if (_s != J.O[5]) {
            if (_s == '' || _s.length == 1) {
                J._clearNum();
            } else {
                $('#' + J.O[0]).val(_s.substr(0, _s.length - 1));
            }
        }
    },
    _onoffNum: function() {
        var J = this,
        _d;
        _d = (parent.J1616.www.my1616.isWideScreen()) ? J.O[16] : J.O[17];
        if ($('#' + J.O[8] + ':visible').length > 0) {
            $('#' + J.O[8]).hide();
            $('.' + J.O[12]).css("width", _d[0]);
            $('#' + J.O[6]).css("width", _d[1]);
            $('#' + J.O[7]).html('<span title="显示"></span>').css("float", "right");
            J.U.setCookie("note-hide", 0, null, null);
            J.O[18] = 0;
        } else {
            $('#' + J.O[8]).show();
            $('.' + J.O[12]).css("width", _d[2]);
            $('#' + J.O[6]).css("width", _d[3]);
            $('#' + J.O[7]).html('<em title="隐藏"></em>').css("float", "left");
            J.U.setCookie("note-hide", 1, null, null);
            J.O[18] = 1;
        }
    },
    _saveNote: function() {
        var J = this,
        _user = parent.J1616.www.ac.i,
        _sd = _s = $('#' + J.O[9]).val(),
        _s2 = $('#' + J.O[14]).val();
        if (_s != _s2) {
            if (_user != true) {
                if (_s.length > J.O[10]) {
                    alert('未登录用户只可储存' + J.O[10] + '字符!');
                    _s = _s.substr(0, J.O[10]);
                    $('#' + J.O[9]).val(_s).scrollTop(document.getElementById(J.O[9]).scrollHeight);
                }
                _s = parent.J1616.obj2str(_s);
                parent.J1616.Util.setCookie("note", _sd, null, null);
                parent.J1616.www.note.__cfg = _sd;
            } else {
                if (_s.length > J.O[11]) {
                    alert('已超过最大字符限制!');
                    _s = _s.substr(0, J.O[11]);
                    $('#' + J.O[9]).val(_s).scrollTop(document.getElementById(J.O[9]).scrollHeight);
                }
                try {
                    _s = (_s.substr(0, 1) == '\n' && J.O[15] == 1) ? _s.substr(1, _s.length) : _s;
                    _s = J1616.obj2str(_s);
                    parent.J1616.www.config("note", _s,
                    function(o) {
                        switch (J1616.str2obj(o).code) {
                        case 1:
                            J.U.console("info", "NoteSave：Success");
                            break;
                        default:
                            J.U.console("warn", "NoteSave：Error_" + J1616.str2obj(o).code);
                            break;
                        }
                    });
                } catch(e) {
                    J.U.console("warn", "NoteError:" + e);
                }
            }
            parent.J1616.www.cfgs['note'] = _s;
        }
        $('#' + J.O[14]).val(_sd);
    },
    _getNote: function(u, d) {
        var J = this,
        bw = brower();
        d = (!d || d == 'null' || d == 'undefined' || J1616.str2obj(d) == 'undefined') ? "": J1616.str2obj(d);
        if (u == 0) {
            $('#l-if').text("欢迎使用在线记事本，为保存您的内容 ");
            $('#note-loginfo').show();
            $('.' + J.O[12]).show();
            if (bw[1] == false) {
                $('#' + J.O[9]).css({
                    "padding-top": "26px",
                    "height": "176px"
                });
            }
            d = (bw[1] && d.substr(0, 1) != '\n') ? "\n" + d: d;
			
        } else {
            $('#' + J.O[9]).css({
                "padding-top": "0",
                "height": "204px"
            });
            if (d == "" || d == "\n") {
                $('#l-if').text("欢迎使用在线记事本！");
                $('#note-loginfo').hide();
                $('.' + J.O[12]).show();
                if (bw[1] == false) {
                    J.O[15] == 0;
                    $('#' + J.O[9]).css({
                        "padding-top": "26px",
                        "height": "176px"
                    });
                } else {
                    J.O[15] = 1;
                }
            } else {
                J.O[15] == 0;
                $('.' + J.O[12]).hide();
            }
        }
        $('#' + J.O[14] + ',#' + J.O[9]).val(d);
    },
    _chkTop: function() {
        var J = this,
        _s = $('#' + J.O[9]).val(),
        bw = brower();
        if (bw[1] != false && J.O[15] == 1) {
            if (_s.substr(0, 1) != '\n') {
                $('#' + J.O[9]).val('\n' + _s);
            }
        }
    },
    _bindEvents: function() {
        var J = this;
        $('#' + J.O[0]).click(function() {
            if ($(this).val() == J.O[5]) {
                $(this).val('').attr("class", "num-c cc");
            }
        });
        $('form.jishiben').submit(function() {
            J._insertNote();
            $('#' + J.O[0]).blur();
            return false;
        });
        $('#' + J.O[1] + '>a').click(function() {
            J._input($(this).text());
            return false;
        });
        $('#' + J.O[2]).click(function() {
            J._clearNum();
            return false;
        });
        $('#' + J.O[3]).click(function() {
            J._clearBack();
            return false;
        });
        $('#' + J.O[4]).click(function() {
            J._insertNote();
            return false;
        });
        $('#' + J.O[7]).click(function() {
            J._onoffNum();
            return false;
        });
        $('#' + J.O[13][0]).click(function() {
            parent.J1616.www.index.p_login();
            return false;
        });
        $('#' + J.O[13][1]).click(function() {
            parent.J1616.www.index.p_reg();
            return false;
        });
        $('.' + J.O[12]).click(function() {
            $(this).addClass("note-tip");
            $('#' + J.O[9]).addClass("note-t").focus();
        });
        $('#' + J.O[9]).click(function() {
            $('.' + J.O[12]).addClass("note-tip");
            $(this).addClass("note-t").focus();
        }).blur(function() {
            $('.' + J.O[12]).removeClass("note-tip");
            $(this).removeClass("note-t");
            $('#' + J.O[14]).focus();
            J._saveNote();
        }).keyup(function() {
            J._chkTop();
        }).keypress(function() {
            $(this).addClass("note-t");
            $('.' + J.O[12]).addClass("note-tip");
        });
        if (J.U.getCookie("note-hide") == 0) {
            J._onoffNum()
        };
    },
    _wideScn: function(t) {
        var J = this,
        v;
        t = t ? J.O[16] : J.O[17];
        v = (J.O[18] == 0) ? [t[0], t[1]] : [t[2], t[3]];
        $('.' + J.O[12]).css("width", v[0]);
        $('#' + J.O[6]).css("width", v[1]);
    },
    _setTheme: function() {
        this._wideScn(parent.J1616.www.my1616.isWideScreen());
        var theme = parent.J1616.str2obj(parent.J1616.www.cfgs['my1616']);
        document.getElementById('sl').href = 'http://i.9533.com/style/' + [theme.th] + '/_s.css';
    },
    init: function() {
        this._bindEvents();
    }
};
function note_login(a, b) {
    J1616.www.app.note._getNote(((a == 'in') ? 1 : 0), b);
}
function setTheme() {
    J1616.www.app.note._setTheme();
}
function brower() {
    var userAgent = navigator.userAgent.toLowerCase();
    var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
    var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
    var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 1);
    return [is_opera, is_moz, is_ie];
}
J1616.www.app.note.init();
//window.onload = function() {
//    try {
//        var i = parent.J1616.www.ac.i,
//        N = J1616.www.app.note;
//        N._setTheme();
//        N._getNote(((i == true) ? 1 : 0), parent.J1616.www.cfgs["note"]);
//    } catch(e) {}
//};