﻿// Scorecard.js
//





// -----------------------------------

// Used to persist the row expansion state
var g_rowVisibilityStore;
var g_configuredViewKey;

//
// Initialize the row states from the persistent store
//
function InitializeViewTableToolbarStore(rowVisibiltyStore, scorecardId, configuredViewId)
{
	g_rowVisibilityStore = document.getElementById(rowVisibiltyStore);
	g_configuredViewKey = "(" + scorecardId + ":" + configuredViewId + ")";
	if (g_rowVisibilityStore.value == null || g_rowVisibilityStore.value.length < 1)
	{
		SaveRowExpansionState();
	}
	else
	{
		if (g_rowVisibilityStore.value.indexOf(g_configuredViewKey) < 0)
		{
			// The configuredView / scorecard has changed, so don't carry on the row expansion state
			SaveRowExpansionState();
		}
		else
		{
			RestoreRowExpansionState();
			UpdateTableVisibility();
			UpdateTableExpansionImages();
		}
	}
}

//
// Save the current row expansion state into a persistent variable
//
function SaveRowExpansionState()
{
	var newState = g_configuredViewKey + ",";
	var trs = document.getElementsByTagName("tr");
	for (i = 0; i < trs.length; i++)
	{
		var row = trs[i];

		if (isScorecardRow(row))
		{
			newState += row.rowId;
			if (row.filtered == "true")
				newState += ":1";
			else
				newState += ":0";

			if (row.showing == "true")
				newState += ":1";
			else
				newState += ":0";

			if (row.expanded == "true")
				newState += ":1";
			else
				newState += ":0";

			newState += ",";
		}
	}
	
	g_rowVisibilityStore.value = newState;
}

//
// Update the row states from the persistent store
//
function RestoreRowExpansionState()
{
	var state = g_rowVisibilityStore.value;

	var trs = document.getElementsByTagName("tr");
	for (i = 0; i < trs.length; i++)
	{
		var row = trs[i];

		if (isScorecardRow(row))
		{
			var pos = state.indexOf("," + row.rowId + ":");
			if (pos > -1)
			{
				var endPos = state.indexOf(",", pos+1);
				var token = state.substring(pos+1, endPos);
				var tokens = token.split(":");
				if (tokens.length >= 4)
				{
					if (tokens[2] == "1")
						row.showing = "true";
					else
						row.showing = "false";

					if (tokens[3] == "1")
						row.expanded = "true";
					else
						row.expanded = "false";
				}
			}
		}
	}
}

//
// Returns the plus-minus image of a row
//
function GetPlusMinusImage(src)
{
    if(src!=null)
    {
	    var imgs = src.getElementsByTagName("img");
	    if (imgs && imgs.length > 0)
	    {
		    if (imgs[0].type && imgs[0].type == "plusminusimg")
			    return imgs[0];
	    }
	}
	
	return null;
}


//
// Returns true if this element is a scorecard row
//
function isScorecardRow(element) 
{
    if(element == null)
        return false;
        
    var rowId = -1;
    if(element.rId)
    {
      rowId = parseInt(element.rId,10);
    }
	if (rowId >=0)
		return true;
	else
		return false;
}

//
// Update Indicator filter
//
function SetIndicatorFilter(parentId, filter, indicatorFilterStoreId)
{
	var tokens = filter.split(".");
	FilterRowsByIndicator(parentId, tokens[0], tokens[1]);
	UpdateTableVisibility();

	indicatorFilterStore = document.getElementById(indicatorFilterStoreId);
	indicatorFilterStore.value = filter;
}

function FilterRowsByIndicator(parentId, indicatorId, inBand)
{
	var rowsToIgnore = ",";
	
	var parent = document.getElementById(parentId);
	var trs = parent.getElementsByTagName("tr");
	for (i = trs.length - 1; i >= 0 ; i--)
	{
		var row = trs[i];
		var isFiltered = true;
		
		if (isScorecardRow(row))
		{
			if (indicatorId != "00000000-0000-0000-0000-000000000000")
			{
				var tds = row.getElementsByTagName("td");
				for (j = 0; j < tds.length; j++)
				{
					var td = tds[j];

					if (td.bpm_iid == indicatorId && td.bpm_ib == inBand)
					{
						isFiltered = false;
						break;
					}
				}
				
				if (isFiltered && (rowsToIgnore.indexOf("," + row.rowId + ",") < 0))
				{
					row.filtered = "true";
				}
				else
				{
					rowsToIgnore += row.parentRowId + ",";
					row.filtered = "false";
				}
			}
			else
			{
				// No indicator filter
				row.filtered = "false";
			}
		}
	}
	SaveRowExpansionState();
}



//
// Go through the scorecard tables and update the visibility of the rows
//
function UpdateTableVisibility()
{
	var trs = document.getElementsByTagName("tr");
	for (i = 0; i < trs.length; i++)
	{
		var row = trs[i];
		if (isScorecardRow(row))
		{
			if (row.filtered != "true" && row.showing == "true")
			{
				row.style.display = "inline";
			}
			else
			{
				row.style.display = "none";
			}
		}
	}
}

//
// Go through the scorecard tables and update the plus/minus images
//
function UpdateTableExpansionImages()
{
	var trs = document.getElementsByTagName("tr");
	for (i = 0; i < trs.length; i++)
	{
		var row = trs[i];
		if (isScorecardRow(row))
		{
			var plusMinusImage = GetPlusMinusImage(row);
			if (null != plusMinusImage)
			{
				if (row.expanded == "true")
				{
					plusMinusImage.src = g_resFolder + "minus.gif";
				}
				else
				{
					plusMinusImage.src = g_resFolder + "plus.gif";
				}
			}
		}
	}
}

var g_itemCell = null;
var g_currentItemID = null;
var g_isMenuShown=false;
var g_currentMenu=null;
var g_onKeyPress = false;
var g_actionsArray = new Array //used to store the actions associated with menu item. The first element always corresponds to annaontaions
var g_isAnnotationEnabled = false;
var g_ShowDetails = false;
var g_Separator = "~";

var g_isTooltipShown=false;
var g_currentToolTip=null;


function resetExecutionStateForMenu()
{
	g_isMenuShown=false;
	g_itemCell=null;
	g_onKeyPress=false;
	g_currentMenu=null;
	g_currentItemID=null;
	g_actionsArray = null;
}

function resetExecutionStateForTooltip()
{
	g_isTooltipShown=false;
    g_currentToolTip=null;
    g_itemCell=null;

}
// Handler for callback
function UpdateScorecardTable(arg, context)
{
 var element = document.getElementById(context);
 element.innerHTML = arg;
 UpdateVisibility();
}


function EscapeJSChars(value)
{ 
    value = value.replace("\\", "\\\\");
    value = value.replace("\"", "\\\""); // TODO 
    value = value.replace("'", "\\\'");
    return value;
}


function OnBsmItem(menuActions)
{
    //if the menu is already being shown 
    if (IsBsmMenuOn())
		return false;
    
    // try to reach the parent cell
     var ele = window.event.srcElement;
     ele = getCellElementFromEvent(ele);
     if(ele ==null)
	    return false;
	
	
	if (g_itemCell !=null)
		OnBsmItemOut();
	
	menuActions = EscapeJSChars(menuActions);
	var menuActionsString = menuActions.split(g_Separator);
	if(menuActionsString.length > 0 )
	{
	    if(g_actionsArray ==null)
	        g_actionsArray = new Array;
	}
	for(i = 0; i < menuActionsString.length; i++)
	{
	        g_actionsArray[i] = encodeURI(menuActionsString[i]);
	}
		
	g_itemCell =ele;

    var scItemTable = getContainerTable(g_itemCell);
    var scItemCells = null;
    if(scItemTable !=null)
	{
	   scItemCells = scItemTable.getElementsByTagName("TD");
	  
	}
	
	for(var i =0 ; scItemCells!=null && i < scItemCells.length; i++)
    {
        if(scItemCells[i].className == "bsm-scItemAnntCell")
        {
           g_annotationbubbleEle =  getAnnotationbubbleElement(scItemCells[i]);
           break;
        }
    }
    
    //set the Event Handlers for click and Context Menu
    g_itemCell.oncontextmenu=CreateBsmMenu;
    g_itemCell.onmouseout=OnBsmItemOut;
	

	return false;
}


function OnBsmItemOut()
{
	if (!IsBsmMenuOn() && g_itemCell !=null)
	{
		g_itemCell.className="bsm-ustitle";
		g_itemCell.onclick="";
		g_itemCell.onmouseout="";
	    g_itemCell.oncontextmenu="";
		resetExecutionStateForMenu();
	}
}

function IsBsmMenuOn()
{
	if (!g_isMenuShown)
		return false;
		
	var fIsOpen=false;
	
	fIsOpen=g_currentMenu.isOpen();
	if (!fIsOpen)
		g_isMenuShown=false;
		
	return fIsOpen;
}

function IsOpen(oMaster)
{
    if (!oMaster)
		return false;
	if (!oMaster._arrPopup)
		return false;
	var oPopup=oMaster._arrPopup[oMaster._nLevel];
	return oPopup && oPopup.isOpen;;
}

function AddChildToParent(p,c)
{
	if(p&&c)p.appendChild(c);
}

function CreateBsmMenu()
{
    if (g_itemCell== null)
        return;
    
    g_isMenuShown = true;
    window.document.body.onclick="";
    g_currentItemID = g_itemCell.getAttribute("ID");
    var m;
    m = CBsmMenu(g_currentItemID + "_menu");
    g_currentMenu = m;
 
    //add the menu options
    AddBsmMenuItems(m);
    var yOffset = -1;
    if (g_itemCell) yOffset += g_itemCell.offsetHeight;
    OBsmMenu(m, g_itemCell, true, null, yOffset);
    document.body.onclick=HideSelectedRow;	
    return false;
}
function GetSelectedElement(elem, tagName)
{
	while(elem !=null && elem.tagName !=tagName)
		elem=elem.parentNode;
	return elem;
}

function HideSelectedRow()
{
    var srcElement = GetSelectedElement(event.srcElement, "TD");
    if (srcElement != g_itemCell && g_itemCell != null)
        OnBsmItemOut();
}

function FRdy(o)
{
	if (!o) return false;
	switch (o.readyState)
		{
		case "loaded": case "interactive": case "complete": return true;
		default: return false;
		}
}

function OBsmMenu(m,r,fr,ft,yoff)
{
	if(typeof(m)=="string")m=document.getElementById(m);
	if(m)
		{
		if(FRdy(document)&&FRdy(m))
			{
			OBsmMenuInt(m,r,fr,ft,yoff);
			}
		else
			{
			if(r!=null)m.setAttribute("relativeTo",r);
			if(fr!=null)m.setAttribute("forceRefresh",fr);
			if(ft!=null)m.setAttribute("flipTop",ft);
			if(yoff!=null)m.setAttribute("yOffsetTop",yoff);
			m.onreadystatechange=OBsmMenuEvnt;
			}
		}
	return false;
}

function OBsmMenuInt(m,r,fr,ft,yoff)
{
	if(m&&!m.isOpen())m.show(r,fr,ft,0,yoff);

}

function OBsmMenuEvnt()
{
	var m=event.srcElement;
	if(m&&FRdy(document)&&FRdy(m))
		{
		var r=m.getAttribute("relativeTo");
		var fr=m.getAttribute("forceRefresh");
		var ft=m.getAttribute("flipTop");
		var yoff=m.getAttribute("yOffsetTop");
		if(r!=null)m.removeAttribute("relativeTo");
		if(fr!=null)m.removeAttribute("forceRefresh");
		if(ft!=null)m.removeAttribute("flipTop");
		if(yoff!=null)m.removeAttribute("yOffsetTop");
		m.onreadystatechange=null;
		OBsmMenuInt(m,r,fr,ft,yoff);
		}
}

function STSNavigate(Url)
{
    window.location= Url ;
}

function CMenuSep()
{
	var sep=CMenuItm("separator");
	SetInnerText(sep, "");
	return sep;
}

function AddMenuSep(p)
{
	var ms=CMenuSep();
	if(!ms)return null;
	AddChildToParent(p,ms);
	return ms;
}

function SetInnerText(oNode, wzText)
{
	if (document.createTextNode !=null)
	{
		var parsedText=document.createTextNode(wzText);
		oNode.innerHTML="";
		oNode.appendChild( parsedText );
	}
	else
		oNode.innerText=wzText;
}

