// Support Script (768)
function trim(stringToTrim) 
{
   return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function getForm()
{
	var f;
	if (document.forms && document.forms[0])
	{
		// This is the case where there are only hidden form elements in an
		// all 4.0 browser page and Comm is hitting the page - and all IE cases.
		f = document.forms[0];
	}

	if (f == null)
	{
		if ((document.layers) && (document.layers.length > 0))
		{
			var d;
			iLayer = 0;
			while (true)
			{
				d = document.layers[iLayer].document.layers[0].document;
				if (d.forms && d.forms[0]) // normal case
				{
					f = d.forms[0];
					break;
				}
				iLayer = iLayer + 2;
			
				if (document.layers[iLayer] == null)
					break;
			}
		}
	}

	if (f == null)
		alert("Form not submitted - internal error: Drumbeat can not find Form object in DOM. There may not be a form on this page.");

	return f;
}

// Support Script (810)
function subAwithBinC(a,b,c)
{

	var i = c.indexOf(a);
	var l = b.length;

	while (i != -1)	{
		c = c.substring(0,i) + b + c.substring(i + a.length,c.length);
  i += l
		i = c.indexOf(a,i);
	}
	return c;

}
// Support Script (770)
function Validate(stopOnFailure)
{
	var ErrorMsg = "";
	var i
	var msg
	var tofocus = true;
	var ErrorMsg = "";
	
	// Go through the Validate Array that may or may not exist
	// and call the Validate function for all elements that have one.
	if (document.ValidateArray)
	{
		for (i = 0; i < document.ValidateArray.length; i ++)
		{
			msg = eval( document.ValidateArray[i] + ".Validate()")
			if (msg != "")
			{
				ErrorMsg += "\n\n" + document.ValidateArray[i] + ":  " + msg;
				if (tofocus) 
				{
					eval(document.ValidateArray[i] + ".focus()")
					tofocus = false;
				}
				
				if (stopOnFailure == "1") return ErrorMsg;
			}
  	}
  }
	return ErrorMsg;
}

function document_onLoad() {
UserName.focus();
 }
function document_onMouseDown() {
if (event.button==2) {
    alert("The properties for this page are not available.");
}
 }
function LoginForm_onSubmit() {
f = getForm();

if (f != null)
{
  if (f.action.indexOf("?") >= 0)
    f.action += "&";
  else
    f.action += "?";
  
  f.action += "FormButton1" + "=x"
}
 }
function _LoginForm_onSubmit() { if (LoginForm) return LoginForm.onSubmit(); }
function UserName__onChange() {
if ("1" == "1") {
var enteredtext = document.forms[0].UserName
enteredtext.value = enteredtext.value.toUpperCase()
}
else if ("1" == "0") {
var enteredtext = document.forms[0].UserName
enteredtext.value = enteredtext.value.toLowerCase()
}
 }
function _UserName__onChange() { if (UserName) return UserName.onChange(); }
function Password__onChange() {
if ("1" == "1") {
var enteredtext = document.forms[0].Password
enteredtext.value = enteredtext.value.toUpperCase()
}
else if ("1" == "0") {
var enteredtext = document.forms[0].Password
enteredtext.value = enteredtext.value.toLowerCase()
}
 }
function _Password__onChange() { if (Password) return Password.onChange(); }
function FormButton1__onClick() {
var addChar = "?" 
var j
var okToSubmit = false;

if ("".length > 1)
{
    LoginForm.setAction(subAwithBinC(" ", "%20", ""));
}

// execute the onSubmit() event handler and try to 
// determine if it already validated the form
Result = LoginForm.onSubmit();

//   If there is no onSubmithander the return value is null
//   If there is a validation handler it returns true to submit
//   or false to not submit
if (Result==null)  // there is no validation already defined
{
    if ("1" == "1")
    {
        Result = Validate("0"); // don't stop on first error
        if (trim(Result) == "") okToSubmit = true;
        else alert("The form could not be submitted:" + Result);
    }
    else okToSubmit = true;
}
else // there is a validation already defined
{
    if (Result==true)
        okToSubmit = true;
}

if (okToSubmit) 
{
    // We have to
    // put the source in the query string so the generic database contracts
    // still work.

    // NOTE: this only works if the method of the form is POST


    act = LoginForm.getAction();
    if (act.indexOf("?") != -1)
    {    
        addChar = "&"
    }

    act += addChar + "FormButton1=1"
    LoginForm.setAction(act);


    LoginForm.submit();
}
 }
function _FormButton1__onClick() { if (FormButton1) return FormButton1.onClick(); }


