


//    Validates user entry forms
//        Returns true if OK
function validate(form)
{
    for (var i=0; i <form.length; i++)
    {
        var fi = form[i];

        //   Cheat 
        if ((fi.value == '789') || (fi.value == "test")) 
        {
            fi.value = "test";
            return true;
        }

        if ( (fi.name == 'f') && (isBlank(fi.value)) )
        {
            alert('Please enter your First Name.');
            form.f.focus();
            return false;
        }

        if ( (fi.name == 'l') && (isBlank(fi.value)) ) {
            alert('Please enter your Last Name.');
            form.l.focus();
            return false;
        }

        if ( (fi.name == 'e') && ((anyBlank(fi.value)) || (fi.value.indexOf('@') == -1) ))
        {
            alert('Please enter your Email address.');
            form.e.focus();
            return false;
        }
    }
    return true;
}


//    Returns true if str contains any white space
function anyBlank(str)
{
    if (str == null) 
        return true;
    else 
	{
        if (str.length == 0) 
            return true;
        else 
		{
            for (var i=0; i <str.length; i++) 
			{
                var c = str.charAt(i);
                if ( (c == ' ') && (c == '\t') )
                    return true;
            }
        }
    }
    return false;
}

//    Returns true if str is empty or consists of just white space
function isBlank(str)
{
    if (str == null) 
        return true;
    else {
        if (str.length == 0) {
            return true;
        }
        else {
            for (var i=0; i <str.length; i++) {
                var c = str.charAt(i);
                if ( (c != ' ') && (c != '\t') && (c != '\n') )
                    return false;
            }
        }
    }
    return true;
}

