/*
 * APPLICATION SPECIFIC JAVASCRIPT
 */


function toggleCheckBoxBySelector(box, class_name )
{
  $$( class_name ).each(function(e){
    e.checked = box.checked;
  }); 
  
}

function categoryToggle(a)
{
  li = $(a).up('li');
  
  li.toggleClassName('expanded');
  
  Effect.toggle(li.down('div'));
  //li.down('div').toggle();
  
  return false;
  
}

function hideCoupon(coupon_id, msg)
{
  coupon = $(coupon_id);

  $$( '#' + coupon.id + ' .description').each(function(el) {
    el.innerHTML = msg;  
    new Effect.Highlight(el, {
      afterFinish: function() { new Effect.Fade(coupon); } 
    });
  });
  

}


function printCoupons(a, url)
{
  //window.open(a.href, 'print', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=800,height=600,top=1,left=1');
  if (!confirm("Please note:  Once you select OK below, and the print request is created, the coupon(s) you have selected to print will no longer be available in your online coupon account.  You will not be able to view, clip or print the offer(s) again.  If you are not sure you would like to print at this time, please select CANCEL.  Please keep all printed coupons in a safe place so they are available for your use when needed.\n\nCoupons are intended for use only by authorized accountholders and are void if copied, reproduced or altered in any manner.  Unauthorized transfer, distribution (electronically or by any other means), and/or reproduction is expressly prohibited.  Any such misuse constitutes fraud and will result in permanent suspension of this benefit service.  Any merchant who suspects misuse has the right to refuse acceptance of the coupon(s).\n\nDo you want to continue?"))
  {
    return false;
  }
  return true;
}


var initFooter = function()
{
  $$('#footer a').each( function(a) {
    a.onmouseover = function() {
      a.down('.down').setStyle({ display: 'none' });
      a.down('.up').setStyle({ display: 'inline' });
    }
    a.onmouseout = function() {
      a.down('.down').setStyle({ display: 'inline' });
      a.down('.up').setStyle({ display: 'none' });
    }
  });
}

Event.observe(window, 'load', initFooter );


var initCouponListings = function()
{
  
  $$('.coupon .buttons a').each(function(el) {
    el.onclick = function() { new Ajax.Request(el.href); return false; }
  });
  
  $$('.coupon').each(function(el){
    el.onmouseover = function() { el.addClassName('hover'); }
    el.onmouseout = function() { el.removeClassName('hover'); }
  });

  $$('.listings .heading').each(function(el){
    el.onclick = function(){
      return categoryToggle(el)
    }
  });

}

Event.observe(window, 'load', initCouponListings );

var doPrint = function ()
{
  images = $$('img');
  
  if (images.length == 0 )
  {
    window.close();
    return; 
  }
  window.print();
  window.location = '/account/';
  
}

var initOutsideLinks = function()
{
  $$('a.outside').each(function(el){
    el.target = '_blank';
    el.onclick = function() {
      return confirm('You are about to view a website outside of lmdbonline.com.  This site link is provided only as a reference tool.  Its content does not represent Mercantile Bank and the Bank may not be held liable.  Please select OK to continue.');
    }
  }); 
}
Event.observe(window, 'load', initOutsideLinks );
