//Define arrays describing the possible card choices
var arrCardName = new Array(22);
var arrCardImage = new Array(22);
var arrCardDescription = new Array(22);
var arrCardCode = new Array(22);
var arrCardWeight = new Array(22);
var arrCardURL = new Array(22);

var bHzOption = false; // global variable showing the current HazEnv status

//Define array describing what is currently selected in the slots
var arrSlotCode = new Array(6);

//constants
var CARD_WEIGHT = 1;
var CARD_DESCRIPTION = 2;
var CARD_NAME = 3;
var CARD_IMAGE = 4;
var CARD_URL = 5;

var DEFAULT_INSTRUCTIONS = "Explore the options of the RMC by clicking on each module and reading its description. <br ><br >Create the motion controller of your choice by clicking on the modules. <br >";

var CARD_IMG_LOC = "/rmcquote/images/quoteme150/";
var DELETE_CARD = "DELETE";
var CANCEL_SELECTION = "Return to General Instructions";

//Card data
arrCardCode[0] = "";
arrCardName[0] = "Expand the RMC";
arrCardImage[0] = CARD_IMG_LOC + "crd_choices2.gif";
arrCardDescription[0] = "These controllers are factory configured to one CPU, one to four I/O modules providing up to 8 axes, and an optional DI/O module in the leftmost slot.	Almost any combination can be specified to fit almost any application: linear or rotary, position, pressure, or position/pressure control. Click as indicated above to expand the controller.";
arrCardURL[0] = ""
arrCardWeight[0] = 0;

arrCardCode[1] = "DNET";
arrCardName[1]	= "Device Net";
arrCardImage[1] = CARD_IMG_LOC + "5.gif";
arrCardDescription[1] = "";
arrCardURL[1] = ""
arrCardWeight[1] = 1;
	
arrCardCode[2] = "DI/O";
arrCardName[2]	= "DI/O (18in, 8 out)";
arrCardImage[2] = CARD_IMG_LOC + "2.gif";
arrCardDescription[2] = "The DI/O module supports fast (control loop speed) response to external inputs and triggering of external outputs, and can provide an interface to any system or be used in stand-alone applications. In the leftmost slot, the part number is -DI/O. In the right-hand slots, the part number is -D.";
arrCardURL[2] = "/products/motion/rmc100/rmc100dio.php";
arrCardWeight[2] = 2;
altDIOCardName = "DI/O (18in, 8 out)";

arrCardCode[3] = "PROFI";
arrCardName[3] = "PROFIBUS-DP";
arrCardImage[3] = CARD_IMG_LOC + "3.gif";
arrCardDescription[3] = "PROFIBUS is one of the fastest industrial fieldbuses in terms of control data response times.	Messaging performance varies by PLC.";
arrCardURL[3] = "/products/motion/rmc100/rmc100profi.php"
arrCardWeight[3] = 3;

arrCardCode[4] = "UI/O";
arrCardName[4]	= "Universal I/O";
arrCardImage[4] = CARD_IMG_LOC + "uio.png";
arrCardDescription[4] = "The module provides two analog inputs, six discrete I/O, and two high-speed channels configurable as quadrature inputs,  SSI inputs or outputs, or even inter-controller communications for synchronizing axes between RMCs.  In the leftmost slot, the part number is -UI/O.  In the right-hand slots, the part number is -U."
arrCardURL[4] = "/products/motion/rmc100/rmc100uio.php"
arrCardWeight[4] = 6;

arrCardCode[5] = "SERIAL";
arrCardName[5]	= "Serial (RS-232/422/485)";
arrCardImage[5] = CARD_IMG_LOC + "7.gif";
arrCardDescription[5] = "This module provides a cost-effective interface to a wide variety of host systems.	Both response time and messaging performance vary by PLC.";
arrCardURL[5] = "/products/motion/rmc100/rmc100serial.php"
arrCardWeight[5] = 5;
		
arrCardCode[6] = "MB+";
arrCardName[6]	= "Modbus Plus";
arrCardImage[6] = CARD_IMG_LOC + "4.gif";
arrCardDescription[6] = "This module allows tremendous data flexibility to maximize performance of this medium performance bus.";
arrCardURL[6] = "/products/motion/rmc100/rmc100mbp.php"
arrCardWeight[6] = 4;

arrCardCode[7] = "M";
arrCardName[7]	= "(M) MDT (2 axes, analog output)";
arrCardImage[7] = CARD_IMG_LOC + "9.gif";
arrCardDescription[7] = "This module (-M) interfaces with magnetostrictive displacement transducers as position feedback devices and provides analog drive outputs.";
arrCardURL[7] = "/products/motion/rmc100/rmc100mdt.php"
arrCardWeight[7] = 7;
		
arrCardCode[8] = "S";
arrCardName[8]	= "(S) SSI (2 axes, analog output)";
arrCardImage[8] = CARD_IMG_LOC + "10.gif";
arrCardDescription[8] = "This module (-S) interfaces with a wide variety of position feedback devices that use the Synchronous Serial Interface standard and provides analog drive outputs. SSI devices typically offer absolute positions at high resolutions.";
arrCardURL[8] = "/products/motion/rmc100/rmc100ssi.php"
arrCardWeight[8] = 8;

arrCardCode[9] = "na";			//"SST"
arrCardName[9]	= "(SST) SSI (2 axes, stepper output)";
arrCardImage[9] = CARD_IMG_LOC + "16.gif";
arrCardDescription[9] = "This module (-SST) allows stepper control with a wide variety of position feedback devices using the Synchronous Serial Interface standard.";
arrCardURL[9] = "/products/motion/rmc100/rmc100ssi.php"
arrCardWeight[9] = 9;

arrCardCode[10] = "R";
arrCardName[10]	= "(R) Resolver (2 axes, analog output)";
arrCardImage[10] = CARD_IMG_LOC + "16.png";
arrCardDescription[10] = "This module (-R) interfaces with resolvers for position feedback and provides analog drive outputs for closed loop control. Resolvers are absolute rotary transducers capable of operating in harsh environments.";
arrCardURL[10] = "/products/motion/rmc100/rmc100res.php"
arrCardWeight[10] = 10;

arrCardCode[11] = "Q";
arrCardName[11]	= "(Q) Quadrature (2 axes, analog out)";
arrCardImage[11] = CARD_IMG_LOC + "11.gif";
arrCardDescription[11] = "This module (-Q) interfaces with quadrature encoders and provides analog drive outputs for closed loop control. The inputs can also be used alone for position reference (gearing).";
arrCardURL[11] = "/products/motion/rmc100/rmc100quad.php"
arrCardWeight[11] = 11;

arrCardCode[12] = "na";		//QST
arrCardName[12]	= "(QST) Quadrature (2 axes, stepper output)";
arrCardImage[12] = CARD_IMG_LOC + "12.gif";
arrCardDescription[12] = "This module (-QST) provides stepper control.	The quadrature encoder inputs can be used for axis feedback or for position reference (gearing).";
arrCardURL[12] = "/products/motion/rmc100/rmc100step.php"
arrCardWeight[12] = 12;

arrCardCode[13] = "H";
arrCardName[13]	= "(H) Analog - 16-bit (4 inputs, 2 axes)";
arrCardImage[13] = CARD_IMG_LOC + "13.gif";
arrCardDescription[13] = "This module (-H) interfaces to analog position or pressure feedback devices for position, pressure, or position/pressure control. Pressure inputs can be used together with position inputs on this or other I/O modules to provide position/pressure control. Pressure control requires the RMC151 CPU.";
arrCardURL[13] = "/products/motion/rmc100/rmc100anlg.php"
arrCardWeight[13] = 14;

arrCardCode[14] = "G";
arrCardName[14]	= "(G) Analog - 16-bit (2 inputs, 2 axes)";
arrCardImage[14] = CARD_IMG_LOC + "14.gif";
arrCardDescription[14] = "This module (-G) provides cost-effective analog position and pressure control. Its 16-bit voltage inputs can also be used for position-pressure control. For 4-20mA current feedback, use the –H analog module. Position-pressure or position-force control requires the RMC151 CPU.";
arrCardURL[14] = "/products/motion/rmc100/rmc100anlg.php"
arrCardWeight[14] = 14.5; // decimal to make it weigh between 14 and 15 without renumbering

arrCardCode[15] = "SO";
arrCardName[15]	= "(SO) SSI (1 axis, SSI+analog out)";
arrCardImage[15] = CARD_IMG_LOC + "so.png";
arrCardDescription[15] = "This module (-SO) allows for synchronizing multiple RMCs to a single SSI position transducer.";
arrCardURL[15] = "/products/motion/rmc100/rmc100so.php"
arrCardWeight[15] = 8.5; // decimal to make it weigh between 8 and 9 without renumbering

arrCardCode[16] = "U";
arrCardName[16]	= "(U) 2 analog inputs, 6 DI/O, 2 Quad/SSI";
arrCardImage[16] = CARD_IMG_LOC + "uio.png";
arrCardDescription[16] = "The module provides two analog inputs, six discrete I/O, and two high-speed channels configurable as quadrature inputs,  SSI inputs or outputs, or even inter-controller communications for synchronizing axes between RMCs.  In the leftmost slot, the part number is -UI/O.  In the right-hand slots, the part number is -U.";
arrCardURL[16] = "/products/motion/rmc100/rmc100uio.php"
arrCardWeight[16] = 15.5; // decimal to make it weigh between 15 and 16 without renumbering


arrCardCode[17] = "A";
arrCardName[17]	= "(A) Analog - 12-bit (4 inputs)";
arrCardImage[17] = CARD_IMG_LOC + "15.gif";
arrCardDescription[17] = "This module (-A) provides 12-bit analog inputs to be used together with another I/O module for position/pressure control, or alone for position or velocity reference. Pressure control requires the RMC101 CPU.";
arrCardURL[17] = "/products/motion/rmc100/rmc100anlg.php"
arrCardWeight[17] = 16;

arrCardCode[18] = "D";
arrCardName[18]	= "DI/O (18in, 8 out)";
arrCardImage[18] = CARD_IMG_LOC + "2.gif";
arrCardDescription[18] = "The DI/O module supports fast (control loop speed) response to external inputs and triggering of external outputs, and can provide an interface to any system or be used in stand-alone applications. In the leftmost slot, the part number is -DI/O. In the right-hand slots, the part number is -D.";
arrCardURL[18] = "/products/motion/rmc100/rmc100dio.php"
arrCardWeight[18] = 16;

arrCardCode[19] = "RMC150E";
arrCardName[19]	= "RMC150 CPU";
arrCardImage[19] = CARD_IMG_LOC + "8.gif";
arrCardDescription[19] = "The RMC150 supports up to 8 axes of position only or pressure only control. The RMC151 controls up to 8 position or pressure (single-loop) axes or up to 8 position/pressure (dual-loop) axes. You must select an analog I/O module for pressure inputs before you can select the RMC151 CPU.";
arrCardURL[19] = "/products/motion/rmc100/cpu150.php"
arrCardWeight[19] = 17;

arrCardCode[20] = "RMC151E";
arrCardName[20]	= "RMC151 CPU";
arrCardImage[20] = CARD_IMG_LOC + "8.gif";
arrCardDescription[20] = "The RMC151 controls up to 8 position or pressure (single-loop) axes or up to 8 position/pressure (dual-loop) axes. This CPU, which contains the Pressure/Force Control Firmware Option, requires at least one analog I/O module for pressure inputs. If pressure control is not needed, the RMC150 can be used for up to 8 axes of position control.";
arrCardURL[20] = "/products/motion/rmc100/cpu150.php"
arrCardWeight[20] = 18;

arrCardCode[21] = "CHOICE";
arrCardName[21] = "Expand the RMC";
arrCardImage[21] = CARD_IMG_LOC + "crd_choices2.gif";
arrCardDescription[21] = "These controllers are factory configured to one CPU, one to four I/O modules providing up to 8 axes, and an optional DI/O module in the leftmost slot.	Almost any combination can be specified to fit almost any application: linear or rotary, position, pressure, or position/pressure control. Click as indicated above to expand the controller.";
arrCardURL[21] = ""
arrCardWeight[21] = 100;

arrCardCode[22] = "BLANK";
arrCardName[22]	= "BLANK";
arrCardImage[22] = CARD_IMG_LOC + "1.gif";
arrCardDescription[22] = "The leftmost slot can be empty (blank) or contain a Discrete I/O module (18in, 8 out).";
arrCardURL[22] = ""
arrCardWeight[22] = 20;

arrCardCode[23] = "BL";
arrCardName[23]	= "Blank Slot Cover";
arrCardImage[23] = CARD_IMG_LOC + "1.gif";
arrCardDescription[23] = "The blank slot cover allows an RMC to be built with an empty slot to allow room for later expansion.";
arrCardURL[23] = ""
arrCardWeight[23] = 21;

arrCardCode[24] = "EMPTY";
arrCardName[24]	= "Empty Slot";
arrCardImage[24] = CARD_IMG_LOC + "1.gif";
arrCardDescription[24] = "";
arrCardURL[24] = ""
arrCardWeight[24] = 22;

//Assign initial values to the slots.
arrSlotCode[0] = arrCardCode[22];
arrSlotCode[1] = arrCardCode[19];
arrSlotCode[2] = arrCardCode[8];
arrSlotCode[3] = arrCardCode[21];
arrSlotCode[4] = arrCardCode[21];
arrSlotCode[5] = arrCardCode[21];

function QuoteMe(sPartNo,type)
{
	/*Uncomment the following line of code to turn on passing the "type" parameter to the form */ 
	//OpenWindow("/rmcquote/quoteme.php?" + sPartNo + "&type=" + type);
	window.location.href = "/rmcquote/quoteme.php?" + sPartNo + "&type=" + type;
	
	/*Comment the following line of code to turn on passing the "type" parameter to the form */
	//OpenWindow("/rmcquote/quoteme.shtml?" + sPartNo);
}

function InitCards()
{
	var i;
	
	lyrWrt("instructions", DEFAULT_INSTRUCTIONS);
	
	for (i = 0; i < arrSlotCode.length; i++)
		lyrWrt("imgslot" + i, "<img src=\"" + GetCardInfo(arrSlotCode[i], CARD_IMAGE) + "\" border=\"0\" width=\"37\" height=\"220\">");
	lyrWrt("partno", GetPartNo());
}

function ResetAppControls()
{
	//Set Text Area to nothing
	$('#txtDescription').text('');
	
	//Reset Pressure Check Box to unchecked
	$('#chkPressure').attr('checked', false);
	
}

function OpenWindow(url,name)
{
	var newwindow;
	newwindow = window.open(url, name);
	newwindow.focus();
}

/************************************************************************************
*Writes out information using the correct syntax for the specific browser
************************************************************************************/
function lyrWrt(element,text) 
{	
	// removed browser detect code. this should work on every modern browser:
	document.getElementById(element).innerHTML = text;
}

/************************************************************************************
*Given the code, will search through the card information and return the requested data
************************************************************************************/
function GetCardInfo(code, info)
{
	var i;
	var val;
	val = "";
	for (i = 0; i < arrCardCode.length; i++)
	{
		if (code == arrCardCode[i])
		{
			//Values used instead of variable label to account for Netscape 4.x bug
			switch (info)
			{
				case CARD_WEIGHT:
					val = arrCardWeight[i];	break;
				case CARD_DESCRIPTION:
					val = arrCardDescription[i]; break;
				case CARD_NAME:
					val = arrCardName[i]; break;
				case CARD_IMAGE:
					val = arrCardImage[i]; break;
				case CARD_URL:
					val = arrCardURL[i]; break;							
				default:

			}
		}
	
	}
	return (val);
}

