

/*
These are the iMarkup form submission help routines.
*/
var AlreadySubmitted = false;

// Has the page completed loading?
var LoadingComplete = false;

// Is this a custom task popup?
var IsPopup = false;

// If this is a popup, the ID of the config form instance
var PopupConfig = "";

// GID for this form
var iGID = -1;

// FORMINSTID for this form
var iFORMINSTID = 0;

// SUID for this form (or 0 if none)
var iSUID = 0;

// Set to true if we should do a Workflow complete popup
var iWFPOPUP=false;

var iWFREAUTH=false;

// Is entire form readonly?
var iREADONLY=false;

// Should we display warning if form cancelled?
var iWARNCANCEL=false;

// Has an array size changed?
var ArrayChanged=false;

// Has an array size changed?
var gAllowAnnotations=true;

// If we are being told (by COM) to auto load a viewer, we must save them in variables and 
// drive the OnSubmit after the page is loaded
var ExternalURL = "";
var ExternalAutoLoad = false;

// NOTE: These vars are needed since the COM may return javascript using the local
// js names rather than the .asp names
var eFormButtonOK = 1;
var eFormButtonCancel = 2;
var eFormButtonApprove = 3;
var eFormButtonReject = 4;
var eFormButtonComplete = 5;
var eFormButtonAttach = 100;
var eFormButtonEvent = 101;
var eFormButtonPrint = 102;
var eFormButtonSave = 103;
var eFormButtonSaveClose = 104;
var eFormButtonSaveForm = 110;
var eFormButtonCancelWorkflow = 105;
var eFormButtonCancelWorkflowDelete = 106;
var eFormButtonArrayIncr = 107;
var eFormButtonArrayDecr = 108;
var eFormButtonCancelForm = 109;

var eObjectNotSet = 0;
var eObjectDocument = 1;
var eObjectFolder = 2;
var eObjectReviewSet = 3;
var eObjectWorkflow = 4;
var eObjectKView = 5;
var eObjectForm = 14;

/*
--------------------------------------------------------------------------------
QueryString parsing routines for JavaScript
--------------------------------------------------------------------------------
*/
var qsParm = new Array();
function qs() 
{
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++)
	{
		var pos = parms[i].indexOf('=');
		if (pos > 0)
		{
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}
}

