// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//Validator Object based on LiveValidation Framework. 
//author: jun tsai AT Gamil.com
//2009-04-17
Validator = Class.create();
Validator.prototype={
  initialize: function(fid){
    el=$(fid);
    this.lv=new LiveValidation(el,{
      onInvalid:function() {
              if (this.element.prototip) {
                  this.element.prototip.content = this.message;
                  //update prototip message
                  Element.update(this.element.prototip.tip,this.message);
              } else {
                  //create element prototip object,bind current element
                   this.element.prototip=new Tip(this.element, this.message, {
                      border:1,
                      radius:3,
                      style: 'creamy',
                      stem:'bottomLeft',
                      hook: { target: 'topMiddle',tip: 'bottomRight', mouse: false},
                      offset: { x: -30, y: 0},
                      width:'100px'
                    });
              }
              this.addFieldClass();

          },
          onValid:function(){
              if(this.element.prototip){
                  //remove prototip object from current element
                  Tips.remove(this.element);//this.element.prototip.remove();
              }
              //change style sheet class
              this.addFieldClass();
        },
        onlyOnBlur:true
    });
    return this;
  },
  required: function(){
    this.lv.add(Validate.Presence,{failureMessage:'输入内容为空！'});
    return this;
  },
  email: function(){
    this.lv.add(Validate.Email,{failureMessage:'不是Email地址！'});
    return this;
  }

}
