function changeAirSetting() {

	function findDataItem(data, airId) {
		if (data) {
			for (var i in data) {
				if (data[i].ModalTypeID == airId) {
					return data[i];
				}
			}
		}
		return null;
	}

	var data = $('#cbxModalID').combobox('getData');
	var airId = $("#cbxModalID").combobox("getValue");
	var entry = findDataItem(data, airId);

	var formData = $("#airForm").serializeJson();

	$.extend(entry, formData, {
		IsLockTemp: $("#chkIsLockTemp").is(":checked"),
		LockTemp: $("#txtLockTemp").numberspinner("getValue"),
		ColdHotMode: $("#cbxColdHotMode").combobox("getValue"),
		DeadTemp: $("#txtDeadTemp").numberspinner("getValue"),
		HotDevition: $("#txtHotDevition").numberspinner("getValue"),
		ColdDevition: $("#txtColdDevition").numberspinner("getValue"),
		RelateRoomStatus: $("#chkRelateRoomStatus").is(":checked"),
		RelateDoorContact: $("#chkRelateDoorContact").is(":checked"),
		FanStop: $("#chkFanStop").is(":checked"),
		DisableFanHighSpeed: $("#chkDisableFanHighSpeed").is(":checked")
	});

	var param = { jsonData: JSON.stringify(entry) };

	$.tools.post(param, "/HostAir/Save/", function () {
		$('#dialog').window('close');
		viewModel && viewModel.loadRooms();
	}, this);
}

function cbxModalIDOnLoadSuccess() {
	var data = $('#cbxModalID').combobox('getData');
	if (data.length > 0) {
		$('#cbxModalID').combobox('select', data[0].ModalTypeID);
	}
}

function cbxModalIDOnSelect(r) {
	if (r) {
		var data = {};
		$.extend(data, r);

		$("#airForm").form("load", data);

		if (r.ControlType == 0) {
			//二管制时禁用
			$("#cbxColdHotMode").combobox("disable");
			$("#txtDeadTemp").numberspinner("disable");
			$("#txtHotDevition").numberspinner("disable");
			$("#txtColdDevition").numberspinner("disable");
		} else {
			//四管制时启用
			$("#cbxColdHotMode").combobox("enable");
			$("#txtDeadTemp").numberspinner("enable");
			$("#txtHotDevition").numberspinner("enable");
			$("#txtColdDevition").numberspinner("enable");
		}

		$("#chkIsLockTemp").prop("checked", r.IsLockTemp);

		enableLockTemp(r.IsLockTemp);

		$("#chkRelateRoomStatus").prop("checked", r.RelateRoomStatus);

		$("#chkRelateDoorContact").prop("checked", r.RelateDoorContact);

		$("#chkFanStop").prop("checked", r.FanStop);

		$("#chkDisableFanHighSpeed").prop("checked", r.DisableFanHighSpeed);

		if (r.ColdHotMode == 1) {
			$('#cbxMode').combobox('disable');
		} else {
			$('#cbxMode').combobox('enable');
		}
	}
}

function cbxColdHotModeOnSelect(r) {
	if (r) {
		if (r.value == 1) {
			$('#cbxMode').combobox('disable');
		} else {
			$('#cbxMode').combobox('enable');
		}
	}
}

function enableLockTemp(enable) {
	$("#txtLockTemp").numberspinner(enable ? "enable" : "disable");
}

$("#chkIsLockTemp").on("change", function () { enableLockTemp(this.checked); });
