var alphaOnlySpecialityName = "No Specialty";

/*=====================================*\
| The following adds three new methods	|
| to the basic JavaScrip "String" class.|
\*=====================================*/
String.prototype.trimL = function() {return this.replace( /^\s+/g, "" );}
String.prototype.trimR = function() {return this.replace( /\s+$/g, "" );}
String.prototype.trim  = function() {tmp=this.trimR();return tmp.trimL();}

/*=========================================================*\
|
| In order to use this, the page must perform the following:
| 1) The page sets up the areas of the screen to be used
| 2) Then the page creates an instance of the Controller
| 3) Then it repeatedly calls CreateItem()
| 4) And finally it calls Init()
|
| It should look something like this:
|
|(1)	<div id="myFilterArea"></div>
|	<div id="myTabArea"></div>
|	<div id="myIndexArea"></div>
|	<div id="myDetailArea"></div>
|
|	<script>
|(2)	var myController = new SCreenController("myController","myFilterArea","myTabArea","myIndexArea","myDetailArea");
|(3)	myController.CreateItem(...);
|	myController.CreateItem(...);
|	myController.CreateItem(...);
|(4)	myController.Init();
|	</script>
|
| From then on the page doesn't have to do anything at all
|
\*=========================================================*/


function screenController(whoAmI, FilterAreaName, TabAreaName, IndexAreaName, DetailAreaName){

this.filterTypes			= new Object;
this.filterTypes.displayAllJournals	= 1;
this.filterTypes.displayFullTextJournal	= 2;

this.browseTypes			= new Object;
this.browseTypes.browseBySpecialty	= 1;
this.browseTypes.browseByTitle		= 2;

this.myName		= whoAmI;
this.filterAreaName	= FilterAreaName;
this.tabAreaName	= TabAreaName;
this.indexAreaName	= IndexAreaName;
this.detailAreaName	= DetailAreaName;

this.Specialties	= new Array();	//.specialityName+Sort
this.bySpecialtiesInfo	= new Array();	//.specialityName+sort .docName+Sort .contentDesc .inNewWindow .url .signInRequired .exitPage
this.byTitlesInfo	= new Array();	//                     .docName+Sort .contentDesc .inNewWindow .url .signInRequired .exitPage
this.infoToDisplay	= null;
this.alphabet		= new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

this.filterType		= this.filterTypes.displayAllJournals;		//1="All Journals & Newsletters" 2="Full-Text Journals"
this.browseType		= this.browseTypes.browseBySpecialty;		//1="Browse by Specialty"        2="Browse by Title"
this.selectedGroup	= "";
this.cookieName		= "test";	//default name (real name developed after function definitions)
this.redirectURL	= "";

this.debugging		= false;
//this.debugging		= true;
this.debugWindow	= null;
this.imageCache		= new Array();

//================================================================
this.CreateItem = function(Specialty, Name, ContentDesc, ShowInNewWindow, SignInRequired, Url, ExitPage, HTMLid)
//================================================================
	{
	var objRaw		= new Object;
	objRaw.Name		= Name;
	objRaw.ContentDesc	= ContentDesc;
	objRaw.ShowInNewWindow	= ShowInNewWindow;
	objRaw.SignInRequired	= SignInRequired;
	objRaw.url		= Url;
	objRaw.exitPage		= ExitPage;
	objRaw.HTMLid		= HTMLid;

	objRaw.docName		= Name;
	this.composeUrl(objRaw);
	objRaw.Specialties	= new Array;
	objRaw.Specialties[0]	= Specialty;

	//there are 2 journals with the same name.
	//to keep them straight one's name has a trailing space

//	//----------------------------------------------------------
//	//Here's a big hack!
//	//Remove space, period and/or comma from the end of the name
//	//----------------------------------------------------------
//	var test = true;
//	while (test == true)
//		{
//		var lastChar = Name.substr(Name.length - 1, 1);
//		if (lastChar == " " || lastChar == "." || lastChar == ",")
//		if (lastChar == " " || lastChar == ",")
//			Name = Name.substring(0, Name.length - 1);
//		else
//			test = false;
//		}

	Specialty = Specialty.replace(/&amp;/g,"&");

	var SpecialtyUpper = Specialty.toUpperCase();
	var NameUpper = Name.toUpperCase();

	//----------------------------------
	//always add this to SpecialtiesInfo
	//----------------------------------
	var objSpl			= new Object;
	objSpl.specialtyName		= Specialty;
	objSpl.specialtyNameSort	= SpecialtyUpper;
	objSpl.docName			= Name;
	objSpl.docNameSort		= NameUpper;
	objSpl.contentDesc		= ContentDesc;
	objSpl.inNewWindow		= (ShowInNewWindow == "true");
	objSpl.url			= Url;
	objSpl.signInRequired		= (SignInRequired == "true");
	objSpl.exitPage			= ExitPage;
	objSpl.HTMLid			= HTMLid;
	this.composeUrl(objSpl);

	this.bySpecialtiesInfo[this.bySpecialtiesInfo.length] = objSpl;

	//---------------------------------------------------------
	//add this Specialty to Specialties if it not already there
	//---------------------------------------------------------
	var found = false;
	for(var x = 0; x < this.Specialties.length; x++)
		if (SpecialtyUpper == this.Specialties[x].specialtyNameSort)
			{
			found = true;
			break;
			}

	//if it's not there, add it to Specialties
	if (found == false)
		{
		var objSpl			= new Object;
		objSpl.specialtyName		= Specialty;
		objSpl.specialtyNameSort	= SpecialtyUpper;

		this.Specialties[this.Specialties.length] = objSpl;
		}

	//----------------------------------------
	//add to byTitlesInfo if not already there
	//----------------------------------------
	var found = false;
	for(var x = 0; x < this.byTitlesInfo.length; x++)
		{
		if (NameUpper == this.byTitlesInfo[x].docNameSort)
			{
			found = true;
			break;
			}
		}

	//-----------------------------------------
	//if it's not there, add it to byTitlesInfo
	//-----------------------------------------
	if (found == false)
		{
		var objDoc			= new Object;
		objDoc.specialtyName		=
		objDoc.specialtyNameSort	= NameUpper.substring(0,1);

		//---------------------------------------------------------
		//if the character to be used for indexing isn't alphabetic
		//---------------------------------------------------------
		if (objDoc.specialtyNameSort < "A" | objDoc.specialtyNameSort > "Z")
			{
			//----------------------------------------------------------------
			//and it's also not already in the the list of indexing characters
			//----------------------------------------------------------------
			var inIndexList = false;
			for (var x = 0; x < this.alphabet.length; x++)
				{
				if (objDoc.specialtyNameSort == this.alphabet[x])
					{
					inIndexList = true;
					break;
					}
				}
			if (inIndexList == false)
				{
				//---------------------------------------------
				//add it to the end of the list and then resort
				//---------------------------------------------
				this.alphabet[this.alphabet.length] = objDoc.specialtyNameSort;
				this.alphabet.sort
					(
					function(a1,a2)
						{
						if (a1 < a2) return -1;
						if (a1 > a2) return  1;
						return 0;
						}
					);
				}
			}
		objDoc.docName			= Name;
		objDoc.docNameSort		= NameUpper;
		objDoc.contentDesc		= ContentDesc;
		objDoc.inNewWindow		= (ShowInNewWindow == "true");
		objDoc.url			= Url;
		objDoc.signInRequired		= (SignInRequired == "true");
		objDoc.exitPage			= ExitPage;
		objDoc.HTMLid			= HTMLid;
		this.composeUrl(objDoc);

		this.byTitlesInfo[this.byTitlesInfo.length] = objDoc;
		}
	}

//================================================================
this.composeUrl = function(obj)
//================================================================
	{
	if (obj.exitPage != "" && obj.url.indexOf(obj.exitPage) == -1)
		obj.url = obj.exitPage + "?url=" + obj.url + "&name=" + this.encode(obj.docName);
	var tag = document.getElementById(obj.HTMLid);
	if (tag)
		{
		if (!document.all)
			{
			var attr = tag.attributes.getNamedItem("sdcTags");
			if (attr) tag["sdcTags"] = attr.nodeValue;
			}
		obj.sdcTags = tag.sdcTags;
		}
	}
//================================================================
this.redirect = function()
//================================================================
	{
	if (this.redirectURL != "")
		document.location.replace(this.redirectURL);	//navigates without ading a history entry
	}
//================================================================
this.Init = function()
//================================================================
	{

	if (this.redirectURL == "")
		this.loadCookieValues();
	else
		{
		if (this.filterAreaName != "")document.getElementById(this.filterAreaName	).style.display	=  "none";
		if (this.tabAreaName	!= "")document.getElementById(this.tabAreaName		).style.display	=  "none";
		if (this.indexAreaName	!= "")document.getElementById(this.indexAreaName	).style.display	=  "none";
		if (this.detailAreaName	!= "")document.getElementById(this.detailAreaName	).style.display	=  "none";
		}

	this.debug("-----------------------[ before sorting ]--------------------------------");
	this.dumpData();

	//--------------------------
	//sort Specialties by name
	//--------------------------
	var SpecialtiesCollator = function(item1, item2)
		{
		//----------------------------------------------
		//major hack to get "Multispecialty" to sort 1st
		//----------------------------------------------
		var name1 = item1.specialtyNameSort.substr(0,5);
		var name2 = item2.specialtyNameSort.substr(0,5);
		name1 = (name1 == "MULTI")?"":item1.specialtyNameSort;
		name2 = (name2 == "MULTI")?"":item2.specialtyNameSort;
		//----------------------------------------------
		if (name1 < name2) return (-1);
		if (name1 > name2) return ( 1);
		return(0);
		}
	this.Specialties.sort(SpecialtiesCollator);

	//-----------------------------------------------------------
	// Before we sort the alphabetic list, let's make a few more.
	// (We waited until all the creats and overrides are done.)
	//-----------------------------------------------------------
	if (this.debugging) this.debug("scanning bySpecialtiesInfo for name changes");
	for (var x = 0; x < this.bySpecialtiesInfo.length; x++)
		{
		var oldItem = this.bySpecialtiesInfo[x];
		if (oldItem.docNameSort.substr(0,4) == "THE ")
			{
//			if (oldItem.docNameSort.indexOf("MERCK") == -1)
//				{
//				//if it's not MERCK change the display name and sort order
//				var oldName		= oldItem.docName;
//				oldItem.docName		= oldItem.docName.substr(4) + ", " + oldItem.docName.substr(0, 3);
//				oldItem.docNameSort	= oldItem.docName.toUpperCase();
//				if (this.debugging) this.debug("changed [" + oldName + "] to [" + oldItem.docName + "]");
//				}
//			else
//				{
				//if it is MERCK only change the sort order
				var oldName		= oldItem.docNameSort;
				oldItem.docNameSort	= oldItem.docNameSort.substr(4) + ", " + oldItem.docNameSort.substr(0, 3);;
				if (this.debugging) this.debug("changed [" + oldName + "] to [" + oldItem.docNameSort + "]");
//				}
			}
		}

	//---------------------------------------------
	//sort SpecialtiesInfo by specialty and docName
	//---------------------------------------------
	var SpecialtyCollator = function(item1, item2)
		{
		//----------------------------------------------
		//major hack to get "Multispecialty" to sort 1st
		//----------------------------------------------
		var name1 = item1.specialtyNameSort.substr(0,5);
		var name2 = item2.specialtyNameSort.substr(0,5);
		name1 = (name1 == "MULTI")?"":item1.specialtyNameSort;
		name2 = (name2 == "MULTI")?"":item2.specialtyNameSort;
		//----------------------------------------------
		if (name1             < name2            ) return (-1);
		if (name1             > name2            ) return ( 1);
		if (item1.docNameSort < item2.docNameSort) return (-1);
		if (item1.docNameSort > item2.docNameSort) return ( 1);
		return(0);
		}
	this.bySpecialtiesInfo.sort(SpecialtyCollator);

	//-----------------------------------------------------------
	// Before we sort the alphabetic list, let's make a few more.
	// (We waited until all the creates are done.)
	//----------------------------------------------------------
	if (this.debugging) this.debug("scanning byTitlesInfo for name changes");
	var originalLength = this.byTitlesInfo.length;
	for (var x = 0; x < originalLength; x++)
		{
		var oldItem = this.byTitlesInfo[x];
		if (oldItem.docNameSort.substr(0,4) == "THE ")
			{
			var newItem			= new Object;
//			if (oldItem.docNameSort.indexOf("MERCK") == -1)
//				{
//				//if its not MERCK change the name, sort order and index
//				newItem.docName			= oldItem.docName.substr(4) + ", " + oldItem.docName.substr(0, 3);
//				newItem.docNameSort		= newItem.docName.toUpperCase();
//				newItem.specialtyName		= newItem.docName.substr(0,1);
//				newItem.specialtyNameSort	= newItem.specialtyName.toUpperCase();
//				}
//			else
//				{
				//if it is MERCK change sort order and index, but not the display name
				newItem.docName			= oldItem.docName;
				newItem.docNameSort		= oldItem.docName.substr(4) + ", " + oldItem.docName.substr(0, 3);
				newItem.docNameSort		= newItem.docNameSort.toUpperCase();
				newItem.specialtyName		=
				newItem.specialtyNameSort	= oldItem.docName.substr(4, 1);
//				}
			newItem.contentDesc		= oldItem.contentDesc;
			newItem.inNewWindow		= oldItem.inNewWindow;
			newItem.url			= oldItem.url;
			newItem.signInRequired		= oldItem.signInRequired;
			newItem.exitPage		= oldItem.exitPage;
			newItem.HTMLid			= oldItem.HTMLid;
			this.byTitlesInfo[x]		= newItem;		//this replaces one for the other
//			this.byTitlesInfo[this.byTitlesInfo.length] = newItem;	//this creates a duel listing
			if (this.debugging) this.debug("generated [" + newItem.docName + "][" + newItem.specialtyNameSort + "] from [" + oldItem.docName + "][" + oldItem.specialtyNameSort + "]");
			}
		}

	//--------------------------
	//sort DocumentsInfo by name
	//--------------------------
	var DocumentCollator = function(item1, item2)
		{
		if (item1.specialtyNameSort < item2.specialtyNameSort) return (-1);
		if (item1.specialtyNameSort > item2.specialtyNameSort) return ( 1);
		if (item1.docNameSort       < item2.docNameSort      ) return (-1);
		if (item1.docNameSort       > item2.docNameSort      ) return ( 1);
		return(0);
		}
	this.byTitlesInfo.sort(DocumentCollator);

	this.debug("-----------------------[ after sorting ]--------------------------------");
	this.dumpData();

	this.GenerateScreen();
	}
//================================================================
this.GenerateScreen = function()
//================================================================
	{
	this.GetInfoToDisplay();
	if (this.filterAreaName != "")this.GenerateFilter();
	this.GenerateTabs();
	this.GenerateIndex();
	this.GenerateDetail();
	if (this.selectedGroup != "")
		this.showOne(this.selectedGroup);
	}
//================================================================
this.GetInfoToDisplay = function()
//================================================================
	{
	//-----------------------------------------
	//if we're to show the listing by specialty
	//-----------------------------------------
	if (this.browseType == this.browseTypes.browseBySpecialty)
		{
		if (this.filterType == this.filterTypes.displayAllJournals)	//show the entire list
			{
			this.infoToDisplay = this.bySpecialtiesInfo;
			}
		if (this.filterType == this.filterTypes.displayFullTextJournal)	//or only show the full-text items
			{
			this.infoToDisplay = new Array();
			for(var x = 0; x < this.bySpecialtiesInfo.length; x++)
				if (this.bySpecialtiesInfo[x].contentDesc == "Full-Text")
					this.infoToDisplay[this.infoToDisplay.length] = this.bySpecialtiesInfo[x];
			}
		}

	//---------------------------------------
	//if we're to show the alphabetic listing
	//---------------------------------------
	if (this.browseType == this.browseTypes.browseByTitle)
		{
		if (this.filterType == this.filterTypes.displayAllJournals)	//show the entire list
			{
			this.infoToDisplay = this.byTitlesInfo;
			}
		if (this.filterType == this.filterTypes.displayFullTextJournal)	//or only show the full-text items
			{
			this.infoToDisplay = new Array();
			for(var x = 0; x < this.byTitlesInfo.length; x++)
				if (this.byTitlesInfo[x].contentDesc == "Full-Text")
					this.infoToDisplay[this.infoToDisplay.length] = this.byTitlesInfo[x];
			}
		}
	}
//================================================================
this.GenerateFilter = function()
//================================================================
	{
	var strHTML = "<div class='filterInstructions'>";
	if (this.filterType == this.filterTypes.displayAllJournals)
		strHTML += "<div class='currentState'>All Publications</div><a href='#' onclick='javascript:" + this.myName + ".SetFilter("+this.filterTypes.displayFullTextJournal+"); return false;'>View Full-Text Only</a>";
	else
		strHTML += "<div class='currentState'>Full-Text Only</div><a href='#' onclick='javascript:" + this.myName + ".SetFilter("+this.filterTypes.displayAllJournals+"); return false;'>View All Publications</a>";
	strHTML += "</div>";

	var objTag = document.getElementById(this.filterAreaName);
	objTag.innerHTML = strHTML;
	}
//================================================================
this.GenerateTabs = function()
//================================================================
	{
	var strHTML = "";

	strHTML += "<div class='tabSection'><div class='tabImages'>";
	if (this.browseType == this.browseTypes.browseBySpecialty)
		strHTML += "<img src='/ppdocs/us/hcp/images/redesign/img_tab_brws_spec_present.gif'><a href='#' onclick='javascript:" + this.myName + ".SetBrowse("+this.browseTypes.browseByTitle+"); return false;'><img border='0' src='/ppdocs/us/hcp/images/redesign/img_tab_brws_titl_on.gif'></a>";
	else
		strHTML += "<a href='#' onclick='javascript:" + this.myName + ".SetBrowse("+this.browseTypes.browseBySpecialty+"); return false;'><img border='0' src='/ppdocs/us/hcp/images/redesign/img_tab_brws_spec_on.gif'></a><img src='/ppdocs/us/hcp/images/redesign/img_tab_brws_titl_present.gif'>";
	strHTML += "</div></div>";

	var objTag = document.getElementById(this.tabAreaName);
	objTag.innerHTML = strHTML;
	}
//================================================================
this.GenerateIndex = function()
//================================================================
	{
	var strHTML = "";

	if (this.browseType == this.browseTypes.browseBySpecialty)
		{
		var specialtyInfo	= [];	//array index by specialty name holding index height info
		var totalColumns	= 4;
		var maxPixelWidth	= 123;	//widest one-liner is 122 px
		var totalLinesNeeded	= 0;

		for (var i = 0; i < this.Specialties.length; i++)
			{
			var specialtyName = this.Specialties[i].specialtyName;
			if (specialtyName == alphaOnlySpecialityName) continue;

			var info = new Object;
			specialtyInfo[specialtyName] = info;

			//determine the pixel width of each item
			var width = FindTextWidth(specialtyName);

			//using a predetermined maximum pixel width calculate how many lines each item requires
			info.linesNeeded = Math.floor(width / maxPixelWidth) + 1;

			//calculate the total number of lines required for all items
			totalLinesNeeded += info.linesNeeded;
			}

		//calculate the ideal height of a column
		var idealLinesInColumn = Math.floor(totalLinesNeeded / totalColumns);

		//assign the ideal height to each column and distribute the remainder
		var colAvailable = [];
		var leftOver = totalLinesNeeded % totalColumns;
		for(var x = totalColumns - 1; x >= 0; x--)
			{
			colAvailable[x] = idealLinesInColumn;
			if (leftOver > 0)
				{
				colAvailable[x]++;
				leftOver--;
				}
			}

		strHTML += "<div class='indexDirections'><span class='indexText'>Choose a specialty";
		if (this.selectedGroup != "")
			strHTML += " or <a href='#' onclick='javascript:" + this.myName + ".showAll(); return false;'>view all</a>";
		strHTML += "</span></div>";
		var columnBeingFilled = 0;

		strHTML += "<table class='specialtybookmarks' cellpadding='0' cellspacing='0'><tr><td valign='top'><ul class='specialtyIndex'>";
		for (var i = 0; i < this.Specialties.length; i++)
			{
			var specialtyName = this.Specialties[i].specialtyName;

			if (specialtyName == alphaOnlySpecialityName) continue;

			if	(	columnBeingFilled + 1 < totalColumns
				&&	specialtyInfo[specialtyName].linesNeeded > colAvailable[columnBeingFilled]
				)
				{
				var unused = colAvailable[columnBeingFilled];	//if something didn't get used
				columnBeingFilled++;
				colAvailable[columnBeingFilled] += unused;	//give it to the next column
				strHTML += "</ul></td><td valign='top'><ul class='specialtyIndex'>";
				}
			colAvailable[columnBeingFilled] -= specialtyInfo[specialtyName].linesNeeded;


			//Check to see if this specialty has any data.  Grey-out the link if there's no data
			var found = false;
			for(var x = 0; x < this.infoToDisplay.length && found == false; x++)
				if (this.infoToDisplay[x].specialtyName == specialtyName)
					found = true;

			var dsplSpecialtyName = specialtyName.replace("'","&#039;");
			dsplSpecialtyName = dsplSpecialtyName.replace(/\//g,"/<br>");	//put a space after the slash
			dsplSpecialtyName = dsplSpecialtyName.replace(/ & /g," &<br>");	//put a space after the slash
			
			if (found == true)
				strHTML += "<li class='specialtybookmark'><a href='#' onclick='javascript:" + this.myName + ".showOne(\"" + specialtyName + "\"); return false;'>" + dsplSpecialtyName + "</a></li>";
			else
				strHTML += "<li class='specialtybookmarkdead'>" + dsplSpecialtyName + "</li>";
			}
		strHTML += "</ul></td></tr></table>";
		}

	if (this.browseType == this.browseTypes.browseByTitle)
		{
		strHTML += "<div class='indexDirections'><span class='indexText'>Choose a letter";
		if (this.selectedGroup != "")
			strHTML += " or <a href='#' onclick='javascript:" + this.myName + ".showAll(); return false;'>view all</a>";
		strHTML += "</span></div>";

		for (i = 0; i < this.alphabet.length; i++)
			{
			letter = this.alphabet[i];

			//Check to see if this letter has any data.  Grey-out the link if there's no data
			var found = false;
			for(var x = 0; x < this.infoToDisplay.length && found == false; x++)
				{
				var docName = this.infoToDisplay[x].docNameSort;
				var firstLetter = docName.substring(0,1);
				if (firstLetter.toUpperCase() == letter)
					found = true;
				}
			if (found == true)
				strHTML += "<span class='letterIndex'><a href='#' onclick='javascript:" + this.myName + ".showOne(\"" + letter + "\"); return false;'>" + letter + "</a></span>";
			else
				strHTML += "<span class='letterIndexDead'>" + letter + "</span>";

			}


		}

	var objTag = document.getElementById(this.indexAreaName);
	objTag.innerHTML = strHTML;
	}
//================================================================
this.GenerateDetail = function()
//================================================================
	{
	var strHTML = "<div id='detailArea'";

	var prevspecialtyName = "";

	for (var x = 0; x < this.infoToDisplay.length; x++)
		{
		var detail = this.infoToDisplay[x];	//.specialtyName .docName .contentDesc .inNewWindow .url

		if (detail.specialtyName == alphaOnlySpecialityName) continue;

		if (this.selectedGroup == "" || this.selectedGroup == detail.specialtyName)
			{
			if (detail.specialtyName != prevspecialtyName)
				{
				if (prevspecialtyName != "") strHTML += this.closeSectionHeader();
				strHTML += "<div name='sectionHeader' class='specialty' specialtyName=\"" + detail.specialtyName + "\">";
				strHTML += "<div class='bucket-header-medium'><div>";
				strHTML += detail.specialtyName + "</div></div>";
				strHTML += "<div class='bucket-content-medium'><ul class='ListOfLinks'>";
				prevspecialtyName = detail.specialtyName;
				}
			var strClassInfo = (detail.signInRequired == true && showLocks == true)?" class=\"locked\"":"";
			var strTargetInfo = (detail.inNewWindow == true)?" target=\"_blank\"":"";
			var strJournalName = this.deriveJournalName(detail.docName);
			var strDescription = this.deriveJournalDescription(detail.docName);
			var strTrailerInfo = (detail.contentDesc == "")?"":"<span class=\"trailer\">(" + detail.contentDesc + ")</span>";
			var strTags = (detail.sdcTags)?(" sdcTags=\"" + detail.sdcTags + "\""):"";
			if(strJournalName == "Journal of American Board of Family Medicine")
				strJournalName = strJournalName.replace("Journal of American Board of Family Medicine","Journal of the American Board of Family Medicine")
			if(strJournalName == "Journal of American Medical Association")
				strJournalName = strJournalName.replace("Journal of American Medical Association","JAMA - Journal of American Medical Association")
			strHTML += "<li" + strClassInfo + "><a href=\"" + detail.url + "\"" + strTargetInfo + strTags + ">" + strJournalName + "</a>" + strTrailerInfo + "</li>";
			if (strDescription != "")
				strHTML += "<div class='trailer' style='margin:0px 0px 1px -15px;'>" + strDescription + "</div>";
			}
		}
	strHTML += this.closeSectionHeader();
	strHTML += "</div>";

	var objTag = document.getElementById(this.detailAreaName);
	objTag.innerHTML = strHTML;
	}
//================================================================
this.closeSectionHeader = function()
//================================================================
	{
	var strHTML = "";
	strHTML += "</ul></div>";
	if (this.selectedGroup == "")
		strHTML += "<div class='back2top'><a href=\"#topOfPage\">back to top</a> <a href=\"#topOfPage\"><img src='/ppdocs/us/hcp/images/redesign/back2top.jpg' border='0' alt='back to top'></a></div>";
	strHTML += "</div>";
	return strHTML;
	}

//================================================================
// The following data definitions and the two routines
// "deriveJournalName" and "deriveJournalDescription" are only
// temporary.  They were added for R31 and the plan is that they
// will be removed for R32 when the derivations will no longer be
// necessary and the descriptions will come from the database.
//================================================================
	this.PubMedJournals = new Array
		(
		"Annals of Internal Medicine&nbsp;",
	//The below Journal title has been modified from "JAMA - Journal of American Medical Association"
	//for the CQ -26619. Since the "JAMA - " have sorting issues.
		"Journal of American Medical Association",
		"The Lancet",
		"The New England Journal of Medicine",
		"Cancer"
		);
	this.nameTrailer	= " - via MD Consult - MerckMedicus Edition";
	this.MDdescription	= "(via MD Consult - Merck<i>Medicus</i> Edition)";
	this.PMdescription	= "(PubMed abstracts from the last 30 days)";
//================================================================
this.deriveJournalName = function (journalName)
//================================================================
	{
	var pos = journalName.indexOf(this.nameTrailer);
	if (pos == -1)
		return journalName;
	else
		return journalName.substr(0, pos);
	}
//================================================================
this.deriveJournalDescription = function (journalName)
//================================================================
	{
	if (journalName.indexOf(this.nameTrailer) != -1)
		return this.MDdescription;
	for (var x = 0; x < this.PubMedJournals.length; x++)
		if (journalName == this.PubMedJournals[x])
			return(this.PMdescription);
	return "";
	}
//================================================================
this.SetFilter	= function(newVal)
//================================================================
	{
	this.filterType = newVal;
	this.saveCookieValues();
	this.GenerateScreen();
	}
//================================================================
this.SetBrowse	= function(newVal)
//================================================================
	{
	this.browseType = newVal;
//	this.saveCookieValues();
	this.setGroup("");	//changing the browse mode deselects a group
	this.GenerateScreen();
	}
//================================================================
this.setGroup	= function(newVal)
//================================================================
	{
	this.selectedGroup = newVal;
	this.saveCookieValues();
	}
//================================================================
this.showOne = function(which)
//================================================================
	{

	if (which == "All")
		{
		this.showAll();
		return;
		}

	if (which == "Family Practice/General Practice") which = "Family Medicine/Primary Care";
	if (which == "Allergy and Immunology") which = "Allergy & Immunology";


	var whichUpper = which.toUpperCase();
	whichUpper = whichUpper.replace("'","&#039;");

	var found = false;
	for (var x = 0; x < this.infoToDisplay.length && found == false; x++)
		{
		var doc = this.infoToDisplay[x];
		if (doc.specialtyNameSort == whichUpper)
			{
			found = true;
			break;
			}
		}
	if (found == true)
		{
		which = which.replace("'","&#039;");
		this.setGroup(which);
		this.GenerateIndex();
		this.GenerateDetail();
		}
	else
		{
		if (this.filterType == this.filterTypes.displayFullTextJournal)
			alert("There are no Full-Text journals for " + which);
		else
			alert("There are no journals for " + which);
		this.showAll();
		}
	}
//================================================================
this.showAll = function()
//================================================================
	{
	this.setGroup("");
	this.GenerateIndex();
	this.GenerateDetail();
	}
//================================================================
this.encode = function(orig)
//================================================================
	{
	ret = orig.replace(/  /g," ");		//change multiple spaces to a single space
	ret = ret.replace(/ /g,"+");		//change a single space to a plus-sign
	ret = ret.replace(/(&amp;|&)/g,"%26");	//change "&amp;" or "&"
	//need to investivate the possible use of "ret = ret.escape();"
//	ret = ret.replace(/;/g,"%3B");		//change a semi-colon
//	ret = ret.replace(/:/g,"%3A");		//change a colon
//	ret = ret.replace(/"/g,"%22");		//change a double quotation mark
	return (ret);
	}
//================================================================
this.debug = function(text)
//================================================================
	{
	if (this.debugging == false) return;

	var Options
		= "directories=0"
		+ ", height=" + Math.floor(window.screen.height - 150)
		+ ", left=0"
		+ ", location=0"
		+ ", menubar=1"
		+ ", resizeable=1"
		+ ", scrollbars=1"
		+ ", status=0"
		+ ", titlebar=1"
		+ ", toolbar=1"
		+ ", top=20"
		+ ", width=" + (window.screen.width - 13);
	if (this.debugWindow == null)
		{
		this.debugWindow = window.open("", "hostLog", Options, false);
		if (this.debugWindow == null) return;
		this.debugWindow.document.writeln("<body style=\"font-family:arial; font-size:9pt;\">");
		}
	this.debugWindow.document.writeln(text + "<br/>");
	}
//================================================================
this.debugHTML = function(text)
//================================================================
	{
	if (this.debugging == false) return;

	var Options
		= "directories=0"
		+ ", height=" + Math.floor(window.screen.height - 150)
		+ ", left=0"
		+ ", location=0"
		+ ", menubar=1"
		+ ", resizeable=1"
		+ ", scrollbars=1"
		+ ", status=0"
		+ ", titlebar=1"
		+ ", toolbar=1"
		+ ", top=20"
		+ ", width=" + (window.screen.width - 13);
	if (this.debugWindow == null)
		{
		this.debugWindow = window.open("", "hostLog", Options, false);
		if (this.debugWindow == null) return;
		this.debugWindow.document.writeln("<body style=\"font-family:arial; font-size:9pt;\">");
		}
	this.debugWindow.document.writeln(text);
	}

//================================================================
this.dumpData = function()
//================================================================
	{
	this.debug("===========");
	this.debug("Specialties (" + this.Specialties.length + ")");
	this.debug("===========");
	for(var x = 0; x < this.Specialties.length; x++)
		{
		var doc = this.Specialties[x];
		this.debug("[" + doc.specialtyName + "]");
		}

	this.debug("=================");
	this.debug("bySpecialtiesInfo (" + this.bySpecialtiesInfo.length + ")");
	this.debug("=================");
	this.debugHTML("<table border='1' style=\"font-family:arial; font-size:8pt;\">");
	var strHeader	= "<tr>"
			+ "<th>speciality Name</th>"
			+ "<th>doc Name</th>"
			+ "<th>content Desc</th>"
			+ "<th>in New Window</th>"
			+ "<th>url</th>"
			+ "<th>sign In Required<th>"
			+ "<th>exit Page<th>"
			+ "<th>url Source<th>"
			+ "</tr>";
	for(var x = 0; x < this.bySpecialtiesInfo.length; x++)
		{
		if (x % 20 == 0) this.debugHTML(strHeader);
		var doc = this.bySpecialtiesInfo[x];
		this.debugHTML("<tr>");
		this.debugHTML("<td>" + doc.specialtyName + "</td>");
		this.debugHTML("<td>" + doc.docName + "</td>");
		this.debugHTML("<td>" + doc.contentDesc + "</td>");
		this.debugHTML("<td>" + doc.inNewWindow + "</td>");
		this.debugHTML("<td>" + doc.url + "</td>");
		this.debugHTML("<td>" + doc.signInRequired + "<td>");
		this.debugHTML("<td>" + doc.exitPage + "<td>");
		this.debugHTML("<td>" + doc.HTMLid + "<td>");
		this.debugHTML("</tr>");
		}
	this.debugHTML("</table>");

	this.debug("============");
	this.debug("byTitlesInfo (" + this.byTitlesInfo.length + ")");
	this.debug("============");
	this.debugHTML("<table border='1' style=\"font-family:arial; font-size:8pt;\">");
	var strHeader	= "<tr>"
			+ "<th>specialty Name</th>"
			+ "<th>specialty Name Upper</th>"
			+ "<th>doc Name</th>"
			+ "<th>doc Name Upper</th>"
			+ "<th>content Desc</th>"
			+ "<th>in New Window</th>"
			+ "<th>url</th>"
			+ "<th>sign In Required<th>"
			+ "<th>exit Page<th>"
			+ "<th>url Source<th>"
			+ "</tr>";
	for(var x = 0; x < this.byTitlesInfo.length; x++)
		{
		if (x % 20 == 0) this.debugHTML(strHeader);
		var doc = this.byTitlesInfo[x];
		this.debugHTML("<tr>");
		this.debugHTML("<td>" + doc.specialtyName + "</td>");
		this.debugHTML("<td>" + doc.specialtyNameSort + "</td>");
		this.debugHTML("<td>" + doc.docName + "</td>");
		this.debugHTML("<td>" + doc.docNameSort + "</td>");
		this.debugHTML("<td>" + doc.contentDesc + "</td>");
		this.debugHTML("<td>" + doc.inNewWindow + "</td>");
		this.debugHTML("<td>" + doc.url + "</td>");
		this.debugHTML("<td>" + doc.signInRequired + "<td>");
		this.debugHTML("<td>" + doc.exitPage + "<td>");
		this.debugHTML("<td>" + doc.HTMLid + "<td>");
		this.debugHTML("</tr>");
		}
	this.debugHTML("</table>");

	if (this.infoToDisplay != null)
		{
	this.debug("=============");
	this.debug("infoToDisplay (" + this.infoToDisplay.length + ")");
	this.debug("=============");
	this.debugHTML("<table border='1' style=\"font-family:arial; font-size:8pt;\">");
	var strHeader	= "<tr>"
			+ "<th>specialty Name</th>"
			+ "<th>specialty Name Upper</th>"
			+ "<th>doc Name</th>"
			+ "<th>doc Name Upper</th>"
			+ "<th>content Desc</th>"
			+ "<th>in New Window</th>"
			+ "<th>url</th>"
			+ "<th>sign In Required<th>"
			+ "<th>exit Page<th>"
			+ "<th>url Source<th>"
			+ "</tr>";
	for(var x = 0; x < this.infoToDisplay.length; x++)
		{
		if (x % 20 == 0) this.debugHTML(strHeader);
		var doc = this.infoToDisplay[x];
		this.debugHTML("<tr>");
		this.debugHTML("<td>" + doc.specialtyName + "</td>");
		this.debugHTML("<td>" + doc.specialtyNameSort + "</td>");
		this.debugHTML("<td>" + doc.docName + "</td>");
		this.debugHTML("<td>" + doc.docNameSort + "</td>");
		this.debugHTML("<td>" + doc.contentDesc + "</td>");
		this.debugHTML("<td>" + doc.inNewWindow + "</td>");
		this.debugHTML("<td>" + doc.url + "</td>");
		this.debugHTML("<td>" + doc.signInRequired + "<td>");
		this.debugHTML("<td>" + doc.exitPage + "<td>");
		this.debugHTML("<td>" + doc.HTMLid + "<td>");
		this.debugHTML("</tr>");
		}
	this.debugHTML("</table>");
		}

	}
//================================================================
this.preloadImage = function(src)
//================================================================
	{
	imageObject = new Image();
	imageObject.src = src;
	this.imageCache[this.imageCache.length] = imageObject;
	}
//================================================================
this.getGenericCookieValue = function (cookieName)
//================================================================
	{
	var retValue = "";
	var cookies = document.cookie;
	var re = cookieName + "=([^;]+);";
	if (cookies.match(re))
		retValue = RegExp.$1;
	return retValue;
	}
//================================================================
this.loadCookieValues = function()
//================================================================
	{
	var cookies = unescape(document.cookie);
	var re = this.cookieName + "=:([1|2]):([1|2]):([^:]*):.*";
	if (cookies.match(re))
		{
		this.filterType = new Number(RegExp.$1);
		this.browseType = new Number(RegExp.$2);
		this.selectedGroup = RegExp.$3;
		}
	}
//================================================================
this.saveCookieValues = function()
//================================================================
	{
	var cookieValue = ":" + this.filterType + ":" + this.browseType + ":" + this.selectedGroup + ":";
	var exp = new Date()
	var nowPlusOneHour = exp.getTime() + (60 * 60 * 1000);	//expires in 1 hour
	exp.setTime(nowPlusOneHour);
	var command = this.cookieName + "=" + escape(cookieValue) + ";expires=" + exp.toGMTString() + ";path=/";
	document.cookie = command;
	}




{
//this initialization logic follows the function definitions, so that one of them can be called
var re = /([^:]*:\/\/([^\/]*\/)*([^\.]*)\.jsp)(.*)/gi;
var loc = document.location.toString();
if (loc.match(re))
	{
	var fileName	= RegExp.$3;	//must be collected 1st because getGenericCookieValue also used RegEx
	var baseURL	= RegExp.$1;
	var params	= RegExp.$4;
	var sessionId	= this.getGenericCookieValue("JSESSIONID");
	this.cookieName	= sessionId + fileName;
	if (params.substr(0,4) == "?sp=")	//look to see if we were passed a directive
		this.redirectURL = baseURL;	//if we were, save the base URL, so we can redirect to it later
	}
}


// the following is the close-of-object bracket
}





document.write("<div id='FindTextWidthWorkArea'></div>");
function FindTextWidth(sample)
	{
	var tag		= document.getElementById("FindTextWidthWorkArea");
	tag.innerHTML	= "<span id='FindTextWidth'>" + sample + "</span>";
	var testTag	= document.getElementById("FindTextWidth");
	var width	= testTag.offsetWidth;
	tag.innerHTML	= "";
	return (width);
	}
