
function genForm(a, delim, action, id, submitter) {

	var out = "<form id='" + id + "' method='post' action='" + action + "' onsubmit=\"return " + submitter + ";\" />\n";

	for (var x in a) {

		var outarray = new Array();
		var label = a[x]["label"];

		if (a[x]["type"] == "checkbox") {

			for (var y in a[x]["values"]) {
				var checked = a[x]["values"][y]["checked"] == "checked" ? "checked" : "";
				outarray.push("<div style='float: left; width: 280px;'>" + a[x]["values"][y]["text"] + ": <input " + checked + " type='checkbox' name='" + x + "_field[]' value='" + y + "' ></div>");
			}
			
		} else if (a[x]["type"] == "radio") {

			for (var y in a[x]["values"]) {
				var checked = a[x]["values"][y]["checked"] == "checked" ? "checked" : "";
				outarray.push(a[x]["values"][y]["text"] + ": <input " + checked + " type='radio' name='" + x + "_field' value='" + y + "' >");
			}

		} else if (a[x]["type"] == "select") {

			var iter = 0;
			for (var y in a[x]["values"]) {
				var selected = a[x]["values"][y]["selected"] == "selected" ? "selected" : "";
				if (iter == 0) {
					iter++;
					outarray.push("<select name='" + x + "_field' />");
				} else {
					outarray.push("<option " + selected + "  value='" + y + "' >" + a[x]["values"][y]["text"] + "</option>");
				}
			}
			outarray.push("</select>");

		} else if (a[x]["type"] == "input") {

		} else if (a[x]["type"] == "textarea") {

		} else {
			
			alert("Invalid type: " + a[x]["type"]);

		}

		var out = out + "<div id='" + id + "_" + x + "' style='clear: both;float: left;display: block; width: 100%;'>" + label + "<br />" + outarray.join("") + "<br />" + "<div style='clear: both;'>" + delim + "</div></div>";

	}
		var out = out + "<br />" + "<input type='submit' name='submit' value='Submit' /></form>";
	return(out);
}


