//  Calendar Popup
//  Written:  2001-11-14 by James Alarie <jalarie@umich.edu>
//    http://spruce.flint.umich.edu/~jalarie/
//
//  Call DatePop0 with no parameters to popup a full-year calendar.
//
//  Example:
//
//    <a href="javascript:void(0);" onclick="DatePop0();">Show Calendar</a>
    
        function DatePop0(What) {
          Today=new Date();
          Today_Y=Today.getYear();
          Today_M=Today.getMonth()*1+1;
          Today_D=Today.getDate();
          if (Today_Y < 70)   { Today_Y=Today_Y*1+2000; }
          if (Today_Y < 1000) { Today_Y=Today_Y*1+1900; }
          if (!What) {
            Now=new Date();
            Now_M=Now.getMonth()*1+1;               // Jan-Dec = 1-12
            Now_D=Now.getDate();                    // 1-31
            Now_Y=Now.getYear();
            if (Now_Y < 70)   { Now_Y=Now_Y*1+2000; }
            if (Now_Y < 1000) { Now_Y=Now_Y*1+1900; }
          } else {
            Now_Y=What;
            if ((ix1=String(Now_Y).indexOf('/')) > -1) {
              Now_Y=Now_Y.substring(0,ix1);
              Now_M=Now_Y.substring(ix1+1)*1+1;
            }
          }

          Opts='resizable,scrollbars';
          PopUp1=window.open('','DatePop',Opts);
          Out ='';
          Out+='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n';
          Out+='  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
          Out+='\n';
          Out+='<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">\n';
          Out+='  <head>\n    <title>Calendar Popup 0<\/title>\n';
          Out+='    <meta http-equiv="Content-Script-Type" content="text\/javascript" \/>\n';
          Out+='    <meta http-equiv="Content-Style-Type" content="text\/css" \/>\n';
          Out+='    <meta http-equiv="PICS-Label" content=\'(PICS-1.1 "http:\/\/www.classify.org\/safesurf\/" l gen true for "http:\/\/spruce.flint.umich.edu\/~jalarie\/" r (SS~~000 1))\' \/>\n';
          Out+='    <meta http-equiv="pics-Label" content=\'(pics-1.1 "http://www.icra.org/pics/vocabularyv03/" l gen true for "http://spruce.flint.umich.edu/~jalarie" r (n 0 s 0 v 0 l 0 oa 0 ob 0 oc 0 od 0 oe 0 of 0 og 0 oh 0 c 0)  gen true for "http://www.spruce.flint.umich.edu/~jalarie" r (n 0 s 0 v 0 l 0 oa 0 ob 0 oc 0 od 0 oe 0 of 0 og 0 oh 0 c 0))\' />\n';
          Out+='    <link rel="meta" href="http://spruce.flint.umich.edu/~jalarie/labels.rdf" type="application/rdf+xml" title="ICRA labels" />\n';
          Out+='    <link href="style1.css" rel="stylesheet" type="text\/css" \/>\n';
          Out+='  <\/head>\n';
          Out+='  <body class="body1">\n';
          Out+='   <div id="body">\n';
          Out+='    <div class="center">\n';
          PopUp1.document.write(Out);
          
          YP1=Now_Y*1+1;
          YM1=Now_Y*1-1;
          Out ='<table border="0" cellspacing="2" cellpadding="2" width="90%">\n';
          Out+='  <tr>\n';
          Out+='    <th bgcolor="#ccffcc" colspan="3">\n';
          Out+="      <a href='javascript:void(0);' onclick='self.opener.DatePop0("+YM1+");return false;' title='year-1'>y-<\/a>&nbsp;&nbsp;\n";
          Out+="        "+Now_Y+'&nbsp;&nbsp;\n';
          Out+="      <a href='javascript:void(0);' onclick='self.opener.DatePop0("+YP1+");return false;' title='year+1'>y+<\/a>\n";
          Out+='    <\/th>\n';
          Out+='  <\/tr>\n';
          PopUp1.document.write(Out);          
          for (ix8=0; ix8<=3; ix8++) {
            PopUp1.document.write('  <tr>\n');
            for (var ix0=1; ix0<=3; ix0++) {
              ix7=ix8*3 + ix0*1;
              PopUp1.document.write('    <td align="left" valign="top">\n');
              calendar_page0(Now_Y, ix7);           // display this month's calendar
              PopUp1.document.write('    <\/td>\n');
            }
            PopUp1.document.write('  <\/tr>\n');
          }
          PopUp1.document.write('<\/table>\n');
          
          PopUp1.document.write('[<a href="javascript:window.close();" title="close">Close<\/a>]\n');
          
          Out ='    <\/div><!\-\- center \-\->\n';
          Out+='   <\/div>\n';
          Out+='  <\/body>\n<\/html>\n';
          PopUp1.document.write(Out);
          PopUp1.document.close();
          PopUp1.focus();
          
          return true;
        } // DatePop0


        function calendar_page0(yr4, mon) {
          var mns = new Array("31,000,January", "28,031,February",
            "31,059,March", "30,090,April", "31,120,May", "30,151,June",
            "31,181,July", "31,212,August", "30,243,September",
            "31,273,October", "30,304,November", "31,334,December");
          var dys = mns[mon-1].substring(0,2);      // days in the month
          var ofs = mns[mon-1].substring(3,6);      // calendar offset
          var mnn = mns[mon-1].substring(7);        // month name
          if ((yr4%400 == 0)
          ||  ((yr4%100 != 0) && (yr4%4 == 0))) {   // is a leap year
            if (mon == 2) { dys = 29; }             // Feb. has 29 days
            if (mon > 2) { ofs = 1 * ofs + 1; }     // extra offset
          }
          var skp = Math.floor((1*yr4 - 1581) * 5 / 4);
          for (ix1 = 1600; ix1 < yr4; ix1 = ix1 + 100) {
            if (ix1 % 400 != 0) { skp = skp + 6; }
          }
          var skp0 = (skp + 4) % 7 + 1*ofs - 1;
          skp = (skp + 4 + 1*ofs) % 7;
          ix9=ofs*1+1;

          out ="<table border='1' cellspacing='2' cellpadding='2' width='30%'>\n";
          out+="  <thead>\n";
          out+="    <tr>\n";
          out+="      <th bgcolor='#ffff99' colspan='7'>"+mnn+" <\/th>\n";
          out+="    <\/tr>\n";
          out+="    <tr>\n";
          out+="      <th bgcolor='#ffff99' width='30' abbr='Sunday'   >Sun <\/th>\n";
          out+="      <th bgcolor='#ffff99' width='30' abbr='Monday'   >Mon <\/th>\n";
          out+="      <th bgcolor='#ffff99' width='30' abbr='Tuesday'  >Tue <\/th>\n";
          out+="      <th bgcolor='#ffff99' width='30' abbr='Wednesday'>Wed <\/th>\n";
          out+="      <th bgcolor='#ffff99' width='30' abbr='Thursday' >Thu <\/th>\n";
          out+="      <th bgcolor='#ffff99' width='30' abbr='Friday'   >Fri <\/th>\n";
          out+="      <th bgcolor='#ffff99' width='30' abbr='Saturday' >Sat <\/th>\n";
          out+="    <\/tr>\n";
          out+="  <\/thead>\n";
          out+="  <tbody>\n";
          out =out+"    <tr>\n";
            PopUp1.document.write(out);
          var wk = Math.floor((skp0 + 1) / 7) + 1;
          if (skp > 0) {
            PopUp1.document.write("      <td align='left' colspan='" + skp + "' bgcolor='silver'>&nbsp;<\/td>\n");
          }
          var ix2 = skp;
          out = '';
          for (ix1 = 1; ix1 <= dys; ix1++) {
            if (ix2 >= 7) {
              PopUp1.document.write(out);
              out = '';
              PopUp1.document.write("    <\/tr>\n    <tr>\n");
              var wk = Math.floor((skp0 + ix1) / 7) + 1;
              ix2 = 0;
            }
            if ((yr4 == Today_Y) && (mon == Today_M) && (ix1 == Today_D)) {
              out =out+"      <td bgcolor='#ffcccc' align='right'>"+ix1+" <\/td>\n";
            } else {
              out =out+"      <td bgcolor='aqua' align='right'>"+ix1+" <\/td>\n";
            }
            ix9 += 1;
            ix2 += 1;
          }
          PopUp1.document.write(out);
          if (ix2 < 7) {
            ix2 = 7 - ix2;
            PopUp1.document.write("      <td align='left' colspan='" + ix2 +"' bgcolor='silver'>&nbsp;<\/td>\n");
          }
          PopUp1.document.write("    <\/tr>\n");
          PopUp1.document.write("  <\/tbody>\n");
          PopUp1.document.write("<\/table>\n");
          return true;
        } // calendar_page0
