// This JavaScript fragment is executed on the client-side in order to dynamically
// place an announcement on various pages that don't have the programatic ability
// to randomly select an announcement.
//
// The configuration is specified below in the various addEgg method calls.


function DynamicEggCarton(configfile, elementname) {

   this.configfile = configfile;
   this.elementname = elementname;
   this.loadmessage = "";
   this.eggs = [];

   this.addEgg         = DynamicEggAddEgg;
   this.loadConfig     = DynamicEggLoadConfig;
   this.selectEgg      = DynamicEggSelectEgg;

   return this;
}


function DynamicEgg(enable, systems, startdate, enddate, html) {
   this.enable    = enable;
   this.systems   = systems     || {all:true};
   this.startdate = startdate   || new Date("Jan 1, 2000");
   this.enddate   = enddate     || new Date("Jan 1, 3000");
   this.html      = html        || "";

   this.setEnable    = DynamicEggSetEnable;
   this.setStartDate = DynamicEggSetStartDate;
   this.setEndDate   = DynamicEggSetEndDate;
   this.setHTML      = DynamicEggSetHTML;

   return this;
}


function DynamicEggAddEgg(egg) {
   this.eggs.push(egg);
}


function DynamicEggLoadConfig() {


// The arguments to the DynamicEgg constructor are:
//      true  |  false   for whether this egg is enabled
//      An object with system names as properties.  The event is eligible to be displayed
//           if the corresponding value evaluates to true.  For ineligible events, either
//           a value of false can be used or the system name omitted entirely.
//           "{all:true}" can be used to specify all systems are eligible.
//      Begining date value
//      Ending date value
//      HTML to be substituted
//
//      As an FYI, don't include a carriage return at the end of the lines that include HTML output.
//      While Mozilla and Firefox seem to just ignore it, IE doesn't.
//
//      all systems include: webmail,ksol,kats,ucl
//
//      To add a time to a date: new Date("Apr 26, 2005 08:00:00"), new Date("Apr 26, 2005 17:00:00"),
//      To check an event, use https://webmail.ksu.edu/?datetime=oct26,2006
//

var systems_all = {all:true};                      // absolutely all systems, even if they don't receive all events
var systems_webmail = {webmail:true};
var systems_isis = {isis:true};
var systems_allevents = {webmail:true,ucl:true};   // these are systems that receive all the events

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("May 26, 2009"), new Date("May 31, 2009 19:00:00"),
           "<a href=\"http://www.k-state.edu/infotech/e-mail/zimbra/\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/finalwebmail_ad.png\" height=\"133\" width=\"198\" border=\"0\" alt=\"E-mail migration to K-State Zimbra - this weekend - May 29-31. E-mail unavailable during migration. \"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Apr 20, 2009"), new Date("May 29, 2009 17:00:00"),
           "<a href=\"http://www.k-state.edu/infotech/e-mail/docs/zimbra/migration.html#addressbook\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/zimbra-address-ad.png\" height=\"133\" width=\"198\" border=\"0\" alt=\"Don't forget to export your WebMail address book for the migration to K-State Zimbra on May 29.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Apr 20, 2009"), new Date("May 29, 2009 17:00:00"),
           "<a href=\"http://www.k-state.edu/infotech/e-mail/docs/zimbra/sessions.html\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/zimbra-got-questions-ad.png\" height=\"133\" width=\"198\" border=\"0\" alt=\"E-mail migration to K-State Zimbra May 29-31. Got questions? Get them answered.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Apr 3, 2009"), new Date("Apr 20, 2009"),
           "<a href=\"http://www.k-state.edu/infotech/e-mail/zimbra/\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/webmail_add.png\" height=\"133\" width=\"198\" border=\"0\" alt=\"K-State move to Zimbra May 29-31.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Mar 23, 2009"), new Date("Apr 6, 2009"),
           "<a href=\"http://why.kstatesports.com/tickets/\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/season-tickets.jpg\" height=\"45\" width=\"100\" border=\"0\" alt=\"Order your student season tickets when you enroll. Click for details.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Mar 3, 2009"), new Date("Mar 13, 2009 17:00:00"),
           "<a href=\"http://www.k-state.edu/infotech/e-mail/zimbra/\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/webmail_add2.png\" height=\"200\" width=\"200\" border=\"0\" alt=\"Sign up to be a K-State Zimbra e-mail early adopter, click for details.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Mar 10, 2009"), new Date("Mar 25, 2009"),
           "<div style=\"color:#351A50; font-size:80%;background-color:#f6f5f5;border-top: 5px solid #351A50;border-bottom: 5px solid #351A50;padding: 15px;text-align:left;\">\n" +
           "<strong>Beware of E-mail Scams Hitting K-State</strong><br /><br />Scam e-mails that attempt to steal your eID password are being received by K-Staters. If you receive one of these messages, delete it.<br /><br /><strong>K-State IT staff will NEVER ask for your password in e-mail.</strong><br /><br />See <a href=\"http://www.k-state.edu/infotech/security/\" style=\"text-decoration:underline;\">IT Security at K-State</a> for more information.<br />\n" +
           "</div>\n"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Dec 8, 2008"), new Date("Dec 20, 2008"),
           "<a href=\"http://www.k-state.edu/hd/askwillie/\"><img src=\"https://www.k-state.edu/hd/askwillie/askwillie_200w_whitebck.png\" height=\"75\" width=\"200\" border=\"0\" alt=\"Need help? Ask Willie!\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Nov 17, 2008"), new Date("Dec 1, 2008"),
           "<a href=\"http://www.k-state.edu/infotech/e-mail/docs/zimbra/\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/zimbra.jpg\" height=\"99\" width=\"96\" border=\"0\" alt=\"Zimbra e-mail to replace WebMail spring 2009, click for details.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Nov 10, 2008"), new Date("Nov 17, 2008"),
           "<div style=\"color:#351A50; font-size:80%;background-color:#f6f5f5;border-top: 5px solid #351A50;border-bottom: 5px solid #351A50;padding: 15px;text-align:left;\">\n" +
           "<strong>Beware of E-mail Scams Hitting K-State</strong><br /><br />Scam e-mails that attempt to steal your eID password are being received by K-Staters. If you receive one of these messages, delete it.<br /><br /><strong>K-State IT staff will NEVER ask for your password in e-mail.</strong><br /><br />See <a href=\"http://www.k-state.edu/infotech/security/\" style=\"text-decoration:underline;\">IT Security at K-State</a> for more information.<br />\n" +
           "</div>\n"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Oct 28, 2008"), new Date("Nov 11, 2008"),
           "<a href=\"http://ev12.evenue.net/cgi-bin/ncommerce3/ExecMacro/evenue/ev69/se/Main.d2w/report?linkID=kansuse\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/basketball.jpg\" height=\"45\" width=\"106\" border=\"0\" alt=\"Buy men's basketball tickets today.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Oct 23, 2008 17:00:00"), new Date("Oct 28, 2008"),
           "<a href=\"http://www.k-state.edu/infotech/e-mail/docs/zimbra/\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/zimbra.jpg\" height=\"99\" width=\"96\" border=\"0\" alt=\"Zimbra e-mail to replace WebMail spring 2009, click for details.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Oct 02, 2008"), new Date("Oct 15, 2008 15:00:00"),
           "<a href=\"http://www.k-state.edu/acic/majorsfair/\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/majorsfair2008.jpg\" height=\"109\" width=\"96\" border=\"0\" alt=\"Attend the Academic Majors Fair 11 a.m. to 3 p.m., October 15 in the K-State Student Union ballroom.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Sep 11, 2008"), new Date("Sep 25, 2008"),
           "<a href=\"http://www.k-state.com/Students/StudentAmbassadors.aspx\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/ambassador.gif\" height=\"45\" width=\"105\" border=\"0\" alt=\"Apply to be a K-State student ambassador\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Sep 11, 2008"), new Date("Sep 15, 2008"),
           "<a href=\"https://eid.k-state.edu/eProfile/passwordReset.do\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/password-forgot.jpg\" height=\"45\" width=\"105\" border=\"0\" alt=\"Forgot to change your password?\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Sep 8, 2008"), new Date("Sep 11, 2008"),
           "<a href=\"https://eid.k-state.edu/\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/password-change.jpg\" height=\"45\" width=\"105\" border=\"0\" alt=\"Change your password by September 10.\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Sep 03, 2008"), new Date("Sep 11, 2008"),
           "<a href=\"http://www.k-state.edu/ces/students/cesaccount.htm\"><img src=\"https://www.k-state.edu/images/home/eventgraphic/ActivateWebmailIconTeal.jpg\" height=\"45\" width=\"105\" border=\"0\" alt=\"Students activate or update your CES account!\"></a>"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Aug 20, 2008"), new Date("Aug 20, 2008"),
           "<div style=\"color:#351A50; font-size:80%;background-color:#f6f5f5;border-top: 5px solid #351A50;border-bottom: 5px solid #351A50;padding: 15px;text-align:left;\">\n" +
           "<strong>Received an e-mail with one of these subjects? Delete it - it's a scam.</strong><ul><li>Update Account</li><li>IMPORTANT NOTICE TO K-STATE WEBMAIL USERS</li><li>CONFIRM YOUR PASSWORD</li><li>Confirm Your E-mail Account</li><li>EMAIL ACCOUNT UPGRADING DEPT!!</li><li>University Webmail Upgrade</li><li><a href=\"http://www.k-state.edu/infotech/security/\" style=\"text-decoration:underline;\">See more</a></li></ul><br /><strong>K-State IT staff will NEVER ask for your password in e-mail.</strong><br /><br />See <a href=\"http://www.k-state.edu/infotech/security/\" style=\"text-decoration:underline;\">IT Security at K-State</a> for details.<br />\n" +
           "</div>\n"
           )
   );

   this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Sep 26, 2008"), new Date("Oct 3, 2008"),
           "<div style=\"color:#351A50; font-size:80%;background-color:#f6f5f5;border-top: 5px solid #351A50;border-bottom: 5px solid #351A50;padding: 15px;text-align:left;\">\n" +
           "<strong>Beware of E-mail Scams Hitting K-State</strong><br /><br />Scam e-mails that attempt to steal your eID password are being received by K-Staters. If you receive one of these messages, delete it.<br /><br /><strong>K-State IT staff will NEVER ask for your password in e-mail.</strong><br /><br />See <a href=\"http://www.k-state.edu/infotech/security/\" style=\"text-decoration:underline;\">IT Security at K-State</a> for more information.<br />\n" +
           "</div>\n"
           )
   );


  this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Oct 3, 2007"), new Date("Oct 4, 2007"),
           "<div style=\"font-size:80%;background-color:#f6f5f5;border-top: 5px solid #351A50;border-bottom: 5px solid #351A50;padding: 5px;text-align:left;\">\n" +
           "Check out the new WebMail <a href=\"https://webmail-preview.k-state.edu\" style=\"text-decoration: underline; color: #0000FF\"> preview!</a> <br /><br />\n " +
           "The new version will replace the current one later this fall.  Send your comments to webmaster@k-state.edu <br />\n" +
           "</div>\n"
           )
    );

  this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Aug 13, 2008"), new Date("Aug 14, 2008 03:00:00"),
           "<div style=\"font-size:80%;background-color:#f6f5f5;border-top: 5px solid #351A50;border-bottom: 5px solid #351A50;padding: 5px;text-align:left;\">\n" +
           "WebMail and other K-State e-mail services (IMAP and POP) will be " +
           "unavailable from 12:01 a.m. - 3:00 a.m., Thursday August 14.  No " +
           "mail will be lost--incoming mail will be queued for delivery.<br />\n" +
           "</div>\n"
           )
    );

  this.addEgg(
       new DynamicEgg(true, systems_webmail,
           new Date("Feb 12, 2009"), new Date("Feb 18, 2009"),
           "<div style=\"font-size:80%;background-color:#f6f5f5;border-top: 5px solid #351A50;border-bottom: 5px solid #351A50;padding: 5px;text-align:left;\">\n" +
           "LISTSERVS were unavailable from 5:30 Tuesday, Feb 10 until Wednesday, Feb 11 at 2:00 p.m. " +
           "Any messages sent to a LISTSERV mailing list during that period " +
           "have been discarded and not delivered. We apologize for the inconvenience. <br />\n" +
           "</div>\n"
           )
    );

   this.addEgg(
        new DynamicEgg(true, systems_isis,
            new Date("Jul 16, 2008"), new Date("Jul 19, 2008 05:00:00"),
            "<div id=\"KSU_mainColumnSidebar\">\n" +
             "<h4 style=\"color:red;\">Network Upgrade<br />9 p.m. Fri. to 5 a.m. Sat.</h4>\n" +
            "<p>Access to all K-State's central IT resources will be intermittent during this time, including, but not limited to, e-mail, <strong>iSIS</strong>, K-State Online, the eProfile and www.k-state.edu. <br /><a href=\"http://www.k-state.edu/infotech/status/\" style=\"text-decoration:underline;\">Read more.</a></p>\n" +
            "</div>\n"
            )
     );

   this.addEgg(
        new DynamicEgg(true, systems_isis,
            new Date("Jan 10, 2010 05:00:00"), new Date("Aug 30, 2011"),
            "<div id=\"KSU_mainColumnSidebar\">\n" +
             "<h4>System Maintenance</h4>\n" +
            "<p>Routine maintenance occurs between the hours of 4 a.m. and 6 a.m. (US Central time) Monday through Saturday and from 4 a.m. to noon on Sundays.  iSIS may not be available during these hours.</p>\n" +
            "</div>\n"
            )
     );
     this.addEgg(
         new DynamicEgg(false, systems_isis,
             new Date("Aug 1, 2008 05:00:00"), new Date("Sep 22, 2008"),
             "<div id=\"KSU_mainColumnSidebar\">\n" +
              "<h4>System Maintenance</h4>\n" +
             "<p>Routine maintenance occurs between the hours of 4 a.m. and 6 a.m. (US Central time) Monday through Saturday and from 4 a.m. to noon on Sundays.  iSIS may not be available during these hours.</p>\n" +
             "<h4>Safari users</h4>\n" +
             "<p>The Safari browser does not currently allow direct access from iSIS to make payments or to view the student bill.  Either use a different browser or go directly to <a href=\"https://commerce.cashnet.com/ksuach\">https://commerce.cashnet.com/ksuach</a>.</p>" +
             "</div>\n"
             )
     );

   this.addEgg(
        new DynamicEgg(true, systems_isis,
            new Date("Sep 23, 2008"), new Date("Oct 12, 2008 12:00:00"),
            "<div id=\"KSU_mainColumnSidebar\">\n" +
            "<h4>System Maintenance<br /> Sunday 8 a.m. to noon</h4>\n" +
            "<p>iSIS will be unavailable Sunday, October 12, for routine maintenance.</p>\n" +
            "<h4>Students before fall 2006</h4>\n" +
            "<p>Students who last attended K-State prior to fall 2006 can <a href=\"http://kats.k-state.edu/signin.html\">sign in to KATS</a> to view grades and class schedules. For transcripts, contact the <a href=\"http://www.k-state.edu/registrar/\">Registrar's Office</a>.</p>\n" +
            "<p>For Tuition Statements for 2007, IRS form 1098-T, <a href=\"http://kats.k-state.edu/signin.html\">sign in to KATS</a>.</p>\n" +
            "<h4>Safari users</h4>\n" +
            "<p>The Safari browser does not currently allow direct access from iSIS to make payments or to view the student bill. Either use a different browser or go to: <a href=\"https://commerce.cashnet.com/ksuach\">https://commerce.cashnet.com/ksuach</a></p>\n" +
            "<p style=\"padding-top:10px;\"><strong>System maintenance</strong><br />Routine maintenance is scheduled<br />4 to 6 a.m. (CST) Monday-Saturday and 4 a.m. to noon on Sundays. iSIS may not be available during these hours.</p>" +
            "</div>\n"
            )
   );

   this.addEgg(
        new DynamicEgg(true, systems_isis,
            new Date("Oct 12, 2008 12:00:00"), new Date("Feb 2, 2009 07:59:00"),
            "<div id=\"KSU_mainColumnSidebar\">\n" +
            "<h4>Students before fall 2006</h4>\n" +
            "<p>Students who last attended K-State prior to fall 2006 can <a href=\"http://kats.k-state.edu/signin.html\">sign in to KATS</a> to view grades and class schedules. For transcripts, contact the <a href=\"http://www.k-state.edu/registrar/\">Registrar's Office</a>.</p>\n" +
            "<p>For Tuition Statements for 2007, IRS form 1098-T, <a href=\"http://kats.k-state.edu/signin.html\">sign in to KATS</a>.</p>\n" +
            "<h4>Safari users</h4>\n" +
            "<p>The Safari browser does not currently allow direct access from iSIS to make payments or to view the student bill. Either use a different browser or go to: <a href=\"https://commerce.cashnet.com/ksuach\">https://commerce.cashnet.com/ksuach</a></p>\n" +
            "<p style=\"padding-top:10px;\"><strong>System maintenance</strong><br />Routine maintenance is scheduled<br />4 to 6 a.m. (CST) Monday-Saturday and 4 a.m. to noon on Sundays. iSIS may not be available during these hours.</p>" +
            "</div>\n"
            )
   );

   this.addEgg(
        new DynamicEgg(true, systems_isis,
            new Date("Feb 2, 2009 08:00:00"), new Date("Feb 3, 2009 08:00:00"),
            "<div id=\"KSU_mainColumnSidebar\">\n" +
            "<h4>New in iSIS</h4>\n" +
            "<p>Undergraduate and Veterinary Medicine degree candidates can now apply for graduation under Academics in the Student Center.</p>\n" +
            "<p>Graduate degree candidates continue to  <a href=\"http://www.k-state.edu/grad/gscurrent/guideforms/index.htm\">apply</a> through the Graduate School.</p>\n" +
            "<h4>Safari users</h4>\n" +
            "<p>The Safari browser does not currently allow direct access from iSIS to make payments or to view the student bill. Either use a different browser or go to: <a href=\"https://commerce.cashnet.com/ksuach\">https://commerce.cashnet.com/ksuach</a></p>\n" +
            "<p style=\"padding-top:10px;\"><strong>System maintenance</strong><br />Routine maintenance is scheduled<br />4 to 6 a.m. (CST) Monday-Saturday and 4 a.m. to noon on Sundays. iSIS may not be available during these hours.</p>" +
            "</div>\n"
            )
   );

   this.addEgg(
        new DynamicEgg(true, systems_isis,
            new Date("Feb 3, 2009 08:00:00"), new Date("Feb 10, 2010"),
            "<div id=\"KSU_mainColumnSidebar\">\n" +
            "<h4>Tax information</h4>\n" +
            "<p>To view your 1098-T tax information, <a href=\"http://www.k-state.edu/controller/student/1098Help.html\">follow the instructions</a>.</p>\n" +
            "<h4>New in iSIS</h4>\n" +
            "<p>Undergraduate and Veterinary Medicine degree candidates can now apply for graduation under Academics in the Student Center.</p>\n" +
            "<p>Graduate degree candidates continue to  <a href=\"http://www.k-state.edu/grad/gscurrent/guideforms/index.htm\">apply</a> through the Graduate School.</p>\n" +
            "<h4>Safari users</h4>\n" +
            "<p>The Safari browser does not currently allow direct access from iSIS to make payments or to view the student bill. Either use a different browser or go to: <a href=\"https://commerce.cashnet.com/ksuach\">https://commerce.cashnet.com/ksuach</a></p>\n" +
            "<p style=\"padding-top:10px;\"><strong>System maintenance</strong><br />Routine maintenance is scheduled<br />4 to 6 a.m. (CST) Monday-Saturday and 4 a.m. to noon on Sundays. iSIS may not be available during these hours.</p>" +
            "</div>\n"
            )
   );

}


