
var appCtx;


function setAppCtx(ctx)
{
	this.appCtx = ctx;
}

//var bankName = "Community Association Banc";


/////////////////////////////////////////////////////////
// Write Out the Title Bar Text.
/////////////////////////////////////////////////////////
// Title is included in each page as per Search Engine code refinement
//document.write('<title>Welcome to Community Association Banc</title>');

/////////////////////////////////////////////////////////
// My Attempts to keep Global data (please keep).
/////////////////////////////////////////////////////////


function ClientState()
{
	// The handle to the Doc-Ex Window
	this.winDocEx = null;

	// The Previously Visited Page string value
	this.prevPage = null;

}

if (this.clientState == null)
{
	// I really, REALLY want to have a truly static global javascript object!
	this.clientState = new ClientState();
}


/////////////////////////////////////////////////////////
// Various functions used to display PDF and HTML forms
/////////////////////////////////////////////////////////

function open_pdf(nameOfApp)
{
	var pWidth = ( ((parseInt(screen.width) / 2)) - 550);
	var pHeight = (((parseInt(screen.height) / 2)) - 500);
	var win = window.open(appCtx+'/pdfs/'+nameOfApp+'.pdf','pdf_app',"toolbar=1,location=0,directories=0,status=0,menubar=0,width=700,height=600,top=" + pHeight + ",left=" + pWidth + ",scrollbars=1,resizable=1,status=1");
	win.focus();
}

function open_published(nameOfApp, width, height)
{
	if (!width || !height)
	{
		width = 700;
		height = 600;
	}

	var pWidth = ( ((parseInt(screen.width) / 2)) - 550);
	var pHeight = (((parseInt(screen.height) / 2)) - 500);

	var win = window.open(appCtx+'/publish/'+nameOfApp,'',"toolbar=1,location=0,directories=0,status=0,menubar=0,width=" + width + ",height=" + height + ",top=" + pHeight + ",left=" + pWidth + ",scrollbars=1,resizable=1,status=1");
	win.focus();
}

function open_pdfform(nameOfForm)
{
	var pWidth = ( ((parseInt(screen.width) / 2)) - 550);
	var pHeight = (((parseInt(screen.height) / 2)) - 500);
	var win = window.open(appCtx+'/enUS/cab2/forms/pdf/'+nameOfForm+'.pdf','pdf_app',"toolbar=1,location=0,directories=0,status=0,menubar=0,width=700,height=600,top=" + pHeight + ",left=" + pWidth + ",scrollbars=1,resizable=1,status=1");

	win.focus();
}

function open_pdffooter(nameOfApp)
{
	var pWidth = ( ((parseInt(screen.width) / 2)) - 350);
	var pHeight = (((parseInt(screen.height) / 2)) - 300);
	var win = window.open(appCtx+'/pdfs/'+nameOfApp+'.pdf','pdf_app',"toolbar=1,location=0,directories=0,status=0,menubar=0,width=700,height=600,top=" + pHeight + ",left=" + pWidth + ",scrollbars=1,resizable=1,status=1");

	win.focus();
}

function open_secureHtmlForm(nameOfForm, width, height)
{
	if (!width || !height)
	{
		width = 700;
		height = 600;
	}

	var pWidth = ( ((parseInt(screen.width) / 2)) - 550);
	var pHeight = (((parseInt(screen.height) / 2)) - 500);

	var win = window.open(appCtx+'/main/cab2/form/'+nameOfForm+'.jsp','html_app',"toolbar=0,location=0,directories=0,status=1,menubar=0,width=" + width + ",height=" + height + ",top=" + pHeight + ",left=" + pWidth + ",scrollbars=1,resizable=1");

	win.focus();
}

function open_apt_lookupForm(nameOfForm, params, width, height)
{
  if (!params)
  {
    params = "";
  }
  if (!width || !height)
	{
		width = 700;
		height = 600;
	}

	var pWidth = ( ((parseInt(screen.width) / 2)) - 550);
	var pHeight = (((parseInt(screen.height) / 2)) - 500);

	// NOTE BENE: All Public HTML forms are to be opened via HTTPS (SSL) !!!!!!
	var win = window.open("https://" + location.host + appCtx+'/apartments/forms/'+nameOfForm+'.jsp' + params,'html_app',"toolbar=0,location=0,directories=0,status=1,menubar=0,width=" + width + ",height=" + height + ",top=" + pHeight + ",left=" + pWidth + ",scrollbars=1,resizable=1");

	win.focus();
}

function open_publicHtmlForm(nameOfForm, width, height)
{
  if (!width || !height)
	{
		width = 700;
		height = 600;
	}

	var pWidth = ( ((parseInt(screen.width) / 2)) - 550);
	var pHeight = (((parseInt(screen.height) / 2)) - 500);

	// NOTE BENE: All Public HTML forms are to be opened via HTTPS (SSL) !!!!!!
	var win = window.open("https://" + location.host + appCtx+'/enUS/cab2/forms/html/'+nameOfForm+'.jsp','html_app',"toolbar=0,location=0,directories=0,status=1,menubar=0,width=" + width + ",height=" + height + ",top=" + pHeight + ",left=" + pWidth + ",scrollbars=1,resizable=1");

	win.focus();
}

/////////////////////////////////////////////////////////
// Various functions used to open windows
/////////////////////////////////////////////////////////

function openCalcWin(calc)
{
	var pWidth = ( ((parseInt(screen.width) / 2)) - 275);
	var pHeight = (((parseInt(screen.height) / 2)) -240);
	var win = window.open(calc,"hello","width=550,height=480,left=" + pWidth + ",top=" + pHeight + ",resizable=1,scrollbars=1");
	win.focus();
}

function openBannerWin(page)
{
	// Clicking on the rotating (animated) image Does nothing right now.
	if (page != null)
	{
		window.open(page).focus();
	}
}

