
function limitachar(campo,limite) {
	if (campo.value.length > limite) {
		campo.value = campo.value.substring(0,limite);
		alert('Inserire massimo '+limite+' caratteri.');
	}
}


/** trasforma il campo in modo da rendere tutti numeri e trasformare la "," in "."
* uso: <input type="text" onChange="prezzizza(this)">
*/
function prezzizza(campo) {
	var strcampo='';
	var nonTrovatoSeparatore=true;
	if (!isEmpty(campo.value)) {
		for (i = 0; i < campo.value.length; i++) {
			c = campo.value.charAt(i);
			if(isNumber(c)) {
				strcampo = strcampo + c;
				continue;
			}
			//controlla se trovato per la prima volta il separatore decimale "," oppure "."
			if (nonTrovatoSeparatore && (c==',' || c=='.')) {
				strcampo = strcampo + '.';
				nonTrovatoSeparatore=false;
			}
		}
		campo.value=strcampo;
	}
}

function paginaupdate(myForm,funzioneControllo) {
	var flag=true;
	if (funzioneControllo!="") {
	eval("flag="+funzioneControllo+"(myForm);");
	}
	if (flag==true) {
		paginahtml = 
		  "<HTML><HEAD><TITLE>Aggiornamento dati</TITLE></HEAD>\n" +
		  "<BODY BGCOLOR='#FFFFFF' onBlur='self.close()'>\n" +
		  "Aggiornamento dati in corso.<br>\n" +
		  "<input type='button' value='Chiudi' onClick='self.close()'>\n" +
		  "</BODY></HTML>\n";
		
		top.updateWin = window.open("javascript:parent.opener.paginahtml", "updateWin", "width=450,height=200");
		myForm.target="updateWin";
		myForm.submit();
	}
}

function paginalocalita(idanagrafica,tutte) {
      pagina="LOC_elenco.php?IDANAGRAFICA="+idanagrafica+"&cmd=popup&tutte="+tutte;
      finestra=window.open(pagina,"elenco_localita","width=800,height=350,menubar=yes,scrollbars=yes,resizable=yes");
	}

function paginalocalita2(idanagrafica,nomeForm,tutte) {
      pagina="LOC_elenco.php?IDANAGRAFICA="+idanagrafica+"&cmd=popup&nomeForm="+nomeForm+"&tutte="+tutte;
      finestra=window.open(pagina,"elenco_localita","width=800,height=350,menubar=yes,scrollbars=yes,resizable=yes");
	}

function confermaUrl(msg,myUrl) {
	if(confirm(msg)) {
		window.location.href=myUrl;
	}
}


function paginacomuni(nomeForm) {
	pagina="STRUTT_PC_elenco.php?cmd=popup&nomeForm="+nomeForm;
	finestra=window.open(pagina,"elenco_comuni","width=800,height=350,menubar=yes,scrollbars=yes,resizable=yes,status=yes");
}

function paginaRubrica(nomeForm,nomeCampo,SirioISTATLavoro) {
	pagina="RUBRICA_elenco.php?ISTAT="+SirioISTATLavoro+"&cmd=selectPopup&nomeForm="+nomeForm+"&nomeCampo="+nomeCampo;
	finestra=window.open(pagina,"elenco_rubrica","width=800,height=350,menubar=yes,scrollbars=yes,resizable=yes,status=yes");
}

function apriSchedaRubrica(idanagrafica) {
	if (!isEmpty(idanagrafica) && ""+idanagrafica+""!="0") {
		pagina="RUBRICA_scheda.php?IDANAGRAFICA="+idanagrafica;
		finestra=window.open(pagina,"scheda_rubrica","width=800,height=350,menubar=yes,scrollbars=yes,resizable=yes,status=yes");
	}
}

function apriSchedaCane(idanagrafica) {
	if (!isEmpty(idanagrafica) && ""+idanagrafica+""!="0") {
		pagina="/volontariato/schedacane.php?idanagrafica="+idanagrafica;
		finestra=window.open(pagina,"schedacane","width=800,height=350,menubar=yes,scrollbars=yes,resizable=yes,status=yes");
	}
}

var numAttachments = 0;
var whitespace = "\t\n\r ";
var defaultEmptyOK = false;
var invalidAddrChars = "\\\/\"<>(),;:$&!\`\'^*|[]{}";
var invalidDomainChars = "\\\/\"<>(),;:$&!\`\'^*@|{}";
var validNumbers = "0123456789";
var emptyAddr = true;
var ErrorAddrChars = "";



