<!--

// prodpage.js
//
// Provides the javscript used by every product page on the website
//
// Module History
// --------------
// V1.0:JPA:15/03/2002: Initial Version
// V1.1:JPA:02/04/2002: Add "...prices for guidance..." line below table
// V1.2:JPA:03/04/2002: Swap US Dollar and Euro columns
// V1.3:JPA:12/04/2002: Remove word "Active" from start of option lines
// V1.4:JPA:16/04/2002: Remove "...prices for guidance..." line
// V1.5:JPA:28/05/2002: Remove USD prices
// V1.6:JPA:25/06/2002: Add open_datasheet_link() & close_datasheet_link();
//											right-align optional items to line up properly
// V1.7:JPA:21/08/2002: Remove Euro prices
// V1.8:JPA:16/09/2002: Remove all prices
// V1.9:JPA:31/12/2009: Make datasheets open in a new window


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// GLOBALS
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


var colHead = "\"#eff7f7\"";		// Background colour of Order Info table headings
var colBody = "\"#f7ffff\"";		// Background colour of Order Info table body cells


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// PUBLIC FUNCTIONS
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


//******************************************************************************
// Add link to datasheet to page
function open_datasheet_link()
{
	var idx;
	var SURL;
	
	idx = findProductForThisWebPage(0);		// Find index of first product that uses this web page
	if (idx != -1)							// If a product was found
	{
		SURL = SPathDownload + products[idx][fldProdDatasheet];	// Form URL of datasheet
		document.write ("<a href='"+ SURL + "' target='_blank'>");								// Write hyperlink into web page
	}
}

//******************************************************************************
// Close link to datasheet
function close_datasheet_link()
{
	document.write ("</a>");							// Close hyperlink tag
}

//******************************************************************************
// Print size of datasheet on page
function print_datasheet_size()
{
	var idx;

	idx = findProductForThisWebPage(0);		// Find index of first product that uses this web page
	if (idx != -1)							// If a product was found
	{
		//alert (products[idx][fldProdSizeDatasheet]);
		document.write (" (" + products[idx][fldProdSizeDatasheet] + ")");	// then print the size of its datasheet
	}
}

//******************************************************************************
// Display (or download, depending on browser settings) datasheet for this product page
function datasheet()
{
	var idx;
	var SURL;

	idx = findProductForThisWebPage(0);		// Find index of first product that uses this web page
	if (idx != -1)							// If a product was found
	{
		SURL = SPathDownload + products[idx][fldProdDatasheet];	// Form URL of datasheet
		//alert (SURL);
		self.location.href=SURL;			// Jump to datahsheet URL
	}
}

//******************************************************************************
// Print Ordering Information
function print_order_info()
{
	printOrderingHeader();
	printMainItems();
	printOptionals();
	printOrderingFooter();
}


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// PRIVATE FUNCTIONS
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


//******************************************************************************
// Return just the filename-part (after the last slash) of the current web-page
function WebPageFilename()
{
	var parts;
	var page;
	parts = self.location.href.split("/");	// Create array of each slashed part of this page's URL
	page = parts[parts.length-1].split("?");// Split last part (i.e. web page name) at question mark (if any)
	//alert(page);
	return(page[0]);												// Return filename
}


//******************************************************************************
// Return the index of the products array for the first product that uses this page
// Start looking thru array at index "start" param
function findProductForThisWebPage(start)
{
	var SThisPage;
	var n;
	var SSize;

	SThisPage = WebPageFilename();			// Get the filename of the current web-page
	//alert(SThisPage);

	// Loop through all the products in the products array
	for (n=start; n<products.length; n++)
	{
		if (products[n][fldProdWebPage] == SThisPage)	// If found a product that uses this web-page
		{
			//alert ("Match found: n=" + n);
			return n;									// then return index of this product (breaking out of loop!)
		}
	}
	return -1;								// Return -1 if no product found for this page
}


//******************************************************************************
// Print top of Ordering info table (fixed data)
function printOrderingHeader()
{
	document.write('<table border="1" style="border-collapse: collapse" bordercolor="#C0C0C0" width="573" cellspacing="0" cellpadding="1">\n');
			document.write('<tr>\n');
			document.write('  <td bgcolor='+colHead+' width="520">\n');
			document.write('    <b><font face="Verdana" size="2">Ordering Information</font></b>\n');
			document.write('  </td>\n');
			document.write('  <td bgcolor='+colHead+' width="53">\n');
			document.write('    <p align="center"><b><font face="Verdana" size="2">Code</font></b>\n');
			document.write('  </td>\n');
//			document.write('  <td bgcolor='+colHead+' width="149">\n');
//			document.write('    <p align="right"><b><font face="Verdana" size="2">Price (UK £)</font></b>\n');
//			document.write('  </td>\n');
			document.write('</tr>\n');
}


