
function infoCoupon(url, choix, cote, evenement, pari, login, validation, combi_activer, mise_combi, cote_combi, lien_complet){
    
    var codehtml;
    
        codehtml = file(url+'/script/coupon.php5?url='+escape(url)+'&choix='+escape(choix)+'&cote='+escape(cote)+'&evenement='+escape(evenement)+'&pari='+escape(pari)+'&validation='+escape(validation)+'&combi='+escape(combi_activer)+'&mise_combi='+escape(mise_combi)+'&cote_combi='+escape(cote_combi)+'&lien_complet='+escape(lien_complet));
        
        document.getElementById('coupon').innerHTML = codehtml;


}

function validation_score(url, score_1, score_2, evenement, pari, login, validation, combi_activer, mise_combi, cote_combi, lien_complet){

    var codehtml;

    var choix_score = score_1.value+" - "+score_2.value;

    var choix_format = file(url+"/script/recuperation_choix.php5?choix_score="+escape(choix_score)+"&pari="+escape(pari));

        choix_format = choix_format.split('/');

        var choix = choix_format[0];
        var cote = choix_format[1];

        codehtml = file(url+'/script/coupon.php5?url='+escape(url)+'&choix='+escape(choix)+'&cote='+escape(cote)+'&evenement='+escape(evenement)+'&pari='+escape(pari)+'&validation='+escape(validation)+'&combi='+escape(combi_activer)+'&mise_combi='+escape(mise_combi)+'&cote_combi='+escape(cote_combi)+'&lien_complet='+escape(lien_complet));

        document.getElementById('coupon').innerHTML = codehtml;

}

function recuperation_cote(url, pari){

    var score_1 = document.getElementById('score_1');
    var score_2 = document.getElementById('score_2');

    var choix_score = score_1.value+" - "+score_2.value;

    var cote = file(url+"/script/recuperation_cote.php5?choix_score="+escape(choix_score)+"&pari="+escape(pari));

    cote = Math.round(cote*100)/100;

    document.getElementById('cote_score').innerHTML = cote;

}

function desactiver_bouton(dom){

    if(dom.className == 'bouton-cote-active'){
        //dom.disabled = false;
        dom.className = 'bouton-cote';
    }else{
        //dom.disabled = true;
        dom.className = 'bouton-cote-active';

    }

}

function desactiver_bouton_list(choix_id){

   if(document.getElementById("cote_acteur_"+choix_id) != null){
       if(document.getElementById("cote_acteur_"+choix_id).className == 'bouton-cote-active'){
            //document.getElementById("cote_acteur_"+choix_id).disabled = true;
            document.getElementById("cote_acteur_"+choix_id).className = 'bouton-cote';
       }else{
           document.getElementById("cote_acteur_"+choix_id).className = 'bouton-cote-active';
       }
    }

}

function desactiver_bouton_haut(choix_id){

    if(document.getElementById("cote_acteur_haut_"+choix_id) != null){
        if(document.getElementById("cote_acteur_haut_"+choix_id).className == 'bouton-cote-active'){
            //document.getElementById("cote_acteur_haut_"+choix_id).disabled = true;
            document.getElementById("cote_acteur_haut_"+choix_id).className = 'bouton-cote';
        }else{
            document.getElementById("cote_acteur_haut_"+choix_id).className = 'bouton-cote-active';
        }
    }

}

function desactiver_bouton_gauche(choix_id){

    if(document.getElementById("cote_acteur_gauche_"+choix_id) != null || document.getElementById("cote_acteur_gauche_"+choix_id) != ""){

        if(document.getElementById("cote_acteur_gauche_"+choix_id).className == 'bouton-cote-active'){
            document.getElementById("cote_acteur_gauche_"+choix_id).className = 'bouton-cote';
        }else{
            //document.getElementById("cote_acteur_gauche_"+choix_id).disabled = true;
            document.getElementById("cote_acteur_gauche_"+choix_id).className = 'bouton-cote-active';
        }
    }

}

function suppression_coupon(url){

    var codehtml = file(url+'/script/coupon.php5?validation=3');

    document.getElementById('coupon').innerHTML = codehtml;

    window.location.reload(true);

}

function verification_mise(champ){

    var chiffres = new RegExp("[0-9]");
    var verif;
    var points = 0;
   

    for(x = 0; x < champ.value.length; x++)
    {
            verif = chiffres.test(champ.value.charAt(x));
        if(champ.value.charAt(x) == "."){points++;}
            if(points > 1){verif = false; points = 1;}
        if(verif == false){champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); x--;}
    }

    

}

