function PortalSearch(event1, searchUrl, searchBoxId) {
    var kCode = String.fromCharCode(event1.keyCode);
    if (kCode == "\n" || kCode == "\r") {
        fnSubmit(searchUrl, searchBoxId);
        return false;
    }
}

function fnSubmit(searchUrl, searchBoxId) {
    try {
        var _textArea = document.getElementById(searchBoxId);
        if (bfnValidate(_textArea.value)) {
            ret = openext1(searchUrl + "/Search/Pages/default.aspx?cx=009909668336905004361%3Arb4bobfbnps&cof=FORID%3A10&ie=UTF-8&q=" + trimspace(_textArea.value), '_blank');

        }
    }
    catch (e) {
        alert(e.message);
        //alert('Search function does not work on authoring mode');
    }
    finally {
    }
    return false;
}

function bfnValidate(str) {
    if (trim(str) != '') {
        return true;
    }
    else {
        alert('Please enter a search keyword.');
        return false;
    }
    return false;
}

function trim(str) {
    return str.replace(/^\s*|\s*$/g, "");
}

function openext1(externalURL, replacewindow) {
    var url = externalURL;
    var replace;

    if (replacewindow == 'undefined')
        replace = '_second';
    else
        replace = replacewindow;

    scrWidth = window.screen.availWidth - 50;
    scrHeight = window.screen.availHeight - 100;
    scrLeft = 0;
    scrTop = 0;
    var strFeatures = "scrollbars=yes,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,left=" + scrLeft + ",top=" + scrTop + ",height=" + scrHeight + ",width=" + scrWidth

    window.open(url, replace, strFeatures, 0);
    return;
}

function trimspace(str) {
    var encoded_string;
    encoded_string = str.replace(/%/g, "%25");
    encoded_string = encoded_string.replace(/ /g, "%20");
    encoded_string = encoded_string.replace(/\$/g, "%24");
    encoded_string = encoded_string.replace(/&/g, "%26");
    encoded_string = encoded_string.replace(/,/g, "%2C");
    encoded_string = encoded_string.replace(/\+/g, "%2B");
    encoded_string = encoded_string.replace(/\//g, "%2F");
    encoded_string = encoded_string.replace(/:/g, "%3A");
    encoded_string = encoded_string.replace(/;/g, "%3B");
    encoded_string = encoded_string.replace(/=/g, "%3D");
    encoded_string = encoded_string.replace(/\?/g, "%3F");
    encoded_string = encoded_string.replace(/@/g, "%40");
    encoded_string = encoded_string.replace(/\"/g, "%22");
    encoded_string = encoded_string.replace(/</g, "%3C");
    encoded_string = encoded_string.replace(/>/g, "%3E");
    encoded_string = encoded_string.replace(/#/g, "%23");
    encoded_string = encoded_string.replace(/{/g, "%7B");
    encoded_string = encoded_string.replace(/}/g, "%7D");
    encoded_string = encoded_string.replace(/\|/g, "%7C");
    encoded_string = encoded_string.replace(/\\/g, "");
    encoded_string = encoded_string.replace(/\^/g, "%5E");
    encoded_string = encoded_string.replace(/~/g, "%7E");
    encoded_string = encoded_string.replace(/\[/g, "%5B");
    encoded_string = encoded_string.replace(/\]/g, "%5D");
    //encoded_string = encoded_string.replace(/\`/g,"");
    encoded_string = encoded_string.replace(/\(/g, "%28");
    encoded_string = encoded_string.replace(/\)/g, "29");
    encoded_string = encoded_string.replace(/\*/g, "%2A");
    encoded_string = encoded_string.replace(/\-/g, "%2D");
    encoded_string = encoded_string.replace(/\./g, "%2E");
    encoded_string = encoded_string.replace(/\_/g, "%5F");
    return encoded_string;
}
