function newsletter(pp) {
		newsletterwin = window.open(pp+"mailing/default.asp", "Newsletter", "HEIGHT=300,WIDTH=500,status,resizable")
		newsletterwin.focus();
}

function svuota(campo) {
	campo.value=campo.value.replace(/^\s*/,'').replace(/\s*$/,'');
}

function isVuoto(campo,msg) {
	var theMsg
	if (msg!='')
		theMsg=msg+" ";
	else
		theMsg="Il campo "+campo.name+" deve essere compilato!";
	if (campo.value=='') {
		alert(theMsg);
		campo.focus();
		return true;
	}
	return false;
}
function badNumberLang(campo,msg)
{
	var str=campo.value
	if (str!='')
	{
		str=str.replace(/\d/gi,"")
		if (str!="")
		{
			alert(msg)
			campo.focus()
			campo.select()
			return true;
		}
	}
	return false
}
function isBadDate(campo) {
	var data=campo.value.replace(/[^-\d\.\/]/gi,'');
	data=data.replace(/-/gi,"/");
	data=data.replace(/\./gi,"/");
	if (data.indexOf("/")!=-1) {
		var vData=data.split("/");
		var d=new Date(vData[2],vData[1]-1,vData[0]);
		var ds=vData[0].replace(/^0*/,'')+"/"+vData[1].replace(/^0*/,'')+"/"+vData[2];
		if (ds!=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear()) {
			alert("Data non corretta!");
			campo.select();
			campo.focus();
			return true;
		}
	}
	else {
		if(data.length==8||data.length==6) {
			var gg=data.substr(0,2);
			var mm=data.substr(2,2);
			var yy=data.substr(4);
			if (yy.length==2) {
				yy="20"+yy;
			}
			var d=new Date(yy,mm-1,gg);
			var ds=gg.replace(/^0*/,'')+"/"+mm.replace(/^0*/,'')+"/"+yy;
			if (ds!=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear()) {
				alert("Data non corretta!");
				campo.select();
				campo.focus();
				return true;
			}
		}
		else {
			alert("Data non corretta");
			campo.select();
			campo.focus();
			return true;
		}
	}
	campo.value=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear();
	return false;
}

function isBadHour(campo) { 
	var ora=campo.value.replace(/[^\d:\.]/gi,'');
	ora=ora.replace(/\./gi,":");
	if (ora.indexOf(":")!=-1) {
		var vOra=ora.split(":");
		var o=new Date(2001,1,1,vOra[0],vOra[1]);
		var os=vOra[0].replace(/^0*/,'')+":"+vOra[1].replace(/^0*/,'');
//		alert(o.getHours()+":"+o.getMinutes())
//		alert((o.getHours()+"").replace(/^0*/,'')+":"+(o.getMinutes()+"").replace(/^0*/,''))
//		alert(os)
//		alert(o.getHours()+":"+o.getMinutes()!=os)
		if (os!=(o.getHours()+"").replace(/^0*/,'')+":"+(o.getMinutes()+"").replace(/^0*/,'')) {
			alert("Ora non corretta!!");
			campo.select();
			campo.focus();
			return true;
		}
	}
	else {
		if (ora.length==4) {
			var hh=ora.substr(0,2);
			var mm=ora.substr(2,2);
			var o=new Date(2001,1,1,hh,mm);
			var os=hh.replace(/^0*/,'')+":"+mm.replace(/^0*/,'');
			if (os!=(o.getHours()+"").replace(/^0*/,'')+":"+(o.getMinutes()+"").replace(/^0*/,'')) {
				alert("Ora non corretta!");
				campo.select();
				campo.focus();
				return true;
			}
		}
		else {
			alert("Ora non corretta!");
			campo.select();
			campo.focus();
			return true;
		}
	}

	var o_s="";
	if (10>o.getHours())
		o_s+="0";
	o_s+=o.getHours()+":";
	if (10>o.getMinutes())
		o_s+="0";
	o_s+=o.getMinutes();
//alert(o_s)
	campo.value=o_s;
	return false;
}

function maxL(campo,msg,ml) {
	if (campo.value.length>ml) {
		alert(msg+" puo' essere lungo al massimo "+ml+" caratteri.\nNe hai inseriti "+campo.value.length+".");
		campo.select();
		campo.focus();
		return true;
	}
	return false;
}

