
//variabili per gestione calendario
var day;
var month;
var year;
document.onclick = myclick;
document.onkeydown = keyDown;
//document.onmousemove=SetXYTip;
var TastoPremuto=0;
var CoordX=0;
var CoordY=0;
var ns4=document.layers;
var ns6=document.getElementById && !document.all;
var ie=document.all;
if (ns4 || ns6)
	ns=true;
else
	ns=false;


// -------------------------------------------------
// 		F U N Z I O N I
// -------------------------------------------------
/*
function SetXYTip(e)
{
	var x=(ns4||ns6) ? e.pageX : event.x+document.body.scrollLeft;
	Tip.left=x+ScostamentoOrrizzontale;
	var y=(ns4||ns6) ? e.pageY : event.y+document.body.scrollTop;
	Tip.top=y+ScostamentoVerticale;
}

function kill()
{
	if(ns4)
		Tip.visibility="hidden";
	else if (ns6||ie)
		Tip.display="none"
}

function popup(msg){
	var content="<TABLE class=TabellaTips><TR><TD>"+msg+"</TD></TR></TABLE>";
 	if(ns4)
 	{
 		Tip.document.write(content);
 		Tip.document.close();
 		Tip.visibility="visible";
 	}
 	if(ns6)
 	{
 		document.getElementById("DivPerTip").innerHTML=content;
 		Tip.display='';
 	}
 	if(ie)
 	{
 		//alert(Tip.left+" "+Tip.top+" "+Event.y);
 		document.all("DivPerTip").innerHTML=content;
 		Tip.display='';
 	}
}
*/
function DataDiOggi()
{
    var DataOdierna = new Date();
	var NomeGg="";

    switch (DataOdierna.getDay()) 
    {
    	case 1: 
			NomeGg=JS_DAY1;
    		break;
    	case 2:
			NomeGg=JS_DAY2;
    		break;
    	case 3:
			NomeGg=JS_DAY3;
    		break;
    	case 4:
			NomeGg=JS_DAY4;
    		break;
    	case 5:
			NomeGg=JS_DAY5;
    		break;
    	case 6:
			NomeGg=JS_DAY6;
    		break;
    	case 0:
			NomeGg=JS_DAY7;
    		break;
    }          
    document.forms["DataOra"].Oggi.value =  NomeGg + ",  " + 
				                DataOdierna.getDate() +
						"-" +
						(DataOdierna.getMonth()+1) +
						"-" +
						DataOdierna.getFullYear();
}

function updateClock() 
{
    var now = new Date();

    var hour = now.getHours().toString();
    var min  = now.getMinutes().toString();
    var sec  = now.getSeconds().toString();

    if (min.length < 2)
      min = "0" + min;
    if (sec.length < 2)
      sec = "0" + sec;
    var time = hour + ":" + min + ":" + sec;

    // Aggiorna il display quando chiami ancora questa funzione per ogni secondo.
    document.forms["DataOra"].Time.value = time;
    setTimeout("updateClock();", 1000);
}

function setfocus(element) {
    element.focus();
    return;
} 

function ControlliFormDataSpec()
{
    if (!CampoObbligatorio(document.DataSpec.NUM1 , document.DataSpec.NUM1.name))
    	return false;
    else if (!CampoObbligatorio(document.DataSpec.NUM2 , document.DataSpec.NUM2.name))
    	return false;
//    else if ((parseInt(document.DataSpec.Sortita.value,10)==3) && (!CampoObbligatorio(document.DataSpec.NUM3 , document.DataSpec.NUM3.name)))
//    	return false;
    else if (!ValoreCompreso(document.DataSpec.NUM1,1,90))
    	return false;
    else if (!ValoreCompreso(document.DataSpec.NUM2,1,90))
    	return false;
    else if (!ValoreCompreso(document.DataSpec.NUM3,1,90))
    	return false;
    else if ((parseInt(document.DataSpec.NUM3.value,10)==parseInt(document.DataSpec.NUM2.value,10)) ||
    	     (parseInt(document.DataSpec.NUM2.value,10)==parseInt(document.DataSpec.NUM1.value,10)) ||
    	     (parseInt(document.DataSpec.NUM1.value,10)==parseInt(document.DataSpec.NUM3.value,10))   )
    {
		alert(ERRJS_002);
		document.DataSpec.NUM1.focus();
	    	return false;
    }
    else
    {
    	 if (parseInt(document.DataSpec.Sortita.value,10)==3)
    	 {
    	 	if (!CampoObbligatorio(document.DataSpec.NUM3 , document.DataSpec.NUM3.name))
			return false;
    	 } 
    	return true; 
    }
}

