////////////////////////////////////////////////////////////////////////////////
//
//    ATTENTION NETSCAPE NAVIGATOR 3.0 USERS!!!
//
//    If you see this text while using the site and you did NOT click on
//    View -> Source, you're using a buggy browser.
//
//    FOLLOW THESE STEPS
//
//    Read through these two steps before doing them.
//    1. Press your BACK BUTTON.
//    2. Click on REFRESH or RELOAD.
//
//    You should now be able to use the site without seeing this message.
//    This problem can however return if your browser does not cache this
//    document correctly.
//
//    UPGRADE YOUR BROWSER
//
//    Upgrade your browser to Netscape's latest and you will not have this
//    problem any more.
//
//    Netscape browsers can be found at http://home.netscape.com/
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//  checker 1.00  --  Please leave this notice.
//
//  By Juan Rubio (jrubio@ece.utexas.edu)  Last modified 2001-09-26
////////////////////////////////////////////////////////////////////////////////

//===================================================================
function checkNumber(theInput,minNumber,maxNumber)
{
    // only allow numbers to be entered
    var checkPattern = "0123456789";
    var checkStr = theInput.value;
    var allValid = true;
    var allNum = "";
    for (i = 0;  i < checkStr.length;  i++)
    {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkPattern.length;  j++)
            if (ch == checkPattern.charAt(j))
                break;
        if (j == checkPattern.length)
        {
            allValid = false;
            break;
        }
        if (ch != ",")
            allNum += ch;
    }
    if (!allValid)
    {
        alert("Please enter only digit characters in this field.");
        theInput.focus();
        return (false);
    }

    var RealNumber = parseInt(theInput.value,10);
    if ( RealNumber<minNumber || RealNumber>maxNumber )
    {
        alert("The number has to be between " + minNumber + " and " + maxNumber + ".");
        theInput.focus();
        return (false);
    }
}
//===================================================================
function checkPhone(theInput)
{
    // only allow numbers and some other symbols to be entered
    var checkPattern = "0123456789 ()+-";
    var checkStr = theInput.value;
    var allValid = true;
    var allNum = "";
    for (i = 0;  i < checkStr.length;  i++)
    {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkPattern.length;  j++)
            if (ch == checkPattern.charAt(j))
                break;
        if (j == checkPattern.length)
        {
            allValid = false;
            break;
        }
        if (ch != ",")
            allNum += ch;
    }
    if (!allValid)
    {
        alert("Only digits and the symbols (, ), +, - are allowed in this field.");
        theInput.focus();
        return (false);
    }
}
//===================================================================
function checkString(theInput)
{
    // only allow numbers to be entered
    var checkPattern = "0123456789";
    var checkStr = theInput.value;
    var allValid = true;
    var allNum = "";
    for (i = 0;  i < checkStr.length;  i++)
    {
        ch = checkStr.charAt(i);
        if ( ! ( (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z" ) || (ch == ' ') ) )
        {
            allValid = false;
        }
    }
    if (!allValid)
    {
        alert("Please enter only letters in this field.");
        theInput.focus();
        return (false);
    }
}
//===================================================================
function checkEmail(theInput)
{
    // test if valid email address, must have @ and .
    var checkPattern = "@.";
    var checkStr = theInput.value;
    var EmailValid = false;
    var EmailAt = false;
    var EmailPeriod = false;
    for (i = 0;  i < checkStr.length;  i++)
    {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkPattern.length;  j++)
        {
            if (ch == checkPattern.charAt(j) && ch == "@")
                EmailAt = true;
            if (ch == checkPattern.charAt(j) && ch == ".")
                EmailPeriod = true;
            if (EmailAt && EmailPeriod)
                break;
            if (j == checkPattern.length)
                break;
        }
        // if both the @ and . were in the string
        if (EmailAt && EmailPeriod)
        {
            EmailValid = true
                break;
        }
    }
    if (!EmailValid)
    {
        alert("The \"email\" field must contain an \"@\" and a \".\".");
        if ( theInput.value.length > 0 )
            theInput.focus();
        return (false);
    }
}
//===================================================================
function FormValidator(theForm)
{
    // --------------------------------------------------------------
    if(theForm.lastname.value == "")
    {
        alert("Please enter your name.");
        theForm.lastname.focus();
        return (false);
    }

    // --------------------------------------------------------------
    if(theForm.email.value == "")
    {
        alert("You must enter a valid email address.");
        theForm.email.focus();
        return (false);
    }

    if ( checkEmail(theForm.email) == false ) { return (false); }

    // --------------------------------------------------------------
    if(theForm.number.value == "")
    {
        alert("Please enter the number of the paper you are reviewing.");
        theForm.number.focus();
        return (false);
    }

    if ( checkNumber(theForm.number,1,39) == false ) { return (false); }

    // --------------------------------------------------------------
    // require at least one radio button be selected
    var rank1Selected = false;
    var rank2Selected = false;
    var rank3Selected = false;
    var rank4Selected = false;
    for (i = 0;  i < theForm.rank1.length;  i++)
    {
        if (theForm.rank1[i].checked)
            rank1Selected = true;
    }
    for (i = 0;  i < theForm.rank2.length;  i++)
    {
        if (theForm.rank2[i].checked)
            rank2Selected = true;
    }
    for (i = 0;  i < theForm.rank3.length;  i++)
    {
        if (theForm.rank3[i].checked)
            rank3Selected = true;
    }
    for (i = 0;  i < theForm.rank4.length;  i++)
    {
        if (theForm.rank4[i].checked)
            rank4Selected = true;
    }
    if ( !rank1Selected || !rank2Selected || !rank3Selected || !rank4Selected )
    {
        alert("Please make sure you rank this paper.");
        return (false);
    }

    // --------------------------------------------------------------
    // All validations were successful.
    return (true);
}
//===================================================================