/** Select an egg from the egg carton.
 *
 * returns either an egg or null if none can be selected
 */
function DynamicEggSelectEgg(system, userchoice, datetime) {

   // If there are no eggs in the carton, return null.
   if (this.eggs.length == 0) {
      return null;
   }

   if (userchoice  &&  !isNaN(parseInt(userchoice))) {

      // The user requested a specific event -- use it
      var eggnumber = parseInt(userchoice);

      // Make very sure that the selected number is in range
      if (eggnumber < 0) { eggnumber = 0; }
      if (eggnumber > this.eggs.length-1) { eggnumber = this.eggs.length-1; }

      var egg = this.eggs[eggnumber];

   } else {

      // Otherwise pick a random one
      // This is the meat of the routine.
      // First, build a temporary array of eligible eggs
      if (!datetime) {
         datetime = new Date();
      }
      var goodeggs = [];
      for (var i = 0; i < this.eggs.length; i++) {
         with (this.eggs[i]) {
            if (enable  &&
               (systems[system] || systems['all']) &&
                datetime >= startdate  &&  datetime < enddate) {
               goodeggs.push(this.eggs[i]);
            }
         }
      }

      if (goodeggs.length == 0) {
         return null;
      }

      var eggnumber = Math.floor(Math.random() * goodeggs.length);

      // Make very sure that the selected number is in range
      if (eggnumber < 0) { eggnumber = 0; }
      if (eggnumber > goodeggs.length-1) { eggnumber = goodeggs.length-1; }

      var egg = goodeggs[eggnumber];
   }

   return egg;

}


