<?php /*a:1:{s:75:"F:\wpf\WpfApp1\WpfApp1\bin\x64\Debug\web\im/plugin/im/view/index\index.html";i:1600050751;}*/ ?>
<html><head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>客服接待席后台界面</title>
   <link href="<?php echo htmlentities($css); ?>/iconfont.css" rel="stylesheet">
  <link href="<?php echo htmlentities($css); ?>/im.css" rel="stylesheet">	
  <script type="text/javascript" src="<?php echo htmlentities($js); ?>/web_socket.js"></script>
  <script type="text/javascript" src="<?php echo htmlentities($js); ?>/jquery.min.js"></script>
   <script type="text/javascript" src="<?php echo htmlentities($js); ?>/ajaxFileUpload.js"></script>
	 <script type="text/javascript" src="<?php echo htmlentities($common); ?>/layer/layer.js"></script>
    <script type="text/javascript">
    if (typeof console == "undefined") {    this.console = { log: function (msg) {  } };}
    // 如果浏览器不支持websocket，会使用这个flash自动模拟websocket协议，此过程对开发者透明
    WEB_SOCKET_SWF_LOCATION = "/swf/WebSocketMain.swf";
    // 开启flash的websocket debug
    WEB_SOCKET_DEBUG = true;
    var ws,  client_list={};
	 var url="<?php echo htmlentities($config['im_url']); ?>";
	var list=[];
	var to_client_id;
    var to_client_name;
	var to_uid=0;
	var to_client_img;var pt='<?php echo htmlentities($img); ?>/qq/';
    var logouturl="<?php echo url('index/user/logout'); ?>";
	var loginurl="<?php echo url('index/user/login'); ?>";
    var name="<?php echo htmlentities($user['username']); ?>";
	var uid = "<?php echo htmlentities($user['id']); ?>";var pt='<?php echo htmlentities($img); ?>/qq/';
    var room_id="<?php echo isset($_GET['room_id']) ? $_GET['room_id'] : 1?>";
    var img="<?php echo htmlentities($user['cover']); ?>";	
    var logo="<?php echo htmlentities($user['cover']); ?>";
    var upload_url = "<?php echo plugin_url('im://files/index'); ?>";
    var bind_url="<?php echo plugin_url('im://Worker/bind'); ?>";	
	var history_url="<?php echo plugin_url('im://Worker/history'); ?>";
	var uploadfileurl = "<?php echo plugin_url('im://files/add'); ?>";
	var filename;
	var key;
	 var interval;
	 var content;
	 var im_group_url= "<?php echo plugin_url('im://group/index'); ?>";
	  var im_group_add="<?php echo plugin_url('im://group/add'); ?>";
	 var p=0; 
	 var play="<?php echo htmlentities((isset($config['play']) && ($config['play'] !== '')?$config['play']:'1')); ?>";
	 var im_tab=1;
	 var im_type;
	 var im_search_url = "<?php echo plugin_url('im://index/search'); ?>";
	 var im_search_group_url = "<?php echo plugin_url('im://index/group'); ?>";
  </script>
  <script type="text/javascript">
   


  </script>
</head>
<body onload="connect();">
    <div class="container">
	    <div class="im_row clearfix">
		
	       <div class="col-md-3 column">
	           <div class="thumbnail"><h4 class="head">
			     <img class="logo" src="<?php echo htmlentities($user['cover']); ?>">
				 
				 </h4>
                   <div class="caption" id="userlist">				   
				  <div id="tab" style="display:;">	
				      <span class="active"><a>消息</a></span> 
				       <span class=""><a>好友</a></span> 
				        <span><a>在线</a></span>
				   </div>
				    <div id="tab-content" style="display:block;">
				      
				       <ul class="message"  style="">
					   <?php if(is_array($res) || $res instanceof \think\Collection || $res instanceof \think\Paginator): $i = 0; $__LIST__ = $res;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
					   <li  data-id="<?php echo htmlentities($vo['id']); ?>" data-type="<?php echo htmlentities($vo['type']); ?>" class="message<?php echo htmlentities($vo['from_uid']); ?> online<?php echo htmlentities($vo['isonline']); ?>"
					   onclick="selectMessage(this,'<?php echo htmlentities($vo['from_uid']); ?>','<?php echo htmlentities($vo['type']); ?>','<?php if($vo['type'] == 'group'): ?><?php echo htmlentities($vo['content']); ?><?php endif; ?>')"
					   id="<?php echo htmlentities((isset($vo['from_client_id']) && ($vo['from_client_id'] !== '')?$vo['from_client_id']:'')); ?> "><img src="<?php echo htmlentities((isset($vo['img']) && ($vo['img'] !== '')?$vo['img']:'')); ?>" class="user_icon"> <span class="name"><?php echo htmlentities((isset($vo['from_client_name']) && ($vo['from_client_name'] !== '')?$vo['from_client_name']:'')); ?></span><span class="tips"> 
					   <?php if($vo['type'] == 'plus'): ?>申请好友<?php endif; if($vo['type'] == 'agree'): ?>已同意<?php endif; if($vo['type'] == 'say'): ?><?php endif; if($vo['type'] == 'refuse'): ?><?php endif; if($vo['type'] == 'gif'): ?><?php endif; if($vo['type'] == 'pic'): ?>发来图片<?php endif; if($vo['type'] == 'file'): ?>发来文件<?php endif; if($vo['type'] == 'group'): ?>申请加群<?php endif; if($vo['type'] == 'agreeGroup'): ?>已同意<?php endif; ?>
					   </span></li>
					   <?php endforeach; endif; else: echo "" ;endif; ?>
					   </ul>
				       </div>
					   <div id="tab-content" style="display:none;">
				         <div class="im_childtab">  
						   <span class="active"><a>好友</a></span> 
				           <span class=""><a>群组</a></span> 
				           <span class="fr"><a><img class="arr" src="<?php echo htmlentities($img); ?>/im/plus.png"></a></span>
						<div id="im_menu">

          <div onclick="openSecond()"> <i class="icon icon-font icon-jiahaoyou"></i>加好友</div>
            <div onclick="CreateGroup()"><i class="icon icon-font icon-qun1"></i>创建群聊</div>

