
// --------------------------------------------------------------------------------
function WaitPage(day, month, year, title, text, replace)
{
   this.date = new Date(year, month-1, day, 9, 0, 0);
   this.title = title;
   this.text = text;
   this.replace = replace;
}

// --------------------------------------------------------------------------------
function DisplayWaitOrPage(cssfile)
{
   var today = new Date();

   // waitPage has the date on which to show the real page
   if(waitPage.date.getTime() <= today.getTime())
   {
      DisplayPage();
   }
   else
   {
      DisplayWait(cssfile);
   }
}

// --------------------------------------------------------------------------------
function DisplayPage()
{
   var url = window.location.href;

   if(waitPage.replace.substring(0,4) == "http")
   {
      // If the replacement starts with 'http' then use this URL
      url = waitPage.replace;
   }
   else if(waitPage.replace.substring(0,1) == "/")
   {
      // If the replacement starts with '/' append this after the first / in old URL
      url = url.substring(0,url.indexOf('/',7)) + waitPage.replace;
   }
   else
   {
      // Otherwise get the URL up to the last / and append the replacement
      var offset = 0;
      var idx = 0;
      var count = 0;
      var stem;

      while(((idx=url.indexOf('/', offset))>=0) && (count++ < 20))
      {
         offset = idx+1;
      }
      stem =  url.substring(0,offset);
      url = stem + waitPage.replace;
   }

   window.location.href=url;
}

// --------------------------------------------------------------------------------
function DisplayWait(cssfile)
{
   var simpledate = new simplifyDate(waitPage.date);
   var linkstring;

   linkstring = "";
   if(cssfile != "")
   {
      linkstring = "<link rel='stylesheet' href='" + cssfile + "'";
   }

   document.open();
   document.writeln("<html>");
   document.writeln("<head>");
   document.writeln("   <title>");
   document.writeln(waitPage.title);
   document.writeln("</title>");
   document.writeln(linkstring);
   document.writeln("</head>");

   document.writeln("<body>\n<h1>");
   document.writeln(waitPage.title);
   document.writeln("      </h1>\n<h2>");
   document.writeln(waitPage.text);
   document.writeln("      </h2>");
   document.writeln("      <h3>This page will go online on");
   document.writeln(simpledate.text);
   document.writeln("   </h3></body>");
   document.writeln("</html>");
   document.close();
}

function simplifyDate(datestr)
{
   var month = new Array();
   month[0] = "Jan";
   month[1] = "Feb";
   month[2] = "Mar";
   month[3] = "Apr";
   month[4] = "May";
   month[5] = "Jun";
   month[6] = "Jul";
   month[7] = "Aug";
   month[8] = "Sep";
   month[9] = "Oct";
   month[10] = "Nov";
   month[11] = "Dec";

   var year = datestr.getYear();
   // Some MIE versions give a 2 digit year. Other versions of MIE
   // and older Netscapes give a 4 digit year while Netscape 4.70 gives
   // years since 1900 (i.e. 2000 ==> 100) !!!!
   if(year < 80)
   {
      year += 2000;
   }
   else
   {
      if(year < 1900)
      {
         year += 1900;
      }
   }

   this.text = datestr.getDate() + "-" + month[datestr.getMonth()] + "-" + year;
}


