>function NewsFeedRefresh() { > > window.clearTimeout(oTimerNewsFeed); > > var loDivNewsFeed = document.getElementById("DivNewsFeed"); > > if (loDivNewsFeed) { > > var lnLength = oNewsFeed.length; > > for (var lnCounter = 0; lnCounter < lnLength; lnCounter++) { > > var loID = document.getElementById("LX" + oNewsFeed[lnCounter][1] + "Time"); > > if (loID) > loID.innerHTML = SinceWhen(oNewsFeed[lnCounter][2], oNewsFeed[lnCounter][3]); > } > > oTimerNewsFeed = setTimeout("NewsFeedRefresh()", 60000) > } >} > >var timeMessage = [[["Yesterday","%d days ago"], > ["One hour ago", "%d hours ago"], > ["One minute ago", "%d minutes ago"], > ["Just now", "%d seconds ago"]], > [["Hier", "Il y a %d jours"], > ["Il y a une heure", "Il y a %d heures"], > ["Il y a une minute", "Il y a %d minutes"], > ["Maintenant", "Il y a %d secondes"]]]; > >function SinceWhen (tdDate, tnNoLanguage) { > > var lnSecond = Math.floor(((new Date()).getTime() - tdDate.getTime()) / 1000); > > if (lnSecond >= 86400){ > var lnUnits = Math.floor(lnSecond / 86400); > var lnIndex = 0; > var lnNoUnits = 1; > } else if (lnSecond >= 3600){ > var lnUnits = Math.floor(lnSecond / 3600); > var lnIndex = 1; > var lnNoUnits = 1; > } else if (lnSecond >= 60){ > var lnUnits = Math.floor(lnSecond / 60); > var lnIndex = 2; > var lnNoUnits = 1; > } else { > var lnUnits = lnSecond; > var lnIndex = 3; > var lnNoUnits = 10; > } > > return timeMessage[tnNoLanguage - 1][lnIndex][lnUnits > lnNoUnits ? 1 : 0].replace(/%d/,lnUnits); >} >>One obvious optimization is to call for variable instantiation and maths calculations only when / if needed.