// JavaScript Document

var codice = null;
var http = assegnaXMLHttpRequest();
var isWorking = false;

// Layer POPUP
function popup_layer(img,img_width,img_height){

document.getElementById('layer_popup').style.width = img_width+'px';;
document.getElementById('layer_popup').style.height = img_height+'px';
document.getElementById('layer_popup').innerHTML = '<img src="'+img+'" border="0" />';
document.getElementById('layer_popup').style.display = 'inline';

}

// AGGIUNGI RIGA

function cambio_ambientazione_handleHttpResponse() {
	
	if (http.readyState == 4) {
		
		if (http.responseText.indexOf('invalid') == -1) {
			// Split the comma delimited response into an array
			results = http.responseText;
			document.getElementById('COMP_AMB').innerHTML = results;
			isWorking = false;
		}
	}
}



function cambio_ambientazione(IDcoll,codice,lang) {
	
	if (!isWorking && http) {
		
	url_img = document.getElementById('AMB').src = 'images/collezioni/'+IDcoll+'/ambientazioni/'+codice+'.jpg';
	
		var url = "ajax.cambio_ambientazione.php?codice="+codice+"&IDcollezione="+IDcoll+"&lang="+lang;
		//var url = "ajax.cambio_ambientazione.php?codice="+codice;
			document.getElementById('COMP_AMB').innerHTML = '<p align="center"><br /><br /><br /><br /><br />LOADING...</p>';
		
			http.open("GET", url, true);
			http.onreadystatechange = cambio_ambientazione_handleHttpResponse;
			isWorking = true;
			http.send(null);
		}
}




// #####################################


// funzione per assegnare l'oggetto XMLHttpRequest
// compatibile con i browsers pių recenti e diffusi
function assegnaXMLHttpRequest() {

// lista delle variabili locali
var
 // variabile di ritorno, nulla di default
 XHR = null,
 
 // informazioni sul nome del browser
 browserUtente = navigator.userAgent.toUpperCase();


 // browser standard con supporto nativo
 // non importa il tipo di browser
 if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
  XHR = new XMLHttpRequest();

 // browser Internet Explorer
 // č necessario filtrare la versione 4
 else if(
  window.ActiveXObject &&
  browserUtente.indexOf("MSIE 4") < 0
 ) {
 
  // la versione 6 di IE ha un nome differente
  // per il tipo di oggetto ActiveX
  if(browserUtente.indexOf("MSIE 5") < 0)
   XHR = new ActiveXObject("Msxml2.XMLHTTP");

  // le versioni 5 e 5.5 invece sfruttano lo stesso nome
  else
   XHR = new ActiveXObject("Microsoft.XMLHTTP");
 }

 return XHR;
}


// ######################################
/*
function getHTTPObject() {

var xmlhttp;


/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
/*

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	
	try {
	xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp = false;
		}
	}

return xmlhttp;

}*/

//var http = getHTTPObject(); // We create the HTTP Object
