// JavaScript Document function formatNumber( num, decimalPlaces, decimalPoint, thousandsPoint ) { // Converts a number into a string with the specified formatting var strng = "", s1; var i = num; if( decimalPlaces == null ) decimalPlaces = 2; if( decimalPoint == null ) decimalPoint = "."; if( thousandsPoint == null ) thousandsPoint = ","; var decPow = Math.pow( 10, decimalPlaces ); i *= decPow; i = Math.abs( Math.round( i ) ); if( decimalPlaces > 0 ) { strng += decimalPoint; s1 = ( i + decPow ).toString(); i /= decPow; strng += s1.substring( s1.length - decimalPlaces, s1.length ); i = Math.floor( i ); } while( Math.floor( i ) >= 1000 ) { s1 = Math.floor( i ).toString(); strng = thousandsPoint + s1.substring( s1.length - 3, s1.length ) + strng; i /= 1000; } strng = ( num < 0 ? -1 : 1 ) * Math.floor( i ) + strng; return( strng ); } function calculate_stamp_duty() { var property_value = parseInt( remove_formatting( document.stamp_duty_calc.property_value.value ) ); if( !isNaN( property_value ) ) { var stamp_duty_pc; if( property_value <= 120000 ) stamp_duty_pc = 0; else if( property_value <= 250000 ) stamp_duty_pc = 1; else if( property_value <= 500000 ) stamp_duty_pc = 3; else stamp_duty_pc = 4; document.stamp_duty_calc.stamp_duty.value = formatNumber( Math.round( property_value * stamp_duty_pc ) / 100, 2 ); } } function currency_field_lost_focus( textInput ) { if( !isNaN( textInput.value ) ) textInput.value = formatNumber( textInput.value, 0 ); } function currency_field_gain_focus( textInput ) { textInput.value = remove_formatting( textInput.value ); } function remove_formatting( value ) { return( value.replace( /,/g, "" ) ); }