// Object Type Codes
var None = 0;
var Account = 1;
var ActivityMimeAttachment = 1001;
var ActivityParty = 135;
var Annotation = 5;
var AnnualFiscalCalendar = 2000;
var BusinessUnit = 10;
var BusinessUnitNewsArticle = 132;
var Competitor = 123;
var Contact = 2;
var Contract = 1010;
var ContractDetail = 1011;
var ContractTemplate = 2011;
var CustomerAddress = 1071;
var DisplayString = 4102;
var CustomerOpportunityRole = 4503;
var Discount = 1013;
var DiscountType = 1080;
var DocumentIndex = 126;
var FixedMonthlyFiscalCalendar = 2004;
var Incident = 112;
var Invoice = 1090;
var InvoiceDetail = 1091;
var KbArticle = 127;
var KbArticleComment = 1082;
var KbArticleTemplate = 1016;
var Lead = 4;
var MonthlyFiscalCalendar = 2003;
var Opportunity = 3;
var OpportunityProduct = 1083;
var Organization = 1019;
var PriceLevel = 1022;
var Privilege = 1023;
var Product = 1024;
var ProductPriceLevel = 1026;
var QuarterlyFiscalCalendar = 2002;
var Queue = 2020;
var QueueItem = 2029;
var Quote = 1084;
var QuoteDetail = 1085;
var Equipment = 4000;
var ResourceSpec = 4006;
var ResourceGroup = 4007;
var Calendar = 4003;
var CalendarRule = 4004;
var Site = 4009;
// Custom Dialogs
var ServiceRestrictionCalendarRule = 5003;
var TimeOffCalendarRule = 5004;
var HolidayCalendarRule = 5005;
var OccurrenceCalendarRule = 5006;
var RecurrenceCalendarRule = 5007;
var OccurringWorkShift = 5008;
var RecurringWorkShift = 5009;
var NotWorkingWorkShift = 5010;
var ActivityScheduling = 5011;
// Done with Custom Dialogs
var Role = 1036;
var SalesLiterature = 1038;
var SalesLiteratureItem = 1070;
var SalesOrder = 1088;
var SalesOrderDetail = 1089;
var SavedQuery = 1039;
var UserQuery = 4230;
var SemiAnnualFiscalCalendar = 2001;
var Service = 4001;
var Subject = 129;
var SystemUser = 8;
var Team = 9;
var Template = 2010;
var Territory = 2013;
var UnresolvedAddress = 2012;
var UoM = 1055;
var UoMSchedule = 1056;
var UserFiscalCalendar = 1086;
var UserSettings = 150;
var WFProcess = 121;
var WFProcessInstance = 122;
var List = 4300;
var ListMember = 4301;
var Campaign	= 4400;
var CampaignResponse = 4401;
var CampaignActivity = 4402;
var BulkOperation = 4406;
var BulkOperationLog = 4405;
var BulkImport = 4407;
var CustomerRelationship = 4502;
var RelationshipRole	 = 4500;
var RelationshipRoleMap	 = 4501;
var ActivityPointer = 4200;
var Appointment = 4201;
var ServiceAppointment = 4214;
var Task = 4212;
var PhoneCall = 4210;
var Letter = 4207;
var Email = 4202;
var Fax = 4204;
var IncidentResolution = 4206;
var QuoteClose = 4211;
var OpportunityClose = 4208;
var OrderClose = 4209;
var AttributeMap = 4601;
var Report	= 9100;
var AppLicense = 9002;
var AppSalesPerson = 9003;
var AppOfflineFilter = 9004;
var AccountAddress = 1000;
var ContactAddress = 1008;
var Import = 4410;
var TransactionCurrency = 9105;
var MailMergeTemplate = 9106;
var ReportPropertyDialog = 9099;
var Workflow = 4703;
var AsyncOperation = 4700;
var AppWorkflowInstance = 9005;
var ScriptErrorDialog = 9200;
var ScriptErrorDetailsDialog = 9201;
var DuplicateRule = 4414;
var ImportMap = 4411;
var BulkDeleteOperation = 4424;
var BaseAddEntityObjectTypeCode	= 10000;

function buildWinName(s)
{
	if (s) return s.toLowerCase().replace(/[-\{\}:]/g, "");
	var d = new Date();
	return d.getTime();
}

function getAdjustedHeightForScreen(iY)
{
	if (IsNull(iY) || iY == 0)
	{
		return (screen.availHeight >= 600) ? 560 : 510;
	}
	else
	{
		return (iY >= screen.availHeight) ? screen.availHeight : iY;		
	}
}

