var cn=400;
var cnT=100;
var addcn="#";
var readcn="#";
var x0=0,y0=0,x1=0,y1=0;
var offx=0,offy=0;//(6)位移量(阴影)
var moveable=false;
var hover='orange',normal='white';//color;
var index=10000;//z-index;
var isIE = /msie/i.test(navigator.userAgent);
var isFF = /firefox/i.test(navigator.userAgent);
//开始拖动;
function startDrag(obj)
{
//锁定标题栏;
//if(isIE){
obj.setCapture();
//}
//if(isFF){
//obj.stopPropagation();
//}

//定义对象;
var win = obj.parentNode;
var sha = win.nextSibling;
//记录鼠标和层位置;
x0 = event.clientX;
y0 = event.clientY;
x1 = parseInt(win.style.left);
y1 = parseInt(win.style.top);
//记录颜色;
normal = obj.style.backgroundColor;
//改变风格;
obj.style.backgroundColor = hover;
win.style.borderColor = hover;
obj.nextSibling.style.color = hover;
sha.style.left = x1 + offx;
sha.style.top = y1 + offy;
moveable = true;
}
//拖动;
function drag(obj)
{
var win = obj.parentNode;
var sha = win.nextSibling;
if(moveable)
{
 win.style.left = x1 + event.clientX - x0;
 win.style.top = y1 + event.clientY - y0;
 sha.style.left = parseInt(win.style.left) + offx;
 sha.style.top = parseInt(win.style.top) + offy;
}
}
//停止拖动;
function stopDrag(obj)
{
var win = obj.parentNode;
var sha = win.nextSibling;
win.style.borderColor = normal;
obj.style.backgroundColor = normal;
obj.nextSibling.style.color = normal;
sha.style.left = obj.parentNode.style.left;
sha.style.top = obj.parentNode.style.top;
//放开标题栏;
obj.releaseCapture();
//if(isIE){ obj.releaseCapture(); }
//if(isFF){ obj.preventDefault();}

moveable = false;
}
//获得焦点;
function getFocus(obj)
{
index = index + 2;
var idx = index;
obj.style.zIndex=idx;
obj.nextSibling.style.zIndex=idx-1;
}
function min(obj)
{
var win = obj.parentNode.parentNode;
var sha = win.nextSibling;
var tit = obj.parentNode;
var msg = tit.nextSibling;
var flg = msg.style.display=="none";
if(flg)
{
 win.style.height = parseInt(msg.style.height) + parseInt(tit.style.height) + 2*2;
 sha.style.height = win.style.height;
 msg.style.display = "block";
 obj.innerHTML = "0";
}
else
{
 win.style.height = parseInt(tit.style.height) + 2*2;
 sha.style.height = win.style.height;
 obj.innerHTML = "2";
 msg.style.display = "none";
}
}
function cls(obj)
{
var win = obj.parentNode.parentNode;
var sha = win.nextSibling;
win.style.visibility = "hidden";
sha.style.visibility = "hidden";
}
//创建一个对象;
function xWin(id,w,h,l,t,tit,msg)
{
index = index+2;
this.id   = id;
this.width  = w;
this.height = h;
this.left  = l;
this.top   = document.body.scrollTop+t;
this.zIndex = index;
this.title  = tit;
this.message = msg;
this.obj   = null;
this.bulid  = bulid;
this.bulid();
}
//初始化;
function bulid()
{
var str = ""
 + "<div id=xMsg" + this.id + " "
 + "style='"
 + "z-index:" + this.zIndex + ";"
 + "width:" + this.width + "px;"
 + "height:" + this.height + "px;"
 + "left:" + this.left + "px;"
 + "top:" + this.top + "px;"
 + "background-color:" + normal + ";"
 + "color:" + normal + ";"
 + "font-size:10px;"
 + "font-family:Verdana;"
 + "position:absolute;"
 + "cursor:default;"
 + "border:0px solid " + normal + ";"
 + "' "
 + "onmousedown='getFocus(this)'>"
  + "<div "
  + "style='cursor:move;position:absolute;filter: Alpha(Opacity=0);"
  //+ "background-color:" + normal + ";"
  + "width:" + (this.width-2*2) + "px;"
  + "height:40px;"
  + "color:white;"
  + "' "
  + "onmousedown='startDrag(this)' "
  + "onmouseup='stopDrag(this)' "
  + "onmousemove='drag(this)' "
  + ">"
  + "<span style='width:" + (this.width-2*12-4) + "px;padding-left:3px;'>" + this.title + "</span>"
  + "<span style='width:12;border-width:0px;color:white;font-family:webdings;'>0</span>"
  + "<span style='width:12;border-width:0px;color:white;font-family:webdings;'>r</span>"
  + "</div>"
  + "<div style='"
  + "width:100%;"
  + "height:" + (this.height-20-4) + "px;"
  + "background-color:white;"
  + "line-height:14px;"
  + "word-break:break-all;"
  + "padding:0px;"
  + "'>" + this.message + "</div>"
 + "</div>"
 + "<div id='sha"+this.id+"' style='"
 + "width:" + this.width + "px;"
 + "height:" + this.height + "px;"
 + "top:" + this.top + "px;"
 + "left:" + this.left + "px;"
 + "z-index:" + (this.zIndex-1) + "px;"
 + "position:absolute;"
 //+ "background-color:black;"
 + "filter:alpha(opacity=0);"
 + "'>"
 +"<iframe src='about:blank' name='hiddenIframe' width='100%' frameborder='0' height='"+this.height+"px'></iframe>"
 +"</div>";
 //alert(str);
 insertHtml('beforeEnd',document.body,str);
//document.body.insertAdjacentHTML("beforeEnd",str);
}
//-->
 function insertHtml(where, el, html){      
      
     where = where.toLowerCase();      
     if(el.insertAdjacentHTML){      
      
         switch(where){      
             case "beforebegin":      
                 el.insertAdjacentHTML('BeforeBegin', html);      
                 return el.previousSibling;      
             case "afterbegin":      
                 el.insertAdjacentHTML('AfterBegin', html);      
                 return el.firstChild;      
             case "beforeend":      
                 el.insertAdjacentHTML('BeforeEnd', html);      
                 return el.lastChild;      
             case "afterend":      
                 el.insertAdjacentHTML('AfterEnd', html);      
                 return el.nextSibling;      
         }      
         throw 'Illegal insertion point -> "' + where + '"';      
     }      
                     
     var range = el.ownerDocument.createRange();      
     var frag;      
     switch(where){      
          case "beforebegin":      
             range.setStartBefore(el);      
             frag = range.createContextualFragment(html);      
             el.parentNode.insertBefore(frag, el);      
             return el.previousSibling;      
          case "afterbegin":      
             if(el.firstChild){      
                 range.setStartBefore(el.firstChild);      
                 frag = range.createContextualFragment(html);      
                 el.insertBefore(frag, el.firstChild);      
                 return el.firstChild;      
              }else{      
                 el.innerHTML = html;      
                 return el.firstChild;      
              }      
         case "beforeend":      
             if(el.lastChild){      
                 range.setStartAfter(el.lastChild);      
                 frag = range.createContextualFragment(html);      
                 el.appendChild(frag);      
                 return el.lastChild;      
             }else{      
                 el.innerHTML = html;      
                 return el.lastChild;      
             }      
         case "afterend":      
             range.setStartAfter(el);      
             frag = range.createContextualFragment(html);      
             el.parentNode.insertBefore(frag, el.nextSibling);      
             return el.nextSibling;      
     }      
     throw 'Illegal insertion point -> "' + where + '"';      
 }     