function ControlliFormCalcoloV()
{
    if (!CampoObbligatorio(document.CalcoloV.TotN , document.CalcoloV.TotN.name))
    	return false;
    else if (!CampoObbligatorio(document.CalcoloV.TotS , document.CalcoloV.TotS.name))
    	return false;
    else if (!ValoreCompreso(document.CalcoloV.TotN,1,10))
    	return false;
    else if (!ValoreCompreso(document.CalcoloV.TotS,1,5))
    	return false;
    else if (parseInt(document.CalcoloV.TotS.value,10)>parseInt(document.CalcoloV.TotN.value,10))
    	{
		alert(ERRJS_002);
		document.CalcoloV.TotS.focus();
	    	return false;
	}
    return true; 
}

function ControlliFormSelezD()
{
    if (!CampoObbligatorio(document.SelezD.Dgg , document.SelezD.Dgg.name))
    	return false;
    else if (!CampoObbligatorio(document.SelezD.Dmm , document.SelezD.Dmm.name))
    	return false;
    else if (!CampoObbligatorio(document.SelezD.Daa , document.SelezD.Daa.name))
    	return false;
    else if (!ValoreCompreso(document.SelezD.Dgg,1,31))
    	return false;
    else if (!ValoreCompreso(document.SelezD.Dmm,1,12))
    	return false;
    else if (!ValoreCompreso(document.SelezD.Daa,1939,2100))
    	return false;
    else if (!ValoreCompreso(document.SelezD.N1,1,90))
    	return false;
    else if (!ValoreCompreso(document.SelezD.N2,1,90))
    	return false;
    else if (!ValoreCompreso(document.SelezD.N3,1,90))
    	return false;
    else if (!ValoreCompreso(document.SelezD.N4,1,90))
    	return false;
    else if (!ValoreCompreso(document.SelezD.N5,1,90))
    	return false;
    return true; 
}

function ControlliFormStatVar()
{
    if (!CampoObbligatorio(document.StatVar.NUM1 , document.StatVar.NUM1.name))
    	return false;
    else if (!CampoObbligatorio(document.StatVar.NUM2 , document.StatVar.NUM2.name))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM1,0,90))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM2,0,90))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM3,0,90))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM4,0,90))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM5,0,90))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM6,0,90))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM7,0,90))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM8,0,90))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM9,0,90))
    	return false;
    else if (!ValoreCompreso(document.StatVar.NUM10,0,90))
    	return false;
    var myArray=new Array(document.StatVar.NUM1.value,document.StatVar.NUM2.value,document.StatVar.NUM3.value,
    			  document.StatVar.NUM4.value,document.StatVar.NUM5.value,document.StatVar.NUM6.value,
    			  document.StatVar.NUM7.value,document.StatVar.NUM8.value,document.StatVar.NUM9.value,
    			  document.StatVar.NUM10.value);
    var MyMsg = ERRJS_002;
    for (c1=0; c1<10; c1++)
    {
    	c3=0;
    	v1=parseInt(myArray[c1],10);
    	for (c2=0; c2<10; c2++)
    	{
    		v2=parseInt(myArray[c2],10);
    		if (!isNaN(v1) && v1==v2)
    			c3++;
    	}
    	if (c3>1)
    	{
		alert(MyMsg);
		return false;
   		
	}
    }
    return true; 
}