/*
--------------------------------------------------------------------------------
This is called on every form load or re-display
--------------------------------------------------------------------------------
*/
function iInitLoaded()
{
// We HAVE completed loading. Set a flag. This is needed so that the user does not submit the 
// eform prior to the ENTIRE page being loaded. This is needed because we place IMK_INIT values
// as hidden input fields at the bottom of the eform. There would be data loss if the eform
// submitted prior to the entire page being loaded on the client.
	LoadingComplete = true;

// Check the external load URL to see if we need to auto load a popup
	if (ExternalURL!="")
	{
		OnSubmit(eFormButtonEvent,"EXT_VIEWER",ExternalURL,ExternalAutoLoad);
		return;
	}
/*
See if we should position the scroll position
*/
	qsParm['IMK_SCROLLPOS'] = 0;
	qsParm['IMK_EXT_USER_RC'] = "";
	qsParm['IMK_EXT_USER_COMMENTS'] = "";
	qs(); 
	if (qsParm['IMK_SCROLLPOS']>0)
	{
		if (IsPopup==false)
		{
			iSetScrollPosition(window,qsParm['IMK_SCROLLPOS']);
		}
	}

	// If we were driven by external form application to complete my task, then do
	// that now.
	if (qsParm['IMK_EXT_USER_RC']=="approve")
	{
		OnSubmit(eFormButtonOK,"","",false,qsParm['IMK_EXT_USER_COMMENTS']);
		return;
	}
	else if (qsParm['IMK_EXT_USER_RC']=="reject")
	{
		OnSubmit(eFormButtonReject,"","",false,qsParm['IMK_EXT_USER_COMMENTS']);
		return;
	}
	
	// Check to see if we need to display the wf complete dialog
	// This is because we now submit the form to the server (for validation checking)
	// before we do the popup.
	
	if (qsParm['showcomplete']=="1")
	{
		var URL="";
		URL=URL + "wf_complete.asp?gid=" + iGID + "&suid=" + iSUID + "&formdirect=1";
		// The previous complete comments are stored in IMK_COMPLETE_COMMENTS_POPUP or IMK_COMPLETE_COMMENTS
		if (document.DialogForm.IMK_COMPLETE_COMMENTS && document.DialogForm.IMK_COMPLETE_COMMENTS.value!="")
		{
			URL=URL + "&wfcomment=" + escape(document.DialogForm.IMK_COMPLETE_COMMENTS.value);
		}
		else if (document.DialogForm.IMK_COMPLETE_COMMENTS_POPUP && document.DialogForm.IMK_COMPLETE_COMMENTS_POPUP.value!="")
		{
			URL=URL + "&wfcomment=" + escape(document.DialogForm.IMK_COMPLETE_COMMENTS_POPUP.value);
		}
		// We also need to check the "INIT" complete comments
		else if (document.DialogForm.IMK_INIT_IMK_COMPLETE_COMMENTS && document.DialogForm.IMK_INIT_IMK_COMPLETE_COMMENTS.value!="")
		{
			URL=URL + "&wfcomment=" + escape(document.DialogForm.IMK_INIT_IMK_COMPLETE_COMMENTS.value);
		}
		// Note how we look at the PreComplete buttons
		if (qsParm['IMK_BUTTON']=="112")
		{
			AlreadySubmitted = false;
			URL=URL+"&approve=1";
			iPopup(100,100,400,600,URL,false);
			return;
		}
		else if (qsParm['IMK_BUTTON']=="113")
		{
			AlreadySubmitted = false;
			URL=URL+"&reject=1";
			iPopup(100,100,400,600,URL,false);
			return;
		}
		else
		{
			AlreadySubmitted = false;
			iPopup(100,100,400,600,URL,false);
			return;
		}
	}
		
}
// This is called before the page is completely loaded. We use this since we dont have
// to modify the <BODY> tag with the onload parm.
function iInit()
{
// PDAs do not support body.onload
	
// Set the onload even to be called after the page is completely loaded
		if (IsIE())		// Of course all browsers seem to use their own syntax
		{
			document.body.onload=iInitLoaded;
			document.body.onbeforeunload=iUnload;
// We will remove the tooltip on every mouse click up and down
			document.body.onmousedown = iFormClicked;
			document.body.onmouseup = iFormClicked;
		}
		else
		{
			document.body.onload=iInitLoaded();
// We will remove the tooltip on every mouse click up and down
			document.body.onmousedown = iFormClicked();
			document.body.onmouseup = iFormClicked();
		}
	
}
function iFormClicked()
{
	iHideTip();
}
function iUnload()
{
	// The iUnload is fired when things like popup calendars are closed. The check for client Y
	// position is used so we ONLY catch the close button on the eForm.
	// NOTE: THIS MEANS WE DO NOT CATCH the ALT-F4 or F5 window close event!
	if (event.clientY < 0)
	{
		// Only if this form is configured to prompt before cancel will we actuall prompt
		if (iWARNCANCEL && !iREADONLY)
		{
			event.returnValue = "Are you sure you want to cancel this form? All of your changes will be lost.";
		}
	}
}

/*
--------------------------------------------------------------------------------
OnSubmit
Called to submit the form
NOTE: DO NOT CHANGE THIS PARAMETER LIST!
      THIS MAY BE CALLED BY END USERS!
--------------------------------------------------------------------------------
*/

function Logit(pText)
{
//	if ( iMarkupClientVersion() > 0 )
//	{
//		ClientiMarkupObject.iCommand("Log: " + pText);
//	}
}

