function MostRecentComments() { if(typeof MostRecentComments._initialized == 'undefined') { MostRecentComments.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."); }; MostRecentComments.prototype.load = function(obj)//Function used to make the ajax call { oXHR = this.createXHR(); var myDate = new Date(); var t = myDate.getTime(); //oXHR.onreadystatechange = eval(obj + '.loadXML'); oXHR.open('GET','/wheels/tools/talkback/By+Date+non+alpha?readviewentries&ExpandView&count=5&t=' + t,false); oXHR.send(null); this.loadXML(oXHR.responseXML); }; MostRecentComments.prototype.loadXML = function(oXML)//Function used to make the ajax call { var entries = oXML.getElementsByTagName('viewentry'); if(!entries)return; this.comments = new Array(); for(var i = 0; i < entries.length; i++) { var cDate = entries[i].getElementsByTagName('datetime')[0].firstChild.nodeValue; var texts = entries[i].getElementsByTagName('text'); var cAuthor = "site user"; if(texts[0].firstChild)cAuthor = texts[0].firstChild.nodeValue; if(texts[1].firstChild)var cArticle = texts[1].firstChild.nodeValue; if(texts[2].firstChild)var cBody = texts[2].firstChild.nodeValue; if(cArticle && cBody) { if(!cDate)cDate = new Date(); // this.comments.push('str'); this.comments.push(new RecentComment(cDate,cAuthor,cArticle,cBody)); //alert(this.comments[this.comments.length - 1].getStr()); } } }; MostRecentComments.prototype.attach = function(oP) { if(!this.comments || this.comments.length == 0)return; oP.className = 'comments'; for(var i=0; i < this.comments.length; i++) { this.comments[i].attach(oP); } }; MostRecentComments.prototype.loaded = function() { if(!this.comments || !(this.comments instanceof Array) || this.comments.length == 0)return false; return true; }; } MostRecentComments._initialized = true; } function RecentComment(rcDate,rcAuthor,rcArticle,rcBody) { if(typeof RecentComment._initialized == 'undefined') { RecentComment.prototype.load = function(rcDate,rcAuthor,rcArticle,rcBody) { this.rcDate = rcDate; this.rcAuthor = rcAuthor; this.rcArticle = rcArticle; this.rcTitle = this.extractTitle(rcArticle); this.rcArticleID = this.extractArticleID(rcArticle); this.rcBody = rcBody; }; RecentComment.prototype.extractTitle = function(str) { var end = str.indexOf('('); return str.substring(0,end); }; RecentComment.prototype.extractArticleID = function(str) { var start = str.indexOf('(') + 1; var end = str.indexOf(')'); return str.substring(start,end); }; RecentComment.prototype.attach = function(oP) { var oSpan = document.createElement('span'); oSpan.appendChild(document.createTextNode('Posted by ' + this.rcAuthor)); oP.appendChild(oSpan); oP.appendChild(document.createTextNode(this.rcBody)); var oAnchor = document.createElement('a'); oAnchor.setAttribute('href','/wheels/site/articleIDs/' + this.rcArticleID + '?open&template=domWheels'); oAnchor.appendChild(document.createTextNode(this.rcTitle)); oP.appendChild(oAnchor); }; RecentComment.prototype.getStr = function() { var str = '--------START---------'; str += '\n' + this.rcDate; str += '\n' + this.rcAuthor; str += '\n' + this.rcArticle; str += '\n' + this.rcTitle; str += '\n' + this.rcArticleID; str += '\n' + this.rcBody; return str; }; RecentComment.prototype.loadDate = function(rcDate) { this.rcDate = rcDate; }; } RecentComment._initialized = true; this.load(rcDate,rcAuthor,rcArticle,rcBody); }