<!--
/*


04/03/2007	Aggiunta ArraToString + isSafari e isFirefox

20/07/2006	Aggiunta ColorSelect (ancora da verificare)

07/06/2006 	Aggiunta oID() alias od doument.getElementById();

20/05/2006 	Aggiunta di getMouseXY

19/05/2006  Aggiunta AddOnLoad 

16/05/2006 	Modificate le funzioni per la gestione degli xfile
      		Ora accettano + tipi di files e riescono a leggere l'ultima estenzione
16/05/2006 	Inserita FiltraKey(typeFilter) che racchiude i vari solo_data, solo_numeri, solo_tel, etc..

*/
//alert(navigator.userAgent);
isMSIE=(navigator.appName=="Microsoft Internet Explorer");
isMSIE5=this.isMSIE&&(navigator.userAgent.indexOf('MSIE 5')!=-1);
isMSIE5_0=this.isMSIE&&(navigator.userAgent.indexOf('MSIE 5.0')!=-1);
isMSIE7=this.isMSIE&&(navigator.userAgent.indexOf('MSIE 7')!=-1);
isSafari=BrowserDetect.browser=='Safari';
isFirefox=BrowserDetect.browser=='Firefox';


// PopupDialog
// ----------------------------------------------------
PopupDialog = null;
function Dialog(url, width, height, resizable)
{
	width = width || 550;
	height = height || 500;
	resizable = resizable || "yes";
	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;
	}
	if (PopupDialog!=null) 
	{
		if (typeof(PopupDialog.DialogClose)=="function")
		{
			PopupDialog.close();
		}
		//setTimeout('DialogOpen(\''+url+'\','+top+','+left+','+width+','+height+','+resizable+');',100);
		DialogOpen(url,top,left,width,height,resizable);		
	}
	else
	{
		DialogOpen(url,top,left,width,height,resizable);
	}
}
function DialogOpen(url, top, left, width, height, resizable)
{
	PopupDialog = window.open(url, 'PopupDialog', 'width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollBars=yes,resizable='+resizable+',top='+top+',left='+left);
}
function DialogClose()
{
	if (confirm("Le modifiche andranno perse.\n\nContinuare?"))
	{
		self.close();
	}
}
// --------------------------------------------------------
function oID(objectId)
{
	objectId = objectId || '';
	if (objectId) return document.getElementById(objectId);
}





//Trasforma un array in stringa con un delimitatore (il contrario di split)
function ArrayToString( arr, sep )
{
	var sep = sep || p_p;
	var str = new String();
	for ( i in arr )
		str += ((str!='')?sep:'') + arr[i];
	return str;
}








//obj = (object) oggetto di riferimento
//e = (string) nome evento : focus,load
//fn = (function)
function AddEvent(obj,e,fn) {
	if (window.addEventListener)		eval('obj.addEventListener("'+ e +'", fn, false);');
	else if (window.attachEvent)		eval('obj.attachEvent("on'+ e +'", fn);');
	else if (document.getElementById)	eval('obj.on'+ e +'=fn;');	
}
function RemoveEvent(obj,e,fn) {
	if (window.addEventListener)		eval('obj.removeEventListener("'+ e +'", fn, false);');
	else if (window.attachEvent)		eval('obj.detachEvent("on'+ e +'", fn);');
	else if (document.getElementById)	eval('obj.on'+ e +'="";');
}




function StopPropagation( e )
{
	if (document.all)
	{	// Code for IE browsers
		window.event.cancelBubble=true;
	} 
	else if (!document.all && document.getElementById)
	{	// Code for Mozilla browsers
		e.stopPropagation();
	}
}








//funzione ricorsiva per calcolare la posizione dell'oggetto rispetto alla pagina
//se getTop=true restituisco distanza dal top, altrimenti left
function GetObjectPosition(sender,getTop)
{
	var x = (getTop?sender.offsetTop:sender.offsetLeft);
	if (sender.offsetParent != null)
		x += GetObjectPosition(sender.offsetParent,getTop);
	return x;
}







// ----------------------------------
// Apertura / Chiusura PopUp
// ----------------------------------
function OpenPopup(Url,Name,width,height,scrollbars)
{
	scrollbars = scrollbars || 'no';
	if (document.all){
		var x = window.screenLeft;
		var y = window.screenTop;
		var w = window.document.body.offsetWidth;
		var h = window.document.body.offsetHeight;
	}else{
		var x = window.screenX;
		var y = window.screenY;
		var w = window.outerWidth;
		var h = window.outerHeight;
	}
	var cntx = x + Math.round((w - width) / 2);
	var cnty = y + Math.round((h - height) / 2);
	window.open(Url,Name, 'top='+cnty+',left='+cntx+',width='+width+',height='+height+',scrollbars='+scrollbars+',status=no,menubar=no,toolbar=no,resizable=yes');
}
// ----------------------------------




