﻿var elearning_version='2009-09-29 14:08';
Ext.BLANK_IMAGE_URL = '/appjs/ext/ext-2.1/resources/images/default/s.gif';
Ext.QuickTips.init();

/*namespace used so that data can be easily accessed reguardless of scoping*/
YAHOO.namespace("elearning");

//shortcut to namespace
var $eLearn=YAHOO.elearning;
	/*setup namespaces for main page vars */
	$eLearn.jsnProject={};
	$eLearn.ELearnTypeGroup=[];
	$eLearn.ELearnFocusGroup=[];

/*do not call anything until page loads*/
/* set up dialogs */
YAHOO.util.Event.onDOMReady(function(){	
//Ext.onReady(function(){
	//TODO:check cookies for logged in status currently cannot find Email (use email) or NMCR_ID
	//clear all cookie information
	//resetAppEvent();
	
	initProjectsObjects();
	initCurriculumObjects();
	initPage();	
	Ext.LoadMask('content-grid',{});
	dialog_login_setup();
	dialog_email_setup();
	dialog_add_setup();
	dialog_remind_setup();
	
	//TODO:change classname on YUI dialog close to x-hide-offsets
	
	//TODO:change display to the elements
	document.getElementById('dialog_login').style.display='block';
	document.getElementById('dialog_add').style.display='block';
	document.getElementById('dialog_email').style.display='block';
	document.getElementById('dialog_remind').style.display='block';
	
	setTimeout(function(){
		Ext.get('loading').remove();
		Ext.get('loading-mask').fadeOut({remove:true});
	}, 1000);
 }); 
 

/*=============================
 * Function is fired on load and unload
 ============================*/
function resetAppEvent(){
	//alert("in the resetApp function triggered by ");
	//for firefox
	//YAHOO.util.Connect.asyncRequest('POST','/appjson/jsnLogin.asp',null,"LoginAction=logout");
	
	//for IE
	HAR.Cookie.del({name: "Login"});
	HAR.Cookie.del({name: "Username"});
	HAR.Cookie.del({name: "Email"});
	HAR.Cookie.del({name: "NMCR_ID"});
}

/*========================================================================
 * this runs on page load.  sets up dialogs and retrieves 
 *  JSON recordset of projects
 ========================================================================*/
function initPage() {
	/* ie quirk fix: javascript sometimes called before page fully loaded.*
		if(!document.getElementById('dialog_login')) {
			 window.setTimeout('initPage()', 500)  
		return false;
		}*/	
	/* display top bar based on user logged in or not */
	UserBarDisplay();
	
	/*get Project List into local JSON recordset (user favorite data included if logged in*/
	var url="/appjson/jsnELearningProjects.asp";
	var ajaxProjectList=YAHOO.util.Connect.asyncRequest('GET',url, {
							success:function(o){
								$eLearn.jsnProject=eval(o.responseText);
								runProjectFilter();
								handle_ProjectLoad();
								},
							failure:function(o){
								alert('Error:\nProject Data not loaded.');
								}
	});
	/*TODO: get related projects - ajax/jsn*/
}

/*========================================================================
 * filter projects based on type, focus, favorites, place results in 
 * array $eLearn.aProjectFiltered
 ========================================================================*/
function runProjectFilter() {
	/*ProjectTypeAndFocusReset();
	YAHOO.elearning.dsJsonProjects.filterBy(filterGrid);
	UpdateProjectTypeAndFocusCounts();*/
	
	/* make sure filter checkboxes are set correctly
	DEPRECATED: 24 Oct 2007 MDB
	//ProjectFocusAndTypeAllCheck();
	*/
	/*===========
	DEPRECATED: 5 Dec 2007 MDB
	/*clear filtered projects*/
	$eLearn.aProjectFiltered=[]; 
		ProjectTypeAndFocusReset();
	//only get selected project type groups 
	var	aELearnTypeGroupID=HAR.Form.getInputValue('ELearnTypeGroupIDList').split(',');
		//use all ELearnTypeGroup if none selected
	if(aELearnTypeGroupID[0].length==0) 
		aELearnTypeGroupID=HAR.Form.getInputValue('ELearnTypeGroupIDList','all').split(',');
	//only get selected project focus groups 
	var	aELearnFocusGroupID=HAR.Form.getInputValue('ELearnFocusGroupIDList').split(',');
	//use all ELearnFocusGroup if none selected
	if(aELearnFocusGroupID[0].length==0) 
		aELearnFocusGroupID=HAR.Form.getInputValue('ELearnFocusGroupIDList','all').split(',');
	//deleted this functionality until v.2.0
	//var	ViewedState=HAR.Form.getInputValue('ViewedState');
	var ViewedState='All';
	//use local var for performance
	var aProject=$eLearn.jsnProject["Records"];
	var jsnThisProject={}, 
		thisELearnTypeGroupID, 
		thisELearnFocusGroupID;
	for(var i=0;i<aProject.length;i++) {
		jsnThisProject=aProject[i];
		thisELearnTypeGroupID=jsnThisProject["ELearnTypeGroupID"];
		thisELearnFocusGroupID=jsnThisProject["ELearnFocusGroupID"];
		var blnViewStateMatch=(ViewedState=='All')
						||( (ViewedState=='NotViewed')&&(jsnThisProject['ViewDate']=='')
						||(ViewedState=='Viewed'&&jsnThisProject["ViewDate"].length>0) ) ;
		var blnELearnTypeGroupMatch=(HAR.Data.inArray(aELearnTypeGroupID, thisELearnTypeGroupID)>=0);
		var blnELearnFocusGroupMatch=(HAR.Data.inArray(aELearnFocusGroupID, thisELearnFocusGroupID)>=0);

		if(blnViewStateMatch&&blnELearnTypeGroupMatch&&blnELearnFocusGroupMatch) {
			$eLearn.ELearnTypeGroup['ELearnTypeGroup_'+thisELearnTypeGroupID]++;
			$eLearn.ELearnFocusGroup['ELearnFocusGroup_'+thisELearnFocusGroupID]++;
			$eLearn.aProjectFiltered.push(jsnThisProject);
			}

		}
		YAHOO.elearning.dsJsonProjects.filterBy(filterGrid); 
		UpdateProjectTypeAndFocusCounts();
		//displayFilteredProjects();
	//====================*/
}

/* all favorites */
function runFavoriteProjectFilter() {
	//refresh listing for grid
	//YAHOO.elearning.dsJsonCurriculum.reload();
	//YAHOO.elearning.dsJsonCurriculum.clearFilter();
	//filter the curriculum grid
	//YAHOO.elearning.dsJsonCurriculum.filter('FavoriteYN','Y');
	//show the grid
	toggleGrid('content-grid-curriculum','show');
	toggleGrid('content-grid','hide');	
	/*clear filtered projects
	$eLearn.aProjectFiltered=[]; 
	var aProject=$eLearn.jsnProject["Records"];
	var jsnThisProject={};
	for(var i=0;i<aProject.length;i++) {
		jsnThisProject=aProject[i];
		if(jsnThisProject["FavoriteYN"]=="Y") {
			$eLearn.aProjectFiltered.push(jsnThisProject);
			}
		} 
	displayFavoriteProjects();
	*/
}

/*==============================================================
 * reset all counts to 0 for:
 * $eLearn.ELearnTypeGroup, $eLearn.ELearnFocusGroup
 * only include project types and focuses displayed on page
 *==============================================================*/
function ProjectTypeAndFocusReset() {
	var aELearnTypeGroupID=HAR.Form.getInputValue('ELearnTypeGroupIDList','all').split(',');
	for(var i in aELearnTypeGroupID){
		if(i.indexOf('function')>0 || typeof($eLearn.ELearnTypeGroup[i])=='function') continue;
		$eLearn.ELearnTypeGroup['ELearnTypeGroup_'+aELearnTypeGroupID[i]]=0;
	}
	var aELearnFocusGroupID=HAR.Form.getInputValue('ELearnFocusGroupIDList','all').split(','); 
	for(var i in aELearnFocusGroupID){
		if(i.indexOf('function')>0 || typeof($eLearn.ELearnFocusGroup[i])=='function') continue;
		$eLearn.ELearnFocusGroup['ELearnFocusGroup_'+aELearnFocusGroupID[i]]=0;
	}
}

