Capitalize the words in JavaScript

<SCRIPT>
function capWords(str){
   words = str.split(" "); 
   for (i=0 ; i < words.length ; i++){
      testwd = words[i];
      firLet = testwd.substr(0,1); //lop off first letter
      rest = testwd.substr(1, testwd.length -1)
      words[i] = firLet.toUpperCase() + rest   
   }         
   document.theForm.results.value = words.join(" ");
}
</SCRIPT>