function AddBsmMenuItems(m)
{
    if(g_actionsArray == null)
      return;
      
    // add annotations
    if(g_isAnnotationEnabled)
    {
        var strDisplayText = g_Annotation_Text;
        var annotaionPage = g_resFolder + "Annotation.htm";
        strAction = "var retval = window.showModalDialog('" + annotaionPage  + "','" + g_actionsArray[0]  + "',\"center: yes;resizable: yes;dialogHeight:450px;dialogWidth:305px;status: no;help: no\"); if(retval){ var bubbleEle = g_annotationbubbleEle;if(bubbleEle){bubbleEle.style.visibility =\"visible\";}}else{var bubbleEle = g_annotationbubbleEle; if(bubbleEle!=null){bubbleEle.style.visibility =\"hidden\";}}";
        strImagePath = g_resFolder + "annIcon.gif";
        AddMenuOptions(m, strDisplayText, strAction, strImagePath, true);
    
         //Add the links  
        for(i = 1; i < g_actionsArray.length ;i++)
        {
            AddMenuSep(m);
            var linkActions  = g_actionsArray[i];
            var linkActionsString = linkActions.split('$$');
    	    
	       if(linkActionsString.length >= 2)
	        {
	            strDisplayText = linkActionsString[0];
                strAction = "window.open('" + linkActionsString[1] + "')"; 
                strImagePath = g_resFolder + "Link.GIF";
                AddMenuOptions(m, strDisplayText, strAction, strImagePath,true);
	        }
           
        }
    }
    
    if(g_ShowDetails)
    {
        // Show details -- drill through.
        if (g_actionsArray.length >= 2)
        {
	        var blobArray = g_actionsArray[g_actionsArray.length -1 ].split('+');
	        var enabled = blobArray[0];
            var strDisplayText = g_ShowDetails_Text;
	        if (enabled == "True")
	        {
	            var reportId = blobArray[1];
                var tupleXml = decodeURI(blobArray[2]);
                strAction = "showDetails('" + reportId + "', '" + tupleXml + "')";
                AddMenuOptions(m, strDisplayText, strAction, "", true);
             }
             else 
             {
                AddMenuOptions(m, strDisplayText, "", "", false);   
             }
         } 
     }
   
    
}


function createThrobber(winRef, name)
{
    var documentObj = winRef.document;
	var imgId = "Img" + name; 
	var imgPath = g_resFolder + "ppsd-throbber.gif";
    documentObj.open();
	documentObj.write("<html><head>\n");
	documentObj.write("</head><body>\n");
	documentObj.write("<div style=\"width:100%;height:152px;\">&nbsp;</div>\n");
	documentObj.write("<div style=\"width:100%;text-align:center;\" >\n");
	documentObj.write("<img id=\"" + imgId + "\" src=\"" + imgPath + "\"/>\n");
	documentObj.write("</div>\n");
	documentObj.write("</body></html>");
	documentObj.close();
}

function animateThrobber(winRef, name)
{
    // By reselecting the image, we cause it to reanimate.
	var imgId = "Img" + name; 
    var imgRef = winRef.document.getElementById(imgId);
    imgRef.src = imgRef.src;
}


function showDetails(reportId, tupleXml)
{  
    var windowName = "DTDWindow";
    var winRef = OpenPopUpWindow("", 800, 400, ",resizable,scrollbars", windowName);
    createThrobber(winRef, windowName);           
    createShowDetailsForm(windowName, reportId, tupleXml, "");
    var formRef = document.getElementById("drillThroughFormID");      
    if (formRef != null) formRef.submit();    
    animateThrobber(winRef, windowName);
    
}
    
function OpenPopUpWindow(url, wW, wH, args, wName)
{
    var wX = parseInt((screen.availWidth - wW) / 2);
    var wY = parseInt((screen.availHeight - wH) / 2);
    var winRef = window.open(url, wName, "left="+ wX +",top=" + wY + ",height=" + wH + ",width=" + wW + args);
    if (winRef != null) 
    {
        winRef.focus();
    }
    return winRef;
}

function createShowDetailsForm(windowName, reportId, tupleXml, resultTableIndex)
{
    var path;
    if (typeof(g_resFolder) == "undefined")
        path = "DrillThrough.aspx";
    else
        path = g_resFolder + "DrillThrough.aspx";
    
    var formElem = document.getElementById("drillThroughFormID");         
    if (formElem == null)
    {
        formElem = document.createElement("form");
        formElem.setAttribute("id", "drillThroughFormID");
        formElem.setAttribute("target", windowName);
        formElem.setAttribute("action", path);
        formElem.setAttribute("method", "post");
        formElem.setAttribute("name", "drillThroughForm");
        document.documentElement.appendChild(formElem);
        
        var inputReportElem = document.createElement("input");
        inputReportElem.setAttribute("id", "reportId");
        inputReportElem.setAttribute("type", "hidden");
        inputReportElem.setAttribute("name", "reportId");
        inputReportElem.setAttribute("value", reportId);
        formElem.appendChild(inputReportElem);
        
        var inputRowTupleElem = document.createElement("input");
        inputRowTupleElem.setAttribute("id", "tupleXmlId");
        inputRowTupleElem.setAttribute("type", "hidden");
        inputRowTupleElem.setAttribute("name", "tuple");
        inputRowTupleElem.setAttribute("value", tupleXml);
        formElem.appendChild(inputRowTupleElem);
      
        var inputResultTableIndexElem = document.createElement("input");
        inputResultTableIndexElem.setAttribute("id", "resultTableIndexId");
        inputResultTableIndexElem.setAttribute("type", "hidden");
        inputResultTableIndexElem.setAttribute("name", "resultTableIndex");
        inputResultTableIndexElem.setAttribute("value", resultTableIndex);
        formElem.appendChild(inputResultTableIndexElem);
        
        var inputPageElem = document.createElement("input");
        inputPageElem.setAttribute("id", "pageId");
        inputPageElem.setAttribute("type", "hidden");
        inputPageElem.setAttribute("name", "page");
        inputPageElem.setAttribute("value", "1");
        formElem.appendChild(inputPageElem);
        
        var inputTypeElem = document.createElement("input");
        inputTypeElem.setAttribute("id", "typeId");
        inputTypeElem.setAttribute("type", "hidden");
        inputTypeElem.setAttribute("name", "isScorecard");
        inputTypeElem.setAttribute("value", "true");
        formElem.appendChild(inputTypeElem);
    }
    else
    {
        var inputReportElem = document.getElementById("reportId"); 
        inputReportElem.setAttribute("value", reportId);
        
        var inputRowTupleElem = document.getElementById("tupleXmlId"); 
        inputRowTupleElem.setAttribute("value", tupleXml);
        
        var inputResultTableIndexElem = document.getElementById("resultTableIndexId"); 
        inputResultTableIndexElem.setAttribute("value", resultTableIndex);
                
        var inputTypeElem = document.getElementById("typeId"); 
        inputTypeElem.setAttribute("value", "true");
    }
}

function AddMenuOptions(p,wzText,wzAct,wzISrc,enabled,wzIAlt,wzISeq,wzDesc)
{
	var mo=CMenuOpt(wzText,wzAct,wzISrc,enabled,wzIAlt,wzISeq,wzDesc);
	if(!mo)return null;
	AddChildToParent(p,mo);
	return mo;
}

function CMenuOpt(wzText,wzAct,wzISrc,enabled,wzIAlt,wzISeq,wzDesc)
{
	var mo=CMenuItm("option");
	if(!mo)return null;
	mo.innerText=wzText;
	if (enabled == true) mo.setAttribute("onMenuClick", wzAct);
	else mo.setAttribute("enabled", "false");
	AddImage(mo,wzISrc,wzIAlt);
	return mo;
}

function CMenuItm(wzType)
{
	var mi=document.createElement("SPAN");
	if(!mi)return null;
	mi.setAttribute("type",wzType);
	return mi;
}

function FNEmpWz(wz)
{
	return (wz&&wz!="");
}

function AddImage(mi,wzISrc,wzIAlt)
{
	if(!mi)return;
	if(FNEmpWz(wzISrc))mi.setAttribute("iconSrc",wzISrc);
	if(FNEmpWz(wzIAlt))
		mi.setAttribute("iconAltText",wzIAlt);
	else
		mi.setAttribute("iconAltText","");
}

function CBsmMenu(wzID)
{
	var m=document.getElementById(wzID);
	if (m)
	{
		m._initialized=false;
		m._oContents=null;
		m.innerHTML="";
		return m;
	}
	m=document.createElement("MENU");
	if(!m)return null;
	if(wzID)m.id=wzID;
	m.className="bsm-SrvMenuUI";
	m.setAttribute("popuptype","bsmmenu");
	AddChildToParent(document.body,m);
	return m;
}

function PopMenu(e)
{
	if (e==null)
		e=window.event;
	var nKeyCode;
	if (browseris.nav6up)
		nKeyCode=e.which;
	else
		nKeyCode=e.keyCode;
		
		//todo defer check
		
		g_onKeyPress=true;
		CreateBsmMenu(e);
		g_onKeyPress=false;
		return false;
	/*if (!IsBsmMenuOn())
	{
		g_onKeyPress=true;
		CreateBsmMenu(e);
		g_onKeyPress=false;
		return false;
	}
	else
		return true;*/
}


var g_ClientStoreMinorSeparator = "~";
var g_PreviousSortFilterValue = 0;

//
//sets the selected index to match the value in the clientstore
//
function Select_onmousedown(dropdown, columnName, clientStoreHidden)
{
	var filterArrayString = GetPreviousFilterValue(columnName, clientStoreHidden);
	var filterArray = filterArrayString.split(':');
	var filterType = filterArray[0];
	g_PreviousSortFilterValue = 0;
	
	switch(filterType)
	{
		case "ALL":
			g_PreviousSortFilterValue = 0;
			break;				
		case "TOP_ITEM":
		case "TOP_PERCENTAGE":
		case "BOTTOM_ITEM":
		case "BOTTOM_PERCENTAGE":
			g_PreviousSortFilterValue = 3;
			break;
		case "CUSTOM":
			g_PreviousSortFilterValue = 4;
			break;
			
		default:
			g_PreviousSortFilterValue = 0;
			break;
	}
}

function Select_onchange(dropdownId, columnName, filterStoreHiddenId, lcid, coltype) 
{
	g_sortFilterValuesArray = GetSortFilterValues(filterStoreHiddenId);
	
	var dropdown = document.getElementById(dropdownId);
	
	if(dropdown!=null)
	{
	    var index = dropdown.selectedIndex;
    	
	    //update the g_sortFilterValuesArray based on the selection
	    switch(index)
	    {
		    case 0:  //(All)
			    UpdateField(columnName, "", "ALL");		
			    dropdown.selectedIndex = 0;
			    break;

		    case 1:  //sort ascending
			    var filter = GetPreviousFilterValue(columnName, filterStoreHiddenId);
			    UpdateField(columnName, "ASC", filter);
			    dropdown.selectedIndex = 1;
			    break;

		    case 2:  //sort descending		
			    var filter = GetPreviousFilterValue(columnName, filterStoreHiddenId);
			    UpdateField(columnName, "DESC", filter);
			    dropdown.selectedIndex = 2;
			    break;
    		
		    case 3:  //(Top 10...)
    		
			    var filter = GetPreviousFilterValue(columnName, filterStoreHiddenId);
			    var sort = GetPreviousSortValue(columnName, filterStoreHiddenId);
    			
			    var arg = new Array();
			    arg[0] = filter;
			    arg[1] = lcid;
			    var newFilter = ShowTop10Dialog(arg,coltype);
			    if (false == newFilter)
			    {
				    dropdown.selectedIndex = g_PreviousSortFilterValue;
				    return false;
			    }
    			
			    UpdateField(columnName, sort, newFilter);
			    break;
    		
		    case 4:  //(Custom...)
			    var filter = GetPreviousFilterValue(columnName, filterStoreHiddenId);
			    var sort = GetPreviousSortValue(columnName, filterStoreHiddenId);
    			
			    var arg = new Array();
			    arg[0] = columnName;
			    arg[1] = filter;
			    arg[2] = lcid;
			    arg[3] = coltype;
    			
			    var newFilter = ShowCustomDialog(arg);
			    if (false == newFilter)
			    {
				    dropdown.selectedIndex = g_PreviousSortFilterValue;
				    return false;
			    }
    			
			    UpdateField(columnName, sort, newFilter);
			    break;
	    }
	}
	
	//now update the store based on the g_sortFilterValuesArray
	UpdateStore(filterStoreHiddenId);
}

