﻿function ucwords(str) {
    return str.replace(/^(.)|\s(.)/g, function ($1) { return $1.toUpperCase(); });
}

function search(submit, root) {
    var text = $("#searchText");
    var form = $("#searchForm");
   
    if (text.val() == "") {
        text.focus();
        if (submit)
            return false;

    } else {
        text.val(ucwords(text.val()));
        re = /[^A-Za-z0-9]/g;
        expression = text.val().replace(re, "_");

        form.attr('action', root + 'search/' + expression + '/1.aspx');

        if (submit)
            return true;
    }
}
