
function viewAppointments(day, month, year,site,allowpart){
  document.getElementById('lastdateclicked').innerHTML = month+'/'+day+'/'+year;
  close_div('save');
  ourDate = new Date();
  tm = ourDate.getTime();
  display_div = document.getElementById('view_appointments');
  curcoaches = document.getElementById('curcoachlist').innerHTML;
  curuid = document.getElementById('curuserid').innerHTML;
  cururole = document.getElementById('currole').innerHTML;
  if (document.getElementById('app_type'))
     restrict = document.getElementById('app_type').innerHTML;
  if (cururole == "Participant" || cururole == "Employer")
  {
  //   if (allowpart)
  //      document.getElementById('create_appointment_div').innerHTML = "<br><br><a href=\"javascript:create_appointment('Mg==','true','"+allowpart+"');\">Make Appiintment</a>  <br><a href=\"javascript:create_appointment('Mg==','true','Reminder');\"><image src=images/setreminder.png></a>";
  //   else
        document.getElementById('create_appointment_div').innerHTML = "<br><br><a href=\"javascript:create_appointment('Mg==','true','Reminder');\"><image src=images/setreminder.png></a>";
  }                             //fixed
  show_div(display_div,'block','absolute','220px','290px','#ffffff','540px','490px','0px solid #000000','auto');
  link = 'x_redir.php?site='+site+'&day='+day+'&month='+month+'&year='+year+'&time='+tm+'&curuserid='+curuid+'&currole='+cururole+'&curcoachlist='+curcoaches+'&allowpart='+allowpart+'&restrict='+restrict;
  target_div = 'inner_appointments';
  document.getElementById(target_div).innerHTML = '<center><b>Loading Calendar</b></center><img src=./images/ajax-loader.gif>';
  dynamic(target_div, link);
}                                   

function view_appointment_info(app_id, app_type, site,action,reset){
  ourDate = new Date();
  tm = ourDate.getTime();
  cururole = document.getElementById('currole').innerHTML;
  curuid = document.getElementById('curuserid').innerHTML;
  curcoaches = document.getElementById('curcoachlist').innerHTML;
  link = 'x_redir.php?site='+site+'&app_id='+app_id+'&app_type='+app_type+'&time='+tm+'&action='+action+'&reset='+reset+'&curuserid='+curuid+'&currole='+cururole+'&curcoachlist='+curcoaches;
  target_div = 'div_'+app_id+'_'+app_type;
  if(action == 'edit' || action == 'info' || action == 'delete'){
    div_width = '380px';
  }
  if(action == 'title'){
    div_width = '0px';
  }
  document.getElementById(target_div).innerHTML = '<img src=./images/ajax-loader.gif>';
  document.getElementById(target_div).style.width = div_width;
  dynamic(target_div, link);
  document.getElementById(target_div).style.display = "";
}

