// JavaScript Document
//<![CDATA[
var cal15 = new CalendarPopup();
cal15.setReturnFunction("setMultipleValues4");
function setMultipleValues4(y,m,d) {
	document.forms['formapp'].date15_year.value=y;
	document.forms['formapp'].date15_month.selectedIndex=m;
	for (var i=0; i<document.forms['formapp'].date15_date.options.length; i++) {
		if (document.forms['formapp'].date15_date.options[i].value==d) {
			document.forms['formapp'].date15_date.selectedIndex=i;
			}
		}
	}
var cal16 = new CalendarPopup();
cal16.setReturnFunction("setMultipleValues5");
function setMultipleValues5(y,m,d) {
	document.forms['formapp'].date16_year.value=y;
	document.forms['formapp'].date16_month.selectedIndex=m;
	for (var i=0; i<document.forms['formapp'].date16_date.options.length; i++) {
		if (document.forms['formapp'].date16_date.options[i].value==d) {
			document.forms['formapp'].date16_date.selectedIndex=i;
			}
		}
	}
function getDateString(y_obj,m_obj,d_obj) {
	var y = y_obj.options[y_obj.selectedIndex].value;
	var m = m_obj.options[m_obj.selectedIndex].value;
	var d = d_obj.options[d_obj.selectedIndex].value;
	if (y=="" || m=="") { return null; }
	if (d=="") { d=1; }
	return str= y+'-'+m+'-'+d;
	}
	function addoption(opt, val, sel)
{var curlen=document.formapp.right.length;
document.formapp.right.options[curlen]=new Option(opt,val,false,sel);}

function addnessuno()
{addoption("----- nessuno -----",-1,false);}

function add()
{		
//cancella --- nessuno -- da destra se c'è
if (document.formapp.right[0].value==-1) document.formapp.right[0]=null;
document.formapp.right.selectedIndex=-1; //deseleziona tutto
 for (var i=0;i<document.formapp.left.length;i++)
    if(document.formapp.left[i].selected)
	 {
	 var present=false;
	 for (var j=0;j<document.formapp.right.length;j++)
		{
	//	document.write ("r="+document.formapp.right[j].value+"l="+document.formapp.left[i].value);
		if (document.formapp.right[j].value==document.formapp.left[i].value)
		 {
		 var present=true;
		 document.formapp.right[j].selected=true; //se già c'è lo seleziona
		 }
		}
	 if (present==false) //se non c'è lo aggiunge selezionato
	  addoption(document.formapp.left[i].text,document.formapp.left[i].value,true);
	 
     }
}

function remove()
{
for (var i=document.formapp.right.length-1;i>=0;i--)
{
    if(document.formapp.right[i].selected)
	{
	document.formapp.right[i]=null;
	}
}
//aggiunge --- nessuno -- se l'array è stato svuotato
if (document.formapp.right.length==0) addnessuno();
}
// ]]>
