/***************PASSARE COME PARAMETRI IL NOME/ID DELL'IMMAGINE E IL NOME DEL FILE*/
function showImg(nome,nome_file){
	var nome;	
	document.images[nome].src= "images/" + nome_file;
}
/***************POP UP CON DIMENSIONI PREDEFINITE*******************/
function apriPopUp(nome_file,nome_win)
{
window.open(nome_file,nome_win, "width=820,height=560,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,top=10,left=10")
}

/**************AREA DI GESTIONE/SITO - MESSAGGIO PER FUNZIONE/LINK NON ANCORA ATTIVATO*************************/
function inRealizzazione(){
		alert("In realizzazione");
}

//cerca qualunque carattere alfanumerico compreso l'underscore [A-Za-z0-9], se il campo contiene "solo" un valore non consentito dà errore.
function CheckValueForNotEmpty(Field,nome_campo)
{	
	// Espressione regolare del campo field
	var field_reg_exp = /([\w])/;  //cerca qualunque carattere alfanumerico compreso l'underscore [A-Za-z0-9], se il campo contiene "solo" un valore non consentito dà errore.
		if (!field_reg_exp.test(Field.value) || (Field.value == "")) {
		       alert("Inserire il valore nel campo " + nome_campo);
		       Field.select();
		       return false;
		    }
	return(true)
}

//controlla l'indirizzo email
function CheckValueForValidEmail(Field)
{
	// Espressione regolare dell'email
	var email_reg_exp = /([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
		if (!email_reg_exp.test(Field.value) || (Field.value == "") || (Field.value == "undefined")) {
		       alert("Inserire un indirizzo email corretto.");
		       Field.select();
		       return false;
		}
		//controllo che sia inserito 1 solo indirizzo email
		var str;
		str = Field.value;
		str = str.toLowerCase();
		//alert(str);
		str1 = str.indexOf("@");
		str2 = str.lastIndexOf("@");
		//alert("indexOf: " + str1);
		//alert("lastIndexOf: " + str2);
		if (str1 != str2){
			alert("Inserire un solo indirizzo email.");
			Field.select();
			   return false;
		}

}
/*verifico che il campo contenga solo numeri*/
function CheckValueForNumeric(Field,nome_campo)
{
		var myRegExp = /^([0-9])+$/;		
		if (!myRegExp.test(Field.value))
		{
			alert("Inserire solo cifre nel campo: " + nome_campo);
			Field.select();
			return false;
		}
}
/*verifico che il CAP contenga 5 cifre*/
function CheckValueForCap(Field)
{
		var myRegExp = /^([0-9]{5})+$/;		
		if (!myRegExp.test(Field.value))
		{
			alert("Inserire il CAP nel formato 00000");
			Field.select();
			return false;
		}
}
/*seleziona il radio button cliccando su tutta la cella che lo contiene*/
function selRadio(Field,num)
{
	//alert(num);	
	Field[num].checked=true;	
}
/*controlla il numero massimo di caratteri per una input-textarea, da html.it*/
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\.\,\/]/
		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(theform,thelimit){
	var limit_text='<i>max <b><span id="'+theform.toString()+'">'+thelimit+'</span></b></i>'
	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); 
	}
}
