var oLoginTable = document.getElementById("loginformtable")
if(oLoginTable != null) {
	var oFormTable = document.getElementById("formtable")
	if(oFormTable != null) {
		var oTBody = oLoginTable.childNodes[0];
		for(var i=0; i<oTBody.childNodes.length; i++) {		
			oRow = oFormTable.insertRow();
			oCell = oRow.insertCell();
			oCell.innerHTML = oTBody.childNodes[i].childNodes[0].innerHTML
			
			var type = oTBody.childNodes[i].childNodes[2].innerHTML
			oCell = oRow.insertCell();
			switch(type) {
				case "text":
					var oInput = document.createElement("input")
				break
				case "select":
					var oInput = document.createElement("select")
					for(var j=3; j<oTBody.childNodes[i].childNodes.length; j++) {	
						var text = 	oTBody.childNodes[i].childNodes[j].innerText
						oInput.options[oInput.options.length] = new Option(text, text)
					}
				break
				default:
					alert("type not found:"+type)
				break
			}
			oInput.name = oTBody.childNodes[i].childNodes[1].innerHTML
			oInput.id = oTBody.childNodes[i].childNodes[1].innerHTML
			oCell.appendChild(oInput)
		}
		
		var oInput = document.createElement("button")
		oInput.onclick = ValidateLoginForm
		oInput.value = "Login"
		oRow = oFormTable.insertRow();
		oCell = oRow.insertCell();
		oCell.appendChild(oInput)
	}
}

function ValidateLoginForm() {
	var value = document.getElementById("employeenumber").value
	var valid = true
	if(value.length == 0 || value.length > 6) {
		valid = false
	} else {
		if((value+"").search(/^\d{5,6}$/gi) == -1) {
			valid = false	
		}
	}
	if(!valid) {
		alert("This is not a valid employee number, only eligible employees can view this section.  Please go back.");
	} else {
		document.location.href = "home"
	}
}