
var replacedHTML = new Array();

function replaceAndEdit(id, nodeId, docId)
{
    el = $(id);

    replacedHTML[id] = '<div id="'+id+'">'+el.innerHTML+'</div>';
/*
 * Number is first span grand child, text is second 
 */
    numEl = el.down('span');
    textEl = numEl.next('span');

    label = numEl.innerHTML;
    text = textEl.innerHTML.stripTags();

    rephtml = "<form id=\"editform"+id+"\" class=\"standard_form text_form\" action=\"../logic/structureddochandler.php\" method=\"POST\">" +
              "<div>" +
                  "<input type=\"hidden\" name=\"action\" value=\"updatetext\">" +
                  "<input type=\"hidden\" name=\"docid\" value=\""+docId+"\">" +
                  "<input type=\"hidden\" name=\"id\" value=\""+nodeId+"\">";
    if (label.length > 0)
    {
        rephtml += "<label for=\"updatetext"+id+"\">"+label+"</label>";
    }

    rephtml += "<textarea id=\"updatetext"+id+"\" name=\"text\" rows=\"100\" cols=\"70\" style=\"height: 8em; width: 70ex;\">"+text+"</textarea><br>";
    
    if (label.length > 0)
    {
        rephtml += "<label for=\"updatetextsubmit"+id+"\"></label>";
    }

    rephtml += "<button id=\"updatetextsubmit"+id+"\" type=\"submit\">Update</button>" +
              " <a href=\"#\" onclick=\"Element.replace('editform"+id+"', replacedHTML['"+id+"']); return false;\">Cancel</a>"
              "</div>" +
              "</form>";

    Element.replace(id, rephtml);
    $('updatetext'+id).select();
}

function highlightStructuredText(id)
{
    el = $(id);
    el.setStyle({backgroundColor: '#e4fce4'});
}

function unhighlightStructuredText(id)
{
    el = $(id);
    el.setStyle({backgroundColor: 'transparent'});
}


