function StoriesIndex() { this.scripts = new Array(); this.stories = new Array(); this.searchScripts = new Array(); this.searchStories = new Array(); this.searchCounts = new Array(); if(typeof StoriesIndex._initialized == "undefined") { //Function used to add filters // type = search type // cat = category // start = start of results // end = end of results StoriesIndex.prototype.addFilter = function(type,cat,start,count,label) { var arIndex = this.scripts.length - 1; if(arIndex < 0)arIndex = 0; this.scripts.push(new Filter(type,cat,start,count,label)); }; StoriesIndex.prototype.addSearch = function(query,start,count,searchOrder,label) { var arIndex = this.scripts.length - 1; if(arIndex < 0)arIndex = 0; this.searchScripts.push(new Search(query,start,count,searchOrder,label)); }; StoriesIndex.prototype.load = function()//Function used to load ajax calls from object 'Filter' { for(var i = 0; i < this.scripts.length; i++) { this.extractViewResults(this.scripts[i].loadAjax(),this.scripts[i].label); } }; StoriesIndex.prototype.loadSearch = function()//Function used to load ajax calls from object 'Filter' { for(var i = 0; i < this.searchScripts.length; i++) { this.extractSearchResults(this.searchScripts[i].loadAjax(),this.searchScripts[i].label); } }; StoriesIndex.prototype.loadSearchCount = function()//Function used to load ajax calls from object 'Filter' { if(!this.searchScripts)return null; for(var i = 0; i < this.searchScripts.length; i++) { eval(this.searchScripts[i].loadCountAjax()); if(this.searchScripts[i].label) { var newSearchCount = eval('searchElements' + this.searchScripts[i].label); } else { var newSearchCount = searchElements; } this.searchCounts[i] = parseInt(newSearchCount); newSearchCount = null; } }; StoriesIndex.prototype.extractSearchResults = function(funcStr,label) { eval(funcStr); if(label) { var newSearchResults = eval('searchResults' + label); } else { var newSearchResults = searchResults; } if(typeof newSearchResults == "object" && newSearchResults.length > 0) { for(var i = 1; i < newSearchResults.length; i++) { if(unescape(newSearchResults[i].viewTitle) != 'No items available.') { this.searchStories.push(new ArticleSearchObject(newSearchResults[i].viewDocID,newSearchResults[i].viewTitle,newSearchResults[i].viewSummary,newSearchResults[i].viewArticleAuthorName,newSearchResults[i].viewPageDate,newSearchResults[i].viewIssue,newSearchResults[i].viewSection,newSearchResults[i].viewCategories,newSearchResults[i].viewGeography,newSearchResults[i].viewCompanies,newSearchResults[i].viewTreePath)); } } } newSearchResults = null; }; //Function used to extract results from ajax call // funcStr = text response from ajax call StoriesIndex.prototype.extractViewResults = function(funcStr) { eval(funcStr); if(typeof viewResults == "object" && viewResults.length > 0) { for(var i = 1; i < viewResults.length; i++) { this.stories.push(new ArticleObject(viewResults[i].viewDocID,viewResults[i].viewTitle,viewResults[i].viewSummary,viewResults[i].viewArticleAuthorName,viewResults[i].viewPageDate,viewResults[i].viewIssue,viewResults[i].viewSection,viewResults[i].viewStoryAccess,viewResults[i].viewParentID,viewResults[i].viewCategories,viewResults[i].viewGeography,viewResults[i].viewCompanies,viewResults[i].viewTreePath)); } } viewResults = null; }; StoriesIndex.prototype.recreateViewResults = function() { viewResults = new Array(); for(var i = 0; i < this.stories.length; i++) { viewResults.push(this.stories[i].copy()); } var oText = document.createElement('textarea'); oText.id = 'displayBox'; oText.setAttribute('rows','100'); oText.setAttribute('cols','80'); document.getElementById('edDeskBody').appendChild(oText); var str = ""; for(var i =0; i < viewResults.length; i++) { str += '\n' + unescape(viewResults[i].viewPageDate) + " " + unescape(viewResults[i].viewSection); } document.getElementById('displayBox').value = '\n\n' + str; }; //Function to sort stories in chronological order // storiesCount = number of items to be stores in variable 'stories' StoriesIndex.prototype.sortStories = function(storiesCount) { /* var oText = document.createElement('textarea'); oText.id = 'displayBox'; oText.style.position = "absolute"; oText.setAttribute('rows','60'); oText.setAttribute('cols','100'); document.getElementById('edDeskBody').appendChild(oText); var str = ""; for(var i =0; i < this.stories.length; i++) { str += '\n' + unescape(this.stories[i].viewPageDate) + " " + unescape(this.stories[i].viewSection) + " " + (unescape(this.stories[i].viewTitle)).substring(0,10); } document.getElementById('displayBox').value = str; var sortStr = ""; */ var tempArray = new Array(); //tempArray.push(this.stories[0]); for(var i = 0; i < this.stories.length; i++) { tempArray.push(this.stories[i]); } for(var i = 0; i < tempArray.length; i++) { //sortStr += '\n\n' + i + ' '; for(var n = i + 1 ; n < tempArray.length; n++) { var curDate = this.createDate(tempArray[i].viewPageDate); var newDate = this.createDate(tempArray[n].viewPageDate); //alert(curDate.toString() + " " + newDate.toString()); if(newDate > curDate) { var tempStory = tempArray[i]; tempArray[i] = tempArray[n]; tempArray[n] = tempStory; //sortStr += '| i:' + i + ' n:' + n; } } } if(storiesCount > tempArray.length) { var count = tempArray.length; } else { var count = storiesCount; } this.stories = new Array(); for(var i = 0; i < count; i ++) { this.stories.push(tempArray[i].copy()); } /* var str = ""; for(var i =0; i < this.stories.length; i++) { str += '\n' + unescape(this.stories[i].viewPageDate) + " " + unescape(this.stories[i].viewSection) + " " + (unescape(this.stories[i].viewTitle)).substring(0,10); } document.getElementById('displayBox').value = document.getElementById('displayBox').value + '\n\n' + str + sortStr; */ }; StoriesIndex.prototype.createDate = function(aDate) { var arDate = (unescape(aDate)).split('/'); return new Date(Date.UTC(arDate[2],((parseFloat(arDate[1])) - 1).toString(),arDate[0])); }; StoriesIndex.prototype.removeSearchCurArticle = function() { var tempArray = new Array(); for(var i = 0; i < this.searchStories.length; i++) { var curDocId = (document.forms[0].DocID && document.forms[0].DocID.value.length > 0) ? document.forms[0].DocID.value : null; var story = this.searchStories[i]; if(!curDocId || curDocId != story.viewDocID)//if article is not currently displayed { tempArray.push(story); } } this.searchStories = tempArray; }; } StoriesIndex._initialized = true; } function Filter(type,cat,start,count,label)//Object to manage ajax calls { this.type = type; this.cat = cat; this.start = start; this.count = count; this.label = label; if(typeof Filter._intialized == "undefined") { Filter.prototype.getURL = function()//Function used to build url with filter { var myDate = new Date(); var t = myDate.getTime(); if(this.label) { return Filter._urlPrefix + '&type=' + this.type + '&cat=' + escape(this.cat) + '&start=' + this.start + '&count=' + this.count + '&t=' + t + '&label=' + this.label; } else { return Filter._urlPrefix + '&type=' + this.type + '&cat=' + escape(this.cat) + '&start=' + this.start + '&count=' + this.count + '&t=' + t; } }; Filter.prototype.loadAjax = function()//Function used to make the ajax call { var oXHR = createXHR(); oXHR.open('GET',this.getURL(),false); oXHR.send(null); return oXHR.responseText; }; } Filter._initialiazed = true; Filter._urlPrefix = '/wheels/site/filter.js?readform'; // static var used to store the url prefix of search } /* function loadViewResults() { alert(viewResults.length); } */ // mimic viewResults function ArticleObject(viewDocID,viewTitle,viewSummary,viewArticleAuthorName,viewPageDate,viewIssue,viewSection,viewStoryAccess,viewParentID,viewCategories,viewGeography,viewCompanies,viewTreePath) { this.viewDocID=viewDocID; this.viewTitle=viewTitle; this.viewSummary=viewSummary; this.viewArticleAuthorName=viewArticleAuthorName; this.viewPageDate=viewPageDate; this.viewIssue=viewIssue; this.viewSection=viewSection; this.viewStoryAccess=viewStoryAccess; this.viewParentID=viewParentID; this.viewCategories=viewCategories; this.viewGeography=viewGeography; this.viewCompanies=viewCompanies; this.viewTreePath=viewTreePath; if(typeof ArticleObject._initialized == "undefined") { ArticleObject.prototype.copy = function() { return new ArticleObject(this.viewDocID,this.viewTitle,this.viewSummary,this.viewArticleAuthorName,this.viewPageDate,this.viewIssue,this.viewSection,this.viewStoryAccess,this.viewParentID,this.viewCategories,this.viewGeography,this.viewCompanies,this.viewTreePath); }; } } function Search(query,start,count,searchOrder,label)//Object to manage ajax calls { this.query = query; this.start = start; this.count = count; this.searchOrder = searchOrder; this.label = label; if(typeof Search._intialized == "undefined") { Search.prototype.getSearchURL = function()//Function used to build url with Search { var urlSuffix = new Array(); urlSuffix.push('&query=' + this.query); if(this.start)urlSuffix.push('&start=' + this.start); if(this.count)urlSuffix.push('&count=' + this.count); if(this.searchOrder)urlSuffix.push('&SearchOrder=' + this.searchOrder); if(this.label)urlSuffix.push('&label=' + this.label); return (Search._urlSearchPrefix + urlSuffix.join('')); }; Search.prototype.getCountSearchURL = function()//Function used to build url with Search { var urlSuffix = new Array(); urlSuffix.push('&query=' + this.query); if(this.searchOrder)urlSuffix.push('&SearchOrder=' + this.searchOrder); if(this.label)urlSuffix.push('&label=' + this.label); return (Search._urlCountSearchPrefix + urlSuffix.join('')); }; Search.prototype.loadAjax = function()//Function used to make the ajax call { var oXHR = createXHR(); oXHR.open('GET',this.getSearchURL(),false); oXHR.send(null); return oXHR.responseText; }; Search.prototype.loadCountAjax = function()//Function used to make the ajax call { var oXHR = createXHR(); oXHR.open('GET',this.getCountSearchURL(),false); oXHR.send(null); return oXHR.responseText; }; } Search._initialiazed = true; Search._urlSearchPrefix = '/wheels/site/search.js?open'; // static var used to store the url search prefix of search Search._urlCountSearchPrefix = '/wheels/site/countsearch.js?open'; // static var used to store the url count search prefix of search } function ArticleSearchObject(viewDocID,viewTitle,viewSummary,viewArticleAuthorName,viewPageDate,viewIssue,viewSection,viewCategories,viewGeography,viewCompanies,viewTreePath) { this.viewDocID=viewDocID; this.viewTitle=viewTitle; this.viewSummary=viewSummary; this.viewArticleAuthorName=viewArticleAuthorName; this.viewPageDate=viewPageDate; this.viewIssue=viewIssue; this.viewSection=viewSection; this.viewCategories=viewCategories; this.viewGeography=viewGeography; this.viewCompanies=viewCompanies; this.viewTreePath=viewTreePath; if(typeof ArticleSearchObject._initialized == "undefined") { ArticleSearchObject.prototype.copy = function() { return new ArticleSearchObject(this.viewDocID,this.viewTitle,this.viewSummary,this.viewArticleAuthorName,this.viewPageDate,this.viewIssue,this.viewSection,this.viewCategories,this.viewGeography,this.viewCompanies,this.viewTreePath); }; } ArticleSearchObject._initialized = true; } function createXHR() //create cross-browser XHR object { if (typeof XMLHttpRequest != "undefined") { return new XMLHttpRequest(); } else if (window.ActiveXObject) { var aVersions = [ "MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0"]; for (var i = 0; i < aVersions.length; i++) { try { var oXHR = new ActiveXObject(aVersions[i]); return oXHR; } catch (oError) { //Do nothing } } } throw new Error("XMLHttp object could not be created."); }