function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
   var d = getObject(szDivID);
	if(iState==1)
		d.style.display = 'block';
	if(iState==0)
		d.style.display = 'none';

	if(iState==2)
	{
		if(d.style.display == 'block')
			d.style.display = 'none';
		else
			d.style.display = 'block';
	}
}

function getObject(id) {
	var ie4 = false; if(document.all) { ie4 = true; }
	if (ie4) {
		return document.all[id]; } 
		else { return document.getElementById(id); } 
}

function GoToLink(combo) { 
	
	if (combo.options[combo.selectedIndex].value!="null")
		window.open(combo.options[combo.selectedIndex].value,"") 
} 

function openWindow(file,w,h){
	offx=40
	offy=100

//	l=(screen.width-w-offx)/1.1
//	t=(screen.height-h-offy)/2
	l=(screen.width-w)/2;
	t=(screen.height-h)/2-100;
	
	
	var a
	a = window.open(file, "_blank", "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,status=no,location=no,directories=no,copyhistory=no,height="+h+",width="+w+",left="+l+",top="+t)
}

function IsNumero(e) 
{
	if (!checkEuro(e)) {
		alert("Sono consentiti solo valori numerici e la virgola come separatore di decimali.")
		return false
	}
	else return true
}

// verfica che il singolo valore immesso sia un numero oppure una virgola (per l'EURO)
function checkEuro(e) 
{
	var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode
	//status = charCode // see ASCII character value!
	if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 44) return false
	else return true
}

function EuroFormat(ImportoEuro) 
{
	if (navigator.appName == "Netscape") {
		if (ImportoEuro<1) var intPart=parseInt(0)
		else var intPart=parseInt(ImportoEuro,10)
	}
	else var intPart = parseInt(ImportoEuro,10)
	var fractPart = Math.round((ImportoEuro - intPart) * 100)
	if(fractPart<10) fractPart = "0" + fractPart
	if(fractPart==100) {
		fractPart = 0
		intPart += 1
	}
	var intPartStr = ""
	var intPartTmp = new String(intPart)
	var j = 0
	for(i=intPartTmp.length;i>0;i--) {
		intPartStr = intPartTmp.substring(i-1,i) + intPartStr
		if(j==2 && i > 1) {
			intPartStr = "." + intPartStr
			j = 0
		}
		else j++
	}
	return intPartStr + "," + fractPart
}

function isEmail(EmailAddr)
{
	//EmailAddr = modulo.email.value;
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (Filtro.test(EmailAddr))
		return true;
	else
		return false;
}

function upperMe(field)
{
	if (field.value != field.value.toUpperCase()) field.value = field.value.toUpperCase()
}

function mostraMenu(menuCorrente) {
	if (document.getElementById) {
		questoMenu = document.getElementById(menuCorrente).style
		if (questoMenu.display == "block") {
			questoMenu.display = "none"
		}
		else {
			questoMenu.display = "block"
		}
		return false
	}
	else {
		return true
	}
}
function popImage(imageURL,imageTitle)
{
	PositionX = 50;
	PositionY = 50;
	defaultWidth  = 500;
	defaultHeight = 500;
	if (parseInt(navigator.appVersion.charAt(0))>=4)
	{
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
	}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document)
	{
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(500,500);');
		writeln('width=500-(document.body.clientWidth-document.images[0].width);');
		writeln('height=500-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		if (!true) writeln('</head><body bgcolor=ffffff scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=ffffff scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
		close();
	}
}