<!-- The following validation scripts are based on scripts found in:               -->
<!-- http://developer.netscape.com/docs/examples/javascript/formval/overview.html  -->	

<!-- Avialable functions:                               -->
<!-- isEmail, checks for valid email address            -->
<!-- isEmpty, checks if field is empty                  -->
<!-- isWhitespace, checks for only spaces               -->
<!-- isInteger, checks valid integer                    -->
<!-- isLetter, accepts only letters of the alphabet     -->
<!-- isPrice, accepts format like 99999,99              -->
<!-- validYear, checks for four digits                  -->
<!-- isInternationalPhoneNumber (s [,eok]) True if string s is a valid international phone number. -->

var whitespace = " \t\n\r";
var digits = "0123456789";
var price = "0123456789.";
var defaultEmptyOK = false

// e-mail address validation 
function isEmail (s)

    // email address is mandatory

    // check if empty
{   if (isEmpty(s)) 
       return false;
   
    // check if only spaces
    if (isWhitespace(s)) 
       return false;
    
    var i = 0;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    // no @ found
    if ((i >= sLength) || (s.charAt(i) != "@")) 
       return false;

    // @ at first position
    if ( i == 0 ) 
       return false;

    // there must be at least 1 character after @ and before .
    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;
}

// check for empty field
function isEmpty (s)
{   return ((s == null) || (s.length == 0));
}

// check for only spaces
function isWhitespace (s)

{   var i;
    
    for (i = 0; i < s.length; i++)
    {   
        // check if current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1)
           return false;
    }

    // only spaces
    return true;
}

// check for 0,1,2,3,4,5,6,7,8,9
function isInteger (s)

{    // check if empty   
    if (isEmpty(s)) 
       return false;

    // check if only spaces
    if (isWhitespace(s)) 
       return false;
   
    var i;
    
    for (i = 0; i < s.length; i++)
    {   
        // check if current character is in (0,1,2,3,4,5,6,7,8,9)
        var c = s.charAt(i);

        if (digits.indexOf(c) == -1)
           return false;
    }

    // only spaces
    return true;
}

// check for letters of alphabet
function isLetter (s)

{

    // input not mandatory
    if (isEmpty(s))
       return true;

    var letters = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";   
    var i;
    
    for (i = 0; i < s.length; i++)
    {   
        // check if current character is in letters
        var c = s.charAt(i);

        if (letters.indexOf(c) == -1)
           return false;
    }

    // only spaces
    return true;
}

// year should return 4 integers digit
function validYear(s) {
	var len = 4;
	
	if((!isInterger(s)) && (len != 4))
		return false;
	
	return true;
}

// check for 0,1,2,3,4,5,6,7,8,9 and "."
function isPrice (s) 

{   
    // input not mandatory
    if (isEmpty(s))
       return true;
   
    var i;
    
    for (i = 0; i < s.length; i++)
    {   
        // check if current character is in (0,1,2,3,4,5,6,7,8,9 or ".")
        var c = s.charAt(i);

        if (price.indexOf(c) == -1)
           return false;
        else
           // we want two decimals
           if ( (c == ".") && (i != (s.length - 3)) )
              return false;
    }

    return true;
}

// isInternationalPhoneNumber (STRING s [, BOOLEAN emptyOK])
// 
// isInternationalPhoneNumber returns true if string s is a valid 
// international phone number.  Must be digits only; any length OK.
// May be prefixed by + character.
function isInternationalPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isInternationalPhoneNumber.arguments[1] == true);
    return (isPositiveInteger(s))
}


// -->