function getAdjustedWidthForScreen(iX)
{
	var iWidth = iX;
	if (IsNull(iX) || iX == 0)
	{
		iX = (screen.availWidth >= 1000) ? 820 : 750;
	}
	iX = (iX >= screen.availWidth) ? screen.availWidth : iX;
	_bWindowSizeAdjusted = (iX != iWidth);
	return iX;
}

function IsNull(o)
{
	return ("undefined" == typeof(o) || "unknown" == typeof(o) || null == o)
}

function getLeftMargin(iX)
{	
	var iLeft = 0;
	if ((screen.availWidth - iX) > 0)
	{
		iLeft = (screen.availWidth - iX)/2
	}	
	return iLeft;
}

function getTopMargin(iY)
{	
	var iTop = 0;
	if ((screen.availHeight - iY) > 0)
	{
		iTop = (screen.availHeight - iY)/2
	}	
	return iTop;
}

// Auto Grid Refresher 
function auto(iObjectTypeCode)
{ 
	RefreshGrid();
}

function IsActivityTypeCode(iObjTypeCode)
{
	switch (parseInt(iObjTypeCode,10))
	{
		case ActivityPointer:
		case Email:
		case Fax:
		case PhoneCall:
		case Letter:
		case Appointment:
		case ServiceAppointment:
		case Task:
		case CampaignResponse:
		case CampaignActivity:
		case IncidentResolution:
		case OpportunityClose:
		case OrderClose:
		case QuoteClose:
			return true;
		default: return false;
	}
}

/// <summary>
/// Finds and refreshes AppGrid v2.0 Grids with the provided Object Type Code
/// </summary>
function findAndRefreshGrids(oTables, iObjectTypeCode, bIsActivity)
{ 
	var o;
	for (var i = 0; i < oTables.length; i++)
	{
		o = oTables[i];
		if (o.className.indexOf("gridControl") > -1 && o.GetParameter("autorefresh") == "1" && 
				(o.GetParameter("otc") == iObjectTypeCode || 
				(bIsActivity && (o.GetParameter("otc") == ActivityPointer || iObjectTypeCode == ActivityPointer)) || o.GetParameter("otc") == 0))
		{
			o.ClearPagingCookie();
			o.Refresh();
		}
	}
}

function openObj(sUrl, iType, sId, sParams, sUrlPrefix)
{	
	sUrl = sUrl + "/";
	var sId2 = "";
											
	if (sId)
	{
		sId2 = "?id=" + sId;
	}
	if (("undefined" == typeof(sParams) || "unknown" == typeof(sParams) || null == sParams))
	{
		sUrl += (sUrl.length == 0) ? "?" : "&";
		// Remove leading question mark from sParams if there is one.
		if ((sParams.charAt(0) == "?"))
		{
			sParams = sParams.substr(1, sParams.length - 1);
		}
				
		sUrl += sParams;
	}
	
	openFrmObj(sUrl, sId2, buildWinName(sId), iType, sUrlPrefix);
}			

function openFrmObj(sUrl, sId, sName, iType, sUrlPrefix)
{			
			
	// There are a certain number of objects that do not have forms, we should list these here
									
	// Get the window URL and sizes for this object type.GetWindowInformation is an auto generated function pulled from WindowInformation.aspx.cs
	// When you create a new entity or need to adjust an entity window size, please update the resource in WindowSizes.resx for the entity
	// window url that needs changing.
	var oWindowInfo = GetWindowInformation(iType, sId);
	var url = oWindowInfo.Url;
	var iX	= oWindowInfo.Width;
	var iY	= oWindowInfo.Height;								
	

	// Check to see if anything special needs to happen for this object type
	if (("undefined" == typeof(url) || "unknown" == typeof(url) || null == url))
	{
		url = "/" + url + sUrl;									

		if (("undefined" == typeof(sUrlPrefix) || "unknown" == typeof(sUrlPrefix) || null == sUrlPrefix))
		{
			url = sUrlPrefix + url;
		}	

		url = sUrl + url;														
	}								
	
	url = sUrl + url + sId;
	
	// Handle Custom Entities
	if (IsUserDefinedEntityObjectTypeCode(iType))
	{
		// If there is no ID, this is a "New" form otherwise its an "Update"
		url += (sId == "") ? "?" : "&";
		url += "etc=" + iType;
	}

	openStdWin( url, sName, iX, iY);
}

function openHelpWin(sUrl)
{
    var sName = "ListWebPartforMicrosoftCRM4HelpLink";
    var customFeatures = "toolbar=yes,location=yes,directories=yes,menubar=yes,scrollbars=yes,copyhistory=yes";
    openStdWin(sUrl,sName,800,600,customFeatures);
}

