Subversion Repositories SmartDukaan

Rev

Rev 1035 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1035 Rev 1252
Line 13... Line 13...
13
 *   http://www.gnu.org/licenses/gpl.html
13
 *   http://www.gnu.org/licenses/gpl.html
14
 */
14
 */
15
 
15
 
16
(function($) {
16
(function($) {
17
 
17
 
18
$.extend($.fn, {
18
  $.extend($.fn, {
19
	// http://docs.jquery.com/Plugins/Validation/validate
19
    // http://docs.jquery.com/Plugins/Validation/validate
20
	validate: function( options ) {
20
    validate: function( options ) {
21
		
21
		
22
		// if nothing is selected, return nothing; can't chain anyway
22
      // if nothing is selected, return nothing; can't chain anyway
23
		if (!this.length) {
23
      if (!this.length) {
24
			options && options.debug && window.console && console.warn( "nothing selected, can't validate, returning nothing" );
24
        options && options.debug && window.console && console.warn( "nothing selected, can't validate, returning nothing" );
25
			return;
25
        return;
26
		}
26
      }
27
		
27
		
28
		// check if a validator for this form was already created
28
      // check if a validator for this form was already created
29
		var validator = $.data(this[0], 'validator');
29
      var validator = $.data(this[0], 'validator');
30
		if ( validator ) {
30
      if ( validator ) {
31
			return validator;
31
        return validator;
32
		}
32
      }
33
		
33
		
34
		validator = new $.validator( options, this[0] );
34
      validator = new $.validator( options, this[0] );
35
		$.data(this[0], 'validator', validator); 
35
      $.data(this[0], 'validator', validator);
36
		
36
		
37
		if ( validator.settings.onsubmit ) {
37
      if ( validator.settings.onsubmit ) {
38
		
38
		
39
			// allow suppresing validation by adding a cancel class to the submit button
39
        // allow suppresing validation by adding a cancel class to the submit button
40
			this.find("input, button").filter(".cancel").click(function() {
40
        this.find("input, button").filter(".cancel").click(function() {
41
				validator.cancelSubmit = true;
41
          validator.cancelSubmit = true;
42
			});
42
        });
43
		
43
		
44
			// validate the form on submit
44
        // validate the form on submit
45
			this.submit( function( event ) {
45
        this.submit( function( event ) {
46
				if ( validator.settings.debug )
46
          if ( validator.settings.debug )
47
					// prevent form submit to be able to see console output
47
            // prevent form submit to be able to see console output
48
					event.preventDefault();
48
            event.preventDefault();
49
					
49
					
50
				function handle() {
50
          function handle() {
51
					if ( validator.settings.submitHandler ) {
51
            if ( validator.settings.submitHandler ) {
52
						validator.settings.submitHandler.call( validator, validator.currentForm );
52
              validator.settings.submitHandler.call( validator, validator.currentForm );
53
						return false;
53
              return false;
54
					}
54
            }
55
					return true;
55
            return true;
56
				}
56
          }
57
					
57
					
58
				// prevent submit for invalid forms or custom submit handlers
58
          // prevent submit for invalid forms or custom submit handlers
59
				if ( validator.cancelSubmit ) {
59
          if ( validator.cancelSubmit ) {
60
					validator.cancelSubmit = false;
60
            validator.cancelSubmit = false;
61
					return handle();
61
            return handle();
62
				}
62
          }
63
				if ( validator.form() ) {
63
          if ( validator.form() ) {
64
					if ( validator.pendingRequest ) {
64
            if ( validator.pendingRequest ) {
65
						validator.formSubmitted = true;
65
              validator.formSubmitted = true;
66
						return false;
66
              return false;
67
					}
67
            }
68
					return handle();
68
            return handle();
69
				} else {
69
          } else {
70
					validator.focusInvalid();
70
            validator.focusInvalid();
71
					return false;
71
            return false;
72
				}
72
          }
73
			});
73
        });
74
		}
74
      }
75
		
75
		
76
		return validator;
76
      return validator;
77
	},
77
    },
78
	// http://docs.jquery.com/Plugins/Validation/valid
78
    // http://docs.jquery.com/Plugins/Validation/valid
79
	valid: function() {
79
    valid: function() {
80
        if ( $(this[0]).is('form')) {
80
      if ( $(this[0]).is('form')) {
81
            return this.validate().form();
81
        return this.validate().form();
82
        } else {
82
      } else {
83
            var valid = false;
83
        var valid = false;
84
            var validator = $(this[0].form).validate();
84
        var validator = $(this[0].form).validate();
85
            this.each(function() {
85
        this.each(function() {
86
				valid |= validator.element(this);
86
          valid |= validator.element(this);
-
 
87
        });
-
 
88
        return valid;
-
 
89
      }
-
 
90
    },
-
 
91
    // attributes: space seperated list of attributes to retrieve and remove
-
 
92
    removeAttrs: function(attributes) {
-
 
93
      var result = {},
-
 
94
      $element = this;
-
 
95
      $.each(attributes.split(/\s/), function(index, value) {
-
 
96
        result[value] = $element.attr(value);
-
 
97
        $element.removeAttr(value);
-
 
98
      });
-
 
99
      return result;
-
 
100
    },
-
 
101
    // http://docs.jquery.com/Plugins/Validation/rules
-
 
102
    rules: function(command, argument) {
-
 
103
      var element = this[0];
-
 
104
		
-
 
105
      if (command) {
-
 
106
        var settings = $.data(element.form, 'validator').settings;
-
 
107
        var staticRules = settings.rules;
-
 
108
        var existingRules = $.validator.staticRules(element);
-
 
109
        switch(command) {
-
 
110
          case "add":
-
 
111
            $.extend(existingRules, $.validator.normalizeRule(argument));
-
 
112
            staticRules[element.name] = existingRules;
-
 
113
            if (argument.messages)
-
 
114
              settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
-
 
115
            break;
-
 
116
          case "remove":
-
 
117
            if (!argument) {
-
 
118
              delete staticRules[element.name];
-
 
119
              return existingRules;
-
 
120
            }
-
 
121
            var filtered = {};
-
 
122
            $.each(argument.split(/\s/), function(index, method) {
-
 
123
              filtered[method] = existingRules[method];
-
 
124
              delete existingRules[method];
87
            });
125
            });
88
            return valid;
126
            return filtered;
89
        }
127
        }
-
 
128
      }
-
 
129
		
-
 
130
      var data = $.validator.normalizeRules(
-
 
131
        $.extend(
-
 
132
        {},
-
 
133
          $.validator.metadataRules(element),
-
 
134
          $.validator.classRules(element),
-
 
135
          $.validator.attributeRules(element),
-
 
136
          $.validator.staticRules(element)
-
 
137
          ), element);
-
 
138
		
-
 
139
      // make sure required is at front
-
 
140
      if (data.required) {
-
 
141
        var param = data.required;
-
 
142
        delete data.required;
-
 
143
        data = $.extend({
-
 
144
          required: param
-
 
145
        }, data);
-
 
146
      }
-
 
147
		
-
 
148
      return data;
-
 
149
    }
-
 
150
  });
-
 
151
 
-
 
152
  // Custom selectors
-
 
153
  $.extend($.expr[":"], {
-
 
154
    // http://docs.jquery.com/Plugins/Validation/blank
-
 
155
    blank: function(a) {
-
 
156
      return !$.trim(a.value);
90
    },
157
    },
91
	// attributes: space seperated list of attributes to retrieve and remove
158
    // http://docs.jquery.com/Plugins/Validation/filled
92
	removeAttrs: function(attributes) {
159
    filled: function(a) {
93
		var result = {},
-
 
94
			$element = this;
-
 
95
		$.each(attributes.split(/\s/), function(index, value) {
-
 
96
			result[value] = $element.attr(value);
-
 
97
			$element.removeAttr(value);
160
      return !!$.trim(a.value);
98
		});
-
 
99
		return result;
-
 
100
	},
161
    },
101
	// http://docs.jquery.com/Plugins/Validation/rules
162
    // http://docs.jquery.com/Plugins/Validation/unchecked
102
	rules: function(command, argument) {
163
    unchecked: function(a) {
103
		var element = this[0];
-
 
104
		
-
 
105
		if (command) {
-
 
106
			var settings = $.data(element.form, 'validator').settings;
-
 
107
			var staticRules = settings.rules;
-
 
108
			var existingRules = $.validator.staticRules(element);
-
 
109
			switch(command) {
-
 
110
			case "add":
-
 
111
				$.extend(existingRules, $.validator.normalizeRule(argument));
-
 
112
				staticRules[element.name] = existingRules;
-
 
113
				if (argument.messages)
-
 
114
					settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
-
 
115
				break;
-
 
116
			case "remove":
-
 
117
				if (!argument) {
-
 
118
					delete staticRules[element.name];
-
 
119
					return existingRules;
-
 
120
				}
-
 
121
				var filtered = {};
-
 
122
				$.each(argument.split(/\s/), function(index, method) {
-
 
123
					filtered[method] = existingRules[method];
-
 
124
					delete existingRules[method];
-
 
125
				});
-
 
126
				return filtered;
164
      return !a.checked;
127
			}
165
    }
128
		}
-
 
129
		
-
 
130
		var data = $.validator.normalizeRules(
-
 
131
		$.extend(
-
 
132
			{},
-
 
133
			$.validator.metadataRules(element),
-
 
134
			$.validator.classRules(element),
-
 
135
			$.validator.attributeRules(element),
-
 
136
			$.validator.staticRules(element)
-
 
137
		), element);
-
 
138
		
-
 
139
		// make sure required is at front
-
 
140
		if (data.required) {
-
 
141
			var param = data.required;
-
 
142
			delete data.required;
-
 
143
			data = $.extend({required: param}, data);
-
 
144
		}
-
 
145
		
-
 
146
		return data;
-
 
147
	}
-
 
148
});
-
 
149
 
-
 
150
// Custom selectors
-
 
151
$.extend($.expr[":"], {
-
 
152
	// http://docs.jquery.com/Plugins/Validation/blank
-
 
153
	blank: function(a) {return !$.trim(a.value);},
-
 
154
	// http://docs.jquery.com/Plugins/Validation/filled
-
 
155
	filled: function(a) {return !!$.trim(a.value);},
-
 
156
	// http://docs.jquery.com/Plugins/Validation/unchecked
-
 
157
	unchecked: function(a) {return !a.checked;}
-
 
158
});
166
  });
159
 
167
 
160
 
168
 
161
$.format = function(source, params) {
169
  $.format = function(source, params) {
162
	if ( arguments.length == 1 ) 
170
    if ( arguments.length == 1 )
163
		return function() {
171
      return function() {
164
			var args = $.makeArray(arguments);
172
        var args = $.makeArray(arguments);
165
			args.unshift(source);
173
        args.unshift(source);
166
			return $.format.apply( this, args );
174
        return $.format.apply( this, args );
167
		};
175
      };
168
	if ( arguments.length > 2 && params.constructor != Array  ) {
176
    if ( arguments.length > 2 && params.constructor != Array  ) {
169
		params = $.makeArray(arguments).slice(1);
177
      params = $.makeArray(arguments).slice(1);
170
	}
178
    }
171
	if ( params.constructor != Array ) {
179
    if ( params.constructor != Array ) {
172
		params = [ params ];
180
      params = [ params ];
173
	}
181
    }
174
	$.each(params, function(i, n) {
182
    $.each(params, function(i, n) {
175
		source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
183
      source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
176
	});
184
    });
177
	return source;
185
    return source;
178
};
186
  };
179
 
187
 
180
// constructor for validator
188
  // constructor for validator
181
$.validator = function( options, form ) {
189
  $.validator = function( options, form ) {
182
	this.settings = $.extend( {}, $.validator.defaults, options );
190
    this.settings = $.extend( {}, $.validator.defaults, options );
183
	this.currentForm = form;
191
    this.currentForm = form;
184
	this.init();
192
    this.init();
185
};
193
  };
186
 
194
 
187
$.extend($.validator, {
195
  $.extend($.validator, {
188
 
196
 
189
	defaults: {
197
    defaults: {
190
		messages: {},
198
      messages: {},
191
		groups: {},
199
      groups: {},
192
		rules: {},
200
      rules: {},
193
		errorClass: "error",
201
      errorClass: "error",
194
		errorElement: "label",
202
      errorElement: "label",
195
		focusInvalid: true,
203
      focusInvalid: true,
196
		errorContainer: $( [] ),
204
      errorContainer: $( [] ),
197
		errorLabelContainer: $( [] ),
205
      errorLabelContainer: $( [] ),
198
		onsubmit: true,
206
      onsubmit: true,
199
		ignore: [],
207
      ignore: [],
200
		ignoreTitle: false,
208
      ignoreTitle: false,
201
		onfocusin: function(element) {
209
      onfocusin: function(element) {
202
			this.lastActive = element;
210
        this.lastActive = element;
203
				
211
				
204
			// hide error label and remove error class on focus if enabled
212
        // hide error label and remove error class on focus if enabled
205
			if ( this.settings.focusCleanup && !this.blockFocusCleanup ) {
213
        if ( this.settings.focusCleanup && !this.blockFocusCleanup ) {
206
				this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass );
214
          this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass );
207
				this.errorsFor(element).hide();
215
          this.errorsFor(element).hide();
208
			}
216
        }
209
		},
217
      },
210
		onfocusout: function(element) {
218
      onfocusout: function(element) {
211
			if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
219
        if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
212
				this.element(element);
220
          this.element(element);
213
			}
221
        }
214
		},
222
      },
215
		onkeyup: function(element) {
223
      onkeyup: function(element) {
216
			if ( element.name in this.submitted || element == this.lastElement ) {
224
        if ( element.name in this.submitted || element == this.lastElement ) {
217
				this.element(element);
225
          this.element(element);
218
			}
226
        }
219
		},
227
      },
220
		onclick: function(element) {
228
      onclick: function(element) {
221
			if ( element.name in this.submitted )
229
        if ( element.name in this.submitted )
222
				this.element(element);
230
          this.element(element);
223
		},
231
      },
224
		highlight: function( element, errorClass ) {
232
      highlight: function( element, errorClass ) {
225
			$( element ).addClass( errorClass );
233
        $( element ).addClass( errorClass );
226
		},
234
      },
227
		unhighlight: function( element, errorClass ) {
235
      unhighlight: function( element, errorClass ) {
228
			$( element ).removeClass( errorClass );
236
        $( element ).removeClass( errorClass );
229
		}
237
      }
230
	},
238
    },
231
 
239
 
232
	// http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
240
    // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
233
	setDefaults: function(settings) {
241
    setDefaults: function(settings) {
234
		$.extend( $.validator.defaults, settings );
242
      $.extend( $.validator.defaults, settings );
235
	},
243
    },
236
 
244
 
237
	messages: {
245
    messages: {
238
		required: "This field is required.",
246
      required: "This field is required.",
239
		remote: "Please fix this field.",
247
      remote: "Please fix this field.",
240
		email: "Please enter a valid email address.",
248
      email: "Please enter a valid email address.",
241
		url: "Please enter a valid URL.",
249
      url: "Please enter a valid URL.",
242
		date: "Please enter a valid date.",
250
      date: "Please enter a valid date.",
243
		dateISO: "Please enter a valid date (ISO).",
251
      dateISO: "Please enter a valid date (ISO).",
244
		dateDE: "Bitte geben Sie ein gültiges Datum ein.",
252
      dateDE: "Bitte geben Sie ein gültiges Datum ein.",
245
		number: "Please enter a valid number.",
253
      number: "Please enter a valid number.",
246
		numberDE: "Bitte geben Sie eine Nummer ein.",
254
      numberDE: "Bitte geben Sie eine Nummer ein.",
247
		digits: "Please enter only digits",
255
      digits: "Please enter only digits",
248
		creditcard: "Please enter a valid credit card number.",
256
      creditcard: "Please enter a valid credit card number.",
249
		equalTo: "Please enter the same value again.",
257
      equalTo: "Please enter the same value again.",
250
		accept: "Please enter a value with a valid extension.",
258
      accept: "Please enter a value with a valid extension.",
251
		maxlength: $.format("Please enter no more than {0} characters."),
259
      maxlength: $.format("Please enter no more than {0} characters."),
252
		minlength: $.format("Please enter at least {0} characters."),
260
      minlength: $.format("Please enter at least {0} characters."),
253
		rangelength: $.format("Please enter a value between {0} and {1} characters long."),
261
      rangelength: $.format("Please enter a value between {0} and {1} characters long."),
254
		range: $.format("Please enter a value between {0} and {1}."),
262
      range: $.format("Please enter a value between {0} and {1}."),
255
		max: $.format("Please enter a value less than or equal to {0}."),
263
      max: $.format("Please enter a value less than or equal to {0}."),
256
		min: $.format("Please enter a value greater than or equal to {0}.")
264
      min: $.format("Please enter a value greater than or equal to {0}.")
257
	},
265
    },
258
	
266
	
259
	autoCreateRanges: false,
267
    autoCreateRanges: false,
260
	
268
	
261
	prototype: {
269
    prototype: {
262
		
270
		
263
		init: function() {
271
      init: function() {
264
			this.labelContainer = $(this.settings.errorLabelContainer);
272
        this.labelContainer = $(this.settings.errorLabelContainer);
265
			this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
273
        this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
266
			this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer );
274
        this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer );
267
			this.submitted = {};
275
        this.submitted = {};
268
			this.valueCache = {};
276
        this.valueCache = {};
269
			this.pendingRequest = 0;
277
        this.pendingRequest = 0;
270
			this.pending = {};
278
        this.pending = {};
271
			this.invalid = {};
279
        this.invalid = {};
272
			this.reset();
280
        this.reset();
273
			
281
			
274
			var groups = (this.groups = {});
282
        var groups = (this.groups = {});
275
			$.each(this.settings.groups, function(key, value) {
283
        $.each(this.settings.groups, function(key, value) {
276
				$.each(value.split(/\s/), function(index, name) {
284
          $.each(value.split(/\s/), function(index, name) {
277
					groups[name] = key;
285
            groups[name] = key;
278
				});
286
          });
279
			});
287
        });
280
			var rules = this.settings.rules;
288
        var rules = this.settings.rules;
281
			$.each(rules, function(key, value) {
289
        $.each(rules, function(key, value) {
282
				rules[key] = $.validator.normalizeRule(value);
290
          rules[key] = $.validator.normalizeRule(value);
283
			});
291
        });
284
			
292
			
285
			function delegate(event) {
293
        function delegate(event) {
286
				var validator = $.data(this[0].form, "validator");
294
          var validator = $.data(this[0].form, "validator");
287
				validator.settings["on" + event.type] && validator.settings["on" + event.type].call(validator, this[0] );
295
          validator.settings["on" + event.type] && validator.settings["on" + event.type].call(validator, this[0] );
288
			}
296
        }
289
			$(this.currentForm)
297
        $(this.currentForm)
290
				.delegate("focusin focusout keyup", ":text, :password, :file, select, textarea", delegate)
298
        .delegate("focusin focusout keyup", ":text, :password, :file, select, textarea", delegate)
291
				.delegate("click", ":radio, :checkbox", delegate);
299
        .delegate("click", ":radio, :checkbox", delegate);
292
 
300
 
293
			if (this.settings.invalidHandler)
301
        if (this.settings.invalidHandler)
294
				$(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
302
          $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
295
		},
303
      },
296
 
304
 
297
		// http://docs.jquery.com/Plugins/Validation/Validator/form
305
      // http://docs.jquery.com/Plugins/Validation/Validator/form
298
		form: function() {
306
      form: function() {
299
			this.checkForm();
307
        this.checkForm();
300
			$.extend(this.submitted, this.errorMap);
308
        $.extend(this.submitted, this.errorMap);
301
			this.invalid = $.extend({}, this.errorMap);
309
        this.invalid = $.extend({}, this.errorMap);
302
			if (!this.valid())
310
        if (!this.valid())
303
				$(this.currentForm).triggerHandler("invalid-form", [this]);
311
          $(this.currentForm).triggerHandler("invalid-form", [this]);
304
			this.showErrors();
312
        this.showErrors();
305
			return this.valid();
313
        return this.valid();
306
		},
314
      },
307
		
315
		
308
		checkForm: function() {
316
      checkForm: function() {
309
			this.prepareForm();
317
        this.prepareForm();
310
			for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
318
        for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
311
				this.check( elements[i] );
319
          this.check( elements[i] );
312
			}
320
        }
313
			return this.valid(); 
321
        return this.valid();
314
		},
322
      },
315
		
323
		
316
		// http://docs.jquery.com/Plugins/Validation/Validator/element
324
      // http://docs.jquery.com/Plugins/Validation/Validator/element
317
		element: function( element ) {
325
      element: function( element ) {
318
			element = this.clean( element );
326
        element = this.clean( element );
319
			this.lastElement = element;
327
        this.lastElement = element;
320
			this.prepareElement( element );
328
        this.prepareElement( element );
321
			this.currentElements = $(element);
329
        this.currentElements = $(element);
322
			var result = this.check( element );
330
        var result = this.check( element );
323
			if ( result ) {
331
        if ( result ) {
324
				delete this.invalid[element.name];
332
          delete this.invalid[element.name];
325
			} else {
333
        } else {
326
				this.invalid[element.name] = true;
334
          this.invalid[element.name] = true;
327
			}
335
        }
328
			if ( !this.numberOfInvalids() ) {
336
        if ( !this.numberOfInvalids() ) {
329
				// Hide error containers on last error
337
          // Hide error containers on last error
330
				this.toHide = this.toHide.add( this.containers );
338
          this.toHide = this.toHide.add( this.containers );
331
			}
339
        }
332
			this.showErrors();
340
        this.showErrors();
333
			return result;
341
        return result;
334
		},
342
      },
335
 
343
 
336
		// http://docs.jquery.com/Plugins/Validation/Validator/showErrors
344
      // http://docs.jquery.com/Plugins/Validation/Validator/showErrors
337
		showErrors: function(errors) {
345
      showErrors: function(errors) {
338
			if(errors) {
346
        if(errors) {
339
				// add items to error list and map
347
          // add items to error list and map
340
				$.extend( this.errorMap, errors );
348
          $.extend( this.errorMap, errors );
341
				this.errorList = [];
349
          this.errorList = [];
342
				for ( var name in errors ) {
350
          for ( var name in errors ) {
343
					this.errorList.push({
351
            this.errorList.push({
344
						message: errors[name],
352
              message: errors[name],
345
						element: this.findByName(name)[0]
353
              element: this.findByName(name)[0]
346
					});
354
            });
347
				}
355
          }
348
				// remove items from success list
356
          // remove items from success list
349
				this.successList = $.grep( this.successList, function(element) {
357
          this.successList = $.grep( this.successList, function(element) {
350
					return !(element.name in errors);
358
            return !(element.name in errors);
351
				});
359
          });
352
			}
360
        }
353
			this.settings.showErrors
361
        this.settings.showErrors
354
				? this.settings.showErrors.call( this, this.errorMap, this.errorList )
362
        ? this.settings.showErrors.call( this, this.errorMap, this.errorList )
355
				: this.defaultShowErrors();
363
        : this.defaultShowErrors();
356
		},
364
      },
357
		
365
		
358
		// http://docs.jquery.com/Plugins/Validation/Validator/resetForm
366
      // http://docs.jquery.com/Plugins/Validation/Validator/resetForm
359
		resetForm: function() {
367
      resetForm: function() {
360
			if ( $.fn.resetForm )
368
        if ( $.fn.resetForm )
361
				$( this.currentForm ).resetForm();
369
          $( this.currentForm ).resetForm();
362
			this.submitted = {};
370
        this.submitted = {};
363
			this.prepareForm();
371
        this.prepareForm();
364
			this.hideErrors();
372
        this.hideErrors();
365
			this.elements().removeClass( this.settings.errorClass );
373
        this.elements().removeClass( this.settings.errorClass );
366
		},
374
      },
367
		
375
		
368
		numberOfInvalids: function() {
376
      numberOfInvalids: function() {
369
			return this.objectLength(this.invalid);
377
        return this.objectLength(this.invalid);
370
		},
378
      },
371
		
379
		
372
		objectLength: function( obj ) {
380
      objectLength: function( obj ) {
373
			var count = 0;
381
        var count = 0;
374
			for ( var i in obj )
382
        for ( var i in obj )
375
				count++;
383
          count++;
376
			return count;
384
        return count;
377
		},
385
      },
378
		
386
		
379
		hideErrors: function() {
387
      hideErrors: function() {
380
			this.addWrapper( this.toHide ).hide();
388
        this.addWrapper( this.toHide ).hide();
381
		},
389
      },
382
		
390
		
383
		valid: function() {
391
      valid: function() {
384
			return this.size() == 0;
392
        return this.size() == 0;
385
		},
393
      },
386
		
394
		
387
		size: function() {
395
      size: function() {
388
			return this.errorList.length;
396
        return this.errorList.length;
389
		},
397
      },
390
		
398
		
391
		focusInvalid: function() {
399
      focusInvalid: function() {
392
			if( this.settings.focusInvalid ) {
400
        if( this.settings.focusInvalid ) {
393
				try {
401
          try {
394
					$(this.findLastActive() || this.errorList.length && this.errorList[0].element || []).filter(":visible").focus();
402
            $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []).filter(":visible").focus();
395
				} catch(e) {
403
          } catch(e) {
396
					// ignore IE throwing errors when focusing hidden elements
404
          // ignore IE throwing errors when focusing hidden elements
397
				}
405
          }
398
			}
406
        }
399
		},
407
      },
400
		
408
		
401
		findLastActive: function() {
409
      findLastActive: function() {
402
			var lastActive = this.lastActive;
410
        var lastActive = this.lastActive;
403
			return lastActive && $.grep(this.errorList, function(n) {
411
        return lastActive && $.grep(this.errorList, function(n) {
404
				return n.element.name == lastActive.name;
412
          return n.element.name == lastActive.name;
405
			}).length == 1 && lastActive;
413
        }).length == 1 && lastActive;
406
		},
414
      },
407
		
415
		
408
		elements: function() {
416
      elements: function() {
409
			var validator = this,
417
        var validator = this,
410
				rulesCache = {};
418
        rulesCache = {};
411
			
419
			
412
			// select all valid inputs inside the form (no submit or reset buttons)
420
        // select all valid inputs inside the form (no submit or reset buttons)
413
			// workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved
421
        // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved
414
			return $([]).add(this.currentForm.elements)
422
        return $([]).add(this.currentForm.elements)
415
			.filter(":input")
423
        .filter(":input")
416
			.not(":submit, :reset, :image, [disabled]")
424
        .not(":submit, :reset, :image, [disabled]")
417
			.not( this.settings.ignore )
425
        .not( this.settings.ignore )
418
			.filter(function() {
426
        .filter(function() {
419
				!this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this);
427
          !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this);
420
			
428
			
421
				// select only the first element for each name, and only those with rules specified
429
          // select only the first element for each name, and only those with rules specified
422
				if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
430
          if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
423
					return false;
431
            return false;
424
				
432
				
425
				rulesCache[this.name] = true;
433
          rulesCache[this.name] = true;
426
				return true;
434
          return true;
427
			});
435
        });
428
		},
436
      },
