//<script type="text/javascript">
//<!--

//******************************
// src="http://www.gaoacu.com/gaoacu/common/form.js"
// this file is for appointment page
// appt.php
//creaet a calendar for appointment
var bas_cal,dp_cal,ms_cal;


var workHours=7;
var workStartTime=9;

function generateTimes(){

   var hrTime=0;
   var selDiv = document.getElementById("selectHrDiv");

   var selectHr = document.getElementById('selectHr');
   if(selectHr == null){
     //append ":" between hour and minute
      var textNode= document.createTextNode(' Time:');
      selDiv.appendChild(textNode);

     //create hour select
     selectHr= document.createElement("select");
     selectHr.setAttribute("id", "selectHr");
     selectHr.setAttribute("onChange", "modifyAMPM(this.options[this.selectedIndex].value);");
     selectHr.setAttribute("tabindex", "5");
     //-----------------hour choices-----------------
     for(i=0; i<=workHours; i++){
        //      var rounddown=roundDown(((i*15)/60));
        var hrOpt= document.createElement("option");
        hrTime=0;
        if(i<=(12-workStartTime)){
          hrTime=i+workStartTime;
        } else {
           hrTime=i-(12-workStartTime);
        }
        hrOpt.setAttribute("id", "hrOpt" + hrTime);
        hrOpt.setAttribute("value", hrTime);

        hrOpt.appendChild(document.createTextNode(hrTime));
        selectHr.appendChild(hrOpt);

     }
     selDiv.appendChild(selectHr);

     //append ":" between hour and minute
      textNode= document.createTextNode(':');
      selDiv.appendChild(textNode);
     //create minute select and textNode ":"
     var selMins=document.getElementById('selMins');
     if( selMins == null){
        //-----------------min select------------------
        selMins= document.createElement('select');
        selMins.setAttribute("id", "selMins");
        selMins.setAttribute("tabindex", "6");
        for(i=0; i<4; i++){
           var mOpt1= document.createElement('option');
           var minute = (i==0?"00":i*15);
           mOpt1.setAttribute('value', minute);
           mOpt1.appendChild(document.createTextNode(minute));
           selMins.appendChild(mOpt1);
        }
        //-----------------":" textNode----------------
        selDiv.appendChild(selMins);
     }
     //create AM/PM
     var selAMPM=document.getElementById('selAMPM');
     if( selAMPM == null){
        //-----------------min select------------------
        selAMPM= document.createElement('select');
        selAMPM.setAttribute("id", "selAMPM");
        selMins.setAttribute("tabindex", "7");
        //selAMPM.setAttribute('DISABLED','DISABLED');
        var mOpt1= document.createElement('option');
        mOpt1.setAttribute('value', "AM");
        mOpt1.appendChild(document.createTextNode("AM"));
        selAMPM.appendChild(mOpt1);

        mOpt1= document.createElement('option');
        mOpt1.setAttribute('value', "PM");
        mOpt1.appendChild(document.createTextNode("PM"));
        selAMPM.appendChild(mOpt1);

        selDiv.appendChild(selAMPM);
     }
   }
};

window.onload = function () {
  generateTimes();
  dp_cal  = new Epoch('epoch_popup','popup',document.getElementById('appDate'));
};


function modifyAMPM(hour) {
   var selAMPM = document.getElementById("selAMPM");
  if (hour > workStartTime && hour <12) {
    selAMPM.selectedIndex = 0;
  } else {
    selAMPM.selectedIndex = 1;
  }
};

function roundDown(value){
var newValue=0;
   if(Math.round(value)>value){
      newValue=Math.round(value)-1;
   } else{
      newValue=Math.round(value);
   }
return newValue;
};

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);
  return false;}
else {return true}
}
};

function validatePhone(phoneNum)
{
if (phoneNum.length > 0)
   {
   if(isNaN(Phone))
   {
      Phone="";
   }
   }

};

function checkEmail(email)
{
if(email.length > 0)
   {
   if (email.indexOf(' ') >= 0)
      alert("email addresses cannot have spaces in them");
   else if (email.indexOf('@') == -1)
      alert("a valid email address must have an @ in it");
   }
};

function validate_form(thisform)
{
  with (thisform)
  {
    if (validate_required(Name,"Name must be filled out!")==false)
      {Name.focus();return false;}
    if (validate_required(ReplyTo,"Email must be filled out!")==false)
      {ReplyTo.focus();return false;}
    if (validate_required(Phone,"Phone# must be filled out!")==false)
      {Phone.focus();return false;}
    if (validate_required(AppointmentTime,"Appointment time must be filled out!")==false)
      {AppointmentTime.focus();return false;}
  }

  document.getElementById("AppointmentTime").value =
  document.getElementById("appDate").value + " " +
  document.getElementById("selectHr").options[document.getElementById("selectHr").selectedIndex].value + ":"+
  document.getElementById("selMins").options[document.getElementById("selMins").selectedIndex].value + " " + document.getElementById("selAMPM").options[document.getElementById("selAMPM").selectedIndex].value;
  return true;
};

//-->
//</script>

