// JavaScript Document

var familyMenu;
var polesMenu;
var typeMenu;
var wireMenu;
var unitMenu;
var textLeadLength;
var shellMenu;

var A_poles = ["Please Select...", "2 Poles", "3 Poles", "4 Poles", "5 Poles", "6 Poles"];
var B_poles = ["Please Select...", "6 Poles", "7 Poles", "8 Poles"];
var C_poles = ["Please Select...", "9 Poles", "10 Poles", "12 Poles"];


var std_types = ["Please Select...", "Female Straight, \u00BD\" - 14NPT Mounting Thread", "Male Straight, \u00BD\" - 14NPT Mounting Thread"];
var A_size_types = ["Please Select...", "Female Straight, \u00BD\" - 14NPT Mounting Thread", "Female 90\u00B0, \u00BD\" - 14NPT Mounting Thread", "Male Straight, \u00BD\" - 14NPT Mounting Thread", "Male 90\u00B0, \u00BD\" - 14NPT Mounting Thread", "Female Straight Flange Mount", "Male Straight Flange Mount"];
var Three_Five_types = ["Please Select...", "Female Straight, \u00BD\" - 14NPT Mounting Thread", "Female 90\u00B0, \u00BD\" - 14NPT Mounting Thread", "Male Straight, \u00BD\" - 14NPT Mounting Thread", "Male 90\u00B0, \u00BD\" - 14NPT Mounting Thread", "Female Straight PG13.5 Mounting Thread", "Male Straight PG13.5 Mounting Thread", "Female Straight Flange Mount", "Male Straight Flange Mount"];

var wires_3P = ["Please Select...", "18 AWG PVC UL 1015 IEC DC Color Code", "18 AWG PVC UL 1061 AUTO Color Code", "16 AWG PVC UL 1015 U.S. Color Code", "16 AWG PVC UL 1015 AUTO Color Code", "18 AWG PVC UL 1015 IEC AC Color Code"];
var wires_4P = ["Please Select...", "18 AWG PVC UL 1015 IEC DC Color Code", "18 AWG PVC UL 1061 AUTO Color Code", "16 AWG PVC UL 1015 U.S. Color Code"];
var wires_5P = ["Please Select...", "18 AWG PVC UL 1061 AUTO Color Code", "16 AWG PVC UL 1015 U.S. Color Code", "16 AWG PVC UL 1015 AUTO Color Code", "18 AWG PVC UL 1015 IEC AC Color Code"];
var wires_std = ["Please Select...", "16 AWG PVC UL 1015 U.S. Color Code"];

var std_shell = ["Zinc Diecast, Epoxy Coat"];
var ss_shell = ["Zinc Diecast, Epoxy Coat", "Stainless Steel, Type 303"];
var all_shell = ["Zinc Diecast, Epoxy Coat", "Stainless Steel, Type 303", "Non-Metallic Nylon"];

var family_code = ["", "1R", "2R", "3R"];

var A_poles_code = ["", "2", "3", "4", "5", "6"];
var B_poles_code = ["", "6", "7", "8"];
var C_poles_code = ["", "9", "1", "2"];

var std_types_code = ["", "004", "006"];
var A_size_types_code = ["", "004", "005", "006", "007", "G04", "G06"];
var Three_Five_types_code = ["", "004", "005", "006", "007", "D04", "D06", "G04", "G06"];

var wires_3P_code = ["", "A16", "A17", "A20", "A24", "A25"];
var wires_4P_code = ["", "A16", "A17", "A20"];
var wires_5P_code = ["", "A17", "A20", "A24", "A25"];
var wires_std_code = ["", "A20"];

var shells_code = ["", "1", "2"];