</div>
						</div>
						 <div class="im_child">
						 <h3 class="ar">
			             <img class="arr" src="<?php echo htmlentities($img); ?>/ar.png">
						 好友
				         </h3>
				          <ul id="imfriend"  style="">
						  <?php if(is_array($list) || $list instanceof \think\Collection || $list instanceof \think\Paginator): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
					   <li class="im_friend<?php echo htmlentities($vo['to_uid']); ?> online<?php echo htmlentities($vo['isonline']); ?>"
					   onclick="selectUser(this,'<?php echo htmlentities($vo['to_uid']); ?>')"
					   id="<?php echo htmlentities((isset($vo['to_uid']) && ($vo['to_uid'] !== '')?$vo['to_uid']:'')); ?> "><img src="<?php echo htmlentities($vo['img']); ?>" class="user_icon"> <span class="name"><?php echo htmlentities($vo['username']); ?></span><span class="tips"> 
					  
					   </span></li>
					   <?php endforeach; endif; else: echo "" ;endif; ?>
						  
						  </ul>
						  
					      <h3 class="ar">
			              <img class="arr" src="<?php echo htmlentities($img); ?>/ar.png">
						 黑名单
				           </h3>
				            <ul class="black">
								  <?php if(is_array($blacklist) || $blacklist instanceof \think\Collection || $blacklist instanceof \think\Paginator): $i = 0; $__LIST__ = $blacklist;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
					   <li class="message<?php echo htmlentities($vo['to_uid']); ?> online<?php echo htmlentities($vo['isonline']); ?>"
					   onclick="selectUser(this,'<?php echo htmlentities($vo['to_uid']); ?>')"
					   id="<?php echo htmlentities((isset($vo['to_uid']) && ($vo['to_uid'] !== '')?$vo['to_uid']:'')); ?> "><img src="<?php echo htmlentities($vo['img']); ?>" class="user_icon"> <span class="name"><?php echo htmlentities($vo['username']); ?></span><span class="tips"> 
					   
					  
					   </span></li>
					   <?php endforeach; endif; else: echo "" ;endif; ?>
							</ul>
							</div>
							
							 <div class="im_child" style="display:none;">
							    <ul id="imgroup" class="grouplist">
								  <?php if(is_array($group) || $group instanceof \think\Collection || $group instanceof \think\Paginator): $i = 0; $__LIST__ = $group;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
					   <li class="room<?php echo htmlentities($vo['room_id']); ?>"
					  
					   id="imgroup<?php echo htmlentities((isset($vo['id']) && ($vo['id'] !== '')?$vo['id']:'')); ?> "><a target="_blank" href="<?php echo plugin_url("im://group/index?group_id=".$vo['group_id']); ?>"><img src="<?php echo htmlentities($vo['img']); ?>" class="user_icon"> <span class="name"><?php echo htmlentities($vo['title']); ?></span><span class="tips"> 
					  
					   </span></a></li>
					   <?php endforeach; endif; else: echo "" ;endif; ?>
								
								</ul>
							</div>
				       </div> 
                     <div id="tab-content" style="display:none;">
					    
				          <ul class="im_group"></ul>
					     
					   </div>
				   </div>
               </div>
            
	        </div>
	        <div class="col-md-6 column">
	           <div class="thumbnail"><h4 class="user"><span class="status">对话框</span><i onclick="logout()" class="right icon icon-font icon-xnormal"></i>
			     
			  
			   </h4>
	               <div class="caption" id="dialog">
				   <ul id="im_list"></ul>
				  
				   </div>
	           </div>
	           <form >
	                <select style="margin-bottom:8px;display:none;" id="client_list">
                        <option value="all">所有人</option>
                    </select> 
					<div class="im_tool">
				    
				   <img onclick="showemoji()" src="<?php echo htmlentities($img); ?>/face.png">  
				   <img onclick="showGif()" src="<?php echo htmlentities($img); ?>/gif.png">
				   <div class="item" id="cover_id" style=><input type="file" class="im_upload_file" id="uploads"/> 
				   <img src="<?php echo htmlentities($img); ?>/pic.png">
				   </div>
				  <div class="item" id="file_id" style=><form enctype="multipart/form-data">
				  <input type="file" name="file" onchange="inputChange(this)" class="im_upload_file" id="files"/> 
				   <img src="<?php echo htmlentities($img); ?>/file.png"></form>
				   </div>
				   <div id="ems" style=""><p>经典表情</p>
				   <?php for ($x=1; $x<=130; $x++) {
  echo "<img onclick='select(".$x.")' src='".$img."/qq/".$x.".gif'>";
}  ?>
				  </div>  <div id="gif" style=""><p>gif热图</p>
				   <?php for ($x=1; $x<=124; $x++) {
  echo "<img onclick='selectGif(".$x.")' src='".$img."/gif/qq".$x.".gif'>";
}  ?>
				  </div>
				   </div>
                    <textarea class="textarea thumbnail" id="textarea"></textarea>
                    <div class="say-btn">
                       
                        <input type="button" onclick='imSubmit()' class="btn btn-default send" value="发表" />
                    </div>
               
          
	        </div>
	     <audio id="audio" src="<?php echo htmlentities($css); ?>/voice.mp3" style="display:none;"></audio>    
	    </div>
    </div>
<!--自定义右键菜单html代码-->
 <!--DIALOGhtml代码--><div id="im_mask"></div><div id="my_content">
      <div class="im_dialog">
        	<div class="im_header">
            <div class="im_center">
	          <span   onclick="initTab(1)" class="active">找人</span>
			  <span class="line"></span> 
			  <span onclick="initTab(2)"class="">找群</span>
            </div>
			<span class="im_dialog_img"><i class="icon icon-font icon-xnormal"></i>
			<span>
		   </div>
		<div class="im_form">
	         <div class="im_search">
			 <span class="im_input"><input style="background:#fff;" id="im_key" name='name' value=''/></span> 
			 <span class="btn" onclick="initSearch()">搜索</span>
			 </div>
			 <div class="im_search_tip">
			 推荐用户
			 </div>
        </div>
		<div class="im_result">
		     <ul id="im_result_user">
			 <?php if(is_array($resultlist) || $resultlist instanceof \think\Collection || $resultlist instanceof \think\Paginator): $i = 0; $__LIST__ = $resultlist;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
	        <li ><img src="<?php echo htmlentities($vo['img']); ?>" class="user_icon"> <span class="name"><?php echo htmlentities($vo['username']); ?></span><span class="btn"  onclick="addImFriend(this,<?php echo htmlentities($vo['id']); ?>)"> 
					   +加好友					   </span></li>
					   <?php endforeach; endif; else: echo "" ;endif; ?>
		     </ul>
			  <ul id="im_result_group" style="display:none;">
			 <?php if(is_array($grouplist) || $grouplist instanceof \think\Collection || $grouplist instanceof \think\Paginator): $i = 0; $__LIST__ = $grouplist;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
	                  <?php echo $vo['html']; ?>
					   <?php endforeach; endif; else: echo "" ;endif; ?>
		     </ul>
        </div>
    </div></div>
