﻿var im_global = new Object();
var im_serverinfo_global = 
     {userstatus:"http://124.225.65.241/flashIM/wdkstatus",
	    av:"rtmp://124.225.65.244:80/media", 
	    historymsg:"http://history.xiaoneng.tianya.cn/historymessage/index.jsp"
	   };
var im_serverinfo =[
  {presence:"124.225.65.245:80",
   chat:"124.225.65.242:80"},
   {presence:"124.225.65.246:80",
   chat:"124.225.65.242:80"},
   {presence:"124.225.65.247:80",
   chat:"124.225.65.242:80"}
];
im_global.version = {
    presence_flash : "2.4.2",
    buddylist_flash: "2.4.2",
    webchat_flash  : "2.4.2"
};
im_global.win = {//聊窗
    fontsize : '12px',
    fontcolor: '#000000',
    tbfontcolor:'#000000',
    fonttext: ''
};
im_global.variable = {
    siteid: null,
    user_id  : null,
    user_name: null,
    user_sid : null,
    userparam: null,
    webchatURL: "",
    onlineuserURL: "",
    scriptPath: "",
    serverPath: "",
    setingItems: [
        {title:"接收所有人消息",name:"autoacceptmessage",type:"radio",value:1},
        {title:"只接受好友消息",name:"autoacceptmessage",type:"radio",value:2},
        {title:"-"},
        {title:"好友上线提示",  name:"buddyonlinenotify",type:"checkbox",value:true},
        {title:"系统声音提示",  name:"notifysound",type:"checkbox",value:true}]
};
        //{title:"拒绝所有人消息",name:"autoacceptmessage",type:"radio",value:3},
im_global.temp = {//临时
    menuTimer: -1,
    searchTYnum:0,
    at: null,
    uid_display:"",
    divY:null,
    flashServers:null,
    userStatusServer:null,
    presenceFlashGoUrl:null,
    buddylistFlashGoUrl:null,
    presenceFlash:null,
    la: new Array(),
    ow: new Object(),
    notify_id: 0,
    userSpanArray: null,
    bHaveSetFlashServers:false,
    resetwintop: new Array(),
    imSid:null,
    logo:null,
    imchatDOM:null
};
im_global.cfg = {//配置
    not_showfloat_sites: new Array("haiguinet","cnmyspace"),
    notShowFloat:   false,
    customtoolbarButtons:[],//自定义工具条按钮
    bgColor:    "#DFDFDF",
    broderColor:"#92918D",
    toolbarOverColor:  "#CDD3E9",
    chatWidth: 514,
    chatHeight:534,
    IMWidth:304,
    IMHeight:(window.screen.height<960 ? 534 : 654),
    General: false,
    customparams:   [],
    cookieTimeout: 1800, //30分钟    
    DebugType: 0,                                          /*0:关闭|1:log4javascript|2:dzy*/
    init: function(){
        this.customparams["cache_serverinfo"] = true;     /**/
        this.customparams["getserverurl"]     = null;     //"http://download.xiaoneng.tianya.cn/chat/2.0/func/getflashserver.php";
        /*-----------------以下参数可在客户端调用---------------*/
        this.customparams["enblebuddyentry"]  = 1;         /*0:关闭|1:开启|2:开启不显示浮动Logo,无固定SPAN时不显示Logo)*/
        this.customparams["floatpos"]         = "right";
        this.customparams["entrytype"]        = "logo";
        this.customparams["layout"]           = "cascade"; /*cascade:层叠|free :自由(toolbar专属参数)*/
        this.customparams["intact"]           = false;     /*true   :完整|false:精简(toolbar专属参数)*/
        this.customparams["webchat_inpage"]   = true;      /*页内|页外打开聊窗*/
        this.customparams["alway_notify"]     = false;     /*alway_notify*/
        this.customparams["show_popmenu"]     = true;      /**/
        this.customparams["show_tooltip"]     = true;      /**/
        this.customparams["hiddenmode"]       = false;     /**/
    }
};
im_global.cache = {
    source: "",
    _images:  ["logo_mini","im_logo","notify_userhead","online","offline","tools_min","tools_min_over","tools_min_click"],
    img:[],
    init:function(){
        if(this.source.length <= 0) alert("缓存图片失败");
        
        for(var i=0; i<this._images.length;i++){
            var image = new Image();
            image.src = this.source + this._images[i] + ".gif";
            this.img[this._images[i]] = image;
        }
        this.img["im_logo"].width = 20;
    }
};
im_global.cfg.init();

var im_wdkUtil = null;
var im_toolbar = null;
var im_TianyaToolbar = null;
var im_toolBar_Menu = null;
var im_notify_manager = null;
var im_chat_window_manager = null;
var wdkApplication = null;
var im_myIMWindow = null;
var im_notshow_ad = false;
//var im_webchat_url = "http://wdknet.vicp.net/wdkchat/func/imwebchat.php";
//var im_buddylist_url = "http://wdknet.vicp.net/wdkchat/func/getflashserver.php";
var im_logger = null;
var enableDebug = 0;

/*---------config end ---------*/

