Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.53 KB | None | 0 0
  1. //fix for ie & chrome
  2. var Page_ValidationVer = "125";
  3. var Page_IsValid = true;
  4. var Page_BlockSubmit = false;
  5. function ValidatorUpdateDisplay(val) {
  6. if (typeof(val.display) == "string") {
  7. if (val.display == "None") {
  8. return;
  9. }
  10. if (val.display == "Dynamic") {
  11. val.style.display = val.isvalid ? "none" : "inline";
  12. return;
  13. }
  14. }
  15. val.style.visibility = val.isvalid ? "hidden" : "visible";
  16. }
  17. function ValidatorUpdateIsValid() {
  18. var i;
  19. for (i = 0; i < Page_Validators.length; i++) {
  20. if (!Page_Validators[i].isvalid) {
  21. Page_IsValid = false;
  22. return;
  23. }
  24. }
  25. Page_IsValid = true;
  26. }
  27. function ValidatorHookupControlID(controlID, val) {
  28. if (typeof(controlID) != "string") {
  29. return;
  30. }
  31. var ctrl = document.all[controlID];
  32. if (typeof(ctrl) != "undefined") {
  33. ValidatorHookupControl(ctrl, val);
  34. }
  35. else {
  36. val.isvalid = true;
  37. val.enabled = false;
  38. }
  39. }
  40. function ValidatorHookupControl(control, val) {
  41. if (typeof(control.tagName) == "undefined" && typeof(control.length) == "number") {
  42. var i;
  43. for (i = 0; i < control.length; i++) {
  44. var inner = control[i];
  45. if (typeof(inner.value) == "string") {
  46. ValidatorHookupControl(inner, val);
  47. }
  48. }
  49. return;
  50. }
  51. else if (control.tagName != "INPUT" && control.tagName != "TEXTAREA" && control.tagName != "SELECT") {
  52. var i;
  53. for (i = 0; i < control.children.length; i++) {
  54. ValidatorHookupControl(control.children[i], val);
  55. }
  56. return;
  57. }
  58. else {
  59. if (typeof(control.Validators) == "undefined") {
  60. control.Validators = new Array;
  61. var ev;
  62. if (control.type == "radio") {
  63. ev = control.onclick;
  64. } else {
  65. ev = control.onchange;
  66. }
  67. if (typeof(ev) == "function" ) {
  68. ev = ev.toString();
  69. ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
  70. }
  71. else {
  72. ev = "";
  73. }
  74. var func = new Function("ValidatorOnChange(); " + ev);
  75. if (control.type == "radio") {
  76. control.onclick = func;
  77. } else {
  78. control.onchange = func;
  79. }
  80. }
  81. control.Validators[control.Validators.length] = val;
  82. }
  83. }
  84. function ValidatorGetValue(id) {
  85. var control;
  86. control = document.all[id];
  87. if (typeof(control.value) == "string") {
  88. return control.value;
  89. }
  90. if (typeof(control.tagName) == "undefined" && typeof(control.length) == "number") {
  91. var j;
  92. for (j=0; j < control.length; j++) {
  93. var inner = control[j];
  94. if (typeof(inner.value) == "string" && (inner.type != "radio" || inner.status == true)) {
  95. return inner.value;
  96. }
  97. }
  98. }
  99. else {
  100. return ValidatorGetValueRecursive(control);
  101. }
  102. return "";
  103. }
  104. function ValidatorGetValueRecursive(control)
  105. {
  106. if (typeof(control.value) == "string" && (control.type != "radio" || control.status == true)) {
  107. return control.value;
  108. }
  109. var i, val;
  110. for (i = 0; i<control.children.length; i++) {
  111. val = ValidatorGetValueRecursive(control.children[i]);
  112. if (val != "") return val;
  113. }
  114. return "";
  115. }
  116. function Page_ClientValidate() {
  117. var i;
  118. for (i = 0; i < Page_Validators.length; i++) {
  119. ValidatorValidate(Page_Validators[i]);
  120. }
  121. ValidatorUpdateIsValid();
  122. ValidationSummaryOnSubmit();
  123. Page_BlockSubmit = !Page_IsValid;
  124. return Page_IsValid;
  125. }
  126. function ValidatorCommonOnSubmit() {
  127. var result = !Page_BlockSubmit;
  128. Page_BlockSubmit = false;
  129. event.returnValue = result;
  130. return result;
  131. }
  132. function ValidatorEnable(val, enable) {
  133. val.enabled = (enable != false);
  134. ValidatorValidate(val);
  135. ValidatorUpdateIsValid();
  136. }
  137. function ValidatorOnChange() {
  138. var vals = event.srcElement.Validators;
  139. var i;
  140. for (i = 0; i < vals.length; i++) {
  141. ValidatorValidate(vals[i]);
  142. }
  143. ValidatorUpdateIsValid();
  144. }
  145. function ValidatorValidate(val) {
  146. val.isvalid = true;
  147. if (val.enabled != false) {
  148. var evafun = val.evaluationfunction;
  149. if(evafun == undefined)
  150. evafun = val.getAttribute('evaluationfunction');
  151. if(typeof(evafun) == "string")
  152. evafun = window[evafun];
  153.  
  154. if (typeof(evafun ) == "function") {
  155. val.evaluationfunction = evafun;
  156. val.controltovalidate = val.getAttribute('controltovalidate');
  157. val.initialvalue = val.getAttribute('initialvalue');
  158. val.display = val.getAttribute("display");
  159. val.isvalid = evafun(val);
  160. }
  161. }
  162. ValidatorUpdateDisplay(val);
  163. }
  164.  
  165. function ValidatorOnLoad() {
  166. if (typeof(Page_Validators) == "undefined")
  167. return;
  168. var i, val;
  169. for (i = 0; i < Page_Validators.length; i++) {
  170. val = Page_Validators[i];
  171. if (typeof(val.getAttribute('evaluationfunction')) == "string") {
  172. eval("val.evaluationfunction = " + val.getAttribute('evaluationfunction') + ";");
  173. }
  174. if (typeof(val.isvalid) == "string") {
  175. if (val.isvalid == "False") {
  176. val.isvalid = false;
  177. Page_IsValid = false;
  178. }
  179. else {
  180. val.isvalid = true;
  181. }
  182. } else {
  183. val.isvalid = true;
  184. }
  185. if (typeof(val.enabled) == "string") {
  186. val.enabled = (val.enabled != "False");
  187. }
  188. ValidatorHookupControlID(val.getAttribute('controltovalidate'), val);
  189. ValidatorHookupControlID(val.getAttribute('controlhookup'), val);
  190. }
  191. Page_ValidationActive = true;
  192. }
  193. function ValidatorConvert(op, dataType, val) {
  194. function GetFullYear(year) {
  195. return (year + parseInt(val.century)) - ((year < val.cutoffyear) ? 0 : 100);
  196. }
  197. var num, cleanInput, m, exp;
  198. if (dataType == "Integer") {
  199. exp = /^\s*[-\+]?\d+\s*$/;
  200. if (op.match(exp) == null)
  201. return null;
  202. num = parseInt(op, 10);
  203. return (isNaN(num) ? null : num);
  204. }
  205. else if(dataType == "Double") {
  206. exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + val.decimalchar + "(\\d+))?\\s*$");
  207. m = op.match(exp);
  208. if (m == null)
  209. return null;
  210. cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
  211. num = parseFloat(cleanInput);
  212. return (isNaN(num) ? null : num);
  213. }
  214. else if (dataType == "Currency") {
  215. exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + val.groupchar + ")*)(\\d+)"
  216. + ((val.digits > 0) ? "(\\" + val.decimalchar + "(\\d{1," + val.digits + "}))?" : "")
  217. + "\\s*$");
  218. m = op.match(exp);
  219. if (m == null)
  220. return null;
  221. var intermed = m[2] + m[5] ;
  222. cleanInput = m[1] + intermed.replace(new RegExp("(\\" + val.groupchar + ")", "g"), "") + ((val.digits > 0) ? "." + m[7] : 0);
  223. num = parseFloat(cleanInput);
  224. return (isNaN(num) ? null : num);
  225. }
  226. else if (dataType == "Date") {
  227. var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-/]|\\. ?)(\\d{1,2})\\4(\\d{1,2})\\s*$");
  228. m = op.match(yearFirstExp);
  229. var day, month, year;
  230. if (m != null && (m[2].length == 4 || val.dateorder == "ymd")) {
  231. day = m[6];
  232. month = m[5];
  233. year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10))
  234. }
  235. else {
  236. if (val.dateorder == "ymd"){
  237. return null;
  238. }
  239. var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-/]|\\. ?)(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$");
  240. m = op.match(yearLastExp);
  241. if (m == null) {
  242. return null;
  243. }
  244. if (val.dateorder == "mdy") {
  245. day = m[3];
  246. month = m[1];
  247. }
  248. else {
  249. day = m[1];
  250. month = m[3];
  251. }
  252. year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10))
  253. }
  254. month -= 1;
  255. var date = new Date(year, month, day);
  256. return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
  257. }
  258. else {
  259. return op.toString();
  260. }
  261. }
  262. function ValidatorCompare(operand1, operand2, operator, val) {
  263. var dataType = val.type;
  264. var op1, op2;
  265. if ((op1 = ValidatorConvert(operand1, dataType, val)) == null)
  266. return false;
  267. if (operator == "DataTypeCheck")
  268. return true;
  269. if ((op2 = ValidatorConvert(operand2, dataType, val)) == null)
  270. return true;
  271. switch (operator) {
  272. case "NotEqual":
  273. return (op1 != op2);
  274. case "GreaterThan":
  275. return (op1 > op2);
  276. case "GreaterThanEqual":
  277. return (op1 >= op2);
  278. case "LessThan":
  279. return (op1 < op2);
  280. case "LessThanEqual":
  281. return (op1 <= op2);
  282. default:
  283. return (op1 == op2);
  284. }
  285. }
  286. function CompareValidatorEvaluateIsValid(val) {
  287. var value = ValidatorGetValue(val.controltovalidate);
  288. if (ValidatorTrim(value).length == 0)
  289. return true;
  290. var compareTo = "";
  291. if (null == document.all[val.controltocompare]) {
  292. if (typeof(val.valuetocompare) == "string") {
  293. compareTo = val.valuetocompare;
  294. }
  295. }
  296. else {
  297. compareTo = ValidatorGetValue(val.controltocompare);
  298. }
  299. return ValidatorCompare(value, compareTo, val.operator, val);
  300. }
  301. function CustomValidatorEvaluateIsValid(val) {
  302. var value = "";
  303. if (typeof(val.controltovalidate) == "string") {
  304. value = ValidatorGetValue(val.controltovalidate);
  305. if (ValidatorTrim(value).length == 0)
  306. return true;
  307. }
  308. var args = { Value:value, IsValid:true };
  309. if (typeof(val.getAttribute("clientvalidationfunction")) == "string") {
  310. eval(val.getAttribute("clientvalidationfunction") + "(val, args) ;");
  311. }
  312. return args.IsValid;
  313. }
  314. function RegularExpressionValidatorEvaluateIsValid(val) {
  315. var value = ValidatorGetValue(val.controltovalidate);
  316. if (ValidatorTrim(value).length == 0)
  317. return true;
  318. var rx = new RegExp(val.validationexpression);
  319. var matches = rx.exec(value);
  320. return (matches != null && value == matches[0]);
  321. }
  322. function ValidatorTrim(s) {
  323. var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
  324. return (m == null) ? "" : m[1];
  325. }
  326. function RequiredFieldValidatorEvaluateIsValid(val) {
  327. return (ValidatorTrim(ValidatorGetValue(val.controltovalidate)) != ValidatorTrim(val.initialvalue))
  328. }
  329. function RangeValidatorEvaluateIsValid(val) {
  330. var value = ValidatorGetValue(val.controltovalidate);
  331. if (ValidatorTrim(value).length == 0)
  332. return true;
  333. return (ValidatorCompare(value, val.minimumvalue, "GreaterThanEqual", val) &&
  334. ValidatorCompare(value, val.maximumvalue, "LessThanEqual", val));
  335. }
  336. function ValidationSummaryOnSubmit() {
  337. if (typeof(Page_ValidationSummaries) == "undefined")
  338. return;
  339. var summary, sums, s;
  340. for (sums = 0; sums < Page_ValidationSummaries.length; sums++) {
  341. summary = Page_ValidationSummaries[sums];
  342. summary.style.display = "none";
  343. if (!Page_IsValid) {
  344. if (summary.getAttribute("showsummary") != "False") {
  345. summary.style.display = "";
  346. if (typeof(summary.displaymode) != "string") {
  347. summary.displaymode = "BulletList";
  348. }
  349. switch (summary.displaymode) {
  350. case "List":
  351. headerSep = "<br>";
  352. first = "";
  353. pre = "";
  354. post = "<br>";
  355. final = "";
  356. break;
  357. case "BulletList":
  358. default:
  359. headerSep = "";
  360. first = "<ul>";
  361. pre = "<li>";
  362. post = "</li>";
  363. final = "</ul>";
  364. break;
  365. case "SingleParagraph":
  366. headerSep = " ";
  367. first = "";
  368. pre = "";
  369. post = " ";
  370. final = "<br>";
  371. break;
  372. }
  373. s = "";
  374. if (typeof(summary.headertext) == "string") {
  375. s += summary.headertext + headerSep;
  376. }
  377. s += first;
  378. for (i=0; i<Page_Validators.length; i++) {
  379. Page_Validators[i].errormessage = Page_Validators[i].getAttribute("errormessage");
  380. if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage ) == "string") {
  381. s += pre + Page_Validators[i].errormessage + post;
  382. }
  383. }
  384. s += final;
  385. summary.innerHTML = s;
  386. window.scrollTo(0,0);
  387. }
  388. summary.showmessagebox = summary.getAttribute("showmessagebox");
  389. if (summary.showmessagebox == "True") {
  390. s = "";
  391. summary.headertext = summary.getAttribute("headertext");
  392. if (typeof(summary.headertext) == "string") {
  393. s += summary.headertext + "<BR>";
  394. }
  395. for (i=0; i<Page_Validators.length; i++) {
  396. Page_Validators[i].errormessage = Page_Validators[i].getAttribute("errormessage");
  397. if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
  398. switch (summary.displaymode) {
  399. case "List":
  400. s += Page_Validators[i].errormessage + "<BR>";
  401. break;
  402. case "BulletList":
  403. default:
  404. s += " - " + Page_Validators[i].errormessage + "<BR>";
  405. break;
  406. case "SingleParagraph":
  407. s += Page_Validators[i].errormessage + " ";
  408. break;
  409. }
  410. }
  411. }
  412. span = document.createElement("SPAN");
  413. span.innerHTML = s;
  414. s = span.innerText;
  415. alert(s);
  416. }
  417. }
  418. }
  419. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement