<script type="text/javascript">
(function(){
	<%
		local para = {
			firewall = {dmz = {}}
		}

		local result = tpl_get_data(para)
		local dmz = result[K_MODULE].firewall.dmz
	-%>

	var enable = '<%=dmz.enable%>';
	var ip = '<%=dmz.ip%>';

	initSwitch("Switch", enable, function(state){
		if (1 == state){
			$("#Param").show();
		}else{
			$("#Param").hide();
		}
	});

	$("#DmzIp").val(ip);

	$("#Save").click(saveDmz);

	function saveDmz(){
		var data = {};
		var para = {};
		para.firewall = {};
		para.firewall.dmz = data;

		data.enable = $("#Switch").attr("data-value");

		if ("1" == data.enable){
			data.ip = $("#DmzIp").val();
			if(handleError(checkDmzIp(data.ip), showNote))
				return;
		}

		showLoading(label.saving);
		apiSet(para, function(ret){
			var code = ret[ERR_CODE];
			handleError(code, showNote)?closeLoading():closeLoading(2);
		});
	}

	function checkDmzIp(dmzIp){
		var err = checkIp(dmzIp);
		var result = E_NONE;
		switch(err){
		case E_BLANK:
			result = E_DMZ_IP_BLANK;
			break;
		case E_INVIPFMT:
			result = E_DMZ_IP_FORMAT;
			break;
		case E_INVIP:
			result = E_DMZ_IP_ILLEGAL;
			break;
		}
		return result;
	}
})();
</script>
<div class="help hidden">
	<ul class="help-content">
		<li class="help-head">
			<img class="app-icon" src="/luci-static/images/app-icon/dmz.png?_=20191016014108" />
			<span class="help-title">{%label.dmz%}</span>
		</li>
		<li class="summary">{%helpStr.dmz%}</li>
		<li class="summary">{%helpStr.dmzTip%}</li>
	</ul>
</div>
<div class="head-con">
	<img class="app-icon" src="/luci-static/images/app-icon/dmz.png?_=20191016014108" />
	<a href="javascript:history.go(-1);" class="head-btn-l">
		<i class="head-btn icon icon_back"></i>
		<span class="head-title">{%label.dmz%}</span>
	</a>
</div>
<div class="set-con below-head">
	<ul class="set-con">
		<li class="text-con">
			<label class="desc-lbl">{%label.dmz%}</label>
			<span class="set-con-middle">
				<span id="Switch" class="switch">
					<i class="switch-circle icon_select_off"></i>
				</span>
			</span>
		</li>
	</ul>
	<div id="Param" class="hidden">
		<ul class="set-con">
			<li class="text-con">
				<label class="desc-lbl">{%label.dmzIpaddr%}</label>
				<input id="DmzIp" class="text hover" maxLength="15" value="" />
			</li>
		</ul>
		<div class="err-note hidden">
			<i class="err-icon icon_remind_line"></i>
			<p class="note-str"></p>
		</div>
	</div>
	<div class="btn-con">
		<input id="Save" class="btn btn-width" type="button" value="{%btn.save%}" />
	</div>
</div>