// system1.1
// --------------------

// 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)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function val_in_query_string(query_par, query_val, query_url)
{
	// posiziona nella url un parametro in query string...
	if (query_url.toLowerCase().indexOf(query_par+"=")!=-1)
	{
		// il parametro è già in queryString, devo solo cambiarne il valore...
		var tmp_str = query_url.substring(
			0
			, query_url.toLowerCase().indexOf(query_par) + query_par.length + 1
		);
		var tmp_str_2 = query_url.substring(
			tmp_str.length
			, query_url.length
		);
		if (tmp_str_2.indexOf("&")==-1)
		{
			tmp_str_2 = "";
		}
		else
		{
			tmp_str_2 = tmp_str_2.substring(tmp_str_2.indexOf("&")+1, tmp_str_2.length);
		};
		query_url = tmp_str + query_val + tmp_str_2;
	}
	else
	{
		// devo aggiungere il parametro in queryString
		if (query_url.toLowerCase().indexOf("?")==-1)
		{
			query_url = query_url + "?" + query_par + "=" + query_val;
		}
		else
		{
			query_url = query_url + "&" + query_par + "=" + query_val;			
		}
	}
	return query_url;
}

function query_string(field_name)
{
	// restituisce il valore del campo passato in GET
	var loc_str = document.location.href;
	var tmp_loc_str = loc_str.toLowerCase();
	var tmp_field_name = field_name.toLowerCase() + "=";
	if (tmp_loc_str.indexOf(tmp_field_name)==-1)
	{
		return "";
	}
	else
	{
		var start_ind = tmp_loc_str.indexOf(tmp_field_name) + tmp_field_name.length;
		var end_ind = tmp_loc_str.length;
		tmp_loc_str = tmp_loc_str.substring(start_ind, tmp_loc_str.length);
		if (tmp_loc_str.indexOf("&")!=-1)
		{
			end_ind = start_ind + tmp_loc_str.indexOf("&");
		};
		return unescape(loc_str.substring(start_ind, end_ind));
	};
}

function read_cookie(cookie_name)
{
	// Restituisce il valore del cookie cookie_name
	var res = new String();
	var all_cookie = document.cookie;
	var pos = all_cookie.indexOf(cookie_name+"=");
	if (pos==-1)
	{
		// Non c'è il cookie richiesto
		res = "";
	} else {
		all_cookie = all_cookie.substring((pos+cookie_name.length+1),all_cookie.length);
		if (all_cookie.indexOf(";")==-1) 
		{
			res = all_cookie.substring(0, all_cookie.length);
		}
		else
		{
			res = all_cookie.substring(0, all_cookie.indexOf(";"));
		};
	};
	return unescape(res);
}


function set_cookie (cookie_name, cookie_value, how_many_days)
{
	/*
	scrive il cookie di nome "cookie_name",
	assegnandogli il valore "cookie_value",
	per la validità di "how_many_days" giorni
	*/
	var this_year = new Date();
	this_year.setDate(this_year.getDate() + how_many_days);
	document.cookie = cookie_name + "=" + cookie_value + "; expires=" + this_year.toGMTString();
}


var page = new Object(); // ** variabile globale. Contiene le dimensioni della pagina
	page.X = 0; 
	page.Y = 0; 

/*
function getPageSize()
{
	// --------------------------------
	// Legge le dimensioni della pagina
	// --------------------------------
	if (window.innerWidth)
	{
		page.X = window.innerWidth; 
		page.Y = window.innerHeight; 
	}
	else
	if (document.documentElement)
	{
		page.X = document.documentElement.clientWidth;
		page.Y = document.documentElement.clientHeight;
	}
	else
	if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		page.X = document.body.clientWidth;
		page.Y = document.body.clientHeight;
	}
};
*/
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 getPageSizeWithScroll()
{
//ritorna le dimensioni della pagina con scroll
     if (window.innerHeight && window.scrollMaxY) 
     {// Firefox         
		 yWithScroll = window.innerHeight + window.scrollMaxY;         
		 xWithScroll = window.innerWidth + window.scrollMaxX;     
     } 
     else if (document.body.scrollHeight > document.body.offsetHeight)
     { // all but Explorer Mac         
		yWithScroll = document.body.scrollHeight;         
		xWithScroll = document.body.scrollWidth;     
	 } 
	 else 
	 { // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
		yWithScroll = document.body.offsetHeight;         
		xWithScroll = document.body.offsetWidth;       
	 }     
arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);     
//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );     
return arrayPageSizeWithScroll; 
} 

