// Takes in the beginning point in the catalog, the ending point in the catalog,
// and the desired number of columns in the table and writes a table using that
// info

function writeTable(desiredCols) {
	// the number of rows in the table not including the last row
	var tablerows = catalog.length / desiredCols - 1; 

	// the number of columns in the last row in the table
	var lastrow = catalog.length % desiredCols;

	// if the table comes out in an even number of rows, make the lastrow the length of the rest
	if (lastrow == 0) lastrow = desiredCols;

	// Begin the table
	document.write ("<TABLE cellspacing=0 cellpadding=2 border=0>\n");

	// Write all rows but the last

	for (i = 0; i < tablerows; i++) {

		document.write ("<tr>\n");
		for (j = 0; j < desiredCols; j++) {
			q = (i * desiredCols) + j;
			document.write ("<TD align='center'>\n");
			document.write ("<A onClick='newDetailPage("+q+")' href='#'>\n");
			document.write ("<IMG SRC='thumbnails/"+catalog[q][ITEMNUMBER]+".jpg' alt='"+catalog[q][NAME]+"' name='"+q+"' border='0'>");
			document.write ("</A>\n");
			document.write ("</TD>\n");
		}
		document.write ("</tr>\n");

	}

	// Write the last row

	document.write ("<tr>\n");
	for (k = 0; k < lastrow; k++) {
		q = (i * desiredCols) + k;
		document.write ("<TD align='center'>\n");
		document.write ("<A onClick='newDetailPage("+q+")' href='#'>\n");
		document.write ("<IMG SRC='thumbnails/"+catalog[q][ITEMNUMBER]+".jpg' alt='"+catalog[q][NAME]+"' name='"+q+"' border='0'>");
		document.write ("</A>\n");
		document.write ("</TD>\n");
	}
	document.write ("</tr>\n");

	// End the table
	document.write ("</TABLE>\n");
}
function newDetailPage(index) {
	newPage = window.open("", "", "height=440, width=785");

	newPage.document.writeln("<HTML>");
	newPage.document.writeln("<HEAD>");
	newPage.document.writeln("<TITLE>");
	newPage.document.write(catalog[index][NAME]);
	newPage.document.writeln("</TITLE>");
	newPage.document.writeln("<style type='text/css'>");
	newPage.document.writeln("body {");
	newPage.document.writeln("background: #D5C7BB repeat-y left;");
	newPage.document.writeln("position: relative;");
	newPage.document.writeln("margin: 0;");
	newPage.document.writeln("padding: 0;");
	newPage.document.writeln("font-family: verdana, serif;");
	newPage.document.writeln("font-size: 8pt;");
	newPage.document.writeln("}");
	newPage.document.writeln("a:link { color: #272117 }");
	newPage.document.writeln("a:visited { color: #594A41 }");
	newPage.document.writeln("td {");
	newPage.document.writeln("font-family: book antiqua, serif;");
	newPage.document.writeln("font-size: 15px;");
	newPage.document.writeln("}");
	newPage.document.writeln("</style>");
	newPage.document.writeln("</HEAD>");

	newPage.document.writeln("<body text='black' link='#272117' vlink='#594A41' marginwidth='0' marginheight='0' leftmargin='0' rightmargin='0' topmargin='0' bottommargin='0'>");
	newPage.document.writeln("<table border='0' cellspacing='0' cellpadding='0' width='785'>");
	newPage.document.writeln("<tr>");
	newPage.document.writeln("<td bgcolor='#7C736D' height='25' width='25'>&nbsp;</td>");
	newPage.document.writeln("<td valign='bottom' height='25' bgcolor='#D5C7BB'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#7C736D' height='25' width='25'>&nbsp;</td>");
	newPage.document.writeln("<td valign='bottom' height='25' bgcolor='#D5C7BB'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#7C736D' height='25' width='25'>&nbsp;</td>");
	newPage.document.writeln("</tr>");

	newPage.document.writeln("<tr>");
	newPage.document.writeln("<td bgcolor='#272117'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#594A41' height='25'><span style='padding-left: 5px; font-size: 12pt; color: white;'><b><center>");
	newPage.document.writeln(catalog[index][NAME]);
	newPage.document.writeln("</center></b></span></td>");
	newPage.document.writeln("<td bgcolor='#272117'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#594A41' height='25'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#272117'>&nbsp;</td>");
	newPage.document.writeln("</tr>");

	newPage.document.writeln("<tr>");
	newPage.document.writeln("<td bgcolor='#7C736D'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#D5C7BB' height='340' width='390' background='images/"+catalog[index][ITEMNUMBER]+".jpg'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#7C736D'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#D5C7BB' height='340' width='320' valign='top'>");
	newPage.document.writeln("<div style='padding-left: 8px; padding-top: 5px; padding-bottom: 5px; padding-right: 8px;'>");
	newPage.document.writeln("<table cellpadding='0' cellspacing='0' border='0'>");
	newPage.document.writeln("<tr valign='top'>");
	newPage.document.writeln("<td>");

	newPage.document.writeln("<table border=0 cellpadding=0 cellspacing=0 width='100%' height='100%'>");
	newPage.document.writeln("<tr align='right'>");
	newPage.document.writeln("<td valign='top' align='left' width='150'>");
	newPage.document.writeln("<div style='padding-bottom: 4px;'>");
	newPage.document.writeln("<div style='font-size: 18px; letter-spacing: 2px; color: #0031CE; padding: 2px; font: Verdana, Geneva, Arial, Helvetica, sans-serif;'>");
	newPage.document.write(catalog[index][PRICE]);
	newPage.document.writeln("</div>");
	newPage.document.writeln("</div>");
	newPage.document.writeln("</td>");
	newPage.document.writeln("<td align='right'>");
	newPage.document.writeln("<form target='paypal' action='https://www.paypal.com/cgi-bin/webscr' method='post'>");
	newPage.document.writeln("<input type='hidden' name='cmd' value='_cart'>");
	newPage.document.writeln("<input type='hidden' name='business' value='barbara@barbarazucker.com'>");
	newPage.document.writeln("<input type='hidden' name='item_name' value='"+catalog[index][NAME]+"'>");
	newPage.document.writeln("<input type='hidden' name='item_number' value='"+catalog[index][ITEMNUMBER]+"'>");
	newPage.document.writeln("<input type='hidden' name='amount' value='"+catalog[index][PRICE]+"'>");
	newPage.document.writeln("<input type='hidden' name='image_url' value='http://www.barbarazucker.com/images/bzlogo_pp2.gif'>");
//	newPage.document.writeln("<input type='hidden' name='return' value='http://www.barbarazucker.com/success.html'>");
//	newPage.document.writeln("<input type='hidden' name='cancel_return' value='http://www.barbarazucker.com/cancel.html'>");
	newPage.document.writeln("<input type='hidden' name='no_note' value='1'>");
	newPage.document.writeln("<input type='hidden' name='currency_code' value='USD'>");
	newPage.document.writeln("<input type='hidden' name='lc' value='US'>");
	newPage.document.writeln("<input type='image' src='https://www.paypal.com/en_US/i/btn/x-click-but22.gif' border='0' name='submit' alt='Order BZ designer jewelry online using Paypal - it's fast, free, and secure'>");
	newPage.document.writeln("<input type='hidden' name='add' value='1'>");
	newPage.document.writeln("</form>");
	newPage.document.writeln("</td>");
	newPage.document.writeln("<td>");
	newPage.document.writeln("<form target='paypal' action='https://www.paypal.com/cgi-bin/webscr' method='post'>");
	newPage.document.writeln("<input type='hidden' name='cmd' value='_cart'>");
	newPage.document.writeln("<input type='hidden' name='business' value='barbara@barbarazucker.com'>");
	newPage.document.writeln("<input type='image' src='https://www.paypal.com/en_US/i/btn/view_cart_02.gif' border='0' name='submit' alt='Order BZ designer jewelry online using Paypal - it's fast, free and secure!'>");
	newPage.document.writeln("<input type='hidden' name='display' value='1'>");
	newPage.document.writeln("</form>");
	newPage.document.writeln("</td>");
	newPage.document.writeln("</tr>");
	newPage.document.writeln("</table>");
	newPage.document.writeln("</td>");
	newPage.document.writeln("</tr>");

	newPage.document.writeln("<tr valign='bottom'>");
	newPage.document.writeln("<td height='230' valign='top'>");
	newPage.document.writeln(catalog[index][DESCRIPTION]);
	newPage.document.writeln("<br>");
	newPage.document.writeln("</td>");
	newPage.document.writeln("</tr>");
	newPage.document.writeln("<tr>");
	newPage.document.writeln("<td>");
	newPage.document.writeln("<table border=0 cellpadding=0 cellspacing=0 width='100%'>");
	newPage.document.writeln("<tr>");
	newPage.document.writeln("<td height='50' align='left' valign='bottom'>");
	newPage.document.writeln("<i>Actual size: "+catalog[index][DIMENSIONS]+"<i>");
	newPage.document.writeln("</td>");
	newPage.document.writeln("<td align='right'>");
	newPage.document.writeln("<img src='images/bzlogo_pp.gif' alt='Barbara Zucker Designer Jewelry'>");
	newPage.document.writeln("</td>");
	newPage.document.writeln("</tr>");
	newPage.document.writeln("</table>");
	newPage.document.writeln("</td>");
	newPage.document.writeln("</tr>");
	newPage.document.writeln("</table>");
	newPage.document.writeln("</div>");
	newPage.document.writeln("</td>");
	newPage.document.writeln("<td bgcolor='#7C736D'>&nbsp;</td>");
	newPage.document.writeln("</tr>");
	newPage.document.writeln("<tr>");
	newPage.document.writeln("<td bgcolor='#272117'>&nbsp;</td>");
	newPage.document.writeln("<td valign='bottom' height='25' bgcolor='#594A41'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#272117'>&nbsp;</td>");
	newPage.document.writeln("<td valign='bottom' height='25' bgcolor='#594A41'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#272117'>&nbsp;</td>");
	newPage.document.writeln("</tr>");
	newPage.document.writeln("<tr>");
	newPage.document.writeln("<td bgcolor='#7C736D' height='25' width='25'>&nbsp;</td>");
	newPage.document.writeln("<td valign='bottom' height='25' bgcolor='#D5C7BB'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#7C736D' height='25' width='25'>&nbsp;</td>");
	newPage.document.writeln("<td valign='bottom' height='25' bgcolor='#D5C7BB'>&nbsp;</td>");
	newPage.document.writeln("<td bgcolor='#7C736D' height='25' width='25'>&nbsp;</td>");
	newPage.document.writeln("</tr>");
	newPage.document.writeln("</table>");
	newPage.document.writeln("</body>");
	newPage.document.writeln("</html>");

	newPage.document.close();
}

