EipToMqttSecondPage.prototype._CheckMqttConnection_ = function(that)
{
	$(that).closest(".RightColumn").find(".Message").hide();
	var MqttConnection=false;
	var Table = $(that).closest(".BrokerTable");
	var Tr = Table.find(".BrokerTr");
	for(var i=0; i<Tr.length; i++)
	{
		var Bool = Tr.eq(i).find(".BrokerTd").eq(0).find(".Checkbox").prop("checked");
		if(Bool == true)
		{
			MqttConnection = true;
			break;
		}
	}
	if(MqttConnection == false)
	{
		$(that).closest(".RightColumn").find(".Message").show();
	}
}

EipToMqttSecondPage.prototype._CheckScanRate_ = function(that)
{
	var ScanRate = $(that).closest(".RightColumn").find(".Text").val();
	var Class = new Type();
	ScanRate = parseInt(ScanRate);
	if(Class.CheckPositiveIntegers(ScanRate) == false)
	{
		$(that).closest(".RightColumn").find(".Text").val(1000);
		return 0;
	}
	if(ScanRate < 100)
	{
		$(that).closest(".RightColumn").find(".Text").val(1000);
		return 0;
	}
	$(that).closest(".RightColumn").find(".Text").val(ScanRate);
}
EipToMqttSecondPage.prototype._CheckDeadBand_ = function(that)
{
	var DeadBand = $(that).closest(".RightColumn").find(".Text").val();
	var Class = new Type();
	DeadBand = parseFloat(DeadBand);
	if(Class.CheckFloat(DeadBand) == false)
	{
		$(that).closest(".RightColumn").find(".Text").val(0);
		return 0;
	}
	if(DeadBand < 0)
	{
		
		$(that).closest(".RightColumn").find(".Text").val(0);
		return 0;
	}
	DeadBand = parseFloat(DeadBand.toFixed(4));
	$(that).closest(".RightColumn").find(".Text").val(DeadBand);
}

EipToMqttUpdatePage.prototype._SaveGlobalVariable_ = function(Row)
{
	var Class = new StepFlow();
	Class.LockAllUi();
	var ssocket = io.connect(), Index=0, Length=Row.length;
	Row.eq(Index).find(".Button").click();
	ssocket.emit("BackgroundExecution");
	ssocket.on("BackgroundExecution", function (Return) {
		if(Row.eq(Index).find(".Message").is(":visible") == true && 
		   Row.eq(Index).find(".Message").css("color") == "rgb(34, 119, 0)")//成功
		{
			Index++;
			Row.eq(Index).find(".Button").click();
			ssocket.emit("BackgroundExecution");
			if(Index==Length)
			{
				ssocket.emit("SocketClose");
				EipToMqttUpdatePage.prototype._ShowFirstPage_();
				Class.UnLockAllUi();
			}
		}
		else if(Index<Length)
		{
			ssocket.emit("BackgroundExecution");
		}
	});
}

EipToMqttUpdatePage.prototype._ShowFirstPage_ = function()
{
	$("#Main_Center-Content").find(".Body").hide();
	$("#Main_Center-Content").find(".Body").eq(1).show();
	EipToMqttFirstPage.prototype._Initialization_();
}
//EIP 轉換按鈕
EipToMqttUpdatePage.prototype._Initialization_ = function()
{
	$("#Main_Center-Content").find(".Body").hide();
	$("#Main_Center-Content").find(".Body").eq(0).show();
	if(EipToMqttUpdatePage.prototype._IsSaveGlobalVariable_() == true)
	{
		EipToMqttUpdatePage.prototype._ShowFirstPage_();
		return 0;
	}
	var Row = $("#Main_Center-Content").find(".Body").eq(0).find(".Table").find(".Row");
	EipToMqttUpdatePage.prototype._SaveGlobalVariable_(Row);
}

EipToMqttUpdatePage.prototype._IsSaveGlobalVariable_ = function()
{
	var Return=false;
	var Class = new Judgment();
	var Bool_1=Class.IsSaveEipMasterModuleGlobalVariable();
	var Bool_2=Class.IsSaveRemoteBrokerGlobalVariable();
	var Bool_3=Class.IsSaveLocalBrokerGlobalVariable();
	if(Bool_1==true && Bool_2==true && Bool_3==true)
	{
		Return = true;
	}
	return Return;
}

