function createTextArea(inputId, inputName) {
	var inputObj = document.createElement('textarea');
	inputObj.id = inputId;
	inputObj.name = inputName;
	return inputObj;
}

function createInput(inputId, inputName) {
	var inputObj = document.createElement('input');
	inputObj.id = inputId;
	inputObj.name = inputName;
	return inputObj;
}

function addCommentsRow(context) {
	
// New Row --------------------------------------------------------------------------------------------

	var rowUdsReference = document.getElementById("commentsRow").insertRow(-1); // insert new row.
	
// Reference Column --------------------------------------------------------------------------------------------
	
	var tdUdsReference = rowUdsReference.insertCell(-1);	// insert 'Reference' cell.

	// IE won't allow setting the NAME attribute with setAttribute.
	if (document.all) 
	{
	    // the IE way ...
		var newRefInput = document.createElement("<input name='udsReference"+(document.getElementById("commentsRow").rows.length - 2)+"'>");
	  	newRefInput.setAttribute("className","udsRef");
	} else {
		// the correct way ...
		var newRefInput = document.createElement("input");
    	newRefInput.setAttribute("name", "udsReference"+(document.getElementById("commentsRow").rows.length - 2));
		newRefInput.setAttribute("class","udsRef");
	}

	// set all other attributes ...
	newRefInput.setAttribute("id","udsReference"+(document.getElementById("commentsRow").rows.length - 2));
	newRefInput.setAttribute("mandatory","yes");
	newRefInput.setAttribute("onblur","checkValue(this.id)");
	newRefInput.setAttribute("tabIndex","8");
	newRefInput.setAttribute("title","UDS Reference");
	newRefInput.setAttribute("validation","yes");
	tdUdsReference.appendChild(newRefInput);
	
// Comments Column --------------------------------------------------------------------------------------------

	var tdComment = rowUdsReference.insertCell(-1); // insert 'Comments' cell.

	// IE won't allow setting the NAME attribute with setAttribute.
	if (document.all) 
	{
		// the IE way ...
	    var newCommentTextarea = document.createElement("<textarea name='Comments"+(document.getElementById("commentsRow").rows.length - 2)+"'>");
		newCommentTextarea.setAttribute("className","udsComment");
	} else {
		// the correct way ...
		var newCommentTextarea = document.createElement("textarea");
    	newCommentTextarea.setAttribute("name", "Comments"+(document.getElementById("commentsRow").rows.length - 2));
		newCommentTextarea.setAttribute("class","udsComment");
	}

	// set all other attributes ...
	newCommentTextarea.setAttribute("id","Comment"+(document.getElementById("commentsRow").rows.length - 2));
	newCommentTextarea.setAttribute("mandatory","yes");
	newCommentTextarea.setAttribute("onblur","checkValue(this.id)");
	newCommentTextarea.setAttribute("tabIndex","8");
	newCommentTextarea.setAttribute("title","Comments");
	newCommentTextarea.setAttribute("validation","yes");
	tdComment.appendChild(newCommentTextarea);

	
	// Add any generated rows to the hidden "formFields" and "sortFields" elements
	//alert(commentsRowNumber);
	// Set the formfields value
	document.getElementById("formfields").value = document.getElementById("formfields").value.replace("udsReference"+(document.getElementById("commentsRow").rows.length - 3),"udsReference"+(document.getElementById("commentsRow").rows.length - 3)+", Comments"+(document.getElementById("commentsRow").rows.length - 2)+", udsReference"+(document.getElementById("commentsRow").rows.length - 2));
	
	// Set the sortFields value
	document.getElementById("sortFields").value = document.getElementById("sortFields").value.replace("udsReference"+(document.getElementById("commentsRow").rows.length - 3),"udsReference"+(document.getElementById("commentsRow").rows.length - 3)+", Comments"+(document.getElementById("commentsRow").rows.length - 2)+", udsReference"+(document.getElementById("commentsRow").rows.length - 2));
}
