﻿//进度条
var ProcessTip = Class(object, {
    Create: function(tipText) {
        this.tip;
        this.tipText = tipText;
        if (!this.tipText)
            this.tipText = '正在保存中...';

        if (!document.getElementById('processTip')) {
            var div = document.createElement('div');
            div.id = 'processTip';
            div.innerHTML = this.getHTML();
            document.body.appendChild(div);
            this.tip = div;
            this.tip.style.display = 'none';
        }
        else {
            this.tip = document.getElementById('processTip');
            //this.show();
        }
    },
    show: function() {
        $('.processTipBorder').css('top', document.documentElement.scrollTop);
        this.tip.style.display = '';
    },
    hide: function() {
        this.tip.style.display = 'none';
    },
    getHTML: function() {
        return '<div class="processTipBorder" style="top:' + document.documentElement.scrollTop + 'px;right:2px;"><div class="processTip"><img align="absmiddle" src="/resource/images/loading.gif"/><span id="tip_text">' + this.tipText + '</span></div></div>';
    }
});

//模式窗口
var Dialog = Class(object, {
    Create: function(title, text, icon, type, funOK) {
        this.title = title;
        this.text = text;
        this.icon = icon;
        this.type = type;
        this.funOK = funOK;
        this.pop;

        if (!document.getElementById('pop_layer')) {
            var div = document.createElement('div');
            div.id = 'pop_layer';
            div.innerHTML = this.getHTML();
            document.body.appendChild(div);
            this.pop = div;
            this.pop.style.display = 'none';
        }
        else {
            this.pop = document.getElementById('pop_layer');
            this.pop.innerHTML = this.getHTML();
        }
        if (document.getElementById('btnOK') && this.funOK)
            $('#btnOK').bind('click', this.funOK);
    },
    show: function() {
        document.getElementById('bg1').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=20';
        this.pop.style.display = '';
        $('#pop_up').css("top", (document.documentElement.clientHeight - $('#pop_up').height()) / 2 + $(document).scrollTop() + 'px');
        $('#pop_up').css("left", ($(document).width() - $('#pop_up').width()) / 2 + 'px');
        $('#bg1').height(document.body.clientHeight);
    },
    hide: function() {
        this.pop.style.display = 'none';
    },
    getHTML: function() {
        switch (this.type) {
            case 0: //only ok   
                return '<div id="bg1" classr="bg"></div><div id="pop_up" class="pop_up"><div class="pop_t"></div><div class="pop_m"><div class="close"></div><div class="clearer"></div><div class="pop_icon' + this.icon + '"></div><div class="pop_txt"><h2>' + this.title + '</h2><h3>' + this.text + '</h3></div><div class="clearer"></div><input id="btnOK" type="button" class="btn" onclick="$(\'#pop_layer\').hide();" value="确  定" /></div><div class="pop_b"></div></div>';
                break;
            case 1: //ok and cancal
                return '<div id="bg1" class="bg"></div><div id="pop_up" class="pop_up"><div class="pop_t"></div><div class="pop_m"><div class="close"></div><div class="clearer"></div><div class="pop_icon' + this.icon + '"></div><div class="pop_txt"><h2>' + this.title + '</h2><h3>' + this.text + '</h3></div><div class="clearer"></div><input id="btnOK" type="button" class="btn" value="确  定" /> <input type="button" class="btn" onclick="$(\'#pop_layer\').hide();" value="取  消" /></div><div class="pop_b"></div></div>';
                break;
        }
    }
});

//登录窗口
var LoginDialog = Class(object, {
    Create: function() {
        this.pop;

        if (!document.getElementById('login_layer')) {
            var div = document.createElement('div');
            div.id = 'login_layer';
            div.innerHTML = this.getHTML();
            document.body.appendChild(div);
            this.pop = div;
            this.pop.style.display = 'none';
        }
        else {
            this.pop = document.getElementById('login_layer');
            this.pop.innerHTML = this.getHTML();
            //this.show();
        }
    },
    show: function() {
        document.getElementById('bg2').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=20';
        this.pop.style.display = '';
        $('#login_access').css("top", (document.documentElement.clientHeight - $('#login_access').height()) / 2 + $(document).scrollTop() + 'px');
        $('#login_access').css("left", ($(document).width() - $('#login_access').width()) / 2 + 'px');
        $('#bg2').height(document.body.clientHeight);
    },
    hide: function() {
        this.pop.style.display = 'none';
    },
    getHTML: function() {
        return '<div id="bg2" class="bg"></div><div class="block_con" id="login_access"><h2>通行证登录</h2><div class="close" onclick="loginDialog.hide();">x</div><h3><a href="#">帮助</a></h3><div class="blog_login"><ul><li>用户名：<input id="loginName" type="text" class="input1" /> <a href="http://my.39.net/register.aspx">注册通行证</a></li><li>密&nbsp;&nbsp;&nbsp;码：<input id="loginPass" type="password" class="input1" /></li><li><input id="loginRemember" type="checkbox" />记住密码</li><li><input type="button" class="btn" onclick="postLogin($(\'#loginName\').val(), $(\'#loginPass\').val(), $(\'#loginRemember\').attr(\'checked\'));" value="登  录" /></li></ul><div id="errmsg" style="color:Red;font-weight:bold;"></div><div class="clearer"></div></div>';
    }
});

