var curLink = null;
var curRow = null;
var scrollRow = null;
var workingTimer = null;

function clearFilter(frm) {
	for (i=0;i<frm.length;i++) {
		f = frm[i];
		if (f.type == 'text') {
			f.value = '';
		}
		if (f.options) {
			f.options[0].selected = true;
		}
		if (frm.FilterOption) {
			frm.FilterOption[0].checked = true;
		}
		if (frm.FilterOptionA && frm.FilterOptionA.type != 'hidden') {
			frm.FilterOptionA[0].checked = true;
		}
		if (frm.FilterOptionB && frm.FilterOptionB.type != 'hidden') {
			frm.FilterOptionB[0].checked = true;
		}
		if (frm.FilterOptionC && frm.FilterOptionC.type != 'hidden') {
			frm.FilterOptionC[0].checked = true;
		}
		if (frm.FilterOptionD && frm.FilterOptionD.type != 'hidden') {
			frm.FilterOptionD[0].checked = true;
		}
		if (frm.FilterOptionE && frm.FilterOptionE.type != 'hidden') {
			frm.FilterOptionE[0].checked = true;
		}
		if (frm.FilterOptionF && frm.FilterOptionF.type != 'hidden') {
			frm.FilterOptionF[0].checked = true;
		}
		if (frm.FilterOptionG && frm.FilterOptionG.type != 'hidden') {
			frm.FilterOptionG[0].checked = true;
		}
		if (frm.FilterLastPrintDate && frm.FilterLastPrintDate.type != 'hidden') {
			frm.FilterLastPrintDate[0].checked = true;
		}
		if (frm.FilterMoveNum && frm.FilterMoveNum.type != 'hidden') {
			frm.FilterMoveNum[0].checked = true;
		}
		if (frm.FilterMoveExpireDate && frm.FilterMoveExpireDate.type != 'hidden') {
			frm.FilterMoveExpireDate[0].checked = true;
		}
		if (frm.FilterHoldExpireDate && frm.FilterHoldExpireDate.type != 'hidden') {
			frm.FilterHoldExpireDate[0].checked = true;
		}
		if (frm.FilterDisciplineType && frm.FilterDisciplineType.type != 'hidden') {
			frm.FilterDisciplineType[0].checked = true;
		}
		if (frm.FilterDisciplineNum && frm.FilterDisciplineNum.type != 'hidden') {
			frm.FilterDisciplineNum[0].checked = true;
		}
		if (frm.FilterDisciplineExpireDate && frm.FilterDisciplineExpireDate.type != 'hidden') {
			frm.FilterDisciplineExpireDate[0].checked = true;
		}
		if (frm.FilterCommType && frm.FilterCommType.type != 'hidden') {
			frm.FilterCommType[0].checked = true;
		}
		if (frm.FilterCommStatus && frm.FilterCommStatus.type != 'hidden') {
			frm.FilterCommStatus[0].checked = true;
		}
		if (frm.FilterCommNum && frm.FilterCommNum.type != 'hidden') {
			frm.FilterCommNum[0].checked = true;
		}
		if (frm.FilterCommFollowUpDate && frm.FilterCommFollowUpDate.type != 'hidden') {
			frm.FilterCommFollowUpDate[0].checked = true;
		}
	}
	expireRowCookie();
	frm.RowNum.value = '';
	frm.PageNum.value = '';
	//frm.action = '';
	frm.submit();
	pageWait();
}

function gotoPage(p) {
	if (document.frmFilter.RowNum) {
		expireRowCookie();
		document.frmFilter.RowNum.value = '';
		document.frmFilter.PageNum.value = p;
		document.frmFilter.submit();
		pageWait();
	}
}

function hiliteRow(i,b) {
	if (document.getElementById) {
		r = document.getElementById(i);
		if (r) {
			var c = r.className;
			if (b == true) {
				rExp = /ReportRow/gi;
				newC = c.replace(rExp,'ReportRowHilite');
				r.className = newC;
				//r.className = 'ReportRowHilite';
			}
			else {
				rExp = /ReportRowHilite/gi;
				newC = c.replace(rExp,'ReportRow');
				r.className = newC;
				//r.className = 'ReportRow';
			}
		}
		rDetail = document.getElementById(i + 'Detail');
		if (rDetail) {
			var cDetail = rDetail.className;
			if (b == true) {
				rExp = /ReportRow/gi;
				newC = cDetail.replace(rExp,'ReportRowHilite');
				rDetail.className = newC;
				//rDetail.className = 'ReportRowHilite';
			}
			else {
				rExp = /ReportRowHilite/gi;
				newC = cDetail.replace(rExp,'ReportRow');
				rDetail.className = newC;
				//rDetail.className = 'ReportRow';
			}
		}
	}
}

function hiliteDetailsCell(o,b) {
	var c = o.className;
	if (b == true) {
		rExp = /DetailsCell/gi;
		newC = c.replace(rExp,'DetailsCellHilite');
		o.className = newC;
	}
	else {
		rExp = /DetailsCellHilite/gi;
		newC = c.replace(rExp,'DetailsCell');
		o.className = newC;
	}
}