var im_uAgent = navigator.userAgent.toLowerCase();
im_browser = function(){
    this.version=(im_uAgent.match( /.+(?:firefox|rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1];
    this.safari= /webkit/.test( im_uAgent );
    this.opera= /opera/.test( im_uAgent );
    this.msie= /msie/.test( im_uAgent ) && !/opera/.test( im_uAgent );
    this.msie56= parseFloat(im_uAgent.substring(im_uAgent.indexOf("msie") + 5)) >= 5.5 && parseFloat(im_uAgent.substring(im_uAgent.indexOf("msie") + 5))<7;
    this.mozilla= /mozilla/.test( im_uAgent ) && !/(compatible|webkit)/.test( im_uAgent );
    this.firefox=/firefox/.test(im_uAgent);
    this.firefox2=/firefox/.test(im_uAgent) && this.version.indexOf("2.") > -1;
    this.chrome=/chrome/.test(im_uAgent);
    this.boxModel= !(/msie/.test( im_uAgent ) && !/opera/.test( im_uAgent )) || document.compatMode == "CSS1Compat";//?
    this.oldModel = /msie/.test( im_uAgent ) && !/opera/.test( im_uAgent ) && document.compatMode=="BackCompat";
    this.scroll = null;
};
/*-----class WdkUtil start-----*/
WdkUtil = function(){
    this.Browser = new im_browser();
    this.Domain  = location.hostname;
    this.Path    = "/";
}
_p = WdkUtil.prototype;
_p.setDomain = function(domain){
    if(domain){
        var _ed     = domain.indexOf("/");
        var _len    = domain.length;
        if(_ed>=0){
            this.Domain = domain.substr(0, _ed);
            this.Path   = domain.substr(_ed, _len);
        }else{
            this.Domain = domain.substr(0, _len);
        }
    }
}
_p.GetCookieVal = function(offset){
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
_p.SetCookie = function(name, value){
    var expdate = new Date();
    var argv = arguments;
    var argc = arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5]  : false;
    if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
    document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
    +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
    +((secure == true) ? "; secure" : "");
}
_p.GetCookie = function(name){
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen)
  {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return this.GetCookieVal(j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}
_p.DelCookie = function(name){
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var domain = this.Domain ? this.Domain : "";
  var path = this.Path ? this.Path : "";
  var cval = this.GetCookie (name);
  document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString() +
    "; path=" + path + "; domain=" + domain;
}
_p.isFunction = function( fn ) {
    return !!fn && typeof fn != "string" && !fn.nodeName && 
        fn.constructor != Array && /function/i.test( fn + "" );
}
_p.isArray = function( o ){
    return Object.prototype.toString.apply(o) === '[object Array]';
}

_p.Event = {
    listEvents: [],
    addEvent: function( obj, type, fn ) {
        if (obj.addEventListener) {
            obj.addEventListener( type, fn, false );
            this.listEvents.push(arguments);
        }
        else{
            obj.attachEvent( "on"+type, fn);
            this.listEvents.push(arguments);
        }
    },
    removeEvent: function( obj, type, fn ){
        if( obj.removeEventListener ){
            obj.removeEventListener(type, fn, false);
        }
        else{
            obj.detachEvent("on"+type, fn) ;
        }
    },
    flush : function(){
        var i, item;
        for(i = this.listEvents.length - 1; i >= 0; i = i - 1){
            item = this.listEvents[i];
            if(item[0].removeEventListener){
                item[0].removeEventListener(item[1], item[2], item[3]);
            };
            if(item[1].substring(0, 2) != "on"){
                item[1] = "on" + item[1];
            };
            if(item[0].detachEvent){
                item[0].detachEvent(item[1], item[2]);
            };
            item[0][item[1]] = null;
        };
    }
};
_p.$ = function(el){
    return(document.getElementById ? document.getElementById(el)
            : document.all ? document.all[el]
            : null);
};
_p.doc = document.documentElement ? document.documentElement : (document.body ? document.body : null);
_p.scroll = function(){
    var wh = this.viewRect.get(window, true).h;
    if( (this.Browser.msie||this.Browser.opera)&&this.doc.scrollHeight>wh)
        return true
    else if ( !(this.Browser.msie||this.Browser.opera) && this.doc.offsetHeight>wh )
        return true;
    else
        return false;
}
_p.JSONtoArray = function(json){
    if(!json) return;
    var arrOut = [];for(var k in json){arrOut[k] = json[k];}return arrOut;
}
_p.StringToArray = function(string){//JSON类型字符
    if(string=="" || string.indexOf("{")!=0 || string.indexOf("}")!=string.length-1) return;
    var arrOut = [];var _temp = string.substr(string.indexOf("{")+1, string.indexOf("}")-1);var _arr  = _temp.split(",");for(var i=0; i<_arr.length; i++){var _t = _arr[i].split(":");arrOut[_t[0]] = _t[1];}return arrOut;
}
_p.viewRect = {
    x:0,
    y:0,
    w:0,
    h:0,
    get: function(el, isupdate){
        el = typeof(el)=='string' ? this.getEl(el) : el;
        if( !el || el==window || el==document ){
            if (!!isupdate || !this.w)
                this._getViewPortRect();/*重新获取窗口参数*/
            return {x:this.x, y:this.y, w:this.w, h:this.h};
        }
        else{
            if( (document.compatMode=="BackCompat" && im_wdkUtil.Browser.msie) ||
                (document.compatMode=="CSS1Compat" && im_wdkUtil.Browser.msie56)
              ){ 
                return {x:this.getX(el), y:this.getY(el),w:this.getW(el), h:this.getH(el)};
            }else{
                this._getViewPortRect();
                var _x = this.getX(el) + this.x;
                var _y = this.getY(el) + this.y;
                return {x:_x, y:_y,w:this.getW(el), h:this.getH(el)};
            }
        }
    },
    _getViewPortRect: function(obj){
        this.x = window.pageXOffset ? window.pageXOffset :
                                    (document.documentElement&&document.documentElement.scrollLeft ? document.documentElement.scrollLeft :
                                    (document.body ? document.body.scrollLeft : 0) );
        
        this.y = window.pageYOffset ? window.pageYOffset :
                                    (document.documentElement&&document.documentElement.scrollTop ? document.documentElement.scrollTop :
                                    (document.body ? document.body.scrollTop : 0) );
        
        this.w = window.innerWidth ? window.innerWidth :
                                    (document.documentElement&&document.documentElement.clientWidth ? document.documentElement.clientWidth :
                                    (document.body ? document.body.clientWidth : 0) );
            
        this.h = window.innerHeight ? window.innerHeight :
                                    (document.documentElement&&document.documentElement.clientHeight ? document.documentElement.clientHeight :
                                    (document.body ? document.body.clientHeight : 0) );
    },
    getX:function(e){
        elm = typeof(e)=='string' ? this.getEl(e) : e;
        var offset=elm.offsetLeft;
        if(elm.offsetParent!=null) offset+=this.getX(elm.offsetParent);
        return offset;
    },
    getY:function(e){
        elm = typeof(e)=='string' ? this.getEl(e) : e;
        var offset=elm.offsetTop;
        if(elm.offsetParent!=null) offset+=this.getY(elm.offsetParent);
        return offset;
    },
    getW:function(el){
        return(el ? (el.offsetWidth || (el.style ? el.style.pixelWidth : 0) || 0) : 0);
    },
    getH:function(el){
        return(el ? (el.offsetHeight || (el.style ? el.style.pixelHeight: 0) || 0) : 0);
    },
    getEl:function(el){
        return(document.getElementById ? document.getElementById(el)
            : document.all ? document.all[el]
            : null);
    }
};
_p.createScript = function(scriptSrc){
    var im_head = document.getElementsByTagName("HEAD")[0];
    var script = window.document.createElement("script");
    im_head.appendChild(script);
    script.type     = "text/javascript";
    script.language = "javascript";
    script.src      = scriptSrc;
    script.charset  = "utf-8";
    return true;
};
_p.createCSS = function(cssFile){
    var im_head = document.getElementsByTagName("HEAD")[0];
    var cssLink = document.createElement("link");
    im_head.appendChild(cssLink);
    cssLink.type= 'text/css';
    cssLink.rel = 'stylesheet';
    cssLink.href= cssFile;
}
_p.createDom = function(elDom, toElement){
    toElement = toElement ? toElement
                : (document.getElementsByTagName ? document.getElementsByTagName("body")[0]
                : (document.body || null));
    if(!toElement){return;}
    if(toElement.insertAdjacentHTML && arguments[2]){
        var where = arguments[2] ? arguments[2].toLowerCase() : "afterbegin";
        html  = '<' + elDom.name;
        for(var k in elDom){if(k && k!='name')  html += ' '+(k=="className" ? "class" : k)+'="' + elDom[k] + '"';}
        html  += '></'+elDom.name+'>';
        switch(where){
            case "beforebegin":
                toElement.insertAdjacentHTML('BeforeBegin', html);
                return toElement.previousSibling;
            case "afterbegin":
                toElement.insertAdjacentHTML('AfterBegin', html);
                return toElement.firstChild;
            case "beforeend":
                toElement.insertAdjacentHTML('BeforeEnd', html);
                return toElement.lastChild;
            case "afterend":
                toElement.insertAdjacentHTML('AfterEnd', html);
                return toElement.nextSibling;
            default :
                toElement.insertAdjacentHTML('AfterBegin', html);
                return toElement.firstChild;
        }
    }else if(typeof toElement.innerHTML != "undefined" && document.createElement && toElement.appendChild){
        if(/text/.test(elDom.name.toLowerCase())){
            var _El = document.createTextNode(elDom.text);
        }else{
            var _El = document.createElement(elDom.name);
            for(var k in elDom){
                if(elDom[k] && k!="name"){
                    switch(k){
                        case "className": _El.className = elDom[k];break;
                        case "style": _El.style.cssText = elDom[k];break;
                        default : _El.setAttribute(k, elDom[k]);
                        break;
                    }
                }
            }
        }
        toElement.appendChild(_El);
        return _El;
    }else{
        html  = '<' + elDom.name;
        for(var k in elDom){if(k && k!='name')  html += ' '+(k=="className" ? "class" : k)+'="' + elDom[k] + '"';}
        html  += '></'+elDom.name+'>';
        toElement.innerHTML += html;
        var _childNodes = toElement.getElementsByTagName(elDom.name);
        return _childNodes[(_childNodes.length-1)];
    }
}
_p.insertAfter = function(newElement,targetElement) {  
    var parent = targetElement.parentNode;  
    if (parent.lastChild == targetElement)
        parent.appendChild(newElement);  
    else
        parent.insertBefore(newElement,targetElement.nextSibling);  
}
_p.insertHtml = function(where, el, html){
    where = where.toLowerCase();
    if(el.insertAdjacentHTML){
        switch(where){
            case "beforebegin":
                el.insertAdjacentHTML('BeforeBegin', html);
                return el.previousSibling;
            case "afterbegin":
                el.insertAdjacentHTML('AfterBegin', html);
                return el.firstChild;
            case "beforeend":
                el.insertAdjacentHTML('BeforeEnd', html);
                return el.lastChild;
            case "afterend":
                el.insertAdjacentHTML('AfterEnd', html);
                return el.nextSibling;
        }
    }
    var range = el.ownerDocument.createRange();
    var frag;
    switch(where){
        case "beforebegin":
            range.setStartBefore(el);
            frag = range.createContextualFragment(html);
            el.parentNode.insertBefore(frag, el);
            return el.previousSibling;
        case "afterbegin":
            if(el.firstChild){
                range.setStartBefore(el.firstChild);
                frag = range.createContextualFragment(html);
                el.insertBefore(frag, el.firstChild);
                return el.firstChild;
            }else{
                el.innerHTML = html;
                return el.firstChild;
            }
        case "beforeend":
            if(el.lastChild){
                range.setStartAfter(el.lastChild);
                frag = range.createContextualFragment(html);
                el.appendChild(frag);
                return el.lastChild;
            }else{
                el.innerHTML = html;
                return el.lastChild;
            }
        case "afterend":
            range.setStartAfter(el);
            frag = range.createContextualFragment(html);
            el.parentNode.insertBefore(frag, el.nextSibling);
            return el.nextSibling;
        }
}
_p.removeChildNodes = function(el, childNodetagName){
    if(!el) return;
    var Nodes = childNodetagName ? el.getElementsByTagName(childNodetagName) : el.childNodes;
    for(var i=0; i<Nodes.length;i++){
        var a = Nodes[i].attributes;
        for(var id in a){
            if(typeof(a[id])=="function"){
                if(im_wdkUtil.Browser.msie)
                    eval("el."+id+"=null");
                else
                    el.removeAttribute(id);
            }
        }
        this.removeChildNodes(Nodes[i], childNodetagName);
        el.removeChild(Nodes[i]);
    }
}
_p.cutText = function(str, len){
    var l = len*2; var t = 0, tl = 0, ol = 0;
    for(var i=0;i<l;i++){
        if(str.charCodeAt(i)>255) t += 2;
        else tl += 1;
        ol += 1;
        if(t + tl == l){return (str.substring(0,ol));break;}
        if(t + tl > l){return (str.substring(0,ol - 1) + " "); break;}
    }
}
_p.lenText = function(str){
    var t = 0;
    for(var i=0;i<str.length;i++){
        if(str.charCodeAt(i)>255) t += 2;
        else t += 1;
    }
    return t;
}
_p.disposeFlashObj = function(flashObj){
    //flash 暴露js 的所有方法清除
    if(!flashObj)
      return;
    for(var id in flashObj){
        if(typeof(flashObj[id]) == "function"){
            if(im_wdkUtil.Browser.msie)
                eval("flashObj."+id+"=null");//清除DOM对象上面绑定的脚本对
            else
                flashObj.removeAttribute(id);
        }
    }
};
_p.onlyOne = function(key, dtyp, timer){
    if(im_wdkUtil.GetCookie(key)===key){return false;
    }else{
        var d = new Date();var od = new Date();
        switch(dtyp){
            case "d": d.setDate(d.getDate() + timer);d.setHours(0);d.setMinutes(0);d.setSeconds(0);break;
            case "h": d.setHours(d.getHours() + timer);d.setMinutes(0);d.setSeconds(0);break;
            case "m": d.setMinutes(d.getMinutes() + timer);d.setSeconds(0);break;
            case "s": d.setSeconds(d.getSeconds() + timer);break;
            default : im_wdkUtil.SetCookie(key, key); return;
        }
        var t = (d.getTime() - od.getTime())/1000;
        im_wdkUtil.SetCookie(key, key, t);
        return true;
    }
};
/*---class WdkUtil end---*/
im_initim();

/*------interface-------*/
function im_tianyaInit(){
	/*ol=document.getElementsByTagName("script")
	oJs=ol[ol.length-1]
	var entryTypeAttr = oJs.getAttribute('entrytype')");
	if(entryTypeAttr && entryTypeAttr.length>0){
	}*/
	
	var uid = null;
	var uname = null;
	var sid = null;
    Request = {
        QueryString : function(item){
            var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
            return svalue ? svalue[1] : svalue;
        }
    }
    /*if(__global.isOnline() || true){
        uid = Request.QueryString("uid") ? Request.QueryString("uid") : "1000";
        uname = Request.QueryString("uname")?Request.QueryString("uname") : "u1000";
        sid = "67536546"
    }*/
  if(__global.isOnline()){
    uid = __global.getUserId();
	  uname = __global.getUserName();
	  sid = __global.getKey();
  }
	if ((uid==null)||(uid=="")||isNaN(uid))
		uid=0;
	if ((sid==null)||(sid=="")||isNaN(sid))
		sid=0;
    var BuddyListDOM = im_wdkUtil.$("imBuddyItem");
    if(BuddyListDOM)
	    im_connetIMStatus(uid, "tianya", uname, uname, sid, "", "", {entrytype:"tianyatoolbar"});
    else{
    	  im_global.cfg.customparams["enblebuddyentry"] = 0;
        im_connetIMStatus(uid, "tianya", uname, uname, sid, "", "");
    }
        
}
function im_connetIMStatus(userparam, siteid, userid, username, sessionid, flashserver, webchatpageurl, Params){
   im_getIMOnlineStatus(siteid);
   if(typeof(userid)!="undefined" && userid && userid.length>0)
     im_runPresence(userparam, siteid, userid, username, sessionid, flashserver, webchatpageurl, Params);
}

function im_getIMOnlineStatus(siteid, webchaturl, onlineuserurl){
    var _siteid = siteid;
	im_global.variable.siteid = siteid;
    im_global.variable.webchatURL = webchaturl;
    im_global.variable.onlineuserURL = onlineuserurl;
    
    if(_siteid=="tianya" || _siteid=="tianya2.5" ||_siteid=="tianya_super" || _siteid=="tianya_test" || _siteid=="dzytest" || _siteid=="discuz60utf8dzy"){
        im_global.cache.source += "tianya/";
        im_global.cache.init();
        im_global.cfg.chatWidth        = 514;
        im_global.cfg.chatHeight       = 534;
        im_global.cfg.IMWidth          = 304;
        im_global.cfg.IMHeight         = window.screen.height<960 ? 534 : 654;
        im_global.win.fonttext         = "天涯聊聊";
        im_global.win.fontcolor        = "#FFFFFF";
        im_global.win.tbfontcolor      = "#004499";
    }
    else{
        im_global.cache.source += "ntalker/";
        im_global.cache.init();
        im_global.cache.img["im_logo"].width = 53;
        im_global.cfg.toolbarOverColor = "#C3F0FF";
        im_global.cfg.bgColor          = "#E8FbFF";
        im_global.cfg.broderColor      = "#3374C4";
        im_global.cfg.chatWidth        = 514;
        im_global.cfg.chatHeight       = 534;
        im_global.cfg.IMWidth          = 304;
        im_global.cfg.IMHeight         = 534;
        im_global.win.fonttext         = "社区聊天软件";
        im_global.win.fontcolor        = "#FFFFFF";
        im_global.win.tbfontcolor      = "#3374C4";
        im_global.cfg.General          = true;
    }
    createGestFlashConnet(siteid, 0);
    
    var userStatusServer = null;
    /*
    /脚本中保存服务器分配信息
    if(typeof(im_serverinfo)!='undefined' && im_serverinfo){
    	 im_onGetFlashServer("http://"+im_serverinfo[0].userstatus+"/flashIM/wdkstatus", 3, true);
    }
    else{//从服务器端获取服务器分配信息
      if(im_global.cfg.customparams["cache_serverinfo"])
          userStatusServer = im_wdkUtil.GetCookie("userstatusserver");
      if(!userStatusServer){
          var getServerUrl = im_global.cfg.customparams["getserverurl"]?im_global.cfg.customparams["getserverurl"]:(im_global.variable.scriptPath+"/func/getflashserver.php");
          im_wdkUtil.createScript(getServerUrl+"?siteid="+siteid+"&resulttype=2&rand="+Math.random());
      }
      else{
          im_onGetFlashServer(userStatusServer, '2', true);
      }
    }*/
}

function im_runPresence(userparam, siteid, userid, username, sessionid, flashserver, webchatpageurl, Params) {
	  if(typeof(userparam)=='undefined' || !userparam || userparam.length==0){
	     userparam = username;
	  }
    if(siteid=="csdn" || siteid=="csdn_test")im_global.cfg.customtoolbarButtons[1].url += username;
    im_global.variable.userparam = userparam;
    im_global.variable.siteid = siteid;
    im_global.variable.user_id = userid;
    im_global.variable.user_name = username;
    im_global.variable.user_sid = sessionid;
    //flashserver
    im_global.variable.webchatURL = webchatpageurl;
    
    if(Params && typeof Params =="object"){
        for(var k in Params){
            if(typeof(im_global.cfg.customparams[k]) != "undefined"){
                im_global.cfg.customparams[k] = Params[k];
            }
        }
    }else if(Params && typeof Params == "string"){//string
        var aParam = Params.split(";")
        for(var i in aParam){
            if(aParam[i] && aParam[i].indexOf(":")){
                var a = aParam[i].split(":");
                k = a[0];v = a[1];
                if(typeof(im_global.cfg.customparams[k]) != "undefined")
                    im_global.cfg.customparams[k] = v=="false" ? false : v=="true"  ? true : v;
            }
        }
    }
    im_global.cfg.customparams["layout"] =  im_global.cfg.customparams["entrytype"]=="toolbar" ? "toolbar" : 
                                            (im_global.cfg.customparams["entrytype"]=="tianyatoolbar" ? "tianyatoolbar" : im_global.cfg.customparams["layout"]);
    
    im_changeFlashConnet();
    try{//动态装载imchat_utf8.js
        if(im_global.cfg.DebugType==1){
            im_wdkUtil.createScript(im_global.variable.scriptPath+"/log4javascript/log4javascript.js");
        }
        
        var BuddyListDOM = im_wdkUtil.$("imBuddyItem");
        if(BuddyListDOM){
            if(!userid){
                BuddyListDOM.onclick = function(){alert("您还未登录，不能与他聊天");}
            }else{
                BuddyListDOM.onclick = function(){im_tbOpenBuddylist("imBuddyItem");}
                im_wdkUtil.createScript(im_global.variable.scriptPath+"/imchat_utf8.js");
            }
        }else{
            im_wdkUtil.createScript(im_global.variable.scriptPath+"/imchat_utf8.js");
        }
    }
    catch(e){}
}
function createGestFlashConnet(siteid, popup){
    if(im_global.temp.createFlash)
        return;
    im_global.temp.createFlash = true;
    if(/1/.test(enableDebug) ) dzy.debug("createGestFlashConnet('"+siteid+"', "+popup+")");
    
    im_global.variable.siteid = siteid;
    //im_wdkUtil.createDom({name:"div", id:"wdk_mini_state",style:"display:none;"});
    document.write('<div id="wdk_mini_state" style="display:none;"></div>');
    var flashvars = "siteid=" + siteid;
    flashvars += "&ispopup=" + (popup ? "1" : "0");
    var flashurl  = im_global.variable.scriptPath+"/impresence.swf";//?rnd="+new Date();
    
    if(im_wdkUtil.Browser.msie){
        var toElement     = document.getElementsByTagName ? document.getElementsByTagName("body")[0] : document.body;
        var flashnodehtml = '<div id="im_presence_div" style=\"position:absolute;z-index:9996; top: -200px;\">'
                          + '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0" '
                          + ' id="impresenceflash" width="1" height="1"> '
                          + '    <param name="movie" value="'+flashurl+'" /> '
                          + '    <param name="allowscriptaccess" value="always" /> '
                          + '    <param name="flashvars" value="'+flashvars+'" /> '
                          + '</object>'
                          + '</div>' ;
        //toElement.insertAdjacentHTML('BeforeEnd', flashnodehtml);
        document.write(flashnodehtml);
    }
    else{
        var divDOM = im_wdkUtil.createDom({name:"div", id:"im_presence_div", style:"position:absolute;z-index:9996; top: -200px;"});
        var flashDOM = document.createElement("embed");
        flashDOM.src               = flashurl;
        flashDOM.id                = "impresenceflash";
        flashDOM.width             = 1;
        flashDOM.height            = 1;
        flashDOM.setAttribute("type",              "application/x-shockwave-flash");
        flashDOM.setAttribute("pluginspage",       "http://www.macromedia.com/go/getflashplayer");
        flashDOM.setAttribute("flashvars",         flashvars);
        flashDOM.setAttribute("allowscriptaccess", "always");
        divDOM.appendChild(flashDOM);
    }
}
function im_changeFlashConnet(){
    if(/1/.test(enableDebug) ) dzy.debug("im_changeFlashConnet(), impresence="+im_wdkUtil.$("impresenceflash"))
    var impresenceflash = im_wdkUtil.$("impresenceflash");
    var _var       = im_global.variable;
    if(!_var.user_id || _var.user_id==0){
        return;
    }
    if(impresenceflash && !im_global.variable.presenceConnet){
        if( impresenceflash.changeFlashConnet){
            impresenceflash.changeFlashConnet(_var.siteid, _var.user_id, _var.user_name, _var.user_sid, _var.userparam);
            im_global.variable.presenceConnet = true;
            if(/1/.test(enableDebug) ) dzy.debug("im_changeFlashConnet, siteid="+_var.siteid+", user_id="+_var.user_id+",user_name="+_var.user_name);
            if(im_wdkUtil.onlyOne("NTALKER_CACHE_FLASH_IM", "d", 1) && false){
                im_wdkUtil.createDom({name:"DIV",id:"FLASH_IM_CACHE",style:"visibility:hidden;"}, null, "AfterBegin");
                swfobject.embedSWF(im_global.variable.scriptPath + "/NtalkerIM.swf", "FLASH_IM_CACHE", 1, 1, "9.0.0", im_global.variable.scriptpath+"/expressInstall.swf", {version: im_global.version.webchat_flash}, {}, {});
            }
        }
    }
}
function fIM_presenceFlashReady(){
    window.setTimeout(function(){
        im_changeFlashConnet();
        StartGetUsersStatus();
    }, 50);
    return true;
}
/*
function setFlashServerToPresence(){return;
    if(!im_global.temp.flashServers)
        return;

    im_global.temp.presenceFlash = document.getElementById("impresenceflash");
    var _presenceFlash = im_global.temp.presenceFlash;
    if(_presenceFlash){
        if(_presenceFlash.setFlashServerInfo){
            _presenceFlash.setFlashServerInfo(im_global.temp.flashServers[0],im_global.temp.flashServers[1],im_global.temp.flashServers[2],im_global.temp.flashServers[3],im_global.temp.flashServers[4],im_global.temp.flashServers[5],im_global.temp.flashServers[6],im_global.temp.flashServers[7],im_global.temp.flashServers[8]);
            im_global.temp.bHaveSetFlashServers = true;       
        }
        if(_presenceFlash.setPageFocus && typeof(promptwindow)!="undefined" && promptwindow.isfocus){
            _presenceFlash.setPageFocus(true);
            if(/1/.test(enableDebug) ) dzy.debug("presenceFlash.setPageFocus(true)", true);
        }
    }
}*/

function im_initim(){
    var scriptobjs = window.document.getElementsByTagName("script");
    var scriptobj = scriptobjs[scriptobjs.length - 1];
    var scriptpath = scriptobj.getAttribute("src");
    if(scriptpath && scriptpath.length>0){
        var pos = scriptpath.lastIndexOf("/");
        if(pos>=0)
            im_global.variable.scriptPath = scriptpath.substring(0,pos);
        else
            im_global.variable.scriptPath = "";

        var pos = scriptpath.indexOf("//");
        if(pos>0){
            var pos2 = scriptpath.indexOf("/", pos+2);
            if(pos2>pos)
                im_global.variable.serverPath = scriptpath.substring(0,pos2);
        }
        else
            im_global.variable.serverPath = "";
    }
    else{
        im_global.variable.scriptPath = "";
        im_global.variable.serverPath = "";
    }
    if(!im_global.cache.source)
        im_global.cache.source = im_global.variable.scriptPath+"/images/";
    im_wdkUtil = new WdkUtil();
    
    //document.write("<div id='im_popMenuid' style='display:none;text-align:left;position:absolute;z-index:10001;'></div>");
    im_wdkUtil.createDom({name:"div", id:"im_popMenuid", style:"left:-100px;top:-100px;display:none;text-align:left;position:absolute;z-index:10001;"}, null, 'AfterBegin');
    im_wdkUtil.createCSS(im_global.cache.source+"/public.css");
}

/*----[im_ToolTip]----*/
var im_ToolTip = {
        FONTCOLOR        : '#000044',
        FONTFACE        : 'Verdana,Geneva,sans-serif',
        FONTSIZE        : '12px',
        FONTWEIGHT        : 'normal',
        TEXTALIGN        : 'left',
        PADDING            : 2,
        tipElements        : ['img','abbr','acronym'],
        IMG:[],
        _elmCss    : [],
        _Obj    : {},
        _Tips    : [],
        _Time    : [],
        _opac    : [],
        _step    : [],
        _iTimerID:[],
        loadImage: function(){
            var asrc = ["tip_bg", "tip_lt", "tip_t", "tip_rt", "tip_r", "tip_rb", "tip_b", "tip_lb", "tip_l", "tip_stemt", "tip_stemb"],
            n = asrc.length,
            aImg = new Array(n),
            img;
            while(n){
                --n;
                img = aImg[n] = new Image();
                img.src = im_global.cache.source + asrc[n] + ".gif";
            }
            this.IMG = aImg;return;
        }
};

/*---- Function ------*/
/*
function im_onGetFlashServer(responseText, type, iscookievalue){
    if(responseText=="-1" || responseText=="-2")
        return;

    if(type=="2"){//获取到userstatus server地址
        im_global.temp.userStatusServer = responseText;
        if(typeof(iscookievalue)=="undefined" || !iscookievalue)//从服务器端返回的数据才写cookie
            im_wdkUtil.SetCookie("userstatusserver", im_global.temp.userStatusServer, im_global.cfg.cookieTimeout);
        StartGetUsersStatus(im_global.temp.userStatusServer);
    }
    else if(type=="1"){//获取到各flashserver地址，可能是从缓存也可能是服务器端
        im_global.temp.presenceFlash =  im_wdkUtil.$("impresenceflash");
        im_global.temp.flashServers = responseText.split(",");
        if(typeof(iscookievalue)=="undefined" || !iscookievalue)//从服务器端返回的数据才写cookie
            im_wdkUtil.SetCookie("flashservers", responseText, im_global.cfg.cookieTimeout);
        //startGetMyIMStatus(im_global.temp.flashServers[8]);
        setFlashServerToPresence();
    }
    else if(type=="3"){//获取到userstatus server地址
    	 StartGetUsersStatus(im_serverinfo_global.userstatus);
    }
    else if(type=="4"){//通过脚本内部获取到各flash server地址
    	 var userhash = 0;
    	 for(var i=0;i<im_global.variable.user_id.length;i++){
    	   userhash += im_global.variable.user_id.charCodeAt(i);    	  
    	 }
    	 var serverIndex = userhash%im_serverinfo.length;
    	 im_global.temp.flashServers = new Array();
    	 im_global.temp.flashServers[0] = "rtmp://"+im_serverinfo[serverIndex].presence+"/flashIM";
    	 im_global.temp.flashServers[1] = "rtmp://"+im_serverinfo[serverIndex].chat+"/freechat";
    	 im_global.temp.flashServers[2] = "http://"+im_serverinfo[serverIndex].presence+"/flashgo";
    	 im_global.temp.flashServers[3] = "http://"+im_serverinfo[serverIndex].chat+"/flashgo";
    	 im_global.temp.flashServers[4] = im_serverinfo_global.userstatus;
    	 im_global.temp.flashServers[5] = "tianya.cn/tianya";
    	 im_global.temp.flashServers[6] = im_serverinfo_global.historymsg;
    	 im_global.temp.flashServers[7] = im_serverinfo_global.av;
    	 im_global.temp.flashServers[8] = "http://"+im_serverinfo[serverIndex].chat+"/flashIM/wdkstatus";
       setFlashServerToPresence();
    }
}*/
function StartGetUsersStatus(userStatusServer){
	  //天涯暂时关闭陌生人聊天功能
	  return;
    if(/1/.test(enableDebug) ) dzy.debug("StartGetUsersStatus();");
    statusSpans = document.getElementsByTagName("SPAN");
    spanindex = 0;

    im_global.temp.userSpanArray = new Array();
    var strUserIDList = "";
    for(i=0; i<statusSpans.length; i++){
        statusSpan = statusSpans[i];
        if(statusSpan.className=="wdk_user_status_span" && statusSpan.id){
            pos = statusSpan.id.indexOf("wdk_user_");
            if(pos>=0){
                var newStatusObj = new Object();
                newStatusObj.destuid = statusSpan.id.substring(pos+"wdk_user_".length, statusSpan.id.length);
                newStatusObj.destnick = statusSpan.title;
                newStatusObj.spanElement = statusSpan;
                im_global.temp.userSpanArray.push(newStatusObj);
                if(im_global.temp.userSpanArray.length>1)
                    strUserIDList += ",";
                strUserIDList += encodeURIComponent(newStatusObj.destuid);
                if(im_global.temp.userSpanArray.length>60)
                    break;
            }
        }
    }

    //天涯专用，解析看帖页面用户链
    var curURL = window.location.href.toLowerCase();
    var isNeedPaser = false;
    if(im_global.temp.userSpanArray.length==0 && (im_global.variable.siteid=="tianya" || im_global.variable.siteid=="tianya2.5")){
        var allowURLList = new Array("/publicforum/content/","/techforum/content/","/tianyacity/content/");
        for(i=0;i<allowURLList.length;i++){
            if(curURL.toLowerCase().indexOf(allowURLList[i].toLowerCase())>=0){
                isNeedPaser = true;
                break;
            }
        }
    }
    if(!isNeedPaser){
        var pattern = /content.*\.asp\?/i;
        if(curURL.match(pattern))
            isNeedPaser = true;
    }
    if(isNeedPaser){
        var lnks = document.links;
        for(var i=0;i<lnks.length;i++){
            match = lnks[i].href.match(/Listwriter\.asp\?(vid=(.*)&)?vwriter=(.*)&?/i);
            if(typeof match != "undefined" && match){
                var chatSpan = window.document.createElement("span");
                chatSpan.className = "wdk_user_status_span";
                chatSpan.id = "wdk_user_"+lnks[i].innerHTML;
                chatSpan.title = lnks[i].innerHTML;
                lnks[i].parentNode.appendChild(chatSpan);
                    
                var newStatusObj = new Object();
                newStatusObj.destuid = lnks[i].innerHTML;
                newStatusObj.destnick = lnks[i].innerHTML;
                newStatusObj.spanElement = chatSpan;
                im_global.temp.userSpanArray.push(newStatusObj);
                if(im_global.temp.userSpanArray.length>1)
                    strUserIDList += ",";
                //strUserIDList += encodeURIComponent(newStatusObj.destuid);
                strUserIDList += newStatusObj.destuid;
                if(im_global.temp.userSpanArray.length>100)
                    break;
            }
        }
    }
    var _presenceFlash = im_wdkUtil.$("impresenceflash");
    im_global.temp.presenceFlash = _presenceFlash;
    if(im_global.temp.userSpanArray.length>0){
        if(_presenceFlash && _presenceFlash.requestUserStatus){
            if(enableDebug==1)dzy.debug("requestUserStatus('"+strUserIDList+"')");
            _presenceFlash.requestUserStatus(strUserIDList, im_global.temp.userSpanArray.length);
        }else{
            if(enableDebug==1)dzy.debug("__StartGetUsersStatus, _presenceFlash="+_presenceFlash+", "+_presenceFlash.requestUserStatus);
        }
    }
}
//状态服务器返回脚本调用，传递用户列表状态值，用户状态值以,分开，每个0值代表离线，1值代表在线
function fIM_onGetUserStatus(responseText){
    if(enableDebug==1) dzy.debug("fIM_onGetUserStatus('"+responseText+"')");
    if(responseText=="-1" || responseText=="-2" || im_global.cfg.customparams["hiddenmode"])
        return;
    userStatusArray = responseText.split(",");

    for(i=0;i<im_global.temp.userSpanArray.length;i++){
        var imgsrc;
        switch(userStatusArray[i]){
        case "0":
            imgsrc = im_global.cache.img["offline"].src;
            break;
        case "1":
            imgsrc = im_global.cache.img["online"].src;
            break;
        }
        alttext="跟我聊天";
        chatLinkStr =  ' <a  href="#" target="_blank" style="display:inline;padding:0px;overflow:visible;" alt="'+alttext+'" onClick="javascript: im_openWebchatWindow(\''+im_global.temp.userSpanArray[i].destuid+'\', \''+im_global.temp.userSpanArray[i].destnick+'\'); return false;" ';
        if(im_global.cfg.customparams["show_popmenu"] && !im_global.cfg.customparams["hiddenmode"])
            chatLinkStr += ' onmouseover="im_popMenu(this,\''+im_global.temp.userSpanArray[i].destuid+'\',\''+im_global.temp.userSpanArray[i].destnick+'\');" onmouseout="im_beginCloseMenu(this);"';
        chatLinkStr += '><img name="wdk_presence_image" style="display:inline;left:0px;top:0px;"';
        if(i==0){
            chatLinkStr += ' tip="点击这里开始聊天';
            if(im_global.cfg.customparams["show_tooltip"] && !im_global.cfg.customparams["hiddenmode"])
                chatLinkStr += ' onload="im_showTip(\'wdk_presence_'+im_global.temp.userSpanArray[i].destuid+'\')"';
        }
        chatLinkStr += " id=\"wdk_presence_"+im_global.temp.userSpanArray[i].destuid+"\" border=\"0\" src=\""+imgsrc+"\" />";
        chatLinkStr += "</a>";
        im_global.temp.userSpanArray[i].spanElement.innerHTML = chatLinkStr;
    }
}

function im_openWebchatWindow(destuid, destname, chatid){
    return im_openWebchat(im_global.variable.user_id, im_global.variable.user_name, im_global.variable.user_sid, im_global.variable.siteid, destuid, destname, chatid, im_global.variable.userparam, !im_global.cfg.customparams["webchat_inpage"], im_global.variable.scriptPath);
}
function im_openBuddyListWindow(){
    if(im_myIMWindow)
        if(im_global.cfg.customparams["entrytype"]=='tianyatoolbar')
	         im_tbOpenBuddylist("imBuddyItem");
	      else      
           im_myIMWindow.showWindow(im_global.cfg.customparams["webchat_inpage"]);
    else{
        //var notifystr = "%u60A8%u5C1A%u672A%u767B%u5F55%uFF0C%u8BF7%u767B%u5F55%u540E%u518D%u4F7F%u7528%u597D%u53CB%u5217%u8868%uFF01";
        //alert(unescape(notifystr));
        MenuUtil.loginIfr("%u8BE5%u529F%u80FD%u9700%u8981%u767B%u5F55%u540E%u4F7F%u7528%uFF01");
    }
}

function im_popMenu(obj, destuid, destnick){
    if(im_global.temp.menuTimer>=0){
        clearTimeout(im_global.temp.menuTimer);
        im_global.temp.menuTimer = -1;
        if(typeof(destuid)=='undefined'||typeof(destnick)=='undefined')
          return;
        //return;
    }
    var menudiv = im_wdkUtil.$('im_popMenuid');
    if(!menudiv || !obj) return;
    var pos = im_wdkUtil.viewRect.get(obj);
    var rect= im_wdkUtil.viewRect.get(window, true);
    var browser = im_wdkUtil.Browser;
    menux = pos.x+pos.w - (browser.msie56 ? 0 : rect.x);
    menuy = pos.y - (browser.msie56 ? 0 : rect.y);

    chatLinkStr = "<a  href=\"#\" target=\"_blank\"  style=\"overflow:visible;font-size:12px;font-weight:100;padding-left:5px;padding-top:5px;overflow:visible;\" onClick=\"javascript: im_openWebchatWindow('"+destuid+"', '"+destnick+"');return false;\">聊天</a>";
    menuStr = "<div>" + chatLinkStr + "</div>";
    buddylistLinkStr = "<a  href=\"#\" target=\"_blank\"  style=\"overflow:visible;font-size:12px;padding:5px;font-weight:100;\" onClick=\"javascript: im_openBuddyListWindow(); return false;\">我的好友</a>";
    addBuddyLinkStr = "<a  href=\"#\" target=\"_blank\"  style=\"overflow:visible;font-size:12px;padding:5px;font-weight:100;\" onClick=\"javascript: im_openAddBuddy('"+destnick+"'); return false;\">加为好友</a>";
    menuStr += "<div>"+addBuddyLinkStr+"</div>";
    menuStr += "<div>"+buddylistLinkStr+"</div>";
    if(im_global.variable.onlineuserURL && im_global.variable.onlineuserURL.length>0){
        onlineLinkStr = "<a  href=\""+im_global.variable.onlineuserURL+"\" target=\"_blank\"  style=\"font-size:12px;font-weight:100;padding-left:5px; overflow:visible;\" >在线会员</a>";
        menuStr += "<div>"+onlineLinkStr+"</div>";
    }

  menuStr += "</div>";
  menudiv.innerHTML = menuStr;
    menudiv.style.display = 'block';
    menudiv.style.left = menux+"px";
    menudiv.style.top  = menuy+"px";
    menudiv.onmouseover = im_popMenu;
    menudiv.onmouseout = im_beginCloseMenu;
}

function im_beginCloseMenu(obj){
    im_global.temp.menuTimer = setTimeout(im_closeMenu, 300);
}

function im_closeMenu(obj){
     var menudiv = im_wdkUtil.$('im_popMenuid');
     menudiv.style.display = 'none';
     im_global.temp.menuTimer = -1;
}
function im_openAddBuddy(destname){
   if(!im_global.variable.user_sid || im_global.variable.user_sid.length<=0){
      MenuUtil.loginIfr("%u8BE5%u529F%u80FD%u9700%u8981%u767B%u5F55%u540E%u4F7F%u7528%uFF01");
      return;
   }
   var addBuddyUrl = "http://my2006.tianya.cn/UserRelation/AllFriends_v2.asp?idWriter="+encodeURIComponent(im_global.variable.userparam)
       +"&Key="+im_global.variable.user_sid+"&gfName="+(destname)+"&sourceType=webim";
   var addBuddyWindow = window.open(addBuddyUrl);
}

Number.prototype.Timer = function(func, iT, bUrge){
    if(!this.value || bUrge)
        this.value = window.setTimeout(func, iT);
}
Number.prototype.EndTimer = function(){
    if(this.value){
        window.clearTimeout(this.value);
        this.value = 0;
    }
}
/*--im_ToolTip--*/
im_ToolTip.loadImage();
function im_hiddenTip(e){
    if(typeof(e)=='string'){evObj = im_wdkUtil.$(e);
    }else {evObj = this;}
    var key = (typeof(e)=='string') ? e : (evObj.id ? 'imiT'+evObj.id : 'imiTToolTip');
    im_tipFade(im_ToolTip._opac[key], key, false);
    clearInterval(im_ToolTip._iTimerID[((typeof(e)=='string') ? e : evObj.id)]);
}
function im_showTip(e){
    if(typeof(e)=='string'){
        evObj = im_wdkUtil.$(e);
        im_createTip(e);
    }else{
        evObj = e;
        im_createTip(evObj.id ? evObj.id : 'ToolTip');
    }
    var key = evObj.id ? evObj.id : 'ToolTip';
    evObj.onload = null;

    if (typeof(e)=='string'){
        im_ToolTip._step[key] = 10;
    }
    im_ToolTip._Time[key][1].Timer("im__showTip('"+key+"')", 100, true);
}
function im__showTip(key){
    var evObj = im_wdkUtil.$(key);
    var LogoRect = im_wdkUtil.viewRect.get(key);
    var winRect = im_wdkUtil.viewRect.get(window, true);
    var Tip_left  = 0;

    try{
      im_ToolTip._Tips[key].innerHTML = im_getTipHTML( evObj.getAttribute('tip'), key);
    }
    catch(e){
    	im_tipFade(10, key, true);
      return;
    }
    var tipRect = im_wdkUtil.viewRect.get(im_ToolTip._Tips[key]);
    var bALlOOnB_obj =  im_wdkUtil.viewRect.get('bALlOOnB_'+key);

    if ( parseInt(LogoRect.x + tipRect.w + 20) > parseInt(winRect.w) ) {
        im_ToolTip._Tips[key].style.top  = (0 - tipRect.h) + "px";
        im_ToolTip._Tips[key].style.left = ( LogoRect.w/2+30 - tipRect.w) + "px";
        im_wdkUtil.$('bALlOOnB_'+key).style.left = "73px";
    } else {
        im_ToolTip._Tips[key].style.top = (LogoRect.y - tipRect.h - winRect.y) + 'px';
        Tip_left = LogoRect.x+LogoRect.w/2-15;
        im_ToolTip._Tips[key].style.left = Tip_left + 'px';
        bALlOOnB_left = document.compatMode=="BackCompat" || bALlOOnB_obj.x<Tip_left || bALlOOnB_obj.x>(Tip_left + tipRect.w ) ?
                        '0px' :
                        (16 - tipRect.w/2) + 'px';
        im_wdkUtil.$('bALlOOnB_'+key).style.left = bALlOOnB_left;
    }
    
    im_ToolTip._Tips[key].style.visibility = 'visible';
    im_ToolTip._Tips[key].style.opacity = '.1';

    im_tipFade(10, key, true);
}
function im_tipFade(opac, key, exeType){
    var passed = parseInt(opac);
    if( exeType == true ){//show
        var newOpac = parseInt(passed+10);
        if ( newOpac <= 80 ) {
            im_ToolTip._Tips[key].style.opacity = '.'+newOpac;
            im_ToolTip._Tips[key].style.filter = "alpha(opacity:"+newOpac+")";
            im_ToolTip._Time[key][1].Timer("im_tipFade('"+newOpac+"', '"+key+"', true)",100, true);
            im_ToolTip._opac[key] = newOpac;
        }
        else {
            im_ToolTip._Time[key][1].EndTimer();
            im_ToolTip._Tips[key].style.opacity = '.80';
            im_ToolTip._Tips[key].style.filter = "alpha(opacity:80)";
            im_ToolTip._Time[key][2].Timer("im_hiddenTip('"+key+"')", 5000, false);
        }
    }else{//hidden
        var newOpac = parseInt(passed-im_ToolTip._step[key]);
        if ( newOpac >=10 ) {
            im_ToolTip._Tips[key].style.opacity = '.'+newOpac;
            im_ToolTip._Tips[key].style.filter = "alpha(opacity:"+newOpac+")";
            im_ToolTip._Time[key][1].Timer("im_tipFade('"+newOpac+"', '"+key+"', false)",50, true);
        }
        else {
            im_ToolTip._Time[key][1].EndTimer();
            im_ToolTip._Time[key][2].EndTimer();
            im_ToolTip._Tips[key].style.visibility = 'hidden';
        }
    }
}
function im_createTip(El){
    if(im_wdkUtil.$("imiT"+El)) return true;
    parentDOM = im_wdkUtil.$(El).parentNode.tagName=="A" ? im_wdkUtil.$(El).parentNode.parentNode : im_wdkUtil.$(El).parentNode;
    var Elm               = null;
    try{
        Elm               = im_wdkUtil.createDom({name:"DIV",id:"imiT"+El,style:"visibility:hidden;position:absolute;z-index:999;top:-100px;left:-500px;width:120px;min-width:100px;"}, parentDOM);
    }catch(e){
        Elm               = document.createElement("DIV");
        Elm.id            = "imiT" + El;
        Elm.style.cssText = "visibility:hidden;position:absolute;z-index:999;top:-100px;left:-500px;width:120px;min-width:100px;";
        parentDOM.appendChild(Elm);
    }
    if(Elm){
        im_ToolTip._Tips[El] = Elm;
        im_ToolTip._Time[El] = [new Number(),new Number(),new Number()];
        im_ToolTip._step[El] = 30;
        return true;
    }
    return false;
}
function im_getTipHTML(strTip,tipID){
    sCssCrn = ' style="width:6px;padding:0px;margin:0px;overflow:hidden;line-height:0px;border:0px;';
    sVaT = 'vertical-align:top;" valign="top"';
    sVaB = 'vertical-align:bottom;" valign="bottom"';
    sCssImg = 'padding:0px;margin:0px;border:0px;';
    sImgZ = '" style="' + sCssImg + '" />';

    tt_sContent = '<table border="0" cellpadding="0" cellspacing="0" style="border:0px;width:auto;padding:0px;margin:0px;left:0px;top:0px;"><tr style="border:0px;">'
                // Left-top corner
                + '<td' + sCssCrn + sVaB + '>'
                + '<img src="' + im_ToolTip.IMG[1].src + '" width="6" height="6' + sImgZ
                + '</td>'
                // Top border
                + '<td valign="bottom" style="position:relative;padding:0px;margin:0px;overflow:hidden;border:0px;">'
                + '<img id="bALlOOnT_'+tipID+'" style="position:relative;top:1px;z-index:1;display:none;' + sCssImg + '" src="' + im_ToolTip.IMG[9].src + '" width="15" height="19" />'
                + '<div style="position:relative;z-index:0;padding:0px;margin:0px;overflow:hidden;width:auto;height:6px;background-image:url(' + im_ToolTip.IMG[2].src + ');">'
                + '</div>'
                + '</td>'
                // Right-top corner
                + '<td' + sCssCrn + sVaB + '>'
                + '<img src="' + im_ToolTip.IMG[3].src + '" width="6" height="6' + sImgZ
                + '</td>'
                + '</tr><tr style="border:0px;">'
                // Left border
                + '<td style="border:0px;position:relative;padding:0px;margin:0px;width:6px;overflow:hidden;background-image:url(' + im_ToolTip.IMG[8].src + ');">'
                // Redundant image for bugous old Geckos that won't auto-expand TD height to 100%
                + '<img width="6" height="100%" src="' + im_ToolTip.IMG[8].src + sImgZ
                + '</td>'
                // Content
                + '<td id="bALlO0nBdY" style="position:relative;line-height:normal;border:0px;'
                + ';background-image:url(' + im_ToolTip.IMG[0].src + ')'
                + ';color:' + im_ToolTip.FONTCOLOR
                + ';font-family:' + im_ToolTip.FONTFACE
                + ';font-size:' + im_ToolTip.FONTSIZE
                + ';font-weight:' + im_ToolTip.FONTWEIGHT
                + ';text-align:' + im_ToolTip.TEXTALIGN
                + ';padding:' + im_ToolTip.PADDING + 'px'
                + ';width:auto'
                + ';">' + strTip + '</td>'
                // Right border
                + '<td style="border:0px;position:relative;padding:0px;margin:0px;width:6px;overflow:hidden;background-image:url(' + im_ToolTip.IMG[4].src + ');">'
                // Image redundancy for bugous old Geckos that won't auto-expand TD height to 100%
                + '<img width="6" height="100%" src="' + im_ToolTip.IMG[4].src + sImgZ
                + '</td>'
                + '</tr><tr style="border:0px;">'
                // Left-bottom corner
                + '<td' + sCssCrn + sVaT + '>'
                + '<img src="' + im_ToolTip.IMG[7].src + '" width="6" height="6' + sImgZ
                + '</td>'
                // Bottom border
                + '<td valign="top" style="position:relative;padding:0px;margin:0px;overflow:hidden;text-align:left;border:0px;">'
                + '<div style="position:relative;left:0px;top:0px;padding:0px;margin:0px;overflow:hidden;width:auto;height:6px;background-image:url(' + im_ToolTip.IMG[6].src + ');"></div>'
                + '<img id="bALlOOnB_'+tipID+'" style="position:relative;top:-1px;z-index:1;display:inline;' + sCssImg + '" src="' + im_ToolTip.IMG[10].src + '" width="15" height="19" />'
                + '</td>'
                // Right-bottom corner
                + '<td' + sCssCrn + sVaT + '>'
                + '<img src="' + im_ToolTip.IMG[5].src + '" width="6" height="6' + sImgZ
                + '</td>'
                + '</tr></table>';
    try{
        return tt_sContent;
    }finally{
        tt_sContent = null;
    }
}

var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);try{ae.parentNode.insertBefore(Y,ae);}catch(e){}ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");try{ Y.parentNode.insertBefore(X,Y);}catch(e){} X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;if(/7/.test(enableDebug)) dzy.debug(X);if(/7/.test(enableDebug)) dzy.debug("y0="+Y[0]+", y1="+Y[1]+", y2="+Y[2]);if(/7/.test(enableDebug)) dzy.debug("Z="+Z+", x0="+X[0]+", x1="+X[1]+", x2="+X[2]);return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();
var im_flashVersion = swfobject.getFlashPlayerVersion().major;
var im_installFlashActionX = im_flashVersion<9 ? true : false;

function im_initChatList(chatListBtn){
    if(typeof(chatListBtn)=="string")
        chatListBtn = im_wdkUtil.$(chatListBtn);
    else
        chatListBtn = chatListBtn[0];
    im_global.temp.imchatDOM = chatListBtn;
}



//openimweindow_v2.js内容
var dzy_drag = function(o,s)
{
    if (typeof o == "string") o = document.getElementById(o);
    o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
    o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
    o.orig_index = o.style.zIndex;

    o.onmousedown = function(a)
    {
        this.style.cursor = "move";
        this.style.zIndex = 10000;
        var d=document;
        if(!a)a=window.event;
        var x = a.clientX+d.body.scrollLeft-o.offsetLeft;
        var y = a.clientY+d.body.scrollTop-o.offsetTop;
        d.ondragstart = "return false;"
        d.onselectstart = "return false;"
        d.onselect = "document.selection.empty();"

        if(o.setCapture)
        o.setCapture();
        else if(window.captureEvents)
        window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);

        d.onmousemove = function(a)    {
            if(!a)a=window.event;
            o.style.left = a.clientX+document.body.scrollLeft-x;
            o.style.top = a.clientY+document.body.scrollTop-y;
            o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
            o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
        }

        d.onmouseup = function(){
            if(o.releaseCapture)
            o.releaseCapture();
            else if(window.captureEvents)
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
            d.onmousemove = null;
            d.onmouseup = null;
            d.ondragstart = null;
            d.onselectstart = null;
            d.onselect = null;
            o.style.cursor = "normal";
            o.style.zIndex = o.orig_index;
        }
    }
    
    function __scroll(){
        o.style.left = o.orig_x + Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
        o.style.top = o.orig_y + Math.max(document.documentElement.scrollTop, document.body.scrollTop);
    }
    
    if (s){
        if (window.addEventListener) {
            window.addEventListener("scroll", __scroll, false);
        }else if(window.attachEvent){
            window.attachEvent("onscroll", __scroll);
        }
    }
}
if(enableDebug){
    var dzy_drag = function(o,s){
        if (typeof o == "string") o = document.getElementById(o);
        o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
        o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
        o.orig_index = o.style.zIndex;

        o.onmousedown = function(a)
        {
            this.style.cursor = "move";
            this.style.zIndex = 10000;
            var d=document;
            if(!a)a=window.event;
            var x = a.clientX+d.body.scrollLeft-o.offsetLeft;
            var y = a.clientY+d.body.scrollTop-o.offsetTop;
            d.ondragstart = "return false;"
            d.onselectstart = "return false;"
            d.onselect = "document.selection.empty();"

            if(o.setCapture)
            o.setCapture();
            else if(window.captureEvents)
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);

            d.onmousemove = function(a)    {
                if(!a)a=window.event;
                o.style.left = a.clientX+document.body.scrollLeft-x;
                o.style.top = a.clientY+document.body.scrollTop-y;
                o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
                o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
            }

            d.onmouseup = function(){
                if(o.releaseCapture)
                    o.releaseCapture();
                else if(window.captureEvents)
                    window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
                d.onmousemove = null;
                d.onmouseup = null;
                d.ondragstart = null;
                d.onselectstart = null;
                d.onselect = null;
                o.style.cursor = "normal";
                o.style.zIndex = o.orig_index;
            }
        }
        
        function __scroll(){
            o.style.left = o.orig_x + Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
            o.style.top = o.orig_y + Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        }
        
        if (s){
            if (window.addEventListener) {
                window.addEventListener("scroll", __scroll, false);
            }else if(window.attachEvent){
                window.attachEvent("onscroll", __scroll);
            }
        }
    }
    dzy = {
        im_debug_MouseX:0,
        im_debug_MouseY:0,
        im_debug_ObjX:0,
        im_debug_ObjY:0,
        
        init:function(){
            document.write('<div id="debugDiv" style="z-index:999;position:absolute;left:0px;top:0px;width:650px;"><div id="debugTitle" style="background:#00f;color:#fff;cursor:move;text-align:left;padding:3px;padding-left:20px"><b><font color="#ffffff">[DEBUG] - MOUSEDOWN DRAG</font></b>&nbsp;&nbsp;&nbsp;&nbsp;<span id="btn_" style="cursor: pointer;">[<-]</span>&nbsp;&nbsp;<span id="btn+" style="cursor: pointer;">[->]</span></div><div id="debugSpan" style="opacity:0.6;filter:alpha(opacity:60);background:#000;text-align:left;border:1px solid #888;height:0px;width:auto;overflow-y:scroll;color:#0f0;cursor: auto;"></div></div>')
            if(window.navigator.appName.indexOf("Microsoft") == 0){//IE
                document.getElementById('debugTitle').attachEvent("ondblclick", SET_MIN_debug);
                document.getElementById('btn+').attachEvent("onclick", SET_MIN_);
                document.getElementById('btn_').attachEvent("onclick", SET_MIN__);
            }else{
                document.getElementById('debugTitle').addEventListener("click", SET_MIN_debug, false); 
                document.getElementById('btn+').addEventListener("click", SET_MIN_, false); 
                document.getElementById('btn_').addEventListener("click", SET_MIN__, false); 
            }
            dzy_drag("debugDiv",true);
            
            function SET_MIN_debug(){
                var SpanStyle = document.getElementById('debugSpan').style;
                var BtnHTML  = document.getElementById('debugTitle');
                SpanStyle.height= SpanStyle.height=='300px' ? '0px' : '300px';
            }
            function SET_MIN_(){
                var Span = document.getElementById('debugSpan');
                Span.style.width = (Span.offsetWidth + 100) + 'px';
            }
            function SET_MIN__(){
                var Span = document.getElementById('debugSpan');
                Span.style.width = (Span.offsetWidth - 100) + 'px';
            }
        },    
        debug:function(out, showdebug){
            if(document.getElementById('debugSpan')){
                if(typeof out == "object"){
                    var _out = '<br />array(' + out.length + ') = [';
                    for(var k in out){
                        _out += ',<br />&nbsp;&nbsp;&nbsp;&nbsp;(' + typeof(out[k]) + ')["' + k + '"]&nbsp;&nbsp;=>';
                        if( typeof(out[k]) == "object" ){
                            _out += 'array(' + out[k].length + ') = [';
                            for(var k1 in out[k]){
                                _out += ',<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(' + typeof(out[k][k1]) + ')["' + k1 + '"]&nbsp;&nbsp;=>' + out[k][k1];
                            } 
                            _out += '<br />&nbsp;&nbsp;&nbsp;&nbsp;]';
                        }else{
                            _out += out[k];
                        }
                    }
                    _out += '<br />]';
                }else{
                    _out = out;
                }
                document.getElementById('debugSpan').innerHTML += '[' + new Date().getHours()+':'+new Date().getMinutes()+':'+new Date().getSeconds()+'] - [DEBUG] - '+ _out+"  [<a href=\"#\" onclick=\"dzy.clear()\"><font color=\"#FFFFFF\">CLEAR</font></a>]<br />";
                document.getElementById('debugSpan').scrollTop=document.getElementById('debugSpan').scrollHeight;
            }
            showdebug = showdebug ? true : false;
            if(showdebug) {
                var SpanStyle = document.getElementById('debugSpan').style;
                SpanStyle.height= SpanStyle.height=='300px' ? '0px' : '300px';
            }
        },
        clear:function(){
            document.getElementById('debugSpan').innerHTML='';
        },
        dispose:function(){
            var debugAttrib = document.getElementById('debugDiv');
            for(var id in debugAttrib){
                if(typeof(debugAttrib[id]) == "function"){
                    eval("debugAttrib."+id+"=null");
                }
            }
        }
    }
    dzy.init();
}
/*=======================================================================================================*/
var im_notshow_ad = false;
//var im_webchat_url = "http://wdknet.vicp.net/chat/2.4soufun/func/imwebchat.php";
//var im_buddylist_url = "http://wdknet.vicp.net/chat/2.4soufun/func/imbuddylist.php";
//var im_groupchat_url = "http://wdknet.vicp.net/chat/2.4soufun/func/imgroupchat.php";
var im_webchat_url = "http://download.xiaoneng.tianya.cn/chat/2.5/func/imwebchat.php";
var im_buddylist_url = "http://download.xiaoneng.tianya.cn/chat/2.5/func/imbuddylist.php";