<!--DIALOGhtml代码-->
<!--自定义右键菜单html代码-->
 <!--DIALOGhtml代码-->
  <div id="im_mask"></div>
 <div id="my_content">
      <div class="im_dialogbox">
        	<div class="im_header">
            
	          <img class="im_notice" src="<?php echo htmlentities($img); ?>/im/i3.png">
			 
			  <span class="item">验证消息</span>
           
				<span class="im_dialog_img"><i class="icon icon-font icon-xnormal"></i>
			</span>
		   </div>
		<div class="im_center">
		<ul class="boxlist">
								  					   <li class="room9999" id="1 ">
													   <div class="left">
													   <img src="http://localhost/im/public/uploads/picture/2014-09-02/5405e0f3b1705.png" class="user_icon"> <span class="name">用户名：555</span>
													   <span class="tips"> 
					  id:55
					   </span></div>
					   <span class="im_btn_group"> 
					   <a onclick="agreeIM()" class="agree">同意</a>
					   <a onclick="refuseIM()">拒绝</a> </span>
					   </li>
					   					 
					   								
								</ul>
		</div>
        </div>
	</div>
<!--DIALOGhtml代码-->
 <!--DIALOGhtml代码-->
  <div id="im_mask"></div>
 <div id="mygroup">
      <div class="im_dialog_group">
        	<div class="im_header">
            
			 
			  <span class="item">创建群</span>
           
			<span class="im_dialog_img" onclick="hideGroup()"><i class="icon icon-font icon-xnormal"></i>
			</span>
		   </div>
		<div class="im_center">
		<ul class="boxlist">
				      
					   <li><span>名称</span><input id="imtitle" name="title"/></li>
					    <li><span>简介</span><textarea id="imdes" name="des"></textarea>
					   </li>
					   			 
					   								
								</ul>   	   <span class="im_btn_group"> 
					   <a onclick="submitIm()" class="agree">确定</a>
					   </span>	
		</div>
        </div>
	</div>
<!--DIALOGhtml代码-->
    <script type="text/javascript">
	  $(".im_childtab span.fr").bind("contextmenu", function(){
            return false;
        })
	   $(".im_childtab span.fr").mousedown(function(e) {
            console.log(e.which);
            //右键为3
            if (3 == e.which) {
              
            } else if (1 == e.which) {
               //$("#menu").toggle();
			   $("#im_menu").toggle();
            }
        })
	 function openSecond(){
	  
	  
         $("#im_mask").css({"height":$(document).height(),"width":$(document).width()});      
        $("#im_mask").show();
		
		  var top=($(window).height()-$('.im_dialog').height())/2;
        //高度==浏览器的高-div（$('#hintBox')）的高/2
        var left=($(window).width()-$('.im_dialog').width())/2;
       //宽度同上
       $('.im_dialog').css('top',top).css('left',left);
		$(".im_dialog").show();
        }
 function submitIm(){
	   $.post(im_group_add,{uid,uid,title:$("#imtitle").val(),des:$("#imdes").val()},function(data){
          if(data.code){
		     layer.msg(data.msg);
			 hideGroup()
		  }else{
		    layer.msg(data.msg);
		  }
  });
	  
        }
function CreateGroup(){
	  
	    $("#im_mask").css({"height":$(document).height(),"width":$(document).width()});      
        $("#im_mask").show();
		
		  var top=($(window).height()-$('.im_dialog_group').height())/2;
        //高度==浏览器的高-div（$('#hintBox')）的高/2
        var left=($(window).width()-$('.im_dialog_group').width())/2;
       //宽度同上
       $('.im_dialog_group').css('top',top).css('left',left);
		$(".im_dialog_group").show();
             
      
        }		
		
function hideGroup(){
	  
	  
             
        $("#im_mask").hide();
		
	
		$(".im_dialog_group").hide();
        }
	 function openSecond(){
	  
	  
         $("#im_mask").css({"height":$(document).height(),"width":$(document).width()});      
        $("#im_mask").show();
		
		  var top=($(window).height()-$('.im_dialog').height())/2;
        //高度==浏览器的高-div（$('#hintBox')）的高/2
        var left=($(window).width()-$('.im_dialog').width())/2;
       //宽度同上
       $('.im_dialog').css('top',top).css('left',left);
		$(".im_dialog").show();
        }	
       function openbox(){
	 
	  
         $("#im_mask").css({"height":$(document).height(),"width":$(document).width()});      
        $("#im_mask").show();
		
		  var top=($(window).height()-$('.im_dialogbox').height())/2;
        //高度==浏览器的高-div（$('#hintBox')）的高/2
        var left=($(window).width()-$('.im_dialogbox').width())/2;
       //宽度同上
       $('.im_dialogbox').css('top',top).css('left',left);
		$(".im_dialogbox").show();
        } 
	   $(".im_dialogbox  .im_header .im_dialog_img").click(function(){
	          $("#im_mask").hide();
			  $(".im_dialogbox").hide();
	    });
		 $(".im_dialog .im_dialog_img").click(function(){
	          $("#im_mask").hide();
			  $(".im_dialog").hide();
	    });
        //第一层页面方法
        function firstMethod(){
          
        }
    
	function initTab(n){
	    im_tab=n; 
	    if(n==1){
    		$(".im_dialog .im_search_tip").text("推荐用户");
		    $("#im_result_user").show();
		    $("#im_result_group").hide();
			$(".im_dialog .im_center span").removeClass("active");
			$(".im_dialog .im_center span").eq(0).addClass("active");
		}else{
		    $(".im_dialog .im_search_tip").text("推荐群组");
		    $("#im_result_user").hide();
		    $("#im_result_group").show();
			$(".im_dialog .im_center span").removeClass("active");
			$(".im_dialog .im_center span").eq(2).addClass("active");
			
		}
	
	} 
	function initSearch(){
	    if(im_tab==1){
    		var url=im_search_url;
			
		}else{
		   var url=im_search_group_url;
		  
			
		}
	     $(".im_dialog .im_search_tip").text("搜索结果");
		
	     $.post(
                     url,
                    {key: $("#im_key").val()},
                    function(bind)
                    {     console.log("服务端发来bind消息"+bind);
					   
					      if(im_tab==1){
    		      
			$("#im_result_user").empty();
		}else{
		   
		   $("#im_result_group").empty();
			
		}var data=bind.data;
					   if(data){
					 
					     for(var x=0;x<data.length;x++){
					      var html=data[x].html;
						  $(".im_dialog .im_result ul").append(html);
					      }
					   } 
					  
                    },
                    'json'
                );
	
	
	}
	
 // 连接服务端
    function connect() {
       // 创建websocket
	  //var url='ws://127.0.0.1:7272';
      ws = new WebSocket(url);
	  //ws = new WebSocket(url);
       // 当socket连接打开时，输入用户名
       ws.onopen = onopen;
       // 当有消息时根据消息类型显示不同信息
       ws.onmessage = onmessage; 
       ws.onclose = function() {
    	  console.log("连接关闭，定时重连");
          connect();
       };
       ws.onerror = function() {
     	  console.log("出现错误");
       };
    }	

 var field="files";	