429
		
437
		
430
		clean: function( selector ) {
438
      clean: function( selector ) {
431
			return $( selector )[0];
439
        return $( selector )[0];
432
		},
440
      },
433
		
441
		
434
		errors: function() {
442
      errors: function() {
435
			return $( this.settings.errorElement + "." + this.settings.errorClass, this.errorContext );
443
        return $( this.settings.errorElement + "." + this.settings.errorClass, this.errorContext );
436
		},
444
      },
437
		
445
		
438
		reset: function() {
446
      reset: function() {
439
			this.successList = [];
447
        this.successList = [];
440
			this.errorList = [];
448
        this.errorList = [];
441
			this.errorMap = {};
449
        this.errorMap = {};
442
			this.toShow = $([]);
450
        this.toShow = $([]);
443
			this.toHide = $([]);
451
        this.toHide = $([]);
444
			this.formSubmitted = false;
452
        this.formSubmitted = false;
445
			this.currentElements = $([]);
453
        this.currentElements = $([]);
446
		},
454
      },
447
		
455
		
448
		prepareForm: function() {
456
      prepareForm: function() {
449
			this.reset();
457
        this.reset();
450
			this.toHide = this.errors().add( this.containers );
458
        this.toHide = this.errors().add( this.containers );
451
		},
459
      },
