﻿//¤¤¤ ON LOAD EVENTS ¤¤¤
var oldLimit = -102365;
var ClassType = 1;
var chkBoxLocked = false;
var previewChoiceMade = false;

$(document).ready(function () {
    $("#ctl00_cphMain_ucForm_divLessonType label").removeClass('ui-state-active');
    $("#ctl00_cphMain_ucForm_divLessonType label").attr("aria-pressed", false);

    $("#ctl00_cphMain_ucForm_rdoLessonType_0").removeAttr("disabled");
    $("#ctl00_cphMain_ucForm_rdoLessonType_1").removeAttr("disabled");

    $("#ctl00_cphMain_ucForm_rdoLessonType_0").attr("checked", true);
    $("#ctl00_cphMain_ucForm_rdoLessonType_1").attr("checked", false);

    $("#ctl00_cphMain_ucForm_rdoLessonType_0").attr("disabled", "disabled");
    $("#ctl00_cphMain_ucForm_rdoLessonType_1").attr("disabled", "disabled");

    $("#ctl00_cphMain_ucForm_hidClassType").val("0");

    if ($.browser.mozilla) {
        $(".divhiddenUpload").addClass("divhiddenUpload-FF");
        $(".divhiddenUpload").removeClass("divhiddenUpload");

        $(".divFakeUpload").addClass("divFakeUpload-FF");
        $(".divFakeUpload").removeClass("divFakeUpload");

        $(".hiddenFileUpload").addClass("hiddenFileUpload-FF");
        $(".hiddenFileUpload").removeClass("hiddenFileUpload");
    }
    else if ($.browser.msie) {
        $(".divhiddenUpload").addClass("divhiddenUpload-FF");
        $(".divhiddenUpload").removeClass("divhiddenUpload");

        $(".divFakeUpload").addClass("divFakeUpload-FF");
        $(".divFakeUpload").removeClass("divFakeUpload");

        $(".hiddenFileUpload").addClass("hiddenFileUpload-IE");
        $(".hiddenFileUpload").removeClass("hiddenFileUpload");

        $(".btnUpload").addClass("btnUpload-IE");
        $(".btnUpload").val("Choisir...");
        $(".btnUpload-IE").removeClass("btnUpload");
    }

    //Preview popup for forms.
    //$(".modal").overlay({ top: 150, closeOnClick: false, load: true });

    $("#divNewPopup .btnlogin").live('click', function () {
        if ($(this).parent().parent().parent().parent().attr("id") == "divNewPopup" && previewChoiceMade == false);
        {
            if ($(this).val() == "Envoyer") {
                previewChoiceMade = true;
                $("#ctl00_cphMain_btnFinalSubmit").click();
                $("#ctl00_cphMain_ucForm_btnFinalSubmit").click();
                $("#ctl00_cphMain_ucFormMember_btnFinalSubmit").click();
                $("#ctl00_cphMain_FormMember_btnFinalSubmit").click();
            }
            else if ($(this).val() == "Modifier") {
                previewChoiceMade = true;
                $(".modalmask").fadeOut("slow");
                $(".IEmask").fadeOut("slow");
                $(".popup").fadeOut("slow");
                $('.modalmask').hide();
            }
            else if ($(this).val() == "Annuler") {
                previewChoiceMade = true;
                $("#ctl00_cphMain_btnCancel").click();
                $("#ctl00_cphMain_ucForm_btnCancel").click();
                $("#ctl00_cphMain_ucFormMember_btnCancel").click();
                $("#ctl00_cphMain_FormMember_btnCancel").click();
            }
        }
    });

    //Preview small popup for forms.
    if (!$(".smallmodal").is(":visible")) {
        $(".smallmodal").overlay({ top: 150, closeOnClick: false, load: true });
        $(".smallmodal").hide();
        $("#ctl00_cphMain_ucForm_smallmodalmask").hide();
    }
    else {
        $(".smallmodal").overlay({ top: 150, closeOnClick: false, load: true });
    }

    //Preview popup with price reset warning for forms.
    //$(".modalwarning").overlay({ closeOnClick: false, load: true });

    //Preview popup with price reset warning for forms.
    //$(".modalwarning").overlay({ top: 150, closeOnClick: false, load: true });

    $('input[id^="ctl00_cphMain_ucForm_rdoPaymentType_"]').live('click', function () {
        if ($.browser.msie && $.browser.version < 9) {
            window.scrollTo(0, document.body.scrollHeight * 100);
        }
    });

    $("form").submit(function (e) {
        //alert($("#ctl00_cphMain_ucForm_divSubmit").is(":visible"));
        if ($("#ctl00_cphMain_ucForm_divSubmit").is(":visible") && $("#ctl00_cphMain_ucForm_divCongres").is(":visible") && !$("#divNewPopup").is(":visible")) {
            if (($('.ui-state-active').length - 1) < 1) {
                e.preventDefault();
                $(".smallmodal").show();
                $("#ctl00_cphMain_ucForm_smallmodalmask").show();
            }
        }
        else if ($("#ctl00_cphMain_txtAmount").is(":visible")) {
            if ($("#ctl00_cphMain_txtAmount").val() == "") {
                e.preventDefault();
                $(".smallmodal").show();
                $("#divFiscalMask").show();
            }
        }
        else if ($("#ctl00_cphMain_ucForm_divSubmit").is(":visible") && !$("#divNewPopup").is(":visible")) {
            if (!$("#ctl00_cphMain_ucForm__pnlSplitEvent").is(":visible")) {
                if (oldLimit != -10) {
                    return true;
                }
                else if ($(".chkevents input:checked").length != 10) {
                    e.preventDefault();
                    $(".smallmodal").show();
                    $("#ctl00_cphMain_ucForm_smallmodalmask").show();
                }
                else {
                    return true;
                }
            }
        }
    });

    //Closing the mask div when clicking on the modify button.
    $("#btnModify").click(function () {
        $(".modalmask").fadeOut("slow");
        $(".IEmask").fadeOut("slow");
        $(".popup").fadeOut("slow");
        $('.modalmask').hide();
    });

    //Closing the mask div when clicking on the modify button.
    $("#SmallBtnModify").click(function () {
        $(".smallmodal").hide();
        $('.modalmask').hide();
        $("#ctl00_cphMain_ucForm_smallmodalmask").hide();
    });

    $("#divTooltip span[title]").tooltip();
    //$(".divenglober .formlabel[title]").tooltip();

    //.simplehover - Rollover effect on links
    $("a.simplehover img, img.simplehover").mouseover(function () {
        $(this).attr("src", $(this).attr("src").replace("-off.", "-on."));
    }).mouseout(function () {
        $(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
    });

    $.get('/activities-ajax-array.aspx', function (data) {
        eval("dates = " + data);
        $("#div-calendar").datepicker({ beforeShowDay: highlightDays, onSelect: SelectedDay, dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'], monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'] });
    });

    $.validity.setup({ scrollTo: true });

    $("form").validity(function () {
        $(".required").require("Ce champ est obligatoire");
        $(".txtemail").match("email", "Courriel invalide");
        $(".validurl").match("url", "Adresse invalide (http://www.site.com)");
        $(".validannée").match("number", "Format invalide (ex: 1985)");
    });


    $(".prettyme br").replaceWith(''); //fix RadioButtonList Bug
    $(".prettyme").buttonset();

    $(".ui-state-disabled").css({ opacity: 1 });

    /*$(".career-box .link-register").fadeTo(0, 0.25);
    $(".career-box").mouseenter(function () {
    $(this).children().children(".link-register").stop(true, true).fadeTo(200, 1);
    }).mouseleave(function () {
    $(this).children().children(".link-register").stop(true, true).fadeTo(200, 0.25);
    });*/


    //On Inscription, select the first price package
    $(".rdoprice:first").click();
    $("#ctl00_cphMain_rdoprice:first").click();
    ShowPriceSubscription();


    //$(".uniform").children().addClass("uniform");
    //$(".uniformme").uniform();


    $(".lnkLostPassword").live('click', function () {
        $("#dialoglostpassword").dialog({ modal: true, width: 400, show: 'fade', hide: 'fade', resizable: false,
            "buttons": { "Fermer": function () { $(this).dialog("close"); }, "Envoyer la demande": function () { $(".btnSendPassword").click(); } }
        });
        $("#dialoglostpassword").parent().appendTo($("form:first")); //otherwise postback will not work
        return false;
    });

    //Add Formation
    $(".lnkAjouterFormation").live('click', function () {
        $("#dialogaddformation").dialog({ modal: true, width: 400, show: 'fade', hide: 'fade', resizable: false,
            "buttons": { "Ajouter": function () {

                //add item to the select
                $("#ctl00_cphMain_lbFormations").append(
                    '<option>' + $("#ctl00_cphMain_ddlNiveau option:selected").text() + ', ' + $("#ctl00_cphMain_ddlProgramme option:selected").text() + ', ' + $("#ctl00_cphMain_ddlInstitution option:selected").text() + ' (' + $("#ctl00_cphMain_txtDateOptention").val() + ') </option>'
                );

                //update textbox in the background
                $("#ctl00_cphMain_txtHiddenFormation").val(
                    $("#ctl00_cphMain_txtHiddenFormation").val() + $("#ctl00_cphMain_ddlNiveau option:selected").val() + ';' + $("#ctl00_cphMain_ddlProgramme option:selected").val() + ';' + $("#ctl00_cphMain_ddlInstitution option:selected").val() + ';' + $("#ctl00_cphMain_txtDateOptention").val() + '|'
                );

                $(this).dialog("close");
            }, "Fermer": function () { $(this).dialog("close"); }
            }
        });
        return false;
    });


    //Delete Formation
    $(".lnkDeleteFormation").live('click', function () {

        //If we had an option selected
        if ($("#ctl00_cphMain_lbFormations option:selected").index() >= 0) {
            //get hidden field that contains the values
            var hiddenvalues = $("#ctl00_cphMain_txtHiddenFormation").val().split('|');

            //Remove item from the hidden values
            hiddenvalues.splice($("#ctl00_cphMain_lbFormations option:selected").index(), 1);

            //update hidden field
            var s = "";
            for (var i = 0; i < hiddenvalues.length - 1; i++) {
                s += hiddenvalues[i] + '|';
            }
            $("#ctl00_cphMain_txtHiddenFormation").val(s);

            //remove from list for the user
            $("#ctl00_cphMain_lbFormations option:selected").remove();
        }
    });


    //enable numeric texboxes
    $(".numeric").numeric();


    //Count the Total Selection in CheckBoxList - BusinessType
    $('input[name*=chkFormation]').live('click', function () {
        var totCount = 1;

        //Get the value of the other inputs
        $(this).siblings().each(function () {
            if ($(this).attr("checked")) { totCount++; }
        });

        //if number of selected item is greater than the 
        if (totCount > $(this).parent().attr('maxselection')) { return false; }
        return true;

    });

    //Profil.aspx - Maximum choices per checkboxlist
    LimitCheckboxes('input[name*=chkProfession]', 4);
    LimitCheckboxes('input[name*=chkExercice]', 2);
    LimitCheckboxes('input[name*=chkOrganismes]', 2);
    LimitCheckboxes('input[name*=chkExpertise]', 3);
    LimitCheckboxes('input[name*=chkSecteursPratique]', 3);
    LimitCheckboxes('input[name*=chkLoisir]', 3);
    LimitCheckboxes('input[name*=chkAffiliation]', 3);
    LimitCheckboxes('input[name*=chkCatEmployeur]', 3);
    LimitCheckboxes('#ctl00_cphMain_chkList1 input', 10);

    $(".divResult .divBottinBox:nth-child(3n)").css('margin-right', 0);

    if ($("#ctl00_cphMain_ucForm__pnlSplitEvent").is(":visible")) 
    {
        $("#_divSplitGroup1 input:first").click();
        $("#_divSplitGroup1 input:first").click();

        $("#_divSplitGroup2 input:first").click();
        $("#_divSplitGroup2 input:first").click();

        $("#_divSplitGroup3 input:last").click();
    }

    if ($("#ctl00_cphMain_ucForm_divPriceList").is(":visible"))
    {
        $(".btnsubmit").live('click', function () {
            eval("var choiceSelected = " + $("#ctl00_cphMain_ucForm_divPriceList input:checked").val());
            $("#ctl00_cphMain_ucForm__hidSelectedChoice").val(choiceSelected[4]);
        });
    }
});

