/*ver. 1.36
28/12/2011 aggiustato rilevazione firefox 9
30/06/2011 corretto closeHW
27/06/2011 aggiunto executeFunctionByName
03/06/2011 corretto openViewWindow
09/06/2010 identificazione ie7 ie8
27/04/2010 gestione webapp indipendente. gestione help
20/04/2010 aggiunto 	f.flgReport.value=""; su gestione salto pagina
09/02/2010 corretto helpW
27/01/2010 setCheckboxvalue... gestisce il caso in cui i checkbox non sono visibili
27-10-2009 aggiunto printPdf per stampe su window iframe
07-10-2009 buildSitemap
24-09-2009 spostato formatNumber e stringToNumber su numberInput.js. Gestione inpunt numerno con checkNumber(i, delKey,direction)
modificato main-menu.js con nuildSM
18-09-2009 inizio supporto google chrome
10-06-2009 gestione windows
20-04-2009 navContainerSmall e navContainerXSmall su hideTabs
18-03-2009 getValId
19-01-2009 aggiornato nextPageDetail, prevPageDatail, goPageDetail per finestre bean con tab vari
corretto e prevede la ricompilazione di tutte le adminSimple e adminSimpleEncType a causa del id mancante su pageNumber
goPageS() diventa obsoleto... da levare
02-12-2008 riaggirnato setRadioButtonValue che non funzionava
17-11-2008 aggiornato setRadioButtonValue e setChekBoxValue per firefox
09-11-2008 levato alert su formatNumber. aggiunto stringToNumber da script stan-accettazione
27-10-2008 aggiunto prendiElementoDaId (ajax)
16-10-2008 aggiunto  submitForm(evt) per gestione submit su tutti i form (firefox ok). corretto setFocus per i select
10-10-2008 modificato showTab per gestire i next focus su show tab. aggiunto setFocus
08-10-2008 aggiunto formatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
06-05-2008 ri-aggiunto openViewWindow (ciatti). Gestione TABS automatica. . aggiunte funzioni leftTrim, rightTrim e trim
02-04-2008 automatismi inserminento form: focusNext + Time du dateInput.js 
24-02-2008 clrField: adesso cancella n campi invece di 2
15-01-08 corretto flag!=null su setChekBoxValue e setRadioButtonValue
28/12/2007 aggiunto funzione setRadioButtonValue(formName,flgName) e setChekBoxValue(formName,flgName,ckValue,unckValue). Aggiornati script template
14/11/07 aggiornato anche getBrowserLang e redirectLang. Testato con firefox per le lingue adesso funziona davvero
09/11/07 modificato funzioni  goPage(l_pageNumber)  goPage() goPage2() nextPagformate() prevPage()
e' necessario creare due funzioni anche vuote 		checkRadioCR();		checkBoxesCR(); sullo script del tipo pkg-theBean.js
13/10/2006 inserito redirectLang() funzionante
10/10/2007 inserito getBrowserLang
12/09/07 gestito isNumKey in checkFields
01-08-07 inserito showVersion
*/
//webApp="/nomewebapp";
//var webApp="/miser";
var webApp=""
var locale="IT";

var loaded = 0;
var helpWin;
var helpWinW;
//**************** DETECT BROWSER **************************************************
//CS1.1

var exclude=1;
var agt=navigator.userAgent.toLowerCase();

