var imServer = getParameter("imserver");
var lvid = getParameter("lvid");
var projectName = getParameter("name");
var md5 = getParameter("md5");
var projectType = getParameter("type");
var projectSize = getParameter("size");
var sign = getParameter("sign");
imServer = getImServer(imServer);
var groupListUrl = imServer + "group/grouplist.action?callback=?";
var CONVERT_GROUP_PROJECT_URL = imServer + "project/transferproject.action?callback=?";
$(document).ready(function() {
	var params = {
		'lvid': lvid,
		'sign': sign
	};
	$.getJSON(groupListUrl, params, function(data) {
		if (data.errorid != 0) {
			//异常
			return;
		}
		var grouplist = data.grouplist.collearray;
		var grouplistTit = data.superlist.collearray;
		if (grouplist.length == 0) {
			var paramStr = "{title:'提示信息',cat:0,content:'您还没有云组，请先创建云组！'}";
			var params = "{command:9006,params:" + paramStr + "}";
			sendCommand(params);
			closeDialogWindow();
			return;
		}
		grouphtml = '';
		$('.copytitle').text('请选择云组');
		var strimg;
		for (var list = 0, len = grouplistTit.length; list < len; list++) {
			grouphtml += '<li class="checklist">';
			grouphtml += '<h4 class="groupTit">' + grouplistTit[list].groupname + '</h4>';
			for (var i = 0, glen = grouplist.length; i < glen; i++) {
				var groupNamelist = grouplist[i]['cloudgroupname'].replaceAll('<', '&lt;').replaceAll('>', '&gt;');
				var groupListimg = grouplist[i]['iconurl'];
				if (groupNamelist.length > 16) {
					groupNamelist = groupNamelist.slice(0, 16) + '...';
				}
				if (groupListimg == undefined) {
					groupListimg = '../images/classic/HEAD-Group-32.png';
				} else {
					groupListimg = grouplist[i]['iconurl'];
				}
				if (grouplistTit[list].id == grouplist[i]['supergroupid']) {
					grouphtml += "<p><label><input type=\"checkbox\" name=\"groupidsc\" value=\"" + grouplist[i]['groupid'] + "\"/><img src=" + groupListimg + " alt='' ><span class=\"groupname\">" + groupNamelist + "</span></label></p>";
				}
			}
			grouphtml += '</li>';
		}
		$("#copyListul").html(grouphtml);
		$('#copyListul h4').click(function() {
			$(this).siblings('p').toggle();
			$(this).toggleClass('Titact');
			$(this).parent().siblings('li').find('p').hide();
			$(this).parent().siblings('li').find('h4').removeClass('Titact');
			if ($("#copyListul li").length < 10) {
				$('.copyObj').css('overflow', 'hidden');
			}
			if ($(this).parent().find('p').length > 10) {
				$('.copyObj').css('overflow-y', 'scroll');
			}
		});
	});
});

/*
 * 执行转换工作
 */
function doConvert() {
	var groupids = "";
	$('input[name="groupidsc"]:checked').each(function() { // 遍历每一个名字为interest的复选框，其中选中的执行函数
		groupids += $(this).val() + ","; // 将选中的值添加到数组chk_value中
	});
	if (groupids == "" || groupids.length < 2) {
		$(".copyPopup").hide();
		return;
	}
	var params = {
		'groupids': groupids,
		'lvid': lvid,
		'sign': sign,
		'filename': projectName,
		'md5': md5,
		'projecttype': projectType,
		'filesize': projectSize
	};

	$.getJSON(CONVERT_GROUP_PROJECT_URL, params, function(data) {
		var tipName = projectName.length > 30 ? projectName.substring(0, 30) + "..." : projectName;
		if (data.errorid == 0) {
			var paramStr = "{title:'提示信息', cat:0, content:'" + tipName + " 发送到云组成功！'}";
			var params = "{command:9006,params:" + paramStr + "}";
			sendCommand(params);
			closeDialogWindow();
		} else {
			var paramStr = "{title:'提示信息',cat:2,content:'" + tipName + " 发送到云组失败，请稍后重试！'}";
			var params = "{command:9006,params:" + paramStr + "}";
			sendCommand(params);
			closeDialogWindow();
		}
	});
}

//关闭对话框
function closeDialogWindow() {
	sendCommand("{command:9001, params:{lvid:" + lvid + "}}");
}