//短消息窗口
var ScripDialog = Class(object, {
    Create: function() {
        this.pop;
        if (!document.getElementById('script_layer')) {
            var div = document.createElement('div');
            div.id = 'script_layer';
            div.innerHTML = this.getHTML();
            document.body.appendChild(div);
            this.pop = div;
            this.pop.style.display = 'none';
        }
        else {
            this.pop = document.getElementById('script_layer');
            this.pop.innerHTML = this.getHTML();
            //this.show();
        }
    },
    show: function() {
        if (!isLogin) {
            loginDialog.show();
            return;
        }

        document.getElementById('bg3').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=20';
        this.pop.style.display = '';
        $('#scrip_access').css("top", (document.documentElement.clientHeight - $('#scrip_access').height()) / 2 + $(document).scrollTop() + 'px');
        $('#scrip_access').css("left", ($(document).width() - $('#scrip_access').width()) / 2 + 'px');
        $('#bg3').height(document.body.clientHeight);
        $('#txtScrip')[0].focus();
    },
    hide: function() {
        this.pop.style.display = 'none';
    },
    getHTML: function() {
        return '<div id="bg3" class="bg"></div><div class="block_con" id="scrip_access"><h2>发送新消息</h2><div class="close" onclick="New(ScripDialog, [null]).hide();">x</div><div class="blog_scrip"><ul><li>发送给： ' + blogInfo.Author + '</li><li><textarea id="txtScrip" class="textarea"></textarea></li><li><input type="button" class="btn" onclick="postScrip();" value="发  送" /></li></ul><div id="errmsg" style="color:Red;font-weight:bold;"></div><div class="clearer"></div></div></div>';
    }
});

//好友申请窗口
var AddFriendDialog = Class(object, {
    Create: function() {
        this.pop;
        if (!document.getElementById('addfriend_layer')) {
            var div = document.createElement('div');
            div.id = 'addfriend_layer';
            div.innerHTML = this.getHTML();
            document.body.appendChild(div);
            this.pop = div;
            this.pop.style.display = 'none';
        }
        else {
            this.pop = document.getElementById('addfriend_layer');
            this.pop.innerHTML = this.getHTML();
        }
    },
    show: function() {
        if (!isLogin) {
            loginDialog.show();
            return;
        }

        document.getElementById('bg4').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=20';
        this.pop.style.display = '';
        $('#addfriend_access').css("top", (document.documentElement.clientHeight - $('#addfriend_access').height()) / 2 + $(document).scrollTop() + 'px');
        $('#addfriend_access').css("left", ($(document).width() - $('#addfriend_access').width()) / 2 + 'px');
        $('#bg4').height(document.body.clientHeight);

        $('#txtMsg')[0].focus();
    },
    hide: function() {
        this.pop.style.display = 'none';
    },
    getHTML: function() {
        return '<div id="bg4" class="bg"></div><div class="block_con" id="addfriend_access"><h2>发送好友申请</h2><div class="close" onclick="New(AddFriendDialog, [null]).hide();">x</div><div class="blog_scrip"><ul><li>您正准备把&nbsp;' + blogInfo.Author + '&nbsp;添加为好友，请填写附言：</li><li><textarea id="txtMsg" class="textarea"></textarea></li><li><input type="button" class="btn" onclick="addFriend();" value="加好友" /></li></ul><div id="errmsg" style="color:Red;font-weight:bold;"></div><div class="clearer"></div></div></div>';
    }
});

//分享弹出窗口
var addShareDialog = Class(object, {
    Create: function(title, url) {
        this.title = title;
        this.url = url;
        this.pop;
        if (!document.getElementById('addshare_layer')) {
            var div = document.createElement('div');
            div.id = 'addshare_layer';
            div.innerHTML = this.getHTML();
            document.body.appendChild(div);
            this.pop = div;
            this.pop.style.display = 'none';
        }
        else {
            this.pop = document.getElementById('addshare_layer');
            this.pop.innerHTML = this.getHTML();
        }
    },
    show: function() {
        document.getElementById('bg5').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=20';
        this.pop.style.display = '';
        $('#addshare_access').css("top", (document.documentElement.clientHeight - $('#addshare_access').height()) / 2 + $(document).scrollTop() + 'px');
        $('#addshare_access').css("left", ($(document).width() - $('#addshare_access').width()) / 2 + 'px');
        $('#bg5').height(document.body.clientHeight);

        $('#txtMsg')[0].focus();
    },
    hide: function() {
        this.pop.style.display = 'none';
    },
    getHTML: function() {
        return '<div id="bg5" class="bg"></div><div class="block_con" id="addshare_access"><h2>分享</h2><div class="close" onclick="New(addShareDialog, [null]).hide();">x</div><div class="blog_scrip"><ul><li><textarea id="txtMsg" class="textarea">' + this.title + '\n' + this.url + '</textarea></li><li>您可以将上面的地址拷贝后发送给好友。</li><li><input type="button" class="btn" onclick="New(addShareDialog, [null]).hide();" value="确定" /></li></ul><div id="errmsg" style="color:Red;font-weight:bold;"></div><div class="clearer"></div></div></div>';
    }
});