﻿function MenuInit() {
    $(".menu_bar > ul > li").hover(function() {
        $(this).css("background-image", "url(/images/menu_bg1.jpg)");
        $(this).children("a").css("color", "#fff");
    }, function() {
        $(this).css("background-image", "url(/images/menu_bg.jpg)");
        $(this).children("a").css("color", "#60606C");
    }).click(function() {
        window.location.href = $(this).children("a").attr("href");
    });

    $(".drop_menu").hover(function() {
        $(this).addClass("drop_menu_over");
    }, function() {
        $(this).removeClass("drop_menu_over");
    });


}


function KeFuInit() {
    var sms = new SMSForm();
    sms.Init();
}

function SMSForm() {
    var _this = this;
    var obj = $("<div style='background-color:White;position: absolute;left:-1000px;border: 1px solid #565662; width: 300px; height: 25px;font-size: 12px;color:#E8E8E8;'>\
            <div id='KeFuTitle' style='width: 298px;  cursor:pointer;height: 28px; background-color: #565662; margin: 1px;'>\
                <div style='float:left; padding: 7px 5px 0px 3px;'>在线咨询</div><div id='BtnClosed' style='margin: 3px 4px;float:right;width:20px;;height:20px;background-image:url(/Images/btn.gif);background-position:center top;'></div>\
                </div> <div id='KeFuBody' style='width: 295px; margin: 0px; padding: 5px 0px 0px 3px;'>\
                <table width='100%' border='0' cellspacing='0' cellpadding='0' style='color:#565662;'>\
                    <tr>\
                        <td align='center'>\
                            QQ方式\
                        </td>\
                        <td align='center'>\
                            Msn方式\
                        </td>\
                    </tr>\
                    <tr>\
                        <td align='center'  valign='top'>\
                            <a href='http://sighttp.qq.com/cgi-bin/check?sigkey=3a02f78d0ba5f39769aeb8b7dcbee769dbe49644f8ac52025364667515f727f5'\
                                target='_blank;' onclick='var tempSrc='http://sighttp.qq.com/wpa.js?rantime='+Math.random()+'&sigkey=3a02f78d0ba5f39769aeb8b7dcbee769dbe49644f8ac52025364667515f727f5';var oldscript=document.getElementById('testJs');var newscript=document.createElement('script');newscript.setAttribute('type','text/javascript'); newscript.setAttribute('id', 'testJs');newscript.setAttribute('src',tempSrc);if(oldscript == null){document.body.appendChild(newscript);}else{oldscript.parentNode.replaceChild(newscript, oldscript);}return false;'>\
                                <img border='0' src='http://wpa.qq.com/pa?p=1:3253150:47' style='margin: 5px 0px 8px 0px;'\
                                    alt='点击这里给我发消息'></a><br />\
                            <a href='http://sighttp.qq.com/cgi-bin/check?sigkey=3a02f78d0ba5f39769aeb8b7dcbee769dbe49644f8ac52025364667515f727f5'\
                                target='_blank;' onclick='var tempSrc='http://sighttp.qq.com/wpa.js?rantime='+Math.random()+'&sigkey=3a02f78d0ba5f39769aeb8b7dcbee769dbe49644f8ac52025364667515f727f5';var oldscript=document.getElementById('testJs');var newscript=document.createElement('script');newscript.setAttribute('type','text/javascript'); newscript.setAttribute('id', 'testJs');newscript.setAttribute('src',tempSrc);if(oldscript == null){document.body.appendChild(newscript);}else{oldscript.parentNode.replaceChild(newscript, oldscript);}return false;'>\
                                <img border='0' src='http://wpa.qq.com/pa?p=1:3253150:47' alt='点击这里给我发消息'></a>\
                        </td>\
                        <td align='center'>\
                            <a href='msnim:add?contact=hzjbye@hotmail.com' target='_blank;'>\
                                <img src='http://im.live.cn/click/images/a4/a4_1_1.jpg' style='clear: Both; padding-bottom: 10px;border: 0px' /></a>\
                        </td>\
                    </tr>\
                    <tr>\
                        <td colspan='2'>\
                            <iframe id='KefuFrm' frameborder='no' border='0' marginwidth='0' marginheight='0' scrolling='no' style='width:294px;height:250px;' src='kefu.html'>\
                            </iframe>\
                        </td>\
                    </tr>\
                </table> </div> </div>");

    this.Init = function() {
        var one = true;
        $(document.body).append(obj);
        $("#KefuFrm").load(function() {
            if (CheckOnline() && one) {
                one = false;
                SetReferrer();
                Rep();

                window.setInterval(_this.SetTop, 10);
                $(obj).css("left", "1px");
                _this.Max();


                $("#KeFuTitle").toggle(function() {
                    _this.Min();
                }, function() {
                    _this.Max();
                });
            } else {
            $(obj).empty();
            }
        });
    };

    this.SetTop = function() {
        var docuTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
        var y = docuTop + document.documentElement.clientHeight - 3;
        $(obj).css("top", y - $(obj).height() + "px");
        $(obj).css("visibility", "visible");
    };


    this.Max = function() {
        $(obj).animate({ height: "383px" }, { queue: false, duration: 1000, complete: function() {
            $("#KeFuBody").show();
            $("#BtnClosed").css("background-position", "center top");
        }
        });
    }

    this.Min = function() {
        $(obj).animate({ height: "30px" }, { queue: false, duration: 1000, complete: function() {
            $("#KeFuBody").hide();
            $("#BtnClosed").css("background-position", "center bottom");
        }
        });
    }
}


function elreg(temp, dataarry) {
    return temp.replace(/\$\{([\w]+)\}/g, function(s1, s2) { var s = dataarry[s2]; if (typeof (s) != "undefined") { return s; } else { return "&nbsp;"; } });
}


function Rep() {
    $("#KefuFrm").contents().find("#title").replaceWith("<a  href='#' style='font-size: 12px; padding-left: 4px; color: rgb(255, 255, 255); font-weight: bold; font-family: Arial; text-decoration: none;'>与在线客服直接交流</a>");
}

function SetReferrer() {
    var item = $("#KefuFrm").contents().find("#innerChat").attr("src").split("&");
    for (i = 0; i < item.length; i++) {
        var temp = item[i].split("=");
        if (temp.length == 2) {
            if (temp[0] == "url")
                item[i] = "url=" + parent.location;
            else if (temp[0] == "ref")
                item[i] = "ref=" + parent.document.referrer;
        }
    }
    var url = "";
    for (i = 0; i < item.length; i++) {
        url += item[i] + "&";
    }
    $("#KefuFrm").contents().find("#innerChat").attr("src", url);
}

function CheckOnline() {
    if ($("#KefuFrm").contents().find("#innerChat").attr("src").lastIndexOf("awayMessage.do?l=") == -1)
        return true;
    else
        return false;
}