
function DundasTreeCBF(controlName, args, event, data) {
	var clientCallback  = DundasTreeCB.callBack;
	var context = DundasTreeCB.createContext(event, data);
	var clientErrorCallback = DundasTreeCB.error;
	OlapCallBack(controlName,args,clientCallback,context,clientErrorCallback,false)
	return false;
}

function OlapCallBackQuirk(controlName, args)
{
	var callbackFunc = "OlapCallBack('" + controlName + "','"+ args + "')"
	setTimeout(callbackFunc, 1);
}

function OlapCallBack(controlName, args, clientCallback, context, clientErrorCallback, synk) {
	if( typeof(synk) != "boolean") {synk = true;} 
	ChartCB.call( null, controlName, args, clientCallback, context, clientErrorCallback, !synk);
}


function dundas_ShowErrorMessage( message)
{
    if ( message.indexOf( "session has expired") != -1) 
     {
        alert(message);
        document.location.replace( document.location.href);
     }
     else
     {
        alert(message);
     }        
}

var DragDropCB = new ChartCBClass();

/// ******************** DundasTreeCB START HERE ******************** ////
/// ******************** Callbacks for treevew   ******************** ////
var DundasTreeCB = {
    callBack  : function( result, context)
    {
        if ( result.indexOf("out:") == 0)
        {
            var node = context.node;
            var table = node.nodeContainer;
            var chunk = result.substring(4);            
            if ( chunk.length > 0 )
            {           
                var newDiv = document.createElement("div");
                newDiv.innerHTML = chunk;
                if ((typeof(table.nextSibling) == "undefined") || (table.nextSibling == null)) {
                    table.parentNode.insertBefore(newDiv.firstChild, table.nextSibling);
                }
                else {
                    table = table.nextSibling;
                    table.parentNode.insertBefore(newDiv.firstChild, table);
                }
                node.expandImage.src = context.data.expanded;
            }
            else
            {
                node.expandImage.src = context.data.leaf;
                node.expandImage.style.width = "16px";
            }
            node.nodeLink.innerHTML = context.text;
            node.expandImage.onclick = null;
            var control = context.data.controlElement;
	        control.style.cursor = "auto";
            var input = DundasTree.getInputByName( "ExpandedNodes", control);
            input.value = input.value + "{" + node.getPath() + "};";
        }
    },

    createContext: function ( e, data)
    {
		 e = DundasTree.fixEvent(e);
		 var element = e.target;
		 var node = new DundasTreeNode( element);
		 var result = new Object();
		 result.node = node;
		 result.data = data;
		 result.element = element;
		 result.text = node.nodeLink.innerHTML;
		 node.nodeLink.innerHTML = node.nodeLink.innerHTML + "( Loading... )";
		 if ( !data.controlElement )
		 {
            data.controlElement = document.getElementById( data.control);
         }
		 data.controlElement.style.cursor = "wait";
		 return result;
    },

    error : function( result, context)
    {
	     var node = context.node;
         node.nodeLink.innerHTML = context.text;	     
	     context.data.controlElement.style.cursor = "auto";
         dundas_ShowErrorMessage( result);
    }
}

/// ******************** DundasTreeCB ENDS HERE ******************** ////

/// ******************** DundasOlap STARTS HERE ******************** ////

