
function showComs(debut) {
	//We can use one Request object many times.
	var req = new Request.HTML({url:'/exec/get-coms.php',
	    method: 'get',
		onSuccess: function(html) {
	        $('globalcomms').set('text', '');
            $('globalcomms').adopt(html);
            $('globalcomms').setStyle('display', 'block');
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('globalcomms').set('text', 'The request failed.');
		}
	});

	req.send('id='+article_id+'&debut='+debut);

}

function showFormComms() {
    var form = new Element('form', {'id': 'formcom', 'action': '/exec/post-comment.php'});

    form.appendChild(new Element('input', { 'type':'hidden', 'name':'article_id', 'value': article_id}));
    form.appendChild(new Element('label').set('text','Nom/pseudo:'));
    form.appendChild(new Element('input', {'class':'comms', 'type':'text', 'name':'nom'}));
    form.appendChild(new Element('br', {'style':'clear: left'}));
    form.appendChild(new Element('label').set('text', 'Site web (optionnel):'))
    form.appendChild(new Element('input', {'class':'comms', 'type':'text', 'name':'site'}));
    form.appendChild(new Element('br', {'style':'clear: left'}));
    form.appendChild(new Element('label').set('text', 'Commentaire:'));
    form.appendChild(new Element('textarea', {'name':'texte','class':'comms'}));
    form.appendChild(new Element('br', {'style':'clear: left'}));
    form.appendChild(new Element('input', {'class':'envoi', 'type':'submit', 'value':'Envoyer'}));

    form.appendChild(new Element('br', {'style':'clear: left'}));

    var pform = new Element('p', {'id': 'formaddcomm', 'style': 'padding: 5px; background-color:#f3f3f3;'});
    pform.appendChild(form);

    var myVerticalSlide = new Fx.Slide('formcomms');

    myVerticalSlide.hide();
    $('formcomms').set('text', '');
    $('formcomms').appendChild(pform);
    myVerticalSlide.slideIn();

    window.addEvent('domready', function() {
    	// --
    	$('formcom').addEvent('submit', function(e) {
    		//Prevents the default submit event from loading a new page.
    		e.stop();
    		this.set('send', {onComplete: function(response) {
    		  if (response == 'COK') {
    		      showComs(0);
    		      updateNbComs();
    		      hideFormComms();
    		  } else {
    		      alert(response);
    		  }
    		}});
    		//Send the form.
    		this.send();
    	});
    });
}

function hideFormComms() {
    var myVerticalSlide = new Fx.Slide('formcomms');
    myVerticalSlide.slideOut();
}

window.addEvent('domready', function() {

    $('globalcomms').setStyle('display', 'none');

	//We can use one Request object many times.
    updateNbComs();
});

function updateNbComs() {
    var req = new Request.HTML({url:'/exec/get-nbcoms.php?id='+article_id,
		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('nbcomms').set('text', '');
			//Inject the new DOM elements into the results div.
			$('nbcomms').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('nbcomms').set('text', 'The request failed.');
		}
	});
    req.send();
}

/**/