function ValidateText(i) {
    if (i.value.length > 0) {
        i.value = i.value.replace(/[^\d]+/g, '');
    }
}

function UpdateHiddenField() 
{
    var s = "<ul>";
    $("#ctl00_cphMain_lbFormations option").each(function () {
        s = s + "<li>" + $(this).text() + "</li>";
    });
    s = s + "</ul>";


    $("#ctl00_cphMain_txtHiddenFormation").val(s);
}

//Limit Checkboxes options - control must be RepeatLayout="Flow". (get rid of ugly tables!)
function LimitCheckboxes(control, max) {

    //Count the Total Selection in CheckBoxList
    $(control).live('click', function () {
        var checkedcount = 1;

        //Get the state of the inputs
        $(this).siblings().each(function () {
            if ($(this).attr("checked")) { checkedcount++; }
        });

        //if number of selected item is greater than the maximum, do not check
        if (checkedcount > max) { $("label[for="+$(this).attr('id')+"]").removeClass("ui-state-active"); $("label[for="+$(this).attr('id')+"]").attr("aria-pressed","false"); return false; }
        return true;
    });

}


function SelectedDay(date, inst) 
{
    //hack so the UI is updated
    window.setTimeout(function () 
    {
        if (inst.dpDiv.find('.ui-datepicker-current-day a').parent().attr("class") != null)
        {
            var classes = inst.dpDiv.find('.ui-datepicker-current-day a').parent().attr("class").split(" ");

            for (var i in classes) {
                //if (classes[i].substring(0, 7) == "formId=") { location.href = "/fr/inscriptions.aspx?i=" + classes[i].substring(7) }
                if (classes[i].substring(0, 7) == "formId=") { location.href = "/fr/activites.aspx#event" + classes[i].substring(7) }
            }
        }

    }, 0);
    
}

