function setCookie (name, value) {
  //document.cookie = name + "=" + value + ";expires=Thursday,01-Jan-2099 00:00:00 GMT";
  document.cookie = name + "=" + value + "; path=/;expires=Thursday,01-Jan-2099 00:00:00 GMT";
}

function getCookie(name) {
  var search;
  search = name + "=";
  offset = document.cookie.indexOf(search); 
  if (offset != -1) {
    offset += search.length ;
    end = document.cookie.indexOf(";", offset) ;
    if (end == -1)
      end = document.cookie.length;
    return unescape(document.cookie.substring(offset, end));
  }
  else
    return "";
}

function deleteCookie(name) {
  setCookie(name, "");
}

//浮动的登录盒子
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;
	//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("bbsuser").value==null || getElement("bbsuser").value==""){
		getElement("bbsuser").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 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("bbsuser").value = out_userid;
	
}

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;
function userLogin(frmid) {
  var frm = document.forms[frmid];
  if (frm==null && typeof(frm)!="object") {
    alert("登陆框不存在！");
    return false;
  }

  var bbsuser     = frm.bbsuser.value;
  var password  = frm.password.value;
  if (bbsuser == null || bbsuser == "") {
    alert("请输入用户名.");
    frm.bbsuser.focus();
    return false;
  }

  if (password == "") {
    alert("请输入密码.");
    frm.password.focus();
    return false;
  }
  return true;
}
function check_search(form)
		{
		if (form.searchcontent.value=="")
			{
			alert("请输入搜索内容！");
			form.searchcontent.focus();
			return false;
			}
			return true;
		}
function popwin(path)
{ window.open(path,'',"height=150,width=200,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no");
}