var enableAjax = true; // jestli se ma strankovat s pomoci ajaxu

/*saveHistory ... da se zakazat aby <back> neuklada  znova
 *
 */
function gotoItemDetail(id){
    var itemDetailUrl = "itemDetail.jsp";
    
    var page = new PageQuery(window.location.search);
    page.setValue("id", id) ;
    var url = window.location.protocol + itemDetailUrl + "?" + page.toString() ;
    var opts = "width=1000,height=575,toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes";

    w = window.open(url, "itemDetail", opts);
    w.focus();
    //window.location = url;
}

function showMoreLess(nav){
    $("#less" + nav).toggle();
    $("#more" + nav).toggle();

}
function removeFilters()
{
    var page = new PageQuery(window.location.search);
    page.removeParam("navigation");
    page.removeParam("defautNavigation");
    page.setValue(fromField, "");
    page.setValue(toField, "");
    var newurl = "?" + page.toString();

    document.location.href = newurl;
}

function sortBy( value ){
    var page = new PageQuery(window.location.search);
    page.setValue("sort", value);
    window.location = window.location.protocol + window.location.pathname + "?" + page.toString();
}

function gotoPageOffset( value ){
    var page = new PageQuery(window.location.search);
    page.setValue("offset", value);
    window.location = window.location.protocol + window.location.pathname + "?" + page.toString();
}

function submitQuery(){
    var page = new PageQuery(window.location.search);
    page.setValue("q", $("#q").val());
    window.location = window.location.protocol + window.location.pathname + "?" + 
        page.toString();
    return false;
}

function addNavigation(navigator, value){
    var page = new PageQuery(window.location.search);
    page.setValue("offset", "0");
    window.location = window.location.protocol + window.location.pathname + "?" + 
        page.toString() + "&fq=" + navigator + ":\"" + value + "\"";
    
    //window.location = url;
}
/* odebrani navigace z url
 *
 */
function removeNavigation(value){
    var url = window.location.href;
    var modToRemove = "&fq=" + value;
    //alert(value + "\n" + modToRemove);
    url = url.replace(new RegExp(modToRemove, "gi"), '');
    modToRemove = "&fq=" + value.split(":")[0] + ":" + encodeURI(value.split(":")[1]);
    url = url.replace(new RegExp(modToRemove, "gi"), '');
    modToRemove = encodeURI("&fq=" + value);
    url = url.replace(new RegExp(modToRemove, "gi"), '');
    modToRemove = "&fq=" + value.split(":")[0] + "%3A" + encodeURI(value.split(":")[1]);
    url = url.replace(new RegExp(modToRemove, "gi"), '');
    modToRemove = "&fq=" + value.split(":")[0] + "%3A" + value.split(":")[1];
    url = url.replace(new RegExp(modToRemove, "gi"), '');
    // osetreni remove pro obdobi, escapovani citlivych znaku
    modToRemove = "&fq=" + value.replace(/\[/,"\\[").replace(/\]/,"\\]").replace(/\s/gi,"%20").replace(/\*/gi,"\\*");
    url = url.replace(new RegExp(modToRemove, "gi"), '');
    window.location = url;
}

function setLaguage(language){
    var page = new PageQuery(window.location.search);
    page.setValue("language", language);
    window.location = window.location.protocol + window.location.pathname + "?" + 
        page.toString();
    
}
