//-------------------------------------------------------------------------------
// Language:
//	JavaScript
// Desciption:
//	Header & Footer
//	Goto Top string
//	Goto Latest Topics string
// History:
//	2003/10/08	Add BarStyle attribute and change the logic belong to BarStyle.
//		Added 7th parameter "barstyle" to the constructor.
//		Added setBarStyle() mothod.
//-------------------------------------------------------------------------------

//-------------------------------------------------------------------------------
// Description:
//	Header & Footer title bar
//	It is assumed that the object of this function is created only 1 in a HTML file.
// Classes:
//	titleBar()
//	titleBar.header()
//	titleBar.footer()
//	...
// Usage in HTML:
//		var title = new titleBar(...);		// create object
//		...
//		title.header();
//		title.footer();
//-------------------------------------------------------------------------------

//---[class]---------------------------------------------------------------------
function titleBar(
// Following parameters are handled by the constructor.
//	title,		// optional: header title; Title at the left side = <any string>
//	linktype,	// optional: link type = "forward", "back", "update", "close", "none" or "" (same as none)
//	linkfile,	// optional: href file = "<file name>" or ""
//	linktitle,	// optional: link title; Link title at the right side = <any string> or "" (used default string, such as "Enter", "Back"
//	target,		// optional: target frame name; "<any>"
//	dispstyle,	// header/footer display style; "normal", "noheader", "nofooter"
//	barstyle	// header/footer bar style such as colors; "default", "close"
)
{

	//---[set parameters: private static]---
	// set defaults
	var title = "";		// header title; Title at the left side = <any string>
	var linktype = "";	// link type = "forward", "back", "update", "close", "none" or "" (same as none)
	var linkfile = "";	// href file = <file name> or ""
	var linktitle = "";	// link title; Link title at the right side = <any string> or "" (used default string, such as "Enter", "Back"
	var target = "";	// target frame name
	var dispstyle = "";	// header/footer display style; normal, noheader, nofooter
	var barstyle = "";	// header/footer bar style such as colors

	// set parameters to variables
	switch (arguments.length) {
	case 7:
		barstyle = arguments[6];
		// go through; not break
	case 6:
		dispstyle = arguments[5];
		// go through; not break
	case 5:
		target = arguments[4];
		// go through; not break
	case 4:
		linktitle = arguments[3];
		// go through; not break
	case 3:
		linkfile = arguments[2];
		// go through; not break
	case 2:
		linktype = arguments[1];
		// go through; not break
	case 1:
		title = arguments[0];
		break;
	case 0:
	default:
		break;
	}

	var arrowchar = "";
	var targetattr = "";
	var linkclassattr = "";

	setParameter();


	//---[inner func]-----------------------------------------------------------------
	// Initialization.
	//--------------------------------------------------------------------------------
	function setParameter()
	{
		// Set dispstyle.
		// parameter value check and set defaults if required
		switch (dispstyle) {
		case "normal":
		case "noheader":
		case "nofooter":
			// good value
			break;
		default:
			dispstyle = "normal";	// set default
			break;
		}

		// Set linktype.
		switch (linktype) {
		case "forward":
		case "back":
		case "update":
		case "close":
		case "none":
			// good value
			break;
		default:
			linktype = "none";
			break;
		}

		// Set targetattr.
		if (target != "") {
			targetattr = "target=\"" + target + "\" ";
		} else {
			targetattr = "";
		}

		// Set linkclassattr, arrowchar, linktitle, linkfile.
		linkclassattr = "back";
		switch (linktype) {
		case "close":	// Close window
			arrowchar = "&#253;";
			linkclassattr = "close";
			if (linktitle == "") {
				linktitle = "Close";
			}
			linkfile = "javascript:window.close();";
			targetattr = "";
			break;
		case "back":	// Back or Forward
			arrowchar = "&#219;";
			if (linktitle == "") {
				linktitle = "Back";
			}
			break;
		case "forward":
			arrowchar = "&#220;";
			if (linktitle == "") {
				linktitle = "Enter";
			}
			break;
		default:
			break;
		}

		// Set barstyle.
		// header/footer bar style
		switch (barstyle) {
		case "close":
		case "default":
			// good value
			break;
		case "":	// set default value.
		default:	// if something is specified, but it's an invalid value.
			switch (linktype) {
			case "close":
				barstyle = "close";	// "close" window color
				break;
			case "back":
			case "forward":
			case "update":
			case "none":
			default:
				barstyle = "default";	// normal window color
				break;
			}
			break;
			break;
		}
	}


	//---[inner func]-----------------------------------------------------------------
	// Write the core <tbody> part of main header/footer title.
	function titleMainStr()
	{
		// draw the title and set the style.
		switch (barstyle) {
		case "close":	// Close window
			document.write("<tr><td class=\"page-header-main-left-close\">" + title + "</td>");
			document.write("<td class=\"page-header-main-right-close\">");
			break;
		case "default":
		default:
			document.write("<tr><td class=\"page-header-main-left\">" + title + "</td>");
			document.write("<td class=\"page-header-main-right\">");
			break;  
		}

		// draw the link part.
		switch (linktype) {
		case "back":	// Back
		case "forward":	// Forward
		case "close":	// Close window
			document.write("<a class=\"" + linkclassattr + "\" href=\"" + linkfile + "\" " + targetattr
				+ " onmouseover=\"status='';return true;\" onmouseout=\"status='';return true;\">");
			document.write("<span style=\"font-family: 'Wingdings'\">" + arrowchar + "</span> " + linktitle + "</a>");
			break;
		case "update":	// Draw date of update
			var lmdate = new Date(document.lastModified);
			document.write("Updated : " + lmdate.getYear() + "/");
			document.write(lmdate.getMonth() + 1);
			document.write("/" + lmdate.getDate());
			break;
		case "none":
		default:	// none
			document.write("&nbsp;");
			break;
		}

		document.write("</td></tr>");

	}


	//---[inner func]-----------------------------------------------------------------
	// Write header.
	function headerBar()
	{
		var style_main_left;
		var style_main_right;
		var style_sub1;
		var style_sub2;

		// draw the main bar.
		switch (dispstyle) {
		case "noheader":
			document.write("<div id=\"page-top\"></div>");	// <div> for ID tag
			break;
		case "nofooter":
		case "normal":
		default:
			// main header line
			document.write("<div><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" id=\"page-top\"><tbody>");
			titleMainStr();
			document.write("</tbody></table></div>");
			break;
		}

		// draw inner header bars
		switch (barstyle) {
		case "close":
			switch (dispstyle) {
			// !! not implemented !!	
			//case "noheader":
			//	break;
			//case "nofooter":
			//	break;

			case "normal":
			default:
				document.write("<div class=\"page-header-sub1-close\">");
				document.write("<div class=\"page-header-sub2-close\">");
				break;
			}
			break;
		case "default":
		default:
			switch (dispstyle) {
			case "noheader":
				document.write("<div class=\"page-header-sub1-noheader\">");
				document.write("<div class=\"page-header-sub2-noheader\">");
				break;
			case "nofooter":
				document.write("<div class=\"page-header-sub1-nofooter\">");
				document.write("<div class=\"page-header-sub2-nofooter\">");
				break;
			case "normal":
			default:
				document.write("<div class=\"page-header-sub1\">");
				document.write("<div class=\"page-header-sub2\">");
				break;
			}
			break;
		}

	}


	//---[inner func]-----------------------------------------------------------------
	// Write footer.
	function footerBar()
	{
		// write inner footer bar sub2/sub1
		document.write("</div></div>");
		// write main footer bar
		switch (dispstyle) {
		case "nofooter":
			// no footer
			document.write('<div id="page-bottom"></div>');	// <div> for ID tag
			break;
		case "noheader":
		case "normal":
		default:
			// main header line
			document.write("<div><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" id=\"page-bottom\"><tbody>");
			titleMainStr();
			document.write("</tbody></table></div>");
			break;
		}
	}


	//--------------------------------------------------------------------------------
	//	Configuration methods
	//--------------------------------------------------------------------------------

	//---[method]---------------------------------------------------------------------
	// Configure left title.
	function setTitle(str)
	{
		title = str;
		setParameter();
	}
	titleBar.prototype.setTitle = setTitle;

	//---[method]---------------------------------------------------------------------
	// Configure link file (href of <a>).
	function setLinkFile(str)
	{
		linkfile = str;
		setParameter();
	}
	titleBar.prototype.setLinkFile = setLinkFile;

	//---[method]---------------------------------------------------------------------
	// Configure link type.
	function setLinkType(str)
	{
		linktype = str;
		setParameter();
	}
	titleBar.prototype.setLinkType = setLinkType;

	//---[method]---------------------------------------------------------------------
	// Configure link title.
	function setLinkTitle(str)
	{
		linktitle = str;
		setParameter();
	}
	titleBar.prototype.setLinkTitle = setLinkTitle;

	//---[method]---------------------------------------------------------------------
	// Configure target frame.
	function setTarget(str)
	{
		target = str;
		setParameter();
	}
	titleBar.prototype.setTarget = setTarget;

	//---[method]---------------------------------------------------------------------
	// Configure "no header".
	function setNoHeader()
	{
		dispstyle = "noheader";
	}
	titleBar.prototype.setNoHeader = setNoHeader;

	//---[method]---------------------------------------------------------------------
	// Configure "no footer".
	function setNoFooter()
	{
		dispstyle = "nofooter";
	}
	titleBar.prototype.setNoFooter = setNoFooter;

	//---[method]---------------------------------------------------------------------
	// Configure "header/footer bar style".
	function setBarStyle(str)
	{
		barstyle = str;
	}
	titleBar.prototype.setBarStyle = setBarStyle;


	//--------------------------------------------------------------------------------
	//	Action (Drawing) methods
	//--------------------------------------------------------------------------------

	//---[method]---------------------------------------------------------------------
	// Write header.
	function header()
	{
		headerBar();
	}
	titleBar.prototype.header = header;

	//---[method]---------------------------------------------------------------------
	// Write footer.
	function footer()
	{
		footerBar();
	}
	titleBar.prototype.footer = footer;

}