/*








function apri_fin (url, width, height) {
	width = width || 400;
	height = height || 500;
	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;
	}
	return window.open(url, '', 'width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=yes,menuBar=no,scrollBars=yes,resizable=yes,top='+top+',left='+left);
	//window.open(url,'','fullscreen,scrollBars=0,resizable=0')
}







function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

// Variabili globali per la posizione del mouse
var MouseX = 0
var MouseY = 0
// Impostazione dell'handler
function GrabMousePosition(arg)
{
	arg = arg || false;
	if (arg)
		document.onmousemove = getMouseXY; 
	else
		document.onmousemove = ''; 	
}
// Funzione che trova e restituisce la posizione del mouse
function getMouseXY(e)
{
  if (isMSIE) { // grab the x-y pos.s if browser is IE
    MouseX = event.clientX + document.body.scrollLeft
    MouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    MouseX = e.pageX + document.body.scrollLeft
    MouseY = e.pageY + document.body.scrollLeft
  } 
  // catch possible negative values in NS4
  if (MouseX < 0){MouseX = 0}
  if (MouseY < 0){MouseY = 0} 
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  JxToDebug('x=' + tempX + '&y=' + tempY);
  return true
} 



//per mozilla non esiste (o non la ho trovata!) un equivalente di offsetX/Y (che
//restituisce in IE la posizione del mouse relativa al suo "contenitore"). Uso quindi 
//funzione ricorsiva per calcolare la posizione del contenitore nella pagina, e la 
//sottraggo alla posizione del mouse nella pagina
function ScriviPosizione(e) {
	if(window.getSelection) { //browser Gecko
		window.status="X: "+(e.pageX-GetPosizioneOggetto(e.currentTarget,false))+ 
			"Y: "+(e.pageY-GetPosizioneOggetto(e.currentTarget,true));
	} else {
		window.status="X: "+window.event.offsetX+"  Y: "+window.event.offsetY;
	}
}





function NewListElement(lstName,newValue)
{
	newValue = newValue || '';
	oSelect = document.getElementById(lstName+'_List');
	oBtn =  document.getElementById(lstName+'_Btn');
	oText =  document.getElementById(lstName);
	// Visualizza la select
	if (oSelect.style.display=="none" && newValue=='') // deve necessariamente non esserci un valore per nascondere la text
	{
		oBtn.firstChild.src = "images/ico_add_sez.png";
		oSelect.style.display="inline";
		oText.style.visibility='hidden';
		oText.value=oSelect.value;
		oSelect.focus();
	}
	else
	{
		oBtn.firstChild.src = "images/ico_del.png";
		oSelect.style.display="none";
		oText.style.visibility='visible';
		oText.value=newValue;
		oText.focus();
	}
}

function Capitalize(myString)
{
	myString = myString || '';
	strCapitalized = '';
	arrString = myString.split(' ');
	for(i=0; i<arrString.length; i++)
	{
		if (arrString[i].length)
			strCapitalized +=  (strCapitalized?' ':'') + arrString[i].substr(0,1).toUpperCase() + arrString[i].substr(1,arrString[i].length).toLowerCase();
	}		
	return strCapitalized;
}







function AddOnLoad(strFunct)
{
	if (window.addEventListener)		window.addEventListener("load", strFunct, false);
	else if (window.attachEvent)		window.attachEvent("onload", strFunct);
	else if (document.getElementById)	window.onLoad=strFunct + window.onload;
	else alert('Impossibile attaccare l\'evento');
}










function SwapVisibility(objID)
{
	if (document.getElementById(objID).className=="Hidden")
	{
		document.getElementById(objID).className="Visible";
	}
	else
	{
		document.getElementById(objID).className="Hidden";
	}
}
function SetVisibility(objID, state)
{
	if (state)
	{
		document.getElementById(objID).className="Visible";
	}
	else
	{
		document.getElementById(objID).className="Hidden";
	}
}


function Visibility(objID, visible)
{
	if (visible)
	{
		document.getElementById(objID).style.visibility="visible";
	}
	else
	{
		document.getElementById(objID).style.visibility="hidden";
	}
}

function addOption(nameTarget, txValue, txText)
{
	var oTarget			=	new Object;
	oTarget				=	document.getElementById(nameTarget);
	if (isMSIE || isMSIE5 || isMSIE5_0)
	{
		var oOption 		= 	document.createElement("OPTION");
		oTarget.options.add(oOption) ;
		oOption.innerText 	= 	txValue;
		oOption.value 		= 	txText;
	}
	else
	{
		oTarget.options[oTarget.options.length] = new Option(txValue,txText);
	}
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			 IsNumber = false;
		}
	}
	return IsNumber;	
}

function mailto(scrivi) {
	var dominio = "spaziografico.it"
	var utente = "info"
	var destinatario = utente + "@" + dominio
	var indirizzo = "mailto:" + destinatario
	if (!scrivi) location.href=indirizzo;
	else document.write(destinatario.link(indirizzo));
}



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) {
	var mytxt = mytext.value.toLowerCase() ;
	var arrType = type.split(",");
	var posFound = 0;
	var posFoundTmp;
	for (i=0; i<arrType.length; i++)
	{
		if (posFoundTmp = mytxt.lastIndexOf(arrType[i]) != -1) {	
			if (posFoundTmp>=posFound) {
				posFound=posFoundTmp;
			}
		}
	}
	if (!posFound) {
		alert("Attenzione file selezionato non corretto.\n\nEstensioni accettate:\n " + type.replace(/,/g,"\n"));
		mytext.value="";
		return false ;
	} else {
		return true ;
	}
}

function type_of_file(namefile, span, typeofile)
{
	var btn_send_this = document.getElementById('btn_upload_' + span);
	var var_send_this = document.getElementById('send_this_' + span);
	var id = document.getElementById('type_file_' + span);
	var arrType	= typeofile.split(",");
	var posFound = 0;
	var posFoundTmp;
	id.className = "typefile";
	if (typeofile=="") ok = true  ;  else ok = false  ;
	namefile = namefile.toLowerCase();
	for (i=0; i<arrType.length; i++)
	{
		for (n=0; n<FileExtensions.length; n++)
		{
			FileExt = FileExtensions[n].split("|");
			if (posFoundTmp = namefile.lastIndexOf(FileExt[0]) != -1) {
				if (posFoundTmp>=posFound) {
					if (arrType[i]==FileExt[0]) ok = true;
					typefile = FileExt[1];
					posFound=posFoundTmp;
				}
			}
		}
	}
	if (!posFound) {
		typefile = "File non supportato";
		ok = false;
	}	
	if (ok) {
		if (document.getElementById('ok')!=null) document.getElementById('ok').disabled=false;
		id.className = "typefile-ok";
		btn_send_this.disabled = false ;
	}	else {
		if (document.getElementById('ok')!=null) document.getElementById('ok').disabled=true;
		id.className = "typefile-err";
		btn_send_this.disabled = true ;
	}
	//id.innerHTML = '<a href="' + namefile + '" target="_blank">' + typefile + '</a>' ;
	id.innerHTML = typefile ;
}

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");
		}
	}
}



// GESTIONE DATE
// ------------------------------------------------------------------
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 verifica_date(myDate) {
	// riceve solo la data in formato testo
	if (myDate!="") {
		err = false;		
		obj=myDate.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) {	
			return false;
		} else {
			return dddata; // Nel campo viene scritta la data generata	
		}
	}	
}
function verifica_date_magg(myDate, preDate) {
	
	data = date_format(myDate);
	//alert('myDate:'+ data);
	data_pre = date_format(preDate);
	//alert('preDate:'+ data_pre);

	if (data_pre > data) {
		return false ;
	} else {
		return true ;
	}
	
}
function date_format(str_data)
{
	//alert(str_data);
	str_date_format = str_data.replace(/[^\d]/g,"0");
	gg = str_date_format.substr(0,2);
	mm = str_date_format.substr(3,2);
	aa = str_date_format.substr(6,4);
	new_data = new Date(aa,mm,gg);
	//alert(new_data);
	return new_data ;
}
function verifica_date_include(myDate, preDate, nextDate) {
	
	data = date_format(myDate);
	//alert('myDate:'+ data);
	data_pre = date_format(preDate);
	//alert('preDate:'+ data_pre);
	data_max = date_format(nextDate);
	//alert('nextDate:'+ data_max);

	if (data >= data_pre && data <= data_max) {
		return true ;
	} else {
		return false ;
	}
	
}
function day_between_date(firstDate, lastDate)
{
	data1 = date_format(firstDate);
	data2 = date_format(lastDate);
	
	var one_day = 1000*60*60*24;
	var day_between = Math.ceil( (data2.getTime()-data1.getTime()) / (one_day) );
	return day_between ;
}
// -----------------------------------------------------------------------------------------






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();
	}
}

// Permette di associare una funzione alla pressione 
// del tasto enter su una text
//----------------------------------------------------
function EnterFn(e, fn)
{
	fn = fn || '';
	if (checkEnter(e)) {
		if (fn) fn(e);
		return true;
	} else return false;
}
// verfica che il singolo valore immesso sia un numero
function checkEnter(e) {
	var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode
	//status = charCode // see ASCII character value!
	if (charCode==13) return true
	else return false
}
//----------------------------------------------------




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='' ;
	window.open(url, id, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable=1');
}
function zoom_popup (url) {
	width='720';
	height='580';
	id='zoomphoto';
	window.open(url, id, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=0,resizable=0');
}
//-->

function ColorSelect() {
  var Dolly=GetRef("dolly"), Body=GetRef("Contenitore");
  for(var r=0;r<=255;r+=15) {
   for(var g=0;g<=255;g+=15) 
    for(var b=0;b<=255;b+=15) {
	 var Color=Dolly.cloneNode(true);
	 var BgColor="#"+toHex(r)+toHex(g)+toHex(b);
	 Color.style.backgroundColor=BgColor;
	 Color.id="";
	 Color.onclick=function() {alert("Scelto colore "+this.style.backgroundColor);}
	 Color.title=BgColor;
	 Body.appendChild(Color);
	}
   var Color=Dolly.cloneNode(true);
   Color.innerHTML="<br/>";
   Color.id="";
   Body.appendChild(Color);
  } 
 } //ColorSelect
*/