function dragStart(event, id) {
    this.dragGo = function(event) {
        var e = event || window.event;

        // Get cursor position with respect to the page.
        var x = window.event ? window.event.clientX + document.body.scrollLeft : e.pageX;
        var y = window.event ? window.event.clientY + document.body.scrollTop : e.pageY;

        // Move drag element by the same amount the cursor has moved.
        this.dragObj.elNode.style.left = (this.dragObj.elStartLeft + x - this.dragObj.cursorStartX) + "px";
        this.dragObj.elNode.style.top = (this.dragObj.elStartTop + y - this.dragObj.cursorStartY) + "px";

        if (window.event) {
            window.event.cancelBubble = true;
            window.event.returnValue = false;
        }
        else
            e.preventDefault();
    }

    this.dragStop = function(event) {
        document.onmousemove = null;
        document.onmouseup = null;
    }

    this.dragObj = new Object();
    this.dragObj.zIndex = 0;

    var e = event || window.event;

    // If an element id was given, find it. Otherwise use the element being
    // clicked on.
    if (id) {
        if (typeof (id) == "string")
            this.dragObj.elNode = document.getElementById(id);
        else
            this.dragObj.elNode = id;
    }
    else {
        this.dragObj.elNode = e.target || e.srcElement;

        // If this is a text node, use its parent element.
        if (this.dragObj.elNode.nodeType == 3)
            this.dragObj.elNode = this.dragObj.elNode.parentNode;
    }

    // Get cursor position with respect to the page.
    var x = window.event ? window.event.clientX + document.body.scrollLeft : e.pageX;
    var y = window.event ? window.event.clientY + document.body.scrollTop : e.pageY;

    // Save starting positions of cursor and element.
    var pos = findPos(this.dragObj.elNode);
    this.dragObj.cursorStartX = x;
    this.dragObj.cursorStartY = y;
    this.dragObj.elStartLeft = pos.x;
    this.dragObj.elStartTop = pos.y;

    if (isNaN(this.dragObj.elStartLeft)) this.dragObj.elStartLeft = 0;
    if (isNaN(this.dragObj.elStartTop)) this.dragObj.elStartTop = 0;

    // Update element's z-index.
    this.dragObj.elNode.style.zIndex = ++this.dragObj.zIndex;

    // Capture mousemove and mouseup events on the page.
    var instance = this;
    document.onmousemove = function(ev) { instance.dragGo(ev); };
    document.onmouseup = function(ev) { instance.dragStop(ev); };
}

function closeLayer(pId) {
    document.getElementById(pId).style.display = "none";
}