function openENewsWin(url)
{
    winStats = 'toolbar=no,location=no,directories=no,status=no,menubar=no,';
    winStats+= 'scrollbars=yes,width=700,height=700';
    winStats+= ',left=250,top=250,';

    window.open(url, "E_News", winStats).focus();
}

function openExternalWin(url, props)
{

	var warning = "You are about to leave Community Association Banc's Web site.\nCommunity Association " +
				  			"Banc is not responsible for the content of this site.\n\nClick OK to continue.";
	if (confirm(warning))
	{
		window.open(url, "_blank", props).focus();
	}
}

function openInternalWin(url, props)
{
	window.open(url, "_blank", props).focus();
}

function openWebGatewayWin()
{
	window.open("https://www.check2ach.com", "", "toolbar=0,location=0,directories=0,menubar=0,width=700,height=600,scrollbars=1,resizable=1,status=1").focus();
	//window.open(appCtx+ "/cabach.jsp", "", "toolbar=0,location=0,directories=0,menubar=0,width=700,height=600,scrollbars=1,resizable=1,status=1").focus();
}

function openDocExWin(urlpath)
{
	var winDocEx = this.clientState.winDocEx;

  if (winDocEx != null && !winDocEx.closed)
	{
		// Only allow one DocEx window to be opened.
		this.clientState.winDocEx.focus();
	}
	else
	{
		var win = window.open(urlpath, 'docex', 'resizable=1, scrollbars=1, toolbar=1, directories=0, status=1, copyhistory=0, location=0, width=720, height=480');
		this.clientState.winDocEx = win;
		win.focus();

		var now = new Date();
    	var tomarrow = new Date( now.getTime() + (1000 * 60 * 60 * 24) );

	    // NOTE BENE: the path var "/" is ESSENTIAL so that other pages have access to this cookie
	    // because cookies are only associated with pages.
		var success = setCookie("docex", "true", tomarrow, "/");

	}
}

function displayMsgBox(msg)
{
	if (msg != null && msg.length > 0)
	{
		var pWidth = 300;
		var pHeight = 100;

		var pLeft = ( ((parseInt(screen.width) / 2)) - (pWidth / 2));
		var pTop = (((parseInt(screen.height) / 2)) - (pHeight / 2));

		var win = window.open(appCtx+ "/enUS/msgbox.jsp?errmsg="+msg, 'errMsg', 'resizable=0,scrollbars=0,toolbar=0,directories=0,status=0,copyhistory=0,location=0,left='+pLeft+',top='+pTop+',width='+pWidth+',height='+pHeight);
		win.focus();
	}

}



///////////////////////////////////////////////////////////////
// Various functions used for Login/Logout and window control
///////////////////////////////////////////////////////////////


function doLogin(f)
{
  // Make sure a login id and password are entered.
  f.login.value = trim(f.login.value);
  f.word.value = trim(f.word.value);

  if (f.login.value.length < 1)
  {
		alert("Please enter a User ID.");
		f.login.focus();
		return false;
  }
  else if (f.word.value.length < 1)
  {
		alert("Please enter a Password.");
		f.word.focus();
		return false;
  }
		/* Can we assume the user logon ID will be a password?
		else if ( !validEmail(f.login.value) )
		{
			alert("User ID must contain both an '@' and a '.' symbols");
		f.word.focus();
		return false;
  } */
  else
  {
		var now = new Date();
    var tomarrow = new Date( now.getTime() + (1000 * 60 * 60 * 24) );
		setCookie("thisPage", f.prev.value, tomarrow, "/");

		return true;
  }
}

function getPrevPage(thisPage)
{
	// If the current page is a secured page, we return the last public page;
	// The secured pages all begin with these paths below:
	if (	thisPage.indexOf("/cab2") != -1  ||
				thisPage.indexOf("/admin") != -1 ||
				thisPage.indexOf("/user") != -1)
	{
		// Return the last unsecure page
		return getCookie('thisPage');
	}
	else // Return the current page (as it is unsecure anyways)
	{
		return thisPage;
	}
}

function doLogout()
{
	// The doLogout functions closes any windows.

	var winDocEx = this.clientState.winDocEx;

	// CASE: was opened but was closed; (ACTION): do nothing but return.
	// BUT this code only works if you are on the Console page!
	if (winDocEx != null && winDocEx.closed)
	{
		this.clientState.winDocEx = null;
		delCookie('docex');

		return;
	}

	if (winDocEx == null)
	{
		// CASE: a null handle means it was either never opened OR was opened,
		// but page has changed and the handle becomes null with start of a new page
		// OR window was opened (and cookie set), but window was closed.
		// (ACTION): test for cookie, and if present, then re-acquire handle to close.
		var docex = getCookie('docex');
		if (docex != null && docex == 'true')
		{
			winDocEx = window.open('','docex');
		}
	}

	if (winDocEx != null)
	{
		winDocEx.close();
		this.clientState.winDocEx = null;
		delCookie('docex');
	}

}

/*
function doLogout()
{
	var winDocEx;

	var docex = getCookie("docex");
	alert('cookie: ' + docex);
	if (docex != null && docex == "true")
	{
		alert('docex cookie is present and true!');
		winDocEx = window.open('','docex');
	}


	if (winDocEx != null)
	{
		alert('calling close of winDocEx handle!');
		winDocEx.close();
		delCookie('docex');
		this.clientState.winDocEx = null;
	}

	alert('<returning>');

} */

/////////////////////////////////////////////////////////
// Various functions used for form validation and trim
/////////////////////////////////////////////////////////

// Trim leading and trailing spaces.
function trim(s)
{
  while (s.length > 0 && s.charAt(0) == " ")
		s = s.substring(1, s.length);

  while (s.length > 0 && s.charAt(s.length-1) == " ")
		s = s.substring(0, s.length-1);

  return s;
}

