$(document).ready(function(){fnInitializeTyreFinders();var A=(typeof(varwidth)=="undefined")?"Width is required":varwidth;var C=(typeof(varprofile)=="undefined")?"Profile is required":varprofile;var D=(typeof(varrim)=="undefined")?"Rim is required":varrim;var B=(typeof(varspeed)=="undefined")?"Speed is required":varspeed;$("form.mini-tyre-finder").validate({errorContainer:"#minifinder-invalidsearch",errorLabelContainer:"#minifinder-invalidsearch ul",wrapper:"li",errorClass:"invalid",rules:{width:{required:true},profile:{required:true},rim:{required:true},speed:{required:true}},messages:{width:{required:A},profile:{required:C},rim:{required:D},speed:{required:B}}})});function fnBindTyreFinderEvents(){$("div.smartfinder .finder-width").change(fnWidthChangeEvent);$("div.smartfinder .finder-profile").change(fnProfileChangeEvent);$("div.smartfinder .finder-rim").change(fnRimChangeEvent)}function fnInitializeTyreFinders(){fnBindTyreFinderEvents();InitControls()}function InitControls(){$("div.smartfinder").each(function(){DisableEnableControls(this)})}function PrePopulate(){$("div.smartfinder .finder-width").each(function(){$(this).trigger("change")});$("div.smartfinder .finder-profile").each(function(){$(this).trigger("change")});$("div.smartfinder .finder-rim").each(function(){$(this).trigger("change")})}function DisableEnableControls(D){var E=$("select.finder-width",D);var C=$("select.finder-profile",D);var F=$("select.finder-rim",D);var B=$("select.finder-speed-index",D);var A=$("select.finder-load-rating",D);if(E==null||E.val()==null||E.val()==""){DisableandClear(C)}else{Enable(C)}if(C==null||C.val()==null||C.val()==""){DisableandClear(F)}else{Enable(F)}if(F==null||F.val()==null||F.val()==""){DisableandClear(B);DisableandClear(A)}else{Enable(B);Enable(A)}}function DisableandClear(A){if(A!=null){A.attr("disabled","true");A.val("")}}function Enable(A){if(A!=null){A.removeAttr("disabled")}}function fnClearControlValues(D,C){var E=$("select.finder-profile",D);var F=$("select.finder-rim",D);var B=$("select.finder-speed-index",D);var A=$("select.finder-load-rating",D);switch(C){case"width":E.val("");fnClearSelectionOptions(E.get(0));DisableandClear(F);DisableandClear(B);DisableandClear(A);break;case"profile":F.val("");fnClearSelectionOptions(F.get(0));DisableandClear(B);DisableandClear(A);break;case"rim":DisableandClear(B);DisableandClear(A);break}}function fnWidthChangeEvent(){var A=$(this).val();var B=$(this).parents("div.smartfinder").get(0);var D=$("select.finder-profile",B);var E=$("select.finder-rim",B);var F=$("#deloption",B).val();var C="0";if(F==1){C=1}fnClearControlValues(B,"width");SetProfileControl(A,D,C,B)}function fnProfileChangeEvent(){var F=$(this).val();var C=$(this).parents("div.smartfinder").get(0);var B=$("select.finder-width",C).val();var E=$("select.finder-rim",C);var A=$("#deloption",C).val();var D="0";if(A==1){D=1}fnClearControlValues(C,"profile");SetRimControl(B,F,E,D,C)}function fnRimChangeEvent(){var E=$(this).val();var F=$(this).parents("div.smartfinder").get(0);var A=$("select.finder-width",F).val();var G=$("select.finder-profile",F).val();var C=$("select.finder-speed-index");var B=$("select.finder-load-rating");var D=$("#deloption",F).val();var H="0";if(D==1){H=1}fnClearControlValues(F,"rim");SetSpeedControl(A,E,G,C,H,F);SetLoadControl(A,E,G,C.val(),B,H,F)}function fnClearSelectionOptions(B){if(B!=null&&B.options!=null&&B.options.length>0){for(var A=B.options.length;A>0;A--){B.options[A-1]=null}}}function SetProfileControl(A,D,C,B){if((A!=null)&&(A!="")){D.addClass("loading");$.ajax({type:"POST",url:"/Order/Tyres/GetSmartFinder/profile",data:{width:A,delivery:C,findercontrolid:D.attr("id"),classname:D.attr("class")},success:function(E){D.html(E);DisableEnableControls(B)}});D.removeClass("loading")}else{DisableEnableControls(B)}}function SetRimControl(A,E,D,C,B){if((A!=null)&&(A!="")&&(E!=null)&&(E!="")){D.addClass("loading");$.ajax({type:"POST",url:"/Order/Tyres/GetSmartFinder/rim",data:{width:A,profile:E,delivery:C,findercontrolid:D.attr("id"),classname:D.attr("class")},success:function(F){D.html(F);DisableEnableControls(B)}});D.removeClass("loading")}else{DisableEnableControls(B)}}function SetSpeedControl(B,E,F,A,D,C){if((B!=null)&&(B!="")&&(E!=null)&&(E!="")&&(F!=null)&&(F!="")){A.addClass("loading");$.ajax({type:"POST",url:"/Order/Tyres/GetSmartFinder/speed",data:{width:B,profile:F,rim:E,delivery:D,findercontrolid:A.attr("id"),classname:A.attr("class")},success:function(G){A.html(G);DisableEnableControls(C)}});A.removeClass("loading")}else{DisableEnableControls(C)}}function SetLoadControl(B,F,G,A,E,D,C){if((B!=null)&&(B!="")&&(F!=null)&&(F!="")&&(G!=null)&&(G!="")){E.addClass("loading");$.ajax({type:"POST",url:"/Order/Tyres/GetSmartFinder/loadrating",data:{width:B,profile:G,rim:F,speed:A,delivery:D,findercontrolid:E.attr("id"),classname:E.attr("class")},success:function(H){E.html(H);DisableEnableControls(C)}});E.removeClass("loading")}else{DisableEnableControls(C)}}function fnSpeedChangeEvent(){};
