$(function(){
 $.datepicker.regional['fr'] = {
	  closeText: 'Fermer',
	  prevText: '&#x3c;Prec',
	  nextText: 'Suiv&#x3e;',
	  currentText: 'Courant',
	  monthNames: ['Janvier','Fevrier','Mars','Avril','Mai','Juin',
	  'Juillet','Aout','Septembre','Octobre','Novembre','Decembre'],
	  monthNamesShort: ['Jan','Fev','Mar','Avr','Mai','Jun',
	  'Jul','Aou','Sep','Oct','Nov','Dec'],
	  dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
	  dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
	  dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
	  dateFormat: 'dd/mm/yy', firstDay: 1,
	  isRTL: false,
	  changeMonth: true,
	  changeYear: true
};

$.datepicker.setDefaults($.datepicker.regional['fr']);
	

	$('input[id*="DT"]').datepicker();

  $('img[src$="calend.gif"]').attr('onclick','').click(function(e){
      e.preventDefault();
      var id = $(this).attr('id');
      $('#DT_'+id)[0].focus();
      return false;
  });
  
    var alternateColumn = function($table){
      $table.find('tr:odd').removeClass('even').addClass('odd');
      $table.find('tr:even').removeClass('odd').addClass('even');
    }
  
    $('table.sortable').each(function(){
    
      var $table=$(this);
      alternateColumn($table);

	$('tr:first-child',$table).find('td span:first-child').each(function(){
		$(this).parent().attr('className',$(this).attr('className'));
	});

      $('tr:first-child',$table).addClass('header').find('td').attr('title','Cliquez pour trier').each(function(column){
        
        var $header = $(this);                                                                           
        var keySort = null
        if($header.is('.sort-alpha')){
          keySort = function($cell){
            return $cell.text().toUpperCase();
          }
        }
        else if($header.is('.sort-date')){
          keySort = function($cell){
            var dateTxt = $cell.text();
            
            if(dateTxt=="") return "99991231";
            
            var date = dateTxt.match(/([0-9]{2}).([0-9]{2}).([0-9]{4})/);
             
            if(date!=null && date.length>=3)
              return date[3]+date[2]+date[1];
            else
              return "99991231"
          }
        }
        
        if(keySort){
          $('<span class="sort-button"></span>').appendTo($header);
          $header.addClass('clickable')
            .hover(function(){$header.addClass('hover')},function(){$header.removeClass('hover')})
            .click(function(){
              var sortDirection = 1;
              
              if($header.is('.sorted-asc')){
                sortDirection=-1;
              }
              
              var rows = $table.find('tr:not(:first-child)').get();
              
              $.each(rows,function(index,row){
                var $cell = $(row).children('td').eq(column).find('span:eq(0)');
                row.sortKey = keySort($cell);
              });
              
              rows.sort(function(a,b){
                if(a.sortKey < b.sortKey) return -sortDirection;
                if(a.sortKey > b.sortKey) return sortDirection;
                return 0;
              });
              
              var $first = $table.find('tr:first-child:eq(0)');
              
              $.each(rows,function(index,row){
                $(row).insertAfter($first);
                row.sortKey == null;
              });
              
              $first.find('td').removeClass('sorted-asc').removeClass('sorted-desc');
              
              $first.find('td').eq(column).addClass(sortDirection==1 ? 'sorted-asc':'sorted-desc');  
              
              alternateColumn($table);
              
            });
        }
      });
    });
    
    function divaltoMakeTableHeaderColapsible(selector,colspan,indexActif){
       var $table = jQuery(selector);
       
       colspan = colspan || $table.attr('divaltoColapsibleColspan');
       
       var tdSel = 'td'
       
       if(colspan>0){
        tdSel = tdSel+'[colspan="'+colspan+'"]'
       }
		
       //jQuery(tdSel,$table).prepend('<span class="ui-icon ui-icon-circle-triangle-e" />').wrapInner('<a class="trigger" href="#" title="Cliquez pour déployer/cacher"></a>').closest('tr')
       jQuery(tdSel,$table).prepend('<span class="ui-icon ui-icon-circle-triangle-e" />').wrapInner('<a class="trigger" href="#" />').closest('tr').css("cursor","pointer").attr("title","Cliquez pour déployer")
       .click(function(event,startScroll){
        event.preventDefault();
        var $this = jQuery(this);
        var $tr = $this.closest('tr');
        
        if($tr.is(':not(.opened)')){
          $tr.attr("title","Cliquez pour cacher").nextUntil('.colapsible').show().end().addClass('opened').removeClass('closed').find('.ui-icon').toggleClass('ui-icon-circle-triangle-e ui-icon-circle-triangle-s');
        } else {
          $tr.attr("title","Cliquez pour deployer").nextUntil('.colapsible').hide().end().addClass('closed').removeClass('opened').find('.ui-icon').toggleClass('ui-icon-circle-triangle-e ui-icon-circle-triangle-s');
        }
		
		var doScroll = $table.attr('divaltoColapsibleScroll') || true;
		
		if(doScroll!=false && !startScroll){
			$.smoothScroll({
			   scrollTarget: $tr
			  ,offset : parseInt($table.attr('divaltoColapsibleScrollOffset')) || 0
			});
		}
        return false;
       }).removeClass('cacheable').addClass('colapsible').nextUntil('.colapsible').filter('tr').addClass('cacheable');
    
       var maxWidth = 0;
       jQuery('tr:not(.colapsible) td:nth-child(1)',$table).each(function(){
        maxWidth = Math.max(maxWidth,jQuery(this).width());
       });
    
       jQuery('td:eq(0)',$table).width(maxWidth);
    
       jQuery('.cacheable',$table).hide();
      
      indexActif = parseInt(indexActif || $table.attr('divaltoColapsibleOpenIndex'));
      
      if(typeof indexActif != 'unknown' ){
        jQuery('tr.colapsible',$table).eq(indexActif).trigger('click', [true]);
      }
    }
    
    divaltoMakeTableHeaderColapsible('table.colapsible');
    
    $('#ui-datepicker-div').height('18em');

 


});