function validEmail(addr)
{
	addr = trim(addr);

	var invalidChars = " /:,;"

	for (i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i);
		if (addr.indexOf(badChar,0) != -1)
		{
			// email addr contains invalid characters
			return false;
		}
	}

	atPos = addr.indexOf("@",1);
	if (atPos == -1)
	{
		// email addr does not conatin '@' symbol
		return false;
	}

	if (addr.indexOf("@",atPos+1) != -1)
	{
	  // email addr contains additional '@' symbol
		return false;
	}

	periodPos = addr.indexOf(".",atPos);
	if (periodPos == -1)
	{
		// email adre does not contain the '.' symbol
		return false;
	}

	if (periodPos+3 > addr.length)
	{
		// email addr domain extension longer than 3 chars
		return false;
	}

	return true;
}

function testEmail(addr)
{
	var isValid = validEmail(addr);
	alert("Email address: " + isValid);
}

function validContact(form)
{
	// Only used by contact.jsp page.

	this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("firstName" , "First Name");
	checkvalid_blank("lastName" , "Last Name");


	checkvalid_ndigits("ph_area" , 3, "Phone Area Code");
	checkvalid_ndigits("ph_prefix" , 3, "Phone Prefix");
	checkvalid_ndigits("ph_suffix" , 4, "Phone Suffix");

	checkvalid_email("Email" , "Email");
	checkvalid_blank("Message" , "Message");

  // All Validation Edits Go Above

	//evaluate results of validation

	if (!valid)
	{
		msg = "_____________________________________\n\n";
		msg += "Your form was not submitted because the\n";
		msg += "following fields have errors or were not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "_____________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
  }

	return valid;
}

function validAddAccount(form)
{
  this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("Association_Name" , "Association Name");
	checkvalid_blank("Association_ID" , "Association ID");
	checkvalid_blank("Tax_ID" , "Tax ID");
	checkvalid_blank("Homeowner_Unit_ID" , "Homewoner Unit/Lot ID");
	checkvalid_blank("Address1" , "Address");
	checkvalid_blank("City" , "City");
	checkvalid_blank("State" , "State");
	checkvalid_blank("Zip" , "Zip Code");

	checkvalid_ndigits("Phone_Area" , 3, "Phone Area Code");
	checkvalid_ndigits("Phone_Prefix" , 3, "Phone Prefix");
	checkvalid_ndigits("Phone_Suffix" , 4, "Phone Suffix");


	if (isRadioChecked(f.Account_Type_Requested, "CertDeposit"))
	{
		checkvalid_blank("CD_Amount" , "CD Amount");
		checkvalid_blank("CD_Term" , "CD Term in months");
	}
	else // else its CertDeposit is NOT requested
	{
		var fields = isFieldNotEmpty("CD_Amount") || isFieldNotEmpty("CD_Term");
		if (fields)
		{
			valid = false;
			focusField = f.elements['CD_Amount'];
			this.fieldList += "Did you mean to open a Certificate of Deposit?\nIf so, please check the appropriate box" + "\n";
		}
	}

	if (isRadioChecked(f.Add_Lockbox, "Yes"))
	{
		checkvalid_blank("Lockbox_Code" , "Lockbox Code");
	}
	else // else its new Lockbox is NOT requested
	{
		var fields = isFieldNotEmpty("Lockbox_Code");
		if (fields)
		{
			valid = false;
			focusField = f.elements['Lockbox_Code'];
			this.fieldList += "Did you mean to add a lockbox?\nIf so, please check the appropriate box" + "\n";
		}
	}


	if (isRadioChecked(f.Open_Source, "FromTransfer"))
	{
		checkvalid_blank("Transfer_Account_Number" , "Account # for Transfer");
	}

	if (isRadioChecked(f.Is_Transition_From_MC, "Yes"))
	{
		checkvalid_blank("Prior_Management_Co" , "Prior Management Company");
	}


	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();

	}

  return valid;
}

function validCloseAccount(form)
{
  this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("Association_Name" , "Association Name");
	checkvalid_blank("Account_Name" , "Account Name");
	checkvalid_blank("Account_Number" , "Account Number");


	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;

}

function validCloseAccountBal(form)
{
  this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("Association_Name" , "Association Name");
	checkvalid_blank("Account_Name" , "Account Name");
	checkvalid_blank("Account_Number" , "Account Number");

	if (isRadioChecked(f.IssueCheck, "Yes"))
	{
		checkvalid_blank("Send_Check_To" , "Address to send Check to");
	}


	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;

}

function validHoldPayment(form)
{
  this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("Association_Name" , "Association Name");
	checkvalid_blank("Association_ID" , "Association ID");
	checkvalid_blank("Homeowner_Name" , "Homeowner's Name");
	checkvalid_blank("Requestor_Name" , "Requestor's Name");
	checkvalid_blank("Homeowner_Unit_ID" , "Homeowner Unit/Lot #");

	checkvalid_ndigits("Phone_Area" , 3, "Phone Area Code");
	checkvalid_ndigits("Phone_Prefix" , 3, "Phone Prefix");
	checkvalid_ndigits("Phone_Suffix" , 4, "Phone Suffix");

	checkradio_blank('Hold_Action', "Hold Action");


	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;

}

function validLockbox(form)
{
  this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("Association_Name" , "Association Name");
	checkvalid_blank("Association_ID" , "Association ID");
	checkvalid_blank("Account_Number" , "Account #");
	checkvalid_blank("Requestor_Name" , "Requestor's Name");
	checkvalid_blank("Homeowner_Unit_ID" , "Homeowner Unit/Lot #");

	checkvalid_ndigits("Phone_Area" , 3, "Phone Area Code");
	checkvalid_ndigits("Phone_Prefix" , 3, "Phone Prefix");
	checkvalid_ndigits("Phone_Suffix" , 4, "Phone Suffix");

	checkboxes_selected("Request_Lockbox", "Request_Deposit", null, null, "Checkboxes (select at least one)");

	//question1
	checkvalid_blank("Research_Needed" , "Describe Research");


	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;

}

