function Item(pvThing) {
this.Value = pvThing;
this.Index = -1;
}
function Collection() {
this.all = [];
this.aall = {};
this.length = 0;
this.Add = function (poItem, pvKey) {
if
(typeof(poItem) == "object" && poItem.constructor == Item)
{
var
idx = this.all.push(poItem) - 1; // 'push' was added in IE 5.5
if
(this.all[idx].Index = -1) {
this.all[idx].Index
= idx;
}
if
(typeof(pvKey) != "undefined") {
this.all[idx].Key = pvKey;
this.aall[pvKey]
= this.all[idx];
}
this.length
= this.all.length;
}
else {
alert("Item
must be an Item object.");
}
}
this.Remove = function (pvItem) {
if
(typeof(pvItem) == "object" && pvItem.constructor == Item)
{
for
(var i = 0; i < this.all.length; i++) {
if
(this.all[i] == pvItem) {
this.all.splice(i, 1);
if
(typeof(this.all[i].Key) != "undefined") {
delete this.aall[this.all[i].Key] ;
}
break;
}
}
}
else if (typeof(this.aall[pvItem]) != "undefined") {
this.all.splice(this.aall[pvItem].Index, 1); // 'splice'
was added in IE 5.5
delete
this.aall[pvItem];
}
else if (typeof(this.all[pvItem]) != "undefined") {
if
(typeof(this.all[pvItem].Key) != "undefined") {
delete
this.aall[this.all[pvItem].Key];
}
this.all.splice(pvItem, 1);
}
for
(var i = 0; i < this.all.length; i++) {
this.all[i].Index
= i;
}
this.length
= this.all.length;
}
this.Item = function (pvKeyOrIndex) {
if
(typeof(this.aall[pvKeyOrIndex]) != "undefined") {
return
this.aall[pvKeyOrIndex];
}
else if (typeof(this.all[pvKeyOrIndex]) != "undefined") {
return
this.all[pvKeyOrIndex];
}
}
this.RemoveAll = function () {
this.all
= [];
this.aall
= {};
this.length
= 0;
}
}
//push and splice do not work in versions of IE less than 5.5.
//you can create new functions to do this functionality using
//combinations of concat and slice.