function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	function MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.id; if ((val=val.value)!="") {
		if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
		if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere una email valida.\n';
		} else if (test!='R') { num = parseFloat(val);
		if (isNaN(val)) errors+='- '+nm+' deve contenere un numero.\n';
		if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
		min=test.substring(8,p); max=test.substring(p+1);
		if (num<min || max<num) errors+='- '+nm+' deve contenere un numero compreso tra '+min+' e '+max+'.\n';
		} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' è obbligatorio.\n'; }
	} if (errors) alert('Si sono verificati i seguenti errori:\n'+errors);
	document.MM_returnValue = (errors == '');
	}
	
	function checkprivacy(privacy) {
		privacy=MM_findObj(privacy);
		if(privacy[0].checked==true) {
			return true;
		} else {
			alert('E\' necessario il consenso esplicito al trattamento dei dati');
			privacy.status=true;
			return false;
		}
	}
	
	function checkpsw(psw, pswagain) {
		valpsw=MM_findObj(psw);
		valpswagain=MM_findObj(pswagain);
		if(valpsw.value==valpswagain.value) {
			return true;
		} else {
			alert('Le password non coincidono');
			valpsw.value='';
			valpswagain.value='';
			return false;
		}
	}
	

/* focus per IE */
function Focus(){
	var inp=document.getElementsByTagName("input");
	for(i=0;i<inp.length;i++){
		inp[i].onfocus=function(){this.style.backgroundColor="#E4CC9E"};
		inp[i].onblur=function(){this.style.backgroundColor="#FFF"};
	}
}
/* fine focus per IE */


/* Script allowing MS IE to see the 'abbr' tag  by Marek Prokop */
/* http://www.sovavsiti.cz/css/abbr.html */
function styleAbbr() {
	var oldBodyText, newBodyText, reg
	if (bwIE) {
		oldBodyText = document.body.innerHTML;
		reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
		newBodyText = oldBodyText.replace(reg, '<ABBR $1><SPAN class=\"abbrIE\" $1>$2</SPAN></ABBR>');
		document.body.innerHTML = newBodyText;
	}
}
bwIE = (document.all) ? true:false;



function intercettaBlank() {
	for (var i=0; i<document.links.length; i++) {
		s=document.links[i].className;
		re= new RegExp("blank");
		if ( r = s.match(re) ) {
			document.links[i].target="_blank";
			document.links[i].title=document.links[i].title+" - Nuova finesta";
		}
	}
}



//domCorners by Alessandro Fulciniti - http://pro.html.it
function DomCheck() {
	return(document.createElement && document.getElementById)
}
function DomCorners(id,bk,h,tries) {
	var el=document.getElementById(id);
	if(el==null) {                              // se l'elemento non è ancora pronto nel dom...
		if(tries==null) tries=200;
		if(tries>0)                            // e ci sono ancora prove disponibili...
			setTimeout("DomCorners('"+id+"','"+bk+"',"+h+","+(--tries)+")",50);  // torna tra 50ms
		return;
	}
	var c=new Array(4);
	for(var i=0;i<4;i++) {                      // crea i quattro elementi per gli angoli
		c[i]=document.createElement("b");
		c[i].style.display="block";            // con le proprietà css necessarie
		c[i].style.height=h+"px";
		c[i].style.fontSize="1px";
		if(i%2==0)
			c[i].style.background="url("+bk+") no-repeat 0 -"+ i*h + "px";
		else
			c[i].style.background="url("+bk+") no-repeat 100% -"+ i*h + "px";
	}
	c[0].appendChild(c[1]);                    // innesta i due angoli superiori
	c[2].appendChild(c[3]);                    // e quelli inferiori
	el.style.padding="0";
	el.insertBefore(c[0],el.firstChild);       // li inserisce in testa...
	el.appendChild(c[2]);                      // e in coda.
}
/** js per gli angoli arrotondati */

function NiftyCheck(){

if(!document.getElementById || !document.createElement)

    return(false);

isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);

if(Array.prototype.push==null){Array.prototype.push=function(){

      this[this.length]=arguments[0]; return(this.length);}}

return(true);

}



