/*#------------------------------------------------------+
# CORE Cashless Inc.
#
# $Id: guestServices.js,v 2.10 2007/12/12 16:54:33 jmayers Exp $
# $Name: rel-5-1-1-0x2 $
#
# Narrative:
#
#------------------------------------------------------+
*/
/****************************************************
* file: 	guestServices.cgi
* author:	brian allan
* date:		2002-11-14
* version:      1.06
* description:	Various Functions Used By
                guestServices.cgi
****************************************************/

/************************************************

   Begin Bar Code / Mag Reader / VID Section

************************************************/

var nav4 = window.Event ? true : false;         // see if browser is netscrap
var isBarcode = false;				// if bar code is currently being read
var isVID = false;                              // if VID currently being read
var isTrack1 = false;				// if track1 is currently being read
var isTrack2 = false;				// if track2 is currently being read
var isTrack3 = false;				// if track3 is currently being read
var track1Set = false;				// if track1 has been set
var track2Set = false;				// if track2 has been set
var track3Set = false;				// if track3 has been set
var barcode = "";				// used to buffer barcode during read
var vid = "";                                   // used to buffer VID during read
var track1 = "";				// used to buffer track1 during read
var track2 = "";				// used to buffer track2 during read
var track3 = "";				// used to buffer track3 during read
var barStart = '`';				// char to signal start of bar code
var barEnd = '`';				// char to signal end of bar code
var vidStart = /\d/;                            // char to signal start of vid (needs reg expression)
var vidEnd = '\r';                              // char to signal end of vid (needs reg expression)
var t1Start = '%';				// char to signal start of track1
var t1Sep = '^';				// field separator for track1
var t1End = '?';				// char to signal end of track1
var t2Start = ';';				// char to signal start of track2
var t2Sep = '=';				// field separator for track2
var t2End = '?';				// char to signal end of track2
var t3Start = ';';				// char to signal start of track3
var t3Sep = '=';				// field separator for track3
var t3End = '?';				// char to signal end of track3
var acceptMag = false;				// must be true to accept mag read
var acceptBar = false;				// must be true to accept bar code read
var acceptVID = false;                          // must be true to accept vid read
var submitForm = false;                         // if form should be submited after scan
var myTimerId; 					// used to keep track of timer
var scanForm;					// what form variables are stored in
var firstName;					// used to temp store first name field
var lastName;					// used to temp store last name field
var visualNumber;				// used to temp store visual number
var accountNo;					// used to temp store account number
var phoneNo;					// used to temp store phone number
var webId;					// used to temp store web Id
var transId;                                    // used to temp store transId
var folioCardNo;                                // used to store folio card number (RCI only)
var xNumb;                                      // pos transaction number

// user fields
var uName;
var pWord;
var pConf;
var purse1_comp_limit;
var purse5_comp_limit;
var purse6_comp_limit;
var entitlement_comp_limit;
var purse1_comp_per_trans;
var purse5_comp_per_trans;
var purse6_comp_per_trans;
var entitlement_comp_per_trans;
var fName;
var mi;
var lName;
var email;
var VID;
var CID;
var MAG;

// if browser is navigator, use capture events function to get key press
if (nav4)
{
   document.captureEvents(Event.KEYPRESS);
}

// set document keypress event to point to process function
document.onkeypress = processKeyPress;

/**************************************************
* function:	setScanForm
* author:	brian allan
* date:		2002-04-10
* description:	provides a way for the page to set
                which form its important fields
                are stored in
**************************************************/
function setScanForm(formName)
{
   // set global canForm equal to object representing defined form
   scanForm = document.forms[formName];
}

/***************************************************
* function:	processKeyPress
* author: 	brian allan
* date:		2002-04-10
* description:	determine what to do when use presses
                a key, or uses a device that prints
                to the keyboard buffer
***************************************************/

