<%@ page
    language="java"
    contentType="text/html;charset=utf-8"
%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.sword.orb.*" %>
<%@ page import="org.crosswire.utils.HTTPUtils" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="java.net.URLEncoder" %>
<%

	final int VERSEKEY_TESTAMENT  = 0;
	final int VERSEKEY_BOOK       = 1;
	final int VERSEKEY_CHAPTER    = 2;
	final int VERSEKEY_VERSE      = 3;
	final int VERSEKEY_CHAPTERMAX = 4;
	final int VERSEKEY_VERSEMAX   = 5;
	final int VERSEKEY_BOOKNAME   = 6;
	final int VERSEKEY_OSISREF    = 7;
	final int VERSEKEY_SHORTTEXT  = 8;
	final int VERSEKEY_BOOKABBREV = 9;

	SWMgr mgr = SwordOrb.getSWMgrInstance(request);
	SWModule book = null;
	String modName = request.getParameter("mod");
	String ks = request.getParameter("key");
	boolean includeRenderHeader = "true".equals(request.getParameter("includeRenderHeader"));

	if (ks != null && !"betacode".equals(modName)) {
		ks = new String(ks.getBytes("iso8859-1"), "UTF-8");
	}
//System.out.println("****");
//System.out.println("ks: " + ks);
//	if (ks != null) ks = new String(ks.getBytes("iso8859-1"), "UTF-8");
	String fn = request.getParameter("fn");
	String format = request.getParameter("format");
	boolean pages = "true".equals(request.getParameter("pages"));

	String footnotes = request.getParameter("footnotes");
	footnotes = (!"On".equals(footnotes)) ? "Off" : "On";
	mgr.setGlobalOption("Footnotes", footnotes);

	mgr.setGlobalOption("Cross-references", "Off");

