﻿


function WebChat(objName) {

    this.baseURL = "http://800.eesina.com/";

    this.staticURL = "http://800.eesina.com/";

    //this.baseURL = "http://801.eesina.com/";
    //this.staticURL = "http://801.eesina.com/";
    
     //this.staticURL = "http://192.168.1.42/";
      //this.baseURL = "http://192.168.1.42/";
    //this.staticURL = "http://kk.com/";
    //this.baseURL = "http://kk.com/";
    //this.baseURL = "http://localhost:3601/";
    //this.staticURL = "http://localhost:3601/";
    
    //alert("aaaaaa");
    
    this.companyId = "";   //公司ID
    this.roomId = null ;
    this.user = "";
    this.language = "";
    this.winTitle = "";  
    this.t_title=""
    this.minText = unescape("%u6DF1%u5733%u5E02%u91D1%u4F26%u79D1%u6280%u5728%u7EBF%u670D%u52A1.."); //深圳市金伦科技在线服务！
    this.bgColor = "#2a60ac"; //背景颜色
    
    
    this.position = ""
    this.barWidth = "200px";  //工具栏宽度
    this.barHeight = "40px";  //工具栏高度
    this.miniWidth = "418px";  // 
    this.miniHeight = "330px";
    this.width = "203px";   //浮出宽度
    this.height = "265px";  //浮出高度

    //this.previewBG = ""; //this.staticURL + "images/prvbg_172x100.png";
    this.bminiMode = false;  //最小模式
    this.bstatic = true;   //固定不变的
    this.bopen = false;
    this.bPreview = false;
    this.canDrag = true;
    this.lastLoad = false;
    this.previewMode = "";
    this.ChatRoomStatus = "";
    
    this.referrerURL = escape(document.referrer); //获得当前网页的关键字
    //alert(this.referrerURL);

    this.URL = null;
    //关闭提示
    this.closeHint = unescape("%u5373%u5C06%u5173%u95ED%u5728%u7EBF%u4EA4%u8C08%u9762%u677F%uFF0C%u5237%u65B0%u9875%u9762%u53EF%u91CD%u65B0%u663E%u793A");
    this.minTitle = unescape("%u6700%u5C0F%u5316%u4EA4%u8C08%u7A97%u53E3");  //最小化提示
    this.maxTitle = unescape("%u5728%u76F8%u540C%u7A97%u53E3%u6253%u5F00");  //最大化提示
    this.openTitle = unescape("%u5728%u65B0%u7A97%u53E3%u6253%u5F00");       //打开提示
    this.inTitle = unescape("%u5927/%u5C0F%u5316%u7A97%u53E3");         //大小化窗口
    this.closeTitle = unescape("%u5173%u95ED%u4EA4%u8C08%u7A97%u53E3");

    this.color = "#000000";
    this.objName = objName;
    this.zIndex = 99999;
    this.staticTime = 5;
    this.bHidden = false;
    this.roomURL = "";
    this.barBG = this.staticURL + "images/top_center.gif";        //工具栏背景
    // 显示按钮图片路径
    this.minButton = this.staticURL + "images/webchat/min_btn.gif";
    this.maxButton = this.staticURL + "images/webchat/max_btn.gif";
    this.openButton = this.staticURL + "images/webchat/open_btn.gif";
    this.closeButton = this.staticURL + "images/webchat/close_btn.gif";
    this.inButton = this.staticURL + "images/webchat/in_btn.gif";
    //工具栏的背景图片
    this.bgTopLeft = this.staticURL + "images/top_left.gif";
    this.bgTopRight = this.staticURL + "images/top_right.gif";
   // this.bgTopCenter = this.staticURL + "images/top_center.gif";
    
    this.odiv = null;   //div对象
    this.popMode = true;
    this.top = "";
    this.left = "";
    this.Ypos = 0;
    this.Xpos = 0;
    this.mwin = null;
    this.staticTimer = null;
    this.tbwidth = 0;
    this.tbheight = 0;
    this.winStatus = "";
    this.barBGStr = "";
    this.oldInit = null;

    //初始化界面
    this.init = function() {

        var ojs = document.getElementById('WebChatScript'); //获得 Script 对象
        var bcreate = true; //要创建 div 对象
        try {
            if (typeof ("zoomsun_wc_cfg") != "undefined") {
                for (var i in zoomsun_wc_cfg) {
                    eval("this." + i + "=zoomsun_wc_cfg." + i);
                }
                if (zoomsun_wc_cfg.roomid)
                    this.URL = zoomsun_wc_cfg.roomid;
            }
        } catch (err) { }
        if (ojs) {
            var tstr;
            //更具 div对象中的属性。来赋值给webchat对象 属性
            tstr = ojs.getAttribute("website")  //网站站点
            if (tstr) this.URL = tstr;

            // tstr = ojs.getAttribute("roomid");  
            //if (tstr) this.roomid = tstr;

            //从Script 对象中获得相关的属性
            tstr = ojs.getAttribute("companyId");  //获得公司ID属性值
            if (tstr) this.companyId = tstr;

            tstr = ojs.getAttribute("minText");
            if (tstr) this.minText = unescape(tstr);
            tstr = ojs.getAttribute("bgColor");
            if (tstr) this.bgColor = tstr;
            tstr = ojs.getAttribute("winTitle");
            if (tstr) this.winTitle = unescape(tstr);
            tstr = ojs.getAttribute("position"); //位置
            if (tstr) this.position = tstr;

            tstr = ojs.getAttribute("bStatic");
            if (tstr) this.bstatic = (tstr.match(/false/i) ? false : true);
            tstr = ojs.getAttribute("popMode");
            if (tstr) this.popMode = (tstr.match(/false/i) ? false : true);
            tstr = ojs.getAttribute("bminiMode");
            if (tstr) this.bminiMode = (tstr.match(/false/i) ? false : true);
            tstr = ojs.getAttribute("create");
            if (tstr) bcreate = (tstr.match(/false/i) ? false : true);
            tstr = ojs.getAttribute("bPreview");
            if (tstr) this.bPreview = (tstr.match(/true/i) ? true : false);
            tstr = ojs.getAttribute("bOpen");
            if (tstr) this.bopen = (tstr.match(/true/i) ? true : false);

            tstr = ojs.getAttribute("user");  //使用者
            if (tstr) {
                tstr = tstr.replace(/(\s|&nbsp;)/ig, "");
                if (tstr.length > 0) this.user = tstr;
            }
        }

        if (typeof (zoomsun_wc_cfg) == "undefined")
            zoomsun_wc_cfg = new Object();
        if (!zoomsun_wc_cfg.setStatus) {
            eval('zoomsun_wc_cfg.setStatus = function(st,expday){ ' + this.objName + '.setStatus(st,expday); };');
        }
        if (!zoomsun_wc_cfg.getStatus) {
            eval('zoomsun_wc_cfg.getStatus = function(){ return ' + this.objName + '.getStatus(); };');
        }

        if (bcreate)
            this.create();  //创建

    };

    //创建对象 打开对应的页面
    this.create = function() {
        // alert("create");
        if (!this.bstatic) {  //是否为固定
            this.canDrag = false;
        } else {
            if (this.position.search(/(left|right)/ig) == -1) // 位置
                this.position = this.position + ";right:16px;";
            if (this.position.search(/(top|bottom)/ig) == -1)
                this.position = this.position + ";bottom:16px;";
        }

        if (this.user && this.user != "")
            this.user = this.user.replace(/<.*>(.*)<.*>/g, "$1").replace(/(\s|&nbsp;)/ig, "");

        if (!this.URL || this.URL == "") {
            this.URL = escape(location.host + location.pathname);
        } else {
            this.URL = this.URL.replace(/^(http|https):\/\//i, "");
        }
        this.roomURL = this.baseURL;
        //this.roomURL = "http://192.168.1.42/EES800/client/ClientChat.aspx";
        var Sys = {}; // 判断浏览器的
        var ua = navigator.userAgent.toLowerCase();
        var s;
        (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
         (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
         (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
         (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
         (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

        var t_titleLenght = this.winTitle.length;
        this.t_title = this.winTitle;
        //以下进行测试
        if (Sys.ie == '6.0') {
            if (this.t_title.length > 8)
            { this.t_title = this.winTitle.substring(0, 8) + "..."; }
            this.roomURL = this.staticURL + "client/ClientChat.aspx";
        }
        else if (Sys.ie == '7.0') {
            if (this.t_title.length > 8) {
                this.t_title = this.winTitle.substring(0, 8) + "...";
            }
            this.roomURL = this.staticURL + "client/ClientChat7.aspx";
        }
        else if (Sys.firefox) {
           
            if (this.t_title.length > 8) {
                this.t_title = this.winTitle.substring(0, 8) + "...";
            }
            this.roomURL = this.staticURL + "client/ClientChatFox.aspx";
        } else {  //默认都跳转到这里
            if (this.t_title.length > 8) {
                this.t_title = this.winTitle.substring(0, 8) + "...";
            }
            this.roomURL = this.staticURL + "client/ClientChat7.aspx";
        }
        // if (Sys.chrome) document.write('Chrome: ' + Sys.chrome);
        //if (Sys.opera) document.write('Opera: ' + Sys.opera);
        //if (Sys.safari) document.write('Safari: ' + Sys.safari);


        // alert("161: " + this.roomURL);


        //设置工具栏的背景颜色
        this.barBGStr = "";
        if ((typeof (document.body.style.filter) != "undefined")) {
            if (this.barBG == "") {
                var colstr = this.bgColor.replace(/#/g, "");
                this.barBGStr += ' background:transparent; filter:';
                this.barBGStr += 'progid:DXImageTransform.Microsoft.gradient(GradientType =1,enabled=true,startColorstr=#88' + colstr + ', endColorstr=#88' + colstr + ')';
            } else {
                if (this.barBG.search(/\.png$/i) != -1) {
                    this.barBGStr += ' background:transparent; filter:';
                    this.barBGStr += "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src='" + this.barBG + "'); ";
                } else {
                    this.barBGStr += " background:transparent url('" + this.barBG + "'); ";
                }
            }
        } else {
            if (this.barBG == "") {
                this.barBGStr += ' background-color:' + this.bgColor + '; ';
            } else {
                this.barBGStr += " background:transparent url('" + this.barBG + "'); ";
            }
        }
        var tHTML = '';
        //  alert("216 this.bstatic: " + this.bstatic);
        if (this.bstatic) {
            tHTML += '<div id="divWebChat" style="font-size:12px;text-align:left; cursor:default;position:absolute;' + this.position + '; width:' + this.barWidth + ';height:' + this.barHeight + ';z-index:' + this.zIndex + ';"></div>';
        } else {
            tHTML += '<div id="divWebChat" style="font-size:12px;text-align:left;cursor:default;position:relative;"></div>';
        }

        if (!this.lastLoad) {
            document.write(tHTML);
            this.load();
        } else {
            if (!this.bstatic)
                document.write(tHTML);
            if (typeof (document.body.onload) == "function")
                this.oldInit = document.body.onload;
            document.body.onload = function() {
                if (__oWC.oldInit)
                    __oWC.oldInit();
                __oWC.load();
            };
        }
    };

    //显示聊天界面
    this.show = function() {
        if (this.previewMode == "block") {

            var el = this.odiv.firstChild;
            // alert("234: block + " + el.clientWidth + " " + el.clientHeight);
            this.odiv.style.width = el.clientWidth + "px";
            this.odiv.style.height = el.clientHeight + "px";
        }
        //alert("show");
        if (!this.odiv) return false;
        var tHTML = "";
        //this.odiv.style.backgroundColor = "#888888"  //自己加的

        if (this.bminiMode) {  //是否为最小模式
            // alert("236: 最小：");
            this.odiv.style.width = this.miniWidth;
            this.odiv.style.height = this.miniHeight;
        } else if (!this.bstatic) { //默认是不变，打开
            //alert("240:正常：");
            this.odiv.style.width = this.width;
            this.odiv.style.height = this.height;
        } else {
            // alert("244: 默认：");
            if (this.width.search("%") != -1) {
                this.odiv.style.width = Math.floor(this.tbwidth * Number(this.width.replace("%", "")) / 100) + "px";
                // alert(this.odiv.style.width);
            } else {
                this.odiv.style.width = this.width;
            }
            if (this.height.search("%") != -1) {
                this.odiv.style.height = Math.floor(this.tbheight * Number(this.height.replace("%", "")) / 100) + "px";
                // alert(this.odiv.style.height);
            } else {
                this.odiv.style.height = this.height;

            }
            //alert("276 this.odiv.style.width  : " + this.odiv.style.width);
            //alert("276 this.odiv.style.height  : " + this.odiv.style.height);
        }
        if (!(!this.bstatic && this.bopen)) {
            tHTML += '<table border="0" cellpadding="0" style="border-collapse: collapse; font-size: 12px; ';
            tHTML += this.barBGStr;
            tHTML += '" width="99%" height="25px"><tr><td style=" background:transparent url(\'' + this.bgTopLeft + '\'); width:7px;" ><div style="width:7px;"><div></td> ';
            tHTML += '<td nowrap width="76%" style="text-align:left;" ><div id="divTitle" onmouseover="__oWC.drag(this);" style="position:relative;' + (this.canDrag ? 'cursor:move;' : '') + 'font-size:9pt;margin-left:4px;margin-top:4px;margin-right:4px;color:#000;">' + this.t_title + '</div></td>';
            tHTML += '<td nowrap align=right valign=top ><div style="position:relative;margin-right:4px;padding:0px; cursor:hand;">';
            //tHTML += '<img onclick="' + this.objName + '.setStatus(\'min\');return false;"  border="0" title="' + this.minTitle + '" src="' + this.minButton + '">';
            tHTML += '<img border="0" onclick="' + this.objName + '.swch();return false;" title="' + this.inTitle + '" src="' + this.inButton + '"/>';
            // tHTML += '<img border="0" onclick="' + this.objName + '.open();return false;" title="' + this.openTitle + '" src="' + this.openButton + '">';
            //tHTML += '<img border="0" onclick="' + this.objName + '.full();return false;" title="' + this.maxTitle + '" src="' + this.maxButton + '">';
            tHTML += '<img onclick="' + this.objName + '.close();return false;"  border="0" title="' + this.closeTitle + '" src="' + this.closeButton + '"/>';
            tHTML += '</div></td>   <td style=" background:transparent url(\'' + this.bgTopRight + '\'); width:7px; " ><div style="width:7px;"><div></td> ';
            tHTML += '</tr></table>';
        }
        tHTML += '<iframe  id="iframeWebChat" width="100%" height="100%" name="iframeWebChat" src="' + this.roomURL + '?text=' + this.URL + '&companyId=' + this.companyId +'&keyWord=' + this.referrerURL+' " frameborder="0" scrolling="no" allowtransparency="true" ></iframe> ';
        //alert("267: " + tHTML);
        this.odiv.innerHTML = tHTML;
        this.winStatus = "show";  //窗口显示的状态

        return true;
    };


    // 加载方法
    this.load = function() {
        //设置或者返回在 Dictionary 对象中进行字符串主键比较时所使用的比较模式。
        var tb = (document.compatMode != "BackCompat") ? document.documentElement : document.body;
        if (tb) {
            this.tbwidth = tb.clientWidth;
            this.tbheigh = tb.clientHeight;
        }

        this.odiv = document.getElementById("divWebChat");
        if (!this.odiv) { // 没有divwebChat ID 创建一个DIV层
            var el;
            el = document.createElement("DIV");
            el.id = "divWebChat";
            el.style.cssText = 'font-size:12px;cursor:default;position:absolute;' + this.position + '; width: ' + this.barWidth + ';height:' + this.barHeight + ';z-index:' + this.zIndex + '; ';
            this.odiv = document.body.appendChild(el);
        }
        var st = this.getCookie("ChatRoomStatus"); //获得聊天室的状态
        st = st ? st : this.ChatRoomStatus;
        if (st == "") {
            st = (this.bHidden ? "hidden" : (this.bopen ? "show" : "min"));
        }
        this.bHidden = (st == "hidden");
        this.setStatus(st); //修改DIV层的显示状态
        var m, tn;
        this.position = this.position.toLowerCase().replace(/\s/g, "");
       // alert("305: this.position: " + this.position);
        if (this.Ypos == 0) {
            m = this.position.match(/(bottom|top):(\d*)px/i)
            if (m && m[1] && m[2]) {
                tn = Number(m[2]);
                if (m[1] == 'bottom')
                    this.Ypos = tn;
                else
                    this.Ypos = tb.clientHeight - tn - this.odiv.clientHeight;
            }
        }
        if (this.Xpos == 0) {
            m = this.position.match(/(left|right):(\d*)px/i)
            if (m && m[1] && m[2]) {
                tn = Number(m[2]);
                if (m[1] == 'right')
                    this.Xpos = tn;
                else
                    this.Xpos = tb.clientWidth - tn - this.odiv.clientWidth;
            }
        }
        this.makeStatic();
    };
    
    // 最小化窗口
    this.min = function() {
        if (!this.odiv) return false;
        if (this.previewMode == "" && !this.bPreview) {
            this.previewMode = "block";
        }
        //return this.preview();
        return this.show();
    };
    
    this.makeWindowName = function(wName) {
        wName = wName.replace(/@/, "at");
        wName = wName.replace(/\./g, "dot");
        wName = wName.replace(/\//g, "slash");
        wName = wName.replace(/&/g, "amp");
        wName = wName.replace(/\'/g, "tick");
        wName = wName.replace(/=/g, "equals");
        wName = wName.replace(/#/g, "pound");
        wName = wName.replace(/:/g, "colon");
        wName = wName.replace(/%/g, "percent");
        wName = wName.replace(/-/g, "dash");
        wName = wName.replace(/ /g, "blank");
        wName = wName.replace(/\?/g, "mk");
        return wName;
    };
    //打开聊天 层
    this.open = function() {
        if (!this.popMode) {
            this.show();
            return;
        }
        this.mwin = window.open(this.roomURL, "WebChat_" + this.makeWindowName(this.roomURL.substr(this.roomURL.length - 10)), "width=640px,height=480px,resizable=yes");
        this.min();
        var oif = document.getElementById("iframeWebChat");
        if (!oif) {
            return;
        } else {
            document.location.href = oif.src;
        }
    };

    this.swch = function() {

        if (!this.odiv) return false;

        var oif = document.getElementById("iframeWebChat");
        if (!oif) return;
        //alert("name: " + oif.name)
        //alert(oif.contentWindow.document);
       // var childDocument = oif.contentWindow.document;
        // alert(childDocument.getElementById("divChat").className);
        // alert(oif.contentWindow.$);


        //alert("446: " + this.odiv.clientWidth + " height: " + this.odiv.clientHeight);
        if (!(this.odiv.clientWidth >203  && this.odiv.clientHeight > 265)) {   //修改过
            this.odiv.style.width = this.miniWidth;
            this.odiv.style.height = this.miniHeight;
            this.bminiMode = true;
            document.getElementById("divTitle").innerText = this.winTitle;
           // this.changeWindowSize(oif.contentWindow.$, "sm"); //修改子窗体的大小样式
        } else {
            if (this.width.search("%") != -1) {
                this.odiv.style.width = Math.floor(this.tbwidth * Number(this.width.replace("%", "")) / 100) + "px";
            } else {
                this.odiv.style.width = this.width;
            }

            if (this.height.search("%") != -1) {
                this.odiv.style.height = Math.floor(this.tbheight * Number(this.height.replace("%", "")) / 100) + "px";
            } else {
                this.odiv.style.height = this.height;
            }
            this.bminiMode = false;
            document.getElementById("divTitle").innerText = this.t_title;
            //this.changeWindowSize(oif.contentWindow.$, "big"); //修改子窗体的大小样式
        }

    };

    //关闭
    this.close = function() {

        if (!this.odiv) return false;
        if (this.closeHint && this.closeHint != "" && !confirm(this.closeHint))
            return;
        this.odiv.style.width = "80px";
        this.odiv.innerHTML = "";
        this.winStatus = "";
        
        // this.user_loginOut();
        var oif = document.getElementById("iframeWebChat");
        if (!oif) return;
        //alert(oif.src);
        document.location.href = oif.src;
    };

    //设置这个DIV层的聊天状态
    this.setStatus = function(st, expday) {
        if (!this.odiv) {
            this.load();
        }
        if (!st || st == "") st = (this.bopen ? "show" : "min");
        if (st == "hidden") {
            if (this.odiv.style.display != "none") { this.odiv.style.display = "none"; }
            this.bHidden = true;
        } else {
            if (this.odiv.style.display == "none") { this.odiv.style.display = ""; }
            this.bHidden = false;
        }
        switch (st) {
            case "hidden":
                if (this.winStatus != "") {
                    this.odiv.innerHTML = "";
                    this.winStatus = "";
                }
                break;
            case "show":
                if (this.winStatus != "show") {
                    this.show();
                } else {
                    this.swch();
                }
                break;
            case "open":
                this.open();
                break;
            default:
                if (this.winStatus != "preview") {
                    this.min();
                }
                break;
        }
        this.ChatRoomStatus = st;
        if (typeof (expday) != 'undefined') {
            var d;
            if (expday == 0) {
                d = null;
            } else {
                d = new Date();
                d.setTime(d.getTime() + (expday * 24 * 60 * 60 * 1000));
            }
            this.setCookie("ChatRoomStatus", st, d, '/');
        }
    };
    //获得当前聊天面板的显示状态
    this.getStatus = function() {
        return this.ChatRoomStatus;
    };
    // 开始显示的位置的变化
    this.makeStatic = function() {
       
        if (!this.odiv) return false;
        if (!this.bstatic) return false;
        var tb = (document.compatMode != "BackCompat") ? document.documentElement : document.body;
        //alert("makeStatic");
        //alert("536: tb:  " + tb);
        if (this.tbheight != tb.clientHeight) {
            this.tbheight = tb.clientHeight;
            if (!this.bminiMode && this.height.search("%") != -1 && this.winStatus == "show") {
                this.odiv.style.height = Math.floor(this.tbheight * Number(this.height.replace("%", "")) / 100) + "px";
            }
            if (this.tbheight < this.odiv.clientHeight)
                this.odiv.style.height = Math.floor(this.tbheight * .8) + "px";
        }

        if (this.tbwidth != tb.clientWidth) {
            this.tbwidth = tb.clientWidth;
            switch (this.winStatus) {
                case "show":
                    if (!this.bminiMode && this.width.search("%") != -1)
                        this.odiv.style.width = Math.floor(this.tbwidth * Number(this.width.replace("%", "")) / 100) + "px";
                    break;
                case "preview":
                    if (this.previewMode == "bar")
                        this.odiv.style.width = this.tbwidth + "px";
                    break;
                default:
                    break;
            }
            if (this.tbwidth < this.odiv.clientWidth)
                this.odiv.style.width = Math.floor(this.tbwidth * .8) + "px";
        }

        var staticYOffset = tb.clientHeight;
        var YOffset = this.odiv.clientHeight;
        var winY = document.all ? tb.scrollTop : window.pageYOffset;
        var newtop = (winY + staticYOffset - YOffset - this.Ypos);
        newtop = (newtop < winY ? winY : newtop) + "px";
        if (this.top != newtop) {
            this.odiv.style.top = newtop;
            this.top = newtop;
        }
        var staticXOffset = tb.clientWidth;
        var XOffset = this.odiv.clientWidth;
        var winX = document.all ? tb.scrollLeft : window.pageXOffset;
        var newleft = (winX + staticXOffset - XOffset - this.Xpos)
        newleft = (newleft < winX ? winX : newleft) + "px";
        if (this.left != newleft) {
            this.odiv.style.left = newleft;
            this.left = newleft;
        }
        this.staticTimer = setTimeout(this.objName + '.makeStatic()', this.staticTime);
    };

    // 获得鼠标移动的位置。来修改显示面板的位置
    this.moveTo = function(left, top) {
       
        var tb = (document.compatMode != "BackCompat") ? document.documentElement : document.body;
        this.Ypos = tb.clientHeight - this.odiv.clientHeight - top;
        this.Xpos = tb.clientWidth - this.odiv.clientWidth - left;
        if (this.staticTimer)
            clearTimeout(this.staticTimer);
        this.makeStatic();
    };

    //全窗体显示  打开当前的页面
    this.full = function() {
        location.href = this.roomURL;
    };

   
    //鼠标移动到窗体上，获得当前鼠标的位置 。拖动聊天窗体。改变位置
    this.drag = function(o, did) {
        if (!this.canDrag)
            return;
        odiv = this.odiv;
        //		o.firstChild.onmousedown=function(){return false;};
        o.onmousedown = function(a) {  // 调用当前div 鼠标上浮的事件
            var d = document;
            if (!a) a = window.event;
            var x = a.layerX ? a.layerX : a.offsetX, y = a.layerY ? a.layerY : a.offsetY;
            if (o.setCapture)
                o.setCapture();
            else if (window.captureEvents)
                window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
            o.style.cursor = 'move';
            document.onmousemove = o.onmouseout = o.onmouseleave = function(a) {
                if (!a) a = window.event;
                var tx = (a.pageX ? a.pageX - window.pageXOffset : a.clientX) - x
                var ty = (a.pageY ? a.pageY - window.pageYOffset : a.clientY) - y;
                var tb = (document.compatMode != "BackCompat") ? document.documentElement : document.body;
                var twx = tb.clientWidth - odiv.clientWidth - 2;
                var twy = tb.clientHeight - odiv.clientHeight - 2;
                if (!document.all) {
                    twx -= 16;
                    twy -= 16;
               } 
                tx = twx < tx ? twx : tx;
                tx = tx < 0 ? 0 : tx;
                ty = twy < ty ? twy : ty;
                ty = ty < 0 ? 0 : ty;
                __oWC.moveTo(tx, ty);
            };

            document.onmouseup = function() {
                if (o.releaseCapture)
                    o.releaseCapture();
                else if (window.captureEvents)
                    window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
                document.onmousemove = o.onmouseout = o.onmouseleave = null;
                document.onmouseup = null;
            };
        };
    };

   // 设置当前的 Cookie
    this.setCookie = function(name, value, expires, path, domain, secure) {
        alert("648: etCoolie: " + name + " "+ value +" " + path );
        document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
    };


    //获得当前的cookie   客户端操作cookie
    this.getCookie = function(name) {
        var dc = document.cookie;   //客户端操作cookie
        var prefix = name + "=";
        var begin = dc.indexOf("; " + prefix);
        if (begin == -1) {
            begin = dc.indexOf(prefix);
            if (begin != 0) return null;
        }
        else {
            begin += 2;
        }
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) {
            end = dc.length;
        }
        return unescape(dc.substring(begin + prefix.length, end)); //获得当前cookie
    };

    this.deleteCookie = function(name, path, domain) {
        if (this.getCookie(name)) {
            document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
    };

    //用户退出
    this.user_loginOut = function() {
        var xmlhttp = this.createRequest();
        // alert(xmlhttp);
        xmlhttp.open("GET", this.staticURL+"/handler/ClientChatHandler.ashx?op=C_Colse", true);
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                   // alert("OK "+ xmlhttp.responseText);
                } else {
                   //alert("webChat800:错误： " + xmlhttp.responseText);
                }
            }
        };
       
        xmlhttp.send(null);
    }


    this.createRequest = function() {   //创建异步访问对象
        /* Create a new XMLHttpRequest object to talk to the Web server */

        var xmlHttp = false;
        /*@cc_on@*/
        if (@_jscript_version >= 5)
            try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e2) {
                xmlHttp = false;
            }
        }
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
            xmlHttp = new XMLHttpRequest();
        }
        return xmlHttp;
    }

    this.changeWindowSize = function($, divclass) {
        // var divclass = $("#divChat").attr("class");
        // alert(_parent.clientWidth);
        // alert(divclass);
        if (divclass != "big") {
            //$("#divChat").attr("class", "big");
            var t_divclass = $("#divChat").attr("class");
            var t_index = 2;
            if (t_divclass == "big") {
                t_index = 3;
            }
            $("#divChat").removeClass();
            $("#divChat").addClass("big");
            $("#divChat div").each(function(i, obj) {
                // alert("i: " + i);
                // alert("class: "+ $(obj).attr("class"));
                var objClass = $(obj).attr("class");
                if (objClass != "") {
                    //alert(objClass.substr(3));
                    var newClass = "big" + objClass.substr(t_index);
                    // alert(newClass);
                    $(obj).removeClass();
                    $(obj).addClass(newClass);
                }
            });
            $("#msg").removeClass();
            $("#msg").addClass("big_textarea");
            $("#validateCode").removeClass();
            $("#validateCode").addClass("big_phone_left_1_int2");
            $("#txtTel").removeClass();
            $("#txtTel").addClass("big_phone_left_1_int1");
        }
        else {
            if (divclass != "sm") {
                var t_divclass = $("#divChat").attr("class");
                var t_index2 = 3;
                if (t_divclass == "sm") {
                    t_index2 = 2;
                }
                //$("#divChat").attr("class", "sm");
                $("#divChat").removeClass();
                $("#divChat").addClass("sm");

                $("#divChat div").each(function(i, obj) {
                    // alert("i: " + i);
                    // alert("class: "+ $(obj).attr("class"));
                    var objClass = $(obj).attr("class");
                    if (objClass != "") {
                        //alert(objClass.substr(3));
                        var newClass = "sm" + objClass.substr(t_index2);
                        // alert(newClass);
                        $(obj).removeClass();
                        $(obj).addClass(newClass);

                    }
                });
                $("#msg").removeClass();
                $("#msg").addClass("sm_textarea");
                $("#validateCode").removeClass();
                $("#validateCode").addClass("sm_phone_left_1_int2");
                $("#txtTel").removeClass();
                $("#txtTel").addClass("sm_phone_left_1_int1");
            }
        }
    }
    
}

    var __oWC = new WebChat("__oWC");

    __oWC.init();