var DundasOlap = {

showDialog : function (url, width, height, returnFunc, left, top, title)
{
	var data = "<iframe src=\""+url+"\" width=\""+width+"px\" scrolling=\"no\" frameborder=\"0\" height=\""+height+"px\" style=\"width:"+width+"px;height:"+height+"px;\" allowtransparency=\"true\"></iframe>"
	var popw = new Dundas_Dialog(title, data, true);
	popw.open();
	if ( left != null & top != null)
	{
		popw.setPosition(top, left);
	}
},

popupRenRep : function(sKey, mngid) {
	var url = _olapResourceURL + "renreport.aspx?"; 
	var frameHeight = 80;
	var frameWidth  = 400;
	DundasOlap.showDialog( url + "mng="+mngid+"&key="+sKey, frameWidth, frameHeight, null, null, null, "Rename Report");
},

popupFilter : function(axtype, sKey, mngid) {
	var url = _olapResourceURL + "filterdlg.aspx?"; 
	var frameHeight = 296;
	var frameWidth  = 410;
	if ( /*DundasLib.*/ DundasChart.geckoFlag )
	{
		frameHeight = 288;
	}
	DundasOlap.showDialog( url + "mng="+mngid+"&key="+sKey+"&axtype=" + axtype, frameWidth, frameHeight, null, null, null, "Sorting and Filtering");
},

setMembersDlgPos: function(elName, axtype, direction)
{
	var targetEl = document.getElementById(elName);
	var rect = /*DundasLib.*/ DundasChart.getElmPosition( targetEl, true );
	if ( targetEl )
	{
		var dialog = DundasChart.topDialog();
		var frameHeight = dialog.container.clientHeight;
		var frameWidth  = dialog.container.clientWidth;
		
		var top = null;
		var left = null;
		
		if (direction == "Auto")
		{
		    direction == "UpRight";
		    if ( axtype.indexOf("Categorical") > -1)
		    {
		        direction = "UpRight";
            }		    
		    else if( axtype.indexOf("Slicer") > -1)
		    {
		        direction = "DownRight";
            }
		    else if( axtype.indexOf("Series") > -1)
		    {
		        direction = "DownLeft";
            }
		}
		
		if ( direction == "UpRight")
		{
			top  = rect.y - frameHeight - 8;
			left = rect.x;
		}
		else if( direction == "DownRight")
		{
			top  = rect.y + rect.h + 4;
			left = rect.x;
		}
		else if (direction == "DownLeft")
		{
			top  = rect.y + rect.h + 4;
			left = rect.x + rect.w - frameWidth;
		}
        else if (direction == "UpLeft")
        {
			top  = rect.y - frameHeight - 8;
			left = rect.x + rect.w - frameWidth;
        }		
		if ( left < 0 || top < 0)
		{
			left = null;
			top  = null;
		}
		
		if ( left != null && top != null)
		{
			DundasChart.topDialog().setPosition(top, left);
		}
	}	
},

poupDescr : function ( axtype, id, elName, sKey, mngid) {
	var targetEl = document.getElementById(elName);
	var rect = /*DundasLib.*/ DundasChart.getElmPosition( targetEl, true );
	if ( targetEl )
	{
		var frameHeight = 314;
		var frameWidth  = 266;
		if ( /*DundasLib.*/ DundasChart.msieFlag )
		{
			frameHeight = 312;
			frameWidth  = 260;
		}
		var top = 0;
		var left = 0;
		if ( axtype.indexOf("Categorical") > -1)
		{
			top  = rect.y - frameHeight - 6 - 24;
			left = rect.x;
		}
		else if( axtype.indexOf("Slicer") > -1)
		{
			top  = rect.y + rect.h + 4;
			left = rect.x;
		}
		else
		{
			top  = rect.y + rect.h + 4;
			left = rect.x + rect.w - frameWidth;
		}
		if ( left < 0 || top < 0)
		{
			left = null;
			top  = null;
		}
		if ( axtype == "Slicer")
		{
			frameHeight -= 26;			
		}
		var url = _olapResourceURL + "dimbrdlg.aspx?"; 
		DundasOlap.showDialog( url + "key="+sKey+"&type="+axtype+"&dsid="+id+"&el="+elName+"&mngid=" + mngid, frameWidth, frameHeight, null, left, top, "Edit "+ axtype +" Axis Item")
	}
	return false;
},

popupDimBr : function ( axtype, id, sKey, mngid) {
	var frameHeight = 314 - 26;
	var frameWidth  = 266;
	var url = _olapResourceURL + "dimbrgdlg.aspx?"; 
	DundasOlap.showDialog( url + "key="+sKey+"&type="+axtype+"&dsid="+id+"&mngid=" + mngid, frameWidth, frameHeight, null, null, null, "Add Dimension to "+ axtype)
	return false;
}

}

/// ******************** DundasOlap ENDS HERE ******************** ////

function DundasDragInfo ( data, text)
{
	this.data = data;
	this.text = text;
}

//// ******************* DundasDrag Elemens START HERE *********** ////

function DundasDragClass ()
{
	
	this.dragSources = new Array(),
	this.dragTargets = new Array(),
	this.dragSource = null;
	this.dragActive = false;
	this.dragHack   = false;
	this.dragPoint  = null;
	this.dragSquare = 8;
	this.img_Accept = null;
	this.img_NotAccept = null;
	this.mapID = null;
	this.gridArea = null;	
}	