function Rounded(selector,wich,bk,color,opt,m){

var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false;



if(color=="transparent"){

    cn=cn+"x";

    ecolor=bk;

    bk="transparent";

    }

else if(opt && opt.indexOf("border")>=0){

    var optar=opt.split(" ");

    for(i=0;i<optar.length;i++)

        if(optar[i].indexOf("#")>=0) ecolor=optar[i];

    if(ecolor=="") ecolor="#666";

    cn+="e";

    edges=true;

    }

else if(opt && opt.indexOf("smooth")>=0){

    cn+="a";

    ecolor=Mix(bk,color);

    }

if(opt && opt.indexOf("small")>=0) cn+="s";

prefixt=cn;

prefixb=cn;

if(wich.indexOf("all")>=0){t=true;b=true}

else if(wich.indexOf("top")>=0) t="true";

else if(wich.indexOf("tl")>=0){

    t="true";

    if(wich.indexOf("tr")<0) prefixt+="l";

    }

else if(wich.indexOf("tr")>=0){

    t="true";

    prefixt+="r";

    }

if(wich.indexOf("bottom")>=0) b=true;

else if(wich.indexOf("bl")>=0){

    b="true";

    if(wich.indexOf("br")<0) prefixb+="l";

    }

else if(wich.indexOf("br")>=0){

    b="true";

    prefixb+="r";

    }

var v=getElementsBySelector(selector);

var l=v.length;

for(i=0;i<l;i++){

    if(edges) AddBorder(v[i],ecolor);

    if(t) AddTop(v[i],bk,color,ecolor,prefixt,m);

    if(b) AddBottom(v[i],bk,color,ecolor,prefixb,m);

    }

}



function AddBorder(el,bc){

var i;

if(!el.passed){

    if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){

        var t=el.firstChild.nodeValue;

        el.removeChild(el.lastChild);

        var d=CreateEl("span");

        d.style.display="block";

        d.appendChild(document.createTextNode(t));

        el.appendChild(d);

        }

    for(i=0;i<el.childNodes.length;i++){

        if(el.childNodes[i].nodeType==1){

            el.childNodes[i].style.borderLeft="1px none "+bc;
            el.childNodes[i].style.borderRight="1px solid "+bc;

            }

        }

    }

el.passed=true;

}

    

function AddTop(el,bk,color,bc,cn,m){

var i,lim=4,d=CreateEl("b");



if(cn.indexOf("s")>=0) lim=2;
if(m=="l")
	{
		if(bc) d.className="altop";

else d.className="ltop";
	}else{
if(bc) d.className="artop";

else d.className="rtop";
	}
d.style.backgroundColor=bk;

for(i=1;i<=lim;i++){

    var x=CreateEl("b");

    x.className=cn + i;

    x.style.backgroundColor=color;

    if(bc) x.style.borderColor=bc;

    d.appendChild(x);

    }

el.style.paddingTop=0;

el.insertBefore(d,el.firstChild);

}



function AddBottom(el,bk,color,bc,cn,m){

var i,lim=4,d=CreateEl("b");



if(cn.indexOf("s")>=0) lim=2;
if(m=="l")
	{ 
		if(bc) d.className="altop";

else d.className="ltop";
	}else{
	if(bc) d.className="artop";

	else d.className="rtop";
	}

d.style.backgroundColor=bk;

for(i=lim;i>0;i--){

    var x=CreateEl("b");

    x.className=cn + i;

    x.style.backgroundColor=color;

    if(bc) x.style.borderColor=bc;

    d.appendChild(x);

    }

el.style.paddingBottom=0;
el.appendChild(d);

}



function CreateEl(x){

if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x));

else return(document.createElement(x));

}



function getElementsBySelector(selector){

var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];



if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"

    s=selector.split(" ");

    var fs=s[0].split("#");

    if(fs.length==1) return(objlist);

    f=document.getElementById(fs[1]);

    if(f) return(f.getElementsByTagName(s[1]));

    return(objlist);

    }

if(selector.indexOf("#")>0){ //id selector like "tag#id"

    s=selector.split("#");

    tag=s[0];

    selid=s[1];

    }

if(selid!=""){

    f=document.getElementById(selid);

    if(f) objlist.push(f);

    return(objlist);

    }

if(selector.indexOf(".")>0){  //class selector like "tag.class"

    s=selector.split(".");

    tag=s[0];

    selclass=s[1];

    }

var v=document.getElementsByTagName(tag);  // tag selector like "tag"

if(selclass=="")

    return(v);

for(i=0;i<v.length;i++){

    if(v[i].className.indexOf(selclass)>=0){

        objlist.push(v[i]);

        }

    }

return(objlist);

}



