/** lt_up : fonction de base du systeme. Permet d'actualiser intelligemment un elt de la page *  * fonction jajax <1.1 stable 18/04/07> * author Pascal Menut <pascal@petitegraine.com> * * params : *  idElt : identifiant html de l'element qui subi la requete ajax *  jdata : un blabla de commande par ex : 'package: sandbox, composant: helloworld' va appeler le script situe dans l'arborescence dans /packages/sandbox/jax/helloworld.php *  lanceOnComplete : TODO ameliorer le passage de fonction. fonction(s) executer lors de l'evenement 'onComplete' *  highlight : true/false , true par defaut *  reloadbehaviours true/false , true par defaut */
function lt_up(idElt, jdata, lanceOnComplete, highlight, reloadbehaviours) {
	if(highlight == null) {
		highlight = false;
	}
	if(reloadbehaviours == null) {
		reloadbehaviours = true;
	}
	
	// recuperation des options.
	// pour compatibilite. A virer en temps opportun, ou a remplacer par un pattern, dans le genre des templates exogen.
	if((lanceOnComplete == null) || (lanceOnComplete == 'noeffect') || (lanceOnComplete == 'APPEAR') || (lanceOnComplete == 'GROW')) {
		lanceOnComplete = '';
	}
	if(reloadbehaviours == true) {
		lanceOnComplete += "; Behaviour.apply()";
	}
	if(highlight == true) {
		lanceOnComplete += "; new Effect.Highlight(idElt, { duration: 0.1 } )";
	}
	new Ajax.Updater(idElt, '?io=get&elt=' + encodeURIComponent(idElt) + '&jdata=' + encodeURIComponent(jdata), {method:'get', evalScripts:true, asynchronous: true, onComplete: function (request) { eval(lanceOnComplete); }});
}
function lt_upmodal(jdata, lanceOnComplete, hightlight, reloadbehaviours) {	if(highlight == null) {		highlight = false;	}	if(reloadbehaviours == null) {		reloadbehaviours = false;	}		Lightview.show({		href: '?io=get&elt=modalbox&jdata=' + encodeURIComponent(jdata),		rel: 'ajax',		options: {			autosize: true,			topclose: true,			ajax: {				evalScripts: true,        		onComplete: function(){								}			}		}	});}function lt_clear(idElt, htmltag) {	if(htmltag == null) {		htmltag = '';	}	$(idElt).innerHTML = htmltag;}
function lt_autocompletion(idElt, jdata) {

	lt_up(idElt, jdata);
}
function lt_download(file, type) {
	//startLoading('xset', 'chargement ...');
	top.frames['dl'].document.location.href = '?io=download&elt=set&file=' + file + '&type=' + type;
	// + '&jdata=' + encodeURIComponent(jdata), {method:'post', evalScripts:true, asynchronous: true, onComplete: function (request) {  }});
}
function lt_set(jdata, inhibeStopLoading, inhibeStartLoading, idElt) {
	if(idElt != null) {
		// a la charge du d�veloppeur de donner un idElt qui existe.
		// TODO faire une v�rif, ou mieux : faire un addChild si jamais..
		idxElt = 'xset';
	}
	else {
		idElt = 'set';
		idxElt = 'xset';
		 // par defaut on active la div xset
	}
	if(inhibeStartLoading != null && inhibeStartLoading != true && inhibeStartLoading != 'true') {
		startLoading(idxElt, 'chargement ...');
	}
	
	if(inhibeStopLoading != null && inhibeStopLoading != true && inhibeStopLoading != 'true') {
		new Ajax.Updater(idElt, '?io=set&elt=' + idElt + '&jdata=' + encodeURIComponent(jdata), {method:'get', evalScripts:true, asynchronous: true, onComplete: function (request) { stopLoading(idxElt); }});
	}
	else {
		// le stopLoading est a la charge du script.
		new Ajax.Updater(idElt, '?io=set&elt=' + idElt + '&jdata=' + encodeURIComponent(jdata), {method:'post', evalScripts:true, asynchronous: true});
	}
}

