$(function()
{
msg=document.getElementById("msg");
Words=document.getElementById("words");
miaoshua();
setInterval("miaoshua()",500);
sxx();
setInterval("sxx()",2000);
yonghu();
setInterval("yonghu()",5000);
sccookie("gd");
xrcookie("cl","true");
});

function get(url)
{
var xmlHttp=new XMLHttpRequest();
xmlHttp.open("get",url,false);
xmlHttp.send();
return xmlHttp.responseText;
}

function miaoshua()
{
var sl=msg.value.length;
if(sl=="0")
{
document.getElementById("qingkong").style.display="none";
}
else
{
document.getElementById("qingkong").style.display="";
}
}

function sxx()
{
$.ajax({
url:"./liebiao.php",
type:"post",
dataType:"json",
success:function(data)
{
var code=data.code;
var id=data.id;
var msg=data.msg;
if(data.zxxx!=null)
{
var jxxx=JSON.parse(data.zxxx);
var jxnr=JSON.parse(jxxx.neirong);
}
if(code=="0")
{
$("#xiaoxi").html(msg);
if(jxnr.type=="秀图")
{
xiutu(jxnr.id,jxnr.img,"false");
}
if(dqcookie("cl")=="true")
{
sccookie("cl");
Words.scrollTop=Words.scrollHeight;
setTimeout(function()
{
Words.scrollTop=Words.scrollHeight;
},2000);
}
else
{
bottom();
}
}
else if(code=="1")
{
$("#xiaoxi").html(msg);
if(id!="")
{
$("#xxsl").html(id);
document.getElementById("write1").style.display="";
}
}
else if(code=="2")
{
$("#xiaoxi").html(msg);
window.location.hash=id;
}
else if(code=="3")
{
$("#xiaoxi").html(msg);
}
}
});
}

function bottom()
{
var speak_height=$("#xiaoxi").height();
$("#words").animate({scrollTop:speak_height},500);
}

function zhuanyi(msg)
{
var msg=msg.replace(/&/g,"[和]");
var msg=msg.replace(/\+/g,"[加]");
return msg=msg.replace(/\n/g,"[换行]");
}

window.onload=function()
{
var fasong=document.getElementById("fasong");
fasong.onclick=function()
{
fsxx(msg.value);
$("#msg").val("");
}
}

function duxiebianji(neirong)
{
$("#msg").val(""+msg.value+""+neirong+"");
}

function fsxx(msg)
{
var msg=zhuanyi(msg);
$.ajax({
url:"./fasong.php",
data:"msg="+msg+"",
type:"post",
error:function(data)
{
alert("发送失败！");
},
success:function(data)
{
if(data=="请输入内容！")
{
}
else if(data=="发送消息成功")
{
sxx();
robot();
setTimeout(function()
{
Words.scrollTop=Words.scrollHeight;
},1000);
}
else
{
alert(data);
}
}
});
}

var timeOutEvent=0;
$(function()
{
$("#fasong").on({
touchstart:function()
{
timeOutEvent=setTimeout("changanok()",500);
},
touchend:function()
{
clearTimeout(timeOutEvent);
}
})
});

function changanok()
{
timeOutEvent=0;
fsxx1(msg.value);
$("#msg").val("");
}

function fsxx1(msg)
{
var msg=zhuanyi(msg);
$.ajax({
url:"../caozuo.php",
data:"msg=畅聊发送消息"+msg+"",
type:"post",
error:function(data)
{
alert("发送失败！");
},
success:function(data)
{
if(data=="请输入内容！")
{
}
else if(data=="发送消息成功")
{
sxx();
robot();
setTimeout(function()
{
Words.scrollTop=Words.scrollHeight;
},1000);
}
else
{
alert(data);
}
}
});
}

function robot()
{
setTimeout(function()
{
$.ajax({
url:"../robot/index.php",
type:"post"
});
},1000);
}

