///////////////////////////////////////////////////////////////
// root.js v12.0
// webtea 页面脚本：基本模块
// Copyright 2001 - 2004 webteam.com.cn 
//
// 更新说明：
// 2004-03-09 v11.0
//	1、定义了全局的路径变量及生成的简便方法
//	 　以便提高母板的可移植性
//	2、重新改写了“前后导航”条的生成函数，使
//	 　其能有更多的选择
//
// 2004-04-13 v12.0
//	1、增加了“分页控制”公共属性，提供对列表分页的支持
///////////////////////////////////////////////////////////////
var OnloadFns=new Array();

var gPathIDs	= new Array();
var gPathNames	= new Array();
var gPathHrefs	= new Array();
var gKeywords	= new Array();

var gWebStyle	= 1;
var viewCount	= 0;

var gWebBase		= "../"
var gNodePageUrl	= ""
var gLibBase		= gWebBase + "lib/"
var gLibBase_Img	= gLibBase + "img/"

function window.WebBaseUrl(fn) {
	return gWebBase + fn;
}
function window.ImagesUrl(fn) {
	return gWebBase + "Images/" + fn;
}
function window.StyleImgUrl(fn) {
	return gWebBase + "Images/" + gWebStyle + "/" + fn;
}

function window.LibImgUrl(fn) {
	return gLibBase_Img + fn
}
function window.NodeXmlUrl(nid) {
	return gWebBase + "NodeXml/" + nid + ".xml";
}

function CurPlaceHtml(spChr, className) {
	var p='';
	var i;

	p = "<span class=" + className + ">" + gPathNames[2] + "</span>"
	for(i=3; i < gPathHrefs.length; i++)
		p = '<a href=' + gPathHrefs[i] + ' class=' + className + '>' + gPathNames[i] + '</a>' + spChr + p;

	return p;
}

function CurPlaceHtmlx(spChr, className, curCaption) {
	var p='';
	var i;
	
	if(curCaption.length == 0)
		curCaption = gPathNames[2];
	p = "<span class=" + className + ">" + curCaption + "</span>"
	for(i=3; i < gPathHrefs.length; i++)
		p = '<a href=' + gPathHrefs[i] + ' class=' + className + '>' + gPathNames[i] + '</a>' + spChr + p;

	return p;
}

