function drag(id, headHeight) {
    var target = document.getElementById(id);
    target.onmousedown = function (e) {
        var d = document;
        var  that=this;
        var page = {
            event: function (evt) {
                var ev = evt || window.event;
                return ev;
            },
            pageX: function (evt) {
                var e = this.event(evt);
                return e.pageX || (e.clientX + document.body.scrollLeft - document.body.clientLeft);
            },
            pageY: function (evt) {
                var e = this.event(evt);
                return e.pageY || (e.clientY + document.body.scrollTop - document.body.clientTop);

            },
            layerX: function (evt) {
                var e = this.event(evt);
                return e.layerX || e.offsetX;
            },
            layerY: function (evt) {
                var e = this.event(evt);
                return e.layerY || e.offsetY;
            }
        }
        var x = page.layerX(e);
        var y = page.layerY(e);

        if((page.pageY(e) - $(target).offset().top) > headHeight){
            return;
        }

        if (that.setCapture) {
            that.setCapture();
        }
        else if (window.captureEvents) {
            window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
        }
        d.onmousemove = function (e) {
            var tx = page.pageX(e) - x;
            var ty = page.pageY(e) - y;
            that.style.left = tx + "px";
            that.style.top = ty + "px";
        }
        d.onmouseup = function () {
            if (that.releaseCapture) {
                that.releaseCapture();
            } else if (window.releaseEvents) {
                window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
            }
            d.onmousemove = null;
            d.onmouseup = null;
        }
    }
}