/**
 * Copyright (c) 2010 Wilker Lúcio
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var __hasProp=Object.prototype.hasOwnProperty;(function($){Array.wrap=function(data){return $.isArray(data)?data:[data];};Array.prototype.extract_options=function(){return $.isPlainObject(this[this.length-1])?this.pop():{};};Array.prototype.isEqual=function(other){var _a,_b,key,value;if(!($.isArray(other))){return false;}
if(this.length!==other.length){return false;}
_a=this;for(key=0,_b=_a.length;key<_b;key++){value=_a[key];if(value!==other[key]){return false;}}
return true;};String.prototype.simple_template_replace=function(options){var _a,key,replacement,text;text=this+"";_a=options;for(key in _a){if(!__hasProp.call(_a,key))continue;replacement=_a[key];text=text.replace(("%{"+(key)+"}"),replacement);}
return text;};String.prototype.uc_first=function(){return this.charAt(0).toUpperCase()+this.substr(1);};String.prototype.camelize=function(){var _a,_b,_c,_d,parts,str;parts=(function(){_a=[];_c=this.split("_");for(_b=0,_d=_c.length;_b<_d;_b++){str=_c[_b];_a.push(str.uc_first());}
return _a;}).call(this);return parts.join('');};$.isString=function(value){return(typeof value)==="string";};window.is_blank=function(object){if(!((typeof object!=="undefined"&&object!==null))){return true;}
if($.isString(object)&&object.replace(/^\s+|\s+$/,'').length===0){return true;}
return false;};window.delete_object_property=function(object,property){var value;value=object[property]||null;delete object[property];return value;};window.object_without_properties=function(object,properties){var _a,_b,_c,obj,property;obj=$.extend({},object);_b=properties;for(_a=0,_c=_b.length;_a<_c;_a++){property=_b[_a];delete obj[property];}
return obj;};window.extract_keys=function(object){var _a,_b,_c,key;_b=[];_c=object;for(key in _c){if(!__hasProp.call(_c,key))continue;_a=_c[key];_b.push(key);}
return _b;};window.slice_object=function(object,keys){var _a,_b,_c,_d,key,obj;obj={};_b=keys;for(_a=0,_c=_b.length;_a<_c;_a++){key=_b[_a];if((typeof(_d=object[key])!=="undefined"&&_d!==null)){obj[key]=object[key];}}
return obj;};return(window.slice_object_and_remove=function(object,keys){var _a,k,obj,v;obj={};_a=object;for(k in _a){if(!__hasProp.call(_a,k))continue;v=_a[k];if($.inArray(k,keys)===-1){obj[k]=object[k];delete object[k];}}
return obj;});})(jQuery);var __bind=function(func,context){return function(){return func.apply(context,arguments);};};(function($){$.FormCheck=function(form,options){this.form=form;this.options=$.extend({prevent_submit:true,field_prefix:null,notifiers:$.FormCheck.default_notifiers,live_notifiers:$.FormCheck.default_live_notifiers,language:$.FormCheck.default_locale},options||{});this.field_cache={};this.errors=new $.FormCheck.Errors(this);this.validations=[];this.hook_events();this.setup_notifiers();return this;};$.FormCheck.prototype.hook_events=function(){var self;this.form.submit(__bind(function(e){var _a,_b,_c,_d,notifier;if(!(this.is_valid())){if(this.options.prevent_submit){e.preventDefault();}
_a=[];_c=this.notifiers;for(_b=0,_d=_c.length;_b<_d;_b++){notifier=_c[_b];_a.push(notifier.notify());}
return _a;}},this));self=this;return this.form.find(":input").each(function(){var field,name;name=self.parse_field_name($(this));if(name){field=self.field(name);return self.options.live_notifiers?(function(el){var f,n;n=name;f=field;el.focus(function(e){self.is_valid();return self.dispatch_live_notifiers("focus",n,e,f.live_notifiers);});return el.blur(function(e){self.is_valid();return self.dispatch_live_notifiers("blur",n,e,f.live_notifiers);});})($(this)):null;}});};$.FormCheck.prototype.dispatch_live_notifiers=function(callback,attribute,event,notifiers){var _a,_b,_c,_d,_e,_f,_g,current_notifiers,n,notifier;current_notifiers=[];_b=notifiers;for(_a=0,_c=_b.length;_a<_c;_a++){n=_b[_a];if(n===":parent"){current_notifiers=current_notifiers.concat(this.live_notifiers);}else{current_notifiers.push(this.get_notifier(n));};}
_d=[];_f=current_notifiers;for(_e=0,_g=_f.length;_e<_g;_e++){notifier=_f[_e];_d.push(notifier[callback](attribute,event));}
return _d;};$.FormCheck.prototype.setup_notifiers=function(){var _a,_b,_c,_d,_e,_f,_g,_h,kind,type;_a=[];_c=["notifiers","live_notifiers"];for(_b=0,_d=_c.length;_b<_d;_b++){type=_c[_b];_a.push((function(){this[type]=[];if(this.options[type]){return(this[type]=(function(){_e=[];_g=this.options[type];for(_f=0,_h=_g.length;_f<_h;_f++){kind=_g[_f];_e.push(this.get_notifier(kind));}
return _e;}).call(this));}}).call(this));}
return _a;};$.FormCheck.prototype.get_notifier=function(notifier){var creator,notifier_class,parameters;parameters=[this];if($.isArray(notifier)){parameters=parameters.concat(notifier.slice(1));notifier=notifier[0];}
if($.isString(notifier)){notifier_class=$.FormCheck.find_notifier(notifier);creator=function(){return notifier_class.apply(this,parameters);};creator.prototype=notifier_class.prototype;return new creator();}else{notifier.form=this;return notifier;}};$.FormCheck.prototype.validate=function(validator){return this.validations.push(validator);};$.FormCheck.prototype.field=function(name){this.field_cache[name]=(typeof this.field_cache[name]!=="undefined"&&this.field_cache[name]!==null)?this.field_cache[name]:new $.FormCheck.Field(this,this.field_name(name),name);return this.field_cache[name];};$.FormCheck.prototype.is_valid=function(){var _a,_b,_c,validation;this.errors.clear();_b=this.validations;for(_a=0,_c=_b.length;_a<_c;_a++){validation=_b[_a];validation(this);}
return this.errors.size()===0;};$.FormCheck.prototype.parse_field_name=function(input){var name;name=input.attr("name");if(!(name)){return null;}
return this.reverse_field_name(name);};$.FormCheck.prototype.reverse_field_name=function(name){var matches;if(this.options.field_prefix){if((matches=name.match(new RegExp((""+(this.options.field_prefix)+"\\[(.+?)\\](.*)"))))){name=matches[1]+(matches[2]||"");}else{name=":"+name;};};return name;};$.FormCheck.prototype.field_name=function(name){var matches,subparts;if((matches=name.match(/^:(.+)/))){return matches[1];}
if(this.options.field_prefix){subparts="";if((matches=name.match(/(.+?)(\[.+)$/))){name=matches[1];subparts=matches[2];}
return""+(this.options.field_prefix)+"["+(name)+"]"+(subparts);}else{return name;}};$.FormCheck.default_locale="en";$.FormCheck.default_notifiers=["notification_dialog"];$.FormCheck.default_live_notifiers=["tip_balloons"];$.FormCheck.Field=function(form,name,attribute){var _a,_b,_c;this.form_checker=form;this.field_name=name;this.attribute=attribute;this.live_notifiers=[":parent"];this.element=this.form_checker.form.find((":input[name='"+(name)+"']"));this.custom_label=null;if(this.form_checker.options.live_notifiers){_b=this.events_for_element();for(_a=0,_c=_b.length;_a<_c;_a++){(function(){var evt=_b[_a];return this.element[evt](__bind(function(e){this.form_checker.is_valid();return this.form_checker.dispatch_live_notifiers("notify",this.attribute,e,this.live_notifiers);},this));}).call(this);}}
return this;};$.FormCheck.Field.prototype.events_for_element=function(){if(this.element.length===0){return[];}
if(this.element.attr("type")==="radio"||this.element.attr("type")==="checkbox"){return["change"];}
if(this.element[0].tagName.toLowerCase()==="select"){return["keyup","change"];}
return["keyup"];};$.FormCheck.Field.prototype.value=function(){if(this.element.attr("type")==="radio"){return this.value_for_radio();}
if(this.element.attr("type")==="checkbox"){return this.value_for_checkbox();}
return this.value_for_text();};$.FormCheck.Field.prototype.value_for_text=function(){return this.element.val()||"";};$.FormCheck.Field.prototype.value_for_radio=function(){return this.element.filter(":checked").val()||"";};$.FormCheck.Field.prototype.value_for_checkbox=function(){return this.element.length>1?$.makeArray(this.element.filter(":checked").map(function(){return $(this).val();})):this.element[0].checked?this.element.val():"";};$.FormCheck.Field.prototype.label=function(){var field_id,label_element,matches;if(!(this.custom_label===null)){if($.isFunction(this.custom_label)){return this.custom_label.call(this);}else{return this.custom_label;}}
field_id=this.element.attr("id");if(this.element.length>1){if((matches=field_id.match(/(.+)_.+$/))){field_id=matches[1];}}
label_element=this.form_checker.form.find(("label[for='"+(field_id)+"']"));return label_element.length>0?label_element.text():this.field_name;};return($.fn.jcheck=function(options){return new $.FormCheck($(this),options||{});});})(jQuery);var __hasProp=Object.prototype.hasOwnProperty,__bind=function(func,context){return function(){return func.apply(context,arguments);};};(function($){$.FormCheck.Errors=function(form){this.form_checker=form;this.clear();return this;};$.FormCheck.Errors.prototype.clear=function(){return(this.errors={});};$.FormCheck.Errors.prototype.add=function(field,message,options){var _a;options=(typeof options!=="undefined"&&options!==null)?options:{};message=(typeof message!=="undefined"&&message!==null)?message:":invalid";this.errors[field]=(typeof this.errors[field]!=="undefined"&&this.errors[field]!==null)?this.errors[field]:[];if((typeof(_a=options.message)!=="undefined"&&_a!==null)){message=options.message;}
message=this.generate_message(message,options);message=message.simple_template_replace(options);return this.errors[field].push(message);};$.FormCheck.Errors.prototype.attributes_with_errors=function(){var _a,attribute,attributes,errors;attributes=[];_a=this.errors;for(attribute in _a){if(!__hasProp.call(_a,attribute))continue;errors=_a[attribute];if(errors.length>0){attributes.push(attribute);}}
return attributes;};$.FormCheck.Errors.prototype.on=function(attribute){this.errors[attribute]=(typeof this.errors[attribute]!=="undefined"&&this.errors[attribute]!==null)?this.errors[attribute]:[];return this.errors[attribute];};$.FormCheck.Errors.prototype.each=function(fn){var _a,_b,_c,_d,_e,_f,attribute,error,errors;_a=[];_b=this.errors;for(attribute in _b){if(!__hasProp.call(_b,attribute))continue;errors=_b[attribute];_a.push((function(){_c=[];_e=errors;for(_d=0,_f=_e.length;_d<_f;_d++){error=_e[_d];_c.push(fn(attribute,error));}
return _c;})());}
return _a;};$.FormCheck.Errors.prototype.size=function(){var _a,attribute,messages,sum;sum=0;_a=this.errors;for(attribute in _a){if(!__hasProp.call(_a,attribute))continue;messages=_a[attribute];sum+=messages.length;}
return sum;};$.FormCheck.Errors.prototype.full_messages=function(){var messages;messages=[];this.each(__bind(function(attribute,message){attribute=this.form_checker.field(attribute).label();return messages.push((""+(attribute)+" "+(message)));},this));return messages;};$.FormCheck.Errors.prototype.generate_message=function(message){var match;return(match=message.match(/^:(.+)/))?$.FormCheck.i18n.translate(("errors.messages."+(match[1])),this.form_checker.options.language):message;};return $.FormCheck.Errors;})(jQuery);var __extends=function(child,parent){var ctor=function(){};ctor.prototype=parent.prototype;child.prototype=new ctor();child.prototype.constructor=child;if(typeof parent.extended==="function")parent.extended(child);child.__superClass__=parent.prototype;},__hasProp=Object.prototype.hasOwnProperty,__bind=function(func,context){return function(){return func.apply(context,arguments);};};(function($){$.FormCheck.Notifiers={};$.FormCheck.Notifiers.create=function(name,object,base){var class_name,notifier;object=$.extend({constructor:function(){},focus:function(){return this.notify.apply(this,arguments);},blur:function(){},notify:function(){}},object||{});base=(typeof base!=="undefined"&&base!==null)?base:$.FormCheck.Notifiers.Base;class_name=name.camelize()+"Notifier";notifier=function(){notifier.__superClass__.constructor.apply(this,arguments);this.constructor.apply(this,arguments);return this;};__extends(notifier,base);$.extend(notifier.prototype,object);notifier.kind=name;$.FormCheck.Notifiers[class_name]=notifier;return notifier;};$.FormCheck.find_notifier=function(kind){var _a,_b,name,notifier;_a=[];_b=$.FormCheck.Notifiers;for(name in _b){if(!__hasProp.call(_b,name))continue;notifier=_b[name];if(notifier.kind===kind){return notifier;}}
return _a;};$.FormCheck.Notifiers.Base=function(form){this.form=form;return this;};$.FormCheck.Notifiers.Base.prototype.focus=function(attribute){};$.FormCheck.Notifiers.Base.prototype.notify=function(attribute){};$.FormCheck.Notifiers.Base.prototype.blur=function(attribute){};$.FormCheck.Notifiers.DialogBase=function(){return $.FormCheck.Notifiers.Base.apply(this,arguments);};__extends($.FormCheck.Notifiers.DialogBase,$.FormCheck.Notifiers.Base);$.FormCheck.Notifiers.DialogBase.prototype.populate_dialog=function(dialog,messages){var _a,_b,_c,html,m;html="<ul>";_b=messages;for(_a=0,_c=_b.length;_a<_c;_a++){m=_b[_a];html+=("<li>* "+(m)+"</li>");}
html+="</ul>";return dialog.html(html);};$.FormCheck.Notifiers.NotificationDialog=function(form,options){$.FormCheck.Notifiers.NotificationDialog.__superClass__.constructor.call(this,form);this.options=$.extend({autoclose_in:4000},options||{});return this;};__extends($.FormCheck.Notifiers.NotificationDialog,$.FormCheck.Notifiers.DialogBase);$.FormCheck.Notifiers.NotificationDialog.prototype.notify=function(){var dialog;dialog=this.generate_dialog();dialog.css({left:"-1000px"});this.populate_dialog(dialog,this.form.errors.full_messages());dialog.css({"margin-top":("-"+(dialog.outerHeight()+10)+"px"),left:"50%","margin-left":("-"+(Math.round(dialog.outerWidth()/2))+"px")});dialog.show();dialog.animate({"margin-top":"0px"});return dialog.mouseout();};$.FormCheck.Notifiers.NotificationDialog.prototype.close_dialog=function(){return this.current_dialog.animate({"margin-top":("-"+(this.current_dialog.outerHeight()+10)+"px")},{complete:function(){return $(this).hide();}});};$.FormCheck.Notifiers.NotificationDialog.prototype.generate_dialog=function(){var dialog,dialog_id;if($.FormCheck.Notifiers.NotificationDialog.dialog_timer){clearTimeout($.FormCheck.Notifiers.NotificationDialog.dialog_timer);}
dialog_id="jcheck-error-dialog";$(("#"+(dialog_id))).remove();dialog=$(document.createElement("div"));dialog.attr("id",dialog_id);this.current_dialog=dialog;if($.browser.msie&&parseInt($.browser.version)<7){dialog.addClass("ie-fixed");}
dialog.click(__bind(function(){return this.close_dialog();},this));if(this.options.autoclose_in){dialog.mouseover(__bind(function(){if($.FormCheck.Notifiers.NotificationDialog.dialog_timer){return clearTimeout($.FormCheck.Notifiers.NotificationDialog.dialog_timer);}},this));dialog.mouseout(__bind(function(){var callback,self;self=this;callback=function(){return self.close_dialog();};return($.FormCheck.Notifiers.NotificationDialog.dialog_timer=setTimeout(callback,this.options.autoclose_in));},this));}
$(document.body).append(dialog);return dialog;};$.FormCheck.Notifiers.NotificationDialog.dialog_timer=0;$.FormCheck.Notifiers.NotificationDialog.kind="notification_dialog";$.FormCheck.Notifiers.TipBalloons=function(form){$.FormCheck.Notifiers.TipBalloons.__superClass__.constructor.call(this,form);this.balloons={};return this;};__extends($.FormCheck.Notifiers.TipBalloons,$.FormCheck.Notifiers.DialogBase);$.FormCheck.Notifiers.TipBalloons.prototype.focus=function(attribute,evt){return this.notify(attribute,evt||null);};$.FormCheck.Notifiers.TipBalloons.prototype.notify=function(attribute,evt){var dialog,element,messages,offset;dialog=this.dialog_for_attribute(attribute);messages=this.form.errors.on(attribute);if(messages.isEqual(dialog.messages)){return null;}
element=evt&&evt.target?$(evt.target):this.form.element;offset=element.offset();if(messages.length>0){if(dialog.messages&&dialog.messages.length>0){this.populate_dialog(dialog,messages);dialog.css({top:(""+(offset.top-dialog.outerHeight())+"px"),left:(""+(offset.left+Math.round(element.outerWidth()*0.9))+"px")});}else{dialog.css({left:"-1000px",top:"-1000px"});dialog.hide();this.populate_dialog(dialog,messages);dialog.css({top:(""+(offset.top-dialog.outerHeight())+"px"),left:(""+(offset.left+Math.round(element.outerWidth()*0.9))+"px")});dialog.fadeIn("fast");}}else{this.close_dialog(attribute);}
return(dialog.messages=messages);};$.FormCheck.Notifiers.TipBalloons.prototype.blur=function(attribute){return this.close_dialog(attribute);};$.FormCheck.Notifiers.TipBalloons.prototype.dialog_for_attribute=function(attribute){if(!(this.balloons[attribute])){this.balloons[attribute]=this.generate_dialog();}
return this.balloons[attribute];};$.FormCheck.Notifiers.TipBalloons.prototype.close_dialog=function(attribute){var dialog;dialog=this.dialog_for_attribute(attribute);dialog.messages=null;return dialog.fadeOut("fast");};$.FormCheck.Notifiers.TipBalloons.prototype.generate_dialog=function(){var arrow,content_area,dialog;dialog=null;dialog=$(document.createElement("div"));dialog.addClass("jcheck-inline-balloon-tip");dialog.css({position:"absolute",top:"-1000px",left:"-1000px"});content_area=$(document.createElement("div"));content_area.addClass("content");dialog.append(content_area);arrow=this.generate_arrow();dialog.append(arrow);$(document.body).append(dialog);return dialog;};$.FormCheck.Notifiers.TipBalloons.prototype.generate_arrow=function(){var center,container,i,line,max_width,x;i=10;container=$(document.createElement("div"));container.addClass("arrow-container");center=i/2;max_width=null;while(i>0){x=i*2-center;if(x<0){x=center+x-1;}
line=$(document.createElement("div"));line.addClass(("line"+(i)));line.css({'font-size':0,width:(""+(x)+"px"),height:"1px",margin:"0 auto"});container.append(line);i-=1;}
return container;};$.FormCheck.Notifiers.TipBalloons.prototype.populate_dialog=function(dialog,messages){return $.FormCheck.Notifiers.TipBalloons.__superClass__.populate_dialog.call(this,dialog.find(".content"),messages);};return($.FormCheck.Notifiers.TipBalloons.kind="tip_balloons");})(jQuery);var __hasProp=Object.prototype.hasOwnProperty,__extends=function(child,parent){var ctor=function(){};ctor.prototype=parent.prototype;child.prototype=new ctor();child.prototype.constructor=child;if(typeof parent.extended==="function")parent.extended(child);child.__superClass__=parent.prototype;},__slice=Array.prototype.slice;(function($){$.FormCheck.Validations={};$.FormCheck.find_validator=function(kind){var _a,k,validator;_a=$.FormCheck.Validations;for(k in _a){if(!__hasProp.call(_a,k))continue;validator=_a[k];if(validator.kind===kind){return validator;}}
return null;};$.FormCheck.Validator=function(options){this.options=options;return this;};$.FormCheck.Validator.prototype.kind=function(){};$.FormCheck.Validator.prototype.validate=function(form){};$.FormCheck.EachValidator=function(options){this.attributes=Array.wrap(delete_object_property(options,"attributes"));if(options["allow_nil"]){options["allow_blank"]=true;}
if(options["allow_blank"]){options["allow_nil"]=true;}
$.FormCheck.EachValidator.__superClass__.constructor.call(this,options);this.check_valitity();return this;};__extends($.FormCheck.EachValidator,$.FormCheck.Validator);$.FormCheck.EachValidator.prototype.validate=function(form){var _a,_b,_c,_d,attribute,value;_a=[];_c=this.attributes;for(_b=0,_d=_c.length;_b<_d;_b++){attribute=_c[_b];value=form.field(attribute).value();if(is_blank(value)&&this.options["allow_blank"]){continue;}
this.validate_each(form,attribute,value);}
return _a;};$.FormCheck.EachValidator.prototype.validate_each=function(record,attribute,value){};$.FormCheck.EachValidator.prototype.check_valitity=function(){};$.FormCheck.prototype.validates_with=function(){var _c,_d,_e,_f,validators;var _a=arguments.length,_b=_a>=2,options=arguments[_b?_a-1:0];validators=__slice.call(arguments,0,_a-1);_c=[];_e=validators;for(_d=0,_f=_e.length;_d<_f;_d++){(function(){var validator;var validator_klass=_e[_d];return _c.push((function(){validator=new validator_klass(options);return this.validate(function(form){return validator.validate(form);});}).call(this));}).call(this);}
return _c;};$.FormCheck.prototype.attributes_for_with=function(attributes){var options;options=attributes.extract_options();return $.extend(options,{attributes:attributes});};$.FormCheck.Validator.create=function(name,object,base){var class_name,validator;object=$.extend({constructor:function(){}},object||{});base=(typeof base!=="undefined"&&base!==null)?base:$.FormCheck.EachValidator;class_name=name.camelize()+"Validator";validator=function(){validator.__superClass__.constructor.apply(this,arguments);this.constructor.apply(this,arguments);return this;};__extends(validator,base);$.extend(validator.prototype,object);validator.kind=name;$.FormCheck.Validations[class_name]=validator;$.FormCheck.prototype[("validates_"+(name)+"_of")]=function(){var attributes;attributes=__slice.call(arguments,0);return this.validates_with(validator,this.attributes_for_with(attributes));};return validator;};$.FormCheck.Validations.BlockValidator=function(options){this.callback=delete_object_property(options,'callback')||$.noop;$.FormCheck.Validations.BlockValidator.__superClass__.constructor.call(this,options);return this;};__extends($.FormCheck.Validations.BlockValidator,$.FormCheck.EachValidator);$.FormCheck.Validations.BlockValidator.prototype.validate_each=function(form,attribute,value){return this.callback.call(this,form,attribute,value);};$.FormCheck.prototype.validates_each=function(){var attributes,options;attributes=__slice.call(arguments,0);options=this.attributes_for_with(attributes);if($.isFunction(options.attributes[options.attributes.length-1])){options.callback=attributes.pop();};return this.validates_with($.FormCheck.Validations.BlockValidator,options);};$.FormCheck.Validations.AcceptanceValidator=function(options){$.FormCheck.Validations.AcceptanceValidator.__superClass__.constructor.call(this,$.extend({accept:'1'},options));return this;};__extends($.FormCheck.Validations.AcceptanceValidator,$.FormCheck.EachValidator);$.FormCheck.Validations.AcceptanceValidator.prototype.validate_each=function(form,attribute,value){if(!(value===this.options.accept)){return form.errors.add(attribute,":accepted",object_without_properties(this.options,['accept','allow_nil']));}};$.FormCheck.Validations.AcceptanceValidator.kind="acceptance";$.FormCheck.prototype.validates_acceptance_of=function(){var attributes;attributes=__slice.call(arguments,0);return this.validates_with($.FormCheck.Validations.AcceptanceValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.ConfirmationValidator=function(){return $.FormCheck.EachValidator.apply(this,arguments);};__extends($.FormCheck.Validations.ConfirmationValidator,$.FormCheck.EachValidator);$.FormCheck.Validations.ConfirmationValidator.prototype.validate_each=function(form,attribute,value){var confirmed,confirmed_field_name;confirmed_field_name=attribute+"_confirmation";confirmed=form.field(confirmed_field_name).value();if(!(value===confirmed)){return form.errors.add(confirmed_field_name,":confirmation",this.options);}};$.FormCheck.Validations.ConfirmationValidator.kind="confirmation";$.FormCheck.prototype.validates_confirmation_of=function(){var attributes;attributes=__slice.call(arguments,0);return this.validates_with($.FormCheck.Validations.ConfirmationValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.ExclusionValidator=function(){return $.FormCheck.EachValidator.apply(this,arguments);};__extends($.FormCheck.Validations.ExclusionValidator,$.FormCheck.EachValidator);$.FormCheck.Validations.ExclusionValidator.prototype.validate_each=function(form,attribute,value){if($.inArray(value,this.options["in"])>-1){return form.errors.add(attribute,":exclusion",$.extend(object_without_properties(this.options,['in']),{value:value}));}};$.FormCheck.Validations.ExclusionValidator.kind="exclusion";$.FormCheck.prototype.validates_exclusion_of=function(){var attributes;attributes=__slice.call(arguments,0);return this.validates_with($.FormCheck.Validations.ExclusionValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.FormatValidator=function(options){var _a,_b,_c,_d,opt;_b=["with","without"];for(_a=0,_c=_b.length;_a<_c;_a++){opt=_b[_a];if((typeof(_d=options[opt])!=="undefined"&&_d!==null)&&$.isString(options[opt])){options[opt]=$.FormCheck.Validations.FormatValidator.FORMATS[options[opt]];}}
$.FormCheck.Validations.FormatValidator.__superClass__.constructor.call(this,options);return this;};__extends($.FormCheck.Validations.FormatValidator,$.FormCheck.EachValidator);$.FormCheck.Validations.FormatValidator.prototype.validate_each=function(form,attribute,value){if(this.options["with"]&&!((value+"").match(this.options["with"]))){form.errors.add(attribute,":invalid",$.extend(object_without_properties(this.options,['with']),{value:value}));};return this.options["without"]&&(value+"").match(this.options["without"])?form.errors.add(attribute,":invalid",$.extend(object_without_properties(this.options,['without']),{value:value})):null;};$.FormCheck.Validations.FormatValidator.FORMATS={email:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,url:/^[A-Za-z]+:\/\/[A-Za-z0-9-_]+(\.[a-zA-Z0-9]+)+(:\d+)?[A-Za-z0-9-_%&\?\/.=]+$/};$.FormCheck.Validations.FormatValidator.kind="format";$.FormCheck.prototype.validates_format_of=function(){var attributes;attributes=__slice.call(arguments,0);return this.validates_with($.FormCheck.Validations.FormatValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.InclusionValidator=function(){return $.FormCheck.EachValidator.apply(this,arguments);};__extends($.FormCheck.Validations.InclusionValidator,$.FormCheck.EachValidator);$.FormCheck.Validations.InclusionValidator.prototype.validate_each=function(form,attribute,value){if($.inArray(value,this.options["in"])===-1){return form.errors.add(attribute,":inclusion",$.extend(object_without_properties(this.options,['in']),{value:value}));}};$.FormCheck.Validations.InclusionValidator.kind="inclusion";$.FormCheck.prototype.validates_inclusion_of=function(){var attributes;attributes=__slice.call(arguments,0);return this.validates_with($.FormCheck.Validations.InclusionValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.LengthValidator=function(options){$.FormCheck.Validations.LengthValidator.__superClass__.constructor.call(this,$.extend({tokenizer:$.FormCheck.Validations.LengthValidator.DEFAULT_TOKENIZER},options));return this;};__extends($.FormCheck.Validations.LengthValidator,$.FormCheck.EachValidator);$.FormCheck.Validations.LengthValidator.prototype.validate_each=function(form,attribute,value){var _a,_b,_c;if($.isString(value)){value=this.options.tokenizer(value);}
if(this.options["is"]&&this.options["is"]!==value.length){if((typeof(_a=this.options["wrong_length"])!=="undefined"&&_a!==null)){this.options["message"]=(typeof this.options["message"]!=="undefined"&&this.options["message"]!==null)?this.options["message"]:this.options["wrong_length"];}
form.errors.add(attribute,":wrong_length",$.extend(object_without_properties(this.options,$.FormCheck.Validations.LengthValidator.RESERVED_OPTIONS),{count:this.options["is"]}));}
if(this.options["minimum"]&&this.options["minimum"]>value.length){if((typeof(_b=this.options["too_short"])!=="undefined"&&_b!==null)){this.options["message"]=(typeof this.options["message"]!=="undefined"&&this.options["message"]!==null)?this.options["message"]:this.options["too_short"];}
form.errors.add(attribute,":too_short",$.extend(object_without_properties(this.options,$.FormCheck.Validations.LengthValidator.RESERVED_OPTIONS),{count:this.options["minimum"]}));}
if(this.options["maximum"]&&this.options["maximum"]<value.length){if((typeof(_c=this.options["too_long"])!=="undefined"&&_c!==null)){this.options["message"]=(typeof this.options["message"]!=="undefined"&&this.options["message"]!==null)?this.options["message"]:this.options["too_long"];}
return form.errors.add(attribute,":too_long",$.extend(object_without_properties(this.options,$.FormCheck.Validations.LengthValidator.RESERVED_OPTIONS),{count:this.options["maximum"]}));}};$.FormCheck.Validations.LengthValidator.DEFAULT_TOKENIZER=function(value){return value.split('');};$.FormCheck.Validations.LengthValidator.RESERVED_OPTIONS=["minimum","maximum","is","tokenizer","too_long","too_short"];$.FormCheck.Validations.LengthValidator.kind="length";$.FormCheck.prototype.validates_length_of=function(){var attributes;attributes=__slice.call(arguments,0);return this.validates_with($.FormCheck.Validations.LengthValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.NumericalityValidator=function(){return $.FormCheck.EachValidator.apply(this,arguments);};__extends($.FormCheck.Validations.NumericalityValidator,$.FormCheck.EachValidator);$.FormCheck.Validations.NumericalityValidator.prototype.validate_each=function(form,attribute,value){var _a,_b,check,raw_value,val;raw_value=value;value=parseFloat(value);if(isNaN(value)||!(raw_value.match(/\d+$/))){form.errors.add(attribute,":not_a_number",this.filtered_options(raw_value));return null;}
if(this.options.only_integer&&!(raw_value.match(/^[-]?\d+$/))){form.errors.add(attribute,":not_an_integer",this.filtered_options(raw_value));return null;}else{value=parseInt(value);}
_a=[];_b=slice_object(this.options,extract_keys($.FormCheck.Validations.NumericalityValidator.CHECKS));for(check in _b){if(!__hasProp.call(_b,check))continue;val=_b[check];_a.push((function(){if(check==="odd"||check==="even"){if(!($.FormCheck.Validations.NumericalityValidator.CHECKS[check](value))){return form.errors.add(attribute,":"+check,this.filtered_options(val));}}else{if(!($.FormCheck.Validations.NumericalityValidator.CHECKS[check](value,val))){return form.errors.add(attribute,":"+check,this.filtered_options(val));}}}).call(this));}
return _a;};$.FormCheck.Validations.NumericalityValidator.prototype.filtered_options=function(value){return $.extend(object_without_properties(this.options,$.FormCheck.Validations.NumericalityValidator.RESERVED_OPTIONS),{count:value});};$.FormCheck.Validations.NumericalityValidator.CHECKS={greater_than:function(a,b){return a>b;},greater_than_or_equal_to:function(a,b){return a>=b;},equal_to:function(a,b){return a===b;},less_than:function(a,b){return a<b;},less_than_or_equal_to:function(a,b){return a<=b;},odd:function(n){return(n%2)===1;},even:function(n){return(n%2)===0;}};$.FormCheck.Validations.NumericalityValidator.RESERVED_OPTIONS=extract_keys($.FormCheck.Validations.NumericalityValidator.CHECKS).concat(["only_integer"]);$.FormCheck.Validations.NumericalityValidator.kind="numericality";$.FormCheck.prototype.validates_numericality_of=function(){var attributes;attributes=__slice.call(arguments,0);return this.validates_with($.FormCheck.Validations.NumericalityValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.PresenceValidator=function(){return $.FormCheck.EachValidator.apply(this,arguments);};__extends($.FormCheck.Validations.PresenceValidator,$.FormCheck.EachValidator);$.FormCheck.Validations.PresenceValidator.prototype.validate_each=function(form,attribute,value){if(is_blank(value)){return form.errors.add(attribute,":blank",this.options);}};$.FormCheck.Validations.PresenceValidator.kind='presence';$.FormCheck.prototype.validates_presence_of=function(){var attributes;attributes=__slice.call(arguments,0);return this.validates_with($.FormCheck.Validations.PresenceValidator,this.attributes_for_with(attributes));};$.FormCheck.prototype.validates=function(){var _a,_b,attributes,current_options,defaults,kind,options,validations,validator;attributes=__slice.call(arguments,0);defaults=attributes.extract_options();validations=slice_object_and_remove(defaults,["if","unless","allow_blank","allow_nil"]);$.extend(defaults,{attributes:attributes});_a=[];_b=validations;for(kind in _b){if(!__hasProp.call(_b,kind))continue;options=_b[kind];_a.push((function(){validator=$.FormCheck.find_validator(kind);current_options=$.extend({},defaults);return validator?this.validates_with(validator,$.extend(current_options,$.FormCheck.parse_validates_options(options))):null;}).call(this));}
return _a;};return($.FormCheck.parse_validates_options=function(options){var _a;if($.isArray(options)){return{"in":options};}
if((typeof(_a=options.test)!=="undefined"&&_a!==null)){return{"with":options};}
if(options===true){return{};}
if($.isPlainObject){return options;}
return{};});})(jQuery);(function($){return($.FormCheck.i18n={default_language:"en",translate:function(path,language){var steps;language=(typeof language!=="undefined"&&language!==null)?language:$.FormCheck.i18n.default_language;steps=path.split(".");steps.unshift(language);return $.FormCheck.i18n.translation_from_path(steps);},translation_from_path:function(steps){var _a,_b,_c,current,step;current=$.FormCheck.i18n.languages;_b=steps;for(_a=0,_c=_b.length;_a<_c;_a++){step=_b[_a];current=current[step];if(!((typeof current!=="undefined"&&current!==null))){return"";}}
return current;},languages:{}});})(jQuery);jQuery.FormCheck.i18n.languages["en"]={errors:{messages:{inclusion:"%{value} is not a valid option",exclusion:"%{value} is reserved",invalid:"is invalid",confirmation:"doesn't match confirmation",accepted:"must be accepted",empty:"can't be empty",blank:"can't be blank",too_long:"is too long (maximum is %{count} characters)",too_short:"is too short (minimum is %{count} characters)",wrong_length:"is the wrong length (should be %{count} characters)",not_a_number:"is not a number",not_an_integer:"must be an integer",greater_than:"must be greater than %{count}",greater_than_or_equal_to:"must be greater than or equal to %{count}",equal_to:"must be equal to %{count}",less_than:"must be less than %{count}",less_than_or_equal_to:"must be less than or equal to %{count}",odd:"must be odd",even:"must be even"}}};
