
//
// Javascript form field check handlers
//

function isAlphaNum(s)
{


	return (/[^\w ]/.test(s)==false);
}

function isEntry(field_text)
{
        if (field_text.length < 1)
                { return false; }
        else { return true; }
}

function isPhoneNumber(field_string)
{
	return(isInteger(stripCharsInBag(field_string,"()- ")) &&
			field_string.length > 9)

}

function isZIPCode(field_string)
{  
	var tmp_string;
	
	tmp_string=stripCharsInBag(field_string,"-");
   	return (isInteger(tmp_string) && 
            ((tmp_string.length == 5) ||
			(tmp_string.length == 9)))

}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't in bag.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function isInteger (s)
{
	var i;

    // Search through string's characters one by one
    // until we find a non-numeric 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.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function isMinLength (s, length)
{   
	if (s.length < length)
		return false;
	return true;

}

function isOverLength (s, length)
{   
	if (s.length > length)
		return false;
	return true;

}




function isEmail (field_string)
{       
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = field_string.length;

    // look for @
    while ((i < sLength) && (field_string.charAt(i) != "@"))
    { 
		i++
    }

    if ((i >= sLength) || (field_string.charAt(i) != "@")) 
		{
		return false;
		}
    else
		{
		i += 2;
		}

    // look for .
    while ((i < sLength) && (field_string.charAt(i) != "."))
    { 
		i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (field_string.charAt(i) != ".")) 
		{
		return false;
		}
    else
		{
		return true;
		}
}