function verifica_dati_registrazione(myForm) {
 var nome = myForm.nome.value;
 var cognome = myForm.cognome.value;
 var email = myForm.email.value; 
 var cellulare  = myForm.cellulare.value;
 var fax = myForm.fax.value;
 var ragionesociale = myForm.ragionesociale.value;
 var partitaiva = myForm.partitaiva.value;
 var indirizzo = myForm.indirizzo.value;
 var cap = myForm.cap.value;
 var citta = myForm.citta.value;
 var idprovincia = myForm.idprovincia.options[myForm.idprovincia.selectedIndex].value;
 var idsettore = myForm.idprovincia.options[myForm.idsettore.selectedIndex].value;
 var username = myForm.username.value;
 var password = myForm.password.value;
 var password2 = myForm.password2.value;
 var accettoInformativa = myForm.accettoInformativa[0].checked;
 var accettoComunicazioni = myForm.accettoComunicazioni.value;
 
 
  
 /*
 var indice_d=myForm.GIORNONASCITA.selectedIndex;
 var giornonascita =  myForm.GIORNONASCITA.options[indice_d].value;
 
 var indice_m=myForm.MESENASCITA.selectedIndex;
 var mesenascita = myForm.MESENASCITA.options[indice_m].value;
  
 var annonascita = myForm.ANNONASCITA.value;
 
 var cod_fisc = myForm.COD_FISC.value;
 //var data_nascita = myForm.DATA_NASCITA.value;
 var comune_nascita = myForm.COMUNE_NASCITA.value; 
 //var partita_iva = myForm.PARTITA_IVA.value; 
 var professione = myForm.PROFESSIONE.value; 
 var reperibilita = myForm.REPERIBILITA.value; 
 
*/


 
 var action = "adesione.php";


//imposto flag=true per lanciare il form
var flag=true;
var passaggio="";


//controlli vari...
//se qualcosa non va: flag=false
//                    messaggio="errore da visualizzare"

if (flag && isWhitespace(nome)) {
	passaggio="Inserire il nome";
	flag=false;
}

if (flag && isWhitespace(cognome)) {
	passaggio="Inserire il cognome";
	flag=false;
}

if (flag && (! emailCheck(email))) {
	passaggio="Email inserita non valida";
	flag=false;
}

/*
if (flag && isWhitespace(cellulare)) {
	passaggio="Inserire il numero di telefono cellulare";
	flag=false;
}
*/

/*
if (flag && isWhitespace(fax)) {
	passaggio="Inserire il numero di fax";
	flag=false;
}
*/

if (flag && isWhitespace(ragionesociale)) {
	passaggio="Inserire il nome della ditta";
	flag=false;
}

if (flag && partitaiva.length<11) {
	passaggio="Inserire partita IVA corretta";
	flag=false;
}

if (flag && isWhitespace(indirizzo)) {
	passaggio="Inserire l'indirizzo";
	flag=false;
}

if (flag && isWhitespace(cap)) {
	passaggio="Inserire CAP";
	flag=false;
}

if (flag && isWhitespace(citta)) {
	passaggio="Inserire cittŕ";
	flag=false;
}

if (flag && idprovincia==0) {
	passaggio="Selezionare provincia";
	flag=false;
}

if (flag && idsettore==0) {
	passaggio="Selezionare settore";
	flag=false;
}

if (flag && isWhitespace(username)) {
	passaggio="Manca username";
	flag=false;
}

if (flag && isWhitespace(password)) {
	passaggio="Manca password";
	flag=false;
}

if (flag && password!=password2) {
	passaggio="Conferma della password non corrispondente";
	flag=false;
}

if (flag && (! accettoInformativa)) {
	passaggio="E' necessario accettare l'informativa";
	flag=false;
}

/*
if (flag && accettoComunicazioni==0) {
	passaggio="accettoComunicazioni no?";
	flag=false;
}
*/


/*
if (flag && checkdate(giornonascita,mesenascita,annonascita)==false) {
	passaggio="Data di nascita non valida";
	flag=false;
}

if (flag && (isWhitespace(cod_fisc) || cod_fisc.length!=16) ) {
	passaggio="Codice fiscale non corretto";
	flag=false;
}

*/





//lancia il form se tutto č a posto
if (flag==false) {
	   alert(passaggio);
	   return false;
	}
else {
   myForm.action=action;
   myForm.submit();
   return true;
}

}



function checkdate(d,m,y) 
{ 
  //alert(d + "/" + m + "/" + y);
  oggi = new Date();
  var yl=1900;   // least year to consider 
  var ym=oggi.getYear();   // most year to consider 
  
  //per netscape che a volte risponde con gli anni passati dal 1900
  if (ym<200) ym=ym+1900;
  
  //alert("yl:"+yl+" ym:"+ym);
  if (m<1 || m>12)  {
  	
  	return(false);}
  if (d<1 || d>31)  {
  		
  		return(false);}
  if (y<yl || y>ym) {
  	alert("yl:"+yl+" ym:"+ym);
  	return(false);}
  if (m==4 || m==6 || m==9 || m==11) 
    if (d==31) {
    	
    	return(false);}
  if (m==2) 
  { 
    var b=parseInt(y/4); 
    if (isNaN(b)) {return(false);}
    if (d>29)     {return(false);} 
    if (d==29 && ((y/4)!=parseInt(y/4))) {return(false);}
    
  } 
  return(true);
}



function isEmpty(s)
{
    if (s == null || s.length == 0) return true;
    return false;
}

function isWhitespace(s)
{
	var i,c;
	flag=true;
	 
    // Is s empty?
    if (isEmpty(s)) {flag=true;}
    else {
 
    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
       
       // Check that current character isn't whitespace.
       c = s.charAt(i);
       if (whitespace.indexOf(c) == -1 ) {
       	flag=false;
       	break;
       }
    }
    }
    // All characters are whitespace.
    return flag;
}

//riceve una stringa
//true se la stringa ha almeno un carattere e ogni carattere e' un numero
//false altrimenti
function isNumber(s)
{
	var i,c;
	flag=true;
	 
    // Is s empty?
    if (isEmpty(s)) {flag=false;}
    else {
 
    // controlla uno ad uno i caratteri della stringa
    // finche' trova caratteri "non-numeri".
    
    for (i = 0; i < s.length; i++)
    {
       c = s.charAt(i);
       if (validNumbers.indexOf(c) == -1 ) {
       	flag=false;
       	break;
       }
    }
    }
    
    return flag;
}

//num numero decimale
//n_int cifre intere
//n_dec cifre decimali
function isDecimal(num,n_int,n_dec)
{
	flag=true;
	var pint,pdec; //parte intera  e parte decimale
    // Is s empty?
    if (isEmpty(num)) {flag=false;}
    else {
 		if (num.indexOf('.')== -1) { //se non c'e' il punto
 			//num deve essere un numero di massimo n_int cifre
 			if (!(isNumber(num) && num.length<=n_int)) {flag=false;};
 		} else { //se c'e' il punto
 			pint=num.substr(0,num.indexOf('.')); //parte intera
 			pdec=num.substr(num.indexOf('.') + 1,num.length); //parte decimale
			if (pint=="") {pint="0";}
			if (pdec=="") {pdec="0";}
			if (!(isNumber(pint) && isNumber(pdec) && pint.length<=n_int && pdec.length<=n_dec)) {
				flag=false;
			}
 		}
    }
    return flag;
}



function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

//alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

//alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
//alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//artificio per avere sempre un valore di ritorno anche con i check box
function cecca(myform,nomecampo) {
	if (eval('myform.HHH_'+nomecampo+'.checked==true')) {
		eval('myform.'+nomecampo+'.value=1');
	} else {
		eval('myform.'+nomecampo+'.value=0');
	}
}

// This function will trim leading and/or trailing spaces from a string
// arg = the value you wish to have trimmed..
// func = "left" for Ltrim(), "right" for RTrim() or "both" for Trim()
//===================================
function trim(arg,func) {
//===================================

	var trimvalue = "";
	var i=0;
	arglen = arg.length;
	if (arglen < 1) return trimvalue;

	if (func == "left" || func== "both") {
		i = 0;
		pos = -1;
		while (i < arglen) {
			if (arg.charCodeAt(i) != 32 &&
!isNaN(arg.charCodeAt(i))) {
				pos = i;
				break;
			}
			i++;
		}
	}

	if (func == "right" || func== "both") {
		var lastpos = -1;
		i = arglen;
		while (i >= 0) {
			if (arg.charCodeAt(i) != 32 &&
!isNaN(arg.charCodeAt(i))) {
				lastpos = i;
				break;
			}
			i--;
		}
	}

	if (func == "left") {
			trimvalue = arg.substring(pos,arglen-1);
		}

	if (func == "right") {
		trimvalue = arg.substring(0,lastpos+1);
	}

	if (func == "both") {
		trimvalue = arg.substring(pos,lastpos + 1);
	}

	return trimvalue;
}

