// Set event capturing if we are using Netscape.
if (document.layers) {
	window.captureEvents(Event.CLICK);
	window.captureEvents(Event.MOUSEDOWN);			
	window.captureEvents(Event.MOUSEUP);			
	window.captureEvents(Event.MOUSEMOVE);						
}


// __set_size is a cross-browser function that determines the current size of the browser window.
// The 'form' parameter identifies the form that we are working with.
// There is an ASSUMPTION that this form contains 'm_screen_x' and 'm_screen_y' input fields.
function __set_size(form) {
	if (form == null)
		form = document.forms[0];

	if (form != null) {
		if (navigator.appName=="Netscape") {
			form.m_screen_x.value = window.innerWidth;
			form.m_screen_y.value = window.innerHeight;
		}
		if (navigator.appName=="Microsoft Internet Explorer") {
			if (document.documentElement && document.documentElement.clientWidth != 0 && document.documentElement.clientHeight != 0) {
				// IE6+ (using "strict" HTML 4.01)
				form.m_screen_x.value = document.documentElement.clientWidth;
				form.m_screen_y.value = document.documentElement.clientHeight;
			} else {
				// IE
				form.m_screen_x.value = document.body.clientWidth;
				form.m_screen_y.value = document.body.clientHeight;		
			}
		}
		if (navigator.appName!="Netscape" && navigator.appName!="Microsoft Internet Explorer") {
			alert("WARNING: Unable to detect browser type. Setting dashboard size to 800x600");
			form.m_screen_x.value = "800";
			form.m_screen_y.value = "600";
		}
	}
}


function __hide_mask() {
	// Hide the postback mask...
	es = document.getElementById('postback_mask');
	if (es != null) {
		es.style.visibility = 'hidden';
	}
}


/// Captures the browser window size and caches this in two fields named by the two parameters passed in.
function __cache_window_size(w, h) {
	if (navigator.appName=="Netscape") {
		document.getElementById(w).value = window.innerWidth;
		document.getElementById(h).value = window.innerHeight;
	} else if (navigator.appName=="Microsoft Internet Explorer") {
		if (document.documentElement && document.documentElement.clientWidth != 0 && document.documentElement.clientHeight != 0) {
			// IE6+ (using "strict" HTML 4.01)
			document.getElementById(w).value = document.documentElement.clientWidth;
			document.getElementById(h).value = document.documentElement.clientHeight;
		} else {
			// IE
			document.getElementById(w).value = document.body.clientWidth;
			document.getElementById(h).value = document.body.clientHeight;
		}
	} else {
//		alert("WARNING: Unable to detect browser type. Setting dashboard size to 800x600");
		document.getElementById(w).value = "800";
		document.getElementById(h).value = "600";
	}
}

// __process_key is an IE function which detects PGUP/DOWN keypresses and translates them
// into clicks on the 'next' and 'previous' (respectively) toolbar buttons.
function __process_key(code)	{
	if (navigator.appName=="Microsoft Internet Explorer") {
		if (code == 33) // "PgUp"
		{
			var es;
			es = document.getElementById('m_toolbar_TB_previous');
			es.click();	// This doesn't work in Netscape or Mozilla		
		}
		if (code == 34) // "PgDown"
		{
			var es;
			es = document.getElementById('m_toolbar_TB_next');
			es.click();	// This doesn't work in Netscape or Mozilla
		}
	}

	if (code == 66) { // "b"
		var bookmark;
		bookmark = 'bookmark.aspx?bookmark=' + window.location.href
		newwindow = window.open(bookmark, '', 'height=200, width=500');
	}

	if (code == 84) { // "t"
		var tb;
		tb = document.getElementById('m_toolbar_table');
		if (tb) {
			if ('visible' == tb.style.visibility) {
				tb.style.visibility = 'hidden';
				document.dashboard_form.m_toolbar_Vis.value = "0";
			} else {
				tb.style.visibility = 'visible';
				document.dashboard_form.m_toolbar_Vis.value = "1";
			}
		}
	}
}

// __setFocus is a cross-browser (i think) function which sets the current focus to the element
// specified in the function parameter.
function __set_focus(element) {
	// Does this work for all browsers?
	document.getElementById(element).focus()
}


// The JavaScript below creates a cookie and the "__check_cookies()" function sets the "innerHTML" of "error_text" if this doesn't work...
document.cookie = "cookies=working";
function __check_cookies(form)
{
	if (document.cookie == "") {
		document.getElementById('error_text').innerHTML = "You must <a href='http://support.microsoft.com/default.aspx?scid=kb;EN-US;196955'>enable Cookies</a> to use Empower .NET.";
	}
}


var __submitting = false;

function __isSubmitting() {
	if (__submitting == true) {
		alert('Please wait for Empower .NET to process your last request...');
		return true;
	} else {
		return false;
	}
}

// __processSubmit() will be called by SmartNavigation before the form is submitted...
function __processSubmit()
{
	if (navigator.appName=="Microsoft Internet Explorer") {
		__submitting = true;

		// Show the postback mask...
		es = document.getElementById('postback_mask');
		if (es != null) {
			es.style.visibility = 'visible';
			es.style.cursor = "wait";
		}

		// Hide any open element selectors...
		var es;
		es = document.getElementById('m_element_selector_m_table');
		if (es != null) {
			es.style.visibility = 'hidden';
		}
	}
}

function __cache_scroll_pos(id, top, row)
{
	sb = document.getElementById(id);
	if (sb != null)
	{
		var new_row = sb.scrollTop / parseInt(sb.style.fontSize.replace("px", ""));
		new_row = Math.ceil(new_row);
		document.getElementById(row).value = new_row;
		document.getElementById(top).value = sb.scrollTop;
	}
}

