
/*

<meta name="CONTENT_OWNER" content="Tracey Middleton">
<meta name="PROGRAMMER" content="Bernhard Speyer">
<meta name="DOCUMENTID" content="BSPR-5EHNBJ">
<meta name="LAST_REVISION" content="03/10/2002">

To add more rows, just add to rowArray at the bottom of these.
To delete rows, just go ahead & comment them out 
(ie //rowArray[1] = '3C1206-0|TXCR - AUI|299|false';)
The code is able to handle removals.

Make sure all elements have the same amount of columns: 3cnumber, description, price and true/false for advance warranty replacement option.
Use | to separate the columns.
The first array element rowArray[0] will always appear at the top - it is always taken to be the table header. You can overwrite this in your page if you'd rather use a different header.
To use: call writeTable(argBdr, argWidth, argSpacing, argPadding, argBoldHead) from within the code wherever you want the table.
 argBdr controls border 0 / 1 etc..
 argWidth is width of table (eg 420)
 argSpacing is table cell spacing (eg 2)
 argPadding is table cell padding (eg 2)
 argBoldHeader controls whether table header is in bold or not (true / false)
*/

//you use arrParts array to access all the data here. see below.

//ONLY EDIT THE ARRAY LIST BELOW, NOT THE FUNCTIONS.*****************************


//The order of the fields here is: 3C number (text), Description of item (text), $US price (text eg. 2,999), Whether this product offers advanreplacement (boolean)

