// Unit Page Generation Template Script
//

function getFactionColor(faction)
{
var factioncolor
if (faction == "minbari")
	factioncolor = "lightblue"
else if (faction == "centauri")
	factioncolor = "purple"
else if (faction == "narn")
	factioncolor = "red"
else if (faction == "earth")
	factioncolor = "blue"
else if (faction == "league")
	factioncolor = "green"
else if (faction == "shadow")
	factioncolor = "#777777"
else if (faction == "raider")
	factioncolor = "red"
else
	factioncolor = "white"
return factioncolor
}

function genUnitPageHeader(data)
{
return '<table width="100%"><tr><td align="left"><a href="../'+data.shortname+'select.html" title="To Navy List"><img src="../images/'+data.shortname+'-insig-min.gif"border="0"></a>&nbsp;&nbsp;&nbsp;</td><td align="center">'+data.title+'</td><td align="right">&nbsp;&nbsp;&nbsp;<a href="../'+data.shortname+'select.html" title="To Navy List"><img src="../images/'+data.shortname+'-insig-min.gif" border="0"></a></td></tr></table>'
}

function genUnitViewsTable(data)
{
var text
text =
'<table border="3" align="center" cellspacing="1">' +
'<tr><th align="left" nowrap><font face="sans-serif" size="3"><b>Ship Recognition Views<b></font></th><tr>' +
'<tr><td align="center">' +
'	<table border="0" cellpadding="1" cellspacing="0">'
if (data.config == "saucer") {
	text +=
'	<tr>' +
'		<td align="right"><img src="'+data.shortname+'-o.jpg" width="'+data.o_width+'" height="'+data.o_height+'" alt="'+data.longname+' Over View"></td>' +
'	</tr><tr>' +
'		<td align="right"><img src="'+data.shortname+'-t.jpg" width="'+data.t_width+'" height="'+data.t_height+'" alt="'+data.longname+' Dorsal View"></td>' +
'	</tr><tr>' +
'		<td align="right"><img src="'+data.shortname+'-u.jpg" width="'+data.u_width+'" height="'+data.u_height+'" alt="'+data.longname+' Under View"></td>' +
'	</tr>'
}
else {
	text +=
'	<tr>' +
'		<td align="right"><img src="'+data.shortname+'-fr.jpg" width="'+data.fr_width+'" height="'+data.fr_height+'" alt="'+data.longname+' Front Right View"></td>' +
'		<td align="left"><img src="'+data.shortname+'-f.jpg" width="'+data.f_width+'" height="'+data.f_height+'" alt="'+data.longname+' Front View"></td>' +
'	</tr><tr>' +
'		<td align="right"><img src="'+data.shortname+'-r.jpg" width="'+data.r_width+'" height="'+data.r_height+'" alt="'+data.longname+' Right View"></td>' +
'		<td align="left"><img src="'+data.shortname+'-bl.jpg" width="'+data.bl_width+'" height="'+data.bl_height+'" alt="'+data.longname+' Back Left View"></td>' +
'	</tr><tr>' +
'		<td align="right"><img src="'+data.shortname+'-t.jpg" width="'+data.t_width+'" height="'+data.t_height+'" alt="'+data.longname+' Dorsal View"></td>' +
'		<td align="left"><img src="'+data.shortname+'-ul.jpg" width="'+data.ul_width+'" height="'+data.ul_height+'" alt="'+data.longname+' Under Left View"></td>' +
'	</tr>'
}
text +=
'	</table>' +
'</td></tr>' +
'</table>'
return text
}

