OpcUaLocalServer.prototype._GetServer_ = function(XmlObject)
{
	var Form = $("#Main_Center-Content").find(".Form");
	var ServerName = Form.eq(0).find(".Row").eq(0).find(".Text").val();
	var Port = Form.eq(0).find(".Row").eq(1).find(".Text").val();
	XmlObject["OpcServerConfig"]["UaServerConfig"]["ServerName"] = ServerName + "@[NodeName]";
	XmlObject["OpcServerConfig"]["UaServerConfig"]["UaEndpoint"]["Url"] = "opc.tcp://[NodeName]:" + Port;
};

OpcUaLocalServer.prototype._GetUserIdentityTokens_ = function(XmlObject)
{
	var Form = $("#Main_Center-Content").find(".Form");
	var EnableAnonymous = Form.eq(2).find(".Row").eq(0).find(":checkbox").prop("checked");
	var EnableUserPw = Form.eq(2).find(".Row").eq(1).find(":checkbox").prop("checked");
	var EnableCertificate = Form.eq(2).find(".Row").eq(2).find(":checkbox").prop("checked");

	XmlObject["OpcServerConfig"]["UaServerConfig"]["UserIdentityTokens"]["EnableAnonymous"] = EnableAnonymous;
	XmlObject["OpcServerConfig"]["UaServerConfig"]["UserIdentityTokens"]["EnableUserPw"] = EnableUserPw;
	XmlObject["OpcServerConfig"]["UaServerConfig"]["UserIdentityTokens"]["EnableCertificate"] = EnableCertificate;
};

OpcUaLocalServer.prototype._SetServerUi_ = function(XmlObject)
{
	var ServerName = XmlObject["OpcServerConfig"]["UaServerConfig"]["ServerName"].split("@")[0];
	var Port =  XmlObject["OpcServerConfig"]["UaServerConfig"]["UaEndpoint"]["Url"].split(":")[2];
	var Form = $("#Main_Center-Content").find(".Form");
	Form.eq(0).find(".Row").eq(0).find(".Text").val(ServerName);
	Form.eq(0).find(".Row").eq(1).find(".Text").val(Port);
};

OpcUaLocalServer.prototype._SetUserIdentityTokensUi_ = function(XmlObject)
{
	var EnableAnonymous = JSON.parse(XmlObject["OpcServerConfig"]["UaServerConfig"]["UserIdentityTokens"]["EnableAnonymous"]);
	var EnableUserPw = JSON.parse(XmlObject["OpcServerConfig"]["UaServerConfig"]["UserIdentityTokens"]["EnableUserPw"]);
	var EnableCertificate =  JSON.parse(XmlObject["OpcServerConfig"]["UaServerConfig"]["UserIdentityTokens"]["EnableCertificate"]);

	var Form = $("#Main_Center-Content").find(".Form");
	Form.eq(2).find(".Row").eq(0).find(":checkbox").prop("checked",EnableAnonymous);
	Form.eq(2).find(".Row").eq(1).find(":checkbox").prop("checked",EnableUserPw);
	Form.eq(2).find(".Row").eq(2).find(":checkbox").prop("checked",EnableCertificate);
};

OpcUaLocalServer.prototype._ShowUi_ = function()
{
	var XmlObject = Global_OpcUaLocalServer;
	OpcUaLocalServer.prototype._SetServerUi_(XmlObject);
	OpcUaLocalServer.prototype._SetUserIdentityTokensUi_(XmlObject);
};

OpcUaLocalServer.prototype._SaveServer_ = function(that)
{
	var XmlObject = Global_OpcUaLocalServer;

	var xotree = new XML.ObjTree();
	var xml = xotree.writeXML(XmlObject);
	
	var ssocket = io.connect();
	var array = new Array(xml);
	OpcUaLocalServer.prototype._TransmissionData_(that, array, ssocket);
};

OpcUaLocalServer.prototype._SaveUserIdentityTokens_ = function(that)
{
	var Class = new LoadFile();
	var XmlObject = Global_OpcUaLocalServer;
	OpcUaLocalServer.prototype._GetUserIdentityTokens_(XmlObject);

	var xotree = new XML.ObjTree();
	var xml = xotree.writeXML(XmlObject);

	var ssocket = io.connect();
	var array = new Array(xml);
	OpcUaLocalServer.prototype._TransmissionData_(that, array, ssocket);
};

OpcUaLocalServer.prototype._TransmissionData_ = function(that, array, ssocket)
{
	$(that).closest('.Row').find(".Message").hide();
	$(that).closest('.Row').find(".Loading").show();
	ssocket.emit('SaveOpcUaLocalServer', array);
	ssocket.on('SaveOpcUaLocalServer', function (Return) {
		if(Return == true)
		{
			$(that).closest('.Row').find(".Loading").hide();
			$(that).closest('.Row').find(".Message").eq(0).show();
		}
		else
		{
			$(that).closest('.Row').find(".Loading").hide();
			$(that).closest('.Row').find(".Message").eq(1).show();
		}
		ssocket.emit("SocketClose");
	});
};

OpcUaLocalServer.prototype._CheckPort_ = function(that)
{
	var Port = $(that).closest('.Row').find(".Text").val();
	var Class = new Type();
	if(Class.CheckPositiveIntegers(Port) == false)
	{
		$(that).closest('.Row').find(".Text").val(48010);
	}
	OpcUaLocalServer.prototype._SynchronizeModifyGlobalVariable_("Server");
};

OpcUaLocalServer.prototype._SynchronizeModifyGlobalVariable_ = function(Mode)
{
	var XmlObject = Global_OpcUaLocalServer;
	if(Mode == "Server")
	{
		OpcUaLocalServer.prototype._GetServer_(XmlObject);
	}
	else if("UserIdentityTokens")
	{
		OpcUaLocalServer.prototype._GetUserIdentityTokens_(XmlObject);
	}
};