function PrevNextHtml() {
	var s="<table width='100%'>"
	s = s + "<colgroup>"
	s = s + "<col align='left' width='33%'><col align='center' width='33%'><col align='right' width='33%'>"
	s = s + "</colgroup><tr>"
	if(gPathIDs[0].length>0) {
		s = s + "<td><a href='" + gPathHrefs[0] + "'>"
		s = s + "<img border='0' width='30' height='30' src='" + window.StyleImgUrl("prev.gif") + "'"
		s = s + "alt='" + gPathNames[0] + "' />"
		s = s + "</a></td>"
	}
	else {
		s = s + "<td><img width='30' height='30' src='" + window.ImagesUrl("c.gif") + "'></td>"
	}

	if(gPathIDs.length>3) {
		s = s + "<td><a href='" + gPathHrefs[3] + "'>"
		s = s + "<img border='0' width='30' height='30' src='" + window.StyleImgUrl("goup.gif") + "'"
		s = s + "alt='" + gPathNames[3] + "' />"
		s = s + "</a></td>"
	}
	else {
		s = s + "<td><img width='30' height='30' src='" + window.ImagesUrl("c.gif") + "'></td>"
	}

	if(gPathIDs[1].length>0) {
		s = s + "<td><a href='" + gPathHrefs[1] + "'>"
		s = s + "<img border='0' width='30' height='30' src='" + window.StyleImgUrl("next.gif") + "'"
		s = s + "alt='" + gPathNames[1] + "' />"
		s = s + "</a></td>"
	}
	else {
		s = s + "<td><img width='30' height='30' src='" + window.ImagesUrl("c.gif") + "'></td>"
	}
	s = s + "</tr></table>"
	return s;
}
function PrevNextHtml_0(titPrev, titNext, titUp) {
	var s = "<colgroup>"
	    s = s + "<col align='center' width='50%'><col align='center' width='50%'>"
	    s = s + "</colgroup><tr>"

	if(gPathIDs[0].length>0) {
		s = s + "<td><a href='" + gPathHrefs[0] + "'>" + titPrev + "</a></td>"
	}
	else {
		s = s + "<td>" + titPrev + "</td>"
	}
	if(gPathIDs[1].length>0) {
		s = s + "<td><a href='" + gPathHrefs[1] + "'>" + titNext + "</a></td>"
	}
	else {
		s = s + "<td>" + titNext + "</td>"
	}
	s = s + "</tr>"
	return s;
}
function PrevNextHtml_1(titPrev, titNext, titUp) {
	var s = "<colgroup>"
	    s = s + "<col align='center' width='33%'><col align='center' width='33%'><col align='center' width='33%'>"
	    s = s + "</colgroup><tr>"

	if(gPathIDs[0].length>0) {
		s = s + "<td><a href='" + gPathHrefs[0] + "' class='PrevNext'>" + titPrev + "</a></td>"
	}
	else {
		s = s + "<td>" + titPrev + "</td>"
	}

	if(gPathIDs.length>3) {
		s = s + "<td><a href='" + gPathHrefs[3] + "' class='PrevNext'>" + titUp + "</a></td>"
	}
	else {
		s = s + "<td>" + titUp + "</td>"
	}

	if(gPathIDs[1].length>0) {
		s = s + "<td><a href='" + gPathHrefs[1] + "' class='PrevNext'>" + titNext + "</a></td>"
	}
	else {
		s = s + "<td>" + titNext + "</td>"
	}
	s = s + "</tr>"
	return s;
}
function PrevNextHtml_2(titPrev, titNext, titUp) {
	var s = "<colgroup>"
	    s = s + "<col align='center' width='50%'><col align='center' width='50%'>"
	    s = s + "</colgroup><tr>"

	if(gPathIDs[0].length>0) {
		s = s + "<td><a href='" + gPathHrefs[0] + "'>"
		s = s + "<img border='0' width='30' height='30' src='" + window.StyleImgUrl("prev.gif") + "'"
		s = s + "alt='" + titPrev + ":" + gPathNames[0] + "' />"
		s = s + "</a></td>"
	}
	else {
		s = s + "<td><img width='30' height='30' src='" + window.ImagesUrl("c.gif") + "'></td>"
	}

	if(gPathIDs[1].length>0) {
		s = s + "<td><a href='" + gPathHrefs[1] + "'>"
		s = s + "<img border='0' width='30' height='30' src='" + window.StyleImgUrl("next.gif") + "'"
		s = s + "alt='" + titNext + ":" + gPathNames[1] + "' />"
		s = s + "</a></td>"
	}
	else {
		s = s + "<td><img width='30' height='30' src='" + window.ImagesUrl("c.gif") + "'></td>"
	}
	s = s + "</tr>"
	return s;
}
function PrevNextHtml_3(titPrev, titNext, titUp) {
	var s = "<colgroup>"
	    s = s + "<col align='left' width='33%'><col align='center' width='33%'><col align='right' width='33%'>"
	    s = s + "</colgroup><tr>"

	if(gPathIDs[0].length>0) {
		s = s + "<td><a href='" + gPathHrefs[0] + "'>"
		s = s + "<img border='0' width='30' height='30' src='" + window.StyleImgUrl("prev.gif") + "'"
		s = s + "alt='" + titPrev + ":" + gPathNames[0] + "' />"
		s = s + "</a></td>"
	}
	else {
		s = s + "<td><img width='30' height='30' src='" + window.ImagesUrl("c.gif") + "'></td>"
	}

	if(gPathIDs.length>3) {
		s = s + "<td><a href='" + gPathHrefs[3] + "'>"
		s = s + "<img border='0' width='30' height='30' src='" + window.StyleImgUrl("goup.gif") + "'"
		s = s + "alt='" + titUp + ":" + gPathNames[3] + "' />"
		s = s + "</a></td>"
	}
	else {
		s = s + "<td><img width='30' height='30' src='" + window.ImagesUrl("c.gif") + "'></td>"
	}

	if(gPathIDs[1].length>0) {
		s = s + "<td><a href='" + gPathHrefs[1] + "'>"
		s = s + "<img border='0' width='30' height='30' src='" + window.StyleImgUrl("next.gif") + "'"
		s = s + "alt='" + titNext + ":" + gPathNames[1] + "' />"
		s = s + "</a></td>"
	}
	else {
		s = s + "<td><img width='30' height='30' src='" + window.ImagesUrl("c.gif") + "'></td>"
	}
	s = s + "</tr>"
	return s;
}

