var hj5107 = new Object();
hj5107.swf = true;
hj5107.proxyLoad = 0;
hj5107.voiceAltDivId = null;
/**
 * 窗口大小控制.
 */
function resizeWindow()
{	
	
	
	var clientWidth = document.body.clientWidth>630 ? document.body.clientWidth : 630;
	var clentHeight = document.body.clientHeight>470 ? document.body.clientHeight : 470;

	$("#chat").width(clientWidth); 
	$("#chat").height(clentHeight);
	
	$("#main").width($("#chat").width()-13); 
	$("#main").height($("#chat").height()-110); 
	
	$("#main").height($("#chat").height()-110);

//	$("#objInput").width($("#inputDiv").width() - 5);

	$("#mqAd").width($("#scrollId").width() - 80);

	$("#leaveMsgIframe").height($("#Content").height());
	hidePanel();
	if (theme == 0) {
		//第一套对话窗口.
		$("#Content").height($("#chat").height()-120);

		$("#left").height($("#Content").height());
		$("#imgAd").height($("#Content").height());

		$("#view").height($("#Content").height()-145);
		$("#view_kbs").height($("#Content").height()-145);
		//语音视频状态.
		if ((statusVoice == 2 || statusVideo == 2) && tabSelected == 0) {
			$("#Content").width($("#chat").width()-230);
			$("#Content").css('left',0);
			$("#view").width($("#Content").width());
			$("#left").hide();
			
			$("#video").show();
			$("#video").height($("#Content").height());
			$("#video").css("left",$("#Content").width()+5);
			$("#divFlashChat").css("left", $("#Content").width()+10)
			showFlsh(1);			
		}else{
			$("#Content").width($("#chat").width()-167);
			$("#view").width($("#Content").width());		
			$("#left").show();
			$("#video").hide();
			$("#Content").css('left',155);
				showFlsh(0);					
		}		
//		return false;
	}else if(theme == 1){
		//第二套对话窗口.
		
		showOpCard(defaultTab);
//		return false;		
	}

	if (debug) {
		$("#debugDiv").css('top', $("#chat").height());
	}
	return false;
}

/**
 * 页面初始化.
 */
function pageInit(){

	if (userData != '' && userData != '||||||||')
	{
		inputInfo = 1;
		saveInfo=1;
		checkNick();
	}
	else 
	{
		if ( isSavedInfo != -1 ) {
			exportDebugInfo("pageInit", "isSavedInfo", isSavedInfo);
			exportDebugInfo("pageInit", "requestType", requestType);
			if (requestType == 0 || requestType == 3) {
				//需要输入信息.
				exportDebugInfo("pageInit", "inputInfo", inputInfo);
				exportDebugInfo("pageInit", "selectType", selectType);
				if (inputInfo == 1) {
					if(isSavedInfo == 1) {
						if (selectType == 1) {
							//如果不需要选择类别.
							$("#view").show();
							sendTalkAskToFlash(encodeURIComponent(visitorName), defaultDep, defaultDep);
						}else{
							//需要选择类别.
							$("#view").show();
							showDepartmentList();
						}
					}else{
						//显示访客信息输入.
						$("#visitorInfoInputDiv").show();
					}
				} else {
					if (selectType == 1) {
						//如果不需要选择类别，不需要输入访客信息.
						saveInfo = 0;
						visitorInfo = -1;
						$("#view").show();
						sendTalkAskToFlash(encodeURIComponent(visitorName), defaultBsDep, defaultDep);
					}else{
						//需要选择类别.
						$("#view").show();
						showDepartmentList();
						
					}
				}
			} else if (requestType == 1 || requestType == 2) {
				//需要输入信息.
				if (inputInfo == 1) {
					//信息已经保存.
					if(isSavedInfo == 1) {
						$("#view").show();
						sendTalkAskToFlash(encodeURIComponent(visitorName), depId, depId);
					}else{
						showInputVisitorInfo();
					}
				} else {
					//如果不需要输入信息.
					$("#view").show();
					sendTalkAskToFlash(encodeURIComponent(visitorName), depId, depId);
				}
			}
		} else {
			setTimeout(function(){pageInit();}, 20);
		}
	}
}

/**
 * 显示访客信息输入部分.
 */
function showInputVisitorInfo() { 
	$("#visitorInfoInputDiv").show();
}

/**
 * 根据ID取得元素对象.
 */
function hjget(id) {
	if (document.getElementById(id)) {
		return document.getElementById(id);
	} else {
		return "";
	}
}

/**
 * 修改发送消息的快捷键 .
 */
//When objInput on key down.
function inputKeyDown(eventTag) {	
	//if (timerOpWait != null) clearTimeout(timerOpWait);	
	//timerOpWait = setTimeout("ifContinueChat()", maxOpWaitTime*1000);
   var event = arguments[0]||window.event; 
   var keyCode = event.charCode||event.keyCode;
   var srcElement =event.target||window.event.srcElement;
   
   if (event.keyCode == 88){
		if(event.ctrlKey && event.shiftKey) {	
			return false;
		}
	}
   
	if (event.keyCode == 13 && sendKey == 0){
		if (event.ctrlKey || event.shiftKey) {
			try{
			if(document.createRange){
				var tR = document.createRange();
			}else{
				var tR = document.selection.createRange();
			}
			//alert(dump(tR));
			//tR=document.selection.createRange();
 			tR.text = "\r\n";
			tR.collapse(false);
			tR.select();		
			return false;
			}catch(e){}
		}else{
			if (tabSelected == 1)
			{
				sendText_kbs();
			}
			else
			{
				sendText();
			}
			return false;
		}
	}else{
		if (event.keyCode == 13 && sendKey == 1) {
			if (event.ctrlKey || event.shiftKey){
				if (tabSelected == 1)
				{
					sendText_kbs();
				}
				else
				{
					sendText();
				}
				return false;			
			}else{
				try{
				if(document.createRange){
					var tR = document.createRange();
				}else{
					var tR = document.selection.createRange();
				}
				//tR=document.selection.createRange();
 				tR.text = "\r\n";
				tR.collapse(false);
				tR.select();		
				return false;
							}catch(e){}
			}		
		}
	} 
	
	//Only enabled key ctrl+z,ctrl+x,ctrl+v,ctrl+c,ctrl+enter.
	if (event.ctrlKey && (srcElement.id != "objInput" && srcElement.id != "objInput_kbs"  || 
								((srcElement.id == "objInput" || srcElement.id == "objInput_kbs")
									&& event.keyCode != 65 
									&& event.keyCode != 67 
									&& event.keyCode != 86 
									&& event.keyCode != 88 
									&& event.keyCode != 89 
									&& event.keyCode != 90))) {
		try {
			event.keyCode=0;
		} catch(e) {
		}
		if (event.returnValue) event.returnValue=false;	    
	}
}

/**
 * 输入信息处理，去除一些复制过来的html标签等.
 */
function inputPaste() {
	var txtBoard = clipboardData.getData('text');
	if (txtBoard != 'undefined') {
		txtBoard = txtBoard.replace(/<[^<]+>/g, "");
		var tR = document.selection.createRange();
 		tR.text = txtBoard;
		tR.collapse(false);
		tR.select();			
	}
	
	return false;
}

/**
 * 发送消息处理，控制发送消息的颜色，字体，是否加超链接等.
 */
//Send message.
function sendText() {
	//if (statusChat != 1) return false;
//	if (isIE) var objectInput = hjget("objInput");
//	else var objectInput = objInput.document.body;
	var objectInput = hjget("objInput");
	var txtContent 			= objectInput.innerHTML;
	var txtFontFamily 		= objectInput.style.fontFamily;
	var txtFontSize 		= objectInput.style.fontSize;
	var txtColor 			= objectInput.style.color;		
	var txtFontStyle 		= objectInput.style.fontStyle;
	var txtFontWeight 		= objectInput.style.fontWeight;
	var txtTextDecoration 	= objectInput.style.textDecoration;

	if (txtFontFamily.length == 0) txtFontFamily = "simsun";
	if (txtFontSize.length == 0) txtFontSize = "12";
	if (txtColor.length == 0) txtColor = "#000000";	
	if (txtFontStyle.length == 0) txtFontStyle = "normal";
	if (txtFontWeight.length == 0) txtFontWeight = "normal";
	if (txtTextDecoration.length == 0) txtTextDecoration = "none";
	
	if (opId == "-1") {
		var chatType = 0;
	} else {
		var chatType = 1;
	}
	
	if (txtContent.replace(/(&nbsp;)|( )|(<br>)|(<br \/>)|(<BR>)|(<BR \/>)/g, "").length > 0) {
		txtContent = txtContent.replace(/\\f/g, '/f');
		txtContent = txtContent.replace(/\\b/g, '/b');
		if (txtContent.replace(/<[^<]+>/g, "").length > 500) {
			txtContent = txtContent.substr(0, txtContent.length-(txtContent.replace(/<[^<]+>/g, "").length-500));
			while(txtContent.replace(/<[^<]+>/g, "").length > 500) {
				txtContent = txtContent.substr(0, txtContent.length-100);
			}
		}

		// 访客输入内容显示.
		var txtContentFull = "<span style='font-family:"+ txtFontFamily 
								+ "; font-style:"+ txtFontStyle 
								+ "; font-size:"+ txtFontSize 
								+ "; text-decoration:"+ txtTextDecoration 
								+ "; font-weight:"+ txtFontWeight 
								+ "; color:"+ txtColor 
								+";line-height:100%'>" + txtContent + "</span>";
		
		if (0) {//statusChat != 1
			var strAnswer = "";
			//alert("qt=2&n=10&rst=3&c="+ company +"&q="+encodeURIComponent(txtContent));
			 $.ajax({
				 type: "GET",
				 url: urlKBS,
				 data: "qt=2&n=10&rst=3&t=2&c="+ company +"&q="+encodeURIComponent(txtContent),
				 dataType: "json",
				 success: function(rs){       
				 	//alert( "Data Saved: " + msg );     
					//eval("rs="+msg);
					//alert(rs.rc);
					if (rs.rs.length > 1) {
						$.each(rs.rs,function(i){
							//alert(this.id+":"+this.q+":"+this.a);
							strAnswer += "&#8226;"+ this.q +":<br />&nbsp;&nbsp;<span style='color:#666'>"+this.a+"</span><br />";
						});
					} else {
						if (rs.rs[0].id == 0)
							strAnswer = lang.kbsNoAnswer+"<br />";
						else 
							strAnswer = rs.rs[0].q+":<br />"+rs.rs[0].a+"<br />";
					}
					
					strAnswer += "<span style='color:#666' >["+lang.initChatNotTrust1+operatorName+lang.initChatNotTrust2+"<a href='#' onclick='loadChat(); return false;' >"+lang.initChatCS+"</a>]</span>";
					
					exportLog(strAnswer, 2);
				}   
			}); 
		} else {
			try{
				callFlashChat("flashChat").callFlashFun("chatMsg", opId, chatType, txtContentFull);
			}catch(e){
			}
		}
		
		if (visterWaitOpTime != 0) 
		{
			clearTimeout(requestTime);
			requestTime = setTimeout(function(){requestTimeOver();}, visterWaitOpTime*1000);
		}
		
		exportLog(txtContentFull, 1);
		exportDebugInfo("callFlashChat", "chatMsg", opId, chatType, txtContentFull);
		
		objectInput.innerHTML = "&nbsp;";
		window.focus();
		objectInput.focus();
	}
	
	timerOpWait = opWaitTime;
	opWaitVisitorTime = opWaitTime;
}

/**
 * 初始化机器人状态.
 */
function loadChat() {
	statusKBS = 1;
}

/**
 * 取得当前时间（时分秒）.
 */
function getNowTime() {
	var txtTime = "";
	var objDate = new Date();
	
	if (objDate.getHours() < 10) txtTime = "0" + objDate.getHours();
	else  txtTime = objDate.getHours();
	
	if (objDate.getMinutes() < 10) txtTime += ":0" + objDate.getMinutes();
	else  txtTime += ":" + objDate.getMinutes();
	
	if (objDate.getSeconds() < 10) txtTime += ":0" + objDate.getSeconds();
	else  txtTime += ":" + objDate.getSeconds();
	
	return txtTime;
}

/**
 * 显示聊天记录.
 */
//Write message into LogDiv.
function exportLog(txt, type) {
	try {
		var txtLog = "";
		var txtTime = getNowTime();
		switch(type) {
			case -1:
				txtLog = txt;
				break;
			case 0:
				txtLog = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'>"
							+"<span class='systemInfo'> " + txt +"</span>";
				break;
			case 1:
				txtLog = "<span class='vstChatTitle'>"+ visitorName + " " + txtTime + "</span><br /><div class='chatContent'>" + txt + "</div>";
				break;
			case 2:
				txtLog = "<span class='opChatTitle'>"+ operatorName + " " + txtTime + "</span><br /><div class='chatContent'>" + txt + "</div>";
				break;
		}
		
		var rowLog = hjget("tabLog").insertRow(-1);
		if ((type == -1 || type == 0) && typeof(arguments[2]) != "undefined") {			
			rowLog.id = arguments[2];
		}
		var tdLog = rowLog.insertCell(0);
		tdLog.innerHTML = txtLog;
		
		if (type == 1 || type == 2 || type == -1) {
			var logAnchors = tdLog.getElementsByTagName("a");		 
			for (var i=0; i<logAnchors.length; i++) { 
				logAnchors[i].target = "_blank";
			}
			var logAnchors = tdLog.getElementsByTagName("A");		 
			for (var i=0; i<logAnchors.length; i++) { 
				logAnchors[i].target = "_blank";
			}
		}
		
		hjget("divLog").scrollTop = hjget("tabLog").scrollHeight;
		//window.focus();
		hjget("objInput").focus();
		exportDebugInfo('exportLog', txt, type);
	} catch(e) {
	}
}

/**
 * debug调试信息的输出.
 */
//Write debug infomation to logDiv//
function exportDebugInfo() {
	try {
		if (debug == 1) {
			var txtDebug = txtParam="";
			var txtTime = getNowTime();
		
			if (arguments[0].indexOf('callJSFun') != -1) 
				txtDebug = "<span style='font-family:verdara; font-size:11px; color:#ff0000'>"+ txtTime +": " + arguments[0] + "(";			
			else if (arguments[0].indexOf('callFlashFun') != -1) 
				txtDebug = "<span style='font-family:verdara; font-size:11px; color:#0000ff'>"+ txtTime +": " + arguments[0] + "(";			
			else
				txtDebug = "<span style='font-family:verdara; font-size:11px; color:#666666'>"+ txtTime +": " + arguments[0] + "(";			
			
			for(var i=1; i<arguments.length; i++) {			
				if (typeof(arguments[i]) != "undefined") {
					if (typeof(arguments[i]) == "string") {						
						var str = arguments[i];
						str = str.replace(/<\/?[^>]+>/g, '');
						str = str.replace(/[ | ]*\n/g, '');
						str = str.replace(/\n[\s| | ]*\r/g, '');
						txtParam += " '"+ str +"', ";
					} else {
						txtParam += arguments[i] +", ";
					}
				}
			}
			
			if (txtParam.substring(txtParam.length-2, txtParam.length) == ", ") 
					txtParam = txtParam.substring(0, txtParam.length-2); 
			txtDebug += txtParam + ")</span><br />";		
			
			var rowDebug = hjget("tabDebugInfo").insertRow(-1);
			var tdDebug = rowDebug.insertCell(0);
			tdDebug.innerHTML = txtDebug;
			hjget("divDebugInfo").scrollTop = hjget("tabDebugInfo").scrollHeight;
		}
	} catch(e) {
	}
}

/**
 * 推出聊天窗口时的提示.
 */
function confirmExit() {
	exportDebugInfo('exportLog', 'confirmExit', 'statusChat:'+statusChat);
	if (statusChat != 3 && statusChat != 0 &&　!/tencenttraveler/.test(navigator.userAgent.toLowerCase())) return lang.exitWarning;
}

/**
 * 输入信息是否保存本地提示.
 */
function diplaySaveNotes() {
	if (hjget("rdoSave1").checked) {
		hjget("nickSaveNote1").style.display = "";
		hjget("nickSaveNote2").style.display = "none";
	} else if (hjget("rdoSave2").checked) {
		hjget("nickSaveNote1").style.display = "none";
		hjget("nickSaveNote2").style.display = "";
	}
}

/**
 * 向服务器发送信息.
 */
function sendTalkAskToFlash(sName, iParent, iChild) {
	//alert(iFlashLoaded);
	if (iFlashLoaded) {
		callFlashChat("flashChat").callFlashFun("userAskInfo", sName, iParent, iChild, saveInfo, visitorInfo, scanInfo);
		exportDebugInfo('userAskInfo', sName, iParent, iChild, saveInfo, visitorInfo, scanInfo);
		if(requestType == 2) {
			var msg = "<div id='systemMsg1' style='line-height:26px;padding-left:20px; background:url(" + images + "sysinfo.gif) no-repeat left center'>"+ lang.systemMsg1 + "</div>";
			exportLog(msg, -1, "inviteSystemMsg1");
		}
	} else {
		setTimeout(function(){sendTalkAskToFlash(sName, iParent, iChild);}, 200);
	}
}

