//*******************************************************************
/* These functions have to do with making the historical data table
	...presentable in any width.  The table is going to be at least
	...500 pixels wide, regardles. */
//********************************************************************

function doTitleHeightResize() {
	var i;
	var maxTitleHeight = 0;
	var hT = document.all['historyTitle']
	for (i=0;i<hT.length;i++)
		if (hT[i].offsetHeight > maxTitleHeight)
			maxTitleHeight = hT[i].offsetHeight;
	
	for (i=0;i<hT.length;i++)
		hT[i].style.height = maxTitleHeight;
		
	document.all['historyTitleCap'].style.height = maxTitleHeight;
}

function findMaxDateWidth() {
	var i;
	var hDC = document.all['historicalDateCell'];
	var maxDateWidth = 0;
	
	for (i=0;i<hDC.length;i++)
		if (hDC[i].offsetWidth > maxDateWidth)
			maxDateWidth = hDC[i].offsetWidth;
			
	doDateWidthResize(hDC, maxDateWidth);
	doTitleWidthResize(maxDateWidth);
}

function doDateWidthResize(dcObj, w) {
	var i;
	for (i=0;i<dcObj.length;i++) {
		dcObj[i].style.width = w;
	}
}

function doTitleWidthResize(w) {
	var i;
	var accumWidth = w;
	var hT = document.all['historyTitle'];
	var hDT = document.all['dataTable'];
	var finalTotalWidth = hDT.offsetWidth - w - 17;
	var finalCellWidth = Math.ceil((finalTotalWidth / (hT.length - 1)) - 0.5)
	
	hT[0].style.width = w;
	
	for (i=1;i<hT.length;i++) {
		hT[i].style.width = finalCellWidth;
		accumWidth += finalCellWidth;
	}
	
	document.all['historyTitleCap'].style.width = 17;
}

function doDataWidthResize() {
	var i;
	var currCell;
	var hT = document.all['historyTitle'];
	var hDC = document.all['historicalDataCell'];
	
	numDataRows = hDC.length / (hT.length - 1);
	
	for (i=1;i<hT.length;i++)
		for (j=0;j<numDataRows;j++) {
			currCell = getCurrentOperatingCell(j, i-1, hT.length-1);
			hDC[currCell].style.width = hT[i].offsetWidth;
		}
}

function doDataTableHeightResize() {
	var i;
	var totHeight = 0;
	var dT = document.all['dataTable'];
	var hR = document.all['historicalRow'];
	
	for (i=0;i<hR.length;i++)
		totHeight += hR[i].offsetHeight
		
	if (totHeight < dT.offsetHeight)
		dT.style.height = totHeight + 2;
}

function getCurrentOperatingCell(currRow, currCol, numDataCols) {
	return ((currRow * numDataCols) + currCol);
}

function showCalendar(ID) {
	var calendarWindow = window.open('/calendar/default.asp?id=' + ID, 'calWin', 'scrollbars=no, height=220, width=430, menubar=no, location=no, resizable=no, status=no, titlebar=no, directories=no');
}

document.onclose = function(evt) {
	alert(calendarWindow);
}

function setDates(dat, whichDate) {
	switch (whichDate) {
		case 0: 
			document.forms['dates'].elements['startDate'].value = dat;
			break;
		case 1:
			document.forms['dates'].elements['endDate'].value = dat;
			break;
	}
}

function activateForm() {
	document.forms['dates'].submit();
}	

//findMaxDateWidth();
//doTitleHeightResize();
//doDataWidthResize();
//doDataTableHeightResize();
//doTitleResize();