//detect user's browser and OS and set global scripting variables
agt=navigator.userAgent.toLowerCase();
//ie=(document.all) ? 1:0
ie4=(agt.indexOf('msie 4')!=-1) ? 1:0
ie5=(agt.indexOf('msie 5')!=-1) ? 1:0
ie6=(agt.indexOf('msie 6')!=-1) ? 1:0
ie7=(agt.indexOf('msie 7')!=-1) ? 1:0
saf=(agt.indexOf('safari')!=-1) ? 1:0
ff=(agt.indexOf('firefox')!=-1) ? 1:0
nsx=(agt.indexOf('netscape')!=-1) ? 1:0
ns4=(document.layers && parseInt(navigator.appVersion)>=4) ? 1:0
win=( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) )
mac=(agt.indexOf("mac")!=-1);
imgs=(document.images) ? 1:0
ie=(ie5||ie6||ie7)?1:0
oldie=(ie5||ie6)?1:0
ns=(ns4||nsx||ff||saf)?1:0
ff=(ff||saf)
timeoout=1
keep=-1
var arrFormHide
var formHideNum = 2
//alert(nsx);

// questo serve per far funzionare menu su explorer 5 e 6
if (oldie){
	navHover = function() {
		var lis = document.getElementById("navmenu").getElementsByTagName("LI");
		for (var i=0; i<lis.length; i++) {
			lis[i].onmouseover=function() {
				this.className+=" iehover";
			}
			lis[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			}
		}
	}
if (window.attachEvent) window.attachEvent("onload", navHover);
}

function Mostra(selected,target) {//by Alessio 2007
	if (oldie){//deve nascondere form solo su explorer 5 e 6
		if (selected == 'SI') {
			document.getElementById(target).style.display = '';
		}
		else {
			document.getElementById(target).style.display = 'none';
		}
	}
}

//This block is used for certain forms and ViewTemplates that are having zindex issues
if (ff) {
	var zindexmodifier = 0;
}
else {
	var zindexmodifier = -1;
}

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_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_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];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function clearField(objField, strDefault){
	if (objField.value == strDefault){
		objField.value = "";
	}
}

function fillField(objField, strDefault){
	if (objField.value == ""){
		objField.value = strDefault;
	}
}

function color_div1(o,b){ //explorer
	if(!ff){
		if(b==1){
			o.style.backgroundColor = "#EAEAEA";
		}
		else{
			o.style.backgroundColor = "#FFFFFF";
		}
	}
}
function color_div2(o,b){ //firefox
	if(ff){
		if(b==1){
			o.style.backgroundColor = "#EAEAEA";
		}
		else{
			o.style.backgroundColor = "#FFFFFF";
		}
	}
}
function color_div3(o,b){ //entrambi
	if(b==1){
		o.style.backgroundColor = "#EAEAEA";
	}
	else{
		o.style.backgroundColor = "#FFFFFF";
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function ale_jumpMenu(selObj,restore){ //Ale2008
	var indirizzo = selObj.options[selObj.selectedIndex].value;
	if (restore) selObj.selectedIndex=0;
	var lunghezza = indirizzo.length;
	var pos = indirizzo.lastIndexOf("~");
	var url;
	if (pos > -1) {
		url = indirizzo.substring(1);
		window.open(url);
		selObj.selectedIndex=0;
	}
	else {
		url = indirizzo;
		eval("parent.location='"+url+"'");
	}
}

function roll(obj) {
var o = document.images[obj];
	var base=o.name;
	var path=o.src;
	var file=path.substring(0,path.length-4);
	var newImage=file + "_roll.gif";
	o.src=newImage;

	return;
}

function restore(obj) {
var o = document.images[obj];
	var base=o.name;
	var path=o.src;
	var file=path.substring(0,path.length-9);
	var newImage=file + ".gif";
	o.src=newImage;
	return;
}

function emailPage(doctitle, urlpath, m, id) {
	doctitle = doctitle.replace("&","e");
	var url = 'emailpage.asp?urlpath=' + urlpath + '&pagetitle=' + doctitle + '&m=' + m + '&id=' + id;
	var newWin = window.open(url,'RivoiraEmail','scrollbars=0,toolbar=0,menubar=0,resizable=0,location=0,status=1,copyhistory=1,width=272,height=420');
}

function printPage(m,id) {
	var url = 'printpage.asp?m=' + m + '&id=' + id;
	// A width of 650 is the approximate print width on 8.5" x 11" paper
	var newWin = window.open(url, 'Print', 'scrollbars=1,toolbar=0,menubar=1,location=0,resizable=1,width=650,height=400');
}

function printPage2(m,id,page,regioni) {
	var url = 'printpage.asp?m=' + m + '&id=' + id + '&page=' + page + '&regioni=' + regioni;
	// A width of 650 is the approximate print width on 8.5" x 11" paper
	var newWin = window.open(url, 'Print', 'scrollbars=1,toolbar=0,menubar=1,location=0,resizable=1,width=650,height=400');
}

function getyear(){
     now = new Date();
     document.write(now.getFullYear());
}

function cerca(modulo){
	var miaRicerca = modulo.searchtxt.value;
	if ((miaRicerca=="") || (miaRicerca=="undefined") || (miaRicerca=="   < Search >")){
		return false;
	} else {
		modulo.action = "cerca.asp";
		modulo.submit();
	}
}

function checkEnter(e,siteSearchfrm){
var characterCode
	 if(e && e.which){
	 e = e
	 characterCode = e.which
	 }
	 else{
	 e = event
	 characterCode = e.keyCode
	 }	 
	 if(characterCode == 13){
 	 cerca(siteSearchfrm);
 	 return false
	 }
return true
	
}
