function naviga(sLeftFrame, sPrincFrame)
{
	var oMenu, oCont ;
	oMenu = document.getElementById("menu");
	oCont = document.getElementById("contenuto");
	if (sLeftFrame!="" && sLeftFrame!=null)
	{
		oMenu.src = sLeftFrame;
	}
	if (sPrincFrame!="" && sPrincFrame!=null)
	{
		oCont.src = sPrincFrame;
	}
}



function AdattaTable(nYSottr)
{
	var oMenu, oCont ;
	var nMaxHeight;
	oMenu = document.getElementById("menu");
	oCont = document.getElementById("contenuto");
	nMaxHeight = document.body.clientHeight -  168 - 51 - nYSottr;
	if (nMaxHeight<358)
	{
		nMaxHeight = 358
	}
	oMenu.height = nMaxHeight
	oCont.height = nMaxHeight
}

function cercaQueryString(sUrl,sSearch)
{
	var sReturn="";
	var nInizPosQS = sUrl.indexOf(sSearch+"=")+2;
	var sRestoQS   = sUrl.substr(nInizPosQS);
	if (sUrl.indexOf(sSearch+"=")!=-1)
	{
	if (sRestoQS.indexOf("&")==-1)
	{
		sReturn = sRestoQS;
	} else {
		sReturn = sRestoQS.substr(0,sRestoQS.indexOf("&"));
	}
	} else {
		sReturn = "";
	}
	return(sReturn);
}

function scrivi(stext)
{
  /*  var SpanElemRef = document.getElementById("txtdida");
    var new_txt = document.createTextNode(stext);
    SpanElemRef.replaceChild(new_txt, SpanElemRef.childNodes[0]);
	*/ 
	document.getElementById("txtdida").innerText = stext;
}


function CreaWindow()
{
	var sTuttaQueryString, nInizPosTitolo, nInizPosImg, nInizPosDida, sTitolo, sSrcImg, sDida;
    var TitleElemRef,DidaElemRef;
    var new_txt, new_txt2;
	var aQS = window.dialogArguments;
	var nAltDispWindow, nLarDispWindow;
	nAltDispWindow = document.body.clientHeight;
	nLarDispWindow = document.body.clientWidth;

	//window.alert("nAltDispWindow = "+nAltDispWindow+"\n"+
	//			 "nLarDispWindow = "+nLarDispWindow+"\n");
	/*sTuttaQueryString = window.location.href;
	if (sTuttaQueryString=="")
	{
			sTuttaQueryString = window.dialogArguments;
	}
	window.alert(sTuttaQueryString);

	sTitolo = cercaQueryString(sTuttaQueryString,"t");
	sSrcImg = cercaQueryString(sTuttaQueryString,"s");
	sDida   = cercaQueryString(sTuttaQueryString,"d");
	if (sDida=="textarea") {
		sDida=self.opener.document.getElementById("txtdida").innerText;
	}
	*/
	sSrcImg = aQS[0];
	sTitolo = aQS[1];
	sDida   = aQS[2];
	sTitolo = sTitolo.replace(/%20/g," ");
	sDida   = sDida.replace(/%20/g," ");
	sTitolo = sTitolo.replace(/%E9/g,"é");
	sDida   = sDida.replace(/%E9/g,"é");
	sTitolo = sTitolo.replace(/%E0/g,"à");
	sDida   = sDida.replace(/%E0/g,"à");

	document.getElementById("imgZoom").src = sSrcImg;
    TitleElemRef = document.getElementById("lblTitolo");
    new_txt = document.createTextNode(sTitolo);
    TitleElemRef.replaceChild(new_txt, TitleElemRef.childNodes[0]);
	
	//document.getElementById("lblTitolo").innerText = sTitolo;
	if (sDida!="")
	{
		DidaElemRef = document.getElementById("lblDida");
		new_txt2 = document.createTextNode(sDida);
		DidaElemRef.replaceChild(new_txt2, DidaElemRef.childNodes[0]);
		// document.getElementById("lblDida").innerText = sDida;
	} 
	
}

function CreaWindowHtm()
{
	var sTuttaQueryString, nInizPosTitolo, nInizPosImg, nInizPosDida, sTitolo, sSrcImg, sDida;
    var TitleElemRef,DidaElemRef;
    var new_txt, new_txt2;
	var nAltDispWindow, nLarDispWindow;
	nAltDispWindow = document.body.clientHeight;
	nLarDispWindow = document.body.clientWidth;

	sTuttaQueryString = window.location.href;
	if (sTuttaQueryString=="")
	{
			sTuttaQueryString = window.dialogArguments;
	}
	sTitolo = cercaQueryString(sTuttaQueryString,"t");
	sSrcImg = cercaQueryString(sTuttaQueryString,"s");
	sDida   = cercaQueryString(sTuttaQueryString,"d");
	if (sDida=="textarea") {
		sDida=self.opener.document.getElementById("txtdida").innerText;
	}
	sTitolo = sTitolo.replace(/%20/g," ");
	sDida   = sDida.replace(/%20/g," ");
	sTitolo = sTitolo.replace(/%E9/g,"é");
	sDida   = sDida.replace(/%E9/g,"é");
	sTitolo = sTitolo.replace(/%E0/g,"à");
	sDida   = sDida.replace(/%E0/g,"à");

	document.getElementById("imgZoom").src = sSrcImg;
    TitleElemRef = document.getElementById("lblTitolo");
    new_txt = document.createTextNode(sTitolo);
    TitleElemRef.replaceChild(new_txt, TitleElemRef.childNodes[0]);
	
	//document.getElementById("lblTitolo").innerText = sTitolo;
	if (sDida!="")
	{
		DidaElemRef = document.getElementById("lblDida");
		new_txt2 = document.createTextNode(sDida);
		DidaElemRef.replaceChild(new_txt2, DidaElemRef.childNodes[0]);
		// document.getElementById("lblDida").innerText = sDida;
	} 
	
}

