//FUNZIONI PER SELEZIONE DIMENSIONI SCHERMO
//Trova Display Settings
//urlWxH=SetDisplay();
//window.location.href= urlWxH;
//textStyle.css
function SetDisplay() {
var css640x480 = "style800x600.css";
var css800x600 = "style800x600.css";
var css1024x768 = "style1024x768.css";
var css1280x1024 = "style1024x768.css";
var css1680x1050 = "style1024x768.css";

if ((screen.width == 640) && (screen.height == 480)) 
	SR="/assets/" + css640x480;
	//@import url(SR);
if ((screen.width == 800) && (screen.height == 600))
	SR="assets/" + css800x600;
else if ((screen.width == 1024) && (screen.height == 768))
	SR="assets/" +css1024x768;
else if ((screen.width == 1280) && (screen.height == 1024))
	SR="assets/" +css1280x1024;
else if ((screen.width == 1680) && (screen.height == 1050))
	SR="assets/" + css1680x1050;
else SR="assets/" +css800x600.css;

return SR;
}

//FUNZIONI PER IL CALCOLO DELLE DIMENSIONI DISPONIBILI
function Is() {
agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer')== -1)&& (agent.indexOf('compatible') ==  -1)));
this.ns2 = (this.ns && (this.major == 3));
this.ns3 = (this.ns && (this.major == 3));
this.ns4b = (this.ns && (this.major == 4) && (this.minor <= 4.03));
this.ns4 = (this.ns && (this.major == 4));
this.ns6 = (this.ns && (this.major >= 5));
this.ie = (agent.indexOf("msie") != -1);
this.ie3 = (this.ie && (this.major < 4));
this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0")
 == -1));
this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0")
 != -1));
this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5")
 != -1));
this.ie6 = (this.ie && (agent.indexOf("msie 6.0")!=-1) );
this.aol = (agent.indexOf("aol") != -1);
this.aol3 = (this.aol && this.ie3);
this.aol4 = (this.aol && this.ie4);
this.aol5 = (this.aol && this.ie5);
}
//Dichiarare dopo var is = new Is();

function winResize() {
if(is.ns4 ||is.ns6||is.ie4||is.ie5||is.ie55||is.ie6) {
	history.go(0);
	}
}
//Poi mettere nel BODY: <BODY bgcolor="#F2EDD9" onResize="winResize()">

function availW() {
if(is.ns4 || is.ns6) {
	available_width = innerWidth;
	}
else if(is.ie4 || is.ie5 || is.ie55 || is.ie6) {
	available_width=document.body.clientWidth;
	}
return available_width;
}

function availH() {
if(is.ns4 || is.ns6) {
//	available_width = innerWidth;
	av_height = innerHeight;
	}
else if(is.ie4 || is.ie5 || is.ie55 || is.ie6) {
//	available_width=document.body.clientWidth;
	av_height=document.body.clientHeight;
	}
return av_height;
}

//Inserisce l'immagine scalando le dimensioni
//YX_AspRatio è dato dalla proporzione Y=YX_AspRatio*X
function insImg(srcIMG,YsuXaspectRatio,MaxH,MaxW) {
var available_width=availW();
var available_height=availH();
	
if(is.ie4 || is.ie5 || is.ie55 || is.ie6 || is.ns6 || is.ns4) {
	actual_width = (available_width * 1.00 * MaxW/100);
	actual_height = (available_height * 0.99 * MaxH/100);

	if(actual_height/YsuXaspectRatio <= actual_width) {
		img_height = actual_height
		img_width = actual_height/YsuXaspectRatio
	}
	else {
		img_height = actual_width*YsuXaspectRatio
		img_width = actual_width
	}

	var bkGr = '<img SRC="' + srcIMG + '" name="titolo" height="' + img_height + '" width="' + img_width + '" style="border-style:fix" />';
	
	document.write(bkGr);
	}
}

//Inserisce l'immagine di sfondo centrata
function InnerScreen(srcIMG,YsuXaspectRatio) {
var available_width=availW();
var available_height=availH();
	
if(is.ie4 || is.ie5 || is.ie55 || is.ie6 || is.ns6 || is.ns4) {
	actual_width = (available_width * 0.89);
	actual_height = (available_height * 0.89);

	var marginStart='<TABLE width="' + available_width + ' height="100%"><TR align="center" ><TD>';
	var marginEnd='</TD></TR></TABLE>'; 

	if(actual_height/YsuXaspectRatio <= actual_width) {
		img_height = actual_height
		img_width = actual_height/YsuXaspectRatio
	}
	else {
		img_height = actual_width*YsuXaspectRatio
		img_width = actual_width
	}

	var bkGr = '<img SRC="' + srcIMG + '" name="titolo" height="' + img_height + '" width="' + img_width + '" style="border-style:fix" />';
	
	document.write(marginStart);
	document.write(bkGr);
	document.write(marginEnd);
	}
}