function ControlliFormSvil()
{
    if (!CampoObbligatorio(document.Svil.NUM1 , document.Svil.NUM1.name))
    	return false;
    else if (!CampoObbligatorio(document.Svil.NUM2 , document.Svil.NUM2.name))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM1,0,90))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM2,0,90))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM3,0,90))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM4,0,90))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM5,0,90))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM6,0,90))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM7,0,90))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM8,0,90))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM9,0,90))
    	return false;
    else if (!ValoreCompreso(document.Svil.NUM10,0,90))
    	return false;
    return true; 
}

function ControlliFormNewMess()
{
    if (!CampoObbligatorio(document.NewMess.NOME , document.NewMess.NOME.name))
    	return false;
    if (!CampoObbligatorio(document.NewMess.TESTO , document.NewMess.TESTO.name))
    	return false;
    return(controllaemail(document.NewMess.EMAIL.value,document.NewMess.EMAIL));
}

function ControlliFormSelezSt(ValMaxSorte)
{
	var S=document.SelezSt.Sortita.value;
	var C=document.SelezSt.Stat.value;
	
	var MyMsg = ERRJS_002;
	
	if (S==2)
	{
		if (C==1)
		{
			alert(MyMsg);
			return false;
		}
	}
	if (S==3)
	{
		if (C<=10)
		{
			alert(MyMsg);
			return false;
		}
	}
	if (S==4)
	{
		if (C<=12)
		{
			alert(MyMsg);
			return false;
		}
	}
	if (S==5)
	{
		if (C<=15)
		{
			alert(MyMsg);
			return false;
		}
	}
	return true;
}

function ControlliFormNewPrev()
{
    if (!CampoObbligatorio(document.NewPrev.NOME , document.NewPrev.NOME.name))
    	return false;
    else if (!CampoObbligatorio(document.NewPrev.NUM1 , document.NewPrev.NUM1.name))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM1,0,90))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM2,0,90))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM3,0,90))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM4,0,90))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM5,0,90))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM6,0,90))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM7,0,90))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM8,0,90))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM9,0,90))
    	return false;
    else if (!ValoreCompreso(document.NewPrev.NUM10,0,90))
    	return false;

    var myArray=new Array(document.NewPrev.NUM1.value,document.NewPrev.NUM2.value,document.NewPrev.NUM3.value,
    			  document.NewPrev.NUM4.value,document.NewPrev.NUM5.value,document.NewPrev.NUM6.value,
    			  document.NewPrev.NUM7.value,document.NewPrev.NUM8.value,document.NewPrev.NUM9.value,
    			  document.NewPrev.NUM10.value);
    var MyMsg = ERRJS_002;
    for (c1=0; c1<10; c1++)
    {
    	c3=0;
    	v1=parseInt(myArray[c1],10);
    	for (c2=0; c2<10; c2++)
    	{
    		v2=parseInt(myArray[c2],10);
    		if (!isNaN(v1) && v1==v2)
    			c3++;
    	}
    	if (c3>1)
    	{
		alert(MyMsg);
		return false;
   		
	}
    }

    if (!document.NewPrev.CHK1.checked && !document.NewPrev.CHK2.checked && !document.NewPrev.CHK3.checked &&
	!document.NewPrev.CHK4.checked && !document.NewPrev.CHK5.checked )
    {
	alert(MyMsg);
	return false;
   		
    }

    if (!document.NewPrev.RUOTA1.checked && !document.NewPrev.RUOTA2.checked && !document.NewPrev.RUOTA3.checked &&
	!document.NewPrev.RUOTA4.checked && !document.NewPrev.RUOTA5.checked &&
        !document.NewPrev.RUOTA6.checked && !document.NewPrev.RUOTA7.checked && !document.NewPrev.RUOTA8.checked &&
	!document.NewPrev.RUOTA9.checked && !document.NewPrev.RUOTA10.checked && !document.NewPrev.RUOTA11.checked)
    {
	alert(MyMsg);
	return false;
   		
    }

    return true;
}

function ControlliFormVerPrev(id)
{
	CallPageVerPrev(PHPSCRIPT_PREVVER+'?id='+id,'');
    	return false;
}

