/* main.js */

var summaryIntroTimer, summaryExitTimer;
var menuTimer;
var menuStateVisible = false;
var selectedElementId;
var selectedElementClassName;

function populateModules(moduleCount){
	var module, moduleTitle;
	var moduleNumber = 1;
	var moduleHtml = "";
	for(module = 0; module < moduleCount; module++){
		searchType = eval("module" + moduleNumber + "SearchType");
		if(searchType == "Article"){
			editMenuHtml = "&nbsp;";
		}else{
			editMenuHtml = "&nbsp;";
		}
			
		moduleTitle = eval("module" + moduleNumber + "Title");
		
		if (isPreview == true)
		{
		    moduleHtml += "<div class='pocketModule'><div id='content" + moduleNumber + "Container' class='pocketBody'><div id='content" + moduleNumber + "ContainerScrollable' class='pocketBody350'><div id='content" + moduleNumber + "Loader' class='loadingContainer'><div class='loadingBox'></div></div><div id='content" + moduleNumber + "' style='display:none'></div></div></div></div>";
		}
		else
		{
		    moduleHtml += "<div class='pocketModule'><div id='pocketToolBar" + moduleNumber + "' class='pocketToolBar'><div class='pocketToolBarLeft'><span id='content1Title' class='title'>" + moduleTitle + "</span></div><div class='pocketToolBarRight'><div id='content" + moduleNumber + "ButtonGroup'>" + editMenuHtml + "</div></div><div class='clear'></div></div><div id='content" + moduleNumber + "Container' class='pocketBody'><div id='content" + moduleNumber + "ContainerScrollable' class='pocketBody350'><div id='content" + moduleNumber + "Loader' class='loadingContainer'><div class='loadingBox'><span class='loading'>Loading <img src='img/icon_loading_red_16x16.gif' alt='Loading...'/></span></div></div><div id='content" + moduleNumber + "' style='display:none'></div></div></div><div class='pocketShadow'></div></div>";
		}

		moduleNumber++;
	}
	var moduleHtmlEnd = "</div>";
	moduleHtml = moduleHtml + moduleHtmlEnd;
	return moduleHtml;
}

function buildPageStructure(moduleCount){
	var mainModuleBox = g("pageBoxContentContainerDiv");
	moduleHtml = populateModules(moduleCount);
	
	mainModuleBox.innerHTML = moduleHtml;
}

function hidePageLoader(){
	var loadingBox = g("pageLoaderContainerDiv");
	loadingBox.style.display = "none";
}

function setPageElements(){
	hidePageLoader();
//	document.title = pageTitle;
//	var footerBrandingBox = g("pageFooterDiv");
//	footerBrandingBox.innerHTML = footerBarBranding;
//	var copyrightBox = g("copyrightTextDiv");
//	copyrightBox.innerHTML = copyrightString;
}

function createNavigation(){
	var navBox = g("navListDiv");
	var navItem, navClass, url, title;
	var start = "<ul>"
	var navHtml = "";
	var end = "</ul>"
	var sectionHeaderSearchString = "SECTION_HEADER:";
	var isSectionHeader = false;
	var sectionHeaderText;
	
	for(navItem = 1; navItem < numberOfNavigationLinks + 1; navItem++){
	    isSectionHeader = false;
	    
		url = eval("navigationLink" + navItem + "Url");
		title = eval("navigationLink" + navItem + "Text");
	
	    title.toString();
	    
		if (title.indexOf(sectionHeaderSearchString) > -1){
		   isSectionHeader = true; 
		}
		
		if(pageOrderNumber == navItem){
			navClass = "navListContainerSelectedNav";
		}else{
			navClass = "navListContainerNav";
		}

		
		if (isSectionHeader == true)
		{
		    sectionHeaderText = title.toString().substring(title.toString().indexOf(":") + 1);
		    navHtml += "<li><h1>" + sectionHeaderText + "</h1></li>";
		}
		else
		{
		    navHtml += "<li><a class='" + navClass + "' href='" + url + "'>" + title + "</a></li>";
		}
		
	}
	navBox.innerHTML = start + navHtml + end;
}

function processRelevanceContent(){
	/*
	Step 1: Populate the various global content arrays
	Step 2: Create the pagination elements (page bar and tabs)
	Step 3: Paginate the content, select the appropriate tab, hide the loader and reveal the content
	*/
	populateContentArrays();
	createPagination();
	paginateContentSections();
}

function populateContentArrays(){
	var counter = "1";
	var moduleType, module, moduleContainerElement, titlesArray, hrefsArray, sourcesArray, datesArray, timesArray, summariesArray, countsArray, moreLink;
	for(module = 1; module < numberOfModules + 1; module++){
		moduleType = eval("module" + counter + "SearchType");
		if(moduleType == "Article"){
			moduleContainerElement = "module" + counter + "Data";
			titlesArray = eval("content" + counter + "ArticleTitlesArray");
			hrefsArray = eval("content" + counter + "ArticleTitleHrefsArray");
			sourcesArray = eval("content" + counter + "ArticleSourcesArray");
			datesArray = eval("content" + counter + "ArticleDatesArray");
			timesArray = eval("content" + counter + "ArticleTimesArray");
			summariesArray = eval("content" + counter + "ArticleSummariesArray");
			moreLink = eval("content" + counter + "MoreLinkHref");
			populateArrayArticles(moduleContainerElement,titlesArray,hrefsArray,sourcesArray,datesArray,timesArray,summariesArray,moreLink);
			
		}else if(moduleType == "Content Analysis"){
			moduleContainerElement = "module" + counter + "Data";
			titlesArray = eval("content" + counter + "ArticleTitlesArray");
			hrefsArray = eval("content" + counter + "ArticleTitleHrefsArray");
			datesArray = eval("content" + counter + "ArticleDatesArray");
			timesArray = eval("content" + counter + "ArticleTimesArray");
			countsArray = eval("content" + counter + "ArticleCountsArray");

			//BW added on 052009
			moreLink = eval("content" + counter + "MoreLinkHref");

			populateArrayContentAnalysis(moduleContainerElement,titlesArray,hrefsArray,datesArray,timesArray,countsArray,moreLink)
		}else{
			alert("Please define the search type by updating the module" + counter + "SearchType variable.");
		}
		
		
		
		counter = (parseInt(counter) + 1).toString();
		
	}
}

function createPagination(){
	var counter = "1";
	var module, containerElement, articlePerPageCountValue, titlesArray;
	for(module = 1; module < numberOfModules + 1; module++){
		containerElement = "content" + counter;
		articlePerPageCountValue = eval("content" + counter + "ArticlePerPageCount");
		
		titlesArray = eval("content" + counter + "ArticleTitlesArray");
		createPaginationElements(containerElement,articlePerPageCountValue,titlesArray.length);
		
		counter = (parseInt(counter) + 1).toString();
		
	}	
}

function paginateContentSections(){
	var counter = "1";
	var module, containerElement, resultsPage, articlePerPageCount, selectedPageId;
	for(module = 1; module < numberOfModules + 1; module++){
		containerElement = "content" + counter;
		resultsPage = eval("content" + counter + "ResultsPage");
		articlePerPageCount = eval("content" + counter + "ArticlePerPageCount");
		
		selectedPageId = eval("content" + counter + "SelectedPageId");
		paginateContent(containerElement,resultsPage,articlePerPageCount,selectedPageId);
		counter = (parseInt(counter) + 1).toString();
	}	
}

//Need collection to array function for processing arrays built from HTML collections sent from CP
function collectionToArray(col){

	var theArray = new Array();
	for(i = 0; i < col.length; i++){
		theArray[theArray.length] = col[i];
	}
	return theArray;
}