function processKeyPress(e)
{
   // set/reset timer if we are reading from external device
   //   or if we think we are
   if ((isBarcode) || (isTrack1) || (isTrack2) || (isTrack3) || (isVID))
   {
      // clear timer if exits
      clearInterval(myTimerId);
      // set new timer: this is done to make sure input is comming from device
      //   and not keyboard
      myTimerId = setInterval("resetVars();", 50);
   }

   // capture keypress and determine what it was
   if (nav4)
   {
      ch = String.fromCharCode(e.which);
   }
   else
   {
      if (event.type == "keypress")
         ch = String.fromCharCode(event.keyCode);
   }

   // if we are currently reading a barcode, mag track, or VID, then
   // call the appropriate processing function.  The allowed flag
   // must also have been set to true by the main page
   if ((isBarcode) && (acceptBar))
   {
      processBarcode(ch);
   }
   else if ((isVID) && (acceptVID))
   {
      processVID(ch);
   }
   else if ((isTrack1) && (acceptMag))
   {
      processTrack1(ch);
   }
   else if ((isTrack2) && (acceptMag))
   {
      processTrack2(ch);
   }
   else if ((isTrack3) && (acceptMag))
   {
      processTrack3(ch);
   }

   // if we are not currently in the middle of an id, then see
   //    if we are at the start of one
   // if the char matches a start char for an id, then set its
   //    its flag to true, save the important info off the form, and continue.
   // since tracks can have the same begin and end chars, make sure a
   //   matching track has not already been read
   // note: allow flag must be set to do anything
   else
   {
      if ((ch == barStart) && (acceptBar))
      {
         saveFormValues();
         isBarcode = true;
      }
      else if ((ch == t1Start) && (! track1Set) && (acceptMag))
      {
         saveFormValues();
         isTrack1 = true;
      }
      else if ((ch == t2Start) && (! track2Set) && (acceptMag))
      {
         saveFormValues();
         isTrack2 = true;
      }
      else if ((ch == t3Start) && (! track3Set) && (acceptMag))
      {
         saveFormValues();
         isTrack3 = true;
      }

      // VID is special because start is the first character in number
      else if ((vidStart.test(ch)) && (acceptVID))
      {
         saveFormValues();
         isVID = true;
         vid = ch;
      }
   }

   return;
}

/****************************************************
* function: 	saveFormValues
* author:	brian allan
* date:		2002-04-10
* description:	save important form values while reading
                in id
****************************************************/

function saveFormValues()
{
   // search form has extra values to store
   if (scanForm.name == "searchForm")
   {
      firstName = scanForm.fName.value;
      lastName = scanForm.lName.value;
      visualNumber = scanForm.VID.value;
      accountNo = scanForm.acctNo.value;
      phoneNo = scanForm.phoneNo.value;
      webId = scanForm.webId.value;
      transId = scanForm.transId.value;
      folioCardNo = scanForm.folioCardNo.value;
      xNumb = scanForm.xNumb.value;
   }
   else if (scanForm.name == "addEditUser")
   {
      uName = scanForm.uName.value;
      pWord = scanForm.pWord.value;
      pConf = scanForm.pConf.value;
      purse1_comp_limit = scanForm.purse1_comp_limit.value;
      purse5_comp_limit = scanForm.purse5_comp_limit.value;
      purse6_comp_limit = scanForm.purse6_comp_limit.value;
      entitlement_comp_limit = scanForm.entitlement_comp_limit.value;
      purse1_comp_per_trans = scanForm.purse1_comp_per_trans.value;
      purse5_comp_per_trans = scanForm.purse5_comp_per_trans.value;
      purse6_comp_per_trans = scanForm.purse6_comp_per_trans.value;
      entitlement_comp_per_trans = scanForm.entitlement_comp_per_trans.value;
      fName = scanForm.fName.value;
      mi = scanForm.mi.value;
      lName = scanForm.lName.value;
      email = scanForm.email.value;
      VID = scanForm.VID.value;
      CID = scanForm.CID.value;
      MAG = scanForm.MAG.value;
   }
   else if ((scanForm.name == "poolAcct") || (scanForm.name == "transfer")
      || (scanForm.name == "receiptTrans"))
   {
      visualNumber = scanForm.VID.value;
      webId = scanForm.webId.value;
   }
   else
   {
      visualNumber = scanForm.VID.value;
   }
}

/*****************************************************
* function:	resetFormValues
* author:	brian allan
* date:		2002-04-10
* description:	set for values back to what they were
                before id scanned
*****************************************************/

