//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 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("url_re");
	var rel=this.location.href;
	
	if(rel==null || rel==""){
		rel="http://bbs.15735.com";
	}
	getElement("url").value=rel;

	hideSelect("hidden");
	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;
	if(getElement("email").value==null || getElement("email").value==""){
		getElement("email").focus();
	}else{
		getElement("password").focus();
	}
}

function showBox_url(url_next,iflogin){
	if(iflogin=="true"){
		window.location=url_next;
	}else{
		var rel=this.location.href;
		if(url_next!=null && url_next!="" && typeof url_next!="undefined"){
			rel=url_next;
		}
		if(rel==null || rel==""){
			rel="http://bbs.15735.com";
		}
	
		getElement("url").value=rel;
	
		hideSelect("hidden");
		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;

		if(getElement("email").value==null || getElement("email").value==""){
			getElement("email").focus();
		}else{
			getElement("password").focus();
		}
	}
}

function showChargeBox(e){
	if(typeof e=="undefined")e=window.event;
	hideSelect("hidden");
	WfloatBox2.style.display="block";
	var range2=getRange();
	WfloatBox2.style.top=(range2.top+WfloatBox2.oy) +"px";
	WfloatBox2.style.left=(range2.left+WfloatBox2.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");
	WfloatBox.style.display="none";
}

function closeChargeBox(){
	hideSelect("visible");
	WfloatBox2.style.display="none";
}

function initbox2(){	

	var range=getRange();
	WfloatBox=getElement("floatBox");
	WfloatBox.ox=(range.width-400)/2;
	WfloatBox.oy=(range.height-300)/2;

	Drag.init(getElement("draghead"),WfloatBox);

	WfloatBox.onDragEnd=function(x,y){
		WfloatBox.ox=x-getRange().left;
		WfloatBox.oy=y-getRange().top;
	}
	out_userid	= reply_getCookie("NETEASE_SSN");
	document.getElementById("email").value = out_userid;

	
}

function initbox(){	

	var range=getRange();
	WfloatBox=getElement("floatBox");
	WfloatBox.ox=(range.width-400)/2;
	WfloatBox.oy=(range.height-300)/2;

	Drag.init(getElement("draghead"),WfloatBox);

	WfloatBox.onDragEnd=function(x,y){
		WfloatBox.ox=x-getRange().left;
		WfloatBox.oy=y-getRange().top;
	}
	out_userid	= reply_getCookie("NETEASE_SSN");
	document.getElementById("email").value = out_userid;
	
	var range2=getRange();
	WfloatBox2=getElement("ChargeBox");
	WfloatBox2.ox=(range2.width-400)/2;
	WfloatBox2.oy=(range2.height-300)/2;
	Drag.init(getElement("draghead2"),WfloatBox2);
	WfloatBox2.onDragEnd=function(x,y){
		WfloatBox2.ox=x-getRange().left;
		WfloatBox2.oy=y-getRange().top;
	}
	
}







var cookies = new String(document.cookie);
function reply_getCookie(namex)
{
	var cookieHeader = namex + "=";
	var beginPosition = cookies.indexOf(cookieHeader);
	if (beginPosition != -1) 
	{
		var acookie = cookies.substring(beginPosition + cookieHeader.length);
		if (acookie.indexOf(";")>-1)
		{
			acookie = acookie.substring(0, acookie.indexOf(";"));
		}
		return acookie;
	}
	return "";
}



//window.onload=initbox;