//ritorna true o false
function isPartitaIva(s) {
	//p.iva celesta 02998490276
	var z=0;
	var y=0;
	var contr="";
	var strTemp="";
	for(x=0;x<9;x+=2) {
		z += parseInt(s.charAt(x));
		strTemp="000" + trim(""+ (parseInt(s.charAt(x+1)) * 2),"both");
		contr = strTemp.substring(strTemp.length - 3,strTemp.length);
		z += parseInt(contr.charAt(1)) + parseInt(contr.charAt(2));
	}
	strTemp="000" + trim(""+ z,"both");
	contr = strTemp.substring(strTemp.length - 3,strTemp.length);
	y=10 - parseInt(contr.charAt(2));
	strTemp="000" + trim(""+ y,"both");
	contr = strTemp.substring(strTemp.length - 3,strTemp.length);
	if (contr.charAt(2) != s.charAt(10)) {
		return false;
	} else {
		return true;
	}
}

function isCodiceFiscale(s) {
	var z=0;
	var y=0;
	var contr="";
	for(x=0;x<15;x+=2) {
		if (s.charAt(x)=="A" || s.charAt(x)=="0") {z += 1;}
		if (s.charAt(x)=="B" || s.charAt(x)=="1") {z += 0;}
		if (s.charAt(x)=="C" || s.charAt(x)=="2") {z += 5;}
		if (s.charAt(x)=="D" || s.charAt(x)=="3") {z += 7;}
		if (s.charAt(x)=="E" || s.charAt(x)=="4") {z += 9;}
		if (s.charAt(x)=="F" || s.charAt(x)=="5") {z += 13;}
		if (s.charAt(x)=="G" || s.charAt(x)=="6") {z += 15;}
		if (s.charAt(x)=="H" || s.charAt(x)=="7") {z += 17;}
		if (s.charAt(x)=="I" || s.charAt(x)=="8") {z += 19;}
		if (s.charAt(x)=="J" || s.charAt(x)=="9") {z += 21;}
		if (s.charAt(x)=="K") {z += 2;}
		if (s.charAt(x)=="L") {z += 4;}
		if (s.charAt(x)=="M") {z += 18;}
		if (s.charAt(x)=="N") {z += 20;}
		if (s.charAt(x)=="O") {z += 11;}
		if (s.charAt(x)=="P") {z += 3;}
		if (s.charAt(x)=="Q") {z += 6;}
		if (s.charAt(x)=="R") {z += 8;}
		if (s.charAt(x)=="S") {z += 12;}
		if (s.charAt(x)=="T") {z += 14;}
		if (s.charAt(x)=="U") {z += 16;}
		if (s.charAt(x)=="V") {z += 10;}
		if (s.charAt(x)=="W") {z += 22;}
		if (s.charAt(x)=="X") {z += 25;}
		if (s.charAt(x)=="Y") {z += 24;}
		if (s.charAt(x)=="Z") {z += 23;}
	}
	for(x=1;x<14;x+=2) {
		if (s.charAt(x)=="A" || s.charAt(x)=="0") {z += 0;}
		if (s.charAt(x)=="B" || s.charAt(x)=="1") {z += 1;}
		if (s.charAt(x)=="C" || s.charAt(x)=="2") {z += 2;}
		if (s.charAt(x)=="D" || s.charAt(x)=="3") {z += 3;}
		if (s.charAt(x)=="E" || s.charAt(x)=="4") {z += 4;}
		if (s.charAt(x)=="F" || s.charAt(x)=="5") {z += 5;}
		if (s.charAt(x)=="G" || s.charAt(x)=="6") {z += 6;}
		if (s.charAt(x)=="H" || s.charAt(x)=="7") {z += 7;}
		if (s.charAt(x)=="I" || s.charAt(x)=="8") {z += 8;}
		if (s.charAt(x)=="J" || s.charAt(x)=="9") {z += 9;}
		if (s.charAt(x)=="K") {z += 10;}
		if (s.charAt(x)=="L") {z += 11;}
		if (s.charAt(x)=="M") {z += 12;}
		if (s.charAt(x)=="N") {z += 13;}
		if (s.charAt(x)=="O") {z += 14;}
		if (s.charAt(x)=="P") {z += 15;}
		if (s.charAt(x)=="Q") {z += 16;}
		if (s.charAt(x)=="R") {z += 17;}
		if (s.charAt(x)=="S") {z += 18;}
		if (s.charAt(x)=="T") {z += 19;}
		if (s.charAt(x)=="U") {z += 20;}
		if (s.charAt(x)=="V") {z += 21;}
		if (s.charAt(x)=="W") {z += 22;}
		if (s.charAt(x)=="X") {z += 23;}
		if (s.charAt(x)=="Y") {z += 24;}
		if (s.charAt(x)=="Z") {z += 25;}
	}
	y = z % 26;
	if (y==0) {contr="A";}
	if (y==1) {contr="B";}
	if (y==2) {contr="C";}
	if (y==3) {contr="D";}
	if (y==4) {contr="E";}
	if (y==5) {contr="F";}
	if (y==6) {contr="G";}
	if (y==7) {contr="H";}
	if (y==8) {contr="I";}
	if (y==9) {contr="J";}
	if (y==10) {contr="K";}
	if (y==11) {contr="L";}
	if (y==12) {contr="M";}
	if (y==13) {contr="N";}
	if (y==14) {contr="O";}
	if (y==15) {contr="P";}
	if (y==16) {contr="Q";}
	if (y==17) {contr="R";}
	if (y==18) {contr="S";}
	if (y==19) {contr="T";}
	if (y==20) {contr="U";}
	if (y==21) {contr="V";}
	if (y==22) {contr="W";}
	if (y==23) {contr="X";}
	if (y==24) {contr="Y";}
	if (y==25) {contr="Z";}
	if ( s.charAt(15) != contr.charAt(0) ) {
		return false;
	} else {
		return true;
	}
}

// JavaScript Calendar Component
// Author: Robert W. Husted  (robert.husted@iname.com)
// Date:   8/22/1999
// Modified Date: 11/30/1999
// Modified By:   Robert W. Husted
// Notes:  Added frameset support (changed reference for "newWin" to "top.newWin")
//         Also changed Spanish "March" from "Marcha" to "Marzo"
//         Fixed JavaScript Date Anomaly affecting days > 28
// 
// 
// 
// Usage:  Add the following lines of code to your page to enable the Calendar
//         component.
//
//
//         // THIS LINE LOADS THE JS LIBRARY FOR THE CALENDAR COMPONENT 
//
//         <SCRIPT LANGUAGE="JavaScript" SRC="calendar.js"></SCRIPT>
//
//
//
//         // THIS LINE IS USED IN CONJUNCTION WITH A FORM FIELD (myDateField) IN A FORM (myForm).
//         // Replace "myForm" and "myDateField" WITH THE NAME OF YOUR FORM AND INPUT FIELD RESPECTIVELY
//         // WINDOW OPTIONS SET THE WIDTH, HEIGHT, AND X/Y POSITION OF THE CALENDAR WINDOW 
//         // WITH TITLEBAR ON, ALL OTHER OPTIONS (TOOLBARS, ETC) ARE DISABLED BY DEFAULT
//
//         <A HREF="javascript:doNothing()" onClick="setDateField(document.myForm.myDateField);top.newWin = window.open('calendar.html','cal','dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes')">
//         <IMG SRC="calendar.gif" BORDER=0></A><font size=1>Popup Calendar</font>
//
//
// 
// Required Files:
//
//         calendar.js   - contains all JavaScript functions to make the calendar work
//
//         calendar.html - frameset document (not required if you call the showCalendar()
//                         function.  However, calling showCalendar() directly causes
//                         the Java Virtual Machine (JVM) to start which slows down the
//                         loading of the calendar.)
//
// 
// Files Generally Included:
//
//         calendar.gif  - image that looks like a little calendar
// 
//         yourPage.html - page that contains a form and a date field which implements 
//                         the calendar component
// 



// BEGIN USER-EDITABLE SECTION -----------------------------------------------------



// SPECIFY DATE FORMAT RETURNED BY THIS CALENDAR
// (THIS IS ALSO THE DATE FORMAT RECOGNIZED BY THIS CALENDAR)

// DATE FORMAT OPTIONS:
//
// dd   = 1 or 2-digit Day
// DD   = 2-digit Day
// mm   = 1 or 2-digit Month
// MM   = 2-digit Month
// yy   = 2-digit Year
// YY   = 4-digit Year
// yyyy = 4-digit Year
// month   = Month name in lowercase letters
// Month   = Month name in initial caps
// MONTH   = Month name in captital letters
// mon     = 3-letter month abbreviation in lowercase letters
// Mon     = 3-letter month abbreviation in initial caps
// MON     = 3-letter month abbreviation in uppercase letters
// weekday = name of week in lowercase letters
// Weekday = name of week in initial caps
// WEEKDAY = name of week in uppercase letters
// wkdy    = 3-letter weekday abbreviation in lowercase letters
// Wkdy    = 3-letter weekday abbreviation in initial caps
// WKDY    = 3-letter weekday abbreviation in uppercase letters
//
// Examples:
//
// calDateFormat = "mm/dd/yy";
// calDateFormat = "Weekday, Month dd, yyyy";
// calDateFormat = "wkdy, mon dd, yyyy";
// calDateFormat = "DD.MM.YY";     // FORMAT UNSUPPORTED BY JAVASCRIPT -- REQUIRES CUSTOM PARSING
//

//calDateFormat    = "mm/dd/yyyy"; 
//calDateFormat    = "MM.DD.YY"; 
calDateFormat    = "DD/MM/YY"; 


// CALENDAR COLORS
topBackground    = "white";         // BG COLOR OF THE TOP FRAME
bottomBackground = "white";         // BG COLOR OF THE BOTTOM FRAME
tableBGColor     = "black";         // BG COLOR OF THE BOTTOM FRAME'S TABLE
cellColor        = "lightgrey";     // TABLE CELL BG COLOR OF THE DATE CELLS IN THE BOTTOM FRAME
headingCellColor = "white";         // TABLE CELL BG COLOR OF THE WEEKDAY ABBREVIATIONS
headingTextColor = "black";         // TEXT COLOR OF THE WEEKDAY ABBREVIATIONS
dateColor        = "blue";          // TEXT COLOR OF THE LISTED DATES (1-28+)
focusColor       = "#ff0000";       // TEXT COLOR OF THE SELECTED DATE (OR CURRENT DATE)
hoverColor       = "darkred";       // TEXT COLOR OF A LINK WHEN YOU HOVER OVER IT
fontStyle        = "12pt arial, helvetica";           // TEXT STYLE FOR DATES
headingFontStyle = "bold 12pt arial, helvetica";      // TEXT STYLE FOR WEEKDAY ABBREVIATIONS

// FORMATTING PREFERENCES
bottomBorder  = false;        // TRUE/FALSE (WHETHER TO DISPLAY BOTTOM CALENDAR BORDER)
tableBorder   = 0;            // SIZE OF CALENDAR TABLE BORDER (BOTTOM FRAME) 0=none



// END USER-EDITABLE SECTION -------------------------------------------------------



// DETERMINE BROWSER BRAND
var isNav = false;
var isIE  = false;

// ASSUME IT'S EITHER NETSCAPE OR MSIE
if (navigator.appName == "Netscape") {
    isNav = true;
}
else {
    isIE = true;
}

// GET CURRENTLY SELECTED LANGUAGE
selectedLanguage = navigator.language;

// PRE-BUILD PORTIONS OF THE CALENDAR WHEN THIS JS LIBRARY LOADS INTO THE BROWSER
buildCalParts();



// CALENDAR FUNCTIONS BEGIN HERE ---------------------------------------------------


function loadToday()
{
  var _info = navigator.userAgent
  var os = _info.indexOf("Mac")
  if( os != "-1")
  {
     setToday();
  }
  return;
}



// SET THE INITIAL VALUE OF THE GLOBAL DATE FIELD
function setDateField(dateField) {

    // ASSIGN THE INCOMING FIELD OBJECT TO A GLOBAL VARIABLE
    calDateField = dateField;

    // GET THE VALUE OF THE INCOMING FIELD
    inDate = dateField.value;

    // SET calDate TO THE DATE IN THE INCOMING FIELD OR DEFAULT TO TODAY'S DATE
    setInitialDate();

    // THE CALENDAR FRAMESET DOCUMENTS ARE CREATED BY JAVASCRIPT FUNCTIONS
    calDocTop    = buildTopCalFrame();
    calDocBottom = buildBottomCalFrame();
}