EipToMqttUpdatePage.prototype._ShowFirstPage_ = function()
{
	$("#Main_Center-Content").find(".Body").hide();
	$("#Main_Center-Content").find(".Body").eq(1).show();
	EipToMqttFirstPage.prototype._Initialization_();
}















/*啟用, 全選打勾*/
EipToMqttSecondPage.prototype._EnabledChangeAllCheckbox_ = function(that)
{
	var DataModelId = $(that).closest(".Table").attr("id");
	var Bool = $(that).closest(".Row").find(":checkbox").eq(1).prop("checked");
	var Length = $("#"+DataModelId).find(".DynamicRow").length;
	for(var i=0; i<Length; i++)
	{
		$("#"+DataModelId).find(".DynamicRow").eq(i).find(":checkbox").eq(1).prop("checked",Bool);
	}
}

/*保留訊息, 全選打勾*/
EipToMqttSecondPage.prototype._RetainChangeAllCheckbox_ = function(that)
{
	var DataModelId = $(that).closest(".Table").attr("id");
	var Bool = $(that).closest(".Row").find(":checkbox").eq(0).prop("checked");
	var Length = $("#"+DataModelId).find(".DynamicRow").length;
	for(var i=0; i<Length; i++)
	{
		$("#"+DataModelId).find(".DynamicRow").eq(i).find(":checkbox").eq(0).prop("checked",Bool);
	}
}


//單模組全選打勾box
EipToMqttFirstPage.prototype._ChangeCheckbox_ = function(that)
{
	var Bool = $(that).closest(".DynamicRow").find(".Column").eq(4).find(":checkbox").prop("checked");
	var number = $(that).closest(".DynamicRow").find(".Column").eq(0).text();
	if(typeof(Global_EipToMqttVariable[number])!="object"){
		return;
	}
	EipToMqttFirstPage.prototype._InitialEipToMqttSettingObject_(number);
	var SystemVariable = Object.keys(Global_EipVariable[number]);
	for(var i=0; i<SystemVariable.length; i++)
	{
		Global_EipToMqttVariable[number][SystemVariable[i]]["TransformMqtt"] = Bool;
	}
}

EipToMqttFirstPage.prototype._InitialEipToMqttSettingObject_ = function(number)
{
	if(typeof(Global_EipToMqttSetting[number]) == "object")
	{
		return 0;
	}
	Global_EipToMqttSetting[number] = new Object();
	Global_EipToMqttSetting[number]["ScanRate"] = 1000;
	Global_EipToMqttSetting[number]["DeadBand"] = 0;
	Global_EipToMqttSetting[number]["WillTopic"] = "";
	Global_EipToMqttSetting[number]["Will"] = "";
	Global_EipToMqttSetting[number]["MqttConnection"] = new Array("Broker (Local)");
}
//全部模組打勾
EipToMqttFirstPage.prototype._ChangeAllCheckbox_ = function(that)
{
	var ModuleTableId = $(that).closest(".Table").attr("id");
	var Bool = $(that).closest(".Row").find(":checkbox").prop("checked");
	var Element = $("#"+ModuleTableId).find(".DynamicRow");
	for(var i=0; i<Element.length; i++)
	{
		if(Element.eq(i).find(":checkbox").prop("checked") != Bool)
		{
			Element.eq(i).find(":checkbox").prop("checked",Bool);
			var that = Element.eq(i).find(":checkbox");
			EipToMqttFirstPage.prototype._ChangeCheckbox_(that);
		}
	}
}

EipToMqttFirstPage.prototype._ShowPreviousPage_ = function()
{
	var Id = "#ModuleToolbar";
	var CurrentlyPage = $(Id).find(".Text").val();
	$(Id).find(".Text").val(parseInt(CurrentlyPage)-1);
	EipToMqttFirstPage.prototype._RedisplayUi_();
}

EipToMqttFirstPage.prototype._ShowNextPage_ = function()
{
	var Id = "#ModuleToolbar";
	var CurrentlyPage = $(Id).find(".Text").val();
	$(Id).find(".Text").val(parseInt(CurrentlyPage)+1);
	EipToMqttFirstPage.prototype._RedisplayUi_();
}

