﻿
function SetCookie(name, value, expires, path, domain, secure)
{
    var expDays = expires * 24 * 60 * 60 * 1000;
    var expDate = new Date();
    expDate.setTime(expDate.getTime() + expDays);
    var expString = ((expires == null) ? "" : (";expires=" + expDate.toGMTString()));
    //var pathString = ((path == null) ? "" : (";path=" + path));
    var pathString = ";path=/";
    var domainString = ((domain == null) ? "" : (";domain=" + domain));
    var secureString = ((secure == true) ? ";secure" : "")
    document.cookie = name + "=" + escape(value) + expString + pathString + domainString + secureString;
}


function GetCookie(name)
{
    var result = null;
    var myCookie = document.cookie + ";";
    var searchName = name + "=";
    var startOfCookie = myCookie.indexOf(searchName);
    var endOfCookie;
    if (startOfCookie != -1)
    {
        startOfCookie += searchName.length;
        endOfCookie = myCookie.indexOf(";", startOfCookie);
        result = unescape(myCookie.substring(startOfCookie, endOfCookie));
    }
    return result;
}


function ClearCookie(name)
{
    var ThreeDays = 3 * 24 * 60 * 60 * 1000;
    var expDate = new Date();
    expDate.setTime(expDate.getTime() - ThreeDays);
    document.cookie = name + "=;expires=" + expDate.toGMTString();
}
 
var ftalk_scbx;

$(function()
{
    ftalk_scbx = new ftalk();
    ftalk_scbx.init();
});


ftalk = function()
{
    this.talk_body = "#ftalk_body";
    this.talk_container = "#ftalk_roster";
    this.talk_header = "#ftalk_header";
    this.talk_header_control = "#ftalk_mm_but";
    this.USER_LIST = "/WS/ftalk.ashx";
    this.USER_PANEL = "#ftalk_user_panel";
    this.USER_PANEL_MESSAGE = "#ftalk_user_panel_message";
    this.USER_PANEL_POKE = "#ftalk_user_panel_poke";
    this.USER_PANEL_GIFT = "#ftalk_user_panel_gift";
    this.MSG_COUNT = 0;
    this.MSG_TAG = true;
    this.OPEN = false;
    this.IS_IE6 = false;
    this.LIMIT_OPEN_COUNT = 3;
    this.CURRENT_OPEN_COUNT = 0;
    this.OPEN_DIALOGUE_LIST = new Array();
    this.CURRENT_OPEN_INDEX = 0;
    this.LOAD_USER_LIST = false;
    this.ONLY_SHOW_NEW = false;//只显示有消息的信息
};

ftalk.prototype.init = function()
{

    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var version = b_version.split(";");
    var trim_version = version[1].replace(/[ ]/g, "");
    if (browser == "Microsoft Internet Explorer" && trim_version == "MSIE6.0")
    {
        this.IS_IE6 = true;
    }
    
    this.instance();

};

