// the format followed is 
// Name # Author1, Author2.. # Conference # Year # pslink # pdflink

var allAuthors = new Array();			/* list of all authors and their information */ 
var allPublications = new Array();		/* list of all the publications from all the authors */

function init()
{
	/* Note To Maintainer: Please update this list as necessary*/
	var authorUrlList = new Array    (
							"Ajay Mani", "http://www.stanford.edu/~ajaym/papers/list.txt",
							"Yoav Shoham", "http://www.stanford.edu/~ajaym/papers/list2.txt",
							"Samuel Ieong", "http://www.stanford.edu/~ajaym/papers/list3.txt"
							);

	//alert(url_list);
	load_all_publications (authorUrlList);
	
}

function load_all_publications(authorUrlList)
{
	for(var idx=0;idx<authorUrlList.length;idx+=2)
	{
		var publicationObj = load_author_publications(authorUrlList[idx], authorUrlList[idx+1]);
	}
	
}


/* adding to the Array prototype */
Array.prototype.contains = function(obj) 
{
	for(var num = 0; num< this.length; num++)
	{
		if(this[num].name == obj.name)
			return true;
	}
	return false;
}

Array.prototype.pushUnique = function(obj) 
{
	for(var num = 0; num< this.length; num++)
	{
		if(this[num].name == obj.name)
			return;
	}
	this.push(obj);
}

function load_author_publications(authorName, authorUrl)
{
	var disp = new Dispatcher(0);
	var url = authorUrl;
	var fnCallBack = function (respParamsObj)
	{
		respText = respParamsObj.getText();
		//alert(respText);
		publicationList = respText.split("\n");
		var authorsPublications = new Array();
		for(var num = 0; num< publicationList.length; num++)
		{
			var publicationObj = new PublicationObject();
			publicationObj.createPublication(publicationList[num]);
			authorsPublications.push(publicationObj);
			if(!allPublications.contains(publicationObj))
			{
				allPublications.pushUnique(publicationObj);
				//publicationObj.addPublicationTo("publications_table");
			}
		}
		var author = new AuthorObject();
		author.createAuthor(authorName, authorsPublications);
		allAuthors.push(author);
	
	}
	
	disp.Invoke(url,null,fnCallBack);
	
}


function sort_by_author()
{
	var authorListTable = elm("author_list_table");
	
	var origTableObj = elm("author_table");
	
	
	for(var num = 0; num< allAuthors.length; num++)
	{
		var publicationList = allAuthors[num].listOfPublications;
		var tableObj = origTableObj.cloneNode(true);
		var trObj = tableObj.insertRow(tableObj.rows.length);
		var tdObj = trObj.insertCell(trObj.cells.length);
		tableObj.setAttribute("id","author_"+num);
		tableObj.style.display = "";
		
		authorListTable.innerHTML += "<div> Author: " + allAuthors[num].getName() + " </div>";
		authorListTable.appendChild(tableObj);
		
		for(var pubNum = 0; pubNum< publicationList.length; pubNum++)
		{
			var publicationObj = publicationList[pubNum];
			publicationObj.addPublicationTo("author_"+num);
		}
		
		var st1 = new SortableTable(elm("author_"+num), ["Number", "CaseInsensitiveString", "CaseInsensitiveString", "CaseInsensitiveString", "None"]);
		
	}
}