function validOrderSupplies(form)
{
  this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("Association_Name" , "Association Name");
	checkvalid_blank("Account_Name" , "Account Name");
	checkvalid_blank("Account_Number" , "Account #");

	checkvalid_ndigits("Phone_Area" , 3, "Phone Area Code");
	checkvalid_ndigits("Phone_Prefix" , 3, "Phone Prefix");
	checkvalid_ndigits("Phone_Suffix" , 4, "Phone Suffix");


	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;

}

function validStopPayment(form)
{
  this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("Association_Name" , "Association Name");
	checkvalid_blank("Account_Name" , "Account Name");
	checkvalid_blank("Account_Number" , "Account #");
	checkvalid_blank("Check_Number" , "Check Number");
	checkvalid_blank("Check_Amount" , "Check Amount");
	checkvalid_blank("Check_Issue_Date" , "Check Issue Date");
	checkvalid_blank("Check_Payee" , "Check Payee");
	checkvalid_blank("Reason" , "Reason");

	if (isRadioChecked(f.Duplicate_Check_Issued, "Yes"))
	{
		checkvalid_blank("Duplicate_Check_Number" , "Duplicate Check Number");
		checkvalid_blank("Duplicate_Check_Date" , "Duplicate Check Date");
	}
	else // else its NOT Yes
		{
			var fields = isFieldNotEmpty("Duplicate_Check_Number") || isFieldNotEmpty("Duplicate_Check_Date");
			if (fields)
			{
				valid = false;
				focusField = f.elements['Duplicate_Check_Number'];
				this.fieldList += "Did you mean to issue a duplicate check?\nIf so, please check the appropriate box" + "\n";
			}
	}



	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;

}

function validTransferFunds(form)
{
  this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	var isFilled = checkvalid_filledRows(f);

	if ( !isFilled)
	{
		this.valid = false;
		fieldList += "The first row must be filled, or partial row is incomplete." + "\n";
	}

	// Check that the subtotals match
	var isMatched = checkvalid_matchTotals(f)

	if ( !isMatched)
	{
		this.valid = false;
		fieldList += "The amounts from debits to credits must match." + "\n";
	}

	if (isFilled && isMatched)
	{
		var hasSkippedRows = checkvalid_skippedRows(f);

		if (hasSkippedRows)
		{
			this.valid = false;
			fieldList += "Rows may not be skipped." + "\n";
		}

	}

	if (isRadioChecked(f.Transfer_Type, "Lockbox_Correction"))
	{
		checkvalid_blank("Lockbox_Date" , "Lockbox Date");
		checkvalid_blank("Lockbox_Check_Number" , "Check Number");
		checkvalid_blank("Lockbox_Description" , "Description");
	}

	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________________________________\n\n";
		msg += "Your request was not submitted because the following fields have errors\n";
		msg += " or were not filled in. Please correct these errors and re-submit.\n\n";
		msg += "__________________________________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;

}


function isRadioChecked(group, attrname)
{
	for (var i = 0; i < group.length; ++i)
	{
		if ( eval("group[" +i+ "].value") == attrname && eval("group[" +i+ "].checked") == true)
		{
			return true;
		}
	}

	return false;
}

function checkvalid_filledRows(f)
{
	// Pattern:
	//from_acct_num1, from_amount1, assoc_name1, to_acct_num1, to_amount1

	var hasOneRow = false;
	for (var i = 0; i < 9; ++i)
	{
		var fieldname1 = "From_Account_Number" + (i+1);
		var fieldname2 = "From_Amount" + (i+1);
		var fieldname3 = "Association_Name" + (i+1);
		var fieldname4 = "To_Account_Number" + (i+1);
		var fieldname5 = "To_Amount" + (i+1);

		var field1 = ( f.elements[fieldname1].value != "" ? true : false);
		var field2 = ( f.elements[fieldname2].value != "" ? true : false);
		var field3 = ( f.elements[fieldname3].value != "" ? true : false);
		var field4 = ( f.elements[fieldname4].value != "" ? true : false);
		var field5 = ( f.elements[fieldname5].value != "" ? true : false);

		var empty1 = ( f.elements[fieldname1].value == "" ? true : false);
		var empty2 = ( f.elements[fieldname2].value == "" ? true : false);
		var empty3 = ( f.elements[fieldname3].value == "" ? true : false);
		var empty4 = ( f.elements[fieldname4].value == "" ? true : false);
		var empty5 = ( f.elements[fieldname5].value == "" ? true : false);

		// RULES TO ENFORCE:
		// a) Must have at least one filled row out of the table, and this MUST be the first row.
		// b) If the first row is filled out, there can be any number of 'legal' partial rows, where the
		//    (pattern) 1,2,3 OR 3,4,5 are filled out only, for any subsequent rows.
		// c) If the first row is filled out, there can be any number of unfilled rows (completely blank)
		//    rows that follow any filled or partially filled rows.


		// TRUE only if all fields in a row are non-empty.
		var filledRow = (field1 && field2 && field3 && field4 && field5);

		// TRUE only if all fields in a row are exactly empty (there is a difference b/t the the two).
		var emptyRow = (empty1 && empty2 && empty3 && empty4 && empty5);

		// TRUE only if we have a legal partial row (where EITHER fields 1,2,3 OR 3,4,5 are filled.
		var partialRow = (	 (field1 && field2 && field3 && empty4 && empty5)
											|| (empty1 && empty2 && field3 && field4 && field5) );


		// Some row tests...
		if (filledRow)
		{
			//: We have at least on filled row; it MUST be the first row, and there can be multiple rows.
			hasOneRow = true;
			continue;
		}
		else if (emptyRow && hasOneRow)
		{
			//: Ignores the additional blank rows.
			continue;
		}
		else if (partialRow)
		{
			if (i == 0 && !filledRow)
			{
				//: The first row MUST be filled, even if it's a legal partial row.
				focusField = f.elements[fieldname1];
				return false;
			}
			else
			{
				//: This is a 'legal' partial row, as it has either 1,2,3 or 3,4,5 pattern.
				continue;
			}
		}
		else // all other abnormalities.
		{
			//: This is an 'illegal' partial row, and we must fail the user at this point.
			focusField = f.elements[fieldname1];
			return false;
		}

	}

	//return true;
	return hasOneRow;
}

