//funzione per stampare (esempio: <div id='printable_zone'>testo da stampare</div id='printable_zone'>)


function print_zone(obj) 

{
	var content = document.getElementById('printable_zone').innerHTML;
	var print_window = window.open("", "ZoneImpr", "height=400, width=600, toolbar=0, menubar=0, scrollbars=1, resizable=1, status=0, location=0, left=10, top=10");
	
	print_window.document.body.style.color = '#000000';
	print_window.document.body.style.backgroundColor = '#FFFFFF';
	print_window.document.body.style.padding = "10px";
	print_window.document.title = 'TRACE';
	print_window.document.body.innerHTML += " " + content + " ";
	print_window.window.print();
	print_window.window.close();
	return true;
} 

/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
FUNZIONI DATAGRID DIV DISLAY INLINE e NONE
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/
///////////////////////////////////////////////////////////////////
// Funzioni per controllare la visualizzazione delle tabelle o div
// basta passare come valore l'oggetto che si deve visualizzare
// esempio: <a href="javascript:openObject('lista');">test</a>
// lista č ID="lista"
/////////////////////////////////////////////////////////////////// 
function openObject(openObject){
obj=document.getElementById(openObject);
obj.style.display="inline";}
		
function closeObject(closeObject){
obj=document.getElementById(closeObject);
obj.style.display="none";}	





/*///////////////////////////////////////////////////////////////////
Funzione per contare i caratteri di una text area
//////////////////////////////////////////////////////////////////*/
   var submitcount=0;
   function checkSubmit() {

      if (submitcount == 0)
      {
      submitcount++;
      document.Surv.submit();
      }
   }


function wordCounter(field, countfield, maxlimit) {
wordcounter=0;
for (x=0;x<field.value.length;x++) {
      if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}  // Counts the spaces while ignoring double spaces, usually one in between each word.
      if (wordcounter > 250) {field.value = field.value.substring(0, x);}
      else {countfield.value = maxlimit - wordcounter;}
      }
   }

function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
      {field.value = field.value.substring(0, maxlimit);}
      else
      {countfield.value = maxlimit - field.value.length;}
  }
  

		
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
				{
				
				  if(popUpWin)
				  {
					if(!popUpWin.closed) popUpWin.close();
				  }
				  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
				}
				
/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
CONTROLLO ELIMINAZIONE RECORD
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/				
//onclick="return functionConferma();"
//<SCRIPT LANGUAGE=javascript  src="../../_js/comuni/comuni.js"></script>
			function functionConferma()
			{
			action = confirm ('Confermi l\'operazione? Una volta selezionata non annullabile!')
			if(action==false){alert('operazione annullata');return false;}
			else{return true;}			
			}
			

/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
FUNZIONI CAMPI FORM INPUT TEXT, TEXTAREA, ECC.
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/	
///////////////////////////////////////////////////////////////////
// Funzione per cambiar colore ai campi input all'interno del form
// basta passare come valore l'oggetto che si deve visualizzare
// esempio: <INPUT name="xxx" class="textinput" 
// onfocus="activatefield(this);allLista();" onblur="deactivatefield(this)" size="11">
///////////////////////////////////////////////////////////////////
dom = (document.getElementById) ? 1 : 0; 
function activatefield(what){
	if (dom){
	what.style.borderColor='#A47D63';
	what.style.backgroundColor='#FFEFC3';
	what.style.color='#003399';}	
}
function deactivatefield(what){
	if (dom){
		what.style.borderColor='#C4A895';
	what.style.backgroundColor='';
	what.style.color='';}
	}
	
	
	
	
function campiFocus()
{
	var username = document.login.username.value;
	var password = document.login.password.value;

	if(username == "username")
	{
		document.login.username.value = "";
		document.login.username.focus();
		false; 
	}
	
	if(password == "password")
	{
		document.login.password.value = "";
		false; 
	}
	
}

function campiBlur()
{
var username = document.login.username.value;
var password = document.login.password.value;

	if(username == "")
	{
		document.login.username.value = "username";
	}
	
	if(password == "")
	{
		document.login.password.value = "password";
	}
	
}

function verificaLogin()
{

var username = document.login.username.value;
var password = document.login.password.value;

if(username == "" || username == "username")
					{
					
						 alert('Username non inserita correttamente!');
						 window.document.login.username.focus();
						 return false; 
						//openObject('verificaDettaglio');
						
							
					}
if(password == "" || password == "password")
					{
					
						 alert('Username non inserita correttamente!');
						 window.document.login.password.focus();
						 return false; 
						//openObject('verificaDettaglio');
						
							
					}					
					return true;
	
}




/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
CERCA
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/	
function verificaFormCerca(nomeForm)
{
	var chiave = document.forms[nomeForm].chiave.value;
	if (chiave=='')
		{
			alert('Inserire parola chiave');
			
			document.forms[nomeForm].chiave.focus();
			document.forms[nomeForm].chiave.style.borderColor='#0072BC';
			return false;
		}
		
		return true;
}



