/**********************************************************************************************
**********************************************************************************************/

/**********************************************************************************************
* Author(s): Anthony Hill ***** Date: 6/10/01                                			  *
* Object Name: ValObj                     					         		        *
***********************************************************************************************
* Proposal: the ValObj is being created to give developers a single interface to be 	        *
* easily validate forms. It will also have the flexibilty to give developers the option  	  *
* in which fields are to be validated. If a field is incorrect the object will also give      *
* option for error to be displayed in one of 3 ways, popup window, or layer display		  *
* these particular error diplays will be bellsouth.com specific for this Object.        	  *
* possible types of Validaitons are isemail, isblank, isempty, isnpa, isnxx, iszip, isdate,   *
* ismonth, isphone, isalpha, isnum, isbday, isdollaramt, iscreditcard, istime, isline.        *
* For passwords there are numofalpha, numofnumbers, maxfldvaluelenngth and maxfldvaluelenngth.*
**********************************************************************************************/
/**********************************************************************************************
* The ValObj function is used to declare the properties of the Validator object and 	    	  *
* intitilezes some of its properties. Parameters values 0 and 1 are reserved for the 	    	  * 
* the form element name and the error display name.							  * 
* 															  *
* Arugument 0 is the field name of the object that is to be validated. An dom object or string*
* is to be passed. If the name of the field as a string is passed the find_obj() function will*
* find the object in the form and return a reference to the constructor. If form object is    *
* passed the cinstrutor will use that. 									  *
*															  *
* Argument 1 is the name that will be shown in the default messaging messages. 		    	  *
**********************************************************************************************/
function validatorObj()
{
var argFlag=false;
 this.formElementObjref = null;

//pass the name of the form object as the first parameter
 if(typeof arguments[0] == "string") 
     {this.formElementObjref = find_obj(arguments[0]); argFlag=true;}
 if(typeof arguments[0] == "object")
    {this.formElementObjref = arguments[0]; argFlag=true;}
  if(!argFlag)
   {alert("Argument 0 of the validation object can only be a string or object, see the instructions for more"); return;}



 
  var VALID_PARAM_START_INDEX =2;
  this.formElementName = this.formElementObjref.name;
  //case for radio added 7-28-2005 referencing the first element of the children in the radio array
  if(this.formElementObjref.length>0)
  {this.type = this.formElementObjref[0].type; /*this.formElementObjref = this.formElementObjref[0];*/}
   else
   {this.type = this.formElementObjref.type;}

  this.parentForm = this.formElementObjref.form;
  this.formElementValue = ((this.type=="text")||(this.type=="password")||(this.type=="file"))?RTrim(LTrim(this.formElementObjref.value)):"";
  this.errorDisplayName = arguments[1]; //pass the field name refrence you want users to see in the error refrences
  this.maxDigitLen=0;
  this.minDigitLen=0;
  this.alphaDigitLen=0;
  this.numDigitLen=0;
  this.spCharDigitlen=0;
  this.consCharDigitLen=0;
  this.parentformObjref= (this.type=="radio")?this.formElementObjref[0].form:this.formElementObjref.form;
  this.blankChksType = false;
  this.blankChks = new Array("ISBLANK");
  this.validationTypes = slice(arguments,VALID_PARAM_START_INDEX,arguments.length);
  this.defaultMessaging = true;
  this.defaultChecks = false;
  this.bgHighLight ="";
  this.errormsgArray = new Array();
  this.specerrormsgArray = new Array();


//add validation type here if a new is needed. These are checked to see if the developer made a input error
  this.textTypeValidations  = new Array("ISNUMFLD","MAXFLDVALUELENGTH","ISDOLLAR","ISZIP","ISBLANK","ISDATE","ISEMAIL",
"ISALPHAFLD","DEFAULTCHECKS","DEFAULTMSG","BGHIGHLIGHT","ISNPA","ISNXX","ISLINE","ISMONTH","ISCREDITCARD",
"MINFLDVALUELENGTH","ISPHONE","EQFLDVALUELENGTH","ISTIME","NUMOFALPHA","NUMOFNUMBERS","NUMOFSPECIALCHR","NUMOFCONSECCHR");

//message type validations. These are checked to see if the developer made a input error
this.msgTypeValidations = new Array("MSG_MISSINGAT","MSG_MISSINGDOT","MSG_ISTIME");
  //added "DEFAULTMSG" for the other form elements incase its turned off. 7-25-2005
  this.radioTypeValidations  = new Array("ISCHECKED","BGHIGHLIGHT","DEFAULTMSG");
  this.checkBoxTypeValidations  = new Array("ISCHECKED","BGHIGHLIGHT","DEFAULTMSG"); //leave this here if you want to add validations take out if there are performance issues
  this.pullDownTypeValidations  = new Array("SELECTDINDEXGT","BGHIGHLIGHT","DEFAULTMSG");

//this creates messages for the error display.    
this.messObj = new messageObj(this.errorDisplayName); 
 
   
   //If defaut messaging is turned off there is an option to assign a msg to a validation by passing 
   //the validation then the correspinding error message that you would like to display if that error occurs
   //example ISNUMFLD_The data in the phone number field must be a number. 
   //for the value holding macros, use 2 underscores. example MINFLDVALUELENGTH_TRUE_The TN field must have 3 digits
   
   
//Macros Availible to set the validations
//ISNUMFLD,MAXFLDVALUELENGTH_{VALUE},ISDOLLAR,ISZIP,ISBLANK,ISDATE,ISEMAIL,
//ISALPHAFLD,DEFAULTCHECKS,DEFAULTMSG_{VALUE},"MINFLDVALUELENGTH_{VALUE}"
// BGHIGHLIGHT_{VALUE},ISNPA,ISNXX,ISLINE,ISMONTH,ISCREDITCARD,ISPHONE,
//MINFLDVALUELENGTH,ISPHONE,EQFLDVALUELENGTH,ISTIME,NUMOFALPHA,NUMOFNUMBERS,NUMOFSPECIALCHR,NUMOFCONSECCHR"
//for radio button
//ISCHECKED, BGHIGHLIGHT_{VALUE}
//for checkbox 
//ISCHECKED, BGHIGHLIGHT_{VALUE}
//for pull downs
//SELECTDINDEXGT_{VALUE},BGHIGHLIGHT_{VALUE}
 
  
  //there are a current total of 14 validation checks
  //5 basic and the rest are a combination of the basic
  this.isBlankType = false;  
  this.isChoosen = false; //this is a reference for radio and check boxes to mark true that they will be selected
  this.islineType = false;  
  this.isEmptyType = false;
  this.isNpaType = false; 
  this.isNxxType = false; 
  this.isMonthType = false; 
  this.isAlphaType = false; 
  this.isMAXLengthType = false;
  this.isMINLengthType = false;
  this.isEQLengthType = false;
  this.isNumType = false; 
  this.isDollarAmtType = false;
  this.isCreditCardType = false;					
  this.phoneType = false;
  this.birthdayType = false;
  this.emailType = false;
  this.zipType = false;
  this.dateType = false;
  this.radioType = false;
  this.checkBoxType = false;
  this.pullDownType = false;
  this.timeType = false;
  this.isNumOfAlphaType = false;
  this.isNumOfNumType = false;
  this.isNumOfSpecCharType = false;
  this.isNumOfConsecCharType = false;


  
  //this is the objects flag that controls weather or not the object is valid 
  this.errorFlag = false;
	 
  //start flag checks
  this.isBlankFlag = false;
  this.isEmptyFlag = false;
  this.isAlphaFlag = false;
  this.isNumFlag = false;
  this.isPhoneFlag = false;
  this.isMAXLengthFlag = false;
  this.isMINLengthFlag = false;
  this.isEQLengthFlag = false;
  this.isDollarFlag = false;
  this.iszipFlag = false;
  this.isMissingAtFlag = false;
  this.isMissingDotFlag = false;
  this.isdateFlag = false;
  this.istimeFlag = false;
  this.isemailFlag = false;
  this.ischeckedFlag = false;
  this.selectionIndexFlag = false;
  this.isNumOfAlphaFlag = false;
  this.isNumOfNumFlag = false;
  this.isNumOfSpecCharFlag = false;
  this.isNumOfConsCharFlag = false;
  this.devErrorFlag = false;

 this.flagArray = new Array();

//this captures the macros captured for the validation.
this.macroArray = new Array();


  this.valObjInit();
}//end  validatorObj

