event_entry_template = """
var TxtEntry{$num} = [
  'Event Details',
  '{$num}&nbsp{$event_name} ',
  '{$time}<br>Entry type {$entry_type}<br>Sent from {$send_from}<br>',
  '<font face="Courier">{$event_data}</font></p>',]
var ShortTxtEntry{$num} = [
  '<option style="color:{$text_color};background-color:{$back_color};{$font_family}{$font_italic}{$font_bold}">{$num_just} {$time}&nbsp&nbsp {$send_from_just} {$type_just} {$event_name} </option>',
  '</p>']
var Entry{$num} = [
  EventProto,
  TxtEntry{$num},
  ShortEventProto,
  ShortTxtEntry{$num} ]
"""

event_table_row = '<option style="color:{$text_color};background-color:{$back_color}";{$font_family}{$font_italic}' \
                  '{$font_bold} value="{$num}">{$num_just} {$time}&nbsp&nbsp {$send_from_just} {$type_just} ' \
                  '{$event_name} </option>'


events_template = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>UCD Console event monitoring report</title>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<script type="text/javascript">
var tbl_InternalStyleSheet =
[
 '<style>',
 'TABLE.DOCUMENT{width: 100%;table-layout: fixed;}',
 'TABLE.DOCUMENT TD.CONTENTS{border-right-style: solid;border-right-color: #000000;border-right-width: thin;table-layout: fixed;width: 55%;}',
 'TABLE.DOCUMENT TD.DOC{table-layout: fixed; width: 45%; word-wrap: break-word;}',
 'P.CONTENTS{font-weight: bold;font-family: "Arial";font-size: 10pt;margin-left: 0.3cm;margin-top: 0.5cm;margin-bottom: 0.3cm;color: #000000;}',
 'P.CONTENTS SELECT{font-weight: normal;font-family: "Courier";font-size: 10pt;width: 98%;height: 500pt;margin-top: 0;text-align: left;}',
 'P.CONTENTS BUTTON{width: 49%;height: 18pt;margin-top: 0.1cm;text-align: center;}',
 'P.COMPANYNAME{margin-top: 0cm;margin-bottom: 0.5cm;margin-left: 0.9cm;font-weight: medium;font-family: "Arial";font-size: 14pt;color: #000000;}',
 'P.COMPANYINFO{margin-top: 0cm;margin-bottom: 0.5cm;margin-left: 1.1cm;font-weight: medium;font-family: "Arial";font-size: 10pt;color: #000000;}',
 'P.HEADING{background-color: #BBC3FF;margin-top: 0;margin-bottom: 0.5cm;margin-left: 0cm;font-weight: bold;font-family: "Arial";font-size: 16pt;color: #000000; word-wrap: break-word;}',
 'P.SUBHEADING{background-color: #BBC3FF;margin-top: 1.25cm;margin-bottom: 0.5cm;margin-left: 0.5cm;margin-right: 0;font-weight: bold;font-family: "Arial";font-size: 11pt;color: #000000;text-transform: uppercase; word-wrap: break-word;}',
 'P.BLUESUBHEADING{background-color: #BBC3FF;margin-top: 0.5cm;margin-bottom: 0.5cm;margin-left: 0.3cm;margin-right: 0;font-weight: bold;font-family: "Arial";font-size: 11pt;color: #000000; word-wrap: break-word;}',
 'P.GREENSUBHEADING{background-color: #DCFABC;margin-top: 0.5cm;margin-bottom: 0.5cm;margin-left: 0.6cm;    margin-right: 0;    font-weight: bold;font-family: "Arial";font-size: 11pt;color: #000000; word-wrap: break-word;}',
 'P.BODYTEXT{margin-top: 0;margin-bottom: 0;margin-left: 0.9cm;font-weight: medium;font-family: "Arial";font-size: 10pt;color: #000000;  word-wrap: break-word;}',
 'P.INDENTBODYTEXT{margin-top: 0;margin-bottom: 0.5cm;margin-left: 1.2cm;font-weight: medium;font-family: "Arial";font-size: 10pt;color: #000000;}',
 'P.PRTGREEN{background-color: #DCFABC;margin-top: 0;margin-bottom: 0.05cm;margin-left: 0.6cm; margin-right: 0; font-weight: medium;font-family: "Courier";font-size: 11pt;color: #000000;}',
 'P.PRTROW{margin-top: 0;margin-bottom: 0.05cm;margin-left: 0.6cm; margin-right: 0; font-weight: medium;font-family: "Courier";font-size: 11pt;color: #000000;}',
 'P.PRTBODY{margin-top: 0;margin-bottom: 0.1cm;margin-left: 0.6cm;font-weight: medium;font-family: "Courier";font-size: 10pt;color: #000000;}',
 '</style>'
]
var tbl_CompanyInfo =
[
	'<p class="COMPANYINFO">',
	'Created with <a href="http://www.unigraf.fi">Unigraf</a> UCD Console',
	'</p>'
]
var tbl_InitialRight =
[
  '<p class="SUBHEADING" style="margin-left: 0; margin-top: 0;">&nbsp;&nbsp;&nbsp;Transaction / Event details</p>',
  '<p class="BODYTEXT">Select an entry from the list to see details</p>'
]
var PacketProto =
[
  '<p class="SUBHEADING" style="margin-left: 0; margin-top: 0;">&nbsp;&nbsp;&nbsp;',
  '</p><p class="BLUESUBHEADING">',
  '</p><p class="GREENSUBHEADING">Info</p><p class="BODYTEXT">',
  '</p><p class="GREENSUBHEADING">HEX Dump</p><p class="BODYTEXT">',
  '</p><p class="GREENSUBHEADING">Content decoder</p><p class="BODYTEXT">'
]
var EventProto =
[
  '<p class="SUBHEADING" style="margin-left: 0; margin-top: 0;">&nbsp;&nbsp;&nbsp;',
  '</p><p class="BLUESUBHEADING">',
  '</p><p class="GREENSUBHEADING">Info</p><p class="BODYTEXT">',
  '</p><p class="GREENSUBHEADING">Content decoder</p><p class="BODYTEXT">'
]
var TraceProto =
[
  '<p class="SUBHEADING" style="margin-left: 0; margin-top: 0;">&nbsp;&nbsp;&nbsp;',
  '</p><p class="BLUESUBHEADING">',
  '</p><p class="GREENSUBHEADING">Info</p><p class="BODYTEXT">',
  '</p><p class="GREENSUBHEADING">Content decoder</p><p class="BODYTEXT">'
]
var ShortPacketProto =
[
  '<p class="PRTROW" style="margin-left: 0; margin-top: 0;">&nbsp;&nbsp;&nbsp;',
  '<p class="PRTBODY">'
]
var ShortEventProto =
[
  '<p class="PRTROW" style="margin-left: 0; margin-top: 0;">&nbsp;&nbsp;&nbsp;',
  '</p><p class="PRTBODY">'
]
var tbl_RepDetails =
[
  '<p class="SUBHEADING" style="margin-left: 0; margin-top: 0;">&nbsp;&nbsp;&nbsp;Report details</p>',
  '<p class="GREENSUBHEADING">Unigraf test equipment</p>',
  '<p class="BODYTEXT">Device: {$ucd_device}<br></p>',
  '<p class="BODYTEXT">Firmware Package: {$ucd_fw_version}<br></p>',
  '<p class="BODYTEXT">Console Application: {$app_version}<br></p>',
  '<p class="BODYTEXT">Software Bundle: {$bundle_version}<br></p>',
  '<p class="BODYTEXT">Frontend Info: {$frontend_version}<br></p>',
  '<p class="BODYTEXT">Memory size: {$memory_size}<br><br></p>',
  '<p class="GREENSUBHEADING">Remarks</p>',
  '<p class="BODYTEXT">{$remarks}</p>',
  '<p class="GREENSUBHEADING">Tested by</p>',
  '<p class="BODYTEXT">{$tested}</p>',
]
{$events_data}
var tbl_AllDetails = [
{$events_list}
]
function MakeLongEntry (iEntryTable)
{
	var lp;
	var res = '';
	for (lp in iEntryTable[0])
	{
		res += iEntryTable [0] [lp];
		res += iEntryTable [1] [lp];
	}
	return res;
}
function MakeShortEntry(iEntryTable)
{
	var lp;
	var res = '';
	for (lp in iEntryTable[2])
	{
		res += iEntryTable [2] [lp];
		res += iEntryTable [3] [lp];
	}
	return res;
}
function GenerateDocument (iTable)
{
	var loop;
	var result = '';
	for (loop in iTable)
        result += iTable [loop];
    return result;
}
function ShowTransaction (iTable)
{
	var loop;
	document.getElementById ('document').innerHTML = '<p class="SUBHEADING" style="margin-left: 0; margin-top: 0;">&nbsp;&nbsp;&nbsp;Transaction details</p>';
	for(loop in iTable)
		if(loop != 0)
    		document.getElementById ('document').innerHTML += MakeLongEntry(iTable[loop]);
}
function ListHandler (iOptionValue)
{
    document.getElementById ('document').innerHTML = MakeLongEntry (tbl_AllDetails [iOptionValue]);
}
function ShowPrinterFriendlyDocument ()
{
	var loop;
	document.open ();
    document.write ('<p class="HEADING">&nbsp;&nbsp;{$report_name}</p>');
    document.write (GenerateDocument (tbl_RepDetails));
    document.write (GenerateDocument (tbl_InternalStyleSheet));
    document.write ('<p class="GREENSUBHEADING">Unigraf Oy contact information</p>');
    document.write (GenerateDocument (tbl_CompanyInfo));
	document.write ('<br><br><p class="SUBHEADING" style="margin-left: 0; margin-top: 0;">&nbsp;&nbsp;Events list</p><br>');
    for(loop in tbl_AllDetails)
    	document.write (MakeShortEntry (tbl_AllDetails[loop]));
	ShowReportDetails ();
    document.close ();
}
function ShowReportDetails ()
{
	document.getElementById ('document').innerHTML = GenerateDocument (tbl_RepDetails);
}
var styleloop;
for (styleloop in tbl_InternalStyleSheet)
{
	document.write (tbl_InternalStyleSheet [styleloop]);
}
</script>
</head>
<body onload="document.getElementById ('document').innerHTML = GenerateDocument (tbl_RepDetails)">
<div>
	<p class="HEADING" id="top">&nbsp;&nbsp;{$report_name}</p>
