function CValidate()
{ 
 this.mintErrorCount = 0;
 this.mstrErrors = new Array();
 
 //------------------------------------
 //clears err object
 this.clearErrs = function()
 {
    this.mstrErrors = new Array();
    this.mintErrorCount = 0;
 }
 
 //------------------------------------------
 this.getErrorCount = function()
 {
 	  return this.mintErrorCount;
 }
 
 //---------------------------------------------
 this.checkRequiredField = function(strTextToValidate, strFieldName)
 {
    if(strTextToValidate == "")
    {
    	 this.mstrErrors[this.mintErrorCount++] = strFieldName + " must be filled in";
       return false;
    }
    return true;   
 }
 
 //-----------------------------------------------
 this.hasErrors = function()
 {
     if ( this.mintErrorCount > 0 )   return true;
     return false;
 }
 
 //----------------------------------------------------- 
 this.getErrorString = function()
 {
     var strErrors = "";
     if ( this.mintErrorCount < 1 )
        return strErrors;
         
     strErrors += this.mstrErrors[0]
     for ( c = 1; c < this.mintErrorCount; c++)
     {
        if ( c < this.mintErrorCount - 1)
           strErrors += ", ";
        if ( c ==  this.mintErrorCount - 1)
           strErrors += " and";
        strErrors += (" " + this.mstrErrors[c]);
      }
      strErrors += ".";
      return strErrors;
 }
 
  //---------------------------------------------------------------
   this.isNumeric = function(strValue)
   {
    	strNumbers = "0123456789";
    	
    	for ( n = 0; n < strValue.length; n++)
    	{
    		for( m = 0; m < strNumbers.length; m++)
    			 if( strNumbers.charAt(m) == strValue.charAt(n))  break;
    		
    		if ( m == strNumbers.length) return false;
    	}
    	return true;
   }
 
  //--------------------------------------------------------------
 //This function evaluates an alphanumeric string ( for zip codes, phone numbers, etc)
 //Mask format
 // x - digit
 //all else is evaluated literally
 this.checkAlphaNumeric = function(strValue, strMask, strFieldName)
 {
       if ( strValue.length != strMask.length)
       {
       	  this.mstrErrors[this.mintErrorCount++] = strFieldName + " is not the correct length";
          return false;
       }   
       
       for ( c = 0; c < strMask.length; c++)
       { 
          if ( strMask.charAt(c) == "x")
          {   if ( ! this.isNumeric(strValue.charAt(c))) break;  }
          else if(! strMask.charAt(c) == strValue.charAt(c)) break;
       }
       if ( c < strMask.length)
       {
          this.mstrErrors[this.mintErrorCount++] = strFieldName + " is not formatted properly";
          return false;
       }
       return true;
 } 

 //-------------------------------------------------------------------
 this.checkEmailAddress = function(strAddress)
 {
 	   if ( ! strAddress.match("^.+@.+\\..+$"))
 	   {
 	     this.mstrErrors[this.mintErrorCount++] = "Email address is not valid";
 	     return false;
 	   }
 	   return true;
 }
}

