function add() {
	$("#dialog")
		.find(".dlg-content").panel({ href: "/RoomCard/Edit/", queryParams: {} }).end()
		.find(".dlg-footer .dlg-btn-save").unbind("click").bind("click", save).end()
		.dialog({
		    title: lang.NewRoomCard,
			width: 400,
			height: 290
		})
		.dialog("open");
}
function edit(row) {
	row = row || $('#dg').datagrid('getSelected');
	if (row) {
		$("#dialog")
			.find(".dlg-content").panel({ href: "/RoomCard/Edit/", queryParams: { ID: row.ID} }).end()
			.find(".dlg-footer .dlg-btn-save").unbind("click").bind("click", save).end()
			.dialog({
			    title: lang.EditRoomCard,
				width: 400,
				height: 290
			})
			.dialog("open");
	} else {
		$.tools.alert(lang.PleaseSelectTheData);
	}
}
function del() {
	var rows = $('#dg').datagrid('getSelections');
	if (!rows || rows.length == 0) {
		$.tools.alert(lang.PleaseSelectTheData);
		return;
	}

	var param;
	$.each(rows, function (i, n) {
		if (i == 0) {
			param = "idList=" + n.ID;
		} else {
			param += "&idList=" + n.ID;
		}
	});

	$.tools.delPost(param, "/RoomCard/Delete/", function () {
		$('#dg').datagrid("clearSelections");
		$('#dg').datagrid("reload");
	}, this);
}
function save() {
	var form = $("#dialog").find("form");
	if (form.form("enableValidation").form("validate")) {

		var entry = form.serializeJson();
		entry.CardType = { ID: entry.CardTypeID };
		var param = { jsonData: JSON.stringify(entry) };

		$.tools.post(param, "/RoomCard/Save/", function () {
			$('#dg').datagrid("reload");
			$("#dialog").window('close');
		}, this);
	}
}