﻿//---------------------------------------------------------------------
// WAF - Web/Windows Application Framework
// Copyright © 2005 The Enticy Group LLC.
//
// File:	datepicker.js
//
// Description:	Javascript class and functions to support a popup date picker window
//
// Revisions :
//		2003-07-07	Conrad	added call to onchange() on clicking a date
//		2003-08-11	Conrad	start at date of field's current value, not today
//		2003-08-12	Conrad	removed yearly calendar, use styles, remove format
//		2003-10-02	Conrad	substantial improvements
//		2005-07-08	Conrad	changed nav_* images to .pngs
//		2005-10-25	Conrad	strip time from date for Safari's Javascript engine
//---------------------------------------------------------------------

var session_dateChoice1 = '';
var session_dateChoice2 = '';
 
function show_calendar(returnFieldId, winCal, monthToShow, yearToShow, pre_text, displaytype, parent_or_id, activedatearray, numcalstoshow, suppress_day_a_refs) {
	
	// This is the "outside link" to this code.
	
    // This creates a new global calendar and displays it
	cal = new Calendar(returnFieldId, winCal, monthToShow, yearToShow, pre_text, displaytype, parent_or_id, activedatearray, numcalstoshow, suppress_day_a_refs);
	

}

function Calendar(returnFieldId, winCal, monthToShow, yearToShow, pre_text, displaytype, parent_or_id, activedatearray, numcalstoshow, suppress_day_a_refs) {

    if (pre_text == undefined) { pre_text = ''; }
    if (displaytype == undefined) { displaytype = 'popup'; } //div or inline
    
    this.pre_text = pre_text;
    this.displaytype = displaytype;
    this.parent_or_id = parent_or_id;
    this.activedatearray = activedatearray;
    this.numcalstoshow = numcalstoshow;
    this.suppress_day_a_refs = suppress_day_a_refs;
    

	// Constructor -- also displays the window

	// Get the current date
	var dNow = new Date();
	this.gNowDay = dNow.getDate();
	this.gNowMonth = dNow.getMonth();
	this.gNowYear = dNow.getFullYear();

	// Get the field's current value as a starting date, or use today as a default
	var dStartDate;
	if (returnFieldId != null)
		dStartDate = this.stringToDate(document.getElementById(returnFieldId).value);
	if (dStartDate == null)
		dStartDate = dNow;
	this.gStartDay = dStartDate.getDate();
	this.gStartMonth = dStartDate.getMonth();
	this.gStartYear = dStartDate.getFullYear();

	// If we haven't chosen a month to display, use the starting date's month
	if (monthToShow == null) {
		monthToShow = new String(dStartDate.getMonth());
		yearToShow = new String(dStartDate.getFullYear().toString());
	}

	// If winCal is null, a new window is created
	if (winCal == null)
		this.gWinCal = this.newWindow();
	else
		this.gWinCal = winCal;

	this.gMonthName = this.monthName(monthToShow);
	this.gMonth = new Number(monthToShow);
	this.gYear = yearToShow;
	this.gReturnItem = returnFieldId;

	this.show();
}

Calendar.prototype.newWindow = function() {
    if (this.displaytype == 'popup') {
	    // Create a new default Calendar window
	    winCal = window.open("", "Calendar", "width=250,height=200,status=no,resizable=no,top=200,left=200");
	    winCal.focus();
	    winCal.opener = self;
	    return winCal;
	}else{
	    if ($(this.pre_text + 'calendardiv') != undefined) {
	        if (this.displaytype == 'div') {
                $(this.pre_text + 'calendardiv').replace(new Element('div',{id: this.pre_text + 'calendardiv', 'class':'popupcalendar'}));
            }else{
                $(this.pre_text + 'calendardiv').replace(new Element('div',{id: this.pre_text + 'calendardiv', 'class':'calendardiv'}));
            }
	    }else{
            if (this.displaytype == 'div') {
                $(this.parent_or_id).insert(new Element('div',{id: this.pre_text + 'calendardiv', 'class':'popupcalendar'}));
            }else{
                $(this.parent_or_id).insert(new Element('div',{id: this.pre_text + 'calendardiv', 'class':'calendardiv'}));
            }
        }
        return window;
	    
	}
}


