//selector.js
//Product Part Selector for Champion Electronics Online
//Jayesh Sheth, November 01, 2002
//Version 0.1
var ourform = document.forms[0] ;
var cdistselected = false;
// Create arrays to store the number of pins for each center distance value
/*
center_index1 | 5.08 mm
center_index2 | 7.62 mm
center_index3 | 10.16 mm
center_index4 | 15.24 mm
center_index5 | 22.86 mm
*/
center_index1 = new Array;
center_index1 = [10]

center_index2 = new Array;
center_index2 = [4,6,8,14,16,18,20,22];

center_index3 = new Array;
center_index3 = [20,22,24,28,32];

center_index4 = new Array;
center_index4 = [10,24,28,32,36,40,42,28,50,52];

center_index5 = new Array;
center_index5 = [50,52,64];

var selection;
centerdistances = new Array;
centerdistances = ["noindexzero", center_index1, center_index2, center_index3, center_index4, center_index5];

// create an array to store the two digit part number code for the chosen center distance
fragment_cd = new Array;
fragment_cd = ["noindexzero","020","030","040","060","090"];

// create an array to store the two digit part number code for the chosen plating
fragment_plating = new Array;
fragment_plating = ["11","12","15","18"];

//create a variable to store the prefix for this part number
var prefix = "SPD";

//create a varibale to store the 'middlefix' for this part number
var middlefix = "BC"

var centerfragment;
function makecfragment (selection)
// creat a function to look up the part number fragment for the center distance selected
{
centerfragment = fragment_cd[selection];
//alert("centerfragment is " + centerfragment);
}

var pinfragment;
function makepincode()
//create a function which will take the number of pins selected, and convert it to a three digit number
// this creates the 3 digit part number fragment for the number of pins
{
if (document.forms[0].pins.options.selectedIndex >= 0 )
{
pinfragment = document.forms[0].pins.options[document.forms[0].pins.options.selectedIndex].text;
pinfragment = parseInt(pinfragment);

	if (pinfragment <= 9)
	{
	pinfragment = "00" + pinfragment;
	}
	
	else if (pinfragment > 9)
	{
	pinfragment = "0" + pinfragment;
	}
}
	else 
	{
	alert ("An error has occured while choosing the pincode.");
	}
	//alert("pinfragment is " + pinfragment);
}

var plating_fragment;

function findplatingcode()
//create a function to determine what the current chosen plating code is, and convert it to a string.
{
plating_fragment = fragment_plating[document.forms[0].plating.options.selectedIndex];
//alert ("plating_fragment is " + plating_fragment);
}

// define the partnumber fragment separator
var sep = "-";

// create a variable to hold the complete part number
var partnumber;

function makepartnum()
//create a function to assemble a part number, based on the fragments of information which we have gathered
{
	if ((!cdistselected))
	{
	alert ("Please choose the center distance, number of pins, and plating type first.");
	}
	else 
	{
		makepincode();
		findplatingcode();
		partnumber = prefix + sep  + centerfragment + sep + pinfragment + sep + middlefix + sep + plating_fragment;
		document.forms[0].partnumber.value = partnumber;
	}
}

var elemname;
function clearpins()
// create function to clear all the option values of the pins select box
{

	for(a = 0; a < document.forms[0].pins.length; a++)
			{
			document.forms[0].pins.options[a].text = "-";
			}
}

function fillpins(selection)
// populate the list of pins, when the center distance is selected
{
		if (selection == 0)
		{
		//alert("Please choose a center distance from the list.");
		clearpins();
		clearplating();
		}
		
		else
		{
		clearpins();
		makecfragment(selection);
		var currentindex = centerdistances[selection];
		//alert("current index is " + currentindex);
			
			for(j = 0; j < currentindex.length; j++)
			{
			//alert("currentindex[j] is " + currentindex[j] );
			document.forms[0].pins.options[j].text = currentindex[j];
			}
			fillplating();
			cdistselected = true;
		 }
}

function clearplating()
//create a function to clear the list of plating available
{

	for(c = 0; c < document.forms[0].plating.length; c++)
			{
			
			document.forms[0].plating.options[c].text = "-";
			}
}

// create array to store plating types
plating = new Array;
plating = ["5-7 micron Tin", "Goldflash", "0.25 micron Gold", "0.75 micron Gold"];

function fillplating()
//populate the list of plating, after the center distance has been selected.
{
for(b = 0; b < plating.length; b++)
			{
			
			document.forms[0].plating.options[b].text = plating[b];
			}
}