function ControlliFormInviaMail()
{
    if (!CampoObbligatorio(document.InviaMail.EMAILDEST , document.InviaMail.EMAILDEST.name))
    	return false;
    if (controllaemail(document.InviaMail.EMAILMITT.value,document.InviaMail.EMAILMITT))
    	return(controllaemail(document.InviaMail.EMAILDEST.value,document.InviaMail.EMAILDEST));
    return false;
}

function ControlliFormStat90()
{
    if (!CampoObbligatorio(document.Stat90.NUM , document.Stat90.NUM.name))
    	return false;
    else if (!ValoreCompreso(document.Stat90.NUM,1,90))
    	return false;
    return true; 
}

function ControlliFormUsers()
{
    if (!CampoObbligatorio(document.Users.NOME , document.Users.NOME.name))
    	return false;
    else if (!CampoObbligatorio(document.Users.EMAIL , document.Users.EMAIL.name))
    	return false;
    else if (controllaemail(document.Users.EMAIL.value,document.Users.EMAIL))
    	return true;
    return false;
}

function ControlliFormProposta()
{
    if (!CampoObbligatorio(document.Proposta.nome , document.Proposta.nome.name))
    	return false;
    else if (!CampoObbligatorio(document.Proposta.domanda , document.Proposta.domanda.name))
    	return false;
    else if (!CampoObbligatorio(document.Proposta.risposta1 , document.Proposta.risposta1.name))
    	return false;
    else if (!CampoObbligatorio(document.Proposta.risposta2 , document.Proposta.risposta2.name))
    	return false;
    else if (controllaemail(document.Proposta.email.value,document.Proposta.email))
    	return true;
    return false; 
}

function ControlliFormED()
{
    if (document.ED.NUM.value!="")
    {
    	if (!ValoreCompreso(document.ED.NUM,0,90))
    		return false;
    }
    if (document.ED.POS.value!="")
    {
    	if (!ValoreCompreso(document.ED.POS,0,5))
    		return false;
    }
    return true; 
}

function ControlliFormGioVin()
{
    if (!CampoObbligatorio(document.GioVin.GG , document.GioVin.GG.name))
    	return false;
    else if (!CampoObbligatorio(document.GioVin.MM , document.GioVin.MM.name))
    	return false;
    else if (!CampoObbligatorio(document.GioVin.AA , document.GioVin.AA.name))
    	return false;
    else if (!ValoreCompreso(document.GioVin.GG,1,31))
    	return false;
    else if (!ValoreCompreso(document.GioVin.MM,1,12))
    	return false;
    else if (!ValoreCompreso(document.GioVin.AA,1939,2100))
    	return false;
    else if (!Controllo_Data(document.GioVin.GG.value,document.GioVin.MM.value,document.GioVin.AA.value))
    	return false;
    return true; 
}

function ControlliFormRICAMBO()
{
    if (!CampoObbligatorio(document.RICAMBO.N1 , document.RICAMBO.N1.name))
    	return false;
    else if (!CampoObbligatorio(document.RICAMBO.N2 , document.RICAMBO.N2.name))
    	return false;
    else if (!ValoreCompreso(document.RICAMBO.N1,1,90))
    	return false;
    else if (!ValoreCompreso(document.RICAMBO.N2,1,90))
    	return false;
    else if (document.RICAMBO.N1.value==document.RICAMBO.N2.value)
    {
	alert (ERRJS_002);
	document.RICAMBO.N1.focus();
	return false;
    }
    return true; 
}

function ControlliFormRICAMBATA()
{
    if (!CampoObbligatorio(document.RICAMBATA.N1 , document.RICAMBATA.N1.name))
    	return false;
    else if (!ValoreCompreso(document.RICAMBATA.N1,1,90))
    	return false;
    return true; 
}

function ControlliFormAmbitutte()
{
    if (!ValoreCompreso(document.Ambitutte.N1,0,90))
    	return false;
    else if (!ValoreCompreso(document.Ambitutte.N2,0,90))
    	return false;    	
    return true; 
}

function ControlliFormTuttiGliAmbiAll()
{
    if (parseInt(document.TuttiGliAmbiAll.RITDA.value,10)>parseInt(document.TuttiGliAmbiAll.RITA.value,10))
    {
		alert(ERRJS_002);
		document.TuttiGliAmbiAll.RITDA.focus();
	    	return false;
    }
    return true; 
}