Calendar.prototype.getWeekday = function(day) {
    var weekday = new Array(7);
    weekday[0] = "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";
    return weekday[day];
}

Calendar.prototype.monthName = function(month) {
	monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	return monthNames[month];
}

Calendar.prototype.daysInMonth = function(month, year) {

	daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

	var nDays = daysInMonth[month];
	if (month == 1) // February
		if ( ((year % 400) == 0) || ((year % 4) == 0 && (year % 100) != 0) )
			nDays += 1;
	return nDays;
}

Calendar.prototype.getMonthlyCalendarCode = function(curcal) {
    
    return (
		'<table class="calMonthTable" cellspacing="0">' +
		this.cal_header(curcal) +
		this.cal_data() +
		'</table>'
	);
}

Calendar.prototype.buildCallText = function(month, year) {
	if (this.displaytype == 'popup') {
	    return (
		    "window.opener.show_calendar(" + 
		    "'" + this.gReturnItem + "', self, " + month + ", " + year +
		    ");"
	    );
	}else{
	    var arrayval = 'null';
	    
	    if (this.activedatearray != undefined && this.activedatearray != null) {
	        arrayval = "Array("
	        
	        for (x=0; x<this.activedatearray.length; x++){
	            arrayval += "Array("
	            for (y=0; y<this.activedatearray[x].length; y++){
	                arrayval += "'" + this.activedatearray[x][y] + "'";
	                if ((y+1) < this.activedatearray[x].length) { 
	                    arrayval += ",";
	                }
	            }
	            arrayval += ")";
	            if ((x+1) < this.activedatearray.length) { 
	                arrayval += ",";
	            }
	        }   
	        arrayval += ")";
	    }
	    if (this.suppress_day_a_refs != undefined && this.suppress_day_a_refs != null) {
	        if (this.suppress_day_a_refs.constructor.toString().indexOf("Array") == -1){
	            arrayval2 = this.suppress_day_a_refs;
	        }else{
	            arrayval2 = "Array("
    	        
	            for (x=0; x<this.suppress_day_a_refs.length; x++){
	                arrayval2 += "'" + this.suppress_day_a_refs[x] + "'";
	                if ((x+1) < this.suppress_day_a_refs.length) { 
	                    arrayval2 += ",";
	                }
	            }   
	            arrayval2 += ")";
	        }
	    }

        return (
	        "show_calendar(" + 
	        "'" + this.gReturnItem + "', null, " + month + ", " + year + ", '" +
	        this.pre_text + "', '" + this.displaytype + "','" + this.parent_or_id + "'" + "," + arrayval + "," + this.numcalstoshow + "," + arrayval2 +
	        ");"
        );
	    
	}
}

Calendar.prototype.buildLinkText = function(month, year, isPrevious, isMonthly) {
	var sLink = 
		'<a class="calNavLink" href="javascript:' + 
		this.buildCallText('\'' + month + '\'', '\'' + year + '\'') + '">';

	if (isPrevious)
		sDirectionText = "prev";
	else
		sDirectionText = "next";

	if (isMonthly)
		sIntervalText = "month";
	else
		sIntervalText = "year";

	sLink += '<img class="calNavImage" title="' + sDirectionText + ' ' + sIntervalText + '" src="images/calb' + sDirectionText + '.gif"/>';
	sLink += '</a>';

	return sLink;
}