function yonghu()
{
$.ajax({
url:"./yonghu.php",
type:"post",
dataType:"json",
success:function(data)
{
var code=data.code;
var yh=data.yonghu;
var rs=data.renshuo;
var cczh=data.chuchang;
var ccnc=data.chuchangnc;
var msg=data.msg;
var img=document.getElementById("cctx");
if(code=="1")
{
$("#yonghu").html("畅聊 ("+yh+"/"+rs+")");
alert(msg);
window.location.href="./denglu.php";
}
else if(code=="2")
{
$("#yonghu").html("畅聊 ("+yh+"/"+rs+")");
$("#jinyan1").val(""+msg+"后解除禁言！");
document.getElementById("jinyan").style.display="";
document.getElementById("jieyan").style.display="none";
}
else
{
$("#yonghu").html("畅聊 ("+yh+"/"+rs+")");
document.getElementById("jinyan").style.display="none";
document.getElementById("jieyan").style.display="";
}
if(cczh!="false")
{
img.src="../shuoju/ziliao/"+cczh+"/touxian.gif";
$("#ccxx").html(""+ccnc+" 闪亮登场");
document.getElementById("chuchang").style.display="";
setTimeout(function()
{
document.getElementById("chuchang").style.display="none";
},3000);
}
}
});
}

$(document).ready(function()
{
$("#words").scroll(function()
{
var divHeight=$(this).height();
var nScrollTop=$(this)[0].scrollTop;
var nScrollHeight=$(this)[0].scrollHeight;
if(nScrollTop=="0")
{
$.ajax({
url:"../caozuo.php",
data:"msg=顶部刷新",
type:"post"
});
document.getElementById("shua").style.display="";
}
else if(divHeight+nScrollTop>=nScrollHeight-50)
{
sccookie("gd");
document.getElementById("write").style.display="none";
document.getElementById("write1").style.display="none";
$.ajax({
url:"../caozuo.php",
data:"msg=滚底部",
type:"post"
});
}
else
{
xrcookie("gd","true");
dkaiguan("guan");
document.getElementById("write").style.display="";
}
});
});

function dingwei(msg)
{
if(document.getElementById(msg))
{
window.location.hash=msg;
window.location.hash="";
document.getElementById(msg).style.background="rgba(0,0,0,.5)";
setTimeout(function()
{
document.getElementById(msg).style.background="";
},1500);
}
else
{
$.ajax({
url:"../caozuo.php",
data:"msg=定位"+msg+"",
type:"post",
error:function(data)
{
alert("无法定位！");
},
success:function(data)
{
sxx();
setTimeout(function()
{
if(document.getElementById(msg))
{
window.location.hash=msg;
window.location.hash="";
document.getElementById(msg).style.background="rgba(0,0,0,.5)";
setTimeout(function()
{
document.getElementById(msg).style.background="";
},1500);
}
else
{
alert("无法定位！");
}
},1500);
}
});
}
}

function xieru(name,msg,type)
{
$.ajax({
url:"../caozuo.php",
data:"msg=写入"+name+"，"+msg+","+type+"",
type:"post"
});
}

function xxcz(msg)
{
$.ajax({
url:"../caozuo.php",
data:"msg=消息操作"+msg+"",
type:"post",
dataType:"json",
error:function(data)
{
document.getElementById("xxcz").style.display="none";
},
success:function(data)
{
var ch=data.chehui;
var lx=data.leixing;
document.getElementById("xxcz").style.display="";
document.getElementById("zfxx").style.display="";
document.getElementById("chxx").style.display="none";
document.getElementById("bjxx").style.display="";
document.getElementById("ldxx").style.display="none";
if(ch=="true")
{
document.getElementById("chxx").style.display="";
}
if(lx=="文本")
{
document.getElementById("ldxx").style.display="";
}
if(lx=="发红包")
{
document.getElementById("zfxx").style.display="none";
document.getElementById("bjxx").style.display="none";
document.getElementById("chxx").style.display="none";
}
}
});
}

function zhuanfa()
{
$.ajax({
url:"../caozuo.php",
data:"msg=转发消息",
type:"post",
error:function(data)
{
alert("转发失败！");
},
success:function(data)
{
fsxx1(data);
}
});
}

function bianji()
{
$.ajax({
url:"../caozuo.php",
data:"msg=编辑消息",
type:"post",
error:function(data)
{
alert("编辑失败！");
},
success:function(data)
{
$("#msg").val(data);
alert("长按发送即可");
}
});
}

function langdu()
{
$.ajax({
url:"../caozuo.php",
data:"msg=朗读消息",
type:"post",
error:function(data)
{
alert("朗读失败！");
},
success:function(data)
{
bofang("http://ai.baidu.com/weapp/speech/tts?tex="+data+"&spd=4&pit=6&vol=7&per=110");
}
});
}

function file()
{
if(document.getElementById("file").style.display=="none")
{
document.getElementById("file").style.display="";
document.getElementById("fasong").style.display="none";
}
else
{
document.getElementById("file").style.display="none";
document.getElementById("fasong").style.display="";
}
}

