var DIGITS="0123456789";
var ALPHABETICS = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var SPECIAL = "ÁÀÂÃÅÄÆÇÉÈÊËÍÌÎÏÐÑÓÒÔÕÖØÚÙÛÜÝÞßáàâãåäæçéèêëíìîïðñóòôõöøúùûüýþÿ:.'";
var SPECIAL2 = "%!£$%&()?-;\t\n\r,/+*"
var MAIL = "@."
var URL ="/:.-_"

//******RESTITUISCE I VALORI DEI CHECKBOX SELEZIONATI	
function get_delval(form,box){							
		valore = "";
		for (j= 0; j < form.elements.length; j++) { 		 
			 if (form.elements[j].name == box) {                 				 
					 if(form.elements[j].checked) {
	                 	valore = valore + form.elements[j].value +", ";
	                 }
	         }
		}
		valore = valore.substr(0,(valore.length - 2));		////toglie l'ultima virgola
		form.app_hid.value = valore;
	}
///******VISUALIZZA UN ELENCO DI FOTO
function visfoto(idimp,tipo)
	{   		
         Vis = window.open("visfoto.asp?id="+idimp+"&imp="+tipo,'Visualizzafoto', 'width=350,height=500,Scrollbars=yes');				 
	}
///*****VISUALIZZA UNA FOTO
function Visual(immagine,server,actz,lunghezza,altezza)
	{
		dove = "http://"+server+"/admin/visualizza.php?file=" + immagine + "&act=" + actz;
		Vis = window.open(dove,'Visualizza', 'width='+lunghezza+',height='+altezza+',Scrollbars=yes');				 
	}	
///****CONTROLLA SE IL CAMPO E' VUOTO O CONTIENE UN DETERMINATO NUMERO DI CATRATTERI
function ISfield(data,vuoto,n_ch){
	if ((vuoto=="no")&&(data.value=="")){						//il campo non può essere vuoto ma lo è
		alert("Ce champ est obligatoire")
		data.focus();
		data.select();
		return false;
	}
	else if (data.value!=""){		
		if ((data.value.length < n_ch)||(n_ch=="0")) return true;			
		else{
			alert("Maximum characters number for this field is "+n_ch)
			data.focus();
			data.select();
			return false;
		}
	}
	else{
		return true;
	}	
}
///****CONTROLLA SE IL CAMPO È NUMERICO
function ISnumber(data,vuota) {
	if ((data.value == "") && (data.value.length < 255)){
		if (vuota != 'si') {
			alert("Ce champ est obligatoire")
			data.focus();
			data.select();
			return false;
			}
		else {			
			return true;
			}
		}	
	else if ((data.value != "") && (data.value.length < 255)){
		  okChar = DIGITS;
		  var thisChar;
		  var counter = 0;
		  for (var i=0; i < data.value.length; i++)  {
		      thisChar = data.value.substring(i, i+1);
		      if (okChar.indexOf(thisChar) != -1)
		         counter ++;
		  }
		  if (counter != data.value.length) {    
			  	alert("Ce champ doit etre numérique");
				data.select();
				data.focus();
				return false;
			}
		   else 
		   	{
			return true;
			}	
		  }
	  else{	
			alert("Ce champ est obligatoire");
			data.select();
			data.focus();
			return false;			
	  }
}
/////****CONTROLLA SE IL CAMPO CONTIENE UNA MAIL VALIDA
function ISemail(data,vuota){
	var emailok1=false;
	var emailok2=false;
	var email=data.value;
	okChar = DIGITS + ALPHABETICS + MAIL;
    if (email != "") {
	 					var thisChar;
  						var counter=0;  						
						for (var i=0; i < email.length; i++)  {
	     				    if (email.substring(i, i+1) == "@")
								{
								emailok1=true;
								}
							if (email.substring(i, i+1) == ".")
								{
								emailok2=true;
								}
							thisChar = email.substring(i, i+1);
						     if (okChar.indexOf(thisChar) != -1)
						     	counter ++;											
						 }				  
					 	if (counter != email.length) {    
	 				 		alert("One or more insert characters is not valid");
							data.select();
							data.focus();
							return false;
						}						
						else if ((emailok1 == false) || (emailok2 == false)){ 
					 		alert("Adresse E-mail pas valid");
							data.select();
							data.focus();
							return false;
						}
						else{							
							return true;							
						}
	}
	else if ((email == "") && (vuota == "no"))
		{
		alert ("Adresse E-mail obligatoire")
		data.focus();
		return false;
		}
	else return true;	
}
/////*****CONTROLLA SE IL CAMPO CONTIENE UN URL VALIDO
function ISurl(data) {
	if (data.value != ""){
	  okChar = DIGITS + ALPHABETICS + URL;
	  var thisChar;
	  var counter = 0;
	  for (var i=0; i < data.value.length; i++)  {
	      thisChar = data.value.substring(i, i+1);
	      if (okChar.indexOf(thisChar) != -1)
	         counter ++;
	  }
	  if (counter != data.value.length) {    
		  	alert("Web address not well formed\n ex.(http://www.sito.it)");
			data.select();
			data.focus();
			return false;
		}
	   else 
	   	{
		return true;
		}	
	  }
	  else{	
			return true;			
	  }
}
////****CONTROLLA SE IL CAMPO CONTIENE UNA DATA VALIDA (GIORNO)
function ISday(data) {
if ((data.value.length == 2))
		{
	 					var numStr= DIGITS;
  						var thisChar;
  						var counter = 0;
  						for (var i=0; i < data.value.length; i++)  {
     				    thisChar = data.value.substring(i, i+1);
      					if (numStr.indexOf(thisChar) != -1)
        			    counter ++;
  					  	}
 						 if (counter == data.value.length) {
						 	if ((data.value == "0") || (data.value == "00") || (data.value > "31")){
								alert ("The insert date is not valid");
								data.select();
								data.focus();
								return false;
							}
							else{
								return true;
							}
    					 }
						 else {
     					 	alert ("This field must be in numerical format");
							data.select();
							data.focus();
							return false;						 
						 	} 						 
	  }
	  else{
		 alert("Il giorno deve essere espresso \n in due cifre es. 05");
		 data.select();
		 data.focus();
		 return false;						 
	 }
	 }
