Link to home
Start Free TrialLog in
Avatar of SEUPB
SEUPB

asked on

4 Week Timesheet

Hi,

I recently finished developing a 4 week web based timesheet with the help of honorGod. I have managed to make addition changes to the coding he helped code for me but I have hit a wall.

I am looking to modify the current coding, which detects if note statuses, one being a full day status and the other being a half day status. The system basically detects that once a full day status has been selected no half day statuses can be selected afterwards.

My current problem is the current coding only detects one instance of half day status but I've managed to modify it to detect two instances of half day status. But now I need to detect 3 instances of half day status.

Can anyone take a look at the coding for me?
var index = obj.selectedIndex;
      if ( obj.options[ index ].disabled ) {
        alert( 'Sorry, that selection is not available.' );
        index = obj.selectedIndex = 0;
      }
      var noteVal = obj.options[ index ].innerHTML;
      //--------------------------------------------------------------
      // Only 1 instance of FDFL, or 2 of HDFL are allowed.
      // So, if 1 FDFL has been selectd, disable all FDFL and HDFL
      // If 1 HDFL has been selected, disable all FDFL
      // If 2 HDFL have been selected, disable all HDFL
      //--------------------------------------------------------------
      var notes = new Array();
	  var names = 'flag01,flag02,flag03,flag04,flag05,flag11,flag12,flag13,flag14,flag15,flag21,flag22,flag23,flag24,flag25,flag31,flag32,flag33,flag34,flag35'.split( ',' );
 
	  //for ( var i = 0; i < names.length; i++ ) 
	 // { notes = notes.concat( document.getElementsByName( names[ i ] ) );
		//}
 
		for ( var i = 0; i < names.length; i++ ) {
  var sel = document.getElementsByName( names[ i ] );
  for ( var j = 0; j < sel.length; j++ ) {
    if ( sel[ j ].type != 'select-one' ) {
      //alert( 'Problem: element with name="' + names[ i ] +  '" has type="' + sel[ j ].type + '"' );
	  document.getElementById( 'debug' ).innerHTML = sel[ j ].innerHTML;
 
    } else {
      notes[ notes.length ] = sel[ j ];
    }
  }
}
 
      var fdfl  = 0;                     // number of FDFL picked?
      var hdfl  = 0;					 // number of HDFL picked
	  var hahf  = 0;					 // number of HAHF picked
	  var hshf  = 0;                     // number of HSHF picked
      for ( var i = 0; i < notes.length; i++ ) {
        var x   = notes[ i ].selectedIndex;
        var val = notes[ i ].options[ x ].innerHTML;
        if ( val == 'FDFL' ) fdfl++;
        if ( val == 'HDFL' ) hdfl++;
		if ( val == 'HAHF' ) hahf++;
		if ( val == 'HSHF' ) hshf++;
      }