function populateArrayContentAnalysis(oArray,titles,hrefs,dates,times,counts,moreLink){
	var contentContainer = g(oArray);
	
	var hrefsArray = collectionToArray(contentContainer.getElementsByTagName("A"));//need to make titlesCollection an array so we have access to array methods - thus collectionToArray function
	//alert(contentContainer.getElementsByTagName("A"));
	//alert(hrefsArray[hrefsArray.length - 1]);

	//BW 12/1/09 - changed next two lines to strip out "Data" so we can support double digit module numbers
	var moduleNumber = oArray.substr(6,6);
	moduleNumber = moduleNumber.replace("Data","");
	
	switch(moduleNumber){
		case "1":
			content1MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "2":
			content2MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "3":
			content3MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "4":
			content4MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "5":
			content5MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "6":
			content6MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "7":
			content7MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "8":
			content8MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "9":
			content9MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "10":
			content10MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "11":
			content11MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "12":
			content12MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "13":
			content13MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;

		case "14":
			content14MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "15":
			content15MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "16":
			content16MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "17":
			content17MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "18":
			content18MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "19":
			content19MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "20":
			content20MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "21":
			content21MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "22":
			content22MoreLinkHref = (hrefsArray[hrefsArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;



		default: alert("The module number does not exist.");

	}
	
	var articlesArrayMinusMoreLink = hrefsArray.pop();//need to remove the more link from titlesArray using pop method. Access to the pop method is why we ran through the collectionToArray function
	//alert(hrefsArray.length);
	
	//build article hrefs array
	var url = "";
	var pagePathURL = "";
	
	for(i=0; i < hrefsArray.length; i++){
	
		url = hrefsArray[i].href.split("SearchResults");//relative path bug in production
		pagePathURL = ("&pagePath=" + pagePathSiteName + pagePathPageName);
		//hrefs.push(rootSite + "/ContentView" + url[1] + pagePathURL + "&search=" + isSearchEnabled);
		hrefs.push(rootSite + "/SearchDelivery/ContentSetSearch/SearchResults" + url[1] + pagePathURL + "&search=" + isSearchEnabled + "&emailSelect=" + isEmailSelectEnabled);		
	}
	//build titles array
	for(i=0; i < hrefsArray.length; i++){
		titles.push(hrefsArray[i].innerHTML);
	}
	
	//start building sources, dates and times arrays by accessing the I tag collection
	var datesTimesArray = collectionToArray(contentContainer.getElementsByTagName("I"));
	//start building counts array by accessing the DIV tag collection
	var divsArray = collectionToArray(contentContainer.getElementsByTagName("DIV"));
	//split up divsArray to get count text - remove div tags
	var number = "";
	for(i=0; i < divsArray.length; i++){
		number = divsArray[i].innerHTML.split(" matching item(s)");
		counts.push(number[0]);
	}
	
	//split up sources/datesTimes to get sources array
	//<br>21 Mar 2008 12:41::00 UT
	//split up sources/datesTimes and datesTimes to create arrays for dates and times
	for(i=0; i < datesTimesArray.length; i++){
		date = datesTimesArray[i].innerHTML.substring(4,15);//date format is always dd Mmm yyyy - thus 11 chars long
		time = formatTime(datesTimesArray[i].innerHTML.substring(16,21));
		dates.push(date);
		times.push(time);
	}
}

function populateArrayArticles(oArray,titles,articles,sources,dates,times,summaries,moreLink){
	var contentContainer = g(oArray);
	
	var articlesArray = collectionToArray(contentContainer.getElementsByTagName("A"));//need to make titlesCollection an array so we have access to array methods - thus collectionToArray function
	
	//BW 12/1/09 - changed next two lines to strip out "Data" so we can support double digit module numbers
	var moduleNumber = oArray.substr(6,6);
	moduleNumber = moduleNumber.replace("Data","");
	
	
	switch(moduleNumber){
		case "1":
			content1MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "2":
			content2MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "3":
			content3MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "4":
			content4MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "5":
			content5MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "6":
			content6MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "7":
			content7MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "8":
			content8MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "9":
			content9MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "10":
			content10MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "11":
			content11MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
		case "12":
			content12MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;
        case "13":
			content13MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	

        case "14":
			content14MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	
        case "15":
			content15MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	
        case "16":
			content16MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	
        case "17":
			content17MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	
        case "18":
			content18MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	
        case "19":
			content19MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	
        case "20":
			content20MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	
        case "21":
			content21MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	
        case "22":
			content22MoreLinkHref = (articlesArray[articlesArray.length - 1] + "&pagePath=" + pagePathSiteName + pagePathPageName + "&search=" + isSearchEnabled);
		break;	
			
		default: alert("The module number does not exist.");
	}
	
	
	var articlesArrayMinusMoreLink = articlesArray.pop();//need to remove the more link from titlesArray using pop method. Access to the pop method is why we ran through the collectionToArray function
	//build article hrefs array
	
	for(i=0; i < articlesArray.length; i++){
		articles.push(articlesArray[i]);
	}
	
	//alert(articles.length);
	//build article titles array
	for(i=0; i < articlesArray.length; i++){
		titles.push(articlesArray[i].innerHTML);
		//titles.push(formatTitle(articlesArray[i].innerHTML)); Keep this to test memory leak
	}
	//alert(titles.length);
	//start building sources, dates and times arrays by accessing the I tag collection
	var sourcesDatesTimesArray = collectionToArray(contentContainer.getElementsByTagName("I"));
	//start building summaries array by accessing the DIV tag collection
	var divsArray = collectionToArray(contentContainer.getElementsByTagName("DIV"));
	//split up summariesArray to get summary text - remove div tags
	for(i=0; i < divsArray.length; i++){
		if(divsArray[i].innerHTML.length > summaryCharacterCount){//the summary was increased to 400 characters.
			divsArray[i].innerHTML = divsArray[i].innerHTML.substring(0,summaryCharacterCount + 1) + "...";//don't forget the elipses...
		}
		summaries.push(divsArray[i].innerHTML);
	}
	
	//split up sources/datesTimes to get sources array
	for(i=0; i < sourcesDatesTimesArray.length; i++){
		segments = sourcesDatesTimesArray[i].innerHTML.split("<");//sources and dates are written with a <br> in between. Using the < to split the two. Avoids uppercase issues with browsers.
		sources.push(segments[0]);//push the source
	}
	
	//alert((segments[0]));
	
	//BW 041609 added try block
	try
	{
    	
	    //split up sources/datesTimes and datesTimes to create arrays for dates and times
	    for(i=0; i < sourcesDatesTimesArray.length; i++){
		    segments = sourcesDatesTimesArray[i].innerHTML.split(">");//sources and dates are written with a <br> in between. Using the > to split the two. Avoids uppercase issues with browsers.
	        date = segments[1].substring(0,11);//date format is always dd Mmm yyyy - thus 11 chars long
	        time = formatTime(segments[1].substring(12,segments[1].length));
	        dates.push(date);
	        times.push(time);
	    }

    }
    catch (e)
    {
        //alert("An error occurred!");
        //alert("An exception has occurred in the script.  Error: " + e.name + ". Error Message: " + e.message);
    }
}

function trimAll(sString) 
{ 
while (sString.substring(0,1) == ' ') 
{ 
sString = sString.substring(1, sString.length); 
} 
while (sString.substring(sString.length-1, sString.length) == ' ') 
{ 
sString = sString.substring(0,sString.length-1); 
} 
return sString; 
} 


function getFormattedDate(oFormat){
	var currentDateFormatted = "";
	var currentSystemDate = new Date();
	var currentDay = currentSystemDate.getDay();
	var currentDate = currentSystemDate.getDate();
	var currentMonth = currentSystemDate.getMonth();
	var currentYear = currentSystemDate.getYear();
	var currentHour = currentSystemDate.getHours();
	var currentMinutes = currentSystemDate.getMinutes();
	//format the time
	var currentTime = currentHour + ":" + currentMinutes;
	var formattedDayOfWeek = formatDayOfWeek(currentDay);
	var formattedMonth = formatMonth(currentMonth);
	switch(oFormat){
		case "stockFormat":
			currentDateFormatted = "<strong>" + formattedDayOfWeek + ", " + formattedMonth.substring(0,3) + " " + currentDate + "</strong> - " + formatTime(currentTime);
		break;
		default:alert("The date format you have requested is not defined."); 
	}
	return(currentDateFormatted);
}

function createPaginationElements(section,resultsPerPage,resultsCount){
	var moreLinkHref = eval(section + "MoreLinkHref");
	//Begin: BW - resolve bug 14
	var moreLinkHrefString = "";

	if (moreLinkHref != undefined)
	{
	    moreLinkHrefString = moreLinkHref.toString();
	}
	
	
	
	//End: BW - resolve bug 14
	//The pagination tab bar is created onload so that it remains hidden during the content load/format process.
	var tabBarContainer=g(section+"Container");//locate the tabBarContainer element so we can insert a tab bar. section is the identifying string passed into the loadRelevance function
	var tabBar = document.createElement("div");//create the tab bar to be used for pagination
	tabBar.setAttribute("id",section+"TabBar");//need id for flushing out innerHTML when user sets article per page count
	tabBar.className = "pocketTabBar";
	
	var tabBarRight = document.createElement("div");//create tab bar right
	tabBarRight.className = "pocketTabBarRight";
	var infoList = document.createElement("ul");//create tab bar right UL element to hold info
	var resultsCountListElement = document.createElement("li");
	var searchLinkListElement = document.createElement("li");
	
	var moduleNumber = section.split("content")[1];
	
	var searchType = eval("module" + moduleNumber + "SearchType");

	
	//alert(searchType);
	if(searchType == "Article"){
	
	//alert(moreLinkHrefString);
	
	//BW 9/21/09 changed to resultset.aspx
		if((moreLinkHrefString.indexOf("SearchResults/") == -1) && (moreLinkHrefString.indexOf("SavedContentDefault.asp") == -1))
		{
			// Do not render a View All Link - the search does not contain a More link
		}else{
		
		    if (isPreview == false)
		    {
			    var resultsCountListElementLink = document.createElement("a");
			    resultsCountListElementLink.setAttribute("href","javascript://");
    			
			    resultsCountListElementLink.attachEvent ? resultsCountListElementLink.attachEvent("onclick",function(){openNewWindow(moreLinkHref)}) : resultsCountListElementLink.addEventListener("click", function(){openNewWindow(moreLinkHref)}, false);
			    var resultsCountListElementLinkText = document.createTextNode("View All");
			    resultsCountListElementLink.appendChild(resultsCountListElementLinkText);
			    resultsCountListElement.appendChild(resultsCountListElementLink);
            }

//			var searchLink = document.createElement("a");
//			searchLink.setAttribute("href","javascript://");
//			searchLink.attachEvent ? searchLink.attachEvent("onclick",function(){openNewWindow(moreLinkHref)}) : searchLink.addEventListener("click", function(){openNewWindow(moreLinkHref)}, false);
//			var searchLinkText = document.createTextNode("Search");
//			searchLink.appendChild(searchLinkText);
//			searchLinkListElement.appendChild(searchLink);
			
		}
	}
	else
	
	//BW added else statement on 052009 - trying to display "View All" link for CA searches
	//Content Analysis
	{
	
        //BW 9/21/09 changed to groupset.aspx	    
		if(moreLinkHrefString.indexOf("SearchResults/") == -1){
			// Do not render a View All Link - the search does not contain a More link
		}else{
		
		    if (isPreview == false)
		    {
		
			    var resultsCountListElementLink = document.createElement("a");
			    resultsCountListElementLink.setAttribute("href","javascript://");
			    resultsCountListElementLink.attachEvent ? resultsCountListElementLink.attachEvent("onclick",function(){openNewWindow(moreLinkHref)}) : resultsCountListElementLink.addEventListener("click", function(){openNewWindow(moreLinkHref)}, false);
			    var resultsCountListElementLinkText = document.createTextNode("View All");
			    resultsCountListElementLink.appendChild(resultsCountListElementLinkText);
			    resultsCountListElement.appendChild(resultsCountListElementLink);
    		}
    			
//			var searchLink = document.createElement("a");
//			searchLink.setAttribute("href","javascript://");
//			searchLink.attachEvent ? searchLink.attachEvent("onclick",function(){openNewWindow(moreLinkHref)}) : searchLink.addEventListener("clickSearch", function(){openNewWindow(moreLinkHref)}, false);
//			var searchLinkText = document.createTextNode("Search");
//			searchLink.appendChild(searchLinkText);
//			searchLinkListElement.appendChild(searchLink);			
			
			
		}	
	}
	
	
	//infoList.appendChild(resultsCountListElement);
	infoList.appendChild(searchLinkListElement);
	tabBarRight.appendChild(infoList);
	
	
	var tabBarLeft = document.createElement("div");//create tab bar left. (This is done in case we need a tab bar right which we probably will not)
	tabBarLeft.className = "pocketTabBarLeft";
	var tabList = document.createElement("ul");//create tab bar left UL element to hold tabs (which are LI elements)
	var tabListArrowPreviousListElement = document.createElement("li");
	var tabListArrowPreviousLink = document.createElement("a");
	tabListArrowPreviousLink.setAttribute("href","javascript://");
	tabListArrowPreviousLink.setAttribute("id",section+"TabPrevious");
	tabListArrowPreviousLink.attachEvent ? tabListArrowPreviousLink.attachEvent("onclick",function(){paginatePrep(this,section,resultsPerPage)}) : tabListArrowPreviousLink.addEventListener("click", function(){paginatePrep(this,section,resultsPerPage,"previous")}, false);
	//var tabListArrowPreviousImage = document.createElement("img");
	//tabListArrowPreviousImage.setAttribute("src","img/icon_arrow_previous_16x16.gif");
	//tabListArrowPreviousImage.setAttribute("alt","Previous");
	//tabListArrowPreviousLink.appendChild(tabListArrowPreviousImage);
	//tabListArrowPreviousListElement.appendChild(tabListArrowPreviousLink);
	tabList.appendChild(tabListArrowPreviousListElement);

	var clearingDiv = document.createElement("div");//create clearing div for layout purposes
	clearingDiv.className = "clear";
	
	var paginationTabCount = Math.ceil(resultsCount/resultsPerPage);//determine number of tabs

    //alert(paginationTabCount);

//BW 052009 - commented this out so we always show the "View All" link even when there are zero results.
//	if(paginationTabCount == 0){
//		return;
//	}
/*
	var tabText = 1;
	var tabId = 1;
	if(paginationTabCount > 0){
		for(i=0; i < paginationTabCount; i++){//create tabs by adding LI elements to the tabBarLeft UL element
			tabListElement = document.createElement("li");
			tabListElementLink = document.createElement("a");
			tabListElementLink.setAttribute("href","javascript://");
			tabListElementLink.setAttribute("id",section+"Tab"+tabId++);
			tabListElementLink.attachEvent ? tabListElementLink.attachEvent("onclick",function(){paginatePrep(this,section,resultsPerPage)}) : tabListElementLink.addEventListener("click", function(){paginatePrep(this,section,resultsPerPage)}, false);
			tabListElementLinkText = document.createTextNode(tabText++);
			tabListElementLink.appendChild(tabListElementLinkText);
			tabListElement.appendChild(tabListElementLink);
			tabList.appendChild(tabListElement);
			
		}
	}
  */ 
	
//	var tabListArrowNextListElement = document.createElement("li");
//	var tabListArrowNextLink = document.createElement("a");
//	tabListArrowNextLink.setAttribute("href","javascript://");
//	tabListArrowNextLink.setAttribute("id",section+"TabNext");
//	tabListArrowNextLink.attachEvent ? tabListArrowNextLink.attachEvent("onclick",function(){paginatePrep(this,section,resultsPerPage)}) : tabListArrowNextLink.addEventListener("click", function(){paginatePrep(this,section,resultsPerPage,"next")}, false);
//	var tabListArrowNextImage = document.createElement("img");
//	tabListArrowNextImage.setAttribute("src","img/icon_arrow_next_16x16.gif");
//	tabListArrowNextImage.setAttribute("alt","Next");
//	tabListArrowNextLink.appendChild(tabListArrowNextImage);
//	tabListArrowNextListElement.appendChild(tabListArrowNextLink);
//	tabList.appendChild(tabListArrowNextListElement);

    tabList.appendChild(resultsCountListElement);	
	
	
	tabBarLeft.appendChild(tabList);
	tabBar.appendChild(tabBarLeft);
	tabBar.appendChild(tabBarRight);
	tabBar.appendChild(clearingDiv);
	tabBarContainer.insertBefore(tabBar,tabBarContainer.firstChild);
}

function paginatePrep(evt,section,resultsPerPage,direction){
	var oSrc = evt;
	if(!evt.innerHTML){//IE
		oSrc = window.event.srcElement;
		if(oSrc.innerHTML == ""){//IE image click
			oSrc = oSrc.parentNode;
		}
	}
	var page;
	if(oSrc.innerHTML.indexOf("img")!=-1){//prev or next image was clicked
		var tabIdPieces = eval(section+"SelectedPageId").split("Tab");
		var idNumber = tabIdPieces[1];
		var numberOfPages = Math.ceil(parseInt(eval(section+"ArticleTitlesArray").length) / resultsPerPage);
		if(oSrc.id.indexOf("Previous")!=-1){//previous clicked
			page = parseInt(eval(section+"ResultsPage")) - 1;
			tabId = section + "Tab" + (parseInt(idNumber) - 1);
			if(page == 0){
				page = Math.ceil(parseInt(eval(section+"ArticleTitlesArray").length) / resultsPerPage);//Math.ceil is required to deal with division remainder
				tabId = section + "Tab" + numberOfPages;
			}
		}else{//next clicked
			page = parseInt(eval(section+"ResultsPage")) + 1;
			tabId = section + "Tab" + (parseInt(idNumber) + 1);
			if(page > Math.ceil(parseInt(eval(section+"ArticleTitlesArray").length) / resultsPerPage)){//Math.ceil is required to deal with division remainder
				page = 1;
				tabId = section + "Tab" + 1;
			}
		}
	}else{
		page = oSrc.innerHTML;
		tabId = oSrc.id;
	}
	paginateContent(section,page,resultsPerPage,tabId);
}

function paginateContent(section,resultsPage,resultsPerPage,currentPageId){
	moduleNumber = section.split("content")[1];
	searchType = eval("module" + moduleNumber + "SearchType");
	// need to determine the index. Onload this is passed in. For pagination tab elements use the section that is hardcoded into the onclick of the element
	var currentIndex = (resultsPage * resultsPerPage) - resultsPerPage;
	
	var totalResults = parseInt(eval(section+"ArticleTitlesArray").length);
	
	//alert(totalResults);
	//BW CA search returns "more" link as a result so we need to decrease the count if CA by 1.
	if(searchType=="Content Analysis")
	{
	    //totalResults = totalResults - 1;
	}
	
	//alert(totalResults);
	
	if(totalResults < (resultsPage * resultsPerPage)){//check for situation where, for example, there are 33 results but 5 per page makes a remainder of 2 results. Thus the loop adds 3 undefined results as it loops through 5 times.
		resultsPerPage = resultsPerPage - ((resultsPage * resultsPerPage) - totalResults);
	}
	var loadingIndicator = g(section+"Loader");
	var contentContainer = g(section);
	
	//BW 6/4/2009 - changed value from 0 to 1 since we always deliver a "more" link even if there are no article results.
	//TODO test this with an article search that has 1 result

    //alert(totalResults);

	if(totalResults == 0){
		contentContainer.innerHTML = noResultsHtml;
		loadingIndicator.style.display = "none";
		contentContainer.style.display = "block";
		return;
	}

	var summaryPreviewState = eval(section + "Summary");
	var articles, end;//declare pieces for innerHTML write
	var caViewLabel = "results";
	switch(searchType){
		case "Article":
			var hrefsArray = eval("content" + moduleNumber + "ArticleTitleHrefsArray");
			var titlesArray = eval("content" + moduleNumber + "ArticleTitlesArray");
			var datesArray = eval("content" + moduleNumber + "ArticleDatesArray");
			var timesArray = eval("content" + moduleNumber + "ArticleTimesArray");
			var sourcesArray = eval("content" + moduleNumber + "ArticleSourcesArray");
			var summariesArray = eval("content" + moduleNumber + "ArticleSummariesArray");
			if(summaryPreviewState == "hide"){
				summaryPreviewLinkClassName = "summaryPreviewLink";
				articleDevSummaryBoxClassName = "articleDevSummaryBoxHidden";
			}else{
				summaryPreviewLinkClassName = "summaryPreviewLinkHidden";
				articleDevSummaryBoxClassName = "articleDevSummaryBox";
			}
			articles = "";
			for(i=0; i < resultsPerPage; i++){
				uniqueId = theGenerator.generateId("articleDev");
				
				    articles += "<div id='" + uniqueId + "' class='articleDevBox'><p class='articleDevNoSummary'><a id='title" + section + i + "' class='articleDevTitle' href='" + hrefsArray[currentIndex + i] + "' target='ViewAll'>" + titlesArray[currentIndex + i] + "<br /></a><span id='date" + section + i + "' class='articleDevDate'>" + datesArray[currentIndex + i] + "</span><span id='time" + section + i + "' class='articleDevTime'>" + timesArray[currentIndex + i] + "</span><span id='source" + section + i + "' class='articleDevSource'>" + sourcesArray[currentIndex + i] + "</span><span id='articleDevSummaryBox" + section + i + "' class='" + articleDevSummaryBoxClassName + "'>" + summariesArray[currentIndex + i] + "</span></p></div>";
			}
			end = "";
		break;
		case "Content Analysis":
			var hrefsArray = eval("content" + moduleNumber + "ArticleTitleHrefsArray");
			var titlesArray = eval("content" + moduleNumber + "ArticleTitlesArray");
			var datesArray = eval("content" + moduleNumber + "ArticleDatesArray");
			var timesArray = eval("content" + moduleNumber + "ArticleTimesArray");
			var countsArray = eval("content" + moduleNumber + "ArticleCountsArray");
			articles = "<p class='caView'>";
			for(i=0; i < resultsPerPage; i++){
				articles += "<a class='headline' href='" + hrefsArray[currentIndex + i] + "' target='ViewAll'><span class='title'>" + titlesArray[currentIndex + i] + "</span><span class='date'>" + datesArray[currentIndex + i] + " - " + timesArray[currentIndex + i] + "</span><span class='count'>- " + countsArray[currentIndex + i] + " </span><span class='label'>" + caViewLabel + "</span></a>";
			}
			end = "</p>";
			
		break;
		default:alert("Please define the search type by updating the module" + moduleNumber + "SearchType variable."); 
	}
	if(totalResults > 0){//no results so no tab - therefore do not select
		//selectTab(section,currentPageId);
	}
	//keep state - reset the proper ResultsPage global variable and SelectedPageId global variable
	switch(section){
		case "content1":
			content1ResultsPage = resultsPage;
			content1SelectedPageId = currentPageId;
		break;
		case "content2":
			content2ResultsPage = resultsPage;
			content2SelectedPageId = currentPageId;
		break;
		case "content3":
			content3ResultsPage = resultsPage;
			content3SelectedPageId = currentPageId;
		break;
		case "content4":
			content4ResultsPage = resultsPage;
			content4SelectedPageId = currentPageId;
		break;
		case "content5":
			content5ResultsPage = resultsPage;
			content5SelectedPageId = currentPageId;
		break;
		case "content6":
			content6ResultsPage = resultsPage;
			content6SelectedPageId = currentPageId;
		break;
		case "content7":
			content7ResultsPage = resultsPage;
			content7SelectedPageId = currentPageId;
		break;
		case "content8":
			content8ResultsPage = resultsPage;
			content8SelectedPageId = currentPageId;
		break;
		case "content9":
			content9ResultsPage = resultsPage;
			content9SelectedPageId = currentPageId;
		break;
		case "content10":
			content10ResultsPage = resultsPage;
			content10SelectedPageId = currentPageId;
		break;
		case "content11":
			content11ResultsPage = resultsPage;
			content11SelectedPageId = currentPageId;
		break;
		case "content12":
			content12ResultsPage = resultsPage;
			content12SelectedPageId = currentPageId;
		break;
		case "content13":
			content13ResultsPage = resultsPage;
			content13SelectedPageId = currentPageId;
		break;

		case "content14":
			content14ResultsPage = resultsPage;
			content14SelectedPageId = currentPageId;
		break;
		
		case "content15":
			content15ResultsPage = resultsPage;
			content15SelectedPageId = currentPageId;
		break;
		case "content16":
			content16ResultsPage = resultsPage;
			content16SelectedPageId = currentPageId;
		break;
		case "content17":
			content17ResultsPage = resultsPage;
			content17SelectedPageId = currentPageId;
		break;
		case "content18":
			content18ResultsPage = resultsPage;
			content18SelectedPageId = currentPageId;
		break;
		case "content19":
			content19ResultsPage = resultsPage;
			content19SelectedPageId = currentPageId;
		break;
		case "content20":
			content20ResultsPage = resultsPage;
			content20SelectedPageId = currentPageId;
		break;
		case "content21":
			content21ResultsPage = resultsPage;
			content21SelectedPageId = currentPageId;
		break;
		case "content22":
			content22ResultsPage = resultsPage;
			content22SelectedPageId = currentPageId;
		break;
				
		default:alert("The content section is not defined."); 
	}
	var twoColumnLayout = false;
	//Determine if the page is two column layout by checking .pocketModule class width
	var moduleBoxes = getElementsByClassName(document.body, "div", "pocketModule");
	for (var moduleBox = 0; moduleBox < moduleBoxes.length; moduleBox++){
		if(moduleBoxes[moduleBox].offsetWidth == "395"){
			twoColumnLayout = true;
		}
	}
	

	
	    if(twoColumnLayout){
	    
		    var resultsBox = g("content" + moduleNumber + "ContainerScrollable");
		    var resultsBoxCurrentOffsetHeight = resultsBox.offsetHeight;
		    if(isEven(moduleNumber)){
			    var siblingResultsBox = g("content" + (parseInt(moduleNumber) - 1) + "ContainerScrollable");
		    }else{
		        //BW 11/11/09 the "+ 1" was causing this particular 1 column module layout
			    //var siblingResultsBox = g("content" + (parseInt(moduleNumber) + 1) + "ContainerScrollable");
			    var siblingResultsBox = g("content" + (parseInt(moduleNumber) ) + "ContainerScrollable");
		    }
		    /* Tests for height calculation
		    alert("My current height is " + g("content" + moduleNumber + "ContainerScrollable").offsetHeight);
		    if(isEven(moduleNumber)){
			    var sibling = g("content" + (parseInt(moduleNumber) - 1) + "ContainerScrollable");
			    alert("Sibling is " + sibling.id + " -- " + sibling.offsetHeight);
		    }else{
			    var sibling = g("content" + (parseInt(moduleNumber) + 1) + "ContainerScrollable");
			    alert("Sibling is " + sibling.id + " -- " + sibling.offsetHeight);
		    }
		    var resultsBox = g("content" + moduleNumber + "ContainerScrollable")
		    alert("I am " + resultsBox.id + " -- " + resultsBox.offsetHeight);
		    */
	    }
	
	
	contentContainer.innerHTML = articles + end;
	if(twoColumnLayout){
		var resultsBoxNewOffsetHeight = resultsBox.offsetHeight;
		if(resultsBoxNewOffsetHeight != resultsBoxCurrentOffsetHeight){
			siblingResultsBox.style.height = resultsBoxNewOffsetHeight + "px";
		}
	}
	loadingIndicator.style.display = "none";
	contentContainer.style.display = "block";
}

function isEven(num){
  return !(num % 2);
}

function selectTab(section,tabId){
	var previousTab = eval(section+"SelectedPageId");
	g(previousTab).className = "pocketTabBarTab";
	g(tabId).className = "pocketTabBarTabSelected";
}

function toggleView(oSrc,oTarget){
	var target = document.getElementById(oTarget);
	if(target.style.display == "none"){
		target.style.display = "block";
		oSrc.style.backgroundImage = "url(img/icon_collapse_16x52.gif)";
	}else{
		target.style.display = "none";
		oSrc.style.backgroundImage = "url(img/icon_expand_16x52.gif)";
	}
}

function selectElement(oSrc,oType){
	if(selectedElementId != null){
		var previousSelection = g(selectedElementId);//first deselect previous selected element
		previousSelection.className = selectedElementClassName;
	}else{
		previousSelection = null;
	}
	switch(oType){
		case "toolbar":
			switch(oSrc.className){
				case "":
					selectedElementClassName = "";//need this to reset the button down state of the previously clicked button. Happens when user clicks a button and then click another without hideMenu taking place
					oSrc.className = "buttonDown";
				break;
				case "iconSprite":
					selectedElementClassName = "iconSprite";
					oSrc.className = "iconSpriteDown";
				break;
				case "iconSprite24":
					selectedElementClassName = "iconSprite24";
					oSrc.className = "menuButtonDown";
				break;
				default:alert("selectElement className is not defined.");
			}
		break;
		case "toolbarModuleEdit":
			switch(oSrc.className){
				case "":
					selectedElementClassName = "";//need this to reset the button down state of the previously clicked button. Happens when user clicks a button and then click another without hideMenu taking place
					oSrc.className = "buttonDown";
				break;
				case "iconSprite":
					selectedElementClassName = "iconSprite";
					oSrc.className = "iconSpriteDown";
				break;
				case "iconSprite24":
					selectedElementClassName = "iconSprite24";
					oSrc.className = "menuButtonDown";
				break;
				default:alert("selectElement className is not defined.");
			}
		break;
		default:
			alert('Source tagName could not be determined.');
	}
	selectedElementId = oSrc.id;
} 

function showMenu(e,oSrc,oType){
	clearTimeout(menuTimer);
	hideMenu(oType);
	var oMenuBox,oMenu;
	switch(oType){
		case "toolbar":
			oMenuBox = g("searchMenuContainer");
			oMenu = g("searchMenu");
		break;
		case "toolbarModuleEdit":
			oMenuBox = g("searchMenuContainer");
			oMenu = g("searchMenu");
		break;
		case "infopage":
			oMenuBox = g("infoPageMenuContainer");
			oMenu = g("infoPageMenu");
		break;
		default:
			alert('The menu type is undefined.');
	}
	oMenu.innerHTML = buildMenu(oSrc,oType);
	oMenuBox.style.visibility = "hidden";
	oMenuBox.style.display = "block";
	//Need to set the pref value in the html and display it to the user
	if(oSrc && oSrc.id == "buttonMyPreferences"){
		if(readCookie("prefValAppc") == null){
			var appcVal = defaultAppc;
			for(radioButton = 0; radioButton < document.allAppcValuesForm.allAppcValues.length; radioButton++){
				if(document.allAppcValuesForm.allAppcValues[radioButton].value == appcVal){
					document.allAppcValuesForm.allAppcValues[radioButton].checked = true;
				}
			}
		}else{
			var appcVal = readCookie("prefValAppc");
			
			for(radioButton = 0; radioButton < document.allAppcValuesForm.allAppcValues.length; radioButton++){
				if(document.allAppcValuesForm.allAppcValues[radioButton].value == appcVal){
					document.allAppcValuesForm.allAppcValues[radioButton].checked = true;
				}
			}
		}
		if(readCookie("prefValSummary") == null){
			var summaryVal = defaultSummary;
			for(radioButton = 0; radioButton < document.allSummaryValuesForm.allSummaryValues.length; radioButton++){
				if(document.allSummaryValuesForm.allSummaryValues[radioButton].value == summaryVal){
					document.allSummaryValuesForm.allSummaryValues[radioButton].checked = true;
				}
			}
		}else{
			var summaryVal = readCookie("prefValSummary");
			for(radioButton = 0; radioButton < document.allSummaryValuesForm.allSummaryValues.length; radioButton++){
				if(document.allSummaryValuesForm.allSummaryValues[radioButton].value == summaryVal){
					document.allSummaryValuesForm.allSummaryValues[radioButton].checked = true;
				}
			}
		}
	}
	
	//Get source element positions
	var oSrcX = getAbsolutePositionX(oSrc);
	var oSrcY = getAbsolutePositionY(oSrc);
	//Position the menu
	oMenuBox.style.top = oSrcY + oSrc.offsetHeight + 'px';
	oMenuBox.style.left = oSrcX - 1 + 'px';
	//Get menu absolute positions
	var menuX = getAbsolutePositionX(oMenuBox);
	var menuY = getAbsolutePositionY(oMenuBox);
	var menuRightX = menuX + oMenuBox.clientWidth + oMenu.clientWidth;
	var menuBottomY = menuY + oMenuBox.clientHeight + oMenu.clientHeight;
	//Get the browser dimensions
	var browserSize = getBrowserSize();
	var browserBottom = browserSize[0];
	var browserRight = browserSize[1];
	//Compare menu to browser and move menu if necessary
	if(menuBottomY > browserBottom){
		var sourceElementBottomEdgeDistanceFromBrowserBottom =  browserBottom - menuY;
		oMenuBox.style.top = browserBottom - oMenuBox.clientHeight - oMenu.clientHeight - sourceElementBottomEdgeDistanceFromBrowserBottom - oSrc.clientHeight + "px";
	}
	if(menuRightX > browserRight){
		var sourceElementLeftEdgeDistanceFromBrowserRight =  browserRight - menuX;
		oMenuBox.style.left = browserRight - oMenu.clientWidth - sourceElementLeftEdgeDistanceFromBrowserRight + oSrc.clientWidth + "px";
	}
	selectElement(oSrc,oType);
	menuStateVisible = true;
	oMenuBox.style.visibility = "visible";
}

function clearInnerHtml(oContainer){
	var box = g(oContainer);
	box.innerHTML = "";
}

function setArticlePerPageCount(oSrc,oModule){
	var int = oModule.split("content"); //identifying number
	var appc = oSrc.options[oSrc.selectedIndex].value;

	clearInnerHtml(oModule);
	removeElement(oModule+"TabBar");
	
	resultsCount = eval(oModule+"ArticleTitlesArray.length");
	
	createPaginationElements(oModule,appc,resultsCount);
	
	currentPageId = oModule+"Tab1";
	paginateContent(oModule,"1",appc,currentPageId);
	var cookieName = "m" + int[1] + "appc";
	createCookie(cookieName,appc,"1");
}

function buildMenu(oSrc,oType){
	var menuHtml;
	if(oType == "toolbar"){
		switch(oSrc.id){
			case "buttonMyPreferences":
				menuHtml = "<ul onmouseover='menuVisible(\"toolbar\")'><li><div class='menuOptionBox'><form name='allSummaryValuesForm'><input type='radio' value='show' id='allSummaryValuesRadioShow' name='allSummaryValues' class='menuRadio'>Show Article Summaries<br /><input type='radio' value='hide' id='allSummaryValuesRadioHide' name='allSummaryValues' class='menuRadio'>Hide Article Summaries</form></div></li><li class='menuSeparator'>&nbsp;</li><li><div class='menuOptionBox'><form name='allAppcValuesForm'><input type='radio' value='3' id='allAppcValuesRadio3' name='allAppcValues' class='menuRadio'>3 Articles Per Module Page<br /><input type='radio' value='5' id='allAppcValuesRadio5' name='allAppcValues' class='menuRadio'>5<br /><input type='radio' value='7' id='allAppcValuesRadio7' name='allAppcValues' class='menuRadio'>7<br /><input type='radio' value='10' id='allAppcValuesRadio10' name='allAppcValues' class='menuRadio'>10<br /><input type='radio' value='15' id='allAppcValuesRadio15' name='allAppcValues' class='menuRadio'>15<br /></form></div></li><li><div class='menuButtonBox'><input class='menuButtonBoxButton' type='button' value='Save' onclick='processUserPrefs()' /><input class='menuButtonBoxButtonCancel' type='button' value='Cancel' onclick='hideMenuNoDelay(\"toolbar\")' /></div></li></ul>";
			break;
			case "buttonLayout":
				menuHtml = "<ul onmouseover='menuVisible(\"toolbar\")'><li><a class='menuItemStandard' href='javascript://' onclick='cssSwitch(\"fixed_col_2\")'><img src='img/icon_layout_cols2_n1_20x20.gif' /> 2 Column (Default) </a></li><li><a class='menuItemStandard' href='javascript://' onclick='cssSwitch(\"fixed_col_3\")'><img src='img/icon_layout_cols3_n2_20x20.gif' /> 3 Column </a></li><li><a class='menuItemStandard' href='javascript://' onclick='cssSwitch(\"fixed_col_1\")'><img src='img/icon_layout_cols1_n1_20x20.gif' /> 1 Column</a></li><li><a class='menuItemStandard' href='javascript://' onclick='cssSwitch(\"fluid_col_3\")'><img src='img/icon_layout_cols3_fullwidth_20x20.gif' /> 3 Column Wide</a></li><li><a class='menuItemStandard' href='javascript://' onclick='cssSwitch(\"fluid_col_1\")'><img src='img/icon_layout_cols1_fullwidth_20x20.gif' /> 1 Column Wide</a></li></ul>";
			break;
			default:
				menuHtml = "No options have been defined for this menu.";
		}
	}else if(oType == "toolbarModuleEdit"){
		//need to determine the module SearchType in order to display the correct menu options
		var number = oSrc.id.substr(7,1);
		searchType = eval("module" + number + "SearchType");
		switch(searchType){
			case "Article":
				menuHtml = "<ul onmouseover='menuVisible(\"toolbarModuleEdit\")'><li><a class='menuItemStandard' href='javascript://' onclick='toggleArticleSummaries(\"module" + number + "\");hideMenuNoDelay(\"toolbarModuleEdit\")'>Show/Hide Summaries</a></li></ul>";
			break;
			case "Content Analysis":
				menuHtml = "<ul onmouseover='menuVisible(\"toolbarModuleEdit\")'><li><div class='menuOptionBox'>Show: <select onChange='setArticlePerPageCount(this,\"content" + number + "\");hideMenuNoDelay(\"toolbarModuleEdit\")'><option value='default'> </option><option value='3'>3</option><option value='5'>5</option><option value='7'>7</option><option value='10'>10</option><option value='15'>15</option></select> per page</div></li></ul>";
			break;
			default:
				menuHtml = "No options have been defined for this menu.";
		}
	}else{
		menuHtml = "No options have been defined for this menu.";
	}
	return menuHtml;
}

function menuVisible(oType){
	clearTimeout(menuTimer);
	var oMenu;
	switch(oType){
		case "toolbar":
			oMenu = g("searchMenuContainer");
			oMenu.style.display = "block";
		break;
		case "toolbarModuleEdit":
			oMenu = g("searchMenuContainer");
			oMenu.style.display = "block";
		break;
		case "infopage":
			oMenu = g("infoPageMenuContainer");
			oMenu.style.display = "block";
		break;
		default:
			alert('The menu type is undefined.');
	}
}

function hideMenu(oType){
	switch(oType){
		case "toolbar":
			menuTimer = setTimeout('hideMenuNoDelay("'+oType+'")',750);
		break;
		case "toolbarModuleEdit":
			menuTimer = setTimeout('hideMenuNoDelay("'+oType+'")',750);
		break;
		case "infopage":
			menuTimer = setTimeout('hideMenuNoDelay("'+oType+'")',500);
		break;
		default:
			alert('The menu type is undefined.');
	}
}

function hideMenuNoDelay(oType){
	var oMenu;
	switch(oType){
		case "toolbar":
			oMenu = g("searchMenuContainer");
			if(selectedElementId != null){
				var selectedElement = g(selectedElementId);
				switch(selectedElement.className){
				case "buttonDown":
					selectedElement.className = "";
				break;
				case "iconSpriteDown":
					selectedElement.className = "iconSprite";
				break;
				case "menuButtonDown":
					selectedElement.className = "iconSprite24";
				break;
				default:;
				}
			}
		break;
		case "toolbarModuleEdit":
			oMenu = g("searchMenuContainer");
			if(selectedElementId != null){
				var selectedElement = g(selectedElementId);
				switch(selectedElement.className){
				case "buttonDown":
					selectedElement.className = "";
				break;
				case "iconSpriteDown":
					selectedElement.className = "iconSprite";
				break;
				case "menuButtonDown":
					selectedElement.className = "iconSprite24";
				break;
				default:;
				}
			}
		break;
		case "infopage":
			oMenu=g("infoPageMenuContainer");
			if(selectedElementId != null){
				var selectedElement = g(selectedElementId);
				selectedElement.blur();
			}
		break;
		default:
			alert('The menu type is undefined.');
	}
	menuStateVisible = false;
	oMenu.style.display = "none";
}

function summaryPreviewCreate(oSrc,scrollableParentBox){
	clearTimeout(summaryExitTimer);//this may have been set if the user mouses from the summary fly-out back to the source icon or if they mouse out and to a new icon
	var parentBox = g(scrollableParentBox);
	var articleNumber = oSrc.id.split("summaryPreviewLink"); //getting section + index number - example: "content35"
	var summaryContainer = g("articleDevSummaryBox"+articleNumber[1]);
	var identifier = oSrc.id.split("summaryPreviewLink");
	var articleTitle = g("title" + identifier[1]);
	var articleDate = g("date" + identifier[1]);
	var articleTime = g("time" + identifier[1]);
	var articleSource = g("source" + identifier[1]);
	var summaryContent = "<a class='articleDevTitle' href='" + articleTitle + "' target='ViewAll'>" + articleTitle.innerHTML + "</a><span class='articleDevDate'>" + articleDate.innerHTML + "</span><span class='articleDevTime'>" + articleTime.innerHTML + "</span><span class='articleDevSource'>" + articleSource.innerHTML + "</span><span class='articleDevSummaryBox'>" + summaryContainer.innerHTML + "</span>";
	var summaryBox = g("summaryBoxMain");
	var summaryPreviewContainer = g("summaryPreviewInnerContainer");
	var apx = getAbsolutePositionX(oSrc);
	var apy = getAbsolutePositionY(oSrc);
	summaryBox.style.display = "none";//resetting the display to none keeps the summary preview element fron hopping when it needs to move because of overlap with the browser window
	if(parentBox.scrollTop > 0){ //fixed height parent container might scroll vertically so we need to check the scrollTop and subtract it from the absolute position
		apy = apy - parentBox.scrollTop;
	}
	summaryBox.style.top = apy + 'px';
	summaryBox.style.left = apx + oSrc.offsetWidth + 'px';
	summaryPreviewContainer.innerHTML = summaryContent;
	//alert("Top: " + summaryBox.style.top + " -- " + summaryBox.style.left);
	summaryIntroTimer = setTimeout('summaryPreviewShow("'+oSrc.id+'")',500);
}

function summaryPreviewCancel(){
	clearTimeout(summaryIntroTimer);
}

function summaryPreviewShow(oTarget){
	var summaryPreviewElement = g("summaryBoxMain");
	var sourceElement = g(oTarget);//need to determine the whereabouts of the summary preview trigger in order to adjust summary preview fly-out if it overlaps the browser window edge
	summaryPreviewElement.style.visibility = "hidden";
	summaryPreviewElement.style.display = "block";
	//The check for flyout position will have to be done after its display is set to block...
	//...both IE7 and Firefox cannot return clientHeight while the element is display none.
	//Get source element absolute positions
	var sourceElementX = getAbsolutePositionX(sourceElement);
	var sourceElementY = getAbsolutePositionY(sourceElement);
	//Get summary preview fly out absolute positions
	var summaryPreviewElementX = getAbsolutePositionX(summaryPreviewElement);
	var summaryPreviewElementY = getAbsolutePositionY(summaryPreviewElement);
	var summaryPreviewElementRightX = summaryPreviewElementX + summaryPreviewElement.clientWidth;
	var summaryPreviewElementBottomY = summaryPreviewElementY + summaryPreviewElement.clientHeight;
	//Get the browser dimensions
	var browserSize = getBrowserSize();
	var browserBottom = browserSize[0];
	var browserRight = browserSize[1];
	//Compare summary preview flyout to browser and move summary preview if necessary
	if(summaryPreviewElementBottomY > browserBottom){
		summaryPreviewElement.style.top = browserBottom - summaryPreviewElement.clientHeight + "px";
		var summaryPreviewElementTop = summaryPreviewElement.style.top.split("px");
	}
	if(summaryPreviewElementRightX > browserRight){
		var sourceElementLeftEdgeDistanceFromBrowserRight =  browserRight - sourceElementX;
		summaryPreviewElement.style.left = browserRight - summaryPreviewElement.clientWidth - sourceElementLeftEdgeDistanceFromBrowserRight + "px";
	}
	summaryPreviewElement.style.visibility = "visible";
}

function summaryPreviewVisible(oTarget){
	clearTimeout(summaryExitTimer);
	var summaryPreviewElement = document.getElementById(oTarget);
	summaryPreviewElement.style.display = "block";
}

function summaryPreviewHide(oTarget){
	summaryExitTimer = setTimeout('summaryPreviewHideNoDelay("'+oTarget+'")',1000);
}

function summaryPreviewHideNoDelay(oTarget){
	var summaryPreviewElement = document.getElementById(oTarget);
	summaryPreviewElement.style.display = "none";
}

function toggleArticleSummaries(oModule){
	var moduleNumber = oModule.split("module");
	var summarySpans = getElementsByClassName(document.getElementById("content" + moduleNumber[1]), "span", "articleDevSummaryBox");
	var summarySpansHidden = getElementsByClassName(document.getElementById("content" + moduleNumber[1]), "span", "articleDevSummaryBoxHidden");
	var summaryPreviewLinks = getElementsByClassName(document.getElementById("content" + moduleNumber[1]), "a", "summaryPreviewLink");
	var summaryPreviewLinksHidden = getElementsByClassName(document.getElementById("content" + moduleNumber[1]), "a", "summaryPreviewLinkHidden");
	var cookieVal;
	if(summarySpans.length == 0){//no summaries shown - show all summaries
		for(i=0; i<summarySpansHidden.length ;i++){
			summarySpansHidden[i].className = "articleDevSummaryBox";
			summaryPreviewLinks[i].className = "summaryPreviewLinkHidden";
			cookieVal = "show";
		}
	}else{//all summaries shown - so hide all summaries
		for(i=0; i<summarySpans.length ;i++){
			summarySpans[i].className = "articleDevSummaryBoxHidden";
			summaryPreviewLinksHidden[i].className = "summaryPreviewLink";
			cookieVal = "hide";
		}
	}
	var cookieName = "m" + moduleNumber[1] + "sum";
	switch(moduleNumber[1]){//set the contentSummary value
		case "1":content1Summary = cookieVal;break;
		case "2":content2Summary = cookieVal;break;
		case "3":content3Summary = cookieVal;break;
		case "4":content4Summary = cookieVal;break;
		case "5":content5Summary = cookieVal;break;
		case "6":content6Summary = cookieVal;break;
		case "7":content7Summary = cookieVal;break;
		case "8":content8Summary = cookieVal;break;
		case "9":content9Summary = cookieVal;break;
		case "10":content10Summary = cookieVal;break;
		case "11":content11Summary = cookieVal;break;
		case "12":content12Summary = cookieVal;break;
		case "13":content13Summary = cookieVal;break;
		case "14":content14Summary = cookieVal;break;
		case "15":content15Summary = cookieVal;break;
		case "16":content16Summary = cookieVal;break;
		case "17":content17Summary = cookieVal;break;
		case "18":content18Summary = cookieVal;break;
		case "19":content19Summary = cookieVal;break;
		case "20":content20Summary = cookieVal;break;
		case "21":content21Summary = cookieVal;break;
		case "22":content22Summary = cookieVal;break;
				
		default: alert("Not a defined module number");
	}
	createCookie(cookieName,cookieVal,"1");
}

function processUserPrefs(){
	//Setting the value of the user prefs via the DOM cannot be done because
	//the HTML is written to the page onclick of the menu. The best we can do
	//in the short term is to check to see if the values have changed. If so
	//process the change and set the cookie. The usability issue is that the
	//prefs will never reflect the current state - possibly confusing the user.
	var userChangedSummaryValue = false;
	var formSummaryValues = document.allSummaryValuesForm;
	var radioSummary, checkedRadioSummary;
	for(radioSummary = 0; radioSummary < formSummaryValues.length; radioSummary++) {
		if(formSummaryValues[radioSummary].checked) {
			checkedRadioSummary = formSummaryValues[radioSummary].value;
			userChangedSummaryValue = true;
		}
	}
	var userChangedAppcValue = false;
	var formAppcValues = document.allAppcValuesForm;
	var radioAppc, checkedRadioAppc;
	for(radioAppc = 0; radioAppc < formAppcValues.length; radioAppc++) {
		if(formAppcValues[radioAppc].checked) {
			checkedRadioAppc = formAppcValues[radioAppc].value;
			userChangedAppcValue = true;
		}
	}
	if(userChangedSummaryValue){
		setAllSummaryValues(checkedRadioSummary);
	}
	if(userChangedAppcValue){
		setAllAppcValues(checkedRadioAppc);
	}
	if(userChangedSummaryValue == false && userChangedAppcValue == false){
		alert("No changes have been made.");
		return;
	}
	document.location.reload();
	/*
	var appcBox = g("allAppcValuesSelectBox");
	var summariesBox = g("allSummaryValuesSelectBox");
	var appcValue = appcBox.options[appcBox.selectedIndex].value;
	var summariesValue = summariesBox.options[summariesBox.selectedIndex].value;
	if(userChangedAppcValue && appcValue != "none"){
		//alert(appcValue + " -- " + defaultAppc);
		setAllAppcValues("allAppcValuesSelectBox");
	}
	if(userChangedSummariesValue && summariesValue != "none"){
		//alert(summariesValue + " -- " + defaultSummary);
		setAllSummaryValues("allSummaryValuesSelectBox");
	}
	document.location.reload();
	*/
}

function setAllAppcValues(oValue){
	var cookieValue = oValue;
	createCookie("prefValAppc",cookieValue,"1");
	createCookie("m1appc",cookieValue,"1");
	createCookie("m2appc",cookieValue,"1");
	createCookie("m3appc",cookieValue,"1");
	createCookie("m4appc",cookieValue,"1");
	createCookie("m5appc",cookieValue,"1");
	createCookie("m6appc",cookieValue,"1");
	createCookie("m7appc",cookieValue,"1");
	createCookie("m8appc",cookieValue,"1");
	createCookie("m9appc",cookieValue,"1");
	createCookie("m10appc",cookieValue,"1");
	createCookie("m11appc",cookieValue,"1");
	createCookie("m12appc",cookieValue,"1");
	createCookie("m13appc",cookieValue,"1");
	createCookie("m14appc",cookieValue,"1");
	createCookie("m15appc",cookieValue,"1");
	createCookie("m16appc",cookieValue,"1");
	createCookie("m17appc",cookieValue,"1");
	createCookie("m18appc",cookieValue,"1");
	createCookie("m19appc",cookieValue,"1");
	createCookie("m20appc",cookieValue,"1");
	createCookie("m21appc",cookieValue,"1");
	createCookie("m22appc",cookieValue,"1");

}


function setAllSummaryValues(oValue){
	var cookieValue = oValue;
	createCookie("prefValSummary",cookieValue,"1");
	createCookie("m1sum",cookieValue,"1");
	createCookie("m2sum",cookieValue,"1");
	createCookie("m3sum",cookieValue,"1");
	createCookie("m4sum",cookieValue,"1");
	createCookie("m5sum",cookieValue,"1");
	createCookie("m6sum",cookieValue,"1");
	createCookie("m7sum",cookieValue,"1");
	createCookie("m8sum",cookieValue,"1");
	createCookie("m9sum",cookieValue,"1");
	createCookie("m10sum",cookieValue,"1");
	createCookie("m11sum",cookieValue,"1");
	createCookie("m12sum",cookieValue,"1");
	createCookie("m13sum",cookieValue,"1");
	createCookie("m14sum",cookieValue,"1");
	createCookie("m15sum",cookieValue,"1");
	createCookie("m16sum",cookieValue,"1");
	createCookie("m17sum",cookieValue,"1");
	createCookie("m18sum",cookieValue,"1");
	createCookie("m19sum",cookieValue,"1");
	createCookie("m20sum",cookieValue,"1");
	createCookie("m21sum",cookieValue,"1");
	createCookie("m22sum",cookieValue,"1");

}

function clearForm(oTarget){
	if(oTarget.value == "Search" && oTarget.className == "searchInput"){
		oTarget.value = "";
	}
	oTarget.className = "searchInputFocus";
}

//document.onmousedown = hideAllMenusNoDelay();
function hideAllMenusNoDelay(){
	if(menuStateVisible){
		clearTimeout(menuTimer);
		g("searchMenuContainer").style.display = "none";
		g("searchTermMenuContainer").style.display = "none";
	}
}

/////////////////////////////////////////////////////////////////////
/*Utility Functions*/
/////////////////////////////////////////////////////////////////////
var theGenerator = new idGenerator();
function idGenerator(){
	var lastId = 0;
	this.generateId = function(qualifierText){
		return qualifierText + (lastId++);
	}
	return this;
}

/*function g is a shortcut for getElementById*/
function g(elementId,noAlert){
	if(document.getElementById(elementId)){
		return document.getElementById(elementId);
	}else{
		if(!noAlert){
			msg = "Error: the element '" + elementId + "' was not found in Document.\n\n";
			callingFunct = g.caller.toString();
			funcName = callingFunct.substr(0,callingFunct.indexOf("{"));
			address = location.href;
			page = address.substr(address.lastIndexOf("/") + 1);
			msg += funcName + ", running in " + page + ", was looking for it.";
			alert(msg);
		}
		return false;
	}
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function removeElement(oElement){
	var element = g(oElement);
	element.parentNode.removeChild(element);
}

function getAbsolutePositionX(oTarget){
	var apx = 0;
	if(oTarget.offsetParent){
		apx = oTarget.offsetLeft;
		while(oTarget = oTarget.offsetParent){
			apx += oTarget.offsetLeft;
		}
	}
	return apx;
}

function getAbsolutePositionY(oTarget){
	var apy = 0;
	if(oTarget.offsetParent){
		apy = oTarget.offsetTop;
		while(oTarget = oTarget.offsetParent){
			apy += oTarget.offsetTop;
		}
	}
	return apy;
}

function getBrowserSize()
{
	// Compute the bottom of the popup window and the bottom of
	// the browser window, in absolute co-ordinates - different
	// on all browsers but the below should be accurate usually!
	var browserBottom = 0;
	if(typeof(window.innerHeight) == 'number'){//FF
		browserBottom = window.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight){//IE7
		browserBottom = document.documentElement.clientHeight;
	}else if(document.body && document.body.clientHeight){//not sure which browser this detects - maybe Opera or old IE
		browserBottom = document.body.clientHeight;
	}//pageYOffset is for scroll position needed by some browsers
	if(typeof(window.pageYOffset) == 'number'){//FF
		browserBottom = browserBottom + window.pageYOffset;
	}else if(document.body && document.body.scrollTop){
		browserBottom = browserBottom + document.body.scrollTop;
	}else if(document.documentElement && document.documentElement.scrollTop){
		browserBottom = browserBottom + document.documentElement.scrollTop;
	}
	var browserRight = 0;
	if(typeof(window.innerWidth) == 'number'){
		browserRight = window.innerWidth;
	}else if(document.documentElement && document.documentElement.clientWidth){
		browserRight = document.documentElement.clientWidth;
	}else if(document.body && document.body.clientWidth){
		browserRight = document.body.clientWidth;
	}
	if(typeof(window.pageXOffset) == 'number'){
		browserRight = browserRight + window.pageXOffset;
	}else if(document.body && document.body.scrollLeft){
		browserRight = browserRight + document.body.scrollLeft;
	}else if(document.documentElement && document.documentElement.scrollLeft){
		browserRight = browserRight + document.documentElement.scrollLeft;
	}
	return [browserBottom,browserRight];
}

function formatDayOfWeek(dayOfWeek){
	var currentDay = dayOfWeek.toString();
	switch(currentDay){
		case "0":currentDay = "Sunday";break;
		case "1":currentDay = "Monday";break;
		case "2":currentDay = "Tuesday";break;
		case "3":currentDay = "Wednesday";break;
		case "4":currentDay = "Thursday";break;
		case "5":currentDay = "Friday";break;
		case "6":currentDay = "Saturday";break;
		default:alert('Day integer does not exist.');
	}
	return(currentDay);
}
	
function formatMonth(month){
	var currentMonth = month.toString();
	switch(currentMonth){
		case "0":currentMonth = "January";break;
		case "1":currentMonth = "February";break;
		case "2":currentMonth = "March";break;
		case "3":currentMonth = "April";break;
		case "4":currentMonth = "May";break;
		case "5":currentMonth = "June";break;
		case "6":currentMonth = "July";break;
		case "7":currentMonth = "August";break;
		case "8":currentMonth = "September";break;
		case "9":currentMonth = "October";break;
		case "10":currentMonth = "November";break;
		case "11":currentMonth = "December";break;
		default:alert('Month integer does not exist.');
	}
	return(currentMonth);
}

function formatTime(time){
	var timePieces = time.split(":")
	var hours = timePieces[0];
	var minutes = timePieces[1];
	//Begin: BW - resolve bug 15
	if (minutes != undefined)
	{
			if(minutes.length == 1){
			minutes = "0" + minutes;
			}
	}
	//End: BW - resolve bug 15
	if(parseInt(hours) >= 12){
		switch(hours){
			case "12":hours = 12;break;
			case "13":hours = 1;break;
			case "14":hours = 2;break;
			case "15":hours = 3;break;
			case "16":hours = 4;break;
			case "17":hours = 5;break;
			case "18":hours = 6;break;
			case "19":hours = 7;break;
			case "20":hours = 8;break;
			case "21":hours = 9;break;
			case "22":hours = 10;break;
			case "23":hours = 11;break;
			default:hours = "?";
		}
		daySection = " pm";
	}else{
		if(hours.charAt(0) == "0"){
			if(hours == "00"){
				hours = "12";
			}else{
				hours = hours.charAt(1);
			}
		}
		daySection = " am";
	}
	time = hours + ":" + minutes + daySection;
	return time;
}

function cssSwitch(styleSheetName){
	createCookie("style",styleSheetName,"7");
	window.location.reload();
}

function emailArticle(oSrc){
	var emailHtml = "";
	var emailPreNumber = oSrc.id.split("emailArticleLinkcontent")[1];
	var emailNumber = emailPreNumber.substr(1,emailPreNumber.length);
	var titleBeforeBreak = g("titlecontent" + emailPreNumber).innerHTML;
	var title = titleBeforeBreak.substr(0, titleBeforeBreak.length - 4);
	var href = g("titlecontent" + emailPreNumber).href;
	var date = g("datecontent" + emailPreNumber).innerHTML;
	var time = g("timecontent" + emailPreNumber).innerHTML;
	var source = g("sourcecontent" + emailPreNumber).innerHTML;
	var summary = g("articleDevSummaryBoxcontent" + emailPreNumber).innerHTML;
	emailHtml += encodeURIComponent(title) + "%0A" + encodeURIComponent(href) + "%0A%0A" + encodeURIComponent(source) + "%20%20%20" + date + "%20" + time + "%0A" + encodeURIComponent(summary);
	var email = "mailto:%20?Subject=" + emailArticleSubjectLine + "&body=" + emailHtml;
	window.location = email;
}

function openNewWindow(url){
	var newWindow = window.open(url,"ViewAll");

	newWindow.focus();
	return false;
}

function renderPage(){
	setHeights();
	setModuleVisibility();
}

function setHeights(){
	var twoColumnLayout = false;
	var rowCount = numberOfModules / 2;
	titleBarOffsetheightsArray = new Array();
	resultsBoxOffsetheightsArray = new Array();
	
	//Determine if the page is two column layout by using styleSheet object
	/* Firefox 3 is choking on this for some reason. Do not use.
	var hrefString;
	var cssFiles = document.styleSheets;
	for (var cssFile = 0; cssFile < cssFiles.length; cssFile++){
		hrefString = cssFiles[cssFile].href.toString();
    //alert(hrefString + " -- " + hrefString.indexOf("fixed_col_2.css"))
		if(hrefString.indexOf("fixed_col_2.css") != -1){
			twoColumnLayout = true;
		}
	}
	*/
	//Determine if the page is two column layout by checking .pocketModule class width
	var moduleBoxes = getElementsByClassName(document.body, "div", "pocketModule");
	for (var moduleBox = 0; moduleBox < moduleBoxes.length; moduleBox++){
		if(moduleBoxes[moduleBox].offsetWidth == "395"){
			twoColumnLayout = true;
		}
	}

	if(twoColumnLayout){
	
		if(numberOfModules > 1){
			/* Code for all modules same height
			var titleBars = getElementsByClassName(document.body, "div", "pocketToolBar");
			for (var titleBar = 0; titleBar < titleBars.length; titleBar++){
				titleBarOffsetheightsArray.push(titleBars[titleBar].offsetHeight);
			}
			var tallestTitleBarHeight = titleBarOffsetheightsArray.sort(sortNumber).reverse();
			for (var iTitleBar = 0; iTitleBar < titleBars.length; iTitleBar++){
					titleBars[iTitleBar].style.minHeight = parseInt(tallestTitleBarHeight[0]) + "px";
			}
			
			var resultsBoxes = getElementsByClassName(document.body, "div", "pocketBody350");
			for (var resultsBox = 0; resultsBox < resultsBoxes.length; resultsBox++){
				resultsBoxOffsetheightsArray.push(resultsBoxes[resultsBox].offsetHeight);
			}
			var tallestResultsBoxHeight = resultsBoxOffsetheightsArray.sort(sortNumber).reverse();
			for (var iResultsBox = 0; iResultsBox < resultsBoxes.length; iResultsBox++){
					resultsBoxes[iResultsBox].style.minHeight = parseInt(tallestResultsBoxHeight[0]) + "px";
			}
			*/
			var titleBarsCounter = 1;
			for (var row = 0; row < rowCount; row++){
				var titleBarA = g("pocketToolBar" + ((titleBarsCounter * 2) - 1));
				var titleBarB = g("pocketToolBar" + (titleBarsCounter * 2));
				var tallestOffsetHeight = compareHeights(titleBarA.offsetHeight, titleBarB.offsetHeight);
				if(/MSIE 6/i.test(navigator.userAgent)){//Determine if browser is IE6
					titleBarA.style.height = tallestOffsetHeight + "px";
					titleBarB.style.height = tallestOffsetHeight + "px";
				}else{
					titleBarA.style.minHeight = tallestOffsetHeight + "px";
					titleBarB.style.minHeight = tallestOffsetHeight + "px";
				}
				titleBarsCounter++;
			}
			
			var resultsBoxesCounter = 1;
			
			//createCookie("style",styleSheetName,"7");
			

		    for (var row = 0; row < rowCount; row++){
			    var resultsBoxA = g("content" + ((resultsBoxesCounter * 2) - 1) + "ContainerScrollable");
			    var resultsBoxB = g("content" + (resultsBoxesCounter * 2) + "ContainerScrollable");
			    var tallestOffsetHeight = compareHeights(resultsBoxA.offsetHeight, resultsBoxB.offsetHeight);
			    if(/MSIE 6/i.test(navigator.userAgent)){//Determine if browser is IE6; returns true if IE6
				    resultsBoxA.style.height = tallestOffsetHeight + "px";
				    resultsBoxB.style.height = tallestOffsetHeight + "px";
			    }else{
				    resultsBoxA.style.minHeight = tallestOffsetHeight + "px";
				    resultsBoxB.style.minHeight = tallestOffsetHeight + "px";
			    }
			    resultsBoxesCounter++;
			    //IE6 CSS fix: #content{min-height:200px;height:auto !important;height:200px}
		    }
		}
	}
}

function compareHeights(value1, value2){
	if(value1 > value2){
		return value1;
	}else if(value2 > value1){
		return value2;
	}else{//equal
		return value1;
	}
}

function sortNumber(a,b){
	return a - b;
}

function setModuleVisibility(){
	g("pageBoxContentContainerDiv").className = "pageBoxContentContainer";
}


