//rilevo SO e Browser
SOWIN = (navigator.userAgent.toLowerCase().indexOf("win") > -1) ? 1 : 0;
SOMAC = (navigator.userAgent.toLowerCase().indexOf("mac") > -1) ? 1 : 0;
SOLIN = (navigator.userAgent.toLowerCase().indexOf("linux") > -1) ? 1 : 0;
SOALT = (!SOWIN && !SOMAC && !SOLIN) ? 1 : 0;
OP = ((ind1 = navigator.userAgent.indexOf("Opera")) > -1) ? 1 : 0;
punto = (OP) ? navigator.userAgent.indexOf(".",ind1):0;
OP5 = (OP && parseInt(navigator.userAgent.substr(punto-1)) == 5) ? 1 : 0;
OP6 = (OP && parseInt(navigator.userAgent.substr(punto-1)) == 6) ? 1 : 0;
IE = ((ind2 = navigator.appVersion.indexOf("MSIE")) > -1 && !OP) ? 1 : 0;
IE4 = (IE && parseInt(navigator.appVersion.substr(ind2+5)) == 4) ? 1 : 0;
IE5 = (IE && parseInt(navigator.appVersion.substr(ind2+5)) == 5) ? 1 : 0;
IE6 = (IE && parseInt(navigator.appVersion.substr(ind2+5)) == 6) ? 1 : 0;
NN = (navigator.appName.indexOf("Netscape")>-1) ? 1 : 0;
NN4 = (NN && parseInt(navigator.appVersion)==4) ? 1 : 0;
NN6 = (NN && parseInt(navigator.appVersion)>4) ? 1 : 0;
GE = (navigator.userAgent.toLowerCase().indexOf("gecko")>-1) ? 1 : 0;
//riconosce mozilla, NN6 e tutti i browser basati sul gecko layout engine


var lingua = "ita";


/*
* PROTOTYPE
*/
String.prototype.equalsIgnoreCase = matchIgnoreCase;
function matchIgnoreCase(strTerm) {
    var strToSearch = this.toLowerCase();
    strTerm = strTerm.toLowerCase();
    if (strToSearch==strTerm)
        return true
    else
        return false
}

String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,'') }


<!--
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];}
}
//-->

	function JWM_swapImage() {
	  a = JWM_swapImage.arguments;
	  document.JWM_tmp = new Array;
	  j=0;
	  for (i=0;i<(a.length-1);i+=2) {
	    x = document.getElementById(a[i]);
	    document.JWM_tmp[j++] = x;
      if(!x.oSrc) x.oSrc=x.src;
      x.src = a[i+1];
	  }
	}

	function JWM_swapImgRestore() {
    a = document.JWM_tmp;
    for (i=0;a&&i<a.length&&a[i].oSrc;i++)
      a[i].src = a[i].oSrc;
	}


//aggiunge il parametro specificato alla querystring
function addParameter(nome,valore) {
  for (var l=0; l<document.links.length; l++) {
    var abslink = document.links[l].href.indexOf("http://");
    var intlink = document.links[l].href.indexOf("#");
    var jslink = document.links[l].href.indexOf("javascript:");  //forse va trattato!!!!
    var jwmlink = document.links[l].href.indexOf("http://");   //forse è meglio aggiungere il nome dell'applicazione
    var isjsp = (document.links[l].href.indexOf(".jsp")!=-1)?true:false;
    var separatore = (document.links[l].href.indexOf("?")!=-1)?"&":"?";

    if (intlink==-1 && jslink==-1 && jwmlink!=-1 && isjsp)
      document.links[l].href += separatore+nome+"="+valore;
  }
}

//ritorna undefined se il parametro non è definito
function getParameter(nome) {

   var url = window.location.href;
   var paramsStart = url.indexOf("?");
   if (paramsStart != -1) {
      var paramString = url.substr(paramsStart + 1);
      var tokenStart = paramString.indexOf(nome);

      if (tokenStart != -1) {
         paramToEnd = paramString.substr(tokenStart + nome.length + 1);
         var delimiterPos = paramToEnd.indexOf("&");

         if (delimiterPos == -1) {
            return paramToEnd;
         } else {
            return paramToEnd.substr(0, delimiterPos);
         }
      }
   }
}

function getParameters() {
   var params = new Array();
   var url = window.location.href;
   var paramsStart = url.indexOf("?");
   var hasMoreParams = true;

   if (paramsStart != -1) {
     var paramString = url.substr(paramsStart + 1);
     var params = paramString.split("&");
     for (var i = 0 ; i < params.length ; i++) {
       var pairArray = params[i].split("=");
       if (pairArray.length == 2) {
         params[pairArray[0]] = pairArray[1];
       }
     }
     return params;
   }
}


function getAttributo(el,attr,isselect) {
  retval = document.getElementById(el)

  if (retval) {
    if (isselect)
      return eval("retval.options[retval.selectedIndex]."+attr)
    else
      return eval("retval."+attr)
  }
}

function vai(desturl,repl) {
  if (desturl && desturl!="") {
    if (repl)
      document.location.replace(desturl)
    else
      document.location = desturl
  }
}