var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;var ie7=0;var ie8=0;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;; var chro=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(typeof navigator.vendor!="undefined" && navigator.vendor.indexOf('Google')!=-1){
	chro=1;
}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(/opera[\/ ][5]/.test(agt)){op5=1;}
	if(/opera[\/ ][6]/.test(agt)){op6=1;}
	if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		if(agt.indexOf("msie 7")!=-1){
			ie7=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		if(agt.indexOf("msie 8")!=-1){
			ie8=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	else if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}


//alert("ns44 "+ns4 +" ie5 "+ie5+" mozz "+mz7+" chro "+chro+" ie6"+ie6+" ie7"+ie7+" ie8"+ie8);
//********************************************************
//********************************************************


//********************************************************
//********************************************************
//  S   T   A   R   T  
//********************************************************
//********************************************************
//********************************************************
var ggWinSW;
function startApp() {

	windowWidth="800";
	windowHeigth="600";
	windowTitle="Time_Report";
	startPage="menu/Menu.abl";
	ggWinSW = window.open(startPage, windowTitle,"width="+windowWidth+",height="+windowHeigth+",status=yes,resizable=yes,top=0,left=0,scrollbars=yes");
	//debug
	//ggWinSW = window.open();

	ggWinSW.opener = self;
	//window.close();
}

//********************************************************
//********************************************************
//  P  R  I  N  T    
//********************************************************
//********************************************************
//********************************************************
function printW()
{
	window.print();
	return true;

}
//////////////////////////////////////////////////////////
/// controlli salvataggi e cancellazione//////////////////

/////////////////////////////////////////////////////////
function confirmDelete()
{
	return confirm("I dati saranno cancellati. Vuoi continuare?")
	

}
/////////////////////////////////////////////////////
// gestione preve e next nelle liste con paginazione
/////////////////////////////////////////////////////
  
//caso maschere di ricerca
function prevPage()
{
	
	var f = document.ricerca;
	//richiamo anche un metodo che carica i checkBox e i checkRadio
	checkRadioCR();
	checkBoxesCR();

	f.action=f.actionPage.value;
	f.cmd.value="search";
    f.flgReport.value="";
	f.pageNumber.value=f.pageNumber.value-1;
	f.target="" ;
	
	f.submit();
}

function nextPage()
{	
	var f = document.ricerca;
	//richiamo anche un metodo che carica i checkBox e i checkRadio
	checkRadioCR();
	checkBoxesCR();
	f.action=f.actionPage.value;
	f.cmd.value="search";
	f.flgReport.value="";
	f.pageNumber.value=eval(f.pageNumber.value)+1;
	f.target="" ;
	
	//alert(f.pageNumber.value);
	f.submit();
}

function goPage(l_pageNumber)
{aler('verificare quando viene chiamata!!!');
 		//richiamo anche un metodo che carica i checkBox e i checkRadio
		checkRadioCR();
		checkBoxesCR();
        var f = document.ricerca;
        f.action=f.actionPage.value;
        f.cmd.value="search";
	    f.flgReport.value="";
        f.pageNumber.value=l_pageNumber;
        f.target="" ;

        f.submit();
}

function goPage()
{
		//richiamo anche un metodo che carica i checkBox e i checkRadio
		checkRadioCR();
		checkBoxesCR();

        goPageMod(document.ricerca);
}

function goPage2()
{
		//richiamo anche un metodo che carica i checkBox e i checkRadio
		checkRadioCR();
		checkBoxesCR();
        goPageMod2(document.ricerca);
}

function goPageS()
{alert('obsoleto');
        //per le pagine di tipo simple
        goPageMod(document.dettaglio);
}

function goPageMod(f)
{
        //var f = document.ricerca;
        if(parseFloat(f.pageNumberGo.value)<= parseFloat(f.totPageNumber.value))
        {
                f.action=f.actionPage.value;
                f.cmd.value="search";
                f.pageNumber.value=f.pageNumberGo.value;
                f.target="" ;

                f.submit();
        }
        else
        alert('Errore!!');

}
function goPageMod2(f)
{
        //var f = document.ricerca;
        if(parseFloat(f.pageNumberGo2.value)<= parseFloat(f.totPageNumber.value))
        {
                f.action=f.actionPage.value;
                f.cmd.value="search";
                f.pageNumber.value=f.pageNumberGo2.value;
                f.target="" ;

                f.submit();
        }
        else
        alert('Errore!!');
}


//caso finestre secondarie di ricerca

function prevPageSW()
{
	
	var f = document.ricerca;
	f.act.value="sw";
	prevPage();
}

function nextPageSW()
{

	
	var f = document.ricerca;
	f.act.value="sw";
	nextPage();
}
function goPageSW(l_pageNumber)
{
	
	var f = document.ricerca;
	f.action=f.actionPage.value;
	f.act.value="sw";
	goPage(l_pageNumber);
}

//caso maschere di dettaglio per liste secondarie
function prevPageDetail(searchType)
{
	var f = document.dettaglio;
	f.action=f.actionPage.value;
	f.cmd.value="md";
	f.act.value=searchType;
	var pn;
	if(typeof searchType=="undefined"){
		pn= prendiElementoDaId("pageNumber");}	
	else
		pn= prendiElementoDaId("pageNumber_"+searchType);
	pn.value=eval(pn.value)-1;
	f.submit();
}

function nextPageDetail(searchType)
{
	var f = document.dettaglio;
	f.action=f.actionPage.value;
	f.cmd.value="md";
	f.act.value=searchType;
	var pn;
	if(typeof searchType=="undefined"){
		pn= prendiElementoDaId("pageNumber");}	
	else
		pn= prendiElementoDaId("pageNumber_"+searchType);
	pn.value=eval(pn.value)+1;
	f.submit();
}

function goPageDetail(searchType)
{
	var f = document.dettaglio;
	f.action=f.actionPage.value;
	f.cmd.value="md";
	if(typeof searchType=="undefined"){
		var pn= prendiElementoDaId("pageNumber");
		var pnN=prendiElementoDaId("pageNumberGo");
		var totPage=prendiElementoDaId("totPageNumber");
	}
	else
	{
		var pn= prendiElementoDaId("pageNumber_"+searchType);
		var pnN=prendiElementoDaId("pageNumberGo_"+searchType);
		var totPage=prendiElementoDaId("totPageNumber_"+searchType);
	}
	if(parseFloat(pnN.value)<= parseFloat(totPage.value))
	{	pn.value=pnN.value;
		f.submit();
	}
	else
	{
        alert('Errore!!');
	}

}
//////////////////////////////////////////////////////////
/// gestione layers ///////////////////7//////////////////
/////////////////////////////////////////////////////////
function bkgMenu(menuName,color) {
      if (ns4 || mz7 || chro) {
 	     	screenWidth = window.innerWidth;
 		document.layers[menuName].background = color;
      } else {
		screenWidth = document.body.clientWidth;
      		document.all[menuName].style.background = color;
  
    }

}
///////////////////////////////////////////////
///////////////////////////////////////////////
function popUp(menuName,left,top) {
///////////////////////////////////////////////
///////////////////////////////////////////////
toleft =typeof left;
totop =typeof top;
      if (ns4==1) {
      screenWidth = window.innerWidth;
      if (left!=0 && toleft  != "undefined")
      {
      //	document.layers[menuName].left = left;
      }
      if(top!=0 && totop != "undefined")
      {
       //document.layers[menuName].top = top;
      }
 

     // alert(document.layers[menuName].visibility );
      document.layers[menuName].visibility = "show";
      //alert(document.layers[menuName].visibility );

      } else {
      screenWidth = document.body.clientWidth;
      if(left!=0 && toleft  != "undefined")
      {//alert('l='+left);
       document.getElementById(menuName).style.pixelLeft = left;
      }

      if(top!=0 && totop != "undefined")
      {//alert('pio2');
       document.getElementById(menuName).style.pixelTop = top;
      }
	
      document.getElementById(menuName).style.visibility = "visible";

 
    }
	//registrazione di current tab
	//  if ((ct=findObj('currentTab'))!=null)
   	 // {
	  //		ct.value=menuName;
			//alert(menuName);
	//  }
	
	
}
      
function popDown(menuName) 
{
	if (ns4 ) {
		document.layers[menuName].visibility = "hide";
	} else {
		//alert("down"+document.getElementById(menuName).style.visibility);
		document.getElementById(menuName).style.visibility = "hidden";
	}
}

function motionListener(){

      if (ns4 || mz7 || chro) {

	      window.addEventListener(Event.MOUSEMOVE,grabXY,true);
      	//window.onmousemove = grabXY;
	} else {
		// document.attachEvent(Event.MOUSEMOVE, modifyText);
		document.onmousemove = grabXY;
	}
}

function motionListenerOld(){

      if (ns4 || mz7 || chro) {
	      window.captureEvents(Event.MOUSEMOVE);
      	window.onmousemove = grabXY;
	} else {
	document.onmousemove = grabXY;
	}
}

function grabXY(ev){
 
     if (ns4 || mz7 || chro) {
	coordx=ev.pageX;
      	coordy=ev.pageY
	} else {
	coordx=event.clientX;
      	coordy=event.clientY;
	}
}
      
function openWin(URL){
        aWindow=window.open(URL,"listwindow", "resizable=yes,scrollbars=yes,status=0,width=200,height=100");
}

function newWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	//alert (mypage+" "+myname+" "+ winprops);
	win = window.open(mypage, myname, winprops);
	
if (parseInt(navigator.appVersion) >= 4) 
	{ 
		win.window.focus();
	}
}


