

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')");

var aluminumArray =  new Array("('Select alloy','',true,true)",
"('1100','0.098')",
"('2024','0.100')",
"('2219','0.103')",
"('5052','0.097')",
"('5083','0.096')",
"('5086','0.096')",
"('6061','0.098')",
"('7050','0.102')",
"('7075','0.101')",
"('7150','0.098')");

var cocrArray =  new Array("('Select alloy','',true,true)",
"('L605','0.330')",
"('MP35N','0.304')",
"('ASTM F1537','0.300')");

var copperArray =  new Array("('Select alloy','',true,true)",
"('C10100','0.323')",
"('C11000','0.323')",
"('C14500','0.323')",
"('C17200','0.298')",
"('C17300','0.298')",
"('C17510','0.317')",
"('C36000','0.307')",
"('C46400','0.304')",
"('C48500','0.305')",
"('C51000','0.320')",
"('C54400','0.321')",
"('C63000','0.274')",
"('C64200','0.278')",
"('C95400','0.323')",
"('Glidcop','0.320')");

var magnesiumArray =  new Array("('Select alloy','',true,true)",
"('AZ31B','0.064')",
"('ZK60A','0.066')");

var nickelArray =  new Array("('Select alloy','',true,true)",
"('200','0.321')",
"('201','0.321')",
"('205','0.321')",
"('Monel 400','0.333')",
"('Monel 405','0.321')",
"('Monel K-500','0.316')",
"('Inconel 600','0.306')",
"('Inconel 601','0.293')",
"('Inconel 625','0.305')",
"('Inconel 718','0.296')",
"('Inconel x-750','0.299')",
"('Hastelloy B-2','0.333')",
"('Hastelloy C-22','0.314')",
"('Hastelloy C-276','0.321')",
"('L-605','0.330')",
"('MP35N','0.304')");

var kovarArray =  new Array("('Select alloy','',true,true)",
"('ASTM F15','0.302')");

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

"('Invar 36','0.293')");


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

"('Molybdenum 99.9%','0.366')");


var tantalumArray =  new Array("('Select alloy','',true,true)",
"('Tantalum 99.9%','0.6')");


var tungstenArray =  new Array("('Select alloy','',true,true)",
"('HD 17 Class 1','0.614')",
"('HD 18 Class 3','0.650')",
"('CW70 Class 10','0.512')",
"('CW75 Class 11','0.531')",
"('Tungsten 99.9%','0.692')");



var stainlessArray =  new Array("('Select alloy','',true,true)",
"('13-8 MO VM','0.280')",
"('15-5 PH VM','0.285')",
"('17-4 PH','0.280')",
"('Nitronic 50','0.285')",
"('Nitronic 60','0.274')",
"('303','0.290')",
"('304','0.285')",
"('309','0.290')",
"('310','0.290')",
"('316 LVM','0.290')",
"('321','0.286')",
"('330','0.289')",
"('416','0.280')",
"('420','0.278')",
"('430','0.276')",
"('430FR','0.279')",
"('440C','0.275')",
"('Custom 455','0.282')",
"('Custom 465','0.282')");


var titaniumArray =  new Array("('Select alloy','',true,true)",
"('6Al-4V','0.160')",
"('6Al-4V ELI','0.163')",
"('CP Grade 1','0.163')",
"('CP Grade 2','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();

