if (!window.Fetion)
    window.Fetion = { "Web": { "Chat": {} } };
var ua = navigator.userAgent.toLowerCase();
var isIE = ua.indexOf("msie") > -1;
window.FetionWebChat = Fetion.Web.Chat;
Fetion.Web.Chat.msgList = [];
Fetion.Web.Chat.ctrlList = [];
Fetion.Web.Chat.ctrlQueue = [];
Fetion.Web.Chat.clsErrList = {};
Fetion.Web.Chat.JSPath = "chat/js/";
Fetion.Web.Chat.SelectImg = null;
var isScrollUp=false;
Fetion.Web.Chat.defined = function (name)
{
    var className = name;
    var nameAry = name.split(".");
    var cls = window;
    for (var i = 0; i < nameAry.length; i++)
    {
        name = nameAry[i];
        if (!cls[name])
            cls[name] = {};
        cls = cls[name];
    }
    cls.className = className;
    Fetion.Web.Chat[name] = Fetion.Web.Chat[name.toLowerCase()] = Fetion.Web.Chat[name.toUpperCase()] = cls;
    window[className.replace(/\./g, "")] = cls;
    return cls;
};
Fetion.Web.Chat.newInfo = function (data)
{
    if (data.constructor == String)
        data = eval("(" + data + ")");
    data.state = data.type;
    data.type = "info";
    Fetion.Web.Chat.newMsg(data);
    window.fxBrowser.ScrollToBottom();
};
Fetion.Web.Chat.newMsg = function (datas)
{
    this.newMsgBase(datas, true);
}
Fetion.Web.Chat.newMsgBase = function (datas, isNew)
{
    //msgDIV.innerHTML = datas;

    initDoc();
    window.chatBody.onselectstart=function(e){return true;}
    var jsonStr = null;
    if (datas.constructor == String)
    {
        jsonStr = datas;
        datas = eval("(" + datas + ")");
    }

    if (datas.constructor != Array)
        datas = [datas];

    if (!datas.length)
        return;

    var head = datas[0];
    var tail = datas[datas.length - 1];
    if (head.type != "head" && tail.type == "head")
    {
        head = datas.pop();
        datas.unshift(head);
    };
	var uid=head.uid?head.uid:"";
    var msgObj = document.createElement("DIV");
    msgObj.type = "msgObj";
    msgObj.jsonStr = jsonStr;
    msgObj.id = head.msgid;
	msgObj.uid = uid;
	
    var div = isNew == false ? bodyHead.nextSibling : bodyBoot;
    this.body.insertBefore(msgObj, div);
    msgObj.style.padding = "7px 10px 0 10px";

    msgObj.head = head;
    msgObj.datas = datas;

    head.parent = msgObj;
    this.newCtrl(head);

    var msgBody = document.createElement("DIV");
    msgBody.style.padding = "2px 0 0 12px";
    msgBody.jsonStr = jsonStr;
    msgBody.id = head.msgid;
	msgBody.uid = uid;
    msgObj.appendChild(msgBody);

    this.msgList.push(datas);

    msgObj.onmousedown = function ()
    {
        window.selMsg = this;
    };
    msgObj.onclick = function ()
    {
    };
    for (var i = 1; i < datas.length; i++)
    {
        var data = datas[i];
        data.parent = msgBody;
        this.newCtrl(data);
    }
    this.hasContent = true;
};
Fetion.Web.Chat.newHistory = function (datas, hasMore)
{
    if (datas.constructor == String)
    {
        if (datas.replace(/^\s+|\s+$/g, "") == "null")
            datas = "[]";
        datas = eval("(" + datas + ")");
    }
    if (hasMore != undefined)
        window.hasMsg = hasMore;

    //msgDIV.innerHTML = datas.length;

    if (datas.length)
    {
        bodyHistoryLine.style.display = "block";
        this.hasHistory = true;
    }

    if (window.hasMsg == 1)
    {
        this.showHistory = true;
        //bodyHead.innerHTML = "<input type='button' class='btn_01' value='更多消息' onclick='Fetion.Web.Chat.scrollHeight=Fetion.Web.Chat.body.scrollHeight;try{window.external.GetLastMsgRecord(20)}catch(e){}'/>";
		bodyHead.innerHTML = "<div class='his-inf' id='morebtn'   a='more'  onclick='Fetion.Web.Chat.scrollHeight=Fetion.Web.Chat.body.scrollHeight;try{window.external.GetLastMsgRecord(3)}catch(e){}'>&nbsp;<a a='more' ><span a='more'  class='his-icon'></span>更多消息</a></div>";
    }
    else
        bodyHead.innerHTML = "";

    bodyHead.style.display = bodyHead.innerHTML != "" ? "block" : "none";

    if (!datas || !datas.length)
        return;

    var scrollBar = this.body.scrollBar;
    if (scrollBar)
        scrollBar.drag = false;

    for (var i = datas.length - 1; i >= 0; i--)
        this.newMsgBase(datas[i], false);
};
Fetion.Web.Chat.newCtrl = function (o)
{
    if (o.constructor == String)
        o = { type: o };
    o.src = this.JSPath + "/" + o.type + ".js";
    this.ctrlQueue.push(o);
    if (!this[o.type])
        this.loadSRC(o);
    return this.createCtrl(o);
};
Fetion.Web.Chat.loadSRC = function (o)
{
    if (o.constructor == String)
        o = o.indexOf(".") == "-1" ? { type: o } : { src: o };
    if (!o.src)
        o.src = this.JSPath + "/" + o.type + ".js";

    if (!window.srcMap)
        window.srcMap = {};
    if (!srcMap[o.src])
    {
        srcMap[o.src] = o;
        var src = null;
        if (o.src.indexOf(".js") != -1)
        {
            src = document.createElement("script");
            src.setAttribute("type", "text/javascript");
            src.setAttribute("src", o.src);
        }
        else if (o.src.indexOf(".css") != -1)
        {
            src = document.createElement("link");
            src.setAttribute("rel", "stylesheet");
            src.setAttribute("type", "text/css");
            src.setAttribute("href", o.src);
        }
        if (src)
        {
            var head = document.getElementsByTagName("head")[0];
            head.appendChild(src);
        }
    }
    if (o.src.indexOf(".js") != -1 && !o.type)
        o.type = o.src.substring(o.src.replace(/\\/g, "/").lastIndexOf("/") + 1, o.src.lastIndexOf(".")).toLowerCase();
};
Fetion.Web.Chat.createCtrl = function (o)
{
    var baseCls = "cardfrm";
    var cls = this.ctrlQueue[0] || baseCls.indexOf(o.type) != -1 ? Fetion.Web.Chat[o.type] : null;
    var obj = null;
    try
    {
        obj = cls.create(o.sub || o);
    }
    catch (e)
    {
        //msgDIV.innerHTML = e.message;
        setTimeout(function () { Fetion.Web.Chat.createCtrl(o) });
        return null;
    }
    if (this.ctrlQueue[0])
        this.ctrlQueue.shift();
    this.clsErrList[o.type] = null;

    if (!o.id)
        o.id = this.newID(o.type);
    obj.cls = cls;
    obj.data = o;
    obj.id = Fetion.Web.Chat.formatID(o.id);
    obj.setAttribute("name", obj.id);
    obj.type = o.type;
    obj.setAttribute("type", o.type);
    obj.lang = '{"type":"' + o.type + '"}';
    if (o.style)
        this.setStyle(obj, o.style);

    Fetion.Web.Chat.scroll();

    obj.onmousedown = function ()
    {
        window.selMsgCtrlMousedown = true;
        window.selObj = null;
        window.imgSrc = null;
        if ("IMG,CE,URLLINK".indexOf(this.type.toUpperCase()) != -1)
        {
            window.selObj = this;
            window.imgSrc = this.data.path;
        }
        window.selMsgCtrl = this;
        window.pid = this.data.id;
		var e = e || window.event;
		var target = e.srcElement || e.target;
			if(target.tagName=="A"&&target.menu){
				return;
			}
        var rect = this.getBoundingClientRect();
        if (rect.bottom - rect.top > document.documentElement.clientHeight)
            return;
        var scrollBar = Fetion.Web.Chat.body.scrollBar;
        if (scrollBar)
        {
            var tValue = rect.top;
            var bValue = rect.bottom - document.documentElement.clientHeight;
            if (tValue < 0 || tValue < bValue){
				scrollBar.isBottom = false;
                scrollBar.setScrollBar(Fetion.Web.Chat.body.scrollTop + tValue);
            }else if (bValue > 0 && tValue > bValue)
                scrollBar.setScrollBar(Fetion.Web.Chat.body.scrollTop + bValue);
        }
    }

    if (false && cls.update)
        setTimeout(function () { cls.update(obj, obj.data); }, 1000);
    return obj
};
Fetion.Web.Chat.newID = function (name)
{
    while (true)
    {
        var tmpName = name + "_" + parseInt(Math.random() * 1000);
        var obj = window[tmpName];
        if (!obj)
            return tmpName;
    }
};
Fetion.Web.Chat.formatID = function (id)
{
    return ("_" + id).replace(/\W/, "_");
};
Fetion.Web.Chat.scroll = function ()
{
    if (!this.body)
        return;
    var scrollBar = this.body.scrollBar;
    if (!scrollBar)
    {
        this.body.scrollBar = {};
        this.newCtrl({ type: "scrollbar", parent: this.body });
        return;
    }
    if (scrollBar.setScrollBar)
    {
        var scrollTop = null;
        if (Fetion.Web.Chat.scrollHeight)
            scrollTop = this.body.scrollHeight - Fetion.Web.Chat.scrollHeight;
        scrollBar.setScrollBar(scrollTop);
    }
}
Fetion.Web.Chat.updateCtrl = function (datas)
{
    if (datas.constructor == String)
        datas = eval("(" + datas + ")");
    if (datas.constructor != Array)
        datas = [datas];
    for (var i = 0; i < datas.length; i++)
    {
        var data = datas[i];
        var id = Fetion.Web.Chat.formatID(data.id);
        var ctrls = document.getElementsByName(id);
        if (!data.type && ctrls[0])
            data.type = ctrls[0].type;
        var cls = Fetion.Web.Chat[data.type];
        if (cls && cls.update)
        {
            var ctrls = document.getElementsByName(id);
            var length = ctrls.length;
            for (var i = 0; i < length; i++)
            {
                var ctrl = ctrls[i];
                if (!ctrl.data)
                    ctrl.data = {};
                for (var attr in data)
                    ctrl.data[attr] = data[attr];
                cls.update(ctrls[i], ctrl.data);
            }
        }
    }
    Fetion.Web.Chat.scroll();
}
Fetion.Web.Chat.setStyle = function (ctrl, style)
{
    if (!style)
        return;
    var styles = style.replace(/,/g, ";").replace(/ /g, "").split(";");
    for (var i = 0; i < styles.length; i++)
    {
        var style = styles[i];
        if (style == "")
            continue;
        style = style.split(":");
        try
        {
            var styleName = style[0];
            if (styleName.indexOf("-") != -1)
            {
                var names = styleName.split("-");
                styleName = names[0] + names[1].substring(0, 1).toUpperCase() + names[1].substring(1);
            }
            ctrl.style[styleName] = style[1];
        }
        catch (e)
        {
            //alert(style + "\n" + e.message);
        }
    }
};
Fetion.Web.Chat.Ltrim=function(str)
{
    var i = 0;
    while(str.substring(6*i, 6*(i+1)) == '&nbsp;'){++i;}
    if(i!=0){
        return str.substring(6*(i+1), str.length);
    }else{
        return str;
    }
};
Fetion.Web.Chat.toString = function (obj)
{
    var type = obj.constructor;
    if (!type)
        return null;

    if (type == String)
        return "\"" + obj.replace(/\\/g, "\\\\") + "\"";
    if (type == Number || type == Boolean)
        return obj.toString();

    var str = "";
    type = typeof obj.push == "function" ? Array : Object;
    if (type == Array)
    {
        str += "[";
        for (var i = 0; i < obj.length; i++)
        {
            if (i > 0)
                str += ",";
            str += Fetion.Web.Chat.toString(obj[i]);
        }
        str += "]";
    }
    else
    {
        str += "{";
        var i = 0;
        for (var attr in obj)
        {
            if (i++ > 0)
                str += ",";
            str += "\"" + attr + "\":";
            str += Fetion.Web.Chat.toString(obj[attr]);
        }
        str += "}";
    }
    return str;
};
Fetion.Web.Chat.formatDatetime = function (time, format)
{
    if (!time)
        return "";

    time = parseInt(time);

    if (!format)
        format = "hh:mm:ss";

    var fmtAry = ["ss", "mm", "hh"];
    var argAry = [60, 60, 24];
    for (var i = 0; i < fmtAry.length; i++)
    {
        var fmt = fmtAry[i];
        var arg = argAry[i];
        format = format.replace(fmt, (time % arg + 100 + "").substring(1, 3));
        time = time / arg;
    }
    format = format.replace(/00:/g, "");
    if (format.length == 2)
        format += "'";
    return format;
}
Fetion.Web.Chat.loadSRC("css/chat.css");
Fetion.Web.Chat.background = window.chatBG;
Fetion.Web.Chat.body = window.chatBody;
bodyHead.style.width = document.documentElement.clientWidth - 13;
Fetion.Web.Chat.scroll();
Fetion.Web.Chat.copy = function ()
{
    var fetionhtml = "", bitmap = "", text = "", html = "";
    var rangeStr = document.selection.createRange().htmlText;

    //预处理rangeStr
    if (rangeStr == "" && window.selObj)
        rangeStr = selObj.outerHTML;
    var span = document.createElement("span");
    span.innerHTML = rangeStr.replace(/fetionres:\/\/\//g, "file:///");
    if (span.childNodes.length == 1 && span.childNodes[0].jsonStr)
        span = span.childNodes[0];

    var imgs = span.getElementsByTagName("IMG");
    for (var i = 0; i < imgs.length; i++)
    {
        var img = imgs[i];
        if (!img.type || "IMG,CE".indexOf(img.type.toUpperCase()) == -1||img.title == "点击查看原图")
        {
            img.parentNode.removeChild(img);
            i--;
            continue;
        }
        img.removeAttribute("title");
        img.removeAttribute("class");
        img.removeAttribute("style");
        img.removeAttribute("oncontextmenu");
        img.src = unescape(img.src).replace(/\+/g, " ");
    }
    var innerHTML = span.innerHTML;
    var innerText = span.innerText;

    //处理bitmap
    if (span.childNodes.length == 1 && imgs.length > 0)
        bitmap = unescape(imgs[0].src).replace("file:///", "");

    //处理文字
    var text = innerText.replace(/\r\n/g, "\r").replace(/^\s+|\s+$/g, "");

    //处理feitionformat
    var tmpObj = document.createElement("span");
    tmpObj.innerHTML = innerHTML.replace(/<img/gi, "&lt;FETION_OBJECT");
    var tmpText = tmpObj.innerText.replace(/</g, "&lt;").replace(/\&nbsp/g, " ");
    var html = tmpText.replace(/\&lt;FETION_OBJECT/gi, "<IMG");
    tmpText = tmpText.replace(/\&lt;FETION_OBJECT/gi, "<OBJECT");
    var fetionhtml = tmpText.replace(/imgid/g, "ID").replace(/^\s+|\s+$/g, "");

    window.external.SetClipbrdData(html, text, bitmap, fetionhtml);
    var str = "html:" + html + "\n\n\ntext:" + text + "\n\n\nbitmap:" + bitmap + "\n\n\nfetionhtml:" + fetionhtml;
    //msgDIV.innerHTML = "<textarea style='width:100%;height:100'>" + str + "</textarea>";
};
Fetion.Web.Chat.split = function (str, len)
{
    if (str.length < len)
        return str;
    len = len * 2 - 3;
    var result = "";
    for (var i = 0; i < str.length && len > 0; i++)
    {
        var tmp = str.substring(i, i + 1);
        if (tmp.replace(/[^\x00-\xff]/g, "").length == 0)
            len -= 1;
        len -= 1;
        result += tmp;
    }
    result += "...";
    return result;
};
document.body.onload = function ()
{
    document.body.style.height = Fetion.Web.Chat.background.style.height = Fetion.Web.Chat.body.style.height = document.documentElement.clientHeight;
};
initDoc();
function initDoc()
{
    if (window.isInitDoc)
    {
        window.isInitDoc = true;
        return;
    }
    window.chatBody.onselectstart=function(e){return false;}
	document.onclick=function(e){
		e = e || window.event;
		var obj = e.srcElement || e.target;
		try{
			if(obj!=Fetion.Web.Chat.SelectImg.img){
				Fetion.Web.Chat.SelectImg.img.className="none-border";
				Fetion.Web.Chat.SelectImg=null;
			}
		}catch(e){}
	}
    document.onkeydown =function(e){
        e = e || event;
		if(e.keyCode==38){
			isScrollUp = true;
		}
		if(Fetion.Web.Chat.SelectImg!=null&&(e.keyCode==32||e.keyCode==13)){
			e.cancel=true;
			Fetion.Web.Chat.SelectImg.ondblclick();
			return false;
		}
        if (e.ctrlKey && e.keyCode == 65) {
                try{
                    window.fxBrowser.SelectAll();
                }catch(e1){
                    alert(e1);
                }
                return false;
        }
        return true;
    }
    document.oncontextmenu = function(e) {
		e = e || event;
		var obj = e.srcElement || e.target;
        var span = document.createElement("span");
		var bRChickUrl = false;
        span.innerHTML = document.selection.createRange().htmlText;
        if (span.childNodes.length <= 1 && window.selMsgCtrl) {
            var type = selMsgCtrl.type.toUpperCase();
			if(type=="URLLINK"){
				bRChickUrl = true;
			}
            if ("HEAD,TEXT,CE,IMG,IMGS,URLLINK".indexOf(type) == -1)
                return false;
        }

        var pStr = "";
        if (window.imgSrc)
            pStr += "<Item k='img' v='" + imgSrc + "' type='" + type + "'/>";

        if (window.pid)
            pStr += "<Item k='div' v='" + pid + "'/>";
        var msgId = "";
        var uid="";
        if(window.selMsgCtrl)
        {
			var selObj=window.selMsgCtrl;
			if(selObj.xtype=="false"&&obj.tagName=="DIV"){
				msgId=null;
			}else{
            while (selObj && selObj.type != "msgObj")
				selObj = selObj.parentNode;
				msgId = selObj.id;
			}
            
			uid = selObj.uid;
        }
		if(span.innerHTML){
			var ids = [];
			for(var i=0;i<span.childNodes.length;i++){
				var item = span.childNodes[i];
				if(item.tagName=="DIV"&&item.type=="msgObj"){
					if(item.id=="undefined"){
						ids[ids.length]="undefinedid";
					}else{
						ids[ids.length]=item.id;
					}
				}
			}
			ids = ids.join();
			pStr += "<Item k='mIds' v='" + ids + "'/>";
		}
	if (msgId){
	    pStr += "<Item k='msgId' v='" + msgId + "'/>";
	}else{
		pStr="";
	}
	if (uid)
	    pStr += "<Item k='uid' v='" + uid + "'/>";
	e = e || event;
	var obj = e.srcElement || e.target;
	if(obj&&(obj.className=="btn_pane"||obj.a=="more")){
	    window.imgSrc = null;
        window.pid = null;
		return false;
	}
		var isHeadXmlNode = "<Item k='isHead' v='false'/>";
		while (obj && (obj.type != "msgObj"&&obj.type != "head")){
            obj = obj.parentNode;
			if(obj.type == "head"){
				isHeadXmlNode= "<Item k='isHead' v='true'/>";
			}
		}
		pStr += isHeadXmlNode;
	//if(msgId!="")
        window.external.RightClickMenu(pStr, span.innerHTML.length > 0,bRChickUrl, point.x, point.y);

        window.imgSrc = null;
        window.pid = null;

        return false;
    };
    document.onmousedown = function (e)
    {
        var event = e || window.event;
        window.mouseButton = event.button;
        if (!window.selMsgCtrlMousedown)
        {
            window.selObj = null;
            window.imgSrc = null;
            window.selMsgCtrl = null;
            window.pid = null;
        }
        window.selMsgCtrlMousedown = false;
    };
    document.onmouseup = function (e)
    {
        var event = e || window.event;
        window.mouseButton = event.button;
    };
    document.onmousemove = function (ev)
    {
        ev = ev || window.event;
        window.mouseButton = event.button;

        if (typeof window.pageYOffset != 'undefined')
        {
            point.x = window.pageXOffset;
            point.y = window.pageYOffset;
        }
        else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
        {
            point.x = document.documentElement.scrollLeft;
            point.y = document.documentElement.scrollTop;
        }
        else if (typeof document.body != 'undefined')
        {
            point.x = document.body.scrollLeft;
            point.y = document.body.scrollTop;
        }

        point.x += ev.clientX;
        point.y += ev.clientY;
    };
    document.body.oncopy = function (e)
    {
        var event = e || window.event;
        Fetion.Web.Chat.copy();
        event.returnValue = false;
    };
	document.getElementById("closeChatTip").onclick=function(e){
		document.getElementById("divChatTip").style.display="none";
	};
	//高红飞 2015年3月2日 开始 添加鼠标滚轮处理
	document.body.onmousewheel=function(e){
		e = window.event || e; 
		var delta = e.wheelDelta>0;
		var scrollBar = Fetion.Web.Chat.body.scrollBar;
		if(scrollBar.getScrollTop()==0&&delta){
			document.getElementById("morebtn").click();
		}
	}
	//高红飞 2015年3月2日 结束 添加鼠标滚轮处理
}

//Fetion.Web.Chat.newMsg('[{"type":"head","imgPortrait":"","nickname":"欧阳一峰","sid":"","time":"2014-02-24 11:29:45","msgType":"","msgid":""}]');

var p = "";
var pid = "";
var point = { x: 0, y: 0 };

window.fxBrowser = {
    setBg: function (src, posX, posY, bgcolor, position,layout)
    {
		layout=(!layout)?0:layout;
        bgPositionType = position;
        window.bgposOffsetX = posX;
        window.bgposOffsetY = posY - -1;
        setTimeout(function ()
        {
            var mainPage = document.body;
            mainPage.style.backgroundRepeat = (layout==0)?"no-repeat":"repeat";
            var lastWinWidth = document.documentElement.clientWidth;
            var lastWinHeight = document.documentElement.clientHeight;
            if (window.prevSrc != src)
            {
                if (position == "right")
                {
                    window.prevSrc = src;
                    prevPosX = posX;
                    prevPosY = posY;
                    var curWinWidth = lastWinWidth;
                    var curWinHeight = lastWinHeight;
                    xpos = curWinWidth - 675 + parseInt(bgposOffsetX);
                    ypos = bgposOffsetY;
                    mainPage.style.background = (layout==0)?("url(" + src + ") no-repeat top right"):("url(" + src + ") repeat top right");
                    mainPage.style.backgroundPositionX = xpos;
                    mainPage.style.backgroundPositionY = -ypos;
                    //mainPage.css({ "background-image": "url(" + src + ")", "background-position-x": xpos.toString() + "px", "background-position-y": -ypos + "px" });
                }
                else
                {
                    mainPage.style.backgroundImage = "url(" + src + ")";
                    mainPage.style.backgroundPositionX = -posX;
                    mainPage.style.backgroundPositionY = -posY;
                    //mainPage.css({ "background-image": "url(" + src + ")", "background-position-x": -posX + "px", "background-position-y": -posY + "px" });
                    window.prevSrc = src;
                    prevPosX = posX;
                    prevPosY = posY;
                }
                prevAlign = position;
            }
            if (prevPosX != posX || prevPosY != posY || position != prevAlign)
            {
                if (position == "right")
                {
                    prevPosX = posX;
                    prevPosY = posY;
                    var curWinWidth = lastWinWidth;
                    var curWinHeight = lastWinHeight;
                    xpos = curWinWidth - 673 + parseInt(bgposOffsetX);
                    ypos = bgposOffsetY;
                    mainPage.style.backgroundPositionX = xpos;
                    mainPage.style.backgroundPositionY = -ypos;
                    //mainPage.css({ "background-position-x": xpos.toString() + "px", "background-position-y": -ypos + "px" });
                }
                else
                {
                    mainPage.style.backgroundPositionX = -posX;
                    mainPage.style.backgroundPositionY = -posY;
                    //mainPage.css({ "background-position-x": -posX + "px", "background-position-y": -posY + "px" });
                    prevPosX = posX;
                    prevPosY = posY;
                }
                prevAlign = position;
            }
            if (bgcolor)
            {
                mainPage.style.backgroundColor = bgcolor;
                //mainPage.css({ "background-color": bgcolor });
                prevColor = bgcolor;
            }
        }, 10);
    },
    setBgOffset: function (offsetX, offsetY)
    {
        var mainPage = document.body;
        var lastWinWidth = document.documentElement.clientWidth;
        var lastWinHeight = document.documentElement.clientHeight;
        if (window.bgPositionType == "right")
        {
            bgposOffsetX = offsetX;
            bgposOffsetY = offsetY;
            var curWinWidth = lastWinWidth;
            var curWinHeight = lastWinHeight;

            prevPosX = offsetX;
            prevPosY = offsetY;
            xpos = curWinWidth - 673 + parseInt(bgposOffsetX);
            ypos = bgposOffsetY;
            mainPage.style.backgroundPositionX = xpos;
            mainPage.style.backgroundPositionY = -ypos;
            //mainPage.css({ "background-position-x": xpos.toString() + "px", "background-position-y": -ypos + "px" });
        }
    },
    ScrollToBottom: function ()
    {
        var scrollBar = Fetion.Web.Chat.body.scrollBar;
        scrollBar.isBottom = true;
        Fetion.Web.Chat.scroll();
    },
    cancelLink: function (linkID)
    {
        var as = document.getElementsByTagName("A");
        for (var i = 0; i < as.length; i++)
        {
            var link = as[i];
            if (link.linkid == linkID){
                link.href = "##";
                link.onclick = null;
                link.style.cursor = "point";
                link.style.color = "#777777";
                link.style.textDecoration = "none";
                //return;
            }
            
        }
    },
    InBubble: function (str)
    {
        //alert("InBubble");
        window.external.InBubble(str);
    },
    HasContent: function ()
    {
        window.external.HasContent(Fetion.Web.Chat.hasContent);
    },
    CanCopy: function (str)
    {
        window.external.CanCopy(str);
    },
    CopyImg: function ()
    {
        Fetion.Web.Chat.copy();
    },
    CopyRage: function ()
    {
        Fetion.Web.Chat.copy();
    },
    updateImage: function ()
    {
    },
    IsSingleObject: function (bool)
    {
        //alert("IsSingleObject");
        window.external.IsSingleObject(bool);
    },
    SelectCurrentBubble: function ()
    {
        if (window.selMsgCtrl)
        {
            var obj = selMsgCtrl;
            while (obj && obj.type != "msgObj")
                obj = obj.parentNode;
            obj = obj.childNodes[1];
            var range = document.body.createTextRange();
            range.moveToElementText(obj);
            range.select();
        }
    },
    DoCustomCopy: function ()
    {
        Fetion.Web.Chat.copy();
    },
    SelectAll: function ()
    {
        var range = document.body.createTextRange();
        var scrollBar = Fetion.Web.Chat.body.scrollBar;
        var top = scrollBar.getScrollTop();
        range.moveToElementText(window.chatBody);
        range.select();
        scrollBar.setScrollBar(top);
    },
    GetSelectedText: function ()
    {
        var rangeStr = document.selection.createRange().htmlText;
        var span = document.createElement("SPAN");
        span.innerHTML = rangeStr;

        var imgs = span.getElementsByTagName("IMG");
        for (var i = 0; i < imgs.length; i++)
        {
            var img = imgs[i];
            var parentNode = img.parentNode;
            var shortcut = img.getAttribute("shortcut");
            if (shortcut)
            {
                var tmp = document.createElement("SPAN");
                tmp.innerHTML = shortcut;
                //parentNode.replaceNode(tmp, img);
				img.insertAdjacentElement("afterEnd", tmp);
            }
            img.parentNode.removeChild(img);
            i--;
        }
        window.external.SetSelectedText(span.innerText);
    },
    GetObjectUrl: function ()
    {
        var rangeStr = document.selection.createRange().htmlText;
        var htmlstr = rangeStr.replace(/<\/?(DIV|FONT|P|TD|TABLE|SPAN|TBODY|TR)[^>]*>/gi, "").replaceAll('&nbsp;', '').Trim();

        var htmlItem = $(htmlstr);
        var isImg = htmlItem.is('IMG') && (htmlItem.length == 1 || (htmlItem.length == 2 && htmlItem.eq(1).attr('class') == "magnifier")) && htmlstr.Trim().substring(0, 4) == ('<IMG') && (htmlstr.charAt(htmlstr.length - 1) == ">");

        var urlStr = (isImg == true) ? $(htmlItem).attr("src").replace('fetionres:///', '') : '';

        if (isImg && htmlItem.length == 1)
        {
            urlStr = $(htmlItem).attr("src").replace('fetionres:///', '')
        } else if (isImg && htmlItem.length == 2)
        {
            urlStr = htmlItem.eq(0).attr("src").replace('fetionres:///', '')
        }
        urlStr = decodeURIComponent(urlStr.replace(/\+/g, " "));
        window.external.SetObjectUrl(urlStr);
    },
    ClearAll: function ()
    {
        var childNodes = Fetion.Web.Chat.body.childNodes;
        for (var i = 0; i < childNodes.length; i++)
        {
            var ctrl = childNodes[i];
            if (ctrl.clear == "false" || (ctrl.type && ctrl.type.toLowerCase() == "scrollbar"))
                continue;
            Fetion.Web.Chat.body.removeChild(ctrl);
            i--;
        }
        Fetion.Web.Chat.showHistory = false;
        Fetion.Web.Chat.newHistory("[]", window.hasMsg);
        Fetion.Web.Chat.hasContent = false;
        Fetion.Web.Chat.scroll();
        window.chatBody.onselectstart=function(e){return false;}
    },
	DeleteMsg: function(mid){
	    var ctrls = document.getElementById(mid);
	    ctrls.parentElement.removeChild(ctrls);
	},
	GoToMsgPlace: function(mid){
		var rect = document.getElementById(mid).getBoundingClientRect();
        if (rect.bottom - rect.top > document.documentElement.clientHeight)
            return;
        var scrollBar = Fetion.Web.Chat.body.scrollBar;
        if (scrollBar)
        {
			scrollBar.isBottom = false;
            var tValue = rect.top;
            var bValue = rect.bottom - document.documentElement.clientHeight;
            //if ((tValue < 0 || tValue < bValue)||(tValue > 0&&bValue <= 0)){
                scrollBar.setScrollBar(Fetion.Web.Chat.body.scrollTop + tValue);
            /*}else if (bValue > 0 && tValue > bValue){
                scrollBar.setScrollBar(Fetion.Web.Chat.body.scrollTop + bValue);
			}*/
        }

	},
	SetMsgTip:function(msg){
		var divChatTip = document.getElementById("divChatTip");
		if(!msg){
			divChatTip.style.display="none";
			return;
		}
		
		if(msg==null||msg==""){
			divChatTip.style.display="none";
			return;
		}
		
		var chatTip = document.getElementById("chatTip");
		divChatTip.style.display="";
		chatTip.innerHTML = msg;
	},
	tagMsgShowAction:function(msgId,status){
		var ww = document.body.clientWidth;
		var wh = document.body.clientHeight;
		if(status==1){
			msgDIV.innerHTML="<div class='sms-pop'><div class='sms-pop-t'></div><div class='sms-pop-c'><span class='tag-suc'></span>标记成功！</div><div class='sms-pop-b'></div></div>";
		}else{
			msgDIV.innerHTML="<div class='sms-pop'><div class='sms-pop-t'></div><div class='sms-pop-c'><span class='tag-fail'></span>标记失败！</div><div class='sms-pop-b'></div></div>";
		}
		msgDIV.style.display="";
		msgDIV.style.top=(wh/2-msgDIV.clientHeight/2)+"px";
		msgDIV.style.left=(ww/2-msgDIV.clientWidth/2)+"px";
		setTimeout(function () { msgDIV.style.display="none"; },2000);
	}
};