// 預載資料 ==================================================================================
var css_js_files = new Array("./js/pako.min.js",
	"./js/language.js",
	"./js/jslib.js");
var preloadvalue = 0;
function preload() {
	//載入css與js
	for (var i = 0; i < css_js_files.length; i++)
		load_css_js(css_js_files[i]);
}
//防止載入css與js失敗
function load_css_js(srchref) {
	var head = document.getElementsByTagName("head")[0];
	var obj;
	var arrsrchref = srchref.split(".");
	switch (arrsrchref[arrsrchref.length - 1]) {
		case "css":
			obj = document.createElement("link");
			obj.type = "text/css";
			obj.rel = "stylesheet";
			obj.href = srchref;
			break;
		case "js":
			obj = document.createElement("script");
			obj.type = "text/javascript";
			obj.src = srchref;
	}
	obj.srchref = srchref;
	head.appendChild(obj);

	obj.onload = function () {
		preloadvalue++;
		if (preloadvalue == (css_js_files.length))
			Load();
	};
	obj.onerror = function () {
		load_css_js(obj.srchref)
	};
}

var fsVersion = 20250710;

//document.write('<script type="text/javascript" src="language.js"><\/script>');
var isphone = false;
var t = setInterval(function () { t_update() }, 500);
var UserIdx = -1;	//登入權限的索引
var canControl = 0;
var canEditor = 0;
var isAdmin = 0;
var isUrlHaveKeyLogin = false;
var nowPage = -99999;	//現在所在頁面
var LastCheckAlarmCountT = new Date() - 10000;
var UseDay = "";
var UpdateName = "";
var JNCSoftwareName = "";
var lang;
var urlsetlang = "";
var ishideinfo = false;
var firstPage = -1;
var reloadT = "";
var isJNCServer = 0;
var fatherpage = this;
var ServerTitle = "";
var ServerVersion = "";
var RemeberLogin = true;
var showconnectFail = true;
var jncdebugplan = "";
var zoomval = 100;
var hidescrollbar = 0;//嵌入/看板模式:?hidescrollbar=1 時平面圖隱藏垂直+水平捲軸
//var bgAlarm = document.getElementById("bgAlarm");
function LanguageChange(temp_no) {
	localStorage.setItem("lang_no", temp_no);
	SendCmd("ChangeLangauge", "Language=" + temp_no, function (res) {
		if (res == "OK") {
			chLanguage(temp_no);
			document.getElementById("iframePage").contentWindow.location.reload();
		}
	});
}
var DelStrCount = location.pathname.length;
window.getLanguageString = function (locationPathname, lidIdx) {
	try {

		locationPathname = "/" + locationPathname.substring(DelStrCount);
		if (locationPathname == "/") locationPathname = "./FatherPage.html";
		return getLanguage(lang, locationPathname.substring(1).split('.')[0])[lidIdx];
	} catch (e) {
		console.log(e);
	}
}
//AQIDevice 三頻道一組:role(idx mod 3) 1=指標污染物、2=等級。後端只存數值碼,這裡映射為當前語系文字。
//role 0(AQI 數值)或非法 code 回傳原值,讓即時值畫面照常顯示數字。
window.getAQIText = function (role, code) {
	var n = parseInt(code);
	if (isNaN(n) || n < 0) return code;
	if (role == 1) {//指標污染物:化學符號,各語系相同,用常數
		var P = ["PM2.5", "PM10", "O3", "CO", "SO2", "NO2"];
		return n < P.length ? P[n] : code;
	}
	if (role == 2) {//等級:取 language.js 的 AQILevel 區段(4 語系)
		try {
			var lv = getLanguage(lang, "AQILevel");
			if (lv && lv[n] != undefined) return lv[n];
		} catch (e) { console.log(e); }
		return code;
	}
	return code;
}
function chLanguage(langcode) {//這裡由menu啟動.
	//語系 與 中央集成本體分開.
	//收集當前iframe, 進行reload動作.
	var iframes = document.getElementsByTagName("iframe");
	if (iframes.length > 0) {
		for (var i = 0; i <= iframes.length - 1; i++) {
			frameload(iframes[i], langcode); //觸發FatherPage當下各個iframe的triggerLang (依據iframe.location.pathname執行), 並更新當下語系值.
		}
	}
	lang = langcode;
	//localStorage.setItem("lang_no", langcode);

	//取得語系資料
	triggerLang(getLang_no());
}
//禁止下拉重新整理
function StopPhoneDownF5() {
	document.body.style.overscrollBehaviorY = "contain";
}
var phone_W;
var phone_H;
var WebUrl;
var tmplocation;
//平面圖-指定頁面
var planPage;
var PlanDeviceMac = null;
var PlanCHIdx = null;
var PlanStartCHIdx = null;
var isSetFirstPage = false;
//不安全網址(http://...:11223)提示轉移到 https://www.jnc-tec.com/88/,參數一併帶過去
function checkInsecureUrlRedirect() {
	var insecureHosts = ["59.125.238.217:11223", "www.jnc-tec.com:11223"];
	if (location.protocol != "http:" || insecureHosts.indexOf(location.host) == -1) return;

	//只有手機版才提示轉移(桌機不跳)。本函式在 Load() 早於下方 isphone 設值處被呼叫,故不單依賴 isphone 全域:
	//isphone 已被設定流程設過則尊重,否則就地以本檔判定手機的同一條件(直式比例 clientWidth*1.2<clientHeight)判斷,
	//確保桌機(橫式)不會誤跳。
	var isPhoneView = isphone || (document.body.clientWidth * 1.2 < document.body.clientHeight);
	if (!isPhoneView) return;

	//四語對照(0繁 1簡 2英 3俄);FatherPage 區段在 language.js 缺俄語,故就地內建保證四語齊全
	var L = {
		msg: ["目前網址不安全，是否轉移到安全網址？",
			"当前网址不安全，是否转移到安全网址？",
			"The current address is insecure. Switch to the secure address?",
			"Текущий адрес небезопасен. Перейти на безопасный адрес?"],
		yes: ["是", "是", "Yes", "Да"],
		no: ["否", "否", "No", "Нет"]
	};
	var no = parseInt(getLang_no());
	if (isNaN(no) || no < 0 || no > 3) no = 0;

	var mask = document.createElement("table");
	mask.id = "tbInsecureUrlTip";
	mask.style.cssText = "position:fixed;top:0px;left:0px;width:100%;height:100%;z-index:99999;background-color:rgba(50,50,50,0.8);";
	var tdMask = mask.insertRow(0).insertCell(0);
	tdMask.style.textAlign = "center";

	var box = document.createElement("table");
	box.style.cssText = "font-weight:bold;display:flex;justify-content:center;";
	box.cellPadding = 0;
	box.cellSpacing = 0;

	var tdHead = box.insertRow(0).insertCell(0);
	tdHead.style.cssText = "width:350px;height:30px;background-color:#369;border-top-left-radius:10px;border-top-right-radius:10px;padding:10px;color:#FFF;font-size:24px;";
	tdHead.innerText = "Information";

	var trMsg = box.insertRow(1);
	trMsg.style.backgroundColor = "#FFF";
	var tdMsg = trMsg.insertCell(0);
	tdMsg.style.cssText = "text-align:center;font-size:20px;height:100px;padding:15px;";
	tdMsg.innerText = L.msg[no];

	var trBtn = box.insertRow(2);
	trBtn.style.backgroundColor = "#FFF";
	trBtn.style.height = "70px";
	var tdBtn = trBtn.insertCell(0);
	tdBtn.style.cssText = "text-align:center;border-bottom-left-radius:10px;border-bottom-right-radius:10px;";

	var btnTb = document.createElement("table");
	btnTb.style.display = "inline";
	var btnTr = btnTb.insertRow(0);

	var tdYes = btnTr.insertCell(0);
	tdYes.className = "bt";
	tdYes.style.cssText = "width:140px;border-radius:50px;background-color:#369;color:#FFF;padding:10px;";
	tdYes.innerText = L.yes[no];
	tdYes.onclick = function () {
		location.href = "https://www.jnc-tec.com/88/" + location.search;
	};

	var tdGap = btnTr.insertCell(1);
	tdGap.style.width = "30px";

	var tdNo = btnTr.insertCell(2);
	tdNo.className = "bt";
	tdNo.style.cssText = "width:140px;border-radius:50px;background-color:#AAA;color:#FFF;padding:10px;";
	tdNo.innerText = L.no[no];
	tdNo.onclick = function () {
		if (mask.parentNode) mask.parentNode.removeChild(mask);
	};

	tdBtn.appendChild(btnTb);
	tdMask.appendChild(box);
	document.body.appendChild(mask);
}
function Load() {
	checkInsecureUrlRedirect();
	//判斷屬性內容改變觸發事件
	// var aa=new MutationObserver(m=>{
	// 	console.log("aaa",m);
	// 	// for(var _idx in m){
	// 	// 	if(m[_idx].attributeName=="src"){
	// 	// 		console.log("aaa",m);
	// 	// 	}
	// 	// }
	// });
	// aa.observe(document.getElementById("iframePage"),{  attributeFilter: ["src"], attributes: true, characterData: false,subtree:false ,childList:false});
	if (document.body.clientWidth * 1.2 < document.body.clientHeight)
		isphone = true;

	WebUrl = document.location.origin + document.location.pathname;

	if (document.location.origin.indexOf("jnc-demo") > 0) {
		var tb = document.createElement("table");
		var tr1 = tb.insertRow(0);
		var td1 = tr1.insertCell(0);
		var tr2 = tb.insertRow(1);
		var td2 = tr2.insertCell(0);
		var span = document.createElement("u");
		var img = document.createElement("img");
		tb.style.width = "100%";
		tb.style.height = "100%";
		tb.style.position = "absolute";
		tb.style.zIndex = "99999";
		tb.style.top = "0px";
		tb.style.backgroundColor = "#7AD";
		img.src = WebUrl + "/pic/JNCMoveURL.svg";

		img.style.paddingBottom = "10px";
		td1.style.textAlign = "center";
		td1.style.verticalAlign = "bottom";
		td1.append(img);
		span.style.color = "#FFF";
		span.innerText = "點擊進入";
		span.style.fontWeight = "bold";
		span.style.fontFamily = "微軟正黑體";
		span.style.cursor = "pointer";
		span.onclick = function () {
			if (location.protocol == "https:") {
				location.href = "https://www.jnc-tec.com/88/" + location.search;
			} else {
				location.href = "http://www.jnc-tec.com:11223/" + location.search;
			}
		}
		if (isphone) {
			img.style.width = "95%";
			span.style.fontSize = "25px";
			td2.style.height = "50%";
		} else {
			img.style.width = "50%";
			span.style.fontSize = "50px";
			td2.style.height = "30%";
		}

		td2.style.verticalAlign = "top";
		td2.append(span);
		td2.style.textAlign = "center";
		document.body.append(tb);
	}

	if (WebUrl[WebUrl.length - 1] == "/") {
		WebUrl = WebUrl.substring(0, WebUrl.length - 1);
	}
	var sDNum = 0;
	for (var i = 15; i < WebUrl.length; i++) {
		if (WebUrl[i] == "?") {
			if (sDNum > 0) {
				DelStrCount = i - sDNum;//+1;台南蛋品多這個會出錯
			}
			break;
		}
		if (WebUrl[i] == "/" && sDNum == 0) {
			sDNum = i;
		}
	}
	//純測試----要刪
	//setInterval(function(){location.reload()},1500);
	UserIdx = localStorage.UserIdx;

	if (UserIdx == -999) {
		localStorageClear();
		UserIdx = -1;
	}

	document.getElementById("iframePage").src = "";
	if (localStorageSpace() > 5000)
		localStorageClear();

	window.addEventListener("resize", function () {
		if (!isphone) return;
		//禁止翻轉手機(提示)
		var isturn = document.body.clientHeight < document.body.clientWidth && phone_W != document.body.clientWidth;
		document.getElementById("lbMsg_StopTurn").style.display = isturn ? "" : "none";
		document.getElementById("iframePage").style.display = isturn ? "none" : "";
		if (document.getElementById("iframePage").src.indexOf("LogIn.html") == -1 && !ishideinfo) {
			document.getElementById("trTitle").style.display = isturn ? "none" : "";
			document.getElementById("trFoot").style.display = isturn ? "none" : "";
		}
		// iframePagePageSizeChange();
	});

	tmplocation = window.location;
	var tmpArr = window.location.search.substring(1).split("&");

	for (var i = 0; i < tmpArr.length; i++) {
		var par = tmpArr[i].split("=")[0];
		var nval = tmpArr[i].substring(par.length + 1);
		switch (par.toLowerCase()) {
			case "lang":
				lang = nval;
				urlsetlang = nval;
				localStorage.setItem("lang_no", lang);
				break;
			case "key":
				try {
					localStorage.mkey = nval;
					isUrlHaveKeyLogin = true;
					SendCmd("Login", "key=" + nval, "LogIn_LogIn");
				} catch (e) {

				}
				break;
			case "rndidx":
				UserIdx = nval;
				break;
			case "page":
				switch (nval) {
					case "map": firstPage = 18; break;
					case "plan": firstPage = 1; break;
					case "allview": firstPage = 2; break;
					case "devicestate": firstPage = 4; break;//page=devicestate&mac=TestMath&hideinfo=1
					case "trend": firstPage = 7; break;
					case "datacount": firstPage = 35; break;
					case "alarm": firstPage = 5; break;
					case "alarmcount": firstPage = 6; break;
					case "datadownload": firstPage = 8; break;
					case "deviceset": firstPage = 9; break;
					case "trajectory": firstPage = 30; break;
					case "mail": firstPage = 15; break;
					case "line": firstPage = 31; break;
					case "datashare": firstPage = 29; break;
					case "devicealarmset": firstPage = 10; break;
				}
				// if (window.location.search.toLowerCase().substring(1).indexOf("key") == -1 && window.location.search.toLowerCase().substring(1).indexOf("rndidx") == -1) {
				// 	localStorageClear();
				// }
				isSetFirstPage = true;

				break;
			case "hideinfo":
				ishideinfo = true;
				document.getElementById("tdMain").style.borderTopWidth = "0px";
				document.getElementById("tdMain").style.borderBottomWidth = "0px";
				document.getElementById("tbMain").style.backgroundColor = "rgba(255,255,255,0)";
				document.body.style.backgroundColor = "rgba(255,255,255,0)";
				document.getElementById("iframePage").style.backgroundColor = "transparent";
				break;
			case "isphone":
				isphone = nval;
				break;
			case "reloadh"://一段時間重新載入頁面(小時)
				reloadT = DateMathAdd(new Date(), 0, 0, 0, nval, 0, 0);
				break;
			case "planpage":
				planPage = nval;
				break;
			case "plandevicemac":
				PlanDeviceMac = decodeURIComponent(nval);
				break;
			case "planchidx":
				PlanCHIdx = nval;
				break;
			case "planstartchidx":
				PlanStartCHIdx = nval;
				break;
			case "noshowdisconnect"://斷線不顯示
				showconnectFail = false;
				break;
			case "jncdebugplan":
				jncdebugplan = nval;
				break;
			case "zoom":
				zoomval = nval;
				document.body.style.zoom = zoomval + "%";
				break;
			case "hidescrollbar":
				hidescrollbar = nval;
				break;
		}
	}

	if (localStorage.lang_no == undefined || localStorage.lang_no == null) localStorage.lang_no = 0;


	// if(isSetFirstPage){
	// 	changePage(firstPage);
	// }
	window.scrollTo(0, 0);

	StopPhoneDownF5();
	try {
		var docElm = document.body;
		if ((docElm.requestFullscreen) || (docElm.mozRequestFullScreen) || (docElm.webkitRequestFullScreen) || (elem.msRequestFullscreen) || (docElm.webkitEnterFullscreen)) {
			document.getElementById("trFullScreen").style.display = "";
		}

	} catch (e) {
		//Iphone沒有全屏... 哭阿..
	}
	SendCmd("LoadTitleName", "", function (res) {
		if (res == "") {
			changePage(-1);
			return;
		}
		res = res.replace(/\t/g, '');
		var obj = JSON.parse(res);
		obj.Title = decodeURIComponent(obj.Title);
		obj.UserName = decodeURIComponent(obj.UserName);
		setTitle(obj.Title);
		UseDay = parseInt(obj.UseDay);
		if (urlsetlang == "") {
			localStorage.setItem("lang_no", obj.Language);
			chLanguage(obj.Language);
			document.getElementById("btLanguage").value = parseInt(obj.Language);
		}
		if (obj.UserName != null) {
			localStorage.Name = obj.UserName;
		}

		//document.getElementById("iframeMenu").contentDocument.getElementById("lbVersion").innerHTML= obj.Version;
		document.getElementById("lbVersion").innerHTML = obj.Version;
		document.title = obj.Title;
		document.JNCSoftwareName = obj.JNCSoftwareName;
		isJNCServer = parseInt(obj.isJNCServer);

		ServerTitle = obj.Title;
		ServerVersion = obj.Version;

		if (obj.ShowStr != "") {
			document.getElementById("lbGSD").style.display = "";
			document.getElementById("lbGSD").innerHTML = obj.ShowStr;
			document.getElementById("lbGSD").href = obj.ClickDir;
		}
		CheckAlarmCount();

		if (UserIdx == -1) changePage(-1);

		//讀取是否靜音
		document.getElementById("bgAlarm").pause();
		if (localStorage.isUNMute == 1) {
			if (confirm("是否要開啟警報音效功能(瀏覽器強制要求每次重開需要使用者重複確認")) {
				document.getElementById("bgAlarm").pause();
				localStorage.isUNMute = 1;
			} else {
				localStorage.isUNMute = 0;
			}
		}
		document.getElementById("swMute").checked = parseInt(localStorage.isUNMute) == 1;
		//取得語系資料
		triggerLang(getLang_no());

		document.getElementById("iframeMenu").onload = function () {
			//改變字體大小
			ChangeSize4Phone();
		}
		ChangeSize4Phone();
	});

}
function ChangeSize4Phone() {
	if (!isphone) return;
	var btMenu = document.getElementById("btMenu");
	btMenu.style.width = "50px";
	btMenu.style.height = "30px";

	document.getElementById("tbSecondTitle").style.fontSize = "9px";
	var lb_title = document.getElementById("lb_title");
	lb_title.style.fontSize = "14px";
	//改變Menu頁
	document.all("iframeMenu").contentWindow.ChangeSize4Phone();
	document.getElementById("iframeMenu").style.width = "100%";
	var btLanguage = document.getElementById("btLanguage");
	btLanguage.style.width = "100px";
	document.getElementById("tdLanguage").style.width = "50px";
	document.getElementById("btLanguage").style.fontSize = "11px";
	document.getElementById("tdLogOut").style.width = "50px";

	document.getElementById("tdTime").style.display = "none";
	document.getElementById("tdPCInfo").style.display = "none";

	var trTitle = document.getElementById("trTitle");
	trTitle.style.boxShadow = "0px -1px 0px 0px #AAA inset";
	trTitle.style.backgroundColor = "#FFF";

	//固定視窗大小(防止子頁翻轉被擠開)
	var iframePagePNode = document.getElementById("iframePage").parentNode;
	iframePagePNode.style.width = iframePage.parentNode.clientWidth + "px";
	iframePagePNode.style.maxWidth = iframePage.parentNode.clientWidth + "px";

	//紀錄手機大小(旋轉用)
	phone_W = document.body.clientWidth;
	phone_H = document.body.clientHeight;
}


