/* org_notes.js */

Page.prototype.orgNotesDidLoad = function(note)
{
	this.orgNotes = note.userInfo.object;
	if(this.orgNotesAnchor){
		this.orgNotesAnchor.style.color = "";
		this.setupOrgNotesLink(this.orgNotesAnchor);
	}
}

Page.prototype.orgNotesDidFail = function(note)
{
	var msg;
	switch(note.userInfo.errorCode){
		case Utils.ParserError:
			msg = "XML parser error:<br>" + note.userInfo.argument;
			break;
		case Utils.LoadError:
			msg = "Load error: " + note.userInfo.argument;
			break;
		case Utils.ServerError:
			msg = "Server error: server returned status " + note.userInfo.argument;
			break;
		case Utils.RequestError:
			msg = "Request error: " + note.userInfo.argument;
			break;
	}
	this.orgNotes = {error:"Unable to fetch Organism notes: " + msg};
	if(this.orgNotesAnchor){
		this.orgNotesAnchor.style.color = "gray";
		this.setupOrgNotesLink(this.orgNotesAnchor);
	}
}

Page.prototype.setupOrgNotesLink = function(link)
{
	if(this.orgNotesAnchor.addEventListener)
		this.orgNotesAnchor.addEventListener('click', function(eventObj){
			Notification.postNotification("ShowOrgNotes", this, {event:eventObj});
		}, false);
	else if(this.orgNotesAnchor.attachEvent)
		this.orgNotesAnchor.attachEvent('onclick', function(){
			Notification.postNotification("ShowOrgNotes", this, {event:event});
		});
	NotificationCenter.removeObserver(this, InfoUtils.OrgNotesLoaded, null);
	NotificationCenter.removeObserver(this, InfoUtils.OrgNotesFailed, null);
	NotificationCenter.addObserver(this, "showOrgNotes", "ShowOrgNotes");
}


Page.prototype.showOrgNotes = function(note)
{
	if(this.infoPanel){
		if(this.infoPanel.itemNode)
			this.infoPanel.removeChild(this.infoPanel.itemNode);
		var div = this.infoPanel.itemNode = $element("div");
		this.infoPanel.appendChild(div);
		if(this.orgNotes){
			if(this.orgNotes.error){
				var h4 = $element("h4");
				h4.appendChild($text("Error getting organism notes"));
				h4.className = "error";
				div.appendChild(h4);
				var p = $element("p");
				p.appendChild($text(this.orgNotes.error));
				p.className = "error";
				div.appendChild(p);
			}
			if(this.orgNotes.title){
				var h3 = $element("h3");
				h3.appendChild($text(this.orgNotes.title));
				div.appendChild(h3);
			}
			if(this.orgNotes.text){
				var p = $element("p");
				p.appendChild($text(this.orgNotes.text));
				div.appendChild(p);
			}
			if(!this.orgNotes.error && !this.orgNotes.title && !this.orgNotes.text){
				var h4 = $element("h4");
				h4.innerHTML = "Organism notes not available";
				div.appendChild(h4);
			}
		}else{
			var p = $element("p");
			p.innerHTML = "Organism notes not loaded";
			div.appendChild(p);
		}
		this.infoPanel.className = "org-notes";
		this.infoPanel.style.top = '120px';
		this.infoPanel.style.left = '100px';
		this.infoPanel.style.visibility = 'visible';
		if(note.userInfo && note.userInfo.event)
			note.userInfo.event.cancelBubble = true;
	}
}
