﻿function RemoveTextWithinSquareBrackets(TextBox) {
  var Finished = false;
  while (Finished == false)
  {
    Finished = RemoveText(TextBox);
  }
}

function RemoveText(TextBox) {
    var Text = TextBox.value;
    var OutPut;
    var pos1 = Text.indexOf("[");
    if (pos1 > -1)
    {
      var pos2 = Text.indexOf("]");
      var TotalLength = Text.length;
      if (pos2 > -1 && pos2 > pos1)
      {
        if (pos1 == 0)
        {
          if (TotalLength >= pos2)
          {
            TextBox.value = Text.substring(pos2 + 1);
            return false;
          } else
          {
            TextBox.value = '';
            return true;
          }
        } else {
          OutPut = Text.substring(0, pos1);
          if (TotalLength >= pos2) {
            TextBox.value = OutPut + Text.substring(pos2 + 1);
            return false;
          } else {
            TextBox.value = OutPut;
            return true;
          }
        }
      } else {
        return true;
      }
    } else {
      return true;
    }
}

//if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
