function IE_workon(id) {
    jQuery('#'+id).empty();
    jQuery('#'+id).append(_listeOptions[id]);
    jQuery('#'+id).val(0);
}


function IE_update(id) {
    jQuery('#'+id).children('option:hidden').remove();
    jQuery('#'+id).val(0);
}



function filtreCategorie() {
	
	jQuery('.bord_arrondi').css('position', 'absolute');
	
	var sgc = document.rechercher_form.rc_gcategorie;
	
	var sc = document.rechercher_form.rc_categorie;
	var id_gc = sgc.options[sgc.selectedIndex].value;
	
	IE_workon('rc_categorie');
	IE_workon('rc_label');
		
	if (jQuery('#rc_gcategorie').val()!=0) {
		
		var sc = document.rechercher_form.rc_categorie;
		var nbc = sgc.options.length;
		
		
		
		jQuery('#rc_categorie option').hide();
		jQuery('#rc_categorie option[value=0]').show();
		
		jQuery('.rc_categorie_'+id_gc).show();
		
		
		jQuery('#pc_label').show();
		
	
		jQuery('#rc_label option').hide();
		jQuery('#rc_label option[value=0]').show();
		
		jQuery('.rc_label_'+id_gc).show();
		jQuery('#rc_label').val(0);
		
		ll = jQuery("#rc_label option[value!=0]:visible").length;
		
		if (ll==0) {
			jQuery('#pc_label').hide();
			jQuery('#rc_label').val(0);
		}

	}
	else {
		jQuery('#rc_categorie option').show();
		
		jQuery('#pc_label').hide();
		jQuery('#rc_label').val(0);
	}
	
	sc.options[0].selected = true;
	lsc = jQuery("#rc_categorie option:visible").length;
	
	
	if (lsc==1 && sc.options[0].value==0)
	jQuery("#pc_categorie").hide();
	else
	jQuery("#pc_categorie").show();
	
	
	IE_update('rc_categorie');
	IE_update('rc_label');
	
	/*if (ll==1 && jQuery('#rc_label').val()==0)
	jQuery("#pc_label").hide();
	else
	jQuery("#pc_label").show();*/
	
	jQuery('.bord_arrondi, .bord_arrondi_inte').css('bottom', '0px');
	
}


function filtreCommune() {
	
	var sgc = document.rechercher_form.rc_zone;
	var sc = document.rechercher_form.rc_commune;
	
	var id_gc = sgc.options[sgc.selectedIndex].value;
	
	IE_workon('rc_commune');
	
	if (id_gc!=0) {
		
		var sc = document.rechercher_form.rc_commune;
		var nbc = sgc.options.length;
		
		
		
		jQuery('#rc_commune option').hide();
		jQuery('#rc_commune option[value=0]').show();
		
		jQuery('.rc_commune_'+id_gc).show();
		
		

	}
	else
	jQuery('#rc_commune option').show();
	
	sc.options[0].selected = true;
	
	lsc = jQuery("#rc_commune option:visible").length;
	
	
	if (lsc==1 && sc.options[0].value==0)
	jQuery("#pc_commune").hide();
	else
	jQuery("#pc_commune").show();
	
	IE_update('rc_commune');
	
}

function filtreClassification() {
	
	//jQuery('#rc_classification').css('width', (jQuery('#rc_classification').width()-50)+"px");
	var opt = jQuery('#rc_classification option:selected');

	
	if (opt.hasClass('DEN')) {
		
		jQuery('#rc_nivclass').show();
		if (jQuery('#rc_classification').width()!=0)
		jQuery('#rc_classification').css('width', (jQuery('#rc_classification').width()-50)+"px");
	}
	else {
		
		if (jQuery('#rc_classification').width()!=0 && jQuery('#rc_nivclass').is(":visible"))
		jQuery('#rc_classification').css('width', (jQuery('#rc_classification').width()+50)+"px");
		jQuery('#rc_nivclass').val(0);
		jQuery('#rc_nivclass').hide();
		
	}
	

}

function filtreInit() {
	
	_listeOptions = new Array();
	_listeOptions['rc_categorie'] = jQuery('#rc_categorie').html();
	_listeOptions['rc_commune'] = jQuery('#rc_commune').html();
	_listeOptions['rc_label'] = jQuery('#rc_label').html();
	
	filtreCategorie();
	//filtreLabel();
	filtreClassification();
	filtreCommune();
	//jQuery('select[name^="rc_"] option[value=0]').attr('selected', 'selected');
	
	
}
