function ValidateForm(){var i,p1,p2,q,description,TestType,num,min,max;var ch,teststr;var first=0;var firstfield,PWvalue,PWdesc;var errors='';var error=false;var argu=ValidateForm.arguments;var args=argu;var fieldval,slength;if(args.length==1){args=argu[0].split(',');for(i=0;i<(args.length);i++){args[i]=args[i].replace(/'/g,"");}}
var formname=args[0];for(i=1;i<(args.length-2);i+=3){TestType=args[i+2];o=eval('document.'+formname+'.'+args[i]);if(o){description=args[i+1];fieldval=o.value;slength=o.value.length;if(fieldval!=""){if(TestType.indexOf('isEmail')!=-1){p1=o.value.indexOf('@');if(p1<1||p1==(slength-1))
errors+='* '+description+' must contain an e-mail address.\n';}
if(TestType.indexOf('isDate')!=-1){error=false;p1=o.value.indexOf('/');if(p1<1||p1>2){errors+='* '+description+' must be in dd/mm/yyyy format.\n';error=true;}else if(p1==1){o.value="0"+o.value;p1++;}
if(!error){p2=o.value.indexOf('/',p1+1);if(p2<4||p2>5){errors+='* '+description+' must be in dd/mm/yyyy format.\n';error=true;}else if(p2==4){o.value=o.value.substr(0,3)+"0"+o.value.substr(3);}}
if(!error){if(o.value.length<8||o.value.length==9){errors+='* '+description+' must be in dd/mm/yyyy format.\n';}else if(o.value.length==8){o.value=o.value.substr(0,6)+"20"+o.value.substr(6);}}}
if(TestType.indexOf('inString')!=-1){p1=TestType.indexOf(':');teststr=TestType.substr(p1+1);for(ch=0;ch<slength;ch++){if(teststr.indexOf(fieldval.substr(ch,1))==-1){errors+='* only "'+teststr+'" characters are allowed in '+description+'.\n';break;}}}
if(TestType.indexOf('stdString')!=-1){for(ch=0;ch<slength;ch++){p2=fieldval.charCodeAt(ch);if((p2<48&&p2!=32)||(p2>57&&p2<65)||(p2>90&&p2<97)||p2>122){errors+='* only characters A-Z,a-z and 0-9 and spaces are allowed in '+description+'.\n';break;}}}
if(TestType.indexOf('exclString')!=-1){p1=TestType.indexOf(':');teststr=unescape(TestType.substr(p1+1));for(ch=0;ch<slength;ch++){if(teststr.indexOf(fieldval.substr(ch,1))!=-1){errors+='* "'+teststr+'" characters are not allowed in '+description+'.\n';break;}}}
if(TestType.indexOf('minLength')!=-1){p1=TestType.indexOf(':');min=TestType.substr(p1+1);if(o.value.length<min){errors+='* '+description+' must be at least '+min+' characters long.\n';}}
if(TestType.indexOf('isNum')!=-1){num=parseFloat(fieldval);if(isNaN(fieldval))
errors+='* '+description+' must be numeric.\n';}
if(TestType.indexOf('inRange')!=-1){num=parseFloat(fieldval);p1=TestType.indexOf('inRange');p2=TestType.indexOf(':');min=TestType.substring(p1+7,p2);max=TestType.substr(p2+1);if(num<min||max<num)
errors+='* '+description+' must be a number between '+min+' and '+max+'.\n';}
if(TestType.indexOf('isPassword')!=-1){PWvalue=o.value;PWdesc=description;}
if(TestType.indexOf('isConfirm')!=-1){if(o.value!=PWvalue){errors+='* '+PWdesc+' is not confirmed.\n';}}
if(TestType.indexOf('isChecked')!=-1){if(!o.checked){errors+='* '+description+'\n';}}}else if(TestType.charAt(0)=='R'){errors+='* '+description+' can not be left blank.\n';}}
if(errors&&first==0){first=1;firstfield=o;}}
if(errors){alert('*** FORM INCOMPLETE ***\n\n'+errors);if(firstfield.type=="text"||firstfield.type=="textarea"||firstfield.type=="password"){firstfield.select();}
return false;}else{return true;}}
