/*
	Copyright (c) Microsoft Corporation.  All rights reserved.
*/

/* _LocalBinding */
// _lcid="1033" _version="12.0.6212"

function crossWindowFromDocument(doc)
{
	if (doc.parentWindow!=null)
	{
		return doc.parentWindow;
	}
	if (doc.defaultView!=null)
	{
		return doc.defaultView;
	}
	return null;
}

function getParentElement(ctrl)
{
	if (ctrl == null)
		return null;

	if (ctrl.parentElement != undefined && ctrl.parentElement != null)
	{
		return ctrl.parentElement;
	}
	if (ctrl.parentNode != undefined && ctrl.parentNode != null)
	{
		return ctrl.parentNode;
	}

	return null;
}

function getChildren(ctrl)
{

	if (ctrl.childNodes != undefined)
		return ctrl.childNodes;

	if (ctrl.children != undefined)
		return ctrl.children;

	return null;
}

function getAttribute(ctrl, attrib)
{

	if (ctrl.hasAttribute != null)
		return (ctrl.hasAttribute(attrib)) ? ctrl.getAttribute(attrib) : null;

	return ctrl.getAttribute(attrib);
}

function getCurrentStyle(elem, ieStyle, cssStyle)
{

	if (elem.currentStyle != undefined)
	{
		return elem.currentStyle[ieStyle];
	}

	if (window.getComputedStyle != undefined)
	{
		var compStyle = window.getComputedStyle(elem, "");
		return compStyle.getPropertyValue(cssStyle);
	}

	return "";
}

function getInnerText(ctrl)
{
	if (ctrl == null)
		return null;

	if (ctrl.innerText != undefined)
	{
		return ctrl.innerText;
	}

	if (ctrl.textContent != undefined)
	{
		return ctrl.textContent;
	}

	return "";
}

function getSrcElement(event)
{
	if (event.srcElement != undefined)
	{
		return event.srcElement;
	}

	if (event.target != undefined)
	{
		return event.target;
	}

	return null;
}

function getMouseButton(event)
{
	switch (event.type.toLowerCase())
	{
		case "mousedown":
		case "mouseup":
		case "mousemove":
			break;

		case "click":
			return 1;

		default:
			return -1;
	}

	if (event.button != undefined)
	{

		if (browseris.nav)
		{
			switch (event.button)
			{

				case 0:
					return 1;

				case 1:
					return 4;

				case 2:
					return 2;

				default:
					return 0;
			}
		}

		return event.button;
	}

	if (event.which != undefined)
	{
		switch (event.which)
		{

			case 1:
				return 1;

			case 2:
				return 4;

			case 3:
				return 2;

			default:
				return 0;
		}
	}

	return 0;
}

function createXmlReader(xml)
{
	var xmlDoc;
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc=(new DOMParser()).parseFromString(xml, "text/xml");
	}
	else
	{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.loadXML(xml);
	}

	return xmlDoc;
}

function selectSingleNode(xmlNode, tagName)
{
	if (document.implementation && document.implementation.createDocument)
	{
		var elems=xmlNode.getElementsByTagName(tagName);
		if(elems.length > 0)
			return elems[0];
		return null;
	}
	else
	{
		return xmlNode.selectSingleNode(tagName);
	}
}

var oTableToolbar = null;			
var minToolbarWidth = -1;			
var oCellsHighlight = null;			
var HighlightedCell = null;			
var HighlightedCellMode = null;		
var HighlightedColumnIndex = -1;			
var HighlightedRowIndex = -1;			

var HorizontallyLimitingControls = new Array();
var VerticallyLimitingControls = new Array();
var ResizeFunctions = new Array();
var ScrollSelectMode = 'GetRange';
var LastNavigationDirection = 'Left';
var InnerEwrLoadNotificationCalled = false;
var varInitialSelectionCell = null;

var userSelectionColumnInput = null;
var userSelectionRowInput = null;
var userScrollPositionVerticalInput = null;
var userScrollPositionHorizontalInput = null;

var oActiveImageDiv = null;
var hvrImgDiv = null;

function showCroppedHvrUI(event, activeImageDiv, horizontalEdge, vertricalEdge)
{
	if (oActiveImageDiv == activeImageDiv)
		return;

	if (hvrImgDiv == null)
		hvrImgDiv = document.getElementById("ewrCropHvrImgDiv");

	hvrImgDiv.style.display = 'block';

	if (horizontalEdge == "right")
	{
		hvrImgDiv.style.left = Math.max(0, activeImageDiv.offsetLeft + activeImageDiv.offsetWidth - hvrImgDiv.offsetWidth - 5);
	}
	else
	{
		hvrImgDiv.style.left = Math.max(0, activeImageDiv.offsetLeft + 5);
	}

	if (vertricalEdge == "bottom")
	{
		hvrImgDiv.style.top = Math.max(0, activeImageDiv.offsetTop + activeImageDiv.offsetHeight - hvrImgDiv.offsetHeight - 5);
	}
	else
	{
		hvrImgDiv.style.top = Math.max(0, activeImageDiv.offsetTop + 5);
	}

	oActiveImageDiv = activeImageDiv;

	event.cancelBubble = true;
	return false;
}

function hideCroppedHvrUI(event, activeImageDiv)
{

	if (hvrImgDiv == null)
		hvrImgDiv = document.getElementById("ewrCropHvrImgDiv");

	var elm;
	for (elm = event.toElement; elm != null; elm = elm.parentNode)
	{
		if (elm == hvrImgDiv)
			return;
	}

	hvrImgDiv.style.display = 'none';

	oActiveImageDiv = null;

	event.cancelBubble = true;
	return false;
}

function scrollCroppedImgDiv(image, scrollLeftPct, scrollTopPct)
{
	var imageDiv = getParentElement(image);
	imageDiv.scrollLeft = scrollLeftPct * image.offsetWidth;
	imageDiv.scrollTop = scrollTopPct * image.offsetHeight;

	return false;
}

function croppedImgDivErr(image, errAltText, errCss)
{
	image.alt = errAltText;
	image.className = errCss;

	return scrollCroppedImgDiv(image, 0.0, 0.0);
}

function showActiveImgFullSize(event)
{
	if (oActiveImageDiv == null)
		return;

	var imageElm = getChildren(oActiveImageDiv)[0];

	var imageSrcUrl = getAttribute(imageElm, "src");

	var sFeatures;
	sFeatures = "dialogHeight:" + 550 + "px;";
	sFeatures += "dialogWidth:" + 780 + "px;";
	sFeatures += "location:no; menubar:no; resizable:yes; scrollbars:yes; status:no; titlebar:yes; toolbar:no";

	hideCroppedHvrUI(event, oActiveImageDiv);

	commonShowModalDialog(imageSrcUrl, sFeatures, null);

	return false;
}

function SetCellSelection(tblObj, selRowIdx, selColIdx, selMode, cellsHighlightId)
{
	{}

try{

	if (oCellsHighlight == null)
	{
		oCellsHighlight = document.getElementById(cellsHighlightId);
	}

	if (selMode == null)
	{

	}
	else if (selMode == "cell")
	{

		var currCell = null;

		if (selRowIdx != null && selColIdx != null)
		{

			var cells = tblObj.rows[selRowIdx].cells;
			if (cells.length == 0)
			{
				return;
			}

			var ewrColumnIndexAttribute = getAttribute(cells[0], "EwrColumnIndex");
			var ewrColIdx = (ewrColumnIndexAttribute != null) ? parseInt(ewrColumnIndexAttribute) : 0;

			var ewrRealColumnIndex = 0;
			while (ewrColIdx < selColIdx && ewrRealColumnIndex < cells.length - 1)
			{
				ewrRealColumnIndex++;

				var ewrColumnIndexAttr = getAttribute(cells[ewrRealColumnIndex], "EwrColumnIndex");
				if (ewrColumnIndexAttr != null)
				{
					ewrColIdx = parseInt(ewrColumnIndexAttr);
				}
				else
				{
					ewrColIdx++;
				}
			}

			currCell = cells[ewrRealColumnIndex];
		}

		highlightCell(currCell, false, selMode, selRowIdx, selColIdx);

		varInitialSelectionCell = HighlightedCell;
	}

	else if (selMode == "column")
	{
		var columnHeaderTable = document.getElementById("ColumnHeaders");
		if (columnHeaderTable != null)
		{

			var headerRows = columnHeaderTable.rows;
			var headerRow = headerRows[headerRows.length - 1];
			var headerCell = headerRow.cells[selColIdx];

			highlightCell(headerCell, false, selMode, selRowIdx, selColIdx);
		}
	}

	else if (selMode == "row")
	{
		var rowHeaderTable = document.getElementById("RowHeaders");
		if (rowHeaderTable != null)
		{

			var headerRowCells = rowHeaderTable.rows[selRowIdx].cells;
			var headerCell = headerRowCells[headerRowCells.length - 1];

			highlightCell(headerCell, false, selMode, selRowIdx, selColIdx);
		}
	}

}catch(ex){}

	{}
	{}
}

function FormatCells(tblID, selRowIdx, selColIdx, selColMode, cellsHighlightId, scrollSelectMode, lastNavigationDirection)
{

	var tblObj = document.getElementById(tblID);
	if (!tblObj)
	{
		return;
	}

	ScrollSelectMode = scrollSelectMode;
	LastNavigationDirection = lastNavigationDirection;

	{}
	var childDivs = document.getElementsByName("ewrcp");
	{}

	var divCount = childDivs.length;
	{};

	for (var i = 0; i < divCount; ++i)
	{
		var divCurrent = childDivs[i];

		var tdParent = getElement(divCurrent, tblID, true, "TD");
		if (tdParent != null)
		{
			var trParent = getParentElement(tdParent);

			ApplyAlignment(divCurrent, trParent, tdParent);
		}
	}
	{};

	SetCellSelection(tblObj, selRowIdx, selColIdx, selColMode, cellsHighlightId);
}

function WrapVerticalContent(cellCurrent, divCurrent, currentRow)
{
	var textFragments = divCurrent.innerHTML.split(browseris.ie ? "<BR>" : "<br>");
	var textFragmentCount = textFragments.length;
	var ratio = cellCurrent.clientHeight / (divCurrent.scrollHeight + textFragmentCount);
	var fragmentsPerCol = ratio * textFragmentCount - 1;

	{};
	{};

	if (fragmentsPerCol > 1)
	{
		var html = "<table class='ewrvertwrap'><tr>";

		var i = 0;
		while (i < textFragmentCount)
		{

			html += "<td class='" + cellCurrent.className + "'>";
			for (var j = 0; j < fragmentsPerCol; j++)
			{
				if (i < textFragmentCount)
				{
					html += textFragments[i]
					i++;
					html += (i < textFragmentCount) ? "<br>" : "";
				}
			}
			html += "</td>";
		}

		html += "</tr></table>";

		divCurrent.innerHTML = html;
	}

	{};
}

function ApplyAlignment(divCurrent, currentRow, cellCurrent)
{
	var fVertical = getAttribute(divCurrent, "VerticalText") != null;
	var fVerticalWrap = getAttribute(divCurrent, "VerticalWrapText") != null;

	if (getAttribute(divCurrent, 'HorizontalFill'))
	{
		FillCell(divCurrent, cellCurrent);
	}
	if (getAttribute(divCurrent, 'ShrinkToFit'))
	{
		ShrinkToFit(cellCurrent, divCurrent, fVertical || fVerticalWrap);
	}
	if (fVerticalWrap)
	{
		WrapVerticalContent(cellCurrent, divCurrent, currentRow);
	}
}

function GetInnerControl(ctrl, fillerStr)
{

	if ((ctrl.nodeType == 3) && (ctrl.nodeValue == fillerStr))
	{
		return ctrl;
	}

	var oChildren = getChildren(ctrl);
	for (var i = oChildren.length - 1; i >= 0 ; --i)
	{
		var innerCtrl = GetInnerControl(oChildren[i], fillerStr);
		if (innerCtrl != null)
			return innerCtrl;
	}

	return null;
}

function getUnwrappedWidth(element)
{

	var cachedWhitespaceStyle = element.style.whitespace;
	var cachedOverflowStyle = element.style.overflow;
	var cachedWidthStyle = element.style.width;

	element.style.whitespace = "nowrap";
	element.style.overflow = "hidden";
	element.style.width = "1px";

	var minimumWidth = element.scrollWidth;

	element.style.whitespace = cachedWhitespaceStyle;
	element.style.overflow = cachedOverflowStyle;
	element.style.width = cachedWidthStyle;

	return minimumWidth;
}

function FillCell(divCurrent, tdParent)
{
	var fillerStr = getInnerText(divCurrent);
	if (fillerStr.length == 0 || divCurrent.offsetWidth == 0 || divCurrent.scrollWidth == 0)
	{
		return;
	}

	var oInnerText = GetInnerControl(divCurrent, fillerStr);
	if (oInnerText == null)
	{
		return;
	}

	var oInnerControl = getParentElement(oInnerText);
	if (oInnerControl == null)
	{
		oInnerControl = divCurrent;
	}

	var innerControlWidth = getUnwrappedWidth(oInnerControl);

	var repeat = (innerControlWidth == 0) ? 0 : Math.floor(tdParent.clientWidth / innerControlWidth);
	if (repeat > 1)
	{
		{};

		var innerText = "";
		for (var j=0; j < repeat; ++j)
		{
			innerText += fillerStr;
		}
		oInnerText.nodeValue = innerText;
	}
}