function ControlliFormDOPPIEFORMAZIONI()
{
	
	var frz1=parseInt(document.DOPPIEFORMAZIONI.f1.value,10);
	var frz2=parseInt(document.DOPPIEFORMAZIONI.f2.value,10);
	var sr1=parseInt(document.DOPPIEFORMAZIONI.s1.value,10);
	var sr2=parseInt(document.DOPPIEFORMAZIONI.s2.value,10);
	
	if ((frz1==1 ||frz1==2 ||frz1==4 ||frz1==6 ||frz1==7) && (sr1==10))
    	{
		alert(ERRJS_002);
		document.DOPPIEFORMAZIONI.s1.focus();
	    	return false;
    	}
	if ((frz2==1 ||frz2==2 ||frz2==4 ||frz2==6 ||frz2==7) && (sr2==10))
    	{
		alert(ERRJS_002);
		document.DOPPIEFORMAZIONI.s2.focus();
	    	return false;
  	}
  	
  	/*
    	if (!ValoreCompreso(document.DOPPIEFORMAZIONI.s2,1,10))
    		return false;
  	*/
    	return true; 
}
function keyDown(e)
{
		TastoPremuto=0;
		if(ie)
			TastoPremuto=event.keyCode;
		else
			TastoPremuto=e.which;
		return true;
}

function myclick(e)
{
		if(ie)
		{
			//CoordX=event.x+document.body.scrollLeft;
			//CoordY=event.y+document.body.scrollTop;
			CoordX=event.x;
			CoordY=event.y;
			//alert(event.x+"+"+document.body.scrollLeft+"="+CoordX);
			//alert(event.y+"+"+document.body.scrollTop+"="+CoordY);
		}
		else
		{
			CoordX=e.screenX;
			CoordY=e.screenY;
			//alert(e.pageX+" "+e.pageY+"...."+e.screenX+" "+e.screenY);
		}
		return true;
}

function CntCampoNumerico(e,Campo)
{
	if(ie)
		var KeyDig = event.keyCode;
  	else
  		var KeyDig = e.which;
	if ((KeyDig>=48 && KeyDig<=57) || (KeyDig==44) || (KeyDig==46) || TastoPremuto==9 || TastoPremuto==8)
		return true;
	
        return false;	
}

function CntCampoNumericoNoVirgola(e,Campo)
{
	if(ie)
    		var KeyDig = event.keyCode;
  	else
  		var KeyDig = e.which;

	if ((KeyDig>=48 && KeyDig<=57) || TastoPremuto==9 || TastoPremuto==8)
		return true;

	return false;	
}

function CampoObbligatorio(Campo , Nome)
{
    if (Campo.value == "")
    {
	alert (ERRJS_001);
	Campo.focus();
	return false;
    }
    return true;
}

function ValoreCompreso(Campo,valmin,valmax)
{
    if ((parseInt(Campo.value,10)<valmin) || (parseInt(Campo.value,10)>valmax))
    {
	alert(ERRJS_003 + valmin + ERRJS_004 + valmax);
	Campo.focus();
	return false;
    }
    return true;
}

function setPointer(theRow, thePointerColor)
{
	
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }
    var row_cells_cnt = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
        theRow.cells[c].bgColor = thePointerColor;
    }
}

function ShowWin(Myurl,Title,H,L)
{
   Title="";	
   window.open(Myurl,Title,"height="+H+",width="+L+",directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes");
}

function CallPageSvil(Myurl,Title)
{
	var h=screen.height-200;
	var w=screen.width-200;
	window.close();
   	ShowWinMax(Myurl,Title,h,w,1,1);
}

function CallPageVerPrev(Myurl,Title)
{
	var h=screen.height/4;
	var w=screen.width/2;
	var x=screen.width/4;
	var y=screen.height/4;
   	ShowWinVerPrev(Myurl,Title,h,w,x,y);
}

function ShowWinVerPrev(Myurl,Title,h,w,x,y)
{
   if(ie)
   {
  	window.open(Myurl,Title,"height="+h+",width="+w+",directories=no,location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes,left="+x+",top="+y);
   }
   else
   {
  	window.open(Myurl,Title,"height="+h+",width="+w+",directories=no,location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes,screenX="+x+",screenY="+y);
   }
}
function ShowWinMax(Myurl,Title,h,w,x,y)
{
   if(ie)
   {
  	window.open(Myurl,Title,"height="+h+",width="+w+",directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,left="+x+",top="+y);
   }
   else
   {
  	window.open(Myurl,Title,"height="+h+",width="+w+",directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,screenX="+x+",screenY="+y);
   }
}

function ShowWinPlay(Myurl,Title,H,L)
{
   window.open(Myurl,Title,"height="+H+",width="+L+",directories=no,location=no,menubar=no,resizable=no,status=no,toolbar=no");
}

function ShowWinNu(Myurl,Title,H,L)
{
   if(ie)
   {
   	window.open(Myurl,Title,"height="+H+",width="+L+",directories=no,location=no,menubar=no,resizable=yes,status=yes,toolbar=no,top="+CoordY+",left="+CoordX);
   }
   else
   {
   	window.open(Myurl,Title,"height="+H+",width="+L+",directories=no,location=no,menubar=no,resizable=yes,status=no,toolbar=no,screenY="+CoordY+",screenX="+CoordX);
   }
}

function ShowWinMin(Myurl,Title,H,L)
{
   if(ie)
   {
   	window.open(Myurl,Title,"height="+H+",width="+L+",directories=no,location=no,menubar=no,resizable=no,status=no,toolbar=no,top="+CoordY+",left="+CoordX);
   }
   else
   {
   	window.open(Myurl,Title,"height="+H+",width="+L+",directories=no,location=no,menubar=no,resizable=yes,status=no,toolbar=no,screenY="+CoordY+",screenX="+CoordX);
   }
}

function ShowWinCenter(Myurl,Title,H,L)
{
	//alert("myclick:"+screen.width+" "+screen.height);
	//alert("ie="+Myurl+" "+Title+" "+H+" "+L+CoordY+CoordX);
	var ywin = (screen.height/2)-(H/2);
	var xwin = (screen.width/2)-(L/2);
   if(ie)
   {
   	window.open(Myurl,Title,"height="+H+",width="+L+",directories=no,location=no,menubar=no,resizable=yes,status=yes,toolbar=no,scrollbars=yes,top="+ywin+",left="+xwin);
   }
   else
   {
   	window.open(Myurl,Title,"height="+H+",width="+L+",directories=no,location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes,screenY="+ywin+",screenX="+xwin);
   }
}

function ShowWinGraph(Myurl,Title,H,L)
{
	//alert(Myurl);
	var CoordY = (screen.height/2)-(H/2);
	var CoordX = (screen.width/2)-(L/2);
   if(ie)
   {
   	window.open(Myurl,Title,"height="+H+",width="+L+",directories=no,location=no,menubar=no,resizable=yes,status=no,toolbar=no,top="+CoordY+",left="+CoordX);
   }
   else
   {
   	window.open(Myurl,Title,"height="+H+",width="+L+",directories=no,location=no,menubar=no,resizable=no,status=no,toolbar=no,screenY="+CoordY+",screenX="+CoordX);
   }
}