EipToMqttFirstPage.prototype._SaveEipToMqtt_ = function(Result)
{
	var Result_1={"Input":null}, Result_2={"Input":null};
	var Class = new Transmission();
	Class.TransmissionString("SaveEipToMqttSetting", JSON.stringify(Global_EipToMqttSetting), Result_1);
	Class.TransmissionString("SaveEipToMqttVariable", JSON.stringify(Global_EipToMqttVariable), Result_2);
	var SetInterval = setInterval(function()
	{
		if(Result_1["Input"]==true && Result_2["Input"]==true)
		{
			clearInterval(SetInterval);
			Result["Input"] = true;
			Class = null; delete Class;
		}
	},500);
}

EipToMqttFirstPage.prototype._SaveButton_ = function(that)
{
	$(that).closest('.Row').find(".Loading").show();
	$(that).closest('.Row').find(".Message").hide();
	var Result={"Input":null};
	EipToMqttFirstPage.prototype._SaveEipToMqtt_(Result);
	var SetInterval = setInterval(function()
	{
		if(Result["Input"]==true)
		{
			clearInterval(SetInterval);
			$(that).closest('.Row').find(".Loading").hide();
			$(that).closest('.Row').find(".Message").eq(0).show();
		}
	},500);
}

EipToMqttFirstPage.prototype._Initialization_ = function()
{
	EipToMqttFirstPage.prototype._RedisplayUi_();
}

EipToMqttFirstPage.prototype._RedisplayUi_ = function()
{
	var DisplayNumber = 20;//RTU 20 TCP 40 ASCII 20 Eip 20
	var ObjectKey = EipToMqttFirstPage.prototype._GetAllNumber_();
	EipToMqttFirstPage.prototype._UpdateTableToolbar_(ObjectKey, DisplayNumber);
	EipToMqttFirstPage.prototype._ShowTable_(ObjectKey, DisplayNumber);
	var Id = "#ModuleTable";
	$(Id).find(".Row").eq(0).find(":checkbox").prop("checked",false);
}

EipToMqttFirstPage.prototype._UpdateTableToolbar_ = function(ObjectKey, DisplayNumber)
{
	var NumberOfPages = Math.ceil(ObjectKey.length/DisplayNumber);
	var Id = "#ModuleToolbar";
	$(Id).find("label").eq(1).text(NumberOfPages);
	var CurrentlyPage = $(Id).find(".Text").val();
	CurrentlyPage = parseInt(CurrentlyPage);
	if(CurrentlyPage>NumberOfPages)
	{
		$(Id).find(".Text").val(NumberOfPages);
	}
	else if(CurrentlyPage<=0 || isNaN(CurrentlyPage)==true)
	{
		$(Id).find(".Text").val(1);
	}
	else
	{
		$(Id).find(".Text").val(CurrentlyPage);
	}
}

EipToMqttFirstPage.prototype._ShowTable_ = function(ObjectKey, DisplayNumber)
{
	var AllModuleData = EipToMqttFirstPage.prototype._GetAllModuleData_();
	$("#ModuleTable").find(".DynamicRow").remove();
	var html = $(".Dynamic").html();
	var PageNumber = $("#ModuleToolbar").find(".Text").val();
	var Start = (PageNumber-1)*DisplayNumber;
	if((ObjectKey.length-Start)>DisplayNumber){
		var End = Start + DisplayNumber;
	}
	else{
		var End = ObjectKey.length;
	}
	var index = 0;
	for(var i=Start; i<End && End!=0; i++)
	{
		$("#ModuleTable").append(html);
		$("#ModuleTable").find(".DynamicRow").eq(index).find(".Column").eq(0).text(ObjectKey[i]);
		$("#ModuleTable").find(".DynamicRow").eq(index).find(".Column").eq(1).text(AllModuleData[ObjectKey[i]]["ModuleName"]);
		$("#ModuleTable").find(".DynamicRow").eq(index).find(".Column").eq(2).text(Global_EipSetting[ObjectKey[i]]["NickName"]);
		var Bool = EipToMqttFirstPage.prototype._IsAllTransformMqtt_(ObjectKey[i]);
		$("#ModuleTable").find(".DynamicRow").eq(index).find(".Column").eq(4).find(":checkbox").prop("checked",Bool);
		index++;
	}
}

