//vars
var _bPresenceEnabled = true;
var _currentTypeCode = 2;
var None = 0;
var Account = 1;
var ActivityMimeAttachment = 1001;
var ActivityParty = 135;
var ActivityPointer = 4200;
var Annotation = 5;
var AnnualFiscalCalendar = 2000;
var Appointment = 4201;
var AsyncOperation = 4700;
var AttributeMap = 4601;
var BulkDeleteFailure = 4425;
var BulkDeleteOperation = 4424;
var BulkOperation = 4406;
var BulkOperationLog = 4405;
var BusinessUnit = 10;
var BusinessUnitNewsArticle = 132;
var Calendar = 4003;
var CalendarRule = 4004;
var Campaign = 4400;
var CampaignActivity = 4402;
var CampaignResponse = 4401;
var Competitor = 123;
var IS_PATHBASEDURLS = false;
// Error Consts
var ERROR_STOP = 0;
var ERROR_NONE = 1;
var ERROR_CONTINUE = 2;
//
var LOCID_UI_DIR = "LTR";

var LOCID_TREE_PLUS = "已折叠，单击即可展开";
var LOCID_TREE_MINUS = "已展开，单击即可折叠 ";
var LOCID_GRID_PREVIEW_ROW = "单击此处可结束预览";
var LOCID_POPUP_BLOCKER_ERROR = "ESMS窗口无法打开，可能已被弹出窗口阻止程序所阻止。请将这台 ESMS 服务器添加到您的弹出窗口阻止程序允许打开新窗口的站点的列表中:";
var LOCID_LU_SELECT_VALUE_FOR = "单击以选择{0}的值。";
var LOCID_LOADING_NOTES_DATA = "正在加载...";
var LOCID_XML_PROCESS_ERROR = '处理您的请求时出错。请稍候再重试。';
var LOCID_RELATEDINFO_DATALOADING = "正在加载...";
var LOCID_RELATEDINFO_NORESULTS = "找";
var LOCID_RELATEDINFO_FLWUP_OK = "已成功创建 {0} {1}";
var LOCID_RELATEDINFO_FLWUP_SUBJ = "跟进: {0}";
var LOCID_RELATEDINFO_EXPAND = "单击以打开表单助理";
var LOCID_RELATEDINFO_COLLAPSE = "单击可关闭表单助理";
var LOCID_RELATEDINFO_ENDSTARTERR = "指定的结束时间必须晚于开始时间。";
var LOCID_RELATEDINFO_TASKNOTREGOBJ = "快速市场活动不能将任务作为跟进活动";
var LOCID_LOADING_GRID_DATA = "正在加载...";
var LOCID_REFRESH_GRID_CANCELLED = "刷新已取消。";
var LOCID_LOADING_GRID_FAILED = "网格刷新失败。";
var LOCID_GRID_TOO_MANY_RECORDS = "您一次只能选择 {0} 行。";
var LOCID_GRID_TOO_MANY_RECORDS_1 = "只能选择一行。";
var LOCID_GRID_SELECT_ALL_KEY = "A";
var LOCID_SEARCH_RESULTS = "搜索结果";
var LOCID_SEARCH_ALERT_NO_CRITERIA = "执行搜索前必须提供查找条件";
var LOCID_SEARCH_LIST_NOT_OPEN = "列表没有完成打开。请重试您的请求。";

//显示隐藏信息
function disableHide(id)
{
	$(id).style.display = 'block';
}

//隐藏隐藏信息
function enableHide(id)
{
	$(id).style.display = 'none';
}

