var dspPopupMenuWindow = null;

function dspUtil_ScriptVersion() {
	return "4.5.6";
}

function dspUtil_GetPath(sUrl) {
	var x=sUrl.lastIndexOf("/");
	return (x>0)?sUrl.substring(0,x+1):"";
}

function dspUtil_OpenPopupMenu(oParent) {
	dspMenuWin = window.createPopup();
	var sUrl = dspUtil_GetPath(oDSP_Style.href) + "dspDropDown_40.css";
	var ss = dspMenuWin.document.createStyleSheet(sUrl);

	var divMenu = dspMenuWin.document.createElement("DIV");
	divMenu.className = "dsp-MenuBody";
	divMenu.style.overflow = "auto";
	var a = oParent.getAttribute("menuItems").split("::::");
	for (var i=0;i<a.length;i++) {
		var s = "<div class='dsp-MenuItem' " +
			"onclick=\"parent." +  a[i].split(";")[1] + "\" " +
			"onmouseover=\"this.className='dsp-MenuItemMouseOver'\" " +
			"onmouseout=\"this.className='dsp-MenuItem'\">" + a[i].split(";")[0] + "</div>";
		var divItem = dspMenuWin.document.createElement("DIV");
			divItem.innerHTML = s;
		
		divMenu.appendChild(divItem);
	}
		
	dspMenuWin.document.body.appendChild(divMenu);
	var iHeight = a.length*22 + 5;
	dspMenuWin.show(oParent.offsetWidth-100, oParent.offsetHeight, 100, iHeight, oParent);
}

function dspUtil_CurrentFilter(xRS, sConnectInfo, sIncluded, sExcluded, sMembersForDim) {
	var oNode, oMembers, sCaption, sTitle;
	var sFilter = sConnectInfo; 
	if (sFilter.length == 0) {
		var oNodes = xRS.selectNodes("/DSPWebPart/Dimensions/Dimension[(@Type='4' or (@Axis='5' and @Type!='2')) and @HideFilterValue='0']");
		if (oNodes != null) {
			for(var iCnt=0; iCnt<oNodes.length; iCnt++) {
				oMembers = xRS.selectNodes("/DSPWebPart/Members/Member[@Dim='" + oNodes(iCnt).getAttribute("Id") + "']");
				if (oMembers.length > 0) {
					sCaption = "";
					if (oNodes(iCnt).getAttribute("Type") == "4") {
						sCaption = (oNodes(iCnt).getAttribute("FilterFunction")=="2")?"*":"";
						for(var iMemCnt=0; iMemCnt<oMembers.length; iMemCnt++) {
							sCaption += oMembers(iMemCnt).getAttribute("Caption") + ",";
						}
						if (sCaption.length>0)
							sCaption = sCaption.substr(0, sCaption.length-1);
						sCaption = "(" + sCaption + ")";
						sTitle = ((oNodes(iCnt).getAttribute("FilterFunction")=="2")?sExcluded:sIncluded) + " " + sMembersForDim + " " + oNodes(iCnt).getAttribute("Caption");
					}
					else {
						sCaption = oMembers(0).getAttribute("Caption");
						if (sCaption != "")
							sTitle = sIncluded + " " + sMembersForDim + " " + oNodes(iCnt).getAttribute("Caption");
					}
					if (sCaption!="")
					  sFilter += "<span class='dsp-currentfilter' title='" + sTitle + "'>" + ((sFilter!="")?", ":"") + sCaption + "</span>";
				}
			}
		}
	}
	return sFilter;
}

function dspUtil_DefaultSettings(p, oStyleSrc, fSetInstanceProp, fSetTypeProp) {
	p.Connected = "";
	p.Values = null;
	p.ViewIndex = 0;
	p.WebPartWidth = 200;
	p.WebPartHeight = 100;
	p.ChartType = 0;
	p.FontClass = "ms-WPBody";
	p.FontSize = "7pt";
	p.BorderColor = oStyleSrc.currentStyle.borderBottomColor;
	p.SerieLegendPosition = 2;
	p.DispAxisValueSerie = 0;
	p.DispAxisValueCategory = 0; 
	p.DrawPoint = false;
	p.LineWeight = 1;
	p.XLegendCutMode = 0;
	p.XLegendCntMode = 0;
	p.XLegendWordWrap = 1;
	p.XLegendOrientation = 0;
	p.XLegendPosition = 0;
	p.DisplaySerieLegendCount = 0;
	p.FormatString = "";
	p.YAxisScaleMin = "null";
	p.YAxisScaleMax = "null";
	p.YAxisUnits = "null";
	p.CombChartColCount = 1;
	p.CellActionName = "";
	p.CellActionDescription = "";
	p.CellActionOpen = "";
	p.ColumnActionName = "";
	p.ColumnActionDescription = "";	
	p.ColumnActionOpen = "";	
	p.RowActionName = "";
	p.RowActionDescription = "";	
	p.RowActionOpen = "";
	p.DetailLinkOpen = "";
	p.DetailLinkDisabled = 0;
	p.FirstColumnHeader = "";
	p.TableColumnWidth = "";
	p.TableStyleSheet = "standard_00";
	p.RowIndentation = 0;
	p.WebPartAlignment = "left";
	p.SerieSelectorStep = 1;
	p.LayoutVersion = "400";
	p.ClientVersionBehavior = 0;
	p.ClientVersionUrl = "";
	p.ClientVersionWindowStyle = "";

	fSetInstanceProp(p);
	if (document.location.protocol == "file:") {
		p.CellActionName = "";
		p.CellActionDescription = "";
		p.MemberActionName = "";
		p.MemberActionDescription = "";	
	}
	fSetTypeProp(p);
	if (p.SerieColorString!=null)
		p.SerieColor = p.SerieColorString.split(",");
	else
		p.SerieColor = new Array("blue", "red", "green");
	p.FillOpacity = (p.FillOpacity!=null)?p.FillOpacity:80;
	p.LineOpacity = (p.LineOpacity!=null)?p.LineOpacity:80;
}

