﻿String.prototype.trim = function () {
  return this.replace(/^\s*/, '').replace(/\s*$/, '');
}

String.prototype.leftTrim = function () {
  return this.replace(/^\s*/, '');
}

String.prototype.rightTrim = function () {
  return this.replace(/\s*$/, '');
}


function ESGetDelimitedStringFromValues(pValues) {

  if (pValues.constructor == Array) {
    returnValue = '';

    for (i = 0; i < pValues.length; i++) {
      returnValue += ESGetDelimitedStringFromValue(pValues[i]);
    }

    return returnValue;
  }
  else {
    return ESGetDelimitedStringFromValue(pValues);
  }
}

function ESGetDelimitedStringFromValue(pValue) {
  try {
    stringValue = pValue.toString();
    stringLength = pValue.length;

    return stringLength + '_' + pValue;
  }
  catch (err) {
    return '';
  }
}

function ESGetStringsFromDelimitedString(pDelimitedString) {

  var result = new Array()

  var delimitedString = pDelimitedString;

  var idx = delimitedString.indexOf('_');

  while (idx != -1) {
    var lenght = parseInt(delimitedString.substr(0, idx));
    var string = delimitedString.substr(idx + 1, lenght);

    result.push(string);

    delimitedString = delimitedString.substr(idx + lenght + 1);
    idx = delimitedString.indexOf('_');
  }

  return result;
}

function TextBox_ToUpper(s, e) {

  var text = s.GetText();
  s.SetText(text.toUpperCase());
}

function TextBox_Trim(s, e) {

  var text = s.GetText();
  s.SetText(text.trim());
}

function TextBox_LeftTrim(s, e) {

  var text = s.GetText();
  s.SetText(text.leftTrim());
}

function TextBox_RightTrim(s, e) {

  var text = s.GetText();
  s.SetText(text.rightTrim());
}

function TextBox_TrimToUpper(s, e) {

  TextBox_Trim(s, e);
  //TextBox_ToUpper(s, e);
}
