function checkEmail(email)
{
    alertMsg = "";
    if( email != "" )
    {
        if( email[0] != "@" )
        {
            isAt = false;
            isDNS = false;
            for(i = 0; i < email.length ; i++ )
                {
                   if( !isAlpha(email[i]) && !isNum(email[i]) && email[i] != " " && email[i] != "-" && email[i] != "_" && email[i] != "." && email[i] != "@" )
                       {
                           alertMsg += "Bad email input!\n";
                           break;
                       }
                    if( !isAt )
                        {
                            if( email[i] == "@" )
                                {
                                    isAt = true;
                                }
                        }
                        else
                            {
                                if( email[i] == "@" )
                                    {
                                        alertMsg += "You cannot have more than one @ in the email name!\n";
                                    }
                                if( !isDNS )
                                    {
                                        if( email[i] == "." )
                                            {
                                                if( email[i-1] != "@" )
                                                    {
                                                        isDNS = true;
                                                    }
                                                    else
                                                        {
                                                            alertMsg += "Bad email domain name!\n";
                                                        }
                                                if( i == ( email.length-1 ) )
                                                    {
                                                        alertMsg += "Email has invalid DNS input! Email name cannot end with '.'!\n";
                                                    }
                                            }
                                    }
                            }
                }


            if( isDNS == false )
                {
                    alertMsg += "Email has invalid DNS input !\n";
                }

            if( isAt == false )
                {
                    alertMsg += "Email need to have one @ !\n";
                }
        }
        else
            {
                alertMsg += "Email cannot start with @!\n";
            }
    }
    else
        {
            alertMsg += "Email field is empty!\n";
        }

    return alertMsg;
}

function checkForm()
{
	alertMsg = checkEmail(document.getElementById('email').value);
	result = true;
        if( alertMsg != "")
        {
            alert(alertMsg);
            result = false;
        }
        else
        {
            if(document.getElementById('message').value == "")
            {
                alert("Message cannot be empty!");
                result = false;                        
            }
        }
        
        return result;            
}

function isAlpha(charecter)
{
    isAlphaVal = true;
    if( charecter < "a" || charecter > "z" )
        {
            isAlphaVal = false;
        }
    return isAlphaVal;                
}

function isNum(charecter)
{
    isAlphaVal = true;
    if( charecter < "0" || charecter > "9" )
        {
            isAlphaVal = false;
        }
    return isAlphaVal;                
}
