//////////////////////////////////////////////////////////////////////////////////////////////
// Gallery
//////////////////////////////////////////////////////////////////////////////////////////////

var CanHandleScrollEvents = document.all || document.getElementById;

function GoURL(oSelect) {
	var url = oSelect.options[oSelect.selectedIndex].value;
	if (url != "") {
		document.location = url;
	}
}
var ActiveTitle = null;
var ActiveDescription = null;

function EnlargeImage(ptr, previewSrc) {
        if (ActiveTitle != null) {
		ActiveTitle.style.display = "none";
	}	
        if (ActiveDescription != null) {
		ActiveDescription.style.display = "none";
	}
        var oPreviewDiv = getObjectById("DisplayWindow");
	var oPreviewImage = eval("document.images.PreviewImage");
	var oSrcImage = eval("document.images.Thumb" + ptr);
        ActiveTitle = getObjectById("PhotoTitle" + ptr);
	ActiveTitle.style.display = "";
	ActiveDescription = getObjectById("PhotoDescription" + ptr);
	ActiveDescription.style.display = "";
	if (oPreviewDiv != null && oPreviewImage != null) {
		if (!CanHandleScrollEvents) {
			var yPos = OffSetY(oSrcImage) - 270;
			if (yPos < 200) yPos = 200;
			SetYPosition(oPreviewDiv, yPos);
		}
		oPreviewImage.src = "/images/SYSTEM/misc/loading.gif";
		oPreviewDiv.style.visibility = "visible";
		oPreviewImage.src = previewSrc;
	}
	
	return false;
}

function HidePreview() {
	var PreviewDiv = getObjectById("DisplayWindow");
	if (PreviewDiv != null) {
		PreviewDiv.style.visibility = "hidden";
	}
	return false;
}

function HandleScroll() {
	var oPreviewDiv = getObjectById("DisplayWindow");
	var yPos = document.body.scrollTop + 30;
	if (yPos < 260) yPos = 260;
	SetYPosition(oPreviewDiv, yPos);
}

function SetYPosition(oPreviewDiv, yPos) {
	oPreviewDiv.style.top = yPos;
}

//////////////////////////////////////////////////////////////////////////////////////////////
// Calendar
//////////////////////////////////////////////////////////////////////////////////////////////

var CalendarDetailTimer = null;
var ActiveContainerDiv = null;
var ActiveDetailDiv = null;

function HiliteCalendarRow(oDiv, sID) {
	oDiv.style.background = "#ddddff";
	var yPos = OffSetY(oDiv)-70;
	var oDetailDiv = getObjectById(sID);
	ShowEventDetail(oDetailDiv, yPos);
}
function HiliteCalendarCell(oTD, sID) {
	oTD.style.textDecoration = "underline";
	var oDetailDiv = getObjectById(sID);
	ShowEventDetail(oDetailDiv, 300);
}

function UnHiliteCalendarRow(oDiv) {
	oDiv.style.background = "transparent";
	HideEventDetail();
}

function UnHiliteCalendarCell(oTD) {
	oTD.style.textDecoration = "none";
	HideEventDetail();
}

function ShowEventDetail(oDetailDiv, yPos) {
	ClearCalendarDetailTimer();
	if (ActiveContainerDiv != null) {
		ActiveContainerDiv.style.display = "none";
	}
	ActiveContainerDiv = oDetailDiv;
	ActiveContainerDiv.style.display = "";
	SetYPosition(ActiveContainerDiv, yPos);
}

function HideEventDetail() {
	CalendarDetailTimer = window.setTimeout('CloseActiveDetailDiv()', 1000);
}

function ClearCalendarDetailTimer() {
	if (CalendarDetailTimer != null) window.clearTimeout(CalendarDetailTimer);
}

function CloseActiveDetailDiv() {
	ActiveContainerDiv.style.display = "none";
}

//////////////////////////////////////////////////////////////////////////////////////////////
// Misc
//////////////////////////////////////////////////////////////////////////////////////////////


function OpenPrinterFriendlyWindow(ShowTitle) {
	var ShowTitleInWindow = ShowTitle == false ? "N" : "Y";
	window.open("/utils/printer-friendly.aspx?ShowTitleInWindow=" + ShowTitleInWindow, "printer_win", "scrollbars=yes,resizable=yes,width=610,height=670");
}

function getObjectById(subMenuID) {
	if (document.all) {
		if (eval('document.all.' + subMenuID)) {
			return eval('document.all.' + subMenuID);
		}
		else {
			return null;
		}
	}
	else if (document.getElementById) {
		if (document.getElementById(subMenuID) != null) {
			return document.getElementById(subMenuID);
		}
		else {
			return null;
		}
	}
	else if (document.layers) {
		return document.layers[subMenuID];
	}
	return null;
}

function OffSetY(obj) {
	if (obj.offsetParent) {
		var oTmp = obj;
		var tmpY = oTmp.offsetTop;
		while (oTmp.offsetParent) {
			oTmp = oTmp.offsetParent;
			tmpY += oTmp.offsetTop;
		}
		return tmpY;
	}
	else if (obj.offsetTop) {
		return obj.offsetTop;
	}
	else if (obj.y) {
		return obj.y;
	}
	else {
		return 0;
	}
}
