/**
 * @author Didier
 */

//
// fonction loading
function displayLoading(element) {
	while(element.hasChildNodes()) {
		element.removeChild(element.lastChild);
	}
	var image = document.createElement("img");
	image.setAttribute("src","images/loading.gif");
	image.setAttribute("alt","loading...");
	element.appendChild(image);
}
//
function requeteAffichage(idAffiche) {
	//alert(this);
	var pars = "choix="+this;
	new Ajax.Request('WNewsChoix.php',
		{
			
			method: 'get',
			parameters: pars,
			onLoading: function() {
				$('loading').show();
			},
			onSuccess: function(requete) {
				afficheChoix(requete);
				}
		});
} // projet
function PrepareAffichage(e) {
	//alert("prepare ok");
	
	var ligneChoix = $('news').getElementsByClassName('echosChoix');
	//alert(ligneChoix);
	for(i=0; i<ligneChoix.length; ++i) 
	{
		
		var idAffiche = ligneChoix[i].id;
		//alert(id);
		Event.observe(idAffiche, 'click', requeteAffichage.bindAsEventListener(idAffiche));
	}
	
	
	
}
//chargement desnews********************************************************************
function afficheNews(transport) {
	//alert('ok');
	//var debut =$('descriNews');
	$('loading').innerHTML="";//on nettoie affichhage loading
	new Insertion.Bottom('insertion', transport.responseText);
	//PrepareAffichage();
	/*var nombreNews = transport.responseXML.getElementsByTagName('line');
	//alert('ok1');
	var ulProjet =  document.createElement("ul");
	ulProjet.id = "ulNews";
	//alert('ok2');
	for(i=0;i<nombreNews.length;++i){
		var nodeTitre = transport.responseXML.getElementsByTagName('line')[i].getAttribute('titre');
		var nodeDate = transport.responseXML.getElementsByTagName('line')[i].getAttribute('date');
		var nodeLien = transport.responseXML.getElementsByTagName('line')[i].getAttribute('lien');
		var nodeTexte = transport.responseXML.getElementsByTagName('line')[i].firstChild.nodeValue;
		//  on ecrit la liste
		var liProjet = document.createElement("li");
		liProjet.id = "liNews";
		// titre
		var pTypeProjet = document.createElement("p");
		var bTypeProjet = document.createElement("b");
		bTypeProjet.appendChild(document.createTextNode(nodeTitre));
		pTypeProjet.appendChild(bTypeProjet);
		liProjet.appendChild(pTypeProjet);
		// date
		var pdateDebutProjet = document.createElement("p");
		pdateDebutProjet.appendChild(document.createTextNode('parue le '+nodeDate));
		liProjet.appendChild(pdateDebutProjet);*/
		//contenu
		/*var pcontenu = document.createElement("p");
		pcontenu.appendChild(document.createTextNode(nodeTexte));
		liProjet.appendChild(pcontenu);*/
		/*var pcontenu = document.createElement("p");
		pcontenu.id='contenuNews';
		liProjet.appendChild(pcontenu);
		pcontenu.innerHTML = nodeTexte;
		//
		ulProjet.appendChild(liProjet);
		
	}
	debut.appendChild(ulProjet);*/
}
//
function news(e) {
	
	new Ajax.Request('WnewsGeneral.php',
		{
			onLoading: function(loading) {
				var emplacement = $('loading');
				displayLoading(emplacement);
			},
			onSuccess: function(transport) {
				afficheNews(transport);
				}
		});
} // projet


Event.observe(window, "load", news);

/*
var oEditor = FCKeditorAPI.GetInstance('mytextbox') ;    // Get the editor instance that we want to interact with
contents =  oEditor.GetXHTML( true ) ;   
 autre solus
 The editor's content is empty when submitting the editor's surrounding form by ajax. What is wrong?

This problem is caused by a missing call of the function FCK.UpdateLinkedField(). By submitting the editor's surrounding form with an ajax function the values of all form elements are collected in a javascript object (some kind of an array). At this time the value of the hidden field that usually contains the editor's html output is empty, because the editor's surrounding form wasn't submitted for real, you can call it a simulated submit. The workaround is to call the FCK.UpdateLinkedField() function before submitting the form. Either you call it directly before the ajax collect function or in the onClick attribute of the submit button. For general use, even if you have more than one FCKeditor instance, I wrote the following hack to solve the problem.


// Some Class
function MyClass()
{
        this.UpdateEditorFormValue = function()
        {
                for ( i = 0; i < parent.frames.length; ++i )
                        if ( parent.frames[i].FCK )
                                parent.frames[i].FCK.UpdateLinkedField();
        }
}
// instantiate the class
var MyObject = new MyClass();
Now can call this method in the onSubmit attribute of the editor's surrounding form before calling the ajax collecting function:

<form ... onSubmit="MyObject.UpdateEditorFormValue(); Ajax.Collect(); return false;">
Note: the previous syntax won't work if using VisualStudio 2005 and Atlas and IE. It will be ok to use :


<form ... onSubmit="MyObject.UpdateEditorFormValue(); return true;">
Or you'll do it in the onClick attribute of the submit button, which is also called before the onSubmit event:


<input type="submit" ... onClick="MyObject.UpdateEditorFormValue();" />
 
 */
