/*  *** OVERVIEW ***
class cWkshp represents a workshop
	* knows its name and qualities (what session, what competency, what level)
	* given a Filter object, knows if its workshop should be displayed or hidden
	* can serialize/deserialize

class cPage represents the set of all workshops represented on the page
	* it orchestrates the visibilty and serialization of all workshop objects

class cFilter represents the setting that the user has selected for determining visibility
	* initializes to a default state
	* knows its current state
	* can change and can declar state -- setting by setting


 ***** All code developed by Randy Carey @ WFF *****
 
 ************* */



// ---------------------------------------
//  REUSABLE FUNCTIONS AND RETURN RESULTS 
function defaultFunction() {return "UNDECLARED";}

function returnTrue() {return true; }
function returnFalse() {return false;}

function retSession1() {return 1;}
function retSession2() {return 2;}
function retSession3() {return 3;}
function retSession4() {return 4;}
function retSession5() {return 5;}
function retSession6() {return 6;}
function retSession7() {return 7;}

function retCompDeveloping() {return "Dev";}
function retCompTough() {return "Tou";}
function retCompVisioning() {return "Vis";}
function retCompInitiative() {return "Ini";}

function retLevelEmLeader() {return "EL";}
function retLevelEmExec() {return "EE";}
function retLevelEXEC() {return "EX";}
function retLevelEmerging() { return "EM" };

function retNone() {return "";}


// ---- show-hide functions
function workshop_isTagFoundInPage(tag) {
	return (document.getElementById(tag) 
			&& document.getElementById(tag).style);
}
/*
function workshop_show(content) {
	if(isTagFoundInPage(content)){ 
		var style2 = document.getElementById(content).style;
		style2.display = "block";
	}
}

function workshop_hide(content) {
	if(isTagFoundInPage(content)) {
		var style2 = document.getElementById(content).style;
		style2.display = "none";
	}
}


function workshop_showHide(tag){
	if(isTagFoundInPage(tag)) {
	var style2 = document.getElementById(tag).style;
	style2.display = (style2.display == "block") ? "none": "block";
	}
}
*/

/*   **** CALLBACK FUNCTIONS -- called by each workshop against the filter

For each of the three major filter categories, I have establishes a callback function for each 
possible option.  As the workshop instance is being created, that workshops's constructor
calls the assign---Callback() function to determine which callback function should be assigned
to the respective implementation function.  This technique improves performance.  When the
workshop is asked to determine it's visibility based upon the filter, it will call the correct
filter function based upon the workshop's session, competency, and level.  Without these callbacks
being loaded during the object's construction, the object would have to conduct string comparison's
each time to it is asked to perform it visibility just to know which function on the fitler it should call.

*/

// **********  reusable callback functions for checking the SESSION
function callFilterSession1(filter){return filter.isSession1()}
function callFilterSession2(filter){return filter.isSession2()}
function callFilterSession3(filter){return filter.isSession3()}
function callFilterSession4(filter){return filter.isSession4()}
function callFilterSession5(filter){return filter.isSession5()}
function callFilterSession6(filter){return filter.isSession6()}
function callFilterSession7(filter){return filter.isSession7()}

function assignSessionCallback(session){
	if(session() == retSession1())
		return callFilterSession1;
	if(session() == retSession2())
		return callFilterSession2;
	if(session() == retSession3())
		return callFilterSession3;
	if(session() == retSession4())
		return callFilterSession4;
	if(session() == retSession5())
		return callFilterSession5;
	if(session() == retSession6())
		return callFilterSession6;
	if(session() == retSession7())
		return callFilterSession7;
	return returnFalse;
}

// **********  reusable callback functions for checking the COMPETENCY
function callFilterCompDeveloping(filter){return filter.isCompDeveloping()}
function callFilterCompTough(filter){return filter.isCompTough()}
function callFilterCompVisioning(filter){return filter.isCompVisioning()}
function callFilterCompInitiative(filter){return filter.isCompInitiative()}

function assignCompCallback(competency){
	if(competency() == retCompDeveloping())
		return callFilterCompDeveloping;
	if(competency() == retCompTough())
		return callFilterCompTough;
	if(competency() == retCompVisioning())
		return callFilterCompVisioning;
	if(competency() == retCompInitiative())
		return callFilterCompInitiative;		
	if(competency() == retNone())
		return returnTrue; // if this obj has no comp declared, assume any value matches
	return returnFalse;
}

