Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var checkedFound = false;
- var bNewCountry, bOldCountry;
- $(document).ready(function() {
- $('fieldset#address_delivery select.id_country').bind('change', function() {
- $('.countryPreloader').show();
- updateAddresses();
- });
- var value = Get_Cookie('forRedirecting');
- if (value === 'yes') {
- var date = new Date();
- date.setTime(date.getTime() + (100 * 24 * 60 * 60 * 1000));
- var expires = "expires=" + date.toGMTString();
- document.cookie = 'forRedirecting=' + "no" + ';' + expires + '; path=/';
- window.location = baseDir + "order.php/?step=2";
- }
- updateAddressesDisplay(true, '');
- $('table#carrierType input[type|="radio"]:checked').each(showShipping);
- $('table#carrierType input[type|="radio"]').bind('click', showShipping);
- if (!checkedFound) {
- fillEmptyFields();
- }
- $('#carrierType input').not('#carrierType input#id_carrier60').bind('click', function() {
- $('#shippingAddress').show();
- });
- $('#id_carrier60').bind('click', function() {
- $('#shippingAddress').hide();
- });
- $('#carrierType input').each(function() {
- if ($(this).attr("id") !== 'id_carrier60' && $(this).attr('checked')) {
- $('#shippingAddress').show();
- }
- });
- // updateAddressDisplay('delivery', true);
- });
- function swapSelectList(type) {
- var totype = type === 'delivery' ? 'invoice' : 'delivery',
- sel1 = $('select#id_address_' + type + ' option:selected'),
- sel2 = $('select#id_address_' + totype + ' option:selected');
- if (sel1.val() === sel2.val()) {
- sel2.attr('selected', false);
- if (sel2.next() === sel2) {
- sel2.first().attr('selected', true);
- } else {
- sel2.next().attr('selected', true);
- }
- updateAddressDisplay(totype);
- }
- }
- function showShipping(thisOne) {
- checkedFound = true;
- if ($(this).val() !== '40') {
- $('div#hidePart').show();
- $('div#shippingAddress input[type|="text"]').each(function() {
- var v = $(this).val();
- if ((v === ' --- ') || (v === '-')) {
- $(this).attr('value', '');
- }
- });
- } else {
- $('div#hidePart').hide();
- fillEmptyFields();
- }
- }
- function fillEmptyFields() {
- $('div#shippingAddress input[type|="text"]').each(function() {
- if ($(this).val() === '') {
- $(this).attr('value', ' --- ');
- }
- });
- }
- function updateAddressesDisplay(first_view, address_type) {
- if ($('input[type=checkbox]#addressesAreEquals:visible').is(':checked')) {
- $('fieldset#address_invoice:visible').hide('fast');
- } else {
- $('fieldset#address_invoice:hidden').show('fast');
- }
- if (typeof address_type !== "undefined") {
- if (address_type === '' && first_view) {
- updateAddressDisplay('delivery', true);
- updateAddressDisplay('invoice', true);
- } else {
- updateAddressDisplay(address_type, false);
- }
- $('div#shippingAddress input[type|="text"]').each(function() {
- var v = $(this).val();
- if ((v === ' --- ') || (v === '-')) {
- $(this).attr('value', '');
- }
- });
- if (!first_view && address_type === 'delivery' && bNewCountry !== bOldCountry) {
- updateAddresses();
- }
- }
- return true;
- }
- function updateAddressDisplay(addressType, first_view) {
- if (typeof addresses === "undefined") {
- return false;
- }
- if (typeof submitedForm !== "undefined" && submitedForm && first_view) {
- return true;
- }
- bOldCountry = $('fieldset#address_delivery select.id_country option:selected').val();
- var idAddress = $('select#id_address_' + addressType + '').val();
- $('fieldset#address_' + addressType + ' input.id_address').attr('value', idAddress);
- $('fieldset#address_' + addressType + ' input.firstname').attr('value', addresses[idAddress][1]);
- $('fieldset#address_' + addressType + ' input.lastname').attr('value', addresses[idAddress][2]);
- $('fieldset#address_' + addressType + ' input.alias').attr('value', addresses[idAddress][9]);
- $('fieldset#address_' + addressType + ' select.id_country option').each(function() {
- $(this).attr('selected', $(this).text() === addresses[idAddress][7]);
- });
- $('fieldset#address_' + addressType + ' input.city').attr('value', addresses[idAddress][6]);
- $('fieldset#address_' + addressType + ' input.postcode').attr('value', addresses[idAddress][5]);
- $('fieldset#address_' + addressType + ' input.address1').attr('value', addresses[idAddress][3]);
- $('fieldset#address_' + addressType + ' input.phone_mobile').attr('value', addresses[idAddress][4]);
- $('fieldset#address_' + addressType + ' textarea.other').val(addresses[idAddress][8]);
- $('fieldset#address_' + addressType + ' input.company').attr('value', addresses[idAddress][0]);
- $('fieldset#address_' + addressType + ' input.company_code').attr('value', addresses[idAddress][10]);
- $('fieldset#address_' + addressType + ' input.vat_code').attr('value', addresses[idAddress][11]);
- var link = $('fieldset#address_' + addressType + ' a.address_update').attr('href');
- var expression = /id_address=\d+/;
- link = link.replace(expression, 'id_address=' + idAddress);
- $('fieldset#address_' + addressType + ' a.address_update').attr('href', link);
- bNewCountry = $('fieldset#address_delivery select.id_country option:selected').val();
- swapSelectList(addressType);
- }
- function updateAddresses() {
- var idAddress_delivery = $('select#id_address_delivery').val();
- var id_country = $('fieldset#address_delivery select.id_country option:selected').val();
- $.ajax({
- type: 'POST',
- url: baseDir + 'order.php',
- async: true,
- cache: false,
- dataType: "json",
- data: 'processCountryChange=true&step=2&id_address=' + idAddress_delivery + '&id_country=' + id_country + '&token=' + static_token,
- success: function(jsonData) {
- if (jsonData.hasError) {
- var errors = '';
- for (error in jsonData.errors) {
- if (error !== 'indexOf') {
- errors += jsonData.errors[error] + "\n";
- }
- }
- }
- $('.countryPreloader').hide();
- location.reload();
- }, error: function(XMLHttpRequest, textStatus, errorThrown) {/*alert("TECHNICAL ERROR: unable to save adresses \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);*/
- }
- });
- }
- function Get_Cookie(check_name) {
- var a_all_cookies = document.cookie.split(';');
- var a_temp_cookie = '';
- var cookie_name = '';
- var cookie_value = '';
- var b_cookie_found = false;
- for (i = 0; i < a_all_cookies.length; i++) {
- a_temp_cookie = a_all_cookies[i].split('=');
- cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
- if (cookie_name === check_name) {
- b_cookie_found = true;
- if (a_temp_cookie.length > 1) {
- cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
- }
- return cookie_value;
- break;
- }
- a_temp_cookie = null;
- cookie_name = '';
- }
- if (!b_cookie_found) {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement