//*****************************************************************************
// APOM.js ActivPortal Object Model
// 
// Fichier qui contient la definition de SQL Portal Services Component.
// 
//*****************************************************************************

	var fEditMode = false;
	var L_TASKLOCKMESSAGE_TEXT = "Cette tâche est actuellement lockée par l'utilisateur "
	var V_KEY_FORM = ''
	var V_VALUE_FORM = ''
	
	function WebPartDef(webPartID,webPartQualifier,HTMLObject,parentDash,HelpLink)
	{
		
		var _listDocument = new Collection();
		var _properties = new PropertiesCollection();
		var _parentDash = parentDash;
		
		this.HelpLink = HelpLink;
		this.WebPartID = webPartID;
		this.WebPartQualifier = webPartQualifier;
		this.HTMLObject = HTMLObject;
		
		this.properties = _properties;		
		this.setVisible = SetVisible;
		this.setCaption = SetCaption;
		this.getCaption = GetCaption;
		this.save = Save;
		this.Document = Document;
		this.AddDocument = AddDocument;
		this.RemoveDocument = RemoveDocument;
		this.FindDocument = FindDocument;
		this.ResizeHeightTo100Percent = ResizeHeightTo100Percent;
		
		
		function Save()
		{
			var strFrm;
			var strPropsValue
			var i;
			
			if( _parentDash == null )
				return false;

			if( typeof(_parentDash.frame.document.all.__FRM_WPsave) == "undefined"  )
			{
				strFrm = "<FORM id='__FRM_WPsave' action='" + _parentDash.urlStore + "' ><INPUT TYPE='TEXT' NAME='" + V_KEY_FORM + "' VALUE='" + V_VALUE_FORM + "' ><INPUT TYPE='TEXT' NAME='DashboardID' VALUE='' ><INPUT TYPE='TEXT' NAME='WebPartID' VALUE='' ><INPUT TYPE='TEXT' NAME='WebPartProps' VALUE=''></FORM>";
				_parentDash.frame.document.write(strFrm);
			}

			strPropsValue = '';
			for( i=0; i < _properties.Count; i++ )
			{
				var prop;

				prop = _properties.Item(i);
				strPropsValue = strPropsValue + '<' + prop.propertyName + '>' + prop.value + '</' + prop.propertyName + '>';
			}
			//window.clipboardData.setData("Text",strPropsValue);

			_parentDash.frame.document.all.__FRM_WPsave.DashboardID.value = _parentDash.DashboardID;
			_parentDash.frame.document.all.__FRM_WPsave.WebPartID.value = this.WebPartID;
			_parentDash.frame.document.all.__FRM_WPsave.WebPartProps.value = strPropsValue;

			_properties.Clear();

			_parentDash.frame.document.all.__FRM_WPsave.submit();
		}
		
		function SetVisible(fValue)
		{
			HTMLObject.style.display = (fValue)?'':'none';	
		}
		
		function SetCaption(sCaption)
		{
			getElByID('WebPartCaption' + HTMLObject.id).innerHTML = sCaption;
		}
		
		function GetCaption()
		{
			return getElByID('WebPartCaption' + HTMLObject.id).innerText;
		}
		
		function FindDocument(Index)
		{
			if (isNaN(Index))
			{
				var i;

				for( i=0; i<_listDocument.Count(); i++ )
				{
					
					if( _listDocument.Item(i).DocumentQualifier == Index )
						return i;
				}
				return -1;
			}
			else
			{
				if( Index < 0 || Index >= _listDocument.Count() )
					return -1;
				else
					return Index;
			}
		}

		function Document(Index)
		{
			var PartIndex;
			PartIndex = FindDocument(Index);
			if (PartIndex >= 0)
				return _listDocument.Item(PartIndex);
			else
				return null;
		}

		function AddDocument(DocumentID,DocumentQualifier,objectTemplate)
		{
			var PartIndex;
			var NewPart;
			
			
			
			PartIndex = FindDocument(DocumentQualifier);
			
			if (PartIndex >= 0)
				return _listDocument.Item(PartIndex);
			
			
			NewPart = new DocumentDef(DocumentID,DocumentQualifier,this,objectTemplate);
			
			
			_listDocument.Add(NewPart);
			this.Count = _listDocument.Count();
			
		
			return NewPart;
		}

		function RemoveDocument(Index)
		{
			_listDocument.Remove(FindWebPart(Index));
			this.Count = _listDocument.Count();
		}
		
		function ResizeHeightTo100Percent()
		{
				
				var oDBScreenAreaTop = 0;
				var oDBScreenAreaHeight = 0;
				
				if( document.getElementById("DBScreenArea")!= undefined )
				{
						oDBScreenAreaTop = GetAbsoluteTop(document.getElementById("DBScreenArea"));
						oDBScreenAreaHeight = document.getElementById("DBScreenArea").offsetHeight;
				}
				
				
				var iTop =  GetAbsoluteTop(HTMLObject);
				var iLayoutTop = GetAbsoluteTop(document.getElementById("LayoutTable"));
				var iLayoutHeight = document.getElementById("LayoutTable").offsetHeight;
				var oWPContainer = document.getElementById('WebPart' + this.WebPartQualifier);
				var iContainerTop =  GetAbsoluteTop(oWPContainer);
				//alert(this.WebPartQualifier + ' : ' + iTop + ' - ' + iContainerTop);
				
				var deltaHeight = (oDBScreenAreaTop + oDBScreenAreaHeight) - (iLayoutHeight + iLayoutTop) + (Number(document.body.bottomMargin)*2) + 3 ; 
				if ((document.body.clientHeight - iTop) - deltaHeight>0)
					HTMLObject.style.height = (document.body.clientHeight - iTop) - deltaHeight;
				else
					HTMLObject.style.height = 0;
				
				var deltaHeightContainer = iContainerTop - iTop; 
				if (HTMLObject.style.pixelHeight - deltaHeightContainer > 0)
					oWPContainer.style.height = HTMLObject.style.pixelHeight - deltaHeightContainer;
				else
					oWPContainer.style.height =  0;
				RaiseEvent('www.activportal.mc:Browser','onWPresized' + this.WebPartQualifier,null);
		}
		
	}
	
	function DocumentDef(documentID,documentQualifier,parentDocument,objectTemplate)
	{
		
		this.ParentWebpart = parentDocument;
		this.Template = objectTemplate;
		
		objectTemplate.Document = this;
		
		this.DocumentID = documentID;
		this.DocumentQualifier = documentQualifier;
		this.id = documentID;
		
		var _Loader = new DocumentLoader("GetDocument('" + documentQualifier + "').Loader", documentID, documentQualifier,'Content_' + documentQualifier);
		this.Loader = _Loader;
		
		
		
	}	

	function DashboardParamDef(Name,Value)
	{
		this.Name = Name;
		this.Value = Value;
	}

	
	function DashboardDef(DBID, HTMLObj,urlStore,sessionTimeout,sParamQuery)
	{

		var _listParam = new Collection();
		var _listWebPart = new Collection();
		var _properties = new PropertiesCollection();

		var _DashboardID = DBID;
		var _HTMLObject = HTMLObj;
		var _sessionTimeout = sessionTimeout;
		var _ParamQuery = sParamQuery;


		this.urlStore = urlStore;
		this.WebPart = WebPart;
		this.AddWebPart = AddWebPart;
		this.RemoveWebPart = RemoveWebPart;
		this.FindWebPart = FindWebPart;
		this.properties = _properties;
		this.sessionTimeout = _sessionTimeout;
		this.paramQuery = _ParamQuery;
		this.DashboardID = DBID;
		this.frame = null;
		this.init = init;
		this.ParameterCount = 0;
		
		this.Parameters = Parameters;
		this.AddParameter = AddParameter;
		this.GetParametersQueryString = GetParametersQueryString;
		
		
		function AddParameter(Name,Value)
		{
			var Index;
			var NewParameter;
			
			
			
			NewParameter = _listParam.FindByName(Name);
			
			if (NewParameter != null)
				return NewParameter
			
			
			NewParameter = new DashboardParamDef(Name,Value);
			
			
			_listParam.Add(NewParameter);
			this.ParameterCount = _listParam.Count();
		
			return NewParameter;			
		}
		
		function Parameters(Index)
		{
			if (isNaN(Index))
			{
				return _listParam.FindByName(Index);
			}
			else
			{
				return _listParam.Item(Index);
			}
		}
		
		function GetParametersQueryString()
		{
			/*var i=0;
			var strQuery = '';
			var oParameter;
			
			for(i=0;i<this.ParameterCount;i++)
			{
				oParameter = Parameters(i);
				if( strQuery != '') strQuery = strQuery + '&';
				strQuery = strQuery + 'DBParamName=' + oParameter.Name
				strQuery = strQuery + '&DBParamValue=' + oParameter.Value
			}
			return strQuery;*/
			return this.paramQuery;
		}				
		
		
		function FindWebPart(Index)
		{
			if (isNaN(Index))
			{
				var i;

				for( i=0; i<_listWebPart.Count(); i++ )
				{
					
					if( _listWebPart.Item(i).WebPartQualifier == Index )
						return i;
				}
				return -1;
			}
			else
			{
				if( Index < 0 || Index >= _listWebPart.Count() )
					return -1;
				else
					return Index;
			}
		}

		function WebPart(Index)
		{
			var PartIndex;
			PartIndex = FindWebPart(Index);
			if (PartIndex >= 0)
				return _listWebPart.Item(PartIndex);
			else
				return null;
		}

		function AddWebPart(WebPartID,WebPartQualifier, HTMLPart,HelpLink)
		{
			var PartIndex;
			var NewPart;
			
			
			
			PartIndex = FindWebPart(WebPartQualifier);
			
			if (PartIndex >= 0)
				return _listWebPart.Item(PartIndex);
			
			
			NewPart = new WebPartDef(WebPartID,WebPartQualifier,HTMLPart,this,HelpLink);
			
			
			_listWebPart.Add(NewPart);
			this.Count = _listWebPart.Count();
			
		
			return NewPart;
		}

		function RemoveWebPart(Index)
		{
			_WebPartList.Remove(FindWebPart(Index));
			this.Count = _WebPartList.Count();
		}


		function init()
		{
			document.write("<IFRAME ID='__ISave' src='blank.html' style='display:none;' ></IFRAME>"); //
			this.frame = document.getElementById("__ISave");
		}

	}
	
	/*-----------------------------*/
	/* CRITERIA DATA EVENT	 	   */
	/*-----------------------------*/		
	function CriteriaDataEvent(IdDocument,IdDatabase,IdDomain,IdObject,LabelObject,TypeObject,Operator,Value)
	{
		this.IdDocument = IdDocument;
		this.IdDatabase = IdDatabase;
		this.IdDomain = IdDomain;
		this.IdObject = IdObject;
		this.LabelObject = LabelObject;
		this.TypeObject = TypeObject;
		this.Operator = Operator;
		this.Value = Value;
		this.IndexCriteria = null;
	}
	
		/*--------------------------------*/
	/* VIEW MANAGER COLLECTION OBJECT */
	/*--------------------------------*/
	function DocumentManagerCollectionDef()
	{
		var _list = new Collection();
		
		this.Add = Add;
		this.Find = Find;
		this.Remove = Remove;
		this.FindById = FindById;
		this.FindByQualifier = FindByQualifier;
		
		
		function Add(oObject)
		{
			var VMIndex;
			
			if( oObject == null ) return null;
			
			VMIndex = Find(oObject.id);
			
			if (VMIndex >= 0)
				Remove(VMIndex)
			
			_list.Add(oObject);
			this.Count = _list.Count();
			
			return oObject;
		}		
	
		function FindByQualifier(DocumentQualifier)
		{
			var i;
			for( i=0; i<_list.Count(); i++ )
			{
				if( _list.Item(i).DocumentQualifier == DocumentQualifier )
					return _list.Item(i);
			}
			return null;			
		}
	
		function FindById(Id)
		{
			var i;
			for( i=0; i<_list.Count(); i++ )
			{
				if( _list.Item(i).id == Id )
					return _list.Item(i);
			}
			return null;
		}		

		function Find(Index)
		{
			if (isNaN(Index))
			{
				var i;
				for( i=0; i<_list.Count(); i++ )
				{
					if( _list.Item(i).id == Index )	
						return i;
				}
				return -1;
			}
			else
			{
				if( Index < 0 || Index >= _list.Count() )
					return -1;
				else
					return Index;
			}
		}

		function Remove(Index)
		{
			_list.Remove(Find(Index));
			this.Count = _list.Count();
		}
		
		function Clear()
		{
			var i;
			for(i=0;i<this.Count;i++)
				Remove(i);
			
		}	
	
	}	
			

	//**************MAIN******************
	
	var Dashboard = null;
	var DocumentManager = new DocumentManagerCollectionDef()
	
	
	window.onresize = function() { RaiseEvent('www.activportal.mc:Browser','onresize',window.event); };
	
	function InitDashboard(DBID, HTMLObj,urlStore,SessionTimeout,keyForm, valueForm,sParamQuery)
	{
		V_KEY_FORM = keyForm;
		V_VALUE_FORM = valueForm;
		
		Dashboard = new DashboardDef(DBID,HTMLObj,urlStore,SessionTimeout,sParamQuery);
		Dashboard.init();
		
		RegisterEvent('www.activportal.mc:Browser','onload',LoadParameters);
		RegisterAvailableInfos('www.activportal.mc:Dashboard','GetParameter',Dashboard.Parameters);
		window.onresize = DashboardResize;
	}
	
	function DashboardResize()
	{
		RaiseEvent('www.activportal.mc:Browser','onresize',window.event);
	}
	
	function LoadParameters()
	{
		var iCount = 0;
		
		if( Dashboard == null ) return;
		
		for(iCount=0;iCount<Dashboard.ParameterCount;iCount++)
			RaiseEvent('www.activportal.mc:Dashboard','SetParameter',Dashboard.Parameters(iCount));
	}
	
	
	function GetCurrentDashboard()
	{
		return Dashboard;	
	}
	
	function AddDashboardParameter(ParamName,ParamValue)
	{
		if( Dashboard == null ) return;
		Dashboard.AddParameter(unescape(ParamName),unescape(ParamValue));
	}
	
	function RegisterWebPart( strWebPartID, strWPQ, WebPartObject,IsFixedLayout,HelpLink  ) 
	{ 
	
		if( typeof(Dashboard) == "object" )
		{
			if(!IsFixedLayout)
			{
				var objWP = WebPartObject;
				var objBody = eval('WebPart' + strWPQ);
				
				var state = objBody.style.display
				objBody.style.display = '';
				var cxOffset = objWP.offsetWidth - objBody.offsetWidth;
				
				objBody.style.width = objBody.offsetWidth - cxOffset;
				objBody.style.display = state;
				objBody = null;
			}
			return Dashboard.AddWebPart(strWebPartID, strWPQ, WebPartObject,HelpLink);
		}
	}
	
	function RegisterDocument( strDocumentID, strDOCQ, objectTemplate ) 
	{ 
		return DocumentManager.Add(new DocumentDef(strDocumentID,strDOCQ,null,objectTemplate));
	}	
	
	function GetDocument(DocumentQualifier)
	{
		return DocumentManager.FindByQualifier(DocumentQualifier);
	}	
	
	function MinimizeRestoreWebPart(WPQualifier)
	{
	
		var varProp;
		
		var part = Dashboard.WebPart(WPQualifier)
		if( part != null )
		{
			var partElem = getElByID('WebPart' + WPQualifier);
	
			if (partElem.style.display == "none")
			{
				
				/*varProp = part.properties.Add("FrameState");
				varProp.value = "1";
				part.save();*/
				
				partElem.style.display = "";
		
				//alert(part.webPartID);
				//var obj = eval('TR' + part.webPartID);
				
				getElByID('_ImgState' + WPQualifier).src = "pictures/minus.gif";
				getElByID('_ImgState' + WPQualifier).title = MinimizeTip_Text;
				
				RaiseEvent('www.activportal.mc:Webpart','Maximize',part);
			}
			else
			{
				/*varProp = part.properties.Add("FrameState");
				varProp.value = "0";
				part.save();*/
		
				partElem.style.display = "none";
				getElByID('_ImgState' + WPQualifier).src = "pictures/plus.gif";
				getElByID('_ImgState' + WPQualifier).title = ExpandTip_Text;
				RaiseEvent('www.activportal.mc:Webpart','Minimize',part);
			}
	
		}	
		
	}
	
	
	function DisplayWebPart(WPQualifier,fVisible)
	{
		var APApplication = null;
		var wp = null;
		
		if( App != undefined ) {
			APApplication = App;	
		} else {
			if (parent.App)
			{
				APApplication = parent.App;
			}
		}
		
		if( APApplication != null ) {
			
			var wp = APApplication.webpartList[WPQualifier];
			if (wp==null) {
				var oDoc = APApplication.documentList[WPQualifier];
				if( oDoc != null ) {
					wp = oDoc.webPart;
				}
				
			}
		} else {		
			if (Dashboard==null) return;
		 	wp = Dashboard.WebPart(WPQualifier);
		}
		
		if( wp != null )
		{
			try
			{
				wp.setDisplay(fVisible);
			}
			catch(e)
			{ }
		}
		
			
	}
	
	
	function SetCaptionWebPart(WPQualifier,sCaption)
	{
		//if (typeof(Dashboard)==undefined || Dashboard==null) return;
		var APApplication = null;
		
		if( App != undefined ) {
			APApplication = App;	
		} else {
			if (parent.App)
			{
				APApplication = parent.App;
			}
		}
		
		if( APApplication != null ) {
			
			var oWP = APApplication.webpartList[WPQualifier];
			if (oWP==null) {
				var oDoc = APApplication.documentList[WPQualifier];
				if (oWP!=null) {
					oWP = oDoc.webPart;
				}
				
			}
			if (oWP!=null)
				oWP.elem_webpartHeader.getElement("span.title").innerText = sCaption;
			return;		
		}

		var wp = Dashboard.WebPart(WPQualifier)

		if( wp != null )
		{
			try
			{
				wp.setCaption(sCaption);
			}
			catch(e)
			{
			}
		}
	}	
	
	function GetCaptionWebPart(WPQualifier)
	{
		var wp = Dashboard.WebPart(WPQualifier)
		if( wp != null )
		{
			try
			{
				return wp.getCaption();
			}
			catch(e)
			{
			}
			return "";
		}		
	}
	
	function GetWebPart(WPQualifier)
	{
		return Dashboard.WebPart(WPQualifier)
	}
	
	function GetHelpWebPart(WPQualifier)
	{
		var wp = Dashboard.WebPart(WPQualifier)
		if( wp != null )
		{
			try
			{
				return wp.HelpLink;
			}
			catch(e)
			{
			}
			return "";
		}				
	}
	
