Event.observe(window, 'load', function() {
  if(typeof(adName) == 'undefined')
    adName = 'Ad';

  if(typeof(isAdmin) == 'undefined')
    isAdmin = 0;

  if($('mark_as_sold')) {
    Event.observe($('mark_as_sold'), 'click', confirmMarkAsSold);
  }

  if($('is_sold')) {
    Event.observe($('is_sold'), 'click', blockEdit);
  }
});

// {{{ blockEdit(ev)
function blockEdit(ev) {
  if(isAdmin) {
    if(!confirm('This ' + adName + ' has been marked as Sold and should\n' +
                'not be edited so as to allow visitors to see the item\n' +
                'as it was sold.\n\n' +
                'However as you are an admin user you can modify the\n' +
                adName + ' by clicking on the "OK" button below.')) {
      ev_stop();
      return;
    }
  } else {
    ev.stop();
    alert('This ' + adName + ' has been marked as Sold. To allow visitors to\n'
        + 'see the item as it was sold this ' + adName +' cannot be edited.\n'
        + 'To edit this ' + adName +' you must remove the "Sold" mark.');
  }
} // }}}

function confirmMarkAsSold(ev) {
  var isSold = $('is_sold');

  if(isSold) {
    confirmed = confirm(
      'This will remove the "sold" sign from your ' + adName + ' and\n' +
      'return it back to its regular type so it can be edited.\n\n' +
      'Note:\n'+
      'The entry should not be marked as unsold if this item really\n' +
      'has been sold. This option is provided in case the sale is not\n' +
      'completed and you wish to re-list the ' + adName + '.\n');
  } else {
    confirmed = confirm(
      'This will mark your ' + adName + ' as sold. You will not be\n' +
      'able to make further changes to your ' + adName + 'once it\n' +
      'has been marked as sold. (But you can unmark it).\n\n' +
      'Click OK to Mark your ' +adName+' as having been sold.');
  }

  if(!confirmed) {
    ev.stop();
    return;
  }

  if(isSold && isAdmin) {
  }

}
