How to Replace Character in String

I have some code that grabs the variable value on the end of a query string, and I want to deal with phrases (such as “Great Road Race”) by placing a plus (+) sign between the words (like "Great+Road+Race) and then run a string replace to swap in a blank space. Here’s the existing code:


<script type="text/javascript">
function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0; i<vars.length; i++) {
        var pair = vars*.split("=");
        if (pair[0] == variable) {
            return pair[1];
        } else {
            return "";// Don't display "undefined"
        }
    }
}
// There is additional script below the form
</script> 

Links would look like this:

<a href="event_registration.html?EventName=Great+Road+Race">Register for this Event</a>

What’s the best way to do the string replace?