
﻿
function WBEFormValidator()
{this.NIFValidator=new NIF_CIFValidator();this.posId=1;this.sLng='es';this.groupErrorMsg=false;this.sMsgMandatoryField="Por favor, introduzca un valor en el campo ";this.sMsgMaxLength="El texto introducido es demasiado largo. Actualmente tiene #current# caracteres. El máximo permitido es #max#."
this.oErrorLayer=null;this.LOGIN="^[a-zA-Z0-9_-]+$";this.PASSWORD="^[a-zA-Z0-9_-]+$";this.EMAIL="^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,4})+$";this.URL="(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\\.))+(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(/[a-zA-Z0-9\\&amp;%_\\./-~-]*)?";this.DIRECCIONWEB="(http://)*(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(/[a-zA-Z0-9\\&amp;%_\\./-~-]*)?";this.FECHA="^\\d{1,2}/\\d{1,2}/\\d{4}$";this.HORA="^\\d{1,2}:\\d{2}$";this.MATRICULA="^(\\d{4}[BCDFGHJKLMNPRSTVWXYZbcdfghjklmnprstvwxyz]{3})$|^([a-zA-Z]{1,2}\\d{4}[a-zA-Z]{1,2})$";this.ENTERO="^(-|[0-9])[0-9]*$";this.FLOAT="^(-|[0-9])[0-9]*(,|\.)[0-9]+$";this.POSTCODE="^\\d{5}$";this.TELEFONO="^\\d{9}$";this.WEBDIR="^[a-z0-9_·áàéèíïóòúüñç]+$";this.NOMBREDOMINIO="^[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])";this.MONEDA="^[0-9]{1,3}(\\.[0-9]{3})*(,[0-9]{1,2})?$|^[0-9]+(,[0-9]{1,2})?$";this.FLOAT2="^-?[0-9]+(,|\.)[0-9]+$";this.LOGIN_MIN_LONG=5;this.PASSWORD_MIN_LONG=5;this.setErrorLayerById=function(sId){this.oErrorLayer=document.getElementById(sId);};this.setErrorLayer=function(elem){this.oErrorLayer=elem;};this.check_frames=false;this.bJustResult=false;sInvalidDefault_es="Formato inválido, por favor revise los datos";this.texts_es=new Array();this.texts_es[0]="Por favor, introduzca un valor en el campo";this.texts_es[1]="El texto introducido es demasiado largo. Actualmente tiene #current# caracteres. El máximo permitido es #max#.";this.texts_es[2]="Debes de especificar un filtro de más de 3 letras.";this.texts_es[3]="El login solo admite letras, números, guiones, y guiones bajos.\nLa longitud mínima es de "+this.LOGIN_MIN_LONG+" caracteres.";this.texts_es[4]="El nombre de dominio no puede tener menos de 3 caracteres.\n No debe contener la letra ñ ni vocales acentuadas.";this.texts_es[5]="El password solo admite letras, números, guiones, y guiones bajos.\nLa longitud mínima es de "+this.PASSWORD_MIN_LONG+" caracteres.";this.texts_es[6]="Debe escribir una direccion de correo correcta";this.texts_es[7]=sInvalidDefault_es;this.texts_es[8]=sInvalidDefault_es;this.texts_es[9]=sInvalidDefault_es;this.texts_es[10]="Formato de fecha incorrecto. Formato correcto: dd/mm/aaaa";this.texts_es[11]=sInvalidDefault_es;this.texts_es[12]="NIF incorrecto. No debe contener ni guiones ni espacios.\n\nEj. 99999999P";this.texts_es[13]="CIF incorrecto. No debe contener ni guiones ni espacios.\n\nEj. B99999999";this.texts_es[14]="NIF / CIF incorrecto. No debe contener ni guiones ni espacios.\n\nEj. B99999999";this.texts_es[15]="Tarjeta de residencia incorrecta.  No debe contener ni guiones ni espacios. Ej. X00000000P";this.texts_es[16]="La matricula debe ser de la forma: 1111BBB o AA1111AA";this.texts_es[17]="Debe escribir un numero entero";this.texts_es[18]="Debe escribir un numero decimal XX,XX";this.texts_es[19]="Código postal incorrecto";this.texts_es[20]="Número incorrecto.\nDebe ser de la forma: 991112233 y contener 9 dígitos.";this.texts_es[21]="Directorio incorrecto. Sólo se pueden introducir caracteres en minúsculas, números y el subrayado.";this.texts_es[22]=sInvalidDefault_es;this.texts_es[23]="Fecha incorrecta";this.texts_es[24]="Cuenta bancaria incorrecta";this.texts_es[25]="El valor no coincide con su duplicado";this.texts_es[26]="-> Existen campos obligatorios sin rellenar.\n";sInvalidDefault_ca="Format inválid, per favor revise les dades introduides";this.texts_ca=new Array();this.texts_ca[0]="Per favor, cal introduir un valor al camp";this.texts_ca[1]="El text introduit es massa llarg. Actualment te #current# caracters. El màxim permés es #max#.";this.texts_ca[2]="Es deu especificar un filtre de mes de 3 lletres.";this.texts_ca[3]="El login sols admet lletres, nombres, guions, y guions baixos.\nLa longitud mínima es de "+this.LOGIN_MIN_LONG+" caracters.";this.texts_ca[4]="El nom de domini no pot tenir menys de 3 caracters.\n No pot contindre la lletra ñ ni vocals acentuades.";this.texts_ca[5]="El password sols admet lletres, nombres, guions, y guions baixos.\nLa longitud mínima es de "+this.PASSWORD_MIN_LONG+" caracters.";this.texts_ca[6]="Deu escriure una adressa de correu correcta";this.texts_ca[7]=sInvalidDefault_ca;this.texts_ca[8]=sInvalidDefault_ca;this.texts_ca[9]=sInvalidDefault_ca;this.texts_ca[10]="Format de la data incorrecte. Format correcte: dd/mm/aaaa";this.texts_ca[11]=sInvalidDefault_ca;this.texts_ca[12]="NIF incorrecte. No pot contindre ni guions ni espais.\n\nEj. 99999999P";this.texts_ca[13]="CIF incorrecte. No pot contindre ni guions ni espais.\n\nEj. B99999999";this.texts_ca[14]="NIF / CIF incorrecte. No pot contindre ni guions ni espais.\n\nEj. B99999999";this.texts_ca[15]="Tarjeta de residencia incorrecta. No pot contindre ni guions ni espais. Ej. X00000000P";this.texts_ca[16]="La matrícula deu ser de la forma: 1111BBB o AA1111AA";this.texts_ca[17]="Deu escriure un nombre senser";this.texts_ca[18]="Deu escriure un nombre decimal XX,XX";this.texts_ca[19]="Codi postal incorrecte";this.texts_ca[20]="Nombre incorrecte.\nDeu ser de la forma: 991112233 y contindre 9 dígits.";this.texts_ca[21]="Directori incorrecte. Sóls es poden introduir caracters en minúscules, nombres y el subratllat.";this.texts_ca[22]=sInvalidDefault_ca;this.texts_ca[23]="Data incorrecta";this.texts_ca[24]="Compte bancari incorrecte";this.texts_ca[25]="El valor no hi coincideix amb el duplicat";this.texts_ca[26]="-> Existeixen camps obligatoris sense plenar.\n";sInvalidDefault_en="Invalid format, please review input values";this.texts_en=new Array();this.texts_en[0]="Text field required";this.texts_en[1]="Text too long. You have typed #current# letters. Maximum letters allowed is #max# chars.";this.texts_en[2]="At least must type 3 chars.";this.texts_en[3]="El login sols admet lletres, nombres, guions, y guions baixos.\nLa longitud mínima es de "+this.LOGIN_MIN_LONG+" caracters.";this.texts_en[4]="El nom de domini no pot tenir menys de 3 caracters.\n No pot contindre la lletra ñ ni vocals acentuades.";this.texts_en[5]="El password sols admet lletres, nombres, guions, y guions baixos.\nLa longitud mínima es de "+this.PASSWORD_MIN_LONG+" caracters.";this.texts_en[6]="Deu escriure una adressa de correu correcta";this.texts_en[7]=sInvalidDefault_en;this.texts_en[8]=sInvalidDefault_en;this.texts_en[9]=sInvalidDefault_en;this.texts_en[10]="Format de la data incorrecte. Format correcte: dd/mm/aaaa";this.texts_en[11]=sInvalidDefault_en;this.texts_en[12]="NIF incorrecte. No pot contindre ni guions ni espais.\n\nEj. 99999999P";this.texts_en[13]="CIF incorrecte. No pot contindre ni guions ni espais.\n\nEj. B99999999";this.texts_en[14]="NIF / CIF incorrecte. No pot contindre ni guions ni espais.\n\nEj. B99999999";this.texts_en[15]="Tarjeta de residencia incorrecta. No pot contindre ni guions ni espais. Ej. X00000000P";this.texts_en[16]="La matrícula deu ser de la forma: 1111BBB o AA1111AA";this.texts_en[17]="Deu escriure un nombre senser";this.texts_en[18]="Deu escriure un nombre decimal XX,XX";this.texts_en[19]="Codi postal incorrecte";this.texts_en[20]="Nombre incorrecte.\nDeu ser de la forma: 991112233 y contindre 9 dígits.";this.texts_en[21]="Directori incorrecte. Sóls es poden introduir caracters en minúscules, nombres y el subratllat.";this.texts_en[22]=sInvalidDefault_en;this.texts_en[23]="Data incorrecta";this.texts_en[24]="Compte bancari incorrecte";this.texts_en[25]="El valor no hi coincideix amb el duplicat";this.texts_en[26]="-> Existeixen camps obligatoris sense plenar.\n";this.getText=function(sCode)
{switch(this.sLng){case'es':{switch(sCode){case'MandatoryField':return this.texts_es[0];break;case'MaxLength':return this.texts_es[1];break;case'InvalidFormat':return sInvalidDefault_es;break;case'SEARCH_BOX':return this.texts_es[2];break;case'LOGIN':return this.texts_es[3];break;case'NOMBREDOMINIO':return this.texts_es[4];break;case'PASSWORD':return this.texts_es[5];break;case'EMAIL':return this.texts_es[6];break;case'URL':return this.texts_es[7];break;case'DIRECCIONWEB':return this.texts_es[8];break;case'MONEDA':return this.texts_es[9];break;case'FECHA':return this.texts_es[10];break;case'HORA':return this.texts_es[11];break;case'NIF':return this.texts_es[12];break;case'CIF':return this.texts_es[13];break;case'NIF_CIF':return this.texts_es[14];break;case'TARJ_RESID':return this.texts_es[15];break;case'MATRICULA':return this.texts_es[16];break;case'ENTERO':return this.texts_es[17];break;case'FLOTANTE':return this.texts_es[18];break;case'POSTCODE':return this.texts_es[19];break;case'TELEFONO':return this.texts_es[20];break;case'WEBDIR':return this.texts_es[21];break;case'STRING':return this.texts_es[22];break;case'threefieldsdate':return this.texts_es[23];break;case'bankAccount':return this.texts_es[24];break;case'compareWith':return this.texts_es[25];break;case'errorMandatoryPresent':return this.texts_es[26];break;}}break;case'ca':{switch(sCode){case'MandatoryField':return this.texts_ca[0];break;case'MaxLength':return this.texts_ca[1];break;case'InvalidFormat':return sInvalidDefault_ca;break;case'SEARCH_BOX':return this.texts_ca[2];break;case'LOGIN':return this.texts_ca[3];break;case'NOMBREDOMINIO':return this.texts_ca[4];break;case'PASSWORD':return this.texts_ca[5];break;case'EMAIL':return this.texts_ca[6];break;case'URL':return this.texts_ca[7];break;case'DIRECCIONWEB':return this.texts_ca[8];break;case'MONEDA':return this.texts_ca[9];break;case'FECHA':return this.texts_ca[10];break;case'HORA':return this.texts_ca[11];break;case'NIF':return this.texts_ca[12];break;case'CIF':return this.texts_ca[13];break;case'NIF_CIF':return this.texts_ca[14];break;case'TARJ_RESID':return this.texts_ca[15];break;case'MATRICULA':return this.texts_ca[16];break;case'ENTERO':return this.texts_ca[17];break;case'FLOTANTE':return this.texts_ca[18];break;case'POSTCODE':return this.texts_ca[19];break;case'TELEFONO':return this.texts_ca[20];break;case'WEBDIR':return this.texts_ca[21];break;case'STRING':return this.texts_ca[22];break;case'threefieldsdate':return this.texts_ca[23];break;case'bankAccount':return this.texts_ca[24];break;case'compareWith':return this.texts_ca[25];break;case'errorMandatoryPresent':return this.texts_ca[26];break;}}break;case'en':{switch(sCode){case'MandatoryField':return this.texts_en[0];break;case'MaxLength':return this.texts_en[1];break;case'InvalidFormat':return sInvalidDefault_en;break;case'SEARCH_BOX':return this.texts_en[2];break;case'LOGIN':return this.texts_en[3];break;case'NOMBREDOMINIO':return this.texts_en[4];break;case'PASSWORD':return this.texts_en[5];break;case'EMAIL':return this.texts_en[6];break;case'URL':return this.texts_en[7];break;case'DIRECCIONWEB':return this.texts_en[8];break;case'MONEDA':return this.texts_en[9];break;case'FECHA':return this.texts_en[10];break;case'HORA':return this.texts_en[11];break;case'NIF':return this.texts_en[12];break;case'CIF':return this.texts_en[13];break;case'NIF_CIF':return this.texts_en[14];break;case'TARJ_RESID':return this.texts_en[15];break;case'MATRICULA':return this.texts_en[16];break;case'ENTERO':return this.texts_en[17];break;case'FLOTANTE':return this.texts_en[18];break;case'POSTCODE':return this.texts_en[19];break;case'TELEFONO':return this.texts_en[20];break;case'WEBDIR':return this.texts_en[21];break;case'STRING':return this.texts_en[22];break;case'threefieldsdate':return this.texts_en[23];break;case'bankAccount':return this.texts_en[24];break;case'compareWith':return this.texts_en[25];break;case'errorMandatoryPresent':return this.texts_en[26];break;}}break;}}
this.validateForm=function(formulario,pos_id,isRecursive,bJustResult)
{this.bJustResult=bJustResult;this.errorObjElements=new Array();this.errorFormatMsg=new Array();if(pos_id)pos_id=''+pos_id;for(var i=0;i<formulario.elements.length;i++)
{var elem=formulario.elements[i];var bvalidate=true;if(!elem.name){bvalidate=false;}else{var iLPos=(pos_id!=null)?elem.name.length-(pos_id.length+1):0;if(pos_id&&(elem.name.lastIndexOf('_'+pos_id)!=iLPos)){bvalidate=false;}}
if(bvalidate){if(elem.getAttribute("required"))
{var msgMandatoryField=elem.getAttribute("msgRequired");if(msgMandatoryField==null){msgMandatoryField=this.getText('MandatoryField');}
elem.style.backgroundColor='';switch(elem.type)
{case'':case'hidden':if(elem.value=='')
{this.ShowErrorMessage(msgMandatoryField,null);if(!this.groupErrorMsg)return false;}
break;case'file':if(elem.value=='')
{this.ShowErrorMessage(msgMandatoryField,null);if(!this.groupErrorMsg)return false;}
break;case'text':if(this.trimAll(elem.value)==''){this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
if(elem.defaultVal&&(elem.value==elem.defaultVal))
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;case'password':if(elem.value==''){this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
if(elem.defaultVal&&(elem.value==elem.defaultVal))
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;case'textarea':if(elem.value=='')
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;case'select-one':if(elem.value=='')
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;case'checkbox':if(!elem.checked)
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;case'radio':var seleccionado=false;var j=0;while(formulario.elements[i+j].type=='radio'&&elem.name==formulario.elements[i+j].name)
{if(formulario.elements[i+j].checked)seleccionado=true;if(i+j-1>=formulario.elements.length)break;j++;}
j=0;while(formulario.elements[i-j].type=='radio'&&elem.name==formulario.elements[i-j].name)
{if(formulario.elements[i-j].checked)seleccionado=true;if(i-j<=0)break;j++;}
if(!seleccionado)
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;}}
if(elem.getAttribute("maxTextLength"))
{var msgMaxLength=elem.getAttribute("msgMaxLength");if(msgMaxLength==null){msgMaxLength=this.getText('MaxLength');}
if(elem.value.length>elem.getAttribute("maxTextLength"))
{msgMaxLength=msgMaxLength.substring(0,msgMaxLength.indexOf('#current#'))+elem.value.length+msgMaxLength.substring(msgMaxLength.indexOf('#current#')+9);msgMaxLength=msgMaxLength.substring(0,msgMaxLength.indexOf('#max#'))+elem.getAttribute("maxTextLength")+msgMaxLength.substring(msgMaxLength.indexOf('#max#')+5);this.ShowErrorMessage(msgMaxLength,elem);if(!this.groupErrorMsg)return false;}}
var msgInvalidFormat=elem.getAttribute("msgInvalid");if(msgInvalidFormat!=null)msgInvalidFormat=this.getText('InvalidFormat').replace(/\\n/g,"\n");var bForzeError=false;switch(elem.type)
{case'':case'text':case'password':if(elem.getAttribute("expresionRegular")!=null&&elem.value!=''){var expresionRegular=elem.getAttribute("expresionRegular");var valor=elem.value;var re;switch(expresionRegular)
{case'SEARCH_BOX':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('SEARCH_BOX');}
bForzeError=(valor.length<3);re=null;break;case'LOGIN':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('LOGIN');}
bForzeError=(valor.length<this.LOGIN_MIN_LONG);re=new RegExp(this.LOGIN);break;case'NOMBREDOMINIO':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('NOMBREDOMINIO');}
re=new RegExp(this.NOMBREDOMINIO);break;case'PASSWORD':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('PASSWORD');}
bForzeError=(valor.length<this.PASSWORD_MIN_LONG);re=new RegExp(this.PASSWORD);break;case'EMAIL':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('EMAIL');}
re=new RegExp(this.EMAIL);break;case'URL':re=new RegExp(this.URL);break;case'DIRECCIONWEB':re=new RegExp(this.DIRECCIONWEB);break;case'MONEDA':case'MONEY':re=new RegExp(this.MONEDA);break;case'FECHA':case'DATE':re=new RegExp(this.FECHA);if(msgInvalidFormat==null)msgInvalidFormat=this.getText('FECHA');bForzeError=!this.chkdate(elem,null);break;case'HORA':case'HOUR':re=new RegExp(this.HORA);bForzeError=!this.chkHora(elem);break;case'NIF':if(msgInvalidFormat==null)msgInvalidFormat=this.getText('NIF');re=null;bForzeError=!this.NIFValidator.checkNIF(valor);break;case'CIF':if(msgInvalidFormat==null)msgInvalidFormat=this.getText('CIF');re=null;bForzeError=!this.NIFValidator.checkCIF(valor);break;case'NIF_CIF':if(msgInvalidFormat==null)msgInvalidFormat=this.getText('NIF_CIF');re=null;bForzeError=!this.NIFValidator.checkAll(valor);break;case'TARJ_RESID':if(msgInvalidFormat==null)msgInvalidFormat=this.getText('TARJ_RESID');re=null;bForzeError=!this.NIFValidator.checkTR(valor);break;case'TARJ_RESID_NIF':if(valor.charAt(0).toUpperCase()=="X"){if(msgInvalidFormat==null)msgInvalidFormat=this.getText('TARJ_RESID');bForzeError=!this.NIFValidator.checkTR(valor);}else{if(msgInvalidFormat==null)msgInvalidFormat=this.getText('NIF');bForzeError=!this.NIFValidator.checkNIF(valor);}
re=null;break;case'MATRICULA':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('MATRICULA');}
re=new RegExp(this.MATRICULA);break;case'DECIMAL':case'ENTERO':case'INT':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('ENTERO');}
re=new RegExp(this.ENTERO);break;case'FLOTANTE':case'FLOAT':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('FLOTANTE');}
re=new RegExp(this.FLOAT);break;case'FLOAT2':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('FLOTANTE');}
re=new RegExp(this.FLOAT2);break;case'POSTCODE':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('POSTCODE');}
re=new RegExp(this.POSTCODE);break;case'TELEFONO':case'PHONE':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('TELEFONO');}
re=new RegExp(this.TELEFONO);break;case'WEBDIR':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('WEBDIR');}
re=new RegExp(this.WEBDIR);break;case'STRING':re=null;break;default:re=new RegExp(expresionRegular);}
var customMsg=elem.getAttribute("errorMessage");if(customMsg&&customMsg!='')msgInvalidFormat=customMsg;if(msgInvalidFormat==null)msgInvalidFormat=this.getText('InvalidFormat');if(bForzeError||(re&&!re.test(valor))){this.ShowErrorMessage(msgInvalidFormat,elem,true);if(!this.groupErrorMsg)return false;}}}
if(elem.getAttribute("threefieldsdate")!=null&&elem.value!=''){if(msgInvalidFormat==null){msgInvalidFormat=this.getText('threefieldsdate');}
var threeFieldsValue=elem.getAttribute("threefieldsdate_"+this.pos_id);var day,month,year;var fullDate;var aFields=threeFieldsValue.split(",");if(aFields.length==3){day=document.getElementById(aFields[0]);month=document.getElementById(aFields[1]);year=document.getElementById(aFields[2]);fullDate=day.value+"/"+month.value+"/"+year.value;if(fullDate!=null){if(!chkdate(null,fullDate)){this.ShowErrorMessage(msgInvalidFormat,day);if(!this.groupErrorMsg)return false;}}}}
if(elem.getAttribute("bankAccount")!=null&&elem.value!=''){if(msgInvalidFormat==null){msgInvalidFormat=this.getText('bankAccount');}
var accountValues=elem.getAttribute("bankAccount_"+this.pos_id)
var entidad,oficina,cuenta,digitoControl;var aFields=accountValues.split(",");if(aFields.length==4){entidad=document.getElementById(aFields[0]);oficina=document.getElementById(aFields[1]);digitoControl=document.getElementById(aFields[2]);cuenta=document.getElementById(aFields[3]);if(entidad.value!=null){if(!checkDC(entidad.value+oficina.value,cuenta.value,digitoControl.value)){this.ShowErrorMessage(msgInvalidFormat,entidad);if(!this.groupErrorMsg)return false;}}}}
if(elem.getAttribute("compareWith"))
{var elem2=formulario.elements[elem.getAttribute("compareWith")];if(elem.value!=elem2.value){var msgNotEqual=elem.getAttribute("msgNotEqual")
if(msgNotEqual==null){msgNotEqual=this.getText('compareWith');}
this.ShowErrorMessage(msgNotEqual,elem);if(!this.groupErrorMsg)return false;}}}}
if(!isRecursive)
{var bFramesOk=true;if(this.check_frames)
{var nframes=window.frames.length;var oFrame;for(var i=0;i<nframes;i++){oFrame=window.frames[i];if(oFrame.document.forms[0]){var oFrmVal=new WBEFormValidator();var bFrameOk=oFrmVal.validateForm(oFrame.document.forms[0],'',true,true);this.bJustResult=false;if(!bFrameOk)
this.ShowErrorMessage(msgMandatoryField,oFrame.frameElement,false)
bFramesOk=bFramesOk&&bFrameOk;}}}}
if(this.groupErrorMsg)return this.showGroupedErrorMsgs();return true;}
this.validateFormWithPrefix=function(formulario,prefix)
{this.errorObjElements=new Array();this.errorFormatMsg=new Array();if(prefix)prefix=''+prefix;for(var i=0;i<formulario.elements.length;i++)
{var elem=formulario.elements[i];var bvalidate=true;if(!elem.name){bvalidate=false;}else{if(prefix&&prefix!=''&&(elem.name.indexOf(prefix)!=0)){bvalidate=false;}}
if(bvalidate){if(elem.getAttribute("required"))
{var msgMandatoryField=elem.getAttribute("msgRequired");if(msgMandatoryField==null){msgMandatoryField=this.getText('MandatoryField');}
elem.style.backgroundColor='';switch(elem.type)
{case'':case'hidden':if(elem.value=='')
{this.ShowErrorMessage(msgMandatoryField,null);if(!this.groupErrorMsg)return false;}
break;case'file':if(elem.value=='')
{this.ShowErrorMessage(msgMandatoryField,null);if(!this.groupErrorMsg)return false;}
break;case'text':case'password':if(elem.value==''){this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
if(elem.defaultVal&&(elem.value==elem.defaultVal))
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;case'textarea':if(elem.value=='')
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;case'select-one':if(elem.value=='')
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;case'checkbox':if(!elem.checked)
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;case'radio':var seleccionado=false;var j=0;while(formulario.elements[i+j].type=='radio'&&elem.name==formulario.elements[i+j].name)
{if(formulario.elements[i+j].checked)seleccionado=true;if(i+j-1>=formulario.elements.length)break;j++;}
j=0;while(formulario.elements[i-j].type=='radio'&&elem.name==formulario.elements[i-j].name)
{if(formulario.elements[i-j].checked)seleccionado=true;if(i-j<=0)break;j++;}
if(!seleccionado)
{this.ShowErrorMessage(msgMandatoryField,elem);if(!this.groupErrorMsg)return false;}
break;}}
if(elem.getAttribute("maxTextLength"))
{var msgMaxLength=elem.getAttribute("msgMaxLength");if(msgMaxLength==null){msgMaxLength=this.getText('MaxLength');}
if(elem.value.length>elem.getAttribute("maxTextLength"))
{msgMaxLength=msgMaxLength.substring(0,msgMaxLength.indexOf('#current#'))+elem.value.length+msgMaxLength.substring(msgMaxLength.indexOf('#current#')+9);msgMaxLength=msgMaxLength.substring(0,msgMaxLength.indexOf('#max#'))+elem.getAttribute("maxTextLength")+msgMaxLength.substring(msgMaxLength.indexOf('#max#')+5);this.ShowErrorMessage(msgMaxLength,elem);if(!this.groupErrorMsg)return false;}}
var msgInvalidFormat=elem.getAttribute("msgInvalid");if(msgInvalidFormat!=null)msgInvalidFormat=this.getText('InvalidFormat').replace(/\\n/g,"\n");var bForzeError=false;switch(elem.type)
{case'':case'text':case'password':if(elem.getAttribute("expresionRegular")!=null&&elem.value!=''){var expresionRegular=elem.getAttribute("expresionRegular");var valor=elem.value;var re;switch(expresionRegular)
{case'SEARCH_BOX':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('SEARCH_BOX');}
bForzeError=(valor.length<3);re=null;break;case'LOGIN':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('LOGIN');}
bForzeError=(valor.length<this.LOGIN_MIN_LONG);re=new RegExp(this.LOGIN);break;case'NOMBREDOMINIO':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('NOMBREDOMINIO');}
re=new RegExp(this.NOMBREDOMINIO);break;case'PASSWORD':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('PASSWORD');}
bForzeError=(valor.length<this.PASSWORD_MIN_LONG);re=new RegExp(this.PASSWORD);break;case'EMAIL':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('EMAIL');}
re=new RegExp(this.EMAIL);break;case'URL':re=new RegExp(this.URL);break;case'MONEDA':case'MONEY':re=new RegExp(this.MONEDA);break;case'FECHA':case'DATE':re=new RegExp(this.FECHA);if(msgInvalidFormat==null)msgInvalidFormat=this.getText('FECHA');bForzeError=!this.chkdate(elem,null);break;case'HORA':case'HOUR':re=new RegExp(this.HORA);bForzeError=!this.chkHora(elem);break;case'NIF':if(msgInvalidFormat==null)msgInvalidFormat=this.getText('NIF');re=null;bForzeError=!this.NIFValidator.checkNIF(valor);break;case'CIF':if(msgInvalidFormat==null)msgInvalidFormat=this.getText('CIF');re=null;bForzeError=!this.NIFValidator.checkCIF(valor);break;case'NIF_CIF':if(msgInvalidFormat==null)msgInvalidFormat=this.getText('NIF_CIF');re=null;bForzeError=!this.NIFValidator.checkAll(valor);break;case'TARJ_RESID':if(msgInvalidFormat==null)msgInvalidFormat=this.getText('TARJ_RESID');re=null;bForzeError=!this.NIFValidator.checkTR(valor);break;case'TARJ_RESID_NIF':if(valor.charAt(0).toUpperCase()=="X"){if(msgInvalidFormat==null)msgInvalidFormat=this.getText('TARJ_RESID');bForzeError=!this.NIFValidator.checkTR(valor);}else{if(msgInvalidFormat==null)msgInvalidFormat=this.getText('NIF');bForzeError=!this.NIFValidator.checkNIF(valor);}
re=null;break;case'MATRICULA':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('MATRICULA');}
re=new RegExp(this.MATRICULA);break;case'ENTERO':case'INT':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('ENTERO');}
re=new RegExp(this.ENTERO);break;case'FLOTANTE':case'FLOAT':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('FLOTANTE');}
re=new RegExp(this.FLOAT);break;case'POSTCODE':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('POSTCODE');}
re=new RegExp(this.POSTCODE);break;case'TELEFONO':case'PHONE':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('TELEFONO');}
re=new RegExp(this.TELEFONO);break;case'WEBDIR':if(msgInvalidFormat==null){msgInvalidFormat=this.getText('WEBDIR');}
re=new RegExp(this.WEBDIR);break;case'STRING':re=null;break;default:re=new RegExp(expresionRegular);}
var customMsg=elem.getAttribute("errorMessage");if(customMsg&&customMsg!='')msgInvalidFormat=customMsg;if(msgInvalidFormat==null)msgInvalidFormat=this.getText('InvalidFormat');if(bForzeError||(re&&!valor.match(re))){this.ShowErrorMessage(msgInvalidFormat,elem,true);if(!this.groupErrorMsg)return false;}}}
if(elem.getAttribute("threefieldsdate")!=null&&elem.value!=''){if(msgInvalidFormat==null){msgInvalidFormat=this.getText('threefieldsdate');}
var threeFieldsValue=elem.getAttribute("threefieldsdate_"+this.pos_id);var day,month,year;var fullDate;var aFields=threeFieldsValue.split(",");if(aFields.length==3){day=document.getElementById(aFields[0]);month=document.getElementById(aFields[1]);year=document.getElementById(aFields[2]);fullDate=day.value+"/"+month.value+"/"+year.value;if(fullDate!=null){if(!chkdate(null,fullDate)){this.ShowErrorMessage(msgInvalidFormat,day);if(!this.groupErrorMsg)return false;}}}}
if(elem.getAttribute("bankAccount")!=null&&elem.value!=''){if(msgInvalidFormat==null){msgInvalidFormat=this.getText('bankAccount');}
var accountValues=elem.getAttribute("bankAccount_"+this.pos_id)
var entidad,oficina,cuenta,digitoControl;var aFields=accountValues.split(",");if(aFields.length==4){entidad=document.getElementById(aFields[0]);oficina=document.getElementById(aFields[1]);digitoControl=document.getElementById(aFields[2]);cuenta=document.getElementById(aFields[3]);if(entidad.value!=null){if(!checkDC(entidad.value+oficina.value,cuenta.value,digitoControl.value)){this.ShowErrorMessage(msgInvalidFormat,entidad);if(!this.groupErrorMsg)return false;}}}}
if(elem.getAttribute("compareWith"))
{var elem2=formulario.elements[elem.getAttribute("compareWith")];if(elem.value!=elem2.value){var msgNotEqual=elem.getAttribute("msgNotEqual")
if(msgNotEqual==null){msgNotEqual=this.getText('compareWith');}
this.ShowErrorMessage(msgNotEqual,elem);if(!this.groupErrorMsg)return false;}}}}
if(this.groupErrorMsg)return this.showGroupedErrorMsgs();return true;}
this.SetFieldErrorStyle=function(_field){if(_field!=null&&_field.style.display!="none"){if(i==0)_field.focus();_field.style.backgroundColor='#ffffcc';}}
this.ShowErrorMessage=function(msgMandatoryField,oField,bFormatErrorMsg){if(this.onErrorHandler!=null)this.onErrorHandler(oField);if(this.oErrorLayer==null){if(this.groupErrorMsg){this.errorObjElements[this.errorObjElements.length]=oField;if(!bFormatErrorMsg)
this.errorMandatoryPresent=true;else
if(bFormatErrorMsg)this.errorFormatMsg[this.errorFormatMsg.length]=msgMandatoryField+'\n';}else{if((typeof this.bJustResult=='undefined')||(this.bJustResult==false))this.alertMsg(msgMandatoryField);this.SetFieldErrorStyle(oField);}}else{oErrorLayer.innerHTML='<p><b>'+msgMandatoryField+'</b></p>';oErrorLayer.style.display='';}}
this.showGroupedErrorMsgs=function(){var sMsg='';if(this.errorMandatoryPresent)sMsg+=this.getText('errorMandatoryPresent');for(var i=0;i<this.errorFormatMsg.length;i++){sMsg+='-> '+this.errorFormatMsg[i];}
if(sMsg!=''){for(var i=0;i<this.errorObjElements.length;i++){oField=this.errorObjElements[i];if((typeof this.bJustResult=='undefined')||(this.bJustResult==false))
this.SetFieldErrorStyle(oField);}
if((typeof this.bJustResult=='undefined')||(this.bJustResult==false))this.alertMsg(sMsg);return false;}
return true;}
this.alertMsg=function(sMsg){alert(sMsg);}
this.chkdate=function(objName,sValue){var strDatestyle="eu";var strDate;var strDateArray;var strDay;var strMonth;var strYear;var intday;var intMonth;var intYear;var booFound=false;var datefield=objName;var strSeparatorArray=new Array("-"," ","/",".");var intElementNr;var err=0;var strMonthArray=new Array(12);strMonthArray[0]="/01/";strMonthArray[1]="/2/";strMonthArray[2]="/3/";strMonthArray[3]="/4/";strMonthArray[4]="/5/";strMonthArray[5]="/6/";strMonthArray[6]="/7/";strMonthArray[7]="/8/";strMonthArray[8]="/9/";strMonthArray[9]="/10/";strMonthArray[10]="/11/";strMonthArray[11]="/12/";if(datefield!=null){strDate=datefield.value;}
if(sValue!=null){strDate=sValue;}
if(strDate.length<6){return false;}
for(intElementNr=0;intElementNr<strSeparatorArray.length;intElementNr++){if(strDate.indexOf(strSeparatorArray[intElementNr])!=-1){strDateArray=strDate.split(strSeparatorArray[intElementNr]);if(strDateArray.length!=3){err=1;return false;}
else{strDay=strDateArray[0];strMonth=strDateArray[1];strYear=strDateArray[2];}
booFound=true;}}
if(booFound==false){if(strDate.length>5){strDay=strDate.substr(0,2);strMonth=strDate.substr(2,2);strYear=strDate.substr(4);}}
if(strYear.length==2){strYear='20'+strYear;}
if(strDatestyle=="US"){strTemp=strDay;strDay=strMonth;strMonth=strTemp;}
intday=parseInt(strDay,10);if(isNaN(intday)){err=2;return false;}
intMonth=parseInt(strMonth,10);if(isNaN(intMonth)){for(i=0;i<12;i++){if(strMonth.toUpperCase()==strMonthArray[i].toUpperCase()){intMonth=i+1;strMonth=strMonthArray[i];i=12;}}
if(isNaN(intMonth)){err=3;return false;}}
intYear=parseInt(strYear,10);if(isNaN(intYear)){err=4;return false;}
if(intMonth>12||intMonth<1){err=5;return false;}
if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intday>31||intday<1)){err=6;return false;}
if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intday>30||intday<1)){err=7;return false;}
if(intMonth==2){if(intday<1){err=8;return false;}
if(this.LeapYear(intYear)==true){if(intday>29){err=9;return false;}}
else{if(intday>28){err=10;return false;}}}
return true;}
this.LeapYear=function(intYear){if(intYear%100==0){if(intYear%400==0){return true;}}
else{if((intYear%4)==0){return true;}}
return false;}
this.chkHora=function(lahora){var arrHora=(lahora.value).split(":");if(arrHora.length!=2){return false;}
if(parseInt(arrHora[0])<0&&parseInt(arrHora[0])>23){return false;}
if(parseInt(arrHora[1])<0&&parseInt(arrHora[1])>59){return false;}
return true;}
this.checkDC=function(cc1,cc2,dc){return true;if(!(cc1.match(/^\d{8}$/)&&cc2.match(/^\d{10}$/)&&dc.match(/^\d{2}$/)))return false;var arrWeights=new Array(1,2,4,8,5,10,9,7,3,6);var dc1=0,dc2=0;for(i=7;i>=0;i--)dc1+=arrWeights[i+2]*cc1.charAt(i);dc1=11-(dc1%11);if(11==dc1)dc1=0;if(10==dc1)dc1=1;for(i=9;i>=0;i--)dc2+=arrWeights[i]*cc2.charAt(i);dc2=11-(dc2%11);if(11==dc2)dc2=0;if(10==dc2)dc2=1;return(10*dc1+dc2==dc);}
this.leftTrim=function(stringToTrim){return stringToTrim.replace(/^\s+/,"");};this.rightTrim=function(stringToTrim){return stringToTrim.replace(/\s+$/,"");};this.trimAll=function(stringToTrim){return stringToTrim.replace(/^\s+|\s+$/g,"");};this.checkMandatoryText=function(elem,error_elem,error_msg){if(elem.value==''){error_elem.innerHTML+=error_msg;return false;}
return true;};this.checkMandatorySelect=function(elem,error_elem,error_msg){if(elem.selectedIndex==-1){error_elem.innerHTML+=error_msg;return false;}
return true;};this.checkMandatoryOpt=function(elem,error_elem,error_msg){var bOK=false;if(elem.value){bOK=elem.checked;}else{for(var i=0;i<elem.length;i++){if(elem[i].checked){bOK=true;break;}}}
if(!bOK){error_elem.innerHTML+=error_msg;return false;}
return true;};this.checkMinLengthText=function(elem,len,error_elem,error_msg){if(this.trimAll(elem.value).length<len){error_elem.innerHTML+=error_msg;return false;}
return true;};this.checkMaxLengthText=function(elem,len,error_elem,error_msg){if(elem.value.length>len){error_elem.innerHTML+=error_msg;return false;}
return true;};this.checkMinLengthSelect=function(elem,len,error_elem,error_msg){var sels=0;for(var i=0;i<elem.options.length;i++){if(elem.options[i].selected)sels++;}
if(sels<len){error_elem.innerHTML+=error_msg;return false;}
return true;};this.checkMaxLengthSelect=function(elem,len,error_elem,error_msg){var sels=0;for(var i=0;i<elem.options.length;i++){if(elem.options[i].selected)sels++;}
if(sels>len){error_elem.innerHTML+=error_msg;return false;}
return true;};this.checkMinLengthOpt=function(elem,len,error_elem,error_msg){var sels=0;if(elem.value){if(elem.checked)sels++;}else{for(var i=0;i<elem.length;i++){if(elem[i].checked){sels++;}}}
if(sels<len){error_elem.innerHTML+=error_msg;return false;}
return true;};this.checkMaxLengthOpt=function(elem,len,error_elem,error_msg){var sels=0;if(elem.value){if(elem.checked)sels++;}else{for(var i=0;i<elem.length;i++){if(elem[i].checked){sels++;}}}
if(sels>len){error_elem.innerHTML+=error_msg;return false;}
return true;};this.getOptValue=function(elem){var sResult='';if(elem.value){if(elem.checked)sResult=elem.value;}else{for(var i=0;i<elem.length;i++){if(elem[i].checked){if(sResult.length!=0)sResult+=",";sResult+=elem[i].value;}}}
return sResult;};this.getMultiSelectValue=function(elem){var sResult='';for(var i=0;i<elem.options.length;i++){if(elem.options[i].selected){if(sResult.length!=0)sResult+=",";sResult+=elem[i].value;}}
return sResult;};this.changeIds=function changeIds(elem,pattern,text){var x=elem.childNodes;if(x){for(var i=0;i<x.length;i++){changeIds(x[i],pattern,text);if(x[i].id){x[i].id=x[i].id.replace(pattern,text);}
if(x[i].attributes){for(var j=0;j<x[i].attributes.length;j++){if((x[i].attributes[j].nodeName.toLowerCase()=='for')||(x[i].attributes[j].nodeName.toLowerCase()=='href')||(x[i].attributes[j].nodeName.toLowerCase()=='value')){x[i].attributes[j].nodeValue=x[i].attributes[j].nodeValue.replace(pattern,text);}}}}}};this.showMsgs=function(sPosId,asMsgs){var elem;var sText;elem=document.getElementById('messages_ok_'+sPosId);elem.innerHTML='';elem.style.display='';sText='<ul>';for(var i=0;i<asMsgs.length;i++){if(asMsgs[i].length>0){sText+='<li>'+asMsgs[i]+'</li>';}}
sText+='</ul>';elem.innerHTML=sText;};this.showErrors=function(sPosId,asMsgs){var elem;var sText;elem=document.getElementById('messages_error_'+sPosId);elem.innerHTML='';elem.style.display='';sText='<ul>';for(var i=0;i<asMsgs.length;i++){if(asMsgs[i].length>0){sText+='<li>'+asMsgs[i]+'</li>';}}
sText+='</ul>';elem.innerHTML=sText;};this.hideMsgs=function(sPosId){var elem;elem=document.getElementById('messages_ok_'+sPosId);elem.innerHTML='';elem.style.display='none';};this.hideErrors=function(sPosId){var elem;elem=document.getElementById('messages_error_'+sPosId);elem.innerHTML='';elem.style.display='none';};};function NIF_CIFValidator(){this.NIF_Letters="TRWAGMYFPDXBNJZSQVHLCKET";this.NIF_regExp="^\\d{8}[a-zA-Z]{1}$";this.CIF_regExp="^[a-zA-Z]{1}\\d{7}[a-jA-J0-9]{1}$";this.checkAll=function(value){if(this.checkCIF(value)){return true;}else if(this.checkTR(value)){return true;}else if(this.checkNIF(value)){return true;}else{return false;}}
this.checkNIF=function(nif){if((nif.length!=8)&&(nif.length!=9))return false;if(nif.length==8)nif='0'+nif;var regExp=new RegExp(this.NIF_regExp);if(!nif.match(regExp))return false;var let=nif.charAt(nif.length-1);var dni=nif.substring(0,nif.length-1)
var letra=this.NIF_Letters.charAt(dni%23);return(letra==let.toUpperCase());}
this.checkTR=function(tr){if((tr.length!=10)&&(tr.length!=9))return false;if((tr.charAt(0).toUpperCase()!="X"))return false;if(tr.length==9){return this.checkNIF('0'+tr.substring(1,tr.length));}else{return this.checkNIF(tr.substring(1,tr.length));}}
this.checkCIF=function(cif){var v1=new Array(0,2,4,6,8,1,3,5,7,9);var tempStr=cif.toUpperCase();var temp=0;var temp1;var dc;var regExp=new RegExp(this.CIF_regExp);if(!tempStr.match(regExp))return false;if(!/^[ABCDEFGHKLMNPQS]/.test(tempStr))return false;for(i=2;i<=6;i+=2){temp=temp+v1[parseInt(cif.substr(i-1,1))];temp=temp+parseInt(cif.substr(i,1));};temp=temp+v1[parseInt(cif.substr(7,1))];temp=(10-(temp%10));if(temp==10)temp=0;dc=cif.toUpperCase().charAt(8);return(dc==temp)||(temp==1&&dc=='A')||(temp==2&&dc=='B')||(temp==3&&dc=='C')||(temp==4&&dc=='D')||(temp==5&&dc=='E')||(temp==6&&dc=='F')||(temp==7&&dc=='G')||(temp==8&&dc=='H')||(temp==9&&dc=='I')||(temp==0&&dc=='J');}}