/************************************************************************************
*Given the slot, displays all the valid card choices
************************************************************************************/
function DisplayCardChoices(slot)
{
	var val;
	var SlotHRef;
	var j;
	var i;
	var iLowSlot;
	var iHighSlot;
				
	//Set slot pointer
	SetSlotPointer(slot, -1)

	//Alternate card name exception for DI/O
	if ("DI/O" == arrSlotCode[slot])
		lyrWrt("txtName",altDIOCardName );
	else
		lyrWrt("txtName",GetCardInfo(arrSlotCode[slot], CARD_NAME));


	//document.forms[0].txtDescription.value = GetCardInfo(arrSlotCode[slot], CARD_DESCRIPTION);
	$('#txtDescription').text(GetCardInfo(arrSlotCode[slot], CARD_DESCRIPTION));

	lyrWrt("moreinfo", " ");
	
	if ("" != GetCardInfo(arrSlotCode[slot], CARD_URL))
		lyrWrt("moreinfo", "<a href=\"javascript:OpenWindow('" + GetCardInfo(arrSlotCode[slot], CARD_URL) + "','moreinfo');\">Get more info</a>");

	//Update instructions to list of cards
	//The following code is for demo.	
	//Intended to be replaced with more dynamic information
	val = "Choose a module from the following list:<br/>";
	val += "<div style='margin-left: 5px;'>";
	switch (slot)
	{
		case "0":
			iLowSlot = 2;
			iHighSlot = 4;
			break;
			
		//CPU slot
		case "1":
			iLowSlot = 19;
			iHighSlot = 20;
			break;
			
		case "2":
			iLowSlot = 7;
			iHighSlot = 16;
			break;

		default:
			iLowSlot = 7;
			iHighSlot = 18;
	}	
	
	for (i = iLowSlot; i <= iHighSlot; i++)
	{
		if ("D" == arrCardCode[i])
		{
			SlotHRef = "javascript:InsertCard(" + slot + ", \"" + arrCardCode[i] + "\");";
			val += "<a href='" + SlotHRef + "'>" + GetCardInfo(arrCardCode[i], CARD_NAME) + "</a><br/>";
		}
		//Rule check for RMC150CPU.	If not available, then disable, (vs. hide.)
		else if (!CPURuleCheck() && ("RMC151E" == arrCardCode[i]) ) 
		{
			val += GetCardInfo(arrCardCode[i], CARD_NAME) + "<br/>";
		}
		else if ("na" != arrCardCode[i])
		{
			SlotHRef = "javascript:InsertCard(" + slot + ", \"" + arrCardCode[i] + "\");";
			val += "<a href='" + SlotHRef + "'>" + GetCardInfo(arrCardCode[i], CARD_NAME) + "</a><br/>";
		}
	}

	//Display BLANK for left-most slot
	if (slot == 0 )
	{
		SlotHRef = "javascript:InsertCard(0, \"" + arrCardCode[22] + "\");";
		val += "<a href='" + SlotHRef + "'>" + GetCardInfo(arrCardCode[22], CARD_NAME) + "</a><br/>";
	}
	
	// Show the blank cover on any expansion slot
	if(slot > 1)
	{
		SlotHRef = "javascript:InsertCard(" + slot + ", \"" + arrCardCode[23] + "\");";
		val += "<a href='" + SlotHRef + "'>" + GetCardInfo(arrCardCode[23], CARD_NAME) + "</a><br/>";
	}

	//Write out "Return to General Instructions" link at bottom
	SlotHRef = "javascript:InsertCard(" + slot + ", \"" + CANCEL_SELECTION + "\");";
	val += "<br/><a href='" + SlotHRef + "'>" + CANCEL_SELECTION + "</a><br/>";

	//Write out "Delete: link at bottom when required
	if (arrSlotCode[slot] != arrCardCode[21] && (slot > 2) )
	
	{
		SlotHRef = "javascript:InsertCard(" + slot + ", \"" + DELETE_CARD + "\");";
		val += "<a href='" + SlotHRef + "'>" + DELETE_CARD + "</a><br/>";
	}
	val+="</div>";
	lyrWrt("instructions", val);
}


/************************************************************************************
*CPU rule checking to allow or not allow the RMC151
************************************************************************************/
function CPURuleCheck()
{
	var i;
	var bFoundAnalog;
	
	bFoundAnalog = false;
	
	//Check for an analog card (A, G, H).	If so, then enable the RMC101
	for (i = 0; i < arrSlotCode.length; i++)
	{
		if (arrSlotCode[i] == "A" ||
			arrSlotCode[i] == "G" ||
			arrSlotCode[i] == "U" ||
			arrSlotCode[i] == "UI/O" ||
			arrSlotCode[i] == "H")
		{
			bFoundAnalog = true;
		}
	}
	if (true == bFoundAnalog)
	{
		$('#chkPressure').attr('disabled', false);
	}
	else
	{
		//Since no analog, then slot 2 to RMC150
		$('#chkPressure').attr('disabled', true);
		$('#chkPressure').attr('checked', false); 
		arrSlotCode[1] = arrCardCode[19];
	}
	
	return (bFoundAnalog);
}

/************************************************************************************
*Rule checking to allow or not allow -HZ (Class I, Div 2)
************************************************************************************/
function HZRuleCheck()
{
	var i;
	var bInvalidFound;
	
	for (i = 0; i < arrSlotCode.length; i++)
	{
		if (arrSlotCode[i] == "U" ||
			arrSlotCode[i] == "UI/O" ||
			arrSlotCode[i] == "G")
		{
			bInvalidFound = true;
		}
	}
	
	if(bInvalidFound)
	{
		$('#chkHz').attr('disabled', true);
		$('#chkHz').attr('checked', false);
		bHzOption = false;
	}
	else
	{
		$('#chkHz').attr('disabled', false);
	}
	
	return (!bInvalidFound);
}

/************************************************************************************
*Moves the slot pointer
************************************************************************************/
function SetSlotPointer(slot,iNewCard)
{
	for (i = 0; i < arrSlotCode.length; i++)
	{
			lyrWrt("slotpointer" + i, "<img src=/rmcquote/images/common/emptyslotarrow.gif>");
	}
				
	//Set the correct if not -1.	-1 means to just reset the pointers, but do not
	//set the arrow position.
	if ((-1 != slot) && (-1 != iNewCard))
		lyrWrt("slotpointer" + slot, "<img src=/rmcquote/images/common/slotarrow.gif>");
	else 
		if (-1 == iNewCard)
			lyrWrt("slotpointer" + slot, "<img src=/rmcquote/images/common/slotarrow.gif>");

	//Display Get More Info URL
	if ("" != GetCardInfo(arrSlotCode[slot], CARD_URL))
		lyrWrt("moreinfo", "<a href=\"javascript:OpenWindow('" + GetCardInfo(arrSlotCode[slot], CARD_URL) + "','moreinfo');\">Get more info</a>");
}

/************************************************************************************
*Performs act of inserting the new card and applying all business rules.
************************************************************************************/
function InsertCard(slot, iNewCard)
{
	//Cancel choice selection and set text back to instructions.
	if (iNewCard == CANCEL_SELECTION)
	{
		lyrWrt("instructions", DEFAULT_INSTRUCTIONS);
		return;
	}				
	else if (iNewCard == DELETE_CARD) //if "DELETE", then set to choice image
	{
		iNewCard = arrCardCode[21];				
	}

	arrSlotCode[slot] = iNewCard;
	lyrWrt("imgslot" + slot, "<img src=\"" + GetCardInfo(arrSlotCode[slot], CARD_IMAGE) + "\" border=\"0\" width=\"37\" height=\"220\">");
	
	//Alternate card name exception for DI/O
	if ("DI/O" == iNewCard)
		lyrWrt("txtName",altDIOCardName );
	else
		lyrWrt("txtName",GetCardInfo(iNewCard, CARD_NAME));
	
	$('#txtDescription').text(GetCardInfo(iNewCard, CARD_DESCRIPTION));

	//If the next slot is "BLANK", then set to card choice message
	if (slot != (arrSlotCode.length - 1) )
		if ( arrSlotCode[slot + 1] == "BLANK" )
		{
			arrSlotCode[slot + 1] == arrCardCode[21];
			lyrWrt("imgslot" + i, "<img src=\"" + GetCardInfo(arrSlotCode[19], CARD_IMAGE) + "\" border=\"0\">");
		}
	
	//If slot 2 and RMC151 is selected, then check chkPressure
	if ( 1 == slot )
	{
		if (arrSlotCode[1] == arrCardCode[20])
			$('#chkPressure').attr('checked', true);
		else
			$('#chkPressure').attr('checked', false);
	}
			
	CPURuleCheck();
	HZRuleCheck();
	ResortSlots(slot, iNewCard);
	lyrWrt("partno", GetPartNo());

	//The slot has been updated.	Revert back to the default instructions
	lyrWrt("instructions", DEFAULT_INSTRUCTIONS);
}

