/**
 * Probably the most ghetto JavaScript ever written.
*/

fields = [];

function addInput(index, parent, child, firstCaption, secondCaption) {
    if (fields[index] == null) // Real Ghetto
            fields[index] = countChildren(parent) - 1;
    var htmlText =  firstCaption +  "<input type='text' value='' class='large' name='" + child + "First[]'>&nbsp;";
    htmlText    +=  secondCaption + "<input type='text' value='' class='smallest' name='" + child + "Second[]'>";
    var newElement = document.createElement('div');
    newElement.id = child + fields[index]; // Give the DIV an ID, if you need to reference it later...
    newElement.innerHTML = htmlText;

    var fieldsArea = document.getElementById(parent);
    fieldsArea.appendChild(newElement);

    fields[index]++;
}

function removeInput(index, parent) {
    var e = document.getElementById(parent);
    if(fields[index] <= 0 || fields[index] == null ||  !e)
         return;
    e.removeChild(e.childNodes[--fields[index]]);
}

function countChildren(tag) {
    par = document.getElementById(tag);
    children = par.getElementsByTagName("div");
    return children.length;
}