var xmlhttpMenu
var xmlhttpListePartenza
var xmlhttpThumbs
var xmlhttpThumbBrowser
var xmlhttpAggiornaPrezzo
var xmlhttpAddToLightBox
var xmlhttpAddToBasket
var xmladdDirectlyLightbox
var xmladdDirectlyBasket
var browser = new Browser();
var dragObj = new Object();
dragObj.zIndex = 0;

// -------------------------------------------------------------------------
// Gestione dell'albero delmenu
// -------------------------------------------------------------------------

function getMenu(DivObject)
{
xmlhttpMenu=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttpMenu=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttpMenu=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttpMenu!=null)
  {
    oldId = SetCookie("MenuSelected", DivObject.parentNode.getAttribute('id'));
    MyLivello = DivObject.getAttribute('livello');
    MyNodeId = DivObject.getAttribute('idnodo');
    xmlhttpMenu.onreadystatechange = state_Change_Menu;
	
	if (DivObject.parentNode.getAttribute('aperto')=="1")
	{
     var len = DivObject.parentNode.childNodes.length;
     for(var i = len-1; i > 0; i--)
     {
      DivObject.parentNode.removeChild(DivObject.parentNode.childNodes[i]);
     }
	 DivObject.parentNode.removeAttribute('aperto');
	 if (MyLivello > 0) 
	  {
		//cancello anche me stesso e re-invoco l'apertura del nodo padre....
    	MyNodeId = DivObject.getAttribute('idnodopadre');
		MyLivello = MyLivello - 1;
        oldId = SetCookie("MenuSelected", "N" + MyNodeId);
		// alla fine cancello me stesso....
		document.getElementById("N" + MyNodeId).removeChild(DivObject.parentNode);	
        xmlhttpMenu.open("GET",'/services/generate-Menu.asp?ID=' + MyNodeId  + '&L=' + MyLivello + '&rand=' + escape(Math.random()),true);
        xmlhttpMenu.send(null);
	  }
	}
	else
	{
	 DivObject.parentNode.setAttribute('aperto','1');
	 if (MyLivello > 0 ) {eliminaNodiParalleli(DivObject);}
     xmlhttpMenu.open("GET",'/services/generate-Menu.asp?ID=' + MyNodeId  + '&L=' + MyLivello + '&rand=' + escape(Math.random()),true);
     xmlhttpMenu.send(null);
    }
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}




function state_Change_Menu()
{
// if xmlhttpMenu shows "loaded"
if (xmlhttpMenu.readyState==4)
  {
  // if "OK"
  if (xmlhttpMenu.status==200)
    {
    oldId = ReadCookie("MenuSelected");
    document.getElementById(oldId).innerHTML = document.getElementById(oldId).innerHTML  +  xmlhttpMenu.responseText;
    }
  else
    {
    alert("Problem retrieving data")
    }
  }
}


// -------------------------------------------------------------------------
// Gestione della visualizzazione delle liste di partenza
// -------------------------------------------------------------------------

function getListePartenza(DivObject, Pagina)
{
xmlhttpListePartenza=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttpListePartenza=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttpListePartenza=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttpListePartenza!=null)
  {

	 xmlhttpListePartenza.onreadystatechange = state_Change_ListePartenza;
     MyNodeId = DivObject.getAttribute('idnodo');
     xmlhttpListePartenza.open("GET",'/services/generate-ListePartenza.asp?ID=' + MyNodeId  + '&P=' + Pagina + '&rand=' + escape(Math.random()),true);
     xmlhttpListePartenza.send(null);
    
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}




function state_Change_ListePartenza()
{
// if xmlhttpMenu shows "loaded"
if (xmlhttpListePartenza.readyState==4)
  {
  // if "OK"
  if (xmlhttpListePartenza.status==200)
    {
    document.getElementById("Thumb-Preview").innerHTML = xmlhttpListePartenza.responseText;
    }
  else
    {
    alert("Problem retrieving data")
    }
  }
}




function prendiAnno(MyMenu)
{
 Cn = MyMenu
 while (Cn.getAttribute('livello') != 0)
 {
	 Cn = Cn.parentNode;
 }
}
	
