/**
 * This is a check form used to validate the GENERIC register form
 */
function doCheckGenericForm()
{
    if (document.bForm.pseudonyme.value == "" || document.bForm.courriel.value == "")
        alert("Attention! Les champs PSEUDONYME, MOT DE PASSE ET COURRIEL doivent étre remplis!");
    else
	document.bForm.submit()
}

/**
 * This is a check form used to validate the GENERIC modify form
 */
function doCheckGenericFormModify()
{
    alert(document.bForm.password.value );
    if (document.bForm.password.value == "" || document.bForm.courriel.value == "")
        alert("Attention! Les champs MOT DE PASSE ET COURRIEL doivent étre remplis!");
    else
        document.bForm.submit();
}

/**
 * This is a check form used to validate the la cream register form
 */
function doCheckForm(){
    var courriel   = $("input#courriel").val();
    var password   = $("input#password").val();
    var passwordC  = $("input#passwordC").val();
    var prenom     = $("input#prenom").val();
    var nom        = $("input#nom").val();
    var codepostal = $("input#codepostal").val();
    var telephone  = $("input#telephone").val();
    var rules      = $("input#concours_creme-reglement");

    if (courriel == "") {
      $("span#courriel_error").show();
      $("input#courriel").focus();
      return false;
    }

    if (password == "") {
      $("span#password_error").show();
      $("input#password").focus();
      return false;
    }
    else
    {
        if (passwordC == "") {
          $("span#passwordC_error").show();
          $("input#passwordC").focus();
          return false;
        }
        else
        {
            if (password != passwordC)
            {
                $("span#passwordDif_error").show();
                $("input#password").focus();
                return false;
            }
        }
    }

    if (prenom == "") {
      $("span#prenom_error").show();
      $("input#prenom").focus();
      return false;
    }

    if (nom == "") {
      $("span#nom_error").show();
      $("input#nom").focus();
      return false;
    }

    if (codepostal == "") {
      $("span#codepostal_error").show();
      $("input#codepostal").focus();
      return false;
    }

    if (telephone == "") {
      $("span#telephone_error").show();
      $("input#telephone").focus();
      return false;
    }

    if (!rules.is(":checked")) {
      $("span#rules_error").show();
      $("input#concours_creme-reglement").focus();
      return false;
    }

    $('#register_form').submit();

}

function doCheckHistory(){
    var titre    = $("input#titre").val();
    var histoire = $("textarea#histoire").val();
    var recette  = '';

    $("span#titre_error").hide();
    $("span#histoire_error").hide();
    $("span#recette_error").hide();

    recette = $("#trois_recettes li.active").attr("id");
    $("input#rec").val(recette);

    if (titre == "") {
      $("span#titre_error").show();
      $("input#titre").focus();
      return false;
    }

    if (histoire == "") {
      $("span#histoire_error").show();
      $("textarea#histoire").focus();
      return false;
    }

    if ($("input#rec").val() == "") {
      $("span#recette_error").show();
      $("input#rec").focus();
      return false;
    }

    $('#frm_histoire').submit();
}

$('#trois_recettes li').live("click",
  function() {
    $("#trois_recettes li").attr("class","");
    $(this).attr("class","active");
});
