var keylist = "abcdefghijklmnopqrstuvwxyz1234567890";            
//var temp = ''                                                  
function generatepass(plength){                                  
  temp = '';                                                       
  for (i=0; i<plength; i++)                                        
    temp += keylist.charAt(Math.floor(Math.random()*keylist.length));
  return temp;                                                     
}










function prefissoTelefono(bPaese)         
{                                  
  var bCod ="";                    
  if (bPaese == "PE") bCod = "+51";
  if (bPaese == "AL") bCod = "+355";
  if (bPaese == "DZ") bCod = "+213";
  if (bPaese == "SA") bCod = "+966";
  if (bPaese == "AR") bCod = "+54"; 
  if (bPaese == "AU") bCod = "+61"; 
  if (bPaese == "AT") bCod = "+43";           
  if (bPaese == "BE") bCod = "+32";           
  if (bPaese == "BZ") bCod = "+501";          
  if (bPaese == "BA") bCod = "+387";          
  if (bPaese == "BR") bCod = "+55";           
  if (bPaese == "BG") bCod = "+359";          
  if (bPaese == "CA") bCod = "+1";            
  if (bPaese == "CZ") bCod = "+42";           
  if (bPaese == "CL") bCod = "+56";           
  if (bPaese == "CN") bCod = "+8";            
  if (bPaese == "CY") bCod = "+357";          
  if (bPaese == "CR") bCod = "+506";          
  if (bPaese == "HR") bCod = "+385";          
  if (bPaese == "CU") bCod = "+53";           
  if (bPaese == "DK") bCod = "+45";           
  if (bPaese == "EG") bCod = "+20";           
  if (bPaese == "FI") bCod = "+358";          
  if (bPaese == "FR") bCod = "+33";           
  if (bPaese == "DE") bCod = "+49";           
  if (bPaese == "GR") bCod = "+30";           
  if (bPaese == "HK") bCod = "+852";          
  if (bPaese == "IS") bCod = "+354";          
  if (bPaese == "IN") bCod = "+91";           
  if (bPaese == "ID") bCod = "+62";           
  if (bPaese == "GB") bCod = "+44";           
  if (bPaese == "UK") bCod = "+44";           
  if (bPaese == "IR") bCod = "+98";           
  if (bPaese == "IQ") bCod = "+964";          
  if (bPaese == "IE") bCod = "+353";          
  if (bPaese == "IL") bCod = "+972";          
  if (bPaese == "IT") bCod = "+39";           
  if (bPaese == "JM") bCod = "+876";          
  if (bPaese == "YU") bCod = "+361";          
  if (bPaese == "KP") bCod = "+82";           
  if (bPaese == "KR") bCod = "+82";           
  if (bPaese == "JP") bCod = "+81";           
  if (bPaese == "LI") bCod = "+41";           
  if (bPaese == "LU") bCod = "+352";          
  if (bPaese == "MK") bCod = "+389";          
  if (bPaese == "MT") bCod = "+356";          
  if (bPaese == "MX") bCod = "+52";           
  if (bPaese == "MC") bCod = "+377";          
  if (bPaese == "MA") bCod = "+212";          
  if (bPaese == "NO") bCod = "+47";           
  if (bPaese == "NZ") bCod = "+64";           
  if (bPaese == "NL") bCod = "+31";           
  if (bPaese == "PK") bCod = "+92";           
  if (bPaese == "PL") bCod = "+48";           
  if (bPaese == "PT") bCod = "+351";          
  if (bPaese == "PY") bCod = "+595";          
  if (bPaese == "RO") bCod = "+40";           
  if (bPaese == "RU") bCod = "+7";            
  if (bPaese == "SM") bCod = "+378";          
  if (bPaese == "SG") bCod = "+65";           
  if (bPaese == "SY") bCod = "+963";          
  if (bPaese == "SK") bCod = "+421";          
  if (bPaese == "SI") bCod = "+386";          
  if (bPaese == "SO") bCod = "+252";          
  if (bPaese == "ES") bCod = "+34";           
  if (bPaese == "LK") bCod = "+94";           
  if (bPaese == "US") bCod = "+1";            
  if (bPaese == "ZA") bCod = "+27";           
  if (bPaese == "SE") bCod = "+46";           
  if (bPaese == "CH") bCod = "+41";           
  if (bPaese == "TH") bCod = "+66";           
  if (bPaese == "TW") bCod = "+886";          
  if (bPaese == "TN") bCod = "+216";          
  if (bPaese == "TR") bCod = "+90";           
  if (bPaese == "HU") bCod = "+36";           
  if (bPaese == "UY") bCod = "+598";          
  if (bPaese == "CO") bCod = "+297";          
  if (bPaese == "VE") bCod = "+58";           
  if (bPaese == "UA") bCod = "+380";          
  if (bPaese == "NG") bCod = "+234";          
  if (bPaese == "LT") bCod = "+370";          
  if (bPaese == "LV") bCod = "+371";          
  if (bPaese == "VG") bCod = "+1284";         
  if (bPaese == "EE") bCod = "+372";          
  if (bPaese == "AM") bCod = "+374";          
  if (bPaese == "KY") bCod = "+1345";         
  if (bPaese == "SN") bCod = "+221";          
  if (bPaese == "QA") bCod = "+974";          
  if (bPaese == "SL") bCod = "+232";          
  if (bPaese == "UZ") bCod = "+998";          
  if (bPaese == "AG") bCod = "+1268";         
                                   
  return bCod;                     
}       

