(function($) {
	$.fn.nText = function(){return Number(this.text())};
	$.fn.json = function(){var val = this.text() || '{}'; return eval('(' + val + ')')};
	$.fn.sumHeights = function(o){var t=0; this.each(function(){t+=$(this).height()}); return t+(o?o:0)}
	$.fn.sumOuterHeights = function(o){var t=0; this.each(function(){t+=$(this).outerHeight(true)}); return t+(o?o:0)}
	$.fn.sumOuterWidths = function(o){var t=0; this.each(function(){t+=$(this).outerWidth(true)}); return t+(o?o:0)}
	$.fn.adjustHeight = function(p, m, offset){
						var p_ = $(p).sumOuterHeights();
						var m_ = $(m).sumOuterHeights();
						var new_h = Math.max(0,p_-m_+ (offset?offset:0));
						//alert(p_ + ' - ' + m_ + ' + ' + offset + ' = ' + new_h);
						return this.height(Math.max(new_h, 0));
	}
	$.fn.createDataObj = function(){return this.each(function(){ if (this.data == null) this.data = {}; })};
	$.fn.addHtml = function(a){return this.each(function() {$(this).html($(this).html() + a)})};
	$.fn.matchHeight = function(source, offset){offset = offset || 0; return this.each(function(){$(this).height($(source).innerHeight() + offset)})};
	$.fn.matchOuterHeight = function(source, offset){offset = offset || 0;var target=$(source).outerHeight(); return this.each(function(){$(this).height(target - $(this).outerHeight() + $(this).height() + offset)})};

	$.fn.heightDiff = function(){var tot=0; this.each(function(){tot += $(this).outerHeight()-$(this).height()}); return tot};
	$.fn.matchWidth = function(source, offset){offset = offset || 0; return this.each(function(){$(this).width($(source).innerWidth() + offset)})};
	$.fn.matchOuterWidth = function(source, offset){offset = offset || 0; var target = $(source).outerWidth(); return this.each(function(){$(this).width(target-$(this).outerWidth()+$(this).width() + offset)})};
	
	$.fn.matchWidthInside = function(source, offset) {offset = offset || 0; return this.each(function(){$(this).width($(this).innerWidth()+offset) })};
	$.fn.matchDim = function(source){return $(this).height(a=source.height()).width(b=source.width());}
	$.fn.replClass = function(cl1, cl2, droite){
		if (droite == null) droite = true;
		if (!droite) {
			var temp = cl1;
			cl1 = cl2;
			cl2 = temp;
		}
		return this.each(function(){
							if ($(this).hasClass(cl1)) $(this).removeClass(cl1).addClass(cl2);
								  })
	} 
	$.fn.fill = function(offset){
		return this.each(function(){
		  var a=$(this);
		  offset = offset || 0;
		  //LK.alert(YLS('par = {par}({id}); sibl = {sibl}; diff = {diff}; off = {off}}', {par:a.parent().height(),id:a.parent().attr('id'), sibl:a.siblings(':visible').not('.ui-resizable-handle').sumOuterHeights() , diff:a.height()-a.outerHeight(), off:offset}))
		  a.height(a.parent().height()-a.siblings(':visible').not('.ui-resizable-handle').sumOuterHeights()+a.height()-a.outerHeight(true) +offset);
		  })
	}
	$.fn.fillWidth = function(params){
		var b, c, d, e, result, offset
		if (typeof(params) == 'object'){
			offset = params.offset
		}
		if (typeof params == 'number')
			params = {offset:params};
		params = $.extend({offset:0}, params || {});
		return this.each(function(){
			var a = $(this), autres;
			if (params.autres){
				autres = $(params.autres)
				//LK.alert('sum ' + params.autres + ' = ' + autres.sumOuterWidths())
			} else
				autres = a.siblings();
			a.width(result = (b=a.parent().width())-(c=autres.sumOuterWidths())+(d=a.width())-(e=a.outerWidth())-1 + params.offset);
			//LK.alert('Result = ' + result + ' = parent (' + b + ') - sum_autres('+ c + ') + w(' + d + ') - outerW(' + e + ') - 1 + offset(' + params.offset + ') ' + offset)
		})
	}
	$.fn.rotateClass = function(classes, droite){ 	
													var repl; 
													return this.each(function(){
														var $this = $(this);
														var done = false;
														$.each(
															 classes, function(ind, classe){
																			if ($this.hasClass(classe)) {
																				if (droite && ind == classes.length-1)
																					repl = classes[0]
																				else if (!droite && ind == 0)
																					repl = classes[classes.length-1]
																				else
																					repl = classes[ind + (droite?1:-1)]
																				$this.replClass(classe, repl)
																					.LKdata({prevClass:classe, newClass:repl})
																				done = true;
																				return false
																			}
															 })
														if (!done) $(this).addClass(classes[0]).LKdata({prevClass:null, newClass: classes[0]});
																			  })
	}
	
	$.fn.trim = function(sel){var set = this; 
					if (sel) 
						{set = this.filter(sel)};
					set.each(function(){
									  var a; 
									  (a=$(this))
									  	.val($.trim(a.val()))
										}); 
					return this}; 
	$.origTarget = function(event){return $.browser.msie?event.srcElement:event.originalEvent.target};
	$.fn.sumBorderHeights = function(){
		var tot = 0; 
		this.each(function(){
						   tot += Number($(this).css('border-top-width').match(/[0-9]+/))
									+ Number($(this).css('border-bottom-width').match(/[0-9]+/))
									}
									); 
		return tot;
	}
	$.fn.sumBorderWidths = function(){
		var tot = 0; 
		this.each(function(){
						   tot += Number($(this).css('border-left-width').match(/[0-9]+/))
									+ Number($(this).css('border-right-width').match(/[0-9]+/))
									}
									); 
		return tot;
	}
	$.fn.sumPaddings = function(){
		var tot = 0; 
		this.each(function(){
						   tot += Number($(this).css('padding-top').match(/[0-9]+/))
									+ Number($(this).css('padding-bottom').match(/[0-9]+/))
									}
									); 
		return tot;
	}
	$.fn.nVal = function(){var res = this.val(), i; 
							if (res.constructor == 'Array')
								for (i in res) {
									if(isNaN(i)) continue; 
									res[i]=Number(res[i]);
									}
								//$.each(res, function(val, ind){res[ind]=Number(res[ind])});
							else
								res = Number(res);
							return res;
	}
	$.fn.ids = function(){var res = []; this.each(function(){res.push('#' + this.id)});return res.toString()};
	$.fn.hide_ = function(){this.each(function(){$(this).css('visibility', 'hidden')}); return this};
	$.fn.invisible_ = function(){this.each(function(){$(this).css('visibility', 'hidden')}); return this};
	$.fn.show_ = function(){this.each(function(){$(this).css({visibility:'visible'})}); return this};
	$.fn.visible_ = function(){this.each(function(){$(this).css('visibility', 'visible')}); return this};
	$.fn.addTo = function($dest){$dest.mypush(this);return this};
	$.fn.addTo_ = function($dest){$dest.mypush(this); return $dest};
	$.fn.mypush = function(val){
		var i,j, nodes = ((typeof(val) == 'string')?$(val):val);
		for(i = 0, j = nodes.length; i<j; i++) this[this.length++] = nodes[i];
		return this;
	}
	$.fn.LKdata = function(key, val){ // if no param, return data obj of 1st element;
										// if key param: return key value of 1st element
										// if key and val, set data.key = val for all elements;
				if (this.length == 0) return null;
				if (arguments.length == 2)	return this.each(function()	{set_data(this)[key] = val;});
				if (arguments.length == 0) return set_data(this[0]);
				if (arguments.length == 1)
					if (typeof(key) == 'string')
						return set_data(this[0])[key];
					else
						
						return this.each(function(){
												  var obj = this;
												  LK.each(key, function(ind, val){
														  $(obj).LKdata(ind, val);
																		   })
												  })
	}
	
	var set_data = function(obj){
						var data = $.data(obj, 'LK');
						if (data == null) data = $.data(obj, 'LK', {this_:obj});
						return data
	}
		
	var show_shadow = function(ev){
		var a;
		if ((a=$(this).LKdata().$shadow) && $(this).is(':visible') ){
			setTimeout(function(){a.attach().show()}, 0);
		}
	}
	var hide_shadow = function(ev){
		var a
		if (a=$(this).LKdata().$shadow)
			a.hide();
	}
	$.fn.hideShadow = function(){
		return this.each(function(){hide_shadow.call(this)});
	}
	
	$.fn.showShadow = function(){
		
		return this.each(function(){show_shadow.call(this)});
	}
	
	$.fn.addShadow = function(shadowClass, offsetLeft, offsetTop){
		this.each(function(){
						if (!shadowClass) return;
						var data = $(this).LKdata();
						if (data.$shadow) return;
						data.$shadow = $('<div>').appendTo(document.body).css({position: 'absolute', display:$(this).is(':visible')?'block':'none'});
						if (isNaN(a=$(this).css('z-index')) || (a==1)) $(this).css('z-index', 10);
						data.$shadow.css('z-index',$(this).css('z-index')-1);
						
						if (shadowClass) data.$shadow.addClass(shadowClass);
						$(this).bind('aftershow', show_shadow)
						$(this).bind('beforehide', hide_shadow)								
						
						data.$shadow.attach('store', {attach: this, match_dim: this, match_dim_mode:'outer', offset_obj: [offsetLeft || 10, offsetTop || 10]});
						if ($(this).is(':visible')) data.$shadow.show();
						   });
		return this;
	}
	/*
	$.fn.onShow = function(fnct){
			this.each(function(){
						var data = set_data(this);
						var old_show = $(this).show;
						$(this).show = function(){old_show(); fnct()}
							   });
			return this;
	}
	*/				  
	var show_orig = $.fn.show;
	$.fn.show = function(){
		var args = arguments;
		 this.each(function(){
			$(this).triggerHandler('beforeshow');
				var data = $(this).LKdata();
				if (data  && data.show)
					data.show.call($(this))
				else 
					show_orig.apply($(this), args)
			 $(this).triggerHandler('aftershow');
					   }
						   
						   )
		 return this;
	}
	var hide_orig = $.fn.hide;
	$.fn.hide = function(){
		var args = arguments;
		this.each(function(){
				var data = $(this).LKdata();
				$(this).triggerHandler('beforehide');
				if (data  && data.hide)
					data.hide.call($(this))
				else
					hide_orig.apply($(this), args)
				$(this).triggerHandler('afterhide');
						   })
		return this;
	}
	var fadeOut_orig = $.fn.fadeOut;
	$.fn.fadeOut = function(){
		var args = arguments;
		this.each(function(){
				var $shadow;
				if (($shadow = $(this).LKdata('$shadow')))
					fadeOut_orig.apply($shadow, args);
				fadeOut_orig.apply($(this), args);
						   });
	}
				
	
	var compte = 3;
	
	var attach_cfg = {};
	attach_cfg.$liste_attach = $('liste_vide');
	attach_cfg.$liste2clear = $('liste_vide');
	attach_cfg.levels = [];
	
	must_refresh_levels = false;
	
	attach_cfg.determine_levels = function() {
		var i = 0;
		attach_cfg.levels = [];
		attach_cfg.nodes = [];
		//time1 = (new Date()).getTime();
		
		$('*').each(function()
					{
						if ($.data(this,'LK')){
							$.data(this,'LK').attached = false;
							$.data(this,'LK').level = null;
							i++;
							//db('-------' + this.id + '.' + this.className);
						};
						
						});
		//time2 = (new Date()).getTime()-time1
		//console.log('-------> ' + time2 + ' ms')
		//db('mise à zéro de ' + i + ' objets')
		attach_cfg.$liste_attach.each(function(){
											  	$(this).LKdata({level: null, attached: true});
											   });
		attach_cfg.$liste_attach.each(function(){
					if ($(this).LKdata('level') != null) return;
					$(this).LKdata('level', determine_level(this, '/', 0));
					if ($(this).LKdata('level')) attach_cfg.levels.push($(this));
											   }
									  )
		attach_cfg.levels.sort(function(a, b) { return a.LKdata('level') - b.LKdata('level')});
	}
	var attachedTo = function(obj){
		var data = $(obj).LKdata(), a;
		if (data.attach_spec == null) return null;
		if (typeof(a=data.attach_spec.attach) == 'object' || typeof(a) == 'string') return $(data.attach_spec.attach)
		return null
	}
	var levels = '----------------------------------';
	var determine_level = function(obj, deja_faits, niv){
		var ancest
		var data = $(obj).LKdata(), attach, a
		if ((a = attachedTo(obj)) && (attach = a[0]))
			if (deja_faits.indexOf('/' + $.data(attach) + '/') != -1){
				return 0;
			}
			else {
				deja_faits += $.data(attach) + '/';
				if ($(attach).LKdata('level') == null) {
					$(attach).LKdata('level', a = determine_level(attach, deja_faits, niv));
					if (a) attach_cfg.levels.push($(attach));
					if (!$(attach).LKdata('attach_spec')) $(attach).addTo_(attach_cfg.$liste2clear);
				}
				return $(attach).LKdata("level") + 1;
			}
		else {
			ancest = obj;
			while ((ancest = ancest.parentNode) && (ancest.nodeName != 'BODY') && !$(ancest).LKdata('attached')) ;
			if ($(ancest).LKdata('attached')){
				return determine_level(ancest, deja_faits, niv) +1
			}
			 else
			 return 0;
		}
	}
	
	var timeout;
	$.adjust_all = function(param){
		if (must_refresh_levels){
			must_refresh_levels = false;
			attach_cfg.determine_levels();
		}
		if (timeout) {
			clearTimeout(timeout);
			timeout = null;
		}
		$.each(attach_cfg.levels, function(ind, $val){
										   var a;
										  if ((a= $val.LKdata('attach_spec')))
											   process_attach($val,a);
										   })
		if (param == null && LK.IE)
			timeout = setTimeout(function(){$.adjust_all('tim')}, 50);
				
		return attach_cfg.levels.length;
	};
										   
	$.fn.attach_cfg = function(cfg){
		$.extend(attach_cfg, cfg);
	}
	$.fn.attach = function(task, params){
		must_refresh_levels = true;
		task = task || "";
		return this.each(function(){
						var a;
						var data = $(this).LKdata();
						data.attach_spec = data.attach_spec || {};
						a = data.attach_spec;
						
						
						if (task=='detach'){	
							$liste_attach = $liste_attach.not(this);
							$(this).LKdata({attached: false, attach_spec: null, level:null});
							if (data.attach_event){
								data.attach_event = false;
								$(this).unbind('aftershow', process_attach_ev)
							}
							return;
						}
						if (task == 'extend_once'){ //extend once
							a = {};
							for (i in data.attach_spec) a[i] = data.attach_spec[i];
							$.extend(a, params);
							process_attach($(this), a);
							if (!data.attach_event) {
								data.attach_event = true;
								$(this).bind('aftershow', process_attach_ev)
							}
							return;
						} else if (task=='extend') {
							$(this).addTo_(attach_cfg.$liste_attach).addTo_(attach_cfg.$liste2clear);
							$.extend(a, params)
							process_attach($(this), a);
							if (!data.attach_event) {
								data.attach_event = true;
								$(this).bind('aftershow', process_attach_ev)
							}
							return;
						}
						
						if (task == 'store'){	
							data.attach_spec = params;
							$(this).addTo_(attach_cfg.$liste_attach).addTo_(attach_cfg.$liste2clear);
							if (!data.attach_event) {
								data.attach_event = true;
								$(this).bind('aftershow', process_attach_ev)
							}
							return;
						}
						process_attach($(this), params || a);
						   })
	}
	var process_attach_ev = function(ev){
		var data = $(this).LKdata();
		var $obj = $(this);
		var empty = true;
		var parent_pos;
		$.each(data.attach_spec, function(ind, val){
										  if (ind) return (empty = false);
										  });
		if (data.attach_spec && !empty){
			process_attach($obj, data.attach_spec);
		}
		if ($obj.is(':visible') && data.$shadow){
			process_attach(data.$shadow, data.$shadow.LKdata('attach_spec'));
		}
			
			
	}
	$.fn.std_dial_cfg = function(){
		return $(this).dialog('option',{
			resizeStart:function(){
				$('body').disableSelection()
			},
			resizeStop:function(){
				$('body').enableSelection()
			},
			dragStart:function(){
				$('body').disableSelection()
			},
			dragStop:function(){
				$('body').enableSelection()
			},
			open:function(){
				var max = parseInt($(this).dialog('option','maxHeight'))
				if (isNaN(max)){
					max = $(window).height()
				}
				var cur_height
				if ((cur_height = $(this).dialog('widget').height()) > max){
					$(this).height(Math.max(100,max + $(this).height() - cur_height))
				}
			}
		})
	}
	$.process_attach = function(){
		return attach_cfg.$liste_attach.each(function(){
					var data = $(this).LKdata();
					if (!data) return;
					process_attach($(this), data.attach_spec);
											   })
	}
	var load_contents_url = "./PHP/get_text2.php?tache=get_help_text&node_id={node_id}&section={section}";
	var process_attach = function($obj, a){
		var obj_data = $obj.LKdata(), pos_attach,x,y, val, diff, valtype
		if (a.off) $(a.off).hide();
		var contents_no
		if (a.loadContents && !obj_data.contentsLoaded){
			if(isNaN(a.loadContents)){
				 contents_no= a.loadContents.no;
				obj_data.header = a.loadContents.header || '';
				obj_data.footer = a.loadContents.footer || '';
			} else
				contents_no = a.loadContents;
			if(contents_no != null)
				$.getJSON(YAHOO.lang.substitute(load_contents_url, {node_id: $obj[0].id, section: contents_no}),
									function(data){
										$obj
											.html(data.text || data.msg)
											.LKdata('contentsLoaded', true);
										
									}
									);
		}
				//attach_cfg.text_load_fnct({tache: 'get_help_text', section: contents_no, node_id: $obj[0].id})
		if (a.attachParent == true) {
			a.attach = $obj.parent();
			a.attachParent = null
		}
		
		var attachToPoint = (a.attach && a.attach.pageX != null) // si c'est un point et non un objet auquel il faut s'attacher
			
		a.offset_obj = a.offset_obj || [0,0];
		a.offset_bulle = a.offset_bulle || [0,0];
		var attach_to_obj = (typeof(a.attach)=='object' || typeof(a.attach) == 'string');
		if (attach_to_obj) {
			pos_attach = attachToPoint?{left: a.attach.pageX, top:a.attach.pageY}:$(a.attach).offset();
			if (a.context){
				if (val = a.context.obj){
					pos_attach.left += (!attachToPoint?$(a.attach).outerWidth()*(val.leftX ||0):0) + (val.left||0);
					pos_attach.top += (!attachToPoint?$(a.attach).outerHeight() * (val.topX ||0):0) + (val.top||0);
					// NOTE: prise en compte de parametre "bulle" de context après détermination de dim de bulle...
				}
			} else {
				
				pos_attach.left += a.offset_obj[0] - a.offset_bulle[0];
				pos_attach.top += a.offset_obj[1] - a.offset_bulle[1];
				if (!attachToPoint) {
					if (a.side == 'right')
						pos_attach.left += $(a.attach).width();
				
					if (a.side == 'center') 
						pos_attach.left += $(a.attach).width()/2;
					if (a.vert == 'bottom')
						pos_attach.top += $(a.attach).height();
				
					if (a.vert == 'center')
						pos_attach.top += $(a.attach).height()/2;
				}
			}
			/*
			// tenir compte du fait que la fenêtre pourrait ne pas avoir <body> pour parent (donc la position sera par rapport au parent)
			if (!$(a.attach).parent().is('body')){
				parent_pos = $(a.attach).parent().offset();
				pos_attach.left -= parent_pos.left;
				pos_attach.top -= parent_pos.top;
			}
		*/
			
		}
		a.diffWidth = a.diffWidth || 0;
		var diffW = (typeof(a.diffWidth) == 'function'?a.diffWidth():a.diffWidth) 
		a.diffHeight = a.diffHeight || 0;
		var diffH = (typeof(a.diffHeight) == 'function'?a.diffHeight():a.diffHeight)
		var h = null, w = null;
		
		if (attach_to_obj && (a.match_dim == true) && !attachToPoint ) {
			if (a.match_dim_mode == 'outer'){
				w = $(a.attach).outerWidth()+diffW;
				h = $(a.attach).outerHeight() + diffH;
			}else{
				w = $(a.attach).width()+diffW;
				h = $(a.attach).height() + diffH;
			}
		} else if (typeof(a.match_dim) == 'object' || typeof(a.match_dim) == 'string') {
			if (a.match_dim_mode == 'outer'){
				w = $(a.match_dim).outerWidth()+diffW;
				h = $(a.match_dim).outerHeight() + diffH;
			} else {
				w = $(a.match_dim).width()+diffW;
				h = $(a.match_dim).height() + diffH;
			}
		} else {
			if (attach_to_obj && (a.match_width == true) && !attachToPoint) {
				w = $(a.attach).width()+diffW;
			} else if (typeof(a.match_width) == 'object' || typeof(a.match_width) == 'string') {
				w = $(a.match_width).width()+diffW;
			} else if (a.width) 
				w = a.width;
			
			if (attach_to_obj && (a.match_height == true) && !attachToPoint) {
				h = $(a.attach).height() + diffH;
			} else if (typeof(a.match_height) == 'object' || typeof(a.match_height) == 'string') {
				h = $(a.match_height).height() + diffH;
			} else if (typeof(a.match_height) == 'function') {
				h = a.match_height() + diffH;
			} else if (a.height_to != null) {
				h = $(a.height_to).height() + $(a.height_to).offset().top - $aOn.offset().top - $aOn.sumPaddings();
			} else if (a.height) 
				h = a.height;

		}
		if (a.center){
			pos_attach = {left: ($(window).width()-$obj.width())/2, top: ($(window).height()-$obj.height())/2 + $(document).scrollTop()};
		}
		
		val = null;
		if (a.minHeight){
			if ((valtype = typeof(a.minHeight)) == 'number')
				val = a.minHeight
			else if (valtype == 'function')
				val = a.minHeight();
			else
				val = $(a.minHeight).height();
			if (val > 0 && val > h) {
				h = val;
			}
		}
		var dimensions = {};
		if (h) dimensions.height = h;
		if (w) dimensions.width = w;
		
		// maintenant que dimensions déterminées, tenir compte de param context.bulle si nécessaire
		if (a.context && (val = a.context.bulle)) {
			if(val.leftX || val.left)
				pos_attach.left -= ((w?w + $obj.outerWidth() - $obj.width():null) || $obj.outerWidth())*(val.leftX||0) + (val.left || 0);
			if (val.topX || val.top)
				pos_attach.top -= ((h?h+$obj.outerHeight()-$obj.height():null) || $obj.outerHeight())*(val.topX||0) + (val.top || 0);
			//alert(h + ' - ' + $obj.outerHeight() + ' - ' + $obj.height())
		}
		// finalement tenir compte de la contrainte si elle est spécifiée
		if (a.constrain) {
			var $constr = $(a.constrain);
			var coff = $constr.offset();
			pos_attach.left = Math.max(pos_attach.left, coff.left);
			pos_attach.top = Math.max(pos_attach.top, coff.top);
			var of = $obj.offset();
			if( (diff = (coff.top + $constr.outerHeight() - of.top - $obj.outerHeight()))  < 0) pos_attach.top += diff;
			if( (diff = (coff.left + $constr.outerWidth() - of.left - $obj.outerWidth()))  < 0) pos_attach.left += diff;
			
		}
		
		//$('#debug_text').append('<br/>-------- ' + $obj[0].nodeName + '#' + $obj.attr('id') + '.' + $obj.attr('className') + ' -><strong> top = ' + pos_attach.top + '; left = ' + pos_attach.left + '</strong>');
		if (a.animate)
			$obj.animate($.extend(pos_attach, dimensions), a.animate, a.animateFnct ||'easeOutElastic', function(){$obj.trigger('animationend')});
		else {
			$obj
				.css(pos_attach)
				.css(dimensions);
		}
			
	
	
	}
	
	$.fn.fixShadow = function(param){ // delay optional; default 1000ms
		var $this = this, s;
		
		setTimeout(function(){
					$this.each(function(){
						
						var par;
						/*
						if ($(this).data('shadow.dialog')){
							(par=$(this).parent()).next('.ui-widget-shadow')
								.height(par.outerHeight())
								.width(par.outerWidth())
								.css({	zIndex: par.css('z-index')-1})
								.css(par.offset());
*/				
						if ($(this).hasClass('ui-dialog-content')){
							show_shadow.call($(this).parent()[0])
						} else show_shadow.call(this);
										}
							)
										
							}, ((typeof(param) == 'object'?param.delai:param)|| 200))
		return this;
	}		
	$.fn.dialogShadow = function(shadowClass){
		
		if (!LK.IE || $.browser.version >= 9) return this
		return this.each(function(){
			var par = $(this).parent();
			par.addShadow(shadowClass);
			par.bind('drag',  function(ev, ui){
				if (ui == undefined) return;
				ui.helper.fixShadow(.01)
			})
			par.bind('resize', function(ev, ui){
				if (ui == undefined) return;
				ui.helper.fixShadow(.01)
			})
		})
	}
	$.fn.closeOn = function(event){
		return this.each(function(){
			var this_ = this;
			$('body').bind(event, function(){
				if ($(this_).is('.ui-dialog-content')){
						if ($(this_).dialog('isOpen'))
							$(this_).dialog('close')
				} else
					$(this_).hide();
		})
		})
	}
	
	
	// donner focus au bouton au rang donné dans la liste d'options du dialogue (ORDRE INVERSE D'ORDRE DE PRESENTATION)
	// commençant au rant 1
	$.fn.dialogButtonFocus = function(index){
		return $(this).each(function(){
			try{
				var $list_buttons
				var nb_buttons = ($list_buttons = $(this).parent().find('.ui-dialog-buttonpane > button')).length
				if (!nb_buttons) return;
				if (index == 'last')
					index = nb_buttons;
				else if (index == 'first')
					index = 1
				if (isNaN(index = parseInt(index))) return;
				if (index < 0)
					index = nb_buttons+index+1
				index = Math.max(Math.min(nb_buttons, index), 1)

				$list_buttons.eq(index-1)[0].focus();
			}
			catch(err){}
		})
	}
	$.fn.dialogToggle = function(mode){
		return $(this).each(function(){
			try {
				if (mode == 'open')
					$(this).dialog('open');
				else if (mode == 'close')
					$(this).dialog('close')
				else if ($(this).dialog('isOpen'))
					$(this).dialog('close')
				else
					$(this).dialog('open')
			}
			catch(err){}
		})
	}
	$.fn.dialogKeepDragPos = function(){
		return $(this).each(function(){
			try{
				$(this).parent().bind('dragstop', function(){
					$(this).find('.ui-dialog-content').dialog('option', 'position', [$(this).offset().left, $(this).offset().top])
				})
			}
			catch(err){
			}
		})
	}
	$.fn.select_div= function(classe){
						return this.each(function(){
									$(this).children().hide().filter('.' + classe).show();
											})
	}
							   
	$.fn.exec_normalized = function(){
		var args = arguments;
		return this.each(function(){
					var a = $(this).LKdata();
					if (!a.normalize || !a.normalize[args[0]]) return true;
					
					var fnct = a.normalize[args[0]];
					fnct.apply($(this), $.makeArray(args).slice(1))
								  });
	}
	$.fn.mask = function(className){
		return this.each(function(){
								  var data = $(this).LKdata();
								  var a;
								  if (!data.$mask)
								  	data.$mask = $('<div>')
										.addClass(className)
										.css({display: 'none'})
										.appendTo('body')
										.attach('store', {attach:$(this), match_dim:$(this), match_dim_mode: 'outer'})
								  a = $(this).css('z-index');
								  if (isNaN(a))
										a = 9999;
								 else 
								 	a = a + 1;
								  data.$mask
								  	.css({zIndex: a})
								  	.show();
								  })
	}
	$.fn.unMask = function(){
		return this.each(function(){
								  var data = $(this).LKdata();
								  if (data.$mask) data.$mask.hide();
								  })
	}

	$.fn.fld_to_obj = function(id){
		var to_ret = {}
		this.each(function(){
			$('input', this).each(function(){
				var type = $(this).attr('type')
				var fldname = $(this).attr('data-' + id)
				if (fldname == undefined){
					return
				}
				switch(type){
					case 'text':
						to_ret[fldname] = $(this).val()
						break;
					case 'checkbox':
						to_ret[fldname] = ($(this).is(':checked')?1:0)
				}
			})
		})
		return to_ret
	}
	$.fn.buttons = function(dial){
		var buttons, widget
		if (!(widget = $(this).dialog('widget')).length){
			return widget
		}
		buttons = widget.find('.ui-dialog-buttonpane').find('button')
		var ind
		if ($.isArray(dial)){
			ind = dial
		} else if (arguments.length) {
			ind = arguments
		} else {
			return buttons
		}
		var to_ret = $([])
		$.each(ind, function(ind, val){
			buttons.eq(val).addTo(to_ret)
		})
		return to_ret



	}
	
	$.fn.disable = function(){
		return $(this).each(function(){
			if ($(this).is('.ui-button')){
				$(this).button('disable')
				return
			}
			$(this).attr('disabled', 'disabled')
		})
	}

	$.fn.enable = function(){
		return $(this).each(function(){
			if ($(this).is('.ui-button')){
				$(this).button('enable')
				return
			}
			$(this).removeAttr('disabled')
		})
	}
	
	$.fn.decorate_buttons = function(icons){
		return $(this).each(function(){
			var buttons = $(this).buttons()
			$.each(icons, function(ind, val){
				if (isNaN(val) && val != undefined ){
					buttons.eq(ind).button('option', 'icons', {primary: 'ui-icon-' + val})
				} 
			})
		})
	}

	$.fn.add_err_msg = function(tag, msg, separ){
		separ = separ || '; '
		return $(this).each(function(){
			var current_msg = $(this).LKdata(tag) || ''
			if (current_msg != ''){
				current_msg += separ
			}
			$(this).LKdata(tag, current_msg + msg)
		})
	}
	$.fn.clr_err_msg = function(tag){
		return this.each(function(){
			var a
			if ((a = $(this).LKdata())[tag]){
				delete(a[tag])
			}
		})
	}
	$.fn.add_tag = function(tag, html, options){
		options = options || {}
		return this.each(function(){

			$(this).append($('<' + tag + '>', options).html(html))
		})
	}
	$.fn.add_line = function(data){
		return $(this).each(function(){
			var tb = $(this)
			var tr
			tb.append(tr = $('<tr>'))
			$.each(data, function(ind, val){
				if ($.isArray(val)){
					tr.append($('<td>', val[1]).text(val[0]))
				} else{
					tr.append($('<td>').text(val))
				}
			})
		})
	}
	
	$.fn.check = function(cond){
		if ($.isFunction(cond)){
				if (cond()){
					return $(this).attr('checked','checked')
				} else {
					return $(this).removeAttr('checked')
				}
				
		} else if (cond != undefined){
			if (cond){
				return $(this).attr('checked','checked')
			} else {
				return $(this).removeAttr('checked')
			}
		}
		return $(this).attr('checked', 'checked').button('refresh')
	}
	$.fn.uncheck = function(){
		return $(this).removeAttr('checked').button('refresh')
	}
	$.fn.ident = function(){
		var t = $(this).first()
		return t[0].nodeName + '#' + t.attr('id') + '.' + t.attr('className')
	}
	$.fn.egale = function(obj){
		var unique = $.unique(this)
		return (unique.length == $.unique(unique.add(obj)).length )
	}

	$.fn.$sort = function(fn){
		if ($(this).length <= 1){
			return $(this)
		}
		var list = []
		$(this).each(function(){
			list.push(this)
		})
		list.sort(fn)
		var insertion_point = $('<div>').insertAfter($(this).last())
		$.each(list, function(ind, val){
			insertion_point.append(val)
		})
		$(this).first().unwrap()
		return $(this)
	}
	$.fn.alternate = function(cl){
		var odd = false
		return $(this).each(function(){
			if (odd){
				$(this).addClass(cl)
			} else{
				$(this).removeClass(cl)
			}
			odd = !odd
		})
	}
	$.fn.disableSelection = function(){
		return $(this).each(function() {
                    this.onselectstart = function() { return false; };
                    this.unselectable = "on";
                    $(this).css('-moz-user-select', 'none');
            })
	}
	$.fn.enableSelection = function(){
		return $(this).each(function() {
                    this.onselectstart = function() { };
                    this.unselectable = "off";
                    $(this).css('-moz-user-select', 'auto');
            })
	}
	$.fn.includes = function(obj){
		return ($(this).length != $(this).not(obj).length)
	}
	$.fn.my_val = function(){
		var a
		if ((a = $(this).customdata('val')) && $(this).LKdata()[a]){
			return $(this).LKdata()[a]()
		} else{
			return $(this).val()
		}
	}
	$.fn.absorbe_separateurs = function(){
		return $(this).each(function(){
			var sep
			if ((sep = $(this).prev('.separ-haut')).length){
				$(this).LKdata('sep_haut', sep.remove())
			}
			if ((sep = $(this).next('.separ-bas')).length){
				$(this).LKdata('sep_bas', sep.remove())
			}
		})
	}
	$.fn.ejecte_separateurs = function(){
		return $(this).each(function(){
			var sep
			if ((sep = $(this).LKdata('sep_haut'))){
				sep.insertBefore(this)
				if (sep.is('.cache_premier') && $(this).prevAll('.struct_elem').length == 0){
					sep.hide()
				} else{
					sep.show()
				}
			}
			if ((sep = $(this).LKdata('sep_bas'))){
				sep.insertAfter(this)
				if (sep.is('.cache_dernier') && $(this).nextAll('.struct_elem').length == 0){
					sep.hide()
				} else{
					sep.show()
				}
			}
		})
	}
	$.fn.my_more = function(params){
		if (params === false){
			return $(this).each(function(){
				var a
				if ($(this).is('a.continuer')){
					a = $(this)
				} else{
					a = $(this).find('a.continuer')
				}
				if (a.length){
					a.closest('div.struct_elem').find('div.continuer_content')
						.slideDown(function(){
							$(this).children(':first').unwrap()
						})
					a.remove()
				}
			})

		}
		params = $.extend({limite:250, marqueur: 'continue...', limite_cache: 100}, (params || {}))
		if ($(this).length != 1){
			params.verbose = false
		}
		return $(this).each(function(){
			if (!$(this).is('div.text_container')){
				return
			}
			var longueur_debut = 0, longueur_contenu
			if ((longueur_contenu = $(this).text().length) <= params.limit + params.limite_cache){
				if(params.verbose){
					LK.alert(LK.msg__.texte_non_abrege)
				}
				return
			}
			var p_list = $(this).find('p'), $text_container = $(this)
			
			p_list.each(function(){
				var a
				longueur_debut += $(this).text().length
				if (longueur_debut >= params.limite && longueur_debut + params.limite_cache < longueur_contenu){
					$(this).after(a = $('<a>', {href:'#', 'class':'continuer'}).text(params.marqueur))
					a.nextAll().wrapAll($('<div>', {'class':'continuer_content'}))
					
					a.parentsUntil('div.text_container').each(function(){
						$(this).nextAll().wrapAll($('<div>', {'class':'continuer_content'}))
					})
					a.click(function(){
						$(this).my_more(false)
					})
					if (params.verbose){
						LK.alert(YLS(LK.msg__.texte_abrege_apres, {nb: longueur_debut}))
					}
					return false
				}
			})
return
			$(this).children().each(function(){
				var a
				longueur_debut += $(this).text().length
				if (longueur_debut > params.limite){
					if (longueur_debut + params.limite_cache < longueur_contenu){
						$(this).after(a = $('<a>', {href:'#', 'class':'continuer'}).text(params.marqueur))
						a.nextAll().wrapAll($('<div>', {'class':'continuer_content'}))
						a.click(function(){
							$(this).my_more(false)
						})
						if (params.verbose){
							LK.alert(YLS(LK.msg__.texte_abrege_apres, {nb: longueur_debut}))
						}
					}
					return false
				}
			})
		})
	}
	$.fn.mark_odd = function(even_lines, even_col){
		return this.each(function(){
				$(this).find('tr:' + (even_lines?'even':'odd')).addClass('odd')
				$(this).find('tr').each(function(){
					$(this).find('td:' + (even_col?'even':'odd')).addClass('odd')
				})
			}
			)
	}
	$.fn.vals = function(){
		var vals = {}
		$(this).each(function(){
			var name = $(this).attr('name') || $(this).attr('id')
			if (name){
				if ($(this).is('[type="checkbox"]')){
					vals[name] = $(this).is(':checked')?1:0
				} else if ($(this).is('[type="radio"]:checked') || !$(this).is('[type="radio"]')){
					vals[name] = $(this).val()
				}
				
			}
		})
		return vals
	}
	$.fn.set_vals = function(vals){
		return $(this).each(function(){
			var name = $(this).attr('name') || $(this).attr('id')
			if (vals[name] != undefined){
				var val = vals[name]
				if ($(this).is('[type="checkbox"]')){
					if (val == 1 || val == '1'){
						$(this).check()
					} else {
						$(this).uncheck()
					}
				} else if ($(this).is('[type="radio"]')){
					if ($(this).val() == val){
						$(this).check()
					} 
				} else {
					$(this).val(val)
				}
			}
		})
	}
	$.fn.setPhoto = function(id, dim){
		var w, h
		id = parseInt(id)
		if (isNaN(id)){
			return $(this)
		}
		if (dim == undefined){
			w = parseInt($(this).attr('width'))
			h = parseInt($(this).attr('height'))
			if (!isNaN(w) && !isNaN(h)){
				dim = w + 'x' * h
			} else if (!isNaN(w)){
				dim = w + 'x' + Math.round(1.1*w)
			} else if (!isNaN(h)){
				dim = Math.round(h/1.1) + 'x' + h
			} else {
				dim = ''
			}
		} else if (/^\d+$/.test(dim)) {
			dim = dim + 'x' + Math.round(parseInt(dim)*1.1)
		}
		return $(this).attr('src', './PHP/get_photo?id=' + id + '&type=' + dim)
		

	}
	$.fn.append_clic_ferme = function(){
		return $(this).append($('<div>',{css:{marginTop:10,textAlign:'center',color:'#666',clear:'both'}, 'class':'field_info'}).text(LK.msg__.clic_ferme))
	}
/***
 * Pacth for dialog-fix ckeditor problem [ by ticket #4727 ]
 * 	http://dev.jqueryui.com/ticket/4727
 */

$.extend($.ui.dialog.overlay, { create: function(dialog){
	if (this.instances.length === 0) {
		// prevent use of anchors and inputs
		// we use a setTimeout in case the overlay is created from an
		// event that we're going to be cancelling (see #2804)
		setTimeout(function() {
			// handle $(el).dialog().dialog('close') (see #4065)
			if ($.ui.dialog.overlay.instances.length) {
				$(document).bind($.ui.dialog.overlay.events, function(event) {
					var parentDialog = $(event.target).parents('.ui-dialog');
					if (parentDialog.length > 0) {
						var parentDialogZIndex = parentDialog.css('zIndex') || 0;
						return parentDialogZIndex > $.ui.dialog.overlay.maxZ;
					}
					
					var aboveOverlay = false;
					$(event.target).parents().each(function() {
						var currentZ = $(this).css('zIndex') || 0;
						if (currentZ > $.ui.dialog.overlay.maxZ) {
							aboveOverlay = true;
							return;
						}
					});
					
					return aboveOverlay;
				});
			}
		}, 1);
		
		// allow closing by pressing the escape key
		$(document).bind('keydown.dialog-overlay', function(event) {
			(dialog.options.closeOnEscape && event.keyCode
					&& event.keyCode == $.ui.keyCode.ESCAPE && dialog.close(event));
		});
			
		// handle window resize
		$(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize);
	}
	
	var $el = $('<div></div>').appendTo(document.body)
		.addClass('ui-widget-overlay').css({
		width: this.width(),
		height: this.height()
	});
	
	(dialog.options.stackfix && $.fn.stackfix && $el.stackfix());
	
	this.instances.push($el);
	return $el;
}});
	
			  })(jQuery);



