// Copyright Marcus Engene / pond5 INC all rights reserved.

P5.Search = {};

P5.Search.getQ = function ()
{
    var searchstr = P5._q.strip();
    var query = encodeURIComponent(searchstr);
    if ('' !== query) {
        return 'q=' + query;
    }
    return '';
};

P5.Search.ordbyChange = function (in_noe)
{
    var qPart = P5.Search.getQ();
    P5.setP5Cookie('sb',$("searchob" + in_noe).value);
    window.location = '/public-bins' + (('' !== qPart) ? '?' + qPart : '');
};

// TODO not used?
P5.Search.rppChange = function (in_noe)
{
    var qPart = P5.Search.getQ();
    P5.setP5Cookie('no',$("searchrpp" + in_noe).value);
    window.location = '/public-bins' + (('' !== qPart) ? '?' + qPart : '');
};

P5.Search.advGo = function (special)
{
    var sb = $("searchob0");
    var qPart = P5.Search.getQ();
    var tt;
    if (sb) {
        if (1 == P5._search_sort_reverse && 100 > sb.value) {
            tt = parseInt(sb.value,10) + 100;
            P5.setP5Cookie('sb',tt);
        }
        if (0 === P5._search_sort_reverse && 100 <= sb.value) {
            tt = parseInt(sb.value,10) - 100;
            P5.setP5Cookie('sb',tt);
        }
    }
    
    var url = "/public-bins";
    if ("" !== qPart) {
        url += "?" + qPart;
    }
    window.location = url;
};


