var faceReg = /\[face:[0-9]*\.gif]/g; // 表情正则表达式
var lvfaceReg = /\[lvface:[\d\D]*\.gif]/g; // 驴表情正则表达式
var imgReg = /\[img:\w+\.(gif|jpg|png|jpeg|bmp|GIF|JPG|PNG|JPEG|BMP)\]/g; // 图片正则表达式
var urlReg = /(http\:\/\/|https\:\/\/){0,1}[\w.\d/\-_]+\.(com|xin|cn|org|wang|club|net)[\w.\d/\-_\?=&:@%\(\)]*/g; // URL地址正则表达式
var urlReg1 = /(http\:\/\/|https\:\/\/)[^\[^\]^,^<^>^\s^\"^\u4E00-\u9FA5\uf900-\ufa2d]*/g; //URL地址正则表达式
var puUrl = /(http\:\/\/|https\:\/\/)[pu.naycent.com][\d\D]*/g;
var projectOldReg = /\[project\:(\d+)\]/g; // 项目ID正则表达式
var projectReg = /\[project\:(\d+)-(.*)\]/; // 项目信息正则表达式
var tupu_projectReg = /^{("tupu_project"(\s*):(\s*){.*})+/; // 图铺项目信息
var tupu_orderReg = /^{("tupu_order"(\s*):(\s*){.*})+/; // 图铺项目信息
var personReg = /\[person:(\d{4,10}|all)-[^\]]*]/g; // 用户正则表达式
var fileReg =  /^{("lv_file"(\s*):(\s*){.*})+/;
var defaultImg = "../images/insertLoading.gif"; // 加载失败后的默认展示图片
var pageArr = new Array();
var page = 1;
var isFirst = true;
var imgArrIn = new Array();
var fileTypeMap = {
	"png": '../images/Type/png.png',
	"jpeg": '../images/Type/jpeg.png',
	"jpg": '../images/Type/jpeg.png',
	"7z": '../images/Type/7z.png',
	'ai': '../images/Type/ai.png',
	'avi': '../images/Type/avi.png',
	'chm': '../images/Type/chm.png',
	'css': '../images/Type/css.png',
	'dll': '../images/Type/dll.png',
	'doc': '../images/Type/doc.png',
	'docx': '../images/Type/docx.png',
	'dv': '../images/Type/dv.png',
	'dwg': '../images/Type/dwg.png',
	'eps': '../images/Type/eps.png',
	'exe': '../images/Type/exe.png',
	'fbx': '../images/Type/fbx.png',
	'flv': '../images/Type/flv.png',
	'folder': '../images/Type/folder.png',
	'gif': '../images/Type/gif.png',
	'html': '../images/Type/html.png',
	'ico': '../images/Type/ico.png',
	'igs': '../images/Type/igs.png',
	'ini': '../images/Type/ini.png',
	'max': '../images/Type/max.png',
	'mid': '../images/Type/mid.png',
	'mov': '../images/Type/mov.png',
	'mp3': '../images/Type/mp3.png',
	'mp4': '../images/Type/mp4.png',
	'mpeg': '../images/Type/mpeg.png',
	'mwv': '../images/Type/mwv.png',
	'obj': '../images/Type/obj.png',
	'pdf': '../images/Type/pdf.png',
	'org': '../images/Type/org.png',
	'ppt': '../images/Type/ppt.png',
	'pptx': '../images/Type/pptx.png',
	'psd': '../images/Type/psd.png',
	'rar': '../images/Type/rar.png',
	'rtf': '../images/Type/rtf.png',
	'stl': '../images/Type/stl.png',
	'swf': '../images/Type/swf.png',
	'txt': '../images/Type/txt.png',
	'url': '../images/Type/url.png',
	'wav': '../images/Type/wav.png',
	'xls': '../images/Type/xls.png',
	'xlsx': '../images/Type/xlsx.png',
	'zip': '../images/Type/zip.png',
	'add file': '../images/Type/add file.png',
	'default': '../images/Type/default.png',
	'js': '../images/Type/js.png'
};
/**
 * 解析聊天信息
 *
 * @param msg
 *            消息体
 */
function parseMsg(msg, tipFlag, lvid, istrue, tolvid) {
	if(!istrue) {
		msg = filterXSS(msg);
	}
	msg = tupu_pro(msg);
	msg = tupu_order(msg);
	msg = parseWordwrap(msg, tipFlag);
	msg = parseUrl(msg);
	msg = parseImg(msg, tipFlag, tolvid);
	msg = parseFace(msg);
	msg = parseLvFace(msg, tipFlag);
	msg = parsePerson(msg, lvid);
	msg = msg.replace(projectReg, tipFlag ? "[项目]" : "").replace(projectOldReg, tipFlag ? "[项目]" : "");
	msg = msg.replace(fileReg,tipFlag ? "[文件]" : "");
	msg = msg.replace(tupu_projectReg,tipFlag ? "[图铺项目]" : "");
	msg = msg.replace(tupu_orderReg,tipFlag ? "[图铺订单提示]" : "");
	return msg;
}

/**
 * 进行XSS
 *
 * @param msg
 */
function filterXSS(msg) {
	msg = msg.replace(/&not/, '&amp;not');
	msg = msg.replaceAll(/</g, '&lt;');
	msg = msg.replaceAll(/>/g, '&gt;');
	return msg;
}

/**
 * 解析换行符
 * 1.如果是tipFlag:true，替换为空格；
 * 2.如果是tipFlag:false，替换为<br/>；
 * 3.如果出现连续换行，剔除一半；
 */
function parseWordwrap(msg, tipFlag) {
	var replaceStr = tipFlag ? " " : '<br/>';
	return msg.replaceAll(/\r\n\r\n/g, "\r\n").replaceAll(/\r\n/g, replaceStr).replaceAll(/\\r\\n/g, replaceStr);
}

/**
 * 解析url地址
 *
 * @param msg
 */
function parseUrl(msg) {
	var urlCache = [];
	var source = msg;
	if(puUrl.test(msg) || puUrl.test(msg)){
		return source;
	}
	msg = msg.replace(/&amp;/, '&').replace(/&nbsp;/g, ' ');
	var urlArr = msg.match(urlReg);
	if(urlArr == null) {
		urlArr = msg.match(urlReg1);
		if(urlArr == null) {
			return source;
		}
	}
	var urlStr, showUrlStr;
	for(var i = 0; i < urlArr.length; i++) {
		urlStr = urlArr[i];
		if($.inArray(urlStr, urlCache) != -1) {
			continue;
		}
		source = source.replaceAll(urlStr, '[[url:' + urlCache.length + ']]');
		urlCache.push(urlStr);
	}
	if(urlCache.length == 0) {
		return source;
	}
	for(var i = 0; i < urlCache.length; i++) {
		urlStr = urlCache[i];
		showUrlStr = urlStr.replace(/&/, '&amp;');
		if(!urlStr.startWith("http://") && !urlStr.startWith("https://")) {
			urlStr = "http://" + urlStr;
		}
		source = source.replaceAll('[[url:' + i + ']]', '<a class="urlread" onclick="clickurl(\'' + urlStr + '\')" href="javascript:0">' + showUrlStr + '</a> ');
	}
	return source;
}

function clickurl(urlStr) {
	var params = "{command:9010, params:{url: " + urlStr + "}}";
	var resultS = sendCommand(params);
}

/**
 * 解析表情
 */
function parseFace(msg) {
	var faceArr = msg.match(faceReg);
	if(faceArr == null) {
		return msg;
	}
	var html = msg;
	var faceStr, faceHtml, lastFaceStr = '';
	for(var i in faceArr) {
		faceStr = faceArr[i];
		if(lastFaceStr == faceStr) {
			continue;
		}
		faceHtml = faceStr.replace('[face:', '<img id="img_" class="imgface imgcut" src="../face/');
		faceHtml = faceHtml.replace(']', '"/>');
		html = html.replaceAll(faceStr, faceHtml);
		lastFaceStr = faceStr;
	}
	return html;
}

//解析图驴表情
function parseLvFace(msg, tipFlag) {
	if(tipFlag) {
		return msg.replace(lvfaceReg, '[符号表情]');
	}
	var faceArr = msg.match(lvfaceReg);
	if(faceArr == null) {
		return msg;
	}
	var html = msg;
	var faceStr, faceHtml, lastFaceStr = '';
	for(var i in faceArr) {
		faceStr = faceArr[i];
		if(lastFaceStr == faceStr) {
			continue;
		}
		faceHtml = faceStr.replaceAll('[lvface:', '<img id="img_" class="imgface imgcut" src="../face/lvface/').replaceAll('&nbsp;', '%20');
		faceHtml = faceHtml.replaceAll(']', '"/>');
		html = html.replaceAll(faceStr, faceHtml);
		lastFaceStr = faceStr;
	}
	return html;
}

/**
 * 解析图片
 */
function parseImg(msg, tipFlag, tolvid) {
	if(tipFlag) {
		return msg.replace(imgReg, '[图片]');
	}
	imgArr = msg.match(imgReg);
	if(imgArr == null) {
		return msg;
	}
	var html = msg;
	var imgStr, img, imgHtml, imgId, lastImgStr = '', imgs, str = '', style, loadPage = 1;
	for(var i in imgArr) {
		imgStr = imgArr[i];
		if(lastImgStr == imgStr) {
			continue;
		}
		if( !tolvid || tolvid == lvid ){
			imgs = defaultImg;
		}else{
			imgs = '../images/uploadImg.gif';
		}
		if( tolvid == lvid ){
			str = '<b class="pic"><i></i></b>';
		}
		img = imgStr.replace('[img:', '').replace(']', '').toLocaleLowerCase();
		imgId = 'img_' + img.substring(0, img.lastIndexOf(".")).toLocaleLowerCase();
		html = html.replaceAll(imgStr, '<span class="par"><img class="imgcut ' + imgId + '" src="' + imgs + '" md5="' + img + '" data-url="'+ requestUrlMap['getChatImg']['url'] +'?md5=' + img + '" onerror="loadImgError(\'' + img + '\')" ondblclick="viewSourceImg(\'' + imgId + '\')" />'+str+'</span>');
		lastImgStr = imgStr;
	}
	return html;
}

/**
 * 解析内容返回图片数组
 */
function parseImgReArr(msg) {
	var imgArr = msg.match(imgReg);
	if(imgArr == null) {
		return [];
	}
	var arr = [];
	var html = msg;
	var imgStr, img, lastImgStr = '';
	for(var i in imgArr) {
		imgStr = imgArr[i];
		if(lastImgStr == imgStr) {
			continue;
		}
		img = imgStr.replace('[img:', '').replace(']', '');
		arr.push(img);
		lastImgStr = imgStr;
	}
	return arr;
}

/**
 * 解析文本样式
 *
 * @param fontStyle
 *            格式化字符串
 */
function parseFontStyle(fontStyle) {
	if(fontStyle && fontStyle.length == 0) {
		return "";
	}
	var fontStyleArr = fontStyle.split(",");
	if(fontStyleArr.length != 4) {
		return "";
	}
	var fontColorStyle = fontStyleArr[3];
	if(fontColorStyle == '[clWindowText]') {
		fontColorStyle = '';
	} else {
		fontColorStyle = parseFontColor(fontColorStyle);
	}
	return 'font-family:' + fontStyleArr[0].replaceAll('"', '') + '; font-size:' + fontStyleArr[1] + 'pt;' + parseBoldItalicUnderline(fontStyleArr[2]) + fontColorStyle;
}

function isItalicStyle(fontStyle) {
	return fontStyle.toLowerCase().indexOf('italic') > -1;
}

function parseBoldItalicUnderline(styleStr) {
	var style = '';
	styleStr = styleStr.toLowerCase();
	if(styleStr.indexOf('bold') > -1) {
		style += 'font-weight: bold;'
	}
	if(styleStr.indexOf('italic') > -1) {
		style += 'font-style: oblique;';
	}
	if(styleStr.indexOf('underline') > -1) {
		style += 'text-decoration: underline;';
	}
	return style;
}

function parseFontColor(fontColorStr) {
	fontColorStr = fontColorStr.toLowerCase().Trim();
	var fontColor = 'color:'
	if(fontColorStr.indexOf('[cl') > -1) {
		fontColor += fontColorStr.replace('[cl', '').replace(']', '');
		return fontColor;
	}
	fontColorStr = fontColorStr.replace('[$00', '').replace(']', '');
	if(fontColorStr.length != 6) {
		return "";
	}
	var redV = fontColorStr.substr(4, 2);
	var greenV = fontColorStr.substr(2, 2);
	var blueV = fontColorStr.substr(0, 2);
	fontColor += '#' + redV + '' + greenV + '' + blueV;
	return fontColor;
}
var persoNum = 100;
function parsePerson(msg, lvid) {
	persoNum = persoNum + 1;
	var personArr = msg.match(personReg);
	if(personArr == null) {
		return msg;
	}
	var html = msg;
	var personStr, personLvid, personHtml, lastPersonStr = '',
		personClass = '';
	var index;
	for(var i in personArr) {
		personStr = personArr[i];
		if(lastPersonStr == personStr) {
			continue;
		}
		index = personStr.indexOf("-");
		personLvid = personStr.substring(personStr.indexOf(":") + 1, index);
		personHtml = "@" + personStr.substr(index + 1);
		personHtml = personHtml.replace(']', ' ');
		personHtml = personHtml.replaceAll(' ', '');
		personClass = personLvid == lvid ? "selfperson" : "person";
		personHtml = '<a id="my_'+persoNum+'" class="' + personClass + '" href="javascript:clickAtMsg(' + personLvid + ')">' + personHtml +"</a>";
		html = html.replaceAll(personStr, personHtml);
		lastPersonStr = personStr;
	}
	return html;
}

/**
 * 解析@信息 
 */
function parsePersonReLvidArr(msg) {
	var personArr = msg.match(personReg);
	if(personArr == null) {
		return null;
	}
	var lvidArr = [];
	var personStr, personLvid, lastPersonStr = '';
	var index;
	for(var i in personArr) {
		personStr = personArr[i];
		if(lastPersonStr == personStr) {
			continue;
		}
		index = personStr.indexOf("-");
		personLvid = personStr.substring(personStr.indexOf(":") + 1, index);
		lvidArr[lvidArr.length] = personLvid;
		lastPersonStr = personStr;
	}
	return lvidArr;
}

/**
 * 解析项目ID
 */
function parseProjectId(msg) {
	var projectInfo = msg.match(projectOldReg);
	if(!projectInfo) {
		return "";
	}
	return projectInfo[0].replace("[project:", "").replace("]", "");
}

/**
 * 解析项目基本信息：ID和标题
 */
function parseProjectBaseInfo(msg) {
	var projectInfo = msg.match(projectReg);
	if(!projectInfo || projectInfo.length != 3) {
		return "";
	}
	if(projectInfo[2].length > 40) {
		projectInfo[2] = projectInfo[2].substr(0, 38) + '...';
	}
	return {
		'id': projectInfo[1],
		'name': projectInfo[2]
	};
}

/**
 * 查看原图
 */
function viewSourceImg(name) {
	var imgObj = $("." + name);
	var src;
	if(imgObj instanceof Array) {
		src = $.toJSON(imgObj[0].attr("src"));
	} else {
		src = $.toJSON(imgObj.attr("src"));
	}
	if(debugStatus) {
		alert(src);
	}
	var imgCutArr = [];
	var md5;
	$(".imgcut").each(function() {
		md5 = $(this).attr("md5");
		if(md5) {
			imgCutArr.push(md5);
		}
	});
	var img = imgObj.attr("md5");
	var index = $.inArray(img, imgCutArr);
	var arrStr = $.toJSON(imgCutArr);
	if(debugStatus) {
		alert(imgCutArr.length);
	}
	var request = '{"command":9007, "params": {"lvid":' + lvid + ', "groupid": ' + groupId + ', "imgurlweb": "' + requestUrlMap['getChatImg']['url'] + '?md5=", "imgarray":' + arrStr + ', "index":' + index + '}}';
	try {
		sendCommand('{command:9015, params:{title:"聊天窗口图片双击查看", content:' + request + ', iswritefile:1}}');
	} catch(e) {}
	sendCommand(request);
}

//通过客户端接口加载图片
function resetImgView() {
	var imgArr = [];
	$("img[data-url]").each(function(i, imgObj) {
		var src = $(imgObj).attr("data-url");
		$(imgObj).removeAttr("data-url");
		if(src) {
			imgArr.push($(imgObj).attr("md5"));
		}
	});
	if(imgArr.length > 0) {
		var params = '{lvid:' + lvid + ', tolvid:' + tolvid + ', groupid:' + groupId + ', "page":"' + pageFlag + '", "imgurlweb":"'+requestUrlMap['getChatImg']['url']+'?md5=", "imgarray":' + $.toJSON(imgArr) + '}';
		sendCommand('{command:9021, params:' + params + '}');
	}
}

/**
 * 修改图片
 * @param imgInfo 图片信息 {"name":"1001", "src": "http://im.2lv.com/dddd", "width": 100, "height": 200}
 */
function changeImg(imgInfo) {
	try {
		sendCommand('{command:9015, params:{title:"修改图片", content:' + $.toJSON(imgInfo) + ', iswritefile:1}}');
	} catch(e) {}
	if(!imgInfo || !imgInfo['name'] || !imgInfo['src']) {
		return -1;
	}
	var md5Name = imgInfo['name'].toLocaleLowerCase();
	var tag = ".img_" + md5Name;
	if(!tag) {
		try {
			sendCommand('{command:9015, params:{title:"修改图片", content:修改图片失败, 未找到该图片' + imgInfo['name'] + ', iswritefile:1}}');
		} catch(e) {}
	}
	$(tag).removeAttr("data-url");
	return loadImg($(tag), imgInfo['src'], [imgInfo['width'], imgInfo['height']], [280,200]);
}

/**
 * 获取图片SRC属性
 */
function getImgSrc(name){
	return $(".img_" + name).attr('src');
}

function loadImgError(img) {
	try {
		sendCommand('{command:9015, params:{title:"加载图片失败", content:"' + img + '", iswritefile:1}}');
		sendCommand('{command:9042, params:{imgid:"'+img+'",tolvid:'+Number(tolvid)+',groupid:'+Number(groupId)+',finish:false}}');
	} catch(e) {}
}

/**
 * 打开文件 
 * @param path 文件路径
 * @param isOpenFolder 是否打开文件夹
 */
function sendOpenFileCmd(path,fid,md5,isOpenFolder) {
	var params = '{lvid:' + lvid + ',  "filename": ' + $.toJSON(path) + ',"fid":'+fid+',"md5":"'+ md5 +'","isopenfolder": ' + isOpenFolder + '}';
	sendCommand('{command:9024, params:' + params + '}');
}
function sendOpenfolderFileCmd(data,isOpenFolder,isdown) {
	data.isOpenFolder = isOpenFolder;
	data.isdown = isdown;
	if(data['filename']){
		data['filename'] = data['filename'].replaceAll('**',' ');
	}
	if(data.pathfilename){
		data.pathfilename = data.pathfilename.replaceAll('**',' ');
	}
	sendCommand('{command:9031, params:' + JSON.stringify(data) + '}');
}

function sendOpenforwardFileCmd(data,isOpenFolder) {
	data.isOpenFolder = isOpenFolder;
	if(!isOpenFolder){
		data.cloudpath = '图驴聊天文件';
	}
	if(data['filename']){
		data['filename'] = data['filename'].replaceAll('**',' ');
	}
	if(data.pathfilename){
		data.pathfilename = data.pathfilename.replaceAll('**',' ');
	}
	sendCommand('{command:9032, params:' + JSON.stringify(data) + '}');
}

function openCloud(name) {
	var params = '{pathname: "/图驴聊天文件/' + name + '" }';
	sendCommand('{command:9025, params:' + params + '}');
}

//文件转发
function forwardFile(data){
	if(data['filename']){
		data['filename'] = data['filename'].replaceAll('**',' ');
	}
	if(data.pathfilename){
		data.pathfilename = data.pathfilename.replaceAll('**',' ');
	}
	sendCommand('{command:9037, params:' + JSON.stringify(data) + '}');
}

//文件菜单
function fileMenu(data){
	if(data['filename']){
		data['filename'] = data['filename'].replaceAll('**',' ');
	}
	if(data.pathfilename){
		data.pathfilename = data.pathfilename.replaceAll('**',' ');
	}
	data.ischat = getParameter("tonickname") ? false : true;
	sendCommand('{command:9036, params:' + JSON.stringify(data) + '}');
}
//下载文件
function fileDownload(data,isOpenFolder){
	data.isOpenFolder = isOpenFolder;
	if(data['filename']){
		data['filename'] = data['filename'].replaceAll('**',' ');
	}
	if(data.pathfilename){
		data.pathfilename = data.pathfilename.replaceAll('**',' ');
	}
	sendCommand('{command:9041, params:' + JSON.stringify(data) + '}');
}

//打开云组
function fileOpenGroup (data){
	if(data['filename']){
		data['filename'] = data['filename'].replaceAll('**',' ');
	}
	if(data.pathfilename){
		data.pathfilename = data.pathfilename.replaceAll('**',' ');
	}
	sendCommand('{command:9043, params:' + JSON.stringify(data) + '}');
}
/**
 * 解析文件
 */
function parseFileHtml(text) {
	if(text.indexOf('\\r\\n')){
		text = text.replaceAll('\\r\\n','');
	}
	if(!fileReg.test(text)){
		return;
	}
	var json = JSON.parse(text);
	var data = json['lv_file'];
	data['tolvid'] = Number(tolvid);
	var fileTransferTip,fileStatusImg,name,ext,fileTypeImg;
	if(data['fileext']){
		ext = data['fileext'].slice(1,15);
		fileTypeImg = fileTypeMap[ext];
		if(!fileTypeImg){
			fileTypeImg = fileTypeMap['default'];
		}
	}else if(data["filetype"] == 0){
		fileTypeImg = fileTypeMap['folder'];
	}else{
		fileTypeImg = fileTypeMap['default'];
	}
	var folder = data["filetype"] == 0 ? '文件夹' : '文件';
	var transtype = data["transtype"];
	var groups,groupName;
	var group = new Array();
	if(data["filemsgtype"] == 2 && data["lvid"] == lvid){
		transtype = 7;
	}else if(data["filemsgtype"] == 2 && data["lvid"] != lvid){
		transtype = 6;
	} else if(data["filemsgtype"] == 1){
		transtype = 8;
	}else if(data['filemsgtype'] == 3){
		groups = data.groupids;
		group = groups.split(',');
		var params = '{groupids:"'+groups+'"}';
		var result = JSON.parse(sendCommand('{command:9044, params:' + params + '}'));
		if(result['errorid'] == 0) {
			groupName = result.namelist.join(',');
		}
		transtype = 9;
	}
	var params = '{lvid:' + tolvid + '}';
	var result = JSON.parse(sendCommand('{command:1017, params:' + params + '}'));
	if(result['errorid'] == 0) {
		name = result['nickname'];
	}
	var pathTrue = false;
	var openTrue = false;
	switch(transtype) {
		case 1:
			pathTrue = true;
			fileTransferTip = '成功发送'+folder+'!';
			fileStatusImg = '../images/success.png';
			break;
		case 2:
			pathTrue = true;
			fileTransferTip = '成功存至' + data["localpath"];
			fileStatusImg = '../images/success.png';
			break;
		case 3:
			fileTransferTip = '您已取消接收'+folder+'';
			fileStatusImg = '../images/imp.png';
			break;
		case 4:
			fileTransferTip = '成功添加到个人云盘/图驴聊天文件';
			fileStatusImg = '../images/success.png';
			break;
		case 5:
			fileTransferTip = '成功发送'+folder+'!';
			fileStatusImg = '../images/success.png';
			break;
		case 6:
			if(data["filemsgtype"] == 2 && data["forwardtype"] == 0){
				openTrue = true;
			}
			fileTransferTip = ''+name+' 对你共享了新'+folder+'!';
			fileStatusImg = '../images/success.png';
			break;
		case 7:
			if(data["filemsgtype"] == 2 && data["forwardtype"] == 0){
				openTrue = true;
			}
			fileTransferTip = '对 '+name+' 共享了新'+folder+'!';
			fileStatusImg = '../images/success.png';
			break;
		case 8:
			fileTransferTip = '已转发该'+folder+'!';
			fileStatusImg = '../images/success.png';
			break;
		case 9:
			if(group.length == 1){
				if(groupName.length >= 14){
					groupName = groupName.slice(0,14)+"..."
				}
			}else{
				if(groupName.length >= 8){
					groupName = groupName.slice(0,8)+"..."
				}
			}
			groups = group.length == 1 ? groupName : groupName +" 等群组";
			fileTransferTip = '成功转存到 '+groups;
			fileStatusImg = '../images/success.png';
			break;
		default:
			fileTransferTip = '出现异常错误!';
			fileStatusImg = '../images/error.png';
			break;
	}
	var html = '<div class="linkBox chatFile" style="margin-left: 10px;">';
	html += '<div class="linkWarp filecont">'
	html += '<div class="linkInfo">';
	var pathfilename = !data['pathfilename'] ? '' : data['pathfilename'];
	var isnot = false;
	var pathfilename;
	pathfilename = !data['pathfilename'] ? data['localpath'] : data['pathfilename'];
	if(!data['pathfilename'] && !data['localpath']){
		pathfilename = '';
	}
	var adress  = pathfilename + data['filename'];
	adress = adress.replaceAll('\\','/');
	var paramStr = {
		'md5':data['filemd5'],
		'filename':data['filename'],
		'path':pathfilename.replaceAll('\\','/'),
		'filetype':data["filetype"]
	}
	var params = "{command:9035,params:" + JSON.stringify(paramStr) + "}";
	var resultS = JSON.parse(sendCommand(params));
	if(resultS.errorid == 0) {
		isnot = resultS.local;
	}
	if(pathTrue){
		if(data["filetype"] == 0 && data["filemsgtype"] == 0 || data["filetype"] == 0 && data["filemsgtype"] == 4){
			html += '<div style="cursor:default" class="linkImg"><img class="typeImg" src='+fileTypeImg+'><img class="successIcon" src='+fileStatusImg+'></div>';
			html += '<div class="linkMessage">';
			html += '<dl>';
				html += '<dt style="padding-left:0px;"><span title='+data["filename"]+' style="font-size:12px">'+data["filename"]+' </span> ('+formatFileSize(data['filesize'])+')</dt>';
				html += '<dd style="padding-left: 0px;"><span title=\'' + fileTransferTip + '\' style="float:left;cursor:default !important" class="linkUpdated">'+fileTransferTip+'</span></dd>';
		}else{
			if(isnot){
				html += '<div class="linkImg" onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', false)"><img class="typeImg" src='+fileTypeImg+'><img class="successIcon" src='+fileStatusImg+'></div>';
				html += '<div class="linkMessage" onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', false)">';
				html += '<dl>';
				html += '<dt style="cursor:pointer;padding-left:0px;"><span title='+data["filename"]+' style="font-size:12px">'+data["filename"]+' </span> ('+formatFileSize(data['filesize'])+')</dt>';
				html += '<dd style="padding-left: 0px;"><span title=\'' + fileTransferTip + '\' style="float:left;" class="linkUpdated">'+fileTransferTip+'</span></dd>';
				
			}else{
				html += '<div onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\', false)" class="linkImg"><img class="typeImg" src='+fileTypeImg+'><img class="successIcon" src='+fileStatusImg+'></div>';
				html += '<div onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\', false)" class="linkMessage">';
				html += '<dl>';
					html += '<dt style="padding-left:0px;cursor:pointer !important"><span title='+data["filename"]+' style="font-size:12px">'+data["filename"]+' </span> ('+formatFileSize(data['filesize'])+')</dt>';
					html += '<dd style="padding-left: 0px;cursor:pointer !important"><span title=\'' + fileTransferTip + '\' style="float:left;" class="linkUpdated">'+fileTransferTip+'</span></dd>';
			}
		}
	}else{
		if(data["filemsgtype"] == 2 || data["filemsgtype"] == 3){
			if(isnot){
				if(data["filetype"] == 0){
					html += '<div class="linkImg" onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',true,false)\'><img class="typeImg" src='+fileTypeImg+'><img class="successIcon" src='+fileStatusImg+'></div>';
					html += '<div class="linkMessage" onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',true,false)\'>';
					html += '<dl>';
						html += '<dt style="cursor:pointer;padding-left:0px;"><span title='+data["filename"]+' style="font-size:12px">'+data["filename"]+' </span> ('+formatFileSize(data['filesize'])+')</dt>';
						html += '<dd style="padding-left: 0px;"><span title=\'' + fileTransferTip + '\' style="float:left;" class="linkUpdated">'+fileTransferTip+'</span></dd>';
				}else{
					if(data["filemsgtype"] == 3){
						html += '<div class="linkImg" onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', false)"><img class="typeImg" src='+fileTypeImg+'><img class="successIcon" src='+fileStatusImg+'></div>';
						html += '<div class="linkMessage" onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', false)">';
					}else{
						html += '<div class="linkImg" onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',false,false)\'><img class="typeImg" src='+fileTypeImg+'><img class="successIcon" src='+fileStatusImg+'></div>';
						html += '<div class="linkMessage" onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',false,false)\'>';
					}
					html += '<dl>';
						html += '<dt style="cursor:pointer;padding-left:0px;"><span title='+data["filename"]+' style="font-size:12px">'+data["filename"]+' </span> ('+formatFileSize(data['filesize'])+')</dt>';
						html += '<dd style="padding-left: 0px;"><span title=\'' + fileTransferTip + '\' style="float:left;" class="linkUpdated">'+fileTransferTip+'</span></dd>';
				}
			}else{
				html += '<div style="cursor:default" class="linkImg"><img class="typeImg" src='+fileTypeImg+'><img class="successIcon" src='+fileStatusImg+'></div>';
				html += '<div class="linkMessage">';
				html += '<dl>';
					html += '<dt style="padding-left:0px;"><span title='+data["filename"]+' style="font-size:12px">'+data["filename"]+' </span> ('+formatFileSize(data['filesize'])+')</dt>';
					html += '<dd style="padding-left: 0px;"><span style="float:left;cursor: text" class="linkUpdated">'+fileTransferTip+'</span></dd>';
			}
		}else{
			html += '<div style="cursor:default" class="linkImg"><img class="typeImg" src='+fileTypeImg+'><img class="successIcon" src='+fileStatusImg+'></div>';
			html += '<div class="linkMessage">';
			html += '<dl>';
				html += '<dt style="padding-left:0px;"><span title='+data["filename"]+' style="font-size:12px">'+data["filename"]+' </span> ('+formatFileSize(data['filesize'])+')</dt>';
				html += '<dd style="padding-left: 0px;"><span style="float:left;cursor: text" class="linkUpdated">'+fileTransferTip+'</span></dd>';
		}
	}
	html += '</dl>';
	html += '</div>';
	html += '<div class="clear"></div>';
	if(data['filename']){
		data['filename'] = data['filename'].replaceAll('&nbsp;','**');
	}
	if(data['pathfilename']){
		data['pathfilename'] = data['pathfilename'].replaceAll('&nbsp;','**');
	}
	// lan
	if(data["filemsgtype"] == 4){
		if(data["filetype"] == 0){
			html += '<div class="linkOpen"><span onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', true)">打开文件夹</span></div>';
		}else{
			html += '<div class="linkOpen"><span  onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', false)">打开</span><span onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', true)">打开文件夹</span></div>';
		}
		return html;
	}
	if(data["filemsgtype"] == 0){ // 默认
		if(transtype == 4){
			html += '<div class="linkOpen"><span onclick=\'sendOpenforwardFileCmd('+JSON.stringify(data)+',false)\'>打开</span><span onclick="openCloud(\'' + data['filename'] + '\')">打开个人云盘</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
		}else if(data["filetype"] == 0){
			html += '<div class="linkOpen"><span onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', true)">打开文件夹</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>'
		}else{
			html += '<div class="linkOpen"><span onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', false)">打开</span><span onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', true)">打开文件夹</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>'
		}
	}else if(data["filemsgtype"] == 1){ //转发
		if(data["origincloud"] != 1){
			if(isnot){
				if(data["filetype"] == 0){
					html += '<div class="linkOpen"><span onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', true)">打开文件夹</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
				}else{
					html += '<div class="linkOpen"><span onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', false)">打开</span><span onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', true)">打开文件夹</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>'
				}
			}else{
				html += '<div class="linkOpen"><span onclick=\'fileDownload('+JSON.stringify(data)+',false)\'>下载</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
			}
		}else{
			switch(data["forwardtype"]){
				case 0:
					html += '<div class="linkOpen"><span onclick=\'sendOpenforwardFileCmd('+JSON.stringify(data)+',true)\'>打开个人云盘</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
					break;
				case 1:
					html += '<div class="linkOpen"><span onclick=\'sendOpenforwardFileCmd('+JSON.stringify(data)+',true)\'>打开企业云盘</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
					break;
				case 2:
					html += '<div class="linkOpen"><span onclick=\'sendOpenforwardFileCmd('+JSON.stringify(data)+',true)\'>打开企业回收站</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
					break;
				default:
					html += '<div class="linkOpen"><span onclick=\'fileDownload('+JSON.stringify(data)+',false)\'>下载</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
			}
		}
	}else if(data["filemsgtype"] == 2){
		if(isnot){
			if(data["filetype"] == 0){
				html += '<div class="linkOpen"><span onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',true,false)\'>打开共享文件夹</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
			}else{
				html += '<div class="linkOpen"><span onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',false,false)\'>打开</span><span onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',true,false)\'>打开共享文件夹</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
			}
		}else{
			html += '<div class="linkOpen"><span onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',false,true)\'>下载</span><span onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',true,false)\'>打开共享文件夹</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
		}
	}else{
		if(isnot){
			html += '<div class="linkOpen"><span onclick="sendOpenFileCmd(\'' + adress +'\',\'' + data['fid'] +'\',\'' + data['filemd5'] +'\', false)">打开</span><span onclick=\'fileOpenGroup('+JSON.stringify(data)+')\'>打开云组</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
		}else{
			html += '<div class="linkOpen"><span onclick=\'sendOpenfolderFileCmd('+JSON.stringify(data)+',false,true)\'>下载</span><span onclick=\'fileOpenGroup('+JSON.stringify(data)+')\'>打开云组</span><span onclick=\'forwardFile('+JSON.stringify(data)+')\'>转发</span><span class="more" onclick=\'fileMenu('+JSON.stringify(data)+')\'></span></div>';
		}
	}
	return html;
}