//this function runs the validations and returns to see if the validations passed or failed. 
function val_runChecks()
{ 
 if(this.isBlankType) this.isBlankFlag = this.isBlank();
 if(this.isEmptyType) this.isEmptyFlag = this.isEmpty();
 if(this.isAlphaType) this.isAlphaFlag = this.checkAlpha(); 
 if(this.isNumType)this.isNumFlag = this.checkNumeric();  
 if(this.isMAXLengthType)this.isMAXLengthFlag = this.checkLengthMAX(); //need to set length before before passing maxDiglength
 if(this.isMINLengthType)this.isMINLengthFlag = this.checkLengthMIN();
 if(this.isEQLengthType)this.isEQLengthFlag = this.checkLengthEQ();

//added 11-11-04 for pw validation. need to set values for all before use. 
 if(this.isNumOfAlphaType) this.isNumOfAlphaFlag = this.checkNumOfAlpa();
 if(this.isNumOfNumType)this.isNumOfNumFlag = this.checkisNumOfNum(); 
 if(this.isNumOfSpecCharType)this.isNumOfSpecCharFlag = this.checkNumOfSpecCharFlag();
 if(this.isNumOfConsecCharType) this.isNumOfConsCharFlag = this.checkConsecChar();

 if(this.timeType) this.istimeFlag = this.checkTime();
 if(this.radioType||this.checkBoxType)this.ischeckedFlag = this.isBlank();
 if(this.pullDownType)this.selectionIndexFlag = this.checkSelectedIndex();
 
//combonation validations
 if(this.islineType)
   {this.isBlankFlag = this.isBlank();  this.isEmptyFlag = this.isEmpty(); this.isNumFlag = this.checkNumeric(); 
  this.seteqDigitLenlength(4); this.isEQLengthFlag = this.checkLengthEQ();}

 if(this.isNpaType||this.isNxxType) 
   { this.isBlankFlag = this.isBlank();  this.isEmptyFlag = this.isEmpty(); this.isNumFlag = this.checkNumeric();
  this.seteqDigitLenlength(3); this.isEQLengthFlag = this.checkLengthEQ();}

 if(this.isDollarAmtType)
   {this.isBlankFlag = this.isBlank(); this.isEmptyFlag = this.isEmpty(); this.isDollarFlag = this.checkDollar();}

 if(this.isCreditCardType)
  {this.isBlankFlag = this.isBlank();  this.isEmptyFlag = this.isEmpty(); this.isNumFlag = this.checkNumeric();}

 if(this.phoneType) 
   {this.isBlankFlag = this.isBlank();  this.isEmptyFlag = this.isEmpty(); this.isNumFlag = this.checkNumeric(); this.isPhoneFlag = this.checkPhone();}  
 
 if(this.emailType)
   {this.isBlankFlag = this.isBlank();  this.isMissingAtFlag = this.missingAt(); this.isMissingDotFlag = this.missingDot();
   this.isEmptyFlag = this.isEmpty(); this.isemailFlag = this.checkEMail();}
   
 if(this.zipType) {this.isBlankFlag = this.isBlank();  this.isEmptyFlag = this.isEmpty(); this.iszipFlag = this.checkZip();}
 
 if(this.birthdayType||this.dateType)
   {this.isBlankFlag = this.isBlank();  this.isEmptyFlag = this.isEmpty(); this.isdateFlag = this.checkDate();}
   
//if a new flag is added, add to this array as well	
//all flags must be added to this array. this flag must be re-initilaized after the checks
this.flagArray = new Array(this.isBlankFlag,this.isEmptyFlag,this.isAlphaFlag,this.isNumFlag,this.isPhoneFlag,this.isMAXLengthFlag,
this.isMINLengthFlag,this.isEQLengthFlag,this.isDollarFlag,this.iszipFlag,this.isMissingAtFlag,this.isMissingDotFlag,this.isdateFlag,
this.istimeFlag,this.isemailFlag,this.ischeckedFlag,this.selectionIndexFlag,this.isNumOfAlphaFlag,this.isNumOfNumFlag,this.isNumOfSpecCharFlag,this.isNumOfConsCharFlag,this.devErrorFlag);

}//end val_runChecks