function checkvalid_skippedRows(f)
{
	var lastRowEmpty = false;
	for (var i = 0; i < 9; ++i)
	{
		var fieldname1 = "From_Account_Number" + (i+1);
		var fieldname2 = "From_Amount" + (i+1);
		var fieldname3 = "Association_Name" + (i+1);
		var fieldname4 = "To_Account_Number" + (i+1);
		var fieldname5 = "To_Amount" + (i+1);

		var field1 = ( f.elements[fieldname1].value != "" ? true : false);
		var field2 = ( f.elements[fieldname2].value != "" ? true : false);
		var field3 = ( f.elements[fieldname3].value != "" ? true : false);
		var field4 = ( f.elements[fieldname4].value != "" ? true : false);
		var field5 = ( f.elements[fieldname5].value != "" ? true : false);

		var empty1 = ( f.elements[fieldname1].value == "" ? true : false);
		var empty2 = ( f.elements[fieldname2].value == "" ? true : false);
		var empty3 = ( f.elements[fieldname3].value == "" ? true : false);
		var empty4 = ( f.elements[fieldname4].value == "" ? true : false);
		var empty5 = ( f.elements[fieldname5].value == "" ? true : false);

		// TRUE only if all fields in a row are filled.
		var filledRow = (field1 && field2 && field3 && field4 && field5);

		// TRUE only if all fields in a row are empty.
		var allEmpty = (empty1 && empty2 && empty3 && empty4 && empty5);

		// TRUE only if we have a legal partial row (where EITHER fields 1,2,3 OR 3,4,5 are filled.
		var partialRow = ((field1 && field2 && field3 && empty4 && empty5)
    						   || (empty1 && empty2 && field3 && field4 && field5) );

		if (allEmpty)
		{
			lastRowEmpty = true;
			continue;
		}

		if ( (filledRow && lastRowEmpty) || (partialRow && lastRowEmpty) )
		{
			focusField = f.elements[fieldname1];
			return true;
		}

	}

	return false;
}

function checkvalid_matchTotals(f)
{
	var total_debit = f.elements['Total_Debit'].value;
	var total_credit = f.elements['Total_Credit'].value;


	total_debit = trimDollar(total_debit);
	total_credit = trimDollar(total_credit);


	if (total_debit == "" || total_credit == "") return false;


	total_debit = eval(total_debit);
	total_credit = eval(total_credit);

	if ( total_debit == total_credit ) return true;
	else
	{
		focusField = f.elements['Total_Debit'];
		return false;
	}
}

function trimDollar(dollar)
{
	//** IMPORTANT: These values MUST be manipulated as strings
	// and need to be converted to strings first!!!!
	dollar = trim(dollar.toString());
	return dollar.replace(/\$|\,/g,'');
}

function addDebits(form)
{
	var total = 0;
	for (var i = 0; i < 9; ++i)
	{
		var fieldname = trim("From_Amount" + (i+1));
		var amount_str = form.elements[fieldname].value;

		if (amount_str != "")
		{
			amount_str = trimDollar(amount_str);

			var amount = eval(amount_str);

			total += amount;
		}
	}

	form.elements['Total_Debit'].value = formatCurrency(total);
}

function addCredits(form)
{
	var total = 0;
	for (var i = 0; i < 9; ++i)
	{
		var fieldname = trim("To_Amount" + (i+1));
		var amount_str = form.elements[fieldname].value;

		if (amount_str != "")
		{
			amount_str = trimDollar(amount_str);

			var amount = eval(amount_str);

			total += amount;
		}
	}

	form.elements['Total_Credit'].value = formatCurrency(total);
}

function formatCurrency(num)
{
	num = trimDollar(num);

	if(isNaN(num)) num = "0";

	var sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);

	var cents = num%100;
	num = Math.floor(num/100).toString();

	if(cents<10) cents = "0" + cents;

	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	{
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	}

	if (num == "0" && cents == "00") return "";

	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function formatDollar(input)
{
	input.value = trimDollar(input.value);

	var num = filterPosNumber(input);

	if (num == "")
	{
		return ""; // important to set so that addCredit/Debits ignore this value!
	}
	else
	{
		return formatCurrency(num);
	}
}

function filterPosNumber(input)
{
	// Test for negative numers or NaN, and forbid them, before
	// allowing the value to set in the input field. Similar to
	// formatDollar, but doesn't format the number for currency.

	var num = trim(input.value);
	if (num == "") return "";

	// Exclude non-numbers
	if(isNaN(num))
	{
		alert("The value '" + num + "' is not a number!");
		input.value = "";
		focusField = input;
		focusField.focus();
		return "";
	}

	var amount = eval(num);

	// Exclude negative numbers
	var isPosSign = ( amount == Math.abs(amount) );
	if ( !isPosSign)
	{
		alert('You must enter positive values only!');
		input.value = "";
		focusField = input;
		focusField.focus();
		return "";
	}

	return num;
}

function filterNumber(input)
{
	// Test for NaN, and forbid them, before allowing the value to
	// set in the input field. Similar to filterPosNumber except it
	// allows negative numbers.

	var num = trim(input.value);
	if (num == "") return "";

	// Exclude non-numbers
	if(isNaN(num))
	{
		alert("The value '" + num + "' is not a number!");
		input.value = "";
		focusField = input;
		focusField.focus();
		return "";
	}

	return num;
}

