
// ***** BEGIN CONVERSION CALCUALTION METHODS *****

function inchesToMillimeters(inputValue, precision)
{
	return(inputValue * 25.4).toFixed(precision);
}

function millimetersToInches(inputValue, precision)
{
	return (inputValue * .03937).toFixed(precision);
}

function inchesToMeters(inputValue, precision)
{
	return(inputValue * .0254).toFixed(precision);
}

function metersToInches(inputValue, precision)
{
	return(inputValue * 39.37).toFixed(precision);
}

function inchesToMicrons(inputValue, precision)
{
	return (inputValue * 25400).toFixed(precision);
}

function micronsToInches(inputValue, precision)
{
	return (inputValue * (3.93700787 * Math.pow(10,-5))).toFixed(precision);
}

function feetToMeters(inputValue, precision)
{
	return (inputValue * .3048).toFixed(precision);
}

function metersToFeet(inputValue, precision)
{
	return (inputValue * 3.2808).toFixed(precision);
}

function poundsToKilos(inputValue, precision)
{
	return (inputValue * .453592).toFixed(precision);
}

function kilosToPounds(inputValue, precision)
{
	return (inputValue * 2.2046).toFixed(precision);
}

function poundsToGrams(inputValue, precision)
{
    return (inputValue * 453.6).toFixed(precision);
}

function gramsToPounds(inputValue, precision)
{
    return (inputValue * .0022).toFixed(precision);
}

function poundPerCubicInchToGramsPerCubicCentimeter(inputValue, precision)
{
    return (inputValue * 27.679).toFixed(precision);
}

function gramsPerCubicCentimeterToPoundsPerCubicInch(inputValue, precision)
{
    return (inputValue * 0.036127292).toFixed(precision);
}


function convert(method, inputValue, precision)
{
	// make sure inputValue is not empty
	if (inputValue.length < 1)
	{
		inputValue = 0;
	}
		
	var returnValue;
	
	// make sure value is a number, otherwise we just return zero
	if (isNumeric(inputValue))
	{
		var methodCall;
		
		// if no decimal places specified, default to two
		if (!precision)
		{
			precision = 2;
		}
		
		methodCall = eval(method +'(' + inputValue + ',' + precision + ')' );
		returnValue = eval(methodCall);
	}
	else
	{
		returnValue = 0;
	}
	
	return returnValue;
}

// ****** END CONVERSION CALCULATION METHODS *****

function isNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }




function roundIt(num)
{
	return roundIt(num, 1);
}

function roundIt(num, decimalPlaces)
{
	switch(decimalPlaces)
	{
		case 1:
			return Math.round(10*num)/10;
			break;
		case 2: 
			return Math.round(100*num)/100;
			break;
		case 3: 
			return Math.round(1000*num)/1000;
			break;
		case 4:
			return Math.round(10000*num)/10000;
			break;
		default:
			return Math.round(10*num)/10;
	}
	return Math.round(10*num)/10;
}

