

var alloysteelArray =  new Array("('Select alloy','',true,true)",
"('      Aircraft Alloys','0..283')",
"('4130','0.283')",
"('4140','0.282')",
"('4340','0.280')",
"('6150','0.283')",
"('9310','0.283')",
"('52100','0.283')",
"('      Maraging Steels','0..289')",
"('250','0.289')",
"('300','0.289')",
"('350','0.289')",
"('      Spring Steels','0..284')",
"('1050','0.283')",
"('1075','0.284')",
"('1095','0.284')",
"('5160','0.283')",
"('      Abrasion Resistant Steels','0..283')",
"('AR 235','0.283')",
"('AR 400','0.283')",
"('AR 500','0.283')");
var aluminumArray =  new Array("('Select alloy','',true,true)",
"('1100','0.098')",
"('2014','0.101')",
"('2017','0.101')",
"('2024','0.100')",
"('2219','0.103')",
"('3003','0.099')",
"('5052','0.097')",
"('5083','0.096')",
"('5086','0.096')",
"('5454','0.097')",
"('5456','0.096')",
"('6013','0.098')",
"('6061','0.098')",
"('6063','0.097')",
"('7050','0.102')",
"('7075','0.101')",
"('7150','0.098')");
var copperArray =  new Array("('Select alloy','',true,true)",
"('101','0.323')",
"('102','0.323')",
"('110','0.323')",
"('122','0.322')",
"('150','0.321')",
"('      Tellurium Copper','0.323')",
"('145','0.323')",
"('      Beryllium Coppers','0.304')",
"('172','0.298')",
"('173','0.298')",
"('17510','0.317')",
"('      Glidcop','0.320')",
"('AL-15','0.321')",
"('AL-25','0.320')",
"('      Copper Chromium','0.321')",
"('180','0.315')",
"('182','0.321')",
"('      Brasses','0.318')",
"('220','0.318')",
"('230','0.316')",
"('260','0.308')",
"('      Leaded Brasses','0.309')",
"('314','0.319')",
"('330','0.307')",
"('360','0.307')",
"('385','0.306')",
"('      Tin Brasses','0.307')",
"('464','0.304')",
"('485','0.305')",
"('      Phosphor Bronzes','0.276')",
"('510','0.320')",
"('521','0.318')",
"('544','0.321')",
"('      Aluminum Bronzes','0.276')",
"('623','0.276')",
"('624','0.269')",
"('630','0.274')",
"('642','0.278')",
"('954','0.323')",
"('      Silicon Bronzes','0.308')",
"('651','0.316')",
"('655','0.308')",
"('      Manganese Bronzes','0.302')",
"('67410','0.292')",
"('675','0.302')",
"('      Copper Nickel','0.323')",
"('706','0.323')",
"('715','0.323')",
"('      Bearing Bronzes','0.323')",
"('863','0.323')",
"('932','0.322')");

var magnesiumArray =  new Array("('Select alloy','',true,true)",
"('AZ31B','0.064')",
"('ZK60A','0.066')");
var nickelArray =  new Array("('Select alloy','',true,true)",
"('      Nickel Chromium Alloys','0.299')",
"('Inconel 600','0.306')",
"('Inconel 601','0.293')",
"('Inconel 625','0.305')",
"('Inconel 718','0.296')",
"('Inconel x-750','0.299')",
"('      Nickel Chromium Iron Alloys','0.290')",
"('Incoloy 800','0.287')",
"('Incoloy 800HT','0.287')",
"('      Nickel Cobalt Chrome Alloys','0.315')",
"('L-605','0.330')",
"('MP35N','0.304')",
"('      Nickel Iron Alloys','0.321')",
"('A286','0.290')",
"('Hastelloy B-2','0.333')",
"('Hastelloy C-22','0.314')",
"('Hastelloy C-276','0.321')",
"('      Corrosion Resistant','0.321')",
"('200','0.321')",
"('201','0.321')",
"('205','0.321')",
"('      Nickel Copper Alloys','0.321')",
"('Monel 400','0.333')",
"('Monel 405','0.321')",
"('Monel K-500','0.316')");

var refractoryArray =  new Array("('Select alloy','',true,true)",
"('Kovar','0.302')",
"('Invar','0.293')",
"('Molybdenum','0.366')",
"('Tantalum','0.6')",
"('Tungsten','0.697')");



