var Offset = 0;
var strFILoanDetails = '/finder/loan_details.aspx';
var confirmed = -1;
var suppressWarning = false;
var nextTab=-1;
function body_load()
{
	if ((g_fMSIE4 || g_fMSIE5 || g_fMSIE6) && document.all.verticalRule != null) document.all.verticalRule.style.pixelHeight = AbsoluteY(document.all.btnNext) - AbsoluteY(document.all.topMark);
	if (g_fMSIE4 || g_fMSIE5 || g_fMSIE6) Offset = AbsoluteY(document.all.topHelp);
	if (g_fNS7 && document.verticalRule != null) document.verticalRule.height = AbsoluteY(curForm.btnNext) - AbsoluteY(document.FYIImage);
	if (HelpText != null) showContextHelp(0);
}

function resetTabs()
{
	var strMessage
	if (currentTab == 0) {
		strMessage = 'Because you have changed your settings on this tab you will need to answer all questions again. Click OK to continue.';
	} else {
		strMessage = "If you change your settings you may need to answer some additional questions. You won't lose the information you entered, but you'll need to complete Tabs " + (currentTab+1) + " through 6 again. Click OK to continue.";
	}
	if (maxTab > (currentTab+1)) {
		alert(strMessage);
		maxTab = currentTab + 1;
		var a = curForm.action;
		if (a.indexOf("MAXTAB")<0) {
			var a = curForm.action;
			if (a.indexOf("?")>=0) {
				curForm.action = curForm.action + "&MAXTAB=" + maxTab
			} else {
				curForm.action = curForm.action + "?MAXTAB=" + maxTab
			}
		}
	}
}

function refresh(tab)
{
	if (currentTab==tab) return;
	if (!formDirty) {
		location.href = 'finder_' + tab + 'r.html';
	} else {
		suppressWarning = true;
		if (tab == (currentTab+1)) {
			if (maxTab>tab) {
				alert("If you change information, you may have to reenter some data.  Click OK to continue.");
			}
		}
		if (tab > (currentTab+1)) {
			if (confirm("Some data on this tab has been changed and the information on subsequent tabs needs to be verified.\n\nClick OK to continue to tab " + (currentTab+2) + ".  Click Cancel to lose your changes and go to tab " + (tab+1) + ".")==false) {
				location.href = 'finder_' + tab + '.aspx';
				return;
			}
		} 
		if (tab < currentTab) {
			if (curForm.action.indexOf("NEXTTAB")<0) {
				if (curForm.action.indexOf("?")>=0)  {
					curForm.action = curForm.action + "&NEXTTAB=" + tab;
				} else {
					curForm.action = curForm.action + "?NEXTTAB=" + tab;
				}
			}
		}
		nextTab = tab;
		curForm.btnNext.click();
	}
}

function loanSelect(strType, iIndex)
{
	if (iIndex == null || strType == "") return;
	switch (strType) {
	case "Detail":
		window.location = "/finder/loan_details.aspx?LI=" + iIndex;
		break;
	case "Apply":
		window.location = "/finder/apply_lock.aspx?LI=" + iIndex;
		break;
	case "Lock":
		window.location = "/finder/apply_lock.aspx?LI=" + iIndex;
		break;
	case "Letter":
		window.location = "/finder/letter.aspx";
	}
}

function doButtonOut(elem, lTabNum)
{
	var n;
	if (lTabNum == currentTab) return;
	elem.children[0].style.color = '';
	elem.children[1].children[0].style.color = '';
}

function doButtonOver(elem, lTabNum)
{
	var n;
	if (lTabNum == currentTab) return;
	elem.children[0].style.color = '#FFFFFF';
	elem.children[1].children[0].style.color = '#FFFFFF';
}

function validateForm(vRules, elemName)
{
	if (vRules == null) return true;

	// vRules format
	var fieldName	   = 0;	// HTML input control name
	var valRule		   = 1;	// Validation rule
	var errorMessage   = 2;	// UE error message
	var errorAction    = 3;	// Browser error action


	var showAlert = true;
	if (elemName == 'xx') {
		showAlert = false;
		elemName = null;
	}
	
	var n;
	for (n=0; n < vRules.length; n++) {
		if (elemName == null || elemName == vRules[n][fieldName]) {
			if (eval(vRules[n][valRule])) {
				if (showAlert) alert(vRules[n][errorMessage]);
				if (vRules[n][errorAction] != null) eval(vRules[n][errorAction])
				cancelEvent();
				return false;
			}
		}
	}	
	//alert("Form Validated");
	resetTabs();
	return true;
}

function cancelEvent()
{
	event.cancelBubble = true;
	event.returnValue = false;
}

function showWorksheet(type, retURL)
{
    strURL = 'worksheet_' + type + '.aspx?url=' + retURL;   
    window.location.href = strURL;
}


function validateSubmit(curForm)
{
		if (vFormValidate != null) {
			return validateForm(vFormValidate);
		} else {
			if (maxTab>(currentTab+1)) {
				alert("If you change information, you may have to reenter some data.  Click OK to continue.");
			}
			return true;
		}
}

function formSubmit(curForm)
{
		if ((suppressWarning==false) && (maxTab>(currentTab+1))) {
			alert("If you change information, you may have to reenter some data.  Click OK to continue.");
		}
}


