$(document).ready(function(){
	var ancre = document.URL;
	ancre = ancre.split("#");
	if (ancre.length > 1)
	{
		ancre = ancre[1];
	}
	else
	{
		ancre = "";
	}
	if (ancre != "")
	{
		$('.scrollable').slimScroll({
		    height: '520px',
		    color: '#0f4055',
		    width: '400px',
		    start: $('#pliage')
        	});
	}
	else
	{
		$('.scrollable').slimScroll({
		    height: '520px',
		    color: '#0f4055',
		    width: '400px'
        	});
	}
	if ($('#closeCommentaire').size() > 0) {
		clickCloseFormCommentaire();
		clickOpenFormCommentaire();
	}
});

$(document).ready(function() { 	
    var options = { 
        target:        "#responseFormCommentaire",   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#formCommentaire').ajaxForm(options); 
}); 
 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
	var isSuccessFull = true;
    var queryString = $.param(formData); 
	erreur = "";
	if ($("#commantaire_nom").val() == "")
	{
		erreur = erreur + "<li>Nom</li>";
	}
	if ($("#commantaire_prenom").val() == "")
	{
		erreur = erreur + "<li>Pr&eacute;nom</li>";
	}
	if ($("#commantaire_societe").val() == "")
	{
		erreur = erreur + "<li>Soci&eacute;t&eacute;</li>";
	}
	if ($("#commantaire_texte").val() == "")
	{
		erreur = erreur + "<li>Commentaire</li>";
	}
	if (erreur != "")
	{
		$("#responseFormCommentaire").html("<ul><li class='titre'>Les champs suivants sont obligatoire</li>" + erreur + "</ul>")
		isSuccessFull = false;
	}
    return isSuccessFull; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText, xhr, $form)  {
    if (responseText == "")
	{
		closeFormCommentaire();
		window.location = "";
	}
}

function closeFormCommentaire()
{
	$("#formCommentaire").fadeOut("slow");
}
function clickCloseFormCommentaire()
{
	$('#closeCommentaire').unbind("click").click(function() {
		closeFormCommentaire();
	});
}
function clickOpenFormCommentaire()
{
	$('#openFormCommentaire').unbind("click").click(function() {
		openFormCommentaire();
	});
}
function openFormCommentaire()
{
	$("#formCommentaire").fadeIn("slow");
}
