//floatbox.js
function getElement(aID)
{
  return (document.getElementById) ? document.getElementById(aID)
                                   : document.all[aID];
}
function getAllElement()
{
  return (document.getElementsByTagName) ? document.getElementsByTagName("*")
										 : document.all;
}
function getParentElement(elm)
{
	return (elm.parentElement) ? elm.parentElement : elm.parentNode
}
var Drag={
        "obj":null,
	"init":function(a, aRoot){
			a.onmousedown=Drag.start;
			a.root = aRoot;
			if(isNaN(parseInt(a.root.style.left)))a.root.style.left="0px";
			if(isNaN(parseInt(a.root.style.top)))a.root.style.top="0px";
			a.root.onDragStart=new Function();
			a.root.onDragEnd=new Function();
			a.root.onDrag=new Function();
		},
	"start":function(a){	
			var b=Drag.obj=this;
			a=Drag.fixE(a);
			var c=parseInt(b.root.style.top);
			var d=parseInt(b.root.style.left);
			b.root.onDragStart(d,c,a.clientX,a.clientY);
			b.lastMouseX=a.clientX;
			b.lastMouseY=a.clientY;
			document.onmousemove=Drag.drag;
			document.onmouseup=Drag.end;
			return false;
		},	
	"drag":function(a){
			a=Drag.fixE(a);
			var b=Drag.obj;
			var c=a.clientY;
			var d=a.clientX;
			var e=parseInt(b.root.style.top);
			var f=parseInt(b.root.style.left);
			var h,g;
			h=f+d-b.lastMouseX;
			g=e+c-b.lastMouseY;
			b.root.style.left=h+"px";
			b.root.style.top=g+"px";			
			b.lastMouseX=d;
			b.lastMouseY=c;
			b.root.onDrag(h,g,a.clientX,a.clientY);
			return false;
		},
	"end":function(){			
			document.onmousemove=null;
			document.onmouseup=null;
			Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style.left),parseInt(Drag.obj.root.style.top));
			Drag.obj=null;
		},
	"fixE":function(a){
			if(typeof a=="undefined")a=window.event;
			if(typeof a.layerX=="undefined")a.layerX=a.offsetX;
			if(typeof a.layerY=="undefined")a.layerY=a.offsetY;
			return a;
		}
};
function addLightboxMarkup() {

	bod 				= document.getElementsByTagName('body')[0];

	overlay 			= document.createElement('div');
	overlay.id			= 'overlay';

	bod.appendChild(overlay);
}
function hideSelect(visibility){
	selects = document.getElementsByTagName('select');
	for(i = 0; i < selects.length; i++) {
		selects[i].style.visibility = visibility;
	}
}
function preIE(height, overflow){
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		htm.style.overflow = overflow;
}
function getRange() {
      var top     = document.documentElement.scrollTop;
      var left    = document.documentElement.scrollLeft;
      var height  = document.documentElement.clientHeight;
      var width   = document.documentElement.clientWidth;

      if (top==0 && left==0 && height==0 && width==0) {
        top     = document.body.scrollTop;
        left    = document.body.scrollLeft;
        height  = document.body.clientHeight;
        width   = document.body.clientWidth;
      }

      return  {top:top  ,left:left ,height:height ,width:width } ;
}
function showBox(e){
	if(typeof e=="undefined")e=window.event;
//获取 原贴信息
	var lobj=e.srcElement;
	var rel=lobj.getAttribute("rel");
	var rellength=rel.length;//id的长度
	var relnewname=rel.substring(0,rellength-2)//去掉后两个字节的名字（后两个字节为赞同_1和反对_2标识）
	var rel2last=rel.substring(rellength-2,rellength)//后两个字节为赞同_1和反对_2标识
	var relobj=getElement(relnewname);
	var rbody = relobj.innerHTML;
	//rbody=rbody.replace(/<.*>/gi,"");
	rbody=rbody.replace(/<[^>]*>/gi,"");
	if(rbody.length>100){
		rbody = rbody.substring(0,100) + "......";
	}
	getElement("reply_quote_text").innerHTML=rbody;
	if(rel2last=="_1"){
	   getElement("reply_quote_state").innerHTML="赞同理由";
	}else if(rel2last=="_2"){
	   getElement("reply_quote_state").innerHTML="反对理由";
	}
	getElement("quote_info").value=rel;

	hideSelect("hidden");
	//overlay.style.display="block";
	WfloatBox.style.display="block";

	var range=getRange();
	WfloatBox.style.top=(range.top+WfloatBox.oy) +"px";
	WfloatBox.style.left=(range.left+WfloatBox.ox) +"px";

	window.onscroll=onbodyscroll;
}

function onbodyscroll(){
	var range=getRange();
	WfloatBox.style.top=(range.top+WfloatBox.oy) +"px";
	WfloatBox.style.left=(range.left+WfloatBox.ox) +"px";
}

function closeBox(){
	hideSelect("visible");
	//overlay.style.display="none";
	WfloatBox.style.display="none";
}

function initbox(){	
	var range=getRange();
	WfloatBox=getElement("reply_quote_Box");
	WfloatBox.ox=(range.width-400)/2;
	WfloatBox.oy=(range.height-300)/2;

	Drag.init(getElement("reply_bar"),WfloatBox);

	WfloatBox.onDragEnd=function(x,y){
		WfloatBox.ox=x-getRange().left;
		WfloatBox.oy=y-getRange().top;
	}

	//addLightboxMarkup();

	//overlay.style.height=document.body.clientHeight;

	var all=getAllElement();
	var l=all.length;
	for(var i=0;i<l;i++){
		var o=all[i];
		if(o.className=="lbOn")
		{
			o.attachEvent("onclick",showBox);
		}
	}
}
//==========================================
//引用评论
function getvaluestrFun(strvalue,quoteid,quotestate){
   if(strvalue!=""){
	  //strvalue=strvalue.replace(/<.*>/gi,"");
	  //strvalue=strvalue.replace(/<[^>]*>/gi,"");
	  if(strvalue.length>200){
		strvalue = strvalue.substring(0,200) + "......</P><p>";
	  }
	}
	
	if(quotestate=="1"){//赞同样式显示
	   strvalue="<div style='border-left:6px #e0fee0 solid;color:#333;margin-left:10px;padding:0px 2px 0px 5px;'><span style='color:#00cc00;'>(赞同)</span>"+strvalue+"</div>";
	}else if(quotestate=="2"){//反对样式显示
	   strvalue="<div style='border-left:6px #ffdfdf solid;color:#333;margin-left:10px;padding:0px 2px 0px 5px;'><span style='color:#cc0000;'>(反对)</span>"+strvalue+"</div>";
	}
	
   strvalue="引用<div style='border:3px #000 dotted;width:590px;padding-bottom:5px;'><div style='text-align:right;'><span style='padding:3px 5px 2px 5px;background-color:#ffff00;'><a href='javascript:;' onclick='javascript:delgetvaluestrFun();' title='取消引用'>取消<img src='images/close.gif' border='0' /></a></span></div>"+strvalue+"</div>";
   document.getElementById('quote_id').value=quoteid;
   document.getElementById('state_id').value=quotestate;
   document.getElementById('show_quote_text').innerHTML=strvalue;
}
//消取引用
function delgetvaluestrFun(){
   document.getElementById('quote_id').value="0";
   document.getElementById('state_id').value="0";
   document.getElementById('show_quote_text').innerHTML="";
}

//window.onload=initbox;