var DundasDrag = new DundasDragClass();

DundasDragClass.prototype.initDrag = function ( imgNA, imgAccept)
{
	DundasChart.attachEvent(document, "mousedown", DundasDrag.dragStart);
	DundasDrag.img_NotAccept = imgNA;
	DundasDrag.img_Accept = imgAccept;
	DundasDrag.img_drag = document.createElement("IMG");
	DundasDrag.img_drag.src = imgNA;
	DundasDrag.img_drag.style.position = "absolute";
	DundasDrag.img_drag.style.display = "none";
	DundasDrag.img_drag.appended = false;
	DundasDrag.cursor = this.createCursor();
}

DundasDragClass.prototype.createCursor = function ()
{
	var div = document.createElement("DIV");
	div.innerHTML = "<table cellpadding=\"2\" cellspacing=\"0\" class=\"ds_drag_item\" style=\"color:gray;position:absolute;\"><tr><td><img src=\""+ DundasDrag.img_NotAccept +"\" alt=\"\"/></td><td style=\"white-space:nowrap;\"><span/></td></tr></table>"
	var table = div.firstChild;

	table.appened = false;
	table.setImage = function ( imgSrc ) 
	{ 
		table.getElementsByTagName("IMG")[0].src = 	imgSrc; 
	};
	table.setText = function ( text ) 
	{ 
		table.getElementsByTagName("SPAN")[0].innerHTML = 	text;
	};

	table.setPos = function ( left, top )
	{ 
		this.style.top  = top + "px";this.style.left = left + "px";
	};
	table.setVisible = function ( visible ) {
		if ( !this.appened && visible)
		{
			document.body.appendChild(this);
			this.appened = true;
		}
		if ( this.appened && !visible)
		{
			document.body.removeChild(this);
			this.appened = false;
		}
	};
	
	table.setText("Test Text");
	table.setImage(DundasDrag.img_NotAccept);
	return table;
}

DundasDragClass.prototype.addSource = function ( elID, elClientID, elControllerID, onGetDragDataF )
{
	var obj = new Object();
	obj.postId = elID;
	obj.element = elClientID;
	obj.controller = elControllerID;
	obj.getDragData = onGetDragDataF;
	obj.dragData  = null;
	DundasDrag.dragSources[DundasDrag.dragSources.length] = obj;
	DundasDrag.markForDrop(elClientID);
}
	
DundasDragClass.prototype.addTarget = function ( elID, elClientID, elControllerID,  onCanAcceptF, onEndDragF )
{
	var obj = new Object();
	obj.postId = elID;
	obj.element = elClientID;
	obj.controller = elControllerID;
	obj.canAccept = onCanAcceptF;
	obj.endDrag = onEndDragF;
	DundasDrag.dragTargets[DundasDrag.dragTargets.length] = obj;
	DundasDrag.markForDrop(elClientID);
}

DundasDragClass.prototype.markForDrop = function ( elID, flag )
{
	var el = document.getElementById( elID);
	if ( el )
	{
		if ( flag )
		{
			el.setAttribute("dragndrop", flag);
		}
		else
		{
			el.setAttribute("dragndrop", "true");
		}		
	}		
}
	

DundasDragClass.prototype.showCursor = function (e, accept)
{
	var scroll = DundasChart.getScrollPos();
	DundasDrag.cursor.setPos((e.clientX + 8 + scroll.left), (e.clientY + 4 + scroll.top));
	DundasDrag.cursor.setImage(accept ? DundasDrag.img_Accept : DundasDrag.img_NotAccept);
	DundasDrag.cursor.setVisible( true);
}

DundasDragClass.prototype.hideCursor = function ()
{
	DundasDrag.cursor.setVisible( false);
}


DundasDragClass.prototype.showCursor_ = function (e, accept)
{
	if ( !DundasDrag.img_drag.appended )
	{
		document.body.appendChild(DundasDrag.img_drag);
		DundasDrag.img_drag.appended = true;
	}
	if ( DundasDrag.img_drag.style.display == "none")
	{
		DundasDrag.img_drag.style.display = "block";
	}
	var scroll = /*DundasLib.*/ DundasChart.getScrollPos();
	DundasDrag.img_drag.style.left  = (e.clientX + 8 + scroll.left) + "px";
	DundasDrag.img_drag.style.top   = (e.clientY + 12 + scroll.top) + "px";
	if ( accept )
	{
		DundasDrag.img_drag.src = DundasDrag.img_Accept;
	}
	else
	{
		DundasDrag.img_drag.src = DundasDrag.img_NotAccept;
	}
}