EipToMqttFirstPage.prototype._GetAllNumber_ = function()
{
	var AllDeviceName = EipToMqttFirstPage.prototype._GetAllDeviceName_();
	var ObjectKey = new Array();
	for(var i=0; i<AllDeviceName.length; i++)
	{
		if(typeof(Global_EipModule[AllDeviceName[i]]) == "object")
		{
			ObjectKey = ObjectKey.concat(Object.keys(Global_EipModule[AllDeviceName[i]]));
		}
	}
	ObjectKey = ObjectKey.sort(function (a, b) {return a - b});
	return ObjectKey;
}

EipToMqttFirstPage.prototype._GetAllModuleData_ = function()
{
	var Return = new Object();
	var DeviceName = Object.keys(Global_EipModule);
	for(var i=0; i<DeviceName.length; i++)
	{
		var nmuber = Object.keys(Global_EipModule[DeviceName[i]]);
		for(var j=0; j<nmuber.length; j++)
		{
			Return[nmuber[j]] = new Object();
			Return[nmuber[j]] = jQuery.parseJSON(JSON.stringify(Global_EipModule[DeviceName[i]][nmuber[j]]));
		}
	}
	return Return;
}

EipToMqttFirstPage.prototype._GetAllDeviceName_ = function()
{
	var Return=Object.keys(Global_EipModule);
	return Return;
}

EipToMqttFirstPage.prototype._IsAllTransformMqtt_ = function(number)
{
	var Return = false;
	if(typeof(Global_EipToMqttVariable[number]) != "object")
	{
		return Return;
	}
	var SystemVariable=Object.keys(Global_EipToMqttVariable[number]);
	if(SystemVariable.length==0)
	{
		return Return;
	}
	for(var i = 0; i < SystemVariable.length; i++)
	{
		if(Global_EipToMqttVariable[number][SystemVariable[i]]["TransformMqtt"]==false)
		{
			return Return;
		}
	}
	Return=true;
	return Return;
}

EipToMqttFirstPage.prototype._EditButton_ = function(that)
{
	$("#Main_Center-Content").find(".Body").eq(2).find(".Message").hide();
	var number = parseInt($(that).closest(".DynamicRow").find(".Column").eq(0).text());
	$("#Main_Center-Content").find(".Body").eq(1).hide();

	EipToMqttSecondPage.prototype._HideColumn_();
	$("#Main_Center-Content").find(".Body").eq(2).show();
	$("#Main_Center-Content").css("border-left-width", "0px");
	$("#Main_Center-Content").css("width", "100%");
	$("#Main_Left-List").hide();
	
	var Name = $("#Main_Center-Content").find(".Body").eq(2).find(".FormTitle").eq(1).text();

	var Class = new Path();
	Class.LoadPathHtml(Name, 2);
	Class = null;
	EipToMqttFirstPage.prototype._InitialEipToMqttSettingObject_(number);
	EipToMqttSecondPage.prototype._LoadBroker_(number);
	EipToMqttSecondPage.prototype._SetInitialValue_(number);
}

EipToMqttFirstPage.prototype._InitialEipToMqttSettingObject_ = function(number)
{
	if(typeof(Global_EipToMqttSetting[number]) == "object")
	{
		return 0;
	}
	Global_EipToMqttSetting[number] = new Object();
	Global_EipToMqttSetting[number]["ScanRate"] = 1000;
	Global_EipToMqttSetting[number]["DeadBand"] = 0;
	Global_EipToMqttSetting[number]["WillTopic"] = "";
	Global_EipToMqttSetting[number]["Will"] = "";
	Global_EipToMqttSetting[number]["MqttConnection"] = new Array("Broker (Local)");
}




















