/* THIS IS GLOBALLY INCLUDED ON EVERY PAGE. SO PUT STUFF HERE YOU NEED TO BE ON *EVERY* PAGE OF THE WEBSITE Previously called inc-htmlheader.js */ /* ------------------ modal controls ------------------ */ //how long to wait to open the modal (in seconds) var howLongToOpenModal = 90; // how long to wait if they said not now (in minutes) var howLongToWaitForNotNow = 5; /* ------------------ modal controls [END] ------------------ */ var hmgbutton = $('.hamburger-icon'); var mobnavholder = $('.mobile-nav-col').first(); $(document).ready(function(){ // Disable Bootstraps IE-breaking accessibility JS $.fn.modal.Constructor.prototype.enforceFocus = function () { }; if($('.datePicker').length) { $('.datePicker').datepicker({ minDate: 0, dateFormat: 'dd/mm/yy' }); } if($('.LangClose').length) { $('.LangClose').click(function(){ document.cookie="LanguageWidgetClose=1;path=/"; $("#LangSelect").remove(); }); } if($("#CurrencySelector").length) { $("#CurrencySelector").on("change",function(){ var oDate = new Date(); oDate.setTime(oDate.getTime() + (30*24*60*60*1000)); var sExpires = "expires="+oDate.toUTCString(); document.cookie="nCurrency_ID="+$(this).val()+"; path=/"; location.reload(); }); } $('form#footerNewsletter').submit(function(e){ // stop form submitting (page load) e.preventDefault(); // get the name (if is exists) var emailName = ""; if($('input[name="sNewsName"]').length) emailName = $('input[name="sNewsName"]').val(); // get email address var emailAddress = $('input[name="sNewsEmailAddress"]').val(); // Check email address length if(emailAddress.length < 10) { alert("Your email address isn't valid"); } else { // ajax it $.ajax({ data: {sEmailName:emailName, sEmailAddress: emailAddress}, type: 'post', url: 'ajax/newsletter_exec.php', success: function(data) { // Append goal information to head $('head').append(data); // Alert user of sign up success alert("Thank you. You have been successfully added to our mailing list."); // Clear the form if($('input[name="sNewsName"]').length) $('input[name="sNewsName"]').val(""); $('input[name="sNewsEmailAddress"]').val(""); $('input[name="sNewsEmailAddress"]').css('background-color',''); } }); } }); }); function fLangChange($sLangAbbr, $sSURL) { $bChange = 0; $sNewURL = window.location.href; aLanguages.forEach(function($sTempLangAbbr){ console.log($sTempLangAbbr); if(window.location.href.indexOf("/"+$sTempLangAbbr+"/")>=0) { $sNewURL = $sNewURL.replace("/"+$sTempLangAbbr+"/","/"+$sLangAbbr+"/"); $bChange = 1; } }); if(!$bChange) { $sNewURL=$sSURL+$sLangAbbr+"/"; } window.location = $sNewURL; } /* COOKIE CUTTER - The "I accept cookies" legal disclaimer */ $(function(){ $.cookieCuttr(); }); // EMAIL CHECK // ============== function fCheckEmail(email) { var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if(!re.test(email)) return "invalid"; else return true; } window.addEventListener('message', fReceiveMessage, false); function fReceiveMessage(e) { fScrollToDiv(e.data); } // SCROLL TO DIV // ============== function fScrollToDiv($sCSSID) { // If it isn't null and it's not a Regex message from jQuery if($sCSSID!=null && !(/[^a-zA-Z0-9-]/.test($sCSSID))) { var $oCSSSelector = $("#"+$sCSSID); if($oCSSSelector.length > 0) { $('html,body').animate({ scrollTop: $oCSSSelector.offset().top-100 }, 500); } } } $(window).on("load", function(){ parent.postMessage("loaded","*"); }); function fValidateEmail(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); } // Hmg click //======================= hmgbutton.on("click",function(){ mobnavholder.toggleClass('mobnavopen'); $('#nav-icon2').toggleClass('open'); }); var $nDemoScrollBreakpoint = $(".demo-scrollpoint").offset().top; $(window).on("resize", function(){ $nDemoScrollBreakpoint = $(".demo-scrollpoint").offset().top; }); var $nLastScrollPosition = 0; var $bCalculatingScroll = false; var $oTopBar = $(".top-bar"); function fShowHideBar($nScrollPosition) { if($nScrollPosition >= $nDemoScrollBreakpoint && $oTopBar.css("top") != "0px") { $oTopBar.css("top", "0px"); } else if($nScrollPosition < $nDemoScrollBreakpoint) { $oTopBar.css("top", ""); } } window.addEventListener('scroll', function(e) { $nLastScrollPosition = window.scrollY || window.pageYOffset; if (!$bCalculatingScroll) { window.requestAnimationFrame(function() { fShowHideBar($nLastScrollPosition); $bCalculatingScroll = false; }); } $bCalculatingScroll = true; }); [].slice.call(document.querySelectorAll('.header-nav-dropdown')).forEach(function(el){ el.addEventListener('click', onClick, false); }); function onClick(e){ //e.preventDefault(); var el = this; el.classList.contains('show-submenu') ? hideSubMenu(el) : showSubMenu(el); } function showSubMenu(el){ el.classList.add('show-submenu'); document.addEventListener('click', function onDocClick(e){ //e.preventDefault(); if(el.contains(e.target)){ return; } document.removeEventListener('click', onDocClick); hideSubMenu(el); }); } function hideSubMenu(el){ el.classList.remove('show-submenu'); } //=================================== // coookie modal //=================================== var modalHTML; var modalOpened = false; var timeShouldOpen; $(document).ready(function(){ initialiseCookieVaribles(); }); function initialiseCookieVaribles(){ //if the site hasnt been opened before set a time for when //the modal shoudl be opened if(readCookie("firstTimeUporiumLoaded") === null ){ //get the current time in milliseconds var millis = Date.now() //add 1 minute to that time openModalTime = millis + (howLongToOpenModal * 1000); //time in seconds //set the cookie createCookie("firstTimeUporiumLoaded",openModalTime,3600); timeShouldOpen = readCookie("firstTimeUporiumLoaded"); } else { //otherwise //get the value from the cookie for when the modal should open timeShouldOpen = readCookie("firstTimeUporiumLoaded"); //if the 'when it should open' cookie is more than a week ago //they were on the site for less than a minute over a week //ago so we reset the timer to not be obnoxious if(timeShouldOpen < (Date.now() - (1000 * 60 * 60 * 24 * 7))){ //recreatet he cookie for 1 minute from now var millis = Date.now() openModalTime = millis + 60000; //1 minute createCookie("firstTimeUporiumLoaded",openModalTime,360000); } } //make sure thereis no 'not now' or 'already subscribed' cookie; if(readCookie("notNowModal") === null && readCookie("subbedToModal") === null){ //and run the check to see if the cookie should be opened loopingModalCheck(); } } function loopingModalCheck(){ //every 5 seconds look to see if its time to openthe modal window.setInterval(function(){ if(Date.now() > timeShouldOpen){ //if it is time, run the check function checkIfModal(); } }, 5000); } function checkIfModal(){ //if the modal isnt already open if(!modalOpened){ //ajaxically get the htnk $.get("../pages/modal/ebook-modal.php",function(modalData){ modalHTML = modalData; //and append the html appendModal(); }) } } function appendModal(){ $('body').append(modalHTML); modalOpened = true; //hide jivo chat mobile thingy thats totally in the way on mobile var jivoStyle = document.createElement("style"); jivoStyle.setAttribute("id", "jivodelete"); jivoStyle.innerHTML = "jdiv { display: none !important } #top-header-wrapper-fixed{display:none;}"; document.head.appendChild(jivoStyle); } function HideModal(){ $('#upm-modal-page-blackout').hide(); //bring back the jivochat thingy var jivoStyleInHead = document.getElementById("jivodelete"); document.head.removeChild(jivoStyleInHead); } $('body').on('click','#upm-modal-not-now-button',function(){ createCookie("notNowModal",1,howLongToWaitForNotNow); HideModal(); }); $('body').on('click','#upm-modal-dont-ask-button',function(){ createCookie("subbedToModal",1,36000000); HideModal(); }); $(document).on('submit','form',function(){ console.log('fired'); createCookie("subbedToModal",1,36000000000); }); //create cookie function createCookie(name,value,hours) { var expires = ""; if (hours) { var date = new Date(); date.setTime(date.getTime() + (hours*60*1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + value + expires + "; path=/"; } //read cookie function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } //delete cookie function eraseCookie(name) { createCookie(name,"",-1); }