var stainlessArray =  new Array("('Select alloy','',true,true)",
"('13-8 MO VM','0.280')",
"('15-5 PH VM','0.285')",
"('15-7 PH','0.282')",
"('17-4 PH','0.280')",
"('Nitronic 40','0.282')",
"('Nitronic 50','0.285')",
"('Nitronic 60','0.274')",
"('301','0.290')",
"('302','0.285')",
"('303','0.290')",
"('304','0.285')",
"('304-L','0.285')",
"('309','0.290')",
"('310','0.290')",
"('316','0.290')",
"('317','0.290')",
"('321','0.286')",
"('330','0.289')",
"('347','0.288')",
"('409','0.278')",
"('410','0.280')",
"('416','0.280')",
"('420','0.278')",
"('430','0.276')",
"('430FR','0.279')",
"('440A','0.280')",
"('440C','0.275')",
"('440F','0.275')");

var steelArray =  new Array("('Select alloy','',true,true)",

"('A-2','0.281')",
"('A-6','0.290')",
"('D-2','0.278')",
"('H-13','0.281')",
"('S-7','0.283')",
"('M-1','0.333')",
"('M-2','0.333')",
"('O-1','0.283')",
"('O-6','0.333')");
var titaniumArray =  new Array("('Select alloy','',true,true)",
"('6Al-4V','0.160')",
"('6Al-4V ELI','0.163')",
"('6AL-6V-2Sn','0.164')",
"('6Al-2Sn-4Zr-2Mo','0.164')",
"('CP Grade 1','0.163')",
"('CP Grade 2','0.163')",
"('CP Grade 3','0.163')",
"('CP Grade 4','0.163')");



function populateAlloy(inForm,selected) {
	var selectedArray = eval(selected + "Array");
	while (selectedArray.length < inForm.alloy.options.length) {
		inForm.alloy.options[(inForm.alloy.options.length - 1)] = null;
		}
	for (var i=0; i < selectedArray.length; i++) {
	eval("inForm.alloy.options[i]=" + "new Option" + selectedArray[i]);
	}
	if (inForm.material.options[0].value == '') {
	inForm.material.options[0]= null;

   }
}

		var focusflag = false;
		var RoundOff = 5;

function ConvertToInch(value,type){
			if(type=="ft")
				value = value*12;
			if(type=="yd")
				value = value*36;
			if(type=="cm")
				value = value/2.54;
			if(type=="m")
				value = (value*100)/2.54;
			if(type== "mm")
				value = (value/10)/2.54;
	return value;
	}

function CalculateWeight(){

		var Param = new Array(5);
		var Units = new Array(4);
		var Convert;
		var FormType;
		var Result;
		var Good;
		var myShape;
		var myPieces;
		var myDensity;
		var myWeight;
		var myPcWeight;
		var totalWeight;
		var dim1;
		var dim2;
		var dim3;
		var dim4;

		myDensity = document.weightcalc.alloy.value;
		dim1 = ConvertToInch(document.weightcalc.dim1.value,document.weightcalc.unitsdim1.value);
		dim2 = ConvertToInch(document.weightcalc.dim2.value,document.weightcalc.unitsdim2.value);
		dim3 = ConvertToInch(document.weightcalc.dim3.value,document.weightcalc.unitsdim3.value);
		dim4 = ConvertToInch(document.weightcalc.dim4.value,document.weightcalc.unitsdim4.value);
		myPieces = document.weightcalc.pieces.value;
		myShape = document.weightcalc.matshape.value;
		document.weightcalc.pcweight.rsize = "4";
		document.weightcalc.totalweight.rsize = "4";		

			if(myShape=="round"){
				myWeight=new String(dim1*dim1*9.42*myDensity*(dim2/12));
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
			}
			if(myShape=="square"){
				myWeight=new String(dim1*dim1*myDensity*dim2);
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
			}
			if(myShape=="hex"){
				myWeight=new String(dim1*dim1*myDensity*10.4*(dim2/12));
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
			}
			if(myShape=="coil"){
				myWeight=new String(dim1*dim2*myDensity*dim3);
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
			}

			if(myShape=="flat"){
				myWeight=new String(dim1*dim2*myDensity*dim3);
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
			}
			if(myShape=="sheet"){
				myWeight=new String(dim1*dim2*myDensity*dim3);
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
			}
			if(myShape=="rectangle"){
				myWeight=new String(dim1*dim2*myDensity*dim3);
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
			}
			if(myShape=="plate"){
				myWeight=new String(dim1*dim2*myDensity*dim3);
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
			}									
			if(myShape=="tube"||myShape=="pipe"){
				myWeight=new String((dim1-dim2)*dim2*myDensity*37.7*(dim3/12));
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
				}

			if(myShape=="rectangle tube"){
				myWeight=new String(((dim1*dim2*12*myDensity)-((dim1-(dim3*2))*(dim2-(dim3*2))*12*myDensity))*(dim4/12));
				document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
				}				
			if(myShape=="square tube"){
						myWeight=new String(37.7*myDensity*dim2*(dim1-dim2)*1.27*(dim3/12));
						document.weightcalc.pcweight.value = myWeight.substring(0,myWeight.indexOf(".")+RoundOff);
				}	
			myPcWeight=document.weightcalc.pcweight.value;
			totalWeight=new String(myPcWeight*myPieces);
			totalWeight = totalWeight.substring(0,myWeight.indexOf(".")+RoundOff);
			document.weightcalc.totalweight.value=totalWeight;
}

