/* after a sale is removed from "My Sales" using link_to_remote */
function ss_postRemoveMySale(ani) {
  // hide the marker assoc with the clicked sale
  var saleid = ani.element.id.match(/(\d+)$/);
  markerGroup.markersById[saleid[0]].hide();

  // if it was the last sale, show a message
  var wfsale = document.getElementById('wfsale');
  for (i=0; i<wfsale.childNodes.length; i++) {
    if (wfsale.childNodes[i].tagName == 'DIV' && wfsale.childNodes[i].className == 'fsale' && wfsale.childNodes[i].style.display != 'none') {
      return true;
    }
  }
  // TODO shouldnt use innerHTML or any of this but oh well.
  wfsale.innerHTML = '<div class="userStatement">You have no more Saved Stoopsales</div>';
  wfsale.style.border = 'none'; // bad hack
}

/* after a pic is removed from a sale in preview action */
function ss_postRemovePic(ani) {
  // show the Add Photo link
  document.getElementById('fsale-photoedit').style.display = 'inline';
}



var SPECIAL_DAYS = {
    0 : [ 13, 24 ],             // special days in January
    2 : [ 1, 6, 8, 12, 18 ],    // special days in March
    4 : [ 11, 14, 15 ],             // special days in September
    5 : [ 4, 19, 17 ],             // special days in September
    8 : [ 21, 11 ],             // special days in September
   11 : [ 25, 28 ]              // special days in December
};

// this function returns true if the passed date is special
function dateIsSpecial(year, month, day) {
    var m = SPECIAL_DAYS[month];
    if (!m) return false;
    for (var i in m) if (m[i] == day) return true;
    return false;
}

// this is the actual date status handler.  Note that it receives the
// date object as well as separate values of year, month and date, for
// your confort.
function dateStatusHandler(date, y, m, d) {
    if (dateIsSpecial(y, m, d)) return 'calDateSpecial';
    else return true;
}

function dateChanged(calendar) {
  if (calendar.dateClicked) {
    document.getElementById('sale_sale_date').value = calendar.date.print(calendar.params.ifFormat);
  }
};