function resetFormValues(isVID)
{
   // search form has extra values
   if (scanForm.name == "searchForm")
   {
      scanForm.fName.value = firstName;
      scanForm.lName.value = lastName;
      scanForm.acctNo.value = accountNo;
      scanForm.phoneNo.value = phoneNo;
      scanForm.webId.value = webId;
      scanForm.transId.value = transId;
      scanForm.folioCardNo.value = folioCardNo;
      scanForm.xNumb.value = xNumb;

      if (! isVID)
      {
         scanForm.VID.value = visualNumber;
      }
   }
   else if (scanForm.name == "addEditUser")
   {
      scanForm.uName.value = uName;
      scanForm.pWord.value = pWord;
      scanForm.pConf.value = pConf;
      scanForm.purse1_comp_limit.value = purse1_comp_limit;
      scanForm.purse5_comp_limit.value = purse5_comp_limit;
      scanForm.purse6_comp_limit.value = purse6_comp_limit;
      scanForm.entitlement_comp_limit.value = entitlement_comp_limit;
      scanForm.purse1_comp_per_trans.value = purse1_comp_per_trans;
      scanForm.purse5_comp_per_trans.value = purse5_comp_per_trans;
      scanForm.purse6_comp_per_trans.value = purse6_comp_per_trans;
      scanForm.entitlement_comp_per_trans.value = entitlement_comp_per_trans;
      scanForm.fName.value = fName;
      scanForm.mi.value = mi;
      scanForm.lName.value = lName;
      scanForm.email.value = email;

      if (! isVID)
      {
         scanForm.VID.value = VID;
      }

      if (! isBarcode)
      {
         scanForm.CID.value = CID;
      }

      if (! isTrack1 && ! isTrack2 && ! isTrack3)
      {
         scanForm.MAG.value = MAG;
      }
   }
   else if ((scanForm.name == "poolAcct") || (scanForm.name == "transfer")
      || (scanForm.name == "receiptTrans"))
   {
      scanForm.webId.value = webId;

      if (! isVID)
      {
         scanForm.VID.value = visualNumber;
      }
   }
   else if (! isVID)
   {
      scanForm.VID.value = visualNumber;
   }

   // since end char will still print in text box that
   //   was highlighted, we must strip it away as soon
   //   as id process is finished
   if (submitForm)
   {
      if (scanForm.onsubmit())
         scanForm.submit();
   }
   else
   {
      window.setTimeout("stripEndChar()", 0);
   }
}

/***************************************************
* function:	stripEndChar
* author:	brian allan
* date:		2002-04-10
* description:	since end char of id is still placed
                in the highlighted text box, we must
                get rid of it after scan is processed
***************************************************/

function stripEndChar()
{
   // set regular expression to match end char of each id type
   myRegExp = RegExp("[\\" + barEnd + "\\" + t1End + "\\" + t2End + "\\" + t3End  + "]");

   // remove this char if exists from each form value
   if (scanForm.name == "searchForm")
   {
      scanForm.fName.value = scanForm.fName.value.replace(myRegExp, "");
      scanForm.lName.value = scanForm.lName.value.replace(myRegExp, "");
      scanForm.VID.value = scanForm.VID.value.replace(myRegExp, "");
      scanForm.acctNo.value = scanForm.acctNo.value.replace(myRegExp, "");
      scanForm.phoneNo.value =  scanForm.phoneNo.value.replace(myRegExp, "");
      scanForm.webId.value = scanForm.webId.value.replace(myRegExp, "");
      scanForm.folioCardNo.value = scanForm.folioCardNo.value.replace(myRegExp, "");
      scanForm.transId.value = scanForm.transId.value.replace(myRegExp, "");
      scanForm.xNumb.value = scanForm.xNumb.value.replace(myRegExp, "");
      scanForm.CID.value = scanForm.CID.value.replace(myRegExp, "");
      scanForm.MAG.value = scanForm.MAG.value.replace(myRegExp, "");
   }
   else if (scanForm.name == "addEditUser")
   {
      scanForm.uName.value = scanForm.uName.value.replace(myRegExp, "");
      scanForm.pWord.value = scanForm.pWord.value.replace(myRegExp, "");
      scanForm.pConf.value = scanForm.pConf.value.replace(myRegExp, "");
      scanForm.purse1_comp_limit.value = scanForm.purse1_comp_limit.value.replace(myRegExp, "");
      scanForm.purse5_comp_limit.value = scanForm.purse5_comp_limit.value.replace(myRegExp, "");
      scanForm.purse6_comp_limit.value = scanForm.purse6_comp_limit.value.replace(myRegExp, "");
      scanForm.entitlement_comp_limit.value = scanForm.entitlement_comp_limit.value.replace(myRegExp, "");
      scanForm.purse1_comp_per_trans.value = scanForm.purse1_comp_per_trans.value.replace(myRegExp, "");
      scanForm.purse5_comp_per_trans.value = scanForm.purse5_comp_per_trans.value.replace(myRegExp, "");
      scanForm.purse6_comp_per_trans.value = scanForm.purse6_comp_per_trans.value.replace(myRegExp, "");
      scanForm.entitlement_comp_per_trans.value = scanForm.entitlement_comp_per_trans.value.replace(myRegExp, "");
      scanForm.fName.value = scanForm.fName.value.replace(myRegExp, "");
      scanForm.mi.value = scanForm.mi.value.replace(myRegExp, "");
      scanForm.lName.value = scanForm.lName.value.replace(myRegExp, "");
      scanForm.email.value = scanForm.email.value.replace(myRegExp, "");
      scanForm.CID.value = scanForm.CID.value.replace(myRegExp, "");
      scanForm.MAG.value = scanForm.MAG.value.replace(myRegExp, "");
      scanForm.VID.value = scanForm.VID.value.replace(myRegExp, "");
   }
   else if ((scanForm.name == "poolAcct") || (scanForm.name == "transfer")
      || (scanForm.name == "receiptTrans"))
   {
      scanForm.VID.value = scanForm.VID.value.replace(myRegExp, "");
      scanForm.webId.value = scanForm.webId.value.replace(myRegExp, "");
      scanForm.CID.value = scanForm.CID.value.replace(myRegExp, "");
      scanForm.MAG.value = scanForm.MAG.value.replace(myRegExp, "");
   }
   else
   {
      scanForm.VID.value = scanForm.VID.value.replace(myRegExp, "");
      scanForm.CID.value = scanForm.CID.value.replace(myRegExp, "");
      scanForm.MAG.value = scanForm.MAG.value.replace(myRegExp, "");
   }
}