/*==============================================================
 * set values (in HTML spans) for Project Type and Project Focus
 * counts based on values in $eLearn.ELearnTypeGroup 
 * and $eLearn.ELearnFocusGroup
 *==============================================================*/
function UpdateProjectTypeAndFocusCounts() {
	for(var i in $eLearn.ELearnTypeGroup) {  
		if(i.indexOf('function')>0 || typeof($eLearn.ELearnTypeGroup[i])=='function') continue;
		document.getElementById(i).innerHTML='('+$eLearn.ELearnTypeGroup[i]+')';
		}
	for(var i in $eLearn.ELearnFocusGroup) {		
		if(i.indexOf('function')>0 || typeof($eLearn.ELearnFocusGroup[i])=='function') continue;
		document.getElementById(i).innerHTML='('+$eLearn.ELearnFocusGroup[i]+')';
		}
}

/*======================================================
 * displays all projects in $eLearn.aProjectFiltered in element Course_List
 //DEPRECATED: 5 Dec 2007
 // using Ext.grid and Ext.data.JsonStore.filterBy(filterGrid)
 *======================================================*/
/*DEPRECATED:
function displayFilteredProjects() {
	var aProj=$eLearn.aProjectFiltered,
		aFinalHTML=[];
	if(aProj.length==0) {
		aFinalHTML.push('<h4>No Courses Available - Search Again</h4>'
						+'<p>There are no courses that fit your selected criteria.</p>'
						+'<p>Please refine your search using the options to the left under BROWSE COURSES.</p>');
	} else {
		aFinalHTML.push('<table id="ProjectTable"><tr>'
						+'<th>Project</th>'
						+'<th>Focus</th>'
						+'<th>Type</th>'
//						+'<th>Date</th>'
						+'<th>Expires</th>'
						+'<th>Curriculum</th>');
//						+'<th>ViewDate</th>');
		for(var i=0;i<aProj.length;i++) {
		aFinalHTML.push('<tr>'
//						+ ' onmouseover="this.class=\'ProjHoverRow\' onmouseout="this.class=\'\'">'
						+'<td>'
						+ '<a href="#" onclick="handle_ProjectLoad('+aProj[i]["ProjectID"]+');return false;">'
						+'['+aProj[i]["ProjectID"]+'] ' //temp for debugging
						+aProj[i]["ProjectName"]
						+ '</a>'
						+'</td>'
						+'<td>'+aProj[i]["ELearnFocusGroup"]+'</td>'
						+'<td>'+aProj[i]["ELearnTypeGroup"]+'</td>'
//						+'<td>'+aProj[i]["DateStart"]+'</td>'
						+'<td>'+aProj[i]["DateEnd"]+'</td>'
						+'<td><a href="#" onclick="handle_ProjectFavorite('+aProj[i]["ProjectID"]+');return false" />'
							+((aProj[i]["FavoriteYN"]=='Y')?'Remove':'Add')
							+'</a></td>');
//						+'<td>'+aProj[i]["ViewDate"]+'</td>');
		}
	aFinalHTML.push('</table>');
	}
	HAR.Dom.getRef('Course_List').innerHTML=aFinalHTML.join('');
	//	ADDED: 24 Oct 2007 MDB
	//	REMOVED: 6 Nov 2007 MDB
	//document.getElementById('ProjectSection').style.display='inline';
}
*/

/*======================================================
 * displays all projects in $eLearn.aProjectFiltered in element Course_List
 *======================================================*/
//DEPRECATED:
function displayFavoriteProjects() {
	var aProj=$eLearn.aProjectFiltered,
		aFinalHTML=[];
	if(aProj.length==0) {
		aFinalHTML.push('<h4>No Curriculum Courses Available - Add Courses Now</h4>'
						+'<p>You have not added any courses to your curriculum.</p>'
						+'<p>Perform a search using the options to the left under BROWSE COURSES and add them now.</p>');
	} else {
		aFinalHTML.push('<table id="ProjectTable"><tr>'
						+'<th>Project</th>'
						+'<th>Focus</th>'
						+'<th>Type</th>'
//						+'<th>Date</th>'
						+'<th>Expires</th>'
						+'<th>Curriculum</th>');
//						+'<th>ViewDate</th>');
		for(var i=0;i<aProj.length;i++) {
		aFinalHTML.push('<tr>'
//						+ ' onmouseover="this.class=\'ProjHoverRow\' onmouseout="this.class=\'\'">'
						+'<td>'
						+ '<a href="#" onclick="handle_ProjectLoad('+aProj[i]["ProjectID"]+');return false;">'
						+'['+aProj[i]["ProjectID"]+'] ' /*temp for debugging */
						+aProj[i]["ProjectName"]
						+ '</a>'
						+'</td>'
						+'<td>'+aProj[i]["ELearnFocusGroup"]+'</td>'
						+'<td>'+aProj[i]["ELearnTypeGroup"]+'</td>'
//						+'<td>'+aProj[i]["DateStart"]+'</td>'
						+'<td>'+aProj[i]["DateEnd"]+'</td>'
						+'<td><a href="#" onclick="handle_ProjectFavorite('+aProj[i]["ProjectID"]+');return false" />'
							+((aProj[i]["FavoriteYN"]=='Y')?'Remove':'Add')
							+'</a></td>');
//						+'<td>'+aProj[i]["ViewDate"]+'</td>');
		}
	aFinalHTML.push('</table>');
	}
	HAR.Dom.getRef('Course_List').innerHTML=aFinalHTML.join('');
}

/*============================================================
 * if all checkboxes are selected, check the "all" checkbox, 
 * otherwise uncheck it for both ELearnFocusGroup and ELearnTypeGroup
 =============================================================*/
 /*DEPRECATED
function ProjectFocusAndTypeAllCheck(){
	var blnProjFocusAll=(HAR.Form.getInputValue('ELearnFocusGroupIDList')==HAR.Form.getInputValue('ELearnFocusGroupIDList','all') 
		|| HAR.Form.getInputValue('ELearnFocusGroupIDList')=='');
	document.getElementById('ELearnFocusGroupAll').checked=blnProjFocusAll;
	var blnProjTypeAll=(HAR.Form.getInputValue('ELearnTypeGroupIDList')==HAR.Form.getInputValue('ELearnTypeGroupIDList','all') 
		|| HAR.Form.getInputValue('ELearnTypeGroupIDList')=='');
	document.getElementById('ELearnTypeGroupAll').checked=blnProjTypeAll;
	}
*/

/*============================================================
 * centralized handler for all activity frame calls
 *============================================================*/