motionListener();

/////////////////////////////////////////7
/////////////////////////////////////////7
function leftCenter(menuName)
/////////////////////////////////////////7
/////////////////////////////////////////7
{
left=0;

if (ns4 || mz7 || chro) {
 
      screenWidth = window.innerWidth;
	//alert('ns mnuname'+menuName);
      layerWidth=parseInt(document.layers[menuName].clip.width);

	//alert('dopowidth');
    
      } else {
	
      screenWidth = document.body.clientWidth;
	layerWidth=parseInt(document.getElementById(menuName).style.width);
    }

//	alert('lw='+layerWidth);
//	alert(screenWidth);

//	alert('left='+left);
      left=(screenWidth -layerWidth)/2;
      if (left<=0)
      {
      	//alert('left;'+left);
      	left=1;
      }
	return left;


}

//////////////////////////////////////////////////////////
/// swap image ///////////////////////////////////////////
/////////////////////////////////////////////////////////
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;
	//alert('loading:'+a[i]);
        d.MM_p[j++].src=a[i];
      }
  }
}

function swapImgRestore() 
{ //v3.0
  var i,x,a=document.sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
  x.src=x.oSrc;
}



function swapImage() 
{ //v3.0
  var i,j=0,x,a=swapImage.arguments;
  document.sr=new Array;
  for(i=0;i<(a.length-2);i+=3)
	{
	   if ((x=findObj(a[i]))!=null)
   		{
		  
			 document.sr[j++]=x;
			 if(!x.oSrc)
			   x.oSrc=x.src;
			 x.src=a[i+2];
	   }
	}
}


//motionListener();

//////////////////////////////////////////////////////////
/// valida form //////////////////////////////////////////
/////////////////////////////////////////////////////////

