﻿function getElementSafe(id) {
    var retval;
    if (document.getElementById) {
        retval = document.getElementById(id);
    }
    else if (document.all) {
        retval = document.all[id];
    }
    else if (document.layers) {
        retval = document.layers[id];
    }
    return retval;
}


function searchProducts(fieldName, url) {
    if (document.forms[0].elements[fieldName] != null && document.forms[0].elements[fieldName].value != "") {
        var SearchTerm = escape(document.forms[0].elements[fieldName].value);
        SearchTerm = SearchTerm.replace(/%u2019/g, "%27");  // replace a fancy apostrophe from MS-WORD with a regular apostrophe.
        SearchTerm = SearchTerm.replace(/%5C/g, ""); // remove all '\'
        SearchTerm = SearchTerm.replace(/\//g, "");   // remove all '/'
        SearchTerm = SearchTerm.replace(/\*/g, "");  // remove all * 
        SearchTerm = SearchTerm.replace(/%5E/g, "");  // remove all ^

        if (url != null && url.length > 0) {
            document.location = url + "?searchTerm=" + SearchTerm;
        }
        else {
            if (document.URL.indexOf("https:") == -1) {
                document.location = appPath + "/Search.aspx?searchTerm=" + SearchTerm;
            }
            else {
                document.location = "https://www.govbizconsultants.com/Search.aspx?searchTerm" + SearchTerm;
            }
        }

    }

}

function keyPressFunction(buttonType, e, url) {
    var eKey;

    if (document.all)
        eKey = window.event.keyCode;
    else
        eKey = e.which;

    if (eKey == 13) {
        if (url != null) {
            document.forms[0].action = "javascript:searchProducts('" + buttonType + "', '" + url + "');";
        }
        else
            document.forms[0].action = "javascript:searchProducts('" + buttonType + "');";
        document.forms[0].submit();
    }
}

function openModalPopup(extendername) {

    var popup = $find(extendername);
    popup.show();
}


function closeModalPopup(extendername) {
    var popup = $find(extendername);

    popup.hide();
}
             