﻿function ToggleTag(obj) {
    var tag = $(obj.id + "_tag");
    var tagc = $(obj.id + "_tag_tag");
    if (!tagc) {
        tagc = CreateElement("div", { id: obj.id + "_tag_tag", className: 'taghide' });
        AddElement(tagc);
    }

    if (Element.hasClassName(tagc, "taghide")) {
        tagc.removeClassName("taghide");
        tagc.addClassName("tagshow");
        var l, t;
        t = obj.positionedOffset().top + "px";
        l = obj.positionedOffset().left + obj.getWidth() + "px";
        tagc.setStyle({ left: l, top: t });
        tagc.innerHTML = "";
        m = GetErrorMessage(tag.innerHTML);
        tagc.appendChild(m);
    } else {
        tagc.removeClassName("tagshow");
        tagc.addClassName("taghide");
    }
}
function BindTag() {
    var t = $$(".tag");
    t.each(function (i) {
        i.onmouseover = function () { ToggleTag(this); };
        i.onmouseout = function () { ToggleTag(this); };
    });
}
function DomLoaded(fun) {
    Event.observe(document, "dom:loaded", fun);
}
function DomLoad(fun) {
    Event.observe(window, "load", fun);
}
function GetErrorMessage(title) {
    var d = CreateElement("div", { className: "boxmessage" }, [
                CreateElement("div", { className: "topleft" },
                    CreateElement("div", { className: "topright" },
                        CreateElement("div", { className: "topcenter" })
                    )
                ),
                Object.isElement(title) ? CreateElement("div", { className: "center" }, title) : CreateElement("div", { className: "center", innerHTML: title }),
                CreateElement("div", { className: "bottomleft" },
                    CreateElement("div", { className: "bottomright" },
                        CreateElement("div", { className: "bottomcenter" })
                    )
                )
            ]);
    return d;
};
var Cookies = {
    morekey: "ChinaLoveMatch",
    moretime: 1000 * 3600 * 24 * 30,
    domain: "",
    path: "/",
    Check: function (k) {
        return !(k == "" || k.match(/[,; ]/));
    },
    Has: function (k) {
        return (Cookies.Get(k) != null);
    },
    Times: function (s, c) {
        return s.split(c).length - 1;
    },
    Get: function (k) {
        if (!Cookies.Check(k))
            return null;
        var arr = document.cookie.match(new RegExp("(^| )" + k + "=([^;]*)(;|$)"));
        return (arr == null) ? null : unescape(arr[2]);
    },
    Set: function (k, v, t) {
        if (!Cookies.Check(k))
            return;
        v = encodeURI(v);
        var expires = new Date();
        expires = new Date(expires.getTime() + t);
        document.cookie = k + "=" + v + ";expires =" + expires.toGMTString();
    },
    Clear: function (k) {
        if (!Cookies.Check(k))
            return;
        if (!Cookies.Has(k))
            return;
        Cookies.Set(k, '', -1);
    },
    ClearAll: function () {
        var cook = document.cookie.split(";");
        var ts;
        for (var i = 0, len = cook.length; i < len; i++) {
            ts = cook[i].split("=")[0].strip();
            Cookies.Clear(ts);
        }
    },
    More: {
        GetAll: function () {
            return Cookies.Get(Cookies.morekey);
        },
        Get: function (k) {
            var cook = Cookies.More.GetAll();
            if (cook == null)
                return null;
            var arr = cook.match(new RegExp("(^|\&)" + k + "=([^\&]*)(\&|$)"));
            return (arr == null) ? null : unescape(arr[2]);
        },
        Set: function (k, v) {
            if (!Cookies.Check(k))
                return;
            var kv = k + "=" + encodeURI(v);
            var s;
            var cook = Cookies.More.GetAll()
            var nowcook = Cookies.More.Get(k);
            if (nowcook != null) {
                s = cook.replace(k + "=" + nowcook, kv);
            }
            else {
                if (cook) {
                    var n = Cookies.Times(cook, "=");
                    if (n > 0)
                        s = cook + "&" + kv;
                    else
                        s = Cookies.key + "=" + cook + "&" + kv;
                }
                else
                    s = kv;
            }
            Cookies.Set(Cookies.morekey, s, Cookies.moretime);
        },
        Clear: function (k) {
            if (!Cookies.Check(k))
                return;
            var v = Cookies.More.Get(k);
            if (v) {
                var cook = Cookies.More.GetAll();
                var kv = k + "=" + encodeURI(v);
                if (cook.indexOf("&" + kv) > -1)
                    cook = cook.replace("&" + kv, "");
                else if (cook.indexOf(kv + "&") > -1)
                    cook = cook.replace(kv + "&", "");
                else
                    cook = '';
                if (cook.blank())
                    Cookies.Clear(Cookies.morekey);
                else
                    Cookies.Set(Cookies.morekey, cook, Cookies.moretime);
            }
        }
    }
}
//Window选中
var WindowFocus = {
    title: null,
    theTimeout: null,
    time: 500,
    isbind: false,
    nowtitle: null,
    Bind: function (t) {
        WindowFocus.isbind = true;
        if (!WindowFocus.title)
            WindowFocus.title = document.title;
        WindowFocus.Stop();
        WindowFocus.nowtitle = "　　" + t + " ";
        WindowFocus.Start();
        Event.observe(document, "mousemove", WindowFocus.Stop);
        Event.observe(document, "focus", WindowFocus.Stop);
    },
    Start: function () {
        WindowFocus.nowtitle = WindowFocus.nowtitle.substring(1, WindowFocus.nowtitle.length) + WindowFocus.nowtitle.substring(0, 1);
        document.title = WindowFocus.nowtitle;
        WindowFocus.theTimeout = setTimeout(WindowFocus.Start, WindowFocus.time);
    },
    Stop: function () {
        if (WindowFocus.isbind) {
            document.title = WindowFocus.title;
            if (WindowFocus.theTimeout)
                clearTimeout(WindowFocus.theTimeout);
            Event.stopObserving(document, "mousemove", WindowFocus.Stop);
            Event.stopObserving(document, "focus", WindowFocus.Stop);
        }
    }
};
function AddElement(element, f) {
    if (f)
        f.appendChild(element);
    else
        document.body.insertBefore(element, document.body.childNodes[0]);
};
//建立Element.
function CreateElement(elementName, options, node) {
    var element = document.createElement(elementName);
    for (attr in options)
        element[attr] = options[attr];
    if (node) {
        if (node.tagName) {
            element.appendChild(node);
            return element;
        }
        if (typeof node == 'object') { // array can hold nodes and text
            node.flatten().each(function (e) {
                if (typeof e == 'object')
                    element.appendChild(e)
                else if (Object.isString(e) || Object.isNumber(e))
                    element.appendChild(document.createTextNode(e));
            });
        } else if (Object.isString(node) || Object.isNumber(node))
            element.appendChild(document.createTextNode(node));
    }
    return element;
}
//--  关于Window.open的参数
//具体总结的各个属性参数如下：
//window = object.open([URL ][, name ][, features ][, replace]]]])
//URL：新窗口的URL地址
//name：新窗口的名称，可以为空
//featurse：属性控制字符串，在此控制窗口的各种属性，属性之间以逗号隔开。
//fullscreen=   { yes/no/1/0 } 是否全屏，默认no
//channelmode=  { yes/no/1/0 } 是否显示频道栏，默认no
//toolbar=      { yes/no/1/0 } 是否显示工具条，默认no
//location=     { yes/no/1/0 } 是否显示地址栏，默认no
//directories = { yes/no/1/0 } 是否显示转向按钮，默认no
//status=       { yes/no/1/0 } 是否显示窗口状态条，默认no
//menubar=      { yes/no/1/0 } 是否显示菜单，默认no
//scrollbars=   { yes/no/1/0 } 是否显示滚动条，默认yes
//resizable=    { yes/no/1/0 } 是否窗口可调整大小，默认no
//width=number  窗口宽度（像素单位）
//height=number 窗口高度（像素单位）
//top=number    窗口离屏幕顶部距离（像素单位）
//left=number   窗口离屏幕左边距离（像素单位 
//eg:window.open ('page.html', 'newwindow',options{width: 100}) 
function WindowOpen(url, windowname, options) {
    options = options || {};
    var s = "toolbar=0,resizable=1,status=1";
    for (o in options)
        s = s + "," + o + "=" + options[o];
    var pw = window.open(url, windowname, s);
    var b = false;
    if (null == pw || true == pw.close)
        b = false;
    else
        b = true;
    if (!b) {
        alert("Before you can chat you must adjust your browser to allow popups.\r\n(您的浏览器阻止了弹出窗口, 如果您希望正常聊天, 请同意弹出窗口.)");
    }
    return b;
}
function GetButton(t, hs, c) {
    hs = hs || {};
    hs.innerHTML = t;
    if (!hs.href)
        hs.href = "javascript: void(0)";
    var c = c || {};
    c.className = "tablebtn";
    c.onmouseover = function () { this.className = 'tablebtnover'; };
    c.onmouseout = function () { this.className = 'tablebtn'; };
    var d = CreateElement("table", c,
                CreateElement("tbody", {},
                    CreateElement("tr", {}, [
                        CreateElement("td", { className: "l" }),
                        CreateElement("td", { className: "c" },
                            CreateElement("a", hs)
                        ),
                        CreateElement("td", { className: "r" })
                    ])
                )
        );
    return d;
}
function GetInput(name, type, options) {
    var input;
    if (Prototype.Browser.IE) {
        input = document.createElement("<input type=\"" + type + "\" name=\"" + name + "\" >"); //ie
    } else {
        input = document.createElement("input");
        input.setAttribute("name", name);
        input.setAttribute("type", type);
    }
    for (attr in options) {
        input[attr] = options[attr];
    }
    return input;
}

