<?php 
require "../Run.php";
require "../include/send_message.fun.php";

if($_GET['act'] == 'ajax'){
SetCookie($wapid.'_message_type','ajax',time()+60*60*24*7,'/');
}elseif($_GET['act'] == 'html'){
SetCookie($wapid.'_message_type','html',time()+60*60*24*7,'/');
}
if($_COOKIE[$wapid.'_message_type'] == 'ajax'){
$css = '<script language="javascript"> 
 var XMLHttpReq; 
 //创建XMLHttpRequest对象 
function createXMLHttpRequest() { 
 if(window.XMLHttpRequest) { //Mozilla 浏览器 
XMLHttpReq = new XMLHttpRequest(); 
 } 
 else if (window.ActiveXObject) { // IE浏览器 
try { 
 XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); 
 } catch (e) { 
 try { 
 XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); 
 } catch (e) {} 
 } 
 } 
 } 
 //发送请求函数 
function sendRequest() { 
 createXMLHttpRequest(); 
 var url = "LoadList.fun.php?id='.$xid.'&uid='.$_GET['uid'].'&_dc="+new Date().getTime();
 XMLHttpReq.open("GET", url, true); 
 XMLHttpReq.onreadystatechange = processResponse;//指定响应函数 
XMLHttpReq.send(null); // 发送请求 
 document.getElementByIdx_x(\'result\').scrollTop = document.getElementByIdx_x(\'result\').scrollHeight;

 } 
 // 处理返回信息函数 
function processResponse() { 
 if (XMLHttpReq.readyState == 4) { // 判断对象状态 
if (XMLHttpReq.status == 200) { // 信息已经成功返回，开始处理信息 
DisplayHot(); 
 setTimeout("sendRequest()",2000); //设置自动刷新时间，这里是毫秒，即2秒//RemoveRow(); 
 } else { //页面不正常 
 //window.alert("您所请求的页面有异常。"); 
 } 
 
 } 
 } 
function DisplayHot()
 {
 var theDate = XMLHttpReq.responseText ;//如果出现编码问题,可以在服务端escape一下,然后在这里使用unescape( responseText )

 result.innerHTML = theDate ;

 }
 
</script>

 <style>html,body {margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;height:100%;
}
.ask_main{width:100%;height:100%;}
.ask_top table{position:fixed;top:0px;background-color:#efefef;height:40px;border-bottom:1px solid #ccc;width:100%;text-align:center;}	
.ask_top a{color:#222;text-align:center;}
.ask_top table td.left,.ask_top table td.right{
	width:80px;
	text-align:center;
	}
.ask_bottom table{
	position:fixed;
	bottom:0px;
	background-color:#efefef;
	height:40px;
	border-top:1px solid #ccc;
	width:100%;
	}	
.ask_bottom input,.ask_bottom textarea{
	height:26px;
	border:none;
	overflow-y:auto;
	margin:0px;
	width:100%;
	margin-top:5px;
	
	}
.ask_bottom textarea{
	border:1px solid #ccc;
}
.ask_list{
	height:100%;
	background-color:#fff;}
</style>'.$css;
$html = get_message_list($xid,$_GET['uid'],$wapid);
echo head('与'.user2('nc',$_GET['uid'],$wapid).'聊天').'<body onLoad="sendRequest()" onload="window.scrollTo((document.body.scrollWidth-document.body.offsetWidth)/2,0)">';
echo '
<table border="0" cellpadding="0" cellspacing="0" class="ask_main">
<tr><td height="40">
<div class="ask_top">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td class="left"><a href="myfriend.php?">&lt;&lt;返回</a></td>
      <td>'.user2('nc',$_GET['uid'],$wapid).'</td>
      <td class="right"><a href="#">详情</a></td>
    </tr>
  </table>
</div>
 </td></tr><tr><td class="ask_list" id="result"></td><a id="ask_bottom" name="ask_bottom"></a><iframe name="formsubmit" style="display:none;">
    </iframe></tr><tr><td height="40">
 <form action="askPost.inc.php?act=send&uid='.$_GET['uid'].'#ask_bottom" method="POST" name="formphp" target="formsubmit">
<div class="ask_bottom"><table border="0" cellpadding="0" cellspacing="0" style="width:100%"><tr><td width="5"></td><td>
<textarea name="content" wrap="physical" id="content"></textarea>
</td><td align="center" style="width:80px;">
<input type="submit" value="提交" name="button" id="button" style="width:60px;background-color:#efefef;"/>
</td><td width="5"></td></tr></table>
</div></form></td></tr></table>
<!--<script type="text/javascript">
$(document).ready(function(){         //DOM的onload事件处理函数 
   $("#button").click(function(){     //当按钮button被点击时的处理函数 
     postdata();                      //button被点击时执行postdata函数 
   }); 
});

function postdata(){                  //提交数据函数 
   $.ajax({                           //调用jquery的ajax方法 
     type: "POST",                    //设置ajax方法提交数据的形式 
     url: "askPost.inc.php?act=send&uid='.$_GET['uid'].'&",                   //把数据提交到ok.php 
     data: "content="+$("#content").val(),  //输入框writer中的值作为提交的数据 
     success: function(msg){          //提交成功后的回调，msg变量是ok.php输出的内容。 
       alert("数据提交成功");          //如果有必要，可以把msg变量的值显示到某个DIV元素中 
     } 
   }); 
}</script>-->
</body>
</html>';
}else{
if($_GET['act'] == 'send'){
	$type = 'ask_1';
	$sendid = $xid;
	$toid = $_GET['uid'];
	$title = NULL;
	$str = htmlspecialchars($_POST['content'], ENT_QUOTES);
	$send = send_message($wapid,$type,$sendid,$toid,$title,$str);
	if( $send== 1){
		$tip ='';
		header("location:?uid=".$_GET['uid']."#ask_bottom");
	}else{
	}
}
$css = '
 <style>html,body {margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;height:100%;
}
.ask_main{width:100%;height:100%;}
.ask_top table{position:fixed;top:0px;background-color:#efefef;height:40px;border-bottom:1px solid #ccc;width:100%;text-align:center;}	
.ask_top a{color:#222;text-align:center;}
.ask_top table td.left,.ask_top table td.right{
	width:80px;
	text-align:center;
	}
.ask_bottom table{
	position:fixed;
	bottom:0px;
	background-color:#efefef;
	height:40px;
	border-top:1px solid #ccc;
	width:100%;
	}	
.ask_bottom input,.ask_bottom textarea{
	height:26px;
	border:none;
	overflow-y:auto;
	margin:0px;
	width:100%;
	margin-top:5px;
	
	}
.ask_bottom textarea{
	border:1px solid #ccc;
}
.ask_list{
	height:100%;
	background-color:#fff;}
</style>'.$css;
$html = get_message_list($xid,$_GET['uid'],$wapid);
echo head('与'.user2('nc',$_GET['uid'],$wapid).'聊天').'<body onLoad="sendRequest()" onload="window.scrollTo((document.body.scrollWidth-document.body.offsetWidth)/2,0)">';
echo '
<table border="0" cellpadding="0" cellspacing="0" class="ask_main">
<tr><td height="40">
<div class="ask_top">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td class="left"><a href="myfriend.php?">&lt;&lt;返回</a></td>
      <td>'.user2('nc',$_GET['uid'],$wapid).'</td>
      <td class="right"><a href="#">详情</a></td>
    </tr>
  </table>
</div>
 </td></tr><tr><td class="ask_list" id="result">'.$html.'</td></tr><tr><td height="40">
 <form action="?act=send&uid='.$_GET['uid'].'#ask_bottom" method="POST">
<div class="ask_bottom"><table border="0" cellpadding="0" cellspacing="0" style="width:100%"><tr><td width="5"></td><td>
<textarea name="content" wrap="physical" id="content"></textarea>
</td><td align="center" style="width:80px;">
<input type="submit" value="提交" name="button" id="button" style="width:60px;background-color:#efefef;"/>
</td><td width="5"></td></tr></table>
</div></form></td></tr></table>
</body>
</html>';
}

?>