//<!--
var 
	IE = navigator.appName.indexOf('Microsoft') >= 0;

function MM_setTextOfLayer(objName,x,newText) { //v3.0
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (navigator.appName=='Netscape' && parseFloat(navigator.appVersion) < 5) {
		document.write(unescape(newText)); document.close();
	} else innerHTML = unescape(newText);
};

var today     = new Date();
var thisDay   = today.getDate();
var thisMonth = today.getMonth();
var thisYear  = y2k(today.getYear());

function calendarPopup(format, index, name) {
	if (name) openCalendar(format, 30, name);
	else openCalendar(format, index, index+2);
}

function openCalendar(format, row, element) {
	var top, left;
	if (format == "") {
		form = document.forms['XMLDB_SEARCH_FORM'];
		prop = PropertiesOf(form.elements[row].options[form.elements[row].selectedIndex].value);
		format = prop[pFORMAT];
	}
	if (IE) { top = screen.height/10 + 7*row; left = screen.width*0.65; }
	else { top = screen.height/8 + 8*row; left = screen.width*0.65; }

	var url = 'calendar.html?&format='+format+'&element=' + element;
	var setings = "width=300,height=200,top="+ top + ",left="+ left;
	window.open(url,'mywindow', setings);
};

function y2k(number) { return (number < 1000) ? number + 1900 : number; };

function updateParent(format, day, month, year, element) {
	var date = formatDate(format, day, month, year, 0, 0);
	opener.document.forms[0].elements[element].value=date[0];
	opener.document.forms[0].elements[element].defaultValue=date[0];
	
	if (opener.document.forms[0].elements[element].onchange)
	  opener.document.forms[0].elements[element].onchange();

	window.close();
};

function getCalendar(onload) {
var chosenDate, chosenDay, chosenMonth, chosenYear;
	element = urlParameters['element'];
	format = urlParameters['format'];
	if (!isNaN(element)) element = Number(element);

	objYear  = MM_findObj('year');
	objMonth = MM_findObj('month');

	chosenMonth = thisMonth;
	chosenYear  = thisYear;

	var initialDate = window.opener ? window.opener.document.forms[0].elements[element].value : '';
	if (chosenDate = isDate(format, initialDate)) {
		thisDay     = chosenDate[1];
		chosenMonth = chosenDate[2]-1;
		chosenYear  = chosenDate[3];
	}

	if (onload) {
		Year = Number(chosenYear);
		thisMonth = chosenMonth;
		thisYear  = chosenYear;
		objMonth.selectedIndex = chosenMonth;
	} else
		Year = Number(objYear.options[objYear.selectedIndex].value);

	for (i = 0, y = (Year - 5); y < (Year + 6); y++)
		objYear.options[i].text = objYear.options[i++].value = y;
	objYear.selectedIndex = 5;


	chosenMonth = objMonth.options[objMonth.selectedIndex].value;
	chosenYear  = objYear.options[objYear.selectedIndex].value;

	var output='';
	firstDay = new Date(chosenYear,chosenMonth,1);
    startDay = firstDay.getDay();
	output += "<TABLE BORDER=0><tr bgcolor='#009966'>";
    for(i=0; i<7; i++)
		output += "<TH WIDTH=40 HEIGHT=20>" + dow[i] + "<\/TH>";
    output += "<\/TR><TR ALIGN=CENTER VALIGN=MIDDLE>";
    if(((chosenYear % 4 == 0) && (chosenYear % 100 != 0)) || (chosenYear % 400 == 0))
		days[1] = 29;
    else
        days[1] = 28;
    var column = 0;
    var lastMonth = chosenMonth - 1;
    if(lastMonth == -1) lastMonth = 11;
    for(i=0; i<startDay; i++){
    	output += "<TD WIDTH=40 HEIGHT=20><\/TD>";
        column++;
      }
    var currentMonth = chosenMonth ;
    currentMonth++ ;
    for(i=1; i<=days[chosenMonth]; i++) {
		if((i == thisDay) && (chosenMonth == thisMonth) && (chosenYear == thisYear)) {
        	output += "<TH WIDTH=40 HEIGHT=20>" ;
			output += "<A HREF=\"javascript:updateParent('"+format+"',"+i+",'"+currentMonth+"','"+chosenYear+"','"+element+"')\">"+i+"</A><\/TH>";
	   		}
        else {
        	output += "<TD WIDTH=40 HEIGHT=20 class='rowHilight'>" ;
			output += "<A HREF=\"javascript:updateParent('"+format+"',"+i+",'"+currentMonth+"','"+chosenYear+"','"+element+"')\">"+i+"</A><\/TD>";
	   		}
        column++;
        if(column == 7) {
        	output += "<\/TR><TR ALIGN=CENTER VALIGN=MIDDLE>";
            column = 0;
        	}
      	}
    if(column > 0)
    	for (i=1; column<7; i++) {
      		output += "<TD WIDTH=40 HEIGHT=20><\/TD>";
          	column++;
       		}
    output += "<\/TR></TABLE>";
    return output;
};

//-->