/* ******************************************************** */
/* ************* Inizializzazione funzioni **************** */
/* ******************************************************** */
function initFunctions() { preloadImages(); }


/* **************************************************** */
/* FUNZIONE per aprire una finestra di PopUp centrata   */
/* **************************************************** */
function openPopUp(url,w,h,scrl) {
  l = 50;
  t = 50;
  newWin = window.open(url,"nuovafinestra", "width="+w+", height="+h+", left="+l+", top="+t+", scrollbars="+scrl+", resizable=no") 
  }

/* **************************************************** */
/* FUNZIONE per aprire una finestra di PopUp            */
/* **************************************************** */
function openPopUpAutoRedim(url,l,t) {
  newWin = window.open(url,"nuovafinestra", "left="+l+", top="+t+", scrollbars=no, resizable=yes") 
}


/* ************************************************* */
/* ****** Elemento a comparsa con un click ********* */
/* ************************************************* */
function scambio(id){
	 if (document.getElementById){
   		if(document.getElementById(id).style.display == 'none'){
     		document.getElementById(id).style.display = 'block';
   		} else {
   			document.getElementById(id).style.display = 'none';
   		}
  	}
}


/* **************************************************** */
/* FUNZIONE per cambiare la grandezza del carattere     */
/* **************************************************** */
var min=8;
var max=20;
var def=12;
//Specify affected tags. Add or remove from list:
var tgs = new Array('p','div','td','tr');
function defaultFontSize() {
   for ( q = 0 ; q < tgs.length ; q++ ) {
     cTags = document.getElementsByTagName(tgs[ q ]);
     for(i=0;i<cTags.length;i++) { cTags[i].style.fontSize = def+"px" }
	}
}
function increaseFontSize() {
   for ( q = 0 ; q < tgs.length ; q++ ) {
	   cTags = document.getElementsByTagName(tgs[ q ]);
	   for(i=0;i<cTags.length;i++) {
	      if(cTags[i].style.fontSize) {
	         var s = parseInt(cTags[i].style.fontSize.replace("px",""));
	      } else { var s = 12; }
	      if(s!=max) { s += 1; }
	      cTags[i].style.fontSize = s+"px"
	   }
	}
}
function decreaseFontSize() {
   for ( q = 0 ; q < tgs.length ; q++ ) {
	   cTags = document.getElementsByTagName(tgs[ q ]);
	   for(i=0;i<cTags.length;i++) {
	      if(cTags[i].style.fontSize) {
	         var s = parseInt(cTags[i].style.fontSize.replace("px",""));
	      } else { var s = 12; }
	      if(s!=min) { s -= 1; }
	      cTags[i].style.fontSize = s+"px"
	   }   
	}
}

/* ************************************************* */
/* POPUP CHE SI AUTODIMENSIONA SU UNA IMMAGINE       */
/* ************************************************* */
function PrevFoto(img){
  foto1= new Image()
  foto1.src=(img)
  Controlla(img)
}
function Controlla(img){
  if((foto1.width!=0)&&(foto1.height!=0)){
    viewFoto(img);
  }
  else{
    funzione="Controlla('"+img+"')";
    intervallo=setTimeout(funzione,20);
  }
}
function viewFoto(img){
  largh=foto1.width;
  altez=foto1.height;
  posY=(screen.width-foto1.width)/2;
  posX=(screen.height-foto1.height)/2;
  stringa="width="+largh+",height="+altez+",top="+posX+",left="+posY;
  finestra=window.open(img,"",stringa);
}


