var filters = new Array();

function contains_filter(idspec, idval) {
  for (var idx = 0; idx < filters.length; idx++) {
    if (idspec == filters[idx].idspec && idval == filters[idx].idval) {
      return idx;
    }
  }
  return -1;
}

function filter_add(idspec, idval, change_cb) {
  if (change_cb) {
    var cb = document.getElementById('cb_ids' + idspec + 'idv' + idval);
    //cb.checked = !cb.checked;
	cb.checked = change_cb;
  }
  
  var filter = new Object();
  filter.idspec = idspec;
  filter.idval = idval;
  
  var index = contains_filter(idspec, idval);
  if (index == -1) {
    filters.push(filter);
  } else {
    filters.splice(index, 1);
  }
}

function get_filters_url() {
  try {
    var url = '/' + (link != '' ? link  + '/' : '') + (link_cat != '' ? link_cat  + '/' : '') + (link_subcat != '' ? link_subcat  + '/' : '') + 'filtre/';
    for (var idx = 0; idx < filters.length - 1; idx++) {
      var filter = filters[idx];
      url += '' + filter.idspec + '-' + filter.idval + '_';
    }
    url += '' + filters[filters.length - 1].idspec + '-' + filters[filters.length - 1].idval;
    
    if (document.getElementById('pmin').value != '') {
      url += '_n-' + document.getElementById('pmin').value;
    }
    if (document.getElementById('pmax').value != '') {
      url += '_m-' + document.getElementById('pmax').value;
    }
    window.location = url + '.html';
  } catch (e) {
    try {
        if (document.getElementById('pmin').value != '') {
            url += 'n-' + document.getElementById('pmin').value;
            if (document.getElementById('pmax').value != '') {
                url += '_m-' + document.getElementById('pmax').value;
            }
        } else {
            if (document.getElementById('pmax').value != '') {
                url += 'm-' + document.getElementById('pmax').value;
            }
        }
        
        if (document.getElementById('pmin').value == '' && document.getElementById('pmax').value == '') {
            window.location = '/' + (link != '' ? link  + '/' : '') + (link_cat != '' ? link_cat  + '/' : '') + (link_subcat != '' ? link_subcat  + '/' : '');
        } else {
            window.location = url + '.html';
        }
    } catch (e2) {
        window.location = '/' + (link != '' ? link  + '/' : '') + (link_cat != '' ? link_cat  + '/' : '') + (link_subcat != '' ? link_subcat  + '/' : '');
    }
  
  }
  //return url;
}