function trim(str){  //删除左右两端的空格
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

function delHtmlTag(str){
	return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
} 

//检测电子邮件
function isEmail(strEmail)
{
	if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

//检测手机号码
function isMobile(strMobile)
{
	var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	if(!myreg.test(strMobile))
		return false;
	else
		return true;
}

function contain(str,charset)//  字符串包含测试函数
{  
	var  i;
	for(i=0;i<charset.length;i++)
	{
		if(str.indexOf(charset.charAt(i))>=0)
			return  false;
	}
	return  true;
}

//检测中文
function isChinese(str)
{
	var patrn = /^[\u4E00-\u9FA5]+$/
	if (!patrn.exec(str)) return false;
	return true;
}


//验证是否为数字
function isDigit(s)
{
	var patrn=/^[0-9]{1,20}$/;
	if (!patrn.exec(s)) return false;
	return true;
}

//校验邮政编码
function isPostCode(s)
{
	var patrn=/^[0-9]{3,6}$/;
	if (!patrn.exec(s)) return false;
	return true;
}

/*************************************************************     
	Author        : Shuo Wang 
	Description    : 正确截取单字节和双字节混和字符串
	String str    : 要截取的字符串
	len		        : 截取长度
*************************************************************/ 
function substr(str, len) 
{     
	if(!str || !len) { return ''; }      
	//预期计数：中文2字节，英文1字节     
	var a = 0;      
	//循环计数     
	var i = 0;      
	//临时字串     
	var temp = '';      
	for (i=0;i<str.length;i++)
	{
		if (str.charCodeAt(i)>255)
		{
			//按照预期计数增加2
			a+=2;
		}
		else
		{
			a++;
		}
		//如果增加计数后长度大于限定长度，就直接返回临时字符串
		if(a > len) { return temp; }
		//将当前内容加到临时字符串
		temp += str.charAt(i);
	}
	//如果全部是单字节字符，就直接返回源字符串
	return str;
} 

function checkPasswd()
{
	var passwd = $F('passwd');
	
	if (passwd != '')
	{
		enableHide('passwd_li');
		return true;
	}
	else
	{
		$('passwd_error').innerHTML = '请输入密码';
		disableHide('passwd_li');
		new Effect.Highlight('passwd', { startcolor: '#ffff99', endcolor: '#ffffff' });
		return false;
	}
}

//检测所有输入
function checkLoginInput()
{
	if (!$F('company'))
	{
		disableHide('formNotifications');
		$('Notification_text').innerHTML = '请输入企业名称';
		crmForm.company.focus();
		return false;
	}
	else if (!$F('username'))
	{
		disableHide('formNotifications');
		$('Notification_text').innerHTML = '请输入用户名';
		crmForm.username.focus();
		return false;
	}
	else if (!$F('passwd'))
	{
		disableHide('formNotifications');
		$('Notification_text').innerHTML = '请输入密码';
		crmForm.passwd.focus();
		return false;
	}

	return true;
}

function checkLogin()
{
	if (checkLoginInput())
	{
		enableHide('formNotifications');
		
		var refer = '';
		try
		{
			if ($F('refer')	)
			{
				refer = $F('refer');
			}
		}
		catch (e)
		{
		}
		var company = $F('company');
		var username = $F('username');
		var passwd = $F('passwd');

		var url = '/Public/doLogin/';
		var pars = 'company='+company+'&username='+username+'&passwd='+passwd+'&refer='+refer;
		var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onSuccess: checkLoginResponse, onFailure: reportError});
	}
}

function checkLoginResponse(originalRequest)
{
	var retcode = originalRequest.responseText.evalJSON(true);

	if (retcode['result'] == '1')
	{
		window.location = retcode['url'];
	}
	else
	{
		disableHide('formNotifications');
		$('Notification_text').innerHTML = retcode['message'];
		crmForm.retcode['field'].focus();
	}
}

function reportError(originalRequest)
{
		alert('服务器连接异常，请稍候再试！');
        return true;
}

function noneResponse(originalRequest)
{
        return true;
}


function logout()
{
	window.location = '/Public/logout';
}

//禁止右键
function document.oncontextmenu()
{
	var s = event.srcElement.tagName;
	// Only allow context menus if:
	// the element is not disabled AND
	// the element is either a TextArea OR a TextBox OR a user selection in some TextBox/TextArea
	event.returnValue = (!event.srcElement.disabled && (document.selection.createRange().text.length > 0 || s == "TEXTAREA" || s == "INPUT" && event.srcElement.type == "text"));
}

function document.onselectstart()
{
	var s = event.srcElement.tagName;
	if (s != "INPUT" && s != "TEXTAREA" && !(s == "DIV" && event.srcElement.className == "esms-Lookup")) event.returnValue = false;
}

var GlobalAllowDrag = false;

function document.ondragstart()
{
	event.returnValue = GlobalAllowDrag;
}

