// ------------------------------------------------------------
// ------------------------------------------------------------
function openwin(file, width, height) {
  var winW = width;
  var winH = height;
  var winX = (screen.width - winW) / 2;
  var winY = (screen.height - winH) / 2;
  var winOpt = 'height='+winH+',width='+winW+',top='+winY+',left='+winX+',scrollbars=1,resizable=0';
  Win = window.open(file, "", winOpt)
}


function openimg(url, image, width, height) {
  var winW = width + 2;
  var winH = height + 21;

  var winX = (screen.width - winW) / 2;
  var winY = (screen.height - winH) / 2;

  var winOpt = 'height='+winH+',width='+winW+',top='+winY+',left='+winX+',scrollbars=no,resizable=0';
  Win = window.open("", "", winOpt);

  Win.document.open();
  Win.document.write("<html><head><title>" + url + "</title></head>");
  Win.document.write("<body TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 scroll=no>");
  Win.document.write("<table border=0 cellpadding=0 cellspacing=0 width=" + winW + ">");
  Win.document.write("<tr><td>");
  Win.document.write("<img src=\"" + image + "\" border=1>");
  Win.document.write("</td></tr>");
  Win.document.write("<tr bgcolor=#808080>");
  Win.document.write("<td align=right>");
  Win.document.write("<a href=javascript:self.close()><font face=verdana size=2 color=#ffffff>chiudi</font></a>&nbsp;");
  //Win.document.write("<a href=javascript:self.close()><img src=" + url + "/images/close_ics.gif align=absmiddle border=0></a>&nbsp;");
  Win.document.write("</td>");
  Win.document.write("</tr>");
  Win.document.write("</table>");
  Win.document.write("</body></html>");
  Win.document.close();
}


// ------------------------------------------------------------
// ------------------------------------------------------------
function cssJsMenu(elemId) {
  if (document.getElementById(elemId)) {
    var navroot = document.getElementById(elemId);
    var lis=navroot.getElementsByTagName("LI");

    for (i=0; i<lis.length; i++) {
      for (j=0; j<lis[i].getElementsByTagName("UL").length; j++) {
        lis[i].onmouseover = function() {
          this.getElementsByTagName("UL")[j].style.visibility = 'visible';
        }

        lis[i].onmouseout = function() {
          this.getElementsByTagName("UL")[j].style.visibility = 'hidden';
        }
      }
    }
  }
}


// ------------------------------------------------------------
// ------------------------------------------------------------
function validate(testo) {
  if (testo.length < 3) { alert("Inserire una chiave di ricerca di almeno 3 caratteri."); return false; }
}


// ------------------------------------------------------------
// ------------------------------------------------------------
function confirmNotify() {
  return confirm("Clicca sul pulsante OK per essere avvisato via e-mail, non appena l'articolo diventa disponibile.");
}


// ------------------------------------------------------------
// ------------------------------------------------------------

function showSpot(width, height) {
  var screenw = screen.width;
  var screenh = screen.height;

  var lft = (screenw - width) / 2;
  var top = ((screenh - height) / 2) - 100;

  var id=document.getElementById("spot");

  id.style.left=lft;
  id.style.top=top;
  id.style.display="block";
}

function hideSpot() {
  var id=document.getElementById("spot");
  id.style.display="none";
}



// ------------------------------------------------------------
// ------------------------------------------------------------

function showGallery(obj, image, width, height) {
  imgBig.src=image;
  imgBig.width=width;
  imgBig.height=height;

  var lft = xPos(obj) + 90;
  //var top = yPos(obj) - (height/2) - 105;
  var top = yPos(obj) - (height/2) - 75;

  var id=document.getElementById("gallery");

  id.style.left=lft;
  id.style.top=top;
  id.style.display="block";
}

function hideGallery() {
  var id=document.getElementById("gallery");
  id.style.display="none";
}


// ------------------------------------------------------------
// ------------------------------------------------------------
var showtime;

function bubbleUp(obj, message) {

	var screenw = screen.width;
	var screenh = screen.height;

	var bubblew = 160;
	var bubbleh = 90;

	var bubblet = 0;
	var bubblel = 0;

	var lft = xPos(obj);
	var tp = yPos(obj);


//	--------------------------------------------
	var theBubble;
	var theWidth;
//	--------------------------------------------

        theBubble = getObject('bubble');
        theWidth = (theBubble.offsetWidth)/2-46;

	bubblel = lft - (bubblew/2) - 20;
	bubblet = tp - bubbleh;

	theBubble.style.top = bubblet + "px";
	theBubble.style.left = bubblel + "px";

	theBubble.style.height = '90px';

//	--------------------------------------------

	textWriter(theBubble, message);
	theBubble.style.visibility = 'visible';
	clearInterval(showtime);
	return;
}


function bubbleCloser()
{
	var theBubble;
	theBubble = getObject('bubble');
	theBubble.style.visibility = 'hidden';
	theBubble.style.height = '0px';
}

function bubbleOff()
{
	showtime = setInterval("bubbleCloser()", 250);
	return;
}

function getObject(objectID) {
	if (document.all && !document.getElementById) {
		return document.all(objectID)
	} else {
		return document.getElementById(objectID)
	}
}


// ------------------------------------------------------------
// ------------------------------------------------------------

function textWriter(obj, msg){
	obj.innerHTML = msg;
}

//get the x position of an element
function xPos(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

//get the y position of an element
function yPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) curtop += obj.y;
	return curtop;
}


//	------------------------------------------------------------
//	------------------------------------------------------------

