﻿$(document).ready(function(){
    tyreSearch(); 
});


// INITIALISING 
function tyreSearch() {
    $("#tyreSearchFields").html('<span id="loading"> </span>');  
    var language = $("input[name='language']").val();   
    $.post('tyreSearch.php', {
        action: 'initialise',
        lang: language
    }, function(data) {
        $("#tyreSearchFields").html(data);    
    tyreWidth(); 
    tyreRatio();
    tyreDiameter(); 
   /* tyreSpeed();        */
    });          
}


// STEP 1 - WIDTH
function tyreWidth() {
  $('#tyreSearchWidth').change(
   function() {
    var language = $("input[name='language']").val();    
    $.post('tyreSearch.php', {
        width: $('#tyreSearchWidth').val(),
        lang: language,        
        action: 'width'
    }, function(data) {
        $("#tyreSearchImg").css('background-position','0 -125px');
        $("#tyreSearch form label").removeClass('searchThis');
        $("#tyreSearchRatio + label").addClass('searchThis');
        $("#tyreSearchRatio").html(data);   
        $("#tyreSearchRatio").removeAttr("disabled");
    }); 	 
    });
}

// STEP 2 - RATIO
function tyreRatio() {
  $('#tyreSearchRatio').change(
   function() {
    var language = $("input[name='language']").val();    
    $.post('tyreSearch.php', {
        width: $('#tyreSearchWidth').val(),
        ratio: $('#tyreSearchRatio').val(),
        lang: language,         
        action: 'ratio'
    }, function(data) {
        $("#tyreSearchImg").css('background-position','0 -250px');   
        $("#tyreSearch form label").removeClass('searchThis');
        $("#tyreSearchDiameter + label").addClass('searchThis');
        $("#tyreSearchDiameter").html(data);   
        $("#tyreSearchDiameter").removeAttr("disabled");
    }); 	 
    });
}


// STEP 3 - DIAMETER
function tyreDiameter() {
    var language = $("input[name='language']").val(); 
  $('#tyreSearchDiameter').change(
   function() {
    $.post('tyreSearch.php', {
        width: $('#tyreSearchWidth').val(),
        ratio: $('#tyreSearchRatio').val(),    
        diameter: $('#tyreSearchDiameter').val(),
        lang: language,        
        action: 'diameter'
    }, function(data) {
        $("#tyreSearch form label").removeClass('searchThis');    
        $("#tyreSubmit").attr('src','includes/languages/english/images/buttons/button_search_blue.png');

/* not used          
        $("#tyreSearchImg").css('background-position','0 -375px'); 
        $("#tyreSearchSpeed + label").addClass('searchThis');
        $("#tyreSearchSpeed").html(data);   
        $("#tyreSearchSpeed").removeAttr("disabled");
*/        
    }); 	 
    });
}


// STEP 4 - SPEED
/* not used 
function tyreSpeed() {
  $('#tyreSearchSpeed').change(
   function() {  
        $("#tyreSearch form label").removeClass('searchThis');
        $("#tyreSubmit").attr('src','includes/languages/english/images/buttons/button_search_blue.png');
    });
}
*/