//验证输入注册信息的EMAIL否合法
function checkEmail(obj)
{
	enableHide('cue_'+obj);
	$(obj+'_error').style.display = "inline";

	var strEmail = trim($F(obj));
	if (isEmail(strEmail)==true)
	{//正确
		rightImg(obj+'_error');
		return true;
	}
	else
	{//错误
		new Effect.Highlight(obj, { startcolor: '#ffff99', endcolor: '#ffffff' });
		warning(obj+'_error', '请输入格式正确的邮箱地址');
		return false;
	}
}

//验证手机号
function checkMobile(obj)
{
	enableHide('cue_'+obj);
	$(obj+'_error').style.display = "inline";

	var strMobile = trim($F(obj));
	if (isMobile(strMobile)==true)
	{//正确
		rightImg(obj+'_error');
		return true;
	}
	else
	{//错误
		new Effect.Highlight(obj, { startcolor: '#ffff99', endcolor: '#ffffff' });
		warning(obj+'_error', '请输入格式正确的手机号码');
		return false;
	}
}

//验证姓名
function checkRealname(obj)
{
	enableHide('cue_'+obj);
	$(obj+'_error').style.display = "inline";

	var strRealname = trim($F(obj));
	if (isChinese(strRealname)==true)
	{//正确
		rightImg(obj+'_error');
		return true;
	}
	else
	{//错误
		new Effect.Highlight(obj, { startcolor: '#ffff99', endcolor: '#ffffff' });
		warning(obj+'_error', '姓名只能为汉字');
		return false;
	}
}

//检测密码
function checkPwd(obj)
{
	enableHide('cue_'+obj);
	$(obj+'_error').style.display = "inline";

	var strPwd = trim($F(obj));
	if (contain(strPwd,'%&*<>?')==true && strPwd.length>=4 && strPwd.length<=20 && isChinese(strPwd)==false)
	{//正确
		rightImg(obj+'_error');
		return true;
	}
	else
	{//错误
		new Effect.Highlight(obj, { startcolor: '#ffff99', endcolor: '#ffffff' });
		warning(obj+'_error', '密码不能含有“%&*<>?”这些符号，且4至20位');
		return false;
	}
}

var _nTimerId = -1;
function OnNavResize()
{
	_nTimerId = window.setInterval(Resize, 100);
}

function Resize()
{
	var iIndex = 0 ;
	if (LOCID_UI_DIR == "RTL")
		iIndex = 1
	var nSize = stageFrameSet.cols.split(",")[iIndex];
	if (nSize != menuBar.leftContextTD.width)
	{
		menuBar.leftContextTD.width = nSize;
	}
	else
	{
		window.clearInterval(_nTimerId);
	}
}

// Create a popup and apply global styles to it
function openPopup()
{
	var oPopup = window.createPopup();
	SetDefaultStyles(oPopup);
	return oPopup;
}

// Whenever a popup is used, it should have default stylesheets applied to it to conform to our
// application
function SetDefaultStyles(oPopup)
{
	if (!IsNull(oPopup))
	{
		var sFontsFilePath = "/Public/Css/fonts.css";
		oPopup.document.createStyleSheet(sFontsFilePath);
	}
}

function IsHelpContext()
{
	return !((typeof(HELP_CONTEXT) == "undefined") || (typeof(HELP_CONTEXT) == "unknown") || (HELP_CONTEXT != 1));
}

function IsNull(o)
{
	return ("undefined" == typeof(o) || "unknown" == typeof(o) || null == o);
}

function prependOrgName(sUrl)
{	
	var sNewUrl = sUrl;	
	if (IS_PATHBASEDURLS && ORG_UNIQUE_NAME.length > 0) 
	{
		sNewUrl = "/" + ORG_UNIQUE_NAME + sUrl;
	}
	return sNewUrl;
}

function getNavBarFrame(sAreaId)
{
return window.frames(sAreaId + "Frame");
}

function getNavBarDiv(sAreaId)
{
return document.all(sAreaId + "Div")
}


