function $(sId)
{
	return document.getElementById(sId);
}

function getXmlHttpObject()
{
	var xmlHttp = null;
	if (window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}
	else
	{
		if (window.ActiveXObject)
		{
			if (new ActiveXObject("Microsoft.XMLHTTP"))
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			else
			{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
		}
	}
	return xmlHttp;

}

function isNumberic(oNum)
{
  if(!oNum) return false;
  var strP=/^\d+(\.\d+)?$/;
  if(!strP.test(oNum)) return false;
  try{
	  if(parseFloat(oNum)!=oNum) return false;
  }
  catch(ex)
  {
   return false;
  }
  return true;
}

var Cookie=new Object();
var CookiesDate = 30;
Cookie.setCookie = function(name,value){
	var exp = new Date();
	exp.setTime(exp.getTime() + CookiesDate*24*60*60*1000);
	var str = name + "=" + escape(value);		
	str += "; path=/; expires="+exp.toGMTString();
	document.cookie = str;
}
Cookie.getCookie = function(name){
	var cookieArray = document.cookie.split("; ");	//得到分割的cookie名值对
	var cookie = new Object();
	for(var i = 0; i < cookieArray.length; i++){
		var arr = cookieArray[i].split("=");				//将名和值分开
		if(arr[0] == name)return unescape(arr[1]);	//如果是指定的cookie，则返回它的值
	}
	return "";
}
Cookie.deleteCookie = function(name){
	document.cookie = name + "=; path=/; expires=-1";
}

function StringBuilder(value)
{
	this.s = [];
	this.append(value);
}
StringBuilder.prototype.append = function(value){
	if(value)
	{
		this.s.push(value);
	}
}
StringBuilder.prototype.clear = function(){
	this.s = [];
}
StringBuilder.prototype.toString = function(){
	return this.s.join('');
}

function init()
{
	//onloadTrans();
	var h = $("content").getElementsByTagName("h2");
	for (var i=0; i<h.length; i++)
	{
		//h[i].onmouseover = function(){
		//	this.className = "MouseOver";
		//}
		//h[i].onmouseout = function(i){
		//	this.className = "";
		//}
		h[i].innerHTML = "<span class=\"returnTop\">[<a href=\"#top\">返回</a>]</span>" + h[i].innerHTML;

	}
	//var p = $("content").getElementsByTagName("p");
	//if (p.length > 10)
	//{
	//	p[6].outerHTML += "<div style=\"margin:20px;\">" + $("bottoma").innerHTML + "</div>";
	//}
	var zImg = $("content").getElementsByTagName("img");
	for (var i=0; i<zImg.length; i++)
	{
		if (zImg[i].src.indexOf("ZoomImg")>-1)
		{
			zImg[i].alt = "点击查看原图";
			zImg[i].className = "zoom";
			zImg[i].onclick = function(){
				dialog("原始图片","<img src=\""+this.src.replace(/(.*?)ZoomImg(.*?)\.jpg/gi, "$1img$2") + "\" />");
			}
		}
	}
	entrySummary();
	showKnowledge();
	scroll();
	showSimilar();
}

function showSimilar()
{
	if (document.body.offsetHeight > 1200)
	{
		if ($("Similar"))
		{
				ss = $("Similar").getElementsByTagName("ul")[0];
				if ($("rightBox"))
				{
					$("rightBox").innerHTML = "<div><img src=\"http://www.wiki8.com/images/l2.gif\" /></div><div class=\"Con\"><h4>我们发现一些条目与此相关</h4><ul>" + ss.innerHTML + "</ul></div><div><img src=\"http://www.wiki8.com/images/l3.gif\" /></div>";
				}
		}
	}
	else
	{
		if ($("rightBox"))
		{
			$("rightBox").style.display = "none";
		}
	}

}
function dialog(winName, str)
{
	if ($("winBox"))
	{
		if (document.body.scrollTop)
		{
			$("winBox").style.top = document.body.scrollTop + 30 + "px";
		}
		else
		{
			$("winBox").style.top = document.documentElement.scrollTop + 30 + "px";
		}
		$("bgDiv").style.display = "block";
		$("winBox").style.display = "block";
		$("winName").innerHTML = winName;
		$("winContent").innerHTML = str;
	}
	else
	{
		var bgDiv = document.createElement("div"); 
		bgDiv.setAttribute("id", "bgDiv");
		bgDiv.style.display = "block";
		bgDiv.style.width = document.body.offsetWidth + "px";
		bgDiv.style.height = document.body.offsetHeight + "px";
		var winBox = document.createElement("div");
		winBox.setAttribute("id", "winBox");
		winBox.style.diaplay = "block";
		if (document.body.scrollTop)
		{
			winBox.style.top = document.body.scrollTop + 30 + "px";
		}
		else
		{
			winBox.style.top = document.documentElement.scrollTop + 30 + "px";
		}
		var winMenu = "\
			<div class=\"winMenu\">\
			<img alt=\"关闭\" src=\"/images/del_btn.gif\" style=\"float:right;cursor:pointer;\" onclick=\"closeDialog();\" />\
			<span id=\"winName\">" + winName + "</span>\
			</div>\
		";
		winBox.innerHTML = winMenu + "<div id=\"winContent\">" + str + "</div>";
		document.body.appendChild(bgDiv); 
		document.body.appendChild(winBox); 
	}
}
function closeDialog()
{
	$("bgDiv").style.display = "none";
	$("winBox").style.display = "none";
}

function entrySummary()
{
	var summaryWin = document.createElement("div"); 
	summaryWin.setAttribute("id", "summaryWin");
	document.body.appendChild(summaryWin);

	var a = $("content").getElementsByTagName("a");
	for (i = 0; i < a.length; i++)
	{
		if (a[i].rel=="summary")
		{
			a[i].onmouseover = function(){
				try
				{
					clearTimeout(gc);
				}
				catch (e)
				{
				}
				var event=arguments[0] || window.event;   
				var x = event.clientX;
				var y = event.clientY;
				var scrollT = getDocType().scrollTop;
				x = x + 20;
				if (x + 400 > document.body.offsetWidth)
				{
					x = x - 400;
				}
				y = y + 10 + scrollT;
				go = setTimeout("openEntrySummary('" + x + "', '" + y + "', '" + this.href + "')", 500);
			}
			a[i].onmouseout = function(){
				try
				{
					clearTimeout(go);
				}
				catch (e)
				{
				}
				gc = setTimeout("closeEntrySummary()", 800);
			}
		}
	}

}

function openEntrySummary(x, y, h)
{
	var _summaryWin = $("summaryWin")
	if (h != "s")
	{
		_summaryWin.style.display = "block";
		_summaryWin.style.top = y + "px";
		_summaryWin.style.left = x + "px";
		_summaryWin.innerHTML = "<div id=\"ol\">Lodding...</div><iframe frameborder=\"0\" src=\"/Summary?" + h + "\"></iframe>";				
	}
	else
	{
		_summaryWin.style.display = "block";
	}
}
function closeEntrySummary()
{
	$("summaryWin").style.display = "none";
}

function showKnowledge()
{
	as = $("content").getElementsByTagName("a");
	kns = new StringBuilder();
	for (i = 0; i < as.length ; i ++)
	{
		if (as[i].rel == "summary")
		{
			kns +="<li><a title=\"" + as[i].innerHTML + "\" href=\"" + as[i].href + "\" rel=\"knowledge\">" + as[i].innerHTML + "</a></li>";
		}
	}
	kn = kns.toString();
	if (kns != "")
	{
		$("floatLeft").innerHTML = "<h3>知识点</h3><ul>" + kns + "</ul>";
	}
}


function search(w)
{
	if(w == "fulltext")
	{
		$("s").action = "http://www.94ab.com/s";
		$("s").target = "_blank";
		$("s").submit();
	}
	else
	{
		$("s").action = "/search";
		$("s").target = "_self";
		$("s").submit();
	}
}
function getWinHeight()
{
	if (window.navigator.appName=="Netscape")
	{
		return window.innerHeight;
	}
	else
	{
		return getDocType().offsetHeight;
	}
}
function getDocType()
{
	if (document.documentElement)
	{
		return document.documentElement;
	}
	else
	{
		return document.body;
	}
}
function reSize()
{
	if ($("floatLeft").getElementsByTagName("ul")[0])
	{
		$("floatLeft").getElementsByTagName("ul")[0].style.height = getWinHeight() - (80 + getFloatTop()) + "px";
		$("floatLeft").style.top = (580 + getFloatTop()) + "px";
	}
}
function getFloatTop()
{
	if ($("showHDay"))
	{
		return 80;
	}
	else
	{
		return 0;
	}
}
function scroll()
{
	reSize();
	window.onscroll = function(){
		t = getDocType().scrollTop;
		if (t > 580 + getFloatTop())
		{
			$("floatLeft").style.top = t + 10 + "px";
		}
		else
		{
			$("floatLeft").style.top = 580 + getFloatTop() + "px";
		}
		
	}
}