/**
 * POPUP CENTREE SUR L'ECRAN
 *
 * @UrlPage				L'adresse de la page
 * @LargeurPopup		La largeur du popup
 * @HauteurPopup		La hauteur du popup
 **************************************************************/
function Popup(UrlPage, LargeurPopup, HauteurPopup) {
	LargeurEcran = window.screen.availWidth;
	HauteurEcran = window.screen.availHeight;
	
	PositionX = parseInt(LargeurEcran / 2) - parseInt(LargeurPopup / 2);
	PositionY = parseInt(HauteurEcran / 2) - parseInt(HauteurPopup / 2);
	
	window.open(UrlPage, "lePopup", "scrollbars=yes,resizable=yes,width="+LargeurPopup+",height="+HauteurPopup+",top="+PositionY+",left="+PositionX);
}

function ajaxListeForm(Url, listeCible, messageAttente)
{
	// console.log(listeCible);
	var imageSmallIndic = '<img src="medias/images/communes/small_indic.gif" alt="" id="imgAjax_' + listeCible + '" />';
	$(listeCible).insert({after: imageSmallIndic});
	$(listeCible).options.length = 0;
	$(listeCible).options[0] = new Option("Recherche en cours", "");
	new Ajax.Request(Url, {	method: 'get',
							onSuccess: function(transport) {
									chargerListe(listeCible, eval(transport.responseText))
								} 
							});
}

function chargerListe(listeCible, optionsListe) 
{
	nbOptions 	= optionsListe.length;
	avecOptions	= false;
	for ( i=0; i<nbOptions; i++ ) {
		avecOptions = true;
		if (i == 0) {
			$(listeCible).options[i] = new Option("Indifférent", optionsListe[i].valeur);
		} else {
			$(listeCible).options[i] = new Option(optionsListe[i].intitule, optionsListe[i].valeur);
		}
		
	}
	
	if ( avecOptions == false ) {
		$(listeCible).options[0] = new Option("Indifférent", "");
	}
		
	if ( $('imgAjax_' + listeCible) != null ) {
		$('imgAjax_' + listeCible).remove();
	}
}

function razListe(listeCible, messageListe)
{
	$(listeCible).options.length = 0;
	$(listeCible).options[0] = new Option(messageListe, "");
	$('btonValider').value = "Recherche";
}

function debugJS(varToDebug)
{
	if ( window.console ) {
		console.log(varToDebug);
	}
}