	// JavaScript functions related to date_menu object
	
	
	function reflectDay(mon, day, year) {
		var now = day.selectedIndex;
		var mnow = mon.selectedIndex;
		var ynow = year.selectedIndex;
		var dayString = (now < 0) ? "undefined" : day[day.selectedIndex].value;
		var monString = (mnow < 0) ? "undefined" : mon[mon.selectedIndex].value;
		var yrString = (ynow < 0) ? "undefined" : year[year.selectedIndex].value;

		var mo;
		var yr;

		if (mnow >= 0) {
			mo = parseInt(mon[mon.selectedIndex].value,10);
		} else {
			mo = 0
		}

		if (ynow >= 0) {
			yr = parseInt(year[year.selectedIndex].value,10);
		} else {
			yr = 0
		}

		if (mo == 4 || mo == 6 || mo == 9 || mo == 11) {
    	for (i = day.length + 1; i <= 30; i++) {
      	addDay(day,i);
      }
      for (i = day.length; i > 30 ;i--) {
        yankDay(day,i);
      }
		} else {
    	if (mo == 2) {
      	for (i = day.length; i > 29 ;i--) {
        	yankDay(day,i);
        }
        if ( yr % 4 > 0 || (yr % 100 == 0 && yr % 400 > 0)) {
        	yankDay(day,29);
        } else {
        	for (i = day.length + 1; i <= 29; i++) {
          	addDay(day,i);
          }
        }
      } else {
      	for (i = day.length + 1; i <= 31; i++) {
        	addDay(day,i);
        }
      }
		}
		if (now >= day.length) {
    	day.selectedIndex = day.length - 1;
      dayString = day[day.selectedIndex].value;
		}

		var dateString = yrString+"-"+monString+"-"+dayString;
		return dateString
	}

	function yankDay(field,day) {
  	   ind = day - 1;
       start = field.selectedIndex;
	   if (isNaN(start)) { start = -1; }
	   // if the currently selected index was the last item, decrement
	   // it so that we set a valid index into the field.
	   if ( ind == start ) { start = start - 1; }
	   field.options[ind] = null;
       field.selectedIndex = start;
	}

	function addDay(field,day) {
  	ind = day - 1;
    start = field.selectedIndex;
		if (isNaN(start)) { start = -1; }
	    field.options[ind] = new Option (day);
      field.selectedIndex = start;
	}	
	
	function getFormIndexByElement(el){
		var i = 0;
		for (i=0;i<document.forms.length;i++){
			if (document.forms[i] == el.form){
				return i;
			}
		}
	}


	function updateHiddenDate(el,field_name,hidden_name,hidden_name_end){
		var i = getFormIndexByElement(el);
		var frm = 'document.forms['+i+'].';
		var hh24,hh24_e;
		
		var yy = eval(frm +field_name+'_yyyy');
		var mm = eval(frm +field_name+'_mm');
		var dd = eval(frm +field_name+'_dd');
		var sdate;
		var dd_sel = dd.selectedIndex +1;
		if (yy.selectedIndex >= 0 && mm.selectedIndex >= 0 && dd_sel >= 1){
			sdate = yy[yy.selectedIndex].value+"-"+mm[mm.selectedIndex].value+"-"+(dd_sel>9?dd_sel:'0'+dd_sel);
			var hh;
			if (typeof (hh = eval(frm +field_name+'_hh')) != "undefined"){						
				var mi = eval(frm +field_name+'_mi');
				var am = eval(frm +field_name+'_am');
				hh24 = parseInt(hh[hh.selectedIndex].value,10);
				if (am.type != "hidden") { 
				// if am is a hidden field, then the hour is already in 24hr format
				  hh24 = hh24 + 12*parseInt(am[am.selectedIndex].value,10);
			  }
			  hh24 = zeroPad(hh24);
				hh24 = hh24+':'+mi[mi.selectedIndex].value+':'+'00';
			}
			else {
				hh24 = '00:00:00';
			}

			var hidden_field = eval(frm + hidden_name);
			hidden_field.value = sdate+' '+hh24;
			var e_hh; 
			if (typeof (e_hh = eval(frm +field_name+'_e_hh')) != "undefined"){
				var e_mi = eval(frm +field_name+'_e_mi');
				var e_am = eval(frm +field_name+'_e_am'); 
				e_hh24 = parseInt(e_hh[e_hh.selectedIndex].value,10);
				var hidden_field_end = eval(frm + hidden_name_end);
				if (e_am.type != "hidden") {					
				    e_hh24= e_hh24 + 12*parseInt(e_am[e_am.selectedIndex].value,10);
			  }
			  e_hh24 = zeroPad(e_hh24);
				hidden_field_end.value = sdate +' ' + e_hh24+':'+e_mi[e_mi.selectedIndex].value+':'+'00';
				
			}
		}
	}	
