// JavaScript Document
<!--

gNum = 1;

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  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();
}
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; }
}
function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function EB_ShowHide(objName){
	if ((obj=MM_findObj(objName))!=null){
		if (obj.style){
			if (obj.style.visibility =='auto'){
				obj.style.height='0px';
			} else {
				obj.style.height='auto';
			}
		} 
	}
}
	
function EB_changeLayer(objName) { //v1.01
	idLayers=new Array('s1','s2','s3','s4','s5','s6','s7','s8','s9','sError','sHelp');
	for (i=0;i<=10;i+=1){
		MM_showHideLayers(idLayers[i],'','hide');
	}
	MM_showHideLayers(objName,'','show');
}
function EB_OneClick(num) { //v1.01
	gNum = num;
	MM_showHideLayers('bottoneacceso' + num,'','hide');
	MM_showHideLayers('bottonespento' + num,'','show');
}
/* 
EB_MultiCheckForm v4.0 // Maggio 2006
Autore: ELIA BOGANI - elia@itacamedialab.it 
//
Stringa da inserire nel codice HTML: <form name="nome" id="nome" method="post" action="action" onSubmit="EB_MultiCheckForm(this,'col1','col2',true,cinquine di valori);return document.EB_returnValue;">
//
Prima CINQUINA di valori
Il PRIMO è nome del modulo,
Il SECONDO ed il TERZO corrispondono rispettivamente al colore di sfondo dei campi input, "normale" e "in errore"
Il QUARTO determina se i messaggi di errore dovranno essere visulizzati in HTMl nel layer con id="help" oppure attraverso una window alert (true=html; false=txt)
//
A seguire una CINQUINA di valori
Il PRIMO determina il tipo di controllo: 
obblg = campo obbligatorio
passw = verifica che due campi input text distinti contengano lo stesso valore
data = verifica che il campo contenga una data corretta 
data3 = verifica che 3 campi distinti per giorno, mese, anno compongano una data corretta 
radio = verifica che almeno 1 radio box della serie sia spuntato
check = verifica che almeno N check box della serie sia spuntato
agree = verifica che il check box dsia spuntato
count = effettua il conteggio delle lettere e verifica che non sia superiore al limite indicato
email = verfica che sia un indirizzo di posta valido
Il SECONDO è l'id del campo 
Il TERZO è il nome da utilizzare per il campo nell'eventuale messaggio di errore
IL QUARTO è il valore di confronto
Il QUINTO indica l'ID del div in cui è posizionato il campo controllato
*/

var vHelp = '<b>Help</b>';
var vBgAct = '#FFFFCC';
var vBgNorm = '#FFFFFF';
var vBgErr = '#FFFFCC';

