﻿	rc365.include("/fms/iutil.js")
	rc365.include("/share/SubFunction_JS/base/jqdnr.js")
	rc365.include("/share/SubFunction_JS/base/cookie.js");
	var indexNum = 9000001;	// 层的优先级用于激活窗口
	var py		 = true;	// 是否偏移
	var pyAdd	 = true;	// 偏移+-类型
	var pyNum	 = 20;		// 平均偏移像素数
	var pyTop 	 = 100;		// 偏移顶部坐标初始位置
	var pyLeft	 = 200;		// 偏移左侧坐标初始位置

	//=============================================
	// 功能：弹出信息状态配置条
	// 参数：flash的Url;宽;高
	//=============================================
	function openIMTool(flashUrl,width,height)
	{
		var toolObj = $("#imToolInfo");
		if (toolObj.is("div"))
		{
			toolObj.show('slow');
		}
		else
		{
			$("body").append("<div id='imToolInfo'></div>");
			toolObj = $("#imToolInfo");
			toolObj.append(createFlash("imToolInfoSel",flashUrl,width,height,true));
			IMToolXY(toolObj);
			toolObj.show('slow').mouseout(function(){$(this).hide();})
		}
	}
	
	//=============================================
	// 相对定位弹出信息状态配置条
	//=============================================
	function IMToolXY(moveObj)
	{
		var coors= jQuery.iUtil.getPosition($("#imTool")[0]);
		moveObj.css('position','absolute');
		moveObj.css('top',parseInt(coors.y)+15+'px');
		moveObj.css('left',parseInt(coors.x)-182+'px');
	}
	
	//=============================================
	// 功能：关闭信息状态配置条
	//=============================================
	function closedIMTool()
	{
		$("#imToolInfo").hide('slow');
	}
	//=============================================
	// 功能：使浮动对象横向居中
	//=============================================
	function centerIMTool(obj)
	{
		var bodyX=document.body.scrollWidth;
		var objX=obj[0].clientWidth;
		obj.css("left",((bodyX/2)-(objX/2))+"px");
	}
	// 打开聊天窗口
	function openIMWindow(id,username,flashUrl,width,height)
	{
        var winObj = $("#im"+id);
		if(winObj.is("div")){
			activeIMWindow(winObj);
		}
		else{
			// 创建聊天窗口基本结构
			var flashIMID = "IM_"+id+"_text"
			var imHtml=imHead=imContent=imText=imqkreply="";
			imHtml+="<div id='im"+id+"' class='im chat'>";
			imHtml+="	<div class='chatview'>";
			imHtml+="		<div class='thead'>";
			imHtml+="		</div>";
			imHtml+="		<div class='content'>";
			imHtml+="		</div>";
			imHtml+="		<div class='text'>";
			imHtml+="		</div>";
			imHtml+="	</div>";
			imHtml+="	<div class='qkreply disno' id='qkreply"+id+"'>";
			imHtml+="	</div>";
			imHtml+="	<div style='clear:both'></div>";
			imHtml+="</div>";
			
			imHead+="			<h3>与   "+username+"聊天中</h3>";
			imHead+="			<span class='close'><img src='/images/chat/gbnew.gif' id='im_closed"+id+"' class='im_closed' /></span>";
			imContent = imContent + createFlash("IM_"+id+"_text",flashUrl,width,height,true);			
			imText+="			<form name='imsubmit'>";
			imText+="				<input type='text' name='imtext' autocomplete='off' class='sendmsg' />";
			imText+="				<div style='position:relative;'>";
			imText+="					<a href='#' id='QuickReplyShow"+id+"'><img src='/images/chat/qkreply/listbtn.gif' /></a>";
			imText+="				</div>";
			imText+="				<div class='operation'>(Enter发送信息)<input type='button' value='关 闭' class='sclose'/><input type='button' value='发 送' class='ssend' /></div>";
			imText+="			</form>";
			imqkreply+="		<span class='qkopera'><a href='#' id='set"+id+"' target='_blank'>设置</a><a href='#' id='quickClose"+id+"'>关闭</a></span>";
			imqkreply+="		<div class='qktype' id='qktype"+id+"'>";
			imqkreply+="			<a href='#' operate='remark' class='remark remarkat thisat'></a>";
			imqkreply+="			<a href='#' operate='website' class='website'></a>";
			imqkreply+="			<a href='#' operate='contact' class='contact'></a>";
			imqkreply+="			<a href='#' operate='answer' class='answer'></a>";
			imqkreply+="			<a href='#' operate='question' class='question'></a>";
			imqkreply+="		</div>";
			imqkreply+="		<div class='qklist' id='qklist"+id+"'>";
			imqkreply+="			<div class='qkinfo'>";
			imqkreply+="				<ul>";
			imqkreply+="				</ul>";
			imqkreply+="				<a href='#' id='sendReply"+id+"' class='sendReply' target='_blank'>添加回复内容</a>";
			imqkreply+="			<div>";
			imqkreply+="		</div>";
			// 开始为结构创建具体模块内容
			$("body").append(imHtml);
			winObj = $("#im"+id);
			winObj.find(".thead").html(imHead);
			winObj.find(".content").html(imContent);
			winObj.find(".text").html(imText);
			winObj.find(".qkreply").html(imqkreply);
			// 为结构创建事件
			IMWindowXY(winObj);	// 定义窗口位置
			activeIMWindow(winObj);// 激活当前窗口
			winObj.jqDrag('.thead');
			winObj.not("#im_closed,.sclose").click(function(){activeIMWindow(winObj);});
			winObj.find(".im_closed").click(function(){winObj.remove();});
			winObj.find(".sclose").click(function(){winObj.remove();});
			winObj.find("form[@name='imsubmit']").submit(function(){
				var textObj = winObj.find("input[@name='imtext']")
				var sendVal = htmlEncode(textObj.val());
				eval("window.document."+flashIMID+".SetVariable('testVar','"+sendVal+"')");
				textObj.val("");
				return false;
			});
			winObj.find("input[@name='imtext']").keyup(function(){
				var k = window.event || arguments.callee.caller.arguments[0];
				if (k.ctrlKey && k.keyCode==13){
					var textObj = winObj.find("input[@name='imtext']")
					var sendVal = htmlEncode(textObj.val());
					eval("window.document."+flashIMID+".SetVariable('testVar','"+sendVal+"')");
					textObj.val("");	
				}
			});
			winObj.find(".ssend").click(function(){
				// 执行发送从这里开始
				var textObj = winObj.find("input[@name='imtext']")
				var sendVal = htmlEncode(textObj.val());
				eval("window.document."+flashIMID+".SetVariable('testVar','"+sendVal+"')");
				textObj.val("");				
			});
			$("#QuickReplyShow"+id).click(function(){//开启提示
				LoadReply($("#qklist"+id+" .qkinfo ul"),id,"remark");
				$("#qkreply"+id).removeClass("disno");
				return false;
			});
			$("#quickClose"+id).click(function(){//关闭提示
				$("#qkreply"+id).addClass("disno");
				return false;
			});
			$("#qktype"+id+" a").mouseover(function(){
				switchInfo($(this).attr("operate"),id);
			})
		}
	}
	//=============================================
	// 功能：更新当前聊天窗口标题信息
	//=============================================
	function UpdateTitle(titleUP,idUP)
	{
		if(titleUP!="" && titleUP !=undefined)
		{
			$("#im"+idUP+" .thead h3").html(titleUP);
		}
	}
	function htmlEncode(text)
	{
		if ( typeof( text ) != "string" )
		{
		text = text.toString() ;
		}
		text = text.replace(/&/g, "&amp;") ;
		text = text.replace(/"/g, "&quot;") ;
		text = text.replace(/</g, "&lt;") ;
		text = text.replace(/>/g, "&gt;") ;
		text = text.replace(/'/g, "&#39;") ;
		return text ;
	}
	function closedIMWindow(obj){
		obj.remove();
	}
	
	function closedIMWindowID(id){
		$("#im"+id).remove();	
	}

	// 激活窗口
	function activeIMWindow(obj){
		indexNum++;
		obj.css("z-index",indexNum);
		obj.show("slow");
		$(".im dt").css('opacity',0.7);
		obj.find("dt").css('opacity',1);
	}
	
	function IMWindowXY(obj){
		var pyXY = (Math.random()*100);  
		if(pyAdd){
			pyXY+=pyNum;
			pyAdd=false;
		}else{
			pyXY-=pyNum;
			pyAdd=true;
			
		}
		obj.css("position","absolute");
		obj.css("top",parseInt(pyTop)+pyXY+'px');
		obj.css("left",parseInt(pyLeft)+pyXY+'px');
	}
	
	function openIMList(flashUrl,width,height){
		var winObj = $("#imList");
		// 判定当前窗口是否存在,存在则激活窗口,否则创建窗口
		if(winObj.is("div")){
			winObj.show();
		}
		else{
			$("body").append("<div id='imList'><div class='imhead'><img src='/images/chat/gb.gif' /></div><div class='imcon'></div></div>");
			$("#imList").css('opacity',0.9).jqDrag('.imhead');
			$("#imList .imhead img").click(function(){
				$("#imList").hide();										
			})
			winObj = $("#imList");
			winObj.find(".imcon").html(createFlash("OpenImList",flashUrl,width,height,false));
			IMListXY(winObj);
			winObj.show();
		}
	}
	// 用户列表右侧浮动层事件
	function openIMListDiv(height,dataInfo){
		// 初始化坐标位置
		// var coors= jQuery.iUtil.getPosition($("#imList")[0]);
		// return true;
	}
	// 显示侦听按钮在特殊状态下与网页的处理事件变换
	function showIMListenButton(typeID){
		if (typeID==1){
			$(".IM_UserMessage").hide();
			$(".IM_IMListen").show();
		}
		else{
			$(".IM_IMListen").hide();
			$(".IM_UserMessage").show();
		}
	}
	function IMListXY(obj){
		obj.css("position","absolute");
		obj.css("top",parseInt(pyTop)+"px");
		obj.css("left","4px");
	}
	function LoadReply(Obj,OperateId,DefaultLoad)
	{
		$.ajax({ url: "/manage/module/QuickReplyView.asp",
			type: "post",
			async:false,
			dataType: "html",
			data: "",
			success:function(msg){
				switch($.trim(msg))
				{
					case "0":
						Obj.html("<li class='showno'>登录后再设置快捷回复 <a href='/union_user/union_login.asp' target='_blank'>点击登录</a></li>");
						$("#set"+OperateId).attr("href","/union_user/union_login.asp");
						$("#sendReply"+OperateId).hide();
						break;
					case "-1":
						Obj.html("<li class='showno'>您还没有设置快捷回复 <a href='/manage/person/QuickReply_list.asp' target='_blank'>点击设置</a></li>");
						$("#set"+OperateId).attr("href","/manage/person/QuickReply_list.asp");
						$("#sendReply"+OperateId).hide();
						break;
					case "-2":
						Obj.html("<li class='showno'>您还没有设置快捷回复 <a href='/manage/qiye/QuickReply_list.asp' target='_blank'>点击设置</a></li>");
						$("#set"+OperateId).attr("href","/manage/qiye/QuickReply_list.asp");
						$("#sendReply"+OperateId).hide();
						break;
					case "-3":
						Obj.html("<li class='showno'>您所在的用户群组未提供在线回复功能</li>");
						$("#set"+OperateId).attr("href","/union_user/union_login.asp");
						$("#sendReply"+OperateId).hide();
						break;
					default:
						var Fuwu_code=$.cookies("fuwu","base_fuwu_code");
						var redirect=""
						var operateType=$("#qktype"+OperateId+" .thisat").attr("operate");
						$("#qktype"+OperateId+" ."+operateType).removeClass(operateType+"at").removeClass("thisat");
						$("#qktype"+OperateId+" ."+DefaultLoad).addClass(DefaultLoad+"at").addClass("thisat");
						$("#qklist"+OperateId).css("backgroundImage","url(/images/chat/qkreply/"+DefaultLoad+"info.gif)");
						if(Fuwu_code=="11"){redirect="qiye";}else{redirect="person";}
						$("#set"+OperateId).attr("href","/manage/"+redirect+"/QuickReply_list.asp");
						Obj.html(msg);
						Obj.children().hide();
						Obj.find("li[@operate="+DefaultLoad+"]").show();
						Obj.children().mouseover(function(){
							Obj.find(".at").removeClass("at");
							$(this).addClass("at");
						}).click(function(){
							var sendVal = htmlEncode($(this).html());
							var flashIMID = "IM_"+OperateId+"_text";
							eval("window.document."+flashIMID+".SetVariable('testVar','"+sendVal+"')");
						}).mouseout(function(){$(this).removeClass("at");});
						loginstate(OperateId,DefaultLoad,redirect);
				}
			}
		});
	}
	function switchInfo(type,OperateId){
		var operateType=$("#qktype"+OperateId+" .thisat").attr("operate"); 
		var Fuwu_code=$.cookies("fuwu","base_fuwu_code");
		var redirect="";
		if(Fuwu_code=="11"){redirect="qiye"}else{redirect="person"}
		if(operateType==type||type==""||type==undefined)
		{return true;}
		$("#qktype"+OperateId+" ."+operateType).removeClass(operateType+"at").removeClass("thisat");
		$("#qktype"+OperateId+" ."+type).addClass(type+"at").addClass("thisat");
		$("#qklist"+OperateId).css("backgroundImage","url(/images/chat/qkreply/"+type+"info.gif)");
		if($("#qklist"+OperateId+" ul li.showno").length>0){return true;}
		$("#qklist"+OperateId+" ul li").hide();
		$("#qklist"+OperateId+" ul li[@operate='"+type+"']").show();
		loginstate(OperateId,type,redirect);
	}
	function loginstate(OperateId,type,redirect)
	{
		if($("#qklist"+OperateId+" ul li[@operate='"+type+"']").length==0)
		{
			$("#qklist"+OperateId+" ul").append("<li class='thisshowno'>您还没有设置本组快捷回复 <a href='/manage/"+redirect+"/QuickReply_form.asp?info_TypeId="+switchValue(type)+"' target='_blank'>点击设置</a></li>");
			$("#sendReply"+OperateId).hide();
		}else{
			$("#qklist"+OperateId+" ul li.thisshowno").remove();
			$("#sendReply"+OperateId).show().attr("href","/manage/"+redirect+"/QuickReply_form.asp?info_TypeId="+switchValue(type));
		}
	}
	function switchValue(type)
	{
		switch(type){
			case "remark":
				return "1";
				break;
			case "website":
				return "2";
				break;
			case "contact":
				return "3";
				break;
			case "answer":
				return "4";
				break;
			case "question":
				return "5";
				break;
		}	
	}
	function createFlash(id,flashUrl,width,height,istransparent){
		//var wmode = "transparent";
		var wmode = "opaque";
		if (!istransparent){
			wmode = "opaque";
		}
		var flashInfo = "";
		flashInfo = flashInfo + "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + width + "' height='" + height + "' id='"+id+"'>";
  		flashInfo = flashInfo + "<param name='movie' value='" + flashUrl + "' />";
  		flashInfo = flashInfo + "<param name='quality' value='high' />";
        flashInfo = flashInfo + "<param name='wmode' value='"+wmode+"' />";
		flashInfo = flashInfo + "<param name='allowScriptAccess' value='always' />"
  		flashInfo = flashInfo + "<embed src='" + flashUrl + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "'   name='"+id+"' swLiveConnect='true' allowScriptAccess='always'></embed>";
		flashInfo = flashInfo + "</object>";
		return flashInfo;
	}