ftalk.prototype.instance = function()
{
    var t = this;
    var xbox = '<div id="ftalk_body" class="ftalk_frame" style="display: none">\
                    <span class="ftalk_top" style="margin: 0pt 2px; display: block; height: 1px; font-size: 1px;\
                        overflow: hidden;"></span><span class="ftalk_top" style="margin: 0pt 1px; display: block;\
                            height: 1px; font-size: 1px; overflow: hidden;"></span><span class="ftalk_top" style="margin: 0pt;\
                                display: block; height: 1px; font-size: 1px; overflow: hidden;"></span>\
                    <div class="ftalk_top" style="cursor: pointer; overflow: hidden;">\
                        <div class="ftalk_presence_bubble">\
                            <img border="0" alt="" src="/Images/roster_icon.gif" width="12" height="12" />\
                        </div>\
                        <div class="ftalk_control" id="ftalk_control">\
                            <div id="ftalk_mm_but">\
                                <img style="display: none" id="ftalk_minimize" class="ftalk_control" src="/Images/roster_minimize.gif"\
                                    width="16" height="16" />\
                                <img style="display: block" id="ftalk_maximize" class="ftalk_control" src="/Images/roster_maximize.gif"\
                                    width="16" height="16" />\
                            </div>\
                        </div>\
                        <div class="ftalk_header" id="ftalk_header">\
                            站内消息</div>\
                    </div>\
                    <div id="ftalk_container" class="ftalk_container" style="display: none">\
                        <div style="display: block; padding: 4px;">\
                            <input type="text" style="width: 140px" id="ftalk_search" />\
                        </div>\
                        <div style="display: block; padding: 2px;color:#808080; font-size:7pt;">\
                         <input type="checkbox" name="checkbox" id="ftalk_is_new_list" />只显示有消息的朋友\
                        </div>\
                        <div id="ftalk_roster" style="display: block;" class="ftalk_roster">\
                        </div>\
                        <div class="splitline"></div>\
                        <div id="ftalk_user_panel" style="display:block; width:100%; height:50px;">\
                        </div>\
                        <div id="ftalk_user_application" style="display:block; padding-left:5px; height:20px;">\
                        <a href="javascript:void(0)" onclick="javascript:ftalk_scbx.new_chat_window(0,\'系统消息\',\'message\')" title="查看系统消息">\
                            <img src="/Images/ftalk_system_msg.gif" style="vertical-align: middle;border:0px;" alt="查看系统消息" ></a>\
                            &nbsp;<span style="color:red" id="ftalk_user_panel_message"></span>&nbsp;&nbsp;\
                        <a href="javascript:void(0)"; onclick="javascript:ftalk_scbx.new_chat_window(0,\'招惹动态\',\'poke\')" title="查看招惹动态">\
                         <img src="/Images/Poke.gif" style="vertical-align: middle;border:0px;" alt="查看招惹动态" ></a>\
                         &nbsp;<span style="color:red" id="ftalk_user_panel_poke"></span>&nbsp;&nbsp;\
                         <a href="javascript:void(0)" onclick="javascript:ftalk_scbx.new_chat_window(0,\'礼物消息\',\'gift\')" title="查看收到的礼物">\
                         <img src="/Applications/Images/Icons/Gift.gif" style="vertical-align: middle;border:0px;" alt="查看收到的礼物" ></a>\
                         &nbsp;<span style="color:red" id="ftalk_user_panel_gift"></span>&nbsp;&nbsp;\
                        </div>\
                    </div>\
                </div>';
    $.get(t.USER_LIST, { "id": Math.random(), "action": "check_user" }, function(data)
    {
        if (data == "1")
        {
            if (document.getElementById('ftalk_body') == null)
                $("body").append(xbox);

            t.init_talk_body();
            //t.check_user();
            t.load_user();
            t.load_user_panel();
            t.bind_search_behaver();
            t.window_resize();
            t.bind_checkbox_behave();
            //            $(t.talk_body).show();

            //            var isc = t.get_open_dialog();
            //            if (isc == null)
            //                t.save_open_dialog();
            //            else
            //                t.auto_open_dialog(isc);

        }
    });

}


ftalk.prototype.bind_checkbox_behave = function()
{
    var t = this;
    $("#ftalk_is_new_list").click(function()
    {
        //alert($(this).attr("checked"));
        if ($(this).attr("checked"))
        {
            t.ONLY_SHOW_NEW = true;
            $(">div", t.talk_container).each(function(ii)
            {
                var na = $("span:eq(1)", this).html();

                if ($.trim(na) != "")
                {
                    $(this).show()
                }
                else
                    $(this).hide();
            });
        }
        else
        {
            t.ONLY_SHOW_NEW = false;
            $(">div", t.talk_container).show();
        }
    });

    //ONLY_SHOW_NEW
};

ftalk.prototype.get_open_dialog = function()
{
    var name = "ftalk_open_dialog";
    return GetCookie(name);
};

ftalk.prototype.save_open_dialog = function()
{
    var name = "ftalk_open_dialog";
    var value = "";
    if (this.OPEN)
        value = "ftalk_body:1";
    else
        value = "ftalk_body:0";

    for (var ii = 0; ii < this.OPEN_DIALOGUE_LIST.length; ii++)
    {
        value += "@" + this.OPEN_DIALOGUE_LIST[ii].divid + ":" + this.OPEN_DIALOGUE_LIST[ii].active;
    }

    SetCookie(name, value, 30,null,null, false)
}

ftalk.prototype.check_user = function()
{
    if (LG_USER > 0)
    {
        $(this.talk_body).show();
    }
};