function GetPtSize(sizeString)
{
	if (!sizeString || sizeString.length == 0)
	{
		return 0;
	}

	var indexOfP = sizeString.indexOf("p");
	if (indexOfP >= 0 && indexOfP == sizeString.length - 2)
	{
		sizeString = sizeString.substring(0, indexOfP);
	}

	return new Number(sizeString);
}

function ShrinkToFit(cellCurrent, divCurrent, fVertical)
{

	var pixelWidth = cellCurrent.offsetWidth;
	var pixelHeight = cellCurrent.offsetHeight;

	if ((divCurrent.scrollWidth <= pixelWidth && !fVertical) ||
		(divCurrent.scrollHeight <= pixelHeight && fVertical))
	{
		return;
	}

	divCurrent.style.whitespace = "nowrap";
	divCurrent.style.overflow = "hidden";
	divCurrent.style.width = "auto";

	var originalFontSize = GetPtSize(getCurrentStyle(divCurrent, "fontSize", "font-size"));
	if (originalFontSize == 0)
	{
		originalFontSize = DefaultFontSize;
	}

	var fontSize = originalFontSize;

	if (!fVertical)
	{

		fontSize *= pixelWidth / divCurrent.scrollWidth;
		if (fontSize < 0.5)
		{
			fontSize = 0.5;
		}

		divCurrent.style.fontSize = fontSize + "pt";

		while (divCurrent.scrollWidth < pixelWidth && fontSize < originalFontSize)
		{
			fontSize += 0.5;
			divCurrent.style.fontSize = fontSize + "pt";
		}

		while (divCurrent.scrollWidth > pixelWidth && fontSize > 0.5)
		{
			fontSize -= 0.5;
			divCurrent.style.fontSize = fontSize + "pt";
		}
	}
	else
	{

		fontSize *= pixelHeight / divCurrent.scrollHeight;
		if (fontSize < 0.5)
		{
			fontSize = 0.5;
		}

		divCurrent.style.fontSize = fontSize + "pt";

		while (divCurrent.scrollHeight < pixelHeight && fontSize < originalFontSize)
		{
			fontSize += 0.5;
			divCurrent.style.fontSize = fontSize + "pt";
		}

		while (divCurrent.scrollHeight > pixelHeight && fontSize > 0.5)
		{
			fontSize -= 0.5;
			divCurrent.style.fontSize = fontSize + "pt";
		}
	}
}

function checkKeyboardScroll(event, topmost)
{

	if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
	{
		event.cancelBubble = false;
		return true;
	}

	var keyPressed = event.keyCode;

	var dx = 0;
	var dy = 0;

	if ((!RtlSheet && keyPressed == 37) || (RtlSheet && keyPressed == 39))
	{
		dx = -1;
	}
	else if (keyPressed == 38)
	{
		dy = -1;
	}
	if ((!RtlSheet && keyPressed == 39) || (RtlSheet && keyPressed == 37))
	{
		dx = 1;
	}
	else if (keyPressed == 40)
	{
		dy = 1;
	}
	else if (keyPressed == 33)
	{
		dy = -9;
	}
	else if (keyPressed == 34)
	{
		dy = 9;
	}

	var cellTable;
	if ((dx == 0 && dy == 0) || ((cellTable = document.getElementById(topmost)) == null))
	{
		event.cancelBubble = false;
		return true;
	}

	var hScroll = Math.max(0, Math.min(oDivContent.scrollLeft + (dx * 50), oDivContent.scrollWidth - oDivContent.clientWidth));
	if (oEwrHScrollbar != null)
		oEwrHScrollbar.scrollLeft = hScroll;
	doEwrHScroll(hScroll);

	var vScroll = Math.max(0, Math.min(oDivContent.scrollTop + (dy * 50), oDivContent.scrollHeight - oDivContent.clientHeight));
	if (oEwrVScrollbar != null)
		oEwrVScrollbar.scrollTop = vScroll;

	event.cancelBubble = true;
	return false;
}

var lastMouseMoveElement = null;
function checkMouse(event, topmost)
{

	var el;

	var scrollHeightDiff = 1;

	if (document.elementFromPoint != undefined)
	{
		el = document.elementFromPoint(event.clientX, event.clientY);
	}

	else if (event.target != undefined)
	{
		el = event.target;
		scrollHeightDiff = 2;
	}
	else
	{
		{}
	}

	if (el == null || el == lastMouseMoveElement)
	{
		return;
	}

	lastMouseMoveElement = el;
	{};

	if (el.tagName != "A" && el.tagName != "DIV")
	{
		el = getElement(el, topmost, false, "DIV");

		if (el == null)
		{
			return;
		}
	}

	{};

	var titleAttribute = getAttribute(el, "title");
	if (titleAttribute == null || titleAttribute == "")
	{
		{}
		var tdCell = getElement(el, topmost, false, "TD");

		if (tdCell == null)
		{
			return;
		}

		var containingTable = getElement(tdCell, topmost, false, "TABLE");
		if (containingTable != null && containingTable.className.toLowerCase() == "ewr-text")
		{
			tdCell = getElement(containingTable, topmost, false, "TD");
			if (tdCell == null)
			{
				return;
			}
		}

		{};

		var cellOverflows = (tdCell.clientWidth < tdCell.scrollWidth - 1 || tdCell.clientHeight < tdCell.scrollHeight - scrollHeightDiff);

		var elText = lastMouseMoveElement;
		cellOverflows |= (tdCell.clientWidth < elText.scrollWidth || tdCell.clientHeight < elText.scrollHeight);

		if (cellOverflows)
		{
			{}

			var tooltip = getInnerText(el);

			if (tooltip.length > 1024)
			{
				tooltip = tooltip.substring(0, 1024);
				tooltip += "...";
			}
			el.title = tooltip;
		}
	}
}

function doEwrResize()
{
	{}

	for (var i = 0; i < ResizeFunctions.length; i++)
	{
		ResizeFunctions[i]();
	}

	{}
	{}
}

function resizeSheetTabs(divId)
{
	{}

	try{
	var oDiv = document.getElementById(divId);
	if (oDiv != null)
	{

		var parentCell = getParentElement(oDiv);
		var parentRowCells  = getParentElement(parentCell).cells;

		var fixedSiblingWidth = 0;
		for (var i = (parentRowCells.length - 1); i >= 0; --i)
		{
			var curCell = parentRowCells[i];
			if (curCell != parentCell)
			{
				fixedSiblingWidth += curCell.offsetWidth;
			}
		}

		var clipWidth = Math.max(0, getSheetAreaExtent(true) - fixedSiblingWidth);
		if (oDiv.style.width != ((clipWidth)+'px'))
		{
			oDiv.style.width = 0;
			oDiv.style.width = ((clipWidth)+'px');

			{}
		}
	}
	}catch(ex){}

	{}
}

function resizeNavigationBarCtrl(divId)
{
	try{

	{}

	var oDiv = document.getElementById(divId);
	if (oDiv != null)
	{
		var siblingWidth = getSheetAreaExtent(true);

		if (oDiv.offsetWidth != siblingWidth)
		{
			oDiv.style.width = 0;
			oDiv.style.width = ((siblingWidth)+'px');

			{}
		}
	}

	{}

	}catch(ex){}
}

function resizeParametersPane(ctlId)
{
	try{

	{}

	var oCtl = document.getElementById(ctlId);
	if (oCtl != null)
	{
		var mainTable = getElement(oCtl, null, false, "TABLE");
		if (mainTable != null)
		{
			var newWidth = Math.max(0, mainTable.offsetWidth - getSideOffset());
			if (oCtl.offsetWidth != newWidth)
			{
				oCtl.style.width = 0;
				oCtl.style.width = ((newWidth)+'px');

				{}
			}

			var newHeight = Math.max(0, getSheetContainerMainCellHeight());
			if (oCtl.offsetHeight != newHeight)
			{
				oCtl.style.height = 0;
				oCtl.style.height = ((newHeight)+'px');

				{}
			}
		}
	}

	{}

	}catch(ex){}
}

function getViewerPageWebPartContainerCell()
{
	var containerCell = document.getElementById("webpartContainerCell");

	if (containerCell == null && window.frameElement != null)
	{
		containerCell = window.frameElement.ownerDocument.getElementById("webpartContainerCell");
	}

	return containerCell;
}

function DoEwrResizeViewerPage()
{
	try{
	var webPartContainerCell = getViewerPageWebPartContainerCell();
	if (webPartContainerCell != null)
	{

		var webPartTableWrapper = webPartContainerCell.getElementsByTagName("table")[0];

		webPartTableWrapper.style.width = "100%";
		webPartTableWrapper.style.height = "100%";
	}
	}catch(ex){}
}

function doEwrServerMessageResize(divId)
{
	var div = document.getElementById(divId);
	if (div == null)
		return;

	var maxWidth = document.body.clientWidth;
	var maxHeight = document.body.clientHeight;

	div.style.width = "100%";
	div.style.height = "100%";

	if (div.scrollWidth > maxWidth)
		div.style.width = ((maxWidth)+'px');
	if (div.scrollHeight > maxHeight)
		div.style.height = ((maxHeight)+'px');
}

function addControlToHorizontalSizeLimitingControls(objId)
{
	if (objId == null) return;

	var obj = document.getElementById(objId);
	if (obj != null)
	{
		HorizontallyLimitingControls[HorizontallyLimitingControls.length] = obj;
	}
}

function addControlToVerticalSizeLimitingControls(objId)
{
	if (objId == null) return;

	var obj = document.getElementById(objId);
	if (obj != null)
	{
		VerticallyLimitingControls[VerticallyLimitingControls.length] = obj;
	}
}

function addScriptToResizeScripts(script)
{
	if (script == null) return;

	ResizeFunctions[ResizeFunctions.length] = new Function(script);
}

var oDivContent = null;
var oResultsTable = null;
var oEwrHScrollbar = null;
var oEwrVScrollbar = null;
var oColumnHeadersDiv = null;
var oRowHeadersDiv = null;
var oTopCell = null;
var oTopRightCell = null;
var oLeftCell = null;
var oRightCell = null;
var oBottomCell = null;
var oBottomLeftCell = null;
var oBottomRightCell = null;

function balanceRowHeight(contentTable, rowsTable)
{
	var oContentTable = document.getElementById(contentTable);
	var oRowsTable = document.getElementById(rowsTable);

	if (oContentTable == null || oRowsTable == null)
		return;

	{}

	try{

	var rowCount = oContentTable.rows.length;
	for (var i = 0; i < rowCount; i++)
	{
		var contentRow = oContentTable.rows[i];
		var contentHeight = contentRow.offsetHeight;

		var headerRow = oRowsTable.rows[i];
		var headerHeight = headerRow.offsetHeight;

		if (contentHeight == headerHeight)
		{

		}
		else if (contentHeight < headerHeight)
		{
			contentRow.style.height = ((headerHeight)+'px');
		}
		else 
		{
			headerRow.style.height = ((contentHeight)+'px');
		}
	}

	}catch(ex){}

	{}
}

function getContentWrapperTableExtent(calcHorzExtent)
{

	if (oDivContent == null)
		return 0;

	var oScrollbarCell = getParentElement(calcHorzExtent ? oEwrVScrollbar : oEwrHScrollbar);
	if (oScrollbarCell != null)
	{

		var contentWidth = (calcHorzExtent ? oDivContent.clientWidth : oDivContent.clientHeight);
		contentWidth += (calcHorzExtent ? oScrollbarCell.offsetWidth : oScrollbarCell.offsetHeight);

		return contentWidth;
	}

	return (calcHorzExtent ? oDivContent.offsetWidth : oDivContent.offsetHeight);
}

function getSheetAreaExtent(calcHorzExtent)
{
	var parentWidth = getContentWrapperTableExtent(calcHorzExtent);

	var oHeaderDiv = calcHorzExtent ? oRowHeadersDiv : oColumnHeadersDiv;
	if (oHeaderDiv != null)
		parentWidth += (calcHorzExtent ? oHeaderDiv.clientWidth : oHeaderDiv.clientHeight);

	return parentWidth;
}

var oFirstVisSheetTabIdxHiddenElm = null;
var sheetTabScrollDivElmId = null;
var bNavBarVisible = false;

function initNavBarParms(navBarVisible, firstVisSheetTabIdxHiddenElm, sheetTabScrollDivId)
{
	bNavBarVisible = navBarVisible;
	oFirstVisSheetTabIdxHiddenElm = document.getElementById(firstVisSheetTabIdxHiddenElm);
	sheetTabScrollDivElmId = sheetTabScrollDivId;
}

function getNavBarVisible()
{
	return bNavBarVisible ? "block" : "none";
}