/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
NEWSLETTER
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/	
function verificaFormNewsletter(nomeForm)
{
	var email = document.forms[nomeForm].email.value;
	if (email=='')
		{
			alert('Inserire Email');
			
			document.forms[nomeForm].email.focus();
			document.forms[nomeForm].email.style.borderColor='#0072BC';
			return false;
		}
		else
		{
			return controllanewsletter(email,nomeForm,'email');
		}
		return true;
}


//CONTROLLO EMAIL
 //controllo form newsletter
function controllanewsletter(valueEmail,nomeForm,nomeCampo)
		{
			var valueEmail;
			var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
			
			if (!email_reg_exp.test(valueEmail) || (valueEmail == "") || (valueEmail == "undefined")) 
			{
				document.forms[nomeForm].elements[nomeCampo].select();
				alert("Inserire un indirizzo email corretto.");
				return false;
			}
			else
			return true;
		}
		
		
/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
MENU
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/		




/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
Contatti.php 
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/	
function infoFormControl()
{
	
	var dataArrivo = document.infoForm.dataArrivo.value;
	var dataPartenza = document.infoForm.dataPartenza.value;
	if(dataArrivo == "")
	{
		alert('Inserire data arrivo');
		document.infoForm.dataArrivo.focus();
		return false; 
	}
	
	if(dataPartenza == "")
	{
		alert('Inserire data partenza prevista');
		document.infoForm.dataPartenza.focus();
		return false; 
	}
	annoInizio = dataArrivo.substr(6,4);
	  	meseInizio = dataArrivo.substr(3,2);
	  	giornoInizio = dataArrivo.substr(0,2);
	  		
	  	annoFine = dataPartenza.substr(6,4);
	  	meseFine = dataPartenza.substr(3,2);
	  	giornoFine = dataPartenza.substr(0,2);	
		

		
		dataInizioControllo = annoInizio+meseInizio+giornoInizio;
		dataFineControllo = annoFine+""+meseFine+""+giornoFine;

	
		if(dataFineControllo < dataInizioControllo)
		{
			alert('La data di arrivo non puņ maggiore della data di partenza');
			document.infoForm.dataArrivo.focus();
			return false;
		}
	
	return true;
}

//autorizzazione trattamento dati personali
// JavaScript Document

//"Accept terms" form submission- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use

var checkobj

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}


/****************************************************************************
*****************************************************************************
Funzione formattazione campi	
<input name="dataNascitaRelataNotifica" class="inpunt"
onfocus="activatefield(this);" 
onblur="deactivatefield(this);"
onkeypress="FormatNumber(this, '##/##/####');" 
maxlength="10" size="10" value="" />
*****************************************************************************
*****************************************************************************/		
function FormatNumber(num, format, shortformat)
{

	if(format==null)
	{	
		format = "##/##/####";
		
	}					

	if(shortformat==null)
	{
		var shortformat = "";
		
	}

	var validchars = "0123456789";
	var tempstring = "";
	var returnstring = "";
	var extension = "";
	var tempstringpointer = 0;
	var returnstringpointer = 0;
	count = 0;

	// Get the length so we can go through and remove all non-numeric characters
	var length = num.value.length;
		

	// We are only concerned with the format of the phone number - extensions can be left alone.
	if (length > format.length)
	{
		length = format.length;
		
	};
	
	// scroll through what the user has typed
	for (var x=0; x<length; x++)
	{
		if (validchars.indexOf(num.value.charAt(x))!=-1)
		{
		tempstring = tempstring + num.value.charAt(x);
		
		};
	};
	// We should now have just the #'s - extract the extension if needed
	if (num.value.length > format.length)
	{
		length = format.length;
		extension = num.value.substr(format.length, (num.value.length-format.length));
		
	};
	
	// if we have fewer characters than our short format, we'll default to the short version.
	for (x=0; x<shortformat.length;x++)
	{
		if (shortformat.substr(x, 1)=="#")
		{
			count++;
			
		};
	}
	if (tempstring.length <= count)
	{
		format = shortformat;
		
	};

	
	//Loop through the format string and insert the numbers where we find a # sign
	for (x=0; x<format.length;x++)
	{
		if (tempstringpointer <= tempstring.length)
		{
			if (format.substr(x, 1)=="#")
			{
				returnstring = returnstring + tempstring.substr(tempstringpointer, 1);
				tempstringpointer++;
				//conta il numero
			}else{
				returnstring = returnstring + format.substr(x, 1);
				//aggiunge la barra
			}
		}
		
	}

	// We have gone through the entire format, let's add the extension back on.
		returnstring = returnstring + extension;
	
	//we're done - let's return our value to the field.
	num.value = returnstring;
	
	
	
	
}	