function genFighterViewsTable(data)
{
var text
text =
'<table border="3" align="center" cellspacing="1">' +
'<tr><th align="left" nowrap><font face="sans-serif" size="3"><b>Fighter Recognition Views<b></font></th><tr>' +
'<tr><td align="center">' +
'	<table border="0" cellpadding="1" cellspacing="0">' +
'	<tr>' +
'		<td align="right"><img src="'+data.shortname+'-fr.jpg" width="'+data.fr_width+'" height="'+data.fr_height+'" alt="'+data.longname+' Front Right View"></td>' +
'		<td align="left"><img src="'+data.shortname+'-f.jpg" width="'+data.f_width+'" height="'+data.f_height+'" alt="'+data.longname+' Front View"></td>' +
'	</tr><tr>' +
'		<td align="right"><img src="'+data.shortname+'-r.jpg" width="'+data.r_width+'" height="'+data.r_height+'" alt="'+data.longname+' Right View"></td>' +
'		<td align="left"><img src="'+data.shortname+'-bl.jpg" width="'+data.bl_width+'" height="'+data.bl_height+'" alt="'+data.longname+' Back Left View"></td>' +
'	</tr>' +
'	</table>' +
'</td></tr>' +
'</table>'
return text
}

function genUnitConfigArcsTable(data)
{
var text
text =
'<table border="3" align="center" cellspacing="1">' +
'<tr><th align="left" nowrap><font face="sans-serif" size="3"><b>Weapon Location / Firing Arcs</b></font></th></tr>' +
'<tr><td align="center">' +
'	<table border="0" cellpadding="1" cellspacing="0">' +
'	<tr><td colspan="3">&nbsp;</td></tr>' +
'	<tr>' +
'		<td align="center" colspan="3"><font size="-1">'+data.forwardtext+'</font></td>' +
'	</tr><tr>' +
'		<td align="right"><font size="-1">'+data.porttext+'</font></td><td align="center"><img src="'+data.shortname+'-arcs.gif" width="'+data.arcs_width+'" height="'+data.arcs_height+'" alt="'+data.longname+' Arcs"></td><td align="left"><font size="-1">'+data.starbdtext+'</font></td>' +
'	</tr><tr>' +
'		<td colspan="3" align="center"><font size="-1">'+data.afttext+'</font></td>' +
'	</tr><tr>' +
'		<td colspan="3">&nbsp;</td>' +
'	</tr><tr>' +
'		<td colspan="3" align="center"><font size="-1">Primary: '+data.primarytext+'</font></td>' +
'	</tr>' +
'	</table>' +
'</td></tr>' +
'</table>'
return text
}

function genFighterConfigArcsTable(data)
{
var text
text  = '<table border="3" align="center" cellspacing="1">'
text += '<tr><th align="left" nowrap><font face="sans-serif" size="3"><b>Weapon Location / Firing Arcs</b></font></th></tr>'
text += '<tr><td align="center">'
text += '	<table border="0" cellpadding="1" cellspacing="0">'
text += '	<tr><td colspan="3">&nbsp;</td></tr>'
text += '	<tr>'
text += '		<td align="center" colspan="3"><font size="-1">'+data.forwardtext+'</font></td>'
text += '	</tr><tr>'
text += '		<td align="right"><font size="-1">'+data.porttext+'</font></td><td align="center"><img src="'+data.shortname+'-arcs.gif" width="'+data.arcs_width+'" height="'+data.arcs_height+'" alt="'+data.longname+' Arcs"></td><td align="left"><font size="-1">'+data.starbdtext+'</font></td>'
text += '	</tr><tr>'
text += '		<td colspan="3" align="center"><font size="-1">'+data.afttext+'</font></td>'
text += '	</tr><tr>'
text += '		<td colspan="3">&nbsp;</td>'
text += '	</tr>'
text += '	</table>'
text += '</td></tr>'
text += '</table>'
return text
}

function genUnitSummaryTable(data)
{
var text
text =
'<table border="1" cellpadding="1" cellspacing="1" width="100%">' +
'<tr><th align="left" colspan="2"><font size="3"><b><nobr>'+data.unittype+' Summary</nobr></b></font></th></tr>' +
'<tr><td nowrap>Class</td><td nowrap>'+data.unitclass+'</td></tr>' +
'<tr><td nowrap>EW Rating</td><td nowrap>'+data.ewrating+'</td></tr>' +
'<tr><td nowrap>Engine Rating</td><td nowrap>'+data.enginerating+'</td></tr>' +
'<tr><td nowrap><a href="../unitpoints.html#'+data.pointslink+'">Point Value</a></td><td nowrap>'+data.points+'</td></tr>' +
'<tr><td nowrap>Jump Engine</td><td nowrap>'+data.jumpengine+'</td></tr>' +
'<tr><td nowrap>Power Surplus</td><td nowrap>'+data.powersurplus+'</td></tr>' +
'<tr><td nowrap>Special</td><td nowrap>'+data.special+'</td></tr>' +
'</table>'
return text
}