/****************************************************
* function:	processBarcode
* author:	brian allan
* date:		2002-04-10
* description:  check for end and add char to bar
                code buffer
****************************************************/

function processBarcode(ch)
{
   // if end char matched
   // 1) set form's barcode value to buffer
   // 2) set flag to false so that next char entered is not added to buffer
   // 3) parse out CID
   // 4) reset buffer
   // 5) reset form values to their original values
   // else add char to buffer
   if (ch == barEnd)
   {
      scanForm.barcode.value = barcode;
      parseCID(barcode);
      barcode = "";
      resetFormValues(false);
      isBarcode = false;
   }
   else
   {
      barcode += ch;
   }
}

function processVID(ch)
{
   // if end char matched
   // 1) set form's VID value to buffer
   // 2) set flag to false so that next char entered is not added to buffer
   // 3) reset buffer
   // 4) reset form value to their original values
   // else add char to buffer
   if (ch == vidEnd && vid.length > 10)
   {  
      scanForm.VID.value = vid;
      vid = "";
      resetFormValues(true);
      isVID = false;
   }
   else
   {
      vid += ch;
   }
}

/******************************************************
* function:	processTrack1
* author:	brian allan
* date:		2002-04-10
* description: check for end and add char to track1 buffer
******************************************************/

function processTrack1(ch)
{
   // if end char matched
   // 1) set form's track1 value to buffer
   // 2) set flag to false so that next char entered is not added to buffer
   // 3) parse out Mag NO (currently stored in track1)
   // 4) reset buffer
   // 5) reset form values to their original values
   // else add char to buffer
   if (ch == t1End)
   {
      scanForm.track1.value = track1;
      track1Set = true;
      parseMag(track1, 1);
      track1 = "";
      resetFormValues(false);
      isTrack1 = false;
   }
   else
   {
      track1 += ch;
   }
}

/******************************************************
* function:	processTrack2
* author:	brian allan
* date:		2002-04-10
* description: check for end and add char to track2 buffer
******************************************************/

function processTrack2(ch)
{
   // if end char matched
   // 1) set form's track2 value to buffer
   // 2) set flag to false so that next char entered is not added to buffer
   // 3) reset buffer
   // 4) reset form values to their original values
   // else add char to buffer
   if (ch == t2End)
   {
      scanForm.track2.value = track2;
      track2Set = true;

      if (scanForm.MAG.value.length == 0)
      {
         parseMag(track2, 2);
      }

      track2 = "";
      resetFormValues(false);
      isTrack2 = false;
   }
   else
   {
      track2 += ch;
   }
}

