function initAddApt() {
	//find the initial apartment list
	var aptlist = document.getElementById("apartmentlist");
	
	//create the new elements
	var newrow = document.createElement("tr"); //new table row
	var leftcell = document.createElement("td"); //new left table cell
	var boldtext = document.createElement("span"); //new bold tag
	var newtext = document.createTextNode(" Add another Property to the enquiry"); //new text node
	var rightcell = document.createElement("td"); //new right cell
	var newcheckbox = document.createElement("input"); // new input element	
	
	leftcell.setAttribute("colSpan","2"); //give the cell a colspan of 2
	leftcell.setAttribute("align","center");
	
	newcheckbox.setAttribute("type","checkbox"); //make the input element a checkbox
	newcheckbox.setAttribute("id","addnewcheckbox"); //give the checkbox an id
	newcheckbox.onclick = initAddNewRow; //add an onclick event to the checkbox
	
	boldtext.appendChild(newtext); //add the text to the bold element	
	
	leftcell.appendChild(newcheckbox); //add the checkbox to the left cell
	leftcell.appendChild(boldtext); //add the bold text to the left cell
	
	newrow.appendChild(leftcell); //add the left cell to the row
	newrow.appendChild(rightcell); //add the right cell to the row
	
	aptlist.parentNode.insertBefore(newrow,aptlist.nextSibling); //insert the new row to the page
}

//initialization function for addNewRow to counter IE deficencies
function initAddNewRow() {
	addNewRow(this);
}

function addNewRow(checkbox) {
	if (checkbox.checked == true) {
		addRow(checkbox);
		checkbox.checked = false;
	}
}

function addRow(checkbox,apartment) {
	var newrow = document.createElement("tr"); //new table row
	var leftcell = document.createElement("td"); //new left table cell
	var boldtext = document.createElement("span"); //new bold tag
	var newtext = document.createTextNode(" Property"); //new text node
	var rightcell = document.createElement("td"); //new right cell
	var newcheckbox = document.createElement("input"); // new input element
	
	//leftcell.setAttribute("align","center");
	leftcell.setAttribute("width","25%"); //give the left cell a width of 25%
	rightcell.setAttribute("width","75%"); //give the right cell a width of 75%
	
	newcheckbox.setAttribute("type","checkbox"); //make the input element a checkbox
	newcheckbox.onclick = initRemoveRow; //add an onclick event to the checkbox
	
	boldtext.appendChild(newtext); //add the text to the bold element
	
	leftcell.appendChild(newcheckbox); //add the checkbox to the left cell
	leftcell.appendChild(boldtext); //add the bold text to the left cell
	
	var dropdown = document.getElementById("apartmentdropdown");
	var newdropdown = dropdown.cloneNode(true);
	
	if (apartment != undefined) {
		newdropdown.value = apartment;
	}
	
	rightcell.appendChild(newdropdown);
	
	newrow.appendChild(leftcell); //add the left cell to the row
	newrow.appendChild(rightcell); //add the right cell to the row
	
	var parenttable = checkbox.parentNode.parentNode.parentNode;
	var currentrow = checkbox.parentNode.parentNode;
	parenttable.insertBefore(newrow,currentrow); //insert the new row to the page
	
	newcheckbox.checked = true; //automatically check the checkbox
}

function initRemoveRow() {
	removeRow(this);
}

function removeRow(checkbox) {
	var currentrow = checkbox.parentNode.parentNode;	
	currentrow.parentNode.removeChild(currentrow);
}

window.onload = initAddApt;