function OnSubmit(pType,pEventName,pEXT_URL,pEXT_Autoload,pExtUserComments)
{
	Logit("OnSubmit");
// Clear any tooltip
	iHideTip();
	
// Prompt for confirmation if this is a cancel workflow request
	if (pType==eFormButtonCancelWorkflow || pType==eFormButtonCancelWorkflowDelete)
	{
		if (!confirm("Are you sure?"))
		{
			return;
		}
	}
	
// If the page has not loaded yet, then do not allow the submission
	if (!LoadingComplete)
	{
		alert("The page has not completed loading. Please try your request again.");
		// Since this may have been a drop-down value that caused the "early" event,
		// reset the value back to "null" to force the user to re-enter it.
		// Otherwise, if this was a drop-down event that was supposed to initialize
		// other fields, it would not ever initialize those fields
		// NOTE: This only resets edit fields and drop-downs - not radios and checks
		if ("undefined" != typeof(pEventName))
		{
			try
			{
				eval("document.DialogForm." + pEventName + ".value = \"\";");
			}
			catch(e)
			{
				// This is needed since we do not "know" if the pEventName was an edit control
				// or just a real event button (which has no .value)
			}
		}

		return;
	}
// Prompt for confirmation if this is a cancel workflow request
	if (pType==eFormButtonCancel)
	{
		// Only if this form is configured to prompt before cancel will we actuall prompt
		if (iWARNCANCEL && !iREADONLY)
		{
			if (!confirm("Are you sure you want to cancel this form? All of your changes will be lost."))
			{
				return;
			}
		}
	}
	Logit("OnSubmit before document.body.onbeforeunload=null");

	if (IsIE())		// Of course all browsers seem to use their own syntax
	{
		
			document.body.onbeforeunload=null;
		
	}
	Logit("OnSubmit before AlreadySubmitted");
// If we have already submitted the form, just ignore the request
// This will prevent multiple button hits or events
	if (AlreadySubmitted)
	{
		return;
	}
	AlreadySubmitted = true;
	Logit("OnSubmit after AlreadySubmitted");
	
// If it was a cancel or close, then just close the popup window
// Actually, if we are displaying a custom task popup, then we DO submit the form
// so we can show the original form viewer.
	if (pType==2 && IsPopup==false)
	{
		
			window.close();
			return;
		
	}

// If this function was directly called from the form complete button (no pEventName),
// then invoke the wf_complete.asp popup to prompt for complete comments.
// NOTE: We check the pType to see what button was hit
// NOTE: We ONLY do this if the workflow step tells us to (iWFPOPUP flag set)
// wf_complete.asp will "re-drive" this function with a full parm list
// NOTE: We also check the re-auth (iWFREAUTH) flag
	if (iWFPOPUP || iWFREAUTH)
	{
		if ("undefined" == typeof(pEventName) && (pType == 3 || pType == 4 || pType == 5))
		{
			// Add the "showcomplete" flag to show complete dialog
			// NOTE: We now refresh the form to do validation BEFORE the complete
			// dialog is actually shown
			document.DialogForm.action=document.DialogForm.action+'&showcomplete=1';
		}
	}
	Logit("OnSubmit before anchors");

// Disable all <A> tags and iMarkup buttons - this seems to have no impact on netscape
	for (i=0; i<document.anchors.length; i++) 
	{
		if ("boolean" == typeof(document.anchors[i].disabled))
			document.anchors[i].disabled = true;
	}
	Logit("OnSubmit after anchors");
	
// Change to a wait cursor before we submit
	iWaitCursor();
	Logit("OnSubmit after iWaitCursor");

// Add the config instance if this is a popup window
	if (IsPopup)
	{
		document.DialogForm.action=document.DialogForm.action+'&popupconfig='+PopupConfig;
	}
	
// Add the array size changed flag
	if (ArrayChanged)
	{
		document.DialogForm.action=document.DialogForm.action+'&ArrayChanged=1';
	}

// Add the actual button (and optional button name)
	if ("undefined" != typeof(pEventName))
		document.DialogForm.action=document.DialogForm.action+'&IMK_BUTTON='+pType+'&IMK_EVENTNAME='+pEventName;
	else
		document.DialogForm.action=document.DialogForm.action+'&IMK_BUTTON='+pType;
	
// Set scroll position
	
		if (IsPopup)
			document.DialogForm.action=document.DialogForm.action+'&IMK_SCROLLPOS='+qsParm['IMK_SCROLLPOS'];
		else
			document.DialogForm.action=document.DialogForm.action+'&IMK_SCROLLPOS='+iGetScrollPosition(window);
	

// Add the extern URL stuff if we are being driven to display an external form
	
		if ("undefined" != typeof(pEXT_URL))
		{
			document.DialogForm.action=document.DialogForm.action+'&IMK_EXT_URL='+escape(pEXT_URL)+'&pIMK_EXT_Autoload='+pEXT_Autoload;
		}
	
	
// Add the external user comments if there are any
	
		if ("undefined" != typeof(pExtUserComments))
		{
			document.DialogForm.action=document.DialogForm.action+'&IMK_EXT_USER_COMMENTS='+escape(pExtUserComments);
		}
	

	Logit("OnSubmit before submit");

// And submit the form
	document.DialogForm.submit();
	Logit("OnSubmit before submit");
}

/*
--------------------------------------------------------------------------------
Form reference functions (attachments, workflow objects, etc)
--------------------------------------------------------------------------------
*/
function iFormContentList(pGID,pFID,IFRAMEHeight)
{
	document.write("<iframe class='FormIFRAME' width=100% height=" + IFRAMEHeight +
		" SRC='workgroup.asp?GID=" + pGID + "&p_id=" + pFID + "&p_type=2&portal=1'" +
		"FRAMEBORDER='0' SCROLLING='yes'></iframe>");
}

