/*
// ------------------------- DO NOT EDIT THIS SECTION --------------------------
// $RCSfile: common_validate.js,v $
// $Author: vamosb $
// $Date: 2004/04/02 20:52:04 $
// $Revision: 1.1 $
// 
// Description: 
// 
// ------------------------- Copyright 2002 ZURIEL Kft -------------------------
// --------------------------- http://www.zuriel.hu ----------------------------
*/
  var whitespace = " \t\n\r";

  function isEmpty(s){
    return ((s == null) || (s.length == 0))
  }// End isEmpty

  function isWhitespace (s){
    var i;

    // 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;
  }// End isWhiteSpace

  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 whitespace.
      var c = s.charAt(i);
      if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
  }

  // Removes all whitespace characters from s.
  // Global variable whitespace (see above)
  // defines which characters are considered whitespace.
  function stripWhiteSpace (s){
    return stripCharsInBag (s, whitespace)
  }

  // Returns true if character c is a digit
  // (0 .. 9).
  function isDigit (c){
    return ((c >= "0") && (c <= "9"))
  }

  function isInteger (s){
    var i;
    if (isEmpty(s))
    return true;

    // 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 isEmail (s){
    if (isEmpty(s)) return true;

    // is s whitespace?
    if (isWhitespace(s)) return false;

	if (charInBagInString ("íéáûõúöüó /\\\'\"?!", 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 charInBagInString (bag, s){
  for (i = 0; i < s.length; i++){
	if (bag.indexOf(s.charAt(i)) > -1) return true;
  }
  
  return false
}
