<!---
This file is Copyright © 1998-2009 by Home Care Business Services. This work may not be reproduced, in whole or in part, 
using any medium, including, but not limited to, electronic transmission, CD-ROM or published in print, without the express 
permission of Home Care Business Services.

$Revision: 1.29 $
$Id: add_schedule.cfm,v 1.29 2010/06/30 21:34:27 melissa Exp $
$Date: 2010/06/30 21:34:27 $
--->
<cfinclude template="../__Security-Block.cfm">

<!--- Page specific code, such as queries and variable settings should go here --->
<script language="javascript" type="text/javascript">

</script>
<cfparam name="URL.Action" default="Step1">
<cfparam name="Form.Sched_Dates" default="">
<cfparam name="ErrorFlag" default="">
<cfset session.rollover=0>
 <cfswitch expression="#URL.Action#"> 
  <cfcase value="Step1"> 
   <!--- Get Patients for Dropdown list ---> 
   <cfquery  datasource="#Application.DataSrc#" name="PatientDrop">
   SELECT Patient_ID, First_Name_M0040, Last_Name_M0040, Middle_Initial_M0040 
	 FROM #Request.prefix_db_agency#.patient 
	 WHERE  Agency_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#Session.AgencyID#" maxlength="10"> 
   AND    Status = 'active'
   <cfif session.eaType EQ 1>
   AND Employee_ID = '#Session.EmployeeId#'
   </cfif>
   ORDER BY Last_Name_M0040, First_Name_M0040
  </cfquery>
    </cfcase> 
  <cfcase value="Step2"> 
   <!--- Get Patient info for display at top of form ---> 
   <cfquery  datasource="#Application.DataSrc#" name="GetPatient">
   SELECT Patient_ID, Last_Name_M0040, First_Name_M0040, Middle_Initial_M0040, Payer_ID,city,State_M0050,Zip_M0060 FROM #Request.prefix_db_agency#.patient WHERE Patient_ID =
  <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.Patient_ID#" maxlength="10"> 
  </cfquery> 
   <!--- Store Patient information for display on form ---> 
   <cflock scope="Session" timeout="10" type="Exclusive"> 
    <cfset Session.Patient.Last = GetPatient.Last_Name_M0040> 
    <cfset Session.Patient.First = GetPatient.First_Name_M0040> 
    <cfset Session.Patient.Middle = GetPatient.Middle_Initial_M0040> 
    <cfset Session.Patient.Payer = GetPatient.Payer_ID> 
  </cflock> 
   <!--- Get Assessments for link list based on Patient selected ---> 
   <cfquery  datasource="#Application.DataSrc#" name="GetAssess">
   SELECT Assessment_ID, Assessment_Number, Start_of_Care_M0030, Admission_Status, Assessment_Reason_M0100, Assessment_Completed_M0090, Assessment_Tracker_ID, Certification_Start, Certification_End FROM #Request.prefix_db_agency#.Assessment_New WHERE Patient_ID =
  <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.Patient_ID#" maxlength="10"> 
  AND Deleted <> 1 AND (Assessment_Reason_M0100 LIKE '1%' OR Assessment_Reason_M0100 LIKE '4%' OR Assessment_Reason_M0100 LIKE '%Evaluation%' OR Assessment_Reason_M0100 LIKE '%Hospice%' OR Assessment_Reason_M0100 LIKE '%NO ASSESSMENT%') ORDER BY Assessment_Completed_M0090 Desc
  </cfquery> 
   </cfcase> 
   
  <cfcase value="Step3"> 
   <!--- Get Payers for Dropdown list ---> 
   <cfquery  datasource="#Application.DataSrc#" name="PayerDrop">
   SELECT Payer_ID, PayName, Output_Type FROM #Request.prefix_db_agency#.Payer WHERE Agency_ID =
  <cfqueryparam cfsqltype="cf_sql_integer" value="#Session.AgencyID#" maxlength="10"> 
  ORDER BY PayName
  </cfquery> 
   </cfcase> 
  <cfcase value="Step4"> 
   <cfif NOT isDefined("form.aid")> 
    <h2>Your Session has timed out. Please Login again.<br /> 
     </h2> 
    <FORM> 
       <INPUT type="button" value="Go Back" onClick="history.back()"> 
     </FORM> 
    <cfelse> 
    <!--- Get assessment details and display calendar below ---> 
    <cfquery  datasource="#Application.DataSrc#" name="GetAssess">
      SELECT patient.Patient_ID, patient.Last_Name_M0040, patient.First_Name_M0040, patient.Middle_Initial_M0040, patient.Payer_ID, Assessment_New.Certification_Start, Assessment_New.Certification_End, Assessment_New.Assessment_ID, Assessment_New.SN_Visit_Orders, Assessment_New.Therapy_Visit_Orders, Assessment_New.HHA_Visit_Orders, Assessment_New.SN_Schedule, Assessment_New.Therapy_Schedule, Assessment_New.HHA_Schedule, Assessment_New.Admission_Status, Assessment_New.Homebound_Status, Assessment_New.HIPPS_Code, Assessment_New.Assessment_Tracker_ID FROM #Request.prefix_db_agency#.patient, #Request.prefix_db_agency#.Assessment_New WHERE patient.Patient_ID = Assessment_New.Patient_ID AND Assessment_ID =
     <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.AID#" maxlength="10"> 
     </cfquery> 
    <!--- Store Certification Period for error checking ---> 
    <cflock scope="Session" timeout="10" type="Exclusive"> 
       <cfset Session.Cert.Homebound_Status = GetAssess.Homebound_Status> 
     </cflock> 
    <!--- Get Employees for dropdown list ---> 
    <cfquery  datasource="#Application.DataSrc#" name="GetEmp">
      SELECT Employee_ID, First_Name, Last_Name FROM #Request.prefix_db_lookup#.Employee WHERE Agency_ID =
     <cfqueryparam cfsqltype="cf_sql_integer" value="#Session.AgencyID#" maxlength="10"> 
     AND EmployeeType != 'Physician' AND Status = 'Active' ORDER BY Last_Name
     </cfquery> 
    <!--- Extract Payer info from form ---> 
    <cfset TempPayerID = GetToken(Form.Payer_ID,1,"|")> 
    <cfset TempPayer = GetToken(Form.Payer_ID, 2,"|")> 
    <!--- Get Visit Types and descriptions from Revenue Codes table ---> 
    <cfquery  datasource="#Application.DataSrc#" name="VisitDrop">
      SELECT Rev_CodeID, Rev_Code, HCPCS, Visit_Type, Description FROM #Request.prefix_db_agency#.Revenue_Code WHERE Agency_ID =
     <cfqueryparam cfsqltype="cf_sql_integer" value="#Session.AgencyID#" maxlength="10"> 
     AND Payer_ID =
     <cfqueryparam cfsqltype="cf_sql_integer" value="#TempPayerID#" maxlength="10"> 
     And EClaim_Price IS NOT NULL And Quick_Books_Price IS NOT NULL Order by Visit_Type ASC
     </cfquery> 
    <!--- Determine the difference between Certification_Start and Certification_End to determine how many months to display ---> 
    <cfif GetAssess.Certification_Start eq "" OR GetAssess.Certification_End eq ""> 
       <cfoutput> Certification Start Date of [#GetAssess.Certification_Start#] or Certification End Date of [#GetAssess.Certification_End#] is illegal. </cfoutput> 
       <cfabort> 
     </cfif> 
    <cfset NumDays = DateDiff("D", GetAssess.Certification_Start, GetAssess.Certification_End)> 
  </cfif> 
   </cfcase> 
  <cfcase value="Step5"> 
   <!--- Perform validity checks ---> 
   <!--- If no dates were selected, display error message ---> 
   <cfif Form.Sched_Dates IS ""> 
    <cfset ErrorFlag = "No Dates"> 
   <cfelse> 
    <!--- Check all dates to make sure they are within the Certification Period, if not display error ---> 
    <cfloop list="#Form.Sched_Dates#" index="CheckDate"> 
       <cfif DateCompare(CheckDate, Form.Certification_Start) IS -1 OR DateCompare(CheckDate, Form.Certification_End) IS 1> 
        <cfset ErrorFlag = "Out of Range"> 
      </cfif> 
    </cfloop> 

    <cfif ErrorFlag neq "Out of Range"> <!--- JDB: Do not insert ScheduleItems if Dates are Out of Range --->
      <!--- Get Rev_Code information ---> 
      <cfquery  datasource="#Application.DataSrc#" name="GetRev">
       SELECT Revenue_Code.Rev_CodeID, Revenue_Code.Visit_Type, Revenue_Code.Rev_Code, Revenue_Code.HCPCS, Revenue_Code.EClaim_Price, Revenue_Code.Quick_Books_Price, Revenue_Code.Measure, Revenue_Code.Description, Revenue_Code.Payer_ID, Payer.Payer_ID, Payer.Output_Type FROM #Request.prefix_db_agency#.Revenue_Code, #Request.prefix_db_agency#.Payer WHERE Revenue_Code.Rev_CodeID =
       <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.Rev_CodeID#" maxlength="10"> 
       And Payer.Payer_ID = Revenue_Code.Payer_ID Order by Revenue_Code.Visit_Type ASC
      </cfquery> 
      <!--- Assign Rev_Code info to Form variables ---> 
      <cfset Form.Visit_Type = GetRev.Visit_Type> 
      <cfset Form.Rev_Code = GetRev.Rev_Code> 
      <cfset Form.HCPCS = GetRev.HCPCS> 
      <cfset Form.Bill_Type = GetRev.Description> 
      <cfset Temp_EClaim_Price = GetRev.EClaim_Price> 
      <cfset Temp_Quick_Books_Price = GetRev.Quick_Books_Price> 
      <cfset Temp_Measure = GetRev.Measure> 
      <cfset Form.EClaimed = 0> 
      <cfif Form.Visit_Type IS 'Assessment' AND GetRev.Output_Type IS 'Medicare'> 
       <cfset Form.Output_Type = 'RAP'> 
       <cfelse> 
       <cfset Form.Output_Type = GetRev.Output_Type> 
      </cfif> 
      <!--- Calculate the Units, Total_EClaim and Total_QB values based on items selected ---> 
      <!--- Determine number of minutes (n) apart ---> 
      <cfset diff = #DateDiff("n",Form.StartTime,Form.EndTime)#> 
      <!--- Calculate number of units (4 per hour) ---> 
      <cfswitch expression="#Temp_Measure#"> 
       <cfcase value=".25"> 
        <cfset Form.Total_Units = (#diff#/60)*100/25> 
       </cfcase> 
       <cfcase value="1"> 
        <cfset Form.Total_Units = (#diff#/60)*100/100> 
       </cfcase> 
       <cfcase value="visit"> 
        <cfset Form.Total_Units = 1> 
       </cfcase> 
       <cfdefaultcase> 
        <cfset Form.Total_Units = 0> 
       </cfdefaultcase> 
      </cfswitch> 
      <cfif Form.Total_Units lt 0> 
       <cfset Form.Total_Units=Form.Total_Units+96> 
     </cfif> 
     <cfif Form.Visit_Type IS NOT 'Assessment' AND Temp_EClaim_Price IS NOT ""> 
       <cfset Form.Total_EClaim = Temp_EClaim_Price * Form.Total_Units> 
       <cfset Form.Total_QB = Temp_Quick_Books_Price> 
     <cfelse> 
      <cfif Session.Cert.Homebound_Status IS NOT ""> 
        <cfset Form.Total_EClaim = Session.Cert.Homebound_Status> 
        <cfset Form.Total_QB = Session.Cert.Homebound_Status> 
        <cfelse> 
        <cfset Form.Total_EClaim = 0> 
        <cfset Form.Total_QB = 0> 
      </cfif> 
     </cfif> 
     <cfloop list="#Form.Sched_Dates#" index="ThisDate"> 
       <cfset TempPayerID = GetToken(Form.Payer_ID,1,"|")> 
       <cfset TempPayer = GetToken(Form.Payer_ID, 2,"|")> 
       <!--- format the start and end times ---> 
       <cfset thehour=GetToken(form.StartTime,1,':')> 
       <cfset theminute=GetToken(form.StartTime,2,':')> 
       <cfset form.starttime="#thehour#:#theminute#"> 
       <cfset thehour=GetToken(form.EndTime,1,':')> 
       <cfset theminute=GetToken(form.EndTime,2,':')> 
       <cfset form.endtime="#thehour#:#theminute#"> 
        <cfquery  datasource="#Application.DataSrc#" name="AllVisits">
          INSERT INTO #Request.prefix_db_agency#.ScheduleItems (
					   Patient_ID, Visit_Date, Employee_ID, EmpPay_ID, Record_creation_Date, Record_created_By, Record_Mod_Date, Record_Mod_By
						,Agency_ID, Visit_Type, Assessment_Tracker_ID, Assessment_ID, Progress_Note, EClaimed, Rev_Code, HCPCS
						,Payer_ID, StartTime, EndTime, Rev_CodeID, Total_Units, Total_EClaim, Total_QB
						,Bill_Type, Paperwork, Travel, Mileage, Output_Type, Telephony_Yes
						,Visit_Notes
				  ) VALUES (
					  #Form.Patient_ID#, #CreateODBCDateTime(ThisDate)#, '#Form.Employee_ID#', '#Form.EmpPay_ID#', #Now()#, #Session.EmployeeID#, #Now()#, #Session.EmployeeID#
					 ,#Session.AgencyID#, '#Form.Visit_Type#', #Form.ATID#, #Form.AID#, 'No', '0', '#Form.Rev_Code#','#Form.HCPCS#'
					 ,'#temppayerid#', #CreateODBCTime(Form.StartTime)#, #CreateODBCTime(Form.EndTime)#, #Form.Rev_CodeID#, #Form.Total_Units#, #Form.Total_EClaim#, #Form.Total_QB#
					 ,'#Form.Bill_Type#', '0.00', '0.00', '0', '#Form.Output_Type#', '#Form.Telephony_Yes#'
					 ,'#Form.Visit_Notes#'
					)
         </cfquery> 
         <cfquery  name="NewVisit" datasource="#Application.DataSrc#">
          <!--- SELECT MAX(ScheduleItems_ID) as maxid from #Request.prefix_db_agency#.ScheduleItems --->
          SELECT Last_Insert_Id() AS maxId
         </cfquery>
       <cfif form.employee_id neq 0>
        <cf_telephonyid result="theitem" action="updateitem" employeeid="#Form.Employee_ID#" visitdate=#thisdate# id=#NewVisit.maxid#> <cf_telephonyid result="encodefinal" action="encode" employeeid="#Form.Employee_ID#" visitdate=#thisdate# item=#theitem#> 
        <cfquery  datasource="#Application.DataSrc#" name="upd">
          update #Request.prefix_db_agency#.ScheduleItems set telephony_id = '#encodefinal#' where scheduleitems_id = #NewVisit.maxid#
         </cfquery> 
      </cfif> 
     </cfloop> 
     <!--- Clear this page's Session vars ---> 
    </cfif> <!--- JDB: End "Out of Range" error check --->
   </cfif> 
	</cfcase> 
</cfswitch> 
<!--- End page specific code ---> 
<cfswitch expression="#URL.Action#"> 
  <cfcase value="Step1"> 
  <h2>Add Schedule - Step 1</h2> 
   <br/>
  <form name="form" method="post" action="index.cfm?page=schedules&cat=&rpt=add_schedule&Action=Step2">
    <table border="0" cellpadding="5" cellspacing="0" class="form-border"> 
      <tr> 
        <td><b>Patient:</b></td> 
        <td> <select name="Patient_ID"> 
            <option value="" selected>-- Select Patient --</option> 
            <cfoutput query="PatientDrop"> 
              <option value="#Patient_ID#">#Last_Name_M0040#, #First_Name_M0040# #Middle_Initial_M0040#</option> 
            </cfoutput> 
          </select> 
          <input type="hidden" name="Patient_ID_required" value="You must select a Patient." /> </td> 
        <td> <input type="submit" value="Select"> </td> 
      </tr> 
    </table> 
  </form> 
  </cfcase> 
  <cfcase value="Step2"> 
  <h2>Add Schedule - Step 2</h2> 
  <p><b>Patient Selected: <cfoutput query="GetPatient">#Last_Name_M0040#, #First_Name_M0040# #Middle_Initial_M0040#</cfoutput></b></p> 
  Select an Assessment from the list below.<br /> 
  <br /> 
  <table cellpadding="5" cellspacing="0" border="0" class="form-border"> 
    <tr bgcolor="#8585c2"> 
      <td class='list-hdr'>Cert Start</td> 
      <td class='list-hdr'>Cert End</td> 
      <td class='list-hdr'>Assessment Type</td> 
      <td class='list-hdr'>Status</td> 
    </tr> 
    <cfoutput query="GetAssess"> 
      <tr  class="trwhite" > 
        <td>#DateFormat(Certification_Start,'mmm dd, yyyy')#</td> 
        <td>#DateFormat(Certification_End,'mmm dd, yyyy')#</td> 
        <td><a href="index.cfm?page=schedules&cat=&rpt=add_schedule&Action=Step3&AID=#Assessment_ID#&PID=#GetPatient.Patient_ID#">#Assessment_Reason_M0100#</a></td> 
        <td>#Admission_Status#</td> 
      </tr> 
    </cfoutput> 
  </table> 
  </cfcase> 
  <cfcase value="Step3"> 
  <h2>Add a Visit - Step 3</h2> 
  <p><b>Patient Selected: <cfoutput>#Session.Patient.Last#, #Session.Patient.First# #Session.Patient.Middle#</cfoutput></b></p> 
  <form name="form" method="post" action="index.cfm?page=schedules&cat=&rpt=add_schedule&Action=Step4"> 
    <cfoutput> 
      <input type="hidden" name="AID" value="#URL.AID#" /> 
      <input type="hidden" name="PID" value="#URL.PID#" /> 
    </cfoutput> 
     <br/>
    <table border="0" cellpadding="2" cellspacing="2" class="form-border"> 
      <tr> 
        <td><b>Payer:</b></td> 
        <td> <select name="Payer_ID"> 
            <option value="" selected>-- Select Payer --</option> 
            <cfoutput query="PayerDrop"> 
              <option value="#Payer_ID#|#PayName#|#Output_Type#" <cfif Session.Patient.Payer EQ Payer_ID>selected</cfif>>#PayName#</option> 
            </cfoutput> 
          </select> 
          <input type="hidden" name="Payer_ID_required" value="You must select a Payer." /> </td> 
        <td> <input type="submit" value="Select"> </td> 
      </tr> 
    </table> 
  </form> 
  </cfcase> 
  <cfcase value="Step4"> 
   <script>
    function cSched(f) {
     if(f.Rev_CodeID.selectedIndex < 1) {
      alert('Please select a Type of Visit');
      f.Rev_CodeID.focus();
      return false;
     }
    } 

   </script>
  <h2>Add Schedule</h2> 
  <cfoutput query="GetAssess"> 
    <p><strong>Patient Selected:</strong> #Last_Name_M0040#, #First_Name_M0040# #Middle_Initial_M0040#</p> 
    <p><strong>Certification Period:</strong> #DateFormat(Certification_Start, "mmm d, yyyy")# to #DateFormat(Certification_End, "mmm d, yyyy")#</p> 
    <form name="sched" method="post" action="index.cfm?page=schedules&cat=&rpt=add_schedule&Action=Step5"  onsubmit="return cSched(this);"> 
      <input type="hidden" name="AID" value="#Form.AID#" /> 
      <input type="hidden" name="Patient_ID" value="#Patient_ID#" /> 
      <input type="hidden" name="ATID" value="#Assessment_Tracker_ID#"> 
      <input type="hidden" name="HIPPS_Code" value="#HIPPS_Code#" /> 
      <input type="hidden" name="Certification_Start" value="#DateFormat(Certification_Start,'mm/dd/yyyy')#" /> 
      <input type="hidden" name="Certification_End" value="#DateFormat(Certification_End,'mm/dd/yyyy')#" /> 
      <input type="hidden" name="Payer_ID" value="#Form.Payer_ID#" /> 
	  <input type="hidden" name="hdncity" id="hdncity" value="#GetPatient.city#"/>
	  <input type="hidden" name="hdnstate" id="hdnstate" value="#GetPatient.State_M0050#" />
	  <input type="hidden" name="hdnzipcode" id="hdnzipcode" value="#GetPatient.Zip_M0060#" />
      <cfif Homebound_Status IS ""> 
        <input type="hidden" name="Homebound_Status" value="0" /> 
        <cfelse> 
        <input type="hidden" name="Homebound_Status" value="#Homebound_Status#" /> 
      </cfif> 
      <table border="0" cellpadding="2" cellspacing="2" class="form-border"> 
        <input type="hidden" name="StartTime_required" value="You must specify a Start Time" /> 
        <input type="hidden" name="EndTime_required" value="You must specify an End Time." /> 
        <cfset getsched.starttime="00:00"> 
        <cfset getsched.endtime="00:00"> 
        <cfset getsched.telephony_yes=0> 
        <tr> 
          <td class="form-label">Payer</td> 
          <td><cfoutput>#TempPayer#</cfoutput></td> 
        </tr> 
        <tr> 
          <td class="form-label-req">Type of Visit</td> 
          <td> <select name="Rev_CodeID"> 
              <option value="">-- Select Visit Type --</option> 
              <cfloop query="VisitDrop"> 
                <cfoutput> 
                  <option value="#Rev_CodeID#">#Visit_Type# - #Description#</option> 
                </cfoutput> 
              </cfloop> 
            </select> 
            <input type="hidden" name="Rev_CodeID_required" value="You must select a Visit Type." /> </td> 
        </tr> 
		<tr>
		 <td class="form-label">Location</td> 
          <td>
		  <input type="text" id="txtLocation" name="txtLocation" />
		  &nbsp;
		  <input type="checkbox" id="chkLocation" name="chkLoaction" onclick="Getgeoip();"/>
		  Nearest 50 KM Distance Employees list
		  </td> 
        <tr> 
          <td class="form-label">Employee</td> 
          <td> <select name="Employee_ID" onchange=getScheduleItemsObjectPage('getitems.cfm?t=payroll','selectpayroll_id',this.value);>
              <option value="0">-- Select Employee --</option> 
              <cfloop query="GetEmp"> 
                <cfoutput> 
                  <option value="#Employee_ID#">#Last_Name#, #First_Name#</option> 
                </cfoutput> 
              </cfloop> 
            </select> </td> 
        </tr> 
<tr>
	<td class="form-label">Payroll Code</td>
		<td>
			<div id=selectpayroll_id>
			<select name=EmpPay_ID id=selectpayroll>
			 <option value=0 selected>Select a Payroll Code...</option>
			</select>
			</div>
		</td>
</tr>
        <tr>
          <td class="form-label">Start Time</td> 
          <td> <cfoutput> 
              <cfif Len(GetSched.StartTime) gt 5> 
                <cfset GetSched.StartTime=mid(GetSched.StartTime,1,5)> 
              </cfif> 
              <cfset thehour=GetToken(GetSched.StartTime,1,':')> 
              <cfset theminute=GetToken(GetSched.StartTime,2,':')> 
              <input type="hidden" id="StartTime"  name="StartTime" value="#thehour#:#theminute#"> 
              <cfif thehour gte 12> 
                <cfset thetod='PM'> 
                <cfset thehour=thehour-12> 
                <cfelse> 
                <cfset thetod='AM'> 
              </cfif> 
              <cfif 0> 
                <select id=StartTimeHour name=StartTimeHour onchange="computeAndValidateDate('Start',this.form);"> 
                  <option value="00" <cfif thehour eq 0> selected</cfif>>00</option> 
                  <option value="01" <cfif thehour eq 1> selected</cfif>>1</option> 
                  <option value="02" <cfif thehour eq 2> selected</cfif>>2</option> 
                  <option value="03" <cfif thehour eq 3> selected</cfif>>3</option> 
                  <option value="04" <cfif thehour eq 4> selected</cfif>>4</option> 
                  <option value="05" <cfif thehour eq 5> selected</cfif>>5</option> 
                  <option value="06" <cfif thehour eq 6> selected</cfif>>6</option> 
                  <option value="07" <cfif thehour eq 7> selected</cfif>>7</option> 
                  <option value="08" <cfif thehour eq 8> selected</cfif>>8</option> 
                  <option value="09" <cfif thehour eq 9> selected</cfif>>9</option> 
                  <option value="10" <cfif thehour eq 10> selected</cfif>>10</option> 
                  <option value="11" <cfif thehour eq 11> selected</cfif>>11</option> 
                  <option value="12" <cfif thehour eq 12> selected</cfif>>12</option> 
                </select> 
&nbsp;:&nbsp; 
                <select id=StartTimeMinute name=StartTimeMinute onchange="computeAndValidateDate('Start',this.form);"> 
                  <option value="00"  <cfif theminute eq 0> selected</cfif>>00</option> 
                  <option value="05" <cfif theminute eq 5> selected</cfif>>05</option> 
                  <option value="10" <cfif theminute eq 10> selected</cfif>>10</option> 
                  <option value="15" <cfif theminute eq 15> selected</cfif>>15</option> 
                  <option value="20" <cfif theminute eq 20> selected</cfif>>20</option> 
                  <option value="25" <cfif theminute eq 25> selected</cfif>>25</option> 
                  <option value="30" <cfif theminute eq 30> selected</cfif>>30</option> 
                  <option value="35" <cfif theminute eq 35> selected</cfif>>35</option> 
                  <option value="40" <cfif theminute eq 40> selected</cfif>>40</option> 
                  <option value="45" <cfif theminute eq 45> selected</cfif>>45</option> 
                  <option value="50" <cfif theminute eq 50> selected</cfif>>50</option> 
                  <option value="55" <cfif theminute eq 55> selected</cfif>>55</option> 
                </select> 
                <cfelse> 
                <input type=text id=StartTimeHour  size=2 name=StartTimeHour value="#thehour#" onchange="computeAndValidateDate2('Start',this.form);"> 
                :
                <input type=text id=StartTimeMinute  size=2 name=StartTimeMinute value="#theminute#" onchange="computeAndValidateDate2('Start',this.form);"> 
              </cfif> 
              <input type=radio id=StartTimeAMPM name=StartTimeAMPM value="AM" <cfif thetod eq 'am'> checked</cfif> onclick="computeAndValidateDate2('Start',this.form);"> 
             AM&nbsp; 
              <input type=radio id=StartTimeAMPM name=StartTimeAMPM value="PM" <cfif thetod eq 'pm'> checked</cfif> onclick="computeAndValidateDate2('Start',this.form);"> 
              PM&nbsp; 
              <!---
<br><input type="Text" name="StartTime_Hour" value="#GetSched.StartTime#" size="8"><font size="1"><em> use 1:00 for 1 AM, 13:00 for 1 PM in 15 min increments </em></font>
---> 
            </cfoutput> </td> 
        </tr> 
        <tr> 
          <td class="form-label">End Time</td> 
          <td> <cfoutput> 
              <cfif Len(GetSched.EndTime) gt 5> 
                <cfset GetSched.EndTime=mid(GetSched.EndTime,1,5)> 
              </cfif> 
              <cfset thehour=GetToken(GetSched.EndTime,1,':')> 
              <cfset theminute=GetToken(GetSched.EndTime,2,':')> 
              <input type="hidden" id="EndTime" name="EndTime" value="#thehour#:#theminute#"> 
              <cfif thehour gte 12> 
                <cfset thetod='PM'> 
                <cfset thehour=thehour-12> 
                <cfelse> 
                <cfset thetod='AM'> 
              </cfif> 
              <cfif 0> 
                <select id=EndTimeHour name=EndTimeHour onchange="computeAndValidateDate('End',this.form);"> 
                  <option value="00" <cfif thehour eq 0> selected</cfif>>00</option> 
                  <option value="01" <cfif thehour eq 1> selected</cfif>>1</option> 
                  <option value="02" <cfif thehour eq 2> selected</cfif>>2</option> 
                  <option value="03" <cfif thehour eq 3> selected</cfif>>3</option> 
                  <option value="04" <cfif thehour eq 4> selected</cfif>>4</option> 
                  <option value="05" <cfif thehour eq 5> selected</cfif>>5</option> 
                  <option value="06" <cfif thehour eq 6> selected</cfif>>6</option> 
                  <option value="07" <cfif thehour eq 7> selected</cfif>>7</option> 
                  <option value="08" <cfif thehour eq 8> selected</cfif>>8</option> 
                  <option value="09" <cfif thehour eq 9> selected</cfif>>9</option> 
                  <option value="10" <cfif thehour eq 10> selected</cfif>>10</option> 
                  <option value="11" <cfif thehour eq 11> selected</cfif>>11</option> 
                  <option value="12" <cfif thehour eq 12> selected</cfif>>12</option> 
                </select> 
&nbsp;:&nbsp; 
                <select id=EndTimeMinute name=EndTimeMinute onchange="computeAndValidateDate('End',this.form);"> 
                  <option value="00"  <cfif theminute eq 0> selected</cfif>>00</option> 
                  <option value="05" <cfif theminute eq 5> selected</cfif>>05</option> 
                  <option value="10" <cfif theminute eq 10> selected</cfif>>10</option> 
                  <option value="15" <cfif theminute eq 15> selected</cfif>>15</option> 
                  <option value="20" <cfif theminute eq 20> selected</cfif>>20</option> 
                  <option value="25" <cfif theminute eq 25> selected</cfif>>25</option> 
                  <option value="30" <cfif theminute eq 30> selected</cfif>>30</option> 
                  <option value="35" <cfif theminute eq 35> selected</cfif>>35</option> 
                  <option value="40" <cfif theminute eq 40> selected</cfif>>40</option> 
                  <option value="45" <cfif theminute eq 45> selected</cfif>>45</option> 
                  <option value="50" <cfif theminute eq 50> selected</cfif>>50</option> 
                  <option value="55" <cfif theminute eq 55> selected</cfif>>55</option> 
                </select> 
                <cfelse> 
                <input type=text id=EndTimeHour size=2 name=EndTimeHour value="#thehour#" onchange="computeAndValidateDate2('End',this.form);"> 
                :
                <input type=text id=EndTimeMinute  size=2 name=EndTimeMinute value="#theminute#" onchange="computeAndValidateDate2('End',this.form);"> 
              </cfif> 
              <input type=radio id=EndTimeAMPM name=EndTimeAMPM value="AM" <cfif thetod eq 'am'> checked</cfif> onclick="computeAndValidateDate2('End',this.form);"> 
              AM&nbsp; 
              <input type=radio id=EndTimeAMPM name=EndTimeAMPM value="PM" <cfif thetod eq 'pm'> checked</cfif> onclick="computeAndValidateDate2('End',this.form);"> 
              PM&nbsp; 
              <!---
<br><input type="Text" name="EndTime" value="#GetSched.EndTime#" size="8"><font size="1"><em> use 1:00 for 1 AM, 13:00 for 1 PM in 15 min increments </em></font>
---> 
            </cfoutput> </td> 
        </tr> 
		<tr>
		<td colspan="2">
       <div id="container">
    <div class="eventtitle">
        <p>
            <a style="text-decoration: none" href="javascript://"><b>Recurrence Pattern</b></a></p>
    </div>
    <div class="eventbody" style="display: none">
        <table cellpadding="0" cellspacing="0" border="0" width="100%">
            <tr>
                <td width="22%" class="form-label">
                    <cfoutput> 
              <input type="radio" name="RecurrencePattern" value="Daily" onclick="Weekly();" /> 
              Daily<br />
               <input type="radio" id ="RadioWeekly" name="RecurrencePattern" value="Weekly" onclick="Weekly();" /> 
              Weekly<br />
               <input type="radio" name="RecurrencePattern" value="Monthly" onclick="Weekly();" /> 
              Monthly<br />
               <input type="radio" name="RecurrencePattern" value="Yearly" onclick="Weekly();"/> 
              Yearly<br /></cfoutput>
                </td>
                <td colspan="2">
                    <div id="divDaily" style="display: none">
                        <table cellpadding="3" cellspacing="3" border="0" width="100%">
                            <tr>
                                <td style="padding-left: 5px">
                                    <span>Recurs every</span>
                                    <input id="txtMonthly" type="text" style="width: 40px" />
                                    <span>Week(s) on</span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input type="checkbox" id="chkSunday" name="Recurs" value="Sunday" />Sunday &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="checkbox" id="chkMonday" name="Recurs" value="Monday" />Monday &nbsp;&nbsp;
                                    <input type="checkbox" id="chkTuesday" name="Recurs" value="Tuesday" />Tuesday &nbsp;&nbsp;
                                    <input type="checkbox" id="chkWednesday" name="Recurs" value="Wednesday" />Wednesday
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input type="checkbox" id="chkThursday" name="Recurs" value="Thursday" />Thursday
                                    &nbsp;&nbsp;
                                    <input type="checkbox" id="chkFriday" name="Recurs" value="Friday" />Friday &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="checkbox" id="chkSaturday" name="Recurs" value="Saturday" />Saturday
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="3" style="padding-top:5px">
                    Range of Recurrence
                </td>
            </tr>
            <tr>
                <td style="height: 5px">
                </td>
            </tr>
            <tr>
                <td valign="top" class="form-label">
                    Start
                </td>
                <td width="8%" style="padding-left: 5px; width: 25%">
                    <cf_popdatetime formname="Start" fieldvalue=""
                        fieldname="dtStart" time="no" euro="no" scriptpath="#NavRoot#/Scripts/popDateTime/">
                </td>
                <td width="60%">
                    <input type="radio" name="RecurrenceReference" value="No End Date" />
                    No End Date<br /><br />
                    <input type="radio" name="RecurrenceReference" value="End after" />
                    End after :
                    <input id="txtendAfter" type="text" style="width: 40px" /><span> occurrences</span><br /><br />
                    <input type="radio" name="RecurrenceReference" value="End By" />
                    End By:
                    <cf_popdatetime formname="Start" fieldvalue=""
                        fieldname="dtEndBy" time="no" euro="no" scriptpath="#NavRoot#/Scripts/popDateTime/">
                </td>
            </tr>
        </table>
    </div>   
</div>
        </td>
        </tr>       
        <tr> 
          <td class="form-label">Telephony?</td> 
          <td> <cfoutput> 
              <input type="radio" name="Telephony_Yes" value="1" <cfif getsched.telephony_yes eq 1>checked</cfif>> 
              Yes&nbsp;&nbsp;&nbsp; 
              <input type="radio" name="Telephony_Yes" value="0" <cfif getsched.telephony_yes eq 0 OR getsched.telephony_yes IS "">checked</cfif>> 
              No </cfoutput></td> 
        </tr>
        <tr> 
          <td class="form-label">Visit Notes</td> 
          <td>
					 <textarea name='Visit_Notes' style='width:300px; height:100px;'></textarea>
					</td> 
        </tr> 
        <tr> 
          <td></td>
          <td>
					 <cfif SN_Visit_Orders IS ""> 
              <span class="alert">No SN orders on 485</span> 
              <cfelse> 
              SN Orders: <span class="message">#SN_Visit_Orders#</span> 
            </cfif> </td> 
        </tr> 
        <tr> 
          <td></td>
          <td>
					 <cfif Therapy_Visit_Orders IS ""> 
              <span class="alert">No therapy ordered on 485</span> 
              <cfelse> 
              Therapy Orders: <span class="message">#Therapy_Visit_Orders#</span> 
            </cfif> </td> 
        </tr> 
        <tr> 
          <td></td>
          <td>
					 <cfif HHA_Visit_Orders IS ""> 
              <span class="alert">No HHA ordered on 485</span> 
              <cfelse> 
              HHA Orders: <span class="message">#HHA_Visit_Orders#</span> 
            </cfif> </td> 
        </tr> 
      </table> 
	  <!--- JavaScript ---> 
	 <script type="text/javascript">
			var wrap = document.getElementById('container'), divs = wrap.getElementsByTagName('div');
			for (var i=0; i<divs.length; i++)
			 if (/\beventtitle\b/gi.test(divs[i].className)) divs[i].getElementsByTagName('a')[0].onclick = showHide;			 
			function showHide()
			 {
				 var p = this.parentNode.parentNode, div = p.nextSibling;
				 while (div.nodeType != 1) div = div.nextSibling;
				 div.style.display = (div.style.display == 'none') ? 'block' : 'none';
            }
     </script>
	 
	 <script type="text/javascript">
		function Weekly()
		{
			  if(document.getElementById('RadioWeekly').checked == true)
			  {
					document.getElementById("divDaily").style.display = 'block'; 
			  }
			  else
			  {
					document.getElementById("divDaily").style.display = 'none'; 
			  }
      }
	  
	function ChkSchedule(form)
	{
		var total = 0;
		var max = form.Recurs.length;
		for(var idx = 0; idx < max; idx++)
		{
		if(eval("document.playlist.Recurs[" + idx + "].checked") == true)
		{
		total += 1;
		}
		}
		var Count =document.getElementById('txtMonthly').value;
		if(total>Count)
		{
		 alert("Recurs every Week(s) & Day Should be equal");
		}
		else if(total<Count)
		{
		 alert("Recurs every Week(s) & Day Should be equal");
		}
    }
  </script> 	  
      <!--- Insert Calendar ---> 
      <p><strong>Select the dates to schedule visits, by checking them on the calendar below.</strong></p> 
      <table width=100%> 
        <cfset nummonths=NumDays/28+1> 
        <tr> 
         <cfloop index=mth from=1 to=#nummonths#> 
          <cfset themth=mth-1> 
          <td valign=top> <cf_pcd_sel_calendar startdate="#DateFormat(DateAdd('m', themth, GetAssess.Certification_Start), 'mm/dd/yyyy')#"><br /> </td> 
          <cfif themth MOD 2 EQ 1> </tr> 
             <tr> </tr> 
           </cfif> 
        </cfloop> 
      </table> 
      <p align="center"> 
        <input type="submit" value="Schedule" onclick="ChkSchedule(this.form)"/> 
      </p> 
    </form> 
  </cfoutput> 
  </cfcase> 
  <cfcase value="Step5"> 
  <!--- If ErrorFlag has not been set, display success message, otherwise display error message ---> 
  <cfif ErrorFlag IS ""> 
    <cflocation url="index.cfm?view=day"> 
    <cfelse> 
    <cfswitch expression="#ErrorFlag#"> 
      <cfcase value="No Dates"> 
      <h3>Scheduling Problem</h3> 
      <p><strong>You must select at least one date to schedule.</strong></p> 
      <p><strong>Please click the Back button in your browser to correct the problem.</strong></p> 
      </cfcase> 
      <cfcase value="Too Many"> 
      <h3>Scheduling Problem</h3> 
      <p><strong>For an Admission Visit, you can only specify one visit date.</strong></p> 
      <p><strong>Please click the Back button in your browser to correct the problem.</strong></p> 
      </cfcase> 
      <cfcase value="Out of Range"> 
      <h3>Scheduling Problem</h3> 
      <p><strong>One of the dates you specified is outside the Certification Period.</strong></p> 
      <p><strong>Please click the Back button in your browser to correct the problem.</strong></p> 
      </cfcase> 
    </cfswitch> 
  </cfif> 
  </cfcase> 
</cfswitch> 