function openStdWin(sPath, sName, iX, iY, sCustomWinFeatures)
{
	iX = getAdjustedWidthForScreen(iX);
	iY = getAdjustedHeightForScreen(iY);
	
	// Get the left and top margin.
	var iLeft = getLeftMargin(iX);
	var iTop = getTopMargin(iY);									
	
	try
	{
		return window.open(sPath, sName, "width=" + iX + ",height=" + iY + ",status=1,resizable=1,left=" + iLeft + ",top=" + iTop + (IsNull(sCustomWinFeatures) ? "" : "," + sCustomWinFeatures));
	}
	catch(e) {}
}

function openStdDlg(sPath, oArgs, iWidth, iHeight, bResizable, bModeless, sCustomWinParams)
{
	if (IsNull(sCustomWinParams))
	{
		sCustomWinParams = "";
	}
	
	// Take into consideration any global increases in dialog size.Used by localization teams.
	// Only use these increased sizes if the dialog is already resizeable.If it is not resizeable then the increased sizes will 
	// most likely not help much because the dialog probably has a fixed layout.
	if ((!IsNull(bResizable) && bResizable))
	{
		iWidth	+= parseInt(LOCID_DIALOG_OFFSET_WIDTH, 10);
		iHeight += parseInt(LOCID_DIALOG_OFFSET_HEIGHT, 10);
	}
	
	// Adjust height for screen size.
	iWidth	= getAdjustedWidthForScreen(iWidth);
	iHeight	= getAdjustedHeightForScreen(iHeight);
	bResizable = (!IsNull(bResizable) && bResizable) ? "yes" : "no";
	
	// Get the left and top margin.
	var iLeft = getLeftMargin(iWidth);
	var iTop = getTopMargin(iHeight);
	
	sCustomWinParams = "dialogWidth:" + iWidth + "px;dialogHeight:" + iHeight + "px;dialogLeft=" + iLeft + "px;dialogTop=" + iTop + "px;help:0;status:0;scroll:0;center:1;resizable:" + bResizable + ";" + sCustomWinParams;
	
	if (IsNull(bModeless) || !bModeless)
	{
		return window.showModalDialog(sPath, oArgs, sCustomWinParams);
	}
	else
	{
		return window.showModelessDialog(sPath, oArgs, sCustomWinParams);
	}
}

function doDelete(sUrl, sGrid, iObjType, sObjId)
{
	var a;
	var sCustParams = "";
	var arySubType;
	var iLen;
	var sIds		= "";	
	
	var sAction = "delete";
	
	a = new Array(sObjId);

	sIds = a[0];
	
	var iX = 400;
	var iY = 200;
			
	// Accounts and contacts are special cases for delete operations
	var oResult;
	switch( parseInt(iObjType, 10) )
	{											
		case Account:
			oResult = openStdDlg(sUrl + "/_grid/cmds/dlg_delete_account.aspx?iObjType=" + iObjType + "&iTotal=" + a.length + "&sIds=" + sIds + sCustParams, a, 450, 250 );
			break;
		case Contact:
			oResult = openStdDlg(sUrl + "/_grid/cmds/dlg_delete_contact.aspx?iObjType=" + iObjType + "&iTotal=" + a.length + "&sIds=" + sIds + sCustParams, a, 450, 250 );
			break;
		default:				
		oResult = openStdDlg(sUrl + "/_grid/cmds/dlg_" + sAction + ".aspx?iObjType=" + iObjType + "&iTotal=" + a.length + "&sIds=" + sIds + sCustParams, a, 450, 205 );
		break;
	}
	
	if ( oResult)
	{
		auto();
	}
}

function RefreshGrid()
{
	document.forms[MSOWebPartPageFormName].submit();
}	

function rollOverDisplayGlowForToolBar(o, sUrl) 
{
	with (o.runtimeStyle)
	{
		backgroundImage = "url(" + sUrl + "/_imgs/toolbar_hover.gif)";
	}
	
}


function rollOutRemoveGlowForToolBar(o, sUrl) 
{
	with (o.runtimeStyle)
	{	
		backgroundImage = "url(" + sUrl + "/_imgs/gridtoolbar_back.gif)";
	}
	
}
function rollOverDisplayGlowForHeader(o, sUrl) 
{ 	

	with (o.runtimeStyle)
	{
		backgroundImage = "url(" + sUrl + "/_imgs/grid/grid_barbkon.gif)";
	}
	
}
function rollOutRemoveGlowForHeader(o, sUrl) 
{ 
	with (o.runtimeStyle)
	{	
		backgroundImage = "";
		backgroundcolor = "#f0f0f0";
	}
	
}
function IsUserDefinedEntityObjectTypeCode(iOTC)
{
	return iOTC >= BaseAddEntityObjectTypeCode;
}

