for all your javascript trimming needs...
function trim(inputString) {
if (typeof inputString != "string") return inputString;
return inputString
//clear leading spaces and empty lines
.replace(/^(\s|\n|\r)*((.|\n|\r)*?)(\s|\n|\r)*$/g,"$2")
//take consecutive spaces down to one
.replace(/(\s(?!(\n|\r))(?=\s))+/g,"")
//take consecutive lines breaks down to one
.replace(/(\n|\r)+/g,"\n\r")
//remove spacing at the beginning of a line
.replace(/(\n|\r)\s/g,"$1")
//remove spacing at the end of a line
.replace(/\s(\n|\r)/g,"$1");
}
-- Jon