//PLEASE ADD A SHORT NOTE WHEN COMMENTING OUT - DATE / REASON / WHO
rowArray = new Array();
rowArray[0] = '3C Number|Description|List Price ($US)|Advance Replacement Entitlement?';
rowArray[1] = '3C1206-0|TXCR - AUI|85|true';
rowArray[2] = '3C12063|TXCR - TP|125|true';
rowArray[4] = '3C1206-5|TXCR - FL|335|true';
rowArray[5] = '3C1206-6|TXCR - Coax|200|true';
rowArray[7] = '3C16010|UPS US|1495|true';
rowArray[11] = '3C1603-0 FMS|Coax Hub Management Module|780|true';
rowArray[12] = '3C16071|ARPS Chassis|799|true';
rowArray[14] = '3C16071B|ARPS Chassis|799|true';
rowArray[15] = '3C16072|APRS 60W Module|249|true';
rowArray[16] = '3C16073|APRS 100W Module|299|true';
rowArray[17] = '3C16074|ARPS T2|599|true';
rowArray[18] = '3C16074A|ARPS Type 2A Module|599|true';
rowArray[19] = '3C16075|ARPS Type 3 Module|799|true';
rowArray[20] = '3C16077|ARPS Y-Cable Type 3|149|true';
rowArray[21] = '3C16078|SuperStack II Advanced RPS Type 2 Y-Cable|149|true';
rowArray[22] = '3C16079|SuperStack II Advanced RPS Y-Cable|99|true';
rowArray[23] = '3C16080|APRS Management Module|699|true';
rowArray[24] = '3C16111|Firewall Web Site Filter|699|true';
rowArray[25] = '3C16115|Web Cache 1000|4,999|true';
rowArray[26] = '3C16116|Web Cache 3000|7,999|true';
rowArray[27] = '3C16117|SuperStack 3 Webcache Cache Storage Device|599|true'; // AO'C PCZI-53MJNT
rowArray[28] = '3C16120|ContentSwitch|9,000|true';
rowArray[29] = '3C16121|ContentSwitch+|9,650|true';
rowArray[30] = '3C16405|PS Hub 40 12-Port|759|true';
rowArray[32] = '3C16406|PS Hub 40 24-Port|1,339|true';
rowArray[34] = '3C16420|SuperStack II PS Hub Cascade Cable (30 cm/1 ft)|49|true';
rowArray[35] = '3C16421|SuperStack II PS Hub Cascade Cable (1 m/3 ft)|59|true';
rowArray[38] = '3C16440A|Baseline Hub 12-Port|195|true';
rowArray[40] = '3C16441A|Baseline Hub 24-Port|295|true';
rowArray[48] = '3C16465B|SuperStack 3 Baseline 10/100 Switch 24-Port|845|true'; //PC PCZI-5A4EAR
rowArray[49] = '3C16467|Baseline 10/100 Switch 24-Port plus 1000BASE-T|995|true';
rowArray[50] = '3C16590|BL Dual Speed Hub 12 Port|1,665|true';
rowArray[54] = '3C16592B|Baseline Dual Speed Hub 12-Port|345|true';
rowArray[56] = '3C16593A|BL Dual Speed Hub 24 Port (3C16593A)|615|true';
rowArray[57] = '3C16593B|Baseline Dual Speed Hub 24-Port|545|true';
rowArray[58] = '3C16610|Dual Speed Hub 500 12-Port|925|true';
rowArray[59] = '3C16611|Dual Speed Hub 500 24-Port|1,275|true';
rowArray[67] = '3C16672A|Hub 10 Telco|1,549|true';
rowArray[70] = '3C16683|SuperStack II 100BASE-TX Distance Extender Module (one RJ-45)|399|true';
rowArray[71] = '3C16684|SuperStack II 100BASE-TX Distance Extender Module (one pair SC)|699|true';
rowArray[72] = '3C16685|SuperStack II Dual Speed Hub 500 Management Module|945|true';
rowArray[73] = '3C16686|SuperStack II Dual Speed Hub 500 - Hub 10 Stacking Kit|199|true';
rowArray[76] = '3C16695|DSH 500 CC|49|true';
rowArray[80] = '3C16950|Switch 1100 24-Port|1,325|true';
rowArray[81] = '3C16951|Switch 1100 12-Port|925|true';
rowArray[82] = '3C16954|Switch 610 24-Port|1,025|true';
rowArray[83] = '3C16960|Switch 1100/3300 Matrix Module|995|true';
rowArray[84] = '3C16965|SuperStack II Switch Matrix Cable|125|true';
rowArray[85] = '3C16968|Switch 1100/3300 Layer 3 Module|1,995|true';
rowArray[87] = '3C16971|Switch 1100/3300 Dual 100Base-FX Module|995|true';
rowArray[88] = '3C16973|Switch 1100/3300 1000BASE-LX Module|1,495|true';
rowArray[89] = '3C16975|Switch 1100/3300 1000BASE-SX Module|995|true';
rowArray[92] = '3C16978|SuperStack II Switch 1000BASE-T Module|455|true';
rowArray[93] = '3C16980|Switch 3300 24-Port|2,150|true';
rowArray[94] = '3C16980A|Switch 3300 24-Port|1,595|true';
rowArray[95] = '3C16981|Switch 3300 12-Port|1,645|true';
rowArray[96] = '3C16981A|Switch 3300 12-Port|1,245|true';
rowArray[97] = '3C16982|Switch 3300 FX|5,845|true';
rowArray[100] = '3C16985B|Switch 3300 XM|1,245|true';
rowArray[102] = '3C16986A|Switch 3300 TM|1,995|true';
rowArray[104] = '3C16987A|Switch 3300 SM|2,350|true';
rowArray[135] = '3C510502|SS 11 TR ARMON|1,450|true';
rowArray[138] = '3C510505|SS 11 TR Adv|2,495|true';
rowArray[141] = '3C510600|SuperStack II Switch 2000 TR|7,995|true';
rowArray[148] = '3C5623|10BASE-T Transceiver Module (UTP)|175|true';
rowArray[149] = '3C625|SuperStack II Hub 10 Expansion Cable|59|true';
rowArray[150] = '3C840|OfficeConnect Remote 840 SDSL Router with Hub|499|true';
rowArray[150] = '3C888|OFFICE CONNECT DUAL 56K LAN MODEM (1 YEAR ONLY)| 379|true';
rowArray[161] = '3C17702|SuperStack 3 Switch 4900 SX|7,200|true';
rowArray[162] = '3C17700|SuperStack 3 Switch 4900|4,995|true';
rowArray[163] = '3C17710|SuperStack 3 Switch 4900 1000BASE-SX Module|3,000|true';
rowArray[164] = '3C17711|SuperStack 3 Switch 4900 1000BASE-T Module|1,600|true';
rowArray[165] = '3C17712|SuperStack 3 Switch 4900 1000BASE-LX Module|6,000|true';
rowArray[166] = '3C16823|Switch 4005 Fan Assembly|350|true';
rowArray[167] = '3C16824|Switch 4005 Fabric/Management|3,495|true';
rowArray[168] = '3C16464C|SuperStack 3 Baseline 10/100 Switch 12 Port|595|true';
rowArray[169] = '3C996B-T|Gigabit Server Nic|169|true';
rowArray[170] = '3C1000-T|Gigabit Client Nic|149|true';
rowArray[172] = '3C16468|SuperStack 3 Baseline 10/100/1000 Switch 6-port|1,795|true'; // rows 172 - 197 added as part of request PCZI-534FVB - AO'C
rowArray[173] = '3C16820|3Com Switch 4005 Chassis, includes Management/Fabric, PSU and Fans|4,995|true';
rowArray[174] = '3C16822|Switch 4005 300 Watt Power supply|1,495|true';
rowArray[177] = '3C16827|Switch 4005 1 Port Gigabit Ethernet 1000Bas-T module (RJ45)|1,195|true';
rowArray[178] = '3C16828|Switch 4005 8 Port Fast Ethernet Module (RJ45)|1,595|true';
rowArray[179] = '3C16829|Switch 4005 8 Port Fast Ethernet Module (MMF, MTRJ)|4,495|true';
rowArray[182] = '3C16970|SuperStack II Switch 100BASE-FX Module|595|true';
rowArray[183] = '3C17100|SuperStack 3 Switch 4300 48 pt|2,495|true';
rowArray[184] = '3C17111|SuperStack 3 4300 100Base-Fx single port module|595|true';
rowArray[185] = '3C17112|SuperStack 3 4300 100Base-Fx dual port module|995|true';
rowArray[186] = '3C17121|SuperStack 3 4300 1000Base-T single port module|395|true';
rowArray[187] = '3C17122|SuperStack 3 4300 1000Base-T dual port module|650|true';
rowArray[188] = '3C17131|SuperStack 3 4300 1000Base-Sx single port module|895|true';
rowArray[189] = '3C17132|SuperStack 3 4300 1000Base-Sx dual port module|1,250|true';
rowArray[190] = '3C17141|SuperStack 3 4300 1000Base-Lx single port module|1,495|true';
rowArray[191] = '3C17203|SuperStack 3 Switch 4400 24pt|1,595|true';
rowArray[192] = '3C17220|SuperStack 3 Switch 4400 1000BASE-T Module|395|true';
rowArray[193] = '3C17221|SuperStack 3 Switch 4400 1000BASE-SX Module|895|true';
rowArray[194] = '3C17222|SuperStack 3 Switch 4400 100BASE-FX Module|595|true';
rowArray[195] = '3C17223|SuperStack 3 Switch 4400 1000BASE-LX Module|1,495|true';
rowArray[196] = '3C17227|SuperStack 3 Switch 4400 Stacking Kit|448|true';
rowArray[197] = '3C17228|SuperStack 3 Switch 4400 Stack Extender Kit|445|true'; // last entry under job id PCZI-534FVB
rowArray[198] = '3C17701|SuperStack 3 Switch 4924|9,995|true'; // added under job id PCZI-54MK5C
rowArray[200] = '3C16988A|SuperStack 3 3300 MM|2,095|true';
rowArray[201] = '3C996-T|10/100/1000 PCI-X Server network Interface Card|219|true';
rowArray[202] = '3C17706|3Com&reg; SuperStack&reg; 3 Switch 4950|13,995|true';
rowArray[203] = '3C17204|SuperStack 3 Switch 4400 48pt|3,295|true';
rowArray[204] = '3C16465C|3Com&reg; SuperStack&reg; 3 Baseline 10/100 Switch 24-Port|775|true';
rowArray[205] = '3CR16110-95|3Com&reg; SuperStack&reg; 3 Firewall|4,999|true';
rowArray[207] = '3CR856-95|3Com&reg; OfficeConnect&reg; Cable/DSL Secure Gateway|350|true';