//判断是否选取内容
function isSelect() {
	return window.getSelection().toString().length > 0;
}



// 图铺项目信息
function tupu_pro(msg){
	if(msg.indexOf('\\r\\n')){
		msg = msg.replaceAll('\\r\\n','');
	}
	if(!tupu_projectReg.test(msg)){
		return msg;
	}
	var json = JSON.parse(msg);
	var data = json['tupu_project'];
	var html = '';
	html += '<div class="tupu_pro">';
	html += '<dl class="clearfix">';
	var imgurl = data.imgurl.replaceAll(' ','').replaceAll('&nbsp;','');
	var linkurl = data.redirecturl.replaceAll(' ','').replaceAll('&nbsp;','');
	html += 	'<dt><img onclick="openTheWindow(this)"  url="'+linkurl+'" src="'+imgurl+'" /></dt>';
	html += '<dd>';
	html += 	'<p class="pu_name">';
	html += 		'<a class="blue" onclick="openTheWindow(this)" url="'+linkurl+'" href="javascript:">'+data.name+'</a>';
	html += 	'</p>';
	html += 	'<p><b class="mon">￥'+data.price+'</b></p>';
	html += '</dd>';
	html += '</dl>';
	html += '</div>';
	return html;
}
// 图铺订单信息
function tupu_order(msg){
	if(msg.indexOf('\\r\\n')){
		msg = msg.replaceAll('\\r\\n','');
	}
	if(!tupu_orderReg.test(msg)){
		return msg;
	}
	var json = JSON.parse(msg);
	var data = json['tupu_order'];
	var html = '';
	html += '<div class="tupu_pro">';
	html += '<dl class="clearfix">';
	var linkurl;
	for(i in data.redirecturl){
		if(data.redirecturl[i].lvid == lvid){
			linkurl = data.redirecturl[i].url.replaceAll(' ','').replaceAll('&nbsp;','');
		}
	}
	var txtmon = data.status == 1 ? '付款金额：' : '待付金额：';
	var orderTime = data.status == 1 ? '成交时间：' : '下单时间：';
	html += 	'<dt><img onclick="openTheWindow(this)" url="'+linkurl+'" alt="" src="'+data.imgurl+'" /></dt>';
	html += '<dd>';
	html += 	'<p>订单编号：<i onclick="openTheWindow(this)" url="'+linkurl+'" class="blue" style="cursor:pointer">'+data.ordernum+'</i></p>';
	html += 	'<p>'+orderTime+'<i>'+$.formatDateStyle4(new Date(data.time*1000))+'</i></p>';
	html += 	'<p>'+txtmon+'<b class="mon">￥'+data['price']+'</b></p>';
	html += '</dd>';
	html += '</dl>';
	html += '</div>';
	return html;
}

