$(document).ready(function() {
    $('ul.list-pages li').each(function() {
        if($('ul',this).length == 0) $(this).addClass('no_fleche');
    });
    //$('ul.list-pages li ul').hide();
    //$('ul.list-pages li').click(function() {
    //  $('ul', this).slideToggle('slow');
    //});
    //
    $('div.entry-content h2').each(function() {
      var content = $(this).nextUntil("h2").detach();
      $(this).after('<div class="subh2"></div>');
      content.appendTo($('+ div.subh2', this));
    });

		// sauf pour la page contact
    if ($("div.entry-content #si_contact_form1").length == 0) {
      $("div.entry-content").accordion({active: false, header: 'h2', autoHeight: false, collapsible: true });
		}

    $('.newsletter form p.submit input.submit').click(function () {
        return verifyNewsletterForm($('.newsletter'));
    });
});


function verifyNewsletterForm(content_form){
    var status = false;
    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    var erreur = '';

    $('.error_form').remove();

    if (!($("input[name=ne]", content_form).val().match(emailRegEx))) {
     erreur += 'Email non conforme';
    }
    
    if ($("input[name=nn]", content_form).val().length == 0) {
     erreur += '<br />Un nom doit être fourni';
    }

    if (erreur !='') {
      $('form', content_form).after('<div class="error_form">'+erreur+'</div>');
    }
    else {
      status = true;
    }

   return status;
}