function setContentDivScrollPosition()
{
	{}

	if ((oEwrVScrollbar != null) || (oEwrHScrollbar != null))
	{
		if (window.frameElement != null)
		{
			innerForm = window.frameElement.contentWindow.document.forms[0];
			userScrollPositionVerticalInput = EwrFindInputField(innerForm, "userscrollposvert", "true");
			userScrollPositionHorizontalInput = EwrFindInputField(innerForm, "userscrollposhorz", "true");
		}

		if (oEwrHScrollbar != null)
		{

			oEwrHScrollbar.style.height = ((getScrollBarSize() + 1)+'px');

			var childDiv = oEwrHScrollbar.getElementsByTagName("DIV")[0];
			if (childDiv != null)
			{
				childDiv.style.height = ((getScrollBarSize())+'px');
				childDiv.style.width = ((oResultsTable.scrollWidth)+'px');
			}
		}

		if (oEwrVScrollbar != null)
		{

			oEwrVScrollbar.style.width = ((getScrollBarSize() + 1)+'px');

			var childDiv = oEwrVScrollbar.getElementsByTagName("DIV")[0];
			if (childDiv != null)
			{
				childDiv.style.width = ((getScrollBarSize())+'px');
				childDiv.style.height = ((oResultsTable.scrollHeight)+'px');
			}
		}
		var userScrollPositionVertical = 0;
		if (userScrollPositionVerticalInput != null)
		{

			userScrollPositionVertical = userScrollPositionVerticalInput.value;

			userScrollPositionVertical = Math.max(0, Math.min(userScrollPositionVertical, oDivContent.scrollHeight - oDivContent.offsetHeight))
		}

		var userScrollPositionHorizontal = 0;
		if (userScrollPositionHorizontalInput  != null)
		{

			if (!RtlSheet)
			{
				userScrollPositionHorizontal = userScrollPositionHorizontalInput.value;
			}
			else
			{
				userScrollPositionHorizontal = oDivContent.scrollWidth - userScrollPositionHorizontalInput.value;
			}

			userScrollPositionHorizontal = Math.max(0, Math.min(userScrollPositionHorizontal, oDivContent.scrollWidth - oDivContent.offsetWidth))
		}

		var hScroll = 0;
		var vScroll = 0;

		if (ScrollSelectMode == 'Find' || ScrollSelectMode == 'GoTo')
		{
			if (varInitialSelectionCell != null)
			{

				hScroll = Math.max(0, varInitialSelectionCell.offsetLeft - ((oDivContent.offsetWidth - varInitialSelectionCell.offsetWidth) / 2));
				vScroll = Math.max(0, varInitialSelectionCell.offsetTop - ((oDivContent.offsetHeight - varInitialSelectionCell.offsetHeight) / 2));

				varInitialSelectionCell = null;
			}
		}
		else if (ScrollSelectMode == 'NavigateGetRange')
		{
			if ((LastNavigationDirection == 'Down') || (LastNavigationDirection == 'UpEnd'))
			{
				hScroll = Math.max(0, Math.min(userScrollPositionHorizontal, oDivContent.scrollWidth - oDivContent.offsetWidth));
			}
			else if ((LastNavigationDirection == 'Up') || (LastNavigationDirection == 'DownEnd'))
			{
				hScroll = Math.max(0, Math.min(userScrollPositionHorizontal, oDivContent.scrollWidth - oDivContent.offsetWidth));
				vScroll = oDivContent.scrollHeight - oDivContent.offsetHeight;
			}
			else if ((!RtlSheet && (LastNavigationDirection == 'Left' || LastNavigationDirection == 'RightEnd')) ||
				 (RtlSheet && (LastNavigationDirection == 'Right' || LastNavigationDirection == 'LeftEnd')))
			{
				hScroll = oDivContent.scrollWidth - oDivContent.offsetWidth;
				vScroll = userScrollPositionVertical;
			}
			else if ((!RtlSheet && (LastNavigationDirection == 'Right' || LastNavigationDirection == 'LeftEnd')) ||
				(RtlSheet && (LastNavigationDirection == 'Left' || LastNavigationDirection == 'RightEnd')))
			{
				vScroll = userScrollPositionVertical;
			}
		}
		else
		{
			hScroll = Math.max(0, Math.min(userScrollPositionHorizontal, oDivContent.scrollWidth - oDivContent.offsetWidth));
			vScroll = userScrollPositionVertical;
		}

		if (oEwrHScrollbar != null)
			oEwrHScrollbar.scrollLeft = hScroll;
		doEwrHScroll(hScroll);

		if (oEwrVScrollbar != null)
			oEwrVScrollbar.scrollTop = vScroll;
		doEwrVScroll(vScroll);
	}

	{}
	{}
}

function initToolbarVariables(tableToolbarId)
{
	oTableToolbar = document.getElementById(tableToolbarId);
}

function initChartContentResize(divContent)
{
	oDivContent = document.getElementById(divContent);
}

function initDatasheetContentResize(scrollTable, resultsTable, divContent, ewrHScrollBar, ewrVScrollBar, columnHeadersDiv, rowHeadersDiv)
{
	{}

	oDivContent = document.getElementById(divContent);
	oEwrHScrollbar = document.getElementById(ewrHScrollBar);
	oEwrVScrollbar = document.getElementById(ewrVScrollBar);

	oColumnHeadersDiv = document.getElementById(columnHeadersDiv);
	oRowHeadersDiv = document.getElementById(rowHeadersDiv);

	oResultsTable = document.getElementById(resultsTable);

	var oScrollTable = document.getElementById(scrollTable);
	if (oScrollTable != null)
	{
		oTopCell = oScrollTable.rows[0].cells[1];
		oLeftCell = oScrollTable.rows[1].cells[0];
		oRightCell = oScrollTable.rows[1].cells[2];
		oBottomCell = oScrollTable.rows[2].cells[1];

		oTopRightCell = oScrollTable.rows[0].cells[2];
		oBottomLeftCell = oScrollTable.rows[2].cells[0];
		oBottomRightCell = oScrollTable.rows[2].cells[2];
	}

	{}
	{}
}

function getBottomOffset()
{

	var bottomOffset = 0;
	if (VerticallyLimitingControls != null)
	{
		for (var i=0; i < VerticallyLimitingControls.length; i++)
		{
			bottomOffset += VerticallyLimitingControls[i].offsetHeight;
		}
	}

	return bottomOffset;
}

function getSideOffset()
{

	var sideOffset = 0;
	if (HorizontallyLimitingControls != null)
	{
		for (var i = 0; i < HorizontallyLimitingControls.length; i++)
		{
			sideOffset += HorizontallyLimitingControls[i].offsetWidth;
		}
	}

	return sideOffset;
}

function doContentResize()
{

	if (oDivContent == null)
		return;

	{}

	var hShowCurrent = false;
	var vShowCurrent = false;

	if (oEwrVScrollbar != null && oEwrHScrollbar != null)
	{
		hShowCurrent = (oEwrHScrollbar.style.display == 'block');
		vShowCurrent = (oEwrVScrollbar.style.display == 'block');
	}

	var bottomOffset = getBottomOffset();

	var sideOffset = getSideOffset();

	internalContentResize(bottomOffset, sideOffset);

	if (oResultsTable != null && oEwrVScrollbar != null && oEwrHScrollbar != null)
	{

		var wDelta = oDivContent.clientWidth - oResultsTable.offsetWidth;
		var hDelta = oDivContent.clientHeight - oResultsTable.offsetHeight;

		var hShow = wDelta < 0;
		var vShow = hDelta < 0;

		if (hShow && vShow &&
			((hShowCurrent && vShowCurrent || !hShowCurrent && !vShowCurrent)) &&
			wDelta < 0 && wDelta > -getScrollBarSize() &&
			hDelta < 0 && hDelta > -getScrollBarSize())
		{
			hShow = vShow = false;
		}

		oEwrHScrollbar.style.display = hShow ? 'block':'none';
		oEwrVScrollbar.style.display = vShow ? 'block':'none';

		oTopRightCell.style.visibility = vShow ? 'visible' : 'hidden';
		oBottomLeftCell.style.visibility = hShow ? 'visible' : 'hidden';
		oBottomRightCell.style.visibility = (vShow || hShow) ? 'visible' : 'hidden';

		internalContentResize(bottomOffset, sideOffset);
	}

	{}
}

function sizeParentToChild(parentElementId, childElementId, matchWidth, matchHeight)
{
	var parentElement = document.getElementById(parentElementId);
	var childElement = document.getElementById(childElementId);

	if (parentElement == null || childElement == null)
	{
		return;
	}

	if (matchWidth)
	{
		var newWidth = ((childElement.clientWidth)+'px');
		if (parentElement.style.width != newWidth)
		{
			parentElement.style.width  = newWidth;
		}
	}

	if (matchHeight)
	{
		var newHeight = ((childElement.clientHeight)+'px');
		if (parentElement.style.height != newHeight)
		{
			parentElement.style.height  = newHeight;
		}
	}
}

function getMinToolbarWidth()
{

	if (oTableToolbar != null)
	{

		if (minToolbarWidth < 0)
		{
			minToolbarWidth = getUnwrappedWidth(oTableToolbar);
		}
	}
	else
	{
		minToolbarWidth = 0;
	}

	return minToolbarWidth;
}

function internalContentResize(bottomOffset, sideOffset)
{
	try{
	var oBody = document.body;

	var bottomOffsetTotal = bottomOffset;
	if (oBottomCell != null)
	{
		bottomOffsetTotal += oBottomCell.offsetHeight;
	}

	var topOffsetTotal = 0;
	if (oTopCell != null)
	{
		topOffsetTotal = getObjectOffsetTop(oTopCell) + oTopCell.offsetHeight;
	}
	else
	{
		topOffsetTotal = getObjectOffsetTop(oDivContent);
	}

	var height = Math.max(1, oBody.clientHeight - topOffsetTotal - bottomOffsetTotal);

	if (((height)+'px') != oDivContent.style.height)
	{

		var heightStr =  ((height)+'px');
		oDivContent.style.height = heightStr;

		if (oRowHeadersDiv != null)
			oRowHeadersDiv.style.height = heightStr;;

		if (oEwrVScrollbar != null)
			oEwrVScrollbar.style.height = heightStr;

		{}
	}

	var sideOffsetTotal = sideOffset + 1;
	if (oLeftCell != null)
	{
		sideOffsetTotal += oLeftCell.offsetWidth;
	}

	if (oRightCell != null)
	{
		sideOffsetTotal += oRightCell.offsetWidth;
	}

	var toolbarOrBodyWidth = Math.max(oBody.clientWidth, getMinToolbarWidth())

	var width = Math.max(1, toolbarOrBodyWidth - sideOffsetTotal);

	if (width == 1 || ((width)+'px') != oDivContent.style.width)
	{

		var widthStr =  ((width)+'px');
		oDivContent.style.width = widthStr;

		if (oColumnHeadersDiv != null)
		{
			oColumnHeadersDiv.style.width = widthStr;

			if (RtlSheet && !browseris.ie)
			{
				oColumnHeadersDiv.style.position = "relative";
				oColumnHeadersDiv.style.right = "1px";
			}
		}

		if (oEwrHScrollbar != null)
			oEwrHScrollbar.style.width = widthStr;

		{}
	}

	}catch(ex){}
}

function getSheetContainerMainCellHeight()
{
	if (oDivContent != null)
	{

		var realContentTop = getObjectOffsetTop(oDivContent) + oDivContent.scrollTop;
		var bordersAndPadding = document.body.clientHeight - realContentTop - getBottomOffset() - oDivContent.offsetHeight;

		return oDivContent.offsetHeight + bordersAndPadding;
	}
	return 0;
}

function getObjectOffsetTop(o)
{
	var offset = 0;
	var oCurrent;
	var oBody = window.document.body;
	if (oBody.clientTop != undefined)
	{
		offset = oBody.clientTop;

		for (oCurrent = o; oCurrent && oCurrent != oBody; oCurrent = oCurrent.offsetParent)
		{
			offset += oCurrent.offsetTop - oCurrent.scrollTop;
		}

		if (oCurrent)
		{
			offset += oCurrent.clientTop - oCurrent.scrollTop;
		}
	}
	else
	{
		for (oCurrent = o; oCurrent && oCurrent != oBody; oCurrent = oCurrent.offsetParent)
		{
			offset += oCurrent.offsetTop;
		}
	}

	return offset;
}

var scrollMetricCalcFlag = false;

var scrollMetricCxCy       = 16;

function getScrollBarSize()
{
	try{
	if (!scrollMetricCalcFlag)
	{

		var elem = document.createElement("DIV");

		elem.style.top = "0";
		elem.style.left = "0";
		elem.style.width = 100;
		elem.style.height = 100;
		elem.style.overflow = "scroll";
		elem.style.position = "absolute";
		elem.style.visibility = "hidden";

		document.body.appendChild(elem);

		scrollMetricCxCy = elem.offsetWidth - elem.clientWidth;

		document.body.removeChild(elem);
	}
	}catch(ex){}

	scrollMetricCalcFlag = true;

	return scrollMetricCxCy;
}

function doEwrVScroll(contentDivScrollTop)
{
	try { MenuHtc_hide(); } catch(ex){}; 

	oDivContent.scrollTop = contentDivScrollTop;
	if (oRowHeadersDiv != null)
		oRowHeadersDiv.scrollTop = contentDivScrollTop;

	if (userScrollPositionVerticalInput != null)
		userScrollPositionVerticalInput.value = oDivContent.scrollTop;
}

function EwrVScroll(event)
{
	doEwrVScroll(getSrcElement(event).scrollTop);
}

