
	var outOfStock = "Temporarily out of stock.";

	// build the selection table

	curRow = 0;
	curCol = 0;
	var nRows = 0;
	var baseDir = "";
	var cimages = new Array();
	row = new Array();
	col = new Array();

	function pair( a, b )
	{
		this.fileName = baseDir + a;
		this.label = b;
	}

	function tableRx()
	{
		this.col = new Array();
		this.row = new Array();
	}

	tableRx.prototype.addCol = function( a, b )
	{
		this.col[ this.col.length ] = new pair( a, b );
	}

	tableRx.prototype.addRow = function( a, b )
	{
		this.row[ this.row.length ] = new pair( a, b );
	}


	function addRow()
	{
		if( (arguments.length & 1) != 0 )
			alert("theres something wrong with the number of labels/files in row: " + nRows );
		else {
			row[ curRow ] = new tableRx();
			for( i = 0 ; i < arguments.length ; i += 2 ) {
				row[ curRow ].addCol( arguments[ i ], arguments[ i+1 ] );
			}
		}
		curRow++;
	}

	function addCol()
	{
		if( (arguments.length & 1) != 0 )
			alert("theres something wrong with the number of labels/files in col: " + nCols );
		else {
			col[ curCol ] = new tableRx();
			for( i = 0 ; i < arguments.length ; i += 2 ) {
				col[ curCol ].addRow( arguments[ i ], arguments[ i+1 ] );
			}
		}
		curCol++;
	}

	function imgPreLoad()
	{
		for( i =0 ; i < arguments.length ; i++ ) {
			cimages[ i ]= new Image();
			cimages[ i ].src = baseDir + arguments[ i ];
		}
	}
	
	var part1 = '<td width="';
	var part2 = '" height="';
	var part3 = '" align="center" ><a onfocus="blur()" href="javascript:choose(';
	var part4 = ')" ><img border = 0 width=30 height=30 class=imgBorder name="img_';
	var vpart4 = ')" ><img border = 0 width=20 height=20 class=imgBorder name="img_';
	var part5 = '" src="';
	var part6 = ' "></a></td>';

	var labelPart1 = '<td class=sm align="center" valign=top width="';
	var vlabelPart1 = '<td class=sm style="padding-left:2;" align="left" width="';
	var labelPart2 = '" height="';
	var labelPart3 = '">';
	var prev = 0;
	var picNum = 0;
	optionTags = new Array();

	function showTable()
	{
		document.writeln( "<table border=0 cellpadding=0 cellspacing=0 >" )
		nRows = row.length;
		for( i = 0 ; i < nRows ; i++ ) {

			document.writeln( "<tr>" );

			nCols = row[ i ].col.length;

			for( j = 0 ; j < nCols ; j++ ) {
				document.writeln( part1 + cellWidth + part2 + cellHeight + part3 + picNum + part4 + picNum + part5 + row[ i ].col[ j ].fileName + part6 );
				optionTags[ picNum ] = row[ i ].col[ j ].label;
				picNum++;
			}

			document.writeln( "</tr>" );
			document.writeln( "<tr>" );

			for( j = 0 ; j < nCols ; j++ ) 
				document.writeln( labelPart1 + labelWidth + labelPart2 + labelHeight + labelPart3 + row[ i ].col[ j ].label + '</td>'  )

			document.writeln( "</tr>" );

		}
		document.writeln( "</table>" );
		document.close();
	}

	function showVTable()
	{
		document.writeln( "<table border=0 cellpadding=0 cellspacing=0 ><tr>" )
		nCols = col.length;
		for( i = 0 ; i < nCols ; i++ ) {

			nRows = col[ i ].row.length;
			document.writeln( '<td valign="top"><table border=0 cellpadding=0 cellspacing=0 >' )

			for( j = 0 ; j < nRows ; j++ ) {
				document.writeln( "<tr>" + part1 + cellWidth + part2 + cellHeight + part3 + picNum + vpart4 + picNum + part5 + col[ i ].row[ j ].fileName + part6 );
				document.writeln( vlabelPart1 + labelWidth + labelPart2 + labelHeight + labelPart3 + col[ i ].row[ j ].label + '</td></tr>' )
				optionTags[ picNum ] = col[ i ].row[ j ].label;
				picNum++;
			}

			document.writeln( "</table></td>" );
		}
		document.writeln( "</tr></table>" );
		document.close();
	}

	var theForm="cart_quantity";
	//var theOptions="D1";		// for testing.

	var internetExplorer = navigator.appVersion.indexOf( "MSIE" ) >= 0;

//	if( !internetExplorer ) 
//		window.onresize = function{ location.reload(1) };

function setDefault()
{
	// find the first legal choice
	var i, n;
	var whichOne=-1;
	for( i = 0 ; i < picNum ; i++ ) {

		if( document.forms[theForm].elements[ theOptions ].options[ 0 ].text == optionTags[ i ] ) {
			whichOne = i;
			break;
		}
	}

	if( internetExplorer ) 
		prev = theForm +".img_"+whichOne
	else 
		prev = "document."+theForm +".img_"+whichOne

	selectColor( prev, 1 );
	
}

function refreshImages()
{
	location.reload(1);
}

function choose( whichOne )
{
	var next;
	if( internetExplorer ) 
		next = theForm +".img_"+whichOne
	else 
		next = "document."+theForm +".img_"+whichOne

	var i, n;
	n = document.forms[theForm].elements[ theOptions ].options.length;
	var theOne = -1;
	for( i = 0 ; i < n ; i++ ) {

		if( document.forms[theForm].elements[ theOptions ].options[ i ].text == optionTags[ whichOne ] ) {
			theOne = i;
			break;
		}
	}
	if( theOne == -1 )
		alert( outOfStock )
	else {
		status = whichOne;
		if( prev )
			selectColor( prev, 0 );
		selectColor( next, 1 );
		prev = next

		document.forms[theForm].elements[ theOptions ].selectedIndex = theOne ;

		if( cimages.length )
			document.images['productImage'].src = cimages[ whichOne ].src;
	}
}


function menuChanged()
{
	if( prev )
		selectColor( prev, 0 );
	prev = 0;

	var whichOne = document.forms[theForm].elements[ theOptions ].selectedIndex;

	var i, n;
	var theOne = -1;
	for( i = 0 ; i < picNum ; i++ ) {

		if( document.forms[theForm].elements[ theOptions ].options[ whichOne ].text == optionTags[ i ] ) {
			whichOne = i;
			theOne = i;
			break;
		}
	}

	if( theOne == -1 ) {
		alert( outOfStock );
	} else {
	
		if( internetExplorer ) 
			prev =theForm +".img_"+whichOne
		else 
			prev = "document."+theForm +".img_"+whichOne

		if( cimages.length )
			document.images['productImage'].src = cimages[ whichOne ].src;

		selectColor( prev, 1 );
	}
}


var dw=4;
function selectColor( pic, on )
{
	pic = eval( pic );
	if( !on ) {
		//pic.width += dw;		// changing this changes height too.!?
		//pic.height += dw; //??
		pic.border = 0;
	} else {
		//pic.width -= dw;	    // changing this changes height too.!?
		//pic.height -= dw; //??
		pic.border = dw/2;
	}
}