function base64encode(input) {
    var keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";
  input = escape(input);
  var output = "";
  var chr1, chr2, chr3 = "";
  var enc1, enc2, enc3, enc4 = "";
  var i = 0;

  do {
     chr1 = input.charCodeAt(i++);
     chr2 = input.charCodeAt(i++);
     chr3 = input.charCodeAt(i++);

     enc1 = chr1 >> 2;
     enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
     enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
     enc4 = chr3 & 63;

     if (isNaN(chr2)) {
        enc3 = enc4 = 64;
     } else if (isNaN(chr3)) {
        enc4 = 64;
     }

     output = output + 
        keyStr.charAt(enc1) + 
        keyStr.charAt(enc2) + 
        keyStr.charAt(enc3) + 
        keyStr.charAt(enc4);
     chr1 = chr2 = chr3 = "";
     enc1 = enc2 = enc3 = enc4 = "";
  } while (i < input.length);

  return output;
}

function im_openWebchat(myuid, myname, mysid, siteid, destuid, destname, chatid, userparam, isnewwindow, imScriptPath){
    var _dir = "";
    if(siteid=="csdn" || siteid=="csdn_test" ||siteid=="discuz60gbkdzy" || siteid=="bbs60gbk")
        _dir = "csdn/";
    if(!myuid || myuid.length<=0){
        //var notifystr = "%u60A8%u5C1A%u672A%u767B%u5F55%uFF0C%u8BF7%u767B%u5F55%u540E%u518D%u4F7F%u7528%u5728%u7EBF%u804A%u5929%u529F%u80FD%uFF01";
        //alert(unescape(notifystr));
        MenuUtil.loginIfr("%u8BE5%u529F%u80FD%u9700%u8981%u767B%u5F55%u540E%u4F7F%u7528%uFF01");
        return null;
    }
    if(typeof(im_openWebchatInPage)!="undefined" && !isnewwindow){
        return im_openWebchatInPage(destuid, destname, chatid);
    }
    if(siteid=="cnmyspace" || siteid=="xiaonengtest"){
        im_notshow_ad = true;
        flashheight = "100%";
    }
    else
        flashheight = "94%";
    /*var curdate = new Date();
    var curtime = curdate.getTime();
    var cookiename = "imlastopenwindow"+destuid;
    var lastopentime = im_wdkUtil.GetCookie(cookiename);
    if(lastopentime){
        if(curtime-lastopentime<5000){
            return true;
        }
    }*/

    if(typeof(chatid)=="undefined")
        var chatid = null;
    if(typeof(userparam)=="undefined")
        var userparam = null;
    var isIE = window.navigator.appName.indexOf("Microsoft") == 0;

   var windowWidth = 544;
   var windowHeight = 428;
    var bshowlocation = isIE?"0":"0";
    var bshowlocation = "1";
    var webchatUrl = "";
    if(typeof(im_webchat_url)!="undefined" && im_webchat_url){
        webchatUrl = im_webchat_url;
        if(myuid) webchatUrl += "?myuid="+encodeURIComponent(myuid);
        if(myname) webchatUrl += "&myname="+encodeURIComponent(myname);
        if(mysid) webchatUrl += "&mysid="+encodeURIComponent(mysid);
        if(siteid) webchatUrl += "&siteid="+encodeURIComponent(siteid);
        if(destuid) webchatUrl += "&destuid="+encodeURIComponent(destuid);
        if(destname) webchatUrl += "&destname="+encodeURIComponent(destname);
        if(chatid) webchatUrl += "&chatid="+encodeURIComponent(chatid);
        if(userparam) webchatUrl += "&userparam="+encodeURIComponent(userparam);
    }
    
    try{
       var webchatWindow = window.open( webchatUrl, "imwebchat_"+destuid, "width="+windowWidth+",height="+windowHeight+",toolbar=0,directories=0,menubar=0,status=0,location="+bshowlocation+",scrollbars=0,resizable=1" );
    }
    catch(e){
        webchatWindow = null;
        return null;
    }
    if(webchatWindow){
      try{
         //webchatWindow.resizeTo(windowWidth, windowHeight);
      }catch(e){};
      webchatWindow.focus();
    }

    if(typeof(im_webchat_url)!="undefined" && im_webchat_url){
    	//webchatWindow.parentWnd = window;
      return webchatWindow;
    }

    var titlestr = unescape("%u4E0E")+destname+unescape("%u804A%u5929");
    var popinstr = unescape("%u8DF3%u5165");
    var docstr =
    '<html><head>\
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\
    <title>'+titlestr+'</title>\
    </head>\
    <body bgcolor="#ffffff" bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0">\
      <div id="imwebchat" style="height:'+flashheight+'">\
      </div>\
        <script src="'+imScriptPath+'/promptwindow.js" type="text/javascript"></script>\
        <script src="'+imScriptPath+'/flashobject_v2.js" type="text/javascript"></script>\
        <script src="'+imScriptPath+'/openimwindow_v2.js" type="text/javascript"></script>\
        <script type="text/javascript">\
        var flashobj = null;\
        var promptwindow = null;\
            im_initChatWindow = function(){\
            n = navigator.userAgent.toLowerCase(),\
            tt_ie = n.indexOf("msie") != -1 && document.all;\
            flashobj = new FlashObject("'+imScriptPath+'/imbuddylist.swf", "webchatflash", "100%", "100%", "9", "#ffffff", false, "best");\
            flashobj.imFlashType = "webchat";\
            flashobj.imScriptPath = "'+imScriptPath+'";\
            flashobj.addParam("scale", "noscale");\
            flashobj.addParam("menu", "true");\
            flashobj.addParam("salign", "LT");\
            flashobj.addParam("allowScriptAccess", "always");\
            if(tt_ie)\
              flashobj.addParam("wmode", "Window");\
            else\
              flashobj.addParam("wmode", "Window");\
            flashobj.addVariable("sessionid", "'+encodeURIComponent(mysid)+'");\
            flashobj.addVariable("myuid", "'+encodeURIComponent(myuid)+'");\
            flashobj.addVariable("myname", "'+encodeURIComponent(myname)+'" );\
            flashobj.addVariable("siteid", "'+encodeURIComponent(siteid)+'" );\
            flashobj.addVariable("destuid", "'+encodeURIComponent(destuid)+'" );\
            flashobj.addVariable("destname", "'+encodeURIComponent(destname)+'" );\
            flashobj.addVariable("chatid", "'+encodeURIComponent(chatid?chatid:'')+'" );\
            flashobj.addVariable("userparam", "'+encodeURIComponent(userparam?userparam:'')+'" );\
            flashobj.write("imwebchat");\
            promptwindow = new PromptWindow();\
          promptwindow.init();\
        };\
        if(typeof(FlashObject)!="undefined")\
          im_initChatWindow();\
          </script>';
          
    if(!im_notshow_ad){
        docstr += 
        '<div style="width=100%;height=6%">\
          <span style="float:left;width:85%;height:22px;overflow:hidden;">\
            <a href="http://www.ntalker.com" target="_blank"><img border="0" src="'+imScriptPath+'/images/popchatad.gif" style="width:100%;height:20px"></a>\
          </span>\
          <span style="float:right;margin:0px;padding:0px;width:15%;height:100%">\
            <a href="#" onclick="javascript: im_popin_webchat();return false;">\
              <img style="width:50px;height:22px;float:right" border="0" src="'+imScriptPath+'/images/'+_dir+'btpopin.jpg"></img>\
            </a>\
          </span>\
         </div>';
    }
    docstr +='</body></html>';
    try{
      webchatWindow.document.open("text/html", "replace");
      webchatWindow.document.charset="utf-8";
      webchatWindow.document.write(docstr);
    }
    catch(e){
      alert(e);
      return null;
    }
    webchatWindow.document.close();
    webchatWindow.focus();
    return webchatWindow;
}
function im_openGroupChat(myuid, myname, mysid, siteid, groupid, groupname, chatid, userparam, isnewwindow, imScriptPath){
   if(!myuid || myuid.length<=0){
     var notifystr = "%u60A8%u5C1A%u672A%u767B%u5F55%uFF0C%u8BF7%u767B%u5F55%u540E%u518D%u4F7F%u7528%u5728%u7EBF%u804A%u5929%u529F%u80FD%uFF01";
     alert(unescape(notifystr));
     return null;
   }

   /*var curdate = new Date();
   var curtime = curdate.getTime();
   var cookiename = "imlastopenwindow"+destuid;
   var lastopentime = im_wdkUtil.GetCookie(cookiename);
   if(lastopentime){
       if(curtime-lastopentime<5000){
         return true;
      }
   }*/

   if(typeof(chatid)=="undefined")
     var chatid = null;
   if(typeof(userparam)=="undefined")
     var userparam = null;
   var isIE = window.navigator.appName.indexOf("Microsoft") == 0;
   
   var windowWidth = 560;
   var windowHeight = 515;
   var bshowlocation = isIE?"0":"0";
   var bshowlocation = "1";
   var webchatUrl = "";
   if(typeof(im_groupchat_url)!="undefined" && im_groupchat_url){
     webchatUrl = im_groupchat_url;
     if(myuid) webchatUrl += "?myuid="+(encodeURIComponent(myuid));
       if(myname) webchatUrl += "&myname="+(encodeURIComponent(myname));
       if(mysid) webchatUrl += "&mysid="+(encodeURIComponent(mysid));
       if(siteid) webchatUrl += "&siteid="+(encodeURIComponent(siteid));
       if(groupid) webchatUrl += "&groupid="+(encodeURIComponent(groupid));
       if(groupname) webchatUrl += "&groupname="+(encodeURIComponent(groupname));
       if(chatid) webchatUrl += "&chatid="+(encodeURIComponent(chatid));
       if(userparam) webchatUrl += "&userparam="+(encodeURIComponent(userparam));
     }
      
     try{
       var webchatWindow = window.open( webchatUrl, "imgrouptchat_"+groupid, "width="+windowWidth+",height="+windowHeight+",toolbar=0,directories=0,menubar=0,status=0,location="+bshowlocation+",scrollbars=0,resizable=1" );
   }
   catch(e){
     webchatWindow = null;
     return null;
   }
   if(webchatWindow){
         try{
             //webchatWindow.resizeTo(windowWidth, windowHeight);
           }catch(e){};
           webchatWindow.focus();
      }
      if(typeof(im_webchat_url)!="undefined" && im_webchat_url)
     return webchatWindow;

   var titlestr = "("+unescape("%u7FA4%u804A")+")"+groupname;
   flashheight = "100%";
     var docstr =
    '<html><head>\
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\
    <title>'+titlestr+'</title>\
    </head>\
    <body bgcolor="#ffffff" bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0">\
      <div id="imwebchat" style="height:'+flashheight+'">\
      </div>\
        <script src="'+imScriptPath+'/promptwindow.js" type="text/javascript"></script>\
           <script src="'+imScriptPath+'/flashobject_v2.js" type="text/javascript"></script>\
           <script src="'+imScriptPath+'/openimwindow_v2.js" type="text/javascript"></script>\
          <script type="text/javascript">\
          var flashobj = null;\
          var promptwindow = null;\
            im_initChatWindow = function(){\
              n = navigator.userAgent.toLowerCase(),\
            tt_ie = n.indexOf("msie") != -1 && document.all;\
              flashobj = new FlashObject("'+imScriptPath+'/imgroup.swf", "webchatflash", "100%", "100%", "9", "#ffffff", false, "best");\
              flashobj.imFlashType = "webchat";\
              flashobj.imScriptPath = "'+imScriptPath+'";\
              flashobj.addParam("scale", "noscale");\
              flashobj.addParam("menu", "true");\
              flashobj.addParam("salign", "LT");\
              flashobj.addParam("allowScriptAccess", "always");\
              if(tt_ie)\
                flashobj.addParam("wmode", "Window");\
              else\
                flashobj.addParam("wmode", "Window");\
              flashobj.addVariable("sessionid", "'+encodeURIComponent(mysid)+'");\
              flashobj.addVariable("myuid", "'+encodeURIComponent(myuid)+'");\
              flashobj.addVariable("myname", "'+encodeURIComponent(myname)+'" );\
              flashobj.addVariable("siteid", "'+encodeURIComponent(siteid)+'" );\
              flashobj.addVariable("groupid", "'+encodeURIComponent(groupid)+'" );\
              flashobj.addVariable("groupname", "'+encodeURIComponent(groupname)+'" );\
              flashobj.addVariable("chatid", "'+encodeURIComponent(chatid?chatid:'')+'" );\
              flashobj.addVariable("userparam", "'+encodeURIComponent(userparam?userparam:'')+'" );\
              flashobj.write("imwebchat");\
              promptwindow = new PromptWindow();\
          promptwindow.init();\
        };\
        if(typeof(FlashObject)!="undefined")\
          im_initChatWindow();\
          </script>';
          
    docstr +='</body></html>';

    try{
      webchatWindow.document.open("text/html", "replace");
      webchatWindow.document.charset="utf-8";
      webchatWindow.document.write(docstr);
    }
    catch(e){
        alert(e);
      return null;
    }
    webchatWindow.document.close();
    webchatWindow.focus();
    return webchatWindow;
}
function im_openBuddyList(myuid, myname, mysid, siteid, userparam, imScriptPath){
    var _dir="";
    if(siteid=="csdn" || siteid=="csdn_test" || siteid=="discuz60gbkdzy" || siteid=="bbs60gbk")
        _dir = "csdn/";
    if (typeof(im_openwindow_inbuddylist)=='undefined'){
        if(!im_global.variable.user_id || im_global.variable.user_id.length<=0){
         //var notifystr = "%u60A8%u5C1A%u672A%u767B%u5F55%uFF0C%u8BF7%u767B%u5F55%u540E%u518D%u4F7F%u7528%u5728%u7EBF%u804A%u5929%u529F%u80FD%uFF01";
         //alert(unescape(notifystr));
         MenuUtil.loginIfr("%u8BE5%u529F%u80FD%u9700%u8981%u767B%u5F55%u540E%u4F7F%u7528%uFF01");
         return null;
       }
    }
    if(typeof(userparam)=="undefined")
        var userparam = null;
    var isIE = window.navigator.appName.indexOf("Microsoft") == 0;
    var buddylistUrl = "";
    var windowWidth = 292;
    var windowHeight = 520;
    var bshowlocation = isIE?"0":"1";
    var bshowlocation = "1";
    var buddylistUrl = "";
    if(typeof(im_buddylist_url)!="undefined" && im_buddylist_url){
        buddylistUrl = im_buddylist_url;
        if(myuid) buddylistUrl += "?myuid="+encodeURIComponent(myuid);
        if(myname) buddylistUrl += "&myname="+encodeURIComponent(myname);
        if(mysid) buddylistUrl += "&mysid="+encodeURIComponent(mysid);
        if(siteid) buddylistUrl += "&siteid="+encodeURIComponent(siteid);
        if(userparam) buddylistUrl += "&userparam="+encodeURIComponent(userparam);
   }
    
    try{
        var buddylistWindow = window.open( buddylistUrl, "imbuddylist_"+myuid, "width="+windowWidth+",height="+windowHeight+",toolbar=0,directories=0,menubar=0,status=0,location="+bshowlocation+",scrollbars=0,resizable=1" );
    }catch(e){
        buddylistWindow = null;
        return null;
    }
     if(buddylistWindow){
           try{
             //buddylistWindow.resizeTo(windowWidth, windowHeight);
           }catch(e){};
        buddylistWindow.focus();
   }
    if(typeof(im_buddylist_url)!="undefined" && im_buddylist_url)
        return buddylistWindow;

    if(siteid=="cnmyspace" || siteid=="xiaonengtest"){
        im_notshow_ad = true;
        flashheight = "100%";
        titlestr = unescape("%u805A%u53CB%u804A%u804A");
    }
    else if(siteid=="csdn"){
      flashheight = "94%";
      titlestr = unescape("CSDN%u5B9E%u65F6%u4FE1%u606F%u901A%u8BAF%u5E73%u53F0");
    }
    else if(siteid=="tianya" || siteid=="tianya2.5" || siteid=="tianya_test"){
      flashheight = "94%";
      titlestr = unescape("%u5929%u6DAF%u804A%u804A");
    }
    else{
        flashheight = "94%";
        titlestr = unescape("%%u597D%u53CB%u5217%u8868");
    }
    var popinstr = unescape("%u8DF3%u5165");
    var docstr =
    '<html>\
     <head>\
         <meta http-equiv=Content-Type content="text/html;  charset=utf-8">\
         <title>'+titlestr+'</title>\
     </head>\
     <body bgcolor="#ffffff" bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0">\
       <div id="imbuddylist" style="height:'+flashheight+'">\
       </div>\
        <script src="'+imScriptPath+'/promptwindow.js" type="text/javascript"></script>\
           <script src="'+imScriptPath+'/flashobject_v2.js" type="text/javascript"></script>\
           <script src="'+imScriptPath+'/openimwindow_v2.js" type="text/javascript"></script>\
           <script type="text/javascript">\
           var flashobj = null;\n\
          var promptwindow = null;\n\
        im_initBuddylistWindow = function(){\n\
          n = navigator.userAgent.toLowerCase(),\n\
            nv = navigator.appVersion;\n\
            tt_ie = n.indexOf("msie") != -1 && document.all;\n\
               flashobj = new FlashObject("'+imScriptPath+'/imwdkbuddylist.swf", "buddylistflash", "100%", "100%", "9", "#ffffff", false, "best");\n\
              flashobj.imFlashType = "buddylist";\n\
              flashobj.imScriptPath = "'+imScriptPath+'";\
               flashobj.addParam("scale", "noscale");\n\
               flashobj.addParam("menu", "true");\n\
               flashobj.addParam("salign", "LT");\n\
               flashobj.addParam("allowScriptAccess", "always");\n\
               if(tt_ie)\n\
                flashobj.addParam("wmode", "Opaque");\n\
              else\n\
                flashobj.addParam("wmode", "Window");\n\
               flashobj.addVariable("sessionid", "'+encodeURIComponent(mysid)+'");\n\
               flashobj.addVariable("myuid", "'+encodeURIComponent(myuid)+'");\n\
               flashobj.addVariable("myname", "'+encodeURIComponent(myname)+'" );\n\
               flashobj.addVariable("mytitle", "'+encodeURIComponent(titlestr)+'" );\n\
               flashobj.addVariable("siteid", "'+encodeURIComponent(siteid)+'" );\n\
               flashobj.addVariable("userparam", "'+encodeURIComponent(userparam?userparam:'')+'" );\
               flashobj.write("imbuddylist");\n\
               var promptwindow = new PromptWindow();\n\
        }\n\
        if(typeof(FlashObject)!="undefined")\n\
          im_initBuddylistWindow();\n\
         </script>\n';
     if(typeof im_notshow_ad=="undefined" || !im_notshow_ad){
         docstr +=
            '<div style="width:100%;height:6%">\
                <span style="float:left;width:80%;height:100%;overflow: hidden;">\
                    <a href="http://www.ntalker.com" target="_blank" ><img border="0"  style="width:100%;height:20px" src="'+imScriptPath+'/images/popbuddyad.gif" /></a>\
                </span>\
                <span style="float:right;margin:0px;padding:0px;width:20%;height:100%">\
                    <a href="#" onclick="javascript: im_popin_buddylist();return false;">\
                        <img style="width:50px;height:22px;float:right;" border="0" src="'+imScriptPath+'/images/'+_dir+'btpopin.jpg" />\
                    </a>\
                </span>\
            </div>';
     }
    docstr +=    
        '</body>\
        </html>';
    try{
        buddylistWindow.document.open("text/html", "replace");
        buddylistWindow.document.charset="utf-8";
        buddylistWindow.document.write(docstr);
    }
    catch(e){
      return null;
    }
    buddylistWindow.document.close();
    buddylistWindow.focus();
    return buddylistWindow;

}