DundasDragClass.prototype.hideCursor_ = function ()
{
	DundasDrag.img_drag.style.display = "none";
}
	


DundasDragClass.prototype.locateEventSrc = function ( el )
{
	while ( el  )
	{
		if ( el.getAttribute  && el.getAttribute("dragndrop"))
		{
			var attrDragDrop = el.getAttribute("dragndrop");
			if ( attrDragDrop == "true" )
			{
				return el;
			}
			else
			{
				var retElement = document.getElementById(attrDragDrop);
				if ( retElement )
				{
					return retElement;
				}
			}
		}
		el = el.parentNode;
	}
	return null;
}

DundasDragClass.prototype.locateElement = function ( el, dragArr )
{
	if ( el.id )
	{
	    for( var i = 0; i < dragArr.length; i++)
	    {
		    if ( dragArr[i].element == el.id )
		    {
			    return dragArr[i];
		    }		
	    }
	}
	return null;
}


DundasDragClass.prototype.isDragMove = function( e )
{
	var dp1 = DundasDrag.dragPoint;
	var dp2 = {X:e.screenX, Y:e.screenY};
	var result = Math.abs(dp1.X - dp2.X) + "/" + Math.abs(dp1.Y - dp2.Y);
	return ( Math.abs(dp1.X - dp2.X) > DundasDrag.dragSquare || Math.abs(dp1.Y - dp2.Y) > DundasDrag.dragSquare )
},

DundasDragClass.prototype.dragStart = function ( event)
{
	
	/*DundasLib.*/ DundasChart.startUp();
	
	var e = /*DundasLib.*/ DundasChart.fixEvent(event);
	if ( e.button && e.button != 1)
	{
		return (false);
	}
	DundasDrag.dragPoint = {X:e.screenX, Y:e.screenY};
	var srcElm = DundasDrag.locateEventSrc( e.target);
	if ( srcElm )
	{
		var d = DundasDrag.locateElement( srcElm, DundasDrag.dragSources);
		if ( d )
		{
			d.dragData = d.getDragData( srcElm, e.target);
			if ( d.dragData != null )
			{
				DundasDrag.dragSource = d;
				DundasDrag.cursor.setText(d.dragData.text);
				document.body.style.cursor = "default";
				/*DundasLib.*/ DundasChart.attachEvent(document, "mousemove", DundasDrag.dragMove);
				/*DundasLib.*/ DundasChart.attachEvent(document, "mouseup", DundasDrag.dragDrop);
				DundasDrag.dragSquare = 8;
				if ( /*DundasLib.*/ DundasChart.dragHack )
				{
					DundasDrag.dragSquare = -1;
					DundasDrag.dragMove(event);
					/*DundasLib.*/ DundasChart.dragHack = false;
				}
			}
		}
		return false;
	}
}

DundasDragClass.prototype.dragFixMap = function ( e )
{
	e.targetX = e.target;
	DundasDrag.mapID = null;
	DundasDrag.gridArea = null;	
	var srcElm = DundasDrag.locateEventSrc( e.target);
	if ( /*DundasLib.*/ DundasChart.msieFlag && srcElm == null && e.target.tagName && e.target.tagName == "HTML")
	{
        // fcn ie...
        var posx = 0;
        for( posx = 0; posx < DundasDrag.dragTargets.length;	posx++)
        {
            var element = DundasDrag.dragTargets[posx];
            var domElement = document.getElementById(element.element);
            if ( domElement )
            {
                var position = /*DundasLib.*/ DundasChart.getElmPosition(domElement);
                if ( e.clientX > position.x && e.clientY > position.y &&
                     e.clientX < (position.x + position.w) && e.clientY < (position.y + position.h))
                {
                   srcElm = domElement; 
                   e.targetX = domElement;
                   break;       
                }
            }
        }
	}
	if ( !srcElm && e.target && e.target.tagName && e.target.tagName == "AREA")
	{
		var map = e.target.parentNode
		if ( map )
		{
			DundasDrag.mapID = e.target;
			var name = map.id != '' ? map.id :  map.getAttribute("name");
			e.targetX = document.getElementById(name.replace("ImageMap","").replace(":","_"));
			srcElm = DundasDrag.locateEventSrc( e.targetX);
		}
	}
	else
	{
	    if (srcElm && e.target)
	    {
	        var cssclass = e.target.className;
	        if ("" == cssclass) // image on cell
	        {
	            if (e.target.parentNode && e.target.parentNode.className != "")
	            {
	                cssclass = e.target.parentNode.className;
	            }
	            else
	            {
	                cssclass = null;
	            }
	            
	        }
	        if ("ida" != cssclass && "rda" != cssclass && "ch" != cssclass && "rh" != cssclass && "t" != cssclass && "g" != cssclass)
            {
	             cssclass = null;
	        }
	        DundasDrag.gridArea = cssclass;
	    }
	}
	return srcElm
}

