var xmlHttp;

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
    
function startRequest(codice,pagina) {
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", "esterni/dettaglio.php?cod=" + encodeURI(codice) + "&pag=" + pagina, true);
    xmlHttp.send(null);
	temp = setTimeout("vaizoom()", 1000);
}
    
function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			initImage(2);
            document.getElementById("lay2").innerHTML = xmlHttp.responseText;
        }
    }
	
}

function startRequestPrice(codice,pagina) {
    createXMLHttpRequest();
	var dati_post = "password=" +
					encodeURIComponent( document.getElementById("password").value ) + 
					"&codice=" +
					encodeURIComponent( document.getElementById("codice").value );
	xmlHttp.open('POST', 'verifica_pwd.php', true);
	xmlHttp.onreadystatechange = handleStateChangePrice;
	
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", dati_post.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(dati_post);
}
    
function handleStateChangePrice() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			initImage(2);
            document.getElementById("price").innerHTML = xmlHttp.responseText;
        }
    }
	
}



function vaizoom() {
	setupZoom();
}	


function initImage(quale) {
	imageId = 'lay' + quale;
	image = document.getElementById(imageId);
	//setOpacityLay(image, 0);
	if (quale==1) {
		document.getElementById('lay2').style.visibility = "hidden";
		document.getElementById('lay1').style.visibility = "visible";
		document.getElementById('contienelays').style.height = "1100px";
		//document.getElementById('l1').innerHTML='<a href="javascript:void(0);" onclick="initImage(2);">versione italiana<img src="img/ita.gif" class="absmdx" alt="italian furnitures" /></a>';
		
		
	} 
	if (quale==2) {
		document.getElementById('lay1').style.visibility = "hidden";
		//document.getElementById('lay2').style.visibility = "visible";
		document.getElementById('contienelays').style.height = "1100px";
		//document.getElementById('l1').innerHTML='<a href="javascript:void(0);" onclick="initImage(1);">english version<img src="img/eng.gif" class="absmdx" alt="italian furnitures" /></a>';

	} 

	image.style.visibility = "visible";
	fadeIn(imageId,0);

}
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacityLay(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 50);
		}
	}
}
function setOpacityLay(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}
function stampa() {
	window.print();
}

/** DA ATTIVARE SE SI VUOLE FARE IL FADE ALL'APERTURA DELAL PAGINA. IN QUESTO CASO NEL CSS METTERE VISIBILITY: HIDDEN**/
window.onload = function() {
setupZoom();
initImage(1);
}
