Javascript form to process text, erroneous results