function BodyOnload() {
	if(parent.IsInOnlineEdit)
		parent.CurNodeChanged(gPathIDs[2]);

	for(var i=0;i<OnloadFns.length;i++) { eval(OnloadFns[i]); }
}
function AddBodyOnloadFn(fnName) {
	OnloadFns[OnloadFns.length]=fnName+"()";
}
function ChkIsArctive(nodeID) {
	if(nodeID=="root") {
		if(gPathIDs[2]==nodeID)
			return true;
		else
			return false;
	}
	else {
		for(var i=2;i<gPathIDs.length;i++) {
			if(gPathIDs[i]==nodeID) 
				return true;
		}
		return false;
	}
}
function showBriefDesc(id)
{	
	Menu_num = document.all(id);
	
	var rightedge = document.body.clientWidth-event.clientX; 
	var bottomedge = document.body.clientHeight-event.clientY; 
	
	if (rightedge < Menu_num.offsetWidth) 
		Menu_num.style.left = document.body.scrollLeft + event.clientX - Menu_num.offsetWidth;
	else
		Menu_num.style.left = document.body.scrollLeft + event.clientX + 10; 
	
	if (bottomedge < Menu_num.offsetHeight) 
		Menu_num.style.top = document.body.scrollTop + event.clientY - Menu_num.offsetHeight; 
	else 
		Menu_num.style.top = document.body.scrollTop + event.clientY + 10; 
	
	document.all(id).style.visibility = "visible";	
}

function hiddenBriefDesc(id) {
	document.all(id).style.visibility = "hidden";
}
/////////////////////////// 分页控制 ///////////////////////
function wtPageCtl(divID, pgCount, pgSize, itemCount, barFlag1, barClass1, barFlag2, barClass2)
{
this.divID	= divID;
this.pgCount	= pgCount;
this.pgSize	= pgSize;
this.itemCount	= itemCount;
this.barFlag1	= barFlag1
this.barFlag2	= barFlag2
this.barClass1	= barClass1
this.barClass2	= barClass2
this.curPg	= 1;
this.ShowPage	= wtPageCtl_ShowPage;
this.ShowBar	= wtPageCtl_ShowBar;
}
function wtPageCtl_ShowPage(pgIdx) {
	with (this) {
		if(curPg != pgIdx) {
			window.document.getElementById(divID+'_P'+curPg).style.display="none";
			curPg = pgIdx;
			window.document.getElementById(divID+'_P'+curPg).style.display="";
		}
	
		ShowBar(1, barFlag1, barClass1);
		ShowBar(2, barFlag2, barClass2);
	}
}
function wtPageCtl_ShowBar(barIdx, barFlag, barClass) {
	var s = ""
	with (this) {
		if(barFlag>0) {
			s = "<p class='" + barClass + "'>"
			if(barFlag>1) {
				s = s + "共有" + itemCount + "条记录，"
					+ "每页" + pgSize + "条，"
					+ "共" + pgCount + "页，"
					+ "当前第" + curPg + "页 ";
			}
		
			if(curPg>1)
				s = s + "<a href='#' value='上一页' onclick='"
					+ divID + "_PageCtl.ShowPage(" + (curPg-1) + ")'>"
					+ "上一页</a>";
			else
				s = s + "上一页";

			if(barFlag>2) {
				s = s + " ["
				for(var i=1;i<=pgCount;i++) {
					if(i==curPg)
						s = s + " " + i;
					else
						s = s + " "
						  + "<a href='#' onclick='"
						  + divID + "_PageCtl.ShowPage("
						  + i + ");'>" + i + "</a>";
				}
				s = s + " ]"
			}

			if(curPg<pgCount)
				s = s + " <a href='#' onclick='"
					+ divID + "_PageCtl.ShowPage(" + (curPg+1) + ")'>"
					+ "下一页</a>";
			else
				s = s + " 下一页";

			s = s + "</p>"
		}
		window.document.getElementById(divID+'_PageBar'+barIdx).innerHTML=s;
	}
}