function genFighterSummaryTable(data)
{
var text
text =
'<table border="1" cellpadding="1" cellspacing="1" width="100%">' +
'<tr><th align="left" colspan="2"><font size="3"><b><nobr>'+data.unittype+' Summary</nobr></b></font></th></tr>' +
'<tr><td nowrap>Class</td><td nowrap>'+data.unitclass+'</td></tr>' +
'<tr><td nowrap>Jink Limit</td><td nowrap>'+data.jinklimit+'</td></tr>' +
'<tr><td nowrap>Ram Factor</td><td nowrap>'+data.ramfactor+'</td></tr>' +
'<tr><td nowrap><a href="../unitpoints.html#Fighter">Point Value</a></td><td nowrap>'+data.points+'</td></tr>' +
'<tr><td nowrap>Offensive Bonus</td><td nowrap>'+data.offbonus+'</td></tr>' +
'<tr><td nowrap>Initiative Bonus</td><td nowrap>'+data.initbonus+'</td></tr>' +
'<tr><td nowrap>Special</td><td nowrap>'+data.special+'</td></tr>' +
'</table>'
return text
}
function genWeaponSummaryTable()
{
var text
text =
'<table border="1" cellpadding="1" cellspacing="1" width="100%">' +
'<tr><th align="left" colspan="3"><b><nobr>Weapon Summary</nobr></b></th></tr>' +
'<tr><td><i>Name</i></td><td><i>Range</i></td><td><i>#</i></td></tr>' +
self.getWeaponSummaryRows() +
'</table>'
return text
}

function genUnitHangarSummaryTable()
{
var text
text =
'<table border="1" cellpadding="1" cellspacing="1" width="100%">' +
'	<tr><th align="left" colspan="2"><b><nobr>Hangar Summary</nobr></b></th></tr>' +
self.getHangarSummaryRows() +
'</table>'
return text
}

function genUnitHullSummaryTable()
{
var text
text =
'<table border="1" cellpadding="1" cellspacing="1" width="100%">' +
'<tr><th align="left" colspan="4"><b><nobr>Hull Summary</nobr></b></th></tr>' +
'<tr align="left"><td><i>Block</i></td><td><i>Defense</i></td><td><i>Armor</i></td><td><i>Structure</i></td></tr>' +
self.getHullSummaryRows() +
'</table>'
return text
}

function genFighterHullSummaryTable()
{
var text
text =
'<table border="1" cellpadding="1" cellspacing="1" width="100%">' +
'<tr><th align="left" colspan="4"><b><nobr>Hull Summary</nobr></b></th></tr>' +
'<tr align="left"><td><i>Facing</i></td><td><i>Armor</i></td><td><i>Defense</i></td></tr>' +
self.getHullSummaryRows() +
'</table>'
return text
}

function genViewsTable(unitdata)
{
if (unitdata.unitclass == 'Fighter')
	return getFighterViewsTable()
else
	return getUnitViewsTable()
}

function genConfigArcsTable(unitdata)
{
if (unitdata.unitclass == 'Fighter')
	return getFighterConfigArcsTable()
else
	return getUnitConfigArcsTable()
}

function genSummaryTable(unitdata)
{
if (unitdata.unitclass == 'Fighter')
	return getFighterSummaryTable()
else
	return getUnitSummaryTable()
}

function genHangarSummaryTable(unitdata)
{
if (unitdata.unitclass == 'Fighter')
	return ''
else
	return genUnitHangarSummaryTable()
}

function genHullSummaryTable(unitdata)
{
if (unitdata.unitclass == 'Fighter')
	return genFighterHullSummaryTable()
else
	return genUnitHullSummaryTable()
}