/* **************************************************** */
/* ****** FUNZIONE DATA ******************************* */
/* **************************************************** */
function data() {
	thisDate = new Date()
		giorno = thisDate.getDay();
		oggi = thisDate.getDate();
		monthNum = thisDate.getMonth();
		year = thisDate.getYear();
	if (year <=100)
		year=1900+Year;
	
	if (monthNum == 0) NomeMese = "Gennaio ";
		else if (monthNum == 1) NomeMese = "Febbraio ";
		else if (monthNum == 2) NomeMese = "Marzo ";
		else if (monthNum == 3) NomeMese = "Aprile ";
		else if (monthNum == 4) NomeMese = "Maggio ";
		else if (monthNum == 5) NomeMese = "Giugno ";
		else if (monthNum == 6) NomeMese = "Luglio ";
		else if (monthNum == 7) NomeMese = "Agosto ";
		else if (monthNum == 8) NomeMese = "Settembre ";
		else if (monthNum == 9) NomeMese = "Ottobre ";
		else if (monthNum == 10) NomeMese = "Novembre ";
		else if (monthNum == 11) NomeMese = "Dicembre ";
	
	if (giorno == 0) NomeGiorno = "Domenica";
		else if (giorno == 1) NomeGiorno = "Lunedì";
		else if (giorno == 2) NomeGiorno = "Martedì";
		else if (giorno == 3) NomeGiorno = "Mercoledì";
		else if (giorno == 4) NomeGiorno = "Giovedì";
		else if (giorno == 5) NomeGiorno = "Venerdì";
		else if (giorno == 6) NomeGiorno = "Sabato";
	document.write(NomeGiorno+' '+oggi+' '+NomeMese+ ' '+year);
}


/* **************************************************** */
/* ****** FUNZIONE USERS VALIDATE ********************* */
/* **************************************************** */
function usersValidate(form) {
    var gruppo 		= form.gruppo.value;
    var login 		= form.login.value;
    var password 	= form.password.value;
    var nome 		= form.nome.value;
    var cognome 	= form.cognome.value;
    var email 		= form.email.value;

    if (gruppo == "0") {
        alert("ATTENZIONE!!!\n\nSelezionare un GRUPPO");
		form.gruppo.focus();
        return false;
    } 
	if (login == "") {
        alert("ATTENZIONE!!!\n\nIl campo LOGIN è obbligatorio");
		form.login.focus();
        return false;
    } 
	if (login.length < 4) {
        alert("ATTENZIONE!!!\n\nIl campo LOGIN deve contenere almeno 4 caratteri");
		form.login.focus();
        return false;
    } 
	if (password == "") {
        alert("ATTENZIONE!!!\n\nIl campo PASSWORD è obbligatorio");
		form.password.focus();
        return false;
    } 
	if (password.length < 4) {
        alert("ATTENZIONE!!!\n\nIl campo PASSWORD deve contenere almeno 4 caratteri");
		form.password.focus();
        return false;
    } 
	if (nome == "") {
        alert("ATTENZIONE!!!\n\nIl campo NOME è obbligatorio");
		form.nome.focus();
        return false;
    } 
	if (cognome == "") {
        alert("ATTENZIONE!!!\n\nIl campo COGNOME è obbligatorio");
		form.cognome.focus();
        return false;
    } 
	if (email != "")
      if (!ControllaMail(email)) {
        alert("ATTENZIONE!!!\n\nL'indirizzo EMAIL non è valido");
		form.email.focus();
        return false;
	} 
	if (!form.attivo.checked) {
		var agree = confirm("ATTENZIONE!!!\n\nIl campo \'\'ATTIVO\'\' non è stato flaggato\nQuesto record non verrà visualizzato on-line\n\nVuoi continuare?? (OK: si -- Annulla: no)");
		if (agree) {
			form.attivo.checked = false;
			return true;
		}else{
			form.attivo.checked = false;
			form.attivo.focus();
		    return false;
		}
    }
    return true;
}


/* **************************************************** */
/* ****** FUNZIONE FILES VALIDATE ********************* */
/* **************************************************** */
function filesValidate(form) {
	var tipo   = form.tipo.options[form.tipo.selectedIndex].value;
	var nome   = form.nome.options[form.nome.selectedIndex].value;
    var titolo = form.titolo.value;
    
    if (tipo == "") {
        alert("ATTENZIONE!!!\n\nScegliere un TIPO DI FILE dal I° menù a tendina");
		form.tipo.focus();
        return false;
    }
   /* if (tipo != "" && nome == "") {
        alert("ATTENZIONE!!!\n\nSelezionare un FILE dal II° menù a tendina");
		form.nome.focus();
        return false;
    }*/
    if (titolo == "") {
        alert("ATTENZIONE!!!\n\nIl campo TITOLO è obbligatorio");
		form.titolo.focus();
        return false;
    }
	if (!form.attivo.checked) {
		var agree = confirm("ATTENZIONE!!!\n\nIl campo \'\'ATTIVO\'\' non è stato flaggato\nQuesto record non verrà visualizzato on-line\n\nVuoi continuare?? (OK: si -- Annulla: no)");
		if (agree) {
			form.attivo.checked = false;
			return true;
		}else{
			form.attivo.checked = false;
			form.attivo.focus();
		    return false;
		}
    }
    return true;
}