//供上層window進行觸發叫.sam 20200901(初始化語系)
function triggerLang(value) {

	lang = getLang_no();
	try {
		pageinit(location.pathname, value);
		var iframes = document.getElementsByTagName("iframe");
		if (iframes.length > 0) {
			for (var i = 0; i <= iframes.length - 1; i++) {
				frameload(iframes[i], value); //觸發FatherPage當下各個iframe的triggerLang (依據iframe.location.pathname執行), 並更新當下語系值.
			}
		}
	} catch (e) {
	}
}
function t_update() {
	var nowT = new Date();
	var y = nowT.getFullYear();
	var mon = (nowT.getMonth() + 1) < 10 ? "0" + (nowT.getMonth() + 1) : nowT.getMonth() + 1;
	var d = nowT.getDate() < 10 ? "0" + nowT.getDate() : nowT.getDate();
	var h = nowT.getHours() < 10 ? "0" + nowT.getHours() : nowT.getHours();
	var m = nowT.getMinutes() < 10 ? "0" + nowT.getMinutes() : nowT.getMinutes();
	var s = nowT.getSeconds() < 10 ? "0" + nowT.getSeconds() : nowT.getSeconds();
	var w = nowT.getDay();
	document.getElementById("lbT").innerHTML = y + "/" + mon + "/" + d + "[" + getLanguageString(location.pathname, w + 10) + "] " + h + ":" + m + ":" + s;

	if (reloadT != "" && new Date() - reloadT > 1000) {
		location.reload();
		//reloadT=reloadT;
	}
	//定期呼叫警報查詢
	if (new Date() - LastCheckAlarmCountT < 5 * 1000) return;
	LastCheckAlarmCountT = new Date();
	if (nowPage >= 0)
		CheckAlarmCount();
}
var isAlarmPlay = false;
function imgMute_onClick() {
	if (localStorage.isUNMute == 1) {
		localStorage.isUNMute = 0;
		document.getElementById("bgAlarm").pause();
	}
	else {
		localStorage.isUNMute = 1;
		if (isAlarmPlay) document.getElementById("bgAlarm").play();
	}
	document.getElementById("swMute").checked = localStorage.isUNMute == 1;
}
function fullscreen_onClick() {
	if (document.getElementById("trFullScreen").isFull) {
		//退出全屏
		if (document.exitFullscreen) {
			document.exitFullscreen();
		}
		else if (document.mozCancelFullScreen) {
			document.mozCancelFullScreen();
		}
		else if (document.webkitCancelFullScreen) {
			document.webkitCancelFullScreen();
		}
		else if (document.msExitFullscreen) {
			document.msExitFullscreen();
		}
		document.getElementById("trFullScreen").isFull = false;
	}
	else {

		//進入全屏
		var docElm = document.body;
		//W3C 
		if (docElm.requestFullscreen) {
			docElm.requestFullscreen();
		}
		//FireFox 
		else if (docElm.mozRequestFullScreen) {
			docElm.mozRequestFullScreen();
		}
		//Chrome等 
		else if (docElm.webkitRequestFullScreen) {
			docElm.webkitRequestFullScreen();
		}
		//IE11
		else if (elem.msRequestFullscreen) {
			elem.msRequestFullscreen();
		}
		//iPhone
		if (docElm.webkitEnterFullscreen) {
			docElm.webkitEnterFullscreen();
		}
		document.getElementById("trFullScreen").isFull = true;
	}

}
var isShowedOverEndTime = false;
var isShowedUseDay = false;
var isFirstLoginWeb = true;
function CheckAlarmCount() {
	if (nowPage == -1)
		return;
	if (UserIdx == undefined) {
		changePage(-1);
		return;
	}

	SendCmd("LoadAlarmCount", "", function (res) {
		var obj = JSON.parse(res);

		var tbOverEndTime = document.getElementById("tbOverEndTime");
		if (!isShowedOverEndTime && obj.isOverEndTime != undefined) {
			if (obj.isOverEndTime == "OverTime") {
				changePage(-1);
			} else {
				isShowedOverEndTime = true;
				tbOverEndTime.style.display = "";
				if (isJNCServer == 1) {
					document.getElementById("tdOverEndTime").innerHTML = "帳號到期日：" + obj.isOverEndTime + "<br>請撥打專線進行續約：06-3110008";
				} else {
					document.getElementById("tdOverEndTime").innerHTML = "帳號到期日：" + obj.isOverEndTime;
				}

			}
		}
		if (UseDay != "") {
			if (UseDay < 0) {
				document.getElementById("tdServerExpiration").innerHTML = getLanguageString(location.pathname, 19);
				UseDayExpire();
			}
			else {
				document.getElementById("tdServerExpiration").innerHTML = getLanguageString(location.pathname, 18) + ":" + UseDay + "(" + getLanguageString(location.pathname, 20) + ")";
			}
			if (!isShowedUseDay && UseDay < 60) {
				document.getElementById("tbServerExpiration").style.display = "";
				isShowedUseDay = true;
			}
		}

		if (obj.fsVersion != null && obj.fsVersion != fsVersion) {
			location.reload();
		}
		if (nowPage == -1) return;
		document.getElementById("iframeMenu").contentWindow.AlarmCount = obj.AlarmCount;
		//obj.AlarmCount += 1;
		if (obj.AlarmCount > 0) {
			if (localStorage.isUNMute == 1)
				document.getElementById("bgAlarm").play();
		}
		else
			document.getElementById("bgAlarm").pause();
		isAlarmPlay = obj.AlarmCount > 0;
		document.getElementById("iframeMenu").contentWindow.UpdateName = obj.UpdateName;
		document.getElementById("StartSoftTime").style.fontWeight = "bold";
		var serverwork = (lang == "0") ? "伺服器運轉：" : (lang == "1") ? "伺服器运转：" : "Server worked for ";
		var days = (lang == "0") ? "天" : (lang == "1") ? "天" : " days";
		document.getElementById("StartSoftTime").innerHTML = serverwork + Math.round(obj.StartSoftTime * 100) / 100 + days;
		var Left = getLanguageString(location.pathname, 9) + ":";;
		var all = getLanguageString(location.pathname, 17) + ":";
		obj.HardDiskSize = parseFloat(obj.HardDiskSize);
		if (obj.HardDiskSize > 0) {
			document.getElementById("lbHardDisk").innerHTML = Left + obj.HardDiskSize + "GB，" + all + obj.HardDiskTotalSize + "GB";
			var proValue1 = document.getElementById("proValue1");
			if (obj.HardDiskSize < 10)
				proValue1.style.backgroundColor = "#F00";
			else if (obj.HardDiskSize < 30)
				proValue1.style.backgroundColor = "#F60";
			else if (obj.HardDiskSize < 50)
				proValue1.style.backgroundColor = "#FA0";
			else
				proValue1.style.backgroundColor = "#58B";


			proValue1.style.width = 100 - obj.HardDiskSize / obj.HardDiskTotalSize * 100 + "%";
			document.getElementById("lbHardDisk").style.fontWeight = "bold";
			document.getElementById("lbHardDisk").style.color = parseInt(obj.HardDiskSize < 1000) ? "#F00" : "#369";
		}

		UpdateName = obj.UpdateName;

		UseDay = parseInt(obj.UseDay);

		canControl = obj.canControl;
		canEditor = parseInt(obj.canEditor);
		isAdmin = parseInt(obj.isAdmin);
		localStorage.canControl = canControl;
		localStorage.canEditor = canEditor;
		localStorage.isAdmin = isAdmin;

		if (isFirstLoginWeb) {
			if ((localStorage.Name == "" && localStorage.ltMenu == "") || localStorage.Name == null) {
				changePage(-1);
			}
			else
				LogInShow();
			if (document.getElementById("lbMsg").style.display == "none") {
				document.getElementById("iframePage").style.display = "";
			}
			isFirstLoginWeb = false;
		}
		//if (UseDay >= 0)

	});
}
// 授權出錯 ==============================================================================
function UseDayExpire() {
	document.all("iframeUseDayZero").contentWindow.CMD_usbKey_Msg();
}
// 切換頁面 ==============================================================================
var arriPage = new Array(-1, "LogIn.html",
	-2, "0_1_UserUpdate.html",
	//即時數據
	18, "1_1_UserTaiwanMapView.html",
	1, "1_2_UserMapView.html",
	2, "1_3_UserALLView.html",
	4, "1_4_UserModuleState.html",
	//數據分析
	5, "2_1_UserAlarm.html",
	6, "2_2_UserAlarmCount.html",
	7, "2_2_UserTrend.html",
	35, "2_12_DataCount.html",
	8, "2_4_UserReportOutput.html",
	// 19,"2_5_UserCenterWeather.html",
	24, "2_6_UserRegetDeviceData.html",
	25, "2_7_UserUserHis.html",
	29, "2_8_DataShare.html",
	30, "2_9_TrajectoryGraph.html",
	32, "2_10_WindRose.html",
	33, "2_11_IpCamHis.html",
	//設定
	9, "3_1_UserDeviceSet.html",
	10, "3_3_DeviceAlarmSet.html",
	// 11,"" + lang,
	// 12,"" + lang,
	// 13,"",
	39, "3_2_ChMonitorSetting.html",
	16, "3_8_SendAlarmSet.html",
	28, "3_9_Agent.html",
	17, "3_10_UserOtherSet.html",
	//管理
	15, "4_1_UserMail.html",
	31, "4_2_LineBotAlarm.html",
	40, "4_2_CHTSMSAlarm.html",
	38, "4_2_JNCAppAlarm.html",
	36, "4_2_WechatAlarm.html",
	34, "4_4_SIMMBAlarm.html",
	37, "4_5_ViewArchitecture.html",
	14, "4_3_UserPurviewSet4User.html",

	//漁業署報表-----
	20, "Custom/FD_UserReport/FD_1_UserReport.html",
	21, "Custom/FD_UserReport/FD_2_UserReport.html",
	22, "Custom/FD_UserReport/FD_3_UserReport.html",
	23, "Custom/FD_UserReport/FD_4_UserReport.html",
	//太陽能發電廠----
	26, "Custom/SUN/SUN_1_ProjectList.html#",
	27, "Custom/SUN/SUN_2_History.html",
	//-------------
	99, "5_1_UserAbout.html"
);
function changePage(idx) {
	for (var i = 0; i < arriPage.length; i++) {
		if (typeof arriPage[i] != "number") {
			arriPage[i] = arriPage[i] + "?val=" + Date.now() + "#" + lang;
		}
	}
	idx = Number(idx);
	if (idx != -1 && nowPage != null && nowPage != -1 && !ishideinfo)
		localStorage.pageIdx = idx;
	if (nowPage == 1 && iframePage.contentWindow.EditorMode) {
		alert(getLanguageString(location.pathname, 5));
		return nowPage;
	}

	if (UseDay < 0 && idx != 0 && idx != -1) {
		if (document.getElementById("divFirstShowLoad").style.display != "none") {
			document.getElementById("divFirstShowLoad").style.display = "none";
			document.getElementById("divLoadOverShow").style.display = "block";
		}
		return;
	}

	if (nowPage == idx) return;


	var pagesrc = arriPage[arriPage.indexOf(idx) + 1];

	Loadiframe("iframePage", pagesrc);
	switch (idx) {
		case -1:
			document.getElementById("trTitle").style.display = "none";
			document.getElementById("trFoot").style.display = "none";
			localStorageClear();
			document.getElementById("lbAlrCount").innerHTML = "";
			document.getElementById("lbAlrCount").style.backgroundColor = "";
			document.getElementById("iframeMenu").contentWindow.AlarmCount = 0;
			SendCmd("LogOut", "", function () { });
			break;
	}
	if (ishideinfo) {
		document.getElementById("tbMain").style.backgroundColor = "rgba(255,255,255,0)";
	} else {
		document.getElementById("tbMain").style.backgroundColor = idx == -1 ? "#7AD" : "#FFF";
	}

	document.getElementById("lbLoad").style.color = idx == -1 ? "#FFF" : "#666";
	var bt_menu = document.getElementById("bt_menu");
	bt_menu.className = "menu_M";
	bt_menu.isMenuShow = false;
	document.getElementById("iframeMenu").style.display = "none";
	divBlackShow_onClick();


	if (!ishideinfo) {
		localStorage.pageIdx = idx;
	}

	nowPage = idx;
	try {
		document.all("iframeMenu").contentWindow.changePageSetStyle(idx);
	} catch (e) {
		console.log(e);
	}
	localStorage.reloadPage = 0;
	return nowPage;
}
// 載入子頁 ==================================================================================
var t_Loadiframe;
function Loadiframe(id, page) {
	var ipage = document.getElementById(id);
	document.getElementById("lbMsg").style.display = "";
	ipage.style.display = "none";
	ipage.src = page;
	ipage.onload = function () {
		if (document.getElementById("divFirstShowLoad").style.display != "none") {
			document.getElementById("divFirstShowLoad").style.display = "none";
			document.getElementById("divLoadOverShow").style.display = "block";
		}
		if (SendFailTime >= StopReTryTime && showconnectFail) {
			document.getElementById("tb_connectFail").style.display = "";
			ShowDivBlack();
			return;
		}

		var ifDoc = this.contentDocument || {};
		var ifTitle = ifDoc.title;

		if (ifTitle == null) {
			SendFailTime += 1;
			isReadytoLoad = false;
			t_Loadiframe = setInterval(() => t_Loadiframe_tick(page), 500);
		}
		else if (ifTitle.indexOf("404") >= 0 || ifTitle.indexOf("錯誤") >= 0)
			this.src = page;
		else {
			document.getElementById("lbMsg").style.display = "none";
			this.style.display = "";
			if (isphone) {
				RotateMap90(0);
			}

			if (this.iW == null) {
				this.iW = this.clientWidth;
				this.iH = this.clientHeight;
			}
			body_onresize();
		}
	};
}
//只有手機需要轉向
var ScreenAngle = 0;
function RotateMap90(angle) {
	var iframePage = document.getElementById("iframePage");
	var tdMain = document.getElementById("tdMain");
	var mw = tdMain.clientWidth;
	var mh;
	if (ishideinfo) {
		mh = document.body.clientHeight;
	} else {
		mh = document.body.clientHeight - document.getElementById("trTitle").clientHeight - document.getElementById("trFoot").clientHeight;
	}


	if (angle == 0) {
		iframePage.style.transform = "rotate(0deg)";
		iframePage.style.width = mw + "px";
		iframePage.style.height = mh + "px";
		iframePage.style.marginLeft = 0;
	} else if (angle == 90) {
		iframePage.style.transform = "rotate(90deg)";
		iframePage.style.width = mh;
		iframePage.style.height = mw;
		iframePage.style.marginLeft = -(mh - mw) * 0.5;
	}
	ScreenAngle = angle;
	iframePage.style.marginTop = 0;
}
function sleep(ms, fun) {
	sleepT = setInterval(function () { fun(); clearInterval(sleepT); }, ms);
}
function call_ChildPageLoadOver() {
	document.getElementById("lbMsg").style.display = "none";
	document.getElementById("iframePage").style.display = "";
}
var isReadytoLoad;
function t_Loadiframe_tick(page) {
	if (SendFailTime >= StopReTryTime && showconnectFail) {
		document.getElementById("tb_connectFail").style.display = "";
		ShowDivBlack();
		return;
	}
	var obj = document.getElementById("iframePage");
	var ifDoc = obj.contentDocument || {};
	var ifTitle = ifDoc.title;
	if (ifTitle == null && isReadytoLoad) {
		obj.src = page;
		clearInterval(t_Loadiframe);
	}
	isReadytoLoad = true;
}
// 登入 ==================================================================================
function LogInFun(res) {
	if (res == "error" || res == "DelUser") {
		changePage(-1);
		//alert("帳號或密碼錯誤!\n請聯絡系統管理人員協助建立帳號或查詢密碼");
		alert(getLanguageString(location.pathname, 25));
	}
	else if (res == "StopUser") {
		changePage(-1);
		//alert("帳號已被停用!\n請聯絡系統管理人員協助啟用帳號");
		alert(getLanguageString(location.pathname, 26));
	}
	else {
		localStorageClear();
		localStorage.reloadPage = 0;
		var obj = JSON.parse(res);
		isAdmin = parseInt(obj.isAdmin);
		localStorage.isAdmin = isAdmin;
		if (window.location.search.substring(1).indexOf("lang=") == -1) {
			localStorage.setItem("lang_no", obj.Language);
			triggerLang(parseInt(obj.Language));
		}
		if (obj.lastViewPage != "") {
			localStorage.pageIdx = obj.lastViewPage;
		}
		document.getElementById("btLanguage").value = parseInt(obj.Language);
		//將帳號密碼暫存
		if (typeof (Storage) !== "undefined") {
			localStorage.Name = decodeURIComponent(obj.Name);
			localStorage.ltMenu = obj.ltMenu;
			localStorage.canControl = obj.canControl == "True" || obj.canControl == "1" ? 1 : 0;
			localStorage.canEditor = obj.canEditor == "True" || obj.canEditor == "1" ? 1 : 0;
			if (localStorage.pageIdx == null) {
				if (obj.ltMenu.length == 0)
					localStorage.pageIdx = 16;
				else {
					if (obj.ltMenu.indexOf("17") >= 0)
						localStorage.pageIdx = 17 + 1;
					else
						localStorage.pageIdx = parseInt(obj.ltMenu[0]) + 1;
				}
			}
			localStorage.mkey = obj.mKey;
			localStorage.UserIdx = obj.UserIdx;
		}
		else {
			document.all("iframeMenu").contentWindow.purviewShow(localStorage.Name, localStorage.ltMenu);
			document.getElementById("trTitle").style.display = ishideinfo ? "none" : "";
			document.getElementById("trFoot").style.display = ishideinfo ? "none" : "";
			var bt_menu = document.getElementById("bt_menu");
			bt_menu.className = "menu_M";
			bt_menu.isMenuShow = false;
			if (localStorage.pageIdx == null) {
				if (obj.ltMenu.length == 0)
					localStorage.pageIdx = 16
				else {
					if (obj.ltMenu.indexOf("17") >= 0)
						localStorage.pageIdx = 17 + 1;
					else
						localStorage.pageIdx = parseInt(obj.ltMenu[0]) + 1;
				}
			}
		}
		//紀錄快速登入
		if (!isUrlHaveKeyLogin && RemeberLogin) {
			if (localStorage.FstLnName == undefined) localStorage.setItem("FstLnName", "");
			if (localStorage.FstLnIdx == undefined) localStorage.setItem("FstLnIdx", "");
			var FastLoginName = [];
			var FastLoginIdx = [];
			if (localStorage.FstLnName != "" && localStorage.FstLnIdx != "") {
				FastLoginName = localStorage.FstLnName.split(",");
				FastLoginIdx = localStorage.FstLnIdx.split(",");
			}
			if (obj.mKey != undefined && obj.mKey != "") {
				if (FastLoginIdx.indexOf(obj.mKey) == -1) {
					FastLoginName.push(obj.Name);
					FastLoginIdx.push(obj.mKey);
				} else {
					FastLoginName[FastLoginIdx.indexOf(obj.mKey)] = obj.Name;
				}
			}
			localStorage.setItem("FstLnName", FastLoginName.join(","));
			localStorage.setItem("FstLnIdx", FastLoginIdx.join(","));
		}
		LogInShow();
		if (isSetFirstPage) {
			changePage(firstPage);
			isSetFirstPage = false;
		}
	}
}
var line_client_id;
var line_callback_URL;
function LogInShow() {
	if (localStorage.Name != null) {
		UserIdx = localStorage.UserIdx;
		SendCmd("LoginGetMenu", "", function (res) {
			res = JSON.parse(res);
			canControl = localStorage.canControl;
			canEditor = parseInt(localStorage.canEditor);
			localStorage.ltMenu = res.ltMenu;

			//替換帳號管理頁面
			if (UserIdx == "-999" || (isAdmin == 1 && res.ltMenu != null && res.ltMenu.indexOf("13") >= 0)) {
				for (var i = 0; i < arriPage.length; i++) {
					if (arriPage[i] == 14) {
						arriPage[i + 1] = "4_3_UserPurviewSet.html";
					}
				}
			}

			try {
				document.getElementById("iframeMenu").contentWindow.purviewShow();
			} catch (e) { }
			document.getElementById("trTitle").style.display = ishideinfo ? "none" : "";
			document.getElementById("trFoot").style.display = ishideinfo ? "none" : "";
			var bt_menu = document.getElementById("bt_menu");
			bt_menu.className = "menu_M";
			bt_menu.isMenuShow = false;
			var tmpArray = res.ltMenu;

			if (tmpArray == null)
				changePage(-1);
			if (!ishideinfo) {
				localStorage.pageIdx = parseInt(localStorage.pageIdx);
			}

			if (firstPage != -1 && tmpArray.indexOf(firstPage.toString() >= 0)) {
				changePage(firstPage);
			} else {
				if (localStorage.pageIdx == 99 || tmpArray.indexOf((localStorage.pageIdx - 1).toString()) >= 0)
					changePage(localStorage.pageIdx);
				else {
					//預設世界地圖頁面
					if (tmpArray.indexOf("17") >= 0)
						changePage(18);
					else if (tmpArray.length == 0)
						changePage(99);
					else
						changePage(parseInt(tmpArray[0]) + 1);
				}
			}
			//Line綁定提示
			if (tmpArray.indexOf(30)) {
				SendCmd("LineBindTip", "", function (res) {
					if (res != "") {
						res = JSON.parse(res);
						line_client_id = res.client_id;
						line_callback_URL = res.callback_URL;
						document.getElementById("tbLineBindTip").style.display = "";
					}
					CheckAlarmCount();
				});
			}
		});
	}
}
function btLineBind_onClick(idx) {
	switch (idx) {
		case 0://綁定
			var url = encodeURIComponent(window.parent.location.href);
			var state = url + String.fromCharCode(1) + encodeURIComponent(UserIdx);
			window.parent.location.href = "https://notify-bot.line.me/oauth/authorize?response_type=code&client_id=" + line_client_id + "&redirect_uri=" + line_callback_URL + "&scope=notify&state=" + state, "Line Notify";
			break;
		case 1://不綁定不再提示
			if (confirm(getLanguageString(location.pathname, 24))) {
				SendCmd("LineBindCancelTip", "", function (res) { });
			}
			break;
	}
	document.getElementById("tbLineBindTip").style.display = "none";
}
// 與Server溝通 ==========================================================================
function newErrorCmd(mcmd, mstr, mRevFun) {
	this.cmd = mcmd;
	this.str = mstr;
	this.RevFun = mRevFun;
	this.ErrorNum = 0;
}
// 加入一筆資料
function reTryConnectServer() {
	document.getElementById("tb_connectFail").style.display = "none";
	document.getElementById("divBlackShow").style.display = "none";
	SendFailTime = 0;
}