//*******************************************************
//	fn_RefreshOpener
//*******************************************************
RegisterEvent('www.activportal.mc:Editor','SaveCompleted',fnRefreshDocument)
RegisterEvent('www.activportal.mc:Editor','UndoCheckout',fnRefreshDocument)
RegisterEvent('www.activportal.mc:Dashboard','Open',fnOpenDashboard)
RegisterEvent("www.activportal.mc:Document","OnDisplayDocument",OnDisplayDocument);
//RegisterEvent('www.activportal.mc:Dashboard','OpenPopup',fnOpenPopupDashboard)

function fnOpenDashboard(urlSuffix){
	OnDBView(urlSuffix);	
}

function OnDisplayDocument(URLSuffix)
{
	var sPath = document.location.href.substr(0, document.location.href.lastIndexOf("/") + 1 );
	fnWindowOpen(sPath + 'dcview.asp?DocumentID=' + URLEncode(URLSuffix),"DisplayDocument",570,700,true,true);
}


function fnRefreshDocument(DocInfo)
{
	/*if( DocumentQualifier != '' )
	{
		var oCriteriaManager = GetCriteriaManager(DocumentQualifier)
		if( oCriteriaManager )
		{
			oCriteriaManager.Reload();
			return;			
		}
	}*/
	if (fEditMode) fnRefresh();		
}



function OpenPrintDocument(DocumentID,DocumentQualifier)
{
	window.open('dcprint.asp?URLSUFFIX=' + URLEncode(DocumentID) + '&DocumentQualifier=' + DocumentQualifier,'Print','menubar=yes,width=800,height=400,scrollbars=yes,resizable=yes,toolbars=yes').focus();
}

function OpenPushDocument(DocumentID, DocQualifier)
{
	window.open("userPushList.asp?DocumentID=" + URLEncode(DocumentID) + "&DocQualifier=" + DocQualifier,'PushDefinition','width=800,height=400,scrollbars=yes,resizable=no,toolbars=no').focus();
}

function OpenSendMailDocument(DocumentID, DocQualifier)
{
	window.open("SendMail.asp?DocumentID=" + URLEncode(DocumentID) + "&DocQualifier=" + DocQualifier,'PushDefinition','width=800,height=400,scrollbars=yes,resizable=no,toolbars=no').focus();
}

function OpenGlobalFilter(IDDomain)
{
	window.open("GlobalFilter.asp?IdDomain=" + IDDomain ,'GlobalFilterDefinition','width=700,height=130,scrollbars=yes,resizable=no,toolbars=no').focus();
}

function OpenPrintWebpart(WebpartID, WebpartQualifier)
{

	if (document.getElementById('_FRMPRINTWP') == null || document.getElementById('_FRMPRINTWP')==undefined)
	{
		var strFrm = "<FORM id='_FRMPRINTWP' name='_FRMPRINTWP' Method='POST' target='_new' action='dcprint.asp?URLSUFFIX=" + URLEncode(WebpartID) + "&WebpartQualifier=" + WebpartQualifier + "'>"
		strFrm = strFrm + "</FORM>";
		var oForm = document.createElement(strFrm);
		
		var strInput = "<INPUT TYPE='TEXT' NAME='" + V_KEY_FORM + "' VALUE='" + V_VALUE_FORM + "' >";
		var oInput = document.createElement(strInput);
		oForm.appendChild(oInput);		
		
		strInput = "<INPUT TYPE='HIDDEN' ID='WPPrintDisplay' NAME='WPPrintDisplay' VALUE=''>";
		oInput = document.createElement(strInput);
		oForm.appendChild(oInput);
		document.body.appendChild(oForm);
	}
	document.getElementById('_FRMPRINTWP').action = "dcprint.asp?URLSUFFIX=" + URLEncode(WebpartID) + "&WebpartQualifier=" + WebpartQualifier;
	document.getElementById('WPPrintDisplay').value = GetDashboardConfig('',WebpartQualifier);
	document.getElementById('_FRMPRINTWP').submit();
	
//	window.open('dcprint.asp?URLSUFFIX=' + URLEncode(DashboardID),'Print','menubar=yes,width=800,height=400,scrollbars=yes,resizable=yes,toolbars=yes').focus();
}

function OpenPrintDashboard(DashboardID)
{

	if (document.getElementById('_FRMPRINT') == null || document.getElementById('_FRMPRINT')==undefined)
	{
		var strFrm = "<FORM id='_FRMPRINT' name='_FRMPRINT' Method='POST' target='_new' action='dcprint.asp?URLSUFFIX=" + URLEncode(DashboardID) + "'>"
		strFrm = strFrm + "</FORM>";
		var oForm = document.createElement(strFrm);
		
		var strInput = "<INPUT TYPE='TEXT' NAME='" + V_KEY_FORM + "' VALUE='" + V_VALUE_FORM + "' >";
		var oInput = document.createElement(strInput);
		oForm.appendChild(oInput);		
		
		strInput = "<INPUT TYPE='HIDDEN' ID='PrintDisplay' NAME='PrintDisplay' VALUE=''>";
		oInput = document.createElement(strInput);
		oForm.appendChild(oInput);
		document.body.appendChild(oForm);
	}
	document.getElementById('PrintDisplay').value = GetDashboardConfig(DashboardID);
	document.getElementById('_FRMPRINT').submit();
	
//	window.open('dcprint.asp?URLSUFFIX=' + URLEncode(DashboardID),'Print','menubar=yes,width=800,height=400,scrollbars=yes,resizable=yes,toolbars=yes').focus();
}