/**
 * trim
 * 去掉开始结束字串空格
 * @param string str
 */
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

/**
 * 输入信息处理.
 */
function checkNick() {
//	var txtNick = hjget("name")?hjget("name").value:"";

	var check_flg	= false;
	var regString	= /^[0-9a-zA-Z_\u4e00-\u9fa5]+$/;//[\u0391-\uFFE5]
	var regEmail	= /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	var regQQ		= /\d/;
	var regEmpty	= /\s+/g;
	if (userData)
	{
		visitorInfo = userData;
		var visitorInfoArr = visitorInfo.split("|");
		var txtNick = decodeURIComponent(visitorInfoArr[0]);//alert(txtNick);
	}
	else
	{
		var info = new Array(visitorInfoList.length);
		for(var i=0;i<visitorInfoList.length;i++) {
			if(visitorInfoList[i].id == 'vi_sex'){
				info[visitorInfoList[i].id] = $("input[@name=vi_sex][@checked]").val();
			}else{
				info[visitorInfoList[i].id] = hjget(visitorInfoList[i].id+'_input')?hjget(visitorInfoList[i].id+'_input').value:"";			
			}
			if (visitorInfoList[i].select && info[visitorInfoList[i].id].replace(regEmpty) == "" && visitorInfoList[i].id != 'vi_sex')
			{
				alert('带有*的必须输入！');
				return false;
	//			check_flg = true;
			} else if (info[visitorInfoList[i].id]){
				
			}
			if ((visitorInfoList[i].id == 'vi_msn' || visitorInfoList[i].id == 'vi_email') && visitorInfoList[i].select) {
				if (!regEmail.test(info[visitorInfoList[i].id])) {
					alert('Email或MSN格式输入不正确！');
					return false;
				}
			}
			if ((visitorInfoList[i].id == 'vi_qq' && !regQQ.test(info[visitorInfoList[i].id]))  && visitorInfoList[i].select) {
				alert('QQ只能为英数字！');
				return false;
			}
		}
		
		//判断是否保存.
		if (hjget("rdoSave1").checked) {
			saveInfo = hjget("rdoSave1").value;
		} else {
			saveInfo = hjget("rdoSave2").value;
		}
		for(var i=1; i<keyArr.length; i++) {
			if(keyArr[i] == 'vi_nickname') continue;
			if (info[keyArr[i]]) {
				if (keyArr[i] != 'vi_sex') {
					info[keyArr[i]] = trim(info[keyArr[i]]);
				}
				if (i == (keyArr.length - 1)) {
					visitorInfo += encodeURIComponent(info[keyArr[i]]);
				} else {
					visitorInfo += encodeURIComponent(info[keyArr[i]]) + '|';
				}
			} else {
				visitorInfo += '|';
			}
		}
	
		var txtNick = trim(info['vi_nickname']);
	}
	var regNick = /^[0-9a-zA-Z_@.\u4e00-\u9fa5]+$/;//[\u0391-\uFFE5]
	if (txtNick.replace(/\s+/g ,"") == "" ) {
		alert(nickError);
		return false;
	} else {
		if (regNick.test(txtNick) == false) { alert(nickError1); return false; }
		if (hjget("rdoSave1").checked) {
			setCookie('HJLiveChatNccWebUserNickName', txtNick);
		}
		//statusChat = 3;

		visitorName = txtNick;
		if (requestType == 1 || requestType == 2) {
			sendTalkAskToFlash(encodeURIComponent(visitorName), depId, depId);
			exportDebugInfo('sendTalkAskToFlash', visitorName, depId, depId);
		} else {
			if (selectType == 1) {
				//如果不需要选择类别.
				sendTalkAskToFlash(encodeURIComponent(visitorName), defaultDep, defaultDep);
			}else{
				//需要选择类别.
				showDepartmentList();
			}
//			showDepartmentList();
		}

		/**
		 * 会员信息发送，icc
		 */
//		EPageInfoSubmit();
		
		$("#visitorInfoInputDiv").hide();
		$("#view").show();
		$("#divChatTop").show();
//		$("#tdInput").show();

		//var url = window.location+"&nk="+encodeURI(txtNick);
		//window.location = url;
		return false;
	}
}

var selDepTime = null;
var selDepTimeSystem = null;//检测是否选择部门.

/**
 * 显示部门列表，以及接通客服，显示top等系统消息.
 */
function showDepartmentList() {
	var selectDepType = 0;
	//removeLog("trWelcomeMsg1");
	if (!jCompanyInfo.list) {
		JumpToLeaveWord("");
		return false;
	}

	if (typeof(arguments[0]) != "undefined") {
		$("#trParentDep").hide();
		parentDepId = arguments[0];
		$("#divChatTop").show();
//		$("#tdOpTyping");
//		hjget("tdOpTyping").innerHTML = "欢迎光临！";
		var msg = "<div id='systemMsg1' style='line-height:26px;padding-left:20px; background:url(" + images + "sysinfo.gif) no-repeat left center'>"+ lang.systemMsg1 + "</div>";
		msg += "<div style='padding-left:20px; background:url(" + images + "sysinfo.gif) no-repeat left top'>"					
						+"<span class='systemInfo' id='depTitle1' style='color:#FF0000'>"+lang.depTitle2
							+"</span><ul class='depList' style='margin-top:0px '>";		
		for (var i=0; i<jCompanyInfo.list.length; i++) {
			if (jCompanyInfo.list[i].btid == arguments[0]) {
				for (var j=0; j<jCompanyInfo.list[i].depList.length; j++) {
					if (j == 0) {
						msg += "<li style='display:none'></li>";
					}
					msg += "<li onmouseover='this.style.color=\"#ff0000\"' onmouseout='this.style.color=\"\"'><span style='cursor:pointer' onClick='sendTalkAsk(\""
						+ jCompanyInfo.list[i].depList[j].deId +"\"); return false'>" 
						+ jCompanyInfo.list[i].depList[j].deName + "";

					if (jCompanyInfo.list[i].depList[j].status) 
						msg += " <span style='color:#FF0000'>["+lang.online+"]</span></span></li>";
					else 
						msg += " <span style='color:#999999'>["+lang.offline+"]</span></span></li>";
				}				
				break;
			}
		}
		
		msg += "</ul></div>";
		
		// 添加部门列表下面部分欢迎语.
		if(lang.chatWelecomeMsg != undefined){
			msg += "<div id='chatWelecomeMsg' style='padding-left:20px; background:url(" + images + "sysinfo.gif) no-repeat left top'>"+ lang.chatWelecomeMsg + "</div>";
		}
		exportLog(msg, -1, "trChildDep");
		exportDebugInfo("exportLog", msg, -1, "trChildDep");
	} else {
		if (jCompanyInfo.list.length==1) {			
			showDepartmentList(jCompanyInfo.list[0].btid);	
		} else {
			var msg = "<div id='systemMsg1' style='padding-left:20px; background:url(" + images + "sysinfo.gif) no-repeat left top'>"+ lang.systemMsg1 + "</div>";
			msg += "<div style='padding-left:20px; background:url(" + images + "sysinfo.gif) no-repeat left top'>"					
							+"<span class='systemInfo' id='depTitle1' style='color:#FF0000'>"+lang.depTitle1
							+"</span><ul class='depList'>";
			for (var i=0; i<jCompanyInfo.list.length; i++) {
				if (i == 0) {
					msg += "<li style='display:none'></li>";
				}
				msg += "<li><a href='#' class='depList' onClick='showDepartmentList(\""
					+ jCompanyInfo.list[i].btid +"\", \""+ jCompanyInfo.list[i].btname +"\"); return false'>" 
					+ jCompanyInfo.list[i].btname + "</a></li>";
			}
			msg += "</ul></div>";
			
			// 添加部门列表下面部分欢迎语.
			if(lang.chatWelecomeMsg != undefined){
				msg += "<div id='chatWelecomeMsg' style='padding-left:20px; background:url(" + images + "sysinfo.gif) no-repeat left top'>"+ lang.chatWelecomeMsg + "</div>";
			}
			exportLog(msg, -1, "trParentDep");
			exportDebugInfo("exportLog", msg, -1, "trParentDep");
		}

	}	

	if (hjget("tdInput").style.display == "none") {
		hjget("tdInput").style.display = "";
	}
	selDepTime = 180;
	if (selDepTimeSystem == null) selDepTimeSystem = setInterval("stopAtDep();", 1000);
}

function stopAtDep() {
	// 部门选择超时.
	if (selDepTime != null && defaultTab == 0) {
		if (selDepTime == 10) {
			var msg = lang.selDepInfo;
			exportLog(msg, 0);
		} else if (selDepTime == 0) {
			$("#trParentDep").hide();
			$("#trChildDep").hide();
			changeTab(2);
			selDepTime = null;
			clearInterval(timerSystem);
		}
		if (selDepTime > 0) {
			selDepTime --;
		}
	}
}

/**
 * 显示聊天记录.
 */
function sendTalkAsk(id) {
	if (selDepTime != null) {
		selDepTime = null;
	}
	childDepId = id;
	$("#trChildDep").hide();
	sendTalkAskToFlash(encodeURIComponent(visitorName), parentDepId, childDepId);
	var msg = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
						+"<span class='systemInfo' id='systemMsg2'>"+lang.systemMsg2+"</span>";
	exportLog(msg, -1, 'trWelcomeMsg2');
	var msg = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
				+"<span class='systemInfo'><span id='top10Msg1'>"+lang.top10Msg1+"</span> "
				+"<img src='" + images + "ico/top10.gif' border='0'> "
				+"<span id='top10Msg2'>"+lang.top10Msg2+"<span></span>";
	exportLog(msg, -1, "trTop10");
	$("#spanTop10").show();
}

/**
 * 取得昵称.
 */
function getNick() {
	var nick = getCookie('HJLiveChatNccWebUserNickName');
	if (nick != null) {
		//document.getElementById("txtNick").value = nick;
		var url = window.location+"&nk="+encodeURI(nick);
		window.location = url;
	} else {
		document.getElementById("tabReading").style.display = "none";
		document.getElementById("tabInput").style.display = "";
	}
}

function changeSendKey(type) {
	if (type == 0) 
		sendKey = 0;
	else if (type == 1)
		sendKey = 1;
		
	changeSendKeyStatus(type);
}

function changeSendKeyStatus(type)
{
	for(var i=0;i<2;i++)
	{//alert(i +'+'+ type);
		if (i == parseInt(type))
		{
			$("#checkIcon"+i).html("√");
		}
		else
		{
			$("#checkIcon"+i).html("");
		}
	}
}
function exitChatRoom(type) {
	if (type == 6 && statusChat == 0) {
		window.close();
	}	
	
	statusChat = 3;
	hjget("tabPanelButton").style.display = "none";
	hjget("tdSaveRecodes").style.display = "none";	
	hjget("tdVoice").style.display = "none";	
	//hjget("tabTopButton").style.display = "none";	
	//hjget("tdSendType").style.display = "none";
	//hjget("tdQuestion").style.display = "none";
	//hjget("tdOpName").style.display = "none";
	//hjget("tdOpName").innerHTML = "&nbsp;";
	hjget("tdOpTyping").innerHTML = "&nbsp;";
	hjget("objInput").innerHTML = "";
	hidePanel();
//	if (isIE) hjget("objInput").disabled = true;
//	$("#objInput").attr("contenteditable","false");
	
	inputEnd();//退出对话，禁用输入框.
	
	hjget("tdInput").style.background = "#eeeeee";
	hjget("objInput").style.background = "#eeeeee";
	
	callFlashChat("flashChat").callFlashFun("LeftChatRoom", type);
	exportDebugInfo("callFlashFun", "LeftChatRoom", type);
	exportDebugInfo("exitChatRoom", type);

	statusVideo = 0;
	statusVoice = 0;
	resizeWindow();

	if (timerSystem != null) {
		clearInterval(timerSystem);
		timerSystem = null;	
	}
	
	if (type == 2 || type == 3) {
		window.location = urlLeaveWord;
		//goLeaveWord(type);		
	} else {
		if (type == 6) {
			if (chatStart == 1) {
				goSatisfaction(1);
			} else {
				window.close();
			}
		} else {
			if (chatStart == 1) {
				goSatisfaction();
			} else {
				window.close();
			}
		}
		//$('#divChatEnd').jqmShow();
		//window.location = urlSatisfaction + "&chat="+chatId;
	}
	
}

function goSatisfaction(type) {
	try{
		$.get
		(
			'../include/satisfaction.php',
			{aj:1,action:'getSurvey',lc:pageLang,co:company,rndVar:(new Date()).getTime()},
			function (msg)
			{
				if(msg) {
//					var msg = '<span>对话已结束，请填写您对本次服务的满意度：</span>'+'<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<a class="depList" href="#" onclick="goSatisfaction(1)"><span>'+ '满意度调查' +'</span></a>';
//					exportLog(msg, 0);
					if (type == 1) {
						try{
							var oldSatis	= surveyVal;
							var oldSatisStr	= encodeURI(surveyStr);
						}catch(e){
							var oldSatis = "";
							var oldSatisStr = "";
						}
						var vstSNId = callFlashChat("flashChat").getSNID();
						window.location = urlSatisfaction
												+"&chat="+chatId
												+"&opid="+curOpId
												+"&snid="+vstSNId
												+"&color="+pageColor
												+"&oldSatis="+oldSatis
												+"&oldSatisStr="+oldSatisStr
												+"&s="+scheme_ID;
					} else {
						
					}
				} else {
					window.close();
				}
			}
		);
	}catch(e){
		
	}
}

//Show setting div.
function showPanel(id){
	var objDiv 		= hjget(id);
	var objLogDiv 	= hjget("divLog");
	var sc = objLogDiv.scrollTop;	
	if (id == "tabFont" || id == "tabSendLink" || id == "tabSendFile" || id == "tabRename") {
		if (objDiv.style.display == "none") {
			hidePanel();
			hjget("trLog").height = "100%";
			hjget("trPanel").style.display = "";
			objDiv.style.display  = "";
		} else {
			hidePanel();	
		}
		objLogDiv.scrollTop = parseInt(sc);
	} else if (id == "divFace" || id == "divColor"){
		if (objDiv.style.display == "none") {
			if (id == "divFace") hidePanel();
			objDiv.style.display  = "";
		} else {
			if (id == "divFace") hidePanel();
			else objDiv.style.display  = "none";
		}
	}	
}

function showPanelDiv(contentDiv,showDiv,type,contentId)
{
	mouseover_open(contentDiv,showDiv,type,contentId);
}

function hidePanel(){
	try
	{
		hjget("showmenu").style.display = "none";
		hjget("showmenu1").style.display = "none";
	}
	catch(e){}
	try{
//	hjget("trPanel").style.display = "none";
//	hjget("trLog").height = "100%";
//	hjget("divFace").style.display = "none";
//	hjget("tabFont").style.display = "none";
//	hjget("tabSendFile").style.display = "none";
//	hjget("tabRename").style.display = "none";
//	hjget("divColor").style.display = "none";
//	hjget("tabSendLink").style.display = "none";	
//	hjget("divTop10").style.display = "none";	
	}catch(e){}
}

function styleChange() {
	var fontFamily 		= hjget("selFontFamily").value;
	var fontSize 		= hjget("selFontSize").value;

/**
	if (isIE) {
		var fontStyle 		= hjget("objInput").style.fontStyle;
		var fontWeight		= hjget("objInput").style.fontWeight;
		var textDecoration 	= hjget("objInput").style.textDecoration;
	} else {
		var fontStyle 		= objInput.document.body.style.fontStyle;
		var fontWeight		= objInput.document.body.style.fontWeight;
		var textDecoration 	= objInput.document.body.style.textDecoration;
	}
*/

	var fontStyle 		= hjget("objInput").style.fontStyle;
	var fontWeight		= hjget("objInput").style.fontWeight;
	var textDecoration 	= hjget("objInput").style.textDecoration;

	if (typeof(arguments[0]) != "undefined") {
		switch (arguments[0]) {
			case "bold":
				if (fontWeight == "normal") {
					var fontWeight = "bold";
				}else{
					var fontWeight = "normal";
				}
				break;
			case "italic":
				if (fontStyle == "normal") {
					var fontStyle = "italic";
				}else{
					var fontStyle = "normal";
				}
				break;
			case "uline":
				if (textDecoration == "none") {
					var textDecoration = "underline";
				}else{
					var textDecoration = "none";
				}
				break;
		}
	}
	
	//try {
		hjget("objInput").style.fontFamily = fontFamily;
		hjget("objInput").style.fontSize = fontSize;
		hjget("objInput").style.fontStyle = fontStyle;
		hjget("objInput").style.fontWeight = fontWeight;				
		hjget("objInput").style.textDecoration = textDecoration;
/**
		if (isIE) {
			hjget("objInput").style.fontFamily = fontFamily;
			hjget("objInput").style.fontSize = fontSize;
			hjget("objInput").style.fontStyle = fontStyle;
			hjget("objInput").style.fontWeight = fontWeight;				
			hjget("objInput").style.textDecoration = textDecoration;
		} else {
			objInput.document.body.style.fontFamily = fontFamily;
			objInput.document.body.style.fontSize = fontSize;
			objInput.document.body.style.fontStyle = fontStyle;
			objInput.document.body.style.fontWeight = fontWeight;				
			objInput.document.body.style.textDecoration = textDecoration;
		}
*/
	//} catch (e) {
	//}
}

