var age = new Date('Mon Feb 6 21:49:32 2012 '); var svrPageLoadedinSecs = 55; var serverLoaded = new Date('Mon Feb 6 21:48:37 2012 '); var serverDate=getServerDate(); var deltaServerInSeconds = parseInt( (new Date(serverDate).getTime() - age.getTime()) / 1000); var deltaInSeconds = parseInt( (new Date( ).getTime() - age.getTime()) / 1000); function elapsedTime (ageInSeconds) { //var ageInSeconds = parseInt((new Date().getTime() - new Date(createdAt).getTime()) / 1000); var s = function(n) { return n == 1 ? '' : 's' }; if (ageInSeconds < 0) { return 'reciĆ©n'; } if (ageInSeconds < 60) { var n = ageInSeconds; return 'hace ' + n + ' segundo' + s(n); } if (ageInSeconds < 60 * 60) { var n = Math.floor(ageInSeconds/60); return 'hace ' + n + ' minuto' + s(n); } if (ageInSeconds < 60 * 60 * 24) { var n = Math.floor(ageInSeconds/60/60); return 'hace ' + n + ' hora' + s(n); } if (ageInSeconds < 60 * 60 * 24 * 7) { var n = Math.floor(ageInSeconds/60/60/24); return 'hace ' + n + ' día' + s(n); } if (ageInSeconds < 60 * 60 * 24 * 31) { var n = Math.floor(ageInSeconds/60/60/24/7); return 'hace ' + n + ' semana' + s(n); } if (ageInSeconds < 60 * 60 * 24 * 365) { var n = Math.floor(ageInSeconds/60/60/24/31); return 'hace ' + n + ' mes' + s(n); } var n = Math.floor(ageInSeconds/60/60/24/365); return 'hace ' + n + ' año' + s(n) ; } function getServerDate() { var oRequest = new XMLHttpRequest(); var sURL = "http://"+self.location.hostname+"/date.php"; oRequest.open("GET",sURL += (sURL.match(/\?/) == null ? "?" : "&") + (new Date()).getTime(), false); oRequest.setRequestHeader("User-Agent",navigator.userAgent); oRequest.send(null) if (oRequest.status==200) { return oRequest.responseText; } else { //alert("Error executing XMLHttpRequest call!"); return ""; } } function getDelta($thisdate){ var thetime = new Date(); return parseInt((thetime.getTime() - $thisdate ) /1000) - deltaInSeconds + deltaServerInSeconds; /* var elapsedsecs = parseInt((thetime.getTime() - age.getTime() ) /1000) - deltaInSeconds + deltaServerInSeconds; */ } function roll(me, cb_news) { // var cb_news = getChildById(me, "cb_" + me.id); var el_news = getChildById(me, "news_" + me.id); if (el_news != null) { var expand = (el_news.style.display=="none"); el_news.style.display = (expand ? "block" : "none"); if (cb_news != null ) { cb_news.innerHTML = (expand ? "-" : "M" ); } }; } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } function init_deltas(){ serverDate=getServerDate(); deltaServerInSeconds = parseInt( (new Date(serverDate).getTime() - age.getTime()) / 1000); } addLoadEvent(init_deltas);