function notNullCheck(str)
{
    if ((str) && (str.length > 0))
        return true;
    else
        return false;
}

function basicNameCheck(str)
{
    if (str.search(/[^a-zA-Z0-9 '\-]/) == -1)
        return true;
    else
        return false;
}

function basicTextCheck(str)
{
    if (str.search(/[^0-9a-zA-Z' _:;&!"\-\.\/\(\)\.\*\+\?\r\t\n]/) == -1)
        return true;
    else
        return false;
}

function basicAuthorCheck(str)
{
    if (str.search(/[^a-zA-Z ]/) == -1)
        return true;
    else
        return false;
}

function basicNumericCheck(str)
{
    if (str.search(/[^0-9]/) == -1)
    {
        if (!str.match(/\./g))
            return true;
        else if (str.match(/\./g).length == 1)
            return true;
    }

    return false;
}

function basicPeriodCheck(str)
{
    if (str.search(/[^A-Za-z0-9 ~\.]/) == -1)
    {
        if (!str.match(/\./g))
            return true;
        else if (str.match(/\./g).length == 1)
            return true;
    }

    return false;
}

function basicEmailCheck(str)
{
    if (str.search(/[^0-9a-zA-Z@_\-\.]/) == -1)
    {
        if ((str.match(/@/g)) && ((str.match(/@/g)).length == 1))
        {
            if ((str.match(/\./g)) && ((str.match(/\./g)).length > 0))
                return true;
        }
    }

    return false;
}

function passwordCheck(str)
{
    if (str.search(/[^0-9a-zA-Z]/) == -1)
        return true;
    else
        return false;
}

function spaced(str)
{
    var newStr = str;

    while (newStr.search(/  /) > -1)
        newStr = newStr.replace(/  /g," ");

    if (newStr.charAt(0) == " ")
        newStr = newStr.substr(1,newStr.length-1);

    if (newStr.charAt(newStr.length-1) == " ")
        newStr = newStr.substr(0,newStr.length-1);

    return newStr;
}

function loginFormCheck(chkForm)
{
    if (notNullCheck(chkForm.uname.value))
    {
        if (basicEmailCheck(chkForm.uname.value))
        {
            if (notNullCheck(chkForm.pword.value = spaced(chkForm.pword.value)))
            {
                if (passwordCheck(chkForm.pword.value))
                {
                    return true;
                }
                else
                    alert('Password must be letters and numbers only');
            }
            else
                alert('Please enter your password');
        }
        else
            alert('Please enter a valid e-mail address');
    }
    else
        alert('Please enter your e-mail address');

    return false;
}

function regFormCheck(chkForm)
{
    if (notNullCheck(chkForm.sub_email_address.value))
    {
        if (basicEmailCheck(chkForm.sub_email_address.value))
        {
            if (notNullCheck(chkForm.pword1.value))
            {
                if (passwordCheck(chkForm.pword1.value))
                {
                    if (chkForm.pword1.value == chkForm.pword2.value)
                    {
                                        return true;
                    }
                    else
                        alert('Your passwords do not match');
                }
                else
                    alert('Password must be letters and numbers only');
            }
            else
                alert('Please enter a password');
        }
        else
            alert('Please provide a valid e-mail address');
    }
    else
        alert('Please enter an e-mail address');

    return false;
}

function deregFormCheck(chkForm)
{
    if (notNullCheck(chkForm.comments.value))
    {
        if ((chkForm.comments.value).length < 255)
        {
            if (basicTextCheck(chkForm.comments.value))
            {
                return true;
            }
            else
                alert('Comments can contain letters, numbers and standard punctuation only');
        }
        else
            alert('Please keep the length of your comment below 255 characters or feel free to e-mail us at mybslbooks@lexiconsignstream.com');
    }
    else
        return true;

    return false;
}

function suggestionFormCheck(chkForm)
{
    if (notNullCheck(chkForm.title.value))
    {
        if (basicTextCheck(chkForm.title.value))
        {
            if (notNullCheck(chkForm.author.value))
            {
                if (basicAuthorCheck(chkForm.author.value))
                {
                    if (notNullCheck(chkForm.comments.value))
                    {
                        if ((chkForm.comments.value).length < 255)
                        {
                            if (basicTextCheck(chkForm.comments.value))
                            {
                                return true;
                            }
                            else
                                alert('Comments can contain letters, numbers and standard punctuation only');
                        }
                        else
                            alert('Please keep the length of your comment below 255 characters');
                    }
                    else
                        return true;
                }
                else
                    alert('Author must be letters only');
            }
            else
                alert('Please tell us the author');
        }
        else
            alert('Story title can contain letters and standard punctuation only');
    }
    else
        alert('Please enter the name of the story');

    return false;
}

function feedbackFormCheck(chkForm)
{
    if (notNullCheck(chkForm.comments.value))
    {
        if ((chkForm.comments.value).length < 255)
        {
            if (basicTextCheck(chkForm.comments.value))
            {
                if (notNullCheck(chkForm.email_com.value))
                {
                    if (basicEmailCheck(chkForm.email_com.value))
                    {
                        return true;
                    }
                    else
                        alert('Please enter a valid email address');
                }
                else
                    return true;
            }
            else
                alert('Comments can contain letters, numbers and standard punctuation only');
        }
        else
            alert('Please keep the length of your comment below 255 characters');
    }
    else
        alert('Please enter your comments');

    return false;
}