/**********************************************************************************************
* function val_setValDefaults is a validator object specific function. It looks at the form   *
* field name and looks for any of the following keywords to know what type of validation to   *
* initialize the values to begin validation. This function can be turned off by running       *
* setDefaultChecks(true) or passing the DEFAULTCHECKS, in the constructor. 					  *
* key words: email, phone, npa, nxx, numline, zip, length, alpha, number, month, date, 		  *
* creditcard, birthday, dollar, date.														  *	
**********************************************************************************************/
function val_setValDefaults()
{
  //var regex_blank =/blank/i;
  var regex_empty =/empty/i;
  var regex_email =/email/i;
  var regex_phone =/phone/i;
  var regex_npa = /npa/i;
  var regex_nxx = /nxx/i;
  var regex_line = /numline/i;
  var regex_zip = /zip/i;
  var regex_len = /time/i;
  var regex_alpha = /alpha/i;
  var regex_num = /number/i;
  var regex_mon = /month/i;
  var regex_date = /date/i;
  var regex_card = /creditcard/i;
  var regex_bday = /birthday/i;
  var regex_dollar = /dollar/i;
  var regex_date = /date/i;
  
if(this.defaultChecks)
 {
  if(this.formElementName.search(regex_empty)) this.isEmptyType = true;
  if(this.formElementName.search(regex_email)) this.emailType = true;
  if(this.formElementName.search(regex_phone)) this.phoneType = true;
  if(this.formElementName.search(regex_npa))  this.isNpaType = true; 
  if(this.formElementName.search(regex_nxx))  this.isNxxType = true; 
  if(this.formElementName.search(regex_line)) this.islineType = true; 
  if(this.formElementName.search(regex_zip)) this.zipType = true;
  if(this.formElementName.search(regex_alpha)) this.isAlphaType = true;
  if(this.formElementName.search(regex_num)) this.isNumType = true;
  if(this.formElementName.search(regex_mon))  this.isMonthType = true;
  if(this.formElementName.search(regex_date)||this.formElementName.search(regex_bday)) this.birthdayType=this.dateType = true;
  if(this.formElementName.search(regex_card))  this.isCreditCardType = true;
  if(this.formElementName.search(regex_dollar)) this.dollarAmtType = true;   
 }
}//end val_setValDefaults


function val_addValidation(validationList)
{
 if(validationList&&!this.defaultMessaging)
 for(var i=0; i<validationList.length; i++)
  this.validationTypes[this.validationTypes.length]=validationList[i];
}//end val_addValidation


 
 //Macros Availible to set the validations
//ISNUMFLD,MAXFLDVALUELENGTH_{VALUE},ISDOLLAR,ISZIP,ISBLANK,ISDATE,ISEMAIL,
//ISALPHAFLD,DEFAULTCHECKS,DEFAULTMSG_{VALUE},"MINFLDVALUELENGTH_{VALUE},EQFLDVALUELENGTH_{VALUE},
// BGHIGHLIGHT_{VALUE},ISNPA,ISNXX,ISLINE,ISMONTH,ISCREDITCARD,ISPHONE,
//NUMOFALPHA_{VALUE},NUMOFNUMBERS_{VALUE},NUMOFSPECIALCHR_{VALUE},NUMOFCONSECCHR_{VALUE}
//for radio button
//ISCHECKED, BGHIGHLIGHT_{VALUE}
//for checkbox 
//ISCHECKED, BGHIGHLIGHT_{VALUE}
//for pull downs
//SELECTDINDEXGT_{VALUE},BGHIGHLIGHT_{VALUE}
function val_setValidationTypes()
{ 
  if(this.validationTypes&&!this.devErrorFlag)
  {
  for(var i=0; i<this.validationTypes.length; i++)
   {
   if(this.validationTypes[i].indexOf("MSG_")==0)this.addToMsgSpecErrorArray(this.validationTypes[i]);
    if(this.validationTypes[i].indexOf("ISNUMFLD")!=-1) this.isNumType=true;
    if(this.validationTypes[i].indexOf("MAXFLDVALUELENGTH_")!=-1) {this.isMAXLengthType = true; this.setmaxDigitLenlength(parseParamVal(this.validationTypes[i]));}
    if(this.validationTypes[i].indexOf("MINFLDVALUELENGTH_")!=-1) {this.isMINLengthType = true; this.setminDigitLenlength(parseParamVal(this.validationTypes[i]));}
    if(this.validationTypes[i].indexOf("EQFLDVALUELENGTH_")!=-1) {this.isEQLengthType = true; this.seteqDigitLenlength(parseParamVal(this.validationTypes[i]));}

    if(this.validationTypes[i].indexOf("NUMOFALPHA_")!=-1) {this.isNumOfAlphaType = true; this.setAlphaDigitLenlength(parseParamVal(this.validationTypes[i]));}
    if(this.validationTypes[i].indexOf("NUMOFNUMBERS_")!=-1) {this.isNumOfNumType = true; this.setNumDigitLenlength(parseParamVal(this.validationTypes[i]));}
    if(this.validationTypes[i].indexOf("NUMOFSPECIALCHR_")!=-1) {this.isNumOfSpecCharType = true; this.setSpCharDigitLenlength(parseParamVal(this.validationTypes[i]));}
	 if(this.validationTypes[i].indexOf("NUMOFCONSECCHR_")!=-1) {this.isNumOfConsecCharType = true; this.setconsCharDigitLen(parseParamVal(this.validationTypes[i]));}


    if(this.validationTypes[i].indexOf("ISDOLLAR")!=-1) this.isDollarAmtType=true;
	if(this.validationTypes[i].indexOf("ISZIP")!=-1) this.zipType=true;
	if(this.validationTypes[i].indexOf("ISBLANK")!=-1) this.isBlankType=true;
    if(this.validationTypes[i].indexOf("ISDATE")!=-1) this.dateType=true;
    if(this.validationTypes[i].indexOf("ISEMAIL")!=-1) this.emailType=true;
	if(this.validationTypes[i].indexOf("ISNPA")!=-1) this.isNpaType=true;
	if(this.validationTypes[i].indexOf("ISNXX")!=-1) this.isNxxType=true;
	if(this.validationTypes[i].indexOf("ISTIME")!=-1) this.timeType=true;
	if(this.validationTypes[i].indexOf("ISLINE")!=-1) this.islineType=true;
	if(this.validationTypes[i].indexOf("ISMONTH")!=-1) this.isMonthType=true;
	if(this.validationTypes[i].indexOf("ISCREDITCARD")!=-1) this.isCreditCardType=true;
	if(this.validationTypes[i].indexOf("ISPHONE")!=-1) this.phoneType=true;
	if(this.validationTypes[i].indexOf("ISALPHAFLD")!=-1) this.isAlphaType=true;
	if(this.validationTypes[i].indexOf("DEFAULTCHECKS")!=-1) this.setDefaultChecks(true);
	if(this.validationTypes[i].indexOf("DEFAULTMSG")!=-1)  this.setDefautMessaging(parseParamVal(this.validationTypes[i]));
	if(this.validationTypes[i].indexOf("BGHIGHLIGHT")!=-1){this.setbgHighLightColor(parseParamVal(this.validationTypes[i]));}
	if(this.validationTypes[i].indexOf("ISCHECKED")!=-1){this.checkBoxType = true; this.radioType = true;}
	
	if(this.validationTypes[i].indexOf("SELECTDINDEXGT")!=-1){this.pullDownType = true; this.setmaxDigitLenlength(parseParamVal(this.validationTypes[i]));}
  }
 }

}//end setvalidationTypes

