/* UPVALID.JS - User-Profile Validation Library
** ============================================
**
** This library contains functions for validating
** the fields of the User Profile form (profile.htm).
**
** Note that these very primitive validation
** routines are designed solely to demonstrate
** JS SmartForms for the devHead ScriptHead column.
** Real-world validation would call for much more
** robust coding.
*/

function isTextBoxValid(str)  // is text-box str valid?
  {
  if (isBlank(str) || str.indexOf("|") != -1)  // nope - blank and/or |s
    return false;
  else           
 // str=replace(str,"'","");
  // yep
    return true;
  }

function isListBoxValid(num)  // is list-box num valid?
  {
  if (num == 0)               // nope - blank (first) item selected
    return false;
  else                        // yep - nonblank item selected
  return true;
  }

function isZipValid(str)        // is zip str valid?
  {
  if (str.length != 5)          // nope - wrong str length
    return false;
  for (i=0; i<5; i++)
    {
    if (!isNum(str.charAt(i)))  // nope - # missing
      return false;
    }
  return true;                  // yep
  }

function isEMailValid(str)                   // is email str valid?
  {
  if (isBlank(str) || str.indexOf("|") != -1)  // nope - blank and/or |s
    {
    alert("Entrez votre adresse email, svp.\n(Ne pas utiliser le caratère | .)")
    return false
    }
  var atsignPos = str.indexOf("@", 0)        // check for @
  if (atsignPos == -1)	                     // nope - @ missing
    {
    alert("Entrez une adresse valide avec le signe @, svp.")
    return false
    }
  if (str.indexOf(".", atsignPos) == -1)     // nope - . after @ missing
    {
    alert("Entrez un domaine valide aprés le signe @, svp.")
    return false
    }
  return true                                // yep
  }

function isPhoneValid(str)          // is phone str valid
  {
  for (i=0; i<=str.length-1; i++)
    {
    if (i == 3 || i == 7)
      {
      if (str.charAt(i) != "-")     // nope - "-" missing
        return false;
      }
    else if (!isNum(str.charAt(i)))  // nope - # missing
      {
      return false;
      }
    }
  return true;                      // yep
  }

function isVisaValid(str)            // is VISA str valid?
  {
  if (str.length != 19)              // nope - wrong str length
    return false;
  for (i=0; i<19; i++)
    {
    if (i == 4 || i == 9 || i == 14)
      {
      if (str.charAt(i) != "-")      // nope - "-" missing
        return false;
      }
    else if (!isNum(str.charAt(i)))  // nope - # missing
      {
      return false;
      }
    }
  return true;                       // yep
  }
  
function isNumv(chr)            // is character a number?
{
	    for (i=0; i<=chr.length-1; i++)
    {
    if (!isNum(chr.charAt(i)))  // nope - # missing
      return false;
	}
	if (chr >100)
	 return false;
}

function isBlank(str)              // is str blank?
  {
  if (str.length == 0)             // yep - nothing entered
    return true;
  for (i=0; i<=str.length-1; i++)  // yep - all spaces
    if (str.charAt(i) != " ")
      return false;
  return true;                    // nope
  }

function isNum(chr)            // is character a number?
  {
	  if (chr < "0" || chr > "9")  // nope
		return false;
	  else                         // yep
		return true;
}

