	function handler(e,l)
	{
	 	if (!e) var e = window.event;
	 	
	 	if (!l) var l = (e.target) ? e.target : e.srcElement
	 	
	 	//alert(l);
	 	
		if (navigator.appVersion.indexOf('MSIE') == -1)
		{
			document.getElementById('coordinataX').value = e.pageX;
			document.getElementById('coordinataY').value = e.pageY+7;
		}
		
		else
		{
			document.getElementById('coordinataX').value = e.screenX;
			document.getElementById('coordinataY').value = e.screenY-118;
		}
		
		document.getElementById(l).style.top = document.getElementById('coordinataY').value;
		document.getElementById(l).style.left = document.getElementById('coordinataX').value;
		document.getElementById(l).style.display = 'block';
	}

function doSomething(e) {
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	alert('Character was ' + character);
}


function getMouseXY(e) {

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
var tempX = 0
var tempY = 0
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
//   document.Show.MouseX.value = tempX
//  document.Show.MouseY.value = tempY
   document.getElementById('ModuloMultilingua').style.left = tempX+'px'
  document.getElementById('ModuloMultilingua').style.top = (tempY+12)+'px'
  return true
}

function ImpostaCampiId(nomeCampo,volte,valore,altroValore,altroNomeCampo)
{
	if (valore != '')
	{
		for (var i = 0; i < volte; i++)
		{
			var qualeCampo = nomeCampo+i;
			//alert(qualeCampo);
			document.getElementById(qualeCampo).value = valore;
			document.getElementById(qualeCampo).className='InputModificato';
		}
	}
	
	if (altroValore != '')
	{
		for (var i = 0; i < volte; i++)
		{
			document.getElementById(altroNomeCampo).value = altroValore;
			document.getElementById(altroNomeCampo).className='InputModificato';
		}
	}
}

function ApriFinestra(url,xfin,yfin)
{
	var y = screen.availHeight;
	var x = screen.availWidth;

	var py = (y-yfin)/2;
	var px = (x-xfin)/2;
	var posy = Math.round(py);
	var posx = Math.round(px);
	
	if (arguments[3] == 'YES')
	{
		var str = "width="+xfin+",height="+yfin+",scrollbars=1,status=yes,resizable=yes";
	}
	
	else
	{
		var str = "width="+xfin+",height="+yfin+",scrollbars=0,status=yes";	
	}
	
	var win=window.open(url,'',str);

	win.moveTo(posx,posy);
}

function ApriFinestraNomove(url,xfin,yfin)
{
	var y = screen.availHeight;
	var x = screen.availWidth;
	var py = (y-yfin)/2;
	var px = (x-xfin)/2;
	var posy = Math.round(py);
	var posx = Math.round(px);
	
	if (arguments[3] == 'YES')	
	{
		var str = "width="+xfin+",height="+yfin+",scrollbars=1,status=yes,resizable=yes";
	}

	else	
	{
		var str = "width="+xfin+",height="+yfin+",scrollbars=0,status=yes";
	}
	
	var win=window.open(url,'',str);
}

function Attenzione(lingua,camere,giorni,valore)
{
	ApriFinestra('pre_pop_up.php?lingua='+lingua+'&camere='+camere+'&giorni='+giorni+'&valore='+valore,'180','120');
	return false;
}

/*Per i campi obbligatori associare a ciascuno la proprieta' ".richiesto" facendo attenzione a radio button e checkbox a cui tale proprieta
 va associata all'elemento "this.nome_campo[0]". All'elemento checkbox va anche associato il numero di opzioni che devono essere
 obbligatoriamente spuntate trmite la proprieta' ".quanti" applicata sempre a "this.nome_campo[0]".
 Per i campi numerici associare a ciascun campo la proprieta' ".numerico", escluso il campo partita iva.*/

