	function propInit(){
		if(counterSize == 0){
			return;
		}
		calculatePropertyValue();
		calculateTotalMortgageAmount();
		calculateTotalMortgagePayment();
		calculateTotalExpense();
    calculateTotalRentalIncome();
		calculateTotalRentalExpense();
    updatePayoffTypes();

	}
    
	function rentalCalc(prefix){
	  if(prefix != null){
        var str = prefix.substring(prefix.indexOf("_") + 1, prefix.length);
        str = parseInt(str);
		var theTotal = calculateTotalRentalExpenseElements("PropExp_",str);
		//eval("document.forms[0]." + prefix + "totalExpenseForBorrowerProperty").value='$ ' + formatNumericValues(round_decimals(theTotal, 2),"")
		var propertyName = prefix + "totalExpenseForBorrowerProperty";
		Format_UpdateContent(propertyName, "" + theTotal);
	  }
	}

	function calculatePropertyValue(){
		Format_UpdateContent("txtTotalPropertyValue", "" + calculateTotals("op", "propertyValue"));
      //document.forms[0].txtTotalPropertyValue.value = "$" + formatNumericValues(round_decimals(calculateTotals("op", "propertyValue"), 2),",");

  }

	function calculateTotalMortgageAmount(){
		Format_UpdateContent("txtTotalMortgageAmount", "" + calculateTotals("mop","balanceRemaining"));
    //document.forms[0].txtTotalMortgageAmount.value = "$" + formatNumericValues(round_decimals(calculateTotals("mop","balanceRemaining"), 2),",");

  }

	function calculateTotalMortgagePayment(){
		Format_UpdateContent("txtTotalMortgagePayment", "" + calculateTotals("mop","piPaymentAmountMonthly"));
     //document.forms[0].txtTotalMortgagePayment.value = "$" + formatNumericValues(round_decimals(calculateTotals("mop","piPaymentAmountMonthly"), 2),",");

  }

	function calculateTotalRentalIncome(){
		//var totalRentalIncome = calculateTotals("opi","incomeAmount");
    	//document.forms[0].txtTotalRentalIncome.value = "$" + formatNumericValues(round_decimals(totalRentalIncome, 2),",");
    	
    	Format_UpdateContent("txtTotalRentalIncome", "" + calculateTotals("opi","incomeAmount"));
	}

	function calculateTotalExpense(){
		var totalExpenses = 0;
		var elementPrefix = "PropExp_";
		for(i=1; i <= counterSize; i++){
			totalExpenses += calculateTotalExpenseElements(elementPrefix, i);
		}
    	
    	Format_UpdateContent("txtTotalExpense", "" + totalExpenses);
    	//document.forms[0].txtTotalExpense.value = "$" + formatNumericValues(round_decimals(totalExpenses, 2),",");
	}

	function calculateTotalRentalExpense(){
		var totalRentalExpenses = 0;
		var elementPrefix = "PropExp_";
		for(i=1; i <= counterSize; i++){
			totalRentalExpenses += calculateTotalRentalExpenseElements(elementPrefix, i);
		}
     
     	Format_UpdateContent("txtTotalRentalExpense", "" + totalRentalExpenses);
     	//document.forms[0].txtTotalRentalExpense.value = "$" + formatNumericValues(round_decimals(totalRentalExpenses, 2),",");
	}

	function calculateTotalExpenseElements(elementPrefix, i){
		var totalRenExp = 0;
		totalRenExp += parseFloat(calculateRentalExpenseValue(elementPrefix, i,"annualTaxes")) / 12;
		totalRenExp += parseFloat(calculateRentalExpenseValue(elementPrefix, i,"monthlyCondoFees"));
		totalRenExp += parseFloat(calculateRentalExpenseValue(elementPrefix, i,"monthlyHeating"));

		return totalRenExp;
	}

	function calculateTotalRentalExpenseElements(elementPrefix, i){
		var totalRenExp = 0;
		totalRenExp += parseFloat(calculateRentalExpenseValue(elementPrefix, i,"insuranceExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue(elementPrefix, i,"hydroExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue(elementPrefix, i,"managementExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue(elementPrefix, i,"repairExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue(elementPrefix, i,"interestExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue(elementPrefix, i,"generalExpense"));

		/*
		totalRenExp += parseFloat(calculateRentalExpenseValue("hf"+elementPrefix, i,"insuranceExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue("hf"+elementPrefix, i,"hydroExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue("hf"+elementPrefix, i,"managementExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue("hf"+elementPrefix, i,"repairExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue("hf"+elementPrefix, i,"interestExpense"));
		totalRenExp += parseFloat(calculateRentalExpenseValue("hf"+elementPrefix, i,"generalExpense"));
		*/
		return totalRenExp;
	}


	function calculateRentalExpenseValue(elementPrefix, i, name){

		var tempValue = eval("document.forms[0]." + elementPrefix + i + "_" + name + ".value");
		if(tempValue == null || isNaN(tempValue) || tempValue==""){
			tempValue = 0;
		}
		return tempValue;
	}

	function calculateTotals(elementPrefix, name ){
		var tempTotal = 0;
	    for(i=1; i <= counterSize; i++){
      var refString = "";
      if (elementPrefix == "mop"){
        for(var f = 0; f <= document.forms[0].elements.length; f++){
          if (document.forms[0].elements[f] && document.forms[0].elements[f].name && document.forms[0].elements[f].name.indexOf("mop_"+i) != -1 && document.forms[0].elements[f].name.indexOf(name) != -1 && document.forms[0].elements[f].name.indexOf("FORMATTER") == -1){
            refString = "document.forms[0]." + document.forms[0].elements[f].name;
             if(refString != "" && eval(refString)){
               var refValue = parseFloat(eval(refString).value);
               //if this value is a number, add it to the total
               if(!isNaN(refValue)){
                 tempTotal += refValue;
               }
             }
          }
        }
      }
			else{
        refString = "document.forms[0]." + elementPrefix + "_" + i + "_" + name;

        if(refString != "" && eval(refString)){
          var refValue = parseFloat(eval(refString).value);
          //if this value is a number, add it to the total
          if(!isNaN(refValue)){
            tempTotal += refValue;
          }
        }
      }
		}
		return formatNumericValues(round_decimals(tempTotal, 2),"");
	}

  /*
      0 = 1 | Monthly = val * 1
      1 = 2 | Semi Monthly = val * 2
      2 = 3 | Biweekly = val * 26 / 12
      3 = 4 | Accelerated Biweekly = val * 26 / 12
      4 = 5 | Weekly = val * 52 / 12
      5 = 6 | Accelerated Weekly = val * 52 / 12
      6 = 0 |
  */
  function calcMonthlyPayment(paymentField, frequencyField, hiddenField) {
    var result = 0.00;
    var payment = 0.00;
    if (!isNaN(parseFloat(paymentField.value))){
      payment = parseFloat(paymentField.value);
    }
    else{
      hiddenField.value = result;
      return;
    }
    switch(parseInt(frequencyField.options[frequencyField.selectedIndex].value)) {
      case 0: //Monthly
        result = payment;
        break;

      case 1: //Semi Monthly
        result = payment * 2.0;
        break;

      case 2: //Biweekly
        result = payment * 26.0 / 12.0;
        break;

      case 3: //Accelerated Biweekly
        result = payment * 26.0 / 12.0;
        break;

      case 4: //Weekly
        result = payment * 52.0 / 12.0;
        break;

      case 5: //Accelerated Weekly
        result = payment * 52.0 / 12.0;
        break;

      default: //default
        result = 0;
        break;
    }
    hiddenField.value = result;
  }

   /*
	*	When ?Rental Offset? = 0 (None) or 2 (Reduce expenses)
	*	Income.inc_include_in_gds = ?N?
	*	Income.inc_include_in_tds = ?N?
	*		Else
	*	Income.inc_include_in_gds = ?Y?
	*	Income.inc_include_in_tds = ?Y?
	*/
function updateOffset(element, theIncomePrefix){

	var theForm = 'document.forms[0].';

	if(element.options[element.selectedIndex].value == 0){

		//eval(theForm + "hf"+ theIncomePrefix + '_incPercentInGds').value='';
		//Format_UpdateContent("hf"+ theIncomePrefix + "_incPercentInGds", "");

      	if(eval(theForm + "hf"+ theIncomePrefix + '_incPercentInGds')){
        	eval(theForm + "hf"+ theIncomePrefix + '_incPercentInGds').disabled = true;
        	Format_UpdateContent("hf"+ theIncomePrefix + "_incPercentInGds", "");
        	Format_EnableControl(eval("hf"+ theIncomePrefix + "_incPercentInGds").name, false);
      	}
      	if(eval(theForm + "hf"+ theIncomePrefix + '_incPercentInTds')){
        	eval(theForm + "hf"+ theIncomePrefix + '_incPercentInTds').disabled = true;
        	Format_UpdateContent("hf"+ theIncomePrefix + "_incPercentInTds", "");
        	Format_EnableControl("hf"+ theIncomePrefix + "_incPercentInTds", false);
      	}
		eval(theForm + theIncomePrefix + '_incIncludeInGds').value="N"
		eval(theForm + theIncomePrefix + '_incIncludeInTds').value="N"

	}
    else if (element.options[element.selectedIndex].value == 1 || element.options[element.selectedIndex].value == 2) {
      if(eval(theForm + "hf"+ theIncomePrefix + '_incPercentInGds')){
        eval(theForm + "hf"+ theIncomePrefix + '_incPercentInGds').disabled = false;
      }
      if(eval(theForm + "hf"+ theIncomePrefix + '_incPercentInTds')){
        eval(theForm + "hf"+ theIncomePrefix + '_incPercentInTds').disabled = false;
      }
			eval(theForm + theIncomePrefix + '_incIncludeInGds').value="N"
			eval(theForm + theIncomePrefix + '_incIncludeInTds').value="Y"
		}
	}

function revertAddressCheck(element){
  var frmName = element.name;
  var str = frmName.substring(frmName.indexOf("_") + 1, frmName.length);
  str = str.substring(0, str.indexOf("_"));
  str = parseInt(str);

  var fm = document.forms[0];

  if (eval("fm.X_op_"+str+"_occupancyPreviousValue.value == 0 && fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value != '0'")){
    eval ( "fm.op_" + str + "_countryTypeDd.selectedIndex = fm.hidden_op_" + str + "_countryTypeDd.value");
    eval ( "fm.op_" + str + "_unitNumber.value = fm.hidden_op_" + str + "_unitNumber.value");
    eval ( "fm.op_" + str + "_propertyStreetNumber.value = fm.hidden_op_" + str + "_propertyStreetNumber.value");
    eval ( "fm.op_" + str + "_propertyStreetName.value = fm.hidden_op_" + str + "_propertyStreetName.value");
    eval ( "fm.op_" + str + "_streetTypeDd.selectedIndex = fm.hidden_op_" + str + "_streetTypeDd.value");
    eval ( "fm.op_" + str + "_streetDirectionDd.selectedIndex = fm.hidden_op_" + str + "_streetDirectionDd.value");
    eval ( "fm.op_" + str + "_propertyCity.value = fm.hidden_op_" + str + "_propertyCity.value");
    eval ( "fm.op_" + str + "_provinceDd.selectedIndex = fm.hidden_op_" + str + "_provinceDd.value");
    eval ( "fm.op_" + str + "_propertyPostalFsa.value = fm.hidden_op_" + str + "_propertyPostalFsa.value");
    eval ( "fm.op_" + str + "_propertyPostalLdu.value = fm.hidden_op_" + str + "_propertyPostalLdu.value");
  }
  else if (eval("fm.X_op_"+str+"_occupancyPreviousValue.value != 0 && fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value == '0'")){
    eval ( "fm.hidden_op_" + str + "_countryTypeDd.value = fm.op_" + str + "_countryTypeDd.selectedIndex");
    eval ( "fm.hidden_op_" + str + "_unitNumber.value = fm.op_" + str + "_unitNumber.value");
    eval ( "fm.hidden_op_" + str + "_propertyStreetNumber.value = fm.op_" + str + "_propertyStreetNumber.value");
    eval ( "fm.hidden_op_" + str + "_propertyStreetName.value = fm.op_" + str + "_propertyStreetName.value");
    eval ( "fm.hidden_op_" + str + "_streetTypeDd.value = fm.op_" + str + "_streetTypeDd.selectedIndex");
    eval ( "fm.hidden_op_" + str + "_streetDirectionDd.value = fm.op_" + str + "_streetDirectionDd.selectedIndex");
    eval ( "fm.hidden_op_" + str + "_propertyCity.value = fm.op_" + str + "_propertyCity.value");
    eval ( "fm.hidden_op_" + str + "_provinceDd.value = fm.op_" + str + "_provinceDd.selectedIndex");
    eval ( "fm.hidden_op_" + str + "_propertyPostalFsa.value = fm.op_" + str + "_propertyPostalFsa.value");
    eval ( "fm.hidden_op_" + str + "_propertyPostalLdu.value = fm.op_" + str + "_propertyPostalLdu.value");

  }
}

function updateMonthlyTaxes(element){

  var frmName = element.name;
  var str = frmName.substring(frmName.indexOf("_") + 1, frmName.length);
  str = str.substring(str.indexOf("PropExp_")+1, str.indexOf("PropExp_")+2);
  str = parseInt(str);

  if(element.value && parseFloat(element.value) > 0){
    eval("document.forms[0].temp_PropExp_" + str + "_monthlyTaxes").value = Format_Decimal("" + parseFloat(element.value) / 12.00, 2);
  }
}

function secondHomeCheck(finishedLoadingCheck, element){

  var frmName = element.name;
  var str = frmName.substring(frmName.indexOf("_") + 1, frmName.length);
  str = str.substring(0, str.indexOf("_"));
  str = parseInt(str);

  var fm = document.forms[0];

  //If the occupany is change to second home and they have existing rental information, handle below.
  if (eval("fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value == '3'") || eval("fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value == '0'") || eval("fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value == '-1'")){
    if((ltrim(rtrim(eval("fm.opi_"+ str + "_incomeAmount.value"))) != "" && parseFloat(eval("fm.opi_"+ str + "_incomeAmount.value")) > 0.00) ||
    eval("fm.hfop_"+ str + "_rentalOffsetOption.selectedIndex != 0") ||
    (eval("fm.opi_"+ str + "_incPercentInTds") && ltrim(rtrim(eval("fm.opi_"+ str + "_incPercentInTds").value)) != "" && parseFloat(eval("fm.opi_"+ str + "_incPercentInTds").value) > 0.00) ||
    (eval("fm.opi_"+ str + "_incPercentInGds") && ltrim(rtrim(eval("fm.opi_"+ str + "_incPercentInGds").value)) != "" && parseFloat(eval("fm.opi_"+ str + "_incPercentInGds").value) > 0.00) ||
    ltrim(rtrim(eval("fm.PropExp_" + str + "_insuranceExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.PropExp_" + str + "_hydroExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.PropExp_" + str + "_managementExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.PropExp_" + str + "_repairExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.PropExp_" + str + "_interestExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.PropExp_" + str + "_generalExpense").value)) != ""){
      var message = "";
      if(finishedLoadingCheck){
        message = "Any data in the rental income and rental expense fields will be deleted for a Second Home occupancy type. If you would like to proceed, select 'OK', otherwise select 'Cancel'.";

      }
      else{
        message = "You are changing the 'Occupancy' pick-list to either 'Second Home' or a value other then one with that contains the word 'Rental'. Any data in the 'Rental Income' and 'Rental' expense fields will be deleted. If you would like to proceed, select 'OK', otherwise select 'Cancel'.";
      }

      if(confirm(message)){
        propertyInfoRetained[str - 1] = new propertyRentalInfo("op_"+str);

        Format_UpdateContent(eval("fm.opi_"+ str + "_incomeAmount").name, "");
        Format_EnableControl(eval("fm.opi_"+ str + "_incomeAmount").name, false);
        //eval("fm.opi_"+ str + "_incomeAmount").value = "";
        //eval("fm.opi_"+ str + "_incomeAmount").disabled=true;


        eval("fm.hfop_"+ str + "_rentalOffsetOption").selectedIndex = 0 ;
        eval("fm.hfop_"+ str + "_rentalOffsetOption").disabled=true;

        if(eval("fm.hfopi_"+ str + '_incPercentInGds')){
            eval("fm.hfopi_"+ str + '_incPercentInGds').disabled = true;
             eval("fm.hfopi_"+ str + '_incPercentInGds').value ='';
        }
        if(eval("fm.hfopi_"+ str + '_incPercentInTds')){
          eval("fm.hfopi_"+ str + '_incPercentInTds').disabled = true;
          eval("fm.hfopi_"+ str + '_incPercentInTds').value = '';
        }



        Format_UpdateContent(eval("fm.PropExp_" + str + "_insuranceExpense").name, "");
        Format_EnableControl(eval("fm.PropExp_" + str + "_insuranceExpense").name, false);
        //eval("fm.PropExp_" + str + "_insuranceExpense").value = "";
        //eval("fm.PropExp_" + str + "_insuranceExpense").disabled=true;

        Format_UpdateContent(eval("fm.PropExp_" + str + "_hydroExpense").name, "");
        Format_EnableControl(eval("fm.PropExp_" + str + "_hydroExpense").name, false);
        //eval("fm.PropExp_" + str + "_hydroExpense").value = "";
        //eval("fm.PropExp_" + str + "_hydroExpense").disabled=true;

		    Format_UpdateContent(eval("fm.PropExp_" + str + "_managementExpense").name, "");
		    Format_EnableControl(eval("fm.PropExp_" + str + "_managementExpense").name, false);
        //eval("fm.PropExp_" + str + "_managementExpense").value = "";
        //eval("fm.PropExp_" + str + "_managementExpense").disabled=true;

		    Format_UpdateContent(eval("fm.PropExp_" + str + "_repairExpense").name, "");
        Format_EnableControl(eval("fm.PropExp_" + str + "_repairExpense").name, false);
        //eval("fm.PropExp_" + str + "_repairExpense").value = "";
        //eval("fm.PropExp_" + str + "_repairExpense").disabled=true;

        Format_UpdateContent(eval("fm.PropExp_" + str + "_interestExpense").name, "");
        Format_EnableControl(eval("fm.PropExp_" + str + "_interestExpense").name, false);
        //eval("fm.PropExp_" + str + "_interestExpense").value = "";
        //eval("fm.PropExp_" + str + "_interestExpense").disabled=true;

        Format_UpdateContent(eval("fm.PropExp_" + str + "_generalExpense").name,"");
        Format_EnableControl(eval("fm.PropExp_" + str + "_generalExpense").name, false);
        //eval("fm.PropExp_" + str + "_generalExpense").value = "";
        //eval("fm.PropExp_" + str + "_generalExpense").disabled=true;
      }
      else{
        eval("handleSelectFields(fm.op_"+str+"_occupancyTypeDd, fm.X_op_"+str+"_occupancyPreviousValue.value)");
      }
    }
    else{
      //eval("fm.opi_"+ str + "_incomeAmount").disabled=true;
      //eval("fm.hfop_"+ str + "_rentalOffsetOption").disabled=true;
      //eval("fm.opi_"+ str + "_incPercentInTds").disabled=true;
      //eval("fm.PropExp_" + str + "_insuranceExpense").disabled=true;
      //eval("fm.PropExp_" + str + "_hydroExpense").disabled=true;
      //eval("fm.PropExp_" + str + "_managementExpense").disabled=true;
      //eval("fm.PropExp_" + str + "_repairExpense").disabled=true;
      //eval("fm.PropExp_" + str + "_interestExpense").disabled=true;
      //eval("fm.PropExp_" + str + "_generalExpense").disabled=true;

      Format_EnableControl(eval("fm.opi_"+ str + "_incomeAmount").name, false);
      eval("fm.hfop_"+ str + "_rentalOffsetOption").disabled=true;
      Format_EnableControl(eval("fm.opi_"+ str + "_incPercentInTds").name, false);
      Format_EnableControl(eval("fm.opi_"+ str + "_incPercentInGds").name, false);
      Format_EnableControl(eval("fm.PropExp_" + str + "_insuranceExpense").name, false);
      Format_EnableControl(eval("fm.PropExp_" + str + "_hydroExpense").name, false);
      Format_EnableControl(eval("fm.PropExp_" + str + "_managementExpense").name, false);
      Format_EnableControl(eval("fm.PropExp_" + str + "_repairExpense").name, false);
      Format_EnableControl(eval("fm.PropExp_" + str + "_interestExpense").name, false);
      Format_EnableControl(eval("fm.PropExp_" + str + "_generalExpense").name, false);
			if(eval("fm.hfopi_"+ str + '_incPercentInGds')){
        eval("fm.hfopi_"+ str + '_incPercentInGds').disabled = true;
			}
      if(eval("fm.hfopi_"+ str + '_incPercentInTds')){
        eval("fm.hfopi_"+ str + '_incPercentInTds').disabled = true;
			}
    }
  }

  //If you are leaving the second home to go to another occupancy re-enable the fields
  if(eval("(fm.X_op_"+str+"_occupancyPreviousValue.value == -1 || fm.X_op_"+str+"_occupancyPreviousValue.value == 0 || fm.X_op_"+str+"_occupancyPreviousValue.value == 3) && fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value != '-1' && fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value != '0' && fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value != '3'")){

    Format_EnableControl(eval("fm.opi_"+ str + "_incomeAmount").name, true);
    eval("fm.hfop_"+ str + "_rentalOffsetOption").disabled=false;
    Format_EnableControl(eval("fm.PropExp_" + str + "_insuranceExpense").name, true);
    Format_EnableControl(eval("fm.PropExp_" + str + "_hydroExpense").name, true);
    Format_EnableControl(eval("fm.PropExp_" + str + "_managementExpense").name, true);
    Format_EnableControl(eval("fm.PropExp_" + str + "_repairExpense").name, true);
    Format_EnableControl(eval("fm.PropExp_" + str + "_interestExpense").name, true);
    Format_EnableControl(eval("fm.PropExp_" + str + "_generalExpense").name, true);
    Format_EnableControl(eval("fm.opi_"+ str + "_incPercentInTds").name, true);
    Format_EnableControl(eval("fm.opi_"+ str + "_incPercentInGds").name, true);
    //eval("fm.opi_"+ str + "_incomeAmount").disabled=false;
    //eval("fm.hfop_"+ str + "_rentalOffsetOption").disabled=false;
    //eval("fm.PropExp_" + str + "_insuranceExpense").disabled=false;
    //eval("fm.PropExp_" + str + "_hydroExpense").disabled=false;
    //eval("fm.PropExp_" + str + "_managementExpense").disabled=false;
    //eval("fm.PropExp_" + str + "_repairExpense").disabled=false;
    //eval("fm.PropExp_" + str + "_interestExpense").disabled=false;
    //eval("fm.PropExp_" + str + "_generalExpense").disabled=false;
    if(propertyInfoRetained != null && propertyInfoRetained[str - 1]!=null){
      repopulateRentalValues(propertyInfoRetained[str - 1],"op_"+str);
    }

    if(eval("fm.hfop_"+ str + "_rentalOffsetOption").options[eval("fm.hfop_"+ str + "_rentalOffsetOption").selectedIndex].value != 0){
      if(eval("fm.hfopi"+ str + '_incPercentInGds')){
        eval("fm.hfopi"+ str + '_incPercentInGds').disabled = false;
			}
      if(eval("fm.hfopi"+ str + '_incPercentInTds')){
        eval("fm.hfopi"+ str + '_incPercentInTds').disabled = false;
			}
    }
  }

  eval("fm.X_op_"+str+"_occupancyPreviousValue.value = fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value");

  /*
  if (eval("fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value == '3'") || eval("fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value == '0'") || eval("fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value == '-1'")){
    if((ltrim(rtrim(eval("fm.hfopi_"+ str + "_incomeAmount.value"))) != "" && parseFloat(eval("fm.hfopi_"+ str + "_incomeAmount.value")) > 0.00) ||
    eval("fm.hfop_"+ str + "_rentalOffsetOption.selectedIndex != 0") ||
    (ltrim(rtrim(eval("fm.hfopi_"+ str + "_incPercentInTds").value)) != "" && parseFloat(eval("fm.hfopi_"+ str + "_incPercentInTds").value) > 0.00) ||
    ltrim(rtrim(eval("fm.hfPropExp_" + str + "_insuranceExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.hfPropExp_" + str + "_hydroExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.hfPropExp_" + str + "_managementExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.hfPropExp_" + str + "_repairExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.hfPropExp_" + str + "_interestExpense").value)) != "" ||
    ltrim(rtrim(eval("fm.hfPropExp_" + str + "_generalExpense").value)) != ""){
      var message = "";
      if(finishedLoadingCheck){
        message = "Any data in the rental income and rental expense fields will be deleted for a Second Home occupancy type. If you would like to proceed, select 'OK', otherwise select 'Cancel'.";

      }
      else{
        message = "You are changing the 'Occupancy' pick-list to either 'Second Home' or a value other then one with that contains the word 'Rental'. Any data in the 'Rental Income' and 'Rental' expense fields will be deleted. If you would like to proceed, select 'OK', otherwise select 'Cancel'.";
      }

      if(confirm(message)){
        propertyInfoRetained[str - 1] = new propertyRentalInfo("op_"+str);

        eval("fm.hfopi_"+ str + "_incomeAmount").value = "";
        eval("fm.hfopi_"+ str + "_incomeAmount").disabled=true;

        eval("fm.hfop_"+ str + "_rentalOffsetOption").selectedIndex = 0 ;
        eval("fm.hfop_"+ str + "_rentalOffsetOption").disabled=true;

        eval("fm.hfopi_"+ str + "_incPercentInTds").value = "";
        eval("fm.hfopi_"+ str + "_incPercentInTds").disabled=true;

        eval("fm.hfPropExp_" + str + "_insuranceExpense").value = "";
        eval("fm.hfPropExp_" + str + "_insuranceExpense").disabled=true;

        eval("fm.hfPropExp_" + str + "_hydroExpense").value = "";
        eval("fm.hfPropExp_" + str + "_hydroExpense").disabled=true;

        eval("fm.hfPropExp_" + str + "_managementExpense").value = "";
        eval("fm.hfPropExp_" + str + "_managementExpense").disabled=true;

        eval("fm.hfPropExp_" + str + "_repairExpense").value = "";
        eval("fm.hfPropExp_" + str + "_repairExpense").disabled=true;

        eval("fm.hfPropExp_" + str + "_interestExpense").value = "";
        eval("fm.hfPropExp_" + str + "_interestExpense").disabled=true;

        eval("fm.hfPropExp_" + str + "_generalExpense").value = "";
        eval("fm.hfPropExp_" + str + "_generalExpense").disabled=true;

      }
      else{
        eval("handleSelectFields(fm.op_"+str+"_occupancyTypeDd, fm.X_op_"+str+"_occupancyPreviousValue.value)");
      }
    }
    else{
      eval("fm.hfopi_"+ str + "_incomeAmount").disabled=true;
      eval("fm.hfop_"+ str + "_rentalOffsetOption").disabled=true;
      eval("fm.hfopi_"+ str + "_incPercentInTds").disabled=true;
      eval("fm.hfPropExp_" + str + "_insuranceExpense").disabled=true;
      eval("fm.hfPropExp_" + str + "_hydroExpense").disabled=true;
      eval("fm.hfPropExp_" + str + "_managementExpense").disabled=true;
      eval("fm.hfPropExp_" + str + "_repairExpense").disabled=true;
      eval("fm.hfPropExp_" + str + "_interestExpense").disabled=true;
      eval("fm.hfPropExp_" + str + "_generalExpense").disabled=true;
    }
  }

  //If you are leaving the second home to go to another occupancy re-enable the fields
  if(eval("(fm.X_op_"+str+"_occupancyPreviousValue.value == -1 || fm.X_op_"+str+"_occupancyPreviousValue.value == 0 || fm.X_op_"+str+"_occupancyPreviousValue.value == 3) && fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value != '-1' && fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value != '0' && fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value != '3'")){
    eval("fm.hfopi_"+ str + "_incomeAmount").disabled=false;
    eval("fm.hfop_"+ str + "_rentalOffsetOption").disabled=false;
    eval("fm.hfPropExp_" + str + "_insuranceExpense").disabled=false;
    eval("fm.hfPropExp_" + str + "_hydroExpense").disabled=false;
    eval("fm.hfPropExp_" + str + "_managementExpense").disabled=false;
    eval("fm.hfPropExp_" + str + "_repairExpense").disabled=false;
    eval("fm.hfPropExp_" + str + "_interestExpense").disabled=false;
    eval("fm.hfPropExp_" + str + "_generalExpense").disabled=false;
    if(propertyInfoRetained != null && propertyInfoRetained[str - 1]!=null){
      repopulateRentalValues(propertyInfoRetained[str - 1],"op_"+str);
    }

    if(eval("fm.hfop_"+ str + "_rentalOffsetOption").options[eval("fm.hfop_"+ str + "_rentalOffsetOption").selectedIndex].value != 0){
      eval("fm.hfopi_"+ str + "_incPercentInTds").disabled=false;
    }
  }

  eval("fm.X_op_"+str+"_occupancyPreviousValue.value = fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value");
  */

}

function subjectPropertyCheck(propertyId, element){
  hasCobrokerMortgage = document.forms[0].hasCobrokerMortgage.value;
  if(hasCobrokerMortgage == "true"){
    alert("You cannot select another property as 'Subject Property' with an existing Co-Brokered mortgage on the deal.");
    element.checked = false;
    return;
  }

  var message = "You requested to change the Subject Property. Switching 'Subject Project' information will also delete any 'Requested Mortgage Details' information entered, select 'OK' to continue or 'Cancel', to cancel the request.";
  if(!confirm(message)){
    element.checked = false;
    return;
  }
    submitPage('switchSubjectProperty',propertyId,'other_properties');
}

function clearFieldsRelatedToPropertyCountryDd(theField) {
        var prefix = theField.name.substring(0,theField.name.lastIndexOf("_") + 1);
        if (prefix.length <= 0) {
                prefix = "";
        }
        eval("document.forms[0].elements['" + prefix + "unitNumber'].value = ''");
        eval("document.forms[0].elements['" + prefix + "propertyStreetNumber'].value = ''");
        eval("document.forms[0].elements['" + prefix + "propertyStreetName'].value = ''");

        eval("document.forms[0].elements['" + prefix + "streetTypeDd'].value = '-1'");
        eval("document.forms[0].elements['" + prefix + "streetDirectionDd'].value = '-1'");
        eval("document.forms[0].elements['" + prefix + "propertyCity'].value = ''");
        eval("document.forms[0].elements['" + prefix + "provinceDd'].value = '-1'");
        if (theField.value == '1') {			//do the reverse, because the value of country has already changed to new value.
                eval("document.forms[0].elements['" + prefix + "internationalPostalCode'].value = ''");
        } else if (theField.value == '2') {
                eval("document.forms[0].elements['" + prefix + "propertyPostalFsa'].value = ''");
                eval("document.forms[0].elements['" + prefix + "propertyPostalLdu'].value = ''");
        }
        return true;
}

function checkPropertyDownpayment(indexValue){
  if(eval("ltrim(rtrim(document.forms[0].op_" + indexValue + "_downpaymentAmount.value)) == \"\" || parseFloat(document.forms[0].op_" + indexValue + "_downpaymentAmount.value) == 0")){
    alert(ALERT_DOWNPAYMENT_VALID_PROCEED_REQUIRED);
  }
  else{
    submitPage('createDownPaymentFromProperty',indexValue,'other_properties');
  }
}
function checkPayoff(element){
  var frmName = element.name;
  var str = frmName.substring(frmName.indexOf("_") + 1, frmName.length);

  var propId = str.substring(0, str.indexOf("_"));
  propId = parseInt(propId);

  str = str.substring(str.indexOf("_") + 1, str.length);
  var mortId = str.substring(0, str.indexOf("_"));
  mortId = parseInt(mortId);

  var fm = document.forms[0];

  if (eval("fm.mop_"+propId + "_" + mortId +"_payoffTypeDd.options[fm.mop_"+propId + "_" + mortId +"_payoffTypeDd.selectedIndex].value == -1")){
    if(eval("document.forms[0].mop_"+propId + "_" + mortId +"_refiBlendedAmortization")){
      eval("document.forms[0].checkbox_mop_"+propId + "_" + mortId +"_refiBlendedAmortization.checked = false");
      eval("document.forms[0].checkbox_mop_"+propId + "_" + mortId +"_refiBlendedAmortization.disabled = true");
      eval("document.forms[0].mop_"+propId + "_" + mortId +"_refiBlendedAmortization.value = 'N'");
    }
  }
  else{
    if(eval("document.forms[0].mop_"+propId + "_" + mortId +"_refiBlendedAmortization")){
      eval("document.forms[0].checkbox_mop_"+propId + "_" + mortId +"_refiBlendedAmortization.disabled = false");
    }

  }

}

function checkInsured(element){
  if(element){
    var frmName = element.name;
    var str = frmName.substring(frmName.indexOf("mop_") + 4, frmName.length);

    var propId = str.substring(0, str.indexOf("_"));
    propId = parseInt(propId);

    str = str.substring(str.indexOf("_") + 1, str.length);
    var mortId = str.substring(0, str.indexOf("_"));
    mortId = parseInt(mortId);

    var fm = document.forms[0];

    if (eval("fm.mop_"+propId + "_" + mortId +"_insuredFlag.value == 'Y'")){
      eval("document.forms[0].nonPrefix_mop_"+propId + "_" + mortId +"_mortgageInsurerId.disabled = false");
    }
    else{
      eval("document.forms[0].nonPrefix_mop_"+propId + "_" + mortId +"_mortgageInsurerId.disabled = true");
      eval("document.forms[0].nonPrefix_mop_"+propId + "_" + mortId +"_mortgageInsurerId.selectedIndex = 0");
      eval("document.forms[0].mop_"+propId + "_" + mortId +"_mortgageInsurerId.value='-1'");
    }
  }
}
function updateInsurer(element){
  if(element){
    var frmName = element.name;
    var str = frmName.substring(frmName.indexOf("mop_") + 4, frmName.length);

    var propId = str.substring(0, str.indexOf("_"));
    propId = parseInt(propId);

    str = str.substring(str.indexOf("_") + 1, str.length);
    var mortId = str.substring(0, str.indexOf("_"));
    mortId = parseInt(mortId);

    var fm = document.forms[0];
    var insurerIndex = eval("document.forms[0].nonPrefix_mop_"+propId + "_" + mortId +"_mortgageInsurerId.selectedIndex");
     var insurer = eval("document.forms[0].nonPrefix_mop_"+propId + "_" + mortId +"_mortgageInsurerId.options[" + insurerIndex + "].value");
      eval("document.forms[0].mop_"+propId + "_" + mortId +"_mortgageInsurerId.value='" + insurer + "'");
    }
}
function propertyRetainValues(){
  // Property section
  var fm = document.forms[0];

  for (var i = 1; i <= numOfPropertyAssocList; i++){
    /*if(eval("fm.hfopi_" + i + "_incomeAmount").value != null){
      //eval("fm.opi_" + i + "_incomeAmount").value = eval("fm.hfopi_" + i + "_incomeAmount").value;
    }
    */
    if(eval("fm.hfop_" + i + "_rentalOffsetOption").value != null){
      eval("fm.op_" + i + "_rentalOffsetOption").value = eval("fm.hfop_" + i + "_rentalOffsetOption").value;
    }

    if(eval("fm.hfopi_" + i + "_incPercentInTds") && eval("fm.hfopi_" + i + "_incPercentInTds").value != null && !eval("fm.hfopi_" + i + "_incPercentInTds").isDisabled){
      eval("fm.opi_" + i + "_incPercentInTds").value = eval("fm.hfopi_" + i + "_incPercentInTds").value;
    }
    if(eval("fm.hfopi_" + i + "_incPercentInGds") && eval("fm.hfopi_" + i + "_incPercentInGds").value != null && !eval("fm.hfopi_" + i + "_incPercentInGds").isDisabled){
      eval("fm.opi_" + i + "_incPercentInGds").value = eval("fm.hfopi_" + i + "_incPercentInGds").value;
    }
  }
    /*
    if(eval("fm.hfPropExp_" + i + "_insuranceExpense").value != null){
      eval("fm.PropExp_" + i + "_insuranceExpense").value = eval("fm.hfPropExp_" + i + "_insuranceExpense").value;
    }

    if(eval("fm.hfPropExp_" + i + "_hydroExpense").value != null){
      eval("fm.PropExp_" + i + "_hydroExpense").value = eval("fm.hfPropExp_" + i + "_hydroExpense").value;
    }

    if(eval("fm.hfPropExp_" + i + "_managementExpense").value != null){
      eval("fm.PropExp_" + i + "_managementExpense").value = eval("fm.hfPropExp_" + i + "_managementExpense").value;
    }

    if(eval("fm.hfPropExp_" + i + "_repairExpense").value != null){
      eval("fm.PropExp_" + i + "_repairExpense").value = eval("fm.hfPropExp_" + i + "_repairExpense").value;
    }

    if(eval("fm.hfPropExp_" + i + "_interestExpense").value != null){
      eval("fm.PropExp_" + i + "_interestExpense").value = eval("fm.hfPropExp_" + i + "_interestExpense").value;
    }

    if(eval("fm.hfPropExp_" + i + "_generalExpense").value != null){
      eval("fm.PropExp_" + i + "_generalExpense").value = eval("fm.hfPropExp_" + i + "_generalExpense").value;
    }
  }*/
}

function includeHeatFees(element){

  var frmName = element.name;
  var str = frmName.substring(frmName.indexOf("PropExp_") + 8, frmName.length);
  str = str.substring(0, str.indexOf("_"));
  str = parseInt(str);
  var fm = document.forms[0];
  var yourValue;

  yourValue = ("" == eval("fm.PropExp_" + str + "_monthlyCondoFees").value)?0:parseFloat(eval("fm.PropExp_" + str + "_monthlyCondoFees").value);

  if (yourValue > 0){
    eval("fm.checkbox_op_" + str + "_feesIncludeHeat").disabled = false;
    if (eval("fm.checkbox_op_" + str + "_feesIncludeHeat").checked){
      Format_EnableControl(eval("fm.PropExp_" + str + "_monthlyHeating").name, false);
      //eval("fm.PrepExp_" + str + "_monthlyHeating");
      //eval("fm.PropExp_" + str + "_monthlyHeating").disabled = true;
      //eval("fm.PropExp_" + str + "_monthlyHeating").value = "";
    }
    else{
      Format_EnableControl(eval("fm.PropExp_" + str + "_monthlyHeating").name, true);
      //eval("fm.PropExp_" + str + "_monthlyHeating").disabled = false;
    }
  }
  else {
    eval("fm.checkbox_op_" + str + "_feesIncludeHeat").checked = false;
    eval("fm.checkbox_op_" + str + "_feesIncludeHeat").disabled = true;
    eval("fm.checkbox_op_" + str + "_feesIncludeHeat").onclick();

    //Enable the Monthly Heating Cost
    eval("fm.PropExp_" + str + "_monthlyHeating").disabled = false;
    //eval("fm.PropExp_" + str + "_monthlyHeating").value = "";
	Format_EnableControl("heating_propertyExpenseAmount", true);
  }

}

function updateAssetFromProperty(element){
  var frmName = element.name;
  var str = frmName.substring(frmName.indexOf("op_") + 3, frmName.length);
  str = str.substring(0, str.indexOf("_"));
  str = parseInt(str);
  var fm = document.forms[0];
  /****/

  //eval("fm.assetValue_"+str).value = eval("fm.op_"+str+"_propertyValue").value;
  Format_UpdateContent(eval("fm.assetValue_"+str).name, eval("fm.op_"+str+"_propertyValue").value);
  eval("fm.assetDescription_"+str).value = eval("fm.op_"+str+"_propertyStreetNumber").value + " " + eval("fm.op_"+str+"_propertyStreetName").value + " " + eval("fm.op_"+str+"_streetTypeDd.options[fm.op_"+str+"_streetTypeDd.selectedIndex]").text;

  if(eval("fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value") != 1 && eval("fm.op_"+str+"_occupancyTypeDd.options[fm.op_"+str+"_occupancyTypeDd.selectedIndex].value") != 2){
    eval("fm.propertyAssetType_"+str).selectedIndex = 0;
  }
  else{
    eval("fm.propertyAssetType_"+str).selectedIndex = 1;
  }

  calcBorrowerTotalAsset();
}

function updateLiabilityFromProperty(element){

  var frmName = element.name;
  var str = frmName.substring(frmName.indexOf("mop_") + 4, frmName.length);

  var propId = str.substring(0, str.indexOf("_"));
  propId = parseInt(propId);

  str = str.substring(str.indexOf("_") + 1, str.length);
  var mortId = str.substring(0, str.indexOf("_"));
  mortId = parseInt(mortId);

   var fm = document.forms[0];
    if(eval("fm.mop_"+ propId + "_"+ mortId +"_balanceRemaining")){
    Format_UpdateContent("malop_"+ propId + "_"+ mortId +"_liabilityAmount", eval("fm.mop_"+ propId + "_"+ mortId +"_balanceRemaining").value);
    }
    if(eval("fm.mop_"+ propId + "_"+ mortId +"_maturityDate")){
    Format_UpdateContent("malop_"+ propId + "_"+ mortId +"_maturityDate", eval("fm.mop_"+ propId + "_"+ mortId +"_maturityDate").value);
    }
    if(eval("fm.mop_"+ propId + "_"+ mortId +"_piPaymentAmountMonthly")){
    Format_UpdateContent("malop_"+ propId + "_"+ mortId +"_liabilityMonthlyPayment", eval("fm.mop_"+ propId + "_"+ mortId +"_piPaymentAmountMonthly").value);
    }
    //have to go through a possible 3 mortgages to update them;
    for(var i = 1; i <=3; i++){
      //eval("fm.malop_"+ propId + "_"+ mortId +"_liabilityMonthlyPayment").value = eval("fm.mop_"+ propId + "_"+ mortId +"_piPaymentAmountMonthly").value;
        if(eval("fm.malop_"+ propId + "_"+ i +"_liabilityDescription")){
        eval("fm.malop_"+ propId + "_"+ i +"_liabilityDescription").value = eval("fm.op_"+propId+"_propertyStreetNumber").value + " " + eval("fm.op_"+propId+"_propertyStreetName").value + " " + eval("fm.op_"+propId+"_streetTypeDd.options[fm.op_"+propId+"_streetTypeDd.selectedIndex]").text;
        }
        if(eval("fm.malop_"+ propId + "_"+ i +"_liabilityPayoffTypeDd") && eval("fm.mop_"+ propId + "_"+ i +"_payoffTypeDd")){
        eval("fm.malop_"+ propId + "_"+ i +"_liabilityPayoffTypeDd").selectedIndex = eval("fm.mop_"+ propId + "_"+ i +"_payoffTypeDd").selectedIndex;
        }
        if(eval("fm.malop_"+ propId + "_"+ i +"_liabType")){
        if(eval("fm.op_"+propId+"_occupancyTypeDd.options[fm.op_"+propId+"_occupancyTypeDd.selectedIndex].value") != 1 && eval("fm.op_"+propId+"_occupancyTypeDd.options[fm.op_"+propId+"_occupancyTypeDd.selectedIndex].value") != 2){
        eval("fm.malop_"+ propId + "_"+ i +"_liabType").selectedIndex = 0;
        }
        else{
        eval("fm.malop_"+ propId + "_"+ i +"_liabType").selectedIndex = 1;
        }
      }
    }
  calcLiabilityMonthlyPaymentAndTotal();
}
function changeMortgageType(prefix, field, payoff){
  //Go through the application edit mortgages if the mortgage is not a payoff.
  if (payoff.options[payoff.selectedIndex].value != 1 && payoff.options[payoff.selectedIndex].value != 2){
    for(var i = 0; i < eval(prefix + "_mortgages").length; i++){

      if(eval(prefix + "_mortgages[" + i+ "]").mortgageType == field.options[field.selectedIndex].value){
        //Same type found in either mortgage Requests or Co-Brokered mortgages

        if (eval(prefix + "_mortgages[" + i+ "]").existingMortgage != 'Y' && eval(prefix + "_mortgages[" + i+ "]").mortgageType != -1 ) {
          //Ticket 7535 -  When there is s a requested, and the user is changing the type of an existing to the same as a requestd
          //but are going from blank ( new type )  default the from proceeds
          if(eval("document.forms[0].X_" + field.name).value==-1){
            eval("document.forms[0]." + payoff.name).selectedIndex=2;
            eval("document.forms[0].X_" + payoff.name).value=2;
          }
          else{
          alert(ALERT_MORTGAGE_MORTGAGE_TYPE_ALREADY_IN_USE);
          field.selectedIndex = eval("document.forms[0].X_" + field.name).value;
          return;
          }
        }
        if (eval(prefix + "_mortgages[" + i+ "]").existingMortgage == 'Y' && eval(prefix + "_mortgages")[i].cobrokeredFlag == 'Y'){
          if (eval(prefix + "_mortgages[" + i+ "]").mortgageType == -1){
               alert(ALERT_MORTGAGE_CHANGE_MORTGAGE_TYPE_TO_BLANK_TOO_MANY_WITHOUT_MORTGAGE_TYPE_2);
            }
          else{
            alert(ALERT_COBROKERED_MORTGAGE_TYPE_ALREAD_IN_USE);
          }
          field.selectedIndex = eval("document.forms[0].X_" + field.name).value;
          return;
        }
      }
    }
  }

  //Go through the existing mortgages on the property.
  var frmName = field.name;
  var str = frmName.substring(frmName.indexOf("mop_") + 4, frmName.length);

  var propId = str.substring(0, str.indexOf("_"));
  propId = parseInt(propId);

  str = str.substring(str.indexOf("_") + 1, str.length);
  var mortId = str.substring(0, str.indexOf("_"));
  mortId = parseInt(mortId);

  var fm = document.forms[0];

  for (f = 1; f <=  eval(prefix+"_numOfExistingMtg"); f++){
    if (eval("fm.mop_" + propId + "_"+ f+"_mortgageTypeDd") != field){
      if (eval("fm.mop_" + propId + "_"+ f+"_mortgageTypeDd").options[eval("fm.mop_" + propId + "_"+ f+"_mortgageTypeDd").selectedIndex].value == field.options[field.selectedIndex].value ){//&& ((eval("fm.mop_" + propId + "_"+ f+"_payoffTypeDd").options[eval("fm.mop_" + propId + "_"+ f+"_payoffTypeDd").selectedIndex].value == 1 || eval("fm.mop_" + propId + "_"+ f+"_payoffTypeDd").options[eval("fm.mop_" + propId + "_"+ f+"_payoffTypeDd").selectedIndex].value == 2) && (payoff.options[payoff.selectedIndex].value == 1 || payoff.options[payoff.selectedIndex].value == 2))){
            if (field.value == -1){
               alert(ALERT_MORTGAGE_CHANGE_MORTGAGE_TYPE_TO_BLANK_TOO_MANY_WITHOUT_MORTGAGE_TYPE_2);
            }
            else{
              alert(ALERT_EXISTING_MORTGAGE_TYPE_ALREADY_IN_USE_PAY_OFF);
            }
            field.selectedIndex = eval("document.forms[0].X_" + field.name).value;
        return;
      }
      if (eval("fm.mop_" + propId + "_"+ f+"_mortgageTypeDd").options[eval("fm.mop_" + propId + "_"+ f+"_mortgageTypeDd").selectedIndex].value == field.options[field.selectedIndex].value ){//&& eval("fm.mop_" + propId + "_"+ f+"_payoffTypeDd").options[eval("fm.mop_" + propId + "_"+ f+"_payoffTypeDd").selectedIndex].value != 1 && eval("fm.mop_" + propId + "_"+ f+"_payoffTypeDd").options[eval("fm.mop_" + propId + "_"+ f+"_payoffTypeDd").selectedIndex].value != 2 && payoff.options[payoff.selectedIndex].value != 1 && payoff.options[payoff.selectedIndex].value != 2){
            if (field.value == -1){
               alert(ALERT_MORTGAGE_CHANGE_MORTGAGE_TYPE_TO_BLANK_TOO_MANY_WITHOUT_MORTGAGE_TYPE_2);
            }
            else{
              alert(ALERT_EXISTING_MORTGAGE_TYPE_ALREADY_IN_USE_NO_PAY_OFF);
            }
            field.selectedIndex = eval("document.forms[0].X_" + field.name).value;

        return;
      }
    }
  }


  eval("document.forms[0].X_" + field.name).value = field.selectedIndex;
  if(field.value==-1){
    eval("document.forms[0]." + payoff.name).disabled = true;
    Format_EnableControl("mop_" + propId + "_" + mortId + "_balanceRemaining",false);
  }
  else{
    eval("document.forms[0]." + payoff.name).disabled = false;
    Format_EnableControl("mop_" + propId + "_" + mortId + "_balanceRemaining",true);
  }
}

function mortgage(mortgageType, payOff, existingMortgage, cobrokeredFlag){
  this.mortgageType = mortgageType;
  this.payOff = payOff;
  this.existingMortgage = existingMortgage;
  this.cobrokeredFlag = cobrokeredFlag;
}
function pasteCurrentAddressToPropertyAddress(index){
  if(confirm(CONFIRM_APPLICANT_CURRENT_ADDRESS_PASTE)){
    if(borrower1CurrentAddressIndex != -1 && numOfPropertyAssocList > 0){
          eval ( "document.forms[0].op_" + index + "_countryTypeDd.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_countryTypeDd.value");
          eval ( "document.forms[0].op_" + index + "_unitNumber.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_unitNumber.value");
          eval ( "document.forms[0].op_" + index + "_propertyStreetNumber.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_streetNumber.value");
          eval ( "document.forms[0].op_" + index + "_propertyStreetName.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_streetName.value");
          eval ( "document.forms[0].op_" + index + "_streetTypeDd.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_streetTypeDd.value");
          eval ( "document.forms[0].op_" + index + "_streetDirectionDd.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_streetDirectionDd.value");
          eval ( "document.forms[0].op_" + index + "_propertyCity.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_city.value");
          eval ( "document.forms[0].op_" + index + "_provinceDd.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_provinceDd.value");
          eval ( "document.forms[0].op_" + index + "_propertyPostalFsa.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_postalFsa.value");
          eval ( "document.forms[0].op_" + index + "_propertyPostalLdu.value = document.forms[0].ba1addr_" + borrower1CurrentAddressIndex + "_postalLdu.value");

          Mask_UpdateContent("_" + index + "_propertyPostal",""+ eval("document.forms[0]._1_addressPostalApplicant1.value"));
    }
  }
}
function updatePayoffTypes(){
      var fm = document.forms[0];
      for(var x = 1 ; x <= counterSize; x++){
          var maxCount = eval("op_" + x + "_numOfExistingMtg");
          for(var i = 1; i <= maxCount; i ++){
            if(eval("fm.mop_" + x + "_"+ i+"_mortgageTypeDd") && eval("fm.mop_" + x + "_"+ i+"_mortgageTypeDd.value== -1")){
              if(eval("fm.mop_" + x + "_"+ i+"_payoffTypeDd")){
              eval("fm.mop_" + x + "_"+ i+"_payoffTypeDd.disabled=true");
              }
              if(eval("fm.mop_" + x + "_"+ i+"_balanceRemaining")){
                Format_EnableControl("mop_" + x + "_"+ i+"_balanceRemaining", false);
              }
            }
          }
      }
}
