// script language="javascript">

//alert("entraJS");

var PGUSER="";      //nome dello user - utile per menu veloce personale.
var PGNOME="";      //nome appl.PG - utile per menu veloce personale.
var PRG_nome="";    //nome del programma attivo.
var PRG_tipo="";    //tipo del programma attivo.

var inicmp="";      //campo del form a ricevere il focus.
var iniform="";     //form.
var iniid="";       //ID del campo (alternativo a inicmp), utile per campi tabellari !
var finestra="";    //finestra da rendere visble . vedi setfocus

var	aa2cifre=30;	// da PARAMETRI   document.entryform.aa2cifre.value;
var logged_in=""; //indica se l'utente č loggato o meno! S/N
var menu_tendina=""; //indica se si deve usare il menu a tendina S/N
var menu_veloce=""; //indica se si deve usare il menu veloce S/N

var wwwroot=""; //č la root dell'applicativo

var browname=navigator.appName;
var browvers=navigator.appVersion;

// trap F1 for IE browser and stop default behaviour
// DISATTIVA L'HELP SUL TASTO F1
document.onhelp = function (){
 event.cancelBubble = true; event.returnValue = false;
}
//document.onbeforeupdate = function (){alert("cazzzzz!");
// event.cancelBubble = true; event.returnValue = false;
//}

// Funzioni da lanciare su onload BODY.
function right(e) {     //TASTO DESTRO MOUSE !
if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
		(event.button == 2 || event.button == 3)) {
		//alert("Spiacenti, il tasto destro del mouse e' disabilitato");
		//menuV();
		var t=window.event.srcElement;
		var v=t.innerHTML;tname=t.name;
		alert(tname+v+t.Item);
		return false;
		}
return true;
}
// Eseguito sull'evento onload della čagina html
function basejs(){	
//if (PRG_tipo=="G")    //LEGGE CAMPI NELLA MASCHERA CHIAMANTE !!!
//	 {alert(self.opener.document.all("PRG_tipo").value);}
setfocus();
if(logged_in=="S"&&menu_tendina=="S"){crmenu();}//{if(PRG_tipo=="P")crmenu();} //non lanciare su programmi Help
//alert(document.getElementById['browname'].value)=browname;
if(PGUSER=="SWadmin"){
	if(browname != 'Microsoft Internet Explorer') {alert(browname);}
}
xxx();//lancia uno script. Se il programma non ce l'ha, parte lo script sottodefinito !
}

function xxx(){	}   //se non c'č nel programma, parte questo !
function foco(){
//alert(PRG_nome+":"+inicmp);
}
function setfocus() {	//if (inicmp){alert(PRG_nome+":"+inicmp);}
//if(PRG_nome=="ord3"){window.parent.frames.Ord3.frameElement.style.visibility='visible';}
if(finestra){eval(finestra);finestra="";}
//alert("setfocus"+iniform+inicmp);
if (inicmp){eval("document.forms['"+iniform+"']."+inicmp+".focus()");
	if(eval("document.forms['"+iniform+"']."+inicmp+".tagName")!="SELECT")
			{eval("document.forms['"+iniform+"']."+inicmp+".select()");}}
//alert("cmp"+inicmp+"id"+iniid);
if (iniid) {eval("document.getElementById['"+iniid+"'].focus()");}
}

// Crea una window MODALE per menł veloce.
function menuV(){
	if(PRG_nome=="ord1"||PRG_nome=="ord2"||PRG_nome=="carrello"||PRG_nome=="dettaglio"
	 ||PRG_nome=="ord4"||PRG_nome=="artic1")
	    {return;}
p=0;if(PGUSER=="SWadmin")p=9;if(PGUSER=="CeramWEB")p=5;if(PGUSER=="CeramMAG")p=4;
y1=wwwroot+"menuv.php?wwwroot="+wwwroot+"&p="+p;yy=new Array(PGUSER,PGNOME);
x1=window.showModalDialog(y1,yy,"dialogWidth:300px;dialogHeight:500px;dialogLeft:500px;dialogTop:100px");
if(x1)window.document.location.href=x1;//alert(x1);
}

