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

jQuery(function() {
  jQuery('#registration_previous_vendor').bind('change', updateNumYears);
  
  jQuery('a.accept').bind('click', showAcceptDialog);
  jQuery('a.deny').bind('click', showDenyDialog);
  jQuery('a.cancel_button').bind('click', showAcceptDenyButtons);
  
  jQuery('#accept_dialog').hide();
  jQuery('#deny_dialog').hide();
  
  jQuery('a#show_why_full_product_detail').bind('click', showProductDetailDialog);
  jQuery('a#hide_why_full_product_detail').bind('click', hideProductDetailDialog);  
  jQuery('#why_full_product_detail').hide();
  
  updateNumYears();
});

function showAcceptDialog(){
  jQuery('#accept_deny_links').hide();
  jQuery('#accept_dialog').show();
  return false;
}

function showProductDetailDialog(){
  jQuery('a#show_why_full_product_detail').hide();
  jQuery('fieldset#why_full_product_detail').fadeIn();
  return false; 
}

function hideProductDetailDialog(){
  jQuery('a#show_why_full_product_detail').show();
  jQuery('fieldset#why_full_product_detail').hide();
  return false;
}

function showAcceptDenyButtons(){
  jQuery('#accept_deny_links').show();
  jQuery('#accept_dialog').hide();
  jQuery('#deny_dialog').hide();
  return false;
}

function showDenyDialog(){
  jQuery('#accept_deny_links').hide();
  jQuery('#deny_dialog').show();
  return false;
}

function updateNumYears() {
  p = jQuery('#registration_previous_vendor')[0];
  if(p && p.value == 'true')
    jQuery('#num_years').fadeIn();
  else
    jQuery('#num_years').hide();
}