//=====================================================
//  FUNZIONE CHE CONTROLLA IL CAMPO EMAIL DI UN FORM
//=====================================================			
function isEmailOk(data) {
  if (data.indexOf(".") != -1) {
      if (data.indexOf("@") != -1)  { 
	      return true;
		  }
		}
	else return false;	  
}

//=============================================================
//  FUNZIONE CHE CONTROLLA IL RIEMPIMENTO DEL CAMPO DI UN FORM
//=============================================================
function isSpace(data) {
	var contr2=0;
   	for(var i=0; i < data.length; i++){
		if(data.substring(i, i+1) != " ")
	   		contr2=1; 
	}   
	if  (contr2==1)   
		return(false);  
return(true);
}

//=============================================================
//  CHIEDE CONFERMA PRIMA DI ELIMINARE
//=============================================================
function elimina(){
    
    if (!confirm("Confermi l'eliminazione?")){
        return false;}
        else
            return true;
}
	
//=============================================================
//  AJAX: CONTROLLA SE UN VALORE E' GIA' INSERITO NEL DB
//=============================================================
function ckeck_campo(valore_campo_controllare, nome_form, nome_campo_messaggio, pagina_check, messaggio_di_errore){
	// si intercetta il browser utilizzato dall'utente
	if (window.XMLHttpRequest) {
		// mozilla, safari, ...
  		http_request = new XMLHttpRequest();
	}
	else {
		 // internet explorer
  		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	// si espone ciò che succederà quando arriverà la risposta dal server
	http_request.onreadystatechange = function(){
		if ( (http_request.readyState == 4) && (http_request.status == 200) ) {
			if (http_request.responseText==messaggio_di_errore){
				document.getElementById(nome_campo_messaggio).style.visibility = 'visible';
				document.getElementById(nome_campo_messaggio).style.display = 'block';
			} else {
				esegui_form = "document."+nome_form+".submit();";
				eval(esegui_form);
			}
		}
	}
	// si formula la richiesta utilizzando i due metodi "open()" e "send()" della classe di richiesta HTTP
	http_request.open("GET",pagina_check+document.getElementById(valore_campo_controllare).value);
 	http_request.send(null);
}

//======================================
//  FUNZIONE CHE APRE UNA FINESTRA 
//======================================
function apripagina(pagina,dx,dy,rsz,scrl,pos,menub){
	
	var settings, TopPosition, LeftPosition;

	//	screen.width    DIMENSIONE DELLO SCHERMO IN LARGHEZZA	
	//	screen.height  	DIMENSIONE DELLO SCHERMO IN ALTEZZA
	//	dx				DIMENSIONE DELLA FINESTRA IN LARGHEZZA
	//	dy				DIMENSIONE DELLA FINESTRA IN ALTEZZA
    if (pos==""){
		pos = "center";
	}
	if (pos=="center"){
		// allineamento della finestra in mezzo
		TopPosition = ((screen.height) / 2) - (dy/2);
		// allineamento della finestra in mezzo
		LeftPosition = ((screen.width) / 2) - (dx/2);
	}
	if (pos=="right"){
		// allineamento della finestra in alto a destra
		TopPosition = 0;
		// allineamento della finestra a destra
		LeftPosition = (screen.width) - dx -10;
	}
	if (pos=="left"){
		// allineamento della finestra in alto a sinistra
		TopPosition = 0;
		// allineamento della finestra a destra
		LeftPosition = 0;
	}
	
	if (menub==""){
		menub = "yes";
	}
		
	// settaggio delle caratteristiche della finestra da aprire
	//settings ='height='+dy+',width='+dx+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrl+',resizable='+rsz+',titlebar=yes,status=yes,menubar='+menub;
	settings ='height='+dy+',width='+dx+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrl+',resizable='+rsz+',titlebar=no,status=no,menubar=no';
	
	// se esite gia' una finestra aperta allora la chiudo e la distruggo;
	//if (win != null){
	//	win.close();
	//	win = null;
	//}
	
	// apro una nuova finestra e le assegno il focus il nome della nuova finestra
	// (secondo campo nell'elenco parametri) non deve contenere nulla ;
	// se il campo nomepagina non è vuoto apro sempre nella stessa finestra che 
	// ha sempre lo stesso nome 
	
	//win = window.open(pagina,'',settings)
	
	//win = window.open(pagina,'ciccio',settings)
	win = window.open(pagina,'ciccio',settings)
	win.window.focus();
}

//==========================================
//  FUNZIONE CHE RIDIMENSIONA UNA FINESTRA 
//==========================================

function ridimensiona(x, y, pos) {
	
	//self.resizeTo(x+10,y+28);
	self.resizeTo(x+10,y+50);
	self.moveTo((screen.width - x)/2, (screen.height - y)/2)
	
	if (pos==""){
		pos = "center";
	}
	if (pos=="center"){
		// allineamento della finestra in mezzo
		self.moveTo((screen.width - x)/2, (screen.height - y)/2)
	}
	if (pos=="right"){
		// allineamento della finestra in alto a destra
		self.moveTo((screen.width) - x -10, 0)
	}
	if (pos=="left"){
		// allineamento della finestra in alto a sinistra
		self.moveTo(0 , 0)
	}
}

//=============================================
//  FILTRA IL NOME DEL FILE UPLODATO SUL SERVER 
//=============================================
function check_allegato(campo_input){
	path_array = campo_input.split("\\");
	var filtro_allegato=/^[a-zA-Z0-9\.\_\-]+$/;
	if (!filtro_allegato.test(path_array[path_array.length-1])) {
		return false;
	}
	return true;
}