function handle_ActivityFrame(sFrameCode) {
	var ProjectID=HAR.Form.getInputValue('ProjectID');
	/*if(ProjectID!=''&& HAR.Cookie.get("Username")==null) {
		document.getElementById('dialog_login').className='yui-module yui-overlay yui-panel';
		YAHOO.elearning.dialog_login.show();
		return false;
		};
	*/
	/*if no project id, don't do action  */
	switch(sFrameCode) {
		case "Announce":
			contentHeaderImageDisplay('Announce');
			HAR.Dom.iframeLoad('ActivityFrame','announcements.asp');
			document.getElementById('content-footer-options').style.display='none';
			break;
		case "SaveProject":
			if(ProjectID=='') { alert('Please select a project to proceed.\n');return false; }
			/* populate spans and fields! */
			document.getElementById('dialog_add').className='yui-module yui-overlay yui-panel';
			YAHOO.elearning.dialog_add.show();
			break;
		case "PrintProject":
			if(ProjectID=='') { alert('Please select a project to proceed.\n');return false; }
			var iUrl=HAR.Dom.getRef('ActivityFrame').src;
			window.open(iUrl,'iWindow');
			break;
		case "ProjectDownload":
			if(ProjectID=='') { alert('Please select a project to proceed.\n');return false; }
			if(ProjectID!=''&& HAR.Cookie.get("Username")==null) {
				document.getElementById('dialog_login').className='yui-module yui-overlay yui-panel';
				YAHOO.elearning.dialog_login.show();
				return false;
			};
			contentHeaderImageDisplay(HAR.Form.getInputValue('ELearnTypeGroupID'));
			HAR.Dom.iframeLoad('ActivityFrame','assets/'+ProjectID+'/downloads.asp');
			//HAR.Dom.iframeLoad('ActivityFrame', 'frmElearningDownloadList.asp?ProjectID='+ProjectID);
			document.getElementById('content-footer-options').style.display='block';
			break;
		case "ProjectCme":
			if(ProjectID=='') { alert('Please select a project to proceed.\n');return false; }
			contentHeaderImageDisplay(HAR.Form.getInputValue('ELearnTypeGroupID'));
			HAR.Dom.iframeLoad('ActivityFrame','assets/'+ProjectID+'/cme.asp');
			document.getElementById('content-footer-options').style.display='block';
			break;
		case "ProjectFaculty":
			if(ProjectID=='') { alert('Please select a project to proceed.\n');return false; }
			contentHeaderImageDisplay(HAR.Form.getInputValue('ELearnTypeGroupID'));
			HAR.Dom.iframeLoad('ActivityFrame','assets/'+ProjectID+'/faculty.asp');
			//HAR.Dom.iframeLoad('ActivityFrame','frmElearningProjectFaculty.asp?ProjectID='+ProjectID);
			document.getElementById('content-footer-options').style.display='block';
			break;
		case "ProjectEval":
			if(ProjectID=='') { alert('Please select a project to proceed.\n');return false; }
			if(ProjectID!=''&& HAR.Cookie.get("Username")==null) {
				document.getElementById('dialog_login').className='yui-module yui-overlay yui-panel';
				YAHOO.elearning.dialog_login.show();
				return false;
			};
			var EvalProjectUrl=HAR.Form.getInputValue('EvalProjectUrl');
			if(EvalProjectUrl=='') { alert('CME evaluation is not currently available. Please check back soon.');return false; }
			contentHeaderImageDisplay(HAR.Form.getInputValue('ELearnTypeGroupID'));
			//HAR.Dom.iframeLoad('ActivityFrame',EvalProjectUrl);
			HAR.Dom.iframeLoad('ActivityFrame','projectcmeevaluation.asp?ProjectID='+ProjectID);
			document.getElementById('content-footer-options').style.display='block';
			break;
		case "ProjectIndex":
			if(ProjectID=='') { alert('Please select a project to proceed.\n');return false; }
			if(ProjectID!=''&& HAR.Cookie.get("Username")==null) {
				document.getElementById('dialog_login').className='yui-module yui-overlay yui-panel';
				YAHOO.elearning.dialog_login.show();
				return false;
			};
			contentHeaderImageDisplay(HAR.Form.getInputValue('ELearnTypeGroupID'));
			if(HAR.Form.getInputValue('ELearnTypeGroupID')=='5'){HAR.Dom.iframeLoad('ActivityFrame','http://vid.imedex.com/'+ProjectID+'/f_msh.htm');}
			else{HAR.Dom.iframeLoad('ActivityFrame','assets/'+ProjectID+'/index.asp');}
			//HAR.Dom.iframeLoad('ActivityFrame','assets/'+ProjectID+'/index.asp');
			document.getElementById('content-footer-options').style.display='block';
			break;
		case "ProjectCase":
			if(ProjectID=='') { alert('Please select a project to proceed.\n');return false; }
			contentHeaderImageDisplay(HAR.Form.getInputValue('ELearnTypeGroupID'));
			HAR.Dom.iframeLoad('ActivityFrame','assets/'+ProjectID+'/case.asp');
			document.getElementById('content-footer-options').style.display='block';
			break;
		case "ProjectDisc":
			if(ProjectID=='') { alert('Please select a project to proceed.\n');return false; }
			contentHeaderImageDisplay(HAR.Form.getInputValue('ELearnTypeGroupID'));
			HAR.Dom.iframeLoad('ActivityFrame','assets/'+ProjectID+'/discussion.asp');
			document.getElementById('content-footer-options').style.display='block';
			break;
		case "Podcast":
			contentHeaderImageDisplay(HAR.Form.getInputValue('ELearnTypeGroupID'));
			HAR.Dom.iframeLoad('ActivityFrame','podcast.asp');
			document.getElementById('content-footer-options').style.display='block';
			break;
		case "RelatedProjects":
			alert("Related Projects go in iframe or elsewhere?");
			break;
		case "Contact":
			menuTabDisplay("0");
			contentHeaderImageDisplay('Contact');			
			HAR.Dom.iframeLoad('ActivityFrame','contact.asp');
			document.getElementById('content-footer-options').style.display='none';
			break;
		case "Help":
			menuTabDisplay("0");
			contentHeaderImageDisplay('Help');
			HAR.Dom.iframeLoad('ActivityFrame','help.asp');
			document.getElementById('content-footer-options').style.display='none';
			break;
		case "Join":
			menuTabDisplay("0");
			contentHeaderImageDisplay('Join');
			HAR.Dom.iframeLoad('ActivityFrame','join.asp');
			document.getElementById('content-footer-options').style.display='none';
			break;
		case "Account":
			menuTabDisplay("0");
			contentHeaderImageDisplay('Account');
			HAR.Dom.iframeLoad('ActivityFrame','membershipdetails.asp');
			document.getElementById('content-footer-options').style.display='none';
			break;
		default:
			alert('Activity Frame Error:\n"'+sFrameCode+'" not handled.');
			break;
		}
	toggleGrid('content-grid','hide');
	toggleGrid('content-grid-curriculum','hide');
	return false;
}

/*=========================================================*/
/* Load Project information into hidden fields when a 
   Project is selected. */
function handle_ProjectLoad(ProjectID,sFrameCode) {
	if(!ProjectID) ProjectID=HAR.Form.getInputValue('ProjectID');
	if(ProjectID=='') return false;
	//set hidden form values for selected project
	HAR.Form.setInputValue('ProjectID',ProjectID);	
	//TODO: perhaps move activityframe("announce") here. default of no project
	/* TODO: hide the project list before displaying the login dialog
		COMPLETED: 6 November 2007 MDB */
	toggleGrid('content-grid','hide');
	/*if(HAR.Cookie.get("Username")==null) {
		document.getElementById('dialog_login').className='yui-module yui-overlay yui-panel';
		YAHOO.elearning.dialog_login.show();
		return false;
	}*/
	//TODO: once logged in, continue to projectID
	//get project data from json record
	var ijsnProjIndex=getjsnProjectIndex(ProjectID);
	var jsnThisProject=$eLearn.jsnProject["Records"][ijsnProjIndex];/*shortcut*/
	//set the values for the project
	HAR.Form.setInputValue('ELearnTypeGroupID', jsnThisProject["ELearnTypeGroupID"]);
	HAR.Form.setInputValue('ELearnFocusGroupID', jsnThisProject["ELearnFocusGroupID"]);
	HAR.Form.setInputValue('ProjectName', jsnThisProject["ProjectName"]);
	HAR.Form.setInputValue('DateStart', jsnThisProject["DateStart"]);
	HAR.Form.setInputValue('DateEnd', jsnThisProject["DateEnd"]);
	HAR.Form.setInputValue('EvalProjectUrl', jsnThisProject["EvalProjectUrl"]);
	HAR.Form.setInputValue('EmailDiscDate', jsnThisProject["EmailDiscDate"]);
	//set values for all dialogs
	HAR.Form.setInputValue('frmLoginProjectID', ProjectID);
	HAR.Form.setInputValue('frmEmailProjectID',ProjectID);
	HAR.Form.setInputValue('frmEmailProjectName', jsnThisProject["ProjectName"]);
	HAR.Form.setInputValue('frmEmailProjectType', jsnThisProject["ELearnTypeGroup"]);
	HAR.Form.setInputValue('frmEmailProjectExpire', jsnThisProject["DateEnd"]);

	//load activity frame for project
	if(!sFrameCode || sFrameCode=='') {handle_ActivityFrame("ProjectCme");}	
	else {handle_ActivityFrame("ProjectIndex");}
	//display appropriate menu options
	menuTabDisplay(jsnThisProject["ELearnTypeGroupID"]);
	/*	TODO: set the content-header-title img src based on ElearnTypeGroupID
		COMPLETED: 23 Oct 2007 MDB */
	contentHeaderImageDisplay(jsnThisProject["ELearnTypeGroupID"]);
	/*	TODO: show the content-footer-options section
		COMPLETED: 23 Oct 2007 MDB */
	document.getElementById('content-footer-options').style.display='block';
	//if user logged in, mark project as viewed in local recordset and record view in database 
	if(HAR.Cookie.get('Login')=='True'){//&&jsnThisProject["ViewDate"]=="") {
		$eLearn.jsnProject["Records"][ijsnProjIndex]["ViewDate"]=HAR.Data.today();
		//displayFilteredProjects();
		var sUrl='/appjson/jsnELearningProjectView.asp?ProjectID='+ProjectID+'&AppUser_pmProjectView_Action=Create';
		var ajaxViewed=YAHOO.util.Connect.asyncRequest('POST',sUrl,
			{ success: function(o) {sUrl='';},
			  failure: function(o) { alert('Error\nCould not save view date.');}
			});
	}
	toggleGrid('content-grid','hide');
}
	

