/******************   global variable declaration,  begin *****************/
var formStatus = new FormStatus();
/******************   global variable declaration,  end *******************/

/******************   class declaration,  begin *****************/
function FormStatus()
{
    this.currentStep = 1;
}
/******************   class declaration,  end *******************/

/***** init section, begin *****/
$(document).ready(
    function() {
        valuationFormInit();
    }
);




function valuationFormInit()
{
    valuationFormBindEvents();

    //for debug steps
    formStatus.currentStep = 1;
    switchStep(formStatus.currentStep);
}

function valuationFormBindEvents()
{
    $("#step_form_btn").bind('click', function(e) {
        var verifyFunc = "verifyStep" + formStatus.currentStep;
        if (eval(verifyFunc)()) {
            formStatus.currentStep++;
            switchStep(formStatus.currentStep);
        }
    });
}

function switchStep(theId)
{
    switch (theId) {
        case 1:
            break;
        case 2:
            goStep2();
            break;
        case 3:
            goStep3();
            break;
        case 4:
            goStep4();
            break;
        case 5:
            goStep5();
            break;
        case 6:
            goStep6();
            break;
        case 7:
            goStep7();
            break;
        default:
    }
}

function setProceeding(percent)
{
    var trgPercentImg = "50purcent.gif";
    var trgSubmitImg = "btn_jecommence.gif";
    var isSmallTemplate = false;
    isSmallTemplate = $("#eurotax_valuation_form").hasClass('small');   
    
    switch (percent) {
        case 1:
            trgPercentImg = BASE_IMAGE_URL + "50.png";
            trgSubmitImg = BASE_IMAGE_URL + "btn_jecommence.gif";
            stepImg = BASE_IMAGE_URL + "";
            $("#step_form_btn").attr("src", trgSubmitImg);               
            break;
        case 2:
            trgPercentImg = BASE_IMAGE_URL + "50.png";
            if (isSmallTemplate == true) {
                var width = 334;
                var height = 312;
                var left_img = 50;
                var top_img = 247;
                trgSubmitImg = BASE_IMAGE_URL + "btn_suivant_big.png";
                $("#percent_img").show();
            } else {
                var width = 760;
                var height = 352;
                var left_img = 610;
                var top_img = 267;
                trgSubmitImg = BASE_IMAGE_URL + "btn_suivant.png";
            }
            stepImg = BASE_IMAGE_URL + "step2.png";    
            $("#step_form_btn").attr("src", trgSubmitImg).css({"position":"relative", "top":"0px", "left":"0px"});
            $("#eurotax_valuation_step_1").hide();
            $("#numero_vert").hide();
            $("#percent_img").attr("src", trgPercentImg);
            $("#content_percent").css({"position":"absolute", "top":top_img+"px", "left":left_img+"px"});
            $("#info").css({"width":width+"px"});
            $("#eurotax_valuation_form").css({"width":width+"px", "position":"relative", "height":height+"px", "margin-left":"10px"});
            $("#eurotax_valuation_step_2").css("width",width+"px");
            $("#flash").css({"width":"237px", "padding":"20px 0 0"}).html("<img src='" + stepImg + "' alt='J&rsquo;obtiens imm&eacute;diatement une valeur estim&eacute;e de mon v&eacute;hicule.' />");
            $("#flash").hide();
            $('.showSteps').show();    
            $('.showSteps').find('li:first').show("fast", function() { $(this).next("li").show("fast", arguments.callee); }).find('div:first').addClass('active'); 
            break;
        case 3:
            trgPercentImg = BASE_IMAGE_URL + "75.png";
            $("#percent_img").attr("src", trgPercentImg);
            break;
        case 4:
            trgPercentImg = BASE_IMAGE_URL + "90.png";
            $("#percent_img").attr("src", trgPercentImg);
            break;
        case 5:
            trgPercentImg = BASE_IMAGE_URL + "100.png";
            $("#percent_img").attr("src", trgPercentImg);
            break;
        case 6:
            $("#eurotax_valuation_step_6_before li").hide();
            $("#eurotax_valuation_step_6_before li:first").stop().hide('slow').delay(2000).show('slow', function() { $(this).next("li").stop().hide('slow').delay(2000).show('slow', arguments.callee); });
            trgPercentImg = BASE_IMAGE_URL + "100.png";            
            break;
        case 7:           
            $('#help_estimate').hide();
            break;
        default:
    }
}

function showStepForm(theId, jsonData)
{
    var stepId = "eurotax_valuation_step_" + theId;
    $("div[stepTab=true]").each(function(){
        if (this.id!=stepId) {
            $('#'+this.id).hide();
        } else {
            setProceeding(theId);
            $('#'+this.id).show();
        }
    });
    
    if (typeof(omniture_s_is_enable) != 'undefined' && omniture_s_is_enable == 1) {
        ajaxCommondRepriseVar(theId-1, jsonData);
    }
}