var eFormAttachToForm = 1			// Child reference to the form
var eFormAttachToWorkflow = 2		// Workflow object
var eFormAttachToWorkflowRef = 3	// Reference to the workflow object
var eFormAttachToMax = 3

var FormRefType=eFormAttachToForm;
var FormReadonly=true;
var FormShowView=false;
var FormShowEdit=false;
var FormShowDownload=false;
var FormShowDelete=false;
var FormShowDate=false;
var FormShowUser=false;
var FormShowHistory=false;
var FormGID=0;
var FormWFID=0;
var FormSTID=0;
var FormSUID=0;

var RefCurr=new Array(eFormAttachToMax+1);
for (var i=0; i<=eFormAttachToMax; i++)
	RefCurr[i] = 0;
var RefCount=new Array(eFormAttachToMax+1);
for (var i=0; i<=eFormAttachToMax; i++)
	RefCount[i] = 0;
var RefDID=new Array(eFormAttachToMax+1);
for (var i=0; i<=eFormAttachToMax; i++)
	RefDID[i] = new Array();
var RefVer=new Array(eFormAttachToMax+1);
for (var i=0; i<=eFormAttachToMax; i++)
	RefVer[i] = new Array();

var RefShowIFRAME;
var RefIFRAMEHeight;

// Did we add our "parent tag" so the workflow.asp children "know" if we are the parent?
var AddedParentTag=false;

function iFormRefBegin(pGID,pWFID,pSTID,pSUID,pView,pEdit,pDownload,pDelete,ShowIFRAME,IFRAMEHeight,pRefType,pReadonly,pShowDate,pShowUser,pShowHistory)
{
	// Add a hidden tag to this document so that my children "know" it was me who 
	// spawned them
	if (AddedParentTag==false)
	{
		document.write("<input DISABLED type=hidden id=iParentTag name=iParentTag value='iParentTag'>");
		AddedParentTag=true;
	}

	FormGID=pGID;
	FormWFID=pWFID;
	FormSTID=pSTID;
	FormSUID=pSUID;
	FormShowView=pView;
	FormShowEdit=pEdit;
	FormShowDownload=pDownload;
	FormShowDelete=pDelete;
	if ( typeof(pShowHistory) != "undefined" )
		FormShowHistory = pShowHistory
	FormRefType=pRefType;
	FormReadonly=pReadonly;
	if ( typeof(pShowDate) != "undefined" )
		FormShowDate = pShowDate
	if ( typeof(pShowUser) != "undefined" )
		FormShowUser = pShowUser
	RefShowIFRAME=ShowIFRAME;
	RefIFRAMEHeight=IFRAMEHeight;
	document.write("<TABLE cellSpacing=0 cellPadding=0 border=0>");
}