function selectColor(){
	srcElem=event.srcElement;
	if(srcElem.tagName=="TD"){
		hjget("objInput").style.color = srcElem.bgColor;
		hjget("divColor").style.display = "none";
	}
}

function sendFace(num){
	var img 	= imageFace + "emoticons/"+ num +".gif";
	var strFace = "<span contentEditable=false><img src=" + img + " border=0 width=\"24\" height=\"24\" /></span>";
//	window.focus();
	hjget("objInput").focus();
	
	
/**
	if (isIE) {
		var	tR = document.selection.createRange();	
		tR.pasteHTML(strFace);
	} else {
		objInput.document.body.innerHTML += strFace;
	}
*/


if (document.selection && document.selection.createRange) {
	var myRange = document.selection.createRange();
	var m = myRange.pasteHTML(strFace);
}
else if (window.getSelection) {
	var selection = window.getSelection();
	var range = window.getSelection().getRangeAt(0);
	range.deleteContents();
	var repl=document.createElement('span');
	repl.innerHTML = strFace;
	range.insertNode(repl);
}

/**
	var	tR = document.selection.createRange();
	tR.pasteHTML(strFace);
*/
	hidePanel();
}

function loadFace() {
	for (var i=0; i<28; i++) {
		hjget("imgFace" + i).src = imageFace + "emoticons/" + i + ".gif";
	}
}


function sendLink(){
	var linkType = hjget("selLinkType").value;
	var linkText = hjget("txtSendLink").value;
	if (linkType != "mailto:") {
		var strLink = "<a href='" + linkType + linkText + "' target='_blank'>" + linkType + linkText + "</a>";
	} else {
		var strLink = "<a href='" + linkType + linkText + "' target='_blank'>" + linkText + "</a>";
	}
	hjget("objInput").focus();
//	if (isIE) {
		var	tR = document.selection.createRange();	
		tR.pasteHTML(strLink);
//	} else {
//		objInput.document.body.innerHTML += strLink;
//	}
	hidePanel();
}

function rename() {
	if (counterRename == 3) {
		var msg = lang.renameError;
		exportLog(msg, 0);
		return false;
	}
	
	var name = hjget("txtNickName").value;
	if (name.replace(/\s+/g, "") == "" || name.replace(/($)/g, "") == "") {
		alert(lang.nickError);
		return false;
	} else {
		var msg = lang.nickSuccess+name;
		exportLog(msg, 0);
		visitorName = name;
		showPanel("tabRename");
		try {
			callFlashChat("flashChat").callFlashFun("ChangeName", name);
			exportDebugInfo("callFlashFun", "ChangeName", name);
		} catch (e) {
		}

		var nick = getCookie('HJLiveChatNccWebUserNickName');
		if (nick != null) {
			setCookie('HJLiveChatNccWebUserNickName', name);		
		}
		
		counterRename++;		
	}
}

function previewLink() {
	var strLink = hjget("txtSendLink").value;
	if (strLink.length == 0) return false;	
	strLink = hjget("selLinkType").value + strLink;	
	try {
		var opener = window.open(strLink, "_blank", "");
		opener.focus();
	} catch(e) {
	}
}

function sendScreen() {
	var objDate = new Date();
	var fileScreen = objDate.getYear();
	
	if (objDate.getMonth() < 10) fileScreen += "0" + objDate.getMonth();
	else  fileScreen += objDate.getMinutes();
	
	if (objDate.getDate() < 10) fileScreen += "0" + objDate.getDate();
	else  fileScreen += objDate.getDate();
	
	fileScreen += objDate.getDate()+Math.floor(Math.random()*1000000)+'.jpg';


	try {
		var objScreen = new ActiveXObject("ScreenCapture.ScreenCaptureCtl");
		var versions = null;
		try{ 
			versions = objScreen.getVer();
		}catch(e){
			versions = null;
		}
		if(versions == null) {
			window.open("screenCapture.php", "screenCapture", "");
			return;
		}
		var nRn = objScreen.Cap2Http(fileScreen, screenHost, screenPort, uploadUrl);
		exportDebugInfo("objScreen.Cap2Http", fileScreen, screenHost, screenPort, uploadUrl);
		exportDebugInfo("objScreen.Cap2Http.return ", nRn);
		
			
		if (nRn == 1) {
			var txtScreen = "<span contentEditable=false><img src='" + screenUrl;			
			txtScreen += fileScreen;
			txtScreen += "' border='0' /></span>";
			
			hjget("objInput").focus();
//			if (isIE) {
				var	tR = document.selection.createRange();	
				tR.pasteHTML(txtScreen);
//			} else {
//				objInput.document.body.innerHTML += txtScreen;
//			}	
		}
	} catch(e) {
		window.open("screenCapture.php", "screenCapture", "");
	}
}

function sendFile() {
		$("#sendfile_loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		$.ajaxFileUpload
		(
			{
				url:'../upload/uploadfilesave.php',
				secureuri:false,
				fileElementId:'inputSendFile',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.msg) != 'undefined')
					{
						if(data.msg == '1')
						{
							var msg = lang.finishedSend;			
							exportLog(msg, 0);
							//UploadAndDownload(1, '');
							callFlashChat("flashChat").callFlashFun("UploadAndDownload", 1, data.url);							
							hidePanel();
							//exportDebugInfo("ajaxFileUpload ok",data.url);
						}else if(data.msg == '2'){
							exportDebugInfo("ajaxFileUpload error unallowed file type");
							var msg = lang.sendTypeError;
							exportLog(msg, 0);
						}else
						{	
							var msg = lang.sendError;
							exportLog(msg, 0);
						}
					}
				},
				error: function (data, status, e)
				{
					var msg = lang.sendError;
					exportLog(msg, 0);
					exportDebugInfo("ajaxFileUpload request error:", e);
				}
			}
		);		
		return false;	
	/*
	try {
		if (hjget('tabSendFile').style.display == '') {
			exportLog(lang.sending, 0);
			return false;
		}
		callFlashChat("flashChat").callFlashFun("UploadAndDownload", 0, "");
		exportDebugInfo("callFlashFun", "UploadAndDownload", 0, "");
	} catch (e) {
	}
	*/	
}

function cancelSendFile(){
	hidePanel();
	/*
	try {
		callFlashChat("flashChat").callFlashFun("UploadAndDownload", "Cancel");
		exportDebugInfo("callFlashFun", "UploadAndDownload", "Cancel");
	} catch (e) {
	}*/	
}

function openTop10() {	
	if (!childDepId) childDepId = defaultDep;
	if (hjget("showmenu").style.display == "none") {
		var url = urlTop10 + "&tp=1&gm="+parentDepId+"&dp="+childDepId;
		$("#ifmTop10").attr("src",url);
		hidePanel();
		//hjget("divTop10").style.display = "";
		mouseover_open('divTop10','imgTop10',2);
	} else {
		hidePanel();
	}
}

function goLeaveWord(type) {
	if (timerFlashList != null) {
		clearInterval(timerFlashList); 
		timerFlashList = null;
	}
	var msg = '&nbsp;&nbsp;&nbsp;&nbsp;<span class="systemInfo" id="leaveWordTitle">'+lang.leaveWordTitle+'</span><br />'
				+"&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' class='depList' onclick='goBBSOrBar("+type+", 1); return false'>"
				+lang.bar+'</a>';
//				+"&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' class='depList' onclick='goBBSOrBar("+type+", 2); return false'>"
//				+lang.bbs+'</a>';
	
	if (type == 2) {
		timerQueuing = null;
		removeLog("trQueuing");					
		msg = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
				+'<span class="systemInfo" id="queuingTimeOver">'+lang.queuingTimeOver+'</span><br />'+ msg;
			
	} else if (type == 3) {
		removeLog("trQueuing");
		msg = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
				+'<span class="systemInfo" id="queuingNumOver">'+lang.queuingNumOver+'</span><br />'+ msg;
	}
		
	if (hjget("divQueuingNumOver")) {
		hjget("divQueuingNumOver").innerHTML	= msg;
	} else {
		exportLog("<div id='divQueuingNumOver'>"+ msg +"</div>", -1, "trQueuingNumOver");
	}
}

function goBBSOrBar(exitType, type) {
	var url = "../monitor/responseOther.php?type="+type+"&company="+company;
	var imgReport = new Image;
    imgReport.src = url;

	statusChat = 3;
	hjget("tabPanelButton").style.display = "none";
	hjget("tdSaveRecodes").style.display = "none";	
	hjget("tdVoice").style.display = "none";	
//	hjget("tdSendType").style.display = "none";
//	hjget("tdQuestion").style.display = "none";
//	hjget("tdOpName").style.display = "none";
//	hjget("tdOpName").innerHTML = "&nbsp;";
	hjget("tdOpTyping").innerHTML = "&nbsp;";
	hjget("objInput").innerHTML = "";
	hidePanel();
//	if (isIE) hjget("objInput").disabled = true;
//	$("#objInput").attr("contenteditable","false");
	//转入留言，禁用输入框.
	inputEnd();
	
	hjget("tdInput").style.background = "#eeeeee";
	hjget("objInput").style.background = "#eeeeee";
	callFlashChat("flashChat").callFlashFun("LeftChatRoom", exitType);
	exportDebugInfo("callFlashFun", "LeftChatRoom", exitType);
	exportDebugInfo("goBBSOrBar", exitType, type);
	
	if (timerSystem != null) {
		clearInterval(timerSystem);
		timerSystem = null;	
	}
	
	if (type == 1) {
		//setTimeout("window.location='{% $chat->urlBBS %}'", 2000);
                //setTimeout("window.close()", 2000);
                //window.open(urlBar);	
				changeTab(2);	
	} else if (type == 2) {
		//setTimeout("window.location='{% $chat->urlBar %}'", 2000);
                //setTimeout("window.close()", 2000);
                //window.open(urlBBS);		
	}
}

function getOperatorName(opId){
	for(var i=0; i < opArray.length; i++){
		var aryOp = opArray[i].split(",");
		if (aryOp[1] == opId){
			return aryOp[0];
		}
	} 
	return "";
}

function getCookie(sName) {
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0])
		return decodeURIComponent(aCrumb[1]);
	}
	return null;
}

function setCookie(sName, sValue) {
	var expires = new Date();
	expires.setTime(expires.getTime() + 3600*24*365*1000);
	document.cookie = sName + "=" + encodeURIComponent(sValue) + "; expires=" + expires.toGMTString() + "; path=/";
}

/**
 * 客服同意延长对话时间.
 */
function ifAddTime(delayOpId, addTimeFlg) {
	if (addTimeFlg == 1) {
		if (!timeAdd || timeAdd <= 0 || isNaN(timeAdd)) {
			timeAdd = 0;
		}
		var replayAddChatTime = timeAdd;
		timerChat = parseInt(timerChat) + parseInt(replayAddChatTime);
		var mess = lang.addChatTime + replayAddChatTime + lang.secExt;
		exportDebugInfo("callFlashFun", "ifAddTime", curOpId);
		exportLog(mess, 0);
	}
}

/**
 * 请求延长对话时间.
 */
function delayChatTime() {
	callFlashChat("flashChat").callFlashFun("ifAddTime", curOpId);
	exportDebugInfo("callFlashFun", "ifAddTime", curOpId);
}

var opWaitVisitorTime = null;

function refreshTimer() {
	if (timerOpWait != null && opWaitVisitorTime == null) {
		opWaitVisitorTime = timerOpWait;
	}
	if (timerChat != null) {
		if (statusChat == 1 && timerChat == 0) {
			var msg = lang.chatTimeOver;
			exportLog(msg, 0);
			timerChat = null;
			exitChatRoom(1);
		} else {
			if (statusChat == 1 && timerChat == 60) {
				var msg = lang.chatTimeWarning;
				exportLog(msg, 0);
				delayChatTime();
			}
			timerChat--;
		}
	}
	
	if (opWaitVisitorTime != null) {
		if (statusVoice == 2 || statusVideo == 2 || EBStart == 1) {
			opWaitVisitorTime = null;
		} else {
			if (statusChat == 1 && opWaitVisitorTime == 0) {
				var msg = lang.opWaitTimeOver;
				exportLog(msg, 0);
				opWaitVisitorTime = null;
				exitChatRoom(4);
			} else {
				if (statusChat == 1 && opWaitVisitorTime == 10) {
					var msg = lang.opWaitTimeWarning;
					exportLog(msg, 0);
				}
				opWaitVisitorTime--;
			}
		}
	}

	if (timerQueuing != null) {
		if (timerQueuing == 0) {
			goLeaveWord(2);
//			timerQueuing = null;
		} else {
			timerQueuing--;
		}
	}
	
	if (timerChat > 0) {
		$("#divChatTop").show();
		hjget("tdChatTime").style.display = "";
		hjget("tdChatTime").innerHTML = lang.serviceTime+" <span class='infoBright'>"
												+ timerChat+ "</span> "+lang.sec;
		if (chatTimeShow == 0 || !chatTimeShow) {
			$("#tdChatTime").hide();
		}
	} else {
		hjget("tdChatTime").style.display = "none";
		hjget("tdChatTime").innerHTML = "";
	}

	if (debug == 1) {
		hjget("tdDebugChatTime").innerHTML = timerChat;
		hjget("tdDebugQueuingTime").innerHTML = timerQueuing+'|'+statusChat;
		hjget("tdDebugQueuingNum").innerHTML = maxQueuingNum;
		hjget("tdDebugOpWaitTime").innerHTML = opWaitVisitorTime;
	}	
}

function saveTrans() {
	if (isIE) {
		var objDate = new Date();
		var txtDate = objDate.getYear();
		
		if (objDate.getMonth() < 10) txtDate += "0" + objDate.getMonth();
		else  txtDate += objDate.getMinutes();
		
		if (objDate.getDate() < 10) txtDate += "0" + objDate.getDate();
		else  txtDate += objDate.getDate();

		var title  = txtDate + "_" + Math.floor(Math.random()*1000000) + ".html";
		var opener = window.open();
		opener.document.open("html","UTF-8");
		opener.document.writeln("<h"+"tml><he"+"ad>"
										+"<me"+"ta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
										+"<ti"+"tle>"+title+"</t"+"itle>");
		opener.document.writeln("<style>body{font-family:Verdana;	font-size: 12px;margin:1px;}");
		opener.document.writeln(".vstChatTitle{font-family:Verdana;	font-size: 12px;color:#009900;}");
		opener.document.writeln(".opChatTitle{font-family:Verdana;	font-size: 12px;color:#0000ee;}");
		opener.document.writeln(".systemInfo{font-family:Verdana;	font-size: 12px;color:#0249a2;}");
		opener.document.writeln(".infoBright{color:#0249a2;}");
		opener.document.writeln("a.depList:link {font-family:verdana,arial,sans-serif;"
									+"font-size: 12px;color: #008cff;text-decoration:underline;}");
		opener.document.writeln("a.depList:visited {font-family:verdana,arial,sans-serif;"
									+"font-size: 12px;color: #008cff;text-decoration:underline;}");
		opener.document.writeln("a.depList:hover {font-family:verdana,arial,sans-serif;"
									+"font-size: 12px;color: #000000;text-decoration:underline;}");
		opener.document.writeln("a.depList:active {font-family:verdana,arial,sans-serif;"
									+"font-size: 12px;color: #000000;text-decoration:underline;}");
		opener.document.writeln("#Cmsg a{target:expression(this.target='_blank');}</style></he"+"ad><" + "body>");
		
		opener.document.write(hjget("divLog").innerHTML);
		opener.document.writeln("</bo"+"dy></ht"+"ml>");
		var ret = opener.document.execCommand ("SaveAs", true, title);
		opener.close();
	}
}