// SET THE INITIAL CALENDAR DATE TO TODAY OR TO THE EXISTING VALUE IN dateField
function setInitialDate() {
   
    // CREATE A NEW DATE OBJECT (WILL GENERALLY PARSE CORRECT DATE EXCEPT WHEN "." IS USED AS A DELIMITER)
    // (THIS ROUTINE DOES *NOT* CATCH ALL DATE FORMATS, IF YOU NEED TO PARSE A CUSTOM DATE FORMAT, DO IT HERE)
    calDate = new Date(inDate);

    // IF THE INCOMING DATE IS INVALID, USE THE CURRENT DATE
    if (isNaN(calDate)) {

        // ADD CUSTOM DATE PARSING HERE
        // IF IT FAILS, SIMPLY CREATE A NEW DATE OBJECT WHICH DEFAULTS TO THE CURRENT DATE
        calDate = new Date();
    }
	//RESETTA TUTTO
	calDate = new Date();
	
    // KEEP TRACK OF THE CURRENT DAY VALUE
    calDay  = calDate.getDate();

    // SET DAY VALUE TO 1... TO AVOID JAVASCRIPT DATE CALCULATION ANOMALIES
    // (IF THE MONTH CHANGES TO FEB AND THE DAY IS 30, THE MONTH WOULD CHANGE TO MARCH
    //  AND THE DAY WOULD CHANGE TO 2.  SETTING THE DAY TO 1 WILL PREVENT THAT)
    calDate.setDate(1);
}


// POPUP A WINDOW WITH THE CALENDAR IN IT
function showCalendar(dateField) {
	var winPrefs='dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes,resizable=yes,status=yes';
    // SET INITIAL VALUE OF THE DATE FIELD AND CREATE TOP AND BOTTOM FRAMES
    setDateField(dateField);

    // USE THE JAVASCRIPT-GENERATED DOCUMENTS (calDocTop, calDocBottom) IN THE FRAMESET
    calDocFrameset = 
        "<HTML><HEAD><TITLE>JavaScript Calendar</TITLE></HEAD>\n" +
        "<FRAMESET ROWS='70,*' FRAMEBORDER='0'>\n" +
        "  <FRAME NAME='topCalFrame' SRC='javascript:parent.opener.calDocTop' SCROLLING='no'>\n" +
        "  <FRAME NAME='bottomCalFrame' SRC='javascript:parent.opener.calDocBottom' SCROLLING='no'>\n" +
        "</FRAMESET>\n";

    // DISPLAY THE CALENDAR IN A NEW POPUP WINDOW
    top.newWin = window.open("javascript:parent.opener.calDocFrameset", "calWin", winPrefs);
    top.newWin.focus();
}


// CREATE THE TOP CALENDAR FRAME
function buildTopCalFrame() {

    // CREATE THE TOP FRAME OF THE CALENDAR
    var calDoc =
        "<HTML>" +
        "<HEAD>" +
        "</HEAD>" +
        "<BODY BGCOLOR='" + topBackground + "' onLoad='window.focus()'>" +
        "<FORM NAME='calControl' onSubmit='return false;'>" +
        "<CENTER>" +
        "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0>" +
        "<TR><TD COLSPAN=7>" +
        "<CENTER>" +
        getMonthSelect() +
        "<INPUT NAME='year' VALUE='" + calDate.getFullYear() + "'TYPE=TEXT SIZE=4 MAXLENGTH=4 onChange='parent.opener.setYear()'>" +
        "<a href='javascript:void(0)'>Vai</a>" +
        "</CENTER>" +
        "</TD>" +
        "</TR>" +
        "<TR>" +
        "<TD COLSPAN=7>" +
        "<INPUT " +
        "TYPE=BUTTON NAME='previousYear' VALUE='<<'    onClick='parent.opener.setPreviousYear()'><INPUT " +
        "TYPE=BUTTON NAME='previousMonth' VALUE=' < '   onClick='parent.opener.setPreviousMonth()'><INPUT " +
        "TYPE=BUTTON NAME='today' VALUE='Oggi' onClick='parent.opener.setToday()'><INPUT " +
        "TYPE=BUTTON NAME='nextMonth' VALUE=' > '   onClick='parent.opener.setNextMonth()'><INPUT " +
        "TYPE=BUTTON NAME='nextYear' VALUE='>>'    onClick='parent.opener.setNextYear()'>" +
        "</TD>" +
        "</TR>" +
        "</TABLE>" +
        "</CENTER>" +
        "</FORM>" +
        "</BODY>" +
        "</HTML>";

    return calDoc;
}


// CREATE THE BOTTOM CALENDAR FRAME 
// (THE MONTHLY CALENDAR)
function buildBottomCalFrame() {       

    // START CALENDAR DOCUMENT
    var calDoc = calendarBegin;

    // GET MONTH, AND YEAR FROM GLOBAL CALENDAR DATE
    month   = calDate.getMonth();
    year    = calDate.getFullYear();


    // GET GLOBALLY-TRACKED DAY VALUE (PREVENTS JAVASCRIPT DATE ANOMALIES)
    day     = calDay;

    var i   = 0;

    // DETERMINE THE NUMBER OF DAYS IN THE CURRENT MONTH
    var days = getDaysInMonth();

    // IF GLOBAL DAY VALUE IS > THAN DAYS IN MONTH, HIGHLIGHT LAST DAY IN MONTH
    if (day > days) {
        day = days;
    }

    // DETERMINE WHAT DAY OF THE WEEK THE CALENDAR STARTS ON
    var firstOfMonth = new Date (year, month, 1);

    // GET THE DAY OF THE WEEK THE FIRST DAY OF THE MONTH FALLS ON
    var startingPos  = firstOfMonth.getDay();
    days += startingPos;

    // KEEP TRACK OF THE COLUMNS, START A NEW ROW AFTER EVERY 7 COLUMNS
    var columnCount = 0;

    // MAKE BEGINNING NON-DATE CELLS BLANK
    for (i = 0; i < startingPos; i++) {

        calDoc += blankCell;
	columnCount++;
    }

    // SET VALUES FOR DAYS OF THE MONTH
    var currentDay = 0;
    var dayType    = "weekday";

    // DATE CELLS CONTAIN A NUMBER
    for (i = startingPos; i < days; i++) {

	var paddingChar = "&nbsp;";

        // ADJUST SPACING SO THAT ALL LINKS HAVE RELATIVELY EQUAL WIDTHS
        if (i-startingPos+1 < 10) {
            padding = "&nbsp;&nbsp;";
        }
        else {
            padding = "&nbsp;";
        }

        // GET THE DAY CURRENTLY BEING WRITTEN
        currentDay = i-startingPos+1;

        // SET THE TYPE OF DAY, THE focusDay GENERALLY APPEARS AS A DIFFERENT COLOR
        if (currentDay == day) {
            dayType = "focusDay";
        }
        else {
            dayType = "weekDay";
        }

        // ADD THE DAY TO THE CALENDAR STRING
        calDoc += "<TD align=center bgcolor='" + cellColor + "'>" +
                  "<a class='" + dayType + "' href='javascript:parent.opener.returnDate(" + 
                  currentDay + ")'>" + padding + currentDay + paddingChar + "</a></TD>";

        columnCount++;

        // START A NEW ROW WHEN NECESSARY
        if (columnCount % 7 == 0) {
            calDoc += "</TR><TR>";
        }
    }

    // MAKE REMAINING NON-DATE CELLS BLANK
    for (i=days; i<42; i++)  {

        calDoc += blankCell;
	columnCount++;

        // START A NEW ROW WHEN NECESSARY
        if (columnCount % 7 == 0) {
            calDoc += "</TR>";
            if (i<41) {
                calDoc += "<TR>";
            }
        }
    }

    // FINISH THE NEW CALENDAR PAGE
    calDoc += calendarEnd;

    // RETURN THE COMPLETED CALENDAR PAGE
    return calDoc;
}


