function displayLoginFields() {
	$("#loginfields").html("<form onSubmit='return false'><span id=message style=\"display: none;\"></span><p><table border=0><tr><td>Email Address: </td><td><input type=text name=username size=20></td></tr><tr><td>Password: </td><td><input type=password name=pass size=20></td></tr><tr><td colspan=2></td></tr><tr><td colspan=2 align=center><input type=button onClick='retrievePassword(this.form)' class=default-border value='Retrieve Password'> <input type=button onClick='loginUser(this.form)' class=default-border value=Login></td></tr></table></form>");
}

function clearLoginMessage() {
	$("#message").fadeOut("slow");
}

function retrievePassword(formObj) {
	$.ajax({
		url: "/instructor/includes/login.php",
		type: "POST",
		data: "action=retrieve&uname=" + formObj.username.value,
		success: function(msg) {
			$("#message").html(msg);
			$("#message").fadeIn("slow");
			var timeid = setTimeout("clearLoginMessage()", 5000);
		}
	});
}

function loginUser(formObj) {
	$.ajax({
		url: "/instructor/includes/login.php",
		type: "POST",
		data: "action=verifylogin&uname=" + formObj.username.value + "&pass=" + formObj.pass.value,
		success: function(xml) {
			var lerror = false;
			$(xml).find("status").each(function() {
				if ($(this).attr("error") == "true") {
					lerror = true;
					$("#message").html("<font color='red'>" + $(this).text() + "</font>");
					$("#message").fadeIn("slow");
					var timeid = setTimeout("clearLoginMessage()", 5000);
				}
			});
			
			if (!lerror) {
				$("#message").html("<b>You have successfully logged in.</b>");
				$("#message").fadeIn("slow");

				$(xml).find("registrantid").each(function() {
					$("#rid").val($(this).text());
				});

				$(xml).find("cfname").each(function() {
					$("#fname").val($(this).text());
				});

				$(xml).find("clname").each(function() {
					$("#lname").val($(this).text());
				});

				$(xml).find("address").each(function() {
					$("#address").val($(this).text());
				});

				$(xml).find("city").each(function() {
					$("#city").val($(this).text());
				});

				$(xml).find("state").each(function() {
					$("#state").val($(this).text());
				});

				$(xml).find("zipcode").each(function() {
					$("#zipcode").val($(this).text());
				});

				$(xml).find("email").each(function() {
					$("#email").val($(this).text());
				});

				$(xml).find("phone").each(function() {
					$("#phone").val($(this).text());
				});
				
				var lTimeId = setTimeout(function() {
					$("#logincode").slideUp("slow");
				}, 5000);
			}
		}
	});
}

function verifyLogout() {
	return window.confirm('Are you sure you want to logout?');
}