Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Page_ValidationVer = "125";
  2. var Page_IsValid = true;
  3. var Page_BlockSubmit = false;
  4. var Page_InvalidControlToBeFocused = null;
  5. var Page_TextTypes = /^(text|password|file|search|tel|url|email|number|range|color|datetime|date|month|week|time|datetime-local)$/i;
  6. function ValidatorUpdateDisplay(val) {
  7.     if (typeof(val.display) == "string") {
  8.         if (val.display == "None") {
  9.             return;
  10.         }
  11.         if (val.display == "Dynamic") {
  12.             val.style.display = val.isvalid ? "none" : "inline";
  13.             return;
  14.         }
  15.     }
  16.     if ((navigator.userAgent.indexOf("Mac") > -1) &&
  17.         (navigator.userAgent.indexOf("MSIE") > -1)) {
  18.         val.style.display = "inline";
  19.     }
  20.     val.style.visibility = val.isvalid ? "hidden" : "visible";
  21. }
  22. function ValidatorUpdateIsValid() {
  23.     Page_IsValid = AllValidatorsValid(Page_Validators);
  24. }
  25. function AllValidatorsValid(validators) {
  26.     if ((typeof(validators) != "undefined") && (validators != null)) {
  27.         var i;
  28.         for (i = 0; i < validators.length; i++) {
  29.             if (!validators[i].isvalid) {
  30.                 return false;
  31.             }
  32.         }
  33.     }
  34.     return true;
  35. }
  36. function ValidatorHookupControlID(controlID, val) {
  37.     if (typeof(controlID) != "string") {
  38.         return;
  39.     }
  40.     var ctrl = document.getElementById(controlID);
  41.     if ((typeof(ctrl) != "undefined") && (ctrl != null)) {
  42.         ValidatorHookupControl(ctrl, val);
  43.     }
  44.     else {
  45.         val.isvalid = true;
  46.         val.enabled = false;
  47.     }
  48. }
  49. function ValidatorHookupControl(control, val) {
  50.     if (typeof(control.tagName) != "string") {
  51.         return;  
  52.     }
  53.     if (control.tagName != "INPUT" && control.tagName != "TEXTAREA" && control.tagName != "SELECT") {
  54.         var i;
  55.         for (i = 0; i < control.childNodes.length; i++) {
  56.             ValidatorHookupControl(control.childNodes[i], val);
  57.         }
  58.         return;
  59.     }
  60.     else {
  61.         if (typeof(control.Validators) == "undefined") {
  62.             control.Validators = new Array;
  63.             var eventType;
  64.             if (control.type == "radio") {
  65.                 eventType = "onclick";
  66.             } else {
  67.                 eventType = "onchange";
  68.                 if (typeof(val.focusOnError) == "string" && val.focusOnError == "t") {
  69.                     ValidatorHookupEvent(control, "onblur", "ValidatedControlOnBlur(event); ");
  70.                 }
  71.             }
  72.             ValidatorHookupEvent(control, eventType, "ValidatorOnChange(event); ");
  73.             if (Page_TextTypes.test(control.type)) {
  74.                 ValidatorHookupEvent(control, "onkeypress",
  75.                     "event = event || window.event; if (!ValidatedTextBoxOnKeyPress(event)) { event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation(); return false; } ");
  76.             }
  77.         }
  78.         control.Validators[control.Validators.length] = val;
  79.     }
  80. }
  81. function ValidatorHookupEvent(control, eventType, functionPrefix) {
  82.     var ev = control[eventType];
  83.     if (typeof(ev) == "function") {
  84.         ev = ev.toString();
  85.         ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
  86.     }
  87.     else {
  88.         ev = "";
  89.     }
  90.     control[eventType] = new Function("event", functionPrefix + " " + ev);
  91. }
  92. function ValidatorGetValue(id) {
  93.     var control;
  94.     control = document.getElementById(id);
  95.     if (typeof(control.value) == "string") {
  96.         return control.value;
  97.     }
  98.     return ValidatorGetValueRecursive(control);
  99. }
  100. function ValidatorGetValueRecursive(control)
  101. {
  102.     if (typeof(control.value) == "string" && (control.type != "radio" || control.checked == true)) {
  103.         return control.value;
  104.     }
  105.     var i, val;
  106.     for (i = 0; i<control.childNodes.length; i++) {
  107.         val = ValidatorGetValueRecursive(control.childNodes[i]);
  108.         if (val != "") return val;
  109.     }
  110.     return "";
  111. }
  112. function Page_ClientValidate(validationGroup) {
  113.     Page_InvalidControlToBeFocused = null;
  114.     if (typeof(Page_Validators) == "undefined") {
  115.         return true;
  116.     }
  117.     var i;
  118.     for (i = 0; i < Page_Validators.length; i++) {
  119.         ValidatorValidate(Page_Validators[i], validationGroup, null);
  120.     }
  121.     ValidatorUpdateIsValid();
  122.     ValidationSummaryOnSubmit(validationGroup);
  123.     Page_BlockSubmit = !Page_IsValid;
  124.     return Page_IsValid;
  125. }
  126. function ValidatorCommonOnSubmit() {
  127.     Page_InvalidControlToBeFocused = null;
  128.     var result = !Page_BlockSubmit;
  129.     if ((typeof(window.event) != "undefined") && (window.event != null)) {
  130.         window.event.returnValue = result;
  131.     }
  132.     Page_BlockSubmit = false;
  133.     return result;
  134. }
  135. function ValidatorEnable(val, enable) {
  136.     val.enabled = (enable != false);
  137.     ValidatorValidate(val);
  138.     ValidatorUpdateIsValid();
  139. }
  140. function ValidatorOnChange(event) {
  141.     event = event || window.event;
  142.     Page_InvalidControlToBeFocused = null;
  143.     var targetedControl;
  144.     if ((typeof(event.srcElement) != "undefined") && (event.srcElement != null)) {
  145.         targetedControl = event.srcElement;
  146.     }
  147.     else {
  148.         targetedControl = event.target;
  149.     }
  150.     var vals;
  151.     if (typeof(targetedControl.Validators) != "undefined") {
  152.         vals = targetedControl.Validators;
  153.     }
  154.     else {
  155.         if (targetedControl.tagName.toLowerCase() == "label") {
  156.             targetedControl = document.getElementById(targetedControl.htmlFor);
  157.             vals = targetedControl.Validators;
  158.         }
  159.     }
  160.     if (vals) {
  161.         for (var i = 0; i < vals.length; i++) {
  162.             ValidatorValidate(vals[i], null, event);
  163.         }
  164.     }
  165.     ValidatorUpdateIsValid();
  166. }
  167. function ValidatedTextBoxOnKeyPress(event) {
  168.     event = event || window.event;
  169.     if (event.keyCode == 13) {
  170.         ValidatorOnChange(event);
  171.         var vals;
  172.         if ((typeof(event.srcElement) != "undefined") && (event.srcElement != null)) {
  173.             vals = event.srcElement.Validators;
  174.         }
  175.         else {
  176.             vals = event.target.Validators;
  177.         }
  178.         return AllValidatorsValid(vals);
  179.     }
  180.     return true;
  181. }
  182. function ValidatedControlOnBlur(event) {
  183.     event = event || window.event;
  184.     var control;
  185.     if ((typeof(event.srcElement) != "undefined") && (event.srcElement != null)) {
  186.         control = event.srcElement;
  187.     }
  188.     else {
  189.         control = event.target;
  190.     }
  191.     if ((typeof(control) != "undefined") && (control != null) && (Page_InvalidControlToBeFocused == control)) {
  192.         control.focus();
  193.         Page_InvalidControlToBeFocused = null;
  194.     }
  195. }
  196. function ValidatorValidate(val, validationGroup, event) {
  197.     val.isvalid = true;
  198.     if ((typeof(val.enabled) == "undefined" || val.enabled != false) && IsValidationGroupMatch(val, validationGroup)) {
  199.         if (typeof(val.evaluationfunction) == "function") {
  200.             val.isvalid = val.evaluationfunction(val);
  201.             if (!val.isvalid && Page_InvalidControlToBeFocused == null &&
  202.                 typeof(val.focusOnError) == "string" && val.focusOnError == "t") {
  203.                 ValidatorSetFocus(val, event);
  204.             }
  205.         }
  206.     }
  207.     ValidatorUpdateDisplay(val);
  208. }
  209. function ValidatorSetFocus(val, event) {
  210.     var ctrl;
  211.     if (typeof(val.controlhookup) == "string") {
  212.         var eventCtrl;
  213.         if ((typeof(event) != "undefined") && (event != null)) {
  214.             if ((typeof(event.srcElement) != "undefined") && (event.srcElement != null)) {
  215.                 eventCtrl = event.srcElement;
  216.             }
  217.             else {
  218.                 eventCtrl = event.target;
  219.             }
  220.         }
  221.         if ((typeof(eventCtrl) != "undefined") && (eventCtrl != null) &&
  222.             (typeof(eventCtrl.id) == "string") &&
  223.             (eventCtrl.id == val.controlhookup)) {
  224.             ctrl = eventCtrl;
  225.         }
  226.     }
  227.     if ((typeof(ctrl) == "undefined") || (ctrl == null)) {
  228.         ctrl = document.getElementById(val.controltovalidate);
  229.     }
  230.     if ((typeof(ctrl) != "undefined") && (ctrl != null) &&
  231.         (ctrl.tagName.toLowerCase() != "table" || (typeof(event) == "undefined") || (event == null)) &&
  232.         ((ctrl.tagName.toLowerCase() != "input") || (ctrl.type.toLowerCase() != "hidden")) &&
  233.         (typeof(ctrl.disabled) == "undefined" || ctrl.disabled == null || ctrl.disabled == false) &&
  234.         (typeof(ctrl.visible) == "undefined" || ctrl.visible == null || ctrl.visible != false) &&
  235.         (IsInVisibleContainer(ctrl))) {
  236.         if ((ctrl.tagName.toLowerCase() == "table" && (typeof(__nonMSDOMBrowser) == "undefined" || __nonMSDOMBrowser)) ||
  237.             (ctrl.tagName.toLowerCase() == "span")) {
  238.             var inputElements = ctrl.getElementsByTagName("input");
  239.             var lastInputElement  = inputElements[inputElements.length -1];
  240.             if (lastInputElement != null) {
  241.                 ctrl = lastInputElement;
  242.             }
  243.         }
  244.         if (typeof(ctrl.focus) != "undefined" && ctrl.focus != null) {
  245.             ctrl.focus();
  246.             Page_InvalidControlToBeFocused = ctrl;
  247.         }
  248.     }
  249. }
  250. function IsInVisibleContainer(ctrl) {
  251.     if (typeof(ctrl.style) != "undefined" &&
  252.         ( ( typeof(ctrl.style.display) != "undefined" &&
  253.             ctrl.style.display == "none") ||
  254.           ( typeof(ctrl.style.visibility) != "undefined" &&
  255.             ctrl.style.visibility == "hidden") ) ) {
  256.         return false;
  257.     }
  258.     else if (typeof(ctrl.parentNode) != "undefined" &&
  259.              ctrl.parentNode != null &&
  260.              ctrl.parentNode != ctrl) {
  261.         return IsInVisibleContainer(ctrl.parentNode);
  262.     }
  263.     return true;
  264. }
  265. function IsValidationGroupMatch(control, validationGroup) {
  266.     if ((typeof(validationGroup) == "undefined") || (validationGroup == null)) {
  267.         return true;
  268.     }
  269.     var controlGroup = "";
  270.     if (typeof(control.validationGroup) == "string") {
  271.         controlGroup = control.validationGroup;
  272.     }
  273.     return (controlGroup == validationGroup);
  274. }
  275. function ValidatorOnLoad() {
  276.     if (typeof(Page_Validators) == "undefined")
  277.         return;
  278.     var i, val;
  279.     for (i = 0; i < Page_Validators.length; i++) {
  280.         val = Page_Validators[i];
  281.         if (typeof(val.evaluationfunction) == "string") {
  282.             eval("val.evaluationfunction = " + val.evaluationfunction + ";");
  283.         }
  284.         if (typeof(val.isvalid) == "string") {
  285.             if (val.isvalid == "False") {
  286.                 val.isvalid = false;
  287.                 Page_IsValid = false;
  288.             }
  289.             else {
  290.                 val.isvalid = true;
  291.             }
  292.         } else {
  293.             val.isvalid = true;
  294.         }
  295.         if (typeof(val.enabled) == "string") {
  296.             val.enabled = (val.enabled != "False");
  297.         }
  298.         if (typeof(val.controltovalidate) == "string") {
  299.             ValidatorHookupControlID(val.controltovalidate, val);
  300.         }
  301.         if (typeof(val.controlhookup) == "string") {
  302.             ValidatorHookupControlID(val.controlhookup, val);
  303.         }
  304.     }
  305.     Page_ValidationActive = true;
  306. }
  307. function ValidatorConvert(op, dataType, val) {
  308.     function GetFullYear(year) {
  309.         var twoDigitCutoffYear = val.cutoffyear % 100;
  310.         var cutoffYearCentury = val.cutoffyear - twoDigitCutoffYear;
  311.         return ((year > twoDigitCutoffYear) ? (cutoffYearCentury - 100 + year) : (cutoffYearCentury + year));
  312.     }
  313.     var num, cleanInput, m, exp;
  314.     if (dataType == "Integer") {
  315.         exp = /^\s*[-\+]?\d+\s*$/;
  316.         if (op.match(exp) == null)
  317.             return null;
  318.         num = parseInt(op, 10);
  319.         return (isNaN(num) ? null : num);
  320.     }
  321.     else if(dataType == "Double") {
  322.         exp = new RegExp("^\\s*([-\\+])?(\\d*)\\" + val.decimalchar + "?(\\d*)\\s*$");
  323.         m = op.match(exp);
  324.         if (m == null)
  325.             return null;
  326.         if (m[2].length == 0 && m[3].length == 0)
  327.             return null;
  328.         cleanInput = (m[1] != null ? m[1] : "") + (m[2].length>0 ? m[2] : "0") + (m[3].length>0 ? "." + m[3] : "");
  329.         num = parseFloat(cleanInput);
  330.         return (isNaN(num) ? null : num);
  331.     }
  332.     else if (dataType == "Currency") {
  333.         var hasDigits = (val.digits > 0);
  334.         var beginGroupSize, subsequentGroupSize;
  335.         var groupSizeNum = parseInt(val.groupsize, 10);
  336.         if (!isNaN(groupSizeNum) && groupSizeNum > 0) {
  337.             beginGroupSize = "{1," + groupSizeNum + "}";
  338.             subsequentGroupSize = "{" + groupSizeNum + "}";
  339.         }
  340.         else {
  341.             beginGroupSize = subsequentGroupSize = "+";
  342.         }
  343.         exp = new RegExp("^\\s*([-\\+])?((\\d" + beginGroupSize + "(\\" + val.groupchar + "\\d" + subsequentGroupSize + ")+)|\\d*)"
  344.                         + (hasDigits ? "\\" + val.decimalchar + "?(\\d{0," + val.digits + "})" : "")
  345.                         + "\\s*$");
  346.         m = op.match(exp);
  347.         if (m == null)
  348.             return null;
  349.         if (m[2].length == 0 && hasDigits && m[5].length == 0)
  350.             return null;
  351.         cleanInput = (m[1] != null ? m[1] : "") + m[2].replace(new RegExp("(\\" + val.groupchar + ")", "g"), "") + ((hasDigits && m[5].length > 0) ? "." + m[5] : "");
  352.         num = parseFloat(cleanInput);
  353.         return (isNaN(num) ? null : num);
  354.     }
  355.     else if (dataType == "Date") {
  356.         var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-/]|\\. ?)(\\d{1,2})\\4(\\d{1,2})\\.?\\s*$");
  357.         m = op.match(yearFirstExp);
  358.         var day, month, year;
  359.         if (m != null && (((typeof(m[2]) != "undefined") && (m[2].length == 4)) || val.dateorder == "ymd")) {
  360.             day = m[6];
  361.             month = m[5];
  362.             year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
  363.         }
  364.         else {
  365.             if (val.dateorder == "ymd"){
  366.                 return null;
  367.             }
  368.             var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-/]|\\. ?)(\\d{1,2})(?:\\s|\\2)((\\d{4})|(\\d{2}))(?:\\s\u0433\\.|\\.)?\\s*$");
  369.             m = op.match(yearLastExp);
  370.             if (m == null) {
  371.                 return null;
  372.             }
  373.             if (val.dateorder == "mdy") {
  374.                 day = m[3];
  375.                 month = m[1];
  376.             }
  377.             else {
  378.                 day = m[1];
  379.                 month = m[3];
  380.             }
  381.             year = ((typeof(m[5]) != "undefined") && (m[5].length == 4)) ? m[5] : GetFullYear(parseInt(m[6], 10));
  382.         }
  383.         month -= 1;
  384.         var date = new Date(year, month, day);
  385.         if (year < 100) {
  386.             date.setFullYear(year);
  387.         }
  388.         return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
  389.     }
  390.     else {
  391.         return op.toString();
  392.     }
  393. }
  394. function ValidatorCompare(operand1, operand2, operator, val) {
  395.     var dataType = val.type;
  396.     var op1, op2;
  397.     if ((op1 = ValidatorConvert(operand1, dataType, val)) == null)
  398.         return false;
  399.     if (operator == "DataTypeCheck")
  400.         return true;
  401.     if ((op2 = ValidatorConvert(operand2, dataType, val)) == null)
  402.         return true;
  403.     switch (operator) {
  404.         case "NotEqual":
  405.             return (op1 != op2);
  406.         case "GreaterThan":
  407.             return (op1 > op2);
  408.         case "GreaterThanEqual":
  409.             return (op1 >= op2);
  410.         case "LessThan":
  411.             return (op1 < op2);
  412.         case "LessThanEqual":
  413.             return (op1 <= op2);
  414.         default:
  415.             return (op1 == op2);
  416.     }
  417. }
  418. function CompareValidatorEvaluateIsValid(val) {
  419.     var value = ValidatorGetValue(val.controltovalidate);
  420.     if (ValidatorTrim(value).length == 0)
  421.         return true;
  422.     var compareTo = "";
  423.     if ((typeof(val.controltocompare) != "string") ||
  424.         (typeof(document.getElementById(val.controltocompare)) == "undefined") ||
  425.         (null == document.getElementById(val.controltocompare))) {
  426.         if (typeof(val.valuetocompare) == "string") {
  427.             compareTo = val.valuetocompare;
  428.         }
  429.     }
  430.     else {
  431.         compareTo = ValidatorGetValue(val.controltocompare);
  432.     }
  433.     var operator = "Equal";
  434.     if (typeof(val.operator) == "string") {
  435.         operator = val.operator;
  436.     }
  437.     return ValidatorCompare(value, compareTo, operator, val);
  438. }
  439. function CustomValidatorEvaluateIsValid(val) {
  440.     var value = "";
  441.     if (typeof(val.controltovalidate) == "string") {
  442.         value = ValidatorGetValue(val.controltovalidate);
  443.         if ((ValidatorTrim(value).length == 0) &&
  444.             ((typeof(val.validateemptytext) != "string") || (val.validateemptytext != "true"))) {
  445.             return true;
  446.         }
  447.     }
  448.     var args = { Value:value, IsValid:true };
  449.     if (typeof(val.clientvalidationfunction) == "string") {
  450.         eval(val.clientvalidationfunction + "(val, args) ;");
  451.     }
  452.     return args.IsValid;
  453. }
  454. function RegularExpressionValidatorEvaluateIsValid(val) {
  455.     var value = ValidatorGetValue(val.controltovalidate);
  456.     if (ValidatorTrim(value).length == 0)
  457.         return true;
  458.     var rx = new RegExp(val.validationexpression);
  459.     var matches = rx.exec(value);
  460.     return (matches != null && value == matches[0]);
  461. }
  462. function ValidatorTrim(s) {
  463.     var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
  464.     return (m == null) ? "" : m[1];
  465. }
  466. function RequiredFieldValidatorEvaluateIsValid(val) {
  467.     return (ValidatorTrim(ValidatorGetValue(val.controltovalidate)) != ValidatorTrim(val.initialvalue))
  468. }
  469. function RangeValidatorEvaluateIsValid(val) {
  470.     var value = ValidatorGetValue(val.controltovalidate);
  471.     if (ValidatorTrim(value).length == 0)
  472.         return true;
  473.     return (ValidatorCompare(value, val.minimumvalue, "GreaterThanEqual", val) &&
  474.             ValidatorCompare(value, val.maximumvalue, "LessThanEqual", val));
  475. }
  476. function ValidationSummaryOnSubmit(validationGroup) {
  477.     if (typeof(Page_ValidationSummaries) == "undefined")
  478.         return;
  479.     var summary, sums, s;
  480.     var headerSep, first, pre, post, end;
  481.     for (sums = 0; sums < Page_ValidationSummaries.length; sums++) {
  482.         summary = Page_ValidationSummaries[sums];
  483.         if (!summary) continue;
  484.         summary.style.display = "none";
  485.         if (!Page_IsValid && IsValidationGroupMatch(summary, validationGroup)) {
  486.             var i;
  487.             if (summary.showsummary != "False") {
  488.                 summary.style.display = "";
  489.                 if (typeof(summary.displaymode) != "string") {
  490.                     summary.displaymode = "BulletList";
  491.                 }
  492.                 switch (summary.displaymode) {
  493.                     case "List":
  494.                         headerSep = "<br>";
  495.                         first = "";
  496.                         pre = "";
  497.                         post = "<br>";
  498.                         end = "";
  499.                         break;
  500.                     case "BulletList":
  501.                     default:
  502.                         headerSep = "";
  503.                         first = "<ul>";
  504.                         pre = "<li>";
  505.                         post = "</li>";
  506.                         end = "</ul>";
  507.                         break;
  508.                     case "SingleParagraph":
  509.                         headerSep = " ";
  510.                         first = "";
  511.                         pre = "";
  512.                         post = " ";
  513.                         end = "<br>";
  514.                         break;
  515.                 }
  516.                 s = "";
  517.                 if (typeof(summary.headertext) == "string") {
  518.                     s += summary.headertext + headerSep;
  519.                 }
  520.                 s += first;
  521.                 for (i=0; i<Page_Validators.length; i++) {
  522.                     if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
  523.                         s += pre + Page_Validators[i].errormessage + post;
  524.                     }
  525.                 }
  526.                 s += end;
  527.                 summary.innerHTML = s;
  528.                 window.scrollTo(0,0);
  529.             }
  530.             if (summary.showmessagebox == "True") {
  531.                 s = "";
  532.                 if (typeof(summary.headertext) == "string") {
  533.                     s += summary.headertext + "\r\n";
  534.                 }
  535.                 var lastValIndex = Page_Validators.length - 1;
  536.                 for (i=0; i<=lastValIndex; i++) {
  537.                     if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
  538.                         switch (summary.displaymode) {
  539.                             case "List":
  540.                                 s += Page_Validators[i].errormessage;
  541.                                 if (i < lastValIndex) {
  542.                                     s += "\r\n";
  543.                                 }
  544.                                 break;
  545.                             case "BulletList":
  546.                             default:
  547.                                 s += "- " + Page_Validators[i].errormessage;
  548.                                 if (i < lastValIndex) {
  549.                                     s += "\r\n";
  550.                                 }
  551.                                 break;
  552.                             case "SingleParagraph":
  553.                                 s += Page_Validators[i].errormessage + " ";
  554.                                 break;
  555.                         }
  556.                     }
  557.                 }
  558.                 alert(s);
  559.             }
  560.         }
  561.     }
  562. }
  563. if (window.jQuery) {
  564.     (function ($) {
  565.         var dataValidationAttribute = "data-val",
  566.             dataValidationSummaryAttribute = "data-valsummary",
  567.             normalizedAttributes = { validationgroup: "validationGroup", focusonerror: "focusOnError" };
  568.         function getAttributesWithPrefix(element, prefix) {
  569.             var i,
  570.                 attribute,
  571.                 list = {},
  572.                 attributes = element.attributes,
  573.                 length = attributes.length,
  574.                 prefixLength = prefix.length;
  575.             prefix = prefix.toLowerCase();
  576.             for (i = 0; i < length; i++) {
  577.                 attribute = attributes[i];
  578.                 if (attribute.specified && attribute.name.substr(0, prefixLength).toLowerCase() === prefix) {
  579.                     list[attribute.name.substr(prefixLength)] = attribute.value;
  580.                 }
  581.             }
  582.             return list;
  583.         }
  584.         function normalizeKey(key) {
  585.             key = key.toLowerCase();
  586.             return normalizedAttributes[key] === undefined ? key : normalizedAttributes[key];
  587.         }
  588.         function addValidationExpando(element) {
  589.             var attributes = getAttributesWithPrefix(element, dataValidationAttribute + "-");
  590.             $.each(attributes, function (key, value) {
  591.                 element[normalizeKey(key)] = value;
  592.             });
  593.         }
  594.         function dispose(element) {
  595.             var index = $.inArray(element, Page_Validators);
  596.             if (index >= 0) {
  597.                 Page_Validators.splice(index, 1);
  598.             }
  599.         }
  600.         function addNormalizedAttribute(name, normalizedName) {
  601.             normalizedAttributes[name.toLowerCase()] = normalizedName;
  602.         }
  603.         function parseSpecificAttribute(selector, attribute, validatorsArray) {
  604.             return $(selector).find("[" + attribute + "='true']").each(function (index, element) {
  605.                 addValidationExpando(element);
  606.                 element.dispose = function () { dispose(element); element.dispose = null; };
  607.                 if ($.inArray(element, validatorsArray) === -1) {
  608.                     validatorsArray.push(element);
  609.                 }
  610.             }).length;
  611.         }
  612.         function parse(selector) {
  613.             var length = parseSpecificAttribute(selector, dataValidationAttribute, Page_Validators);
  614.             length += parseSpecificAttribute(selector, dataValidationSummaryAttribute, Page_ValidationSummaries);
  615.             return length;
  616.         }
  617.         function loadValidators() {
  618.             if (typeof (ValidatorOnLoad) === "function") {
  619.                 ValidatorOnLoad();
  620.             }
  621.             if (typeof (ValidatorOnSubmit) === "undefined") {
  622.                 window.ValidatorOnSubmit = function () {
  623.                     return Page_ValidationActive ? ValidatorCommonOnSubmit() : true;
  624.                 };
  625.             }
  626.         }
  627.         function registerUpdatePanel() {
  628.             if (window.Sys && Sys.WebForms && Sys.WebForms.PageRequestManager) {
  629.                 var prm = Sys.WebForms.PageRequestManager.getInstance(),
  630.                     postBackElement, endRequestHandler;
  631.                 if (prm.get_isInAsyncPostBack()) {
  632.                     endRequestHandler = function (sender, args) {
  633.                         if (parse(document)) {
  634.                             loadValidators();
  635.                         }
  636.                         prm.remove_endRequest(endRequestHandler);
  637.                         endRequestHandler = null;
  638.                     };
  639.                     prm.add_endRequest(endRequestHandler);
  640.                 }
  641.                 prm.add_beginRequest(function (sender, args) {
  642.                     postBackElement = args.get_postBackElement();
  643.                 });
  644.                 prm.add_pageLoaded(function (sender, args) {
  645.                     var i, panels, valFound = 0;
  646.                     if (typeof (postBackElement) === "undefined") {
  647.                         return;
  648.                     }
  649.                     panels = args.get_panelsUpdated();
  650.                     for (i = 0; i < panels.length; i++) {
  651.                         valFound += parse(panels[i]);
  652.                     }
  653.                     panels = args.get_panelsCreated();
  654.                     for (i = 0; i < panels.length; i++) {
  655.                         valFound += parse(panels[i]);
  656.                     }
  657.                     if (valFound) {
  658.                         loadValidators();
  659.                     }
  660.                 });
  661.             }
  662.         }
  663.         $(function () {
  664.             if (typeof (Page_Validators) === "undefined") {
  665.                 window.Page_Validators = [];
  666.             }
  667.             if (typeof (Page_ValidationSummaries) === "undefined") {
  668.                 window.Page_ValidationSummaries = [];
  669.             }
  670.             if (typeof (Page_ValidationActive) === "undefined") {
  671.                 window.Page_ValidationActive = false;
  672.             }
  673.             $.WebFormValidator = {
  674.                 addNormalizedAttribute: addNormalizedAttribute,
  675.                 parse: parse
  676.             };
  677.             if (parse(document)) {
  678.                 loadValidators();
  679.             }
  680.             registerUpdatePanel();
  681.         });
  682.     } (jQuery));
  683. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement