jQuery(document).ready(function () {
    comboJquery('#C_CN', '#L_CN', '#RefCountry');
    comboJquery('#C_LS', '#L_LS', '#RefLangue');
    comboJquery('#C_Day', '#L_Day', '#RefDay');
    comboJquery('#C_Month', '#L_Month', '#RefMonth');
    comboJquery('#C_Year', '#L_Year', '#RefYear');
    comboJquery('#C_BMC', '#L_BMC', '#RefBMC');
    comboJquery('#C_Ville', '#L_Ville', '#RefVILLE');
    comboJquery('#C_Devise', '#L_Devise', '#RefDevise');
    comboJquery('#C_PaymentType', '#L_PaymentType', '#RefPaymentType');
    comboJquery('#C_DeviseR', '#L_DeviseR', '#RefDeviseR');
    comboJquery('#C_Type', '#L_Type', '#RefType');
    comboJquery('#C_Pays', '#L_Pays', '#RefPays');
    comboJquery('#C_Benif', '#L_Benif', '#RefBenif');
    comboJquery('#C_PayMeth', '#L_PayMeth', '#RefPayMeth');
    comboJquery('#C_Object', '#L_Object', '#RefObject');
    comboJquery('#C_Sim', '#L_Sim', '#RefSim');
    Checkbox('.C_GEN');
    Radiobox('#GroupRadio a');
    miniTabs('#BlocInfo');
    Radiobox_T2('#R_STATUS > a');
    Radiobox_T2('#C_BQ > a');
    Radiobox_T2('#P_BQ > a');
    Slide();
    AnimateBGAcc();
    initComboJquery();
    DiapoGG();
});

function DiapoGG() {
    $('.E_GU').bind('click', function () {
        $(this).parent().find('.E_GU').removeClass('CurrentSel');
        $('#BI_1').hide();
        $('#BI_2').fadeIn('pretty');
        
        var index = $(this).index();
        $(this).addClass('CurrentSel');
    });
}

function AnimateBGAcc() {
    $("#NavHome a").live("click", function () {
        var Href = $(this).attr("href").substr(1, $(this).attr("href").length - 1);
        $("#ImgChange img").hide();
        setTimeout(function () {
            if ($.browser.msie) $("#imgGD_" + Href).show();
            else $("#imgGD_" + Href).fadeIn("slow");
        }, 1200);

    });
}
/* combobox Jquery */
function comboJquery(IdCombo, IdList, IdRef) {
    $(IdCombo).live("click", function () {
        if (!$(this).hasClass('disabled')) {
            $Parent = $(this).parent();

            if ($.browser.msie && $.browser.version == "6.0") {
                $Parent.removeClass('Type2c');
                $Parent.addClass('CurrentType2c');
            }
            else {
                $Parent.toggleClass('Current');
            }
            $(IdList).slideToggle(100);
        }
    });
    $(IdList + " > li").live("click", function () {
        $Parent = $(this).parent().parent();
        $(IdRef).attr("value", $(this).attr("id"));
        $(IdList).slideUp(100);

        if ($.browser.msie && $.browser.version == "6.0") {

            $Parent.removeClass('CurrentType2c');
            $Parent.addClass('Type2c');
        }
        else {
            $Parent.removeClass('Current');
        }
        $(IdCombo).find('.C_C').html($(this).find('a').html());
    });
}

/* combobox Jquery nit */
function initComboJquery() {
    $('body').bind('click', function (e) {
        if (!$(e.target).parent().hasClass('clickC')) {
            if ($.browser.msie && $.browser.version == "6.0") {
                $Parent.removeClass('CurrentType2c');
                $Parent.addClass('Type2c');
                $('.L_CMB').slideUp('fast');
            }
            else {
                $('.Combo').removeClass('Current');
                $('.L_CMB').slideUp('fast');
            }
        }
    });
}

