function addBookmark(url, title)
{
    if (!url) url = location.href;
    if (!title) title = document.title;

    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
    else if (typeof window.external == "object") window.external.AddFavorite(url, title);
    else if (window.opera && document.createElement)
    {
        var a = document.createElement('A');
        if (!a) return false; //IF Opera 6
        a.setAttribute('rel','sidebar');
        a.setAttribute('href',url);
        a.setAttribute('title',title);
        a.click();
    }
    else return false;

    return true;
}

function f() {
    var el = document.getElementById("query");
    if (el.value == "Search...") el.value = "";
}

function b() {
    var el = document.getElementById("query");
    if (el.value == "") el.value = "Search...";
}

function ltrim(str) {
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}

function rtrim(str) {
    for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
    return str.substring(0,j+1);
}

function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f\.\-";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function doSearch() {
    var searchform_errorfield = document.getElementById('search_form_error'), searchform = document.getElementById('searchForm');

    if (!searchform) return false;

    f();

    var q_raw = searchform.query.value.substr(0, 90);


    if(q_raw.length<1){
//        alert(q_raw);
        top.location.href = searchform.action + '/';
        return false;
    }

    var q_a = q_raw.split(/[\s\\\/\-\+\?\'\"\`,_ ]+/g);
//    alert(q_a);

    var q = '';
    for(i in q_a){
        q_aa = q_a[i].split('/(?=v?(?:\d+?\.)+)(v?(?:\d+?\.?)+)|(\w+)/');
        for(j in q_aa){
            if(q_aa[j] != ''){
                q += '-'+rtrim(q_aa[j]);
            }
        }
    }

//    alert(q);
    var href_str = searchform.action + '/' + encodeURIComponent(ltrim(q.toLowerCase())) + '/';
    top.location.href = href_str;
    return false;
}