//    alert( 'FDFL = ' + fdfl + '\nHDFL = ' + hdfl + '\nthis = ' + noteVal + '\nid = "' + id + '"' );
      //--------------------------------------------------------------
      // Now that we've determined how many Flexi Leave selects have
      // been made, we process the "notes" selection lists to
      // enable/disable the Flexi Leave selections as appropriate.
      // Note: In a perfect world, an "option" disabled attribute
      //       could be set to true/false, and everything would work
      //       fine.  Unfortunately, FireFox, and IE act very
      //       differently when it comes to "disabled" options.
      //       FireFox - doesn't care what the value is, the presence
      //                 of the disabled attribute makes the option
      //                 unselectable.  So, in order to "enable" the
      //                 option, we need to use removeAttribute()
      //       IE      - doesn't care if the attribute is present or
      //                 not.  So, we have to check when an option is
      //                 selected to see if the attribute is present.
      //--------------------------------------------------------------
      for ( var i = 0; i < notes.length; i++ ) {
        for ( var j = 0; j < notes[ i ].options.length; j++ ) {
          var val = notes[ i ].options[ j ].innerHTML;
          //----------------------------------------------------------
          // FDFL - disable if any (other) FDFL have been selected, or
          //        if any HDFL have been selected.
          //----------------------------------------------------------
//        var set = ( notes[ i ].id != id ) && ( ( fdfl > 0 ) || ( hdfl > 0 ) );
          var set = ( fdfl > 0 ) || ( hdfl > 0 ) || (hahf > 0) || (hshf > 0);
          if ( val == 'FDFL' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
		  
		  set = ( fdfl > 0 ) || ( hdfl > 1) || (hshf > 1) || (hahf > 1);
          if ( val == 'HAHF' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
		  
		  set = ( fdfl > 0 ) || ( hdfl > 1) || (hahf > 1) || (hshf > 1);
          if ( val == 'HSHF' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
          //----------------------------------------------------------
          // HDFL - disable if any FDFL have been selected, or if move
          //        than 1 other HDFL have been selected
          //----------------------------------------------------------
//        set = ( notes[ i ].id != id ) && ( ( fdfl > 0 ) || ( hdfl > 1 ) );
          set = ( fdfl > 0 ) || (hahf > 1) || ( hshf > 1) || ( hdfl > 1);
          if ( val == 'HDFL' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
        }
      }
    }

Open in new window

Avatar of HonorGod
HonorGod
Flag of United States of America image

What, exactly, do you mean by "3 instances of half-day" status?
Avatar of SEUPB
SEUPB

ASKER

Hey HonorGod!!

Thank god I have found you heh. Hope you are keeping? Apologies for the confusion. You remember when you coded this for me I wanted a rule that would only allow you to pick 1 FDFL or 2 HDFL?

Basically since then I've had to accommodate other variations of HDFL in terms of HAHF (half day annual + half day flexi) and HSHF (half day special + half day flexi). So basically,

If I choose one HDFL I should only be allowed to select one more HDFL or HAHF or HSFL with the rule only allowing a combination of 2 half days.

Hope this makes sense.

Regards,

Mike
 I've been trying to survive.  Hopefully you have been doing well.
As far as the "changing requirements", that's life in the software development
world. :-)

  I see that you put in the following code to "count" the number of full & hald
day vacations that someone has used in a week.  Is that what it is supposed
to compute?  Or is it supposed to compute the number of full/half days off for
the 4-week period?

  What is the value of notes.length?  Does it reflect/represent entries for a
week, or a "month" (i.e., 4-week period)?

  At one time, you had an alert output the values (fdfd, hdfl, ...)  Were these
values being computed correctly?  What about hafl & hsfl?
      for ( var i = 0; i < notes.length; i++ ) {
        var x   = notes[ i ].selectedIndex;
        var val = notes[ i ].options[ x ].innerHTML;
        if ( val == 'FDFL' ) fdfl++;
        if ( val == 'HDFL' ) hdfl++;
        if ( val == 'HAHF' ) hahf++;
        if ( val == 'HSHF' ) hshf++;
      }
//    alert( 'FDFL = ' + fdfl + '\nHDFL = ' + hdfl + '\nthis = ' + noteVal + '\nid = "' + id + '"' );

Open in new window

Avatar of SEUPB

ASKER

Hi HonorGod,

Thats good to know. Yeah I've trying to survie too by working loads heh. The code you attached was orignally coded by you heh. I only made a few changes, which were,

if ( val == 'HAHF' ) hahf++;
if ( val == 'HSHF' ) hshf++;

If i remember the value of notes.length represented a 1 month / 4 week period. To be honest I couldn't fully workout your coding heh so I was pretty much trial and erroring with my additions. I only did manage to get it to recognise 2 instances of half day flexi leave in therms of HDFL and HAHF, its the newest addition of HSHF I couldn't get working.

I never tried the alert output feature with the HAFL & HSFL flags....
Well, the code that follows that references the counters (i.e., fdfl, hdfl, hahf, & hshf) appears to be trying to decide whether the entries should be enabled.

Can you provide the whole code?

It would be much easier to understand what is happening by looking at the code in its entirety.
Avatar of SEUPB

ASKER

Hi HonorGod,

Apologies for the delay was away home when you replied. Yeah I managed to get the code to try to enable or disable the notes depending on what has been selected so far. But it doesn't seem to work properly, it seems to work fine when notes are seleted in a certain sequence etc.

I have attached the code for you.
<script type='text/javascript'>
  //------------------------------------------------------------------
  // Name: twoD()
  // Role: convert single digit (numeric) values to 2 digits by
  //       prepending a leading zero (if appropriate)
  //------------------------------------------------------------------
  function twoD( val ) {
    if ( ( ( typeof( val ) == 'number' ) && ( val < 10 ) ) || ( val.length < 2 ) ) {
      val = '0' + val;
    }
    return val;
  }
 
  //------------------------------------------------------------------
  // Name: HtoM()
  // Role: convert a time (HH:MM) to minutes
  //  Fix: Change to handle hours > 99, as well as negative values...
  //------------------------------------------------------------------
  function HtoM( val ) {
    var result = 0;
    //----------------------------------------------------------------
    // Use a Regular Expression to see if the specified value is in
    // the proper format, i.e., optional +/- sign, 0 to 3 digits,
    // optional ':', and required 2 digits.
    //----------------------------------------------------------------
    if ( val.search( /^([-+])?(\d{0,3}):?(\d\d)$/ ) == 0 ) {
      //--------------------------------------------------------------
      // A pattern match will update the global RegExp object so that
      // $1 == sign, $2 == Hours, and $3 == Minutes
      //--------------------------------------------------------------
      var s = RegExp.$1, h = RegExp.$2, m = RegExp.$3;
      //--------------------------------------------------------------
      // Note: parseInt() of a value having leading zeros will be
      //       interpreted/parsed an an octal value, unless we specify
      //       the radix (i.e., the numeral system to be used).
      //--------------------------------------------------------------
      result = ( parseInt( h, 10 ) * 60 + parseInt( m, 10 ) ) * ( ( s == '-' ) ? -1 : 1 );
    }
    return result;
  }
 
  //------------------------------------------------------------------
  // Name: MtoH()
  // Role: Format the specified value (minutes) into +HH:MM
  //------------------------------------------------------------------
  function MtoH( val ) {
    var result, prefix = '+';
    if ( val < 0 ) {
      prefix = '-';
      val = -val;
    }
    var min = ( val % 60 );
    var hrs = ( val - min ) / 60;
    return prefix + twoD( hrs ) + ':' + twoD( min );
  }
 
  //------------------------------------------------------------------
  // Name: field()
  // Role: verify that a DOM element with the specified id exists.
  //------------------------------------------------------------------
  function field( id ) {
    var item = document.getElementById( id );
    if ( !item ) {
      alert( 'Specified field not found: ' + id );
    }
    return item;
  }
 
  //------------------------------------------------------------------
  // Name: compute()
  // Role: Use the available values for a specific day to compute the
  //       hours worked, and flexi hours credited or debited.
  //------------------------------------------------------------------
  function compute( idSuffix ) {
    if ( typeof( idSuffix ) == 'number' ) {
      idSuffix += '';                  // Convert to a string
      if ( idSuffix.length < 2 ) {     // And guarantee string length
        idSuffix = '0' + idSuffix;
      }
    }
    var start  = field( 'startTime'  + idSuffix );
    var stop   = field( 'finishTime' + idSuffix );
    var brk    = field( 'lunch'      + idSuffix );
    var debit  = field( 'debit'      + idSuffix );
    var atWrk  = field( 'totalHr'    + idSuffix );
    var worked = field( 'hrWorked'   + idSuffix );
    var credit = field( 'credit'     + idSuffix );
    var note   = field( 'note'       + idSuffix );
    //----------------------------------------------------------------
    // Unfortunately, we have to use this idiom to make sure to obtain
    // the actual note.value (thanks to IE)... :-(
    //----------------------------------------------------------------
    var noteVal = note.value || note.options[ note.selectedIndex ].innerHTML;
 
    //----------------------------------------------------------------
    // The number of minutes in a standard workday is based upon the
    // day of the week.  For Mon..Thu (i.e., day# 1..4), there are
    // 445 minutes, on Fri, (i.e., day# 5) we only work 440.
    // Note: A half-day is 3:45 - regardless of the day of the week.
    //----------------------------------------------------------------
    var wday = ( idSuffix.substr( 1 ) < '5' ) ? 445 : 440;
    var hday = ( idSuffix.substr( 1 ) < '5' ) ? 225 : 220;
 
    //----------------------------------------------------------------
    // Given non-blank start & stop times, try to compute the rest...
    //----------------------------------------------------------------
    if ( ( start.value != '' ) && ( stop.value != '' )  ) {
      //--------------------------------------------------------------
      // Retrieve the day values (and convert each to minutes)
      //--------------------------------------------------------------
      var startT = HtoM( start.value );     // Start Time (minutes)
      var stopT  = HtoM( stop.value );      // Stop  Time (minutes)
      var brkT   = HtoM( brk.value );       // Break Time (minutes)
	  var workT  = HtoM( worked.value );    // Work Time  (minutes)
      var debitT = HtoM( debit.value );     // Debit Time (minutes)
      //--------------------------------------------------------------
      // minutes == # minutes they have been at work
      // For "Half-Days" either Annual Leave, or Flexi Leave, we don't
      // make them take a lunch break
      //--------------------------------------------------------------
      var minutes = stopT - startT;
	  var difference = wday - minutes;
      if ( noteVal.substr( 0, 2 ) == 'HD' ) {
        brkT = 0;
        brk.value = '00:00';
      } else {
        //------------------------------------------------------------
        // Has a lunch break been specified?  If not, default it...
        // Note: If 4 hours (240 minutes) or less are worked then no
        //       lunch break is required.
        // Note: If a "Half Day" is coded, no lunch break is required.
        //------------------------------------------------------------
        if ( ( brk.value == '' ) || ( brkT < 0 ) ) {
          brkT = ( minutes < 241 ) ? 0 : 30;
          brk.value = MtoH( brkT ).substr( 1 );
        }
        if ( ( brk.value != '' ) && ( minutes > 240 ) && ( brkT < 30 ) ) {
          alert( 'A Lunch break of 30 (or more) minutes is required.' );
          brkT = 30;
          brk.value = MtoH( brkT ).substr( 1 );     // No sign included
        }
      }
      if ( minutes < 0 ) {
        alert( 'The start time must be at or before the end time.' );
        brk.value = debit.value = credit.value = atWrk.value = worked.value = '';
      } else {
        //------------------------------------------------------------
        // These values do not include a sign prefix since they are,
        // or at least, should be positive.
        //------------------------------------------------------------
        atWrk.value  = MtoH( minutes ).substr( 1 );
        worked.value = MtoH( minutes - brkT ).substr( 1 );
        //------------------------------------------------------------
        // Have they worked less than a full day?
        //------------------------------------------------------------
//      alert( 'startT: ' + startT + '\n stopT: ' + stopT + '\nminutes: ' + ( minutes - brkT ) + '\n  atWork: ' + minutes );
       // if ( minutes - brkT < wday ) {
         // debit.value = MtoH( minutes - brkT - wday );
          //credit.value  = '+' + MtoH( 0 ).substr( 1 );
        //} else {
          if ( minutes - brkT < wday ) {
            switch ( noteVal ) {
              //--------------------------------------------------------
              // Stat Leave
              //--------------------------------------------------------
              case 'STAT' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
				worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
                debit.value  = '-00:00';
                break;
              //--------------------------------------------------------
              // Full Day Annual Leave
              //-------------------------------------------------------- 
              case 'FDAL' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
              //--------------------------------------------------------
              // Half Day Annual Leave - with Flexi Band Restrictions
              //--------------------------------------------------------
              case 'HDAL' :
                debit.value = credit.value = '-00:00';
                //------------------------------------------------------
                // Are they working in the morning, or in the afternoon?
                //------------------------------------------------------
                if ( startT < HtoM( '12:00' ) ) {
                  var msg = '';
                  //----------------------------------------------------
                  // Afternoon off.  Check the starting & ending time...
                  //----------------------------------------------------
                  if ( ( startT < HtoM( '08:00' ) ) || ( stopT < HtoM( '12:00' ) ) || ( stopT > HtoM( '14:00' ) ) ) {
                    if ( startT < HtoM( '08:00' ) ) {
                      start.value = '08:00';
                      startT = HtoM( '08:00' );
                      msg = 'Changing start time to 08:00';
                    }
                    if ( stopT < HtoM( '12:00' ) ) {
                      stop.value = '12:00';
                      stopT = HtoM( '12:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 12:00';
                      } else {
                        msg += ', and stop time to 12:00';
                      }
                    }
                    if ( stopT > HtoM( '14:00' ) ) {
                      stop.value = '14:00';
                      stopT = HtoM( '14:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 14:00';
                      } else {
                        msg += ', and stop time to 14:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                } else {
                  //----------------------------------------------------
                  // Morning off.  Check the starting & ending time...
                  //----------------------------------------------------
                  msg = '';
                  if ( ( startT > HtoM( '14:00' ) ) || ( stopT > HtoM( '18:00' ) ) ) {
                    if ( startT > HtoM( '14:00' ) ) {
                      start.value = '14:00';
                      startT = HtoM( '14:00' );
                      msg = 'Changing start time to 14:00';
                    }
                    if ( stopT > HtoM( '18:00' ) ) {
                      stop.value = '18:00';
                      stopT = HtoM( '18:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 18:00';
                      } else {
                        msg += ', and stop time to 18:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                }
                
                if ( minutes < hday ) {
                  if ( ( startT == stopT ) && ( startT == 0 ) ) {
                    start.value = stop.value = atWrk.value = worked.value = brk.value = debit.value = '';
                  } else {
                    debit.value = MtoH( minutes + hday - wday );
                  }
                } else {
                  credit.value = MtoH( minutes + hday - wday );
                }
                worked.value = MtoH( minutes + hday ).substr( 1 );
                break;              
              //--------------------------------------------------------
              // Full Day Flexi Leave
              //--------------------------------------------------------
              case 'FDFL' :
                alert( 'Specified start and/or stop times ignored, and reset.' );
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = '00:00';
 
                credit.value = MtoH( minutes - brkT );
                debit.value  = MtoH( -wday );
                break;
              //--------------------------------------------------------
              // Half Day Flexi Leave - with Flexi Band Restrictions
              //--------------------------------------------------------
              case 'HDFL' :
                credit.value = '+00:00';
                //------------------------------------------------------
                // Are they working in the morning, or in the afternoon?
                //------------------------------------------------------
                if ( startT < HtoM( '12:00' ) ) {
                  var msg = '';
                  //----------------------------------------------------
                  // Afternoon off.  Check the starting & ending time...
                  //----------------------------------------------------
                  if ( ( startT < HtoM( '08:00' ) ) || ( stopT < HtoM( '12:00' ) ) || ( stopT > HtoM( '14:00' ) ) ) {
                    if ( startT < HtoM( '08:00' ) ) {
                      start.value = '08:00';
                      startT = HtoM( '08:00' );
                      msg = 'Changing start time to 08:00';
                    }
                    if ( stopT < HtoM( '12:00' ) ) {
                      stop.value = '12:00';
                      stopT = HtoM( '12:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 12:00';
                      } else {
                        msg += ', and stop time to 12:00';
                      }
                    }
                    if ( stopT > HtoM( '14:00' ) ) {
                      stop.value = '14:00';
                      stopT = HtoM( '14:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 14:00';
                      } else {
                        msg += ', and stop time to 14:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                } else {
                  //----------------------------------------------------
                  // Morning off.  Check the starting & ending time...
                  //----------------------------------------------------
                  msg = '';
                  if ( ( startT > HtoM( '14:00' ) ) || ( stopT > HtoM( '18:00' ) ) ) {
                    if ( startT > HtoM( '14:00' ) ) {
                      start.value = '14:00';
                      startT = HtoM( '14:00' );
                      msg = 'Changing start time to 14:00';
                    }
                    if ( stopT > HtoM( '18:00' ) ) {
                      stop.value = '18:00';
                      stopT = HtoM( '18:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 18:00';
                      } else {
                        msg += ', and stop time to 18:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                }
                if ( minutes < hday ) {
                  if ( ( startT == stopT ) && ( startT == 0 ) ) {
                    start.value = stop.value = atWrk.value = worked.value = brk.value = debit.value = '';
                  } else {
                    debit.value  = MtoH( minutes - wday );
                  }
                }
                worked.value = MtoH( minutes ).substr( 1 );
                debit.value  = MtoH( minutes - wday );
                break;
			  //--------------------------------------------------------
              // Half Day Flexi / Half Day Annual
              //--------------------------------------------------------	
			  case 'HAHF' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( hday ).substr( 1 );
                credit.value = '+00:00';
                debit.value  = MtoH( -hday );
                break;
				
			  //--------------------------------------------------------
              // Half Day Special / Half Day Annual
              //--------------------------------------------------------	
			  case 'HSHA' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
				
			  //--------------------------------------------------------
              // Half Day Special / Half Day Flexi
              //--------------------------------------------------------	
			  case 'HSHF' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( hday ).substr( 1 );
                credit.value = '+00:00';
                debit.value  = MtoH( -hday );
                break;
			  //--------------------------------------------------------
              // Full Day Sick Leave
              //--------------------------------------------------------	
			  case 'FDSL' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
              //--------------------------------------------------------
              // Half Day Sick Leave
              //--------------------------------------------------------
			  case 'HDSL' :
                worked.value = MtoH( wday ).substr( 1 );
				brk.value = '00:00';
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
				break;
			  //--------------------------------------------------------
			  // Special Leave
			  //--------------------------------------------------------
			  case 'FDSP' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
			  //--------------------------------------------------------
              // Half Day Special Leave - with Flexi Band Restrictions
              //--------------------------------------------------------
              case 'HDSP' :
			  	credit.value = '+00:00';
                debit.value = '-00:00';
                //------------------------------------------------------
                // Are they working in the morning, or in the afternoon?
                //------------------------------------------------------
                if ( startT < HtoM( '12:00' ) ) {
                  var msg = '';
                  //----------------------------------------------------
                  // Afternoon off.  Check the starting & ending time...
                  //----------------------------------------------------
                  if ( ( startT < HtoM( '08:00' ) ) || ( stopT < HtoM( '12:00' ) ) || ( stopT > HtoM( '14:00' ) ) ) {
                    if ( startT < HtoM( '08:00' ) ) {
                      start.value = '08:00';
                      startT = HtoM( '08:00' );
                      msg = 'Changing start time to 08:00';
                    }
                    if ( stopT < HtoM( '12:00' ) ) {
                      stop.value = '12:00';
                      stopT = HtoM( '12:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 12:00';
                      } else {
                        msg += ', and stop time to 12:00';
                      }
                    }
                    if ( stopT > HtoM( '14:00' ) ) {
                      stop.value = '14:00';
                      stopT = HtoM( '14:00' );
 
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 14:00';
                      } else {
                        msg += ', and stop time to 14:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                } else {
                  //----------------------------------------------------
                  // Morning off.  Check the starting & ending time...
                  //----------------------------------------------------
                  msg = '';
                  if ( ( startT > HtoM( '14:00' ) ) || ( stopT > HtoM( '18:00' ) ) ) {
                    if ( startT > HtoM( '14:00' ) ) {
                      start.value = '14:00';
                      startT = HtoM( '14:00' );
                      msg = 'Changing start time to 14:00';
                    }
                    if ( stopT > HtoM( '18:00' ) ) {
                      stop.value = '18:00';
                      stopT = HtoM( '18:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 18:00';
                      } else {
                        msg += ', and stop time to 18:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                }
                
                if ( minutes < hday ) {
                  if ( ( startT == stopT ) && ( startT == 0 ) ) {
                    start.value = stop.value = atWrk.value = worked.value = brk.value = debit.value = '';
                  } else {
                    debit.value = MtoH( minutes + hday - wday );
                  }
                } else {
                  credit.value = MtoH( minutes + hday - wday );
                }
                worked.value = MtoH( minutes + hday ).substr( 1 );
                break;
              //--------------------------------------------------------
              // Unspecified / Undefined
              //--------------------------------------------------------
              case '--' :
                if ( credit.value != '+00:00' ) credit.value = '+00:00';
                debit.value = ( minutes && brkT ) ? MtoH( minutes - brkT - wday ) : '';
                break;
              //--------------------------------------------------------
              // Unexpected!
              //--------------------------------------------------------
              default:
                alert( 'Unexpected note value: "' + noteVal + '"' );
            }
          } else {
            //----------------------------------------------------------
            // ( minutes - brkT >= wday ) ...
            //----------------------------------------------------------
            if ( noteVal.substr( 0, 2 ) == 'HD' ) {
              alert( 'Too many hours worked for specified note selection: ' + noteVal );
              note.selectedIndex = 0;
              adjust( document.getElementById( 'note' + idSuffix ), idSuffix, idSuffix.substr( 0, 1 ) );
            }
            debit.value  = '-' + MtoH( 0 ).substr( 1 );
            credit.value = MtoH( minutes - brkT - wday );
          }
        }
    //}
    } else {
      switch ( noteVal ) {
        //--------------------------------------------------------
        // Stat Leave
        //--------------------------------------------------------
        case 'STAT' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
		  worked.value = MtoH( wday ).substr( 1 );
          credit.value  = '+00:00';
          debit.value  = '-00:00';
          break;
        //------------------------------------------------------------
        // Full Day Annual Leave
        //------------------------------------------------------------
        case 'FDAL' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = MtoH( wday ).substr( 1 );
          credit.value  = '+00:00';
          debit.value  = '-00:00';
          break;
        //------------------------------------------------------------
        // Half Day Annual Leave
        //------------------------------------------------------------
        case 'HDAL' :
          credit.value = debit.value = '+00:00';
          worked.value = MtoH( hday ).substr( 1 );
          break;
        //------------------------------------------------------------
        // Full Day Flexi Leave
        //------------------------------------------------------------
        case 'FDFL' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = credit.value = '00:00';
          debit.value  = MtoH( -wday );
          break;
        //------------------------------------------------------------
        // Half Day Flexi Leave
        //------------------------------------------------------------
        case 'HDFL' :
          credit.value = '+00:00';
          debit.value  = '-00:00';
//        start.value  = stop.value = atWrk.value = worked.value = brk.value = credit.value = '';
          break;
		  
		//--------------------------------------------------------
        // Half Day Flexi / Half Day Annual
        //--------------------------------------------------------	
		case 'HAHF' :
           start.value  = stop.value = atWrk.value = brk.value = '00:00';
           worked.value = MtoH( hday ).substr( 1 );
           credit.value = '+00:00';
           debit.value  = MtoH( -hday );
           break;
				
		//--------------------------------------------------------
        // Half Day Special / Half Day Annual
        //--------------------------------------------------------	
		case 'HSHA' :
           start.value  = stop.value = atWrk.value = brk.value = '00:00';
           worked.value = MtoH( wday ).substr( 1 );
           credit.value  = '+00:00';
           debit.value  = '-00:00';
           break;
				
		//--------------------------------------------------------
        // Half Day Special / Half Day Flexi
        //--------------------------------------------------------	
		case 'HSHF' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = MtoH( hday ).substr( 1 );
          credit.value = '+00:00';
          debit.value  = MtoH( -hday );
          break;
        //------------------------------------------------------------
        // Full Day Sick Leave
        //------------------------------------------------------------
        case 'FDSL' :
		  worked.value = MtoH( wday ).substr( 1 );
		  start.value  = stop.value = atWrk.value = brk.value = '00:00';		
		  credit.value = '+00:00';
          debit.value  = '-00:00';
          
          break;
		//------------------------------------------------------------
        // Half Day Sick Leave
        //------------------------------------------------------------
		case 'HDSL' :
		  worked.value = MtoH( wday ).substr( 1 );
          credit.value = '+00:00';
		  debit.value = '-00:00';
		  brk.value = '00:00';
          break;
		//------------------------------------------------------------
        // Full Day Special Leave
        //------------------------------------------------------------
        case 'FDSP' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = MtoH( wday ).substr( 1 );
          credit.value  = '+00:00';
          debit.value  = '-00:00';
          break;
		//------------------------------------------------------------
        // Half Day Special Leave
        //------------------------------------------------------------
        case 'HDSP' :
          credit.value = '+00:00';
		  debit.value = '-00:00';
          worked.value = MtoH( hday ).substr( 1 );
          break;
        //------------------------------------------------------------
        // Unspecified / Undefined
        //------------------------------------------------------------
        case '--' :
          if ( credit.value != '+00:00' ) credit.value = '+00:00';
          debit.value = ( minutes && brkT ) ? MtoH( minutes - brkT - wday ) : '';
          break;
        //------------------------------------------------------------
        // Unexpected!
        //------------------------------------------------------------
        default:
          alert( 'Unexpected note value: "' + noteVal + '"' ) 
      }
    }
  }
 
  //------------------------------------------------------------------
  // Name: calc()
  // Role: Compute the weekly hours and flexi time fields
  //------------------------------------------------------------------
  function calc( hId, cId, dId, week ) {
    var worked = field( hId + week );  // Weekly hours worked field
    var credit = field( cId + week );  // Weekly credit field
    var debit  = field( dId + week );  // Weekly debit  field
    var hSum   = 0;                    // Weekly hours worked sum
    var cSum   = 0;                    // Weekly credit hours sum
    var dSum   = 0;                    // Weekly debit  hours sum
    //----------------------------------------------------------------
    // weekly sum of (non-blank) hoursWorked, credit, & debit values
    //----------------------------------------------------------------
    for ( var i = 1; i < 6; i++ ) {
      var hDay = field( hId + week + i ).value;
      if ( hDay != '' ) {
        hDay.match( /^(\d\d:\d\d)$/ );
        hSum += HtoM( RegExp.$1 );
      }
      var cDay = field( cId + week + i ).value;
      if ( cDay != '' ) {
        cDay.match( /^([-+]?)(\d\d:\d\d)$/ );
        var s = RegExp.$1, m = HtoM( RegExp.$2 );
        cSum += ( s == '-' ) ? -m : m;
      }
      var dDay = field( dId + week + i ).value;
      if ( dDay != '' ) {
        dDay.match( /^([-+]?)(\d\d:\d\d)$/ );
        var s = RegExp.$1, m = HtoM( RegExp.$2 );
        dSum += ( s == '-' ) ? -m : m;
      }
    }
    //----------------------------------------------------------------
    // If the hours worked target field exists, store the info
    //----------------------------------------------------------------
    if ( worked ) {
      worked.value = MtoH( hSum ).substr( 1 );   // Discard sign
    }
    //----------------------------------------------------------------
    // If the credit target field exists, store the value
    //----------------------------------------------------------------
    if ( credit ) {
      credit.value = MtoH( cSum );               // Include sign
    }
    //----------------------------------------------------------------
    // If the debit target field exists, store the value
    //----------------------------------------------------------------
    if ( debit ) {
      debit.value = MtoH( dSum );               // Include sign
    }
  }
 
  //------------------------------------------------------------------
  // Name: adjust()
  // Role: Check the daily, and weekly calculations, and adjust the
  //       cumulative flexi time accordingly;
  // Note: obj is a reference to the DOM element containing the call
  //       which is required to have a "well formed" id attribute of
  //       the form id='note##' where: xx is the idSuffix of the value
  //------------------------------------------------------------------
  function adjust( obj, idSuffix, week ) {
    if ( obj && ( obj.nodeName == 'SELECT' ) && ( 'id' in obj ) && ( obj.id.search( /^note(\d\d)$/ ) == 0 ) ) {
      idSuffix = RegExp.$1;
      week     = idSuffix.substr( 0, 1 );
      var id   = obj.id;
      //--------------------------------------------------------------
      // Which DOM element was selected, and to what value was it set?
      // Note: it is possible (at least in IE) that the previous
      //       selection was HDFL, and they just tried to change it to
      //       FDFL instead.  Unfortunately, if this option has been
      //       marked as disabled, then the selection will be reset to
      //       '--' (i.e., index = 0), and we need to redo all of the
      //       option settings to see which (if any) should be
      //       disabled.
      //--------------------------------------------------------------
      var index = obj.selectedIndex;
      if ( obj.options[ index ].disabled ) {
        alert( 'Sorry, that selection is not available.' );
        index = obj.selectedIndex = 0;
      }
      var noteVal = obj.options[ index ].innerHTML;
      //--------------------------------------------------------------
      // Only 1 instance of FDFL, or 2 of HDFL are allowed.
      // So, if 1 FDFL has been selectd, disable all FDFL and HDFL
      // If 1 HDFL has been selected, disable all FDFL
      // If 2 HDFL have been selected, disable all HDFL
      //--------------------------------------------------------------
      var notes = new Array();
	  var names = 'flag01,flag02,flag03,flag04,flag05,flag11,flag12,flag13,flag14,flag15,flag21,flag22,flag23,flag24,flag25,flag31,flag32,flag33,flag34,flag35'.split( ',' );
 
	  //for ( var i = 0; i < names.length; i++ ) 
	 // { notes = notes.concat( document.getElementsByName( names[ i ] ) );
		//}
 
		for ( var i = 0; i < names.length; i++ ) {
  var sel = document.getElementsByName( names[ i ] );
  for ( var j = 0; j < sel.length; j++ ) {
    if ( sel[ j ].type != 'select-one' ) {
      //alert( 'Problem: element with name="' + names[ i ] +  '" has type="' + sel[ j ].type + '"' );
	  document.getElementById( 'debug' ).innerHTML = sel[ j ].innerHTML;
 
    } else {
      notes[ notes.length ] = sel[ j ];
    }
  }
}
 
      var fdfl  = 0;                     // number of FDFL picked?
      var hdfl  = 0;					 // number of HDFL picked
	  var hahf  = 0;					 // number of HAHF picked
	  var hshf  = 0;                     // number of HSHF picked
      for ( var i = 0; i < notes.length; i++ ) {
        var x   = notes[ i ].selectedIndex;
        var val = notes[ i ].options[ x ].innerHTML;
        if ( val == 'FDFL' ) fdfl++;
        if ( val == 'HDFL' ) hdfl++;
		if ( val == 'HAHF' ) hahf++;
		if ( val == 'HSHF' ) hshf++;
      }
//    alert( 'FDFL = ' + fdfl + '\nHDFL = ' + hdfl + '\nthis = ' + noteVal + '\nid = "' + id + '"' );
      //--------------------------------------------------------------
      // Now that we've determined how many Flexi Leave selects have
      // been made, we process the "notes" selection lists to
      // enable/disable the Flexi Leave selections as appropriate.
      // Note: In a perfect world, an "option" disabled attribute
      //       could be set to true/false, and everything would work
      //       fine.  Unfortunately, FireFox, and IE act very
      //       differently when it comes to "disabled" options.
      //       FireFox - doesn't care what the value is, the presence
      //                 of the disabled attribute makes the option
      //                 unselectable.  So, in order to "enable" the
      //                 option, we need to use removeAttribute()
      //       IE      - doesn't care if the attribute is present or
      //                 not.  So, we have to check when an option is
      //                 selected to see if the attribute is present.
      //--------------------------------------------------------------
      for ( var i = 0; i < notes.length; i++ ) {
        for ( var j = 0; j < notes[ i ].options.length; j++ ) {
          var val = notes[ i ].options[ j ].innerHTML;
          //----------------------------------------------------------
          // FDFL - disable if any (other) FDFL have been selected, or
          //        if any HDFL have been selected.
          //----------------------------------------------------------
//        var set = ( notes[ i ].id != id ) && ( ( fdfl > 0 ) || ( hdfl > 0 ) );
          var set = ( fdfl > 0 ) || ( hdfl > 0 ) || (hahf > 0) || (hshf > 0);
          if ( val == 'FDFL' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
		  
		  set = ( fdfl > 0 ) || ( hdfl > 1) || (hshf > 1) || (hahf > 1);
          if ( val == 'HAHF' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
		  
		  set = ( fdfl > 0 ) || ( hdfl > 1) || (hahf > 1) || (hshf > 1);
          if ( val == 'HSHF' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
          //----------------------------------------------------------
          // HDFL - disable if any FDFL have been selected, or if move
          //        than 1 other HDFL have been selected
          //----------------------------------------------------------
//        set = ( notes[ i ].id != id ) && ( ( fdfl > 0 ) || ( hdfl > 1 ) );
          set = ( fdfl > 0 ) || (hahf > 1) || ( hshf > 1) || ( hdfl > 1);
          if ( val == 'HDFL' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
        }
      }
    }
    
    compute( idSuffix );               // Process daily values
    calc( 'hrWorked', 'credit', 'debit', week );
    //----------------------------------------------------------------
    // Compute, and update the cumulative flexi hours value,
    // processing include potential carryover from previous month...
    //----------------------------------------------------------------
    var cum   = field( 'cumulative' );
    var carry = field( 'CarriedFlexi' );
    if ( cum ) {
      var total = 0;
      if ( carry && carry.value != '' ) {
        total = HtoM( carry.value );
      }
      for ( var w = 0; w < 4; w++ ) {
        var wFlexi = field( 'credit' + w );
        if ( wFlexi && wFlexi.value != '' ) {
          total += HtoM( wFlexi.value );
        }
        var debit  = field( 'debit'  + w );
        if ( debit && debit.value != '' ) {
          total += HtoM( debit.value );
        }
      }
      cum.value = MtoH( total );
    }
  }
  
  //------------------------------------------------------------------
  // Name: checkIt()
  // Role: Verify that user input is a "valid" time.
  // Note: It is expected that this will normally be invoked using
  //       a call like the following, where 0 is the week # 0..3:
  //       for example: onchange='checkIt(this,0);'
  //------------------------------------------------------------------
  function checkIt( obj, week ) {
    var val = obj.value;          // Current field value
    //----------------------------------------------------------------
    // Was a valid value provided?
    //----------------------------------------------------------------
    if ( val.search( /^[-+]?(\d{0,3}):?(\d\d)$/ ) < 0 ) {
      if ( val != '' ) {
        alert( 'Please enter a numeric value of the form: HH:MM' );
        obj.value = '';
      }
    } else {
      //--------------------------------------------------------------
      // Process a valid value, don't include the sign in the output
      //--------------------------------------------------------------
      obj.value = MtoH( HtoM( val ) ).substr( 1 );
    }
    var id = obj.id;                        // id attribute for element
    var ix = id.substr( id.length - 2 );    // Trailing 2 digits
    adjust( null, ix, week );
  }
 
  //------------------------------------------------------------------
  // Information used to populate the date related DOM elements based
  // upon the week number (0..3).
  //------------------------------------------------------------------
  var info = new Array( 4 );
  info[ 0 ] = { names  : 'txtDate2,txtDate3,txtDate4,txtDate5'.split( ',' ),
                hidden : 'Date2,Date3,Date4,Date5'.split( ',' ),
                extId  : 'txtDate1',
                intId  : 'Date1'
              };
 
  info[ 1 ] = { names  : 'txtDate7,txtDate8,txtDate9,txtDate10'.split( ',' ),
                hidden : 'Date2b,Date3b,Date4b,Date5b'.split( ',' ),
                extId  : 'txtDate6',
                intId  : 'Date1b'
              };
 
  info[ 2 ] = { names  : 'txtDate12,txtDate13,txtDate14,txtDate15'.split( ',' ),
                hidden : 'Date2c,Date3c,Date4c,Date5c'.split( ',' ),
                extId  : 'txtDate11',
                intId  : 'Date1c'
              };
 
  info[ 3 ] = { names  : 'txtDate17,txtDate18,txtDate19,txtDate20'.split( ',' ),
                hidden : 'Date2d,Date3d,Date4d,Date5d'.split( ',' ),
                extId  : 'txtDate16',
                intId  : 'Date1d'
              };
 
  //------------------------------------------------------------------
  // Name: fillDates
  // Role: Generate a sequence of valid dates, in a specific format
  //------------------------------------------------------------------
  function fillDates( week ) {
    var extId = info[ week ].extId;
    
    var val = field( extId ).value;
    if ( val != '' ) {
      var dat = val.split( '/' );
      var names  = info[ week ].names;
      var hidden = info[ week ].hidden;
      var intId  = info[ week ].intId;
 
      //--------------------------------------------------------------
      // Extract the user specified date fields
      //--------------------------------------------------------------
      var y0  = Number( dat[ 2 ] );
      var m0  = Number( dat[ 1 ] ) - 1;
      var d0  = Number( dat[ 0 ] );
 
      //--------------------------------------------------------------
      // Use this information to generate a "valid" date
      //--------------------------------------------------------------
      var D1  = new Date( y0, m0, d0 );
      var y1  = D1.getFullYear();
      var m1  = twoD( D1.getMonth() + 1 );
      var d1  = twoD( D1.getDate() );
 
      //--------------------------------------------------------------
      // Save this valid date to the field from which it was retrieved
      // (i.e., the external field) as well as the associated "hidden"
      // (internal) field.
      //--------------------------------------------------------------
      field( extId ).value = d1 + '/' + m1 + '/' + y1;
      field( intId ).value = y1 + '/' + m1 + '/' + d1;
 
      //--------------------------------------------------------------
      // Using the valid date, generate the subsequent 4 dates
      //--------------------------------------------------------------
      for ( var i = 0; i < 4; i++ ) {
        var D2 = new Date( y0, m0, d0 + i + 1 );
        var d2 = twoD( D2.getDate() );
        var m2 = twoD( D2.getMonth() + 1 );
        var y2 = D2.getFullYear();
 
        field( names[ i ] ).value = d2 + '/' + m2 + '/' + y2;
        field( hidden[ i ] ).value = y2 + '/' + m2 + '/' + d2;
      }
    }
  }
 
  //------------------------------------------------------------------
  // Name: header()
  // Role: Generate the header for the specified week
  //------------------------------------------------------------------
  function header( weekNum ) {
    return '<h1>Week <span class="headingLightBlue">' + weekNum + '</span></h1>';
  }
 
  //------------------------------------------------------------------
  // Name: toggle()
  // Role: Display the appropriate week DIV
  //------------------------------------------------------------------
  function toggle( weekNum ) {
    //----------------------------------------------------------------
    // Is the selected week "hidden"?
    //----------------------------------------------------------------
    if ( field( 'Week' + weekNum ).style.display == 'none' ) {
      for ( var w = 1; w < 5; w++ ) {
        field( 'Week' + w ).style.display = ( ( w == weekNum ) ? 'block' : 'none' );
      }
    }
    field( 'commentHeader' ).innerHTML = header( weekNum );
  }
 
  //------------------------------------------------------------------
  // Name: Style()
  // Role: set the style details for the specified weekNum (1..4)
  //------------------------------------------------------------------
  function Style( weekNum ) {
    
    //----------------------------------------------------------------
    // Get references to the portions of the document for all weeks
    //----------------------------------------------------------------
    var table = field( 'Week' + weekNum );
    var week = new Array( 4 );
    for ( var w = 1; w < 5; w++ ) {
      week[ w ] = field( 'wk' + w );
    }
    
    //----------------------------------------------------------------
    // Set the table style details
    //----------------------------------------------------------------
    table.style.borderColor = '#00CCFF';
    table.style.borderWidth = '2px';
    
    //----------------------------------------------------------------
    // Set the week style details for each week, with the selected
    // week (i.e., weekNum) differentiated.
    //----------------------------------------------------------------
    for ( w = 1; w < 5; w++ ) {
      if ( w == weekNum ) {
        week[ w ].style.backgroundColor = '#00CCFF';
        week[ w ].style.color = '#ffffff';
      } else {
        week[ w ].style.backgroundColor = '#efefef';
        week[ w ].style.color = '#999999';
      }
    }
  }
 
  function show(){
    sectionHelp.style.display = ( sectionHelp.style.display == 'none' ) ? '' : 'none';
  }
</script>

Open in new window

Thanks for the code.  Now, can you describe the scenario of what the page
does that it isn't supposed to do, and what it doesn't do that it is supposed
to?
Avatar of SEUPB

ASKER

Hi HonorGod,

Ok so basically what I want the code to do is acknowledge the additional half day flexi flags into the logic i.e. HAHF, HSHF. The original coding you coded for me only worked with FDFL and HDFL where you only allowed to take one HDFL or 2 HDFL. With the two new flags I will need the system to be able to detect that they have been selected and still only allow a combination of 2 half day flexi flags within a 4 week period. The combinations could be,

1x HDFl + 1x HDFL
1x HDFl + 1x HAHF
1x HDFL + 1x HSHF

1x HAHF + 1x HAHF
1x HAHF + 1x HDFL
1x HAHF + 1x HSHF

1x HSHF + 1x HSHF
1x HSHF + 1x HDFL
1x HSHF + 1x HAHF

At the moment the system seems to recognise when I have selected two identical flags, but fails to detect when I select 2 different flags. Once these flags are selected it seems to override the logic and allow me to continue selecting half day flexi days.
 Wait a minute!  The way you worded that makes it sound like I imposed those
restrictions on you, instead of the other way around.  :-D

  You were the one who provided the design specifications.  :-)

  ok, I hope to be able to take a look at it later today.
Avatar of SEUPB

ASKER

Hey HonorGod,

No no heh I didn't mean to impose anything on you!! Yeah the original restrictions you coded for me worked fantastically. I just couldn't modify it to acknowledge the additional half day flexi flags.

Another question possibly need to start up a new question after this as it is probably worth 500pts on its own but it could be tied into the current problem as well. Em currently there have been times were we have allowed people to take more than one full day flexi leave, this was achieved by simply manually changing the details on the database. Is there anyway that it could be coded to detect once a 2nd full day flexi leave is selected that it prompts the user for a pin code perhaps? And if the person keys in an invalid pin code it alerts "selection not available" as normal or if the person cancels it etc.

That possible?
Avatar of SEUPB

ASKER

Hi HonorGod,

Any luck with the coding?
Avatar of SEUPB

ASKER

Hi HonorGod,

Hope you are keeping well. Just checking to see if you've had any luck yet?

Thanks,

Michael
Oh my goodness.  I completely forgot about this question!  Please forgive me.

Between family health issues, and trying to complete the milestones related to
the book that I'm writing, I got completely distracted, and forgot you.

I am so sorry.

Let me review this, and get back to you today.  ... again, please forgive me.
Avatar of SEUPB

ASKER

Hi Mate,

No worries, sorry to hear about the family health issues. Hope everything is well with you and your family. No problem mate, we all get easily distracted these days. No rush, take your time.

Hear from you soon.

There's no need to forgive you, you did nothing wrong!! I'm just grateful you can help. Seriously, take your time the coding i'm using at the moment still functions like beforehand except something minor issues related to this question. So anytime this week or next is fine!

Regards,

Michael
Michael:

  Can you give me some values that I can use to test what it is you want to do, and what you see when you enter them?

Thanks
Bob
Avatar of SEUPB

ASKER

Hi Bob,

Basically I want to implement some additional flags onto the system, which will also work inline with the 1 full flexi day rule or 2 half flexi days. Below is the combination that should be allowed,

1x HDFL + 1x HDFL
1x HDFL + 1x HAHF
1x HDFL + 1x HSHF

or

1x HAHF + 1x HAHF
1x HAHF + 1x HDFL
1x HAHF + 1x HSHF

or

1x HSHF + 1x HSHF
1x HSHF + 1x HDFL
1x HSHF + 1x HAHF

That's the main part I'm trying to get sorted. I was toying with the idea of having a pin code authorisation if the employee wants to override the 1 full flexi day rule. By entering the pin code the employee will be able to select another 1 full flexi day. Is that possible?

Thanks,

Michael
HDFL == Half Day Flexi Leave?
HAHF == ?
HSHF == ?

"almost anything" is possible... if you can describe it in unambiguous detail.
HSHA = Half Day Special / Half Day Annual
HAHF = Half Day Annual / Half Day Flexi

looking.
Avatar of SEUPB

ASKER

Hi Bob,

HAHF = Half Day Annual / Half Day Flexi
HSHF = Half Day Special / Half Day Flexi.

Hope this helps.

Thanks,

Michael
Michael:

  The code that I have doesn't seem to work as I expect.  Perhaps I'm missing something.
Here are the order of things that I do.

1. Click "Select from date"
2. Select some Monday, thus populating the first "day of week" slot
3. Tab, thus changing focus to the next input field, which populates the rest of the date fields.

  So far, so good.

4. Then, I put in a "start time" 800, and press Tab
    Focus in now on the "Finish Time" field, and the "Flexi Credit Daily" field is initialized as "+00:00"
5. Entering 1600 in the "Finish Time" field, and pressing Tab fills in the rest of the fields for that day...
    Total hours for day = 08:00
    Lunch break         = 00:30
    Hours worked        = 07:30
    Flexi credit        = 00:05
    Flexi debit         = 00:00

  I "think" that this is right.  Is it?

  At this point, I thought that I was supposed to be able to select a Note value to indicate that I
was taking this as a vacation (annual leave = AL), or flexi-leave (FL), or special leave (SL).

  Is that right?

  Are the values supposed to change at this point?  I don't remember.  Sorry...
Avatar of SEUPB

ASKER

hi Bob,

No problem. Em yes the time calculations is correct. You would usually select the Note value first as most of the Notes contain a set values, only a serveral of them require you to enter in values.

I think the coding did allow the person to change his or her mind, in sense that if values were entered in and they decide to select a Note value that the values relating to that Note with be enforced. I can't rememeber if this was fully working or not from last time.

Thanks,

Michael
Michael:

  So, can you be more specific about what it is you would like it to do?

Thanks
Bob
Avatar of SEUPB

ASKER

Hi Bob,

I basically want to update the current logic to allow the combination of two half day flexi notes from the below list,

1x HDFL + 1x HDFL
1x HDFL + 1x HAHF
1x HDFL + 1x HSHF

or

1x HAHF + 1x HAHF
1x HAHF + 1x HDFL
1x HAHF + 1x HSHF

or

1x HSHF + 1x HSHF
1x HSHF + 1x HDFL
1x HSHF + 1x HAHF

If it's possible (maybe as a new question) allow for some sort of pass code logic, that would kick in when the person wants to enter in two full day flexi days or more.

Hope this makes sense.

Michael
Avatar of SEUPB

ASKER

Sorry there are a total of 9 combinations.... of having two half day flexi notes. So once the person tries to select another half day flexi note it should stop them.

Thanks,

Michael
I'm traveling today, and won't have a chance to look at it until tomorrow.  Sorry
Avatar of SEUPB

ASKER

Hi Bob,

That's not a problem. I'm pretty busy with other stuff as well and plus the system still works with the changes I made.

No worries,

Michael
Avatar of SEUPB

ASKER

Hi Bob,

Hope you are keeping well. Just checking to see if you had any luck with the coding?

Thanks,

Michael
Michael:

  Thanks for the thought.  Unfortunately, life has been intruding into my fun... (sigh).
Anyway, I have another question for you.

Q: When do you want the note selection to be made?
     Before, or after times have been filled in?

If you are available, I'd like to try to get this done today.  It has been hanging on for far too long.  Please forgive me.
The reason for the question about when the note should be selected is due to the following:

Say someone needs to select one of the notes (e.g., HAHF). From this, we know that
the entire day was taken off.  So, does it make sense to require the times to be filled in for this situation?
One of the things that I was considering was to have a routine called when any note selection occurred.  This would allow the number of each type (AL, FL, SL, HAHF, HDFL, and HSHF) to be counted.

Does that make sense?
The more that I work with the code that I have, the more I think that my code is out of date.  Are these the "proper" Note codes?

AL, FL, SL, HAHF, HDFL, and HSHF
Avatar of SEUPB

ASKER

Hi Bob,

No worries. Yes your question makes sense. Sorry for the late reply, I was on a half day yesterday. In my opinion I believe the notes should be selected first if any sort of HDAL or HDFL is needed. In only makes sense to select them first. Your question regarding HAHF note, if some selects this note, the fields required are automatically filled in. All fields will be filled in with 00:00 except for hrs worked which will have 03:45 and debit flexi will have -03:45. Hope that makes sense.

The codes you and I used before has been updated and modified by myself. Below are the new set of codes,

STAT - Statutory Leave
FDAL - Full Day Annual Leave
HDAL - Half Day Annual Leave
FDFL - Full Day Flexi Leave
HDFL - Half Day Flexi Leave
HAHF - Half Day Annual Leave + Half Day Flexi Leave
HSHA - Half Day Special Leave + Half Day Annual Leave
HSHF - Half Day Special Leave + Half Day Flexi Leave
FDSP - Full Day Special Leave
HDSP - Half Day Special Leave
FDSL - Full Day Sick Leave
HDSL - Half Day Sick Leave

I'm the above set of codes will be the final codes and will not be changed again.

Yeah if we can get it sorted today it would be great, if not its not the end of the word heh.

Thanks,

Michael

"... it's the end of the word as we know it..."  Hm. maybe that's supposed to be "world"... :-)

Thanks for the list.  Apparently, the code with which I have been working is out of date.

Thanks also for the "complete" list (du jour).

ok, if "HAHF" is selected then the other fields can be filled in as shown previously.
What about the other selections?

What is "Statutory Leave"?
Avatar of SEUPB

ASKER

Hi Bob,

Heh yup that should have been "world".

Statutory Leave is basically for Bank Holidays, The logic is the same as a full day annual leave.

I've included below a list and whether or they need fields filled in or not.

STAT - Statutory Leave - Fields Automatically Filled In.
FDAL - Full Day Annual Leave - Fields Automatically Filled In.
HDAL - Half Day Annual Leave - Lunch Break, Hrs Worked is Automatically filled in.
FDFL - Full Day Flexi Leave - Fields Automatically Filled In.
HDFL - Half Day Flexi Leave - Lunch Break, Hrs Worked is Automatically filled in.
HAHF - Half Day Annual Leave + Half Day Flexi Leave - Fields Automatically Filled In.
HSHA - Half Day Special Leave + Half Day Annual Leave - Fields Automatically Filled In.
HSHF - Half Day Special Leave + Half Day Flexi Leave - Fields Automatically Filled In.
FDSP - Full Day Special Leave - Fields Automatically Filled In.
HDSP - Half Day Special Leave - Lunch Break, Hrs Worked is Automatically filled in.
FDSL - Full Day Sick Leave - Fields Automatically Filled In.
HDSL - Half Day Sick Leave - Fields Automatically Filled In.

Hope the list helps.
Mike:

  Yes, it does help, but unfortunately, it is incomplete.  What values should be used to fill in the fields?

Thanks
Bob
Avatar of SEUPB

ASKER

Hi Bob,

I thought u would ask me heh. If I showed the current code would that be enough info?

As it pretty much has the automatic field values coded for each note. These were originally coded by you and I later made the changes.

If not I will do up a more in depth summary.

Thanks,

Michael
switch ( noteVal ) {
              //--------------------------------------------------------
              // Stat Leave
              //--------------------------------------------------------
              case 'STAT' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
				worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
                debit.value  = '-00:00';
                break;
              //--------------------------------------------------------
              // Full Day Annual Leave
              //-------------------------------------------------------- 
              case 'FDAL' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
              //--------------------------------------------------------
              // Half Day Annual Leave - with Flexi Band Restrictions
              //--------------------------------------------------------
              case 'HDAL' :
                debit.value = credit.value = '-00:00';
                //------------------------------------------------------
                // Are they working in the morning, or in the afternoon?
                //------------------------------------------------------
                if ( startT < HtoM( '12:00' ) ) {
                  var msg = '';
                  //----------------------------------------------------
                  // Afternoon off.  Check the starting & ending time...
                  //----------------------------------------------------
                  if ( ( startT < HtoM( '08:00' ) ) || ( stopT < HtoM( '12:00' ) ) || ( stopT > HtoM( '14:00' ) ) ) {
                    if ( startT < HtoM( '08:00' ) ) {
                      start.value = '08:00';
                      startT = HtoM( '08:00' );
                      msg = 'Changing start time to 08:00';
                    }
                    if ( stopT < HtoM( '12:00' ) ) {
                      stop.value = '12:00';
                      stopT = HtoM( '12:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 12:00';
                      } else {
                        msg += ', and stop time to 12:00';
                      }
                    }
                    if ( stopT > HtoM( '14:00' ) ) {
                      stop.value = '14:00';
                      stopT = HtoM( '14:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 14:00';
                      } else {
                        msg += ', and stop time to 14:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                } else {
                  //----------------------------------------------------
                  // Morning off.  Check the starting & ending time...
                  //----------------------------------------------------
                  msg = '';
                  if ( ( startT > HtoM( '14:00' ) ) || ( stopT > HtoM( '18:00' ) ) ) {
                    if ( startT > HtoM( '14:00' ) ) {
                      start.value = '14:00';
                      startT = HtoM( '14:00' );
                      msg = 'Changing start time to 14:00';
                    }
                    if ( stopT > HtoM( '18:00' ) ) {
                      stop.value = '18:00';
                      stopT = HtoM( '18:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 18:00';
                      } else {
                        msg += ', and stop time to 18:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                }
                
                if ( minutes < hday ) {
                  if ( ( startT == stopT ) && ( startT == 0 ) ) {
                    start.value = stop.value = atWrk.value = worked.value = brk.value = debit.value = '';
                  } else {
                    debit.value = MtoH( minutes + hday - wday );
                  }
                } else {
                  credit.value = MtoH( minutes + hday - wday );
                }
                worked.value = MtoH( minutes + hday ).substr( 1 );
                break;              
              //--------------------------------------------------------
              // Full Day Flexi Leave
              //--------------------------------------------------------
              case 'FDFL' :
                alert( 'Specified start and/or stop times ignored, and reset.' );
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = '00:00';
 
                credit.value = MtoH( minutes - brkT );
                debit.value  = MtoH( -wday );
                break;
              //--------------------------------------------------------
              // Half Day Flexi Leave - with Flexi Band Restrictions
              //--------------------------------------------------------
              case 'HDFL' :
                credit.value = '+00:00';
                //------------------------------------------------------
                // Are they working in the morning, or in the afternoon?
                //------------------------------------------------------
                if ( startT < HtoM( '12:00' ) ) {
                  var msg = '';
                  //----------------------------------------------------
                  // Afternoon off.  Check the starting & ending time...
                  //----------------------------------------------------
                  if ( ( startT < HtoM( '08:00' ) ) || ( stopT < HtoM( '12:00' ) ) || ( stopT > HtoM( '14:00' ) ) ) {
                    if ( startT < HtoM( '08:00' ) ) {
                      start.value = '08:00';
                      startT = HtoM( '08:00' );
                      msg = 'Changing start time to 08:00';
                    }
                    if ( stopT < HtoM( '12:00' ) ) {
                      stop.value = '12:00';
                      stopT = HtoM( '12:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 12:00';
                      } else {
                        msg += ', and stop time to 12:00';
                      }
                    }
                    if ( stopT > HtoM( '14:00' ) ) {
                      stop.value = '14:00';
                      stopT = HtoM( '14:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 14:00';
                      } else {
                        msg += ', and stop time to 14:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                } else {
                  //----------------------------------------------------
                  // Morning off.  Check the starting & ending time...
                  //----------------------------------------------------
                  msg = '';
                  if ( ( startT > HtoM( '14:00' ) ) || ( stopT > HtoM( '18:00' ) ) ) {
                    if ( startT > HtoM( '14:00' ) ) {
                      start.value = '14:00';
                      startT = HtoM( '14:00' );
                      msg = 'Changing start time to 14:00';
                    }
                    if ( stopT > HtoM( '18:00' ) ) {
                      stop.value = '18:00';
                      stopT = HtoM( '18:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 18:00';
                      } else {
                        msg += ', and stop time to 18:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                }
                if ( minutes < hday ) {
                  if ( ( startT == stopT ) && ( startT == 0 ) ) {
                    start.value = stop.value = atWrk.value = worked.value = brk.value = debit.value = '';
                  } else {
                    debit.value  = MtoH( minutes - wday );
                  }
                }
                worked.value = MtoH( minutes ).substr( 1 );
                debit.value  = MtoH( minutes - wday );
                break;
			  //--------------------------------------------------------
              // Half Day Flexi / Half Day Annual
              //--------------------------------------------------------	
			  case 'HAHF' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( hday ).substr( 1 );
                credit.value = '+00:00';
                debit.value  = MtoH( -hday );
                break;
				
			  //--------------------------------------------------------
              // Half Day Special / Half Day Annual
              //--------------------------------------------------------	
			  case 'HSHA' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
				
			  //--------------------------------------------------------
              // Half Day Special / Half Day Flexi
              //--------------------------------------------------------	
			  case 'HSHF' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( hday ).substr( 1 );
                credit.value = '+00:00';
                debit.value  = MtoH( -hday );
                break;
			  //--------------------------------------------------------
              // Full Day Sick Leave
              //--------------------------------------------------------	
			  case 'FDSL' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
              //--------------------------------------------------------
              // Half Day Sick Leave
              //--------------------------------------------------------
			  case 'HDSL' :
                worked.value = MtoH( wday ).substr( 1 );
				brk.value = '00:00';
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
				break;
			  //--------------------------------------------------------
			  // Special Leave
			  //--------------------------------------------------------
			  case 'FDSP' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
			  //--------------------------------------------------------
              // Half Day Special Leave - with Flexi Band Restrictions
              //--------------------------------------------------------
              case 'HDSP' :
			  	credit.value = '+00:00';
                debit.value = '-00:00';
                //------------------------------------------------------
                // Are they working in the morning, or in the afternoon?
                //------------------------------------------------------
                if ( startT < HtoM( '12:00' ) ) {
                  var msg = '';
                  //----------------------------------------------------
                  // Afternoon off.  Check the starting & ending time...
                  //----------------------------------------------------
                  if ( ( startT < HtoM( '08:00' ) ) || ( stopT < HtoM( '12:00' ) ) || ( stopT > HtoM( '14:00' ) ) ) {
                    if ( startT < HtoM( '08:00' ) ) {
                      start.value = '08:00';
                      startT = HtoM( '08:00' );
                      msg = 'Changing start time to 08:00';
                    }
                    if ( stopT < HtoM( '12:00' ) ) {
                      stop.value = '12:00';
                      stopT = HtoM( '12:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 12:00';
                      } else {
                        msg += ', and stop time to 12:00';
                      }
                    }
                    if ( stopT > HtoM( '14:00' ) ) {
                      stop.value = '14:00';
                      stopT = HtoM( '14:00' );
 
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 14:00';
                      } else {
                        msg += ', and stop time to 14:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                } else {
                  //----------------------------------------------------
                  // Morning off.  Check the starting & ending time...
                  //----------------------------------------------------
                  msg = '';
                  if ( ( startT > HtoM( '14:00' ) ) || ( stopT > HtoM( '18:00' ) ) ) {
                    if ( startT > HtoM( '14:00' ) ) {
                      start.value = '14:00';
                      startT = HtoM( '14:00' );
                      msg = 'Changing start time to 14:00';
                    }
                    if ( stopT > HtoM( '18:00' ) ) {
                      stop.value = '18:00';
                      stopT = HtoM( '18:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 18:00';
                      } else {
                        msg += ', and stop time to 18:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                }
                
                if ( minutes < hday ) {
                  if ( ( startT == stopT ) && ( startT == 0 ) ) {
                    start.value = stop.value = atWrk.value = worked.value = brk.value = debit.value = '';
                  } else {
                    debit.value = MtoH( minutes + hday - wday );
                  }
                } else {
                  credit.value = MtoH( minutes + hday - wday );
                }
                worked.value = MtoH( minutes + hday ).substr( 1 );
                break;
              //--------------------------------------------------------
              // Unspecified / Undefined
              //--------------------------------------------------------
              case '--' :
                if ( credit.value != '+00:00' ) credit.value = '+00:00';
                debit.value = ( minutes && brkT ) ? MtoH( minutes - brkT - wday ) : '';
                break;
              //--------------------------------------------------------
              // Unexpected!
              //--------------------------------------------------------
              default:
                alert( 'Unexpected note value: "' + noteVal + '"' );
            }
          } else {
            //----------------------------------------------------------
            // ( minutes - brkT >= wday ) ...
            //----------------------------------------------------------
            if ( noteVal.substr( 0, 2 ) == 'HD' ) {
              alert( 'Too many hours worked for specified note selection: ' + noteVal );
              note.selectedIndex = 0;
              adjust( document.getElementById( 'note' + idSuffix ), idSuffix, idSuffix.substr( 0, 1 ) );
            }
            debit.value  = '-' + MtoH( 0 ).substr( 1 );
            credit.value = MtoH( minutes - brkT - wday );
          }
        }
    //}
    } else {
      switch ( noteVal ) {
        //--------------------------------------------------------
        // Stat Leave
        //--------------------------------------------------------
        case 'STAT' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
		  worked.value = MtoH( wday ).substr( 1 );
          credit.value  = '+00:00';
          debit.value  = '-00:00';
          break;
        //------------------------------------------------------------
        // Full Day Annual Leave
        //------------------------------------------------------------
        case 'FDAL' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = MtoH( wday ).substr( 1 );
          credit.value  = '+00:00';
          debit.value  = '-00:00';
          break;
        //------------------------------------------------------------
        // Half Day Annual Leave
        //------------------------------------------------------------
        case 'HDAL' :
          credit.value = debit.value = '+00:00';
          worked.value = MtoH( hday ).substr( 1 );
          break;
        //------------------------------------------------------------
        // Full Day Flexi Leave
        //------------------------------------------------------------
        case 'FDFL' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = credit.value = '00:00';
          debit.value  = MtoH( -wday );
          break;
        //------------------------------------------------------------
        // Half Day Flexi Leave
        //------------------------------------------------------------
        case 'HDFL' :
          credit.value = '+00:00';
          debit.value  = '-00:00';
//        start.value  = stop.value = atWrk.value = worked.value = brk.value = credit.value = '';
          break;
		  
		//--------------------------------------------------------
        // Half Day Flexi / Half Day Annual
        //--------------------------------------------------------	
		case 'HAHF' :
           start.value  = stop.value = atWrk.value = brk.value = '00:00';
           worked.value = MtoH( hday ).substr( 1 );
           credit.value = '+00:00';
           debit.value  = MtoH( -hday );
           break;
				
		//--------------------------------------------------------
        // Half Day Special / Half Day Annual
        //--------------------------------------------------------	
		case 'HSHA' :
           start.value  = stop.value = atWrk.value = brk.value = '00:00';
           worked.value = MtoH( wday ).substr( 1 );
           credit.value  = '+00:00';
           debit.value  = '-00:00';
           break;
				
		//--------------------------------------------------------
        // Half Day Special / Half Day Flexi
        //--------------------------------------------------------	
		case 'HSHF' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = MtoH( hday ).substr( 1 );
          credit.value = '+00:00';
          debit.value  = MtoH( -hday );
          break;
        //------------------------------------------------------------
        // Full Day Sick Leave
        //------------------------------------------------------------
        case 'FDSL' :
		  worked.value = MtoH( wday ).substr( 1 );
		  start.value  = stop.value = atWrk.value = brk.value = '00:00';		
		  credit.value = '+00:00';
          debit.value  = '-00:00';
          
          break;
		//------------------------------------------------------------
        // Half Day Sick Leave
        //------------------------------------------------------------
		case 'HDSL' :
		  worked.value = MtoH( wday ).substr( 1 );
          credit.value = '+00:00';
		  debit.value = '-00:00';
		  brk.value = '00:00';
          break;
		//------------------------------------------------------------
        // Full Day Special Leave
        //------------------------------------------------------------
        case 'FDSP' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = MtoH( wday ).substr( 1 );
          credit.value  = '+00:00';
          debit.value  = '-00:00';
          break;
		//------------------------------------------------------------
        // Half Day Special Leave
        //------------------------------------------------------------
        case 'HDSP' :
          credit.value = '+00:00';
		  debit.value = '-00:00';
          worked.value = MtoH( hday ).substr( 1 );
          break;
        //------------------------------------------------------------
        // Unspecified / Undefined
        //------------------------------------------------------------
        case '--' :
          if ( credit.value != '+00:00' ) credit.value = '+00:00';
          debit.value = ( minutes && brkT ) ? MtoH( minutes - brkT - wday ) : '';
          break;
        //------------------------------------------------------------
        // Unexpected!
        //------------------------------------------------------------
        default:
          alert( 'Unexpected note value: "' + noteVal + '"' ) 
      }
    }
  }

Open in new window

Nope, that's good...  Let me see what I can do with it...  Thanks
Avatar of SEUPB

ASKER

That's great.

If you require the full coding you did awhile back I have included it below.

Many Thanks again.
<script type='text/javascript'>
  //------------------------------------------------------------------
  // Name: twoD()
  // Role: convert single digit (numeric) values to 2 digits by
  //       prepending a leading zero (if appropriate)
  //------------------------------------------------------------------
  function twoD( val ) {
    if ( ( ( typeof( val ) == 'number' ) && ( val < 10 ) ) || ( val.length < 2 ) ) {
      val = '0' + val;
    }
    return val;
  }
 
  //------------------------------------------------------------------
  // Name: HtoM()
  // Role: convert a time (HH:MM) to minutes
  //  Fix: Change to handle hours > 99, as well as negative values...
  //------------------------------------------------------------------
  function HtoM( val ) {
    var result = 0;
    //----------------------------------------------------------------
    // Use a Regular Expression to see if the specified value is in
    // the proper format, i.e., optional +/- sign, 0 to 3 digits,
    // optional ':', and required 2 digits.
    //----------------------------------------------------------------
    if ( val.search( /^([-+])?(\d{0,3}):?(\d\d)$/ ) == 0 ) {
      //--------------------------------------------------------------
      // A pattern match will update the global RegExp object so that
      // $1 == sign, $2 == Hours, and $3 == Minutes
      //--------------------------------------------------------------
      var s = RegExp.$1, h = RegExp.$2, m = RegExp.$3;
      //--------------------------------------------------------------
      // Note: parseInt() of a value having leading zeros will be
      //       interpreted/parsed an an octal value, unless we specify
      //       the radix (i.e., the numeral system to be used).
      //--------------------------------------------------------------
      result = ( parseInt( h, 10 ) * 60 + parseInt( m, 10 ) ) * ( ( s == '-' ) ? -1 : 1 );
    }
    return result;
  }
 
  //------------------------------------------------------------------
  // Name: MtoH()
  // Role: Format the specified value (minutes) into +HH:MM
  //------------------------------------------------------------------
  function MtoH( val ) {
    var result, prefix = '+';
    if ( val < 0 ) {
      prefix = '-';
      val = -val;
    }
    var min = ( val % 60 );
    var hrs = ( val - min ) / 60;
    return prefix + twoD( hrs ) + ':' + twoD( min );
  }
 
  //------------------------------------------------------------------
  // Name: field()
  // Role: verify that a DOM element with the specified id exists.
  //------------------------------------------------------------------
  function field( id ) {
    var item = document.getElementById( id );
    if ( !item ) {
      alert( 'Specified field not found: ' + id );
    }
    return item;
  }
 
  //------------------------------------------------------------------
  // Name: compute()
  // Role: Use the available values for a specific day to compute the
  //       hours worked, and flexi hours credited or debited.
  //------------------------------------------------------------------
  function compute( idSuffix ) {
    if ( typeof( idSuffix ) == 'number' ) {
      idSuffix += '';                  // Convert to a string
      if ( idSuffix.length < 2 ) {     // And guarantee string length
        idSuffix = '0' + idSuffix;
      }
    }
    var start  = field( 'startTime'  + idSuffix );
    var stop   = field( 'finishTime' + idSuffix );
    var brk    = field( 'lunch'      + idSuffix );
    var debit  = field( 'debit'      + idSuffix );
    var atWrk  = field( 'totalHr'    + idSuffix );
    var worked = field( 'hrWorked'   + idSuffix );
    var credit = field( 'credit'     + idSuffix );
    var note   = field( 'note'       + idSuffix );
    //----------------------------------------------------------------
    // Unfortunately, we have to use this idiom to make sure to obtain
    // the actual note.value (thanks to IE)... :-(
    //----------------------------------------------------------------
    var noteVal = note.value || note.options[ note.selectedIndex ].innerHTML;
 
    //----------------------------------------------------------------
    // The number of minutes in a standard workday is based upon the
    // day of the week.  For Mon..Thu (i.e., day# 1..4), there are
    // 445 minutes, on Fri, (i.e., day# 5) we only work 440.
    // Note: A half-day is 3:45 - regardless of the day of the week.
    //----------------------------------------------------------------
    var wday = ( idSuffix.substr( 1 ) < '5' ) ? 445 : 440;
    var hday = ( idSuffix.substr( 1 ) < '5' ) ? 225 : 220;
 
    //----------------------------------------------------------------
    // Given non-blank start & stop times, try to compute the rest...
    //----------------------------------------------------------------
    if ( ( start.value != '' ) && ( stop.value != '' )  ) {
      //--------------------------------------------------------------
      // Retrieve the day values (and convert each to minutes)
      //--------------------------------------------------------------
      var startT = HtoM( start.value );     // Start Time (minutes)
      var stopT  = HtoM( stop.value );      // Stop  Time (minutes)
      var brkT   = HtoM( brk.value );       // Break Time (minutes)
	  var workT  = HtoM( worked.value );    // Work Time  (minutes)
      var debitT = HtoM( debit.value );     // Debit Time (minutes)
      //--------------------------------------------------------------
      // minutes == # minutes they have been at work
      // For "Half-Days" either Annual Leave, or Flexi Leave, we don't
      // make them take a lunch break
      //--------------------------------------------------------------
      var minutes = stopT - startT;
	  var difference = wday - minutes;
      if ( noteVal.substr( 0, 2 ) == 'HD' ) {
        brkT = 0;
        brk.value = '00:00';
      } else {
        //------------------------------------------------------------
        // Has a lunch break been specified?  If not, default it...
        // Note: If 4 hours (240 minutes) or less are worked then no
        //       lunch break is required.
        // Note: If a "Half Day" is coded, no lunch break is required.
        //------------------------------------------------------------
        if ( ( brk.value == '' ) || ( brkT < 0 ) ) {
          brkT = ( minutes < 241 ) ? 0 : 30;
          brk.value = MtoH( brkT ).substr( 1 );
        }
        if ( ( brk.value != '' ) && ( minutes > 240 ) && ( brkT < 30 ) ) {
          alert( 'A Lunch break of 30 (or more) minutes is required.' );
          brkT = 30;
          brk.value = MtoH( brkT ).substr( 1 );     // No sign included
        }
      }
      if ( minutes < 0 ) {
        alert( 'The start time must be at or before the end time.' );
        brk.value = debit.value = credit.value = atWrk.value = worked.value = '';
      } else {
        //------------------------------------------------------------
        // These values do not include a sign prefix since they are,
        // or at least, should be positive.
        //------------------------------------------------------------
        atWrk.value  = MtoH( minutes ).substr( 1 );
        worked.value = MtoH( minutes - brkT ).substr( 1 );
        //------------------------------------------------------------
        // Have they worked less than a full day?
        //------------------------------------------------------------
//      alert( 'startT: ' + startT + '\n stopT: ' + stopT + '\nminutes: ' + ( minutes - brkT ) + '\n  atWork: ' + minutes );
       // if ( minutes - brkT < wday ) {
         // debit.value = MtoH( minutes - brkT - wday );
          //credit.value  = '+' + MtoH( 0 ).substr( 1 );
        //} else {
          if ( minutes - brkT < wday ) {
            switch ( noteVal ) {
              //--------------------------------------------------------
              // Stat Leave
              //--------------------------------------------------------
              case 'STAT' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
				worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
                debit.value  = '-00:00';
                break;
              //--------------------------------------------------------
              // Full Day Annual Leave
              //-------------------------------------------------------- 
              case 'FDAL' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
              //--------------------------------------------------------
              // Half Day Annual Leave - with Flexi Band Restrictions
              //--------------------------------------------------------
              case 'HDAL' :
                debit.value = credit.value = '-00:00';
                //------------------------------------------------------
                // Are they working in the morning, or in the afternoon?
                //------------------------------------------------------
                if ( startT < HtoM( '12:00' ) ) {
                  var msg = '';
                  //----------------------------------------------------
                  // Afternoon off.  Check the starting & ending time...
                  //----------------------------------------------------
                  if ( ( startT < HtoM( '08:00' ) ) || ( stopT < HtoM( '12:00' ) ) || ( stopT > HtoM( '14:00' ) ) ) {
                    if ( startT < HtoM( '08:00' ) ) {
                      start.value = '08:00';
                      startT = HtoM( '08:00' );
                      msg = 'Changing start time to 08:00';
                    }
                    if ( stopT < HtoM( '12:00' ) ) {
                      stop.value = '12:00';
                      stopT = HtoM( '12:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 12:00';
                      } else {
                        msg += ', and stop time to 12:00';
                      }
                    }
                    if ( stopT > HtoM( '14:00' ) ) {
                      stop.value = '14:00';
                      stopT = HtoM( '14:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 14:00';
                      } else {
                        msg += ', and stop time to 14:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                } else {
                  //----------------------------------------------------
                  // Morning off.  Check the starting & ending time...
                  //----------------------------------------------------
                  msg = '';
                  if ( ( startT > HtoM( '14:00' ) ) || ( stopT > HtoM( '18:00' ) ) ) {
                    if ( startT > HtoM( '14:00' ) ) {
                      start.value = '14:00';
                      startT = HtoM( '14:00' );
                      msg = 'Changing start time to 14:00';
                    }
                    if ( stopT > HtoM( '18:00' ) ) {
                      stop.value = '18:00';
                      stopT = HtoM( '18:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 18:00';
                      } else {
                        msg += ', and stop time to 18:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                }
                
                if ( minutes < hday ) {
                  if ( ( startT == stopT ) && ( startT == 0 ) ) {
                    start.value = stop.value = atWrk.value = worked.value = brk.value = debit.value = '';
                  } else {
                    debit.value = MtoH( minutes + hday - wday );
                  }
                } else {
                  credit.value = MtoH( minutes + hday - wday );
                }
                worked.value = MtoH( minutes + hday ).substr( 1 );
                break;              
              //--------------------------------------------------------
              // Full Day Flexi Leave
              //--------------------------------------------------------
              case 'FDFL' :
                alert( 'Specified start and/or stop times ignored, and reset.' );
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = '00:00';
 
                credit.value = MtoH( minutes - brkT );
                debit.value  = MtoH( -wday );
                break;
              //--------------------------------------------------------
              // Half Day Flexi Leave - with Flexi Band Restrictions
              //--------------------------------------------------------
              case 'HDFL' :
                credit.value = '+00:00';
                //------------------------------------------------------
                // Are they working in the morning, or in the afternoon?
                //------------------------------------------------------
                if ( startT < HtoM( '12:00' ) ) {
                  var msg = '';
                  //----------------------------------------------------
                  // Afternoon off.  Check the starting & ending time...
                  //----------------------------------------------------
                  if ( ( startT < HtoM( '08:00' ) ) || ( stopT < HtoM( '12:00' ) ) || ( stopT > HtoM( '14:00' ) ) ) {
                    if ( startT < HtoM( '08:00' ) ) {
                      start.value = '08:00';
                      startT = HtoM( '08:00' );
                      msg = 'Changing start time to 08:00';
                    }
                    if ( stopT < HtoM( '12:00' ) ) {
                      stop.value = '12:00';
                      stopT = HtoM( '12:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 12:00';
                      } else {
                        msg += ', and stop time to 12:00';
                      }
                    }
                    if ( stopT > HtoM( '14:00' ) ) {
                      stop.value = '14:00';
                      stopT = HtoM( '14:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 14:00';
                      } else {
                        msg += ', and stop time to 14:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                } else {
                  //----------------------------------------------------
                  // Morning off.  Check the starting & ending time...
                  //----------------------------------------------------
                  msg = '';
                  if ( ( startT > HtoM( '14:00' ) ) || ( stopT > HtoM( '18:00' ) ) ) {
                    if ( startT > HtoM( '14:00' ) ) {
                      start.value = '14:00';
                      startT = HtoM( '14:00' );
                      msg = 'Changing start time to 14:00';
                    }
                    if ( stopT > HtoM( '18:00' ) ) {
                      stop.value = '18:00';
                      stopT = HtoM( '18:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 18:00';
                      } else {
                        msg += ', and stop time to 18:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                }
                if ( minutes < hday ) {
                  if ( ( startT == stopT ) && ( startT == 0 ) ) {
                    start.value = stop.value = atWrk.value = worked.value = brk.value = debit.value = '';
                  } else {
                    debit.value  = MtoH( minutes - wday );
                  }
                }
                worked.value = MtoH( minutes ).substr( 1 );
                debit.value  = MtoH( minutes - wday );
                break;
			  //--------------------------------------------------------
              // Half Day Flexi / Half Day Annual
              //--------------------------------------------------------	
			  case 'HAHF' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( hday ).substr( 1 );
                credit.value = '+00:00';
                debit.value  = MtoH( -hday );
                break;
				
			  //--------------------------------------------------------
              // Half Day Special / Half Day Annual
              //--------------------------------------------------------	
			  case 'HSHA' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
				
			  //--------------------------------------------------------
              // Half Day Special / Half Day Flexi
              //--------------------------------------------------------	
			  case 'HSHF' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( hday ).substr( 1 );
                credit.value = '+00:00';
                debit.value  = MtoH( -hday );
                break;
			  //--------------------------------------------------------
              // Full Day Sick Leave
              //--------------------------------------------------------	
			  case 'FDSL' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
              //--------------------------------------------------------
              // Half Day Sick Leave
              //--------------------------------------------------------
			  case 'HDSL' :
                worked.value = MtoH( wday ).substr( 1 );
				brk.value = '00:00';
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
				break;
			  //--------------------------------------------------------
			  // Special Leave
			  //--------------------------------------------------------
			  case 'FDSP' :
                start.value  = stop.value = atWrk.value = brk.value = '00:00';
                worked.value = MtoH( wday ).substr( 1 );
                credit.value  = '+00:00';
          		debit.value  = '-00:00';
                break;
			  //--------------------------------------------------------
              // Half Day Special Leave - with Flexi Band Restrictions
              //--------------------------------------------------------
              case 'HDSP' :
			  	credit.value = '+00:00';
                debit.value = '-00:00';
                //------------------------------------------------------
                // Are they working in the morning, or in the afternoon?
                //------------------------------------------------------
                if ( startT < HtoM( '12:00' ) ) {
                  var msg = '';
                  //----------------------------------------------------
                  // Afternoon off.  Check the starting & ending time...
                  //----------------------------------------------------
                  if ( ( startT < HtoM( '08:00' ) ) || ( stopT < HtoM( '12:00' ) ) || ( stopT > HtoM( '14:00' ) ) ) {
                    if ( startT < HtoM( '08:00' ) ) {
                      start.value = '08:00';
                      startT = HtoM( '08:00' );
                      msg = 'Changing start time to 08:00';
                    }
                    if ( stopT < HtoM( '12:00' ) ) {
                      stop.value = '12:00';
                      stopT = HtoM( '12:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 12:00';
                      } else {
                        msg += ', and stop time to 12:00';
                      }
                    }
                    if ( stopT > HtoM( '14:00' ) ) {
                      stop.value = '14:00';
                      stopT = HtoM( '14:00' );
 
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 14:00';
                      } else {
                        msg += ', and stop time to 14:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                } else {
                  //----------------------------------------------------
                  // Morning off.  Check the starting & ending time...
                  //----------------------------------------------------
                  msg = '';
                  if ( ( startT > HtoM( '14:00' ) ) || ( stopT > HtoM( '18:00' ) ) ) {
                    if ( startT > HtoM( '14:00' ) ) {
                      start.value = '14:00';
                      startT = HtoM( '14:00' );
                      msg = 'Changing start time to 14:00';
                    }
                    if ( stopT > HtoM( '18:00' ) ) {
                      stop.value = '18:00';
                      stopT = HtoM( '18:00' );
                      if ( msg == '' ) {
                        msg = 'Changing stop time to 18:00';
                      } else {
                        msg += ', and stop time to 18:00';
                      }
                    }
                    alert( msg );
                    minutes = stopT - startT;
                    atWrk.value = worked.value = MtoH( minutes ).substr( 1 );
                  }
                }
                
                if ( minutes < hday ) {
                  if ( ( startT == stopT ) && ( startT == 0 ) ) {
                    start.value = stop.value = atWrk.value = worked.value = brk.value = debit.value = '';
                  } else {
                    debit.value = MtoH( minutes + hday - wday );
                  }
                } else {
                  credit.value = MtoH( minutes + hday - wday );
                }
                worked.value = MtoH( minutes + hday ).substr( 1 );
                break;
              //--------------------------------------------------------
              // Unspecified / Undefined
              //--------------------------------------------------------
              case '--' :
                if ( credit.value != '+00:00' ) credit.value = '+00:00';
                debit.value = ( minutes && brkT ) ? MtoH( minutes - brkT - wday ) : '';
                break;
              //--------------------------------------------------------
              // Unexpected!
              //--------------------------------------------------------
              default:
                alert( 'Unexpected note value: "' + noteVal + '"' );
            }
          } else {
            //----------------------------------------------------------
            // ( minutes - brkT >= wday ) ...
            //----------------------------------------------------------
            if ( noteVal.substr( 0, 2 ) == 'HD' ) {
              alert( 'Too many hours worked for specified note selection: ' + noteVal );
              note.selectedIndex = 0;
              adjust( document.getElementById( 'note' + idSuffix ), idSuffix, idSuffix.substr( 0, 1 ) );
            }
            debit.value  = '-' + MtoH( 0 ).substr( 1 );
            credit.value = MtoH( minutes - brkT - wday );
          }
        }
    //}
    } else {
      switch ( noteVal ) {
        //--------------------------------------------------------
        // Stat Leave
        //--------------------------------------------------------
        case 'STAT' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
		  worked.value = MtoH( wday ).substr( 1 );
          credit.value  = '+00:00';
          debit.value  = '-00:00';
          break;
        //------------------------------------------------------------
        // Full Day Annual Leave
        //------------------------------------------------------------
        case 'FDAL' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = MtoH( wday ).substr( 1 );
          credit.value  = '+00:00';
          debit.value  = '-00:00';
          break;
        //------------------------------------------------------------
        // Half Day Annual Leave
        //------------------------------------------------------------
        case 'HDAL' :
          credit.value = debit.value = '+00:00';
          worked.value = MtoH( hday ).substr( 1 );
          break;
        //------------------------------------------------------------
        // Full Day Flexi Leave
        //------------------------------------------------------------
        case 'FDFL' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = credit.value = '00:00';
          debit.value  = MtoH( -wday );
          break;
        //------------------------------------------------------------
        // Half Day Flexi Leave
        //------------------------------------------------------------
        case 'HDFL' :
          credit.value = '+00:00';
          debit.value  = '-00:00';
//        start.value  = stop.value = atWrk.value = worked.value = brk.value = credit.value = '';
          break;
		  
		//--------------------------------------------------------
        // Half Day Flexi / Half Day Annual
        //--------------------------------------------------------	
		case 'HAHF' :
           start.value  = stop.value = atWrk.value = brk.value = '00:00';
           worked.value = MtoH( hday ).substr( 1 );
           credit.value = '+00:00';
           debit.value  = MtoH( -hday );
           break;
				
		//--------------------------------------------------------
        // Half Day Special / Half Day Annual
        //--------------------------------------------------------	
		case 'HSHA' :
           start.value  = stop.value = atWrk.value = brk.value = '00:00';
           worked.value = MtoH( wday ).substr( 1 );
           credit.value  = '+00:00';
           debit.value  = '-00:00';
           break;
				
		//--------------------------------------------------------
        // Half Day Special / Half Day Flexi
        //--------------------------------------------------------	
		case 'HSHF' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = MtoH( hday ).substr( 1 );
          credit.value = '+00:00';
          debit.value  = MtoH( -hday );
          break;
        //------------------------------------------------------------
        // Full Day Sick Leave
        //------------------------------------------------------------
        case 'FDSL' :
		  worked.value = MtoH( wday ).substr( 1 );
		  start.value  = stop.value = atWrk.value = brk.value = '00:00';		
		  credit.value = '+00:00';
          debit.value  = '-00:00';
          
          break;
		//------------------------------------------------------------
        // Half Day Sick Leave
        //------------------------------------------------------------
		case 'HDSL' :
		  worked.value = MtoH( wday ).substr( 1 );
          credit.value = '+00:00';
		  debit.value = '-00:00';
		  brk.value = '00:00';
          break;
		//------------------------------------------------------------
        // Full Day Special Leave
        //------------------------------------------------------------
        case 'FDSP' :
          start.value  = stop.value = atWrk.value = brk.value = '00:00';
          worked.value = MtoH( wday ).substr( 1 );
          credit.value  = '+00:00';
          debit.value  = '-00:00';
          break;
		//------------------------------------------------------------
        // Half Day Special Leave
        //------------------------------------------------------------
        case 'HDSP' :
          credit.value = '+00:00';
		  debit.value = '-00:00';
          worked.value = MtoH( hday ).substr( 1 );
          break;
        //------------------------------------------------------------
        // Unspecified / Undefined
        //------------------------------------------------------------
        case '--' :
          if ( credit.value != '+00:00' ) credit.value = '+00:00';
          debit.value = ( minutes && brkT ) ? MtoH( minutes - brkT - wday ) : '';
          break;
        //------------------------------------------------------------
        // Unexpected!
        //------------------------------------------------------------
        default:
          alert( 'Unexpected note value: "' + noteVal + '"' ) 
      }
    }
  }
 
  //------------------------------------------------------------------
  // Name: calc()
  // Role: Compute the weekly hours and flexi time fields
  //------------------------------------------------------------------
  function calc( hId, cId, dId, week ) {
    var worked = field( hId + week );  // Weekly hours worked field
    var credit = field( cId + week );  // Weekly credit field
    var debit  = field( dId + week );  // Weekly debit  field
    var hSum   = 0;                    // Weekly hours worked sum
    var cSum   = 0;                    // Weekly credit hours sum
    var dSum   = 0;                    // Weekly debit  hours sum
    //----------------------------------------------------------------
    // weekly sum of (non-blank) hoursWorked, credit, & debit values
    //----------------------------------------------------------------
    for ( var i = 1; i < 6; i++ ) {
      var hDay = field( hId + week + i ).value;
      if ( hDay != '' ) {
        hDay.match( /^(\d\d:\d\d)$/ );
        hSum += HtoM( RegExp.$1 );
      }
      var cDay = field( cId + week + i ).value;
      if ( cDay != '' ) {
        cDay.match( /^([-+]?)(\d\d:\d\d)$/ );
        var s = RegExp.$1, m = HtoM( RegExp.$2 );
        cSum += ( s == '-' ) ? -m : m;
      }
      var dDay = field( dId + week + i ).value;
      if ( dDay != '' ) {
        dDay.match( /^([-+]?)(\d\d:\d\d)$/ );
        var s = RegExp.$1, m = HtoM( RegExp.$2 );
        dSum += ( s == '-' ) ? -m : m;
      }
    }
    //----------------------------------------------------------------
    // If the hours worked target field exists, store the info
    //----------------------------------------------------------------
    if ( worked ) {
      worked.value = MtoH( hSum ).substr( 1 );   // Discard sign
    }
    //----------------------------------------------------------------
    // If the credit target field exists, store the value
    //----------------------------------------------------------------
    if ( credit ) {
      credit.value = MtoH( cSum );               // Include sign
    }
    //----------------------------------------------------------------
    // If the debit target field exists, store the value
    //----------------------------------------------------------------
    if ( debit ) {
      debit.value = MtoH( dSum );               // Include sign
    }
  }
 
  //------------------------------------------------------------------
  // Name: adjust()
  // Role: Check the daily, and weekly calculations, and adjust the
  //       cumulative flexi time accordingly;
  // Note: obj is a reference to the DOM element containing the call
  //       which is required to have a "well formed" id attribute of
  //       the form id='note##' where: xx is the idSuffix of the value
  //------------------------------------------------------------------
  function adjust( obj, idSuffix, week ) {
    if ( obj && ( obj.nodeName == 'SELECT' ) && ( 'id' in obj ) && ( obj.id.search( /^note(\d\d)$/ ) == 0 ) ) {
      idSuffix = RegExp.$1;
      week     = idSuffix.substr( 0, 1 );
      var id   = obj.id;
      //--------------------------------------------------------------
      // Which DOM element was selected, and to what value was it set?
      // Note: it is possible (at least in IE) that the previous
      //       selection was HDFL, and they just tried to change it to
      //       FDFL instead.  Unfortunately, if this option has been
      //       marked as disabled, then the selection will be reset to
      //       '--' (i.e., index = 0), and we need to redo all of the
      //       option settings to see which (if any) should be
      //       disabled.
      //--------------------------------------------------------------
      var index = obj.selectedIndex;
      if ( obj.options[ index ].disabled ) {
        alert( 'Sorry, that selection is not available.' );
        index = obj.selectedIndex = 0;
      }
      var noteVal = obj.options[ index ].innerHTML;
      //--------------------------------------------------------------
      // Only 1 instance of FDFL, or 2 of HDFL are allowed.
      // So, if 1 FDFL has been selectd, disable all FDFL and HDFL
      // If 1 HDFL has been selected, disable all FDFL
      // If 2 HDFL have been selected, disable all HDFL
      //--------------------------------------------------------------
      var notes = new Array();
	  var names = 'flag01,flag02,flag03,flag04,flag05,flag11,flag12,flag13,flag14,flag15,flag21,flag22,flag23,flag24,flag25,flag31,flag32,flag33,flag34,flag35'.split( ',' );
 
	  //for ( var i = 0; i < names.length; i++ ) 
	 // { notes = notes.concat( document.getElementsByName( names[ i ] ) );
		//}
 
		for ( var i = 0; i < names.length; i++ ) {
  var sel = document.getElementsByName( names[ i ] );
  for ( var j = 0; j < sel.length; j++ ) {
    if ( sel[ j ].type != 'select-one' ) {
      //alert( 'Problem: element with name="' + names[ i ] +  '" has type="' + sel[ j ].type + '"' );
	  document.getElementById( 'debug' ).innerHTML = sel[ j ].innerHTML;
 
    } else {
      notes[ notes.length ] = sel[ j ];
    }
  }
}
 
      var fdfl  = 0;                     // number of FDFL picked?
      var hdfl  = 0;					 // number of HDFL picked
	  var hahf  = 0;					 // number of HAHF picked
	  var hshf  = 0;                     // number of HSHF picked
      for ( var i = 0; i < notes.length; i++ ) {
        var x   = notes[ i ].selectedIndex;
        var val = notes[ i ].options[ x ].innerHTML;
        if ( val == 'FDFL' ) fdfl++;
        if ( val == 'HDFL' ) hdfl++;
		if ( val == 'HAHF' ) hahf++;
		if ( val == 'HSHF' ) hshf++;
      }
//    alert( 'FDFL = ' + fdfl + '\nHDFL = ' + hdfl + '\nthis = ' + noteVal + '\nid = "' + id + '"' );
      //--------------------------------------------------------------
      // Now that we've determined how many Flexi Leave selects have
      // been made, we process the "notes" selection lists to
      // enable/disable the Flexi Leave selections as appropriate.
      // Note: In a perfect world, an "option" disabled attribute
      //       could be set to true/false, and everything would work
      //       fine.  Unfortunately, FireFox, and IE act very
      //       differently when it comes to "disabled" options.
      //       FireFox - doesn't care what the value is, the presence
      //                 of the disabled attribute makes the option
      //                 unselectable.  So, in order to "enable" the
      //                 option, we need to use removeAttribute()
      //       IE      - doesn't care if the attribute is present or
      //                 not.  So, we have to check when an option is
      //                 selected to see if the attribute is present.
      //--------------------------------------------------------------
      for ( var i = 0; i < notes.length; i++ ) {
        for ( var j = 0; j < notes[ i ].options.length; j++ ) {
          var val = notes[ i ].options[ j ].innerHTML;
          //----------------------------------------------------------
          // FDFL - disable if any (other) FDFL have been selected, or
          //        if any HDFL have been selected.
          //----------------------------------------------------------
//        var set = ( notes[ i ].id != id ) && ( ( fdfl > 0 ) || ( hdfl > 0 ) );
          var set = ( fdfl > 0 ) || ( hdfl > 0 ) || (hahf > 0) || (hshf > 0);
          if ( val == 'FDFL' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
		  
		  set = ( fdfl > 0 ) || ( hdfl > 1) || (hshf > 1) || (hahf > 1);
          if ( val == 'HAHF' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
		  
		  set = ( fdfl > 0 ) || ( hdfl > 1) || (hahf > 1) || (hshf > 1);
          if ( val == 'HSHF' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
          //----------------------------------------------------------
          // HDFL - disable if any FDFL have been selected, or if move
          //        than 1 other HDFL have been selected
          //----------------------------------------------------------
//        set = ( notes[ i ].id != id ) && ( ( fdfl > 0 ) || ( hdfl > 1 ) );
          set = ( fdfl > 0 ) || (hahf > 1) || ( hshf > 1) || ( hdfl > 1);
          if ( val == 'HDFL' ) {
            if ( set ) {
              notes[ i ].options[ j ].setAttribute( 'disabled', true );
            } else {
              notes[ i ].options[ j ].removeAttribute( 'disabled' );
            }
          }
        }
      }
    }
    
    compute( idSuffix );               // Process daily values
    calc( 'hrWorked', 'credit', 'debit', week );
    //----------------------------------------------------------------
    // Compute, and update the cumulative flexi hours value,
    // processing include potential carryover from previous month...
    //----------------------------------------------------------------
    var cum   = field( 'cumulative' );
    var carry = field( 'CarriedFlexi' );
    if ( cum ) {
      var total = 0;
      if ( carry && carry.value != '' ) {
        total = HtoM( carry.value );
      }
      for ( var w = 0; w < 4; w++ ) {
        var wFlexi = field( 'credit' + w );
        if ( wFlexi && wFlexi.value != '' ) {
          total += HtoM( wFlexi.value );
        }
        var debit  = field( 'debit'  + w );
        if ( debit && debit.value != '' ) {
          total += HtoM( debit.value );
        }
      }
      cum.value = MtoH( total );
    }
  }
  
  //------------------------------------------------------------------
  // Name: checkIt()
  // Role: Verify that user input is a "valid" time.
  // Note: It is expected that this will normally be invoked using
  //       a call like the following, where 0 is the week # 0..3:
  //       for example: onchange='checkIt(this,0);'
  //------------------------------------------------------------------
  function checkIt( obj, week ) {
    var val = obj.value;          // Current field value
    //----------------------------------------------------------------
    // Was a valid value provided?
    //----------------------------------------------------------------
    if ( val.search( /^[-+]?(\d{0,3}):?(\d\d)$/ ) < 0 ) {
      if ( val != '' ) {
        alert( 'Please enter a numeric value of the form: HH:MM' );
        obj.value = '';
      }
    } else {
      //--------------------------------------------------------------
      // Process a valid value, don't include the sign in the output
      //--------------------------------------------------------------
      obj.value = MtoH( HtoM( val ) ).substr( 1 );
    }
    var id = obj.id;                        // id attribute for element
    var ix = id.substr( id.length - 2 );    // Trailing 2 digits
    adjust( null, ix, week );
  }
 
  //------------------------------------------------------------------
  // Information used to populate the date related DOM elements based
  // upon the week number (0..3).
  //------------------------------------------------------------------
  var info = new Array( 4 );
  info[ 0 ] = { names  : 'txtDate2,txtDate3,txtDate4,txtDate5'.split( ',' ),
                hidden : 'Date2,Date3,Date4,Date5'.split( ',' ),
                extId  : 'txtDate1',
                intId  : 'Date1'
              };
 
  info[ 1 ] = { names  : 'txtDate7,txtDate8,txtDate9,txtDate10'.split( ',' ),
                hidden : 'Date2b,Date3b,Date4b,Date5b'.split( ',' ),
                extId  : 'txtDate6',
                intId  : 'Date1b'
              };
 
  info[ 2 ] = { names  : 'txtDate12,txtDate13,txtDate14,txtDate15'.split( ',' ),
                hidden : 'Date2c,Date3c,Date4c,Date5c'.split( ',' ),
                extId  : 'txtDate11',
                intId  : 'Date1c'
              };
 
  info[ 3 ] = { names  : 'txtDate17,txtDate18,txtDate19,txtDate20'.split( ',' ),
                hidden : 'Date2d,Date3d,Date4d,Date5d'.split( ',' ),
                extId  : 'txtDate16',
                intId  : 'Date1d'
              };
 
  //------------------------------------------------------------------
  // Name: fillDates
  // Role: Generate a sequence of valid dates, in a specific format
  //------------------------------------------------------------------
  function fillDates( week ) {
    var extId = info[ week ].extId;
    
    var val = field( extId ).value;
    if ( val != '' ) {
      var dat = val.split( '/' );
      var names  = info[ week ].names;
      var hidden = info[ week ].hidden;
      var intId  = info[ week ].intId;
 
      //--------------------------------------------------------------
      // Extract the user specified date fields
      //--------------------------------------------------------------
      var y0  = Number( dat[ 2 ] );
      var m0  = Number( dat[ 1 ] ) - 1;
      var d0  = Number( dat[ 0 ] );
 
      //--------------------------------------------------------------
      // Use this information to generate a "valid" date
      //--------------------------------------------------------------
      var D1  = new Date( y0, m0, d0 );
      var y1  = D1.getFullYear();
      var m1  = twoD( D1.getMonth() + 1 );
      var d1  = twoD( D1.getDate() );
 
      //--------------------------------------------------------------
      // Save this valid date to the field from which it was retrieved
      // (i.e., the external field) as well as the associated "hidden"
      // (internal) field.
      //--------------------------------------------------------------
      field( extId ).value = d1 + '/' + m1 + '/' + y1;
      field( intId ).value = y1 + '/' + m1 + '/' + d1;
 
      //--------------------------------------------------------------
      // Using the valid date, generate the subsequent 4 dates
      //--------------------------------------------------------------
      for ( var i = 0; i < 4; i++ ) {
        var D2 = new Date( y0, m0, d0 + i + 1 );
        var d2 = twoD( D2.getDate() );
        var m2 = twoD( D2.getMonth() + 1 );
        var y2 = D2.getFullYear();
 
        field( names[ i ] ).value = d2 + '/' + m2 + '/' + y2;
        field( hidden[ i ] ).value = y2 + '/' + m2 + '/' + d2;
      }
    }
  }
 
  //------------------------------------------------------------------
  // Name: header()
  // Role: Generate the header for the specified week
  //------------------------------------------------------------------
  function header( weekNum ) {
    return '<h1>Week <span class="headingLightBlue">' + weekNum + '</span></h1>';
  }
 
  //------------------------------------------------------------------
  // Name: toggle()
  // Role: Display the appropriate week DIV
  //------------------------------------------------------------------
  function toggle( weekNum ) {
    //----------------------------------------------------------------
    // Is the selected week "hidden"?
    //----------------------------------------------------------------
    if ( field( 'Week' + weekNum ).style.display == 'none' ) {
      for ( var w = 1; w < 5; w++ ) {
        field( 'Week' + w ).style.display = ( ( w == weekNum ) ? 'block' : 'none' );
      }
    }
    field( 'commentHeader' ).innerHTML = header( weekNum );
  }
 
  //------------------------------------------------------------------
  // Name: Style()
  // Role: set the style details for the specified weekNum (1..4)
  //------------------------------------------------------------------
  function Style( weekNum ) {
    
    //----------------------------------------------------------------
    // Get references to the portions of the document for all weeks
    //----------------------------------------------------------------
    var table = field( 'Week' + weekNum );
    var week = new Array( 4 );
    for ( var w = 1; w < 5; w++ ) {
      week[ w ] = field( 'wk' + w );
    }
    
    //----------------------------------------------------------------
    // Set the table style details
    //----------------------------------------------------------------
    table.style.borderColor = '#00CCFF';
    table.style.borderWidth = '2px';
    
    //----------------------------------------------------------------
    // Set the week style details for each week, with the selected
    // week (i.e., weekNum) differentiated.
    //----------------------------------------------------------------
    for ( w = 1; w < 5; w++ ) {
      if ( w == weekNum ) {
        week[ w ].style.backgroundColor = '#00CCFF';
        week[ w ].style.color = '#ffffff';
      } else {
        week[ w ].style.backgroundColor = '#efefef';
        week[ w ].style.color = '#999999';
      }
    }
  }
 
  function show(){
    sectionHelp.style.display = ( sectionHelp.style.display == 'none' ) ? '' : 'none';
  }
</script>

Open in new window

Please take some time to play with this, and let me know what you think.

I don't believe it's "perfect", but would like to get your input.
4Weeks.html.txt
08-12-12.js.txt
Avatar of SEUPB

ASKER

Hi Bob,

Apologies for the delayed response. I have only had the chance to test out the new coding today. The coding works to a point, depending on the sequence of half day flexi notes are selected.

For example,

If I select HDFL on a Monday, then selected HDFL on a Tuesday and when I try to select say, HAHF, it would prompt me with an error saying its not available, this is fine.

But when I select HDFL on a Monday, then select HAHF on a Tuesday I am able to select HAHF again or HSHF. So it seems if I don't select two of the same notes after each other, the logic is lost.

The FDFL logic seems to be working fine, just the half days that are giving problems.

Hope this makes sense.

Thankls,

Michael
I think that you missed something...

When you select HDFL on Monday, then HAHF on a/any Tuesday then all of the notes lists are updated to remove HDFL, HAHF, and HSHF, so these can't be selected unless you change one of the previously selected "half day" entries.
Avatar of SEUPB

ASKER

Hi Bob,

Apologies, I didn't apply the changes with the html file you included. I have applied the changes to the html now and have tested the javascript as well. I'm guessing the main part I'm checking here is the half day notes? As the FDFL logic doesn't seem to be working properly as I am able to select FDFL constantly. In relation to the HDFL, HAHF and HSFL, the logic you have coded works very nice, I didn't think about the possibility of limited options instead of using an alert message.

In conjunction with this, I don't know if you remember, is it possible to code a bit of logic that if the person decides to select FDFL twice that it prompts them to enter in a pin code to validate their choice? If not the logic would just deny the selection?

Thanks,

Michael
I hadn't looked into that other request yet.

Let's focus on getting the original request working as needed first.

If your code isn't working, I guess I'm going to need to have you attach what you have so that I can take a look.
Avatar of SEUPB

ASKER

Hi Bob,

That's not a problem. I have attached my html coding, I left out the javascript as I simply just downloaded yours and linked it to my timesheet.

Thanks,

Michael
flexiTimesheetAddTest.txt
Avatar of SEUPB

ASKER

Hi Bob,

Just letting you know I tested your coding as well and the logic doesn't seem to be working for the FDFL note. SO when I select FDFL, I am still able to select to another FDFL or HDFL.

I have noticed there is an error when opening your page as well, but its point to the line,

<html xmlns="http://www.w3.org/1999/xhtml">

which doesn't make sense.

The error message says,

LIne 2,
Char : 1
Error Invalid Code.

Thanks,

Michael
Yeah, something is really wrong...  it doesn't display properly because of something...

Looking.
Avatar of SEUPB

ASKER

Hi Bob,

I managed to get rid of that error I posted, it was linked to the javascript datepicker. But the logic for FDFL is still not working. Is it a problem with the javascript?

Hope this helps,

Michael
Haven't found any yet... Still looking...
Avatar of SEUPB

ASKER

Hi Bob,

Hope you are keeping well and that you had a lovely Christmas and a Happy new Year. Just a quick comment to see if you have had any luck with errors?

Thanks,

Michael
Michael:

  Thanks for asking.  Hopefully yours was nice.

  Looking, again, at the code today.
When you say "But the logic for FDFL is still not working." Can you be more specific?
Avatar of SEUPB

ASKER

Hi Bob,

Thanks for the quick reply. Apologies for the vague explaination, what I meant was, the logic you coded so far works fine in the sense that, when I select 2x half day flexi leave notes, it removes the rest of the half day flexi notes but doesn't remove the FDFL note. When I select FDFL note, it doesn't remove the Half Day Flexi Leave notes.

Does that make sense?
Ah.  I didn't realize that it should remove the FDFL as well...

ok, that makes more sense...  Let me see what I can do
Avatar of SEUPB

ASKER

Sorry, for the confusion.

So basically it should allow for 1 FDFL or 2 Half Day Flexi Leaves. The other part of my question was, if its possible to have a logic to detect if the person has selected 2 FDFL notes to flag up a message requesting for pin code? I don't know if this will affect what you're coding now?

Thanks,

Michael
How would they select 2 FDFL if all unselected FDFL are removed when 1 is selected?
The problem is that say 1 half-day flexi is selected.
Should a prompting occur when a FDFL is selected, or should all unselected FDFL be removed?
Avatar of SEUPB

ASKER

In theory, when I discussed with the HR department, they would only allow 2 FDFL notes and not a combination of 1 FDFL and 2 Half Day Flexi Leave notes. So in a sense if the code incorporated the pin code idea, the only flags that get removed when Half Day Flexi Leave notes are selected is the FDFL, and when FDFL is selected the Half Day Flexi Leave notes are removed, so the option of selecting another FDFL is still available.

Does that make sense?

I can make this into a separate question if its easier to resolve the initial issue first?
That sounds reasonable.

Let's stick with this one issue first.
Avatar of SEUPB

ASKER

No problem!! The coding you have for the first issue is pretty much nearly there. I think it works morer nicer and smoother than the prompts :D.
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SEUPB

ASKER

Hi Bob,

I just tested the coding. Yes that seems to be spot on! Works really well. I just need to let a few users to look at it and test it. Will get back to you soon.

Thanks,

Michael
Good, let me know.
Avatar of SEUPB

ASKER

Hi Bob,

Great news, got the go ahead with this, so thats the first problem solved. Should I create a new question for the 2nd problem and post a link here?

The coding worked a treat in testing without any problems!

Thanks,

Michael
Let's do a second question, if you don't mind
now all I have to do is figure out how to get at least $1 for each EE point earned. :-)
Avatar of SEUPB

ASKER

Hehe $1 a point is good!! I'll make you get loads of points. Yup I will set up the question in that zone and post a link as well. Many Thanks for the help again.
Avatar of SEUPB

ASKER

Thanks for the grade & points.