//<!--
function MM_setTextOfLayer(objName,x,newText) { //v3.0
	var obj=MM_findObj(objName);
	obj.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 = 'common/calendar.html?&format='+format+'&element=' + element;
	var setings = "width=300,height=200,top="+ top + ",left="+ left;
	window.open(url,'mywindow', setings);
}

function showCalendar(format, element, form, id, width, height) {
	var url = 'common/calendar.html?&format='+format+'&element=' + element+'&id=' + id+'&form=' +form;
	var div = document.getElementById(id);
	if (div) {
		div.innerHTML='<iframe src="'+url+'" frameborder="no" border="0" scrolling="no" style="width:'+width+'px; height:'+height+'px"></iframe>';
		if (div.style.display == 'none') {
			div.style.display = 'block';
			div.style.visibility = 'visible';
		} else {
			div.style.display = 'none';
			div.style.visibility = 'hidden';
		}
	}
}

function findMyIndex(n) {
	var i;
	var e = document.getElementById(n);
	for (i=0; i<e.form.elements.length; i++) {
		 if (e.form.elements[i].id == e.id) return i;
	}
	return -1;
}

function findFormIndex(formChildElementID) {
	var i;
	var form = document.getElementById(formChildElementID).form;
	for (i=0; i< document.forms.length; i++) {
		if (document.forms[i] == form) 	return i;
	}
	return -1;
}


function hideCalendar(id) {
	var div = document.getElementById(id);
	if (div) {
		with (div.style) {
			display = 'none';
			visibility = 'hidden';
		}
	}
}

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

function updateParent(format, day, month, year, element,form) {
	var date = formatDate(format, day, month, year, 0, 0);
	if (typeof(opener)=='undefined' || parent) opener=parent;
	opener.document.forms[form].elements[element].value=date[0];
	opener.document.forms[form].elements[element].defaultValue=date[0];
	
	if (opener.document.forms[form].elements[element].onchange)
	  opener.document.forms[form].elements[element].onchange();
	if (parent) {
		with (parent.document.getElementById(urlParameters['id']).style) {
			display = 'none';
			visibility = 'hidden';
		}
	} else window.close();
}

function getCalendar(onload) {
var chosenDate, chosenDay, chosenMonth, chosenYear;

	element = urlParameters['element'];
	form = urlParameters['form'];
	format = urlParameters['format'];
	if (!isNaN(element)) element = Number(element);

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

	chosenMonth = thisMonth;
	chosenYear  = thisYear;

	if (typeof(opener)=='undefined' || parent) opener=parent;
	var initialDate = opener.document.forms[form].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='';
	var firstDay = new Date(chosenYear,chosenMonth,1);
    var startDay = firstDay.getDay();
		startDay = (startDay == 0 ? 7 : startDay)-1;
	
	output += "<TABLE BORDER='0' cellspacing='3' cellpadding='3' class='calendar-pop-up'><tr bgcolor='#CCCCCC'>";
    for(i=0; i<7; i++)
		output += "<TH WIDTH=20 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=20 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=20 HEIGHT=20 onclick='mouseClick(this)'>" ;
			output += "<A HREF=\"javascript:updateParent('"+format+"',"+i+",'"+currentMonth+"','"+chosenYear+"','"+element+"','"+form+"')\">"+i+"</A><\/TH>";
	   		}
        else {
        	output += "<TD WIDTH=20 HEIGHT=20 class='rowHilight' onmouseover='mouseOver(this)' onmouseout='mouseOut(this)' onclick='mouseClick(this)'>" ;
			output += "<A HREF=\"javascript:updateParent('"+format+"',"+i+",'"+currentMonth+"','"+chosenYear+"','"+element+"','"+form+"')\">"+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=20 HEIGHT=20><\/TD>";
          	column++;
       		}
    output += "<\/TR></TABLE>";
	return output;
};

//-->