function UpdateStore(storeId)
{
    var filterstoreEle = document.getElementById(storeId);
    
    if(filterstoreEle!=null)
    {
	    var newStoreValue = "";
    	
	    for(key in g_sortFilterValuesArray)
	    {
		    var sortFilterValueArray = g_sortFilterValuesArray[key];
    	
		    newStoreValue += key + g_ClientStoreMinorSeparator + sortFilterValueArray[0] + g_ClientStoreMinorSeparator + sortFilterValueArray[1] + "|";
	    }
    	
	    filterstoreEle.value = newStoreValue.substr(0, newStoreValue.length - 1); //remove the last ","
	}
}


function UpdateField(column, sort, filter)
{
	var newArray = new Array(g_sortFilterValuesArray.length);
	
	//copy all the elements except for the current column selection to newArray
	var i = 0;
	for(title in g_sortFilterValuesArray)
	{
		if(title != column)
			newArray[title] = g_sortFilterValuesArray[title];
	
	}
	
	//now add the current column selection
	newArray[column] = new Array(sort,filter);
	
	//now replace the global store
	g_sortFilterValuesArray = newArray;

}


function GetPreviousSortValue(columnName, store)
{
	
	var sortFilter = g_sortFilterValuesArray[columnName];
	
	if(sortFilter != null)
		return sortFilter[0];
	else
		return "";

}


function GetPreviousFilterValue(columnName, storeId)
{
	g_sortFilterValuesArray = GetSortFilterValues(storeId);
	
	var sortFilter = g_sortFilterValuesArray[columnName];
	
	if(sortFilter != null)
		return sortFilter[1];
	else
		return "";

}


var g_sortFilterValuesArray;

function GetSortFilterValues(storeId)
{
    var filterstoreEle = document.getElementById(storeId);
    var sortFilterArray = new Array();
    
    if(filterstoreEle!=null)
    {
	    //get the previous values of the sort filed
	    if(filterstoreEle.value != null && filterstoreEle.value != "")
	    {
		    var sortFilterTriples = filterstoreEle.value.split("|");
		    for(i = 0; i < sortFilterTriples.length; i++)
		    {
			    var triple = sortFilterTriples[i].split(g_ClientStoreMinorSeparator);

			    sortFilterArray[triple[0]] = new Array(triple[1],triple[2]); 
		    }
	    }
	}
	
	return sortFilterArray;
}


//
//dialog related section
//
function ShowCustomDialog(args)
{
	var dialogFeatures = "dialogHeight: 300px; dialogWidth: 500px; ";
	dialogFeatures += "dialogTop: 200px; dialogLeft: 200px; scroll:no; center: Yes; help: No; resizable: Yes; status: No;";
	
	var ret = window.showModalDialog(g_resFolder + "CustomFilter.htm", args, dialogFeatures);
	return ret;
}
function ShowTop10Dialog(args,coltype)
{
	var dialogFeatures = "dialogHeight: 140px; dialogWidth: 600px; ";
	dialogFeatures += "dialogTop: 200px; dialogLeft: 200px; scroll:no; center: Yes; help: No; resizable: Yes; status: No;";

	var ret = window.showModalDialog(g_resFolder + "Top10Filter.htm" , args, dialogFeatures);
	return ret;
}


function UpdateScorecardTableRows(arg, context)
{
     var element = document.getElementById(context);
     element.innerHTML = arg;
}

function CheckMaxLength(field, maxlimit) 
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
	}
}

function MapImagePath(sitePath, imageName) 
{
	return sitePath + imageName;
}

function MapPath(sitePath, url) 
{
	return sitePath + url;
}

function HelpPopUp(sitePath, url) 
{
	var wndHelp = window.open(MapPath(sitePath, url), "SCORECARDHELP", "width=400,height=700,menubar,scrollbars,toolbar,resizable");
    wndHelp.focus();
}

function ScorecardTableCollapseAll(sitePath, beginWithId, rootId) 
{
	var trs = document.getElementsByTagName('tr');
	for (i = 0; i < trs.length; i++) 
	{
		if (ScorecardPreivewIsElement(trs[i]) && trs[i].KpiId.indexOf(beginWithId) > -1) 
		{	
			if (trs[i].KpiId != beginWithId + rootId) 
			{
				var image = ScorecardPreviewGetImage(trs[i]);	
				if (image != null)			
					image.src = MapImagePath(sitePath,'Plus.gif');
				trs[i].Expanded = 'false';		
				trs[i].style.display = 'none';				
			}
			else 
			{
				trs[i].Expanded = 'false';
				ScorecardPreviewGetImage(trs[i]).src = MapImagePath(sitePath, 'Plus.gif');	
			}
		}
	}
}

function ScorecardTableExpandAll(sitePath, beginWithId, rootId) {
	var trs = document.getElementsByTagName('tr');
	for (i = 0; i < trs.length; i++) 
	{
		if (ScorecardPreivewIsElement(trs[i]) && trs[i].KpiId.indexOf(beginWithId) > -1) 
		{	
			if (trs[i].KpiId != beginWithId + rootId) 
			{
				var image = ScorecardPreviewGetImage(trs[i]);
				if (image != null)				
					image.src = MapImagePath(sitePath, 'Minus.gif');
				trs[i].Expanded = 'true';
				trs[i].style.display = 'inline';				
			}
			else 
			{
				trs[i].Expanded = 'true';
				ScorecardPreviewGetImage(trs[i]).src = MapImagePath(sitePath, 'Minus.gif');	
			}
		}
	}
}

function ScorecardPreviewToggle(imagePath) 
{
	var toggle_icon = window.event.srcElement;
	var toggle_src = ScorecardPreivewGetElement(toggle_icon);
	ScorecardPreviewToggleParams(imagePath, toggle_icon, toggle_src);
}

function ScorecardPreviewToggleParams(imagePath, toggle_icon, toggle_src) 
{
	var trs = document.getElementsByTagName('tr');
	for (i = 0; i < trs.length; i++) 
	{
		if (trs[i].KpiParentId) 
		{
			if (trs[i].KpiParentId == toggle_src.KpiId) 
			{
				if (toggle_src.Expanded == 'false') 
				{
					trs[i].style.display = 'inline';
					ScorecardPreivewShowChildren(trs[i], trs);
				}
				else 
				{
					trs[i].style.display = 'none';
					ScorecardPreivewHideChildren(trs[i], trs);
				}
			}
		}
	}

	if (toggle_src.Expanded == 'false') 
	{
		toggle_icon.src = imagePath + 'Minus.gif';
		toggle_src.Expanded = 'true';
	}
	else 
	{
		toggle_icon.src = imagePath + 'Plus.gif';
		toggle_src.Expanded = 'false';
	}
}

function  ScorecardPreivewHideChildren(src, trs) 
{
	var j = 0;
	for (j = 0; j < trs.length; j++) 
	{
		if (trs[j].KpiParentId) 
		{
			if (trs[j].KpiParentId == src.KpiId) 
			{
				trs[j].style.display = 'none';
				ScorecardPreivewHideChildren(trs[j], trs);
			}
		}
	}
}

function ScorecardPreivewShowChildren(src, trs) 
{
	if (src.Expanded == 'false') 
		return;
	
	var j = 0;
	for (j = 0; j < trs.length; j++) 
	{
		if (trs[j].KpiParentId) 
		{
			if (trs[j].KpiParentId == src.KpiId) 
			{
				trs[j].style.display = 'inline';
				ScorecardPreivewShowChildren(trs[j], trs);
			}
		}
	}
}

function ScorecardPreivewGetElement(src) 
{
	var parentSrc = src;
	while (parentSrc != null && !ScorecardPreivewIsElement(parentSrc))
		parentSrc = parentSrc.parentElement;
	
	return parentSrc;
}

function ScorecardPreivewIsElement(src) 
{
	if (src.KpiId) 
		return true;
	else
		return false;
}

function ScorecardPreviewGetImage(src) 
{
	var imageSrc = src;
	
	while (imageSrc != null && imageSrc.tagName != "IMG") {
		imageSrc = imageSrc.firstChild;
	}
	
	return imageSrc;
}

function ToggleFoldablePanel(sitePath, id) 
{
	var divTag = document.getElementById(id + '_div');
	var hiddenDivTag = document.getElementById(id + '_hidden');
	var imageTag = document.getElementById(id + '_img');
	if (divTag.style.display == 'none')
	{
		imageTag.src= MapPath(sitePath, 'TPMin1.gif');
		divTag.style.display = '';
		hiddenDivTag.style.display = 'none';
		SetCookie(id, 'false');
	}
	else
	{
		imageTag.src= MapPath(sitePath, 'TPMax1.gif');
		divTag.style.display = 'none';
		hiddenDivTag.style.display = '';
		SetCookie(id, 'true');
	}
}

function InitializeFoldablePanel(id) 
{
	var isFolded = GetCookie(id);
	if ('true' == isFolded) ToggleFoldablePanel(id);
}

function SetCookie(attr, value)
{
	document.cookie = attr + '=' + value;
}

function GetCookie(attrToFind)
{
	var allcookies = document.cookie;
	var elementName = attrToFind + '=';
	var pos = allcookies.indexOf(elementName);
	var value = '';

	if (pos != -1)
	{
		var start = pos + attrToFind.length + 1;
		var end = allcookies.indexOf(';', start);
		value = allcookies.substring(start, end);
	}
	
	return value;
}

function BITreeNodeToggle(sitePath) 
{
	var toggle_icon = window.event.srcElement;
	var toggle_src = BITreeNodeGetElement(toggle_icon)
	BITreeNodeToggleParams(sitePath, toggle_icon, toggle_src);
}

function BITreeNodeToggleParams(sitePath, toggle_icon, toggle_src_orgin) 
{
	var toggle_src = toggle_src_orgin.nextSibling;
	if (toggle_src.style.display == 'none')
	{
		toggle_src.style.display = 'inline';
		toggle_icon.src = MapImagePath(sitePath, 'Minus.gif');
		SetCookie(toggle_src_orgin.BITreeId + '_' + toggle_src_orgin.BITreeNodeId, 'true')
	}
	else
	{
		toggle_src.style.display = 'none';
		toggle_icon.src = MapImagePath(sitePath, 'Plus.gif');
		SetCookie(toggle_src_orgin.BITreeId + '_' + toggle_src_orgin.BITreeNodeId, 'false')
	}
}

function  BITreeNodeGetElement(src) 
{
	var parentSrc = src;
	while (parentSrc != null && !BITreeNodeIsElement(parentSrc))
		parentSrc = parentSrc.parentElement;
	
	return parentSrc;
}

function BITreeNodeIsElement(src) 
{
	if (src.BITreeNode) 
		return true;
	else
		return false;
}

function  BITreeNodeGetImage(src) 
{
	return src.children[0].children[0].children[0].children[0].children[0];
}

function InitializeBITree(sitePath, treeId) 
{
	var treeElement = document.getElementById(treeId);
	var divs = treeElement.getElementsByTagName('div');
	for (i = 0; i < divs.length; i++) 
	{
		if (BITreeNodeIsElement(divs[i])) 
		{
			if (('true' == GetCookie(divs[i].BITreeId + '_' + divs[i].BITreeNodeId)) &&  ('false' == divs[i].BITreeNodeExpaneded)) 
			{
				BITreeNodeToggleParams(sitePath, BITreeNodeGetImage(divs[i]), divs[i]);
			}
		}
	}
}

function DimensionSlicerSelect(atag) 
{
	var parentTag = DimensionSliceGetSlice(atag);
	var myTables = document.getElementsByTagName('table');
	
	if (parentTag.SliceSelected && parentTag.SliceSelected == "true") 
	{
		parentTag.SliceSelected = "false";
		parentTag.className = "";
	}	
	else 
	{	
		for (i = 0; i < myTables.length; i++) 
		{	
			if (DimensionSlicerIsSlice(myTables[i])) 
			{
				myTables[i].className = "";		
				myTables[i].SliceSelected = "false";		
			}
		}					
	
		parentTag.SliceSelected = "true";
		parentTag.className = "bsm-UserCellSelected";
	}			
}

function DimensionSlicerIsSlice(src) 
{
	if (src.Slice) 
		return true;
	else
		return false;
}

function  DimensionSliceGetSlice(src) 
{
	var parentSrc = src;
	while (parentSrc != null && !DimensionSlicerIsSlice(parentSrc))
		parentSrc = parentSrc.parentElement;
	
	return parentSrc;
}

function DecodeSingleQuote(inStr) 
{
	return inStr.replace("&apos;", "'");
}	

