	var lastMouseX;
	var lastMouseY;

	function none() {
	}

	function setSelectionRange(input, selectionStart, selectionEnd)
	{
		if (input.setSelectionRange) {
			input.focus();
			input.setSelectionRange(selectionStart, selectionEnd);
		}
		else if (input.createTextRange) {
			var range = input.createTextRange();
			range.collapse(true);
			range.moveEnd('character', selectionEnd);
			range.moveStart('character', selectionStart);
			range.select();
		}
	}
	
	function hilite_row(row) {
		if (row.className != "RowSelected")
			row.className = "RowHilite";
	}

	function unhilite_row(row) {
		if (row.className != "RowSelected")
			row.className = "RowNormal";
	}
	
	function hilite_task(task) {
		document.getElementById(task).className = "TaskIconHilite";
		document.getElementById(task).parentNode.parentNode.className = "TaskHilite";
	}
	
	function unhilite_task(task) {
		document.getElementById(task).className = "TaskIconNormal";
		document.getElementById(task).parentNode.parentNode.className = "TaskNormal";
	}
	
	function setCookie(name, value, expires, path, domain, secure)
	{
	    document.cookie= name + "=" + escape(value) +
	        ((expires) ? "; expires=" + expires.toGMTString() : "") +
	        ((path) ? "; path=" + path : "") +
	        ((domain) ? "; domain=" + domain : "") +
	        ((secure) ? "; secure" : "");
	}
	
	function getCookie(name)
	{
	    var dc = document.cookie;
	    var prefix = name + "=";
	    var begin = dc.indexOf("; " + prefix);
	    if (begin == -1)
	    {
	        begin = dc.indexOf(prefix);
	        if (begin != 0) return null;
	    }
	    else
	    {
	        begin += 2;
	    }
	    var end = document.cookie.indexOf(";", begin);
	    if (end == -1)
	    {
	        end = dc.length;
	    }
	    return unescape(dc.substring(begin + prefix.length, end));
	}
	
	function deleteCookie(name, path, domain)
	{
	    if (getCookie(name))
	    {
	        document.cookie = name + "=" + 
	            ((path) ? "; path=" + path : "") +
	            ((domain) ? "; domain=" + domain : "") +
	            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	    }
	}
	
	function getWindowWidth(l_window) {
		var l_document = l_window.document;
		
		if (typeof(l_window.innerWidth ) == 'number')
			return l_window.innerWidth;
			
		if (l_document.documentElement && (l_document.documentElement.clientWidth || l_document.documentElement.clientHeight))
			return l_document.documentElement.clientWidth;

		if (l_document.body && (l_document.body.clientWidth || l_document.body.clientHeight))
			return l_document.body.clientWidth;
			
		return -1;
	}

	function getWindowHeight(l_window) {
		var l_document = l_window.document;
		
		if (typeof(l_window.innerHeight) == 'number')
			return l_window.innerHeight;
			
		if (l_document.documentElement && (l_document.documentElement.clientWidth || l_document.documentElement.clientHeight))
			return l_document.documentElement.clientHeight;

		if (l_document.body && (l_document.body.clientWidth || l_document.body.clientHeight))
			return l_document.body.clientHeight;
			
		return -1;
	}
	
	function updateWindowSize() {
		var l_window = window.top;
		var l_document = l_window.document;
		
// window.status = "Window: " + getWindowWidth(l_window) + " " +
// getWindowHeight(l_window);
		
		setCookie('window.width', getWindowWidth(l_window), null, null, null, null);
		setCookie('window.height', getWindowHeight(l_window), null, null, null, null);
		setCookie('screen.width', screen.width, null, null, null, null);
		setCookie('screen.height', screen.height, null, null, null, null);
	}

	function isInternetExplorer() {
		return navigator.appName.indexOf("Internet Explorer") != -1;
	}
	
	function setLastMousePosition(e) {
		if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
		lastMouseX = e.screenX;
		lastMouseY = e.screenY;
	}
	
	function closeWindowRedirect(f_strURL) {
		window.opener.location.href = f_strURL;
		window.close();
	}	
	
	function getPopupProperties(f_intWidth, f_intHeight) {
		return "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=" + f_intWidth + ",height=" + f_intHeight;
	}

	function getBrowserProperties(f_intWidth, f_intHeight) {
		return "toolbar=yes,location=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes,width=" + f_intWidth + ",height=" + f_intHeight;
	}

	function openCalendarChooser(f_strForm, f_strInput, f_strTitle, f_strURL, f_intWidth, f_intHeight) {
		var l_strProperties = getPopupProperties(f_intWidth, f_intHeight);
		
		l_strProperties = l_strProperties + ",scrollbars=no";

		if (lastMouseX - f_intWidth < 0) {
			lastMouseX = f_intWidth;
		}
	
		if (lastMouseY + f_intHeight > screen.height) {
			lastMouseY -= (lastMouseY + f_intHeight + 50) - screen.height;
		}
		
		lastMouseX -= f_intWidth;
		lastMouseY += 10;

		l_strProperties += ",screenX=" + lastMouseX;
		l_strProperties += ",screenY=" + lastMouseY;
		l_strProperties += ",left=" + lastMouseX;
		l_strProperties += ",top=" + lastMouseY;
		
		// try to get the date?
		if (f_strForm != 'null' && f_strInput != 'null') {
			var l_strDate = document.forms[f_strForm].elements[f_strInput].value;
			
			f_strURL = f_strURL + "&_date=" + l_strDate;
		}
		
		window.open(f_strURL, f_strTitle, l_strProperties).focus();
	}

	function openWindowMaximized(f_strURL) {
		openWindowMaximizedTitle(f_strURL, '');
	}

	function openWindowMaximizedTitle(f_strURL, f_strTitle) {
		var l_strProperties = getPopupProperties(-1, -1);
		var handle = window.open(f_strURL, f_strTitle, l_strProperties);
		
		handle.moveTo(0,0);
		handle.resizeTo(screen.availWidth, screen.availHeight);
		handle.focus();
	}
	
	function resizeWindow(f_strURL, f_intWidth, f_intHeight) {
		resizeTo(getWidth(f_intWidth), getHeight(f_intHeight));
		
		setURL(f_strURL);
	}

	function openWindowCenteredConstrained(f_strURL, f_intWidth, f_intHeight) {
		if (getWidth(-1) < f_intWidth)
			f_intWidth = getWidth(-1);
			
		if (getHeight(-1) < f_intHeight)
			f_intHeight = getHeight(-1);
		
		openWindowCenteredTitle('', f_strURL, f_intWidth, f_intHeight);
	}

	function openWindowCentered(f_strURL, f_intWidth, f_intHeight) {
		openWindowCenteredTitle('', f_strURL, f_intWidth, f_intHeight);
	}
	
	function openWindowCenteredTitle(f_strTitle, f_strURL, f_intWidth, f_intHeight) {
		f_intWidth = getWidth(f_intWidth);
		f_intHeight = getHeight(f_intHeight);
	
		var l_intScreenX = getX(f_intWidth);
		var l_intScreenY = getY(f_intHeight);
		var l_strProperties = getPopupProperties(f_intWidth, f_intHeight);

		l_strProperties += ",screenX=" + l_intScreenX;
		l_strProperties += ",screenY=" + l_intScreenY;
		l_strProperties += ",left=" + l_intScreenX;
		l_strProperties += ",top=" + l_intScreenY;

		if (false && window.opener != null)
			window.opener.open(f_strURL, f_strTitle, l_strProperties).focus();
		else
			window.open(f_strURL, f_strTitle, l_strProperties).focus();
	}

	function openBrowserCentered(f_strURL, f_intWidth, f_intHeight) {
		f_intWidth = getWidth(f_intWidth);
		f_intHeight = getHeight(f_intHeight);
	
		var l_intScreenX = getX(f_intWidth);
		var l_intScreenY = getY(f_intHeight);
		var l_strProperties = getBrowserProperties(f_intWidth, f_intHeight);

		l_strProperties += ",screenX=" + l_intScreenX;
		l_strProperties += ",screenY=" + l_intScreenY;
		l_strProperties += ",left=" + l_intScreenX;
		l_strProperties += ",top=" + l_intScreenY;

		window.open(f_strURL, '', l_strProperties).focus();
	}

	function openWindowCenteredCloseOpener(f_strURL, f_intWidth, f_intHeight) {
		f_intWidth = getWidth(f_intWidth);
		f_intHeight = getHeight(f_intHeight);
	
		var l_intScreenX = screen.availWidth / 2 - f_intWidth / 2;
		var l_intScreenY = screen.availHeight / 2 - f_intHeight / 2;

		moveTo(l_intScreenX, l_intScreenY);
		resizeTo(f_intWidth, f_intHeight);
		
		self.location.href = f_strURL;
	}

	function closeWindow() {
		window.close();
	}

	function closeTopWindow() {
		window.top.close();
	}
	
	function back() {
		history.go(-1);
	}
	
	function refresh() {
		history.go(0);
	}

	function setURL(f_strURL) {
		self.location = f_strURL;
	}

	function setParentURL(f_strURL) {
		window.top.location = f_strURL;
	}

	function setOpenerURL(f_strURL) {
		window.top.opener.location = f_strURL;
	}
	
	function closeSetOpenerURL(f_strURL) {
		window.top.opener.location = f_strURL;
		
		window.close();
	}

	function setRootOpenerURL(f_strURL) {
		if (window.top.opener.opener != null)
			window.top.opener.opener.location = f_strURL;
		else
			window.top.opener.location = f_strURL;
	}

	function setRootURL(f_strURL) {
		var l_window = window.top.opener;
		
		if (l_window.top.opener != null)
			l_window = l_window.top.opener;

		if (l_window.top.opener != null)
			l_window = l_window.top.opener;
			
		l_window.top.location = f_strURL;
	}
	
	function setHiddenUrl(f_strUrl) {
		window.top.frames['hidden'].location.href = f_strUrl;
	}
	
	function submitForm(f_strForm) {
		document.forms[f_strForm].submit();
	}

	function submitFormForMethod(f_strForm, f_strMethod) {
		document.forms[f_strForm].method.value = f_strMethod;
		document.forms[f_strForm].submit();
	}

	function submitFormForActionAndMethod(f_strForm, f_strAction, f_strMethod) {
		document.forms[f_strForm].action = f_strAction;
		document.forms[f_strForm].method.value = f_strMethod;
		document.forms[f_strForm].submit();
	}

	function closeWindowOnEscape(ev) {
		if (ev.keyCode == 27)
			closeWindow();
	}
	
	function disableButtonAndSubmitForm(f_strForm, f_strButton) {
		document.forms[f_strForm][f_strButton].disabled = true;
		document.forms[f_strForm].submit();
	}
	
	function sendEmail(f_strAddress, f_strDomain) {
		window.location.href = 'mailto:' + f_strAddress + '@' + f_strDomain;
	}
	
	function getX(f_intWidth) {
		return (screen.availWidth - (f_intWidth + 32)) / 2;
	}

	function getY(f_intHeight) {
		return (screen.availHeight - (f_intHeight + 48)) / 2;
	}
	
	function getWidth(f_intWidth) {
		if (f_intWidth == -1)
			f_intWidth = screen.availWidth - 96;
			
		if (f_intWidth > 0.0 && f_intWidth <= 1.0)
			f_intWidth = (screen.availWidth - 96) * f_intWidth;
			
		return f_intWidth;
	}
	
	function getHeight(f_intHeight) {
		if (f_intHeight == -1)
			f_intHeight = screen.availHeight - 96;

		if (f_intHeight > 0.0 && f_intHeight <= 1.0)
			f_intHeight = (screen.availHeight - 96) * f_intHeight;
			
		return f_intHeight;
	}
	
	function gup(name)
	{
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		
		if( results == null )
	    	return "";
	    else
	    	return results[1];
	}	
	
	function flow_hilite_row(row) {
		flow_hilite_row_from_to(row, "RowHilite", "RowSelected");
	}

	function flow_unhilite_row(row) {
		flow_hilite_row_from_to(row, "RowNormal", "RowSelected");
	}

	function flow_hilite_row_from_to(row, name, selected) {
		for (var column = 0; column < 100 ; ++column) {
			var cell = document.getElementById("row_" + row + "_" + column);
		
			if (cell == null)
				break;
				
			if (cell.className != selected)
				cell.className = name;
		}
	}

	function flow_toggle_select_row(row) {
		flow_toggle_select_row_from_to(row, "RowNormal", "RowSelected");
	}
	
	function flow_toggle_select_row_from_to(row, name, selected) {
		for (var column = 0; column < 100 ; ++column) {
			var cell = document.getElementById("row_" + row + "_" + column);
		
			if (cell == null)
				break;
				
			if (cell.className == selected)
				cell.className = name;
			else
				cell.className = selected;
		}
	}
	
	window.onresize = updateWindowSize;