/*
 * Author RIGO MICHELE
 * Funzioni da utilizzare nel caso in qui bisogna passare i dati da una select multipla ad un'altra
 * funzione insert(Go,To) --> sposta i campi selezionati
 * funzione insertAll(Go,To) --> sposta tutti i campi della select 'Go' alla select 'To'
 * parametri : Go --> select di partenza (document.nomeForm.nomeSelect)
 *			   To --> select di arrivo 	(document.nomeForm.nomeSelect)
 */

function insert(Go,To){
	try{
		selected = new Array();
		disabled = new Array();
		while (Go.selectedIndex != -1)
		    {
	        if (Go.selectedIndex != -1){
		    	if(!Go.options[Go.selectedIndex].disabled){
		    	  	selected.push(Go.options[Go.selectedIndex]);
	    	  	}
	    	  	else{
					disabled.push(Go.options[Go.selectedIndex]);	    	  	
	    	  	}
	       }
          	Go.options[Go.selectedIndex] = null;
	    }
		for(var i=0;i<selected.length;i++){
			var opt = new Option(selected[i].text,selected[i].value);
			To.options[To.length] = opt;
		}
		for(var i=0;i<disabled.length;i++){
			var opt = new Option(disabled[i].text,disabled[i].value);
			opt.setAttribute('className','disabled');
			opt.disabled = true;
			Go.options[Go.length] = opt;
		}
		
	}
	catch(e){
		alert(e);
	}
}

function insertAll(Go,To){
	try{
		selected = new Array();
		disabled = new Array();
		for(var i=0;i<Go.length;i++){
			Go.options[i].selected = true;
		}
		while (Go.selectedIndex != -1)
	    {
	        if (Go.selectedIndex != -1){
		        if(!Go.options[Go.selectedIndex].disabled){
		        	selected.push(Go.options[Go.selectedIndex]);
		        }
		        else{
					disabled.push(Go.options[Go.selectedIndex]);	    	  	
	    	  	}
	        }
	        Go.options[Go.selectedIndex] = null;
	        
	    }
		
		for(var i=0;i<selected.length;i++){
			var opt = new Option(selected[i].text,selected[i].value);
			To.options[To.length] = opt;
		}
		for(var i=0;i<disabled.length;i++){
			var opt = new Option(disabled[i].text,disabled[i].value);
			opt.setAttribute('className','disabled');
			opt.disabled = true;
			Go.options[Go.length] = opt;
		}
	}
	catch(e){
		alert(e);
	}	
}

function setSelectedAllLeft(){
		var select = document.getElementById('leftMultiboxSelected');
		for(var i=0;i<select.length;i++){
			select.options[i].selected = true;
		}		
}

function setSelectedAllRight(){
		var select = document.getElementById('rightMultiboxSelected');
		for(var i=0;i<select.length;i++){
			select.options[i].selected = true;
		}		
}


/*
*	Funzione che fa il submit passando il parametro e il form
*/

function redirectWithSelectForm(action,parameter,select){
	var value =	select.options[select.selectedIndex].value;
	document.location.href = action+'?'+parameter+'='+value;
}


/*Funzione che alliena le combo in base alla combo con larghezza maggiore sulla pagina 
 *	author: Rigo Michele
 *  Data: 12/12/2006	
 *  Da inserire all'onload della pagina
 */

	function lengthComboLoad(){
	try{
		var tot = document.getElementsByTagName('select');
		var numberCombo = tot.length;
		var maxWidth = 0;
		if(numberCombo != 0){
			for(var y=0;y<numberCombo;y++){
				var options = tot[y];
				for(var z=0;z<options.length;z++){
					var tmp = options[z].firstChild.nodeValue.length;
					if(tmp > maxWidth){
						maxWidth = tmp;
					}
				}
			}
			if(maxWidth > 5){
				maxWidth = parseInt(maxWidth)*0.70;
				maxWidth = maxWidth+'em';
				for(var i=0;i<numberCombo;i++){
					tot[i].style.setAttribute('width',maxWidth);
				}		
			}
		}
	}
	catch(e){}
	}

function refreshResolution(){

	var minH = 600;
	/*Recupero altezza e larghezza della finestra*/
	if(typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	/*Recupero altezza della header*/
	heightHeader = document.getElementById('header').clientHeight
	
	/*Recupero altezza del footer*/
	heightFooter = document.getElementById('footer').clientHeight
	
	/*Recupero altezza content*/	
	heightContent = document.getElementById('contentInt').clientHeight
	
	/*Recupero altezza della colonna di sinistra*/	
	heightLeft = document.getElementById('columnLeft').clientHeight
	
	/*Recupero altezza della colonna di destra*/	
	try{heightRight = document.getElementById('columnRight').clientHeight	}
	catch(e){}
	
	if(myHeight>minH){
		
		/*Calcolo altezza*/
		height = myHeight-heightFooter-heightHeader-20;
		document.getElementById('contentInt').style.setAttribute('height',height);
		document.getElementById('columnLeft').style.setAttribute('height',height);
		try{document.getElementById('columnRight').style.setAttribute('height',height);}
		catch(e){}
	}
}	
	
function confirmDel() {
	return confirm("Confermi l'eliminazione ?");
}

 