function iFormRefEnd()
{
	document.write("</TABLE>");
	if (RefCount[FormRefType]>0)
	{
		// When the IFRAME first comes up, use the FIRST document in the list
		document.write("<iframe class='FormIFRAME' id='FormFRAME" + FormRefType + "' width=100% height=" + RefIFRAMEHeight +
			" SRC='obj_view.asp?GID=" + FormGID + "&id=" + RefDID[FormRefType][1] + "&type=1" +
			"&ver=" + RefVer[FormRefType][1] + "' " +
			"FRAMEBORDER='0' SCROLLING='yes'></iframe>");
	}
}
function iSelect(pNum,pRefType)
{
	if (RefCurr[pRefType]>0)
	{
		iHideObject("FormRef"+pRefType+"-"+RefCurr[pRefType]);
	}
	iShowObject("FormRef"+pRefType+"-"+pNum);
	RefCurr[pRefType] = pNum;
	iGetObject("FormFRAME" + pRefType).src = "obj_view.asp?GID=" + FormGID + 
		"&id=" + RefDID[pRefType][RefCurr[pRefType]] + "&type=1" +
		"&ver=" + RefVer[pRefType][RefCurr[pRefType]];
}
function iRemove(pMAPID)
{
	if (!confirm("Are you sure?"))
	{
		return;
	}
	document.DialogForm.action=document.DialogForm.action + "&REMOVE_MAPID=" + pMAPID
	OnSubmit(101,"IMK_REMOVE");
}
function iFormRef(pName, pID, pType, pShortcut, pDocVer, pDocOID, pMAPID, pDate, pUser)
{
	// Do not show items that have been removed
	if (pID==-1)
		return;

	if (pType==1 && RefShowIFRAME)
	{
		RefCount[FormRefType] = RefCount[FormRefType] + 1;
		RefDID[FormRefType][RefCount[FormRefType]]=pID;
		RefVer[FormRefType][RefCount[FormRefType]]=pDocVer;
	}

	document.write("<tr>");
	document.write("<td class='FormRefs'>");
	if (pType==1)
	{
		var TempStyle;
		if (RefCount[FormRefType]==1)
		{
			RefCurr[FormRefType] = RefCount[FormRefType];
			TempStyle = "display:inline";
		}
		else
		{
			TempStyle = "display:none";
		}
		document.write("<span id='FormRef" + FormRefType + "-" + RefCount[FormRefType] + "' style='" + TempStyle + "'>");
		document.write("<img src='images/obj_selected.gif' border=0>");
		document.write("</span>");
	}
	document.write("</td>");
	document.write("<td class='FormRefs'>");
	if (pType==1 && RefShowIFRAME)
	{
		document.write("<A CLASS='iHotLink' HREF='#' onclick='iSelect(" + RefCount[FormRefType] + ", " + FormRefType + ");return false;'>" + HTMLString(pName) + "</A>");
	}
	else
	{
		document.write(HTMLString(pName));
	}
	document.write("</td>");
	document.write("<td width=14px></td>");
	document.write("<td class='FormRefs'>");
	if (FormShowView)
	{
		// Viewing documents uses a different page since it may have annotations
		// Note we only show annotations for workflow objects and form references (not wf references)
		// NOTE: If this is for form references, then annotations are ONLY used if there is a WFID
		// NOTE: If this is for workflow objects, then annotations are ONLY used if there is a WFID
		if (pType==1 && ( (FormRefType==eFormAttachToWorkflow && FormWFID!=0) || (FormRefType==eFormAttachToForm && FormWFID!=0) ) )
		{
			var Temp;
			Temp = "form_doc_review.asp?gid=" + FormGID  + "&did=" + pID + "&ver=" + pDocVer +
				"&wfid=" + FormWFID + "&stid=" + FormSTID + "&suid=" + FormSUID;
//			document.write("<A CLASS='iHotLink' HREF='#' onclick='iPopup(100,100,0,0,\"" + Temp + "\",false);return false;'>Review</A>");
// We now use a function so we can inspect the gAllowAnnotations variable which is set after this function is called
			document.write("<A CLASS='iHotLink' HREF='#' onclick='iReviewPopup(\"" + Temp + "\");return false;'>Review</A>");
		}
		// NOTE: Review sets (URLs) now have a special page to look for .PDF documents
		// for PDF annotations
		else if (pType==3 && ( (FormRefType==eFormAttachToWorkflow && FormWFID!=0) || (FormRefType==eFormAttachToForm && FormWFID!=0) ) )
		{
			var Temp;
			Temp = "form_rs_review.asp?gid=" + FormGID  + "&rsid=" + pID + 
				"&wfid=" + FormWFID + "&stid=" + FormSTID + "&suid=" + FormSUID;
			document.write("<A CLASS='iHotLink' HREF='#' onclick='iPopup(100,100,0,0,\"" + Temp + "\",false);return false;'>Review</A>");
		}
		else
		{
			var Temp;
			Temp = "obj_view.asp?gid=" + FormGID + "&id=" + pID + "&type=" + pType;
			if (pType==15)
			{
				// We use OpenForm to open a form (so it can use gPopupParm)
				document.write("<A CLASS='iHotLink' HREF='#' onclick='OpenForm(0,\"" + pID + "\",0,0,0,0,0);return false;'>View</A>");
			}
			else
			{
				document.write("<A CLASS='iHotLink' HREF='#' onclick='iPopup(100,100,0,0,\"" + Temp + "\",false);return false;'>View</A>");
			}
		}
	}
	document.write("</td>");
	// Only documents have an edit and download link
	if (pType==1)
	{
		if (FormShowEdit)
		{
			// Only show edit if this is not readonly
			if ( (FormReadonly==false) && (FormRefType==eFormAttachToWorkflow) &&
				FormWFID!=0 && FormSTID!=0 && FormSUID!=0 )
// (FormRefType==eFormAttachToForm && pShortcut==0)				
			{
				document.write("<td width=8px></td>");
				document.write("<td class='FormRefs'>");
				var Temp;
				Temp = "workflow.asp?gid=" + FormGID + "&wfid=" + FormWFID + "&suid=" + FormSUID +
					"&id=" + pID + "&type=" + pType + "&formdirect=1";
				document.write("<A CLASS='iHotLink' HREF='#' onclick='iPopup(100,100,500,750,\"" + Temp + "\",false);OnSubmit(101,\"IMK_EDIT\");return false;'>Edit</A>");
				document.write("</td>");
			}
		}
		if (FormShowDownload)
		{
			document.write("<td width=8px></td>");
			document.write("<td class='FormRefs'>");
			document.write("<a class='iHotLink' href='download.asp?download=1&oid=" + pDocOID + "'>Download</a>");
			document.write("</td>");
		}
		if (FormShowDelete)
		{
			document.write("<td width=8px></td>");
			document.write("<td class='FormRefs'>");
			document.write("<A CLASS='iHotLink' HREF='#' onclick='iRemove(" + pMAPID + ");return false;'>Remove</A>");
			document.write("</td>");
		}
		if (FormShowHistory)
		{
			document.write("<td width=8px></td>");
			document.write("<td class='FormRefs'>");
			var Temp;
			Temp = "doc_hist.asp?gid=" + FormGID + "&did=" + pID + "&formdirect=1";
			document.write("<A CLASS='iHotLink' HREF='#' onclick='iPopup(100,100,500,750,\"" + Temp + "\",false);return false;'>History</A>");
			document.write("</td>");
		}
	}
	else
	{
		if (FormShowDelete)
		{
			document.write("<td width=8px></td>");
			document.write("<td class='FormRefs'>");
			document.write("<A CLASS='iHotLink' HREF='#' onclick='iRemove(" + pMAPID + ");return false;'>Remove</A>");
			document.write("</td>");
		}
	}
	if (FormShowDate)
	{
		document.write("<td width=8px></td>");
		document.write("<td class='FormRefs'>");
		document.write(pDate);
		document.write("</td>");
	}
	if (FormShowUser)
	{
		document.write("<td width=8px></td>");
		document.write("<td class='FormRefs'>");
		document.write(pUser);
		document.write("</td>");
	}
	document.write("</tr>");
}