//******************************************************************************
// Print a row for each main item that uses this web page as its product page
function printMainItems()
{
	var idx = -1;
	var desc;
	var code;
	var UKP;

	while ((idx = findProductForThisWebPage(idx+1)) != -1)	// Loop thru all products that use this web page
	{
		// Get info to print from products array
		desc = products[idx][fldProdDesc];
		code = products[idx][fldProdCode];
		UKP = products[idx][fldProdPriceUKP];

		// Print row on page
		document.write('<tr>\n');
		document.write('  <td bgcolor='+colBody+' width="520">\n');
		document.write('    <font face="Verdana" size="1">'+desc+'</font>\n');
		document.write('  </td>\n');
		document.write('  <td bgcolor='+colBody+' width="53">\n');
		document.write('    <p align="center"><font face="Verdana" size="1">'+code+'</font>\n');
		document.write('  </td>\n');
//		document.write('  <td align="right" bgcolor='+colBody+' width="149">\n');
//		document.write('    <font face="Verdana" size="2">'+UKP+' </font>\n');
//		document.write('  </td>\n');
		document.write('</tr>\n');

	}
}

//******************************************************************************
// Print optional items (if any) in Order Info table
function printOptionals()
{
	var idx = -1;
	var desc;
	var code;
	var UKP;
	var opt;
	var options;
	var j;
	var bAdd;

	//alert("printOptionals");

	options = new Array();

	while ((idx = findProductForThisWebPage(idx+1)) != -1)	// Loop thru all products that use this web page
	{
		//alert("idx=" + idx);

		// Loop thru each option for the product
		for (opt = fldProdOptFirst; opt <= fldProdOptLast; opt++)
		{
			code = products[idx][opt];				// read stock code of optional item
			code.replace(/^\s*/, '').replace(/\s*$/, ''); // trim leading & trailing spaces
			if (code != "")
			{
				//alert("code='" + code + "'");
				bAdd = 1;
				// Loop thru the existing options
				for (j = 0; j < options.length; j++)
				{
					//alert("in loop1");
					if (code == products[options[j]][fldProdCode]) // If code same as code of a product already in options
						bAdd = 0;										// Don't add this option
				}
			}
			if (bAdd)													// If want to add option
			{
				//alert ("this far");
				for (j = 0; j < products.length; j++)				// Loop thru products in database
				{
					if (code == products[j][fldProdCode])			// If found product with code of option
					{
						//alert ("found it");
						options[options.length] = j;						// then add the index of this product to the options
						break;
					}
				}
			}
		}
	}

	if (options.length)																// If there is 1 or more option to print
	{
		// Print option heading
		document.write('<tr>\n');
		document.write('  <td colspan="5" bgcolor='+colHead+' width="100%"><b>\n');
		document.write('  <font face="Verdana" size="2">Options</font></b></td>\n');
		document.write('</tr>\n');

		// Loop thru each option
		for (j = 0; j < options.length; j++)
		{
			// Print a row of info for the option
			document.write('<tr>\n');
			document.write('  <td width="520" bgcolor='+colBody+'><font face="Verdana" size="1">\n');
			document.write('  ' + products[options[j]][fldProdDesc] + '</font></td>\n');
			document.write('  <td width="53" bgcolor='+colBody+' align="center">\n');
			document.write('  <font face="Verdana" size="1">' + products[options[j]][fldProdCode] + '</font></td>\n');
//			document.write('  <td width="149" align="right" bgcolor='+colBody+'>\n');
//			document.write('  <font face="Verdana" size="1">' + products[options[j]][fldProdPriceUKP] + ' </font></td>\n');
			document.write('</tr>\n');
		}
	}

	//alert ("Exiting printOptionals");
}


//******************************************************************************
// Print bottom of Ordering Info table (fixed data) and close table
function printOrderingFooter()
{
	document.write('</table>\n');
	document.write('<font face="Verdana" size="1"> \n');			// Small blank line after price info table
}

// End of prodpage.js
	
//-->
