﻿function startSearch() {
    if (document.getElementById("sa")) {
        var searchButton = document.getElementById("sa");
        searchButton.onclick = search;
    }
    if (document.getElementById("q")) {
        var searchField = document.getElementById("q");
        searchField.onkeyup = checkEnter;

    }

}

function checkEnter(event) {
    var e = event || window.event;

    if (e.enterKey || e.keyCode == 13) {        
        if (document.getElementById("sa")) {
            var button = document.getElementById("sa");
            button.click();
        }
        return false;
    }
}

function search() {
    var googleSearchURL = "http://www.google.com/cse"
    var googleAccountCode = "008433985864827869179:f1z1knd5mh0";
    var encoding = "UTF-8";
    var queryBox = document.getElementById("q");
    if (queryBox) {
        var query = encodeURIComponent(queryBox.value);  // Get rid of spaces and such
        var getString = googleSearchURL + "?cx=" + googleAccountCode + "&ie=" + encoding + "&q=" + query;
        window.location.href = getString;
    }
}
