// Javascript UI classes for easier effects
// Requires prototyp 1.6.0 or higher

var Watermark = Class.create({
  initialize: function(target, value) {
    this.element = $(target);
    this.element.observe('focus',this.onFocus.bind(this));
    this.element.observe('blur',this.onBlur.bind(this));
    this.textValue = value;
    
    if(this.element.value == '')
        this.element.value = this.textValue;
  },
  onFocus: function(evt){
    this.clearDefault();
  },
  onBlur: function(evt){
    this.reset();
  },
  clearDefault: function() { // Clears the field IF it contains the default text   
    if(this.element.value == this.textValue)
        this.element.value = '';
  },
  reset: function(element) {// Called in conjunction with clearDefault. Sets default text if clear
    if(this.element.value == '')
        this.element.value = this.textValue;
  }
});

// Take
// target - the element id or reference to the image
// imgOffSrc - the src that is visible when the mouse is not over the image.
// imgOnSrc - the src that is visible when the mouse is over the image.

var Rollover = Class.create({
  initialize: function(target, imgOffSrc, imgOnSrc) {
    this.element = $(target);
    this.imgOffSrc = imgOffSrc;
    this.imgOnSrc = imgOnSrc;
    
    this.element.observe('mouseover',this.onMouseOver.bind(this));
    this.element.observe('mouseout',this.onMouseOut.bind(this));
    
  },
  onMouseOut: function(evt){
    this.element.src = this.imgOffSrc;
  },
  onMouseOver: function(evt){
    this.element.src = this.imgOnSrc;
  }
});

var CaptureEnterAndSubmit = Class.create({
  initialize: function(target, form) {  
    this.element = $(target);
    this.form = form;
    if(!form)
        this.form = document.forms[0];
    
     Event.observe(this.element,'keydown', this.onEnter.bindAsEventListener(this));
    
  },
  onEnter: function(evt){

    if(evt.keyCode == Event.KEY_RETURN)
    {
        this.form.submit();
        evt.stop();                                                           
        return false;
    }
  }  
});




/**** Prototype Extensions ****/

var methods = {
   getInnerText: function(element){     
        element = $(element);     

        if(element.innerText){
            return element.innerText.trim();
        } else{
            return element.textContent.trim();
        }
    }
}

//Array.addMethods();
Element.addMethods(methods);

Array.prototype.remove=function(item){
	for (i=0; i < this.length; i++){
		if (item == this[i]) this.splice(i, 1);
	}
}