function maxLUsr(campo,msg,ml) {
	if (campo.value.length>ml) {
		var msgUsr = msg.replace('@@ml@@', ml).replace('@@len@@', campo.value.length)
		alert(msgUsr);
		campo.select();
		campo.focus();
		return true;
	}
	return false;
}

vImg=new Array();
function preLoad(nome,src1,src2)
{
	vImg[nome+"n"]=new Image();
	vImg[nome+"n"].src=src1;
	vImg[nome+"o"]=new Image();
	vImg[nome+"o"].src=src2;
}
function hiLite(img,modo)
{
	document.images[img].src=vImg[img+modo].src
}

function winOpen(theURL,winName,features)
{
  var w=window.open(theURL,winName,features);
  w.focus()
}
function detail(info)
{
	detailWin = window.open("preview.asp", "detail", "HEIGHT=300,WIDTH=500,status,resizable")
	detailWin.focus();
	document.preview.info.value=info
	document.preview.submit()
}
function roteaImg(ri_name)
{
	var cIdx=eval("c"+ri_name)
	cIdx++
	if (cIdx==eval("v"+ri_name).length){cIdx=0}
	eval("c"+ri_name+"=cIdx")
	cImg=eval("v"+ri_name+"["+cIdx+"].src")
	//opzionale
	var cTxt=eval("v"+ri_name+"Txt["+cIdx+"]")
	if (document.all||document.getElementById)
	{
		var obj=document.getElementById("i"+ri_name)
		if(obj){obj.style.backgroundImage="url("+cImg+")"}
		
		var obj=document.getElementById("t"+ri_name)
		if (obj) {obj.innerHTML=cTxt}
	}
	setTimeout("roteaImg('"+ri_name+"')",5000)
}

function loadRun(vname,jspath) {
	if(isNotDefinedVar(vname)) {document.write("<script src=\""+jspath+"\"></script>")}
}

function isNotDefinedVar(vname) {
	var a=eval("typeof "+vname)
	return (a=="undefined")
}

function VerticalMenu(id) {//menuvert[cat]
    this.init = function() {
        if (!document.getElementById(this.id)) {
            alert("Element '"+this.id+"' does not exist in this document. VerticalMenu cannot be initialized");
            return;
        }
        this.parse(document.getElementById(this.id).childNodes, this.tree, this.id);
    }

    this.parse = function(nodes, tree, id) {
        for (var i = 0; i < nodes.length; i++) {
			var itmSelected = false;
            if (nodes[i].nodeType != 1) {
                continue;
            }
            if (nodes[i].tagName.toLowerCase() == "li") {
				if(nodes[i].id.substr(0, 6) == 'select')	//la voce, od una sua sottovoce, sono attualmente visualizzati/selezionati 
					itmSelected = true;
                nodes[i].id = id + "-" + tree.length;
                tree[tree.length] = new Array();
                if (nodes[i].childNodes && this.hasUl(nodes[i].childNodes)) {
					if (itmSelected)
						nodes[i].className = "branchopen";	//alexadd 
					else
						nodes[i].className = "branch";
                    var a;
                    if (a = this.getA(nodes[i].childNodes)) {
						if (a.id.substr(0, 6) != 'noopen') {
							a.id = nodes[i].id + "-a";
							eval("document.getElementById('"+a.id+"').onclick = function() {"+
								"self.click('"+nodes[i].id+"');"+
							"}");
						}
                    }
                } else {
					if (itmSelected)
						nodes[i].className = "leafsel";	//alexadd
					else
						nodes[i].className = "leaf";
                }
            }
            if (nodes[i].tagName.toLowerCase() == "ul") {
                if (nodes[i].id.substr(0, 6) != 'select')	//alexadd
					nodes[i].style.display = "none";
                id = id + "-" + (tree.length - 1);
                nodes[i].id = id + "-branch";
                tree = tree[tree.length - 1];
            }
            if (nodes[i].childNodes) {
                this.parse(nodes[i].childNodes, tree, id);
            }
        }
    }

    this.hasUl = function(nodes) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType != 1) {
                continue;
            }
            if (nodes[i].tagName.toLowerCase() == "ul") {
                return true;
            }
            if (nodes[i].childNodes) {
                if (this.hasUl(nodes[i].childNodes)) {
                    return true;
                }
            }
        }
        return false;
    }

    this.getA = function(nodes) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType == 1) {
                if (nodes[i].tagName.toLowerCase() == "a") {
                    return nodes[i];
                }
                return false;
            }
        }
    }

    this.click = function(id) {
        e1 = document.getElementById(id + "-branch");
        e2 = document.getElementById(id);
        if (e1.style.display == "none") {
            e1.style.display = "";
            e2.className = "branchopen";
        } else {
            e1.style.display = "none";
            e2.className = "branch";
        }
    }

    var self = this;
    this.id = id;
    this.tree = new Array();
    this.init();
}