function DynamicEggSetEnable(enable) {
   this.enable = enable;
}

function DynamicEggSetStartDate(startdate) {
   this.startdate = startdate;
}

function DynamicEggSetEndDate(enddate) {
   this.enddate = enddate;
}

function DynamicEggSetHTML(html) {
   this.html = html;
}




/*
 * parseRequest -- parse the parameters specified in the URL into a "request" object
 *
 * This function returns an object that has a property for each parameter
 * in the URL.  The value of the property is the value as specified in the
 * URL.  For example, with the URL "whatever.html?dog=Max&cat=Saturn",
 * the object returned would have two properties:
 *
 *    request.dog = "Max" and request.cat="Saturn".
 *
 * The returned object is typically named "request", and is modelled after the
 * Server-Side JavaScript "request" object.
 *
 * Note: No facility is available to handle parameters that are specified
 * multiple times.  The last value specified on the URL is the one returned.
 */
function parseRequest(s) {
   var request = new Object();

   // Strip the leading question mark
   if (s.substr(0,1) == '?') {
      s = s.substr(1);
   }

   // Split the query/search string into "name=value" strings.
   var a = s.split(/&/);

   // For each string, split into the name and value, and assign to
   // the request object.
   for (var i = 0; i < a.length; i++) {
      var v = a[i].match(/^([^=]*)=(.*)$/);
      if (v) {
         request[v[1]] = unescape(v[2]);
      }
   }

   return request;
}

request=parseRequest(window.location.search);          // Sets REQUEST.variable
var eggs = new DynamicEggCarton();
eggs.loadConfig();

var datetime = null;
if (request.datetime) {
   datetime = new Date(request.datetime);
}
if (typeof(system)=='undefined') {
   system = "webmail";
}
var ann = eggs.selectEgg(system, request.event, datetime);

// "ann" is either an Egg object or null
if (ann != null) {
   document.write(ann.html);
}
