﻿
    var selectedChoice = "site";
    var shIsLoad = true;
    var shImageWidth = 0;
    var shBoxWidthWithLogo = 0;
    var shBoxWidthWithoutLogo = 0;


    function onChoiceClick(selChoice) {
        var logoImage = document.getElementById("shLogo");
        var searchBoxInput = document.getElementById("shBox");
        var searchImage = document.getElementById("shSearchButton");
        //logoImage.alt = bingText;
        var arrowChoice1 = document.getElementById("shChoice1");
        var arrowChoice2 = document.getElementById("shChoice2");


        if (shIsLoad == true) {
            shImageWidth = logoImage.clientWidth;
            shBoxWidthWithLogo = searchBoxInput.clientWidth;
            shBoxWidthWithoutLogo = searchBoxInput.clientWidth + shImageWidth;
            shIsLoad = false;
        }

        if (selChoice == "site") {
            selectedChoice = "site";
            if ((searchBoxInput.value == selectedChoiceText) || (searchBoxInput.value.replace(/(^\s*)|(\s*$)/g, '') == '')) {
                searchBoxInput.value = searchChoiceOne;

                searchBoxInput.style.fontStyle = 'Italic';
                searchBoxInput.style.color = "#a1a1a1";
                logoImage.style.width = shImageWidth;
                logoImage.style.display = "inline";
                searchBoxInput.style.width = shBoxWidthWithLogo + 'px';
            }
            selectedChoiceText = searchChoiceOne;
            searchImage.title = searchChoiceOne;
            arrowChoice1.style.display = "inline";
            arrowChoice2.style.display = "none";
        }
        else {
            selectedChoice = "all";
            if ((searchBoxInput.value == selectedChoiceText) || (searchBoxInput.value.replace(/(^\s*)|(\s*$)/g, '') == '')) {
                searchBoxInput.value = searchChoiceTwo;

                searchBoxInput.style.fontStyle = 'Italic';
                searchBoxInput.style.color = "#a1a1a1";
                logoImage.style.width = shImageWidth;
                logoImage.style.display = "inline";
                searchBoxInput.style.width = shBoxWidthWithLogo;
            }
            selectedChoiceText = searchChoiceTwo;
            searchImage.title = searchChoiceTwo;
            arrowChoice2.style.display = "inline";
            arrowChoice1.style.display = "none";
        }
    }
    function doSearch() {
        var qu = document.getElementById('shBox').value;

        if (qu != selectedChoiceText) {
            if (selectedChoice == "site") {
                window.location.href = wmSite + encodeURIComponent(qu);
            }
            else {
                window.location.href = msSite + encodeURIComponent(qu);
            }
        }
        return;
    }




    function onSearchBoxFocus(defaultSearchLabel) {
        var searchBoxInput = document.getElementById("shBox");
        if (searchBoxInput.value == defaultSearchLabel) {
            searchBoxInput.value = "";
        }
        //var logoImage = document.getElementById("shLogo");

        if (shIsLoad == true) {
            //shImageWidth = logoImage.clientWidth;
            shBoxWidthWithLogo = searchBoxInput.clientWidth;
            shBoxWidthWithoutLogo = searchBoxInput.clientWidth + shImageWidth;

            shIsLoad = false;
        }

        if ((searchBoxInput.value == defaultSearchLabel) || (searchBoxInput.value.replace(/(^\s*)|(\s*$)/g, '') == '')) {

            searchBoxInput.value = '';

            searchBoxInput.style.fontStyle = '';
            searchBoxInput.style.color = '#000000';
            //logoImage.style.width = '0px';
            //logoImage.style.display = "none";

            searchBoxInput.style.width = shBoxWidthWithoutLogo + 'px';

        }
    }

    function onSearchBoxBlur(defaultSearchLabel) {
        var searchBoxInput = document.getElementById("shBox");
        //var logoImage = document.getElementById("shLogo");

        if (searchBoxInput.value.replace(/(^\s*)|(\s*$)/g, '') == '') {
            searchBoxInput.style.fontStyle = 'Italic';
            searchBoxInput.style.color = "#a1a1a1";

            searchBoxInput.value = defaultSearchLabel;
            searchBoxInput.style.width = shBoxWidthWithLogo + 'px';
            //logoImage.style.width = shImageWidth + 'px';
            //logoImage.style.display = "inline";
        }


    }
    function searchTextBoxKeyPressed(e) {
        var key = String.fromCharCode(e.keyCode);

        if (key == "\n" || key == "\r") {
            doSearch();

            return false;
        }

    }
