/* author: jheadric@msn.com */
/* code copyright by Judy Headrick */
/* Creation date: 3/24/2007 */
function display(fromPC) {
	tileBorders = parseInt(document.form1.cuttingLines.value);
	tile1Rows = parseInt(document.form1.tableRows1.value);
	tile2Rows = parseInt(document.form1.tableRows2.value);
	tile3Rows = parseInt(document.form1.tableRows3.value);
	tile1Size = parseInt(document.form1.tileSize1.value);
	tile2Size = parseInt(document.form1.tileSize2.value);
	tile3Size = parseInt(document.form1.tileSize3.value);
	totalTile1Size = ((tile1Size + tileBorders) * tile1Rows);
	totalTile2Size = ((tile2Size + tileBorders) * tile2Rows);
	totalTile3Size = ((tile3Size + tileBorders) * tile3Rows);
	totalHeight = (totalTile1Size + totalTile2Size + totalTile3Size);
	totalPages = (totalHeight/900);
	thisTile = new Array(document.form1.tileSelection1.value, document.form1.tileSelection2.value, document.form1.tileSelection3.value);
	thisSize = new Array(tile1Size, tile2Size, tile3Size);
	thisRow = new Array(tile1Rows, tile2Rows, tile3Rows);
	thisSequence = new Array("first", "second", "third");
/* If this function is being called from a page where users can select tiles from their hard drive, the file location will need to be specified */
	tbtLocation = ""
	if (fromPC == 1) tbtLocation = "file://";

	alertText = "NOTICE: Your current tile and row selection will print on "+ Math.ceil(totalPages) +" pages.\n";
	alertText +="If you want to print everything on one page, you will need to select smaller tiles or fewer rows.";

/* Make sure there was at least one tile selection and check to make sure all selection information is complete*/
	selectionError = 0
	blankRows = 0
	for (k=0; k<3; k++){
		if (thisTile[k] != 0 && (thisSize[k] == 0 || thisRow[k] == 0)){
			window.alert("Please choose a tile size and/or number of rows for your " + thisSequence[k] + " tile selection");
			selectionError = 1;
			break;
			}
		if (thisTile[k] == 0 && (thisSize[k] != 0 || thisRow[k] != 0)) {
			window.alert("You have selected a tile size and/or number of rows, \n but you have not selected a tile for your " + thisSequence[k] + " choice. \n Please select a tile or clear your size/row selection.");
			selectionError = 1;
			break;
			}
		/* If all selections in the row are blank, increase the blank row count by 1 */
		if (thisTile[k] == 0 && thisSize[k] == 0 && thisRow[k] == 0) blankRows = blankRows + 1;
		}
/* if all selections for all rows are blank generate a message and increase the selectionError count by 1 */
	if (blankRows == 3){
		selectionError = 1;
		window.alert("Please select at least one tile and indicate the size and number of rows to generate.");
	}
/* If there were no problems with the tile selection, build the tile page */
	if (selectionError == 0){
	
	if (totalHeight > 900) window.alert(alertText);
	DispWin = window.open('','NewWin')
	DispWin.document.close();
	if (document.form1.tileSize1.value == 75) table1Cells = 8;
	if (document.form1.tileSize1.value == 100) table1Cells = 6;
	if (document.form1.tileSize1.value == 125) table1Cells = 5;
	if (document.form1.tileSize1.value == 150) table1Cells = 4;
	if (document.form1.tileSize1.value == 175) table1Cells = 3;
	if (document.form1.tileSize1.value == 200) table1Cells = 3;
	if (document.form1.tileSize1.value == 225) table1Cells = 2;
	if (document.form1.tileSize2.value == 75) table2Cells = 8;
	if (document.form1.tileSize2.value == 100) table2Cells = 6;
	if (document.form1.tileSize2.value == 125) table2Cells = 5;
	if (document.form1.tileSize2.value == 150) table2Cells = 4;
	if (document.form1.tileSize2.value == 175) table2Cells = 3;
	if (document.form1.tileSize2.value == 200) table2Cells = 3;
	if (document.form1.tileSize3.value == 225) table2Cells = 2;
	if (document.form1.tileSize3.value == 75) table3Cells = 8;
	if (document.form1.tileSize3.value == 100) table3Cells = 6;
	if (document.form1.tileSize3.value == 125) table3Cells = 5;
	if (document.form1.tileSize3.value == 150) table3Cells = 4;
	if (document.form1.tileSize3.value == 175) table3Cells = 3;
	if (document.form1.tileSize3.value == 200) table3Cells = 3;
	if (document.form1.tileSize3.value == 225) table3Cells = 2;
	message = "<html><head></head><body><table bordercolor='#FFFFFF' Border='0' cellpadding='0' cellspacing='0'>"
	for (rows1 = 0; rows1 < tile1Rows; rows1++) {
		message += "<tr>"
		for (cells1 = 0; cells1 < table1Cells; cells1 ++) {
			message += "<td><img src='" + tbtLocation + document.form1.tileSelection1.value +"' width=" + document.form1.tileSize1.value +" height="+ document.form1.tileSize1.value +" hspace='" + tileBorders + "' vspace='" + tileBorders +"'></td>"
		}
		message += "</tr>"
		}
	message +="</table>"

	message += "<table bordercolor='#FFFFFF' Border='0' cellpadding='0' cellspacing='0'>"
	for (rows2 = 0; rows2 < tile2Rows; rows2++) {
		message += "<tr>"
		for (cells2 = 0; cells2 < table2Cells; cells2 ++) {
			message += "<td><img src='" + document.form1.tileSelection2.value +"' width=" + document.form1.tileSize2.value +" height="+ document.form1.tileSize2.value +" hspace='" + tileBorders + "' vspace='" + tileBorders +"'></td>"
		}
		message += "</tr>"
		}
	message +="</table>"

	message += "<table bordercolor='#FFFFFF' Border='0' cellpadding='0' cellspacing='0'>"
	for (rows2 = 0; rows2 < tile3Rows; rows2++) {
		message += "<tr>"
		for (cells2 = 0; cells2 < table3Cells; cells2 ++) {
			message += "<td><img src='" + document.form1.tileSelection3.value +"' width=" + document.form1.tileSize3.value +" height="+ document.form1.tileSize3.value +" hspace='" + tileBorders + "' vspace='" + tileBorders +"'></td>"
		}
		message += "</tr>"
		}
	message +="</table></body></html>"
	DispWin.document.write(message);
	DispWin.document.close;
	DispWin.focus();
}
}