function DimensionSlicerSetReturnValue()
{
	var myTables = document.getElementsByTagName('table');
	for (i = 0; i < myTables.length; i++) 
	{	
		if (DimensionSlicerIsSlice(myTables[i]) && myTables[i].SliceSelected == "true") 
		{		
			var returnParams = new Object();
			returnParams.SliceUniqueName = escape(DecodeSingleQuote(myTables[i].Slice));
			returnParams.SliceName = escape(DecodeSingleQuote(myTables[i].SliceName));
			window.returnValue = returnParams;
			window.close();
			return;
		}		
	}
	
	var returnParams = new Object();
	returnParams.SliceUniqueName = "";
	returnParams.SliceName = "";
	window.returnValue = returnParams;	
	window.close();		
}

function DimensionSlicerSetEmptyReturnValue()
{
	var returnParams = new Object();
	returnParams.SliceUniqueName = "";
	returnParams.SliceName = "";
	window.returnValue = returnParams;			
}

function DimensionSlicerTruncate(dimStr) 
{	
	var truncateDimStr = "";
					
	if (dimStr == null || dimStr.length == 0) 
		truncateDimStr = " ";
	else
	{
		var periodPos = dimStr.lastIndexOf(".");
		if (periodPos >= 0 && periodPos < dimStr.length -1)
		{
			truncateDimStr = dimStr.substring(periodPos+1);
		}
		else
		{
			truncateDimStr = dimStr;
		}
	}
	
	if (truncateDimStr.length >= 25) 
		truncateDimStr = "..." + truncateDimStr.substring(truncateDimStr.length - 24);
	
	return truncateDimStr;
}

function CustomViewDesignToggle(sitePath, paramString) 
{
	var toggle_icon = window.event.srcElement;
	var toggle_src1 = BITreeNodeGetElement(toggle_icon)	
	var child_src = toggle_src1.nextSibling;
	
	if (child_src.style.display == "none") 
	{
		if (child_src.getAttribute("loaded") == "false") 
		{
			child_src.innerHTML = "<div error=\"true\" class=\"ms-forminput\" style=\"MARGIN-LEFT:20px;\">Loading...</div>";
			var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			var strUrl = MapPath(sitePath, "DimensionValuesPartial.aspx?" + paramString);									
			xmlHttp.open("GET", strUrl, false);			
			xmlHttp.send();			
			child_src.innerHTML = xmlHttp.responseText;

			child_src.setAttribute("loaded", "true");						
		}
	}
	
	BITreeNodeToggleParams(sitePath, toggle_icon, toggle_src1);
}

function CustomViewDesignFindImage(src) 
{	
	var childSrc = src;
	while (childSrc != null && childSrc.tagName != "IMG")
		childSrc = childSrc.firstChild;
	
	return childSrc;
}

function CustomViewDimensionChecked(sitePath, atag) 
{
	var sliceTag = DimensionSliceGetSlice(atag);
	var imageTag = CustomViewDesignFindImage(atag.previousSibling.previousSibling);
	var myTables = document.getElementsByTagName('table');
	
	if (sliceTag.SliceSelected == "true") 
	{
		sliceTag.SliceSelected = "false";		
		imageTag.src = MapImagePath(sitePath, "CheckOpen.gif");
				
		var parnetTag = CustomViewGetParent(myTables, sliceTag);
		
		// run up the tree seeing if each level has other selected
		while (parnetTag != null) 
		{															
			if (CustomViewHasChildrenChecked(myTables, parnetTag))
				break; 
				
			parnetTag.SliceSelected = "false";		
			CustomViewDesignFindImage(parnetTag).src = MapImagePath(sitePath, "CheckOpen.gif");	
			
			parnetTag = CustomViewGetParent(myTables, parnetTag);
		}	
	}	
	else if (sliceTag.SliceSelected == "partial") 
	{	
		CustomViewUnCheckChildren(sitePath, myTables, sliceTag);
		
		sliceTag.SliceSelected = "true";		
		imageTag.src = MapImagePath(sitePath, "Check.gif");	
	}
	else 
	{				
		CustomViewCheck(sitePath, myTables, sliceTag, imageTag);
	}
}

function CustomViewUnCheckChildren(sitePath, myTables, sliceTagIn) 
{	
	var stack = new Array();
	stack.push(sliceTagIn);
	
	while (stack.length > 0) 
	{
		var sliceTag = stack.pop();
	
		for (i = 0; i < myTables.length; i++) 
		{	
			if (DimensionSlicerIsSlice(myTables[i]) && sliceTag.Slice == myTables[i].SliceParent) 
			{
				if (myTables[i].SliceSelected == "true" || myTables[i].SliceSelected == "partial")
				{			
					myTables[i].SliceSelected = "false";	
					var childImageTag = CustomViewDesignFindImage(myTables[i]);
					childImageTag.src = MapImagePath(sitePath, "CheckOpen.gif");		
					stack.push(myTables[i]);		
				}
			}		
		}
	}			
}

function CustomViewGetParent(myTables, itemTag) 
{
	var parentTag;
	var parentSlice = "";

	for (i = 0; i < myTables.length; i++) 
	{	
		if (DimensionSlicerIsSlice(myTables[i]) && itemTag.SliceParent == myTables[i].Slice) 
		{							
			parentTag = myTables[i];
			break;
		}		
	}
	
	return parentTag;	
}

function CustomViewHasChildrenChecked(myTables, itemTag) 
{
	for (i = 0; i < myTables.length; i++) 
	{	
		if (DimensionSlicerIsSlice(myTables[i]) && itemTag.Slice == myTables[i].SliceParent) 
		{		
			if (myTables[i].SliceSelected == "true" || myTables[i].SliceSelected == "partial")
				return true;					
		}
	}
	
	return false;	
}

function CustomViewCheck(sitePath, myTables, sliceTag, imageTag) 
{
	var parnetTag = CustomViewGetParent(myTables, sliceTag);

	while (parnetTag != null) 
	{																				
		parnetTag.SliceSelected = "partial";	
		var parentImageTag = CustomViewDesignFindImage(parnetTag);
		parentImageTag.src = MapImagePath(sitePath, "CheckGray.gif");	
		
		parnetTag = CustomViewGetParent(myTables, parnetTag);
	}			
	
	sliceTag.SliceSelected = "true";		
	imageTag.src = MapImagePath(sitePath, "Check.gif");	
}

function CustomViewGetDimensionValues(dimensionValues, dimensionDisplayValues, dimensionParentValues) 
{
	var returnValues = "";
	var returnDisplayValues = "";
	var returnParentValues = "";
	var myTables = document.getElementsByTagName('table');
	
	for (i = 0; i < myTables.length; i++) 
	{	
		if (DimensionSlicerIsSlice(myTables[i]) && (myTables[i].SliceSelected == "partial" || myTables[i].SliceSelected == "true")) 
		{			
			if (returnValues.length > 0) {
				returnValues += "|";
				returnDisplayValues += "|";
				returnParentValues += "|";
			}
			
			returnValues += myTables[i].Slice;
			returnDisplayValues += myTables[i].SliceDisplayName;
			returnParentValues += myTables[i].SliceParent;
		}
	}
	
	dimensionValues.value = returnValues;
	dimensionDisplayValues.value = returnDisplayValues;	
	dimensionParentValues.value = returnParentValues;
}


function SetFocusOnFirstInputElement() 
{
	var inputs = document.getElementsByTagName("input");
	if ( inputs )
	{
		var inputElement;
		for ( var i=0; i < inputs.length; i++ )
		{
			inputElement = inputs[i];
			if ( (inputElement.type != "hidden") && !inputElement.disabled )
			{	
				inputElement.focus();
				break;
			}
		}
	}
}

function HandleRvDropdownChange(me, rvidStore)
{
    var table = me.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
    var frame = table.getElementsByTagName("iframe")["RvFrame"];
    var src = frame.src;
    var pos1 = src.lastIndexOf("rvid=");
    if (pos1 > 0)
    {
        pos1 += 5;
        var pos2 = src.indexOf("&", pos1);
        if (pos2 < 0)
            pos2 = src.length - 1;
        var tokens = me.value.split(";");

        if (tokens.length > 0)
        {
            var rvid = tokens[0];
            var newSrc = src.substr(0, pos1) + rvid + src.substr(pos2);
            frame.src = newSrc;
            rvidStore.value = rvid;
            
            if (tokens.length > 2)
            {
                var height = tokens[1];
                var width = tokens[2];
                frame.height = height;
                frame.width = width;
            }
            
            if (tokens.length > 3)
            {
                var ctype = document.createAttribute("ctype");
                ctype.value = tokens[3];
                frame.attributes.setNamedItem(ctype);
            }
        }
    }
}

function ShowRvPopup(me)
{
    var table = me.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
    var frame = table.getElementsByTagName("iframe")["RvFrame"];
    var src = frame.src + "&popup=1";

    var height = GetToken(src, "msht=", "&");
    var width = GetToken(src, "mswd=", "&");
    
    var ctypeAttr = frame.attributes.getNamedItem("ctype");
    if (ctypeAttr != null && ctypeAttr.value == "u")
    {
        window.open(src, "_blank", "width=" + width + ", height=" + height + ", resizable=yes, location=yes, menubar=yes, toolbar=yes, status=yes, scrollbars=yes");
    }
    else
    {
        window.open(src, "_blank", "width=" + width + ", height=" + height + ", resizable=yes, location=yes, menubar=yes, toolbar=yes, status=yes");
    }
}

function GetToken(str, startDelimiter, endDelimiter)
{
    var result = "";
    
    var pos1 = str.lastIndexOf(startDelimiter);
    if (pos1 > 0)
    {
        pos1 += startDelimiter.length;
        var pos2 = str.indexOf(endDelimiter, pos1);
        if (pos2 < 0)
            pos2 = str.length;

        result = str.substr(pos1, pos2-pos1);
    }
    
    return result;
}

var g_visibilityArray = new Array();
var g_visibilityStore;

function StartupVisibility(visibiltyStore)
{
	g_visibilityStore = document.getElementById(visibiltyStore);
	GetVisibilityValuesFromStore(g_visibilityStore);
	
	UpdateVisibility();
}

//
// updates the visitility store and sets visibility of the 
// components to the proper value
//
function UpdateVisibility()
{
	g_visibilityStore.value = "";

	for(var id in g_visibilityArray)
	{
		var el = document.getElementById(id);
		el.style.display = g_visibilityArray[id];

		//now clean up the store
		g_visibilityStore.value += id + "," + g_visibilityArray[id] + "|";
	}

	//remove the last |
	g_visibilityStore.value = g_visibilityStore.value.substr(0, g_visibilityStore.value.length - 1);
}

function GetVisibilityValuesFromStore()
{
	var pairs = g_visibilityStore.value.split("|");
	
	//split returns a "" even if the value was "" to begin with
	if(pairs == "")
		return;
	
	for(i = 0; i < pairs.length; i++)
	{
		var pair = pairs[i];

		var val = pair.split(",");
		g_visibilityArray[val[0]] = val[1];
	}
}

//
// toggle the visibility of the element
//
function HideUnhide(element)
{
	var vis = '';
	
	// get the original value
	var vis = element.style.display
	
	//toggle it
	if (vis == 'none')
		vis = '';
	else
		vis = 'none';
	
	//save the value back to the array
	g_visibilityArray[element.id] = vis;
	
	UpdateVisibility();
}

function AutoSize_HandleResize()
{
    var src = window.location.href;
    src = AutoSize_ReplaceToken(src, "msht=", "&", document.body.clientHeight);
    src = AutoSize_ReplaceToken(src, "mswd=", "&", document.body.clientWidth);
    
    window.location.href = src;
}

function AutoSize_ReplaceToken(str, startDelimiter, endDelimiter, replacementToken)
{
    var result = str;
    
    var pos1 = str.lastIndexOf(startDelimiter);
    if (pos1 > 0)
    {
        pos1 += startDelimiter.length;
        var pos2 = str.indexOf(endDelimiter, pos1);
        if (pos2 < 0)
            pos2 = str.length;

        result = str.substr(0, pos1) + replacementToken + str.substr(pos2);
    }
    
    return result;
}

function AutoSizeOWC_HandleResize()
{
    var objs = document.getElementsByTagName("object");
    if (objs != null && objs.length > 0)
    {
        var obj = objs[0];
        obj.style.height = document.body.clientHeight;
        obj.style.width = document.body.clientWidth;
    }
}