//buddylist flash will call this function when user double click buddy name in buddylist
function imOpenChatWindow(destuid, destname, myuid, myname, mysid, siteid, userparam){
   if(typeof(im_openWebchatInPage)!="undefined"){
     im_openWebchatInPage(destuid, destname);
     return true;
   }
   else{
     if(flashobj)
       im_openWebchat(myuid, myname, mysid, siteid, destuid, destname, null, userparam, true, flashobj.imScriptPath, "")
   }
}

//webchat flash will call this function when user  click buddylist button
function OnWebchatOpenBuddylist(myuid, myname, mysid, siteid, userparam){
    if(typeof(wdkfloat)!="undefined"){
        if(wdkfloat)
            wdkfloat.showWindow();
    }
    else{
        alert(siteid);
        if(flashobj)
            im_openBuddyList(myuid, myname, mysid, siteid, userparam, flashobj.imScriptPath);
    }
    return true;
}

function OnGroupOpenChatWindow(destuid, destname, myuid, myname, mysid, siteid, userparam){
  if(flashobj)
    im_openWebchat(myuid, myname, mysid, siteid, destuid, destname, null, userparam, true, flashobj.imScriptPath)
  return true;
}
function OnGroupListOpenGroupWindow(groupid, groupname, myuid, myname, mysid, siteid, userparam){
  if(flashobj)
     im_openGroupChat(myuid, myname, mysid, siteid, groupid, groupname, null, userparam, true, flashobj.imScriptPath)
  return true;
}

im_tianyaInit();
