var nav6 = true;
var ie, ver, dom, nav;
var coll="";
var styleObj="";
var dominio = "sivaf.it"
var protocollo = "http"

var pathLinux = protocollo+ "://www1." + dominio;
var pathWindows = protocollo + "://www." + dominio;
var extLinux = "htm";
var extWindows = "asp";
var timeLogOut = 1200000
//var timeLogOut = 15000

browserDetect();

/* Browser Detection - browserDetect() will detect both the browser type and the version number.
   	nav/ie: browser type, ver:    version number */
function browserDetect(){
	var agt=navigator.userAgent.toLowerCase();
	if ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible')==-1))) {
		nav=1;
		ie=0;
		lastWidth = window.innerWidth;
		lastHeight = window.innerHeight;
		window.onresize = handleResize;
		ver=parseFloat(navigator.appVersion)
		if ((ver>=4) && (ver < 5))
			dom="document.layers";
		else{
			nav6 = false;
			ie = 1;
			nav = 0;
			dom="document.all";
			coll="all."
			styleObj=".style";
		}
	} else if (agt.indexOf("msie")!=-1) {
		ie=1;
		nav=0;
		s=navigator.appVersion;
    	s=s.substr(s.indexOf("MSIE")).substr(5);
    	ver=parseFloat(s)
		if (ver>=4) {
			dom="document.all";
			coll="all."
			styleObj=".style";
		}
	}
}

/* Window Resize Handler - standard handler for dealing with netscape's resizing problems */
function handleResize(){
	winWidth = window.innerWidth;
	winHeight = window.innerHeight
	if ((lastWidth != winWidth) && (lastHeight != winHeight)){
		lastWidth = winWidth;
		lastHeight = winHeight;
		location.reload();
	}
}

/* Layer Construction (Write) - layerMakeWrite() creates a LAYER for nextscape and
   a DIV for IE. It should be called from in the BODY of the document, as it will
   WRITE the layer wherever it is. If you need to nest a layer or call the function
   elsewhere use layerMakeReturn, which returns a value.
   Arguments:
	n:   name
	w:   width
	h:   height
	x:   left
	y:   top
	z:   z-index
	cls: class
	vis: visibility (0=hide/1=show)
	cnt: starting content
	exn: extra event handler info for netscape, note that these need to be spaced out attribute, eg: 'onMouseover="someFunction()" onMouseout="someFunction()"'
	exe: extra event handler info for explorer
	eg: layerMakeWrite('mylayer',180,50,480,400,1,myClass,1,'This is what's in the layer','','');*/
function layerMakeWrite(n,w,h,x,y,z,cls,vis,cnt,exn,exe) {
	if (ver>=4) {
		if (nav) {
			vis==1?vis='show':vis='hide';
			document.write('<layer width='+w+' height='+h+' left='+x+' top='+y+' name="'+n+'" id="'+n+'" z-index='+z+' visibility='+vis+' class="'+cls+'" '+exn+'>'+cnt+'</layer>');
		} else if (ie) {
			vis==1?vis='visible':vis='hidden';
			document.write('<div id="'+n+'" style="position:absolute; width:'+w+';height:'+h+';left:'+x+';top:'+y+';z-index:'+z+';visibility:'+vis+';" '+exe+' class="'+cls+'" >'+cnt+'</div>');
		}
	}
}


/* Mouse rollover for image swapping within layers.
   Arguments:
	layRef: name of parent layer
	imgRef: name of image (<img name="?">) within layRef layer
	srcRef: new src value for <img> */
function rollover(layRef,imgRef,srcRef) {
	if (nav){
		if ((layRef==null)||(layRef==''))
		{
		    document[imgRef].src = srcRef;
		}
		else
		{
		    document.layers[layRef].document.images[imgRef].src = srcRef;
		}
	} else if (ie)
        document[imgRef].src = srcRef;
}

/* Make a layer invisible.
   Argument(s):	layRef: string reference to layer name. */
function hideLayer(layRef) {
	if (nav) {
		document[layRef].visibility = "hide";
	}
	if (ie) {
	  	document.all[layRef].style.visibility = "hidden";
	}
}

/* Make a layer visible.
   Argument(s):	layRef: string reference to layer name.*/
function showLayer(layRef) {
 	if (nav) {
  		document[layRef].visibility = "show";
	}
	if (ie) {
  		document.all[layRef].style.visibility = "visible";
	}
}


/* Open a seperate window.
   Arguments:
	theURL:
	winName:
	features:*/
function openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

/* Layer Construction (specific use) - layerWriteHTML() creates a LAYER for nextscape
   and a IFRAME for IE. It should be called from in the BODY of the document, as it
   will WRITE the layer wherever it is.
   Arguments: n: name, w: width, h: height, x: left, y: Top, z: z-index, cls: class, vis: visibility (0=hide/1=show)
	ex:  extra event handler info, eg: layerWriteHTML('mylayer',180,50,480,400,1,myClass,1,'');
*/
function layerWriteHTML(n,w,h,x,y,z,cls,vis,ex){
	if (ver>=4) {
		if (nav) {
			vis==1?vis='show':vis='hide';
			document.write('<layer width='+w+' height='+h+' left='+x+' top='+y+' id="'+n+'" z-index='+z+' visibility='+vis+' class="'+cls+'" '+ex+'></layer>');
		} else if (ie) {
			vis==1?vis='visible':vis='hidden';
			document.write('<iframe name="'+n+'" id="'+n+'" src="/blank.htm" style="position:absolute; width:'+w+';height:'+h+';left:'+x+';top:'+y+';z-index:'+z+';visibility:'+vis+'; " frameBorder="0" marginHeight="0" marginWidth="0"'+ex+' class="'+cls+'" ></iframe>');
		}
	}
}