var SendFailTime = 0;
var StopReTryTime = 100;
var ServerLoadData_Max;
var ServerLoadData_loadValue;
//宣告 - 上次發送內容及時間
var lastSend;
//發送
var ActiveRequests = 0;        // 🔹目前進行中的連線數
var MaxActiveRequests = 6;     // 🔹最多允許6條同時連線
var SendCmdQueue = [];         // 🔹等待中的請求佇列

function SendCmd(cmd, str, RevFun, Rev_Parameter, uploadProFun) {
	// 🧩 當同一筆10秒內重複發送則不再執行
	if (lastSend != null) {
		var tmpArr = lastSend.split(",");
		if (new Date().getTime() - tmpArr[0] < 10000 &&
			cmd == decodeURIComponent(tmpArr[1]) &&
			str == decodeURIComponent(tmpArr[2]))
			return;
	}

	// 🧩 若目前連線已達上限，先放進佇列等待
	if (ActiveRequests >= MaxActiveRequests) {
		SendCmdQueue.push([cmd, str, RevFun, Rev_Parameter, uploadProFun]);
		console.warn("目前連線過多（" + ActiveRequests + "/" + MaxActiveRequests + "），排入佇列：" + cmd);
		return;
	}

	lastSend = new Date().getTime() + "," + encodeURIComponent(cmd) + "," + encodeURIComponent(str);

	if (UseDay >= 0 && document.getElementById("iframeUseDayZero").style.display == "") {
		document.getElementById("iframeUseDayZero").style.display = "none";
	}
	if (UseDay < 0 && document.getElementById("iframeUseDayZero").style.display == "none") {
		document.getElementById("iframeUseDayZero").style.display = "";
	}

	if (SendFailTime >= StopReTryTime && showconnectFail) {
		document.getElementById("tb_connectFail").style.display = "";
		ShowDivBlack();
		return;
	}
	if (document.getElementById("tb_connectFail").style.display == "") return;

	var req = getXmlHttp();
	ActiveRequests++; // 🔹開始一條新連線
	req.open("POST", "./" + cmd, true);

	req.onprogress = function (event) {
		if (event.lengthComputable) {
			ServerLoadData_loadValue = event.loaded;
			ServerLoadData_Max = event.total;
		}
	};
	req.upload.onprogress = function (evt) {
		if (uploadProFun == null) return;
		if (evt.lengthComputable) {
			var complete = (evt.loaded / evt.total * 100 | 0);
			uploadProFun(complete);
		}
	};

	req.onreadystatechange = function () {
		if (req.readyState == 4) {
			ActiveRequests = Math.max(0, ActiveRequests - 1); // 🔹結束連線

			if (req.status == 200 || req.status == 400) {
				lastSend = null;
				var res = req.response;
				if (res == "NoLogin") {
					changePage(-1);
					location.reload();
				}
				if (RevFun == "")
					alert(res);
				else if (RevFun && Object.prototype.toString.call(RevFun) == "[object Function]")
					RevFun(res, Rev_Parameter, req.status);
				else
					Receive(RevFun, res);

				SendFailTime = 0;
				req = null;
			} else {
				SendFailTime += 1;
				SendCmd(cmd, str, RevFun, Rev_Parameter, uploadProFun);
			}

			// 🔹嘗試從佇列取出下一筆執行
			if (SendCmdQueue.length > 0) {
				var next = SendCmdQueue.shift();
				setTimeout(function () {
					SendCmd(next[0], next[1], next[2], next[3], next[4]);
				}, 100); // 稍微延遲0.1秒避免瞬間爆發
			}
		}
	};

	if (str == "")
		req.send("UserIdx=" + UserIdx + "&val=" + Math.random());
	else
		req.send(str + "&UserIdx=" + UserIdx + "&val=" + Math.random());
}