function save_appointment_info(app_id, app_type, site, action){
  ourDate = new Date();
  tm = ourDate.getTime();
  //the following gets the values of the new appointment information
  if (document.forms['save_app'].elements['start_hour'])
  {
     start_hour = document.forms['save_app'].elements['start_hour'].value;
     start_minute = document.forms['save_app'].elements['start_minute'].value;
     start_ampm = document.forms['save_app'].elements['start_ampm'].value;
  }
  else
  {
     var starttime = document.forms['save_app'].elements['start_time'].value;
     if (starttime == "0")
     {
        alert("You need to select a time");
        return;
     }
     var tarray = starttime.split(':');
     start_hour = tarray[0];
     start_minute = tarray[1];
     start_ampm = tarray[2];
  }
  start_day = document.forms['save_app'].elements['start_day'].value;
  start_month = document.forms['save_app'].elements['start_month'].value;
  start_year = document.forms['save_app'].elements['start_year'].value;
  var length = document.forms['save_app'].elements['appointment_length_'+app_id].value;
  appttype = document.forms['save_app'].elements['appttype'].value;
  if (document.forms['save_app'].elements['apptloc'])
     apptlocation = document.forms['save_app'].elements['apptloc'].value + "_" + document.forms['save_app'].elements['address'].value + "_" + document.forms['save_app'].elements['city'].value + "_" + document.forms['save_app'].elements['state'].value + "_" + document.forms['save_app'].elements['staffcount'].value;
  else
     apptlocation = "";
  notes = document.forms['save_app'].elements['notes'].value;
  see_group = document.forms['save_app'].elements['see_group_'+app_id].value;
  see_coach = document.forms['save_app'].elements['see_coach_'+app_id].value;
  target_entity_id = document.forms['save_app'].elements['target_entity_id_'+app_id].value;
  if (target_entity_id == "0")
  {
        alert("You need to select a company." + target_entity_id + 'target_entity_id_'+app_id);
        return;
  }
  target_entity_type = document.forms['save_app'].elements['target_entity_type'].value;
  source_entity_type = document.forms['save_app'].elements['source_entity_type'].value;
  source_entity_id = document.getElementById('curuserid').innerHTML;
  apptsource = "X";
  if (apptsource = document.forms['save_app'].elements['apptinterval'])
     apptsource = document.forms['save_app'].elements['apptinterval'].value;
  if (target_entity_id == -1) // reminder
  {
     target_entity_id = source_entity_id;
     target_entity_type = source_entity_type;
  }
  if (target_entity_id.charAt(0) == '-') // coach making appt with participant
  {
     var t2 = target_entity_id;
     target_entity_id = source_entity_id;
     target_entity_type = "Coach";
     source_entity_id = t2.substring(1,t2.length);;
     source_entity_type = "Participant";
  }
  aq = "";
  if (document.getElementById('rememail') && document.getElementById('rememail').checked)
     aq = "-11";
  date_link = 'start_day='+start_day+'&start_month='+start_month+'&start_year='+start_year;
  add_link = 'length='+length+'&type='+appttype+'&notes='+notes+'&target_entity_id='+target_entity_id+'&target_entity_type='+target_entity_type+'&source_entity_id='+source_entity_id+'&source_entity_type='+source_entity_type+'&start_hour='+start_hour+'&start_minute='+start_minute+'&start_ampm='+start_ampm+'&apptloc='+apptlocation+'&apptsource='+apptsource+'&see_group='+see_group+'&see_coach='+see_coach+"&aq="+aq;
  link = 'x_redir.php?site='+site+'&app_id='+app_id+'&app_type='+app_type+'&time='+tm+'&action='+action+'&'+add_link+'&'+date_link;
  target_div = 'inner_save';
  display_div = document.getElementById('save');
  document.getElementById(target_div).innerHTML = '<img src=./images/ajax-loader.gif>';
  show_div(display_div,'block','absolute','480px','350px','#ffffff','300px','150px','0px solid #000000','auto');
  dynamic(target_div, link);    //fixedd
}

function ChangeSelTime()
{
   var ddiv = document.getElementById("lendiv");
   if (ddiv)
   {
      if (document.getElementById("start_time").value == "00:01")
         ddiv.style.visibility = 'hidden';
      else
         ddiv.style.visibility = 'visible';
   }
}

function create_appointment(site,reset,assessnum){
  tm = document.getElementById('lastdateclicked').innerHTML;
  curuid = document.getElementById('curuserid').innerHTML;
  cururole = document.getElementById('currole').innerHTML;
  curcoaches = document.getElementById('curcoachlist').innerHTML;
  display_div = document.getElementById('create_appointments');
  appttype = document.getElementById('app_type').innerHTML;
  if (assessnum > 0)
     appttype = "AssessSignup"; //fixed
  show_div(display_div,'block','absolute','430px','200px','#ffffff','450px','350px','0px solid #000000','auto');
  link = 'x_redir.php?site='+site+'&time='+tm+'&curuserid='+curuid+'&currole='+cururole+'&action=create&app_id=0&reset='+reset+'&curcoachlist='+curcoaches+'&app_type='+appttype+'&assessnum='+assessnum;
  target_div = 'inner_create';
  document.getElementById(target_div).innerHTML = '<center><b>Loading Form</b></center><img src=./images/ajax-loader.gif>';
  dynamic(target_div, link);
}

function close_div(div_id){
  document.getElementById(div_id).style.display = 'none';
}

function clear_div(target_div){
  document.getElementById(target_div).innerHTML = '<center><b>Loading Calendar</b></center><img src=./images/ajax-loader.gif>';
}

function show_div(display_div,display,position,left,top,background,width,height,border,overflow){
  display_div.style.display = display;
  display_div.style.position = position;
  display_div.style.left = left;
  display_div.style.top = top;
  display_div.style.background = background;
  display_div.style.width = width;
  display_div.style.height = height;
  display_div.style.border = border;
  display_div.style.overflow = overflow;
}
