//客服qq
var tips; var theTop = 100/*这是默认高度,越大越往下*/; var old = theTop;

function initFloatTips() {

    tips = document.getElementById('floatTools');

    moveTips();
};

function moveTips() {

    var tt = 50;

    if (window.innerHeight) {

        pos = window.pageYOffset

    }

    else if (document.documentElement && document.documentElement.scrollTop) {

        pos = document.documentElement.scrollTop

    }

    else if (document.body) {

        pos = document.body.scrollTop;

    }

    pos = pos - tips.offsetTop + theTop;

    pos = tips.offsetTop + pos / 10;



    if (pos < theTop) pos = theTop;

    if (pos != old) {

        tips.style.top = pos + "px";

        tt = 10;

        //alert(tips.style.top);

    }



    old = pos;

    setTimeout(moveTips, tt);

}


//KefuQQMSN.style.display="none";

initFloatTips();


function kf_setCookie(name, value, exp, path, domain) {
    var nv = name + "=" + escape(value) + ";";

    var d = null;
    if (typeof (exp) == "object") {
        d = exp;
    }
    else if (typeof (exp) == "number") {
        d = new Date();
        d = new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes() + exp, d.getSeconds(), d.getMilliseconds());
    }

    if (d) {
        nv += "expires=" + d.toGMTString() + ";";
    }

    if (!path) {
        nv += "path=/;";
    }
    else if (typeof (path) == "string" && path != "") {
        nv += "path=" + path + ";";
    }

    if (!domain && typeof (VS_COOKIEDM) != "undefined") {
        domain = VS_COOKIEDM;
    }

    if (typeof (domain) == "string" && domain != "") {
        nv += "domain=" + domain + ";";
    }

    document.cookie = nv;
}

function kf_getCookie(name) {
    var value = "";
    var cookies = document.cookie.split("; ");
    var nv;
    var i;

    for (i = 0; i < cookies.length; i++) {
        nv = cookies[i].split("=");

        if (nv && nv.length >= 2 && name == kf_rTrim(kf_lTrim(nv[0]))) {
            value = unescape(nv[1]);
        }
    }

    return value;
}

function kf_sleepShow() {
    kf_setCookie('hasshown', 0, '', '/', wpadomain);
    var position_1 = (document.documentElement.clientWidth - 381) / 2 + document.body.scrollLeft;
    var position_2 = (document.documentElement.clientHeight - 159) / 2 + document.body.scrollTop;
    popupDivHtml = '<div class="zixun0704" id="kfpopupDiv" onmousedown="MyMove.Move(\'kfpopupDiv\',event,1);"  style="z-index:10000; position: absolute; top: ' + position_2 + 'px; left: ' + position_1 + 'px;color:#000;font-size: 12px;cursor:move;height: 159px;width: 381px;">';
    popupDivHtml += kf_getPopupDivHtml(kfguin, ws, companyname, welcomeword, wpadomain);
    popupDivHtml += '</div>';
    if (document.body.insertAdjacentHTML) {
        document.body.insertAdjacentHTML("beforeEnd", popupDivHtml);
    }
    else {
        $("#footer").before(popupDivHtml);
        //		sWhere="beforeEnd";
        //		sHTML=popupDivHtml;
        //		alert(HTMLElement.prototype.insertAdjacentHTML);
        //		HTMLElement.prototype.insertAdjacentHTML = function(sWhere, sHTML){
        //            var df = null,r = this.ownerDocument.createRange();
        //            switch (String(sWhere).toLowerCase()) {
        //                case "beforebegin":
        //                    r.setStartBefore(this);
        //                    df = r.createContextualFragment(sHTML);
        //                    this.parentNode.insertBefore(df, this);
        //                    break;
        //                case "afterbegin":
        //                    r.selectNodeContents(this);
        //                    r.collapse(true);
        //                    df = r.createContextualFragment(sHTML);
        //                    this.insertBefore(df, this.firstChild);
        //                    break;
        //                case "beforeend":				
        //                    r.selectNodeContents(this);
        //                    r.collapse(false);
        //                    df = r.createContextualFragment(sHTML);
        //                    this.appendChild(df);
        //                    break;
        //                case "afterend":
        //                    r.setStartAfter(this);
        //                    df = r.createContextualFragment(sHTML);
        //                    this.parentNode.insertBefore(df, this.nextSibling);
        //                    break;
        //            }
        //        };
    }
}

function kf_dealErrors() {
    kf_hide();
    return true;
}

function kf_lTrim(str) {
    while (str.charAt(0) == " ") {
        str = str.slice(1);
    }
    return str;
}

function kf_rTrim(str) {
    var iLength = str.length;
    while (str.charAt(iLength - 1) == " ") {
        str = str.slice(0, iLength - 1);
        iLength--;
    }
    return str;
}

window.onerror = kf_dealErrors;
var MyMove = new Tong_MoveDiv();

