// Codice per utilizzare le funzionalitą AJAX
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

// Funzione per creare la lista delle miniature
function changefoto(path) {

	var img = document.getElementById('prodotti_img');
	img.src = '/i/trasparent.gif';
	
  xmlhttp.open("GET", path, true);
  xmlhttp.onreadystatechange=function() {
		switch (xmlhttp.readyState) {
		//case 0:
		//	alert('Error!');
		//break;
		case 1:
		break;
		case 2:
		break;
		case 3:
		case 4:
			img.src = path;
		break;
		} // end switch
 };
 
 xmlhttp.send(null);

}

function changeselect(elementi_id) {
	var doc = document.getElementById('colD');
	var a_voce = doc.getElementsByTagName("a");
	for(var i=0; i<a_voce.length; i++){
		if ( (a_voce[i].id == elementi_id) && (a_voce[i].id != '') ) {
			a_voce[i].style.color = "#FFC23A";
		} else {
			a_voce[i].style.color = "#FFFFFF";
		}
	}
}

/**** SWAP TESTO ****/
// JavaScript Document
function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

var lastSelectedLayer;

function changeobjectvisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    if ( newVisibility == "visible" )
    {
		if ( lastSelectedLayer != null )
			changeobjectvisibility(lastSelectedLayer, "hidden");
		lastSelectedLayer = objectId;
	}
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility


/* Funzione che memorizza i cookies */
function setCookie(sNome, sValore, iGiorni) {
  var dtOggi = new Date()
  var dtExpires = new Date()
  dtExpires.setTime
    (dtOggi.getTime() + 24 * iGiorni * 3600000)
  document.cookie = sNome + "=" + escape(sValore) +
    "; expires=" + dtExpires.toGMTString();
}

function getCookie(sNome) {
  // genera un array di coppie "Nome = Valore"
  // NOTA: i cookies sono separati da ';'
  var asCookies = document.cookie.split("; ");
  // ciclo su tutti i cookies
  for (var iCnt = 0; iCnt < asCookies.length; iCnt++)
  {
    // leggo singolo cookie "Nome = Valore"
    var asCookie = asCookies[iCnt].split("=");
    if (sNome == asCookie[0]) { 
      return (unescape(asCookie[1]));
    }
  }

  // SE non esiste il cookie richiesto
  return("");
}

function changelinkvisibility(objectId) {
    // get a reference to the cross-browser style object and make sure the object exists
    if (getCookie('IdImmagine') == "") {
		
		var styleObject = getStyleObject(objectId);
		if(styleObject) {
			if ( (styleObject.color == "#fff") || (styleObject.color == "rgb(255, 255, 255)") )
				styleObject.color = "#f18692";
			else
				styleObject.color = "#FFF";
		}
		setCookie('IdImmagine', "'" + objectId + "'", 1);
		
    } else {
    
    	var styleObject = getStyleObject(getCookie('IdImmagine').replace(/'/g, ""));
		if(styleObject) {
			if ( (styleObject.color == "#fff") || (styleObject.color == "rgb(255, 255, 255)") )
				if ( getCookie('IdImmagine').replace(/'/g, "") != objectId )
					styleObject.color = "#f18692";
			else
				styleObject.color = "#FFF";
		}
		
		if ( getCookie('IdImmagine').replace(/'/g, "") != objectId ) {
			var styleObject1 = getStyleObject(objectId);
			if(styleObject1) {
				if ( (styleObject1.color == "#fff") || (styleObject1.color == "rgb(255, 255, 255)") )
					styleObject1.color = "#f18692";
				else
					styleObject1.color = "#FFF";
			}		
		}
		setCookie('IdImmagine', "'" + objectId + "'", 1);
		
    }
       
} // changeObjectVisibility