//ver. 16/09/2002

var webApp="";
var locale="IT";

var loaded = 0;
var NS4=0;
var IE4=0;
var brow=0;
var browser=navigator.appName;
//window.toolbar=false;

//alert('Browser:'+navigator.appName);

NS4=(browser=='Netscape')?1:0;
IE4=(browser.search(/microsoft/i)!=-1)?2:0;

//NS4 = (document.layers) ? 1 : 0;
//IE4 = (document.all) ? 1 : 0;

ver4 = (NS4 || IE4) ? 1 : 0;
NS4==1?brow=2:brow=1;

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

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

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

}

function commandChooser(theForm)
{

//question();
//alert(theForm.id_fornitore.value);
	//alert(theForm.NEW.value);
return false;
	alert(theForm.NEW);
	if (NS4) 
	{
		if (theForm.NEW.x!=0 || theForm.NEW.y!=0)
		{
			return newCommand();
		}
      	} 
      	else 
      	{
		return true;
	}
		

}


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


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


function question(msg,titolo)
{
	msgWin = window.open("", titolo, 
		"width=250,height=250,status=no,resizable=no,top=200,left=200");
	

	msgWin.document.open();

	// Setup the page...
	msgWin.document.writeln("<html>");
	msgWin.document.writeln("<head><title>Calendar</title>");
	msgWin.document.writeln("</head>");

	msgWin.document.writeln("<body> " );
	msgWin.document.writeln("<b>msg</B>" );
	
	msgWin.document.writeln("</body> " );
	msgWin.document.writeln("</html>");
	
}

 /////////////////////////////////////////////////////
  // gestione preve e next nelle liste con paginazione
  /////////////////////////////////////////////////////
  
//caso maschere di ricerca
function prevPage()
{
	//FACCIO IL SUBMIT
	var f = document.ricerca;
	f.action=f.actionPage.value;
	f.cmd.value="search";
	f.pageNumber.value=f.pageNumber.value-1;
	f.submit();
}

function nextPage()
{//alert('pio');
	//FACCIO IL SUBMIT
	var f = document.ricerca;
	f.action=f.actionPage.value;
	f.cmd.value="search";
	f.pageNumber.value=eval(f.pageNumber.value)+1;
	//alert(f.pageNumber.value);
	f.submit();
}
function goPage(l_pageNumber)
{//alert('pio');
	//FACCIO IL SUBMIT
	var f = document.ricerca;
	f.action=f.actionPage.value;
	f.cmd.value="search";
	f.pageNumber.value=l_pageNumber;
	f.submit();
}

//caso finestre secondarie di ricerca

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

function nextPageSW()
{//alert('pio');
	//FACCIO IL SUBMIT
	var f = document.ricerca;
	f.act.value="sw";
	nextPage();
}
function goPageSW(l_pageNumber)
{//alert('pio');
	//FACCIO IL SUBMIT
	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)
{
	//FACCIO IL SUBMIT
	var f = document.dettaglio;
	f.action=f.actionPage.value;
	f.cmd.value="md";
	f.act.value=searchType;
	f.pageNumber.value=f.pageNumber.value-1;
	f.submit();
}

function nextPageDetail(searchType)
{//alert('pio');
	//FACCIO IL SUBMIT
	var f = document.dettaglio;
	f.action=f.actionPage.value;
	f.cmd.value="md";
	f.act.value=searchType;
	f.pageNumber.value=eval(f.pageNumber.value)+1;
	//alert(f.pageNumber.value);
	f.submit();
}
function goPageDetail(l_pageNumber)
{//alert('pio');
	//FACCIO IL SUBMIT
	var f = document.dettaglio;
	f.action=f.actionPage.value;
	f.cmd.value="md";
	f.pageNumber.value=l_pageNumber;
	//alert(f.pageNumber.value);
	f.submit();
}
//////////////////////////////////////////////////////////
/// gestione layers ///////////////////7//////////////////
/////////////////////////////////////////////////////////
function bkgMenu(menuName,color) {
      if (NS4) {
 
      screenWidth = window.innerWidth;
 
      document.layers[menuName].background = color;


      } else {

      screenWidth = document.body.clientWidth;

      document.all[menuName].style.background = color;
  
    }

}
///////////////////////////////////////////////
///////////////////////////////////////////////
function popUp(menuName,left,top) {
///////////////////////////////////////////////
///////////////////////////////////////////////
//alert('PUp :ns4='+NS4 + ' ie5='+IE4);
//alert('menuname='+menuName+' left='+left+' top='+top);
toleft =typeof left;
totop =typeof top;
//alert (toleft+' '+totop);

      if (NS4==1) {
//alert('PopUp ns4');
 
      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.all[menuName].style.pixelLeft = left;
      }
      if(top!=0 && totop != "undefined")
      {//alert('pio2');
       document.all[menuName].style.pixelTop = top;
      }
	//alert('pio');
      document.all[menuName].style.visibility = "visible";

 
    }

}
      
function popDown(menuName) 
{
//alert('PDown :ns4='+NS4 + ' ie5='+IE4);

	if (NS4) {
		document.layers[menuName].visibility = "hide";
	} else {
		document.all[menuName].style.visibility = "hidden";
	}
}

function motionListener(){

      if (NS4) {

      window.captureEvents(Event.MOUSEMOVE);
      window.onmousemove = grabXY;

      } else {

      document.onmousemove = grabXY;

      }
}

function grabXY(ev){
 
     if (NS4) {

      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'
	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) {
 
      screenWidth = window.innerWidth;
	//alert('ns mnuname'+menuName);
      layerWidth=parseInt(document.layers[menuName].clip.width);

	//alert('dopowidth');
    
      } else {
	
      screenWidth = document.body.clientWidth;
	layerWidth=parseInt(document.all[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
	//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';
				}
        		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
	//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('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 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;
      }
   }
   
   
function callSvlt(theSvlt)
{
		//FACCIO IL SUBMIT
		var f = document.menu;
		if (theSvlt.charAt(0)=="/")
			{//path assoluto
			theSvlt=webApp+theSvlt;
			}
		//	alert(theSvlt+".Svlt");
		f.action=theSvlt+".Svlt";
		f.cmd.value="search";
		f.submit();
}

 function callAbl(theSvlt,theFrame)
{
		//FACCIO IL SUBMIT
		var f = document.menu;
		if (theSvlt.charAt(0)=="/")
		{//path assoluto
			theSvlt=webApp+theSvlt;
		}
		if(theFrame==null)
		{
			f.action=theSvlt+".abl";
			f.cmd.value="search";
			f.submit();
		}
		else
		{
			var theBody=document.parentWindow.top.frames[theFrame];
			//alert(theSvlt+".abl");
			theBody.location.href=theSvlt+".abl?cmd=search";
		}
}

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