function roundNumber(rnum, rlength) { 
	var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	return newnumber;
}		
function calcArrowSpeed() {
	var value1 = document.getElementById( "field1" ).value; // bow ibo speed
	var value2 = document.getElementById( "field2" ).value; // arrow weight
	var value3 = document.getElementById( "field3" ).value; // draw length
	var value4 = document.getElementById( "field4" ).value; // draw weight
	var value5 = document.getElementById( "field5" ).value; // weight added to string
	var calc = 0;
	
	if( value1 != '' ) {
		calc = value1;
		if( value2 != '' ) {
			document.getElementById( "field6" ).value = value2;
			calc = calc - ( value2 - 350 ) / 3;
			if( value3 != '' ) {
				var tmp = 30 - value3;
				if( tmp > 0 ) {
					calc = calc - ( tmp * 10 );
				}
				if( value4 != '' ) {
					if( value4 <= 65 ) {
						var tmp = roundNumber( ( 70 - value4 ) / 5, 0 ) * 10;
						calc = calc - tmp;
					}
					if( value5 != '' ) {
						calc = calc - ( value5 / 3 );
						calc = roundNumber( calc, 2 );
						document.getElementById( "calc1" ).value = calc;
					}
				}
			}
		}
	}
}
function calcKineticEnergy() {
	var value6 = document.getElementById( "field6" ).value; // arrow weight
	var value7 = document.getElementById( "field7" ).value; // arrow speed
	var calc2 = 0;
	
	if( value6 != '' && value7 != '' ) {
		calc2 = ( value6 * value7 * value7 ) / 450240;
		calc2 = roundNumber( calc2, 2 );
		document.getElementById( "calc2" ).value = calc2;
	}
}
function calcFOC() {
	var value8 = document.getElementById( "field8" ).value; // arrow length
	var value9 = document.getElementById( "field9" ).value; // balance point length
	var calc3 = 0;
	
	if( value8 != '' && value9 != '' ) {
		calc3 = ( value9 - value8 / 2 ) / value8 * 100;
		calc3 = roundNumber( calc3, 2 );
		document.getElementById( "calc3" ).value = calc3;
	}
}
function calcArrowWeight() {
	var value10 = document.getElementById( "field10" ).value; // shaft weight
	var value11 = document.getElementById( "field11" ).value; // arrow shaft length
	var value12 = document.getElementById( "field12" ).value; // point weight
	var value13 = document.getElementById( "field13" ).value; // insert weight
	var value14 = document.getElementById( "field14" ).value; // nock weight
	var value15 = document.getElementById( "field15" ).value; //  number of veins
	var value16 = document.getElementById( "field16" ).value; //  vane weight per vane
	var value17 = document.getElementById( "field17" ).value; // wrap weight
	var calc4 = 0;
				
	if( value10 != '' && value11 != '' ) {
		value10 = parseFloat( value10 );
		value11 = parseFloat( value11 );
		calc4 = value10 * value11;			
		if( value12 != '' ) {
			value12 = parseFloat( value12 );
			calc4 = calc4 + value12;
			if( value13 != '' ) {
				value13 = parseFloat( value13 );
				calc4 = calc4 + value13;
				if( value14 != '' ) {
					value14 = parseFloat( value14 );
					calc4 = calc4 + value14;
					if( value15 != '' && value16 != '' ) {
						value15 = parseFloat( value15 );
						value16 = parseFloat( value16 );
						calc4 = calc4 + ( value15 * value16 );
						if( value17 != '' ) {
							value17 = parseFloat( value17 );
							calc4 = calc4 + value17;
						}
					}
				}
			}
		}
	}
	calc4 = roundNumber( calc4, 2 );
	document.getElementById( "calc4" ).value = calc4;
}