function filterCCNumber(input)
{
	// Test for non-standard credit numbers, which may contain
	// spaces and dashes.

	var num = trim(input.value);
	if (num == "") return "";

	var cardnum = num.replace(/\-|\ /g,'');

	// Exclude non-numbers
	if(isNaN(cardnum) || num.indexOf("-") == 0)
	{
		alert("The number '" + num + "' is not a valid card number!");
		input.value = "";
		focusField = input;
		focusField.focus();
		return "";
	}

	return num;
}

function filterFieldMax(input, fieldname, max)
{
	var val = trim(input.value);
	if (val == "") return "";

	if (val.length > max)
	{
		alert("The field '" + fieldname + "' cannot be longer than " + max + " characters.");
		//input.focus();
		input.value = "";
	}

}

function calcCreditCharge(input)
{
	var val = trimDollar(input.value);
	var fee = 0;

	if (val > 0 && val <= 150.00)
		fee = 5.00;
	else if (val >= 150.01 && val <= 300.00)
		fee = 10.00;
	else if (val >= 300.01 && val <= 500.00)
		fee = 15.00;
	else if (val >= 500.01)
		fee = 25.00;

	var amount = eval(val) + eval(fee);

	document.forms[0].elements['Total_Charge'].value = formatCurrency(amount);

}

function calcCheckCharge(input)
{
	var val = trimDollar(input.value);

	var pct = (val * 0.0);	// for now, no charge for e-check
	var amount = eval(val) + eval(pct);

	document.forms[0].elements['Total_Charge'].value = formatCurrency(amount);
}

function calcAptCharge(input)
{
	var val = trimDollar(input.value);
	var fee = 25.00;
	var amount = eval(val) + eval(fee);
	document.forms[0].elements['Total_Charge'].value = formatCurrency(amount);

}

function validCCard(form)
{
	this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("First_Name" , "First Name");
	checkvalid_blank("Last_Name" , "Last Name");
	checkvalid_blank("Billing_Address" , "Billing Address");
	checkvalid_blank("Billing_City" , "Billing City");
	checkvalid_blank("Billing_State" , "Billing State");
	checkvalid_blank("Billing_Zip" , "Billing Zip");

	checkvalid_ndigits("Phone_Area" , 3, "Phone Area Code");
	checkvalid_ndigits("Phone_Prefix" , 3, "Phone Prefix");
	checkvalid_ndigits("Phone_Suffix" , 4, "Phone Suffix");

	checkvalid_email("Email" , "Email Address");

	// mc_id, assoc_id, assoc_name, mc_name, assoc_acct_num, cc_name, cc_amount,
	// cc_type, cc_num, cc_expire_mo, cc_expire_yr

	checkvalid_blank("Management_Company_ID" , "Management Company ID");
	checkvalid_maxchars("Management_Company_ID" , 4, "Management Company ID; no more than 4 characters");
	checkvalid_blank("Association_ID" , "Association ID");
	checkvalid_maxchars("Association_ID" , 6, "Association ID; no more than 6 characters");

	checkvalid_blank("Association_Name" , "Association Name");
	checkvalid_blank("Management_Company" , "Management Company");
	checkvalid_blank("Association_Account_Number" , "Association Account #");

	checkvalid_blank("CC_Name" , "Name on Credit Card");
	checkvalid_alphas("CC_Name" , "Name on Credit Card needs to have alpha characters");
	checkvalid_blank("CC_Amount" , "Payment Amount");
	checkvalid_blank("CC_Number" , "Card Number");



	// If all else is valid, then we proceed to specific credit card validation.
	if (valid)
	{
		var isValidExpires = isValidExpDate(form.CC_Expire_Month, form.CC_Expire_Year);
		if (!isValidExpires)
		{
			this.valid = false;
			fieldList += "Card Expiration Date is inaccurate." + "\n";
		}

		var isCardNumEmpty = (form.CC_Number.value.length == 0 || form.CC_Number.value == "");
		if (isCardNumEmpty)
		{
			this.valid = false;
			fieldList += "Card Number is empty." + "\n";
			focusField = form.CC_Number;
		}

		// Only perform this test if the card number is not empty.
		if (!isCardNumEmpty)
		{
			var isValidCardNum = isValidCreditCardNumber(form.CC_Number, form.CC_Type.value);
			if (!isValidCardNum)
			{
				this.valid = false;
				fieldList += "Card Number is invalid." + "\n";
			}
		}

	}



	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;
}


function validAptCCard(form)
{
	this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("First_Name" , "First Name");
	checkvalid_blank("Last_Name" , "Last Name");
	checkvalid_blank("Billing_Address" , "Billing Address");
	checkvalid_blank("Billing_City" , "Billing City");
	checkvalid_blank("Billing_State" , "Billing State");
	checkvalid_blank("Billing_Zip" , "Billing Zip");

	checkvalid_ndigits("Phone_Area" , 3, "Phone Area Code");
	checkvalid_ndigits("Phone_Prefix" , 3, "Phone Prefix");
	checkvalid_ndigits("Phone_Suffix" , 4, "Phone Suffix");

	checkvalid_email("Email" , "Email Address");

	checkvalid_blank("CC_Name" , "Name on Credit Card");
	checkvalid_alphas("CC_Name" , "Name on Credit Card needs to have alpha characters");
	checkvalid_blank("CC_Amount" , "Payment Amount");
	checkvalid_blank("Apt_Num_Payment" , "Apartment Number to apply payment to");
	checkvalid_blank("CC_Number" , "Card Number");



	// If all else is valid, then we proceed to specific credit card validation.
	if (valid)
	{
		var isValidExpires = isValidExpDate(form.CC_Expire_Month, form.CC_Expire_Year);
		if (!isValidExpires)
		{
			this.valid = false;
			fieldList += "Card Expiration Date is inaccurate." + "\n";
		}

		var isCardNumEmpty = (form.CC_Number.value.length == 0 || form.CC_Number.value == "");
		if (isCardNumEmpty)
		{
			this.valid = false;
			fieldList += "Card Number is empty." + "\n";
			focusField = form.CC_Number;
		}

		// Only perform this test if the card number is not empty.
		if (!isCardNumEmpty)
		{
			var isValidCardNum = isValidCreditCardNumber(form.CC_Number, form.CC_Type.value);
			if (!isValidCardNum)
			{
				this.valid = false;
				fieldList += "Card Number is invalid." + "\n";
			}
		}

	}



	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;
}


