           //checks that data are valid 
            function checkNumber(input, min, max, msg) {
 
                        msg = msg + " field has invalid data: " + input.value;
 
                        //this makes sure that the number is a number
                        var str = input.value;
                        for (var i = 0; i < str.length; i++) {
                                   var ch = str.substring( i, i + 1)
                                   if ((ch < "0" || "9" < ch) && ch != '.') {
                                               alert(msg);
                                               return false;
                                   }
                        }
 
                        //this makes sure that the number lies between the min and max values allowed
                        var num = 0 + str
                        if (num < min || max < num) {
                                   alert(msg + " not in range [" + min + ".." + max + "]");
                                   return false;
                        }
                        input.value = str;
                        return true;
            }
 
            function computeField(input) {
                        if (input.value != null && input.value.length != 0)
                        {
                                    input.value = "" + eval(input.value);
                        }
                        computeForm(input.form);
            }
 
            function computeForm() {
                        var A=form.A.value;
                        var T=form.T.value;
                        var R=form.R.value;
 
                        //making sure that an entry has been made in each field.
                        if ((A == null || A.length == 0) ||
                                   (R == null || R.length == 0)) 
                        {
                                   //alert('not all fields filled in');
                                   return;
                        }
 
                        // making sure that entries are valid by using check number
                        if (!checkNumber(form.A, 1, 999999, "Amount") ||
                                   !checkNumber(form.R, .001, 1000, "Interest Rate") ||
                                   !checkNumber(form.T, 5, 25, "Period")) 
                        {
                                   form.Cm.value = "Invalid";
                                   return;
                        }
 
                        // maths et al to be computed
                        R = R / 100;
                        var P = ((A*R)/12) * (1/(1-(Math.pow(1/(1+R),T))));
                        form.Cm.value = poundsPence( P );
                        P = ((A*0.12)/12) * (1 / (1-(Math.pow((1/1.12),T))));
                        form.CCm.value = poundsPence( P );
                        P = (A*R)/12;
                        form.CI.value = poundsPence( P );
                        P = (A*0.12)/12;
                        form.CCI.value = poundsPence( P );
            }
 
            function poundsPence( N ) {
                        // don't try this with ie3 because it's rubbish
                        if ((navigator.appName.indexOf('Microsoft')>-1)
                                   && (navigator.appVersion.indexOf('3.0')>-1) )
                        {
                                   return N;
                        }
                        S = new String( N );
                        var i = S.indexOf('.');
                        if (i != -1) {
                                   S = S.substr( 0, i+3 );
                                   if (S.length-i < 3)
                                               S = S + '0';
                        } else {
                            S = S + '.00';
                        }
                        return S;
            }
 
            //clears form
            function clearForm() {
             form.A.value = "";
             form.T.value = "";
             form.R.value = "";
 			 form.Cm.value = "";
			 form.CI.value = "";
  			 form.CCm.value = "";
  			 form.CCI.value = "";
            }