function sendTrans() {
	if (isIE) {
		var sendLogAddress = hjget("txtSendLogAddress").value;
		if(sendLogAddress.match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/) == null){
			alert(lang.emailError);
			return false;
		}
	
		var sendLogContent = "<html><head><meta http-equiv=Content-Type content=text/html; charset=utf-8 /><title>SendMail</title></head><style type=text/css> .text_chat {font-family:verdana,arial,sans-serif;font-size: 12px;color: #666666;} .text_system {font-family:,verdana,arial,sans-serif;font-size: 12px;color: #000000;} .text_system_title {font-family:,verdana,arial,sans-serif;font-size: 12px;color: #ff3300;} .text_title {font-family:verdana,arial,sans-serif;font-size: 12px;color: #ffffff;filter : progid:dximagetransform.microsoft.dropshadow(color=#0099ff,offx=1,offy=1,positives=true)} .text_c_01 {font-family: ,verdana,arial,sans-serif;font-size: 12px;color: #222222;line-height: 140%;} </style>";
		
		sendLogContent += hjget("divLog").innerHTML;
		sendLogContent += "</body></html>";

		sendLogContent = sendLogContent.replace(/'/g, "");
		sendLogContent = sendLogContent.replace(/&nbsp;/g, "");
		sendLogContent = sendLogContent.replace(/(<A)([^<])+?(>)/g, "");
		sendLogContent = sendLogContent.replace(/<\/A>/g, "");

		var st = window.open();
		st.document.open("html","UTF-8");
		var title = lang.chatlog;
		
		if (title.length == 0) title += "Trans_";
		var date = new Date();
		var month = date.getMonth() + 1;
		var sMonth = month.toString();
		if (month < 10) sMonth = "0" + sMonth;
		title += date.getYear().toString()+sMonth+(date.getDate()).toString()+date.getHours().toString()+date.getMinutes().toString();
		st.document.writeln("<h"+"tml><h"+"ead><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><title>SendMail</title></h"+"ead><style type=\"text/css\"> .text_chat {font-family:verdana,arial,sans-serif;font-size: 12px;color: #666666;} .text_system {font-family:,verdana,arial,sans-serif;font-size: 12px;color: #000000;} .text_system_title {font-family:,verdana,arial,sans-serif;font-size: 12px;color: #ff3300;} .text_title {font-family:verdana,arial,sans-serif;font-size: 12px;color: #ffffff;filter : progid:dximagetransform.microsoft.dropshadow(color=#0099ff,offx=1,offy=1,positives=true)} .text_c_01 {font-family: ,verdana,arial,sans-serif;font-size: 12px;color: #222222;line-height: 140%;} </style><bod"+"y><form name='frm_sendLog' action='sendChatLog.php' method='post'><input type='hidden' name='from' value='hjlivechat@cengis.com' /><input type='hidden' name='to' value='"+ sendLogAddress +"'/><input type='hidden' name='subject' value='"+ title +"' /><input type='hidden' name='content' value='"+ sendLogContent +"' /></form><scr"+"ipt language='javascript' type='text/javascript'> document.frm_sendLog.submit();</s"+"cript></b"+"ody></h"+"tml>");

	}
}

function removeLog(id) {
	try {
		if (isIE) {
			if (hjget(id)) {
				hjget(id).removeNode(true);
			}
		} else {			
			if (hjget(id)) {
				var idx = hjget(id).rowIndex;
				hjget("tabLog").deleteRow(idx);
			}
		}		
	} catch(e) {
	}
}

function preVstText(){
	try {
		if (statusChat != 1) return false;	
//		if (isIE) var objectInput = hjget("objInput");
//		else var objectInput = objInput.document.body;
		var objectInput = hjget("objInput");
		
		var txtContent = objectInput.innerHTML;		
		txtContent = txtContent.replace(/<[^<]+>/g, "");		
		if (txtContent != vstInputText) {
			vstInputText = txtContent;
			if (txtContent.length == 0) {
				txtContent = " ";
			} else if (txtContent.replace(/(&nbsp;)|( )|(<br>)|(<br \/>)|(<BR>)|(<BR \/>)/g, "").length > 0) {
				if (txtContent.length > 100) txtContent = txtContent.substr(0, 100);
			}
			
			callFlashChat("flashChat").callFlashFun("PreViewMsg", opId, txtContent);
			exportDebugInfo("callFlashFun", opId, txtContent);
		}
		setTimeout("preVstText();", 1000);
	} catch (e) {
	}
}

//Create FLASH object.
function callFlashChat(movieName) {
	if(hj5107.swf == false) return hj5107.jsChat;
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet") == -1) {
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName];
		}
	else {
		return document.getElementById(movieName);
	}
}

//The interface for Flash call Javascript.
function callJSFun(){
	exportDebugInfo("callJSFun", arguments[0], arguments[1], arguments[2], arguments[3], 
						arguments[4], arguments[5], arguments[6], arguments[7], arguments[8],arguments[9]);

	switch (arguments[0]){
		case "initChatRoom":
			//Init chat room.
			initChatRoom(arguments[1], arguments[2], arguments[3], arguments[4], 
							arguments[5], arguments[6],arguments[7],arguments[8],arguments[9]);
			break;
		case "userStateChanged":
			//When new opetator join or leave chat (0: join; 1: leave).
			userStateChanged(arguments[1],arguments[2],arguments[3],arguments[4]);
			break;
		case "chatMsg":			
			//The chat message from operator.
			chatMsg(arguments[1],arguments[2],arguments[3],arguments[4]);
			break;
		case "UploadAndDownload":
			//Upload or Download files.
			UploadAndDownload(arguments[1],arguments[2],arguments[3],arguments[4]);
			break;
		case "FileOrPageSending":
			//The message about Files or Pages.
			FileOrPageSending(arguments[1],arguments[2],arguments[3],arguments[4]);
			break;			
		case "DepartmentList":	
			//Department list.
			DepartmentList(0, arguments[1], arguments[2], arguments[3], arguments[4]);			
			break;
		case "parentDepartmentList":	/*类别列表*/
			DepartmentList(1, arguments[1], 0, 0, 0);
			break;
		case "IFJSinitOK":		
			//Flash ask JavaScript status.
			IFJSinitOK();
			break;
		case "JumpToLeaveWord":	
			//Jump to leaveword page.
			JumpToLeaveWord(arguments[1]);
			break;
		case "DisConnected":	
			//When Disconnect.
			DisConnected();
			break;
		case "EPageInfoSet":	
			//Set Visitors cards.
			EPageInfoSet(arguments[1], arguments[2], arguments[3]);
			break;
		case "EPageInfoOfClient":
			//Set Operator's cards.
			EPageInfoOfClient(arguments[1], arguments[2]);
			break;
		case "ClientInputStateChange": 
			//The operator is typing .
			ClientInputStateChange(arguments[1]);
			break;
		case "FlashListNum": 	
			//Flash Visitor Queuing Num .
			FlashListNum(arguments[1]);	
			break;
		case "EventDetail":
			EventDetail(arguments[1], arguments[2], arguments[3]);
			break;
		case "UDSwitch":
			// 发送文件功能是否打开.
			UDSwitch(arguments[1], arguments[2]);
			break;
		case "OverNumOfSysWait":
			OverNumOfSysWait();
			break;
		case "InvitToVChat":	
			//Operator invited visitors voice chat.
			InvitToVChat(arguments[1]);
			break;
		case "BeenRejectOfVCInvite":
			//Visitors invited for voice chat were rejected.
			BeenRejectOfVCInvite(arguments[1]);
			break;
		case "LeftVChatGroup":	
			//Some withdraw from the voice chat groups.
			LeftVChatGroup(arguments[1]);
			break;
		case "EnterVChatGroup":	
			//Some joined the voice chat groups.
			EnterVChatGroup(arguments[1]);
			break;
		case "AutoChatMsg":
			AutoChatMsg(arguments[1], arguments[2], arguments[3], arguments[4]);
			break;
		case "socketConnectCheck":
			socketConnectCheck(arguments[1]);
			break;
		case "ReceiveVideoInvite": /*收到客服视频邀请*/
			ReceiveVideoInvite(arguments[1]);
			break;
		case "ReceiveVideoClose": /*收到客服视频关闭*/
			ReceiveVideoClose(arguments[1]);
			break;
		case "ReplayFromClient": /*访客邀请客服视频，收到客服反馈消息*/
			ReplayFromClient(arguments[1], arguments[2]);
			break;			
		case "pushQN":	/*满意度调查推送*/
			//surveys on customer satisfaction 
			pushQN(arguments[1], arguments[2]);
			break;
		case "paramRelative":
			paramRelative(arguments[1], arguments[2], arguments[3]);
			break;
		case "inviteEB": /*收到客服eBoard邀请*/
			inviteEB(arguments[1], arguments[2], arguments[3], arguments[4]);
			break;
		case "closeEB": /*收到客服eBoard关闭*/
			closeEBCient(arguments[1], arguments[2], arguments[3], arguments[4]);
			break;
		case "ifAddTime": /* 收到延长回复　1　同意　0　不同意 */
			ifAddTime(arguments[1], arguments[2]);
			break;
		case "takeover":　/* 强制接管 */
			takeover(arguments[1], arguments[2], arguments[3]);
			break;			
		case "screenSnap":
			screenSnap();
			break;
		case "onlyOneAutoLeft":
			exitVoice();
			break;
		case "cancleSoundInvite":
			cancleSoundInvite();
			break;
	}
}

/**
 * 强制接管处理.
 */
function takeover(opId,opName,opCode)
{
	//operatorName = bakOperatorName;
	curOpId = opId;
	var strOp = opName + "," + opId;
	opArray = new Array('-1,All');
	opArray.push(strOp);
	hjget("operatorStatus").innerHTML = opName;
	if (theme == 1) {
		showOpCard(defaultTab);
	}
	try{
		if (ebWin != null) closeEB(opId);
	}catch(e){}
//	bakOperatorName = opName;
//	takeovered = 1;
}

function socketConnectCheck(flag)
{
/*	if (flag == 1 || flag == 3)
	{
		$("#objInput").attr("contenteditable","false");
		$("#tdInput").css({backgroundColor: "#CCCCCC"});	
	}
	else if (flag == 2)
	{
		$("#objInput").attr("contenteditable","true");
		$("#tdInput").css({backgroundColor: "#FFFFFF"});	
	}
*/
	exportDebugInfo("socketConnectCheck",flag);
	switch (flag)
	{
		case '1':
//			if (isIE) hjget("objInput").disabled = true;
//			$("#objInput").attr("contenteditable","false");
			//禁用输入框.
			inputEnd();
			
			$("#tdInput").css({backgroundColor: "#CCCCCC"});
			$("#objInput").css({backgroundColor: "#CCCCCC"});
			
			var msg = lang.socketStatus_1;
			exportLog(msg, 0, 'socketConnectCheck_1');
			break;
		case '2':
			if (isIE) hjget("objInput").disabled = false;
			$("#objInput").attr("contenteditable","true");
			//启用输入框.
			inputStart();

			$("#tdInput").css({backgroundColor: "#FFFFFF"});
			$("#objInput").css({backgroundColor: "#FFFFFF"});
			var msg = lang.socketStatus_2;
			exportLog(msg, 0, 'socketConnectCheck_2');
			break;
		case '3':
			//重连成功，但对方已经离开，禁用输入框.
			inputEnd();
			var msg = lang.socketStatus_3 + lang.or;
				msg += "<a href='#' onclick='chatEndToLeaveWord(6);'>" + lang.selectMsg + "</a>";
			exportLog(msg, 0, 'socketConnectCheck_3');
			break;
		case '4':
			//50秒重连失败，选择留言，禁用输入框.
			inputEnd();
			var msg = lang.socketStatus_4;
				msg += "<a href='#' onclick='chatEndToLeaveWord(6);'>" + lang.selectMsg + "</a>";
			exportLog(msg, 0, 'socketConnectCheck_4');
			break;
	}
}

/**
 * 启用输入框.
 */
function inputStart() {
	if (isIE) hjget("objInput").disabled = false;
	else $("#objInput").attr("contenteditable","true");
}

/**
 * 禁用输入框.
 */
function inputEnd() {
	if (isIE) hjget("objInput").disabled = true;
	else $("#objInput").attr("contenteditable","false");
}

function doDepartmentList() {
	var msg = initDepList;
	if (chatSrcType == 0)
	{
		if (msg == "") 
		{
			if (flashIsReady==1)
			{
				hjget("initDiv").innerHTML = "";
				msg = "<div id='depList'></div>";
				writeMsg(msg);
				setTimeout("autoSelectDep();", 0);//alert("wu-zhuan");
			}
			else 
			{
				setTimeout("doDepartmentList()", 500);
			}
		}
		else
		{
			if (loadLangOk) {		
				if (showDepList) {
					//hjget("initDiv").innerHTML = "";
					//writeMsg(msg);
					//setTimeout("autoSelectDep();", expire);//alert("zhuan");
					exportLog(msg, -1, "trDep"+0);
				}
			} else {
				setTimeout("doDepartmentList()", 1000);
			}
		}
	}
}

function DepartmentList(type, aryDep, pQueuingTime, pQueuingNum, pEvent) {
	removeLog("trWelcomeMsg1");
	if (type == 0) {
		var msg = "<div style='padding-left:5px'>"
					+"<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
					+"<span class='systemInfo' id='depTitle2'>"+lang.depTitle2+"</span>";
		
		if (typeof(pQueuingTime) != "undefined") {
			timerQueuing = parseInt(pQueuingTime);
		}
		
		if (typeof(pQueuingNum) != "undefined") {
			maxQueuingNum = parseInt(pQueuingNum);
		}	
	} else if (type == 1) {
		var msg = "<div style='padding-left:5px'>"
					+"<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
					+"<span class='systemInfo' id='depTitle1'>"+lang.depTitle1+"</span>";
	}	
	
	for (var i=0; i < aryDep.length; i++){
		if (company == 16){
			msg += "<div style=\"line-height:23px;height:23px;\"><a href='#' class='depList' onClick='selectDep(\""
				+ aryDep[i].Id +"\", \""+ aryDep[i].Name +"\", \""+ type +"\"); return false'><font size=\"3\">" + aryDep[i].Name + "</font></a></div>";
		} else {
			msg += "<br /><a href='#' class='depList' onClick='selectDep(\""
				+ aryDep[i].Id +"\", \""+ aryDep[i].Name +"\", \""+ type +"\"); return false'>" + aryDep[i].Name + "</a>";
		}
	}
	
	msg += "</div>";
	exportLog(msg, -1, "trDep"+type);
	
	if (typeof(pEvent) != "undefined" && pEvent.length > 0) {
		exportDebugInfo('event.type='+typeof(pEvent), 'event.length'+pEvent.length);
		for (var i=0; i<pEvent.length; i++) {
				exportDebugInfo('event.id='+pEvent[i].Id, 'event.Name='+pEvent[i].Name);
		}
		showEventList(pEvent);
	}
}

function selectDep(depId, depName, type) {
	try {
		exportDebugInfo("selectDep", depId, depName, type);
		if (type == 0) {
			childDepId = depId;
			callFlashChat("flashChat").callFlashFun("DepartmentList", parentDepId, depId);
			exportDebugInfo("callFlashFun", "DepartmentList", parentDepId, depId);
			var msg = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
						+"<span class='systemInfo' id='systemMsg2'>"+lang.systemMsg2+"</span>";
			exportLog(msg, -1, 'trWelcomeMsg2');
			var msg = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
						+"<span class='systemInfo'>"+lang.top10Msg1+" "
						+"<img src='" + images + "ico/top10.gif' border='0'> "
						+lang.top10Msg2+"</span>";
			exportLog(msg, -1, "trTop10");
			setTimeout("removeLog('trTop10')", 10000);
			//hjget("imgTop10").src = "images + "chat_1_31_c.gif";
		} else if (type == 1) {
			parentDepId = depId;
			callFlashChat("flashChat").callFlashFun("parentDepartmentList", depId);
			exportDebugInfo("callFlashFun", "parentDepartmentList", depId);			
		}				
		removeLog("trDep"+type);
	} catch (e) {
	}
}