/* **************************************************** */
/* ****** FUNZIONE ANAGRUPPI VALIDATE ***************** */
/* **************************************************** */
function menuValidate(form) {
    var nome = form.nome.value;

    if (nome == "") {
        alert("ATTENZIONE!!!\n\nIl campo NOME MENU è obbligatorio");
		form.nome.focus();
        return false;
    }
	if (!form.attivo.checked) {
		var agree = confirm("ATTENZIONE!!!\n\nIl campo \'\'ATTIVO\'\' non è stato flaggato\nQuesto record non verrà visualizzato on-line\n\nVuoi continuare?? (OK: si -- Annulla: no)");
		if (agree) {
			form.attivo.checked = false;
			return true;
		}else{
			form.attivo.checked = false;
			form.attivo.focus();
		    return false;
		}
    }
    return true;
}


/* ********************************************************* */
/* ****** FUNZIONE DOCUMENTI VALIDATE ********************** */
/* ********************************************************* */
function docsValidate(form) {
    var titolo = form.titolo.value;
    if (titolo == "") {
        alert("ATTENZIONE!!!\n\nIl campo TITOLO è obbligatorio");
		form.titolo.focus();
        return false;
    }
	if (!form.attivo.checked) {
		var agree = confirm("ATTENZIONE!!!\n\nIl campo \'\'ATTIVO\'\' non è stato flaggato\nQuesto record non verrà visualizzato on-line\n\nVuoi continuare?? (OK: si -- Annulla: no)");
		if (agree) {
			form.attivo.checked = false;
			return true;
		}else{
			form.attivo.checked = false;
			form.attivo.focus();
		    return false;
		}
	}
    return true;
}


/* **************************************************** */
/* ****** FUNZIONE NEWS VALIDATE ********************** */
/* **************************************************** */
function galleryImgsValidate(form) {
	var imgid = form.imgid.options[form.imgid.selectedIndex].value;
    
    if (imgid == "") {
        alert("ATTENZIONE!!!\n\nScegliere almeno un\'immagine dal menù a tendina");
		form.imgid.focus();
        return false;
    }
	if (!form.attivo.checked) {
		var agree = confirm("ATTENZIONE!!!\n\nIl campo \'\'ATTIVO\'\' non è stato flaggato\nQuesto record non verrà visualizzato on-line\n\nVuoi continuare?? (OK: si -- Annulla: no)");
		if (agree) {
			form.attivo.checked = false;
			return true;
		}else{
			form.attivo.checked = false;
			form.attivo.focus();
		    return false;
		}
	}
    return true;
}


/* **************************************************** */
/* ****** FUNZIONE LINKS VALIDATE ****************** */
/* **************************************************** */
function linksValidate(form) {
    var nome   = form.nome.value;
    var link   = form.link.value;
	var gruppo = form.gruppo.options[form.gruppo.selectedIndex].value;
    
    if (gruppo == "") {
        alert("ATTENZIONE!!!\n\nScegliere un gruppo dal menù a tendina");
		form.gruppo.focus();
        return false;
    }
    if (nome == "") {
        alert("ATTENZIONE!!!\n\nIl campo NOME LINK è obbligatorio");
		form.nome.focus();
        return false;
    }
    if (link == "") {
        alert("ATTENZIONE!!!\n\nIl campo LINK è obbligatorio");
		form.link.focus();
        return false;
    }
    if (link != "") {
      if (!ControllaURL(link)) {
        alert("ATTENZIONE!!!\n\nL'indirizzo Web inserito non è valido\n\nControlla se è stato inserito http://");
		form.link.focus();
        return false;
      }
	}
	if (!form.attivo.checked) {
		var agree = confirm("ATTENZIONE!!!\n\nIl campo \'\'ATTIVO\'\' non è stato flaggato\nQuesto record non verrà visualizzato on-line\n\nVuoi continuare?? (OK: si -- Annulla: no)");
		if (agree) {
			form.attivo.checked = false;
			return true;
		}else{
			form.attivo.checked = false;
			form.attivo.focus();
		    return false;
		}
	}
    return true;
}


