/* questo script, se non diversamente specificato, e' di proprieta' intellettuale di INTERNEXT S.n.c. E' severamente vietato l'uso non autorizzato di tutto o parte del programma */

function nulla() {}

function getRefToDiv(divID) {
    if( document.layers ) { //Netscape layers
        return document.layers[divID]; }
    if( document.getElementById ) { //DOM; IE5, NS6, Mozilla, Opera
        return document.getElementById(divID); }
    if( document.all ) { //Proprietary DOM; IE4
        return document.all[divID]; }
    if( document[divID] ) { //Netscape alternative
        return document[divID]; }
    return false;
}

function showDiv(divID) {
	var myReference = getRefToDiv(divID);
	if( !myReference ) { window.alert('Nothing works in this browser'); return; }
	if( myReference.style ) { myReference.style.visibility = 'visible'; } else {
		if( myReference.visibility ) { myReference.visibility = 'show'; } else {
			window.alert('Nothing works in this browser'); return; } }
}

function hideDiv(divID) {
	var myReference = getRefToDiv(divID);
	if( !myReference ) { window.alert('Nothing works in this browser'); return; }
	if( myReference.style ) { myReference.style.visibility = 'hidden'; } else {
		if( myReference.visibility ) { myReference.visibility = 'hide'; } else {
			window.alert('Nothing works in this browser'); return; } }
}

function posDiv(divID,xpos,ypos) { // posiziona il div
	var myReference = getRefToDiv(divID), noPx = document.childNodes ? 'px' : 0;
	if( !myReference ) { window.alert('Nothing works in this browser'); return; }
	if( myReference.style ) { myReference = myReference.style; }
	myReference.left = xpos + noPx; myReference.top = ypos + noPx; 
}

function mvDiv(divID,deltax,deltay) { // muove il div di .. px
	var myReference = getRefToDiv(divID), noPx = document.childNodes ? 'px' : 0;
	if( !myReference ) { window.alert('Nothing works in this browser'); return; }
	if( myReference.style ) { myReference = myReference.style; }
	myReference.left = ( parseInt(myReference.left) + deltax ) + noPx;
	myReference.top  = ( parseInt(myReference.top)  + deltay ) + noPx;
}

function centerDiv(divID) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
		}
	}

	var myReference = getRefToDiv(divID);
	if( !myReference ) { window.alert('Nothing works in this browser'); return; }
	if( myReference.style ) { myReference = myReference.style; }
	var myDivWidth = parseInt(myReference.width);
	var myDivHeight= parseInt(myReference.height);
	var myDivTop   = parseInt(myReference.top);
	var myDivLeft  = parseInt(myReference.left);
	var newx=(myWidth-myDivWidth)/2; if(newx<0){newx=0}
	var newy=(myHeight-myDivHeight)/2; if(newy<0){newy=0}
	var deltax=newx-myDivLeft;
	var deltay=newy-myDivTop;
	
	posDiv(divID,newx,newy);
	
	//ora centra tutti gli altri
	for (var i=1; i<NomiDiv.length; i++) {
		if (NomiDiv[i] != divID) {
			mvDiv(NomiDiv[i],deltax,deltay);
		}
	}

	
	if (window.scrollbars) {
		if (myHeight-myDivHeight>0 && myWidth-myDivWidth>0) {
			window.scrollbars.visible = false;
		} else {
			window.scrollbars.visible = true;
		}
	}
}
 

//  fadeDiv
//  -------
//  DEVONO essere definiti questi parametri di stile:
//  <div id="nome" style="filter:alpha(opacity=10);-moz-opacity:10">bla bla</div>

var curpos=10;

function fadeDiv(divID){
	var myReference = getRefToDiv(divID);
	if (curpos<100){
		curpos+=10
		if (myReference.filters)
			myReference.filters.alpha.opacity=curpos
		else if (myReference.style.MozOpacity)
			myReference.style.MozOpacity=curpos/100
		timerID=setTimeout("fadeDiv('"+divID+"')",30)
	} else {
		curpos=1
	}
}

//  contentDiv
//  -------

function contentDiv(divID,html){
	var myReference = getRefToDiv(divID);
	html+="<a name='"+divID+"_a_height' id='"+divID+"_a_height'></a>";
	myReference.innerHTML=html;
}



//  scrollDiv
//  ---------
//  ATTENZIONE: nel caso venga cambiato il contenuto del div (con contentDiv())
//              il div non viene piu' posizionato, anche se la sua posizione (scrollDiv_height) cambia correttamente.

