function showSuggestions(e){
            var query = e.target.value;
            var xhr = new XMLHttpRequest();
            xhr.open("POST","https://aeroxplorer.com/search.php");
            xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xhr.send("action=showSuggestions&results=10&q=" + query);
            xhr.onload = function(){
                console.log(JSON.parse(this.responseText));
                try {
                    var resp = JSON.parse(this.responseText);
                    var builder = "";
                    for(var x=0;x<resp.length;x++){
                        if(resp[x] != ""){
                            builder += '<div class="single-nav-result" onclick="window.location.href=\'' + resp[x].url + '\'">' + resp[x].text + '</div>';
                        }
                    }
                    document.querySelector(".nav-search-results").innerHTML = builder;
                } catch(err){
                    document.querySelector(".nav-search-results").innerHTML = "No results.";
                }
            }
        }
        function protectImages(){
            for(var x=0;x<document.getElementsByTagName("img").length;x++){
                document.getElementsByTagName("img")[x].addEventListener("contextmenu",function(e){
                    e.preventDefault();
                    console.log("Image is protected and cannot be opened.");
                });
            }
        }
        
        function openSearch(){
            document.querySelector(".search-cont").style.display = "block";
        }
        
        // function openCart(){
        //     document.querySelector(".cart-cont").style.left = "0";
        // }
        
        var first = false;
        
        function getWeather(){
            var xhr = new XMLHttpRequest();
            xhr.open("POST","https://aeroxplorer.com/");
            xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xhr.send("fetch=weather");
            xhr.onload = function(){
                try {
                    var weather = JSON.parse(this.responseText);
                    document.querySelector("#weather-type img").src = "http://openweathermap.org/img/wn/" + weather.weather[0].icon + "@2x.png";
                    document.querySelector("#temp-disp").innerHTML = Math.round(((weather.main.temp-273.15)*9/5)+32) + "&deg;F";
                    document.querySelector("#weather-name").innerHTML = weather.weather[0].description;
                    document.querySelector("#humidity").innerHTML = weather.main.humidity + '<span class="type-title">PERCENT</span>';
                    document.querySelector("#lowtemp").innerHTML = Math.round(((weather.main.temp_min-273.15)*9/5)+32) + '<span class="type-title">DEGREES F</span>';
                    document.querySelector("#hightemp").innerHTML = Math.round(((weather.main.temp_max-273.15)*9/5)+32) + '<span class="type-title">DEGREES F</span>';
                    document.querySelector("#feels-like").innerHTML = "Feels like " + Math.round(((weather.main.feels_like-273.15)*9/5)+32) + "&deg;F";
                    document.querySelector(".area-name").innerHTML = weather.name;
                    document.querySelector("#wind-dir").style.transform = "rotateZ(" + weather.wind.deg + "deg)";
                    document.querySelector("#wind span").innerHTML = Math.round(weather.wind.speed) + " MPH";
                } catch(err){
                    document.querySelector(".feed-elem").innerHTML = "Failed to load weather data :: " + err.message;
                }
                console.log(JSON.parse(this.responseText));
            }
        }
         var currentOn = 0;
        function loadHeadline(){
            var headlines = document.querySelectorAll(".single-headline");
            for(var x=0;x<headlines.length;x++){
                headlines[x].style.display = "none";
            }
            currentOn++;
            if(currentOn >= headlines.length){
                currentOn = 0;
            }
            setTimeout(function(){
                headlines[currentOn].style.display = "block";
            },100);
        }
        setInterval(loadHeadline,7000);
        function getLiveFeed(){
            var xhr = new XMLHttpRequest();
            xhr.open("POST","https://aeroxplorer.com/dashboard/ajax/news_inline_feed.php");
            xhr.send();
            xhr.onload = function(){
                document.getElementById("live-news-feed").innerHTML = this.responseText;
            }
        }
        
        function openSidebar(){
            if(!first){
                first = true;
                getWeather();
                getLiveFeed();
            }
            document.querySelector(".nav-sidebar").style.left = "0";
        }
        
        function openMobileNav(){
            document.querySelector(".mobile-links").style.right = "0";
            document.querySelector(".mobile-links").style.display = "block";
        }
        
        function switchTab(tab){
            for(var x=0;x<document.querySelectorAll(".mobile-links-page").length;x++){
                document.querySelectorAll(".mobile-links-page")[x].style.display = "none";
            }
            document.querySelector("." + tab).style.display = "block";
        }
        
        document.body.onload = function(){
            showCookies();
            loadHeadline();
            protectImages();
        }
        
        function filterList(num){
            for(var x=0;x<document.querySelectorAll(".article-placement").length;x++){
                document.querySelectorAll(".article-placement")[x].style.opacity = "0";
                document.querySelectorAll(".filter-node > span")[x].classList.remove("filter-selected");
            }
            document.querySelectorAll(".filter-node > span")[num].classList.add("filter-selected");
            document.querySelectorAll(".article-placement")[num].style.opacity = "1";
            setTimeout(function(){
                for(var x=0;x<document.querySelectorAll(".article-placement").length;x++){
                    document.querySelectorAll(".article-placement")[x].style.display = "none";
                }
                document.querySelectorAll(".article-placement")[num].style.display = "grid";
            },100);
        }
        window.onscroll = function() {scrollFunction()};

        function scrollFunction() {
          if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
            document.querySelector(".nav").style.boxShadow = "0 0 10px grey";
          } else {
            document.querySelector(".nav").style.boxShadow = "0 0 0";
          }
        }