function eliminaNodiParalleli(MyMenu)
{
	 ConfId = MyMenu.getAttribute('idnodo');
	 ConfLivello = MyMenu.getAttribute('livello');
	 Padre = MyMenu.parentNode.parentNode;
     var len = Padre.childNodes.length;
     for(var i = len-1; i > 0; i--)
     {
	  CurLivello = Padre.childNodes[i].childNodes[0].getAttribute('livello');
	  CurId = Padre.childNodes[i].childNodes[0].getAttribute('idnodo');	
	  if (CurLivello == ConfLivello && CurId != ConfId)
	   {
         Padre.removeChild(Padre.childNodes[i]);
	   }
     }
	 
}

// -------------------------------------------------------------------------
// Gestione dei Thumbs
// -------------------------------------------------------------------------

function getThumbs(DivObject, Pagina)
{
xmlhttpThumbs=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttpThumbs=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttpThumbs=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttpThumbs!=null)
  {
     xmlhttpThumbs.onreadystatechange = state_Change_Thumbs;
     MyNodeId = DivObject.getAttribute('idnodo');
     xmlhttpThumbs.open("GET",'/services/generate-Thumbs.asp?ID=' + MyNodeId  + '&P=' + Pagina + '&rand=' + escape(Math.random()),true);
     xmlhttpThumbs.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function state_Change_Thumbs()
{
// if xmlhttpThumbs shows "loaded"
if (xmlhttpThumbs.readyState==4)
  {
  // if "OK"
  if (xmlhttpThumbs.status==200)
    {
    document.getElementById("Thumb-Preview").innerHTML = xmlhttpThumbs.responseText;
    }
  else
    {
    alert("Problem retrieving data")
    }
  }
}


// -------------------------------------------------------------------------
// Gestione dell'albero delThumbBrowser
// -------------------------------------------------------------------------

function getThumbBrowser(DivObject, Crop, IdBasket, IdLightBox)
{
xmlhttpThumbBrowser=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttpThumbBrowser=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttpThumbBrowser=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttpThumbBrowser!=null)
  {
     xmlhttpThumbBrowser.onreadystatechange = state_Change_ThumbBrowser;
     MyFileId = DivObject.getAttribute('idfile');
     MyNodeId = DivObject.getAttribute('idnodo');
	 if (IdBasket == null) { IdBasket = 0};
	 if (IdLightBox == null) { IdLightBox = 0};
     xmlhttpThumbBrowser.open("GET",'/services/generate-thumbbrowser.asp?ID=' + MyFileId  + '&IDN=' + MyNodeId  + '&IDB=' + IdBasket  + '&IDL=' + IdLightBox  + '&C=' + Crop + '&rand=' + escape(Math.random()),true);
     xmlhttpThumbBrowser.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function state_Change_ThumbBrowser()
{
// if xmlhttpThumbBrowser shows "loaded"
if (xmlhttpThumbBrowser.readyState==4)
  {
  // if "OK"
  if (xmlhttpThumbBrowser.status==200)
    {
    document.getElementById('ThumbBrowser').innerHTML = xmlhttpThumbBrowser.responseText;
  	document.getElementById('AlphaBrowser').style.display = 'block';
  	document.getElementById('ThumbBrowser').style.display = 'block';
    }
  else
    {
    alert("Problem retrieving data")
    }
  }
}


function CloseThumbBrowser()
{
  	document.getElementById('ThumbBrowser').style.display = 'none';
  	document.getElementById('AlphaBrowser').style.display = 'none';
}




// ******************************************************************************************
// ******************************************************************************************
// ******************************************************************************************
// ******************************************************************************************

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}


function dragStart(event, id, mX, mY)
{

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }
  
// Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  
  
    // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;
  


  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (mX == 1 && mY ==1) 
  {
   if (browser.isIE) {document.attachEvent("onmousemove", dragGo); document.attachEvent("onmouseup",   dragStop); window.event.cancelBubble = true; window.event.returnValue = false;}
   if (browser.isNS) {document.addEventListener("mousemove", dragGo,   true); document.addEventListener("mouseup",   dragStop, true); event.preventDefault();}
  } 
    else if (mX == 0 && mY ==1)
  {
   if (browser.isIE) {document.attachEvent("onmousemove", dragGoY); document.attachEvent("onmouseup",   dragStopY); window.event.cancelBubble = true; window.event.returnValue = false;}
   if (browser.isNS) {document.addEventListener("mousemove", dragGoY,   true); document.addEventListener("mouseup",   dragStopY, true); event.preventDefault();}
  } 
}


function dragGo(event) {
  var x, y;
  // Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
    // Move drag element by the same amount the cursor has moved.
  vx = x - dragObj.cursorStartX;
  vy = y - dragObj.cursorStartY;
  x = dragObj.elStartLeft + vx; 
  y = dragObj.elStartTop + vy;
  ml = parseInt(dragObj.elNode.getAttribute('ml'));
  mt = parseInt(dragObj.elNode.getAttribute('mt'));
  if (x < ml) { x = ml;}
  if (y < mt) { y = mt;}
  larghezzafoto = dragObj.elNode.getAttribute('larghezzafoto')
  altezzafoto = dragObj.elNode.getAttribute('altezzafoto')
  x1 =  parseInt(larghezzafoto) - parseInt(dragObj.elNode.style.width) + ml - 1;
  y1 =  parseInt(altezzafoto) - parseInt(dragObj.elNode.style.height) + mt - 1;
  if (x > x1) { x = x1;}
  if (y > y1) { y = y1;}
  dragObj.elNode.style.left = x + "px";
  dragObj.elNode.style.top  = y + "px";
  myImg = document.getElementById("ImageInsideCrop");
  initmleft = parseInt(myImg.getAttribute('initmleft'));
  initmtop = parseInt(myImg.getAttribute('initmtop'));
  maxleft = parseInt(myImg.getAttribute('maxleft'));
  maxtop = parseInt(myImg.getAttribute('maxtop'));
  mx = initmleft - vx;
  my = initmtop - vy;
  if (mx > -1) {mx = -1};
  if (my > -1) {my = -1};
  if (mx < -maxleft) {mx = -maxleft};
  if (my < -maxtop) {my = -maxtop};
  myImg.style.marginLeft = mx + "px"; myImg.setAttribute('currmleft', mx + 'px');
  myImg.style.marginTop  = my + "px"; myImg.setAttribute('currmtop', my + 'px');
  // dragObj.elNode.innerHTML =  "L:" + dragObj.elNode.style.left + " - " + "T:" + dragObj.elNode.style.top + "<br / >x:" + x + " - " + "y:" + y + "<br / >x1:" + x1 + " - " + "y1:" + y1 + "<br / >"
  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
  
  myImg = document.getElementById("ImageInsideCrop");
  initmleft = myImg.getAttribute('currmleft');
  initmtop = myImg.getAttribute('currmtop');
  myImg.setAttribute('initmleft',initmleft);
  myImg.setAttribute('initmtop',initmtop);

}

function dragStopY(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGoY);
    document.detachEvent("onmouseup",   dragStopY);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGoY,   true);
    document.removeEventListener("mouseup",   dragStopY, true);
  }
  
  myImg = document.getElementById("ImageInsideCrop");
  initmleft = myImg.getAttribute('currmleft');
  initmtop = myImg.getAttribute('currmtop');
  myImg.setAttribute('initmleft',initmleft);
  myImg.setAttribute('initmtop',initmtop);

}


function dragGoY(event) {
  var x, y;
  // Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
    // Move drag element by the same amount the cursor has moved.
  vy = y - dragObj.cursorStartY;
  y = dragObj.elStartTop + vy;
  dragObj.elNode.style.top  = y + "px";
  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}



function dragPodStart(event)
{

  var el;
  var x, y;
  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

    dragObj.elNode = document.getElementById("Pod");

	// Get cursor position with respect to the page.
    if (browser.isIE) {
      x = window.event.clientX + document.documentElement.scrollLeft
          + document.body.scrollLeft;
      }
    if (browser.isNS) {
      x = event.clientX + window.scrollX;
    }
  
  
    // Save starting positions of cursor and element.
    dragObj.cursorStartX = x;
    dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);

    if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 40;
    dragObj.elNode.style.zIndex = ++dragObj.zIndex;

    // Capture mousemove and mouseup events on the page.
    if (browser.isIE) {document.attachEvent("onmousemove", dragPodGo); document.attachEvent("onmouseup",   dragPodStop); window.event.cancelBubble = true; window.event.returnValue = false;}
    if (browser.isNS) {document.addEventListener("mousemove", dragPodGo,   true); document.addEventListener("mouseup",   dragPodStop, true); event.preventDefault();}
}