/**
 * 定期检测图片加载状态,对失败图片进行重试
 */
var imgLoadCount = {};

function imgLoadCheck() {
	var imgArr = [];
	$(".imgcut").each(function() {
		var src = $(this).attr("src");
		if(src == defaultImg && typeof($(this).attr("data-url"))=="undefined") {
			var md5 = $(this).attr("md5").toLocaleLowerCase();
			var count = imgLoadCount[md5];
			if(!count) {
				imgLoadCount[md5] = 1;
				imgArr.push(md5);
			} else if(count < 3) {
				imgLoadCount[md5] = ++count;
				imgArr.push(md5);
				try {
					sendCommand('{command:9015, params:{title:"重试加载聊天图片", content:"{md5: ' + md5 + ', count: ' + count + '}", iswritefile:1}}');
				} catch(e) {}
			}
		}
	});
	if(imgArr.length == 0) {
		return;
	}
	var params = '{lvid:' + lvid + ', tolvid:' + tolvid + ', groupid:' + groupId + ', "page":"' + pageFlag + '", "imgurlweb":"' + requestUrlMap['getChatImg']['url'] + '?md5=", "imgarray":' + $.toJSON(imgArr) + '}';
	sendCommand('{command:9021, params:' + params + '}');
}
setInterval(imgLoadCheck, 5000);


function openTheWindow(a) {
	var paramStr = "{url:'" + $(a).attr('url') + "'}";
	var params = "{command:9010, params:" + paramStr + "}";
	sendCommand(params);
}