<!--
function add(id,name){
if(addcn.indexOf("#"+id+"#")>0){
document.getElementById("xMsg"+id).style.visibility = "visible";
document.getElementById("sha"+id).style.visibility = "visible";
}else{
cn=cn+30;
cnT=cnT+30;
var sendStr="";
var str ="";
if(isFF){
	str = "<div style='position:absolute; height:16px ; width:16px; margin-left:260px;margin-top:8px;color:#ffffff;font-weight:bold; font-size:14px;cursor:hand' onclick='close1("+id+")'>×</div>";
}
if(isIE){
	str = "<div style='position:absolute; height:16px ; width:16px; margin-left:125px;margin-top:8px;color:#ffffff;font-weight:bold; font-size:14px;cursor:hand' onclick='close1("+id+")'>×</div>";
}
sendStr="<div id='frame_talk1'>"
+str
//+"<div style='position:absolute; height:16px ; width:16px; margin-left:260px;margin-top:8px;color:#ffffff;font-weight:bold; font-size:14px;cursor:hand' onclick='close1("+id+")'>×</div>"
+"	<div><img src='/websev/images/send_top.gif' width='285px' height='40px' alt=''></div> "
+"	<div>     "
+"		<table cellpadding='0' cellspacing='0' border='0' width='100%'>"
+"			<tr>"
+"				<td width='19px'><img src='/websev/images/sendTL.gif' width='19px' height='34px' alt=''></td>"
+"				<td class='pnlT_bg'><span id='web_name1' style='font-size:14px;color:#000000'>给&nbsp;<img src='/websev/images/talk_logo2.gif' width='18px' height='20px' align='absmiddle'> "+name+"&nbsp;发信息</span></td>"
+"				<td width='19px'><img src='/websev/images/sendTR.gif' width='19px' height='34px' alt=''></td>"
+"			</tr>"
+"		</table>"
+"	</div>"
+"	<div>"
+"		<table width='100%' border='0' cellspacing='0' cellpadding='0'>"
+"			<tr>"
+"				<td class='pnlML_bg'><img src='/websev/images/sendMR.jpg' width='15px' height='250px' alt=''></td>"
+"				<td class='pnlMM'>"
+"				<div class='pnlContent'>"
+"					<textarea id='content"+id+"' cols='30' rows='13' style='border:0px;overflow:auto' onkeydown='if(event.ctrlKey&&event.keyCode==13){send("+id+");}'></textarea>"
+"				</div>"
+"				</td>"
+"				<td class='pnlMR_bg'><img src='/websev/images/sendMR-14.jpg' width='16px' height='250px' alt=''></td>"
+"			</tr>"
+"		</table>"
+"	</div>"
+"	<div id='loading"+id+"' style='display:none;position:absolute; z-index:9999; margin-top:10px; margin-left:18px'><img src='/websev/images/sending.gif' width='16' height='16' alt='正在发送,请稍候'></div> "
+"	<div>"
+"		<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
+"			<tr>"
+"				<td width='19px'><img src='/websev/images/sendBL.gif' width='19px' height='36px' alt=''></td>"
+"				<td class='pnlB_content_2'><a href='javascript:close1("+id+")'><font color='#ffffff'>关闭</font></a>&nbsp;&nbsp;<a href='javascript:send("+id+");' title='按ctrl+enter发送'><font color='#ffffff'>发送</font></a></td>"
+"				<td width='19px'><img src='/websev/images/sendBR.gif' width='19px' height='36px' alt=''></td>  "
+"			</tr>"
+"		</table> "
+"	</div> "
+"</div>";
new xWin(id,285,320,cn,cnT,"",sendStr);
addcn+="#"+id+"#";
}
document.getElementById("content"+id).focus();
}


