<!-- Form Validation Code Starts -->

///////////////////// DSCRIPTS PRESENTS /////////////////////////////////////
//                                                                         //    
//   This script has been downloaded from http://dscripts.awardspace.com   //
//  ---------------------------------------------------------------------  //
//                                                                         //
//  Script Name: Form Validator                                            //
//  Written on: 25 September 2006                                          //        
//  Written by: Burhan Uddin                                               //        
//                                                                         //      
//  Browse: http://dscripts.awardspace.com for more free scripts.          //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
<!--

// Deep Email Validation
function emailCheck (emailStr) 
    {
        var emailPat=/^(.+)@(.+)$/
        var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
        var validChars="\[^\\s" + specialChars + "\]"
        var quotedUser="(\"[^\"]*\")"
        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
        var atom=validChars + '+'
        var word="(" + atom + "|" + quotedUser + ")"
        var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
        var matchArray=emailStr.match(emailPat)
        
        if (matchArray==null)
            {
                alert("The email address you provided is not valid! \n \n Check if you provided '@' & '.' symbol.")
                return false
            }
        var user=matchArray[1]
        var domain=matchArray[2]
        
        if (user.match(userPat)==null) 
            {
                alert("The email address you provided is not valid! \n \n It's username seems invalid.")
                return false
            }
            
        var IPArray=domain.match(ipDomainPat)
        if (IPArray!=null) 
            {
                // this is an IP address
                for (var i=1;i<=4;i++) 
                    {
                        if (IPArray[i]>255) 
                            {
                                alert("Destination IP address is invalid!")
                                return false
                            }
                    }
                return true
            }
            
        var domainArray=domain.match(domainPat)
        
        if (domainArray==null) 
            {
                alert("The email address you provided is not valid! \n \n It's domain name seems invalid.")
                return false
            }
            
        var atomPat=new RegExp(atom,"g")
        var domArr=domain.match(atomPat)
        var len=domArr.length
        if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
            {
                alert("The email address you provided is not valid! \n \n The address must end in a three-letter domain, or two letter country.")
                return false
            }
        if (len<2) 
            {
                var errStr="The email address you provided is not valid! \n \n This address is missing a hostname!"
                alert(errStr)
            return false
            }
        return true;
    }

// Form Validation

// Validate Name
function Validate()
    {
        if (contact_form.name.value=='')
            {
                alert("Please provide your name!");
                document.contact_form.name.focus();
                return (false);
            }
        
        // Validate Email
        if (contact_form.email.value=='')
            {
                alert("Please enter your email address!");
                document.contact_form.email.focus();
                return (false);
            }
        if (!emailCheck (contact_form.email.value) )
            {
                document.contact_form.email.focus();
                return (false);
            }
        
        // Validate Subject
        if (contact_form.subject.value=='')
            {
                alert("Please specify a subject for your contact!");
                document.contact_form.subject.focus();
                return (false);
            }
        
        // Validate Message
        if (contact_form.message.value=='')
            {
                alert("You should provide your message!");
                document.contact_form.message.focus();
                return (false);
            }        
        return(true);
    }

//-->