bug in javascript calendar
<p>I used the following code for display calender on click the pick date link.</p>

<pre><code>// JavaScript Document
//script for date picker

// You can edit this function if you need the date in a different format
function format_date_field(y, m, d) {
   return '' + y + '-' + 
          ((m &gt; 9) ? m : '0' + m) + '-' +
          ((d &gt; 9) ? d : '0' + d);
}



m_list = Array("January", "February", "March",
               "April",   "May",      "June",
               "July",    "August",   "September",
               "October", "November", "December");    
//target = '';
targets = Array();

function set_date_field(y, m, d, t_idx) {
   eval(targets[t_idx] + ' = unescape(\'' + escape(format_date_field(y, m, d)) + '\')' );
}

function show_cal(target_a) {
   var d = new Date();
   show_cal_m(d.getFullYear(), d.getMonth(), target_a);
}

function show_cal_m(y,m, target_a) {
   t_idx = targets.push(target_a) - 1;
   write_cal_pop(y,m, open('about:blank','cal_win'+t_idx,'width=175,height=150'), t_idx);
}

function write_cal_pop(y,m, cal_win, t_idx) {
   cal_win.document.open();
   cal_win.document.writeln('&lt;html&gt;&lt;head&gt;&lt;title&gt;Date Picker&lt;/title&gt;');
   cal_win.document.writeln('&lt;style type="text/css"&gt;');
   cal_win.document.writeln('td {');
   cal_win.document.writeln('   font-family: Verdana, Arial, Helvetica, sans-serif;');
   cal_win.document.writeln('   font-size: 9pt;');
   cal_win.document.writeln('   color: #000000;');
   cal_win.document.writeln('   background-color: #CCCCCC;');
   cal_win.document.writeln('   text-align: center;');
   cal_win.document.writeln('}');
   cal_win.document.writeln('th {');
   cal_win.document.writeln('   font-family: Verdana, Arial, Helvetica, sans-serif;');
   cal_win.document.writeln('   font-size: 9pt;');
   cal_win.document.writeln('   color: #000000;');
   cal_win.document.writeln('   background-color: #CC0000;');
   cal_win.document.writeln('   text-align: center;');
   cal_win.document.writeln('}');
   cal_win.document.writeln('a {');
   cal_win.document.writeln('   color: #000000;');
   cal_win.document.writeln('   text-decoration: none;');
   cal_win.document.writeln('}');
   cal_win.document.writeln('&lt;/style&gt;&lt;/head&gt;&lt;body leftmargin=2 topmargin=2 marginwidth=2 marginheight=2&gt;');


   var one_day     = 1000 * 60 * 60 * 24;
   //var next_month  = (m==11) ? 0 : m + 1;

   d = new Date(y,m,1, 0,0,0,0);
   d = new Date(d.valueOf() - (one_day * 6));

   while (d.getDay() != 1) {
      d = new Date(d.valueOf() + one_day);
   }

   cal_win.document.writeln('&lt;table align="center" width="100%" height="100%"&gt;');
   cal_win.document.writeln('&lt;tr&gt;'); 

   //PREV
   cal_win.document.write('&lt;th&gt;&lt;a href="javascript: opener.write_cal_pop(');
   if (m==0) {  cal_win.document.write((y-1) + ', 11'); } 
   else      {  cal_win.document.write(y + ', ' + (m-1)); }
   cal_win.document.writeln(', self, ' + t_idx + ');"&gt;&amp;lt;&lt;/a&gt;&lt;/td&gt;');

   //CUR.
   cal_win.document.writeln('&lt;th colspan=5&gt;&lt;b&gt;' + m_list[m] + ' ' + y + '&lt;/b&gt;&lt;/td&gt;');

   //NEXT
   cal_win.document.write('&lt;th&gt;&lt;a href="javascript: opener.write_cal_pop(');
   if (m==11) {  cal_win.document.write((y+1) + ', 0');    } 
   else       {  cal_win.document.write(y + ', ' + (m+1)); }
   cal_win.document.writeln(', self, ' + t_idx + ');"&gt;&amp;gt;&lt;/a&gt;&lt;/td&gt;');

   cal_win.document.writeln('&lt;/tr&gt;'); 

   //day of week header
   cal_win.document.writeln('&lt;tr&gt;&lt;th&gt;M&lt;/th&gt;&lt;th&gt;T&lt;/th&gt;&lt;th&gt;W&lt;/th&gt;&lt;th&gt;T&lt;/th&gt;&lt;th&gt;F&lt;/th&gt;&lt;th&gt;S&lt;/th&gt;&lt;th&gt;S&lt;/th&gt;&lt;/tr&gt;');

   //DAYS
   day_count = 0;
   while (day_count &lt; 42) {
      day_count++

      if (d.getDay() == 1) { cal_win.document.writeln('&lt;tr&gt;'); }
      cal_win.document.writeln('&lt;td&gt;' + (d.getMonth()==m ? '&lt;b&gt;' : ''));
      cal_win.document.writeln('&lt;a href="javascript: opener.set_date_field(' +
              d.getFullYear() + ', ' + (d.getMonth()+1) + ', ' + d.getDate() + 
              ', ' + t_idx + '); self.close();"&gt;' +  d.getDate() + '&lt;/a&gt;');

      cal_win.document.writeln(d.getMonth()==m ? '&lt;/b&gt;&lt;/td&gt;' : '&lt;/td&gt;');
      //next
      //d = new Date(d.valueOf() + one_day); //replaced to stop double day in oct error
      d.setDate(d.getDate() + 1);
      //if (d.getMonth() == next_month &amp;&amp; d.getDay() == 1) {  break;  }
   }


   cal_win.document.writeln('&lt;/table&gt;');
   cal_win.document.writeln('&lt;/body&gt;&lt;/html&gt;');
   cal_win.document.close();
} 
</code></pre>

<p>In my php page i used the following code.</p>

<pre><code>&lt;td&gt;&lt;input type="text" name="joining" id="joining"/&gt;
                  &lt;a href="javascript: show_cal('document.admission_form.joining.value')"&gt;pick date&lt;/a&gt;&lt;/td&gt;
            &lt;/tr&gt;
</code></pre>

<p>If i click the pick date link calendar will opened in a new window. I need the calender should open near the input field in the same page. How can i do that?</p>