ftalk.prototype.check_dialog_open_in_cookie = function(id)
{
    var name = "ftalk_open_dialog";
    var value = GetCookie(name);
    var arr_value = value.split("@");
    var result = true;

    //alert("check_dialog_open_in_cookie:"+value+"___"+id);
    for (var ii = 0; ii < arr_value.length; ii++)
    {
        var last = arr_value[ii].substring(arr_value[ii].length - 1);
        var first = arr_value[ii].substring(0, arr_value[ii].length - 2);

        if (first == id)
        {
            if (parseInt(last) == 0)
            {
                //alert(first + ":" + last);
                result = false;
                break;
            }
        }
    }
    return result;
};


ftalk.prototype.auto_open_dialog = function(value)
{
    var t = this;
    //alert("auto_open_dialog:"+value);
    var arr_value = value.split("@");
    for (var ii = 0; ii < arr_value.length; ii++)
    {
        var last = arr_value[ii].substring(arr_value[ii].length - 1);
        var first = arr_value[ii].substring(0, arr_value[ii].length - 2);
        //alert(first+':'+last+"@@"+arr_value[ii]);
        if (first == "ftalk_body")
        {
            if (last == 1)
            {
                t.control_min_to_max_noupdate();
            }
            else
                t.control_max_to_min_noupdate();
        }
        else if (first == "message_0")
        {
            t.new_chat_window('0', '系统消息', 'message', true);
        }
        else if (first == "poke_0")
        {
            t.new_chat_window('0', '招惹动态', 'poke', true);
        }
        else if (first == "gift_0")
        {
            t.new_chat_window('0', '礼物消息', 'gift', true);
        }
        else
        {

            $(">div", t.talk_container).each(function(ii)
            {

                if (($(this).attr("name") + '_' + this.id) == first)
                {
                    t.new_chat_window($(this).attr("id"), $(">span:eq(0)", this).html(), $(this).attr("name"), true);
                }
            });
        }
    }
};

ftalk.prototype.bind_head_behaver = function()
{
    var t = this;
    $(t.talk_header_control).click(function()
    {
        if (t.OPEN)
        {
            t.control_max_to_min();
        }
        else
        {
            t.control_min_to_max();
        }
    });

    $(t.talk_header_control).hover(function() { $(this).addClass("ftalk_control_hover") }, function() { $(this).removeClass("ftalk_control_hover") });
};


ftalk.prototype.control_min_to_max = function()
{
    $("#ftalk_minimize").show();
    $("#ftalk_maximize").hide();
    //$("#ftalk_container").show();
    $("#ftalk_container").slideDown("slow");
    this.OPEN = true;
    this.save_open_dialog();
};

ftalk.prototype.control_min_to_max_noupdate = function() {
    $("#ftalk_minimize").show();
    $("#ftalk_maximize").hide();
    //$("#ftalk_container").show();
    $("#ftalk_container").slideDown("slow");
    this.OPEN = true;
    //this.save_open_dialog();
};

ftalk.prototype.control_max_to_min = function()
{
    $("#ftalk_minimize").hide();
    $("#ftalk_maximize").show();
    //$("#ftalk_container").hide();
    $("#ftalk_container").slideUp("slow");
    this.OPEN = false;
    this.save_open_dialog();
};

ftalk.prototype.control_max_to_min_noupdate = function()
{
    $("#ftalk_minimize").hide();
    $("#ftalk_maximize").show();
    //$("#ftalk_container").hide();
    $("#ftalk_container").slideUp("slow");
    this.OPEN = false;
    //this.save_open_dialog();
};


ftalk.prototype.bind_search_behaver = function()
{
    var t = this;
    var k = "快速查找你的好友";
    $("#ftalk_search").addClass("placeholder").val(k).focus(function()
    {
        if (this.value == k) { $(this).removeClass("placeholder").val(""); }
    }).blur(function()
    {
        if (this.value == '')
        {
            $(this).addClass("placeholder").val(k);
        }
    }).keyup(function(event)
    {
        t.search_user($("#ftalk_search").val());
    });
};