</div>
<div>
	<table class="DOCUMENT" cellpadding="0" cellspacing="0">
		<colgroup>
		</colgroup>
		<tr valign="top">
			<td class="CONTENTS">
				<p class="SUBHEADING" style="margin-left: 0; margin-top: 0;">
					&nbsp;&nbsp;&nbsp;Transactions and events
				</p>
				<p class="CONTENTS">
					Click entry to see details</p>		   				
				   <p class="CONTENTS">
				    &nbsp# <span style='padding-left:95px;'></span>Timestamp<span style='padding-left:62px;'></span>Source <span style='padding-left:40px;'> </span>Type <span style='padding-left:103px;'> </span> Info
					<select id="testlist" size="2" onchange="ListHandler (document.getElementById ('testlist').value)" onkeyup="ListHandler (document.getElementById ('testlist').value)">
					{$events_table}
					</select>
  				<button onclick="ShowPrinterFriendlyDocument ()">Show printer friendly format ...</button>
				<button onclick="ShowReportDetails ()">Show report information ...</button><br><br>
				<script type="text/javascript">
					document.write (GenerateDocument (tbl_CompanyInfo));
				</script>
				</p>

			</td>
			<td class="DOC">
				<div id="document">
					&nbsp;
				</div>
			</td>
		</tr>
	</table>
</div>
</body>
</html>

"""

packet_entry_template = """
var TxtEntry{$num} = [
  'Event Details',
  '{$num}&nbsp{$event_name} ',
  '{$time}<br>Entry type {$entry_type}<br>Sent from {$send_from}<br>',
  '{$hex}',
  '<font face="Courier">{$event_data}</font></p>',]
var ShortTxtEntry{$num} = [
  '<div style="color:{$text_color};margin-left: 0; margin-top: 0;background-color:{$back_color};{$font_family}{$font_italic}{$font_bold}">{$num_just} {$time}&nbsp&nbsp {$send_from_just} {$type_just} {$event_name}</div>',
  '{$hex_just}</p>']
var Entry{$num} = [
  PacketProto,
  TxtEntry{$num},
  ShortPacketProto,
  ShortTxtEntry{$num} ]

"""