function displayYearsAhead(submitted)
{
	if (submitted == false)
	{
		var inputYear = document.forms['form_CreditCard'].CC_Expire_Year;

		for (var i = inputYear.length-1; i > 0; i--)
	      inputYear[i] = null;

	  var size = 8;

		var now = new Date();
		var thisYear = now.getFullYear();

	  for (var j = 0; j < size; j++)
	  {
	  	inputYear[j] = new Option(thisYear+j, thisYear+j);
	  }

  } // end of if submitted == false
}

function currentMonth(submitted)
{
	if (submitted == false)
	{
		var inputYear = document.forms['form_CreditCard'].CC_Expire_Year;
		var inputMonth = document.forms['form_CreditCard'].CC_Expire_Month;

		// Clear out previous contents of month drop down list
		for (var i = inputMonth.length-1; i > 0; i--)
	      inputMonth[i] = null;

		var myindex  = inputYear.selectedIndex;
		var selYear = trim(inputYear.options[myindex].value);

		var now = new Date();
		var thisYear = now.getFullYear();

		if (thisYear == selYear)
		{
			// Create a truncated list of months for the current year,
			// based upon the current month upto the end of this year.

			var thisMonth = now.getMonth();
			for (var i = 0; i < (12-thisMonth); ++i)
			{
				var month_str = "0" + (i+(thisMonth+1));
				if (month_str.length == 3) month_str = month_str.substring(1, month_str.length);

				inputMonth[i] = new Option(month_str, month_str);
			}

			inputMonth.selectedIndex = 0;
		}
		else
		{
			// Just create all 12 months for the given year, as usual.

			for (var i = 0; i < 12; ++i)
			{
				var month_str = "0" + (i+1);
				if (month_str.length == 3) month_str = month_str.substring(1, month_str.length);

				inputMonth[i] = new Option(month_str, month_str);
			}
		}

		//////////////////////////////////////////////////////////////////////////////////////
		// Now dynamically create the years based upon the current year plus 5 years more...

		for (var i = inputYear.length-1; i > 0; i--)
	      inputYear[i] = null;

	  var size = 8;

	  for(var k = 0 ; k < size; ++k)
	  {
	  	inputYear[k] = new Option( (thisYear + k), (thisYear + k));
	  }

	  inputYear.selectedIndex = myindex;

	} // end of if submitted == false

}


function validECheck(form)
{
	this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("First_Name" , "First Name");
	checkvalid_blank("Last_Name" , "Last Name");
	checkvalid_blank("Billing_Address" , "Billing Address");
	checkvalid_blank("Billing_City" , "Billing City");
	checkvalid_blank("Billing_State" , "Billing State");
	checkvalid_blank("Billing_Zip" , "Billing Zip");

	checkvalid_ndigits("Phone_Area" , 3, "Phone Area Code");
	checkvalid_ndigits("Phone_Prefix" , 3, "Phone Prefix");
	checkvalid_ndigits("Phone_Suffix" , 4, "Phone Suffix");

	checkvalid_email("Email" , "Email Address");

	// mc_id, assoc_id, assoc_name, mc_name, assoc_acct_num, ach_name,
	// ach_amount, ach_acct_num, ach_bank_name, ach_routing_num

	checkvalid_blank("Management_Company_ID" , "Management Company ID");
	checkvalid_maxchars("Management_Company_ID" , 4, "Management Company ID; no more than 4 characters");
	checkvalid_blank("Association_ID" , "Association ID");
	checkvalid_maxchars("Association_ID" , 6, "Association ID; no more than 6 characters");

	checkvalid_blank("Association_Name" , "Association Name");
	checkvalid_blank("Management_Company" , "Management Company");
	checkvalid_blank("Association_Account_Number" , "Association Account #");



	checkvalid_blank("ACH_Name" , "Name on Check");
	checkvalid_alphas("ACH_Name" , "Name on Check needs to have alpha characters");
	checkvalid_blank("ACH_Amount" , "Payment Amount");
	checkvalid_blank("ACH_Account_Number" , "Checking Account #");
	checkvalid_blank("ACH_Bank_Name" , "Bank Name");
	checkvalid_blank("ACH_Routing_Number" , "Routing #");

	// If all else is valid, then we proceed to specific ABA Routing number validation.
	if (valid)
	{
		var isValidRoutingNum = isValidABARouting(form.ACH_Routing_Number);
		if (!isValidRoutingNum)
		{
			this.valid = false;
			fieldList += "Check Routing Number is inaccurate." + "\n";
		}
	}


	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;
}

function validAptECheck(form)
{

	this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();

	// All Validation Edits Go Below

	checkvalid_blank("First_Name" , "First Name");
	checkvalid_blank("Last_Name" , "Last Name");


	checkvalid_ndigits("Phone_Area" , 3, "Phone Area Code");
	checkvalid_ndigits("Phone_Prefix" , 3, "Phone Prefix");
	checkvalid_ndigits("Phone_Suffix" , 4, "Phone Suffix");

	checkvalid_email("Email" , "Email Address");

	checkvalid_blank("ACH_Name" , "Name on Check");
	checkvalid_alphas("ACH_Name" , "Name on Check needs to have alpha characters");
	checkvalid_blank("ACH_Amount" , "Payment Amount");
	checkvalid_blank("ACH_Account_Number" , "Checking Account #");
	checkvalid_blank("ACH_Bank_Name" , "Bank Name");
	checkvalid_blank("ACH_Routing_Number" , "Routing #");

	checkvalid_blank("Apt_Num_Payment" , "Apartment Number to apply payment to");


	// If all else is valid, then we proceed to specific ABA Routing number validation.
	if (valid)
	{

		var isValidRoutingNum = isValidABARouting(form.ACH_Routing_Number);
		if (!isValidRoutingNum)
		{
			this.valid = false;
			fieldList += "Check Routing Number is inaccurate." + "\n";
		}
	}


	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;
}