function findObj(n, d) 
{ //v3.0

  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=findObj(n,d.layers[i].document); 
  return x;
}
function validateForm2() { //v3.0
	//R per required
	//isNum per numerico
	//isNumKey è una chiave.. uguale a isNum>0 ma cambio il messaggio
	//isNum>x per numerico maggiore di x
	//isNum<x per numerico minore di x
	//isEmail per indirizzo email
	//inRange1:10 per ..
	//3 stringhe
	//1: nome del field
	//2: se '' visualizza il nome del field, altrimenti questo campo
	//3: R/N+''/isNum/isEmail/inRangea:b
//
//esempi
//	validateForm2('nomeform,'textfield','','R','textfield2','','NisNum','textfield3','','NisEmail','textfield4','','RinRange2:10')
//
  var i,p,q,nm,nf,desc,test,testN,num,min,max,errors='',args=validateForm2.arguments;
  nf=args[0];
  //alert('forms'+nf);
  for (i=1; i<(args.length-2); i+=3) 
  { 
  		test=args[i+2]; 
		//val=findObj(args[i]);
		val=document[nf][args[i]];
		
		if(args[i+1]=="")
			desc=val.name;
		else
			desc=args[i+1];
			
    	if (val) { nm=val.name; if ((val=val.value)!="") 
		{
      		if (test.indexOf('isEmail')!=-1) 
			{ 
				p=val.indexOf('@');
        		if (p<1 || p==(val.length-1)) errors+='- '+desc+' non è un indirizzo valido.\n';
      		} 
			else if (test!='R') 
			{ 
				//alert(val);
				if(locale=="IT")
				{
					
					val=val.replace(/[.]/,'');
					val=val.replace(/[.]/,'');
					val=val.replace(/[.]/,'');
					val=val.replace(/[.]/,'');
					val=val.replace(',','.');
					//tolgo gli zeri finali
					var dotIdx=val.indexOf('.');
					//alert("dotidx0"+dotIdx);
					if(dotIdx!=-1)
					{
						var j=val.length-1;
					/*	while(val.charAt(i)!='.' && val.charAt(i)=='0' ) NON FUNZIONA.. forse perche' usavo i invece di j!!*/
						while(val.charAt(j)!='.' )
						{
						//alert("j="+j+" val charat(j):"+val.charAt(j));
							if(val.charAt(j)=='0')
							{
								val=val.substr(0,j);
								j--;
							}
							else j=dotIdx;
						}
						if(val.charAt(val.length-1)=='.')
							val=val.substr(0,val.length-1);
					}
				}
				else if(locale=="US" || locale=="UK")
				{
					val=val.replace(/[,]/,'');
					val=val.replace(/[,]/,'');
					val=val.replace(/[,]/,'');
					val=val.replace(/[,]/,'');
					val=val.replace('.',',');
					//tolgo gli zeri finali
					var dotIdx=val.indexOf(',');
					if(dotIdx!=-1){
						var j=val.length-1;
						while(val.charAt(j)!=',')
						{
							if(val.charAt(j)=='0')
							{
								val=val.substr(0,j);
								j--;
							}
							else
							 j=dotIdx;
						}
						if(val.charAt(val.length-1)==',')
							val=val.substr(0,val.length-1);
					}					
					//alert("US:"+val);
				}
				
			
				//da correggere il caso 33,40 Non mi accetta lo 0 finale!!!'

				num = parseFloat(val);
				//alert('num:'+num);
				
        //		if (val!=''+num && val!=''+num +'0'&& val!=''+num +'00'&& val!=''+num +'000' ) errors+='- '+desc+' non è numerico.\n';
				if (val!=''+num) errors+='- '+desc+' non è numerico.\n';
				if(test.search(/[><]/) != -1 )
				{
					if (test.charAt(0) == 'R')
					{
						testN=test.substring(7,test.length);
					}
					else
					{
						testN=test.substring(6,test.length);
					}
					//alert('test:'+test+' tn: '+testN+" num: "+num +" pftn: "+parseFloat(testN));
					if(test.indexOf('>') !=-1 && num <= parseFloat(testN)) errors+='- '+desc+' è <= '+testN+'.\n';
					if(test.indexOf('<') !=-1 && num >= parseFloat(testN)) errors+='- '+desc+' è >= '+testN+'.\n';
					
				}
				//alert('test:'+test+' tn: '+testN);
				if (test.indexOf('isNumKey') != -1)
				{
					if(num <= 0) errors+='- '+desc+' è obbligatorio.\n';
				}
        		if (test.indexOf('inRange') != -1) 
				{ 
					p=test.indexOf(':');
          			min=test.substring(8,p); 
					max=test.substring(p+1);
          			if (num<min || max<num) errors+='- '+desc+' deve essere un numero tra '+min+' e '+max+'.\n';
    			} 
			} 
		} 
		else if (test.charAt(0) == 'R') errors += '- '+desc+' è obbligatorio.\n'; }
  } 
  if (errors) alert('Il form contiene i seguenti errori:\n'+errors);
  return (errors == '');
  

}