/* **************************************************** */
/* ****** FUNZIONE CONTACTS VALIDATE ****************** */
/* **************************************************** */
function contactsValidate(form) {
    var nome = form.nome.value;
    var mailto = form.mailto.value;

    if (nome == "") {
        alert("ATTENZIONE!!!\n\nIl campo NOME CONTATTO è obbligatorio");
		form.nome.focus();
        return false;
    }
    if (mailto != "") {
      if (!ControllaMail(mailto)) {
        alert("ATTENZIONE!!!\n\nL'indirizzo EMAIL non è valido");
		form.mailto.focus();
        return false;
      }
	}
	if (!form.attivo.checked) {
		var agree = confirm("ATTENZIONE!!!\n\nIl campo \'\'ATTIVO\'\' non è stato flaggato\nQuesto record non verrà visualizzato on-line\n\nVuoi continuare?? (OK: si -- Annulla: no)");
		if (agree) {
			form.attivo.checked = false;
			return true;
		}else{
			form.attivo.checked = false;
			form.attivo.focus();
		    return false;
		}
	}
    return true;
}

// da testare ma dovrebbe essere ok - 18 marzo 2008
/* **************************************************** */
/* ****** FUNZIONE che Verifica la validità della mail  */
/* **************************************************** */
function ControllaMail(mail){	
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;	
	if (espressione.test(mail)) 
		return true;
	else
		return false;
}


/* **************************************************** */
/* ****** FUNZIONE che Verifica la validità dell'URL ** */
/* **************************************************** */
function ControllaURL(dominio){	
var RE = /^http:\/\/(www\.)?[a-zA-Z0-9-]{3,}\.([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-zA-Z]{2,}(\/)?$/;
	//var RE = /^http:\/\/(www\.)?[a-zA-Z0-9-]{3,}\.[a-zA-Z]{2,}(\/)?$/;
	if (RE.test(dominio))
		return true;
	else
		return false;
}

	/*string strRegex = "^(https?://)" 
        + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //user@ 
        + @"(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP- 199.194.52.184 
        + "|" // allows either IP or domain 
        + @"([0-9a-z_!~*'()-]+\.)*" // tertiary domain(s)- www. 
        + @"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // second level domain 
        + "[a-z]{2,6})" // first level domain- .com or .museum 
        + "(:[0-9]{1,4})?" // port number- :80 
        + "((/?)|" // a slash isn't required if there is no file name 
        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
	*/	
 
/* **************************************************** */
/* ****** FUNZIONE CORREGGI DATA ********************** */
/* **************************************************** */
  function nd() {
        var d = document.getElementById('day'  ).value;
		var m = document.getElementById('month').value - 1;
		var y = document.getElementById('year' ).value;
		
  		var dt = new Date(y, m, d);

		// this two fix wrong dates such as 30-feb
		document.getElementById('day').selectedIndex = dt.getDate() - 1;
		document.getElementById('month').selectedIndex = dt.getMonth();
  }

  
/* ****************************************************** */
/* FUNZIONE per togliere cornice ai filmati flash in IE   */
/* ****************************************************** */
function loadswf(swf,w,h){
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"");
	document.write("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\"");
	document.write("width=\""+w+"\" height=\""+h+"\">");
	document.write("<param name='movie' value='"+swf+"' />\n");
	document.write("<param name='quality' value='high' /><param name='wmode' value='transparent' />\n");
	document.write("<embed src=\""+swf+"\" quality=\"high\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\"></embed>");
	document.write("</object>\n");
}