////****CONTROLLA SE IL CAMPO CONTIENE UNA DATA VALIDA (MESE)
function ISmonth(data) {
if ((data.value.length == 2))
		{
	 					var numStr= DIGITS;
  						var thisChar;
  						var counter = 0;
  						for (var i=0; i < data.value.length; i++)  {
     				    thisChar = data.value.substring(i, i+1);
      					if (numStr.indexOf(thisChar) != -1)
        			    counter ++;
  					  	}
 						 if (counter == data.value.length) {
						 	if ((data.value == "0") || (data.value == "00") || (data.value > "12")){
								alert ("La data inserita non è valida");
								data.select();
								data.focus();
								return false;
							}
							else{
								return true;
							}
    					 }
						 else {
	     					alert ("Questo è un campo numerico");
							data.select();
							data.focus();
							return false;					 
						 } 						 
	  }
	  else{
		 alert("Il mese deve essere espresso \n in due cifre es. 07");
		 data.select();
		 data.focus();
		 return false;				 
	 }
	 }
////****CONTROLLA SE IL CAMPO CONTIENE UNA DATA VALIDA (ANNO)	 
function ISyear(data) {	 
if ((data.value.length == 4))
		{
	 					var numStr= DIGITS;
  						var thisChar;
  						var counter = 0;
  						for (var i=0; i < data.value.length; i++)  {
     				    thisChar = data.value.substring(i, i+1);
      					if (numStr.indexOf(thisChar) != -1)
        			    counter ++;
  					  	}
 						 if (counter == data.value.length) {
						 	if ((data.value == "0") || (data.value == "00") || (data.value == "000") || (data.value == "0000") || (data.value > "2200") || (data.value < "1936")){
								alert ("La data inserita non è valida");
								data.select();
								data.focus();
								return false;
							}
							else{
								return true;
							}
    					 }
						 else {
     					 	alert ("Questo è un campo numerico");
							data.select();
							data.focus();
							return false;
						 } 						 
	  }
	  else{
		 alert("L'anno deve essere espresso \n in quattro cifre es. 2002");
		 data.select();
		 data.focus();
		 return false;
	 }
	 }