function CRMGRID_RenderToolTip()
{
	var o = event.srcElement;

	if (o && o.tagName == "NOBR" && o.title == "" && o.innerText != "")
	{
		o.title = o.innerText;
	}
}

function CRMGRID_HandleSingleClick(sUrl, iOtc)
{
	var oTr = event.srcElement;

	oTr = CRMGRID_FindTargetRow(oTr);

	if (typeof(oTr) == "undefined" || oTr == null) return; 	// ignore the dragged cursor command

	oTr.cells[0].firstChild.click();
}

function CRMGRID_HandleDblClick(sUrl, iOtc)
{
	var oTr = event.srcElement;

	oTr = CRMGRID_FindTargetRow(oTr);

	if (typeof(oTr) == "undefined" || oTr == null) return; 	// ignore the dragged cursor command

	if (oTr.otype)
	{
		iOtc = oTr.otype;
	}
	
	openObj(sUrl, iOtc, oTr.oid, "", "");
}

function CRMGRID_FindTargetRow(oElement)
{
	while ((typeof(oElement) != "undefined" && oElement != null) && (oElement.tagName != "TR" || !oElement.oid))
	{
		oElement = oElement.parentElement;
	}

	return oElement;
}

function CRMGRID_Resizer(oTable)
{
	try
	{
		var oRow1 = oTable.rows[0];
		var oRow2 = oTable.rows[1];
		var bTooNarrow = false;
		bTooNarrow = bTooNarrow || oRow1.cells[0].firstChild.rows[0].cells[1].firstChild.clientWidth < 75;
		bTooNarrow = bTooNarrow || oRow1.cells[2].firstChild.clientWidth < 75;
		bTooNarrow = bTooNarrow || oRow1.cells[4].firstChild.clientWidth < 75;
		bTooNarrow = bTooNarrow || oRow1.cells[6].firstChild.clientWidth < 75;
			
		if (bTooNarrow)
		{
			if (oRow2.style.display == "none")
			{
				//Expand to two rows.
				oRow2.style.display = "block";
				oRow2.appendChild(oTable.all.tdTypeSelectorLabel);
				oRow2.appendChild(oTable.all.tdTypeSelector);
				oRow2.appendChild(oTable.all.tdViewSelectorLabel);
				oRow2.appendChild(oTable.all.tdViewSelector);
				//Fix column widths.
				oTable.firstChild.children[0].style.width = oRow1.cells[0].firstChild.rows[0].cells[0].clientWidth;
				oTable.firstChild.children[1].style.width = "55%";
				oTable.firstChild.children[2].style.width = "";
				oTable.firstChild.children[3].style.width = "80%";
				oTable.firstChild.children[4].style.width = "";
				oTable.firstChild.children[5].style.width = "";
				oTable.firstChild.children[6].style.width = "";
				oTable.firstChild.children[7].style.width = "";
			}
		}
	}
	catch(e)
	{
		// Ignore
	}
}

function CRMGRID_AccessibilityClick()
{
	if (event.keyCode == 13)
	{
		event.srcElement.click();
		event.cancelBubble = true;
		event.returnValue = false;
		return false;
	}
}

function HandleTextBoxEnterKey(btnId)
{
    if(event.keyCode == 13)
	{
	    if(IsNull(btnId))
	    {
	        //Make the default behaviour as Tab Key
	        event.keyCode=9;
	    }
	    else
	    {
	        //Click the button event
	        document.getElementById(btnId).click();
	    }
    }
}

function Resize(sGridBarColId, sGridDataColId, bIsRtl)
{
	var currentDragColIndex = event.srcElement.parentElement.previousSibling.cellIndex;
	
	var _currentDragCol = window.document.getElementById(sGridBarColId).children[currentDragColIndex];
	var iDelta = event.offsetX;

	if(bIsRtl == "true")
	{
		iDelta = -iDelta;
	}
	if (iDelta > 5 || iDelta < -5 && // If the delta is greater than 5 (for perf)
		(_currentDragCol.offsetWidth + iDelta) >= 1) // If the new width is valid
	{
		var i = _currentDragCol.offsetWidth + iDelta;
		_currentDragCol.width = i;
		
		var currentDragDataColParent = window.document.getElementById(sGridDataColId);
		if(currentDragDataColParent != null)
		{
			var currentDragDataCol = currentDragDataColParent.children[currentDragColIndex];
			currentDragDataCol.width = i;
		}
		
	}
}

