add
String.prototype.trim=function () {return this.replace(/^\s+|\s+$/g, "");}
somewhere before your posted code.
then, its very easy to use:
var temp = document.localform.someInput.value[COLOR="Red"].trim()[/COLOR];
this will be a standard string method in the next version of javascript, due to come out in late 2009.