function dkaiguan(msg)
{
if(msg=="guan"||document.getElementById(msg).style.display=="none")
{
document.getElementById("biaoqing").style.display="none";
document.getElementById("gengduo").style.display="none";
document.getElementById("xiutu").style.display="none";
if(msg=="guan")
{
document.getElementById("words").style.height="calc(100% - 170px)";
document.getElementById("write").style.bottom="155px";
document.getElementById("write1").style.bottom="155px";
}
else
{
document.getElementById("words").style.height="calc(100% - 330px)";
document.getElementById("write").style.bottom="320px";
document.getElementById("write1").style.bottom="320px";
document.getElementById(msg).style.display="";
Words.scrollTop=Words.scrollHeight;
}
}
else
{
document.getElementById("words").style.height="calc(100% - 170px)";
document.getElementById("write").style.bottom="155px";
document.getElementById("write1").style.bottom="155px";
document.getElementById(msg).style.display="none";
}
}

function tingxian(id,msg)
{
dh=document.getElementById(id);
dh.style.opacity="0";
setTimeout(function()
{
dh.style.opacity="1";
},msg);
}


function xiutu(id,img,msg)
{
if(id=="1")
{
document.getElementById("words").style.backgroundImage="url("+img+")";
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url(../shuoju/ziliao/"+dqcookie("zh")+"/beijing/2.gif)";
},10000);
}
else if(id=="2")
{
document.getElementById("words").style.backgroundImage="url("+img+")";
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url(../page/image/hs.png)";},100);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url("+img+")";
},1000);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url(../page/image/ls.png)";
},100);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url("+img+")";
},1000);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url(../page/image/hs.png)";},100);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url("+img+")";
},1000);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url(../page/image/ls.png)";
},100);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url("+img+")";
},1000);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url(../page/image/hs.png)";},100);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url("+img+")";
},1000);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url(../page/image/ls.png)";
},100);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url("+img+")";
},1000);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url(../page/image/hs.png)";},100);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url("+img+")";
},1000);
setTimeout(function()
{
document.getElementById("words").style.backgroundImage="url(../shuoju/ziliao/"+dqcookie("zh")+"/beijing/2.gif)";
},11000);
}
else if(msg=="true")
{
alert("秀图类型不存在！");
}
}

function danchu(msg)
{
dh=document.getElementById(msg);
dh.style.opacity="0";
setTimeout(function()
{
dh.style.opacity="0.05";
},50);
setTimeout(function()
{
dh.style.opacity="0.1";
},100);
setTimeout(function()
{
dh.style.opacity="0.15";
},150);
setTimeout(function()
{
dh.style.opacity="0.2";
},200);
setTimeout(function()
{
dh.style.opacity="0.25";
},250);
setTimeout(function()
{
dh.style.opacity="0.3";
},300);
setTimeout(function()
{
dh.style.opacity="0.35";
},350);
setTimeout(function()
{
dh.style.opacity="0.4";
},400);
setTimeout(function()
{
dh.style.opacity="0.45";
},450);
setTimeout(function()
{
dh.style.opacity="0.5";
},500);
setTimeout(function()
{
dh.style.opacity="0.55";
},550);
setTimeout(function()
{
dh.style.opacity="0.6";
},600);
setTimeout(function()
{
dh.style.opacity="0.65";
},650);
setTimeout(function()
{
dh.style.opacity="0.7";
},700);
setTimeout(function()
{
dh.style.opacity="0.75";
},750);
setTimeout(function()
{
dh.style.opacity="0.8";
},800);
setTimeout(function()
{
dh.style.opacity="0.85";
},850);
setTimeout(function()
{
dh.style.opacity="0.9";
},900);
setTimeout(function()
{
dh.style.opacity="0.95";
},950);
setTimeout(function()
{
dh.style.opacity="1";
},1000);
}

function xrcookie(name,msg)
{
var cookie=new Date();
cookie.setTime(cookie.getTime()+30*24*60*60*1000);
document.cookie=name+"="+escape(msg)+";expires="+cookie.toGMTString();
}

function dqcookie(name)
{
var cookie=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(cookie!=null)
{
return unescape(cookie[2]); 
}
else
{
return "0";
}
}

function sccookie(name)
{
var cookie=new Date();
cookie.setTime(cookie.getTime()-1);
document.cookie=name+"=;expires="+cookie.toGMTString();
}