EipToMqttSecondPage.prototype._ModifyEipToMqttSettingObject_ = function(number)
{
	var Row = $("#Main_Center-Content").find(".Body").eq(2).find(".Form").eq(0).find(".Row");

	Global_EipToMqttSetting[number]["ScanRate"] = parseInt(Row.eq(3).find(".RightColumn").find(".Text").val());
	Global_EipToMqttSetting[number]["DeadBand"] = parseFloat(Row.eq(4).find(".RightColumn").find(".Text").val());
	Global_EipToMqttSetting[number]["WillTopic"] = Row.eq(5).find(".RightColumn").find(".Text").val();
	Global_EipToMqttSetting[number]["Will"] = Row.eq(6).find(".RightColumn").find(".Text").val();
	Global_EipToMqttSetting[number]["MqttConnection"] = EipToMqttSecondPage.prototype._GetMqttConnection_();
}

EipToMqttSecondPage.prototype._GetMqttConnection_ = function()
{
	var Return=new Array();  var Bool;
	var BrokerTable = $("#Main_Center-Content").find(".Body").eq(2).find(".Form").eq(0).find(".Row").eq(7).find(".BrokerTable");
	var BrokerTr = BrokerTable.find(".BrokerTr");
	for(var i=0; i<BrokerTr.length; i++)
	{
		Bool = BrokerTr.eq(i).find(".BrokerTd").eq(0).find(".Checkbox").prop("checked");
		if(Bool == true)
		{
			Return.push(BrokerTr.eq(i).find(".BrokerTd").eq(1).text());
		}
	}
	return Return;
}




EipToMqttSecondPage.prototype._ModifyEipToMqttVariableObject_ = function(number)
{
	var Row = $("#VariableTable").find(".DynamicRow");
	for(var i=0; i<Row.length; i++)
	{
		var SystemVariable = Row.eq(i).find(".Column").eq(0).text();
		Global_EipToMqttVariable[number][SystemVariable]["SubscribeTopic"] = Row.eq(i).find(".Column").eq(4).find(".Text").val();
		Global_EipToMqttVariable[number][SystemVariable]["SubscribeQos"] = Row.eq(i).find(".Column").eq(5).find(".Select").val();
		Global_EipToMqttVariable[number][SystemVariable]["PublishTopic"] = Row.eq(i).find(".Column").eq(6).find(".Text").val();
		Global_EipToMqttVariable[number][SystemVariable]["PublishQos"] = Row.eq(i).find(".Column").eq(7).find(".Select").val();
		Global_EipToMqttVariable[number][SystemVariable]["Retain"] = Row.eq(i).find(".Checkbox").eq(0).prop("checked");
		Global_EipToMqttVariable[number][SystemVariable]["TransformMqtt"] = Row.eq(i).find(".Checkbox").eq(1).prop("checked");
	}
}

EipToMqttSecondPage.prototype._ShowColumn_ = function()
{
	$("#VariableTable").find(".Row").find(".TitleColumn").eq(2).show();
	$("#VariableTable").find(".Row").find(".TitleColumn").eq(3).show();
	var DynamicRow = $("#VariableTable").find(".DynamicRow");
	for(var i=0; i<DynamicRow.length; i++)
	{
		DynamicRow.eq(i).find(".Column").eq(2).show();
		DynamicRow.eq(i).find(".Column").eq(3).show();
	}
}

EipToMqttSecondPage.prototype._HideColumn_ = function()
{
	$("#VariableTable").find(".Row").find(".TitleColumn").eq(2).hide();
	$("#VariableTable").find(".Row").find(".TitleColumn").eq(3).hide();
	var DynamicRow = $("#VariableTable").find(".DynamicRow");
	for(var i=0; i<DynamicRow.length; i++)
	{
		DynamicRow.eq(i).find(".Column").eq(2).hide();
		DynamicRow.eq(i).find(".Column").eq(3).hide();
	}
}