function getPage() {
//ritorna le dimensioni della pagina senza scroll	
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}

function getScrollXY() {
//ritorna le dimensioni dello scroll

  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

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 = (page.X-parseInt(pageWidth))/2;
	posY = (page.Y-parseInt(pageHeight))/2;
	winName="popup_win";
	if (navigator.appName!="Netscape")
	{
		window.open( pageName, "", "toolbar=no,scrollbars=yes,directories=no,menubar=no,width="+pageWidth+",height="+pageHeight+",left="+posX+",top="+posY+",resizable=yes" );
	}
	else
	{
		window.open( pageName, "", "toolbar=no,scrollbars=yes,directories=no,menubar=no,width="+pageWidth+",height="+pageHeight+",screenX="+posX+",screenY="+posY+",resizable=yes" );
	};
};

// dichiaro un livello da utilizzare per i pop-up
var pop_up_str = ""
+ "\n <div id='pop_up_lay' style='visibility:hidden; position:absolute; left:10px; top:10px'>"
+ "\n <table border='0' cellspacing='0' cellpadding='0' style='border:1px solid #000000; font-family:verdana; font-size:10px; background-color:#eeeeee'> "
+ "\n <tr>"
+ "\n <td style='padding:5px'>"
+ "\n <a style='border:1px solid #000000; padding:2px' href='#' onclick=\"document.getElementById('pop_up_lay').style['visibility']='hidden';\">x</a>"
+ "\n </td>"
+ "\n </tr>"
+ "\n <tr>"
+ "\n <td style='padding:5px'>"
+ "\n <a href='#' onclick=\"document.getElementById('pop_up_lay').style['visibility']='hidden';\"><img id='pop_up_img' style='border:1px #555555 solid' onload='pos_img_pop_up()' /></a>"
+ "\n <div style='padding:5px' id='pop_up_dida'></div>"
+ "\n </td>"
+ "\n </tr>"
+ "\n </table>"
+ "\n </div>";
document.write(pop_up_str);

function showImgPopUp2(img, imageWidth, imageHeight, popUpTitle, print_Y_N)
{
	document.getElementById("pop_up_img").src=img;
	document.getElementById("pop_up_lay").style["visibility"]="visible";
	document.getElementById("pop_up_dida").innerHTML = popUpTitle;
}

function pos_img_pop_up()
{
	getPageSize();
	document.getElementById("pop_up_lay").style["left"]=(xMousePos - ( getLayWidth("pop_up_lay") ));
	document.getElementById("pop_up_lay").style["top"]=(yMousePos - ( getLayHeight("pop_up_lay") ));
	if (parseInt(document.getElementById("pop_up_lay").style["left"])<5) { document.getElementById("pop_up_lay").style["left"] = "5"; };
	if (parseInt(document.getElementById("pop_up_lay").style["top"])<5) { document.getElementById("pop_up_lay").style["top"] = "5"; };
}

function showImgPopUp(img, imageWidth, imageHeight, popUpTitle, print_Y_N) {
	img = img.replace(/%20/gi, "%2520");
	var popTxt = "";
	popTxt += "<html> ";
	popTxt += "<head> ";
	if (popUpTitle=="") { popTxt += "<title></title> "; }
	else {                popTxt += "<title>" + popUpTitle + "</title> "; };
	popTxt += "</head> ";
	popTxt += "<BODY leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" bgcolor=\"#ffffff\" oncontextmenu=\"return false\" onselectstart=\"return false\" ondragstart=\"return false\"> ";
	popTxt += "<div id=\"Layer1\" style=\"position:absolute; z-index:1; left: 0px; top: 0px; width:" + imageWidth + "px; height:" + imageHeight + "px;\" onmouseover=\"this.style.cursor='hand'\" onclick=\"window.self.close()\">&nbsp;</div>";
	popTxt += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100%\"> ";
	popTxt += "<tr> ";
	popTxt += "<td align=\"center\" valign=\"top\"> ";
	popTxt += "	<a href=\"javascript: window.self.close();\"><img src=\"" + img + "\" width=\"" + imageWidth + "\" height=\"" + imageHeight + "\" border=\"0\" onerror=\"this.src='" + img.replace("disp_", "") + "'\"></a> ";
	if (popUpTitle!="") { popTxt += "<div style='font-family:verdana;font-size:10px;text-align:center;color:#000000'>" + popUpTitle + "</div>"; };
	popTxt += "</td> ";
	popTxt += "</tr> ";
	popTxt += "</table></div> ";
	popTxt += "</body> ";
	popTxt += "</html> ";

	if (popUpTitle!="") { imageHeight += 20; };
	if (typeof(hint_wnd)=="undefined" || hint_wnd.closed)
	{
		// finestra non aperta ...
		// faccio un'assegnamento fittizio alla fimestra per poi chiuderla....
		hint_wnd = window.open("", "hint_wnd", "width=" + imageWidth + ", height=" + imageHeight + ", resizable=no, scrollbars=no" );
		hint_wnd.self.close();
	}
	else
	{
		hint_wnd.self.close();
	};
	hint_wnd = window.open("", "hint_wnd", "width=" + imageWidth + ", height=" + imageHeight + ", resizable=no, scrollbars=no" );
	hint_wnd.document.write(popTxt);
	if (print_Y_N!=null && print_Y_N=="y") { // <-- si vuol stampare il pop-up
		hint_wnd.print(); 
		if (clientBrowser()=="explorer") { hint_wnd.document.location.reload(); }; // <-- per un qualche strano motivo, affinche explorer stampi il pop-up, bisogna ricaricare la pagina del pop-up medesimo... boh?
	};
}

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;
};

