<!-- Begin

    function load_events() {
      $('.slot').click(function() {        
        var log_id = $(this).attr('id');
        var timestamp = $(this).attr('title');
        $.post('master_ajax.php?z=1&t='+timestamp+'&l='+log_id,
          function(data) {
              if (data.substring(0,4)=='err:') {
                alert(data.substring(4));
                location.reload();              
              } else {
                $('#search_header').empty();
                $('#search_results').empty();        
                $('#dialog').dialog('open');
                $('#search_header').html(data);        
              }      
        });         
      });
      $('.plus').click(function() {        
        var plus_admin_id = $(this).attr('id');
        admin_id = plus_admin_id.substring(16);
        log_date = plus_admin_id.substring(5,15); 
        $('#search_header').empty();
        $('#search_results').empty();        
        $('#dialog').dialog('open');
        $('#search_header').load('master_ajax.php?z=7&a='+admin_id+'&d='+log_date);
      });
    }

    function runupdate() {
      $.post('master_ajax.php?z=9',
        function(data) {
          if (data.substring(0,4)=='new:') {
            if ($('#'+data.substring(4)).length) {
              // call the fillSlot              
            } else {
              // create the new slot if date range
            }
            window.setTimeout(runupdate, 2500);
          }
      });
    }

    function fslot(log_id,timestamp,student_id) {
      var slot_id = '#' + log_id;                  
      $.post('master_ajax.php?z=3&t='+timestamp+'&s='+student_id+'&l='+log_id,
        function(data) {
            if (data.substring(0,4)=='err:') {
              alert(data.substring(4));

              location.reload();              
            } else {
              $(slot_id).attr('title',data.substring(0,10));               
              $(slot_id).html(data.substring(10));
            }      
      });
      $('#dialog').dialog('close');            
    }

    function uslot(log_id,timestamp,student_id) {
      var slot_id = '#'+log_id;
      var details = $('#details').val();
      $.post('master_ajax.php?z=6&t='+timestamp+'&s='+student_id+'&l='+log_id, { details: details },
         function(data) {
            if (data.substring(0,4)=='err:') {
              alert(data.substring(4));
              location.reload();              
            } else {
              $(slot_id).attr('title',data.substring(0,10));
              $(slot_id).html(data.substring(10));
            }
      });
      $('#dialog').dialog('close');
    }

    function rslot(log_id, timestamp) {
      var slot_id = '#'+log_id;
      $.post('master_ajax.php?z=4&t='+timestamp+'&l='+log_id,
        function(data) {
            if (data.substring(0,4)=='err:') {
              alert(data.substring(4));
              location.reload();              
            } else {
              $(slot_id).attr('title',data.substring(0,10)); 
              $(slot_id).html(data.substring(10));
            }      
      });
      $('#dialog').dialog('close');
    }             

    function dslot(log_id, timestamp) {
      var slot_id = '#' + log_id;
      $.post('master_ajax.php?z=5&t='+timestamp+'&l='+log_id,
         function(data) {
            if (data.substring(0,4)=='err:') {
              alert(data.substring(4));
              location.reload();              
            } else {
              $(slot_id).remove();
            }
      });
      $('#dialog').dialog('close');            
    }

    function pslot(log_date,admin_id) {
      var rundate_div = '#'+log_date;
      var time_in = $('#time_in').val();
      var time_out = $('#time_out').val();
      $.post('master_ajax.php?z=8&a='+admin_id+'&d='+log_date, { time_in: time_in, time_out: time_out },
         function(data) {
            if (data.substring(0,4)=='err:') {
              alert(data.substring(4));
            } else {
              $(rundate_div).replaceWith(data);
              $('#dialog').dialog('close');
            }
      });
    }  

function ajax_students(){
    var url;
    url = "students.php?l=1&s=";
    url = url + document.getElementById('search_text').value;
    url = url + "&i=";
    url = url + document.getElementById('site_id').value;
    new Ajax.Updater('ajaxDiv', url, { });
}

function setfocusone () {
  try {
      if (document.getElementsByTagName('input')[0].focus()) return true;
  } catch(err) {
      return false;
  }
}

function toggleAll(id)
{
	box = document.getElementById('toggleall');
 
	if(box.checked == true)
	{
		var setting = true;
	}
	else
	{
		var setting = false;
	}
 
	var cur_id = id+'1';
 
	var count = 1;
	while(box = document.getElementById(cur_id))
	{
		box.checked = setting;
		cur_id = id+count;
		count++;
	}
}


function SubmitOff() {
  document.getElementById('submit_btn').style.display = "none";
  document.getElementById('wait_btn').style.display = "";    
}

function checkdate(objName) {
  var datefield = objName;
  if (chkdate(objName) == false) {
    datefield.select();
    alert("That date is invalid.  Please try again.");
    datefield.focus();
    return false;
  }
  else {
    return true;
  }
}