// Controlla il tasto premuto.
var shiftON=0;  //per intercettare
var ctrlON=0;   // ctrl+shift
var cmpdt,cmpora;	// settato per controllo tab su data e ora
function bodykeydown() {    bodykeydownX();	
var k=window.event.keyCode;
var t=window.event.srcElement.name;
//var v=window.event.srcElement.value;
//F1=112->F12=123, pgup=33-dw=34,home=36,end=35, fSX=37,UP=38,DX=39,DW=40
//shift=16, ctrl=17,alt=18, tab=9
if(k==112){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==113){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==114){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==115){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==116){//alert("Funz"+(k-111)+window.event.name);vprop(window.event,"");
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==117){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==118){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==119){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==120){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==121){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==122){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}
if(k==123){//alert("Funz"+(k-111));
	window.event.cancelBubble=true;window.event.returnValue=false;}

//if (k==9&&t==cmpdt){ EditData(t); }

// per controllo partenza menu' veloce !
if(logged_in=="S"&&menu_veloce=="S"&&PGUSER=="SWadmin"){
	if (k==16){if(ctrlON>0){shiftON=ctrlON=0;menuV();} else shiftON+=1;}
	if (k==17){if(shiftON>0){shiftON=ctrlON=0;menuV();} else ctrlON+=1;}
}

if (k==116){ //F5   esegue alert e poi aggiornamento !
	window.event.cancelBubble=true;window.event.returnValue=false;//alert("F5555555");
}
if (k==120&&t=='idPaz'){ //F9
	window.event.cancelBubble=true;window.event.returnValue=false;xhelp();}
if (k==33&&(document.all['gtb_pgup'])){ //PG Up
	window.event.cancelBubble=true;window.event.returnValue=false;
	document.all['gtb_pgup'].click();}  //suscita l'evento  !
if (k==34&&(document.all['gtb_pgdw'])){ //PG Dw
	window.event.cancelBubble=true;window.event.returnValue=false;
	document.all['gtb_pgdw'].click();}  //suscita l'evento  !
if (k==36&&(document.all['gtb_top'])){ //Home
	window.event.cancelBubble=true;window.event.returnValue=false;
	document.all['gtb_top'].click();}    //suscita l'evento  !
if (k==35&&(document.all['gtb_end'])){ //End
	window.event.cancelBubble=true;window.event.returnValue=false;
	document.all['gtb_end'].click();}    //suscita l'evento  !
}
function bodykeydownX(){
// solo per non far andare in errore, in caso non esista nel programma.
}
function bodykeyup() {
var k=window.event.keyCode;
var t=window.event.srcElement.name;
if (k==16){shiftON=0;}
if (k==17){ctrlON=0;}
}

// evento KEYPRESS
function bodykey() {   bodykeyX();
var k=window.event.keyCode;
var t=window.event.srcElement.name;
var v=window.event.srcElement.value;
var tag=window.event.srcElement.type;
if (PRG_tipo=="G"||PRG_tipo=="P"||PRG_tipo=="H"){
	if (k==13&&tag=="textarea") {return;}}
if (PRG_tipo=="G"||PRG_tipo=="P"||PRG_tipo=="H"){
  if (document.all['invio'])
	if (document.all['invio'][0]){tinvio=document.all['invio'][0];}else
	                             {tinvio=document.all['invio'];}
  if (document.all['esci'])
	if (document.all['esci'][0]){tesci=document.all['esci'][0];}else
	                            {tesci=document.all['esci'];}
}
if (PRG_tipo=="G"){ //programmma di Gestione: Anagrafica etc.
	if (k==13&&(t=="searchtxt"||t=="search")){
		window.event.cancelBubble=true;window.event.returnValue=false;
		document.all['search'].click();}	//suscita l'evento submit di "cerca" !
	if (k==13&&(document.all['invio'])) {
		window.event.cancelBubble=true;window.event.returnValue=false; 
		tinvio.click();}    //suscita l'evento submit di "invio" !
	else if (k==27&&(document.all['esci'])) {
		window.event.cancelBubble=true;window.event.returnValue=false; 
		if(document.all['mode'].value=="visua")window.close();
		else //if(document.all['livx'].value>0){
		//document.all['livx'].value=document.all['livx'].value-2;tinvio.click();}else
			tesci.click();}    //suscita l'evento submit di "esci" !
}
if (PRG_tipo=="H"){ //programma di help per scelta codice
	if (k==13&&(t=="searchtxt"||t=="search")){
		window.event.cancelBubble=true;window.event.returnValue=false;
		document.all['search'].click();}	//suscita l'evento submit di "cerca" !
	else if (k==13&&(document.all['invio'])){
		window.event.cancelBubble=true;window.event.returnValue=false;
		tinvio.click();}    //suscita l'evento submit di "invio" !
	else if (k==27&&(document.all['esci'])) {//se esiste tasto Esc
			window.close();} //chiude la finestra !
}
if (PRG_tipo=="P"){ //programma Partenza, elenco
	if (k==13&&(t=="searchtxt"||t=="search")){
		window.event.cancelBubble=true;window.event.returnValue=false;
		document.all['search'].click();}	//suscita l'evento submit di "cerca" !
	else if(k==13&&(document.all['invio'])){
		window.event.cancelBubble=true;window.event.returnValue=false;
		tinvio.click();}	//suscita l'evento submit di "invio" !
	else if (k==27&&(document.all['esci'])) {
		window.event.cancelBubble=true;window.event.returnValue=false;
		tesci.click();}		//suscita l'evento submit di "esci" !
}
}
function bodykeyX(){
// solo per non far andare in errore, in caso non esista nel programma.
}

