// (c) 2000 M.O'Neill - www.virtualamnesia.com
// Default Separator: " _-+'"
function ChangeCase(objEdit, functType, Separator)
{
   var data     = objEdit.value;
   var found    = 0;
   var position = new Array();
   var result   = "";
   var endstring;
   var x;

   // All upper case...
   if (functType == "All Up")
   {
      objEdit.value = data.toUpperCase();
   }


   // All lower case...
   if (functType == "All Lo")
   {
      objEdit.value = data.toLowerCase();
   }


   // otherwise it's "1st Letter Upper" OR "1st Letter Upper of each word"
   // so first letter to upper case - no matter what
   result = data.substring(0,1).toUpperCase();


   // 1st letter upper case of first word - rest lower case...
   if (functType == "1st Up")
   {
      objEdit.value = (result + data.substring(1,data.length).toLowerCase());
   }


   // 1st letter upper case of EACH word ...
   if (functType == "1st Up Wd")
   {
      for (var i=0; i < data.length; i++)
      {
         x = data.substring(i, i+1);
         if (Separator.indexOf(x) != -1)
         {
            if (position[found-1] != i-1)
            {
               position[found] = i;
               found ++;
            }
            else
            {
               // incase there are separators next to each other,
               // we just want to remember the last separator position
               found --;
               position[found] = i;
               found ++;
            }
         }
      }
      
      if (found > 0) // separators found
      {
         x = 1;
         for (var i=0; i < found; i++)
         {
            if (position[i+1])
            {
               endstring = position[i+1];
            }
            else
            {
               endstring = data.length;
            }
            result = result + data.substring(x,eval(position[i]+1)).toLowerCase();
            result = result + data.substring(eval(position[i]+1),eval(position[i]+2)).toUpperCase();
            result = result + data.substring(eval(position[i]+2),endstring).toLowerCase();
            x = position[i+1];
         }
      }
      else // no separators found, so just write the rest of the string
      {
         result = result + data.substring(1,data.length).toLowerCase();
      }
   
      objEdit.value = result;
   }
}