The javascript string object lacks a native trim method for removing leading and trailing spaces. Here's a function that does the job:
function trim(value) { value = value.replace(/^\s+/,''); value = value.replace(/\s+$/,''); return value; }