var OUTBOUNDFORMID = "25b9d714-badd-47d5-8b6f-30612a2bcba2";
var CALLBACKFORMID = "2e74a092-f59a-412c-ae16-7f115538ffed";
var DEFAULTFORMID = "a91390a5-99bb-4d10-9eee-3a5c87f841f1";

function form_OnLoad()
{
	if (Xrm.Page.ui.getFormType() != 1)
	{
		var formId = DEFAULTFORMID;
		var currentFormName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

		if (Xrm.Page.getAttribute("DNS_type_code") != null)
		{		
			var type = Xrm.Page.getAttribute("DNS_type_code").getText();
			
			if (currentFormName != type)
			{
				switch(type)
				{
					case "HRC Outbound":
						if (Xrm.Page.ui.formSelector.items.get(OUTBOUNDFORMID) != null)
						{
							formId = OUTBOUNDFORMID;
						}
						break;
					case "HD Callback":
						if (Xrm.Page.ui.formSelector.items.get(CALLBACKFORMID) != null)
						{
							formId = CALLBACKFORMID;
						}
						break;
					default:
						formId = DEFAULTFORMID;
						break;
				}
				
				if (Xrm.Page.ui.formSelector.items.get(formId) != null)
				{
					Xrm.Page.ui.formSelector.items.get(formId).navigate();
				}
			}
		}
	}
}

