Boot.prototype._Collect_RunAtStartup_Data_ = function()
{
	var Form = $(".Form");
	var Row = Form.eq(1).find(".Row");
	var MainSystem = Row.eq(0).find(":checkbox").prop("checked");
	var MqttBroker = Row.eq(1).find(":checkbox").prop("checked");
	var DDNS = Row.eq(2).find(":checkbox").prop("checked");
	var Return = new Array(MainSystem, MqttBroker, DDNS);
	return Return;
};

Boot.prototype._Transmission_RunAtStartup_Data_ = function(that, array, ssocket)
{
	ssocket.emit('SaveBootAllData', array);
	ssocket.on('SaveBootAllData', function (Return) {
		if(Return == true)
		{
			$(that).closest('.Form').find(".Loading").hide();
			$(that).closest(".Form").find(".Message").eq(0).show();
		}
		else if(Return == false)
		{
			$(that).closest('.Form').find(".Loading").hide();
			$(that).closest(".Form").find(".Message").eq(1).show();
		}
		ssocket.emit("SocketClose");
	});
};

Boot.prototype._Save_RunAtStartup_Data_ = function(that)
{
	$(that).closest('.Form').find(".Message").hide();
	$(that).closest(".Form").find(".Loading").show();
	var array = Boot.prototype._Collect_RunAtStartup_Data_();
	var ssocket = io.connect();
	Boot.prototype._Transmission_RunAtStartup_Data_(that, array, ssocket);
};

Boot.prototype._Reboot_ = function(ssocket)
{
	ssocket.emit('DeviceReboot');
};

Boot.prototype._Polling_ = function(ssocket)
{
	var index = 0;
	var SetInterval = setInterval(function(){
		try{
			if(index < 300){
				ssocket.emit('ServerStarts');
				index = index + 1;
			}
			else{
				clearInterval(SetInterval);
			}
		}
		catch(err){
//設備在300秒內就重啟完畢的話，
//ssocket會被ReceiveServerMessage()關閉，就會出現錯誤訊息
			index = 300;
		}
	},1000);
};
Boot.prototype._ReceiveServerMessage_ = function(that, ssocket)
{
	ssocket.on('ServerStarts', function (Return) {
		if(Return == true)
		{
			$(that).closest(".Form").find(".Loading").hide();
			$(that).closest(".Form").find(".Message").eq(0).show();
		}
		else if(Return == false)
		{
		}
		ssocket.emit("SocketClose");
	});
};

Boot.prototype._DeviceRestart_ = function(that)
{
	$(that).closest(".Form").find(".Message").hide();
	$(that).closest(".Form").find(".Loading").show();
	var ssocket = io.connect();
	Boot.prototype._Reboot_(ssocket);
	Boot.prototype._ReceiveServerMessage_(that, ssocket);
	Boot.prototype._Polling_(ssocket);
};

Boot.prototype._ShowUi_ = function()
{
	var Result={"Input":null};
	var Class = new LoadFile();
	Class.ReadFile("./File/Boot.json", new Object(), Result);
	var SetInterval = setInterval(function()
	{
		if(Result["Input"] != null)
		{
			clearInterval(SetInterval);
			Class = null;
			var object = Result["Input"];
			var Form = $(".Form");
			var Row = Form.eq(1).find(".Row");
			Row.eq(0).find(":checkbox").prop("checked", object["Main System Run at startup"]);
			Row.eq(1).find(":checkbox").prop("checked", object["MQTT Broker Run at startup"]);
			Row.eq(2).find(":checkbox").prop("checked", object["DDNS Run at startup"]);
		}
	},500);
};