// page and group mechanism

String.prototype.toProperCase = function() 
{
    return this.charAt(0).toUpperCase() + this.substring(1,this.length).toLowerCase();
}
function showHide(id,doShow){
	if (document.getElementById){
	obj = document.getElementById(arrayName(id));
	if (doShow){
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
} 
}
function showHideArray(theArray,doShow) {
	for(var i=0;i<theArray.length;i++) {
		showHide(theArray[i],doShow);
	}
}
function arrayName(theName) {
	return theName.split(" ").join("");
}
function changeIndex(amount) {
currentIndex +=Number(amount);
display()
}
function changeGroup(newGroup) {
currentGroup = newGroup;
currentIndex =0;
changeSelectors(newGroup);
display();
}
function changeSelectors(newGroup) {
for(var i =0;i<groups.length;i++) {
	
	var obj = document.getElementById("select"+arrayName(groups[i]));
	if (groups[i]==newGroup) {
		obj.innerHTML = '<span class="currentSelection"> '+newGroup.toProperCase()+' </span>';
	} else {
		obj.innerHTML = '<a href="javascript:changeGroup(\''+groups[i]+'\')"> '+groups[i].toProperCase()+' </a>';
	}
}
}
function disableButton(buttonName,buttonId) {
	var obj = document.getElementById(buttonId);
 	obj.innerHTML ='<span id="disabledButton"> '+buttonName+' </span>';
}
function enableButton(buttonName,indexChange,buttonId) {
	var obj = document.getElementById(buttonId);
	obj.innerHTML = '<a href="javascript:changeIndex(\''+indexChange+'\')"> '+buttonName+' </a>';
}
function display() {
if (showPages!=false) {
	groupList = eval(arrayName(currentGroup));
	if (currentIndex==0) {
		disableButton("&lt;Previous","previousButton");
	} else {
		enableButton("&lt;Previous",-1,"previousButton");
	}
	if (currentIndex==(groupList.length-1)) {
		disableButton("Next&gt;","nextButton");
	} else {
		enableButton("Next&gt;",1,"nextButton");
	}
	obj = document.getElementById("pageOf");
	obj.innerHTML = (currentIndex+1)+" of "+groupList.length;
	showHideArray(All,false);
	
	showHide(groupList[currentIndex],true);
} else {
	if (currentGroup!="All") {
		showHideArray(All,false);
		showHide(currentGroup,true);
	} else {
		showHideArray(All,true);
	}
}
}