// **********  reusable callback functions for checking the LEVEL
function callFilterLevelEL(filter){return filter.isLevelEmLeader()}
function callFilterLevelEE(filter){return filter.isLevelEmExec()}
function callFilterLevelEX(filter){return filter.isLevelEXEC()}
function callFilterLevelEmerging(filter){return filter.isLevelEmerging()}

function assignLevelCallback(level){ // returns the appropriate callback function based upon level
	if(level() == retLevelEmLeader())
		return callFilterLevelEL;
	if(level() == retLevelEmExec())
		return callFilterLevelEE;
	if(level() == retLevelEXEC())
		return callFilterLevelEX;
	if(level() == retLevelEmerging())
		return callFilterLevelEmerging;
	if(level() == retNone())
		return returnTrue; // if this obj has no comp declared, assume any value matches
	return returnFalse();
}


//  --------------------------------
//  --------    CLASSES    --------

		// *** cWorkshop ***
/*
function workshop_performVisibility(filter){
	if( (filter.isAllDays() || this.isSessionIncluded(filter))
		&&	this.isCompetencyIncluded(filter) 
		&&	this.isLevelIncluded(filter) 
			)
	{	this.displayWorkshop();
		return true; // returns value to assist testing
	}else{
		this.hideWorkshop();
		return false; // returns value to assist testing
	}
}
*/
function workshop_displayWorkshop(id) {
	if(workshop_isTagFoundInPage(id)){ 
		var style2 = document.getElementById(id).style;
		style2.display = "block";
	}
}
function workshop_hideWorkshop(id) {
		if(workshop_isTagFoundInPage(id)) {
		var style2 = document.getElementById(id).style;
		style2.display = "none";
	}
}


function cWorkshop(idCode, session, competency, level) {

	this.m_id = new String(idCode);
	this.getName= function(){return this.m_id;}
	this.getSession = session;
	this.getCompetency = competency;
	this.getLevel = level;
	this.performVisibility  //= workshop_performVisibility;
	= function (filter){
		
		if( filter == null) alert("filter is null");
		//alert(this.m_id+".performVisibility");

		if( (filter.isAllDays() || this.isSessionIncluded(filter))
			&&	this.isCompetencyIncluded(filter) 
			&&	this.isLevelIncluded(filter) 
				)
		{	this.displayWorkshop(this.m_id);
			return true; // returns value to assist testing
		}else{
			this.hideWorkshop(this.m_id);
			return false; // returns value to assist testing
		}
		

	}

	this.serializeSelf = defaultFunction;
	this.loadSelf = defaultFunction;
	
	// implemenation functions...
	this.isSessionIncluded = assignSessionCallback(session);// sets the appropriate callback function based upon SESSION
	this.isCompetencyIncluded = assignCompCallback(competency);// sets the appropriate callback function based upon COMPETENCY
	this.isLevelIncluded = assignLevelCallback(level); // sets the appropriate callback function based upon LEVEL
	this.displayWorkshop = workshop_displayWorkshop;
	this.hideWorkshop = workshop_hideWorkshop;

}

// ********** cPage ****

// construct member functions to be loaded into cPage...
function page_performVisibility(filter){
		var wk, i;
		for (i=0; i<this.workshops.length; ++i )
		{	wk = this.workshops[i];
			if(wk!=null) wk.performVisibility(filter);
		}
		return i;
	}
function page_serializeSelf(){
		for (i=0; i<this.workshops.length; ++i )
		{	this.workshops[i].serializeSelf(filter);
		}
	}
function page_loadSelf(filter){
		for (i=0; i<this.workshops.length; ++i )
		{	this.workshops[i].loadSelf(filter);
		}
	}
function page_set(item,wksp){ 
		this.workshops[item]=wksp;
	}

function cPage() {
	this.itemCount = 54; /* arbitrary number for now */
	this.workshops = new Array(this.itemCount); 
	this.performVisibility = page_performVisibility;
	this.serializeSelf= page_serializeSelf;
	this.loadSelf = page_loadSelf;
	this.set = page_set;
	}

// ************** cFilter **********

function retTestString() {return "test string"};

