var clicked = 0;

function saveScrollPos(offset) {
    scrollPosVert = (document.all)?document.body.scrollTop:window.pageYOffset-offset;
}

function setScrollPos() {
    window.scrollTo(0, scrollPosVert);
    setTimeout('window.scrollTo(0, scrollPosVert)',1);
}

var clicked = 0;

function addElement()
{
    var ni = document.getElementById('myDiv');
    var numi = document.getElementById('theValue');

    var num = (document.getElementById("theValue").value -1)+ 2;

    if (clicked >= (19))
    {
        window.alert('No more than 20 song(s) per player are allowed');
        return;
    }
    else
    {
    	clicked++;
        numi.value = num;
        var divIdName = "my"+num+"Div";
        var newdiv = document.createElement('div');
        newdiv.setAttribute("id",divIdName);
        newdiv.innerHTML = "<label>Track&nbsp;Url:&nbsp;<input type=\"songurl\" id=\"songurl\" name=\"songurl[]\" size=\"20\" /></label>&nbsp;&nbsp;<label>Title&nbsp;&amp;&nbsp;Artist:&nbsp;<input type=\"songname\" id=\"songname\" name=\"songname[]\" size=\"20\" />&nbsp;-<a href=\"javascript:;\" onclick=\"removeElement(\'"+divIdName+"\')\">Remove</a>";
        ni.appendChild(newdiv);
    }
}

function removeElement(divNum)
{
    var d = document.getElementById('myDiv');
    var olddiv = document.getElementById(divNum);
    saveScrollPos(0);
    d.removeChild(olddiv);
    setScrollPos();
    clicked--;
}