//upload(field);
function inputChange(e){
    $.ajaxFileUpload
    (
        {
            url: uploadfileurl, //用于文件上传的服务器端请求地
            method:"post",
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: field, //文件上传域的ID
            dataType: 'json',
            //返回值类型 一般设置为json
            success: function (up)  //服务器成功响应处理函数
            {
                if(up.status == 200){
                   sendFile(up);
					
                }
            }
        }
    )
}

 function sendFile(up){
     										
   var joinContent = {
        "type": "file",
        "content": up.path,
        "to_client_id":to_client_id,
		 "to_uid":to_uid,
        "to_client_name": to_client_name,
		"img":logo,
		"to_client_img": to_client_img,
		"uid":uid,
		"filename":up.name,
		"filesize": up.size,
		"filetype": up.exts
    };
	 console.log("提交消息"+JSON.stringify(joinContent));
	 $('#files').replaceWith('<input type="file" name="file" onchange="inputChange(this)" class="im_upload_file" id="files">');
	var joinContent=JSON.stringify(joinContent);	
    ws.send(joinContent);
		
    }	 
    // 连接建立时发送登录信息
    function onopen()
    {    
        if(!name)
        {
		   	location.href=loginurl;
            //show_prompt();
        }
        // 登录
       

		var joinContent = {
        "type": "login",
        "room_id": room_id, 
		"uid": uid,
        "client_name": name,
		"img":img
    };
	var login_data=JSON.stringify(joinContent);
        console.log("websocket握手成功，发送登录数据:"+login_data);
        ws.send(login_data);
    }

    // 服务端发来消息时
    function onmessage(e)
    {
        console.log("服务端发来消息"+e.data);
        var data = JSON.parse(e.data);
        switch(data['type']){
		
            // 服务端ping客户端
            case 'ping':
                ws.send('{"type":"pong"}');
                break;;
            // 登录 更新用户列表
            case 'login':
                 $.post(
                     bind_url,
                    {client_id: data.client_id,uid:uid,room_id:room_id,client_name:name},
                    function(bind)
                    {     console.log("服务端发来bind消息"+bind);
					   
                    },
                    'json'
                );
				if(data['data'])
                { 
                    list = data['data'];
					
                }
              
                if(data['client_list'])
                {
                    client_list = data['client_list'];
                }
                else
                {
                    client_list[data['client_id']] = data['client_name']; 
                }
                flush_client_list();
             
                break;
            // 发言
            case 'say':
                sayText(data);
                break;
			 // 发言
            case 'pic':
                sayPic(data);  
				break;
			 case 'file':
                sayFile(data);	
                break;	
            // 用户退出 更新用户列表
			 case 'agree':
                sayAgree(data);
                break;
			  case 'refuse':
                sayRefuse(data);
                break;
				 case 'agreeGroup':
                sayAgreeGroup(data);
                break;
			  case 'refuseGroup':
                sayRefuseGroup(data);
                break;
            case 'logout':
                delete client_list[data['from_client_id']];
                flush_client_list();
        }
    }
function playMusic() {
  if(play){
    var audioEle = document.getElementById("audio");
  audioEle.load();
    if (audioEle.paused){ /*如果已经暂停*/
        audioEle.play();   //播放
    }else {
        audioEle.pause();  //暂停
    }
   }
}
    
   function parseS(a){

    return a.replace(/\[(\d+)\]/g, function(m,i) {
          var n=m.replace('[','');
           n= n.replace(']','')
            return '<img src="'+pt+n+'.gif">';
;  
        return n;
        
    });
 }
	
    // 提交对话
     // 提交对话
    function imSubmit() {
	$("#ems").hide();$("#gif").hide();
      var input =$("#textarea").val();
    
	  var joinContent = {
        "type": "say",
        "content": parseS(input),
        "to_client_id":to_client_id,
        "to_client_name": to_client_name,
		"img":img,
		"to_client_img": to_client_img,
		"uid":uid,
		"to_uid":to_uid
    };
	
	var joinContent=JSON.stringify(joinContent);
	 
	    ws.send(joinContent);
	 
    
     $("#textarea").val('');
      $("#textarea").focus();
    }
   
	
   function selectMessage(obj,fid,n,group_id){ 
  
	 if(!$(obj).hasClass("active")){
	   $(obj).parents("ul").find("li").removeClass("active");
	   $(obj).addClass("active");
	 }  
	 $(obj).find(".tips").text("");
         if(group_id){
		    content=group_id;
		 }	 
	    
	     to_client_name=$(obj).find('.name').text();
	     to_client_id=$(obj).attr("id");
		 console.log("提交消息im_type"+im_type);
		 to_uid=fid;
	     to_client_img=$(obj).find(".user_icon").attr("src");
		
		 if(interval){
		   clearInterval(interval );
		 }
		var type=$(obj).attr("data-type") ;
	 if(type=="plus"&&typeof im_type == "undefined"){
	     $(".im_dialogbox li .name").attr("id",to_client_id);
		 
		$(".im_dialogbox li .name").text(to_client_name);
		$(".im_dialogbox li .tips").text(to_uid);
		$(".im_dialogbox li img").attr("src",to_client_img);
		$(".im_dialogbox .im_btn_group a").eq(0).attr("onclick","agreeIM()");
		$(".im_dialogbox .im_btn_group a").eq(1).attr("onclick","refuseIM()");
	    openbox();return false;
	  }
	  	 
	else if(type=="group"&&typeof im_type == "undefined"){
	     $(".im_dialogbox li .name").attr("id",to_client_id);
		 $(".im_dialogbox .im_header .item").eq(1).text("申请加群");
		$(".im_dialogbox .im_btn_group a").eq(0).attr("onclick","agreeIMGroup()");
		$(".im_dialogbox .im_btn_group a").eq(1).attr("onclick","refuseIMGroup()");
		$(".im_dialogbox li .name").text(to_client_name);
		$(".im_dialogbox li .tips").text(to_uid);
		$(".im_dialogbox li img").attr("src",to_client_img);
	    openbox();
	  }
	  else{
	   
	     $(".status").html("与"+$(obj).find('.name').text()+'对话中');
	     initalk(uid,fid);
	   }
    }
	
function agreeIMGroup(){

    //var content="已同意"; 													
    var joinContent = {
        "type": "agreeGroup",
        "content": content,
        "to_uid":to_uid,
		"to_client_id":to_client_id,
        "to_client_name": to_client_name,
		"img":logo,
		"to_client_img": to_client_img,
		"uid":uid
    };
	 console.log("提交消息"+JSON.stringify(joinContent));
	var joinContent=JSON.stringify(joinContent);	
      ws.send(joinContent);
		
    }
function refuseIMGroup(){

    //var content="已拒绝"; 													
 var joinContent = {
        "type": "refuseGroup",
        "content": content,
        "to_uid":to_uid,
		"to_client_id":to_client_id,
        "to_client_name": $(".im_dialogbox li .name").text(),
		"img":logo,
		"to_client_img": to_client_img,
		"uid":uid
    };
	 console.log("提交消息"+JSON.stringify(joinContent));
	var joinContent=JSON.stringify(joinContent);	
      ws.send(joinContent);
		
    }		
	
function agreeIM(){

    var content="已同意"; 													
    var joinContent = {
        "type": "agree",
        "content": content,
        "to_uid":to_uid,
		"to_client_id":$(".im_dialogbox li .name").attr("id"),
        "to_client_name": $(".im_dialogbox li .name").text(),
		"img":logo,
		"to_client_img": to_client_img,
		"uid":uid
    };
	 console.log("提交消息"+JSON.stringify(joinContent));
	var joinContent=JSON.stringify(joinContent);	
      ws.send(joinContent);
		
    }
function refuseIM(){

    var content="已拒绝"; 													
 var joinContent = {
        "type": "refuse",
        "content": content,
        "to_uid":to_uid,
		"to_client_id":$(".im_dialogbox li .name").attr("id"),
        "to_client_name": $(".im_dialogbox li .name").text(),
		"img":logo,
		"to_client_img": to_client_img,
		"uid":uid
    };
	 console.log("提交消息"+JSON.stringify(joinContent));
	var joinContent=JSON.stringify(joinContent);	
      ws.send(joinContent);
		
    }	
function addImFriend(obj,to_uid){

    var content="好友申请"; 													
    var joinContent = {
        "type": "plus",
        "content": content,
        "to_uid":to_uid,
		"to_client_id":'',
        "to_client_name": $(obj).parents("li").find('.name').text(),
		"img":logo,
		"to_client_img": $(obj).parents("li").find(".user_icon").attr("src"),
		"uid":uid
    };
	 console.log("提交消息"+JSON.stringify(joinContent));
	var joinContent=JSON.stringify(joinContent);	
      ws.send(joinContent);
		
    }	
function addImGroup(obj,to_uid,id){

    var content="好友申请"; 													
    var joinContent = {
        "type": "group",
        "content": id,
        "to_uid":to_uid,
		"to_client_id":'',
        "to_client_name": $(obj).attr('data-name'),
		"img":logo,
		"to_client_img":  $(obj).attr('data-img'),
		"uid":uid
    };
	 console.log("提交消息"+JSON.stringify(joinContent));
	var joinContent=JSON.stringify(joinContent);	
      ws.send(joinContent);
		
    }
	
function selectUser(obj,fid){ 
	 if(!$(obj).hasClass("active")){
	   $(obj).parents("ul").find("li").removeClass("active");
	   $(obj).addClass("active");
	 }
	 to_uid=fid;
	 to_client_name=$(obj).find('.name').text();
	 to_client_id=$(obj).attr("id");
	 to_client_img=$(obj).find(".user_icon").attr("src");
	 //console.log("select成功");
    
    	$(".status").html("与"+$(obj).find('.name').text()+'对话中');
	   initalk(uid,fid);
    }
	function initalk(uid,fid){
	$("#im_list").empty();
	    $.post(
                    history_url,
                    {uid: uid,fid:fid},
                    function(data)
                    {   
                  // console.log(data+"data成功");
					//inituser(list);
					for(var x=0;x<data.length;x++){
					var from_client_name=data[x]['from_client_name'];
					var userimg=data[x]['img'];
					var to_client_img=data[x]['to_client_img'];
					var to_client_name=data[x]['to_client_name'];
					var content=data[x]['content'];
					content=content.replace(/&quot/g, '"');
					var type=data[x]['type'];
					var id=data[x]['id'];
					var from_uid=data[x]['from_uid'];
					if(type=='say'){
					  var content=content;  var append=1;
					}
					if(type=='pic'){
					  var content='<img class="pic" src="'+content+'">'; 
					  var append=1;
					}
					if(type=='agree'){
					  var append=0;
					}
					if(type=='agreeGroup'){
					  var append=0;
					}
					if(type=='refuseGroup'){
					  var append=0;
					}
					if(type=='file'){
					 var content='<p class="filename">'+data[x].filename+"("+data[x].filesize+')</p><p class="path"><a href="'+content+'" target="_blank">下载</a></p>';
					  var append=1;
					}
					if(type=='refuse'){
					  var append=0;
					}
                 if(from_uid!=uid){
		           var html='<li id='+id+' class="textRight '+from_uid+'"><img src="'+userimg+'" class="icon" /><span class="'+type+'">'+content+'</span> </li>';
				   if(append){				  
				     $("#im_list").append(html);
				   }
				   var div = document.getElementById('im_list');		
	               div.scrollTop = div.scrollHeight;
		        }else
		       {
	             var html='<li id='+id+' class="textLeft '+from_uid+'"><img src="'+logo+'" class="icon" /><span class="'+type+'">'+content+'</span> </li>';
			       if(append){				  
				     $("#im_list").append(html);
				   }
				  var div = document.getElementById('im_list');		
	div.scrollTop = div.scrollHeight;
		     }
        
           
		
		}
                    },
                    'json'
                );
		
	}
	
	var image=img;
    // 刷新用户列表框
	 
    function flush_client_list(){
	 //console.log(list.length+"flush成功");
	   //var userlist_window = $(".message");
	    var group = $(".im_group");
		//userlist_window.empty();
		group.empty();
		//console.log(list.length+'client_name'+"flush成功");
		for(var x=0;x<list.length;x++){
		  var username=list[x]['client_name']; 
		  var image=list[x]['img'];
		  var uid=list[x]['uid'];var client=list[x]['client_id'];
		  if ( $(".message"+uid).length > 0 ) {
             $(".message"+uid).attr("id",client);
			 
          }
		   if ( $(".im_friend"+uid).length > 0 ) {
             $(".im_friend"+uid).attr("id",client);
			 $(".im_friend"+uid).find("tips").text('已上线');
          }
		  
            if(name!=username){
               //userlist_window.append('<li onclick="selectUser(this,'+uid+')" id="'+client+'"><img src="'+image+'" class="user_icon" /> <span class="name">'+username+' </span><span class="tips"> </span></li>');
			    group.append('<li onclick="selectUser(this,\''+uid+'\')" id="'+client+'"><img src="'+image+'" class="user_icon" /> <span class="name">'+username+' </span><span class="tips"> </span></li>');
			}
           
        }
		
		if(list.length>0){
		
		  //to_client_name=$(".message li").eq(0).find('.name').text();
	      //to_client_id=$(".message li").eq(0).attr("id");
	      //to_client_img=$(".message li").eq(0).find(".user_icon").attr("src");
		  //console.log(" to_client_id"+ to_client_id);
		}
      
    }
  
  
	 function sayAgree(data){
        //解析新浪微博图片,
        var from_client_id=data['from_client_id'];
	  var from_client_name=data['from_client_name']; 
	 var content=data['content'];
	 var time= data['time'];
	var image=  data['img'];
	 var to_client_img= data['to_client_img'];
	 var to_client_id= data['to_client_id'];
      var to_uid= data['to_uid'];
	  var from_uid= data['from_uid'];
	  if(from_uid==uid){
	  
	     if ( $(".message"+to_uid).length==0 ) {
		      var html='<li onclick="selectMessage(this,"'+to_uid+'","agree")" id="'+to_client_id+'"><img src="'+to_client_img+'" class="user_icon" /> <span class="name">'+to_client_name+' </span><span class="tips"> </span>已同意</li>';
              $(".message").append(html);
			 
          }else{
		    $(".message"+to_uid).find("span.tips").text("已同意");
		  }
		 var html=' <li class="im_friend'+data['to_uid']+' online0" onclick="selectUser(this,'+data['to_uid'].replace(/^\s+|\s+$/g,"")+')" id="'+data['to_uid'].replace(/^\s+|\s+$/g,"")+' "><img src="'+data['to_client_img']+'" class="user_icon"> <span class="name">'+data['to_client_name']+'</span><span class="tips">  </span></li>';
		 
		  if ( $(".im_friend"+to_uid).length==0 ) {
		      $("ul#imfriend").append(html);
		  }
		  
		  $("#im_mask").hide();
		 $(".im_dialogbox").hide();
	  
	  }
	  
	if(to_uid==uid){
	  
	     if ( $(".message"+from_uid).length==0 ) {
		      var html='<li onclick="selectMessage(this,"'+from_uid+'","agree")" id="'+from_client_id+'"><img src="'+image+'" class="user_icon" /> <span class="name">'+from_client_name+' </span><span class="tips"> </span>已同意</li>';
              $(".message").append(html);
			 
          }else{
		    $(".message"+from_uid).find("span.tips").text("已同意");
		  }
		 var html=' <li class="im_friend'+data['from_uid']+' online0" onclick="selectUser(this,'+data['from_uid'].replace(/^\s+|\s+$/g,"")+')" id="'+data['from_uid'].replace(/^\s+|\s+$/g,"")+' "><img src="'+data['img']+'" class="user_icon"> <span class="name">'+data['from_client_name']+'</span><span class="tips">  </span></li>';
		 
		  if ( $(".im_friend"+from_uid).length==0 ) {
		      $("ul#imfriend").append(html);
		  }
		  
		  $("#im_mask").hide();
		  $(".im_dialogbox").hide();
	  
	  }	
		
    	
    }
	 function sayAgreeGroup(data){
        //解析新浪微博图片,
        var from_client_id=data['from_client_id'];
	  var from_client_name=data['from_client_name']; 
	 var content=data['content'];
	 var time= data['time'];
	var image=  data['img'];
	 var to_client_img= data['to_client_img'];
	 var to_client_id= data['to_client_id'];
      var to_uid= data['to_uid'];
	  var from_uid= data['from_uid'];
	   if(from_uid==uid){
		   if ( $(".message"+to_uid).length==0 ) {
		      var html='<li onclick="selectMessage(this,"'+to_uid+'","agreeGroup")" id="'+to_client_id+'"><img src="'+data['to_client_img']+'" class="user_icon" /> <span class="name">'+to_client_name+' </span><span class="tips"> </span>已同意</li>';
              $(".message").append(html);
			 
          }else{
		    $(".message"+to_uid).find("span.tips").text("已同意");
		  }
		  
		   var html='<li id="imgroup"'+content+'><a target="_blank" href="'+im_group_url+'?group_id='+content+'"><img src="'+data['to_client_img']+'" class="user_icon"> <span class="name">'+to_client_name+'</span><span class="tips">  </span></a></li>';
		 
		  if ( $("#imgroup"+content).length==0 ) {
		      $("ul#imgroup").append(html);
		  }
		  
		  $("#im_mask").hide();
		  $(".im_dialogbox").hide();
		  im_type="AgreeGroup";
    	}
		if(to_uid==uid){
		   if ( $(".message"+from_uid).length==0 ) {
		      var html='<li onclick="selectMessage(this,"'+from_uid+'","agreeGroup")" id="'+from_client_id+'"><img src="'+data['img']+'" class="user_icon" /> <span class="name">'+from_client_name+' </span><span class="tips"> </span>已同意</li>';
              $(".message").append(html);
			 
          }else{
		    $(".message"+from_uid).find("span.tips").text("已同意");
		  }
		  var html='<li id="imgroup"'+content+'><a target="_blank" href="'+im_group_url+'?group_id='+content+'"><img src="'+data['from_client_img']+'" class="user_icon"> <span class="name">'+from_client_name+'</span><span class="tips">  </span></a></li>';
		 
		  if ( $("#imgroup"+content).length==0 ) {
		      $("ul#imgroup").append(html);
		  }
		  
		  $("#im_mask").hide();
		  $(".im_dialogbox").hide();
		  im_type="AgreeGroup";
    	}
    }
	 function sayRefuse(data){
        //解析新浪微博图片,
        var from_client_id=data['from_client_id'];
	  var from_client_name=data['from_client_name']; 
	 var content=data['content'];
	 var time= data['time'];
	var image=  data['img'];
	 var to_client_img= data['to_client_img'];
	 var to_client_id= data['to_client_id'];
      var to_uid= data['to_uid'];
	  var from_uid= data['from_uid'];
	   if(from_uid==uid){
		   if ( $(".message"+to_uid).length==0 ) {
		      var html='<li onclick="selectMessage(this,'+to_uid+',"refuse")" id="'+to_client_id+'"><img src="'+data['to_client_img']+'" class="user_icon" /> <span class="name">'+to_client_name+' </span><span class="tips"> </span>已拒绝</li>';
              $(".message").append(html);
			 
          }else{
		    $(".message"+to_uid).find("span.tips").text("已拒绝");
			$(".message"+to_uid).remove();
		  }
		  $("#im_mask").hide();
		  $(".im_dialogbox").hide();
		}
    	
    }
	 function sayRefuseGroup(data){
        //解析新浪微博图片,
        var from_client_id=data['from_client_id'];
	  var from_client_name=data['from_client_name']; 
	 var content=data['content'];
	 var time= data['time'];
	var image=  data['img'];
	 var to_client_img= data['to_client_img'];
	 var to_client_id= data['to_client_id'];
      var to_uid= data['to_uid'];
	  var from_uid= data['from_uid'];
	   if(from_uid==uid){
		   if ( $(".message"+to_uid).length==0 ) {
		      var html='<li onclick="selectMessage(this,'+from_uid+',"pic")" id="'+from_client_id+'"><img src="'+image+'" class="user_icon" /> <span class="name">'+from_client_name+' </span><span class="tips"> </span>已拒绝</li>';
              $(".message").append(html);
			 
          }else{
		    $(".message"+to_uid).find("span.tips").text("已拒绝");
		  }
		 
		}
    	 $("#im_mask").hide();
		  $(".im_dialogbox").hide();
    }
	  // 发言
   function sayText(data){
        //解析新浪微博图片,
        var from_client_id=data['from_client_id'];
	  var from_client_name=data['from_client_name']; 
	 var content=data['content'];
	content=content.replace(/&quot/g, '"');
	 var time= data['time'];
	var image=  data['img'];
	 var to_client_img= data['to_client_img'];
	 var to_client_id= data['to_client_id'];
      var to_client_uid= data['to_uid'];
	  var from_uid= data['from_uid'];
       var to_client_uid= data['to_uid'];  
		//发送
	
		if(from_uid==uid){
		  
		   var html='<li class="textLeft"><img src="'+image+'" class="icon" /><span>'+content+'</span> </li>';
		   $("#im_list").append(html);
		}//接收
		if(to_client_uid==uid){ 
		  
		    if(to_client_uid==uid){
   		     var html='<li class="textRight"><img src="'+image+'" class="icon" /><span>'+content+'</span> </li>';
		      $("#im_list").append(html);
		   }
		   if ( $(".message"+from_uid).length==0 ) {
		      var html='<li data-type="pic" onclick="selectMessage(this,'+from_uid+')" id="'+from_client_id+'"><img src="'+image+'" class="user_icon" /> <span class="name">'+from_client_name+' </span><span class="tips"> </span>有新消息</li>';
              $(".message").append(html);
			 
          }else{
		     $(".message #"+from_client_id).find("span.tips").text("有新消息");
		  }
		  
		 document.title = "【您有一条新消息】"+from_client_name+"发来消息";


        //定时
        setInterval(function(){
            //取 title 中最后一个 字符
            var first_char = document.title[0];
            //取除了第一个剩下的
            var last_string = document.title.substr(1);
            //给title重新赋值
            document.title = last_string + first_char;

        }, 100);
		  playMusic();
		}
    	var div =document.getElementById('im_list');		
	    div.scrollTop = div.scrollHeight;
    }
   // 发言
    function sayPic(data){
        //解析新浪微博图片
      var from_client_id=data['from_client_id'];
	  var from_client_name=data['from_client_name']; 
	 var content=data['content'];
	 var time= data['time'];
	var image=  data['img'];
	 var to_client_img= data['to_client_img'];
	 var to_client_id= data['to_client_id'];
      var to_client_uid= data['to_uid'];
	  var from_uid= data['from_uid']	
		//发送
		if(name==from_client_name){
		   console.log("用户发送");
		  var html='<li class="textLeft"><img src="'+image+'" class="icon" /><span><img class="pic" src="'+content+'"></span> </li>';
		   $("#im_list").append(html);
		}//接收
		if(to_client_uid==uid){ 
		   console.log("用户接收");
		    if(to_uid==from_uid){
   		      var html='<li class="textRight"><img src="'+image+'" class="icon" /><span><img class="pic" src="'+content+'"></span> </li>';
		      $("#im_list").append(html);
		   }
		   if ( $(".message"+from_uid).length==0 ) {
		      var html='<li data-type="pic" onclick="selectMessage(this,'+from_uid+')" id="'+from_client_id+'"><img src="'+image+'" class="user_icon" /> <span class="name">'+from_client_name+' </span><span class="tips"> </span>有新消息</li>';
              $(".message").append(html);
			 
          }else{
		     $(".message #"+from_client_id).find("span.tips").text("有新消息");
		  }
		 document.title = "【您有一条新消息】"+from_client_name+"发来消息";


        //定时
        interval =setInterval(function(){
            //取 title 中最后一个 字符
            var first_char = document.title[0];
            //取除了第一个剩下的
            var last_string = document.title.substr(1);
            //给title重新赋值
            document.title = last_string + first_char;

        }, 100);
		   playMusic();
		}
    	var div =document.getElementById('im_list');		
	    div.scrollTop = div.scrollHeight;
    	
    }
	
	 // 发言
    function sayFile(data){
        //解析新浪微博图片
       var from_client_id=data['from_client_id'];
	  var from_client_name=data['from_client_name']; 
	 var content=data['content'];
	 var time= data['time'];
	var image=  data['img'];
	 var to_client_img= data['to_client_img'];
	 var to_client_id= data['to_client_id'];
      var to_client_uid= data['to_uid'];
	  var from_uid= data['from_uid']	
	  
	
    
        //$("#im_list").append(html);
			//发送
		if(name==from_client_name){
		var html='<li class="textLeft"><img src="'+image+'" class="icon" /><span><p class="filename">'+data.filename+"("+data.filesize+')</p><p class="path"><a href="'+content+'" target="_blank">下载</a></p></span> </li>';
		     $("#im_list").append(html);
	     }
		if(to_client_uid==uid){ 
            if(to_uid==from_uid){
               var html='<li class="textRight"><img src="'+image+'" class="icon" /><span><p class="filename">'+data.filename+"("+data.filesize+')</p><p class="path"><a href="'+content+'" target="_blank">下载</a></p></span> </li>';
               $("#im_list").append(html);
		   }	
		   if ( $(".message"+from_uid).length==0 ) {
		      var html='<li onclick="selectMessage(this,'+from_uid+'",pic")" id="'+from_client_id+'"><img src="'+image+'" class="user_icon" /> <span class="name">'+from_client_name+' </span><span class="tips"> </span>有新消息</li>';
              $(".message").append(html);
			 
          }else{
		   $(".message #"+from_client_id).find("span.tips").text("有新消息");
		  }
		 document.title = "【您有一条新消息】"+from_client_name+"发来消息";


        //定时
        interval =setInterval(function(){
            //取 title 中最后一个 字符
            var first_char = document.title[0];
            //取除了第一个剩下的
            var last_string = document.title.substr(1);
            //给title重新赋值
            document.title = last_string + first_char;

        }, 100);
		   playMusic();
		}
    	var div =document.getElementById('im_list');		
	    div.scrollTop = div.scrollHeight;
    	
    }
    $(function(){
    	select_client_id = 'all';
	    $("#client_list").change(function(){
	         select_client_id = $("#client_list option:selected").attr("value");
	    });
       
    });


											

												document.getElementById('cover_id').onchange = function(event){  
													var img = event.target.files[0];   
													if(!img){  
														return false;  
													}  
													if(!(img.type.indexOf('image')==0 && img.type && /\.(?:jpg|png|gif)$/.test(img.name)) ){  
														alert('图片只能是jpg,gif,png');  
														return ;  
													}  
													var reader = new FileReader();  
													reader.readAsDataURL(img);  
											  
													reader.onload = function(e){ 
													var  content="";
											$.post(upload_url, { img: e.target.result},function(ret){  
															if(ret){ 
                                                           console.log(ret.src);
															  content=ret.src;
															  send(content);
															}else{  
																alert('upload fail');  
															}  
														},'json'); 		
													
     
                                                          }
                    return false;
													} 
												 