function validateForm() { //v3.0 23/07/2002
	//R per required
	//isNum per numerico
	//isNumKey è una chiave.. uguale a isNum>0 ma cambio il messaggio
	//isNum>x per numerico maggiore di x
	//isNum<x per numerico minore di x
	//isEmail per indirizzo email
	//inRange1:10 per ..
	//3 stringhe
	//1: nome del field
	//2: se '' visualizza il nome del field, altrimenti questo campo
	//3: R/N+''/isNum/isEmail/inRangea:b
//
//esempi
//	validateForm('textfield','','R','textfield2','','NisNum','textfield3','','NisEmail','textfield4','','RinRange2:10')
//
  var i,p,q,nm,desc,test,testN,num,min,max,errors='',args=validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  { 
  		test=args[i+2]; 
		val=findObj(args[i]);
		if(args[i+1]=="")
			desc=val.name;
		else
			desc=args[i+1];
			
    	if (val) { nm=val.name; if ((val=val.value)!="") 
		{
      		if (test.indexOf('isEmail')!=-1) 
			{ 
				p=val.indexOf('@');
        		if (p<1 || p==(val.length-1)) errors+='- '+desc+' non è un indirizzo valido.\n';
      		} 
			else if (test!='R') 
			{ 
				//alert(val);
				if(locale=="IT")
				{
					
					val=val.replace(/[.]/,'');
					val=val.replace(/[.]/,'');
					val=val.replace(/[.]/,'');
					val=val.replace(/[.]/,'');
					val=val.replace(',','.');
					//tolgo gli zeri finali
					var dotIdx=val.indexOf('.');
					//alert("dotidx0"+dotIdx);
					if(dotIdx!=-1)
					{
						var j=val.length-1;
					/*	while(val.charAt(i)!='.' && val.charAt(i)=='0' ) NON FUNZIONA.. forse perche' usavo i invece di j!!*/
						while(val.charAt(j)!='.' )
						{
						//alert("j="+j+" val charat(j):"+val.charAt(j));
							if(val.charAt(j)=='0')
							{
								val=val.substr(0,j);
								j--;
							}
							else j=dotIdx;
						}
						if(val.charAt(val.length-1)=='.')
							val=val.substr(0,val.length-1);
					}
				}
				else if(locale=="US" || locale=="UK")
				{
					val=val.replace(/[,]/,'');
					val=val.replace(/[,]/,'');
					val=val.replace(/[,]/,'');
					val=val.replace(/[,]/,'');
					val=val.replace('.',',');
					//tolgo gli zeri finali
					var dotIdx=val.indexOf(',');
					if(dotIdx!=-1){
						var j=val.length-1;
						while(val.charAt(j)!=',')
						{
							if(val.charAt(j)=='0')
							{
								val=val.substr(0,j);
								j--;
							}
							else
							 j=dotIdx;
						}
						if(val.charAt(val.length-1)==',')
							val=val.substr(0,val.length-1);
					}					
					//alert("US:"+val);
				}
				
			
				//da correggere il caso 33,40 Non mi accetta lo 0 finale!!!'

				num = parseFloat(val);
				//alert('num:'+num);
				
        //		if (val!=''+num && val!=''+num +'0'&& val!=''+num +'00'&& val!=''+num +'000' ) errors+='- '+desc+' non è numerico.\n';
				if (val!=''+num) errors+='- '+desc+' non è numerico.\n';
				if(test.search(/[><]/) != -1 )
				{
					if (test.charAt(0) == 'R')
					{
						testN=test.substring(7,test.length);
					}
					else
					{
						testN=test.substring(6,test.length);
					}
					//alert('test:'+test+' tn: '+testN+" num: "+num +" pftn: "+parseFloat(testN));
					if(test.indexOf('>') !=-1 && num <= parseFloat(testN)) errors+='- '+desc+' è <= '+testN+'.\n';
					if(test.indexOf('<') !=-1 && num >= parseFloat(testN)) errors+='- '+desc+' è >= '+testN+'.\n';
				}
        		if (test.indexOf('isNumKey') != -1)
				{
					if(num <= 0) errors+='- '+desc+' è obbligatorio.\n';
				}
        		if (test.indexOf('inRange') != -1) 
				{ 
					p=test.indexOf(':');
          			min=test.substring(8,p); 
					max=test.substring(p+1);
          			if (num<min || max<num) errors+='- '+desc+' deve essere un numero tra '+min+' e '+max+'.\n';
    			} 
			} 
		} 
		else if (test.charAt(0) == 'R') errors += '- '+desc+' è obbligatorio.\n'; }
  } 
  if (errors) alert('Il form contiene i seguenti errori:\n'+errors);
  return (errors == '');
  
}
//ckAll per combobox
function checkAll(f,ckAll)
   {
      for (var i=0;i<f.elements.length;i++)
      {
         var e = f.elements[i];
         if (e.name != ckAll)
            e.checked = f[ckAll].checked;
      }
   }

//funzioni di menu   
function callSvlt(theSvlt)
{	var f = document.menu;
	if (theSvlt.charAt(0)=="/")
	{	//path assoluto
		theSvlt=webApp+theSvlt;
	}
	f.action=theSvlt+".Svlt";
	f.cmd.value="search";
	f.submit();
}

