function newWindow(mypage,myname,w,h,features,center) 
	{

  	if ((screen.width) && center)
		{
		var winl = ((screen.width-w)/2) - 5;
		var wint = ((screen.height-h)/2) - 25;
  		}
  	else
  		{winl = 0; wint =0;}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += 'toolbar=no,'; 
	settings += 'scrollbars=no,'; 
	settings += 'location=no,';
	settings += 'status=no,';
	settings += 'resizable=no,';	
	settings += 'menubar=no,';
	settings += 'titlebar=no,';	
	settings += features;
	var win = window.open(mypage,myname,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
	
	return false;  
}

function getDiv(name) {
if (document.all) return document.all[name];
else if (document.getElementById) return(document.getElementById(name));
}

function Trim(TRIM_VALUE)
	{
	if(TRIM_VALUE.length < 1)
		{return"";}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
		{return "";}
	else
		{return TRIM_VALUE;}
	}
	
function RTrim(VALUE)
	{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
		{return"";}
	var iTemp = v_length -1;

	while(iTemp > -1)
		{if(VALUE.charAt(iTemp) == w_space)
			{}
		else
			{strTemp = VALUE.substring(0,iTemp +1);
			break;
			}
		iTemp = iTemp-1;
		}
	return strTemp;
	}
	
function LTrim(VALUE)
	{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
		{return"";}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;
	while(iTemp < v_length)
		{if(VALUE.charAt(iTemp) == w_space)
			{}
		else
			{strTemp = VALUE.substring(iTemp,v_length);
			break;
			}
		iTemp = iTemp + 1;
		}
	return strTemp;
	} 
	
	
	
function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    return typeof a == 'string';
}
function isUndefined(a) {
    return typeof a == 'undefined';
} 

function isDigitNoAlert(testValue)
	{
	var digits = "0123456789.,";
	
	for (var i=0;i<testValue.length;i++)
		{
		temp=testValue.substring(i,i+1);
		if (digits.indexOf(temp)==-1)
			{
			return false;
			}
		}
	return true;
	}

function replaceSpecials(oString)
{
    nString = new String(oString);	
    nString = nString.replace(/<!--([^>]|[^-]>|[^-]->)*-->/g, ' ');
    nString = nString.replace(/<[\/!]?[a-z]+\d*(\s+[a-z][a-z\-]*(=[^\s>"']*|="[^"]*"|='[^']*')?)*\s*(\s\/)?>/gi, ' ');
    nString = nString.replace(/[^\S ]+/g, ' ');
    nString = nString.replace(/&lt;/g, '<');
    nString = nString.replace(/&gt;/g, '\>');
    nString = nString.replace(/&nbsp;/g, ' ');
    nString = nString.replace(/&quot;/g, '\"');	
    nString = nString.replace(/&amp;/g, '\t');
    nString = nString.replace(/&#?\w+;/g, ' ');
    nString = nString.replace(/\t/g, '\&');
    nString = nString.replace(/ +/g, ' ');
    return nString;
}	

function removeBadCharacters(text) 
{
   if (text.replace) {
      return text.replace(/[<>\"\'%;\)\(&\+]/g, '');
   }
}

function invalidChars(text) 
{
	var invalidCharsReg = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=o; i<invalidCharsReg.length; i++)
		{
		if (text.indexOf(invalidCharsReg.charAt(i),0) > -1)
			{return false;}
		}
}


//-----------------------------------------------------------------------------
// Image Layer.
//-----------------------------------------------------------------------------

var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;
var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;

function getDiv(name) {
if (document.all) return document.all[name];
else if (document.getElementById) return(document.getElementById(name));
}


function getLayer1(name) {

  alert(isMinNS4);
  if (isMinNS4)
    return findLayer(name, document);
  if (isMinIE4)
    return eval('document.all.' + name);
  return null;
}

function findLayer(name, doc) {

  var i, layer;

  for (i = 0; i < doc.layers.length; i++) {
    layer = doc.layers[i];
    if (layer.name == name)
      return layer;
    if (layer.document.layers.length > 0)
      if ((layer = findLayer(name, layer.document)) != null)
        return layer;
  }
  return null;
}

//-----------------------------------------------------------------------------
// Image utilities.
//-----------------------------------------------------------------------------

function getImage(name) {

  if (isMinNS4) {
    return findImage(name, document);
  }
  if (isMinIE4)
    return eval('document.all.' + name);
  return null;
}

function findImage(name, doc) {

  var i, img;

  for (i = 0; i < doc.images.length; i++)
    if (doc.images[i].name == name)
      return doc.images[i];
  for (i = 0; i < doc.layers.length; i++)
    if ((img = findImage(name, doc.layers[i].document)) != null) {
      img.container = doc.layers[i];
      return img;
    }
  return null;
}


function getById(attr_id) {
 return(document.all[attr_id])
}

if(document.all && !document.getElementById)  document.getElementById = getById

function getByTagName(tag) {
/*---------------------------------------------
Prima convertiamo in maiuscole il parametro
tag (la proprietà tagName, che andremo ad
analizzare è infatti espressa in maiuscole).
---------------------------------------------*/
tag = tag.toUpperCase();


/*---------------------------------------------
Creiamo poi, un nuovo array relativo all'elemento
che chiama il metodo, qualora non sia già
presente
---------------------------------------------*/
if(!this["lista"+tag]) {
this["lista"+tag] = new Array()

/*---------------------------------------------
A questo punto scandiamo la collezione all
alla ricerca di quegli elementi caratterizzati
dall'avere il tag voluto (quello passato come
parametro della funzione), e li sistemiamo
nell'array appena creato.
---------------------------------------------*/
for(jtag=0,itag=0; jtag<this.all.length; jtag++) {
if(this.all[jtag].tagName == tag)
this["lista"+tag][itag++] = this.all[jtag]
}
}
/*---------------------------------------------
Restituiamo infine l'array
---------------------------------------------*/
return(this["lista"+tag])
}

if(document.all && !document.getElementsByTagName)
document.getElementsByTagName = getByTagName

for(ind=0; ind<document.all.length; ind++)
if(!document.all[ind].getElementsByTagName)
document.all[ind].getElementsByTagName = getByTagName


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 true;
	if( pi.length != 11 )
		/** return "La lunghezza della partita IVA non è\n" +
			"corretta: la partita IVA dovrebbe essere lunga\n" +
			"esattamente 11 caratteri.\n"; **/
		return false;
	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"; **/
			return false;
	}
	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 false;
	return true;
}