//AJAX
var fd_httpReponse = '';

function	fd_ajax_exec(nameScript,data,nameFunction)
{
	var xhr_object	= null;

	if(window.XMLHttpRequest)		// Firefox 
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) 	// Internet Explorer 
	      xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	if (xhr_object != null)
	{
		xhr_object.open("POST", nameScript, true);
					
		xhr_object.onreadystatechange = function()
		{ 
			if(xhr_object.readyState == 4)
			{		
				httpReponse = xhr_object.responseText;
				if(nameFunction != '') eval(nameFunction +';')
			}
		}
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.send(data);
	}
	else
		nameFunction('noAjax');
}

function fd_actionDOM(){
	eval(unescape(httpReponse));
}

function fd_fillObj(obj,val)
{
	//alert(unescape(val));
	document.getElementById(obj).innerHTML = unescape(val);
}

function fd_fillObjDeb(obj,val)
{
	document.getElementById(obj).innerHTML = unescape(val)+document.getElementById(obj).innerHTML;
}

function fd_ajax(type,critere)
{
	//alert(fd_PATH);
	fd_ajax_exec(fd_PATH+'librairie/class.fondation/lib/fdGstAjax.php?fd_path='+fd_PATH,'type='+type+'&'+critere,'fd_actionDOM()');
}

//apparition temporisée
var fd_T = '';
function fd_showObj(nomObj, duration)
{
	top.document.getElementById(nomObj).style.display='block';
	if(duration!='inf')
	{
		clearTimeout(fd_T);
		var href = top.document.getElementById(nomObj).getElementsByTagName('A');
		for (var i = 0; i < href.length; i++)
		{
			href[i].onmouseover= function (){ showObj(nomObj,duration); }
		}
		fd_T = setTimeout('fd_hideObj("'+nomObj+'");',duration);
	}
}
function fd_hideObj(nomObj)
{
	top.document.getElementById(nomObj).style.display = 'none';
}

/**
 * _$
 * alias de document.getElementById
 * underscore pour éviter les conflits avec 
 * d'autres librairies js
 */

function _$(id){
	return document.getElementById(id);
}


/**
 * applyClass
 * applique une classe a un element du DOM
 * @param	string	oElement	element
 * @param	string	sCSSClass	nom de la classe
 */

function applyClass(oElement,sCSSClass){  
	oElement.className = sCSSClass; 
}


/**Function de gestion ajax du sort */

function gstDatagridAjaxSort(vals)
{
	fd_ajax('sortDataGrid','page='+vals.page+'&order='+vals.sort[0].field+'&direction='+vals.sort[0].direction+'&prefix='+vals.data);
	return false;
}
/**Function de gestion ajax du pagger */
function gstPager(numPage,prefix)
{
	fd_ajax('gstPager','page='+numPage+'&prefix='+prefix);
}
