/////////////////////////////////////////////////////////////////////////////
//  $Workfile: FormAutomation.js $ $Revision: 1.2 $ $Author: biden $ $Date: 2006/06/05 14:06:38 $
/////////////////////////////////////////////////////////////////////////////

var STR_LOC_STARTPAGE = "/mpr";
var STR_LOC_HELPPAGE = "masController.jsp?action=help";
var formEnterKeyTrapped = document.forms[0]; // default.
var BROWSER_IE4 = document.all;
var BROWSER_NS4 = document.layers;

/////////////////////////////////////////////////////////////////////
//	loadStart()
//
//	DESCRIPTION: Loads MAS Start page
//
//	PARAMETERS: none.
//
//	RETURNS: None.
/////////////////////////////////////////////////////////////////////
function formLoadStart()
{
  document.location = STR_LOC_STARTPAGE;
}


/////////////////////////////////////////////////////////////////////
//	loadHelp()
//
//	DESCRIPTION: Loads Help in new window
//
//	PARAMETERS: String strHref
//
//	RETURNS: None.
/////////////////////////////////////////////////////////////////////
function loadHelp()
{
	window.open("masController.jsp?action=help","Help",
		"resizable,status,menubar,scrollbars,width=700,height=500,top=100,left=200");
}

/////////////////////////////////////////////////////////////////////
//	loadHelp()
//
//	DESCRIPTION: Loads Select List in new window
//
//	PARAMETERS: String strHref
//
//	RETURNS: None.
/////////////////////////////////////////////////////////////////////
function loadSelectList(sName)
{
	window.open("masController.jsp?action=viewList&name="+sName,"LIST",
		"resizable,scrollbars,width=650,height=400,top=70,left=25");
}

/////////////////////////////////////////////////////////////////////
//	setLoginFocus()
//
//	DESCRIPTION: Loads Help in new window
//
//	PARAMETERS: String strHref
//
//	RETURNS: None.
/////////////////////////////////////////////////////////////////////
function setLoginFocus()
{
	//alert("setting Focus");
	setTimeout("document.login.username.focus()",1);
}

/////////////////////////////////////////////////////////////////////
//	setSubmitOnEnter()
//
//	DESCRIPTION: Configures Form to submit when the enter key is trapped.
//
//	PARAMETERS: Form formToSubmit
//
//	RETURNS: None.
/////////////////////////////////////////////////////////////////////
function setSubmitOnEnter(formToSubmit)
{
	if (window.document.captureEvents != null)
	{
		//alert(formToSubmit.name + "Form has " + formToSubmit.elements);
		formEnterKeyTrapped = formToSubmit;
		window.document.captureEvents(Event.KEYPRESS);
		window.document.onKeyPress = submitOnEnter;
	}

}

/////////////////////////////////////////////////////////////////////
//	submitOnEnter()
//
//	DESCRIPTION: Function submits form when enter key.
//
//	PARAMETERS: Form formToSubmit
//
//	RETURNS: None.
//  Note: IE requires an <input type="submit" or type="image" 
// 			on the page
/////////////////////////////////////////////////////////////////////
function submitOnEnter(e)
{

 var keyPressed;
	if (BROWSER_NS4)
	{
			keyPressed = String.fromCharCode(e.which);
	}

	if (BROWSER_IE4)
	{
			keyPressed = String.fromCharCode(window.event.keyCode);
	}

	if (keyPressed == "\r" || keyPressed == "\n")
	{
			formEnterKeyTrapped.submit();
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////
//	viewContent()
//
//  DESCRIPTION: Opens new window to view content in and obtains focus for it.
//
//	PARAMETERS: Number nAssetId
//              Number nProxyId
//							
//	RETURNS: None
//
//////////////////////////////////////////////////////////////////////////////////////////////
function viewContent(nAssetId,nProxyId)
{
	var sViewerUrl = "masController.jsp?action=viewProxy&ObjectId=" + nAssetId + "&proxy=" + nProxyId;
	var w = window.open(sViewerUrl, "DSMCi_Viewer", config='width=600,height=600,toolbar=0,resizable=1,menubar=0,scrollbars=1,location=0,directories=0,status=0');
	w.focus();
}


///////////////////////////////////////////////////////////////////////////////////////////////
//	viewContent()
//
//  DESCRIPTION: Opens new window to view content in and obtains focus for it.
//
//	PARAMETERS: Number nModeValue
//							
//	RETURNS: None
//
//////////////////////////////////////////////////////////////////////////////////////////////
function setModeValue(formToSet,nModeValue)
{
	if (nModeValue != null) 
	{
		formToSet.mode.value = nModeValue;
		formToSet.submit();
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////
//	submitForm()
//
//  DESCRIPTION: Calls validation function for form and sumbits if valid.
//
//	PARAMETERS: Form formToSubmit
//							
//	RETURNS: boolean
//
//////////////////////////////////////////////////////////////////////////////////////////////
function submitForm(formToSubmit)
{
	
	if(validateForm(formToSubmit))
  	formToSubmit.submit();
  else
  	alert(formToSubmit.name + " had errors.  Please check all values");

}

///////////////////////////////////////////////////////////////////////////////////////////////
//	submitForm()
//
//  DESCRIPTION: Calls validation function for Registration form and sumbits if valid.
//
//	PARAMETERS: Form formToSubmit
//							
//	RETURNS: boolean
//
//////////////////////////////////////////////////////////////////////////////////////////////
function submitRegistrationForm(formToSubmit)
{
	
	if(validateRegistrationForm(formToSubmit))
  	formToSubmit.submit();
  //else
  	//alert(formToSubmit.name + " had errors.  Please check all values");

}
