﻿var backupOnSubmit;
var searchValue = "Site Search";

function searchFocus() {
    if (document.getElementById("searchField").value == searchValue) {
        document.getElementById("searchField").value = "";
    }
    //Kundan - keep a backup of current Form.OnSubmit
    backupOnSubmit = document.forms[0].getAttribute("onsubmit");
    //Kundan - the form should not be submitted. we ensure it by returning false
    document.forms[0].setAttribute("onsubmit", "javascript:return false;");
}

function searchBlur() {
    if (document.getElementById("searchField").value.replace(" ") == "") {
        document.getElementById("searchField").value = searchValue;
    }
    //Kundan - if there was something, restore it with the original else always return true (this is equivalent to not having an OnSubmit attribute)
    if (backupOnSubmit != null) {
        document.forms[0].setAttribute("onsubmit", backupOnSubmit);
    }
    else {
        document.forms[0].setAttribute("onsubmit", "javascript:return true;");
    }
}
function checkForInvalidChars(e) {
    if (window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    if (keynum == 34 || keynum == 39 || keynum == 47 || keynum == 60 || keynum == 62 || keynum == 92)
        return false;
    return true;
}
function doSearch(e) {
    if (window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    if (keynum == 13) {
        performSearch();
    }
}

function performSearch() {
    if (document.getElementById("searchField").value != searchValue) {
        window.location.href = location.protocol + "//" + location.host + "/search/Results.aspx?q=" + document.getElementById("searchField").value;
    }
}