ftalk.prototype.search_user = function(key)
{
    if (key == "")
    {
    if (this.ONLY_SHOW_NEW=false)
        $(">div", this.talk_container).show();
    else
        $(">div", this.talk_container).show();
        return;
    }

    $(">div", this.talk_container).each(function(ii)
    {
        var na = $("span:eq(0)", this).html();

        if (na.indexOf(key) >= 0)
        {
            $(this).show()
        }
        else
            $(this).hide();
    });
};

ftalk.prototype.load_user = function() {
    var t = this;
    $.get(t.USER_LIST, { "id": Math.random(), "action": "user_list" }, function(data) {
        $(t.talk_container).html(data);
        t.bind_head_behaver();
        t.bind_user_behaver();
        //t.load_user_application();
        t.reflash_message();
        $(t.talk_body).show();

        var isc = t.get_open_dialog();
        if (isc == null)
            t.save_open_dialog();
        else
            t.auto_open_dialog(isc);

        t.check_newmessage();
        setInterval(function() { t.reflash_message(); }, 20000);
    });
}

ftalk.prototype.check_newmessage = function() {
    var t = this;
    //t.show_pop_window_alert(10);

        $.get(t.USER_LIST, { "id": Math.random(), "action": "load_newmessage" }, function(data) {
            if (data!="") {
                t.show_pop_window_alert(data);
            }
        });
}


ftalk.prototype.show_pop_window_alert = function(count) {
    var t = this;
    var xbox = '<div id="newmessage_0" class="ftalk_frame" style="display: none;height:64px;width:250px;overflow: hidden;">\
                    <span class="ftalk_top" style="margin: 0pt 2px; display: block; height: 1px; font-size: 1px;\
                        overflow: hidden;"></span><span class="ftalk_top" style="margin: 0pt 1px; display: block;\
                            height: 1px; font-size: 1px; overflow: hidden;"></span><span class="ftalk_top" style="margin: 0pt;\
                                display: block; height: 1px; font-size: 1px; overflow: hidden;"></span>\
                    <div class="ftalk_top" style="cursor: pointer; overflow: hidden;">\
                        <div class="ftalk_presence_bubble">\
                            <img border="0" alt="" src="/Images/roster_icon.gif" width="12" height="12" />\
                        </div>\
                        <div class="ftalk_control" id="ftalk_newmessage_control">\
                            <div>\
                                <img id="ftalk_newmessage_close" class="ftalk_control" src="/Images/close.gif"\
                                    width="16" height="16" />\
                            </div>\
                        </div>\
                        <div class="ftalk_header">\
                            新信息提示</div>\
                    </div>\
                    <div class="ftalk_container">\
                    <div style="padding:10px;height:20px" >' + count + '</div>\
                    </div>\
                </div>';

    if (document.getElementById("newmessage_0") == null) {
        $("body").append($(xbox).find("#ftalk_newmessage_close").click(function() { t.close_new_message_window(); }).end());

        this.CURRENT_OPEN_COUNT += 1;
        this.OPEN_DIALOGUE_LIST.push({ pos: t.CURRENT_OPEN_COUNT, divid: "newmessage_0", cyid: "0", name: "新消息提示", type: "newmessage", active: 1, awoke: 0 });
        var de = document.documentElement;
        var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
        var box_w = $("#newmessage_0").width();
        $("#newmessage_0").css({ left: (w - (box_w + 5) * (this.CURRENT_OPEN_COUNT) - 10) + "px" }).slideDown("slow");
        setTimeout(function() { t.close_new_message_window(); }, 10000);
    }
}

ftalk.prototype.load_user_panel = function()
{
    var t = this;
    $.get(t.USER_LIST, { "id": Math.random(), "action": "user_info" }, function(data)
    {
        $(t.USER_PANEL).html(data); t.bind_my_application()
        t.LOAD_USER_LIST = true;
    });
}


ftalk.prototype.load_user_application = function()
{
    var t = this;
    $.get(t.USER_LIST, { "id": Math.random(), "action": "load_application" }, function(data)
    {
        //
    });
};

ftalk.prototype.bind_my_application = function()
{
    var t = this;
    $("#ftalk_my_application").click(function()
    {
        
     });
    
};

ftalk.prototype.bind_user_behaver = function()
{
    var t = this;
    $(">div", this.talk_container).hover(function()
    {
        $(this).addClass("ftalk_container_div_hover");
    }, function()
    {
        $(this).removeClass("ftalk_container_div_hover");
    })
    .css("cursor", "pointer")
    .click(function()
    {
        t.new_chat_window($(this).attr("id"), $(">span:eq(0)", this).html(), $(this).attr("name"));
    });
}

