var ajaxReg = {}, countryFields = {'country': '', 'zipcode': '', 'city': '', 'street': '', 'ship_country': '', 'ship_zipcode': '', 'ship_city': '', 'ship_street': ''}, countryDatas = {'zipcodes': {}, 'streets': {}, 'ship_zipcodes': {}, 'ship_streets': {}}; $(document).ready(function () { setCountryField(); /* szamlazos resz */ getCountryData(''); vatnumberCheckByCountry(); $('#country').on('change select', function () { getCountryData(''); vatnumberCheckByCountry(); }); $('.autocomplete-area ul').on('click', 'li', function () { var li = $(this), parent = $(this).parents('.form-group').find('.autocomplete'); if (li.data('zip')) { parent.val(li.data('zip')); getCountryData(''); } if (li.data('street')) { parent.val(li.data('street')+' ').focus(); } if (parent.attr('id') == 'zipcode') { $('#city').val(li.data('city')); } $('.autocomplete-area').addClass('hide'); $('.backdrop').hide(); }); /*$('#street_auto ul').on('click', 'li', function () { var li = $(this); $('#street').val(li.data('street')); $('#street_auto').addClass('hide'); getCountryData(''); });*/ $('.backdrop').click(function () { $(this).hide(); $('.autocomplete-area').addClass('hide'); }); /* szallitasi resz */ getCountryData('ship_'); $('#ship_country').on('change select', function () { getCountryData('ship_'); }); $('#ship_zipcode_auto ul').on('click', 'li', function () { var li = $(this), parent = $(this).parents('.form-group').find('.autocomplete'); if (li.data('zip')) { parent.val(li.data('zip')); getCountryData('ship_'); } if (li.data('street')) { parent.val(li.data('street')+' ').focus(); } if (parent.attr('id') == 'ship_zipcode') { $('#ship_city').val(li.data('city')); } /*$('#ship_zipcode').val(li.data('zip')); $('#ship_city').val(li.data('city'));*/ }); /*$('#ship_street_auto ul').on('click', 'li', function () { var li = $(this); $('#ship_street').val(li.data('street')); });*/ $('.autocomplete').focusin(function () { if ($(this).parent().find('ul li').length > 0) { $(this).addClass('focus'); $(this).parent().find('.scrollbar').removeClass('hide'); $('.backdrop').show(); } }).focusout(function () { $(this).removeClass('focus'); }).on('keyup', function () { var value = $(this).val().toLowerCase(); $(this).parents('.form-group').find('.autocomplete-area ul li').each(function (i, v) { if ($(v).text().toLowerCase().match("^" + value + "")) { $(v).show(); } else { $(v).hide(); } /*if ($(v).text().toLowerCase().search(value) > -1) { $(v).show(); } else { $(v).hide(); }*/ }); }); /* $('input[name="registrationSubmit"]').on('click',function(){ var regBtn = $(this); regBtn.prop('disabled',true); setTimeout(function(){ regBtn.prop('disabled', false); }, 3000); }); */ }); function getCountryData(before) { var newC = getFieldValue(before + 'country'); if (newC != countryFields[before + 'country']) { countryFields[before + 'country'] = newC; ajaxLoader('show'); if (ajaxReg[before + 'getZipcode'] != undefined) ajaxReg[before + 'getZipcode'].abort(); ajaxReg[before + 'getZipcode'] = $.ajax({ url: 'inc/ajax/index.php', type: 'post', data: 'getZipcodeByCountry=1&country=' + countryFields[before + 'country'], dataType: 'json', success: function (ret) { countryDatas[before + 'zipcodes'] = ret.zipcodes; /* lista letrehozasa */ var ziplist = ''; $.each(countryDatas[before + 'zipcodes'], function (zipid, city) { var zipdata = zipid.split('|'); ziplist += '
  • ' + zipdata[0] + ' (' + city + ')
  • '; }); $('#' + before + 'zipcode_auto ul').html(ziplist); /* aktualis ertek ellenorzese */ var ok = false; $.each(countryDatas[before + 'zipcodes'], function (zipid, city) { var zipdata = zipid.split('|'); if ((countryFields[before + 'zipcode']*1)==(zipdata[0]*1)) ok = true; }); if (ok==false) { $('#' + before + 'zipcode, #' + before + 'city, #' + before + 'street').val(''); } /* if (countryDatas[before + 'zipcodes'][countryFields[before + 'zipcode']] == undefined) { $('#' + before + 'zipcode, #' + before + 'city, #' + before + 'street').val(''); }*/ ajaxLoader('hide'); } }); } var newZ = getFieldValue(before + 'zipcode'); if (newZ != countryFields[before + 'zipcode']) { countryFields[before + 'zipcode'] = newZ; ajaxLoader('show'); if (ajaxReg[before + 'getStreet'] != undefined) ajaxReg[before + 'getStreet'].abort(); ajaxReg[before + 'getStreet'] = $.ajax({ url: 'inc/ajax/index.php', type: 'post', data: 'getStreetByZipcode=1&country=' + countryFields[before + 'country'] + '&zipcode=' + countryFields[before + 'zipcode'], dataType: 'json', success: function (ret) { countryDatas[before + 'streets'] = ret.streets; /* lista letrehozasa */ var streetlist = ''; $.each(countryDatas[before + 'streets'], function (key, street) { streetlist += '
  • ' + street + '
  • '; }); //$('#' + before + 'street_auto ul').html(streetlist); /* aktualis ertek ellenorzese */ if (countryDatas[before + 'streets'][countryFields[before + 'street']] == undefined) { $('#' + before + 'street').val(''); } ajaxLoader('hide'); } }); } } function setCountryField() { $.each(countryFields, function (id, v) { countryFields[id] = getFieldValue(id); }); } function getFieldValue(id) { if ($('#' + id).is('select')) { var val = $('#' + id + ' option:selected').val(); } else { var val = $('#' + id).val(); } return val; } function ajaxLoader(type) { if (type == 'show') { $('.ajaxLoader').stop().fadeIn('fast'); } else { $('.ajaxLoader').stop().fadeOut('fast'); } } function vatnumberCheckByCountry() { var vatnumber = $('#vatnumber'); var val = $('#country option:selected').val(); if (val==43) { vatnumber.addClass('only_number').attr('maxlength', '11'); } else { vatnumber.removeClass('only_number').attr('maxlength', '20'); } }