function lt_notify(jdata, idElt) {
	if(idElt != null) {
		
	}
	else {
		idElt = 'listener';
	}
	new Ajax.Updater(idElt, '?io=set&elt=' + idElt + '&jdata=' + encodeURIComponent(jdata), {method:'get', evalScripts:true, asynchronous: true});
}
function lt_post(idElt, jdata, form) {		var lanceOnComplete = "Behaviour.apply(); new Effect.Highlight(idElt, { duration: 0.1 } )";		new Ajax.Updater(idElt, '?io=get&elt=' + encodeURIComponent(idElt) + '&jdata=' + encodeURIComponent(jdata), {			method:'post', 			parameters: Form.serialize(form),			evalScripts:true, 			asynchronous: true, 			onComplete: function (request) { eval(lanceOnComplete); }	});	return false;
	/* var ajax = new Ajax.Request('index.php', {
	 		 method: 'post', 
	 		 parameters: 'io=get&elt=' + encodeURIComponent(idElt) + '&jdata=' + encodeURIComponent(jdata) + '&'+Form.serialize(form),
	 		 onSuccess: function() { new Effect.Highlight(idElt, { duration: 0.4 } ) },
	 		 onFailure: function() { alert('Erreur ! Données non transmises'); }
	 });
	 */
}
function highlight(idElt, delai) {
	if(delai == null) {
		delai = 0;
	}
	new Effect.Parallel(
				 [ new Effect.Opacity(idElt, 
								{ sync: true, to: 1, from: 1 } ) 
				 ],
				 { 	duration: delai, 
					afterFinish: function(effect) { 						
						new Effect.Highlight(idElt, { duration: 0.4 } )
					}
				 }
				);
}

function lt_minimize(idElt) {
	if(document.getElementById('max_' + idElt).style.display != 'none') {
		if(document.all) {
			document.getElementById('content_' + idElt).style.display = 'none';
		}
		else {
			new Effect.Shrink('content_' + idElt, {duration: 0.25});
		}
		//new Effect.BlindUp('content_' + idElt, {duration: 0.25});
		//document.getElementById.style.display = 'none';
		document.getElementById('max_' + idElt).style.display = 'none';
		document.getElementById('min_' + idElt).style.display = 'block';
		document.getElementById(idElt).className = idElt + '_min';
		new Effect.ShakeUp(idElt);
		
		if(document.getElementById('help')) {
			new Effect.Appear('help', {duration: 0.1});
		}
	}
}

function lt_maximize(idElt, cdata) {
	if(cdata != null) {
		lt_up(idElt, cdata, '');
	}
	else {
		
		// ces lignes sont spécifiques
		document.getElementById('bloc2').className = 'nonestompe';
		
		new Effect.Appear('content_' + idElt, {duration: 0.5});
		document.getElementById('max_' + idElt).style.display = 'block';
		document.getElementById('min_' + idElt).style.display = 'none';
		document.getElementById(idElt).className = idElt + '_max';
		
		if(document.getElementById('help')) {
			new Effect.Fade('help', {duration: 0.1});
		}
	}
}


