var FormValidator=function(pForm){this.gForm=document.forms[pForm];this.gFields=new Array();this.gMsgErro='';this.gSubmitButton='';this.gErrCount=0;this.gFieldFocus='';var lAlertErro=true;if(arguments.length>1){lAlertErro=arguments[1]}if(!this.gForm){if(lAlertErro){alert('Formulario inexistente: '+pForm)}}else{addEvent(this.gForm,"submit",this.formSubmit,this)}};FormValidator.prototype.addField=function(pField,pAlias,pType){var o=new Object();o.field=pField;o.alias=pAlias;o.type=pType;this.gFields.push(o)};FormValidator.prototype.setSubmitButton=function(pField){this.gSubmitButton=pField};FormValidator.prototype.formSubmit=function(){this.validate();lReturn=true;if(this.gErrCount>0){alert(this.gMsgErro);try{this.gForm.elements[this.gFieldFocus].focus();this.gForm.elements[this.gFieldFocus].select()}catch(e){}lReturn=false}else{if(this.gSubmitButton!=''){this.gForm.elements[this.gSubmitButton].disabled=true}try{eval("lReturn = afterSubmit"+this.gForm.name.toUpperCase()+"()");eval("this.gForm.elements[this.gSubmitButton].disabled = lReturn;")}catch(e){}}return lReturn};FormValidator.prototype.getField=function(pField){return this.gForm.elements[pField]};FormValidator.prototype.validate=function(){var lType;var lFieldValue;var lErrField=0;this.gMsgErro='';this.gErrCount=0;this.gFieldFocus='';if(this.gFields.length>0){for(i=0;i<this.gFields.length;i++){lErrField=0;lField=this.gForm.elements[this.gFields[i].field];if(lField!=undefined){lFieldValue=lField.value;lAux=this.gFields[i].type.split("|");for(j=0;j<lAux.length;j++){lType=lAux[j];lParam='';if(lAux[j].search("=")>-1){lTypeAux=lAux[j].split("=");lType=lTypeAux[0];lParam=lTypeAux[1]}switch(lType){case"req":{if(lFieldValue.length==0){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve ser preenchido.\n';this.gErrCount++;lErrField++}break}case"email":{var lPatternEmail=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;if((lFieldValue.length>0)&&(!lPatternEmail.test(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve ser preenchido com um e-mail valido.\n';this.gErrCount++;lErrField++}break}case"mnl":{if((lFieldValue.length>0)&&(lFieldValue.length<(lParam*1))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve conter no minimo '+lParam+' caracters.\n';this.gErrCount++;lErrField++}break}case"mxl":{if((lFieldValue.length>0)&&(lFieldValue.length>(lParam*1))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve conter no maximo '+lParam+' caracters.\n';this.gErrCount++;lErrField++}break}case"date":{if((lFieldValue.length>0)&&(!isDate(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve ser preenchido com uma data valida.\n';this.gErrCount++;lErrField++}break}case"num":{if((lFieldValue.length>0)&&(isNaN(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve conter somente numeros [0-9].\n';this.gErrCount++;lErrField++}break}case"al":{var lPatternAlpha=/^[A-Za-z]*$/;if((lFieldValue.length>0)&&(!lPatternAlpha.test(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve conter somente letras [A-Z].\n';this.gErrCount++;lErrField++}break}case"alnum":{var lPatternAlpha=/^[A-Za-z0-9]*$/;if((lFieldValue.length>0)&&(!lPatternAlpha.test(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve conter somente letras [A-Z] e numeros [0-9].\n';this.gErrCount++;lErrField++}break}case"alnumt":{var lPatternAlpha=/^[A-Za-z0-9-]*$/;if((lFieldValue.length>0)&&(!lPatternAlpha.test(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve conter somente letras [A-Z], numeros [0-9] e [-].\n';this.gErrCount++;lErrField++}break}case"alnumu":{var lPatternAlpha=/^[A-Za-z0-9_]*$/;if((lFieldValue.length>0)&&(!lPatternAlpha.test(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve conter somente letras [A-Z], numeros [0-9] e [_].\n';this.gErrCount++;lErrField++}break}case"alnumtu":{var lPatternAlpha=/^[A-Za-z0-9-_]*$/;if((lFieldValue.length>0)&&(!lPatternAlpha.test(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve conter somente letras [A-Z], numeros [0-9] e [-_].\n';this.gErrCount++;lErrField++}break}case"lt":{if(((lFieldValue*1)>=(lParam*1))&&(!isNaN(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve ter um valor menor que '+lParam+'.\n';this.gErrCount++;lErrField++}break}case"gt":{if(((lFieldValue*1)<=(lParam*1))&&(!isNaN(lFieldValue))){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' deve ter um valor maior que '+lParam+'.\n';this.gErrCount++;lErrField++}break}case"rb":{var lChecked=false;if(lField.length==undefined){lChecked=lField.checked}else{for(r=0;r<lField.length&&(!lChecked);r++){lChecked=lField[r].checked}}if(!lChecked){this.gMsgErro+='- O campo '+this.gFields[i].alias.toUpperCase()+' e de preenchimento obrigatorio.\n';this.gErrCount++;lErrField++}break}}if(lErrField>0){if(this.gFieldFocus==''){this.gFieldFocus=this.gFields[i].field}break}}}}}};function showMsg(pText,pType){var formContent=$("fContent");if(formContent){var objMsg=document.createElement("div");objMsg.id='infoMsg';objMsg.innerHTML=pText;switch(pType){case 1:{objMsg.className='infoMsg msgOk';break}case 2:{objMsg.className='infoMsg msgError';break}}formContent.insertBefore(objMsg,formContent.firstChild)}else{alert(pText)}};