Calendar.prototype.show = function() {
	
	// CCC: I commented this out, because it causes a Javascript error.
	// I'd get rid of it, but I don't know why it was here to begin with.
	//this.gWinCal.document.open();

    if (this.displaytype == 'popup') {
	    this.wwrite('<html><head>');
	    this.wwrite('<title>Calendar</title>');
	    this.wwrite('<style type="text/css">');
	    this.wwrite('<!--');

	    this.wwrite('.calBody {}');

	    this.wwrite('.calInputTable {width: 100%; border: solid 1px; margin-bottom: 10px; }');
	    this.wwrite('.calInputRow {vertical-align: middle; }');
	    this.wwrite('.calInputCell {text-align: center; white-space: nowrap;}');
	    this.wwrite('.calNavLink {}');
	    this.wwrite('.calNavImage {vertical-align: middle; border: none; }');
	    this.wwrite('.calMonthChoice {vertical-align: middle; }');
	    this.wwrite('.calYearChoice {vertical-align: middle; }');

	    this.wwrite('.calMonthTable {width: 100%; border: solid 1px; }');
	    this.wwrite('.calHeaderRow {font-weight: bold; font-size: 9pt; font-family: Verdana, Arial, helvetica; }');
	    this.wwrite('.calHeaderCell {text-align: center; }');
	    this.wwrite('.calWeekRow {font-size: 9pt; font-family: Verdana, Arial, helvetica; }');
	    this.wwrite('.calWeekdayCell {cursor: pointer; width: 14%; text-align: right; background-color: white; }');
	    this.wwrite('.calWeekendCell {cursor: pointer; width: 14%; text-align: right; background-color: lightgrey; }');
	    this.wwrite('.calCurrentCell {width: 14%; text-align: right; background-color: lightblue; }');
	    this.wwrite('.calTodayCell {width: 14%; text-align: right; border: solid 1px red; }');
	    this.wwrite('.calEmptyCell {width: 14%; text-align: right; }');

	    this.wwrite('-->');
	    this.wwrite('</style>');
    }
    
	tempwrite = '<script type="text/javascript">' +
	'<!--';
	    
	if (this.displaytype == 'popup') {
	    tempwrite = tempwrite + 'function returnValue(sValue) {' +
	    '  self.opener.document.getElementById("' + this.gReturnItem + '").value = sValue;' +
	    '  if (self.opener.document.getElementById("' + this.gReturnItem + '").onchange)' +
	    '    self.opener.document.getElementById("' + this.gReturnItem + '").onchange();' +
	    '  window.close();' +
	    '}';
    }

	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? '0' + vMonth : vMonth;
	var vY4 = new String(this.gYear);

	this.wwrite(tempwrite + 'function returnDay(nDay) {' +
	'  var vDD = (nDay.toString().length < 2) ? "0" + nDay : nDay;' +
	'  returnValue("' + vMonth + '/" + vDD + "/' + vY4 + '")' +
	'}' +
	'//-->' +
	'</script>');
		
    if (this.displaytype == 'popup') {
	    this.wwrite('</head>');
	    this.wwrite('<body style="calBody">');
	}
	
	// Calculate previous month
	var prevMM = (this.gMonth + 11) % 12;
	var prevYYYY = this.gYear;
	if (this.gMonth == 0) prevYYYY--;

	// Calculate next month
	
	var nextMM = (this.gMonth + 1) % 12;
	var nextYYYY = this.gYear;
	if (this.gMonth == 11) nextYYYY++;

    


	if (this.numcalstoshow == 2 || this.numcalstoshow == 3) {
        //no input table
   }else{

	tempwrite = '<table class="calInputTable">';
	tempwrite += '<tr class="calInputRow">';
	tempwrite += '<td class="calInputCell">';

	// Make a previous month link
	tempwrite += this.buildLinkText(prevMM, prevYYYY, true, true);

	// Make a month drop-down
	tempwrite += '<select class="calMonthChoice" onchange="' + this.buildCallText('this.value', '\'' + this.gYear + '\'') + '">';
	for (monthNo = 0; monthNo < 12; monthNo++) {
		tempwrite +=  '<option value="' + monthNo + '"';
		if (monthNo == this.gMonth)
			tempwrite += ' selected="selected"';
		tempwrite +=  '>' + this.monthName(monthNo) + '</option>';
	}
	tempwrite += '</select>';

	// Make a next month link
	tempwrite += this.buildLinkText(nextMM, nextYYYY, false, true);

	tempwrite += '</td><td class="calInputCell">';

	// Make a previous year link
	tempwrite += this.buildLinkText(this.gMonth, (parseInt(this.gYear)-1), true, false);

	// Make a year text field
	tempwrite += '<input type="text" class="calYearChoice" value="' + this.gYear + '" size="4" onchange="' + this.buildCallText('\'' + this.gMonth + '\'', 'this.value') + '"/>';

	// Make a next year link
	tempwrite += this.buildLinkText(this.gMonth, (parseInt(this.gYear)+1), false, false);

	this.wwrite(tempwrite += "</td></tr></table>");

    tempwrite = '';
    }

	// Get the complete calendar code for the month..
	this.wwrite(this.getMonthlyCalendarCode(0));
	
	// Get the complete calendar code for the extra calendar displays (if necessary)
	if (this.numcalstoshow != undefined && this.numcalstoshow != null && this.numcalstoshow > 1){
	    var x;
	    original_gMonth = this.gMonth;
	    original_gYear = this.gYear;
	    for (x=1; x<this.numcalstoshow; x++){
	        if (this.gMonth == 11) this.gYear++;
	        this.gMonth = (this.gMonth + 1) % 12;
	        	        
	        this.wwrite(this.getMonthlyCalendarCode(x));
	    }
	    this.gMonth = original_gMonth;
	    this.gYear = original_gYear;
	}
	

    if (this.displaytype == 'popup') {
	    this.wwrite("</body></html>");  
	}
    this.gWinCal.document.close();
	
}

Calendar.prototype.wwrite = function(wtext) {
    if (this.displaytype == 'popup') {
	    this.gWinCal.document.writeln(wtext);
	}
	if (this.displaytype == 'div' || this.displaytype == 'inline') {
	    //alert($(this.pre_text + 'calendardiv'));
	    $(this.pre_text + 'calendardiv').insert(wtext);
	}
}

Calendar.prototype.cal_header = function(curcal) {
    var vCode = '';

    // Calculate previous month
    var prevMM = (this.gMonth + 11) % 12;
    var prevYYYY = this.gYear;
    if (this.gMonth == 0) prevYYYY--;

    // Calculate next month

    var nextMM = (this.gMonth + 1) % 12;
    var nextYYYY = this.gYear;
    if (this.gMonth == 11) nextYYYY++;

    if (this.numcalstoshow > 1) {
        vCode += '<tr class="calHeaderRow_mn_yr">' +
		'<td colspan="7" class="calHeaderCell_mn_yr">';

        //show prev
        if (curcal == 0) {
            vCode += '<div class="goback">' + this.buildLinkText(prevMM, prevYYYY, true, true) + '</div>';
        }

        if (this.numcalstoshow == 2) {
            if (curcal == 0) {
                vCode += '<div class="prevmonth">' + this.monthName(this.gMonth) + ' ' + this.gYear + '</div>';
            } else {
                vCode += '<div class="nextmonth">' + this.monthName(this.gMonth) + ' ' + this.gYear + '</div>';
            }
        } else {
            vCode += this.monthName(this.gMonth) + ' ' + this.gYear;
        }


        //show next
        if (curcal == (this.numcalstoshow - 1)) {
            //vCode += '<div class="gonext">' + this.buildLinkText(nextMM, nextYYYY, false, true) + '</div>';

            if (this.numcalstoshow == 3) {
                var cmonth = this.gMonth - 1;
                var cyear = this.gYear;
                if (cmonth == -1) {
                    cmonth = 11;
                    cyear--;
                }
                vCode += '<div class="gonext">' + this.buildLinkText(cmonth, cyear, false, true) + '</div>';
            } else {
                vCode += '<div class="gonext">' + this.buildLinkText(this.gMonth, this.gYear, false, true) + '</div>';
            }

        }

        vCode += '</td>' +
		'</tr>';
    }

    vCode += '<tr class="calHeaderRow">' +
		'<td class="calHeaderCell">Sun</td>' +
		'<td class="calHeaderCell">Mon</td>' +
		'<td class="calHeaderCell">Tue</td>' +
		'<td class="calHeaderCell">Wed</td>' +
		'<td class="calHeaderCell">Thu</td>' +
		'<td class="calHeaderCell">Fri</td>' +
		'<td class="calHeaderCell">Sat</td>' +
		'</tr>';
    return vCode;
}