function chkdate(objName) {
  var strDatestyle = "US"; //United States date style
  //var strDatestyle = "EU";  //European date style
  var strDate;
  var strDateArray;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var booFound = false;
  var datefield = objName;
  var strSeparatorArray = new Array("-"," ","/",".");
  var intElementNr;
  var err = 0;
  var strMonthArray = new Array(12);
  strMonthArray[0] = "Jan";
  strMonthArray[1] = "Feb";
  strMonthArray[2] = "Mar";
  strMonthArray[3] = "Apr";
  strMonthArray[4] = "May";
  strMonthArray[5] = "Jun";
  strMonthArray[6] = "Jul";
  strMonthArray[7] = "Aug";
  strMonthArray[8] = "Sep";
  strMonthArray[9] = "Oct";
  strMonthArray[10] = "Nov";
  strMonthArray[11] = "Dec";
  strDate = datefield.value;
  if (strDate.length < 1) {
    return true;
  }

  for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
    if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
      strDateArray = strDate.split(strSeparatorArray[intElementNr]);
      if (strDateArray.length < 2 || strDateArray.length > 3) {
        err = 1;
        return false;
      } else {
        strDay = strDateArray[0];
        strMonth = strDateArray[1];
        if (strDateArray.length == 2) {
          var d = new Date();
          strYear = d.getFullYear();
        } else {       
          strYear = strDateArray[2];
        }
      }
      booFound = true;
    }
  }

  if (booFound == false) {
    if (strDate.length>5) {
      strDay = strDate.substr(0, 2);
      strMonth = strDate.substr(2, 2);
      strYear = strDate.substr(4);
    }
  }
  if (strYear.length == 1) {
    strYear = '200' + strYear;
  }
  if (strYear.length == 2) {
    if (parseInt(strYear) > 38) {
      strYear = '19' + strYear;
    }
    else {
      strYear = '20' + strYear;
    }
  }

  // US style
  if (strDatestyle == "US") {
    strTemp = strDay;
    strDay = strMonth;
    strMonth = strTemp;
  }
  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    err = 2;
    return false;
  }
  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i = 0;i<12;i++) {
      if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
        intMonth = i+1;
        strMonth = strMonthArray[i];
        i = 12;
      }
    }
    if (isNaN(intMonth)) {
      err = 3;
      return false;
    }
  }
  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    err = 4;
    return false;
  }
  if (intMonth>12 || intMonth<1) {
    err = 5;
    return false;
  }
  if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
    err = 6;
    return false;
  }
  if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
    err = 7;
    return false;
  }
  if (intMonth == 2) {
    if (intday < 1) {
      err = 8;
      return false;
    }
    if (LeapYear(intYear) == true) {
      if (intday > 29) {
        err = 9;
        return false;
      }
    }
    else {
      if (intday > 28) {
        err = 10;
        return false;
      }
    }
  }
  if (strDatestyle == "US") {
    datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
  }
  else {
    datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
  }
  return true;
}

function LeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) { return true; }
  } else {
    if ((intYear % 4) == 0) { return true; }
  }
  return false;
}

function dFilterStrip (dFilterTemp, dFilterMask) {
  // This function Formats formfield with pattern ###
  dFilterMask = replace(dFilterMask,'#','');
  for (dFilterStep = 0; dFilterStep < dFilterMask.length++; dFilterStep++) {
    dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
  }
  return dFilterTemp;
}

function dFilterMax (dFilterMask) {
  dFilterTemp = dFilterMask;
  for (dFilterStep = 0; dFilterStep < (dFilterMask.length+1); dFilterStep++) {
    if (dFilterMask.charAt(dFilterStep)!='#') {
      dFilterTemp = replace(dFilterTemp,dFilterMask.charAt(dFilterStep),'');
    }
  }
  return dFilterTemp.length;
}

function dFilter (key, textbox, dFilterMask) {
  dFilterNum = dFilterStrip(textbox.value, dFilterMask);
  if (key==9) {
    return true;
  }
  else if (key==8&&dFilterNum.length!=0) {
    dFilterNum = dFilterNum.substring(0,dFilterNum.length-1);
  }
  else if ( ((key>47&&key<58)||(key>95&&key<106)) && dFilterNum.length<dFilterMax(dFilterMask) ) {
    dFilterNum=dFilterNum+String.fromCharCode(key);
  }

  var dFilterFinal='';
  for (dFilterStep = 0; dFilterStep < dFilterMask.length; dFilterStep++) {
    if (dFilterMask.charAt(dFilterStep)=='#') {
      if (dFilterNum.length!=0) {
        dFilterFinal = dFilterFinal + dFilterNum.charAt(0);
        dFilterNum = dFilterNum.substring(1,dFilterNum.length);
      } else {
        dFilterFinal = dFilterFinal + "";
      }
    }
    else if (dFilterMask.charAt(dFilterStep)!='#') {
      dFilterFinal = dFilterFinal + dFilterMask.charAt(dFilterStep);
    }

  // dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
  }
  textbox.value = dFilterFinal;
  return false;
}