//
// toggle the visibility of the element
//
function HideUnhideEx(elementId,spaceTableId)
{
	var vis = '';
	
	var element = document.getElementById(elementId);
	var spaceEle = document.getElementById(spaceTableId);
	// get the original value
	var vis = element.style.display;
	
	//toggle it
	if (vis == 'none')
		vis = '';
	else
		vis = 'none';
	
	element.style.display = vis;
	spaceEle.style.display = vis;
	
	var currEvent = window.event;
    var currToolbarItem = window.event.srcElement;
    if(currToolbarItem == null)
     return;
    var currToolbarItemCell = getCellElementFromEvent(currToolbarItem); 
    currToolbarItem.focus();
    selectCell(currToolbarItemCell);
}

var g_httpObj =null;
var g_targetItemId = null; 

function getHTTPObject() 
{

  var xmlhttp;

  if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    
  return xmlhttp;

}

function handleClickEvent(controlCallbackPath, //WebMethod Name
                          scMode ,           // Mode
                          inputParams ,      //input param
                          cachedGlobalStateStoreId,
                          clickEvent,      // Event Name 
                          clickEventArgs //Event Arguments
                          )
{
       
           
        var elecachedGlobalStateStoreId = null;
        
        var antenbldviewmode = null;
        var antenbldfiltermode = null;
        var dbitemid = null;
        var dbid = null;
        var cvid = null;
        var pf = null;
        var rowpf = null;
        var colpf = null;
        var tvid = null;
        var filtervid = null;
        var tvctltype = null;
        var filtervctltype = null;
        var proxyid = null;
        var rolluptype = null;
        var mode = null;
        var targetControlType = null;
        //for filter drop down
        var lcid = null;
        var filterstroreId = null;
        var dropdownListId = null;
        var title = null;
        var arrFilterValues = null;
        var showInlineText = false;
        
            
        elecachedGlobalStateStoreId  = document.getElementById(cachedGlobalStateStoreId);
        if(elecachedGlobalStateStoreId!=null)
        {
           antenbldviewmode         = elecachedGlobalStateStoreId.antenbldviewmode ;
           antenbldfiltermode       = elecachedGlobalStateStoreId.antenbldfiltermode;
           dbitemid                 = elecachedGlobalStateStoreId.dbitemid;
           dbid                     = elecachedGlobalStateStoreId.dbid;
           cvid                     = elecachedGlobalStateStoreId.cvid;
           pf                       = elecachedGlobalStateStoreId.pf;
           rowpf                    = elecachedGlobalStateStoreId.rowpf;
           colpf                    = elecachedGlobalStateStoreId.colpf;
           tvid                     = elecachedGlobalStateStoreId.tvid;
           filtervid                = elecachedGlobalStateStoreId.filtervid;
           tvctltype                = elecachedGlobalStateStoreId.tvctltype;
           filtervctltype           = elecachedGlobalStateStoreId.filtervctltype;
           proxyid                  = elecachedGlobalStateStoreId.proxyid;
           rolluptype               = elecachedGlobalStateStoreId.rolluptype;
           mode                     = elecachedGlobalStateStoreId.mode;
            
        }

        if(mode == "view")
        {
            g_targetItemId = tvid;
            targetControlType = tvctltype;
            showannotation = antenbldviewmode;
        }
        else
        {
            g_targetItemId = filtervid;
            targetControlType = filtervctltype;
            showannotation = antenbldfiltermode;
            
        }
        g_isAnnotationEnabled = showannotation;
        
        var currEvent = window.event;
        var currToolbarItem = window.event.srcElement;
        if(currToolbarItem == null)
            return;
        var currToolbarItemCell = getCellElementFromEvent(currToolbarItem); 
        currToolbarItem.focus();
        selectCell(currToolbarItemCell);
        
        switch(clickEvent)
        {
            case "FilterDropdownOnChange":
            {
                arrFilterValues = inputParams.split('$$');
                if(arrFilterValues.length > 0)
                {
                   dropdownListId = arrFilterValues[0];
                   title          = arrFilterValues[1];
                   filterstoreId  = arrFilterValues[2];
                   lcid           = arrFilterValues[3];
                   coltype        = arrFilterValues[4];
                   
                   Select_onchange(dropdownListId, title, filterstoreId, lcid,coltype) ;
                   var filterEle = document.getElementById(filterstoreId);
                   clickEventArgs = filterEle.value;
                }
            }
            break;
            
            case "ToggleTooltipClick":
            {
                 if(currToolbarItem.iconstate)
                 {
                    if(currToolbarItem.iconstate == "enabled")
                    {
                    
                        currToolbarItem.iconstate = "disabled";
                        currToolbarItem.src = g_resFolder + "DisableInlineText.gif";
                        currToolbarItem.title = g_DisableInline_Text;
                        showInlineText = true;
                    }
                    else
                    {
                        currToolbarItem.iconstate = "enabled";
                        currToolbarItem.src = g_resFolder + "EnableInlineText.gif";
                        currToolbarItem.title = g_EnableInline_Text;
                        showInlineText = false;
                    }
                    //pass back the client filter value
                    var filterstoreId = "__" + filtervid + "_ClientStore";
                    var filterEle = document.getElementById(filterstoreId);
                    if(filterEle)
                        clickEventArgs = filterEle.value;
                 }
            }
            break;
        }

         g_httpObj =  getHTTPObject();
        
        if (g_httpObj!=null)
        {
            var url = controlCallbackPath;
            var params = "";
            params += "&scMode=" + escape(mode);
            params += "&cachedGlobalStateStoreId=" + escape(cachedGlobalStateStoreId);
            params += "&dashboardItemId=" + escape(dbitemid);
            params += "&dashboardId=" + escape(dbid);
            params += "&pageFilters=" + escape(pf);
            params += "&rowFilters=" + escape(rowpf);
            params += "&colFilters=" + escape(colpf);
            params += "&targetControlType=" +escape(targetControlType);
            params += "&targetControlId=" + escape(g_targetItemId);
            params += "&clickEvent=" + escape(clickEvent);
            params += "&clickEventArgs=" + escape(clickEventArgs);
            params += "&proxyId=" + escape(proxyid);
            params += "&rollupType=" + escape(rolluptype);
            params += "&resourcePath=" +escape(g_resFolder);
            params += "&showAnnotation=" +escape(showannotation);
            params += "&showInlineText=" +escape(showInlineText);
            
            
            g_httpObj.onreadystatechange= getHandleClickResponse;
            g_httpObj.open('POST',url,true);
            g_httpObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            g_httpObj.send(params);
        }
        else
            alert("Your browser does not support XMLHTTP.");
}
     
     
function getHandleClickResponse()
{
    if (g_httpObj.readyState==4)
    {
        if (g_httpObj.status==200)
        {
            if( null != g_httpObj.responseText && "" != g_httpObj.responseText )
            {

                var html = g_httpObj.responseText;
                if (null != html)
                {
                var targetEle = document.getElementById(g_targetItemId);
                    if( null != targetEle )
                    {
                        html = html.replace(/&lt;/g, "<");
                        html = html.replace(/&gt;/g, ">");
                        html = html.replace(/&amp;/g, "&");
                        html = html.replace(/&apos;/g, "'");
                        html = html.replace(/&quot;/g, '"');
                        html = html.replace(/{PPSMACRI}lt/g, "&lt;");
                        html = html.replace(/{PPSMACRI}gt/g, "&gt;");
                        html = html.replace(/{PPSMACRI}amp/g, "&amp;");
                        html = html.replace(/{PPSMACRI}apos/g, "&apos;");
                        html = html.replace(/{PPSMACRI}quot/g, "&quot;");
                                                
                    targetEle.innerHTML = html;
                    }
                }
            }
        }
         else
            alert("Problem with inbound data.  " + g_httpObj.responseText);
    }                     
}


function SwitchMode(controlCallbackPath, //WebMethod Name
                          inputParams ,      //input param
                          targetItemId,        // TargetItemId to be Replaced -- ViewTable /SortAndFilter 
                          cachedGlobalStateStoreId,
                          clickEvent,      // Event Name 
                          clickEventArgs //Event Arguments
                          )
{
        var elecachedGlobalStateStoreId = null;
        var antenbldviewmode = null;
        var antenbldfiltermode = null;
        var dbitemid = null;
        var dbid = null;
        var cvid = null;
        var pf = null;
        var rowpf = null;
        var colpf = null;
        var tvid = null;
        var filtervid = null;
        var tvctltype = null;
        var filtervctltype = null;
        var proxyid = null;
        var rolluptype = null;
        var mode = null;
        var targetControlType = null;
        //for filter drop down
        var lcid = null;
        var filterstroreId = null;
        var dropdownListId = null;
        var title = null;
        var arrFilterValues = null;
        var tlbId    = null;
        var tlbtype  = null;
        var showInlineText = false;
        
        elecachedGlobalStateStoreId  = document.getElementById(cachedGlobalStateStoreId);
        if(elecachedGlobalStateStoreId!=null)
        {
           antenbldviewmode         = elecachedGlobalStateStoreId.antenbldviewmode ;
           antenbldfiltermode       = elecachedGlobalStateStoreId.antenbldfiltermode;
           dbitemid                 = elecachedGlobalStateStoreId.dbitemid;
           dbid                     = elecachedGlobalStateStoreId.dbid;
           cvid                     = elecachedGlobalStateStoreId.cvid;
           pf                       = elecachedGlobalStateStoreId.pf;
           rowpf                    = elecachedGlobalStateStoreId.rowpf;
           colpf                    = elecachedGlobalStateStoreId.colpf;
           tvid                     = elecachedGlobalStateStoreId.tvid;
           filtervid                = elecachedGlobalStateStoreId.filtervid;
           tvctltype                = elecachedGlobalStateStoreId.tvctltype;
           filtervctltype           = elecachedGlobalStateStoreId.filtervctltype;
           proxyid                  = elecachedGlobalStateStoreId.proxyid;
           rolluptype               = elecachedGlobalStateStoreId.rolluptype;
           mode                     = elecachedGlobalStateStoreId.mode;
           tlbId                    = elecachedGlobalStateStoreId.tlbId;
           tlbtype                  = elecachedGlobalStateStoreId.tlbtype;
        }

        g_targetItemId = targetItemId;
        var controlId = null;
        var showannotation = null;
        var target = document.getElementById(targetItemId);
        
        if(mode == "view")
        {
                elecachedGlobalStateStoreId.mode = "filter";
                controlId = filtervid;
                targetControlType = filtervctltype;
                showannotation = antenbldfiltermode;
        }
        else
        {
               elecachedGlobalStateStoreId.mode = "view";
               controlId = tvid;
               targetControlType = tvctltype;
               showannotation = antenbldviewmode;
        }
        g_isAnnotationEnabled = showannotation;

         g_httpObj =  getHTTPObject();
        
        if (g_httpObj!=null)
        {
            var url = controlCallbackPath;
            var params = "";
            params += "&scMode=" + escape(elecachedGlobalStateStoreId.mode);
            params += "&cachedGlobalStateStoreId=" + escape(cachedGlobalStateStoreId);
            params += "&dashboardItemId=" + escape(dbitemid);
            params += "&dashboardId=" + escape(dbid);
            params += "&pageFilters=" + escape(pf);
            params += "&rowFilters=" + escape(rowpf);
            params += "&colFilters=" + escape(colpf);
            params += "&targetControlId=" + escape(g_targetItemId);
            params += "&ctrlType=" +escape(targetControlType);
            params += "&ctrlId=" + escape(controlId);
            params += "&tlbCtrlType=" + escape(tlbtype);
            params += "&tlbId=" + escape(tlbId);
            params += "&clickEvent=" + escape(clickEvent);
            params += "&clickEventArgs=" + escape(clickEventArgs);
            params += "&proxyId=" + escape(proxyid);
            params += "&rollupType=" + escape(rolluptype);
            params += "&resourcePath=" +escape(g_resFolder);
            params += "&showAnnotation=" +escape(g_isAnnotationEnabled);
            params += "&showInlineText=" +escape(showInlineText);
            
            g_httpObj.onreadystatechange= getHandleClickResponse;
            g_httpObj.open('POST',url,true);
            g_httpObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            g_httpObj.send(params);
           
        }
        else
            alert("Your browser does not support XMLHTTP.");
}
     
     
function getSwitchModeResponse()
{
    if (g_httpObj.readyState==4)
    {
        if (g_httpObj.status==200)
        {
            if( null != g_httpObj.responseText && "" != g_httpObj.responseText )
            {

                var html = g_httpObj.responseText;
                if (null != html)
                {
                var targetEle = document.getElementById(g_targetItemId);
                    if( null != targetEle )
                    {
                html = html.replace(/&lt;/g, "<");
                html = html.replace(/&gt;/g, ">");
                html = html.replace(/&amp;/g, "&");
                html = html.replace(/&apos;/g, "'");
                html = html.replace(/&quot;/g, '"');
                html = html.replace(/{PPSMACRI}lt/g, "&lt;");
                html = html.replace(/{PPSMACRI}gt/g, "&gt;");
                html = html.replace(/{PPSMACRI}amp/g, "&amp;");
                html = html.replace(/{PPSMACRI}apos/g, "&apos;");
                html = html.replace(/{PPSMACRI}quot/g, "&quot;");
                                                            
                    targetEle.innerHTML = html;
                    }
                }
            }
        }
         else
            alert("Problem with inbound data.  " + g_httpObj.responseText);
    }                     
    
}