function verification_valeur_mise(champ){

    if(champ.value < 100){
        alert('Votre mise doit être supérieure à 100');
        document.getElementById('validation_coupon').disabled = true;
    }else if(champ.value > 1000){
        alert('Votre mise doit être inférieure à 1000');
        document.getElementById('validation_coupon').disabled = true;
    }else{
        document.getElementById('validation_coupon').disabled = false;
    }

}

function verification_mise_pari(champ, mise_restante){

    if(champ.value > mise_restante){
        alert('Votre mise ne doit pas excéder '+mise_restante+' jetons');
        document.getElementById('validation_coupon').disabled = true;
    }

}

function calcul_gain_potentiel(nb_details){

    var cote;
    var mise;
    var gain_potentiel = 0;
    var gain_pari;

    for(i = 0; i < nb_details; i++){

        cote = document.getElementById('cote_'+i);
        mise = document.getElementById('mise_'+i);

        if(mise.value == ''){
            gain_pari = 0;
        }else{
            gain_pari = cote.value * mise.value;
        }

        gain_potentiel = gain_potentiel + gain_pari;

    }

    gain_potentiel = parseInt(gain_potentiel);

     document.getElementById('gain_potentiel').innerHTML = gain_potentiel;

}

function calcul_gain_cote(nb_details){

    var cote;
    var mise;
    var gain_potentiel = 0;
    var gain_pari;

    for(i = 0; i < nb_details; i++){

        cote = document.getElementById('cote_'+i);
        mise = document.getElementById('mise_'+i);

        if(mise.value == ''){
            gain_pari = 0;
        }else{
            gain_pari = cote.value * mise.value;
        }

        gain_potentiel = gain_potentiel + gain_pari;

    }

    gain_potentiel = parseInt(gain_potentiel);

     document.getElementById('gain_potentiel').innerHTML = gain_potentiel;

}

function calcul_valeur_coupon(nb_details){

    var cote;
    var mise;
    var gain_potentiel = 0;
    var gain_potentiel_combine = 0;
    var gain_potentiel_total = 0;
    var cout_potentiel = 0;
    var cout_potentiel_combine = 0;
    var cout_potentiel_total = 0;
    var gain_pari;
    var case_coche;
    var nb_pari = 0;
    var nb_pari_total = 0;

    for(i = 0; i < nb_details; i++){

        cote = document.getElementById('cote_'+i);
        mise = document.getElementById('mise_'+i);
        case_coche = document.getElementById('active_pari_'+i);

        if(case_coche.checked){

            if(mise.value == ''){
            gain_pari = 0;
            }else{
                gain_pari = cote.value * mise.value;
            }

            gain_pari = parseInt(gain_pari);

            document.getElementById('gain_unitaire_'+i).innerHTML = gain_pari;

            gain_potentiel = gain_potentiel + gain_pari;

            cout_potentiel = cout_potentiel + parseInt(mise.value);

            nb_pari++;
        }

    }

    

    mise = document.getElementById('mise_combi');
    cote = document.getElementById('cote_combi');
    case_coche = document.getElementById('id-combi-21');

    if(case_coche.checked){
        if(mise.value == ''){
            gain_potentiel_combine = 0;
        }else{
            gain_potentiel_combine = cote.value * mise.value;
            cout_potentiel_combine = mise.value;
        }

        nb_pari_total = nb_pari + 1;

    }else{
        gain_potentiel_combine = 0;

        nb_pari_total = nb_pari;
    }
    
    gain_potentiel = parseInt(gain_potentiel);
    gain_potentiel_combine = parseInt(gain_potentiel_combine);
    gain_potentiel_total = gain_potentiel + gain_potentiel_combine;

    cout_potentiel = parseInt(cout_potentiel);
    cout_potentiel_combine = parseInt(cout_potentiel_combine);
    cout_potentiel_total = cout_potentiel + cout_potentiel_combine;

    nb_pari = parseInt(nb_pari);
    nb_pari_total = parseInt(nb_pari_total);

    document.getElementById('gain_potentiel').innerHTML = gain_potentiel;
    document.getElementById('gain_potentiel_combine').innerHTML = gain_potentiel_combine;
    document.getElementById('gain_potentiel_total').innerHTML = gain_potentiel_total;

    document.getElementById('cout_total').innerHTML = cout_potentiel_total;
    document.getElementById('nb_pari').innerHTML = nb_pari;
    document.getElementById('nb_total_pari').innerHTML = nb_pari_total;

}