var chatStart = null;//聊天是否开始.
//pObjUsers, pChatHistory, pUseVer, pChatId, pChatTime, pOpWait, pVisitorWait, addTime  // 原参数列表.
function initChatRoom(pObjUsers, pChatHistory, pUseVer, pChatId, pChatTime, pOpWait, pVisitorWait, addTime, pVwot){
	chatStart = 1;
	var fromName = Array();
//	var pOpWait = null;
	try {
		for(var i=0; i<pObjUsers.length; i++){
			exportDebugInfo("objUser->", pObjUsers[i].Id, pObjUsers[i].Name);
			if (pObjUsers[i].Id.indexOf("PAGE") != -1) {
				vstId = pObjUsers[i].Id;
				var strName = pObjUsers[i].Name.substr(pObjUsers[i].Name.indexOf("~")+1);
				if (strName.length > 0 && strName != " ") {
					visitorName = decodeURI(strName);
					exportDebugInfo("*visitorName=", decodeURI(strName));//alert(visitorName);
				}
			} else {
				opArray.push(decodeURIComponent(pObjUsers[i].Name) + "," + pObjUsers[i].Id);
				curOpId = pObjUsers[i].Id;
				fromName[i] = pObjUsers[i].Name;
			}
		}
		initOperatroName(fromName);
	} catch (e) {
	}
	
	if (typeof(pUseVer) != "undefined") {
		useVer = parseInt(pUseVer);
	}
	
	if (typeof(pChatId) != "undefined") {
		chatId = pChatId;
	}
	
	if (typeof(pChatTime) != "undefined") {
		if (chatTimeShow == 1) {
			timerChat = parseInt(pChatTime);
		} else {
			timerChat = 100000;
		}
		
		timeAdd = parseInt(addTime);//延长对话时间.
		var msg = "<span id='chatWelcome'>"+lang.chatWelcome+'</span> '
					+'<span class="infoBright">'+pChatTime+'</span> <span id="secExt">'+lang.secExt+'</span> .';
		if (chatTimeShow == 1) {
			exportLog(msg, 0);
		}
	}

	if (typeof(pOpWait) != "undefined") {
		timerOpWait = opWaitTime = parseInt(pOpWait);
	}
	
	if (typeof(pVisitorWait) != "undefined") {
		timerVisitorWait = visitorWaitTime = parseInt(pVisitorWait);
	}
	
	if (typeof(pVwot) != "undefined"){
		visterWaitOpTime = pVwot;//Vwot = visterWaitOpTime;
	}
	
	if(timerQueuing != null) timerQueuing = null;
	if(maxQueuingNum != null) maxQueuingNum = null;
	removeLog("trWelcomeMsg2");
	removeLog("trQueuing");
	removeLog("trQueuingNumOver");
	if (timerFlashList != null) {
		clearInterval(timerFlashList); 
		timerFlashList = null;
	}
	
	$("#tdInput").show();	
	$("#inputDiv").show();
	$("#inputDiv_d").hide();
	$("#divChatTop").show();
	hjget("tabPanelButton").style.display = "";
	
	
	//if (isIE) hjget("objInput").disabled = false;
	//else objInput.document.designMode = "On"; 
	//else hjget("objInput").src = "";
//	hjget("objInput").disabled = false;

	//对话开始，启用输入框.
	inputStart();

	hjget("objInput").style.background = "#ffffff";
//	hjget("objInput").innerHTML = '&nbsp;';
	hjget("objInput").innerHTML = "&nbsp;";
	hjget("objInput").focus();
	
	setTimeout("loadFace()", 1000);
	if (timerSystem == null) timerSystem = setInterval("refreshTimer();", 1000);
	if(requestType == 2) removeLog("inviteSystemMsg1");
	
	statusChat = 1;
	exportDebugInfo("initChatRoom", "set", "statusChat="+statusChat);	
	preVstText();	
}


function showEventList(aryEvents) {
	var msg = lang.eventList+"<br />";
	exportLog(msg, 0);
	
	for (var i=0; i<aryEvents.length; i++) {
		var msg = "&nbsp;<a href='#' class='depList' onclick='getEventDetail(\""+aryEvents[i].Id+"\"); return false')'>"
				+"<img src='" + images + "closed.gif' border='0' /> "
				+aryEvents[i].Time+lang.eventTitle
				+"</a><br /><div id='divEventDetail_"+aryEvents[i].Id+"' style='display:none; padding-left:20px'></div><br />";
		exportLog(msg, -1);
	}
}

function getEventDetail(id) {
	try {
		callFlashChat("flashChat").callFlashFun("EventDetail", id);
		exportDebugInfo("callFlashFun", "EventDetail", id);
	} catch(e) {
	}
}

function EventDetail(pId, pContent, pMemo) {
	var objDiv = hjget("divEventDetail_"+pId);
	if (typeof(objDiv) != "undefined") {
		pContent = decodeURIComponent(pContent).replace(/(%2B)/g, " ");
		pMemo = decodeURIComponent(pMemo).replace(/(%2B)/g, " ");
		objDiv.innerHTML = "<span style='color:008cff'><b>" + pContent + ":</b><br />" + pMemo + "</span>";
		objDiv.style.display = "";
	}
}

function FlashListNum(num) {
	removeLog("trWelcomeMsg2");
	
	if (queuingNum == -1) {
		queuingNum = num;
	} else if (num < queuingNum) {
		if (num >= maxQueuingNum) queuingNum = maxQueuingNum;
		else queuingNum = num;		 
	}

	var txtTime = getNowTime();
	if (queuingNum == 0) {
		var txtLog = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
						+"<span id='spaQueuingTime' class='systemInfo'>["+txtTime+"] "
						+lang.queuingMsg3;
	} else {
		var txtLog = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
						+"<span id='spaQueuingTime' class='systemInfo'>["+txtTime+"] "
						+lang.queuingMsg1+'<span id="spaQueuingNum" class="infoBright"> <strong>'+ queuingNum +'</strong> </span>'+lang.queuingMsg2+'</span>';
	}
	
	if (num >= maxQueuingNum) {
		if (effectiveQueuing) {
			if (hjget("divQueuing")) {
				hjget("divQueuing").innerHTML	= txtLog;
			} else {
				exportLog("<div id='divQueuing'>"+ txtLog +"</div>", -1, "trQueuing");				
			}
		} else {
			goLeaveWord(3);
		}
	
	} else {
		if (!effectiveQueuing) effectiveQueuing = true;
		removeLog("trQueuingNumOver");
		
		if (hjget("divQueuing")) {
			hjget("divQueuing").innerHTML	= txtLog;
		} else {
			exportLog("<div id='divQueuing'>"+ txtLog +"</div>", -1, "trQueuing");
		}
	}
	
	if (timerSystem == null) timerSystem = setInterval("refreshTimer();", 1000);
	
	flashListNumStyle();
	
	if (timerFlashList == null)	timerFlashList = setInterval("FlashListNum("+queuingNum+")", 10000);
}

function flashListNumStyle() {
	setTimeout("$('#spaQueuingTime').css('color','#FF0000')", 200);	
	setTimeout("$('#spaQueuingTime').css('color','#000000')", 400);
	setTimeout("$('#spaQueuingTime').css('color','#FF0000')", 600);	
	setTimeout("$('#spaQueuingTime').css('color','#000000')", 800);
	setTimeout("$('#spaQueuingTime').css('color','#FF0000')", 1000);	
	setTimeout("$('#spaQueuingTime').css('color','#000000')", 1200);
	
	setTimeout("$('#spaQueuingNum').css('color','#FF0000')", 200);	
	setTimeout("$('#spaQueuingNum').css('color','#000000')", 400);
	setTimeout("$('#spaQueuingNum').css('color','#FF0000')", 600);	
	setTimeout("$('#spaQueuingNum').css('color','#000000')", 800);
	setTimeout("$('#spaQueuingNum').css('color','#FF0000')", 1000);	
	setTimeout("$('#spaQueuingNum').css('color','#000000')", 1200);
	
}

function EPageInfoOfClient(opId, strOpCard) {
	opName = opId;
	opInfoList = strOpCard;
	showOpCard(0);
}

function chatMsg(fromId, toId, msgType, content){
	exportDebugInfo("chatMsg", fromId, toId, msgType, content);
	operatorName = getOperatorName(fromId);
	//exportLog(unescape(content), 2);
	exportLog(decodeURIComponent(content.replace(/\+/gi," ")), 2);
	if (requestTime != null)
	{
		clearTimeout(requestTime);
		requestTime = null;
	}
	if (typeof windowFocusEventCounter != 'undefined')clearTimeout(windowFocusEventCounter);
	windowFocusEvent();
}

function AutoChatMsg(fromId, toId, msgType, aryContent) {
	operatorName = getOperatorName(fromId);
	var strContent = "";
	//alert((aryContent.length));
	if (aryContent.length == 1) {
		if (aryContent[0].id == 0) strContent = decodeURI(aryContent[0].title);
		else strContent = decodeURI(aryContent[0].id)+":<br />"+decodeURI(aryContent[0].title);
	} else {
		for(var i=0; i<aryContent.length; i++) {
			strContent += "<a href='#' onclick='selectAutoChatMsg("+aryContent[i].id+", "+msgType+", \""+fromId+"\"); return false'>"
							+decodeURI(aryContent[i].title)+"<a><br />";
		}
	}
	if (requestTime != null)
	{
		clearTimeout(requestTime);
		requestTime = null;
	}
	exportLog(strContent, 2);
}


function selectAutoChatMsg(id, type, opId) {
	callFlashChat("flashChat").callFlashFun("AutoChatMsg", vstId, opId, type, id);
	exportDebugInfo("AutoChatMsg", vstId, opId, type, id);
}

var toTimeLeaveWord = null;//无客服在线等待时间.
var setTimeToLeaveWord = null;//跳留言时间设定.
//无客服在线.
function JumpToLeaveWord(SnId) {	
	removeLog("trWelcomeMsg2");
	removeLog("trQueuing");
	if (timerFlashList != null) {
		clearInterval(timerFlashList); 
		timerFlashList = null;
	}
	var msg = '<span id="jumpToLeaveWord">'+lang.jumpToLeaveWord+"</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span id=\"leaveWordTitle\">"+lang.leaveWordTitle+"</span><br />"
				+"&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' class='depList' onclick='goBBSOrBar(6, 1); return false'><span id=\"bar\">"+lang.bar+"</span></a></span>";				
//				+"&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' class='depList' onclick='goBBSOrBar(6, 2); return false'>"+lang.bbs+"</a>";
	exportLog(msg, 0);
	$("#tabPanelButtonLeave").html($("#spanTop10").html());
	$("#tabPanelButtonLeave").show();
	$("#spanTop10").html("");
	//定时执行.
	setTimeToLeaveWord = 0;//old-180
	if (toTimeLeaveWord == null) toTimeLeaveWord = setInterval("setTimeLeaveWord();", 1000);
}

//定时判断是否跳留言.
function setTimeLeaveWord() {
	if (chatStart != 1 && defaultTab == 0) {
		
		if (setTimeToLeaveWord == 0) {
			setTimeToLeaveWord = null;
			changeTab(2);
			clearInterval(timerSystem);
		}

		if (setTimeToLeaveWord != null) {
			setTimeToLeaveWord = setTimeToLeaveWord - 1;
		}
	}
}

function BusyJumpToLeaveWord() {	
	removeLog("trWelcomeMsg2");
	var msg = lang.busyJumpToLeaveWord+"<br>"
				+"&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' class='depList' onclick='goBBSOrBar(6, 1); return false'>"+lang.bar+"</a>";				
//				+"&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' class='depList' onclick='goBBSOrBar(6, 2); return false'>"+lang.bbs+"</a>";
	exportLog(msg, 0);
}
//When new member join or leave chat (0: join; 1: leave).
function userStateChanged(type, opId, operatorName, showInfo){
	exportDebugInfo("userStateChanged", type, opId, operatorName, showInfo);
	switch (type)
	{
		case '0':
		case 0:
		curOpId = opId;
		exportDebugInfo("curOpId value:"+curOpId);
		var strOp = operatorName + "," + opId;
			opArray.push(strOp);
			setOpList();
			if (parseInt(showInfo) == 0) {
				var msg = lang.operator+" " +  operatorName + lang.joinChat;
				exportLog(msg, 0);
			}
			break;
		case '1':
		case 1 :
			var newOpArray = new Array();
			for(var i=j=0; i<opArray.length; i++){
				var strOldOp = opArray[i].split(",");
				if (strOldOp[1] != opId) {
					newOpArray[j] = opArray[i];
					j++;
				} else {
					operatorName = strOldOp[0];
				}
			}
			opArray = newOpArray;
			
			// operatorName 用来判断监控状态下，最先接入的客服退出提示"客服NAN退出"的提示.
			if (opArray.length > 1) {
				
			} else if (parseInt(showInfo) == 0 && operatorName) {
				var msg = lang.operator+"<span style='#0099ff'>" +  operatorName + "</span>"+ lang.exitChat;
				exportLog(msg, 0);
			}

			exportDebugInfo('opArray.length', opArray.length);
			if (opArray.length == 1) {
				statusChat = 3;
				exitChatRoom(0);
			}
			break;
		case '2':
			chatStart = 0;
			var msg = lang.userStateChanged_2 + lang.or;
				msg += "<a href='#' onclick='chatEndToLeaveWord(6);'>" + lang.selectMsg + "</a>";
			exportLog(msg, 0, 'userStateChanged_2');
			//BusyJumpToLeaveWord();
			break;
		case '3':
			inputEnd();
			var msg = lang.operator + ' ' +  operatorName + ' ' +  lang.userStateChanged_3 + lang.or;
				msg += "<a href='#' onclick='chatEndToLeaveWord(6);'>" + lang.selectMsg + "</a>";
			exportLog(msg, 0, 'userStateChanged_4');
			break;
		case '4':
//			if (isIE) hjget("objInput").disabled = false;
			inputStart();
			var msg = lang.operator + ' ' + operatorName + ' ' +  lang.userStateChanged_4;
			exportLog(msg, 0);
			removeLog("userStateChanged_4");
			break;
		case '5':
			inputEnd();
			var msg = lang.operator + ' ' + operatorName + ' ' + lang.userStateChanged_5;
				msg += "<a href='#' onclick='window.location.reload();'>" + lang.refresh + "</a> " + lang.or;
				msg += " <a href='#' onclick='chatEndToLeaveWord(6);'>" + lang.selectMsg + "</a>";
			exportLog(msg, 0);
			callFlashChat("flashChat").callFlashFun("LeftChatRoom", exitType);
			break;
	}
}

//对话连接断开跳转留言.
function chatEndToLeaveWord(exitType) {
	exportDebugInfo("chatEndToLeaveWord",exitType);
	callFlashChat("flashChat").callFlashFun("LeftChatRoom", exitType);
	goBBSOrBar(6, 1);
}

function UploadAndDownload(MsgType, FileUrl){
	switch(MsgType){
		//Finished upload or download.
		case "1":
			//hidePanel();
			var msg = lang.finishedSend;			
			exportLog(msg, 0);
			break;
		//On error.
		case "2":
			hidePanel();
			var msg = lang.sendError;			
			exportLog(msg, 0);
			tabSchedule.width = "0%";
			break;
		//Cancel upload	or download.
		case "8":
			hidePanel();
			var msg = lang.sendFileStop;			
			exportLog(msg, 0);
			tabSchedule.width = "0%";
			break;
	}
}

function FileOrPageSending(SendType, fromId, ToId, strUrl){
	var fromName = getOperatorName(fromId);
	//case file//	
	if (SendType == 0){
		var msg = lang.operator + fromName + lang.receiveFile;
		msg += "<br />&nbsp;&nbsp;&nbsp;&nbsp;<a href='"+ unescape(strUrl) +"' target='_blank' class='depList'>"+ lang.download +"</a>";		
		exportLog(msg, 0);		
	}
	//case link//	
	if (SendType == 1){
		var msg = lang.operator + fromName + lang.receiveLink;
		msg += "<br />&nbsp;&nbsp;&nbsp;&nbsp;<a href='"+ strUrl +"' class='depList' target='_blank'>"+ strUrl +"</a>";
		exportLog(msg, 0);		
		window.open(strUrl, "_blank", "");
	}
}

function DownLoadFile(strUrl) {
	try {
		callFlashChat("flashChat").callFlashFun("UploadAndDownload", 1, strUrl);
		exportDebugInfo("callFlashFun", "UploadAndDownload", 1, "strUrl");
	} catch (e) {
	}
}


function ClientInputStateChange(inputIdList) {
	var fromName = "";
	for (var i=0; i<inputIdList.length; i++) {
		if (i == 0) fromName += getOperatorName(inputIdList[i]);
		else fromName += ", " + getOperatorName(inputIdList[i]);
	}

	if (inputIdList.length == 0) {
		hjget("tdOpTyping").innerHTML = "&nbsp;";
	}else {
		hjget("tdOpTyping").innerHTML = "&nbsp;(<img src='" + images + "typing.gif' border='0' style=' float:none' /> "+lang.operator+" <span class='infoBright'>" 
																+ fromName + "</span> "+lang.isTyping+")";
	}
}


function DisConnected() {
	if (statusChat == 1) {
		var msg = lang.disConnected;
		exportLog(msg,0);
	}
}


function UDSwitch(opId, type) {
	if (type == 0) {
		hjget("imgFile").style.display = "none";
		var msg = lang.sendFileClose;
		exportLog(msg, 0);
	} else if (type == 1) {
		hjget("imgFile").style.display = "";
		var fileImgPath = images;
		var reg = /\/(zh\-cn|zh\-tw|en)\//;
		fileImgPath = fileImgPath.replace(reg,"/"+pageLang+"/");
		var msg = lang.sendFileOpen+" <img src='"+fileImgPath+"ico/sendfile.gif' border='0' />";
		exportLog(msg, 0);
	}
}


