$(function () {
	$("#txtUsername").focus();

	$("#frmCreate").submit(function () {
		$.ajax({
			url: "/bruger/opret/Ajax.Create.asp",
			type: "POST",
			data: $(this).serialize(),
			dataType: "json",
			success: function (data) {
				if (data.Error)
					$("#frmCreate").error(data.ErrorMsg);
				else
					window.location.reload();
			},
			error: function () {
				alert("Der opstod en fejl");
			}
		});

		return false;
	});

	$("#txtZipcode").keyup(function () {
		if ($(this).val().length == 4) {
			$.ajax({
				url: "/Ajax/City/GetByZipcode.asp",
				data: { Zipcode: $(this).val() },
				success: function (sCity) {
					$("#txtCity").val(sCity);
				}
			});
		}
	});
});
