//  Calendar Popup
//  Written:  2002-01-25 by James Alarie <jalarie@umich.edu>
//    http://spruce.flint.umich.edu/~jalarie/
//
//  Within a form, create an input field and name it.  Create a link which
//  calls DatePop3 with the form number or name, the name of the input 
//  field, and a format code.
//
//  Format code may be uppercase or lowercase.  Valid codes are:
//
//    yyyymm                                  year, month; no separators (default)
//    yyyy-mm, yyyy/mm                        year, month (note 1)
//    mm-yyyy, mm/yyyy                        month, year (note 1)
//    mm-yy, mm/yy                            month, two-digit year (note 1)
//    yy-mm, yy/mm                            two-digit year, month (note 1)
//    yyyy month, month yyyy, month yy        spelled-out month
//
//  Example:
//
//    <input type="text" name="Date1" id="Date1" />
//    <a href="javascript:void(0);" onclick="DatePop3('0','Date1','MM-DD-YYYY');">Get Date</a>
//
//  Notes:
//    1.  The separators (dash or slash) may be whatever you wish.
//
//  Works in frames.
//  Works in Firefox 1.0, Netscape 4.78 and 6.2, Internet Explorer 5.5, Opera 5.12.
//  Does not work in WebTV 2.6 nor Opera 5.11.
    
        function DatePop3(FNum,IName,Format) {
          if (FNum != -1) {                         // called from form
            GD_FNum=FNum;                           // the form number
            GD_IName=IName;                         // field name
            GD_Format=Format;                       // format specifier
            GD_Format=GD_Format.toLowerCase();
            Now=new Date();
            Now_M=Now.getMonth()*1+1;               // Jan-Dec = 0-11
            Now_D=Now.getDate();                    // 1-31
            Now_Y=Now.getYear();
            if (Now_M < 10) { Now_M='0'+Now_M; }
            if (Now_Y < 70)   { Now_Y=Now_Y*1+2000; }
            if (Now_Y < 1000) { Now_Y=Now_Y*1+1900; }
            calendar_page3(Now_Y);
            return true;
          } else {                                  // callback from popup
            //  IName:
            //          -1 to go backward a year
            //          +1 to go forward a year
            //  output:
            //    document.forms[GD_FNum].GD_IName.value
            if (IName == -1) {
              Now_Y=Now_Y-1;
              calendar_page3(Now_Y);
              return false;
            }
            if (IName == 1) {
              Now_Y=Now_Y*1+1;
              calendar_page3(Now_Y);
              return false;
            }
            var I1=PopUp1.document.forms[0].DatePop3_Sel1.selectedIndex;
            I1=I1*1+1;
            if (I1 < 10) { I1='0'+I1; }
            var Y2=Now_Y%100;
            if (Y2 < 10) { Y2='0'+Y2; }
            var Months=new Array('January', 'February', 'March', 'April', 'May',
              'June', 'July', 'August', 'September', 'October', 'November', 'December');
            var Month=Months[I1-1];
            Out=''+Now_Y+I1;                        // default format is YYYYMM
            if (GD_Format.match(/^yyyy.mm$/)) {
              Sep=GD_Format.substring(4,5);         // pick up the separator
              Out=Now_Y+Sep+I1;
            }
            if (GD_Format.match(/^mm.yyyy$/)) { 
              Sep=GD_Format.substring(2,3);         // pick up the separator
              Out=I1+Sep+Now_Y;
            }
            if (GD_Format.match(/^mm.yy$/)) { 
              Sep=GD_Format.substring(2,3);         // pick up the separator
              Out=I1+Sep+Y2;
            }
            if (GD_Format.match(/^yy.mm$/)) {
              Sep=GD_Format.substring(2,3);         // pick up the separator
              Out=Y2+Sep+I1;
            }
            if (GD_Format == 'yyyy month') { Out=Now_Y+' '+Month; }
            if (GD_Format == 'month yyyy') { Out=Month+' '+Now_Y; }
            if (GD_Format == 'month yy')   { Out=Month+' '+Y2;    }
            document.forms[GD_FNum][GD_IName].value=Out;
            PopUp1.window.close();
            return true;
          }
          return true;
        } // DatePop3
        
        
        function calendar_page3(yr4) {
          Opts='width=200,height=150,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 3<\/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';
          Out+='      <form action="javascript:void(0);">\n';
            PopUp1.document.write(Out);
          Out ="        <a href='javascript:void(0);' onclick='self.opener.DatePop3(-1,-1);return false;' title='year-1'>y-<\/a>&nbsp;&nbsp;\n";
          Out+="        "+yr4+'&nbsp;&nbsp;\n';
          Out+="        <a href='javascript:void(0);' onclick='self.opener.DatePop3(-1,1);return false;' title='year+1'>y+<\/a>\n";
          Out+='        <br \/><br \/>\n';
            PopUp1.document.write(Out);
          Out ='        <select name="DatePop3_Sel1" id="DatePop3_Sel1">\n';
          Out+='          <option selected="selected">January<\/option>\n';
          Out+='          <option>February<\/option>\n';
          Out+='          <option>March<\/option>\n';
          Out+='          <option>April<\/option>\n';
          Out+='          <option>May<\/option>\n';
          Out+='          <option>June<\/option>\n';
          Out+='          <option>July<\/option>\n';
          Out+='          <option>August<\/option>\n';
          Out+='          <option>September<\/option>\n';
          Out+='          <option>October<\/option>\n';
          Out+='          <option>November<\/option>\n';
          Out+='          <option>December<\/option>\n';
          Out+='        <\/select>\n';
          Out+='        <br \/><br \/>\n';
            PopUp1.document.write(Out);
          Out ='        <input type="button" value="Ready" alt="Ready" title="Ready" onclick="self.opener.DatePop3(-1,0);" \/>\n';
          Out+='      <\/form>\n';
          Out+='    <\/div><!\-\- center \-\->\n';
          Out+='   <\/div>\n';
          Out+='  <\/body>\n<\/html>\n';
            PopUp1.document.write(Out);
          PopUp1.document.close();
          PopUp1.focus();
          return true;
        } // calendar_page3