/*=============================================================*/
/* returns JSON record for individual project */
function getjsnProjectIndex(ProjectID) {
	for(var i=0;i<$eLearn.jsnProject["Records"].length;i++) 
		if($eLearn.jsnProject["Records"][i]["ProjectID"]==ProjectID)
			return(i)
	return null
	}
	
	
/*=============================================================*/
/* show and process dialog for project favorites
UPDATED: 26 Nov 2007 MDB */
function handle_ProjectFavorite(ProjectID) {
	/* if not logged in, display login form */
	if(HAR.Cookie.get("Username")==null) {
		document.getElementById('dialog_login').className='yui-module yui-overlay yui-panel';
		YAHOO.elearning.dialog_login.show();
		return false;
	}
	/*if project id not passed, use current project id*/
	if(!ProjectID) ProjectID=HAR.Form.getFieldValue('ProjectID');
	if(!ProjectID) { alert('Application Error:\nCannot save a favorite without a project selected.');return false;}
	//show favorite section
	//populate project info into favorite section
	var ijsnProjIndex=getjsnProjectIndex(ProjectID);
	var jsnProject=$eLearn.jsnProject["Records"][ijsnProjIndex];/*shortcut*/
	HAR.Form.setInputValue('dialog_add_projectid', jsnProject["ProjectID"]);
	HAR.Form.setInputValue('dialog_add_projectname',jsnProject["ProjectName"]);
	//HAR.Form.setInputValue('dialog_add_rating', 10);
	HAR.Form.setInputValue('dialog_add_dateview', jsnProject["ViewDate"]);
	HAR.Form.setInputValue('dialog_add_datestart', jsnProject["DateStart"]);
	HAR.Form.setInputValue('dialog_add_dateend', jsnProject["DateEnd"]);
	document.getElementById('dialog_add_info').innerHTML='<h5>'+jsnProject["ProjectName"]+'</h5><i>'+jsnProject["ELearnFocusGroup"]+'&nbsp;'+jsnProject["ELearnTypeGroup"]+'</i><br />Expires on '+jsnProject["DateEnd"];
	document.getElementById('dialog_add').className='yui-module yui-overlay yui-panel';
	YAHOO.elearning.dialog_add.show();
	/*document.getElementById('dialog_add_datestart').innerHTML=jsnProject["DateStart"];
	document.getElementById('dialog_add_projectname').innerHTML=jsnProject["ProjectName"];
	var Rating=jsnProject["Rating"]+'';if(Rating=='') Rating='10';*/
}

/*============================================================*/
/* show and process dialog for emailing project 
	DEPRECATED: 7 Nov 2007 MDB */
/*function handle_EmailProject() {
	var ProjectID=HAR.Form.getInputValue('ProjectID'),
		ProjectName=HAR.Form.getInputValue('ProjectName');
	HAR.Form.ClearFields('EmailFav$To,EmailFav$Body');
	document.getElementById('frmEmailProjectID').value=ProjectID;
	document.getElementById('frmEmailProjectName').value=ProjectName;
	document.getElementById('frmEmailFrom').value=HAR.Cookie.get('email');
		$eLearn.dialog_email.show();
	//display email div form in center of screen
	//hijack form to json email processor
	}*/


/*============================================*/
/* setup Project Email dialog */
function dialog_email_setup() {
	// Define various event handlers for Dialog
	var handleSubmit = function() {
		//HAR.Form.setInputValue('frmEmailFrom',HAR.Cookie.get('Email'));
		this.submit();
	};
	var handleCancel = function() {
		document.getElementById('frmEmail').reset();
		document.getElementById('dialog_email').className='x-hide-offsets';
		this.cancel();
	};
	var handleSuccess = function(o) {
		document.getElementById('frmEmail').reset();
		document.getElementById('dialog_email').className='x-hide-offsets';
		var response = o.responseText;
		response = response.split("<!")[0];
		jsnResponse=eval(response);
		alert(jsnResponse["EmailStatusMessage"]);
	};
	var handleFailure = function(o) {
		document.getElementById('dialog_email').className='x-hide-offsets';
		var response = o.responseText;
		response = response.split("<!")[0];
		jsnResponse=eval(response);
		alert("Application error: "+jsnResponse["EmailStatusMessage"]);
	};

	// Instantiate the Dialog
	YAHOO.elearning.dialog_email = new YAHOO.widget.Dialog("dialog_email", 
								{ xy:[-360,-360],
								  width:"360px",
								  iframe:true,
								  close:false,
								  fixedcenter:true,
								  visible:false, 
								  constraintoviewport:true,
								  modal:true,
								  zIndex:6001,
								  buttons:[{text:"Send Email",handler:handleSubmit,isDefault:true},
											  {text:"Cancel",handler:handleCancel}]
								 });
	
	/*	TODO: validate the email against a regular expression
		COMPLETED: 6 Nov 2007 MDB */
	YAHOO.elearning.dialog_email.validate = function() {
		var data = this.getData();
		var strMessage = "More information is required:\n\n";
		var errors = false;
		if(data.frmEmailFrom == "" || data.frmEmailTo == "") {
			strMessage = strMessage + "~ enter your email and the recipient email\n";
			document.getElementById('frmEmailTo').select();
			errors = true;
		} else {
			if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(data.frmEmailTo)) {
				strMessage = strMessage + "~ enter a valid recipient email address\n";
				document.getElementById('frmEmailTo').select();
				errors = true;
			}
		}
		
		if(errors) {
			alert(strMessage);
			return false;
		}
		//reset variables and exit
		strMessage = "";
		return true;
	};

	// Wire up the success and failure handlers
	$eLearn.dialog_email.callback = { 
			success: handleSuccess,
		 failure: handleFailure };	
	// Render the Dialog
	$eLearn.dialog_email.render();
	document.getElementById('dialog_email').className='x-hide-offsets';
	if (YAHOO.env.ua.gecko) {
        /* 
         * Other part of workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=167801 !!?
         * I have no explanation for why the new thread (setTimeout) is needed, but it is.
         */
        YAHOO.util.Dom.addClass(YAHOO.elearning.dialog_email.form, "caretfix");

        YAHOO.elearning.dialog_email.showEvent.subscribe(function() {
            YAHOO.util.Dom.setStyle(YAHOO.elearning.dialog_email.form, "display", "none");

            var fixDisplay = function() {
                YAHOO.util.Dom.setStyle(YAHOO.elearning.dialog_email.form, "display", "block");
                try {
                    YAHOO.elearning.dialog_email.firstFormElement.focus();
                } catch (e) {
                    // Not related to the workaround, I just try/catch focus calls
                    // do avoid testing for the various conditions in which they could
                    // fail.
                }
            }
            setTimeout(fixDisplay, 0);
		});
	}
	YAHOO.util.Event.addListener("dialog-email-show","click",toggleDialog,YAHOO.elearning.dialog_email);
}

