	////////////////////////////////////////////////////////////////////////////////////////////////////
	//                                                                                                //
	//  Defined below are some variables that are global to the application. Pretty standard stuff :) //
	//                                                                                                //
	////////////////////////////////////////////////////////////////////////////////////////////////////

	// This is the most important array in the program. It holds all of the subject objects.
	var subjects = new Array();
	// This is the counter for the aforementioned. It increments++ when we add more subjects.
	var subjectsCount=0;
	// This is the subjectIndex. It is the index in the subjects[] array, of the current subject.
	var subjectIndex=0;

	// Some more global variables for our program. These aren't important enough to merit individual explanations but we still need em.
	var defaultSubjectIndex = 0;
	var SMContentSetStartIndex;
	var SMContentSetEndIndex;
	var hierarchyDepth = 0;

	// Cookie variables
	var cookieMenu;
	var cookieFavorites;
	var favoriteCategoriesArray = new Array();
	var SMNewsstand_CookieData



	function gatherMultipleCategoryData(categories) {
		for(var i=0;i<categories.length;i++) {
            alert("hi");
			document.write("<SC" + "RIPT LANGUAGE=\"JavaScript\" SRC=\"http://newsstand.yellowbrix.com/servlet/getNewsstand?product_id=" + categories[i].product_id + "&REFERER=" + window.top.location.hostname + window.top.location.pathname + "&file_name=" + categories[i].url + ".js&file_type=0\"></SC" + "RIPT>");
		}
	}

	function writeMultipleCategoryHeadlines(categories) {
		for(var i=0;i<categories.length;i++) {
			defineContentIndeces(i);
			subjectIndex = categories[i].subjectIndex;

			document.open();
			document.write(ns.multiCatHeadlines.preCategoryNameHTML + categories[i].name + ns.multiCatHeadlines.postCategoryNameHTML + ns.multiCatHeadlines.preHeadlinesHTML);
			document.close();

			writeHeadlines(i);

			document.open();
			document.write(ns.multiCatHeadlines.postHeadlinesHTML);
			document.close();
		}
	}





	////////////////////////////////////////////////////////////////////////////////////////////////////
	//                                                                                                //
	//  The following chunk of functions are for the creation, validation, and configuration of the   //
	//  Subject Objects. The subject objects hold information about a category such as the subject's  //
	//  parent in the hierarchy, an array of it's child subjects, the name of the JSRF file that      //
	//  that contains the info about all the articles. AKA a "content set set"                        //
	//                                                                                                //
	////////////////////////////////////////////////////////////////////////////////////////////////////

	// This function is the first of two that make up the core of the program. It creates subject objects.
	function addSubject(name,url,product_id) {
		this.name=name;
		this.url=url;
		this.product_id=product_id;
		this.parentSub=null;
		this.childSub=null;
		this.isCurrent=false;
		this.childCount=0;
		this.subjectIndex=subjectsCount;
		subjects[subjectsCount] = this;
		subjectsCount++;
	}

	// This function is the second of two that make up the core of the program. It lets you make subject objects, childs of other subject objects. 
	function addChild(parentObj,childObj) {
		if ( validateAddChild(parentObj,childObj) == true ) {
			if ( parentObj.childSub == null )  {
				parentObj.childSub = new Array();
			}
			parentObj.childSub[parentObj.childCount++] = childObj;
			childObj.parentSub = parentObj;
		} else {
			alert("The modification you have requested is not valid.\n\n" + childObj.name + " already exists above " + parentObj.name + " in your selected subject hierarchy.");
		}
	}

	// This function makes sure you don't create a circular tree. By having a subject be a child or grandchild of itself.
	function validateAddChild(parentObj,childObj) {
		if ( parentObj.parentSub == null ) {
			return true;
		}
		if ( parentObj.parentSub == childObj ) {
			return false;
		}
		return validateAddChild(parentObj.parentSub,childObj);
	}










	////////////////////////////////////////////////////////////////////////////////////////////////////
	//                                                                                                //
	//  The following chunk of functions create and write out the HTML for the navigation.            //
	//                                                                                                //
	////////////////////////////////////////////////////////////////////////////////////////////////////

	// This function takes a subject, and sets it as current, as well as it's parents all the way up tree.
	// It also finds out how many columns we need to span across, so the whole thing can be tabled, and fix wrapping issues.
	function flagCurrentCheckDepth(subject,hierarchyDepth) {
		if ( subject.childSub != null && hierarchyDepth == 0) {
			hierarchyDepth++;
		}
		subject.isCurrent = true;
		if ( subject.parentSub ) {
			hierarchyDepth++;
			hierarchyDepth=flagCurrentCheckDepth(subject.parentSub,hierarchyDepth);
		}
		return hierarchyDepth;
	}

	// This function loops through the subjects, and creates the menu.
	// When it encounters a subject with child subjects, it passes the subject to the createSubCategoryNavHTML function.
	function createCategoryNavHTML(subject) {
		for (var i=0;i<subject.childSub.length;i++) {
			document.write(createCategoryNavLinkHTML(subject.childSub[i],0));

			// See if this subject has any childSubs. If it does, print them out.
			if( subject.childSub[i].childSub!=null && subject.childSub[i].isCurrent ) {
				createSubCategoryNavHTML(subject.childSub[i].childSub,1);
			}
		}
	}

	// This function loops through a child's subjects, and creates the menu.
	// When it encounters a child subject with another level of child subjects below it,
	// it passes the subject to itself, and thus begins the recursion.
	function createSubCategoryNavHTML(childSub,indent) {
		for (var j=0;j<childSub.length;j++) {
			document.write(createCategoryNavLinkHTML(childSub[j],indent));
			// See if this childSub has any child trees. If it does, print them out.
			if( childSub[j].childSub!=null && childSub[j].isCurrent ) {
				indent++;
				createSubCategoryNavHTML(childSub[j].childSub,indent);
				indent--;
			}
		}
	}

	// This function actually concatinates the HTML for a link. Most of the code in it figures out what the
	// "current state" of the link is, and assigns a class to it. This allows full customization to the user.
	function createCategoryNavLinkHTML(subject,indent) {
		var html = "";
		html += "<TR>\n";

		if ( indent > 0 ) {
			html += "<TD COLSPAN=" + indent + "></TD>";
		}

		html += "<TD VALIGN=TOP>";
		if ( subject.childSub!=null ) {
			if ( subject.isCurrent ) {
				html += ns.categoryNav.currentParentBullet;
			} else {
				html += ns.categoryNav.parentBullet;
			}
		} else {
			if ( subject.isCurrent ) {
				html += ns.categoryNav.currentChildBullet;
			} else {
				html += ns.categoryNav.childBullet;
			}
		}
		html += "</TD>";

		className = "ns";
		if ( subject.subjectIndex == subjectIndex ) {
			className += "Current";
		}

		if ( subject.parentSub == menu || subject.parentSub == cookieMenu ) {
			var expanded = false;
			if (subject.childSub != null) {
				for (var i=0;i<subject.childSub.length;i++) {
					if ( subject.childSub[i].isCurrent ) {
						expanded = true;
					}
				}
			}
			if ( expanded ) {
				className += "CurrentTopLinkExpanded";
			} else {
				className += "TopLink";
			}
		} else if ( subject.childSub != null ) {
			var j;
			expanded = false;
			for (j=0;j<subject.childSub.length;j++) {
				if ( subject.childSub[j].isCurrent ) {
					expanded = true;
				}
			}
			if ( expanded ) {
				className += "CurrentSubParentLinkExpanded";
			} else {
				//className += "SubParentLink";
				className += "ns_text_small";
			}
		} else if ( subject.childSub == null ) {
			//className += "SubLink";
			className += "ns_text_small";
		}

		var colspan;
		colspan = hierarchyDepth - indent;
		linkColumnWidth = ns.categoryNav.width-((indent*ns.categoryNav.indentWidth)+ns.categoryNav.indentWidth);
		html += "<TD COLSPAN=\"" + colspan + "\" VALIGN=TOP WIDTH=" + linkColumnWidth + " BACKGROUND=\"images/x.gif\"><FONT FACE=\"verdana\" SIZE=1><A HREF=\"" + ns.headlinesTemplate;
		html += "?subject=" + subject.subjectIndex;
		html +=  "\" CLASS=\"" + className + "\"><span class=\"ns_text_small\">" + subject.name + "</A></FONT></TD>\n";
		html += "</TR>\n\n";

		return html;
	}
	
	// This function takes all of the user defined style sheet variables, and writes out the style sheet for the Category Nav.
	function createCategoryNavStyleHTML() {
		var html = "";
		html += "<STYLE>\n";
		html += ".nsTopLink { " + ns.categoryNav.nsTopLink + " }\n";
		html += ".nsCurrentTopLink { " + ns.categoryNav.nsCurrentTopLink + " }\n";
		html += ".nsCurrentTopLinkExpanded { " + ns.categoryNav.nsCurrentTopLinkExpanded + " }\n";
		html += ".nsSubLink { " + ns.categoryNav.nsSubLink + " }\n";
		html += ".nsCurrentSubLink { " + ns.categoryNav.nsCurrentSubLink + " }\n";
		html += ".nsSubParentLink { " + ns.categoryNav.nsSubParentLink + " }\n";
		html += ".nsCurrentSubParentLink { " + ns.categoryNav.nsCurrentSubParentLink + " }\n";
		html += ".nsCurrentSubParentLinkExpanded { " + ns.categoryNav.nsCurrentSubParentLinkExpanded + " }\n";
		html += "</STYLE>\n";
		return html;
	}

	// This function make it easier for the user to throw the navigation down on the page. Previously they would have had
	// had to run 5 lines of code, like this, they can run one function. This allows us, to change the function also. So if there
	// is every additional functionality, we don't have to bug the client about changing their code.
	function writeCategoryNav() {
		hierarchyDepth = flagCurrentCheckDepth(subjects[subjectIndex],hierarchyDepth);
		document.open();
		document.write(createCategoryNavStyleHTML());
		document.write("<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=" + ns.categoryNav.width + " BORDER=0>");
		if ( typeof cookieFavorites != "undefined" ) {
			createCategoryNavHTML(cookieMenu);
		}
		createCategoryNavHTML(menu);
		document.write("<TR><TD WIDTH=" + hierarchyDepth*ns.categoryNav.indentWidth + " COLSPAN=" + hierarchyDepth + "></TD>");
		document.write("<TD WIDTH=" + (ns.categoryNav.width-(hierarchyDepth*ns.categoryNav.indentWidth)) + "></TD></TR>");
		document.write("</TABLE>");
		document.close();
	}










	////////////////////////////////////////////////////////////////////////////////////////////////////
	//                                                                                                //
	//  The following chunk of functions perform routines that allow the UI to work. They are used    //
	//  to figure out global variables and perform routines some UI features. They are not bundled    //
	//  with the other group of functions that create UI features, because these functions do not     //
	//  actually write out HTML or display the UI features. These functions just make the UI work.    //
	//                                                                                                //
	////////////////////////////////////////////////////////////////////////////////////////////////////

	// This function retrieves values from the location string, and parses using using standard GET query syntax.
	function getParamValue(matchString,defaultValue) {
		var thisURL = window.location.toString();
		var value = defaultValue;
		if ( ( thisURL.indexOf("?") != -1 ) && ( thisURL.indexOf(matchString) != -1 ) && ( thisURL.charAt(thisURL.indexOf(matchString) + matchString.length) != "&" ) ) {
			start = thisURL.indexOf(matchString) + matchString.length;
			if ( thisURL.indexOf("&", start) > -1 ) {
				value = thisURL.substring(start,( thisURL.indexOf("&", start)));
			} else {
				value = thisURL.substring(start,thisURL.length);
			}
		}
		if ( value == "NaN" ) {
			value = devaultValue;
		}
		return value;
	}

	// This function gets the subjectIndex. If the subject chosen by the user, does not have a URL, it goes to the subject's
	// first child, and recursively continues till it finds a subject with a URL.
	function getSubjectIndex(chosenSubjectIndex) {
		if ( chosenSubjectIndex > subjects.length ) {
			chosenSubjectIndex = subjects.length-1;
		}

		if (subjects[chosenSubjectIndex].url == "") {
			subjectIndex = getSubjectIndex(subjects[chosenSubjectIndex].childSub[0].subjectIndex);
		} else {
			subjectIndex = chosenSubjectIndex;
		}

		return subjectIndex;
	}

	// This function, takes the index passed to the page, and figures out the indeces to begin and end writing out headlines.
	function defineContentIndeces(SMContentSetIndex) {
		if (typeof SMContentSet != "undefined") {
			if (typeof SMContentSetIndex == "undefined") {
				SMContentSetIndex = 0;
			}
			SMContentSetStartIndex = Number(getParamValue("SMContentSetStartIndex=",0));
			if ((SMContentSetStartIndex + ns.headlines.articlesPerPage) > SMContentSet[SMContentSetIndex].contents.length) {
				SMContentSetEndIndex = SMContentSet[SMContentSetIndex].contents.length;
			} else {
				SMContentSetEndIndex = SMContentSetStartIndex + ns.headlines.articlesPerPage;
			}
		}
	}

	// Because the summaries would get printed out on the page with all sorts of fun single and double quotes,
	// the function call to printSummarycould not be run inside of each individual link. So we run it here instead.
	function showSummary(SMContentSetIndex,ContentIndex) {
		if (typeof document.summaryApplet != "undefined") {
			if ( ns.summaryApplet.showTitle == "true" ) {
				var title = SMContentSet[SMContentSetIndex].contents[ContentIndex].article.title;
			} else {
				var title = "";
			}
			document.summaryApplet.printSummary(title,SMContentSet[SMContentSetIndex].contents[ContentIndex].article.core.docAbstract,prettyDate(SMContentSet[SMContentSetIndex].contents[ContentIndex].article.metadata.documentMetadata.publisherReleaseDate),SMContentSet[SMContentSetIndex].contents[ContentIndex].article.metadata.publicationMetadata.publicationName,"None");
		}
	}










	////////////////////////////////////////////////////////////////////////////////////////////////////
	//                                                                                                //
	//  The following chunk of functions perform routines that create the HTML for some UI features.  //
	//  At the time that this comment was originally written, those features included an applet to    //
	//  display summaries for each headline, navigation to crop the amount of headlines per page,     //
	//  and a navigable display of the current category.                                              //
	//                                                                                                //
	////////////////////////////////////////////////////////////////////////////////////////////////////

	// This function takes all of the user defined applet parameters, and writes out the applet HTML code.
	function writeSummaryApplet() {
		document.open();
		document.write("<APPLET CODEBASE=\".\" CODE=\"summaryDisplay.class\" NAME=\"summaryApplet\" WIDTH=" + ns.summaryApplet.width + " HEIGHT=" + ns.summaryApplet.height + " HSPACE=0 VSPACE=0>\n");
		document.write("<PARAM NAME=\"totalWidth\" VALUE=\"" + ns.summaryApplet.width + "\">\n");
		document.write("<PARAM NAME=\"totalHeight\" VALUE=\"" + ns.summaryApplet.height + "\">\n");
		document.write("<PARAM NAME=\"titleFont\" VALUE=\"" + ns.summaryApplet.titleFont + "\">\n");
		document.write("<PARAM NAME=\"titleSize\" VALUE=\"" + ns.summaryApplet.titleSize + "\">\n");
		document.write("<PARAM NAME=\"titleColor\" VALUE=\"" + ns.summaryApplet.titleColor + "\">\n");
		document.write("<PARAM NAME=\"titleColorRGB\" VALUE=\"" + ns.summaryApplet.titleColorRGB + "\">\n");
		document.write("<PARAM NAME=\"titleText\" VALUE=\"" + ns.summaryApplet.titleText + "\">\n");
		document.write("<PARAM NAME=\"summaryFont\" VALUE=\"" + ns.summaryApplet.summaryFont + "\">\n");
		document.write("<PARAM NAME=\"summarySize\" VALUE=\"" + ns.summaryApplet.summarySize + "\">\n");
		document.write("<PARAM NAME=\"summaryColor\" VALUE=\"" + ns.summaryApplet.summaryColor + "\">\n");
		document.write("<PARAM NAME=\"summaryColorRGB\" VALUE=\"" + ns.summaryApplet.summaryColorRGB + "\">\n");
		document.write("<PARAM NAME=\"summaryText\" VALUE=\"" + ns.summaryApplet.summaryText + "\">\n");
		document.write("<PARAM NAME=\"providerFont\" VALUE=\"" + ns.summaryApplet.providerFont + "\">\n");
		document.write("<PARAM NAME=\"providerSize\" VALUE=\"" + ns.summaryApplet.providerSize + "\">\n");
		document.write("<PARAM NAME=\"providerColor\" VALUE=\"" + ns.summaryApplet.providerColor + "\">\n");
		document.write("<PARAM NAME=\"providerColorRGB\" VALUE=\"" + ns.summaryApplet.providerColorRGB + "\">\n");
		document.write("<PARAM NAME=\"providerText\" VALUE=\"" + ns.summaryApplet.providerText + "\">\n");
		document.write("<PARAM NAME=\"showproviderheading\" VALUE=\"" + ns.summaryApplet.showProviderHeading + "\">\n");
		document.write("<PARAM NAME=\"dateFont\" VALUE=\"" + ns.summaryApplet.dateFont + "\">\n");
		document.write("<PARAM NAME=\"dateSize\" VALUE=\"" + ns.summaryApplet.dateSize + "\">\n");
		document.write("<PARAM NAME=\"dateColor\" VALUE=\"" + ns.summaryApplet.dateColor + "\">\n");
		document.write("<PARAM NAME=\"dateColorRGB\" VALUE=\"" + ns.summaryApplet.dateColorRGB + "\">\n");
		document.write("<PARAM NAME=\"dateText\" VALUE=\"" + ns.summaryApplet.dateText + "\">\n");
		document.write("<PARAM NAME=\"showdateheading\" VALUE=\"" + ns.summaryApplet.showDateHeading + "\">\n");
		document.write("<PARAM NAME=\"backgroundImage\" VALUE=\"" + ns.summaryApplet.backgroundImage + "\">\n");
		document.write("<PARAM NAME=\"backgroundColor\" VALUE=\"" + ns.summaryApplet.backgroundColor + "\">\n");
		document.write("<PARAM NAME=\"backgroundColorRGB\" VALUE=\"" + ns.summaryApplet.backgroundColorRGB + "\">\n");
		document.write("<PARAM NAME=\"borderColor\" VALUE=\"" + ns.summaryApplet.borderColor + "\">\n");
		document.write("<PARAM NAME=\"borderColorRGB\" VALUE=\"" + ns.summaryApplet.borderColorRGB + "\">\n");
		document.write("</APPLET>\n");
		document.close();
	}







	function writeSummaryAppletTest() {
		document.open();
		//document.write("<APPLET CODEBASE=\".\" CODE=\"summaryDisplay.class\" NAME=\"summaryApplet\" WIDTH=" + ns.summaryApplet.width + " HEIGHT=" + ns.summaryApplet.height + " HSPACE=0 VSPACE=0>\n");

		document.write("test---" + ns.summaryApplet.width + "<br>\n");
		document.write("test---" + ns.summaryApplet.height + "<br>\n");
		document.write("test---" + ns.summaryApplet.titleFont + "<br>\n");
		document.write("test---" + ns.summaryApplet.titleSize + "<br>\n");
		document.write("test---" + ns.summaryApplet.titleColor + "<br>\n");
		document.write("test---" + ns.summaryApplet.titleColorRGB + "<br>\n");
		document.write("titleText---" + ns.summaryApplet.titleText + "<br>\n");
		document.write("summaryText---" + ns.summaryApplet.summaryText + "<br>\n");
		document.write("providerText---" + ns.summaryApplet.providerText + "<br>\n");
		document.write("showProviderHeading---" + ns.summaryApplet.showProviderHeading + "<br>\n");
		document.write("dateText---" + ns.summaryApplet.dateText + "<br>\n");
		document.write("showDateHeading---" + ns.summaryApplet.showDateHeading + "<br>\n");
		

	
		document.write("<PARAM NAME=\"titleColor\" VALUE=\"" + ns.summaryApplet.titleColor + "\">\n");
		document.write("<PARAM NAME=\"titleColorRGB\" VALUE=\"" + ns.summaryApplet.titleColorRGB + "\">\n");
		document.write("<PARAM NAME=\"titleText\" VALUE=\"" + ns.summaryApplet.titleText + "\">\n");
		document.write("<PARAM NAME=\"summaryFont\" VALUE=\"" + ns.summaryApplet.summaryFont + "\">\n");
		document.write("<PARAM NAME=\"summarySize\" VALUE=\"" + ns.summaryApplet.summarySize + "\">\n");
		document.write("<PARAM NAME=\"summaryColor\" VALUE=\"" + ns.summaryApplet.summaryColor + "\">\n");
		document.write("<PARAM NAME=\"summaryColorRGB\" VALUE=\"" + ns.summaryApplet.summaryColorRGB + "\">\n");
		document.write("<PARAM NAME=\"summaryText\" VALUE=\"" + ns.summaryApplet.summaryText + "\">\n");
		document.write("<PARAM NAME=\"providerFont\" VALUE=\"" + ns.summaryApplet.providerFont + "\">\n");
		document.write("<PARAM NAME=\"providerSize\" VALUE=\"" + ns.summaryApplet.providerSize + "\">\n");
		document.write("<PARAM NAME=\"providerColor\" VALUE=\"" + ns.summaryApplet.providerColor + "\">\n");
		document.write("<PARAM NAME=\"providerColorRGB\" VALUE=\"" + ns.summaryApplet.providerColorRGB + "\">\n");
		document.write("<PARAM NAME=\"providerText\" VALUE=\"" + ns.summaryApplet.providerText + "\">\n");
		document.write("<PARAM NAME=\"showproviderheading\" VALUE=\"" + ns.summaryApplet.showProviderHeading + "\">\n");
		document.write("<PARAM NAME=\"dateFont\" VALUE=\"" + ns.summaryApplet.dateFont + "\">\n");
		document.write("<PARAM NAME=\"dateSize\" VALUE=\"" + ns.summaryApplet.dateSize + "\">\n");
		document.write("<PARAM NAME=\"dateColor\" VALUE=\"" + ns.summaryApplet.dateColor + "\">\n");
		document.write("<PARAM NAME=\"dateColorRGB\" VALUE=\"" + ns.summaryApplet.dateColorRGB + "\">\n");
		document.write("<PARAM NAME=\"dateText\" VALUE=\"" + ns.summaryApplet.dateText + "\">\n");
		document.write("<PARAM NAME=\"showdateheading\" VALUE=\"" + ns.summaryApplet.showDateHeading + "\">\n");
		document.write("<PARAM NAME=\"backgroundImage\" VALUE=\"" + ns.summaryApplet.backgroundImage + "\">\n");
		document.write("<PARAM NAME=\"backgroundColor\" VALUE=\"" + ns.summaryApplet.backgroundColor + "\">\n");
		document.write("<PARAM NAME=\"backgroundColorRGB\" VALUE=\"" + ns.summaryApplet.backgroundColorRGB + "\">\n");
		document.write("<PARAM NAME=\"borderColor\" VALUE=\"" + ns.summaryApplet.borderColor + "\">\n");
		document.write("<PARAM NAME=\"borderColorRGB\" VALUE=\"" + ns.summaryApplet.borderColorRGB + "\">\n");
		//document.write("</APPLET>\n");
		document.close();
	}








	// This function creates the HTML to display the current subject location in a line starting from the top level.
	function createCurrentCategoryHTML(curSubject) {
		if(curSubject != menu && curSubject != cookieMenu) {
			document.write("<A HREF=\"" + ns.headlinesTemplate + "?subject=" +  curSubject.subjectIndex + "\" CLASS=\"nsCurrentCategoryLinkStyle\">" + curSubject.name + "</A>");
			if ( curSubject.childSub != null ) {
				document.write(ns.currentCategory.delimeter);
			}
		}

		if ( curSubject.childSub != null ) {
			for (var i = 0; i < curSubject.childCount; i++) {
				if (curSubject.childSub[i].isCurrent) {
					createCurrentCategoryHTML(curSubject.childSub[i]);
				}
			}
		}
	}

	// This function takes all of the user defined style sheet variables, and writes out the style sheet for the Current Category.
	function createCurrentCategoryStyleHTML() {
		var html = "";
		html += "<STYLE>\n";
		html += ".nsCurrentCategoryLinkStyle { " + ns.currentCategory.linkStyle + " }\n";
		html += "</STYLE>\n";
		return html;
	}

	// This function writes out the Current Category and the style sheet.
	function writeCurrentCategory() {
		if ( hierarchyDepth == 0 ) {
			flagCurrentCheckDepth(subjects[subjectIndex],hierarchyDepth);
		}
		document.open();
		document.write(createCurrentCategoryStyleHTML());
		if ( subjects[subjectIndex].parentSub == cookieFavorites ) {
			createCurrentCategoryHTML(cookieMenu);
		} else {
			createCurrentCategoryHTML(menu);
		}
		document.close();
	}

	// This function writes out the Previous/Next Navigation
	function writePrevNextNav() {
		var html = "";
		if (typeof SMContentSet != "undefined") {
			html += "<FONT COLOR=" + ns.prevNextNav.nonClickableLinkColor + ">";
			if (SMContentSetStartIndex > 0 ) {
				html += "<A HREF=\"" + ns.headlinesTemplate + "?SMContentSetStartIndex=" + (((SMContentSetStartIndex - ns.headlines.articlesPerPage) < 0) ? 0 : (SMContentSetStartIndex - ns.headlines.articlesPerPage)) + "&subject=" + subjectIndex + "\" CLASS=\"text_small\">";
				html += ns.prevNextNav.prevLinkClickable;
				html += "</A>";
			} else if ( SMChosenContent > 0 ) {
				html += "<A HREF=\"" + ns.articleTemplate + "?SMContentIndex=" + (SMChosenContent-1) + "&SMContentSet=" + SMChosenContentSet + "&subject=" + subjectIndex + "\" CLASS=\"text_small\">";
				html += ns.prevNextNav.prevLinkClickable;
				html += "</A>";
			} else {
				html += "<span class=\"text_small\">" + ns.prevNextNav.prevLinkNonClickable;
			}
			html += "<A HREF=\"" + ns.headlinesTemplate + "?SMContentSetStartIndex=0&subject=" + subjectIndex + "\" CLASS=\"text_small\">";
			html += ns.prevNextNav.homeLink;
			html += "</A>";
			if (SMContentSetEndIndex < SMContentSet[0].contents.length) {
				html += "<A HREF=\"" + ns.headlinesTemplate + "?SMContentSetStartIndex=" + (SMContentSetStartIndex + (SMContentSetEndIndex - SMContentSetStartIndex)) + "&subject=" + subjectIndex + "\" CLASS=\"text_small\">";
				html += ns.prevNextNav.nextLinkClickable;
				html += "</A>";
			} else if ( SMChosenContent != -1 && SMChosenContent < (SMContentSet[SMChosenContentSet].contents.length - 1) ) {
				html += "<A HREF=\"" + ns.articleTemplate + "?SMContentIndex=" + (SMChosenContent+1) + "&SMContentSet=" + SMChosenContentSet + "&subject=" + subjectIndex + "\" CLASS=\"text_small\">";
				html += ns.prevNextNav.nextLinkClickable;
				html += "</A>";
			} else {
				html += "<span class=\"text_small\">" + ns.prevNextNav.nextLinkNonClickable;
			}
			html += "</FONT>";

			document.open();
			document.write(createPrevNextNavStyleHTML());
			document.write(html);
			document.close();
		}
	}

	// This function takes all of the user defined style sheet variables, and writes out the style sheet for the Previous/Next navigation.
	function createPrevNextNavStyleHTML() {
		var html = "";
		html += "<STYLE>\n";
		html += ".nsNextLinkStyle { " + ns.prevNextNav.nextLinkStyle + " }\n";
		html += ".nsPrevLinkStyle { " + ns.prevNextNav.prevLinkStyle + " }\n";
		html += ".nsHomeLinkStyle { " + ns.prevNextNav.homeLinkStyle + " }\n";
		html += "</STYLE>\n";
		return html;
	}

	// This function writes out the headlines.
	function writeHeadlines(SMContentSetIndex) {
		if (typeof SMContentSet != "undefined") {
			if (typeof SMContentSetIndex == "undefined") {
				SMContentSetIndex = 0;
			}
			document.open();
			document.write(createHeadlinesStyleHTML());
			for (var j = SMContentSetStartIndex; j < SMContentSetEndIndex; j++) {
				document.write(ns.headlines.preLinkHTML);
				document.write("<A HREF=\"");
				document.write(ns.articleTemplate + "?SMContentIndex=" + j + "&SMContentSet=0&subject=" + subjectIndex);
				document.write("\" onMouseOver=\"showSummary(" + SMContentSetIndex + "," + j + ");\" CLASS=\"nsHeadlinesLink\">");
				document.write(SMContentSet[SMContentSetIndex].contents[j].article.title);
				document.write("</A>");
				document.write(ns.headlines.postLinkHTML);
				document.write(ns.headlines.preProviderDateHTML);

				document.write(SMContentSet[SMContentSetIndex].contents[j].article.metadata.publicationMetadata.publicationName);
				document.write(", ");
				document.write(prettyDate(SMContentSet[SMContentSetIndex].contents[j].article.metadata.documentMetadata.publisherReleaseDate));
				document.write(ns.headlines.postProviderDateHTML);
			}
			document.close();
		} else {
			document.open();
			document.write(servlet_error);
			document.close();
		}
	}







