var dumpContract = function() {
	if (global.contractInstance == undefined){
		myToast("失败","请选择合约实例");
		return;
	}

	var request = {};
	request.action = "dumpContract";
	request.contractID = global.instanceName;
	console.log(request);
	global.wssocket.send(JSON.stringify(request));
};

var onDumpContract = function(obj) {
	obj_label = document.getElementById("recoverResult");
	var show = "保存合约状态" + obj.data + ",状态文件大小" + obj.size + ",保存用时" + obj.time;
	obj_label.value = show;
	listMemoryFiles();
};

var listMemoryFiles = function(){
	console.log("listMemoryFiles");
	if(global.instanceName == undefined || global.instanceName == ""){
		return;
	}
	var request = {};
	request.action = "listMemoryFiles";
	request.contractID = global.instanceName;
	console.log(request);
	global.wssocket.send(JSON.stringify(request));
};

var onListMemoryFiles = function(obj){
	var files = obj.data;
	console.log(files);
	if(files == undefined || files.length == 0){
		var htm = "<option selected>选择时间</option>";
		$("#selectMemeryFiles").html(htm);
		return;
	}

	var htm = "";
	if(files.length > 0){
		for (var i = 0; i < files.length; i++) {
			console.log(files[i]);
			htm += "<option selected>" + files[i] + "</option>";
		}
	}
	htm += "<option selected>选择时间</option>";
	console.log(htm);

	$("#selectMemeryFiles").html(htm);
	changeMemeryFiles($("#selectMemeryFiles")[0].value);
};

var transferTo = function(){
	var memoryFile = $("#selectMemeryFiles")[0].value;
	if(memoryFile == "选择时间"){
		myToast("提示","请选择时间!");
		return;
	}

	var request = {};
	request.action = "loadMemory";
	request.contractName = global.instanceName;
	request.memoryFile = memoryFile;
	console.log(request);
	global.wssocket.send(JSON.stringify(request));
};

var onTransferTo = function(obj){
	obj_label = document.getElementById("recoverResult");
	var show = "合约状态迁移" + obj.data + ",状态文件大小" + obj.size + ",迁移用时" + obj.time;
	obj_label.value = show;
	listMemoryFiles();
};



var getSyncType = function(contractName){
	var request = {};
	request.action = "getSyncType";
	request.contractName = contractName;
	console.log(request);
	global.wssocket.send(JSON.stringify(request));
};

var onGetSyncType = function(obj){
	if(obj.data == "Memory" || obj.data == "Trace" || obj.data == "Trans"){
		global.contractSynType = obj.data;
		obj_label = document.getElementById("syncResult");
		var show = "合约  " + global.instanceName + " 的同步机制策略为  " + obj.data;
		obj_label.value = show;
	}else
		global.contractSynType = "failed";
};