/* drag div */
function startdrag(t, e)
{
    var targ;
    if (!e) e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3)
    {  // defeat Safari bug
        targ = targ.parentNode;
    }
    var tname = targ.tagName;

    if ((tname.toLowerCase() != "input") && (tname.toLowerCase() != "select"))
    {
        if (e.preventDefault) e.preventDefault();
        e.cancelBubble = true;
        window.document.onmousemoveOld = window.document.onmousemove;
        window.document.onmouseupOld = window.document.onmouseup;
        window.document.onmousemove = dodrag;
        window.document.onmouseup = stopdrag;
        window.document.draged = t;
        t.dragX = e.clientX;
        t.dragY = e.clientY;
        return false;
    }
}
function dodrag(e)
{
    if (!e) e = event;
    t = window.document.draged;
    t.style.left = (t.offsetLeft + e.clientX - t.dragX) + "px";
    t.style.top = (t.offsetTop + e.clientY - t.dragY) + "px";
    t.dragX = e.clientX;
    t.dragY = e.clientY;
    return false;
}
function stopdrag()
{
    window.document.onmousemove = window.document.onmousemoveOld;
    window.document.onmouseup = window.document.onmouseupOld;

    if (localStorage)
    {

        var left = parseInt(document.getElementById("beheer").style.left, 10);

        if (left > 0)
        {
            localStorage.setItem("dragX", left);
        } else
        {
            localStorage.setItem("dragX", "10");
        }
        var top = parseInt(document.getElementById("beheer").style.top, 10);
        if (top > 0)
        {
            localStorage.setItem("dragY", top);
        } else
        {
            localStorage.setItem("dragY", "10");
        }
    }
}

function InitBeheer()
{
    if (localStorage)
    {
        if (localStorage.getItem("dragX") != null)
        {
            var left = parseInt(localStorage.getItem("dragX"), 10);
            if (left > 0)
            {
                document.getElementById("beheer").style.left = parseInt(localStorage.getItem("dragX"), 10) + 'px';
            }
        }
        if (localStorage.getItem("dragY") != null)
        {
            var top = parseInt(localStorage.getItem("dragY"), 10);
            if (top > 0)
            {
                document.getElementById("beheer").style.top = parseInt(localStorage.getItem("dragY"), 10) + 'px';
            }
        }
    }
}