function bodyclick(){  bodyclickX();	//alert("bodyclick");
if(logged_in=="S"&&menu_tendina=="S"){delx();}  //disattiva menu se attivo.
var t=window.event.srcElement;
var v=t.value;tname=t.name;
}
function bodyclickX(){
// solo per non far andare in errore, in caso non esista nel programma.
}

function bodyblur(){   bodyblurX();  //alert("BLUR");
var t=window.event.srcElement;
var v=t.value;	tname=t.name;
window.status="";   //Ripulisce la barra di stato
if(tname==cmpdt){ EditData(tname); }   //se lascia campo data, deve editare
if(tname==cmpora){ EditOra(tname); }   //se lascia campo  ora, deve editare
bodyblurY();
}
function bodyblurX(){
// solo per evitare l'errore, in caso non esista nel programma.
}
function bodyblurY(){
// solo per evitare l'errore, in caso non esista nel programma.
}

// Su evento KEYPRESS impostato sul campo per il controllo digitazione.
// TP=Tipo del campo - DG= Tipo digitazione del campo
function tipodgt(DG,TP){
    var key=window.event.keyCode;	//alert(key);
    if (key==13||key==27)return;    //se invio-esc lascia la gestione ai contenitori.
	var t=window.event.srcElement;
	var v=t.value;tname=t.name;
	var c="",d="",e="";
 	if(key>=97&&key<=122)c="a";//Alfab.minusc.
	if(key>=65&&key<=90) c="A";//Alfab.maiusc.
	if(key>=48&&key<=57) c="n";//Numerico
	if(key==44||key==46) c="v";//Virgola/punto
	if(key==32)c="b";//Blank
	if(key==47)c="/";//Barra
	if(key==45||key==43)c="-";//Segno +-
	if(key==46||key==39)e="A";//punto-apice
	if(key==44||key==46||key==39||key==43||key==45||key==40||key==41||key==32||key==47)
		 d="B";//Virgola-punto-apice-pił-meno-apri(-chiudi)-blank-barra
 	switch (DG){//M=Maiuscolo - m=Minuscolo - 1=Capitalizzata
		case("M"):if (c=="a"){window.event.keyCode = key-0x20;c="A"}break;
		case("m"):if (c=="A"){window.event.keyCode = key+0x20;c="a"}break;
		case("1"):
		    if (v==""&&c=="a"){window.event.keyCode = key-0x20;}
		    if (v!=""&&c=="A"){window.event.keyCode = key+0x20;}
			break;
	}//endswitch
	//alert(key+c+d+e+TP);
    switch (TP){//A=Alfabetico - X=Alfanumerico - N=Numerico - D=Data
		case ("A"):if (!(c=="a"||c=="A"||c=="b")){window.event.keyCode = 0;}break;
		case ("L"):if (!(c=="a"||c=="A"||c=="b"||e=="A")){window.event.keyCode = 0;}break;
		case ("B"):if (!(c=="a"||c=="A"||c=="n"||d=="B")){window.event.keyCode = 0;}break;
		case ("X"):if (!(c=="a"||c=="A"||c=="n"||c=="b")){window.event.keyCode = 0;}break;
		case ("C"):if (!(c=="n"||c=="b")){window.event.keyCode = 0;}break;
		case ("T"):break;
		case ("N"):
			if (key==46){window.event.keyCode=44;break;}// cambia il punto in virgola
			if (!(c=="n"||c=="v"||c=="-")){window.event.keyCode = 0;break;}
			break;
		case ("D"):
		    cmpdt=tname;    //imposta il campo per il controllo data sul tab.
			if (key==45){window.event.keyCode=47;break;}// cambia il trattino in barra
			if (!(c=="n"||c=="/"||c=="-")){window.event.keyCode = 0;}
			break;
		case ("H"):
		    cmpora=tname;    //imposta il campo per il controllo ora sul tab.
		    //alert(key);   alert(v+"__"+tname);
			//if(v==":"){t.value=OraOdierna();}
			//r = document.selection.createRange();alert(r.length);
			//t.select();x=t.createRange();alert(x.length);
			if (key==44||key==45||key==46){window.event.keyCode=58;break;}// cambia ,.- in :
			if (!(c=="n"||key==58)){window.event.keyCode = 0;}
			break;
		case ("F"):
		  if(v.length>0){
			for(i=0;i<v.length;i++){c1=v.substr(i,1);cx="";
			    if((c1>="a" && c1<="z")||(c1>="A" && c1<="Z"))cx="A";
			    if(c1>=0 && c1<=9)cx="n";
			    if(cx==""){alert("Carattere non previsto in C.F.");
			    			window.event.keyCode = 0;}
			}
		  }
		  break;
	}//endswitch
	if(window.event.keyCode == 0){
		//z=t.createTextRange();z.text="gfgf";z.select();z=null;        FUNZIONA !!
		//z=t.createTextRange();nn=z.move("character",2);z.select();    FUNZIONA !!
		alert("Carattere non previsto ");return;}
	//alert(v); il campo non č ancora aggiiornato.
}
function EditData(campo){   //trovare funz.JS per numberformat !
	el=document.all(campo);
	dt=el.value;if(dt=="/"){dt=DataOdierna();}
	Adt=dt.split('/');
	// accetta data in formato ggmmaa oppure ggmmaaaa
	if(Adt.length==1&&(dt.length==6||dt.length==8)){
		Adt[0]=dt.substr(0,2);Adt[1]=dt.substr(2,2);Adt[2]=dt.substr(4);
		}
	if(Adt.length!=3)return;
	if(Adt[2].length<=2){
		vx=Adt[2];vv=parseInt(vx,10);//if(vx!==vv){alert("PARSEiNT NON FUNZIONA !!!"+vx+"-"+vv);}
		if(vv<aa2cifre){vv+=2000;}else{vv+=1900;}
		Adt[2]=vv;}
	if(Adt[0].length==1){Adt[0]="0"+Adt[0];} //porta anno a 2 cifre
	if(Adt[1].length==1){Adt[1]="0"+Adt[1];} //porta mese a 2 cifre
	el.value=Adt.join('/');
}
function DataOdierna(){    //imposta con data corrente.
  var d,s;
  d = new Date();
  s  = d.getDate() + "/";
  s += (d.getMonth() + 1) + "/";
  s += d.getYear();
  return(s);
}
function EditOra(campo){   //trovare funz.JS per numberformat !
	el=document.all(campo);
	dt=el.value;
	if(dt==""||dt.length==0)return;
	if(dt==":"){dt=OraOdierna();}
	Adt=dt.split(':');  //alert(Adt.length);
	if(Adt.length==0||Adt.length>2)return;
	if(Adt.length==1&&Adt[0].length==4){//alert(Adt[0].substr(2,2));
		Adt[1]=Adt[0].substr(2,2);Adt[0]=Adt[0].substr(0,2);
		//alert(Adt[0]);alert(Adt[1]);
		}
	if(Adt[0].length==0){Adt[0]="00";} //se manca ma c'č il :
	if(Adt[0].length==1){Adt[0]="0"+Adt[0];} //porta ore    a 2 cifre
	if(Adt.length==1)Adt[1]="00";
	if(Adt[1].length==0){Adt[1]="00";} //se manca ma c'č il :
	if(Adt[1].length==1){Adt[1]="0"+Adt[1];} //porta minuti a 2 cifre
	if(Adt[0]>23){alert("Ora errata !");el.focus();return;}
	if(Adt[1]>59){alert("minuti errato !");el.focus();return;}
	el.value=Adt.join(':');
}
function OraOdierna(){    //imposta con ora corrente.
  var d,s;
  d = new Date();
  s  = d.getHours() + ":";
  s += d.getMinutes();
  return(s);
}

