function is_valid_number(theElement, pLang) 
{
  var str;
  str = theElement.value;
            
  if(isNaN(str) == true) 
  { 
   if (pLang == "d")
     alert(str + " ist keine gueltige Nummer!"); 
   else	
     alert(str + " is not a valid number!"); 
   theElement.select(); 
   theElement.focus();
  }
}

function isDate(theElement, pLang)                                                               
{                                                                                                    
 var DayArray =new Array(31,28,31,30,31,30,31,31,30,31,30,31);                                       
 var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");            
 var thisYear = null;                                                                                
 var thisMon = null;                                                                                 
 var thisDay = null;                                                                                 
 var today = null;   
 var iErrMsg;
 
 if (pLang == "d")
    iErrMsg = "Bitte geben Sie das Datum im Format DD.MM.YYYY ein!"; 
 else
    iErrMsg = "Please enter the date in the following format DD.MM.YYYY !"; 
                                                                                          
 inpDate = theElement.value;                                                                         
                                                                                                     
 if (inpDate.length == 0 ) return true;                                                              
                                                                                                     
 if (inpDate.substr(1,1)==".") inpDate = "0"+inpDate;                                              
 thisDay = inpDate.substr(0,2);                                                                      
                                                                                                     
 if (inpDate.substr(4,1)==".") inpDate = inpDate.substr(0, 3)+"0"+inpDate.substr(3, 10);           
                                                                                                     
 thisMonth = inpDate.substr(3, 2);                                                                   
 thisYear = inpDate.substr(6,4);                                                                     
                                                                                                     
 var filter=/^[0-9]{2}.[0-9]{2}.[0-9]{4}$/;                                                          
                                                                                                     
 if (! filter.test(inpDate))                                                                         
  {    
  	   alert(iErrMsg);                                  
       theElement.focus();                                                                           
       theElement.select();                                                                          
       return false;                                                                                 
  }                                                                                                  
                                                                                                     
  /* Check Valid Month */                                                                            
  var filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;                                                 
                                                                                                     
  if (! filter.test(thisMonth))                                                                      
  {                                                                                                  
     alert(iErrMsg);                                   
     theElement.focus();                                                                             
     theElement.select();                                                                            
     return false;                                                                                   
  }                                                                                                  
  /* Check For Leap Year */                                                                          
                                                                                                     
  N=Number(thisYear);                                                                                
                                                                                                     
  if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )                                                     
  {                                                                                                  
    DayArray[1]=29;                                                                                  
  }                                                                                                  
  /* Check for valid days for month */                                                               
                                                                                                     
  for(var ctr=0; ctr<=11; ctr++)                                                                     
  {                                                                                                  
   if (MonthArray[ctr]==thisMonth)                                                                   
   {                                                                                                 
      if (thisDay<= DayArray[ctr] && thisDay >0 )                                                    
           return true;                                                                              
       else                                                                                          
       {      
   			   if (pLang == "d")
     				  alert("Bitte geben Sie einen gueltigen Tag ein!"); 
  				 else	
     					alert("Please enter a valid day!");                                                                                       
           theElement.focus();                                                                       
           theElement.select();                                                                      
           return false;                                                                             
       }                                                                                             
    }                                                                                                
   }                                                                                                 
}           

function isTime (theElement, pLang)                                                                                                                                                                                                                                                                            
{                                                                                                                                                                                                               
  var thisHour   = null;                                                                                                                                                                                        
  var thisMinute = null;    
  var iErrMsg;
 
  if (pLang == "d")
     iErrMsg = "Bitte geben Sie die Uhrzeit im Format HH:MI ein!"; 
  else
     iErrMsg = "Please enter the time in the following format HH:MI!";                                                                                                                                                                                    
                                                                                                                                                                                                                
  inpTime = theElement.value;                                                                                                                                                                                   
                                                                                                                                                                                                                
  if (inpTime.length == 0 ) return true;                                                                                                                                                                        
                                                                                                                                                                                                                
  if (inpTime.substr(1,1)==":") inpTime = "0"+inpTime;                                                                                                                                                        
                                                                                                                                                                                                                
  thisHour = inpTime.substr(0,2);                                                                                                                                                                               
  inpTime = inpTime.substr(3);                                                                                                                                                                                  
                                                                                                                                                                                                                
  if (inpTime.length != 2 )                                                                                                                                                                                     
  {                                                                                                                                                                                                             
     alert(iErrMsg);                                                                                                                                                  
     theElement.focus();                                                                                                                                                                                        
     theElement.select();                                                                                                                                                                                       
     return false;                                                                                                                                                                                              
  }                                                                                                                                                                                                             
  else thisMinute = inpTime;                                                                                                                                                                                    
                                                                                                                                                                                                                
  var filter=/00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23/ ;                                                                                                                           
                                                                                                                                                                                                                
  if (! filter.test(thisHour))                                                                                                                                                                                  
  {                                                                                                                                                                                                             
     alert(iErrMsg);                                                                                                                                                  
     theElement.focus();                                                                                                                                                                                        
     theElement.select();                                                                                                                                                                                       
     return false;                                                                                                                                                                                              
  }                                                                                                                                                                                                             
                                                                                                                                                                                                                
  var filter=/00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59/ ;            
                                                                                                                                                                                                                
  if (! filter.test(thisMinute))                                                                                                                                                                                
  {                                                                                                                                                                                                             
     alert(iErrMsg);                                                                                                                                                  
     theElement.focus();                                                                                                                                                                                        
     theElement.select();                                                                                                                                                                                       
     return false;                                                                                                                                                                                              
  }                                                                                                                                                                                                             
                                                                                                                                                                                                                
  return true;                                                                                                                                                                                                  
}               

function CheckTime(theElement, pLang)                                                                                                                                                                                                                  
{                                                            
 if (!isTime(theElement, pLang) && theElement.value!="")            
 {                                                           
  theElement.focus(); 
  return false;                                       
 }   
 return true;                                                        
}                                                            
                                                             
function CheckDate(theElement, pLang)                              
{                                                            
 if (!isDate(theElement, pLang) && theElement.value!="")            
 {                                                           
  theElement.focus(); 
  return false;                                       
 }             
 return true;                                              
}         

function isEmailAddressOk(theElement, pLang) 
{
  var s = theElement.value;
  var localPartfilter1 = /^[^<>()\[\]\x5C.,;:@" ]+(\.[^<>()\[\]\x5C.,;:@" ]+)*@$/;
  var localPartfilter2 = /^"[^\r\n]+"@$/;
  var domainfilter = /^([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]|[a-zA-Z0-9])(\.([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]|[a-zA-Z0-9]))*$/;
  var sepPos = 0;
  var localPart;
  var domain;
  var localPartOk = false;
  var domainOk    = false;
  sepPos = s.lastIndexOf("@");
  localPart = s.substring(0,sepPos+1);
  domain    = s.substring(sepPos+1,s.length);
  if  (localPartfilter1.test(localPart))
      localPartOk = true;
  else if (localPartfilter2.test(localPart))
      localPartOk = true;
  else
      localPartOk = false;
  if (domainfilter.test(domain))
      domainOk = true;
  else
      domainOk = false;
  if ( (localPartOk==true && domainOk==true)||(s=="") )
      return true;
  else
   if (pLang == "d")
     alert(theElement.value + " ist keine gueltige E-Mail Adresse!"); 
   else	
     alert(theElement.value + " is not a valid e-mail address!");
  	
  theElement.focus(); 
  theElement.select(); 
  return false;
}                                                   
