//conferma cancellazione 
function tmt_confirm(msg){
	document.MM_returnValue=(confirm(unescape(msg)));
}

//nascondi layer
function nascondi(){
	var nava = (document.layers);
	var dom = (document.getElementById);
	var iex = (document.all);
	if (nava) { oggetto = document.aggiornas}
	else if (dom) {oggetto = document.getElementById("aggiornas").style}
	else if (iex) {oggetto = aggiornas.style}
	oggetto.visibility = "hidden";
}
function mostra(){
	oggetto.visibility = "visible";
}
// data
var isnMonths=new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
var isnDays= new Array("domenica","lunedì","martedì","mercoledì","giovedì","venerdì","sabato");
today=new Date();


function finestra_menu(str) {
	var width="530", height="450";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var finestra = window.open(str,'nuova',styleStr); 
}
function finestra_testo(str) {
	var width="770", height="480";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var finestra = window.open(str,'nuova',styleStr); 
}
function finestra_foto(str) {
	var width="550", height="220";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var finestra_foto = window.open(str,'nuova',styleStr); 
}
function finestra_datos(str) {
	var width="550", height="250";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var finestra_foto = window.open(str,'nuova',styleStr); 
}
function finestra_scheda(str) {
	var width="600", height="480";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var finestra = window.open(str,'nuova',styleStr); 
}

function finestra_utente(str) {
	var width="400", height="200";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var finestra = window.open(str,'nuova',styleStr); 
}


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.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\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+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' Campo richiesto.\n'; }
  } if (errors) alert('Questo campo è obbligatorio:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_validateFormA() { //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.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\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+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' è richiesto.\n'; }
  } if (errors) { 
  	alert('Questo campo è obbligatorio:\n'+errors);
  	document.MM_returnValue = (errors == '');
  	nascondi();
	} 
	mostra();
}

// funzione per indentificare i layer del testo foto
function MM_reloadPage(init) { 
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_setTextOfLayer(objName,x,newText) { 
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}


// funzione per cambiare al volo le foto piccole
function foto_carica(){
	foto=document.piccola0.src;
	testo=document.piccola0.value;
	document.media.src=foto.replace('S','L');
	MM_setTextOfLayer('foto_testo','',testo);	
}
function fotomedie(fotos,txt){
  	document.media.src='../upload/schede/'+ fotos.replace('S','L');
	MM_setTextOfLayer('foto_testo','',txt.replace('foto_testo','value'));
}

function controllo_schedaNew1() {
	//var Radioarray=new Array();
	Radioarray=parent.top.document.form1.scheda;
	flag=false;
	for (var i=0;i<Radioarray.length; i++) {
	if (Radioarray[i].checked==true) { 
		flag=true;
	}
}
	if (flag==false) {
  		alert("Selezionare una tipologia !");
		return false
  	} else {
	  	parent.top.document.form1.submit();
		}
}

function controllo_schedaNew2() {
	//var Radioarray=new Array();
	Radioarray=parent.top.document.form2.scheda;
	flag=false;
	for (var i=0;i<Radioarray.length; i++) {
	if (Radioarray[i].checked==true) { 
		flag=true;
	}
}
	if (flag==false) {
  		alert("Selezionare una tipologia !");
		return false
  	} else {
	  	parent.top.document.form2.submit();
		}
}

function controllo_allegatoNew1() {
	//var Radioarray = new Array();
	Radioarray = parent.top.document.form1.dato_documento;
	flag=false;
	for (var i=0;i<Radioarray.length; i++) {
	if (Radioarray[i].checked==true) { 
		flag=true;
		}
	}
	if (flag==false) {
		alert("Selezionare una tipologia !");
		return false
	} else {
	mostra();
	}
}

function controllo_allegatoNew2() {
	//var Radioarray=new Array();
	Radioarray=parent.top.document.form2.dato_documento;
	flag=false;
	for (var i=0;i<Radioarray.length; i++) {
	if (Radioarray[i].checked==true) { 
		flag=true;
		}
	}
	if (flag==false) {
		alert("Selezionare una tipologia !");
		return false
	} else {
	mostra();
	}
}


function controllo_utente() {
		if (document.form1.user.value == "") {
			alert("Inserire USER per questo utente");
			return false
		}
		else if (document.form1.user.value.length <= 3) {
			alert("Attenzione ! USER errato Inserire almeno 4 caratteri");
			return false
		}

		if (document.form1.password.value == "") {
			alert("Inserire PASSWORD per questo utente");
			return false
		}
		else if (document.form1.password.value.length <= 3) {
			alert("Attenzione ! PASSWORD errato Inserire almeno 4 caratteri");
			return false
		}
}
