/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
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='#FF0000';
	what.style.backgroundColor='#E0F3EB';
	what.style.color='#0e337d';}	
}
function deactivatefield(what){
	if (dom){
		what.style.borderColor='#0e337d';
	what.style.backgroundColor='#E0F3EB';
	what.style.color='#0e337d';}
	}
	
	





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
}
}
}

// JavaScript Document

/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
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 e ID="lista"
/////////////////////////////////////////////////////////////////// 
function openObject(openObject){
	
obj=document.getElementById(openObject);
obj.style.display="inline";}
		
function closeObject(closeObject){
obj=document.getElementById(closeObject);
obj.style.display="none";}		

/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
FUNZIONI CONTA CARATTERI IN INPUT e TEXAREA
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/


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

/*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
CONTROLLO TIPO ESTENZIONE
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
*********************************************************************************************/
function get_estensione(path) 
{    
	posizione_punto=path.lastIndexOf(".");	
	lunghezza_stringa=path.length;	
	estensione=path.substring(posizione_punto+1,lunghezza_stringa);	
	return estensione;
}

function controlla_estensione(path)
{	
	
	if(get_estensione(path)!="jpg" && get_estensione(path)!="gif" && get_estensione(path)!="png")
	{		
		alert("Il file deve avere estensione jpg / gif / png");	
	}
}
