// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
Event.observe(window, "load", function(){
  
  Event.observe("help_link","click",function(e){
    toggle_help();
    e.stop();
  });
  
  if($("my_lollis_link")) {
    Event.observe("my_lollis_link","click",function(e){
      toggle_my_lollis();
      e.stop();
    });
  }

  Event.observe(document,"click",function(e){
    if($('help_dropdown')){
        if($('help_dropdown').visible()) {
          toggle_help();
        };
    }
    if($('my_lollis_dropdown')){
        if($('my_lollis_dropdown').visible()) {
          toggle_my_lollis();
        };
    }
  })

  function toggle_help(){
    $('help_dropdown').toggle();
  }
  
  function toggle_my_lollis(){
    $('my_lollis_dropdown').toggle();
  }
  
  // nice little maxlength function to limit the amount of characters in a textarea
  $$('textarea').each(function(e){
    Event.observe(e, "keyup", function() {
      var max_length = this.readAttribute('maxlength')
      //console.log("max length = "+max_length)
      //console.log(this.value.length)
      // added "max_length > 0" requirement because in "edit card" interface 
      // this  was deleting ALL character input. - MFIG
      if(max_length > 0 && this.value.length > max_length) {
        this.value = this.value.substring(0,max_length)
      }
    })
  });

})

function strip_non_numbers(arg){
    //return arg.replace(/\D/g, "")
    //return arg.replace(/[0-9|.]/g, "")
    returnvalue = "";
    for (i = 0; i < arg.length; i++){
        if (arg.charAt(i) == "."){
            returnvalue += ".";
        } else {
            returnvalue += arg.charAt(i).replace(/\D/g, "");
        }
    }
    return returnvalue;
}