ftalk.prototype.init_talk_body = function()
{
    var t = this;
    if (this.IS_IE6)
    {
        $(this.talk_body).css("position", "absolute");
        $(this.talk_body).css("zIndex", "99999");
        $(this.talk_body).css("bottom", "auto");
        $(this.talk_body).css("clear", "both");
        setInterval(function() { t.set_scroll(); }, 30);
    }
};

ftalk.prototype.new_chat_window = function(id, name, type, nocookie)
{
    var t = this;
    var w = '';
//    if (type != 'message' && type != 'gift' && type != 'poke')
       w = '<div id="' + type + '_' + id + '" class="ftalk_frame" style="width:250px;height:360px; overflow: hidden;" style="display:none;">\
                    </div>';
//    else
//        w = '<div id="' + type + '_' + id + '" class="ftalk_frame" style="width:250px;height:160px; overflow: hidden;" style="display:none;">\
//                    </div>';
    var is_max = 1; //是否最大化
    if (document.getElementById(type + '_' + id) == null)
    {
        if (this.CURRENT_OPEN_COUNT < this.LIMIT_OPEN_COUNT)
        {
            $("body").append(w);
            this.CURRENT_OPEN_COUNT += 1;

            if (t.check_dialog_open_in_cookie(type + '_' + id))//是否打开
                this.OPEN_DIALOGUE_LIST.push({ pos: t.CURRENT_OPEN_COUNT, divid: type + '_' + id, cyid: id, name: name, type: type, active: 1, awoke: 0 });
            else
            {
                is_max = 0;
                this.OPEN_DIALOGUE_LIST.push({ pos: t.CURRENT_OPEN_COUNT, divid: type + '_' + id, cyid: id, name: name, type: type, active: 0, awoke: 0 });
            }
            if (arguments.length == 3)
            {
                this.save_open_dialog();
            }

            this.CURRENT_OPEN_INDEX = this.CURRENT_OPEN_COUNT;
            var de = document.documentElement;
            var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
            var box_w = $('#' + type + '_' + id).width();
            var iframe_src = t.get_frame_url(id, name, type,is_max);
            var iframeid = 'ftalk_iframe_' + type + '_' + id;
            var obj_pop_div = document.getElementById(type + '_' + id)
            var obj_iframe = window.document.createElement("iframe");
            if (iframe_src)
            {
                obj_iframe.setAttribute("src", iframe_src);
                obj_iframe.setAttribute("height", 360);
                obj_iframe.setAttribute("width", "100%");
                obj_iframe.setAttribute("id", iframeid);
                obj_iframe.name = iframeid;
                obj_iframe.scrolling = "no";
                obj_iframe.frameBorder = "0";
                obj_iframe.allowTransparency = true;
                obj_pop_div.appendChild(obj_iframe);

                if (this.IS_IE6)
                {
                    $('#' + type + '_' + id).css("position", "absolute");
                    $('#' + type + '_' + id).css("zIndex", "99999");
                    $('#' + type + '_' + id).css("bottom", "auto");
                    $('#' + type + '_' + id).css("clear", "both");
                }

                $('#' + type + '_' + id).css({ left: (w - (box_w + 5) * (t.CURRENT_OPEN_COUNT)-10) + "px" }).show();
                //$('#' + type + '_' + id).css({ left: (w - (box_w + 5) * (t.CURRENT_OPEN_COUNT) - 10) + "px" }).slideDown("slow");
            }
        }
        else
        {
            alert("你打开的窗口太多了，请先关闭几个");
        }
    }

};


ftalk.prototype.window_resize = function()
{
    var t = this;
    $(window).resize(function()
    {
        if (t.OPEN_DIALOGUE_LIST.length > 0)
        {
            t.dialog_reflash();
        }
    });
};

