//relies on a couple of functions in common7.js

function AjaxRepeater(containerID, repeaterGuid, dataURL) {
	
	this.containerID = containerID;
	this.guid = repeaterGuid;
	this.currentlySelectedAlphaTD = undefined;
	this.currentIDFilter = undefined;
	this.dataURL = dataURL;
	
	this.loadData = function(strFilterOnLetter, offset, ids) {
		var filter = (strFilterOnLetter ? "&fol=" + strFilterOnLetter : "");
		var offsetTxt = (offset ? "&off=" + offset : "");
		var idsTxt = (ids ? "&ids=" + ids : "");
		el(this.containerID + "_loadingDiv").style.display = 'block';
		loadURLToInnerHTML(dataURL + "?guid=" + this.guid + filter + offsetTxt + idsTxt, containerID + "_gridDiv", this.containerID + "_loadingDiv");
	};
	
	this.selectAlphabet = function(letter, a) {
		if(a) {
			if(el(this.containerID + "_alphaDiv")) el(this.containerID + "_alphaDiv").style.display = 'block';
			var td = a.parentNode;
			this.unselectAlphabet();
			td.className = "tabSelected";
			this.currentlySelectedAlphaTD = td;
			this.currentlySelectedAlpha = letter;
			this.loadData(letter);
		}
	};
	
	this.unselectAlphabet = function() {
		if(this.currentlySelectedAlphaTD) {
			this.currentlySelectedAlphaTD.className = "tabright";
			this.currentlySelectedAlpha = undefined;
		}
	};
	
	this.filterByIDs = function(ids) {
		if(el(this.containerID + "_alphaDiv")) el(this.containerID + "_alphaDiv").style.display = 'none'; 
		this.currentIDFilter = ids;
		this.loadData(this.currentlySelectedAlpha, 0, ids);
	};
	
	this.setOffset = function(offset) {
		this.loadData(this.currentlySelectedAlpha, offset, this.currentIDFilter);
	};
	
	this.resetDisplay = function() {
		this.unselectAlphabet();
		this.currentlySelectedAlphaTD = undefined;
		this.currentIDFilter = undefined;
		if (el(this.containerID + "_Alpha_A")) {
			this.selectAlphabet("A", el(this.containerID + "_Alpha_A"));
		} else {
			this.loadData();
		}
	};
	
	this.resetDisplay();
}