function callAbl(theSvlt,theFrame,theCmd,theAct)
{
	
	
	var f = document.menu;
	//default
	var cmd="search";
	var act="";
	if(theCmd!=null)
		cmd=theCmd;
	if(theAct!=null)
		act=theAct;
	if (theSvlt.charAt(0)=="/")
	{//path assoluto
		theSvlt=webApp+theSvlt;
	}
	if(theFrame==null || !theFrame )
	{
		f.action=theSvlt+".abl";
		f.cmd.value=cmd;
		f.act.value=act;
		f.submit();
	}
	else
	{
		//preparo il location
		var loc=theSvlt+".abl";
		if(cmd!="" || act != "")
			loc=loc+"?";
		if(cmd!="")
			loc=loc+"cmd="+cmd;
		if(act!="")
			loc=loc+"&act="+act;
			//alert('loc='+loc);
		if(ns4 || mz7 || chro)
		{
			window.parent.frames[1].location.href=loc;
		}
		else
		{
			var theBody=document.parentWindow.top.frames[theFrame];
			//alert(theSvlt+".abl");
			theBody.location.href=loc;
		}
	}
}

 function closeWindow()
{
	if(confirm("Vuoi chiudere la finestra? (il record NON sarà aggiornato)"))
	window.close();
}

function getVal(field)
{
	
	var val=findObj(field);
	if (val)
		val=val.value;
	else
		val="";
	return val;
}
//change language
function lang(code)
{
	var hrf=location.href;
	//alert (hrf);
	var f = document.menu;
	f.action="Lang.abl";
	f.hrf.value=hrf;
	f.lang.value=code;
	f.submit();
}

function clrField()
{
	var args=clrField.arguments;
	var f = document[args[0]];
	for (i=1; i<(args.length); i++)
	{
		f[args[i]].value="";
	
	}
}
function showVersion(theId)
{
if (document.getElementById) {
  var theIdStyle = document.getElementById(theId).style;
  if (theIdStyle.display == "block") {
   theIdStyle.display = "none";
   } else {
   theIdStyle.display = "block";
  } 
  return false;
  } else {
  return true;
 }	
	
}

// SCELTA AUTOMATICA LINGUA DEL BROWSER

function getBrowserLang(){
var lang;
	if(typeof navigator.userLanguage != "undefined"){
		lang=navigator.userLanguage.toLowerCase();
	}
	else if(typeof navigator.language != "undefined"){
		lang=navigator.language.toLowerCase();
	}
		else{ 
		lang=locale.toLowerCase;
	}
	if(lang.length>2)
		lang=lang.substring(0,2);
	return lang;

}
/*
funzione per fare il redirect della stessa pagina ma con la lingua del browser.
Subito dopo function.js iserire
<form name="langForm"><input name="hrf" type="hidden" /><input name="lang" type="hidden" value="<%=lang%>" /></form><script language="JavaScript1.2" >if(document.langForm.lang.value=="")redirectLang();</script> 
*/
function redirectLang()
{
	code=getBrowserLang();
	var hrf=location.href;
	//alert (hrf);
	var f = document.langForm;
	f.action="Lang.abl";
	f.hrf.value=hrf;
	//devo verificare il parametro lang....
	//se non sepcificato scelgo inglese
	//alert("redlang "+code);
	//##############################
	// QUESTA PARTE POTREBBE VARIARE A SECONDA DELLE LINGUE SUPPORTATE DAL SITO
	//##################################################
	if(code=="" || code =="it" || code =="en")
		f.lang.value=code;
	else 	
		f.lang.value="en";
	
	f.submit();
	
}
function setRadioButtonValue(formName,flgName)
{
	//imposta un campo hidden di none flgName al valore del radio button 'rb'+flgname selezionato
	//es: setRadioButtonValue("dettaglio","flgPlaAntPos");
	//var f = document.form[formName];
	var f = document.getElementById(formName);
	var flag=document.getElementById(flgName);
	if(flag!=null)
	{
		var radioGrp=f['rb'+flgName];
		//var radioGrp=document.getElementById('rb'+flgName);
		
		flag.value="";
		for (var i = 0; i< radioGrp.length; i++) 
		{
			if (radioGrp[i].checked) {
				flag.value=radioGrp[i].value;
				break;
			}
		}
	}
}

function setChekBoxValue(formName,flgName,ckValue,unckValue)
{
	//imposta un campo hidden di none flgName al valore del ckValue se checked, unckValue se unchecked
	//es: setChekBoxValue("dettaglio","flgSommaCRL","1","0");
	//var f = document.form[formName];
	var f = document.getElementById(formName);
	//alert('flgName: '+flgName);
	var flag=document.getElementById(flgName);
	if(flag!=null)
	{
		//var ckbox=f['ck'+flgName];
		var ckbox=document.getElementById('ck'+flgName);
		if(ckbox!=null){
			if (ckbox.checked)flag.value=ckValue;else flag.value=unckValue;
		}
	}
	
}