452
		
460
		
453
		prepareElement: function( element ) {
461
      prepareElement: function( element ) {
454
			this.reset();
462
        this.reset();
455
			this.toHide = this.errorsFor(element);
463
        this.toHide = this.errorsFor(element);
456
		},
464
      },
457
	
465
	
458
		check: function( element ) {
466
      check: function( element ) {
459
			element = this.clean( element );
467
        element = this.clean( element );
460
			
468
			
461
			// if radio/checkbox, validate first element in group instead
469
        // if radio/checkbox, validate first element in group instead
462
			if (this.checkable(element)) {
470
        if (this.checkable(element)) {
463
				element = this.findByName( element.name )[0];
471
          element = this.findByName( element.name )[0];
464
			}
472
        }
465
			
473
			
466
			var rules = $(element).rules();
474
        var rules = $(element).rules();
467
			var dependencyMismatch = false;
475
        var dependencyMismatch = false;
468
			for( method in rules ) {
476
        for( method in rules ) {
-
 
477
          var rule = {
-
 
478
            method: method,
469
				var rule = { method: method, parameters: rules[method] };
479
            parameters: rules[method]
-
 
480
          };
470
				try {
481
          try {
471
					var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters );
482
            var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters );
472
					
483
					
473
					// if a method indicates that the field is optional and therefore valid,
484
            // if a method indicates that the field is optional and therefore valid,
474
					// don't mark it as valid when there are no other rules
485
            // don't mark it as valid when there are no other rules
475
					if ( result == "dependency-mismatch" ) {
486
            if ( result == "dependency-mismatch" ) {
476
						dependencyMismatch = true;
487
              dependencyMismatch = true;
477
						continue;
488
              continue;
478
					}
489
            }
479
					dependencyMismatch = false;
490
            dependencyMismatch = false;
480
					
491
					
481
					if ( result == "pending" ) {
492
            if ( result == "pending" ) {
482
						this.toHide = this.toHide.not( this.errorsFor(element) );
493
              this.toHide = this.toHide.not( this.errorsFor(element) );
483
						return;
494
              return;
484
					}
495
            }
485
					
496
					
486
					if( !result ) {
497
            if( !result ) {
487
						this.formatAndAdd( element, rule );
498
              this.formatAndAdd( element, rule );
488
						return false;
499
              return false;
489
					}
500
            }
490
				} catch(e) {
501
          } catch(e) {
491
					this.settings.debug && window.console && console.log("exception occured when checking element " + element.id
502
            this.settings.debug && window.console && console.log("exception occured when checking element " + element.id
492
						 + ", check the '" + rule.method + "' method");
503
              + ", check the '" + rule.method + "' method");
493
					throw e;
504
            throw e;
494
				}
505
          }
495
			}
506
        }