function EPageInfoSet(ContextName, Context, type) {
	if (type == 0) return;
	if (Context.length != 0 && Context.toString() != "null") {
		try {
			exportDebugInfo("callJsFun", "EPageInfoSet", ContextName, Context, type);
			//alert(ContextName);			
			switch (ContextName) {
				case "customName":
					Context = decodeURI(Context);
					if (Context == -1) {
//						var msg = lang.nickChange+" "+Context;
//						exportLog(msg, 0);
						var snid = callFlashChat("flashChat").getSNID();
						if(snid != 0){
							if (!userData)visitorName = lang.visitorName1 + parseInt(snid.substr(3,snid.length),10);
						}else{
							if (!userData)visitorName = lang.visitorName1;
						}
					} else {
//						var msg = lang.nickChange+" "+Context;
//						exportLog(msg, 0);
						if (!userData)visitorName = Context;
//						var nick = getCookie('HJLiveChatNccWebUserNickName');
//						if (nick != null) {
//							setCookie('HJLiveChatNccWebUserNickName', Context);		
//						}
					}
					break;
				case "isSaveEPageInfo":
					Context = decodeURI(Context);
					isSavedInfo = Context;
					break;
			}
		} catch(e) {
		}	
	}
}


function OverNumOfSysWait() {
	var msg = lang.queuingNumOver;
	exportLog(msg, 0);
	goLeaveWord(3);
	//exitChatRoom(3);
}

function loadKBS() {
	if (requestType != 2) {
		if (useKBS)
		{
		exportLog_kbs(lang.initChatWelcome//+operatorName
					+"<br />", 2, 1);
		}
		if(company != 70) //无机器人功能.
		statusChat = 1;

		loadChat();
	}
}

var lang_zhcn = "";
var lang_zhtw = "";
var lang_en = "";
var langInit = pageLang.replace("-","");
eval("lang_"+langInit+"=lang;");

function changeLang(chgLang)
{
	//var cntLang;
	var langVar = chgLang.replace("-","");
	var reg = /\/(zh\-cn|zh\-tw|en)\//;
	try
	{
		$("img").each
		(
			function (i) 
			{
				if (reg.test(this.src)) 
				{
					this.src = this.src.replace(reg,"/"+chgLang+"/");
				} 
			}
		);
	}
	catch(e)
	{}
	
	pageLang = chgLang;
	urlSendMsg 	= urlSendMsg+"&lang="+chgLang;
	urlBar		= urlBar+"&lang="+chgLang;
	eval("lang = lang_"+langVar+";");
	if (lang)
	{
		setLang(lang);
	}
	else
	{
		$.get
		(
			'getChatLang.php',
			{'aj':1,'lc':chgLang,'co':company},
			function(msg)
			{
				eval("lang = "+msg);
				setLang(lang);
				eval("lang_"+langVar+"= lang;");
			}
		);
	}
	//取得广告信息.
	$.getJSON("getChatAd.php?aj=1&l="+ chgLang +"&c=" + company + "&s=" + scheme_ID,
		function(data){
			$.each(data, function(adid,adStr){
				if(adid != 'title'){
					$("#"+adid).html(adStr);
				}else{
					try	{
					document.title = adStr;	
					}catch(e){}
				}
			});
		}
	); 
}

function setLang(langJson)
{
	var tempVar;
	var tempObj;
	var tempTag;
	if (!langJson) return ;
	/*	
	try
	{
		document.title = langJson.title;
		//operatorName = langJson.operatorName;
	}
	catch(e)
	{}
	*/
	for(var i in langJson)
	{
		j++;
		tempVar = "";
		tempVar = eval("langJson."+i);	
		tempObj = hjget(i);
		if (tempObj)
		{
			//alert(i+tempObj.tagName);
			tempTag = tempObj.tagName.toLowerCase();
			if ( tempTag == "input")
			{
				tempObj.value = tempVar;
			}
			else if ( tempTag == "img")
			{
				tempObj.setAttribute("title",tempVar);
			}
			else
			{
				if(tempVar != 'undefined')
				tempObj.innerHTML = tempVar;
			}
			
		}
		else
		{
			
		}
	}
}

//alert($("#simsun").html());
var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var menu_z_index = 1;

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if(obj.x)
	{
		curleft += obj.x;
	}
	return curleft - ietruebody().scrollLeft;
}
function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} 
	else if(obj.y)
	{
		curtop += obj.y;
	}
	return curtop - ietruebody().scrollTop;
}
//   var event = arguments[0]||window.event; 
//   var keyCode = event.charCode||event.keyCode;
//   var srcElement =event.target||window.event.srcElement;
function menupz(obj,type,contentId,bymouse)
{
	menu_z_index++;
	if (!contentId) contentId = "showmenu";
	var o = hjget(contentId);
	o.style.display = '';
	o.style.cssText = 'FILTER:Alpha(opacity=95);opacity:0.95;z-index:300000;position:absolute;';
	if (contentId == "showmenu") 
	{
		menu_z_index += 300000;
		o.style.cssText = 'FILTER:Alpha(opacity=95);opacity:0.95;position:absolute;z-index:'+menu_z_index;
	}
	//alert(o.style.cssText);
	if(typeof obj == 'string')
	{
		obj = hjget(obj);
	}
	if(obj == null)
	{
		o.style.top  = (ietruebody().clientHeight - o.offsetHeight)/2 + ietruebody().scrollTop + 'px';
		o.style.left = (ietruebody().clientWidth - o.offsetWidth)/2 + 'px';
	} 
	else
	{
		var top  = findPosY(obj);
		var left = findPosX(obj);
		//alert(top+"-"+left);
		if (!is_ie) {bymouse = 0;top += 2;left += 2;}
		if (bymouse == 1) 
		{
			try{
				var e = is_ie ? event: arguments[0];//alert(dump(e));
				left	= is_ie ? e.x : e.pageX;
				top		= is_ie ? e.y + ietruebody().scrollTop : e.pageY;
			}catch(e){ 
				return;
			}
		}
		//alert(top+"-"+left);
		if(top < ietruebody().clientHeight/2 || type>3)
		{
			top += ietruebody().scrollTop + obj.offsetHeight;
		} 
		else
		{
			top += ietruebody().scrollTop - o.offsetHeight;
		}
		if(left > (ietruebody().clientWidth)*3/5)
		{
			left -= o.offsetWidth - obj.offsetWidth;
			if (bymouse == 1) left -= o.offsetWidth-95;
		}
		o.style.top  = (top-5)  + 'px';
		o.style.left = left +'px';
		//alert(o.style.top+"-"+o.style.left+o.outerHTML);
	}
}


function mouseover_open(idName,object,type, contentId, bymouse)
{
	if(typeof type == "undefined")
	{
		type = 1;
	}
	
	if (!contentId) contentId = "showmenu";
	if (hjget(contentId).style.display == "none") hjget(contentId).style.display = "block";
	hjget(contentId).innerHTML = hjget(idName).innerHTML;
	hjget(contentId).className = hjget(idName).className;

	menupz(object,type,contentId,bymouse);
	try{
	if (contentId == "showmenu" && hjget("showmenu1")) closep("showmenu1");
	}catch(e){}
	if(type!=2)
	{
		document.onmouseout = doc_mouseout;
		//alert("ccc");
	}
	
	return false;
}
function closep(contentId)
{//alert(contentId);
	if (!contentId) contentId = "showmenu";
	hjget(contentId).style.display = "none";
	hjget(contentId).innerHTML = "";
	document.onmouseout = '';
	try{
	if (contentId == "showmenu" && hjget("showmenu1")) 
	{
		//showSub(navigationSubId , navigationTopId );
		//alert(navigationSubId +"-"+ navigationTopId);
	}//alert(navigationSubId +"-"+ navigationTopId+ "+");
	}catch(e){}
	return false;
}
function doc_mouseout(e,contentId)
{
	var e = is_ie ? event: e;
	if (!contentId) contentId = "showmenu";
	var o = hjget(contentId);
	_x	= is_ie ? e.x : e.pageX;
	_y	= is_ie ? e.y + ietruebody().scrollTop : e.pageY;
	_x1 = o.offsetLeft + 4;
	_x2 = o.offsetLeft + o.offsetWidth;
	_y1 = o.offsetTop - 20;
	_y2 = o.offsetTop + o.offsetHeight + 10;

	if(_x<_x1 || _x>_x2 || _y<_y1 || _y>_y2)
	{
		closep(contentId);
	}
}
function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
function IsElement(id)
{
	return document.getElementById(id)!=null ? true : false;
}

/**
 * 取得更换发送消息的键名.
 */
function displaySendType()
{
	mouseover_open('sendTypeDiv','sendTypeSelect','','',1);
	changeSendKeyStatus(sendKey);
}
function initOperatroName(opNameArr)
{
	var opNameStr;
	var k=0;
	for(var i in opNameArr)
	{
		if (k == 0) opNameStr = opNameArr[i];
		else opNameStr += ","+opNameArr[i];
		k++;
	}
	if (opNameStr) 
	{
		$("#tdOpStatus").show();
		$("#operatorStatus").html(opNameStr);
	}
}

function showOpCard(num) {
	if (theme != 1) {
		return false;
	}

	//设置页面元素尺寸.
	//$("#Content").width($("#chat").width()-180);
	$("#Content").height($("#chat").height()-120);
	
	if(statusVoice == 2 || statusVideo == 2){
		$("#Content").width($("#chat").width()-235);
	}else{
		$("#Content").width($("#chat").width()-169);	
	}

	if (num <= 0) {
		$("#view").width($("#Content").width());
		$("#view").height($("#Content").height()-129);
		$("#view_kbs").height($("#Content").height()-129);
		$("#shuru").width($("#Content").width());
		//$("#rightDiv").height($("#chat").height()-154);
		$("#rightDiv").height($("#Content").height());
		$("#rightDiv").css("left",$("#Content").width()+7);
		$("#video").css("left",$("#Content").width()+7);
		
		$("#divLog").width($("#Content").width());
		$("#divLog").height($("#Content").height() - 145);
		$("#imgAd").height($("#Content").height()-2);
		$("#rightDiv").height($("#Content").height());
		//
	}
	if (num == 1) {
		//自动应答.
		//显示广告.
		$("#video").hide();
		$("#rightDiv").show();

		$("#robot").show();
		$("#imgAd2").show();
		$("#imgAd2").height($("#rightDiv").height()-$("#robot").height()-10);
		$("#imgAd").hide();
		$("#opInfo").hide();
		if (statusVoice == 2 || statusVideo == 2) {
//			$("#Content").css('right','158px');
			$("#Content").width($("#chat").width()-169);
			showFlsh(0);				
		}
		$("#rightDiv").css("left",$("#Content").width()+5);
		/*
		if (statusVoice == 2 || statusVideo == 2) {
				$("#right").hide();
				$("#robot").show();
				$("#ad").height($("#rightDiv").height()-$("#robot").height()-10);
				$("#ad").show();
		} else {
			$("#robot").show();
			$("#opInfo").hide();
			$("#ad").height($("#rightDiv").height()-$("#robot").height()-10);
			$("#ad").show();
		}
		*/
	} else if (num == 2) {
		//留言.
		//显示广告.
		$("#rightDiv").show();
		$("#robot").hide();
		$("#opInfo").hide();
		$("#imgAd2").hide();
		$("#imgAd").show();
		if (statusVoice == 2 || statusVideo == 2) {
			$("#video").hide();
//			$("#Content").css('right','158px');
			$("#Content").width($("#chat").width()-169);
			showFlsh(0);

//			hjget("flashChat").width = '1';
//			hjget("flashChat").height = '1';				
		}
		$("#rightDiv").css("left",$("#Content").width()+5);
		$("#imgAd").height($("#Content").height());
		$("#rightDiv").height($("#Content").height());
	} else {
		$("#robot").hide();
		//对话.
		if (opName) {
			
			aryOpCard = opInfoList.split("|");
			//try {
//				hjget("opInfo").innerHTML = "<h1><span id='opCard'>"+lang.opCard+"</span></h1><ul>";
//				hjget("opInfo").innerHTML	+= "<li><span id='opTitle'>"+lang.opTitle+"</span><span>"
//																	+ aryOpCard[0] +"</span></li>";
//				hjget("opInfo").innerHTML	+= "<li><span id='opProfessional'>"+lang.opProfessional+"</span><span>"
//																	+ aryOpCard[1] +"</span></li>";
//				hjget("opInfo").innerHTML	+= "<li><span id='opTel'>"+lang.opTel+"</span><span>"
//																	+ aryOpCard[2] +"</span></li>";
//				hjget("opInfo").innerHTML	+= "<li><span id='opMob'>"+lang.opMob+"</span><span>"
//																	+ aryOpCard[3] +"</span></li>";
//				hjget("opInfo").innerHTML	+= "<li><span id='opEmail'>"+lang.opEmail+"</span><span>"
//																	+ aryOpCard[4] +"</span></li>";
//				hjget("opInfo").innerHTML	+= "<li>&nbsp;</li><li>&nbsp;</li>";

				hjget("opInfo").innerHTML = "<h1><span id='opCard'>"+lang.opCard+"</span></h1>"
											+ "<ul>"
											+ "<li><span title="+aryOpCard[0]+"><span id='opTitle'>"+lang.opTitle + "</span>" + aryOpCard[0] +"</span></li>"
											+ "<li><span title="+aryOpCard[1]+"><span id='opProfessional'>"+lang.opProfessional + "</span>" + aryOpCard[1] +"</span></li>"
											+ "<li><span title="+aryOpCard[2]+"><span id='opTel'>"+lang.opTel + "</span>" + aryOpCard[2] +"</span></li>"
											+ "<li><span title="+aryOpCard[3]+"><span id='opMob'>"+lang.opMob + "</span>" + aryOpCard[3] +"</span></li>"
											+ "<li><span title="+aryOpCard[4]+"><span id='opEmail'>"+lang.opEmail+ "</span>" + aryOpCard[4] +"</span></li>"
											+ "<li></li>"

											+ "<li style=\"height:27px; text-align:center; line-height:27px;\"><a href='opCardDownload.php?" 
											+ 'otitle=' + encodeURI(aryOpCard[0]) + '&opjob='+ encodeURI(aryOpCard[1]) + '&opphone=' + encodeURI(aryOpCard[2]) + '&opmobile=' + encodeURI(aryOpCard[3]) + '&opemail=' + encodeURI(aryOpCard[4]) 
											+ "' target='_blank'>" 
											+ "<img src='"+ images + "downcard.gif' /></a></li>"
											+ "</ul>";
				
				/*
				if (statusVoice == 2 || statusVideo == 2) {
					$("#right").show();
					$("#ad").hide();
					$("#robot").hide();
					$("#opInfo").hide();
				} else {
					$("#right").hide();
					$("#opInfo").show();
					$("#ad").show();
					$("#ad").height($("#rightDiv").height()-$("#opInfo").height()-12);
				}*/
				
				if (statusVoice == 2 || statusVideo == 2) {
					$("#video").show();
					$("#video").height($("#Content").height());
					$("#video").css("left",$("#Content").width()+5);
					$("#rightDiv").hide();
					$("#Content").css('right','220px');
					$("#divFlashChat").css("left", $("#Content").width()+10)
					showFlsh(1);
					
//					hjget("flashChat").width = '216';
//					hjget("flashChat").height = '360';
				}else{
					showFlsh(0);
					$("#video").hide();
					$("#imgAd").hide();
					$("#rightDiv").show();
					$("#opInfo").show();
					$("#imgAd2").show();
					$("#imgAd2").height($("#rightDiv").height()-$("#opInfo").height()-10);
					//showVideoChatInterface(0);
				}
			//} catch(e) {
			//}
		} else {
			$("#imgAd").show();
			$("#imgAd").height($("#rightDiv").height());
			showFlsh(0);
		}
	}
}

/**
 * 显示和关闭flash语音和视频.
 */
function showFlsh(type) {
	if(debug != 1){
		if (type == 1) {
			if (isIE) {
				hjget("flashChat").width = '216';
				hjget("flashChat").height = '360';
			} else {
				document.embeds["flashChat"].width = '216';
				document.embeds["flashChat"].height = '360';
			}
			$("#video").show();
		} else if(type == 0) {
			if (isIE) {
				hjget("flashChat").width = '1';
				hjget("flashChat").height = '1';
			} else {
				document.embeds["flashChat"].width = '1';
				document.embeds["flashChat"].height = '1';
			}
			$("#video").hide();
		}
	}else{
			if (isIE) {
					hjget("flashChat").width = '216';
					hjget("flashChat").height = '360';
			} else {
					document.embeds["flashChat"].width = '216';
					document.embeds["flashChat"].height = '360';
			}
	}
	return false;
}