function dragPodStop(event) {

  // Stop capturing mousemove and mouseup events.
  if (browser.isIE) {
    document.detachEvent("onmousemove", dragPodGo);
    document.detachEvent("onmouseup",   dragPodStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragPodGo,   true);
    document.removeEventListener("mouseup",   dragPodStop, true);
  }

  myImg = document.getElementById("ImageInsideCrop");
  initmleft = myImg.getAttribute('currmleft');
  initmtop = myImg.getAttribute('currmtop');
  myImg.setAttribute('initmleft',initmleft);
  myImg.setAttribute('initmtop',initmtop);
}

function roundTo(value, decimalpositions)
{
    var i = value * Math.pow(10,decimalpositions);
    i = Math.round(i);
    return i / Math.pow(10,decimalpositions);
} 

function dragPodGo(event) {
  var x, y;
  // Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
  }
    // Move drag element by the same amount the cursor has moved.
  vx = x - dragObj.cursorStartX;
  x = dragObj.elStartLeft + vx; 
  if (x < -9) { x = -9;}
  if (x > 140) { x = 140;}
  mp = x + 9;
  mp = mp * 20 / 150; // escursione del 20%
  mp = mp + 80; // partendo da un 80% di dimensione



  myImg = document.getElementById("ImageCrop");
  AltezzaFoto = parseInt(myImg.getAttribute('altezzafoto'));
  LarghezzaFoto = parseInt(myImg.getAttribute('larghezzafoto'));
  AttAltezzaCrop = parseInt(myImg.style.height);
  AttLarghezzaCrop = parseInt(myImg.style.width);
  LC = parseInt(myImg.getAttribute('lc'));
  AC = parseInt(myImg.getAttribute('ac'));
  ML = parseInt(myImg.getAttribute('ml'));
  MT = parseInt(myImg.getAttribute('mt'));

  if ((LC / AC) <= (LarghezzaFoto / AltezzaFoto))
    {
 	   AltezzaCrop = AltezzaFoto;
	   LarghezzaCrop = Math.floor(LC *  AltezzaFoto / AC);
	}
  else
    {
	   LarghezzaCrop = LarghezzaFoto;
 	   AltezzaCrop = Math.floor(AC *  LarghezzaFoto / LC);
    }
	
  LarghezzaCrop = Math.floor(LarghezzaCrop * mp / 100);
  AltezzaCrop = Math.floor(AltezzaCrop * mp / 100);
  
  DiffL = LarghezzaCrop - AttLarghezzaCrop;
  DiffA = AltezzaCrop - AttAltezzaCrop;

  CropLeft = parseInt(myImg.style.left) - 10;
  CropTop = parseInt(myImg.style.top) - 9;
  

  DiffICL = 0;
  DiffICA = 0;

  Ridimensionamento = false;

if (DiffL > 0 && DiffA > 0) 
  // Aumento
  {
	  //Aumento in entrambi i versi
	  TotLarCrop = LarghezzaCrop + CropLeft;
	  TotAltCrop = AltezzaCrop + CropTop;
	  if (CropLeft > 0 && CropTop > 0 && TotLarCrop < LarghezzaFoto && TotAltCrop < AltezzaFoto)
	  {
    	DiffL = parseInt(DiffL / 2);
	    DiffA = parseInt(DiffA / 2);
	    CropLeft = CropLeft - DiffL;
	    CropTop = CropTop - DiffA; 
	    LarghezzaCrop = AttLarghezzaCrop + DiffL;
	    AltezzaCrop = AttAltezzaCrop + DiffA;
  		DiffICL = DiffL;
  	    DiffICA = DiffA;
	    Ridimensionamento = true;
	  }
	  else
	  {
		  if (TotLarCrop < LarghezzaFoto && TotAltCrop < AltezzaFoto)
		  {
	    	LarghezzaCrop = AttLarghezzaCrop + DiffL;
	    	AltezzaCrop = AttAltezzaCrop + DiffA;
	        Ridimensionamento = true;
		  }
		  else
		  {
			   if (CropLeft > 0 && CropTop > 0)
			   {
	    	CropLeft = CropLeft - DiffL;
	    	CropTop = CropTop - DiffA; 
  			DiffICL = DiffL;
		    DiffICA = DiffA;
	        Ridimensionamento = true;
			   }
		  }
		// Aumento solo in un verso...
	  }
  }
  else
  //Diminuzione
  {
    DiffL = parseInt(DiffL / 2);
    DiffA = parseInt(DiffA / 2);
    CropLeft = CropLeft - DiffL;
    CropTop = CropTop - DiffA; 
    LarghezzaCrop = AttLarghezzaCrop + DiffL;
    AltezzaCrop = AttAltezzaCrop + DiffA;
    DiffICL = DiffL;
    DiffICA = DiffA;
	Ridimensionamento = true;
  }


  
if (Ridimensionamento)
{
   //Aggiornamento dei Valori
   myImg.style.width = LarghezzaCrop + "px";
   myImg.style.height  = AltezzaCrop + "px";
   myImg.style.top = CropTop + 9 + "px";
   myImg.style.left  = CropLeft + 10 + "px";
  dragObj.elNode.style.left = x + "px";
   
   myImg = document.getElementById("ImageInsideCrop");
   Currmleft = parseInt(myImg.getAttribute('currmleft'));
   Currmtop = parseInt(myImg.getAttribute('currmtop'));
   Currmleft = Currmleft + DiffICL;	
   Currmtop = Currmtop + DiffICA;	
   myImg.setAttribute('maxleft', LarghezzaFoto-LarghezzaCrop);
   myImg.setAttribute('maxtop', AltezzaFoto-AltezzaCrop);
   myImg.setAttribute('currmleft', Currmleft);
   myImg.setAttribute('currmtop', Currmtop);
   myImg.style.marginLeft  = Currmleft + "px";
   myImg.style.marginTop  = Currmtop + "px";
}
   if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    }
    if (browser.isNS)
    event.preventDefault();
}



// -------------------------------------------------------------------------
// Aggiornamento Dimanico del Prezzo
// -------------------------------------------------------------------------

function getAggiornaPrezzo(MyIdListino, MyIdCrop, MyQt)
{
xmlhttpAggiornaPrezzo=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttpAggiornaPrezzo=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttpAggiornaPrezzo=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttpAggiornaPrezzo!=null)
  {
	if (MyIdListino==null) {
	    var selIndex = document.getElementById("Listino").selectedIndex;
		MyIdListino = document.getElementById("Listino").options[selIndex].value;
		}
    xmlhttpAggiornaPrezzo.onreadystatechange = state_Change_AggiornaPrezzo;
    xmlhttpAggiornaPrezzo.open("GET",'/services/AggiornaPrezzo.asp?ML=' + MyIdListino + '&MC=' + MyIdCrop + '&MQ=' + MyQt + '&rand=' + escape(Math.random()),true);
    xmlhttpAggiornaPrezzo.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}


function state_Change_AggiornaPrezzo()
{
// if xmlhttpMenu shows "loaded"
if (xmlhttpAggiornaPrezzo.readyState==4)
  {
  // if "OK"
  if (xmlhttpAggiornaPrezzo.status==200)
    {
    document.getElementById("Price").innerHTML = '&euro; ' + xmlhttpAggiornaPrezzo.responseText;
    }
  else
    {
    alert("Problem retrieving data")
    }
  }
}

// -------------------------------------------------------------------------
// Aggiunta nel LightBox
// -------------------------------------------------------------------------

function getAddToLightBox(MyIdFoto, MyIdCrop)
{
xmlhttpAddToLightBox=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttpAddToLightBox=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttpAddToLightBox=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttpAddToLightBox!=null)
  {
	var selIndex = document.getElementById("Listino").selectedIndex;
	MyIdListino = document.getElementById("Listino").options[selIndex].value;	  
	myImg = document.getElementById("ImageCrop");
    LC = parseInt(myImg.style.width);
    AC = parseInt(myImg.style.height);
    ML = parseInt(myImg.style.left);
    MT = parseInt(myImg.style.top);
	ML = ML - 10;
	MT = MT - 9;
    xmlhttpAddToLightBox.onreadystatechange = state_Change_AddToLightBox;
    xmlhttpAddToLightBox.open("GET",'/services/AddToLightBox.asp?X=' + ML + '&Y=' + MT + '&W=' + LC + '&H=' + AC + '&IDF=' + MyIdFoto + '&IDL=' + MyIdListino + '&IDC=' + MyIdCrop + '&rand=' + escape(Math.random()),true);
    xmlhttpAddToLightBox.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}


function state_Change_AddToLightBox()
{
// if xmlhttpMenu shows "loaded"
if (xmlhttpAddToLightBox.readyState==4)
  {
  // if "OK"
  if (xmlhttpAddToLightBox.status==200)
    {
     document.getElementById("SaveImgLightBox").src = "/css/images/archive/SavedInMyLightbox.gif";
     document.getElementById("Lightbox").setAttribute("className", "BlueBackGround");
     document.getElementById("Lightbox").setAttribute("class", "BlueBackGround");
     //alert(xmlhttpAddToLightBox.responseText);
    }
  else
    {
    //alert("Problem retrieving data")
    }
  }
}

// -------------------------------------------------------------------------
// Aggiunta nel Basket
// -------------------------------------------------------------------------

function getAddToBasket(MyIdFoto, MyIdCrop)
{
xmlhttpAddToBasket=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttpAddToBasket=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttpAddToBasket=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttpAddToBasket!=null)
  {
	var selIndex = document.getElementById("Listino").selectedIndex;
	MyIdListino = document.getElementById("Listino").options[selIndex].value;	  
	myImg = document.getElementById("ImageCrop");
    LC = parseInt(myImg.style.width);
    AC = parseInt(myImg.style.height);
    ML = parseInt(myImg.style.left);
    MT = parseInt(myImg.style.top);
	ML = ML - 10;
	MT = MT - 9;
    xmlhttpAddToBasket.onreadystatechange = state_Change_AddToBasket;
    xmlhttpAddToBasket.open("GET",'/services/AddToBasket.asp?X=' + ML + '&Y=' + MT + '&W=' + LC + '&H=' + AC + '&IDF=' + MyIdFoto + '&IDL=' + MyIdListino + '&IDC=' + MyIdCrop + '&rand=' + escape(Math.random()),true);
    xmlhttpAddToBasket.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}


function state_Change_AddToBasket()
{
// if xmlhttpMenu shows "loaded"
if (xmlhttpAddToBasket.readyState==4)
  {
  // if "OK"
  if (xmlhttpAddToBasket.status==200)
    {
     document.getElementById("SaveImgBasket").src = "/css/images/archive/AddedInMyBasket.gif";
     document.getElementById("Basket").setAttribute("className", "BlueBackGround");
     document.getElementById("Basket").setAttribute("class", "BlueBackGround");
     //alert(xmlhttpAddToBasket.responseText);
    }
  else
    {
    //alert("Problem retrieving data")
    }
  }
}




//================================================================================
//================================================================================
//================================================================================
//================================================================================
//================================================================================




function addDirectlyToLightbox(DivObject)
{
xmladdDirectlyLightbox=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmladdDirectlyLightbox=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmladdDirectlyLightbox=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmladdDirectlyLightbox!=null)
  {
     MyNodeId = DivObject.getAttribute('idfile');
     xmladdDirectlyLightbox.onreadystatechange = state_Change_addDirectlyToLightbox(MyNodeId);
     xmladdDirectlyLightbox.open("GET",'/services/addDirectlyToLightbox.asp?ID=' + MyNodeId  + '&rand=' + escape(Math.random()),true);
     xmladdDirectlyLightbox.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function state_Change_addDirectlyToLightbox(MyId)
{
// if xmlhttpThumbs shows "loaded"
if (xmlhttpThumbs.readyState==4)
  {
  // if "OK"
  if (xmlhttpThumbs.status==200)
    {
    MyResult = xmladdDirectlyLightbox.responseText;
	document.getElementById('aDL' + MyId).style.visibility='hidden'; 
    }
  else
    {
    alert("Problem retrieving data")
    }
  }
}


//####################################################################################
//####################################################################################
//####################################################################################
//####################################################################################
//####################################################################################
//####################################################################################


function addDirectlyToBasket(DivObject)
{
xmladdDirectlyBasket=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmladdDirectlyBasket=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmladdDirectlyBasket=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmladdDirectlyBasket!=null)
  {
     MyNodeId = DivObject.getAttribute('idfile');
     xmladdDirectlyBasket.onreadystatechange = state_Change_addDirectlyToBasket(MyNodeId);
     xmladdDirectlyBasket.open("GET",'/services/addDirectlyToBasket.asp?ID=' + MyNodeId  + '&rand=' + escape(Math.random()),true);
     xmladdDirectlyBasket.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function state_Change_addDirectlyToBasket(MyId)
{
// if xmlhttpThumbs shows "loaded"
if (xmlhttpThumbs.readyState==4)
  {
  // if "OK"
  if (xmlhttpThumbs.status==200)
    {
    MyResult = xmladdDirectlyBasket.responseText;
	document.getElementById('aDB' + MyId).style.visibility='hidden'; 
    }
  else
    {
    alert("Problem retrieving data")
    }
  }
}