496
			if (dependencyMismatch)
507
        if (dependencyMismatch)
497
				return;
508
          return;
498
			if ( this.objectLength(rules) )
509
        if ( this.objectLength(rules) )
499
				this.successList.push(element);
510
          this.successList.push(element);
500
			return true;
511
        return true;
501
		},
512
      },
502
		
513
		
503
		// return the custom message for the given element and validation method
514
      // return the custom message for the given element and validation method
504
		// specified in the element's "messages" metadata
515
      // specified in the element's "messages" metadata
505
		customMetaMessage: function(element, method) {
516
      customMetaMessage: function(element, method) {
506
			if (!$.metadata)
517
        if (!$.metadata)
507
				return;
518
          return;
508
			
519
			
509
			var meta = this.settings.meta
520
        var meta = this.settings.meta
510
				? $(element).metadata()[this.settings.meta]
521
        ? $(element).metadata()[this.settings.meta]
511
				: $(element).metadata();
522
        : $(element).metadata();
512
			
523
			
513
			return meta && meta.messages && meta.messages[method];
524
        return meta && meta.messages && meta.messages[method];
-
 
525
      },
-
 
526
		
-
 
527
      // return the custom message for the given element name and validation method
-
 
528
      customMessage: function( name, method ) {
-
 
529
        var m = this.settings.messages[name];
-
 
530
        return m && (m.constructor == String
-
 
531
          ? m
-
 
532
          : m[method]);
-
 
533
      },
514
		},
534
		
-
 
535
      // return the first defined argument, allowing empty strings
-
 
536
      findDefined: function() {
-
 
537
        for(var i = 0; i < arguments.length; i++) {
-
 
538
          if (arguments[i] !== undefined)
-
 
539
            return arguments[i];
-
 
540
        }
-
 
541
        return undefined;
-
 
542
      },
515
		
543
		
516
		// return the custom message for the given element name and validation method
-
 
517
		customMessage: function( name, method ) {
-
 
518
			var m = this.settings.messages[name];
-
 
519
			return m && (m.constructor == String
-
 
520
				? m
-
 
521
				: m[method]);
-
 
522
		},
-
 
523
		
-
 
524
		// return the first defined argument, allowing empty strings
-
 
525
		findDefined: function() {
-
 
526
			for(var i = 0; i < arguments.length; i++) {
-
 
527
				if (arguments[i] !== undefined)
-
 
528
					return arguments[i];
-
 
529
			}
-
 
530
			return undefined;
-
 
531
		},
-
 
532
		
-
 
533
		defaultMessage: function( element, method) {
544
      defaultMessage: function( element, method) {
534
			return this.findDefined(
545
        return this.findDefined(
535
				this.customMessage( element.name, method ),
546
          this.customMessage( element.name, method ),
536
				this.customMetaMessage( element, method ),
547
          this.customMetaMessage( element, method ),
537
				// title is never undefined, so handle empty string as undefined
548
          // title is never undefined, so handle empty string as undefined
538
				!this.settings.ignoreTitle && element.title || undefined,
549
          !this.settings.ignoreTitle && element.title || undefined,
539
				$.validator.messages[method],
550
          $.validator.messages[method],
540
				"<strong>Warning: No message defined for " + element.name + "</strong>"
551
          "<strong>Warning: No message defined for " + element.name + "</strong>"
541
			);
552
          );
542
		},
553
      },
543
		
554
		
544
		formatAndAdd: function( element, rule ) {
555
      formatAndAdd: function( element, rule ) {
545
			var message = this.defaultMessage( element, rule.method );
556
        var message = this.defaultMessage( element, rule.method );
546
			if ( typeof message == "function" ) 
557
        if ( typeof message == "function" )
547
				message = message.call(this, rule.parameters, element);
558
          message = message.call(this, rule.parameters, element);
548
			this.errorList.push({
559
        this.errorList.push({
549
				message: message,
560
          message: message,
550
				element: element
561
          element: element
551
			});
562
        });
552
			this.errorMap[element.name] = message;
563
        this.errorMap[element.name] = message;
553
			this.submitted[element.name] = message;
564
        this.submitted[element.name] = message;
554
		},
565
      },
555
		
566
		
556
		addWrapper: function(toToggle) {
567
      addWrapper: function(toToggle) {
557
			if ( this.settings.wrapper )
568
        if ( this.settings.wrapper )
558
				toToggle = toToggle.add( toToggle.parents( this.settings.wrapper ) );
569
          toToggle = toToggle.add( toToggle.parents( this.settings.wrapper ) );
559
			return toToggle;
570
        return toToggle;
560
		},
571
      },
561
		
572
		
562
		defaultShowErrors: function() {
573
      defaultShowErrors: function() {
563
			for ( var i = 0; this.errorList[i]; i++ ) {
574
        for ( var i = 0; this.errorList[i]; i++ ) {
564
				var error = this.errorList[i];
575
          var error = this.errorList[i];
565
				this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass );
576
          this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass );
566
				this.showLabel( error.element, error.message );
577
          this.showLabel( error.element, error.message );
567
			}
578
        }
568
			if( this.errorList.length ) {
579
        if( this.errorList.length ) {
569
				this.toShow = this.toShow.add( this.containers );
580
          this.toShow = this.toShow.add( this.containers );
570
			}
581
        }