//2009.9.18 power by kkbac
//eg: NewWindow.Bind();
//新浮动窗口.
var NewWindow = {
    middledivid: "newWindowMiddleDiv",
    windowid: "newWindow",
    windowtitleid: "newWindowTitle",
    windowtextid: "newWindowText",
    windowcontentid: "pwcontent",
    MiddleDiv: function (b, f) {
        var id = NewWindow.middledivid;
        if (!$(id)) {
            var div = CreateElement("div", { "id": id });
            div.ondblclick = f;
            AddElement(div);
        }
        if (b) {
            Element.show($(id));
            $(id).setStyle({
                position: "absolute",
                backgroundColor: "#000",
                top: "0px",
                left: "0px",
                filter: "alpha(opacity=80)",
                width: Math.max(document.body.scrollWidth, document.documentElement.scrollWidth) + "px",
                height: Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) + "px",
                opacity: 0.8,
                zIndex: 999
            });
        } else Element.hide($(id));
    },
    HideWindow: function () {
        NewWindow.Hide();
    },
    Hide: function () {
        Element.absolutize($(NewWindow.windowid));
        NewWindow.Bind(false);
        NewWindow.MiddleDiv(false);
    },
    Bind: function (b, options) {
        options = options || {};
        var profilewindowid = NewWindow.windowid;
        var profilewindowtid = NewWindow.windowtitleid;
        var profilewindowtxtid = NewWindow.windowtextid;
        var isnew = false;
        if (b) {
            var dcid = NewWindow.windowcontentid;
            if (!$(profilewindowid)) {
                var d = CreateElement("div", { id: profilewindowid }, [
                    CreateElement("div", { id: profilewindowtid, className: "top" },
                        CreateElement("table", {},
                            CreateElement("tbody", {},
                                CreateElement("tr", {}, [
                                    CreateElement("td", { className: "topL" }),
                                    CreateElement("td", { className: "topM" },
                                        CreateElement("h3", { id: profilewindowtxtid, innerHTML: options.title })
                                    ),
                                    options.isclosebutton != false ?
                                    CreateElement("td", { className: "topC", title: (pagelanguage.language == 0 ? "close" : "关闭"), onclick: NewWindow.Hide }, [
                                        CreateElement("span", { innerHTML: (pagelanguage.language == 0 ? "close" : "关闭") }),
                                        CreateElement("img", { src: "/images/icons/close.gif" })
                                    ]
                                    ) :
                                    CreateElement("td", { className: "topM" })
                                    ,
                                    CreateElement("td", { className: "topR" })
                                    ]
                                )
                            )
                        )
                    ),
                    CreateElement("div", { id: dcid, className: "container" }),
                    CreateElement("div", { className: "bottom" },
                        CreateElement("div", { className: "l" },
                            CreateElement("div", { className: "r" },
                                CreateElement("div", { className: "m" })
                            )
                        )
                    )
                    ]
                );

                if (options.width) Element.setStyle(d, { width: options.width + "px" });
                if (options.height) Element.setStyle(d, { height: options.height + "px" });

                AddElement(d);
            } else {
                Element.show($(profilewindowid));
                $(profilewindowtxtid).innerHTML = options.title;
                if (options.width) $(profilewindowid).setStyle({ width: options.width + "px" });
                if (options.height) $(profilewindowid).setStyle({ height: options.height + "px" });
                $(dcid).innerHTML = "";
            }
            if (options.content) $(dcid).appendChild(options.content);
            var top;
            if (options.top)
                top = document.viewport.getScrollOffsets().top + options.top + "px";
            else
                top = (document.viewport.getDimensions().height / 2 - Element.getHeight($(profilewindowid))) / 2 + document.viewport.getScrollOffsets().top + "px";
            var left = (document.viewport.getDimensions().width - Element.getWidth($(profilewindowid))) / 2 + document.viewport.getScrollOffsets().left + "px";
            Element.setStyle($(profilewindowid), { top: top, left: left });
            new MoveObject($(profilewindowid), { Handle: $(profilewindowtid), onMoveWithPage: (options.notmovewithpage ? false : true) });
        } else {
            if ($(profilewindowid)) Element.hide($(profilewindowid));
        }
    }
};
//2009.9.26 power by kkbac
//eg: new ScrollSlider('滚动条id','滚动条框id','内容id', { startValue: 1 });
//滚动条
var ScrollSlider = Class.create();
ScrollSlider.prototype = {
    initialize: function (handle, track, bd, options) {
        var slider = this;

        if (Object.isArray(handle)) {
            this.handles = handle.collect(function (e) { return $(e) });
        } else {
            this.handles = [$(handle)];
        }

        this.track = $(track);
        this.bd = $(bd);
        this.options = options || {};

        this.axis = this.options.axis || 'vertical';
        this.increment = this.options.increment || 1;
        this.step = parseInt(this.options.step || '1');
        this.range = this.options.range || $R(0, 1);

        this.value = 0; // assure backwards compat
        this.values = this.handles.map(function () { return 0 });
        this.spans = this.options.spans ? this.options.spans.map(function (s) { return $(s) }) : false;
        this.options.startSpan = $(this.options.startSpan || null);
        this.options.endSpan = $(this.options.endSpan || null);

        this.restricted = this.options.restricted || false;

        this.maximum = this.options.maximum || this.range.end;
        this.minimum = this.options.minimum || this.range.start;

        // Will be used to align the handle onto the track, if necessary
        this.alignX = parseInt(this.options.alignX || '0');
        this.alignY = parseInt(this.options.alignY || '0');

        this.trackLength = this.maximumOffset() - this.minimumOffset();

        this.handleLength = this.isVertical() ?
                Element.getHeight(this.handles[0]) : Element.getWidth(this.handles[0]);
        this.active = false;
        this.dragging = false;
        this.disabled = false;

        if (this.options.disabled) this.setDisabled();

        // Allowed values array
        this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
        if (this.allowedValues) {
            this.minimum = this.allowedValues.min();
            this.maximum = this.allowedValues.max();
        }

        this.eventMouseDown = this.startDrag.bindAsEventListener(this);
        this.eventMouseUp = this.endDrag.bindAsEventListener(this);
        this.eventMouseMove = this.update.bindAsEventListener(this);

        // Initialize handles in reverse (make sure first handle is active)
        this.handles.each(function (h, i) {
            i = slider.handles.length - 1 - i;
            slider.setValue(parseFloat(
            (Object.isArray(slider.options.sliderValue) ?
              slider.options.sliderValue[i] : slider.options.sliderValue) ||
             slider.range.start), i);
            h.makePositioned().observe("mousedown", slider.eventMouseDown);
        });

        this.track.observe("mousedown", this.eventMouseDown);
        document.observe("mouseup", this.eventMouseUp);
        document.observe("mousemove", this.eventMouseMove);

        this.initialized = true;

        if (this.options.startValue) this.setValue(this.options.startValue);
    },
    dispose: function () {
        var slider = this;
        Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
        Event.stopObserving(document, "mouseup", this.eventMouseUp);
        Event.stopObserving(document, "mousemove", this.eventMouseMove);
        this.handles.each(function (h) {
            Event.stopObserving(h, "mousedown", slider.eventMouseDown);
        });
    },
    setDisabled: function () {
        this.disabled = true;
    },
    setEnabled: function () {
        this.disabled = false;
    },
    getNearestValue: function (value) {
        if (this.allowedValues) {
            if (value >= this.allowedValues.max()) return (this.allowedValues.max());
            if (value <= this.allowedValues.min()) return (this.allowedValues.min());

            var offset = Math.abs(this.allowedValues[0] - value);
            var newValue = this.allowedValues[0];
            this.allowedValues.each(function (v) {
                var currentOffset = Math.abs(v - value);
                if (currentOffset <= offset) {
                    newValue = v;
                    offset = currentOffset;
                }
            });
            return newValue;
        }
        if (value > this.range.end) return this.range.end;
        if (value < this.range.start) return this.range.start;
        return value;
    },
    setValue: function (sliderValue, handleIdx) {
        if (!this.active) {
            this.activeHandleIdx = handleIdx || 0;
            this.activeHandle = this.handles[this.activeHandleIdx];
            this.updateStyles();
        }
        handleIdx = handleIdx || this.activeHandleIdx || 0;
        if (this.initialized && this.restricted) {
            if ((handleIdx > 0) && (sliderValue < this.values[handleIdx - 1]))
                sliderValue = this.values[handleIdx - 1];
            if ((handleIdx < (this.handles.length - 1)) && (sliderValue > this.values[handleIdx + 1]))
                sliderValue = this.values[handleIdx + 1];
        }
        sliderValue = this.getNearestValue(sliderValue);
        this.values[handleIdx] = sliderValue;
        this.value = this.values[0]; // assure backwards compat

        this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] = this.translateToPx(sliderValue);

        this.drawSpans();
        if (!this.dragging || !this.event) this.updateFinished();
    },
    setValueBy: function (delta, handleIdx) {
        this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
            handleIdx || this.activeHandleIdx || 0);
    },
    translateToPx: function (value) {
        return Math.round(
            ((this.trackLength - this.handleLength) / (this.range.end - this.range.start)) *
            (value - this.range.start)) + "px";
    },
    translateToValue: function (offset) {
        return ((offset / (this.trackLength - this.handleLength) *
            (this.range.end - this.range.start)) + this.range.start);
    },
    getRange: function (range) {
        var v = this.values.sortBy(Prototype.K);
        range = range || 0;
        return $R(v[range], v[range + 1]);
    },
    minimumOffset: function () {
        return (this.isVertical() ? this.alignY : this.alignX);
    },
    maximumOffset: function () {
        return (this.isVertical() ? Element.getHeight(this.track) - this.alignY :
            Element.getWidth(this.track) - this.alignX);
    },
    isVertical: function () {
        return (this.axis == 'vertical');
    },
    drawSpans: function () {
        var slider = this;
        if (this.spans)
            $R(0, this.spans.length - 1).each(function (r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
        if (this.options.startSpan)
            this.setSpan(this.options.startSpan, $R(0, this.values.length > 1 ? this.getRange(0).min() : this.value));
        if (this.options.endSpan)
            this.setSpan(this.options.endSpan, $R(this.values.length > 1 ? this.getRange(this.spans.length - 1).max() : this.value, this.maximum));
    },
    setSpan: function (span, range) {
        if (this.isVertical()) {
            span.style.top = this.translateToPx(range.start);
            span.style.height = this.translateToPx(range.end - range.start + this.range.start);
        } else {
            span.style.left = this.translateToPx(range.start);
            span.style.width = this.translateToPx(range.end - range.start + this.range.start);
        }
    },
    updateStyles: function () {
        this.handles.each(function (h) { Element.removeClassName(h, 'selected') });
        Element.addClassName(this.activeHandle, 'selected');
    },
    startDrag: function (event) {
        if (Event.isLeftClick(event)) {
            if (!this.disabled) {
                this.active = true;

                var handle = Event.element(event);
                var pointer = [Event.pointerX(event), Event.pointerY(event)];
                var track = handle;
                if (track == this.track) {
                    var offsets = Element.cumulativeOffset(this.track);
                    this.event = event;
                    this.setValue(this.translateToValue(
                        (this.isVertical() ? pointer[1] - offsets[1] : pointer[0] - offsets[0]) - (this.handleLength / 2)
                    ));
                    var offsets = Element.cumulativeOffset(this.activeHandle);
                    this.offsetX = (pointer[0] - offsets[0]);
                    this.offsetY = (pointer[1] - offsets[1]);
                } else {
                    // find the handle (prevents issues with Safari)
                    while ((this.handles.indexOf(handle) == -1) && handle.parentNode)
                        handle = handle.parentNode;

                    if (this.handles.indexOf(handle) != -1) {
                        this.activeHandle = handle;
                        this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
                        this.updateStyles();

                        var offsets = Element.cumulativeOffset(this.activeHandle);
                        this.offsetX = (pointer[0] - offsets[0]);
                        this.offsetY = (pointer[1] - offsets[1]);
                    }
                }
            }
            Event.stop(event);
        }
    },
    update: function (event) {
        if (this.active) {
            if (!this.dragging) this.dragging = true;
            this.draw(event);
            if (Prototype.Browser.WebKit) window.scrollBy(0, 0);
            Event.stop(event);
        }
    },
    draw: function (event) {
        var pointer = [Event.pointerX(event), Event.pointerY(event)];
        var offsets = Element.cumulativeOffset(this.track);
        pointer[0] -= this.offsetX + offsets[0];
        pointer[1] -= this.offsetY + offsets[1];
        this.event = event;
        this.setValue(this.translateToValue(this.isVertical() ? pointer[1] : pointer[0]));
        this.scrollVertical(this.values.length > 1 ? this.values : this.value);
    },
    endDrag: function (event) {
        if (this.active && this.dragging) {
            this.finishDrag(event, true);
            Event.stop(event);
        }
        this.active = false;
        this.dragging = false;
    },
    finishDrag: function (event, success) {
        this.active = false;
        this.dragging = false;
        this.updateFinished();
    },
    updateFinished: function () {
        this.scrollVertical(this.values.length > 1 ? this.values : this.value);
        this.event = null;
    },
    scrollVertical: function (value) {
        this.bd.scrollTop = Math.round(value * (this.bd.scrollHeight - this.bd.offsetHeight));
    }
};

//2009.8.15 power by kkbac
//eg: new MoveObject($("aa"), { Handle: $("ff"),onMoveWithPage:true });
//拖放程序
var MoveObject = Class.create();
MoveObject.prototype = {
    //拖放对象
    initialize: function (drag, options) {
        this.thesettimeout = null;
        this.MoveObject = $(drag); //拖放对象
        this._x = this._y = 0; //记录鼠标相对拖放对象的位置
        this._dx = Element.positionedOffset(this.MoveObject).left - document.viewport.getScrollOffsets().left;
        this._dy = Element.positionedOffset(this.MoveObject).top - document.viewport.getScrollOffsets().top;
        this.Movebind = this.Move.bindAsEventListener(this);
        this.Upbind = this.Stop.bindAsEventListener(this);
        this.SetOptions(options);
        this.onMoveWithPage = this.options.onMoveWithPage;
        this.onStart = this.options.onStart;
        this.onMove = this.options.onMove;
        this.onStop = this.options.onStop;
        this._Handle = $(this.options.Handle) || this.MoveObject;
        this.MoveObject.absolutize();
        Event.observe(this._Handle, "mousedown", this.Start.bindAsEventListener(this), false);
        this.BindMoveWithPage();
    },
    //跟随页面滚动.
    BindMoveWithPage: function () {
        if (this.onMoveWithPage) {
            Event.observe(window, 'scroll', this.MoveWithPage.bindAsEventListener(this), false);
        }
        else
            clearTimeout(this.theSettimeout);
    },
    MoveWithPage: function () {
        if (this.MoveObject && Element.visible(this.MoveObject)) {
            var t = document.viewport.getScrollOffsets().top + this._dy + "px";
            var l = document.viewport.getScrollOffsets().left + this._dx + "px";
            Element.setStyle(this.MoveObject, { top: t, left: l });
        }
    },
    //设置默认属性
    SetOptions: function (options) {
        this.options = {//默认值
            Handle: "", //设置触发对象（不设置则使用拖放对象）
            onMoveWithPage: true,
            onStart: function () { }, //开始移动时执行
            onMove: function () { }, //移动时执行
            onStop: function () { } //结束移动时执行
        };
        Object.extend(this.options, options || {});
    },
    //准备拖动
    Start: function (e) {
        e = e || window.event;
        this._x = Event.pointerX(e) - Element.positionedOffset(this.MoveObject).left;
        this._y = Event.pointerY(e) - Element.positionedOffset(this.MoveObject).top;
        Event.observe(document, 'mousemove', this.Movebind, false);
        Event.observe(document, 'mouseup', this.Upbind, false);
        //附加程序
        this.onStart();
    },
    //拖动
    Move: function (e) {
        e = e || window.event;
        //清除选择
        window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
        var l, t, s, m;
        s = document.viewport.getScrollOffsets().top;
        m = document.viewport.getScrollOffsets().left;
        l = Event.pointerX(e) - this._x;
        t = Event.pointerY(e) - this._y;
        l = Math.max(l, m);
        t = Math.max(t, s);
        l = Math.min(l, (document.viewport.getDimensions().width - Element.getWidth(this.MoveObject)) + m);
        t = Math.min(t, (document.viewport.getDimensions().height - Element.getHeight(this.MoveObject)) + s);
        this.MoveObject.setStyle({ left: l + "px", top: t + "px" });
        //附加程序
        this.onMove();
    },
    //停止拖动
    Stop: function () {
        this._dx = Element.positionedOffset(this.MoveObject).left - document.viewport.getScrollOffsets().left;
        this._dy = Element.positionedOffset(this.MoveObject).top - document.viewport.getScrollOffsets().top;
        //移除事件
        Event.stopObserving(document, 'mousemove', this.Movebind, false);
        Event.stopObserving(document, 'mouseup', this.Upbind, false);
        //附加程序
        this.onStop();
    }
};
var tooltip = {
    b: function (objid) {
        var o = $$(objid);
        for (var i = 0, len = o.length; i < len; i++) { 
            o[i].onmousemove = function (event) { tooltip.mm(event, this); }
            o[i].onmouseout = function () { tooltip.mo(this); }
        }
    },
    mm: function (event, t) {
        event = event || window.event;
        var area = Element.readAttribute(t, "area");
        var img = Element.getElementsBySelector(t, 'img')[0];
        var tsize = Element.cumulativeOffset(img);
        var o = Element.getElementsBySelector(t, 'span');
        var x = 0, y = 0;
        if (area == "left") {
            x = tsize.left - 3 - Element.getWidth(o[0]);
            y = tsize.top;
        } else if (area == "right") {
            x = tsize.left + 3 + Element.getWidth(t);
            y = tsize.top;
        } else {
            x = Event.pointerX(event) + 12;
            y = Event.pointerY(event) + 3;
        }
        Element.setStyle(o[0], { left: x + "px", top: y + "px" });
    },
    mo: function (t) {
        var o = Element.getElementsBySelector(t, 'span');
        Element.setStyle(o[0], { left: "-1000px", top: "-1000px" });
    }
}