//---------------------------------------------------- HELP --------------------
//chiamata dall'help sul campo, organizza il psg param.
//cmpL=campo dell'help  hlp=stringa parametri dell'help
function chiamaHelp(cmpL,hlp){
cmplink=cmpL; 
par=hlp.split("|"); //suddivide i parametri di help
Q="";posiz="";
for(i=0;i<par.length;i++){
	z=par[i].split("=");if(z.length!=2)alert("parametri help errati !");
	if(z[1].charAt(0)=="%"){ //se il valore del campo inizia con % deve passare il nome del campo
		x1=z[0]+"_cmp";x2=z[1].substr(1);
		z[1]=document.all(z[1].substr(1)).value;
		if(Q.length>0)Q+="&";
		Q+=x1+"="+x2+"&"+z[0]+"="+z[1];continue;
		}
	if(z[1].charAt(0)=="&"){//se il valore del campo inizia con & lo deve prendere dalla mask
		z[1]=document.all(z[1].substr(1)).value;}
	if(z[0]=="prg")prg=z[1];
	else if(z[0]=="posiz")posiz=z[1];else
		{if(Q.length>0)Q+="&";
		 Q+=z[0]+"="+z[1];}
}	//alert(Q);
	newwin(prg+".php",Q,posiz);
}

// Crea una Window non modale 
	var newWin3=null;
	var cmplink="";//Campo collegamento x ritorno da help !
	var avlW=window.screen.availWidth;  //per calcolo
	var avlH=window.screen.availHeight; //in percentuale
