Exclude certain words from Capitalization

Exclude certain words from Capitalization

I would like to know how can exclude certain words from Capitalization

    Exclude words and match the case: "and, or, TOM"  
   
    input value : "Tom AND Jerry, Peter OR Tom";

    result : "TOM and Jerry, Peter or TOM";

Your help will be appreciated.

Thanks

      
                  

  1.                     function toUpper(obj) {
  2.                         var mystring = obj.value;
  3.                         var sp = mystring.split(' ');
  4.                         var wl = 0;
  5.                         var f, r;
  6.                         var word = new Array();
  7.                         for (i = 0; i < sp.length; i++) {
  8.                             f = sp[i].substring(0, 1).toUpperCase();
  9.                             r = sp[i].substring(1).toLowerCase();
  10.                             word[i] = f + r;
  11.                         }
  12.                         newstring = word.join(' ');
  13.                         obj.value = newstring;
  14.                         return true;
  15.                     }