function handleFindKeystroke(sWebPartId, sViewDropDownClientId, sEmptyMsg, iNumOfRecords)
{
	var KEY_DOWN = 40;
	var KEY_ENTER = 13;
	var KEY_TAB = 9;
	var KEY_ALT = 18;
	if (event.keyCode == KEY_ENTER)
	{
		RunQuickFind(sWebPartId, sViewDropDownClientId, sEmptyMsg);
	}
	else if ((event.keyCode == KEY_DOWN) && (iNumOfRecords > 0))
	{
		window.document.getElementById(sWebPartId + "_gridDataTable").focus();
	}
	else if (event.keyCode != KEY_TAB && event.keyCode != KEY_ALT)
	{
		showRunFindButton(sWebPartId);
	}
}
function ClearQuickFind(sWebPartId, sViewId, sViewDropDownClientId)
{
	NotifyExitedQuickFind(sWebPartId);
	window.document.getElementById(sWebPartId + "crmdb_isSearch").value = "False";
	window.document.getElementById(sWebPartId + "crmdb_searchString").value = "";
	window.document.getElementById(sWebPartId + "crm_pagingCookie").value = "";
	window.document.getElementById(sWebPartId + "crm_pageNumber").value = "1";
		
	window.document.getElementById(sViewDropDownClientId).value = sViewId;
	document.forms[MSOWebPartPageFormName].submit();
}
function NotifyExitedQuickFind(sWebPartId)
{
	showRunFindButton(sWebPartId);
	window.document.getElementById(sWebPartId + "_findCriteria").value = "";
}