function newwin(URL,Q,P) {
T='20';L='450';W='343';H='400'; //Valori posizionamento default.
TOOL="not";MEN="0";STA="yes";SCROLL="yes";	//Valori parametri default.
RES="yes";  //Window residente !
if(P!=""){posiz=P.split(",");T=posiz[0];L=posiz[1];W=posiz[2];H=posiz[3];
nn=posiz.length;	
if(nn>4){PP=posiz[4];if(PP=="RES")RES="not";if(PP=="SCROLL")SCROLL="not";
	if(PP=="TOOL")TOOL="yes";if(PP=="MEN")MEN="1";if(PP=="STA")STA="not";}
if(nn>5){PP=posiz[5];if(PP=="RES")RES="not";if(PP=="SCROLL")SCROLL="not";
	if(PP=="TOOL")TOOL="yes";if(PP=="MEN")MEN="1";if(PP=="STA")STA="not";}
if(nn>6){PP=posiz[6];if(PP=="RES")RES="not";if(PP=="SCROLL")SCROLL="not";
	if(PP=="TOOL")TOOL="yes";if(PP=="MEN")MEN="1";if(PP=="STA")STA="not";}
if(nn>7){PP=posiz[7];if(PP=="RES")RES="not";if(PP=="SCROLL")SCROLL="not";
	if(PP=="TOOL")TOOL="yes";if(PP=="MEN")MEN="1";if(PP=="STA")STA="not";}
if(nn>8){PP=posiz[8];if(PP=="RES")RES="not";if(PP=="SCROLL")SCROLL="not";
	if(PP=="TOOL")TOOL="yes";if(PP=="MEN")MEN="1";if(PP=="STA")STA="not";}
}
if(T.search(/%/)!=-1){T=T.replace(/%/,"");T=avlH*(T/100);}//alert("Top="+T);}
if(L.search(/%/)!=-1){L=L.replace(/%/,"");L=avlW*(L/100);}//alert("Left="+L);}
if(W.search(/%/)!=-1){W=W.replace(/%/,"");W=avlW*(W/100);}//alert("Width="+W);}
if(H.search(/%/)!=-1){H=H.replace(/%/,"");H=avlH*(H/100);}//alert("Height="+H);}

var params='top='+T+',left='+L+',width='+W+',height='+H+',minimized=not,resizable=yes,scrollbars='+SCROLL+',toolbar='+TOOL+',menubar='+MEN+',status='+STA+'';

// se c'č una window ma č stata chiusa:
if (newWin3&&newWin3.closed) {newWin3=null;}

if (Q=="")Q2=""; else Q2="?"+Q;
if(RES=="not"){window.open(URL+"?"+Q,"",params);return;}

//if (newWin3) {alert("base"+newWin3.PRG_tipo);}    //indica che č attivo e il tipoprg!
//se la newwin č attiva, verifica se in INSerimento o MODifica !
if (newWin3&&(newWin3.PRG_tipo=="G")) {	
	if(newWin3.document.all("mode").value=="modif"){
		alert("ATTENZIONE: sei in modifica!");newWin3.focus();return;}
	if(newWin3.document.all("mode").value=="nuovo"){
		alert("ATTENZIONE: sei in inserimento!");newWin3.focus();return;}
	newWin3.close();newWin3=null;}
if (newWin3) {newWin3.close();newWin3=null;}
if (Q=="")Q2=""; else Q2="?"+Q;
if (!newWin3 || newWin3.closed) {newWin3=window.open(URL+Q2,"",params);}
}
//seleziona il codice, lo riporta nel form chiamante,
//e chiude questa maschera di HELP !
function doContact(inv) {
	valo=document.all("selz").value;    
	re=/'/g;    //per convertire tutti gli apici
	valo=valo.replace(re,"\\'");
	pann=document.all("pann").value;
	riga=document.all("riga").value;
	inv=document.all("inv").value;

	if((window.event.type=="keypress"&&window.event.keyCode==27)||valo=="")
		{self.window.close();return;}

	if(document.all("nselz").value>0){
		x="self.opener.execScript('tbbackM(\""+valo+"\",\""+pann+"\",\""+riga+"\",\""+inv+"\")')";
		eval(x);}
	else{
		x="self.opener.execScript('tbback(\""+valo+"\",\""+pann+"\",\""+riga+"\",\""+inv+"\")')";
		eval(x);}

    self.window.close();
}

