// SPECIAL PASS

// var specialpass = ((new Date()).getDate() + (new Date()).getMonth() + 1).toString();

// COLLECTION PROCESSING

function Collection(name) {
	var names = name.split(" ");

	// properties
	
	// document.writeln("NAMES: " + names + " TYPE: " + typeof(names));
	
	this.type = "Creator instance";
	this.id = ((typeof(names) == "object") && (names.length > 1)) ? (names[0] + "_" + names[1]) : name;
	this.header = '<!-- ' + this.id + ' -->\n';
	this.header = this.header + 'addListener(cds_out,"' + this.id + '")';
	this.items = new Array();
	this.itemsList = new Array();

	// methods
	this.add = addCollectorItem;
	this.remove = removeCollectorItem;
	this.find = findCollectorItem;
	this.showItems = displayCollectorItems;
	this.showHeader = displayCollectorHeader;
	this.showEntry = displayCollector;
	this.writeItems = writeCollectorItems;
	this.writeHeader = writeCollectorHeader;
	this.writeEntry = writeCollector;
	this.listEntry = listCollection;
	return this;
}

function addCollectorItem(catno) {
	if (this.find(catno) == -1) {
		this.items.push('addToCollection(cds_out,"' + this.id + '","' + catno + '")');
		this.itemsList.push(catno);
		// document.writeln("Adding collector item: " + this.items[this.items.length-1] + "<br>\n");
	}
}

function removeCollectorItem(catno) {
	var catIndex = this.find(catno);
	if ( catIndex != -1 ) {
		this.items.splice(catIndex,1);
		this.itemsList.splice(catIndex,1);
	}
}

function findCollectorItem(catno) {
	for (var i=0; i < this.items.length; i++) {
		if (this.items[i].indexOf(catno) != -1) {
			return i;
		}
	}
	return -1;
}

function writeCollectorItems() {
	var result = "";
	for (var i=0; i < this.items.length; i++) {
		result += this.items[i] + ";\n";
	}
	return result;
}

function writeCollectorHeader() {
	return this.header + ";\n";
}

function displayCollectorItems() {
	var result = "";
	for (var i=0; i < this.items.length; i++) {
		result += this.items[i] + ";<br>\n";
	}
	return result;
}

function displayCollectorHeader() {
	return this.header + ";<br>\n";
}

function displayCollector() {
	return this.showHeader() + this.showItems();
}

function writeCollector() {
	return this.writeHeader() + this.writeItems();
}

function listCollection() {
	var result = "";
	for (var i=0; i < this.itemsList.length; i++) {
		result += this.itemsList[i];
		if (i < (this.itemsList.length - 1)) {
			result += ",";
		}
	}
	return result;
}