// system1.0
// --------------------

// imposta variabile di controllo avvenuto caricamento
var system = 1;

// verifica avvenuto caricamento delle librerie necessarie
// -------------------------------------------------------
if (typeof(checkBrowser)=="undefined") alert("Attenzione!\n--------------\n La libreria \"system\" necessita della libreria \"checkBrowser\".");
if (typeof(strings)=="undefined") alert("Attenzione!\n--------------\n La libreria \"system\" necessita della libreria \"strings\".");

// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// system utility (inizio Codice)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var page = new Object(); // ** variabile globale. Contiene le dimensioni della pagina
	page.X = 0; 
	page.Y = 0; 

function getPageSize()
{
	// --------------------------------
	// Legge le dimensioni della pagina
	// --------------------------------
	var temp = new String();
	temp = clientBrowser();
	if (temp=='netscape4.x' || temp=='netscape6.x')
	{
		page.X = window.innerWidth;
		page.Y = window.innerHeight;
	}
	else
	{
		page.X = document.body.clientWidth;
		page.Y = document.body.clientHeight;
	};
};

function getName(nameString)
{
	// -------------------------------------
	// Dato un campo di  tipo file estrapola
	// dall'intero percorso il nome del file
	// -------------------------------------
var puntatore;
puntatore=0;
for (var scansione = 0; scansione < nameString.length; scansione++)
	{
		if (nameString.substring(scansione,scansione+1)=="\\" || nameString.substring(scansione,scansione+1)=="/")
		{ puntatore=scansione;}
	};
return nameString.substring(puntatore+1,nameString.length);
};

var inc=0;
function showPopUp(pageName, pageWidth, pageHeight)
{inc ++;
	// -----------------------------------
	// Usata per aprire finestra di pop-up
	// -----------------------------------
	var posX, posY;
	var winName = new String();
	posX = 0;
	posY = 0;
	winName="popup"+inc;
	if (navigator.appName!="Netscape")
	{
		window.open( pageName, winName, "toolbar=no,scrollbars=auto,directories=no,menubar=no,width="+pageWidth+",height="+pageHeight+",left="+posX+",top="+posY+",resizable=yes" );
	}
	else
	{
		window.open( pageName, winName, "toolbar=no,scrollbars=auto,directories=no,menubar=no,width="+pageWidth+",height="+pageHeight+",screenX="+posX+",screenY="+posY+",resizable=yes" );
	};
};

function showImgPopUp(img, imageWidth, imageHeight, popUpTitle) {
	var popTxt = "";
	popTxt += "<html> \n";
	popTxt += "<head> \n";
	if (popUpTitle=="") { popTxt += "<title></title> \n"; }
	else {                popTxt += "<title>" + popUpTitle + "</title> \n"; };
	popTxt += "</head> \n";
	popTxt += "<BODY leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" bgcolor=\"#ffffff\"> \n";
	popTxt += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100%\"> \n";
	popTxt += "<tr> \n";
	popTxt += "<td align=\"center\" valign=\"top\"> \n";
	popTxt += "	<a href=\"javascript: window.self.close();\"><img src=\"" + img + "\" border=\"0\"></a> \n";
	if (popUpTitle!="") { popTxt += "<div style='font-family:verdana;font-size:10px;text-align:center;color:#000000'>" + popUpTitle + "</div>"; };
	popTxt += "</td> \n";
	popTxt += "</tr> \n";
	popTxt += "</table> \n";
	popTxt += "</body> \n";
	popTxt += "</html> \n";
	if (popUpTitle!="") { imageHeight += 20; };
	hint_wnd = window.open("", "hint_wnd", "width=" + imageWidth + ", height=" + imageHeight + ", resizable=no, scrollbars=no" );
	hint_wnd.document.write(popTxt);
}

function getDate()
{
// ------------------------
// Ritorna la data espressa 
// nel  formato  "aaaammgg"
// ------------------------
	var giorno = new String();
	var mese = new String();
	var anno = new String();
	var data = new Date();
	if ((data.getDate())<10) giorno = "0" + (data.getDate()).toString();
	else giorno = (data.getDate()).toString();
	if ((data.getMonth()+1)<10) mese = "0" + (data.getMonth()+1).toString();
	else mese = (data.getMonth()+1).toString();
	anno = (data.getFullYear()).toString();
	return anno+mese+giorno;
};