function OpenPushDashboard(DashboardID)
{
	var oWin;

	if (document.getElementById('_FRMPUSH') == null || document.getElementById('_FRMPUSH')==undefined)
	{
		var strFrm = "<FORM id='_FRMPUSH' name='_FRMPUSH' Method='POST' target='PushDefinition' action='userPushList.asp?DashboardID=" + URLEncode(DashboardID) + "'>"
		strFrm = strFrm + "</FORM>";
		var oForm = document.createElement(strFrm);
		
		var strInput = "<INPUT TYPE='TEXT' NAME='" + V_KEY_FORM + "' VALUE='" + V_VALUE_FORM + "' >";
		var oInput = document.createElement(strInput);
		oForm.appendChild(oInput);
		
		strInput = "<INPUT TYPE='HIDDEN' ID='PushDisplay' NAME='PushDisplay' VALUE=''>";
		oInput = document.createElement(strInput);
		oForm.appendChild(oInput);
		
		strInput = "<INPUT TYPE='HIDDEN' ID='MODEDASHBOARD' NAME='MODEDASHBOARD' VALUE='1'>";
		oInput = document.createElement(strInput);
		oForm.appendChild(oInput);
		document.body.appendChild(oForm);
	}
	document.getElementById('PushDisplay').value = GetDashboardConfig(DashboardID);
	oWin = window.open("blank.html",'PushDefinition','width=800,height=400,scrollbars=yes,resizable=no,toolbars=no');
	document.getElementById('_FRMPUSH').submit();
	oWin.focus();

//	window.open("userPushList.asp?DashboardID=" + URLEncode(DashboardID) ,'PushDefinition','width=800,height=400,scrollbars=yes,resizable=no,toolbars=no').focus();
}

