
var js;//

var page=1;
var number=10;
var time;//定时器
var historyTotal=1;//获取历史记录的点击次数，默认为1


//显示
/*$("#custom-service").click(function(){
	time = setInterval('getChatRecord()', 3000);
	$("#sub-emotion").addClass("sub-emotion");		  	
	getChatRecord();
});



//显示左侧对话内容
function showLeftChat(head_icon,name,con,time){
	con=replace_em(con);
	var html="";
	html += "<div  class='content-left'><div class='head-time'><div class='head-img ml'>"+
	"<img src='"+head_icon+"' /></div><div class='service-custom'>"+name+"&nbsp;<span>"+FormatDate9(time)+"</span>"+
	"</div></div><div class='coment-left'><span>"+con+"</span></div></div>";
	$("#con").append(html);
}
//显示右侧对话内容
function showRightChat(head_icon,name,con,time){
	con=replace_em(con);
	var html="";
     html += "<div class='content-right'><div class='head-time img-right'>"+
	"<div class='service-custom'><span>"+FormatDate9(time)+"</span>&nbsp;"+name+"</div><div class='head-img'>"+
	"<img src="+head_icon+" /></div></div><div class='coment-right'><span>"+con+"</span></div></div>";
     $("#con").append(html);
}*/





//用户 获取聊天记录
/*function getChatRecord() {
	number = parseInt(number)*parseInt(historyTotal);
	var fd="page="+page+"&number="+number;
	
	$.ajax({
		url : "../../web/center/FindUserChat",
		type : "GET",
		processData : false,
		contentType : false,
		data:fd,
		success : function(d) {
					
			console.log(d);
			if(d.code==1001){
				check_code(d.code);
			}else if(d.code==1){
				$("#con").html("");
				js=d.data.reverse();
				console.log(d.data);
				for(var i=0;i<js.length;i++){
					if(js[i].state==0){
						showLeftChat(js[i].image,js[i].name,js[i].sender_text,js[i].sender_time);
					}else if(js[i].state==1){
						showRightChat(js[i].image,js[i].name,js[i].sender_text,js[i].sender_time);
					}
				}
				
				if(number<=js.length){
					$(".service-title").text("点击更多");
				}
				
			}else if(d.code==-1){
				$(".service-title").text("服务器繁忙, 请稍后再试");
			}
		}
	});
}
*/


//添加聊天记录
/*function send_text(con){

	var str="send_text="+con;
	$.ajax({
		url : "../../web/center/InsertChat",
		type : "GET",
		processData : false,
		contentType : false,
		data:str,
		success : function(d) {
			$("#saytext").val("");
			console.log(d);
			if(d.code==1001){
				check_code(d.code);
				//window.location.href="../html/account.jsp";
			}else if(d.code==1){
				getChatRecord();
			}
		}
	});
}
*/

//查看结果
function replace_em(str){
	str = str.replace(/\</g,'&lt;');
	str = str.replace(/\>/g,'&gt;');
	str = str.replace(/\[em_([0-9]*)\]/g,'<img src="../arclist/$1.gif" border="0" />');	
	return str;	
}



//用户点击发送按钮
function sendMail(){
	var msg = $("#saytext").val();
	msg = $.trim(msg);
	if(msg.length == 0){
		$("#saytext").val(null);
		return;
	}else{
		//$('#show').scrollTop( $('#show')[0].scrollHeight );
		var str = $("#saytext").val();
		$("#con").html(str);
		//send_text(str);
	}
}

document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];           
     if(e && e.keyCode==13){ // enter 键
    	 sendMail();//发送信息
    	 e.returnValue = false;    
    	 return false;  
    }
}; 


//点击查看更多
/*function getHistory(){
	if(number<=js.length){
		historyTotal = historyTotal + 1;
		getChatRecord();
	}else {
		$(".service-title").text("欢迎您的咨询，期待为您服务!");
	}
}*/


$(function(){
	//getChatRecord();
	$('.emotion').qqFace({		
		id : 'facebox', 
		assign:'saytext', 
		path:'../arclist/'	//表情存放的路径
	});
	/*sendMail();*/
/*	$(".sub_btn").click(function(){
		var str = $("#saytext").val();
		$("#show").append(replace_em(str));
	});*/

	var width=document.documentElement.clientWidth;
	console.log(width);
	var marLeft=(width-340)/2;
	console.log(marLeft);
	$(".dialog").css("left",marLeft+"px");
	
	//计算对话框居中
    window.onresize=function(){  
    	var width=document.documentElement.clientWidth;
    	console.log(width);
    	var marLeft=(width-340)/2;
    	console.log(marLeft);
    	$(".dialog").css("left",marLeft+"px");
    }
});