///////////////////////////////////////////////////////////		NEW FUNCTIONS		ADDED 09-24-01		START


	// hide all abstracts
	function hideAllAbstracts() {
		for (var j = SMContentSetStartIndex; j < SMContentSetEndIndex; j++) {
			var nextLayer = "l" + j;
			if (navigator.appName == "Netscape")
			{
				var ual=navigator.userAgent.toLowerCase();
				var is_gecko = (ual.indexOf('gecko') != -1);
				if (is_gecko)
				{
					document.getElementById(nextLayer).style.visibility = "hidden";
				}
				else
				{
					document.layers[nextLayer].visibility = "hidden";
				}
			}
			else
			{
				document.all[nextLayer].style.visibility = "hidden";
			}
		}
	}

	// show abstract
	function showAbstract(layerId) {
		var nextLayer = "l" + layerId;
		if (navigator.appName == "Netscape")
		{
			var ual=navigator.userAgent.toLowerCase();
			var is_gecko = (ual.indexOf('gecko') != -1);
			if (is_gecko)
			{
				var x = document.getElementById("pos1").style.left;
				var y = document.getElementById("pos1").style.top;
				//var myElement = document.getElementById("pos1");
				//var x = myElement.style.left;
				//var y = myElement.style.top;
				document.getElementById(nextLayer).style.left= x;
				document.getElementById(nextLayer).style.top= y;
				//document.getElementById(nextLayer).style.visibility = "visible";
			}
			else
			{
				var x = document.layers['pos1'].pageX;
				var y = document.layers['pos1'].pageY;
				document.layers[nextLayer].left = x;
				document.layers[nextLayer].top = y;
				document.layers[nextLayer].visibility = "show";
			}
		}
		else
		{
			var x = document.all['pos1'].offsetLeft;
			var y = document.all['pos1'].offsetTop;
			document.all[nextLayer].style.pixelLeft = x;
			document.all[nextLayer].style.pixelTop = y;
			document.all[nextLayer].style.visibility = "visible";
			//alert ('zzz');
			//swapPhoto(0,0,false,2);
		}
	}

	// write DHTML headlines
	function writeHeadlinesDHTML(SMContentSetIndex) {
		if (typeof SMContentSet != "undefined") {
			if (typeof SMContentSetIndex == "undefined") {
				SMContentSetIndex = 0;
			}
			document.open();
			document.write(createHeadlinesStyleHTML());
			for (var j = SMContentSetStartIndex; j < SMContentSetEndIndex; j++) {
				document.write(ns.headlines.preLinkHTML);
				document.write("<A HREF=\"");
				document.write(ns.articleTemplate + "?SMContentIndex=" + j + "&SMContentSet=0&subject=" + subjectIndex);
				document.write("\" onMouseOver=\"hideAllAbstracts();showAbstract('" + j + "');\" onMouseOut=\"hideAllAbstracts();\" CLASS=\"ns_text_normal\">");
				document.write(SMContentSet[SMContentSetIndex].contents[j].article.title);
				document.write("</A>");
				document.write(ns.headlines.postLinkHTML);
				document.write(ns.headlines.preProviderDateHTML);
				document.write("<span class=\"ns_text_credit_small\">");	document.write(SMContentSet[SMContentSetIndex].contents[j].article.metadata.publicationMetadata.publicationName);
				document.write(", ");
				document.write(prettyDate(SMContentSet[SMContentSetIndex].contents[j].article.metadata.documentMetadata.publisherReleaseDate));
				document.write("</span>");
				document.write(ns.headlines.postProviderDateHTML);
			}
			document.close();
		} else {
			document.open();
			document.write(servlet_error);
			document.close();
		}
	}

	// write css info for abstract layers
	function writeCssInfo(SMContentSetIndex) {
		if (typeof SMContentSet != "undefined") {
			if (typeof SMContentSetIndex == "undefined") {
				SMContentSetIndex = 0;
			}
			document.open();
			document.write("<style>");
			document.write("	#pos1 { position:relative;width:10px;height:10px;visibility:hidden; }");
			for (var j = SMContentSetStartIndex; j < SMContentSetEndIndex; j++) {
				document.write("	#l" + j + " { position:absolute;width:" + ns.abstractLayerWidth + "px;height:" + ns.abstractLayerHeight + "px;left:0px;top:0px;visibility:hidden; }");
			}
			document.write("</style>");
			document.close();
		} else {
			document.open();
			document.write(servlet_error);
			document.close();
		}
	}

	// write headline abstracts
	function writeHeadlineAbstracts(SMContentSetIndex,abstractTextLength) {
		if (typeof SMContentSet != "undefined") {
			if (typeof SMContentSetIndex == "undefined") {
				SMContentSetIndex = 0;
			}
			document.open();
			document.write ("<div id=\"pos1\"></div>\n");
			document.write(createHeadlinesStyleHTML());
			for (var j = SMContentSetStartIndex; j < SMContentSetEndIndex; j++) {
				document.write("<div id=\"l" + j + "\" class=\"text_small\">");
				var abstract_text = SMContentSet[SMContentSetIndex].contents[j].article.core.docAbstract;
				abstract_text = abstract_text.substr(0,abstractTextLength);
				abstract_text = abstract_text+ "...";
				document.write(abstract_text);
				document.write("<br><br>");
			
				document.write("<font color=\"#666666\">");
				document.write("<i>");	document.write(prettyDate(SMContentSet[SMContentSetIndex].contents[j].article.metadata.documentMetadata.publisherReleaseDate));
				document.write("</i>");
				document.write("<br><br>");
				document.write(SMContentSet[SMContentSetIndex].contents[j].article.metadata.publicationMetadata.publicationName);	
				document.write("</font>");
				document.write("</div>\n");
			}
			document.close();
		} else {
			document.open();
			document.write(servlet_error);
			document.close();
		}
	}