DundasDragClass.prototype.dragMove = function( event)
{
	if ( DundasDrag.dragSource != null )
	{
		var e = /*DundasLib.*/ DundasChart.fixEvent(event)
		if ( !DundasDrag.dragActive )
		{
			if ( !DundasDrag.isDragMove( e ) )
			{
				return false;
			}
		}
		DundasDrag.dragActive = true;
		var accept = false;
		var srcElm = DundasDrag.dragFixMap( e);
		if ( srcElm )
		{
			var d = DundasDrag.locateElement( srcElm, DundasDrag.dragTargets);
			if ( d )
			{
				accept = d.canAccept(srcElm, e.targetX, e);			
			}
		}
		//ChartCB.debugOut( e.target.tagName + "/" + e.target.id + "/" + (srcElm ? srcElm.id : "null")) ;
		DundasDrag.showCursor( e, accept);
		return false;
	}
}
	
DundasDragClass.prototype.dragDrop = function( event)
{
	DundasDrag.hideCursor();
	/*DundasLib.*/ DundasChart.detachEvent(document, "mousemove", DundasDrag.dragMove);
	/*DundasLib.*/ DundasChart.detachEvent(document, "mouseup", DundasDrag.dragDrop);
	document.body.style.cursor = "";
	if ( DundasDrag.dragActive )
	{
		var e = /*DundasLib.*/ DundasChart.fixEvent(event)
		var srcElm = DundasDrag.dragFixMap( e);
		if ( srcElm )
		{
			var d = DundasDrag.locateElement( srcElm, DundasDrag.dragTargets);
			if ( d && d.canAccept(srcElm, e.targetX, e) )
			{		
				d.endDrag(srcElm, e.targetX, e);
			}
		}
	}
	DundasDrag.dragSource = null;
	DundasDrag.dragActive = false;
	return false;
}
	
DundasDragClass.prototype.DBStartDrag = function( tree, element)
{
	var input   = DundasTree.getInputByName("SelectedNode", tree);
	var selectedNode = DundasTree.getSelectedNode( input.value, tree);
	var slnNode = new DundasTreeNode( element);
	if ( !slnNode.isValid() )
	{
			return null;
	}
	var isImage = element.tagName && element.tagName.toUpperCase() == "IMG";
	if ( element == slnNode.nodeLink || (isImage && element != slnNode.expandImage && element != slnNode.checkBox) )
	{
		var result = slnNode.getValue();
		if ( result.indexOf("F:") == -1)
		{
		    return new DundasDragInfo("B:" + slnNode.getValue(), slnNode.getText());
		}
	}						
	return null;
}

DundasDragClass.prototype.DBCanAccept = function( container, element)
{
	if ( DundasDrag.dragSource && DundasDrag.dragSource.dragData )
	{
		var s = DundasDrag.dragSource.dragData.data;
		return s.indexOf("X:") > -1 && (s.indexOf(",true") == -1 || s.indexOf(",rem") > -1); //fix for Mo should be here
	}
	return false;
}

DundasDragClass.prototype.DBDrop = function( control, element)
{
	if ( DundasDrag.dragSource != null )
	{
		var s = DundasDrag.dragSource.dragData.data;
		var dst = DundasDrag.locateElement( control, DundasDrag.dragTargets)
		if ( dst != null )
		{
			if ( typeof(OlapCallBack) == "function" )
			{
                OlapCallBack( dst.controller, "["+dst.postId+"::AxisBuilder,OlapChart[!drop@" + s + "!]]");
			}
			else 
			{
			    __doPostBack(dst.postId, "drop@" + s);		
			}
		}
	
	}
}