function OpenSendMailDashboard(DashboardID)
{
	var oWin;

	if (document.getElementById('_FRMMAIL') == null || document.getElementById('_FRMMAIL')==undefined)
	{
		var strFrm = "<FORM id='_FRMMAIL' name='_FRMMAIL' Method='POST' target='PushDefinition' action='SendMail.asp?DashboardID=" + URLEncode(DashboardID) + "'>"
		strFrm = strFrm + "</FORM>";
		var oForm = document.createElement(strFrm);

		var strInput = "<INPUT TYPE='TEXT' NAME='" + V_KEY_FORM + "' VALUE='" + V_VALUE_FORM + "' >";
		var oInput = document.createElement(strInput);
		oForm.appendChild(oInput);

		
		strInput = "<INPUT TYPE='HIDDEN' ID='MailDisplay' NAME='MailDisplay' VALUE=''>";
		oInput = document.createElement(strInput);
		oForm.appendChild(oInput);
		
		strInput = "<INPUT TYPE='HIDDEN' ID='MODEDASHBOARD' NAME='MODEDASHBOARD' VALUE='1'>";
		oInput = document.createElement(strInput);
		oForm.appendChild(oInput);
		
		document.body.appendChild(oForm);
	}
	document.getElementById('MailDisplay').value = GetDashboardConfig(DashboardID);
	oWin = window.open("blank.html",'PushDefinition','width=800,height=400,scrollbars=yes,resizable=no,toolbars=no');
	document.getElementById('_FRMMAIL').submit();
	oWin.focus();

//	window.open("SendMail.asp?DashboardID=" + URLEncode(DashboardID) ,'PushDefinition','width=800,height=400,scrollbars=yes,resizable=no,toolbars=no').focus();
}