ftalk.prototype.dialog_activite = function(id, result)
{
    var iframeid = 'ftalk_iframe_' + id;
    if (result == 1)
    {
        $("#" + id).css("height", "360px")
        //this.auto_fit_iframe(iframeid);
    }
    else
    {
        $("#" + id).css("height", "20px")
        //$("#" + iframeid).css("height", "20px");
        //this.auto_fit_iframe(iframeid);
    }
    for (var ii = 0; ii < this.OPEN_DIALOGUE_LIST.length; ii++)
    {
        if (this.OPEN_DIALOGUE_LIST[ii].divid == id)
        {
            this.OPEN_DIALOGUE_LIST[ii].active = result;
            break;
        }
    }

    this.save_open_dialog();
};

ftalk.prototype.update_head_title = function()
{
    if (this.MSG_COUNT > 0)
    {
        $(this.talk_header).html('站内消息&nbsp;<span>(' + this.MSG_COUNT + ')</span>');
    }
    else
    {
        $(this.talk_header).html('站内消息');
    }
};


ftalk.prototype.reflash_message = function()
{
    var k = this;
    this.MSG_COUNT = 0;
    var messagecount = 0;
    var pokecount = 0;
    var giftcount = 0;
    $.getJSON(this.USER_LIST + "?action=reflash_msg_count&id=" + Math.random(), function(data)
    {
        $(">div", k.talk_container).each(function(ii)
        {
            var t = this;
            var id = $(this).attr("id");
            var type = $(this).attr("name");
            var count = k.get_value_in_JSON(data, id, type);
            if (!k.isexist_in_array(id, type) && count > 0)
            {
                if (k.CURRENT_OPEN_COUNT < k.LIMIT_OPEN_COUNT)
                {
                    k.new_chat_window($(this).attr("id"), $(">span:eq(0)", this).html(), $(this).attr("name"));
                }
                else
                {
                    k.MSG_COUNT += parseInt(count);
                    $("span:eq(1)", t).html('(' + count + ')');
                }
            }
            else
                $("span:eq(1)", t).html('');
        });

        $.each(data, function(i, n)
        {
            if (n.type == 'message')
            {
                messagecount = n.count;
            }
            else if (n.type == 'poke')
            {
                pokecount = n.count;
            }
            else if (n.type == 'gift')
            {
                giftcount = n.count;
            }
        });

        if (messagecount > 0)
        {
            k.MSG_COUNT += parseInt(messagecount);
            $(k.USER_PANEL_MESSAGE).html('(' + messagecount + ')');
        }
        else
        {
            $(k.USER_PANEL_MESSAGE).html('');
        }

        if (pokecount > 0)
        {
            k.MSG_COUNT += parseInt(pokecount);
            $(k.USER_PANEL_POKE).html('(' + pokecount + ')');
        }
        else
        {
            $(k.USER_PANEL_POKE).html('');
        }

        if (giftcount > 0)
        {
            k.MSG_COUNT += parseInt(giftcount);
            $(k.USER_PANEL_GIFT).html('(' + giftcount + ')');
        }
        else
        {
            $(k.USER_PANEL_GIFT).html('');
        }

        k.update_head_title();
    });
};


ftalk.prototype.poke = function(userid, objectid)
{
    PokeMe(userid, objectid);
};


ftalk.prototype.ignore_poke = function(pokeid, obj)
{
    ignorePoke(pokeid, obj);
};

ftalk.prototype.get_value_in_JSON = function(data, id, type)
{
    var nm = 0;
    $.each(data, function(i, n)
    {

        if (id == n.id && type == n.type)
        {
            nm = n.count;
        }
    });

    return nm;
};

ftalk.prototype.isexist_in_array = function(id, type)
{
    for (var ii = 0; ii < this.OPEN_DIALOGUE_LIST.length; ii++)
    {
        if (this.OPEN_DIALOGUE_LIST[ii].divid == type + '_' + id)
        {
            return true;
        }
    }
    return false;
};


ftalk.prototype.dialog_reflash = function()
{
    this.dialog_manage();
    var t = this;
    var de = document.documentElement;
    var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    for (var ii = 0; ii < this.OPEN_DIALOGUE_LIST.length; ii++)
    {
        var box_w = $('#' + t.OPEN_DIALOGUE_LIST[ii].divid).width();
        $('#' + t.OPEN_DIALOGUE_LIST[ii].divid).css({ left: (w - (box_w + 5) * (t.OPEN_DIALOGUE_LIST[ii].pos)-10) + "px" });
    }
};