function cFilter(page) {
	this.page = page;
	this.text = retTestString;

	this.isAllDays = returnFalse; /* by turning this off, the sessions are not being overridden */
	this.isSession1 = returnTrue;
	this.isSession2 = returnTrue;
	this.isSession3 = returnTrue;
	this.isSession4 = returnTrue;
	this.isSession5 = returnTrue;
	this.isSession6 = returnTrue;
	this.isSession7 = returnTrue;

	this.isCompDeveloping = returnTrue;
	this.isCompTough = returnTrue;
	this.isCompVisioning = returnTrue;
	this.isCompInitiative = returnTrue;

	this.isLevelEmLeader = returnTrue;
	this.isLevelEmExec = returnTrue;
	this.isLevelEXEC = returnTrue;
	this.isLevelEmerging = function() { return (this.isLevelEmLeader() || this.isLevelEmExec() )};


/*	this.setAllDays(bool) = function(bool){  this.isAllDays = bool ? returnTrue : returnFalse }
	this.setSession1(bool) = function(bool){  this.isSession1 = bool ? returnTrue : returnFalse }
	this.setSession2(bool) = function(bool){  this.isSession2 = bool ? returnTrue : returnFalse }
	this.setSession3(bool) = function(bool){  this.isSession3 = bool ? returnTrue : returnFalse }
	this.setSession4(bool) = function(bool){  this.isSession4 = bool ? returnTrue : returnFalse }
	this.setSession5(bool) = function(bool){  this.isSession5 = bool ? returnTrue : returnFalse }
	this.setSession6(bool) = function(bool){  this.isSession6 = bool ? returnTrue : returnFalse }
	this.setSession7(bool) = function(bool){  this.isSession7 = bool ? returnTrue : returnFalse }

	this.setCompDeveloping(bool) = function(bool){  this.isCompDeveloping = bool ? returnTrue : returnFalse }
	this.setCompTough(bool) = function(bool){  this.isCompTough = bool ? returnTrue : returnFalse }
	this.setCompVisioning(bool) = function(bool){  this.isCompVisioning = bool ? returnTrue : returnFalse }
	this.setCompInitiative(bool) = function(bool){  this.isCompInitiative = bool ? returnTrue : returnFalse }

	this.setLevelEmLeader(bool) = function(bool){  this.isLevelEmLeader = bool ? returnTrue : returnFalse }
	this.setLevelEmExec(bool) = function(bool){  this.isLevelEmExec = bool ? returnTrue : returnFalse }
	this.setLevelEXEC(bool) = function(bool){  this.isLevelEXEC = bool ? returnTrue : returnFalse }
*/
	// TOGGLE...  // note: the passing of 'this' implements the 'Visitor' pattern.  See the Gang og Four's 'Design Patterns' for an explanation.
	this.toggleAllDays = function(){  this.isAllDays = this.isAllDays() ? returnFalse :returnTrue; this.page.performVisibility(this); }
	this.toggleSession1 = function(){  this.isSession1 = this.isSession1() ? returnFalse :returnTrue; this.page.performVisibility(this);}
	this.toggleSession2 = function(){  this.isSession2 = this.isSession2() ? returnFalse :returnTrue; this.page.performVisibility(this);}
	this.toggleSession3 = function(){  this.isSession3 = this.isSession3() ? returnFalse :returnTrue; this.page.performVisibility(this);}
	this.toggleSession4 = function(){  this.isSession4 = this.isSession4() ? returnFalse :returnTrue; this.page.performVisibility(this);}
	this.toggleSession5 = function(){  this.isSession5 = this.isSession5() ? returnFalse :returnTrue; this.page.performVisibility(this);}
	this.toggleSession6 = function(){  this.isSession6 = this.isSession6() ? returnFalse :returnTrue; this.page.performVisibility(this);}
	this.toggleSession7 = function(){  this.isSession7 = this.isSession7() ? returnFalse :returnTrue; this.page.performVisibility(this);}

	this.toggleCompDeveloping = function(){  this.isCompDeveloping = this.isCompDeveloping() ? returnFalse :returnTrue ; this.page.performVisibility(this);}
	this.toggleCompTough = function(){  this.isCompTough = this.isCompTough() ? returnFalse :returnTrue; this.page.performVisibility(this); }
	this.toggleCompVisioning = function(){  this.isCompVisioning = this.isCompVisioning() ? returnFalse :returnTrue; this.page.performVisibility(this); }
	this.toggleCompInitiative = function(){  this.isCompInitiative = this.isCompInitiative() ? returnFalse :returnTrue; this.page.performVisibility(this); }

	this.toggleLevelEmLeader = function(){  this.isLevelEmLeader = this.isLevelEmLeader() ? returnFalse :returnTrue; this.page.performVisibility(this); }
	this.toggleLevelEmExec = function(){  this.isLevelEmExec = this.isLevelEmExec() ? returnFalse :returnTrue; this.page.performVisibility(this); }
	this.toggleLevelEXEC = function(){  this.isLevelEXEC = this.isLevelEXEC() ? returnFalse :returnTrue; this.page.performVisibility(this); }



}