function calcul_gain_unitaire(mise, cote, rang){

    var gain;

    gain = mise * cote;

    gain = parseInt(gain);

    document.getElementById('gain_unitaire_'+rang).innerHTML = gain;

}

function suppression_choix(url, details_coupon, choix_id, lien_complet){

    if( document.getElementById('cote_acteur_'+choix_id) != null){
        document.getElementById('cote_acteur_'+choix_id).disabled = false;
        document.getElementById('cote_acteur_'+choix_id).className = 'bouton-cote';
    }

    if(document.getElementById('cote_acteur_gauche_'+choix_id) != null){
        document.getElementById('cote_acteur_gauche_'+choix_id).disabled = false;
        document.getElementById('cote_acteur_gauche_'+choix_id).className = 'bouton-cote';
    }

    if(document.getElementById('cote_acteur_haut_'+choix_id) != null){
        document.getElementById('cote_acteur_haut_'+choix_id).disabled = false;
        document.getElementById('cote_acteur_haut_'+choix_id).className = 'bouton-cote';
    }

    file(url+'/script/coupon.php5?suppression=1&details_coupon='+escape(details_coupon));
    
    infoCoupon(url, 0, 0, 0, 0, 1, 0, 0, 0, 0, lien_complet);

}

function active_choix(choix_id){
    
    document.getElementById('cote_acteur_'+choix_id).disabled = false;
    document.getElementById('cote_acteur_'+choix_id).className = 'bouton-cote';
    
}

function affichage_question_sup(compteur){

    var cadre = document.getElementById('cadre_question_sup_'+compteur);

    if(cadre.style.display == 'none'){

        cadre.style.display = '';

    }else if(cadre.style.display == ''){

        cadre.style.display = 'none';

    }

}

function recap_defi_podium(formulaire){

    var premier_choix = document.getElementById('premier_place');
    var second_choix = document.getElementById('seconde_place');
    var trosieme_choix = document.getElementById('troisieme_place');
    var nom_premier = premier_choix.value.split('/')[1];
    var nom_second = second_choix.value.split('/')[1];
    var nom_troisieme = trosieme_choix.value.split('/')[1];
    var verif_recap = 0;

    if(premier_choix.value == "podium_premier"){
        alert("Vous n'avez pas séléctionné le premier acteur");
        return false;
        verif_recap = 1;
    }

    if(second_choix.value == "podium_seconde"){
        alert("Vous n'avez pas séléctionné le second acteur");
        return false;
        verif_recap = 1;
    }

    if(trosieme_choix.value == "podium_troisieme"){
        alert("Vous n'avez pas séléctionné le troisieme acteur");
        return false;
        verif_recap = 1;
    }

    if(verif_recap != 1){
        if (confirm("Pronostic : \n\n 1er : "+nom_premier+" \n 2e : "+nom_second+" \n 3e : "+nom_troisieme+"\n\n Confirmer ?"))
         {
             formulaire.submit();
         }
        else
         {}
    }


}

function verif_coupon(formulaire){

    var jetons_parieur = document.getElementById('jeton_parieur');
    var cout_total = document.getElementById('cout_total_parieur');

    var verif_coupon = 0;

    if(parseInt(jetons_parieur.value) < parseInt(cout_total.value)){
        alert('Vous n\'avez pas assez de jetons pour jouer ce coupon.');
        return false;
        verif_coupon = 1;
    }

    if(verif_coupon == 0){
        formulaire.submit();
    }

    

}

//function switch_coupon(libelle){
//
//    if(libelle == 'pari'){
//        if(document.getElementById('coupon_milieu_pari').style.display == 'none'){
//            document.getElementById('coupon_milieu_pari').style.display = '';
//            document.getElementById('coupon_footer_pari').style.display = '';
//            document.getElementById('coupon_milieu_defi').style.display = 'none';
//            document.getElementById('coupon_footer_defi').style.display = 'none';
//            document.getElementById('onglet_pari').className = 'onglet-haut';
//            document.getElementById('onglet_grille').className = 'onglet-bas';
//        }
//    }else if(libelle == 'defi'){
//        if(document.getElementById('coupon_milieu_defi').style.display == 'none'){
//            document.getElementById('coupon_milieu_defi').style.display = '';
//            document.getElementById('coupon_footer_defi').style.display = '';
//            document.getElementById('coupon_milieu_pari').style.display = 'none';
//            document.getElementById('coupon_footer_pari').style.display = 'none';
//            document.getElementById('onglet_pari').className = 'onglet-bas';
//            document.getElementById('onglet_grille').className = 'onglet-haut';
//        }
//    }
//
//}