function VerificaForm(f,lingua) 
{
	var campo_assente = "<ul>";
	var campo_non_sufficiente = "<ul>";
	var campo_numerico = "<ul>";
	var campo_gia = new Array();;
	
	if (f.email && f.email.value != '' && f.email.richiesto == true)
	{
		var pattern = /([\w]+)@([a-zA-Z0-9\-]+)\.([\D]+)/;
		var text = f.email.value;
		var ver = text.match(pattern);
		
		if (ver == null)
		{
			//alert(ver);
			ApriFinestra('./pop_up.php?lingua='+lingua+'&id_messaggio=7','360','180');
			return false;
		}
	}
	
	if (f.emailconferma)
	{
		if (f.emailconferma.value != f.email.value)
		{
			ApriFinestra('./pop_up.php?lingua='+lingua+'&id_messaggio=11','360','180');
			return false;
		}
	}
	
	if (f.iva)
	{
		if (isNaN (f.iva.value))
		{
			ApriFinestra('./pop_up.php?lingua='+lingua+'&id_messaggio=4','360','180');
			return false;
		}
	}
	
	k = 0;
	
	for (var i = 0; i < f.length; i++) 
	{
		var campo = f.elements[i];

		if (campo.numerico == true)
		{
			if ((campo.type == "text") || (campo.type == "textarea") || (campo.type == "password") || (campo.type == "hidden")) 
			{
				if (isNaN(campo.value)) 
				{
					campo_numerico += "<li>"+campo.id.replace('temp','')+"</li>";
					continue;
				}
			}
		}

		if (campo.richiesto == true)
		{
			if ((campo.type == "text") || (campo.type == "textarea") || (campo.type == "password") || (campo.type == "file") || (campo.type == "hidden")) 
			{
				if ((campo.value == null) || (campo.value == "") || (campo.value == "0000-00-00") || (campo.value == "0000-00-00 00:00:00")) 
				{
					campo_assente += "<li>"+campo.id.replace('temp','')+"</li>";
					continue;
				}
					
				if (campo.numerico == true && campo.value == 0)
				{
					campo_assente += "<li>"+campo.id.replace('temp','')+"</li>";
					continue;
				}
			}
		
			else if ((campo.type == "select-one") && (campo.selectedIndex == 0))
			{
				campo_assente += "<li>"+campo.id.replace('temp','')+"</li>";
				continue;
			}
		
			else if ((campo.type == "select-multiple") && (campo.selectedIndex == 0))
			{
				campo_assente += "<li>"+campo.id.replace('temp','')+"</li>";
				continue;
			}
		
			else if (campo.type == "radio")
			{
				var gia = 0;
				var chk = false;
				
				//alert('radio: '+eval('document.modulo.'+campo.name+'.length;'));
				
				var len = eval('document.modulo.'+campo.name+'.length;');
				
				for (h=0; h<len; h++)
				{
					chk = eval('document.modulo.'+campo.name+'['+h+'].checked;');
					
					if (chk == true)
					{
						//alert(chk);
						
						gia++;
					}
				}

				if (gia == 0)
				{
					campo_assente += "<li>"+campo.id.replace('temp','')+"</li>";
				}
			}
			
			else if ((campo.type == "checkbox"))
			{
// ancora da verificarne il funzionamento
				var gia = 0;
				
				for (h=0; h<campo_gia.length; h++)
				{
					if (campo.id == campo_gia[h])
					{
						gia++;
					}
				}

				if (gia == 0)
				{
					campo_gia[k] = campo.id;
					k++;
					
					//document.write (campo.quanti+' - '+campo.type+' - '+campo.id+' - '+campo.value+' - '+campo.checked+' - '+f.elements[campo.id].length+'<br>');
					
					var pieni = 0;
					
					for (j=0; j<f.elements[campo.id].length; j++)
					{
						if (f.elements[campo.id][j].checked)
						{
							pieni++;
						}
					}

					if (campo.type == "checkbox")
					{
						if (pieni < campo.quanti)
						{
							campo_assente += "<li>"+campo.id.replace('temp','')+"</li>";
							campo_non_sufficiente += "<li>"+campo.id.replace('temp','')+"</li>";
						}
					}
				
					else
					{
						if (pieni == 0)
						{
							campo_assente += "<li>"+campo.id.replace('temp','')+"</li>";
						}
					}
					
					continue;
				}
				
				else
				{
					continue;
				}
			}
		}
	}
	
	campo_numerico += '</ul>';
	campo_assente += '</ul>';
		
	if (campo_assente != '<ul></ul>' || campo_numerico != '<ul></ul>') 
	{	
		ApriFinestra('./pop_up.php?lingua='+lingua+'&id_messaggio_numerico=2&id_messaggio_assente=1&campo_numerico='+campo_numerico+'&campo_assente='+campo_assente,'360','180','YES');
		return false;
	}

	if (f.password) 
	{
		if (f.password.value != f.conferma_password.value) 
		{
			ApriFinestra('./pop_up.php?lingua='+lingua+'&id_messaggio=7','360','180');
			return false;
		}
	}	

	if (f.privacy)
	{
		if (f.privacy[0].checked == true) 
		{
			return true;
		}
		
		else 
		{
			ApriFinestra('./pop_up.php?lingua='+lingua+'&id_messaggio=6','360','180');
			return false;
		}
	}	

	if (f.registrazione_mailinglist)
	{
		if (f.registrazione_mailinglist[0].checked == true) 
		{
			return true;
		}
		
		else 
		{
			ApriFinestra('./pop_up.php?lingua='+lingua+'&id_messaggio=6','360','180');
			return false;
		}
	}	
}