Calendar.prototype.cal_data = function() {

    // Start with the day of the month being negative.
    var vDate = new Date();
    vDate.setDate(1);
    vDate.setMonth(this.gMonth);
    vDate.setFullYear(this.gYear);
    var nDayOfMonth = 1 - vDate.getDay();

    

    var nLastDayOfMonth = this.daysInMonth(this.gMonth, this.gYear);
    var sCode = "";

    var numweeks = 0;
    while (nDayOfMonth <= nLastDayOfMonth) {
        numweeks++;
        // Write a week at a time.
        sCode += '<tr class="calWeekRow">';
        for (dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
            if ((nDayOfMonth >= 1) && (nDayOfMonth <= nLastDayOfMonth))
            // If the day of the month is between 1 and the end of the month, write it normally
                sCode += this.dayCell(nDayOfMonth, dayOfWeek);
            else
            // Otherwise, write a blank cell
                sCode += '<td class="calEmptyCell"></td>';
            nDayOfMonth++;
        }
        sCode += '</tr>';

    }
    var x;
    for (x = numweeks; x < 6; x++) {
        sCode += '<tr class="calWeekRow">';
        for (dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
            sCode += '<td class="calEmptyCell"></td>';
        }
        sCode += '</tr>';
    }

    return sCode;
}

Calendar.prototype.findDayInArray = function(day) {
  if (this.activedatearray != null){
    var x; var xdate;
    for (x=0; x < this.activedatearray.length; x++) {
        xdate = new Date();
        xdate.setFullYear('20'+this.activedatearray[x][2],(this.activedatearray[x][0])-1,this.activedatearray[x][1]);
	      
        if (day == xdate.getDate() && this.gMonth == xdate.getMonth() && this.gYear == xdate.getFullYear())
            return x;
    }
    return -1;
  }else{
    return -1;
  }
}

Calendar.prototype.dayCell = function(day, dayOfWeek) {
    /*if (this.suppress_day_a_refs != null && this.suppress_day_a_refs != undefined) {
        if (this.suppress_day_a_refs.constructor.toString().indexOf("Array") == -1){
            return (
		        '<td class="' + this.cellClassName(dayOfWeek, day) + '" >' +  
		        day + 
		        '</td>'
	        )
	    }else{
	        //we need to check the date and put in a href..
	        var x = this.findDayInArray(day);
	        
	        if (x!=-1 && this.suppress_day_a_refs[x]!='') {
	            return (
		            '<td class="' + this.cellClassName(dayOfWeek, day) + ' calCallHand" ' +  
		            'onClick="window.location.href=\'' + this.suppress_day_a_refs[x] + '\';">' + 
		            day + 
		            '</td>'
	            )
	        }else{
	            return (
		            '<td class="' + this.cellClassName(dayOfWeek, day) + '" >' +  
		            day + 
		            '</td>'
	            )
	        }
	    }
    }else{*/
	    /*return (
		    '<td class="' + this.cellClassName(dayOfWeek, day) + ' calCallHand" ' + 
		    'onClick="returnDay(\'' + day + '\');">' + 
		    day + 
		    '</td>'
	    )*/
	    var vMonth = 1 + this.gMonth;
        vMonth = (vMonth.toString().length < 2) ? '0' + vMonth : vMonth;
        var vY4 = new String(this.gYear);
	
	    return (
		    '<td class="' + this.cellClassName(dayOfWeek, day, vMonth) + ' calCallHand" ' + 
		    'onClick="processDayChoice(\'' + day + '\',\'' + vMonth + '\',\'' + vY4 + '\',\'' + this.gReturnItem + '\', this);">' + 
		    day + 
		    '</td>'
	    )
	    
	    
	//}
}