function Receive(RevFun, res) {
	switch (RevFun) {
		//主頁面
		case "Main_LoadAlarmCount": //警報查詢
			{
				var obj = JSON.parse(res);
				document.getElementById("iframePage").contentWindow.AlarmCount = obj.AlarmCount;
				break;
			}
		case "LogIn_LogIn":
			{
				LogInFun(res);
				break;
			}
	}
}
function setTitle(str) {
	document.getElementById("lb_title").innerHTML = str;
}
//手機板做一次大小調整
var phoneSizeChangeing = false;
function body_onresize() {
	if (isphone && phoneSizeChangeing) return;
	document.getElementById("divBlackShow").style.height = document.body.clientHeight * (100 / zoomval) - document.getElementById("trTitle").clientHeight * (zoomval / 100) - document.getElementById("trFoot").clientHeight * (zoomval / 100) - 2 + "px";
	document.getElementById("iframePage").style.height = document.getElementById("divBlackShow").style.height;
	document.getElementById("iframeMenu").style.height = document.getElementById("divBlackShow").style.height;
	phoneSizeChangeing = true;
}
//平面圖頁面呼叫使用，完成讀取更改適合的大小
var pagesize = -1;
function PageLoadOver(w, h) {
	if (isphone) {
		pagesize = (document.getElementById("iframePage").clientWidth / w) * 100;
	} else {
		pagesize = (document.body.clientWidth / w) * 100;
	}

	// if(ScreenAngle==0){
	// 	pagesize=(document.body.clientWidth/w)*100;
	// }else{
	// 	pagesize=(document.body.clientHeight/w)*100;
	// }
	iframePagePageSizeChange();
}
function iframePagePageSizeChange() {
	document.getElementById("iframePage").contentWindow.PageSizeChange(pagesize / 101);
}
//讀取Cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function getXmlHttp() {
	var objXMLHttp = null;
	if (window.XMLHttpRequest)
		objXMLHttp = new XMLHttpRequest();
	else if (window.ActiveXObject)
		try { objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	return objXMLHttp;
}