//System.out.println("****");
	String inTestament = null;
	String inBook = null;
	String inChapter = null;
	String inVerse = null;

	if ("plain".equals(format)) {
		mgr.setGlobalOption("Strong's Numbers", "Off");
		mgr.setGlobalOption("Morphological Tags", "Off");
	}
	if ("tei".equals(format) && "LXXCATSS".equals(modName)) {
		mgr.setGlobalOption("Greek Accents", "Off");
	}

	String mods[] = new String[0];
	if (modName != null) {
		mods = modName.split("\\|");
	}

	if (ks != null) {
		String parts[] = ks.split("\\|");
		for (int i = 0; i < parts.length; i++) {

			if (i < mods.length) modName = mods[i];

			String key = parts[i];

			if ("betacode".equals(modName)) {
//				key = new String(key.getBytes("iso8859-1"), "UTF-8");
			}

			if (i > 0) out.print("<br/>__________________<br/><br/>");
			// hack until LXXM morph is cleaned up -----
			if ("Packard".equals(modName)) {
				while (key.indexOf("  ") > -1) key = key.replaceAll("  ", " ");
			}
			// end of LXXM Packard hack ----------------
			if ("ls".equals(modName)) {
				SWModule greekLemma = mgr.getModuleByName("GreekStrongToLem");
				greekLemma.setKeyText(key);
				key = greekLemma.getRawEntry();
				modName = "betacode";
			}

			// ------ betacode lookup from perseus ------------------------------------------------
			if ("betacode".equals(modName)) {
//System.out.println("Perseus Lookup: " + key);
				String ls = org.crosswire.swordweb.PerseusUtils.getLiddellScottDef(key);
//System.out.println("Perseus returned: " + ls);
				if (ls.length() > 0) {
%>
					<%= ls %>
					<div class="copyLine">from Liddell and Scott, <i>An Intermediate Greek-English Lexicon</i><br/>
					Courtesy of <a href="//www.perseus.tufts.edu">Perseus Digital Library</a></div>
<%
				}
				else {
%>
					<h2><span class="verse"><%= key %></span></h2>
<%
				}
			}

			// ------ Textual Evidence Lookup from INTF ---------------------------------------------

			else if ("TC".equals(modName)) {
				String srcMod = request.getParameter("srcMod");
				String activeKey = (String)session.getAttribute("ActiveKey");
				if (srcMod != null) {
					book = mgr.getModuleByName(srcMod);
				}
//System.out.println("book:" + book+ ";key="+key+"activeKey:"+activeKey);
				if ((key != null) && (book != null) && activeKey != null) {
					try {
						Integer.parseInt(key);	// assert we have only an int and need to get our book and chapter from session
						String activeChapter = activeKey.substring(0, activeKey.indexOf(":"));
						activeKey = activeChapter+"."+key;
					}
					catch (Exception e) { activeKey = key; } // not an error, just hopefully have entire versekey already
					String vk[] = book.parseKeyList(activeKey);
					activeKey=vk[0];
					StringBuffer vmrResponse = HTTPUtils.postURL("https://ntvmr.uni-muenster.de/community/vmr/api/metadata/liste/search/", "biblicalContent="+activeKey+"&detail=page&limit=40");
//System.out.println("**** response: " + vmrResponse);
					XMLBlock manuscripts = new XMLBlock(vmrResponse.toString());
%>
					<p><b>Some Manuscript Witnesses for <%=vk[0]%></b></p>
					<div id="tableContainer" class="tableContainer" style="width:100%;">
					<table border="0" cellpadding="0" cellspacing="0" style="width:100%;" class="scrollTable">
					<thead class="fixedHeader">
						<tr style="font-size:80%;"><th>Ms</th><th>Century</th><th>Folio</th><th>Content</th><th>&nbsp;</th></tr>
					</thead>
					<tbody class="scrollContent">
<%
					for (XMLBlock m : manuscripts.getBlocks("manuscript")) {
						for (XMLBlock p : m.getBlock("pages").getBlocks("page")) {
							String thumbURL = null;
							String imageURL = null;
							String transURL = null;
							XMLBlock block = p.getBlock("images");
							if (block != null) {
								block = block.getBlock("image");
								if (block != null) {
									thumbURL = block.getAttribute("thumbURL");
									imageURL = block.getAttribute("webFriendlyURL");
								}
							}
							block = p.getBlock("transcriptions");
							if (block != null) {
								block = block.getBlock("transcription");
								if (block != null) {
									transURL = block.getAttribute("uri");
								}
							}
							String mssURL = "//ntvmr.uni-muenster.de/manuscript-workspace?docID=" + m.getAttribute("docID")+"&pageID="+p.getAttribute("pageID");
%>
							<tr>
								<td><a href="<%=mssURL%>" target="NTVMR">
									<%=m.getAttribute("gaNum")%>
								</a></td>
								<td><%=m.getValue("originYear")%></td>
								<td><%=p.getAttribute("folio")%></td>
								<td>
<%
							if (transURL != null) {
%>
									<a href="#" onclick="window.open('<%=transURL%>','ViewTranscription','width=500,height=600,resizable=1,scrollbars=1');return false;">
<%
							}
%>
										<%=p.getAttribute("biblicalContent")%>
<%
							if (transURL != null) {
%>
									</a>
<%
							}
%>
								</td><td>
<%
							if (imageURL != null) {
%>
									<a href="<%=mssURL%>" target="NTVMR">
<%
							}
							if (thumbURL != null) {
%>
										<img width="50px" src="<%=thumbURL%>"/>
<%
							}
							if (imageURL != null) {
%>
										</a>
<%
							}
%>
								</td></tr>
<%
						}
					}
%>
						</tbody>
						</table>
						</div>
						<div class="copyLine"><br/>This dataset is by no means exhaustive and is growing rapidly. Check back soon for more results.<br/><br/>Courtesy of <a href="//egora.uni-muenster.de/intf/index_en.shtml">Institut für Neutestamentliche Textforschung</a></div>
<%
				}
			}

			// normal SWORD mod lookup
			else {
				if (modName != null) {
					book = mgr.getModuleByName(modName);
				}
				if ((key != null) && (book != null)) {

					if ("RenderHeader".equals(key)) {
						out.print(book.getRenderHeader());
						return;
					}
					if (includeRenderHeader) {
%>
<style>
<%=book.getRenderHeader()%>
.verse_number::before {
  content: ' ';
}
.verse_number::after {
  content: attr(data-suggested);
	font-size: 0.8em;
	width:3em;
	color:navy;
	vertical-align:top;
}
</style>
<%
					}
					String keyList[] = SwordOrb.BIBLES.equals(book.getCategory())?book.parseKeyList(key) : new String[] { key };
//System.out.println(key);
//System.out.println(keyList[0]);
					
					if ("json".equals(format)) {
						response.setContentType("application/json");
						out.print("{ \"result\": [ ");
					}
					if ("raw".equals(format)) {
						response.setContentType("text/plain");
					}
					if ("tei".equals(format)) {
						response.setContentType("text/xml");
%>
<TEI>
<%
						if (keyList.length > 0) {
							book.setKeyText(keyList[0]);
						}
						else {
%>
<div>
<div>
<%
						}
					}

					// shift subscriptio to the end
					boolean lastInscriptio = false;
					String subscriptio = null;
					if (keyList.length > 0 && SwordOrb.BIBLES.equals(book.getCategory())) {
						String curBook = "";
//System.out.println("***** cleaning up in/subsriptios");
						for (int k = 0; k < keyList.length; ++k) {
							String keyParts[] = keyList[k].split("\\.");
							String thisBook = keyParts[0];
//System.out.println("Key: " + keyList[k] + "; thisBook: " + thisBook + "; keyParts.length: " + keyParts.length + "; lastInscription: " + lastInscriptio);

							if (subscriptio != null && thisBook != curBook) {
								keyList[k-1] = subscriptio;
								subscriptio = null;
								curBook = thisBook;
							}
							if (keyParts.length == 2 && "1".equals(keyParts[1])) {
//System.out.println("Scriptio found ("+k+"): " + keyList[k]);
								if (lastInscriptio) keyList[k] = null;
								else subscriptio = keyList[k];
							}
							lastInscriptio = (keyParts.length == 1);
							if (subscriptio != null && k < keyList.length-1) {
								keyList[k] = keyList[k+1]; 
							}
							curBook = thisBook;
/* shift first to end
							String start = keyList[0];
							System.arraycopy(keyList, 1, keyList, 0, keyList.length - 1);
							keyList[keyList.length - 1] = start;
*/
						}
						if (subscriptio != null) keyList[keyList.length-1] = subscriptio;
//System.out.println("===== finished cleaning up in/subsriptios");
					}


					String lastBook = "";
					String lastChapter = "";
					String lastShownPBN = "";
					for (int k = 0; k < keyList.length; ++k) {
						String k1 = keyList[k];
						if (k1 == null) continue;
						
						// kludge for verse 0 which comes out to e.g., "Rev.2"
						if (k1.split("\\.").length == 2 && SwordOrb.BIBLES.equals(book.getCategory())) {
							// magic '=' prefix turns on intros
							k1 = "=" + k1 + ".0";
//							continue;	// just skip chapter headings
						}
						else if (k1.split("\\.").length == 1 && SwordOrb.BIBLES.equals(book.getCategory())) {
							k1 = "=" + k1 + ".0.0";
//							continue;	// just skip chapter headings
						}
//System.out.println("key: " + k1);
						book.setKeyText(k1);
						String keyChildren[] = book.getKeyChildren();
						String nowTestament = keyChildren.length > VERSEKEY_TESTAMENT ? keyChildren[VERSEKEY_TESTAMENT] : "";
						String nowBook = keyChildren.length > VERSEKEY_BOOK ? keyChildren[VERSEKEY_BOOK] : "";
						String nowChapter = keyChildren.length > VERSEKEY_CHAPTER ? keyChildren[VERSEKEY_CHAPTER] : "";
						String nowVerse = keyChildren.length > VERSEKEY_VERSE ? keyChildren[VERSEKEY_VERSE] : "";
						String nowBookAbbrev = keyChildren.length > VERSEKEY_BOOKABBREV ? keyChildren[VERSEKEY_BOOKABBREV] : "";
						String nowBookName = keyChildren.length > VERSEKEY_BOOKNAME ? keyChildren[VERSEKEY_BOOKNAME] : "";
						String nowOSISRef = keyChildren.length > VERSEKEY_OSISREF ? keyChildren[VERSEKEY_OSISREF] : "";
						boolean hasEntry = book.getRawEntry().length() > 0;
						// skip empty incipits and explicits
						if (nowVerse.equals("0") && !hasEntry) {
							continue;
						}
//System.out.println("book key: " + book.getKeyText());
						if (("StrongsGreek".equals(modName)) && ("3588".equals(k1))) {
							out.print("with Greek Article");
						}
						else if (fn != null) {
							try {
								String[] type = book.getEntryAttribute("Footnote", fn, "type", false);
								if ((type.length > 0) && type[0].equalsIgnoreCase("crossReference")) {
									String[] attr = book.getEntryAttribute("Footnote", fn, "refList", false);
									if (attr.length > 0) {
										String[] keys = book.parseKeyList(attr[0]);
										if (keys.length > 0) {
											out.print("<dl>");
											for (int j = 0; j < keys.length; j++) {
												book.setKeyText(keys[j]);
												out.print("<dt><a href=\"passagestudy.jsp?key=" + URLEncoder.encode(book.getKeyText())+"#cv\">" + book.getKeyText() + "</a></dt><dd>" + book.getRenderText()+"</dd>\n");
											}
											out.print("</dl>");
										}
									}
								}
								else {
									String[] attr = book.getEntryAttribute("Footnote", fn, "body", true);
									if (attr.length > 0) {
										out.print(attr[0]);
									}
								}
							}
							catch (Exception e) { e.printStackTrace(); }
						}
						else {
							if ("raw".equals(format) || "tei".equals(format)) {
								// ----- header for trier tinymce editor ------
								if ("tei".equals(format)) {
									if (inChapter != null && (!nowChapter.equals(inChapter) || !nowBook.equals(inBook) || nowVerse.equals("0"))) {
	if (!"0".equals(inChapter)) {
%>
</div>
<%
	}
									}
									if (inBook != null && !nowBook.equals(inBook)) {
%>
</div>
<%
									}
									if (!nowBook.equals(inBook)) {
										if (pages) {
											int t = Integer.parseInt(nowTestament);
											int b = Integer.parseInt(nowBook);
											int c = Integer.parseInt(nowChapter);
											if (b == 0) b = 1;
											if (c == 0) c = 1;
											String n = String.format("%d%03d%03d000", t, b, c);
											if (!n.equals(lastShownPBN)) {
	%>
	<pb n="<%=nowBookName + " " + c%>" osisID="<%=nowBookAbbrev + "." + c%>" pageID="<%=n%>" type="chapter"/>
	<%
												lastShownPBN = n;
											}
										}
%>
<div type="book" n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>" osisID="<%=nowBookAbbrev%>">
<%
									}
									if (!nowChapter.equals(inChapter) || !nowBook.equals(inBook) || nowVerse.equals("0")) {
										if (!nowVerse.equals("0")) {
											int t = Integer.parseInt(nowTestament);
											int b = Integer.parseInt(nowBook);
											int c = Integer.parseInt(nowChapter);
											if (b == 0) b = 1;
											if (c == 0) c = 1;
											if (pages) {
												String n = String.format("%d%03d%03d000", t, b, c);
												if (!n.equals(lastShownPBN)) {
%>
<pb n="<%=nowBookName + " " + c%>" osisID="<%=nowBookAbbrev + "." + c%>" pageID="<%=n%>" type="chapter"/>
<%
													lastShownPBN = n;
												}
											}
%>
<div type="chapter" n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>K<%= nowChapter %>" osisID="<%=nowBookAbbrev + "." + c%>">
<%
										}
									}
									inChapter = nowChapter;
									inBook = nowBook;
									if (nowVerse.equals("0")) {
										inChapter = "0";
										if (nowChapter.equals("0")) {
%><div type="incipit" n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>incipit" osisID="<%=nowOSISRef%>"><ab><%
										}
										else if (nowChapter.equals("1")) {
%><div type="explicit" n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>explicit" osisID="<%=nowOSISRef%>"><ab><%
										}
									}
									else {
%>
<ab n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>K<%= nowChapter %>V<%= nowVerse %>" osisID="<%=nowOSISRef%>">
<%
									}
								}
								// --------------------------------------------
									if (!"raw".equals(format) && ("WHNU".equals(modName) || "WLC".equals(modName) || "LXX".equals(modName) || "Vulgate".equals(modName))) {
%>
<%= book.getStripText() %>
<%
									}
									else if ("LXXCATSS".equals(modName) || "Aleppo".equals(modName)) {
										String raw = book.getStripText();
										raw = mgr.filterText("OSISPlain", raw);
//										raw = mgr.filterText("UTF8GreekAccents", raw);
										while (raw.indexOf("\n") > -1) raw = raw.replaceAll("\n", " ");
										while (raw.indexOf("\r") > -1) raw = raw.replaceAll("\r", " ");
										while (raw.indexOf("  ") > -1) raw = raw.replaceAll("  ", " ");
										out.print(raw);
									}
									else if (!"raw".equals(format) && "ThML".equals(book.getConfigEntry("SourceType"))) {
										mgr.setGlobalOption("Strong's Numbers", "Off");
										mgr.setGlobalOption("Morphological Tags", "Off");
										book.getRenderText();
										String raw = book.getRenderText();
//										raw = mgr.filterText("ThMLPlain", raw);
%>
<%= raw %>
<%
									}
									else if ("tei".equals(format)) {
										String t = book.getRawEntry();
										t = t.replaceAll("x-preverse\"/", "x-preverse\"");
										if ("Off".equals(footnotes)) {
											t = t.replaceAll("<note[^>]*[^/]>.*</note>", "");
											t = t.replaceAll("<note[^>]*/>", "");
											t = t.replaceAll("<note[^>]*>", "");
											t = t.replaceAll("<ab [^>]*>", "");
											t = t.replaceAll("</ab>", "");
											t = t.replaceAll("</note>", "");
											t = t.replaceAll("<hi[^>]*>", "");
											t = t.replaceAll("</hi>", "");
											t = t.replaceAll("<s [^>]*>", "");
											t = t.replaceAll("</s>", "");
											t = t.replaceAll("</w>([>:;,'ʼ˙··.\u2014\u2027])", "</w><pc>$1</pc>");
											// if we're adding our own chapter <pb /> markers, then remove any <pb /> tags in the text
											if (pages) {
												t = t.replaceAll("<pb[^>]*/>", "");
											}
										}
%>
<%= t %>
<%
									}
									else {
%>
<%= book.getRawEntry() %>
<%
									}
								// ----- header for trier tinymce editor ------
								if ("tei".equals(format)) {
									if (nowVerse.equals("0")) {
										if (nowChapter.equals("0") || nowChapter.equals("1")) {
%></ab></div><%
										}
									} else {
%></ab><%
									}
								}
								// --------------------------------------------
							}
							else {


								// ----- header for trier tinymce editor ------
								if ("basetext".equals(format)) {
%>
<span class="chapter_number" part="<%=("1".equals(nowVerse))?"I":"Y"%>"> <%= nowChapter %></span>
<%
%>
<span class="verse_number"> <%= nowVerse %></span>
<%
								}
								if ("strip".equals(format)) {
									mgr.setGlobalOption("Greek Accents", "Off");
									String raw = book.getStripText();
									raw = raw.replaceAll("\\*", " ");
									raw = raw.replaceAll("  ", " ");
									raw = raw.replaceAll("  ", " ");
									raw = raw.replaceAll("  ", " ");
									// apparatus tags.  TODO: we need to add this to a filter proper rather than do this here
									raw = raw.replaceAll("[⸆¹⸆²⸆⸇᾿˸¹˸²˸³˸·¹²⟦–ʹ°¹°²⸋¹⸋²⸋⸌¹⸌°*\\[\\];⸀¹⸀²⸀³⸁⸀◆⟧⸂¹⸂²⸄⸂⸅⸃⸉¹⸈⸉⸊]", "");
%>
<%= raw %>
<%
								}
								else if ("plain".equals(format)) {
									String raw = book.getRawEntry();
// assume our modules are OSIS for now (should change output format of mgr or have a second mgr for this one.
//
// TODO: this doesn't work, but should.  Find out why this crashes
//									raw = mgr.filterText("Strong's Numbers", raw);
//									raw = mgr.filterText("Morphological Tags", raw);
//
									raw = mgr.filterText("OSISPlain", raw);
									raw = raw.replaceAll("\\([^)]*\\)", "");
									raw = raw.replaceAll("\\<[^>]*\\>", "");
									raw = raw.replaceAll("  ", " ");
									raw = raw.replaceAll("  ", " ");
									raw = raw.replaceAll("  ", " ");
									raw = raw.replaceAll("  ", " ");
									raw = raw.replaceAll("  ", " ");
									
%>
<%= raw %>
<%
								}
								else {
									// --------------------------------------------

									String suggest = "";
									StringBuffer verseText = new StringBuffer();
									if (book.getKeyChildren().length > VERSEKEY_BOOKABBREV) {
										suggest = book.getKeyChildren()[VERSEKEY_VERSE];
										if (!lastChapter.equals(book.getKeyChildren()[VERSEKEY_CHAPTER]) || !lastBook.equals(book.getKeyChildren()[VERSEKEY_BOOKABBREV])) suggest = book.getKeyChildren()[VERSEKEY_CHAPTER] + ":" + suggest;
										if (!lastBook.equals(book.getKeyChildren()[VERSEKEY_BOOKABBREV])) suggest = book.getKeyChildren()[VERSEKEY_BOOKABBREV] + " " + suggest;
										verseText.append("<span class=\""+ ("0".equals(book.getKeyChildren()[VERSEKEY_CHAPTER]) ? "book_intro" : "0".equals(book.getKeyChildren()[VERSEKEY_VERSE]) ? "chapter_intro" : "verse_number") + "\" data-book=\"" + book.getKeyChildren()[VERSEKEY_BOOKABBREV] + "\" data-chapter=\""+ book.getKeyChildren()[VERSEKEY_CHAPTER] + "\" data-verse=\"" + book.getKeyChildren()[VERSEKEY_VERSE] + "\" data-verseKey=\"" + book.getKeyChildren()[VERSEKEY_OSISREF] + "\" data-suggested=\"" + suggest + "\"></span>");
									}
									else {
										verseText.append("<span class=\"verse_number\" data-verseKey=\"" + book.getKeyText() + "\" data-suggested=\"" + book.getKeyText() + "\"></span>");
									} 
									verseText.append(book.getRenderText());
									if ("json".equals(format)) {
										if (k > 0) out.print(", ");
										out.print("{ \"verse\": \"" + book.getKeyText() + "\", \"text\": \"" + jsonEscape(verseText.toString()) + "\" }");
									}
									else out.print(verseText.toString());
								}
							}
						}
						if (book.getKeyChildren().length > VERSEKEY_BOOKABBREV && !"0".equals(book.getKeyChildren()[VERSEKEY_VERSE])) {
							lastBook = book.getKeyChildren()[VERSEKEY_BOOKABBREV];
							lastChapter = book.getKeyChildren()[VERSEKEY_CHAPTER];
						}
					}
					if ("tei".equals(format)) {
//System.out.println("inchapter: " + inChapter);
	if (!"0".equals(inChapter)) {
%></div><%
	}
%>
</div>
</TEI>
<%
					}
					else if ("json".equals(format)) {
						out.print(" ] }");
					}
				}
			}
		}
	}
	else {
		response.setContentType("text/xml");
%>
<?xml version="1.0" encoding="utf-8"?>
<modules>
<%
		ModInfo[] modInfo = mgr.getModInfoList();
		for (int i = 0; i < modInfo.length; i++) {
			SWModule b = mgr.getModuleByName(modInfo[i].name);
			String dist = b.getConfigEntry("DistributionLicense");
			if ("<SWNULL>".equals(dist)) dist="";
%>
	<module id="<%=modInfo[i].name %>" category="<%= modInfo[i].category %>" distributionLicense="<%= HTTPUtils.canonize(dist) %>"><%= HTTPUtils.canonize(b.getDescription()) %></module>

<%
		}
%>
</modules>
<%
	}
%>
<%!
private static String jsonEscape(String raw) {
    String escaped = raw;
    escaped = escaped.replace("\\", "\\\\");
    escaped = escaped.replace("\"", "\\\"");
    escaped = escaped.replace("\b", "\\b");
    escaped = escaped.replace("\f", "\\f");
    escaped = escaped.replace("\n", "\\n");
    escaped = escaped.replace("\r", "\\r");
    escaped = escaped.replace("\t", "\\t");
    return escaped;
}
%>