/*============================================*/
/* setup Reminder Email dialog */
function dialog_remind_setup() {
	// Define various event handlers for Dialog
	var handleSubmit = function() {
		//HAR.Form.setInputValue('frmEmailFrom',HAR.Cookie.get('Email'));
		this.submit();
	};
	var handleCancel = function() {
		document.getElementById('frmRemind').reset();
		document.getElementById('dialog_remind').className='x-hide-offsets';
		this.cancel();
	};
	var handleSuccess = function(o) {
		//TODO: move dialog offscreen
		document.getElementById('dialog_remind').className='x-hide-offsets';
		document.getElementById('frmRemind').reset();
		var response = o.responseText;
		response = response.split("<!")[0];
		jsnResponse=eval(response);
		alert(jsnResponse["EmailStatusMessage"]);		
	};
	var handleFailure = function(o) {
		//TODO: move dialog offscreen
		document.getElementById('dialog_remind').className='x-hide-offsets';
		var response = o.responseText;
		response = response.split("<!")[0];
		jsnResponse=eval(response);
		alert("Application error: "+jsnResponse["EmailStatusMessage"]);
	};

	// Instantiate the Dialog
	YAHOO.elearning.dialog_remind = new YAHOO.widget.Dialog("dialog_remind", 
								{ xy:[-360,-360],
								  width:"360px",
								  iframe:true,
								  close:false,
								  fixedcenter:true,
								  visible:false, 
								  constraintoviewport:true,
								  modal:true,
								  zIndex:6001,
								  buttons:[{text:"Send Reminder",handler:handleSubmit,isDefault:true},
											  {text:"Cancel",handler:handleCancel}]
								 });
	
	/*	TODO: validate the email against a regular expression
		COMPLETED: 6 Nov 2007 MDB */
	YAHOO.elearning.dialog_remind.validate = function() {
		var data = this.getData();
		var strMessage = "More information is required:\n\n";
		var errors = false;
		if(data.email_frmRemind == "") {
			strMessage = strMessage + "~ enter your member email address\n";
			document.getElementById('email_frmRemind').select();
			errors = true;
		} else {
			if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(data.email_frmRemind)) {
				strMessage = strMessage + "~ enter a valid email address\n";
				document.getElementById('email_frmRemind').select();
				errors = true;
			}
		}
		
		if(errors) {
			alert(strMessage);
			return false;
		}
		//reset variables and exit
		strMessage = "";
		return true;
	};

	// Wire up the success and failure handlers
	$eLearn.dialog_remind.callback = { 
			success: handleSuccess,
		 failure: handleFailure };	
	// Render the Dialog
	$eLearn.dialog_remind.render();
	document.getElementById('dialog_remind').className='x-hide-offsets';
	if (YAHOO.env.ua.gecko) {
        /* 
         * Other part of workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=167801 !!?
         * I have no explanation for why the new thread (setTimeout) is needed, but it is.
         */
        YAHOO.util.Dom.addClass(YAHOO.elearning.dialog_remind.form, "caretfix");

        YAHOO.elearning.dialog_remind.showEvent.subscribe(function() {
            YAHOO.util.Dom.setStyle(YAHOO.elearning.dialog_remind.form, "display", "none");

            var fixDisplay = function() {
                YAHOO.util.Dom.setStyle(YAHOO.elearning.dialog_remind.form, "display", "block");
                try {
                    YAHOO.elearning.dialog_remind.firstFormElement.focus();
                } catch (e) {
                    // Not related to the workaround, I just try/catch focus calls
                    // do avoid testing for the various conditions in which they could
                    // fail.
                }
            }
            setTimeout(fixDisplay, 0);
		});
	}
	YAHOO.util.Event.addListener("dialog-remind-show","click",toggleDialog,YAHOO.elearning.dialog_remind);
}
											 
/*============================================*/
/* setup Project Favorite Dialog */
function dialog_add_setup() {
	// Define various event handlers for Dialog
	var handleSubmit = function() {
		this.submit();
		};
	var handleCancel = function() {
		HAR.Form.ClearFields('dialog_add_projectid,dialog_add_dateview');
		document.getElementById('dialog_add').className='x-hide-offsets';
		this.cancel();
		};
	var handleSuccess = function(o) {
		//TODO:move dialog offscreen
		document.getElementById('dialog_add').className='x-hide-offsets';
		//reload the curriculum ds to grab the latest addition
		YAHOO.elearning.dsJsonCurriculum.reload();
		var response = o.responseText.split("<!")[0];
		jsnResponse=eval(response);
		alert("Course added to My Curriculum");
		/* set jsn values */
		var ijsnProjIndex=getjsnProjectIndex(HAR.Form.getFieldValue('dialog_add_projectid'));
		$eLearn.jsnProject["Records"][ijsnProjIndex]["ViewDate"]=jsnResponse["ViewDate"];
		$eLearn.jsnProject["Records"][ijsnProjIndex]["Rating"]=jsnResponse["Rating"];
		$eLearn.jsnProject["Records"][ijsnProjIndex]["FavoriteYN"]=isNaN(parseInt(jsnResponse["Rating"],10))?"N":"Y";
		//displayFilteredProjects();
		/*reset form*/
		HAR.Form.ClearFields('dialog_add_projectid,dialog_add_dateview');		
		};
	var handleFailure = function(o) {
		//TODO:move dialog offscreen
		document.getElementById('dialog_add').className='x-hide-offsets';
		HAR.Form.ClearFields('dialog_add_projectid,dialog_add_dateview');
		alert("Saving favorite failed: " + o.status);
		};

	// Instantiate the Dialog
	$eLearn.dialog_add = new YAHOO.widget.Dialog("dialog_add", 
								{ xy:[-360,0],
								  width:"360px",
								  iframe:true,
								  close:false,
								  fixedcenter:true,
								  visible:false, 
								  constraintoviewport:true,
								  modal:true,
								  zIndex:6001,
								  buttons:[{text:"Add Course",handler:handleSubmit,isDefault:true},
											  {text:"Cancel",handler:handleCancel}]
								 } );
	
	// TODO: Validate the entries in the form 
	/*$eLearn.dialog_add.validate = function() {
	//	var data = this.getData();
	//	if (data.ProjectFav$From == "" || data.ProjectFav$To == "" || data.ProjectFav$Subject=='' ) {
	//		alert("Please enter from to and subject.");
	//		return false;
	//	} else {
	//		return true;
	//	}
	};*/

	// Wire up the success and failure handlers
	$eLearn.dialog_add.callback = {success:handleSuccess,failure: handleFailure};
	
	// Render the Dialog
	$eLearn.dialog_add.render();
	document.getElementById('dialog_add').className='x-hide-offsets';
	if (YAHOO.env.ua.gecko) {
        /* 
         * Other part of workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=167801 !!?
         * I have no explanation for why the new thread (setTimeout) is needed, but it is.
         */
        YAHOO.util.Dom.addClass(YAHOO.elearning.dialog_add.form, "caretfix");

        YAHOO.elearning.dialog_add.showEvent.subscribe(function() {
            YAHOO.util.Dom.setStyle(YAHOO.elearning.dialog_add.form, "display", "none");

            var fixDisplay = function() {
                YAHOO.util.Dom.setStyle(YAHOO.elearning.dialog_add.form, "display", "block");
                try {
                    YAHOO.elearning.dialog_add.firstFormElement.focus();
                } catch (e) {
                    // Not related to the workaround, I just try/catch focus calls
                    // do avoid testing for the various conditions in which they could
                    // fail.
                }
            }
            setTimeout(fixDisplay, 0);
		});
	}

	YAHOO.util.Event.addListener("dialog-add-show","click",toggleDialog,YAHOO.elearning.dialog_add);
}


/*============================================*/
/* for debugging only, delete
DEPRECATED: 24 Oct 2007 MDB 
function prn(s) {document.getElementById('logdiv_tmp').innerHTML+='<br />'+s}
function prncls() {document.getElementById('logdiv_tmp').innerHTML=''}

/*=============================================================*/

/* creation and validation of the login dialog
	UPDATED: 5 Nov 2007 MDB */