function unzip(b64Data) {
	var strData = atob(b64Data);
	// Convert binary string to character-number array
	var charData = strData.split('').map(function (x) { return x.charCodeAt(0); });
	// Turn number array into byte-array
	var binData = new Uint8Array(charData);
	// // unzip
	var data = pako.inflate(binData);
	// Convert gunzipped byteArray back to ascii string:
	strData = String.fromCharCode.apply(null, new Uint16Array(data));
	return strData;
}
function zip(str) {
	var binaryString = pako.gzip(str, { to: 'string' });
	return btoa(binaryString);
}
function localStorageSpace() {
	var allStrings = '';
	for (var key in window.localStorage) {
		if (window.localStorage.hasOwnProperty(key)) {
			allStrings += window.localStorage[key];
		}
	}
	return allStrings ? 3 + ((allStrings.length * 16) / (8 * 1024)) : 0;
}
function localStorageClear() {
	if (localStorage.UserIdx == undefined) return;

	if (localStorage.FstLnName == undefined) localStorage.setItem("FstLnName", "");
	if (localStorage.FstLnIdx == undefined) localStorage.setItem("FstLnIdx", "");
	var FastLoginName = [];
	var FastLoginIdx = [];
	if (localStorage.FstLnName != "" && localStorage.FstLnIdx != "") {
		FastLoginName = localStorage.FstLnName.split(",");
		FastLoginIdx = localStorage.FstLnIdx.split(",");
	}

	localStorage.clear();

	localStorage.setItem("FstLnName", FastLoginName.join(","));
	localStorage.setItem("FstLnIdx", FastLoginIdx.join(","));
}
//時間計算(日期時間,增減年,增減月,增減日,增減時,增減分,增減秒)
function DateMathAdd(t, y, m, d, h, min, s) {
	var tN = Date.parse(t);
	if (s != undefined && s != null) tN = tN + s * 1000;
	if (min != undefined && min != null) tN = tN + min * 60 * 1000;
	if (h != undefined && h != null) tN = tN + h * 60 * 60 * 1000;
	if (d != undefined && d != null) tN = tN + d * 24 * 60 * 60 * 1000;
	var tmpT = new Date(tN);
	var cM = tmpT.getMonth() + 1 + m;
	//console.log(t.getMonth()+"月增加"+m);
	//============月份處理============
	var tmpDate = tmpT.getDate();
	tmpT.setDate(1);
	while (m != 0) {
		if (m > 0) {
			if (tmpT.getMonth() < 12) {
				tmpT.setMonth(tmpT.getMonth() + 1);
			} else {
				tmpT.setYear(tmpT.getFullYear() + 1);
				tmpT.setMonth(0);
			}
			m = m - 1;
		} else {
			if (tmpT.getMonth() > 0) {
				tmpT.setMonth(tmpT.getMonth() - 1);
			} else {
				tmpT.setYear(tmpT.getFullYear() - 1);
				tmpT.setMonth(11);
			}
			m = m + 1;
		}
	}
	var tmpMonth = tmpT.getMonth();
	tmpT.setDate(tmpDate);
	if (tmpT.getMonth() != tmpMonth) {
		//改成那個月份最後一天
		tmpT.setDate(1);
		tmpT.setMonth(tmpMonth);
		tmpT = new Date(Date.parse(tmpT) + 24 * 60 * 60 * 1000 * 32);
		tmpT.setDate(1);
		tmpT = new Date(Date.parse(tmpT) - 24 * 60 * 60 * 1000 * 1);
	}
	//===============================
	//遇到
	tmpT.setYear(tmpT.getFullYear() + y);
	return tmpT;
}
//瀏覽器觸發上下頁時，頁面清單對應顯示
function IframePageLeave(page) {
	return;//會有誤觸發問題
	setTimeout(function () {
		var tmppt = document.all("iframePage").contentWindow.location.pathname;
		tmppt = tmppt.split("/")[tmppt.split("/").length - 1];
		var idx = null;
		for (var i = 0; i < arriPage.length; i++) {
			if (arriPage[i].toString().indexOf(tmppt) >= 0) {
				idx = arriPage[i - 1];
				break;
			}
		}
		if (nowPage == idx) return;
		if (idx == null || idx == -1) {
			changePage(-1);
			location.reload();
		} else {
			document.all("iframeMenu").contentWindow.changePageSetStyle(idx);
		}
	}, 1000);
}