function getAllErrorMsgs()
{ var errArry = new Array();
 if(arguments)
  for (var i=0; i<arguments.length; i++)
    if(arguments[i].errorFlag)  errArry = errArry.concat(arguments[i].errormsgArray)
 
 return errArry;
}

//assumes your using 1 form
function getAllErrorResults()
{ var errArry = new Array(); var flag = false;
 if(arguments)
  for (var i=0; i<arguments.length; i++)
    if(arguments[i].errorFlag) {flag=true; break;}
 
 return flag;
}

function submitFormifAllOk()
{ 
var errArry = new Array(); var flag = false;
 if(arguments)
  for (var i=0; i<arguments.length; i++)
    if(arguments[i].errorFlag) {flag=true; break;}
 
 if(!flag) arguments[0].parentformObjref.submit();
}


//counts number of occurences of a passed char in a passed string. 
function charCount(str,ch)
{var s = new String(str); var count=0; 
 for(var i=0; i<s.length; i++){if(s.charAt(i)==ch) count++;}
  return count;
}

function val_setDevErrorFlag(val){this.devErrorFlag=(val==true||val=="true")?true:false;}
function val_showbgHighLightColor(){if(this.type=="radio")this.formElementObjref[0].style.backgroundColor=this.bgHighLight; else this.formElementObjref.style.backgroundColor=this.bgHighLight;}
function val_setbgHighLightColor(val){if(val)this.bgHighLight=val;}
function val_setDefaultMsg(val){this.defaultChecks=(val==true||val=="true")?true:false;}
function val_setDefaultChecks(val){this.defaultChecks=(val==true||val=="true")?true:false;}
function val_setErrorDisplayName(name){this.errorDisplayName=(name)?name:this.formElementName;}//end val_setErrorDisplayName
function val_setmaxDigitLenlength(num){this.maxDigitLen=(num)?num:0;}
function val_setminDigitLenlength(num){this.minDigitLen=(num)?num:0;}
function val_seteqDigitLenlength(num){this.minDigitLen=this.maxDigitLen=(num)?num:0;}

//functions added 11-11-04 for pw validaiton
function val_setAlphaDigitLenlength(num){this.alphaDigitLen=(num)?num:0;}
function val_setNumDigitLenlength(num){this.numDigitLen=(num)?num:0;}
function val_setSpCharDigitLenlength(num){this.spCharDigitlen=(num)?num:0;}
function val_setconsCharDigitLen(num){this.consCharDigitLen=(num)?num:0;}


function val_chkErrorFlag()
{ if(this.errormsgArray.length>0) {this.setErrorFlag(true); this.showbgHighLightColor();} else{this.setbgHighLightColor("white"); this.showbgHighLightColor();} }

function val_setblankTypes(val){this.blankChksType = (val==true||val=="true")?true:false;}//end val_setMessages
function val_setErrorFlag(val){this.errorFlag = (val==true||val=="true")?true:false;}
function val_getErrorFlag(){return this.errorFlag;}

function val_runblankChks(){if(this.blankChksType)this.validationTypes = this.blankChks.concat(this.validationTypes);}

function val_setdefautChecks(val){this.defaultChecks =(val==true||val=="true")?true:false;}//end val_setdefautMessaging
function val_setDefautMessaging(val){this.defaultMessaging = (val==true||val=="true")?true:false;}//end val_setdefautMessaging
function val_addToErrorArray(str){if(str)this.errormsgArray[this.errormsgArray.length]=str; this.setErrorFlag(true);}   
function val_addToMacroArray(str){if(str)this.macroArray[this.macroArray.length]=str;}   
function val_addToMsgSpecErrorArray(str){if(str)this.specerrormsgArray[this.specerrormsgArray.length]=str.substring(str.lastIndexOf("_")+1,str.length);}  