var scrollDiv_step=5;
var scrollDiv_actualstep = new Object();
var scrollDiv_time=50;
var scrollDiv_top = new Object();
var scrollDiv_height = new Object();
var scrollDiv_visibleheight = new Object();
var scrollDiv_crossobj = new Object();

function apriScrollDiv(divID,width,height,left,top,style_opt){
	var html="";
	
	if (document.all||document.getElementById) {
		html+='<div id="'+divID+'" style="position:absolute;width:'+width+'px;height:'+height+'px;left:'+left+'px;top:'+top+'px;overflow:hidden';
		if (style_opt!="") { html+=';'+style_opt }
		html+='"><div id="'+divID+'_content" style="position:absolute;width:'+width+'px;left:0px;top:0px">';
	}
	
	html+='<ilayer name="'+divID+'"_nscontainer width='+width+' height='+height+' clip="0,0,'+width+','+height+'">';
	html+='<layer name="'+divID+'"_nscontent width='+width+' height='+height+' visibility=hidden>';
	scrollDiv_visibleheight[divID]=height;
	
	return html;
}

function chiudiScrollDiv(divID){
	var html="";

	html+='</layer></ilayer>';

	if (document.all||document.getElementById){
		html+='</div></div>';
		scrollDiv_crossobj[divID]=getRefToDiv(divID+"_content");
	}
	else if (document.layers){
		scrollDiv_crossobj[divID]=eval("document."+divID+"_nscontainer.document.nscontent");
	}

	getheightScrollDiv(divID);
	return html;
}

function movedownScrollDiv(divID){
	if (window.scrollDiv_moveupvar) clearTimeout(scrollDiv_moveupvar)
	if (scrollDiv_top[divID]>=(0-scrollDiv_height[divID]+scrollDiv_visibleheight[divID])) {
		scrollDiv_top[divID]-=scrollDiv_actualstep[divID];
		scrollDiv_actualstep[divID]++;
	} else {
		stopScrollDiv(divID)
		return 0;
	}	
	
	moveScrollDiv(divID);
	
	scrollDiv_movedownvar=setTimeout("movedownScrollDiv('"+divID+"')",scrollDiv_time)
}

function moveupScrollDiv(divID){
	if (window.scrollDiv_movedownvar) clearTimeout(scrollDiv_movedownvar)
	if (scrollDiv_top[divID]<0) {
		scrollDiv_top[divID]+=scrollDiv_actualstep[divID];
		scrollDiv_actualstep[divID]++;
	} else {
		movetopScrollDiv(divID);
		return 0;
	}	

	moveScrollDiv(divID);
		
	scrollDiv_moveupvar=setTimeout("moveupScrollDiv('"+divID+"')",scrollDiv_time)
}

function moveScrollDiv(divID){
	if (document.all||document.getElementById)
		scrollDiv_crossobj[divID].style.top=scrollDiv_top[divID]+"px"
	else if (document.layers)
		scrollDiv_crossobj[divID].top=scrollDiv_top[divID]
}

function stopScrollDiv(divID){
	if (window.scrollDiv_moveupvar) clearTimeout(scrollDiv_moveupvar)
	if (window.scrollDiv_movedownvar) clearTimeout(scrollDiv_movedownvar)
	scrollDiv_actualstep[divID]=scrollDiv_step
}

function movetopScrollDiv(divID){
	stopScrollDiv(divID);
	scrollDiv_top[divID]=0;
	moveScrollDiv(divID);
}

function getheightScrollDiv(divID){
	if (document.all||document.getElementById){
		scrollDiv_height[divID]=scrollDiv_crossobj[divID].offsetHeight;
	}
	else if (document.layers){
		scrollDiv_height[divID]=scrollDiv_crossobj[divID].clip.height;
		scrollDiv_crossobj[divID].visibility="show";
	}
	if (scrollDiv_height[divID]==0) { // cerco l'ancora
	 	if (document.getElementById && document.all && document.all[divID+"_a_height"]) {
			scrollDiv_height[divID]=document.all[divID+"_a_height"].offsetTop;
		} else if (document.getElementById && document.getElementById(divID+"_a_height")) {
			scrollDiv_height[divID]=document.getElementById(divID+"_a_height").offsetTop;
		} else if (document.all && document.all[divID+"_a_height"]) {
			scrollDiv_height[divID]=document.all[divID+"_a_height"].offsetTop;
		}
	}
	
	scrollDiv_top[divID]=0;
	scrollDiv_actualstep[divID]=scrollDiv_step;
}

