calendarSelections=new Object();
requireConfirmation=new Object();

function toggleDay(date) {
  var td=ID('Day'+date);

  if(calendarSelections[date]) {
    calendarSelections[date]=false;
    td.style.backgroundColor='';
  }
  else {
    calendarSelections[date]=true;
    td.style.backgroundColor='#3B9EEF';                            // Selected color
  }
}

function confirmToggleDay(date) {
  if(requireConfirmation[date])
    requireConfirmation[date]=!requireConfirmation[date];
  else
    requireConfirmation[date]=true
}

// Highlight day under mouse

function DayOver(c) {
  if (!c) return false;
  c.style.backgroundColor='#ffffff';                               // Highligh color
  c.style.cursor='pointer';
}

// Return to state before highlight

function CalDayOut(c,date) {
  if (!c) return false;
  if(calendarSelections[date]) {
    c.style.backgroundColor='#3B9EEF';                             // Selected color
  }
  else
    c.style.backgroundColor='';
  c.style.cursor='default';
}

function DoAction(action,id,cal_date) {

  var dows = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  var moys = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aus','Sep','Oct','Nov','Dec');
     
  var confirms = '';
  for(var date in requireConfirmation) {
    if(requireConfirmation[date]) {
      cfdate = new Date();
      cfdate.setDate(parseInt(date.substring(8,10)));
      cfdate.setMonth(parseInt(date.substring(5,7))-1);
      cfdate.setYear(parseInt(date.substring(0,4)));
      confirms+=dows[cfdate.getDay()]+' '+cfdate.getDate()+', '+moys[cfdate.getMonth()]+' '+cfdate.getYear()+'\n';
    }
  }
  if(confirms.length > 0) {
    msg='The follow dates are booked by customers\n\n'+confirms+'\nAre you sure you want to apply this change?'; 
    if(!confirm(msg)) {
      return false;
    }
  }

  var days='';
  for(var date in calendarSelections) {
    if(calendarSelections[date]) {
      days+=date+',';
      //Unselect the day now that it has been used
      //ID('Day'+date).style.backgroundColor='';
      //calendarSelections[date]=false;
    }
  }
  if(days.length==0) {
    alert('Please select the days you want to change by clicking on them in the calendar below.');
    return;
  }
  days=days.substring(0,days.length-1);
  document.location='/admin/availability.'+action+'.'+id+'?cal_date='+cal_date+'&dates='+days+'&js_redirect_date='+current_browse_date;
}