//function checks to see if any error flags were set, if so it set the objects error flag to know to show error messages
function val_checkFlags()
{for (var i=0; i<this.flagArray.length; i++) 
if(this.flagArray[i]) { this.setErrorFlag(true); break;}
}


  //this function checks to see what error flags were set and adds the correct error message. 
 function val_setMessages()
 {
//for reference
//this.flagArray = new Array(this.isBlankFlag,this.isEmptyFlag,this.isAlphaFlag,this.isNumFlag,this.isPhoneFlag,this.isMAXLengthFlag,
//this.isMINLengthFlag,this.isEQLengthFlag,this.isDollarFlag,this.iszipFlag,this.isMissingAtFlag,this.isMissingDotFlag,this.isdateFlag,
//this.istimeFlag,this.isemailFlag,this.ischeckedFlag,this.selectionIndexFlag,this.isNumOfAlphaFlag,this.isNumOfNumFlag,this.isNumOfSpecCharFlag,this.isNumOfConsCharFlag,this.devErrorFlag);


//set error flag to true and assign error
//ISNUMFLD,MAXFLDVALUELENGTH_{VALUE},ISDOLLAR,ISZIP,ISBLANK,ISDATE,ISEMAIL,
//ISALPHAFLD,DEFAULTCHECKS,DEFAULTMSG_{VALUE},"MINVALUEFLDLENGTH_{VALUE},EQFLDVALUELENGTH_{VALUE}
// BGHIGHLIGHT_{VALUE},ISNPA,ISNXX,ISLINE,ISMONTH,ISCREDITCARD,ISPHONE,
//NUMOFALPHA_{VALUE},NUMOFNUMBERS_{VALUE},NUMOFSPECIALCHR_{VALUE}
//for radio button
//ISCHECKED, BGHIGHLIGHT_{VALUE}
//for checkbox 
//ISCHECKED, BGHIGHLIGHT_{VALUE}
//for pull downs
//SELECTDINDEXGT_{VALUE},BGHIGHLIGHT_{VALUE}

if((this.flagArray[0])||(this.flagArray[1])){this.addToMacroArray("ISBLANK"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.field_blank_error); else this.addToErrorArray(this.getSpecMsg("ISBLANK"));} //isblank, isempty
if(this.flagArray[2]){this.addToMacroArray("ISALPHAFLD"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.alpha_only_error); else this.addToErrorArray(this.getSpecMsg("ISALPHAFLD"));} //isalpha
if(this.flagArray[3]){this.addToMacroArray("ISNUMFLD"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.num_only_error); else this.addToErrorArray(this.getSpecMsg("ISNUMFLD"));} //isnum
if(this.flagArray[4]){this.addToMacroArray("ISPHONE"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.phone_fmt_error); else this.addToErrorArray(this.getSpecMsg("ISPHONE"));} //isphone
if(this.flagArray[5]){this.addToMacroArray("MAXFLDVALUELENGTH"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.retCharMsg(this.maxDigitLen,"max")); else this.addToErrorArray(this.getSpecMsg("MAXFLDVALUELENGTH"));} //isMaxlen
if(this.flagArray[6]){this.addToMacroArray("MINVALUEFLDLENGTH"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.retCharMsg(this.minDigitLen,"min")); else this.addToErrorArray(this.getSpecMsg("MINFLDVALUELENGTH"));} //isMinlen
if(this.flagArray[7]){this.addToMacroArray("EQFLDVALUELENGTH"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.retCharMsg(this.minDigitLen,"eq")); else this.addToErrorArray(this.getSpecMsg("EQFLDVALUELENGTH"));} //iseqlen
if(this.flagArray[8]){this.addToMacroArray("ISDOLLAR"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.dollar_error); else this.addToErrorArray(this.getSpecMsg("ISDOLLAR"));} //isDollar
if(this.flagArray[9]){this.addToMacroArray("ISZIP"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.zipcode_fmt_error); else this.addToErrorArray(this.getSpecMsg("ISZIP"));} //iszip
if(this.flagArray[10]){this.addToMacroArray("MISSINGAT"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.email_miss_at_error); else this.addToErrorArray(this.getSpecMsg("MISSINGAT"));} //missingAT
if(this.flagArray[11]){this.addToMacroArray("MISSINGDOT"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.email_miss_dot_error); else this.addToErrorArray(this.getSpecMsg("MISSINGDOT"));} //missingDOt
if(this.flagArray[12]){this.addToMacroArray("ISDATE"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.date_fmt_error); else this.addToErrorArray(this.getSpecMsg("ISDATE"));} //isDate
if(this.flagArray[13]){this.addToMacroArray("ISTIME"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.time_fmt_error); else this.addToErrorArray(this.getSpecMsg("ISTIME")); } //istime
if(this.flagArray[14]){this.addToMacroArray("ISEMAIL"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.email_format_error); else this.addToErrorArray(this.getSpecMsg("ISEMAIL"));} //isemail
if(this.flagArray[15]){this.addToMacroArray("ISCHECKED"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.missing_check_error); else this.addToErrorArray(this.getSpecMsg("ISCHECKED"));} //ischecked
if(this.flagArray[16]){this.addToMacroArray("SELECTDINDEXGT"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.not_selected_error); else this.addToErrorArray(this.getSpecMsg("SELECTDINDEXGT"));} //selectionIndex
if(this.flagArray[17]){this.addToMacroArray("NUMOFALPHA"); if(this.defaultMessaging) this.addToErrorArray(this.messObj.retCharMsg(this.alphaDigitLen,"alpha")); else this.addToErrorArray(this.getSpecMsg("NUMOFALPHA"));} //numberofalpha
if(this.flagArray[18]){this.addToMacroArray("NUMOFNUMBERS"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.retCharMsg(this.numDigitLen,"num")); else this.addToErrorArray(this.getSpecMsg("NUMOFNUMBERS"));} //numOfNum
if(this.flagArray[19]){this.addToMacroArray("NUMOFSPECIALCHR"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.retCharMsg(this.spCharDigitlen,"spch")); else this.addToErrorArray(this.getSpecMsg("NUMOFSPECIALCHR"));} //numberofSpecChar
if(this.flagArray[20]){this.addToMacroArray("NUMOFCONSECCHR"); if(this.defaultMessaging)this.addToErrorArray(this.messObj.retCharMsg(this.consCharDigitLen,"conChar")); else this.addToErrorArray(this.getSpecMsg("NUMOFCONSECCHR"));} //numberof consecutive chars

//if(this.flagArray[21]){ this.addToErrorArray(this.messObj.not_selected_error);} //deverror are set with the dev checks, deverror is always lasr
}//end val_setMessages

//function returns position of the macro in the macro array. added 1-31-05
function val_retMacroPos(mac)
{
count =-1;
for(var i=0; i<this.macroArray.length; i++)
	if(mac==this.macroArray[i]) {count=i; break;}

return count;   
}

//this function will replace the error masg in the errormsg array according to 
//the macro passed. if macro input here is not validated to see if it's correct. Make sure to 
//spell the macro correctly. this function is dependent on the retMacroPos function. added 1-31-05 
function val_replaceErrorMSG(mac,msg)
{var pos = this.retMacroPos(mac);
 if(pos!=-1) this.errormsgArray[pos] = msg;
}

//this function checks the value of the macro to see wheather it has been flagged for an error or not
//this function is dependent on the retMacroPos function. Returns true if the macro had an error and false
// if it didn't. added 1-31-05 
function val_checkSpecFlag(mac)
{var pos = this.retMacroPos(mac);
return (pos!=-1)?true:false;
}

function val_checkValidations()
{
 var allVal = this.textTypeValidations.concat(this.radioTypeValidations.concat(this.checkBoxTypeValidations.concat(this.pullDownTypeValidations)));
 var flag = false; var index=0;

 for(var i=0; i<this.validationTypes.length; i++)
  {if(flag)break; 
        for(var j=0; j<allVal.length; j++)
		    {if(this.validationTypes[i].indexOf(allVal[j])!=-1)
                 {flag = false; break;}
  		     else {flag = true; index=i;}
			}
 	}
 if(flag){this.setDevErrorFlag(true); this.addToErrorArray("Develpor Message: The "+this.validationTypes[index]+" parameter is incorrect or unrecognized please change to a valid macro");}
} 

//Macros MISSINGAT, MISSINGDOT, ISTIME are allowed here as a value. 
//if str=val and validation matches return msg string
//the getSpecMsg is only called when getting specific messages, Therefore Default messaging must be turned off.  
//this was changed 1-17-2005
function val_getSpecMsg(val) 
{
 var allVal = this.textTypeValidations.concat(this.radioTypeValidations.concat(this.checkBoxTypeValidations.concat(this.pullDownTypeValidations.concat(this.msgTypeValidations))));
 var str=""; var macArray = new Array("MAXFLDVALUELENGTH","MINFLDVALUELENGTH","EQFLDVALUELENGTH","NUMOFALPHA","NUMOFNUMBERS","NUMOFSPECIALCHR","SELECTDINDEXGT","NUMOFCONSECCHR")
if(!macMatch(macArray,val)) val+="_"; 

 if(!this.defaultMessaging)
  {
for(var i=0; i<this.validationTypes.length; i++)
	 { if(this.validationTypes[i].indexOf(val)!=-1) //check to see if its valid. and in place
		return(macMatch(macArray,val))? parseParamVal(this.validationTypes[i],1):parseParamVal(this.validationTypes[i]);
		
 	 }
	}//end if defalutmsg

}//end function 

//a function used to match the val to see if it needs to be parsed. used for the function above. 7-25-2005
function macMatch(arr,val)
{var matchFlag=false;
 for(var i=0; i<arr.length; i++)if(val==arr[i]){matchFlag=true; break;}
 
 return matchFlag;
}

//gets the value of the macros after the '_'. if there are 2 parameters passed it will get the value after the last
//'_' character. 
function parseParamVal(str)
{

var val = (parseInt(str.substring(str.indexOf('_')+1,str.length)).toString()=="NaN")? str.substring(str.indexOf('_')+1,str.length):parseInt(str.substring(str.indexOf('_')+1,str.length));

if(arguments[1]) val=str.substring(str.lastIndexOf('_')+1,str.length);

  if(typeof(val)=="string")
  {if(val.toString().toLowerCase()=="true")val=true;  if(val.toString().toLowerCase()=="false")val=false;}

 return(str!=""||str!=" ")?val:-1;
}

function LTrim(str) { // Returns string with left whitespaces trimmed
 if((str!=null)&&(str!=""))
  for (var i=0; str.charAt(i)==" "; i++);
   return str.substring(i,str.length);
}

function RTrim(str) { // Returns string with right whitespaces trimmed
   if((str!=null)&&(str!=""))
   for (var i=str.length-1; str.charAt(i)==" "; i--);
   return str.substring(0,i+1);
}


function val_checkType()
 {
  var formValType = new Array(); var flag = false; var index=0;

  if(this.type=="radio")formValType =  this.radioTypeValidations;
  if(this.type=="checkbox")formValType = this.checkBoxTypeValidations;
  if(this.type=="select-one")formValType = this.pullDownTypeValidations 
  if(this.type=="text"||this.type=="textarea"||this.type=="password"){formValType = this.textTypeValidations; this.setblankTypes(true);}
   for(var i=0; i<this.validationTypes.length; i++)
     { if(flag)break;
        for(var j=0; j<formValType.length; j++)
		    { if(this.validationTypes[i].indexOf(formValType[j])!=-1)
                 {flag = false; break;}
  		     else {flag = true; index=j;}
			}		
 	}
  if(flag){this.setDevErrorFlag(true); this.addToErrorArray("Develpor Message: The "+this.validationTypes[index]+" parameter is incorrect for the TYPE of field you are trying to validate.")}
 }
 
//extra check to make sure that if default messaging is turned off, that specific messages are being sent. 
function val_checkDefaultMess()
{if((!this.defaultMessaging)&&(this.errorFlag))
  if(this.errormsgArray.length==0)
    {this.setDevErrorFlag(true);  this.addToErrorArray(this.messObj.nomess_msg);}
}

//function used to overide the error message array. It erases the error array and puts in the overiding message
function val_globalMessOverRide(str)
{
if(this.errorFlag)
for(var i=this.errormsgArray.length; i>0; i--)  this.errormsgArray.pop();
this.errormsgArray.push(str);
}