function showimage(){
	var myShape;
	var myPicture;
	
	myShape=document.weightcalc.matshape.options[document.weightcalc.matshape.selectedIndex].value;

	if (myShape=="round"){
	myPicture="images/calc/circle.gif";
	}
	if (myShape=="flat"||myShape=="plate"||myShape=="coil"||myShape=="rectangle"||myShape=="sheet"){
	myPicture="images/calc/flat.gif";
	}
	if (myShape=="rectangle tube"){
	myPicture="images/calc/rectube.gif";
	}
	if (myShape=="hex"){
	myPicture="images/calc/hexagon.gif";
	}
	if (myShape=="square"){
	myPicture="images/calc/square.gif";
	}
	if (myShape=="square tube"){
	myPicture="images/calc/sqtube.gif";
	}
	if (myShape=="tube"){
	myPicture="images/calc/tube.gif";
	}
	if (myShape=="ring"){
	myPicture="images/calc/tube.gif";
	}
	if (myShape=="pipe"){
	myPicture="images/calc/tube.gif";
	}
	document.images.pictures.src=myPicture;
	{
	if (!document.images)
	return
	}
}

function ClearFields(){
	document.weightcalc.dim1.value = "";
	document.weightcalc.dim2.value = "";
	document.weightcalc.dim3.value = "";
	document.weightcalc.dim4.value = "";
	document.weightcalc.pcweight.value = "";
	document.weightcalc.totalweight.value = "";		
	}
function ChangeLabel(){
	var myShape;
	myShape = document.weightcalc.matshape.value;

	if(myShape=="round"){
		document.weightcalc.dim1label.value = "Diameter:";
		document.weightcalc.dim2label.value = "Length:";
		document.weightcalc.dim3label.value = "";
		document.weightcalc.dim4label.value = "";
		}
	if(myShape=="square"){
		document.weightcalc.dim1label.value = "Width:";
		document.weightcalc.dim2label.value = "Length:";
		document.weightcalc.dim3label.value = "";
		document.weightcalc.dim4label.value = "";
		}
	if(myShape== "hex"){
		document.weightcalc.dim1label.value = "Diameter:";
		document.weightcalc.dim2label.value = "Length:";
		document.weightcalc.dim3label.value = "";
		document.weightcalc.dim4label.value = "";
		}
	if(myShape=="flat"||myShape=="sheet"||myShape=="coil"||myShape=="plate"||myShape=="rectangle"){
		document.weightcalc.dim1label.value = "Thickness:";
		document.weightcalc.dim2label.value = "Width:";
		document.weightcalc.dim3label.value = "Length:";
		document.weightcalc.dim4label.value = "";
		}
	if(myShape=="tube"||myShape=="pipe"){
		document.weightcalc.dim1label.value = "Outer Diameter:";
		document.weightcalc.dim2label.value = "Wall:";
		document.weightcalc.dim3label.value = "Length:";
		document.weightcalc.dim4label.value = "";
		}
	if(myShape=="circular"){
		document.weightcalc.dim1label.value = "Diameter:";
		document.weightcalc.dim2label.value = "Thickness:";
		document.weightcalc.dim3label.value = "";
		document.weightcalc.dim4label.value = "";
		}
	if(myShape=="ring"){
		document.weightcalc.dim1label.value = "Thickness:";
		document.weightcalc.dim2label.value = "Outer Diameter:";
		document.weightcalc.dim3label.value = "Inner Diameter:";
		document.weightcalc.dim4label.value = "";
		}
	if(myShape=="square tube"){
		document.weightcalc.dim1label.value = "Outer Diameter:";
		document.weightcalc.dim2label.value = "Wall:";
		document.weightcalc.dim3label.value = "Length:";
		document.weightcalc.dim4label.value = "";
		}
	if(myShape=="rectangle tube"){
		document.weightcalc.dim1label.value = "Height:";
		document.weightcalc.dim2label.value = "Width:";
		document.weightcalc.dim3label.value = "Wall:";
		document.weightcalc.dim4label.value = "Length:";
		}
		
}
ChangeLabel();
ClearFields();