function validLoanApplication(form)
{
	this.f = form;
	this.setAvailableMethods = setAvailableMethods;
	setAvailableMethods();


	// All Validation Edits Go Below

	/*
	var allChecked = checkvalid_allChecked(form);
	if ( !allChecked)
	{
		this.valid = false;
		fieldList += "All Checkboxes must be check to show that all requirements are met.\n";
	}
	*/

	checkvalid_blank("CIC_Name" , "Full Name");
	checkvalid_blank("CIC_Address" , "Address");
	checkvalid_blank("CIC_City" , "City");
	checkvalid_blank("CIC_State" , "State");
	checkvalid_zip("CIC_Zip" , "Zip");
	checkvalid_email("Email" , "Email Address");
	checkvalid_blank("Management_Company" , "Management Company");

	var hasBlanks = checkvalid_anyblank(form);
	if (hasBlanks)
	{
		this.valid = false;
		fieldList += "* All remaining fields of the loan application must be filled out--\nif a field is not applicable, then type N/A.\n";
	}




	// All Validation Edits Go Above

	//evaluate results of validation
	if (!valid)
	{
		msg =  "__________________________________\n\n";
		msg += "Your request was not submitted because\n";
		msg += "the following fields have errors or were\n";
		msg += "not filled in.\n\n";
		msg += "Please correct these errors and re-submit.\n";
		msg += "__________________________________\n\n\n";
		msg += fieldList;

		alert(msg);

		focusField.focus();
	}

  return valid;

}

function checkvalid_allChecked(f)
{
	for (var i = 0; i < 21; i++)
	{
		var fieldname = "checkbox" + (i+1);
		var field = f.elements[fieldname];

		if ( eval("f."+fieldname+".checked") == false)
		{
			focusField = field;
			return false;
		}
	}

	return true;
}

function checkvalid_anyblank(f)
{
	var elements = f.elements;
	var buf = "";
	for (var i = 0; i < elements.length; i++)
	{
		if (f.elements[i].id != null && f.elements[i].id == "tf")
		{
			if (f.elements[i].value =="")
			{
				focusField = f.elements[i];
				return true;
			}
		}
	}

	return false;
}

function onFirstLoad(submitted, form, fieldname)
{
	if (submitted == false)
	{
		setFieldList(form);

		try {

		var input = form.elements[fieldname];
		input.focus();

		// Supply a test to determine if javascript is enabled.
		form.elements['js.enabled'].value = "true";

		if (form.name == "form_Transfer_Funds")
		{
			//alert("inside: " + form.name);
			var input1 = form.Total_Debit;
			var input2 = form.Total_Credit;
			var text1 = form.Total_Debit_Text;
			var text2 = form.Total_Credit_Text;

			input1.style.visibility = 'visible';
			input2.style.visibility = 'visible';
			text1.style.visibility = 'visible';
			text2.style.visibility = 'visible';
		}
		else if (form.name == "form_ECheck" || form.name == "form_CreditCard")
		{
			var input = form.Total_Charge;
			input.style.visibility = 'visible';

			var text = form.Total_Charge_Text;
			text.style.visibility = 'visible';
		}

		}catch(err) { } // just ignore if the fieldname is wrong!

	}

	return true;
}

function setFieldList(form)
{
	var coll = new Array();

	var fieldlist = "";
	for (var i = 0; i < form.elements.length; ++i)
	{
			var fieldname = trim(form.elements[i].name);

			// 1. Filter out spurious fields
			if (fieldname.length == 0
				|| fieldname.indexOf("submit") != -1
				|| fieldname.indexOf("reset") != -1 ) continue;

			// 2. Filter out duplicate field names (mostly for radio buttons)
			var foundDup = false;
			for (var j = 0; j < coll.length; ++j)
			{
				if ( coll[j] == fieldname )
				{
					foundDup = true;
					break;
				}
			}

			if (foundDup) continue;

			// 3. Filter out checkbox* field names from the loan application.
			if (fieldname.indexOf("checkbox") != -1) continue;

			// Otherwise add this fieldname to the fieldlist string
			// and add the fieldname to the array (for testing).
			fieldlist += fieldname + ";";
			coll.push(fieldname);
	}

	//alert("fieldlist: " + fieldlist);

	form.fieldlist.value = fieldlist;
}




/////////////////////////////////////////////////////////
// Various functions used to manipulate Cookies
/////////////////////////////////////////////////////////


function getCookie(name)
{
  var start = document.cookie.indexOf(name + '=');
  var len = start + name.length + 1;
  if ((!start) && (name != document.cookie.substring(0,name.length)))
    return null;
  if (start == -1)
    return null;
  var end = document.cookie.indexOf(';',len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len,end));
}


function setCookie(name, value, expires, path, domain, secure)
{
  document.cookie =
    name + '=' + escape(value) +
    ( (expires) ? ';expires=' + expires.toUTCString() : '') +
    ( (path) ? ';path=' + path : '') +
    ( (domain) ? ';domain=' + domain : '') +
    ( (secure) ? ';secure' : '');

    if (!getCookie(name)) return false;
    else return true;
}

function delCookie(name, path, domain)
{
  if (getCookie(name))
    document.cookie =
      name + '=' +
      ( (path) ? ';path=' + path : '') +
      ( (domain) ? ';domain=' + domain : '') +
      ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
