function writemailto(utente,dominio,ext,stile){		
		
	document.write('<a href=\"mailto:' + utente + '@' + dominio + '.' + ext + '\"  class=\"' + stile +'\">'+utente+'@'+dominio+'.'+ext+'</a>');
}

//======================================
//  FUNZIONE GENERALI TRIM
//======================================
function Ltrim(s){
	
	var s1
	var re;
  
  	re=/^\s+/g;
  	
	s1 = s.replace(re,"");
	
	return s1;
}

function Rtrim(s){
	
	var s1
	var re;
  
  	re=/\s+$/g;
  	
	s1 = s.replace(re,"");
	
	return s1;
}

function trim(s){
	
	var s1
	var re;
	
	re = /\s+$|^\s+/g;
  	s1 = s.replace(re,"");
	
	return s1;
}

//======================================
//  FUNZIONE CHE CONTROLLA LA LOGIN 
//======================================
function checkLogin(){
	
	var userid, psw, msg;
	
	msg = '';
	userid = trim(document.frm_login.userid.value);
	psw = trim(document.frm_login.psw.value);
	
	if (psw.length == 0) msg='Inserire la password';
	if (userid.length == 0) msg='Inserire il nome utente';
	
	if (msg != '' ){
		alert(msg);
		return false;
	}else
		return true;
}

//======================================
//  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 = 0;
		// 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=no,menubar='+menub;
	
	// 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 ;
	
	win = window.open(pagina,'',settings)
	win.window.focus();
}

//==========================================
//  FUNZIONE CHE RIDIMENSIONA UNA FINESTRA 
//==========================================

function ridimensiona(x, y, pos) {
	
	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)
	}
}


//*******************************************************************************************
// Funzioni per il controllo sintattico dei campi di form
// checkRequiredFields()

// Controlla che i dati obbligatori siano inseriti.
// Riceve in ingresso l'elenco dei campi obbligatori separati da ;
//*******************************************************************************************
function checkRequiredFields(idLang,form_name,ElencoCampi) // 'campo1;campo2;campo3'
	{
		
	  // var length = document.form.elements.length;
	   var length = eval("document."+form_name+".elements.length");
	   var name, value, lunghezzaCampo;  // contengono il nome, il valore e la lunghezza di ogni entry
	   var index = 0;   // indice dei campi dell'intera form
	   
	   var count = 0;
	   var errorLevel = 0;  
	   var tipo;
	 
	   if (idLang=='') {
		idLang="IT";	
		}
		if (idLang.toUpperCase()=='IT') {
	   		var messaggio = 'I campi in grassetto sono obbligatori!'
	   }else{
	   		var messaggio = 'Bold fields are compulsory!'
	   }
	   var ElencoCampi_array = ElencoCampi.split(";")
	
	   // per ogni elemento della form
	  while (index < length)
	   {      
	       count++;
		
		for (loop=0; loop < ElencoCampi_array.length; loop++)
	   	{
	   	
		  //alert(ElencoCampi_array[loop])
	
	         //legge il nome ed il suo valore
	         name  = eval("document."+form_name+".elements[index].name");
	         
	       	  //Controllo se il campo della form è nell'elenco dei campi obbligatori
		  if (name == ElencoCampi_array[loop])
		       
		       {
		      
					valore = eval(trim("document."+form_name+".elements[index].value"));
					lunghezzaCampo = valore.length;
					
					if ((errorLevel == 0) && (lunghezzaCampo == 0) )  
			       		errorLevel = index+1;
			}
		}
	
		index++;
	   }
	   if (errorLevel > 0 ) { 
	   		alert(messaggio); 
			return false;
		} 
		
	   return true;
	   
	}
//*******************************************************************************************
/*********************************************************************************************
	CONTROLLO SINTATTICO DELL'EMAIL
**********************************************************************************************/
function checkMail(idLang,field_mail)
{
	
	var x = field_mail.value;
	var x2 = field_mail.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	if ((filter.test(x)) || (x2 ==0)) {
		 //alert('YES! Correct email address');
		 return true;
	}else{
		 
		 if (idLang=='IT') {
	   		alert('Un indirizzo di posta deve essere nel formato utente@dominio.ext');
		 }else{
		   	alert('Un indirizzo di posta deve essere nel formato utente@dominio.ext (da tradurre in UK)');
		  }
		 field_mail.value = "";
         field_mail.focus(); 
         field_mail.select();
         return false;  
	}
}