var lastSelectedEle = null;
var lastSelecedStyle = null;
function UpdateSelectedCellStyle()
{
     /*var currentSelectedEle = window.event.srcElement;
     currentSelectedEle = getCellElementFromEvent(currentSelectedEle);
     if(currentSelectedEle ==null)
	    return false;
	    
    if(lastSelectedEle !=null)
    {
        if(lastSelecedStyle!=null)
            lastSelectedEle.className=lastSelecedStyle;
    }
    if(currentSelectedEle!=null)
    {
        lastSelectedEle = currentSelectedEle;
        lastSelecedStyle = currentSelectedEle.className;
        
        currentSelectedEle.className = "bsm-UserCellSelected";
    }*/
}

         

function getRowFromId(scCtrlId,rowId)
{
    var scElement = document.getElementById(scCtrlId);
    var viewId = null;
    
    if(scElement!=null)
    {
        var mode = scElement.mode;
        if(mode == "view")
        {
            viewId = scElement.tvid;
        }
        else
        {
            viewId = scElement.filtervid;
        }
    }

    var augRowId = viewId + '_' + rowId;
    var row = document.getElementById(augRowId);
    return row;

}


// Collapse All non root level nodes
function CollapseAll(scCtrlId)
{
	var tableElement = document.getElementById(scCtrlId);
	var trs = tableElement.getElementsByTagName("tr");
	var lastChildId = -1;
	for (i = 0; i < trs.length; i++)
	{
		var row = trs[i];

		if (isScorecardRow(row))
		{
            var currentRowLastChildId = parseInt(row.lcId,10);
            
            if(lastChildId >= currentRowLastChildId )
            {
                row.isCollapsed = "true";
                row.style.display = "none";
            }
            else
            {
                lastChildId = currentRowLastChildId;
                var plusMinusImage = GetPlusMinusImage(row);
                if (null != plusMinusImage)
                {
                    plusMinusImage.src = g_resFolder + "plus.gif";
                }
            }
            

	    }
	}
	
	var currEvent = window.event;
    var currToolbarItem = window.event.srcElement;
    if(currToolbarItem == null)
     return;
    var currToolbarItemCell = getCellElementFromEvent(currToolbarItem); 
    currToolbarItem.focus();
    selectCell(currToolbarItemCell);		
}




// expand all rows
//
function ExpandAll(scCtrlId)
{
	var tableElement = document.getElementById(scCtrlId);
	var trs = tableElement.getElementsByTagName("tr");
	for (i = 0; i < trs.length; i++)
	{
		var row = trs[i];

		if (isScorecardRow(row))
		{
		    if(row.isHiddenBasedOnFilterStatus == "false")
		    {
                row.isCollapsed = "false";
                row.style.display = "inline";
                var plusMinusImage = GetPlusMinusImage(row);
        		
	            if (null != plusMinusImage)
	            {
	                plusMinusImage.src = g_resFolder + "minus.gif";
        		
	            }
		    }
		    else
		    {
		        row.isCollapsed = "true";
		        row.style.display = "none";
		        row.style.borderStyle= "none";
		    }
		}
	}
	
	var currEvent = window.event;
    var currToolbarItem = window.event.srcElement;
    if(currToolbarItem == null)
     return;
    var currToolbarItemCell = getCellElementFromEvent(currToolbarItem); 
    currToolbarItem.focus();
    selectCell(currToolbarItemCell);		
}

function ExpandCollapseChildren(scCtrlId,rowId)
{
    
    var row = getRowFromId(scCtrlId,rowId);
    var plusMinusImage = GetPlusMinusImage(row);
    if (null != plusMinusImage)
    {
        if(plusMinusImage.state == "expanded")
        {
            collapseAllChildren(scCtrlId,rowId);
            plusMinusImage.state = "collapsed";
        }
        else
        {
            expandAllChildren(scCtrlId,rowId);
            plusMinusImage.state = "expanded";       
        }
    }
}


function FilterRowsBasedOnIndicators(scCtrlId,selectedIndicator)
{
    var tokens = selectedIndicator.split(".");
    var indicatorId = tokens[0];
    var inBandId = tokens[1];
	var rowsToIgnore = ",";
	
	var tableElement = document.getElementById(scCtrlId);
	var trs = tableElement.getElementsByTagName("tr");
	for (i = trs.length - 1; i >= 0 ; i--)
	{
		var row = trs[i];
		var isRowShown  = false;
		
		if (isScorecardRow(row))
		{
			if (indicatorId != "00000000-0000-0000-0000-000000000000")
			{
				var tds = row.getElementsByTagName("td");
				for (j = 0; j < tds.length; j++)
				{
					var td = tds[j];

					if (td.bpm_iid == indicatorId && td.bpm_ib == inBandId)
					{
						isRowShown = true;
						break;
					}
				}
				
				if (isRowShown && row.isCollapsed == "false")
				{
					row.isHiddenBasedOnFilterStatus = "false";
					row.style.display = "inline";
				}
				else
				{
					row.isHiddenBasedOnFilterStatus = "true";
					row.style.display = "none";
				}
			}
			else
			{
			   row.isHiddenBasedOnFilterStatus = "false";
			   row.style.display = "inline";
			}
			
		}
	}
}

//This function will be used to create dyanmic css styles
function ReadStyleSheets()
    {
    for (var nSS = 0; nSS < document.styleSheets.length; nSS++)
    {
        var oStyleSheetSrc = document.styleSheets[nSS];
        
            for (var nRule = 0; nRule < oStyleSheetSrc.rules.length; nRule++)
            {
                var oRule = oStyleSheetSrc.rules[nRule];
                wzCssText = oRule.style.cssText;
                
            }
    }
}


function HandleAnnotations(scElementId)
{
    var scElement = document.getElementById(scElementId);
    var mode = scElement.mode;
    var antenbldviewmode   = null;
    var antenbldfiltermode = null;
    var bshowAnnotation = false;

    if(mode == "view")
    {
        antenbldviewmode   = scElement.antenbldviewmode ;
        if(antenbldviewmode == "true")
        {
            scElement.antenbldviewmode ="false";
            bshowAnnotation = false;
        }
        else
        {
            scElement.antenbldviewmode ="true";
            bshowAnnotation = true
        }
    }       
    else
    {
        antenbldfiltermode = scElement.antenbldfiltermode;
        if(antenbldfiltermode== "true")
        {
            scElement.antenbldfiltermode ="false";
            bshowAnnotation = false;
        }
        else
        {
            scElement.antenbldfiltermode ="true";
            bshowAnnotation = true;
         }
    }
    
    var showdetail = scElement.showdetailenabled;
    
    if(showdetail == "true")
        g_ShowDetails = true;
    else
        g_ShowDetails = false;
        
        
    var currEvent = window.event;
    var currToolbarItem = window.event.srcElement;
    if(currToolbarItem == null)
     return;
    var currToolbarItemCell = getCellElementFromEvent(currToolbarItem); 
    currToolbarItem.focus();
    selectCell(currToolbarItemCell);
            
    if(bshowAnnotation)
    {
        currToolbarItem.src = g_resFolder + "icon.disableannotations.gif";
        currToolbarItem.title = g_DisableAnnotation_Tooltip;
    }
    else
    {
        currToolbarItem.src = g_resFolder + "icon.enableannotations.gif";
        currToolbarItem.title = g_EnableAnnotation_Tooltip;
    }
    g_isAnnotationEnabled = bshowAnnotation;
    
	var trs = scElement.getElementsByTagName("tr");
	var iRowCounter = 0;
	var iColCounter = 0;
	for (; iRowCounter < trs.length ; iRowCounter++)
	{
		var row = trs[iRowCounter];
		if (isScorecardRow(row))
		{
		    var tds = row.getElementsByTagName("TD");
			for (iColCounter = 0; iColCounter < tds.length; iColCounter++)
			{
			    if(tds[iColCounter].className != "bsm-scItemAnntCell")
			      continue;
			      
			    var divcontainer = null;
			      
                divcontainer = getAnnotationbubbleElement(tds[iColCounter]);
                if(!g_isAnnotationEnabled)
                {
                    //annotaion toggle hide the bubble icon                   
                   divcontainer.style.visibility = "hidden";
                    continue;
                }
                else
                {
                      if(tds[iColCounter].annotated == "True")
                        divcontainer.style.visibility = "visible";
                      else
                       divcontainer.style.visibility = "hidden";
                }
		   }
        }
     }
}


function fnonclick(scElementId)
{
    //Get the cell Element
     var currCell = window.event.srcElement;
     currCell = getCellElementFromEvent(currCell);
     if(currCell ==null)
	    return false;
	    
	 if(!showDropdownMenu(scElementId,currCell))
        return false;
	
	//read the cell attributes
	var cellpath = null;
	var ddenabled = null;
	var ddTupleXml = "";
	var antaction = "";
	var cellvalue = "";
	
	if(g_isAnnotationEnabled)
	{
        cellpath = currCell.cellpath;
        antaction = currCell.antaction;    
        if (typeof(antaction) == "undefined") 
          antaction = "";
    }
	ddenabled = currCell.ddenabled;
	ddTupleXml = currCell.ddTupleXml;
	
	//get the span element for the cell and read the value of the cell
	var scItemCells = currCell.children;
	var scItemTable = getContainerTable(currCell);
	if(scItemTable !=null)
	{
	   scItemCells = scItemTable.getElementsByTagName("TD");
	}
	
	var bFoundValCell = false; //read  the first scItemValuecell
    for(var i =0 ; scItemCells!=null && i < scItemCells.length && bFoundValCell == false; i++)
    {
        if(scItemCells[i].className == "bsm-scItemValueCellNoWrap" || scItemCells[i].className== "bsm-scItemValueCellWrap")
        {
          var children = scItemCells[i].children;
          for(var j = 0 ; j < children.length ; j++)
          {
            if(children[j].className = "bsm-val")
            {
                var value = children[j].innerText; 
                cellvalue = value;
                if(value.length > 25)
                {
                   cellvalue = value.substr(0,25);
                   cellvalue = cellvalue + "...";
                }            
            }
            bFoundValCell = true;
            break;
          }
        }
    }
    	
    var menuactions = BuildMenuActions(scElementId, cellvalue, cellpath, antaction, ddenabled, ddTupleXml);
    
    OnBsmItem(menuactions);
	
}

function BuildMenuActions(scCtrlId, cellValue, cellPath, cellhyperlinks ,hasShowDetails, showDetailsTupleXml)
{
    var scElement = document.getElementById(scCtrlId);
    var  annotationInfoStr = "AnnotationDetail.aspx" + 
                    "?SCID=" + scElement.scid +
                    "&CVID=" + scElement.cvid +
                    "&PF=" + scElement.pf +
                    "&CCV=" + cellValue +
                    "&HA=" + g_isAnnotationEnabled +
                    "&CELLPATH=" + cellPath +
                    "&RF=" + scElement.rowpf +
                    "&CF=" + scElement.colpf + 
                    cellhyperlinks; //this is for displaying the links in the menu list
   
       
    var showDetailsInfoStr = hasShowDetails + "+" + scElement.scid + "+" + showDetailsTupleXml; 
    return (annotationInfoStr + g_Separator + showDetailsInfoStr);
}     


function expandAllChildren(scCtrlId,rowId)
{
    //Get the current row
    var clickedRow =  getRowFromId(scCtrlId,rowId);
    
    //Reset the plusminus sign
    var plusMinusImage = GetPlusMinusImage(clickedRow);
    if(plusMinusImage!=null)
    {
        plusMinusImage.src = g_resFolder + "minus.gif";
        plusMinusImage.state = "expanded";
        
    }
    
    //Get all the children of the current row.
    var childrenOfRow = getRowChildrenHeirarchy(scCtrlId,rowId);
    
    for (i = 0; i < childrenOfRow.length; i++)
	{
	    //expand all the children
		var row = childrenOfRow[i];
		//check to mainitain the expanded or collapsed state of the children
		//donot show the children who were collapsed by an earlier operation
		if(isAnyAscendantStateCollapsed(scCtrlId, row)) 
		{
            row.isCollapsed = "true";
		    row.style.display = "none";
		    row.style.borderStyle= "none";
		}
		else
		{
		    if(row.isHiddenBasedOnFilterStatus == "false")
		    {
		        row.isCollapsed = "false";
                row.style.display = "inline";
		    }
		    else
		    {
		        row.isCollapsed = "true";
		        row.style.display = "none";
		        row.style.borderStyle= "none";
		    }
		}
        
     }
}