//start validator functions
function val_isBlank(){
	
	var bRet = true;
	switch(this.type)
	{
		case "text":
		case "file":
		case "textarea":
		case "password":
				bRet = this.isEmpty();
				break;
		case "select-one":
		case "select-multiple":
				if (element.selectedIndex == -1){
						bRet = true;
				}else{
					if (this.isEmpty(this.formElementObjref.options[this.formElementObjref.selectedIndex].value) ||
							this.isEmpty(this.formElementObjref.options[this.formElementObjref.selectedIndex].text)){
						bRet = true;
					}else{
						bRet = false;
					}
				}
				break;
		case "radio":
				// Test a radio group 
				for (var i = 0; i < this.formElementObjref.length; i++){
					if(this.formElementObjref[i].checked) {bRet=false; break;}
				}
				break;
		case "checkbox":
				bRet = (!this.formElementObjref.checked)?false:true;
				break;
		default:
				this.setErrorDisplayName(this.formElementName);
				this.addToErrorArray(this.messObj.unex_error);
				bRet = false;
				break; 
	}
	//if(this.type=="radio")

	return bRet;
}//val_isblank

//function checks the number of alpha numeric characters in a string 
function val_checkNumOfAlpa()
{
var pattern = /^[A-Za-z]+$/;
var flag = true; var str = new String(this.formElementValue);
var count=0;

if((str==null)||(str==""))flag=false;

if(flag)
for(var i=0; i<str.length; i++)
 {
 if(pattern.test(str.charAt(i)))count++;
  if(count==this.alphaDigitLen){flag=false; break;}
 }
return flag;
}//check num of alpah

//function checks the number of numbers in a string 
function val_checkisNumOfNum()
{
var flag = true; var str = new String(this.formElementValue);
var count=0;

if((str==null)||(str==""))flag=false;

if(flag)
for(var i=0; i<str.length; i++)
 {
 if(!isNaN(str.charAt(i)))count++;
  if(count==this.numDigitLen){flag=false; break;}
 }
return flag;
}//check num of numbers 
 
function val_checkNumOfSpecCharFlag()
{
var flag = true; var str = new String(this.formElementValue);
var count=0;

if((str==null)||(str==""))flag=false;

if(flag)
for(var i=0; i<str.length; i++)
 {if((str.charCodeAt(i)>32)&&(str.charCodeAt(i)<=47))count++;
  if(count==this.spCharDigitlen){flag=false; break;}
 }
return flag;
}//check num of special characters 

//function checks the number of consecutive characters in a string 
function val_checkConsecChar()
{
var flag = false; var str = new String(this.formElementValue);
var count=0; var j=0;

if((str==null)||(str==""))flag=false;

if(flag)
for(var i=0; i<str.length; i++)
 { for(var j=1; j<this.consCharDigitLen; j++)
     { if(j>str.length)break;
	   if(str.charAt(i)!=str.charAt(i+j))break;
       else count++;  
	   if(count==this.consCharDigitLen){flag=true; break;} //this is never met if the chars are at the end of string
	  } 
 }
return flag;
}//check num of numbers 
 


function val_isEmpty(){
	if (this.formElementValue == null) return true;
	// Check whether string is empty.

	for (var intLoop = 0; intLoop < this.formElementValue.length; intLoop++)
		if ((" "!= this.formElementValue.charAt(intLoop))||(""!= this.formElementValue.charAt(intLoop)))  return false;

	return true;
}

function val_checkEMail(){
  if (this.isEmpty()) return false;
  var result = testEMail(this.formElementValue);
  if (result == false){ // Test to see if hyphen caused failure
    var pos = this.formElementValue.lastIndexOf(".");
    var front = (this.formElementValue.substring(0, pos));
    var ext = (this.formElementValue.substring(pos));
    this.formElementValue = front.replace(/-/g, "x");
    this.formElementValue = this.formElementValue + ext;
    result = testEMail(this.formElementValue);
  }
  return result;
}

function val_missingAt()
{
if (this.isEmpty()) return false;
var regex_at = /@/;
 return !(regex_at.test(this.formElementValue));
}//end val_missingAt

function val_missingDot()
{
if (this.isEmpty()) return false;
var regex_dot = /\./;
 return !(regex_dot.test(this.formElementValue));
}//end val_missingDot

function testEMail(str){
  var pattern1 = /(@.*@)|(\.\.)|(\\.\\.)|(@\\.)|(^\\.)/;
  var pattern2 = /^(\w[\w_-]*\.)*\w+@{1}(\w[\w_-]*\.)*\w+\.\w{2,3}$/;
   return !((!pattern1.test(str) && pattern2.test(str)));
}

function val_checkNumeric(){
	if (this.isEmpty()) return false;
	var v = parseFloat(this.formElementValue);
	  return (isNaN(v));
}
//this does change the property of the object
function val_checkDollar(){
	if (this.isEmpty()) return false;
    if (this.formElementValue.charAt(0) == "."){
      var temp = "0" + this.formElementValue;
      this.formElementValue = temp;
    }
	var pattern = /^(\d+(.\d{2})?)$/;
      return !(pattern.test(this.formElementValue));
}

function val_checkPhone(){
	if (this.isEmpty())	return false;
	var pattern = /^(\d{3})[-.]?(\d{3})[-.]?(\d{4})$/;
	return (!(pattern.test(this.formElementValue)));
}


function val_checkTime(){
	if (this.isEmpty())	return false;
	var pattern = /^(\d{2})[:]?(\d{2})$/;
	return !(pattern.test(this.formElementValue));
}


function val_checkAlpha(){ 
	if (this.isEmpty()) return false;
	var pattern = /^[A-Za-z]+$/;
return !(pattern.test(this.formElementValue));
}

function val_checkLengthEQ()
{if (this.isEmpty()) return false;
      return !((this.formElementValue.length == this.maxDigitLen)&&(this.formElementValue.length == this.minDigitLen));
}

function val_checkLengthMAX()
{if (this.isEmpty()) return false;
      return (this.formElementValue.length > this.maxDigitLen);
}

function val_checkLengthMIN()
{if (this.isEmpty()) return false;
      return (this.formElementValue.length < this.minDigitLen);
}

