1 2 3 4 5 6 7 8 9function decodeEmailImpl(encodeEmail) 10{ 11 var email = encodeEmail; 12 if (email.indexOf("~") > -1) 13 email = email.replace(/~/gi, '@'); 14 if(email.indexOf("!") > -1) 15 email = email.replace(/!/gi, '.'); 16 17 18 var newEmail = new Array(email.length); 19 for (i = 0; i < email.length; i++) 20 { 21 newEmail[i] = email.charAt(email.length - i - 1); 22 } 23 email = newEmail.join(""); 24 return email; 25} 26function decodeEmail(encodeEmail) 27{ 28 window.location.href="mailto:"+decodeEmailImpl(encodeEmail); 29} 30function writeEmailToPage(encodeEmail) 31{ 32 document.write(decodeEmailImpl(encodeEmail)); 33} 34function openTargetBlank(link, event) 35{ 36 var href = link.href; 37 38 if (href.indexOf("javascript:")==0) return true; 39 40 window.open(href,'_blank'); 41 event.returnValue = false; 42 event.stopPropagation(); 43 return false; 44} 45 46 47$(document).ready(function() 48{ 49 try 50 { 51 if ($("a[rel='wjimageviewer']").length > 0) 52 { 53 var head = document.getElementsByTagName('HEAD')[0]; 54 55 if ($("#photoswipe1").length <= 0) { 56 var link = document.createElement("script"); 57 link.src = "/components/gallery/photoswipe/js/photoswipe.js"; 58 link.id = "photoswipe1"; 59 head.appendChild(link); 60 } 61 if ($("#photoswipe2").length <= 0) { 62 var link = document.createElement("script"); 63 link.src = "/components/gallery/photoswipe/js/photoswipe-ui-default.js"; 64 link.id = "photoswipe2"; 65 head.appendChild(link); 66 } 67 if ($("#photoswipe3").length <= 0) { 68 var link = document.createElement("script"); 69 link.src = "/components/gallery/photoswipe/photoswipe.jsp"; 70 link.id = "photoswipe3"; 71 head.appendChild(link); 72 } 73 } 74 75 } catch (e) {} 76}); 77 78 79 $(document).ready(function() 80 { 81 try { 82 if ("Odkaz sa otvorà v novom okne"!="") 83 { 84 //console.log("Doplnam target blank"); 85 $('a[onclick*="return openTargetBlank"]').each(function() 86 { 87 var href = $(this).attr("href"); 88 89 //console.log(href); 90 91 if (href != null) 92 { 93 var actualTitle = $(this).attr("title"); 94 if (actualTitle!=null && actualTitle!="") $(this).attr("title", actualTitle+" (Odkaz sa otvorà v novom okne)"); 95 else $(this).attr("title", "Odkaz sa otvorà v novom okne"); 96 } 97 }); 98 } 99 } 100 catch (e) {} 101 }); 102 103var checkFormLoaded = true; 104 105 106 107 108 109//event_attacher.js 110 function addEventCheckForm(obj, evType, fn) 111 { 112 if (navigator.userAgent.indexOf("Opera")!=-1) 113 { 114 //opera je tupa, cez addEventListener to nefunguje 115 eval("obj.on"+evType+"=fn"); 116 return; 117 } 118 119 if (obj.addEventListener) 120 { 121 obj.addEventListener(evType, fn, true); 122 return true; 123 } 124 else if (obj.attachEvent) 125 { 126 var r = obj.attachEvent("on"+evType, fn); 127 return r; 128 } 129 else 130 { 131 return false; 132 } 133 } 134 135//fix for Internet Explorer event model 136 function fixECheckForm(e) { 137 if (!e && window.event) e = window.event; 138 if (!e.target) e.target = e.srcElement; 139 return e; 140 } 141 142//class magic 143 var classMagic = {}; 144 145//prida objektu novy class 146 classMagic.add = function (elm, newCl) { 147 if (elm && newCl) { 148 elm = this.fixElm(elm); 149 for (var i = 0; i < elm.length; i++) { 150 // ak uz dany objekt ma dany class, nepridame ho 151 if (!classMagic.has(elm[i], newCl)) 152 { 153 elm[i].className += (this.get(elm[i])) ? " " + newCl : newCl; 154 } 155 try 156 { 157 if (("required"==newCl || "invalid"==newCl) && (elm[i].type=="radio" || elm[i].type=="checkbox")) 158 { 159 var newcl2 = newCl+elm[i].type; 160 if (!classMagic.has(elm[i], newcl2)) 161 { 162 elm[i].className += (this.get(elm[i])) ? " " + newcl2 : newcl2; 163 } 164 } 165 } 166 catch (e) { } 167 } 168 return true; 169 } 170 return false; 171 }; 172 173//zisti, ci dany objekt ma priradeny dany class 174 classMagic.has = function (elm, cl) { 175 if (elm && cl) { 176 if (actCl = this.get(elm)) { 177 for (var i = 0; i < actCl.length; i++) { 178 if (actCl[i] == cl) { 179 return true; 180 } 181 } 182 } 183 } 184 return false; 185 } 186 187//nahradi class(-y) objektu novym classom 188 classMagic.set = function (elm, newCl) { 189 if (elm && newCl) { 190 elm = this.fixElm(elm); 191 for (var i = 0; i < elm.length; i++) { 192 elm[i].className = newCl; 193 } 194 return true; 195 } 196 return false; 197 }; 198 199//nahradi stary class objektu novym classom 200 classMagic.replace = function (elm, newCl, oldCl) { 201 if (elm && newCl && oldCl) { 202 elm = this.fixElm(elm); 203 for (var i = 0; i < elm.length; i++) { 204 var cl; 205 var replCl = ""; 206 if (cl = this.get(elm[i])) { 207 for (var j = 0; j < cl.length; j++) { 208 replCl += (j > 0) ? " " : ""; 209 replCl += (cl[j] == oldCl) ? newCl : cl[j]; 210 } 211 elm[i].className = replCl; 212 } 213 } 214 return true; 215 } 216 return false; 217 }; 218 219//odstrani stary class 220 classMagic.remove = function (elm, oldCl) { 221 if (elm && oldCl) { 222 elm = this.fixElm(elm); 223 for (var i = 0; i < elm.length; i++) { 224 var cl; 225 var replCl = ""; 226 if (cl = this.get(elm[i])) { 227 for (var j = 0; j < cl.length; j++) { 228 replCl += (j > 0) ? " " : ""; 229 replCl += (cl[j] == oldCl) ? "" : cl[j]; 230 } 231 elm[i].className = replCl; 232 } 233 234 try 235 { 236 if (("required"==oldCl || "invalid"==oldCl) && (elm[i].type=="radio" || elm[i].type=="checkbox")) 237 { 238 var oldcl2 = oldCl+elm[i].type; 239 this.remove(elm[i], oldcl2); 240 } 241 } 242 catch (e) { } 243 } 244 return true; 245 } 246 return false; 247 }; 248 249//vrati pole vsetkych classov, ktore objekt ma 250//(toto je pomocna funkcia, ktoru vyuzivaju dalsie funkcie, ale moze sa pouzit aj samostatne) 251 classMagic.get = function (elm) { 252 if (elm) { 253 return (elm.className == "") ? false : elm.className.split(" "); 254 } 255 return false; 256 }; 257 258//pomocna funkcia, ktore prevedie samostatny element na pole 259 classMagic.fixElm = function (elm) { 260 if (elm) { 261 if (!elm.sort) { 262 elm = [elm]; 263 } 264 return elm; 265 } 266 return false; 267 } 268 269 270 271 function checkNaN(value) 272 { 273 if (isNaN(value)) 274 { 275 return(0); 276 } 277 278 value = (""+value.toFixed(2)).replace(".", ","); 279 return(value); 280 } 281 282//Excel funkcie 283 function rounddown(n, nd) 284 { 285 if(isFinite(n) && isFinite(nd)) 286 { 287 var sign_n = (n<0)?-1:1; 288 var abs_n=Math.abs(n); 289 var factor=Math.pow(10,nd); 290 return sign_n*Math.floor(abs_n*factor)/factor; 291 } 292 else 293 { 294 return NaN; 295 } 296 } 297 298 function round2(fltValue) 299 { 300 return Math.round(fltValue * 100) / 100; 301 } 302 303 function getFloat(value) 304 { 305 value = value.replace(/,/gi, "."); 306 return(parseFloat(value)); 307 } 308 309 function onlyPositive(value) 310 { 311 if (value < 0) return 0; 312 return value; 313 } 314 315 function smallerNumber(value1, value2) 316 { 317 if (value1 < value2) return value1; 318 return value2; 319 } 320 321 function biggerNumber(value1, value2) 322 { 323 if (value1 > value2) return value1; 324 return value2; 325 } 326 327 function ifCondition(condition, value1, value2) 328 { 329 if (condition) return value1; 330 return value2; 331 } 332 333 var REQCOND1 = "no"; 334 var REQCOND2 = "no"; 335 var REQCOND3 = "no"; 336 var REQCOND4 = "no"; 337 var REQCOND5 = "no"; 338 var REQCOND6 = "no"; 339 340 /* 341 checkForm by Riki "Fczbkk" Fridrich, 2002 342 ver 2.0 343 http://www.fczbkk.com/ 344 mailto:[email protected] 345 You should find latest version of this script and documentation at 346 http://www.fczbkk.sk/com/check_form/ 347 */ 348 349 350 351 /* 352 This is second version of my script for automatic checking of forms. It should
353 work in in all standards-compliant browsers (Mozilla, Internet Explorer 5+), it 354 downgrades OK in older browsers. No, it's not working in Opera (I said it works 355 in standards-compliant browsers only). 356 357 It requires additional functions and libraries: 358 - event_attacher.js 359 http://www.fczbkk.com/js/event_attacher/ 360 - fix_e.js 361 http://www.fczbkk.com/js/fix_e/ 362 - class_magic.js 363 http://www.fczbkk.com/js/class_magic/ 364 365 ATTENTION!!! Additional libraries and functions must be placed/linked before 366 checkForm. 367 368 All used scripts and libraries are writen by me, except "Event Attacher", which 369 was writen by Scott Andrew (http://www.scottandrew.com/). Feel free to use 370 and/or modify them (as far as I know, "Event Attacher" is free to use too), just 371 please let me know where you used it if possible (I want to see it in action). 372 Any suggestions, comments, bugreports, modifications or functionality 373 enhancements are wellcome. 374 */ 375 376 /* 377 Formatting of the fields (e.g. highlighting of "required" or "invalid" fields) 378 is defined in external CSS file "check_field.css". These definitions can be 379 modified to fit your layout and they can be moved anywhere into your CSS 380 definitions. 381 */ 382 383// object holding all other functions and variables 384 var checkForm = {}; 385 386 /* 387 Regular expression builder, used for simplier adding or editing of character 388 groups. 389 */ 390 391 checkForm.buildRegExp = function(str) { 392 if (str) {return new RegExp("^[" + str + "]{1,}$");} 393 return false; 394 } 395 396 /* -------------- customizations start here -------------- */ 397 398 /* 399 Message, which will be displayed in the alert, when user tries to submit 400 incomplete or invalid form. 401 */ 402 403 checkForm.invalidMsg = "PrepáÄte, ale formulár nie je vyplnený správne.\nNiektoré polia obsahujú nesprávne údaje, alebo sú nevyplnené. ProsÃm opravte vÅ¡etky zvýraznené polia."; 404 checkForm.allreadySendingMsg = "Formulár sa už odosiela, Äakajte prosÃm"; 405 406//toto sa pouziva v custom onSubmit funkciach, ak vracaju false, musia toto nastavit na false 407 checkForm.isInvalidForm = false; 408 409//ak chceme zobrazit klasicku error hlasku hore a nie vedla inputov daj true 410 checkForm.showClassicErrorMessage = false; 411 412 /* 413 Acceptable characters or regular expressions defining valid content of checked 414 classes. 415 */ 416 417 checkForm.fieldType = new Array(); 418 checkForm.title = new Array(); 419 420 checkForm.trimRegexp = new RegExp("^[ \f\n\r\t\v]+|[ \f\n\r\t\v]+$", "i"); 421 422 423 checkForm.fieldType["phone"] = new RegExp("^([+]?[s0-9]+)?(d{3}|[(]?[0-9]+[)])?([-]?[s]?[0-9])+$", "i"); 424 checkForm.title["phone"] = "telefónne ÄÃslo vo formáte (+)1234567890"; 425 426 checkForm.fieldType["alphabet"] = new RegExp("^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZľÄÅ¡ÄťŞýáÃéúůÅťóÄäôöüĽÄÅ ÄŤÅŽÃÃÃÃÃÅ®ÅŤÃÄÃÃÃà ]{1,}$", "i"); 427 checkForm.title["alphabet"] = "povolené pÃsmená"; 428 429 checkForm.fieldType["alphabetLowercase"] = new RegExp("^[abcdefghijklmnopqrstuvwxyzľÄÅ¡ÄťŞýáÃéúůÅťóÄäô ]{1,}$", "i"); 430 checkForm.title["alphabetLowercase"] = "povolené len malé znaky"; 431 432 checkForm.fieldType["alphabetUppercase"] = new RegExp("^[ABCDEFGHIJKLMNOPQRSTUVWXYZĽÄÅ ÄŤÅŽÃÃÃÃÃÅ®ÅŤÃÄÃà ]{1,}$", "i"); 433 checkForm.title["alphabetUppercase"] = "povolené len veľké znaky"; 434 435 checkForm.fieldType["alphanumeric"] = new RegExp("^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ľÄÅ¡ÄťŞýáÃéúůÅťóÄäôĽÄÅ ÄŤÅŽÃÃÃÃÃÅ®ÅŤÃÄÃà ]{1,}$", "i"); 436 checkForm.title["alphanumeric"] = "povolené ÄÃslice a pÃsmená"; 437 438 checkForm.fieldType["date"] = new RegExp("^(([0]?[123456789])|([12][0-9])|(3[01]))[.]((0?[123456789])|(1[012]))[.][0-9]{4}$", "i"); 439 checkForm.title["date"] = "dátum vo formáte dd.mm.rrrr"; 440 441 checkForm.fieldType["datetime"] = new RegExp("^[0-9]{1,2}[.][0-9]{1,2}[.][0-9]{4}.[0-9]{1,2}[:][0-9]{1,2}[:][0-9]{1,2}$", "i"); 442 checkForm.title["datetime"] = "dátum a Äas vo formáte dd.mm.rrrr hh:mm:ss"; 443 444 checkForm.fieldType["email"] = new RegExp("^[a-zA-Z0-9]+[a-zA-Z0-9\._+=#$%&-]*[a-zA-Z0-9]+@[a-zA-Z0-9]+[a-zA-Z0-9\._-]*[a-zA-Z0-9]+\.[a-zA-Z]{2,16}$", "i"); 445 checkForm.title["email"] = "e-mail adresa vo formáte [email protected]"; 446 447 checkForm.fieldType["email2"] = new RegExp("^[a-z0-9]+[a-z0-9\._-]*[a-z0-9]+@[a-z0-9]+[a-z0-9\._-]*[a-z0-9]+\.[a-z]{2,4}$", "i"); 448 checkForm.title["email2"] = "checkform.title.email2"; 449 450 checkForm.fieldType["fixedPhone"] = new RegExp("(^[0-9]{2,3}[\/][0-9]{3,12}$)|(^[+][0-9]{1,3}
450[\/][0-9]{1,2}[\/][0-9]{3,12}$)", "i"); 451 checkForm.title["fixedPhone"] = "telefónne ÄÃslo pevnej linky vo formáte xxx(x)/yyy(yyyyyyyyy)"; 452 453 checkForm.fieldType["integer"] = new RegExp("^[-]?[0-9]+$", "i"); 454 checkForm.title["integer"] = "Celé ÄÃslo"; 455 456 checkForm.fieldType["loginChars"] = new RegExp("^[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.]{1,}$", "i"); 457 checkForm.title["loginChars"] = "povolené ÄÃslice a pÃsmená (bez diakritiky)"; 458 459 checkForm.fieldType["minLen16"] = new RegExp(".................*", "i"); 460 checkForm.title["minLen16"] = "minimálne 16 znakov"; 461 462 checkForm.fieldType["minLen2"] = new RegExp("...*", "i"); 463 checkForm.title["minLen2"] = "minimálne 2 znaky"; 464 465 checkForm.fieldType["minLen3"] = new RegExp("....*", "i"); 466 checkForm.title["minLen3"] = "minimálne 3 znaky"; 467 468 checkForm.fieldType["minLen4"] = new RegExp(".....*", "i"); 469 checkForm.title["minLen4"] = "minimálne 4 znaky"; 470 471 checkForm.fieldType["minLen5"] = new RegExp("......*", "i"); 472 checkForm.title["minLen5"] = "minimálne 5 znakov"; 473 474 checkForm.fieldType["minLen6"] = new RegExp(".......*", "i"); 475 checkForm.title["minLen6"] = "minimálne 6 znakov"; 476 477 checkForm.fieldType["minLen8"] = new RegExp(".........*", "i"); 478 checkForm.title["minLen8"] = "minimálne 8 znakov"; 479 480 checkForm.fieldType["mobilePhone"] = new RegExp("(^[0-9]{4}[\/][0-9]{6}$)|(^[+][0-9]{1,3}[\/][0-9]{3}[\/][0-9]{6}$)", "i"); 481 checkForm.title["mobilePhone"] = "mobilné telefónne ÄÃslo vo formáte xxxx/yyyzzz"; 482 483 checkForm.fieldType["numbers"] = new RegExp("^[-]?[0-9]+([,.][0-9]+)?$", "i"); 484 checkForm.title["numbers"] = "povolené ÄÃslice"; 485 486 checkForm.fieldType["postalCode"] = new RegExp("^(([0-9]{5})|([0-9]{3} [0-9]{2})|([0-9]{2} [0-9]{3}))$", "i"); 487 checkForm.title["postalCode"] = "PSÄ"; 488 489 checkForm.fieldType["safeChars"] = new RegExp("^[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ]{1,}$", "i"); 490 checkForm.title["safeChars"] = "povolené ÄÃslice a pÃsmená (bez diakritiky)"; 491 492 checkForm.fieldType["safeChars2"] = new RegExp("^[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_\\-]{1,}$", "i"); 493 checkForm.title["safeChars2"] = "checkform.title.safeChars2"; 494 495 checkForm.fieldType["time"] = new RegExp("^[0-9]{1,2}[:][0-9]{1,2}$", "i"); 496 checkForm.title["time"] = "Äas vo formáte hh:mm"; 497 498 checkForm.fieldType["trim"] = new RegExp("^[^ \f\n\r\t\v]+[.]*", "i"); 499 checkForm.title["trim"] = "Prázdny znak"; 500 501 checkForm.fieldType["url"] = new RegExp("^http[s]?:\/\/[a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])*\.[a-zA-Z]{2,4}([:0-9]*)(\/{1}[%-_~&=\?\.:a-z0-9]*)*$", "i"); 502 checkForm.title["url"] = "adresa web stránky vo formáte http://www.example.com"; 503 504 /* 505 Default values for classes. These will be displayed, if form field with given 506 class is focused and empty. 507 */ 508 509 checkForm.defaultValue = new Array(); 510 checkForm.defaultValue["url"] = "http://www."; 511 checkForm.defaultValue["email"] = "@"; 512 513 checkForm.formula = new Array(); 514 515 /* -------------- customizations end here -------------- */ 516 517 /* 518 Initialisation of checkForm when document is loaded. It finds all forms and 519 fields, checks them and adds events to them. 520 */ 521 522 checkForm.allreadyInitialized = false; 523 524 checkForm.init = function() { 525 526 if (checkForm.allreadyInitialized == true) return; 527 checkForm.allreadyInitialized = true; 528 529 var forms = document.getElementsByTagName("form"); 530 for (var i = 0; i < forms.length; i++) 531 { 532 if(classMagic.has(forms[i], 'noCheckForm')) { 533 continue; 534 } 535 addEventCheckForm(forms[i], "submit", checkForm.check); 536 addEventCheckForm(forms[i], "reset", checkForm.resetClick); 537 if (classMagic.has(forms[i], "checkFormClassicMessage")) checkForm.showClassicErrorMessage = true; 538 } 539 540 var fields = checkForm.findInputs(); 541 for (var i = 0; i < fields.length; i++) 542 { 543 if (fields[i].value && fields[i].value.indexOf("=")==0 && fields[i].form.name!="") 544 { 545 //window.alert("value="+fields[i].value); 546 fnc = fields[i].value.replace(/]/gi, ".value)"); 547 fnc = fnc.replace(/\[/gi, "getFloat(document."+fields[i].form.name+"."); 548 fnc = fnc.replace(/=/gi, "=checkNaN("); 549 fnc = fnc + ")"; 550 fnc = "document."+fields[i].form.name+"." + fields[i].name + ".value"+ fnc + ";"; 551 //window.alert("fnc: " + fnc); 552 checkForm.formula[checkForm.formula.length] = fnc; 553 //window.alert("size: " + checkForm.formula.length); 554 } 555 556 if (fields[i].type.toLowerCase().indexOf("select")!=-1) 557 { 558 //pre select box nemozu byt ostatne eventy lebo to v IE blblo 559 addEventCheckForm(fields[i], "change", checkForm.checkField); 560 } 561 else 562 { 563 checkForm.fillTitles(fields[i]); 564 565 //ak je vypnuta validacia pri inicializacii tak nevaliduj 566 if(false) 567 { 568 checkForm.checkField(fields[i]); 569 } 570 else 571 { 572 //vypnuta validacia pri inicializacii -> nevalidovat len ak je pole prazdne 573 if(!isEmpty(fields[i].value)) 574 checkForm.checkField(fields[i]); 575 } 576 577 addEventCheckForm(fields[i], "blur", checkForm.checkImplBlur); 578 addEventCheckForm(fields[i], "focus", checkForm.checkField);
579 if (classMagic.has(fields[i], "noEnterSubmit")) 580 { 581 addEventCheckForm(fields[i], "keydown", checkForm.checkFieldEnter); 582 } 583 addEventCheckForm(fields[i], "keyup", checkForm.checkField); 584 585 addEventCheckForm(fields[i], "click", checkForm.checkField); 586 587 if ($(fields[i]).is(":checkbox")) { 588 addEventCheckForm(fields[i], "change", checkForm.checkImplBlur); 589 } 590 else { 591 addEventCheckForm(fields[i], "change", checkForm.checkField); 592 } 593 594 //pridaj mu classu, aby sa to dalo rozumnejsie stylovat 595 classMagic.add(fields[i], "input"+fields[i].type.toLowerCase()); 596 597 //pridaj requiredradio pre required radia 598 if (fields[i].type=="radio" || fields[i].type=="checkbox") 599 { 600 if (classMagic.has(fields[i], "required")) 601 { 602 var newcl = "required"+fields[i].type; 603 classMagic.add(fields[i], newcl); 604 } 605 } 606 } 607 } 608 } 609 610 function isEmpty(obj) { 611 if (typeof obj == 'undefined' || obj == null || obj == '' || obj == '@') return true; 612 if (typeof obj == 'number' && isNaN(obj)) return true; 613 if (obj instanceof Date && isNaN(Number(obj))) return true; 614 return false; 615 } 616 617 checkForm.resetClickLastE = null; 618 checkForm.resetClick = function(e) 619 { 620 var formResultDiv = document.getElementById("ajaxFormResultContainer"); 621 if (formResultDiv != null) 622 { 623 formResultDiv.style.display = "none"; 624 formResultDiv.innerHTML = ""; 625 } 626 checkForm.resetClickLastE = e; 627 window.setTimeout(checkForm.resetClickRecheck, 100); 628 } 629 checkForm.resetClickRecheck = function() 630 { 631 if (checkForm.resetClickLastE != null) checkForm.recheck(checkForm.resetClickLastE); 632 } 633 634 /* 635 Helper functions, which finds all fields in given element and returns them in 636 an array. If no element is specified, all fields in document are returned. 637 */ 638 639 checkForm.findInputs = function(elm) { 640 var fields = new Array(); 641 if (!elm) {elm = document;} 642 643 var selects = elm.getElementsByTagName("select"); 644 var textareas = elm.getElementsByTagName("textarea"); 645 var inputs = elm.getElementsByTagName("input"); 646 647 for (var i = 0; i < inputs.length; i++) { 648 if ((inputs[i].type == "text") || (inputs[i].type == "email") || (inputs[i].type == "tel") || (inputs[i].type == "date") || (inputs[i].type == "number") || (inputs[i].type == "password") || (inputs[i].type == "file") || (inputs[i].type == "radio") || (inputs[i].type == "checkbox")) { 649 fields[fields.length] = inputs[i]; 650 } 651 } 652 653 for (var i = 0; i < textareas.length; i++) { 654 fields[fields.length] = textareas[i]; 655 } 656 657 for (var i = 0; i < selects.length; i++) { 658 fields[fields.length] = selects[i]; 659 } 660 661 return fields; 662 } 663 664 /* 665 Checking the form before submitting. To be sure, we will check all fields of 666 given form once more and cancel the submit action if some fields are invalid. 667 */ 668 checkForm.allreadySending = false; 669 670 checkForm.check = function(e) 671 { 672 if (checkForm.isInvalidForm==true) 673 { 674 return false; 675 } 676 677 e = fixECheckForm(e); 678 var obj = e.target; 679 while (obj.tagName != "FORM") { 680 obj = obj.parentNode; 681 } 682 683 var isSubmit = (e.type == "submit"); 684 if (checkForm.checkImpl(obj, isSubmit, e)==false) 685 { 686 return false; 687 } 688 689 if (checkForm.allreadySending == true) 690 { 691 alert(checkForm.allreadySendingMsg); 692 e.preventDefault(); 693 return false; 694 } 695 if (e.type == "submit") 696 {
697 checkForm.allreadySending = true; 698 } 699 checkForm.hideAutocompleteOff(obj); 700 return true; 701 } 702 703 checkForm.checkImpl = function(obj, isSubmit, e) 704 { 705 var fields = checkForm.findInputs(obj); 706 var isSubmitError = false; 707 var errorMessage = checkForm.invalidMsg+"\n"; 708 var errorMessageHtml = '<div class="ajaxError">ProsÃm, opravte nasledovné chyby:</div><ol>'; 709 for (var i = 0; i < fields.length; i++) 710 { 711 //sprav trim (ak treba) 712 checkForm.trimField(fields[i]); 713 //skontroluj 714 var status = checkForm.checkField(fields[i]); 715 var errorBlock = []; 716 var isExistErrorBlock = false; 717 try 718 { 719 errorBlock = checkForm.getErrorBlock(fields[i]); 720 721 if (errorBlock.length == 0) { 722 var id = fields[i].id != null ? fields[i].id : fields[i].name; 723 if (id != '') { 724 errorBlock = $("#" + id).parent().find(".cs-error"); 725 if (errorBlock.length<1) errorBlock = checkForm.getErrorBlock(fields[i]); 726 } 727 else { 728 errorBlock = $(); 729 } 730 } 731 isExistErrorBlock = errorBlock.length > 0; 732 } catch (e) { console.log(e); } 733 734 if (status == "invalid") 735 { 736 if (isSubmit) 737 { 738 isSubmitError = true; 739 var msg = checkForm.markAndGetLabelText(fields[i], true); 740 if (errorMessage.indexOf("- "+msg)==-1) 741 { 742 if(!isExistErrorBlock) 743 { 744 errorMessage = errorMessage + "\n- " + msg; 745 errorMessageHtml = errorMessageHtml + "\n<li>" + msg; 746 if (fields[i].title != null && fields[i].title != undefined && fields[i].title!="") { 747 errorMessageHtml += " - " + fields[i].title 748 } 749 errorMessageHtml += "</li>"; 750 751 if(typeof $(fields[i]).attr("rel") != "undefined") 752 { 753 msg = $(fields[i]).attr("rel"); 754 } 755 else { 756 msg += " " + fields[i].title; 757 } 758 759 if (checkForm.showClassicErrorMessage==false) { 760 var el; 761 var id = fields[i].id != null ? fields[i].id : fields[i].name; 762 if (id != '') { 763 el = $("#" + id).next(".cs-error"); 764 } 765 else { 766 el = $(); 767 } 768 el.parent().append('<div class="help-block cs-error cs-error-'+obj.id+'">'+msg+'</div>').show(); 769 } 770 } 771 else { 772 if (errorBlock.html() == "") { 773 errorBlock.html(msg +' - ' + fields[i].title); 774 } 775 errorBlock.show(); 776 } 777 } 778 } 779 else 780 { 781 return false; 782 } 783 } 784 else 785 { 786 //odznac label, ze je zle vyplneny 787 checkForm.markAndGetLabelText(fields[i], false); 788 } 789 } 790 791 if (isSubmitError) 792 { 793 checkForm.printAlertMessage(errorMessageHtml, errorMessage, e, obj); 794 795 if (e!=null && e.preventDefault) 796 { 797 e.preventDefault(); 798 } 799 800 return false; 801 } 802 } 803 804 checkForm.checkImplBlur = function(e) 805 {
806 var errorMessage = checkForm.invalidMsg+"\n"; 807 var errorMessageHtml = '<div class="ajaxError">ProsÃm, opravte nasledovné chyby:</div><ol>'; 808 var obj; 809 if (e && e.tagName) { 810 obj = e; 811 } else { 812 e = fixECheckForm(e); 813 obj = e.target; 814 } 815 //window.alert(fields[i]); 816 isSubmit = true; 817 //sprav trim (ak treba) 818 checkForm.trimField(obj); 819 //skontroluj 820 var status = checkForm.checkField(obj); 821 var errorBlock = checkForm.getErrorBlock(obj); 822 if (errorBlock.length == 0) { 823 var id = obj.id != null ? obj.id : obj.name; 824 if (id != '') { 825 errorBlock = $("#" + id).next(".cs-error"); 826 } 827 else { 828 errorBlock = $(); 829 } 830 } 831 var isExistErrorBlock = errorBlock.length > 0; 832 833 if (status == "invalid") 834 { 835 var msg = checkForm.markAndGetLabelText(obj, true); 836 837 if (errorMessage.indexOf("- "+msg)==-1) 838 { 839 if(!isExistErrorBlock){ 840 if($(obj).attr("rel") != undefined ){ 841 msg = $(obj).attr("rel"); 842 843 }else{ 844 msg += " " + obj.title; 845 } 846 if (checkForm.showClassicErrorMessage==false) { 847 var el; 848 var id = obj.id != null ? obj.id : obj.name; 849 if (id != '') { 850 el = $("#"+obj.id); 851 } 852 else { 853 el = $(); 854 } 855 el.parent().append('<div class="help-block cs-error cs-error-'+obj.id+'">'+msg+'</div>'); 856 } 857 }else{ 858 if (errorBlock.html() == "") { 859 errorBlock.html(msg +' - ' + obj.title); 860 } 861 errorBlock.show(); 862 } 863 } 864 } 865 else 866 { 867 if(isExistErrorBlock) { 868 errorBlock.hide(); 869 } 870 871 //odznac label, ze je zle vyplneny 872 checkForm.markAndGetLabelText(obj, false); 873 } 874 } 875 876 checkForm.getErrorBlock = function(obj) { 877 var id = obj.id != null ? obj.id : obj.name; 878 if (id != '') { 879 return $(".cs-error-" + obj.id); 880 } 881 return $(); 882 } 883 884 checkForm.printAlertMessage = function(errorMessageHtml, errorMessage, e, obj) 885 { 886 try 887 { 888 if (errorMessageHtml == null) errorMessageHtml="<div class='ajaxError'>"+errorMessage+"</div>"; 889 890 var errorDivElement = document.getElementById("checkFormAlertDiv"); 891 if (errorDivElement == null) errorDivElement = document.getElementById("ajaxFormResultContainer"); 892 if (errorDivElement == null && ($('.cs-error').length == 0 || checkForm.showClassicErrorMessage==true)) 893 { 894 //console.log("Vytvaram error div message"); 895 //vytvor ho 896 var form = null; 897 if (obj != null && obj != undefined) form = $(obj) 898 else form = $("form[name=formMailForm]"); 899 form.prepend("<div id='formResult'><div id='ajaxFormResultContainer'></div></div>"); 900 errorDivElement = document.getElementById("ajaxFormResultContainer"); 901 } 902 903 if (errorDivElement != null) { 904 //console.log("Zobrazujem, html="+$(errorDivElement).html()+"; length=", $(errorDivElement).html().length); 905 if ($(errorDivElement).html().length < 5) $(errorDivElement).html(checkForm.invalidMsg); 906 $(errorDivElement).addClass("alert alert-danger"); 907 $(errorDivElement).removeClass("alert-success"); 908 } 909 910 if ($('.cs-error').length > 0 && checkForm.showClassicErrorMessage==false) { 911 var csError = $('.cs-error:visible').first(); 912 if (csError.length > 0) { 913 $("html,body").animate({ scrollTop: (csError.offset().top - 100) }, { duration: 'fast', easing: 'linear'}); 914 } 915 } 916 else if (errorDivElement != null) 917 { 918 try 919 { 920 //console.log("Zobrazujem error hlasenie, div=", errorDivElement, "message=", errorMessageHtml); 921 $(errorDivElement).html(errorMessageHtml+"</ol>").show("slow"); 922 //div.tab-pane pridane pre tabovany content (usredit) 923 $("html,body,div.tab-pane").animate({ scrollTop: ($(errorDivElement).offset().top - 100) }, { duration: 'fast', easing: 'linear'}); 924 } 925 catch (e) { 926 alert(errorMessage); 927 } 928 } 929 else { 930 alert(errorMessage); 931 } 932 933 if (e!=null && e.preventDefault) 934 { 935 e.preventDefault(); 936 } 937 } 938 catch (e) 939 { 940 alert(errorMessage); 941 } 942 } 943 944 checkForm.markAndGetLabelText = function(field, isInvalid) 945 { 946 //najskor skus najst label pre dany field 947 var id = field.id; 948 if (id == "") id = field.name; 949 950 var text = null; 951 if (id != null) 952 { 953 //skus najst label pre dane pole 954 var labelElm = checkForm.formGetLabel(id); 955 if (labelElm != null) 956 { 957 if (isInvalid) 958 { 959 $("form").removeClass("sending"); 960 if (field.type == "radio" || field.type == "checkbox") 961 { 962 var leftLabelElm = checkForm.formGetLabel(field.name); 963 if (leftLabelElm != null) text = checkForm.getInnerText(leftLabelElm); 964 } 965 if (text == null || text == "") text = checkForm.getInnerText(labelElm); 966 967 if (!classMagic.has(field, "noCheckForm")) { 968 classMagic.add(labelElm, "invalidLabel"); 969 } 970 } 971 else 972 { 973 if (!classMagic.has(field, "noCheckForm")) { 974 classMagic.remove(labelElm, "invalidLabel"); 975 } 976 } 977 } 978 } 979 980 if (text==null && id.indexOf("wjcaptcha")!=-1) { 981 text = "Text na obrázku"; 982 } 983 984 if (text == null) { 985 text = id; 986 } 987 988 if (text == null) { 989 text = $(field).prop('name'); 990 } 991 992 var dataName = $(field).data('name'); 993 if (typeof dataName != "undefined" && dataName != "") { 994 text = dataName; 995 } 996 997 return text; 998 } 999 1000 checkForm.getInnerText = function(elem) 1001 { 1002 var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false; 1003 if(!hasInnerText) 1004 { 1005 return elem.textContent; 1006 } 1007 return elem.innerText; 1008 } 1009 1010 checkForm.formGetLabel = function(forField) 1011 { 1012 if (forField == null || forField == "") return null 1013 1014 var labels = document.getElementsByTagName("LABEL"); 1015 for (i=0; i < labels.length; i++) 1016 { 1017 if (labels[i].htmlFor == forField) return labels[i]; 1018 } 1019 return null; 1020 } 1021 1022 1023 checkForm.hideAutocompleteOff = function(obj) 1024 { 1025 var fields = obj.elements; 1026 for (var i = 0; i < fields.length; i++) 1027 { 1028 var classes = classMagic.get(fields[i]); 1029 //taketo pole nastavim na hidden aby si FF nepamatal heslo 1030 if (classMagic.has(fields[i], "autocompleteoff")) 1031 { 1032 fields[i].setAttribute("type", "hidden"); 1033 } 1034 } 1035 } 1036 1037 checkForm.showAutocompleteOff = function(obj) 1038 { 1039 1040 var fields = obj.elements; 1041 for (var i = 0; i < fields.length; i++) 1042 { 1043 var classes = classMagic.get(fields[i]); 1044 //taketo pole nastavim na hidden aby si FF nepamatal heslo 1045 if (classMagic.has(fields[i], "autocompleteoff")) 1046 { 1047 fields[i].setAttribute("type", "password"); 1048 } 1049 } 1050 } 1051 1052 checkForm.btnSubmit = function(obj) 1053 { 1054 if (checkForm.isInvalidForm==true) 1055 { 1056 return false; 1057 } 1058 1059 var fields = checkForm.findInputs(obj); 1060 for (var i = 0; i < fields.length; i++) 1061 { 1062 //window.alert(fields[i]); 1063 1064 //sprav trim (ak treba) 1065 checkForm.trimField(fields[i]); 1066 //skontroluj 1067 var status = checkForm.checkField(fields[i]);
1068 if (status == "invalid") 1069 { 1070 alert(checkForm.invalidMsg); 1071 return false; 1072 } 1073 } 1074 if (checkForm.allreadySending == true) 1075 { 1076 alert(checkForm.allreadySendingMsg); 1077 return false; 1078 } 1079 checkForm.allreadySending = true; 1080 checkForm.hideAutocompleteOff(obj); 1081 obj.submit(); 1082 return true; 1083 } 1084 1085 /* 1086 Prekontroluje polia, ale nespravi ziadny alert, potrebne po zmene REQCOND 1087 */ 1088 checkForm.recheck = function(e) 1089 { 1090 var valid = true 1091 var fields = checkForm.findInputs(); 1092 for (var i = 0; i < fields.length; i++) 1093 { 1094 status = checkForm.checkField(fields[i]); 1095 if (valid && status == "invalid" || status == "required") 1096 valid = false 1097 } 1098 return valid 1099 } 1100 1101 checkForm.recheckAjax = function(form) 1102 { 1103 return checkForm.checkImpl(form, true, null); 1104 } 1105 1106 /* 1107 checks one field, prints message if not valid 1108 */ 1109 checkForm.recheckFieldAjax = function(element) 1110 { 1111 var status = checkForm.checkField(element); 1112 var errorMessage = checkForm.invalidMsg+"\n"; 1113 var errorMessageHtml = '<div class="ajaxError">ProsÃm, opravte nasledovné chyby:</div><ol>'; 1114 if (status == "invalid") 1115 { 1116 //TODO: mark the input 1117 1118 var msg = checkForm.markAndGetLabelText(element, true); 1119 if (errorMessage.indexOf("- "+msg)==-1) 1120 { 1121 errorMessage = errorMessage + "\n- " + msg; 1122 errorMessageHtml = errorMessageHtml + "\n<li>" + msg; 1123 if (element.title != null && element.title != undefined && element.title!="") errorMessageHtml += " - " + element.title 1124 errorMessageHtml += "</li>"; 1125 } 1126 checkForm.printAlertMessage(errorMessageHtml, errorMessage, null, element.form); 1127 return false; 1128 } 1129 return true; 1130 } 1131 1132 /* 1133 checks more fields, prints messages if at least one not valid 1134 */ 1135 checkForm.recheckFieldsAjax = function(fields) 1136 { 1137 var ret =true; 1138 var errorMessage = checkForm.invalidMsg+"\n"; 1139 var errorMessageHtml = '<div class="ajaxError">ProsÃm, opravte nasledovné chyby:</div><ol>'; 1140 var form = fields[0].form; 1141 for (var i = 0; i < fields.length; i++) 1142 { 1143 checkForm.trimField(fields[i]); 1144 var status = checkForm.checkField(fields[i]); 1145 if (status == "invalid") 1146 { 1147 ret = false; 1148 var msg = checkForm.markAndGetLabelText(fields[i], true); 1149 if (errorMessage.indexOf("- "+msg)==-1) 1150 { 1151 errorMessage = errorMessage + "\n- " + msg; 1152 errorMessageHtml = errorMessageHtml + "\n<li>" + msg; 1153 if (fields[i].title != null && fields[i].title != undefined && fields[i].title!="")errorMessageHtml += " - " + fields[i].title 1154 errorMessageHtml += "</li>"; 1155 } 1156 } 1157 else 1158 { 1159 //odznac label, ze je zle vyplneny 1160 checkForm.markAndGetLabelText(fields[i], false); 1161 } 1162 } 1163 if(!ret) checkForm.printAlertMessage(errorMessageHtml, errorMessage, null, form); 1164 return ret; 1165 } 1166 1167 1168 1169 /* 1170 Checking the form field. 1171 */ 1172 checkForm.checkFieldEnter = function(e) 1173 { 1174 if (e.keyCode && e.keyCode==13) 1175 { 1176 window.alert("Formulár nie je možné odoslaÅ¥ klávesou enter, kliknite prosÃm na prÃsluÅ¡né tlaÄÃtko pre odoslanie formuláru."); 1177 if (e.preventDefault) { 1178 e.preventDefault(); 1179 } 1180 return false; 1181 } 1182 return true; 1183 } 1184 1185 checkForm.trimField = function(e) 1186 { 1187 var obj; 1188 if (e && e.tagName) { 1189 obj = e; 1190 } else { 1191 e = fixECheckForm(e); 1192 obj = e.target; 1193 } 1194 1195 //tieto nebudeme kontrolovat 1196 if (classMagic.has(obj, "trim")==false) return; 1197
1198 //2x je to tu lebo to netrimovalo spravne konce 1199 obj.value = obj.value.replace(checkForm.trimRegexp, ""); 1200 obj.value = obj.value.replace(checkForm.trimRegexp, ""); 1201 } 1202 1203 1204 var checkFormSetCursorObj = null; 1205 var checkFormSetCursorPos = 0; 1206 checkForm.setCursorAsync = function() 1207 { 1208 var node = checkFormSetCursorObj; 1209 var pos = checkFormSetCursorPos; 1210 try 1211 { 1212 var node = (typeof node == "string" || node instanceof String) ? document.getElementById(node) : node; 1213 1214 if(!node) 1215 { 1216 return false; 1217 } 1218 else if(node.createTextRange) 1219 { 1220 var textRange = node.createTextRange(); 1221 textRange.collapse(true); 1222 textRange.moveEnd(pos); 1223 textRange.moveStart(pos); 1224 textRange.select(); 1225 return true; 1226 } 1227 else if(node.setSelectionRange) 1228 { 1229 node.setSelectionRange(pos,pos); 1230 return true; 1231 } 1232 } 1233 catch (e) { } 1234 1235 return false; 1236 } 1237 checkForm.setCursor = function(node,pos) 1238 { 1239 checkFormSetCursorObj = node; 1240 checkFormSetCursorPos = pos; 1241 setTimeout(checkForm.setCursorAsync, 50); 1242 } 1243 1244 checkForm.checkField = function(e) 1245 { 1246 var obj; 1247 if (e && e.tagName) { 1248 obj = e; 1249 } else { 1250 e = fixECheckForm(e); 1251 obj = e.target; 1252 } 1253 1254 //recalculate values 1255 try 1256 { 1257 if (checkForm.formula.length>0) 1258 { 1259 for (i=0; i< checkForm.formula.length; i++) 1260 { 1261 try 1262 { 1263 //window.alert("vypocitavam: "+checkForm.formula[i]); 1264 eval(checkForm.formula[i]); 1265 } 1266 catch (e2) 1267 { 1268 window.status= "chyba vypoctu 2: "+e2+" fnc: "+checkForm.formula[i]; 1269 } 1270 } 1271 } 1272 } 1273 catch (e) 1274 { 1275 window.status= "chyba vypoctu: "+e; 1276 } 1277 1278 var fieldOK = true; 1279 var classes = classMagic.get(obj); 1280 1281 //tieto nebudeme kontrolovat 1282 if (classMagic.has(obj, "noCheckForm")) return; 1283 1284 if (classMagic.has(obj, "captcha")) 1285 { 1286 var actualStatus = "invalid"; 1287 if (classMagic.has(obj, "invalid")==false) actualStatus = "valid"; 1288 1289 checkForm.checkCaptcha(obj); 1290 1291 return actualStatus; 1292 } 1293 1294 classMagic.add(obj, "invalid"); 1295 1296 // conditional required field 1297 if (classMagic.has(obj, "reqcond1")) 1298 { 1299 if ("yes"==REQCOND1) 1300 { 1301 classMagic.remove(obj, "invalid"); 1302 classMagic.remove(obj, "required"); 1303 return("valid"); 1304 } 1305 else 1306 { 1307 classMagic.add(obj, "invalid"); 1308 classMagic.add(obj, "required"); 1309 } 1310 } 1311 1312 if (classMagic.has(obj, "reqcond2")) 1313 { 1314 if ("yes"==REQCOND2) 1315 { 1316 classMagic.remove(obj, "invalid"); 1317 classMagic.remove(obj, "required"); 1318 return("valid"); 1319 } 1320 else 1321 { 1322 classMagic.add(obj, "invalid") 1323 classMagic.add(obj, "required") 1324 } 1325 } 1326 1327 if (classMagic.has(obj, "reqcond3")) 1328 { 1329 if ("yes"==REQCOND3) 1330 { 1331 classMagic.remove(obj, "invalid"); 1332 classMagic.remove(obj, "required"); 1333 return("valid"); 1334 } 1335 else 1336 { 1337 classMagic.add(obj, "invalid"); 1338 classMagic.add(obj, "required"); 1339 } 1340 } 1341 1342 if (classMagic.has(obj, "reqcond4")) 1343 { 1344 if ("yes"==REQCOND4) 1345 { 1346 classMagic.remove(obj, "invalid"); 1347 classMagic.remove(obj, "required"); 1348 return("valid"); 1349 } 1350 else 1351 { 1352 classMagic.add(obj, "invalid") 1353 classMagic.add(obj, "required") 1354 } 1355 } 1356 1357 if (classMagic.has(obj, "reqcond5")) 1358 { 1359 if ("yes"==REQCOND5) 1360 { 1361 classMagic.remove(obj, "invalid"); 1362 classMagic.remove(obj, "required"); 1363 return("valid"); 1364 } 1365 else 1366 { 1367 classMagic.add(obj, "invalid") 1368 classMagic.add(obj, "required") 1369 } 1370 } 1371 1372 if (classMagic.has(obj, "reqcond6")) 1373 { 1374 if ("yes"==REQCOND6) 1375 { 1376 classMagic.remove(obj, "invalid"); 1377 classMagic.remove(obj, "required"); 1378 return("valid"); 1379 } 1380 else 1381 { 1382 classMagic.add(obj, "invalid") 1383 classMagic.add(obj, "required") 1384 } 1385 } 1386 1387 var i = 0; 1388 // required field can't be empty 1389 if (classMagic.has(obj, "required")) 1390 { 1391 if (obj.type == "radio" || obj.type == "checkbox") 1392 { 1393 fieldOK = checkForm.isRadioSelected(obj); 1394 } 1395 else 1396 { 1397 i = 0; 1398 while (i < classes.length) 1399 { 1400 if ((e.type == "blur") && (obj.value == checkForm.defaultValue[classes[i]])) { 1401 obj.value = ""; 1402 } 1403 i++; 1404 } 1405 1406 fieldOK = (checkForm.isBlank(obj.value)) ? false : true; 1407 } 1408 } 1409 1410 // find classes of given field and check, if there are any rules for it 1411 i = 0; 1412 while (i < classes.length) 1413 { 1414 if (checkForm.defaultValue[classes[i]]) { 1415 if ((e.type == "focus") && checkForm.isBlank(obj.value)) 1416 { 1417 obj.value = checkForm.defaultValue[classes[i]]; 1418 checkForm.setCursor(obj, 0); 1419 } 1420 1421 if ((e.type == "blur") && (obj.value == checkForm.defaultValue[classes[i]])) { 1422 obj.value = ""; 1423 } 1424 } 1425 1426 if (fieldOK && obj.type!="checkbox" && obj.type!="radio") 1427 { 1428 if (checkForm.fieldType[classes[i]]) 1429 { 1430 fieldOK = (!checkForm.isBlank(obj.value) && checkForm.checkChars(obj.value, checkForm.fieldType[classes[i]])) ? false : true; 1431 i = classes.length; 1432 } 1433 } 1434 i++; 1435 } 1436 1437 //password2 check 1438 //console.log("Pass 2 check, name=", obj.name); 1439 if ("password2"===obj.name && typeof obj.form["usr.password"] != "undefined") { 1440 var pass2 = obj.value; 1441 var pass1 = obj.form["usr.password"].value; 1442 //console.log("pass1=", pass1, "pass2=", pass2); 1443 if (pass1 != pass2) fieldOK = false; 1444 } 1445 1446 fieldOK = fieldOK || obj.type == 'hidden'; 1447 1448 // if content of the field is not OK, highlight it as invali
1448d 1449 (fieldOK) ? classMagic.remove(obj, "invalid") : classMagic.add(obj, "invalid"); 1450 1451 /* 1452 Function like this should return "true" or "false". But this would be 1453 blocking of keyboard input in case of incomplete content of the field 1454 (e.g. URL). That's why this function returns "valid" or "invalid". 1455 */ 1456 return (fieldOK) ? "valid" : "invalid"; 1457 } 1458 1459 checkForm.fillTitles = function(obj) 1460 { 1461 try 1462 { 1463 if (obj.title!="") return; 1464 1465 if (classMagic.has(obj, "required")) 1466 { 1467 obj.title = "povinné pole"; 1468 } 1469 1470 var classes = classMagic.get(obj); 1471 var i = 0; 1472 for (i=0; i < classes.length; i++) 1473 { 1474 var text = checkForm.title[classes[i]]; 1475 if (text != null && text!=undefined && text != "") 1476 { 1477 if (obj.title != "") obj.title = obj.title+", "+text; 1478 else obj.title = obj.title+" "+text; 1479 } 1480 } 1481 } catch (e) {} 1482 } 1483 1484 /* 1485 Checks if given string contains given pattern (regullar expression). 1486 */ 1487 1488 checkForm.checkChars = function(str, re) { 1489 if (str && re) { 1490 return (str.search(re) == -1) ? true : false; 1491 } 1492 return true; 1493 } 1494 1495 /* 1496 Checks, if given string is blank or not. 1497 */ 1498 1499 checkForm.isBlank = function(str) 1500 { 1501 str = str.replace(checkForm.trimRegexp, ""); 1502 str = str.replace(checkForm.trimRegexp, ""); 1503 return (str == "" || str == " ") ? true : false; 1504 } 1505 1506 /* 1507 WebJET: skontroluje, ci je zvolene aspon jedno radio/checkbox z danej skupiny 1508 */ 1509 checkForm.isRadioSelected = function(obj) 1510 { 1511 try 1512 { 1513 var radioForm = obj.form; 1514 var radios = radioForm.elements[obj.name]; 1515 1516 if (radios.length==undefined) 1517 { 1518 //mame jedno radio 1519 if (obj.checked) 1520 { 1521 classMagic.remove(obj, "invalid"); 1522 if (obj.type=="radio") classMagic.remove(obj, "required"); 1523 } 1524 else 1525 { 1526 classMagic.add(obj, "invalid"); 1527 } 1528 return obj.checked; 1529 } 1530 1531 var someChecked = false; 1532 var checkedCount = 0; 1533 for (i=0; i< radios.length; i++) 1534 { 1535 if (radios[i].checked) 1536 { 1537 someChecked = true; 1538 checkedCount++; 1539 } 1540 } 1541 1542 //skontroluj hodnoty pre min a max len 1543 try 1544 { 1545 var classes = classMagic.get(obj); 1546 if (classes && classes.length) 1547 { 1548 for (i=0; i< classes.length; i++) 1549 { 1550 if (classes[i].indexOf("countCond-")==0) 1551 { 1552 var data = classes[i].split("-"); 1553 if (data && data.length==3) 1554 { 1555 if (checkedCount < data[1]) someChecked = false; 1556 if (checkedCount > data[2]) someChecked = false; 1557 } 1558 } 1559 } 1560 } 1561 } 1562 catch (ex2) {} 1563 1564 for (i=0; i< radios.length; i++) 1565 { 1566 if (someChecked == false) 1567 { 1568 classMagic.add(radios[i], "invalid"); 1569 1570 //najdi prislusny label a nastav aj tomu 1571 var elmId = radios[i].id; 1572 var label = $("label[for="+elmId+"]").addClass("invalidLabel"); 1573 } 1574 else 1575 { 1576 //cb sa uz neda odselectnut, mozeme removnut aj required aby sa to ako tak odstylovalo 1577 classMagic.remove(radios[i], "invalid"); 1578 1579 //najdi prislusny label a nastav aj tomu 1580 var elmId = radios[i].id; 1581 var label = $("label[for="+elmId+"]").removeClass("invalidLabel"); 1582 1583 } 1584 } 1585 1586 return someChecked; 1587 } 1588 catch (ex) 1589 { 1590 //alert(ex); 1591 } 1592 return true; 1593 } 1594 1595 /* 1596 WebJET - kontrola captcha kodu 1597 */ 1598 checkForm.xmlhttp = null; 1599 checkForm.captchaObj = null; 1600 checkForm.checkCaptcha = function(obj) 1601 { 1602 var value = obj.value; 1603 checkForm.xmlhttp=null; 1604 if (window.XMLHttpRequest) 1605 { 1606 // code for IE7+, Firefox, Chrome, Opera, Safari 1607 checkForm.xmlhttp=new XMLHttpRequest(); 1608 } 1609 else 1610 { 1611 // code for IE6, IE5 1612 checkForm.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 1613 } 1614 1615 classMagic.add(obj, "invalid"); 1616 checkForm.captchaObj = obj;
1617 1618 checkForm.xmlhttp.onreadystatechange=checkForm.checkCaptchaChange; 1619 checkForm.xmlhttp.open("GET", "/components/form/catpcha_ajax.jsp?v="+value, true); 1620 checkForm.xmlhttp.send(null); 1621 } 1622 1623 checkForm.checkCaptchaChange = function() 1624 { 1625 try 1626 { 1627 if (checkForm.captchaObj != null) 1628 { 1629 if (checkForm.xmlhttp.readyState==4) 1630 { 1631 // 4 = "loaded" 1632 if (checkForm.xmlhttp.status==200) 1633 { 1634 // 200 = "OK" 1635 classMagic.remove(checkForm.captchaObj, "invalid"); 1636 } 1637 else 1638 { 1639 classMagic.add(checkForm.captchaObj, "invalid"); 1640 } 1641 } 1642 } 1643 } catch (e) {} 1644 } 1645 1646 /* 1647 Initialize script when document is loaded. 1648 */ 1649 addEventCheckForm(window, "load", checkForm.init); 1650//failsafe, ak uz sa nahodou okno loadlo a horny event nenastane 1651 window.setTimeout(checkForm.init, 2000); 1652 1653 /* schova dany element ak checkbox nie je zaskrtnuty */ 1654 function formShowHide(checkbox, elementNamesShow, elementNamesHide) 1655 { 1656 if (checkbox.checked == false) return; 1657 1658 var elements = elementNamesShow.split(","); 1659 for (i=0; i< elements.length; i++) 1660 { 1661 var element = document.getElementById(elements[i]); 1662 if (element != null) element.style.display="block"; 1663 } 1664 elements = elementNamesHide.split(","); 1665 for (i=0; i< elements.length; i++) 1666 { 1667 var element = document.getElementById(elements[i]); 1668 if (element != null) element.style.display="none"; 1669 } 1670 } 1671 1672//alert na odoslanie formularu 1673 if (location.href.indexOf("formsend=true")!=-1) 1674 { 1675 checkForm.printAlertMessage(null, "Formulár bol úspeÅ¡ne odoslaný", null); 1676 } 1677 1678 if (location.href.indexOf("formfail=formIsAllreadySubmitted")!=-1) 1679 { 1680 checkForm.printAlertMessage(null, "Formulár ste už raz odoslali, nie je možné ho odoslaÅ¥ znova.", null); 1681 } 1682 else if (location.href.indexOf("formfail=javascript")!=-1) 1683 { 1684 checkForm.printAlertMessage(null, "<strong><span style='color: red;'>UPOZORNENIE:</span> Pre odoslanie formuláru musÃte maÅ¥ povolený JavaScript. Ak váš prehliadaÄ JavaScript nepodporuje môžete <a href='/components/form/spamprotectiondisable.jsp?backurl=null'>deaktivovaÅ¥ ochranu formulárov</a>.</strong>", null); 1685 } 1686 else if (location.href.indexOf("formfail=probablySpamBot")!=-1) 1687 { 1688 checkForm.printAlertMessage(null, "Formulár bol detekovaný ako SPAM (nevyžiadaná poÅ¡ta). Pre správne odoslanie formuláru musÃte maÅ¥ Å¡tandardné nastavenie prehliadaÄa, medzi jednotlivými odoslaniami poÄkaÅ¥ 30 sekúnd a neodoslaÅ¥ viac ako 20 formulárov za hodinu.", null); 1689 } 1690 else if (location.href.indexOf("formfail=requiredFields")!=-1) 1691 { 1692 checkForm.printAlertMessage(null, "Vo formulári ste nevyplnili vÅ¡etky povinné polia, alebo polia nemajú správne hodnoty. Skontrolujte jednotlivé polia formuláru a skúste ho znova odoslaÅ¥.", null); 1693 } 1694 else if (location.href.indexOf("formfail=bad_file")!=-1) 1695 { 1696 checkForm.printAlertMessage(null, "Vami poslaný súbor nevyhovuje požiadavkám, formulár nebol odoslaný", null); 1697 } 1698 else if (location.href.indexOf("formfail=captcha")!=-1) 1699 { 1700 checkForm.printAlertMessage(null, "Zadaný text z obrázku nie je zhodný", null); 1701 } 1702 else if (location.href.indexOf("formfail=emailNotSend")!=-1) 1703 { 1704 window.alert("Formulár sa nepodarilo odoslaÅ¥ na email! Skúste ho znova odoslaÅ¥ neskôr."); 1705 } 1706 else if (location.href.indexOf("formfail=")!=-1) 1707 { 1708 checkForm.printAlertMessage(null, "Formulár sa nepodarilo odoslaÅ¥! Skúste ho znova odoslaÅ¥ neskôr.", null); 1709 } 1710 1711 1712 1713var defaultStripesExenstion = ".x"; 1714var ajaxStripesExenstion = ".ajax"; 1715 1716/* 1717* Function that uses jQuery to invoke an action of a form. Slurps the values 1718* from the form using prototype's 'form.serialize()' method, and then submits 1719* them to the server using prototype's 'jQuery.post' which transmits the request 1720* and then renders the resposne text into the named container. 1721* 1722* @param formDiv reference to the form object being submitted 1723* @param resultDivthe name of the HTML container to insert the result into 1724* @param event the name of the event to be triggered, or null 1725*/ 1726 1727function invokeWJAjax(formDiv, resultDiv, event, action, callMyFunction) 1728{ 1729 try 1730 { 1731 var form = null; 1732 1733 $("form[name="+formDiv+"]").addClass("sending"); 1734 1735 //"formMailForm"==formDiv 1736 if (formDiv.indexOf("formMailForm") > -1) 1737 { 1738 1739 form = $("form[name="+formDiv+"]"); 1740 form.attr("id", formDiv); 1741 } 1742 var formByIds = null; 1743 if (form == null) formByIds = $("#" + formDiv + " form"); 1744 if (form == null && formByIds != null && formByIds.length!=0) 1745 { 1746 if(formByIds.length > 1) 1747 { 1748 form = $(formByIds[1]); //zoberiem druhy formular - prvy je webjetObfuscateForm 1749 } 1750 else 1751 { 1752 form = $(formByIds[0]); 1753 } 1754 } 1755 1756 try 1757 { 1758 if ("multipart/form-data" == form.attr("enctype")) 1759 { 1760 return true; 1761 } 1762 } 1763 catch (ex1) {alert("1:" + ex1)} 1764 1765 $("#formResult").remove();// vymaze form result 1766 $("input, textarea, select").removeClass("invalid");
1766// vymaze vsetky classy invalid 1767 1768 if ($("#" + resultDiv).length==0) 1769 { 1770 form.prepend("<div id=\"formResult\"><div id='"+resultDiv+"'></div></div>"); 1771 } 1772 1773 try 1774 { 1775 //checkform test 1776 if (checkForm) 1777 { 1778 var check = checkForm.recheckAjax(document.getElementById(formDiv)); 1779 if (check==false) 1780 { 1781 1782 try 1783 { 1784 if (typeof callMyFunction != 'undefined') callMyFunction(check); 1785 } 1786 catch (e) { } 1787 1788 //prevent default 1789 return false; 1790 } 1791 } 1792 } 1793 catch (ex2) { window.alert("7" + ex2); console.log(ex2); } 1794 1795 1796 var extIndex = action.indexOf(defaultStripesExenstion); 1797 //compose ajax url from original form action replacing original stripes script extension 1798 //with stripes ajax extension configured in web.xml 1799 var url = action; 1800 1801 //"formMailForm"==formDiv 1802 if (formDiv.indexOf("formMailForm") > -1) 1803 { 1804 url = form.attr("action").replace(/\/formmail\.do/gi, "/FormMailAjax.action"); 1805 } 1806 1807 //create params from serializing form inputs and add param simulating button click in order to 1808 //Stripes could find actionBean event handler 1809 1810 var formSubmitCallback = function() { 1811 var params = form.serialize(); 1812 if(event != null) params = event + '&' + params; 1813 //hide errors if visible 1814 $("#" + resultDiv).hide(); 1815 //fire ajax request 1816 1817 var callback = function(dataFromServer) { 1818 wjAjaxOnFormResult(formDiv, resultDiv, dataFromServer, callMyFunction); 1819 }; 1820 //set up what to do if AJAX request fails 1821 $("").ajaxError(wjAjaxOnServerError); 1822 1823 1824 $.post(url, params, callback, "text"); 1825 //return false to button to stop standard submit of the form 1826 } 1827 //pre re-captcha v3 potrebujeme najskor volat validate 1828 if (typeof window.wjFormSubmit == "function") { 1829 window.wjFormSubmit(form, formSubmitCallback); 1830 } else { 1831 formSubmitCallback(); 1832 } 1833 1834 return false; 1835 } 1836 catch(ex) 1837 { 1838 window.alert("Error 2: " + ex); 1839 return true; 1840 } 1841} 1842 1843/* 1844* Method is executed when server returns exception. 1845*/ 1846function wjAjaxOnServerError(event, request, settings, error){ 1847 alert("Server returned an error, form was not probably processed by the server."); 1848} 1849 1850/* 1851* Method is called when server returns non JSON data. 1852*/ 1853function wjAjaxOnServerDataError(data){ 1854 alert("Server has returned data in unknown format."); 1855} 1856 1857/* 1858* Method is called when server returns reply to ajax call. 1859* 1860* @param data contains reply from the server 1861*/ 1862function wjAjaxOnFormResult(formDiv, resultDiv, data, callMyFunction) { 1863 try 1864 { 1865 var result = eval(data); 1866 } catch (ex) { 1867 wjAjaxOnServerDataError(data); 1868 return; 1869 } 1870 1871 try 1872 { 1873 if (typeof callMyFunction != 'undefined') callMyFunction(result); 1874 } 1875 catch (e) { } 1876 1877 if (result.ok) 1878 { 1879 wjAjaxOnSuccess(formDiv, resultDiv, result, callMyFunction); 1880 } else { 1881 wjAjaxOnError(formDiv, resultDiv, result); 1882 } 1883} 1884 1885/* 1886* Method is executed, when form was submited with success. 1887*/ 1888function wjAjaxOnSuccess(formDiv, resultDiv, result) 1889{ 1890 $("#" + formDiv).queue(function() 1891 { 1892 //console.log(formDiv+"/"+resultDiv+"/"+result); 1893 $("#" + resultDiv).parent().addClass("alert alert-ajax alert-success"); 1894 $("#" + resultDiv).parent().removeClass("alert-danger"); 1895 formAfterSend(); 1896 $("#" + resultDiv).html("<div class=\"overlay\"></div><div class=\"form-dialog\">"+result.okResult).fadeIn(); 1897 $("html,body").animate({ scrollTop: ($("#" + resultDiv).offset().top - 100) }, { duration: 'fast', easing: 'linear'}); 1898 $(this).dequeue(); 1899 1900 window.setTimeout(wjAjaxResetForm.bind(null, formDiv), 500); 1901 window.setTimeout(function(){ 1902 var div = $("#" + resultDiv), 1903 formResult = div.closest('#formResult'); 1904 1905 if (formResult.length > 0) { 1906 formResult.fadeOut("slow"); 1907 } 1908 else { 1909 div.fadeOut("slow"); 1910 } 1911 }, 4000); 1912 1913 wjAjaxSetToken(formDiv, result.token); 1914 }); 1915} 1916 1917function formAfterSend() { 1918} 1919 1920function wjAjaxResetForm(formDiv) 1921{ 1922 try 1923 { 1924 var form = $('form[name="' + formDiv + '"]') 1925 if (formDiv.length > 0) 1926 { 1927 1928 form.find('input[type=text], input[type=email], input[type=tel], input[type=date], input[type=checkbox], input[type=radio], textarea').each(function(){ 1929 var el = $(this); 1930 1931 $("form[name="+formDiv+"]").removeClass("sending"); 1932 1933 if (el.is(':checkbox') || el.is(':radio')) { 1934 el.prop('checked', el[0].defaultValue).trigger('change'); 1935 } 1936 else { 1937 el.val('').trigger('change'); 1938 } 1939 1940 if (el.hasClass('selectmenu')) { 1941 setTimeout(function(){ 1942 el.val('').selectmenu('refresh'); 1943 }); 1944 } 1945 }); 1946 1947 form.find('select').each(function() { 1948 this.selectedIndex = 0; 1949 }); 1950 1951 form.find(".dropzone").each(function() { 1952 Dropzone.forElement(this).removeAllFiles(); 1953 }); 1954 } 1955 } catch (e) { 1956 console.log(e); 1957 } 1958} 1959 1960function wjAjaxSetToken(formDiv, token) 1961{ 1962 try 1963 { 1964 if (token != undefined && token != null && token!="") 1965 { 1966 $("form[name="+formDiv+"]").find("input[name=__token]").val(token); 1967 } 1968 } catch (e) {} 1969} 1970 1971/* 1972* Method is executed, when form was submitted and server returned error. 1973*/ 1974function wjAjaxOnError(formDiv, resultDiv, result) { 1975 $("#" + resultDiv).html(result.errorResult).show("slow"); 1976 $("#" + formDiv).queue(function () 1977 { 1978 var callback = function() 1979 { 1980 wjAjaxColorizeLabel(this, result); 1981 }; 1982 $("#" + formDiv + " label").each(callback); 1983 $("#wjcaptchaImg1").click(); 1984 $("#wjcaptcha1").addClass("invalid"); 1985 $("#" + resultDiv).parent().addClass("alert alert-ajax alert-danger"); 1986 $("html,body").animate({ scrollTop: ($("#" + resultDiv).offset().top - 100) }, { duration: 'fast', easing: 'linear'}); 1987 $("form").removeClass("sending"); 1988 $(this).dequeue(); 1989 1990 wjAjaxSetToken(formDiv, result.token); 1991 }); 1992} 1993 1994/* 1995* Method will add class "error" to each label, whose input was found in validationErrors object. 1996* In the oposite way, it removes any possible "error" class from any labes, that currently is not in error. 1997*/ 1998function wjAjaxColorizeLabel(label, result) { 1999 var error = result.validationErrors[label.htmlFor]; 2000 var errorIndex = -1; 2001 if (label.className != null) errorIndex = label.className.indexOf('error'); 2002 if (error != null && errorIndex == -1) { 2003 label.className = label.className + " error"; 2004 } 2005 if (error == null && errorIndex > -1) { 2006 label.className = label.className.substring(0, errorIndex) 2007 + label.className.substring(errorIndex + 5, label.className.length); 2008 } 2009} 2010 2011 2012 2013(function() { 2014 var method; 2015 var noop = function () {}; 2016 var methods = [ 2017 'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 2018 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 2019 'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', 2020 'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn' 2021 ]; 2022 var length = methods.length; 2023 var console = (window.console = window.console || {}); 2024 2025 while (length--) { 2026 method = methods[length]; 2027 2028 2029 if (!console[method]) { 2030 console[method] = noop; 2031 } 2032 } 2033}()); 2034 2035
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.