/*Add rows here ^ above 
DO NOT duplicate element numbers.
*/

// END OF USER EDITABLE AREA ****************************************************
var rows = rowArray.length;


//make a clean array which we can guarantee has no gaps in it. 
cleanArray = new Array(rowArray.length);
var count = 0;
for (i=0;i<rowArray.length;i++)
{
  if(rowArray[i])
    cleanArray[count++] = rowArray[i];
}
cleanArray.length = count; // trim off any unused elements.
var cleanRows = cleanArray.length;
sortArray(); // sort the array by part number.

  
  
//sort the array
function sortArray()
{
  var temp = '';
  // we need to select one field from the array to use as the sorting element. This is because the pipe character has a high value & will evaluate (1A|red < 1|red) == true
  // here we will sort by the first table column, ie the string before the first | character.
  for (j = 2 ; j < cleanRows ; j ++)
    for (k = 2; k < cleanRows ; k++)
    {
      if (cleanArray[k].substring(0,cleanArray[k].indexOf('|') ) < cleanArray[k-1].substring(0,cleanArray[k-1].indexOf('|')) )// swap if true
  	  {
	    temp = cleanArray[k-1];
	    cleanArray[k-1] = cleanArray[k];
	    cleanArray[k] = temp;
	  }
    }
}


function removePrice() //this removes the right hand data segments from every element in cleanArray, leaving "3Cnumber|description". Used by writeTable() which only wants 3Com numbers & description.
{// receive a string, leave string unchanged, return a new, shortened string.
    return arguments[0].replace(/(\|[^\|]*){2,2}$/,'');
}
function isAdvanceReplacement()
{//receive a string (usually an element in cleanArray) & return boolean as to whether this item is an Advance Warranty item.
  return arguments[0].match(/true$/)
}

function writeTable(argBdr, argWidth, argSpacing, argPadding, argBoldHead) //(int, int, int, int, bool) - without price information. 
{// send additional argument 'true' to override the advance warranty selection.
  var formattedRow = '';
  var rowString; // temp variable to hold the cleanArray row while it's chopped about so the array remains unchanged.
  var headFormatOpen =  (argBoldHead) ? '<b>' : '';
  var headFormatClose = (argBoldHead) ? '</b>': '';
  document.writeln('<table border="' + argBdr + '" cellspacing="' + argSpacing + '" cellpadding="' + argPadding + '" width="' + argWidth + '">');
  cellcol = '#ffffff';
  //write the header first, in case it has to be emphasized
  rowString = removePrice(cleanArray[0]);
  formattedRow = '<tr><td bgcolor="#d4d4d4" width="25%" valign="top" ><font face="arial,helvetica,sans-serif" size="2">' + headFormatOpen + rowString.replace(/\|/g, headFormatClose  + '</font></td><td bgcolor="#d4d4d4" width="75%" valign="top"><font face="arial,helvetica,sans-serif" size="2">' + headFormatOpen) + headFormatClose + '</font></td></tr>'; 
  document.writeln(formattedRow); 
  for (i = 1, rowsWritten = 1; i < cleanRows ; i++)
  {
    //is this one an advance preplacement part ?
	if(isAdvanceReplacement(cleanArray[i]) || arguments[5])// send additional argument 'true' to override the advance warranty selection.
	{
	  rowsWritten++;
      cellcol = (rowsWritten / 2 == Math.floor(rowsWritten / 2)) ? '#ffffff' : '#f5f5f5';
	  rowString = removePrice(cleanArray[i]);
      formattedRow = '<tr><td valign="top" bgcolor="' + cellcol + '"><font face="arial,helvetica,sans-serif" size="2">' + rowString.replace(/\|/g,'</font></td><td valign="top" bgcolor="' + cellcol + '"><font face="arial,helvetica,sans-serif" size="-1">') + '</font></td></tr>'; 
	  document.writeln(formattedRow); 
	}
  }

  document.writeln('</table>');
}

