jQuery(document).ready(function($){ $('#opentec-vinfo-reset').on('click', function() { $('#opentec-vinfo-detail').hide(); $('#opentec-vinfo-form').show(); $('#opentec-vinfo-cancel').show(); }); $('#opentec-vinfo-cancel').on('click', function() { $('#opentec-vinfo-detail').show(); $('#opentec-vinfo-form').hide(); $('#opentec-vinfo-cancel').hide(); }); $("#opentec-vinfo-type").on('change', function() { var _this = $(this); if(_this.val() !== '--- Select Type ---'){ var url="https://www.cmeparts.com/index.php?route=module/opentec/getMakes"; $('#opentec-vinfo-make').attr('disabled', 'disabled'); $('#opentec-vinfo-make').html('').append($("").text("Loading...")); var request = $.ajax({ url: url, method: "POST", data: { type: _this.val() }, dataType: "json" }); request.done(function(models) { if (models.length > 0 ){ $('#opentec-vinfo-make').html('').append($("").text("--- Select Model ---")); $.each(models, function(key, model) { $('#opentec-vinfo-make').append($("").attr("value",model.value).text(model.text)); }); $('#opentec-vinfo-make').removeAttr('disabled'); } }); request.fail(function( jqXHR, textStatus ) { alert( "Request failed: " + textStatus ); }); }else{ $('#opentec-vinfo-make').attr('disabled', 'disabled'); $('#opentec-vinfo-model').attr('disabled', 'disabled'); $('#opentec-vinfo-vehicle').attr('disabled', 'disabled'); $('#opentec-vinfo-make').html($("")); $('#opentec-vinfo-model').html($("")); $('#opentec-vinfo-vehicle').html($("")); } }); $("#opentec-vinfo-make").on('change', function() { var _this = $(this); var url="https://www.cmeparts.com/index.php?route=module/opentec/getModels"; var type = $('#opentec-vinfo-type').val(); var type_id = type == 'commercial-vehicle' ? 'O' : 'P'; $('#opentec-vinfo-submit').attr('disabled', 'disabled'); $('#opentec-vinfo-model').html('').append($("").text("Loading...")); $('#opentec-vinfo-vehicle').html('').append($("").html("⚠ Model not selected.")); var request = $.ajax({ url: url, method: "POST", data: { make_id: _this.val(),type_id: type_id }, dataType: "json" }); request.done(function(models) { if (models.length > 0 ){ $('#opentec-vinfo-model').html('').append($("").text("--- Select Model ---")); $.each(models, function(key, model) { $('#opentec-vinfo-model').append($("").attr("value",model.value).text(model.text)); }); $('#opentec-vinfo-model').removeAttr('disabled'); } else { $('#opentec-vinfo-model').html('').append($("").html("⚠ No Model Found!")); } }); request.fail(function( jqXHR, textStatus ) { alert( "Request failed: " + textStatus ); }); }); $("#opentec-vinfo-model").on('change', function() { var _this = $(this); var url="https://www.cmeparts.com/index.php?route=module/opentec/getVehicles"; var type = $('#opentec-vinfo-type').val(); var type_id = type == 'commercial-vehicle' ? 'O' : 'P'; $('#opentec-vinfo-submit').attr('disabled', 'disabled'); $('#opentec-vinfo-vehicle').html('').append($("").text("Loading...")); var request = $.ajax({ url: url, method: "POST", data: { model_id: _this.val(), make_id: $('#opentec-vinfo-make').val(),type_id: type_id }, dataType: "json" }); request.done(function(vehicles) { if (vehicles.length > 0 ){ $('#opentec-vinfo-vehicle').html('').append($("").text("--- Select Vehicle ---")); $.each(vehicles, function(key, vehicle) { $('#opentec-vinfo-vehicle').append($("").attr("value",vehicle.value).text(vehicle.text)); }); $('#opentec-vinfo-vehicle').removeAttr('disabled'); } else { $('#opentec-vinfo-vehicle').html('').append($("").html("⚠ No Vehicle Found!")); } }); request.fail(function( jqXHR, textStatus ) { alert( "Request failed: " + textStatus ); }); }); $("#opentec-vinfo-vehicle").on('change', function() { if ($(this).val() === ""){ $('#opentec-vinfo-submit').attr('disabled', 'disabled'); } else { $('#opentec-vinfo-submit').removeAttr('disabled'); } }); // VIN work start here var _modal = $('#vinModal'); var _modal_body = _modal.find('.modal-body'); var _modal_load = _modal_body.find('i.fa-spinner'); var _modal_warn = _modal_body.find('i.fa-warning'); var _modal_content = _modal_body.find('div'); function opentecVinVehicles(result) { var _table = $("
"); var _trh = $(''); _trh.append($("").text("Vehicle")); _trh.append($("").text("Fuel")); _trh.append($("").text("Year")); _trh.append($("").text("KW")); _trh.append($("").text("CCM")); _trh.append($("").text("Codes")); _trh.append($("").text("")); _table.append(_trh); $.each(result.types, function( idx, type ) { var _tr = $(""); var _td_name = $("").text(result.make + " " + result.model + " " + type.name); var _td_fuel = $("").text(type.fuel); var _td_date = $("").text(type.yearfrom + " - " + type.yearto); var _td_kw = $("").text(type.kw); var _td_ccm = $("").text(type.ccm); var _td_codes = $("").text(type.codes); var _url = $('Select') .attr('data-class', type.class) .attr('data-make', result.make) .attr('data-model', result.model) .attr('data-ktype', type.ktype) .attr('data-name', type.name); var _td_url = $("").append(_url); _tr.append(_td_name); _tr.append(_td_fuel); _tr.append(_td_date); _tr.append(_td_kw); _tr.append(_td_ccm); _tr.append(_td_codes); _tr.append(_td_url); _table.append(_tr); }); _modal_load.hide(); _modal_warn.hide(); _modal_content.html("

" + result.msg + "

"); _modal_content.append("
Please select your vehicle from below list.

"); _modal_content.append(_table); } function opentecVinModels(result) { var _select = $(""); $.each(result.models, function( idx, model ) { var _opt = $(""); _opt.text(result.make + " " + model.name); _opt.val(model.id); _select.append(_opt); }); _modal_load.hide(); _modal_warn.hide(); _modal_content.html("

" + result.msg + "

"); _modal_content.append("
Please select your model to continue.

"); _modal_content.append(_select); _modal_content.append($('')); } $("#opentec-vin-check").on('click', function(){ var vin = $("#opentec-vin").val(); if (!vin) return; var _this = $(this); var url="https://www.cmeparts.com/index.php?route=module/opentec/vin"; var backurl = $("#opentec-vinfo-backurl").val(); var vin = $("#opentec-vin").val(); var model = _modal.data('model'); _this.attr('disabled', 'disabled'); _modal_load.show(); _modal_warn.hide(); _modal_content.html("

Searching Vechicle for VIN: " + vin + "...

"); _modal.modal('show'); var request = $.ajax({ url: url, method: "GET", data: { vin: vin, model: model }, dataType: "json" }); request.done(function(result) { //console.log(result); if (result.status !== null) { if (result.status == 0) { _modal_load.hide(); _modal_warn.show(); _modal_content.html("

" + result.msg + "

"); } else if (result.status == 1) { opentecVinModels(result); } else if (result.status == 2) { opentecVinVehicles(result); } else if (result.status == 3) { _modal_load.show(); _modal_warn.hide(); _modal_content.html("

Fetching Parts Catalogue for " + result.make + " " + result.model + " " + result.vehicle + "...

"); if (backurl) { window.location.replace(backurl); } else { location.reload(); } } } else { _modal_load.hide(); _modal_warn.show(); _modal_content.html("

Unexpected error, please contact our support staff.

"); alert("Unexpected error, please contact our support staff."); } _this.removeAttr('disabled'); }); request.fail(function( jqXHR, textStatus ) { alert( "Request failed: " + textStatus ); _this.removeAttr('disabled'); }); }); $(document).on('click', "#vin-btn-model", function(){ _modal.data('model', $("#vin-sel-model").val()); $("#opentec-vin-check").trigger("click"); _modal.data('model', ""); }); $(document).on('click', ".vin-sel-vehicle", function(){ var _this = $(this); var vtype = _this.data('class'); var make = _this.data('make'); var model = _this.data('model'); var ktype = _this.data('ktype'); var vehicle = _this.data('name'); var vin = $("#opentec-vin").val(); var url="https://www.cmeparts.com/index.php?route=module/opentec/vinktype"; var backurl = $("#opentec-vinfo-backurl").val(); _modal_load.show(); _modal_warn.hide(); _modal_content.html("

Fetching Parts Catalogue for " + make + " " + model + " " + vehicle + "...

"); var request = $.ajax({ url: url, method: "GET", data: { ktype: ktype, vtype: vtype}, dataType: "html" }); request.done(function(ktype) { if (ktype > 0){ if (backurl) { window.location.replace(backurl); } else { location.reload(); } } else { _modal_content.html("

No Vehicle Found for Vin: " + vin + "

"); } }); request.fail(function( jqXHR, textStatus ) { alert( "Request failed: " + textStatus ); _this.removeAttr('disabled'); }); }); // VIN work ends here $('#ask-price-form').on('submit',function(){ $('#price-quote-submit').attr('disabled','disabled'); var qty = parseFloat($('#price-quote-qty').val()); var name = $('#price-quote-fullname').val(); var phone = $('#price-quote-phone').val(); var email = $('#price-quote-email').val(); if(qty.length == 0 || isNaN(qty)){ alert('Please insert valid quantity'); $('#price-quote-submit').removeAttr('disabled'); return false; }else if(name.length == 0){ alert('Please insert your name'); $('#price-quote-submit').removeAttr('disabled'); return false; }else if(phone.length == 0){ alert('Please insert your contact number'); $('#price-quote-submit').removeAttr('disabled'); return false; }else if(email.length == 0 || !validateEmail(email)){ alert('Please insert valid email'); $('#price-quote-submit').removeAttr('disabled'); return false; }else{ var _this = $(this); var url="index.php?route=opentec/contact"; var vin = _this.find('#price-quote-vin').val(); var brand_name = _this.find('#price-quote-brand_name').val(); var part_number = _this.find('#price-quote-part_number').val(); var qty = _this.find('#price-quote-qty').val(); var product = _this.find('#price-quote-product').val(); var fullname = _this.find('#price-quote-fullname').val(); var phone = _this.find('#price-quote-phone').val(); var email = _this.find('#price-quote-email').val(); var comment = _this.find('#price-quote-comment').val(); var request = $.ajax({ url: url, method: "POST", data: { vin:vin,brand_name:brand_name,part_number:part_number,qty:qty,product:product,fullname:fullname,phone:phone,email:email,comment:comment } }); request.done(function(models) { alert('We\'ve received your email and will get back to you.'); $('#askprice .close').trigger('click'); return false; }); request.fail(function( jqXHR, textStatus ) { alert('Sorry try again !!!'); $('#askprice .close').trigger('click'); $('#price-quote-submit').removeAttr('disabled'); return false; }); return false; } }); function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } $('.layer-category').on('click','.cart.askprice .btn',function(){ var brand = $(this).data('brand'); var part = $(this).data('part'); var product = $(this).data('product'); $('#askprice').find('#price-quote-brand_name').val(brand); $('#askprice').find('#price-quote-part_number').val(part); $('#askprice').find('#price-quote-product').val(product); }); $('#agree-terms').click(function(){ $('#button-payment-method').trigger('click'); }); $('#notagree-terms').click(function(){ $('#modal-agree').hide(); }); $('#opentec-reset-vehicle').on('click',function(){ var route = getUrlVars()['route']; var request = $.ajax({ url: 'index.php?route=module/opentec/clearKtype', method: "POST" }); if(route == 'common/home'){ request.done(function(){ window.location.href = 'index.php?route=common/home'; }); }else{ request.done(function(){ window.location.href = 'index.php?route=product/category&path=59'; }); } }); function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; } });