﻿var xVal=xVal||{};xVal.Plugins=xVal.Plugins||{};xVal.Messages=xVal.Messages||{};xVal.AttachValidator=function(e,b,a,c){if(c!=null)this.Plugins[c].AttachValidator(e,b,a);else for(var f in this.Plugins){this.Plugins[f].AttachValidator(e,b,a);return}};
(function(e){xVal.Plugins["jquery.validate"]={AttachValidator:function(b,a,c){var f=this;f._ensureCustomFunctionsRegistered();e(function(){f._ensureValidationSummaryContainerExistsIfRequired(c);for(var g=0;g<a.Fields.length;g++){var d=a.Fields[g].FieldRules,i=f._makeAspNetMvcHtmlHelperID((b?b+".":"")+a.Fields[g].FieldName);if(i=document.getElementById(i))for(var j=0;j<d.length;j++){var h=d[j];if(h!=null)f._attachRuleToDOMElement(h.RuleName,h.RuleParameters,typeof h.Message=="undefined"?null:h.Message,
e(i),b,c)}}})},_makeAspNetMvcHtmlHelperID:function(b){return b.replace(/\./g,"_")},_attachRuleToDOMElement:function(b,a,c,f,g,d){var i=f.parents("form");i.length!=1&&alert("Error: Element "+f.attr("id")+" is not in a form");this._ensureFormIsMarkedForValidation(e(i[0]),d);this._associateNearbyValidationMessageSpanWithElement(f);d={};switch(b){case "Required":d.required=true;d.messages={required:c||xVal.Messages.Required};break;case "Range":if(a.Type=="string"){d.xVal_stringRange=[a.Min,a.Max];if(c!=
null)d.messages={xVal_stringRange:e.format(c)}}else if(a.Type=="datetime"){var j,h;if(typeof a.MinYear!="undefined")j=new Date(a.MinYear,a.MinMonth-1,a.MinDay,a.MinHour,a.MinMinute,a.MinSecond);if(typeof a.MaxYear!="undefined")h=new Date(a.MaxYear,a.MaxMonth-1,a.MaxDay,a.MaxHour,a.MaxMinute,a.MaxSecond);d.xVal_dateRange=[j,h];if(c!=null)d.messages={xVal_dateRange:e.format(c)}}else if(typeof a.Min=="undefined"){d.max=a.Max;c=c||xVal.Messages.Range_Numeric_Max;if(c!=null)d.messages={max:e.format(c)}}else if(typeof a.Max==
"undefined"){d.min=a.Min;c=c||xVal.Messages.Range_Numeric_Min;if(c!=null)d.messages={min:e.format(c)}}else{d.range=[a.Min,a.Max];c=c||xVal.Messages.Range_Numeric_MinMax;if(c!=null)d.messages={range:e.format(c)}}break;case "StringLength":if(typeof a.MinLength=="undefined"){d.maxlength=a.MaxLength;c=c||xVal.Messages.StringLength_Max;if(c!=null)d.messages={maxlength:e.format(c)}}else if(typeof a.MaxLength=="undefined"){d.minlength=a.MinLength;c=c||xVal.Messages.StringLength_Min;if(c!=null)d.messages=
{minlength:e.format(c)}}else{d.rangelength=[a.MinLength,a.MaxLength];c=c||xVal.Messages.StringLength_MinMax;if(c!=null)d.messages={rangelength:e.format(c)}}break;case "DataType":switch(a.Type){case "EmailAddress":d.email=true;d.messages={email:c||xVal.Messages.DataType_EmailAddress};break;case "Integer":d.xVal_regex=["^\\-?\\d+$",""];d.messages={xVal_regex:c||xVal.Messages.DataType_Integer||"Please enter a whole number."};break;case "Decimal":d.number=true;d.messages={number:c||xVal.Messages.DataType_Decimal};
break;case "Date":d.date=true;d.messages={date:c||xVal.Messages.DataType_Date};break;case "DateTime":d.xVal_regex=["^\\d{1,2}/\\d{1,2}/(\\d{2}|\\d{4})\\s+\\d{1,2}\\:\\d{2}(\\:\\d{2})?$",""];d.messages={xVal_regex:c||xVal.Messages.DataType_DateTime||"Please enter a valid date and time."};break;case "Currency":d.xVal_regex=["^\\D?\\s?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$",""];d.messages={xVal_regex:c||xVal.Messages.DataType_Currency||"Please enter a currency value."};break;case "CreditCardLuhn":d.xVal_creditCardLuhn=
true;if(c!=null)d.messages={xVal_creditCardLuhn:c};break}break;case "RegEx":d.xVal_regex=[a.Pattern,a.Options];if(c!=null)d.messages={xVal_regex:c};break;case "Comparison":b=this._makeAspNetMvcHtmlHelperID((g?g+".":"")+a.PropertyToCompare);b=document.getElementById(b);if(b!=null){d.xVal_comparison=[a.PropertyToCompare,b,a.ComparisonOperator];if(c!=null)d.messages={xVal_comparison:c}}break;case "Remote":var k={};i.find("input[name], textarea[name], select[name]").each(function(){var l=this;k[l.name]=
function(){return e(l).val()}});d.remote={url:a.url,data:k,type:"post"};break;case "Custom":b=this._parseAsFunctionWithWarnings(a.Function);if(b!=null){b=this._registerCustomValidationFunction(b);a=a.Parameters=="null"?null:eval("("+a.Parameters+")");d[b]=a||true;d.messages=[];d.messages[b]=c}break}f.rules("add",d)},_parseAsFunctionWithWarnings:function(b){var a;try{a=eval("("+b+")")}catch(c){alert("Custom rule error: Could not find or could not parse the function '"+b+"'");return null}if(typeof a!=
"function"){alert("Custom rule error: The JavaScript object '"+b+"' is not a function.");return null}return a},_associateNearbyValidationMessageSpanWithElement:function(b){var a=b.nextAll("span.field-validation-error");a.length>0&&e(a[0]).attr("generated","true").attr("htmlfor",b.attr("id"))},_ensureFormIsMarkedForValidation:function(b,a){if(!b.data("isMarkedForValidation")){b.data("isMarkedForValidation",true);var c={errorClass:"field-validation-error",errorElement:"span",highlight:function(f){e(f).addClass("input-validation-error")},
unhighlight:function(f){e(f).removeClass("input-validation-error")}};if(a.ValidationSummary){c.wrapper="li";c.errorLabelContainer="#"+a.ValidationSummary.ElementID+" ul:first"}b=b.validate(c);a.ValidationSummary&&this._modifyJQueryValidationElementHidingBehaviourToSupportValidationSummary(b,a)}},_registerCustomValidationFunction:function(b){jQuery.validator.xValCustomFunctionCount=(jQuery.validator.xValCustomFunctionCount||0)+1;var a="xVal_customFunction_"+jQuery.validator.xValCustomFunctionCount;
jQuery.validator.addMethod(a,function(c,f,g){if(this.optional(f))return true;return b(c,f,g)});return a},_ensureCustomFunctionsRegistered:function(){if(!jQuery.validator.xValFunctionsRegistered){jQuery.validator.xValFunctionsRegistered=true;jQuery.validator.addMethod("xVal_stringRange",function(b,a,c){if(this.optional(a))return true;if(c[0]!=null)if(b<c[0])return false;if(c[1]!=null)if(b>c[1])return false;return true},function(b){return b[0]!=null&&b[1]!=null?e.format(xVal.Messages.Range_String_MinMax||
"Please enter a value alphabetically between '{0}' and '{1}'.",b[0],b[1]):b[0]!=null?e.format(xVal.Messages.Range_String_Min||"Please enter a value not alphabetically before '{0}'.",b[0]):e.format(xVal.Messages.Range_String_Max||"Please enter a value not alphabetically after '{0}'.",b[1])});jQuery.validator.addMethod("xVal_dateRange",function(b,a,c){if(this.optional(a))return true;b=Date.parse(b);if(isNaN(b))return false;else b=new Date(b);if(c[0]!=null)if(b<c[0])return false;if(c[1]!=null)if(b>c[1])return false;
return true},function(b,a){if(isNaN(Date.parse(a.value)))return xVal.Messages.DataType_Date||"Please enter a valid date in yyyy/mm/dd format.";a=function(c){var f=c.getFullYear()+"-"+(c.getMonth()+1)+"-"+c.getDate();if(c.getHours()+c.getMinutes()+c.getSeconds()!=0)f+=" "+c.getHours()+":"+c.getMinutes()+":"+c.getSeconds();return f.replace(/\b(\d)\b/g,"0$1")};return b[0]!=null&&b[1]!=null?e.format(xVal.Messages.Range_DateTime_MinMax||"Please enter a date between {0} and {1}.",a(b[0]),a(b[1])):b[0]!=
null?e.format(xVal.Messages.Range_DateTime_Min||"Please enter a date no earlier than {0}.",a(b[0])):e.format(xVal.Messages.Range_DateTime_Max||"Please enter a date no later than {0}.",a(b[1]))});jQuery.validator.addMethod("xVal_regex",function(b,a,c){if(this.optional(a))return true;return(new RegExp(c[0],c[1])).test(b)},function(){return xVal.Messages.Regex||"This value is invalid."});jQuery.validator.addMethod("xVal_creditCardLuhn",function(b,a){if(this.optional(a))return true;b=b.replace(/\D/g,
"");if(b=="")return false;a=0;for(var c=b.length-2;c>=0;c-=2)a+=Array(0,2,4,6,8,1,3,5,7,9)[parseInt(b.charAt(c),10)];for(c=b.length-1;c>=0;c-=2)a+=parseInt(b.charAt(c),10);return a%10==0},function(){return xVal.Messages.DataType_CreditCardLuhn||"Please enter a valid credit card number."});jQuery.validator.addMethod("xVal_comparison",function(b,a,c){if(this.optional(a))return true;a=c[1];switch(c[2]){case "Equals":return b==a.value;case "DoesNotEqual":return b!=a.value}return true},function(b){var a=
b[0];switch(b[2]){case "Equals":return e.format(xVal.Messages.Comparison_Equals||"This value must be the same as {0}.",a);case "DoesNotEqual":return e.format(xVal.Messages.Comparison_DoesNotEqual||"This value must be different from {0}.",a)}});e.expr[":"].displayableValidationSummaryMessage=function(b){b=e(b).find("span:first");if(b.length==0)return true;return b.css("display")!=="none"&&!b.is(":empty")}}},_ensureValidationSummaryContainerExistsIfRequired:function(b){if(b.ValidationSummary){var a=
e("#"+b.ValidationSummary.ElementID);a.length==0&&alert('Cannot find validation summary element "'+b.ValidationSummary.ElementID+"\". Make sure you've put an element with this ID into your HTML document.");a.is(":has(ul)")||a.append(e("<span class='validation-summary-errors' />").text(b.ValidationSummary.HeaderMessage)).append(e("<ul />")).hide()}},_modifyJQueryValidationElementHidingBehaviourToSupportValidationSummary:function(b,a){var c=b.hideErrors,f=b.showErrors;b.hideErrors=function(){this.toHide=
this.toHide.not("ul");c.apply(this,arguments);e("#"+a.ValidationSummary.ElementID+":not(:has(li:displayableValidationSummaryMessage))").hide()};b.showErrors=function(){f.apply(this,arguments);e("#"+a.ValidationSummary.ElementID+":has(li:displayableValidationSummaryMessage)").show()}}}})(jQuery);