// WRITE THE MONTHLY CALENDAR TO THE BOTTOM CALENDAR FRAME
function writeCalendar() {

    // CREATE THE NEW CALENDAR FOR THE SELECTED MONTH & YEAR
    calDocBottom = buildBottomCalFrame();

    // WRITE THE NEW CALENDAR TO THE BOTTOM FRAME
    top.newWin.frames['bottomCalFrame'].document.open();
    top.newWin.frames['bottomCalFrame'].document.write(calDocBottom);
    top.newWin.frames['bottomCalFrame'].document.close();
}


// SET THE CALENDAR TO TODAY'S DATE AND DISPLAY THE NEW CALENDAR
function setToday() {

    // SET GLOBAL DATE TO TODAY'S DATE
    calDate = new Date();

    // SET DAY MONTH AND YEAR TO TODAY'S DATE
    var month = calDate.getMonth();
    var year  = calDate.getFullYear();

    // SET MONTH IN DROP-DOWN LIST
    top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;

    // SET YEAR VALUE
    top.newWin.frames['topCalFrame'].document.calControl.year.value = year;

    // DISPLAY THE NEW CALENDAR
    writeCalendar();
}


// SET THE GLOBAL DATE TO THE NEWLY ENTERED YEAR AND REDRAW THE CALENDAR
function setYear() {

    // GET THE NEW YEAR VALUE
    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;

    // IF IT'S A FOUR-DIGIT YEAR THEN CHANGE THE CALENDAR
    if (isFourDigitYear(year)) {
        calDate.setFullYear(year);
        writeCalendar();
    }
    else {
        // HIGHLIGHT THE YEAR IF THE YEAR IS NOT FOUR DIGITS IN LENGTH
        top.newWin.frames['topCalFrame'].document.calControl.year.focus();
        top.newWin.frames['topCalFrame'].document.calControl.year.select();
    }
}


// SET THE GLOBAL DATE TO THE SELECTED MONTH AND REDRAW THE CALENDAR
function setCurrentMonth() {

    // GET THE NEWLY SELECTED MONTH AND CHANGE THE CALENDAR ACCORDINGLY
    var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;

    calDate.setMonth(month);
    writeCalendar();
}


// SET THE GLOBAL DATE TO THE PREVIOUS YEAR AND REDRAW THE CALENDAR
function setPreviousYear() {

    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;

    if (isFourDigitYear(year) && year > 1000) {
        year--;
        calDate.setFullYear(year);
        top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
        writeCalendar();
    }
}


// SET THE GLOBAL DATE TO THE PREVIOUS MONTH AND REDRAW THE CALENDAR
function setPreviousMonth() {

    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
    if (isFourDigitYear(year)) {
        var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;

        // IF MONTH IS JANUARY, SET MONTH TO DECEMBER AND DECREMENT THE YEAR
        if (month == 0) {
            month = 11;
            if (year > 1000) {
                year--;
                calDate.setFullYear(year);
                top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
            }
        }
        else {
            month--;
        }
        calDate.setMonth(month);
        top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;
        writeCalendar();
    }
}


// SET THE GLOBAL DATE TO THE NEXT MONTH AND REDRAW THE CALENDAR
function setNextMonth() {

    var year = top.newWin.frames['topCalFrame'].document.calControl.year.value;

    if (isFourDigitYear(year)) {
        var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;

        // IF MONTH IS DECEMBER, SET MONTH TO JANUARY AND INCREMENT THE YEAR
        if (month == 11) {
            month = 0;
            year++;
            calDate.setFullYear(year);
            top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
        }
        else {
            month++;
        }
        calDate.setMonth(month);
        top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;
        writeCalendar();
    }
}


// SET THE GLOBAL DATE TO THE NEXT YEAR AND REDRAW THE CALENDAR
function setNextYear() {

    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
    if (isFourDigitYear(year)) {
        year++;
        calDate.setFullYear(year);
        top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
        writeCalendar();
    }
}


// GET NUMBER OF DAYS IN MONTH
function getDaysInMonth()  {

    var days;
    var month = calDate.getMonth()+1;
    var year  = calDate.getFullYear();

    // RETURN 31 DAYS
    if (month==1 || month==3 || month==5 || month==7 || month==8 ||
        month==10 || month==12)  {
        days=31;
    }
    // RETURN 30 DAYS
    else if (month==4 || month==6 || month==9 || month==11) {
        days=30;
    }
    // RETURN 29 DAYS
    else if (month==2)  {
        if (isLeapYear(year)) {
            days=29;
        }
        // RETURN 28 DAYS
        else {
            days=28;
        }
    }
    return (days);
}


// CHECK TO SEE IF YEAR IS A LEAP YEAR
function isLeapYear (Year) {

    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
        return (true);
    }
    else {
        return (false);
    }
}


// ENSURE THAT THE YEAR IS FOUR DIGITS IN LENGTH
function isFourDigitYear(year) {

    if (year.length != 4) {
        top.newWin.frames['topCalFrame'].document.calControl.year.value = calDate.getFullYear();
        top.newWin.frames['topCalFrame'].document.calControl.year.select();
        top.newWin.frames['topCalFrame'].document.calControl.year.focus();
    }
    else {
        return true;
    }
}


// BUILD THE MONTH SELECT LIST
function getMonthSelect() {

    // BROWSER LANGUAGE CHECK DONE PREVIOUSLY (navigator.language())
    // FIRST TWO CHARACTERS OF LANGUAGE STRING SPECIFIES THE LANGUAGE
    // (THE LAST THREE OPTIONAL CHARACTERS SPECIFY THE LANGUAGE SUBTYPE)
    // SET THE NAMES OF THE MONTH TO THE PROPER LANGUAGE (DEFAULT TO ENGLISH)

    // IF FRENCH
    if (selectedLanguage == "fr") {
        monthArray = new Array('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin',
                               'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
    }
    // IF GERMAN
    else if (selectedLanguage == "de") {
        monthArray = new Array('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
                               'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
    }
    // IF ENGLISH
    else if (selectedLanguage == "en") {
        monthArray = new Array('January', 'February', 'March', 'April', 'May', 'June',
                               'July', 'August', 'September', 'October', 'November', 'December');
    }
    // IF SPANISH
    else if (selectedLanguage == "es") {
        monthArray = new Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
                               'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
    }
    // DEFAULT TO ITALIAN
    else {
        monthArray = new Array('Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno',
                               'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre');
    }

    // DETERMINE MONTH TO SET AS DEFAULT
    var activeMonth = calDate.getMonth();

    // START HTML SELECT LIST ELEMENT
    monthSelect = "<SELECT NAME='month' onChange='parent.opener.setCurrentMonth()'>";

    // LOOP THROUGH MONTH ARRAY
    for (i in monthArray) {
        
        // SHOW THE CORRECT MONTH IN THE SELECT LIST
        if (i == activeMonth) {
            monthSelect += "<OPTION SELECTED>" + monthArray[i] + "\n";
        }
        else {
            monthSelect += "<OPTION>" + monthArray[i] + "\n";
        }
    }
    monthSelect += "</SELECT>";

    // RETURN A STRING VALUE WHICH CONTAINS A SELECT LIST OF ALL 12 MONTHS
    return monthSelect;
}


// SET DAYS OF THE WEEK DEPENDING ON LANGUAGE
function createWeekdayList() {

    // IF FRENCH
    if (selectedLanguage == "fr") {
        weekdayList  = new Array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
        weekdayArray = new Array('Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa');
    }
    // IF GERMAN
    else if (selectedLanguage == "de") {
        weekdayList  = new Array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag');
        weekdayArray = new Array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa');
    }
    // IF SPANISH
    else if (selectedLanguage == "es") {
        weekdayList  = new Array('Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado')
        weekdayArray = new Array('Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa');
    }
    // IF ENGLISH
    else if (selectedLanguage == "es") {
        weekdayList  = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
        weekdayArray = new Array('Su','Mo','Tu','We','Th','Fr','Sa');
    }
    else {
        weekdayList  = new Array('Domenica', 'Lunedi', 'Martedi', 'Mercoledi', 'Giovedi', 'Venerdi', 'Sabato');
        weekdayArray = new Array('Do','Lu','Ma','Me','Gi','Ve','Sa');
    }

    // START HTML TO HOLD WEEKDAY NAMES IN TABLE FORMAT
    var weekdays = "<TR BGCOLOR='" + headingCellColor + "'>";

    // LOOP THROUGH WEEKDAY ARRAY
    for (i in weekdayArray) {

        weekdays += "<TD class='heading' align=center>" + weekdayArray[i] + "</TD>";
    }
    weekdays += "</TR>";

    // RETURN TABLE ROW OF WEEKDAY ABBREVIATIONS TO DISPLAY ABOVE THE CALENDAR
    return weekdays;
}


// PRE-BUILD PORTIONS OF THE CALENDAR (FOR PERFORMANCE REASONS)
function buildCalParts() {

    // GENERATE WEEKDAY HEADERS FOR THE CALENDAR
    weekdays = createWeekdayList();

    // BUILD THE BLANK CELL ROWS
    blankCell = "<TD align=center bgcolor='" + cellColor + "'>&nbsp;&nbsp;&nbsp;</TD>";

    // BUILD THE TOP PORTION OF THE CALENDAR PAGE USING CSS TO CONTROL SOME DISPLAY ELEMENTS
    var styleSheet=
    calendarBegin =
        "<HTML>" +
        "<HEAD>" +
        // STYLESHEET DEFINES APPEARANCE OF CALENDAR
        "<STYLE type='text/css'>" +
        "<!--" +
        "TD.heading { text-decoration: none; color:" + headingTextColor + "; font: " + headingFontStyle + "; }" +
        //"A.focusDay:link { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
        //"A.focusDay:hover { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
        //"A.weekday:link { color: " + dateColor + "; text-decoration: none; font: " + fontStyle + "; }" +
        //"A.weekday:hover { color: " + hoverColor + "; font: " + fontStyle + "; }" +
        "-->" +
        "</STYLE>" +
        "</HEAD>" +
        "<BODY BGCOLOR='" + bottomBackground + "'" +
        "<CENTER>";

        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE TABLE OUTLINES PROPERLY
        if (isNav) {
            calendarBegin += 
                "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'><TR><TD>";
        }

        // BUILD WEEKDAY HEADINGS
        calendarBegin +=
            "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'>" +
            weekdays +
            "<TR>";


    // BUILD THE BOTTOM PORTION OF THE CALENDAR PAGE
    calendarEnd = "";

        // WHETHER OR NOT TO DISPLAY A THICK LINE BELOW THE CALENDAR
        if (bottomBorder) {
            calendarEnd += "<TR></TR>";
        }

        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE BORDERS PROPERLY
        if (isNav) {
            calendarEnd += "</TD></TR></TABLE>";
        }

        // END THE TABLE AND HTML DOCUMENT
        calendarEnd +=
            "</TABLE>" +
            "</CENTER>" +
            "</BODY>" +
            "</HTML>";
}


// REPLACE ALL INSTANCES OF find WITH replace
// inString: the string you want to convert
// find:     the value to search for
// replace:  the value to substitute
//
// usage:    jsReplace(inString, find, replace);
// example:  jsReplace("To be or not to be", "be", "ski");
//           result: "To ski or not to ski"
//
function jsReplace(inString, find, replace) {
    var outString = "";

    if (!inString) {
        return "";
    }

    // REPLACE ALL INSTANCES OF find WITH replace
    if (inString.indexOf(find) != -1) {
    	inString=inString+' ';
        // SEPARATE THE STRING INTO AN ARRAY OF STRINGS USING THE VALUE IN find
        t = inString.split(find);
		
        // JOIN ALL ELEMENTS OF THE ARRAY, SEPARATED BY THE VALUE IN replace
        outString=t.join(replace);
        outString=outString.substring(0,outString.length-1);
        return outString;
    }
    else {
        return inString;
    }
}


// JAVASCRIPT FUNCTION -- DOES NOTHING (USED FOR THE HREF IN THE CALENDAR CALL)
function doNothing() {
}


// ENSURE THAT VALUE IS TWO DIGITS IN LENGTH
function makeTwoDigit(inValue) {

    var numVal = parseInt(inValue, 10);

    // VALUE IS LESS THAN TWO DIGITS IN LENGTH
    if (numVal < 10) {

        // ADD A LEADING ZERO TO THE VALUE AND RETURN IT
        return("0" + numVal);
    }
    else {
        return numVal;
    }
}


// SET FIELD VALUE TO THE DATE SELECTED AND CLOSE THE CALENDAR WINDOW
function returnDate(inDay)
{

    // inDay = THE DAY THE USER CLICKED ON
    calDate.setDate(inDay);

    // SET THE DATE RETURNED TO THE USER
    var day           = calDate.getDate();
    var month         = calDate.getMonth()+1;
    var year          = calDate.getFullYear();
    var monthString   = monthArray[calDate.getMonth()];
    var monthAbbrev   = monthString.substring(0,3);
    var weekday       = weekdayList[calDate.getDay()];
    var weekdayAbbrev = weekday.substring(0,3);

    outDate = calDateFormat;

    // RETURN TWO DIGIT DAY
    if (calDateFormat.indexOf("DD") != -1) {
        day = makeTwoDigit(day);
        outDate = jsReplace(outDate, "DD", day);
    }
    // RETURN ONE OR TWO DIGIT DAY
    else if (calDateFormat.indexOf("dd") != -1) {
        outDate = jsReplace(outDate, "dd", day);
    }

    // RETURN TWO DIGIT MONTH
    if (calDateFormat.indexOf("MM") != -1) {
        month = makeTwoDigit(month);
        outDate = jsReplace(outDate, "MM", month);
    }
    // RETURN ONE OR TWO DIGIT MONTH
    else if (calDateFormat.indexOf("mm") != -1) {
        outDate = jsReplace(outDate, "mm", month);
    }

    // RETURN FOUR-DIGIT YEAR
    if (calDateFormat.indexOf("yyyy") != -1) {
        outDate = jsReplace(outDate, "yyyy", year);
    }
    // RETURN TWO-DIGIT YEAR
    else if (calDateFormat.indexOf("yy") != -1) {
        var yearString = "" + year;
        var yearString = yearString.substring(2,4);
        outDate = jsReplace(outDate, "yy", yearString);
    }
    // RETURN FOUR-DIGIT YEAR
    else if (calDateFormat.indexOf("YY") != -1) {
        outDate = jsReplace(outDate, "YY", year);
    }

    // RETURN DAY OF MONTH (Initial Caps)
    if (calDateFormat.indexOf("Month") != -1) {
        outDate = jsReplace(outDate, "Month", monthString);
    }
    // RETURN DAY OF MONTH (lowercase letters)
    else if (calDateFormat.indexOf("month") != -1) {
        outDate = jsReplace(outDate, "month", monthString.toLowerCase());
    }
    // RETURN DAY OF MONTH (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("MONTH") != -1) {
        outDate = jsReplace(outDate, "MONTH", monthString.toUpperCase());
    }

    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat.indexOf("Mon") != -1) {
        outDate = jsReplace(outDate, "Mon", monthAbbrev);
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat.indexOf("mon") != -1) {
        outDate = jsReplace(outDate, "mon", monthAbbrev.toLowerCase());
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("MON") != -1) {
        outDate = jsReplace(outDate, "MON", monthAbbrev.toUpperCase());
    }

    // RETURN WEEKDAY (Initial Caps)
    if (calDateFormat.indexOf("Weekday") != -1) {
        outDate = jsReplace(outDate, "Weekday", weekday);
    }
    // RETURN WEEKDAY (lowercase letters)
    else if (calDateFormat.indexOf("weekday") != -1) {
        outDate = jsReplace(outDate, "weekday", weekday.toLowerCase());
    }
    // RETURN WEEKDAY (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("WEEKDAY") != -1) {
        outDate = jsReplace(outDate, "WEEKDAY", weekday.toUpperCase());
    }

    // RETURN WEEKDAY 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat.indexOf("Wkdy") != -1) {
        outDate = jsReplace(outDate, "Wkdy", weekdayAbbrev);
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat.indexOf("wkdy") != -1) {
        outDate = jsReplace(outDate, "wkdy", weekdayAbbrev.toLowerCase());
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("WKDY") != -1) {
        outDate = jsReplace(outDate, "WKDY", weekdayAbbrev.toUpperCase());
    }

    // SET THE VALUE OF THE FIELD THAT WAS PASSED TO THE CALENDAR
    calDateField.value = outDate;
    

    // GIVE FOCUS BACK TO THE DATE FIELD
    calDateField.focus();

    // CLOSE THE CALENDAR WINDOW
    top.newWin.close()
}
///////////
/////////// END OF JavaScript Calendar Component
/////////// END OF Author: Robert W. Husted  (robert.husted@iname.com)
/////////// END OF Date:   8/22/1999


/** function getElement from phpMyAdmin project (http://sourceforge.net/projects/phpmyadmin/) */
function getElement(e,f){
	if(document.layers) {
		f=(f)?f:self;
		if(f.document.layers[e]) { return f.document.layers[e];	}
		for(W=0;i<f.document.layers.length;W++) { return(getElement(e,f.document.layers[W])); }
	}
	if(document.all) { return document.all[e]; }
	return document.getElementById(e);
}

//funzione che cambia gli stili per simulare i tab
function cambia(mioid,arrayIdMenu) {
	getElement(mioid).className = 'TABtd1';
	getElement(mioid+'_tab').className = 'TABtable1';
	for(i=0;i<arrayIdMenu.length;i++) {
		if (arrayIdMenu[i]!=mioid) {
			getElement(arrayIdMenu[i]).className = 'TABtd0';
 			getElement(arrayIdMenu[i]+'_tab').className = 'TABtable0';
 		}
	}
}