// script di programma chiamante, eseguito da newwin3 - elabora v1(valore scelto!)
// se proviene da scelta multipla viene eseguito tbbackM che, essendo specifico, deve
// essere presente nel programma chiamante.
function tbback(v1,pann,riga,inv) {
arv1=v1.split("£");
x="document.all['"+cmplink+"'].value=arv1[0]";eval(x);//aggiorna campo chiamante
x="document.all['"+cmplink+"'].focus()"; eval(x);
if(inv==1){
  if(document.all['invio'])
	if(document.all['invio'][0]){tinvio=document.all['invio'][0];}else
	                            {tinvio=document.all['invio'];}
	tinvio.click();}
}
//eseguito da prgH con scelta multipla. elabora array v1(valori scelti!)  //#ANG (no tbback)
function tbbackM(v1,pann,riga,inv) {
//toglie prefisso e suffisso (pann,riga)
//cx=cmplink.substr(2);//cx=cmplink;cx=cx.substr(0,cx.length-1);
arlink0=v1.split("|");

//utilizzare cmplink per capire di quale help si tratta
for (i=0;i<arlink0.length;i++){
	arlink1=arlink0[i].split("£");
	//se č pannello
	//x="document.all['"+cx+riga+"'].value=arlink1[0]";eval(x);
	//x="document.all['Dstariffario"+riga+"'].value=arlink1[1]";eval(x);
	//x="document.all['Impprivato"+riga+"'].value=arlink1[2]";eval(x);
	//x="document.all['Impssn"+riga+"'].value=arlink1[3]";eval(x);
	//x="document.all['prsFlprestazconvenz"+riga+"'].value=arlink1[4]";eval(x);
	//if(document.all("prsQtarichiesti"+riga).value==""){
		//document.all("prsQtarichiesti"+riga).value=DfQtarichiesti;}
	//checcalo('prsFlprestazconvenz'+riga);
	riga++;
}
if(inv==1){
  if(document.all['invio'])
	if(document.all['invio'][0]){tinvio=document.all['invio'][0];}else
	                            {tinvio=document.all['invio'];}
	tinvio.click();}
}

// Se esce dal programma: verifica che non sia attivo l'help !!!
// Innescato da evento onunload su body.
function esceprg(){
if(newWin3&&newWin3.closed) {newWin3=null;}
if(newWin3)newWin3.close();
}


//onbeforeunload
//anche se si preme aggiorna o si avanza pagina !!!!!!!
function clos(){
	return; // disattiva clos
	//var t=window.event.srcElement;var v=t.value;tname=t.name;	alert(tname+v);
if(newWin3&&newWin3.closed) {newWin3=null;}
if(PRG_tipo=="P"){
	if(!newWin3){return;}
	agg=newWin3.document.all("mode").value;
	if(agg=="modif"||agg=="nuovo"){
		window.event.returnValue="ATTENZIONE: se esci puoi perdere gli aggiornamenti !";
	}
}
if(submit_eseguito){return;}    //solo se X o F5 !
if(PRG_tipo=="G"&&!submit_eseguito){
	if(document.all("mode").value=="modif"){
	window.event.returnValue="ATTENZIONE: sei in modifica!";return;}
	if(document.all("mode").value=="nuovo"){
	window.event.returnValue="ATTENZIONE: sei in inserimento!";return;}
}
if(newWin3){
	window.event.returnValue="ATTENZIONE: se esci puoi perdere gli aggiornamenti !";
}
}//endfunction


function DisableSubmit(tasto,form) {
	campo=tasto.name;
	campov=tasto.value;
	nomeform=form.name;
    var input = document.createElement('INPUT');
        input.type = "hidden";
        input.name = campo;
        input.value = campov;
	form.appendChild(input);
	for (var i=0; i < form.elements.length; i++)
	    if (form.elements[i].type.toLowerCase()=='submit')
	        form.elements[i].disabled=true;
	form.submit();
}

var submit_eseguito=0   //serve per non rieseguire un submit
function submitto(){
//var t=window.event.srcElement;  //trattasi del form !

if (submit_eseguito){
	window.event.cancelBubble=true;window.event.returnValue=false;//annulla l'evento !
	return;
}
ok1=submittoX();    //da al programma la possibilitą di intercettare il submit
if(ok1==1){
	if(!confirm("Posso procedere ?")){
		window.event.cancelBubble=true;window.event.returnValue=false;//annulla l'evento !
		return;
	}
}
submit_eseguito=1;
// disabilitazione buttons
// non viene lanciato quando viene premuto un button.
// non sempre il click di un button deve disabilitare tutto, se di un submit SI !
for(i=0; i<document.all.length; i++) {
    xp=document.all(i);
	if(!xp.type)continue;
	xpp=xp.type.toLowerCase();
	if(xpp=="button"){xp.disabled=true;}
}
return;
}
function submittoX(){   //per evitare l'errore se non esistesse nel programma.
}

// chiede conferma alla prosecuzione di un evento !
function vedi_confirm(D){ if(D=="")D="Posso procedere ?";
	if(!confirm(D)){
		window.event.cancelBubble=true;window.event.returnValue=false;//annulla l'evento !
		return 0;
	}
return 1;
}
//Converte numero in stringa numerica formattata !
function ConvNumber(){
//					    dec  inD  outD sep
// ConvNumber(InNumber, "2", ".", ",", ".")
var InNumber="";	//  Stringa da convertire
var dec=2;			//	numero di decimali di output
var inD=".";		//	separatore decimale di input
var outD=",";		//	separatore decimale di output
var sep=".";		//	separatore delle migliaie  ="n" se non ci deve essere
for (icn=0; icn<arguments.length; icn++){
	if(icn==0){InNumber=arguments[icn];}
	if(icn==1){dec=arguments[icn];}
	if(icn==2){inD=arguments[icn];}
	if(icn==3){outD=arguments[icn];}
	if(icn==4){sep=arguments[icn];}
}
Number=new Array();     //  Array dei risultati
//  Calcola Number.db che conterrą InNumber in formato db (xxxxxxx.xx)
cStr=new String (InNumber);
cStr=cStr.replace(inD,"^");
cStr=cStr.replace(",","");
cStr=cStr.replace(".","");
cStr=cStr.replace("^",".");
cStr=parseFloat(cStr);if(isNaN(cStr)){cStr=0;}
Number.db=cStr.toFixed(dec);

//  Calcola Number.edit che conterrą InNumber in formato editato (xxx.xxx,xx)
nStr=Number.db;
nStr += '';
var dpos = nStr.indexOf(".");
var nStrEnd = '';
if (dpos != -1) {
	nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
	nStr = nStr.substring(0, dpos);
}
if(sep!="n"){
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(nStr)) {
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
}
Number.edit=nStr + nStrEnd;
//  Calcola Number.editSp che conterrą InNumber = Spaces se uguale a zero
Number.editSp=Number.edit;
if(Number.db==0){Number.editSp="";}
return Number;
}//fine ConvNumber
// visualizza le proprietą di un oggetto, eventualmente che iniziano con ...
function vprop(li,vl){
	var result = "";
	for (var i in li) {    //elenca tutte le propritą dell'oggetto
		if(i.indexOf(vl)==0){result +=  i + " = " + li[i] + " \t ";}  //se inizia con vl
	}
	alert(result);
}
//SCRIPT>

