$(function () {

    //global vars
    var inputBoxes = $(".input");
    var search = $("#search");
    var searchVal = "Search the site...";

    //Effects for both searchbox
    inputBoxes.focus(function (e) {
        $(this).addClass("active");
    });
    inputBoxes.blur(function (e) {
        $(this).removeClass("active");
    });

    //show/hide default text if needed

    search.focus(function () {
        if ($(this).attr("value") == searchVal) $(this).attr("value", "");
    });
    search.blur(function () {
        if ($(this).attr("value") == "") $(this).attr("value", searchVal);
    });
});


function GetHtmlControl(controlId) {
    var frm = document.forms[0];
    if (frm != undefined) {
        for (var i = 0; i < frm.length; i++) {
            e = frm.elements[i];
            if (e.name.indexOf(controlId) != -1) {
                return e;
            }
        }
    }

    return null;
}

function CheckForEnter(e, urlPath) {
    var keyPressCode = 0;
    if (window.event) {
        keyPressCode = e.keyCode;
    }

    if (e.which) {
        keyPressCode = e.which;
    }

    if (parseFloat(keyPressCode) == 13) {
        SiteSearchSubmit(urlPath, "");
        return false;
    }

    return true;
}

function SiteSearchSubmit(url, searchBtn) {

    var cx = GetHtmlControl("cx");
    var cof = GetHtmlControl("cof");
    var ie = GetHtmlControl("ie");
    var q = GetHtmlControl("q");

    if (cx != null && cof != null && ie != null && q != null && q.value != 'Search the site...') {
        var queryString = "cx=" + cx.value + "&cof=" + cof.value + "&ie=" + ie.value + "&q=" + q.value + "&sa=Search";
        document.location.href = url + "?" + queryString;
    }
}