function Mix(c1,c2){

var i,step1,step2,x,y,r=new Array(3);

if(c1.length==4)step1=1;

else step1=2;

if(c2.length==4) step2=1;

else step2=2;

for(i=0;i<3;i++){

    x=parseInt(c1.substr(1+step1*i,step1),16);

    if(step1==1) x=16*x+x;

    y=parseInt(c2.substr(1+step2*i,step2),16);

    if(step2==1) y=16*y+y;

    r[i]=Math.floor((x*50+y*50)/100);

    }

return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16));

} 

/** oppure ruzer */
/**
 * RuzeeBorders Version 0.2
 * (c) 2006 Steffen Rusitschka, www.ruzee.com, All Rights Reserved.
 *
 * You may use this software free of charge. You may modify and 
 * redistribute it as long as this complete comment remains included.
 * There is no warranty of any kind. Contact steffen@rusitschka.de for
 * details on its commercial usage.
 */
function rzCrSimpleBorder(rad){
  return new RuzeeBorder(rad,rad,rad,0,true);
}

function rzCrShadowBorder(rad,smar){
  return new RuzeeBorder(rad,rad+smar*2,rad+smar,Math.round(smar/2),false);
}

function rzCrFadeBorder(rad){
  return new RuzeeBorder(1,rad,1,0,true);
}

function rzCrGlowBorder(rad,gmar){
  return new RuzeeBorder(rad,rad+gmar,rad,0,true);
}

