function trim(string) {
    return string.replace(/(^\s+)|(\s+$)/g, "");
}

function Search(submit, section) {
    form = document.getElementById("search_form");

    if (form.search_key.value == '') {
        alert('Please enter search text');
        form.search_key.focus();
        if (submit) {
            return false;
        }
    } else {
        if (section == 'product') {
            expression = trim(form.search_key.value.toLowerCase()).replace(/(\s+)/g, '+');
            form.action = '/software.html?key=' + expression;
            form.submit();
        } else {
            if (section == 'press_release') {
                expression = trim(form.search_key.value.toLowerCase()).replace(/(\s+)/g, '+');
                document.location = '/' + section + '/search.html?search_key=' + expression + '&p=1';
            } else {
                document.location = '/' + section + '/search.html?search_key=' + form.search_key.value;
            }
            if (submit) {
                return false;
            }
        }
    }
}
