

var show_calendar_obj;
var show_calendar_win;
function show_calendar()
{
  var vDsym = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
               "January", "February", "March", "April", "May", "June",
               "July", "August", "September", "October", "November", "December",
               "en", "Preselected", "Today", 42];
  
  if (arguments[0] != null)
    show_calendar_obj = arguments[0];
  
  var p_dsym = "null"
  if (arguments[1] != null)
  {
    p_dsym = "'" + arguments[1] + "'";
    vDsym = arguments[1].split(",");
  }
  
  user_date_correct(show_calendar_obj);
  var vDate = user_date(show_calendar_obj.value);
  if (vDate == null) vDate = new Date();
  var vNowDay = vDate.getDate();
  var vNowMonth = vDate.getMonth();
  var vNowYear = vDate.getFullYear();
  var vCurDay = (new Date()).getDate();
  var vCurMonth = (new Date()).getMonth();
  var vCurYear = (new Date()).getFullYear();
  
  var res = "";
  if (vNowDay < 10) res += "0";
  res += vNowDay + "\/";
  if (vNowMonth < 9) res += "0";
  res += (vNowMonth + 1) + "\/";
  res += vNowYear;

  show_calendar_obj.value = res;

  var p_month;
  var p_year;
  if (arguments[2] == null) p_month = vNowMonth;
  else p_month = parseInt(arguments[2]);
  if (arguments[3] == null) p_year = vNowYear;
  else p_year = parseInt(arguments[3]);

  vDate.setDate(1);
  vDate.setMonth(p_month);
  vDate.setFullYear(p_year);

  var vFirstDay=vDate.getDay();
  var vDay=1;
  var vLastDay = 32 - new Date(p_year, p_month, 32).getDate();
  var vOnLastDay = false;
  var vCode = "";
  
  if (!show_calendar_win || show_calendar_win.closed)
  {
    res =  "width=250,";
    res += "height=270,";
    res += "status=no,";
    res += "resizable=no,";
    res += "top=200,";
    res += "left=200,";
    res += "dependent=yes";
    show_calendar_win = window.open("", "Calendar", res);
    show_calendar_win.opener = self;
  }
  
  var vWin = show_calendar_win;
  var thdoc = vWin.document;
  vWin.document.open();
  vWin.focus();
  
  thdoc.writeln("<html>");
  thdoc.writeln("<head>");
  thdoc.writeln("<title>Fund Gate Calendar</title>");
  
  thdoc.writeln("<style type=\"text/css\">");
  thdoc.writeln("<!--");
  thdoc.writeln("p.cal1 { font: bold 12px Arial; margin-top: 0px; margin-bottom: 5px; margin-left: 0px; color:#003366; text-decoration: none }");
  thdoc.writeln("td.cal2 { vertical-align: middle; text-align: center; padding: 0px; font: bold 11px Arial; color: #003366; text-decoration: none }");
  thdoc.writeln("td.cal3 { vertical-align: middle; text-align: right; padding-right: 7px; font: 11px Arial; color: gray }");
  thdoc.writeln("td.cal4 { vertical-align: middle; text-align: center; font: 11px Arial; color: #336699 }");
  thdoc.writeln("td.cal7 { padding: 0px; text-decoration: none }");
  thdoc.writeln("td.cal8 { vertical-align: middle; text-align: left; font: 10px Arial; color: #003366 }");
  thdoc.writeln("a.cal5 { font: 11px Arial; color: #336699 }");
  thdoc.writeln("a.cal6 { font: 11px Arial; color: #ffffff }");
  thdoc.writeln("-->");
  thdoc.writeln("</style>");  
  
  thdoc.writeln("</head>");

  thdoc.write("<body "
              + "bgcolor=\"#ffffff\" "
              + "link=\"black\" "
              + "vlink=\"black\" "
              + "alink=\"black\" "
              + "text=\"black\">");
  thdoc.write("<p class='cal1'>");
  thdoc.write(vDsym[p_month + 7] + " " + p_year);
  thdoc.write("</p>");
  
  var prevMM =   (p_month == 0)  ? 11 : p_month - 1;
  var prevYYYY = (p_month == 0)  ? p_year - 1 : p_year;
  var nextMM =   (p_month == 11) ? 0 : p_month + 1;
  var nextYYYY = (p_month == 11) ? p_year + 1 : p_year;
  
  var vUi = [p_month,   (p_year - 1), "prevy",              23,
             prevMM,    prevYYYY,     "prevm",              17,
             vCurMonth, vCurYear,     "today_" + vDsym[19], vDsym[22],
             nextMM,    nextYYYY,     "nextm",              17,
             p_month,   (p_year + 1), "nexty",              23];
  
  thdoc.writeln("<table width='230' border=0 cellspacing=0 cellpadding=5 bgcolor='#dbe4ed'>");
  thdoc.writeln("<tr>");
  
  for (n = 0; n < 20; n += 4)
  {
    thdoc.write("<td class='cal4' bgcolor='#dbe4ed'>");
    thdoc.write("<a ");
    
    thdoc.write("onmouseup=\"document.images['");
    thdoc.write(vUi[n + 2]);
    thdoc.write("'].src = 'grafik/cal/");
    thdoc.write(vUi[n + 2]);
    thdoc.write("_up.gif'\" ");
    
    thdoc.write("onmousedown=\"document.images['");
    thdoc.write(vUi[n + 2]);
    thdoc.write("'].src = 'grafik/cal/");
    thdoc.write(vUi[n + 2]);
    thdoc.write("_down.gif'\" ");
    
    thdoc.write("onmouseout=\"document.images['");
    thdoc.write(vUi[n + 2]);
    thdoc.write("'].src = 'grafik/cal/");
    thdoc.write(vUi[n + 2]);
    thdoc.write("_up.gif'\" ");
    
    thdoc.write("href=\"javascript:window.opener.show_calendar(null, ");
    thdoc.write(p_dsym);
    thdoc.write(", '");
    thdoc.write(vUi[n]);
    thdoc.write("', '");
    thdoc.write(vUi[n + 1]);
    thdoc.write("');\">");
    thdoc.write("<img height=17 alt='");
    thdoc.write(vDsym[vUi[n] + 7]);
    thdoc.write(" ");
    thdoc.write(vUi[n + 1]);
    thdoc.write("' src='grafik/cal/");
    thdoc.write(vUi[n + 2]);
    thdoc.write("_up.gif' width=");
    thdoc.write(vUi[n + 3]);
    thdoc.write(" border=0 name='");
    thdoc.write(vUi[n + 2]);
    thdoc.write("'>");
    thdoc.writeln("<\/a></td>");
  }
  
  thdoc.writeln("</tr>");
  thdoc.writeln("</table>");
  
  thdoc.writeln("<table width='230' border=0 cellspacing=1 cellpadding=2 bgcolor='#ffffff'>");
  thdoc.writeln("<tr>");
  thdoc.writeln("<td width='230' colspan='7' height='5'><img height=5 alt='' src='grafik/cal/0.gif' width=1></td>");
  thdoc.writeln("</tr>");
  thdoc.writeln("<tr>");
  for (n = 0; n < 7; n++)
  {
    thdoc.write("<td class='cal2' width='32'>" + vDsym[n] + "</td>");
  }
  thdoc.writeln("</tr>");
  thdoc.writeln("<tr>");
  thdoc.writeln("<td class='cal7' width='230' colspan='7' bgcolor='#99adc2' height='2'><img height=2 alt='' src='grafik/cal/0.gif' width=1></td>");
  thdoc.writeln("</tr>");
  
  vDay = 1 - vFirstDay;
  var vBgcolor1 = "";
  var vBgcolor2 = "";
  var vIsActive = true;
  var vAstyle = "cal5";
  
  for (w = 0; w < 7; w++)
  {
     thdoc.writeln("<tr>");
     
     for (d = 0; d < 7; d++)
     {
       //
       // Calculate user date string
       //
     	
       res = "";
       if (vDay < 10) res += "0";
       res += vDay + "\/";
       if (p_month < 9) res += "0";
       res += (p_month + 1) + "\/";
       res += p_year;
       
       vBgcolor1 = "f2f3f5";
       vBgcolor2 = "f2f3f5";
       vIsActive = true;
       vAstyle = "cal5";
       
       if (d == 0 || d == 6)
       {
         vBgcolor1 = "e6eaee";
         vBgcolor2 = "e6eaee";
       }
       
       if (vDay == vNowDay
          && p_month == vNowMonth
          && p_year == vNowYear)
       {
       	 vBgcolor1 = "99adc2";
         vBgcolor2 = "99adc2";
         vAstyle = "cal6";
       }
       
       if (vDay == vCurDay
          && p_month == vCurMonth
          && p_year == vCurYear)
       {
       	 vBgcolor1 = "003366";
       }
       
       if (vDay > vLastDay) vIsActive = false;
       
       thdoc.write("<td width='32' heigth='24' bgcolor='#" + vBgcolor1 + "'>");
       thdoc.write("<table border='0' cellspacing='0' cellpadding='3' height='20' width='28' bgcolor='" + vBgcolor2 + "'>");
       thdoc.write("<tr><td class='cal3'>");
       
       if (vIsActive)
         thdoc.write("<a class='"
                     + vAstyle
                     + "' href='#' "
                     + "onClick=\"self.opener.show_calendar_obj.value='"
                     + res
                     + "';if (self.opener.change_selection) self.opener.change_selection();window.close();\">");
       
       if (vDay <= 0) thdoc.write(" ");
       else if (vDay > vLastDay) thdoc.write(vDay - vLastDay);
       else thdoc.write(vDay);
       
       if (vIsActive)
         thdoc.write("</a>");
       
       thdoc.write("</td></tr></table>");
       thdoc.writeln("</td>");
       vDay = vDay + 1;
     }
     
     thdoc.writeln("</tr>");
     if (vDay > vLastDay) break;
  }
  
  thdoc.writeln("</table>");
  
  thdoc.writeln("<table width='230' border=0 cellspacing=0 cellpadding=3 bgcolor='#ffffff'>");
  thdoc.writeln("<tr>");
  thdoc.write("<td class='cal8'><img height=7 alt='");
  thdoc.write(vDsym[22]);
  thdoc.write("' src='grafik/cal/preselected.gif' width=7> = ");
  thdoc.write(vDsym[20]);
  thdoc.write("&nbsp;&nbsp;&nbsp;<img height=7 alt='");
  thdoc.write(vDsym[21]);
  thdoc.write("' src='grafik/cal/today.gif' width=7> = ");
  thdoc.write(vDsym[21]);
  thdoc.write("</td>");
  thdoc.writeln("</tr>");
  thdoc.writeln("</table>");
  
  
  thdoc.writeln("</body></html>");
  vWin.document.close();
}