function RuzeeBorder(cr,sr,sp,ss,si){

this.isIE=navigator.userAgent.toLowerCase().indexOf("msie") > 0
  && navigator.userAgent.toLowerCase().indexOf("opera") == -1;
this.cornerRadius=cr?cr:6;
this.shadowRadius=sr?sr:18;
this.shadowPadding=sp?sp:14;
this.shadowShift=ss?ss:0;
this.simple=si?si:false;
this.coShadow=rzS2C("000");

this.crDiv=function(w,h,bg,o){
  var d=document.createElement("div");
  d.style.padding=d.style.margin="0px";
  d.style.display="block";
  d.style.border="none";
//   if(w) d.style.width=w;
  d.style.width=w?w:"auto";
  if(h) { d.style.height=h; d.style.fontSize=h; }
  if(bg) d.style.background=bg;
  if(o) d.style.overflow=o;
  return d;
}

this.addLRD=function(c,l,r,bg,fst){
  var w=this.crDiv(null,null,bg);
  this.flt(l,"left");
  this.flt(r,"right");
  l.style.overflow=r.style.overflow="hidden";
  if(this.isIE&&fst){ // fix IE 3px bug
    l.style.marginRight=r.style.marginLeft="-3px";
  }
  c.style.marginLeft=l.style.width;
  c.style.marginRight=r.style.width;
  w.appendChild(l);
  w.appendChild(r);
  w.appendChild(c);
  return w;
}

this.addLRC=function(c,co,w,h){
  var e=this.crDiv(null,h,co);
  c.style.margin="0px "+(w?w:"1px");
  e.appendChild(c);
  return e;
}

this.flt=function(e,f){
  e.style.cssFloat=e.style.styleFloat=f;
}

this.crTB=function(top){
  var sh=top?-this.shadowShift:this.shadowShift;
  var cxc=this.shadowPadding-this.cornerRadius-1;
  var cxb=cxc;
  var cxe=cxc+this.cornerRadius;
  var exb=0;
  var exe=cxc-1;
  var syc=this.cornerRadius-this.shadowPadding+sh+1;
  var yb,ye;
  if(top){
    yb=syc+this.shadowRadius-1; 
    // tocut it
    if(!this.simple&&yb<this.cornerRadius){
      yb=this.cornerRadius;
    }
    ye=-1;
    yi=-1;
  }else{
    yb=syc<0?syc:0;
    ye=syc+this.shadowRadius;
    yi=1;
  }

  var e=this.crDiv(null, Math.abs(yb-ye));
  for(var y=yb; y!=ye; y+=yi){
    var co;
    if(y<=this.cornerRadius-1){
      co=this.coBgIn;
    }else if(y==this.cornerRadius){
      co=this.coBorder;
    }else if(y-syc<0){
      co=this.coShadow;
    }else{
      co=rzBlend(this.coShadow,this.coBgOut,(y-syc)/this.shadowRadius);
    }
    var line=this.crDiv(null,"1px",rzC2S(co),"hidden");
    for(var x=0; x<this.shadowRadius; ++x){
      var sd;
      if(y<syc){
        sd=x;
      }else{
        sd=Math.sqrt(Math.sqr(x)+Math.sqr(y-syc));
      }
      if(this.shadowRadius>this.cornerRadius && sd<=this.shadowRadius){
        co=rzBlend(this.coShadow, this.coBgOut, sd/this.shadowRadius);
      }else{
        co=this.coBgOut;
      }
      if(y<=this.cornerRadius){
        if(x>=exb && x<=exe){
          co=y==this.cornerRadius?this.coBorder:this.coBgIn;
        }else if(x>=cxb && x<=cxe){
          var cd=Math.sqrt(Math.sqr(x-cxc)+Math.sqr(y))-this.cornerRadius;
          if(y<0 || cd<-1){
            co=x==cxe?this.coBorder:this.coBgIn;
          }else if(cd<0){
            co=rzBlend(this.coBorder,this.coBgIn,-cd);
          }else if(cd<=1){
            co=rzBlend(this.coBorder,co,cd);
          }
        }
      }
      line=this.addLRC(line,rzC2S(co));
    }
    e.appendChild(line);
  }
  return e;
}

this.crLR=function(e){
  var coBgInS=rzC2S(this.coBgIn);
  var coBS=rzC2S(this.coBorder);
  e=this.addLRC(e,coBgInS,"3px");
  e=this.addLRC(e,coBS,"1px");
  var ye=this.shadowPadding+this.shadowShift-this.cornerRadius-2;
  for(var x=this.shadowPadding; x<this.shadowRadius; ++x){
    var l=this.crDiv("1px");
    var r=this.crDiv("1px");
    var coS;
    for(var y=ye; y>0; --y){
      var d=Math.sqrt(Math.sqr(x)+Math.sqr(y));
      if (this.shadowRadius<=this.cornerRadius || d>this.shadowRadius){
        coS=rzC2S(this.coBgOut);
      }else{
        coS=rzC2S(rzBlend(this.coShadow,this.coBgOut,d/this.shadowRadius));
      }
      l.appendChild(this.crDiv("1px","1px",coS,"hidden"));
      r.appendChild(this.crDiv("1px","1px",coS,"hidden"));
    }
    coS=rzC2S(rzBlend(this.coShadow,this.coBgOut,x/this.shadowRadius));
    if(ye<=0){
      l.appendChild(this.crDiv("1px","1px",coS,"hidden"));
      r.appendChild(this.crDiv("1px","1px",coS,"hidden"));
    }
    e=this.addLRD(e,l,r,coS);
  }
  return e;
}

this.crLRC=function(e){
  var coBgInS=rzC2S(this.coBgIn);
  var coBS=rzC2S(this.coBorder);
  e=this.addLRC(e,coBgInS,"3px");
  e=this.addLRC(e,coBS);
  for(var x=this.shadowPadding; x<this.shadowRadius; ++x){
    coS=rzC2S(rzBlend(this.coShadow,this.coBgOut,x/this.shadowRadius));
    e=this.addLRC(e,coS);
  }
  return e;
}

this.draw=function(e,coShadowS){
  if(!e) return;
  if(typeof e=='string') e=document.getElementById(e);
  if(!e) return;
  if(e.constructor==Array){
    for(var i=0; i<e.length; ++i){
      this.draw(e[i],coShadowS);
    }
    return;
  }
  if(coShadowS) this.coShadow=rzS2C(coShadowS);

  this.coBgIn=rzS2C(rzGetStyle(e,'background-color'));
  this.coBgOut=rzS2C(rzGetStyle(e.parentNode,'background-color'),'#ffffff');
  var bs=rzGetStyle(e,'border-top-style',false,'none');
  if(bs && bs!='' && bs!='none' && bs!='hidden'){
    this.coBorder=rzS2C(rzGetStyle(e,'border-top-color'));
  }else{
    this.coBorder=this.coBgIn;
  }
  var wr=this.crDiv();
  var cwr=this.crDiv();
  cwr.style.backgroundColor=rzC2S(this.coBgIn);

  wr.appendChild(this.crTB(true));
  wr.appendChild(this.simple?this.crLRC(cwr):this.crLR(cwr));
  wr.appendChild(this.crTB(false));

  if(this.isIE) e.style.height=cwr.style.height="1%"; // fix IE 3px jog when floated
  rzCopyStyleTRBL(cwr,e,"padding");
  e.style.padding="0px";
  e.style.border="none";
  e.appendChild(wr);
  while (e.childNodes.length>1){
    cwr.appendChild(e.removeChild(e.childNodes[0]));
  }
}
} // of RuzeeBorder