/*
--------------------------------------------------------------------------------
This is used to do the popup for reviewing attachements. It is done here
so that we can inspect the gAllowAnnotations variable which can be set at the
bottom of the page because of the FormPre API.
--------------------------------------------------------------------------------
*/
function iReviewPopup(pURL)
{
	if (gAllowAnnotations == false)
	{
		pURL = pURL + "&allowannotations=0";
	}
	iPopup(100,100,0,0,pURL,false);
}

/*
--------------------------------------------------------------------------------
External form viewer functions
--------------------------------------------------------------------------------
*/
function iExternalViewer(pURL,pAutoloaded)
{
	qsParm['IMK_EXT_USER_RC'] = "";
	qsParm['IMK_EXT_URL'] = "";
	qs(); 

	if (qsParm['IMK_EXT_USER_RC']!="")
	{
		// NOTE: We do NOT process this event if this is an "auto-load" call, AND
		// this page has a IMK_EXT_USER_RC parm (which means it was loaded by the
		// for_ext_b_resp.asp page.
		if (pAutoloaded || pAutoloaded=="1")
		{
			return;
		}
	}
	
	if (qsParm['IMK_EXT_URL']!="")
	{
		// NOTE: If the external URL is already set, then do NOT process the command.
		// The iMarkup eForm was just refreshed to display the most recent data
		if (pAutoloaded || pAutoloaded=="1")
		{
			return;
		}
	}

// We cannot directly view the external form ... we must first save the form data (in temp mode)
// and then re-drive the page with the pURL and pAutoloaded parms as URL parms
// Note that this is also needed for new form instances that actually may have no
// forminstid right now

// If the form has not completed loading, then ...
// we CANNOT directly call OnSubmit yet. The form has NOT completed loading (COM places the 
// iExternalViewer inline on the form). We need the entire form to load because it may have default
// values as hidden fields that need to be sent to the server

// But if the form HAS completed loading (e.g. from IMK_EXT_APPL_LINK or IMK_EXT_APPL_BUTTON), 
// then call ObSubmit directly
	if (LoadingComplete)
	{
		OnSubmit(eFormButtonEvent,"EXT_VIEWER",pURL,pAutoloaded);
	}
// Instead, set variables that we will query in iInitLoaded()
	else
	{
		ExternalURL = pURL;
		ExternalAutoLoad = pAutoloaded;
	}

}

// Used for Doc picker
function iFormDocChoose(pType,pFolder,pCurr,pReturnStr,pReturnVal,pFileType)
{
	winLeft = (screen.width>1200) ? 100 : 50
	winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
	winTop = (screen.height>1000) ? 100 : 50
	winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

	iPopup(winLeft, winTop, winHeight, winWidth, 
		"doc_choose_template.asp?gid=" + iGID + "&fid=" + pFolder + "&type=DO&curr=" + pCurr + "&curr_type=1&returnstr=" + pReturnStr  + "&returnval=" + pReturnVal + "&filetype=" + pFileType, 
		0);
}