function doEwrHScroll(contentDivScrollLeft)
{
	try { MenuHtc_hide(); } catch(ex){}; 

	oDivContent.scrollLeft = contentDivScrollLeft;
	if (oColumnHeadersDiv != null)
		oColumnHeadersDiv.scrollLeft = contentDivScrollLeft;

	if (userScrollPositionHorizontalInput != null)
	{
		if (!RtlSheet)
		{
			userScrollPositionHorizontalInput.value = oDivContent.scrollLeft;
		}
		else
		{
			userScrollPositionHorizontalInput.value = oDivContent.scrollWidth - oDivContent.scrollLeft;
		}
	}
}

function EwrHScroll(event)
{
	doEwrHScroll(getSrcElement(event).scrollLeft);
}

function EwrVSheetScroll(event)
{
	try { MenuHtc_hide(); } catch(ex){}; 

	if (event.wheelDelta != undefined)
	{

		oEwrVScrollbar.scrollTop = oDivContent.scrollTop - (event.wheelDelta / 2);

		if (oEwrVScrollbar.scrollTop == 0 || oEwrVScrollbar.scrollHeight - oEwrVScrollbar.scrollTop == oEwrVScrollbar.offsetHeight)
			return true;
	}

	event.cancelBubble = true;
	return false;
}

function EwrHSheetScroll(event)
{
	try { MenuHtc_hide(); } catch(ex){}; 

	oEwrHScrollbar.scrollLeft = oDivContent.scrollLeft;

	if (oEwrHScrollbar.scrollLeft == 0 || oEwrHScrollbar.scrollWidth - oEwrHScrollbar.scrollLeft == oEwrHScrollbar.offsetWidth)
		return true;

	event.cancelBubble = true;
	return false;
}

var firstVisSheetCellIdx = 0;

function ScrollRightTo(oRow, oDiv, maxIdx)
{

	var clientWidth = oDiv.clientWidth;

	var inBoundTargetIdx = Math.min(maxIdx, oRow.cells.length - 1);
	while (firstVisSheetCellIdx < inBoundTargetIdx && oDiv.scrollWidth > oDiv.clientWidth)
	{

		oRow.cells[firstVisSheetCellIdx].style.display = "none";
		++firstVisSheetCellIdx;
	}
}

function ShowSheetTab(cell)
{

	try
	{
		cell.style.display = "table-cell";
	}
	catch (ex)
	{
		cell.style.display = "block";
	}
}

function ScrollLeftTo(oRow, oDiv, minIdx)
{

	var inBoundTargetIdx = Math.max(minIdx, 0);
	while (firstVisSheetCellIdx > inBoundTargetIdx)
	{

		--firstVisSheetCellIdx;

		ShowSheetTab(oRow.cells[firstVisSheetCellIdx]);
	}

	if (firstVisSheetCellIdx == 0)
	{
		ShowSheetTab(oRow.cells[firstVisSheetCellIdx]);
	}
}

function ScrollSheetTabs(operation)
{
	try{

	var oDiv = document.getElementById(sheetTabScrollDivElmId);
	if (oDiv == null) return;

	var oTable = getChildren(oDiv)[0];
	if (oTable == null) return;

	var oRow = oTable.rows[0];
	if (oRow == null) return;

	if (oRow.cells.length == 0)
		return;

	switch(operation)
	{
		case "First":
			ScrollLeftTo(oRow, oDiv, 0);
			break;

		case "Left":
			ScrollLeftTo(oRow, oDiv, firstVisSheetCellIdx - 1);
			break;

		case "Right":
			ScrollRightTo(oRow, oDiv, firstVisSheetCellIdx + 1);
			break;

		case "Last":
			ScrollRightTo(oRow, oDiv, oRow.cells.length - 1);
			break;

		case "FormIdx":
		{

			if (oFirstVisSheetTabIdxHiddenElm == null)
				break;

			var tempIdx = Math.min(Math.max(0, oFirstVisSheetTabIdxHiddenElm.value), oRow.cells.length-1);

			if (oDiv.scrollWidth != oDiv.clientWidth)
			{
				if (tempIdx == firstVisSheetCellIdx)		
					;
				else if (tempIdx > firstVisSheetCellIdx)	
					ScrollRightTo(oRow, oDiv, tempIdx);
				else										
					ScrollLeftTo(oRow, oDiv, tempIdx);
			}

			break;
		}
	}

	if (oFirstVisSheetTabIdxHiddenElm != null)
	{
		oFirstVisSheetTabIdxHiddenElm.value = firstVisSheetCellIdx;
	}

	}catch(ex){}
}

function SetNotificationDelay(divId, timeout)
{
	var divNotification = document.getElementById(divId);
	if (divNotification == null)
	{
		return;
	}

	divNotification.flashes = 0; 

	if (timeout == 0)
	{
		ShowNotification(divId, false);
	}
	else
	{
		window.setTimeout("ShowNotification('" + divId + "', true)", timeout);
	}
}

function ShowNotification(divId, shouldBlink)
{
	var divNotification = document.getElementById(divId);
	if (divNotification == null)
	{
		return;
	}

	if (divNotification.style.display == "none") 
	{
		divNotification.style.display = "block";
		if (shouldBlink)
			divNotification.style.height = "1px";
		else
			divNotification.style.height = ((20)+'px');

		var notificationRow = getNotificationRow(divNotification);
		notificationRow.style.display = "block";
	}

	if (divNotification.clientHeight < 20)
	{
		divNotification.style.height = ((divNotification.clientHeight+1)+'px');
		doEwrResize();
		window.setTimeout("ShowNotification('" + divId + "', " + shouldBlink + ")", 50);
	}
	else
	{
		if (shouldBlink == true)
		{

			window.setTimeout("flashNotification('" + divId + "')", 100);
		}
		else
		{

			notificationFlashState(divNotification, true);
		}
	}
}

function HideNotification(divId)
{
	var divNotification = document.getElementById(divId);
	if (divNotification == null)
	{
		return;
	}

	divNotification.style.display = "none";
	var notificationRow = getNotificationRow(divNotification);
	notificationRow.style.display = "none";

	doEwrResize();
}

function getNotificationRow(div)
{
	var parent = getParentElement(div);
	while (parent != null)
	{
		if (parent.className == "ewr-notificationbar-row")
			return parent;
		parent = getParentElement(parent);
	}
	return null;
}

function flashNotification(divId)
{
	var divNotification = document.getElementById(divId);
	if (divNotification == null)
	{
		return;
	}

	if (divNotification.flashes < 7)
	{
		var tblNotification = getChildren(divNotification)[0];
		if (tblNotification != null)
		{
			notificationFlashState(divNotification, divNotification.flashes % 2 == 0);
			divNotification.flashes++;
			window.setTimeout("flashNotification('" + divId + "')", 500);
		}
	}
}

function notificationFlashState(divNotification, flashed)
{
	var tblNotification = getChildren(divNotification)[0];
	if (tblNotification == null)
		return;

	if (flashed)
		tblNotification.className = "ewr-notification-flash";
	else
		tblNotification.className = "ewr-notification";
}

function notificationNever(divId, neverElementId)
{
	var oNotificationDiv = document.getElementById(divId);
	var oNever = document.getElementById(neverElementId);
	if (oNotificationDiv == null || oNever == null)
	{
		return;
	}

	HideNotification(divId);
	oNever.value = "never";
}

function DeferredShowWaitElement(ewrWaitId, ewrFrameId, forceRemove)
{
	try{
	var ewrWait = document.getElementById(ewrWaitId);
	if (ewrWait == null)
	{
		return;
	}

	{};

	if (!forceRemove)
	{
		var newVal = getAttribute(ewrWait, "ShouldShowWait");
		{};
		if (newVal == null)
		{
			return;
		}
	}

	var frame = document.getElementById(ewrFrameId);
	if (getAttribute(frame, "EwrStatus") != "loading" || forceRemove)
	{
		newVal = "none";
	}

	if (newVal == "none")
	{
		if (frame.style.visibility != "visible")
		{
			frame.style.visibility = "visible";
		}
	}
	else
	{
		if (frame.style.visibility != "hidden")
		{
			frame.style.visibility = "hidden";
		}
	}

	if (ewrWait.style.display != newVal)
	{
		ewrWait.style.display = newVal;
		{};
	}

	{};

	}catch(ex){}
}

function ShowWaitElement(ewrWait, ewrFrameId, show, winParam, forceRemove)
{
	try{
	var newValue;
	var timeout;
	if (show)
	{
		newValue = "block";
		timeout = 5000;
	}
	else
	{
		newValue = "none";
		timeout = 0;
	}

	ewrWait.setAttribute("ShouldShowWait", newValue);
	var frame = winParam.document.getElementById(ewrFrameId);
	frame.setAttribute("EwrStatus", "loading");

	var timerId = getAttribute(ewrWait, "TimerId");
	if (timerId != null)
	{
		winParam.clearTimeout(timerId);
		{};
	}

	{};
	timerId = winParam.setTimeout("DeferredShowWaitElement('" + ewrWait.id + "','" +  ewrFrameId + "', " + forceRemove + ");", timeout);

	ewrWait.setAttribute("TimerId", timerId);
	}catch(ex){}
}

function EwrFrameReadyStateChanged(ewrFrameId, ewrWaitId)
{
	try{

	var ewrFrame = document.getElementById(ewrFrameId);
	var ewrWait = document.getElementById(ewrWaitId);

	if (ewrFrame == null)
	{
		return;
	}

	{};

	var innerDoc = ewrFrame.contentWindow.document;
	var innerForm = innerDoc.forms[0];

	var wbid = EwrFindInputField(innerForm, "wbid", "true");
	if (wbid == null)
	{

		return;
	}

	var outerForm = GetFormParent(ewrFrame);
	var outerWbid = EwrFindInputField(outerForm, "wbid", ewrFrameId);
	if (outerWbid == null)
	{
		return;
	}
	outerWbid.value = wbid.value;

	if (ewrFrame.attributes["EwrStatus"].value == "cancellingLoad")
	{
		ewrFrame.attributes["EwrStatus"].value = "";
	}
	else
	{
		ewrFrame.attributes["EwrStatus"].value = "loaded";
	}

	{};
	ShowWaitElement(ewrWait, ewrFrameId, false, window, false);

	var cancelId = getAttribute(ewrFrame, "cancelButtonId");
	if (cancelId != null &&
		cancelId != "")
	{
		var cancelButton = document.getElementById(cancelId);
		cancelButton.disabled = false;
	}

	}catch(ex){}
}

function EwaReloadWorkbook(id)
{
	var ewrTopControl = document.getElementById(id);
	if (ewrTopControl == null)
	{
		return false;
	}

	var frame = EwrFindElementByAttributeHelper(ewrTopControl, "IsEwrMainIframe");
	if (frame == null)
	{
		return false;
	}

	var frameWindow = frame.contentWindow;
	if (frameWindow == null)
	{
		return false;
	}

	frameWindow.execScript("ReloadWorkbook()", "javascript");
	return true;
}

function EwaGetSessionId(id)
{
	var ewrTopControl = document.getElementById(id);
	if (ewrTopControl == null)
	{
		return null;
	}

	var frame = EwrFindElementByAttributeHelper(ewrTopControl, "IsEwrMainIframe");
	if (frame == null)
	{
		return null;
	}

	var frameDocument = frame.contentWindow.document;
	if (frameDocument == null)
	{
		return null;
	}

	var mainForm = frameDocument.forms[0];
	if (mainForm == null)
	{
		return null;
	}

	var wbidInput = EwrFindInputField(mainForm, "wbid", "true");
	if (wbidInput == null)
	{
		return null;
	}

	if (wbidInput.value.length == 0)
	{
		return null;
	}

	return wbidInput.value;
}

function getWebPartTable(startingElement)
{
	var elem = getElement(startingElement, null, false, "TABLE");

	while (elem != null)
	{
		if (getAttribute(elem, "TOPLEVEL") != null)
		{
			return elem;
		}

		elem = getParentElement(elem);
		elem = getElement(elem, null, false, "TABLE");
	}

	return null;
}

function resizeToAccomodateToolbar()
{
	try{

	{};

	var minWidth = getMinToolbarWidth();
	var ewrFrame = window.frameElement;

	if (minWidth <= 0 || ewrFrame == null)
	{
		return;
	}

	var outerDoc = ewrFrame.ownerDocument;
	var outerForm = GetFormParent(ewrFrame);
	var outerWbid = EwrFindInputField(outerForm, "wbid", ewrFrame.id);
	if (outerWbid == null)
	{
		return;
	}

	var outerTable = getWebPartTable(ewrFrame);
	var outerDivEwr = getElement(outerWbid, null, false, "DIV");
	var outerDivWebPart = getParentElement(outerDivEwr);
	var elems = new Array(outerTable, outerDivWebPart, outerDivEwr);

	var onViewerPage = (getViewerPageWebPartContainerCell() != null);
	var shouldResize = false;

	if (onViewerPage)
	{
		minWidth = Math.max(minWidth, outerDoc.body.clientWidth);
	}

	for (var i = 0; i < elems.length; i++)
	{
		var elem = elems[i];

		if (elem == null)
		{
			{};
			return;
		}

		if (minWidth > elem.offsetWidth)
		{
			shouldResize = true;
			break;
		}
	}

	if (shouldResize)
	{
		var minWidthStr = ((minWidth)+'px');

		for (var i = 0; i < elems.length; i++)
		{
			var elem = elems[i];
			if (elem.width != undefined && elem.width != null)
			{

				elem.width = "";
			}
			if (minWidthStr != elem.style.width)
			{
				elem.style.width = minWidthStr;
				{}
			}
		}
	}

	{};

	}catch(ex){}
}