/* Load an HTML file into a layer with the layerWriteHTML() function.
   Arguments: layRef: layer name, hRef: url of HTML file
*/
function writeHTML(layRef,hRef){
	if (ver>=4) {
		if (nav)
			document[layRef].src = hRef;
		else if (ie)
			document.all[layRef].src = hRef;
	}
}

/* Form Reference function
	layRef: name of parent layer
	formRef: name of form being submitted
	returns a reference to the form. */
function getFormRef(layRef,formRef)
{
	formObj=null;
	if (nav)
	{
	    if ((layRef==null)||(layRef==''))
			formObj=document.forms[formRef];
		else
		    formObj=document.layers[layRef].document.forms[formRef];
	}
	else if (ie)
		formObj=document.forms[formRef];
	return formObj;
}

function showIFrame(layRef) {
	if (nav)
		document[layRef].visibility = "show";
	if (ie)
        top.document.all[layRef].style.visibility = "visible";
}


/* Hide Iframes in IE and layers in Nav.
   Argument(s):	layRef: string reference to layer name.*/
function hideIFrame(layRef) {
	if (nav)
		document[layRef].visibility = "hide";
	if (ie)
        top.document.all[layRef].style.visibility = "hidden";
}

// navigate different URL
function navigateTo(url){
	if ((url==null)||(url=="null"))
		top.bottomFrame.location	= "#";
	else
		top.bottomFrame.location	= url;
}

function jArrotonda(NumeroPartenza, UltimaCifraSignificativa) {
//Arrotonda un numero con le cifre decimali specificate
	var NumeroArrotondato;
	NumeroPartenza = parseFloat(NumeroPartenza * Math.pow(10, UltimaCifraSignificativa));
	NumeroPartenza = Math.round(NumeroPartenza);
	NumeroArrotondato = NumeroPartenza / Math.pow(10, UltimaCifraSignificativa);
	return(NumeroArrotondato);
}

function FormattaNumero(iNumero, iDecimali, formato){
	var bNegativo, sRet, buff, arBuff, dots
	var sNumero = new String(iNumero);
	if (formato=='undefined' || formato==null)
		formato='ita';
	
	if (formato.toLowerCase()!='eng')
	{
		if(sNumero.indexOf(".") > -1)
			sNumero = sNumero.replace('.','');
			
		sNumero = sNumero.replace(',','.');
	}	
	sNumero=jArrotonda(sNumero, iDecimali);
	
	bNegativo=false;
	/*if (parseFloat(sNumero)<0){
		bNegativo=true;
		sNumero *= -1;
	}*/
	
	sRet='';
	dots=0;
	sNumero = new String(sNumero);
	arBuff=sNumero.split('.');
	buff=parseFloat(arBuff[0]);
	while(buff>=1000){
		buff/=1000;
		dots++;
	}
	
	while(dots>0){
		sRet='.' + arBuff[0].substr(arBuff[0].length-3,3) + sRet;
		arBuff[0]=arBuff[0].substr(0,arBuff[0].length-3);
		dots--;
	}
	
	if(arBuff[0]!='') sRet = arBuff[0] + sRet;
	buff='';
	if(arBuff.length>1) buff=arBuff[1];
	while(buff.length<parseFloat(iDecimali)) buff+='0';
	if(parseFloat(iDecimali)>0) sRet+=',' + buff;
	
	return sRet;
}

//Read Cookie
function readCookie(name){
	var COOKIE = document.cookie;
	var start = COOKIE.indexOf(name + "=");

	if (start==-1)
		return 0;
	start = COOKIE.indexOf("=", start) + 1;
	var end = COOKIE.indexOf(";", start);

	if (end == -1)
		end = COOKIE.length;

	var value = unescape(COOKIE.substring(start, end));

	if (value==null)
		return 00;
	return value;
}

//Del Cookie
function delCookie(name){
	var COOKIE = document.cookie;
	if (readCookie(name) != 00 )
		document.cookie = name+"=;expires=Thu, 01-Jan-1970 00:00:01 GMT"
}

//Set Cookie
function setCookie(name,value,exp){
	if (typeof(exp)=="undefined"){expTxt = ""}else{expTxt = "expires="+exp}
	//alert(name+"="+value+";"+expTxt)
	document.cookie = name+"="+value+";path=/;"+expTxt
}

function getDoc(layer){
	if(nav)
		return document.layers[layer].document;
	else
		return document;
}

function MsgSezione_PopUp( Msgtemp1, Msgtemp2)
{
	if (Msgtemp2 != "")
	{
		alert(Msgtemp2);
	}
	if (Msgtemp1 != "")
	{
		window.open("/libraries/MsgSezione_PopUp.html?testo=" + Msgtemp1, "MsgWind", "width=500,height=200,toolbar=no,scrollbars=yes,resizable=no");
	}
}

function getDoc(layer){
	if(nav)
		return document.layers[layer].document;
	else
		return document;
}

function Stolowerc(sParola)
{
	var sVal= new String(sParola);
	return sVal.toLowerCase();
	
}

