<!--

// isLetter (c)
// isDigit (c)
// isEmpty(s)
// isWhitespace (s)
// isAlphanumeric (s)
// isEmail (s)
// validate_length (s, len)
// validate_contact(f)
// validate_registration(f)
// validate_login(f)


function isLetter (c)
{   
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function isEmpty(s)
{   
	// Check whether string s is empty.
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   
	// Returns true if string s is empty or 
	// whitespace characters only.
	var i;
	// whitespace characters
	var whitespace = " \t\n\r";
    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isAlphanumeric (s)
{   
	var i;
    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) ) ) return false;
    }

    // All characters are numbers or letters.
    return true;
}

function isEmail (s)
{   
	// Email address must be of form a@b.c -- in other words:
	// * there must be at least one character before the @
	// * there must be at least one character before and after the .
	// * the characters @ and . are both required
	//
	// For explanation of optional argument emptyOK,
	// see comments of function isInteger.
   
    // is s whitespace?
	// cant get this to work so comment out
    // if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { 
		i++;
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) 
	{
		return false;
	}
    else 
	{
		i += 2;
	}
	
    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { 
		i++;
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
	{
		return false;
	}
    else 
	{
		return true;
	}
}

function validate_length (s, len)
{
	var sLength = s.length;
	
	if (sLength > len)
	{
		return false;
	}
	else
	{
		return true;
	}
}
 

function validateOrder(f)
{
	var msg;
	var empty_fields = "";
	var errors = "";
	
	if (f.name.value == null || f.name.value == "") {
		empty_fields += "\n Name";
	}
	if (f.address == null || f.address.value == "") {
		empty_fields += "\n Address";
	}
	if (f.phone == null || f.phone.value == "") {
		empty_fields += "\n Telephone";
	}
	msg = "_______________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s). \n";
	msg += "Please correct these error(s) and re-submit.\n";
    msg += "_______________________________________________________________\n\n";
	

	if ( !(isDigit (f.football.value)) )
	{
		errors += "invalid Football quantity";
		msg += "- You must enter a valid Football quantity\n";
	}
	
	if ( !(isDigit (f.running.value)) )
	{
		errors += "invalid Running quantity";
		msg += "- You must enter a valid Running quantity\n";
	}
	
	if ( !(isDigit (f.rugby.value)) )
	{
		errors += "invalid Rugby quantity";
		msg += "- You must enter a valid Rugby Chair quantity\n";
	}
	
	
	if ( !(isDigit (f.basketball.value)) )
	{
		errors += "invalid Basketball quantity";
		msg += "- You must enter a valid Basketball quantity\n";
	}
	
	if ( !(isDigit (f.hockey.value)) )
	{
		errors += "invalid Hockey quantity";
		msg += "- You must enter a valid Hockey quantity\n";
	}
	
	if ( !(isDigit (f.tennis.value)) )
	{
		errors += "invalid Tennis quantity";
		msg += "- You must enter a valid Tennis quantity\n";
	}
	
	if ( !(isDigit (f.golf.value)) )
	{
		errors += "invalid Golf quantity";
		msg += "- You must enter a valid Golf quantity\n";
	}
	
	if ( !(isDigit (f.osteo.value)) )
	{
		errors += "invalid Osteoporosis quantity";
		msg += "- You must enter a valid Osteoporosis quantity\n";
	}
	
	if ( !(isDigit (f.cellulite.value)) )
	{
		errors += "invalid Cellulite  quantity";
		msg += "- You must enter a valid Cellulite quantity\n";
	}
	
	if ( !(isDigit (f.marathon.value)) )
	{
		errors += "invalid Marathon quantity";
		msg += "- You must enter a valid Marathon quantity\n";
	}
	
	
	if ( !(isEmail (f.email.value)) )
	{
		errors += "invalid email";
		msg += "- You must enter a valid email address\n\n";
	}
	
	if (empty_fields || errors)  
	{
		if (empty_fields)
		{
			msg += "- The following required field(s) are empty:" + empty_fields + "\n";
		}
		alert(msg);
		return false;
	}
	
	
}

//-->