﻿jQuery(document).ready(function() {

    setAdhesion();
});




function setAdhesion() {
    AfficheInfoAdultes($get(GetObj('cbadultes')));

    if ($get(GetObj('ville')).value != '' && $get(GetObj('cp')).value != '')
        getVille(GetObj('cp'), 'cbvilles', $get(GetObj('ville')).value);

    jQuery('#' + GetObj('dnadulte1')).unbind('click').bind('click', (function(event) { this.select() })).bind('blur', { err: GetObj('err_dnadulte1') }, (function(event) {
        TestDate(this.id, event.data.err);
    }));
    jQuery('#' + GetObj('dnadulte2')).unbind('click').bind('click', (function(event) { this.select() })).bind('blur', { err: GetObj('err_dnadulte2') }, (function(event) {
        if (this.value != '' && this.value != 'JJ/MM/AAAA')
            TestDate(this.id, event.data.err);
    }));


    jQuery('#' + GetObj('ckiscontact')).unbind('click').bind('click', (function(event) {
        if (this.checked) {
            jQuery('#trjour').show();
            jQuery('#trheure').show();
            jQuery('#trtelephone').show();
        } else {
        jQuery('#trjour').hide();
        jQuery('#trheure').hide();
        jQuery('#trtelephone').hide();

        }

    }));




    
}

function AfficheInfoAdultes(obj) {
    switch (obj.value) {
        case '0':
            jQuery("#tradulte1").hide();
            jQuery("#tradulte2").hide();

            break;
        case '1':
            jQuery("#tradulte1").show();
            jQuery("#tradulte2").hide();

            break;
        case '2':
            jQuery("#tradulte1").show()
            jQuery("#tradulte2").show();

            break;
    }
}

function TestConformite() {
    
    var isErreur = false;
    if (!TestComboLabel(GetObj('cbcivilite'), GetObj('lcbcivilite'))) isErreur = true;
    if (!TestComboLabel(GetObj('cbsituation'), GetObj('lcbsituation'))) isErreur = true;
    if (!TestComboLabel(GetObj('cbactivites'), GetObj('lcbactivites'))) isErreur = true;
    if (!TestChaineLabel(GetObj('nom'), GetObj('lnom'))) isErreur = true;
    if (!TestChaineLabel(GetObj('prenom'), GetObj('lprenom'))) isErreur = true;
    if (!TestChaineLabel(GetObj('adresse'), GetObj('ladresse'))) isErreur = true;
    if (!TestChaineLabel(GetObj('cp'), GetObj('lcp'))) isErreur = true;
    if (!TestChaineLabel(GetObj('ville'), GetObj('lville'))) isErreur = true;
    

    if (!TestTelephone(GetObj('telephone'), GetObj('ltelephone'), 'err_telephone')) isErreur = true;
    if (!TestTelephone(GetObj('portable'), GetObj('lportable'), 'err_portable')) isErreur = true;

    if (TestTelephone(GetObj('telephone'), GetObj('ltelephone'), 'err_telephone') && TestTelephone(GetObj('portable'), GetObj('lportable'), 'err_portable')) {
        if ($get(GetObj('telephone')).value == '' && $get(GetObj('portable')).value == '') {
            jQuery("#" + GetObj('ltelephone')).addClass('erreur');
            isErreur = true;
        }
    } else
        isPageErreur = true;
    
    
    
    
    if (!TestComboLabel(GetObj('cbadultes'), GetObj('lcbadultes'))) isErreur = true;
    if (!TestComboLabel(GetObj('cbgaranties'), GetObj('lcbgaranties'))) isErreur = true;
    if (!TestComboLabel(GetObj('cborigines'), GetObj('lcborigines'))) isErreur = true;
    if (!TestChaineLabel(GetObj('captcha'), GetObj('lcaptcha'))) isErreur = true;
    if (!CheckConcordanceEmail(GetObj('email'), GetObj('email1'), GetObj('lemail'), GetObj('lemail1'))) isErreur = true;
    if ($get(GetObj('ckiscontact')).checked) {
        if (!TestComboLabel(GetObj('cbjour'), GetObj('lcbjour'))) isErreur = true;
        if (!TestComboLabel(GetObj('cbheure'), GetObj('lcbheure'))) isErreur = true;
        if (!TestTelephone(GetObj('telephonecontact'), GetObj('ltelephonecontact'), 'err_ltelephonecontact')) isErreur = true;
        if ($get(GetObj('telephonecontact')).value == '') {
            jQuery("#" + GetObj('ltelephonecontact')).addClass('erreur');
            isErreur = true;
        }
    }


    if (!isErreur) {
        $get(GetObj('BtnAdhesion')).click();
        return true;
    }
    return false;
}        