// Used for the assign task
// Used also for various "pickers"
function iFormChoose(pType,pMultiple,pCurr,pReturnStr,pReturnVal,pInUgroup)
{
	// Folder picker
	if (pType=="F")
	{
		// pMultiple is actually the starting folder
		winLeft = (screen.width>1200) ? 100 : 50
		winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
		winTop = (screen.height>1000) ? 100 : 50
		winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

		iPopup(winLeft, winTop, winHeight, winWidth, 
			"doc_choose_template.asp?gid=" + iGID + "&fid=" + pMultiple + "&nosel=1&type=F&key=" + pCurr + "&returnstr=" + pReturnStr  + "&returnval=" + pReturnVal, 
			0);
	}
	// Workflow picker
	else if (pType=="WF")
	{
		// pMultiple is actually the starting folder
		winLeft = (screen.width>1200) ? 100 : 50
		winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
		winTop = (screen.height>1000) ? 100 : 50
		winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

		iPopup(winLeft, winTop, winHeight, winWidth, 
			"doc_choose_template.asp?gid=" + iGID + "&fid=" + pMultiple + "&nosel=1&type=W&curr=" + pCurr + "&curr_type=4&returnstr=" + pReturnStr  + "&returnval=" + pReturnVal, 
			0);
	}
	// KView picker
	else if (pType=="KVIEW")
	{
		// pMultiple is actually the starting folder
		winLeft = (screen.width>1200) ? 100 : 50
		winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
		winTop = (screen.height>1000) ? 100 : 50
		winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

		iPopup(winLeft, winTop, winHeight, winWidth, 
			"doc_choose_template.asp?gid=" + iGID + "&fid=" + pMultiple + "&nosel=1&type=KV&curr=" + pCurr + "&curr_type=5&returnstr=" + pReturnStr  + "&returnval=" + pReturnVal, 
			0);
	}
	// Form picker
	else if (pType=="FORM")
	{
		// pMultiple is actually the starting folder
		winLeft = (screen.width>1200) ? 100 : 50
		winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
		winTop = (screen.height>1000) ? 100 : 50
		winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

		iPopup(winLeft, winTop, winHeight, winWidth, 
			"doc_choose_template.asp?gid=" + iGID + "&fid=" + pMultiple + "&nosel=1&type=EW&curr=" + pCurr + "&curr_type=14&returnstr=" + pReturnStr  + "&returnval=" + pReturnVal, 
			0);
	}
	// Category picker
	else if (pType=="CATID")
	{
		// pMultiple is actually the starting CATID
		winLeft = (screen.width>1200) ? 100 : 50
		winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
		winTop = (screen.height>1000) ? 100 : 50
		winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

		iPopup(winLeft, winTop, winHeight, winWidth, 
			"cat_choose.asp?gid=" + iGID + "&type=KC&top=" + pMultiple + "&key=" + pCurr + "&returnstr=" + pReturnStr  + "&returnval=" + pReturnVal, 
			0);
	}
	// Attribute picker
	else if (pType=="ATTID")
	{
		// pMultiple is actually the starting CATID
		winLeft = (screen.width>1200) ? 100 : 50
		winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
		winTop = (screen.height>1000) ? 100 : 50
		winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

		// Note how we leve key and returnval2 as BLANK. The cat_choose.asp will fill the "key" 
		// in from the ATTID in "key2"
		iPopup(winLeft, winTop, winHeight, winWidth, 
			"cat_choose.asp?gid=" + iGID + "&type=KA&top=" + pMultiple + "&key=&key2=" + pCurr + "&returnstr=" + pReturnStr + "&returnval=" + pReturnVal + "&returnval2=", 
			0);
	}
	// Attribute dropdown picker
	else if (pType=="ATTID_DROPDOWN")
	{
		// pMultiple is actually the starting CATID
		winLeft = (screen.width>1200) ? 100 : 50
		winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
		winTop = (screen.height>1000) ? 100 : 50
		winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

		// Note how we leve key and returnval2 as BLANK. The cat_choose.asp will fill the "key" 
		// in from the ATTID in "key2"
		iPopup(winLeft, winTop, winHeight, winWidth, 
			"cat_choose.asp?gid=" + iGID + "&type=KAD&top=" + pMultiple + "&key=&key2=" + pCurr + "&returnstr=" + pReturnStr + "&returnval=" + pReturnVal + "&returnval2=", 
			0);
	}
	else
	{
		winLeft = (screen.width>1200) ? 100 : 50
		winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
		winTop = (screen.height>1000) ? 100 : 50
		winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

		iPopup(winLeft, winTop, winHeight, winWidth, 
			"wf_choose.asp?gid=" + iGID + "&type=" + pType + "&multiple=" + pMultiple + "&curr=" + pCurr + "&returnstr=" + pReturnStr  + "&returnval=" + pReturnVal + "&inugroup=" + pInUgroup, 
			0);
	}
}

