// JavaScript Document


/*<!--
if ((screen.width>=1024) && (screen.height>=768))
{
 window.location="highres.html";
}
else
{
  window.location="lowres.html";
}

function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}
//-->*/



<!--

function getQueryVariable(variable) { 
	var query = window.location.search.substring(1); 
	var vars = query.split("&"); 
	for (var i=0;i<vars.length;i++) { 
		var pair = vars[i].split("="); 
		if (pair[0] == variable) {return pair[1];} 
	} 
	return "null";
//alert('Query Variable ' + variable + ' not found'); 
} 
//alert( getQueryVariable("x") ); 



function openPopupAsp(imgId)
{
	var width = screen.width
	var height = screen.height
	var lang=getQueryVariable("lang");
	var langpath;
	
	if (lang =='null') {langpath=''} 
	else{langpath='../';}
	
	var file=langpath+'popup.asp?id=' + imgId
	var titolo='Foto'
	switch (width) {
		
		case 640 :
					PopupCentrata(file,titolo,580,420);
              	//window.open(file,titolo,'width=580,height=420');
					break;
      case 800 :
					PopupCentrata(file,titolo,740,560);
              	//window.open('popup.asp?id=' + imgId,'Foto','width=740,height=560');
					break;
      case 1024 :
					PopupCentrata(file,titolo,960,640);
              	//window.open('popup.asp?id=' + imgId,'Foto','width=960,height=640');
					break;
      case 1280 :
					PopupCentrata(file,titolo,1024,768);
              	//window.open('popup.asp?id=' + imgId,'Foto','width=1024,height=768');
					break;
      case 1600 :
					PopupCentrata(file,titolo,1024,768);
              	//window.open('popup.asp?id=' + imgId,'Foto','width=1024,height=768');
					break;
      default :
					PopupCentrata(file,titolo,1024,768);
              	//window.open('popup.asp?id=' + imgId,'Foto','width=1024,height=768');
					break;
}

}

function res()
{
window.moveTo(0,0);
//window.resizeTo(400,300);
var x=screen.width;
var y=screen.height;
var hx=x/2;
var hy=y/2;
var a=800;  //Inserire i valori per il resize
var b=600;  //della finestra popup a=x; b=y;
var ha=a/2;
var hb=b/2;
var dx=hx-ha;
var dy=(hy-hb)-20;
var param="width="+a+",height="+b+",left="+dx+",top="+dy+",screenX="+dx+",screenY="+dy;
/*window.open("http://www.google.com/","Popup",param);*/
}
 function PopupCentrata(file,titolo,iW,iH) {
   var w = iW;
   var h = iH;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
	var param="width=" + w + ",height=" + h + ",top=" + t + ",left=" + l
   window.open(file,titolo,param);
 }
 
 function Modale() {
    var prop = "dialogWidth: 430px; dialogHeight: 280px; center: 1; scroll: 0; help: 1; status: 0;";
       if (document.all) {
          window.showModalDialog("mioFile.htm", null, prop);
       }
       else {
          alert("Questa funzione è compatibile solo con MSIE");
       }
  }
	
/*var win=null;
function NewWindow(mypage,myname,w,h,scroll){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+scroll+',';
	settings +='resizable=yes';
	win=window.open(mypage,myname,settings);
	if(parseInt(navigator.appVersion) >= 4){
		win.window.focus();
		}
}*///-->
function proporzionaImgInPopup(idImmagine){

	var screenwidth = screen.width
	var screenheight = screen.height
	var im=document.getElementById(idImmagine);
	var maxH;
	var maxW;
	maxW=screenwidth-(screenwidth*30/100);
	maxH=(screenheight-(screenheight*20/100)) * (screenheight/screenwidth);
	
	//
/*	switch (screenwidth) {
		
		case 640 :
					maxW=screenwidth-(screenwidth*30/100);
					maxH=(screenheight-(screenheight*20/100)) * (screenheight/screenwidth);
					break;
      case 800 :
					maxW=screenwidth-(screenwidth*30/100);
					maxH=(screenheight-(screenheight*20/100)) * (screenheight/screenwidth);
					break;
      case 1024 :
					maxW=screenwidth-(screenwidth*30/100);
					maxH=(screenheight-(screenheight*20/100)) * (screenheight/screenwidth);
					break;
      case 1280 :
					maxW=screenwidth-(screenwidth*30/100);
					maxH=(screenheight-(screenheight*20/100)) * (screenheight/screenwidth);
					break;
      case 1600 :
					maxW=screenwidth-(screenwidth*30/100);
					maxH=(screenheight-(screenheight*20/100)) * (screenheight/screenwidth);
					break;
      default :
					maxW=screenwidth-(screenwidth*30/100);
					maxH=(screenheight-(screenheight*20/100))* (screenheight/screenwidth);
					break;
}*/

	var tmpWidth = im.width;
	var tmpHeight = im.height;
	var newHeight;
	var newWidth;
	
	
	/*NUOVA PROPORZIONE IMMAGINE*/
	if (tmpWidth >= tmpHeight){
	
		newWidth = maxW
		newHeight = maxH * (tmpHeight/tmpWidth)}
	else{
		newHeight = maxH
		newWidth = maxW * (tmpWidth/tmpHeight)}

	im.width=newWidth
	im.height=newHeight

}

