function TrovaOccorrenze(carattere, stringa){
	arrayoccorrenze=stringa.split(carattere);
	return arrayoccorrenze.length;
	
	
}

function CambiaDimensione(campo){
	obj = document.getElementById(campo);
	stringa = obj.value;
	lunghezza = stringa.length;
	//alert("Caratteri: " + lunghezza);
	larghezza = obj.cols;
	altezzaattuale = obj.rows;
	nuovaaltezza = parseInt(lunghezza/larghezza);
	numeroacapi = TrovaOccorrenze("\n", stringa)
	nuovaaltezza = nuovaaltezza + numeroacapi;

	if (nuovaaltezza>altezzaattuale){
		obj.rows=nuovaaltezza;
	}
}

function IsInt(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function check_email(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
	
	
function colorarigatitolo(item){
	elem=document.getElementById(item);
	elem.style.backgroundColor='#c6dcf9';
	elem.style.Color='#FFFFFF';
}
function restorerigatitolo(item){
	elem=document.getElementById(item);
	elem.style.backgroundColor='#FFFFFF';
}

function keyPressSoloNumeri(_event)
{
  var keyPressed= _event.keyCode ? _event.keyCode : _event.which ? _event.which : _event.charCode;
	var isDigit;
	if (!isDigit)
  {
    var AllowedKeys = new Array(8, 48,49,50,51,52,53,54,55,56,57,9,37,39)
		for(var i=0; i<AllowedKeys.length; i++)
      if(keyPressed == AllowedKeys[i])
        return true;
	}
  return false;
}
function keyPressFloat(_event)
{
  var keyPressed= _event.keyCode ? _event.keyCode : _event.which ? _event.which : _event.charCode;
	var isDigit;
	if (!isDigit)
  {
    var AllowedKeys = new Array(8, 48,49,50,51,52,53,54,55,56,57,9,44,46,37,39)
		for(var i=0; i<AllowedKeys.length; i++)
      if(keyPressed == AllowedKeys[i])
        return true;
	}
  return false;
}


/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
	return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
	var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
	if (pressedkey.test(String.fromCharCode(e.which)))
		e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder)){
		if (lengthleft<0)
			theform.value=theform.value.substring(0,maxlength)
			placeholderobj.innerHTML=lengthleft
	}
}


function displaylimit(thename, theid, thelimit){
	var theform=theid!=""? document.getElementById(theid) : thename
	var limit_text='<b>Puoi inserire ancora <span id="'+theform.toString()+'">'+thelimit+'</span> caratteri</b>'
	if (document.all||ns6)
		document.write(limit_text)
		if (document.all){
			eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
			eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
		} else if (ns6){
			document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
			document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
		}
}