// Used to popup the manage users dialog
function iManageUsers(pWFID,pCanReassign,pCanAdd,pCanCancel,pCanRemove,pCanRestart,pUGID)
{
	

	winLeft = (screen.width>1200) ? 100 : 50
	winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
	winTop = (screen.height>1000) ? 100 : 50
	winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

	iPopup(winLeft, winTop, winHeight, winWidth, 
		"wf_report.asp?gid=" + iGID + "&formdirect=1&direct=1&wfid=" + pWFID + 
			"&can_reassign=" + pCanReassign + "&can_add=" + pCanAdd + "&can_cancel=" + pCanCancel + "&can_remove=" + pCanRemove + "&can_restart=" + pCanRestart +
			"&inugroup=" + pUGID,
		0);
	// After we popup the manage users, save the form data
	OnSubmit(eFormButtonEvent,"IMK_MANAGE_USERS")
}

// Used to popup the manage users dialog
function iFormLog(pFieldName, pStepName, pLogType)
{
	// Do not show the form log if there is no form instance
	if (iFORMINSTID==0)
		return;

	winLeft = (screen.width>1200) ? 100 : 50
	winWidth = (screen.width - 100 - winLeft>700) ? 700 : screen.width - 100 - winLeft
	
	winTop = (screen.height>1000) ? 100 : 50
	winHeight = (screen.height>1000) ? (screen.height - 300 - winTop) : (screen.height - 100 - winTop)

	iPopup(winLeft, winTop, winHeight, winWidth, 
		"form_audit.asp?gid=" + iGID + "&forminstid=" + iFORMINSTID + "&fieldname=" + pFieldName + "&stepname=" + pStepName + "&logtype=" + pLogType,
		0);

}
function iObjectView(pID,pType)
{
// NOTE: The wfdirect=1 tells the popup to use the complete/approve/reject buttons if the 
// popup form is in a workflow.
	iPopup(100,100,0,0,"obj_view.asp?gid=" + iGID + "&id=" + pID + "&type=" + pType + "&wfdirect=1",false);
}

// Used to scroll to the iMarkup form field
function iScrollToObject(pObject)
{
	// NOTE: In FireFox and Netscape, the HTML objects MUST have an id=
	// Currently only textboxs and radio buttons have this
	if (iGetObject(pObject))
	{
		if (iGetObject(pObject).disabled==false && (!iGetObject(pObject).type || iGetObject(pObject).type!="hidden"))
		{
			iGetObject(pObject).focus();
			// If browser supports scrollIntoView
			if (iGetObject(pObject).scrollIntoView)
			{
				iGetObject(pObject).scrollIntoView();
			}
		}
		// Picker controls
		else if (iGetObject(pObject + "_Pick") && iGetObject(pObject + "_Pick").disabled==false && (!iGetObject(pObject + "_Pick").type || iGetObject(pObject + "_Pick").type!="hidden"))
		{
			iGetObject(pObject + "_Pick").focus();
		}
		// Checkboxs in iMarkup are actually arrays
		else if ("undefined" != typeof(iGetObject(pObject).length))
		{
			var TempObj = iGetObject(pObject);
			if (TempObj[0].disabled==false && TempObj[0].type && TempObj[0].type=="checkbox")
			{
				TempObj[0].focus();
			}
		}
	}
	// Radio buttons in iMarkup have IMK_RAD_ appended to first element
	else if (iGetObject("IMK_RAD_" + pObject))
	{
		// Can't check disabled because doesn't work in Firefox
		try
		{
			iSetScrollPosition(window,iGetDocOffset(iGetObject("IMK_RAD_" + pObject)))
		}
		catch(e)
		{
			// ignore
		}
	}
	// Drop-downs in iMarkup have IMK_DD_ prepended to id
	else if (iGetObject("IMK_DD_" + pObject))
	{
		// Can't check disabled because doesn't work in Firefox
		try
		{
			iGetObject("IMK_DD_" + pObject).focus();
		}
		catch(e)
		{
			// ignore
		}
	}
}