function family(Obj)
{
	var x;
	typeMenu = document.getElementById("selType");
	wireMenu = document.getElementById("selWire");
	polesMenu = document.getElementById("selPoles");	
	shellMenu = document.getElementById("selShell");
	
	
	switch(Obj.selectedIndex)
	{
		case 0:
			polesMenu.options.length = 0;			
			var y=document.createElement('option');
			y.text = "Please Select...";
			polesMenu.options[0] = y;			
		break;			
				
		case 1:			
			
			polesMenu.options.length = 0;			
			for (x = 0; x < A_poles.length; x++)
			{
				var y=document.createElement('option');
				y.text = A_poles[x];
				polesMenu.options[x] = y;				
			}
		break;
		
		case 2:			
			
			polesMenu.options.length = 0;			
			for (x = 0; x < B_poles.length; x++)
			{
				var y=document.createElement('option');
				y.text = B_poles[x];
				polesMenu.options[x] = y;			
			}
		break;
		
		case 3:			
			
			polesMenu.options.length = 0;			
			for (x = 0; x < C_poles.length; x++)
			{
				var y=document.createElement('option');
				y.text = C_poles[x];
				polesMenu.options[x] = y;			
			}
		break;
	}
	typeMenu.options.length = 0;
	wireMenu.options.length = 0;
	var y=document.createElement('option');
	y.text = "Please Select...";
	typeMenu.options[0] = y;
	y=document.createElement('option');
	y.text = "Please Select...";
	wireMenu.options[0] = y;
	shellMenu.options.length = 0;			
	for (x = 0; x < std_shell.length; x++)
	{
		var y=document.createElement('option');
		y.text = std_shell[x];
		shellMenu.options[x] = y;	
	}
	
	clearPartNum();
			
}

function poles(Obj)
{
	var x;
	familyMenu = document.getElementById("selFamily");
	typeMenu = document.getElementById("selType");
	wireMenu = document.getElementById("selWire");
	shellMenu = document.getElementById("selShell");
	
	clearPartNum();
	
	if (Obj.selectedIndex == 0)
	{
		typeMenu.options.length = 0;
		wireMenu.options.length = 0;
		var y=document.createElement('option');
		y.text = "Please Select...";
		typeMenu.options[0] = y;
		y=document.createElement('option');
		y.text = "Please Select...";
		wireMenu.options[0] = y;
		shellMenu.options.length = 0;			
		for (x = 0; x < std_shell.length; x++)
		{
			var y=document.createElement('option');
			y.text = std_shell[x];
			shellMenu.options[x] = y;	
		}
		
		return;
	}
		
	
	if(familyMenu.selectedIndex == 1)
	{
		if (Obj.selectedIndex >= 2 && Obj.selectedIndex <= 4)
		{
			typeMenu.options.length = 0;			
			for (x = 0; x < Three_Five_types.length; x++)
			{
				var y=document.createElement('option');
				y.text = Three_Five_types[x];
				typeMenu.options[x] = y;	
			}
		}else
		{
			typeMenu.options.length = 0;			
			for (x = 0; x < A_size_types.length; x++)
			{
				var y=document.createElement('option');
				y.text = A_size_types[x];
				typeMenu.options[x] = y;					
			}
		}
		// fill wire menu
		if(Obj.selectedIndex == 2)	// 3 Pole Selected
		{
			wireMenu.options.length = 0;			
			for (x = 0; x < wires_3P.length; x++)
			{
				var y=document.createElement('option');
				y.text = wires_3P[x];
				wireMenu.options[x] = y;					
			}
		}else if (Obj.selectedIndex == 3)	// 4 Pole selected
		{
			wireMenu.options.length = 0;			
			for (x = 0; x < wires_4P.length; x++)
			{
				var y=document.createElement('option');
				y.text = wires_4P[x];
				wireMenu.options[x] = y;					
			}
		}else if (Obj.selectedIndex == 4) 	// 5 Pole selected
		{
			wireMenu.options.length = 0;			
			for (x = 0; x < wires_5P.length; x++)
			{
				var y=document.createElement('option');
				y.text = wires_5P[x];
				wireMenu.options[x] = y;					
			}
		}else
		{
			wireMenu.options.length = 0;			
			for (x = 0; x < wires_std.length; x++)
			{
				var y=document.createElement('option');
				y.text = wires_std[x];
				wireMenu.options[x] = y;					
			}
		}		
		
	}else
	{
		typeMenu.options.length = 0;			
		for (x = 0; x < std_types.length; x++)
		{
			var y=document.createElement('option');
			y.text = std_types[x];
			typeMenu.options[x] = y;			
		}	
		
		wireMenu.options.length = 0;			
		for (x = 0; x < wires_std.length; x++)
		{
			var y=document.createElement('option');
			y.text = wires_std[x];
			wireMenu.options[x] = y;					
		}
	}
}

