1/** 2 * @fileoverview js/plugins 3 * @description JS form validation, Uses Symfony generated data structure 4 * 5 * @author bKarolyi, Worbyd 6 * @version Network 1.0 7 */ 8 9var Dom = YAHOO.util.Dom, 10 Event = YAHOO.util.Event; 11 12/** 13 * initialize validators after domready 14 * 15 * @param {Object} id variable name of the structure, and the id of the form 16 */ 17function initValidator( id ) 18{ 19 Event.onDOMReady( function() 20 { 21 new formValidator( id ); 22 } ); 23} 24 25/** 26 * stores the validator instances 27 * 28 * @type array 29 */ 30var formValidators = []; 31 32/** 33 * call initValidator for all the validators created by server 34 */ 35if ( typeof nw_js_validators != "undefined" ) 36{ 37 for ( i in nw_js_validators ) 38 { 39 initValidator( i ); 40 } 41} 42 43/** 44 * collection of event- and error handler functions 45 * one instance for each forms 46 * @param {Object} form_id 47 */ 48function formValidator( form_id ) 49{ 50 this.form_id = form_id; 51 /** 52 * form 53 * @type HTMLelement 54 */ 55 this.form = Dom.get( form_id ); 56 this.origsubmit = null; 57 this.validators = []; 58 59 /** 60 * constructor of the formValidator class 61 */ 62 this._init = function() 63 { 64 formValidators.push( this ); 65 this.addValidators(); 66 this.setEvents(); 67 this.setSubmitEvent(); 68 } 69 70 /** 71 * stores all validators in an array 72 */ 73 this.addValidators = function() 74 { 75 this.validators = eval( "nw_js_validators." + form_id ); 76 } 77 78 /** 79 * sets all validation handler events related to form elements, except "submit" validators 80 */ 81 this.setEvents = function() 82 { 83 for ( var i_validators = 0; i_validators < this.validators.length; i_validators++ ) 84 { 85 if ( !this.validators[i_validators].runat ) 86 { 87 continue; 88 } 89 90 var act_validator = this.validators[i_validators]; 91 92 for ( var i_runat=0; i_runat < this.validators[i_validators].runat.length; i_runat++ ) 93 { 94 var act_runat = act_validator.runat[i_runat]; 95 if ( act_runat != "submit" ) 96 { 97 var el = ""; 98 if ( !Dom.get( act_validator.id ) && act_validator.type != "sfValidatorDate" ) 99 { 100 if ( Dom.get(act_validator.id + "_1" ) ) 101 { 102 el = Dom.get( act_validator.id + "_1" ); 103 } 104 else 105 { 106 continue; 107 } 108 } 109 110 if ( act_validator.type == "sfValidatorDate" ) 111 { 112 el = [Dom.get(act_validator.id+"_year" ), Dom.get(act_validator.id+"_month" ), Dom.get(act_validator.id+"_day" )]; 113 if ( act_validator.options.with_time ) 114 { 115 el.push( Dom.get( act_validator.id+"_hour" ) ); 116 el.push( Dom.get( act_validator.id+"_min" ) ); 117 el.push( Dom.get( act_validator.id+"_second" ) ); 118 } 119 } 120 else 121 { 122 if (el == "") 123 { 124 el = Dom.get( act_validator.id ); 125 } 126 } 127 128 //e - event 129 //b - payload 130 //b[0] - this (formValidator ) 131 //b[1] - act_validator 132 var origEvent = eval( "el.on" + act_runat ); 133 if ( !origEvent ) 134 { 135 origEvent = function(){} 136 } 137 138 eval( "el.on" + act_runat + "=function(){}" ); 139 140 Event.on( el, act_runat, function( e, b ){ 141 var e = Event.getEvent( e ); 142 Event.stopEvent( e ); 143 var validatorobj = new validator( b[1].type, b[1] ); 144 if ( validatorobj.valid ) 145 { 146 var act_validator = b[1]; 147 var location = b[0].getLocation( act_validator ); 148 var el; 149 if ( act_validator.type == "sfValidatorDate" ) 150 { 151 el = [Dom.get( act_validator.id+"_year" ), Dom.get( act_validator.id+"_month" ), Dom.get( act_validator.id+"_day" )]; 152 if ( act_validator.options.with_time ) 153 { 154 el.push( Dom.get( act_validator.id+"_hour" ) ); 155 el.push( Dom.get( act_validator.id+"_min" ) ); 156 el.push( Dom.get( act_validator.id+"_second" ) ); 157 } 158 } 159 else 160 { 161 if ( !Dom.get( act_validator.id ) ) 162 { 163 if ( Dom.get(act_validator.id + "_1" ) ) 164 { 165 el = Dom.get( act_validator.id + "_1" ); 166 } 167 168 else if ( Dom.get(act_validator.id + "_field" ) ) 169 { 170 el = Dom.get( act_validator.id + "_field" ); 171 } 172 else 173 { 174 return false;
175 } 176 } 177 else 178 { 179 el = [ Dom.get( act_validator.id ) ]; 180 } 181 } 182 183 if ( location == "field" ) 184 { 185 for (i_el = 0; i_el < el.length; i_el++ ) 186 { 187 errorHandlers.showTrueFeedback( el[i_el] ); 188 if ( i_el == el.length -1 ) 189 { 190 break; 191 } 192 } 193 } 194 else 195 { 196 for (i_el = 0; i_el < el.length; i_el++ ) 197 { 198 errorHandlers.hideErrorMsg( el[i_el], location ); 199 if ( i_el == el.length -1 ) 200 { 201 break; 202 } 203 } 204 } 205 206 eval ( "this.on" + b[3] + "=" + b[2] ); 207 eval ( "this.on" + b[3] + "();" ); 208 eval ( "this.on" + b[3] + "=function(){}" ); 209 210 } 211 else 212 { 213 //only one error exists 214 var act_error = validatorobj.errors; 215 var type = b[1].type; 216 act_error = b[0].changeErrorValues( act_error )[0]; 217 var location = b[0].getLocation( act_error ); 218 if ( type == "sfValidatorDate" && this.id.search( "_day" ) == -1 ) 219 { 220 errorHandlers.hideErrorMsg( act_error.id + "_year", location ); 221 } 222 else 223 { 224 errorHandlers.showErrorMsg( act_error.id, act_error.message, location ); 225 } 226 } 227 }, [this, act_validator, origEvent, act_runat] ) 228 } 229 }; 230 }; 231 } 232 233 /** 234 * collects all validators and run them on submit 235 * the relation between validators is AND 236 */ 237 this.handleSubmitEvent = function() 238 { 239 errorHandlers.hideAllErrorMsg( this.form ); 240 if ( this.validators.length == 0 ) 241 { 242 return true; 243 } 244 else if ( this.validators.length == 1 ) 245 { 246 this.hideAllErrors(); 247 var type = this.validators[0].type; 248 var validatorobj = new validator( type, this.validators[0] ); 249 if ( validatorobj.valid ) 250 { 251 for ( i_form=0; i_form < this.form.elements.length; i_form++ ) 252 { 253 errorHandlers.showTrueFeedback( this.form.elements[i_form] ); 254 } 255 return true; 256 } 257 else 258 { 259 var errors = validatorobj.errors; 260 errors = this.changeErrorValues( errors ); 261 var error = errors[0]; 262 var location = this.getLocation( error ); 263 errorHandlers.showErrorMsg( error.id, error.message, location ); 264 265 return false; 266 } 267 } 268 else 269 { 270 var valid = true; 271 var errors = []; 272 for ( i_validator = 0; i_validator < this.validators.length; i_validator++ ) 273 { 274 var act_validator = this.validators[i_validator]; 275 276 var act_validatorobj = new validator( act_validator.type, act_validator ); 277 if ( !act_validatorobj.valid ) 278 { 279 for ( i_errors = 0; i_errors < act_validatorobj.errors.length; i_errors++ ) 280 { 281 errors.push( act_validatorobj.errors[i_errors] ); 282 } 283 284 if ( valid === true ) 285 { 286 valid = false; 287 } 288 } 289 } 290 if ( valid ) 291 { 292 //this.hideAllErrors(); 293 for ( i_form=0; i_form < this.form.elements.length; i_form++ ) 294 { 295 errorHandlers.showTrueFeedback( this.form.elements[i_form] ); 296 } 297 298 return true; 299 } 300 else 301 { 302 for ( i_validator = 0; i_validator < this.validators.length; i_validator++ ) 303 { 304 var act_validator = this.validators[i_validator]; 305 var location = this.getLocation( act_validator ); 306 var el; 307 if ( act_validator.type == "sfValidatorDate" ) 308 { 309 el = [Dom.get( act_validator.id+"_year" ), Dom.get( act_validator.id+"_month" ), Dom.get( act_validator.id+"_day" )]; 310 if ( act_validator.options.with_time ) 311 { 312 el.push( Dom.get( act_validator.id+"_hour" ) ); 313 el.push( Dom.get( act_validator.id+"_min" ) ); 314 el.push( Dom.get( act_validator.id+"_second" ) ); 315 } 316 } 317 else 318 { 319 if ( !Dom.get( act_validator.id ) ) 320 { 321 if ( Dom.get(act_validator.id + "_1" ) ) 322 { 323 el = Dom.get( act_validator.id + "_1" ); 324 } 325 326 else if ( Dom.get(act_validator.id + "_field" ) ) 327 { 328 el = Dom.get( act_validator.id + "_field" ); 329 } 330 else 331 { 332 break 333 } 334 } 335 else 336 { 337 el = [ Dom.get( act_validator.id ) ]; 338 } 339 } 340 if ( location == "field" ) 341 { 342 for (i_el = 0; i_el < el.length; i_el++ ) 343 { 344 errorHandlers.showTrueFeedback( el[i_el] ); 345 if ( i_el == el.length -1 ) 346 { 347 break; 348 } 349 } 350 } 351 } 352 353 errors = this.changeErrorValues( errors ); 354 for ( i_error = 0; i_error < errors.length; i_error++ ) 355 { 356 var error = errors[i_error]; 357 var location = this.getLocation( error ); 358 errorHandlers.showErrorMsg( error.id, error.message, location ); 359 } 360 var first_error_in_form = this.getFirstOfErrors( errors ); 361 362 if ( first_error_in_form ) 363 { 364 var n_highlight = new errorHandlers.highlightManager( first_error_in_form.id, this.getLocation( first_error_in_form ) );
365 n_highlight.init(); 366 } 367 } 368 369 return false; 370 } 371 } 372 373 /** 374 * changes %value% pattern in error messages to the value of the specied fields 375 * 376 * @param {Object} errors 377 */ 378 this.changeErrorValues = function( errors ) 379 { 380 for ( i_error = 0; i_error < errors.length; i_error++ ) 381 { 382 if ( errors[i_error].message.search( "%value%" ) >= 0 ) 383 { 384 errors[i_error].message = errors[i_error].message.replace( "%value%", Dom.get( errors[i_error].id ).value ); 385 } 386 } 387 return errors; 388 } 389 390 this.getFirstOfErrors = function( errors ) 391 { 392 var min_num = this.form.elements.length + 1; 393 var min_error = null; 394 var form_elements = this.form.elements; 395 396 for( i_error = 0; i_error < errors.length; i_error++ ) 397 { 398 var act_error = errors[i_error]; 399 var element_to_check = ( Dom.get( act_error.id ) || 400 Dom.get( act_error.id + "_year" ) ); 401 if ( !element_to_check ) 402 { 403 continue; 404 } 405 406 for( i_form_element = 0; i_form_element < form_elements.length; i_form_element++ ) 407 { 408 var act_form_element = form_elements[i_form_element]; 409 410 if ( act_form_element == element_to_check ) 411 { 412 if ( min_num === null || 413 i_form_element < min_num ) 414 { 415 min_num = i_form_element; 416 min_error = act_error; 417 } 418 } 419 } 420 } 421 422 return min_error; 423 } 424 425 this.hideAllErrors = function() 426 { 427 this.hideAllFieldErrors(); 428 this.hideAllBlockErrors(); 429 return true; 430 } 431 432 this.hideAllFieldErrors = function() 433 { 434 var fieldErrors = Dom.getElementsByClassName( "n_fielderror", "*", this.form ); 435 Dom.addClass( fieldErrors, "n_invisible" ); 436 return true; 437 } 438 439 /** 440 * sets submit event on form 441 */ 442 this.setSubmitEvent = function() 443 { 444 //e - event 445 //b - payload 446 //b - this (formValidator ) 447 if ( this.form.getAttribute("onsubmit") != null ) 448 { 449 var submitstr = this.form.getAttribute("onsubmit")+""; 450 submitstr = submitstr.replace("this", "Dom.get('"+this.form.id+"')"); 451 eval ( "this.origsubmit = function(){ " + submitstr + "}" ); 452 if ( ie ) 453 { 454 eval ( "this.origsubmit = " + submitstr ); 455 } 456 457 /** 458 * sets form submit event 459 * @param {Object} e 460 */ 461 this.form.onsubmit = function( e ){ 462 var obj = null; 463 for ( i_validators = 0; i_validators < formValidators.length; i_validators++ ) 464 { 465 if ( formValidators[i_validators].form == this ) 466 { 467 obj = formValidators[i_validators]; 468 } 469 } 470 471 var valid_true = obj.handleSubmitEvent() 472 if ( !valid_true ) 473 { 474 return false; 475 } 476 477 return obj.origsubmit(); 478 }; 479 } 480 else 481 { 482 this.form.onsubmit = function( e ){ 483 var obj = null; 484 for ( i_validators = 0; i_validators < formValidators.length; i_validators++ ) 485 { 486 if ( formValidators[i_validators].form == this ) 487 { 488 obj = formValidators[i_validators]; 489 } 490 } 491 492 var valid_true = obj.handleSubmitEvent(); 493 if ( !valid_true ) 494 { 495 return false; 496 } 497 498 return true; 499 }; 500 } 501 } 502 this.showFieldError = function( id, msg ) 503 { 504 var el = Dom.get( id ); 505 var right = Dom.getElementsByClassName( "n_fielderror", "*", Dom.getAncestorByTagName( el, "tr" ) )[0]; 506 var bottomwrap = Dom.getNextSibling( Dom.getAncestorByTagName( el, "tr" ) ); 507 if ( !bottomwrap ) 508 { 509 return false; 510 } 511 var bottom = Dom.getElementsByClassName( "n_formerrormessage", "*", bottomwrap )[0]; 512 if ( !bottom ) 513 { 514 return false; 515 } 516 Dom.removeClass( bottomwrap, "n_invisible" ); 517 bottom.innerHTML = msg; 518 519 Dom.removeClass( right, "n_invisible" ); 520 Dom.removeClass( right, "n_validinputtext" ); 521 Dom.addClass( right, "n_invalidinputtext" ); 522 right.innerHTML = "hiba"; 523 524 return true; 525 } 526 527 this.showTrueFeedback = function( el ) 528 { 529 if ( el.type == "submit" ) 530 { 531 return false;
532 } 533 var right = Dom.getElementsByClassName( "n_fielderror", "*", Dom.getAncestorByTagName( el, "tr" ) )[0]; 534 535 if ( !right ) 536 { 537 return false; 538 } 539 540 var bottomwrap = Dom.getNextSibling( Dom.getAncestorByTagName( el, "tr" ) ); 541 if ( !bottomwrap ) 542 { 543 return false; 544 } 545 var bottom = Dom.getElementsByClassName( "n_formerrormessage", "*", bottomwrap )[0]; 546 Dom.addClass( bottomwrap, "n_invisible" ); 547 548 right.innerHTML = __("rendben"); 549 Dom.removeClass( right, "n_invisible" ); 550 Dom.removeClass( right, "n_invalidinputtext" ); 551 Dom.addClass( right, "n_validinputtext" ); 552 553 return true; 554 } 555 556 this.hideAllBlockErrors = function() 557 { 558 var block_errors = Dom.getElementsByClassName( "n_fieldseterrortext", "*", this.form ); 559 Dom.addClass( block_errors, "n_invisible" ); 560 561 return true; 562 } 563 564 this.showBlockError = function( id, msg ) 565 { 566 var el = Dom.get( id ); 567 var block = Dom.getAncestorByClassName( el, "n_contentboxinlay" ); 568 var right = Dom.getElementsByClassName( "n_fieldseterrortext", "*", block )[0]; 569 570 right.innerHTML = msg; 571 Dom.removeClass( right, "n_invisible" ); 572 573 return true; 574 } 575 576 this.getLocation = function( obj ) 577 { 578 if ( obj.location ) 579 { 580 return obj.location; 581 } 582 else 583 { 584 return "field"; 585 } 586 } 587 this._init(); 588} 589 590/** 591 * class, that collects validation functions according to symfony classes 592 * 593 * 594 * @param {Object} type type of the validation (and, or, sfValidatorInteger, ...) and the nem of the validation function at the same time 595 * @param {Object} obj stores the validation information 596 * obj.id, 597 * obj.options, 598 * obj.messages 599 */ 600function validator( type, obj ) 601{ 602 this.type = type; 603 this.obj = obj; 604 605 606 this.errors = []; 607 this.valid = false; 608 /** 609 * evaluates validators, and relations between them 610 */ 611 this._init = function() 612 { 613 var a; 614 try 615 { 616 a = eval ( "this."+this.type+"( this.obj )" ); 617 } 618 catch ( e ) 619 { 620 this.errors.push( e ); 621 a = false; 622 } 623 624 this.valid = a; 625 } 626 627 /** 628 * or relation validator 629 * 630 * @param {Object} obj 631 */ 632 this.or = function( obj ) 633 { 634 for ( i_or = 0; i_or < obj.validators.length; i_or ++ ) 635 { 636 var act_validator = obj.validators[i_or]; 637 this.errors = [];
638 try 639 { 640 return eval ( "this."+act_validator.type+"( act_validator ) == true" ) 641 } 642 catch( e ) 643 { 644 this.errors = []; 645 this.errors[0] = e; 646 } 647 } 648 throw this.errors[0]; 649 } 650 651 /** 652 * and relation validator 653 * 654 * @param {Object} obj 655 */ 656 this.and = function( obj ) 657 { 658 this.errors = []; 659 for ( i_and = 0; i_and < obj.validators.length; i_and ++ ) 660 { 661 var act_validator = obj.validators[i_and]; 662 try 663 { 664 eval ( "this."+act_validator.type+"( act_validator )" ) 665 } 666 catch ( e ) 667 { 668 //this.errors.push( e ); 669 throw e; 670 return false; 671 } 672 } 673 674 675 return true; 676 } 677 678 this.NwValidatorClubName = function( obj ) 679 { 680 obj.type = "sfValidatorString"; 681 682 obj.messages.min_length = __( "Túl rövid url" ); 683 obj.messages.max_length = __( "Túl hosszú url" ); 684 obj.messages.required = __( "Kitöltése kötelezÅ" ); 685 686 obj.options.required = true; 687 obj.options.trim = true; 688 obj.options.min_length = 1; 689 obj.options.max_length = 100; 690 return this.sfValidatorString( obj ); 691 } 692 693 this.NwValidatorClubURL = function( obj ) 694 { 695 obj.type = "sfValidatorString"; 696 697 obj.messages.min_length = __( "Túl rövid url" ); 698 obj.messages.max_length = __( "Túl hosszú url" ); 699 obj.messages.required = __( "Kitöltése kötelezÅ" ); 700 701 obj.options.required = true; 702 obj.options.trim = true; 703 obj.options.min_length = 3; 704 obj.options.max_length = 30; 705 return this.sfValidatorString( obj ); 706 } 707 708 this.NwValidatorFirstLastName = function( obj ) 709 { 710 var el = Dom.get( obj.id ); 711 var text = el.value; 712 text = this.clean( obj, el ); 713 714 var pattern = /^[a-zÃéáäÄÄĺľÅôÅšťýžűÅúöüóÃÃÃŰÅÃÃÃÃÄÄĹĽÅÅŠŤÃÃŽÃÃÅ®A-ZÃéáűÅúöüóÃÃÃŰÅÃÃÃÃÄÄĹĽÅÅŠŤÃÃŽÃÃÅ®0-9-\. ]{1,}$/; 715 716 if ( text == "" ) 717 { 718 return true; 719 } 720 721 if( !pattern.test( text ) ) 722 { 723 throw { 724 id: obj.id, 725 message: obj.messages.invalid, 726 location: obj.error_msg_location 727 } 728 } 729 730 return true; 731 } 732 733 this.NwValidatorRegCity = function( obj ) 734 { 735 // ajax lenne 736 737 obj.options.required = true; 738 obj.options.trim = true; 739 if ( obj.id.substring( obj.id.length - 10, obj.id.length ) != "_city_city" ) 740 { 741 obj.id = obj.id + "_city"; 742 } 743 744 var el = Dom.get( obj.id ); 745 var text = el.value; 746 text = this.clean( obj, el ); 747 748 return true; 749 } 750 751 this.NwValidatorRegEmail = function( obj ) 752 { 753 var el = Dom.get( obj.id ); 754 var text = el.value; 755 text = this.clean( obj, el ); 756 var emailPattern = /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i; 757 758 if ( text == "" ) 759 { 760 return true; 761 } 762 763 if( !emailPattern.test( text ) ) 764 { 765 throw { 766 id: obj.id, 767 message: obj.messages.invalid, 768 location: obj.error_msg_location 769 } 770 } 771 772 return true; 773 } 774 775 this.NwValidatorNickname = function( obj ) 776 { 777 var el = Dom.get( obj.id ); 778 var text = el.value; 779 text = this.clean( obj, el ); 780 781 var validPattern = /^[a-zA-Z0-9]+$/; 782 783 if ( text == "" ) 784 { 785 return true; 786 } 787 788 if( !validPattern.test( text ) ) 789 { 790 throw { 791 id: obj.id, 792 message: obj.messages.valid_nick, 793 location: obj.error_msg_location 794 } 795 } 796 797 return true; 798 } 799 800 this.NwValidatorPassword = function( obj ) 801 { 802 var el = Dom.get( obj.id ); 803 var text = el.value; 804 text = this.clean( obj, el ); 805 806 if ( text.length == 0 ) 807 { 808 return true; 809 } 810 811 if ( text.length <= 3 ) 812 { 813 throw { 814 id: obj.id, 815 message: obj.messages.min_length, 816 location: obj.error_msg_location 817 } 818 } 819 820 var validPattern = /^[a-zA-Z0-9]+$/; 821 822 if( !validPattern.test( text ) ) 823 { 824 throw { 825 id: obj.id, 826 message: obj.messages.invalid_password, 827 location: obj.error_msg_location 828 } 829 } 830 831 return true; 832 } 833 834 this.NwValidatorInterests = function( obj ) 835 { 836 var count = 0; 837 var id = obj.id; 838 var temp_el = null; 839 840 //checkboxes 841 Dom.getElementsBy( function( el ) 842 { 843 if ( el.id.substring( 0, id.length ) == id ) 844 { 845 if ( el.checked ) 846 { 847 count++; 848 } 849 temp_el = el; 850 } 851 }, "input" ); 852 853 //select 854 if ( Dom.get( id ) ) 855 { 856 if ( Dom.get( id ).nodeName.toLowerCase() == "select" ) 857 { 858 var select_el = Dom.get( id ); 859 temp_el = select_el; 860 if ( select_el.value != 0 ) 861 { 862 count++; 863 } 864 } 865 } 866 867 if ( count == 0 ) 868 { 869 throw { 870 id: temp_el.id, 871 message: obj.messages.interest_required, 872 location: obj.error_msg_location 873 } 874 } 875 876 return true; 877 } 878
879 this.NwValidatorString = function( obj ) 880 { 881 var el = Dom.get( obj.id ); 882 var text = el.value; 883 text = this.clean( obj, el ); 884 885 if ( text == "" ) 886 { 887 return true; 888 } 889 890 var invalid = __("hiba"); 891 892 if ( obj.messages.invalid ) 893 { 894 invalid = obj.messages.invalid; 895 } 896 897 var min_length = invalid, 898 max_length = invalid; 899 900 if ( obj.messages.min_length ) 901 { 902 min_length = obj.messages.min_length; 903 } 904 905 if ( obj.messages.max_length ) 906 { 907 max_length = obj.messages.max_length; 908 } 909 910 if ( obj.options.min_length && text.length < obj.options.min_length ) 911 { 912 min_length = min_length.replace( "%min_length%", obj.options.min_length ); 913 throw { 914 id: obj.id, 915 message: min_length, 916 location: obj.error_msg_location 917 } 918 } 919 920 if ( obj.options.max_length && text.length > obj.options.max_length ) 921 { 922 max_length = max_length.replace( "%max_length%", obj.options.max_length ); 923 throw { 924 id: obj.id, 925 message: max_length, 926 location: obj.error_msg_location 927 } 928 } 929 930 return true; 931 } 932 this.NwValidatorUrl = function( obj ) 933 { 934 return true; 935 } 936 /** 937 * additional data validator 938 * @param {Object} obj 939 */ 940 this.NwValidatorAdditionalData = function( obj ) 941 { 942 var el_field = Dom.get( obj.id + "_field" ); 943 var el_value = Dom.get( obj.id + "_value" ); 944 if ( !el_field || !el_value ) 945 { 946 throw { 947 id: obj.id, 948 message: obj.messages.invalid, 949 location: obj.error_msg_location 950 } 951 } 952 953 if( el_field.value == "" && el_value.value.length > 0 ) 954 { 955 throw { 956 id: obj.id, 957 message: obj.messages.invalid, 958 location: obj.error_msg_location 959 } 960 } 961 return true; 962 } 963 964 this.sfValidatorPHPCaptcha = function( obj ) 965 { 966 var el = Dom.get( obj.id ); 967 var text = el.value; 968 text = this.clean( obj, el ); 969 970 return true; 971 } 972 /** 973 * integer validator 974 * 975 * @param {Object} obj 976 */ 977 this.sfValidatorInteger = function( obj ) 978 { 979 var el = Dom.get( obj.id ); 980 var text = el.value; 981 text = this.clean( obj, el ); 982 983 if ( text == "" ) 984 { 985 return true; 986 } 987 988 var invalid = __("hiba"); 989 990 if ( obj.messages.invalid ) 991 { 992 invalid = obj.messages.invalid; 993 } 994 995 var min = invalid, 996 max = invalid; 997 998 if ( obj.messages.min ) 999 { 1000 min = obj.messages.min; 1001 } 1002 1003 if ( obj.messages.max ) 1004 { 1005 max = obj.messages.max; 1006 } 1007 1008 if ( parseInt( text ) != text ) 1009 { 1010 throw { 1011 id: obj.id, 1012 message: invalid, 1013 location: obj.error_msg_location 1014 } 1015 } 1016 1017 if ( obj.options.min && parseInt( text ) < obj.options.min ) 1018 { 1019 min = min.replace( "%min%", obj.options.min ); 1020 throw { 1021 id: obj.id, 1022 message: min, 1023 location: obj.error_msg_location 1024 } 1025 } 1026 1027 if ( obj.options.max && parseInt( text ) > obj.options.max ) 1028 { 1029 max = max.replace( "%max%", obj.options.max ); 1030 throw { 1031 id: obj.id, 1032 message: max, 1033 location: obj.error_msg_location 1034 } 1035 } 1036 1037 return true; 1038 } 1039 1040 /** 1041 * boolean validator 1042 * @param {Object} obj 1043 */ 1044 this.sfValidatorBoolean = function( obj ) 1045 { 1046 var el = Dom.get( obj.id ); 1047 this.clean( obj, el ); 1048 1049 var true_values = new Array( 'true', 't', 'yes', 'y', 'on', '1' ); 1050 if ( obj.options.true_values ) 1051 { 1052 true_values = obj.options.true_values; 1053 } 1054 1055 var false_values = new Array( 'false', 'f', 'no', 'n', 'off', '0' ); 1056 if ( obj.options.false_values ) 1057 { 1058 false_values = obj.options.false_values; 1059 } 1060 1061 if( el.type == "text" ) 1062 { 1063 for ( i=0; i<=true_values.length; i++ ) 1064 { 1065 if( text == true_values[i] ) 1066 { 1067 return true; 1068 } 1069 } 1070 1071 for ( i=0; i<=false_values.length; i++ ) 1072 { 1073 if( text == false_values[i] ) 1074 { 1075 return false; 1076 } 1077 } 1078 1079 return false;
1080 } 1081 else if( el.type == "checkbox" ) 1082 { 1083 if( el.checked ) 1084 { 1085 return true; 1086 } 1087 else if( !el.checked ) 1088 { 1089 throw { 1090 id: obj.id, 1091 message: obj.messages.invalid, 1092 location: obj.error_msg_location 1093 } 1094 } 1095 } 1096 1097 throw { 1098 id: obj.id, 1099 message: obj.messages.invalid, 1100 location: obj.error_msg_location 1101 } 1102 } 1103 1104 /** 1105 * password validator 1106 * @param {Object} obj 1107 */ 1108 this.sfValidatorPass = function( obj ) 1109 { 1110 var el = Dom.get( obj.id ); 1111 var text = el.value; 1112 text = this.clean( obj, el ); 1113 1114 return true; 1115 } 1116 1117 /** 1118 * e-mail validator 1119 * @param {Object} obj 1120 */ 1121 this.sfValidatorEmail = function( obj ) 1122 { 1123 var el = Dom.get( obj.id ); 1124 var text = el.value; 1125 text = this.clean( obj, el ); 1126 1127 if ( text == "" ) 1128 { 1129 return true; 1130 } 1131 1132 var emailPattern = /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/; 1133 1134 if( !emailPattern.test( text ) ) 1135 { 1136 throw { 1137 id: obj.id, 1138 message: obj.messages.invalid, 1139 location: obj.error_msg_location 1140 } 1141 } 1142 1143 return true; 1144 } 1145 1146 /** 1147 * empty field validator 1148 * @param {Object} obj 1149 */ 1150 this.sfValidatorEmptyField = function( obj ) 1151 { 1152 if( obj.id.split("_")[1].substr(0,5) == "field" && id.value == "" ) 1153 { 1154 if( document.getElementById( id.split("_")[0] + "_value" + id.split("_")[1].substr(5) ).value.length > 0 ) 1155 { 1156 throw { 1157 id: obj.id, 1158 message: empty, 1159 location: obj.error_msg_location 1160 } 1161 } 1162 } 1163 return true; 1164 } 1165 1166 /** 1167 * file validator empty 1168 * @param {Object} obj 1169 */ 1170 this.sfValidatorFile = function( obj ) 1171 { 1172 return true; 1173 } 1174 1175 /** 1176 * string validator 1177 * @param {Object} obj 1178 */ 1179 this.sfValidatorString = function( obj ) 1180 { 1181 var el = Dom.get( obj.id ); 1182 var text = el.value; 1183 text = this.clean( obj, el ); 1184 1185 if ( text == "" ) 1186 { 1187 return true; 1188 } 1189 1190 var invalid = __( "hiba" ); 1191 1192 if ( obj.messages.invalid ) 1193 { 1194 invalid = obj.messages.invalid; 1195 } 1196 1197 var min_length = invalid, 1198 max_length = invalid; 1199 1200 if ( obj.messages.min_length ) 1201 { 1202 min_length = obj.messages.min_length; 1203 } 1204 1205 if ( obj.messages.max_length ) 1206 { 1207 max_length = obj.messages.max_length; 1208 } 1209 1210 if ( obj.options.min_length && text.length < obj.options.min_length ) 1211 { 1212 min_length = min_length.replace( "%min%", obj.options.min_length ); 1213 throw { 1214 id: obj.id, 1215 message: min_length, 1216 location: obj.error_msg_location 1217 } 1218 } 1219 1220 if ( obj.options.max_length && text.length > obj.options.max_length ) 1221 { 1222 max_length = max_length.replace( "%max%", obj.options.max_length ); 1223 throw { 1224 id: obj.id, 1225 message: max_length, 1226 location: obj.error_msg_location 1227 } 1228 } 1229 1230 return true; 1231 } 1232 1233 /** 1234 * url validator 1235 * @param {Object} obj 1236 */ 1237 this.sfValidatorUrl = function( obj ) 1238 { 1239 var el = Dom.get( obj.id ); 1240 var text = el.value; 1241 text = this.clean( obj, el ); 1242 1243 if ( text == "" ) 1244 { 1245 return true; 1246 } 1247 1248 var urlPattern = /^(https?|ftps?):\/\/(([a-z0-9-]+\.)+[a-z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(:[0-9]+)?(\/?|\/\S+)$/i; 1249 1250 if( !urlPattern.test( text ) ) 1251 { 1252 throw { 1253 id: obj.id, 1254 message: obj.messages.invalid, 1255 location: obj.error_msg_location 1256 } 1257 } 1258 1259 return true; 1260 } 1261 1262 /** 1263 * number validator 1264 * @param {Object} obj 1265 */ 1266 this.sfValidatorNumber = function( obj ) 1267 { 1268 var el = Dom.get( obj.id ); 1269 1270 var invalid = __( "hiba" ); 1271 1272 if ( obj.messages.invalid ) 1273 { 1274 invalid = obj.messages.invalid; 1275 } 1276 1277 var min = invalid, 1278 max = invalid; 1279 1280 if ( obj.messages.min ) 1281 { 1282 min = obj.messages.min; 1283 } 1284 1285 if ( obj.messages.max ) 1286 { 1287 max = obj.messages.max; 1288 } 1289 1290 elm = document.getElementById( obj.id + "_1" ); 1291 if ( elm && elm.type == "radio" ) 1292 { 1293 var idname, idnum = 1; 1294 while ( idname = document.getElementById( "BaseData_v_sex_" + idnum ) ) 1295 { 1296 if ( idname.checked ) 1297 { 1298 if ( ( min && idname.value >= obj.options.min ) && ( max && idname.value <= obj.options.max ) ) 1299 { 1300 return true; 1301 } 1302 else 1303 { 1304 throw { 1305 id: obj.id, 1306 message: invalid, 1307 location: obj.error_msg_location 1308 } 1309 } 1310 } 1311 idnum ++; 1312 } 1313 throw { 1314 id: obj.id, 1315 message: obj.messages.required, 1316 location: obj.error_msg_location 1317 } 1318 } 1319 else 1320 { 1321 var el = Dom.get( obj.id ); 1322 var text = el.value; 1323 text = this.clean( obj, el ); 1324 1325 if ( parseFloat( text ) != text ) 1326 { 1327 throw { 1328 id: obj.id, 1329 message: invalid, 1330 location: obj.error_msg_location 1331 } 1332 } 1333 1334 if ( obj.options.min && parseFloat( text ) < parseFloat( obj.options.min ) ) 1335 { 1336 min = min.replace( "%min%", obj.options.min ); 1337 throw { 1338 id: obj.id, 1339 message: min, 1340 location: obj.error_msg_location 1341 } 1342 } 1343 1344 if ( obj.options.max && parseFloat( text ) > parseFloat( obj.options.max ) ) 1345 { 1346 max = max.replace( "%max%", obj.options.max ); 1347 throw { 1348 id: obj.id, 1349 message: max, 1350 location: obj.error_msg_location 1351 } 1352 } 1353 1354 return true; 1355 } 1356 } 1357 1358 /** 1359 * date validator 1360 * @param {Object} obj 1361 */ 1362 this.sfValidatorDate = function( obj ) 1363 { 1364 if ( obj.options.with_time ) 1365 { 1366 var i_length = 6; 1367 } 1368 else 1369 { 1370 var i_length = 3; 1371 } 1372 1373 var date_names = new Array( "year", "month", "day", "hour", "minute", "second" ); 1374 1375 var year_id = obj.id+'_year';
1376 var month_id = obj.id+'_month'; 1377 var day_id = obj.id+'_day'; 1378 var hour_id = obj.id + '_hour'; 1379 var minute_id = obj.id + '_minute'; 1380 var second_id = obj.id + '_second'; 1381 1382 var year_value, 1383 month_value, 1384 day_value, 1385 hour_value, 1386 minute_value, 1387 second_value; 1388 1389 for ( i = 0; i < i_length; i++ ) 1390 { 1391 var id = eval( date_names[i]+"_id" ); 1392 if ( Dom.get( id ).nodeName.toLowerCase() == "input" ) 1393 { 1394 eval( date_names[i]+"_value = Dom.get( id ).value" ); 1395 } 1396 else 1397 { 1398 var selectedIndex = Dom.get( id ).selectedIndex; 1399 var options = Dom.get( id ).getElementsByTagName( "option" ); 1400 eval( date_names[i]+"_value = options[selectedIndex].value" ); 1401 } 1402 } 1403 1404 if ( obj.options.required ) 1405 { 1406 for( i=0; i < i_length; i++ ) 1407 { 1408 if( eval( date_names[i]+"_value" ) == '' ) 1409 { 1410 throw { 1411 id: obj.id, 1412 message: obj.messages.required, 1413 location: obj.error_msg_location 1414 } 1415 } 1416 } 1417 } 1418 1419 for ( i = 0; i < i_length; i++ ) 1420 { 1421 if ( parseInt( eval( date_names[i]+"_value" ) ) != eval( date_names[i]+"_value" ) && eval( date_names[i]+"_value" ) != "" ) 1422 { 1423 throw { 1424 id: obj.id+"_"+date_names[i], 1425 message: obj.messages.invalid, 1426 location: obj.error_msg_location 1427 } 1428 } 1429 } 1430 1431 1432 var date; 1433 if ( parseInt( month_value ).toString() == "NaN" || parseInt( month_value ) == 0 ) 1434 { 1435 month_value = 0; 1436 } 1437 else 1438 { 1439 month_value = parseInt( month_value )-1; 1440 } 1441 1442 if ( i_length == 3 ) 1443 { 1444 date = new Date( year_value, month_value, day_value ); 1445 } 1446 else if ( i_length == 6 ) 1447 { 1448 date = new Date( year_value, month_value, day_value, hour_value, minute_value, second_value ); 1449 } 1450 1451 if ( date.toString() == "Invalid Date" ) 1452 { 1453 throw { 1454 id: obj.id+"_year", 1455 message: obj.messages.invalid, 1456 location: obj.error_msg_location 1457 } 1458 } 1459 1460 Dom.get( year_id ).value = date.getFullYear(); 1461 Dom.get( month_id ).value = date.getMonth()+1; 1462 Dom.get( day_id ).value = date.getDate(); 1463 1464 return true; 1465 } 1466 1467 /** 1468 * regex validator 1469 * @param {Object} obj 1470 */ 1471 this.sfValidatorRegex = function( obj ) 1472 { 1473 var el = Dom.get( obj.id ); 1474 var text = el.value; 1475 text = this.clean( obj, el ); 1476 1477 if ( text == "" ) 1478 { 1479 return true; 1480 } 1481 1482 var reg = new RegExp( eval( obj.options.pattern ) ); 1483 if( !reg.test( text ) ) 1484 { 1485 throw { 1486 id: obj.id, 1487 message: obj.messages.invalid, 1488 location: obj.error_msg_location 1489 } 1490 } 1491 1492 return true; 1493 } 1494 1495 /** 1496 * choice validator 1497 * @param {Object} obj 1498 */ 1499 this.sfValidatorChoice = function( obj ) 1500 { 1501 var el = Dom.get( obj.id ); 1502 1503 //if radio 1504 if ( !el ) 1505 { 1506 if ( obj.options.choices ) 1507 { 1508 var radio_els = []; 1509 for ( i_choice = 0; i_choice < obj.options.choices.length; i_choice++ ) 1510 { 1511 var act_choice = obj.options.choices[ i_choice ]; 1512 var id = obj.id + "_" + act_choice; 1513 var radio_el = Dom.get( id ); 1514 if ( radio_el ) 1515 { 1516 radio_els.push( radio_el ); 1517 } 1518 } 1519 1520 var is_checked = false; 1521 1522 for ( i_radio = 0; i_radio < radio_els.length; i_radio++ ) 1523 { 1524 var act_radio_el = radio_els[ i_radio ]; 1525 if ( act_radio_el.checked ) 1526 { 1527 is_checked = true; 1528 } 1529 } 1530 1531 if ( is_checked ) 1532 { 1533 return true; 1534 } 1535 else 1536 { 1537 throw { 1538 id: obj.id, 1539 message: obj.messages.required, 1540 location: obj.error_msg_location 1541 } 1542 } 1543 } 1544 } 1545 1546 if ( el.type == "checkbox" ) 1547 { 1548 if ( obj.options.required ) 1549 { 1550 if ( !el.checked ) 1551 { 1552 throw { 1553 id: obj.id, 1554 message: obj.messages.required, 1555 location: obj.error_msg_location 1556 } 1557 } 1558 } 1559 1560 return true; 1561 } 1562 optionTags = el.getElementsByTagName( 'option' ); 1563 selIndex = el.selectedIndex; 1564 1565 for ( i=0; i<obj.options.choices.length; i++ ) 1566 { 1567 if( optionTags[selIndex].value == obj.options.choices[i] ) 1568 { 1569 return true; 1570 } 1571 else if( i == ( obj.options.choices.length-1 ) ) 1572 { 1573 throw { 1574 id: obj.id, 1575 message: obj.messages.invalid, 1576 location: obj.error_msg_location 1577 } 1578 } 1579 } 1580 } 1581 1582 /** 1583 * choiceMany validator 1584 * @param {Object} obj 1585 */ 1586 this.sfValidatorChoiceMany = function( obj ) 1587 { 1588 var el = Dom.get( obj.id ); 1589 1590 this.clean( obj, el ); 1591 1592 var optionTags = el.getElementsByTagName( 'option'); 1593 var selIndex = el.selectedIndex; 1594 1595 for ( i=selIndex; i<optionTags.length; i++ ) 1596 { 1597 for( j=0; j<obj.options.choices.length; j++ ) 1598 { 1599 if( optionTags[i].selected == true ) 1600 { 1601 if ( optionTags[i].value == obj.options.choices[j] ) 1602 { 1603 break; 1604 } 1605 else if ( j == ( obj.options.choices.length - 1 ) ) 1606 { 1607 throw { 1608 id: obj.id, 1609 message: obj.messages.invalid, 1610 location: obj.error_msg_location 1611 } 1612 } 1613 } 1614 } 1615 } 1616 return true; 1617 } 1618 1619 /** 1620 * schemaCompare validator 1621 * @param {Object} obj 1622 */ 1623 this.sfValidatorSchemaCompare = function( obj ) 1624 { 1625 var left_field = obj.options.left_field; 1626 var el_left = Dom.get( left_field ); 1627 var leftValue = el_left.value; 1628 leftValue = this.clean( obj, el_left ); 1629 1630 var right_field = obj.options.right_field; 1631 var el_right = Dom.get( right_field ); 1632 var rightValue = el_right.value; 1633 rightValue = this.clean( obj, el_right ); 1634
1635 var valid; 1636 1637 if( !el_left || !el_right ) 1638 { 1639 throw { 1640 id: obj.id, 1641 message: obj.messages.invalid, 1642 location: obj.error_msg_location 1643 } 1644 } 1645 1646 switch ( obj.options.operator ) 1647 { 1648 case "greater_than" : 1649 valid = leftValue > rightValue; 1650 break; 1651 case "greater_than_equal" : 1652 valid = leftValue >= rightValue; 1653 break; 1654 case "less_than" : 1655 valid = leftValue < rightValue; 1656 break; 1657 case "less_than_equal" : 1658 valid = leftValue <= rightValue; 1659 break; 1660 case "not_equal" : 1661 valid = leftValue != rightValue; 1662 break; 1663 case "equal" : 1664 default: 1665 valid = leftValue == rightValue; 1666 } 1667 1668 if( !valid ) 1669 { 1670 throw { 1671 id: el_left.id, 1672 message: obj.messages.invalid, 1673 location: obj.error_msg_location 1674 } 1675 } 1676 else 1677 { 1678 return true; 1679 } 1680 } 1681 1682 /** 1683 * e-mail validator 1684 * @param {Object} obj 1685 */ 1686 this.NwValidatorEmailServerCheck = function( obj ) 1687 { 1688 try 1689 { 1690 this.NwValidatorRegEmail( obj ); 1691 } 1692 catch( e ) 1693 { 1694 throw e; 1695 } 1696 1697 return true; 1698 } 1699 1700 this.NwValidatorClubCampaignEmail = function( obj ) 1701 { 1702 return true; 1703 } 1704 1705 this.clean = function( obj, el ) 1706 { 1707 var text; 1708 if ( el.type == "text" || el.type == "password" || el.nodeName.toLowerCase() == "textarea" ) 1709 { 1710 text = el.value; 1711 } 1712 1713 if ( obj.options ) 1714 { 1715 if ( obj.options.trim ) 1716 { 1717 if ( el.type == "text" || el.type == "password" || el.nodeName.toLowerCase() == "textarea" ) 1718 { 1719 text = YAHOO.lang.trim( text ); 1720 Dom.get( obj.id ).value = text; 1721 } 1722 1723 } 1724 1725 if ( obj.options.required ) 1726 { 1727 if ( ( el.type == "text" || el.type == "password"|| el.nodeName.toLowerCase() == "textarea" ) && text == "" ) 1728 { 1729 throw { 1730 id: el.id, 1731 message: obj.messages.required, 1732 location: obj.error_msg_location 1733 } 1734 } 1735 else if ( el.nodeName.toLowerCase() == "select" ) 1736 { 1737 if ( el.selectedIndex == -1 ) 1738 { 1739 throw { 1740 id: el.id, 1741 message: obj.messages.required, 1742 location: obj.error_msg_location 1743 } 1744 } 1745 } 1746 else if ( el.type == "checkbox" && !el.checked ) 1747 { 1748 throw { 1749 id: el.id, 1750 message: obj.messages.required, 1751 location: obj.error_msg_location 1752 } 1753 } 1754 } 1755 } 1756 1757 return text; 1758 } 1759 1760 this._init(); 1761} 1762 1763var email_validator = 1764{ 1765 email_validator_unit_class: function() 1766 { 1767 this.el = null; 1768 this.ajax_url = ""; 1769 this.last_value = ""; 1770 }, 1771 1772 setEmailValidatorUnitClass: function() 1773 { 1774 this.email_validator_unit_class.prototype = 1775 { 1776 _construct: function( el, url ) 1777 { 1778 this.el = el; 1779 this.ajax_url = url; 1780 1781 return true; 1782 }, 1783 1784 ajax_validate: null, 1785 1786 validate: function() 1787 { 1788 if ( this.el.value == "" ) 1789 { 1790 return true; 1791 } 1792 1793 if ( this.last_value == this.el.value ) 1794 { 1795 return true; 1796 } 1797 1798 //remove default errormessage 1799 try 1800 { 1801 errorHandlers.hideErrorMsg( this.el ); 1802 } 1803 catch( e ) 1804 { 1805 } 1806 1807 this.ajax_validate = this.ajax_validate || new n_ajax_class( this.ajax_url, this.el, this.validateCallback, null, "post" ); 1808 this.ajax_validate.handleDefaultError = this.handleDefaultError; 1809 this.ajax_validate.postData = "email=" + this.el.value; 1810 1811 this.ajax_validate.send( this ); 1812 return true; 1813 }, 1814 1815 handleDefaultError: function( message ) 1816 { 1817 this.last_value = this.el.value; 1818 errorHandlers.showErrorMsg( this.el.id, message ); 1819 1820 return true; 1821 }, 1822 1823 validateCallback: function( o ) 1824 { 1825 this.last_value = this.el.value; 1826 1827 if ( !this.ajax_validate.json_response ) 1828 { 1829 return true; 1830 } 1831 1832 var json = this.ajax_validate.json_response; 1833 1834 if ( !json.email ) 1835 { 1836 return true; 1837 } 1838 1839 Dom.get( "emailsuggest_original" ).innerHTML = json.email.original; 1840 Dom.get( "emailsuggest_suggested" ).innerHTML = json.email.guess; 1841 1842 email_validator.actual_unit = this; 1843 nw.openLight( "emailsuggest_dialog" ); 1844 1845 return true; 1846 } 1847 } 1848 }, 1849 1850 email_validator_class: function() 1851 { 1852 this.units = []; 1853 }, 1854
1855 setEmailValidatorClass: function() 1856 { 1857 this.email_validator_class.prototype = 1858 { 1859 getUnitById: function( el ) 1860 { 1861 for ( i_unit = 0; i_unit < this.units.length; i_unit++ ) 1862 { 1863 var act_unit = this.units[ i_unit ]; 1864 if ( act_unit.el == el ) 1865 { 1866 return act_unit; 1867 } 1868 } 1869 }, 1870 1871 add: function( el, url ) 1872 { 1873 if ( !this.getUnitById( el ) ) 1874 { 1875 var unit = new email_validator.email_validator_unit_class(); 1876 unit._construct( el, url ); 1877 this.units.push( unit ); 1878 return true; 1879 } 1880 } 1881 } 1882 }, 1883 1884 handler_class: null, 1885 1886 initClass: function( input_el, url ) 1887 { 1888 if ( !this.handler_class ) 1889 { 1890 this.handler_class = new this.email_validator_class(); 1891 } 1892 1893 this.handler_class.add( input_el, url ); 1894 return true; 1895 }, 1896 1897 initClassWithAlert: function( input_el, url ) 1898 { 1899 this.initClass( input_el, url ); 1900 1901 var unit = this.getUnit( input_el ); 1902 unit.handleDefaultError = function( message ) 1903 { 1904 this.last_value = this.el.value; 1905 nw.alert( message ); 1906 n_emailinvitation.showStepOne(); 1907 1908 return true; 1909 } 1910 1911 unit.validateCallback = function( o ) 1912 { 1913 this.last_value = this.el.value; 1914 1915 if ( !this.ajax_validate.json_response ) 1916 { 1917 return true; 1918 } 1919 1920 var json = this.ajax_validate.json_response; 1921 1922 if ( !json.email ) 1923 { 1924 return true; 1925 } 1926 1927 n_emailinvitation.showStepOne(); 1928 Dom.get( "emailsuggest_original" ).innerHTML = json.email.original; 1929 Dom.get( "emailsuggest_suggested" ).innerHTML = json.email.guess; 1930 1931 email_validator.actual_unit = this; 1932 nw.openLight( "emailsuggest_dialog" ); 1933 1934 return true; 1935 } 1936 1937 return true; 1938 }, 1939 1940 getUnit: function( input_el ) 1941 { 1942 return this.handler_class.getUnitById( input_el ); 1943 }, 1944 1945 1946 //interface 1947 validate: function( input_el, url ) 1948 { 1949 this.initClass( input_el, url ); 1950 var unit = this.getUnit( input_el ); 1951 unit.validate(); 1952 1953 return true; 1954 }, 1955 1956 validateWithAlert: function( input_el, url ) 1957 { 1958 this.initClassWithAlert( input_el, url ); 1959 var unit = this.getUnit( input_el ); 1960 unit.validate(); 1961 1962 return true; 1963 }, 1964 1965 actual_unit: null, 1966 1967 acceptSuggested: function() 1968 { 1969 this.actual_unit.el.value = Dom.get( "emailsuggest_suggested" ).innerHTML; 1970 this.actual_unit.last_value = Dom.get( "emailsuggest_suggested" ).innerHTML; 1971 nw.hideLight( 'emailsuggest_dialog' ); return false; 1972 1973 return true; 1974 } 1975} 1976 1977email_validator.setEmailValidatorClass(); 1978email_validator.setEmailValidatorUnitClass(); 1979 1980var date_validator_unit_class = function() 1981{ 1982 1983} 1984 1985date_validator_unit_class.prototype = 1986{ 1987 id: "", 1988 year_el: null, 1989 month_el: null, 1990 day_el: null, 1991 1992 construct: function( id ) 1993 { 1994 this.id = id; 1995 this.year_el = Dom.get( id + "_year"); 1996 this.month_el = Dom.get( id + "_month"); 1997 this.day_el = Dom.get( id + "_day"); 1998 1999 return true; 2000 }, 2001 2002 setValidDay: function() 2003 { 2004 var year = this.year_el.value; 2005 var month = parseInt( this.month_el.value ) - 1; 2006 var selected_date = new Date(); 2007 var new_day_length = 0; 2008 var orig_day_length = $( "OPTION", this.day_el ).length; 2009 var orig_selected_day = this.day_el.value; 2010 2011 for ( i_day = 29; i_day <= 32; i_day++ ) 2012 { 2013 selected_date.setFullYear( year, month, i_day ); 2014 var new_month = selected_date.getMonth(); 2015 if ( new_month != month ) 2016 { 2017 new_day_length = i_day - 1; 2018 break; 2019 } 2020 } 2021 2022 //if orig is more 2023 if ( orig_day_length > new_day_length ) 2024 { 2025 var diff = orig_day_length - new_day_length; 2026 2027 for ( i_diff = 1; i_diff <= diff; i_diff++ ) 2028 { 2029 var day_els = $( "OPTION", this.day_el ); 2030 var last_day_el = day_els[ day_els.length - 1 ]; 2031 last_day_el.parentNode.removeChild( last_day_el ); 2032 } 2033 } 2034 else if ( orig_day_length < new_day_length ) 2035 { 2036 //if orig is less 2037 var diff = new_day_length - orig_day_length; 2038 2039 for ( i_diff = 1; i_diff <= diff; i_diff++ ) 2040 { 2041 var day_els = $( "OPTION", this.day_el ); 2042 var new_option_el = document.createElement( "option" ); 2043 var last_day = day_els.length; 2044 new_option_el.value = last_day + 1; 2045 new_option_el.innerHTML = last_day + 1; 2046 2047 this.day_el.appendChild( new_option_el ); 2048 } 2049 } 2050 2051 //if previously selected day is higher than this month days length 2052 var days = $( "OPTION", this.day_el ); 2053 if ( orig_selected_day > days.length ) 2054 { 2055 console.log( "nagyobb" ); 2056 days[ days.length - 1 ].selected = true; 2057 } 2058 2059 return true; 2060 } 2061} 2062 2063var date_validator_class = function() 2064{ 2065 2066} 2067 2068date_validator_class.prototype = 2069{ 2070 units: [], 2071 2072 getUnitById: function( id ) 2073 { 2074 for ( i_unit = 0; i_unit < this.units.length; i_unit++ ) 2075 { 2076 var act_unit = this.units[ i_unit ]; 2077 if ( id == act_unit.id ) 2078 { 2079 return act_unit; 2080 } 2081 } 2082 2083 return false;
2084 }, 2085 2086 add: function( id ) 2087 { 2088 if ( !this.getUnitById( id ) ) 2089 { 2090 var unit = new date_validator_unit_class(); 2091 unit.construct( id ); 2092 this.units.push( unit ); 2093 return unit; 2094 } 2095 else 2096 { 2097 return this.getUnitById( id ); 2098 } 2099 } 2100} 2101 2102var date_validator = 2103{ 2104 handler_class: null, 2105 2106 initHandlerClass: function( id ) 2107 { 2108 this.handler_class = this.handler_class || new date_validator_class(); 2109 var unit = this.handler_class.add( id ); 2110 2111 return unit; 2112 }, 2113 2114 /** 2115 * @description set elements of the given day select list depending on the selected year and month 2116 * @param {HTMLelement} select_el this can be the yeat select list, or the month select list 2117 */ 2118 setValidDay: function( select_el ) 2119 { 2120 var select_id = select_el.id; 2121 var raw_id = ""; 2122 var a_select_id = select_id.split( "_" ); 2123 a_select_id.pop(); 2124 raw_id = a_select_id.join( "_" ); 2125 2126 var unit = this.initHandlerClass( raw_id ); 2127 unit.setValidDay(); 2128 2129 return true; 2130 } 2131}
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.