


//**************************************************************************************
// Global constants

// Xml data nodes
var __donorXmlNode = "donor";
var __collabXmlNode = "collaboration";
var __summaryXmlNode = "description";
var __contactXmlNode = "contact";
var __faqXmlNode = "faq";
var __countryXmlNode = "country";

var __casestudy = "casestudy";
var __issue = "issue";
var __manual = "manual";
var __other = "other";
var __book = "book";
var __article= "article";

Project.prototype = new TabNav();
Project.prototype.constructor = Project;
function Project() {
		
	this.code;
	this.name;
	this.mailinglist;
	this.isOpen = false;
		
} // end object

	Project.prototype.open = function(code, projname, contentDiv) {
		if (!code) {alert("UNEXPECTED: 'code' argument requires a value.");return;} // end if	
		if (!contentDiv || !CDA.find(contentDiv)){alert("UNEXPECTED: 'contentDiv' either requires a value or does not exist.");return;} // end if 

		//var data = CDA.AjaxXml.getdata(this.xmlsource)		
		this.code = code;
		this.name = projname;
		this.contentDiv = CDA.find(contentDiv);
		this.load("maintab");
		this.mailinglist = new EmailForm("project_mailinglist.php?pid="+this.code+"&pname="+this.name);
		this.isOpen = true;		
	} // end method
	
	//**************************************************************************************
	// Method:		Override getEvalJsFunc().  Sets function calls to be evaluated on tab click
	// Returns:		Null
	Project.prototype.getEvalJsFunc = function(anchorLoopIndex) { // method override
		switch (anchorLoopIndex) {
			case 0: // General Tab
				return "CDA.Project.showGeneral(__summaryXmlNode)";					
			
			// CHANGE 05/07: Publication tab change to Project Document tab.  Loads project-related
			// description of their project documents instead of defaulting to case studies.
			case 1: // Project Documents
				//return "CDA.Project.showPublication(__casestudy)";
				return "CDA.Project.showProjDoc()";
				
			// CHANGE 05/07: Books tab change to Publications tab.  Publications tab will now include
			// both Books and Articles			
			case 2: // Publications						
				return "CDA.Project.showPublication('book')";
						
			case 3: // Countries
				return "CDA.Project.showCountry()";
				break;
			
			case 4: // Contact
				return "CDA.Project.showContact()";
				break;
			
			case 5: // FAQ
				return "CDA.Project.showFaq()";
				break;
			
			default:
				break;
		
		} // end switch
		return null;
	} // end override
		
	
	//**************************************************************************************
	// Method:		showProjDoc()
	// Returns:		Null
	// Comments:	CHANGE 05/07: Was showPublication(). Change displays default description screen
	//				description what Project Documents are to the user				
	Project.prototype.showProjDoc = function(pubtype) {
		
		if (!this.isOpen){alert("UNEXPECTED: Project must be opened first prior to calling showDesc()");return;} // end if 
		this.clearContent()
		// Build nestednav
		var nav = new ProjNestedNav(
							new Array(
							CDA.Html.makeAnchor("javascript:CDA.Project.showProjDoc(__casestudy);", "Case Study/Field Visit"),
							CDA.Html.makeAnchor("javascript:CDA.Project.showProjDoc(__issue);", "Issues"),
							CDA.Html.makeAnchor("javascript:CDA.Project.showProjDoc(__manual);", "Training Materials"),
							CDA.Html.makeAnchor("javascript:CDA.Project.showProjDoc(__other);", "Reports & Other Documents")
							)	
							);								
		
		this.contentDiv.appendChild(nav.toElement());
		
		var dt=null;
		
		switch (pubtype) {
			case __casestudy:				
				nav.anchors[0].className="selected";				
				dt = new CaseStudy( this.code, "datatable", true );			
				break;
				
			case __issue:
				nav.anchors[1].className="selected";
				dt = new Issue( this.code, "datatable", true );				
				break;
			
			case __manual:
				nav.anchors[2].className="selected";
				dt = new Manual( this.code, "datatable", true );
				break;
				
			case __other:
				nav.anchors[3].className="selected";
				dt = new Other( this.code, "datatable", true );
				break;
				
			default:				
				dt = new IFrameElem( );
				dt.iframeSrc = "nested_project_doc_summary.php?pid="+this.code;	
				break;
						
		} // end switch	
		
		dt.parent = this.contentDiv;
		dt.show();
		    
	} // end method
	
	//**************************************************************************************
	// Method:		showPublication()
	// Returns:		Null
	// Comments:	ADDED 05/07: Was showPublication(). Change displays default description screen
	//				description what Project Documents are to the user				
	Project.prototype.showPublication = function(pubtype) {
		
		if (!this.isOpen){alert("UNEXPECTED: Project must be opened first prior to calling showDesc()");return;} // end if 
		this.clearContent()
		// Build nestednav
		var nav = new ProjNestedNav(
							new Array(
							CDA.Html.makeAnchor("javascript:CDA.Project.showPublication('book');", "Books"),
							CDA.Html.makeAnchor("javascript:CDA.Project.showPublication('article');", "Articles")
							)	
							);								
		
		this.contentDiv.appendChild(nav.toElement());
		
		var dt=null;
		
		switch (pubtype) {
			case "book":				
				nav.anchors[0].className="selected";				
				dt = new Book(this.code, null, false);		
				break;
				
			case "article":
				nav.anchors[1].className="selected";
				dt = new Article(this.code, "datatable", true);		
				break;
		} // end switch	
		
		dt.parent = this.contentDiv;
		dt.show();
		    
	} // end method
	Project.prototype.showCountry = function() {

		if (!this.isOpen){alert("UNEXPECTED: Project must be opened first prior to calling showDesc()");return;} // end if 
		this.clearContent();
		var countryMap = new Map(this.code, true);		
		countryMap.parent = this.contentDiv;
		countryMap.show();		
	} // end method

	Project.prototype.showGeneral = function(dataNode) {
		if (!this.isOpen){alert("UNEXPECTED: Project must be opened first prior to calling showDesc()");return;} // end if 
		this.clearContent(); 
		// Build nestednav
		var nav = new ProjNestedNav(
							new Array(
							CDA.Html.makeAnchor("javascript:CDA.Project.showGeneral(__summaryXmlNode);", "Project Summary"),
							CDA.Html.makeAnchor("javascript:CDA.Project.showGeneral(__donorXmlNode);", "Donors"),
							CDA.Html.makeAnchor("javascript:CDA.Project.showGeneral(__collabXmlNode);", "Agencies we work with")		
							)
							);	
		this.contentDiv.appendChild(nav.toElement());	
		
		switch (dataNode) {
			case __summaryXmlNode:
				nav.anchors[0].className="selected";
				nested = new IFrameElem( );
				nested.iframeSrc = "nested_project_summary.php?pid="+this.code;				
				break;
				
			case __donorXmlNode:
				nav.anchors[1].className="selected";
				nested = new IFrameElem( );
				nested.iframeSrc = "nested_donor.php?pid="+this.code;
				break;
			
			case __collabXmlNode:
				nav.anchors[2].className="selected";
				nested = new IFrameElem( );
				nested.iframeSrc = "nested_collaboration.php?pid="+this.code+"&intro=1";
				break;
				
			default:				
				alert("UNEXPECTED:  showGeneral() method.  Expected switch match not found.");return;
						
		} // end switch	
			
		nested.parent = this.contentDiv;
		nested.show();
	} // end method

	Project.prototype.showContact = function() {
		if (!this.isOpen){alert("UNEXPECTED: Project must be opened first.");return;} // end if 	

		this.clearContent();
		nested = new IFrameElem( );
		nested.iframeSrc = "nested_projcontact.php?pid="+this.code+"&css=datatable&pname="+this.name;	
		nested.parent = this.contentDiv;
		nested.show();				
	} // end method
	
	Project.prototype.showFaq = function() {
		if (!this.isOpen){alert("UNEXPECTED: Project must be opened first.");return;} // end if 	

		this.clearContent();
		nested = new IFrameElem( );
		nested.iframeSrc = "nested_projfaq.php?pid="+this.code+"&intro=1";	
		nested.parent = this.contentDiv;
		nested.show();				
	} // end method

