function buildPrintableTable(lootlist)
{
	var i;
	var output = "";

	for(i=0;i<lootlist.length;i++)
		output += buildPrintableRow(lootlist[i]);

	return(output);
}

function buildPrintableRow(lootitem)
{
	var text ;
	var theattack,thedefense;
	var itemID;
	var where;

	text = "<tr>";

	// ----------------- loot image -------------------------------------
	text += "<td class=\"printcell\" style=\"border-bottom: 1px solid black\">";

	if(lootitem.image)
		text += "<img style=\"width: 15pt;\"src='" + getImageName(lootitem) + "'/>";
	else
		text += "<img src='noimage.jpg' />";

	text += "</td>";

	// ----------------- loot name ------------------------------------
	text += "<td class=\"printcell\"  style=\"border-bottom: 1px solid black\">" +  lootitem.name + "</td>";

	// ----------------- attack ------------------------------------------
	theattack = (lootitem.attack == -1) ?  "?" : lootitem.attack;
	text += "<td class=\"printcell\"  style=\"border-bottom: 1px solid black\">" + theattack + "</td>";

	// ----------------- defense ------------------------------------------
	thedefense = (lootitem.defense == -1) ? "?" : lootitem.defense;
	text += "<td class=\"printcell\"  style=\"border-bottom: 1px solid black\">" + thedefense + "</td>";

	// ----------------- location --------------------------------------------
	where = lootitem.where;
	where = where.replace(/<br\/>/," - ");

	text += "<td class=\"printcell\"  style=\"border-bottom: 1px solid black\">" + where + "</td>";

	// ---------------- quantity ---------------------------------------------
	text += "<td class=\"printcell\"  style=\"border-bottom: 1px solid black; text-align: right\">";

	if(lootitem.type != "O")
		text += lootitem.quantity;
	else
		text += "&nbsp;";

	text  += "</td>";

	// ---------------- cost ---------------------------------------------
	text += "<td class=\"printcell\"  style=\"border-bottom: 1px solid black; text-align: right\">";

	if(lootitem.cost > 0 )
	{
		var symbol = getCurrencySymbol(lootitem);
		text += formatCost(lootitem.cost,symbol);
	}
	else
		text += "&nbsp";

	text += "</td>";

	// ----------------gift/sell ---------------------------------------------	
	text += "<td class=\"printcell\"  style=\"border-bottom: 1px solid black; text-align: right\">";

	if(lootitem.giftorsale)
		text += lootitem.giftorsale;
	else
		text += "&nbsp;";
	
	text += "</td>";

	// ----------------required ---------------------------------------------	
	text += "<td class=\"printcell\"  style=\"border-bottom: 1px solid black; text-align: right\">";

	if(lootitem.needed)
		text += lootitem.needed;
	else
		text += "&nbsp";
	
	text += "</td>";
	text += "</tr>";

	return(text);
}

function buildPrintableHeader(loottype)
{
	var text = "";
	text += "<tr><td class=\"printheader\" colspan=\"8\">" + loottype + "</td></tr>";
	text += "<tr><th>Image</th><th>Name</th><th>Attack</th><th>Defense</th><th>Where do I get it</th><th>Quantity</th><th>Cost</th><th>Gift/Sell</th><th>Required</th></tr>";
	return(text);
}

function DoPrintable()
{
	var text = "";
	var obj;
	var temp;

	text += "<h1 style=\"font-size: 16pt; color: black; text-align: center; font-family: verdana,arial,helvetica; margin: 0px; padding: 0px\"><b>Blofeld's</b> Loot List &amp; Combat Calculator</h1>";
	
	text += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color: white; margin-left: 0px; margin-top: 4px; border: 2px solid black; width: 100%\">";
	text += "<tr><td><img id=\"blofeldsimage\" src=\"scott.jpg\" height=\"80\" style=\"margin-right: 8px; margin-left: 3px; margin-top: 5px; margin-bottom: 5px\" alt='' />";
	text += "</td><td valign=\"top\" style=\"padding-right: 7px\">";
	text += "<p style=\"font-family: verdana,arial,helvetica; color: black\">Have you found Blofeld's Loot List &amp; Combat Calculator valuable? Has it helped you enjoy Mafia Wars more?  Please make a donation to help me maintain this tool.  Anything would help - I spend many many hours working on this so everyone can enjoy it and would like a good beer once in a while ;).<br/>Thank You - Ernst Blofeld.</p>";
	text += "</td></tr></table>";

	text += "<img onclick=\"closePrinting();\" src=\"closebox.png\" width=\"29\" style=\"position: absolute; right: 0px; top: 0px\"/>";
	text += "<table border='0' cellspacing='0' cellpadding='5' width='100%'>";

	text += buildPrintableHeader("Weapons");
	text += buildPrintableTable(weapon);

	text += buildPrintableHeader("Armor");
	text += buildPrintableTable(armor);

	text += buildPrintableHeader("Vehicles");
	text += buildPrintableTable(vehicle);
	
	text += buildPrintableHeader("Animals");
	text += buildPrintableTable(animal);
		
	text += buildPrintableHeader("Special");
	text += buildPrintableTable(other);
	
	text += "</table>";
	
	obj = getObj("nonprintarea");
	obj.style.display = "none";

	obj = getObj("printarea");

	obj.innerHTML = text;
	obj.style.display = "block";

}

function closePrinting()
{
	obj = getObj("nonprintarea");
	obj.style.display = "block";

	obj = getObj("printarea");

	obj.innerHTML = "";
	obj.style.display = "none";
}