/* ************************************************************* */
/* 2 FUNZIONI per aprire il DIV di aiuto per l'editor di testo   */
/* ************************************************************* */
function overlay(curobj,subobj,w,h){
	if (document.getElementById){
		var subobj=document.getElementById(subobj);
		subobj.style.left=(screen.width-w)/2+"px";
		//distanza fissa e non calcolata
		//subobj.style.top=(screen.height-h)/2+"px"; 
		subobj.style.top=h+"px";
		subobj.style.zIndex=1;
		subobj.style.display="block";
		return false;
	}
	else
	  return true;
}
function overlayclose(subobj){ document.getElementById(subobj).style.display="none" }


/* ************************************************* */
/* ****** COUNTDOWN CARATTERI SULLE TEXTAREA ******* */
/* ************************************************* */
function countChars(d) {
	if (navigator.appName.indexOf("Netscape")>=0 &&
	    parseInt(navigator.appVersion) >=4) { var nn4 = true }
		document.formCMS_edit.testo.onkeydown = countChars;
	if (nn4) document.captureEvents(Event.KEYDOWN);

	var oldString = "";

	if (document.formCMS_edit.testo.value.length> 255) {
        var agree = confirm("Hai raggiunto il numero massimo di caratteri disponibili (255)\n\n• \'\'OK\'\' per svuotare l\'area di testo\n• \'\'Annulla\'\' per visualizzare solo i primi 255 caratteri");
        if (agree) {
			document.formCMS_edit.rimasti.value = 255;
		    document.formCMS_edit.testo.value = "";
			return true;
		}else{
			document.formCMS_edit.rimasti.value = 0;
		    document.formCMS_edit.testo.value = document.formCMS_edit.testo.value.substring(0,255);
			return false;
		}
	} else {
	  document.formCMS_edit.rimasti.value = 255 - document.formCMS_edit.testo.value.length;
	  oldString = document.formCMS_edit.testo.value.substring(0,255);
	}
}


/* **************************************************** */
/* ****** FUNZIONE bubble tooltips ******************** */
/* **************************************************** */
function enableTooltips(id){
	var links,i,h;
	if(!document.getElementById || !document.getElementsByTagName) return;
	AddCss();
	h=document.createElement("span");
	h.id="btc";
	h.setAttribute("id","btc");
	h.style.position="absolute";
	document.getElementsByTagName("body")[0].appendChild(h);
	if(id==null) links=document.getElementsByTagName("a");
	else links=document.getElementById(id).getElementsByTagName("a");
	for(i=0;i<links.length;i++){ Prepare(links[i]); }
}

function Prepare(el){
	var tooltip,t,b,s,l;
	t=el.getAttribute("title");
	if(t==null || t.length==0) t="link:";
	el.removeAttribute("title");
	tooltip=CreateEl("span","tooltip");
	s=CreateEl("span","top");
	s.appendChild(document.createTextNode(t));
	tooltip.appendChild(s);
	b=CreateEl("b","bottom");
	l=el.getAttribute("href");
	if(l.length>30) l=l.substr(0,27)+"...";
	//commentato per non far comparire il link in fondo al tooltip
	//b.appendChild(document.createTextNode(l)); 
	tooltip.appendChild(b);
	setOpacity(tooltip);
	el.tooltip=tooltip;
	el.onmouseover=showTooltip;
	el.onmouseout=hideTooltip;
	el.onmousemove=Locate;
}

function showTooltip(e){
	document.getElementById("btc").appendChild(this.tooltip);
	Locate(e);
}

function hideTooltip(e){
	var d=document.getElementById("btc");
	if(d.childNodes.length>0) d.removeChild(d.firstChild);
}

function setOpacity(el){
	el.style.filter="alpha(opacity:95)";
	el.style.KHTMLOpacity="0.95";
	el.style.MozOpacity="0.95";
	el.style.opacity="0.95";
}

function CreateEl(t,c){
	var x=document.createElement(t);
	x.className=c;
	x.style.display="block";
	return(x);
}

function AddCss(){
	var l=CreateEl("link");
	l.setAttribute("type","text/css");
	l.setAttribute("rel","stylesheet");
	l.setAttribute("href","bt.css");
	l.setAttribute("media","screen");
	document.getElementsByTagName("head")[0].appendChild(l);
}

