/*	
	initialise scripts
*/

$(document).ready(function(){
	/* Zebra Striping for Tables */					   
	$(".listing tbody tr:nth-child(even)").addClass("even");
	
	// add toggle panels on H5
	$(".toggle_container").hide();
	$("h5.trigger").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	}).click(function(){
		$(this).next(".toggle_container").slideToggle("slow,");
	});

	
	
	// table sorter
if ($.tablesorter){
	// add parser : deal with formatted numbers
    $.tablesorter.addParser({
        // set a unique id
        id: 'fmtnum',
        is: function(s) {
            // return false so this parser is not auto detected
            return false;
        },
        format: function(t) {
		
            // remove non digit or '.'
			var s = parseFloat(t.replace(/[^0-9\-\.]/g,''));
			//	if (t=='1 090 815') debug(t+ ' = '+s + '  '+ isNaN(s));
			if (isNaN(s)) s=0;
			return s;
           // return s.toLowerCase().replace(/good/,2).replace(/medium/,1).replace(/bad/,0);
        },
        // set type, either numeric or text
        type: 'numeric'
    });


	// add parser : deal with period yyyy or yyyy-yyyy or mm-yyyy or yyyy-Tn
    $.tablesorter.addParser({
        // set a unique id
        id: 'period',
        is: function(s) {
            // return false so this parser is not auto detected
            return false;
        },
        format: function(t) {
            var s = t.split('-');
			if (s[1]==undefined) { // année pleine
				return s+'01'; // code 01
			}
			else if (s[1].charAt(0)=='T') { // trimestre
				return s[0]+s[1].charAt(1);
			}
			else if (s[1].length==2) { // mois
				return t;
			}
			else { // année à cheval
				return s[1]+'02'; // code 01
			}

			
           // return s.toLowerCase().replace(/good/,2).replace(/medium/,1).replace(/bad/,0);
        },
        // set type, either numeric or text
        type: 'text'
    });

}

	/* Closing Divs */
	$(".canhide").append("<div class='close-message'>Fermer</div>").css("position", "relative");
	$(".close-message").click(function() {
		$(this).hide();
		$(this).parent().fadeOut(600);
	});

	// setup ul.tabs to work as tabs for each div directly under div.panes
    $("ul.tabs").tabs("div.panes > div");
	
	
});

//  ======= confirmer =====
function confirmed(msg){
 var a = window.confirm("voulez vous r\351ellement supprimer cet \351l\351ment ?\n"+msg);
 return a;
}
// ==== smal debug util ====
function debug (log) {
    if (window.console != undefined)  console.log(log);
}

