//-----------------------------------------------------------------------------
// trims leading and trailing spaces and control characters
// from the given string, and remove redundant space in the
// middle of sSrc
//-----------------------------------------------------------------------------
function trim(sSrc) {
    if (sSrc == null)
        return "";

    var str = "";
    sSrc = sSrc.toString();
    var len = sSrc.length;
    var i = 0;
    while (i < len) {
        if (sSrc.charAt(i) != ' ') {
            str += sSrc.charAt(i);
        }
        else if (str != "") {
            var j = i;
            while ((sSrc.charAt(j) == ' ') && (j < len)) {
                j++;
            }
            if (j < len)
                str += " ";
            i = j - 1;
        }
        i++;
    }
    return str;
}








































































































































































































