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_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}

var win = null;
function popup(mypage,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	//h = h + 20;
	//w = w + 20;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+'no'+''
	ran_number= Math.round(Math.random()*100);
	winName = 'bla'+ran_number+h+w;
	window.open(mypage,winName,settings);
}

var win = null;
function popupscroll(mypage,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	//h = h + 20;
	//w = w + 20;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+'yes'+''
	ran_number= Math.round(Math.random()*100);
	winName = 'bla'+ran_number+h+w;
	window.open(mypage,winName,settings);
}

// funzioni base
function apridiv(domid) {
	var nodeObj = document.getElementById(domid);
	nodeObj.style.display = 'block';
}
function chiudidiv(domid) {
	var nodeObj = document.getElementById(domid);
	nodeObj.style.display = 'none';
}

function controllaData(frm,gg,mm,aa,nome){
if (document.forms[frm][aa].value.length == 1 || document.forms[frm][aa].value.length == 3 )
	{
		alert("Attenzione! " + nome + " errata. Inserire un valore corretto per l'anno")
		return false
	}
	
if (document.forms[frm][aa].value.length == 2 ){
	if (document.forms[frm][aa].value < 30 ) {
		anno = "20" + document.forms[frm][aa].value 
		document.forms[frm][aa].value = anno
		}
	else {
		anno = "19" + document.forms[frm][aa].value 
		document.forms[frm][aa].value = anno
		}
	}
if (document.forms[frm][aa].value < 1800 && document.forms[frm][aa].value != "" ) {
	alert("Attenzione! L'anno del campo " + nome + " inserita è fuori dal range consentito")
	return false
	}
	
if (document.forms[frm][mm].value > 12 ) {
	alert("Attenzione! " + nome + " errata. Inserire un valore corretto per il mese")
	return false
	} 

if (document.forms[frm][mm].value == "2" ||  document.forms[frm][mm].value == "02" ) {
	if ((document.forms[frm][aa].value % 4 ) == 0 ){
		if (document.forms[frm][gg].value > 29 ) {
			alert("Attenzione! " + nome + " errata. Inserire un valore corretto per il giorno")
			return false
			} 
		}
	else if (document.forms[frm][gg].value > 28 ) {
			alert("Attenzione! " + nome + " errata. Inserire un valore corretto per il giorno")
			return false
			}
	}
else if (document.forms[frm][mm].value == "04" ||  document.forms[frm][mm].value == "4" || document.forms[frm][mm].value == "06" ||   document.forms[frm][mm].value == "6"  || document.forms[frm][mm].value == "09" ||   document.forms[frm][mm].value == "9"  ||  document.forms[frm][mm].value == "11") {
	if (document.forms[frm][gg].value > 30 ) {
		alert("Attenzione! " + nome +" errata. Inserire un valore corretto per il giorno")
		return false
		}
	}
else { 
	if (document.forms[frm][gg].value > 31 ) {
		alert("Attenzione! " + nome +" errata. Inserire un valore corretto per il giorno")
		return false
	}
} 

return true
}

function controllaNumeri(frm,campo){
  var ckOK = ",0123456789";
  var cf = document.forms[frm][campo].value;
  if (cf.length > 0) {
    var ok = true;
    for (i=0;i < cf.length;i++)  {
      for (j=0;j < ckOK.length;j++)
        if (cf.charAt(i) == ckOK.charAt(j)) {ok = true; break;}
        else ok=false;
      if (!ok)  break;
    }
    if (!ok){
      alert("Attenzione! Campo numerico.");
      return (false);
    }
  }
  return (true);
//if (isNaN(document.forms[frm][campo].value)) {
//	alert("Attenzione!Campo numerico.")
//	return false
//	}
//return true
}


function ControllaMail(EmailAddr){
 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 statusSetter() {   
window.defaultStatus = "";
window.status = "";
}

function partitaIVA(sz_Codice){
   var n_Val,n_Som1=0,n_Som2=0,lcv;
   if (sz_Codice.length!=11 || isNaN(parseFloat(sz_Codice)) || parseFloat(sz_Codice)<parseFloat(0))
      return false;
   
   for (lcv=0;lcv<9;lcv+=2)
   {
      n_Val=parseInt(sz_Codice.charAt(lcv));
      n_Som1+=n_Val;
      n_Val=parseInt(sz_Codice.charAt(lcv+1));
      n_Som1+=Math.floor(n_Val/5) + (n_Val<<1) % 10;
   }
   n_Som2 = 10 - (n_Som1 % 10);
   n_Val=parseInt(sz_Codice.charAt(10));
   if (n_Som2==n_Val)
      return true;
   return false;
}

function controllaCellulare(numero){
	if (!numero.match(/^((00|\+)39[\. ]??)??3\d{2}[\. ]??\d{6,7}$/))
	return false;
	else return true;	
}
