// JavaScript Document
function openCalendar(form, field, type, actual) {
    window.open("./calendar.php?type=" + type + "&actual=" + actual, "calendar", "width=240,height=310,status=yes");
    dateField = eval("document." + form + "." + field);
    dateType = type;
}

function returnDate(d) {
    txt = d;
    if (window.opener.dateType != 'date') {
        // need to get time
        h = parseInt(document.getElementById('hour').value,10);
        m = parseInt(document.getElementById('minute').value,10);
        s = parseInt(document.getElementById('second').value,10);
        if (window.opener.dateType == 'datetime') {
            txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
        } else {
            // timestamp
            txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
        }
    }
//	alert(txt);
    window.opener.dateField.value = txt;
    window.close();
}

function formatNum2(i, valtype) {
    f = (i < 10 ? '0' : '') + i;
    if (valtype && valtype != '') {
        switch(valtype) {
            case 'month':
                f = (f > 12 ? 12 : f);
                break;

            case 'day':
                f = (f > 31 ? 31 : f);
                break;

            case 'hour':
                f = (f > 24 ? 24 : f);
                break;

            default:
            case 'second':
            case 'minute':
                f = (f > 59 ? 59 : f);
                break;
        }
    }

    return f;
}

function calendarLocation(first, middle, second, actual)
{
	if (middle!="") {
		var l=middle.options[middle.selectedIndex].value;
		window.location.href=first + l + second + actual;
	}
}