function controllaemail(email,campo)
{
	//alert(email);
	if (email == "")
		return true;
	var chiocciola = "@";
	var punto = ".";
	var contachiocciole=0;
	var contapunti=0;
	var contapuntochiocciola=0;
	var contachiocciolapunto=0;
	var cepuntodopochiocciola=false;
	var posch=0;
	var pospu=0;
	for (var i = 0; i < email.length; i++)
	{
		if (email.charAt(i) == chiocciola)
		{
			contachiocciole++;
			if (i > 0)
				if (email.charAt(i-1) == punto)
					contapuntochiocciola++;
			if (i < (email.length-1))
				if (email.charAt(i+1) == punto)
					contachiocciolapunto++;
			posch=i;
		}
		if (email.charAt(i) == punto)
		{
			contapunti++;
			if (contapunti>1 && email.charAt(i-1) == punto)
			{
				alert(ERRJS_005);
				campo.focus();
				return false;
			}
			if (i > 0)
				if (email.charAt(i-1) == chiocciola)
					contachiocciolapunto++;
			if (i < (email.length-1))
				if (email.charAt(i+1) == chiocciola)
					contapuntochiocciola++;
			pospu=i;
		}
	}
	if ( contachiocciole > 1 )
	{
		alert(ERRJS_005);
		campo.focus();
		return false;
	}
	if (contapunti == 0)
	{
		alert(ERRJS_005);
		campo.focus();
		return false;
	}
	if ((email.charAt(0) == punto) ||
	    (email.charAt(0) == chiocciola) ||
	    (email.charAt(email.length-1) == punto) ||
	    (email.charAt(email.length-1) == chiocciola))
	{
		alert(ERRJS_005);
		campo.focus();
		return false;
	}
	if (contachiocciolapunto > 0 || contapuntochiocciola > 0)
	{
		alert(ERRJS_005);
		campo.focus();
		return false;
	}
	if (pospu <(posch+2))
	{
		alert(ERRJS_005);
		campo.focus();
		return false;
	}
	return true;
}
function ShowWinFull(Myurl,Title)
{
   if(ie)
   {
	window.open(Myurl,Title,"height="+screen.height+" ,width="+screen.width+",directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,top=1,left=1");
   }
   else
   {
	window.open(Myurl,Title,"height="+screen.height+" ,width="+screen.width+",directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,screenX=1,screenY=1");
   }
}
function Controllo_Data(gg,mm,aa)
{
	if (gg.length<2)
		gg='0'+gg;
	if (mm.length<2)
		mm='0'+mm;
	if(isNaN(gg))
	{
		alert(ERRJS_006);
		return false;
	}
	else if((gg>31)||(gg.length<2))
	{
		alert(ERRJS_006);
		return false;
	}
	else if(isNaN(mm))
	{
		alert(ERRJS_006);
		return false;
	}
	else if((mm>12)||(mm.length<2))
	{
		alert(ERRJS_006);
		return false;
	}
	else if(isNaN(aa))
	{
		alert(ERRJS_006);
		return false;
	}
	else if ((aa.length<4)||(aa.length>4))
	{
		alert(ERRJS_006);
		return false;
	}	 

	if ((mm=='04')||(mm=='06')||(mm=='09')||(mm=='11'))
	{
		if(gg>30)
		{
			alert(ERRJS_006);
			return false;
		}
	}
	else if(mm=='02')
	{
		if(gg>29)	//processo anno bisestile
		{
			alert(ERRJS_006);
			return false
		}
		else if ((gg=='29')&&(!((aa % 4 == 0) && (!(aa % 100 == 0)) || (aa % 400 == 0))))
		{
			alert(ERRJS_006);
			return false;
		}
	}
  return true;
}

function CntCampoData(e,Campo)
{
	if(ie)
		var KeyDig = event.keyCode;
  	else
  		var KeyDig = e.which;
	if ((KeyDig>=48 && KeyDig<=57) || (String.fromCharCode(KeyDig)=='-') || TastoPremuto==9 || TastoPremuto==8)
		return true;
	
        return false;	
}
function DefaultDataDiOggi(NomeForm,NomeCampo)
{
    CampoData = eval("document." + NomeForm + "." + NomeCampo);
    if (CampoData.value=="")
	CampoData.value=DataOdiernaForm();
}
function DataOdiernaForm()
{
    var DataOdierna = new Date();
    var gg = String(DataOdierna.getDate());
    var aa = String(DataOdierna.getFullYear());
    var mm = String((DataOdierna.getMonth())+1);
    if (gg.length < 2)
      gg = "0" + gg;
    if (mm.length < 2)
      mm = "0" + mm;
    var DataForm = gg+"-"+mm+"-"+aa;
    return(DataForm);
    
}