function GetDashboardConfig(DashboardID, WebpartQualifier)
{
	var nodeAttr;
	var newNode;
	var i;
	var oDashboard = GetCurrentDashboard();
	var nodeXML = new ActiveXObject("Msxml2.DOMDocument.3.0");
	nodeXML.loadXML("<PushConfig />");
	nodeXML = nodeXML.documentElement;
	if (!WebpartQualifier)
	{
		nodeAttr = nodeXML.ownerDocument.createNode("attribute", "URLSuffix","");
		nodeXML.setAttributeNode(nodeAttr);
		nodeAttr.text = DashboardID;
		nodeAttr = nodeXML.ownerDocument.createNode("attribute", "Type","");
		nodeXML.setAttributeNode(nodeAttr);
		nodeAttr.text = "Dashboard";
	}

	for (i=0 ; i<oDashboard.Count ; i++)
	{
		if ((oDashboard.WebPart(i).HTMLObject.style.display == '') && (!WebpartQualifier || WebpartQualifier == oDashboard.WebPart(i).WebPartQualifier))
		{
			newNode = nodeXML.ownerDocument.createNode("element", "WebPart", "");
			nodeXML.appendChild(newNode);
			nodeAttr = newNode.ownerDocument.createNode("attribute", "URLSuffix","");
			newNode.setAttributeNode(nodeAttr);
			nodeAttr.text = oDashboard.WebPart(i).WebPartID;
			nodeAttr = newNode.ownerDocument.createNode("attribute", "Qualifier","");
			newNode.setAttributeNode(nodeAttr);
			nodeAttr.text = oDashboard.WebPart(i).WebPartQualifier;

			var oTabStrip = GetTabStrip(oDashboard.WebPart(i).WebPartQualifier);
			if (oTabStrip != null)
			{
				var oDiv = getElByID(oTabStrip.currentTabSelected + "Div");	
				if( oDiv != null)
				{
					nodeAttr = newNode.ownerDocument.createNode("attribute", "Tab","");
					newNode.setAttributeNode(nodeAttr);
					nodeAttr.text = "1";

					var newNodeDoc = newNode.ownerDocument.createNode("element", "Document", "");
					newNode.appendChild(newNodeDoc);
					nodeAttr = newNodeDoc.ownerDocument.createNode("attribute", "URLSuffix","");
					newNodeDoc.setAttributeNode(nodeAttr);
					nodeAttr.text = oDiv.DocumentID;

					nodeAttr = newNodeDoc.ownerDocument.createNode("attribute", "Qualifier","");
					newNodeDoc.setAttributeNode(nodeAttr);
					nodeAttr.text = oDiv.DOCQualifier;
				}
			}

		}
	}
	return nodeXML.xml;
}