//Highlight days on the calendar
function highlightDays(date) {
    for (var i = 0; i < dates.length; i++) {
        if (date - dates[i][0] == 0) { return [true, 'formId=' + dates[i][2], dates[i][1]]; }
    }
    return [false];
}


//¤¤¤ FUNCTIONS & UTILITIES ¤¤¤

function ReturnLanguage() {
    language = $(location).attr('href').substr($(location).attr('href').indexOf('/', 7) + 1, 2);
    return language;
}

function VerticalCenteringForIE() {
    $(".category-image").load(function() {
        $(this).css("top", ($(this).parent().height() - $(this).height()) / 2);
    }).each(function() {
        if (this.complete) $(this).trigger("load"); //Patch for IE cached images
    });
}

//parse URL to get values  - To retrieve example : var i = getUrlVars()["i"];
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

$("#imagePrint").live('click', function () {

});


function PrintForm() {
    $('head').append("<link rel=\"stylesheet\" type=\"text/css\" media=\"print\" href=\"/css/print.css\" />"); 

    $('#ctl00_divPrint').html($('.PrintSource').html());
    window.print();
}

$(".rdoprice").live('click', function () {

    //Super ASP.Net Bug Radio button with repeater
    $(".rdoprice input").attr("checked", false);
    $(this).find("input").attr("checked", true);

    ShowPrice();
});

