function elimina () {
if (confirm("Confermi eliminazione?")) {
	document.FormImmisione.ope.value=70;
	document.FormImmisione.submit();
}
}
//funzione per prendere uno stile
function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function changeRadioValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


function changeCheckValue(checkObj) {

if (checkObj.checked==true)
	checkObj.checked=false;
else
	checkObj.checked=true;
}


function focussusearch() {
var textsearch=document.getElementById("fieldsearch");
if (textsearch!= null) {
textsearch.focus();
textsearch.select();
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
/*function CambiaColorePrimaRiga() {
var myElement = document.getElementById("Rig1");
myElement.setAttribute("class",  "selected");	
}
*/
function ChiediConferma(testoconferma) {
if (confirm(testoconferma)) {
	document.forms[0].submit();
}
}

function CambiaColore(iNumRiga,idrec,script) {
var Righe=document.getElementById("TabellaDati").tBodies[0].rows.length;
for (i=0;i<Righe;i++) {
	var myElement = document.getElementById("Rig" + i);
	if (myElement!= null)
		myElement.setAttribute((document.all ? "className" : "class"),  "normal");
}
var myElement = document.getElementById("Rig" + iNumRiga);
myElement.setAttribute((document.all ? "className" : "class"),  "selected");
document.passaparametri.PPID.value=idrec;
/*
myElement !=  document.getElementById("RigSel");
if (myElement !=  null)
	myElement.value=iNumRiga;
*/
}

function NMA_gotopage(direction){
if (direction==0)
	document.FormImmisione.page2go.value=document.FormImmisione.ppage.value;
else
	document.FormImmisione.page2go.value=document.FormImmisione.npage.value;
}


function TornaAlPadre() {
document.passaparametri.ope.value=4;
document.passaparametri.submit();
}

function TornaAlFratello() {
document.passaparametri.ope.value=20;
document.passaparametri.submit();
}


function LanciaMenuScorri(dove) {
document.passaparametri.ope.value=100;
document.passaparametri.PPsf.value=dove;
document.passaparametri.submit();
}

function LanciaMenuHelp() {
document.passaparametri.ope.value=200;
document.passaparametri.submit();
}

function LanciaRicerca(ope) {
var searchcommand=document.search.field.value;
document.passaparametri.ope.value=ope;
document.passaparametri.PPsf.value=document.search.field.value;
document.passaparametri.submit();
}



function CreaFiltro() {
document.passaparametri.PPsf.value=document.formsearch.nIndexSearch.value + document.formsearch.nOpera.value + document.formsearch.sVaria.value ;
if (document.formsearch.ncollega) 
	document.passaparametri.PPsf.value=document.formsearch.ncollega.value +  document.passaparametri.PPsf.value;
document.passaparametri.ope.value=100;
//alert(document.passaparametri.PPsf.value + " " + document.passaparametri.ope.value);
document.passaparametri.submit();
}


function LanciaMenuAnnullaFiltro(){
document.passaparametri.ope.value=100;
document.passaparametri.PPsf.value='af';
document.passaparametri.submit();
}

function selezionaFiltro(numfiltro){
document.passaparametri.ope.value=0;
document.passaparametri.PPnf.value=numfiltro;
document.passaparametri.submit();
}

function SalvaFiltro(numfiltro) {
document.passaparametri.ope.value=102;
document.passaparametri.numfiltro.value=numfiltro;
document.passaparametri.submit();
}

function ModificaNote(i,numfiltro) {
k=document.passaparametri.maxrighe.value;
for (h=0;h<k;h++) {
	strClasse="nascondi";
	if (h==i)
		strClasse="mostra";
	var myElement = document.getElementById("area_" + h);
	myElement.setAttribute((document.all ? "className" : "class"),  strClasse);
}
}

function TornaIndietrooChiudi(script,querystring) {
	window.location.href=script + '?ope=0' +querystring;
	return;
	if (!history.go(-1))
		window.close();
}

function LanciaMenu(url,ope,conferma,testoconferma,ServeID,NewWindow) {
esegui=false;
if (ope==0) {
	if(typeof(document.passaparametri.PPvi) != "undefined")
		document.passaparametri.PPvi.value="";
}
if (ServeID=='SI' && (document.passaparametri.PPID.value==0 || document.passaparametri.PPID.value=="")) {
	alert("Operazione non disponibile! Selezionare un Record");
	exit();
}
if (conferma) {
	if (confirm(testoconferma)) 
		esegui=true;
}
else
	esegui=true;	
if (esegui) {
	if (url!="") 
		document.passaparametri.action=url;
	if (NewWindow=="SI"){
		//alert("SI");
		//win=window.open('','myWin','toolbars=0');
		//document.passaparametri.target='myWin';
		document.passaparametri.target='_blank';
	}
	else {
		//alert(document.passaparametri.target);
		document.passaparametri.target='_self';
	}
	var tiporeq=document.passaparametri.method;
	if (tiporeq.toUpperCase()=="GET") {
		var  getstr=url.split("?");
		lungetstr=getstr.length;
		if (lungetstr>1) {
			var form = document.forms['passaparametri'];				
			var newval=getstr[1].split("&");
			for (i=0;i<newval.length;i++) {
				var valname=newval[i].split("=");
				var el = document.createElement("input");
				el.type = "hidden";
				el.name = valname[0];
				el.value = valname[1];
				form.appendChild(el);
			}
		}
	}
	document.passaparametri.ope.value=ope;
	//document.passaparametri.method="POST";
	document.passaparametri.submit();
}
}


function LanciaMenuOrdina(ope,ordina) {
document.passaparametri.ope.value=ope;
if (ordina==document.passaparametri.PPor.value) {
	if (document.passaparametri.PPto.value==0) 
		document.passaparametri.PPto.value=1;
	else
		document.passaparametri.PPto.value=0;
}
else
	document.passaparametri.PPto.value=0;
document.passaparametri.PPor.value=ordina;
document.passaparametri.submit();
}


function VisualizzaCommento(numcampi) {
for (i=0;i<numcampi;i++) {
	var myElement = document.getElementById("commento" + i);
	if (myElement!= null) {
		nomeattr=myElement.getAttribute((document.all ? "className" : "class"));
		if (nomeattr=="commentovisibile")	
			myElement.setAttribute((document.all ? "className" : "class"),"commentonascosto");
		else
			myElement.setAttribute((document.all ? "className" : "class"),"commentovisibile");
	}
}
}

function NonfaNulla(){
}


function CercaDatiTabellaDecodifica(i,script,CampoForm) {
var myElement=document.forms[0].elements[CampoForm];
nomeattr=myElement.getAttribute((document.all ? "className" : "class"));
if (nomeattr=="combo") {
	myElement.setAttribute((document.all ? "className" : "class"),"nascondi");
	myElement=document.forms[0].elements[CampoForm + "_CERCA"];
	myElement.setAttribute((document.all ? "className" : "class"),"field");	
	myElement.focus();
	myElement=document.forms[0].elements[CampoForm + "_ButtonCerca"];
	myElement.setAttribute((document.all ? "className" : "class"),"cerca");
	
}
else {
myElement.setAttribute((document.all ? "className" : "class"),"combo");
myElement=document.forms[0].elements[CampoForm + "_CERCA"];
myElement.setAttribute((document.all ? "className" : "class"),"nascondi");
myElement=document.forms[0].elements[CampoForm + "_ButtonCerca"];
myElement.setAttribute((document.all ? "className" : "class"),"cercaselect");	

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Il tuo browser non supporta Ajax!");
  return;
} 
var url=script;
var a=document.forms[0].elements[CampoForm + "_CERCA"].value;
url=url+"?ope=10020&chiave=" + CampoForm + "&ricerca=" + a + "&indice=" + i ;
Oggetto=document.forms[0].elements[CampoForm];
xmlHttp.onreadystatechange= function(){
if (xmlHttp.readyState==4) {
	var risposta=new String(xmlHttp.responseText);
	var numrighe=risposta.split("|");
	totaledati=numrighe.length/3;
	Oggetto.options.length = 0;

	daselezionare=0;
	for(var i = 0; i < totaledati; i++) {
		k=i*3;
		j=k+1;
		
		var opt = new Option(numrighe[j],numrighe[k]);
		Oggetto.options[Oggetto.options.length] = opt;
		if (numrighe[k+2]==1)
			daselezionare=i;
			
	}
	Oggetto.selectedIndex=daselezionare;
	Oggetto.focus();
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}

//da cancellare
function AggiornaSelectOld(Oggetto,script,chiaveCampo,ope) {
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
	alert ("Il tuo browser non supporta Ajax!");
	return;
} 
var url=script;
url=url+"?ope=" + ope + "&Campo=" + chiaveCampo;
xmlHttp.onreadystatechange= function(){
if (xmlHttp.readyState==4){
	var risposta=new String(xmlHttp.responseText);
	var numrighe=risposta.split("|");
	totaledati=numrighe.length/3;
	Oggetto.options.length = 0;

	daselezionare=0;
	for(var i = 0; i < totaledati; i++) {
		k=i*3;
		j=k+1;
		
		var opt = new Option(numrighe[j],numrighe[k]);
		Oggetto.options[Oggetto.options.length] = opt;
		if (numrighe[k+2]==1)
			daselezionare=i;
			
	}
	Oggetto.selectedIndex=daselezionare;
	Oggetto.focus();
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}


function SelezioneCampo(ID,chiave,i) {
	var linkInnerText=document.getElementById("decHref" + i);
	document.forms[0].elements[chiave].value = linkInnerText.innerHTML;
	var DivDecodifica=document.getElementById("DivDec" + chiave);
	DivDecodifica.setAttribute((document.all ? "className" : "class"),"decodifica");
}


function rimettiInnerHtmlOriginal(i) {
var myElement = document.getElementById("idriga_" + i);
if (myElement!=null) {
	strOriginal=myElement.innerHTML;
	strITD=strOriginal.split('<br>');
	if (strITD.length>1) {
		myElement.innerHTML=strITD[0];	
		myElement.style.color="";
	}
}
}

function VerificaNonPresenzaErrore(k,giaUnErrore,formOKres,Msg) {
if (document.forms[0].elements[k].value=="")  {
	if (giaUnErrore==0)
		rimettiInnerHtmlOriginal(k);	
}
else {
	var myElement = document.getElementById("idriga_" + k);
	myElement.style.color="rgb(255,0,0)";
	myElement.innerHTML=myElement.innerHTML + "<br><span style=\"font-size: 80%; font-weight:bold;\">" + Msg + "</span>";
	formOKres[0]=false;
}
}

function testIsValidObject(objToTest) {
	if (null == objToTest) {
		return false;
	}
	if ("undefined" == typeof(objToTest) ) {
		return false;
	}
	return true;

}

function checkvalue(continua) {
lungh=ElencoCampi.length;
k=0;

formOK= new Array(true);


primoErrore=-1;
for (i=0;i<lungh;i++) {
	giaUnErrore=0;

	k=ElencoCampi[i];
	//var myElement = document.getElementById("idriga_" + i);
	//if (myElement!=null) {

	if (TipoCampo[i]!="0"  && testIsValidObject(document.forms[0].elements[k]) ) {
		if ((document.forms[0].elements[k].value == "") && (TipoCampoForm[i] != "AUTO") && (TipoCampoForm[i] != "PERS"))  {
			if ( CampoObbligatorio[i]=="1")  {
				var myElement = document.getElementById("idriga_" + k);
				myElement.style.color="rgb(255,0,0)";
				strOriginal=myElement.innerHTML;
				strITD=strOriginal.split('<br>');
				if (minlen[i]>0) 
					myElement.innerHTML=strITD[0] + "<br><span style=\"font-size: 80%; font-weight:bold;\">(Minimo numero di caratteri: " + minlen[i] + ")</span>";
				else
					myElement.innerHTML=strITD[0] + "<br><span style=\"font-size: 80%; font-weight:bold;\">(Campo obbligatorio)</span>";
				formOK[0]=false;

				giaUnErrore=1;
			}
		}
		else {
			if ( CampoObbligatorio[i]=="1" && TipoCampo[i]=='d' && document.forms[0].elements[k].value=="00-00-0000")  {
				var myElement = document.getElementById("idriga_" + k);
				myElement.style.color="rgb(255,0,0)";
				strOriginal=myElement.innerHTML;
				strITD=strOriginal.split('<br>');
					myElement.innerHTML=strITD[0] + "<br><span style=\"font-size: 80%; font-weight:bold;\">(Campo obbligatorio)</span>";
				formOK[0]=false;
			}
			else 
			rimettiInnerHtmlOriginal(k);			
		}
		if (TipoCampoForm[i]=="TEXT" || TipoCampoForm[i]=="AREA") {
			switch (TipoCampo[i]) {
				case 'c':
				case 'lc':
					break;
				case 'i':
					if (!(isInteger(document.forms[0].elements[k].value))) {
						VerificaNonPresenzaErrore(k,giaUnErrore,formOK,"(Inserire solo caratteri numerici evitando spaziature o simboli di separazione quali \" , \" \" &acute; \" \" . \" ))");
					}
					break;
				case 'd':
					today=new Date();
					anno=today.getFullYear();

					b=document.forms[0].elements[k].value;
					var o=b.split('/');
					if (o.length==2) {
						document.forms[0].elements[k].value=b + "/" +anno; 
						//alert(b);
					}else {
						var v=b.split('-');
						if (v.length==2) {
							document.forms[0].elements[k].value=b + "-" +anno; 
						}
					}
					if (!(isDate(document.forms[0].elements[k].value)) ) {
						VerificaNonPresenzaErrore(k,giaUnErrore,formOK,"(Inserire una Data corretta)");
					}
					break;
				case 'f':
				case 'f3':
					uu=document.forms[0].elements[k].value;
					if (!(isFloat(document.forms[0].elements[k].value))) {
						VerificaNonPresenzaErrore(k,giaUnErrore,formOK,"(Inserire un Numero)" + uu);
					}
					break;
			}
		}
		var passwd=document.forms[0].elements[k].value;
		if (TipoCampoForm[i]=="PASSWORD") {
			if (document.forms[0].elements[k].value!=document.forms[0].elements[k + "2"].value)
				VerificaNonPresenzaErrore(k,giaUnErrore,formOK,"(I due campi devono coincidere)");
			else 
				if (passwd.length<minlen[i])
					VerificaNonPresenzaErrore(k,giaUnErrore,formOK,"(Password con minimo " +  minlen[i] +")");
				
		}
	}
	if (giaUnErrore==1 && primoErrore==-1)
		primoErrore=k;
}
if (formOK[0]) {
	esatto=true;
	if(typeof VerificaAltriErrori == 'function') {
		esatto=VerificaAltriErrori();
	}
	if (esatto) {
		document.forms[0].continua.value=continua;
		document.forms[0].submit();
	}
	else
		return false;
}
else {
	document.forms[0].elements[primoErrore].focus();
	return false;
}
}


function isInteger(value) {
return (parseInt(value,10) == value)

}

function isFloat(value) {
a=value.split(",")

if (a.length>2)
   return false
if (a.length==1) {
	if (isInteger(a[0]))
		return true;		
	else
		return false;		
}
else {
	if ((isInteger(a[0])) && (isInteger(a[1])))
		return true
	else
		return false;	
}
}

function isDate(value) {	
var a=value.split('/');
if (a.length!=3)
{
a=value.split('-');
if (a.length!=3)
return false
}
giorno=Number(a[0]);
mese=Number(a[1]);
anno=Number(a[2]);

giusto=true;
if (!(isInteger(giorno)) || !(isInteger(mese)) || !(isInteger(anno)))
giusto= false;

if (mese<1 || mese >12)
giusto= false;
if ((giorno<1) || (giorno >31))
giusto= false;
if (((mese==4) || (mese==6) || (mese==9) || (mese==11)) && (giorno>30))
giusto= false;
if ((mese==2) && (giorno>29))
giusto= false;
if (((mese == 2) && (giorno == 29)) &&  (((anno % 4) !=0) || (((anno % 4)==0) &&  (((anno % 100)==0) && ((anno % 400)!=0)  ))))
// && (((anno % 4) !=0) || (((anno % 4)==0) && ((anno %  100)==0) ))
giusto= false;
if ((mese==0) && (giorno==0) && (anno==0))
giusto=true;
return giusto;
}

function AnnullaRendiconto(ID) {
if (confirm("Confermi annullamento invio rendiconto?")) {
	document.passaparametri.ope.value=1021;
	document.passaparametri.rendiconto.value=ID;
	document.passaparametri.submit();
}
}

function ConsentiInvio(IDutente,Msg) {
if (Msg=="Annulla")
	strMsg="Annullo l'autorizzazione?";
else
	strMsg="Confermi autorizzazione all'invio scavalcando i controlli?";
	
if (confirm(strMsg)) {
	document.passaparametri.ope.value=1025;
	document.passaparametri.rendiconto.value=IDutente;
	document.passaparametri.submit();
}
}

function EntraInModifica() {
k=document.passaparametri.maxrighe.value;
for (h=0;h<k;h++) {
	strClasse="mostra";
	var myElement = document.getElementById("area_" + h);
	myElement.setAttribute((document.all ? "className" : "class"),  strClasse);
	var myElement = document.getElementById("tit_" + h);
	myElement.setAttribute((document.all ? "className" : "class"),  "nascondi");
	var myElement = document.getElementById("mem_" + h);
	myElement.setAttribute((document.all ? "className" : "class"),  "nascondi");
	var myElement = document.getElementById("comb_" + h);
	myElement.setAttribute((document.all ? "className" : "class"),  "combo");
	var myElement = document.getElementById("salva");
	myElement.setAttribute((document.all ? "className" : "class"),  "button");
	var myElement = document.getElementById("modifica");
	myElement.setAttribute((document.all ? "className" : "class"),  "nascondi");
}
}

function CambiaVisualizzazione() {
var myElement = document.getElementById("vis_" + document.passaparametri.PPID.value);
document.passaparametri.PPvi.value=myElement.value;
var myElement = document.getElementById("nas_" + document.passaparametri.PPID.value);
document.passaparametri.PPna.value=myElement.value;
var myElement = document.getElementById("tot_" + document.passaparametri.PPID.value);
document.passaparametri.PPtt.value=myElement.value;
var myElement = document.getElementById("nre_" + document.passaparametri.PPID.value);
document.passaparametri.PPnr.value=myElement.value;
document.passaparametri.submit();
}

function ModificaOpzioni() {
document.passaparametri.ope.value=12;
document.passaparametri.IDopzione.value=document.passaparametri.PPID.value;
document.passaparametri.submit();
}

function CopiaCampo(nomecampo) {
if (trim(window.opener.document.passaparametri.FiltroDati.value)=="")
	window.opener.document.passaparametri.FiltroDati.value= nomecampo;
else
	window.opener.document.passaparametri.FiltroDati.value= window.opener.document.passaparametri.FiltroDati.value + " and " + nomecampo;
}

function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function AnnullaSQL() {
var myElement = document.getElementById("pulsanteSQL");
myElement.style.color="rgb(255,0,0)";
}

function CheckSQL(script) {
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Il tuo browser non supporta Ajax!");
  return;
} 
var url=script;
url=url+"?ope=102&filtro=" + document.passaparametri.FiltroDati.value + "&script=" + document.passaparametri.file.value;
xmlHttp.onreadystatechange= function(){
if (xmlHttp.readyState==4) {
	
	var risposta=new String(xmlHttp.responseText);
	if (risposta==1) {
		var myElement=document.getElementById("pulsanteSQL");
		myElement.style.color="rgb(0,255,0)";
		var myElement = document.getElementById("msgerr");
		while (myElement.firstChild) {
		myElement.removeChild(myElement.firstChild);
		}
		document.passaparametri.FiltroDati2.value=document.passaparametri.FiltroDati.value;
	}
	else {

		var myElement=document.getElementById("pulsanteSQL");
		myElement.style.color="rgb(255,0,0)";
		var myElement = document.getElementById("msgerr");
		while (myElement.firstChild) {
		myElement.removeChild(myElement.firstChild);
		}
		var testo =document.createTextNode(risposta)
		myElement.appendChild(testo);
	}
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function CreaFiltroDati() {
if (document.passaparametri.FiltroDati2.value!=document.passaparametri.FiltroDati.value && trim(document.passaparametri.FiltroDati.value)!="") {
	alert("Eseguire una verifica della correttezza del codice SQL tramite il pulsante TEST SQL!")
	var myElement=document.getElementById("pulsanteSQL");
	myElement.style.color="rgb(255,0,0)";
}
else {
	document.passaparametri.submit();
}
}


function getformvalues (fobj, valfunc){
  var str = "";
  aok = true;
  var val;
  //Run through a list of all objects contained within the form.
  for(var i = 0; i < fobj.elements.length; i++){
    if(valfunc) {
      if (aok == true){
        val = valfunc (fobj.elements[i].value,fobj.elements[i].name);
        if (val == false){
           aok = false;
        }
      }
    }
    str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
  }
  //Then return the string values.
  return str;
}

function CancelEventClick(i,CodCheck,FormName) {
	ChangeRowSelection(i,CodCheck,FormName)
}

function ChangeRowSelection(i,CodCheck,FormName) {
var a=document.getElementById("rig" + i);
var checkBoxName="";
checkBoxName=CodCheck;
checkBoxName=CodCheck +i;
x=document.forms[FormName].elements[checkBoxName].checked;
if (x) {

	colore="normal";
	document.forms[FormName].elements[checkBoxName].checked=false;
}
else {
	colore="selected";	
	document.forms[FormName].elements[checkBoxName].checked=true;
}
a.setAttribute((document.all ? "className" : "class"), colore);
}

function NascondiElemento(NomeCampo){
var myElement=document.getElementById("row_" + NomeCampo);
myElement.setAttribute((document.all ? "className" : "class"),"commentonascosto");
}

function MostraElemento(NomeCampo){
var myElement=document.getElementById("row_" + NomeCampo);
myElement.setAttribute((document.all ? "className" : "class"),"");
}


//solo per isnart


function NMA_gotopage(direction){
if (direction==0)
	document.FormImmisione.page2go.value=document.FormImmisione.ppage.value;
else
	document.FormImmisione.page2go.value=document.FormImmisione.npage.value;
}

