
// Displays advanced search box, hides link for showing and displays link for hiding advanced box
function displayAdvancedSearchForm() {
  try {
    showAdvancedTab("adv_quick");
    $("#adv_hide_link").show();
    $("#adv_link").hide();
    $("#adv").show();
    isAdvancedSearchLoaded = true;
  } catch (e) {}
}
    
// Hides advanced box, shows link for showing and hides link for hiding advanced box
function hideAdvancedSearchForm() {
  try {
    $("#adv_hide_link").hide();
    $("#adv_link").show();
    $("#adv").hide();
  } catch (e) {}
}

// Changes between tabs
function showAdvancedTab(tab) {
  try {
  
    // First we turn them of all
    var divs = $('#adv_tabs > div');
    for (i = 0; i < divs.length; i++) {
      if ($(divs[i]).hasClass('advanced_tab') == true) {
        $(divs[i]).hide();
      }
    }
    
    $('#link_adv_quick').removeClass();
    $('#link_adv_concept').removeClass();
    $('#link_adv_people').removeClass();
    $('#link_adv_scene').removeClass();
    $('#link_' + tab).addClass('selecttab');
    
    // Than turn on the chosen one
    $("#" + tab).show();
    
  } catch (e) { }
}

// Update simple text
function updateSimpleText() {
  try {
    var searchbox = $('#searchTextHorni');
    searchbox.val('');

    include = $('#search_include').val().split(' ');
    for (i=0; i < include.length; i++) {
      if (include.length > 0) {
        var val = searchbox.val();
        searchbox.val(val + (searchbox.val().length > 0 ? ' ' : '') + include[i]);
      }
    }

   exclude = $('#search_exclude').val().split(' ');
    for (i=0; i < exclude.length; i++) {
      if (exclude[i].length > 0) {
        var val = searchbox.val();
        searchbox.val(val + (searchbox.val().length > 0 ? ' ' : '') + '-' + exclude[i]);
      }
    }
  } catch (e) { }
}

// Resets form - because of setting values after search action, we cannot use just form.reset(),
// so it goes through form.elements[] and unsets checkboxes, selects and text inputs manually
function resetForm() {
  try {
  
    var topSearch = $("#topSearchForm");
    $("input,select", topSearch).each(function (el) {
      
      if ($(this).attr('type') == 'checkbox' || $(this).attr('type') == 'radio') {
      
        $(this).attr('checked', false);
        
      } else if ($(this).attr('type') == 'select-multiple') {
      
        $("option", $(this)).each(function (opt) {
          $(this).attr('selected', false);
        });
        
      } else if ($(this).attr('type') == 'text') {
      
        $(this).val('');
        
      }
      
    });

    $('#adv_clear').hide();
    
  } catch (e) {  }
}


// Showing clear link (yes|no)
function showClearLink() {
  try {
    var show = false;
    var topSearch = $("#topSearchForm");
    $("input,select", topSearch).each(function (el) {
      
      if (!$(this).is(':hidden')) {
        
        if ($(this).attr('type') == 'checkbox' && $(this).attr('checked') == true) {
          if ($(this).attr('name') != "collection[]") {
            show = true;
          }
        } else if ($(this).attr('type') == 'select-multiple' && $(this).get(0).selectedIndex != -1) {
          show = true;
        } else if ($(this).attr('type') == 'text' && $(this).val() != '') {
          show = true;
        }
        
      }
      
    });
    
    if (show == true) {
      $('#adv_clear').show();
    } else {
      $('#adv_clear').hide();
    }
  } catch (e) {  }
}

// prepina advanced search po realoadu
// Not sure what this actually does...
function showAdvancedSearch(section) {
    displaySearch = readCookie("displaySearch");
    if (displaySearch == 1) {
      menuZobraz('advanced_search_form');
      zmenZnamenkoAdvanced(section)
    }
}

// Clear option of chosen selection
function clearOption(nameOption) {
  try {
    $("option", $("#"+nameOption)).each(function(el) {
      $(this).attr('selected', false);
    });
    
    showClearLink();
    $("#" + nameOption + '_Link').hide();
  } catch (e) { }
}

// Show clear option 
function showClearOptionLink(nameLink, value) {
  var showLink = false;
  if (value != 'undefined') {
    showLink = true;
  }
  if (showLink == true) {
    $("#"+nameLink).show();
  } else {
    $("#"+nameLink).hide();
  }
}

// Empty function
function synchroniseInputs() {
}