$(".chkevents").live('click', function () {
    ShowPrice();
});

$(".rdopriceSub label").live('click', function () {
    ShowPrice();
    ShowPriceSubscription();
});

$(".fixcheckboxes .rdopriceSub").live('click', function () {
    $(".rdopriceSub input").attr("checked", false);
    $(this).find("input").attr("checked", true);
    ShowPriceSubscription();
});


function changeClassType()
{
    $("#ctl00_cphMain_ucForm_divLessonType label[aria-pressed=true]").removeClass('ui-state-active');
    $("#ctl00_cphMain_ucForm_divLessonType label[aria-pressed=false]").addClass('ui-state-active');
    $("#ctl00_cphMain_ucForm_divLessonType label[aria-pressed=true]").attr("aria-pressed", false);
    $("#ctl00_cphMain_ucForm_divLessonType .ui-state-active").attr("aria-pressed", true);

    if(ClassType == 1) {
        $("#ctl00_cphMain_ucForm_rdoLessonType_0").attr("checked", true);
        $("#ctl00_cphMain_ucForm_rdoLessonType_1").attr("checked", false);
        $("#ctl00_cphMain_ucForm_hidClassType").val("0");
    }
    else
    {
        $("#ctl00_cphMain_ucForm_rdoLessonType_0").attr("checked", false);
        $("#ctl00_cphMain_ucForm_rdoLessonType_1").attr("checked", true);
        $("#ctl00_cphMain_ucForm_hidClassType").val("1");
    }
}

$("#ctl00_cphMain_txtAmount").live('keyup', function () {
    $('#ctl00_cphMain_txtAmount').val($('#ctl00_cphMain_txtAmount').val().replace(/[^\d]/g, ""));
    ShowPriceSubscription();
});