///////////////////////////////////////////////////////////		NEW FUNCTIONS		ADDED 09-24-01		END






	// This functions writes out an article.
	function writeArticle() {
		if (typeof SMContentSet != "undefined") {
			if (SMChosenContent >= 0) {
			//alert(SMContentSet[SMChosenContentSet].contents[SMChosenContent].article.body=="");
				document.open();
				document.write('<span class=text_normal>');
				document.write(ns.article.preHeadlineHTML + SMContentSet[SMChosenContentSet].contents[SMChosenContent].article.title + ns.article.postHeadlineHTML);
				//document.write("<BR><SCR"+"IPT LANGUAGE=\"JavaScript1.2\">displayPhoto(0,0,true,1);</SCR"+"IPT>");
				document.write(ns.article.preBodyHTML + SMContentSet[SMChosenContentSet].contents[SMChosenContent].article.body + ns.article.postBodyHTML);
				document.write(ns.article.preCopyrightHTML + SMContentSet[SMChosenContentSet].contents[SMChosenContent].article.core.copyright + ns.article.postCopyrightHTML);
				document.write('</span>');
				document.close();
			}
		} else {
				document.open();
				document.write(servlet_error);
				document.close();
		}
	}

	// This functions writes out an article.		TEST		TEST		TEST
	function writeArticleTest() {
		if (typeof SMContentSet != "undefined") {
			if (SMChosenContent >= 0) {
			//alert(SMContentSet[SMChosenContentSet].contents[SMChosenContent].article.body=="");
				document.open();
				document.write(ns.article.preHeadlineHTML + SMContentSet[SMChosenContentSet].contents[SMChosenContent].article.title + ns.article.postHeadlineHTML);
				//document.write("<BR><SCR"+"IPT LANGUAGE=\"JavaScript1.2\">displayPhoto(0,0,true,1);</SCR"+"IPT>");
				document.write(ns.article.preBodyHTML + SMContentSet[SMChosenContentSet].contents[SMChosenContent].article.body + ns.article.postBodyHTML);
				document.write(ns.article.preCopyrightHTML + SMContentSet[SMChosenContentSet].contents[SMChosenContent].article.core.copyright + ns.article.postCopyrightHTML);
				document.close();
			}
		} else {
				document.open();
				document.write(servlet_error);
				document.close();
		}
	}


	//This function writes out the first photo that it finds.
	function displayFirstPhoto(showCaption, scale ){
		contentSetNum=0;
		contentNum=0;	
		FoundPhoto=false;

		while((FoundPhoto == false) && (contentNum < 20)){
			if(typeof (SMContentSet[contentSetNum].contents[contentNum]) !='undefined'){
				if(typeof (SMContentSet[contentSetNum].contents[contentNum].article.photo) !='undefined'){
					if(typeof (SMContentSet[contentSetNum].contents[contentNum].article.photo.url) !='undefined'){
						//alert(contentSetNum);
						//
							//alert(contentNum);
						//contentNum=1;
						//v=prompt("t","url"+SMContentSet[contentSetNum].contents[contentNum].article.photo.url);
						if(SMContentSet[contentSetNum].contents[contentNum].article.photo.url !=''){

							//alert("here"+ SMContentSet[contentSetNum].contents[contentNum].article.photo.url );
							displayPhoto(contentSetNum, contentNum, showCaption, scale );
							FoundPhoto=true;
						}
			 		}
				}		
		 	}
		contentNum=contentNum+1;
		//alert(FoundPhoto+", "+contentNum);

		}
 	}

	//This function writes out the photo- if it exists.
	function displayPhoto(contentSetNum, contentNum, showCaption, scale ){
		
		if ((contentNum>=0)&& (contentSetNum>=0)){ //this makes sure that correct parameters are passed
			//alert(contentNum+","+contentSetNum);
			//alert( typeof SMContentSet[contentSetNum].contents[contentNum].article.photo);
			if(typeof (SMContentSet[contentSetNum].contents[contentNum].article.photo) !='undefined'){
				if(typeof (SMContentSet[contentSetNum].contents[contentNum].article.photo.url) !='undefined'){
					if((SMContentSet[contentSetNum].contents[contentNum].article.photo.url) !=''){

						//v=prompt("t",SMContentSet[contentSetNum].contents[contentNum].article.photo.url);
						//alert("in photo"+contentNum+","+contentSetNum)
						document.write("<A HREF=\"" + ns.articleTemplate + "?SMContentIndex=" + contentNum + "&SMContentSet="+contentSetNum+"&subject=" + subjectIndex + "\" CLASS=\"nsRelatedHeadlinesLink\">");
						document.write("<img src="+SMContentSet[contentSetNum].contents[contentNum].article.photo.url+" width=\'" + (SMContentSet[contentSetNum].contents[contentNum].article.photo.width / scale) + "\' height=\'" +
		 					(SMContentSet[contentSetNum].contents[contentNum].article.photo.height / scale) + "\' border=\'0\'; alt=\'"+SMContentSet[contentSetNum].contents[contentNum].article.photo.alt+"\'/>");
						document.write("</A>");

						if (showCaption){
							document.write("<TABLE width="+(ns.article.photowidth - 10)+"><TR><TD><span class=\"text_small\">");
	 						document.write(ns.article.prePhotoHTML);
	 						document.write(SMContentSet[contentSetNum].contents[contentNum].article.photo.caption);
	 						document.write(ns.article.postPhotoHTML);
	 						document.write("</span></TD></TR></TABLE>");
	 					}
	 				}
		 			//	alert("out")
		 		}
		 	}
 		}
	}

	//This function writes out the photo- if it exists.
	function swapPhoto(contentSetNum, contentNum, showCaption, scale ){
		
		if ((contentNum>=0)&& (contentSetNum>=0)){ //this makes sure that correct parameters are passed
			//alert(contentNum+","+contentSetNum);
			//alert( typeof SMContentSet[contentSetNum].contents[contentNum].article.photo);
			if(typeof (SMContentSet[contentSetNum].contents[contentNum].article.photo) !='undefined'){
				if(typeof (SMContentSet[contentSetNum].contents[contentNum].article.photo.url) !='undefined'){
					if((SMContentSet[contentSetNum].contents[contentNum].article.photo.url) !=''){

						//v=prompt("t",SMContentSet[contentSetNum].contents[contentNum].article.photo.url);
						//alert("in photo"+contentNum+","+contentSetNum)
//						document.write("<A HREF=\"" + ns.articleTemplate + "?SMContentIndex=" + contentNum + "&SMContentSet="+contentSetNum+"&subject=" + subjectIndex + "\" CLASS=\"nsRelatedHeadlinesLink\">");
//						document.write("<img src="+SMContentSet[contentSetNum].contents[contentNum].article.photo.url+"width=\'" + (SMContentSet[contentSetNum].contents[contentNum].article.photo.width / scale) + "\height=\'" + (SMContentSet[contentSetNum].contents[contentNum].article.photo.height / scale) + "\'border=\'0\'; alt=\'"+SMContentSet[contentSetNum].contents[contentNum].article.photo.alt+"\'/>");

						document.images[0].src = eval (SMContentSet[contentSetNum].contents[contentNum].article.photo.url);

//						document.write("</A>");

						if (showCaption){
							document.write("<TABLE width="+(ns.article.photowidth - 10)+"><TR><TD>");
	 						document.write(ns.article.prePhotoHTML);
	 						document.write(SMContentSet[contentSetNum].contents[contentNum].article.photo.caption);
	 						document.write(ns.article.postPhotoHTML);
	 						document.write("</TD></TR></TABLE>");
	 					}
	 				}
		 			//	alert("out")
		 		}
		 	}
 		}
	}

	// This function takes all of the user defined style sheet variables, and writes out the style sheet for the Headline list.
	function createHeadlinesStyleHTML() {
		var html = "";
		html += "<STYLE>\n";
		html += ".nsHeadlinesLink { " + ns.headlines.linkStyle + " }\n";
		html += "</STYLE>\n";
		return html;
	}

	// This function writes out related headlines for the current subject.
	function writeRelatedHeadlines() {
		if (typeof SMContentSet != "undefined") {
			document.open();
			document.write(createRelatedHeadlinesStyleHTML());
			if ( (SMContentSet[SMChosenContentSet].contents.length-SMChosenContent) > ns.relatedHeadlines.articlesPerPage ) {
				var SMContentStartIndex = SMChosenContent + 1;
				var SMContentEndIndex = SMContentStartIndex + ns.relatedHeadlines.articlesPerPage;
			} else if ( SMContentSet[SMChosenContentSet].contents.length < ns.relatedHeadlines.articlesPerPage ) {
				var SMContentStartIndex = 0;
				var SMContentEndIndex = SMContentSet[SMChosenContentSet].contents.length;
				var showAllHeadlines = 1;
			} else {
				var SMContentStartIndex = SMContentSet[SMChosenContentSet].contents.length - ns.relatedHeadlines.articlesPerPage - 1;
				if ( SMContentStartIndex == -1 ) {
					SMContentStartIndex = 0;
				}
				var SMContentEndIndex = SMContentSet[SMChosenContentSet].contents.length;
			}

			for (var j = SMContentStartIndex; j < SMContentEndIndex; j++) {
				if ( j != SMChosenContent || showAllHeadlines == 1 ) {
					document.write(ns.relatedHeadlines.preLinkHTML);
					document.write("<A HREF=\"" + ns.articleTemplate + "?SMContentIndex=" + j + "&SMContentSet=0&subject=" + subjectIndex + "\" CLASS=\"text_small\">");
					document.write(SMContentSet[0].contents[j].article.title);
					document.write("<br></A>");
					document.write(ns.relatedHeadlines.postLinkHTML);
				}
			}
			document.close();
		}
	}

	// This function takes all of the user defined style sheet variables, and writes out the style sheet for the Headline list.
	function createRelatedHeadlinesStyleHTML() {
		var html = "";
		html += "<STYLE>\n";
		html += ".nsRelatedHeadlinesLink { " + ns.relatedHeadlines.linkStyle + " }\n";
		html += "</STYLE>\n";
		return html;
	}










