function std_trim(word) {
    return word.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function urlencode(k){
    if(encodeURIComponent) {
        try {
            return encodeURIComponent(k);
        }catch (e) {
            return '';
        }
    }else if(escape) {
        return escape(k);
    }

    return '';
}

// query is a {key:val, key2:val2} object literal.
function make_query_string(query) {
    if(typeof query == "object") {
        var query_bag = new Array();

        for(k in query) {
            query_bag.push(k + "=" + urlencode(query[k]));
        }

        query = query_bag.join("&");
    }

    return query;
}

// third (optional) argument is an object literal of attributes. eg. {'id':'thisid', 'rel':'nofollow'}
function make_html_anchor(url, text) {
    var a = '<a href="' + url + '"';

    if(arguments.length == 3) {
        var attributes = arguments[2];
        var att_bag = new Array();

        for(k in attributes) {
            att_bag.push(k + '="' + attributes[k] + '"');
        }

        a += " " + att_bag.join(" ");
    }

    a += ">" + text + "</a>";

    return a;
}