/* author: Variance */
/* Creation date: 09/10/2004 */
function appear(obj) {
  var oggetto = document.getElementById(obj); 
  if ((oggetto.style.display=='')||(oggetto.style.display=='none')){
    show_fusion(obj, '');
  }
  else{
    hide_fusion(obj, '');
  }
}

function disappear(obj) {
  var oggetto = document.getElementById(obj);
  if ((oggetto.style.display=='')||(oggetto.style.display=='block')){
    hide_fusion(obj, '');
  }
  else{
    show_fusion(obj, '');
  }
}

function hide_plus(element){
  elemento=element+'_td';
  document.getElementById(elemento).style.background="url('images/tab_pagine_no_select_bg.jpg')";
  document.getElementById(elemento).style.border="1px solid rgb(192,192,192)";
  hide(element);
}

function show_plus(element){
  elemento=element+'_td';
  document.getElementById(elemento).style.background="url('images/tab_pagine_bg.jpg')";
  document.getElementById(elemento).style.border="1px solid rgb(22,69,162)";
  show(element);
}

function show(obj) {
  document.getElementById(obj).style.display='block';
}

function hide(obj) {
  document.getElementById(obj).style.display='none';
}

function scroll_position(coordinata){
	if(coordinata=='x'){
		if (navigator.appName == 'Microsoft Internet Explorer'){valore = document.body.scrollLeft;}
		else{valore = window.pageXOffset;}		
	}
	else{
		if (navigator.appName == 'Microsoft Internet Explorer'){valore = document.body.scrollTop;}
		else{valore = window.pageYOffset;}	
	}
return valore;
}


/* da usare nei moduli fusion per problemi di duplicazione nomi javascript*/
function show_fusion(obj, width) {
  document.getElementById(obj).style.display='block';
  bodyX = document.body.offsetWidth;
  bodyY = document.body.offsetHeight;

  if(width != ''){
  	document.getElementById(obj).style.width=width+'px';
  	x = document.getElementById(obj);
  	xposition = trova_posizione(x);
  	tmp = parseInt(xposition[0])+parseInt(width);
  	if(bodyX < tmp){
  	  tmp2 = (bodyX - width) - 10;
			x.style.left = tmp2+'px';
		}
		
		height = x.offsetHeight;
		tmp = parseInt(xposition[1])+parseInt(height);
		if(bodyY < tmp){
			tmp2 = (bodyY - (2*height)) - 20;
			x.style.top = tmp2+'px';
		}
	}
}

function hide_fusion(obj){
  document.getElementById(obj).style.display='none';
}


function show_div_popup(obj, altezza, sfondo, padre_relative){
	var x = document.getElementById(obj);
	
	bodyX = document.body.offsetWidth;
	bodyY = document.body.offsetHeight;

	array_dimensioni_pagina = dimensioni_pagina();
	
	if(document.getElementById(sfondo)){
		var contenitore = document.getElementById(sfondo);
		if(contenitore){
			contenitore.style.width = array_dimensioni_pagina[2]+'px';
			contenitore.style.height = array_dimensioni_pagina[3]+'px';
		}
	}
	
	if(document.getElementById(padre_relative)){
		bodyX = document.getElementById(padre_relative).offsetWidth;
		bodyY = document.getElementById(padre_relative).offsetHeight;
		if(document.getElementById(sfondo)){
			contenitore.style.width = bodyX+'px';
			contenitore.style.height = bodyY+'px';
		}
	}
	if(document.getElementById(sfondo)){
		contenitore.style.display = 'block';
	}

	divWidth = parseInt(x.style.width);
	div_position_X = parseInt(bodyX - divWidth) / 2;
	scrollY = altezza;
	x.style.top = scrollY+'px';
	x.style.left = div_position_X+'px';
	x.style.display = 'block';		
}

/*  */


function dimensioni_pagina(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function trova_posizione(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