//forniscono Heigh e Width per una image
function img_height(YsuXaspectRatio) {
var available_width=availW();
var available_height=availH();
	
	if(is.ie4 || is.ie5 || is.ie55 || is.ie6 || is.ns6 || is.ns4) {
		actual_width = (available_width * 0.89);
		actual_height = (available_height * 0.89);

		if(actual_height/YsuXaspectRatio <= actual_width) {
			img_height = actual_height
		}
		else {
			img_height = actual_width*YsuXaspectRatio
		}
	}
	return img_height
}

function img_width(YsuXaspectRatio) {
var available_width=availW();
var available_height=availH();
	
	if(is.ie4 || is.ie5 || is.ie55 || is.ie6 || is.ns6 || is.ns4) {
		actual_width = (available_width * 0.89);
		actual_height = (available_height * 0.89);
	
		if(actual_height/YsuXaspectRatio <= actual_width) {
			img_width = actual_height/YsuXaspectRatio
		}
		else {
			img_width = actual_width
		}
	}
	return img_width;
}

//FunzioniAusiliarie per il rollover
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//FINE FUNZIONI DI ROLLOVER


//Inserisce l'immagine di sfondo come mappa sensibile centrata
//YX_AspRatio è dato dalla proporzione Y=YX_AspRatio*X
function SensitiveMap(srcIMG,map,YsuXaspectRatio) {
//Definire sotto la chiamata le corde e l'image frame da usare
var available_width=availW();
var available_height=availH();
	
if(is.ie4 || is.ie5 || is.ie55 || is.ie6 || is.ns6 || is.ns4) {
	actual_width = (available_width * 1.00);
	actual_height = (available_height * 0.99);
	

	var marginStart='<TABLE width="' + available_width + '"><TR align="center"><TD>';
	var marginEnd='</TD></TR></TABLE>'; 
	
	if(actual_height/YsuXaspectRatio <= actual_width) {
		img_height = actual_height
		img_width = actual_height/YsuXaspectRatio
	}

	else {
		img_height = actual_width*YsuXaspectRatio
		img_width = actual_width
	}

	//var bkGr = '<img SRC="' + srcIMG + '" height="' + img_height + '" width="' + img_width + '>';
	var bkGr = '<img SRC="' + srcIMG + '" name=base_' + map + ' height="' + img_height + '" width="' + img_width + '" usemap="#' + map + '" style="border-style:fix" />';
	
	document.write(marginStart);
	document.write(bkGr);
	document.write(marginEnd);
	}
} 

function mapRegion(isRegion,Xcord,Ycord,Rcord,regIndex,nCircle,imgPath,isImg,map){
//Costruisce le coordinate per un area di una mappa sensibile
	var mapRegionCoordinate='<area shape="circle"#' + isRegion + nCircle + ' coords="' + Xcord + ',' + Ycord + ',' + Rcord + '" href="#" target="_self" alt=' + isRegion + ' title=' + isRegion + ' onClick=selRegion(' + regIndex + ') onMouseOver=document.base_' + map + '.src="' + imgPath + isRegion + '.gif" onMouseOut=document.base_' + map + '.src="' + isImg + '">';
	return mapRegionCoordinate;
}


function selRegion(vRegion) {
//Seleziona il parametro Regioni=vRegion della form "SelectDbData" nel frame "mainFrame" e lancia la query
	parent.frames["mainFrame"].SelectDbData.Regioni.value=vRegion;
	parent.frames["mainFrame"].SelectDbData.submit();
}


function shwRegion(regIndex) {
//Seleziona l'immagine damostrare in base all'indice
var sImg="./Images/cartina_italia.gif";

	if (regIndex=="1") {
		sImg="./Images/lazio.gif";
	}
	else if (regIndex=="2") {
		sImg="./Images/abruzzo.gif";
	}
	else if (regIndex=="3") {
		sImg="./Images/toscana.gif";
	}
	else if (regIndex=="4") {
		sImg="./Images/umbria.gif";
	}
	else if (regIndex=="5") {
		sImg="./Images/molise.gif";
	}
	else if (regIndex=="6") {
		sImg="./Images/marche.gif";
	}
	else {
		sImg="./Images/cartina_italia.gif";
	}

	parent.frames["rightFrame"].base_regioni.src=sImg;
}