function changeTab(id)
{
	var obj;
	
	var nowObj = hjget("tab"+id);
	if (nowObj.className == "Nowtab") {
		return false;
	}
	if(theme == 1) {
		defaultTab = id;
	}

	for(var i =0; i<3; i++)
	{
		obj = hjget("tab"+i);
		if (i == id)
		{
			obj.className = "Nowtab";
			if (theme == 1) {
				showOpCard(i);
			}
		}
		else
		{
			obj.className = "Ptab";
		}
	}
	if (id == 0)
	{
		hjget("tabContent0").style.display = "";
		hjget("tabContent1").style.display = "none";
		hjget("tabContent2").style.display = "none";

		tabSelected = 0;
	}
	else if (id == 1)
	{
		hjget("tabContent0").style.display = "none";
		hjget("tabContent1").style.display = "";
		hjget("tabContent2").style.display = "none";

		tabSelected = 1;
		//loadKBS();
	}
	
	else if (id == 2)
	{
		tabSelected = 2;
		$("#tabContent0").hide();
		$("#tabContent1").hide();
		$("#tabContent2").show();
		
		if(company == 70) {
			window.open("http://kefu.xoyo.com/index_zq.php?soft=ciba");
			window.close();
		}else{
			if (hjget("leaveMsgIframe").src != urlSendMsg)hjget("leaveMsgIframe").src = urlSendMsg+"&color="+pageColor+"&lang="+pageLang;
		}
	}
	//if(statusVoice == 2 || statusVideo == 2) {
		resizeWindow();
	//}
}



//******自動應答
function displaySendType_kbs()
{
	mouseover_open('sendTypeDiv','sendTypeSelect_kbs','','',1);
	changeSendKeyStatus(sendKey);
}

var kbsCount = 0;
//Send message.
function sendText_kbs() {
	//if (statusChat != 1) return false;	
	if (isIE) var objectInput = hjget("objInput_kbs");
	else var objectInput = objInput_kbs.document.body;
	var txtContent 			= objectInput.innerHTML;
	var txtFontFamily 		= objectInput.style.fontFamily;
	var txtFontSize 		= objectInput.style.fontSize;
	var txtColor 			= objectInput.style.color;		
	var txtFontStyle 		= objectInput.style.fontStyle;
	var txtFontWeight 		= objectInput.style.fontWeight;
	var txtTextDecoration 	= objectInput.style.textDecoration;

	if (txtFontFamily.length == 0) txtFontFamily = "simsun";
	if (txtFontSize.length == 0) txtFontSize = "12";
	if (txtColor.length == 0) txtColor = "#000000";	
	if (txtFontStyle.length == 0) txtFontStyle = "normal";
	if (txtFontWeight.length == 0) txtFontWeight = "normal";
	if (txtTextDecoration.length == 0) txtTextDecoration = "none";
	
	if (opId == "-1") {
		var chatType = 0;
	} else {
		var chatType = 1;
	}
	
	if (txtContent.replace(/(&nbsp;)|( )|(<br>)|(<br \/>)|(<BR>)|(<BR \/>)/g, "").length > 0) {
		if (txtContent.replace(/<[^<]+>/g, "").length > 500) {
			txtContent = txtContent.substr(0, txtContent.length-(txtContent.replace(/<[^<]+>/g, "").length-500));
			while(txtContent.replace(/<[^<]+>/g, "").length > 500) {
				txtContent = txtContent.substr(0, txtContent.length-100);
			}
		}

		var txtContentFull = "<span style='font-family:"+ txtFontFamily 
								+ "; font-style:"+ txtFontStyle 
								+ "; font-size:"+ txtFontSize 
								+ "; text-decoration:"+ txtTextDecoration 
								+ "; font-weight:"+ txtFontWeight 
								+ "; color:"+ txtColor 
								+"; line-height:130%;'>" + txtContent + "</span>";
		
		if (1) {//statusChat != 
			var strAnswer = "";
			//alert("qt=2&n=10&rst=3&c="+ company +"&q="+encodeURIComponent(txtContent));
			 $.ajax({
				 type: "GET",
				 url: urlKBS,
				 data: "qt=2&n=10&rst=3&t=2&c="+ company +"&q="+encodeURIComponent(txtContent),
				 dataType:"json",
				 success: function(rs){       
				 	//alert( "Data Saved: " + msg );     
					//eval("rs="+msg);
					//alert(rs.rc);
					kbsCount++;
					if (rs.rs.length > 1) {
						$.each(rs.rs,function(i){
							//alert(this.id+":"+this.q+":"+this.a);
							strAnswer += "<div><span style='cursor:pointer;color:#0000FF;text-decoration:underline;' onclick=showKbs('KT"+kbsCount+"-"+i+"')>&#8226;"
									  + this.q +":</span>&nbsp;&nbsp;<span style='color:#666; display:none;' id='KT"+kbsCount+"-"+i+"'>&nbsp;&nbsp;"
									  +this.a+"</span></div>";
						});
					} else {
						if (rs.rs[0].id == 0)
							//strAnswer = rs.rs[0].q+"<br />"+rs.rs[0].a+"<br />";
							strAnswer = lang.kbsNoAnswer;
						else 
							strAnswer = rs.rs[0].q+":<br />"+rs.rs[0].a+"<br />";
					}
					
					//strAnswer += "<span style='color:#666' >["+initChatNotTrust1+operatorName+initChatNotTrust2+"<a href='#' onclick='loadChat(); return false;' >"+initChatCS+"</a>]</span>";
					
					exportLog_kbs(strAnswer, 2);
					objectInput.focus();
				}   
			}); 
		} else {
			try{
				callFlashChat("flashChat").callFlashFun("chatMsg", opId, chatType, txtContentFull);
			}catch(e){
			}
		}
		
		exportLog_kbs(txtContentFull, 1);
		exportDebugInfo("callFlashChat", "chatMsg", opId, chatType, txtContentFull);
		
		objectInput.innerHTML = "";
		
	}
	
	//timerOpWait = opWaitTime;
}

function showKbs(id)
{
	if ($("#"+id).css('display') == 'none')
	$("#"+id).show('slow');
	else 
	$("#"+id).hide('slow');
}

//Write message into LogDiv.
function exportLog_kbs(txt, type) {
	try {
		var txtLog = "";
		var txtTime = getNowTime();
		switch(type) {
			case -1:
				txtLog = txt;
				break;
			case 0:
				txtLog = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'>"
							+"<span class='systemInfo'> " + txt +"</span>";
				break;
			case 1:
				txtLog = "<span class='vstChatTitle'>"+ visitorName + " " + txtTime + "</span><div class='chatContent'>" + txt + "</div>";
				break;
			case 2:
				txtLog = "<span class='opChatTitle'>"+ lang.operatorRobot + " " + txtTime + "</span><div class='chatContent'>" + txt + "</div>";
				break;
		}
		
		var rowLog = hjget("tabLog_kbs").insertRow(-1);
		if (type == -1 && typeof(arguments[2]) != "undefined") {			
			rowLog.id = arguments[2];
		}
		var tdLog = rowLog.insertCell(0);
		tdLog.innerHTML = txtLog;
		
		if (type == 1 || type == 2) {			
			var logAnchors = tdLog.getElementsByTagName("a");		 
			for (var i=0; i<logAnchors.length; i++) { 
				logAnchors[i].target = "_blank";
			}
			var logAnchors = tdLog.getElementsByTagName("A");		 
			for (var i=0; i<logAnchors.length; i++) { 
				logAnchors[i].target = "_blank";
			}
		}
		//alert(txtLog);
		hjget("divLog_kbs").scrollTop = hjget("tabLog_kbs").scrollHeight;
		window.focus();
		hjget("objInput_kbs").focus();
		exportDebugInfo('exportLog_kbs', txt, type);
	} catch(e) {
	}
}

//------------ voice start ---------------------------//
var AskForVChatFlag = 0;
//Visitor ask voice chat.
function sendVoiceAsk() {
	//如果在视频，语音不启用.
	if (statusVideo == 2) {
//		callFlashChat("flashChat").callFlashFun("InvitToVChat",1);
		return false;
	}

	var msg = lang.sendVoice+"<br><a href=\"#\" onclick=\"exitVoice();return false;\" style=\"margin-left:10px\">"+lang.handup+"</a>";
	exportLog(msg, 0,'trAskForVChat');

	try {
		callFlashChat("flashChat").callFlashFun("AskForVChat");
		exportDebugInfo("callFlashFun", "AskForVChat");
		hjget("tdExitVoice").style.display = "";
		hjget("tdVoice").style.display = "none";
		statusVoice = 2;
		AskForVChatFlag = 1;
		showVideoChatInterface(1);
	} catch(e) {
	}
}

//Visitor leave voice chat.
function exitVoice() {
	try {
		var msg = lang.vstExitVoice;
		exportLog(msg, 0);
		showVideoChatInterface(0);
		statusVoice = 0;
		hjget("tdExitVoice").style.display = "none";
		hjget("tdVoice").style.display = "";
		callFlashChat("flashChat").callFlashFun("LeftVChat");
		exportDebugInfo("callFlashFun", "LeftVChat");
		if (theme == 1) {
			showOpCard(defaultTab);
		}
		showVideoChatInterface(0);
	} catch(e) {
	}
}

function InvitToVChat(fromId) {
	//如果正在视频，语音不启用.
	if (statusVideo == 2) {
//		callFlashChat("flashChat").callFlashFun("InvitToVChat",1);
		return false;
	}
	try {
		var divId = Math.floor(Math.random()*1000000);
		hj5107.voiceAltDivId = divId;
		var msg = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
					+ "<span class='systemInfo'>"+ lang.operator+" "+ operatorName +" "+lang.receiveVoice+"</span>"
					+ " <a href='#' onclick='voiceAnswer(0, \""+divId+"\"); return false'>"+lang.accept+"</a>"
					+ " <a href='#' onclick='voiceAnswer(1, \""+divId+"\"); return false'>"+lang.refuse+"</a>";
		exportLog(msg, -1, divId);
		hjget("tdExitVoice").style.display = "";
		hjget("tdVoice").style.display = "none";
		statusVoice = 1;
		exportDebugInfo("InvitToVChat");
	} catch(e) {
	}
}

function cancleSoundInvite(){
	//取消语音邀请.
	try{
		if(hj5107.voiceAltDivId != null){
			removeLog(hj5107.voiceAltDivId);
			hj5107.voiceAltDivId = null;
		}
	}catch(e) { 
	}
}

function voiceAnswer(type, divId) {
	try {
		if (type == 0) {
			//同意.
			//hjget(divId).innerHTML = "<td>{% $lang.acceptVoice %}</td>";
			removeLog(divId);
			callFlashChat("flashChat").callFlashFun("InvitToVChat",0);
			//hjget("tdExitVoice").style.display = "";
			//hjget("tdVoice").style.display = "none";
			var msg = EnterVChatGroupMsg;
			exportLog(msg, 0);
			statusVoice = 2;
			showVideoChatInterface(1);
		} else if (type == 1) {
			//拒绝.
			//hjget(divId).innerHTML = "<td>{% $lang.vstExitVoice %}</td>";
			removeLog(divId);
			callFlashChat("flashChat").callFlashFun("InvitToVChat",1);
			//hjget("tdExitVoice").style.display = "none";
			//hjget("tdVoice").style.display = "";
			statusVoice = 3;
			showVideoChatInterface(0);
			
			exportLog(lang.refuseAudio, 0);
		}
		exportDebugInfo("voiceAnswer", type, divId);
	} catch(e) {
	}
}

//访客邀请进行语音交谈被拒绝时.
function BeenRejectOfVCInvite() {
	try {
		var msg = lang.opRefuseVoice;
		exportLog(msg, 0);
		exportDebugInfo("BeenRejectOfVCInvite");
		// 请求语音被客服拒绝时.
		statusVoice = 0;
		showOpCard(defaultTab);
		$("#video").hide();
			$("#rightDiv").show();
			$("#Content").css('right','158px');
//		statusVideo
	} catch(e) {
	}
}

//有人离开交谈组消息.
function LeftVChatGroup(userId) {
	try {
//		var msg = lang.operator+ getOperatorName(inputIdList[i]) + lang.opExitVoice;
		var msg = lang.operator+ getOperatorName(userId) + lang.opExitVoice;
		exportLog(msg, 0);
		exportDebugInfo("LeftVChatGroup", userId);
		//statusVoice = 0;
//		statusVideo = 0;
		//showVideoChatInterface(0);
	}catch(e) {
	}
}
var EnterVChatGroupMsg = '';
//有人加入语音交谈组消息.
function EnterVChatGroup(userId) {
	try {
		exportDebugInfo("EnterVChatGroup", "inputIdList", "i");
//		var msg = lang.operator+ getOperatorName(inputIdList[i]) + lang.opJoinVoice;
		EnterVChatGroupMsg = lang.operator+ getOperatorName(userId) + lang.opJoinVoice;
		if (AskForVChatFlag == 1)
		{
			removeLog("trAskForVChat");
			exportLog(EnterVChatGroupMsg, 0);
		}
		curOpId = userId;
		statusVoice = 2;
		//showVideoChatInterface(1);
		exportDebugInfo("LeftVChatGroup", userId);
	}catch(e) {
	}
}
//------------ voice end ---------------------------//


//------------ video start ------------------------//
//Show video chat operator list//
function showVideoChatOperatorList() {
	var divVideoChatOperatorList = hjget("div_VideoChatOperatorList");
	if (divVideoChatOperatorList.style.display == "none") {
		divVideoChatOperatorList.style.display = "";
	} else {
		divVideoChatOperatorList.style.display = "none";
	}	
}


//Visitor ask video chat.
function sendVideoAsk(toOperator) {
	var msg = lang.sendVideo;
	exportLog(msg, 0);
	hjget("div_VideoChatOperatorList").style.display = 'none';
	timerVideoChat = setTimeout("videoChatRequestTimeout()", 30000);
	try {
		callFlashChat("flashChat").callFlashFun("AskForChatVideo", toOperator);
		exportDebugInfo("callFlashFun", "AskForChatVideo");
		hjget("tdExitVideo").style.display = "";
		hjget("tdVideo").style.display = "none";
	} catch(e) {	
	}
}

function videoChatRequestTimeout() {
	showVideoChatInterface(0);
	callFlashChat("flashChat").callFlashFun("TerminationInvite");		
	exportDebugInfo("callFlashFun", "TerminationInvite");
}

function vstAnswerVideoChatTimeout(divId) {
	//var msg = rejectVideo;
	removeLog(divId);
	showVideoChatInterface(0);	
	
	exportLog(lang.videoTimeout, 0);
}

//Visitor leave video chat.
function exitVideo() {
	try {
		var msg = lang.vstExitVideo;
		exportLog(msg, 0);
		statusVideo = 0;
		statusVoice = 0;
		showVideoChatInterface(0);
		
		
		//hjget("tdExitVideo").style.display = "none";
		callFlashChat("flashChat").callFlashFun("LeftChatVideo");
		exportDebugInfo("callFlashFun", "LeftChatVideo");
	} catch(e) {
	}
}

function showVideoChatInterface(type) {
	if (type == 1) {
		//显示视频框.
		if (statusVoice == 2 && statusVideo == 2) {
			$("#tdExitVoice").show();
			$("#tdVoice").hide();
			$("#tdExitVideo").show();
		}else if (statusVoice == 2) {
			hjget("tdExitVoice").style.display = "";
			hjget("tdVoice").style.display = "none";
		} else if (statusVideo == 2) {
			$("#tdExitVoice").hide();
//			$("#tdVoice").show();
			$("#tdExitVideo").show();
		} else {
			hjget("tdExitVoice").style.display = "none";
			hjget("tdVoice").style.display = "";
			$("#tdExitVideo").hide()
		}
		if (theme == 1) {
			$("#Content").css('right','220px');
			$("#rightDiv").hide();
			$("#video").show();
		} else {
			if (statusVoice == 2 || statusVideo == 2) {
				$("#right").show();
			} else {
				$("#right").hide();
			}
		}
		showFlsh(1);
//		hjget("flashChat").width = '216';
//		hjget("flashChat").height = '360';
	} else if (type == 0) {
		//如果在语音交谈.
		if (statusVideo == 2) {
//			$("#tdExitVoice").show();
//			$("#tdVoice").hide();
			$("#tdExitVideo").show();
		} else {
			$("#tdExitVideo").hide();
		}
		
		if (statusVoice == 2) {
//			$("#tdExitVoice").show();
//			$("#tdVoice").hide();
			$("#tdExitVoice").show();
		} else {
			$("#tdExitVoice").hide();
			$("#tdVoice").show();
		}
		

		$("#right").hide();
		if (theme == 1) {
			$("#video").hide();
			$("#rightDiv").show();
			$("#Content").css('right','158px');
		}
		showFlsh(0);
//		hjget("flashChat").width = '1';
//		hjget("flashChat").height = '1';
	}
	resizeWindow();
}

/* Visitor recive operator video invite */
function ReceiveVideoInvite(opID) {
	if (statusVoice == 2) {
//		callFlashChat("flashChat").callFlashFun("RejectClientVideo");
		return false;
	}
	var operatorName = getOperatorName(opID);
	var divId = Math.floor(Math.random()*1000000);

	var msg = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
				+ "<span class='systemInfo'>"+ lang.operator+" "+ operatorName +" "+lang.receiveVideo+"</span>"
				+ " <a href='#' onclick='videoAnswer(0, \""+divId+"\"); return false'>"+lang.accept+"</a>"
				+ " <a href='#' onclick='videoAnswer(1, \""+divId+"\"); return false'>"+lang.refuse+"</a>";
	exportLog(msg, -1, divId);
	//hjget("tdExitVideo").style.display = "none";
	//hjget("tdVideo").style.display = "none";
//	hjget("tdVoice").style.display = "none";
	exportDebugInfo("ReceiveVideoInvite");
	timerVideoChat = setTimeout("vstAnswerVideoChatTimeout("+divId+")", 20000);
}