571
			if (this.settings.success) {
582
        if (this.settings.success) {
572
				for ( var i = 0; this.successList[i]; i++ ) {
583
          for ( var i = 0; this.successList[i]; i++ ) {
573
					this.showLabel( this.successList[i] );
584
            this.showLabel( this.successList[i] );
574
				}
585
          }
575
			}
586
        }
576
			if (this.settings.unhighlight) {
587
        if (this.settings.unhighlight) {
577
				for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {
588
          for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {
578
					this.settings.unhighlight.call( this, elements[i], this.settings.errorClass );
589
            this.settings.unhighlight.call( this, elements[i], this.settings.errorClass );
579
				}
590
          }
580
			}
591
        }
581
			this.toHide = this.toHide.not( this.toShow );
592
        this.toHide = this.toHide.not( this.toShow );
582
			this.hideErrors();
593
        this.hideErrors();
583
			this.addWrapper( this.toShow ).show();
594
        this.addWrapper( this.toShow ).show();
584
		},
595
      },
585
		
596
		
586
		validElements: function() {
597
      validElements: function() {
587
			return this.currentElements.not(this.invalidElements());
598
        return this.currentElements.not(this.invalidElements());
588
		},
599
      },
589
		
600
		
590
		invalidElements: function() {
601
      invalidElements: function() {
591
			return $(this.errorList).map(function() {
602
        return $(this.errorList).map(function() {
592
				return this.element;
603
          return this.element;
593
			});
604
        });
594
		},
605
      },
595
		
606
		
596
		showLabel: function(element, message) {
607
      showLabel: function(element, message) {
597
			var label = this.errorsFor( element );
608
        var label = this.errorsFor( element );
598
			if ( label.length ) {
609
        if ( label.length ) {
599
				// refresh error/success class
610
          // refresh error/success class
600
				label.removeClass().addClass( this.settings.errorClass );
611
          label.removeClass().addClass( this.settings.errorClass );
601
			
612
			
602
				// check if we have a generated label, replace the message then
613
          // check if we have a generated label, replace the message then
603
				label.attr("generated") && label.html(message);
614
          label.attr("generated") && label.html(message);
604
			} else {
615
        } else {
605
				// create label
616
          // create label
606
				label = $("<" + this.settings.errorElement + "/>")
617
          label = $("<" + this.settings.errorElement + "/>")
-
 
618
          .attr({
607
					.attr({"for":  this.idOrName(element), generated: true})
619
            "for":  this.idOrName(element),
-
 
620
            generated: true
-
 
621
          })
608
					.addClass(this.settings.errorClass)
622
          .addClass(this.settings.errorClass)
609
					.html(message || "");
623
          .html(message || "");
610
				if ( this.settings.wrapper ) {
624
          if ( this.settings.wrapper ) {
611
					// make sure the element is visible, even in IE
625
            // make sure the element is visible, even in IE
612
					// actually showing the wrapped element is handled elsewhere
626
            // actually showing the wrapped element is handled elsewhere
613
					label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
627
            label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
614
				}
628
          }
615
				if ( !this.labelContainer.append(label).length )
629
          if ( !this.labelContainer.append(label).length )
616
					this.settings.errorPlacement
630
            this.settings.errorPlacement
617
						? this.settings.errorPlacement(label, $(element) )
631
            ? this.settings.errorPlacement(label, $(element) )
618
						: label.insertAfter(element);
632
            : label.insertAfter(element);
619
			}
633
        }
620
			if ( !message && this.settings.success ) {
634
        if ( !message && this.settings.success ) {
621
				label.text("");
635
          label.text("");
622
				typeof this.settings.success == "string"
636
          typeof this.settings.success == "string"
623
					? label.addClass( this.settings.success )
637
          ? label.addClass( this.settings.success )
624
					: this.settings.success( label );
638
          : this.settings.success( label );
625
			}
639
        }
626
			this.toShow = this.toShow.add(label);
640
        this.toShow = this.toShow.add(label);
627
		},
641
      },
628
		
642
		
629
		errorsFor: function(element) {
643
      errorsFor: function(element) {
630
			return this.errors().filter("[for='" + this.idOrName(element) + "']");
644
        return this.errors().filter("[for='" + this.idOrName(element) + "']");
631
		},
645
      },
632
		
646
		
633
		idOrName: function(element) {
647
      idOrName: function(element) {
634
			return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
648
        return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
635
		},
649
      },
636
 
650
 
637
		checkable: function( element ) {
651
      checkable: function( element ) {
638
			return /radio|checkbox/i.test(element.type);
652
        return /radio|checkbox/i.test(element.type);
639
		},
653
      },
640
		
654
		
641
		findByName: function( name ) {
655
      findByName: function( name ) {
642
			// select by name and filter by form for performance over form.find("[name=...]")
656
        // select by name and filter by form for performance over form.find("[name=...]")
643
			var form = this.currentForm;
657
        var form = this.currentForm;
644
			return $(document.getElementsByName(name)).map(function(index, element) {
658
        return $(document.getElementsByName(name)).map(function(index, element) {
645
				return element.form == form && element.name == name && element  || null;
659
          return element.form == form && element.name == name && element  || null;
646
			});
660
        });
647
		},
661
      },
648
		
662
		
649
		getLength: function(value, element) {
663
      getLength: function(value, element) {
650
			switch( element.nodeName.toLowerCase() ) {
664
        switch( element.nodeName.toLowerCase() ) {
651
			case 'select':
665
          case 'select':
652
				return $("option:selected", element).length;
666
            return $("option:selected", element).length;
653
			case 'input':
667
          case 'input':
654
				if( this.checkable( element) )
668
            if( this.checkable( element) )
655
					return this.findByName(element.name).filter(':checked').length;
669
              return this.findByName(element.name).filter(':checked').length;
656
			}
670
        }
657
			return value.length;
671
        return value.length;
658
		},
672
      },
659
	
673
	
660
		depend: function(param, element) {
674
      depend: function(param, element) {
661
			return this.dependTypes[typeof param]
675
        return this.dependTypes[typeof param]
662
				? this.dependTypes[typeof param](param, element)
676
        ? this.dependTypes[typeof param](param, element)
663
				: true;
677
        : true;
664
		},
678
      },
665
	
679
	
666
		dependTypes: {
680
      dependTypes: {
667
			"boolean": function(param, element) {
681
        "boolean": function(param, element) {
668
				return param;
682
          return param;
669
			},
683
        },
670
			"string": function(param, element) {
684
        "string": function(param, element) {
671
				return !!$(param, element.form).length;
685
          return !!$(param, element.form).length;
672
			},
686
        },
673
			"function": function(param, element) {
687
        "function": function(param, element) {
674
				return param(element);
688
          return param(element);
675
			}
689
        }
676
		},
690
      },
677
		
691
		
678
		optional: function(element) {
692
      optional: function(element) {
679
			return !$.validator.methods.required.call(this, $.trim(element.value), element) && "dependency-mismatch";
693
        return !$.validator.methods.required.call(this, $.trim(element.value), element) && "dependency-mismatch";
680
		},
694
      },
681
		
695
		
682
		startRequest: function(element) {
696
      startRequest: function(element) {
683
			if (!this.pending[element.name]) {
697
        if (!this.pending[element.name]) {
684
				this.pendingRequest++;
698
          this.pendingRequest++;
685
				this.pending[element.name] = true;
699
          this.pending[element.name] = true;
686
			}
-
 
687
		},
-
 
688
		
-
 
689
		stopRequest: function(element, valid) {
-
 
690
			this.pendingRequest--;
-
 
691
			// sometimes synchronization fails, make sure pendingRequest is never < 0
-
 
692
			if (this.pendingRequest < 0)
-
 
693
				this.pendingRequest = 0;
-
 
694
			delete this.pending[element.name];
-
 
695
			if ( valid && this.pendingRequest == 0 && this.formSubmitted && this.form() ) {
-
 
696
				$(this.currentForm).submit();
-
 
697
			} else if (!valid && this.pendingRequest == 0 && this.formSubmitted) {
-
 
698
				$(this.currentForm).triggerHandler("invalid-form", [this]);
-
 
699
			}
700
        }
700
		},
701
      },
701
		
-
 
702
		previousValue: function(element) {
-
 
703
			return $.data(element, "previousValue") || $.data(element, "previousValue", previous = {
-
 
704
				old: null,
-
 
705
				valid: true,
-
 
706
				message: this.defaultMessage( element, "remote" )
-
 
707
			});
-
 
708
		}
-
 
709
		
702
		
-
 
703
      stopRequest: function(element, valid) {
-
 
704
        this.pendingRequest--;
-
 
705
        // sometimes synchronization fails, make sure pendingRequest is never < 0
-
 
706
        if (this.pendingRequest < 0)
-
 
707
          this.pendingRequest = 0;
-
 
708
        delete this.pending[element.name];
-
 
709
        if ( valid && this.pendingRequest == 0 && this.formSubmitted && this.form() ) {
-
 
710
          $(this.currentForm).submit();
-
 
711
        } else if (!valid && this.pendingRequest == 0 && this.formSubmitted) {
-
 
712
          $(this.currentForm).triggerHandler("invalid-form", [this]);
-
 
713
        }
-
 
714
      },