/******************************************************
* function:	processTrack3
* author:	brian allan
* date:		2002-04-10
* description: check for end and add char to track3 buffer
******************************************************/

function processTrack3(ch)
{
   // if end char matched
   // 1) set form's track3 value to buffer
   // 2) set flag to false so that next char entered is not added to buffer
   // 3) reset buffer
   // 4) reset form values to their original values
   // else add char to buffer
   if (ch == t3End)
   {
      scanForm.track3.value = track3;
      track3Set = true;
      track3 = "";
      resetFormValues(false);
      isTrack3 = false;
   }
   else
   {
      track3 += ch;
   }
}

/*******************************************************
* function: 	parseCID
* author:	brian allan
* date:		2002-04-10
* description:	pull CID out of bar code
*******************************************************/

function parseCID(barcode)
{
   // set reg expression that pulls out B2's (cap is for cap lock)
   var myRegExp = /[bB]2/

   // replace B2's with blank
   scanForm.CID.value = barcode.replace(myRegExp,"");
}

/*********************************************************
* function: 	parseMag
* author:	brian allan
* date:		2002-04-10
* description:	pull mag id out of tracks (track 1 only for now)
*********************************************************/

function parseMag(trackData, track)
{
   // split of field separator
   // number can begin w/char(s) and then digits
   // number stored in slot one (get it)
   var magNo;
   var myRegExp = /\D/g;

   if (track == 1)
   {
      magNo = trackData.split(t1Sep);
   }
   else if (track == 2)
   {
      magNo = trackData.split(t2Sep);
   }

   scanForm.MAG.value = magNo[0].replace(myRegExp, "");
}

function resetVars()
{
   isBarcode = false;
   isVID = false;
   isTrack1 = false;
   isTrack2 = false;
   isTrack3 = false;
   track1Set = false;
   track2Set = false;
   track3Set = false;
   barCode = "";
   vid = "";
   track1 = "";
   track2 = "";
   track3 = "";
}

/************************************************

   End Bar Code / Mag Reader Section

************************************************/

/************************************************

   Begin CID receipt check section

*************************************************/

/*********************************************************
* function:   isAlohaReceipt
* author:	brian allan
* date:		2002-06-25
* description:	return true if format matches aloha receipt
*********************************************************/

function isAlohaReceipt(cid)
{
   if ((cid.length == 18) && ((cid.substr(0, 1) == '7') || (cid.substr(0, 1) == '8')))
   {
      return true;
   }
   else
   {
      return false;
   }
}

/*********************************************************
* function: 	isRegularReceipt
* author:	brian allan
* date:		2002-06-25
* description:	return true if format matches regular receipt
*********************************************************/

function isRegularReceipt(cid)
{
   if ((cid.length == 12) && ((cid.substr(0, 1) == '3') || (cid.substr(0, 1) == '4')))
   {
      return true;
   }
   else
   {
      return false;
   }
}

/************************************************

   End CID receipt check section

*************************************************/

/************************************************

   Begin validation section

*************************************************/

/************************************************
* function:	nonword
* author: 	brian allan
* date:		2003-10-12
* description:	return true if contains non-word chars (not incl \s . `)
*************************************************/

