Template:Team:Uppsala/JS/notebook

From 2013.igem.org

Revision as of 11:53, 19 August 2013 by Krlu2935 (Talk | contribs)

<script language="javascript">

var month = new Date().getMonth();		  // current month that the calendar will show 

var year = new Date().getFullYear(); // current year that the calendar will show var cal_table = ; // calendar string var eventString; var days_with_dirys = new Array('t201381'); var inputs = 1; var days_in_month = new Array(31,28,31,30,31,30,31,31,30,31,30,31);


Date.prototype.getWeek = function() {

       var onejan = new Date(this.getFullYear(),0,1);
       return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);

}

function calendar_normal() { var m = month+1; var date = new Date(); // todays date

       var today = date.getDate(); 	   //  todays month number 

cal_table = ;

if(year<=200) {

               year += 1900;

}

       months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

var weekDay = new Array('Mon', 'Tue', 'We', 'Thu', 'Fri', 'Sat', 'Sun'); days_in_month = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

if(year%4 == 0 && year!=1900) {

               days_in_month[1]=29;

}

       total = days_in_month[month];
       var date_today = months[month]+' '+year;
       
cal_table = cal_table + '<tbody id="cal_body">'; cal_table = cal_table + '';
       week = 0;

var first_week_day = new Date(year, month, 0).getDay();

       for(week_day = 0; week_day < first_week_day; week_day++) 
       {
cal_table = cal_table +'';
               week++;
       }
       for(i=1;i<=total;i++)
       {
               if(week==0)
               {
cal_table = cal_table + ''; } if(today==i && month == date.getMonth() && year == date.getFullYear()) { cal_table = cal_table +'';
               }
               else
               {
cal_table = cal_table +'';
               }
               week++;

markerNotes(year, m, i);

               if(week==7)
               {

var weeknr = new Date(year, month, i-1).getWeek();

cal_table = cal_table + ''; cal_table = cal_table + ''; week=0; } } for(i=1;week!=0;i++) { cal_table = cal_table + '';
               week++;
               if(week==7)
               {		

if(weeknr == 53) { var weeknr = 1; } else { var weeknr = weeknr+1; }

cal_table = cal_table + '';
                       cal_table = cal_table + '</tr>';
                       week=0;
               }
       }
cal_table = cal_table + '</tbody>
<input id="left" type="image" onclick="left_arrow()" src="image/buttons/arrowleft.png">'+date_today+'<input id="right" type="image" onclick="right_arrow()" src="image/buttons/arrowright.png">
MonTueWedThuFriSatSunWeek
<input type="submit" onclick="showNotes(year, month, value)" value="'+i+'"> <input type="submit" onclick="showNotes(year, month, value)" value="'+i+'"> <input type="submit" onclick="showNotesOfweek(year, value)" value="'+weeknr+'">
<input type="submit" onclick="showNotesOfweek(year, value)" value="'+weeknr+'">
';

}


function left_arrow() { month = month-1; if(month == -1) { year = year - 1; month = 11; } calendar_normal(); document.getElementById('calendar').innerHTML = cal_table; }


function right_arrow() { month = month+1; if(month == 12) { year = year +1; month = 0; } calendar_normal(); document.getElementById('calendar').innerHTML = cal_table; }


function showNotes(y, m, day) { var m = month+1;

eventString = '

'+y+'-'+m+'-'+day+'

';

document.getElementById('file_holder').innerHTML = eventString; }

function showNotesOfweek(y, wnr) { var d = new Date(y, 0, 0); var w = d.getTime() + 604800000 * (wnr-1); var m = new Date(w).getMonth()+1; var y = new Date(w).getFullYear(); var day = new Date(w).getDate();

var e = new Date(w).getDay(); day = day - e+1;

eventString = '

'+y+'-'+m+'-'+day+'

';

for(i=1;i<7;i++) { if(days_in_month[m-1] == day ) { day = 0; m++; if(m>12) { y++; var d = new Date(y, 0, 0); var w = d.getTime() + 604800000 * (wnr-1); var m = 1; }

} day++;

eventString = eventString + '

'+y+'-'+m+'-'+day+'

';

} document.getElementById('file_holder').innerHTML = eventString; eventString = ; }

function markerNotes(y, m, d) { var id='t'+y+m+d;

for(c = 0; c<=inputs; c++) { if(days_with_dirys[c] == id) {


cal_table = cal_table + '<style type="text/css">#'+id+'{border: 2px solid #FFA500;}</style>';

} } } </script>