function GetWebQuery(sDocQualifier,sDocID)
{
	window.open('WebQueryOption.asp?DocumentQualifier=' + sDocQualifier + '&URLSuffix=' + URLEncode(sDocID),'WebQuery',"height=120,width=500,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no").focus();
}

function DeconnectUser()
{
	
}

function OpenConnectBy()
{
	var sLogin = false;
	sLogin = showModalDialog("searchHierarchyUser.asp",null,"font-family:Verdana; dialogWidth:500px; dialogHeight:510px; Scroll: no; help:No; resizable:No; status:No;");
	if (sLogin)	
	{
		if (sLogin == '-') 
		{
			var sUrl = location.href;
			switch(sUrl.lastIndexOf("?"))
			{
				case -1 : location.href = sUrl + '?LogOffBy=1';
									break;
				case (sUrl.length - 1) : location.href = sUrl + 'LogOffBy=1';
									break;				
				default : 
									if (sUrl.lastIndexOf("&") == sUrl.length - 1) location.href = sUrl + 'LogOffBy=1';
									else location.href = sUrl + '&LogOffBy=1';
			}
		}
		else location.href = location.href;
	}
}



function OnDBViewEditMode(url)
{
	document.location.href = 'dashboard.asp?editmode=1&dashboardID=' + url;
}

function OnDBView(url)
{
	document.location.href = 'dashboard.asp?DashboardID=' + url;
}

function OnDBPopupView(url, param)
{
	var sPage;
	
	if( param == undefined || param == null || param == '' ){
		param = 'scrollbars=yes,top=80,left=80,height=600,width=800,resizable=yes';
	}
	
	sPage='dashboard.asp?DashboardID=' + url;
	
	window.open(sPage,'',param);
}

function OnDBView2(url,model)
{
	document.location.href = "dashboard.asp?DashboardID=" + url + "&model=" + model;
}

function OnAddDB(ParentDashboardID)
{
	document.location.href = "CatalogProviderV2.asp?cmd=adddashboard&DashboardID=" + ParentDashboardID;
}

function OnEditContent(part,url)
{
	window.open('admincontent.asp?URL=' + URLEncode(url),null,'resizable=yes,toolbar=no,menubar=no,location=no');
}

function OpenWebPart(urlWP,width,height)
{
	var sSize = '';
	if( width != null && width != '' ) sSize = 'width=' + width.replace("px","") + ',';
	if( height != null && height != '' ) sSize = sSize + 'height=' + height.replace("px","");

	window.open('webpart.asp?WebpartID=' + urlWP + '&' + GetCurrentDashboard().GetParametersQueryString(),null,'resizable=yes,toolbar=no,menubar=no,location=no,' + sSize);

}

	