////****CONTROLLA SE IL CAMPO CONTIENE TIME VALIDO (ORA)
function IShour(data) {
if ((data.value.length == 2))
		{
	 					var numStr= DIGITS;
  						var thisChar;
  						var counter = 0;
  						for (var i=0; i < data.value.length; i++)  {
     				    thisChar = data.value.substring(i, i+1);
      					if (numStr.indexOf(thisChar) != -1)
        			    counter ++;
  					  	}
 						 if (counter == data.value.length) {
						 	if (data.value > "23"){
								alert ("L' ora inserita non è valida");
								data.select();
								data.focus();
								return false;
							}
							else{
								return true;
							}
    					 }
						 else {
     					 	alert ("Questo è un campo numerico");
							data.select();
							data.focus();
							return false;						 
						 	} 						 
	  }
	  else{
		 alert("L' ora deve essere espressa \n in due cifre es. 05");
		 data.select();
		 data.focus();
		 return false;						 
	 }
	 }	 
////****CONTROLLA SE IL CAMPO CONTIENE TIME VALIDO (MINUTI)
function ISminute(data) {
if ((data.value.length == 2))
		{
	 					var numStr= DIGITS;
  						var thisChar;
  						var counter = 0;
  						for (var i=0; i < data.value.length; i++)  {
     				    thisChar = data.value.substring(i, i+1);
      					if (numStr.indexOf(thisChar) != -1)
        			    counter ++;
  					  	}
 						 if (counter == data.value.length) {
						 	if (data.value > "59"){
								alert ("Il formato dei minuti inseriti non è valido");
								data.select();
								data.focus();
								return false;
							}
							else{
								return true;
							}
    					 }
						 else {
     					 	alert ("Questo è un campo numerico");
							data.select();
							data.focus();
							return false;						 
						 	} 						 
	  }
	  else{
		 alert("I minuti devono essere espressi\n in due cifre es. 05");
		 data.select();
		 data.focus();
		 return false;						 
	 }
	 }	 	 
 ///******CONFERMA ELIMINAZIONE DI UN RECORD
function conf(form,box){
	var Ckbox = false;
	for (j= 0; j < form.elements.length; j++) { 
		 if (form.elements[j].name == box) {                 
				 if(form.elements[j].checked) {
                 	Ckbox = true;
                 }
         }
	}		
	if (Ckbox){
		if (confirm("==== Eliminare le voci selezionate? ====\n\n    Per procedere premere OK altrimenti\nper fermare l'eliminazione premere Annulla")){
			return true;			
		}
		else{
			return false;
		}
	}
	else{
	alert("Non hai selezionato nessun\n   elemento da cancellare");
	return false;
	}
}
////***** 
////*****CONTROLLA L'ESTENSIONE DEL FILE
	function ISext(data,file1,file2){		 
		lstr = 	data.value.length;		
		if (lstr > 0){
			strno = lstr - 3;
			ext = data.value.substring(strno, lstr);
			check1 = "no"
			check2 = "no"		
			if (ext.toLowerCase() == file1.toLowerCase()){ 
				check1 = "si";
			}				
			if (ext.toLowerCase() == file2.toLowerCase()) check2 = "si";								
			if ((check1 == "si") || (check2 == "si")) {
				return true;
			}
			else{			
				data.focus();
				data.select();
				data.value = "";
				if (file2 != "0"){
					alert ("Il file deve avere estensione '"+file1+"' o '"+file2+"'");
					return false;
				}	
				else {
					alert ("Il file deve avere estensione '"+file1+"'");
					return false;
				}			
				return false;	
			}
		}	
		else return true;	
	}
///*****  
///*****VERIFICA CHE IN UN MENU A TENDINA NON SIA STATA SCELTA UNA DETERMINATA OPZIONE
	function ISelect(data,opz){		
		if (data.value == opz){
			alert("Attenzione l'opzione selezionata non è valida");
			return false;
			data.select();
			data.focus();			
		}
		else return true;
	}
///*****