function EB_MultiCheckForm(){ //v3.01
	var errors='', ErrorMsg='errore', errtxt='',errhtml='',first='',ddmmVal='',ddmmLenght='',args=EB_MultiCheckForm.arguments,formName=args[0],backcolorbad=args[1],backcolor=args[2],errformat=args[3],method=args[4],test='',campo='',anno='',year='';
	ErrorMsgHtml= 'Please note: the form as it is currently compiled displays the following <b>errores</b>:<br>';
	ErrorMsgTxt='Attenzione!\nsono stati riscontrati i seguenti errori nella compilazione del form:\n\n'
	divID = 's1';
	errformat=true;
	for (i=4; i<(args.length-3); i+=5){
		var test=args[i]; 
		//intercetta il campo del form da controllare
		var campo=MM_findObj(args[i+1]);
		//questa variabile determina se l'errore è su un campo input/select (false) oppure radio/checkbox (true)
		if(campo.type == "text" || campo.type == "select-one" || campo.type == "select-multiple" || campo.type == "password"){
			var testype = false;
		} else {
			var testype = true;
		}
		//quale verifica è stata richiesta?
		switch (test){
		// campo obbligatorio - il quarto valore è il valore di confronto (per es.: campo input normale: '')
		case "obblg":
			campo.style.backgroundColor= backcolor;	
			if (campo.value==args[i+3]){
				errors=ErrorMsg;
				errtxt+=args[i+2]+' > campo obbligatorio\n';
				errhtml+='<LI><b>'+args[i+2]+'</b><BR>obligatory field</LI>';
				divID = args[i+4];
				campo.style.backgroundColor=backcolorbad;
				if(!first){first=campo;}
			}
			break;
		// verifica della doppia digitazione della password
		case "passw":
			campo.style.backgroundColor= backcolor;
			var val1 = campo.value;
			var val2 = args[i+3];			
			if (val1!=val2){
				errors=ErrorMsg;
				errtxt+=args[i+2]+' > i due valori devono essere uguali\n';
				errhtml+='<LI><b>'+args[i+2]+'</b><br>the two must be the same</LI>';
				divID = args[i+4];
				campo.style.backgroundColor=backcolorbad;
				if(!first){first=campo;}
			}
			break;
		case "data":
			campo.style.backgroundColor= backcolor;
			campo.value=campo.value.replace('-','/');
			campo.value=campo.value.replace('-','/');
			if (campo.value.match(/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/)!=null){
				datePart=campo.value.split("/");
				var data = new Date();
				var year=data.getYear();
				if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {day=29;}else{day=28;}
				gg=(datePart[0]>=1) && (datePart[0]<=31);
				mm=(datePart[1]>=1) && (datePart[1]<=12);
				aa=(datePart[2]>=1900) && (datePart[2]<=9999);
				xx=(datePart[0]==31) && ((datePart[1]==4) || (datePart[1]==6) || (datePart[1]==9) || (datePart[1]==11));
				fb=(datePart[0]>day) && (datePart[1]==2);
				if(!gg || !mm || !aa || xx || fb) { 
					errors=ErrorMsg;
					errtxt+=args[i+2]+' > data non valida\n';
					errhtml+='<li><b>'+args[i+2]+'</b><br>data non valida</li>';
					divID = args[i+4];
					campo.style.backgroundColor=backcolorbad;
					first=campo;
				}
			} else { 
				// da attivare se si vuole che il campo sia anche obbligatorio
				if (args[i+3] == 'y' || campo.value!=''){
					errors=ErrorMsg;
					errtxt+=args[i+2]+' > data non valida\n';
					errhtml+='<li><b>'+args[i+2]+'</b><br>data non valida</li>';
					divID = args[i+4];
					campo.style.backgroundColor=backcolorbad;
					if(!first){first=campo;}
				}
			}
			break;
		case "data3":
			campo.style.backgroundColor= backcolor;
			EBgfield=MM_findObj(args[i+1] +'gg');
			EBmfield=MM_findObj(args[i+1] +'mm');
			EBafield=MM_findObj(args[i+1] +'aa');
			EBstampafield=MM_findObj(args[i+1] +'_stampa');
			var EBdata=EBgfield.value+"/"+EBmfield.value+"/"+EBafield.value;
			if (EBdata.match(/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/)!=null){
				var data = new Date();
				var year=data.getYear();
				if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {day=29;}else{day=28;}
				gg=(EBgfield.value>=1) && (EBgfield.value<=31);
				mm=(EBmfield.value>=1) && (EBmfield.value<=12);
				aa=(EBafield.value>=1900) && (EBafield.value<=9999);
				xx=(EBgfield.value==31) && ((EBmfield.value==4) || (EBmfield.value==6) || (EBmfield.value==9) || (EBmfield.value==11));
				fb=(EBgfield.value>day) && (EBmfield.value==2);
				if((!gg || !mm || !aa || xx || fb) && (EBgfield.value!="00" && EBmfield.value!="00" && EBafield.value!="0000")) { 
					errors=ErrorMsg;
					errtxt+=args[i+2]+' > data non valida\n';
					errhtml+='<li><b>'+args[i+2]+'</b><br>data non valida</li>';
					divID = args[i+4];
					campo.style.backgroundColor=backcolorbad;
					first=campo;
				} else {
					campo.value=EBafield.value+"/"+EBmfield.value+"/"+EBgfield.value;
					if(EBgfield.value<10){EBgg='0' + EBgfield.value;}else{EBgg=EBgfield.value;}
					if(EBmfield.value<10){EBmm='0' + EBmfield.value;}else{EBmm=EBmfield.value;}
					EBdata=EBgg+"/"+EBmm+"/"+EBafield.value;
					EBstampafield.disabled =false;
					EBstampafield.value=EBdata;
					EBstampafield.disabled =true;
				}
			} else { 
				// da attivare se si vuole che il campo sia anche obbligatorio
				//errors=ErrorMsg;
				//errtxt+=args[i+2]+' > data non valida\n';
				//errhtml+='<li><b>'+args[i+2]+'</b><br>data non valida</li>';
				//campo.style.backgroundColor=backcolorbad;
				//if(!first){first=campo;}
			}
			break;
		case "multi":
			modulo[args[i+2]].value='';
			for (j=0; j<campo.length; j++){
				if (campo.options[j].selected){	
					if(campo.options[j].value) modulo[args[i+2]].value+=campo.options[j].value+[args[i+3]];
				}
			}
			break;
		// verifica della scelta obbligata di almeno uno dei radio box
		case "radio":
			var radiocounter=false;
			var kr;
		    for (kr=0; kr<campo.length; kr++){
				if (campo[kr].checked){
					 radiocounter=true;
				}
            }
			if (!radiocounter){
				errors=ErrorMsg;	
				errtxt+=args[i+2]+' > scelta obbligatoria\n';
				errhtml+='<li><b>'+args[i+2]+'</b><br>obligatory selection</li>';
				divID = args[i+4];
				testype= true;
			}
			break;
		// verifica della scelta obbligata di n check box
		case "check":
			var checkcounter=0;
			var kc;
			var checkvalue = "";
			var numero=(args[i+3]);
		    for (kc=0; kc<campo.length; kc++){
				if (campo[kc].checked){
					 checkcounter++;
					 checkvalue+=campo[kc].value;
				}
            }
			if (checkcounter!=numero){
				errors=ErrorMsg;	
				errtxt+=args[i+2]+' > è necessario selezionare "'+args[i+3]+'" voci\n';
				errhtml+='<li><b>'+args[i+2]+'</b><br>è necessario selezionare "'+args[i+3]+'" voci</li>';
				divID = args[i+4];
				testype= true;
			} 
			break;
		// verifica della scelta obbligata di un singolo check box
		case "agree":
			if (campo.indeterminate==true || campo.status==false){
				errors=ErrorMsg;	
				errtxt+=args[i+2]+' > selezione obbligatoria\n';
				errhtml+='<LI><b>'+args[i+2]+'</b><BR>obligatory selection</LI>';
				divID = args[i+4];
				testype= true;
			}
			break;
		// conteggio lettere digitate, per es.:'count','descrizione','Descrizione articolo','15'
		case "countmax":
			campo.style.backgroundColor= backcolor;	
			if (campo.value.length>args[i+3]){
				errors=ErrorMsg;
				errtxt+=args[i+2]+' > ('+parseInt(campo.value.length-args[i+3])+') caratteri in eccesso rispetto a quelli consentiti\n';
				errhtml+='<LI><b>'+args[i+2]+'</b><br>('+parseInt(campo.value.length-args[i+3])+') caratteri in eccesso rispetto a quelli consentiti</li>';
				campo.style.backgroundColor=backcolorbad;
				divID = args[i+4];
				if(!first){first=campo;}
			} 
			break;
		case "cmin":
			campo.style.backgroundColor= backcolor;	
			if (campo.value.length<args[i+3]){
				errors=ErrorMsg;
				errtxt+=args[i+2]+' > ('+parseInt(campo.value.length-args[i+3])+') caratteri in eccesso rispetto a quelli consentiti\n';
				errhtml+='<LI><b>'+args[i+2]+'</b><br>minimum number of characters: ' + args[i+3] + '</li>';
				campo.style.backgroundColor=backcolorbad;
				divID = args[i+4];
				if(!first){first=campo;}
			} 
			break;
		// conteggio caratteri minimi (per esempio per campi password)
		case "countmin":
			campo.style.backgroundColor= backcolor;	
			if (campo.value.length<args[i+3]){
				errors=ErrorMsg;
				errtxt+= args[i+2]+ ' > numero minimo caratteri: ' +parseInt(args[i+3])+ '\n';
				errhtml+='<LI><b>'+args[i+2]+'</b><br>minimum number of characters:  ' +parseInt(args[i+3])+'</li>';
				divID = args[i+4];
				campo.style.backgroundColor=backcolorbad;
				if(!first){first=campo;}
			} 
			break;
		// verifica di un campo e-mail attraverso il controllo dei caratteri necessari e di quelli non consentiti
		case "email":
			campo.style.backgroundColor= backcolor;	
			if (campo.value.match(/^[a-zA-Z0-9_\-\.]+\@[a-zA-Z0-9][a-zA-Z0-9_\-\.]*\.[a-zA-Z]{2,8}$/)==null){
				errors=ErrorMsg;
				errtxt+=args[i+2]+' > indirizzo e-mail non valido\n';
				errhtml+='<li><b>'+args[i+2]+'</b><br>non-valid e-mail address</li>';
				divID = args[i+4];
				campo.style.backgroundColor=backcolorbad;
				if(!first){first=campo;}
			} 
			break;
		}
		/* 
		attivare la riga sottostante se si vuole 
		che il check form sia restituito campo per campo 
		anziché tutti insieme
		*/
		//if (errors){break;}		
	}
	if (errors) {
		if (errformat){
			errmessage=ErrorMsgHtml+"<UL>"+errhtml+"</UL>";
			//EB_changeLayer('sError');
			MM_setTextOfLayer('aiuto_testo','',errmessage);
		} else {
			errmessage=ErrorMsgTxt+errtxt;
			alert(errmessage);
		}
		MM_showHideLayers('bottoneacceso' + gNum,'','show');
		MM_showHideLayers('bottonespento' + gNum,'','hide');
		document.location.href='#';
	} 		
	
	document.EB_returnValue=(errors=='');
}