function HorizontalMenu(id) {//menuor[cat]
	this.id = id;
	this.defHorMenu = '';
	var doinit = false;
	var thishm = this;
	var delayHideHMmain = 600;
	var delayHideHM = 700;
	var delayHideHM_tout;
	var showedHM=0;
	var aShowedHM=[];
	var HM_MAX_INNER_ITM = 10;

	this.init = function (defmnuid) {
		var hm = document.getElementById(this.id);
		var linum = 0;
		if (hm && !doinit) {
			var lis = hm.childNodes;
			for(var j=0; j<lis.length; j++)
				if (lis[j].nodeType == 1) {
					if(lis[j].tagName.toLowerCase() == "li") {
						linum++;
						for(var k=0; k<lis[j].childNodes.length; k++) {
							if (lis[j].childNodes[k].nodeType == 1) {
								if(lis[j].childNodes[k].tagName.toLowerCase() == "a") {
									lis[j].childNodes[k].onmouseover = new Function(this.id+'.showHorMnu(' + lis[j].id.substring(lis[j].id.indexOf('_')+1, lis[j].id.length) + ')');
									lis[j].childNodes[k].onmouseout = new Function(this.id+'.hideHorMnu(' + lis[j].id.substring(lis[j].id.indexOf('_')+1, lis[j].id.length) + ', ' + delayHideHMmain + ')');
									lis[j].childNodes[k].id = 'a' + lis[j].id;
									lis[j].childNodes[k].className = 'hmlnk';
									lis[j].childNodes[k].style.display = 'block';
								}
							}
						}
					}
				}
			for (z=1; z<=linum; z++) {
				var subul = document.getElementById(this.id + '_' + z);
				if (subul) {
					var lis = subul.childNodes;
					subul.style.display = 'none';
					for(var j=0; j<lis.length; j++)
						if (lis[j].nodeType == 1) {
							if(lis[j].tagName.toLowerCase() == "li") {
								for(var k=0; k<lis[j].childNodes.length; k++) {
									if (lis[j].childNodes[k].nodeType == 1) {
										if(lis[j].childNodes[k].tagName.toLowerCase() == "a") {
											lis[j].childNodes[k].onmouseover = new Function(this.id+'.showHorMnuSub()');
											lis[j].childNodes[k].onmouseout = new Function(this.id+'.hideHorMnu(' + z + ', -1)');
											lis[j].childNodes[k].className = 'hmsublnk';
											lis[j].childNodes[k].style.display = 'block';
										}
									}
								}
							}
						}
				}
			}
			if(defmnuid && defmnuid!='') {
				var us = defmnuid.indexOf('_');
				if (us<0)
					this.defHorMenu = 'thishm.showHorMnu(' + defmnuid + ')';
				else
					this.defHorMenu = 'thishm.showHorMnu(' + defmnuid.substring(0, us) + '); atmp = thishm.getA(\'' + defmnuid + '\'); if(atmp) atmp.className += \'sel\';';
/*				if (us<0)
					this.defHorMenu = 'thishm.showHorMnu(' + defmnuid + ')';
				else {
					var mid = defmnuid.substring(0, us).replace(/[^0-9]/gi, '');
					this.defHorMenu = 'var atmp = document.getElementById(\'ahm_' + mid + '\'); if(atmp) if(atmp.className.indexOf(\'sel\')<0) atmp.className+=\'sel\'; atmp = thishm.getA(\'' + defmnuid + '\'); if(atmp) atmp.className = atmp.className.replace(\'sel\', \'\'); thishm.showHMSub(\'' + defmnuid + '\', ' + mid + ', \'s\'); aShowedHM[showedHM] = thishm.id + \'_' + mid + '\'; showedHM++;';
				}
				*/
				eval(this.defHorMenu);
			}
			doinit = true;
		}
		else
			alert('Element "' + this.id + '" does not exist in this document; Horizontal Menu cannot be initialized');
	}

	this.showHorMnu = function(id) {
		this.hideAll();
		var hm = document.getElementById(this.id + '_' + id);
		if (hm) {
			var apar = document.getElementById('ahm_' + id);
			if (apar)
				apar.className += 'sel';
			hm.style.display = '';
			this.showHMSub(id, id, '');
			aShowedHM[showedHM] = hm.id;
			showedHM++;
		}
	}

	this.hideHorMnu = function(id, wait) {
		delayHideHM_tout = setTimeout(function() {hideHM(thishm.id + '_' + id, true)}, (wait>=0) ? wait : delayHideHM);
	}

	this.showHorMnuSub = function() {
		if (delayHideHM_tout)
			clearTimeout(delayHideHM_tout);
		return;
	}

	this.stayVisible = function(mainid, liid) {
		var lipref = 's';
		var maxloop = 0;
		while(mainid.indexOf(lipref)==0) {
			mainid = mainid.substring(lipref.length, mainid.lastIndexOf('_'));
			if (mainid.charAt(0)=="s" && mainid==liid.substring(0, mainid.length))
				return true;
			else if(mainid.charAt(0)!="s" && mainid==liid)
				return true;
			if (maxloop++>HM_MAX_INNER_ITM)
				return false;
		}
		return false;
	}

	this.showHMSub = function (id, idparent, prefix) {
		var ulpar = document.getElementById(this.id + '_' + idparent);
		if (ulpar) {
			ulpar.style.display = '';
			var lisibl = ulpar.childNodes;
			var idtmp = '';
			idtmp = prefix + id.toString() + '_';
			var a = this.getA(id);
			if (a && prefix!='') {
				if (a.className.indexOf('sel')<0) {
					a.className += 'sel';
				}
				else {
					idtmp = id.toString().substring(0, id.toString().lastIndexOf('_')+1);
					a.className = a.className.replace('sel', '');
				}
			}
			var idlen = idtmp.length;
			for (var j=0; j<lisibl.length; j++) {
				if (lisibl[j].nodeType == 1) {
					if(lisibl[j].tagName.toLowerCase() == "li") {
						if (id==lisibl[j].id || this.stayVisible(id.toString(), lisibl[j].id)) {
							lisibl[j].style.display = '';
							if (id!=lisibl[j].id ) {
								var preva = this.getA(lisibl[j].id);
								if (preva)
									if (preva.className.indexOf('sel')<0)
										preva.className += 'sel';
							}
						}
						else if (idtmp == lisibl[j].id.substring(0, idlen)) {
							lisibl[j].style.display = '';
							a = this.getA(lisibl[j].id);
							if (a)
								a.className = a.className.replace('sel', '');
						}
						else
							lisibl[j].style.display = 'none';
					}
				}
			}
		}
	}

	function hideHM(id, dec) {
		var aelm = document.getElementById('ahm_' + id.substring(id.indexOf('_')+1, id.length));
		if (aelm)
			aelm.className = aelm.className.replace('sel', '');
		var ulelm = document.getElementById(id);
		if (ulelm) {
			ulelm.style.display = 'none';
			if (aShowedHM[showedHM-1]==id && dec)
				showedHM--;
		}
		if(thishm.defHorMenu!='' && dec)
			eval(thishm.defHorMenu);
	}

	this.hideAll = function() {
		if (delayHideHM_tout)
			clearTimeout(delayHideHM_tout);
		while (showedHM>0) {
			showedHM--;
			hideHM(aShowedHM[showedHM], false);
		}
	}

	this.getA = function (liid) {
		var li = document.getElementById(liid);
		if (li) {
			var chls = li.childNodes;
			for(var i=0; i<chls.length; i++)
				if (chls[i].nodeType==1)
					if (chls[i].tagName.toLowerCase()=='a')
						return chls[i];
		}
		return null;
	}
}