function selType(Obj)
{
	var t004 = "Female Straight, \u00BD\" - 14NPT Mounting Thread";
	var t006 = "Male Straight, \u00BD\" - 14NPT Mounting Thread";
	var x;
	
	shellMenu = document.getElementById("selShell");
	familyMenu = document.getElementById("selFamily");
	
	clearPartNum();
	
	if (Obj.value == t004 || Obj.value == t006)
	{
		if(familyMenu.selectedIndex == 1)
		{
			shellMenu.options.length = 0;			
			for (x = 0; x < all_shell.length; x++)
			{
				var y=document.createElement('option');
				y.text = all_shell[x];
				shellMenu.options[x] = y;	
			}
		}else
		{
			shellMenu.options.length = 0;			
			for (x = 0; x < ss_shell.length; x++)
			{
				var y=document.createElement('option');
				y.text = ss_shell[x];
				shellMenu.options[x] = y;	
			}
		}
	}else
	{
		shellMenu.options.length = 0;			
		for (x = 0; x < std_shell.length; x++)
		{
			var y=document.createElement('option');
			y.text = std_shell[x];
			shellMenu.options[x] = y;	
		}
	}
}
		



function calculate()
{
	
	var len;
	var partNum;
	
	familyMenu = document.getElementById("selFamily");
	polesMenu = document.getElementById("selPoles");
	typeMenu = document.getElementById("selType");
	wireMenu = document.getElementById("selWire");
	unitMenu = document.getElementById("selUnit");
	textLeadLength = document.getElementById("txtLength");
	shellMenu = document.getElementById("selShell");
	
	if (familyMenu.selectedIndex < 1 || polesMenu.selectedIndex < 1 || typeMenu.selectedIndex < 1 || wireMenu.selectedIndex < 1)
	{
		alert ("Please select valid options for all items");
		return;
	}
	
	len = parseFloat(textLeadLength.value);
	
	if (isNaN(len) || len > 99.9 || len < 1)
	{
		alert ("Please enter a valid length");
		textLeadLength.focus();
		textLeadLength.select();
		return;
	}

	partNum = family_code[familyMenu.selectedIndex];
	switch(familyMenu.selectedIndex)
	{
		case 0:
			return;
			break;
		case 1:
			partNum += A_poles_code[polesMenu.selectedIndex];
			switch(polesMenu.selectedIndex)
			{
				case 0:
					return;
					break;
				case 1:			// 2 poles
					partNum += A_size_types_code[typeMenu.selectedIndex];
					partNum += wires_std_code[wireMenu.selectedIndex];
					break;
				case 2:			// 3 poles
					partNum += Three_Five_types_code[typeMenu.selectedIndex];
					partNum += wires_3P_code[wireMenu.selectedIndex];
					break;
				case 3:			// 4 poles
					partNum += Three_Five_types_code[typeMenu.selectedIndex];
					partNum += wires_4P_code[wireMenu.selectedIndex];
					break;
				case 4:			// 5 poles
					partNum += Three_Five_types_code[typeMenu.selectedIndex];
					partNum += wires_5P_code[wireMenu.selectedIndex];
					break;
				case 5:			// 6 poles
					partNum += A_size_types_code[typeMenu.selectedIndex];
					partNum += wires_std_code[wireMenu.selectedIndex];
					break;					
			}
			
			break;
		case 2:
			partNum += B_poles_code[polesMenu.selectedIndex];
			partNum += std_types_code[typeMenu.selectedIndex];
			partNum += wires_std_code[wireMenu.selectedIndex];
			break;
		case 3:
			partNum += C_poles_code[polesMenu.selectedIndex];
			partNum += std_types_code[typeMenu.selectedIndex];
			partNum += wires_std_code[wireMenu.selectedIndex];
			break;
	}
	
	if (unitMenu.selectedIndex == 0)
	{
		partNum += "A";
	}else
	{
		partNum += "F";
	}
	if ( len < 10)
	{
		partNum += "0";
		partNum += parseInt(len*10);
	}else
	{
		
		partNum += parseInt(len*10);
	}
	
	partNum += shells_code[shellMenu.selectedIndex];
	
		
			
		

	var addQuote = "<a href=\'quote/quote_action.php?action=add&part_num=" + partNum + "&description=Custom Generated Cable\'>Add to Quote</a>";
	document.getElementById("custompartnum").innerHTML = partNum +"          "+ addQuote;
	document.getElementById("custompartnum").style.display = "block";
	document.getElementById("butCalculate").style.display = "none";
	
	
}

function clearPartNum()
{
	document.getElementById("custompartnum").innerHTML = "";
	document.getElementById("custompartnum").style.display = "none";
	document.getElementById("butCalculate").style.display = "block";
	
}

	
	