function ShowPriceSubscription() {
    $(".prettyme").button("refresh");

    if ($("#ctl00_cphMain_rdoprice").is(":visible"))
    {
        if ($('#ctl00_cphMain_rdoprice').attr('checked'))
        {
            eval("var pricedata = " + $("#ctl00_cphMain_rdoprice").attr("value"));
        }
        else
        {
            eval("var pricedata = " + $("#ctl00_cphMain_rdoprice2").attr("value"));
        }

        var subtotal  = Number(pricedata[0].replace(',', '.'));
        var tps = Number(pricedata[2]) / 100;
        var tvq = Number(pricedata[3]) / 100;
        var total = 0;
        var taxes = 0;
        if (tps > 0) { taxes = subtotal * tps; }
        if (tvq > 0) { taxes += (subtotal + taxes) * tvq; }

        subtotal = subtotal.toFixed(2);
        taxes = taxes.toFixed(2);
        total = parseFloat(parseFloat(subtotal) + parseFloat(taxes));
        total = total.toFixed(2);

        $(".total-subtotal").html(subtotal);
        $(".total-taxes").html(taxes);
        $(".total-total").html(total);

        //alert("taxes :" + taxes);
        $("#ctl00_cphMain_ucForm_hiddenPriceId").val(pricedata[4]);
        $("#ctl00_cphMain_FormMember_hiddenPriceId").val(pricedata[4]);
    }
    else if ($("#ctl00_cphMain_txtAmount").hasClass("exam"))
    {

        if($("#ctl00_cphMain_txtAmount").val() > 0)
        {
            eval("var pricedata = " + $("#ctl00_cphMain_txtAmount").attr("hiddenValue"));

            var subtotal;

            if($("#ctl00_cphMain_txtAmount").val() < 100)
            {
                subtotal = Number(pricedata[0].replace(',', '.'));
            }
            else if($("#ctl00_cphMain_txtAmount").val() >= 100 && $("#ctl00_cphMain_txtAmount").val() < 500)
            {
                subtotal = Number(pricedata[5].replace(',', '.'));
            }
            else if ($("#ctl00_cphMain_txtAmount").val() >= 500)
            {
                subtotal = Number(pricedata[6].replace(',', '.'));
            }

            subtotal = subtotal * $("#ctl00_cphMain_txtAmount").val();

            var tps = Number(pricedata[2]) / 100;
            var tvq = Number(pricedata[3]) / 100;
            var total = 0;
            var taxes = 0;
            if (tps > 0) { taxes = subtotal * tps; }
            if (tvq > 0) { taxes += (subtotal + taxes) * tvq; }

            subtotal = subtotal.toFixed(2);
            taxes = taxes.toFixed(2);
            total = parseFloat(parseFloat(subtotal) + parseFloat(taxes));
            total = total.toFixed(2);

            $(".total-subtotal").html(subtotal);
            $(".total-taxes").html(taxes);
            $(".total-total").html(total);

            //alert("taxes :" + taxes);
            $("#ctl00_cphMain_ucForm_hiddenPriceId").val(pricedata[4]);
            $("#ctl00_cphMain_FormMember_hiddenPriceId").val(pricedata[4]);
        }
    }
    else if ($("#ctl00_cphMain_txtAmount").hasClass("revue")) 
    {
        if ($("#ctl00_cphMain_txtAmount").val() > 0)
        {
            eval("var pricedata = " + $("#ctl00_cphMain_txtAmount").attr("hiddenValue"));

            var subtotal;
            subtotal = Number(pricedata[0].replace(',', '.'));

            subtotal = subtotal * $("#ctl00_cphMain_txtAmount").val();

            var tps = Number(pricedata[2]) / 100;
            var tvq = Number(pricedata[3]) / 100;
            var total = 0;
            var taxes = 0;
            if (tps > 0) { taxes = subtotal * tps; }
            if (tvq > 0) { taxes += (subtotal + taxes) * tvq; }

            subtotal = subtotal.toFixed(2);
            taxes = taxes.toFixed(2);
            total = parseFloat(parseFloat(subtotal) + parseFloat(taxes));
            total = total.toFixed(2);

            $(".total-subtotal").html(subtotal);
            $(".total-taxes").html(taxes);
            $(".total-total").html(total);

            //alert("taxes :" + taxes);
            $("#ctl00_cphMain_ucForm_hiddenPriceId").val(pricedata[4]);
            $("#ctl00_cphMain_FormMember_hiddenPriceId").val(pricedata[4]);
        }
    }

    $(".prettyme").button("refresh");
}

