// JavaScript Document
// Priam's utilitaires
var imgLoader = $('<img class="ajaxloader" src="images/ajax-loader.gif" title="Veuillez patientez...">');
$(document).ready(function(){$('body').append(imgLoader);});
$(imgLoader).hide();
function PicLoad(classCSS)
{
	out = "<img ";
	if(!classCSS)
		classCSS = "ajaxloader";
		
	out += "class="+classCSS+" ";
	out += "src='images/ajax-loader.gif' title='Veuillez patientez...' />";
	return out;
}

var nbcall = 0;
function getFormData(formId)
{
	var res = {};
	
	// INPUTS
	var inps =  $('#'+formId).find(':input');
	//alert(inps.length);
	inps.each(function(i)
	{
		//alert(this.name+' = '+this.value);
		isCheckable = (this.type=='checkbox' || this.type=='radio');
		//if(!this.name) this.name = 'inputName'+(nbcall++);
		if(this.name)
			if(!isCheckable || (isCheckable && this.checked))
				eval("res."+this.name+" = '"+this.value+"';");
				//eval("res."+this.name)= this.value;
	});
	
	// ONLY ONE FCK EDITOR WITH NAME IN INPUT FCKeditorName
	if(res.FCKeditorName)
	{
		//alert(res.FCKeditorName);
		var oEditor = FCKeditorAPI.GetInstance(res.FCKeditorName) ;
		if(oEditor)
			res.texte = oEditor.GetHTML();
	}
	return res;
}

function callAndFill(sel,classe,methode,params,statique)
{	
	//alert(sel);
	//alert(typeof(params));
	if(typeof(params)!='object')
		params = {};
	params.classe = classe;
	params.methode = methode;


	// defaut behavior
	if(!statique)
		statique = false;


	// STATIC
	if(statique)
		$.post("ajax.php",params, function(data){$(sel).html(data);});
	else // DYNAMIC 
		// hide/show 
		///*
		$(sel).hide("normal",function(){
			$(sel).empty();
			$(sel).append($(imgLoader).show());
			$(sel).show("normal",function(){
					$.post("ajax.php",params, function(data){	
						$(sel).hide("normal", function(){
							$(sel).html(data);
							$(sel).show("normal"); 
						});
					}, "html");
			}); 
		});
		//*/
		// fadeIn/fadeOut 
		/*
		$(sel).fadeOut("normal",function(){
			$(sel).empty();
			$(sel).append($(imgLoader).fadeIn());
			$(sel).fadeIn("normal",function(){
					$.post("ajax.php",params, function(data){	
						$(sel).fadeOut("normal", function(){
							$(sel).html(data);
							$(sel).fadeIn("normal"); 
						});
					}, "html");
			}); 
		});
		*/

}




