// This function checks whether the user has entered other than characters in the name field.
 function validatestring(str1,str2)
   {
    for(i=0;i<str1.length;i++)
      {
        if(str1.charAt(i)=="0" || str1.charAt(i)=="1" || str1.charAt(i)=="2"|| str1.charAt(i)=="3"|| str1.charAt(i)=="4"|| str1.charAt(i)=="5"|| str1.charAt(i)=="6"|| str1.charAt(i)=="7"|| str1.charAt(i)=="8"|| str1.charAt(i)=="9")
         {
           alert("Invalid "+str2)
           return false
         }
       } 
      return true 
    }
//Validate email address entered by the user.
 function validateemail()
   {
    att=false
    dot=false
    email=document.registration.email.value
    l=document.registration.email.value.length
    
    if(email.charAt(l-1)==".")
     {
      alert("Email address cannot end with a \".\" ")
      document.registration.email.focus()
      return false
     } 
       
    if(email.charAt(0)=="" || email.charAt(0)=="@" || email.charAt(0)==".")
     {
      alert("Invalied email")
      document.registration.email.focus()
      return false
     }

    for(i=0;i<l;i++)
     {
      
      if(email.charAt(i)=='@')
        {
         
         if(email.charAt(i+1)==".")
          {
           alert("Invalied email")
           document.registration.email.focus()
           return false
          }
          att=true
        }
       else if(email.charAt(i)=='.')
        {
         dot=true
        }
      }
    
    if(!att)
      {
       alert("Invalid email id")
       document.registration.email.focus()
       return false
      }
    if(!dot)
      {
       alert("Invalid email id")
       document.registration.email.focus()
       return false
      }
     return true

    }

  function validate()
    {
      
      if(document.registration.username.value=="")
       {
        
        alert("Please enter your login name")
        document.registration.username.focus()
        return false
       }
      
      else if(document.registration.password.value=="")
       {
        alert("Please enter your password")
        document.registration.password.focus()
        return false
       }
      
            
      else if(document.registration.firstname.value=="")
       {
        alert("Please enter your firstname")
        document.registration.firstname.focus()
        return false
       }

      
 
      else if(document.registration.lastname.value=="")
       {
        
        alert("Please enter your lastname")
        document.registration.lastname.focus()
        return false
       }

      else if(document.registration.phone.value=="")
       {
        
        alert("Please enter your telephone number")
        document.registration.phone.focus()
        return false
       }
       
      else if(document.registration.email.value=="")
       {
        alert("Please enter your email address")
        document.registration.email.focus()
        return false
       }  
       
      else if(document.registration.address1.value=="")
       {
        
        alert("Please enter your address")
        document.registration.address1.focus()
        return false
       } 
       
       
      else if(document.registration.city.value=="")
       {
        
        alert("Please enter your city")
        document.registration.city.focus()
        return false
       }      
       
      else if(document.registration.state.value=="")
       {
        
        alert("Please enter your lastname")
        document.registration.state.focus()
        return false
       }     
 
      else if(document.registration.zip.value=="")
       {
        
        alert("Please enter your lastname")
        document.registration.zip.focus()
        return false
       }       
       

  
            
       else if(validatestring(document.registration.firstname.value,"First Name") && validatestring(document.registration.lastname.value,"last Name") && validateemail())
        {     
          return true
         //document.registration.submit()
        }
       
       else
        {
         return false
        } 
    
     }
  