function cerca(form,id,error) {
    if (trimString(document.getElementById(id).value) == '' ) {
       alert(error)
    } else {
     document.forms[form].submit();
    }
}

function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}
//stampa la data in formato gg/mm/aaaa
//o mm/gg/aaaa se passiamo 'eng'
function printUltimaModifica(lng) {
  var mydate = new Date(document.lastModified);
  var g = mydate.getDate();
  var gg = new String(g);
  gg = gg.length==1?"0"+g:g;
  var m = mydate.getMonth();
  var mm = new String(m);
  mm = mm.length==1?"0"+(m+1):(m+1);
  var aaaa = mydate.getFullYear();
  if (lng=="eng")
    document.write(mm+ "/" + gg + "/" + aaaa)
  else
    document.write(gg+ "/" + mm + "/" + aaaa)

}

//funzione per "nascondere" un layer
function hideLayers() {
  //compatibilità: Netscape 6.x, Explorer 5 e 6, Opera 5 e 6, Mozilla
  a = hideLayers.arguments;
  for (i=0;i<a.length;i++) {
    if (document.getElementById(a[i])) {
      //document.getElementById(a[i]).style.visibility="hidden";
      document.getElementById(a[i]).style.display="none";
    }
  }
}

//rende visibile un layer
function showLayers() {
  //compatibilità: Netscape 6.x, Explorer 5 e 6, Opera 5 e 6, Mozilla
  a = showLayers.arguments;
  for (i=0;i<a.length;i++) {
    if (document.getElementById(a[i])) {
      //document.getElementById(a[i]).style.visibility="visible";
      document.getElementById(a[i]).style.display="block";
    }
  }
}


//simo per gestione apri chiudi form si ricerca
function nobox(nome) {
document.getElementById(nome).style.display='none'
}
function box(nome) {
document.getElementById(nome).style.display='block'
}

//ricerca eventi
function cercaEv(fnome) {
  var campot=document.getElementById('ev_tema');
  document.getElementById('n_tema').value=campot.options[campot.selectedIndex].text;
  var campod=document.getElementById('ev_dest');
  document.getElementById('n_dest').value=campod.options[campod.selectedIndex].text;
  var campom=document.getElementById('ev_mese');
  document.getElementById('n_mese').value=campom.options[campom.selectedIndex].text;
  document.forms[fnome].submit();
}

//ritorna true se una variabile o una funzione è definita
function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}


//funzione per il controllo lato client sui campi obbligatori
// - da aggiungere nell'attributo 'onsubmit' della form
// - richiede un campo hidden con id='requiredfields' con
//   l'elenco dei nomi dei campi obbligatori separati da virgola (AND)
// - supporta anche parentesi e || per creare diverse combinazioni di campi
//   obbligatori
// - se viene specificato un campo hidden con id='requiredfieldsmsg',
//   questo viene visualizzato in caso non siano compilati tutti i
//   campi obbligatori.
function validateForm(_form) {

  var reqfields = document.getElementById('requiredfields');
  var reqfieldsmsg = document.getElementById('requiredfieldsmsg');

	try
	{

		if (reqfields && reqfields.value.trim().length > 0)
		{
	    var rf = reqfields.value;

	    var re = new RegExp(",","gi");
	    rf = rf.replace(re,'&&');
	    re = new RegExp("\s","gi");
	    var rf2 = rf.split(/[\s&&\(\)||]/gi);

	    for (var i = 0; i < rf2.length; i++)
			{
	      var token = rf2[i].trim();
	      if (token.length > 0)
				{
	        var valcampo = false;
	        if (isFilled(_form, token))
					{
	          valcampo = true;
					}

	        rf = rf.replace(token,valcampo)
	      }
	    }
	    //alert(rf)

	    re = null;
	    rf2 = null;

	    var err = false;
	    eval("if(!("+rf+")) err=true")

	    if (err)
	    {
	      alert(reqfieldsmsg&&reqfieldsmsg.value!='' ? reqfieldsmsg.value : 'Per proseguire è necessario compilare tutti i campi obbligatori')

	      return false;
	    }
	    else
	    {
	      return true;
	    }

	  } //end if ci sono campi obbligatori

	  return true;

	}
  catch (e)
  {
    alert(e.message);

    return false;
  }
}



function isFilled(_form, _el) {

  var filled = false;

  for (var i=0;_form.elements[i];i++)
  {
    var campo = _form.elements[i];
    if (campo && campo.name == _el)
    {
      switch (campo.type) {
	case "select-one":
          if (campo.selectedIndex!=-1 && campo.options[campo.selectedIndex].value!="") {
            filled = true;
          }
	  break;
        case "select-multiple":
          for (var x=0; x < campo.length; x++)
          {
            if (campo[x].selected == true)
            {
              filled = true;
              break;
            }
          }
	  break;
	case "radio":
          if (campo.checked) return true;
          break;
	case "checkbox":
          if (campo.checked) return true;
	  break;
/*
case "file":
case "text":
case "textarea":
*/
	default:
		if (campo.value.trim() != '')
		{
			filled = true;
		}
	  break;
      }
    }
  }

  return filled;
}








