﻿// Defeasance Specific Javascript


// Since the defeasance calculator can be on different pages, the control sets this id
// so we can determine the names of the controls on the page.
// by setting this variable we don't have to pass it in on every function call, and the
// AddLoadEvent method will work

//addLoadEvent(resizeDefeasanceVeil);
var calculatorControlId;

function showEmail()
{
    var resultsDiv = document.getElementById('RatesTimeTable');
    var x = getAbsoluteLeft(resultsDiv) + 'px';
    var y = getAbsoluteTop(resultsDiv) + 'px';
    var emailTable = document.getElementById(calculatorControlId + '_MailTable');
    emailTable.style.display = 'block';
    emailTable.style.top = y;
    emailTable.style.left = x;
    var emailTextBox = document.getElementById(calculatorControlId + '_EmailTextBox');
    if (emailTextBox != null)
    {
        emailTextBox.focus();
    }
    return false;
    
}

function hideEmail()
{
    hideElement(calculatorControlId + '_MailTable');
    return false;
}

function setDefeasanceLoanType()
{
	// Close any help bubbles (see ClientControls.js) in Chatham.Web
	closeOpenHelp();
	
    var interestOnlyLoanRadio = document.getElementById(calculatorControlId + '_InterestOnlyRadio');
    var combinationLoanRadio = document.getElementById(calculatorControlId + '_CombinationRadio');
    
   	var isAmortizing;
	isAmortizing = (!interestOnlyLoanRadio.checked );
	var isCombination;
	isCombination = (combinationLoanRadio.checked );

	hideShowElement("EndOfInterestOnlyRow", isCombination, true);
	hideShowElement("AmortizationRow", isAmortizing, true);
	var amortizingReqVal = document.getElementById(calculatorControlId + "_AmortizationRequiredFieldValidator")
	amortizingReqVal.enabled = isAmortizing;
    var amortizingRangeVal = document.getElementById(calculatorControlId + "_AmortizationRangeValidator")
    amortizingRangeVal.enabled = isAmortizing;
    var intOnlyReqVal = document.getElementById(calculatorControlId + "_EndInterestOnlyPeriodValidator");
    intOnlyReqVal.enabled = isCombination;
    var intOnlyPreceedVal = document.getElementById(calculatorControlId + "_EndInterestOnlyPeriodPreceedValidator");
	intOnlyPreceedVal.enabled = isCombination;
	var intOnlyDayMonthVal = document.getElementById(calculatorControlId + "_EndInterestOnlyPeriodDayOfMonthValidator");
	intOnlyDayMonthVal.enabled = isCombination;

}

function resizeDefeasanceVeil()
{
    var resultsDiv = document.getElementById(calculatorControlId + '_ShowResultsTextDiv');
    var veilDiv = document.getElementById(calculatorControlId + '_VeilDiv');
    var x = getAbsoluteLeft(resultsDiv) + 'px';
    var y = getAbsoluteTop(resultsDiv) + 'px';
    veilDiv.style.top = y;
    veilDiv.style.left = x;
    veilDiv.style.width = resultsDiv.offsetWidth  + 'px';
    veilDiv.style.height = resultsDiv.offsetHeight  + 'px';
   

}