function nonword(myform, field, name)
{
   if (document.all(field) != null)
   {
      var realField = eval("myform." + field);
      var regExp = /[^a-zA-Z0-9\s\.`]/g;

      if (regExp.test(realField.value))
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	nondigit
* author: 	brian allan
* date:		2003-10-12
* description:	return true if contains non digit (0-9)
*************************************************/

function nondigit(myform, field, name)
{
   if (document.all(field) != null)
   {
      var realField = eval("myform." + field);
      var regExp = /[^0-9]/g;

      if (regExp.test(realField.value))
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	nonchar
* author: 	brian allan
* date:		2003-10-12
* description:	return true if non character
*************************************************/

function nonchar(myform, field, name)
{
   if (document.all(field) != null)
   {
      var realField = eval("myform." + field);
      var regExp = /[^a-zA-z\s\.`]/g;

      if (regExp.test(realField.value))
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	nonyear
* author: 	brian allan
* date:		2003-10-12
* description:	return true if ! match 4 digits
*************************************************/

function nonyear(myform, field, name)
{
   if (document.all(field) != null)
   {
      var realField = eval("myform." + field);
      var regExp = /\d\d\d\d/;

      if (! regExp.test(realField.value) && realField.value.length > 0 && realField.value != 'YYYY')
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	nonmonth
* author: 	brian allan
* date:		2003-10-12
* description:	return true if ! between 1 & 12
*************************************************/

function nonmonth(myform, field, name)
{
   if (document.all(field) != null)
   {  
      var realField = eval("myform." + field);
      var regExp = /\d\d/g;

      if (! regExp.test(realField.value) && realField.value.length > 0 && realField.value != 'MM')
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }

      if (realField.value.length > 0 && (realField.value < 0 || realField.value > 12))
      {
         alert(name + " is out of range.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	nonday
* author: 	brian allan
* date:		2003-10-12
* description:	return true if ! between 1 & 31
*************************************************/

function nonday(myform, field, name)
{
   if (document.all(field) != null)
   {  
      var realField = eval("myform." + field);
      var regExp = /\d\d/g;

      if (! regExp.test(realField.value) && realField.value.length > 0 && realField.value != 'MM')
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }

      if (realField.value.length > 0 && (realField.value < 0 || realField.value > 31))
      {
         alert(name + " is out of range.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	noncc
* author: 	brian allan
* date:		2003-10-12
* description:	must by in cc format (or masked cc format; 16 digits)
*************************************************/

function noncc(myform, field, name)
{
   if (document.all(field) != null)
   {
      var realField = eval("myform." + field);
      var regExp = /\d{15}|\d\*{11}\d{4}|\d\*{10}\d{4}/g;

      if (! regExp.test(realField.value) && realField.value.length > 0)
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	nonccdate
* author: 	brian allan
* date:		2003-10-12
* description:	must be in format mm/yy
*************************************************/

function nonccdate(myform, field, name)
{
   if (document.all(field) != null)
   {
      var realField = eval("myform." + field);
      var regExp = /\d\d\/\d\d/;

      if (! regExp.test(realField.value) && realField.value.length > 0)
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	bademail
* author: 	brian allan
* date:		2003-10-12
* description:	must meet email format
*************************************************/

function bademail(myform, field, name)
{
   if (document.all(field) != null)
   {
      var realField = eval("myform." + field);
      var format = /\w*@\w*\.\w/g;
      var multPeriods = /\.\./g;
      var badChars = /[^\w\.\@\_\-]/g;

      if (realField.value.length > 0 && (! format.test(realField.value) || multPeriods.test(realField.value)
         || badChars.test(realField.value)))
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	badpartemail
* author: 	brian allan
* date:		2003-10-12
* description:	must meet email rules minus overall format
*************************************************/

function badpartemail(myform, field, name)
{
   if (document.all(field) != null)
   {
      var realField = eval("myform." + field);
      var multPeriods = /\.\./g;
      var badChars = /[^\w\.\_\-]/g;

      if (realField.value.length > 0 && (multPeriods.test(realField.value)
         || badChars.test(realField.value)))
      {
         alert(name + " is not valid.");
         realField.focus();
         return true;
      }
   }

   return false;
}

/************************************************
* function:	validate_demographics
* author: 	brian allan
* date:		2003-10-12
* description:	function to validate demographic entry form and/or member entry form
*************************************************/

function validate_demographics()
{
   myform = document.demoForm;
   var errors = false;

   if (! errors)
      errors = nondigit(myform, 'zip', 'Zip');

   if (! errors)
      errors = nonword(myform, 'country', 'Country');

   for (var i = 1; i < 7; i++)
   {
      if (! errors)
         errors = nondigit(myform, 'phone' + i, 'Phone ' + i);
   }

   for (var x = 1; x < 3; x++)
   {
      for (var j = 1; j < 4; j++)
      {
         if (! errors)
            errors = nondigit(myform, 'phone' + x + j, 'Phone ' + x);
      }
   }

   if (! errors)
      errors = nonyear(myform, 'yyyy', 'Birth year');

   if (! errors)
      errors = nonmonth(myform, 'mm', 'Birth month');

   if (! errors)
      errors = nonday(myform, 'dd', 'Birth day');

   if (! errors)
      errors = nondigit(myform, 'household', '# in household');

   if (! errors)
      errors = bademail(myform, 'email', 'Email address');

   if (! errors)
      errors = badpartemail(myform, 'email1', 'Email address');

   if (! errors)
      errors = badpartemail(myform, 'email2', 'Email address');

   if (errors)
      return false;
   else
      return true;
}

/************************************************

   End validate section

*************************************************/