// Return an array of TR that contains all the children of the given row.
function getRowChildrenHeirarchy(scCtrlId,rowId)
{
    var tableElement = document.getElementById(scCtrlId);
	var trs = tableElement.getElementsByTagName("tr");
	var childTrs = new Array();
	var clickedRowId = parseInt(rowId,10);
	var clickedRowLastChildId = 0;
	var j = 0;
    var i = 0;

	for (i = 0; i < trs.length; i++)
	{
	    var row = trs[i];
	    var currentRowId = parseInt(row.rId,10);
	    	    
	    // get the number of hidden rows of the clicked row
	    if ( currentRowId == clickedRowId )
	        clickedRowLastChildId = parseInt(row.lcId,10);
	    
	    //ignore all the rows before the clicked row including the clicked row.    
	    if(!isScorecardRow(row) || currentRowId <= clickedRowId )  
	        continue;
	    
	    if( currentRowId <=  clickedRowLastChildId )   
	    {
	        childTrs[j]=row;
	        j++;
	    }
	    else 
	        break;
	}

	return childTrs;
}

function isAnyAscendantStateCollapsed(scCtrlId,row)
{
    if(row == null || parseInt(row.pId,10) <=0)
        return false;
    
    var parentRow = getRowFromId(scCtrlId ,row.pId);
    
    var plusMinusImage = GetPlusMinusImage(parentRow);
    if(plusMinusImage!=null && plusMinusImage.state == "collapsed" )
        return true;
    else
       return isAnyAscendantStateCollapsed(scCtrlId,parentRow); 
}


function collapseAllChildren(scCtrlId,rowId)
{
    //Get the current row
    var clickedRow =  getRowFromId(scCtrlId,rowId);
    
    //Reset the plusminus sign
    var plusMinusImage = GetPlusMinusImage(clickedRow);
    if(plusMinusImage!=null)
    {
        plusMinusImage.src = g_resFolder + "plus.gif";
        plusMinusImage.state = "collapsed";
        
    }
    
    //Get all the children of the current row.
    var childrenOfRow = getRowChildrenHeirarchy(scCtrlId,rowId);
    
    for (i = 0; i < childrenOfRow.length; i++)
	{
	    //collapse all the children
		var row = childrenOfRow[i];
        row.isCollapsed = "true";
		row.style.display = "none";
        row.style.borderStyle = "none";
     }
}

//this function show/hide the dropdownmenu based on (ON or OFF) status of showdetails and annotaions
function onCellHover(scElementId)
{
    var scElement = document.getElementById(scElementId);
    
    //read the current mode of scorecard and check if the annotation in enabled
    var mode = scElement.mode;
    
    var antenbldforCurrentmode   = null;

    if(mode == "view")
    {
        antenbldforCurrentmode = scElement.antenbldviewmode ;
        if(antenbldforCurrentmode == "true")
            g_isAnnotationEnabled = true;
        else
            g_isAnnotationEnabled = false;
    }       
    else
    {
        antenbldforCurrentmode = scElement.antenbldfiltermode;
        if(antenbldforCurrentmode== "true")
            g_isAnnotationEnabled = true;
        else
            g_isAnnotationEnabled = false;
    }
    
    //check if the showdetails is enabled for the scorecard
    var showdetail = scElement.showdetailenabled;
    
     if(showdetail == "true")
        g_ShowDetails = true;
    else
        g_ShowDetails = false;
    
    //Get the cell Element
     var ele = window.event.srcElement;
     ele = getCellElementFromEvent(ele);
     if(ele ==null)
	    return false;
	
    if(g_isAnnotationEnabled || g_ShowDetails)
    {
        if (IsBsmMenuOn()) // if the menu is already on just retun
		    return false;
    }
	    
	var itemcell = null;	
	itemcell =ele;
	return false;
}


function onCellItemOut()
{
    if(!IsBsmMenuOn())
    {
        var ele = window.event.srcElement;
        ele = getCellElementFromEvent(ele);
        if(ele ==null)
	        return false;
	        
        ele.className="bsm-ustitle";
        ele.onclick="";
	    ele.onmouseout="";
	    
	    var tbl = getContainerTable(ele);
	    tbl.className = "bsm-scItemTable";
	    tbl.onclick="";
	    tbl.onmouseout="";
	  
	}
	return false;
}

function IsContainerCell(ele)
{
  if(ele == null)
    return true;
    
  if(ele.className =="bsm-scItemValueCellNoWrap" ||
    ele.className == "bsm-scItemValueCellWrap" ||
    ele.className =="bsm-scItemCellImgCell" ||
    ele.className == "bsm-scItemAnntCell" ||  
    ele.className == "bsm-scItemDummycell" ||
    ele.className =="bsm-scItemLinkCellNoWarp" ||
    ele.className =="bsm-scItemLinkCellWarp" ||
    ele.className == "bsm-scItemPlusMinusCell")
    return true;
    
   return false;
}

function getCellElementFromEvent(evntEle)
{
    var cellEle = null;
    if(evntEle == null)
        return cellEle;
        
    while(evntEle!= null)
    {
       if(evntEle.tagName =="TD" && !IsContainerCell(evntEle))
            break;
       evntEle = evntEle.parentElement;        
    }
	  
	 cellEle = evntEle;
    
     return cellEle;      
	        
}

function getMenuDropdownElement(cell)
{
    var drpdwnEleSpan = null;
    var children = cell.children;   
    //from the cell
	for(i =0; children!=null && i < children.length ;i++)
	{
        if(children[i].className == "bsm-drpdwn")
	    {
	        drpdwnEleSpan = children[i];
	        break;
	    }
	}
	
	return drpdwnEleSpan;
}
	    

function getAnnotationbubbleElement(cell)
{
    var anntbbleEle = null;
    var children = cell.children;   
    //from the cell
	for(i =0; children!=null && i < children.length ;i++)
	{
        if(children[i].className == "bsm-antbbl")
	    {
	        anntbbleEle = children[i];
	        break;
	    }
	}
	
	return anntbbleEle;
}

function getdropdownImgElement(drpdwnEleSpan)
{
    var drpdwnChildren = null;
	var dropDownEleImg = null;

    if(drpdwnEleSpan)
	    drpdwnChildren = drpdwnEleSpan.children;
    	
    for(i =0; drpdwnChildren!=null && i < drpdwnChildren.length ;i++)
    {
        if(drpdwnChildren[i].className == "bsm-mimgcl")
        {
            dropDownEleImg = drpdwnChildren[i];
            break;
        }
    }
    
    return dropDownEleImg;
}


function showDropdownMenu(scElementId, currCell)
{
    var scEle  = document.getElementById(scElementId);
    var annotaionOn = "false";
    if(scEle!=null) //read the annotation status on the view
    {
        mode = scEle.mode;
        if(mode == "view")
        {
            annotaionOn = scEle.antenbldviewmode
        }
        else
        {
            annotaionOn = scEle.antenbldfiltermode
        }
    }
    
    if(annotaionOn == "false")
        g_isAnnotationEnabled = false;
    else
        g_isAnnotationEnabled = true;
        
      //check if the showdetails is enabled for the scorecard
    var showdetail = scEle.showdetailenabled;
    
     if(showdetail == "true")
        g_ShowDetails = true;
    else
        g_ShowDetails = false;
       
     return (((g_isAnnotationEnabled || g_ShowDetails) )&& (getCellId(currCell) > 0 ));
}
//code for keyboard event handling in the scorecard control 

//returns true if the selected cell is toolbar item
function isToolbarCell(currCell)
{
    if(currCell!= null && currCell.tagName == "TD" && currCell.type !=null)
      return true;
    else
      return false;  
}

//returns true if the selected cell is scorecard item
function isScorecardCell(currCell)
{
    if(getRowFromCell(currCell) == null)
        return false;
     else
     return true;   
}

//selection for the current cell
function selectCell(currCell)
{
    //check the current celltype
    
    if(isToolbarCell(currCell))
    {
        selectToolbarCell(currCell);
        return;
    }
    
    if(isScorecardCell(currCell))
    {
        selectScorecardCell(currCell);
         return;
    }
}

// get the embedded table in the cell

function getContainerTable(src)
{
    if(src!=null)
    {
        var tbls = src.getElementsByTagName("TABLE");
        if (tbls && tbls.length > 0)
        {
	        if (tbls[0].className && tbls[0].className== "bsm-scItemTable")
		        return tbls[0];
        }
    }
    return null;
}

//previous selected cell and style
var g_lastCell = null;
var g_lastCellStyle= null;
var g_lastBkClr= null;

var g_lasttbl = null;

//selection for the scorecard cell
function selectScorecardCell(currCell)
{
  if(g_lastCell == currCell)
  {
        return;
  }
     var currtbl = getContainerTable(currCell);
     if (g_lastCell!=null)
     {
       if((g_lastCellStyle!=null && g_lastCellStyle == "bsm-ustitleSelected")&& (g_lasttbl!=null))
       {
            g_lastCell.className  = "bsm-ustitle";
            g_lastCell.style.backgroundColor = g_lastBkClr; 
            g_lasttbl.style.backgroundColor = g_lastBkClr; 
       }
            
       if((g_lastCellStyle!=null && g_lastCellStyle == "rhcSelected") && (g_lasttbl!=null))
       {
            g_lastCell.className  = "rhc";     
            g_lastCell.style.backgroundColor = g_lastBkClr; 
            g_lasttbl.style.backgroundColor = g_lastBkClr; 
       }
     }
     
      g_lastBkClr = currCell.style.backgroundColor;
     
      if(currCell.className == "bsm-ustitle")
      {
            currCell.className  = "bsm-ustitleSelected";
            currCell.style.backgroundColor = "#fee197";
            currtbl.style.backgroundColor = "#fee197";
      }
            
      if(currCell.className == "rhc")
      {
            currCell.className  = "rhcSelected";   
            currCell.style.backgroundColor = "#fee197";
            currtbl.style.backgroundColor = "#fee197";
      }
            
     g_lastCellStyle = currCell.className;
     g_lastCell = currCell;
     g_lasttbl = currtbl;
     
     return;
}

var g_lastToolbarCell = null;
var g_lastToolbarStyle = null;

//selection for the toolbar cell
function selectToolbarCell(currCell)
{
    if (g_lastToolbarCell!=null)
     {
       if(g_lastToolbarStyle!=null)
        g_lastToolbarCell.className = "bsm-toolbarCell";
     }
     
     g_lastToolbarStyle = currCell.className;
     currCell.className = "bsm-toolbarCellSelected";
     g_lastToolbarCell = currCell;
     return;
}

//reset the tooldbar ite style
function onToolBarDeactivate()
{
    //reset the bkclr
     var ele = window.event.srcElement;
     ele = getCellElementFromEvent(ele);
       if(ele ==null)
	      return false;
	 ele.className = "bsm-toolbarCell";     
	      
}

function onCellblur()
{
     if(!IsBsmMenuOn())
    {
        var ele = window.event.srcElement;
        ele = getCellElementFromEvent(ele);
        if(ele ==null)
	        return false;
    	    
	    itemcell =ele;
        ele.className="bsm-ustitle";
        ele.onclick="";
	    ele.onmouseout="";
        
	}
	return false;
}

//mouse click handler for the table    
function HandleMouseClick()
{
    //get current cell from event
    var currEvent = window.event;
    var currCell = window.event.srcElement;
    
    currCell = getCellElementFromEvent(currCell);
    if(currCell == null)
      return;
      
    if(getRowFromCell(currCell) == null)
        return false;    
    selectCell(currCell);
}

function HandleMouseDown(scElementId)
{
     //get current cell from event
    var currEvent = window.event;
    var currCell = window.event.srcElement;
    if(currEvent.button == 2)
    {
        currCell = getCellElementFromEvent(currCell);
        if(currCell == null)
          return false;
                
        if(getCellId(currCell) == -1)  
            return false ;
            
        if(getRowFromCell(currCell) == null)
            return false;    
        selectCell(currCell);
        fnonclick(scElementId);
    }
}


