function ajaxLoad(url, idDest, callback, scriptID) {

	document.getElementById(idDest).innerHTML = '<div style="position:relative;width:100%;"><div id="loading" style="position:absolute;top:100px;border:1px solid black;background:white;padding:16px;">Chargement en cours...</div></div>';
	if (document.getElementById('ajaxMain') != null)
		document.getElementById('loading').style.left=(document.getElementById('ajaxMain').clientWidth-document.getElementById('loading').clientWidth)/2+'px';

	var obj = null; 
	if(window.XMLHttpRequest)
		obj = new XMLHttpRequest();
	else if(window.ActiveXObject)
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return;
			
	obj.open("GET", url, true);

	obj.onreadystatechange = function() {
		if(obj.readyState == 4) {
			var result = obj.responseText;
			document.getElementById(idDest).innerHTML = result;
			if (scriptID == null) scriptID = 'scriptInAjax';
			scriptInAjax = document.getElementById(scriptID);
			if (scriptInAjax != null)
				if (scriptInAjax.src==null || scriptInAjax.src=="" || (!scriptInAjax.src)) {
					eval(scriptInAjax.innerHTML);
				}
				if (callback) callback();
		}
	}

	obj.send(null);
	
}

function ajaxGet(url, callback) {

	document.body.style.cursor = 'wait';

	var obj = null; 
	if(window.XMLHttpRequest)
		obj = new XMLHttpRequest();
	else if(window.ActiveXObject)
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return;
			
	obj.open("GET", url, true);

	obj.onreadystatechange = function() {
		if(obj.readyState == 4) {
			var result = obj.responseText;
			document.body.style.cursor = 'default';
			callback(result);
		}
	}

	obj.send(null);
	
}

function setLoading(elt, text, keepSize) {
	
	if (keepSize == undefined) keepSize = false;
	
	if (text == undefined || text == null) text = "Veuillez patienter, chargement en cours.";
	var oldH = elt.height();var oldW = elt.width();

	elt.html('<span class="loading"><img src="img/ajax-loader-FFFFFF.gif" id="ajaxload">' + text + "</span>");
	if (keepSize) {
		elt.attr('oldheight', elt.css('height'));
		elt.attr('oldwidth', elt.css('width'));
		eltLoading = elt.find('span.loading');
		eltLoading.css('position', 'relative').css('top', (oldH-eltLoading.height())/2);
		if (elt.css('text-align') == 'left' || elt.css('text-align') == 'start') {
			eltLoading.css('left', (oldW-eltLoading.width())/2);
		}
		if (elt.css('text-align') == 'right') {
			eltLoading.css('left', -(oldW-eltLoading.width())/2);
		}
		elt.width(oldW);
		elt.height(oldH);
	}
}
function doneLoading(elt) {
	elt.css('width', elt.attr('oldwidth')).removeAttr('oldwidth');
	elt.css('height', elt.attr('oldheight')).removeAttr('oldheight');
	elt.find('span.loading').fadeOut();
}
function addClose(elt) {
	elt.prepend('<a href="#" onclick="$(this).parent().remove();return false;"><img src="img/close.png" style="float:right;"></a>');
}

function showPopup(url, css) {
	removePopup();
	if (css == undefined) css = 'left:0px;top:0px;';
	$('body').prepend('<div class="popupholder" style="position:absolute;"><div class="popup" style="'+css+'"></div></div>');
	var elt = $('.popupholder').children('.popup');
	setLoading(elt);
	elt.load(url, {}, function() {
	});
}
function showPopupIn(container, url, width) {
	removePopup();
	var css = 'left:0px;top:0px;';
	if (width != undefined) css += 'width:'+width+'px;';
	container.prepend('<div class="popupholder"><div class="popup" style="'+css+'"></div></div>');
	var elt = container.children('.popupholder').children('.popup');
	setLoading(elt);
	elt.load(url, {}, function() {
	});
}
function removePopup() {
	$('div.popupholder').remove();
}