function proporzionaImmagine(objImg,maxWidth,maxHeight){
	    var tmpWidth 
        var tmpHeight 
        var newHeight
        var newWidth
		
		

        tmpWidth = objImg.width
        tmpHeight = objImg.height

        //NUOVA PROPORZIONE IMMAGINE
        if( tmpWidth >= tmpHeight ){

            newWidth = maxWidth
            newHeight = (tmpHeight*newWidth)/tmpWidth
			
			if( newHeight > maxHeight ){
				newHeight=maxHeight
				newWidth = (tmpWidth*newHeight)/tmpHeight
			}
		}
        else{
            newHeight = maxHeight
            newWidth = (tmpWidth*newHeight)/tmpHeight
			
			if( newWidth > maxWidth ){
				newWidth=maxWidth
				newHeight = (tmpHeight*newWidth)/tmpWidth
			}
			
		}

		objImg.width=newWidth
		objImg.height=newHeight
		
	}
	
		
	function proporzione(Estremo1, Medio1, Medio2, Estremo2){
	//alert (Estremo1+Medio1+Medio2);
	var risultato;
	
	this.arrotonda= function(valore){
	
	valore=(Math.round(valore*100)/100);
	return parseFloat(valore);
	
	}

	if(Estremo1==''|Estremo1==undefined){
	// ?:y=z:k -> (y * z / k)
	risultato=parseFloat((Medio1 * Medio2) / Estremo2);
	}
	else if(Medio1==''|Medio1==undefined){
	// x:?=z:k -> (x * k /z )
	risultato=parseFloat((Estremo1 * Estremo2) / Medio2);

	}
	else if(Medio2==''|Medio2==undefined){
	// x:y=?:k -> (x * k / y)
	risultato=parseFloat((Estremo1 * Estremo2) / Medio1);
	
	}
	else if(Estremo2==''|Estremo2==undefined){
	// x:y=z:? -> (y * z / x)
	risultato=parseFloat((Medio1 * Medio2) / Estremo1);

	}
	
	return this.arrotonda(risultato);
	
	}
/*--------------------------------------------------------*/	
/*	function parseDecimal(valore,dec){
	
	var multiperDec='0';
	
	for (var i=0;i<dec;i++){
	multiperDec+='';
	}
	
	multiperDec=parseInt('1' + multiperDec);
	
	Risultato=(Math.round(valore*multiperDec)/multiperDec);
	return valore;
	
	
	}*/
	
	function arrotonda(valore){
	
	valore=(Math.round(valore*100)/100);
	return parseFloat(valore);
	
	}
	
/*--------------------------------------------------------*/	
	
	/*nomeIdContainer,nomeIDContenuto,arrayIDAltriDiv,pixelAggiuntividasommare*/
	function centerAniwhere(idNameContainer,idNameContent,arjIdXtraObj,xtraPixel){
		
		var message='';
		var d=document;
		var objContainer=d.getElementById(idNameContainer);/* Contenitore 100% */
		var objContent=d.getElementById(idNameContent);/* Contenuto da centrare 100% */
		var arjObjXtra=new Array();/* array di oggetti che influiscono sull'altezza*/
		var PercBaseHeight=100;/* Altezza percentuale rispetto alla quale si vuole centrare l'oggetto */
		var positionTop=(100-PercBaseHeight);/* Posizione marginTop dalla quale si vuole partire rispetto a PercentBaseHeight*/
		var arjPixelHeight=new Array();
		var arjPercentHeight=new Array();
		var totalHeight=0;
		var MarginTopBottomPercent;
		var xtraPixelPercent;
		var containerHeightPercent;
		
		xtraPixelPercent=proporzione(objContainer.offsetHeight,PercBaseHeight,xtraPixel);
		containerHeightPercent=proporzione(objContainer.offsetHeight,PercBaseHeight,objContent.offsetHeight)
		totalHeight=containerHeightPercent;
		totalHeight+=xtraPixelPercent;
		
		//message+='AltezzaContainer : ' + objContainer.offsetHeight + ' px \n'
		//message+='Container : ' + containerHeightPercent + '\n';
		//message+='xtraPixel : ' + xtraPixelPercent + '\n\n';
		
		for (var i=0 ;i<arjIdXtraObj.length;i++){
			arjObjXtra[i]=d.getElementById(arjIdXtraObj[i]);
			arjPixelHeight[i]=arjObjXtra[i].offsetHeight;
			arjPercentHeight[i]=proporzione(objContainer.offsetHeight,PercBaseHeight,arjPixelHeight[i]);
			totalHeight+=arjPercentHeight[i];
			message+='Altezza : ' + arjIdXtraObj[i] + ' : ' + arjPercentHeight[i] + '% \n';
		}
		

		//message+='Somma :' + arrotonda(totalHeight) + '\n';


		totalHeight=(totalHeight>100)? 96:totalHeight;
		MarginTopBottomPercent=arrotonda(((100-totalHeight)/2));	
		MarginTopBottomPercent=(MarginTopBottomPercent<0)? 0:MarginTopBottomPercent;
		objContent.style.position='relative';
		objContent.style.marginTop=MarginTopBottomPercent+'%';	
		
		//message+='margine diviso 2 : ' + arrotonda(MarginTopBottomPercent);		
		//alert (message);		
	
	}


	
	
	
	
	
	
	
	
	