function roll(img_name1, img_src1){
	document[img_name1].src = img_src1;
}
function launch( url, name, w, h ) {
	yOffset = 23;
	xOffset = 23;
    pop = window.open( url,name,"width="+w+",height="+h+",status=1,resizable=0,menubar=0,toolbar=0,directories=0,location=0,scrollbars=0,top="+yOffset+",left="+xOffset );
	pop.focus();
}
function redirect(){ document.location='/main.php'; }

function ADD()
{
	var aSelection = new Array();
	var aSelectionText = new Array();
	var aSelect = new Array();
	var aSelectText = new Array();
	var i = 0;
	var len = document.add.selection.options.length;
	var lenSel = document.add.selected.options.length;
	if ((lenSel == 1) && (document.add.selected.options[0].value==""))
	{
		document.add.selected.options[0].value = null;
		document.add.selected.options.length--;
		lenSel--;
	}

	while (i<len)
	{
		if (document.add.selection.options[i].selected == true)
		{
			var bTrovato = false;
			if (lenSel > 0)
			{
				for (j=0; j<lenSel; j++)
				{
					if (document.add.selection.options[i].value == document.add.selected.options[j].value)
					{
						bTrovato = true;
						break;
					}
				}
			}
			if (!bTrovato)
			{
				//confirm(document.add.selection.options[i].text)
				//break;
				aSelect.length++;
				aSelect[aSelect.length-1] = new Array(2);
				aSelect[aSelect.length-1][0] = document.add.selection.options[i].value;
				aSelect[aSelect.length-1][1] = document.add.selection.options[i].text;
			}
			else
			{
			}
		}
		else
		{
			aSelection.length++;
			aSelection[aSelection.length-1] = new Array(2);
			aSelection[aSelection.length-1][0] = document.add.selection.options[i].value;
			aSelection[aSelection.length-1][1] = document.add.selection.options[i].text;
		}
		i++;
	}


	//Popolo la prima selectbox
	aSelection.sort(sortSelectName);
	document.add.selection.options.length=0;
	for (i=0; i<aSelection.length; i++)
	{
		document.add.selection.options.length++;
		document.add.selection.options[i].value=aSelection[i][0];
		document.add.selection.options[i].text=aSelection[i][1];
	}

	//Popolo la seconda selectbox
	for (i=0; i<document.add.selected.options.length; i++)
	{
		aSelect.length++;
		aSelect[aSelect.length-1] = new Array(2);
		aSelect[aSelect.length-1][0] = document.add.selected.options[i].value;
		aSelect[aSelect.length-1][1] = document.add.selected.options[i].text;
	}
	aSelect.sort(sortSelectName);

	document.add.selected.options.length=0;
	for (i=0; i<aSelect.length; i++)
	{
		document.add.selected.options.length++;
		document.add.selected.options[i].value=aSelect[i][0];
		document.add.selected.options[i].text=aSelect[i][1];
	}

}

function sortSelectName(a, b) {
    var x = a[1].toLowerCase();
    var y = b[1].toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function REMOVE()
{
		var aSelection=new Array();
		var aSelectionText = new Array();
		var aSelect=new Array();
		var aSelectText = new Array();
		
		var lenSel = document.add.selected.options.length;
		var i=0;
		if ((lenSel == 1) && (document.add.selected.options[0].value==""))
			return;
		while(i<lenSel)
		{
			if (document.add.selected.options[i].selected == true)
			{
					aSelection.length++;
					aSelection[aSelection.length-1] = new Array(2);
					aSelection[aSelection.length-1][0]=document.add.selected.options[i].value;
					aSelection[aSelection.length-1][1]=document.add.selected.options[i].text;
			}
			else
			{
				aSelect.length++;
				aSelect[aSelect.length-1] = new Array(2);
				aSelect[aSelect.length-1][0] = document.add.selected.options[i].value;
				aSelect[aSelect.length-1][1] = document.add.selected.options[i].text;
			}
			i++;
		}

		//Popolo la prima selectbox
		for (i=0; i<document.add.selection.options.length; i++)
		{
			aSelection.length++;
			aSelection[aSelection.length-1] = new Array(2);
			aSelection[aSelection.length-1][0] = document.add.selection.options[i].value;
			aSelection[aSelection.length-1][1] = document.add.selection.options[i].text;
		}
		
		aSelection.sort(sortSelectName);
		document.add.selection.options.length=0;
		for (i=0; i<aSelection.length; i++)
		{
			document.add.selection.options.length++;
			document.add.selection.options[i].value=aSelection[i][0];
			document.add.selection.options[i].text=aSelection[i][1];
		}
		
		//Popolo la seconda selectBox
		aSelect.sort(sortSelectName);
		document.add.selected.options.length=0;
		for (i=0; i<aSelect.length; i++)
		{
			document.add.selected.options.length++;
			document.add.selected.options[i].value=aSelect[i][0];
			document.add.selected.options[i].text=aSelect[i][1];
		}

		loadEmpty();

}

function loadEmpty()
{
	if (document.add.selected.options.length == 0)
	{
		document.add.selected.options.length++;
		document.add.selected.options[0].text="";
		document.add.selected.options[0].value="";
	}
}

function listsel()
{
	//alert(document.add.selected.options[0].value);
	var szSelection = "";
	if (document.add.selected.options[0].value != "" )
	{
		for (i=0; i<document.add.selected.options.length; i++)
		{
			szSelection = szSelection + document.add.selected.options[i].value +',';
		}
		document.add.content.value=szSelection;
		document.add.submit();
	}
	else{
		alert("Please select one or more images to appear in the feature.");
	}
}