function writeTableAllFields(argBdr, argWidth, argSpacing, argPadding, argBoldHead) //(int, int, int, int, bool) - without price information. 
{// send additional argument 'true' to override the advance warranty selection.
  var formattedRow = '';
  var rowString; // temp variable to hold the cleanArray row while it's chopped about so the array remains unchanged.
  var headFormatOpen =  (argBoldHead) ? '<b>' : '';
  var headFormatClose = (argBoldHead) ? '</b>': '';
  document.writeln('<table border="' + argBdr + '" cellspacing="' + argSpacing + '" cellpadding="' + argPadding + '" width="' + argWidth + '">');
  cellcol = '#ffffff';
  //write the header first, in case it has to be emphasized
  rowString = cleanArray[0];
  formattedRow = '<tr><td bgcolor="#d4d4d4" width="25%" valign="top" ><font face="arial,helvetica,sans-serif" size="2">' + headFormatOpen + rowString.replace(/\|/g, headFormatClose  + '</font></td><td bgcolor="#d4d4d4" width="75%" valign="top"><font face="arial,helvetica,sans-serif" size="2">' + headFormatOpen) + headFormatClose + '</font></td></tr>'; 
  document.writeln(formattedRow);
  for (i = 1, rowsWritten = 1; i < cleanRows ; i++)
  {
    //is this one an advance preplacement part ?
	if(isAdvanceReplacement(cleanArray[i]) || arguments[5])// send additional argument 'true' to override the advance warranty selection.
	{
	  rowsWritten++;
      cellcol = (rowsWritten / 2 == Math.floor(rowsWritten / 2)) ? '#ffffff' : '#f5f5f5';
	  rowString = cleanArray[i];
      formattedRow = '<tr><td valign="top" bgcolor="' + cellcol + '"><font face="arial,helvetica,sans-serif" size="2">' + rowString.replace(/\|/g,'</font></td><td valign="top" bgcolor="' + cellcol + '"><font face="arial,helvetica,sans-serif" size="-1">') + '</font></td></tr>'; 
	  document.writeln(formattedRow); 
	}
  }
  document.writeln('</table>');
}

// ###################################### Table sorter Ends ###########################################################


/*
DATA SOURCE FUNCTIONS.
additional code to provide an array of objects for use in the external page.
arrParts is an array of TPart objects whose data members are description, number and price.
*/


function TPart(argNum, argDesc, argPrice, argAdvanceReplacement)
{
  this.description = argDesc;
  this.number = argNum;
  this.price = argPrice;
  this.advanceReplacement = argAdvanceReplacement;
  return this
}

var arrParts = new Array();
var m;
//alert(RegExp.leftContext + ' - ' + m[1] + ' - ' + RegExp.rightContext);
for (a = 0; a < cleanArray.length; a++)
{
  m = cleanArray[a].match(/^([^\|]*)\|([^\|]*)\|([^\|]*)\|([^\|]*)/); //retrieve the information of interest from each string element.
  arrParts[a] = new TPart(m[1],m[2],m[3],m[4]);
}
//to use: arrParts[0].description, arrParts[0].number and '$' + arrParts[0].price + '.00' to format the price correctly.
// arrParts[0].advanceReplacement returns true or false.