// internal tools

Math.sqr=function(x){
  return x*x;
}

function rzCC(s){
  for(var exp=/-([a-z])/; exp.test(s); s=s.replace(exp,RegExp.$1.toUpperCase()));
  return s;
}

function rzGetStyle(e,a,transOk,d){
  if(typeof e=='string') e=document.getElementById(e);
  var v;
  if(document.defaultView){
    var cs=document.defaultView.getComputedStyle(e,null);
    if (!cs && window.getComputedStyle) cs=window.getComputedStyle(e,null);
    if(cs){
      v=cs.getPropertyValue(a);
      if(!v && cs.getPropertyCSSValue){
        v=cs.getPropertyCSSValue(a);
        if(v) v=v.getStringValue();
      }
    }
  }

  if(!v && e.currentStyle){
    v=e.currentStyle[rzCC(a)];
    if (!v) v=e.currentStyle[a];
  }

  if(!v) v=e.style[rzCC(a)];
  // KHTML bug fix: transparent is #000000 - if you want black, use #010101 in your CSS.
  if(!transOk && v && (v.toLowerCase()=='transparent' || v=='#000000')) v=null;
  return v?v:d?d:rzGetStyle(e.parentNode,a);
}

function rzCopyStyleTRBL(d,s,a,ae){
  var aeCCS=ae?rzCC(ae):"";
  var aeS=ae?"-"+ae:"";
  d.style[a+"Top"+aeCCS]=rzGetStyle(s,a+"-top"+aeCCS);
  d.style[a+"Right"+aeCCS]=rzGetStyle(s,a+"-right"+aeCCS);
  d.style[a+"Bottom"+aeCCS]=rzGetStyle(s,a+"-bottom"+aeCCS);
  d.style[a+"Left"+aeCCS]=rzGetStyle(s,a+"-left"+aeCCS);
}

function rzGetElementsByClass(cn,node,tag) {
  var a=new Array();
  if (!node) node=document;
  if (!tag) tag='*';
  var els=node.getElementsByTagName(tag);
  var pattern=new RegExp('(^|\\s)'+cn+'(\\s|$)');
  for (i=0; i<els.length; i++){
    if (pattern.test(els[i].className)){
      a.push(els[i]);
    }
  }
  return a;
}

function rzS2C(s,d){
    if (!s) return d?rzS2C(d):[0,0,0];
    if (s.charAt(0)=='#') s=s.substr(1,6);
    s=s.replace(/ /g,'').toLowerCase();
    // The CSS 2.1 colors
    var COLORS = {
         aqua:'00ffff', black:'000000', blue:'0000ff', fuchsia:'ff00ff',
         gray:'808080', green:'008000', lime:'00ff00', maroon:'800000',
         navy:'000080', olive:'808000', orange:'ffa500', purple:'800080',
         red:'ff0000', silver:'c0c0c0', teal:'008080', white:'ffffff',
         yellow:'ffff00'
    };
    for (var key in COLORS) if (s==key) s=COLORS[key];

    var p=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.exec(s);
    if(p) return [parseInt(p[1]), parseInt(p[2]), parseInt(p[3])];
    p=/^(\w{2})(\w{2})(\w{2})$/.exec(s);
    if(p) return [parseInt(p[1],16), parseInt(p[2],16), parseInt(p[3],16)];
    p=/^(\w{1})(\w{1})(\w{1})$/.exec(s);
    if(p) return [parseInt(p[1]+p[1],16), parseInt(p[2]+p[2],16), parseInt(p[3]+p[3],16)];
    return d?rzS2C(d):[0,0,0];
}

function rzC2S(c){
  r="0"+c[0].toString(16);
  g="0"+c[1].toString(16);
  b="0"+c[2].toString(16);
  return "#"
    +r.substring(r.length-2)
    +g.substring(g.length-2)
    +b.substring(b.length-2);
}

function rzBlend(a,b,w){
  return Array(
    Math.round(a[0]+(b[0]-a[0])*w),
    Math.round(a[1]+(b[1]-a[1])*w),
    Math.round(a[2]+(b[2]-a[2])*w));
}