//  --------------------------------
//  ----- WORKSHOP INSTANCES  ------

var Aspkr1 = new cWorkshop("W1spkr4", retSession1,retCompInitiative,retLevelEmLeader);
var Aspkr2 = new cWorkshop("W1spkr5", retSession1,retCompInitiative,retLevelEmLeader);
var Aspkr3 = new cWorkshop("W1spkr8", retSession1,retCompVisioning,retLevelEmLeader);
var Aspkr4 = new cWorkshop("W1spkr7", retSession1,retCompTough,retLevelEmLeader);
var Aspkr5 = new cWorkshop("W1spkr6", retSession1,retCompTough,retLevelEmLeader);
var Aspkr6 = new cWorkshop("W1spkr1", retSession1,retCompDeveloping,retLevelEmExec);
var Aspkr7 = new cWorkshop("W1spkr2", retSession1,retCompTough,retLevelEmExec);
var Aspkr8 = new cWorkshop("W1spkr3", retSession1,retCompVisioning,retLevelEmExec);
var EW1spkr = new cWorkshop("E-W1spkr", retSession1,retNone,retLevelEXEC);
var EW1spkr2 = new cWorkshop("E-W1spkr2", retSession1,retNone,retLevelEXEC);

var Bspkr1 = new cWorkshop("W2spkr1", retSession2,retCompDeveloping,retLevelEmExec);
var Bspkr2 = new cWorkshop("W2spkr2", retSession2,retCompVisioning,retLevelEmExec);
var Bspkr3 = new cWorkshop("W2spkr3", retSession2,retCompInitiative,retLevelEmLeader);
var Bspkr4 = new cWorkshop("W2spkr4", retSession2,retCompInitiative,retLevelEmLeader);
var Bspkr5 = new cWorkshop("W2spkr5", retSession2,retCompTough,retLevelEmLeader);
var NET08_1 = new cWorkshop("NET08-1", retSession2,retCompVisioning,retNone);
var NET08_2 = new cWorkshop("NET08-2", retSession2,retNone,retNone);
var NET08_3 = new cWorkshop("NET08-3", retSession2,retNone,retNone);
var EW2spkr = new cWorkshop("E-W2spkr", retSession2,retNone,retLevelEXEC);

var Cspkr1 = new cWorkshop("W3spkr1", retSession3,retCompDeveloping,retLevelEmExec);
var Cspkr2 = new cWorkshop("W3spkr2", retSession3,retCompTough,retLevelEmExec);
var Cspkr3 = new cWorkshop("W3spkr3", retSession3,retCompVisioning,retLevelEmExec);
var Cspkr4 = new cWorkshop("W3spkr4", retSession3,retCompInitiative,retLevelEmLeader);
var Cspkr5 = new cWorkshop("W3spkr5", retSession3,retCompInitiative,retLevelEmLeader);
var Cspkr6 = new cWorkshop("W3spkr6", retSession3,retCompTough,retLevelEmLeader);
var Cspkr7 = new cWorkshop("W3spkr7", retSession3,retCompTough,retLevelEmLeader);
var Cspkr8 = new cWorkshop("W3spkr8", retSession3,retCompVisioning,retLevelEmLeader);
var EW3spkr = new cWorkshop("E-W3spkr", retSession3,retNone,retLevelEXEC);

var Dspkr1 = new cWorkshop("W4spkr1", retSession4,retCompDeveloping,retLevelEmExec);
var Dspkr2 = new cWorkshop("W4spkr2", retSession4,retCompTough,retLevelEmExec);
var Dspkr3 = new cWorkshop("W4spkr3", retSession4,retCompDeveloping,retLevelEmLeader);
var Dspkr4 = new cWorkshop("W4spkr4", retSession4,retCompDeveloping,retLevelEmLeader);
var Dspkr5 = new cWorkshop("W4spkr5", retSession4,retCompInitiative,retLevelEmLeader);
var Dspkr6 = new cWorkshop("W4spkr6", retSession4,retCompTough,retLevelEmLeader);
var Dspkr7 = new cWorkshop("W4spkr7", retSession4,retCompVisioning,retLevelEmLeader);
var EW4spkr = new cWorkshop("E-spkr4", retSession4,retNone,retLevelEXEC);


