﻿/// <reference path="../../Scripts/jquery-1.5-vsdoc.js" />
/* ActiveWindow event - part of active session management
 * Requires jQuery 1.4.2+ 
 * Notifies Timer in frmHead that window is active
 */

var hdrMain = window.top.frames.frmHead;
try {
	if (hdrMain.CustomerTimeOut) {
		$(document).ready(function () {
			bindActiveWindow();
		});
	} else {
		// Don't Run IdleTimeout
		$.noop;
	}
} catch (e) {
	switch (e.number) {
		case -2146823281:
			//alert("No HeaderMain."); // Debug Code
			$.noop;
			break;
		default:
			//alert("Unanticipated error:\n" + e.message + '\n#' + e.number); // Debug Code
			$.noop;
			break;
	}
}

/*	bindActiveWindow() - binds mouse and keyboard events to iframes
	recursively seeks out iframes within iframes and binds them too.
	Initial run without argument.
	Binding to iframe only affects the iframe border; binding to iframe 
	document doesn't seem to work; binding to body is just right.	
*/
function bindActiveWindow(obj) {
	if (obj == null) {
		$("body").bind("mousemove keydown DOMMouseScroll mousewheel mousedown", function () {
			triggerActiveWindow();
		});
		$("iframe, frame").each(function (i, e) { bindActiveWindow(this); });
		$("iframe, frame").live("load", function (i, e) { bindActiveWindow(this); });
	} else {
		if ($(obj).length > 0) {
			try {
				$(obj).contents().delegate("body", "mousemove keydown DOMMouseScroll mousewheel mousedown", function () {
					triggerActiveWindow();
				});
				$(obj).live("load", function () { bindActiveWindow(this); });
				$(obj).contents().find("iframe, frame").each(function (i, e) { bindActiveWindow(this); });
			} catch (e) {
				/* if this fails we don't want to blowup the app, user can just deal with the warning */
				$.noop;
			}
		} else {
			if (obj.tagName.indexOf('FRAME') > -1) $(obj).live("load", function () { bindActiveWindow(this); });
		}
	}
}

/*	triggerActiveWindow() - trigger logic for all ActiveWindow bindings
	fires the ActiveWindow handler in frmHead (HeaderMain).
*/
function triggerActiveWindow() {
	try {
		hdrMain.$(hdrMain.document).trigger("ActiveWindow");
	} catch (e) {
		// Debug Code
		$.noop;
	}
}