function genVariantTable(data)
{
if (data.variantlinkname == null)
	data.variantlinkname = data.variantshortname
var text
text =
'<table border="1" cellpadding="1" cellspacing="1" width="100%">' +
'<tr><th align="center" colspan="5"><b><nobr>Variant Summary</nobr></b></th></tr>' +
'<tr><td width="10%" nowrap>Hull Type&nbsp;</td><td width="15%" nowrap><a href="../'+data.faction+'/'+data.variantlinkname+'.html"><img src="text-'+data.variantshortname+'.gif" alt="'+data.variantlongname+'" align="left" border="0"></a>&nbsp;</td><td width="25%" height="100%" rowspan="2" valign="top" nowrap><i>Additions:</i><br>'+data.variantadds+'</td><td  width="25% height="100%" rowspan="2" valign="top" nowrap><i>Deletions:</i><br>'+data.variantdels+'</td><td width="25% height="100%" rowspan="2" valign="top" nowrap><i>Modifications:</i><br>'+data.variantmods+'</td></tr>' +
'<tr><td width="10%" nowrap>Frequency&nbsp;</td><td width="15%" nowrap>'+data.variantfreq+'&nbsp;</td></tr>' +
'</table>'
return text
}

function genVariantListRow(data)
{
var text
if (data.linkname == null)
	data.linkname = data.shortname
text =
'<tr><td align="right" width="50%">' +
'<a href="'+data.linkname+'.html"><img src="text-'+data.shortname+'.gif" alt="'+data.longname+'" border="0"></a>'
if (data.shortnameext != null)
	text += '&nbsp;&nbsp;<a href="'+data.linkname+'.html"><img src="text-'+data.shortnameext+'.gif" border="0"></a>'
text += '&nbsp;</td><td>&nbsp;'+data.descr+'</td></tr>'
data.linkname = null
return text
}

function genVariantList(data)
{
var text
text =
'<table border="1" cellpadding="1" cellspacing="1" align="center" width="100%">' +
'	<tr><th align="center" colspan="2"><b><nobr>Variant List</nobr></b></th></tr>' +
self.getVariantListRows() +
'</table>'
return text
}

function genUnitPage(unitdata)
{
if (unitdata.papertype == null)
   unitdata.papertype = "paper"
if (unitdata.textcolour == null)
   unitdata.textcolour = "white"
var text

text =
'</head><body bgcolor="black" text="'+unitdata.textcolour+'" background="../images/'+unitdata.faction+'-stars.gif"><font face="sans-serif">' +
'<table border="3" cellpadding="5" cellspacing="0" background="../images/'+unitdata.papertype+'.gif" align="center">' +
'<tr><td>' +
'	<table border="0">' +
'	<tr>' +
'		<td colspan="2">' +
			getUnitPageHeader() +
'		</td>' +
'	</tr>' +
'	<tr>' +
'		<td>' +
			genViewsTable(unitdata) +
'		</td>' +
'		<td>' +
			genConfigArcsTable(unitdata) +
'		</td>' +
'	</tr>' +
'	<tr>' +
'		<td colspan="2">' +
'			<table border="0" cellpadding="1" cellspacing="1" width="100%">' +
'			<tr><td width="33%" valign="top">' +
				genSummaryTable(unitdata) +
'			</td>' +
'			<td width="33%" valign="top">' +
				genWeaponSummaryTable() +
'				<font size="1"><br></font>' +
				genHangarSummaryTable(unitdata) +
'			</td>' +
'			<td width="34%" valign="top">' +
				genHullSummaryTable(unitdata) +
'			</td></tr>'
if (unitdata.variantlongname != null) {
text +=
'			<tr><td colspan="3" valign="top">' +
				genVariantTable(unitdata) +
'			</td></tr>'
}
else if (unitdata.variantlist != null) {
text +=
'			<tr><td colspan="3" valign="top">' +
				genVariantList(unitdata) +
'			</td></tr>'
}
text +=
'			</table>' +
'		</td>' +
'	</tr>' +
'	</table>' +
'</td></tr>' +
'</table>' +
'</font></body></html>'
return text
}