function stopLoading(idElt, msg) {
	if(msg == null) {
		msg = '';
	}
	switch(idElt) {
		case 'xset':
			
			new Effect.Fade('xset', {	duration: 0.4, 
										delay: 0.5,
										beforeStart: function(effect) {
														new Effect.Morph('cset', {style: 'width: 200px; height: auto;', duration: 0.3, beforeStart: function() { $('xset-loader').style.visibility = 'hidden'; $('set-label').innerHTML = 'Termin&eacute;'; $('set').innerHTML = msg; }});
													},
										afterFinish: function(effect) { 
														$('xset-loader').style.visibility = 'visible';
														$('set-label').innerHTML = 'Patientez...';
													 }
								});
			
			
			break;
		default:
			// arret de l'affichage du petit bitoniau
			$(idElt).src = 'themes/images/toolDown.gif';
			break;
	}
}function startWizzard(urldest, msg, title, width, cancelable, idElt) {		if(msg == null) { msg = '';	}	if(idElt == null) { idElt = 'modalbox';	}	if(cancelable == null) { cancelable = true;	}		switch(idElt) {		case 'modalbox':			if(cancelable) {				if(width == null) {					Modalbox.show(urldest, {title: title, afterLoad: function(){ Modalbox.activate(); } });				}				else {					Modalbox.show(urldest, {title: title, height: 700, width: width, afterLoad: function(){ Modalbox.activate(); } });				}			}			else {				Modalbox.show(urldest, {title: title});			}			Modalbox.deactivate();			break;		default:			break;	}}function continueWizzard(urldest, cancelable, idElt) {		if(idElt == null) { idElt = 'modalbox';	}	if(cancelable == null) { cancelable = true;	}		switch(idElt) {		case 'modalbox':			if(cancelable) {				Modalbox.show(urldest, {afterLoad: function(){ Modalbox.activate(); } });			}			else {				Modalbox.show(urldest, {});			}			Modalbox.deactivate();			break;		default:			break;	}}function stopWizzard(msg, title, idElt) {	if(msg == null) {		msg = '';	}	if(idElt == null) {		idElt = 'modalbox';	}	switch(idElt) {		case 'modalbox':			if(msg == '') {				Modalbox.hide();				break;			}			else {				var htmlmsg = Builder.build('<div style="text-align: center;">' + msg + '</div>');				Modalbox.show(htmlmsg, {title: title, overlayClose: false});				Modalbox.activate();			}			break;		default:			break;	}}
function startLoading(idElt, msg) {	if(msg == null) {		msg = '';	}	switch(idElt) {		case 'xset':			$('set').innerHTML = msg;			new Effect.Appear('xset', {duration: 0.1});			break;		default:			$(idElt).src = 'themes/images/toolLoader.gif';			break;	}}
function suspendLoading(idElt, msg) {	if(msg == null) {		msg = '';	}	switch(idElt) {		case 'xset':			$('set-label').innerHTML = 'Termin&eacute;';			$('xset-loader').style.visibility = 'hidden';			$('set').innerHTML = msg + '<p style="text-align: center; padding-top: 10px;"><a style="border: 1px solid gray; padding: 2px 10px;" href="#" onclick="stopLoading(\'' + idElt + '\'); return false;" title="fermer">Ok</a></p>';			break;		default:			stopLoading(idElt);			xalert(msg);			break;	}}
function accordeon(el, racineAccordeon) {
    if (el.id == racineAccordeon + '-visible') {
        return false;
    }
    eltVisible = $(racineAccordeon + '-visible');
    if (eltVisible) {
    	//startLoading(el.parentNode.id+'-state');
        var eldown = el.parentNode.id+'-body';
        var elup = eltVisible.parentNode.id+'-body';
        
    	//new Ajax.Updater(eldown, '?io=get&elt=' + el.parentNode.id, { asynchronous:true, evalScripts:true, onComplete: function () {
	        new Effect.Parallel(
	        [
	            new Effect.BlindUp(elup),
	            new Effect.BlindDown(eldown)
	        ], {
	            duration: 0.3
	        });
	    	//stopLoading(el.parentNode.id+'-state');
    		//document.getElementById(eltVisible.parentNode.id+'-state').src = 'themes/images/toolUp.gif';
    		//eltVisible.id = '';
    	//}});
    	// el.id = 'acc-visible';*/
    	 el.id = racineAccordeon + '-visible';
    	 eltVisible.id = '';
    }
    else {
    	var eldown = el.parentNode.id+'-body';
    	new Effect.BlindDown(eldown, {duration: 0.3});
        el.id = racineAccordeon + '-visible';
    }
    
    
}

function cocherdecocherTout(classename, cocher) {	$A(document.getElementsByClassName(classename)).each(function(elt) {		if(elt.disabled) {				}		else {			elt.checked = cocher;		}	});}
function addEvent(elm, evType, fn, useCapture) {
    elm["on"+evType]=fn;return;
}
function xalert(message) {	return alert(message);}
function xconfirm(message, action) {	if(confirm(message)) {		eval(action);	}}
function xnotice(message) {	// affichage d'une notice. Et vivent les zeffets scriptaculous	$('notice').innerHTML = message;
	new Effect.Parallel(		[ new Effect.Appear('xnotice', {duration: 0.5}  ),		  new Effect.Pulsate('notice', {duration: 2, pulses: 2}) ],		  { duration: 2,	      	afterFinish: function(effect) { new Effect.Fade('xnotice', {duration: 0.5}); }	      }	  );}
/** * effets**/
function shakeitbaby(idelt) {	$(idelt).shake();}
/**  * chargement de l'arrosoir. **/
function arrShowLoginBox() {	$('arrosoirbox').className = 'arrosoirbox_positionDessus';	lt_up('arrosoir-loginbox', 'package: arrosoir, composant: loginbox', 'new Effect.Appear(\'arrosoir-loginbox\', {duration: 0.1});');}
/** * fonctions de debug*/
function swappeDiv(iddiv) {	$(iddiv).toggle();}/** * Pour IE : fix PNG 24 (source : joomla) * @param element * @return */function fixPNG(element) {	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {		var src;		if (element.tagName == 'IMG') {			if (/\.png$/.test(element.src)) {				src = element.src;				element.src = 'themes/common/images/spacer.gif';			}		}		else {			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);			if (src) {				src = src[1];				element.runtimeStyle.backgroundImage = 'none';			}		}		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "')";	}}

