function MostPopular() { if(typeof MostPopular._initialized == 'undefined') { MostPopular.prototype.load = function() { //var oXML = this.parseXML(''); var oXML = this.loadAjax(); if(typeof oXML == 'object')//if file has been loaded { var pages = oXML.getElementsByTagName('Page'); this.items = new Array(); for(var i = 0; i < pages.length; i++) { var count = parseInt(pages[i].getAttribute('count')); var text = pages[i].getAttribute('url'); this.items.push(new MPArticle(count,text)); } } }; MostPopular.prototype.parseXML = function(text) { // code for IE if (window.ActiveXObject) { var doc=new ActiveXObject("Microsoft.XMLDOM"); doc.async="false"; doc.loadXML(text); } else { // code for Mozilla, Firefox, Opera, etc. var parser=new DOMParser(); var doc=parser.parseFromString(text,"text/xml"); } return doc; }; MostPopular.prototype.createXHR = function() { 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."); }; MostPopular.prototype.loadAjax = function()//Function used to make the ajax call { var oXHR = this.createXHR(); oXHR.open('GET',MostPopular._fileURL,false); oXHR.send(null); //alert('oXHR.status: ' + oXHR.status); if(!(oXHR.status == 200 || oXHR.status == 304))return 'undefined'; //alert(oXHR.responseXML); return oXHR.responseXML; }; /* MostPopular.prototype.display = function() { var oXML = mostPopular.loadAjax(); var items = oXML.getElementsByTagName('Page'); alert(typeof items); if(!items)return; var str = ""; document.write("
    "); for(var i = 0; i < items.length; i++) { if (items[i].getAttribute('url').match(/(\/\wheels\/site\/articleIDs\/)/)) { var tmpID = items[i].getAttribute('url').replace(/(\/\wheels\/site\/articleIDs\/)|(\?\w*)/ig,""); eval(Article(tmpID)); var tmpTitle = articleResult.Title; var tmpLink = items[i].getAttribute('url'); } else { var tmpTitle = items[i].getAttribute('url').replace(/(\/\w*\/)|(.html)/ig,""); var tmpLink = items[i].getAttribute('url'); } str += "
  1. " + tmpTitle.replace(/\+/ig, " ") + "
  2. "; } document.write('
    ',str,'
    '); if(!this.items)return; var str = ""; for(var i = 0; i < this.items.length; i++) { str += this.items[i].getArticleStr(); } alert(str); document.write("
"); }; */ MostPopular.prototype.display = function() { if(!this.items)return; var str = ""; for(var i = 0; i < this.items.length; i++) { str += this.items[i].getArticleStr(); } alert(str); }; MostPopular.prototype.print = function() { if(!this.items)return; document.write('
'); document.write('

Most Popular Wheels

'); document.write('
    '); for(var i = 0; i < this.items.length; i++) { if(this.items[i].title) { document.write('
  1. ' + this.items[i].print() + '
  2. '); } } document.write('
'); document.write('
'); }; MostPopular.prototype.titleLegal = function(sTitle) { }; } MostPopular._initialized = true; /* if(window.location.toString().indexOf('wheelsmag') == -1) { //MostPopular._fileURL = 'http://wheelsbak.itechne.com/wheels.xml'; MostPopular._fileURL = 'http://wheelsdev.itechne.com/wheels.xml' } else { MostPopular._fileURL = 'http://wheelsmag.com.au/wheels.xml'; } */ MostPopular._fileURL = '/wheels.xml'; } function MPArticle(count,link) { this.count = count; this.link = link; if(typeof MPArticle._initialized == 'undefined') { MPArticle.prototype.load = function() { if(this.link.indexOf('.htm') != -1) { this.loadHumanURL(); } else { this.loadIDURL(); } }; MPArticle.prototype.loadHumanURL = function() { var start = this.link.lastIndexOf('/') + 1; var end = this.link.indexOf('.htm'); this.title = this.link.substring(start,end).replace(/\+/gi,' '); }; MPArticle.prototype.loadIDURL = function() { var start = this.link.indexOf('articleID') + 11; this.docID = this.link.substring(start, start + 32); this.loadArticleTitle(); }; MPArticle.prototype.display = function() { var str =""; str += this.count; str += '\n' + this.link; str += '\n' + this.title; alert(str); }; MPArticle.prototype.print = function() { return ('' + this.title + ''); }; MPArticle.prototype.loadArticleTitle = function() { var article = new StoriesIndex(); var searchQuery = '((([PageType]=article)+or+([PageType]=related))+and+([MainID]=' + this.docID + '))'; article.addSearch(searchQuery,'1','9','3','MPArticle'); article.loadSearch(); if(!article.searchStories || article.searchStories.length == 0)return; this.title = unescape(article.searchStories[0].viewTitle); }; MPArticle.prototype.getArticleStr = function() { var str = "\n\n"; if(this.count) str += '\ncount: ' + this.count; if(this.link) str += '\nlink: ' + this.link; if(this.title) str += '\ntitle: ' + this.title; if(this.docID) str += '\nid: ' + this.docID; return str; }; MPArticle.prototype.valid = function() { if(this.link && this.title)return true; return false; }; } MPArticle._initialized = true; this.load(); } var mostPopular = new MostPopular(); mostPopular.load(); //mostPopular.display(); mostPopular.print();