package net.sourceforge.jsurveyor.tags;

import java.io.*;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.*;

/**
 * Custom tag that inserts the main design on a page
 * @version 1.0
 * @author Claus Methmann Christensen
 * @author Anders Spliid Hansen
 * @author Esben Iversen Hansen
 * @author Lars H Jensen
 * @author Marcus Overheu
 * @author Thomas Ramdal
 * @author Peter Thomsen
 */
public class MainDesignTag extends TagSupport {

	/**
	 * Field title
	 */
	private String title = "jSurveyor";


	/**
	 *  Automatically captures the attribute title when using the tag.
	 * @param title String
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * 
	 * Automatically called when starting the tag.
	 * Inserts the first part of the design and continues to evaluate any included body with the tag.
	 * @return int
	 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
	 * 
	 */
	public int doStartTag() {
		try {
			JspWriter out = pageContext.getOut();
			out.println(
				"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
			out.println(
				"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML Strict 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
			out.println(
				"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">");
			out.println("<head>");
			out.println(
				"<link rel='stylesheet' href='css_jsurveyor.css' />");
			out.println("<title>" + title + "</title>");
			out.println("</head>");
			out.println("<body>");
			out.println("<table border='0'>");
			out.println("<tr> <!-- Top menu start -->");
			out.println("<td class='topmenu' colspan='3'>");
			out.println(
				"<table border='0' cellpadding='0' cellspacing='0'>");
			out.println("<tr>");
			out.println("<td align='left' style='padding-left:20px;'><img src='pics/jsurveyor_logo2.png' alt='Logo' title='Jsurveyor logo' border='0' /></td>");
			out.println(
				"<td align='right' style='padding-right:20px;'><input class='stdbutton_long' type='button' value='Log out' title='Click to log out' onClick=\"location.href='logout.jsp'\" /'></td>");
			out.println("</tr>");
			out.println("</table>");
			out.println("</td>");
			out.println("</tr>");
			out.println("<tr>");
			out.println("<td></td>");
			out.println("<td class='mainmenu'>");
			out.println(
				"<table border='0' cellspacing='0' cellpadding='0'>");

		} catch (IOException e) {
		} //ignored
		return EVAL_BODY_INCLUDE;
	}

	/**
	 * Automatically called when closing the tag.
	 * Inserts the second part of the design after evaluating the body of the tag
	 * @return int
	 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
	 * 
	 */
	public int doEndTag() {
		try {
			JspWriter out = pageContext.getOut();
			out.println("</table>");
			out.println("</td>");
			out.println("<td></td>");
			out.println("</tr>");
			out.println("<tr>");
			out.println(
				"<td colspan='3' class='bottommenu'>&nbsp;</td>");
			out.println("</tr>");
			out.println("</table>");
			out.println("</body>");
			out.println("</html>");

		} catch (IOException e) {
		} // ignored
		return EVAL_PAGE;
	}

}