﻿function SearchIconSelected() {
    var selectedDivObject = document.getElementById('SearchContainer');
    var searchIcon = document.getElementById('SearchIcon');

    if (selectedDivObject.style.display.toLowerCase() == "none") {
        selectedDivObject.style.display = "block";
        searchIcon.src = "/Images/Icons/SearchIconSelected.png";
    }
    else {
        selectedDivObject.style.display = "none";
        searchIcon.src = "/Images/Icons/SearchIcon.png";
    }
}

function RefreshShoutBox() {
    setTimeout("LoadShoutBox()", 15000);
}

function LoadShoutBox() {
    $("#RefreshShoutboxForm").submit();
}

function NavigationHoverOver(navigationContainer) {
    var navigationContainerDiv = document.getElementById(navigationContainer);

    navigationContainerDiv.className = "navigationMain_hovered";
}

function NavigationHoverOut(navigationContainer) {
    var navigationContainerDiv = document.getElementById(navigationContainer);

    navigationContainerDiv.className = "navigationMain";
}

function NavigationEndHoverOver(navigationContainer) {
    var navigationContainerDiv = document.getElementById(navigationContainer);

    navigationContainerDiv.className = "navigationMainEnd_hovered";
}

function NavigationEndHoverOut(navigationContainer) {
    var navigationContainerDiv = document.getElementById(navigationContainer);

    navigationContainerDiv.className = "navigationMainEnd";
}

function ClearTextbox(textboxName) {
    var selectedTextbox = document.getElementById(textboxName);

    selectedTextbox.value = "";
}

function ClearShoutbox() {
    var selectedTextbox = document.getElementById("ShoutOut");

    if (selectedTextbox.value == "Your message...")
        selectedTextbox.value = "";
}

function PopulateBlankTextbox(obj, content) {
    if (obj.getAttribute && obj.value.length == 0) {
        obj.value = content;
    }
}

function ismaxlength(obj) {
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length > mlength)
        obj.value = obj.value.substring(0, mlength)
}

function clearAllFloats() {
    ScrollToTop();
    ClearFloatingDiv("TermsContainer");
    ClearFloatingDiv("PrivacyContainer");
    ClearFloatingDiv("SuggestionContainer");
    ClearFloatingDiv("ContactUsContainer");
    ClearFloatingDiv("AboutUsContainer");
    ClearFloatingDiv("BlogContainer");
}

function SwitchDivAvailable(selectedDiv) {
    var selectedDivObject = document.getElementById(selectedDiv);

    if (selectedDivObject.style.display.toLowerCase() == "none")
        selectedDivObject.style.display = "block";
    else
        selectedDivObject.style.display = "none";
}

function ClearFloatingDiv(divName) {
    var floatingDiv = document.getElementById(divName);

    if (floatingDiv != null) {
        parentDiv = floatingDiv.parentNode;
        parentDiv.removeChild(floatingDiv);
    }
}

function ScrollToTop() {
    window.scroll(0, 0);
}

function ScrollToBottom() {
    window.scrollTo(0, document.body.scrollHeight);
}

function ClearTopTenItem() {
    var itemName = document.getElementById('Answer');
    var itemAdditional = document.getElementById('Description');

    itemName.value = "";
    itemAdditional.value = "";
}

function ConfirmNavigation(confirmMessage, selectedUrl) {
    if (confirm(confirmMessage)) {
        document.location = selectedUrl;
    }
}

var imageSwitchingAllowed = true;

function SwapImage(imageObject, imagePath) {
    if (imageSwitchingAllowed) {
        if (imageObject != null) {
            imageObject.src = imagePath;
        }
    }
}

function SwapImageById(imageId, imagePath) {
    var gameIcon = document.getElementById(imageId);

    if (imageSwitchingAllowed) {
        if (gameIcon != null) {
            gameIcon.src = imagePath;
        }
    }
}

function SwapImageClicked(imageObject, imagePath) {
    if (imageSwitchingAllowed) {
        if (imageObject != null) {
            imageObject.src = imagePath;
        }

        imageSwitchingAllowed = false;
    }
}

function SetImage(imageId, imagePath) {
    var imageObject = document.getElementById(imageId);

    if (imageObject != null) {
        imageObject.src = imagePath;
        imageObject.onMouseOver = null;
        imageObject.onMouseOut = null;
        imageObject.onmouseover = null;
        imageObject.onmouseout = null;
    }
}

function SetGameSectionImage(imageId) {
    var gameGamersIcon = document.getElementById("GameGamersIcon");
    var gameTradesIcon = document.getElementById("GameTradesIcon");
    var gameReviewsIcon = document.getElementById("GameReviewsIcon");

    var selectedIcon = document.getElementById(imageId);

    if ((gameGamersIcon != null) && (gameTradesIcon != null) && (gameReviewsIcon != null)) {
        switch (imageId.toLowerCase()) {
            case "gamegamersicon":
                gameGamersIcon.src = '/Images/Icons/GameGamersHighlighted.png';
                gameTradesIcon.src = '/Images/Icons/GameTrades.png';
                gameReviewsIcon.src = '/Images/Icons/GameReviews.png';
                break;
            case "gametradesicon":
                gameGamersIcon.src = '/Images/Icons/GameGamers.png';
                gameTradesIcon.src = '/Images/Icons/GameTradesHighlighted.png';
                gameReviewsIcon.src = '/Images/Icons/GameReviews.png';
                break;
            case "gamereviewsicon":
                gameGamersIcon.src = '/Images/Icons/GameGamers.png';
                gameTradesIcon.src = '/Images/Icons/GameTrades.png';
                gameReviewsIcon.src = '/Images/Icons/GameReviewsHighlighted.png';
                break;
        }
    }
}

function EmptyDiv(divName) {
    var selectedDiv = document.getElementById(divName);
    var i;

    while (i = selectedDiv.childNodes[0]) {
        if (i.nodeType == 1 || i.nodeType == 3) {
            selectedDiv.removeChild(i);
        }
    }
}

function RemoveDiv(divName) {
    var selectedDiv = document.getElementById(divName);
    if (selectedDiv != null)
        selectedDiv.parentNode.removeChild(selectedDiv);
}
