function Nsec(h,m,s) { return 3600*h + 60*m + s; }

function NsecDT(year,mon1r,day1r,h,m,s) { return (Nday(year,mon1r,day1r)-1)*86400 + Nsec(h,m,s); }

function Nday(year,mon1r,day1r)
{
 if (year%4==0)
 {
  var Mesb = new Array(0,31,60,91,121,152,182,213,244,274,305,335);
  return ((year-81)%100)*365 + Math.floor(((year-81)%100)/4) + Mesb[mon1r-1] + day1r;
 }
 else
 {
  var Mes = new Array(0,31,59,90,120,151,181,212,243,273,304,334);
  return ((year-81)%100)*365 + Math.floor(((year-81)%100)/4) + Mes[mon1r-1] + day1r;
 }
}

function isDigit(n) { return n>='0' && n<='9'; }

// dt in "Dayname, DD-Mon-YYYY HH:MM:SS" format
function Nsec1d(dt)
{
 var p = dt.indexOf(" ",0);
 if (p<0) return 0;
 p++;

 if (!isDigit(dt.charAt(p)) || !isDigit(dt.charAt(p+1))) return 0;
 var d1r = 10*(+dt.charAt(p)) + (+dt.charAt(p+1));
 p += 3;

 var Months = " Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
 var m1r = Months.indexOf(" "+dt.substring(p,p+3)+" ",0);
 p += 4;
 if (m1r<0) return 0;
 m1r /= 4; m1r++;

 var year=dt.substring(p,p+4)-0;
 p += 5;

 return NsecDT(year,m1r,d1r,+dt.substring(p,p+2),+dt.substring(p+3,p+5),+dt.substring(p+6,p+8));
}

var serverTs = Math.floor(Nsec1d(servertimegmt)/60);
difTs = serverTs-gmtts;
if (difTs<0) difTs=0;
if (mww && difTs>=5)
{
 document.write('<br><center><IMG SRC="/gif/colbar.gif" WIDTH="600" HEIGHT="5" ALIGN="center" NATURALSIZEFLAG="3"><br><h4>');
 document.write("Hmmm, you may have an old copy of this page in your browser's cache. Please, try to reload it...<br><br>");

 document.write("If you still see this message after reloading, that means the Market Watch engine has been down for "+difTs+" minutes.<br>");
 if (difTs<10)
    document.write("Most likely the engine PC is just rebooting, in which case it should restart soon.<br>");
 else if (difTs<25)
    document.write("This is probably due to some temporary problem with my ISP's FTP server.<br>");
 else if (difTs<120)
    document.write("This is probably due to a power failure or some problem with my ISP's ftp server.<br>");
 else
    document.write('This is probably due to some severe power failure or ISP server malfunction,<br>or maybe the engine PC has simply died. That happens.<br>');
 document.write("Anyway, the Market Watch reports won't show the items posted in those last "+difTs+" minutes.<br>");
 document.write("Sorry for the inconvenience and please check this page later.<br><br>The Market Watch Watchdog.<br>");
 document.write('</h4><IMG SRC="/gif/colbar.gif" WIDTH="600" HEIGHT="5" ALIGN="center" NATURALSIZEFLAG="3"><br></center><br>');
}