710
	},
715
		
-
 
716
      previousValue: function(element) {
-
 
717
        return $.data(element, "previousValue") || $.data(element, "previousValue", previous = {
-
 
718
          old: null,
-
 
719
          valid: true,
-
 
720
          message: this.defaultMessage( element, "remote" )
-
 
721
        });
-
 
722
      }
-
 
723
		
-
 
724
    },
711
	
725
	
712
	classRuleSettings: {
726
    classRuleSettings: {
-
 
727
      required: {
713
		required: {required: true},
728
        required: true
-
 
729
      },
-
 
730
      email: {
714
		email: {email: true},
731
        email: true
-
 
732
      },
-
 
733
      url: {
715
		url: {url: true},
734
        url: true
-
 
735
      },
-
 
736
      date: {
716
		date: {date: true},
737
        date: true
-
 
738
      },
-
 
739
      dateISO: {
717
		dateISO: {dateISO: true},
740
        dateISO: true
-
 
741
      },
-
 
742
      dateDE: {
718
		dateDE: {dateDE: true},
743
        dateDE: true
-
 
744
      },
-
 
745
      number: {
719
		number: {number: true},
746
        number: true
-
 
747
      },
-
 
748
      numberDE: {
720
		numberDE: {numberDE: true},
749
        numberDE: true
-
 
750
      },
-
 
751
      digits: {
721
		digits: {digits: true},
752
        digits: true
-
 
753
      },
-
 
754
      creditcard: {
722
		creditcard: {creditcard: true}
755
        creditcard: true
-
 
756
      }
723
	},
757
    },
724
	
758
	
725
	addClassRules: function(className, rules) {
759
    addClassRules: function(className, rules) {
726
		className.constructor == String ?
760
      className.constructor == String ?
727
			this.classRuleSettings[className] = rules :
761
      this.classRuleSettings[className] = rules :
728
			$.extend(this.classRuleSettings, className);
762
      $.extend(this.classRuleSettings, className);
729
	},
763
    },
730
	
764
	
731
	classRules: function(element) {
765
    classRules: function(element) {
732
		var rules = {};
766
      var rules = {};
733
		var classes = $(element).attr('class');
767
      var classes = $(element).attr('class');
734
		classes && $.each(classes.split(' '), function() {
768
      classes && $.each(classes.split(' '), function() {
735
			if (this in $.validator.classRuleSettings) {
769
        if (this in $.validator.classRuleSettings) {
736
				$.extend(rules, $.validator.classRuleSettings[this]);
770
          $.extend(rules, $.validator.classRuleSettings[this]);
737
			}
771
        }
738
		});
772
      });
739
		return rules;
773
      return rules;
740
	},
774
    },
741
	
775
	
742
	attributeRules: function(element) {
776
    attributeRules: function(element) {
743
		var rules = {};
777
      var rules = {};
744
		var $element = $(element);
778
      var $element = $(element);
745
		
779
		
746
		for (method in $.validator.methods) {
780
      for (method in $.validator.methods) {
747
			var value = $element.attr(method);
781
        var value = $element.attr(method);
748
			if (value) {
782
        if (value) {
749
				rules[method] = value;
783
          rules[method] = value;
750
			}
784
        }
751
		}
785
      }
752
		
786
		
753
		// maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
787
      // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
754
		if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
788
      if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
755
			delete rules.maxlength;
789
        delete rules.maxlength;
756
		}
790
      }
757
		
791
		
758
		return rules;
792
      return rules;
759
	},
793
    },
760
	
794
	
761
	metadataRules: function(element) {
795
    metadataRules: function(element) {
762
		if (!$.metadata) return {};
796
      if (!$.metadata) return {};
763
		
797
		
764
		var meta = $.data(element.form, 'validator').settings.meta;
798
      var meta = $.data(element.form, 'validator').settings.meta;
765
		return meta ?
799
      return meta ?
766
			$(element).metadata()[meta] :
800
      $(element).metadata()[meta] :
767
			$(element).metadata();
801
      $(element).metadata();
768
	},
802
    },
769
	
803
	
770
	staticRules: function(element) {
804
    staticRules: function(element) {
771
		var rules = {};
805
      var rules = {};
772
		var validator = $.data(element.form, 'validator');
806
      var validator = $.data(element.form, 'validator');
773
		if (validator.settings.rules) {
807
      if (validator.settings.rules) {
774
			rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
808
        rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
775
		}
809
      }
776
		return rules;
810
      return rules;
777
	},
811
    },
778
	
812
	
779
	normalizeRules: function(rules, element) {
813
    normalizeRules: function(rules, element) {
780
		// handle dependency check
814
      // handle dependency check
781
		$.each(rules, function(prop, val) {
815
      $.each(rules, function(prop, val) {
782
			// ignore rule when param is explicitly false, eg. required:false
816
        // ignore rule when param is explicitly false, eg. required:false
783
			if (val === false) {
817
        if (val === false) {
784
				delete rules[prop];
818
          delete rules[prop];
785
				return;
819
          return;
786
			}
820
        }
787
			if (val.param || val.depends) {
821
        if (val.param || val.depends) {
788
				var keepRule = true;
822
          var keepRule = true;
789
				switch (typeof val.depends) {
823
          switch (typeof val.depends) {
790
					case "string":
824
            case "string":
791
						keepRule = !!$(val.depends, element.form).length;
825
              keepRule = !!$(val.depends, element.form).length;
792
						break;
826
              break;
793
					case "function":
827
            case "function":
794
						keepRule = val.depends.call(element, element);
828
              keepRule = val.depends.call(element, element);
795
						break;
829
              break;
796
				}
830
          }
797
				if (keepRule) {
831
          if (keepRule) {
798
					rules[prop] = val.param !== undefined ? val.param : true;
832
            rules[prop] = val.param !== undefined ? val.param : true;
799
				} else {
833
          } else {
800
					delete rules[prop];
834
            delete rules[prop];
801
				}
835
          }
802
			}
836
        }
803
		});
837
      });
804
		
838
		
805
		// evaluate parameters
839
      // evaluate parameters
806
		$.each(rules, function(rule, parameter) {
840
      $.each(rules, function(rule, parameter) {
807
			rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
841
        rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
808
		});
842
      });
809
		
843
		
810
		// clean number parameters
844
      // clean number parameters
811
		$.each(['minlength', 'maxlength', 'min', 'max'], function() {
845
      $.each(['minlength', 'maxlength', 'min', 'max'], function() {
812
			if (rules[this]) {
846
        if (rules[this]) {
813
				rules[this] = Number(rules[this]);
847
          rules[this] = Number(rules[this]);
814
			}
848
        }
815
		});
849
      });
816
		$.each(['rangelength', 'range'], function() {
850
      $.each(['rangelength', 'range'], function() {
817
			if (rules[this]) {
851
        if (rules[this]) {
818
				rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
852
          rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
819
			}
853
        }
820
		});
854
      });
821
		
855
		
822
		if ($.validator.autoCreateRanges) {
856
      if ($.validator.autoCreateRanges) {
823
			// auto-create ranges
857
        // auto-create ranges
824
			if (rules.min && rules.max) {
858
        if (rules.min && rules.max) {
825
				rules.range = [rules.min, rules.max];
859
          rules.range = [rules.min, rules.max];
826
				delete rules.min;
860
          delete rules.min;
827
				delete rules.max;
861
          delete rules.max;
828
			}
862
        }
829
			if (rules.minlength && rules.maxlength) {
863
        if (rules.minlength && rules.maxlength) {
830
				rules.rangelength = [rules.minlength, rules.maxlength];
864
          rules.rangelength = [rules.minlength, rules.maxlength];
831
				delete rules.minlength;
865
          delete rules.minlength;
832
				delete rules.maxlength;
866
          delete rules.maxlength;
833
			}
867
        }
834
		}
868
      }
835
		
869
		
836
		// To support custom messages in metadata ignore rule methods titled "messages"
870
      // To support custom messages in metadata ignore rule methods titled "messages"
837
		if (rules.messages) {
871
      if (rules.messages) {
838
			delete rules.messages
872
        delete rules.messages
839
		}
873
      }
840
		
874
		
841
		return rules;
875
      return rules;
842
	},
876
    },
843
	
877
	
844
	// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
878
    // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
845
	normalizeRule: function(data) {
879
    normalizeRule: function(data) {
846
		if( typeof data == "string" ) {
880
      if( typeof data == "string" ) {
847
			var transformed = {};
881
        var transformed = {};
848
			$.each(data.split(/\s/), function() {
882
        $.each(data.split(/\s/), function() {
849
				transformed[this] = true;
883
          transformed[this] = true;
850
			});
884
        });
851
			data = transformed;
885
        data = transformed;
852
		}
886
      }
853
		return data;
887
      return data;
854
	},
888
    },
855
	
889
	
856
	// http://docs.jquery.com/Plugins/Validation/Validator/addMethod
890
    // http://docs.jquery.com/Plugins/Validation/Validator/addMethod
