﻿function checkForEnterKey(e, keywordsID, subfolder)
{
    var retVal = true;
    var keycode = 0;
    if ((typeof(e) != "undefined") && (e != null))
    {
        if ((typeof(e.keyCode) != "undefined") && (e.keyCode != null))
        {
            keycode = e.keyCode;
        }
        else if ((typeof(e.which) != "undefined") && (e.which != null))
        {
            keycode = e.which;
        }
        else if ((typeof(e.charCode) != "undefined") && (e.charCode != null))
        {
            keycode = e.charCode;
        }
    }
    if (keycode == 13)
    {
        doSearch(keywordsID, subfolder);
        retVal = false;
    }
    return retVal;
}

function doSearch(keywordsID, subfolder)
{
    var keywordsTextbox = document.getElementById(keywordsID);
    if (keywordsTextbox != null)
    {
        var keywords = keywordsTextbox.value;
        if (keywords.length > 0)
        {
            var q = "q=" + escape(keywords);
            var l = "l=en";
            var form = "FORM=QBMA";
            var mkt = "mkt=" + escape("en-US");

            // Restrict the search to just pages in this site
            var s100 = "s100=on";

            var otherSite = "OtherSite=http%3A%2F%2Fwww.microsoft.com%2Fweb";            
            if ((typeof(subfolder) != "undefined") && (subfolder != ""))
            {
                otherSite += "%2F" + escape(subfolder);
            }

            var url = "http://search.microsoft.com/results.aspx?" + q + "&" + l + "&" + form + "&" + mkt + "&" + s100 + "&" + otherSite;
            window.location.href = url;
        }
    }
}