DundasDragClass.prototype.GridCanAccept = function(container, element)
{
	if ( DundasDrag.dragSource && DundasDrag.dragSource.dragData && DundasDrag.gridArea != null)
	{	    
		var s = DundasDrag.dragSource.dragData.data;
		return s.indexOf("B:") > -1;
	}
	return false;
}

DundasDragClass.prototype.GridDrop = function( control, element)
{
	if ( DundasDrag.dragSource != null )
	{
		var attr = "";
		if (DundasDrag.gridArea)
		{
			attr = DundasDrag.gridArea;
		}
		var s = attr+"&"+DundasDrag.dragSource.dragData.data;
		var dst = DundasDrag.locateElement( control, DundasDrag.dragTargets)
		if ( dst != null )
		{
	        if ( typeof(OlapCallBack) == "function" )
	        {
                OlapCallBack( dst.controller, "["+dst.postId+"::AxisBuilder,OlapGrid[!drop&" + s + "!]]");
	        }
	        else 
	        {
	            __doPostBack(dst.postId, "drop&" + s);		
	        }
		}
		
	}
}

DundasDragClass.prototype.ChartCanAccept = function( container, element)
{
	var a = 1;
	if ( DundasDrag.dragSource && DundasDrag.dragSource.dragData )
	{
		var s = DundasDrag.dragSource.dragData.data;
		return s.indexOf("B:") > -1;
	}
	return false;
}

DundasDragClass.prototype.ChartDrop = function( control, element)
{
	if ( DundasDrag.dragSource != null )
	{
		var attr = "";
		if ( DundasDrag.mapID )
		{
			attr = DundasDrag.mapID.className;
			if (!attr)
			{
				attr = "";
			}
		}
		var s = DundasDrag.dragSource.dragData.data + attr;
		var dst = DundasDrag.locateElement( control, DundasDrag.dragTargets)
		if ( dst != null )
		{
	        if ( typeof(OlapCallBack) == "function" )
	        {
                OlapCallBack( dst.controller, "["+dst.postId+"::AxisBuilder,OlapChart[!drop@" + s + "!]]");
	        }
	        else 
	        {
	            __doPostBack(dst.postId, "drop@" + s);		
	        }
		}
		
	}
}

DundasDragClass.prototype.AXGetIdElement = function ( element, control )
{
		var el = element;
		while ( el.id.length == 0 )
		{
			el = el.parentNode;	
		}
		if ( el.id == control.id )
		{
			var el1 = element;
			while ( el1 && el1.id.length == 0 )
			{
				el1 = el1.firstChild;
				if ( el1 && el1.nodeType == 3 )
				{
					el1 = null;
				}	
			}
			if ( el1 && el1.id.length > 0 )
			{
				el = el1;
			}
		}
		return el;
},

DundasDragClass.prototype.AXGetTopElement = function ( controlID )
{
		var idx = 0;
		var result = null;
		var check = null;
		while (( check = document.getElementById(controlID +  "_C" + idx++)))
		{
			result = check;
		}
		return result;
}

DundasDragClass.prototype.AXBStartDrag = function (control, element)
{
	if ( control.getAttribute("axtype") != null)
	{
		if ( element.onclick != null)
		{
			return null;
		}
		var type = control.getAttribute("axtype")
		var el = DundasDrag.AXGetIdElement(element, control);
		var noID = el.id.replace( control.id, "");
		var isMeasure =  false;
		var allowRemoveMeasure = "";
		if ( el.getAttribute("measure"))
		{
			isMeasure = true;
			if ( el.getAttribute("rem"))
			{
			    allowRemoveMeasure = "rem";
			}
		}
		if ( noID != "" )
		{
			///*DundasLib.*/ DundasChart.dragHack = true;
			var index = parseInt(noID.replace("_P",""),10);
			if ( !isNaN(index) )
			{
			   var text = "";
			   var etds = el.getElementsByTagName("TD");
			   for( var i = 0; i < etds.length; i++)
			   {
				 if ( etds[i].title && etds[i].title.length > 0 )
				 {
					text = etds[i].title; break;
				 }
			   }
			   return new DundasDragInfo("X:" + type + "," + index + "," + isMeasure+","+allowRemoveMeasure, text);
			}
		}
	}
	return null;
}

DundasDragClass.prototype.AXBCanAccept = function (control, element, e)
{
	if ( DundasDrag.dragSource && DundasDrag.dragSource.dragData )
	{
		var s = DundasDrag.dragSource.dragData.data;
		var type = control.getAttribute("axtype");
		if ( type == "Slicer" )
		{
			if ( s.indexOf("X:") > -1 && s.indexOf(",true") > -1)
			{
				return false;
			}
			var mname = control.getAttribute("mesaure");
			var idx = s.indexOf(mname);
			if ( s.indexOf("B:") > -1 && (idx == 2 || idx == 3))
			{
				return false;
			}
		}
		var el = DundasDrag.AXGetIdElement(element, control);
		var name = el.id.replace( control.id, "");
		var borderName = "";
		if ( name.indexOf("_P") > -1)
		{
			var rect = el.rect ? el.rect : /*DundasLib.*/ DundasChart.getElmPosition( el, true);
			control.rect = rect;
			
			var idx = parseInt(name.replace("_P",""));
			var isvert = control.getAttribute("vertical") == "true";
			if ( !isvert )
			{
				if ( (e.clientX - rect.x) > (rect.w/2) )
				{
					idx ++;
				}
			}
			else
			{
				if ( (e.clientY - rect.y) > (rect.h/2) )
				{
					idx ++;
				}
			}
			borderName = control.id + "_C" + idx.toString();
		}
		else if ( name.indexOf("_C") > -1)
		{
			borderName = control.id + name;
		}
		else
		{
			var elm = DundasDrag.AXGetTopElement( control.id );
			if ( elm )
			{
				borderName = elm.id;
			}
		}
		if ( borderName != "")
		{
			var borderEl   = document.getElementById( borderName );
			if ( control.selectedDropArea )
			{
				var borderEl1 = control.selectedDropArea;
				if ( borderEl1.className != "xx_empty_message_xx" )
				{
				    borderEl1.style.backgroundColor = "";
				}
			}
			if ( borderEl )
			{
			    if  ( borderEl.className != "xx_empty_message_xx" )
			    {
				    borderEl.style.backgroundColor = "black";
				}
				control.selectedDropArea = borderEl;
			}
		}
		return s.indexOf("B:") > -1 || s.indexOf("X:") > -1 && control.selectedDropArea;
	}
	return false;
}

DundasDragClass.prototype.AXBDrop = function (control, element, e)
{
	if ( control.selectedDropArea )
	{
		var el = control.selectedDropArea;
		var s = DundasDrag.dragSource.dragData.data;
		var dragData = DundasDrag.AXBStartDrag( control, element);
		if ( dragData != s )
		{
			s += "!>>" + el.id.replace( control.id + "_C", "");
			var dst = DundasDrag.locateElement( control, DundasDrag.dragTargets)
			if ( dst != null )
			{
				var postID = dst.postId;
		        if ( typeof(OlapCallBack) == "function" )
		        {
                    OlapCallBack( dst.controller, "["+dst.postId+"::AxisBuilder,OlapChart[!drop@" + s + "!]]");
		        }
		        else 
		        {
		            __doPostBack(dst.postId, "drop@" + s);		
		        }
			}
		}
	}
}

DundasDragClass.prototype.AXMouseOut = function(event, element)
{
	var e = /*DundasLib.*/ DundasChart.fixEvent( event );
	//if (element.selectedDropArea && e.target == element)
	if (element.selectedDropArea)
	{
	    var borderEl = element.selectedDropArea;
		if  ( borderEl.className != "xx_empty_message_xx" )
		{
		    borderEl.style.backgroundColor = "";
        }
		element.selectedDropArea = null;
	}
}



//// ****************** DundasDrag Elemens END HERE ****************** ////

//// ****************** DundasTB  STARTS HERE ****************** ////