function val_checkDate(){
	if (this.isEmpty()) return false;
	var pattern = /^([01]{0,1}\d)[-\/]?([0123]{0,1}\d)[-\/]?((19|20)\d{2})$/;
	return !(pattern.test(this.formElementValue));
}

function val_checkMonth(){
	if (this.isEmpty()) return false;
	var pattern = /^(01|02|03|04|05|06|07|08|09|10|11|12)$/;
	return !(pattern.test(this.formElementValue));
}

function val_checkYear(){
	if (this.isEmpty()) return false;
	var pattern = /^((19|20)\d{2})$/;
	return !(pattern.test(this.formElementValue));
}

function val_checkZip(){
	if (this.isBlank()) return false;
	var pattern5 = /^\d{5}$/;
	var pattern54 = /^\d{5}-\d{4}$/;
	return !(pattern5.test(this.formElementValue)||pattern54.test(this.formElementValue));
}

function val_checkChecked(){return (this.isBlank());

}
function val_checkSelectedIndex(){return !(this.formElementObjref.selectedIndex>this.maxDigitLen);}

//creates an instance of the validation object (constructor)
//arguments passed in this order
//obj,displayname,blankchecks,defaultChecks,defaultmessaging,objlength(5th),validationarray,
//messagearray,presAlert,presWin,presLayer

function val_valObjInit()
{
this.checkType(); 
this.checkValidations(); 
this.setValidationTypes();
this.runblankChks(); 
this.runChecks();
this.checkFlags();
this.setMessages();
this.checkDefaultMess();
this.chkErrorFlag();




  /*
  this.setValDefaults();
  this.runChecks();
  this.setdefautMessages(); */
  
}//end val_checkType

validatorObj.prototype.valObjInit = val_valObjInit;
validatorObj.prototype.checkZip = val_checkZip;
validatorObj.prototype.checkYear = val_checkYear;
validatorObj.prototype.checkMonth = val_checkMonth;
validatorObj.prototype.checkDate = val_checkDate;
validatorObj.prototype.checkLengthEQ = val_checkLengthEQ;
validatorObj.prototype.checkLengthMIN = val_checkLengthMIN;
validatorObj.prototype.checkLengthMAX = val_checkLengthMAX;
validatorObj.prototype.checkAlpha = val_checkAlpha;
validatorObj.prototype.checkPhone = val_checkPhone;
validatorObj.prototype.checkNumeric = val_checkNumeric;
validatorObj.prototype.missingDot = val_missingDot;
validatorObj.prototype.missingAt = val_missingAt;
validatorObj.prototype.checkEMail = val_checkEMail;
validatorObj.prototype.isBlank = val_isBlank;
validatorObj.prototype.isEmpty = val_isEmpty;
validatorObj.prototype.addValidation = val_addValidation;
validatorObj.prototype.checkDate = val_setValDefaults;
validatorObj.prototype.setValDefaults = val_setValDefaults;
validatorObj.prototype.setErrorDisplayName = val_setErrorDisplayName;
validatorObj.prototype.setmaxDigitLenlength = val_setmaxDigitLenlength;
validatorObj.prototype.setminDigitLenlength = val_setminDigitLenlength;
validatorObj.prototype.chkErrorFlag = val_chkErrorFlag;
validatorObj.prototype.setblankTypes = val_setblankTypes;
validatorObj.prototype.runblankChks = val_runblankChks;
validatorObj.prototype.setdefautChecks = val_setdefautChecks;
validatorObj.prototype.setMessages = val_setMessages;
validatorObj.prototype.valObjInit = val_valObjInit;
validatorObj.prototype.runChecks = val_runChecks;
validatorObj.prototype.setDefaultChecks = val_setDefaultChecks;
validatorObj.prototype.setDefautMessaging = val_setDefautMessaging;
validatorObj.prototype.checkTime = val_checkTime;
validatorObj.prototype.checkType = val_checkType;
validatorObj.prototype.addToErrorArray = val_addToErrorArray;
validatorObj.prototype.setValidationTypes = val_setValidationTypes;
validatorObj.prototype.setErrorFlag = val_setErrorFlag;
validatorObj.prototype.checkValidations = val_checkValidations;
validatorObj.prototype.setDevErrorFlag = val_setDevErrorFlag;
validatorObj.prototype.checkFlags = val_checkFlags;
validatorObj.prototype.checkChecked = val_checkChecked;
validatorObj.prototype.checkSelectedIndex = val_checkSelectedIndex;
validatorObj.prototype.seteqDigitLenlength = val_seteqDigitLenlength;
validatorObj.prototype.getSpecMsg = val_getSpecMsg;
validatorObj.prototype.addToMsgSpecErrorArray = val_addToMsgSpecErrorArray;
validatorObj.prototype.showbgHighLightColor = val_showbgHighLightColor;
validatorObj.prototype.setbgHighLightColor =  val_setbgHighLightColor;
validatorObj.prototype.checkDefaultMess = val_checkDefaultMess;
validatorObj.prototype.globalMessOverRide = val_globalMessOverRide;
validatorObj.prototype.checkisNumOfNum = val_checkisNumOfNum;
validatorObj.prototype.checkNumOfSpecCharFlag = val_checkNumOfSpecCharFlag;
validatorObj.prototype.checkNumOfAlpa =  val_checkNumOfAlpa;
validatorObj.prototype.setAlphaDigitLenlength = val_setAlphaDigitLenlength;
validatorObj.prototype.setNumDigitLenlength = val_setNumDigitLenlength;
validatorObj.prototype.setSpCharDigitLenlength = val_setSpCharDigitLenlength;
validatorObj.prototype.checkConsecChar = val_checkConsecChar;
validatorObj.prototype.setconsCharDigitLen = val_setconsCharDigitLen;
validatorObj.prototype.addToMacroArray = val_addToMacroArray;
validatorObj.prototype.retMacroPos = val_retMacroPos;
validatorObj.prototype.replaceErrorMSG = val_replaceErrorMSG;
validatorObj.prototype.checkSpecFlag = val_checkSpecFlag;
validatorObj.prototype.getErrorFlag = val_getErrorFlag;