/*********************************************************************************************************
 * Extender :     _JSArrayExtender
 *
 * Description :  JS File to extend array/named arrary functionality.
 *
 * Notes :        'Use' this JavaScript file if you want to utilize
 *                Object Array Sorting, and Named Array Count capabilities.
 *
 *********************************************************************************************************/


function _SortByProperty(property,rev) {
  /*
   * Extender :     _SortByProperty
   *
   * Description :  Array Object Sort Extender Method(s).
   *
   * Notes :        'Use' this JavaScript file if you want to utilize
   *                Object Array Sorting capabilities.
   *
   */
  var fn = function(a,b)
  {

    if (a[property] < b[property])
    {
      return (rev)? 1:-1;

    }
    else if (a[property] > b[property])
    {
      return (rev)? -1:1;
    }
    else
    {
      return 0;
    }
  }

  this.sort(fn);

  return this;

}
Array.prototype.SortByProperty = _SortByProperty;



Array.prototype.Index = -1;
Array.prototype.Count = function() {
  /*
   * Extender :     Count
   *
   * Description :  Method to return a Count of named arrays.
   *
   * Notes :
   *
   */
  var intX = 0;
  for(var x in this) {
    if(typeof (this[x]) != "function" && typeof(this[x]) != "number" ) intX++;
  }
  return intX;
}
Array.prototype.HasNext = function() {
  /*
   * Extender :     HasNext
   *
   * Description :  Method to determine if there are any more items in the collection.
   *
   * Notes :
   *
   */
  if(this.Index < this.Count())
      return true
  else
      return false
}
Array.prototype.HasPrevious = function() {
  /*
   * Extender :     HasPrevious
   *
   * Description :  Method to determine if there are any more items in the collection.
   *
   * Notes :
   *
   */
  if(this.Index > 0)
      return true
  else
      return false
}
Array.prototype.GetPrevious = function() {
  /*
   * Extender :     GetPrevious
   *
   * Description :  Gets the previous item in the collection.
   *
   * Notes :
   *
   */
  var intNewIndex = 0;

  if ( this.HasPrevious() )
  {
    for( var x in this ) {
      if(typeof (this[x]) != "function" && typeof(this[x]) != "number" )
      {
        if( intNewIndex == (this.Index-1) ) {
          this.Index = intNewIndex;
          return this[x];
        }

        intNewIndex++;
      }
    }

  }
  else
  {
    return null;
  }

}
Array.prototype.GetNext = function() {
  /*
   * Extender :     GetNext
   *
   * Description :  Gets the next item in the collection.
   *
   * Notes :
   *
   */
  var intNewIndex = 0;

  if ( this.HasNext() )
  {
    for( var x in this ) {
      if(typeof (this[x]) != "function" && typeof(this[x]) != "number" )
      {
        if( intNewIndex == (this.Index+1) ) {
          this.Index = intNewIndex;
          return this[x];
        }

        intNewIndex++;
      }
    }

  }
  else
  {
    return null;
  }
}
Array.prototype.GetAt = function(pobjPos) {
  /*
   * Extender :     GetAt
   *
   * Description :  Gets the item at the current index in the collection.
   *
   * Notes :
   *
   */
  var intCtr = 0;

  if ( typeof(pobjPos) == "string" )
  {
    for( var x in this ) {
      if(typeof (this[x]) != "function" && typeof(this[x]) != "number" )
      {
        if( this[x].SpecCode == pobjPos ) {
          this.Index = intCtr;
          return this[x];
        }

        intCtr++;
      }
    }
  }
  else
  {
    for( var x in this ) {
      if(typeof (this[x]) != "function" && typeof(this[x]) != "number" )
      {
        if( intCtr == pobjPos ) {
          this.Index = intCtr;
          return this[x];
        }

        intCtr++;
      }
    }
  }


  return null;
}


function LTrimComma(s) { var trimExp = /^,*/; return s.replace(trimExp, ""); }
function RTrimComma(s) { var trimExp = /,*$/; return s.replace(trimExp, ""); }
String.prototype.TrimComma = function() { var tmp = RTrimComma(LTrimComma(this)); return tmp; }