function Tong_MoveDiv() {
    this.Move = function (Id, Evt, T) {
        if (Id == "") {
            return;
        }
        var o = document.getElementById(Id);
        if (!o) {
            return;
        }
        evt = Evt ? Evt : window.event;
        o.style.position = "absolute";
        o.style.zIndex = 9999;
        var obj = evt.srcElement ? evt.srcElement : evt.target;
        var w = o.offsetWidth;
        var h = o.offsetHeight;
        var l = o.offsetLeft;
        var t = o.offsetTop;
        var div = document.createElement("DIV");
        document.body.appendChild(div);
        div.style.cssText = "filter:alpha(Opacity=10,style=0);opacity:0.2;width:" + w + "px;height:" + h + "px;top:" + t + "px;left:" + l + "px;position:absolute;background:#000";
        div.setAttribute("id", Id + "temp");
        this.Move_OnlyMove(Id, evt, T);
    }

    this.Move_OnlyMove = function (Id, Evt, T) {
        var o = document.getElementById(Id + "temp");
        if (!o) {
            return;
        }
        evt = Evt ? Evt : window.event;
        var relLeft = evt.clientX - o.offsetLeft;
        var relTop = evt.clientY - o.offsetTop;
        if (!window.captureEvents) {
            o.setCapture();
        }
        else {
            window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
        }

        document.onmousemove = function (e) {
            if (!o) {
                return;
            }
            e = e ? e : window.event;

            var bh = Math.max(document.body.scrollHeight, document.body.clientHeight, document.body.offsetHeight,
	        						document.documentElement.scrollHeight, document.documentElement.clientHeight, document.documentElement.offsetHeight);
            var bw = Math.max(document.body.scrollWidth, document.body.clientWidth, document.body.offsetWidth,
	        						document.documentElement.scrollWidth, document.documentElement.clientWidth, document.documentElement.offsetWidth);
            var sbw = 0;
            if (document.body.scrollWidth < bw)
                sbw = document.body.scrollWidth;
            if (document.body.clientWidth < bw && sbw < document.body.clientWidth)
                sbw = document.body.clientWidth;
            if (document.body.offsetWidth < bw && sbw < document.body.offsetWidth)
                sbw = document.body.offsetWidth;
            if (document.documentElement.scrollWidth < bw && sbw < document.documentElement.scrollWidth)
                sbw = document.documentElement.scrollWidth;
            if (document.documentElement.clientWidth < bw && sbw < document.documentElement.clientWidth)
                sbw = document.documentElement.clientWidth;
            if (document.documentElement.offsetWidth < bw && sbw < document.documentElement.offsetWidth)
                sbw = document.documentElement.offsetWidth;

            if (e.clientX - relLeft <= 0) {
                o.style.left = 0 + "px";
            }
            else if (e.clientX - relLeft >= bw - o.offsetWidth - 2) {
                o.style.left = (sbw - o.offsetWidth - 2) + "px";
            }
            else {
                o.style.left = e.clientX - relLeft + "px";
            }
            if (e.clientY - relTop <= 1) {
                o.style.top = 1 + "px";
            }
            else if (e.clientY - relTop >= bh - o.offsetHeight - 30) {
                o.style.top = (bh - o.offsetHeight) + "px";
            }
            else {
                o.style.top = e.clientY - relTop + "px";
            }
        }

        document.onmouseup = function () {
            if (!o) return;

            if (!window.captureEvents) {
                o.releaseCapture();
            }
            else {
                window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
            }

            var o1 = document.getElementById(Id);
            if (!o1) {
                return;
            }
            var l0 = o.offsetLeft;
            var t0 = o.offsetTop;
            var l = o1.offsetLeft;
            var t = o1.offsetTop;

            //alert(l0 + " " +  t0 +" "+ l +" "+t);     

            MyMove.Move_e(Id, l0, t0, l, t, T);
            document.body.removeChild(o);
            o = null;
        }
    }


    this.Move_e = function (Id, l0, t0, l, t, T) {
        if (typeof (window["ct" + Id]) != "undefined") {
            clearTimeout(window["ct" + Id]);
        }

        var o = document.getElementById(Id);
        if (!o) return;
        var sl = st = 8;
        var s_l = Math.abs(l0 - l);
        var s_t = Math.abs(t0 - t);
        if (s_l - s_t > 0) {
            if (s_t) {
                sl = Math.round(s_l / s_t) > 8 ? 8 : Math.round(s_l / s_t) * 6;
            }

            else {
                sl = 0;
            }
        }
        else {
            if (s_l) {
                st = Math.round(s_t / s_l) > 8 ? 8 : Math.round(s_t / s_l) * 6;
            }
            else {
                st = 0;
            }
        }

        if (l0 - l < 0) {
            sl *= -1;
        }
        if (t0 - t < 0) {
            st *= -1;
        }
        if (Math.abs(l + sl - l0) < 52 && sl) {
            sl = sl > 0 ? 2 : -2;
        }
        if (Math.abs(t + st - t0) < 52 && st) {
            st = st > 0 ? 2 : -2;
        }
        if (Math.abs(l + sl - l0) < 16 && sl) {
            sl = sl > 0 ? 1 : -1;
        }
        if (Math.abs(t + st - t0) < 16 && st) {
            st = st > 0 ? 1 : -1;
        }
        if (s_l == 0 && s_t == 0) {
            return;
        }
        if (T) {
            o.style.left = l0 + "px";
            o.style.top = t0 + "px";
            return;
        }
        else {
            if (Math.abs(l + sl - l0) < 2) {
                o.style.left = l0 + "px";
            }
            else {
                o.style.left = l + sl + "px";
            }
            if (Math.abs(t + st - t0) < 2) {
                o.style.top = t0 + "px";
            }
            else {
                o.style.top = t + st + "px";
            }

            window["ct" + Id] = window.setTimeout("MyMove.Move_e('" + Id + "', " + l0 + " , " + t0 + ", " + (l + sl) + ", " + (t + st) + "," + T + ")", 1);
        }
    }
}

function wpa_count() {
    var body = document.getElementsByTagName('body').item(0);
    var img = document.createElement('img');
    var now = new Date();
    img.src = "http://" + wpadomain + ".qq.com/cgi/wpac?kfguin=" + kfguin + "&ext=0" + "&time=" + now.getTime() + "ip=172.23.30.15&";
    img.style.display = "none";
    body.appendChild(img);
}