function send(content){
        console.log("提交消息to_client_id"+to_client_id);													
 var joinContent = {
        "type": "pic",
        "content": content,
        "to_client_id":to_client_id,
        "to_client_name": to_client_name,
		"img":logo,
		"to_client_img": to_client_img,
		"to_uid": to_uid,
		"uid":uid
    };
	$('#uploads').replaceWith('<input type="file" class="im_upload_file" id="uploads"  />');
	 console.log("提交消息"+JSON.stringify(joinContent));
	var joinContent=JSON.stringify(joinContent);	
      ws.send(joinContent);
		
    }											  
                                
//这里阻止默认行为没有用　我也不知道怎么回事　知道的童鞋　麻烦告知

window.onclick=function(e){
　　　　$('#menu').hide();
}	
$('#textarea').click(function(){
　　　　$('#ems').hide();
 　$('#gif').hide();
})	
		

  function showemoji(){
     $("#ems").toggle();
	 $("#gif").hide();
    }
	function logout(){
    
	 window.location.href=logouturl;
    }
 function showGif(){
    $("#ems").hide();
	$("#gif").toggle();
		
    }	
  function select(n){ 
      $("#ems").hide();	
     $("#textarea").val($("#textarea").val()+"["+n+"]");
	 
	
    }
	function selectGif(n){
	   var content="<?php echo htmlentities($img); ?>/gif/qq"+n+".gif";
	   console.log(content);
       send(content);
	   $("#gif").hide();		
    }
	$("#tab span").click(function(){
					if(!$(this).hasClass("active")){
						var index = $("#tab span").index($(this));console.log(index);
						$("div#tab-content").eq(index).show().siblings('div#tab-content').hide();
						$(this).addClass("active").siblings("#tab span").removeClass("active");
					}
					
			});
     $(".im_childtab span").click(function(){
	 	           var index = $(".im_childtab span").index($(this));
				   if(index>1){
				   return false;
				   }
					if(!$(this).hasClass("active")){
						var index = $(".im_childtab span").index($(this));
						console.log(index);
						$("div.im_child").eq(index).show().siblings('div.im_child').hide();
						$(this).addClass("active").siblings(".im_childtab span").removeClass("active");
					}
					
			});


	</script>
    <script type="text/javascript">
      // 动态自适应屏幕
      document.write('<meta name="viewport" content="width=device-width,initial-scale=1">');
      $("textarea").on("keydown", function(e) {
          // 按enter键自动提交
          if(e.keyCode === 13 && !e.ctrlKey) {
              e.preventDefault();
              $('form').submit();
              return false;
          }

          // 按ctrl+enter组合键换行
          if(e.keyCode === 13 && e.ctrlKey) {
              $(this).val(function(i,val){
                  return val + "\n";
              });
          }
      });
    </script>
</body>
</html>