var Fspkr1 = new cWorkshop("W5spkr1", retSession5,retCompDeveloping,retLevelEmExec);
var Fspkr2 = new cWorkshop("W5spkr2", retSession5,retCompTough,retLevelEmExec);
var Fspkr3 = new cWorkshop("W5spkr3", retSession5,retCompDeveloping,retLevelEmLeader);
var Fspkr4 = new cWorkshop("W5spkr4", retSession5,retCompDeveloping,retLevelEmLeader);
var Fspkr5 = new cWorkshop("W5spkr5", retSession5,retCompInitiative,retLevelEmLeader);
var Fspkr6 = new cWorkshop("W5spkr6", retSession5,retCompTough,retLevelEmLeader);
var Fspkr7 = new cWorkshop("W5spkr7", retSession5,retCompVisioning,retLevelEmLeader);
var EW5spkr = new cWorkshop("E-W5spkr", retSession5,retNone,retLevelEXEC);
var FNet = new cWorkshop("NET08-2", retSession5,retCompTough,retNone);

var Gspkr = new cWorkshop("W6spkr", retSession6,retNone,retLevelEmerging);

var Hspkr1 = new cWorkshop("W7spkr1", retSession7,retNone,retLevelEmerging);
var Hspkr2 = new cWorkshop("W7spkr2", retSession7,retNone,retLevelEmerging);
var Hspkr3 = new cWorkshop("W7spkr3", retSession7,retNone,retLevelEmerging);
var Hspkr4 = new cWorkshop("W7spkr4", retSession7,retNone,retLevelEmerging);

var NETS2 = new cWorkshop("NET-S2", retSession2,retCompVisioning,retLevelEmerging);
var NETS2E = new cWorkshop("E-NET-S2", retSession2,retNone,retLevelEXEC);
var NETS5 = new cWorkshop("NET-S5", retSession5,retCompTough,retLevelEmerging);
var NETS5E = new cWorkshop("E-NET-S5", retSession5,retNone,retLevelEXEC);


//  --------------------------------
//  ----- LOAD PAGE  ------

var thePage = new cPage();
thePage.set(0,Aspkr1);
thePage.set(1,Aspkr2);
thePage.set(2,Aspkr3);
thePage.set(3,Aspkr4);
thePage.set(4,Aspkr5);
thePage.set(5,Aspkr6);
thePage.set(6,Aspkr7);
thePage.set(7,Aspkr8);
thePage.set(8,EW1spkr);
thePage.set(9,EW1spkr2);
thePage.set(10,Bspkr1);
thePage.set(11,Bspkr2);
thePage.set(12,Bspkr3);
thePage.set(13,Bspkr4);
thePage.set(14,Bspkr5);
thePage.set(15,NET08_1);
thePage.set(16,NET08_2);
thePage.set(17,NET08_3);
thePage.set(18,EW2spkr);
thePage.set(19,Cspkr1);
thePage.set(20,Cspkr2);
thePage.set(21,Cspkr3);
thePage.set(22,Cspkr4);
thePage.set(23,Cspkr5);
thePage.set(24,Cspkr6);
thePage.set(25,Cspkr7);
thePage.set(26,Cspkr8);
thePage.set(27,EW3spkr);
thePage.set(28,Dspkr1);
thePage.set(29,Dspkr2);
thePage.set(30,Dspkr3);
thePage.set(31,Dspkr4);
thePage.set(32,Dspkr5);
thePage.set(33,Dspkr6);
thePage.set(34,Dspkr7);
thePage.set(35,EW4spkr);
thePage.set(36,Fspkr1);
thePage.set(37,Fspkr2);
thePage.set(38,Fspkr3);
thePage.set(39,Fspkr4);
thePage.set(40,Fspkr5);
thePage.set(41,Fspkr6);
thePage.set(42,Fspkr7);
thePage.set(43,FNet);
thePage.set(44,EW5spkr);
thePage.set(45,Gspkr);
thePage.set(46,Hspkr1);
thePage.set(47,Hspkr2);
thePage.set(48,Hspkr3);
thePage.set(49,Hspkr4);
// -----  late additions...
thePage.set(50,NETS2);
thePage.set(51,NETS2E);
thePage.set(52,NETS5);
thePage.set(53,NETS5E);



//  --------------------------------
//  ----- LOAD FILTER  ------

var theFilter = new cFilter(thePage);
thePage.m_filter = theFilter;
