
var ie=document.all;
var dom=document.getElementById;
var ns4=document.layers;
var myhost = window.location.hostname;


function calendar(date2,divid) {
  if(date2 == null || date2 == "") {
    date = new Date();
    day = date.getDate();
  } else  {
    date = new Date (date2);
    todate = new Date();
    if (todate >= date) {
       day = 31;
    } else {
       day = 0;
    }
  }

  month = date.getMonth();
  year = date.getFullYear();

  months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

  this_month = new Date(year, month, 1);
  next_month = new Date(year, month + 1, 1);

  first_week_day = this_month.getDay();
  days_in_this_month = Math.round((next_month.getTime() - this_month.getTime()) / (1000 * 60 * 60 * 24));

  
  nmonth = next_month.getMonth();
  prev_month = new Date(year, month -1, 1);
  pmonth = prev_month.getMonth();


  calendar_html = '<table>';
  calendar_html += '<tr><td colspan="2"><a href="javascript:calendar(\''+ prev_month +'\',\''+ divid +'\');">'+months[pmonth]+'</td><td colspan="3">' + months[month] + ' ' + year + '</td><td colspan="2"><a href="javascript:calendar(\''+ next_month +'\',\''+ divid +'\');">'+months[nmonth]+'</td></tr>';
  calendar_html += '<tr>';
  for(week_day = 0; week_day < first_week_day; week_day++) {
    calendar_html += '<td> </td>';
  }

  week_day = first_week_day;
  m = this_month.getMonth();
  m = m+1;
  if (m < 10) { m = "0"+m; }
  for(day_counter = 1; day_counter <= days_in_this_month; day_counter++) {
    week_day %= 7;
    if(week_day == 0)
      calendar_html += '</tr><tr>';
    
    d = day_counter;
    if (d < 10) { d = "0"+d; }
    if(day >= day_counter)
      calendar_html += '<td><a href="http://www.bollywoodhappening.com/news/date/'+year+'-'+m+'-'+d+'">' + day_counter + '</a></td>';
    else 
      calendar_html += '<td> ' + day_counter + ' </td>';


    week_day++;
  }

  calendar_html += '</tr>';
  calendar_html += '</table>';

 var crossobja = (dom)?document.getElementById(divid) : ie? document.all.divid : document.divid;
 crossobja.innerHTML = calendar_html;
}