function Cookie(document, name, hours, path, domain, secure) {
this.$document = document;
this.$name = name;
if (hours)
	this.$expiration = new Date((new Date()).getTime() + hours*360000);
else this.$expiration = null;
if (path) 
	this.$path = path;
else this.$path = null;
if (domain) 
	this.$domain = domain;
else this.$domain = null;
if (secure)
	this.$secure = true;
else this.$secure = false;}

function _Cookie_store() {
var cookieval = "";
for (var prop in this) {
	if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
		continue;
	if (cookieval != "")
		cookieval += '&';
	cookieval += prop + ':' + escape(this[prop]);
	}
var cookie = this.$name + '=' + cookieval;
if (this.$expiration)
	cookie += '; expires=' + this.$expiration.toGMTString();
if (this.$path)
	cookie += '; path=' + this.$path;
if (this.$domain)
	cookie += '; domain=' + this.$domain;
if (this.$secure)
	cookie += '; secure';
this.$document.cookie = cookie;
}

function _Cookie_load() {
var allcookies = this.$document.cookie;
if (allcookies == "")
	return false;
var start = allcookies.indexOf(this.$name + '=');
if (start == -1)
	return false;
start += this.$name.length + 1;
var end = allcookies.indexOf(';', start);
if (end == -1)
	end = allcookies.length;
var cookieval = allcookies.substring(start, end);
var a = cookieval.split('&');
for (var i=0; i < a.length; i++)
	a[i] = a[i].split(':');
for (var i=0; i < a.length; i++) {
	this[a[i][0]] = unescape(a[i][1]); }
return true;}

