void function($) {
    $.fn.tab = function(obj) {
        var a = this.children().tab_blur();
        var c = $(obj.cnt).hide();
        var k = obj.cur || 0,
        n = a.length;
        var f = obj.onChange;
        $(a[k]).tab_focus();
        $(c[k]).show();
        for (var i = 0; i < n; i++) $(a[i]).click(Go(i));
        return {
            go: go,
            cur: function() {
                return k;
            }
        };
        function go(i) {
            if (k > -1) {
                $(a[k]).tab_blur();
                $(c[k]).hide();
            }
            $(a[i]).tab_focus();
            $(c[i]).show();
            k = i;
            if (f) f(i);
        }
        function Go(i) {
            return function() {
                if (k != i) go(i);
                return false;
            };
        }
    };
    $.fn.tab_blur = function() {
        return this.attr('class', '');
    };
    $.fn.tab_focus = function() {
        return this.attr('class', 'app_bt_sc');
    };
} (jQuery);
function $id(s) {
    return document.getElementById(s);
}
function inArray(a, v) {
    var i = a.length;
    while (i--) if (a[i] === v) return i;
    return - 1;
}
function toArray(list) {
    var a = [],
    len = list.length;
    for (var i = 0; i < len; i++) a[i] = list[i];
    return a;
}
var isLogin;
var needLogin;
if (self != parent) {
    isLogin = parent.J.isLogin;
    needLogin = function() {
        parent.showLoginWindow('请先登录再进行操作:');
    };
} else {
    isLogin = true;
    needLogin = function() {
        alert('请先登录');
    };
}
function updateHeight() {
    if (self != parent) getIns('tools').__updateHeight(true);
}
function hasClass(el, s) {
    return (' ' + el.className + ' ').indexOf(' ' + s + ' ') > -1;
}
function addClass(el, s) {
    if (!hasClass(el, s)) el.className += ' ' + s;
}
function removeClass(el, s) {
    var s = (' ' + el.className + ' ').replace(' ' + s + ' ', ' ');
    if (/\S/.test(s)) s = s.match(/\S+/g).join(' ');
    else s = '';
    el.className = s;
}
function msOver() {
    addClass(this, 'hover');
}
function msOut() {
    removeClass(this, 'hover');
}
var Tip = function() {
    var div;
    var t = 0,
    th = 0;
    function show(s) {
        clearTimeout(th);
        clearInterval(t);
        div.innerHTML = s;
        div.style.opacity = 1;
        div.style.filter = 'alpha(opacity=100)';
        div.style.display = 'block';
        th = setTimeout(hide, 1000);
    }
    var n = 100,
    v = 10,
    a = 2;
    function _hide() {
        n -= v;
        if (n <= 0) {
            clearInterval(t);
            div.style.display = 'none';
            return;
        }
        div.style.opacity = n / 100;
        div.style.filter = 'alpha(opacity=' + n + ')';
        v += a;
    }
    function hide() {
        n = 100;
        v = 1;
        t = setInterval(_hide, 50);
    }
    function init() {
        if (!div) div = $id('ts');
    }
    return {
        show: show,
        hide: hide,
        init: init
    };
} ();
var spanDel = function() {
    var sp = document.createElement('span');
    sp.title = '从我的工具箱中删除';
    sp.className = 'tool-del';
    return sp;
} ();
var ie6 = navigator.userAgent.indexOf('MSIE 6') > -1;
function toMyTool(li) {
    var l2 = li.cloneNode(true),
    d;
    l2.id = 'my-' + li.id;
    if (ie6 && (d = l2.getElementsByTagName('div')[0])) {
        msOut.call(d);
        d.onmouseover = msOver;
        d.onmouseout = msOut;
    }
    var a = l2.getElementsByTagName('span');
    var sp = a[a.length - 2];
    sp.innerHTML = '<span class=tool-move title="移动"></span>';
    return l2;
}
function findUp(o) {
    while (o = o.parentNode) if (o.className == 'div') return o;
    return null;
}
function tipInput(o, s) {
    o.onfocus = function() {
        if (this.value == s) this.value = '';
    };
    o.onblur = function() {
        if (!this.value) this.value = s;
    };
    o.onblur();
}
function getOffset(el) {
    var T = 0,
    L = 0;
    do {
        T += el.offsetTop;
        L += el.offsetLeft;
    } while (( el = el . offsetParent ).id != 'main');
    return {
        top: T,
        left: L
    };
}
var stimer = 0;
function showSpecial(o) {
    clearTimeout(stimer);
    o = o.form;
    addClass(o.getElementsByTagName('div')[0], 'focus');
    var d = o.parentNode;
    var s = d.id;
    var a = d.parentNode.childNodes;
    for (var i = 0,
    j = 0; a[j]; j++) {
        if (a[j].nodeType != 1) continue;
        if (a[j] == d) break;
        i++;
    }
    var top = (i / 3 | 0) * 68 + o.offsetHeight + 88;
    var left = (i % 3) * 258 + 11;
    o = o.getElementsByTagName('p')[0];
    o.style.display = 'block';
    o.style.top = top + 'px';
    o.style.left = left + 'px';
}
function hideSpecial(o) {
    o = o.form;
    removeClass(o.getElementsByTagName('div')[0], 'focus');
    o.getElementsByTagName('p')[0].style.display = 'none';
}
function showSpecial2(o) {
    clearTimeout(stimer);
    o = o.form;
    addClass(o.getElementsByTagName('div')[0], 'focus');
    o.getElementsByTagName('p')[0].style.display = 'block';
}
function hideSpecial2(o) {
    o = o.form;
    removeClass(o.getElementsByTagName('div')[0], 'focus');
    o.getElementsByTagName('p')[0].style.display = 'none';
}
hideSpecial = function(f) {
    return function(o) {
        stimer = setTimeout(function() {
            f(o);
        },
        50);
    };
} (hideSpecial);
hideSpecial2 = function(f) {
    return function(o) {
        stimer = setTimeout(function() {
            f(o);
        },
        50);
    };
} (hideSpecial2);
function date2str(date, pad) {
    var s = date.getFullYear();
    s += '-' + (date.getMonth() + 1);
    s += '-' + date.getDate();
    return pad ? s.replace(/\d+/g,
    function(a) {
        return a.length % 2 ? '0' + a: a;
    }) : s;
}
function loginClick() {
    parent.showLoginWindow();
    return false;
}
var dragSave = isLogin ?
function() {
    var T = getIns('tools');
    T.busy = true;
    T.__cfg.list = s_cfg;
    T.__simpleSave(function(e) {
        T.busy = false;
        if (e == 1) {} else {}
    });
}: function() {
    setCookie('cfglist', s_cfg, 30);
};
var s_cfg = 'rc-0,rc-1,rc-2,kj-0,rc-3,rc-4,rc-5,rc-6,rc-7,ms-0,ms-3,rc-11,rc-8,ms-1,kj-2,rc-9,rc-10,kj-1';
var s_cfg2 = 'rc-0,rc-1,rc-2,kj-0,rc-3,rc-4,rc-29';
function cfg_sort(a) {
    var b = [];
    var i = a.length;
    while (i--) if (s_cfg2.indexOf(a[i]) != -1) b.push(a.splice(i, 1)[0]);
    b.sort(function(a, b) {
        return s_cfg2.indexOf(a) - s_cfg2.indexOf(b);
    });
    a.unshift.apply(a, b);
    return a;
}
function msg(s) {
    Tip.show(s);
}
function clearBoth() {
    var d = document.createElement('div');
    d.style.clear = 'both';
    return d;
}
var startMove = function() {
    var startX;
    var startY;
    var deltaX;
    var deltaY;
    var betaX;
    var betaY;
    var obj;
    var db = document.body;
    var m0 = $id('main0');
    var pos, pos0;
    var posX, posY;
    var cfga;
    var rows;
    var sk0 = document.createElement('div');
    sk0.id = 'sk';
    sk0.className = 'div';
    var sk;
    var save = self == parent ?
    function() {
        alert(s_cfg);
    }: dragSave;
    function move(e) {
        if (!e) e = window.event;
        var x = e.clientX;
        var y = e.clientY;
        obj.style.top = y + deltaY + 'px';
        obj.style.left = x + deltaX + 'px';
        var cx = x + betaX;
        var cy = y + betaY;
        posX = Math.ceil((cx - 5) / 258);
        posY = Math.ceil((cy - 6 - 80) / 68);
        if (posX > 0 && posY > 0 && posX <= 3 && posY <= rows) {
            var t = posX + (posY - 1) * 3 - 1;
            if (t != pos && t < cfga.length) {
                var sb = t < pos ? m0.childNodes[t] : m0.childNodes[t].nextSibling;
                m0.insertBefore(sk, sb);
                pos = t;
            }
        }
    }
    function up(e) {
        if (obj.removeEventListener) {
            document.removeEventListener('mousemove', move, true);
            document.removeEventListener('mouseup', up, true);
        } else {
            obj.detachEvent('onmousemove', move);
            obj.detachEvent('onmouseup', up);
            obj.detachEvent('onlosecapture', up);
            obj.releaseCapture();
        }
        obj.style.position = 'static';
        if ('styleFloat' in obj.style) obj.style.styleFloat = 'left';
        else obj.style.cssFloat = 'left';
        obj.style.top = 'auto';
        obj.style.left = 'auto';
        m0.replaceChild(obj, sk);
        if (pos != pos0) {
            var s = '';
            var a = m0.childNodes;
            for (var i = 0; i < a.length - 1; i++) {
                if (i) s += ',';
                s += a[i].id.substr(3);
            }
            s_cfg = s;
            save();
        }
    }
    function _move(e) {
        if (!e) e = window.event;
        var x = e.clientX;
        var y = e.clientY;
        var _x, _y;
        if (Math.abs(x - startX) > 3 || Math.abs(y - startY) > 3) {
            _up();
            var s = obj.id;
            var a = cfga = stoa(s_cfg);
            rows = Math.ceil(a.length / 3);
            for (var i = 0; i < a.length; i++) if ('my-' + a[i] == s) {
                pos = pos0 = i;
                _x = (i % 3) * 258 + 11 + x - startX;
                _y = Math.floor(i / 3) * 68 + 12 + 80 + y - startY;
                break;
            }
            deltaX = _x - x;
            deltaY = _y - y;
            betaX = deltaX + 124;
            betaY = deltaY + 29;
            sk = sk0.cloneNode(true);
            m0.replaceChild(sk, obj);
            db.appendChild(obj);
            obj.style.position = 'absolute';
            if ('styleFloat' in obj.style) obj.style.styleFloat = 'none';
            else obj.style.cssFloat = 'none';
            obj.style.top = _y + 'px';
            obj.style.left = _x + 'px';
            if (obj.addEventListener) {
                document.addEventListener('mousemove', move, true);
                document.addEventListener('mouseup', up, true);
            } else {
                obj.setCapture();
                obj.attachEvent('onmousemove', move);
                obj.attachEvent('onmouseup', up);
                obj.attachEvent('onlosecapture', up);
            }
        }
    }
    function _up(e) {
        if (obj.removeEventListener) {
            document.removeEventListener('mousemove', _move, true);
            document.removeEventListener('mouseup', _up, true);
        } else {
            obj.detachEvent('onmousemove', _move);
            obj.detachEvent('onmouseup', _up);
            obj.detachEvent('onlosecapture', _up);
            obj.releaseCapture();
        }
    }
    return function(el, e) {
        obj = el;
        startX = e.clientX;
        startY = e.clientY;
        if (obj.addEventListener) {
            document.addEventListener('mousemove', _move, true);
            document.addEventListener('mouseup', _up, true);
        } else {
            obj.setCapture();
            obj.attachEvent('onmousemove', _move);
            obj.attachEvent('onmouseup', _up);
            obj.attachEvent('onlosecapture', _up);
        }
    };
} ();
function stoa(s) {
    return s ? s.split(/,+/) : [];
}
function addTitles() {
    for (var i = 1; i <= 4; i++) {
        var a = $id('main' + i).childNodes;
        for (var j = 0; a[j]; j++) {
            if (a[j].nodeType == 1) {
                var c = a[j].getElementsByTagName('span');
                if (c.length) c[c.length - 1].title = '添加到我的工具箱';
            }
        }
    }
}
function getCookie(s) {
    var a = RegExp('\\b' + s + '=([^;]+)').exec(document.cookie);
    return a && a[1];
}
function setCookie(name, value, days) {
    var d = new Date;
    d.setDate(d.getDate() + days);
    document.cookie = name + '=' + value + '; expires=' + d.toGMTString();
}
var tools = {
    busy: false,
    click: function(e) {
        if (!e) e = window.event;
        var etar = e.target || e.srcElement;
        var m;
        switch (etar.className) {
        case 'tool-del':
            m = 'del';
            break;
        case 'tool-fav':
            m = 'add';
            break;
        case 'tool-move':
            m = 'move';
            break;
        default:
            return;
        }
        if (e.stopPropagation) e.stopPropagation();
        else e.cancelBubble = true;
        if (e.preventDefault) e.preventDefault();
        else e.returnValue = false;
        if (m == 'move') return;
        if (!isLogin) {
            needLogin();
            return;
        }
        if (this.busy) {
            msg('请稍候...');
            return;
        }
        this[m](findUp(etar));
    },
    mousedown: function(e) {
        if (!e) e = window.event;
        var etar = e.target || e.srcElement;
        if (etar.className == 'tool-move') {
            if (e.stopPropagation) e.stopPropagation();
            else e.cancelBubble = true;
            if (e.preventDefault) e.preventDefault();
            else e.returnValue = false;
            if (this.busy) {
                msg('请稍候...');
                return;
            }
            startMove(findUp(etar), e);
        }
    },
    add: function(li) {
        var T = this;
        if ((',' + T.__cfg.list + ',').indexOf(',' + li.id + ',') != -1) {
            msg('您已经添加过该工具了');
            return;
        }
        T.busy = true;
        var s = T.__cfg.list;
        if (s) s += ',';
        s_cfg = T.__cfg.list = s + li.id;
        T.__simpleSave(function(e) {
            T.busy = false;
            if (e == 1) {
                msg('成功加入“我的工具箱”');
                T.refresh();
            } else {
                alert('出错啦！请联系管理员');
            }
        });
    },
    del: function(li) {
        var T = this;
        if (li.parentNode.childNodes.length < 2) {
            alert('请不要全部删除，至少保留一个工具！');
            return;
        }
        if (!confirm('确实要删除吗？')) return;
        T.busy = true;
        var a = stoa(T.__cfg.list);
        a.splice(inArray(a, li.id.substr(3)), 1);
        s_cfg = T.__cfg.list = a.join();
        T.__simpleSave(function(e) {
            T.busy = false;
            if (e == 1) {
                msg('此工具已被删除');
                li.parentNode.removeChild(li);
                updateHeight();
            } else {
                alert('出错啦！请联系管理员');
            }
        });
    },
    refresh: function() {
        var a = stoa(this.__cfg.list);
        var tc = $id('main0');
        tc.innerHTML = '';
        var df = document.createDocumentFragment();
        for (var i = 0; i < a.length; i++) {
            df.appendChild(toMyTool($id(a[i])));
        }
        df.appendChild(clearBoth());
        tc.appendChild(df);
        updateHeight();
    },
    __cfg: {
        list: s_cfg
    },
    __login: function() {
		
        $id('to-bar').style.display = 'none';
        this.refresh();
    },
    __logout: function() {
        $id('to-bar').style.display = 'none';
        this.refresh();
    },
    init: function() {
		
        var s;
        if (isLogin) {
            s = this.__cfg.list;
        } else {
            s = getCookie('cfglist') || s_cfg;
        }
		
        this.__cfg.list = s_cfg = s.replace(/^,+|,+$/g, '');
        $('#to-tab').tab({
            cnt: '.main',
            onChange: updateHeight
        });
        var me = this;
        var tc = $id('main');
        tc.onclick = function(e) {
            me.click.call(me, e);
        };
        tc.onmousedown = function(e) {
            me.mousedown.call(me, e);
        };
        document.forms[4].searchDepartureTime.value = date2str(new Date, 1);
        Tip.init();
        $id('lkLogin').onclick = loginClick;
        if (ie6) {
            var fs = document.forms,
            d;
            for (var i = 0; i < fs.length; i++) {
                d = fs[i].getElementsByTagName('div')[0];
                d.onmouseover = msOver;
                d.onmouseout = msOut;
            }
        }
        setTimeout(addTitles, 1);
    }
};
if (self != parent) {
    parent.J.add('tools', tools, window);
} else {
    tools.init();
    tools.__login();
}