function rowClick(i) {
	if (document.getElementById) {
		el = document.getElementById(i + 'ShowDetailsCell');
		if (el) {
			toggleDetails(el,i);
		}
	}
}

function toggleDetails(o,i) {
	clearTimeout(scrollRow);
	curRow = i;
	var c = o.className;
	if (document.getElementById) {
		rHidden = document.getElementById(i + 'Hidden');
		topBtn = document.getElementById('ShowAllDetailsTop');
		botBtn = document.getElementById('ShowAllDetailsBottom');
		if (rHidden) {
			if (rHidden.className == 'VisibleDetails') {
				collapseSnippet(i);
				rHidden.className = 'HiddenDetails';
				rExp = /HideDetailsCell/gi;
				newC = c.replace(rExp,'ShowDetailsCell');
				o.className = newC;
				if (topBtn) {
					topBtn.className = 'ShowDetailsCell';
				}
				if (botBtn) {
					botBtn.className = 'ShowDetailsCell';
				}
				expireRowCookie();
			}
			else {
				rHidden.className = 'VisibleDetails';
				rExp = /ShowDetailsCell/gi;
				newC = c.replace(rExp,'HideDetailsCell');
				o.className = newC;
				if (topBtn) {
					topBtn.className = 'HideDetailsCell';
				}
				if (botBtn) {
					botBtn.className = 'HideDetailsCell';
				}
				closePrevRow(i);
				expandSnippet(i);
				//h = xHeight(o) + xHeight(rHidden);
				//scrollRow = setTimeout('scrollToElement()', 100);
				//fitHiddenDetails(i);
				scrollToElement(o);
			}
			if (!window.opener) {
				resizeLayout();
			}
			clearCurrentButton();
		}
	}
}

function scrollToElement(el) {
	if (el) {
		posEl = xPageY(el);
		if (posEl >= (viewportHeight * (3/5))) {
			ws = xScrollTop();
			elContent = document.getElementById('content');
			elSidebar = document.getElementById('sidebar');
			if (isChild(el, elContent)) {
				cs = xScrollY(elContent)
				sY = posEl + cs - ws;
				elContent.scrollTop = sY;
			}
			else if (isChild(el, elSidebar)) {
				cs = xScrollY(elSidebar)
				sY = posEl + cs - ws;
				elSidebar.scrollTop = sY;
			}
			else {
				sY = posEl - ws;
				window.scrollBy(0,sY);
			}
		}
	}
}

function fitHiddenDetails(i) {
	return;
	if (document.getElementById) {
		rHidden = document.getElementById(i + 'Hidden');
		if (rHidden) {
			rInner = rHidden.childNodes[0];
			if (rInner) {
				hHidden = 200;
				xHeight(rHidden, hHidden);
				hInner = xHeight(rInner);
				if (hInner > hHidden) {
					wHidden = xWidth(rHidden);
					xWidth(rInner, wHidden - 140);
				}
				else {
					xHeight(rHidden, hInner + 2);
				}
			}
		}
	}
}

function toggleAllDetails(o) {
	var c = o.className;
	//alert(c);
	if (document.getElementById) {
		topBtn = document.getElementById('ShowAllDetailsTop');
		botBtn = document.getElementById('ShowAllDetailsBottom');
		if (document.frmReport) {
			if (document.frmReport.FirstRowNum) {
				rowA = document.frmReport.FirstRowNum.value;
			}
			if (document.frmReport.LastRowNum) {
				rowZ = document.frmReport.LastRowNum.value;
			}
			if (rowA != '' && rowZ != '') {
				rowA = parseFloat(rowA);
				rowZ = parseFloat(rowZ);
				for (i=rowA;i<=rowZ;i++) {
					rHidden = document.getElementById(i + 'Hidden');
					if (rHidden) {
						if (c == 'HideDetailsCell' || c == 'HideDetailsCellHilite') {
							collapseSnippet(i);
							rHidden.className = 'HiddenDetails';
							el = document.getElementById(i + 'ShowDetailsCell');
							if (el) {
								oldC = el.className;
								rExp = /HideDetailsCell/gi;
								newC = oldC.replace(rExp,'ShowDetailsCell');
								el.className = newC;
							}
						}
						else {
							rHidden.className = 'VisibleDetails';
							el = document.getElementById(i + 'ShowDetailsCell');
							if (el) {
								oldC = el.className;
								rExp = /ShowDetailsCell/gi;
								newC = oldC.replace(rExp,'HideDetailsCell');
								el.className = newC;
							}
							expandSnippet(i);
						}
					}
				}
				if (c == 'HideDetailsCell' || c == 'HideDetailsCellHilite') {
					if (topBtn) {
						topBtn.className = 'ShowDetailsCell';
					}
					if (botBtn) {
						botBtn.className = 'ShowDetailsCell';
					}
				}
				else {
					if (topBtn) {
						topBtn.className = 'HideDetailsCell';
					}
					if (botBtn) {
						botBtn.className = 'HideDetailsCell';
					}
					o.className = 'HideDetailsCell';
				}
				if (!window.opener) {
					resizeLayout();
				}
				clearCurrentButton();
			}
		}
	}
}