// -------------------------------------------------
// FUNZIONI PER GESTIONE CALENDARIO
// -------------------------------------------------
function openCalendar(NomeForm, NomeCampo, NomePgm) {
    //alert(NomePgm+" "+NomeForm+" "+NomeCampo);
    window.open("./"+NomePgm, "calendar", "width=350,height=170,status=yes");
    dateField = eval("document." + NomeForm + "." + NomeCampo);
}
function formatNum2(i, valtype) {
    f = (i < 10 ? '0' : '') + i;
    if (valtype && valtype != '') {
        switch(valtype) {
            case 'month':
                f = (f > 12 ? 12 : f);
                break;

            case 'day':
                f = (f > 31 ? 31 : f);
                break;

            default:
                break;
        }
    }
    return f;
}
function formatNum4(i) {
    return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
}
function initCalendar() {
    if (!year && !month && !day) 
    {
        if (window.opener.dateField.value)	// Called for first time 
        {
            value = window.opener.dateField.value;
                date        = value.split("-");
                //day         = parseInt(date[2],10);
                day         = parseInt(date[0],10);
                month       = parseInt(date[1],10) - 1;
                //year        = parseInt(date[0],10);
                year        = parseInt(date[2],10);
        }
        if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0)
        {
            dt      = new Date();
            year    = dt.getFullYear();
            month   = dt.getMonth();
            day     = dt.getDate();
        }
    } else {
        if (month > 11) {
            month = 0;
            year++;
        }
        if (month < 0) {
            month = 11;
            year--;
        }
    }

    if (document.getElementById) {
        cnt = document.getElementById("calendar_data");
    } else if (document.all) {
        cnt = document.all["calendar_data"];
    }

    cnt.innerHTML = "";

    str = ""

    //heading table
    str += '<table class="TabCalendario"><tr><th width="50%">';
    str += '<form method="NONE" onsubmit="return 0">';
    str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
    str += '<select id="select_month" name="monthsel" onchange="month = parseInt(document.getElementById(\'select_month\').value); initCalendar();">';
    for (i =0; i < 12; i++) {
        if (i == month) selected = ' selected="selected"';
        else selected = '';
        str += '<option value="' + i + '" ' + selected + '>' + month_names[i] + '</option>';
    }
    str += '</select>';
    str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
    str += '</form>';
    str += '</th><th width="50%">';
    str += '<form method="NONE" onsubmit="return 0">';
    str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
    str += '<select id="select_year" name="yearsel" onchange="year = parseInt(document.getElementById(\'select_year\').value); initCalendar();">';
    oggi = new Date();
    yearoggi = oggi.getFullYear();    
    
    
    for (i = 1939; i <= yearoggi; i++) {
        if (i == year) selected = ' selected="selected"';
        else selected = '';
        str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
    }
    str += '</select>';
    str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
    str += '</form>';
    str += '</th></tr></table>';

    str += '<table class="TabCalendario"><tr>';
    for (i = 0; i < 7; i++) {
        str += "<th>" + day_names[i] + "</th>";
    }
    str += "</tr>";

    var firstDay = new Date(year, month, 1).getDay();
    var lastDay = new Date(year, month + 1, 0).getDate();
    
    str += "<tr>";

    dayInWeek = 0;
    for (i = 0; i < firstDay; i++) {
        str += "<td>&nbsp;</td>";
        dayInWeek++;
    }
    for (i = 1; i <= lastDay; i++) {
        if (dayInWeek == 7) {
            str += "</tr><tr>";
            dayInWeek = 0;
        }

        dispmonth = 1 + month;

            //actVal = formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
            actVal = formatNum2(i, 'day') + "-" + formatNum2(dispmonth, 'month') + "-" +formatNum4(year)  ;

        if (i == day) {
            style = ' class="CalSelectedDay"';
        } else {
            style = '';
        }
        str += "<td" + style + "><a href=\"javascript:returnDate('" + actVal + "');\">" + i + "</a></td>"
        dayInWeek++;
    }
    for (i = dayInWeek; i < 7; i++) {
        str += "<td>&nbsp;</td>";
    }
    str += "</tr></table>";

    cnt.innerHTML = str;
}
function returnDate(d) {
    window.opener.dateField.value = d;
    window.close();
}