function getHour()
// ----------------------
// Ritorna l'ora espressa
// nel  formato  "hhmmss"
// ----------------------
{
	var ora = new String();
	var minuti = new String();
	var secondi = new String();
	var data = new Date();
	if ((data.getHours())<10) ora = "0" + (data.getHours()).toString();
	else ora = (data.getHours()).toString();
	if ((data.getMinutes())<10) minuti = "0" + (data.getMinutes()).toString();
	else minuti = (data.getMinutes()).toString();
	if ((data.getSeconds())<10) secondi = "0" + (data.getSeconds()).toString();
	else secondi = (data.getSeconds()).toString();
	return ora+minuti+secondi;
};

function required_field(field_name) {
	// Restituisce   un  alert  di  avvertimento  di 
	// mancata compilazione di un campo obbligatorio
	alert("|  Attenzione!\n------------------------------------\n|  La compilazione del campo \n|\n|  --> "+field_name+" \n|\n|  e\' obbligatoria\n------------------------------------ "); 
	return false;
};

// Controlla la correttezza del codice fiscale
// -------------------------------------------
function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return "La lunghezza del codice fiscale non è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n";
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return "Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n";
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return "Il codice fiscale non è corretto:\n"+
			"il codice di controllo non corrisponde.\n";
	return "";
};


function ControllaPIVA(pi)
{
	if( pi == '' )  return '';
	if( pi.length != 11 )
		return "La lunghezza della partita IVA non è\n" +
			"corretta: la partita IVA dovrebbe essere lunga\n" +
			"esattamente 11 caratteri.\n";
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
			return "La partita IVA contiene un carattere non valido `" +
				pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
	}
	s = 0;
	for( i = 0; i <= 9; i += 2 )
		s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	for( i = 1; i <= 9; i += 2 ){
		c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
		if( c > 9 )  c = c - 9;
		s += c;
	}
	if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
		return "La partita IVA non è valida:\n" +
			"il codice di controllo non corrisponde.\n";
	return '';
};

function required(field_name) {
	// visualizza msg di errore e restituisce false
	var msg = new String();
	alert("Attenzione!\nIl campo \""+field_name+"\" è obbligatorio.");
	return false;
};

function check_date_format(dd, mm, yyyy) {
	// controlla la correttezza formale di una data espressa come dd mm yyyy
	var test = true;
	if (dd.length==0 && mm.length==0 && yyyy.length>0 ) { test=false; };
	if (dd.length==0 && mm.length>0  && yyyy.length==0) { test=false; };
	if (dd.length>0  && mm.length==0 && yyyy.length==0) { test=false; };
	if (dd.length>0  && mm.length>0  && yyyy.length==0) { test=false; };
	if (dd.length>0  && mm.length==0 && yyyy.length>0 ) { test=false; };
	if (dd.length==0 && mm.length>0  && yyyy.length>0 ) { test=false; };
	return test;
};

function showDate () {
	// restituisce la data di oggi (formato eng)
	var oggi = new Date();
	var d = oggi.getDay();
	var giorno = oggi.getDate();
	var anno = oggi.getYear();
	if (anno < 1000) anno += 1900;
	var m = oggi.getMonth();
	var today = "";
	var mon = "";
	
	if (d==0) today="Sunday";
	if (d==1) today="Monday";
	if (d==2) today="Tuesday";
	if (d==3) today="Wednesday";
	if (d==4) today="Thursday";
	if (d==5) today="Friday";
	if (d==6) today="Saturday";
	
	if (m==0) mon="January";
	if (m==1) mon="February";
	if (m==2) mon="March";
	if (m==3) mon="April";
	if (m==4) mon="May";
	if (m==5) mon="June";
	if (m==6) mon="July";
	if (m==7) mon="August";
	if (m==8) mon="September";
	if (m==9) mon="October";
	if (m==10) mon="November";
	if (m==11) mon="December";
	
	document.writeln ( today + ', ' + mon + ' ' + giorno + ' ' + anno );
};
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// system utility (fine Codice)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
