window.OOS=window.OOS||{};OOS.Slug_validator={input:null,input_container:null,timer:null,initialize:function(input_element){if(input_element===null){return false;}this.input=input_element;this.input.observe("keyup",this._check_slug_availability.bindAsEventListener(this));this.input.observe("change",this._check_slug_size.bindAsEventListener(this));},_check_slug_availability:function(){if(this.timer==null){this.timer=window.setTimeout(this._perform_request,1000);}},_check_slug_size:function(e){var elto=e.element();if(elto.getValue().length<3){this._show_error_msg(_("mínimo 3 caracteres"));}},_perform_request:function(){OOS.Slug_validator.timer=null;var slug=OOS.Slug_validator.input.getValue();if(slug.length>=3){new Ajax.Request("/check-url-availability",{method:"post",parameters:{url:slug,subject:"joaquin"},onSuccess:function(transport){if(transport.responseText.blank()){OOS.Slug_validator._show_error_msg();}else{OOS.Slug_validator._show_error_msg(transport.responseText);}}});}else{return true;}},_show_error_msg:function(msg){var slug_error=$("slug-error");if(msg==undefined){slug_error.remove();}else{if(slug_error){slug_error.update(msg);}else{var slug_error=new Element("p",{id:"slug-error",className:"error"});slug_error.setStyle({clear:"both"});OOS.Slug_validator.input.up().insert(slug_error);slug_error.update(msg);}}}};