function _Cookie_remove() {
var cookie;
cookie = this.$name + '=';
if (this.$path)
	cookie += '; path=' + this.$path;
if (this.$domain)
	cookie += '; domain=' + this.$domain;
cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
this.$document.cookie = cookie;}

new Cookie();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;














	function initializeCookieData() {
		SMNewsstand_CookieData = new Cookie(document, "SMNewsstand_CookieData", 8760);
		SMNewsstand_CookieData.load();
	}

	function getFavoriteCategories() {
		if ( typeof SMNewsstand_CookieData.favoriteCategoriesList != "undefined" && SMNewsstand_CookieData.favoriteCategoriesList != "undefined" && SMNewsstand_CookieData.favoriteCategoriesList != "" ) {
			favoriteCategoriesArray = SMNewsstand_CookieData.favoriteCategoriesList.split(",");
		}

		if ( favoriteCategoriesArray.length > 0 ) {
			cookieMenu = new addSubject("Cookie Menu","","0");
			cookieFavorites = new addSubject("My Favorites","","0");
			addChild(cookieMenu,cookieFavorites);

			for (var c=0;c<favoriteCategoriesArray.length;c++) {
				for (var i=0;i<subjects.length;i++) {
					if ( subjects[i].product_id == favoriteCategoriesArray[c] && subjects[i].parentSub != cookieFavorites ) {
						subjects[subjects.length] = new addSubject(subjects[i].name,subjects[i].url,subjects[i].product_id);
						addChild(cookieFavorites,subjects[subjects.length-1]);
					}
				}
			}
			defaultSubjectIndex = cookieFavorites.subjectIndex;
		}
	}

	function getCookieResultsPage() {
		tempSMContentSetStartIndex = Number(getParamValue("SMContentSetStartIndex=",0));
		tempSMContentIndex = Number(getParamValue("SMContentIndex=",0));
		tempSMContentSet = Number(getParamValue("SMContentSet=",0));
		currentURL = window.location.toString();

		if ( currentURL.indexOf(ns.headlinesTemplate) != -1 ) {
			destinationURL = ns.headlinesTemplate + "?SMContentSetStartIndex=" + tempSMContentSetStartIndex;
		} else {
			destinationURL = ns.articleTemplate + "?SMContentIndex=" + tempSMContentIndex + "&SMContentSet=" + tempSMContentSet;
		}

		return destinationURL;
	}

	function addFavoriteCategory(product_id) {
		favoriteCategoriesArray[favoriteCategoriesArray.length] = product_id;
		SMNewsstand_CookieData.favoriteCategoriesList = favoriteCategoriesArray.join(",");
		SMNewsstand_CookieData.store();
		document.location = getCookieResultsPage() + "&subject=" + subjects.length;
	}

	function deleteFavoriteCategory(product_id) {
		newFavoriteCategoriesArray = new Array();
		for (var i=0;i<favoriteCategoriesArray.length;i++) {
			if ( favoriteCategoriesArray[i] != product_id ) {
				newFavoriteCategoriesArray[newFavoriteCategoriesArray.length] = favoriteCategoriesArray[i];
			}
		}

		for (var i=0;i<subjects.length;i++) {
			if ( subjects[i].product_id == product_id && subjects[i].parentSub != cookieFavorites ) {
				tempSubjectIndex = subjects[i].subjectIndex;
			}
		}

		SMNewsstand_CookieData.favoriteCategoriesList = newFavoriteCategoriesArray.join(",");
		SMNewsstand_CookieData.store();

		document.location = getCookieResultsPage() + "&subject=" + tempSubjectIndex;
	}

	function writeFavoriteCategory() {
		var categoryExists;
		for (var j=0;j<favoriteCategoriesArray.length;j++) {
			if ( favoriteCategoriesArray[j] == subjects[subjectIndex].product_id ) {
				categoryExists = true;
			}
		}

		document.open();
		document.write(createFavoriteCategoryStyleHTML());
		if ( categoryExists == true ) {
			document.write("<A HREF=\"javascript:void(deleteFavoriteCategory(subjects[subjectIndex].product_id));\" CLASS=\"nsDeleteFromFavoritesStyle\">" + ns.favoriteCategories.deleteFromFavorites + "</A>");
		} else {
			document.write("<A HREF=\"javascript:void(addFavoriteCategory(subjects[subjectIndex].product_id));\" CLASS=\"nsAddToFavoritesStyle\">" + ns.favoriteCategories.addToFavorites + "</A>");
		}
		document.close();
	}

	function createFavoriteCategoryStyleHTML() {
		var html = "";
		html += "<STYLE>\n";
		html += ".nsAddToFavoritesStyle { " + ns.favoriteCategories.addToFavoritesStyle + " }\n";
		html += ".nsDeleteFromFavoritesStyle { " + ns.favoriteCategories.deleteFromFavoritesStyle + " }\n";
		html += "</STYLE>\n";
		return html;
	}











	////////////////////////////////////////////////////////////////////////////////////////////////////
	//                                                                                                //
	//  The following chunk of variable declarations define a default setting for all of the          //
	//  configurable UI features in the program. This is very cool, because it means when we add a    //
	//  feature, we don't have to tell the client to change their code. We'll have a default setting  //
	//  and if the client would like to implement any customization to it, we can tell them what code //
	//  to add to their files.                                                                        //
	//                                                                                                //
	////////////////////////////////////////////////////////////////////////////////////////////////////

	// These are the objects that contain all the customization variables.
	ns = new Object();
	ns.categoryNav = new Object();
	ns.prevNextNav = new Object();
	ns.currentCategory = new Object();
	ns.headlines = new Object();
	ns.multiCatHeadlines = new Object();
	ns.article = new Object();
	ns.relatedHeadlines = new Object();
	ns.summaryApplet = new Object();
	ns.favoriteCategories = new Object();

	// Set up global variables for the page.
	ns.headlinesTemplate = "headlines.html";
	ns.articleTemplate = "article.html";

	// Set up variables for the hierarchy navigation
	ns.categoryNav.parentBullet = "<CENTER><FONT FACE=\"verdana\" SIZE=1 COLOR=\"000000\">+</FONT></CENTER>";
	ns.categoryNav.currentParentBullet = "<CENTER><FONT FACE=\"verdana\" SIZE=1 COLOR=\"CC0000\">-</FONT></CENTER>";
	ns.categoryNav.childBullet = "<CENTER><FONT FACE=\"verdana\" SIZE=1 COLOR=\"000000\">-</FONT></CENTER>";
	ns.categoryNav.currentChildBullet = "<CENTER><FONT FACE=\"verdana\" SIZE=1 COLOR=\"CC0000\">-</FONT></CENTER>";
	ns.categoryNav.nsTopLink = "color:000000; text-transform:uppercase;";
	ns.categoryNav.nsCurrentTopLink = "color:CC0000; text-transform:uppercase;";
	ns.categoryNav.nsCurrentTopLinkExpanded = "color:CC0000; text-transform:uppercase;";
	ns.categoryNav.nsSubLink = "color:000000;";
	ns.categoryNav.nsCurrentSubLink = "color:CC0000;";
	ns.categoryNav.nsSubParentLink = "color:000000;";
	ns.categoryNav.nsCurrentSubParentLink = "color:CC0000;";
	ns.categoryNav.nsCurrentSubParentLinkExpanded = "color:CC0000;";
	ns.categoryNav.width = 160;
	ns.categoryNav.indentWidth = 15;

	// Set up variables for the previous/next navigation
	ns.prevNextNav.nextLinkClickable = " | next";
	ns.prevNextNav.nextLinkNonClickable = " | next";
	ns.prevNextNav.prevLinkClickable = "prev | ";
	ns.prevNextNav.prevLinkNonClickable = "prev | ";
	ns.prevNextNav.homeLink = "home";
	ns.prevNextNav.nextLinkStyle = "text-decoration:none; color:cc0000";
	ns.prevNextNav.prevLinkStyle = "text-decoration:none; color:cc0000";
	ns.prevNextNav.homeLinkStyle = "text-decoration:none; color:cc0000";
	ns.prevNextNav.nonClickableLinkColor = "ffffff";

	// Set up variables for current category heading.
	ns.currentCategory.linkStyle = "color:CC0000; font-weight:bold; text-transform:uppercase;"
	ns.currentCategory.delimeter = " <FONT COLOR=\"CC0000\">></FONT> ";

	// Set up variables for headline listing.
	ns.headlines.linkStyle = "color:000000;";
	ns.headlines.preLinkHTML = "<P><B>";
	ns.headlines.postLinkHTML = "</B><BR>";
	ns.headlines.preProviderDateHTML = "<FONT COLOR=\"666666\">";
	ns.headlines.postProviderDateHTML = "</FONT>";
	ns.headlines.articlesPerPage = 5;

	// Set up variables for multiple category headline listing
	ns.multiCatHeadlines.preCategoryNameHTML = "<P><FONT SIZE=2 FACE=\"verdana\"><B>";
	ns.multiCatHeadlines.postCategoryNameHTML = "</FONT></B><HR>";
	ns.multiCatHeadlines.preHeadlinesHTML = "<FONT SIZE=1 FACE=\"verdana\">";
	ns.multiCatHeadlines.postHeadlinesHTML = "</FONT>";

	// Set up variables for article.
	ns.article.preHeadlineHTML = "<P><FONT SIZE=2><B><span class=\"ns_text_normal\">";
	ns.article.postHeadlineHTML = "</span></B></FONT>";
	ns.article.preBodyHTML = "<P>";
	ns.article.postBodyHTML = "";
	ns.article.preCopyrightHTML = "<P>";
	ns.article.postCopyrightHTML = "";

	// Set up variables for related headline listing.
	ns.relatedHeadlines.linkStyle = "color:CC0000";
	ns.relatedHeadlines.preLinkHTML = "<TR><TD VALIGN=TOP><span class=\"text_small\">•</span> </TD><TD><span class=\"text_small\">";
	ns.relatedHeadlines.postLinkHTML = "</span></TD></TR>";
	ns.relatedHeadlines.articlesPerPage = 5;

	// Set up variables for favorite categories.
	ns.favoriteCategories.addToFavorites = "Add To Favorites";
	ns.favoriteCategories.deleteFromFavorites = "Delete From Favorites";
	ns.favoriteCategories.addToFavoritesStyle = "color:CC0000;";
	ns.favoriteCategories.deleteFromFavoritesStyle = "color:CC0000;";

	// Set up variable for the summary applet
	ns.summaryApplet.width = "185";
	ns.summaryApplet.height = "200";
	ns.summaryApplet.titleFont = "verdana";
	ns.summaryApplet.titleSize = "11";
	ns.summaryApplet.titleColor = "black";
	ns.summaryApplet.titleColorRGB = "000,000,000";
	ns.summaryApplet.titleText = "";
	ns.summaryApplet.showTitle = "true";
	ns.summaryApplet.summaryFont = "verdana";
	ns.summaryApplet.summarySize = "10";
	ns.summaryApplet.summaryColor = "black";
	ns.summaryApplet.summaryColorRGB = "000,000,000";
	ns.summaryApplet.summaryText = "To view news, choose a category from the left menu on the left, or select an article from the current list. To see an article's summary, roll your mouse over it's headline.";
	ns.summaryApplet.providerFont = "verdana";
	ns.summaryApplet.providerSize = "10";
	ns.summaryApplet.providerColor = "";
	ns.summaryApplet.providerColorRGB = "102,102,102";
	ns.summaryApplet.providerText = "";
	ns.summaryApplet.showProviderHeading = "false";
	ns.summaryApplet.dateFont = "verdana";
	ns.summaryApplet.dateSize = "10";
	ns.summaryApplet.dateColor = "";
	ns.summaryApplet.dateColorRGB = "102,102,102";
	ns.summaryApplet.dateText = "";
	ns.summaryApplet.showDateHeading = "false";
	ns.summaryApplet.backgroundImage = "";
	ns.summaryApplet.backgroundColor = "white";
	ns.summaryApplet.backgroundColorRGB = "255,255,255";
	ns.summaryApplet.borderColor = "white";
	ns.summaryApplet.borderColorRGB = "255,255,255";
