
// Presenter List Browser Class
function PresenterList() {
	// 
	this._pageNumber = 1;
	this._displayNumber = 20; // The number of presenters to display in the list
	this._startNumber = 0; // The starting item number to display
	this._alphaFName = ''; // The alpha filter for the first name
	this._alphaLName = ''; // The alpha filter for the last name
	this._sortCol = "l_name"; // The column to sort the list. Can be id, title, date, type or views
	this._sortType = "ASC";
	this._conferenceID = 'all';
	this._conferenceNameArray = new Array(); // Array of all of the conference Names
	this._conferenceIDArray = new Array(); // Array of all of the conference ID's
}

PresenterList.prototype.goPage = function(pageNumber) {
	this._pageNumber = pageNumber;
	this._startNumber = (this._displayNumber * (this._pageNumber-1));
	this.getList();
}

PresenterList.prototype.alphaFilter = function(type,letter) {
	//alert("Setting alpha filter");
	if(letter == 'all') {
		this.clearAlphaFilter('last');
	} else {
		if(type == 'first') {
			this._alphaFName = String(letter).toLowerCase();
		} else {
			this._alphaLName = String(letter).toLowerCase();
		}
		this._pageNumber = 1;
		this._startNumber = 0;
		this.displayFilters();
		this.getList();
	}
}
PresenterList.prototype.conferenceFilter = function(id) {
	this._conferenceID = id;
	//alert("New ID is "+id);
	this.displayFilters();
	this.getList();
}

PresenterList.prototype.clearAlphaFilter = function(type) {
	if(type == 'first') {
		this._alphaFName = '';
	} else {
		this._alphaLName = '';
	}
	this.displayFilters();
	this.getList();
}
PresenterList.prototype.displayFilters = function() {
	var alphaArray = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
	var fHTML = "";
	if(this._filterDiv) {
		// Conference Filter
		fHTML += "<div id='conferenceFilter' style='margin-bottom:5px'><div style='width:100px;float:left'>Conference:</div>";
		fHTML += "<select name='conferenceFilter' id='conferenceFilter' onchange='PL.conferenceFilter(this.value)' style='width:400px;'>";
		fHTML += "<option value='all'>All Conferences</option>";
		for(var i=0; i<this._conferenceIDArray.length; i++) {
			if(this._conferenceIDArray[i] == this._conferenceID) {
				fHTML += "<option value='"+this._conferenceIDArray[i]+"' selected='selected'>"+this._conferenceNameArray[i]+"</option>";
			} else {
				fHTML += "<option value='"+this._conferenceIDArray[i]+"'>"+this._conferenceNameArray[i]+"</option>";
			}
		}
		fHTML += "</select>";
		fHTML += "</div>";		
		
		
		// Alpha Last Name Filter
		fHTML += "<div id='alphaFNameFilter' style='margin-bottom:5px'><div style='width:100px;float:left'>Last Name:</div>";
		fHTML += "<select name='alphaFilter' id='alphaFilter' onchange='PL.alphaFilter(\"last\",this.value)' style='width:200px;'>";
		fHTML += "<option value='all'>All Presenters</option>";
		for(var i=0; i<alphaArray.length; i++) {
			var l = alphaArray[i].toLowerCase();
			
			if(this._alphaLName.toLowerCase() == l) {
				//fHTML += "<span class='active'>"+alphaArray[i]+"</span>&nbsp;";	
				fHTML += "<option value='"+alphaArray[i]+"' selected='selected'>Starts with "+alphaArray[i]+"</option>";
			} else {
				//fHTML += "<a href='javascript:PL.alphaFilter(\"first\",\""+l+"\")'>"+alphaArray[i]+"</a>&nbsp;";
				fHTML += "<option value='"+alphaArray[i]+"'>Starts with "+alphaArray[i]+"</option>";
			}				
		}
		fHTML += "</select>";
		fHTML += "</div>";
		/*
		if(this._alphaFName == '') {
			fHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<span class='active'>All</span>";
		} else {
			fHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:PL.clearAlphaFilter(\"first\");'>All</a>";
		}
		
		fHTML += "</div>";
		
		// Alpha Last Name Filter
		fHTML += "<div id='alphaFNameFilter'>Last name: &nbsp;&nbsp;&nbsp; ";
		for(var i=0; i<alphaArray.length; i++) {
			var l = alphaArray[i].toLowerCase();
			if(this._alphaLName.toLowerCase() == l) {
				fHTML += "<span class='active'>"+alphaArray[i]+"</span>&nbsp;";	
			} else {
				fHTML += "<a href='javascript:PL.alphaFilter(\"last\",\""+l+"\")'>"+alphaArray[i]+"</a>&nbsp;";	
			}			
		}
		if(this._alphaLName == '') {
			fHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<span class='active'>All</span>";
		} else {
			fHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:PL.clearAlphaFilter(\"last\");'>All</a>";
		}
		fHTML += "</div>";	
		*/
	}
	
	this._filterDiv.innerHTML = fHTML;
}

PresenterList.prototype.showFilter = function(filterName) {
	if(filterName.toLowerCase() == 'fname') {
		
	} else if(filterName.toLowerCase() == 'lname') {
		
	} else if(filterName.toLowerCase() == 'conference') {
		
	}
}

PresenterList.prototype.clearFilter = function(filterName) {
	
}


PresenterList.prototype.sort = function(sortColumn,sortType) {
	this._pageNumber = 1;
	this._startNumber = 0;
	this._sortCol = sortColumn;
	this._sortType = sortType;	
	this.getList();
}

PresenterList.prototype.filter = function() {	
	this._pageNumber = 1;
	this._startNumber = 0;
	this.getList();
}

PresenterList.prototype.addConference = function(id,name) {	
	this._conferenceIDArray.push(id);
	this._conferenceNameArray.push(name);	
}

PresenterList.prototype.getList = function() {
	var ajaxRequestObj = new ajaxRequest();
	var pDIV = this._presenterDiv;
	//pDIV.innerHTML = "<div align='center'>Loading Results....</div>";
	ajaxRequestObj.onreadystatechange = function(){		
		if(ajaxRequestObj.readyState == 4){
			if(ajaxRequestObj.status == 200) {
				// Process response
				pDIV.innerHTML = ajaxRequestObj.responseText;
			} else {
				// Error
				pDIV.innerHTML = "<strong>Error!</strong>";
			}			
		}
	}
	
	var qString = 'alphaFName='+this._alphaFName+'&alphaLName='+this._alphaLName;
	qString += '&sort='+this._sortCol+'&startNum='+this._startNumber+'&displayNum='+this._displayNumber;
	qString += '&sortType='+this._sortType+'&conferenceID='+this._conferenceID+'&action=getlist';
	//alert("qstring is "+qString);
	ajaxRequestObj.open('GET', 'ajax/PresenterBrowse.php?'+qString, true);
	ajaxRequestObj.send(null);
}
PresenterList.prototype.setFilterDiv = function(divID) {
	this._filterDiv = document.getElementById(divID);
}
PresenterList.prototype.setPresenterDIV = function(divID) {
	this._presenterDiv = document.getElementById(divID);
}