function loadArea(sAreaId, sAreaTitle)
{
	//刷新头部左侧标题
	var oAreaTitle = parent.menuBar.$('tdLeftContextBar').innerHTML;
	if (oAreaTitle != sAreaTitle)
	{
		parent.menuBar.$('tdLeftContextBar').innerHTML = sAreaTitle;
	}

	//是否存在缓存DIV
	var o = getNavBarDiv(sAreaId);

	if (o)
	{
		o.style.display = "inline";
		return false;
	}
	else
	{
		var sUrl = "/Home/nav.html";
		html = "<iframe src='" + sUrl;
		html += "?app=" + CrmEncodeDecode.CrmUrlEncode(sAreaId);
		html += "' id='" + sAreaId + "Frame' scrolling='no' width='100%' height='100%' frameborder='0'></iframe>";

		o = document.createElement("DIV");
		o.id = sAreaId + "Div";

		$('tdAreas').innerHTML = html;

		return true;
	}
}

function loadSubArea(sAreaId, sAreaTitle)
{
	//刷新头部左侧标题
	var oAreaTitle = parent.parent.menuBar.$('tdStageContextBar').innerHTML;

	if (oAreaTitle != sAreaTitle)
	{
		parent.parent.menuBar.$('tdStageContextBar').innerHTML = sAreaTitle;
	}

	parent.parent.stage.location = '/' + app + '/' + sAreaId;
}

function handleXMLErr(xml, bContinue)
{
	if (bContinue == null)
		bContinue = false;
	if (xml.parseError.errorCode != 0)
	{
		alert(LOCID_XML_PROCESS_ERROR);
		if (!bContinue)
		{
			return ERROR_STOP;
		}
		else
		{
			return ERROR_CONTINUE;
		}
	}
	
	var node = xml.selectSingleNode("/error");
	if (!IsNull(node))
	{
		if (!bContinue)
		{
			var oError = node.selectSingleNode("code");
			var oDescription = node.selectSingleNode("description");
			openErrorDlg((!IsNull(oError) ? oError.text : ""), (!IsNull(oDescription) ? oDescription.text : ""));
			return ERROR_STOP;
		}
		else
		{
			return ERROR_CONTINUE;
		}
	}

	return ERROR_NONE;
}

function buildWinName(s)
{
	if (s) return s.toLowerCase().replace(/[-\{\}:]/g, "");
	var d = new Date();
	return d.getTime();
}

//uaid 上级应用, aid操作
function openObj(app, operation, id, bNewWindow)
{
	try
	{
		if (app && operation)
		{
			var sUrl = "/" + app + "/" + operation + ".html";
		
			if (!IsNull(id))
			{
				sUrl += "?id=" + id;
			}
			return openFrmObj(sUrl, buildWinName(id), app, bNewWindow);
		}
		else
		{
			return false;
		}
	}
	catch (e)
	{
		return false;
	}
}

// This function now returns true or false - false if it did not open anything, true if it did.
function openFrmObj(sUrl, sName, app, bNewWindow)
{
	if (IsNull(bNewWindow))
	{
		bNewWindow = true;
	}

	// There are a certain number of objects that do not have forms, we should allow 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(app);
	var iX	= oWindowInfo.Width;
	var iY	= oWindowInfo.Height;
	// Check to see if anything special needs to happen for this object type
	if (!IsNull(sUrl))
	{
		switch (app)
		{
			case '':
				return (!IsNull(openStdDlg(sUrl, iX, iY)));
				break;
			default:
				// Open up window with localized size
				if (bNewWindow)
				{
					return (!IsNull(openStdWin(sUrl, sName, iX, iY)));
					
				}
				else
				{
					openInPlace(sUrl, iX, iY);
				}
				break;
		}
	}
	return false;
}

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);
	var sWinDir = "left";
	if (LOCID_UI_DIR == "RTL")
		sWinDir = "right";
	return safeWindowOpen(sPath, sName, "width=" + iX + ",height=" + iY + ",status=1,resizable=1," + sWinDir + "=" + iLeft + ",top=" + iTop + (IsNull(sCustomWinFeatures) ? "" : "," + sCustomWinFeatures));
}