ftalk.prototype.get_frame_url = function(id, name, type,ismax)
{
    if (type == "personal")
    {
        return "/Pop/Message/personal.aspx?userid=" + id + "&name=" + escape(name) + "&is_max="+ismax+"&id=" + Math.random();
    }
    else if (type == "crowd")
    {
        return "/Pop/Message/crowd.aspx?userid=" + id + "&name=" + escape(name) + "&is_max=" + ismax + "&id=" + Math.random();
    }
    else
    {
        return "/Pop/Message/Message.aspx?userid=" + id + "&name=" + escape(name) + "&is_max=" + ismax + "&type="+type+"&id=" + Math.random();
    }
};


ftalk.prototype.set_scroll = function()
{
    var t = this;
    var de = document.documentElement;

    var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;

    var yScrolltop;
    if (self.pageYOffset)
    {
        yScrolltop = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop)
    {	 // Explorer 6 Strict
        yScrolltop = document.documentElement.scrollTop;
    } else if (document.body)
    {// all other Explorers
        yScrolltop = document.body.scrollTop;
    }

    var TB_HEIGHT = $(this.talk_body).height();
    $(this.talk_body).css({ top: (h - TB_HEIGHT + yScrolltop) + "px" });


    for (var ii = 0; ii < this.OPEN_DIALOGUE_LIST.length; ii++)
    {
        var TB_HEIGHT1 = $('#' + this.OPEN_DIALOGUE_LIST[ii].divid).height();
        $('#' + this.OPEN_DIALOGUE_LIST[ii].divid).css({ top: (h - TB_HEIGHT1 + yScrolltop) + "px" });
    }

};


ftalk.prototype.auto_fit_iframe = function(iframeObj)
{
    alert(iframeObj.Document.body.scrollHeight);
    iframeObj.height = (iframeObj.Document ? iframeObj.Document.body.scrollHeight : iframeObj.contentDocument.body.offsetHeight);

};

ftalk.prototype.close_pancel = function(type, id)
{
    this.get_current_activite_dialog_index(type + '_' + id);
    this.OPEN_DIALOGUE_LIST.splice(this.CURRENT_OPEN_INDEX, 1);
    $('#ftalk_iframe' + type + '_' + id).remove();
    $('#' + type + '_' + id).remove();
    this.CURRENT_OPEN_COUNT -= 1;
    this.save_open_dialog();
    this.dialog_reflash();
};

ftalk.prototype.close_new_message_window = function() {
    var t = this;
    if (document.getElementById("newmessage_0") != null) {
        $("#newmessage_0").slideUp("slow", function() {
            t.get_current_activite_dialog_index("newmessage_0");
            t.OPEN_DIALOGUE_LIST.splice(t.CURRENT_OPEN_INDEX, 1);
            t.CURRENT_OPEN_COUNT -= 1;
            $("#newmessage_0").remove();
            //t.save_open_dialog();
            t.dialog_reflash();
        });
    }
};

ftalk.prototype.dialog_manage = function()
{
    for (var ii = 0; ii < this.OPEN_DIALOGUE_LIST.length; ii++)
    {
        this.OPEN_DIALOGUE_LIST[ii].pos = ii+1;
    }

    this.CURRENT_OPEN_COUNT = this.OPEN_DIALOGUE_LIST.length;
};

ftalk.prototype.getPageSize = function()
{
    var de = document.documentElement;
    var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;

    arrayPageSize = new Array(w, h)
    return arrayPageSize;
};


ftalk.prototype.get_current_activite_dialog_index = function(id)
{
    //this.CURRENT_OPEN_INDEX
    for (var ii = 0; ii < this.OPEN_DIALOGUE_LIST.length; ii++)
    {
        if (this.OPEN_DIALOGUE_LIST[ii].divid == id)
        {
            this.CURRENT_OPEN_INDEX = ii;
            break;
        }
    }
    
};

ftalk.prototype.getPageScrollTop = function()
{
    var yScrolltop;
    if (self.pageYOffset)
    {
        yScrolltop = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop)
    {	 // Explorer 6 Strict
        yScrolltop = document.documentElement.scrollTop;
    } else if (document.body)
    {// all other Explorers
        yScrolltop = document.body.scrollTop;
    }
    arrayPageScroll = new Array('', yScrolltop)
    return arrayPageScroll;
};