var toHeight = 0;
var isFinish = true;
function comboJquery2(IdCombo, IdList, IdRef) {
    $(IdCombo).live("click", function () {
        $Parent = $(this).parent();
        $Parent.toggleClass('Current2');

        if (isFinish && $(IdList).css("display") == "none")
            comboJquery2Show(IdList);
        else if (isFinish && $(IdList).css("display") != "none")
            comboJquery2Hide(IdList);
    });
    $(IdList + " > li").live("click", function () {
        $(IdRef).attr("value", $(this).attr("id"));

        comboJquery2Hide(IdList);

        $Parent.removeClass('Current2');
        $(IdCombo).find('.C_C').html($(this).find('a').html());
    });
}

function comboJquery2Show(IdList) {
    $(IdList).parent().css("z-index", "8");
    toHeight = $(IdList).height();
    $(IdList).css("height", "0px");
    $(IdList).css("top", "-8px");
    $(IdList).show();
    isFinish = false;

    $(IdList).animate({
        height: toHeight,
        top: '-' + (toHeight + 8)
    }, 150, function () { isFinish = true; });
}

function comboJquery2Hide(IdList) {
    isFinish = false;
    $(IdList).animate({
        height: 0,
        top: '-8px'
    }, 150, function () {
        $(IdList).hide();
        $(IdList).css("height", toHeight + "px");
        $(IdList).parent().css("z-index", "1");
        isFinish = true;
    });
}
/* checkbox */
function Checkbox(tagName) {
    $(tagName).live("click", function () {
        $(this).parent().toggleClass('Active');
    });

}
/* radio box */
function Radiobox(tagName) {
    $(tagName).live("click", function () {
        if (!$(this).parent().hasClass('disabled')) {
            $(tagName).removeClass('active');
            $(this).addClass('active');
            $(this).parent().find('input[type="hidden"]').val($(this).attr('name'));
        }
    });
}
/* radio box type 2 */
function Radiobox_T2(tagName) {
    $(tagName).live("click", function () {
        if (!$(this).parent().hasClass("inactif")) {
            $(tagName).removeClass('CUR').parent().find('div').children('a').children('span').removeClass('CUR');
            $(this).addClass('CUR');
            if ($(this).nextAll('a')[0]) $(this).parent().find('div').children('a').children('span').eq(0).addClass('CUR');
            else $(this).parent().find('div').children('a').children('span').eq(1).addClass('CUR');
        }
    });
    $('.RadioActive > div').bind('click', function () {
        if (!$(this).parent().hasClass("inactif"))
            $(this).parent().children('a').toggleClass('CUR').closest('.RadioActive').find('div').children('a').children('span').toggleClass('CUR');
    });
}
/* next etape */
function nextTape(id) {
    $('[id^=B_]').children("a").removeClass('Active');
    $('.AlertError').removeClass('activedAlertError');
    $('[class^=Bloc]').hide();
    $('#B_' + id).children('a').addClass('Active');
    $('.Bloc' + id + '>.AlertError').addClass('activedAlertError');
    $('.Bloc' + id).show();
    var o = $('.Bloc' + id).find('input:text,input:password,input:hidden').eq(0);
    if ($(o).attr('type') == 'hidden') {
        //alert();
        $(o).nextAll('a').eq(0).focus();
    }
    else
        $(o).focus();
    //$('.Bloc' + id).find('input:text,input:password').eq(0).blur();
}
/* mini tabs */
function miniTabs(bloc) {
    $('#NavTabs a').live('click', function () {
        if (!$(this).hasClass('Active')) {
            id = $(this).attr('id').substr($(this).attr('id').length - 1, 1);
            blocEx = bloc.substr(1);
            $('[id^=' + blocEx + ']:not([id^=' + blocEx + ']:first)').hide();
            $(bloc + id).fadeIn('pretty');
            $('#NavTabs a').removeClass('Active');
            $(this).addClass('Active');
        }
    });
}
/* Slide*/
function Slide() {
    $('.BandeSlide .V_DETAIL').live('click', function () {
        var $NivP = $(this).closest('.BlocBenF');
        if ($NivP.hasClass('Current')) {
            $NivP.removeClass('Current');
            $NivP.find('.Slide').slideUp('pretty');
        }
        else {
            $('.BlocBenF').removeClass('Current');
            $('.Slide').slideUp('pretty');
            $NivP.addClass('Current');
            $NivP.find('.Slide').slideDown('pretty');
        }
    });
}