function previewCancel() 
{
    $('#ctl00_cphMain_btnCancel').click();
}

function ShowPrice() {
    $(".prettyme").button("refresh");

    /*if ($("#ctl00_cphMain_ucForm_divLessonType label").hasClass('ui-state-disabled'))
    {
        $("#ctl00_cphMain_ucForm_divLessonType label").removeClass('ui-state-disabled');
    }*/

    //The value attribute of the selected checkbox contains informations (prices and taxes)
    eval("var pricedata = " + $(".rdoprice input:checked").attr("value"));

    if(oldLimit == -102365)
    {
        oldLimit = pricedata[1];

        if (!$("#ctl00_cphMain_ucForm_divCongres").is(":visible"))
        {
            $(".chkevents input").attr("checked", false);
        }
    }
    else if (oldLimit != pricedata[1])
    {
        oldLimit = pricedata[1];
        $(".chkevents input").attr("checked", false);
        $('input[name*=chkEvents]').die();
    }

    if (ClassType != pricedata[5])
    {
        ClassType = pricedata[5];
        changeClassType();
    }

    var subtotal = 0;

    //If series
    if (pricedata[1] >= 999) 
    {
        if (!$("#ctl00_cphMain_ucForm__pnlSplitEvent").is(":visible")) 
        {
            $(".chkevents input").attr("disabled", true);
            $(".chkevents input").attr("checked", true);
        }

        var subtotal = Number(pricedata[0].replace(',', '.'));
    }
    else {
        $(".chkevents input").attr("disabled", false);
        $(".cost").html("0.00");

        //if static price no matter how many events we pick

        if (pricedata[1] == -1) 
         {
             var subtotal = Number(pricedata[0].replace(',', '.'));

             $('#ctl00_cphMain_ucForm_divCongres .chkevents input:checkbox').each(function () {
                 //--------------------------------------------------------------------------------------------------------------------------------------
                 if (this.id.toString() == 'ctl00_cphMain_ucForm_chkEventsCongres_0' && this.checked) {
                     $('#ctl00_cphMain_ucForm_chkEventsCongres_1').attr("disabled", true);
                     $('#ctl00_cphMain_ucForm_chkEventsCongres_2').attr("disabled", true);
                     $('#ctl00_cphMain_ucForm_chkEventsCongres_3').attr("disabled", true);

                     $('#ctl00_cphMain_ucForm_chkEventsCongres_1').attr('checked', true);
                     $('#ctl00_cphMain_ucForm_chkEventsCongres_2').attr('checked', true);
                     $('#ctl00_cphMain_ucForm_chkEventsCongres_3').attr('checked', true);

                     $('#chkEventsCongres_1').attr('enabled', 'disabled');
                     $('#chkEventsCongres_2').attr('enabled', 'disabled');
                     $('#chkEventsCongres_3').attr('enabled', 'disabled');
                     chkBoxLocked = true;
                 }
                 else if (this.id.toString() == 'ctl00_cphMain_ucForm_chkEventsCongres_0' && chkBoxLocked == true) {
                     $('#chkEventsCongres_1').attr('enabled', 'enabled');
                     $('#chkEventsCongres_2').attr('enabled', 'enabled');
                     $('#chkEventsCongres_3').attr('enabled', 'enabled');

                     $('#ctl00_cphMain_ucForm_chkEventsCongres_1').attr('checked', false);
                     $('#ctl00_cphMain_ucForm_chkEventsCongres_2').attr('checked', false);
                     $('#ctl00_cphMain_ucForm_chkEventsCongres_3').attr('checked', false);
                     chkBoxLocked = false;
                 }

                 if ($(this).parent().attr("enabled") == "disabled") {
                     $(this).attr("disabled", true);
                 }
                 //--------------------------------------------------------------------------------------------------------------------------------------

                 if (this.checked && !this.disabled) {
                     eval("var eventPrice = " + $("#chkEventsCongres_" + this.id.toString().substring(38, 39)).attr("hiddenValue"));
                     subtotal += Number(eventPrice[0].replace(',', '.'));
                 }
             });

             //$("#ctl00_cphMain_ucForm_divCongres .chkevents input:checked").length;

         }
        //else, each events cost X amount with a fixed price
        else if (pricedata[1] == -10)
        {
               LimitCheckboxes('input[name*=chkEvents]', 10);
               var subtotal = Number(pricedata[0].replace(',', '.'));
        }
        //else, each events cost X amount with a limit
        else if ($(".chkevents input:checked").length < pricedata[1] && pricedata[1] != 0)
        {
            LimitCheckboxes('input[name*=chkEvents]', pricedata[1]);
            var subtotal = Number(pricedata[0].replace(',', '.') * $(".chkevents input:checked").length);
        }
        //else, each events cost X amount
        else { var subtotal = Number(pricedata[0].replace(',', '.') * $(".chkevents input:checked").length); }
    }

    var tps = Number(pricedata[2]) / 100;
    var tvq = Number(pricedata[3]) / 100;
    var total = 0;
    var taxes = 0;
    if (tps > 0) { taxes = subtotal * tps; }
    if (tvq > 0) { taxes += (subtotal + taxes) * tvq; }

    subtotal = subtotal.toFixed(2);
    taxes = taxes.toFixed(2);
    total = parseFloat(parseFloat(subtotal) + parseFloat(taxes));
    total = total.toFixed(2);

    $(".total-subtotal").html(subtotal);
    $(".total-taxes").html(taxes);
    $(".total-total").html(total);

    $("#ctl00_cphMain_ucForm_hiddenPriceId").val(pricedata[4]);
    $("#ctl00_cphMain_FormMember_hiddenPriceId").val(pricedata[4]);
    $(".prettyme").button("refresh");
}