function EB_CheckForm(form,num){//v1.00
	var errors='';
	msg= '<b>Please note:</b><br>fill at least one of the fields';
	checknum=0;
	for(i=1;i<=num;i++){
		if(document[form].elements[i].value==''){
			checknum+=1;
		}
	}
	if(checknum==num){
		errors = msg;
		MM_setTextOfLayer('aiuto_testo','',errors);
	}
	
	document.EB_returnValue=(errors=='');
}
function EB_CheckFormAdvanced(form,num,campo){//v1.00
	var c = campo;
	var errors='';
	msg= '<b>Please note:</b><br>fill at least one of the fields';
	checknum=0;
	for(i=0;i<=num-1;i++){
		if(document[form].elements[i].value==''){
			checknum+=1;
		}
	}
	if(checknum==num){
		if(c!=null){
			if(document[form][c].selectedIndex==-1){
				errors = msg;
				MM_setTextOfLayer('aiuto_testo','',errors);
			}
		} else {		
			errors = msg;
			MM_setTextOfLayer('aiuto_testo','',errors);
		}
	}
	
	document.EB_returnValue=(errors=='');
}

function EB_cart(campo,quanto){
	var azione=MM_findObj(azione);
	var field=MM_findObj(campo);
	if (quanto==0){
		field.value = 0;
	} else {
		field.value = parseInt(field.value) + quanto;
	}
	document.form1.submit();
}
function EB_radio(campo,azione){
	var field=MM_findObj(campo);
	if(azione){
		field.disabled = false;
		field.style.backgroundColor=vBgErr;
		field.focus();
	} else {
		field.disabled = false;
		field.style.backgroundColor=vBgNorm;
		field.blur();
		field.disabled = true;
	}	
}
function EB_Confirm(ID,URL){
	divID = ID;
	actionHREF = URL;
	ErrorMsgHtml='';
	ErrorMsgHtml+='<b>Attenzione!</b><br>questa operazione <b>non</b> è annullabile<br>';
	ErrorMsgHtml+='Sicuro di voler proseguire?<br>';
	EB_changeLayer('sError');
	MM_setTextOfLayer('aiuto_testo','',ErrorMsgHtml);	
	document.location.href='#';
}

function EB_ResetScadenza(){
	var campo1=MM_findObj('articolo_visibile_agg');
	var campo2=MM_findObj('articolo_visibile_amm');
	var campo3=MM_findObj('articolo_visibile_aaa');
	campo1.options[0].selected = true;
	campo2.options[0].selected = true;
	campo3.options[0].selected = true;
}
//-->
