$(function() {
    $.getScript( "/static/demo/calendar.js" )
	  .done(function( script, textStatus ) {
                      var d = new Date();
                      var dm = d.getMonth() + 2;
                      var dan = d.getYear();
                      if(dan < 999) dan+=1900;
                      var $calendar= calendrier( dm,dan );
		      $( 'div.calendrier' ).append( $calendar );		  
		      // $( 'div.calendrier' ).css("display","none");
		      console.log( textStatus );
		      var $items = $("div.calendrier ul li label");
		      $items.each(function() {
                              var span = ("span", $(this)).html();
			      $("span",this).html(span.replace(/;/g,"<br>"))
			      $(this).css("display","block");
			      var $input = $("input", this);
		              var item_date = $input.attr("id").split('_')[2];
			      $("table.calendrier td[td_date='"+item_date+"']").append($(this));
			      if ($input.attr("id").indexOf("exception") != -1) {
				   $(this).css({'color':'red',
				                'margin-top':'0.5em',
				                'text-align':'center'});
			           $input.remove();
		              }
		          });
		    })
	  .fail(function( jqxhr, settings, exception ) {
		      $( "div.log" ).text( "Triggered ajaxError handler." );
	  });
}); /* end */