EipToMqttSecondPage.prototype._ConfirmButton_ = function(that)
{
	$(that).closest(".Form").find(".Message").hide();
	var Element = $("#Main_Center-Content").find(".Body").eq(2).find(".Message");
	for(var i=0; i<Element.length; i++)
	{
		if(Element.eq(i).is(":visible") == true){
			$(that).closest(".Row").find(".Message").show();
			return 0;
		}
	}
	var ContentSettings = $(".Body").eq(2).find(".Form").eq(0).find(".Row");
	var number = parseInt(ContentSettings.eq(0).find(".Text").val());
	EipToMqttSecondPage.prototype._ModifyEipToMqttVariableObject_(number);
	EipToMqttSecondPage.prototype._ModifyEipToMqttSettingObject_(number);
	$("#Main_Center-Content").find(".Body").eq(2).find(".FormTitle").eq(0).text("");
	$("#Main_Center-Content").find(".Body").eq(2).hide();
	$("#Main_Center-Content").find(".Body").eq(1).show();
	$("#Main_Center-Content").css("border-left-width", "1px");
	$("#Main_Center-Content").css("width", "795px");
	$("#Main_Left-List").show();
	EipToMqttFirstPage.prototype._RedisplayUi_();
	var Class = new Path();
	Class.LoadPathHtml($("#Left-List-EipToMqtt").text(), 1, "main_PathEipToMqtt_click(this)");
	Class = null;
}

EipToMqttSecondPage.prototype._NoConfirmButton_ = function()
{
	$("#Main_Center-Content").find(".Body").eq(2).find(".FormTitle").eq(0).text("");
	$("#Main_Center-Content").find(".Body").eq(2).hide();
	$("#Main_Center-Content").find(".Body").eq(1).show();
	$("#Main_Center-Content").css("border-left-width", "1px");
	$("#Main_Center-Content").css("width", "795px");
	$("#Main_Left-List").show();
	var Class = new Path();
	Class.LoadPathHtml($("#Left-List-EipToMqtt").text(), 1, "main_PathEipToMqtt_click(this)");
	Class = null;
}

EipToMqttSecondPage.prototype._HideColumn_ = function()
{
	$("#VariableTable").find(".Row").find(".TitleColumn").eq(2).hide();
	$("#VariableTable").find(".Row").find(".TitleColumn").eq(3).hide();
	var DynamicRow = $("#VariableTable").find(".DynamicRow");
	for(var i=0; i<DynamicRow.length; i++)
	{
		DynamicRow.eq(i).find(".Column").eq(2).hide();
		DynamicRow.eq(i).find(".Column").eq(3).hide();
	}
}

EipToMqttSecondPage.prototype._LoadBroker_ = function(number)
{
	var Body = $("#Main_Center-Content").find(".Body").eq(2);
	var Html = Body.find(".MqttConnectionDynamic").html();
	var Form = $("#Main_Center-Content").find(".Body").eq(2).find(".Form").eq(0);
	var Row = Form.find(".Row").eq(7);
	var Table = Row.find(".BrokerTable");
	Table.empty();
	var RemoteNumber = Object.keys(Global_RemoteBroker);
	EipToMqttSecondPage.prototype._AddBrokerHtml_(Table, RemoteNumber);
	EipToMqttSecondPage.prototype._SetBrokerValue_(number, Table, RemoteNumber);
}

EipToMqttSecondPage.prototype._AddBrokerHtml_ = function(Table, RemoteNumber)
{
	var Html = $("#Main_Center-Content").find(".Body").eq(2).find(".MqttConnectionDynamic").html();
	$(Table).append(Html);
	for(var i=0; i<RemoteNumber.length; i++)
	{
		$(Table).append(Html);
	}
}

EipToMqttSecondPage.prototype._SetBrokerValue_ = function(number, Table, RemoteNumber)
{
	var obj={Index:0};  var BrokerName;
	var Tr = Table.find(".BrokerTr");
	var BrokerName = Global_EipToMqttSetting[number]["MqttConnection"];
	EipToMqttSecondPage.prototype._SetLocalBrokerName_(Tr, obj, BrokerName);
	EipToMqttSecondPage.prototype._SetRemoteBrokerName_(Tr, obj, RemoteNumber, BrokerName);
	if(Tr.find(".BrokerTd").find(":checked").length == 0)
	{
		Tr.closest(".Row").find(".Message").show();
	}
}

EipToMqttSecondPage.prototype._SetLocalBrokerName_ = function(Tr, obj, BrokerName)
{
	var array = new Array("Broker (Local)");
	var Name = EipToMqttSecondPage.prototype._ArrayInteraction_(BrokerName, array);
	if(Name.length>0)
	{
		Tr.eq(obj.Index).find(".BrokerTd").eq(0).find(".Checkbox").prop("checked",true);
	}
	Tr.eq(obj.Index).find(".BrokerTd").eq(1).text("Broker (Local)");
}

