// ----------------------------------
//    contact
// ----------------------------------

function switchTab(step) {
    var nbSteps = 3;
    var form = $('frmContact');
    var btnReturn = $('actionReturn');
    var btnSubmit = $('actionSubmit');
    var btnContinue = $('actionContinue');

    // on recup l'étape courante
    var currentStep = form.getElements('div.step-active')[0].getProperty('id').replace('Step', '').toInt();
    var stepValidation = false;

    var validationStep = 0;
    var gotoStep = 0;

    if(step == 'continue') {
        validationStep = currentStep;
        gotoStep = currentStep + 1;
    } else if(step == 'return') {
        validationStep = currentStep - 1;
        gotoStep = currentStep - 1;
    } else if(step == 'index') {
        validationStep = 0;
        gotoStep = $('step').getValue();
    } else {
        validationStep = currentStep;
        gotoStep = 0;
    }

    if (validationStep == 1) {
        stepValidation = validateStep('frmContact', 'Step1');
    } else if (validationStep == 2) {
        stepValidation = validateStep('frmContact', 'Step2');
    } else if (validationStep == 3) {
        stepValidation = validateStep('frmContact', 'Step3');
    } else {
        stepValidation = true;
    }





    if (step == 'submit' && stepValidation) {
        $E('form[name=frmContact]').submit();
        return;
    }

    if (stepValidation) {
        for (var i = 1; i <= nbSteps ; i++) {
            if (i ==  gotoStep) {
                $('tab-Step'+ i).setProperty('class', 'step'+ i +'-active');
                $('Step'+ i).setProperty('class', 'step-active');
            } else {
                $('tab-Step'+ i).setProperty('class', 'step'+ i);
                $('Step'+ i).setProperty('class', 'step');
            }
        }

        if (gotoStep == 1 ) {
            btnReturn.addClass('hidden');
            btnContinue.removeClass('hidden');
            btnSubmit.addClass('hidden');
        } else if (gotoStep == 2) {
            btnReturn.removeClass('hidden');
            btnContinue.removeClass('hidden');
            btnSubmit.addClass('hidden');
        } else if (gotoStep == 3) {
            btnReturn.removeClass('hidden');
            btnContinue.addClass('hidden');
            btnSubmit.removeClass('hidden');
        }
    }
}

window.addEvent('domready', function() {
    if($('step').getValue() != '') switchTab('index');
});

