// -----------------------------------------------------------------------------------


/**
*	Aggiungo un tag
*/
function initTags(valore, tagline) {
	if(valore.length > 0) 
	{
		var tags = valore.split(',');
		if(tags.length > 0)
		{
			for(i=0; i<tags.length; i++)
			{
				tagline.push(tags[i]);
				tag_id = 'tag_' + tags[i];
				$(tag_id).addClass('tagged');
			}
		}	
	}
}

// -----------------------------------------------------------------------------------

/**
*	Aggiungo un tag
*/
function switchTag(caller, tag, dove, tagline)
{

	// lo imposto come on / off
	if($(caller).hasClass('tagged')) {
		$(caller).removeClass('tagged');
		$(caller).addClass('untagged');
	} else {
		$(caller).removeClass('untagged');
		$(caller).addClass('tagged');
	}
	
	var trovato = false;
	
	// cerco nell'array se esiste già la variabile
	for(i=0; i<tagline.length; i++)
	{
		if(tag == tagline[i]) {
			trovato = true;
			tagline.splice(i, 1);
		}
	}
	
	if(trovato == false)
	{
		tagline.push(tag);
	}
	
	var uscita = tagline.join(',');
	document.getElementById(dove).value = uscita;

	return true;
}

// -----------------------------------------------------------------------------------