EipToMqttSecondPage.prototype._ArrayInteraction_ = function(FirstArray, SecondArray)
{
	var Return=new Array();
	for(var i=0; i<FirstArray.length; i++){
		if(SecondArray.indexOf(FirstArray[i]) != -1){
			Return.push(FirstArray[i]);
		}
	}
	return Return;
}
EipToMqttSecondPage.prototype._SetRemoteBrokerName_ = function(Tr, obj, RemoteNumber, BrokerName)
{
	for(var i=0; i<RemoteNumber.length; i++)
	{
		obj.Index=obj.Index+1;
		var RemoteBroker = Global_RemoteBroker[RemoteNumber[i]]["Name"];
		var array = new Array(RemoteBroker+" (Remote)");
		Name = EipToMqttSecondPage.prototype._ArrayInteraction_(BrokerName, array);
		if(Name.length>0)
		{
			Tr.eq(obj.Index).find(".BrokerTd").eq(0).find(".Checkbox").prop("checked",true);
		}
		Tr.eq(obj.Index).find(".BrokerTd").eq(1).text(Global_RemoteBroker[RemoteNumber[i]]["Name"]+" (Remote)");
	}
}

EipToMqttSecondPage.prototype._SetInitialValue_ = function(number)
{
	EipToMqttSecondPage.prototype._ClearTable_(number);
	EipToMqttSecondPage.prototype._SetFormInitialValue_(number);
	EipToMqttSecondPage.prototype._SetVariableTableInitialValue_(number);
}

EipToMqttSecondPage.prototype._ClearTable_ = function(number)
{
	$("#VariableTable").find(".Row").eq(0).find(".Checkbox").prop("checked",false);
	$("#VariableTable").find(".DynamicRow").remove();
}

EipToMqttSecondPage.prototype._SetFormInitialValue_ = function(number)
{
	var ModuleName=EipToMqttSecondPage.prototype._GetModuleName_(number);
	var ContentSettings = $(".Body").eq(2).find(".Form").eq(0).find(".Row");
	ContentSettings.eq(0).find(".Text").val(number);
	ContentSettings.eq(1).find(".Text").val(ModuleName);
	ContentSettings.eq(2).find(".Text").val(Global_EipSetting[number]["NickName"]);
	ContentSettings.eq(3).find(".Text").val(Global_EipToMqttSetting[number]["ScanRate"]);
	ContentSettings.eq(4).find(".Text").val(Global_EipToMqttSetting[number]["DeadBand"]);
	ContentSettings.eq(5).find(".Text").val(Global_EipToMqttSetting[number]["WillTopic"]);
	ContentSettings.eq(6).find(".Text").val(Global_EipToMqttSetting[number]["Will"]);
}

EipToMqttSecondPage.prototype._GetModuleName_ = function(number)
{
	var Return="";
	var DeviceName = Object.keys(Global_EipModule);
	for(var i=0; i<DeviceName.length; i++)
	{
		if(typeof(Global_EipModule[DeviceName[i]][number]) == "object")
		{
			Return = Global_EipModule[DeviceName[i]][number]["ModuleName"];
			break;
		}
	}
	return Return;
}

EipToMqttSecondPage.prototype._SetVariableTableInitialValue_ = function(number)
{
	EipToMqttSecondPage.prototype._VariableTableAddNewRow_(number);
	EipToMqttSecondPage.prototype._SetVariableTableNewRowValue_(number);
}

EipToMqttSecondPage.prototype._VariableTableAddNewRow_ = function(number)
{
	if(typeof(Global_EipToMqttVariable[number]) !== "object")	{return 0;}
	var html="", TempHtml = $(".Body").eq(2).find(".Dynamic").html();
	var SystemVariable = parseInt(Global_EipSetting[number]["ModeType"]);
	for(var i=0; i<SystemVariable; i++)
	{
		html = html + TempHtml;
	}
	$("#VariableTable").append(html);
}