Calendar.prototype.cellClassName = function(dayOfWeek, day, vmonth) {

    var sClassName = "";

    // Return special formatting for the weekend day.
    if ((dayOfWeek == 0) || (dayOfWeek == 6))
        sClassName = "calWeekendCell";
    else
        sClassName = "calWeekdayCell";

    // Special formatting for today
    if (day == this.gNowDay && this.gMonth == this.gNowMonth && this.gYear == this.gNowYear)
        sClassName += " calTodayCell";

    // Special formatting for the starting date
    if (day == this.gStartDay && this.gMonth == this.gStartMonth && this.gYear == this.gStartYear)
        sClassName += " calCurrentCell";

    // Special formatting for the currently displayed dates
    /*if (this.activedatearray != null){
    var x; var xdate;
    for (x=0; x < this.activedatearray.length; x++) {
    xdate = new Date();
    xdate.setFullYear('20'+this.activedatearray[x][2],(this.activedatearray[x][0])-1,this.activedatearray[x][1]);
    	      
    if (day == xdate.getDate() && this.gMonth == xdate.getMonth() && this.gYear == xdate.getFullYear())
    sClassName += " calEventCell";
    }
    }*/


    if (this.numcalstoshow == 2) {

        if (session_dateChoice2 != '') {
            var curSavedDate1 = this.stringToDate(session_dateChoice1);

            var curSavedDate2 = this.stringToDate(session_dateChoice2);

            var curCellDate = this.stringToDate((this.gMonth + 1) + '/' + day + '/' + this.gYear);
            if (curCellDate >= curSavedDate1 && curCellDate <= curSavedDate2) {
                sClassName += " calCurrentSelectedCell";
            }
        } else {
            if (session_dateChoice1 != '') {
                var curSavedDate = this.stringToDate(session_dateChoice1);
                if (day == curSavedDate.getDate() && this.gMonth == curSavedDate.getMonth() && this.gYear == curSavedDate.getFullYear()) {
                    sClassName += " calCurrentSelectedCell";
                }
            }
        }
    }

    if (this.numcalstoshow == 3) {
        var x;
        //var curCellDate = this.stringToDate(vmonth + '/' + day + '/' + this.gYear);
        for (x = 0; x < multiDateEventArray.length; x++) {
            var curSavedDate = this.stringToDate(multiDateEventArray[x]);
            if (day == curSavedDate.getDate() && (vmonth-1) == curSavedDate.getMonth() && this.gYear == curSavedDate.getFullYear()) {
                            
                sClassName += " calCurrentSelectedCell";
            }
        }
    }


    return sClassName;
}

Calendar.prototype.stringToDate = function(sDate) {

	// Replace dots or dashes with slashes
	var tempDate = sDate.replace(/[\.\-]/g, '/');

	var aDate = new Date(tempDate);

	// Special test for Safari
	if (aDate.valueOf() == -2147483648000) {
		// Strip off any time (stuff after a space) and try again.
		// Most Javascript engines can handle time, but Safari does not.
		// This will cause problems with "Oct 10, 2005"
		if (tempDate.indexOf(' ') > -1) {
			tempDate = tempDate.substring(0, tempDate.indexOf(' '));
		}
		aDate = new Date(tempDate);
	}

	// if this is a date, return it, 
	if (aDate.getDate()) {
		return this.sanifyDate(aDate);
	}

	// Otherwise, try to add the current year.
	var now = new Date();
	aDate = new Date(tempDate + '/' + now.getFullYear());
	if (aDate.getDate()) {
		return this.sanifyDate(aDate);
	} else {
		return null;
	}
}

Calendar.prototype.sanifyDate = function(aDate) {
	var tempDate = aDate;
	var year = tempDate.getFullYear();
	if (Math.max(year, 50) == 50) year += 2000;
	if (Math.max(year, 100) == 100) year += 1900;
	tempDate.setFullYear(year);
	return (tempDate);
}


function processDayChoice(sDay, sMon, sYr, Elmt, tdElmt) {
	var vDD = (sDay.toString().length < 2) ? "0" + sDay : sDay;
	
	if (Elmt == 'edate') {
	
	    if (session_dateChoice1 != '' && session_dateChoice2 != '') {
	        session_dateChoice2 = '';
	        session_dateChoice1 = sMon + '/' + vDD + '/' + sYr;
	        show_calendar(Elmt, null, cal.gMonth, cal.gYear, 'actualeventcal_', 'inline', 'calendardateholder', Array(), 2, Array());
	        return;
	    }


	    Element.addClassName(tdElmt, 'calCurrentSelectedCell');

	    if (session_dateChoice1 == '') {
	        session_dateChoice1 = sMon + '/' + vDD + '/' + sYr;
	        //$(Elmt).value = session_dateChoice1;
	    } else {

	        session_dateChoice2 = sMon + '/' + vDD + '/' + sYr;

	        if (cal.stringToDate(session_dateChoice1) > cal.stringToDate(session_dateChoice2)) {
	            tempd = session_dateChoice1;
	            session_dateChoice1 = session_dateChoice2;
	            session_dateChoice2 = tempd;
	        }
	        //---- redraw - color td's
	        //cal.show();
	        show_calendar('edate', null, cal.gMonth, cal.gYear, 'actualeventcal_', 'inline', 'calendardateholder', Array(), 2, Array());

	        //$(Elmt).value = session_dateChoice1 + '-' + session_dateChoice2;
	        //hideCalendar();
	    }
	} else {
	    if (Element.hasClassName(tdElmt, 'calCurrentSelectedCell')) {
	        Element.removeClassName(tdElmt, 'calCurrentSelectedCell');
	        multiDateEventArray.pop(sMon + '/' + vDD + '/' + sYr);
	    } else {
	        Element.addClassName(tdElmt, 'calCurrentSelectedCell');
	        multiDateEventArray.push(sMon + '/' + vDD + '/' + sYr);
	    }
	} 
   }

   function populateFieldWithDayChoices(Elmt) {
   	if (session_dateChoice1 == '') {

   	} else {
   		if (session_dateChoice2 == '') {
   			var vd1 = cal.stringToDate(session_dateChoice1);
   			var vyr = new String(vd1.getFullYear().toString());
   			$(Elmt).value = (vd1.getMonth() + 1) + '/' + vd1.getDate() + '/' + vyr.substring(2, 4);
   		} else {
   		var vd1 = cal.stringToDate(session_dateChoice1);
   		var vyr1 = new String(vd1.getFullYear().toString());
   		var vd2 = cal.stringToDate(session_dateChoice2);
   		var vyr2 = new String(vd2.getFullYear().toString());
   		$(Elmt).value = (vd1.getMonth() + 1) + '/' + vd1.getDate() + '/' + vyr1.substring(2, 4) + '-' + (vd2.getMonth() + 1) + '/' + vd2.getDate() + '/' + vyr2.substring(2, 4);
   		}
   	}
   	hideCalendar();
   }