857
	addMethod: function(name, method, message) {
891
    addMethod: function(name, method, message) {
858
		$.validator.methods[name] = method;
892
      $.validator.methods[name] = method;
859
		$.validator.messages[name] = message;
893
      $.validator.messages[name] = message;
860
		if (method.length < 3) {
894
      if (method.length < 3) {
861
			$.validator.addClassRules(name, $.validator.normalizeRule(name));
895
        $.validator.addClassRules(name, $.validator.normalizeRule(name));
862
		}
896
      }
863
	},
897
    },
864
 
898
 
865
	methods: {
899
    methods: {
866
 
900
 
867
		// http://docs.jquery.com/Plugins/Validation/Methods/required
901
      // http://docs.jquery.com/Plugins/Validation/Methods/required
868
		required: function(value, element, param) {
902
      required: function(value, element, param) {
869
			// check if dependency is met
903
        // check if dependency is met
870
			if ( !this.depend(param, element) )
904
        if ( !this.depend(param, element) )
871
				return "dependency-mismatch";
905
          return "dependency-mismatch";
872
			switch( element.nodeName.toLowerCase() ) {
906
        switch( element.nodeName.toLowerCase() ) {
873
			case 'select':
907
          case 'select':
874
				var options = $("option:selected", element);
908
            var options = $("option:selected", element);
875
				return options.length > 0 && ( element.type == "select-multiple" || ($.browser.msie && !(options[0].attributes['value'].specified) ? options[0].text : options[0].value).length > 0);
909
            return options.length > 0 && ( element.type == "select-multiple" || ($.browser.msie && !(options[0].attributes['value'].specified) ? options[0].text : options[0].value).length > 0);
876
			case 'input':
910
          case 'input':
877
				if ( this.checkable(element) )
911
            if ( this.checkable(element) )
878
					return this.getLength(value, element) > 0;
912
              return this.getLength(value, element) > 0;
879
			default:
913
          default:
880
				return $.trim(value).length > 0;
914
            return $.trim(value).length > 0;
881
			}
915
        }
882
		},
916
      },
883
		
917
		
884
		// http://docs.jquery.com/Plugins/Validation/Methods/remote
918
      // http://docs.jquery.com/Plugins/Validation/Methods/remote
885
		remote: function(value, element, param) {
919
      remote: function(value, element, param) {
886
			if ( this.optional(element) )
920
        if ( this.optional(element) )
887
				return "dependency-mismatch";
921
          return "dependency-mismatch";
888
			
922
			
889
			var previous = this.previousValue(element);
923
        var previous = this.previousValue(element);
890
			
924
			
891
			if (!this.settings.messages[element.name] )
925
        if (!this.settings.messages[element.name] )
892
				this.settings.messages[element.name] = {};
926
          this.settings.messages[element.name] = {};
893
			this.settings.messages[element.name].remote = typeof previous.message == "function" ? previous.message(value) : previous.message;
927
        this.settings.messages[element.name].remote = typeof previous.message == "function" ? previous.message(value) : previous.message;
894
			
928
			
895
			param = typeof param == "string" && {url:param} || param; 
929
        param = typeof param == "string" && {
-
 
930
          url:param
-
 
931
        } || param;
896
			
932
			
897
			if ( previous.old !== value ) {
933
        if ( previous.old !== value ) {
898
				previous.old = value;
934
          previous.old = value;
899
				var validator = this;
935
          var validator = this;
900
				this.startRequest(element);
936
          this.startRequest(element);
901
				var data = {};
937
          var data = {};
902
				data[element.name] = value;
938
          data[element.name] = value;
903
				$.ajax($.extend(true, {
939
          $.ajax($.extend(true, {
904
					url: param,
940
            url: param,
905
					mode: "abort",
941
            mode: "abort",
906
					port: "validate" + element.name,
942
            port: "validate" + element.name,
907
					dataType: "json",
943
            dataType: "json",
908
					data: data,
944
            data: data,
909
					success: function(response) {
945
            success: function(response) {
910
						if ( response ) {
946
              if ( response ) {
911
							var submitted = validator.formSubmitted;
947
                var submitted = validator.formSubmitted;
912
							validator.prepareElement(element);
948
                validator.prepareElement(element);
913
							validator.formSubmitted = submitted;
949
                validator.formSubmitted = submitted;
914
							validator.successList.push(element);
950
                validator.successList.push(element);
915
							validator.showErrors();
951
                validator.showErrors();
916
						} else {
952
              } else {
917
							var errors = {};
953
                var errors = {};
918
							errors[element.name] =  response || validator.defaultMessage( element, "remote" );
954
                errors[element.name] =  response || validator.defaultMessage( element, "remote" );
919
							validator.showErrors(errors);
955
                validator.showErrors(errors);
920
						}
956
              }
921
						previous.valid = response;
957
              previous.valid = response;
922
						validator.stopRequest(element, response);
958
              validator.stopRequest(element, response);
923
					}
959
            }
924
				}, param));
960
          }, param));
925
				return "pending";
961
          return "pending";
926
			} else if( this.pending[element.name] ) {
962
        } else if( this.pending[element.name] ) {
927
				return "pending";
963
          return "pending";
928
			}
964
        }
929
			return previous.valid;
965
        return previous.valid;
930
		},
966
      },
931
 
967
 
932
		// http://docs.jquery.com/Plugins/Validation/Methods/minlength
968
      // http://docs.jquery.com/Plugins/Validation/Methods/minlength
933
		minlength: function(value, element, param) {
969
      minlength: function(value, element, param) {
934
			return this.optional(element) || this.getLength($.trim(value), element) >= param;
970
        return this.optional(element) || this.getLength($.trim(value), element) >= param;
935
		},
971
      },
936
		
972
		
937
		// http://docs.jquery.com/Plugins/Validation/Methods/maxlength
973
      // http://docs.jquery.com/Plugins/Validation/Methods/maxlength
938
		maxlength: function(value, element, param) {
974
      maxlength: function(value, element, param) {
939
			return this.optional(element) || this.getLength($.trim(value), element) <= param;
975
        return this.optional(element) || this.getLength($.trim(value), element) <= param;
940
		},
976
      },
941
		
977
		
942
		// http://docs.jquery.com/Plugins/Validation/Methods/rangelength
978
      // http://docs.jquery.com/Plugins/Validation/Methods/rangelength
943
		rangelength: function(value, element, param) {
979
      rangelength: function(value, element, param) {
944
			var length = this.getLength($.trim(value), element);
980
        var length = this.getLength($.trim(value), element);
945
			return this.optional(element) || ( length >= param[0] && length <= param[1] );
981
        return this.optional(element) || ( length >= param[0] && length <= param[1] );
946
		},
982
      },
947
		
983
		
948
		// http://docs.jquery.com/Plugins/Validation/Methods/min
984
      // http://docs.jquery.com/Plugins/Validation/Methods/min
949
		min: function( value, element, param ) {
985
      min: function( value, element, param ) {
950
			return this.optional(element) || value >= param;
986
        return this.optional(element) || value >= param;
951
		},
987
      },
952
		
988
		
953
		// http://docs.jquery.com/Plugins/Validation/Methods/max
989
      // http://docs.jquery.com/Plugins/Validation/Methods/max
954
		max: function( value, element, param ) {
990
      max: function( value, element, param ) {
955
			return this.optional(element) || value <= param;
991
        return this.optional(element) || value <= param;
956
		},
992
      },
957
		
993
		
958
		// http://docs.jquery.com/Plugins/Validation/Methods/range
994
      // http://docs.jquery.com/Plugins/Validation/Methods/range
959
		range: function( value, element, param ) {
995
      range: function( value, element, param ) {
960
			return this.optional(element) || ( value >= param[0] && value <= param[1] );
996
        return this.optional(element) || ( value >= param[0] && value <= param[1] );
961
		},
997
      },
962
		
998
		
963
		// http://docs.jquery.com/Plugins/Validation/Methods/email
999
      // http://docs.jquery.com/Plugins/Validation/Methods/email
964
		email: function(value, element) {
1000
      email: function(value, element) {
965
			// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
1001
        // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
966
			return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
1002
        return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
967
		},
1003
      },
968
	
1004
	
969
		// http://docs.jquery.com/Plugins/Validation/Methods/url
1005
      // http://docs.jquery.com/Plugins/Validation/Methods/url
970
		url: function(value, element) {
1006
      url: function(value, element) {
971
			// contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
1007
        // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
972
			return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
1008
        return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
973
		},
1009
      },
974
        
1010
        
975
		// http://docs.jquery.com/Plugins/Validation/Methods/date
1011
      // http://docs.jquery.com/Plugins/Validation/Methods/date
976
		date: function(value, element) {
1012
      date: function(value, element) {
977
			return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
1013
        return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
978
		},
1014
      },
979
	
1015
	
980
		// http://docs.jquery.com/Plugins/Validation/Methods/dateISO
1016
      // http://docs.jquery.com/Plugins/Validation/Methods/dateISO
981
		dateISO: function(value, element) {
1017
      dateISO: function(value, element) {
982
			return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);
1018
        return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);
983
		},
1019
      },
984
	
1020
	
985
		// http://docs.jquery.com/Plugins/Validation/Methods/dateDE
1021
      // http://docs.jquery.com/Plugins/Validation/Methods/dateDE