function openViewWindow() {
	// usare openViewWindow(comando, larghezza, altezza);
    windowWidth=500;
    windowHeigth=200;
	searchSvlt = arguments[0];
	//campo di ritorno completo
	
	//larghezza finestra di ricerca
	if (arguments[1]!=null)
	{
		windowWidth=arguments[1];
	}
	//altezza finestra di ricerca
	if (arguments[2]!=null)
	{
		windowHeigth=arguments[2];
	}
	if (searchSvlt.charAt(0)=="/")
	{//path assoluto
		searchSvlt=webApp+searchSvlt;
	}
	if(searchSvlt.indexOf("?")>0)
			swcmd="&cmd=view";
		else
			swcmd="?cmd=view";
	if(debug==false)
	{
		
						  
		ggWinView = window.open(searchSvlt+swcmd, "View_Window","width="+windowWidth+",height="+windowHeigth+",status=no,resizable=yes,top=100,left=100,scrollbars=yes");
	}
	else
	{
		ggWinView = window.open(searchSvlt+swcmd); 
	}
	
	ggWinView.opener = self;
	
	
	
}

/////////////////////////////////////////////////
// GESTIONE FORM INSERIMENTO PER AUTOMATISMI
//
// UTILIZZARE SU CAMPI
// onFocus="this.select();" onKeyDown="focusNextOnCr(event,'XXXXX');" onKeyUp="return focusNext(this,event,'XXXX',NN);" 
// SE ICLUSO ANCHE dateInput.js
// PER I CAMPI DATA
////  onFocus="this.select();" onChange="checkDate(this);printDate(this,'giorno')" onKeyDown="if(event.keyCode==13) {focusNextOnCr(event,'XXXXX');} else {formatDate(this, window.event.keyCode,'down')}" onKeyUp="formatDate(this, window.event.keyCode,'up');focusNext(this,event,'XXXX',10);"
// PER I CAMPI TIME
// onFocus="this.select();" onChange="" onKeyDown="if(event.keyCode==13) {focusNextOnCr(event,'XXXX');} else {formatTime(this, window.event.keyCode,'down')}" onKeyUp="formatTime(this, window.event.keyCode,'up');focusNext(this,event,'XXX',5);"
/////////////////////////////////////////////////
function focusNextOnCr(e,nextField)
{
	//utlilizzare
	//onKeyDown="focusNextOnCr(event,nextField);" 
	var keyCode = e.keyCode; 
	if(keyCode==13) {
	//elemento successivo
	//input.form[(getIndex(input)+1) % input.form.length].focus();
	//preprocess
		document.getElementById(nextField).focus()
	}
}

function focusNext(input,e,nextField,len)
{
	//utilizzare onKeyUp="return focusNext(this,event,'field',nn);
	//var keyCode = (isNN) ? e.which : e.keyCode; 
	// var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  
	var keyCode = e.keyCode; 
	var filter = [0,8,9,16,17,18,37,38,39,40,46];
  	var f = document.dettaglio;
	//if(event.keyCode==13) {document.getElementById('codiceTS').focus();
 	if(keyCode!=13 && input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		//elemento successivo
		//input.form[(getIndex(input)+1) % input.form.length].focus();
		document.getElementById(nextField).focus()
  	}

	  function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	  }
	
	  function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	  }
	return true;
}

/****************************************************/
/************* NUOVE FUNZIONI PER TAB ***************/
/****************************************************/
//10-10-2008 levato tabgroup e messo nextFocus (non lo usavo in show tab)

function showTab(tabName,nextFocus) {
	  if (ns4==1) {
		 // alert(document.layers[menuName].visibility );
		  document.layers[tabName].display = "block";
		 

      } else {
     	
		//PRIMA NASCONDO TUTTI I TAB
		hideTabs(tabName);
		var theIdStyle = document.getElementById(tabName).style;
      	theIdStyle.display = "block"; 

 
    }
	//registrazione di current tab
	  if ((ct=findObj('currentTab'))!=null)
   	  {
	  		ct.value=tabName;
			//alert(menuName);
	  }
	  //next focus
	  	toNextFocus =typeof nextFocus;
		if(toNextFocus  != "undefined")
		{
			setFocus(nextFocus);
		}
	
	
}

function popDownTab(tabName,tabGroup) {
	toTabGroup =typeof tabGroup;
	if(toTabGroup  != "undefined")
		tg=tabGroup;
	else
		tg="TABS";
      if (ns4==1) {
		 // alert(document.layers[menuName].visibility );
		  document.layers[tabName].display = "none";
		  //alert(document.layers[menuName].visibility );

      } else {
     	
		var theIdStyle = document.getElementById(tabName).style;
      	theIdStyle.display = "none";
    }
}

