// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


Ajax.Responders.register({
  onCreate: function() {
    if($('busy') && Ajax.activeRequestCount>0) {
      showActivityIndicator();     
    }            
  },
  onComplete: function() {
    if($('busy') && Ajax.activeRequestCount==0) {
      hideActivityIndicator();
    }
  }
});


function help(id) {
  $(id).toggle();
}



function guide(obj) {     
  if (target = $('guide_'+obj.id)) {    
    //target.style.visibility = 'visible';
    target.style.display = 'block';
  }     
}


function unguide(obj) {   
  if (target = $('guide_'+obj.id)) {    
    //target.style.visibility = 'hidden';
    target.style.display = 'none';
  }
}


function addGuide(name) {
  // e.g. name="user[dob(3i)]"  
  obj = document.forms[0].elements[name];
  obj.onfocus = function () { 
    if (target = $('guide_'+this.name)) {    
      target.style.display = 'inline';
    }       
  }
  
  obj.onblur = function () {
    if (target = $('guide_'+this.name)) {    
      target.style.display = 'none';
    }
  }      
}



function addGuideById(id) {
  // e.g. name="user[dob(3i)]"  
  obj = $(id);
  obj.onfocus = function () { 
    if (target = $('guide_'+this.id)) {    
      target.style.display = 'inline';
    }       
  }
  
  obj.onblur = function () {
    if (target = $('guide_'+this.id)) {    
      target.style.display = 'none';
    }
  }      
}


function showActivityIndicator() {
  Effect.Appear('busy',{duration:0.5,queue:'end'});  
  document.getElementsByTagName('html').item(0).style.cursor = 'progress';   
}


function hideActivityIndicator() {
  Effect.Fade('busy',{duration:0.5,queue:'end'});      
  document.getElementsByTagName('html').item(0).style.cursor = 'auto';
}


function highlightAnchor() {
  var id = (arguments.length > 0) ? arguments[0] : false;
  if ((!id) && (self.document.location.hash != '')) {
    id = self.document.location.hash.substring(1);
    if (!($(id))) {
      id = (element = $$('a[name="'+id+'"]').first() )  ? element : false;      
    }    
  }
  if (id) {      
    new Effect.Highlight(id,{duration: 6});
  }  
}