/*!
 * jQuery Smooth Scroll Plugin v1.3
 *
 * Date: Wed Dec 1 15:03:21 2010 -0500
 * Requires: jQuery v1.3+
 *
 * Copyright 2010, Karl Swedberg
 * Dual licensed under the MIT and GPL licenses (just like jQuery):
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 *
 *
 *
*/
(function(b){function k(e){var c=[],a=false;this.each(function(){if(!(this==document||this==window)){var d=b(this);if(d.scrollTop()>0)c.push(this);else{d.scrollTop(1);a=d.scrollTop()>0;d.scrollTop(0);a&&c.push(this)}}});if(e==="first"&&c.length)c=[c.shift()];return c}function l(e){return e.replace(/^\//,"").replace(/(index|default).[a-zA-Z]{3,4}$/,"").replace(/\/$/,"")}var m=l(location.pathname);b.fn.extend({scrollable:function(){return this.pushStack(k.call(this))},firstScrollable:function(){return this.pushStack(k.call(this,
"first"))},smoothScroll:function(e){e=e||{};var c=b.extend({},b.fn.smoothScroll.defaults,e);this.die("click.smoothscroll").live("click.smoothscroll",function(a){var d=b(this),f=location.hostname===this.hostname||!this.hostname,g=c.scrollTarget||(l(this.pathname)||m)===m,i=this.hash,h=true;if(!c.scrollTarget&&(!f||!g||!i))h=false;else{f=c.exclude;g=0;for(var j=f.length;h&&g<j;)if(d.is(f[g++]))h=false;f=c.excludeWithin;g=0;for(j=f.length;h&&g<j;)if(d.closest(f[g++]).length)h=false}if(h){c.scrollTarget=
e.scrollTarget||i;c.link=this;a.preventDefault();b.smoothScroll(c)}});return this}});b.smoothScroll=function(e,c){var a,d,f,g=0;d="offset";var i={};if(typeof e==="number"){a=b.fn.smoothScroll.defaults;f=e}else{a=b.extend({},b.fn.smoothScroll.defaults,e||{});if(a.scrollElement){d="position";a.scrollElement.css("position")=="static"&&a.scrollElement.css("position","relative")}f=c||b(a.scrollTarget)[d]()&&b(a.scrollTarget)[d]()[a.direction]||0}a=b.extend({link:null},a);if(a.scrollElement){d=a.scrollElement;
g=d.scrollTop()}else d=b("html, body").firstScrollable();i["scroll"+{top:"Top",left:"Left"}[a.direction]]=f+g+a.offset;d.animate(i,{duration:a.speed,easing:a.easing,complete:function(){a.afterScroll&&b.isFunction(a.afterScroll)&&a.afterScroll.call(a.link,a)}})};b.smoothScroll.version="1.3.1";b.fn.smoothScroll.defaults={exclude:[],excludeWithin:[],offset:0,direction:"top",scrollElement:null,scrollTarget:null,afterScroll:null,easing:"swing",speed:400}})(jQuery);