function Locate(e){
var posx=0,posy=0;
if(e==null) e=window.event;
if(e.pageX || e.pageY){ posx=e.pageX; posy=e.pageY; }
else if(e.clientX || e.clientY){
    if(document.documentElement.scrollTop){
        posx=e.clientX+document.documentElement.scrollLeft;
        posy=e.clientY+document.documentElement.scrollTop;
        }
    else{
        posx=e.clientX+document.body.scrollLeft;
        posy=e.clientY+document.body.scrollTop;
        }
    }
document.getElementById("btc").style.top=(posy+10)+"px";
document.getElementById("btc").style.left=(posx-20)+"px";
}


/* **************************************************** */
/* ************** FUNZIONE MOLTI-A-MOLTI ************** */
/* **************************************************** */
var fromBoxArray = new Array();
var toBoxArray = new Array();
var selectBoxIndex = 0;
var arrayOfItemsToSelect = new Array();

function moveSingleElement() {
	var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,'');
	var tmpFromBox;
	var tmpToBox;
	if(this.tagName.toLowerCase()=='select'){			
		tmpFromBox = this;
		if(tmpFromBox==fromBoxArray[selectBoxIndex])tmpToBox = toBoxArray[selectBoxIndex]; else tmpToBox = fromBoxArray[selectBoxIndex];
	}else{
		if(this.value.indexOf('>')>=0){
			tmpFromBox = fromBoxArray[selectBoxIndex];
			tmpToBox = toBoxArray[selectBoxIndex];			
		}else{
			tmpFromBox = toBoxArray[selectBoxIndex];
			tmpToBox = fromBoxArray[selectBoxIndex];	
		}
	}
	
	for(var no=0;no<tmpFromBox.options.length;no++){
		if(tmpFromBox.options[no].selected){
			tmpFromBox.options[no].selected = false;
			tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);
			
			for(var no2=no;no2<(tmpFromBox.options.length-1);no2++){
				tmpFromBox.options[no2].value = tmpFromBox.options[no2+1].value;
				tmpFromBox.options[no2].text = tmpFromBox.options[no2+1].text;
				tmpFromBox.options[no2].selected = tmpFromBox.options[no2+1].selected;
			}
			no = no -1;
			tmpFromBox.options.length = tmpFromBox.options.length-1;
		}			
	}
	
	var tmpTextArray = new Array();
	for(var no=0;no<tmpFromBox.options.length;no++){
		tmpTextArray.push(tmpFromBox.options[no].text + '___' + tmpFromBox.options[no].value);			
	}
	tmpTextArray.sort();
	var tmpTextArray2 = new Array();
	for(var no=0;no<tmpToBox.options.length;no++){
		tmpTextArray2.push(tmpToBox.options[no].text + '___' + tmpToBox.options[no].value);			
	}		
	tmpTextArray2.sort();
	
	for(var no=0;no<tmpTextArray.length;no++){
		var items = tmpTextArray[no].split('___');
		tmpFromBox.options[no] = new Option(items[0],items[1]);
	}		
	
	for(var no=0;no<tmpTextArray2.length;no++){
		var items = tmpTextArray2[no].split('___');
		tmpToBox.options[no] = new Option(items[0],items[1]);			
	}
}

function sortAllElement(boxRef) {
	var tmpTextArray2 = new Array();
	for(var no=0;no<boxRef.options.length;no++){
		tmpTextArray2.push(boxRef.options[no].text + '___' + boxRef.options[no].value);			
	}		
	tmpTextArray2.sort();		
	for(var no=0;no<tmpTextArray2.length;no++){
		var items = tmpTextArray2[no].split('___');
		boxRef.options[no] = new Option(items[0],items[1]);			
	}		
}

