OpcuaCertificate.prototype._FileTransmission_= function(that, file)
{
	var ssocket = io.connect();
	var stream = ss.createStream();
	var blobStream = ss.createBlobReadStream(file);
	
	blobStream.on('data', function(chunk) { 
		console.log('data chunk.length:',chunk.length);
	});
	blobStream.on('end', function() {
		$(that).closest(".Row").find(".Loading").eq(0).hide();
		//$(that).closest(".Row").find(".Message").eq(0).show();
		$(that).closest("div").find(":file").val("");
	});
	
	blobStream.pipe(stream);
	ss(ssocket).emit('UploadFile', stream, {name: file.name});
}

OpcuaCertificate.prototype._CheckCertificateFileName_ = function(that, FileName)
{
	var Return=true;
	if(!(FileName.indexOf(".pem") != -1 || 
		 FileName.indexOf(".der") != -1 || 
		 FileName.indexOf(".crt") != -1))
	{
		$(that).closest(".Row").find(".Loading").hide();
		$(that).closest(".Row").find(".Message").eq(1).show();
		Return=false;
		return Return;
	}
	$(that).closest(".Row").find(".Message").hide();
	return Return;
};

OpcuaCertificate.prototype._UploadCertificateFile_ = function(that, Event)
{
	var file = Event.target.files[0];
	if(file == null)	{return 0;}

	$(that).closest(".Row").find(".Message").hide();
	$(that).closest(".Row").find(".Loading").eq(0).show();
	var FileName = file.name;
	$(that).closest("div").find(":text").val(file.name);
	if(OpcuaCertificate.prototype._CheckCertificateFileName_(that, FileName) == false)		{return 0;}
	OpcuaCertificate.prototype._FileTransmission_(that, file);
};

OpcuaCertificate.prototype._UpdateCertificateFile_ = function(that)
{
	var FileName = $(that).closest("div").find(":text").val();
	$(that).closest("div").find(":text").val("");
	$(that).closest(".Row").find(".Message").hide();
	$(that).closest(".Row").find(".Loading").eq(1).show();
	var ssocket = io.connect();
	ssocket.emit("UpdateOpcuaTrustedCertificate", FileName);
	ssocket.on("UpdateOpcuaTrustedCertificate", function (Return) {
		if(Return == true)
		{
			$(that).closest(".Row").find(".Loading").hide();
			$(that).closest(".Row").find(".Message").eq(3).show();
		}
		else{
			$(that).closest(".Row").find(".Loading").hide();
			$(that).closest(".Row").find(".Message").eq(4).show();
		}
		ssocket.emit("SocketClose");
	});
};

OpcuaCertificate.prototype._RemoveTrustedCertificateFile_ = function(that)
{
	$(that).closest('.Row').find(".Loading").show();
	$(that).closest('.Row').find(".Message").hide();
	var ssocket = io.connect();
	ssocket.emit("RemoveOpcuaTrustedCertificate");
	ssocket.on("RemoveOpcuaTrustedCertificate", 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");
	});
};

OpcuaCertificate.prototype._RemoveServerCertificateFile_ = function(that)
{
	$(that).closest('.Row').find(".Loading").show();
	$(that).closest('.Row').find(".Message").hide();
	var ssocket = io.connect();
	ssocket.emit("RemoveOpcuaServerCertificate");
	ssocket.on("RemoveOpcuaServerCertificate", 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");
	});
};

OpcuaCertificate.prototype._DownloadCertificateFile_ = function(that)
{
	$(that).closest('.Row').find(".Loading").show();
	$(that).closest('.Row').find(".Message").hide();
	var ssocket = io.connect();
	ssocket.emit("DownloadOpcuaServerCertificate");
	ssocket.on("DownloadOpcuaServerCertificate", function (Return) {
		if(Return == true)
		{
			location.href='/DownloadFile/Certificate_'+location.hostname+'_.tar';
			var array = new Array();
			array[0]=180;
			ssocket.emit("DeleteTarFile", array);
		}
		ssocket.emit("SocketClose");
	});
};