

$(document).ready(function(){

		
	var $aggiungi = $('#aggiungi').html();
	var $rimuovi = $('#rimuovi').html();
	var $reset = $('#reset').html();
	$('#af_component_nazioniextra').append($('<a id="addnat" class="natbutton" name="addnat" href="#addnat">'+$aggiungi+'</a>'));
	$('#af_component_nazioniextra').append($('<a id="subnat" class="natbutton" name="subnat" href="#subnat">'+$rimuovi+'</a>'));
	$('#af_component_addnation').append($('<a id="resetaddnat" class="natbutton" name="resetaddnat" href="#resetaddnat">'+$reset+'</a>'));
	$('#af_component_removenation').append($('<a id="resetsubnat" class="natbutton" name="resetsubnat" href="#resetsubnat">'+$reset+'</a>'));

	$('#addnat').click(function(){
		if ($('#nazioniextra option:selected').val() != "-1") {
			$('#nazioniextra option:selected').appendTo('#addnation');
		}
	});
	$('#subnat').click(function(){
		if ($('#nazioniextra option:selected').val() != "-1") {
			$('#nazioniextra option:selected').appendTo('#removenation');
		}
	});
	$('#resetaddnat').click(function(){
		$('#addnation option:selected').each(function(){
			$(this).appendTo('#nazioniextra');
		});
		selectSort('#nazioniextra');
	});
	$('#resetsubnat').click(function(){
		$('#removenation option:selected').each(function(){
			$(this).appendTo('#nazioniextra');
		});
		selectSort('#nazioniextra');
	});

	$('#Categoria').change(function(){
		$('#navcataloghi').submit();
	});

	/*if (!$('#accetto3').attr('checked')){
		{$('#activity').hide('fast')};
		{$('#seeks').hide('fast')};
		{$('#followindproducts').hide('fast')};


	}
	$('#accetto3').click(function(){
		if ($('#accetto3').attr('checked')){
			$('#activity').show('slow');
			$('#seeks').show('slow');
			$('#followindproducts').show('slow');
		}else{
			$('#activity').hide('slow');
			$('#seeks').hide('slow');
			$('#followindproducts').hide('slow');
		}
	});*/
});


function selectSort(id){
	var $dd = $(id);
	if ($dd.length > 0) { // make sure we found the select we were looking for
		// save the selected value
		var selectedVal = $dd.val();
		
		// get the options and loop through them
		var $options = $('option', $dd);
		var arrVals = [];
		$options.each(function(){
			// push each option value and text into an array
			arrVals.push({
				val: $(this).val(),
				text: $(this).text()
			});
		});
		
		// sort the array by the value (change val to text to sort by text instead)
		arrVals.sort(function(a, b){
		    if(a.val>b.val){
		        return 1;
		    }
		    else if (a.val==b.val){
		        return 0;
		    }
		    else {
		        return -1;
		    }
		});
		
		// loop through the sorted array and set the text/values to the options
		for (var i = 0, l = arrVals.length; i < l; i++) {
			$($options[i]).val(arrVals[i].val).text(arrVals[i].text);
		}
		// set the selected value back
		$dd.val(selectedVal);
	}	
}




/*
<!--
function show_element(element_id) {
	var i = 0;
	do {
		i++;
		var div_element = document.getElementById("Origins_elements_" + i);
		if (div_element) {
			title_element = document.getElementById("title_Origins_elements_" + i);
			if (element_id == i) {
				  $("div#Origins_elements_" + element_id).show("slow");
				//div_element.style.display = 'block';
				//if (title_element) title_element.style.textDecoration = "underline";
				if (title_element) title_element.className = "menu_selected";
				
			}
			else {
				div_element.style.display = 'none';
				if (title_element) title_element.className = "";
				//if (title_element) title_element.style.textDecoration = "none";
			}
		}
	}
	while (div_element); 
}
-->
*/