function dialog_login_setup() {
	// Define various event handlers for Dialog
	var handleSubmit = function() {
		this.submit();
	};
	var handleCancel = function() {
		document.getElementById('frmLogin').reset();
		//clear the projectid field
		//document.getElementById('ProjectID').value='';		
		document.getElementById('dialog_login').className='x-hide-offsets';
		this.cancel();
	};
	var handleFailure = function(o) {
		alert("Application error: " + o.status);
		ELearn$logout();
	};
	var handleSuccess = function(o) {
		document.getElementById('frmLogin').reset();
		var response = o.responseText;
		response = response.split("<!")[0];
		/*document.getElementById("resp").innerHTML = response;*/
		var jsnResponse = eval(response);
		if (HAR.Cookie.get("Login") == "True") {
			document.getElementById('dialog_login').className = 'x-hide-offsets';
			//reset project info for additional user info to populate
			//TODO: load dsJsonCurriculum
			UserBarDisplay();
			handle_ProjectLoad();
		}
		else {
			alert(jsnResponse["LoginMessage"]);
			/////+"\n\nCheck the email and password for accuracy.\n"
			///////addded
			document.getElementById('dialog_login').className = 'yui-module yui-overlay yui-panel';
			YAHOO.elearning.dialog_login.show();
		}
	};

	// Instantiate the Dialog
	YAHOO.elearning.dialog_login = new YAHOO.widget.Dialog("dialog_login", 
				{ xy:[-300,0],
				  width:"300px",
				  iframe:true,
				  close:false,
				  fixedcenter:true,
				  visible:false, 
				  constraintoviewport:true,
				  modal:true,
				  zIndex:6001,
				  buttons:[{text:"Submit",handler:handleSubmit,isDefault:true},
							  {text:"Cancel",handler:handleCancel}]
				 });
	
	//TODO: validation of email format DONE
	//TODO: validation of password min format (length, 1 capital alpha, 1 num) DONE
	YAHOO.elearning.dialog_login.validate = function() {
		var data = this.getData();
		var strMessage = "More information is required:\n\n";
		var errors = false;
		if(data.email == "" || data.password == "") {
			strMessage = strMessage + "~ enter your email and password\n";
			document.getElementById('email').select();
			errors = true;
		} else {
			if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(data.email)) {
				strMessage = strMessage + "~ enter a valid email address\n";
				document.getElementById('email').select();
				errors = true;
			}
			if(data.password.length < 6 || !/\d+/.test(data.password) || !/[A-Z]+/.test(data.password)) {
				strMessage = strMessage + "~ enter a properly formatted password\n";
				document.getElementById('password').select();
				errors = true;
			}
		}
		
		if(errors) {
			alert(strMessage);
			return false;
		}
		//reset variables and exit
		strMessage = "";
		return true;
	};
	YAHOO.elearning.dialog_login.callback = { success: handleSuccess,
												 failure: handleFailure };
	YAHOO.elearning.dialog_login.render();
	//TODO: hide offscreen using offset
	document.getElementById('dialog_login').className='x-hide-offsets';
	if (YAHOO.env.ua.gecko) {
        /* 
         * Other part of workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=167801 !!?
         * I have no explanation for why the new thread (setTimeout) is needed, but it is.
         */
        YAHOO.util.Dom.addClass(YAHOO.elearning.dialog_login.form, "caretfix");

        YAHOO.elearning.dialog_login.showEvent.subscribe(function() {
            YAHOO.util.Dom.setStyle(YAHOO.elearning.dialog_login.form, "display", "none");

            var fixDisplay = function() {
                YAHOO.util.Dom.setStyle(YAHOO.elearning.dialog_login.form, "display", "block");
                try {
                    YAHOO.elearning.dialog_login.firstFormElement.focus();
                } catch (e) {
                    // Not related to the workaround, I just try/catch focus calls
                    // do avoid testing for the various conditions in which they could
                    // fail.
                }
            }
            setTimeout(fixDisplay, 0);
        });
    }
    YAHOO.util.Event.addListener("show","click",toggleDialog,YAHOO.elearning.dialog_login);
	YAHOO.util.Event.addListener("show-join","click",toggleDialog,YAHOO.elearning.dialog_login);
}

/* CREATED: 5 Dec 2007 MDB */
function toggleDialog(){
	switch(this.id) {
		case 'show':		
			document.getElementById('dialog_login').className='yui-module yui-overlay yui-panel';
			YAHOO.elearning.dialog_login.show();
			break;
		case 'dialog-add-show':
			document.getElementById('dialog_add').className='yui-module yui-overlay yui-panel';
			YAHOO.elearning.dialog_add.show();
			break;
		case 'dialog-email-show':
			document.getElementById('dialog_email').className='yui-module yui-overlay yui-panel';
			YAHOO.elearning.dialog_email.show();
			break;
		case 'dialog-remind-show':
		    document.getElementById('frmLogin').reset();
		    YAHOO.elearning.dialog_login.cancel();
		    document.getElementById('dialog_login').className='x-hide-offsets';
		    document.getElementById('dialog_remind').className='yui-module yui-overlay yui-panel';
			YAHOO.elearning.dialog_remind.show();
			break;
		case 'show-join':
		    document.getElementById('frmLogin').reset();
		    YAHOO.elearning.dialog_login.cancel();
		    document.getElementById('dialog_login').className='x-hide-offsets';
		    document.getElementById('ProjectID').value='';
		    handle_ActivityFrame("Join");
		    break;
	}
	return null;
}

/*	called to logout user with frmLogin submission
	UPDATED: 5 Nov 2007 MDB */
function ELearn$logout() { 
	var url="/appjson/jsnLogin.asp";
	YAHOO.util.Connect.setForm(document.getElementById('frmLogin'));
	var jsnParams={
		success: function(o) {
			resetAppEvent();
			/*	TODO: hide the content-footer-options section
				COMPLETED: 23 Oct 2007 MDB */
			document.getElementById('content-footer-options').style.display='none';
			/*	TODO: reset menuTabDisplay
				COMPLETED: 6 Nov 2007 MDB */
			menuTabDisplay("0");
			/*	TODO: unload project and reset iframe
				COMPLETED: 6 Nov 2007 MDB */
			HAR.Form.setInputValue('ProjectID','');
			handle_ActivityFrame("Announce");
			clearCourseList();
			UserBarDisplay();
			},
		failure: function(o) { 
			alert('Error:\nCould not log out user.');
			}
		};
	var ajaxLogin=YAHOO.util.Connect.asyncRequest('POST',url,jsnParams);
}

/* for determining which tabs display
	UPDATED: 29 Apr 2009 MDB
	UPDATED: 29 Sep 2009 MDB */
function menuTabDisplay(ELearnTypeGroupID) {
	var jsnMenu= {
		0: {show: [], hide: ['content-nav-case','content-nav-disc','content-nav-index','content-nav-cme','content-nav-faculty','content-nav-download','content-nav-eval','content-nav-podcast']},
		1: {show: ['content-nav-index','content-nav-cme','content-nav-faculty','content-nav-eval','content-nav-podcast'], hide: ['content-nav-download','content-nav-case','content-nav-disc']},
		2: {show: ['content-nav-index','content-nav-cme','content-nav-faculty','content-nav-download','content-nav-eval','content-nav-podcast'], hide: ['content-nav-case','content-nav-disc']},
		3: {show: ['content-nav-index','content-nav-cme','content-nav-faculty','content-nav-eval'], hide: ['content-nav-case','content-nav-disc','content-nav-download','content-nav-podcast']},
		4: {show: ['content-nav-index','content-nav-cme','content-nav-faculty','content-nav-download','content-nav-eval','content-nav-podcast'], hide: ['content-nav-case','content-nav-disc']},
		5: {show: ['content-nav-index','content-nav-cme','content-nav-faculty','content-nav-download','content-nav-eval','content-nav-podcast'], hide: ['content-nav-case','content-nav-disc']},
		6: {show: ['content-nav-index','content-nav-cme','content-nav-eval','content-nav-podcast'], hide: ['content-nav-faculty','content-nav-download','content-nav-case','content-nav-disc']},
		7: {show: ['content-nav-cme','content-nav-eval','content-nav-podcast','content-nav-download'], hide: ['content-nav-index','content-nav-faculty','content-nav-case','content-nav-disc']},
		8: {show: ['content-nav-index','content-nav-cme','content-nav-faculty','content-nav-download','content-nav-eval','content-nav-podcast'], hide: ['content-nav-case','content-nav-disc']},
		9: {show: ['content-nav-index','content-nav-cme','content-nav-faculty','content-nav-eval','content-nav-podcast'], hide: ['content-nav-download','content-nav-case','content-nav-disc']}
	}
	if(jsnMenu[ELearnTypeGroupID])
		ShowHideJSN(jsnMenu[ELearnTypeGroupID]);
	/*	TODO: call the function to set content-header-title attributes
	COMPLETED: 23 Oct 2007 MDB */
	contentHeaderImageDisplay(ELearnTypeGroupID);
}

/*	Purpose: determine img and attributes {title,alt, and src} for the content-header-title div
	ADDED: 23 Oct 2007 MDB
	UPDATED: 6 Nov 2007 MDB
	UPDATED: 29 Sep 2009 MDB */
function contentHeaderImageDisplay (sElearnContent) {
	switch (sElearnContent) {
		//cases 1-9 are based on ELearnTypeGroupID
		case "1":
			document.getElementById("content-header-image").alt="Best of the Day";
			document.getElementById("content-header-image").title="Best of the Day";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/best-of-the-day.png";
			break;
		case "2":
			document.getElementById("content-header-image").alt="Clinical Case Review";
			document.getElementById("content-header-image").title="Clinical Case Review";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/clinical-case-review.png";
			break;
		case "3":
			document.getElementById("content-header-image").alt="Email Case";
			document.getElementById("content-header-image").title="Email Case";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/email-case.png";
			break;
		case "4":
			document.getElementById("content-header-image").alt="Monograph";
			document.getElementById("content-header-image").title="Monograph";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/monograph.png";
			break;
		case "5":
			document.getElementById("content-header-image").alt="New Frontiers";
			document.getElementById("content-header-image").title="New Frontiers";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/new-frontiers.png";
			break;
		case "6":
			document.getElementById("content-header-image").alt="Webcast";
			document.getElementById("content-header-image").title="Webcast";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/webcast.png";
			break;
		case "7":
			document.getElementById("content-header-image").alt="Podcast";
			document.getElementById("content-header-image").title="Podcast";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/podcast.png";
			break;
		case "8":
			document.getElementById("content-header-image").alt="Journal Supplement";
			document.getElementById("content-header-image").title="Journal Supplement";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/journal-supplement.png";
			break;
		case "9":
			document.getElementById("content-header-image").alt="DocTalk";
			document.getElementById("content-header-image").title="DocTalk";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/doctalk.png";
			break;
		// remaining cases are for page loads not based on ELearnTypeGroupID from handle_ActvityFrame()
		case "0":
		case "Announce":
			document.getElementById("content-header-image").alt="ELC Home Announcements";
			document.getElementById("content-header-image").title="ELC Home Announcements";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/elc-home.png";
			break;
		case "Account":
			document.getElementById("content-header-image").alt="Membership Details";
			document.getElementById("content-header-image").title="Membership Details";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/membership-details.png";
			break;
		case "Help":
			document.getElementById("content-header-image").alt="Help Information";
			document.getElementById("content-header-image").title="Help Information";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/help.png";
			break;
		case "Contact":
			document.getElementById("content-header-image").alt="Contact Us";
			document.getElementById("content-header-image").title="Contact Us";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/contact.png";
			break;
		case "Join":
			document.getElementById("content-header-image").alt="Join the ELC";
			document.getElementById("content-header-image").title="Join the ELC";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/join.png";
			break;
		default:
			document.getElementById("content-header-image").alt="ELC Home Announcements";
			document.getElementById("content-header-image").title="ELC Home Announcements";
			document.getElementById("content-header-image").src="/appresources/images/elearn/content-header-image/elc-home.png";
			alert("Image type not handled\n"+sElearnContent);
			break;
	}
}
 	
//displays all elements in show array, hides all in hide array
function ShowHideJSN( jsn ) {
	var aShow=jsn['show'], aHide=jsn['hide'];
	for(var i in aShow) {
		if(i.indexOf('function')>0 || typeof($eLearn.ELearnTypeGroup[i])=='function') continue;
		document.getElementById(aShow[i]).style.display='block';
	}
	for(var i in aHide) {
		if(i.indexOf('function')>0 || typeof($eLearn.ELearnTypeGroup[i])=='function') continue;
		document.getElementById(aHide[i]).style.display='none';
	}
}

/* displays login/logout/username info
	UPDATED: 5 Nov 2007 MDB */
function UserBarDisplay() {
	if(HAR.Cookie.get("Login")=="True") {
		document.getElementById('LoginAction').value='logout';
		document.getElementById('login-info-loggedin').style.display='block';		
		document.getElementById('login-info-loggedout').style.display='none';		
		document.getElementById('login-info-username').value=HAR.Cookie.get("Username");
		document.getElementById('login-info-email').value=HAR.Cookie.get("Email");		
		//reload data for curriculum based on username
		YAHOO.elearning.dsJsonCurriculum.reload();
	}
	else {
		document.getElementById('LoginAction').value='login';
		document.getElementById('login-info-loggedin').style.display='none';
		document.getElementById('login-info-loggedout').style.display='block';		
		document.getElementById('login-info-username').value='';
		document.getElementById('login-info-email').value='';
	}
}

//TODO: Add an image downloader to cache all images when loading the interface
//Should be masked behind the loading-mask

/*function login-menu-setup () {
	YAHOO.example.container.login-menu = new YAHOO.widget.Overlay("login-info-menu",{context:["login-info-loggedin","bl","bl"],visible:false,width:"200px"});
		
	YAHOO.util.Event.addListener("login-info-loggedin", "click", YAHOO.example.container.login-menu.show, YAHOO.example.container.login-menu, true);
	//YAHOO.util.Event.addListener("login-info", "click", YAHOO.example.container.login-menu.hide, YAHOO.example.container.overlay3, true);
}*/

/* Added 29 Oct 2007 MDB
Function to display the element holding the filtered course list*/
function toggleGrid (sObj,sState) {
	if(sState=='show'){
		//HACK: if project is loaded and it is video, change to Activity Index page
		var ProjectID=HAR.Form.getInputValue('ProjectID');
		var ELearnTypeGroupID=HAR.Form.getInputValue('ELearnTypeGroupID')
		if (ProjectID!='' && (ELearnTypeGroupID=='1' || ELearnTypeGroupID=='2' || ELearnTypeGroupID=='5' || ELearnTypeGroupID=='6' || ELearnTypeGroupID=='9')) {
		    handle_ActivityFrame("ProjectCme");
		}
		document.getElementById(sObj).className='';
		//document.getElementById('content-grid').style.display='inline';
	} else{
		document.getElementById(sObj).className='x-hide-offsets';
		//document.getElementById('content-grid').style.display='none';
	}
	return null;
}

/* Added 29 Oct 2007 MDB
Function to clear the checkboxes and hide the list*/
function clearCourseList () {
	/* HACK: implemented to clear all checkboxes on page
	5 December 2007 */
	var a=document.getElementById('frmSearch')
	for(var i=0;i<a.length;i++){
		if(a[i].getAttribute('type')=='checkbox')
		a[i].checked=false;
	}
	toggleGrid('content-grid','hide');
	toggleGrid('content-grid-curriculum','hide');
	//YAHOO.elearning.dsJsonProjects.clearFilter();
	runProjectFilter();
	
	/*replaced with HACK above
	var aELearnFocusGroupID=HAR.Form.getInputValue('ELearnFocusGroupIDList','all').split(',');
	var aELearnTypeGroupID=HAR.Form.getInputValue('ELearnTypeGroupIDList','all').split(',');
	for(var i in aELearnFocusGroupID) {
		if(i.indexOf('function')>0) continue;
		document.getElementById('frmSearch').ELearnFocusGroupIDList[i].checked=false;
	}
	for(var j in aELearnTypeGroupID) {
		if(j.indexOf('function')>0) continue;
		document.getElementById('frmSearch').ELearnTypeGroupIDList[j].checked=false;
	}
	*/
}

