var matcherAlphaDigitCplx2=/^[a-zA-Z0-9_"' \n\r\!\@\#\$\%\^\*\(\)\-\+\=\:\;\,\.\/\?\|\\\~\{\}\[\]]*$/;function CW_Format(){}CW_Format.prototype={FORMAT_EMAIL:"email",FORMAT_2Tags:"2tags",FORMAT_INTER_PHONE_NB:"interPhoneNb",FORMAT_DIGIT:"digit",FORMAT_ALPHA_DIGIT:"alphadigit",FORMAT_ALPHA_DIGIT_CPLX:"alphadigitcplx",FORMAT_ALPHA_DIGIT_CPLX2:"alphadigitcplx2",invalidCharacters:new Array("&","<",">"),isValidFormat:function(C,A){switch(C){case (CW_Format.FORMAT_EMAIL):return this.isValidEMail(A);case (CW_Format.FORMAT_2Tags):return this.isValid2Tags(A);case (CW_Format.FORMAT_INTER_PHONE_NB):return this.isValidInterPhoneNb(A);case (CW_Format.FORMAT_ALPHA_DIGIT):return this.isValidAlphaDigit(A);case (CW_Format.FORMAT_ALPHA_DIGIT_CPLX):return this.isValidAlphaDigitCPLX(A);case (CW_Format.FORMAT_ALPHA_DIGIT_CPLX2):return this.isValidAlphaDigitCPLX2(A);case (CW_Format.FORMAT_DIGIT):return this.isValidDigit(A);break;default:var B=new Error();B.message="CW_Format : unknown given format:"+C;throw B;break}},isValidEMail:function(A){var B=new RegExp("^[a-zA-Z0-9_]+[a-zA-Z0-9.-_]{1,}@[a-zA-Z0-9-_]{2,}.[a-zA-Z.-_]{1,}[a-zA-Z-_]+","g");return B.test(A)},isValid2Tags:function(B){var A=this.getSimplifyTags(B);if(A!=""&&A!=""){var C=A.split(",");return C.length>1}else{return false}},isValidInterPhoneNb:function(B){if(B==null||B=="null"||B==""){return false}if(B.length!=12){return false}var A=new RegExp("[+][0-9]{11}$","g");return A.test(B)},isValidDigit:function(B){if(B==null||B=="null"||B==""){return false}var A=new RegExp("^[0-9]+$","g");return A.test(B)},isValidAlphaDigit:function(A){if(A==null||A=="null"||A==""){return false}var B=new RegExp("^[a-zA-Z0-9]+$");return B.test(A)},isValidAlphaDigitCPLX:function(A){if(A==null||A=="null"||A==""){return false}var B=new RegExp("^[a-zA-Z0-9.,:@? ]+$");return B.test(A)},isValidAlphaDigitCPLX2:function(B){B=new String(B);var A=true;for(var C=0;C<this.invalidCharacters.length&&A;C++){A=(B.indexOf(this.invalidCharacters[C])<0)}return A},_isInvalidCharacter:function(C){var A=false;for(var B=0;B<this.invalidCharacters.length&&!A;B++){A=((this.invalidCharacters[B])==C)}return A},getUnvalidCaracAlphaDigitCPLX2:function(E){var D="";E=new String(E);var C=null;for(var B=0;B<E.length;B++){C=E.charAt(B);var A=this._isInvalidCharacter(C);if(A==true){if(D.indexOf(C)<0){D+=C+", "}}}return D},getSimplifyTags:function(F){if(F.length<2){return""}var A=new RegExp("[ ]+","g");var D=(new String(F)).toLowerCase();D=D.replace(A," ");while(D.charAt(D.length-1)==","||D.charAt(D.length-1)==" "){if(D.charAt(D.length-1)==","){D=D.substring(0,D.length-1)}if(D.charAt(D.length-1)==" "){D=D.substring(0,D.length-1)}}var E=null;var C=D.split(",");for(var B=0;B<C.length;B++){E=this.getStringWithoutStartEndSpace(C[B]);if(E.length<2){return""}else{C[B]=E}}return C.join(",")},getStringWithoutStartEndSpace:function(A){A=new String(A);while(A.charAt(0)==" "&&A.length>0){A=A.substring(1)}while(A.length>0&&A.charAt(A.length-1)==" "){A=A.substring(0,A.length-1)}return A}};var CW_Format=new CW_Format();function CW_FormValidator(){}CW_FormValidator.prototype={classValidatorNormal:"errorForm",classValidatorError:"errorFormActiv",check:function(D){if(ComWeb_navigator.isSafari()){return true}var A=D.getElementsByTagName("div");var F=new Array();var E=true;for(var C=0;C<A.length;C++){if(A.item(C).id=="validator"){F.push(A.item(C))}}var B=null;while(F.length>0){CW_logger.log(CW_logger.LEVEL_INFORMATION,"CW_FormValidator check "+D.name);B=new ComwebFormValidatorElement(F.shift());E=B.check(D)&&E}return E},setErrorMessage:function(F,H,E){if(ComWeb_navigator.isSafari()){alert(E);return }CW_logger.log(CW_logger.LEVEL_WARNING,"comwebFormValidator.setErrorMessage : "+F+" , "+H+" , "+E);var A=F.getElementsByTagName("div");var G=true;var C=null;for(var B=0;B<A.length;B++){if(A.item(B).id=="validator"){C=A.item(B);if(C.innerHTML.indexOf("field:"+H+";")>0){CW_logger.log(CW_logger.LEVEL_WARNING,"comwebFormValidator.setErrorMessage : fieldName 1:"+C.innerHTML);C.className=this.classValidatorError;var D=C.innerHTML;D=D.substring(D.indexOf("<!--"),D.indexOf("-->")+3);if(E==null||E==""){E="&nbsp;"}C.innerHTML=E+D;CW_logger.log(CW_logger.LEVEL_WARNING,"comwebFormValidator.setErrorMessage : fieldName 2:"+C.innerHTML)}}}}};var CW_FormValidator=new CW_FormValidator();function ComwebFormValidatorElement(A){this.divElement=null;this.requiered=null;this.fieldName=null;this.commentText=null;this.parameters=null;this.initialize(A)}ComwebFormValidatorElement.prototype={initialize:function(A){try{if(A.id=="validator"){this._parseDivElement(A);this.divElement=A}else{CW_logger.log(CW_logger.LEVEL_ERROR,"cant create ComwebFormValidatorElement the given div ("+A+") has not the correct id ('validator')")}return }catch(B){CW_logger.log(CW_logger.LEVEL_ERROR,"cant create ComwebFormValidatorElement, cant parse the given div ("+A+"):"+B)}},_parseDivElement:function(D){var A=D.innerHTML;var E=A.indexOf("<!--");var B=A.indexOf("-->");var K=A.substring(E+4,B);this.commentText=" <!--"+K+"-->";var G=new RegExp("field:[^\n]+;","g");var H=G.exec(K);if(H==null||H=="null"||H==""){var F=new Error();F.message="comment text have not the obligatory 'field' parameter";throw F;return }else{H=new String(H);H=H.substring(6,H.length-1);this.fieldName=H}G=new RegExp("requiered:[^\n]+;","g");H=G.exec(K);if(H==null||H=="null"||H==""){var F=new Error();F.message="comment text have not the obligatory 'required' parameter";throw F;return }else{if(H=="requiered:true;"){this.requiered=true}else{if(H=="requiered:false;"){this.requiered=false}else{var F=new Error();F.message="'required' parameter has no correct value, value must be 'true' or 'false'";throw F;return }}}this.parameters=new HashTable();var M=true;var J=1;while(M){G=new RegExp("field"+J+":[^\n]+;","g");H=G.exec(K);if(H==null||H=="null"||H==""){M=false}else{H=new String(H);H=H.substring(6+(new String(J)).length,H.length-1);this.parameters.put("field"+J,H);J=J+1}}G=new RegExp("format:[^\n]+;","g");H=G.exec(K);if(H!=null&&H!="null"&&H!=""){H=new String(H);H=H.substring(7,H.length-1);this.parameters.put("format",H);if(H=="confirm"){G=new RegExp("confirmField:[^\n]+;","g");H=G.exec(K);if(H==null||H=="null"||H==""){var F=new Error();F.message="comment text have 'confirm' parameter, but have not the obligatory 'confirmField' parameter";throw F;return }else{H=new String(H);H=H.substring(13,H.length-1);this.parameters.put("confirmField",H)}}else{if(H=="date"){G=new RegExp("dateDayName:[^\n]+;","g");var I=G.exec(K);G=new RegExp("dateMonthName:[^\n]+;","g");var L=G.exec(K);G=new RegExp("dateYearName:[^\n]+;","g");var C=G.exec(K);if(I==null||I=="null"||I==""||L==null||L=="null"||L==""||C==null||C=="null"||C==""){var F=new Error();F.message="comment text have 'date' parameter, but have not the obligatory 'dateDayName' 'dateMonthName' 'dateYearName' parameters";throw F;return }else{H=new String(I);H=H.substring(12,H.length-1);this.parameters.put("dateDayName",H);H=new String(L);H=H.substring(14,H.length-1);this.parameters.put("dateMonthName",H);H=new String(C);H=H.substring(13,H.length-1);this.parameters.put("dateYearName",H)}}}}G=new RegExp("errorRequiered:[^\n]+;","g");H=G.exec(K);if(H!=null&&H!="null"){H=new String(H);H=H.substring(15,H.length-1);this.parameters.put("errorRequiered",H)}G=new RegExp("errorFormat:[^\n]+;","g");H=G.exec(K);if(H!=null&&H!="null"){H=new String(H);H=H.substring(12,H.length-1);this.parameters.put("errorFormat",H)}G=new RegExp("minLenght:[^\n]+;","g");H=G.exec(K);if(H!=null&&H!="null"&&H!=""){H=new String(H);H=H.substring(10,H.length-1);this.parameters.put("minLenght",H)}G=new RegExp("maxLenght:[^\n]+;","g");H=G.exec(K);if(H!=null&&H!="null"&&H!=""){H=new String(H);H=H.substring(10,H.length-1);this.parameters.put("maxLenght",H)}G=new RegExp("originalContent:[^\n]*;","g");H=G.exec(K);if(H!=null&&H!="null"&&H!=""){if(H=="originalContent:;"){this.parameters.put("originalContent","")}else{H=new String(H);H=H.substring(16,H.length-1);this.parameters.put("originalContent",H)}}},_setErrorFormat:function(){var A=this.parameters.get("errorFormat");if(A==null){if(this.requiered){A=ComwebI18N_Manager.getErrorFormatRequired()}else{A=ComwebI18N_Manager.getErrorFormat()}}this._setError(A)},_setErrorRequiered:function(){var A=this.parameters.get("errorRequiered");if(A==null){A=ComwebI18N_Manager.getErrorRequired()}this._setError(A)},_setError:function(A){var B=this.parameters.get("errorFormat");if(B!=null){A=B}this.divElement.className=CW_FormValidator.classValidatorError;if(A==null||A==""){A="&nbsp;"}this.divElement.innerHTML=(A+this.commentText)},_setNoError:function(){var A=this.parameters.get("originalContent");if(A==null){if(this.requiered){A=ComwebI18N_Manager.getRequired()}else{A=""}}this.divElement.className=CW_FormValidator.classValidatorNormal;if(A==null||A==""){A="&nbsp;"}this.divElement.innerHTML=(A+this.commentText)},check:function(E){if(this.divElement==null){return false}var B=CW_util.getFormElement(E,this.fieldName);var J=new String(B.type).toLowerCase();CW_logger.log(CW_logger.LEVEL_INFORMATION,"ComwebFormValidatorElement CHECK:\n"+this.fieldName+"\nrequiered:"+this.requiered+"\nvalue:"+H+"\ntype:"+J+"\n parameters:"+this.parameters.toString());if(J=="radio"){}if(J=="checkbox"){if(this.requiered){if(!B.checked){this._setErrorRequiered();return false}}}else{var H=B.value;var M=this.parameters.get("format");if(this.requiered&&M!="date"){if(H==null||H==""||H=="null"||H==" "){this._setErrorRequiered();return false}var O=true;var N=1;var F="";while(O){F=this.parameters.get("field"+N);if(F==null){O=false}else{var D=CW_util.getFormElement(E,F).value;if(D==null||D==""||D=="null"||D==" "){this._setErrorRequiered();return false}N=N+1}}}var P="";if(M!=null){if(M=="date"){var K=CW_util.getFormElement(E,this.parameters.get("dateYearName")).value;var I=CW_util.getFormElement(E,this.parameters.get("dateMonthName")).value;var L=CW_util.getFormElement(E,this.parameters.get("dateDayName")).value;if(L==null||L=="null"||L==""||I==null||I=="null"||I==""||K==null||K=="null"||K==""){this._setErrorRequiered();return false}else{if(CW_util.isValidDate(K,I,L)){B.value=CW_util.buildSQLDateFormat(K,I,L)}else{var G="requiered= ";if(this.requiered){G="requiered="+ComwebI18N_Manager.getRequired()}this._setError(ComwebI18N_Manager.getErrorDateFormat(),G);return false}}}else{if(M=="confirm"){P=this.parameters.get("confirmField");if(H!=CW_util.getFormElement(E,P).value){var G="requiered= ";if(this.requiered){G="requiered="+ComwebI18N_Manager.getRequired()}this._setError(ComwebI18N_Manager.getErrorFormConfirmation(G));return false}}else{if(H!=""){if(!CW_Format.isValidFormat(M,H)){this._setErrorFormat();return false}else{if(M==CW_Format.FORMAT_2Tags){B.value=CW_Format.getSimplifyTags(H)}}}}}}else{}if(H!=""&&!CW_Format.isValidAlphaDigitCPLX2(H)){var G="requiered= ";if(this.requiered){G="requiered="+ComwebI18N_Manager.getRequired()}this._setError(ComwebI18N_Manager.getErrorFormCarac(CW_Format.getUnvalidCaracAlphaDigitCPLX2(H),G));return false}var C=this.parameters.get("minLenght");var A=this.parameters.get("maxLenght");if(C!=null&&A!=null){C=parseInt(C);A=parseInt(A);var G="requiered= ";if(this.requiered){G="requiered="+ComwebI18N_Manager.getRequired()}if(H.length<C||H.length>A){this._setError(ComwebI18N_Manager.getErrorFormStringLenghtMinMax(C,A,G));return false}}else{if(C!=null){C=parseInt(C);var G="requiered= ";if(this.requiered){G="requiered="+ComwebI18N_Manager.getRequired()}if(H.length<C){this._setError(ComwebI18N_Manager.getErrorFormStringLenghtMin(C,G));return false}}else{if(A!=null){A=parseInt(A);if(H.length>A){var G="requiered= ";if(this.requiered){G="requiered="+ComwebI18N_Manager.getRequired()}this._setError(ComwebI18N_Manager.getErrorFormStringLenghtMax(A,G));return false}}}}}this._setNoError();return true}};