$(window).load(function () 
{
    if ($(".PrintSource").html() != null) {
        var winH = $(window).height();
        var winW = $(window).width();

        if ($(".modal").html() != null) {
            $('.modal').clone().appendTo('#divNewPopup');
            $('.modal').hide();

            $('#divNewPopup .modal').show();
        }
        else if ($(".modalwarning").html() != null) {
            $('.modalwarning').clone().appendTo('#divNewPopup');
            $('.modalwarning').hide();

            $('#divNewPopup .modalwarning').show();
        }

        //Set the popup window to center
        $(".popup").css('top', winH / 2 - $(".popup").height() / 2);
        $(".popup").css('left', winW / 2 - $(".popup").width() / 2);

        $(".modalmask").css('filter', 'alpha(opacity=60)');
        $('#divNewPopupModalMask').css({ 'width': $(window).width(), 'height': $(document).height() });

        $(".modalmask").fadeIn("slow");
        $(".popup").fadeIn("slow");
    }
});

function updateFileLabel(ReceivedID) 
{
    var IDNumber = ReceivedID;
    var lblID = "#ctl00_cphMain_lblFile"+IDNumber;
    var UploadFileID = "#ctl00_cphMain_uploadFile" + IDNumber;



    if ($(UploadFileID).val() == "") 
    {
        $(lblID).html("Aucun fichier selectionné");
    }
    else 
    {
        if ($(UploadFileID).val().indexOf('fakepath') != -1) {
            $(lblID).html($(UploadFileID).val().substring(($(UploadFileID).val().indexOf('fakepath') + 9), $(UploadFileID).val().length));
        }
        else {
            $(lblID).html($(UploadFileID).val());
        }
    }
}

function openFileUpload(ReceivedID)
 {
    if(!$.browser.msie && !$.browser.mozilla)
    {
        var IDNumber = ReceivedID;
        var UploadFileID = "#ctl00_cphMain_uploadFile" + IDNumber;
        $(UploadFileID).click();
        return false;
    }
}

function ClearUploadedFiles() {
    $elem = $("#ctl00_cphMain_uploadFile1");
    $elem.replaceWith($elem.clone(true));
    updateFileLabel(1) 

    $elem = $("#ctl00_cphMain_uploadFile2");
    $elem.replaceWith($elem.clone(true));
    updateFileLabel(2) 

    $elem = $("#ctl00_cphMain_uploadFile3");
    $elem.replaceWith($elem.clone(true));
    updateFileLabel(3) 

    $elem = $("#ctl00_cphMain_uploadFile4");
    $elem.replaceWith($elem.clone(true));
    updateFileLabel(4) 

    $elem = $("#ctl00_cphMain_uploadFile5");
    $elem.replaceWith($elem.clone(true));
    updateFileLabel(5) 
    return false;
}