function hideTabs(tabName)
{
//da fare gestione campio stile navtabs
	/*var theTabs=document.getElementById('tabNav').getElementsByTagName('li');
	var currentTab=tabName+"_li";

	 for(i=0;i<theTabs.length;i++)
	{
			
		if(theTabs[i].id==currentTab)
		{alert(theTabs[i].id);
			var liTag=document.getElementById(theTabs[i].id);
			alert(liTag.style.getPropertyValue('background'));
			//liTag.class="current"
			//theTabs[i].class="current";	
			//theTabs[i].getElementsByTagName('a')[0].class="active";
		}
		else
		{
			//document.getElementById(theTabs[i].id).style=" background: blu;"
			//theTabs[i].class="";	
			//theTabs[i].getElementsByTagName('a')[0].class="";

		}

	
	}*/
	

	var theTabs=document.getElementById('TABS').getElementsByTagName('div');
	 for(i=0;i<theTabs.length;i++)
	 {
		 if(theTabs[i].id!='tabNav' && theTabs[i].id!='navContainer' 
	&& theTabs[i].id!='navContainerSmall'&& theTabs[i].id!='navContainerXSmall' && theTabs[i].id!="")
		 popDownTab(theTabs[i].id);
		 
	 }
}


/****** funzioni trim stringa ****/
function leftTrim(stringa) 
{
	while (stringa.substring(0,1) == ' ')
	{
		stringa = stringa.substring(1, stringa.length);
	}
	return stringa;
}


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


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 setFocus(theField)
{
	document.getElementById(theField).focus();
	if(document.getElementById(theField).type!='select-one')
		document.getElementById(theField).select();
}

//gestione submit per form dettaglio e ricerca
function submitForm(evt)
{
	if (ns4 || mz7 || chro)
	{
		theForm=evt.target.form.name;
	}
	else
	{
		theForm=evt.srcElement.form.name;
		
	}
	if(theForm=="dettaglio")
	{
		//dettaglio
		saveCommand();	
	}
	else if(theForm=="ricerca")
	{
		//ricerca
		searching();
	}
}

// funzione per prendere un elemento con id univoco
function prendiElementoDaId(id_elemento) {
	var elemento;
	if(document.getElementById)
		elemento = document.getElementById(id_elemento);
	else
		elemento = document.all[id_elemento];
	return elemento;
}

function getValId(id_elemento){
	
	return 	prendiElementoDaId(id_elemento).value;
}

function help(cod)
{	
	if(cod==null){
		cod=getValId("actionPage");
		cod=cod.substring(0,cod.length-4);
	}
	//theAction=webApp+"/admin/help/v/H.abl?cmd=view&cod="+cod;
	theMainHelpPage=webApp+"/admin/help/v/index.jsp?cod="+cod;
	//debug
	//helpWin=window.open(theMainHelpPage); 
	//NO DEBUG
	helpWin=window.open(theMainHelpPage, "HELP","width=1020,height=700,status=yes,resizable=yes,top=0,left=0,scrollbars=yes");
	//helpWin=dhtmlwindow.open('helpBox', 'ajax', 'external.htm', 'Help - '+id, 'width=650px,height=400px,left=300px,top=100px,resize=0,scrolling=1'); 

	
}

function helpW(titolo, pagina, ww, hh )
{	
	//help del bean definito da actionPage
	//alert(tableName);
	helpWinW=dhtmlwindow.open('helpBox', 'ajax', pagina, 'Help - '+titolo, 'width='+ww+'px,height='+hh+'px,left=300px,top=100px,resize=1,scrolling=1'); 
}
function closeHW()
{
	if(typeof(helpWinW)!= "undefined")
		helpWinW.close();
	else 
	{
		
		window.close();
	}
	
}
function modalW(titolo, pagina, ww, hh )
{
		var w=500, h=400;
		if(ww!=null)
			w=ww;
		if(hh!=null)
			h=hh;
        //help del bean definito da actionPage
        //alert(tableName);
        modalWin=dhtmlwindow.open('modalW', 'ajax', pagina, titolo, 'width='+w+'px,height='+h+'px,left=300px,top=100px,resize=1,scrolling=1');
}
function closeMW()
{
        modalWin.close();
}

function buildSitemap()
{
	
	if(confirm("Vuoi creare la sitemap?"))
		{
			var f = document.ricerca;
			f.action=f.actionPage.value;
			f.fileName.value=prompt("Inserisci nome file (vuoto per nome file default)",f.fileName.value);
			//alert('pio_'+f.eMail.value);
			if(f.fileName.value!='null')
			{
				//popUp("ELAB");
				f.cmd.value="buildSM";
				f.submit();
			}
		}
	
}
function printPdf(titolo, pagina, ww, hh )
{
	var w=500, h=400;
	if(ww!=null)
		w=ww;
	if(hh!=null)
		h=hh;
	dhtmlwindow.open('Pdf print', 'iframe', pagina, ' '+titolo, 'width='+w+'px,height='+h+'px,left=300px,top=100px,resize=1,scrolling=1'); 
}


function executeFunctionByName(functionName, context /*, args */) {
  var args = Array.prototype.slice.call(arguments).splice(2);
  var namespaces = functionName.split(".");
  var func = namespaces.pop();
  for(var i = 0; i < namespaces.length; i++) {
    context = context[namespaces[i]];
  }
  return context[func].apply(this, args);
}