/************************************************************************************
*Generates the part number
************************************************************************************/
function GetPartNo()
{
	var i;
	var Slot;
	var cENET
	var cMDT;
	var cSSI;
	var cSO;
	var cSSIStep;
	var cAna12;
	var cAna16;
	var cAnaG;
	var cQuad;
	var cStep;
	var cDIO;
	var cUIO;
	var cBlanks;
	var cResolver;
	var sPartNo;
	var cBl;

	sPartNo = "";
	Slot = "";
	cMDT = cSSI = cSO = cSSIStep = cAna12 = cAna16 = cAnaG = cQuad = cStep = cDIO = cBlanks = cResolver = cPos = cAux = cUIO = cBl = 0;

	for ( i= 2; i < arrSlotCode.length; i++ )
	{
	
		Slot = arrSlotCode[i];
		switch(Slot)
		{
			case "M":
				cMDT++; break
			case "S":
				cSSI++; break;
			case "SO":
				cSO++; break;
			case "SST":
				cSSIStep++; break;
			case "A":
				cAna12++; break;
			case "H":
				cAna16++; break;
			case "G":
				cAnaG++; break;
			case "Q":
				cQuad++; break;
			case "QST":
				cStep++; break;
			case "R":
				cResolver++; break;
			case "D":
				cDIO++; break;
			case "U":
				cUIO++; break;
			case "BLANK":
				cBlanks++; break;
			case "BL":
				cBl++; break;
		}
	}

	//Create and display part no
	sPartNo += arrSlotCode[1];

	if (cMDT > 0) sPartNo += "-M" + cMDT;
	if (cSSI> 0) sPartNo += "-S" + cSSI;
	if (cSO> 0) sPartNo += "-SO" + cSO;
	if (cSSIStep > 0) sPartNo += "-SST" + cSSIStep;
	if (cResolver > 0) sPartNo += "-R" + cResolver;
	if (cQuad > 0) sPartNo += "-Q" + cQuad;
	if (cStep > 0) sPartNo += "-QST" + cStep;
	if (cAna16 > 0) sPartNo += "-H" + cAna16;
	if (cAnaG > 0) sPartNo += "-G" + cAnaG;
	if (cAna12 > 0) sPartNo += "-A" + cAna12;
	if (cUIO > 0) sPartNo += "-U" + cUIO;
	if (cDIO > 0) sPartNo += "-D" + cDIO;
	if (cBl > 0) sPartNo += "-BL" + cBl;
	if (arrSlotCode[0] != "BLANK")
		sPartNo += "-" + arrSlotCode[0];

	if(bHzOption) { // bHzOption is a global variable
		sPartNo += "-HZ";
	}
	
	return (sPartNo);
}

/************************************************************************************
*Rearanges the cards into the correct order.
************************************************************************************/
function ResortSlots(slot, sNewCard)
{
	var i;
	var j;
	var sCurrentCard;
	var iSelectedCardLoc = slot;

	for (i = 2; i < arrSlotCode.length; i++)
	{
		for (j = i; j < arrSlotCode.length; j++)
		{
			sCurrentCard = arrSlotCode[i];

			// Compare the weights of the cards (positioning weight) and shift, if necessary.
			if (GetCardInfo(sCurrentCard, CARD_WEIGHT) > GetCardInfo(arrSlotCode[j], CARD_WEIGHT) )	
			{

				//Remember the position of the card we just added
				if (i == iSelectedCardLoc)
					iSelectedCardLoc = j
				else if (j == iSelectedCardLoc)
					iSelectedCardLoc = i

				//Switch the cards
				arrSlotCode[i] = arrSlotCode[j];
				arrSlotCode[j] = sCurrentCard;
			}
		}
	}
	//Apply array to actual slots
	for (i = 2; i < arrSlotCode.length; i++)
		lyrWrt("imgslot" + i, "<img src=\"" + GetCardInfo(arrSlotCode[i], CARD_IMAGE) + "\" border=\"0\" width=\"37\" height=\"220\">");
	
	//Move the pointer to the recently added cards location
	SetSlotPointer(iSelectedCardLoc,0);	
}

/************************************************************************************
*Based on the checkbox for Pressure/Force, select the RMC100 or 101
************************************************************************************/
function ChooseCPU()
{
	if ($('#chkPressure').attr('checked')) {
		InsertCard(1, arrCardCode[20]);
	}
	else
		InsertCard(1, arrCardCode[19]);

	SetSlotPointer(1, 0);
}

/************************************************************************************
*Based on the checkbox for Hazardous Environments, set the hz option
************************************************************************************/
function ChooseHZ()
{
	if(true == $('#chkHz').attr('checked') && HZRuleCheck()) {
		bHzOption = true; // bHzOption is a global variable
	}
	else {
		bHzOption = false; // bHzOption is a global variable
	}
	
	lyrWrt("partno", GetPartNo());
}