function openStdDlg(sPath, iWidth, iHeight, bResizable, bModeless, sCustomWinParams, oArgs)
{
	if (IsNull(sCustomWinParams))
	{
	sCustomWinParams = "";
	}

	// 	By default all modal dialog is resizable
	if(IsNull(bResizable))
	{
		bResizable = true;
	}

	// 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);
	if (LOCID_UI_DIR == "RTL")
		iLeft = screen.availWidth-iLeft-iWidth;
		sCustomWinParams = "dialogWidth:" + iWidth + "px;dialogHeight:" + iHeight + "px;dialogLeft=" + iLeft + "px;dialogTop=" + iTop + "px;help:0;status:1;scroll:0;center:1;resizable:" + bResizable + ";" + sCustomWinParams;

	if (IsNull(bModeless) || !bModeless)
	{
		return safeWindowShowModalDialog(sPath, oArgs, sCustomWinParams);
	}
	else
	{
		return safeWindowShowModelessDialog(sPath, oArgs, sCustomWinParams);
	}
}

// The following functions do try/catch, and display the popup blocker error message as an alert when the window fails to open.
function safeWindowOpen(sUrl, sName, sFeatures, bReplace)
{
	var windowOpened = null;
	try
	{
		windowOpened = window.open(sUrl, sName, sFeatures, bReplace);
	}
	catch (e)
	{
	}
	if (IsNull(windowOpened))
	{
		handlePopupBlockerError();
	}
	return windowOpened;
}

function safeWindowShowModalDialog(sUrl, vArguments, sFeatures)
{
	// Make sure the dialog arguments are set.
	if (vArguments === null)
	{
		vArguments = "";
	}

	var returnVar = null;

	try
	{
		do
		{
			returnVar = window.showModalDialog(sUrl, vArguments, sFeatures);
		}
		while (returnVar === DialogRetryReturnValue);
	}
	catch (e)
	{
		handlePopupBlockerError();
	}

	return returnVar;
}

function safeWindowShowModelessDialog(sUrl, vArguments, sFeatures)
{
	var windowOpened = null;

	try
	{
		windowOpened = window.showModelessDialog(sUrl, vArguments, sFeatures);
	}
	catch (e)
	{
	}

	if (IsNull(windowOpened))
	{
		handlePopupBlockerError();
	}

	return windowOpened;
}

function handlePopupBlockerError()
{
	alert(LOCID_POPUP_BLOCKER_ERROR +  window.location.hostname);
}

function openInPlace(sUrl, iX, iY)
{
	iX = getAdjustedWidthForScreen(iX);
	iY = getAdjustedHeightForScreen(iY);
	// Get the left and top margin.
	var iLeft = getLeftMargin(iX);
	var iTop = getTopMargin(iY);

	// Resize and reposition window then open in place
	window.moveTo(iLeft, iTop);
	window.resizeTo(iX, iY);
	window.location = sUrl;
}

var _bWindowSizeAdjusted = false;
// Given a screen width will adjust it to fit in the current screen.  If it is empty it will default it to the application default.
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;
}

// Given a screen height will adjust it to fit in the current screen.  If it is empty it will default it to the application default.
function getAdjustedHeightForScreen(iY)
{
	if (IsNull(iY) || iY == 0)
	{
		return (screen.availHeight >= 600) ? 560 : 510;
	}
	else
	{
		return (iY >= screen.availHeight) ? screen.availHeight : iY;
	}
}

// Calculate the left and top margin to place the form in center.
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;
}

function CRMWindowInfo(iXOffset, iYOffset)
{
	this.Width	= parseInt(iXOffset, 10);
	this.Height	= parseInt(iYOffset, 10);
}

function GetWindowInformation(iObjectType)
{
	switch (iObjectType)
	{
		case "Staff":
			return new CRMWindowInfo(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
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
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
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:
			break;
	}
}

function isArray(item)
{
	return item != null && ((item instanceof Array) || (typeof item.splice) == "function");
}

function formatString()
{
	if (arguments.length == 0)
	{
		return "";
	}
	var s = arguments[0];
	var aArguments = arguments;
	if (arguments.length > 1 && isArray(arguments[1]))
	{
		aArguments = arguments[1];
		//Shift the string template into the first slot so that the new array matches the function arguments.
		aArguments.unshift(s);
	}
	for (var i = 1; i < aArguments.length; i++)
	{
		var argIndex = i - 1;
		s = s.replace(new RegExp("\\{" + argIndex + "\\}", "g"), aArguments[i].toString());
	}
	return s;
}