//==============================================================================
//  cmpName=nome del campo che necessita del suggerimento
//  cmpValue=valore utile al suggerimento
//  tpTool=tipo del suggerimento T-->restituisce Tutti i valori possibili
//                               U-->restituisce il valore solo se Univoco
//  suggprg=programma destinato al suggerimento
//==============================================================================
var xmlHttp;
function shoToolTip(cmpName,cmpValue,tpTool,suggprg,cmpName2) {
	var k=window.event.keyCode;	//alert(k);
//	if(k==8||k==37||k==39||k==46){return 0;}    //backsp fsx  fdx    canc
	if(k==37||k==39){return 0;}    //backsp fsx  fdx    canc

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {return;}  //alert ("Browser does not support HTTP Request");
	var url=suggprg;
    url=url+"?cmpValue="+cmpValue+"&tpTool="+tpTool+"&cmpName="+cmpName+"&cmpName2="+cmpName2;
    xmlHttp.onreadystatechange= function() {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
        	doFuncxmlHttp(cmpName,tpTool);
    	}
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function doFuncxmlHttp(cmpName,tpTool) {
	campo=xmlHttp.responseText.split('|');
	nrElementi=campo[0];strHTML=campo[1];
	cmpName2=campo[2];cmpValo2=campo[3];
    if(tpTool=="T"){
    	ToolTip.Show(nrElementi,strHTML,cmpName);
    }
    if(tpTool=="U"&&nrElementi=="1"){
    	document.all[cmpName].value=strHTML;
		if(cmpName2!=""){document.all(cmpName2).value=cmpValo2;}
	}
}

function GetXmlHttpObject() {
    var xmlHttp=null;
    try{
        xmlHttp=new XMLHttpRequest();
    }catch (e){
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

//==============================================================================
var ToolTip=function(){
	var isInit = -1;
	var div,divWidth,divHeight;
	var html;
 return{

	Init:function(){
 		if(div==null){
			div = document.createElement('div');
			document.body.appendChild(div);
			div.setAttribute("id", "divXtooltip")
			div.style.font='12px Arial';
			//div.style.fontWeight = 'bold';
			div.style.opacity = 0.75;
			div.style.filter = 'alpha(opacity=85)';
			div.style.backgroundColor='ivory';
			div.style.border='solid 1 gray';
			div.style.width=100;
			div.style.height=20;
		}

		if((div.style.width=="" || div.style.height=="")){
			alert("Both width and height must be set");return;
		}
		divWidth = parseInt(div.style.width);
		divHeight= parseInt(div.style.height);
		if(div.style.overflow!="hidden")div.style.overflow="hidden";
		if(div.style.display!="none")div.style.display="none";
		if(div.style.position!="absolute")div.style.position="absolute";
 		isInit++;
	},

	Show:function(nrElementi,strHTML,cmpName){
		if(div==null){ToolTip.Init();}
		if(isInit<0) return;

		var newPosx,newPosy,height,width;
		if(typeof( document.documentElement.clientWidth ) == 'number' ){
			width = document.body.clientWidth+50;
			height = document.body.clientHeight;
		}else{
			width = parseInt(window.innerWidth+50);
			height = parseInt(window.innerHeight);
		}

		elemWidth=document.all(cmpName).clientWidth+50;
		elemHeight=document.all(cmpName).clientHeight;
		div.style.width=elemWidth+3;
		div.style.height=(elemHeight*nrElementi);
		p=getPageCoords(document.all(cmpName));
		var curPosx =p.x;   			//var curPosx =document.all(cmpName).offsetLeft;
		var curPosy=p.y+elemHeight+3;   //var curPosy=document.all(cmpName).offsetTop;

    	if(strHTML!=null){
			html = strHTML;
			div.innerHTML=html;
		}

    	if((curPosx+divWidth)< width){
    		newPosx= curPosx;
    	}else{
			newPosx = curPosx-divWidth;
		}

    	if((curPosy+divHeight)< height){
    		newPosy= curPosy;
    	}else{
    		newPosy = curPosy-divHeight-10;
		}

		if(window.pageYOffset){
			newPosy= newPosy+ window.pageYOffset;
			newPosx = newPosx + window.pageXOffset;
	 	}else{
			newPosy= newPosy+ document.body.scrollTop;
			newPosx = newPosx + document.body.scrollLeft;
		}

    	div.style.display='block';
    	//alert(document.body.scrollTop);   //debugger;
    	div.style.top= newPosy + "px";
    	div.style.left= newPosx+ "px";

    },//end Show

	Hide:function(){
   		div.style.display='none';
	}

  };

}();//fine ToolTip

function remToolTip() {
	if(document.activeElement.id!='divXtooltip'){ToolTip.Hide();}
}

function aggSuggest(campoValo,cmpName,cmpValo2,cmpName2) {
	campoValo1=campoValo.replace(/\xA0/g," ");
	if(cmpName2!=""){document.all(cmpName2).value=cmpValo2;}
	document.all(cmpName).focus();
	document.all(cmpName).value=campoValo1;
	remToolTip();
}

//==============================================================================
function getPageCoords (element) {
	var coords = {x: 0, y: 0};
	while (element) {
		coords.x += element.offsetLeft-element.scrollLeft;
		coords.y += element.offsetTop-element.scrollTop;
		element = element.offsetParent;
	}
	return coords;
}

//==============================================================================
function jaddslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function jstripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}