function closePrevRow(i) {
	if (document.getElementById) {
		if (document.frmFilter) {
			if (document.frmFilter.RowNum) {
				if (document.frmFilter.RowNum.value != '') {
					var iPrev = parseInt(document.frmFilter.RowNum.value);
					if (iPrev != i) {
						rHidden = document.getElementById(iPrev + 'Hidden');
						if (rHidden) {
							rHidden.className = 'HiddenDetails';
							o = document.getElementById(iPrev + 'ShowDetailsCell');
							if (o) {
								collapseSnippet(iPrev);
								var c = o.className;
								rExp = /HideDetailsCell/gi;
								newC = c.replace(rExp,'ShowDetailsCell');
								o.className = newC;
							}
						}
					}
				}
				document.frmFilter.RowNum.value = i;
				setRowCookie(i);
			}
		}
	}
}

function expandSnippet(i) {
	if (document.getElementById) {
		rSnippet = document.getElementById(i + 'Snippet');
		rFullText = document.getElementById(i + 'FullText');
		if (rSnippet && rFullText) {
			rSnippet.className = 'rptRowHideSnippet';
			rFullText.className = 'rptRowShowFullText';
		}
	}
}

function collapseSnippet(i) {
	if (document.getElementById) {
		rSnippet = document.getElementById(i + 'Snippet');
		rFullText = document.getElementById(i + 'FullText');
		if (rSnippet && rFullText) {
			rFullText.className = 'rptRowHideFullText';
			rSnippet.className = 'rptRowShowSnippet';
		}
	}
}

function hiliteSibling(i,b) {
	if (document.getElementById) {
		el = document.getElementById(i);
		if (el) {
			if (b == true) {
				var c = el.className;
				rExp = /morePages/gi;
				newC = c.replace(rExp,'currentPage');
				rExp = /rptButtonLabel/gi;
				newC = newC.replace(rExp,'rptButtonLabelHilite');
				el.className = newC;
			}
			else {
				var c = el.className;
				rExp = /currentPage/gi;
				newC = c.replace(rExp,'morePages');
				rExp = /rptButtonLabelHilite/gi;
				newC = newC.replace(rExp,'rptButtonLabel');
				el.className = newC;
			}
		}
	}
}

function popWordSearch(w1,w2) {
	var url='http://www.google.com/search?q=';
	if (w1 != '') {
		url = url + w1;
	}
	if (w1 != '' && w2 != '') {
		url = url + '+';
	}
	if (w2 != '') {
		url = url + w2;
	}
	w = viewportWidth - 100;
	if (w < 400) { w = 400; }
	h = viewportHeight - 100;
	popWinStatusBar(url, 'wordSearch', w, h, 'yes', 'center');
}

function setCurrentButton() {
	if (curLink != null) {
		if (document.getElementById) {
			o = document.getElementById(curLink + 'Button');
			var c = o.className;
			rExp = /morePages/gi;
			newC = c.replace(rExp,'hilitePage');
			rExp = /currentPage/gi;
			newC = newC.replace(rExp,'hilitePage');
			o.className = newC;
		}
	}
}

function clearCurrentButton() {
	if (curLink != null) {
		if (document.getElementById) {
			temp = curLink;
			curLink = null;
			o = document.getElementById(temp + 'TooltipMsg');
			if (o) {
				if (o.innerHTML == '') {
					tt = document.getElementById('ttContainer');
					o.innerHTML = tt.innerHTML;
				}
			}
			else {
				o = document.getElementById('TooltipSharedMsg');
				if (o) {
					if (o.innerHTML == '') {
						tt = document.getElementById('ttContainer');
						o.innerHTML = tt.innerHTML;
					}
				}
			}
			clearTimeout(ttTimer);
			resetTooltip();
			o = document.getElementById(temp + 'Button');
			if (o) {
				var c = o.className;
				rExp = /hilitePage/gi;
				newC = c.replace(rExp,'morePages');
				o.className = newC;
			}
		}
	}
}

function printMatchingReport() {
	setSelectionsThisPage();
	document.frmFilter.action = 'reportPDF.asp';
	//document.frmFilter.target = '_blank';
	document.frmFilter.submit();
	document.frmFilter.action = document.location;
}

function printMatchingXLS() {
	setSelectionsThisPage();
	document.frmFilter.action = 'reportXLS.asp';
	//document.frmFilter.target = '_blank';
	document.frmFilter.submit();
	document.frmFilter.action = document.location;
}

function printLetters(i) {
	setSelectionsThisPage();
	document.frmFilter.action = 'letterPDF.asp?i=' + i;
	//document.frmFilter.target = '_blank';
	document.frmFilter.submit();
	document.frmFilter.action = document.location;
}

reopenLastRow = function() {
	if (window.opener) {
		return;
	}
	if (document.getElementById) {
		r = getRowCookie();
		if (r != null) {
			o = document.getElementById(r);
			if (o) {
				toggleDetails(o,r);
			}
		}
	}
}

clearLastRow = function() {
	if (window.opener) {
		expireRowCookie();
	}
}

addLoadEvent(reopenLastRow);
addUnloadEvent(clearLastRow);


