
var latestId = 0;

function addNewItem() {
//	appendElement("container", "element" + latestId, "I Am Element " + latestId + "<a href=\"javascript:removeItem(" + latestId + ")\"> [Remove]</a>");

appendElement("container", "element" + latestId, "<input type ='text' class='input-text' name='" + latestId + "'><br>");
	
	latestId++;
}

function removeItem(idNumber) {
	
	removeElement("container", "element" + idNumber);
}

function removeElement(parentId, elementId) {
	
	//Get a reference to the element containgint the element we are removing
  	var parentElement = document.getElementById(parentId);
  	//Get a reference to the element we are removing
  	var childElement = document.getElementById(elementId);
  	
	//remove the 
  	parentElement.removeChild(childElement);
}

function appendElement(containerId, newElementId, newElementContent) {
	
	//First, we need to create a new DIV element
  	var newElement=document.createElement("div");
	//New we will give it the specified ID so we can manage it later if necessary
	newElement.setAttribute("id", newElementId);
	//Insert the HTML content into the new element
  	newElement.innerHTML=newElementContent;
	
	//Get a reference to the element that will contain the new element
 	var container = document.getElementById(containerId);
	//Now we just need to insert our new element into the containing element
  	container.appendChild(newElement, container);
	
}

