//////// DECLARE METHODS ///////

function calcExactYears (obj)
  {
    return new Date().getFullYear() -1921;
  }

// RADAR: legacy code! Unused call from site footer
function exactYears (obj)
  {
    //obj.write(calcExactYears);
  }


//////// REQ JQUERY ////////

$(document).ready(
  function()
    {

    //////// CONDITIONAL EXECUTION ////////

    $('#homepage #content').append('<a id="splash" href="http://faces.sansumclinic.org"></a>');
    
    
    $.tablesorter.defaults.widgets = ['zebra']; // add zebra striping
    $('table.sortable').tablesorter(
      {
       
      headers:
        { // turn off sorting of these two columns because they refuse to sort correctly  ALERT: brittle when more sortable tables eventually get added
        2: { sorter: false }, 
        3: { sorter:false }
        }
      }
    );
    
    if ($('#homepage #headlines ul li')[2]) {$('#homepage #courses ul li')[5].innerHTML=''; $('#homepage #courses ul li')[2].innerHTML='';}; // when there's an excess of news, reduce course listings to 2 per city to ensure layout doesn't break

    $('table table table a[name=attach]').append('<div class="alert"><i>Resume file attachment may be up to 1.4MB in size.</i></div>');

    if($('#cv'))
    {
      //hide "Education" section when it's empty
      a=$.grep(
        $('#cv'), function(e)
        {
          return e.innerHTML.match(/<h2>Education<\/h2>\s*<ul><\/ul>/);
        }
        )[0];
      if(a)
        {
          a.innerHTML=a.innerHTML.replace(/<h2>Education<\/h2>\s*<ul><\/ul>/, "");
        }

      //hide photo placeholder when it's empty
      $('#cv .picture_frame img[src=/ContentStore/photo_unavailable.gif]').parent().hide();
      a=$.grep(
        $('#cv li'), function(e)
        {
          return e.innerHTML.match(/(Cum Laude)|(Highest Departmental Honors)|(Highest Honors)|(Magna Cum Laude)|(Summa Cum Laude)|(With Distinction)|(With Honors)$/);
        }
        )[0];
      if(a)
        {
          a.innerHTML=a.innerHTML.replace(/,([^,]+)$/, ", <i>$1</i>");
        }
    }

   if((location.pathname + location.search == "/site.asp?app=500&page=1"))
   {
     $('div.message:contains(No matches found for)').append(' Or you may prefer to <a href="http://sansumclinic.org/site.asp?s=9&id=2DA9FDBFE52C4B059593D4E5AEF7A77A&actapp=8a">browse the list of physicians and other healthcare providers</a>.');
   }

    //////////// ALWAYS DO THESE ////////////

    //** update org age statements throughout page
    for (var i=0; i < $('span.org_age').length; i++)
      {
        $('span.org_age')[i].innerHTML=calcExactYears();
      };

    //** update footer separately since jQuery doesn't recognize it above as a 'span.org_age'
    $('.description strong').text("For " + calcExactYears() + " years we've been bringing world-class physicians to Santa Barbara County.");

      if ($('form#donor') && $('form#donor').length > 0) {
        $('form#donor .notice').html('<em>(starred fields are required)</em>');
        $('form#donor th')[0].childNodes[0].nodeValue='Contact Sansum Clinic Philanthropy';
        $('.begin_fundraising').html('<div id="because_you_give"><p>Because you give,</p><p>we can give back.</p></div><p id="giving_matters"><strong>Your philanthropic partnership with us matters.</strong> Your gift, of any amount, makes a tangible difference. Your support extends the gift of good health to thousands of individuals every year. <strong>We can never say <em>thank you</em> enough!</strong></p><p id="tax_deduction">Because we are a nonprofit <span class="keeptogether">501(c)(3)</span> foundation, your donation is also tax-deductible to the fullest extent allowed by law. Our federal tax ID # is <span class="keeptogether">95-6419205</span>.  Thank you for improving the health of Santa Barbara through your generous donation to Sansum Clinic. To discuss additional ways you can help, please call <strong>Sansum Clinic Philanthropy</strong> at (805) 681-7762.</p><br class="nofloat"></div>');
      }

}
);