function isEmail(who) {                                                                                                                                                    
	function isEmpty(who) {                                                                                                                        
		var testArr=who.split("");                                                                                                                    
		if(testArr.length==0)                                                                                                                         
			return true;                                                                                                                                 
		var toggle=0;                                                                                                                                 
		for(var i=0; i<testArr.length; i++) {                                                                                                         
			if(testArr[i]==" ") {                                                                                                                        
				toggle=1;                                                                                                                                   
				break;                                                                                                                                      
			}                                                                                                                                            
		}                                                                                                                                             
		if(toggle)                                                                                                                                    
			return true;                                                                                                                                 
		return false;                                                                                                                                 
	}                                                                                                                                              
                                                                                                                                                
	function isValid(who) {                                                                                                                        
		var invalidChars=new Array("~","!","@","#","$","%","^","&","*","(",")","+","=","[","]",":",";",",","\"","'","|","{","}","\\","/","<",">","?");
		var testArr=who.split("");                                                                                                                    
		for(var i=0; i<testArr.length; i++) {                                                                                                         
			for(var j=0; j<invalidChars.length; j++) {                                                                                                   
				if(testArr[i]==invalidChars[j]) {                                                                                                           
					return false;                                                                                                                              
				}                                                                                                                                           
			}                                                                                                                                            
		}                                                                                                                                             
		return true;                                                                                                                                  
	}                                                                                                                                              
                                                                                                                                                
	function isfl(who) {                                                                                                                           
		var invalidChars=new Array("-","_",".");                                                                                                      
		var testArr=who.split("");                                                                                                                    
		which=0;                                                                                                                                      
		for(var i=0; i<2; i++) {                                                                                                                      
			for(var j=0; j<invalidChars.length; j++) {                                                                                                   
				if(testArr[which]==invalidChars[j]) {                                                                                                       
					return false;                                                                                                                              
				}                                                                                                                                           
			}                                                                                                                                            
			which=testArr.length-1;                                                                                                                      
		}                                                                                                                                             
		return true;                                                                                                                                  
	}                                                                                                                                              
                                                                                                                                                
	function isDomain(who) {                                                                                                                       
		var invalidChars=new Array("-","_",".");                                                                                                      
		var testArr=who.split("");                                                                                                                    
		if(testArr.length<2||testArr.length>4) {                                                                                                      
			return false;                                                                                                                                
		}                                                                                                                                             
		for(var i=0; i<testArr.length; i++) {                                                                                                         
			for(var j=0; j<invalidChars.length; j++) {                                                                                                   
				if(testArr[i]==invalidChars[j]) {                                                                                                           
					return false;                                                                                                                              
				}                                                                                                                                           
			}                                                                                                                                            
		}                                                                                                                                             
		return true;                                                                                                                                  
	}                                                                                                                                              
                                                                                                                                                
                                                                                                                                                
	var testArr=who.split("@");                                                                                                                    
	if(testArr.length<=1||testArr.length>2) {                                                                                                      
		return false;                                                                                                                                 
	}                                                                                                                                              
	else {                                                                                                                                         
		if(isValid(testArr[0])&&isfl(testArr[0])&&isValid(testArr[1])) {                                                                              
			if(!isEmpty(testArr[testArr.length-1])&&!isEmpty(testArr[0])) {                                                                              
				var testArr2=testArr[testArr.length-1].split(".");                                                                                          
				if(testArr2.length>=2) {                                                                                                                    
					var toggle=1;                                                                                                                              
					for(var i=0; i<testArr2.length; i++) {                                                                                                     
						if(isEmpty(testArr2[i])||!isfl(testArr2[i])) {                                                                                            
							toggle=0;                                                                                                                                
							break;                                                                                                                                   
						}                                                                                                                                         
					}                                                                                                                                          
					if(toggle&&isDomain(testArr2[testArr2.length-1]))                                                                                          
						return true;                                                                                                                              
					return false;                                                                                                                              
				}                                                                                                                                           
				return false;                                                                                                                               
			}                                                                                                                                            
		}                                                                                                                                             
	}                                                                                                                                              
}                                                                                                                                               
                                                                                                                                                
/* With RegExp */                                                                                                                               
function isEmail2(who) {                                                                                                                        
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;                                           
	return(email.test(who));                                                                                                                       
}         

                                                                                                                                      