//**************************************************************************************
// Object:		ProjNestedNav
// Inherits:	NestedNav (js/NestedNav.js)
ProjNestedNav.prototype = new NestedNav();
ProjNestedNav.prototype.constructor=ProjNestedNav;
function ProjNestedNav(menuarray) {
		
	this.cssClass = "nnInnerTab";
	this.separator = new TextSeparator("|", "separator");
	this.anchors = menuarray;
			
} // end object

	
//**************************************************************************************
// Object:		EmailForm
// Inherits:	DivPopup.  
EmailForm.prototype = new DivPopup();
EmailForm.prototype.constructor=EmailForm;
function EmailForm(frameSrc) {

	this.superC = DivPopup;
	this.superC(480, 350);
	this.frameSrc = frameSrc;
	this.frame = document.createElement("iframe");
	this.frame.id = "iframeEmailForm";
	this.frame.setAttribute("scrolling", "0");  // setting this attribute without setAttribute crashes IE for some reason			
	this.frame.frameBorder="0";
} // end object

	//**************************************************************************************
	// Method:		show() 
	// Returns:		
	EmailForm.prototype.show = function(){
		this.screen.show();
		this.createElements();	
				
		this.frame.src = this.frameSrc;
		
		this.contentDiv.innerHTML = "";
		this.contentDiv.appendChild(this.frame);
		CDA.getDocBody().appendChild(this.outerTable);
		
	} // end function

	
if(!window.CDA) {
	CDA=new Object();
} // end if

if(!window.CDA.Project) {
	CDA.Project=new Project();
} // end if
	



