var PatternsDict = new Object();
PatternsDict.textPat = /[a-z][a-z]/i;
// matches name and other text fields - must be at least 2 alpha characters.

PatternsDict.zipPat = /\d{5}(-\d{4})?/;
// matches zip codes

PatternsDict.currencyPat = /\$\d{1,3}(,\d{3})*\.\d{2}/;
// matches $17.23 or $14,281,545.45 or ...

PatternsDict.timePat = /\d{2}:\d{2}/;
// matches 12:34 but also 75:83

PatternsDict.timePat2=/^([1-9]|1[0-2]):[0-5]\d$/;
// matches 5:04 or 12:34 but not 75:83

PatternsDict.ssnPat=/\d{9}/;
// matches social security number - no hyphens

PatternsDict.ssn2Pat=/\d{3}-\d{2}-\d{4}/;
// matches NNS - with hyphens

PatternsDict.timePat2=/^([1-9]|1[0-2]):[0-5]\d$/;
// matches 5:04 or 12:34 but not 75:83

PatternsDict.emailPat=/^(.+)@(.+)[.][a-z]|[A-Z]$/
// matches E-mail address

PatternsDict.integer=/^\d+$/;
// matches Integer

PatternsDict.noempty=/./;
// matches Integer

function validateForm(theForm){// return true if all is well
var elArr = theForm.elements; // get all elements of the form into array
for(var i = 0; i < elArr.length; i++)
with(elArr[i]){ // for each element of the form...
var v = elArr[i].validator; // get validator, if any
if(!v) continue; // no validator property, skip
var thePat = PatternsDict[v]; // select the validating regular expr
var gotIt = thePat.exec(value); // run it on value of elArr[i]
if(!gotIt){
//alert("As informações preenchidas no campo ["+name + "] está incorreta ou insuficiente/nfailure to match " + v + " to " + value);
alert("As informações preenchidas no campo ["+name + "] \nestão incorretas ou insuficientes. Por favor,\nentre com as informações corretas.");
elArr[i].select();
elArr[i].focus();
 return false;}
} return true;
}