function maxSize(mytextarea, mysize) {
	if (mytextarea.value.length>mysize){
		mytextarea.value = mytextarea.value.substring(0,mysize);
	};
	window.status = mytextarea.value.length + " di " + mysize;
};

// 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 );
};

// Questo codice cattura la posizione del mouse
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		xMousePos = e.pageX;
		yMousePos = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		if (document.body)
		{
			xMousePos = e.clientX + document.body.scrollLeft;
			yMousePos = e.clientY + document.body.scrollTop;
		}
	}
	xMousePosMax = window.innerWidth+window.pageXOffset;
	yMousePosMax = window.innerHeight+window.pageYOffset;
}

function numb_precision(numb, prec)
{
	// arrotonda un num. in virgola mobile al num. di decimali specificato in prec.
	var myNumb = numb.toString();
	if (myNumb=="0" || myNumb=="")
	{
		myNumb="0.00";
	}
	else
	{
		myNumb = myNumb.replace(",",".");
		if (myNumb.indexOf(".")==-1)
		{
			myNumb += ".";
			for (var i=0; i<prec; i++) myNumb += "0";
		}
		else
		{
			var dec = myNumb.substring(myNumb.indexOf(".")+1, myNumb.length);
			if (dec.length<prec)
			{
				for (var i=0; i<(prec-dec.length); i++) dec += "0";
			}
			else if (dec.length>prec)
			{
				dec = Math.round(
					parseFloat(
						dec.substring(0,prec) + "." + dec.substring(prec, dec.length)
					)
				);
			};
			myNumb = myNumb.substring(0, myNumb.indexOf(".")+1) + dec;
		};
	};
	return myNumb;
}

function findPos(obj) {
	// restituisce un vettore (x, y) con la posizione assoluta dell'oggetto passato a parametro
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


function findPosX(obj)
{ 
	// ricava la posizione x di un oggetto...
	return findPos(obj)[0];
}

function findPosY(obj)
{ 
	// ricava la posizione y di un oggetto
	return findPos(obj)[1];
}

function findWidth(obj)
{ // ricava la larghezza di un oggetto...
	var width = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			width += obj.offsetWidth
			obj = obj.offsetParent;
		}
	}
	else if (obj.width)
		width += obj.width;
	return width;
}

function findHeight(obj)
{ // ricava l'altezza x di un oggetto...
	var height = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			height += obj.offsetHeight
			obj = obj.offsetParent;
		}
	}
	else if (obj.height)
		width += obj.height;
	return height;
}

function URLEncode( plaintext )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function URLDecode(encoded )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};

function checkForDouble(event)
{
	var unicode = event.charCode ? event.charCode : event.keyCode;
	if ((unicode>=48 && unicode<=57) || unicode==46) 
	{ 
		return true; 
	} 
	else 
	{ 
		return false; 
	};
}
function checkForInteger(event)
{
	var unicode = event.charCode ? event.charCode : event.keyCode;
	if (unicode>=48 && unicode<=57) 
	{ 
		return true; 
	} 
	else 
	{ 
		return false; 
	}; 
}

function checkForData(event)
{
	var unicode = event.charCode ? event.charCode : event.keyCode;
	if ((unicode>=48 && unicode<=57) || unicode==47) 
	{ 
		return true; 
	} 
	else 
	{ 
		return false; 
	}; 
}
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// system utility (fine Codice)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