function dspUtil_SetSerieButtonState(oRow) {
	var p = (oRow.CurrentIndex > 0)?0:1;
	var n = (oRow.CurrentIndex < (oRow.ItemCount-1))?0:1;
	if (oRow.cells[0].childNodes(2).filters.length > 0) {
		oRow.cells[0].childNodes(2).filters.item(0).enabled = p;
		oRow.cells[2].childNodes(2).filters.item(0).enabled = n;
	}
}

function dspUtil_SetCurrSerieIndex(i, oRow) {
	var iMax = oRow.ItemCount, iIndex = oRow.CurrentIndex, bUpdate;
	switch (i) {
		case -1: iIndex--;bUpdate=(iIndex>-1);break;
		case 1:	 iIndex++;bUpdate=(iIndex<iMax);break;
		default: iIndex=0;bUpdate=true;break;
	}
	if (bUpdate)
		oRow.CurrentIndex = iIndex;
	return bUpdate;
}

function dspUtil_InitSerieSelector(oRow, aSerieItems, oTopLegend, iStep) {
	var s = "", sWidest=0, n, iMax=0;
	oRow.CurrentIndex = 0;
	oRow.SerieSelectorStep = iStep;
	if (aSerieItems.length > iStep) {
		oTopLegend.parentElement.style.display = "block";
		var iCount = aSerieItems.length;
		for (var i=0;i<iCount;i+=iStep) {
			n = aSerieItems[i];
			s += n + ";"
			if (n.length > iMax) {
				iMax = n.length;
				sWidest = n
			}
		}
		s = s.substr(0, s.length-1);
		oRow.Items = s;
		oRow.ItemCount = iCount/iStep;
		oRow.cells[1].innerText = oRow.Items.split(";")[oRow.CurrentIndex];
		dspUtil_SetSerieButtonState(oRow);
	}
}

function dspUtil_ApplyTopBorderStyle(sId, sColor) {
	var oTR = document.all(sId);
	if (oTR != null) {
		for(c=0;c<oTR.cells.length;c++) {
			if (oTR.cells[c].style.borderTopColor == "")
				oTR.cells[c].style.borderTopColor = sColor;
		}
	}
}

function dspUtil_EncodeUniqueName(s, e) {
	return s.replace(/&\[/g,(e==1)?"%26[":"+[");
}

function dspUtil_GetWpID(sId) {
	var sWpID = "";
	var oDiv = document.all(sId);
	while (oDiv.parentElement != null) {
		var oParent = oDiv.parentElement;
		if (oParent.WebPartID != null) {
			sWpID = oParent.id;
			break;
		}
		oDiv = oParent;
	}
	return sWpID;
}

function dspUtil_GetWpCopySize(sId) {
	var sSize = "";
	var oDiv = document.all(sId);
	while (oDiv.parentElement != null) {
		var oParent = oDiv.parentElement;
		if (oParent.tagName == "TABLE" && sSize == "")
			sSize = oParent.clientWidth + ":" + oParent.clientHeight;
		if (oParent.name == "dspwpcopygroup") {
			sSize = oParent.clientWidth + ":" + oParent.clientHeight;
			break;
		}
		oDiv = oParent;
	}
	return sSize;
}

function dspUtil_GetWpCaption(sId) {
	var s = "";
	var oTitle = document.all("WebPartTitle" + sId.substr(4, sId.length-14));
	if (oTitle != null) {
		s = oTitle.title;
		if (s.indexOf(" - ") > 0)
			s =  s.substring(0, s.indexOf(" - "));
	}
	return s;
}

function dspUtil_IsWpVisible(sId) {
	var v = false;
	try {
		var d = document.all("MSOZoneCell_WebPart" + sId.substr(4, sId.length-14));
		v = (d.childNodes(0).style.display != "none");
	}
	catch(e) {v = true;}
	return v;
}

function dspUtil_CreatedivTextWidth(sId, sClass) {
	var div = document.getElementById(sId);
	if (div == null) {
		div = document.createElement("DIV");
		div.style.display = "block";
		div.style.width = "5px";
		div.className = sClass;
		div.style.margin = "0";
		div.style.padding = "0";
		div.style.top = "-1000";
		div.style.position = "absolute";
		div.id = sId;
		document.body.insertBefore(div, document.body.children(0));
	}
	return div;
}
