function closeLR(){
	setTimeout("getId('BN_LAYER').style.display='none'", 30000);
}
function rotateBN(field, first){
	if( first == null )
		var first = 1;
	
	var item;
	for( i=0; i<field.length; ++i ){
		 item = field[i];

		 if( !item )
			 continue;
			 
		 var tt = null;
		 for( j=0; j<item.length; ++j ){
			 if( document.getElementById(item[j]).style.display=="" ){
			     document.getElementById(item[j]).style.display="none";
			 	 if( tt == null )
				 	 tt = j;
			 }
		 }
		 if( !item[tt+1] || first )
		 	 document.getElementById(item[0]).style.display="";
		 else
		 	 document.getElementById(item[tt+1]).style.display="";
	}	
	
	setTimeout(function(){
  		rotateBN(field, 0);
	}, 15000);
}

function addSeparatorsNF(nStr, inD, outD, sep){
	nStr += '';
	var dpos = nStr.indexOf(inD);
	var nStrEnd = '';
	if (dpos != -1) {
		nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
		nStr = nStr.substring(0, dpos);
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(nStr)) {
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
	return nStr + nStrEnd;
}

function openWindow(mypage,myname,w,h,resizable,scrollbars){ 
	w = (Number(w) + 1);
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0; 
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'scrollbars='+scrollbars+',resizable='+resizable+',status=no,height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
	win = window.open(mypage,myname,settings);
}

function goto(url){
	location.href=url;
}

function redirect(redirect){
	setTimeout("location.href='"+redirect+"'", 2000);
}

function addOption(Sel, theText, theValue){
	if( theText != '' ){
		var theSel = document.getElementById(Sel+'');
		var check = true;
		for( var i=theSel.length-1; i>=0; i-- ){
			 if( theSel.options[i].text == theText ){
				 alert("Elemento già presente nella lista!");
				 check = false;
				 return false;
			 }
		}
		if( check ){
			var newOpt = new Option(theText, theValue);
			theSel.options[theSel.length] = newOpt;
			
			return true;
		}
	}
}

function deleteOption(Sel, theIndex){
	var theSel = document.getElementById(Sel+'');
	if( theSel.length>0 )
		theSel.options[theIndex] = null;
}

function deleteOptions(From){
	var theSelFrom = document.getElementById(From+'');
	for( var i=theSelFrom.length-1; i>=0; i-- ){
		 if( theSelFrom.options[i].selected )
			 deleteOption(From, i);
	}
}

function selectAll(Sel){
	var theSel = document.getElementById(Sel+'');
	if( !theSel.options.length && document.getElementById('st1').checked == false ){
		document.getElementById('dv1').checked = 1;
		document.getElementById('sd1').checked = 1;
	}
	
	for( i=0; i<theSel.options.length; i++ ){
		 theSel.options[i].selected = 1;
	}
	return true;
}

function moveUpDown(From, to){
	var list = document.getElementById(From+'');
	var index = list.selectedIndex;
	var total = list.options.length-1;
	
	if(index == -1) return false;
	if(to == +1 && index == total) return false;
	if(to == -1 && index == 0) return false;
	
	var items = new Array;
	var values = new Array;
	
	for( i = total; i >= 0; i-- ){
		 items[i] = list.options[i].text;
		 values[i] = list.options[i].value;
	}
	for( i = total; i >= 0; i-- ){
		 if( index == i ){
			 list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
			 list.options[i] = new Option(items[i + to], values[i]);
			 i--;
		 }else{
			list.options[i] = new Option(items[i], values[i]);
		 }
	}
}

function setLista(Sel, From){
	var theSel = document.getElementById(Sel+'');
	var theSelFrom = document.getElementById(From+'');

	var stroptions = "";
	for( i = 0; i <= theSelFrom.options.length-1; i++ ){
		 if (i!=0) stroptions += "#$#";
		 stroptions += theSelFrom.options[i].text;
	}
	theSel.value = stroptions;
}

function returnSelection(radioButton){
	var selection=null;
	for( var i=0; i<radioButton.length; i++ ){
		 if( radioButton[i].checked ){
		     selection=radioButton[i].value;
		     return selection;
		 }
	}
	return selection; 
} 

function getId(id){
	var element = document.getElementById(id+"");	
	return element;
}

// simplePreload( '01.gif', '02.gif' );
function simplePreload(){
  	 var args = simplePreload.arguments;
  	 document.imageArray = new Array(args.length);
  	 for(var i=0; i<args.length; i++)
  	 {
    	 document.imageArray[i] = new Image;
    	 document.imageArray[i].src = args[i];
  	 }
}

function stampDate(){
	var months = new Array(12);
	months[0]  = "gennaio";
	months[1]  = "febbraio";
	months[2]  = "marzo";
	months[3]  = "aprile";
	months[4]  = "maggio";
	months[5]  = "giugno";
	months[6]  = "luglio";
	months[7]  = "agosto";
	months[8]  = "settembre";
	months[9]  = "ottobre";
	months[10] = "novembre";
	months[11] = "dicembre";
	
	var days = new Array(6);
	days[0]  = "Domenica";
	days[1]  = "Lunedì";
	days[2]  = "Martedì";
	days[3]  = "Mercoledì";
	days[4]  = "Giovedì";
	days[5]  = "Venerdì";
	days[6]  = "Sabato";

	var data 	= new Date();
	var lday    = days[data.getDay()];
	var lmonth  = months[data.getMonth()];
	var date 	= data.getDate();
	var year	= data.getYear();
	if( year < 1900 )
		year+=1900;
	
	var date_div = document.getElementById('day');
	date_div.innerHTML = lday + ", " + date + " " + lmonth + " " + year;
}

function stampClock(){
	var clock_time = new Date();
	var clock_hours = clock_time.getHours();
	var clock_minutes = clock_time.getMinutes();
	var clock_seconds = clock_time.getSeconds();
	
	if (clock_hours < 10){
		clock_hours = "0" + clock_hours;
	}
	if (clock_minutes < 10){
		clock_minutes = "0" + clock_minutes;
	}
	if (clock_seconds < 10){
		clock_seconds = "0" + clock_seconds;
	}
	
	var clock_div = document.getElementById('clock');
	clock_div.innerHTML = clock_hours + ":" + clock_minutes + ":" + clock_seconds;
	
	setTimeout("stampClock()", 1000);
}

