//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=250, width=400, 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";}	


/* FUNZIOINE CAMBIO LINGUA */
function cambiaLingua(){
window.location.replace('_function/_comuni/lingue/cookieSessionLanguage.php?submit&Language=' + Formlanguage.Language.value + '');
}


/*///////////////////////////////////////////////////////////////////
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 eliminazione? Operazione 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='#798AE0';
	what.style.backgroundColor='#FEF55F';
	what.style.color='#003399';}	
}
function deactivatefield(what){
	if (dom){
		what.style.borderColor='#cccccc';
	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;
	
}

/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
CONTROLLO ELIMINAZIONE RECORD
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/				
//onclick="return functionConferma();"
//<SCRIPT LANGUAGE=javascript  src="../../_js/comuni/comuni.js"></script>
			function functionConferma()
			{
			action = confirm ('Confermi eliminazione? Operazione non annullabile!')
			if(action==false){alert('operazione annullata');return false;}
			else{return true;}			
			}
			
			function functionConfermaPubblicazione()
			{
			action = confirm ('Confermi la pubblicazione? Potrai in ogni caso continuare a gestire l\'annuncio/articolo in seguito')
			if(action==false){alert('operazione annullata');return false;}
			else{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;
		}