function moveAllElements() {
	var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,'');
	var tmpFromBox;
	var tmpToBox;		
	if(this.value.indexOf('>')>=0){
		tmpFromBox = fromBoxArray[selectBoxIndex];
		tmpToBox = toBoxArray[selectBoxIndex];			
	}else{
		tmpFromBox = toBoxArray[selectBoxIndex];
		tmpToBox = fromBoxArray[selectBoxIndex];	
	}
	
	for(var no=0;no<tmpFromBox.options.length;no++){
		tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);			
	}	
	tmpFromBox.options.length=0;
	sortAllElement(tmpToBox);
}

/* This function highlights options in the "to-boxes". 
   It is needed if the values should be remembered after submit. 
   Call this function onsubmit for your form */
function multipleSelectOnSubmit() {
	for(var no=0;no<arrayOfItemsToSelect.length;no++){
		var obj = arrayOfItemsToSelect[no];
		for(var no2=0;no2<obj.options.length;no2++){
			obj.options[no2].selected = true;
		}
	}
}

function createMovableOptions(fromBox,toBox,totalWidth,totalHeight,labelLeft,labelRight) {		
	fromObj = document.getElementById(fromBox);
	toObj = document.getElementById(toBox);
	
	arrayOfItemsToSelect[arrayOfItemsToSelect.length] = toObj;
	
	fromObj.ondblclick = moveSingleElement;
	toObj.ondblclick = moveSingleElement;
	
	fromBoxArray.push(fromObj);
	toBoxArray.push(toObj);
	
	var parentEl = fromObj.parentNode;
	
	var parentDiv = document.createElement('DIV');
	parentDiv.className='multipleSelectBoxControl';
	parentDiv.id = 'selectBoxGroup' + selectBoxIndex;
	parentDiv.style.width = totalWidth + 'px';
	parentDiv.style.height = totalHeight + 'px';
	parentDiv.style.textAlign = 'center';
	parentEl.insertBefore(parentDiv,fromObj);
	
	var subDiv = document.createElement('DIV');
	subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
	fromObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
	
	var label = document.createElement('SPAN');
	label.innerHTML = labelLeft;
	subDiv.appendChild(label);
	
	subDiv.appendChild(fromObj);
	subDiv.className = 'multipleSelectBoxDiv';
	parentDiv.appendChild(subDiv);
	
	var buttonDiv = document.createElement('DIV');
	buttonDiv.style.verticalAlign = 'middle';
	buttonDiv.style.paddingTop = (totalHeight/2) - 50 + 'px';
	buttonDiv.style.width = '30px';
	buttonDiv.style.textAlign = 'center';
	parentDiv.appendChild(buttonDiv);
	
	var buttonRight = document.createElement('INPUT');
	buttonRight.type='button';
	buttonRight.value = '>';
	buttonRight.style.textAlign = 'center';
	buttonDiv.appendChild(buttonRight);	
	buttonRight.onclick = moveSingleElement;	
	
	var buttonAllRight = document.createElement('INPUT');
	buttonAllRight.type='button';
	buttonAllRight.value = '>>';
	buttonAllRight.style.textAlign = 'center';
	buttonAllRight.onclick = moveAllElements;
	buttonDiv.appendChild(buttonAllRight);		
	
	var buttonLeft = document.createElement('INPUT');
	buttonLeft.style.marginTop='10px';
	buttonLeft.type='button';
	buttonLeft.value = '<';
	buttonLeft.style.textAlign = 'center';
	buttonLeft.onclick = moveSingleElement;
	buttonDiv.appendChild(buttonLeft);		
	
	var buttonAllLeft = document.createElement('INPUT');
	buttonAllLeft.type='button';
	buttonAllLeft.value = '<<';
	buttonAllLeft.style.textAlign = 'center';
	buttonAllLeft.onclick = moveAllElements;
	buttonDiv.appendChild(buttonAllLeft);
	
	var subDiv = document.createElement('DIV');
	subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
	toObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
	
	var label = document.createElement('SPAN');
	label.innerHTML = labelRight;
	subDiv.appendChild(label);
			
	subDiv.appendChild(toObj);
	parentDiv.appendChild(subDiv);		
	
	toObj.style.height = (totalHeight - label.offsetHeight) + 'px';
	fromObj.style.height = (totalHeight - label.offsetHeight) + 'px';
	
	selectBoxIndex++;
}