function read(id,name){
if(readcn.indexOf("#"+id+"#")>0){
document.getElementById("xMsg"+id+"read").style.visibility = "visible";
document.getElementById("sha"+id).style.visibility = "visible";
}else{
cn=cn+30;
cnT=cnT+30;
var read="<div id='frame_talk'>"
+"<div style='position:absolute; height:16px ; width:16px; margin-left:260px;margin-top:8px;color:#ffffff;font-weight:bold; font-size:14px;cursor:hand' onclick='closeR("+id+")'>×</div>"
+"<div><img src='/websev/images/talk_top.gif' width='285px' height='34px' alt=''></div> "
+"	<div>"
+"		<table width='100%' border='0' cellspacing='0' cellpadding='0'>"
+"			<tr>"
+"				<td class='pnlML_bg'><img src='/websev/images/pnlM_bg_l.jpg' width='14px' height='249px'></td>"
+"				<td class='pnlMM'><div class='pnlTitle'><span id='web_name' style='font-size:14px;color:#000000'>来自&nbsp;<img src='/websev/images/talk_logo.gif' width='18px' height='20px' align='absmiddle'> "+name+"&nbsp;的信息</span>"
+"						<div class='lineB'></div>"
+"					</div>"
+"					<div id='web_meg"+id+"' class='pnlContent' style='background-color:white;TABLE-LAYOUT: fixed;word-break:break-all;word-wrap:word-break;overflow-y:auto;text-size:12px'>"
+"					正在加载数据,请稍候...  "
+"					</div></td>"
+"				<td class='pnlMR_bg'><img src='/websev/images/pnlM_bg_r.jpg' width='15px' height='249px'></td>"
+"			</tr>"
+"		</table>"
+"	</div>"
+"	<div>"
+"		<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
+"			<tr>"
+"				<td width='19px'><img src='/websev/images/talkB_left.gif' width='19px' height='36' alt=''></td>"
+"				<td class='pnlB_content'><a href='javascript:closeR("+id+")'><font color='#ffffff'>关闭</font></a>&nbsp;&nbsp;<a href='javascript:reply("+id+",\""+name+"\");'><font color='#ffffff'>回复</font></a></td>  "
+"				<td width='19px'><img src='/websev/images/talkB_right.gif' width='19px' height='36px' alt=''></td>"
+"			</tr>"
+"		</table>"
+"	</div>"
+"</div>";
new xWin(id+"read",285,200,cn,cnT,"Wildwind's Msgbox",read);
readcn+="#"+id+"#";
}
}
function close1(id){
document.getElementById("xMsg"+id).style.visibility = "hidden";
document.getElementById("sha"+id).style.visibility = "hidden";
//sha.style.visibility = "hidden";
}
function closeR(id){
document.getElementById("xMsg"+id+"read").style.visibility = "hidden";
document.getElementById("sha"+id).style.visibility = "hidden";
}
function reply(id,name){
	add(id,name);
	closeR(id);
}
function textLength(v){
   var j = 0;
   var i = 0;
   var len = v.length;
   for(i = 0 ; i < len; i ++){
       if(v.charCodeAt(i)> 255){
            j += 2;
        }else{
            j++;
          }
   }
   return j;
}

function send(id){
	var content = document.getElementById("content"+id).value;
	if(check_send(id)){
		document.getElementById("loading"+id).style.display="";		
		var ajax=new AjaxRequest();
		ajax.method="POST";
			ajax.url="/websev/send.jsp?id="+id+"&content="+content;
			ajax.callback=function(xmlobj){
				var resText="";
				if(xmlobj.responseText==0){
					document.getElementById("content"+id).value="";
					document.getElementById("loading"+id).style.display="none";
					document.getElementById("content"+id).focus();
				}else if(xmlobj.responseText==2){
					alert("信息发送失败,请重试!");
				}
				
			}
			ajax.send();	
	}	
}

function check_send(id){
if(document.getElementById("content"+id).value==""){
		alert("内容不能为空!");
		document.getElementById("content"+id).focus();
		return false;
	}
	return true;
}