function AdattaWindow()
{
	var  nAltTbl, nLarTbl;
	nAltTbl = document.getElementById("tblImg").clientHeight;
	nLarTbl = document.getElementById("tblImg").clientWidth;
	if (nAltTbl>screen.availHeight)
	{
		nAltTbl = screen.availHeight;
	}
	if (nLarTbl>screen.availWidth)
	{
		nLarTbl = screen.availWidth;
	}
	window.resizeTo(nAltTbl-window.top,nLarTbl-window.left);
}

function AdattaImg()
{
	var nAltDispWindow, nLarDispWindow, nConstReduction;
	var  nAltImg, nLarImg, nAltColTitolo, nAltColDida, nAltImgOrig, nLarImgOrig;
	nConstReduction = 24;
	nAltDispWindow = document.body.clientHeight;
	nLarDispWindow = document.body.clientWidth;
	nAltImg = document.getElementById("imgZoom").clientHeight;
	nLarImg = document.getElementById("imgZoom").clientWidth;
	nAltImgOrig = nAltImg;
	nLarImgOrig = nLarImg;
	nAltColTitolo = document.getElementById("colTitolo").clientHeight;
	nAltColDida = document.getElementById("colDida").clientHeight;
	/*window.alert("nAltDispWindow = "+nAltDispWindow+"\n"+
				 "nLarDispWindow = "+nLarDispWindow+"\n"+
				 "nAltImg = "+nAltImg+"\n"+
				 "nLarImg = "+nLarImg+"\n"+
				 "nLarImg = "+nLarImg+"\n"+
				 "nAltColTitolo = "+nLarDispWindow+"\n"+
				 "nAltColDida = "+nLarDispWindow+"\n"
				 );*/
	/*if (nAltImg>window.screen.availHeight  - nAltColTitolo - 10)
	{
		nAltImg = window.screen.availHeight  - nAltColTitolo - 10;
		nLarImg = parseInt((nLarImgOrig / nAltImgOrig) * nAltImg);
	}
	if (nLarImg>window.screen.availWidth -20)
	{
		nLarImg = window.screen.availWidth - 20;
		nAltImg = parseInt((nAltImgOrig / nLarImgOrig) * nLarImg);
	}
	*/
	if (nAltImg>nAltDispWindow  - nAltColTitolo - nAltColDida - nConstReduction)
	{
		nAltImg = nAltDispWindow  - nAltColTitolo - nAltColDida - nConstReduction;
		nLarImg = parseInt((nLarImgOrig / nAltImgOrig) * nAltImg);
	}
	if (nLarImg>nLarDispWindow - nConstReduction)
	{
		nLarImg = nLarDispWindow - nConstReduction;
		nAltImg = parseInt((nAltImgOrig / nLarImgOrig) * nLarImg);
	}

	if (nAltImg!=nAltImgOrig && nLarImg!=nLarImgOrig)
	{
	document.getElementById("imgZoom").height = nAltImg;
	document.getElementById("imgZoom").width  = nLarImg;
	}
}

function closeApp()
{
	 var bChiudi;
	 bChiudi = window.confirm("Chiudere l'applicativo?");
	 if (bChiudi) {
			window.close();
	 } 
}

function apriWindow(sUrl,nPosTop,nPosLeft)
{
	if (window.navigator.appName.indexOf("Microsoft")>-1)
	{
	var sBaseUrl;
	var aQS = new Array(5);
	//sBaseUrl = sUrl.substr(0,sUrl.indexOf("?"));
	aQS[0] = cercaQueryString(sUrl,"s");
	aQS[1] = cercaQueryString(sUrl,"t");
	aQS[2] = cercaQueryString(sUrl,"d");
	if (aQS[2]=="textarea")
	{
		aQS[2] = document.getElementById("txtdida").innerText;
	}
	aQS[3] = document.body.clientWidth;
	aQS[4] = document.body.clientHeight;
	//window.alert(aQS[3]+"\n"+aQS[4]);
	window.showModalDialog(sUrl,aQS,"status:no;resizable:no;dialogHeight:"+window.screen.availHeight+"px;dialogWidth:"+window.screen.availWidth+"px;center:yes;help:no;unadorned:no;");
	} else {
		sUrl = sUrl.replace("zoom.htm","zoomhtm.htm");
		window.open(sUrl,"zoom","status=no, titlebar=no, toolbar=no,location=no,scrollbars=yes,fullscreen=yes, resizable=no,top="+nPosTop+",left="+nPosLeft+",height="+window.screen.availHeight+",width="+window.screen.availWidth);		
	}
}