var DundasTB = {

activeMenu : null,
btnElement : null,

popMenu: function( elm, url, e, afterAbs)
{
	var e = e ? DundasChart.fixEvent( e) : null;
	DundasTB.closeMenu();
	//var fr = document.getElementById("ds_popframe");
	var fr = document.createElement("IFRAME");
	fr.frameBorder = "0";
	fr.scrolling = "no";
	fr.style.position = "absolute";
	fr.style.zIndex = 1000;
	fr.style.width = "0px";
	fr.style.height = "0px";
	if ( e )
	{
		var scroll = DundasChart.getScrollPos();
		fr.style.left = (e.clientX + scroll.left) + "px";
		fr.style.top  = (e.clientY + scroll.top) + "px";
	}
	else
	{
		var r = DundasChart.getElmPosition( elm, true);
		fr.style.left = r.x + "px";
		fr.style.top  = (r.y + r.h) + "px";
	}
	fr.style.display = "block";
	fr.src = url;
	DundasTB.btnElement = elm;
	DundasTB.tbOver( DundasChart.btnElement);
	document.body.appendChild( fr);
	DundasTB.activeMenu = fr;
	window.setTimeout("DundasTB.setCloseMenu()", 100)
	if (e)
	{
		e.returnValue = false;	
	}
	return false;
},

showMenu: function ( elm, menuID )
{
	DundasTB.closeMenu();
	var el = document.getElementById(menuID);
	el.style.display =  'block';
	var r = DundasChart.getElmPosition( el.parentNode);
	el.style.left = (r.x - 3) + "px";
	DundasTB.btnElement = elm;
	DundasTB.tbOver( DundasChart.btnElement);
	DundasTB.activeMenu = el;
	window.setTimeout("DundasTB.setCloseMenu()", 100)
},

menuHandlerAttached : false,

cancelCloseMenu : function ()
{
	if ( DundasTB.menuHandlerAttached )
	{
		DundasChart.detachEvent(document, "click", DundasTB.closeMenu);
		DundasTB.menuHandlerAttached = false;
	}
},

setCloseMenu : function ()

{
	if ( !DundasTB.menuHandlerAttached )
	{
		DundasChart.attachEvent(document, "click", DundasTB.closeMenu);
		DundasTB.menuHandlerAttached = true; 
	}
},

closeMenu : function ()
{
	DundasTB.cancelCloseMenu();
	if ( DundasTB.activeMenu != null )
	{
		DundasTB.activeMenu.style.display="none";
		DundasTB.activeMenu.style.width = 0;
		DundasTB.activeMenu.style.height = 0;
		document.body.removeChild( DundasTB.activeMenu);
		DundasTB.activeMenu = null;
		DundasTB.tbOut( DundasTB.btnElement);
		DundasTB.btnElement = null;
    }
},

tbOverMnu : function ( el )
{
	el.className = "ds_mtbover";
},

tbOutMnu: function ( el )
{
	el.className = "ds_tbbtn";
},

tbOver : function ( el )
{
	if ( DundasTB.activeMenu == null && el)
	{
		el.className = "ds_tbover";
	}
},

tbOut : function ( el )
{
	if ( DundasTB.activeMenu == null && el)
	{
		el.className = "ds_tbbtn";
	}
},

AXBackGetImageType : function ( modeImageUrl)
{
	var idx = modeImageUrl.indexOf("?t=");
	modeImageUrl = modeImageUrl.substring(idx + 3);
	modeImageUrl = modeImageUrl.substring(0, modeImageUrl.indexOf("_"));
	return modeImageUrl;
},

AXBackProcess : function ( control, hover)
{
	if ( control.rows )
	{
		var parentControlID = control.id.substring(0,control.id.lastIndexOf("_P"));
		var controlObj = eval( parentControlID + "_Images");
		if ( controlObj )
		{
			var cells = control.rows[0].cells;
			for( var i = 0; i < cells.length; i++)
			{
				var addModel = hover ? "_1" : "_0";
				var filter = null;
				try
				{
					filter = cells[i].filters('DXImageTransform.Microsoft.AlphaImageLoader')
				}
				catch (e) {}
				if ( cells[i].style.filter && filter)
				{
					var modeImageUrl = DundasTB.AXBackGetImageType(filter.src)+addModel;
					filter.src = controlObj[modeImageUrl];
				}				
				else
				{
					var modeImageUrl = DundasTB.AXBackGetImageType(cells[i].style.backgroundImage)+addModel;
					cells[i].style.backgroundImage = "url(" + controlObj[modeImageUrl] + ")";
				}
			}
		}
	}
},

AXBackHover : function (control)
{
	DundasTB.AXBackProcess(control, true);
},

AXBackOut : function (control)
{
	DundasTB.AXBackProcess(control, false);
}

}
//// ****************** DundasTB Elemens END HERE ****************** ////