//preload();

function divBlackShow_onClick() {
	var bt_menu = document.getElementById("bt_menu");
	var iframeMenu = document.getElementById("iframeMenu");
	var divBlackShow = document.getElementById("divBlackShow");
	if (iframeMenu.style.display != "none") {
		bt_menu.className = "menu_M";
		iframeMenu.style.display = "none";
	}
	var tbTool = document.getElementById("tbTool");
	if (tbTool.style.display != "none") {
		tbTool.style.display = "none";
	}
	HideDivBlack();
}
function bt_menu_onClick() {
	document.getElementById("tbTool").style.display = "none";
	var bt_menu = document.getElementById("bt_menu");
	var iframeMenu = document.getElementById("iframeMenu");
	if (bt_menu.isMenuShow == null) bt_menu.isMenuShow = false;
	var divBlackShow = document.getElementById("divBlackShow");
	if (!bt_menu.isMenuShow) {
		bt_menu.className = "menu_M2";
		iframeMenu.style.top = document.getElementById("trTitle").clientHeight + "px";
		iframeMenu.style.height = document.body.clientHeight * (100 / zoomval) - document.getElementById("trTitle").clientHeight * (zoomval / 100) - document.getElementById("trFoot").clientHeight * (zoomval / 100) + "px";
		iframeMenu.style.display = "";
		iframeMenu.className = "menu_show";

		ShowDivBlack()
	} else {
		bt_menu.className = "menu_M";
		iframeMenu.style.display = "none";
		HideDivBlack();
	}
	bt_menu.isMenuShow = !bt_menu.isMenuShow;
}
function ShowDivBlack() {
	var divBlackShow = document.getElementById("divBlackShow");
	if (divBlackShow.style.display == "") return;
	divBlackShow.style.top = document.getElementById("trTitle").clientHeight;
	divBlackShow.style.height = document.body.clientHeight * (100 / zoomval) - document.getElementById("trTitle").clientHeight * (zoomval / 100) - document.getElementById("trFoot").clientHeight * (zoomval / 100) + "px";
	divBlackShow.style.display = "";
	divBlackShow.className = "black50_show";
}
function HideDivBlack() {
	if (document.getElementById("iframeMenu").style.display == "") return;
	if (document.getElementById("tbTool").style.display == "") return;
	if (document.getElementById("tb_connectFail").style.display == "") return;
	document.getElementById("divBlackShow").style.display = "none";
}
function btTool_onclick() {
	var iframeMenu = document.getElementById("iframeMenu");
	if (iframeMenu.style.display == "") {
		iframeMenu.style.display = "none";
		var bt_menu = document.getElementById("bt_menu");
		bt_menu.className = "menu_M";
		bt_menu.isMenuShow = !bt_menu.isMenuShow;
	}

	var tbTool = document.getElementById("tbTool");
	if (tbTool.style.display == "none") {
		tbTool.style.display = "";
		ShowDivBlack()
	} else {
		tbTool.style.display = "none";
		HideDivBlack();
	}
}

function isCB(DeviceType) {
	switch (DeviceType) {
		case "CloudBox":
		case "CWS":
		case "DO16":
		case "IM":
			return true;
	}
	return false;
}

// //可以抓取哪行進行呼叫
// try {
// 	throw new Error();
// } catch (e) {
// 	if (e.stack) {
// 		// var callerLine = e.stack.split("\n")[2];
// 		// var callerFileAndLine = callerLine.match(/\(([^)]+)\)/)[1];
// 		console.log(e.stack);
// 	} else {
// 		console.log("無法取得呼叫資訊");
// 	}
// }