function videoAnswer(type, divId) {
	try {
		if (type == 0) {
			//同意.
			//hjget(divId).innerHTML = "<td>{% $lang.acceptVoice %}</td>";
			removeLog(divId);
			callFlashChat("flashChat").callFlashFun("AgreeClientVideo");
			statusVideo = 2;
			showVideoChatInterface(1);
			clearTimeout(timerVideoChat);
			timerVideoChat = null;			
		} else if (type == 1) {
			//拒绝.
			//hjget(divId).innerHTML = "<td>{% $lang.vstExitVoice %}</td>";
			removeLog(divId);
			callFlashChat("flashChat").callFlashFun("RejectClientVideo");
			statusVideo = 3;
			showVideoChatInterface(0);
			
			exportLog(lang.refuseVideo, 0);
		}
		exportDebugInfo("videoAnswer", type, divId);
	} catch(e) {
	}
}

/* visitor receive operator video close */
function ReceiveVideoClose(opID) {
	var operatorName = getOperatorName(opID);
	var msg = "<span class='systemInfo'>"+ lang.operator+" "+ operatorName +" "+lang.opExitVideo+"</span>";
	exportLog(msg, 0);
	statusVideo = 0;
	showVideoChatInterface(0);
}

/* visitor receive operator answer about video chat */
function ReplayFromClient(opID, type) {
	switch (type) {
		case "agree":
			//Operator agree video chat request//
			var operatorName = getOperatorName(opID);
			var msg = "<span class='systemInfo'>"+ lang.operator+" "+ operatorName +" "+lang.opJoinVideo+"</span>";
			exportLog(msg, 0);
			clearTimeout(timerVideoChat);
			timerVideoChat = null;
			statusVoice = 2;
			showVideoChatInterface(1);
			break;
		case "reject":
			//Operator reject video chat request//
			var operatorName = getOperatorName(opID);
			var msg = "<span class='systemInfo'>"+ lang.operator+" "+ operatorName +" "+lang.opRefuseVideo+"</span>";
			exportLog(msg, 0);
			clearTimeout(timerVideoChat);
			timerVideoChat = null;
			showVideoChatInterface(0);
			break;
		case "CameraBusing":
			var operatorName = getOperatorName(opID);
			var msg = "<span class='systemInfo'>"+ lang.operator+" "+ operatorName +" "+lang.opCameraIsBusy+"</span>";
			exportLog(msg, 0);
			clearTimeout(timerVideoChat);
			timerVideoChat = null;
			showVideoChatInterface(0);
			break;
		case "NoCamera":
			var operatorName = getOperatorName(opID);
			var msg = "<span class='systemInfo'>"+ lang.operator+" "+ operatorName +" "+lang.opNoCamera+"</span>";
			exportLog(msg, 0);
			clearTimeout(timerVideoChat);
			timerVideoChat = null;
			showVideoChatInterface(0);
			break;
	}
	
}
//------------ video end ------------------------//

//------------ 满意度调查推送 start ------------------------//
/**
 * pushQN
 * 满意度调查推送.
 */
function pushQN(opId,opCode)
{
	//alert(opId+opCode);
	QNopId = opId;
	QNopCode = opCode;
	$.get
	(
		'../include/satisfaction.php',
		{aj:1,action:'getSurvey',lc:pageLang,co:company,rndVar:(new Date()).getTime()},
		function (msg)
		{
			if (msg) {
				var msg = "<div>"+lang.pushQN1+"<br />" + msg + "</div>";					
				exportLog(msg, 2);
			}
		}
	);
}
/**
 * setSurveyFun
 * 满意度调查提交.
 */
function setSurveyFun()
{
	//alert(opId+opCode);
	surveyVal 	= selectRadio('surveyItem');
	surveyStr 	= $("#surveyItemStr"+surveyVal).html();
	$.get
	(
		'../include/satisfaction.php',
		{aj:1,action:'setSurvey',lc:pageLang,chatId:chatId,surveyVal:surveyVal,co:company,rndVar:(new Date()).getTime()},
		function (msg)
		{	
			if ( msg == 'OK' )
			{
				try {
					callFlashChat("flashChat").callFlashFun("QNResult", QNopId, QNopCode, encodeURI(surveyStr));
					exportDebugInfo("callFlashFun", "QNResult", QNopId, QNopCode, encodeURI(surveyStr));
				} 
				catch (e) 
				{}
				msg = lang.setSurveyFun1+lang.operator+"&nbsp;"+getOperatorName(QNopId)+"&nbsp;"+lang.setSurveyFun2+surveyStr;
				var a = hjget("surveyItemStr"+surveyVal).parentNode.parentNode.parentNode;
				a.innerHTML = msg;
			}
		}
	);
}

/**
 * 选择Radio，取得值.
 */
function selectRadio(radioName)
{//alert(radioName);
	var tempRadio = document.getElementsByName(radioName);
	
	for (var i=0; i<tempRadio.length; i++) 
	{
		if (tempRadio[i].checked == true) 
		{
			var tempValue = tempRadio[i].value;
			break;
		}
	}
	//alert(tempValue);
	return tempValue;
}

/**
 * 设置Radio，值.
 */
function setRadio(radioName,checked)
{//alert(radioName);
	var tempRadio = document.getElementsByName(radioName);
	var number = "";
	for (var i=0; i<tempRadio.length; i++) 
	{
		if (tempRadio[i].value == checked) 
		{
			tempRadio[i].checked = true;
			number = i;
			break;
		}
		else
		{
			tempRadio[i].checked = false;
		}
	}
	//alert(tempValue);
	return number;
}
//------------ 满意度调查推送 end ------------------------//

//电子白板功能开始.
/**
 * inviteEB
 * 收到客服eBoard邀请.
 * 参数列表:coid,chatGroupid,opid,snid,操作码("1").
 */
function inviteEB(coid, chatGroupid, opid, snid)
{
	var operatorName = getOperatorName(opid);
	var divId = Math.floor(Math.random()*1000000);

	var msg = "<img src='" + images + "sysinfo.gif' width='14' height='14' border='0'> "
				+ "<span class='systemInfo'>"+ lang.operator+" "+ operatorName +" "+lang.inviteEB+"</span>"
				+ " <a href='#' onclick='EBAnswer(1, \""+divId+"\",\""+chatGroupid+"\",\""+opid+"\",\""+snid+"\"); return false'>"+lang.accept+"</a>"
				+ " <a href='#' onclick='EBAnswer(0, \""+divId+"\",\""+chatGroupid+"\",\""+opid+"\",\""+snid+"\"); return false'>"+lang.refuse+"</a>";
	exportLog(msg, -1, divId);	
}

var EBStart = null;
var ebWin = null;
/**
 * EBAnswer
 * 电子白板请求回复.
 * @param type (0,拒绝,1,同意.)
 */
function EBAnswer(type, divId, chatGroupid, opid, snid)
{
	callFlashChat("flashChat").callFlashFun("replyEB", opid, type);
	exportDebugInfo("callFlashFun", "replyEB", opid, type);		
	if(type == 0){
		//拒绝电子白板请求.
		removeLog(divId);
		var msg = lang.refuseEB;
		exportLog(msg, -1);
	}else if(type == 1){
		EBStart = 1;
		//同意电子白板请求.
		var ebUrl = "eBoard.php";
			ebUrl += "?cpId="+company+"&gpId="+chatGroupid+"&opId="+opid+"&snId="+snid+"&chatId="+chatId+"&lan="+pageLang+"&bId=1";
		ebWin = window.open(ebUrl, 'ebWindow', 'height=500, width=588, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, status=yes');
		if(ebWin == null){
			alert("ebwin error!");
		}else{
			removeLog(divId);
			var msg = lang.acceptEB;
			exportLog(msg, -1);
		}
	}
}

/**
 * closeEB
 * 访客关闭电子白板.
 * @param opid.
 */
function closeEB(opid)
{
	callFlashChat("flashChat").callFlashFun("closeEB", opid);
	var msg = lang.exitEB;
	EBStart = null;
	exportLog(msg, -1);
	exportDebugInfo("callFlashFun", "closeEB", opid);
	
}

/**
 * closeEBCient
 * 客服关闭电子白板.
 * @param opid.
 */
function closeEBCient(){
	ebWin.window.close();
}

//电子白板功能结束.

function paramRelative(iTime, iNum, aEvent) {
	if (typeof(iTime) != "undefined") {
		timerQueuing = parseInt(iTime);
	}
	
	if (typeof(iNum) != "undefined") {
		maxQueuingNum = parseInt(iNum);
	}	
		
	if (typeof(aEvent) != "undefined" && aEvent.length > 0) {
		exportDebugInfo('event.type='+typeof(aEvent), 'event.length'+aEvent.length);
		for (var i=0; i<aEvent.length; i++) {
				exportDebugInfo('event.id='+aEvent[i].Id, 'event.Name='+aEvent[i].Name);
		}
		showEventList(aEvent);
	}
	
}

function KeyDown(){ 
	try{
		if ((window.event.altKey)&& 
		((window.event.keyCode==37)|| 
		(window.event.keyCode==39))){ 
			event.returnValue=false; 
		} 
		if ((event.ctrlKey)&&(event.keyCode==78)){ //屏蔽 Ctrl+n 
			event.returnValue=false; 
		}
	}catch(e){ }
} 
function dump(obj)
{
	var str = '';
	for(var i in obj)
	{
		str += i+':'+ eval("obj."+i)+"<br>\r\n";
	}
	//document.getElementById("debug").innerHTML += str;
	return str;
}

function IFJSinitOK() {
	try {
		if (statusKBS == 1 || requestType == 2) {
			callFlashChat("flashChat").callFlashFun("JSinitOK");
			exportDebugInfo("callFlashFun", "JSinitOK");
		}
	} catch (e) {
	}
}

function checkFlashInit() {	
	try{
		if (isIE) {
			var iChatLoaded = $("#flashChat")[0].PercentLoaded();
			var iSNLoaded = $("#flashSN")[0].PercentLoaded();
		} else {
			var iChatLoaded = document.embeds["flashChat"].PercentLoaded();
			var iSNLoaded = document.embeds["flashSN"].PercentLoaded();
		}
	}catch(e){
		hj5107.swf = hj5107.fla.chk();
		if(hj5107.swf == false){
			hj5107.loadJs(hj_proxyUrl+"chat_msg.js");
			//iFlashLoaded = 1;
			isSavedInfo = 1;
			startWebLink();
			exportDebugInfo("checkFlashInit");
		}
		clearInterval(oCheckFlash); 
		return; 
	}
	
	if (debug) $("#tdFlashDebug").html('&nbsp;Flash Debug: (SN:'+iSNLoaded+"%)(Chat:"+iChatLoaded+"%)");
	if (iChatLoaded == 100 && iSNLoaded == 100) {
		clearInterval(oCheckFlash);
		oCheckFlash = null;	
		iFlashLoaded = 1;
	}
}
//var oCheckFlash = setInterval("checkFlashInit()", 100);

function startWebLink(){
	if(hj5107.proxyLoad){
		hj_jsweblink(1, '');
	}else{
		setTimeout("startWebLink()",200);
	}	
}

function requestTimeOver()
{
	if (statusChat==1) exportLog(lang.LangRequestTimeOverText1, 2);
}

var windowFocusEventCounter = 0;
var windowFocusEventCount = 0;
var windowFocus = 0;
var inputFocus = 0;

window.onblur = function ()
{

	if (typeof windowFocusEventCounter != 'undefined')clearTimeout(windowFocusEventCounter);
	windowFocus = 0;
	
	document.title = document.title.toString().replace(eval("/"+lang.LangNewMsgAlert+"/g"),"");
	//document.title = document.title.toString().replace(newMsg,"");
	//writeMsg(windowFocus);
	//$("#bottom").html($("#bottom").html()+'b');

};

window.onfocus = function ()
{
	if (typeof windowFocusEventCounter != 'undefined')clearTimeout(windowFocusEventCounter);
	windowFocus = 1;
	
	document.title = document.title.toString().replace(eval("/"+lang.LangNewMsgAlert+"/g"),"");
	//$("#bottom").html($("#bottom").html()+'f'+windowFocus);
};

function windowFocusEvent()
{//exportDebugInfo('windowFocusEvent',windowFocus,inputFocus,lang.LangNewMsgAlert);
//writeMsg(windowFocus);
	if (is_ie && windowFocus == 0 && inputFocus == 0 || !is_ie && inputFocus == 0)//windowFocus == 0
	{
		if (windowFocusEventCount%2 ==0)
		{document.title = lang.LangNewMsgAlert+document.title.toString();}
		else 
		{document.title = document.title.toString().replace(eval("/"+lang.LangNewMsgAlert+"/g"),"");}
		//exportDebugInfo('windowFocusEvent',windowFocus,inputFocus,lang.LangNewMsgAlert,document.title);
	}
	windowFocusEventCount++;
	windowFocusEventCounter = setTimeout(function(){windowFocusEvent();},500);

}


function sendScreenShort()
{
	if (isIE) {
		var event = arguments[0]||window.event; 
		var keyCode = event.charCode||event.keyCode;
		var srcElement =event.target||window.event.srcElement;
	
		var strTemp = '';
		//alert(event.keyCode+"|"+event.ctrlKey+"|"+event.altKey);	
		if (event.keyCode == 88){
			if(event.ctrlKey && event.shiftKey) {	
				sendScreen();
			}
		}
	}
}

hj5107.loadJs = function(s) 
{
		var html_doc = document.getElementsByTagName('head').item(0);
		var js = document.createElement('script');
		js.setAttribute('language', 'javascript');
		js.setAttribute('type', 'text/javascript');
		js.setAttribute('src', s);
		html_doc.appendChild(js);
};

hj5107.fla = {
	ControlVersion:function () {
		var version;
		var axo;
		var e;

		// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
		try {
			// version will be set for 7.X or greater players
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
		if (!version) {
			try {
				// version will be set for 6.X players only
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				
				// installed player is some revision of 6.0
				// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
				// so we have to be careful. 
				
				// default to the first public version
				version = "WIN 6,0,21,0";

				// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
				axo.AllowScriptAccess = "always";

				// safe to call for 6.0r47 or greater
				version = axo.GetVariable("$version");
			} catch (e) {
			}
		}

		if (!version) {
			try {
				// version will be set for 4.X or 5.X player
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				version = axo.GetVariable("$version");
			} catch (e) {
			}
		}

		if (!version) {
			try {
				// version will be set for 3.X player
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				version = "WIN 3,0,18,0";
			} catch (e) {
			}
		}

		if (!version) {
			try {
				// version will be set for 2.X player
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				version = "WIN 2,0,0,11";
			} catch (e) {
				version = -1;
			}
		}
		return version;
	},
	// JavaScript helper required to detect Flash Player PlugIn version information
	GetSwfVer : function () {
		// NS/Opera version >= 3 check for Flash plugin in plugin array
		var flashVer = -1;
		var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
		var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
		var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
		
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
				var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
				var descArray = flashDescription.split(" ");
				var tempArrayMajor = descArray[2].split(".");			
				var versionMajor = tempArrayMajor[0];
				var versionMinor = tempArrayMajor[1];
				var versionRevision = descArray[3];
				if (versionRevision == "") {
					versionRevision = descArray[4];
				}
				if (versionRevision[0] == "d") {
					versionRevision = versionRevision.substring(1);
				} else if (versionRevision[0] == "r") {
					versionRevision = versionRevision.substring(1);
					if (versionRevision.indexOf("d") > 0) {
						versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
					}
				}
				var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			}
		}
		// MSN/WebTV 2.6 supports Flash 4
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
		// WebTV 2.5 supports Flash 3
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
		// older WebTV supports Flash 2
		else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
		else if ( isIE && isWin && !isOpera ) {
			flashVer = hj5107.fla.ControlVersion();
		}
		return flashVer;
	},
	chk : function () {
		versionStr = hj5107.fla.GetSwfVer();
		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			return true;
		}
	}		
};

$().ready(function(){
	if($('#mqAd').length){
		$('#mqAd').marquee('pointer').mouseover(function () {   
			$(this).trigger('stop');
		}).mouseout(function () {
			$(this).trigger('start');
		}).mousemove(function (event) {
			if ($(this).data('drag') == true) {
				this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
			}
		}).mousedown(function (event) {
			$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
		}).mouseup(function () {
			$(this).data('drag', false);
		});
	}
	hj5107.loadJs(hj_proxyUrl+"hjProxy.js");
});