function HandleContextMenu(scElementId)
{
     //get current cell from event
    var currEvent = window.event;
    var currCell = window.event.srcElement;
    currCell = getCellElementFromEvent(currCell);
    if(currCell == null)
      return false;
            
    if(getCellId(currCell) == -1)  
        return false ;
        
    if(getRowFromCell(currCell) == null)
        return false;    
    selectCell(currCell);
    fnonclick(scElementId);
}

//keyboard event handling
function HandleKeyboardEvents(scElementId)
{
    if(IsBsmMenuOn())
        return false;
        var currEvent = window.event;
        var srcElement= window.event.srcElement;
        var currCell = null;
        var bubbleEvent = true;
        currCell = getCellElementFromEvent(srcElement);
        if(currCell == null)
         return;
        
          // Noncharacter key codes
        var keyLeft = 37;
        var keyRight = 39;
        var keyUp = 38;
        var keyDown = 40;
        var keySpace = 32;
        var keyContextmenu = 93;
        var keyTab = 9;
        var keyEnter = 13
        
		
        var keyPressed = currEvent.keyCode; //Get selected key code
            
        switch (keyPressed)
        {
            case keyLeft:  // 37
            if (currCell.previousSibling != null)
            {
                currCell = currCell.previousSibling;
                currCell.focus();
                if(getRowFromCell(currCell) != null)
                {
                   selectCell(currCell);
                   currEvent.cancelBubble = true;
                   currEvent.keyCode = 0; 
                   bubbleEvent = false;
                }
			}
			
            break;
            
            case keyUp:  // 38
            if (currCell.parentNode.previousSibling != null)
            {
                if(currCell.cellId)
                {
                   currCell= getPrevVisibleCell(currCell);
                   if(currCell!=null)
                   {
                      currCell.focus();
                      if(getRowFromCell(currCell) != null)
                      {
                        selectCell(currCell);
                       
                      }
                    }   
                }
            }
            currEvent.cancelBubble = true;
            bubbleEvent = false;
            currEvent.keyCode = 0; 
            break;
            
            case keyRight:  // 39
            if (currCell.nextSibling != null)
            {
                currCell = currCell.nextSibling;
                currCell.focus();
                if(getRowFromCell(currCell) != null)
                 {
                    selectCell(currCell);
                 }
            }
            currEvent.cancelBubble = true;
            bubbleEvent = false;
            currEvent.keyCode = 0; 
            break;
            
            case keyDown:  // 40
            if (currCell.parentNode.nextSibling != null)
            {
                 if(currCell.cellId)
                {
                   currCell= getNextVisibleCell(currCell);
                   if(currCell!=null)
                   {
                      currCell.focus();
                      if(getRowFromCell(currCell) != null)
                      {
                        selectCell(currCell);
                       
                      }
                    }   
                }
            }
            currEvent.cancelBubble = true;
            bubbleEvent = false;
            currEvent.keyCode = 0; 
            break;

            case keySpace:  // 32 expand collapse
            var img = GetPlusMinusImage(currCell);
            if(img!=null)
            {
                img.click();
               
            }
            currEvent.cancelBubble = true;
            bubbleEvent = false;
            currEvent.keyCode = 0; 
            break;
            
           case keyContextmenu: //context menu for anotations
            HandleContextMenu(scElementId);
            currEvent.cancelBubble = true;
            currEvent.keyCode = 0; 
            break;
                        
            case keyEnter: // anchor element on click simultion
            var anchor = getAnchorElement(currCell)
            if(anchor!=null)
            {
                anchor.click();
                selectCell(currCell);
            }
            currEvent.cancelBubble = true;
            bubbleEvent = false;
            currEvent.keyCode = 0; 
            break;
            
        }
        return bubbleEvent;
}	

//forces the tab order on the links 
function forcetaborder()
{
     var currEvent = window.event;
     var srcElement= window.event.srcElement;
     var currCell = null;
   
     currCell = getCellElementFromEvent(srcElement);
     if(currCell!=null)
     {
          selectCell(currCell);
     }
     currEvent.cancelBubble = true;
}

//reset the scorecard item cell style
function sctableDeactivate()
{
    var currEvent = window.event;
    var srcElement= window.event.srcElement;
    if(srcElement.tagName=="SELECT") // check for the dropdown controls in the filter mode
        return;
   
     currCell = getCellElementFromEvent(srcElement);
     if(currCell !=null)
     {
         if(currCell.className == "bsm-ustitleSelected")
          {
                currCell.className  = "bsm-ustitle";
                currCell.style.backgroundColor = g_lastBkClr;
          }
                
          if(currCell.className == "rhcSelected")
          {
                currCell.className  = "rhc";   
                currCell.style.backgroundColor = g_lastBkClr;
          }
         currEvent.cancelBubble = true;  
    }    
}

//forces the tab order to the first elemnt of the scorecard
function tabeventgrabber(scElementId)
{
     var currEvent = window.event;
     var srcElement= window.event.srcElement;
     var currCell = null;
   
     currCell = getFirstvisibleCell(scElementId);
     if(currCell!=null)
     {
          selectCell(currCell);
     }
     currEvent.cancelBubble = true;
}


//reads the cell id of the scorecard element
function getCellId(cell)
{ 
  var cellId = -1;
  if(cell!==null )
  { 
      cellId = parseInt(cell.cellId);
      if(cellId >= 0) return cellId;
  }
  return cellId;
}

//toolbar items event handler
function HandleToolbarEvents(scElementId)
{
    var currEvent = window.event;
    var currToolbarItem = window.event.srcElement;
    if(currToolbarItem == null)
     return;
    
    var currToolbarItemCell = getCellElementFromEvent(currToolbarItem); 
    var keyPressed = currEvent.keyCode; //Get selected key code
    var keyEnter = 13;
    currToolbarItem.focus();
    selectCell(currToolbarItemCell);
    
    switch(keyPressed)
    {
        case keyEnter: //13
           currToolbarItem.click();
           currEvent.cancelBubble = true;
          break;      
              
    }
}



function getRowFromCell(currCell)
{
    if(currCell== null)
      return null;
    
    var currentRow  = currCell.parentNode;
   
    while(currentRow !=null)
    {
        if(isScorecardRow(currentRow))
            return currentRow;
         currentRow =  currentRow.parentNode;  
    }
    
    return null;
}

//returns the next visible cell in the scorecard in case the rows are hidden
function getNextVisibleCell(currCell)
{
    var cellId = parseInt(currCell.cellId);
    var nextCell = null;
    var nextRow =  null;
    nextRow = currCell.parentNode.nextSibling;
    nextCell  = nextRow.childNodes[cellId];
    while(nextCell !=null)
    {
        //var row = getRowFromCell(prevCell)
        if(isScorecardRow(nextRow) && nextRow.isCollapsed == "false")
          return nextCell;
        else
         {
            nextRow = nextCell.parentNode.nextSibling;
            if(nextRow == null) return null;
            nextCell  = nextRow.childNodes[cellId];
         }
    }
    return null;
}

//returns the previous visible cell in the scorecard in case the rows are hidden
function getPrevVisibleCell(currCell)
{
    var cellId = parseInt(currCell.cellId);
    var prevCell = null;
    var prevRow =  null;
    prevRow = currCell.parentNode.previousSibling;
    prevCell  = prevRow.childNodes[cellId];
    while(prevCell !=null)
    {
        //var row = getRowFromCell(prevCell)
        if(isScorecardRow(prevRow) && prevRow.isCollapsed =="false")
          return prevCell;
        else
         {
            prevRow = prevCell.parentNode.previousSibling;
            if(prevRow == null) return null;
            prevCell  = prevRow.childNodes[cellId];
         }
    }
    return null;
}

//returns the first visible cell in the scorecard in case the rows are hidden
function getFirstvisibleCell(scElementId)
{
    var tableElement = document.getElementById(scElementId);
	var trs = tableElement.getElementsByTagName("tr");
	for (i = 0; i < trs.length; i++)
	{
		var row = trs[i];

		if (isScorecardRow(row)&& row.isCollapsed =="false")
		{
		    return row.childNodes[0];
	    }
	}
}

function getAnchorElement(cell)
{
    if(cell!=null)
    {
	    var anchors = cell.getElementsByTagName("A");
	    for (i = 0; anchors && i < anchors.length; i++)
	    {
		    if (anchors[i].val && anchors[i].val == "bsmval")
			    return anchors[i];
	    }
	}
	
	return null;
}

//tooltip support
var g_ttpTimerId = null;

function showtooltip()
{
    if(g_isMenuShown)
    return;
    hidetooltip();
    // try to reach the parent cell
    var ele = window.event.srcElement;
    if(ele.className == "bsm-scItemImgCell")
      return;
    ele = getCellElementFromEvent(ele);
    if(ele ==null)
    return false;
    g_itemCell = ele;

    if(g_ttpTimerId)
    clearTimeout(g_ttpTimerId);

    g_ttpTimerId =  setTimeout(CreateBsmToolTip,1000);
}


function OntooltipOut()
{
	hidetooltip();
}

function hidetooltip()
{
    if(IstooltipOn())
    {
       g_currentToolTip.hide();
    }
}


function IstooltipOn()
{
    var fIsOpen=false;
    if(g_currentToolTip == null)
        return fIsOpen;

    fIsOpen=g_currentToolTip.isOpen();
    if (!fIsOpen)
        g_isTooltipShown=false;

    return fIsOpen;
}

function CreateBsmToolTip()
{
    if (g_itemCell== null || g_isMenuShown)
        return;
    
    g_isTooltipShown = true;
    window.document.body.onclick="";
    g_currentItemID = g_itemCell.getAttribute("ID");
    var ttp;
    ttp = CBsmToolTip(g_currentItemID + "_bsmtooltip");
    g_currentToolTip = ttp;
 
    //add the tooltip options
    
    
    AddBsmToolTipItems(ttp);
    
    var yOffset = -1;
    if (g_itemCell) yOffset += g_itemCell.offsetHeight;
    OBsmMenu(ttp, g_itemCell, true, null, yOffset);
    return false;
}

//createe tooltip
function CBsmToolTip(wzID)
{
	var ttp=document.getElementById(wzID);
	if (ttp)
	{
		ttp._initialized=false;
		ttp._oContents=null;
		ttp.innerHTML="";
		return ttp;
	}
	ttp=document.createElement("BSMTOOLTIP");
	if(!ttp)return null;
	if(wzID)ttp.id=wzID;
	ttp.className="bsm-SrvMenuUI";
	AddChildToParent(document.body,ttp);
	ttp.setAttribute("popuptype","bsmttp");
	return ttp;
}

function AddBsmToolTipItems(ttp)
{
    var wzType = gettooltipType(g_itemCell);
    var wzDesc = gettooltipDesc(g_itemCell);
    
    AddToolTiphdr(ttp);
    
    if(wzType == "descvaltooltip")
    {
        //only time when the value and desc can be differnet
        var wzValue = gettooltipValue(g_itemCell);
        AddToolTipOptions(ttp,wzType,wzValue,null);
        AddToolTipOptions(ttp,wzType,null,wzDesc);
    }
    else
    {
       AddToolTipOptions(ttp,wzType,null,wzDesc);
    }
}

function AddToolTipOptions(p,wzType,wzValue,wzDesc)
{
	var ttpo=CTooltipOpt(wzType,wzValue,wzDesc);
	if(!ttpo)return null;
	AddChildToParent(p,ttpo);
	return ttpo;
}

function CTooltipOpt(wzType,wzValue,wzDesc)
{
	var ttpo=CToolTipItm(wzType);
	if(!ttpo)return null;
	if(wzDesc!=null)
	 ttpo.setAttribute("ttpdesc",wzDesc);
	if(wzValue!=null)
	 ttpo.setAttribute("ttpval",wzValue);
	return ttpo;
}

function CToolTipItm(wzType)
{
	var ttpi=document.createElement("SPAN");
	if(!ttpi)return null;
	ttpi.setAttribute("type",wzType);
	return ttpi;
}

function gettooltipValue(currCell)
{
    return currCell.ttpVal;
}

function gettooltipType(currCell)
{
    return currCell.ttpType;
}

function gettooltipDesc(currCell)
{
    return currCell.ttpDesc;
}

function CTooltiphdr()
{
	var sep=CToolTipItm("ttpheader");
	SetInnerText(sep, "");
	return sep;
}

function AddToolTiphdr(p)
{
	var ms=CTooltiphdr();
	if(!ms)return null;
	AddChildToParent(p,ms);
	return ms;
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();