<style type="text/css">div.wisp-auto{width:410px;overflow:hidden;border-radius:5px;background-color:#FFF;margin:180px auto;position:relative}i.close-btn{top:7px;right:10px}ul.pwd-tip{margin:20px auto 10px}div.pwd-err{position:absolute;margin:0 27px}div.pwd-btn{margin:10px 0}input.btn-width{width:364px;margin-top:46px}label.wisp-lbl{position:relative;margin-right:12px;width:80px;margin-left:0}li.wisp-con input.text{width:240px}li.wisp-con input.text-eye{width:228px}i.err-icon{margin-left:80px}p.note-str{width:248px}</style>
<script type="text/javascript">
(function(){
	<%
		local para = {
			dev_feature = {wifi_extend = {}}
		}

		local result = tpl_get_data(para)
		local reboot_confirm = result[K_MODULE].dev_feature.wifi_extend.reboot_confirm
	-%>

	var reboot_confirm = <%=reboot_confirm%>;

	function showNote(noteStr){
		$("#PwdErr").show();
		$("#PwdTip").html(noteStr);
	}

	$("#SaveWisp").click(function(){
		var extendModetype,extendPwdtype,extendBand,extendMac;
		extendModetype = $("#WispModeType").val();
		extendPwdtype = $("#WispPwdType").val();
		extendBand = $("#WispBand").val();
		extendMac = $("#WispMac").val();

		var data = {};
		var para = {};
		para.wisp = {};
		para.wisp.config = data;
		data.enable = "1";
		data.band = extendBand;
		data.bssid = extendMac;
		data.ssid = $("#SsidNameAuto").val();
		if (handleError(checkSsid(data.ssid))){
			return;
		}
		data.encryption = extendPwdtype;
		data.safe_mode = extendModetype;
		if (data.safe_mode != "OPEN") {
			data.password = $("#SsidPwdAuto").val();
			if (handleError(checkPwd(data.password))){
				return;
			}
		}

		if(reboot_confirm){
			showConfirm(label.openExtend, function(choose){
				if (choose){
					saveWisp(para);
				}
			});
		}else{
			saveWisp(para);
		}
	});

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

	function refreshWisp(ret){
		if(reboot_confirm){
			showProgressBar(label.saveOpenExtend, label.rebooting, ROUTER.time.reboot, function(){
				window.location.reload();
			});

			$.setTimeout(function(){
				// 检测LAN是否可以连接DUT
				lanDetecting(function(){
					window.location.reload();
				});
			}, ROUTER.time.detectDelay);
		}else{
			var time = ret[K_MODULE].wisp.config.wait_time;
			$.setTimeout(function(){
				closeLoading();
				window.location.reload();
			}, time * 1000);
		}
	}

	function checkPwd(password){
		var err = checkStrFormat(password);
		switch(err){
		case E_STRINGBLANK:
			return E_WISP_PWD_BLANK;
		case E_STRINGFORMAT:
			return E_WISP_PWD_ILLEGAL;
		}

		if (checkStrLen(password, 63, 8) != E_NONE){
			return E_WISP_PWD_LEN;
		}

		return E_NONE;
	}

	function checkSsid(ssid){
		if("" == ssid){
			return E_WISP_SSID_BLANK;
		}

		if (checkStrLen(ssid, 32, 1) != E_NONE){
			return E_WISP_SSID_LEN;
		}

		return E_NONE;
	}
})();
</script>
<div class="wisp-auto">
	<input class="hidden" id="WispModeType" value="" />
	<input class="hidden" id="WispPwdType" value="" />
	<input class="hidden" id="WispBand" value="" />
	<input class="hidden" id="WispMac" value="" />
	<p class="alert-title">{%label.wisp%}</p>
	<i class="tip icon_close color-red close-btn"></i>
	<div class="set-con">
		<ul class="set-con pwd-tip">
			<li class="text-con wisp-con">
				<label class="desc-lbl wisp-lbl">{%label.networkName%}</label>
				<input class="text ime-mode-n hover" maxLength="32" id="SsidNameAuto" value="" readonly />
			</li>
		</ul>
		<ul id="WispAutoPwd" class="set-con pwd-tip">
			<li class="text-con wisp-con">
				<label class="desc-lbl wisp-lbl">{%label.networkPwd%}</label>
				<input class="text ime-mode-n hover" type="password" autocomplete="new-password" maxLength="64" id="SsidPwdAuto" value="" />
				<i class="tip icon-eye" data-value="0"></i>
			</li>
		</ul>
		<div class="err-note hidden pwd-err" id="PwdErr">
			<i class="err-icon icon_remind_line"></i>
			<p class="note-str" id="PwdTip"></p>
		</div>
		<div class="btn-con pwd-btn">
			<input id="SaveWisp" class="btn btn-width" type="button" value="{%btn.startExtend%}" />
		</div>
	</div>
</div>