986
		dateDE: function(value, element) {
1022
      dateDE: function(value, element) {
987
			return this.optional(element) || /^\d\d?\.\d\d?\.\d\d\d?\d?$/.test(value);
1023
        return this.optional(element) || /^\d\d?\.\d\d?\.\d\d\d?\d?$/.test(value);
988
		},
1024
      },
989
	
1025
	
990
		// http://docs.jquery.com/Plugins/Validation/Methods/number
1026
      // http://docs.jquery.com/Plugins/Validation/Methods/number
991
		number: function(value, element) {
1027
      number: function(value, element) {
992
			return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
1028
        return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
993
		},
1029
      },
994
	
1030
	
995
		// http://docs.jquery.com/Plugins/Validation/Methods/numberDE
1031
      // http://docs.jquery.com/Plugins/Validation/Methods/numberDE
996
		numberDE: function(value, element) {
1032
      numberDE: function(value, element) {
997
			return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
1033
        return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
998
		},
1034
      },
999
		
1035
		
1000
		// http://docs.jquery.com/Plugins/Validation/Methods/digits
1036
      // http://docs.jquery.com/Plugins/Validation/Methods/digits
1001
		digits: function(value, element) {
1037
      digits: function(value, element) {
1002
			return this.optional(element) || /^\d+$/.test(value);
1038
        return this.optional(element) || /^\d+$/.test(value);
1003
		},
1039
      },
1004
		
1040
		
1005
		// http://docs.jquery.com/Plugins/Validation/Methods/creditcard
1041
      // http://docs.jquery.com/Plugins/Validation/Methods/creditcard
1006
		// based on http://en.wikipedia.org/wiki/Luhn
1042
      // based on http://en.wikipedia.org/wiki/Luhn
1007
		creditcard: function(value, element) {
1043
      creditcard: function(value, element) {
1008
			if ( this.optional(element) )
1044
        if ( this.optional(element) )
1009
				return "dependency-mismatch";
1045
          return "dependency-mismatch";
1010
			// accept only digits and dashes
1046
        // accept only digits and dashes
1011
			if (/[^0-9-]+/.test(value))
1047
        if (/[^0-9-]+/.test(value))
1012
				return false;
1048
          return false;
1013
			var nCheck = 0,
1049
        var nCheck = 0,
1014
				nDigit = 0,
1050
        nDigit = 0,
1015
				bEven = false;
1051
        bEven = false;
1016
 
1052
 
1017
			value = value.replace(/\D/g, "");
1053
        value = value.replace(/\D/g, "");
1018
 
1054
 
1019
			for (n = value.length - 1; n >= 0; n--) {
1055
        for (n = value.length - 1; n >= 0; n--) {
1020
				var cDigit = value.charAt(n);
1056
          var cDigit = value.charAt(n);
1021
				var nDigit = parseInt(cDigit, 10);
1057
          var nDigit = parseInt(cDigit, 10);
1022
				if (bEven) {
1058
          if (bEven) {
1023
					if ((nDigit *= 2) > 9)
1059
            if ((nDigit *= 2) > 9)
1024
						nDigit -= 9;
1060
              nDigit -= 9;
1025
				}
1061
          }
1026
				nCheck += nDigit;
1062
          nCheck += nDigit;
1027
				bEven = !bEven;
1063
          bEven = !bEven;
1028
			}
1064
        }
1029
 
1065
 
1030
			return (nCheck % 10) == 0;
1066
        return (nCheck % 10) == 0;
1031
		},
-
 
1032
		
-
 
1033
		// http://docs.jquery.com/Plugins/Validation/Methods/accept
-
 
1034
		accept: function(value, element, param) {
-
 
1035
			param = typeof param == "string" ? param : "png|jpe?g|gif";
-
 
1036
			return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i")); 
-
 
1037
		},
1067
      },
1038
		
-
 
1039
		// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
-
 
1040
		equalTo: function(value, element, param) {
-
 
1041
			return value == $(param).val();
-
 
1042
		}
-
 
1043
		
1068
		
-
 
1069
      // http://docs.jquery.com/Plugins/Validation/Methods/accept
-
 
1070
      accept: function(value, element, param) {
-
 
1071
        param = typeof param == "string" ? param : "png|jpe?g|gif";
-
 
1072
        return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
-
 
1073
      },
1044
	}
1074
		
-
 
1075
      // http://docs.jquery.com/Plugins/Validation/Methods/equalTo
-
 
1076
      equalTo: function(value, element, param) {
-
 
1077
        return value == $(param).val();
-
 
1078
      }
-
 
1079
		
-
 
1080
    }
1045
	
1081
	
1046
});
1082
  });
1047
 
1083
 
1048
})(jQuery);
1084
})(jQuery);
1049
 
1085
 
1050
// ajax mode: abort
1086
// ajax mode: abort
1051
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
1087
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
1052
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() 
1088
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() 
-
 
1089
 
1053
;(function($) {
1090
(function($) {
1054
	var ajax = $.ajax;
1091
  var ajax = $.ajax;
1055
	var pendingRequests = {};
1092
  var pendingRequests = {};
1056
	$.ajax = function(settings) {
1093
  $.ajax = function(settings) {
1057
		// create settings for compatibility with ajaxSetup
1094
    // create settings for compatibility with ajaxSetup
1058
		settings = $.extend(settings, $.extend({}, $.ajaxSettings, settings));
1095
    settings = $.extend(settings, $.extend({}, $.ajaxSettings, settings));
1059
		var port = settings.port;
1096
    var port = settings.port;
1060
		if (settings.mode == "abort") {
1097
    if (settings.mode == "abort") {
1061
			if ( pendingRequests[port] ) {
1098
      if ( pendingRequests[port] ) {
1062
				pendingRequests[port].abort();
1099
        pendingRequests[port].abort();
1063
			}
1100
      }
1064
			return (pendingRequests[port] = ajax.apply(this, arguments));
1101
      return (pendingRequests[port] = ajax.apply(this, arguments));
1065
		}
1102
    }
1066
		return ajax.apply(this, arguments);
1103
    return ajax.apply(this, arguments);
1067
	};
1104
  };
1068
})(jQuery);
1105
})(jQuery);
1069
 
1106
 
1070
// provides cross-browser focusin and focusout events
1107
// provides cross-browser focusin and focusout events
1071
// IE has native support, in other browsers, use event caputuring (neither bubbles)
1108
// IE has native support, in other browsers, use event caputuring (neither bubbles)
1072
 
1109
 
1073
// provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
1110
// provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
1074
// handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target 
1111
// handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target 
1075
 
1112
 
1076
// provides triggerEvent(type: String, target: Element) to trigger delegated events
1113
// provides triggerEvent(type: String, target: Element) to trigger delegated events
-
 
1114
 
1077
;(function($) {
1115
(function($) {
1078
	$.each({
1116
  $.each({
1079
		focus: 'focusin',
1117
    focus: 'focusin',
1080
		blur: 'focusout'	
1118
    blur: 'focusout'
1081
	}, function( original, fix ){
1119
  }, function( original, fix ){
1082
		$.event.special[fix] = {
1120
    $.event.special[fix] = {
1083
			setup:function() {
1121
      setup:function() {
1084
				if ( $.browser.msie ) return false;
1122
        if ( $.browser.msie ) return false;
1085
				this.addEventListener( original, $.event.special[fix].handler, true );
1123
        this.addEventListener( original, $.event.special[fix].handler, true );
1086
			},
1124
      },
1087
			teardown:function() {
1125
      teardown:function() {
1088
				if ( $.browser.msie ) return false;
1126
        if ( $.browser.msie ) return false;
1089
				this.removeEventListener( original,
1127
        this.removeEventListener( original,
1090
				$.event.special[fix].handler, true );
1128
          $.event.special[fix].handler, true );
1091
			},
1129
      },
1092
			handler: function(e) {
1130
      handler: function(e) {
1093
				arguments[0] = $.event.fix(e);
1131
        arguments[0] = $.event.fix(e);
1094
				arguments[0].type = fix;
1132
        arguments[0].type = fix;
1095
				return $.event.handle.apply(this, arguments);
1133
        return $.event.handle.apply(this, arguments);
1096
			}
1134
      }
1097
		};
1135
    };
1098
	});
1136
  });
1099
	$.extend($.fn, {
1137
  $.extend($.fn, {
1100
		delegate: function(type, delegate, handler) {
1138
    delegate: function(type, delegate, handler) {
1101
			return this.bind(type, function(event) {
1139
      return this.bind(type, function(event) {
1102
				var target = $(event.target);
1140
        var target = $(event.target);
1103
				if (target.is(delegate)) {
1141
        if (target.is(delegate)) {
1104
					return handler.apply(target, arguments);
1142
          return handler.apply(target, arguments);
1105
				}
1143
        }
1106
			});
1144
      });
1107
		},
1145
    },
1108
		triggerEvent: function(type, target) {
1146
    triggerEvent: function(type, target) {
1109
			return this.triggerHandler(type, [$.event.fix({ type: type, target: target })]);
1147
      return this.triggerHandler(type, [$.event.fix({
-
 
1148
        type: type,
-
 
1149
        target: target
-
 
1150
      })]);
1110
		}
1151
    }
1111
	})
1152
  })
1112
})(jQuery);
1153
})(jQuery);