function EwrFindInputField(form, attributeName, attributeValue)
{
	if (form==null || form.elements==null)
	{
		return null;
	}
	var i;
	for (i=0; i<form.elements.length;i++)
	{
		var att = form.elements[i].attributes[attributeName];
		if (att!=null && att.value==attributeValue)
		{
			return form.elements[i];
		}
	}
	return null;
}

function EwrCancelRequest(event, ewrFrameId, cancelFrameId)
{
	try{
	try
	{
		getSrcElement(event).disabled = true;
	}
	catch (ex)
	{
	}

	var ewrFrame;
	var ewrDocument;
	ewrFrame = document.getElementById(ewrFrameId);
	if (ewrFrame==null)
	{
		return;
	}	

	ewrFrame.setAttribute("cancelButtonId", getSrcElement(event).id);

	ewrDocument = ewrFrame.contentWindow.document;

	var ewrRenderrerNakedUrl = ewrDocument.location.pathname;
	var params = "?cancel=True";

	var status = getAttribute(ewrFrame, "EwrStatus");
	if (status == null || 
		status == "" || 
		status == "cancellingLoad")
	{
		FillIFrameWithForm(ewrFrameId, true, "");
	}
	else if (status == "loaded" || status == "loading")
	{
		var ewrCancelFrame;
		ewrCancelFrame = document.getElementById(cancelFrameId);
		var innerForm = ewrDocument.forms[0];
		if (innerForm != null)
		{
			var wbidInput = EwrFindInputField(ewrDocument.forms[0], "wbid", "true");
			if (wbidInput != null)
			{
				params += "&wbid=" + encodeURIComponent(wbidInput.value);
			}
		}
		ewrCancelFrame.contentWindow.document.location.assign(ewrRenderrerNakedUrl + params);
	}
	}catch(ex){}
}

function EwrMainPageBeforeUnload()
{
	var newAtt = document.createAttribute("EwrOnBeforeUnload");
	newAtt.value = "True";
	try{
		document.body.attributes.setNamedItem(newAtt);
	}catch(ex){}
}

function ShowWaitElementFromFrame(ewrFrame, show, winParam, forceRemove)
{
	if (ewrFrame == null)
		return;

	var waitElementId = getAttribute(ewrFrame, "EwrWaitElementId");
	if (waitElementId == null)
		return;

	var ewrWaitElm = ewrFrame.ownerDocument.getElementById(waitElementId);
	if (ewrWaitElm == null)
		return;

	ShowWaitElement(ewrWaitElm, ewrFrame.id, show, winParam, forceRemove);
}

function InnerEwrUnloadNotification()
{
	try{

	var ewrFrame = window.frameElement;
	if (ewrFrame == null)	return;

	var parentUnloading = ewrFrame.ownerDocument.body.attributes["EwrOnBeforeUnload"];
	if (parentUnloading == null)
	{
		ShowWaitElementFromFrame(ewrFrame, true, parent, false);
	}
	}catch(ex){}
}

function EwrFindElementByAttribute(attributeName)
{
	try
	{
		return EwrFindElementByAttributeHelper(document, attributeName);
	}
	catch (ex)
	{
	}
	return null;
}

function EwrFindElementByAttributeHelper(elParent, attributeName)
{
	var i;
	var len = getChildren(elParent).length;
	for (i = 0; i < len; i++)
	{
		var el = getChildren(elParent)[i];
		if (el.nodeType == 1)
		{
			var att = el.attributes[attributeName];
			if (att != null)
			{
				return el;
			}
		}
		if (getChildren(el).length > 0)
		{
			var elFound = EwrFindElementByAttributeHelper(el, attributeName);
			if (elFound != null)
			{
				return elFound;
			}
		}
	}
	return null;
}

function FillIFrameWithForm(frameId, cancel, wbid)
{
	var frame = document.getElementById(frameId);
	frame.src = frame.getAttribute("DummyPage");
	window.setTimeout("FillIFrameWithFormDeferred('" + frameId + "'," + cancel + ", false, '" + wbid + "');", 1);
}

function FillIFrameWithFormEx(frameId, cancel, reload, wbid)
{
	var frame = document.getElementById(frameId);
	frame.src = frame.getAttribute("DummyPage");
	window.setTimeout("FillIFrameWithFormDeferred('" + frameId + "'," + cancel + "," + reload + ",'" + wbid + "');", 1);
}

function FillIFrameWithFormDeferred(frameId, cancel, reload, wbid)
{
	var cancelString = "";
	var reloadString = "";
	if (cancel)
	{
		cancelString = "cancel=True&";
	}
	if (reload)
	{
		reloadString = "reload=True&";
	}

	var frame = document.getElementById(frameId);
	var scriptText = getAttribute(frame, "ScriptForIFrameContent");
	scriptText = scriptText.replace(/%cancel%/g, cancelString);
	scriptText = scriptText.replace(/%reload%/g, reloadString);

	try
	{
		var innerDoc = frame.contentWindow.document;
		innerDoc.write(scriptText);
	}
	catch (ex) {};
}

function PollForDocumentCompletion(frameId, justReturn)
{
	var callAgain = true;

	try
	{

		var frame = document.getElementById(frameId);
		if (frame != null && frame.contentWindow!= null)
		{
			var innerDoc = null;
			var host = "";
			var accessDenied = false;
			try
			{
				innerDoc = frame.contentWindow.document;
				host = frame.contentWindow.location.host;
			}
			catch (ex)
			{
				accessDenied = true;
			}
			if (host != "" && (accessDenied || (innerDoc != null && innerDoc.body != null)))
			{

				var initialPage; 
				var ewrPage; 
				if (!accessDenied)
				{
					initialPage = getAttribute(innerDoc.body, "IAmTheInitialPage");
					ewrPage = getAttribute(innerDoc.body, "IAmTheInnerPage");
				}
				if (accessDenied || (initialPage == null && ewrPage == null)) 
				{
					if (frame.readyState == "complete")
					{
						ShowWaitElementFromFrame(frame, false, window, true);
						callAgain = false;
					}
				}
			}
		}
	}
	catch (ex)
	{
	}
	if (!justReturn && callAgain == true)
	{
		var code = "PollForDocumentCompletion('" + frameId + "', false);";
		setTimeout(code, 2000, "javascript");
	}
	return callAgain; 
}

function ReloadWorkbook()
{
	var frame = window.frameElement;
	crossWindowFromDocument(frame.ownerDocument).setTimeout("FillIFrameWithFormEx('" + frame.id + "',false,true, '');", 0);
}

function ReloadWorkbookEx()
{
	var frame = window.frameElement;

	crossWindowFromDocument(frame.ownerDocument).setTimeout("FillIFrameWithFormEx('" + frame.id + "',false,true, '');", 0);
}

function InnerEwrLoadNotification(calledFromOnLoad)
{
	try{

	{}

	doEwrResize();

	if (!InnerEwrLoadNotificationCalled)
	{

		InnerEwrLoadNotificationCalled = true;

		setContentDivScrollPosition();
		ScrollSheetTabs('FormIdx');

		ShowWaitElementFromFrame(window.frameElement, false, parent, false);
	}

	if (calledFromOnLoad && window.frameElement != null)
	{
		var waitID = getAttribute(window.frameElement, "EwrWaitElementId");
		crossWindowFromDocument(window.frameElement.ownerDocument).setTimeout("EwrFrameReadyStateChanged('" + window.frameElement.id + "', '" + waitID + "')", 0);
	}

	{}
	{}

	}catch(ex){}
}

function GetFormParent(el)
{
	while (el!=null)
	{
		if (el.tagName=="FORM")
			return el;
		el = el.parentNode;
	}
	return null;
}

function toggleMenu(menuId, parent)
{

	if (typeof(menuId) == "string")
	{
		menuId = document.getElementById(menuId);
	}

	if (MenuHtc_isOpen(menuId))
	{
		MenuHtc_hide();
	}
	else
	{
		OMenu(menuId, parent);
	}

	window.onresize = doEwrResize;

	window.event.cancelBubble=true;
	return false;
}

function toggleDrill(div)
{
	try{

	var tdParent = getElement(div, null, false, "TD")
	if (tdParent != null)
	{
		return tdParent.ondblclick();
	}
	}catch(ex){}

	return false;
}

var FilterFields = null;

function initFilterFieldsArray()
{

	if (FilterFields != null)
		return;

	{}

	FilterFields = new Array();
	for (var i=0; i < FieldIdsArray.length; i++)
	{
		FilterFields[i] = document.getElementById(FieldIdsArray[i]);
	}

	{}

}

function isLeftClickOrKbActivation(event)
{
	var mouseButton = getMouseButton(event);
	return (mouseButton == -1 || mouseButton == 1);
}

function onAutoFilter(event, menuId, filterId, filterType, filterRow, filterColumn)
{

	if (!isLeftClickOrKbActivation(event))
		return false;

	initFilterFieldsArray();

	FilterFields[0].value = filterId;
	FilterFields[1].value = filterType;
	FilterFields[2].value = filterRow;
	FilterFields[3].value = filterColumn;

	return toggleMenu(menuId, getSrcElement(window.event));
}

function setPivotCommand(command)
{

	initFilterFieldsArray();

	FilterFields[13].value = command;
}

function setCriteriaTypeParams(fieldId, filterType, filterColumn)
{

	initFilterFieldsArray();

	FilterFields[0].value = fieldId;
	FilterFields[1].value = filterType;
	FilterFields[3].value = filterColumn;
}

function setPivotFieldId(fieldId, sourceIndex)
{

	initFilterFieldsArray();

	FilterFields[0].value = fieldId;
	FilterFields[9].value = sourceIndex;
}

function setPivotDrillParams(rowIndex, columnIndex, sourceIndex)
{

	initFilterFieldsArray();

	FilterFields[2].value = rowIndex;
	FilterFields[3].value = columnIndex;
	FilterFields[9].value = sourceIndex;
}

function setPivotFilterParams(filterType, rowIndex, columnIndex, sourceIndex)
{

	initFilterFieldsArray();

	FilterFields[2].value = rowIndex;
	FilterFields[3].value = columnIndex;
	FilterFields[9].value = sourceIndex;
	FilterFields[1].value = filterType;
}

function pvtDrill(confirm, rowIndex, columnIndex, sourceIndex)
{
	if (!confirm || (confirm && getUserRefreshConfirm(oPivotRefreshConfirmationString)))
	{
		setPivotDrillParams(rowIndex, columnIndex, sourceIndex);
		submitFilterCommand("ToggleDrill");
	}

	return false;
}

var oFilterPostBack;

function showFilter(event, filterPageUrl, confirmationRequired, filterPostBack)
{

	if (!isLeftClickOrKbActivation(event))
		return false;

	initFilterFieldsArray();

	FilterFields[15] = confirmationRequired;

	if (confirmationRequired && !getUserRefreshConfirm(oPivotRefreshConfirmationString))
		return false;

	oFilterPostBack = new Function(filterPostBack);

	var width = 220;
	var height = 350;

	var sFeatures;
	sFeatures = "dialogHeight:" + height + "px;";
	sFeatures += "dialogWidth:" + width + "px;";
	sFeatures += "resizable:yes;";
	sFeatures += "help:no;";
	sFeatures += "status:no;";
	sFeatures += "scroll:no;";
	sFeatures += "titlebar;";
	sFeatures += "dependent;";

	MenuHtc_hide(); 

	commonShowModalDialog(filterPageUrl, sFeatures, showFilterCallback);
}

function showFilterCallback(retval)
{
	if (oFilterPostBack == null || retval == null) return;

	initFilterFieldsArray();

	var error = retval.error;
	if (error != null)
	{
		FilterFields[1].value = error;
		oFilterPostBack();
		return;
	}

	var checkedItems = "";
	if (retval.checkedItems != null)
	{
		var retCheckedItems = retval.checkedItems;
		for (var i=0; i < retCheckedItems.length; i++)
		{
			checkedItems += retCheckedItems[i]; 
			if (i < retCheckedItems.length-1)
				checkedItems += "&";
		}
	}

	FilterFields[7].value = checkedItems;

	if (retval.stateId != null)
		setUpdatedStateId(retval.stateId);

	if (retval.canceled)
		return;

	oFilterPostBack();
}

function setUpdatedStateId(stateId)
{
	var innerDoc = window.frameElement.contentWindow.document;
	var innerForm = innerDoc.forms[0];
	var oHiddenStateIdField = EwrFindInputField(innerForm, "updatedStateId", "true");

	if (oHiddenStateIdField != null)
		oHiddenStateIdField.value = stateId;
}

var oTop10PostBack;

function showTop10(top10PageUrl, top10PostBack, filterType, dataFieldIdsArray, dataFieldNamesArrray, activeDataField)
{
	try{

	FilterFields[1].value = filterType;
	oTop10PostBack = new Function(top10PostBack);

	var dialogArgs = null;
	if (dataFieldIdsArray != null && dataFieldNamesArrray != null)
		dialogArgs = new Array(dataFieldIdsArray, dataFieldNamesArrray, activeDataField);

	var width = 300;
	var height = 100;

	var sFeatures;
	sFeatures = "dialogHeight:" + height + "px;";
	sFeatures += "dialogWidth:" + width + "px;";
	sFeatures += "resizable:no;";
	sFeatures += "help:no;";
	sFeatures += "status:no;";
	sFeatures += "scroll:no;";
	sFeatures += "titlebar;";
	sFeatures += "dependent;";

	MenuHtc_hide(); 

	commonShowModalDialog(top10PageUrl, sFeatures, showTop10Callback, dialogArgs);

	}catch(ex){}
}

function top10Params()
{
	var top;
	var count;
	var type;
	var dataField;
}

function showTop10Callback(retval)
{
	if (oTop10PostBack == null || retval == null) return;

	var top10Params = retval;

	initFilterFieldsArray();

	FilterFields[8].value = top10Params.dataField;
	FilterFields[4].value = top10Params.top;
	FilterFields[5].value = top10Params.count;
	FilterFields[6].value = top10Params.type;

	oTop10PostBack();
}

var oCurrentDropDown = null;
var oRefreshConfirmed = false;
var oPivotRefreshConfirmationString;

function showPivotFilterMenu(event, filterType, filterRow, filterColumn, callbackFunction, confirmationRequired, asyncImageSrc)
{

	if (!isLeftClickOrKbActivation(event))
		return false;

	event.cancelBubble = true;

	initFilterFieldsArray();

	FilterFields[15] = confirmationRequired;

	if (confirmationRequired && !getUserRefreshConfirm(oPivotRefreshConfirmationString))
		return false;

	var dropDownImage = getSrcElement(event);
	var parentElement = getParentElement(dropDownImage);
	var oSpan = parentElement.lastChild;
	if (oSpan.nodeType == 1 && oSpan.tagName != null && oSpan.tagName.toLowerCase() == "span")
	{

		var oMenu = oSpan.firstChild;
		if (oMenu.nodeType == 1 && oMenu.tagName != null && oMenu.tagName.toLowerCase() == "menu")
		{

			FilterFields[1].value = filterType;
			FilterFields[2].value = filterRow;
			FilterFields[3].value = filterColumn;

			toggleMenu(oMenu, dropDownImage);
			return false;
		}
	}

	if (dropDownImage.fetchError != null)
	{
		alert(dropDownImage.fetchError);
		return false;
	}

	if (dropDownImage.fetching != null)
	{
		return false;
	}

	dropDownImage.fetching = true;

	setAsynchOperationProgressImage(dropDownImage, true, asyncImageSrc);

	oCurrentDropDown = dropDownImage;
	oCurrentDropDown.setCapture();
	oCurrentDropDown.onmousedown = asyncMenuCaptureHandler;

	FilterFields[1].value = filterType;
	FilterFields[2].value = filterRow;
	FilterFields[3].value = filterColumn;

	var oCallbackFunction = new Function(callbackFunction);
	oCallbackFunction();

	return false;
}

function asyncMenuCaptureHandler()
{
	releaseAsyncMenuCapture();
	oCurrentDropDown = null;
}

function releaseAsyncMenuCapture()
{
	if (oCurrentDropDown != null)
	{
		oCurrentDropDown.releaseCapture();
	}
}

function setAsynchOperationProgressImage(element, asyncInProgress, asyncImageSrc)
{

	var imageElement = null;

	switch (element.tagName.toLowerCase())
	{

		case "input":
		case "img":
			imageElement = element;
			break;
	}

	if (imageElement == null)
	{

		return;
	}

	if (getAttribute(imageElement, "src") == null)
	{

		return;
	};

	var objHasAsyncMarkers = getAttribute(imageElement, "asyncSrc") != null;
	if ((asyncInProgress && objHasAsyncMarkers) || (!asyncInProgress && !objHasAsyncMarkers))
	{
		return;
	}

	if (asyncInProgress)
	{

		imageElement.setAttribute("asyncSrc", getAttribute(imageElement, "src"));

		imageElement.setAttribute("src", asyncImageSrc);
	}

	else
	{

		imageElement.setAttribute("src", getAttribute(imageElement, "asyncSrc"));

		imageElement.setAttribute("asyncSrc", null);
	}
}

function getMenuSucceeded(arg, context)
{

	var	dropDownImage = document.getElementById(context);
	if (dropDownImage == null) 
		return;

	var xmlDoc = createXmlReader(arg);
	var rootNode = selectSingleNode(xmlDoc, "MenuResponse");
	if (rootNode == null)
		return;

	var errorNode = selectSingleNode(rootNode, "ErrorMessage");
	if (errorNode != null)
	{
		releaseAsyncMenuCapture();
		dropDownImage.fetching = null;
		alert(errorNode.text);

		var errorAction = selectSingleNode(rootNode, "ErrorAction");
		if (errorAction != null)
		{
			return new Function(errorAction.text)();
		}

		return;
	}

	var menuNode = selectSingleNode(rootNode, "FilterMenu");
	if (menuNode == null)
		return;

	var elem = document.createElement('span');
	elem.innerHTML = menuNode.text;

	getParentElement(dropDownImage).appendChild(elem);

	var dataArraysXml = selectSingleNode(rootNode, "DataArrays");
	if (dataArraysXml != null)
		new Function(dataArraysXml.text)();

	if (oCurrentDropDown != null && oCurrentDropDown.id == dropDownImage.id)
	{
		releaseAsyncMenuCapture();
		OMenu(elem.firstChild, dropDownImage);
	}

	dropDownImage.fetching = false;
	setAsynchOperationProgressImage(dropDownImage, false);
}

function getMenuFailed(arg, context)
{
	var	dropDownImage = document.getElementById(context);
	if (dropDownImage != null)
	{

		dropDownImage.fetchError = arg;

		if (oCurrentDropDown != null && oCurrentDropDown.id == dropDownImage.id)
		{
			alert(arg);
		}

		dropDownImage.fetching = null;
	}
}

var oFindWin = null;
var oFindTextHiddenElement = null;
var oFindDirectionHiddenElement = null;
var oFindPostBack = null;

function findParams()
{
	var direction;
	var findText;
}

function showFind(findPageUrl, doPostbackFunc, findText, direction)
{
	try{

	oFindPostBack = new Function(doPostbackFunc);

	oFindTextHiddenElement = document.getElementById(findText);
	oFindDirectionHiddenElement = document.getElementById(direction);

	var width = 400;
	var height = 115;

	var sFeatures;
	sFeatures = "dialogHeight:" + height + "px;";
	sFeatures += "dialogWidth:" + width + "px;";
	sFeatures += "resizable:no;";
	sFeatures += "help:no;";
	sFeatures += "status:no;";
	sFeatures += "scroll:no;";
	sFeatures += "titlebar;";
	sFeatures += "dependent;";

	commonShowModalDialog(findPageUrl, sFeatures, showFindCallback);

	return false;
	}catch(ex){}
}

function showFindCallback(retval)
{
	if (oFindPostBack == null || retval == null) return;

	topFindParams = retval;
	oFindTextHiddenElement.value = topFindParams.findText;
	oFindDirectionHiddenElement.value = topFindParams.direction;

	oFindPostBack();	
}

var oCustomFilterCallback;

function customFilterParams()
{
	var compareType;
	var value1;
	var value2;
	var dataField;
}

function showCustomFilter(customFilterPageUrl, customFilterPostBack, filterType, memberProperties, dataFieldIdsArray, dataFieldNamesArrray, activeDataField)
{
	try{

	initFilterFieldsArray();

	FilterFields[1].value = filterType;
	FilterFields[14].value = memberProperties;
	oCustomFilterCallback = new Function(customFilterPostBack);

	var dialogArgs = null;
	if (dataFieldIdsArray != null && dataFieldNamesArrray != null)
		dialogArgs = new Array(dataFieldIdsArray, dataFieldNamesArrray, activeDataField);

	var width = 300;
	var height = 100;

	var sFeatures;
	sFeatures = "dialogHeight:" + height + "px;";
	sFeatures += "dialogWidth:" + width + "px;";
	sFeatures += "resizable:no;";
	sFeatures += "help:no;";
	sFeatures += "status:no;";
	sFeatures += "scroll:no;";
	sFeatures += "titlebar;";
	sFeatures += "dependent;";

	MenuHtc_hide(); 

	commonShowModalDialog(customFilterPageUrl, sFeatures, showCustomFilterCallback, dialogArgs);

	}catch(ex){}
}

function showCustomFilterCallback(retval)
{
	if (oCustomFilterCallback == null || retval == null) return;

	customFilterParams = retval;

	initFilterFieldsArray();

	FilterFields[10].value = customFilterParams.compareType;
	FilterFields[11].value = customFilterParams.value1;
	FilterFields[12].value = customFilterParams.value2;
	FilterFields[8].value = customFilterParams.dataField;

	oCustomFilterCallback();	
}

var oConfirmationMessage = null;
var oNoDataObjMessage = null;

function doPostbackOnUserConfirm(postback, confirmationRequired)
{
	if (confirmationRequired && !getUserRefreshConfirm(oConfirmationMessage))
		return false;

	var callbackFunc = new Function(postback);
		callbackFunc();
}

function doManualRefresh(hiddenConnectionNameId, rangesArray, postback, confirmationRequired)
{
	var hidden = document.getElementById(hiddenConnectionNameId);
	if (hidden == null) return;

	var cell = HighlightedCell;
	if (cell == null || rangesArray == null || rangesArray.length == 0)
	{
		alert(oNoDataObjMessage);
		return;
	}

	var rowIndex = getParentElement(cell).rowIndex;
	var columnIndex = getCellRealIndex(cell);

	var inRange = false;
	for (var i=0; i < rangesArray.length; i++)
	{
		if (rowIndex >= rangesArray[i][0] &&
			rowIndex <= rangesArray[i][2] &&
			columnIndex >= rangesArray[i][1] &&
			columnIndex <= rangesArray[i][3])
		{

			hidden.value = rangesArray[i][4];
			inRange = true;
			break;
		}
	}

	if (inRange)
	{
		if (confirmationRequired && !getUserRefreshConfirm(oConfirmationMessage))
			return;
		var callbackFunc = new Function(postback);
		callbackFunc();
	}
	else
	{
		alert(oNoDataObjMessage);
	}
}

function doNovManualRefresh(hiddenConnectionNameId, connectionName, postback, confirmationRequired)
{
	var hidden = document.getElementById(hiddenConnectionNameId);
	if (hidden == null) return;

	if (confirmationRequired && !getUserRefreshConfirm(oConfirmationMessage))
			return;

	hidden.value = connectionName;
	var callbackFunc = new Function(postback);
	callbackFunc();
}

function getUserRefreshConfirm(message)
{

	if (oRefreshConfirmed)
		return true;

	if (message == null)
	{

		return false;
	}

	if (confirm(message))
	{
		oRefreshConfirmed = true;
	}

	return oRefreshConfirmed;
}

function getCellRealIndex(cell)
{

	var cells = getParentElement(cell).cells;
	var cellIndex = cell.cellIndex;

	var columnIndex = cellIndex;

	for (var i = 0; i <= cellIndex; ++i)
	{
		var ewrColumnIndex = getAttribute(cells[cellIndex - i], "EwrColumnIndex");
		if (ewrColumnIndex != null)
		{
			columnIndex = i + parseInt(ewrColumnIndex);
			break;
		}
	}

	return columnIndex;
}

function resizeToContent(oWnd)
{
	var oBody = oWnd.document.body;
	var height = oBody.scrollHeight - oBody.clientHeight + parseInt(oWnd.dialogHeight);
	oWnd.dialogHeight = height + 'px';

	var width = oBody.scrollWidth - oBody.clientWidth + parseInt(oWnd.dialogWidth);
	oWnd.dialogWidth = width + 'px';
}

function isReady(o)
{
	if (!o) return false;
	switch (o.readyState)
	{
		case "loaded": case "interactive": case "complete": return true;
		default: return false;
	}
}

function populateDataFieldsCombo(comboBox, dataFieldIds, dataFieldNames, activeDataFieldIndex)
{
	if (comboBox == null || dataFieldIds == null || dataFieldNames == null)
		return;

	var count = dataFieldIds.length;

	for (var i=0; i < count; i++)
	{
		var oOption = document.createElement("OPTION");
		oOption.text = dataFieldNames[i];
		oOption.value = dataFieldIds[i];
		if (activeDataFieldIndex == i)
		{
			oOption.selected = true;
		}

		comboBox.add(oOption);
	}
}

function encodeParameterNameValueStrings(textBoxIds, destHiddenFieldId)
{
	var destHiddenField = document.getElementById(destHiddenFieldId);
	var textBoxIdStart = "WorkbookParametersTextBox-";
	var paramNameStartIndex = textBoxIdStart.length;
	var encodedString = "";

	try{

	for (var i = 0; i < textBoxIds.length; i++)
	{
		var textBoxId = textBoxIds[i];
		var textBox = document.getElementById(textBoxId);
		var paramNameStartIndex = textBoxId.indexOf(textBoxIdStart) + textBoxIdStart.length;

		var paramName = escapeProperly(textBoxId.substr(paramNameStartIndex));
		var paramValue = escapeProperly(textBox.value);

		if (paramName != null && paramValue != null)
		{
			if (encodedString.length > 0)
			{
				encodedString += "&";
			}
			encodedString += paramName + "=" + paramValue;
		}
	}

	destHiddenField.value = encodedString;
	}catch(ex){}
}

var parametersPaneMainCell = null;

function initParametersTaskPaneResize(parametersPaneMainCellId)
{
	parametersPaneMainCell = document.getElementById(parametersPaneMainCellId);
}

function resizeParametersTaskPane(lastMainTableRowId)
{
	try{
	var lastMainTableRow = document.getElementById(lastMainTableRowId);
	var lastMainTableRowVisible = (getCurrentStyle(lastMainTableRow, "display", "display") != "none");
	var rowSpan = 3;

	if (parametersPaneMainCell != null)
	{
		if (!bNavBarVisible)
		{
			rowSpan--;
		}

		if (!lastMainTableRowVisible)
		{
			rowSpan--;
		}

		parametersPaneMainCell.rowSpan = rowSpan;
	}
	}catch(ex){}
}

function toggleParametersTaskPane(onlyOnEnterOrSpaceKey, taskPaneId, imgId, expandImgSrc, expandImgTitle, expandImgAltText, collapseImgSrc, collapseImgTitle, collapseImgAltText, expandStateFieldId)
{
	try{

	if (onlyOnEnterOrSpaceKey)
	{
		if (isEventTriggeredByKey(13) || isEventTriggeredByKey(32))
		{

			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		else
		{
			return;
		}
	}

	var taskPane = document.getElementById(taskPaneId);
	var img = document.getElementById(imgId);
	var imgParent = getParentElement(img);
	var expandStateField = document.getElementById(expandStateFieldId);
	var willBeExpanded;
	var newImgSrc, newImgTitle, newImgAltText;
	var newDisplayStyle;

	if (taskPane == null)
	{
		return;
	}

	willBeExpanded = (taskPane.style.display == "none");
	newImgSrc = (willBeExpanded ? collapseImgSrc : expandImgSrc);
	newImgTitle = (willBeExpanded ? collapseImgTitle : expandImgTitle);
	newImgAltText = (willBeExpanded ? collapseImgAltText : expandImgAltText);
	newDisplayStyle = (willBeExpanded ? "block" : "none");

	taskPane.style.display = newDisplayStyle;
	if (img != null)
	{
		img.src = newImgSrc;
		img.title = newImgTitle;
		img.alt = newImgAltText;
		if (imgParent != null)
		{
			imgParent.title = newImgTitle;
		}
	}

	expandStateField.value = willBeExpanded.toString();

	doEwrResize();
	}catch(ex){}
}

function isEventTriggeredByKey(keyCode)
{
	try
	{
		if (window.event == null)
		{
			return false;
		}

		return (window.event.keyCode == keyCode);
	}
	catch (ex)
	{
		return false;
	}
}

function openXLStreamWithActiveX(varObId, strSiteUrl, strFileName, strSessionId, strCommand, strSheet, iRow, iColumn, varProgId, strAspxUrl, strErrorMsg)
{
	try
	{
		if (strAspxUrl && (strAspxUrl !== ""))
		{

			objWindow = window.open(strAspxUrl);
		}
		else
		{
			objEditor = new ActiveXObject(varObId);
			objEditor.ViewInExcel(strSiteUrl, strFileName, strSessionId, strCommand, strSheet, iRow, iColumn, varProgId);
		}

	}
	catch (ex)
	{
		alert(strErrorMsg);
	}
}

function openFileWithActiveX(varObId, strDocument, varProgId, strErrorMsg, allowRedirect)
{
	try
	{
		var objEditor = new ActiveXObject(varObId);
		if (!objEditor.EditDocument2(window, strDocument, varProgId))
		{
			throw new exception();
		}
	}
	catch (ex)
	{

		if (allowRedirect)
			window.parent.location.href(strDocument);
		else
			alert(strErrorMsg);
	}
}

function openLinkInNewWindow(strDocument)
{

	try
	{
		var newWindow = window.open(strDocument,'_blank','menubar=yes,resizable=yes,scrollbars=yes,location=yes');
	}
	catch (ex)
	{
	}
}

function getElement(descendent, toplevel, greedy)
{
	var element = descendent;
	var tagList = new Object();
	for (var i = 3; i < arguments.length; i++)
	{
		tagList[arguments[i].toLowerCase()] = true;
	}

	if (greedy)
	{
		if (toplevel != null)
		{
			while (descendent != null && descendent.id != toplevel)
			{
				if (tagList[descendent.tagName.toLowerCase()] != null)
				{
					element = descendent;
				}
				descendent = getParentElement(descendent);
			}
		}
		else
		{
			while (descendent != null)
			{
				if (tagList[descendent.tagName.toLowerCase()] != null)
				{
					element = descendent;
				}
				descendent = getParentElement(descendent);
			}
		}
	}
	else
	{
		if (toplevel != null)
		{
			while (descendent != null && descendent.id != toplevel && tagList[descendent.tagName.toLowerCase()] == null)
			{
				descendent = getParentElement(descendent);
			}
			element = descendent;
		}
		else
		{
			while (descendent != null && tagList[descendent.tagName.toLowerCase()] == null)
			{
				descendent = getParentElement(descendent);
			}
			element = descendent;
		}
	}
	if (tagList[element.tagName.toLowerCase()] != null)
	{
		return element;
	}
	else
	{
		return null;
	}
}

function hvrAxisItem(axisItem, hover, newClass)
{
	if (axisItem == null)
		return false;

	var baseCssClassName = null;

	if (newClass != null)
	{

		baseCssClassName = newClass;
		axisItem.setAttribute("selCss", baseCssClassName);
	}
	else
	{
		baseCssClassName = getAttribute(axisItem, "selCss");
		if (baseCssClassName == null)
		{

			baseCssClassName = axisItem.className;
			axisItem.setAttribute("selCss", baseCssClassName);
		}
	}

	if (hover)
	{

		axisItem.className =  baseCssClassName + "-hover";
	}
	else
	{

		axisItem.className = baseCssClassName;
	}

	return false;
}

function getColHeaderCell(event, colHeaderTableId)
{
	try
	{

		var colHdrCell = getElement(getSrcElement(event), colHeaderTableId, false, "TD");
		if (colHdrCell == null)
			return null;

		var parentRow = getParentElement(colHdrCell);
		if (parentRow.rowIndex != getParentElement(parentRow).rows.length - 1)
			return null;

		return colHdrCell;
	}
	catch(e)
	{
		return null;
	}
}

function getRowHeaderCell(event, rowHeaderTableId)
{
	try
	{

		var rowHdrCell = getElement(getSrcElement(event), rowHeaderTableId, false, "TD");
		if (rowHdrCell == null)
			return null;

		if (rowHdrCell.cellIndex != getParentElement(rowHdrCell).cells.length - 1)
			return null;

		return rowHdrCell;
	}
	catch(e)
	{
		return null;
	}
}

function movrCol(event, colHeaderTableId)
{
	return hvrAxisItem(getColHeaderCell(event, colHeaderTableId), true, null);
}
function moutCol(event, colHeaderTableId)
{
	return hvrAxisItem(getColHeaderCell(event, colHeaderTableId), false, null);
}

function movrRow(event, rowHeaderTableId)
{
	return hvrAxisItem(getRowHeaderCell(event, rowHeaderTableId), true, null);
}

function moutRow(event, rowHeaderTableId)
{
	return hvrAxisItem(getRowHeaderCell(event, rowHeaderTableId), false, null);
}

function hltCol(event, colHeaderTableId)
{
try{
	{}

	var colHdrCell = getColHeaderCell(event, colHeaderTableId);
	if (colHdrCell != null)
	{
		highlightCell(colHdrCell, true, 'column', -1, colHdrCell.cellIndex);
	}

	{}

	return false;
}catch(ex){}
}

function hltRow(event, rowHeaderTableId)
{
try{
	{}

	var rowHdrCell = getRowHeaderCell(event, rowHeaderTableId);
	if (rowHdrCell != null)
	{
		highlightCell(rowHdrCell, true, 'row', getParentElement(rowHdrCell).rowIndex, -1);
	}

	{}

	return false;
}catch(ex){}
}

function unHighlight()
{
	{}

	if (oCellsHighlight != null)
	{
		oCellsHighlight.style.display='none';
	}

	{}

	return true;
}

function unHighlightClick(event)
{

	if (getMouseButton(event) != 1)
		return false;

	return unHighlight();
}

function highlightClick(event, topmost)
{

	if (getMouseButton(event) != 1)
		return false;

	{}

	var cell = getElement(getSrcElement(event), topmost, true, "TD", "TH");
	if (cell == null) return;

	highlightCell(cell, true, "cell", getParentElement(cell).rowIndex, getCellRealIndex(cell));

	{}

	return true;
}

function highlightCell(cell, userInitiated, mode, rowIndex, columnIndex)
{

	if (userInitiated)
	{
		var innerForm = null;
		if (window.frameElement != null && (userSelectionColumnInput == null || userSelectionRowInput == null))
		{
			var innerDoc = window.frameElement.contentWindow.document;
			innerForm = innerDoc.forms[0];
		}

		if (userSelectionColumnInput == null)
		{
			userSelectionColumnInput = EwrFindInputField(innerForm, "userselcolnbr", "true");
		}

		if (userSelectionRowInput == null)
		{
			userSelectionRowInput = EwrFindInputField(innerForm, "userselrownbr", "true");
		}
	}

	unHighlight();

	if (userInitiated)
	{
		if (userSelectionColumnInput != null)
			userSelectionColumnInput.value = null;

		if (userSelectionRowInput != null)
			userSelectionRowInput.value = null;
	}

	if ((cell == HighlightedCell && HighlightedCellMode == mode) || cell == null)
	{

		if (userInitiated)
		{
			updateHeaderCssStyles(-1, -1, -1, -1, null, null);
		}

		HighlightedCell = null;
		HighlightedCellMode = null;
		HighlightedColumnIndex = -1;
		HighlightedRowIndex = -1;

		return;
	}

	positionSelectionElements(rowIndex, columnIndex, cell, mode);

	if (userInitiated)
	{
		var columnNumber = -1;
		var rowNumber = -1;

		if (userSelectionColumnInput != null)
		{
			if (mode == "cell" || mode == "column")
			{

				userSelectionColumnInput.value = varColumnNumberMap[columnIndex];
				columnNumber = parseInt(varColumnNumberMap[columnIndex]);
			}
		}

		if (userSelectionRowInput != null)
		{
			if (mode == "cell" || mode == "row")
			{

				userSelectionRowInput.value = varRowNumberMap[rowIndex];
				rowNumber = parseInt(varRowNumberMap[rowIndex]);
			}
		}

		updateHeaderCssStyles(rowNumber, columnNumber, rowIndex, columnIndex, mode, cell);
	}

	HighlightedCell = cell;
	HighlightedCellMode = mode;
	HighlightedColumnIndex = columnIndex;
	HighlightedRowIndex = rowIndex;
}

function getHighlightedCellA1Reference(ewrId)
{
	try {

		var outerEwrDiv = document.getElementById(ewrId);

		var iframes = outerEwrDiv.getElementsByTagName("iframe");
		var outerEwrIframe = null;
		for (var i=0; i<iframes.length; i++)
		{
			if (iframes[i].IsEwrMainIframe != null)
			{
				outerEwrIframe = iframes[i];
				break;
			}
		}

		if (outerEwrIframe == null || outerEwrIframe.contentWindow == null)
		{
			return null;	
		}
		var ewrWindow = outerEwrIframe.contentWindow;

		if (ewrWindow.varCurrentSheetName == null || ewrWindow.varCurrentSheetName.length == 0 ||
			ewrWindow.HighlightedCellMode != "cell" ||
			ewrWindow.userSelectionRowInput == null || ewrWindow.userSelectionColumnInput == null)
		{
			return null;
		}

		var rowIndex = parseInt(ewrWindow.userSelectionRowInput.value) + 1;
		var colIndex = parseInt(ewrWindow.userSelectionColumnInput.value) + 1;
		var colTitle = columnNumberToTitle(colIndex);

		var sheetName = ewrWindow.varCurrentSheetName;
		var re = /'/g;
		sheetName = sheetName.replace(re, "''");

		return "'" + sheetName + "'!" + colTitle + rowIndex;
	}
	catch (ex)
	{
		return null;
	}
}

function columnNumberToTitle(number)
{
	if (number < 1)
	{
		return null;
	}

	var title = "";
	title = a1ColumnNumberToTitle(number - 1, title);
	return title;
}

var alphaRadix = ("Z".charCodeAt(0) - "A".charCodeAt(0)) + 1;

function a1ColumnNumberToTitle(number, title)
{
	if (number >= alphaRadix)
	{
		a1ColumnNumberToTitle(number / alphaRadix - 1, title);
	}

	return title + (String.fromCharCode("A".charCodeAt(0) + (number % alphaRadix)));
}

function getColumnHeaderClass(selColumnIndex, columnNumber, rowNumber, currColumnNumber, mergeAcross)
{

	if (rowNumber != -1 && columnNumber == -1)
	{
		return "shdr ewrch-col-all ewrch-col-cellsel";
	}

	if (rowNumber == -1 && currColumnNumber == columnNumber)
	{
		return "shdr ewrch-col-all ewrch-col-sel";
	}

	if (rowNumber != -1)
	{

		if (currColumnNumber == columnNumber)
		{
			return "shdr ewrch-col-all ewrch-col-cellsel";
		}

		if (mergeAcross != 0 && currColumnNumber > columnNumber)
		{
			var lastColumnNumberInMerge = varColumnNumberMap[selColumnIndex + mergeAcross - 1];
			if (currColumnNumber <= lastColumnNumberInMerge && columnNumber <= lastColumnNumberInMerge)
			{
				return "shdr ewrch-col-all ewrch-col-cellsel";
			}
		}
	}

	return "shdr ewrch-col-all ewrch-col-nosel";
}

function getRowHeaderClass(columnNumber, selRowIndex, rowNumber, currRowNumber, mergeDown)
{

	if (columnNumber != -1 && rowNumber == -1)
	{
		return "shdr ewrch-row-all ewrch-row-cellsel";
	}

	if (columnNumber == -1 && currRowNumber == rowNumber)
	{
		return "shdr ewrch-row-all ewrch-row-sel";
	}

	if (columnNumber != -1)
	{

		if (currRowNumber == rowNumber)
		{
			return "shdr ewrch-row-all ewrch-row-cellsel";
		}

		if (mergeDown != 0 && currRowNumber > rowNumber)
		{
			var lastRowNumberInMerge = varRowNumberMap[selRowIndex + mergeDown - 1];
			if (currRowNumber <= lastRowNumberInMerge && rowNumber <= lastRowNumberInMerge)
			{
				return "shdr ewrch-row-all ewrch-row-cellsel";
			}
		}
	}

	return "shdr ewrch-row-all ewrch-row-nosel";
}

function updateHeaderCssStyles(selRowNumber, selColumnNumber, selRowIndex, selColumnIndex, mode, cell)
{

	var processRows = !((HighlightedCellMode == "column") && (mode == "column"));

	var processColumns = !((HighlightedCellMode == "row") && (mode == "row"));

try{

	updateHeaderCssStylesInternal(selRowIndex, selColumnIndex, selRowNumber, selColumnNumber, mode, cell, HighlightedCellMode, HighlightedCell, processRows, processColumns, HighlightedRowIndex, HighlightedColumnIndex);

	updateHeaderCssStylesInternal(selRowIndex, selColumnIndex, selRowNumber, selColumnNumber, mode, cell, mode, cell, processRows, processColumns, selRowIndex, selColumnIndex);
}catch(ex){}
}

function getMergeAttribute(cell, mode, htmlAttr)
{
try{
	if (mode == "cell" && cell != null)
	{
		var spanAttr = cell.attributes[htmlAttr];
		if (spanAttr != null)
		{
			return parseInt(spanAttr.value);
		}
	}
}catch(ex){}

	return 1;
}

function updateHeaderCssStylesInternal(selRowIndex, selColumnIndex, selRowNumber, selColumnNumber, selMode, selCell, mode, cell, processRows, processColumns, startRowIndex, startColumnIndex)
{
	var selMergeAcross = getMergeAttribute(selCell, selMode, "colSpan");
	var selMergeDown = getMergeAttribute(selCell, selMode, "rowSpan");

	switch (mode)
	{

		case null:
			updateHeaderCssStylesLoop(selRowIndex, selColumnIndex, selRowNumber, selColumnNumber, selMode, selMergeDown, selMergeAcross, processRows, processColumns,
				0, varRowNumberMap.length, 0, varColumnNumberMap.length);
			break;

		case "cell":
		{
			var mergeAcross = getMergeAttribute(cell, mode, "colSpan");
			var mergeDown = getMergeAttribute(cell, mode, "rowSpan");

			updateHeaderCssStylesLoop(selRowIndex, selColumnIndex, selRowNumber, selColumnNumber, selMode, selMergeDown, selMergeAcross, processRows, processColumns,
				startRowIndex, startRowIndex + mergeDown, startColumnIndex, startColumnIndex + mergeAcross);
			break;
		}

		case "column":
			updateHeaderCssStylesLoop(selRowIndex, selColumnIndex, selRowNumber, selColumnNumber, selMode, selMergeDown, selMergeAcross, processRows, processColumns,
				0, varRowNumberMap.length, startColumnIndex, startColumnIndex + 1);
			break;

		case "row":
			updateHeaderCssStylesLoop(selRowIndex, selColumnIndex, selRowNumber, selColumnNumber, selMode, selMergeDown, selMergeAcross, processRows, processColumns,
				startRowIndex, startRowIndex + 1, 0, varColumnNumberMap.length);
			break;
	}
}

function updateHeaderCssStylesLoop(selRowIndex, selColumnIndex, selRowNumber, selColumnNumber, selMode, selMergeDown, selMergeAcross, processRows, processColumns, firstRow, lastRow, firstColumn, lastColumn)
{

	if (oRowHeadersDiv != null && processRows)
	{

		var rowHeaderTable = document.getElementById("RowHeaders");
		var isRowMode = selMode == "row";

		for (var i=firstRow; i<lastRow; ++i)
		{

			var headerRowCells = rowHeaderTable.rows[i].cells;
			var headerCell = headerRowCells[headerRowCells.length - 1];

			var curRowNumber = parseInt(varRowNumberMap[i]);
			hvrAxisItem(headerCell, isRowMode && curRowNumber == selRowNumber, getRowHeaderClass(selColumnNumber, selRowIndex, selRowNumber, curRowNumber, selMergeDown));
		}
	}

	if (oColumnHeadersDiv != null && processColumns)
	{

		var columnHeaderTable = document.getElementById("ColumnHeaders");
		var isColumnMode = selMode == "column";

		var headerRows = columnHeaderTable.rows;
		var headerRow = headerRows[headerRows.length - 1];

		for (var i=firstColumn; i<lastColumn; ++i)
		{

			var headerCell = headerRow.cells[i];

			var curColumnNumber = parseInt(varColumnNumberMap[i]);
			hvrAxisItem(headerCell, isColumnMode && curColumnNumber == selColumnNumber, getColumnHeaderClass(selColumnIndex, selColumnNumber, selRowNumber, curColumnNumber, selMergeAcross));
		}
	}
}

function setSelectionRect(rowIndex, columnIndex, top, left, width, height, mode, lastRow, lastColumn)
{

	var offsetTable =
	{
		IE :
		{
			LTR : { cell : [ -1,  3, -1,  3 ], row : [ -1,  2, -1,  3 ], column : [ -1,  3, -1,  2 ] },
			RTL : { cell : [ -2,  3, -1,  3 ], row : [ -1,  1, -1,  3 ], column : [ -1,  2, -1,  2 ] }
		},
		Firefox :
		{
			LTR : { cell : [ -2, -1, -2, -1 ], row : [ -1, -2, -2, -1 ], column : [ -2, -1, -1, -2 ] },
			RTL : { cell : [ -2, -1, -2, -1 ], row : [ -1, -2, -2, -1 ], column : [ -4, -1, -1, -2 ] }
		}
	};

	var edgeOffsetTable =
	{

		firstRow :
		{
			IE :      { LTR : { cell : [  1, -1 ], row : [  1, -1 ] },    RTL : { cell : [  1, -1 ], row : [  1, -1 ] } },
			Firefox : { LTR : { cell : [  2, -1 ], row : [  2, -1 ] },    RTL : { cell : [  2, -1 ], row : [  2, -1 ] } }
		},
		lastRow :
		{
			IE :      { LTR : { cell : [  0, -1 ], row : [  0, -1 ] },    RTL : { cell : [  0, -1 ], row : [  0, -1 ] } },
			Firefox : { LTR : { cell : [  0,  0 ], row : [  0,  0 ] },    RTL : { cell : [  0,  0 ], row : [  0,  0 ] } }
		},

		firstColumn :
		{
			IE :      { LTR : { cell : [  1, -1 ], column : [  1, -1 ] },    RTL : { cell : [  0, -2 ], column : [ -1, -1 ] } },
			Firefox : { LTR : { cell : [  2, -1 ], column : [  2, -1 ] },    RTL : { cell : [  0,  0 ], column : [  0,  0 ] } }
		},
		lastColumn :
		{
			IE :      { LTR : { cell : [  0, -1 ], column : [  0, -1 ] },    RTL : { cell : [  1, -1 ], column : [  0,  0 ] } },
			Firefox : { LTR : { cell : [  0,  0 ], column : [  0,  0 ] },    RTL : { cell : [  1, -1 ], column : [  1, -1 ] } }
		}
	};

	if (mode == "row")
	{
		left = 0;
	}

	var direction = RtlSheet ? 'RTL' : 'LTR';
	var browser = browseris.ie ? 'IE' : 'Firefox';

	if (rowIndex == 0)
	{
		var edgeOffsets = edgeOffsetTable['firstRow'][browser][direction][mode];
		top += edgeOffsets[0];
		height += edgeOffsets[1];
	}
	if (lastRow)
	{
		var edgeOffsets = edgeOffsetTable['lastRow'][browser][direction][mode];
		top += edgeOffsets[0];
		height += edgeOffsets[1];
	}
	if (columnIndex == 0)
	{
		var edgeOffsets = edgeOffsetTable['firstColumn'][browser][direction][mode];
		left += edgeOffsets[0];
		width += edgeOffsets[1];
	}
	if (lastColumn)
	{
		var edgeOffsets = edgeOffsetTable['lastColumn'][browser][direction][mode];
		left += edgeOffsets[0];
		width += edgeOffsets[1];
	}

	var offsets = offsetTable[browser][direction][mode];
	oCellsHighlight.style.left = (left + offsets[0]) + 'px';
	oCellsHighlight.style.width = (width + offsets[1]) + 'px';
	oCellsHighlight.style.top = (top + offsets[2]) + 'px';
	oCellsHighlight.style.height = (height + offsets[3]) + 'px';
}

function positionSelectionElements(rowIndex, columnIndex, cell, mode)
{
	if (oCellsHighlight != null)
	{

		var lastRow = (rowIndex + cell.rowSpan == varRowNumberMap.length);
		var lastColumn = (columnIndex + cell.colSpan == varColumnNumberMap.length);

		if (mode == "cell")
		{
			setSelectionRect(rowIndex, columnIndex, cell.offsetTop, cell.offsetLeft, cell.offsetWidth, cell.offsetHeight, mode, lastRow, lastColumn);
		}
		else if (mode == "row")
		{
			var contentTable = getChildren(getChildren(oDivContent)[0].rows[0].cells[0])[0];
			setSelectionRect(rowIndex, columnIndex, cell.offsetTop, contentTable.offsetLeft, contentTable.offsetWidth, cell.offsetHeight, mode, lastRow, lastColumn);
		}
		else if (mode == "column")
		{
			var contentTable = getChildren(getChildren(oDivContent)[0].rows[0].cells[0])[0];
			var left = cell.offsetLeft + ((!browseris.ie && RtlSheet) ? contentTable.offsetWidth : 0);  
			setSelectionRect(rowIndex, columnIndex, contentTable.offsetTop, left, cell.offsetWidth, contentTable.offsetHeight, mode, lastRow, lastColumn);
		}

		var cssClass = "ewr-cell-selection-highlight-all";
		if (rowIndex == 0)
		{
			cssClass+= " ewr-cell-selection-highlight-adj-col-hdr";
		}
		else
		{
			cssClass+= " ewr-cell-selection-highlight-notadj-col-hdr";
		}

		if (columnIndex == 0)
		{
			cssClass+= RtlSheet ? " ewr-cell-selection-highlight-adj-row-hdr-rtl" : " ewr-cell-selection-highlight-adj-row-hdr-ltr";
		}
		else
		{
			cssClass+= " ewr-cell-selection-highlight-notadj-row-hdr";
		}

		oCellsHighlight.className = cssClass;
		oCellsHighlight.style.display = 'block';
	}
}

function toggleHoverSheetTab(tab, textClassName, startColor, endColor)
{
	try{

	if (textClassName != null)
	{
		getChildren(tab.rows[0].cells[1])[0].className = textClassName;
	}

	if (tab.filters == undefined)
	{

		tab.style.backgroundColor = ("#" + endColor);
	}

	else
	{
		var filter = tab.filters[0];

		filter.Enabled = false;
		filter.StartColorStr = ("#FF" + startColor);
		filter.EndColorStr = ("#FF" + endColor);
		filter.Enabled = true;
	}

	}catch(ex){}
}

function ChangeToolpartInputEnabled(event)
{
	try{
	var form = GetFormParent(getSrcElement(event));
	if (form==null || form.elements==null)
	{
		return;
	}
	var i;

	for (i=0; i<form.elements.length;i++)
	{
		var att = getAttribute(form.elements[i], "EwrToolpartParentControl");
		if (att!=null)
		{

			var ctrls = att.split(";");
			var enable = true;
			var j;

			for (j = 0;j<ctrls.length && enable;j++)
			{
				var master = form.elements[ctrls[j]];
				enable = enable && master.checked;
			}
			form.elements[i].disabled = !enable;
		}
	}
	}catch(ex){}
}

function hideMessageButton(buttonId)
{
	try{
	var button = document.getElementById(buttonId);

	if (button != null)
	{
		button.display = window.history.length != 0 ? 'block' : 'none';
	}
	}catch(ex){}
}

function EwrGoTo(locationIndex, postback)
{
	var callbackFunc = new Function(postback);
	callbackFunc(HyperlinkLocations[locationIndex]);
}