function replace(fullString,text,by) {
  // Replaces text with by in string
  var strLength = fullString.length, txtLength = text.length;
  if ((strLength == 0) || (txtLength == 0)) return fullString;
  var i = fullString.indexOf(text);
  if ((!i) && (text != fullString.substring(0,txtLength))) return fullString;
  if (i == -1) return fullString;
  var newstr = fullString.substring(0,i) + by;
  if (i+txtLength < strLength) newstr += replace(fullString.substring(i+txtLength,strLength),text,by);
  return newstr;
}

function checknum(objName) {    
    var num = objName.value/1;
    if (num>0) {
      objName.value = num.toFixed(2);
    } else {
      if (objName.value.substr(0,1)=="$" ) {
          num = objName.value.substr(1)/1;
          objName.value = num.toFixed(2);                
      } else {
          objName.value ="";
      }
    }
    return true;
}

function checktime(objName) {
  var timefield = objName;
  if (chktime(objName) == false) {
    timefield.select();
    alert("That time is invalid.  Please try again.");
    timefield.focus();
    return false;
  }
  else {    
    return true;
  }
}

function chktime(objName) {
  var timefield = objName;
  var timeStr = timefield.value;

  if (timeStr.length < 1) {
    return true;
  }
  if (timeStr.length == 1) {
    timeStr = "0" + timeStr + ":00";
  }
  if (timeStr.length == 2) {
    timeStr = timeStr + ":00";
  }
  if (timeStr.length == 3) {
    timeStr = "0" + timeStr;
  }
  if (timeStr.indexOf(':') < 1) {
    timeStr = timeStr.substr(0,2) + ":" +   timeStr.substr(2);
  }

  var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
  var matchArray = timeStr.match(timePat);
  if (matchArray == null) {
    return false;
  }
  hour = matchArray[1];
  minute = matchArray[2];
  second = matchArray[4];
  ampm = matchArray[6];

  if (second=="") { second = null; }
  if (ampm=="") { ampm = null }

  if (hour < 0  || hour > 23) {
    return false;
  }
  if  (hour > 12 && ampm != null) {
    return false;
  }
  if (minute<0 || minute > 59) {
    return false;
  }
  if (second != null && (second < 0 || second > 59)) {
    return false;
  }
  if (ampm) {
    ampmStr = " " + ampm.toLowerCase();
  } else {
    ampmStr = " pm";
    if (hour > 12) {
      hour = hour - 12;
    } else {
      if (hour < 12) ampmStr = " am";
      if (hour < 10 && hour.length ==2) hour = hour.substr(1);
    }
  }
  timefield.value = hour + ":" + minute + ampmStr;
  
  if (timefield.id=="time_in") {
      h = (parseInt(hour) + 2);
      ap = ampmStr;
      if (h >= 12) ap = " pm";
      if (h > 12) h = h - 12;
      document.getElementById("time_out").value = h + ":" + minute + ap;
  }

  return true;
}

function checkemail(objName) {
  var emailfield = objName;
  if (emailfield.value.length < 1) {
    return true;
  }
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/.test(emailfield.value)) {
    return (true);
  }
  emailfield.select();
  alert("Invalid E-mail Address! Please re-enter.");
  emailfield.focus();
  return (false);
}

function checkphone(objName) {
    var phonefield = objName;
    var FmtStr="";
    var index = 0;
    var LimitCheck;

    IniStr = phonefield.value;
    LimitCheck = IniStr.length;

    if (LimitCheck < 1) {
      return true;
    }

    while (index != LimitCheck) {
        if (isNaN(parseInt(IniStr.charAt(index)))) {
        } else {
          FmtStr = FmtStr + IniStr.charAt(index);
        }
        index = index + 1;
      }
    
    if (FmtStr.length == 7) {
      // FmtStr = "714" + FmtStr;
      FmtStr = "909" + FmtStr;
    }
    
    if (FmtStr.length == 10) {
        FmtStr = "(" + FmtStr.substring(0,3) + ") " + FmtStr.substring(3,6) + "-" + FmtStr.substring(6,10);
      } else {
        if (FmtStr.length < 10) {
          phonefield.select();
          alert("Phone numbers must have at least ten digits.");
          phonefield.focus();
          return (false);
        } else {          
          FmtStr = "(" + FmtStr.substring(0,3) + ") " + FmtStr.substring(3,6) + "-" + FmtStr.substring(6,10) + " x" + FmtStr.substring(10);
        }
      }
    phonefield.value = FmtStr;
    return true;
}

function boxcolor(x, d) {
  document.getElementById(d).bgColor=x
}

function show_instructor(num) {

    if (num=="3" | num=="4") {
        // show instructor 
        document.getElementById("show_instructor").style.display = 'block';        
    } else {
        document.getElementById("show_instructor").style.display = 'none';        
    }
}

function show_other_ref(num) {

    if (num=="99") {
        // show_other_ref span
        document.getElementById("show_other_ref").style.display = 'inline';        
    } else {
        document.getElementById("show_other_ref").style.display = 'none';        
    }
}

//  End -->