function showRunFindButton(sWebPartId)
{
	var runButton = window.document.getElementById(sWebPartId + "_findCriteriaButton");
	var clearButton = window.document.getElementById(sWebPartId + "_clearCriteriaButton");
	runButton.style.display = "inline";
	clearButton.style.display = "none";
}
function showCancelFindButton(sWebPartId)
{
	var runButton = window.document.getElementById(sWebPartId + "_findCriteriaButton");
	var clearButton = window.document.getElementById(sWebPartId + "_clearCriteriaButton");
	clearButton.style.display = "inline";
	runButton.style.display = "none";
}
function RunQuickFind(sWebPartId, sViewDropDownClientId, sEmptyMsg)
{
	var sFindCriteria = window.document.getElementById(sWebPartId + "_findCriteria").value;
	sFindCriteria = sFindCriteria.replace(/[\*]+/, "*")
	sFindCriteria = Trim(sFindCriteria);
	
	//Remove leading and trailing IDEOGRAPHIC SPACE (unicode 0x3000) introduced by Fullwidth unicode input methods like Japanese Hiragana, Chinese Fullwidth etc..
	sFindCriteria = sFindCriteria.replace(/^\u3000+|\u3000+$/g, "");
	if (sFindCriteria == "")
	{
		// This message comes to this method as an argument. The string is rendered by server in HTML area in HTMLEncoded form.
		// We need to decode it before displaying.
		alert(CrmEncodeDecode.CrmHtmlDecode(sEmptyMsg));
		return false;
	}
	window.document.getElementById(sWebPartId + "crmdb_isSearch").value = "True";
	window.document.getElementById(sWebPartId + "crmdb_searchString").value = sFindCriteria;
	window.document.getElementById(sWebPartId + "crmdb_previousViewToSearch").value = window.document.getElementById(sViewDropDownClientId).value;
	window.document.getElementById(sWebPartId + "crm_pagingCookie").value = "";
	window.document.getElementById(sWebPartId + "crm_pageNumber").value = "1";

	
	showCancelFindButton(sWebPartId);
	document.forms[MSOWebPartPageFormName].submit();
}
function findTxtOnFocus(sWebPartId)
{
	var label = window.document.getElementById(sWebPartId + "_findHintText");
	label.style.display = "none";
	
}
function findTxtOnFocusOut(sWebPartId, isSearch)
{
    var findCriteriaText = window.document.getElementById(sWebPartId + "_findCriteria").value;
	if(isSearch == "false" && findCriteriaText=="")
	{
		var label = window.document.getElementById(sWebPartId + "_findHintText");
		label.style.display = "inline";
	}
}
function Trim(s)
{
	//These are handled by normal trim: { 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x0020 }
	s = s.replace(/^\s+|\s+$/g, '');

	//Now trim the rest.
	var chars = String.fromCharCode(0x0085, 0x00A0, 0x2028, 0x2029, 0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000);
	for (var i = 0; i < chars.length; i++)
	{
		var iChar = chars.charCodeAt(i);
		var sChar = "";
		if (iChar < 0x100)
		{
			sChar += "00";
		}
		else if (iChar < 0x1000)
		{
			sChar += "0";
		}
		
		sChar += iChar.toString(16);

		s = s.replace(new RegExp("^\\u" + sChar + "+|\\u" + sChar + "+$", "g"), '');
	}
	
	return s;
}
function CRMWindowInfo(sUrl, iXOffset, iYOffset)
{
	this.Width	= parseInt(iXOffset, 10);
	this.Height	= parseInt(iYOffset, 10);
	this.Url	= sUrl;
}
function GetWindowInformation(iObjectType, sId) 
{
	switch (parseInt(iObjectType, 10)) 
	{
		case Account: return new CRMWindowInfo("sfa/accts/edit.aspx",1000,560);
		case List: return new CRMWindowInfo("ma/lists/edit.aspx",820,560);
		case Import: return new CRMWindowInfo("import/edit.aspx",1000,560);
		case Campaign: return new CRMWindowInfo("ma/camps/edit.aspx",820,560);
		case BulkOperation: return new CRMWindowInfo("ma/bulkoperations/edit.aspx",860,560);
		case Service: return new CRMWindowInfo("sm/services/edit.aspx",800,560);
		case CampaignResponse: return new CRMWindowInfo("ma/campaignresponse/edit.aspx",880,630);
		case CampaignActivity: return new CRMWindowInfo("ma/campaignactivity/edit.aspx",755,540);
		case Equipment: return new CRMWindowInfo("sm/resources/edit.aspx",820,560);
		case ResourceGroup: return new CRMWindowInfo("sm/resourcegroups/edit.aspx",820,560);
		case ResourceSpec: return new CRMWindowInfo("sm/resourcespecs/edit.aspx",820,560);
		case Site: return new CRMWindowInfo("sm/sites/edit.aspx",820,560);
		case ServiceRestrictionCalendarRule: return new CRMWindowInfo("sm/workplans/dialogs/serviceavailability.aspx",550,380);
		case OccurrenceCalendarRule: return new CRMWindowInfo("sm/workplans/dialogs/occurrence.aspx",550,500);
		case RecurrenceCalendarRule: return new CRMWindowInfo("sm/workplans/dialogs/recurrencerule.aspx",550,500);
		case OccurringWorkShift: return new CRMWindowInfo("sm/workplans/dialogs/timesheet.aspx",640,500);
		case Calendar: return new CRMWindowInfo("tools/availabilitytemplateeditor/edit.aspx",750,480);
		case Contact: return new CRMWindowInfo("sfa/conts/edit.aspx",1000,560);
		case CustomerAddress: return new CRMWindowInfo("sfa/customeraddress/edit.aspx",820,560);
		case Opportunity: return new CRMWindowInfo("sfa/opps/edit.aspx",1000,560);
		case OpportunityProduct: return new CRMWindowInfo("sfa/opportunityproduct/edit.aspx",820,560);
		case CustomerOpportunityRole: return new CRMWindowInfo("sfa/customeropportunityrole/edit.aspx",450,450);
		case Lead: return new CRMWindowInfo("sfa/leads/edit.aspx",1000,560);
		case Annotation: return new CRMWindowInfo("notes/edit.aspx",500,350);
		case Quote: return new CRMWindowInfo("sfa/quotes/edit.aspx",1000,560);
		case QuoteDetail: return new CRMWindowInfo("sfa/quotedetail/edit.aspx",820,560);
		case SalesOrder: return new CRMWindowInfo("sfa/salesorder/edit.aspx",1000,560);
		case SalesOrderDetail: return new CRMWindowInfo("sfa/salesorderdetail/edit.aspx",820,560);
		case Invoice: return new CRMWindowInfo("sfa/invoice/edit.aspx",1000,560);
		case InvoiceDetail: return new CRMWindowInfo("sfa/invoicedetail/edit.aspx",820,560);
		case SystemUser: return new CRMWindowInfo("biz/users/edit.aspx",820,675);
		case Team: return new CRMWindowInfo("biz/teams/edit.aspx",880,500);
		case BusinessUnit: return new CRMWindowInfo("biz/business/edit.aspx",880,500);
		case Incident: return new CRMWindowInfo("cs/cases/edit.aspx",1000,600);
		case Competitor: return new CRMWindowInfo("sfa/comps/edit.aspx",820,560);
		case DocumentIndex: return new CRMWindowInfo("cs/articles/viewer/default.aspx",650,530);
		case KbArticle: 
		if(sId == "")
		{
			return new CRMWindowInfo("cs/articles/lookup_template.aspx",820,560);
		}
		else
		{
			return new CRMWindowInfo("cs/articles/edit_article.aspx",820,560);
		}
		
		
		case KbArticleComment: return new CRMWindowInfo("cs/articles/comment/edit.aspx",500,350);
		case KbArticleTemplate: return new CRMWindowInfo("tools/kbtemplateeditor/kbtemplateeditor.aspx",820,560);
		case Template: return new CRMWindowInfo("tools/emailtemplateeditor/emailtemplateeditor.aspx",820,560);
		case Subject: return new CRMWindowInfo("cs/subjs/edit_subj.aspx",400,300);
		case BusinessUnitNewsArticle: return new CRMWindowInfo("tools/newseditor/edit.aspx",820,560);
		case ActivityMimeAttachment: return new CRMWindowInfo("activities/attachment/edit.aspx",500,175);
		case Task: return new CRMWindowInfo("activities/task/edit.aspx",880,600);
		case Fax: return new CRMWindowInfo("activities/fax/edit.aspx",880,600);
		case PhoneCall: return new CRMWindowInfo("activities/phone/edit.aspx",880,600);
		case Email: return new CRMWindowInfo("activities/email/edit.aspx",1000,530);
		case Letter: return new CRMWindowInfo("activities/letter/edit.aspx",880,600);
		case Appointment: return new CRMWindowInfo("activities/appointment/edit.aspx",880,575);
		case ServiceAppointment: return new CRMWindowInfo("activities/serviceappointment/edit.aspx",905,600);
		case Contract: return new CRMWindowInfo("cs/contracts/edit.aspx",1000,537);
		case ContractDetail: return new CRMWindowInfo("cs/contractdetails/edit.aspx",1000,557);
		case ContractTemplate: return new CRMWindowInfo("tools/contracttypemanager/edit.aspx",750,600);
		case SalesLiterature: return new CRMWindowInfo("sfa/saleslit/edit.aspx",820,560);
		case SalesLiteratureItem: return new CRMWindowInfo("sfa/saleslit/attachment_edit.aspx",820,560);
		case Product: return new CRMWindowInfo("products/product/edit.aspx",1000,560);
		case ProductPriceLevel: return new CRMWindowInfo("products/productpricelevel/edit.aspx",650,500);
		case Role: return new CRMWindowInfo("biz/roles/edit.aspx",1024,690);
		case SavedQuery: return new CRMWindowInfo("tools/vieweditor/viewmanager.aspx",800,400);
		case PriceLevel: return new CRMWindowInfo("products/pricelevel/edit.aspx",770,560);
		case UoMSchedule: return new CRMWindowInfo("products/uomschedule/edit.aspx",820,560);
		case UoM: return new CRMWindowInfo("products/uom/edit.aspx",580,370);
		case DiscountType: return new CRMWindowInfo("products/discounttype/edit.aspx",820,560);
		case Discount: return new CRMWindowInfo("products/discounttypeitem/edit.aspx",580,370);
		case Queue: return new CRMWindowInfo("tools/queuingmanager/edit.aspx",820,560);
		case OpportunityClose: return new CRMWindowInfo("sfa/opps/closeopp.aspx",550,375);
		case OrderClose: return new CRMWindowInfo("sfa/salesorder/cancelorder.aspx",550,375);
		case QuoteClose: return new CRMWindowInfo("sfa/quotes/closequote.aspx",550,375);
		case CustomerRelationship: return new CRMWindowInfo("sfa/customerrelationships/edit.aspx",720,390);
		case IncidentResolution: return new CRMWindowInfo("cs/cases/closecase.aspx",550,375);
		case Territory: return new CRMWindowInfo("biz/territories/edit.aspx",820,560);
		case TransactionCurrency: return new CRMWindowInfo("biz/transactioncurrencies/edit.aspx",820,560);
		case MailMergeTemplate: return new CRMWindowInfo("tools/mailmerge/edit.aspx",820,580);
		case RelationshipRole: return new CRMWindowInfo("tools/relationshiproleeditor/edit.aspx",820,560);
		case Report: 
		if(sId == "")
		{
			return new CRMWindowInfo("crmreports/reportproperty.aspx",880,700);
		}
		else
		{
			return new CRMWindowInfo("crmreports/viewer/viewer.aspx",880,700);
		}
		case ReportPropertyDialog: return new CRMWindowInfo("crmreports/reportproperty.aspx",680,620);
		case TimeOffCalendarRule: return new CRMWindowInfo("sm/workplans/dialogs/timeoff.aspx",550,420);
		case HolidayCalendarRule: return new CRMWindowInfo("sm/workplans/dialogs/holiday.aspx",550,420);
		case RecurringWorkShift: return new CRMWindowInfo("sm/workplans/edit.aspx",550,540);
		case NotWorkingWorkShift: return new CRMWindowInfo("sm/workplans/edit.aspx",550,540);
		case FixedMonthlyFiscalCalendar: return new CRMWindowInfo("_grid/cmds/dlg_addquota.aspx",600,425);
		case MonthlyFiscalCalendar: return new CRMWindowInfo("_grid/cmds/dlg_addquota.aspx",600,425);
		case QuarterlyFiscalCalendar: return new CRMWindowInfo("_grid/cmds/dlg_addquota.aspx",600,425);
		case SemiAnnualFiscalCalendar: return new CRMWindowInfo("_grid/cmds/dlg_addquota.aspx",600,425);
		case AnnualFiscalCalendar: return new CRMWindowInfo("_grid/cmds/dlg_addquota.aspx",600,425);
		case UserQuery: return new CRMWindowInfo("advancedfind/advfind.aspx",900,600);
		case AppOfflineFilter: return new CRMWindowInfo("tools/offlinedata/offlinefilter.aspx",850,720);
		case DisplayString: return new CRMWindowInfo("tools/systemcustomization/displaystrings/edit.aspx",820,560);
		case ActivityScheduling: return new CRMWindowInfo("sm/activityscheduling/schedulingdialog.aspx",880,600);
		case Workflow:
		if(sId == "")
		{
			return new CRMWindowInfo("sfa/workflow/workflowTemplate/workflowTemplatePage.aspx",1000,560);
		}
		else
		{
			return new CRMWindowInfo("sfa/workflow/edit.aspx",1000,560);
		}
		case AsyncOperation: return new CRMWindowInfo("tools/asyncoperation/edit.aspx",900,560);
		case AppWorkflowInstance: return new CRMWindowInfo("tools/workflowinstance/edit.aspx",1000,560);
		case ScriptErrorDialog: return new CRMWindowInfo("_common/error/dlg_scripterror.aspx",550,260);
		case ScriptErrorDetailsDialog: return new CRMWindowInfo("_common/error/dlg_scripterrordetails.aspx",500,300);
		case DuplicateRule: return new CRMWindowInfo("tools/duplicatedetection/duplicatedetectionrules/edit.aspx",1000,640);
		case ImportMap: return new CRMWindowInfo("tools/managemaps/edit.aspx",1000,680);
		case BulkDeleteOperation: return new CRMWindowInfo("tools/bulkdelete/edit.aspx",1000,640);
	default: 
	if (IsUserDefinedEntityObjectTypeCode(Number(iObjectType))) 
	return new CRMWindowInfo("userdefined/edit.aspx",1000,560);
	}
}
function CollapseButtonClick(sWebPartId, sBackgroundUrl)
{
	window.document.getElementById( sWebPartId + '_expandButton').style.display='inline';
	window.document.getElementById( sWebPartId + '_expandHelpIcon').style.display='inline';
	window.document.getElementById( sWebPartId + '_userData').style.display='none';
	var signOutBtn = window.document.getElementById( sWebPartId + '_signOut');
	if(signOutBtn != null)
	{
		signOutBtn.style.display='none';
	}
	window.document.getElementById( sWebPartId + '_orgName').style.display='none';
	
	window.document.getElementById( sWebPartId + '_bannerTable').style.backgroundImage='url(' + sBackgroundUrl + ')';
	window.document.getElementById( sWebPartId + 'crmdb_isBannerCollapsed').value='true';
}
function ExpandButtonClick(sWebPartId, sBackgroundUrl)
{
	window.document.getElementById( sWebPartId + '_userData').style.display='inline';
	var signOutBtn = window.document.getElementById( sWebPartId + '_signOut');
	if(signOutBtn != null)
	{
		signOutBtn.style.display='inline';
	}
	window.document.getElementById( sWebPartId + '_orgName').style.display='inline';	
	window.document.getElementById( sWebPartId + '_expandButton').style.display='none';
	window.document.getElementById( sWebPartId + '_expandHelpIcon').style.display='none';
	window.document.getElementById( sWebPartId + '_bannerTable').style.backgroundImage='url(' + sBackgroundUrl + ')';
	window.document.getElementById( sWebPartId + 'crmdb_isBannerCollapsed').value='false';
}
