// Copyright (C) 2002  SJS Solutions Ltd

// KNOWN BUG: doesn't always trim off whitespace at the end of a multiline
//            string

function trim(str)
{
    if (typeof(str) == "string") {
        var old = RegExp.multiline;
        RegExp.multiline = true;

        var re = new RegExp("^\\s*([^\\s]*)\\s*$");
        var result = str.replace(re, "$1");
        
        RegExp.multiline = old;
        return result;
    } else {
        return str;
    }
}