function insertImgLink(srcIMG,YsuXaspectRatio,extTableWidth,extTableHeight,linkType,linkReference,strTitle,tabIdx,lnkDst) {
//Inserisce una immagine con un link
//OPZIONI: MAIL,H_MAIL_TEXT,V_MAIL_TEXT,V_LINK_TEXT
var available_width=availW();
var available_height=availH();
	
if(is.ie4 || is.ie5 || is.ie55 || is.ie6 || is.ns6 || is.ns4) {
	actual_width = (available_width * extTableWidth);
	actual_height = (available_height * extTableHeight);
	
	if(actual_height/YsuXaspectRatio <= actual_width) {
		img_height = actual_height
		img_width = actual_height/YsuXaspectRatio
	}
	else {
		img_height = actual_width*YsuXaspectRatio
		img_width = actual_width
	}

	if(linkType=="MAIL"){
		var marginStart='<TABLE width="' + available_width + '"><TR align="center"><TD>';
		var marginEnd='</TD></TR></TABLE>'; 
		var bkGr = '<a href="mailto:' + linkReference + '"  title="' + strTitle + '"><img SRC="' + srcIMG + '" height="' + img_height + '" width="' + img_width + '" style="border-style:none" /></a>';
	}
	else if(linkType=="H_MAIL_TEXT"){
		var marginStart='<TABLE border="0" cellspacing="0" cellpadding="0"><TR valign="bottom" align="center"><TD valign="middle">';
		var marginEnd='</TD></TR></TABLE>'; 
		var bkGrImg = '<a href="mailto:' + linkReference + '"  title="' + strTitle + '"><img SRC="' + srcIMG + '" height="' + img_height + '" width="' + img_width + '" style="border-style:none" /></a>';
		var bkGrNC = '</td><td valign="middle">';
		var bkGrTxt = '<a href="mailto:' + linkReference + '"  class="mainPageLink">' + strTitle + '</a>';
		var bkGr = bkGrImg + bkGrNC + bkGrTxt;
	}
	else if(linkType=="V_MAIL_TEXT"){
		var marginStart='<TABLE border="0" cellspacing="0" cellpadding="0"><TR valign="bottom" align="center"><TD valign="middle">';
		var marginEnd='</TD></TR></TABLE>'; 
		var bkGrImg = '<a href="mailto:' + linkReference + '"  title="' + strTitle + '"><img SRC="' + srcIMG + '" height="' + img_height + '" width="' + img_width + '" style="border-style:none" /></a>';
		var bkGrNC = '<BR>';
		var bkGrTxt = '<a href="mailto:' + linkReference + '"  class="mainPageLink">' + strTitle + '</a>';
		var bkGr = bkGrImg + bkGrNC + bkGrTxt;
	}
		else if(linkType=="V_LINK_TEXT"){
		var marginStart='<TABLE border="0" cellspacing="0" cellpadding="0"><TR valign="bottom" align="center"><TD valign="middle">';
		var marginEnd='</TD></TR></TABLE>'; 
		var bkGrImg = '<a href="' + linkReference + '"  tabindex="' + tabIdx + '" title="' + strTitle + '" target="' + lnkDst + '"><img SRC="' + srcIMG + '" height="' + img_height + '" width="' + img_width + '" style="border-style:none" /></a>';
		var bkGrNC = '<BR>';
		var bkGrTxt = '<a href="' + linkReference + '"  tabindex="' + tabIdx + '" title="' + strTitle + '" target="' + lnkDst + '" class="mainPageLink">' + strTitle + '</a>';
		var bkGr = bkGrImg + bkGrNC + bkGrTxt;
	}

		else if(linkType=="V_LINK_TEXT_WS"){
		var marginStart='<TABLE border="0" cellspacing="0" cellpadding="0"><TR valign="bottom" align="center"><TD valign="middle">';
		var marginEnd='</TD></TR></TABLE>'; 
		var bkGrImg = '<a href="' + linkReference + '"  tabindex="' + tabIdx + '" title="' + strTitle + '" target="' + lnkDst + '"><img SRC="' + srcIMG + '" height="' + img_height + '" width="' + img_width + '" style="border-style:none" /></a>';
		var bkGrNC = '<BR>';
		var bkGrTxt = '<a href="' + linkReference + '"  tabindex="' + tabIdx + '" title="' + strTitle + '" target="' + lnkDst + '" class="mainPageLink, toolbar=0">' + strTitle + '</a>';
		var bkGr = bkGrImg + bkGrNC + bkGrTxt;
	}

	else {
		var bkGr = "Unassigned"
	}
	document.write(marginStart);
	document.write(bkGr);
	document.write(marginEnd);
	}
}



