<%
local api = self.api
-%>
<script type="text/javascript">
	//<![CDATA[
	document.addEventListener("DOMContentLoaded", function () {
		waitForElement('select[name*="<%=api.appname%>"][name*="type"]', function(el) {
			let o_val = el.value;
			el.addEventListener("change", () => {
				el.blur();
				if (o_val != el.value) {
					let save = true;
					if (save) {
						//document.getElementsByClassName('cbi-button-save')[0].click();
						update_node({
							remarks: getOption("remarks").value,
							group: getOption("group").value,
							type: getOption("type").value,
							//protocol: ''
						});
					}
				}
			});
		});
		waitForElement('select[name*="<%=api.appname%>"][name*="protocol"]', function(el) {
			let o_val = el.value;
			el.addEventListener("change", () => {
				el.blur();
				if (el.value.startsWith("_") || (o_val.startsWith("_") && !el.value.startsWith("_"))) {
					let name_split = el.name.split(".");
					let name = name_split[name_split.length - 1];
					let save = true;
					if (save) {
						//document.getElementsByClassName('cbi-button-save')[0].click();
						update_node({
							remarks: getOption("remarks").value,
							group: getOption("group").value,
							protocol: getOption(name).value
						});
					} else {
						window.location.href = node_config_url + "?select_proto=" + el.value;
					}
				}
			});
		});
	});
	//]]>
</script>