//EXT scripting
function initProjectsObjects() {
    YAHOO.elearning.expanderProjects = new Ext.grid.RowExpander({
		        tpl:new Ext.Template('<p><br /><b>Summary:</b> {ProjectDescription}</p>')
    });	    
   
    YAHOO.elearning.dsJsonProjects = new Ext.data.JsonStore({
		autoLoad:true,			
		url:'/appjson/jsnELearningProjects.asp',
		root:'Records',
		fields:[{name:'ProjectID'},
        {name:'ProjectName'},
        {name:'ELearnTypeGroupID'},
        {name:'ELearnTypeGroup'},
        {name:'ELearnFocusGroupID'},
        {name:'ELearnFocusGroup'},
        {name:'DateStart', type:'date'},
        {name:'DateEnd', type:'date'},
        {name:'ProjectDescription'},
        {name:'EvalProjectUrl'}],
		sortInfo:{field:'DateEnd', direction:'DESC'}
	});
		
	YAHOO.elearning.gridProjects = new Ext.grid.GridPanel({
        store:YAHOO.elearning.dsJsonProjects,
        cm:new Ext.grid.ColumnModel([
			YAHOO.elearning.expanderProjects,
	        {header:'Name', width:350, sortable:true, renderer:renderProjectLink, dataIndex:'ProjectName'},
	        {header:'Disease', width:100, sortable:true, dataIndex:'ELearnFocusGroup'},
	        {header:'Product', width:120, sortable:true, dataIndex:'ELearnTypeGroup'},
	        {header:'Expires', width:70, sortable:true, renderer:Ext.util.Format.dateRenderer('m/d/Y'), dataIndex:'DateEnd'}
        ]),
        viewConfig:{forceFit:true,
	        enableRowBody:true,
	        emptyText:'<h4>No Courses Available - Search Again</h4>'
					+'<p>There are no courses that fit your selected criteria.<br />'
					+'Please refine your search using the options to the left under BROWSE COURSES.</p>'
        },
        loadMask:true,
        trackMouseOver:false,
        sm:new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn}),
        width:740,
		height:510,
		frame:true,
        autoRowHeight:true,
        autoScroll:true,
        stripeRows:true,
        plugins:YAHOO.elearning.expanderProjects,
        //TODO: show the totalRecords in the title 'Available Courses (totalRecords)'
        //OR implement something similar to the footer of the paging grid example
        title:'Available Courses',
		tools:[{
			id:'close',
			qtip:'Hide',
			handler: function(e, target, panel){
				toggleGrid('content-grid','hide');
			}
		}],
        iconCls:'icon-grid',
		renderTo:'content-grid'
    });
    
    
	return;
}//end initProjectsObjects();

function initCurriculumObjects(){
	YAHOO.elearning.expanderCurriculum = new Ext.grid.RowExpander({
		        tpl:new Ext.Template('<p><br /><b>Summary:</b> {ProjectDescription}</p>')
    });	
    
	YAHOO.elearning.dsJsonCurriculum = new Ext.data.JsonStore({
		autoLoad:false,			
		url:'/appjson/jsnELearningCurriculum.asp',
		root:'Records',
		fields:[{name:'ProjectID'},
        {name:'ProjectName'},
        {name:'ELearnTypeGroupID'},
        {name:'ELearnTypeGroup'},
        {name:'ELearnFocusGroupID'},
        {name:'ELearnFocusGroup'},
        {name:'DateStart', type:'date'},
        {name:'DateEnd', type:'date'},
        {name:'ProjectDescription'},
        {name:'EvalProjectUrl'}],
		sortInfo:{field:'DateEnd', direction:'DESC'}
	});
		
	YAHOO.elearning.gridCurriculum = new Ext.grid.GridPanel({
        store:YAHOO.elearning.dsJsonCurriculum,
        cm:new Ext.grid.ColumnModel([
			YAHOO.elearning.expanderCurriculum,
	        {header:'Name', width:350, sortable:true, renderer:renderProjectLink, dataIndex:'ProjectName'},
	        {header:'Disease', width:100, sortable:true, dataIndex:'ELearnFocusGroup'},
	        {header:'Product', width:120, sortable:true, dataIndex:'ELearnTypeGroup'},
	        {header:'Expires', width:70, sortable:true, renderer:Ext.util.Format.dateRenderer('m/d/Y'), dataIndex:'DateEnd'},
	        {header:'Remove', align:'center', width:70, renderer:renderRemoveLink}
	        //TODO: img for remove column
	        //COMPLETED : 17 Dec 2007 MDB
        ]),
        viewConfig:{forceFit:true,
	        enableRowBody:true,
	        emptyText:'<h4>No Curriculum Courses Available - Add Courses Now</h4>'
					+'<p>You have not added any courses to your curriculum.</p>'
					+'<p>Perform a search using the options to the left under BROWSE COURSES and add them now.</p>'
        },
        loadMask:true,
        trackMouseOver:false,
        sm:new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn}),
        width:740,
		height:510,
		frame:true,
        autoRowHeight:true,
        autoScroll:true,
        stripeRows:true,
        plugins:YAHOO.elearning.expanderCurriculum,
        //TODO: show the totalRecords in the title 'Available Courses (totalRecords)'
        //OR implement something similar to the footer of the paging grid example
        title:'My Curriculum Courses',
        tools:[{
			id:'close',
			qtip:'Hide',
			handler: function(e, target, panel){
				toggleGrid('content-grid-curriculum','hide');
			}
		}],
        iconCls:'icon-grid',
		renderTo:'content-grid-curriculum'
    });
    //YAHOO.elearning.dsJsonCurriculum.on('load',function(){YAHOO.elearning.dsJsonCurriculum.filter('FavoriteYN','Y');});
    return;
}

function renderProjectLink(value, obj, record, rowIndex, colIndex, ds){
	return '<a href="#" onclick="handle_ProjectLoad('+record.data.ProjectID+');return false;" target="_blank">'+record.get('ProjectName')+'</a>';
}

function renderRemoveLink(value, obj, record, rowIndex, colIndex, ds){
	return '<a href="#" onclick="handle_ProjectFavRemove('+record.data.ProjectID+');return false;"><img title="Remove Course" alt="Remove Course" src="/appresources/images/elearn/drop-no.gif" height="16" width="16" /></a>';//<a href="#" onclick="handle_ProjectFavRemove('+record.data.ProjectID+');return false;">remove</a>
}

function handle_ProjectFavRemove(sProjectID){
	var sUrl='/appjson/jsnELearningProjectFav.asp?dialog_add_projectid='+sProjectID+'&AppUser_pmProjectFav_Action=Delete';
	var ajaxViewed=YAHOO.util.Connect.asyncRequest('GET',sUrl,
	{ success: function(o) {YAHOO.elearning.dsJsonCurriculum.reload();/*YAHOO.elearning.dsJsonCurriculum.on('load',function(){YAHOO.elearning.dsJsonCurriculum.filter('FavoriteYN','Y');})*/},
	  failure: function(o) {alert('Error\nCould not delete the course.');}
	});
}

function filterGrid(record){
    var	aELearnTypeGroupID=HAR.Form.getInputValue('ELearnTypeGroupIDList').split(',');
		/*use all ELearnTypeGroup if none selected */
	if(aELearnTypeGroupID[0].length==0) 
		aELearnTypeGroupID=HAR.Form.getInputValue('ELearnTypeGroupIDList','all').split(',');
	/*only get selected project focus groups*/ 
	var	aELearnFocusGroupID=HAR.Form.getInputValue('ELearnFocusGroupIDList').split(',');
	/*use all ELearnFocusGroup if none selected */
	if(aELearnFocusGroupID[0].length==0) 
		aELearnFocusGroupID=HAR.Form.getInputValue('ELearnFocusGroupIDList','all').split(',');
	/* test the requirements and return true */
	if(HAR.Data.inArray(aELearnFocusGroupID,record.data.ELearnFocusGroupID)>=0 && HAR.Data.inArray(aELearnTypeGroupID,record.data.ELearnTypeGroupID)>=0) return true;
}