EipToMqttSecondPage.prototype._SetVariableTableNewRowValue_ = function(number)
{
	if(typeof(Global_EipToMqttVariable[number]) !== "object")	{return 0;}
	var Variable = Global_EipVariable[number];
	var Class=new Algorithm();
	var SystemVariable = Object.keys(Global_EipToMqttVariable[number]).sort(Class.StringNumberMixedSort());
	var Row = $("#VariableTable").find(".DynamicRow");
	for(var i=0; i<SystemVariable.length; i++){
		Row.eq(i).find(".Column").eq(0).text(SystemVariable[i]);
		Row.eq(i).find(".Column").eq(1).find(".Text").val(Variable[SystemVariable[i]]["VariableName"]);
		var ReadWriteType = EipToMqttSecondPage.prototype._GetReadWriteType_(SystemVariable[i].split("-")[0]);
		if(ReadWriteType == "Read")
		{
			Row.eq(i).find(".Column").eq(4).find(".Text").attr('disabled','disabled');
			Row.eq(i).find(".Column").eq(5).find(".Select").attr('disabled','disabled');
		}
		Row.eq(i).find(".Column").eq(2).find(".Select").val(ReadWriteType);
		Row.eq(i).find(".Column").eq(3).text(SystemVariable[i].split("-")[1]);
		Row.eq(i).find(".Column").eq(4).find(".Text").val(Global_EipToMqttVariable[number][SystemVariable[i]]["SubscribeTopic"]);
		Row.eq(i).find(".Column").eq(5).find(".Select").val(Global_EipToMqttVariable[number][SystemVariable[i]]["SubscribeQos"]);
		Row.eq(i).find(".Column").eq(6).find(".Text").val(Global_EipToMqttVariable[number][SystemVariable[i]]["PublishTopic"]);
		Row.eq(i).find(".Column").eq(7).find(".Select").val(Global_EipToMqttVariable[number][SystemVariable[i]]["PublishQos"]);
		var Bool = Global_EipToMqttVariable[number][SystemVariable[i]]["Retain"];
		Row.eq(i).find(".Column").eq(8).find(".Checkbox").prop("checked",Bool);
		Bool = Global_EipToMqttVariable[number][SystemVariable[i]]["TransformMqtt"];
		Row.eq(i).find(".Column").eq(9).find(".Checkbox").prop("checked",Bool);
	}
}

EipToMqttSecondPage.prototype._GetReadWriteType_ = function(string)
{
	var Return;
	if(string == "DO")			{Return = "ReadWrite";}
	else if(string == "DI")		{Return = "Read";}
	else if(string == "AO")		{Return = "ReadWrite";}
	else if(string == "AI")		{Return = "Read";}
	return Return;
}

EipToMqttSecondPage.prototype._CheckTopic_ = function(that)
{
	$(that).closest(".DynamicRow").find(".Column").eq(4).find(".Message").hide();
	$(that).closest(".DynamicRow").find(".Column").eq(6).find(".Message").hide();
	var Class=new Type();
	var SubscribeTopic = $(that).closest(".DynamicRow").find(".Column").eq(4).find(".Text").val();
	var PublishTopic = $(that).closest(".DynamicRow").find(".Column").eq(6).find(".Text").val();
	var SubscribeTopicDisabled = $(that).closest(".DynamicRow").find(".Column").eq(4).find(".Text").attr('disabled');
	if(Class.CheckMqttTopic(PublishTopic) == false)//檢查PublishTopic
	{
		$(that).closest(".DynamicRow").find(".Column").eq(6).find(".Message").eq(0).show();
	}
	else if(PublishTopic == SubscribeTopic)
	{
		$(that).closest(".DynamicRow").find(".Column").eq(6).find(".Message").eq(1).show();
	}
	if(typeof(SubscribeTopicDisabled)=="undefined" && Class.CheckMqttTopic(SubscribeTopic) == false)//檢查SubscribeTopic
	{
		$(that).closest(".DynamicRow").find(".Column").eq(4).find(".Message").eq(0).show();
	}
	else if(typeof(SubscribeTopicDisabled)=="undefined" && SubscribeTopic == PublishTopic)
	{
		$(that).closest(".DynamicRow").find(".Column").eq(4).find(".Message").eq(1).show();
	}
}