jQuery(document).ready(function() { jQuery('.redirectModal').on('hidden.bs.modal', function (e) { clearTimeout(timer); var cid = "USA"; if (cid == '' && jQuery("#cid")){ var cid = jQuery("#cid").val(); } if (cid == ''){ if (window.location.indexOf('canada')){ var cid = 'can'; } if (window.location.indexOf('australia')){ var cid = 'aus'; } } console.log(cid,window.location); if (cid.toUpperCase() == "USA"){ cid = ''; var country = "U.S."; }else if (cid.toUpperCase() == "CAN"){ var country = "Canadian"; }else if (cid.toUpperCase() == "AUS"){ var country = "Australian"; } jQuery(".country-redirect").val(cid.toUpperCase()).change(); clearInterval(countDowntimer) }); }); jQuery("head").append(''); jQuery(".country-redirect").change(function(){ var exception = "0"; var cid = "USA"; if (cid == '' && jQuery("#cid")){ var cid = jQuery("#cid").val(); } if (cid == ''){ if (window.location.indexOf('canada')){ var cid = 'can'; } if (window.location.indexOf('australia')){ var cid = 'aus'; } } console.log(cid,window.location); if (cid.toUpperCase() == "USA"){ var country = "U.S."; }else if (cid.toUpperCase() == "CAN"){ var country = "Canadian"; }else if (cid.toUpperCase() == "AUS"){ var country = "Australian"; } if (exception == 1 ){ var country = jQuery('#Country option:selected').text().trim(); if (jQuery('#Country option:selected').text().trim() == "United States of America"){ var country = " the U.S."; }else if (jQuery('#Country option:selected').text().trim() == "Canada"){ var country = "Canada"; }else if (jQuery('#Country option:selected').text().trim() == "Australia"){ var country = "Australia"; } } var countryValue = jQuery(this).find('option:selected').attr('data-isoalpha2'); var d2countryValue = jQuery(this).find('option:selected').attr('value'); var continentValue = jQuery(this).find('option:selected').attr('data-continent'); var store, storeUrl, textUrl= ""; console.log(cid,country,countryValue,d2countryValue,exception); var redirect = '0'; if (countryValue === 'US' && exception == 1) { redirect = '1'; storeUrl = jQuery('#usaURL').val(); store = 'U.S.'; textUrl = "hayward-pool.com"; } else if (countryValue === 'CA' && cid != 'CAN') { redirect = '1'; storeUrl = jQuery('#canURL').val(); store = "Canada"; textUrl = "hayward-pool.ca"; } else if ((countryValue === "AU" || countryValue === "NZ") && (cid != 'AUS')) { redirect = '1'; storeUrl = jQuery('#ausURL').val(); textUrl = "hayward-pool.com.au"; store = "Australia"; } else if ( [ 'RU','DE','GB','FR','IT','ES','UA','PL','RO','NL','BE','GR','CZ','PT','SE','HU','BY','AT','CH', 'BG','DK','FI','SK','NO','IE','HR','MD','BA','AL','LT','MK','SI','LV','EE','LU','MT','IS','AD', 'MC','GE','KZ','LI','SM','TR'].indexOf(countryValue) >= 0 && ['AUS','USA','CAN'].indexOf(cid) >= 0 ) { redirect = '1'; storeUrl = jQuery('#eurURL').val(); textUrl = "hayward.fr"; store = "Europe"; } else if ( ['RU','DE','GB','FR','IT','ES','UA','PL','RO','NL','BE','GR','CZ','PT','SE','HU','BY','AT','CH', 'BG','DK','FI','SK','NO','IE','HR','MD','BA','AL','LT','MK','SI','LV','EE','LU','MT','IS','AD', 'MC','GE','KZ','LI','SM','TR','CA','AU','NZ'].indexOf(countryValue) >= 0 === false && ['AUS','CAN'].indexOf(cid) >= 0 && exception == 1) { redirect = '1'; storeUrl = jQuery('#miscURL').val(); store = ''; textUrl = "hayward-pool.com"; } else if ( ['RU','DE','GB','FR','IT','ES','UA','PL','RO','NL','BE','GR','CZ','PT','SE','HU','BY','AT','CH', 'BG','DK','FI','SK','NO','IE','HR','MD','BA','AL','LT','MK','SI','LV','EE','LU','MT','IS','AD', 'MC','GE','KZ','LI','SM','TR','CA','AU','NZ'].indexOf(countryValue) >= 0 === false && ['AUS','CAN'].indexOf(cid) >= 0 ) { redirect = '1'; storeUrl = jQuery('#usaURL').val(); textUrl = "hayward-pool.com"; store = "U.S."; } if (redirect == '1' && (d2countryValue.toUpperCase() != cid.toUpperCase() || (cid.toUpperCase() == 'USA' && exception == 1))){ jQuery('.redirectModal .txt_country').text(country); jQuery('.redirectModal .txt_store').text(store); jQuery('.redirectModal .counter').text(15); jQuery('.redirectModal .txt_url').text(textUrl); jQuery('.redirectModal #nonresidentLink').attr('href',storeUrl); jQuery('.redirectModal #residentLink').attr('data-country',cid); jQuery(".redirectModal").modal('show'); timer = window.setTimeout(function() { jQuery("#nonresidentLink")[0].click(); }, 15000); var countdown = function() { jQuery('.counter').each(function() { var count = parseInt(jQuery(this).html()); if (count !== 0) { jQuery(this).html(count - 1); } }); }; countDowntimer = setInterval(countdown, 1000); } });