// JavaScript functions for robvanderwoude.com
// (c) 2010 Rob van der Woude
// https://www.robvanderwoude.com
function changedAcre( ) {
var areaAcre = parseFloat( document.AreaConversion1.Acre.value );
var areaSqM = areaAcre * 4046.8564224;
var areaAre = areaSqM / 100;
var areaSqKm = areaSqM / 1000000;
var areaHectare = areaSqM / 10000;
var areaSqYd = areaSqM / 0.83612736;
var areaSqFt = areaSqYd * 9;
var areaSqIn = areaSqFt * 144;
var areaSqMi = areaSqM / 2589988.110336;
document.AreaConversion1.Acre.value = areaAcre.toFixed(4)
document.AreaConversion1.Are.value = areaAre.toFixed(4)
document.AreaConversion1.Hectare.value = areaHectare.toFixed(5)
document.AreaConversion1.SqFt.value = areaSqFt.toFixed(2)
document.AreaConversion1.SqIn.value = areaSqIn.toFixed(1)
document.AreaConversion2.SqKm.value = areaSqKm.toFixed(6)
document.AreaConversion2.SqM.value = areaSqM.toFixed(2)
document.AreaConversion2.SqMi.value = areaSqMi.toFixed(6)
document.AreaConversion2.SqYd.value = areaSqYd.toFixed(2)
return true;
}
function changedAre( ) {
var areaAre = parseFloat( document.AreaConversion1.Are.value );
var areaSqM = areaAre * 100;
var areaSqKm = areaSqM / 1000000;
var areaHectare = areaSqM / 10000;
var areaAcre = areaSqM / 4046.8564224;
var areaSqYd = areaSqM / 0.83612736;
var areaSqFt = areaSqYd * 9;
var areaSqIn = areaSqFt * 144;
var areaSqMi = areaSqM / 2589988.110336;
document.AreaConversion1.Acre.value = areaAcre.toFixed(4)
document.AreaConversion1.Are.value = areaAre.toFixed(4)
document.AreaConversion1.Hectare.value = areaHectare.toFixed(5)
document.AreaConversion1.SqFt.value = areaSqFt.toFixed(2)
document.AreaConversion1.SqIn.value = areaSqIn.toFixed(1)
document.AreaConversion2.SqKm.value = areaSqKm.toFixed(6)
document.AreaConversion2.SqM.value = areaSqM.toFixed(2)
document.AreaConversion2.SqMi.value = areaSqMi.toFixed(6)
document.AreaConversion2.SqYd.value = areaSqYd.toFixed(2)
return true;
}
function changedAtmosphere( ) {
var pressureAtm = parseFloat( document.PressureConversion.Atmosphere.value );
var pressureBar = pressureAtm * 1.01325;
var pressurePa = pressureBar * 100000;
var pressurePsi = pressureBar * 14.5037744;
document.PressureConversion.Atmosphere.value = pressureAtm.toFixed(3);
document.PressureConversion.Bar.value = pressureBar.toFixed(3);
document.PressureConversion.Pascal.value = pressurePa.toFixed(0);
document.PressureConversion.Psi.value = pressurePsi.toFixed(3);
return true;
}
function changedBar( ) {
var pressureBar = parseFloat( document.PressureConversion.Bar.value );
var pressureAtm = pressureBar / 1.01325;
var pressurePa = pressureBar * 100000;
var pressurePsi = pressureBar * 14.5037744;
document.PressureConversion.Atmosphere.value = pressureAtm.toFixed(3);
document.PressureConversion.Bar.value = pressureBar.toFixed(3);
document.PressureConversion.Pascal.value = pressurePa.toFixed(0);
document.PressureConversion.Psi.value = pressurePsi.toFixed(3);
return true;
}
function changedBarrel( ) {
var numBarrel = parseFloat( document.VolumeConversion.Barrel.value );
var numGallon = numBarrel * 42;
var numPint = numGallon * 8;
var numFlOz = numGallon * 128;
var numLitre = numPint * 0.473176473;
document.VolumeConversion.Barrel.value = numBarrel.toFixed(3);
document.VolumeConversion.FlOz.value = numFlOz.toFixed(1);
document.VolumeConversion.Gallon.value = numGallon.toFixed(3);
document.VolumeConversion.Litre.value = numLitre.toFixed(3);
document.VolumeConversion.Pint.value = numPint.toFixed(2);
return true;
}
function changedCelsius() {
var tempC = Number( document.TemperatureConversion.Celsius.value );
var tempK = tempC + 273.15;
var tempF = tempK * 1.8 - 459.67;
document.TemperatureConversion.Celsius.value = tempC.toFixed(2);
document.TemperatureConversion.Fahrenheit.value = tempF.toFixed(2);
document.TemperatureConversion.Kelvin.value = tempK.toFixed(2);
return true;
}
function changedDecimal( ) {
var numI = parseInt( document.RomanNumerals.Decimal.value );
if ( numI < 1 || numI > 4999 ) {
alert( 'Integer must be in the range of 1..4999' );
return false;
} else{
numR = Decimal2Roman( numI );
document.RomanNumerals.Roman.value = numR;
return true;
}
}
function changedFahrenheit() {
var tempF = Number( document.TemperatureConversion.Fahrenheit.value );
var tempK = ( tempF + 459.67 ) / 1.8;
var tempC = tempK - 273.15;
document.TemperatureConversion.Celsius.value = tempC.toFixed(2);
document.TemperatureConversion.Fahrenheit.value = tempF.toFixed(2);
document.TemperatureConversion.Kelvin.value = tempK.toFixed(2);
return true;
}
function changedFeet( ) {
var strFeetInch = document.LengthConversion.Feet.value;
var pattern1 = /\d+(\.\d+)?[\'\"]$/;
var errmsg = "Feet/inches value must be in feet'inches\" or feet' or inches\" format";
if ( strFeetInch.search( pattern1 ) == -1 ) {
alert( errmsg );
return false;
}
var pattern2 = /^(((\d+)\')?)(((\d+(\.\d+)?)\")?)$/;
if ( strFeetInch.search( pattern2 ) == -1 ) {
alert( errmsg );
return false;
}
var posFt = strFeetInch.indexOf( "'" );
var posIn = strFeetInch.indexOf( '"' );
if ( posFt > -1 && posIn > -1 && posIn < posFt ) {
alert( errmsg );
return false;
}
if ( posFt > -1 && posIn > -1 ) {
var numFeet = parseInt( strFeetInch.substring( 0, posFt ) );
var numInch = parseFloat( strFeetInch.substring( posFt + 1, posIn ) );
} else if ( posFt == -1 && posIn == -1 ) {
var numFeet = 0;
var numInch = 0;
} else if ( posFt > -1 ) {
var numFeet = parseInt( strFeetInch.substring( 0, posFt ) );
var numInch = 0;
} else {
var numFeet = 0;
var numInch = parseFloat( strFeetInch.substring( 0, posIn ) );
}
if ( numInch > 11 ) {
numFeet = numFeet + parseInt( numInch / 12 );
numInch = numInch % 12;
}
if ( numInch == 0 && numFeet == 0 ) {
strFeetInch = "0";
} else if ( numInch == 0 ) {
strFeetInch = numFeet + "'";
} else if ( numFeet == 0 ) {
strFeetInch = numInch.toFixed(1) + '"';
} else {
strFeetInch = numFeet + "'" + numInch.toFixed(1) + '"';
}
numInch = numInch + ( 12 * numFeet );
var numMeters = numInch * 0.0254;
document.LengthConversion.Feet.value = strFeetInch;
document.LengthConversion.Meters.value = numMeters.toFixed(2);
return true;
}
function changedFlOz( ) {
var numFlOz = parseFloat( document.VolumeConversion.FlOz.value );
var numGallon = numFlOz / 128;
var numBarrel = numGallon / 42;
var numPint = numGallon * 8;
var numLitre = numPint * 0.473176473;
document.VolumeConversion.Barrel.value = numBarrel.toFixed(3);
document.VolumeConversion.FlOz.value = numFlOz.toFixed(1);
document.VolumeConversion.Gallon.value = numGallon.toFixed(3);
document.VolumeConversion.Litre.value = numLitre.toFixed(3);
document.VolumeConversion.Pint.value = numPint.toFixed(2);
return true;
}
function changedGallon( ) {
var numGallon = parseFloat( document.VolumeConversion.Gallon.value );
var numBarrel = numGallon / 42;
var numPint = numGallon * 8;
var numFlOz = numGallon * 128;
var numLitre = numPint * 0.473176473;
document.VolumeConversion.Barrel.value = numBarrel.toFixed(3);
document.VolumeConversion.FlOz.value = numFlOz.toFixed(1);
document.VolumeConversion.Gallon.value = numGallon.toFixed(3);
document.VolumeConversion.Litre.value = numLitre.toFixed(3);
document.VolumeConversion.Pint.value = numPint.toFixed(2);
return true;
}
function changedGrain( ) {
var wtGrain = parseInt( document.WeightConversion.Grain.value );
var wtPound = wtGrain / 7000;
var wtKg = wtPound * 0.45359237;
var wtStone = parseInt( wtPound / 14 );
var intPound = parseInt( wtPound + 0.5 - ( 14 * wtStone ) );
if ( intPound == 0 ) {
var strStone = wtStone.toString( ) + " stone";
} else {
var strStone = wtStone.toString( ) + " stone " + intPound.toString( );
}
document.WeightConversion.Stone.value = strStone;
document.WeightConversion.Grain.value = wtGrain;
document.WeightConversion.Pound.value = WritePound( wtPound );
document.WeightConversion.Kg.value = wtKg.toFixed(3);
return true;
}
function changedHectare( ) {
var areaHectare = parseFloat( document.AreaConversion1.Hectare.value );
var areaSqM = areaHectare * 10000;
var areaSqKm = areaSqM / 1000000;
var areaAre = areaSqM / 100;
var areaAcre = areaSqM / 4046.8564224;
var areaSqYd = areaSqM / 0.83612736;
var areaSqFt = areaSqYd * 9;
var areaSqIn = areaSqFt * 144;
var areaSqMi = areaSqM / 2589988.110336;
document.AreaConversion1.Acre.value = areaAcre.toFixed(4)
document.AreaConversion1.Are.value = areaAre.toFixed(4)
document.AreaConversion1.Hectare.value = areaHectare.toFixed(5)
document.AreaConversion1.SqFt.value = areaSqFt.toFixed(2)
document.AreaConversion1.SqIn.value = areaSqIn.toFixed(1)
document.AreaConversion2.SqKm.value = areaSqKm.toFixed(6)
document.AreaConversion2.SqM.value = areaSqM.toFixed(2)
document.AreaConversion2.SqMi.value = areaSqMi.toFixed(6)
document.AreaConversion2.SqYd.value = areaSqYd.toFixed(2)
return true;
}
function changedHPImpE( ) {
var pwrHPImpE = parseFloat( document.PowerConversion.HPImpE.value );
var pwrWatt = pwrHPImpE * 746;
var pwrHPImpM = pwrWatt / 745.69987158227022;
var pwrHPMetric = pwrWatt / 735.49875;
document.PowerConversion.HPImpE.value = pwrHPImpE.toFixed(3);
document.PowerConversion.HPImpM.value = pwrHPImpM.toFixed(3);
document.PowerConversion.HPMetric.value = pwrHPMetric.toFixed(3);
document.PowerConversion.Watt.value = pwrWatt.toFixed(1);
return true;
}
function changedHPImpM( ) {
var pwrHPImpM = parseFloat( document.PowerConversion.HPImpM.value );
var pwrWatt = pwrHPImpM * 745.69987158227022;
var pwrHPImpE = pwrWatt / 746;
var pwrHPMetric = pwrWatt / 735.49875;
document.PowerConversion.HPImpE.value = pwrHPImpE.toFixed(3);
document.PowerConversion.HPImpM.value = pwrHPImpM.toFixed(3);
document.PowerConversion.HPMetric.value = pwrHPMetric.toFixed(3);
document.PowerConversion.Watt.value = pwrWatt.toFixed(1);
return true;
}
function changedHPMetric( ) {
var pwrHPMetric = parseFloat( document.PowerConversion.HPMetric.value );
var pwrWatt = pwrHPMetric * 735.49875;
var pwrHPImpE = pwrWatt / 746;
var pwrHPImpM = pwrWatt / 745.69987158227022;
document.PowerConversion.HPImpE.value = pwrHPImpE.toFixed(3);
document.PowerConversion.HPImpM.value = pwrHPImpM.toFixed(3);
document.PowerConversion.HPMetric.value = pwrHPMetric.toFixed(3);
document.PowerConversion.Watt.value = pwrWatt.toFixed(1);
return true;
}
function changedKelvin( ) {
var tempK = Number( document.TemperatureConversion.Kelvin.value );
var tempC = tempK - 273.15;
var tempF = tempK * 1.8 - 459.67;
document.TemperatureConversion.Celsius.value = tempC.toFixed(2);
document.TemperatureConversion.Fahrenheit.value = tempF.toFixed(2);
document.TemperatureConversion.Kelvin.value = tempK.toFixed(2);
return true;
}
function changedKg( ) {
var wtKg = parseFloat( document.WeightConversion.Kg.value );
var wtPound = wtKg / 0.45359237;
var wtGrain = parseInt( wtPound * 7000 );
var wtStone = parseInt( wtPound / 14 );
var intPound = parseInt( wtPound + 0.5 - ( 14 * wtStone ) );
if ( intPound == 0 ) {
var strStone = wtStone.toString( ) + " stone";
} else {
var strStone = wtStone.toString( ) + " stone " + intPound.toString( );
}
document.WeightConversion.Stone.value = strStone;
document.WeightConversion.Grain.value = wtGrain;
document.WeightConversion.Pound.value = WritePound( wtPound );
document.WeightConversion.Kg.value = wtKg.toFixed(3);
return true;
}
function changedKilometers( ) {
var numkm = parseFloat( document.DistanceConversion.Kilometers.value );
var nummi = numkm / 1.609344;
var numnm = numkm / 1.852;
document.DistanceConversion.Kilometers.value = numkm.toFixed(2);
document.DistanceConversion.Miles.value = nummi.toFixed(2);
document.DistanceConversion.Nautical.value = numnm.toFixed(2);
return true;
}
function changedKnots( ) {
var numKnots = parseFloat( document.SpeedConversion.Knots.value );
var numKph = numKnots * 1.852;
var numMph = numKph / 1.609344;
var numMps = numKph / 3.6;
document.SpeedConversion.Kph.value = numKph.toFixed(2);
document.SpeedConversion.Mps.value = numMps.toFixed(2);
document.SpeedConversion.Mph.value = numMph.toFixed(2);
document.SpeedConversion.Knots.value = numKnots.toFixed(2);
return true;
}
function changedKph( ) {
var numKph = parseFloat( document.SpeedConversion.Kph.value );
var numMps = numKph / 3.6;
var numMph = numKph / 1.609344;
var numKnots = numKph / 1.852;
document.SpeedConversion.Kph.value = numKph.toFixed(2);
document.SpeedConversion.Mps.value = numMps.toFixed(2);
document.SpeedConversion.Mph.value = numMph.toFixed(2);
document.SpeedConversion.Knots.value = numKnots.toFixed(2);
return true;
}
function changedLitre( ) {
var numLitre = parseFloat( document.VolumeConversion.Litre.value );
var numGallon = numLitre / 3.785411784;
var numBarrel = numGallon / 42;
var numFlOz = numGallon * 128;
var numPint = numGallon * 8;
document.VolumeConversion.Barrel.value = numBarrel.toFixed(3);
document.VolumeConversion.FlOz.value = numFlOz.toFixed(1);
document.VolumeConversion.Gallon.value = numGallon.toFixed(3);
document.VolumeConversion.Litre.value = numLitre.toFixed(3);
document.VolumeConversion.Pint.value = numPint.toFixed(2);
return true;
}
function changedMeters( ) {
var numMeters = parseFloat( document.LengthConversion.Meters.value );
var numFeet = Math.floor( numMeters / 0.3048 );
var numInches = 12 * ( numMeters / 0.3048 - Math.floor( numMeters / 0.3048 ) );
document.LengthConversion.Meters.value = numMeters.toFixed(2);
document.LengthConversion.Feet.value = numFeet + "'" + numInches.toFixed(1) + '"';
return true;
}
function changedMiles( ) {
var nummi = parseFloat( document.DistanceConversion.Miles.value );
var numkm = nummi * 1.609344;
var numnm = numkm / 1.852;
document.DistanceConversion.Kilometers.value = numkm.toFixed(2);
document.DistanceConversion.Miles.value = nummi.toFixed(2);
document.DistanceConversion.Nautical.value = numnm.toFixed(2);
return true;
}
function changedMph( ) {
var numMph = parseFloat( document.SpeedConversion.Mph.value );
var numKph = numMph * 1.609344;
var numMps = numKph / 3.6;
var numKnots = numKph / 1.852;
document.SpeedConversion.Kph.value = numKph.toFixed(2);
document.SpeedConversion.Mps.value = numMps.toFixed(2);
document.SpeedConversion.Mph.value = numMph.toFixed(2);
document.SpeedConversion.Knots.value = numKnots.toFixed(2);
return true;
}
function changedMps( ) {
var numMps = parseFloat( document.SpeedConversion.Mps.value );
var numKph = numMps * 3.6;
var numMph = numKph / 1.609344;
var numKnots = numKph / 1.852;
document.SpeedConversion.Kph.value = numKph.toFixed(2);
document.SpeedConversion.Mps.value = numMps.toFixed(2);
document.SpeedConversion.Mph.value = numMph.toFixed(2);
document.SpeedConversion.Knots.value = numKnots.toFixed(2);
return true;
}
function changedNautical( ) {
var numnm = parseFloat( document.DistanceConversion.Nautical.value );
var numkm = numnm * 1.852;
var nummi = numkm / 1.609344;
document.DistanceConversion.Kilometers.value = numkm.toFixed(2);
document.DistanceConversion.Miles.value = nummi.toFixed(2);
document.DistanceConversion.Nautical.value = numnm.toFixed(2);
return true;
}
function changedPascal( ) {
var pressurePa = parseFloat( document.PressureConversion.Pascal.value );
var pressureBar = pressurePa / 100000;
var pressureAtm = pressureBar / 1.01325;
var pressurePsi = pressureBar * 14.5037744;
document.PressureConversion.Atmosphere.value = pressureAtm.toFixed(3);
document.PressureConversion.Bar.value = pressureBar.toFixed(3);
document.PressureConversion.Pascal.value = pressurePa.toFixed(0);
document.PressureConversion.Psi.value = pressurePsi.toFixed(3);
return true;
}
function changedPint( ) {
var numPint = parseFloat( document.VolumeConversion.Pint.value );
var numGallon = numPint / 8;
var numBarrel = numGallon / 42;
var numFlOz = numGallon * 128;
var numLitre = numPint * 0.473176473;
document.VolumeConversion.Barrel.value = numBarrel.toFixed(3);
document.VolumeConversion.FlOz.value = numFlOz.toFixed(1);
document.VolumeConversion.Gallon.value = numGallon.toFixed(3);
document.VolumeConversion.Litre.value = numLitre.toFixed(3);
document.VolumeConversion.Pint.value = numPint.toFixed(2);
return true;
}
function changedPound( ) {
var wtPound = ReadPound( document.WeightConversion.Pound.value );
var wtGrain = parseInt( wtPound * 7000 + 0.5 );
var wtKg = wtPound * 0.45359237;
var wtStone = parseInt( wtPound / 14 );
var intPound = parseInt( wtPound + 0.5 - ( 14 * wtStone ) );
if ( intPound == 0 ) {
var strStone = wtStone.toString( ) + " stone";
} else {
var strStone = wtStone.toString( ) + " stone " + intPound.toString( );
}
document.WeightConversion.Stone.value = strStone;
document.WeightConversion.Grain.value = wtGrain;
document.WeightConversion.Pound.value = WritePound( wtPound );
document.WeightConversion.Kg.value = wtKg.toFixed(3);
return true;
}
function changedPsi( ) {
var pressurePsi = parseFloat( document.PressureConversion.Psi.value );
var pressureBar = pressurePsi / 14.5037744;
var pressureAtm = pressureBar / 1.01325;
var pressurePa = pressureBar * 100000;
document.PressureConversion.Atmosphere.value = pressureAtm.toFixed(3);
document.PressureConversion.Bar.value = pressureBar.toFixed(3);
document.PressureConversion.Pascal.value = pressurePa.toFixed(0);
document.PressureConversion.Psi.value = pressurePsi.toFixed(3);
return true;
}
function changedRoman( ) {
var numR = document.RomanNumerals.Roman.value.toUpperCase( );
var numI = Roman2Decimal( numR ).toString( );
document.RomanNumerals.Decimal.value = numI;
document.RomanNumerals.Roman.value = Decimal2Roman( numI );
return true;
}
function changedSqFt( ) {
var areaSqFt = parseFloat( document.AreaConversion1.SqFt.value );
var areaSqIn = areaSqFt * 144;
var areaSqYd = areaSqFt / 9;
var areaSqM = areaSqYd * 0.83612736;
var areaSqKm = areaSqM / 1000000;
var areaAre = areaSqM / 100;
var areaHectare = areaSqM / 10000;
var areaAcre = areaSqM / 4046.8564224;
var areaSqMi = areaSqM / 2589988.110336;
document.AreaConversion1.Acre.value = areaAcre.toFixed(4)
document.AreaConversion1.Are.value = areaAre.toFixed(4)
document.AreaConversion1.Hectare.value = areaHectare.toFixed(5)
document.AreaConversion1.SqFt.value = areaSqFt.toFixed(2)
document.AreaConversion1.SqIn.value = areaSqIn.toFixed(1)
document.AreaConversion2.SqKm.value = areaSqKm.toFixed(6)
document.AreaConversion2.SqM.value = areaSqM.toFixed(2)
document.AreaConversion2.SqMi.value = areaSqMi.toFixed(6)
document.AreaConversion2.SqYd.value = areaSqYd.toFixed(2)
return true;
}
function changedSqIn( ) {
var areaSqIn = parseFloat( document.AreaConversion1.SqIn.value );
var areaSqFt = areaSqIn / 144;
var areaSqYd = areaSqFt / 9;
var areaSqM = areaSqYd * 0.83612736;
var areaSqKm = areaSqM / 1000000;
var areaAre = areaSqM / 100;
var areaHectare = areaSqM / 10000;
var areaAcre = areaSqM / 4046.8564224;
var areaSqMi = areaSqM / 2589988.110336;
document.AreaConversion1.Acre.value = areaAcre.toFixed(4)
document.AreaConversion1.Are.value = areaAre.toFixed(4)
document.AreaConversion1.Hectare.value = areaHectare.toFixed(5)
document.AreaConversion1.SqFt.value = areaSqFt.toFixed(2)
document.AreaConversion1.SqIn.value = areaSqIn.toFixed(1)
document.AreaConversion2.SqKm.value = areaSqKm.toFixed(6)
document.AreaConversion2.SqM.value = areaSqM.toFixed(2)
document.AreaConversion2.SqMi.value = areaSqMi.toFixed(6)
document.AreaConversion2.SqYd.value = areaSqYd.toFixed(2)
return true;
}
function changedSqKm( ) {
var areaSqKm = parseFloat( document.AreaConversion2.SqKm.value );
var areaSqM = areaSqKm * 1000000;
var areaAre = areaSqM / 100;
var areaHectare = areaSqM / 10000;
var areaAcre = areaSqM / 4046.8564224;
var areaSqYd = areaSqM / 0.83612736;
var areaSqFt = areaSqYd * 9;
var areaSqIn = areaSqFt * 144;
var areaSqMi = areaSqM / 2589988.110336;
document.AreaConversion1.Acre.value = areaAcre.toFixed(4)
document.AreaConversion1.Are.value = areaAre.toFixed(4)
document.AreaConversion1.Hectare.value = areaHectare.toFixed(5)
document.AreaConversion1.SqFt.value = areaSqFt.toFixed(2)
document.AreaConversion1.SqIn.value = areaSqIn.toFixed(1)
document.AreaConversion2.SqKm.value = areaSqKm.toFixed(6)
document.AreaConversion2.SqM.value = areaSqM.toFixed(2)
document.AreaConversion2.SqMi.value = areaSqMi.toFixed(6)
document.AreaConversion2.SqYd.value = areaSqYd.toFixed(2)
return true;
}
function changedSqM( ) {
var areaSqM = parseFloat( document.AreaConversion2.SqM.value );
var areaSqKm = areaSqM / 1000000;
var areaAre = areaSqM / 100;
var areaHectare = areaSqM / 10000;
var areaAcre = areaSqM / 4046.8564224;
var areaSqYd = areaSqM / 0.83612736;
var areaSqFt = areaSqYd * 9;
var areaSqIn = areaSqFt * 144;
var areaSqMi = areaSqM / 2589988.110336;
document.AreaConversion1.Acre.value = areaAcre.toFixed(4)
document.AreaConversion1.Are.value = areaAre.toFixed(4)
document.AreaConversion1.Hectare.value = areaHectare.toFixed(5)
document.AreaConversion1.SqFt.value = areaSqFt.toFixed(2)
document.AreaConversion1.SqIn.value = areaSqIn.toFixed(1)
document.AreaConversion2.SqKm.value = areaSqKm.toFixed(6)
document.AreaConversion2.SqM.value = areaSqM.toFixed(2)
document.AreaConversion2.SqMi.value = areaSqMi.toFixed(6)
document.AreaConversion2.SqYd.value = areaSqYd.toFixed(2)
return true;
}
function changedSqMi( ) {
var areaSqMi = parseFloat( document.AreaConversion2.SqMi.value );
var areaSqM = areaSqMi * 2589988.110336;
var areaSqKm = areaSqM / 1000000;
var areaAre = areaSqM / 100;
var areaHectare = areaSqM / 10000;
var areaAcre = areaSqM / 4046.8564224;
var areaSqYd = areaSqM / 0.83612736;
var areaSqFt = areaSqYd * 9;
var areaSqIn = areaSqFt * 144;
document.AreaConversion1.Acre.value = areaAcre.toFixed(4)
document.AreaConversion1.Are.value = areaAre.toFixed(4)
document.AreaConversion1.Hectare.value = areaHectare.toFixed(5)
document.AreaConversion1.SqFt.value = areaSqFt.toFixed(2)
document.AreaConversion1.SqIn.value = areaSqIn.toFixed(1)
document.AreaConversion2.SqKm.value = areaSqKm.toFixed(6)
document.AreaConversion2.SqM.value = areaSqM.toFixed(2)
document.AreaConversion2.SqMi.value = areaSqMi.toFixed(6)
document.AreaConversion2.SqYd.value = areaSqYd.toFixed(2)
return true;
}
function changedSqYd( ) {
var areaSqYd = parseFloat( document.AreaConversion2.SqYd.value );
var areaSqM = areaSqYd * 0.83612736;
var areaSqKm = areaSqM / 1000000;
var areaAre = areaSqM / 100;
var areaHectare = areaSqM / 10000;
var areaAcre = areaSqM / 4046.8564224;
var areaSqFt = areaSqYd * 9;
var areaSqIn = areaSqFt * 144;
var areaSqMi = areaSqM / 2589988.110336;
document.AreaConversion1.Acre.value = areaAcre.toFixed(4)
document.AreaConversion1.Are.value = areaAre.toFixed(4)
document.AreaConversion1.Hectare.value = areaHectare.toFixed(5)
document.AreaConversion1.SqFt.value = areaSqFt.toFixed(2)
document.AreaConversion1.SqIn.value = areaSqIn.toFixed(1)
document.AreaConversion2.SqKm.value = areaSqKm.toFixed(6)
document.AreaConversion2.SqM.value = areaSqM.toFixed(2)
document.AreaConversion2.SqMi.value = areaSqMi.toFixed(6)
document.AreaConversion2.SqYd.value = areaSqYd.toFixed(2)
return true;
}
function changedStone( ) {
var strStone = document.WeightConversion.Stone.value;
var pattern = /^\d+\s+stone(\s+\d+)?$/i;
if ( strStone.search( pattern ) == -1 ) {
alert( "Stones (and pounds) must be input as\n\n\t<stones> stone [ <pounds> ]\n\nE.g. 18 pounds must be input as\n\n\t1 stone 4\n\nAnd 28 pounds must be input as\n\n\t2 stone" );
return false;
}
var arrStone = new Array( );
arrStone = strStone.split( " " );
if ( arrStone.length > 2 ) {
var wtPound = ( 14 * parseInt( arrStone[0] ) ) + parseInt( arrStone[2] );
} else {
var wtPound = 14 * parseInt( arrStone[0] );
}
var wtGrain = parseInt( wtPound * 7000 + 0.5 );
var wtKg = wtPound * 0.45359237;
var wtStone = parseInt( wtPound / 14 );
var intPound = parseInt( wtPound + 0.5 - ( 14 * wtStone ) );
if ( intPound == 0 ) {
var strStone = wtStone.toString( ) + " stone";
} else {
var strStone = wtStone.toString( ) + " stone " + intPound.toString( );
}
document.WeightConversion.Stone.value = strStone;
document.WeightConversion.Grain.value = wtGrain;
document.WeightConversion.Pound.value = WritePound( wtPound );
document.WeightConversion.Kg.value = wtKg.toFixed(3);
return true;
}
function changedWatt( ) {
var pwrWatt = parseFloat( document.PowerConversion.Watt.value );
var pwrHPImpE = pwrWatt / 746;
var pwrHPImpM = pwrWatt / 745.69987158227022;
var pwrHPMetric = pwrWatt / 735.49875;
document.PowerConversion.HPImpE.value = pwrHPImpE.toFixed(3);
document.PowerConversion.HPImpM.value = pwrHPImpM.toFixed(3);
document.PowerConversion.HPMetric.value = pwrHPMetric.toFixed(3);
document.PowerConversion.Watt.value = pwrWatt.toFixed(1);
return true;
}
function Decimal2Roman( numDecimal ) {
var intDecimal = parseInt( numDecimal );
var strRoman = "";
// First, add an "M" for every multiple of 1000
while ( intDecimal >= 1000 ) {
intDecimal = intDecimal - 1000;
strRoman = strRoman + "M";
}
// Next, add "CM" for 900, or "D" for 500, or "CD" for 400
if ( intDecimal >= 900 ) {
intDecimal = intDecimal - 900;
strRoman = strRoman + "CM";
} else if ( intDecimal >= 500 ) {
intDecimal = intDecimal - 500;
strRoman = strRoman + "D";
} else if ( intDecimal >= 400 ) {
intDecimal = intDecimal - 400;
strRoman = strRoman + "CD";
}
// Add a "C" for every remaining multiple of 100
while ( intDecimal >= 100 ) {
intDecimal = intDecimal - 100;
strRoman = strRoman + "C";
}
// Add "XC" for 90, or "L" for 50, or "XL" for 40
if ( intDecimal >= 90 ) {
intDecimal = intDecimal - 90;
strRoman = strRoman + "XC";
} else if ( intDecimal >= 50 ) {
intDecimal = intDecimal - 50;
strRoman = strRoman + "L";
} else if ( intDecimal >= 40 ) {
intDecimal = intDecimal - 40;
strRoman = strRoman + "XL";
}
// Add an "X" for every remaining multiple of 10
while ( intDecimal >= 10 ) {
intDecimal = intDecimal - 10;
strRoman = strRoman + "X";
}
// Add "IX" for 9, or "V" for 5, or "IV" for 4
if ( intDecimal >= 9 ) {
intDecimal = intDecimal - 9;
strRoman = strRoman + "IX";
} else if ( intDecimal >= 5 ) {
intDecimal = intDecimal - 5;
strRoman = strRoman + "V";
} else if ( intDecimal >= 4 ) {
intDecimal = intDecimal - 4;
strRoman = strRoman + "IV";
}
// Finally, add an "I" for every remaining multiple of 1
while ( intDecimal >= 1 ) {
intDecimal = intDecimal - 1;
strRoman = strRoman + "I";
}
// Return the result
return strRoman;
}
function ReadPound( strPound ) {
// var strPound = document.WeightConversion.Pound.value;
var pattern = /\d+\s+\d+\/16/;
if ( strPound.search( pattern ) != -1 ) {
var arrPound = new Array( );
arrPound = strPound.split( " " );
var numPound = parseInt( arrPound[0] );
if ( arrPound.length > 1 ) {
var arrOunce = new Array( );
arrOunce = arrPound[1].split( "/" );
numPound = numPound + ( parseInt( arrOunce[0] ) / 16 );
}
return numPound;
} else {
return parseFloat( strPound );
}
}
function Roman2Decimal( strRoman ) {
var intRoman = 0;
var arrRoman = [];
var i;
// Store each "digit" of the Roman numeral in an array
for ( i = 0; i < strRoman.length; i++ ) {
arrRoman[i] = strRoman.substring( i, i + 1 ).toUpperCase( );
}
// Then convert each "digit" to its numeric value
for ( i = 0; i < arrRoman.length; i++ ) {
switch ( arrRoman[i] ) {
case "M": {
arrRoman[i] = 1000;
break;
}
case "D": {
arrRoman[i] = 500;
break;
}
case "C": {
arrRoman[i] = 100;
break;
}
case "L": {
arrRoman[i] = 50;
break;
}
case "X": {
arrRoman[i] = 10;
break;
}
case "V": {
arrRoman[i] = 5;
break;
}
case "I": {
arrRoman[i] = 1;
break;
}
}
}
// Now comes the hard part: for each "digit" decide if it will be
// added or subtracted, based on the value of the following "digit"
for ( i = 0; i < arrRoman.length - 1; i++ ) {
if ( arrRoman[i] < arrRoman[i+1] ) {
// E.g. "I" in "IX" (9): subtract 1
intRoman = intRoman - arrRoman[i];
} else if ( arrRoman[i] == arrRoman[i+1] ) {
// E.g. "I" in "XII" (12), "III" (3) or in "IIX" (ancient notation for 8).
// The latter should actually be "VIII" in "modern" roman numerals, but
// "IIX" was used in ancient times, so let's just be prepared.
// We'll add the value to the next position in the array, so it will be
// reevaluated in the next iteration of the loop.
// Note: this trick will definitely fail on invalid notations like "IIIX".
arrRoman[i+1] = arrRoman[i] + arrRoman[i+1];
arrRoman[i] = 0;
} else {
// arrRoman( i ) > arrRoman( i + 1 )
// E.g. "V" in "XV" (15): add 5
intRoman = intRoman + arrRoman[i];
}
}
// The last "digit" doesn't have a following "digit" so it
// can be added without having to test a following "digit"
intRoman = intRoman + arrRoman[arrRoman.length-1];
// Return the calculated value
return intRoman;
}
function WritePound( numPound ) {
var intPound = parseInt( numPound );
var strPound = intPound.toString( );
var intOunce = parseInt( ( numPound - intPound ) * 16 + 0.5 );
if ( intOunce > 0 ) {
strPound = strPound + " " + intOunce.toString( ) + "/16";
}
return strPound;
}