    // Validator Object
    var valid = new Object();
    var errmsg = new Object();

    // REGEX Elements

        // matches zip codes
        valid.zipCode = /\d{5}(-\d{4})?/;
        errmsg.zipCode = "You entered an incorrect zip code.";

        // matches $17.23 or $14,281,545.45 or ...
        valid.Currency = /\$\d{1,3}(,\d{3})*\.\d{2}/;
        errmsg.Currency = "You entered an invalid amount.";

        // matches 5:04 or 12:34 but not 75:83
        valid.Time = /^([1-9]|1[0-2]):[0-5]\d$/;
        errmsg.Time = "You entered an invalid time.";

        //matches email
        valid.emailAddress = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
        errmsg.emailAddress = "You entered an invalid email address.";

        // matches phone ###-###-####
        valid.phoneNumber = /\d{3}\D*\d{3}\D*\d{4}$/;
        errmsg.phoneNumber = "You entered an invalid phone number.";

        // International Phone Number
        valid.phoneNumberInternational = /^\d(\d|-){7,20}/;
        errmsg.phoneNumberInternational = "You entered an invalid phone number.";
        
        // IP Address
        valid.ipAddress = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
        errmsg.ipAddress = "You entered an invalid IP address.";

        // Date xx/xx/xxxx
        valid.Date = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
        errmsg.Date = "You entered an invalid date.";

        // State Abbreviation
        valid.State = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NE|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY|AE)$/i;
        errmsg.State = "You entered an invalid state. Use the 2 character state abbreviation.";

        // Social Security Number
        valid.SSN = /^\d{3}\-\d{2}\-\d{4}$/;
        errmsg.SSN = "You entered an invalid social security number.";

		// Required text
        valid.reqtext = /\S/;
        errmsg.reqtext = "You left a required field blank.";
        
        // Credit card
        valid.cc = /^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$/;
        errmsg.cc = "You entered an invalid credit card number.";
        
        // Month (as 1 or 2 digits)
        valid.month = /\d{1,2}/;
        errmsg.month = "Please specify the expiration month for your credit card.";

        // Year (as 4 digits)
        valid.year = /\d4/;
        errmsg.year = "Please specify the expiration year for your credit card.";
        
        // MRB Code (for registration code requests)
        valid.mrbcode = /mrb314|MRB314/;
        errmsg.mrbcode = "You entered an invalid MRB code.";
    
    function validateForm(theForm) {

        var elArr = theForm.elements; 

        for(var i = 0; i < elArr.length; i++) {

	       if (! elArr[i].disabled) {
	        
           	with(elArr[i]) { 

              	var v = elArr[i].validator; 

              	if(!v) continue;
              
              	var thePat = valid[v];

              	if (v == "State"|| v == "zipCode") {
	            //  	alert (elArr[0].selectedIndex);
				//	alert (theForm.getElementById('countryname').selectedIndex);
					if (elArr[0].selectedIndex != 0 && elArr[0].selectedIndex != 228) continue;
				}

              	if ((v == "month") || (v == "year")) {
	            	  if (elArr[i].selectedIndex == 0) {
		            	  alert(errmsg[v]);
		            	  elArr[i].focus();
		              	return false;
	          			}
				}
	         	else {
              	var gotIt = thePat.exec(value); 

              	if(! gotIt){
					 alert(errmsg[v]);
	             	//alert(name + ": failure to match " + v + " to " + value);                  
                 	elArr[i].select();
                 	elArr[i].focus(); 
                 	return false;
                	}
              	}
           	 }
           }
        }

        return true;

    }
